home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / examples.arc / PUTRAM.A < prev    next >
Text File  |  1989-12-01  |  8KB  |  217 lines

  1. ; putram.asm
  2. ;====================================
  3. ; Command: Save RAM disk to floppy
  4. ;====================================
  5.                                   
  6. zrimg       = $0060               
  7. z128        = $0061               
  8. zrda        = $0063               
  9. zxfer       = $0066               
  10.  
  11. poker       = $0016               
  12. index1      = $0024               
  13. index2      = $0026               
  14. fetvec      = $02aa               
  15. fetch       = $02a2               
  16. int04       = $1704               
  17. int05       = $1705               
  18. int09       = $1709               
  19. int0c       = $170c               
  20. int0d       = $170d               
  21. int0e       = $170e               
  22. int13       = $1713               
  23. int21       = $1721               
  24. rflag       = $1bf0               
  25. primm       = $ff7d               
  26. chrout      = $ffd2               
  27. chkout      = $ffc9               
  28. clrchn      = $ffcc               
  29. rdmax       = $1bf1               
  30. rdadr       = $1bf5               
  31. rdbnk       = $1bf3               
  32. tx          = $1bfe               
  33. getcfg      = $ff6b               
  34.                                   
  35.  
  36. star        = $0b00               
  37.             .wor  star
  38.             * = star              
  39.  
  40.             jmp Putram
  41.             dw  Date
  42.                      
  43. Putram      bit tx                  ; Make sure RAM disk is there
  44.             bvs putram              ; It is
  45.             jsr primm             
  46.             .asc  "RAM disk isn't installed.",13,0
  47.             lda #1                
  48.             jmp int0e             
  49.                                   
  50. putram      jsr chkram              ; Setup
  51.             ldx #1                  ; Scratch the output file
  52.             jsr int13             
  53.             ldx #1                  ; filename is %1
  54.             lda #"p"                ; save as PRG file
  55.             jsr int09             
  56.             bcc opnok               ; open went ok
  57. dskerr      jsr clrchn              ; disk error. display ds$ and quit
  58.             jsr int0d             
  59.             lda #2                
  60.             jmp int0e               ; all done
  61.                                   
  62. opnok       jsr chkout              ; get ready for output
  63.             bcs dskerr            
  64.             lda #0                  ; write a phony load address
  65.             jsr chrout            
  66.             lda #$a0              
  67.             jsr chrout            
  68. wrtlp       jsr fetblk              ; fetch RAM disk block
  69.             jsr wrtblk              ; write it to disk
  70.             bcc wrtlp               ; still more
  71.             lda #0                
  72.             jsr chrout            
  73.             lda #0                
  74.             jsr chrout            
  75.             jsr clrchn            
  76.             jsr primm             
  77.             .asc  "RAM disk saved as ", 0
  78.             ldx #1                
  79.             jsr int04             
  80. more        jsr chrout            
  81.             jsr int05             
  82.             bcc more              
  83.             lda #13               
  84.             jsr chrout            
  85.             lda #0                
  86.             jmp int0e             
  87.                                   
  88. ;-------------------------------------
  89. ; Subroutine: Setup RAM disk for read
  90. ;-------------------------------------
  91. ; SEC = error, CLC = disk seems ok so far
  92.                                   
  93. chkram      ldy #4                  ; Initialize, seek to start of RAM disk
  94.             jsr int21             
  95.             ldy #5                  ; Move ahead to first name
  96.             jsr int21             
  97.             bne cr0                 ; Found one
  98.             jsr primm
  99.             .asc  "RAM disk is empty. Why save it?",13,0
  100.             lda #1
  101.             jmp int0e             
  102.                                   
  103. cr0         ldy #9                  ; save REC image for move
  104. rmi0        lda zrimg,y           
  105.             sta source,y          
  106.             dey                   
  107.             bpl rmi0              
  108.             ldy #8                  ; seek to end of RAM disk
  109.             jsr int21             
  110.             bcc rmi1              
  111. rmi3        jsr primm             
  112.             .asc  "Error reading RAM disk.",13,0
  113.             lda #4                
  114.             jmp int0e             
  115.                                   
  116. rmi1        clc                   
  117.             lda zrda                ; +2 to get true size
  118.             adc #2                
  119.             sta zrda              
  120.             bcc mri1              
  121.             inc zrda+1            
  122.             bne mri1              
  123.             inc zrda+2            
  124. mri1        bit rflag               ; in RAM or 1750?
  125.             bmi in1750            
  126.             lda source+3            ; in RAM we need zero page
  127.             sta rdorg
  128.             lda source+4          
  129.             sta rdorg+1
  130. in1750      lda #<buf               ; setup buffer address
  131.             sta source+1          
  132.             lda #>buf
  133.             sta source+2          
  134.             lda #<256             
  135.             sta source+6          
  136.             lda #>256             
  137.             sta source+7          
  138.             rts                   
  139.                                   
  140. fetblk      sec                     ; if (end of disk)-source <256 then change xfer length
  141.             lda zrda                ;    to the difference
  142.             sbc source+3          
  143.             sta temp              
  144.             lda zrda+1            
  145.             sbc source+4          
  146.             sta temp+1            
  147.             lda zrda+2            
  148.             sbc source+5          
  149.             ora temp+1            
  150.             bne use256            
  151.             sta source+7            ; change blocksize for last block
  152.             lda temp              
  153.             sta source+6          
  154. use256      bit rflag             
  155.             bpl nt1750            
  156.             ldy #9                  ; fetch page
  157.             lda $d030             
  158.             pha                   
  159.             and #%11111110        
  160.             sta $d030             
  161. l1          lda source,y          
  162.             sta $df01,y           
  163.             dey                   
  164.             bpl l1                
  165. wait        bit $df00               ; wait for completion
  166.             bvc wait              
  167.             pla                   
  168.             sta $d030             
  169. l4          inc source+4
  170.             bne l3                
  171.             inc source+5          
  172. l3          rts                   
  173.                                   
  174. source      .wor  0,0,0,0,0
  175. temp        .wor  0
  176.                                   
  177. nt1750      lda rdorg
  178.             sta index1
  179.             lda rdorg+1
  180.             sta index1+1
  181.             lda #<index1
  182.             sta fetvec
  183.             ldy #0
  184. ntfl        ldx rdbnk+1           
  185.             jsr fetch             
  186.             sta buf,y
  187.             iny                   
  188.             bne ntfl
  189.             inc rdorg+1
  190.             jmp l4
  191.                                   
  192. wrtblk      ldy #0                
  193.             lda source+7          
  194.             bne doall             
  195.             ldy source+6          
  196.             beq none              
  197. doall       sty max               
  198.             ldy #0                
  199. wlp         lda buf,y
  200.             jsr chrout            
  201.             iny                   
  202.             cpy max               
  203.             bne wlp               
  204.             lda source+7          
  205.             bne more1             
  206. none        sec                   
  207.             .byt $24
  208. more1       clc                   
  209.             rts                   
  210.                                   
  211. max         .byt 0
  212.  
  213. rdorg       * = *+2
  214. buf         * = *+256
  215.                                   
  216.             .end                  
  217.