polished and cleaned-up; updated all flashers.

This commit is contained in:
Jakub Husak
2023-07-18 10:08:26 +02:00
parent a21517838c
commit b767c0ce9e
19 changed files with 193 additions and 127 deletions
+8 -7
View File
@@ -97,13 +97,13 @@ _check_chips
?_next inc numchips
lda numchips
clc
adc #$30
sta chipno
adc #'0'
sta chipno ; stored as '0'/'1' to print inline
jsr print
dta c'chip '
chipno
dta c'0'
dta c'0' ; will be replaced
dta c' vend/prod: ',0
lda m_vendor
jsr printhex
@@ -170,8 +170,7 @@ FORMAT
jsr printformatting
jsr print
dta c'1...',0
ldx #0
jsr flashformatchip
jsr flashformatchip1
bcs formatfailed
jsr flashend ; restores display etc. preserves all
.if .def TWOCHIPS
@@ -179,8 +178,7 @@ FORMAT
jsr printformatting
jsr print
dta c'2...',0
ldx #$40
jsr flashformatchip
jsr flashformatchip2
bcs formatfailed
jsr flashend ; restores display etc. preserves all
.endif
@@ -388,6 +386,9 @@ MAIN_PROCESS
stx calccrc_bank
jsr CALCCRC
mwa #_DEST flashaddr
;ldx #<_DEST
;ldy #>_DEST
;jsr flashsetaddr
jsr printBank
lda operation
+79 -70
View File
@@ -11,17 +11,23 @@ num_mems = 3
; CONSTANTS
m_offsets
softid_entry = 0
softid_exit = 3
flashoppreamble = 6
flash_lockchip = 9
flash_unlockchip = 12
flash_wait_unit = 15
flash_idstr = 18
; jump table
softid_entry = 0
softid_exit = 3
flash_formatchip = 6
flash_formatsector = 9
flash_writebyte = 12
flash_lockchip = 15
flash_unlockchip = 18
flash_wait_unit = 21
; data table
; 1 byte
flash_sectorsizeMSB = 24
; var bytes 0 terminated
flash_idstr = 25
; rw section, may be moved to ZP if needed
M_VECTOR .word 0
tmpa .byte 0
m_vendor .byte 0
m_kind .byte 0
m_iter .byte 0
@@ -130,11 +136,19 @@ jsrtovectorproc
adc #0
plp ; restore C
pha
lda tmpa
lda tmpa:#0
pha
php
rti
; a - vector value offset
; returns y-LSB A-MSB
getvectorvalue
clc
adc M_VECTOR
tay
lda M_VECTOR+1
adc #0
rts
; --------------------------
flashformatchip2
ldx #$40
@@ -150,9 +164,8 @@ flashformatchip
jsr flashcheckempty
bcc flashformatexit
sei
sec ; will format flash!
ldx store_x
lda #flashoppreamble
lda #flash_formatchip
jsr jsrtovectorproc ; preserves A
; not needed to mva $ff flashcmp
jsr wait4flashcheckresult ; waits for format finished
@@ -162,8 +175,7 @@ flashcheckempty
sta flashformatcounter
flashbankloop sei
ldx store_x
flashformatcounter equ*+1
sta $d5FF,x ; set chip (x) and bank
sta flashformatcounter:$d5FF,x ; set chip (x) and bank
; set pages count, 8kB
ldy #$20
; reset address
@@ -184,56 +196,6 @@ flashcartoff ; preserves C
pla
rts
; --------------------------
store_x dta 0
; --------------------------
; PROCEDURE
flashformatsector
; x - bank number 00 - 7f (even sector>>1)
; a - erase 4KB from $B000 if A=$B0, FROM $A000 IF A=$A0
; format 4kb evensector
; strange form - easily maps to cartridge banks
; to format bank, must format sector (x<<1) and (x<<1) +1
; IT IS LONG because it has to be save, ie not format if formatted etc.
; first check if all ff
; this is to avoid wear
stx flashformatstorex
sta flashformatstorea
sei
jsr flashsetbank
; store #$a0 or #$b0
sta flashformataddrcheck + 2
jsr flashchecksectorformatted
bcc flashsectorformatgood
sei
flashformatstorex equ * + 1
ldx #0 ; filled before
; check least sector bit
sec
lda #flashoppreamble ; does not touch A,X
jsr jsrtovectorproc
sta $D500,x
; A must be either $A0 or $B0
flashformatstorea equ * + 1
lda #0 ; filled before
sta flashtmpaddr+1
sta flashformataddrcheck + 2
lda #$30
flashtmpaddr equ *+1
sta $a000 ; SECTOR FORMAT INVOKED HERE!
jsr wait4flashcheckresult ;
sei
lda flashformatstorea
sta flashformataddrcheck+2
ldx flashformatstorex
jsr flashsetbank
; check if all data in sector is $ff
flashchecksectorformatted
ldy #$10
flashchecksectorformatted_bare
@@ -249,17 +211,59 @@ flashformataddrcheck
dey
bne flashformataddrcheck
FEEDBACKEND
flashsectorformatgood
jsr flashcartoff
clc
rts
flashsectorformaterror
jsr flashcartoff
sec
rts
; --------------------------
store_x dta 0
; --------------------------
; PROCEDURE
flashformatsector
; x - bank number 00 - 7f (even sector>>1)
; a - page number in 128byte units $0-$3f
; erase sector containing address bank number * $2000 + page number * 128
stx flashformatstorex
sei
; calculate lower 13 bits of sector
; (address in 8kb bank)
ldx #0
; convert page in A to cartridge a000-bfff address flashtmpaddr
; 0,1 -> 0 ; 2,3 -> 256 ; 4,5 -> 512 etc
lsr
ora #$A0
tay
jsr flashsetaddr ;(x/y) store address for write byte to format sector
;
ldx flashformatstorex:#0 ; filled before, 8k bank number
lda #flash_formatsector ; does not touch A,X?
jsr jsrtovectorproc
ldy #{ sta.w }
jsr flashprocessbyte ; format sector INVOKED !
jsr wait4flashcheckresult ;
;sei
ldx flashformatstorex
jsr flashsetbank
cli
; check if all data in sector is $ff
flashsectorformatgood
;jsr flashcartoff
clc
rts
.macro FEEDBACK
.if (FRAME_FEEDBACK)>=1
php
@@ -286,9 +290,11 @@ flashsectorformaterror
lda #0
sta colbaks
sta colbak
.if (FRAME_FEEDBACK&2)==2
lda #34
sta sdmctl
sta dmactl
.endif
pla
plp
.endif
@@ -315,8 +321,7 @@ byte_differs
sta flashcmp
sei
pha
clc ; byte program preamble
lda #flashoppreamble ; preserves A,X
lda #flash_writebyte ; preserves A,X
jsr jsrtovectorproc
pla
; set right bank
@@ -364,12 +369,14 @@ skipwsync
inc flashcnt+1
bne cont
jsr flashcartoff
FEEDBACKEND
lda #$ff ; status
rts
cont
and #$40
bne flashwaitfordone
jsr flashcartoff
FEEDBACKEND
lda flashval:#0
cmp flashcmp:#0
; when byte compare non zero = error
@@ -412,7 +419,9 @@ flashlockchip
flashsetbank
sta $d500,x
pha
lda $d013
sta $3fa
pla
rts
+40 -12
View File
@@ -1,30 +1,53 @@
C_FORMAT_28SF equ $30
C_CHIPFORMAT_28SF equ $30
C_SECTORFORMAT_28SF equ $D0
C_BYTE_PROG_28SF equ $10
M_SSIZE_28SF equ $0100 ; sector size
M_SSIZE_28SF equ $01 ; sector size
;
M_VECTORS_28SF
jmp softid_entry_28SF
jmp softid_exit_28SF
jmp flashoppreamble_28SF
jmp flash_formatchip_28SF
jmp flash_formatsector_28SF
jmp flash_writebytepreamble_28SF
jmp flash_lockchip_28SF
jmp flash_unlockchip_28SF
jmp flash_wait_unit_28SF
dta M_SSIZE_28SF
dta c'28SF0x0',0
flashoppreamble_28SF
lda #C_BYTE_PROG_28SF
bcc flashoppreamble_acc_28SF
; entry for command in A, mainly for sector format
flash_formatsector_28SF ; 28SF0x0
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
sta $a000; command commit: FORMAT/ID_MODE/BYTE_PROG, any address
lda #$20
sta $a000; command select: FORMATSECTOR/ID_MODE, any address
lda #C_SECTORFORMAT_28SF
; sta in proper address done level up
; only address in range a000-bfff,calculated by $80 bytesize page number 0-3f
rts
flashoppreamble_acc_28SF ; 28SF0x0
flash_writebytepreamble_28SF
; chip should be unlocked to work;
; it is done during format
; or manually
lda #C_BYTE_PROG_28SF
sta $d500,x
sta $a000
flash_wait_unit_28SF
rts
; main entry
; c set ->format (either chip or sector)
; c cleared ->byte write
flash_formatchip_28SF
jsr flash_unlockchip_28SF ; x is 0 or $40, else does not unlock
lda #C_CHIPFORMAT_28SF ; only if c set
sta $d500,x ; can be any addres, in any bank
sta $a000; command select: FORMAT/ID_MODE/BYTE_PROG, any address
sta $a000; command commit: FORMAT/ID_MODE/BYTE_PROG, any address
rts
; entry for command in A, mainly for sector format
flashoppreamble_accnotunlock_28SF ; 28SF0x0
;read_manufacturer_28SF
; sta $D500,x ; x=0 or $40 else will read wrong
; lda $a000
@@ -35,16 +58,21 @@ flash_wait_unit_28SF
; rts
flash_unlockchip_28SF
txa
pha
and #$40
tax
sta $D500,x ; x =0 or $40, else will not unlock
; read from 1823H, 1820H, 1822H, 0418H, 041BH, 0419H, 041AH
jsr flash_lock_preamb_28SF
lda $A41A
pla
tax
rts
softid_entry_28SF
lda #$90
sta $a000
rts
dta {bit.w}
softid_exit_28SF
lda #$ff
+33 -19
View File
@@ -1,30 +1,41 @@
TRIGGER_FORMAT_29F equ $10
TRIGGER_CHIPFORMAT_29F equ $10
TRIGGER_SECTORFORMAT_29F equ $30
C_FORMAT_29F equ $80
C_BYTE_PROG_29F equ $a0
M_SSIZE_29F equ $10000 ; sector size; MAXFlash
command_ZP_29F = $f0
M_SSIZE_29F equ <$100 ; sector size; MAXFlash
M_VECTORS_29F
jmp softid_entry_29F
jmp softid_exit_29F
jmp flashoppreamble_29F
jmp flash_formatchip_29F
jmp flash_formatsector_29F
jmp flash_writebytepreamble_29F
jmp flash_lockchip_29F
jmp flash_unlockchip_29F
jmp flash_wait_unit_29F
dta M_SSIZE_29F
dta c'29F0x0',0
flashoppreamble_29F
pha
flash_writebytepreamble_29F
lda #C_BYTE_PROG_29F
scc
lda #C_FORMAT_29F ; only if c set
sta command_ZP_29F
pla
.byte {bit.w}
bne flashoppreamble_acc_29F
flash_formatsector_29F
lda #TRIGGER_SECTORFORMAT_29F
dta {bit.w} ; skip next 2 bytes
; main entry
; c set ->format (either chip or sector)
; c cleared ->byte write
flash_formatchip_29F
lda #TRIGGER_CHIPFORMAT_29F
sta flash_fmcommand_29F
lda #C_FORMAT_29F
; entry for command in A, mainly for sector format
flashoppreamble_acc_29F ; 29F040
sta command_ZP_29F
sta command_29F
stx flash_format_storex_29F
txa
pha
; when write byte x must be set to either 0 or 40 temporarily
and #$40
tax
@@ -32,15 +43,19 @@ flashoppreamble_acc_29F ; 29F040
mva #$aa $a555 ; $555<$aa
mva #$55 $a2aa ; $2aa<$55
; $555<$80 or $A0
mva command_ZP_29F $a555; will become command: FORMAT/ID_MODE/BYTE_PROG
mva command_29F:#0 $a555; will become command: FORMAT/ID_MODE/BYTE_PROG
cmp #C_FORMAT_29F
bne @+ ; if not FORMAT, procedure finishes
bne flash_format_exit_29F ; if not FORMAT, procedure finishes
; FORMAT part, more to write
mva #$aa $a555 ; $555<$aa
mva #$55 $a2aa ; $2aa<$55
mva #TRIGGER_FORMAT_29F $a555 ; $555<$10
@ pla
tax
lda flash_fmcommand_29F:#TRIGGER_CHIPFORMAT_29F
cmp #TRIGGER_CHIPFORMAT_29F
sne
sta $a555 ; $555<$10
flash_format_exit_29F
ldx flash_format_storex_29F:#0
sta $d500,x
flash_lockchip_29F
flash_unlockchip_29F
rts
@@ -66,7 +81,6 @@ flash_wait_unit_29F
; lda $a001
; rts
softid_exit_29F
sta $D500,x ; x=0 or $40 else will read wrong
lda #$f0
+33 -19
View File
@@ -1,30 +1,41 @@
TRIGGER_FORMAT_39SF equ $10
TRIGGER_CHIPFORMAT_39SF equ $10
TRIGGER_SECTORFORMAT_39SF equ $30
C_FORMAT_39SF equ $80
C_BYTE_PROG_39SF equ $a0
M_SSIZE_39SF equ $1000 ; sector size
command_ZP_39SF = $f0
M_SSIZE_39SF equ $10 ; sector size
M_VECTORS_39SF
jmp softid_entry_39SF
jmp softid_exit_39SF
jmp flashoppreamble_39SF
jmp flash_formatchip_39SF
jmp flash_formatsector_39SF
jmp flash_writebytepreamble_39SF
jmp flash_lockchip_39SF
jmp flash_unlockchip_39SF
jmp flash_wait_unit_29F
jmp flash_wait_unit_39SF
dta M_SSIZE_39SF
dta c'39SF0x0',0
flashoppreamble_39SF ; preserves X
pha
flash_writebytepreamble_39SF
lda #C_BYTE_PROG_39SF
scc
bne flashoppreamble_acc_39SF
flash_formatsector_39SF
lda #TRIGGER_SECTORFORMAT_39SF
dta {bit.w} ; skip next 2 bytes
; main entry
; c set ->format (either chip or sector)
; c cleared ->byte write
flash_formatchip_39SF ; preserves X
lda #TRIGGER_CHIPFORMAT_39SF
sta flash_fmcommand_39SF
lda #C_FORMAT_39SF ; only if c set
sta command_ZP_39SF
pla
.byte {bit.w}
; entry for command in A, mainly for sector format
flashoppreamble_acc_39SF ; 39sf0x0, 29F040
sta command_ZP_39SF
sta command_39SF
stx flash_format_storex_39SF
txa
pha
; when write byte x must be set to either 0 or 40 temporarily
and #$40
tax
@@ -34,18 +45,22 @@ flashoppreamble_acc_39SF ; 39sf0x0, 29F040
mva #$55 $aaaa ; $2aaa<$55
; $5555<$80
sta $d502,x
mva command_ZP_39SF $b555; will become command: FORMAT/ID_MODE/BYTE_PROG
mva command_39SF:#0 $b555; will become command: FORMAT/ID_MODE/BYTE_PROG
cmp #C_FORMAT_39SF
bne @+ ; if not FORMAT, procedure finishes
bne flash_format_39SF_exit ; if not FORMAT, procedure finishes
; FORMAT part, more to write
sta $d502,x
mva #$aa $b555 ; $5555<$aa
sta $d501,x
mva #$55 $aaaa ; $2aaa<$55
sta $d502,x
mva #$10 $b555 ; $5555<$10
@ pla
tax
lda flash_fmcommand_39SF:#TRIGGER_CHIPFORMAT_39SF
cmp #TRIGGER_CHIPFORMAT_39SF
sne
sta $b555 ; $5555<$10
flash_format_39SF_exit
ldx flash_format_storex_39SF:#0
sta $d500,x
flash_lockchip_39SF
flash_unlockchip_39SF
flash_wait_unit_39SF
@@ -67,7 +82,6 @@ softid_exit_39SF
sta $a000
rts
softid_entry_39SF
lda #$90
bne flashoppreamble_acc_39SF
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.