TITLE PCPCK ; Check a File for Invalid PC Pursuit Code Sequence (CR, '@', CR) ; R. A. Freed ; 1.0 17 Oct 86 (init data to allow rerunning without reloading) ; 0.0 06 Aug 86 .Z80 BOOT EQU 0000H BDOS EQU BOOT+005H DFCB EQU BOOT+05CH DBUF EQU BOOT+080H TBASE EQU BOOT+100H $PRTSTR EQU 9 $OPEN EQU 15 $READ EQU 20 CR EQU 'M'-'@' LF EQU 'J'-'@' ASEG ORG TBASE BEGIN: LD A,(DFCB+1) ; Any file name? CP ' ' LD DE,HELP ; No, print short help JP Z,EXIT ; and exit LD DE,DFCB ; Open file LD C,$OPEN CALL BDOS INC A ; Found it? LD DE,NOFILE ; No, print error JP Z,EXIT ; and exit LD A,'$' ; Assume file is unconditionally ok LD (NOTK),A LD HL,0 ; Init record no. for error messages LD (RECNUM),HL LD (RECNUM+2),HL LD (RECNUM+4),HL LD HL,DBUF+127 ; Set buffer ptr to force 1st rec read LD B,L ; Init the modulo 8 record count LOOP: CALL GET ; Get next byte LOOP1: CP CR ; Carriage return? JP NZ,LOOP ; No, loop CALL GET ; Followed by '@'? CP '@' JP NZ,LOOP1 ; No, go see if start of new sequence CALL GET ; Followed by return? CP CR JP NZ,LOOP ; No, loop LD A,L ; Check buffer ptr CP LOW (DBUF+2) ; Sequence crosses record boundary? LD DE,FAIL ; No, PC Pursuit will always fail! JP NC,EXIT ; Report and exit LD A,B ; Get mod 8 record cnt AND 7 ; Sequence crosses 1K boundary? JP Z,LOOP ; Yes, that's ok LD DE,WARN ; No, will fail only with 1K packets LD H,B ; Save count PUSH HL ; and ptr CALL EXIT LD DE,KONLY ; Print warning for 1K transfers CALL EXIT LD A,' ' ; Qualify 'file ok' message LD (NOTK),A POP HL ; Restore regs LD B,H LD H,HIGH DBUF JP LOOP ; Loop to check some more GET: INC L ; Get next byte... JP Z,READ ; Skip if need new record GET1: LD A,(HL) ; Fetch byte AND 7FH ; Mask to 7 bits RET ; Return byte READ: PUSH BC ; Save count LD DE,DFCB ; Read a record LD C,$READ CALL BDOS POP BC ; Restore reg OR A ; End of file? JP NZ,EOF ; Yes, all done (file is ok) INC B ; Update 1K record count LD HL,RECEND ; Point after decimal ASCII rec. no. COUNT: DEC HL ; Count record no. in decimal ASCII... LD A,(HL) CP '9' JP NZ,COUNT1 LD (HL),'0' JP COUNT COUNT1: OR A JP NZ,COUNT2 LD (HL),'0' COUNT2: INC (HL) LD HL,DBUF ; Setup record ptr JP GET1 ; Go return 1st byte of record EOF: POP HL ; End of file, cleanup stack LD DE,OK ; Report file is ok! EXIT: LD C,$PRTSTR ; Print message string JP BDOS ; and return through BDOS HELP: DB 'PCPCK -- ' DB 'check if file is ok to upload with PC Pursuit$' NOFILE: DB 'No such file!$' OK: DB 'File is ok!' NOTK: DB '$(with 128-byte blocks)$' WARN: DB 'Warning: ' FAIL: DB 'File will fail in record # ' RECNUM: DB 0,0,0,0,0,0 RECEND: DB '!$' KONLY: DB ' (with 1K blocks)',CR,LF,'$' END BEGIN