External Levels/Files
Xeda Elnara 12 Mar 2013 04:29
For your code accessing the files, here is some code that might be useful:
ld hl,Name
rst rMov9ToOP1
bcall(_ChkFindSym)
jr c,FileNotFound
ld a,b
ld b,0
or a
jr z,SizeBytes
add hl,bc
ld c,10
add hl,bc
jp m,SizeBytes
inc a
ld h,40h
SizeBytes:
;at this point, A is the flash page the data is on (or 0 if in RAM)
;HL points to the size bytes
Now from here, you have two options. If you are working from an App, you will probably either want to copy archive reading code to RAM, or use a bcall like _FlashToRAM or _FlashToRAM2. If it is a program in RAM, I would combine it all like this:
ld hl,Name
rst rMov9ToOP1
bcall(_ChkFindSym)
jr c,FileNotFound
in a,(6)
push af ;save the current flash page
ld a,b
ld b,0
or a
jr z,SizeBytes
add hl,bc
ld c,10
add hl,bc
jp m,SizeBytes
inc a
ld h,40h
SizeBytes:
out (6),a
ld c,(hl)
inc l
call z,AdjustAHL
ld b,(hl)
inc l
call z,AdjustAHL
ex (sp),hl
ld l,a
ld a,h
out (6),a
ld a,l
pop hl
;now AHL points to the variable data, BC is the size of the data
;You can either copy the rest of the data to a temp variable or to saferam, or whatever, but the original variable can remain archived or unarchived
<<rest of code>>
And the call AdjustAHL would be this:
inc h
ret m
inc a
out (6),a
ld hl,40h
ret
And you could similarly create your own archive reading routine:
ReadArc:
;Inputs:
; A is the flash page on which to read (or 0 if in RAM)
; HL points to the data to read
; DE points to where to copy the data
; BC is the number of bytes to copy
;Outputs:
; BC is 0
or a
jr nz,FlashPageRead
ld a,b
or c
ret z
ldir
ret
FlashPageRead:
push hl
ld l,a
ld a,b
or c
jr z,Pop1Exit
in a,(6)
ld h,a
ld a,l
ex (sp),hl
out (6),a
ArcReadLoop:
ldi
jp po,ExitArcRead
bit 7,h
jr nz,ArcReadLoop
ld h,40h
inc a
out (6),a
jp ArcReadLoop ;JP is one byte larger than JR, but 2 t-states faster
ExitArcRead:
pop af
out (6),a
ret
Pop1Exit:
pop hl
ret
Also, sorry if that code is broken, I am really tired at the moment.
Z80 Assembly>English>TI-BASIC>Python>French>C>0