home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / ZCAT / MOVE12.LBR / MOVE12.ZQ0 / MOVE12.Z80
Text File  |  2000-06-30  |  10KB  |  405 lines

  1. ;
  2. ; program: move
  3. ; author:  dennis wright
  4. ; version:  1.1
  5. ; date: 11 oct 85
  6. ;
  7. vers    equ    12
  8. ;
  9. ; version 1.2  -  Changed to warm boot only if directory written. dlw
  10. ;
  11. ; version 1.1    - Fixed bug in file name compare routine. dlw
  12. ;
  13. ; version 1.0    - release
  14. ;
  15. MONTH    EQU    9
  16. DAY    EQU    8
  17. YEAR    EQU    85
  18. ;
  19. ; Based on public domain program mov2usr by R.E.D
  20. ;
  21. DOS    EQU    0005H        ; Dos entry address
  22. BUFFER    EQU    80H        ; Default cp/m buffer
  23. FCB    EQU    5CH        ; Default cp/m fcb
  24. FCB2    EQU    6CH
  25. USR1    EQU    FCB+13        ; Fcb1 user
  26. USR2    EQU    FCB2+13        ; Fcb2 user
  27. GSUSER    EQU    32        ; Set/get user code
  28. CR    EQU    0DH
  29. LF    EQU    0AH
  30. ;
  31. Z3ENV    SET    0E200H
  32. ;
  33.     EXT    Z3VINIT,TINIT
  34.     EXT    DUTDIR
  35.     EXT    COUT,CRLF,BIOS
  36. ;
  37. ; environment definition
  38. ;
  39.      IF    Z3ENV NE 0
  40. ;
  41. ; external zcpr3 environment descriptor
  42. ;
  43.     JP    START
  44.     DB    'Z3ENV'        ; This is a zcpr3 utility
  45.     DB    1        ; External environment descriptor
  46. Z3EADR:
  47.     DW    Z3ENV
  48. START:
  49.     LD    HL,(Z3EADR)    ; Pt to zcpr3 environment
  50. ;
  51.      ELSE
  52. ;
  53. ; internal zcpr3 environment descriptor
  54. ;
  55.     MACLIB    Z3BASE.LIB
  56.     MACLIB    SYSENV.LIB
  57. Z3EADR:
  58.     JP    START
  59.     SYSENV
  60. START:
  61.     LD    HL,Z3EADR    ; Pt to zcpr3 environment
  62.      ENDIF
  63. ;
  64. ; start of program -- initialize zcpr3 environment
  65. ;
  66.     CALL    Z3VINIT        ; Initialize the zcpr3 env
  67.     CALL    TINIT        ; Initialize the terminal
  68.     ld    hl,0
  69.     add    hl,sp
  70.     ld    (oldstk),hl
  71.     ld    hl,stack
  72.     ld    sp,hl
  73.     LD    E,0FFH        ; Get current user number
  74.     LD    C,GSUSER
  75.     CALL    DOS
  76.     LD    (CURUSR),A    ; Save it
  77.     LD    A,(USR1)    ; Get requested source user number
  78.     LD    E,A        ; And log in to it.
  79.     LD    C,GSUSER
  80.     CALL    DOS
  81.         LD    A,(FCB+1)
  82.     CP    '/'
  83.     JP    Z,HELP
  84.     CP    ' '
  85.     JP    NZ,GOTNAM
  86. HELP:    LD    DE,USAGE
  87.     JP    PRNRET
  88. ;
  89. CPMRET:    LD    A,(FOUND1)
  90.     OR    A
  91.     JP    NZ,GOT1
  92.     LD    DE,NOFILE
  93. PRNRET:    CALL    PRNTLIN
  94. GOT1:    LD    A,(CURUSR)    ; Log back into original user area.
  95.     LD    E,A
  96.     LD    C,GSUSER
  97.     CALL    DOS
  98.     ld    a,(dirwrt)
  99.     or    a
  100.     JP    nz,0
  101.     ld    hl,(oldstk)
  102.     ld    sp,hl
  103.     ret
  104. ;
  105. GOTNAM:    LD    HL,BUFFER
  106.     INC    HL
  107. BUFLP:    INC    HL
  108.     LD    A,(HL)
  109.     CP    0
  110.     JP    NZ,BUFLP
  111.     DEC    HL
  112.     LD    A,(HL)
  113.     CP    ':'
  114.     LD    DE,NOUSR
  115.     JP    NZ,PRNRET
  116.     LD    A,(USR2)
  117.     LD    (USERNO),A
  118.     LD    A,(FCB)        ; Get fcb drive number (1st byte)
  119.     CP    0        ; Check for default drive (0)
  120.     JP    Z,DEFAULT    ; Jump if default else subtract 1
  121.     SBC    01        ; To convert into dos usable
  122.                 ; Drive  number a=0,b=1,c=2
  123.     LD    (DRVNO),A    ; Save drive number for later
  124.     JP    RDONLY
  125. DEFAULT:LD    C,19H        ; Dos get drive number function
  126.     CALL    DOS        ; Get drive number
  127.     LD    (DRVNO),A    ; Save the actual drive number
  128. ;
  129. ; check drive for read only status - do this before selecting
  130. ; drive because selection will void r/o status
  131. ;
  132. RDONLY:    LD    A,(FCB2)
  133.     CP    0
  134.     JP    Z,DFLT
  135.     SBC    01
  136.     JP    CHKDRV
  137. ;
  138. DFLT:    LD    C,19H
  139.     CALL    DOS
  140. CHKDRV:    LD    HL,DRVNO
  141.     CP    (HL)
  142.     LD    DE,DIRMSG
  143.     JP    NZ,PRNRET
  144.     LD    A,(USR1)
  145.     LD    C,A
  146.     LD    A,(USR2)
  147.     CP    C
  148.     LD    DE,SAMUSR
  149.     JP    Z,PRNRET
  150.     CP    16
  151.     LD    DE,USRMSG
  152.     JP    NC,PRNRET
  153.     LD    C,1DH        ; Dos r/o vector function
  154.     CALL    DOS        ; Do it
  155.     LD    A,(DRVNO)    ; Get the drive number back
  156.     ADD    02        ; Increment count to
  157.                 ; Rotate vector bit to carry
  158.     LD    C,A        ; Set up rotate
  159. SHIFT:    DEC    C        ; Check for end
  160.     JP    Z,CHECK        ; Check carry if finished
  161.     LD    H,A        ; Else get first byte
  162.     OR    A        ; Clear carry
  163.     RRA            ; Shift it
  164.     LD    H,A        ; And put it back
  165.     LD    A,L        ; Get next byte
  166.     RRA            ; Shift it
  167.     LD    L,A        ; Put it back
  168.     JP    SHIFT        ; Loop for more
  169. ;
  170. CHECK:    JP    C,ROERR        ; Jump if carry set
  171.     LD    A,(DRVNO)    ; Get drive number
  172.     LD    E,A        ; Set up for dos call, move Drive number to E
  173.     LD    C,0EH        ; Dos select disk function
  174.     CALL    DOS
  175.     LD    DE,AMBFIL    ; Point to match any filename.typ
  176.     LD    C,11H        ; Dos search first function
  177.     CALL    DOS        ; Do it
  178.     LD    (DIRCODE),A    ; Save directory code
  179.     CP    0FFH        ; See if end of entries
  180.     JP    Z,CPMRET    ; Return if end
  181. ;
  182. ;          main program function loop
  183. ;
  184. LOOP:    LD    A,(DIRCODE)    ; Get the directory code
  185.     ADD    A,A        ; Offset by 32 bytes per entry
  186.     ADD    A,A
  187.     ADD    A,A
  188.     ADD    A,A
  189.     ADD    A,A
  190.     LD    E,A        ; Prepare for offset computation
  191.     LD    D,00        ; Clear high byte
  192.     LD    HL,BUFFER    ; Get buffer address
  193.     ADD    HL,DE        ; Compute offset into buffer
  194.     LD    (DBOFF),HL    ; Save the address into the buffer
  195.     EX    DE,HL        ; Swap
  196.     LD    A,(DE)        ; Get the dr byte for this entry
  197.     CP    0E5H        ; See if erased
  198.     JP    Z,INDIRCD    ; Jump to do next entry if erased
  199.     LD    HL,USERNO    ; Point to user number
  200.     CP    (HL)        ; See if old and new user number are same
  201.     JP    Z,INDIRCD    ; Jump to do next entry
  202.     LD    HL,USR1        ; See if directory entry user is same as
  203.     CP    (HL)        ; Specified user.
  204.     JP    NZ,INDIRCD
  205. ;
  206. COMPARE:LD    HL,FCB+1    ; Point to first character
  207.     LD    C,0BH        ; Load count for compare
  208.     EX    DE,HL        ; Swap
  209.      INC    HL        ; Incr past directory user number
  210. CP1:    LD    A,(DE)        ; Get fcb file character
  211.     CP    '?'        ; See if anything matches
  212.     JP    Z,MATCH        ; Jump past compare if '?'
  213.     SUB    (HL)        ; Compare thru subtraction
  214.     AND    7FH        ; Clear high (flag) bit
  215.     JP    NZ,INDIRCD    ; Quit if no match
  216. MATCH:    INC    DE        ; Point to next characters
  217.     INC    HL
  218.     DEC    C        ; Decrease count of characters
  219.     JP    NZ,CP1        ; Loop until zero
  220.     LD    A,(USERNO)    ; Get the new user number
  221.     LD    HL,(DBOFF)    ; Get buffer offset
  222.     LD    (HL),A        ; Put new user number in directory
  223.     LD    A,(WRTOK)    ; Get write flag
  224.     INC    A        ; Increase flag
  225.     LD    (WRTOK),A    ; Save updated flag
  226.     LD    HL,(DBOFF)    ; Address of file fcb
  227.     LD    DE,12        ; Offset to extent byte
  228.     ADD    HL,DE
  229.     LD    A,(HL)
  230.     OR    A        ; First extent?
  231.     JP    NZ,INDIRCD    ; Only want to print message once per file
  232.     LD    A,-1
  233.     LD    (FOUND1),A
  234.     CALL    CRLF
  235.     CALL    FILPRN        ; Print the file name
  236.     LD    DE,MV2MSG
  237.     CALL    PRNTLIN
  238.     LD    A,(DRVNO)
  239.     ADD    'A'
  240.     CALL    COUT
  241.     LD    A,(USERNO)    ; Get user number
  242.     CALL    PRTUSR
  243.     LD    A,':'
  244.     CALL    COUT
  245.     LD    A,(USERNO)
  246.     LD    C,A
  247.     LD    A,(DRVNO)
  248.     LD    B,A
  249.     CALL    DUTDIR
  250.     JP    Z,INDIRCD
  251.     LD    C,8
  252. DIRLP:    LD    A,(HL)
  253.     CP    ' '
  254.     JP    Z,INDIRCD
  255.     CALL    COUT
  256.     INC    HL
  257.     DEC    C
  258.     JP    NZ,DIRLP
  259. INDIRCD:LD    A,(DIRCODE)    ; Get the directory code
  260.     INC    A        ; Increase it one
  261.     LD    (DIRCODE),A    ; Save new key into buffer
  262.     CP    04        ; Only four entries in buffer
  263.     JP    Z,WRTBUF    ; Update buffer if last entry
  264.     JP    LOOP        ; Else look at remainder of buffer
  265. ;
  266. WRTBUF:    LD    A,(WRTOK)    ; Get write flag - anything greater
  267.                 ; Than zero means a change was made
  268.     CP    0        ; Check for change made
  269.     JP    Z,SRNXT        ; Jump if no changes made
  270.     CALL    WRTDE        ; Else write the buffer back to directory
  271.     XOR    A        ; Zero accum to clear writr flag
  272.     LD    (WRTOK),A    ; Save cleared flag
  273.     dec    a        ; Set directory written flag
  274.     ld    (dirwrt),a
  275. SRNXT:    LD    DE,AMBFIL    ; Point to any match fcb
  276.     LD    C,12H        ; Dos search next function
  277.     CALL    DOS        ; Do it
  278.     CP    0FFH        ; See if end of entries
  279.     JP    Z,CPMRET    ; And return if no more files
  280.     CP    0        ; Loop until buffer is updated by dos
  281.     JP    NZ,SRNXT    ; Jump until dircode is zero
  282.     LD    (DIRCODE),A    ; Save the 0 in dircode
  283.     JP    LOOP        ; And loop again
  284.     RET            ; End of main program
  285.  
  286. ;
  287. ; error messages
  288. ;
  289. ;
  290. ROERR:    LD    DE,ROMSG    ; Print disk r/o
  291.     JP    PRNRET        ; And end
  292. ;
  293. SECERR:    LD    DE,BADSEC    ; Print bios sector error
  294.     JP    PRNRET        ; And end
  295. ;
  296. ;
  297. PRNTLIN:LD    C,09H        ; Dos print string function
  298.     JP    DOS
  299. ;
  300. ;
  301. FILPRN:                ; Print filename
  302.     LD    A,(DRVNO)
  303.     ADD    'A'
  304.     CALL    COUT        ; Print drive letter
  305.     LD    E,0FFH
  306.     LD    C,32
  307.     CALL    DOS
  308.     CALL    PRTUSR        ; Print user number
  309.     LD    A,':'        ; Followed by ':'
  310.     CALL    COUT
  311.     LD    HL,(DBOFF)    ; Address of file fcb
  312.     LD    C,0CH        ; Filename.typ char count
  313.     INC    HL        ; Bypass first byte
  314. FP1:    PUSH    BC        ; Save count
  315.     LD    A,4        ; Check for period position
  316.     CP    C
  317.     JP    Z,PERIOD    ; Print period if time
  318.     LD    A,(HL)        ; Ignore blanks
  319.     CALL    COUT        ; Else print character
  320. FP2:    POP    BC        ; Get count
  321.     DEC    C        ; Dcr count
  322.     INC    HL        ; Point to next char
  323.     JP    NZ,FP1        ; Loop until zero
  324.     RET
  325. ;
  326. PERIOD:    LD    A,'.'        ; Print the period
  327.     CALL    COUT
  328.     POP    BC        ; Get count
  329.     DEC    C        ; Dcr count
  330.     JP    FP1
  331. ;
  332. WRTDE:    LD    DE,BUFFER    ; Set dma to buffer
  333.     LD    C,1AH        ; Dos setdma function
  334.     CALL    DOS
  335.     LD    C,1H        ; Set bios write to directory
  336.                 ; Write vice 0=write to allocated
  337.                 ; 2=write to unallocated
  338.     LD    A,14        ; Bios write
  339.     CALL      BIOS
  340.     OR    A        ; Check for error
  341.     JP    NZ,SECERR
  342.     LD    DE,BUFFER    ; Reset buffer address to buffer
  343.     LD    C,1AH        ; Dos setdma function
  344.     JP    DOS
  345. ;
  346. PRTUSR:    CP    09        ; See one or two digit user number
  347.     JP    NC,DOUBLE    ; Jump if two digits
  348. SINGLE:    ADD    30H        ; Else convert to ascii
  349.     CALL    COUT           ; And print it
  350.     RET
  351. ;
  352. DOUBLE:    ADD    26H        ; Subtract 9 to get first digit
  353.                 ; And add 30h to make ascii.
  354.                 ; Or just add 26h to do both...
  355.     PUSH    AF        ; Save this digit and print '1'
  356.     LD    A,'1'        ; Load the character
  357.     CALL    COUT           ; And print it
  358.     POP    AF        ; Get the remainder digit
  359.     CALL    COUT           ; And print it
  360.     RET
  361. ;
  362. DIRMSG:    DB    ' Can Only Move between User Areas on Same Drive.$'
  363. SAMUSR:    DB    ' Specified User number is same as current User number.$'
  364. BADSEC:    DB    ' Bad Sector Write Error','$'
  365. ROMSG:    DB    ' Drive is set to R/O','$'
  366. USRMSG:    DB    ' User number must be 0-15','$'
  367. NOUSR:    DB    ' No User number or dir: specified','$'
  368. MV2MSG:    DB    ' - Directory entry moved to $'
  369. USAGE:    DB    'MOVE, Version ',VERS/10+'0','.',VERS MOD 10+'0',CR,LF
  370.     DB    'MOVE - Move file(s) to new user area.',CR,LF
  371.     DB    'Syntax:',CR,LF
  372.     DB    '        MOVE du:afn user:',CR,LF
  373.     DB    'or      MOVE du:afn dir:',CR,LF,LF
  374.     DB    'NOTE:   Filename and type may contain wildcards.',CR,LF
  375.     DB    '        User area must be on same drive as du:.',CR,LF
  376.     DB    '        Valid User numbers from 0 to 15 or',CR,LF
  377.     DB    '        Directory names may be used.',CR,LF,'$'
  378. ;
  379. NOFILE:    DB    ' No File','$'
  380. FOUND1:    DB    0
  381. CURUSR:    DB    0        ; Save area for current user number
  382. WRTOK:    DB    0        ; Flag for change requiring write
  383.                 ; Set if change to directory made
  384. AMBFIL:                ; Fcb for match anything file
  385.     DB    '????????????????',0,0,0
  386.     DB    0,0,0,0,0,0,0,0,0,0,0,0,0
  387.  
  388. USERNO:    DB    0        ; Storage for new user number
  389.                 ; Obtained from tfcb
  390. DIRCODE:DB    0        ; Storage for directory code
  391.                 ; Provided by dos in accum
  392. DBOFF:    DW    0        ; Address for current fcb
  393.                 ; In the buffer starting at 80h
  394.                 ; Created by (32 * dircode + buffer
  395.                 ; Address) 32 bytes per dir entry
  396. DRVNO:    DB    0        ; Storage for selected drive number
  397.                 ; Provided by fcb dr byte(1st byte)
  398.                 ; And confirmed by dos if needed
  399. dirwrt:    db    0
  400. oldstk:    dw    0
  401.     ds    32
  402. stack:    ds    2
  403. ;
  404. END
  405.