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

  1. ; Program to illustrate operation of data rotate and bit mask
  2. ;  features of Graphics Data Controller. Draws 8x8 character at
  3. ;  specified location, using EGA's 8x8 ROM font. Designed
  4. ;  for use with modes 0Dh, 0Eh, 0Fh, and 10h.
  5. ; Assembled with MASM 4.0, linked with LINK 3.51.
  6. ; By Michael Abrash, 2/8/87.
  7. ; Updated 6/25/89.
  8. ;
  9. stackseg        segment para stack 'STACK'
  10.         db      512 dup(?)
  11. stackseg        ends
  12. ;
  13. EGA_VIDEO_SEGMENT       equ     0a000h  ;EGA display memory segment
  14. SCREEN_WIDTH_IN_BYTES   equ     044ah   ;offset of BIOS variable
  15. FONT_CHARACTER_SIZE     equ     8       ;# bytes in each font char
  16. ;
  17. ; EGA register equates.
  18. ;
  19. GC_INDEX        equ     3ceh    ;GC index register
  20. GC_ROTATE       equ     3       ;GC data rotate/logical function
  21.                                 ; register index
  22. GC_BIT_MASK     equ     8       ;GC bit mask register index
  23. ;
  24. dseg    segment para common 'DATA'
  25. TEST_TEXT_ROW   equ     69      ;row to display test text at
  26. TEST_TEXT_COL   equ     17      ;column to display test text at
  27. TEST_TEXT_WIDTH equ     8       ;width of a character in pixels
  28. TestString      label   byte
  29.         db      'Hello, world!',0       ;test string to print.
  30. FontPointer     dd      ?               ;font offset
  31. dseg    ends
  32. ;
  33. ; Macro to set indexed register INDEX of GC chip to SETTING.
  34. ;
  35. SETGC   macro   INDEX, SETTING
  36.         mov     dx,GC_INDEX
  37.         mov     ax,(SETTING SHL 8) OR INDEX
  38.         out     dx,ax
  39.         endm
  40. ;
  41. cseg    segment para public 'CODE'
  42.         assume  cs:cseg, ds:dseg
  43. start   proc    near
  44.         mov     ax,dseg
  45.         mov     ds,ax
  46. ;
  47. ; Select 640x350 graphics mode.
  48. ;
  49.         mov     ax,010h
  50.         int     10h
  51. ;
  52. ; Set driver to use the 8x8 font.
  53. ;
  54.         call    Select8x8Font
  55. ;
  56. ; Print the test string.
  57. ;
  58.         mov     si,offset TestString
  59.         mov     bx,TEST_TEXT_ROW
  60.         mov     cx,TEST_TEXT_COL
  61. StringOutLoop:
  62.         lodsb
  63.         and     al,al
  64.         jz      StringOutDone
  65.         call    DrawChar
  66.         add     cx,TEST_TEXT_WIDTH
  67.         jmp     StringOutLoop
  68. StringOutDone:
  69. ;
  70. ; Reset the data rotate and bit mask registers.
  71. ;
  72.         SETGC   GC_ROTATE, 0
  73.         SETGC   GC_BIT_MASK, 0ffh
  74. ;
  75. ; Exit to DOS. (Still in graphics mode; the MODE CO80 command
  76. ; can be used to restore the screen to text mode.)
  77. ;
  78.         mov     ah,4ch
  79.         int     21h
  80. Start   endp
  81. ;
  82. ; Subroutine to draw a text character in a linear graphics mode
  83. ;  (0Dh, 0Eh, 0Fh, 010h).
  84. ; Font to be used must be pointed to by FontPointer.
  85. ;
  86. ; Input:
  87. ;  AL = character to draw
  88. ;  BX = row to draw text character at
  89. ;  CX = column to draw text character at
  90. ;
  91. ;  Forces ALU function to "move".
  92. ;
  93. DrawChar        proc    near
  94.         push    ax
  95.         push    bx
  96.         push    cx
  97.         push    dx
  98.         push    si
  99.         push    di
  100.         push    bp
  101.         push    ds
  102. ;
  103. ; Set DS:SI to point to font and ES to point to display memory.
  104. ;
  105.         lds     si,[FontPointer]        ;point to font
  106.         mov     dx,EGA_VIDEO_SEGMENT
  107.         mov     es,dx                   ;point to display memory
  108. ;
  109. ; Calculate screen address of byte character starts in.
  110. ;
  111.         push    ds      ;point to BIOS data segment
  112.         sub     dx,dx
  113.         mov     ds,dx
  114.         xchg    ax,bx
  115.         mov     di,ds:[SCREEN_WIDTH_IN_BYTES]   ;retrieve BIOS
  116.                                                 ; screen width
  117.         pop     ds
  118.         mul     di      ;calculate offset of start of row
  119.         push    di      ;set aside screen width
  120.         mov     di,cx   ;set aside the column
  121.         and     cl,0111b ;keep only the column in-byte address
  122.         shr     di,1
  123.         shr     di,1
  124.         shr     di,1    ;divide column by 8 to make a byte address
  125.         add     di,ax   ;and point to byte
  126. ;
  127. ; Calculate font address of character.
  128. ;
  129.         sub     bh,bh
  130.         shl     bx,1    ;assumes 8 bytes per character; use
  131.         shl     bx,1    ; a multiply otherwise
  132.         shl     bx,1    ;offset in font of character
  133.         add     si,bx   ;offset in font segment of character
  134. ;
  135. ; Set up the GC rotation for the bit alignment of the character
  136. ; within each display memory byte.
  137. ;
  138.         mov     dx,GC_INDEX
  139.         mov     al,GC_ROTATE
  140.         mov     ah,cl
  141.         out     dx,ax
  142. ;
  143. ; Set up BH as bit mask for part of character in left byte,
  144. ; BL as bit mask for part of character in right byte.
  145. ;
  146.         mov     bx,0ff00h
  147.         shr     bx,cl
  148. ;
  149. ; Draw the character, the part in left byte first, then the part in
  150. ; right byte next, using the data rotation to position the character
  151. ; across the byte boundary and then using the bit mask to get the
  152. ; proper portion of the character into each byte.
  153. ;
  154. ; Does not check for the case where the character is byte-aligned,
  155. ; so no rotation (and hence only one write) is required; special
  156. ; code would speed that case considerably.
  157. ;
  158.         mov     bp,FONT_CHARACTER_SIZE
  159.         mov     dx,GC_INDEX
  160.         pop     cx      ;get back screen width
  161.         dec     cx
  162.         dec     cx      ; -2 because do two bytes for each char
  163. ; Point the GC Index register to the Bit Mask register for the
  164. ; duration of the loop.
  165.         mov     al,GC_BIT_MASK
  166.         out     dx,al
  167.         inc     dx      ;point to GC Data register
  168. CharacterLoop:
  169. ;
  170. ; Set the bit mask for the part of the character in the left byte.
  171. ;
  172.         mov     al,bh
  173.         out     dx,al
  174. ;
  175. ; Get the next character byte & write it to display memory.
  176. ; (This draws the part of the character in the left byte.)
  177. ;
  178.         mov     al,es:[di]      ;load latches from left byte
  179.         lodsb                   ;get character byte
  180.         stosb                   ;write left part of character byte
  181. ;
  182. ; Set the bit mask for the part of the character in the right byte.
  183. ;
  184.         xchg    ax,bx           ;get right-byte bit mask in AL
  185.                                 ; and save the font byte
  186.         out     dx,al           ;set the right-byte bit mask
  187.         xchg    ax,bx           ;put the font byte back in AL
  188.                                 ; and the bit masks back in BX
  189. ;
  190. ; Write the character byte to display memory again.
  191. ; (Right part of character.)
  192. ;
  193.         mov     ah,es:[di]      ;load latches from right byte
  194.         stosb                   ;write character byte
  195. ;
  196. ; Point to next line of character in display memory.
  197. ;
  198.         add     di,cx
  199. ;
  200.         dec     bp
  201.         jnz     CharacterLoop
  202. ;
  203.         pop     ds
  204.         pop     bp
  205.         pop     di
  206.         pop     si
  207.         pop     dx
  208.         pop     cx
  209.         pop     bx
  210.         pop     ax
  211.         ret
  212. DrawChar        endp
  213. ;
  214. ; Set the pointer to the 8x8 font.
  215. ;
  216. Select8x8Font   proc    near
  217.         mov     ah,11h  ;EGA BIOS character generator function,
  218.         mov     al,30h  ; return info subfunction
  219.         mov     bh,3    ;get 8x8 font pointer
  220.         int     10h
  221.         mov     word ptr [FontPointer],bp       ;save pointer
  222.         mov     word ptr [FontPointer+2],es
  223.         ret
  224. Select8x8Font   endp
  225. ;  
  226. cseg    ends
  227.         end     start