finished works on software for 1 MB (two 512kB flashes) cartridge

This commit is contained in:
Jakub Husak
2020-11-05 00:46:23 +01:00
parent b9d39da9a7
commit 7fe42388d4
4 changed files with 55 additions and 37 deletions
+50 -37
View File
@@ -1,55 +1,66 @@
; flash eeprom library
; by JHusak , 04.01.2020
; free to use.
; x - bank to select on exit
lstore_x dta 0
; x - 0x0 or 0x40 - chip select
; c - 1 - format, 0 - write
;.print flashcnt
flashoppreamble
pha
txa
pha
; when write byte x must be set to either 0 or 40 temporarily
and #$40
tax
; $5555<$aa
sty $d502
ldy #$aa
sty $b555
@ sta $d502,x
lda #$aa
sta $b555
; $2aaa<$55
sty $d501
ldy #$55
sty $aaaa
sta $d501,x
lda #$55
sta $aaaa
; $5555<$80
sty $d502
sta $d502,x
; sector format: carry set
scc
ldy #$80 ; sector erase
lda #$80 ; sector erase
scs
ldy #$a0 ; byte programm
sty $b555
lda #$a0 ; byte programm
sta $b555
bcc @+
; $5555<$aa
sty $d502
ldy #$aa
sty $b555
sta $d502,x
lda #$aa
sta $b555
; $2aaa<$55
sty $d501
ldy #$55
sty $aaaa
sta $d501,x
lda #$55
sta $aaaa
; PREPARE FOR SECTOR TO ERASE
; set upper bank bits
@ rts
@ pla
tax
pla
rts
; --------------------------
; PROCEDURE
; x = 0 or 0x40 - flash chip address.
store_x dta 0
flashformatchip2
ldx #$40
dta { bit.w }
flashformatchip
ldx #0
sei
stx store_x
sec ; format preamble
jsr flashoppreamble ; does not touch A
sta $d502
sta $d502,x
lda #$10
sta $b555
lda #$ff
@@ -59,17 +70,19 @@ flashformatchip
; cart is off and cli
; sec ; error
; rts
@ lda #$1f
@ lda #$3f
sta flashformatcounter
@ sei
ldx store_x
flashformatcounter equ*+1
sta $d51f
ldx #0
sta $d5FF,x ; set chip (x) and bank
; set pages count
ldy #$20
; reset address
lda #$a0
sta flashformataddrcheck + 2
lda #$ff
jsr flashformataddrcheck
; check whole sector against 0xff
jsr flashchecksectorformatted_bare ; destroys x
bcs @+ ; format error
dec flashformatcounter
bpl @-
@@ -79,7 +92,7 @@ flashformatcounter equ*+1
; --------------------------
; PROCEDURE
flashformatsector
; x - even sector 00 - 1f
; x - even sector 00 - 7f
; a - erase 4KB from $B000 if A=$B0, FROM $A000 IF A=$A0
; format 4kb evensector
; strange form - easily maps to cartridge banks
@@ -93,10 +106,6 @@ flashformatsector
sta flashformataddrcheck + 2
jsr flashchecksectorformatted
bcc flashsectorformatgood
;php
;lda #'F'
;jsr PRINTWHAT
;plp
sei
flashformatstorex equ * + 1
ldx #0 ; filled before
@@ -125,9 +134,10 @@ flashtmpaddr equ *+1
; check if all data in sector is $ff
flashchecksectorformatted
ldx #0
ldy #$10
flashchecksectorformatted_bare
lda #$ff
ldx #0
flashformataddrcheck
cmp $a000,x
bne flashsectorformaterror
@@ -147,20 +157,23 @@ flashsectorformaterror
sec
rts
; ---------------------
; PROCEDURE
flashwritebyte
; a - byte to write
; x - 8kb bank to switch
; x - 8kb bank to switch, $00 to $7f, also chip select
; flashaddr - addres in flash - must be a000-offset
; do not programm byte if already good
sei
sta $D500,x
sta $D500,x ; select bank, chip
ldy #{ cmp.w }
jsr flashprocessbyte
bne @+
;clc
;jmp flashcartoff
sta $D580
cli
clc
@@ -169,12 +182,12 @@ flashwritebyte
sei
clc ; write byte preamble
jsr flashoppreamble ; preserves A,X
sta $D500,x
ldy #{ sta.w }
; WRITE BYTE !
jsr flashprocessbyte
flashcheckresult ; sei mode
@@ -220,7 +233,7 @@ flashcmp equ *+1
rts
flashcnt
brk
dta 0
; ----------------------
; PROCEDURE