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

  1. ; Program to illustrate flipping from bit-mapped graphics mode to
  2. ; text mode and back without losing any of the graphics mode
  3. ; bit map.
  4. ;
  5. ; Assembled with MASM 5.0, linked with MS-LINK 3.60.
  6. ;
  7. ; By Michael Abrash 11/8/87
  8. ; Updated 6/27/89.
  9. ;
  10. stackseg        segment para stack 'STACK'
  11.         db      512 dup(0)
  12. stackseg        ends
  13.  
  14. SAVE_PLANE_3    equ     0       ;set to 1 to save the first 8K of
  15.                                 ; plane 3, used to handle EGAs and
  16.                                 ; VGAs that store text info in
  17.                                 ; plane 3. IBM EGAs and VGAs don't
  18.                                 ; use plane 3.
  19.                                 ; Set to 0 not to save the first
  20.                                 ; 8K of plane 3
  21.  
  22. GRAPHICS_SEGMENT equ    0a000h  ;mode 10 bit-map segment
  23. TEXT_SEGMENT    equ     0b800h  ;mode 3 bit-map segment
  24. SC_INDEX        equ     3c4h    ;Sequence Controller Index register
  25. MAP_MASK        equ     2       ;index of Map Mask register
  26. GC_INDEX        equ     3ceh    ;Graphics Controller Index register
  27. READ_MAP        equ     4       ;index of Read Map register
  28.  
  29. Data    segment para common 'DATA'
  30.  
  31. GStrikeAnyKeyMsg0       label   byte
  32.         db      0dh, 0ah, 'Graphics mode', 0dh, 0ah
  33.         db      'Strike any key to continue...', 0dh, 0ah, '$'
  34.  
  35. GStrikeAnyKeyMsg1       label   byte
  36.         db      0dh, 0ah, 'Graphics mode again', 0dh, 0ah
  37.         db      'Strike any key to continue...', 0dh, 0ah, '$'
  38.  
  39. TStrikeAnyKeyMsg        label   byte
  40.         db      0dh, 0ah, 'Text mode', 0dh, 0ah
  41.         db      'Strike any key to continue...', 0dh, 0ah, '$'
  42.  
  43. Plane2Save      db      2000h dup (?)   ;save area for plane 2 data
  44.                                         ; where font gets loaded
  45. if SAVE_PLANE_3
  46. Plane3Save      db      2000h dup (?)   ;save area for plane 3 data
  47. endif
  48. CharAttSave     db      4000 dup (?)    ;save area for memory wiped
  49.                                         ; out by character/attribute
  50.                                         ; data in text mode
  51. Data    ends
  52.  
  53. Code    segment para public 'CODE'
  54.         assume  cs:Code, ds:Data
  55. Start   proc    near
  56.         mov     ax,10h
  57.         int     10h             ;select video mode 10h (640x350)
  58. ;
  59. ; Fill the graphics bit-map with a colored pattern.
  60. ;
  61.         cld
  62.         mov     ax,GRAPHICS_SEGMENT
  63.         mov     es,ax
  64.         mov     ah,3            ;initial fill pattern
  65.         mov     cx,4            ;four planes to fill
  66.         mov     dx,SC_INDEX
  67.         mov     al,MAP_MASK
  68.         out     dx,al           ;leave the SC Index pointing to the
  69.                                   ; Map Mask register
  70.         inc     dx
  71.  
  72. FillBitMap:
  73.         mov     al,10h
  74.         shr     al,cl           ;generate map mask for this plane
  75.         out     dx,al           ;set map mask for this plane
  76.         sub     di,di           ;start at offset 0
  77.         mov     al,ah           ;get the fill pattern
  78.         push    cx              ;preserve plane count
  79.         mov     cx,8000h        ;fill 32K words
  80.         rep stosw               ;do fill for this plane
  81.         pop     cx              ;get back plane count
  82.         shl     ah,1
  83.         shl     ah,1
  84.         loop    FillBitMap
  85. ;
  86. ; Put up "strike any key" message.
  87. ;
  88.         mov     ax,Data
  89.         mov     ds,ax
  90.         mov     dx,offset GStrikeAnyKeyMsg0
  91.         mov     ah,9
  92.         int     21h
  93. ;
  94. ; Wait for a key.
  95. ;
  96.         mov     ah,01h
  97.         int     21h
  98. ;
  99. ; Save the 8K of plane 2 that will be used by the font.
  100. ;
  101.         mov     dx,GC_INDEX
  102.         mov     al,READ_MAP
  103.         out     dx,al
  104.         inc     dx
  105.         mov     al,2
  106.         out     dx,al           ;set up to read from plane 2
  107.         mov     ax,Data
  108.         mov     es,ax
  109.         mov     ax,GRAPHICS_SEGMENT
  110.         mov     ds,ax
  111.         sub     si,si
  112.         mov     di,offset Plane2Save
  113.         mov     cx,2000h/2      ;save 8K (length of default font)
  114.         rep movsw
  115. if SAVE_PLANE_3
  116. ;
  117. ; Save the 8K of plane 3 that is used by some BIOSes in text mode.
  118. ;
  119.         mov     dx,GC_INDEX
  120.         mov     al,READ_MAP
  121.         out     dx,al
  122.         inc     dx
  123.         mov     al,3
  124.         out     dx,al           ;set up to read from plane 3
  125.         mov     ax,Data
  126.         mov     es,ax
  127.         mov     ax,GRAPHICS_SEGMENT
  128.         mov     ds,ax
  129.         sub     si,si
  130.         mov     di,offset Plane3Save
  131.         mov     cx,2000h/2      ;save 8K (length of default font)
  132.         rep movsw
  133. endif
  134. ;
  135. ; Go to text mode without clearing display memory.
  136. ;
  137.         mov     ax,083h
  138.         int     10h
  139. ;
  140. ; Save the text mode bit-map.
  141. ;
  142.         mov     ax,Data
  143.         mov     es,ax
  144.         mov     ax,TEXT_SEGMENT
  145.         mov     ds,ax
  146.         sub     si,si
  147.         mov     di,offset CharAttSave
  148.         mov     cx,4000/2       ;length of one text screen in words
  149.         rep movsw
  150. ;
  151. ; Fill the text mode screen with dots and put up "strike any key"
  152. ; message.
  153. ;
  154.         mov     ax,TEXT_SEGMENT
  155.         mov     es,ax
  156.         sub     di,di
  157.         mov     al,'.'          ;fill character
  158.         mov     ah,7            ;fill attribute
  159.         mov     cx,4000/2       ;length of one text screen in words
  160.         rep stosw
  161.         mov     ax,Data
  162.         mov     ds,ax
  163.         mov     dx,offset TStrikeAnyKeyMsg
  164.         mov     ah,9
  165.         int     21h
  166. ;
  167. ; Wait for a key.
  168. ;
  169.         mov     ah,01h
  170.         int     21h
  171. ;
  172. ; Restore the text mode screen to the state it was in on entering
  173. ; text mode.
  174. ;
  175.         mov     ax,Data
  176.         mov     ds,ax
  177.         mov     ax,TEXT_SEGMENT
  178.         mov     es,ax
  179.         mov     si,offset CharAttSave
  180.         sub     di,di
  181.         mov     cx,4000/2       ;length of one text screen in words
  182.         rep movsw
  183. ;
  184. ; Return to mode 10h without clearing display memory.
  185. ;
  186.         mov     ax,90h
  187.         int     10h
  188. ;
  189. ; Restore the portion of plane 2 that was wiped out by the font.
  190. ;
  191.         mov     dx,SC_INDEX
  192.         mov     al,MAP_MASK
  193.         out     dx,al
  194.         inc     dx
  195.         mov     al,4
  196.         out     dx,al           ;set up to write to plane 2
  197.         mov     ax,Data
  198.         mov     ds,ax
  199.         mov     ax,GRAPHICS_SEGMENT
  200.         mov     es,ax
  201.         mov     si,offset Plane2Save
  202.         sub     di,di
  203.         mov     cx,2000h/2      ;restore 8K (length of default font)
  204.         rep movsw
  205. if SAVE_PLANE_3
  206. ;
  207. ; Restore the portion of plane 3 that is used by some BIOSes in
  208. ; text mode.
  209. ;
  210.         mov     dx,SC_INDEX
  211.         mov     al,MAP_MASK
  212.         out     dx,al
  213.         inc     dx
  214.         mov     al,8
  215.         out     dx,al           ;set up to write to plane 3
  216.         mov     ax,Data
  217.         mov     ds,ax
  218.         mov     ax,GRAPHICS_SEGMENT
  219.         mov     es,ax
  220.         mov     si,offset Plane3Save
  221.         sub     di,di
  222.         mov     cx,2000h/2      ;restore 8K (length of default font)
  223.         rep movsw
  224. endif
  225. ;
  226. ; Put up "strike any key" message.
  227. ;
  228.         mov     ax,Data
  229.         mov     ds,ax
  230.         mov     dx,offset GStrikeAnyKeyMsg1
  231.         mov     ah,9
  232.         int     21h
  233. ;
  234. ; Wait for a key before returning to text mode and ending.
  235. ;
  236.         mov     ah,01h
  237.         int     21h
  238.         mov     ax,03h
  239.         int     10h
  240.         mov     ah,4ch
  241.         int     21h
  242. Start   endp
  243. Code    ends
  244.         end     Start