]> git.sur5r.net Git - cc65/blob - libsrc/lynx/eeprom66.s
Move Atari-specific PIA reg vals to atari.h
[cc65] / libsrc / lynx / eeprom66.s
1 ;***************
2 ; EEPROM-routines
3 ; for 93C66 (512 bytes as 256 16-bit words)
4 ;
5 ; created : 11.05.95
6 ; last modified :
7
8 ; 16.02.96      leaner (thanks to Harry)
9 ; 12.03.96      test for busy after write and erase (well, Harry ;)) )
10 ; 22.08.97      ported to ra65 for use with cc65
11 ; 02.12.97      added xref for the new ra65
12 ;     2010      93c66 support B. Spruck
13 ;     2011      modified to suit cc65 environment Karri Kaksonen
14 ;
15 ; (c) 1995..97 Bastian Schick
16 ; CS    = A7 (18)
17 ; CLK   = A1 (11)
18 ; DI/DO = AUDIN (32)
19 ;
20 ;And now how to contact the EEPROM :
21 ;
22 ;CARD
23 ;PORT               ----\/----      93C66(SMD too)
24 ;(18)  A7   --------| CS     |- +5V
25 ;(11)  A1   --------| CLK    |- NC
26 ;               +---| DI     |- NC
27 ;(32) AUDIN ----+---| DO     |- GND
28 ;                   ----------
29
30         .export         _lynx_eeread_93c66
31         .export         _lynx_eewrite_93c66
32         .import         popax
33         .importzp       ptr1
34
35         .include        "lynx.inc"
36
37 ; -------------------
38 ; EEPROM command list
39 EE_C_WRITE      =    $14
40 EE_C_READ       =    $18
41 EE_C_ERASE      =    $1C
42 EE_C_EWEN       =    $13
43 EE_C_EWEN2      =    $FF   ;; C0 schould be enough
44 EE_C_EWDS       =    $10
45 EE_C_EWDS2      =    $00
46
47 ;**************
48 ; Only lower byte in A is used for address
49 ; unsigned int __fastcall__ lynx_eeread_93c66(unsigned int addr);
50 _lynx_eeread_93c66:
51         ldx #EE_C_READ
52         jsr EE_Send11Bit
53         jsr EE_Read16Bit
54         lda ptr1
55         ldx ptr1+1
56         rts
57
58 ;***************
59 ; reads EEPROM-word to ptr1
60 ; A,Y destroyed
61 EE_Read16Bit:
62         lda #$a
63         sta IODIR       ; set AUDIN to Input
64         clc
65         stz ptr1
66         stz ptr1+1
67         ldy #15
68 EEloop1:
69 ; CLK = 1
70         stz RCART0
71         stz RCART0
72 ; CLK = 0
73         stz RCART0
74         stz RCART0
75
76         lda IODAT
77         and #$10        ; mask bit
78         adc #$f0        ; C=1 if A=$10
79         rol ptr1
80         rol ptr1+1      ; shifts 0 to Carry
81         dey
82         bpl EEloop1
83
84         ldx #$1a
85         stx IODIR       ; set AUDIN for output
86 ;EE_SET_CS_LOW
87
88         ldx #3
89         stx SYSCTL1
90         dex
91         stx SYSCTL1
92
93         rts
94
95 ;***************
96 ; write word to EEPROM
97 ; void __fastcall__ lynx_eewrite_93c66(unsigned int addr, unsigned int val);
98 _lynx_eewrite_93c66:
99         sta ptr1
100         stx ptr1+1
101         ldx #EE_C_EWEN
102         lda #EE_C_EWEN2
103         jsr EE_Send11Bit
104         jsr popax
105         ldx #EE_C_WRITE
106         jsr EE_Send11Bit
107         jsr EE_Send16Bit        ; Sends ptr1 that contains val
108
109 EE_wait:
110 ; EE_SET_CS_HIGH
111
112         ldx #63
113 EEloop:
114         stz RCART0
115         stz RCART0
116         dex
117         bpl EEloop
118
119         lda #$0A
120         sta IODIR       ; AUDIN to input
121         lda #$10
122 EE_wait1:
123         bit IODAT       ; 'til ready :D0-read is /D0-written
124         beq EE_wait1
125         lda #$1a        ; AUDIN to output
126         sta IODIR
127         ldx #EE_C_EWDS
128         lda #EE_C_EWDS2
129 ;       bra EE_Send11Bit ; fall into
130 ;***************
131 ; send A via I2C
132 ; A,Y destroyed
133 EE_Send11Bit:
134 ; EE_SET_CS_LOW
135         ldy #3
136         sty SYSCTL1
137         dey
138         sty SYSCTL1
139 ; EE_SET_CS_HIGH
140
141         ldy #63
142 EEloop2:
143         stz RCART0
144         stz RCART0
145         dey
146         bpl EEloop2
147
148         pha
149         txa   ;; Ok erstmal x abarbeiten und A sichern
150         ldy #2 ; 3 times
151 EEloop3:
152         tax
153         and #$10
154         ora #$b
155         sta IODAT
156 ; CLK = 1
157         stz RCART0
158         stz RCART0
159 ; CLK = 0
160         stz RCART0
161         stz RCART0
162         txa
163         rol A
164         dey
165         bpl EEloop3
166
167         ldy #7 ; 8 times
168         pla  ;; jetzt kommt a an die reihe
169
170         ror A
171         ror A
172         ror A           ; bit 7 at pos. 4
173 EEloop4:
174         tax
175         and #$10
176
177         ora #$b
178         sta IODAT
179 ; CLK = 1
180         stz RCART0
181         stz RCART0
182 ; CLK = 0
183         stz RCART0
184         stz RCART0
185         txa
186         rol A
187         dey
188         bpl EEloop4
189         rts
190
191 ;***************
192 ; send ptr1 to EEPROM
193 EE_Send16Bit:
194         lda ptr1+1
195
196         ror A
197         ror ptr1
198         ror A
199         ror ptr1
200         ror A
201         ror ptr1
202
203         ldy #15
204 EEloop5:
205         tax
206         and #$10
207         ora #$b
208         sta IODAT
209 ; CLK = 1
210         stz RCART0
211         stz RCART0
212 ; CLK = 0
213         stz RCART0
214         stz RCART0
215         txa
216         rol ptr1
217         rol A
218         dey
219         bpl EEloop5
220
221 ; EE_SET_CS_LOW
222         ldx #3
223         stx SYSCTL1
224         dex
225         stx SYSCTL1
226         rts
227