Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .def _doUnlock
- .def _doLock
- .def _doErase
- .def _doWrite
- .def _doReset
- _doUnlock:
- assume adl = 1
- ld a, $D1
- ld mb, a ;Set mbase to userMem
- call.is .unlock and $FFFF ;call unlock in Z80 mode
- ret
- .unlock:
- assume adl = 0
- ld a, $FF
- out0 ($24), a ;Sets the memory protection upper range's middle byte
- ld c, 4 ;4 = 0x100. Unlocks protected ports (SHA256/Flash)
- in0 a,(6) ;Get the value in port 6
- or c ;Do the unlock without changing other bits in port 6
- out0 (6), a
- out0 (28), c ;Finally unlock flash. It just so happens that c (0x100) is the right value for unlocking flash.
- ret.l ;Return back to ADL mode.
- _doLock:
- assume adl = 1
- ld a, $D1
- ld mb, a ;Set mbase to userMem
- call.is .lock and $FFFF ;call unlock in Z80 mode
- ret
- .lock:
- assume adl = 0
- in0 a, (6) ;Get value in port 6
- res 2, a ;Locks protected ports. This also locks flash automatically.
- out0 (6), a
- ld a, $88 ;Disables privilege
- out0 ($24), a
- ret.l ;Return back to ADL mode.
- _doErase:
- assume adl = 1
- ld iy, 0 ;Get 1st C arg into A
- add iy, sp
- ld a, (iy+3)
- ld bc, $F8 ;0xF8: This is a jmp to a ret instruction
- push bc
- jp $2DC ;EraseFlashSector. We don't use call so we can override the return address to convince it to run
- _doWrite:
- assume adl = 1
- ld iy, 0 ;Get C args
- add iy, sp
- ld de, (iy+3)
- ld b, (iy+6)
- call $2D4 ;Write a byte
- ret
- _doReset:
- assume adl = 1
- jp 0 ;Reset the calculator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement