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

  1. ; Program to illustrate operation of ALUs and latches in the EGA's
  2. ;  Graphics Data Controller. Draws a variety of patterns against
  3. ;  a horizontally striped background, using each of the 4 available
  4. ;  logical functions (data unmodified, AND, OR, XOR) in turn to combine
  5. ;  the images with the background.
  6. ; Assembled with MASM 4.0, linked with LINK 3.51.
  7. ; By Michael Abrash, 11/27/86.
  8. ; Updated 6/24/89.
  9. ;
  10. stackseg        segment para stack 'STACK'
  11.         db      512 dup(?)
  12. stackseg        ends
  13. ;
  14. EGA_VIDEO_SEGMENT       equ     0a000h  ;EGA display memory segment
  15. SCREEN_HEIGHT           equ     350
  16. SCREEN_WIDTH_IN_BYTES   equ     80
  17. DEMO_AREA_HEIGHT        equ     336     ;# of scan lines in area
  18.                                         ; logical function operation
  19.                                         ; is demonstrated in
  20. DEMO_AREA_WIDTH_IN_BYTES equ    40      ;width in bytes of area
  21.                                         ; logical function operation
  22.                                         ; is demonstrated in
  23. VERTICAL_BOX_WIDTH_IN_BYTES equ 10      ;width in bytes of the boxes
  24.                                         ; used to demonstrate the
  25.                                         ; logical functions
  26. ;
  27. ; EGA register equates.
  28. ;
  29. GC_INDEX        equ     3ceh    ;GC index register
  30. GC_ROTATE       equ     3       ;GC data rotate/logical function
  31.                                 ; register index
  32. GC_MODE         equ     5       ;GC mode register index
  33. ;
  34. dseg    segment para common 'DATA'
  35. ;
  36. ; String used to label logical functions.
  37. ;
  38. LabelString     label   byte
  39.         db      'UNMODIFIED    AND       OR        XOR   '
  40. LABEL_STRING_LENGTH     equ     $-LabelString
  41. ;
  42. ; Strings used to label fill patterns.
  43. ;
  44. FillPatternFF   db      'Fill Pattern: 0FFh'
  45. FILL_PATTERN_FF_LENGTH  equ     $ - FillPatternFF
  46. FillPattern00   db      'Fill Pattern: 000h'
  47. FILL_PATTERN_00_LENGTH  equ     $ - FillPattern00
  48. FillPatternVert db      'Fill Pattern: Vertical Bar'
  49. FILL_PATTERN_VERT_LENGTH        equ     $ - FillPatternVert
  50. FillPatternHorz db      'Fill Pattern: Horizontal Bar'
  51. FILL_PATTERN_HORZ_LENGTH equ    $ - FillPatternHorz
  52. ;
  53. dseg    ends
  54. ;
  55. ; Macro to set indexed register INDEX of GC chip to SETTING.
  56. ;
  57. SETGC   macro   INDEX, SETTING
  58.         mov     dx,GC_INDEX
  59.         mov     ax,(SETTING SHL 8) OR INDEX
  60.         out     dx,ax
  61.         endm
  62. ;
  63. ;
  64. ; Macro to call BIOS write string function to display text string
  65. ;  TEXT_STRING, of length TEXT_LENGTH, at location ROW,COLUMN.
  66. ;
  67. TEXT_UP macro   TEXT_STRING, TEXT_LENGTH, ROW, COLUMN
  68.         mov     ah,13h                  ;BIOS write string function
  69.         mov     bp,offset TEXT_STRING   ;ES:BP points to string
  70.         mov     cx,TEXT_LENGTH
  71.         mov     dx,(ROW SHL 8) OR COLUMN        ;position
  72.         sub     al,al           ;string is chars only, cursor not moved
  73.         mov     bl,7            ;text attribute is white (light gray)
  74.         int     10h
  75.         endm
  76. ;
  77. cseg    segment para public 'CODE'
  78.         assume  cs:cseg, ds:dseg
  79. start   proc    near
  80.         mov     ax,dseg
  81.         mov     ds,ax
  82. ;
  83. ; Select 640x350 graphics mode.
  84. ;
  85.         mov     ax,010h
  86.         int     10h
  87. ;
  88. ; ES points to EGA memory.
  89. ;
  90.         mov     ax,EGA_VIDEO_SEGMENT
  91.         mov     es,ax
  92. ;
  93. ; Draw background of horizontal bars.
  94. ;
  95.         mov     dx,SCREEN_HEIGHT/4
  96.                                 ;# of bars to draw (each 4 pixels high)
  97.         sub     di,di           ;start at offset 0 in display memory
  98.         mov     ax,0ffffh       ;fill pattern for light areas of bars
  99.         mov     bx,DEMO_AREA_WIDTH_IN_BYTES / 2 ;length of each bar
  100.         mov     si,SCREEN_WIDTH_IN_BYTES - DEMO_AREA_WIDTH_IN_BYTES
  101.         mov     bp,(SCREEN_WIDTH_IN_BYTES * 3) - DEMO_AREA_WIDTH_IN_BYTES
  102. BackgroundLoop:
  103.         mov     cx,bx           ;length of bar
  104.     rep stosw                   ;draw top half of bar
  105.         add     di,si           ;point to start of bottom half of bar
  106.         mov     cx,bx           ;length of bar
  107.     rep stosw                   ;draw bottom half of bar
  108.         add     di,bp           ;point to start of top of next bar
  109.         dec     dx
  110.         jnz     BackgroundLoop
  111. ;
  112. ; Draw four boxes, stacked vertically and filled with a variety of
  113. ; fill patterns, using each of the 4 logical functions in turn.
  114. ;
  115.         SETGC   GC_ROTATE, 0            ;select data unmodified
  116.                                         ; logical function...
  117.         mov     di,0
  118.         call    DrawVerticalBoxes       ;...and draw boxes
  119.  
  120.         SETGC   GC_ROTATE, 08h          ;select AND logical function...
  121.         mov     di,10
  122.         call    DrawVerticalBoxes       ;...and draw boxes
  123. ;
  124.         SETGC   GC_ROTATE, 10h          ;select OR logical function...
  125.         mov     di,20
  126.         call    DrawVerticalBoxes       ;...and draw boxes
  127. ;
  128.         SETGC   GC_ROTATE, 18h          ;select XOR logical function...
  129.         mov     di,30
  130.         call    DrawVerticalBoxes       ;...and draw boxes
  131. ;
  132. ; Reset the logical function to data unmodified, the default state.
  133. ;
  134.         SETGC   GC_ROTATE, 0
  135. ;
  136. ; Label the screen.
  137. ;
  138.         push    ds
  139.         pop     es      ;strings we'll display are passed to BIOS
  140.                         ; by pointing ES:BP to them
  141. ;
  142. ; Label the logical functions, using the EGA BIOS's
  143. ;  write string function.
  144. ;
  145.         TEXT_UP LabelString, LABEL_STRING_LENGTH, 24, 0
  146. ;
  147. ; Label the fill patterns, using the EGA BIOS's
  148. ;  write string function.
  149. ;
  150.         TEXT_UP FillPatternFF, FILL_PATTERN_FF_LENGTH, 3, 42
  151.         TEXT_UP FillPattern00, FILL_PATTERN_00_LENGTH, 9, 42
  152.         TEXT_UP FillPatternVert, FILL_PATTERN_VERT_LENGTH, 15, 42
  153.         TEXT_UP FillPatternHorz, FILL_PATTERN_HORZ_LENGTH, 21, 42
  154. ;
  155. ; Wait until a key's been hit to reset screen mode & exit.
  156. ;
  157. WaitForKey:
  158.         mov     ah,1
  159.         int     16h
  160.         jz      WaitForKey
  161. ;
  162. ; Finished. Clear key, reset screen mode and exit.
  163. ;
  164. Done:
  165.         mov     ah,0    ;clear key that we just detected
  166.         int     16h
  167. ;
  168.         mov     ax,3    ;reset to text mode
  169.         int     10h
  170. ;
  171.         mov     ah,4ch  ;exit to DOS
  172.         int     21h
  173. ;
  174. start   endp
  175. ;
  176. ; Subroutine to draw a set of four boxes, each 80x84 in size, using
  177. ;  the currently selected logical function, with the upper left corner
  178. ;  at the display memory offset in DI. Each box is filled with a
  179. ;  separate pattern. The top box is filled with a 0FFh (solid) pattern,
  180. ;  the next box is filled with a 00h (empty) pattern, the next box is
  181. ;  filled with a 33h (double-pixel-wide vertical bar) pattern, and the
  182. ;  bottom box is filled with a double-pixel-high horizontal bar pattern.
  183. ;
  184. ; Macro to draw a column of the specified width in bytes, 84 pixels
  185. ;  high, filled with the specified fill pattern.
  186. ;
  187. DRAW_BOX_QUARTER        macro   FILL, WIDTH
  188.         local   RowLoop, ColumnLoop
  189.         mov     al,FILL                 ;fill pattern
  190.         mov     dx,DEMO_AREA_HEIGHT / 4 ;1/4 of the full box height
  191. RowLoop:
  192.         mov     cx,WIDTH
  193. ColumnLoop:
  194.         mov     ah,es:[di]      ;load display memory contents into
  195.                                 ; GC latches (we don't actually care
  196.                                 ; about value read into AH)
  197.         stosb                   ;write pattern, which is logically
  198.                                 ; combined with latch contents for each
  199.                                 ; plane and then written to display
  200.                                 ; memory
  201.         loop    ColumnLoop
  202.         add     di,SCREEN_WIDTH_IN_BYTES - WIDTH
  203.                                 ;point to start of next line down in box
  204.         dec     dx
  205.         jnz     RowLoop
  206.         endm
  207. ;
  208. DrawVerticalBoxes       proc    near
  209.         DRAW_BOX_QUARTER        0ffh, VERTICAL_BOX_WIDTH_IN_BYTES
  210.                                         ;first fill pattern: solid fill
  211.         DRAW_BOX_QUARTER        0, VERTICAL_BOX_WIDTH_IN_BYTES
  212.                                         ;second fill pattern: empty fill
  213.         DRAW_BOX_QUARTER        033h, VERTICAL_BOX_WIDTH_IN_BYTES
  214.                                         ;third fill pattern: double-pixel
  215.                                         ; wide vertical bars
  216.         mov     dx,DEMO_AREA_HEIGHT / 4 / 4
  217.                                 ;fourth fill pattern: horizontal bars in
  218.                                 ; sets of 4 scan lines
  219.         sub     ax,ax
  220.         mov     si,VERTICAL_BOX_WIDTH_IN_BYTES  ;width of fill area
  221. HorzBarLoop:
  222.         dec     ax              ;0ffh fill (faster to do word than
  223.                                 ; byte DEC)
  224.         mov     cx,si           ;width to fill
  225. HBLoop1:
  226.         mov     bl,es:[di]      ;load latches (don't care about value)
  227.         stosb                   ;write solid pattern, through ALUs
  228.         loop    HBLoop1
  229.         add     di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  230.         mov     cx,si           ;width to fill
  231. HBLoop2:
  232.         mov     bl,es:[di]      ;load latches
  233.         stosb                   ;write solid pattern, through ALUs
  234.         loop    HBLoop2
  235.         add     di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  236.         inc     ax              ;0 fill (faster to do word than byte INC)
  237.         mov     cx,si           ;width to fill
  238. HBLoop3:
  239.         mov     bl,es:[di]      ;load latches
  240.         stosb                   ;write empty pattern, through ALUs
  241.         loop    HBLoop3
  242.         add     di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  243.         mov     cx,si           ;width to fill
  244. HBLoop4:
  245.         mov     bl,es:[di]      ;load latches
  246.         stosb                   ;write empty pattern, through ALUs
  247.         loop    HBLoop4
  248.         add     di,SCREEN_WIDTH_IN_BYTES - VERTICAL_BOX_WIDTH_IN_BYTES
  249.         dec     dx
  250.         jnz     HorzBarLoop
  251. ;
  252.         ret
  253. DrawVerticalBoxes       endp
  254. cseg    ends
  255.         end     start