soeren gust <sgus-@...> wrote:
original article:http://www.egroups.com/group/vmu-dev/?start=29
> Is there a way to use writeflash (at .org $100) to write at the
FAT/DIRECTORY?
No. There is a check that prevents you from writing outside the game
file iself. _However_, there is another BIOS vector you can use which
does not have this limitation. It's a bit tricky to call though, as it
doesn't have any code to return to the game ROM bank. Here's some code
you might find useful:
;; Firmware entry vectors
.org $100
fm_wrt_ex:
not1 ext,0
jmpf fm_wrt_ex
ret
.org $110
fm_vrf_ex:
not1 ext,0
jmpf fm_vrf_ex
ret
.org $120
fm_prd_ex:
not1 ext,0
jmpf fm_prd_ex
ret
.org $130
int3_btr_irq:
push ie
clr1 ie,7
not1 ext,0
jmpf int3_btr_irq
pop ie
reti
;[...]
;; Low level access functions
fwcall .macro
mov #<$0123,0
push 0
mov #>$0123,0
push 0
not1 ext,0
jmpf \1
.endm
bios_rflash:
fwcall $e027
bios_vflash:
fwcall $e01b
;; Danger Will Robinson!
;;
;; This call gives direct access to the flashmem write
;; function. All safeguards will be bypassed.
bios_wflash:
fwcall $e024
;; Write a quarter of a sector.
;;
;; trh,trl = sector number, acc = part (0-3)
;; returns: 0 = ok, not 0 = not ok
write_page:
bp trh,7,.bad_sector
push 0
push trh
push trl
push b
push c
callf calc_page_addr
push ie
push ocr
push xbnk
clr1 ie,7
mov #$81,ocr
mov #2,xbnk
push xram+4
set1 xram+4,0
mov #0,$7c
callf bios_wflash
callf bios_vflash
pop xram+4
pop xbnk
pop ocr
pop ie
pop c
pop b
pop trl
pop trh
pop 0
ret
.bad_sector:
mov #$ff,acc
ret
;; Read a quarter of a sector.
;;
;; trh,trl = sector number, acc = part (0-3)
read_page:
bp trh,7,.bad_sector
push 0
push trh
push trl
callf calc_page_addr
push ie
push ocr
clr1 ie,7
mov #$81,ocr
callf bios_rflash
pop ocr
pop ie
pop trl
pop trh
pop 0
ret
.bad_sector:
ret
calc_page_addr:
rorc
and #1
st $7e
rorc
st $7f
ld trl
rolc
and #$fe
or $7e
st $7e
ld trh
rolc
st $7d
ret
Not actually tested or anything... :-)
// Marcus