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

  1. ;void  wrt(strg,color);
  2. ;  unsigned char  *strg,color;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _video_buffer:word
  6.     EXTRN  _video_page:byte
  7.     EXTRN  _snow_protect:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME CS:_TEXT
  11.     PUBLIC _wrt
  12. _wrt proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;set stack frame
  15.     push di            ;
  16.     push si            ;
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    push ds            ;DS changed
  22.     cld            ;direction flag forward
  23.     mov  ax,_video_buffer    ;fetch _video_buffer
  24.     mov  es,ax        ;place in ES
  25.     mov  bh,_video_page    ;set the cursor page
  26.     mov  bl,_snow_protect    ;get _snow_protect
  27.     mov  ah,3        ;BIOS func for cursor pos
  28.     int  10h        ;now DH-DL holds row-col
  29.     cmp  _memory_model,2    ;data near or far?
  30.     jb   L0            ;jump if near
  31.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  32.     inc  bp            ;add 2 to BP since dword ptr    
  33.     inc  bp            ;
  34.     jmp  short L00        ;
  35. L0:    mov  si,[bp+4]        ;near case
  36. L00:    mov  [bp+4],bx        ;save page number and snow_protect
  37.     sub  cx,cx        ;clear CX
  38.     push si            ;keep initial pointer position
  39. L000:    cmp  byte ptr[si],0    ;end of string?
  40.     je   L0000        ;jump if so
  41.     inc  si            ;inc ptr 
  42.     inc  cx            ;inc counter
  43.     jmp  short L000        ;loop till end
  44. L0000:    pop  si            ;restore Ptr
  45.     jcxz L9            ;quit if null string
  46.     mov  ax,160        ;byte per row
  47.     mul  dh            ;multiply by num rows
  48.     sub  dh,dh        ;now DX holds num cols
  49.     shl  dx,1        ;double for attri bytes
  50.     add  ax,dx        ;cursor offset in buffer
  51.     mov  di,ax        ;now ES:DI pts to pos
  52.     mov  bx,3998        ;scroll if won't fit...
  53.     sub  bx,di        ;space left
  54.     mov  ax,cx        ;chars to be printed
  55.     shl  ax,1        ;double for attributes
  56.     cmp  bx,ax        ;enough room?
  57.     jge  L3            ;jump ahead if so
  58.     sub  ax,bx        ;amount space required
  59.     mov  bl,160        ;byte per row
  60.     div  bl            ;divide
  61.     cmp  ah,0        ;any remainder?
  62.     je   L1            ;if not, jump ahead
  63.     inc  al            ;else, scroll 1 more line
  64. L1:    push cx            ;save string length
  65.     push bp            ;scrolling changes BP
  66.     push ax            ;save num lines scrolled
  67.     mov  bh,[bp+6]        ;attribute of new lines
  68.     mov  cx,0000h        ;top left row-col
  69.     mov  dx,184Fh        ;bottom right row-col
  70.     mov  ah,6        ;upwards scroll function
  71.     int  10h        ;make the scroll
  72.     pop  cx            ;num lines scrolled in CL
  73.     sub  ch,ch        ;clear CH, use CX counter
  74. L2:    sub  di,160        ;screen ptr back 1 line
  75.     loop L2            ;repeat for ea ln of scrl
  76.     pop  bp            ;restore BP
  77.     pop  cx            ;restore string length
  78. L3:    mov  ah,[bp+6]        ;get attribute
  79. L4:    lodsb            ;get a character
  80.     mov  dx,es        ;get video buffer address
  81.     cmp  byte ptr[bp+4],0    ;protect against show?
  82.     je   L7            ;jump ahead if not
  83.     mov  dx,3dah        ;status byte address
  84.     mov  bx,ax        ;save AX contents
  85. L5:    in   al,dx        ;get status byte
  86.     test al,1        ;test bit
  87.     jnz  L5            ;loop till 0
  88.     cli            ;disable interrupts
  89. L6:    in   al,dx        ;get status byte
  90.     test al,1        ;test bit
  91.     jz   L6            ;loop till 1
  92.     mov  ax,bx        ;restore AX contents
  93. L7:    stosw            ;write char and attri
  94.     loop L4            ;go do next char
  95. L8:    sti            ;reenable interrupts
  96.     mov  ax,di        ;now set new cursor pos
  97.     mov  dl,160        ;chars in a row
  98.     div  dl            ;divide scrn ptr
  99.     shr  ah,1        ;div remainder by 2
  100.     mov  dl,ah        ;BIOS: col in DL
  101.     mov  dh,al        ;row in DH
  102.     mov  bh,[bp+5]        ;page number
  103.     mov  ah,2        ;function number
  104.     int  10h        ;set the cursor
  105. L9:    pop  ds            ;
  106.     pop  si            ;
  107.     pop  di            ;
  108.     pop  bp            ;
  109.     cmp  _memory_model,0    ;quit
  110.     jle  quit        ;
  111.     db   0CBh        ;RET far
  112. quit:    ret            ;RET near
  113. _wrt endp
  114. _TEXT    ENDS
  115.     END
  116.