ORG 100H LD (STACK-2),SP LD SP,STACK-2 ;new stack LD HL,65h ;file ext = LBR LD A,(HL) CP ' ' ;(unless specified) JR NZ,OK0 LD (HL),'L' INC HL LD (HL),'B' INC HL LD (HL),'R' OK0: LD DE,5Ch LD C,15 ;open up library CALL 5 INC A ;did it open? JR NZ,OK1 CALL PRINT DB 'Library file not found.',0 EXIT: LD SP,(STACK-2) RET OK1: XOR A LD (7Dh),A ;set sector #0 LD (7Eh),A LD (7Fh),A LD HL,5Ch ;set up duplicate FCB LD DE,FCB2 LD BC,36 LDIR LD DE,LDIRBUF ;point to start of LBR buffer LD C,26 ;set dma addr CALL 5 LD DE,5Ch LD C,33 ;read first sector CALL 5 OR A ;did it read? JR Z,OK2 CALL PRINT DB 'Library file is empty.',0 JP EXIT BADLBR: CALL PRINT DB 'Improper format in library file.',0 JP EXIT OK2: LD HL,LDIRBUF LD A,(HL) ;check for deleted flag off OR A JR NZ,BADLBR CALL DIRCRC INC HL LD A,' ' LD B,11 ;check for all spaces in name LP0: CP (HL) JR NZ,BADLBR CALL DIRCRC INC HL DJNZ LP0 XOR A ;check for start=0000 CP (HL) JR NZ,BADLBR CALL DIRCRC INC HL CP (HL) JR NZ,BADLBR CALL DIRCRC INC HL ;get library length LD C,(HL) CALL DIRCRC INC HL LD B,(HL) CALL DIRCRC LD (MEMBCNT),BC INC HL LD (HL),0 ;zero CRC bytes for calculation CALL DIRCRC INC HL LD (HL),0 CALL DIRCRC LD B,15 ;skip to next entry CALL SKIP LOOP: LD A,(HL) ;check active flag OR A JP Z,PROCESS ;go if deleted or unused LD B,32 ;skip this entry CALL SKIP JP NXTMEMB PROCESS: CALL DIRCRC INC HL CALL PRINT DB 'Member ',0 LD B,8 CALL LX2 LD E,'.' CALL PUTC LD B,3 CALL LX2 JR LX3 LX2: LD A,(HL) CP ' ' JP Z,SKIP CALL DIRCRC LD E,A CALL PUTC INC HL DJNZ LX2 RET MEMBCNT: DW 0 LX3: LD E,(HL) ;get file start ptr CALL DIRCRC INC HL LD D,(HL) CALL DIRCRC INC HL LD C,(HL) ;get length CALL DIRCRC INC HL LD B,(HL) CALL DIRCRC INC BC ;plus one INC HL PUSH HL ;save CRC address PUSH BC LD (FCB2+33),DE ;point to first rec of member LD DE,FILBUF ;set DMA for CRC comp LD C,26 CALL 5 XOR A LD (FCB2+35),A LD H,A ;zero CRC to start LD L,A CRCLP: POP BC ;get back member length DEC BC ;minus one LD A,B ;check if more sectors in member OR C JR Z,CRCDONE ;all done if sector cnt=0 PUSH BC ;save PUSH HL LD DE,FCB2 ;read the record LD C,33 CALL 5 POP HL ;restore one byte LD DE,FILBUF ;byte pointer LD B,128 ;do one sector CRCLP2: LD A,(DE) ;get a byte CALL CRCBYT ;add to CRC INC DE ;next byte DJNZ CRCLP2 ;and loop LD BC,(FCB2+33) ;point to next sector INC BC LD (FCB2+33),BC JR CRCLP ;do next CRCDONE: XOR A ;two zeros to finish CRC CALL CRCBYT XOR A CALL CRCBYT EX DE,HL ;put CRC in DE POP HL ;restore address for CRC LD (HL),E ;save CRC CALL DIRCRC INC HL LD (HL),D CALL DIRCRC INC HL PUSH HL CALL PRINT ;print a newline DB 13,10,0 POP HL LD B,14 ;skip rest of entry CALL SKIP NXTMEMB: LD A,L CP 128 ;done with this LDIR sector? JP NZ,LOOP ;do next entry LD DE,LDIRBUF ;set DMA LD C,26 CALL 5 LD DE,5Ch ;write updated directory sector LD C,34 CALL 5 LD HL,(MEMBCNT) ;any more directory sectors? DEC HL LD (MEMBCNT),HL LD A,H OR L JR Z,ALLDONE ;nope, finish up LD HL,(7Dh) ;point to next INC HL LD (7Dh),HL LD DE,5Ch ;read next directory sector LD C,33 CALL 5 LD HL,LDIRBUF ;point to first member JP LOOP ;go around ALLDONE: LD HL,0 ;point back to first sector LD (7Dh),HL LD DE,5Ch ;read first sector LD C,33 CALL 5 LD HL,(DCRC) ;fetch computed directory CRC LD (LDIRBUF+16),HL ;save it LD DE,5Ch ;close file LD C,16 CALL 5 CALL PRINT ;parting is such sweet-sweet sorrow DB '** DONE **',0 JP EXIT ;done CRCBYT: PUSH BC ;don't destroy LD C,A ;byte to bo added LD B,8 ;8 bit loop CRC1: RLC C ADC HL,HL ;shift H-L-C left 1 JR NC,CRC2 LD A,H ;HL <- HL XOR 1021h XOR 16 LD H,A LD A,L XOR '!' LD L,A CRC2: DJNZ CRC1 ;loop POP BC RET SKIP: CALL DIRCRC INC HL DJNZ SKIP RET DIRCRC: PUSH HL PUSH AF LD HL,(DCRC) CALL CRCBYT LD (DCRC),HL POP AF POP HL RET DCRC: DW 0 PRINT: EX (SP),HL LD A,(HL) INC HL EX (SP),HL OR A RET Z LD E,A CALL PUTC JR PRINT PUTC: PUSH BC PUSH HL LD C,2 CALL 5 POP HL POP BC RET STACK EQU ($+255)&0FF00h ;page align buffers DS STACK-$ ;space for stack LDIRBUF: DS 128 ;space for directory entries FCB2: DS 36 ;space for second FCB FILBUF: DS 128 ;space for files EOF: DB '' END