home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / px8util.lbr / SAVEVRAM.MZC / SAVEVRAM.MAC
Encoding:
Text File  |  1993-10-25  |  4.8 KB  |  189 lines

  1. ; SAVEVRAM.MAC
  2. ; program to try to grab contents of video RAM and store them
  3. ; in a file
  4. ; jbh, Feb 11, 1988, after the original Epson subroutine,
  5. ;  but using BIOS RDVRAM routine instead
  6.  
  7. ; John B. Haviland, 3312 SE Woodstock, Portland, OR 97202
  8.  
  9. ; USAGE NOTES:
  10. ;  The form is simply: >savevram filename
  11. ; where "filename" is the file where you want the screen contents to be filed
  12. ; THere are no further switches, and the program does not bother to check
  13. ; whether you are in screen mode 0,1,2 or not (it probably won't work in
  14. ; any mode but 0, I should think.)
  15. ;
  16. ; The program DOES check to see how many lines your virtual screen has in it,
  17. ; and it tries to capture them all.  It strips trailing blanks, and puts in
  18. ; standard CR-LF line terminators.  Because of the way the BIOS routine works,
  19. ; it can only capture data from the selected screen.
  20. ; (I use CONFIG to set up screen 1 on my PX8 to have 40 lines, limiting
  21. ; the other screen to only 8 lines, but allowing all 40 lines of screen 1 to
  22. ; be recovered to a file by SAVEVRAM.)
  23.  
  24. ; I thought of this as either a DO-able routine to make such things as
  25. ; FIND and various directory programs more useful (by allowing you to save
  26. ; at least some of their output to file), or as a possible add-on to RTX--
  27. ; but I haven't had the time to do the whole job.  I have combined it with
  28. ; the little NECRX program that captures files to the PX8 from a NEC PC8201a
  29.  
  30.     .z80
  31. ; CPM equates, and PX=8 stuff
  32. bios    equ    1    ;wmboot addr
  33. bdos    equ    5    ;BDOS function dispatch jump vector
  34. scrmode    equ    0f2c9h    ;current screen mode
  35. slvflg    equ    0f358h    ; slave comm. enable flag
  36. selscrn    equ    0f2CAh    ;0 or 1 depending on what screen is selected
  37. sc1lin    equ    0f720h    ;# of lines in screen 1 (mode 0)
  38. sc2lin    equ    0f726h    ;# of lines in screen 2
  39. ;
  40. ;
  41.     aseg
  42.     org    100h
  43. start:
  44.     call    calcrdv
  45.     call    create    ;set up file to save screen
  46.     cp    0ffh    ;is disk directory full?
  47.     jr    z,exit    ; if so, exit routine
  48. ; otherwise, the file is now open
  49. ; now check the screen selected and fill in the # of lines to read
  50.     ld    a,(selscrn)
  51.     ld    hl,sc1lin
  52.     or    a
  53.     jr    z,scr1
  54.     ld    hl,sc2lin
  55. scr1:
  56.     ld    a,(hl)
  57.     dec    a
  58.     ld    (lines),a    ;don't bother to save the last screen line
  59.                 ; since at best it just has this program on it
  60. ; now read the lines
  61.     xor    a    ;cheap zero for counters
  62. loop:
  63.     inc    a
  64.     ld    (count),a
  65.     call    readvram    ;get data block from VRAM
  66.     ld    a,(count)    ; increment block counter
  67.     cp    40        ; have we written the whole screen?
  68. lines    equ    $-1
  69.     jr    nz,loop        ; if not, go back and do it again
  70. ;
  71. ; now all screen is written to RAM,
  72. ; put in final ^Z
  73.     ld    hl,(nextadr)
  74.     ld    (hl),'Z'-40h
  75. ;now we need to write the file
  76.     call    wrfile
  77.     jp    0
  78. ; routine to wrte file from buffer to (nextadr)
  79. wrfile:
  80.     call    setdma
  81.     call    write
  82.     inc    a
  83.     jr    z,exit        ;if write fault, close the file and quit
  84. ; otherwise go on to next record
  85.     ld    de,128
  86.     ld    hl,(dmabuf)
  87.     add    hl,de
  88.     ld    (dmabuf),hl
  89.     ex    de,hl        ;de has top dma addr
  90.     ld    hl,(nextadr)
  91.     or    a
  92.     sbc    hl,de        ;see if dmabuf is above nextadr
  93.     jr    nc,wrfile
  94. ;otherwise the file is written
  95. exit:
  96. ;close the file
  97.     call    close
  98.     jp    0        ;return to cpm
  99. ;
  100. ;subroutine to read VRAM in  a block of 80 bytes
  101.  
  102. readvram:
  103.     ld    a,(count)    ;line number of data to be read
  104.     ld    c,a        ; C holds line at start of read
  105.     ld    b,1        ;always start at left edge of screen
  106.     ld    de,80        ;read 80 chars
  107.     ld    hl,(nextadr)    ;HL holds address for read
  108. rdv:
  109.     call    rdv        ; call readvram routine
  110. ;now back up to last non-blank, and put in crlf
  111.     ld    hl,(nextadr)
  112.     ld    de,80
  113.     add    hl,de
  114. srchlp:    dec    hl
  115.     ld    a,(hl)
  116.     cp    ' '
  117.     jr    z,srchlp
  118. ; if we get here hl points to last non-blank on latest line
  119.     inc    hl
  120.  
  121. ;  subroutine to fix add crlf at end of line
  122. docrlf:    ld    (hl),CR
  123.     inc    hl
  124.     ld    (hl),LF
  125.     inc    hl
  126.     ld    (nextadr),hl
  127.     ret
  128. ;
  129. CR    equ    'M'-40h
  130. LF    equ    'J'-40h
  131. ;
  132. ; calculate and set proper rdv address
  133. calcrdv:
  134.     ld    hl,(bios)
  135.     ld    a,75h
  136.     add    a,l
  137.     ld    l,a
  138.     ld    (rdv+1),hl
  139.     ret
  140. ;
  141. ; subroutine to create data file
  142. create:
  143.     xor    a
  144.     ld    (fcbadr+12),a    ;zero first FCB byte for safety
  145.     ld    hl,fcbadr+12
  146.     ld    de,fcbadr+13
  147.     ld    bc,25
  148.     ldir            ;and zero rest of FCB, too
  149.     ld    c,13        ;reset disks BDOS function
  150.     call    bdos
  151. ;    call    setdma
  152.     call    delete        ;wipe out any preexisting file
  153.     ld    c,22
  154. file:    ld    de,fcbadr    ;set up new FCB address
  155. file2:    call    bdos        ;try to create
  156.     ret            ; calling routine must deal with errors
  157. ; set DMA
  158. setdma:
  159.     ld    c,26
  160.     ld    hl,(dmabuf)
  161.     ex    de,hl
  162.     jr    file2
  163. ;
  164. dmabuf:    defw    buffer
  165. ;
  166. ; write subroutine for each block
  167. write:
  168.     ld    c,21
  169.     jr    file
  170. ; close subroutine
  171. close:
  172.     ld    c,16
  173.     jr    file
  174. ;
  175. erase:    call    close
  176. delete:    ld    c,19
  177.     jr    file
  178. ;
  179. ; data storage area for all variables
  180.  
  181. fcbadr    equ    5ch        ; default FCB from CPM
  182. count:    db    0        ;block counter
  183. nextadr:
  184.     defw    buffer
  185. crlf:    db    CR,LF
  186. buffer    equ    $        ;this will be the buffer for the file
  187.  
  188.     end    start
  189.