SUBROUTINE TO ERASE AND WRITE A BYTE:

        ; NON EXECUTE HEADER
18 ce f4 9d ; LDY 0xF49D
c6 01       ; LDAB 0x01
ce ff b0    ; LDX loc_FFB0
ad 00       ; JSR,x+00
39          ; RTS

        ; LOAD CONFIG:
3C      ; PSHX  - save existing X register
B6 $value_storage_loc ; LDAA 6293 - load value to program into A
FE $address_storage_loc ; LDX 6294 - load eeprom offset to program into X

        ; COMPARE:
A1 00   ; CMPA,X - compare target value with existing value
27 10   ; BEQ +16  - jump to complete

        ; ERASE:
C6 16   ; LDAB 0x16 - program mode ELAT/BYTE/ERASE
8D 0F   ; BSR REL+15  - call program subroutine

        ; SKIP 0xFF:
81 FF   ; CMPA 0xFF   - see if A = 0xFF
27 04   ; BEQ REL+4  - jump to verify if equal

        ; PROGRAM:
C6 02   ; LDAB 0x02 - program mode ELAT
8D 07   ; BSR REL+7  - call program subroutine

        ; VERIFY:
A1 00   ; CMPA,X - compare A (value) with memory at X (destination)
26 F0   ; BNE REL-16 (restart operation if not the same)

        ; COMPLETE:
38      ; PULX  - restore X register
20 D6   ; BRA -42 back to reply header.
        
        ; PROGRAM SUBROUTINE (START) - ACCUMULATOR B = PROGRAMMING MODE.

        ; LATCH AND SET BYTE
F7 103B ; STAB 0x103B  - set eeprom control register from B
A7 00   ; STAA,x  - store A (value) at X (location) (write byte)

        ; SET EPGM (PROGRAM VOLTAGE)
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 REL-3 IF > 0
38      ; PULX  - restore X register

        ; COMPLETE
7F 103B ; CLR eeprom control register
39      ; RTS return
        ; PROGRAM SUBROUTINE (END)