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

  1. ;move.asm
  2. ;==============================================================
  3. ; Command:  move patternlist [d:]
  4. ;==============================================================
  5. ; Purpose:  MOVE copies files between two separate disk drives.
  6. ;           No provision is made for single drive users.
  7. ;           MOVE cannot copy RELative files.
  8.                                   
  9. index1      = $0024               ;zero page pointer
  10. strend      = $0033               ;pointer to start of bank 1 buffer
  11. fretop      = $0035               ;pointer to end+1 of bank 1 buffer
  12. status      = $0090               
  13. sa          = $00b9               
  14. dv          = $00ba               
  15. pntr        = $00ec               
  16. int01       = $1701               
  17. int04       = $1704               
  18. int05       = $1705               
  19. int08       = $1708               
  20. int09       = $1709               
  21. int0a       = $170a               
  22. int0c       = $170c               
  23. int0d       = $170d               
  24. int16       = $1716               
  25. int17       = $1717               
  26. int0e       = $170e               
  27. primm       = $ff7d               
  28. tksa        = $ff96               
  29. second      = $ff93               
  30. talk        = $ffb4               
  31. listen      = $ffb1               
  32. acptr       = $ffa5               
  33. untlk       = $ffab               
  34. unlsn       = $ffae               
  35. close       = $ffc3               
  36. open        = $ffc0               
  37. setlfs      = $ffba               
  38. setnam      = $ffbd               
  39. clrchn      = $ffcc               
  40. chrin       = $ffcf               
  41. chrout      = $ffd2               
  42. chkin       = $ffc6               
  43. chkout      = $ffc9               
  44.                                   
  45. cl          = $1bf7               ;drive letter accessed by int16
  46.                                   
  47. star        = $0b00               
  48.             .wor star             
  49.             * = star              
  50.  
  51.             jmp move
  52.             dw  Date
  53.                   
  54. move        jsr getdes            ;get destination drive
  55.             ldx #1                ;for parameter=1 to highest one
  56.             stx parm              
  57. imov        jsr int16             ;get 1st match
  58.             lda cl                ;save the source drive letter
  59.             sta cll               
  60.             bcs nxtprm            ;no matches
  61. agin        jsr copy              ;copy this file
  62.             jsr int17             ;any more for this pattern
  63.             bcc agin              ;yes
  64. nxtprm      inc parm              ;no...move on to the next one
  65.             ldx parm              
  66.             cpx hiparm            
  67.             bcc imov              ;until no more parameters
  68.             beq imov              
  69.             lda #0                ;all went as expected...return errorlevel zero
  70.             jmp int0e             
  71.                                   
  72. ;----------------------------
  73. ; Subroutine: Main COPY loop
  74. ;----------------------------
  75.                                   
  76. doit        lda #0                ;st=0
  77.             sta stat              
  78.             jsr getbuf            ;fill  buffer from source file
  79.             jsr putbuf            ;flush buffer to destination file
  80.             bit stat              ;EOF?
  81.             bmi movx              ;No..error
  82.             bvc doit              ;still more
  83. movx        lda srcla             ;done...close source
  84.             jsr close             
  85.             lda desla             ;and destination
  86.             jsr close             
  87.             jsr int0c             
  88.             jmp int0d             ;Display DS$ and return
  89.                                   
  90. ;------------------------------------------
  91. ; Subroutine: Fill buffer from source file
  92. ;------------------------------------------
  93.                                   
  94. getbuf      jsr resbuf            ;point to start of buffer
  95.             sty buflen            ;zero # of bytes read
  96.             sty buflen+1          
  97.             sty status            
  98.             ldx srcla             
  99.             jsr chkin             
  100. gb          jsr chrin             ;get char
  101.             sta $ff02             ;put in bank 1
  102.             ldy #0                
  103.             sta (index1),y        
  104.             sty $ff00             
  105.             jsr bindex            ;adjust pointer,length
  106.             inc buflen            
  107.             bne gb1               
  108.             inc buflen+1          
  109. gb1         bit status            ;still more?
  110.             bmi gb2               ;error
  111.             bvs gb2               ;EOF
  112.             lda index1+1          ;buffer full?
  113.             cmp fretop+1          
  114.             bne gb                ;no
  115.             lda index1            
  116.             cmp fretop            
  117.             bne gb                
  118. gb2         lda status            ;save ST and RTS
  119.             sta stat              
  120.             jmp clrchn            
  121.                                   
  122. ;-----------------------------------------
  123. ; Subroutine: Flush buffer to output file
  124. ;-----------------------------------------
  125.                                   
  126. putbuf      jsr resbuf            ;reset buffer pointer
  127.             ldx desla             
  128.             jsr chkout            
  129. pb0         lda buflen            ;all done?
  130.             ora buflen+1          
  131.             bne pb                ;no..still more
  132.             jmp clrchn            
  133.                                   
  134. pb          sta $ff02             ;fetch from bank 1
  135.             ldy #0                
  136.             lda (index1),y        
  137.             sty $ff00             
  138.             jsr chrout            ;write it
  139.             jsr bindex            ;adjust pointer,length
  140.             lda buflen            
  141.             bne pb1               
  142.             dec buflen+1          
  143. pb1         dec buflen            
  144.             jmp pb0               ;and loop for more
  145.                                   
  146. resbuf      lda strend            ;reset buffer pointer to start
  147.             sta index1            
  148.             lda strend+1          
  149.             sta index1+1          
  150.             ldy #0                
  151.             rts                   
  152.                                   
  153. bindex      inc index1            ;bump buffer pointer
  154.             bne bix               
  155.             inc index1+1          
  156. bix         rts                   
  157.                                   
  158. ;--------------------------------------------------------------------
  159. ; Subroutine: Fetch destination drive (highest parameter or default)
  160. ;--------------------------------------------------------------------
  161.                                   
  162. getdes      ldx #21               ;for x=21 to 0 step -1
  163. gd1         jsr int04             ;    if parameter(x) is defined use it
  164.             bcc gd0               ;otherwise next x
  165.             dex                   
  166.             bne gd1               
  167. gd0         cpx #0                ;just move?
  168.             bne gd2               ;no
  169.             jsr primm             
  170.             .asc 13,"Syntax:  move patternlist d:",13
  171.             .asc 13,"Purpose: copies files from one drive to another",13, 0
  172.             lda #1                
  173.             jmp int0e             
  174.                                   
  175. gd2         stx hiparm            ;save highest parameter number
  176.             sta name              ;and destination drive letter assuming its ok
  177.             jsr int05             ;check if it was d:
  178.             bcs gd9               ;no...it was just one character, use default drive
  179.             cmp #":"              
  180.             bne gd9               ;wasn't d:
  181.             sta name+1            
  182.             jsr int05             ;any more chars?
  183.             bcc gd9               ;yes, then its not d:
  184.             dec hiparm            ;it was d:, adjust last parameter to move
  185.             rts                   
  186.                                   
  187. gd9         jsr int01             ;use default drive
  188.             sta name              
  189.             lda #":"              
  190.             sta name+1            
  191.             rts                   
  192.                                   
  193. spur        .asc "dspu"           
  194.                                   
  195. cntcpy      jsr primm             
  196.             .asc " Can't copy",13, 0
  197.             rts                   
  198.                                   
  199. ;-------------------------------------------------------------
  200. ; Subroutine: Setup filenames, open them and check for errors
  201. ;-------------------------------------------------------------
  202.                                   
  203. copy        lda cll               ;append s: to source filename
  204.             sta $1b01             
  205.             lda #":"              
  206.             sta $1b02             
  207.             ldy #0                
  208. cp0         lda $1b03,y           ;int16/17 puts filename here
  209.             cmp #$a0              ;end of name?
  210.             beq cp1               ;yep
  211.             sta name+2,y          ;copy name to destination name
  212.             jsr chrout            ;and echo to screen
  213.             iny                   
  214.             cpy #16               
  215.             bcc cp0               
  216. cp1         lda #","              ;tag on ',type,w' to destination
  217.             sta name+2,y          ;and    ',type,r' to source
  218.             sta $1b03,y           
  219.             iny                   
  220.             jsr tab               ;tab(22)
  221.             lda $1b00             ;filetype from directory ($81=SEQ etc.)
  222.             and #7                
  223.             cmp #0                ;deleted?
  224.             beq cntcpy            ;if so, then can't copy
  225.             cmp #4                ;is it P,S or U?
  226.             bcs cntcpy            ;if not, can't copy
  227.             tax                   ;translate to ASCII
  228.             lda spur,x            
  229.             sta name+2,y          
  230.             sta $1b03,y           
  231.             iny                   
  232.             lda #","              
  233.             sta name+2,y          
  234.             sta $1b03,y           
  235.             iny                   
  236.             lda #"r"              
  237.             sta $1b03,y           
  238.             lda #"w"              
  239.             sta name+2,y          
  240.             iny                   
  241.             iny                   
  242.             iny                   
  243.             sty fnl               
  244.             tya                   
  245.             ldx #<$1b01           ;open source
  246.             ldy #>$1b01           
  247.             jsr setnam            
  248.             jsr int0a             
  249.             sta srcla             
  250.             jsr setlfs            
  251.             jsr open              
  252.             jsr int0c             ;check DS
  253.             cmp #0                
  254.             beq cp2               ;ok, go on
  255.             lda #" "              ;otherwise just print DS$
  256.             jsr chrout            
  257.             jsr int0d             
  258.             lda srcla             ;next file
  259.             jmp close             
  260.                                   
  261. cp2         lda fnl               ;open destination
  262.             ldx #<name            
  263.             ldy #>name            
  264.             jsr setnam            
  265.             jsr int0a             
  266.             ldy #1                
  267.             sta desla             
  268.             jsr setlfs            
  269.             jsr open              
  270.             jsr int0c             ;check DS
  271.             cmp #0                
  272.             beq cp4               ;OK, go on
  273.             lda #" "              ;else just print ds$
  274.             jsr chrout            
  275.             jsr int0d             
  276.             lda desla             ;next file
  277.             jmp close             
  278.                                   
  279. cp4         jmp doit              ;goto main copy loop & return from there
  280.                                   
  281. ;---------------------
  282. ; Subroutine: TAB(22)
  283. ;---------------------
  284.                                   
  285. tab         pha                   
  286.             tya                   
  287.             pha                   
  288.             txa                   
  289.             pha                   
  290. tabb        lda #" "              
  291.             jsr chrout            
  292.             lda pntr              
  293.             cmp #22               
  294.             bcc tabb              
  295.             pla                   
  296.             tax                   
  297.             pla                   
  298.             tay                   
  299.             pla                   
  300.             rts                   
  301.                                   
  302. ;------------------------
  303. ; Un-Initialized storage
  304. ;------------------------
  305.                                   
  306. parm        *=*+1                 ;parameter number (for/next index)
  307. hiparm      *=*+1                 ;highest parameter to move
  308. cll         *=*+1                 ;source drive letter
  309. fnl         *=*+1                 ;destination filename length
  310. name        *=*+32                ;destination filename
  311. desla       *=*+1                 ;save destination la
  312. srcla       *=*+1                 ;save source la
  313. srctyp      *=*+1                 ;source filetype
  314. buflen      *=*+2                 ;number of bytes read into the buffer
  315. stat        *=*+1                 ;save ST here when input buffer is full or EOF
  316.  
  317.             .end                  
  318.