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

  1. ;void  write_portion(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  _video_buffer:word
  6.     EXTRN  _snow_protect:byte
  7.     EXTRN  _error_code:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _write_portion
  12. _write_portion proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;set stack frame
  15.     push di            ;
  16.     push si            ;
  17.     pushf            ;
  18.     cmp  _memory_model,0    ;near or far?
  19.     jle  begin        ;jump if near
  20.     inc  bp            ;else add 2 to BP
  21.     inc  bp            ;
  22. begin:    mov  cl,_snow_protect    ;get _snow_protect
  23.     push ds            ;save Turbo's DS
  24.     mov  ax,_video_buffer    ;fetch Videobuffer
  25.     mov  es,ax        ;ES pts to buffer
  26.     cmp  _memory_model,2    ;data near or far?
  27.     jb   L0            ;jump if near
  28.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  29.     inc  bp            ;add 2 to BP since dword ptr    
  30.     inc  bp            ;
  31.     jmp  short L00        ;
  32. L0:    mov  si,[bp+4]        ;near case
  33. L00:    sub  bx,bx        ;
  34.     mov  bl,[bp+12]        ;Row
  35.     dec  bx            ;count from zero
  36.     mov  [bp+12],cl        ;save _snow_protect
  37.     sub  cx,cx        ;
  38.     mov  cl,[bp+10]        ;Col
  39.     dec  cx            ;count from zero
  40.     mov  ax,160        ;bytes per row
  41.     mul  bl            ;row offset
  42.     shl  cx,1        ;dble cols for attributes
  43.     add  ax,cx        ;offset to start position
  44.     mov  di,ax        ;ES:DI pts to start
  45.     push si            ;must find string length
  46.     sub  cx,cx        ;count in CX
  47. L000:    inc  si            ;forward strg ptr
  48.     inc  cx            ;inc counter
  49.     cmp  byte ptr[si],0    ;end of string?
  50.     jne  L000        ;loop if not
  51.     pop  si            ;SI back to start of string
  52.     dec  si            ;adjust for start of loop below
  53.     mov  bh,1        ;error code 1 = null strg
  54.     jcxz L7            ;quit if null
  55.     mov  al,[bp+6]        ;startpoint
  56.     inc  al            ;count from 1
  57.     inc  bh            ;2 = Start outside of string
  58.     cmp  al,cl        ;start point in range?
  59.     jnbe L7            ;quit if not
  60.     inc  bh            ;3 = not enough room for NumCh
  61.     cmp  byte ptr[bp+8],0    ;check for NumCh nonzero
  62.     jz   L7            ;quit if zero
  63.     mov  ah,al        ;copy startpoint
  64.     add  ah,[bp+8]        ;add number chars
  65.     dec  ah            ;adjust
  66.     cmp  ah,cl        ;in range?
  67.     jna  L1            ;jump ahead if OK
  68.     sub  cl,[bp+6]        ;number chars to write
  69.     inc  cl            ;adjust
  70.     jmp  short L2        ;
  71. L1:    mov  cl,[bp+8]        ;num chars to write
  72.     sub  bh,bh        ;0 = no error
  73. L2:    sub  ah,ah        ;extend byte value
  74.     add  si,ax        ;offset string ptr
  75.     cld            ;forward direction
  76.     mov  ah,[bp+14]        ;get screen attribute
  77. L3:    lodsb            ;get a char from Strg
  78.     cmp  byte ptr[bp+12],0    ;protect against snow?
  79.     je   L6            ;jump if not
  80.     push ax            ;save char-attri
  81.     mov  dx,3dah        ;status byte address
  82. L4:    in   al,dx        ;get status byte
  83.     test al,1        ;test bit
  84.     jnz  L4            ;loop till 0
  85.     cli            ;disable interrupts
  86. L5:    in   al,dx        ;get status byte
  87.     test al,1        ;test bit
  88.     jz   L5            ;loop till 1, then write
  89.     pop  ax            ;restore char-attri
  90. L6:    stosw            ;write the char and color
  91.     loop L3            ;loop till finished
  92. L7:    sti            ;reenable interrupts
  93.     pop  ds            ;restore DS and quit
  94.     mov  _error_code,bh    ;set _error_code
  95.     popf            ;
  96.     pop  si            ;
  97.     pop  di            ;
  98.     pop  bp            ;
  99.     cmp  _memory_model,0    ;quit
  100.     jle  quit        ;
  101.     db   0CBh        ;RET far
  102. quit:    ret            ;RET near
  103. _write_portion endp
  104. _TEXT    ENDS
  105.     END
  106.