home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / basic / QBNWS202.ZIP / FASTPRNT.ZIP / DISPLAY.ASM next >
Encoding:
Assembly Source File  |  1991-06-01  |  11.1 KB  |  239 lines

  1. ; DISPLAY.ASM - contains a collection of video-related procedures and
  2. ;               functions for use with Microsoft high-level languages.
  3. ;
  4. ;   Author:     Christy Gemmell
  5. ;   For:        Assembly-Language Toolbox for QuickBASIC
  6. ;   Version:    4.06
  7. ;   Date:       22/9/1990
  8. ;
  9. ;   Compatible with the QuickBASIC 4.0, 4.5 and BASIC 6 compilers
  10. ;   Assembled using Microsoft Macro Assembler, MASM version 5.1
  11. ;
  12. ;   Global symbols and procedures.
  13. ;
  14.                 .model  medium
  15.  
  16.                 public  ScreenAddress, ScreenWrite
  17.                 public  VideoType, FastPrint
  18.  
  19.                 .code
  20.  
  21. ;   Data Division.
  22. ;
  23. ;   Video parameters - default to monochrome screen display
  24. ;
  25. SnowFlag        db      0               ; Snow prevention flag
  26. VideoRam        dw      0B000h          ; Current video segment
  27. VideoPort       dw      03BAh           ; Current video status port
  28. Param1          label   word
  29. Mode            db      7               ; Current screen mode
  30. Columns         db      80              ; Current screen width
  31. Param2          label   word
  32. Rows            db      25              ; Current screen length
  33. ActivePage      db      0               ; Current video page
  34.  
  35. ;Listing 1.1     Collect video information
  36.  
  37. ;  Collect information about the current video display.
  38. ;
  39. ;   Returns:    AL =    Current display mode
  40. ;               AH =    Screen width in columns
  41. ;               BL =    Screen height in rows
  42. ;               BH =    Active display page
  43. ;
  44. ;  The correct video display segment and CRT status port addresses are
  45. ;  determined for the current system and, if necessary, the internal
  46. ;  'snow' prevention flag is set.
  47. ;
  48. VideoType       proc    far
  49.                 push    cx                      ; Preserve these
  50.                 push    dx                      ;    registers
  51.                 push    es                      ;
  52.                 push    bp                      ;Added this [DEC]
  53.                 mov     ah,0Fh                  ; ROM-BIOS Service 16
  54.                 int     10h                     ; - Check video mode
  55.                 cmp     al,7                    ; Monochrome display?
  56.                 je      Type_02                 ; Yes, use defaults
  57.                 mov     cs:VideoRam,0B800h      ; Otherwise set up
  58.                 mov     cs:VideoPort,03DAh      ;    for colour
  59. Type_01:
  60.                 mov     cs:Param1,ax            ; Save display mode
  61.                                                 ;    and width
  62.                 push    bx                      ; Save active display
  63.                 xor     bh,bh                   ;    page
  64.                 mov     dl,24                   ; Default to 25 rows
  65.                 mov     ax,1130h                ; ROM-BIOS Service 16
  66.                 int     10h                     ;  - get font
  67.                 pop     bx                      ;    information
  68.                 mov     bl,dl                   ; DL = rows - 1
  69.                 inc     bl                      ; Save video page     
  70.                 mov     cs:Param2,bx            ;    and height
  71.                 mov     bl,10h                  ; Test for presence
  72.                 mov     ah,12h                  ;    of an EGA or VGA
  73.                 int     10h                     ;      display adaptor
  74.                 cmp     bl,10h                  ; Any response?
  75.                 jne     Type_02                 ; Yes, can't be a CGA
  76.                 mov     cs:SnowFlag,1           ; Set snow prevention
  77. Type_02:                                        ;    flag
  78.                 mov     bx,cs:Param2            ; Recover page and
  79.                                                 ;    screen height
  80.                 mov     ax,cs:Param1            ; Recover screen mode
  81.                                                 ;    and width
  82.                 pop     bp                      ;added [DEC]
  83.                 pop     es                      ; Clean up the stack
  84.                 pop     dx
  85.                 pop     cx
  86.                 ret                             ; Return to caller
  87. VideoType       endp
  88.  
  89. ;Listing 1.2     Convert row/column co-ordinates to an address
  90.  
  91. ;   Calculate address from a pair of row/column co-ordinates.
  92. ;
  93. ;   Given the row/column column co-ordinate of a character on the
  94. ;   screen, this function returns the segment:offset address of that
  95. ;   character in video memory. The address is correctly adjusted to
  96. ;   the start of the the currently active display page, but no check
  97. ;   is made to ensure that the co-ordinates supplied are within the
  98. ;   actual screen bounds.
  99. ;
  100. ;   Input:     AL      = Row co-ordinate of character (base zero).
  101. ;              AH      = Column co-ordinate of character (base zero).
  102. ;   Output:    ES:DI==>  Address in video display buffer of the
  103. ;                         character cell specified.
  104. ;              DX      = CRT status register port address.
  105. ;
  106. ;   It is assumed that a previous call has been made to the VideoType
  107. ;   function to determine the screen width, the port address of the
  108. ;   CRT status register and the correct video display segment.
  109. ;
  110. ScreenAddress  proc    far
  111.                push    ax               ; Save working registers
  112.                push    bx
  113.                mov     bh,ah            ; Column to BH
  114.                mov     bl,cs:Columns    ; Get current screen width
  115.                shl     bl,1             ; Add in attribute bytes
  116.                mul     bl               ; Multiply by row number
  117.                xor     bl,bl            ; Calculate
  118.                xchg    bh,bl            ;    column offset
  119.                shl     bl,1             ;      in BX
  120.                add     ax,bx            ; Add it to the row offset
  121.                mov     di,ax            ;    and copy to DI
  122.                xor     ax,ax            ; Index to ROM-BIOS
  123.                mov     es,ax            ;    data in low memory
  124.                mov     ax,es:[44Eh]     ; Get offset of current page
  125.                add     di,ax            ; Adjust target pointer
  126.                mov     es,cs:VideoRam   ; Return segment of video RAM
  127.                mov     dx,cs:VideoPort  ; Return CRT status port
  128.                pop     bx               ; Clean up the stack
  129.                pop     ax
  130.                ret                      ;    and return to caller
  131. ScreenAddress  endp
  132.  
  133. ;Listing 1.3     Output a character and attribute to the screen.
  134. ;
  135. ;   Output a character and attribute to the video display.
  136. ;
  137. ;   If the 'snow prevention' flag is set, this routine waits until the
  138. ;   beginning of the next CRT horizontal retrace period before writing
  139. ;   data to the display. This is necessary only on computers fitted
  140. ;   with Colour Graphics Adaptor (CGA) which may suffer from glitches
  141. ;   or screen snow if data is written to the screen while the video
  142. ;   buffer is being refreshed.
  143. ;
  144. ;   Input:      ES:DI==>    Address in the video display buffer where
  145. ;                           the data is to be written.
  146. ;               DX =        Port address of CRT status register.
  147. ;               AL =        Character to output.
  148. ;               AH =        Display attribute of character.
  149. ;
  150. ;   Output:     DI          Updated to point to next output address.
  151. ;
  152. ScreenWrite     proc    far
  153.                 push    bx              ; Preserve BX
  154.                 cmp     cs:SnowFlag,0   ; Snow prevention needed?
  155.                 cli                     ; Don't interrupt!
  156.                 jz      Write_3         ; No, don't bother
  157.                 mov     bx,ax           ; Save byte and attribute
  158. Write_1:
  159.                 in      al,dx           ; Read video port
  160.                 test    al,1            ; Test bit zero
  161.                 jnz     Write_1         ; Wait until it's reset
  162. Write_2:
  163.                 in      al,dx           ; Read port again
  164.                 test    al,1            ; Test bit zero
  165.                 jz      Write_2         ; Wait until it's set
  166.                 mov    ax,bx            ; Recover data
  167. Write_3:
  168.                 stosw                   ; Write data to screen
  169.                 sti                     ; Restore interrupts
  170.                 pop     bx              ; Restore BX
  171.                 ret
  172. ScreenWrite     endp
  173.  
  174. ;Listing 1.4     Main program module.
  175.  
  176. ;   Fast screen printing.
  177. ;
  178. ;   This procedure outputs text directly to the video display without
  179. ;   going through DOS or ROM-BIOS services.
  180. ;
  181. FastPrint       proc    far
  182.                 push    bp              ; Save Base pointer
  183.                 mov     bp,sp           ; Establish stack frame
  184.                 push    es              ; Save Extra Segment
  185.                 push    si              ;    and index pointers
  186.                 push    di
  187.                 call    VideoType       ; Get video parameters
  188.                 mov     dh,ah           ; Load screen dimensions
  189.                 mov     dl,bl           ;    into DX
  190.                 mov     ax,[bp+12]      ; Get row number
  191.                 dec     al              ; Convert to base zero
  192.                 cmp     al,0            ; Top screen row?
  193.                 jae     Fast_01         ; Jump if not below
  194.                 xor     al,al           ; Don't go over the top!
  195. Fast_01:
  196.                 cmp     al,dl           ; Bottom row?
  197.                 jb      Fast_02         ; Go no further
  198.                 mov     al,dl
  199.                 dec     al
  200. Fast_02:
  201.                 mov     bx,[bp+10]      ; Get column number
  202.                 mov     ah,bl           ;    into AH
  203.                 dec     ah              ; Convert to base zero
  204.                 cmp     ah,0            ; Leftmost column?
  205.                 jae     Fast_03         ; Jump if not below
  206.                 xor     ah,ah           ; Don't go off the screen
  207. Fast_03:
  208.                 cmp     ah,dh           ; Rightmost column?
  209.                 jb      Fast_04         ; Go no further
  210.                 mov     ah,dh           ; Don't go off the screen
  211.                 dec     ah              ; Base zero, remember?
  212. Fast_04:
  213.                 call    ScreenAddress   ; Calculate target address
  214.                 mov     bx,[bp+8]       ; Index to string descriptor
  215.                 mov     cx,[bx]         ;    Get string length
  216.                 cmp     cx,0            ; Make sure it isn't
  217.                 ja      Fast_05         ;    a null string
  218.                 mov     ax,1            ; If so set Error code
  219.                 jmp     short Fast_07   ;    and abort
  220. Fast_05:
  221.                 mov     si,[bx+2]       ; DS:SI==> string data
  222.                 mov     ax,[bp+6]       ; Get display attribute
  223.                 xchg    ah,al           ;    into AH
  224.                 cld                     ; Clear direction flag
  225. Fast_06:
  226.                 lodsb                   ; Get a byte from the string
  227.                 call    ScreenWrite     ; Write byte and attribute
  228.                 loop    Fast_06         ; For length of string
  229.                 xor     ax,ax           ; Report success
  230. Fast_07:
  231.                 pop     di              ; Clean up the stack
  232.                 pop     si
  233.                 pop     es
  234.                 pop     bp
  235.                 ret     8               ; Return to QuickBASIC
  236. FastPrint       endp
  237.  
  238. end
  239.