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

  1. ; Program to put up a mode 10h EGA graphics screen, then save it
  2. ; to the file SNAPSHOT.SCR.
  3. ;
  4. ; Updated 6/29/89.
  5. ;
  6. VGA_SEGMENT     equ     0a000h
  7. GC_INDEX        equ     3ceh    ;Graphics Controller Index register
  8. READ_MAP        equ     4       ;Read Map register index in GC
  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. SampleText db   'This is bit-mapped text, drawn in hi-res '
  19.         db      'EGA graphics mode 10h.', 0dh, 0ah, 0ah
  20.         db      'Saving the screen (including this text)...'
  21.         db      0dh, 0ah, '$'
  22. Filename db     'SNAPSHOT.SCR',0        ;name of file we're saving to
  23. ErrMsg1 db      '*** Couldn''t open SNAPSHOT.SCR ***',0dh,0ah,'$'
  24. ErrMsg2 db      '*** Error writing to SNAPSHOT.SCR ***',0dh,0ah,'$'
  25. WaitKeyMsg db   0dh, 0ah, 'Done. Press any key to end...',0dh,0ah,'$'
  26. Handle  dw      ?       ;handle of file we're saving to
  27. Plane   db      ?       ;plane being read
  28. Data    ends
  29. ;
  30. Code    segment
  31.         assume  cs:Code, ds:Data
  32. Start   proc    near
  33.         mov     ax,Data
  34.         mov     ds,ax
  35. ;
  36. ; Go to hi-res graphics mode.
  37. ;
  38.         mov     ax,10h  ;AH = 0 means mode set, AL = 10h selects
  39.                         ; hi-res graphics mode
  40.         int     10h     ;BIOS video interrupt
  41. ;
  42. ; Put up some text, so the screen isn't empty.
  43. ;
  44.         mov     ah,9    ;DOS print string function
  45.         mov     dx,offset SampleText
  46.         int     21h
  47. ;
  48. ; Delete SNAPSHOT.SCR if it exists.
  49. ;
  50.         mov     ah,41h  ;DOS unlink file function
  51.         mov     dx,offset Filename
  52.         int     21h
  53. ;
  54. ; Create the file SNAPSHOT.SCR.
  55. ;
  56.         mov     ah,3ch  ;DOS create file function
  57.         mov     dx,offset Filename
  58.         sub     cx,cx           ;make it a normal file
  59.         int     21h
  60.         mov     [Handle],ax     ;save the handle
  61.         jnc     SaveTheScreen   ;we're ready to save if no error
  62.         mov     ah,9            ;DOS print string function
  63.         mov     dx,offset ErrMsg1
  64.         int     21h             ;notify of the error
  65.         jmp     short Done      ;and done
  66. ;
  67. ; Loop through the 4 planes, making each readable in turn and
  68. ; writing it to disk. Note that all 4 planes are readable at
  69. ; A000:0000; the Read Map register selects which plane is readable
  70. ; at any one time.
  71. ;
  72. SaveTheScreen:
  73.         mov     [Plane],0       ;start with plane 0
  74. SaveLoop:
  75.         mov     dx,GC_INDEX
  76.         mov     al,READ_MAP     ;set GC Index to Read Map register
  77.         out     dx,al
  78.         inc     dx
  79.         mov     al,[Plane]      ;get the # of the plane we want
  80.                                 ; to save
  81.         out     dx,al   ;set to read from the desired plane
  82.         mov     ah,40h  ;DOS write to file function
  83.         mov     bx,[Handle]
  84.         mov     cx,DISPLAYED_SCREEN_SIZE ;# of bytes to save
  85.         sub     dx,dx   ;write all displayed bytes at A000:0000
  86.         push    ds
  87.         mov     si,VGA_SEGMENT
  88.         mov     ds,si
  89.         int     21h     ;write the displayed portion of this plane
  90.         pop     ds
  91.         jc      WriteError      ;handle write error, if any
  92.         cmp     ax,DISPLAYED_SCREEN_SIZE ;did all bytes get written?
  93.         jz      SaveLoopBottom  ;yes, no error
  94. WriteError:                     ;a error occurred while writing
  95.         mov     ah,9            ;DOS print string function
  96.         mov     dx,offset ErrMsg2
  97.         int     21h             ;notify about the error
  98.         jmp     short DoClose   ;and done
  99. SaveLoopBottom:
  100.         mov     al,[Plane]
  101.         inc     ax      ;point to the next plane
  102.         mov     [Plane],al
  103.         cmp     al,3    ;have we done all planes?
  104.         jbe     SaveLoop ;no, so do the next plane
  105. ;
  106. ; Close SNAPSHOT.SCR.
  107. ;
  108. DoClose:
  109.         mov     ah,3eh  ;DOS close file function
  110.         mov     bx,[Handle]
  111.         int     21h
  112. ;
  113. ; Wait for a keypress.
  114. ;
  115.         mov     ah,9    ;DOS print string function
  116.         mov     dx,offset WaitKeyMsg
  117.         int     21h     ;prompt
  118.         mov     ah,8    ;DOS input without echo function
  119.         int     21h
  120. ;
  121. ; Restore text mode.
  122. ;
  123.         mov     ax,3
  124.         int     10h
  125. ;
  126. ; Done.
  127. ;
  128. Done:
  129.         mov     ah,4ch  ;DOS terminate function
  130.         int     21h
  131. Start   endp
  132. Code    ends
  133.         end     Start