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