It seems to me that you should put your levels in archives programs or archived Appvars, then just directly RLE unpack them into your RAM level area. As I told you on IRC, I have Doors CS routines that make it simple to iterate over variables in Flash just as if they were in RAM, fetching one byte at a time. I think trying to pack your levels into a separate App is going to make your life much harder, though, unless I misunderstand what you're saying.
Anyway, variables in Flash are, unlike variables in RAM, stored with a copy of their VAT entries before the actual data. The purpose of this is to make it easy to rebuild the VAT on a RAM Clear: simply iterate through all user Flash pages, copy out each VAT entry found into a new VAT, point it to the right place, and voila, a proper list of all the Archived variables. Anyway, for my routines, you first need to do a ChkFindSym, to set up
hl and
de. As Tari said, this will fill in register
b with the page of the variable (or 0 for RAM), and
a with 0 if in RAM, non-zero otherwise. The following routines are built to work the same regardless of whether the variable is in RAM or Flash:
Code: SetUpROM:
ld a,(CurROMPage)
or a
ret z
push de
ld de,9
add hl,de
call GetArcProgByte
ld d,0
inc a
ld e,a
add hl,de
pop de
ret
GetArcProgByte:
push de
push bc
push hl
ld a,(CurROMPage)
or a
jr z,GetArcProgByteReg
ld b,a
call AutoArcPtrUpdate
bcall(_LoadCIndPaged)
ld a,c
GetArcProgByteFinishHL:
pop hl
GetArcProgByteFinish:
pop bc
pop de
ret
GetArcProgByteReg:
pop hl
ld a,(hl)
jr GetArcProgByteFinish
GetArcProgByteDE:
push de
push bc
push hl
ld a,(CurROMPage)
or a
jr z,GetArcProgByteRegDE
ld b,a
ex de,hl
call AutoArcPtrUpdate
bcall(_LoadCIndPaged)
ld a,c
jr GetArcProgByteFinishHL
GetArcProgByteRegDE:
pop hl
pop bc
pop de
ld a,(de)
ret
GetArcProgWord:
push de
push bc
ld a,(CurROMPage)
or a
jr z,GetArcProgWordReg
ld b,a
call AutoArcPtrUpdate
bcall(_LoadDEIndPaged)
ex de,hl
pop bc
pop de
ret
GetArcProgWordReg:
pop bc
pop de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a ;_ldhlind
ret
AutoArcPtrUpdate:
bit 7,h
ret z
inc b
res 7,h
set 6,h
ret
Important notes:
:: Please excuse any inefficiencies. I wrote these many years ago.
:: I use a one-byte variable, (CurROMPage), to store the page of the current variable, which may change as you read forward, if you hit a page boundary. It you use my routines verbatim, load b into (CurROMPage) after you ChkFindSym.
:: GetArcProgByte gets 1 byte into a and increments the read pointer. GetArcProgWord gets 1 byte into hl and increments the read pointer twice. GetArcProgByteDE looks like something I should have optimized out years ago...
Let me know if you have any questions.