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
+53 -33
View File
@@ -14,7 +14,8 @@ m_offsets
flashoppreamble = 6 flashoppreamble = 6
flash_lockchip = 9 flash_lockchip = 9
flash_unlockchip = 12 flash_unlockchip = 12
flash_idstr = 15 flash_wait_unit = 15
flash_idstr = 18
; rw section, may be moved to ZP if needed ; rw section, may be moved to ZP if needed
M_VECTOR .word 0 M_VECTOR .word 0
@@ -29,7 +30,7 @@ m_iter .byte 0
; 39sf0x0 protokol 5555/AA;2aaa/55 ; 39sf0x0 protokol 5555/AA;2aaa/55
; 29f0x0 protokol 555/AA;2aa/55 ; 29f0x0 protokol 555/AA;2aa/55
; Working scan order; scanning from the end; ; 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: ;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 ; this fails only when somebody stores vendor and product bytes
; at the proper cells. ; 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 check_type
ldy #(2*(num_mems-1)) ldy #(2*(num_mems-1))
?again ?again
sty m_iter sty m_iter
; store default values ; store default values
sta $d500,x jsr flashsetbank
lda $a000 lda $a000
sta m_vendor sta m_vendor
lda $a001 lda $a001
@@ -75,7 +76,7 @@ check_type
jsr jsrtosoftidentry jsr jsrtosoftidentry
sta $d500,x jsr flashsetbank
lda $a000 ; vendor lda $a000 ; vendor
cmp m_vendor cmp m_vendor
sta m_vendor sta m_vendor
@@ -99,22 +100,26 @@ check_type
lda M_CHECK_VECS,y lda M_CHECK_VECS,y
sta M_VECTOR sta M_VECTOR
jsrtosoftidexit
lda #softid_exit lda #softid_exit
jsr jsrtovetorproc jsr jsrtovectorproc
lda $d013
sta $3fa
clc clc
rts rts
jsrtosoftidentry jsrtosoftidentry
lda M_CHECK_VECS+1,y ; first is softid entry lda M_CHECK_VECS+1,y ; first is softid entry
pha pha
lda M_CHECK_VECS,y ; first is softid entry lda M_CHECK_VECS,y ; first is softid entry
pha pha
php php
rti ; jsr to tabled func rti ; jsr to tabled func
; PROCEDURE ; PROCEDURE
; performs jump to vector table at offset in A provided ; performs jump to vector table at offset in A provided
; y passed to the procedure called ; y passed to the procedure called
jsrtovetorproc jsrtovectorproc
php ; preserve C php ; preserve C
clc clc
adc M_VECTOR adc M_VECTOR
@@ -141,14 +146,9 @@ flashformatchip
sei sei
stx store_x stx store_x
; lda #C_FORMAT sec ; will format flash!
sec
lda #flashoppreamble lda #flashoppreamble
jsr jsrtovetorproc ; does not touch A jsr jsrtovectorproc ; preserves A
;sta $d502,x
; !!!!!!!!!!!!!!!!!!! CHECK THIS !!!!!!!!!!!!!!!!!!!!
;lda #TRIGGER_FORMAT
;sta $b555 ; FORMAT HERE TRIGGERED!
; not needed to mva $ff flashcmp ; not needed to mva $ff flashcmp
jsr wait4flashcheckresult ; waits for format finished jsr wait4flashcheckresult ; waits for format finished
; then check number of banks for FFs ; then check number of banks for FFs
@@ -186,7 +186,7 @@ flashformatsector
stx flashformatstorex stx flashformatstorex
sta flashformatstorea sta flashformatstorea
sei sei
sta $d500,x jsr flashsetbank
; store #$a0 or #$b0 ; store #$a0 or #$b0
sta flashformataddrcheck + 2 sta flashformataddrcheck + 2
jsr flashchecksectorformatted jsr flashchecksectorformatted
@@ -197,7 +197,7 @@ flashformatstorex equ * + 1
; check least sector bit ; check least sector bit
sec sec
lda #flashoppreamble ; does not touch A,X lda #flashoppreamble ; does not touch A,X
jsr jsrtovetorproc jsr jsrtovectorproc
sta $D500,x sta $D500,x
; A must be either $A0 or $B0 ; A must be either $A0 or $B0
flashformatstorea equ * + 1 flashformatstorea equ * + 1
@@ -215,7 +215,7 @@ flashtmpaddr equ *+1
sta flashformataddrcheck+2 sta flashformataddrcheck+2
ldx flashformatstorex ldx flashformatstorex
sta $d500,x jsr flashsetbank
; check if all data in sector is $ff ; check if all data in sector is $ff
flashchecksectorformatted flashchecksectorformatted
@@ -231,7 +231,7 @@ flashformataddrcheck
inc flashformataddrcheck + 2 inc flashformataddrcheck + 2
dey dey
bne flashformataddrcheck bne flashformataddrcheck
flashsectorformatgood flashsectorformatgood
jsr flashcartoff jsr flashcartoff
clc clc
@@ -265,9 +265,9 @@ byte_differs
sta flashcmp sta flashcmp
sei sei
pha pha
clc ; byte preamble clc ; byte program preamble
lda #flashoppreamble ; preserves A,X lda #flashoppreamble ; preserves A,X
jsr jsrtovetorproc jsr jsrtovectorproc
pla pla
; set right bank ; set right bank
sta $D500,x sta $D500,x
@@ -276,10 +276,12 @@ byte_differs
wait4flashcheckresult ; sei mode wait4flashcheckresult ; sei mode
mva #0 flashcnt mva #0 flashcnt
sta flashcnt+1
ldy #1 ; first time wait short first turn to speed up byte write. ldy #1 ; first time wait short first turn to speed up byte write.
bne @+ bne @+
flashwaitfordone flashwaitfordone
; WARNING! 29f040 erases even 10 seconds!
; approx 100ms in overall for chip erase: ; approx 100ms in overall for chip erase:
; as many cycles needed, as 256*cycles >100ms * (1+epsilon) ; as many cycles needed, as 256*cycles >100ms * (1+epsilon)
; 100 ms is 180000 cycles ; 100 ms is 180000 cycles
@@ -289,26 +291,38 @@ flashwaitfordone
; so flipipng values, and adding margin, ; so flipipng values, and adding margin,
; we count 128*6 cycles in inner loop. ; we count 128*6 cycles in inner loop.
; max sector erase by datasheet: 25 ms ; 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 ldy#250
@ dey @
nop ;lda #flash_wait_unit
;jsr jsrtovectorproc
inc colbaks
lda colbaks
sta colbak
dey
bne @- bne @-
@ ldy #{ lda.w } @
ldy #{ lda.w }
jsr flashprocessbyte jsr flashprocessbyte
sta flashval sta flashval
ldy #{ eor.w } ldy #{ eor.w }
jsr flashprocessbyte jsr flashprocessbyte
inc flashcnt inc flashcnt
bne @+ bne @+
sta $d580 inc flashcnt+1
bne @+
jsr flashcartoff
lda #$ff ; status lda #$ff ; status
rts rts
@ @
and #$40 and #$40
bne flashwaitfordone bne flashwaitfordone
sta $d580 jsr flashcartoff
flashval equ *+1 flashval equ *+1
lda #0 lda #0
flashcmp equ *+1 flashcmp equ *+1
@@ -317,7 +331,7 @@ flashcmp equ *+1
rts rts
flashcnt flashcnt
dta 0 dta 0,0
; ---------------------- ; ----------------------
; PROCEDURE ; PROCEDURE
@@ -340,6 +354,12 @@ flashsetaddr
sty flashaddr+1 sty flashaddr+1
rts rts
flashsetbank
sta $d500,x
lda $d013
sta $3fa
rts
flashcartoff flashcartoff
pha pha
sta $d580 sta $d580
+6 -2
View File
@@ -1,7 +1,6 @@
C_FORMAT_28SF equ $30 C_FORMAT_28SF equ $30
C_BYTE_PROG_28SF equ $10 C_BYTE_PROG_28SF equ $10
M_SSIZE_28SF equ $0100 ; sector size M_SSIZE_28SF equ $0100 ; sector size
; store
; ;
M_VECTORS_28SF M_VECTORS_28SF
jmp softid_entry_28SF jmp softid_entry_28SF
@@ -9,6 +8,7 @@ M_VECTORS_28SF
jmp flashoppreamble_28SF jmp flashoppreamble_28SF
jmp flash_lockchip_28SF jmp flash_lockchip_28SF
jmp flash_unlockchip_28SF jmp flash_unlockchip_28SF
jmp flash_wait_unit_28SF
dta c'28SF0x0',0 dta c'28SF0x0',0
flashoppreamble_28SF flashoppreamble_28SF
@@ -23,6 +23,7 @@ flashoppreamble_28SF
flashoppreamble_acc_28SF ; 28SF0x0 flashoppreamble_acc_28SF ; 28SF0x0
sta $d500,x sta $d500,x
sta $a000 sta $a000
flash_wait_unit_28SF
rts rts
;read_manufacturer_28SF ;read_manufacturer_28SF
; sta $D500,x ; x=0 or $40 else will read wrong ; sta $D500,x ; x=0 or $40 else will read wrong
@@ -41,12 +42,15 @@ flash_unlockchip_28SF
rts rts
softid_entry_28SF softid_entry_28SF
sta $d500,x
lda #$90 lda #$90
sta $a000 sta $a000
rts rts
softid_exit_28SF softid_exit_28SF
lda #$ff
sta $a000
rts
flash_lockchip_28SF flash_lockchip_28SF
sta $D500,x ; x =0 or $40, else will not unlock sta $D500,x ; x =0 or $40, else will not unlock
jsr flash_lock_preamb_28SF jsr flash_lock_preamb_28SF
+13 -1
View File
@@ -10,6 +10,7 @@ M_VECTORS_29F
jmp flashoppreamble_29F jmp flashoppreamble_29F
jmp flash_lockchip_29F jmp flash_lockchip_29F
jmp flash_unlockchip_29F jmp flash_unlockchip_29F
jmp flash_wait_unit_29F
dta c'29F0x0',0 dta c'29F0x0',0
flashoppreamble_29F flashoppreamble_29F
@@ -30,7 +31,7 @@ flashoppreamble_acc_29F ; 29F040
sta $d500,x sta $d500,x
mva #$aa $a555 ; $555<$aa mva #$aa $a555 ; $555<$aa
mva #$55 $a2aa ; $2aa<$55 mva #$55 $a2aa ; $2aa<$55
; $555<$80 ; $555<$80 or $A0
mva command_ZP_29F $a555; will become command: FORMAT/ID_MODE/BYTE_PROG mva command_ZP_29F $a555; will become command: FORMAT/ID_MODE/BYTE_PROG
cmp #C_FORMAT_29F cmp #C_FORMAT_29F
bne @+ ; if not FORMAT, procedure finishes bne @+ ; if not FORMAT, procedure finishes
@@ -44,6 +45,17 @@ flash_lockchip_29F
flash_unlockchip_29F flash_unlockchip_29F
rts 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 ;read_manufacturer_29F
; sta $D500,x ; x=0 or $40 else will read wrong ; sta $D500,x ; x=0 or $40 else will read wrong
; lda $a000 ; lda $a000
+2
View File
@@ -10,6 +10,7 @@ M_VECTORS_39SF
jmp flashoppreamble_39SF jmp flashoppreamble_39SF
jmp flash_lockchip_39SF jmp flash_lockchip_39SF
jmp flash_unlockchip_39SF jmp flash_unlockchip_39SF
jmp flash_wait_unit_29F
dta c'39SF0x0',0 dta c'39SF0x0',0
flashoppreamble_39SF flashoppreamble_39SF
@@ -47,6 +48,7 @@ flashoppreamble_acc_39SF ; 39sf0x0, 29F040
tax tax
flash_lockchip_39SF flash_lockchip_39SF
flash_unlockchip_39SF flash_unlockchip_39SF
flash_wait_unit_39SF
rts rts
;read_manufacturer_39SF ;read_manufacturer_39SF
+18 -25
View File
@@ -3,6 +3,7 @@
; dta c'Ala ma kota',$9b,0 ; dta c'Ala ma kota',$9b,0
; next instructions ; next instructions
print .proc print .proc
stx ?_tmpx
clc clc
pla pla
adc #$01 adc #$01
@@ -22,40 +23,32 @@ print .proc
?prt jsr $f2b0 ?prt jsr $f2b0
inw ?strv inw ?strv
bne ?strv-1 bne ?strv-1
ldx ?_tmpx:#0
rts rts
.endp .endp
printhex .proc printhex .proc
jsr lHex pha
sta ?printhextmp stx ?_tmpx
txa :4 lsr
jsr HEX2INT
jsr $f2b0 jsr $f2b0
pla
and #$0f
jsr HEX2INT
jsr $f2b0
ldx ?_tmpx
rts
?_tmpx .byte 0
?printhextmp equ * +1 HEX2INT
lda #$ff php
jmp $f2b0 sei
.endp SED
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
CMP #$0A CMP #$0A
ADC #'0' ADC #'0'
CLD CLD
plp
; wynik dzialania w regA ; wynik dzialania w regA
rts rts
.endp .endp
Binary file not shown.
+76 -3
View File
@@ -34,6 +34,7 @@ _DEST equ $A000
; test code ; test code
org $2000 org $2000
STARTFLASHWRITE
mva #$A0 106 mva #$A0 106
jsr opened jsr opened
lda 20 lda 20
@@ -55,6 +56,72 @@ _DEST equ $A000
lda $d013 lda $d013
sta $3fa 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 ;lda #$ff
;sta $d301 ;sta $d301
@@ -74,7 +141,7 @@ _DEST equ $A000
cmp #option cmp #option
jeq CHECKONLY jeq CHECKONLY
; start ; start
FORMAT FORMAT
jsr printformatting jsr printformatting
jsr print jsr print
dta c'1...',0 dta c'1...',0
@@ -110,6 +177,12 @@ CHECKONLY
jsr print jsr print
dta c'Compare.',$9b,0 dta c'Compare.',$9b,0
rts rts
t_vendor .byte 0
t_kind .byte 0
numchips .byte 0
_storex .byte 0
crcsums crcsums
:128 dta 0,0 :128 dta 0,0
opened opened
@@ -344,7 +417,7 @@ badcompare_tmp2 equ * +1
sec sec
jmp dmaon jmp dmaon
; ------- ; -------
icl '../../lib/flashwritelib.asx' icl '../../lib/flashwritelib_new.asx'
icl '../../lib/crc16_v2.asm' icl '../../lib/crc16_v2.asm'
@@ -357,7 +430,7 @@ badcompare_tmp2 equ * +1
;jmp * ;jmp *
icl '../../lib/print2.asx' icl '../../lib/print2.asx'
org $2e2 org $2e2
dta a($2000) dta a(STARTFLASHWRITE)
; --------------------------------------- ; ---------------------------------------
; blocks for every 8kb bank ; blocks for every 8kb bank
.rept 128, # .rept 128, #