406
; Execute erase-verify
EVR: MOV.W #RAMSTR, R2
MOV.W #ERVADR, R3
ADD.W R3, R2
MOV.W #START, R3
SUB.W R3, R2
; Starting transfer destination address (RAM)
;
; #RAMSTR + #ERVADR
→
R2
;
; Address of data area used in RAM
MOV.B #H'00, R1L
MOV.B #H'b, R4H
BSET #3, @FLMCR:8
; Set EV bit
LOOPEV: DEC R4H
BNE LOOPEV
EBRTST: CMP.B #H'0C, R1L
BEQ HANTEI
CMP.B #H'08, R1L
BMI EBR2EV
MOV.B R1L, R1H
SUBX #H'08, R1H
BTST R1H, R0H
BNE ERSEVF
BRA ADD01
EBR2EV: BTST R1L, R0L
BNE ERSEVF
ADD01: INC R1L
MOV.W @R2+, R3
BRA EBRTST
; Used to test R1L bit in R0
; Set erase-verify loop counter
;
; Wait loop
; R1L = H'0C
; If finished checking all R0 bits, branch to HANTEI
;
; Test EBR1 if R1L
≥
8, or EBR2 if R1L < 8
;
; R1L – 8
→
R1H
; Test R1H bit in EBR1 (R0H)
; If R1H bit in EBR1 (R0H) is 1, branch to ERSEVF
; If R1H bit in EBR1 (R0H) is 0, branch to ADD01
; Test R1L bit in EBR2 (R0L)
; If R1L bit in EBR2 (R0H) is 1, branch to ERSEVF
; R1L + 1
→
R1L
; Dummy-increment R2
;
ERASE1: BRA ERASE
; Branch to ERASE via Erase 1
ERSEVF: MOV.W @R2+, R3
EVR2: MOV.B #H'FF, R1H
MOV.B R1H, @R3
MOV.B #H'c, R4H
LOOPEP: DEC R4H
BNE LOOPEP
MOV.B @R3+, R1H
CMP.B #H'FF, R1H
BNE BLKAD
MOV.W @R2, R4
CMP.W R4, R3
BNE EVR2
; Top address of block to be erase-verified
;
; Dummy write
; Set erase-verify loop counter
;
; Wait loop
; Read
; Read data = H'FF
; If read data
≠
H'FF branch to BLKAD
; Top address of next block
; Last address of block
CMP.B #H'08, R1L
BMI SBCLR
MOV.B R1L, R1H
SUBX #H'08, R1H
BCLR R1H, R0H
BRA BLKAD
SBCLR: BCLR R1L, R0L
BLKAD: INC R1L
BRA EBRTST
; Test EBR1 if R1L
≥
8, or EBR2 if R1L < 8
;
; R1L – 8
→
R1H
; Clear R1H bit in EBR1 (R0H)
; Clear R1L bit in EBR2 (R0L)
; R1L + 1
→
R1L
;
HANTEI: BCLR #3, @FLMCR:8
; Clear EV bit
MOV.W R0, @EBR1
BEQ EOWARI
;
; If EBR1/EBR2 is all 0, erasing ended normally