I
think this will work, although I haven't gotten a chance to test it yet. This is of course the code to populate the appvar:
Code: VatSize:
ld bc,0
ld hl,(progptr)
VatSizeLoop:
ld de,(ptemp)
bcall(_cphlde)
jr z,VatCreateAppVar
ld de,-6
ld a,(hl)
and $1f
cp $05
jr z,VatSizeLoopPrgm
cp $06
jr nz,VatSizeLoopSkipName
VatSizeLoopPrgm:
push hl
add hl,de ;de=-6
ld l,(hl)
ld h,0
inc l ;for the size byte
add hl,bc
pop hl
VatSizeLoopSkipName:
add hl,de
push bc
inc b
VatSizeLoopSkipName1:
dec hl
djnz VatSizeLoopSkipName1
pop bc
jr VatSizeLoop
VatCreateAppVar:
push bc
pop hl
bcall(_enoughmem)
ret c ;not enough memory
push de
ld hl,AppVarName
rst 20h
bcall(_chkfindsym)
pop hl
ret c ;already exists
bcall(_createappvar)
inc de
inc de
VatStore:
ld bc,0
ld hl,(progptr)
VatStoreLoop:
ld de,(ptemp)
bcall(_cphlbc)
ret z ;all done
ld a,(hl)
and $1f
cp $05
jr z,VatStoreLoopPrgm
cp $06
jr nz,VatStoreLoopSkipName
VatStoreLoopPrgm:
push hl
ld bc,-6
add hl,bc ;de=-6
ld a,(hl)
ld (de),a
inc de
dec hl
ld b,a
VatStoreLoopPrgmName:
ld a,(hl)
ld (de),a
inc de
dec hl
djnz VatStoreLoopPrgmName
pop hl
VatStoreLoopSkipName:
ld bc,-6
add hl,bc
inc b
VatStoreLoopSkipName1:
dec hl
djnz VatStoreLoopSkipName1
jr VatStoreLoop
AppVarName:
.db AppVarObj,"PRGMS",0