|
|
1.1 root 1: ;************************************************
2: ; *
3: ; EEPROM Write & Read Primitives *
4: ; *
5: ;************************************************
6: ;
7: ; Hi-Score on-board-cartridge EEPROM primitives
8: ; for use by Jaguar game cartridge developers.
9: ;
10: ; 128 bytes (accessable as 64 words) of non-volatile
11: ; memory are available on Jaguar game cartridges to
12: ; preserve Hi-scores or other game status.
13: ; Data is retained for up to 10 years, and a minimum
14: ; of 10,000 read/write cycles is assured, according to
15: ; product literature.
16: ;
17: ;
18: ;
19: ;
20: ;
21: ; Programmer: Dave Staugas
22: ; Atari, Sunnyvale
23: ; [408] 745-8802
24: ;
25: ; Last Update: 24-Sept-93
26: ;
27: ;
28: ; Equates needed that may already be defined in the JAGUAR.INC file..
29: ;
30: JOY1 equ $f14000 ;this we'll use as our I/O base address
31: GPIO_0 equ $f14800 ;General purpose I/O #0
32: GPIO_1 equ $f15000 ;General purpose I/O #1
33: ;
34: ; Equates derived from the above
35: ; to allow indirect with 16-bit displacement addressing
36: ;
37: GPIO_0of equ GPIO_0-JOY1 ;offset to GPIO_0 (when addr reg Ax -> JOY1)
38: GPIO_1of equ GPIO_1-JOY1 ;offset to GPIO_1 (when addr reg Ax -> JOY1)
39: ;
40: ; Commands specific to the National Semiconductor NM93C14
41: ;
42: ; 9-bit commands..
43: ; 876543210
44: eREAD equ %110000000 ;read from EEPROM
45: eEWEN equ %100110000 ;Erase/write Enable
46: eWRITE equ %101000000 ;Write selected register
47: eEWDS equ %100000000 ;Erase/Write disable (default)
48: ;
49: ;
50: ; DO (data out) - is read on bit0 of JOY1
51: ; DI (data in) - is written on bit0 of GPIO_0
52: ; CS (chip select) - is pulsed low by any access to GPIO_1
53: ;
54: ;
55: ;*****************************************************************
56: ;
57: ; Write a word to EEPROM
58: ;
59: ; entry: d0.w = data to be written
60: ; d1.w = least signifigant 6 bits specify write address (0-63)
61: ;
62: ; exit: all preserved
63: ;
64: ;
65: _eewrite::
66: movem.l a0/d0-d4,-(sp)
67:
68: move.l 28(sp),d0 ; get data from stack (JDC)
69: move.l 32(sp),d1 ; get address from stack (JDC)
70: lea JOY1,a0 ;set ptr to EEPROM i/o addresses
71: ;
72: tst.w GPIO_1of(a0) ;strobe ChipSelect
73: ;
74: move.w #eEWEN,d2 ;erase/write enable command
75: bsr out9bits ;send it to EEPROM
76: ;
77: tst.w GPIO_1of(a0) ;strobe ChipSelect
78: ;
79: andi.w #$3f,d1 ;force write addr to be legit (0-63)
80: ori.w #eWRITE,d1 ;form WRITE command
81: move.w d1,d2
82: bsr out9bits ;send it to EEPROM
83: ;
84: move.w d0,d2 ;get 16-bit data word to send
85: bsr out16bit ; & send it
86: ;
87: tst.w GPIO_1of(a0) ;strobe ChipSelect
88: ;
89: nop ;1 us required after CS for status valid
90: nop
91: move.w #1,d2
92: move.w #$2000,d4
93: wrwait:
94: move.w (a0),d3 ;wait until write is complete
95: sub.w #1,d4 ; don't stay in here forever
96: beq badwrite ; didn't work
97: and.w d2,d3
98: beq wrwait
99: ;
100: move.w #eEWDS,d2 ;get erase/write disable command
101: bsr out9bits ;send it
102: ;
103: tst.w GPIO_1of(a0) ;strobe ChipSelect
104: ;
105: movem.l (sp)+,a0/d0-d4
106: move.l #1,d0 ; ok write
107: rts ;we're done
108:
109: badwrite:
110: movem.l (sp)+,a0/d0-d4
111: move.l #0,d0 ; bad write
112: rts
113:
114: ;
115: ;
116: ;
117: ;******************************************************
118: ;
119: ;
120: ; Read a word from EEPROM
121: ;
122: ; entry: d1.w = least signifigant 6 bits specify read address (0-63)
123: ;
124: ; exit: d0.w = data as read from EEPROM
125: ; all other registers preserved
126: ;
127: _eeread::
128: movem.l a0/d1-d4,-(sp)
129:
130: move.l 24(sp),d1 ; get address off the stack (JDC)
131: lea JOY1,a0 ;set ptr to EEPROM i/o address
132: ;
133: tst.w GPIO_1of(a0) ;strobe ChipSelect
134: ;
135: andi.w #$3f,d1 ;force legit read addr
136: ori.w #eREAD,d1
137: move.w d1,d2
138: bsr out9bits
139: ;
140: moveq #0,d0
141: moveq #15,d3 ;pick up 17 bits (1st is dummy)
142: inlp:
143: tst.w GPIO_0of(a0)
144: nop
145: move.w (a0),d1
146: lsr.w #1,d1
147: addx.w d0,d0
148: nop
149: nop
150: nop
151: nop
152: nop
153: nop
154: dbra d3,inlp
155: ;
156: movem.l (sp)+,a0/d1-d4
157: rts
158: ;
159: ;
160: ;
161: ;**************************************************************
162: ;
163: ; Subordinate Routines needed by "eewrite"
164: ;
165: ; Serial data sent to device is written to DI, bit0 of GPIO_0
166: ;
167: ; entry:
168: ; a0 -> JOY1
169: ; d2.w = 16-bit data word to write
170: ;
171: ; exit:
172: ; d2.w, d3.l destroyed
173: ;
174: out16bit:
175: rol.w #1,d2 ;align 1st serial data bit (bit15) to bit0
176: moveq #15,d3 ;send 16 bits
177: bra.s out9lp
178: ;
179: ; entry:
180: ; a0 -> JOY1
181: ; d2.w = 9-bit command to write
182: ;
183: out9bits:
184: rol.w #8,d2 ;align 1st serial data bit (bit8) to bit0
185: moveq #8,d3 ;send 9
186: out9lp:
187: move.w d2,GPIO_0of(a0) ;write next bit
188: nop
189: nop
190: nop ;delay next write
191: nop
192: nop
193: nop
194: rol.w #1,d2 ;adjust bit0 for next datum
195: dbra d3,out9lp ;go for all 9 or all 16
196: rts
197: ;
198: ;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.