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

  1. ; Program that draws a diagonal line to illustrate the use of a
  2. ; Color Don't Care register setting of 0FFh to support fast
  3. ; read-modify-write operations to VGA memory in write mode 3 by
  4. ; drawing a diagonal line.
  5. ;
  6. ; Note: Works on VGAs only.
  7. ;
  8. ; By Michael Abrash 4/2/88
  9. ; Updated 6/27/89.
  10. ;
  11. stackseg        segment word stack 'STACK'
  12.         db      512 dup (?)
  13. stackseg        ends
  14. ;
  15. VGA_SEGMENT     EQU     0a000h
  16. SCREEN_WIDTH    EQU     80      ;in bytes
  17. GC_INDEX        EQU     3ceh    ;Graphics Controller Index register
  18. SET_RESET       EQU     0       ;Set/Reset register index in GC
  19. GRAPHICS_MODE   EQU     5       ;Graphics Mode register index in GC
  20. COLOR_DONT_CARE EQU     7       ;Color Don't Care register index in 
  21. GC
  22. ;
  23. code    segment word 'CODE'
  24.         assume  cs:code
  25. Start   proc    near
  26. ;
  27. ; Select graphics mode 12h.
  28. ;
  29.         mov     ax,12h
  30.         int     10h
  31. ;
  32. ; Select write mode 3 and read mode 1.
  33. ;
  34.         mov     dx,GC_INDEX
  35.         mov     al,GRAPHICS_MODE
  36.         out     dx,al
  37.         inc     dx
  38.         in      al,dx           ;VGA registers are readable, bless them!
  39.         or      al,00001011b    ;bit 3=1 selects read mode 1, and
  40.                                 ; bits 1 & 0=11 selects write mode 3
  41.         jmp     $+2             ;delay between IN and OUT to same port
  42.         out     dx,al
  43.         dec     dx
  44. ;
  45. ; Set up set/reset to always draw in white. It's not necessary to
  46. ; enable set/reset, which is always enabled in write mode 3.
  47. ;
  48.         mov     al,SET_RESET
  49.         out     dx,al
  50.         inc     dx
  51.         mov     al,0fh
  52.         out     dx,al
  53.         dec     dx
  54. ;
  55. ; Set Color Don't Care to 0, so reads of VGA memory always return 0FFh.
  56. ;
  57.         mov     al,COLOR_DONT_CARE
  58.         out     dx,al
  59.         inc     dx
  60.         sub     al,al
  61.         out     dx,al
  62. ;
  63. ; Set up the initial memory pointer and pixel mask.
  64. ;
  65.         mov     ax,VGA_SEGMENT
  66.         mov     ds,ax
  67.         sub     bx,bx
  68.         mov     al,80h
  69. ;
  70. ; Draw 400 points on a diagonal line sloping down and to the right.
  71. ;
  72.         mov     cx,400
  73. DrawDiagonalLoop:
  74.         and     [bx],al ;reads display memory, loading the latches,
  75.                         ; then writes AL to the VGA. AL becomes the
  76.                         ; bit mask, and set/reset provides the
  77.                         ; actual data written
  78.         add     bx,SCREEN_WIDTH
  79.                         ; point to the next scan line
  80.         ror     al,1    ;move the pixel mask one pixel to the right
  81.         adc     bx,0    ;advance to the next byte if the pixel mask
  82.                         ; wrapped
  83.         loop    DrawDiagonalLoop
  84. ;
  85. ; Wait for a key to be pressed to end, then return to text mode and
  86. ; return to DOS.
  87. ;
  88. WaitKeyLoop:
  89.         mov     ah,1
  90.         int     16h
  91.         jz      WaitKeyLoop
  92.         sub     ah,ah
  93.         int     16h     ;clear the key
  94.         mov     ax,3
  95.         int     10h     ;return to text mode
  96.         mov     ah,4ch
  97.         int     21h     ;done
  98. Start   endp
  99. code    ends
  100.         end     Start