home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / PJGRAPH.ZIP / CHAP07.2 < prev    next >
Encoding:
Text File  |  1989-09-26  |  6.1 KB  |  158 lines

  1. ; Program to illustrate use of read mode 1 (color compare mode)
  2. ; to detect collisions in display memory. Draws a yellow line on a
  3. ; blue background, then draws a perpendicular green line until the
  4. ; yellow line is reached.
  5. ;
  6. ; By Michael Abrash 4/2/88
  7. ;
  8. stackseg        segment word stack 'STACK'
  9.         db      512 dup (?)
  10. stackseg        ends
  11. ;
  12. VGA_SEGMENT     EQU     0a000h
  13. SCREEN_WIDTH    EQU     80      ;in bytes
  14. GC_INDEX        EQU     3ceh    ;Graphics Controller Index register
  15. SET_RESET       EQU     0       ;Set/Reset register index in GC
  16. ENABLE_SET_RESET EQU    1       ;Enable Set/Reset register index in 
  17. GC
  18. COLOR_COMPARE   EQU     2       ;Color Compare register index in GC
  19. GRAPHICS_MODE   EQU     5       ;Graphics Mode register index in GC
  20. BIT_MASK        EQU     8       ;Bit Mask register index in GC
  21. ;
  22. code    segment word 'CODE'
  23.         assume  cs:code
  24. Start   proc    near
  25.         cld
  26. ;
  27. ; Select graphics mode 10h.
  28. ;
  29.         mov     ax,10h
  30.         int     10h
  31. ;
  32. ; Fill the screen with blue.
  33. ;
  34.         mov     al,1            ;blue is color 1
  35.         call    SelectSetResetColor ;set to draw in blue
  36.         mov     ax,VGA_SEGMENT
  37.         mov     es,ax
  38.         sub     di,di
  39.         mov     cx,7000h
  40.         rep     stosb           ;the value written actually doesn't
  41.                                 ; matter, since set/reset is providing
  42.                                 ; the data written to display memory
  43. ;
  44. ; Draw a vertical yellow line.
  45. ;
  46.         mov     al,14           ;yellow is color 14
  47.         call    SelectSetResetColor ;set to draw in yellow
  48.         mov     dx,GC_INDEX
  49.         mov     al,BIT_MASK
  50.         out     dx,al           ;point GC Index to Bit Mask
  51.         inc     dx              ;point to GC Data
  52.         mov     al,10h
  53.         out     dx,al           ;set Bit Mask to 10h
  54.         mov     di,40           ;start in the middle of the top line
  55.         mov     cx,350          ;do full height of screen
  56. VLineLoop:
  57.         mov     al,es:[di]      ;load the latches
  58.         stosb                   ;write next pixel of yellow line
  59.                                 ; (set/reset provides the data written
  60.                                 ; to display memory, and AL is actually
  61.                                 ; ignored)
  62.         add     di,SCREEN_WIDTH-1 ;point to the next scan line
  63.         loop    VLineLoop
  64. ;
  65. ; Select write mode 0 and read mode 1.
  66. ;
  67.         mov     dx,GC_INDEX
  68.         mov     al,GRAPHICS_MODE
  69.         out     dx,al           ;point GC Index to Graphics Mode register
  70.         inc     dx              ;point to GC Data
  71.         mov     al,00001000b    ;bit 3=1 is read mode 1, bits 1 & 0=00
  72.                                 ; is write mode 0
  73.         out     dx,al           ;set Graphics Mode to read mode 1,
  74.                                 ; write mode 0
  75. ;
  76. ; Draw a horizontal green line, one pixel at a time, from left
  77. ; to right until color compare reports a yellow pixel is encountered.
  78. ;
  79. ; Draw in green.
  80. ;
  81.         mov     al,2            ;green is color 2
  82.         call    SelectSetResetColor ;set to draw in green
  83. ;
  84. ; Set color compare to look for yellow.
  85. ;
  86.         mov     dx,GC_INDEX
  87.         mov     al,COLOR_COMPARE
  88.         out     dx,al           ;point GC Index to Color Compare register
  89.         inc     dx              ;point to GC Data
  90.         mov     al,14           ;we're looking for yellow, color 14
  91.         out     dx,al           ;set color compare to look for yellow
  92.         dec     dx              ;point to GC Index
  93. ;
  94. ; Set up for quick access to Bit Mask register.
  95. ;
  96.         mov     al,BIT_MASK
  97.         out     dx,al           ;point GC Index to Bit Mask register
  98.         inc     dx              ;point to GC Data
  99. ;
  100. ; Set initial pixel mask and display memory offset.
  101. ;
  102.         mov     al,80h          ;initial pixel mask
  103.         mov     di,100*SCREEN_WIDTH
  104.                                 ;start at left edge of scan line 100
  105. HLineLoop:
  106.         mov     ah,es:[di]      ;do a read mode 1 (color compare) read.
  107.                                 ; This also loads the latches.
  108.         and     ah,al           ;is the pixel of current interest yellow?
  109.         jnz     WaitKeyAndDone  ;yes--we've reached the yellow line, so
  110.                                 ; we're done
  111.         out     dx,al           ;set the Bit Mask register so that we
  112.                                 ; modify only the pixel of interest
  113.         mov     es:[di],al      ;draw the pixel. The value written is
  114.                                 ; irrelevant, since set/reset is providing
  115.                                 ; the data written to display memory
  116.         ror     al,1            ;shift pixel mask to the next pixel
  117.         adc     di,0            ;advance the display memory offset if
  118.                                 ; the pixel mask wrapped
  119.         jmp     HLineLoop
  120. ;
  121. ; Wait for a key to be pressed to end, then return to text mode and
  122. ; return to DOS.
  123. ;
  124. WaitKeyAndDone:
  125. WaitKeyLoop:
  126.         mov     ah,1
  127.         int     16h
  128.         jz      WaitKeyLoop
  129.         sub     ah,ah
  130.         int     16h     ;clear the key
  131.         mov     ax,3
  132.         int     10h     ;return to text mode
  133.         mov     ah,4ch
  134.         int     21h     ;done
  135. Start   endp
  136. ;
  137. ; Enables set/reset for all planes, and sets the set/reset color
  138. ; to AL.
  139. ;
  140. SelectSetResetColor     proc    near
  141.         mov     dx,GC_INDEX
  142.         push    ax              ;preserve color
  143.         mov     al,SET_RESET
  144.         out     dx,al           ;point GC Index to Set/Reset register
  145.         inc     dx              ;point to GC Data
  146.         pop     ax              ;get back color
  147.         out     dx,al           ;set Set/Reset register to selected color
  148.         dec     dx              ;point to GC Index
  149.         mov     al,ENABLE_SET_RESET
  150.         out     dx,al           ;point GC Index to Enable Set/Reset
  151.                                 ; register
  152.         inc     dx              ;point to GC Data
  153.         mov     al,0fh
  154.         out     dx,al           ;enable set/reset for all planes
  155.         ret
  156. SelectSetResetColor     endp
  157. code    ends
  158.         end     Start