; Program: FORZ ; Version: 1.0 ; Assembly: Z80ASM.COM, PDLN.COM, Z3LIB ; Date: 5 Aug 87 ; Author: Carson Wilson ; ; Purpose: This is an enhanced version Irv Hoff's FOR.COM for ZCPR33. ; ; Features: Sets the ZCPR program error flag if a string was given at ; the command line and no match was found ; Resets ZCPR program error flag if a string was given at the ; command line and a match WAS found. ; Operates quietly (no informative messages) if ZCPR quiet ; flag is set (useful for running under ZFILER). ; Responds to ZCPR '/' or '//' help commands. ; Reinitializes its internal FCB so that FORZ can be rerun ; with ZCPR's GO command. ; Apologies for parts of this source which remain unclear; ; this file was adapted from a disassembly. Version equ 10 ; BDOS equ 5 CR equ 0dh LF equ 0ah DMA equ 80h ; .request z3lib ext z3init, puter2, getquiet ; entry: jp Start db 'Z3ENV' db 3 z3eadr: dw 0 ; address ZCPR ENV descriptor ; to be filled in by CCP dw entry ; Type 3 environment points to itself ; db '[CONFIG>' FORdrv: db 'A' ; drive of FOR file (not used) FORusr: db 14 ; user # of FOR file ; Start: ld hl,0 add hl,sp ld (StkSav),hl ; save sp ld sp,StkSav ld a,(4) ld (DefDU),a ; ld hl,(z3eadr) ; Initialize Z environment call z3init ; ld hl,FORFCB1 ; Initialize FCB so we can use ; ZCPR's GO command on FORZ ld b,21 ; Length to fill xor a ; Zero out InitFCBa: ld (hl),a inc hl djnz InitFCBa ; ld a,(FORusr) ld e,a ld c,' ' ; select FOR. user call BDOS ; ld a,(FORdrv) sub 'A' ld e,a ld c,0eh call 5 ; select FOR. drive ; (as returned by getmsg) ; ld de,ForFCB ld c,0fh call BDOS ; search first inc a jp z,NoFOR ; FOR file not found ; call getquiet jr nz,ChkLen ; No messages if Quiet on call InlPrnt db CR,LF db 'FORZ ',version/10+'0','.',version mod 10+'0', db ' (c) 1987 by C. Wilson',CR,LF db '[type ^S to pause, ^C, ^X or ^K to abort]' db CR,LF,CR,LF,0 ; ; ChkLen: ld a,(DMA) ; # of chars in command tail or a ld (TailLen),a ; save length jp nz,ChkTail ; had tail ld a,CR ; no CL tail call PCharA jp Read ; ; ChkTail: '?', '/', or '//' gives help message. ; ChkTail: ld a,(82h) ; 1st char of CL tail cp '/' jp nz,ChkT2 ld a,(83h) ; 2nd char or a jp z,Help ; no 2nd char cp '/' ; 2nd char '/' jp z,Help ; ChkT2: ld a,(82h) cp '?' jp nz,CopyTail ; No help ld a,(83h) ; 2nd CL char detected? or a jp nz,CopyTail ; Yes, no help. jp Help ; Lone '?' gives help CopyTail: call SetZerr ; set ZCPR error flag as default ; until match for CL string found ld hl,DMA ld b,(hl) ; # of chars in command line buffer ld de,FORBuf inc hl CopyT1: inc hl ld a,(hl) ld (de),a inc de dec b jp nz,CopyT1 ; copy tail to our buffer ; ld de,FORDMA Read: push de ld c,1ah ; set DMA 80h ld de,DMA call BDOS ld c,14h ; read seq. ld de,ForFCB call BDOS pop de or a jp nz,l04fb ; read error / EOF ld hl,DMA ; TestCh: ld a,(First) ; flag or a ; = 0? jp z,l020c ; yes, first char. xor a ; set flag to 0 ld (First),a ld a,(hl) ; get next char from file and 7fh ; mask cp '-' jp nz,l020c ld a,3 ld (de),a jp l0473 l020c: ld a,(hl) and 7fh cp 7fh ; delete mark? jp z,ReadChk cp 1ah ; end of file? jp z,l0520 ld b,a ld a,(TailLen) or a ld a,b jp nz,l0228 call PCharA jp l022a l0228: ld (de),a inc de l022a: cp LF jp nz,ReadChk ld a,(TailLen) ld (First),a call ChkCon ReadChk: ; time to read again? inc l jp z,Read ; yes jp TestCh ; no, test next char. ; ; ChkCon: ; Test for user interrupt push hl push de ld c,0bh ; get console status call BDOS or a jp z,ChkConX ; no input waiting ld c,1 ; get input and 5fh call BDOS cp 13h ; ^S? jp nz,ChkCon1 ; no ld c,1 ; yes, await input call BDOS and 5fh ChkCon1: cp 3 ; ^C? jp z,Abort cp 0bh ; ^K? jp z,Abort cp 18h ; ^X? jp z,Abort and 5fh ; capitalize cp 'C' jp z,Abort cp 'K' jp z,Abort cp 'X' jp nz,ChkConX Abort: call getquiet jp nz,Exit call PrnExit db CR,LF,'++ ABORTED ++$' ChkConX: pop de pop hl ret ; ; PrnExit: ; print string & exit pop de ld c,9 ; print following '$' terminated string call BDOS call InlPrnt db CR,LF,0 ; Exit: ld a,(DefDU) rra rra rra rra and 0fh ld e,a ; set user code to original ld c,' ' call BDOS ; ld a,(DefDU) and 0fh ld e,a ld c,0eh call 5 ; restore drive ; ld hl,(StkSav) xor a ld sp,hl ret ; exit FOR.COM ; ; Help: call PrnExit db CR,' Examples of how to use:',CR,LF,CR,LF db ' B>FORZ MOD',CR,LF db ' B>FORZ MOD|BYE',CR,LF db ' B>FORZ M7',CR,LF db ' B>FORZ \M7',CR,LF db ' B>FORZ SPHL',CR,LF db ' B>FORZ .A?M',CR,LF,CR,LF db ' If no string is included, all the file ' db 'is shown. A ''|'' allows',CR,LF db ' numerous strings to be used at the same time. ' db ' ''?'' is used for',CR,LF db ' "any character at this position". A ''\'' fakes a ' db 'line feed and',CR,LF,' ' db ' looks only at the start of the filename line.',CR,LF db '$' ; ; InlPrnt: ; Print inline chars up to 0 ex (sp),hl Prnt1: ld a,(hl) call PCharA inc hl ld a,(hl) or a jp nz,Prnt1 ex (sp),hl ret ; NoFOR: call SetZerr call getquiet jp nz,Exit call PrnExit db CR,LF,'++ No current FOR text file available ++$' ; ; l0473: push hl ld hl,FORBuf l0477: ; Point to start of CL buffer ld (BufPt),hl ; save at BUfPt ld hl,FORDMA ; Point to start of DMABuf l047d: ex de,hl ; DE --> start of DMABuf ld hl,(BufPt) ; HL --> start of CL ex de,hl ; DE --> CL push hl ; HL --> DMABuf l0483: ld a,(de) ; get first char of CL cp '\' jp nz,l048b ld a,LF ; Look only at start of filename line l048b: inc de ; next CL char or a jp z,l04d9 ; First char is zero cp '|' jp z,l04d9 ; Start search for next CL string (| = or) ld b,a ld a,(hl) cp 'a' jp c,l04a3 cp '{' jp nc,l04a3 and 5fh l04a3: ld c,a inc hl ld a,b cp '?' jp z,l0483 cp c jp z,l0483 pop hl inc hl ld b,0 ld a,(hl) cp 3 jp z,l04bf cp 4 jp nz,l047d inc b l04bf: ld hl,(BufPt) l04c2: ld a,(hl) inc hl cp 7ch jp z,l0477 or a jp nz,l04c2 ld a,b or a jp nz,Close ld de,FORDMA1 pop hl jp ReadChk ; ; l04d9: pop hl ; HL --> DMABuf ld a,CR call PCharA ld hl,FORDMA ; PrintBuf: ; Print DMABuf until terminator ld a,(hl) cp 3 ; ^C jp z,l04f4 cp 4 ; ^D jp z,Success call PCharA inc hl jp PrintBuf ; Success: call ResZerr ; Found match, so reset ZCPR error flag jp Close ; l04f4: call ResZerr pop hl ld de,FORDMA1 jp ReadChk ; ; l04fb: cp 1 jp z,l0520 call getquiet jp nz,Exit call PrnExit db '++ SOURCE FILE READ ERROR ++$' l0520: ld a,(TailLen) or a jp z,Close ld a,4 ld (de),a jp l0473 Close: ld c,10h ; close file ld de,ForFCB call BDOS call getquiet jp nz,Exit call PrnExit db CR,'----',CR,LF,'[end of listing]$' ; PCharA: ; print char in A push bc push de push hl push af ld e,a ld c,2 call BDOS pop af pop hl pop de pop bc ret ; ; Set ZCPR program error flag ; SetZerr: ld a,0ffh call puter2 ; set error flag to non-zero ret ; ; Reset ZCPR error flag (clear it) ; ResZerr: ld a,0 call puter2 ; set error flag to 0 ret ; ; ForFCB: db 0,'FOR ' ForFCB1: ds 21 DefDU: ; default drive/user ds 1 ; First: ; flag db 0 ; TailLen: ; length of comand line tail ds 1 ; OurStk: ds 32 StkSav: ds 2 ; BufPt: ds 2 ; FORBuf: ds 128 ; DSEG FORDMA: ds 1 FORDMA1 equ $ end