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

  1. ;copy.asm
  2. ;====================================
  3. ; Command:  copy source destination
  4. ;====================================
  5.                                   
  6. index1      = $0024               
  7. maxmem      = $0039               
  8. status      = $0090               
  9. sa          = $00b9               
  10. dv          = $00ba               
  11. int08       = $1708               
  12. int09       = $1709               
  13. int0e       = $170e               
  14. primm       = $ff7d               
  15. tksa        = $ff96               
  16. second      = $ff93               
  17. talk        = $ffb4               
  18. listen      = $ffb1               
  19. acptr       = $ffa5               
  20. untlk       = $ffab               
  21. unlsn       = $ffae               
  22. close       = $ffc3               
  23. clrchn      = $ffcc               
  24. chrin       = $ffcf               
  25. chrout      = $ffd2               
  26. chkin       = $ffc6               
  27. chkout      = $ffc9               
  28.                                   
  29. star        = $0b00               
  30.             .wor star             
  31.             * = star              
  32.  
  33.             jmp imove
  34.             dw Date
  35.                       
  36. imove       lda #"p"              ;open source file for read...try PRG first
  37.             sta srctyp            
  38.             ldx #1                
  39.             jsr int08             
  40.             bcc im0               ;open went ok
  41.             cmp #64               ;file type mismatch?
  42.             bne im1               ;no...exit
  43.             txa                   
  44.             jsr close             ;close it and try again
  45.             ldx #1                
  46.             lda #"s"              ;maybe it wasn't PRG, try SEQ
  47.             sta srctyp            
  48.             jsr int08             
  49.             bcc im0               ;ok
  50. im1         jsr primm             
  51.             .asc 13,"Syntax: copy s:name d:name",13
  52.             .byt 0                
  53.             jmp int0e             
  54.                                   
  55. im0         stx srcla             
  56.             lda srctyp            ;now open destination file
  57.             ldx #2                
  58.             jsr int09             
  59.             bcs im1               ;error...abort
  60.             stx desla             
  61. move        lda #0                
  62.             sta stat              ;st=0
  63.             jsr getbuf            ;move to buffer
  64.             jsr putbuf            ;buffer to destination
  65.             bit stat              
  66.             bmi movx              
  67.             bvc move              ;end if eof
  68. movx        jmp int0e             
  69.                                   
  70. desla       .byt 0                
  71. srcla       .byt 0                
  72. srctyp      .byt 0                
  73. buflen      .wor 0                
  74. stat        .byt 0                
  75.                                   
  76. getbuf      jsr resbuf            ;point to start of buffer
  77.             sty buflen            
  78.             sty buflen+1          
  79.             sty status            
  80.             ldx srcla             
  81.             jsr chkin             
  82. gb          jsr chrin             
  83.             sta $ff02             
  84.             ldy #0                
  85.             sta (index1),y        
  86.             sty $ff00             
  87.             jsr bindex            
  88.             inc buflen            
  89.             bne gb1               
  90.             inc buflen+1          
  91. gb1         bit status            
  92.             bmi gb2               
  93.             bvs gb2               
  94.             lda index1+1          
  95.             cmp maxmem+1          
  96.             bcc gb                
  97.             lda index1            
  98.             cmp maxmem            
  99.             bcc gb                
  100. gb2         lda status            
  101.             sta stat              
  102.             jmp clrchn            
  103.                                   
  104. putbuf      jsr resbuf            
  105.             ldx desla             
  106.             jsr chkout            
  107. pb0         lda buflen            
  108.             ora buflen+1          
  109.             bne pb                
  110.             jmp clrchn            
  111.                                   
  112. pb          sta $ff02             
  113.             ldy #0                
  114.             lda (index1),y        
  115.             sty $ff00             
  116.             jsr chrout            
  117.             jsr bindex            
  118.             lda buflen            
  119.             bne pb1               
  120.             dec buflen+1          
  121. pb1         dec buflen            
  122.             jmp pb0               
  123.                                   
  124. resbuf      lda #<$4000           
  125.             sta index1            
  126.             lda #>$4000           
  127.             sta index1+1          
  128.             ldy #0                
  129.             rts                   
  130.                                   
  131. bindex      inc index1            
  132.             bne bix               
  133.             inc index1+1          
  134. bix         rts                   
  135.                                   
  136.             .end                  
  137.