; BAK.MAC Version 1.3 ; ; Erases all files with the filetype BAK. For ZCPR3 only. ; ; USAGE: ; ; BAK {dir:} ; ; Erases all files with a filetype of BAK on the specified drive ; and user. If a DU or DIR specification is not given, the ; current drive/user is assumed. ; ; HISTORY: ; ; Version 1.0 -- Author unknown. ; Public domain BK.MAC, written in Zilog mnemonics to be ; assembled with M80. ; ; Version 1.1 -- May 11, 1987 -- Gene Pizzetta ; Modified to allow a drive parameter in the command line. ; Converted to extended Intel mnemonics to assemble with MAC. ; ; Version 1.2 -- December 25, 1988 -- Gene Pizzetta ; Modified to return to CCP without warm boot. ; ; Version 1.3 -- September 18, 1989 -- Gene Pizzetta ; Now ZCPR3 specific. Allows DU or DIR specification. ; "BAK //" now displays usage message. ; Bdos equ 05h MemTop equ Bdos+1 CpmFcb equ 5Ch FcbUsr equ CpmFcb+13 TPA equ 100h ; ConOut equ 2 FErase equ 19 CurDisk equ 25 CurUsr equ 32 ; CR equ 0Dh LF equ 0Ah ; MACLIB Z80 ; org TPA ; jmp Start ; db 'Z3ENV' db 1 Z3EAdr: dw 0FE00h ; address of environment descriptor ; MsgUse: db 'BAK Version 1.3',CR,LF db ' BAK {dir:}',CR,LF db 'Erases all files with filetype BAK.',0 MsgEra: db 'BAK files erased on ',0 MsgNoF: db 'No BAK files found on ',0 ; OldStk: dw 0 FUsr: db 0 ; file user area ; EraFcb: db 0,'????????BAK' ; erase BAK filetype db 0,0,0,0,0,0,0,0,0,0,0,0 db 0,0,0,0,0,0,0,0,0,0,0,0 ; ; check for drive specification ; Start: sspd OldStk ; save old stack pointer lhld MemTop ; set stack to top of memory mov a,h sui 16 ; preserve 4K for CCP mov h,a sphl ; lda CpmFcb+1 ; check for help request cpi '/' jrnz GoToIt ; (no, this is the real thing) lxi h,MsgUse ; print help message call PrtNSt jmp Exit ; GoToIt: lda CpmFcb ; check default FCB cpi 0 ; is it the default drive? cz GetDft ; if so, find out what it is sta EraFcb ; put the drive spec into FCB lda FcbUsr ; get user sta FUsr ; store it mov e,a ; ..and set it mvi c,CurUsr call Bdos ; ; set up CP/M erase call and execute it ; mvi c,FErase lxi d,EraFcb ; point at EraFcb call Bdos ; do it ; ora a lxi h,MsgNoF ; no files message jrnz NoFile lxi h,MsgEra ; normal message NoFile: call PrtNSt lda EraFcb ; get drive adi 64 ; make it printable mov e,a mvi c,ConOut ; ..and print it call Bdos lda FUsr ; get user call BinDec ; ..and print it mvi e,':' mvi c,ConOut call Bdos lda EraFcb ; get drive mov b,a lda FUsr mov c,a call GetNdr ; print directory name ; Exit: lspd OldStk ; restore old stack ret ; return to CP/M ; ; Subroutines . . . ; ; GetDft -- returns default drive ; GetDft: mvi c,CurDisk ; get current drive call Bdos adi 1 ; make it acceptable to FCB ret ; ; PrtNSt -- prints a NUL-terminated string. Expects address of string ; in HL. ; PrtNSt: mov a,m ; get character cpi 0 ; null yet? rz ; (yes) mov e,a ; character in e mvi c,ConOut ; and print it push h call Bdos pop h inx h jr PrtNSt ; ; BinDec -- prints binary number (1 byte) at console in ASCII. Expects ; binary number in A. ; BinDec: mvi b,0 ; make B the no print flag mvi d,100 ; divide by 100 call BDLoop mvi d,10 ; divide by 10 call BDLoop mvi d,1 ; divide by 1 call BDLoop xra a ; have we printed anything? cmp b rnz ; (yes) mov c,a ; no, so we'll print a zero push psw jr Less1 ; jump to print and return to caller ; BDLoop: mvi c,0 ; initialize count BDL1: cmp d ; compare A to divisor jc BDLess ; (it's less) inr c ; it's greater, so increment C sub d ; subtract divisor jr BDL1 ; BDLess: push psw ; count finished, save binary number mov a,c cpi 0 ; is the count 0? jrnz Less1 ; (no) cmp b ; if both C and B are 0, jrz IsZero ; ..then it's a zero Less1: mvi a,30h add c ; convert to ASCII mov e,a ; ..and print it mvi c,ConOut call Bdos mvi b,1 ; set print flag pop psw ret ; IsZero: pop psw ; we're skipping leading zeros or spaces ret ; ; GetNdr -- gets and prints named directory. Expects drive in B and user ; in C. ; GetNdr: lhld Z3EAdr ; get environment address lxi d,15h ; add NDR address offset dad d mov e,m ; get address into DE inx h mov d,m inx h mov a,m ; get size in A xchg ; address in HL ora a jrnz IsNdr ; (got it) NoNdr: xra a ; NDR not found ret ; IsNdr: mov a,m ; get drive ora a ; 0 = end of directory jrz NoNdr ; (not found) cmp b ; check drive jrnz SkpNdr ; (no match) inx h mov a,m ; get user dcx h ; point back to drive cmp c ; check user jrnz SkpNdr ; (no match) inx h inx h call PrtNdr ; print directory name ret ; SkpNdr: push b ; save BC lxi b,18 ; point to next entry dad b pop b ; restore BC jr IsNdr ; ; PrtNdr -- prints named directory. Expects address in HL. ; PrtNdr: mvi b,8 PrtNd2: mov e,m ; get character mvi c,ConOut ; and print it push b push h call Bdos pop h pop b inx h djnz PrtNd2 ret ; end