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

  1. ; Program to restore a mode 10h EGA graphics screen from
  2. ; the file SNAPSHOT.SCR.
  3. ;
  4. ; Updated 6/29/89.
  5. ;
  6. VGA_SEGMENT     equ     0a000h
  7. SC_INDEX        equ     3c4h    ;Sequence Controller Index register
  8. MAP_MASK        equ     2       ;Map Mask register index in SC
  9. DISPLAYED_SCREEN_SIZE equ (640/8)*350
  10.                                 ;# of displayed bytes per plane in a
  11.                                 ; hi-res graphics screen
  12. ;
  13. stackseg        segment para stack 'STACK'
  14.         db      512 dup (?)
  15. stackseg        ends
  16. ;
  17. Data    segment word 'DATA'
  18. Filename db     'SNAPSHOT.SCR',0 ;name of file we're restoring from
  19. ErrMsg1 db      '*** Couldn''t open SNAPSHOT.SCR ***',0dh,0ah,'$'
  20. ErrMsg2 db      '*** Error reading from SNAPSHOT.SCR ***',0dh,0ah,'$'
  21. WaitKeyMsg db   0dh, 0ah, 'Done. Press any key to end...',0dh,0ah,'$'
  22. Handle  dw      ?       ;handle of file we're restoring from
  23. Plane   db      ?       ;plane being written
  24. Data    ends
  25. ;
  26. Code    segment
  27.         assume  cs:Code, ds:Data
  28. Start   proc    near
  29.         mov     ax,Data
  30.         mov     ds,ax
  31. ;
  32. ; Go to hi-res graphics mode.
  33. ;
  34.         mov     ax,10h  ;AH = 0 means mode set, AL = 10h selects
  35.                         ; hi-res graphics mode
  36.         int     10h     ;BIOS video interrupt
  37. ;
  38. ; Open SNAPSHOT.SCR.
  39. ;
  40.         mov     ah,3dh  ;DOS open file function
  41.         mov     dx,offset Filename
  42.         sub     al,al           ;open for reading
  43.         int     21h
  44.         mov     [Handle],ax     ;save the handle
  45.         jnc     RestoreTheScreen ;we're ready to restore if no error
  46.         mov     ah,9            ;DOS print string function
  47.         mov     dx,offset ErrMsg1
  48.         int     21h             ;notify of the error
  49.         jmp     short Done      ;and done
  50. ;
  51. ; Loop through the 4 planes, making each writable in turn and
  52. ; reading it from disk. Note that all 4 planes are writable at
  53. ; A000:0000; the Map Mask register selects which planes are writable
  54. ; at any one time. We only make one plane writable at a time.
  55. ;
  56. RestoreTheScreen:
  57.         mov     [Plane],0       ;start with plane 0
  58. RestoreLoop:
  59.         mov     dx,SC_INDEX
  60.         mov     al,MAP_MASK     ;set SC Index to Map Mask register
  61.         out     dx,al
  62.         inc     dx
  63.         mov     cl,[Plane]      ;get the # of the plane we want
  64.                                 ; to restore
  65.         mov     al,1
  66.         shl     al,cl   ;set the bit enabling writes to
  67.                         ; only the one desired plane
  68.         out     dx,al   ;set to write to the desired plane
  69.         mov     ah,3fh  ;DOS read from file function
  70.         mov     bx,[Handle]
  71.         mov     cx,DISPLAYED_SCREEN_SIZE ;# of bytes to read
  72.         sub     dx,dx   ;start loading bytes at A000:0000
  73.         push    ds
  74.         mov     si,VGA_SEGMENT
  75.         mov     ds,si
  76.         int     21h     ;read the displayed portion of this plane
  77.         pop     ds
  78.         jc      ReadError               ;handle error, if any
  79.         cmp     ax,DISPLAYED_SCREEN_SIZE ;did all bytes get read?
  80.         jz      RestoreLoopBottom       ;yes, no error
  81. ReadError:                      ;an error occurred
  82.         mov     ah,9            ;DOS print string function
  83.         mov     dx,offset ErrMsg2
  84.         int     21h             ;notify about the error
  85.         jmp     short DoClose   ;and done
  86. RestoreLoopBottom:
  87.         mov     al,[Plane]
  88.         inc     ax      ;point to the next plane
  89.         mov     [Plane],al
  90.         cmp     al,3    ;have we done all planes?
  91.         jbe     RestoreLoop ;no, so do the next plane
  92. ;
  93. ; Close SNAPSHOT.SCR.
  94. ;
  95. DoClose:
  96.         mov     ah,3eh  ;DOS close file function
  97.         mov     bx,[Handle]
  98.         int     21h
  99. ;
  100. ; Wait for a keypress.
  101. ;
  102.         mov     ah,8    ;DOS input without echo function
  103.         int     21h
  104. ;
  105. ; Restore text mode.
  106. ;
  107.         mov     ax,3
  108.         int     10h
  109. ;
  110. ; Done.
  111. ;
  112. Done:
  113.         mov     ah,4ch  ;DOS terminate function
  114.         int     21h
  115. Start   endp
  116. Code    ends
  117.         end     Start