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 / CPM / ZCPR33 / A-R / ERASE51A.LBR / ERASE51A.ZZ0 / ERASE51A.Z80
Text File  |  2000-06-30  |  13KB  |  578 lines

  1. ; Program:  ERASE
  2. ; Version:  5.0
  3. ; Date:  18 May 84
  4. ; Author:  Richard Conn
  5. ; v4.0 (16 JAN 83)
  6. ; v3.3 (06 Jan 83), 3.2 (07 Dec 82)
  7. ; v3.1 (09 Nov 82), 3.0 (18 Oct 82), 2.0 (18 Nov 81)
  8. ; v1.2 (12 Apr 81), 1.3 (25 Oct 81), 1.4 (26 Oct 81)
  9. ; v1.0 (14 Jun 80), 1.1 (19 Oct 80)
  10.  
  11. VERS    EQU    51
  12. Z3ENV    DEFL    0FE00H
  13.  
  14. ; Version 5.1A - Fix option parser as per RENAME32, strip high bit when
  15. ; printing program's actual name for help screen, wheel byte checked
  16. ; before granting "S" or "R" option or help text on those options.
  17. ;                December 30, 1987, Bruce Morgen
  18.  
  19. ; Version 5.1 - Z80 opcodes, Zilog mnemonics and ZCPR33 Type 3 format.
  20. ; Help message gives correct COMfile name of program.  Following Howard
  21. ; Goldstein's (LX17 & 18) lead, the ZCPR 3.3 parser is used if it's
  22. ; available.
  23. ;                December 21, 1987, Bruce Morgen
  24.  
  25. ;  ERASE COMMAND --
  26. ;    Erase files specified in command line.    Command is of the form:
  27. ;
  28. ;        ERASE DIR:FILENAME.TYP,... ISR
  29. ;
  30. ;    If 'I' option is given, Inspection of each file is performed and
  31. ;    the user is given the option to erase the file or not.    If 'S'
  32. ;    option is given, System files are included in erase procedure.
  33. ;    Drive specification is optional.  If 'R' option is given, R/O
  34. ;    files are erased without prompting.
  35. ;
  36.     .Z80
  37.  
  38. NO    EQU    0
  39. YES    EQU    NOT NO
  40.  
  41. FALSE    EQU    0
  42. TRUE    EQU    NOT FALSE
  43.  
  44. ESIZE    EQU    16        ; Size of directory entry (from SYSLIB DIRQ routine)
  45.  
  46.     PUBLIC    COUT        ; Make SYSLIB use our COUT routine
  47.  
  48.     EXTRN    DIRQ        ; Directory processor
  49.  
  50.     EXTRN    Z33CHK        ; Version 3.3 test
  51.     EXTRN    Z33FNAME    ; Zfname, 3.3-style
  52.  
  53.     EXTRN    Z3INIT        ; Init z3 enviornment
  54.     EXTRN    ZFNAME        ; File name parser
  55.     EXTRN    Z3LOG        ; Log into Z3 FCB specification
  56.     EXTRN    GETEFCB
  57.     EXTRN    GETWHL
  58.  
  59.     EXTRN    PUTUD        ; Save current DU
  60.     EXTRN    GETUD        ; Get current DU
  61.     EXTRN    PHLDC        ; Print HL as decimal characters
  62.     EXTRN    PHL4HC        ; Print HL as hexadecimal characters
  63.     EXTRN    EPRINT        ; Print routine
  64.     EXTRN    BOUT        ; Console output routine
  65.     EXTRN    CIN        ; Console input routine
  66.     EXTRN    CAPS        ; Capitalize routine
  67.     EXTRN    CRLF        ; New line routine
  68.     EXTRN    FILLB        ; Fill routine
  69.     EXTRN    CODEND        ; Code end computation routine
  70. ;
  71. ;  CP/M EQUATES
  72. ;
  73. CPM    EQU    0        ; Warm boot
  74. BDOS    EQU    5        ; BDOS entry
  75. FCB    EQU    5CH        ; FCB
  76. BUFF    EQU    80H        ; Input line buffer
  77. CR    EQU    13        ; <cr>
  78. LF    EQU    10        ; <lf>
  79. ;
  80. ; External ZCPR3 Environment Descriptor
  81. ;
  82. ; TYPE 3 HEADER
  83. ;
  84. ; Code modified as suggested by Charles Irvine to function correctly with
  85. ; interrupts enabled.  Program will abort with an error message when not
  86. ; loaded to the correct address (attempt to run it under CP/M or Z30).
  87.  
  88.      IF    Z3ENV NE 0
  89. ENTRY:    JR    START0        ; Must use relative jump
  90.     NOP            ; Filler
  91.     DB    'Z3ENV',3    ; Type-3 environment
  92.  
  93. Z3EADR:    DW    Z3ENV        ; Filled in by Z33
  94.     DW    ENTRY        ; Intended load address
  95.  
  96. START0:    LD    HL,0        ; Point to warmboot entry
  97.     LD    A,(HL)        ; Save the byte there
  98.     DI            ; Protect against interrupts
  99.     LD    (HL),0C9H    ; Replace warmboot with a return opcode
  100.     RST    0        ; Call address 0, pushing return address
  101.                 ; Onto stack
  102. RETADDR:LD    (HL),A        ; Restore byte at 0
  103.     DEC    SP        ; Get stack pointer to point
  104.     DEC    SP        ; To the value of return address
  105.     POP    HL        ; Get it into hl and restore stack
  106.     EI            ; We can allow interrupts again
  107.     LD    DE,RETADDR    ; This is where we should be
  108.     XOR    A        ; Clear carry flag
  109.     PUSH    HL        ; Save address again
  110.     SBC    HL,DE        ; Subtract -- we should have 0 now
  111.     POP    HL        ; Restore value of return address
  112.     JR    Z,START        ; If addresses matched, begin real code
  113.  
  114.     LD    DE,NOTZ33MSG-RETADDR ; Offset to message
  115.     ADD    HL,DE
  116.     EX    DE,HL        ; Switch pointer to message into DE
  117.     LD    C,9
  118.     JP    0005H        ; Return via BDOS print string function
  119.  
  120. NOTZ33MSG:
  121.     DB    'Not Z33+$'    ; Abort message if not Z33-compatible
  122.  
  123. START:    LD    HL,(Z3EADR)    ; Point to ZCPR3 environment
  124.      ENDIF            ; Z3ENV NE 0
  125. ;
  126. ; Internal ZCPR3 Environment Descriptor
  127. ;
  128.      IF    NOT (Z3ENV NE 0)
  129.  
  130.     MACLIB    Z3BASE.LIB
  131.     MACLIB    SYSENV.LIB
  132.  
  133. Z3EADR:    JP    START
  134.     SYSENV
  135.  
  136. START:    LD    HL,Z3EADR    ; Point to zcpr3 environment
  137.      ENDIF            ; NOT (Z3ENV NE 0)
  138. ;
  139. ; Start of Program -- Initialize ZCPR3 Environment
  140. ;
  141.     CALL    Z3INIT        ; Initialize the ZCPR3 env and the VLIB env
  142.     LD    (STACK),SP    ; Get stack pointer and save it
  143. ;
  144. ; Compute Buffer Locations
  145. ;
  146.     CALL    CODEND        ; Determine free space
  147.     LD    (CMDLNE),HL    ; Set ptr to command line
  148.     LD    DE,100H        ; Buffer size
  149.     ADD    HL,DE        ; Command line
  150.     LD    (ERAFCB),HL    ; Fcb for erase
  151.     ADD    HL,DE
  152.     LD    (DIRBUF),HL    ; Set ptr to directory buffer
  153.     LD    SP,HL        ; Set stack ptr
  154. ;
  155. ; Save Location
  156. ;
  157.     CALL    PUTUD        ; Save away current DU
  158. ;
  159. ; Print Banner
  160. ;
  161.     CALL    EPRINT
  162.     DB    'ERASE  Version '
  163.     DB    VERS/10+'0','.',[VERS MOD 10]+'0'
  164.     DB    ' (loaded at ',0
  165.     LD    HL,ENTRY
  166.     CALL    PHL4HC
  167.     CALL    EPRINT
  168.     DB    'h)',CR,LF,0
  169.     LD    A,(FCB+1)    ; Get first character of file name
  170.     CP    '/'        ; Option caught?
  171.     JR    Z,HELP
  172.     CP    ' '
  173.     JP    NZ,ECONT
  174. ;
  175. ; Print help information
  176. ;
  177. HELP:    CALL    EPRINT
  178.     DB    'Syntax:',CR,LF,'  ',0
  179.     CALL    GETEFCB
  180.     JR    Z,NOEFCB
  181.     LD    B,8
  182.  
  183. CNMLP:    INC    HL
  184.     LD    A,(HL)
  185.     AND    7FH
  186.     CP    ' '
  187.     CALL    NZ,BOUT
  188.     DJNZ    CNMLP
  189.     JR    HELP2
  190.  
  191. NOEFCB:    CALL    EPRINT
  192.     DB    'ERASE',0
  193.  
  194. HELP2:    CALL    EPRINT
  195.     DB    ' dir:filename.typ,dir:fn.ft,... [/]o...'
  196.     DB    CR,LF,'Options:'
  197.     DB    CR,LF,'   I -- Inspect Mode (Give user approval option)'
  198.     DB    0
  199.     CALL    GETWHL
  200.     JR    Z,RETURN
  201.     CALL    EPRINT
  202.     DB    CR,LF,'   R -- Erase R/O Files without prompting user'
  203.     DB    CR,LF,'   S -- Include SYS Files'
  204.     DB    0
  205. ;
  206. ; Return fo operating system
  207. ;
  208. RETURN:    CALL    GETUD        ; Reset user if necessary
  209.  
  210. RETX:    LD    SP,(STACK)    ; Get old stack and set it
  211.     RET
  212. ;
  213. ; Copy buffer into temp buffer
  214. ;
  215. ECONT:    LD    HL,(CMDLNE)    ; Pt to command line
  216.     EX    DE,HL        ; In DE
  217.     LD    HL,BUFF+1    ; Point to buffer
  218.     LD    BC,80H        ; Buffer size (maximum)
  219.     LDIR            ; Copy into command line buffer
  220. ;
  221. ; Extract flags if present
  222. ;
  223.     XOR    A        ; Set no inspect, no R/O, and no system files
  224.     LD    (INSPECT),A
  225.     LD    (READONLY),A
  226.     LD    A,80H        ; Select non-system
  227.     LD    (SYSTEM),A
  228.     LD    HL,0        ; Set file count
  229.     LD    (FILECNT),HL
  230.     LD    HL,(CMDLNE)    ; Point to buffer
  231. ;
  232. ; Skip to file name string
  233. ;
  234. SBLANK:    LD    A,(HL)        ; Skip to non-blank
  235.     CP    ' '        ; <space>?
  236.     JR    NZ,SBL1
  237.     INC    HL        ; Point to next character
  238.     JR    SBLANK
  239. ;
  240. ; Skip to end of file name string
  241. ;
  242. SBL1:    LD    A,(HL)        ; Skip to <space> or EOL
  243.     OR    A        ; Done?
  244.     JP    Z,DSPEC
  245.     CP    ' '        ; <space>
  246.     JR    Z,SBL2
  247.     INC    HL        ; Point to next
  248.     JR    SBL1
  249. ;
  250. ; Skip over trailing blanks
  251. ;
  252. SBL2:
  253.     INC    HL        ; Point to character after space
  254.     LD    A,(HL)
  255.     OR    A        ; End of command tail?
  256.     JP    Z,DSPEC
  257.     CP    ' '        ; Another space
  258.     JR    Z,SBL2        ; If so, continue skipping
  259. ;
  260. ; Check for leading slash on option and skip it if so
  261. ;
  262. OPT:    CP    '/'        ; Option character?
  263.     JR    NZ,OPTION
  264.     INC    HL        ; Skip slash
  265. ;
  266. ; Process list of options
  267. ;
  268. OPTION:    LD    A,(HL)        ; Get byte
  269.     OR    A        ; Done?
  270.     JR    Z,DSPEC
  271.     INC    HL        ; Point to next character
  272.     CP    ' '        ; Skip over spaces
  273.     JR    Z,OPTION
  274.     CP    '/'        ; If option letter, obvious error, so help
  275.     JP    Z,HELP
  276.     CP    'I'        ; Inspect?
  277.     JR    Z,OPTINS
  278.     CP    'R'        ; Read/only?
  279.     JR    Z,OPTRO
  280.     CP    'S'        ; System files?
  281.     JP    NZ,HELP
  282. ;
  283. ; Sset system selection
  284. ;
  285.     PUSH    AF
  286.     CALL    GETWHL
  287.     JR    Z,NOWHL
  288.     POP    AF
  289.     LD    A,0C0H        ; Set for system and non-system files
  290.     LD    (SYSTEM),A
  291.     JR    OPTION
  292. ;
  293. ; Set inspect option
  294. ;
  295. OPTINS:    LD    A,0FFH        ; Inspect
  296.     LD    (INSPECT),A
  297.     JR    OPTION
  298. ;
  299. ; Set R/O option
  300. ;
  301. OPTRO:    PUSH    AF
  302.     CALL    GETWHL
  303.     JR    Z,NOWHL
  304.     POP    AF
  305.     LD    A,0FFH        ; Set R/O
  306.     LD    (READONLY),A
  307.     JR    OPTION
  308.  
  309. NOWHL:    LD    A,'"'
  310.     CALL    BOUT
  311.     POP    AF
  312.     CALL    BOUT
  313.     CALL    EPRINT
  314.     DB    '" option denied, Wheel privileges required.',CR,LF,0
  315.     JR    OPTION
  316. ;
  317. ; Extract disk, user, and file name information
  318. ;
  319. DSPEC:    LD    HL,(CMDLNE)    ; Point to before first byte
  320.     DEC    HL        ; Point to before first byte for following inc
  321.  
  322. DSPEC0:    INC    HL        ; Point to byte
  323.     LD    A,(HL)        ; Get byte
  324.     OR    A        ; Done?
  325.     JP    Z,HELP
  326.     CP    ' '        ; <space>?
  327.     JR    Z,DSPEC0
  328. ;
  329. ; Major reentry point when file specs are separated by commas
  330. ;   HL points to first byte of next file specification
  331. ;
  332. DSPEC1:    CALL    GETUD        ; Return home
  333.     LD    DE,FCB        ; Point to FCB in DE and to first character of file name in HL
  334.     CALL    PARSIT        ; Extract file name into FCB, and get disk and user
  335.     LD    (NEXTCH),HL    ; Save pointer to delimiter which ended scan
  336.     LD    HL,FCB+1    ; See if file name is all wild
  337.     LD    B,11        ; 11 bytes
  338.  
  339. WTEST:    LD    A,(HL)        ; Get byte
  340.     INC    HL        ; Point to next
  341.     CP    '?'        ; Wild?
  342.     JR    NZ,NOWILD
  343.     DJNZ    WTEST        ; Count down
  344.     LD    A,(INSPECT)    ; Inspect?
  345.     OR    A        ; 0=no
  346.     JR    NZ,NOWILD
  347.     CALL    EPRINT
  348.     DB    CR,LF,'Erase All Files? ',0
  349.     CALL    CIN        ; Get response
  350.     CALL    CAPS        ; Capitalize
  351.     CALL    BOUT        ; Echo
  352.     CP    'Y'        ; Yes?
  353.     JR    Z,NOWILD
  354.     CALL    EPRINT
  355.     DB    CR,LF,'Aborting',0
  356.     JP    RETX
  357.  
  358. NOWILD:    LD    DE,FCB        ; Point to FCB
  359.     CALL    Z3LOG        ; Log into directory
  360. ;
  361. ; Load directory and erase files
  362. ;
  363. ERASE:    LD    HL,(DIRBUF)    ; Point to directory buffer
  364.     LD    A,(SYSTEM)    ; Get sys/non-sys flags
  365.     LD    DE,FCB        ; Pt to fcb
  366.     CALL    DIRQ        ; Load dir, select files, pack, and alphabetize
  367. ;
  368. ; Erase directory files; HL points to first file, BC=file count
  369. ;
  370.     CALL    ERAFILES
  371. ;
  372. ; Check for next file specification
  373. ;
  374.     LD    HL,(NEXTCH)    ; Get pointer
  375.     LD    A,(HL)        ; Get delimiter
  376.     CP    ','        ; Another file?
  377.     JR    NZ,ERADONE
  378.     INC    HL        ; Point to character after comma
  379.     JR    DSPEC1        ; Continue processing
  380. ;
  381. ; Erase complete -- print count and exit
  382. ;
  383. ERADONE:CALL    PRCOUNT        ; Print file count
  384.     JP    RETURN
  385. ;
  386. ; Erase selected files
  387. ;
  388. ERAFILES:
  389.     LD    A,B        ; Check for any files loaded
  390.     OR    C
  391.     RET    Z
  392. ;
  393. ; Print file name
  394. ;
  395. ERAFLP:    PUSH    BC        ; Save entry count
  396.     CALL    CRLF        ; New line
  397.     PUSH    HL        ; Save pointer to FCB
  398.     INC    HL        ; Point to file name
  399.     LD    B,8        ; Print name
  400.     CALL    PRNT
  401.     LD    A,'.'        ; Decimal
  402.     CALL    BOUT
  403.     LD    B,3        ; Print type
  404.     CALL    PRNT
  405.     POP    HL        ; Get pointer
  406. ;
  407. ; Check for inspection and inspect if set
  408. ;
  409.     LD    A,(INSPECT)    ; Get flag
  410.     OR    A        ; 0=no
  411.     JR    Z,ERAIT
  412. ;
  413. ; Prompt user for erase
  414. ;
  415.     CALL    ERAQ        ; Erase question
  416.     CP    'Q'        ; Quit?
  417.     JR    Z,QUIT
  418.     CP    'Y'        ; Yes?
  419.     JR    Z,ERAIT
  420. ;
  421. ; Don't erase file
  422. ;
  423. ERANO:    CALL    EPRINT
  424.     DB    '  NOT Erased',0
  425.     JP    ERATEST
  426. ;
  427. ; Prompt user for erase
  428. ;
  429. ERAQ:    CALL    EPRINT        ; Print prompt
  430.     DB    ' -- Erase (Y/N/Q=Quit/other=N)? ',0
  431.     CALL    CIN        ; Get response
  432.     CALL    CAPS        ; Capitalize
  433.  
  434. COUT:    JP    BOUT        ; Echo
  435. ;
  436. ; Quit erase program
  437. ;
  438. QUIT:    CALL    PRCOUNT        ; Print count of files erased
  439.     JP    RETURN
  440. ;
  441. ; Erase file
  442. ;
  443. ERAIT:    PUSH    HL
  444.     LD    DE,9        ; Point to R/O attribute
  445.     ADD    HL,DE
  446.     LD    A,(HL)        ; Get R/O attribute
  447.     POP    HL        ; Restore pointer
  448.     AND    80H        ; R/O?
  449.     JR    Z,ERAIT1    ; R/W - proceed
  450.     LD    A,(READONLY)    ; Get R/O erase flag
  451.     OR    A        ; 0=query
  452.     JR    NZ,ERAIT0    ; Erase without question if flag set
  453.     CALL    EPRINT        ; Notify user and prompt
  454.     DB    CR,LF,' File is R/O',0
  455.     CALL    ERAQ        ; Ask question
  456.     CP    'Q'        ; Quit?
  457.     JR    Z,QUIT
  458.     CP    'Y'        ; Erase R/O
  459.     JR    NZ,ERATEST    ; Do not erase if not yes
  460. ;
  461. ; Erase R/O file
  462. ;
  463. ERAIT0:    PUSH    HL        ; Save pointer to file entry
  464.     LD    DE,9        ; Point to R/O attribute
  465.     ADD    HL,DE
  466.     LD    A,(HL)        ; Get attribute
  467.     AND    7FH        ; Make R/W
  468.     LD    (HL),A
  469.     POP    HL        ; Get pointer to FCB
  470.     PUSH    HL        ; Save pointer again
  471.     EX    DE,HL        ; DE points to FCB
  472.     XOR    A        ; Make sure current disk is selected
  473.     LD    (DE),A
  474.     LD    C,30        ; Set file attributes
  475.     CALL    BDOS
  476.     POP    HL
  477. ;
  478. ; Erase R/W file
  479. ;
  480. ERAIT1:    PUSH    HL        ; Save pointer to file name to erase
  481.     INC    HL        ; Point to first byte of name
  482.     PUSH    HL        ; Save HL
  483.     LD    HL,(ERAFCB)    ; Set up FCB
  484.     EX    DE,HL        ; In DE
  485.     POP    HL        ; Get HL
  486.     PUSH    DE        ; Save pointer
  487.     XOR    A        ; A=0
  488.     LD    (DE),A        ; Current disk
  489.     INC    DE        ; Point to first characterx
  490.     LD    BC,11        ; Copy 11 bytes
  491.     LDIR            ; Copy HL to DE for 11 bytes
  492.     EX    DE,HL        ; HL points to rest of FCB
  493.     LD    B,24        ; Fill rest of FCB with zeroes
  494.     XOR    A        ; A=0
  495.     CALL    FILLB
  496.     POP    DE        ; Get pointer
  497.     LD    C,19        ; Delete file
  498.     CALL    BDOS
  499.     CALL    EPRINT
  500.     DB    '      Erased',0
  501.     LD    HL,(FILECNT)    ; Increment count
  502.     INC    HL
  503.     LD    (FILECNT),HL
  504.     POP    HL        ; Get pointer to directory entry
  505. ;
  506. ; Point to next entry
  507. ;
  508. ERATEST:LD    DE,ESIZE    ; Point to next entry
  509.     ADD    HL,DE
  510.     POP    BC        ; Get count
  511.     DEC    BC        ; Count down
  512.     LD    A,B        ; Check for zero
  513.     OR    C
  514.     JP    NZ,ERAFLP
  515. ;
  516. ; Return to caller
  517. ;
  518.     RET
  519. ;
  520. ; Print characters pointed to by HL for B bytes
  521. ;
  522. PRNT:    LD    A,(HL)        ; Get character
  523.     CALL    BOUT
  524.     INC    HL        ; Point to next
  525.     DJNZ    PRNT        ; Count down
  526.     RET
  527. ;
  528. ; Print count of number of files erased
  529. ;
  530. PRCOUNT:CALL    CRLF        ; New line
  531.     LD    HL,(FILECNT)    ; Get count
  532.     LD    A,L        ; Check for none
  533.     OR    H
  534.     JR    Z,PRNO
  535.     CALL    PHLDC        ; Print decimal count
  536.     JR    PRMS
  537.  
  538. PRNO:    CALL    EPRINT
  539.     DB    'No',0
  540.  
  541. PRMS:    LD    HL,(FILECNT)    ; 1 file erased?
  542.     LD    A,H        ; High zero?
  543.     OR    A
  544.     JR    NZ,PRMULT
  545.     LD    A,L        ; Low one?
  546.     CP    1
  547.     JR    Z,PRSING
  548.  
  549. PRMULT:    CALL    EPRINT
  550.     DB    ' Files Erased',0
  551.     RET
  552.  
  553. PRSING:    CALL    EPRINT
  554.     DB    ' File  Erased',0
  555.     RET
  556.  
  557. PARSIT:    CALL    Z33CHK
  558.     JP    Z,Z33FNAME
  559.     XOR    A
  560.     JP    ZFNAME
  561. ;
  562. ; Buffers
  563. ;
  564.     DSEG
  565. INSPECT:DS    1    ; Inspect flag (0=NO, 0ffh=YES)
  566. SYSTEM:    DS    1    ; System flag (0=NO, 80h=YES)
  567. READONLY:DS    1    ; Read/only flag (0=query for R/O, 0ffh=don't)
  568. USER:    DS    1    ; New user, or 0FFh if no change
  569. CURUSER:DS    1    ; Current user number
  570. NEXTCH:    DS    2    ; Pointer to next character in multifile command line
  571. FILECNT:DS    2    ; Count of number of files erased
  572. ERAFCB:    DS    2    ; Pointer to FCB for erase
  573. CMDLNE:    DS    2    ; Pointer to command line
  574. DIRBUF:    DS    2    ; Pointer to directory buffer
  575. STACK:    DS    2    ; Old stack pointer
  576.  
  577.     END
  578.