works 29f0x0 format

This commit is contained in:
Jakub Husak
2023-01-14 11:48:41 +01:00
parent 9197267cfb
commit 46d71033c3
7 changed files with 168 additions and 64 deletions
+52 -32
View File
@@ -14,7 +14,8 @@ m_offsets
flashoppreamble = 6
flash_lockchip = 9
flash_unlockchip = 12
flash_idstr = 15
flash_wait_unit = 15
flash_idstr = 18
; rw section, may be moved to ZP if needed
M_VECTOR .word 0
@@ -29,7 +30,7 @@ m_iter .byte 0
; 39sf0x0 protokol 5555/AA;2aaa/55
; 29f0x0 protokol 555/AA;2aa/55
; Working scan order; scanning from the end;
M_CHECK_VECS .word M_VECTORS_29F, M_VECTORS_39SF, M_VECTORS_28SF
M_CHECK_VECS .word M_VECTORS_39SF, M_VECTORS_29F, M_VECTORS_28SF
; --------------------------------------------------------------------
;Problems to solve with writing:
@@ -61,13 +62,13 @@ M_CHECK_VECS .word M_VECTORS_29F, M_VECTORS_39SF, M_VECTORS_28SF
; this fails only when somebody stores vendor and product bytes
; at the proper cells.
;
; then in the code we call lda #offset/jsr jsrtovetorproc
; then in the code we call lda #offset/jsr jsrtovectorproc
check_type
ldy #(2*(num_mems-1))
?again
sty m_iter
; store default values
sta $d500,x
jsr flashsetbank
lda $a000
sta m_vendor
lda $a001
@@ -75,7 +76,7 @@ check_type
jsr jsrtosoftidentry
sta $d500,x
jsr flashsetbank
lda $a000 ; vendor
cmp m_vendor
sta m_vendor
@@ -99,22 +100,26 @@ check_type
lda M_CHECK_VECS,y
sta M_VECTOR
jsrtosoftidexit
lda #softid_exit
jsr jsrtovetorproc
jsr jsrtovectorproc
lda $d013
sta $3fa
clc
rts
jsrtosoftidentry
lda M_CHECK_VECS+1,y ; first is softid entry
pha
lda M_CHECK_VECS,y ; first is softid entry
pha
php
rti ; jsr to tabled func
lda M_CHECK_VECS+1,y ; first is softid entry
pha
lda M_CHECK_VECS,y ; first is softid entry
pha
php
rti ; jsr to tabled func
; PROCEDURE
; performs jump to vector table at offset in A provided
; y passed to the procedure called
jsrtovetorproc
jsrtovectorproc
php ; preserve C
clc
adc M_VECTOR
@@ -141,14 +146,9 @@ flashformatchip
sei
stx store_x
; lda #C_FORMAT
sec
sec ; will format flash!
lda #flashoppreamble
jsr jsrtovetorproc ; does not touch A
;sta $d502,x
; !!!!!!!!!!!!!!!!!!! CHECK THIS !!!!!!!!!!!!!!!!!!!!
;lda #TRIGGER_FORMAT
;sta $b555 ; FORMAT HERE TRIGGERED!
jsr jsrtovectorproc ; preserves A
; not needed to mva $ff flashcmp
jsr wait4flashcheckresult ; waits for format finished
; then check number of banks for FFs
@@ -186,7 +186,7 @@ flashformatsector
stx flashformatstorex
sta flashformatstorea
sei
sta $d500,x
jsr flashsetbank
; store #$a0 or #$b0
sta flashformataddrcheck + 2
jsr flashchecksectorformatted
@@ -197,7 +197,7 @@ flashformatstorex equ * + 1
; check least sector bit
sec
lda #flashoppreamble ; does not touch A,X
jsr jsrtovetorproc
jsr jsrtovectorproc
sta $D500,x
; A must be either $A0 or $B0
flashformatstorea equ * + 1
@@ -215,7 +215,7 @@ flashtmpaddr equ *+1
sta flashformataddrcheck+2
ldx flashformatstorex
sta $d500,x
jsr flashsetbank
; check if all data in sector is $ff
flashchecksectorformatted
@@ -265,9 +265,9 @@ byte_differs
sta flashcmp
sei
pha
clc ; byte preamble
clc ; byte program preamble
lda #flashoppreamble ; preserves A,X
jsr jsrtovetorproc
jsr jsrtovectorproc
pla
; set right bank
sta $D500,x
@@ -276,10 +276,12 @@ byte_differs
wait4flashcheckresult ; sei mode
mva #0 flashcnt
sta flashcnt+1
ldy #1 ; first time wait short first turn to speed up byte write.
bne @+
flashwaitfordone
; WARNING! 29f040 erases even 10 seconds!
; approx 100ms in overall for chip erase:
; as many cycles needed, as 256*cycles >100ms * (1+epsilon)
; 100 ms is 180000 cycles
@@ -289,26 +291,38 @@ flashwaitfordone
; so flipipng values, and adding margin,
; we count 128*6 cycles in inner loop.
; max sector erase by datasheet: 25 ms
; max chip erase by datasheet: 100 ms
; max chip erase by datasheet: 100 ms 39sf040
; max chip erase by datasheet: 20 ms 28sf040
; max chip erase by datasheet: 10000 ms 29f040
ldy#250
@ dey
nop
@
;lda #flash_wait_unit
;jsr jsrtovectorproc
inc colbaks
lda colbaks
sta colbak
dey
bne @-
@ ldy #{ lda.w }
@
ldy #{ lda.w }
jsr flashprocessbyte
sta flashval
ldy #{ eor.w }
jsr flashprocessbyte
inc flashcnt
bne @+
sta $d580
inc flashcnt+1
bne @+
jsr flashcartoff
lda #$ff ; status
rts
@
and #$40
bne flashwaitfordone
sta $d580
jsr flashcartoff
flashval equ *+1
lda #0
flashcmp equ *+1
@@ -317,7 +331,7 @@ flashcmp equ *+1
rts
flashcnt
dta 0
dta 0,0
; ----------------------
; PROCEDURE
@@ -340,6 +354,12 @@ flashsetaddr
sty flashaddr+1
rts
flashsetbank
sta $d500,x
lda $d013
sta $3fa
rts
flashcartoff
pha
sta $d580
+6 -2
View File
@@ -1,7 +1,6 @@
C_FORMAT_28SF equ $30
C_BYTE_PROG_28SF equ $10
M_SSIZE_28SF equ $0100 ; sector size
; store
;
M_VECTORS_28SF
jmp softid_entry_28SF
@@ -9,6 +8,7 @@ M_VECTORS_28SF
jmp flashoppreamble_28SF
jmp flash_lockchip_28SF
jmp flash_unlockchip_28SF
jmp flash_wait_unit_28SF
dta c'28SF0x0',0
flashoppreamble_28SF
@@ -23,6 +23,7 @@ flashoppreamble_28SF
flashoppreamble_acc_28SF ; 28SF0x0
sta $d500,x
sta $a000
flash_wait_unit_28SF
rts
;read_manufacturer_28SF
; sta $D500,x ; x=0 or $40 else will read wrong
@@ -41,12 +42,15 @@ flash_unlockchip_28SF
rts
softid_entry_28SF
sta $d500,x
lda #$90
sta $a000
rts
softid_exit_28SF
lda #$ff
sta $a000
rts
flash_lockchip_28SF
sta $D500,x ; x =0 or $40, else will not unlock
jsr flash_lock_preamb_28SF
+13 -1
View File
@@ -10,6 +10,7 @@ M_VECTORS_29F
jmp flashoppreamble_29F
jmp flash_lockchip_29F
jmp flash_unlockchip_29F
jmp flash_wait_unit_29F
dta c'29F0x0',0
flashoppreamble_29F
@@ -30,7 +31,7 @@ flashoppreamble_acc_29F ; 29F040
sta $d500,x
mva #$aa $a555 ; $555<$aa
mva #$55 $a2aa ; $2aa<$55
; $555<$80
; $555<$80 or $A0
mva command_ZP_29F $a555; will become command: FORMAT/ID_MODE/BYTE_PROG
cmp #C_FORMAT_29F
bne @+ ; if not FORMAT, procedure finishes
@@ -44,6 +45,17 @@ flash_lockchip_29F
flash_unlockchip_29F
rts
flash_wait_unit_29F
bit VCOUNT
bmi *-3
bit VCOUNT
bpl *-3
bit VCOUNT
bmi *-3
bit VCOUNT
bpl *-3
rts
;read_manufacturer_29F
; sta $D500,x ; x=0 or $40 else will read wrong
; lda $a000
+2
View File
@@ -10,6 +10,7 @@ M_VECTORS_39SF
jmp flashoppreamble_39SF
jmp flash_lockchip_39SF
jmp flash_unlockchip_39SF
jmp flash_wait_unit_29F
dta c'39SF0x0',0
flashoppreamble_39SF
@@ -47,6 +48,7 @@ flashoppreamble_acc_39SF ; 39sf0x0, 29F040
tax
flash_lockchip_39SF
flash_unlockchip_39SF
flash_wait_unit_39SF
rts
;read_manufacturer_39SF
+18 -25
View File
@@ -3,6 +3,7 @@
; dta c'Ala ma kota',$9b,0
; next instructions
print .proc
stx ?_tmpx
clc
pla
adc #$01
@@ -22,40 +23,32 @@ print .proc
?prt jsr $f2b0
inw ?strv
bne ?strv-1
ldx ?_tmpx:#0
rts
.endp
printhex .proc
jsr lHex
sta ?printhextmp
txa
pha
stx ?_tmpx
:4 lsr
jsr HEX2INT
jsr $f2b0
pla
and #$0f
jsr HEX2INT
jsr $f2b0
ldx ?_tmpx
rts
?_tmpx .byte 0
?printhextmp equ * +1
lda #$ff
jmp $f2b0
.endp
lHex .proc
// po deklaracji procedury .PROC z parametrami, automatycznie wymuszone zostaje wykonanie
// makra @PULL, ktore zdejmie za nas parametry ze stosu programowego i umiesci je w pamieci
// od adresu @PROC_VARS_ADR, etykiecie parametru LOW zostaje przypisany adres @PROC_VARS_ADR
pha
:4 lsr @
jsr HEX2INT
tax ; wynik dzialania w regX
pla
and #$0f
HEX2INT SED
HEX2INT
php
sei
SED
CMP #$0A
ADC #'0'
CLD
plp
; wynik dzialania w regA
rts
.endp
Binary file not shown.
+75 -2
View File
@@ -34,6 +34,7 @@ _DEST equ $A000
; test code
org $2000
STARTFLASHWRITE
mva #$A0 106
jsr opened
lda 20
@@ -55,6 +56,72 @@ _DEST equ $A000
lda $d013
sta $3fa
ldx #0 ; chip address
stx numchips
_check_chips
stx _storex
jsr check_type
bcc ?_next
jsr print
dta c'unrecognized chip: ',0
lda m_vendor
jsr printhex
lda m_kind
jsr printhex
cpx #$0
seq
jmp *
jsr print
dta c'ignoring chip ...',0
jmp menu
?_next inc numchips
lda numchips
clc
adc #$30
sta chipno
jsr print
dta c'chip '
chipno
dta c'0'
dta c' vend/prod: ',0
lda m_vendor
jsr printhex
lda m_kind
jsr printhex
jsr print
dta c' code: ',0
; print memory type
lda M_VECTOR
clc
adc #flash_idstr ; will print flashmem text id
sta ?taddr
lda M_VECTOR+1
adc #0
sta ?taddr+1
ldy #0
?loop ; write string onscreen till 0
lda ?taddr:$ffff,y
beq ?exit
sty st_y
jsr outchar
ldy st_y:#0
iny
bne ?loop
?exit
jsr printnl
ldx _storex
cpx #0
bne menu
lda m_vendor
sta t_vendor
lda m_kind
sta t_kind
ldx #$40
jmp _check_chips
menu
jsr printnl
;lda #$ff
;sta $d301
@@ -110,6 +177,12 @@ CHECKONLY
jsr print
dta c'Compare.',$9b,0
rts
t_vendor .byte 0
t_kind .byte 0
numchips .byte 0
_storex .byte 0
crcsums
:128 dta 0,0
opened
@@ -344,7 +417,7 @@ badcompare_tmp2 equ * +1
sec
jmp dmaon
; -------
icl '../../lib/flashwritelib.asx'
icl '../../lib/flashwritelib_new.asx'
icl '../../lib/crc16_v2.asm'
@@ -357,7 +430,7 @@ badcompare_tmp2 equ * +1
;jmp *
icl '../../lib/print2.asx'
org $2e2
dta a($2000)
dta a(STARTFLASHWRITE)
; ---------------------------------------
; blocks for every 8kb bank
.rept 128, #