2011-04-25 18:42:50 +00:00
|
|
|
;***************
|
|
|
|
; EEPROM-routines
|
|
|
|
; for 93C66 (512 bytes as 256 16-bit words)
|
|
|
|
;
|
|
|
|
; created : 11.05.95
|
|
|
|
; last modified :
|
2022-04-17 14:06:22 +00:00
|
|
|
;
|
2011-04-25 18:42:50 +00:00
|
|
|
; 16.02.96 leaner (thanks to Harry)
|
|
|
|
; 12.03.96 test for busy after write and erase (well, Harry ;)) )
|
|
|
|
; 22.08.97 ported to ra65 for use with cc65
|
2013-05-09 11:56:54 +00:00
|
|
|
; 02.12.97 added xref for the new ra65
|
2011-04-25 18:42:50 +00:00
|
|
|
; 2010 93c66 support B. Spruck
|
|
|
|
; 2011 modified to suit cc65 environment Karri Kaksonen
|
|
|
|
;
|
|
|
|
; (c) 1995..97 Bastian Schick
|
|
|
|
; CS = A7 (18)
|
|
|
|
; CLK = A1 (11)
|
|
|
|
; DI/DO = AUDIN (32)
|
|
|
|
;
|
|
|
|
;And now how to contact the EEPROM :
|
|
|
|
;
|
|
|
|
;CARD
|
|
|
|
;PORT ----\/---- 93C66(SMD too)
|
|
|
|
;(18) A7 --------| CS |- +5V
|
|
|
|
;(11) A1 --------| CLK |- NC
|
|
|
|
; +---| DI |- NC
|
|
|
|
;(32) AUDIN ----+---| DO |- GND
|
|
|
|
; ----------
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _lynx_eeread_93c66
|
|
|
|
.export _lynx_eewrite_93c66
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1
|
2011-04-25 18:42:50 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "lynx.inc"
|
2011-04-25 18:42:50 +00:00
|
|
|
|
|
|
|
; -------------------
|
|
|
|
; EEPROM command list
|
|
|
|
EE_C_WRITE = $14
|
|
|
|
EE_C_READ = $18
|
|
|
|
EE_C_ERASE = $1C
|
|
|
|
EE_C_EWEN = $13
|
|
|
|
EE_C_EWEN2 = $FF ;; C0 schould be enough
|
|
|
|
EE_C_EWDS = $10
|
|
|
|
EE_C_EWDS2 = $00
|
|
|
|
|
|
|
|
;**************
|
|
|
|
; Only lower byte in A is used for address
|
|
|
|
; unsigned int __fastcall__ lynx_eeread_93c66(unsigned int addr);
|
|
|
|
_lynx_eeread_93c66:
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #EE_C_READ
|
|
|
|
jsr EE_Send11Bit
|
|
|
|
jsr EE_Read16Bit
|
|
|
|
lda ptr1
|
|
|
|
ldx ptr1+1
|
|
|
|
rts
|
2011-04-25 18:42:50 +00:00
|
|
|
|
|
|
|
;***************
|
|
|
|
; reads EEPROM-word to ptr1
|
|
|
|
; A,Y destroyed
|
|
|
|
EE_Read16Bit:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$a
|
|
|
|
sta IODIR ; set AUDIN to Input
|
|
|
|
clc
|
|
|
|
stz ptr1
|
|
|
|
stz ptr1+1
|
|
|
|
ldy #15
|
2011-04-25 18:42:50 +00:00
|
|
|
EEloop1:
|
|
|
|
; CLK = 1
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 0
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
|
|
|
|
|
|
|
lda IODAT
|
|
|
|
and #$10 ; mask bit
|
|
|
|
adc #$f0 ; C=1 if A=$10
|
|
|
|
rol ptr1
|
|
|
|
rol ptr1+1 ; shifts 0 to Carry
|
|
|
|
dey
|
|
|
|
bpl EEloop1
|
|
|
|
|
|
|
|
ldx #$1a
|
|
|
|
stx IODIR ; set AUDIN for output
|
2011-04-25 18:42:50 +00:00
|
|
|
;EE_SET_CS_LOW
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #3
|
|
|
|
stx SYSCTL1
|
|
|
|
dex
|
|
|
|
stx SYSCTL1
|
2011-04-25 18:42:50 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2011-04-25 18:42:50 +00:00
|
|
|
|
|
|
|
;***************
|
|
|
|
; write word to EEPROM
|
|
|
|
; void __fastcall__ lynx_eewrite_93c66(unsigned int addr, unsigned int val);
|
|
|
|
_lynx_eewrite_93c66:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
ldx #EE_C_EWEN
|
|
|
|
lda #EE_C_EWEN2
|
|
|
|
jsr EE_Send11Bit
|
|
|
|
jsr popax
|
|
|
|
ldx #EE_C_WRITE
|
|
|
|
jsr EE_Send11Bit
|
|
|
|
jsr EE_Send16Bit ; Sends ptr1 that contains val
|
2011-04-25 18:42:50 +00:00
|
|
|
|
|
|
|
EE_wait:
|
|
|
|
; EE_SET_CS_HIGH
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #63
|
2011-04-25 18:42:50 +00:00
|
|
|
EEloop:
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
|
|
|
dex
|
|
|
|
bpl EEloop
|
|
|
|
|
|
|
|
lda #$0A
|
|
|
|
sta IODIR ; AUDIN to input
|
|
|
|
lda #$10
|
2011-04-25 18:42:50 +00:00
|
|
|
EE_wait1:
|
2013-05-09 11:56:54 +00:00
|
|
|
bit IODAT ; 'til ready :D0-read is /D0-written
|
|
|
|
beq EE_wait1
|
|
|
|
lda #$1a ; AUDIN to output
|
|
|
|
sta IODIR
|
|
|
|
ldx #EE_C_EWDS
|
|
|
|
lda #EE_C_EWDS2
|
|
|
|
; bra EE_Send11Bit ; fall into
|
2011-04-25 18:42:50 +00:00
|
|
|
;***************
|
|
|
|
; send A via I2C
|
|
|
|
; A,Y destroyed
|
|
|
|
EE_Send11Bit:
|
|
|
|
; EE_SET_CS_LOW
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #3
|
|
|
|
sty SYSCTL1
|
|
|
|
dey
|
|
|
|
sty SYSCTL1
|
2011-04-25 18:42:50 +00:00
|
|
|
; EE_SET_CS_HIGH
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #63
|
2011-04-25 18:42:50 +00:00
|
|
|
EEloop2:
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
|
|
|
dey
|
|
|
|
bpl EEloop2
|
|
|
|
|
|
|
|
pha
|
|
|
|
txa ;; Ok erstmal x abarbeiten und A sichern
|
|
|
|
ldy #2 ; 3 times
|
2011-04-25 18:42:50 +00:00
|
|
|
EEloop3:
|
2013-05-09 11:56:54 +00:00
|
|
|
tax
|
|
|
|
and #$10
|
|
|
|
ora #$b
|
|
|
|
sta IODAT
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 1
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 0
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
|
|
|
txa
|
|
|
|
rol A
|
|
|
|
dey
|
|
|
|
bpl EEloop3
|
|
|
|
|
|
|
|
ldy #7 ; 8 times
|
|
|
|
pla ;; jetzt kommt a an die reihe
|
|
|
|
|
|
|
|
ror A
|
|
|
|
ror A
|
|
|
|
ror A ; bit 7 at pos. 4
|
2011-04-25 18:42:50 +00:00
|
|
|
EEloop4:
|
2013-05-09 11:56:54 +00:00
|
|
|
tax
|
|
|
|
and #$10
|
2011-04-25 18:42:50 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ora #$b
|
|
|
|
sta IODAT
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 1
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 0
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
|
|
|
txa
|
|
|
|
rol A
|
|
|
|
dey
|
|
|
|
bpl EEloop4
|
|
|
|
rts
|
2011-04-25 18:42:50 +00:00
|
|
|
|
|
|
|
;***************
|
|
|
|
; send ptr1 to EEPROM
|
|
|
|
EE_Send16Bit:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr1+1
|
2011-04-25 18:42:50 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ror A
|
|
|
|
ror ptr1
|
|
|
|
ror A
|
|
|
|
ror ptr1
|
|
|
|
ror A
|
|
|
|
ror ptr1
|
2011-04-25 18:42:50 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #15
|
2011-04-25 18:42:50 +00:00
|
|
|
EEloop5:
|
2013-05-09 11:56:54 +00:00
|
|
|
tax
|
|
|
|
and #$10
|
|
|
|
ora #$b
|
|
|
|
sta IODAT
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 1
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
2011-04-25 18:42:50 +00:00
|
|
|
; CLK = 0
|
2013-05-09 11:56:54 +00:00
|
|
|
stz RCART0
|
|
|
|
stz RCART0
|
|
|
|
txa
|
|
|
|
rol ptr1
|
|
|
|
rol A
|
|
|
|
dey
|
|
|
|
bpl EEloop5
|
2011-04-25 18:42:50 +00:00
|
|
|
|
|
|
|
; EE_SET_CS_LOW
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #3
|
|
|
|
stx SYSCTL1
|
|
|
|
dex
|
|
|
|
stx SYSCTL1
|
|
|
|
rts
|
2011-04-25 18:42:50 +00:00
|
|
|
|