home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter27 / l27-3.asm < prev    next >
Assembly Source File  |  1997-06-18  |  6KB  |  194 lines

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