diff --git a/lib/flashwritelib_new.asx b/lib/flashwritelib_new.asx index eeb7f77..a61094c 100644 --- a/lib/flashwritelib_new.asx +++ b/lib/flashwritelib_new.asx @@ -4,8 +4,8 @@ icl "lib_28sf0x0.asm" icl "lib_29f0x0.asm" - icl "lib_29sf0x0.asm" icl "lib_39sf0x0.asm" +num_mems = 3 ; CONSTANTS m_offsets @@ -24,29 +24,36 @@ m_kind .byte 0 m_iter .byte 0 ; ro section again +; Protocols for known kinds of memory: +; 28sf0x0 protokol unlock/write +; 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_28SF, M_VECTORS_29F, M_VECTORS_29SF, M_VECTORS_39SF -;Problems with writing: +; -------------------------------------------------------------------- +;Problems to solve with writing: ; - check flash presence ; - flash protocol ; - size of flash 1,2 ; - size of sector in some cases ; - number of flashes (easy, they do not overlap) -; All can be read by erasing memory, writing several bytes and reading them -; For flash recognition +; All can be read by erasing memory, writing several bytes and reading them; +; But we will rely rather on user's choice not to wear memory + +; First detection is to read raw memory and id and compare results. However, we do not want to keep all those ids to recognise. +; Second detection is to compare contents. But not very reliable as contents may repeat. +; And ome issues may occur when no memory inserted. +; Eventually, for flash recognition ; - format, -; - write 128 kbytes, read more -> if not ff, flash is 128k -; - write additional 128KB, read more ->if not ff flash is 256kB, else is 512kb +; - write 128k-1 byte, read 2*128k-1 -> if not ff flash is 128k +; - write 256k-1 byte, read 2*256k-1 -> if not ff flash is 256kB, else is 512kb ; -; First detection is to read raw memory and id and compare results. Some issues may occur when no memory inserted. -;flash_detect_protocol: -; lda #ID_MODE -; jsr flashoppreamble_5555_2aaa - -; c parameter as format/writebyte -; for compatibility, 5555_2aaa only +; ??? c parameter as format/writebyte +; ??? for compatibility, 5555_2aaa only +; ------------------------------------------------------------------------ ; -------------------------- ; PROCEDURE ; x = 0 or 0x40 - flash chip address. @@ -54,10 +61,11 @@ M_CHECK_VECS .word M_VECTORS_28SF, M_VECTORS_29F, M_VECTORS_29SF, M_VECTORS_39SF ; this fails only when somebody stores vendor and product bytes ; at the proper cells. ; -; then in the code we call lda #offset/jsr jsrtoproc +; then in the code we call lda #offset/jsr jsrtovetorproc check_type - ldy #0-2 + ldy #(2*(num_mems-1)) ?again + sty m_iter ; store default values sta $d500,x lda $a000 @@ -65,34 +73,34 @@ check_type lda $a001 sta m_kind - iny - iny - sty m_iter - jsr jsrtosoftidentry sta $d500,x lda $a000 ; vendor cmp m_vendor - bne OK + sta m_vendor + beq ?next lda $a001 ; id cmp m_kind + sta m_kind + beq ?next bne ?OK - +?next ldy m_iter - cpy #$6 - bne ?again + dey + dey + bpl ?again ; error sec rts ?OK lda M_CHECK_VECS+1,y - sta M_VECTORS+1 + sta M_VECTOR+1 lda M_CHECK_VECS,y - sta M_VECTORS + sta M_VECTOR lda #softid_exit - jsr jsrtoproc + jsr jsrtovetorproc clc rts @@ -106,12 +114,12 @@ jsrtosoftidentry ; PROCEDURE ; performs jump to vector table at offset in A provided ; y passed to the procedure called -jsrtoproc +jsrtovetorproc php ; preserve C clc - adc M_VECTORS + adc M_VECTOR sta tmpa - lda M_VECTORS+1 + lda M_VECTOR+1 adc #0 plp ; restore C pha @@ -133,12 +141,14 @@ flashformatchip sei stx store_x - lda #C_FORMAT - jsr flashoppreamble_acc ; does not touch A - sta $d502,x + ; lda #C_FORMAT + sec + lda #flashoppreamble + jsr jsrtovetorproc ; does not touch A + ;sta $d502,x ; !!!!!!!!!!!!!!!!!!! CHECK THIS !!!!!!!!!!!!!!!!!!!! - lda #TRIGGER_FORMAT - sta $b555 ; FORMAT HERE TRIGGERED! + ;lda #TRIGGER_FORMAT + ;sta $b555 ; FORMAT HERE TRIGGERED! ; not needed to mva $ff flashcmp jsr wait4flashcheckresult ; waits for format finished ; then check number of banks for FFs @@ -185,9 +195,9 @@ flashformatsector flashformatstorex equ * + 1 ldx #0 ; filled before ; check least sector bit - - lda #C_FORMAT - jsr flashoppreamble_acc ; does not touch A,X + sec + lda #flashoppreamble ; does not touch A,X + jsr jsrtovetorproc sta $D500,x ; A must be either $A0 or $B0 flashformatstorea equ * + 1 @@ -255,8 +265,9 @@ byte_differs sta flashcmp sei pha - lda #C_BYTE_PROG - jsr flashoppreamble_acc ; preserves A,X + clc ; byte preamble + lda #flashoppreamble ; preserves A,X + jsr jsrtovetorproc pla ; set right bank sta $D500,x diff --git a/lib/lib_28sf0x0.asm b/lib/lib_28sf0x0.asm index 7144b43..81fb3bd 100644 --- a/lib/lib_28sf0x0.asm +++ b/lib/lib_28sf0x0.asm @@ -9,11 +9,12 @@ M_VECTORS_28SF jmp flashoppreamble_28SF jmp flash_lockchip_28SF jmp flash_unlockchip_28SF - .byte "28SF0x0",0 + dta c'28SF0x0',0 flashoppreamble_28SF lda #C_BYTE_PROG_28SF bcc flashoppreamble_acc_28SF + jsr flash_unlockchip_28SF lda #C_FORMAT_28SF ; only if c set sta $d500,x ; can be any address sta $a000; command select: FORMAT/ID_MODE/BYTE_PROG, any address @@ -23,16 +24,15 @@ flashoppreamble_acc_28SF ; 28SF0x0 sta $d500,x sta $a000 rts -read_manufacturer_28SF - sta D500,x ; x=0 or $40 else will read wrong - lda $a000 - rts -read_product_28SF - sta D500,x ; x=0 or $40 else will read wrong - lda $a001 - rts +;read_manufacturer_28SF +; sta $D500,x ; x=0 or $40 else will read wrong +; lda $a000 +; rts +;read_product_28SF +; sta $D500,x ; x=0 or $40 else will read wrong +; lda $a001 +; rts -softid_entry_28SF flash_unlockchip_28SF sta $D500,x ; x =0 or $40, else will not unlock ; read from 1823H, 1820H, 1822H, 0418H, 041BH, 0419H, 041AH @@ -40,7 +40,13 @@ flash_unlockchip_28SF lda $A41A rts -softid_xit_28SF +softid_entry_28SF + sta $d500,x + lda #$90 + sta $a000 + rts + +softid_exit_28SF flash_lockchip_28SF sta $D500,x ; x =0 or $40, else will not unlock jsr flash_lock_preamb_28SF diff --git a/lib/lib_29f0x0.asm b/lib/lib_29f0x0.asm index 0d6d79d..6ed23a8 100644 --- a/lib/lib_29f0x0.asm +++ b/lib/lib_29f0x0.asm @@ -2,7 +2,7 @@ TRIGGER_FORMAT_29F equ $10 C_FORMAT_29F equ $80 C_BYTE_PROG_29F equ $a0 M_SSIZE_29F equ $10000 ; sector size; MAXFlash, protocol compatible with 39sf0x0 -command_ZP = $f0 +command_ZP_29F = $f0 M_VECTORS_29F jmp softid_entry_29F @@ -10,18 +10,18 @@ M_VECTORS_29F jmp flashoppreamble_29F jmp flash_lockchip_29F jmp flash_unlockchip_29F - .byte "29F0x0",0 + dta c'29F0x0',0 flashoppreamble_29F pha lda #C_BYTE_PROG_29F scc lda #C_FORMAT_29F ; only if c set - sta command_ZP + sta command_ZP_29F pla .byte {bit.w} flashoppreamble_acc_29F ; 39sf0x0, 29F040 - sta command_ZP + sta command_ZP_29F txa pha ; when write byte x must be set to either 0 or 40 temporarily @@ -33,7 +33,7 @@ flashoppreamble_acc_29F ; 39sf0x0, 29F040 mva #$55 $aaaa ; $2aaa<$55 ; $5555<$80 sta $d502,x - mva command_ZP $b555; will become command: FORMAT/ID_MODE/BYTE_PROG + mva command_ZP_29F $b555; will become command: FORMAT/ID_MODE/BYTE_PROG cmp #C_FORMAT_29F bne @+ ; if not FORMAT, procedure finishes ; FORMAT part, more to write @@ -43,22 +43,23 @@ flashoppreamble_acc_29F ; 39sf0x0, 29F040 mva #$55 $aaaa ; $2aaa<$55 @ pla tax +flash_lockchip_29F flash_unlockchip_29F rts ;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 ; rts ;read_product_29F -; sta D500,x ; x=0 or $40 else will read wrong +; sta $D500,x ; x=0 or $40 else will read wrong ; lda $a001 ; rts softid_exit_29F - sta D500,x ; x=0 or $40 else will read wrong + sta $D500,x ; x=0 or $40 else will read wrong lda #$f0 sta $a000 rts diff --git a/lib/lib_29sf0x0.asm b/lib/lib_29sf0x0.asm deleted file mode 100644 index 9a76b43..0000000 --- a/lib/lib_29sf0x0.asm +++ /dev/null @@ -1,65 +0,0 @@ -C_FORMAT_29SF equ $80 -C_BYTE_PROG_29SF equ $a0 -M_SSIZE_29SF equ $0080 ; sector size -command_ZP = $f0 - -M_VECTORS_29SF - jmp softid_entry_29SF - jmp softid_exit_29SF - jmp flashoppreamble_29SF - jmp flash_lockchip_29SF - jmp flash_unlockchip_29SF - .byte "29SF0x0",0 - -flashoppreamble_29SF - pha - lda #C_BYTE_PROG_29SF - scc - lda #C_FORMAT_29SF ; only if c set - sta command_ZP - pla - .byte {bit.w} -flashoppreamble_acc_29SF ; 29sf040 - sta command_ZP - txa - pha - ; when write byte x must be set to either 0 or 40 temporarily - and #$40 - tax - sta $d500,x - mva #$aa $a555 ; $555<$aa - mva #$55 $a2aa ; $2aa<$55 - ; $555