2019-06-15 04:15:30 +10:00
|
|
|
; *** Consts ***
|
|
|
|
; Memory address where the AT28 is configured to start
|
|
|
|
.equ AT28W_MEMSTART 0x2000
|
|
|
|
|
|
|
|
; Value mismatch during validation
|
|
|
|
.equ AT28W_ERR_MISMATCH 0x10
|
|
|
|
|
|
|
|
; *** Variables ***
|
|
|
|
.equ AT28W_MAXBYTES AT28W_RAMSTART
|
2019-10-31 07:59:35 +11:00
|
|
|
.equ AT28W_RAMEND @+2
|
2019-06-15 04:15:30 +10:00
|
|
|
; *** Code ***
|
|
|
|
|
|
|
|
at28wMain:
|
|
|
|
ld de, .argspecs
|
|
|
|
ld ix, AT28W_MAXBYTES
|
|
|
|
call parseArgs
|
|
|
|
jr z, at28wInner
|
|
|
|
; bad args
|
|
|
|
ld a, SHELL_ERR_BAD_ARGS
|
|
|
|
ret
|
|
|
|
.argspecs:
|
|
|
|
.db 0b111, 0b101, 0
|
|
|
|
|
|
|
|
at28wInner:
|
2019-06-15 11:11:45 +10:00
|
|
|
; Reminder: words in parseArgs aren't little endian. High byte is first.
|
|
|
|
ld a, (AT28W_MAXBYTES)
|
|
|
|
ld b, a
|
|
|
|
ld a, (AT28W_MAXBYTES+1)
|
|
|
|
ld c, a
|
2019-06-15 04:15:30 +10:00
|
|
|
ld hl, AT28W_MEMSTART
|
2019-06-15 06:30:01 +10:00
|
|
|
call at28wBCZero
|
2019-06-15 04:15:30 +10:00
|
|
|
jr nz, .loop
|
2019-06-15 11:11:45 +10:00
|
|
|
; BC is zero, default to 0x2000 (8k, the size of the AT28)
|
2019-06-15 04:15:30 +10:00
|
|
|
ld bc, 0x2000
|
|
|
|
.loop:
|
2019-10-31 07:59:35 +11:00
|
|
|
call blkGetB
|
2019-06-15 04:15:30 +10:00
|
|
|
jr nz, .loopend
|
|
|
|
ld (hl), a
|
|
|
|
ld e, a ; save expected data for verification
|
|
|
|
; initiate polling
|
|
|
|
ld a, (hl)
|
|
|
|
ld d, a
|
|
|
|
.wait:
|
|
|
|
; as long as writing operation is running, IO/6 will toggle at each
|
|
|
|
; read attempt. We know that write is finished when we read the same
|
|
|
|
; value twice.
|
|
|
|
ld a, (hl)
|
|
|
|
cp d
|
|
|
|
jr z, .waitend
|
|
|
|
ld d, a
|
|
|
|
jr .wait
|
|
|
|
.waitend:
|
|
|
|
|
|
|
|
; same value was read twice. A contains our final value for this memory
|
|
|
|
; address. Let's compare with what we're written.
|
|
|
|
cp e
|
|
|
|
jr nz, .mismatch
|
|
|
|
inc hl
|
|
|
|
dec bc
|
2019-06-15 06:30:01 +10:00
|
|
|
call at28wBCZero
|
2019-06-15 04:15:30 +10:00
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
.loopend:
|
|
|
|
; We're finished. Success!
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.mismatch:
|
|
|
|
ld a, AT28W_ERR_MISMATCH
|
|
|
|
ret
|
|
|
|
|
2019-06-15 06:30:01 +10:00
|
|
|
at28wBCZero:
|
2019-06-15 04:15:30 +10:00
|
|
|
xor a
|
|
|
|
cp b
|
|
|
|
ret nz
|
|
|
|
cp c
|
|
|
|
ret
|
|
|
|
|