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

  1. ; Program to demonstrate the 32 text pages of the VGA/EGA.
  2. ;
  3. ; To demonstrate the 32 text pages of the VGA, set
  4. ; ADAPTER_IS_VGA to 1.
  5. ;
  6. ; To demonstrate the 32 text pages of the EGA, set
  7. ; ADAPTER_IS_VGA to 0.
  8. ;
  9. ; By Michael Abrash  5/22/88
  10. ; Updated 6/29/89.
  11. ;
  12.  
  13. ADAPTER_IS_VGA          equ     0       ;set to 1 to assemble for VGA,
  14.                                         ; 0 to assemble for EGA
  15. PAGE_LENGTH             equ     1000h   ;number of bytes per page
  16. MISCELLANEOUS_OUTPUT_W  equ     3c2h    ;Miscellaneous Output write port
  17. MISCELLANEOUS_OUTPUT_R  equ     3cch    ;Miscellaneous Output read port
  18.                                         ; (available only on VGA)
  19. GC_INDEX                equ     3ceh
  20. GC_MISCELLANEOUS        equ     6
  21. CRTC_INDEX              equ     3d4h
  22. CRTC_START_ADDRESS_HIGH equ     0ch
  23. CRTC_START_ADDRESS_LOW  equ     0dh
  24.  
  25. stackseg        segment para stack 'STACK'
  26.         db      512 dup (?)
  27. stackseg        ends
  28.  
  29. code    segment para public 'CODE'
  30.         assume  cs:code, ds:nothing
  31. start   proc    near
  32. ;
  33. ; Set to text mode.
  34. ;
  35.         mov     ax,3
  36.         int     10h
  37. ;
  38. ; Relocate display memory to A000 by reprogramming
  39. ; the Graphics Controller's Miscellaneous register.
  40. ;
  41.         mov     dx,GC_INDEX
  42.         mov     al,GC_MISCELLANEOUS
  43.         out     dx,al
  44.         inc     dx
  45.         mov     al,06h
  46.         out     dx,al
  47. ;
  48. ; Point to display memory.
  49. ;
  50.         mov     ax,0a000h
  51.         mov     es,ax
  52. ;
  53. ; Fill text pages 0-15 (the pages that are accessible when
  54. ; the Page bit is 1, the setting after a mode set is performed).
  55. ; (Page 0 is filled with "A", page 1 with "B", and so on.)
  56. ;
  57.         sub     ax,ax   ;start with page 0
  58.         mov     bl,'A'  ;base letter for pages 0-15
  59. FillPages0_15Loop:
  60.         push    ax
  61.         call    FillPage
  62.         pop     ax
  63.         inc     ax
  64.         cmp     ax,16
  65.         jb6     FillPages0_15Loop
  66. ;
  67. ; Set the Page bit to 0.
  68. ;
  69. if ADAPTER_IS_VGA
  70.         mov     dx,MISCELLANEOUS_OUTPUT_R
  71.         in      al,dx
  72.         and     al,not 20h      ;Page bit (bit 5) -> 0
  73.         mov     dx,MISCELLANEOUS_OUTPUT_W
  74.         out     dx,al
  75. else
  76.         mov     dx,MISCELLANEOUS_OUTPUT_W
  77.         mov     al,87h          ;Page bit (bit 5) -> 0
  78.         out     dx,al
  79. endif
  80. ;
  81. ; Now fill text pages 16-31 (the pages that are accessible when
  82. ; the Page bit is 0).
  83. ; (Page 16 is filled with "Q", page 17 with "R", and so on.)
  84. ;
  85.         sub     ax,ax   ;start with page 0 in the second set of
  86.                         ; 16 pages; pages in this set are accessed
  87.                         ; exactly as pages 0-15 were
  88.         mov     bl,'Q'  ;base letter for pages 16-31
  89. FillPages16_31Loop:
  90.         push    ax
  91.         call    FillPage
  92.         pop     ax
  93.         inc     ax
  94.         cmp     ax,16
  95.         jb      FillPages16_31Loop
  96. ;
  97. ; Display each of the text pages in turn, waiting for a key
  98. ; before going to the next page. Note that all 32 pages can
  99. ; be displayed without changing the Page bit; the Page bit
  100. ; only affects CPU accesses, not video data fetching.
  101. ;
  102.         sub     ax,ax
  103. ShowPageLoop:
  104.         push    ax
  105.         call    ShowPage
  106.         call    WaitKey
  107.         pop     ax
  108.         inc     ax
  109.         cmp     ax,32
  110.         jb      ShowPageLoop
  111. ;
  112. ; Done-perform a mode set to reset all paging and clear
  113. ; the screen, then return to DOS.
  114. ;
  115.         mov     ax,3
  116.         int     10h
  117.         mov     ah,4ch
  118.         int     21h
  119. start   endp
  120. ;
  121. ; Fills a text page with a corresponding character.
  122. ;
  123. ; Input:
  124. ;       AX = text page
  125. ;       BL = character for text page 0 (each text page
  126. ;               is filled with character BL + text page #)
  127. ;
  128. FillPage        proc    near
  129.         push    ax      ;save the page #
  130.         mov     dx,PAGE_LENGTH
  131.         mul     dx      ;calculate the start offset of the page
  132.                         ; in the display memory segment
  133.         mov     di,ax
  134.         pop     ax      ;get back the page #
  135.         add     al,bl   ;convert it to a unique letter
  136.         mov     ah,7    ;attribute is white
  137.         mov     cx,PAGE_LENGTH/2 ;page length as measured
  138.                                  ; in character/attribute pairs
  139.         cld
  140.         rep     stosw   ;fill the page
  141.         ret
  142. FillPage        endp
  143. ;
  144. ; Programs the CRTC to display the desired text page.
  145. ;
  146. ; Input: AX = text page.
  147. ;
  148. ShowPage        proc    near
  149.         mov     dx,PAGE_LENGTH/2
  150.         mul     dx              ;start offset of the pages as
  151.                                 ; measured in character/attribute
  152.                                 ; pairs (which is how the CRTC
  153.                                 ; counts in text mode)
  154.         mov     dx,CRTC_INDEX   ;point to the CRTC Index register
  155.         push    ax
  156.         mov     al,CRTC_START_ADDRESS_HIGH
  157.         out     dx,al
  158.         inc     dx              ;point to the CRTC Data register
  159.         mov     al,ah
  160.         out     dx,al           ;set the high start address byte
  161.         dec     dx              ;point to the CRTC Index register
  162.         mov     al,CRTC_START_ADDRESS_LOW
  163.         out     dx,al
  164.         inc     dx              ;point to the CRTC Data register
  165.         pop     ax
  166.         out     dx,al           ;set the low start address byte
  167.         ret
  168. ShowPage        endp
  169. ;
  170. ; Waits until a key is pressed.
  171. ;
  172. WaitKey proc    near
  173.         mov     ah,1
  174.         int     16h
  175.         jz      WaitKey
  176.         sub     ah,ah
  177.         int     16h     ;clear the key
  178.         ret
  179. WaitKey endp
  180.  
  181. code    ends
  182.         end     start