home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / msjournl / msjv3_6.arc / VIDEO.ARC / ASMVIDEO.ASM next >
Assembly Source File  |  1988-08-10  |  6KB  |  146 lines

  1. ;====================================================================
  2. ; ASMVIDEO.ASM - Macro Assembler video modules for 
  3. ;                small model C programs.
  4. ;====================================================================
  5.  
  6.               .MODEL SMALL
  7.               .CODE
  8.               PUBLIC _DispString, _DispCharAttr, _GetCharAttr
  9.               
  10. ;--------------------------------------------------------------------
  11. ; _DispString writes a string to the active video buffer.
  12. ;--------------------------------------------------------------------
  13. _DispString   PROC
  14.               push   bp                ;save registers and establish
  15.               mov    bp,sp             ;  stack frame addressability
  16.               push   si
  17.               push   di
  18.               mov    bx,[bp+12]        ;get pointer to VideoInfo
  19.  
  20.               mov    si,[bp+4]         ;get pointer to string
  21.               mov    dh,[bp+6]         ;calculate video address
  22.               mov    dl,[bp+8]
  23.               call   AddressOf
  24.               mov    es,[bx+8]         ;point ES to video buffer
  25.               mov    ah,[bp+10]        ;get video attribute in AH
  26.               cld                      ;clear DF
  27.  
  28. dstr1:        lodsb                    ;get next character
  29.               or     al,al             ;terminate on null byte
  30.               jz     dstr3
  31.               test   byte ptr [bx+4],1 ;branch if SyncFlag is clear
  32.               jz     dstr2
  33.               call   WriteWithWait     ;write during retrace
  34.               jmp    dstr1
  35. dstr2:        stosw                    ;write one character/attribute
  36.               jmp    dstr1             ;loop back for more
  37.  
  38. dstr3:        pop    di                ;restore registers and exit
  39.               pop    si
  40.               pop    bp
  41.               ret
  42. _DispString   ENDP
  43.  
  44. ;--------------------------------------------------------------------
  45. ; _DispCharAttr      writes a character and attribute to the active 
  46. ;                    video buffer.
  47. ;--------------------------------------------------------------------
  48. _DispCharAttr PROC
  49.               push   bp                ;save registers and establish
  50.               mov    bp,sp             ;  stack frame addressability
  51.               push   di
  52.               mov    bx,[bp+12]        ;get pointer to VideoInfo
  53.  
  54.               mov    dh,[bp+6]         ;calculate video address
  55.               mov    dl,[bp+8]
  56.               call   AddressOf
  57.               mov    es,[bx+8]         ;point ES to video buffer
  58.               mov    al,[bp+4]         ;get character/attribute
  59.               mov    ah,[bp+10]        ;  in AX
  60.  
  61.               test   byte ptr [bx+4],1 ;branch if SyncFlag is clear
  62.               jz     dca1
  63.               call   WriteWithWait     ;write during retrace
  64.               jmp    short dca2        ;then exit
  65. dca1:         stosw                    ;write one character/attribute
  66.  
  67. dca2:         pop    di                ;restore registers and exit
  68.               pop    bp
  69.               ret
  70. _DispCharAttr ENDP
  71.  
  72. ;--------------------------------------------------------------------
  73. ; _GetCharAttr       returns the character and attribute at the 
  74. ;                    specified address.
  75. ;--------------------------------------------------------------------
  76. _GetCharAttr  PROC
  77.               push   bp                ;save registers and establish
  78.               mov    bp,sp             ;  stack frame addressability
  79.               push   di
  80.               mov    bx,[bp+8]         ;get pointer to VideoInfo
  81.  
  82.               mov    dh,[bp+4]         ;calculate video address
  83.               mov    dl,[bp+6]
  84.               call   AddressOf         ;offset in DI
  85.               mov    es,[bx+8]         ;point ES to video buffer
  86.               test   byte ptr [bx+4],1 ;branch if SyncFlag is clear
  87.               jz     gca3
  88.  
  89.               mov    dx,3DAh           ;point DX to CRTC status reg
  90. gca1:         in     al,dx             ;wait for non-retrace period
  91.               test   al,1
  92.               jnz    gca1
  93. gca2:         in     al,dx             ;wait for next horizontal
  94.               test   al,1              ;  retrace
  95.               jz     gca2
  96.  
  97. gca3:         mov    ax,es:[di]        ;get character and attribute
  98.                      pop   di          ;restore registers and exit
  99.                      pop   bp
  100.                      ret
  101. _GetCharAttr  ENDP
  102.  
  103. ;--------------------------------------------------------------------
  104. ; AddressOf          returns the video buffer address that 
  105. ;                    corresponds to the specified row and column.
  106. ;
  107. ;   Entry:  DS:BX - address of VideoInfo structure
  108. ;           DH,DL - row and column
  109. ;   Exit:   DI    - offset address
  110. ;--------------------------------------------------------------------
  111. AddressOf     PROC   NEAR
  112.                      mov   al,[bx+2]   ;get columns per row
  113.                      mul   dh          ;multiply by row number
  114.                      xor   dh,dh       ;add column number
  115.                      add   ax,dx
  116.                      shl   ax,1        ;multiply by 2
  117.                      add   ax,[bx+6]   ;add offset of active page
  118.                      mov   di,ax       ;transfer result to DI
  119.                      ret               ;  and exit
  120. AddressOf     ENDP
  121.  
  122. ;--------------------------------------------------------------------
  123. ; WriteWithWait      writes a character and attribute to a CGA during 
  124. ;                    the horizontal blanking interval.
  125. ;
  126. ;   Entry:  ES:DI - video buffer address
  127. ;           AH,AL - character/attribute
  128. ;--------------------------------------------------------------------
  129. WriteWithWait PROC   NEAR
  130.                      mov   cx,ax       ;save character/attribute
  131.                      mov   dx,3DAh     ;point DX to Status Register
  132.                      cli               ;disable interrupts
  133. www1:                in    al,dx       ;wait for non-retrace period
  134.                      test  al,1
  135.                      jnz   www1
  136. www2:                in    al,dx       ;wait for next horizontal
  137.                      test  al,1        ;  retrace
  138.                      jz    www2
  139.                      xchg  ax,cx       ;retrieve character/attribute
  140.                      stosw             ;write them to video memory
  141.                      sti               ;enable interrupts
  142.                      ret
  143. WriteWithWait ENDP
  144.  
  145.                      END
  146.