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

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