home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CEXPRESS.ZIP / SCREEN.ASM / WRTPRTNB.ASM < prev    next >
Assembly Source File  |  1989-05-03  |  3KB  |  98 lines

  1. ;void  write_portion_b(strg,start,num_ch,col,row,color);
  2. ;  unsigned char  *strg,start,num_ch,col,row,color;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _video_page:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _write_portion_b
  11. _write_portion_b proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set stack frame
  14.     push di            ;
  15.     push si            ;
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:    push ds            ;
  21.     mov  bh,_video_page    ;set video page
  22.     cmp  _memory_model,2    ;data near or far?
  23.     jb   L0            ;jump if near
  24.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  25.     inc  bp            ;add 2 to BP since dword ptr    
  26.     inc  bp            ;
  27.     jmp  short L00        ;
  28. L0:    mov  si,[bp+4]        ;near case
  29. L00:    mov  bl,[bp+14]        ;attribute in BL
  30.     mov  dh,[bp+12]        ;row in DH
  31.     dec  dh            ;count from 0
  32.     mov  dl,[bp+10]        ;col in DL
  33.     dec  dl            ;count from 0
  34.     sub  ax,ax        ;clear AX
  35.     cld            ;direction forward
  36.     push si            ;must find string length
  37.     sub  ax,ax        ;count in AX
  38. L000:    inc  si            ;forward strg ptr
  39.     inc  ax            ;inc counter
  40.     cmp  byte ptr[si],0    ;end of string?
  41.     jne  L000        ;loop if not
  42.     pop  si            ;SI back to start of string
  43.     mov  byte ptr[bp+14],1    ;errorcode 1 = Strg null
  44.     or   ax,ax        ;check for null
  45.     jz   L4            ;quit if null
  46.     mov  di,ax        ;use DI as len counter
  47.     inc  byte ptr[bp+14]    ;2 = start out of range
  48.     mov  al,[bp+6]        ;get Start
  49.     inc  al            ;count from 1
  50.     cmp  ax,di        ;in range?
  51.     ja   L4            ;quit if so
  52.     add  si,ax        ;forward string ptr to Start
  53.     dec  si            ;
  54.     inc  byte ptr[bp+14]    ;3 = NumCh out of range
  55.     cmp  byte ptr[bp+8],0    ;null?
  56.     je   L4            ;
  57.     add  al,[bp+8]        ;add NumCh to Start
  58.     dec  al            ;adjust
  59.     cmp  ax,di        ;longer than string?
  60.     jna  L1            ;move along if not
  61.     mov  al,[bp+6]        ;else grab Start
  62.     sub  di,ax        ;subtract from string length
  63.     inc  di            ;adjust
  64.     jmp  short L2        ;
  65. L1:    mov  byte ptr[bp+14],0    ;0 = no error
  66.     mov  al,[bp+8]        ;NumCh
  67.     mov  di,ax        ;set as counter
  68. L2:    mov  cx,1        ;chars to write each time
  69.     mov  ah,2        ;function to set cursor
  70.     int  10h        ;set the cursor
  71.     mov  ah,9        ;function to write char
  72.     lodsb            ;get a char
  73.      int  10h        ;write it
  74.     inc  dl            ;forward column ptr
  75.     cmp  dl,80        ;out or bounds?
  76.     jne  L3            ;jump ahead if not
  77.     mov  dl,0        ;back to left
  78.     cmp  dh,24        ;bottom row?
  79.     je   L3            ;jump if so
  80.     inc  dh            ;else forward row
  81. L3:    dec  di            ;check len counter
  82.     jnz  L2            ;loop till finished
  83.     mov  ah,2        ;function to set cursor
  84.     int  10h        ;set final curs position
  85. L4:    pop  ds            ;restore DS
  86.     mov  al,[bp+14]        ;fetch _error_code
  87.     mov  _error_code,al    ;set it
  88.     pop  si            ;
  89.     pop  di            ;
  90.     pop  bp            ;
  91.     cmp  _memory_model,0    ;quit
  92.     jle  quit        ;
  93.     db   0CBh        ;RET far
  94. quit:    ret            ;RET near
  95. _write_portion_b endp
  96. _TEXT    ENDS
  97.     END
  98.