i wrote this sub as a better way of accomplishing a series of single byte modifications to the EEPROM with minimal aldl overhead
after this sub is in ram each instruction from flashhack need only contain: JMP subroutine_address value address
it adheres to the standards of the datasheet - erase, delay 10 ms, write, delay 10 ms, compare, and loops if the write is incorrect
i wrote it to be relocatable with no extended addressing except for the static upload addresses (first few lines) so should work for EE, the CCM, or any 68hcwhatever with onboard eeprom.
.. it's also only 43 bytes so can be easily uploaded in a single mode 6 command
Code:
; LOAD CONFIG:
3C ; PSHX - save existing X register
B6 $value_storage_loc ; LDAA xxxx - load value to program into A
FE $address_storage_loc ; LDX xxxx - load eeprom offset to program into X
; ERASE:
C6 16 ; LDAB 0x16 - program mode ELAT/BYTE/ERASE
8D 0A ; BSR +10 - call program subroutine
; PROGRAM:
C6 16 ; LDAB 0x02 - program mode ELAT
8D 06 ; BSR +6 - call program subroutine
; VERIFY:
A1 00 ; CMPA,X - compare A (value) with memory at X (destination)
26 F4 ; BNE -12 (to ERASE) if compare fails.
; COMPLETE:
38 ; PULX - restore X register
39 ; RTS return
; PROGRAM (start subroutine)
F7 103B ; STAB 0x103B - set eeprom control register from B
A7 00 ; STAA,x - store A (value) at X (location) (write byte)
CA 01 ; ORA 0x01 - set EPGM (bit 1) in B
F7 103B ; STAB 0x103B - set eeprom control register from B
; DELAY
3C ; PSHX - save X register
CE 0D06 ; LDX 0xD06 - loop total exec time approx 10ms @ 2mhz clock (6 cycles in loop)
09 ; DEX - x--
26 FD ; BNE -3 > 0
38 ; PULX - restore X register
; COMPLETE
7F 013B ; CLR eeprom control register
39 ; RTS return
; PROGRAM (end subroutine)
Bookmarks