title Module from library BASE_4 : VARREC name ('VARREC') maclib baselib.lib ; Utilities for handling with variable length records ; Copyright (C) Werner Cirsovius ; Hohe Weide 44 ; D-20253 Hamburg ; Tel.: +49-40-4223247 ; Version 1.0 April 1987 entry @tsrec,@gtphs,@gtrec,@mvrec,@fxnxt,@rnrec extrn rndred,curdma ; ; Test legal record parameters ; ENTRY Accu and reg pair BC hold record parameter ; EXIT Carry set on error, else reset ; @tsrec: ld (reclen),a ; Save record length or a ; Test zero scf ret z ; ... it's an error ld a,b ; Test record number or c ; Zero is error, too scf ret z ccf ld a,(reclen) ; Restore accu ret ; ; Prepare record transfer ; ENTRY Accu and location RECLEN hold record length ; Reg pair BC holds record number ; EXIT Reg B holds record length ; Reg C holds offset within 128 byte record ; @gtphs: push hl push de push bc push af ld hl,_RRN+2 add hl,de ; Get random record pointer ld (hl),0 ; Clear hi end dec hl dec hl ld (@rnrec),hl ; Save pointer call curdma ; Get current DMA pointer ld ($$DMA),hl ; And save it pop af pop hl call @mlrec ; Get logical record pointer ex de,hl ld hl,(@rnrec) ld (hl),e ; Get record number inc hl ld (hl),d pop de pop hl ld c,a ; Get offset ld a,(reclen) ld b,a ; And record length ret ; ; Read random record from file ; ENTRY Reg pair DE holds FCB ; Reg C holds relative buffer pointer ; EXIT Carry set on error, otherwise reset ; On normal return reg pair DE points to ; start of record buffer ; @gtrec: call rndred ; Get record ret c ; Exit on error push hl push bc ld b,0 ld hl,($$DMA) ; Get DMA base add hl,bc ex de,hl ; Get DE as pointer pop bc pop hl ret ; ; Move some bytes ; ENTRY Reg pair DE points to source ; Reg pair HL points to destination ; Reg B holds count of variable record ; Reg C holds record pointer ; EXIT Zero set on complete move. If move incomplete ; zero reset and reg C cleared ; @mvrec: ld a,(de) ; Get from source ld (hl),a ; Into destination inc de inc hl dec b ; Test end ret z ; Aha, done inc c ; Bump count ld a,c cp reclng ; Test record complete jr nz,@mvrec ld c,0 ; Reset pointer or a ; Set non zero ret ; ; Fix random record counter ; ENTRY Location @RNREC holds address of counter ; EXIT Counter incremented by one ; @fxnxt: push hl push de ld hl,(@rnrec) ; Get pointer ld e,(hl) ; Get actual count inc hl ld d,(hl) inc de ; Increment ld (hl),d ; Bring back count dec hl ld (hl),e pop de pop hl ret ; ; Get logical record from variable one ; ENTRY Accu holds variable record length ; Reg pair HL holds record number ; EXIT Reg pair HL holds logical 128 byte record # ; Accu holds offset within 128 byte record ; @mlrec: push bc push de ex de,hl dec de ; Fix record # ld hl,0 ; Clear product ld b,l ld c,8 ; Set bit count ld (rec),a ; Save record length xor a ld (rec+1),a mullop: or a ld a,d ; Divide record by two rra ld d,a ld a,e rra ld e,a jr nc,nofix ; Test bit shifted out ld a,(rec) add a,b ; If so, add product ld b,a ld a,(rec+1) adc a,l ld l,a ld a,h adc a,0 ld h,a nofix: push hl ld hl,(rec) ; Double record add hl,hl ld (rec),hl pop hl dec c ; Test end jr nz,mullop add hl,hl ; Fix 16 bit ld a,b rla jr nc,fix inc hl ; Fix LSB fix: or a rra ; Make seven bit pop de pop bc ret dseg reclen: ds 1 ; Length of variable record @rnrec: ds 2 ; Random record pointer $$DMA: ds 2 ; DMA pointer rec: ds 2 ; RECLEN expanded to 16 bit end