]> cloudbase.mooo.com Git - avrcpm.git/blob - avr/dsk_ram.asm
8a212c7a32c1ad61dd1cb0f78112dd127dc35c3c
[avrcpm.git] / avr / dsk_ram.asm
1 ; RAM disk driver
2 ;
3 ; Copyright (C) 2010 Leo C.
4 ;
5 ; This file is part of avrcpm.
6 ;
7 ; avrcpm is free software: you can redistribute it and/or modify it
8 ; under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
11 ;
12 ; avrcpm is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
16 ;
17 ; You should have received a copy of the GNU General Public License
18 ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.
19 ;
20 ; $Id$
21 ;
22
23 #ifndef RAMDISKCNT
24 #define RAMDISKCNT 0
25 #endif
26
27 #if RAMDISKCNT
28
29 #ifdef DRAM_8BIT
30
31 ; -------------- RAM disk (8-bit DRAM) --------------
32
33 .dseg
34 rdskbuf:
35 .byte 32
36
37 .cseg
38 ; ----------------------------------------------
39
40 rdsk_adr:
41 ldi zl,0
42 lds zh,seeksec
43 lds temp2,seektrk
44 lsr zh
45 ror zl ;Col 0..7
46
47 mov temp,temp2
48 andi temp,0x0f
49 swap temp
50 or zh,temp ;Row 0..7
51
52 ldi yl,~((1<<RAM_A10)|(1<<RAM_A9)|(1<<RAM_A8)) ;Col 8..10
53 mov yh,yl ;Row 8..10
54 lds temp,seekdsk
55 subi temp,RAMDISKNR
56
57 sbrc temp2,4
58 sbr yl,(1<<RAM_A8)
59 sbrc temp2,5
60 sbr yh,(1<<RAM_A8)
61 sbrc temp2,6
62 sbr yl,(1<<RAM_A9)
63 sbrc temp2,7
64 sbr yh,(1<<RAM_A9)
65 sbrc temp,0
66 sbr yl,(1<<RAM_A10)
67 sbrc temp,1
68 sbr yh,(1<<RAM_A10)
69 ret
70
71 ;----------------------------------------------
72
73 rdsk_read:
74 lds xl,dmaadr
75 lds xh,dmaadr+1
76 rcall rdsk_adr
77 ldi temp3,4
78 rdsk_rdlo:
79 ; cli
80 out PORTB,yh ; Row 8..10
81 out PORTD,zh ; Row 0..7
82 out PORTC,_RAS0
83 out PORTB,yl ;1 Col 8..10
84 push yh
85 push yl
86
87 ldi yl,low (rdskbuf)
88 ldi yh,high(rdskbuf)
89 ldi temp2,32
90 rdsk_rdli:
91 out PORTD,zl ;1 Col 0..7
92 out PORTC,_CAS0 ;1
93 out DDRD,_0 ;1
94 out PORTC,_OE ;1
95 inc zl ;1
96 dec temp2 ;1
97 dram_wait DRAM_WAITSTATES ;
98 in temp,PIND ;1
99 out PORTC,_RAS0 ;1
100 out DDRD,_255 ;1
101 st y+,temp ;2
102 brne rdsk_rdli ;2 --> 12 * 128 = 1536 = 77µs
103 out PORTC,_255 ;1
104 ; sei
105 out PORTB,_255 ;1
106
107 ldi yl,low (rdskbuf)
108 ldi yh,high(rdskbuf)
109 ldi temp2,32
110 rdsk_rdstl:
111 ld temp,y+ ;2
112 mem_write_d x ;14 (?)
113 adiw x,1 ;2 --> 18 * 128 = 2304 = 115µs
114 dec temp2
115 brne rdsk_rdstl
116 pop yl
117 pop yh
118 dec temp3
119 brne rdsk_rdlo
120 ret
121
122
123 rdsk_write:
124 lds xl,dmaadr
125 lds xh,dmaadr+1
126 rcall rdsk_adr
127 ldi temp3,4
128 push yh
129 push yl
130 rdsk_wrlo:
131 ldi yl,low (rdskbuf)
132 ldi yh,high(rdskbuf)
133 ldi temp2,32
134 rdsk_wrldl:
135 mem_read_s x
136 st y+,temp
137 adiw x,1
138 dec temp2
139 brne rdsk_wrldl
140
141 pop yl
142 pop yh
143 push yh
144 push yl
145 ldi temp2,32
146 ; cli
147 out PORTB,yh
148 out PORTD,zh
149 out PORTC,_RAS0
150 out PORTB,yl ;1
151 ldi yl,low (rdskbuf)
152 ldi yh,high(rdskbuf)
153 rdsk_wrli:
154 out PORTD,zl
155 out PORTC,_CAS0
156 ld temp,y+
157 out PORTD,temp
158 out PORTC,_WE
159 out PORTC,_RAS0
160 inc zl
161 dec temp2
162 brne rdsk_wrli
163
164 out PORTC,_255
165 ; sei
166 out PORTB,_255
167 dec temp3
168 brne rdsk_wrlo
169 pop yl
170 pop yh
171 ret
172
173 #else /* 4-bit DRAM */
174
175
176 ;-------------------------------------- Defines for RAMDISK Structures
177
178 ;----------------------------------------------- Start of Data Segment
179
180 .dseg
181
182 rdskbuf: .byte 128 ; Buffer for RAM-Disk interaktions
183
184 ; ---------------------------------------------- Start of Code Segment
185 .cseg
186
187 ; ====================================================================
188 ; Function: Calculate an sets the adress of Sector within the RAMDISK
189 ; ====================================================================
190 ; Parameters
191 ; --------------------------------------------------------------------
192 ; Registers : none
193 ; Variables : [r] seeksec Sector to read
194 ; [r] seektrk Track to read
195 ; [w] temp3 Number of Bytes per Sector (128)
196 ; --------------------------------------------------------------------
197 ; Description:
198 ; ====================================================================
199
200
201 rdsk_adr:
202 ldi xl,0
203 lds xh,seeksec
204 lds temp2,seektrk
205
206 lsr xh
207 ror xl ;Col 0..7
208
209 mov temp,temp2
210 andi temp,0x0f
211 swap temp
212 or xh,temp ;Row 0..7
213
214 ldiw z,rdskbuf
215 ldi temp3,128
216 DRAM_SETADDR xh, ~0,(1<<ram_ras), ~0,(1<<ram_a8)|(1<<ram_oe)
217 cbi P_RAS,ram_ras
218
219 .if DISK_DEBUG > 1
220 printstring " "
221 mov temp,xh
222 rcall printhex
223 printstring " "
224 mov temp,xl
225 rcall printhex
226 printstring " "
227 .endif
228 ret
229
230 ; ====================================================================
231 ; Function: Does a read opperation on a RAMDISK
232 ; ====================================================================
233 ; Parameters
234 ; --------------------------------------------------------------------
235 ; Registers : none
236 ; Variables : [r] seeksec Sector to read
237 ; [r] seektrk Track to read
238 ; [r] flags RW operation Flags
239 ; [w] erflag Error Status of the operation
240 ; --------------------------------------------------------------------
241 ; Description:
242 ; ====================================================================
243
244
245 rdsk_read:
246
247 .if DISK_DEBUG > 1
248 printnewline
249 printstring "rd-adr: "
250 .endif
251 rcall rdsk_adr
252
253 rdsk_rdl:
254 DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_oe)), (1<<ram_a8)
255 cbi P_CAS,ram_cas
256 cbi P_A8,ram_a8
257 inc xl
258 dram_wait DRAM_WAITSTATES ;
259 in temp,P_DQ-2 ; PIN
260 sbi P_CAS,ram_cas
261
262 cbi P_CAS,ram_cas
263 andi temp,0x0f
264 swap temp
265 dram_wait DRAM_WAITSTATES ;
266 in temp2,P_DQ-2 ; PIN
267 andi temp2,0x0f
268 or temp,temp2
269
270 sbi P_OE,ram_oe
271 sbi P_CAS,ram_cas
272 dec temp3
273 st z+,temp
274 brne rdsk_rdl
275
276 sbi P_RAS,ram_ras
277 ldiw z,rdskbuf
278 lds xl,dmaadr
279 lds xh,dmaadr+1
280 ldi temp3,128
281 rdsk_rdstl:
282 ld temp,z+
283 mem_write
284 adiw x,1
285 dec temp3
286 brne rdsk_rdstl
287 ret
288
289 ; ====================================================================
290 ; Function: Does a write opperation on a RAMDISK
291 ; ====================================================================
292 ; Parameters
293 ; --------------------------------------------------------------------
294 ; Registers : none
295 ; Variables : [r] seeksec Sector to read
296 ; [r] seektrk Track to read
297 ; [r] flags RW operation Flags
298 ; [w] erflag Error Status of the operation
299 ; --------------------------------------------------------------------
300 ; Description:
301 ; ====================================================================
302
303 rdsk_write:
304 .if DISK_DEBUG > 1
305 printnewline
306 printstring "wr-adr: "
307 .endif
308 lds xl,dmaadr
309 lds xh,dmaadr+1
310 ldiw z,rdskbuf
311 ldi temp3,128
312 rdsk_wrldl:
313 mem_read
314 st z+,temp
315 adiw x,1
316 dec temp3
317 brne rdsk_wrldl
318
319 ldi temp2,RAM_DQ_MASK | (1<<ram_w) | (1<<ram_cas)
320 out DDRC,temp2
321 rcall rdsk_adr
322 rdsk_wrl:
323 ld temp,z+
324 mov temp2,temp
325 andi temp,RAM_DQ_MASK & ~(1<<ram_w)
326 ori temp,(1<<ram_cas)
327 out PORTC,temp
328 DRAM_SETADDR xl, ~(1<<ram_ras),0, ~((1<<ram_a8)),(1<<ram_oe)
329 cbi PORTC,ram_cas
330 sbi PORTD,ram_a8
331 sbi PORTC,ram_cas
332 swap temp2
333 andi temp2,RAM_DQ_MASK & ~(1<<ram_w)
334 ori temp2,(1<<ram_cas)
335 out PORTC,temp2
336 cbi PORTC,ram_cas
337 inc xl
338 sbi PORTC,ram_cas
339 dec temp3
340 brne rdsk_wrl
341
342 sbi P_RAS,ram_ras
343 ldi temp,~RAM_DQ_MASK | (1<<ram_w) | (1<<ram_cas)
344 out DDRC,temp
345 out PORTC,temp
346 ret
347
348
349 rdsk_add_partition:
350 ret
351
352
353
354 #endif /* DRAM_8BIT */
355
356
357 #else /* no ram disk */
358
359 rdsk_read:
360 ret
361 rdsk_write:
362 ret
363 rdsk_add_partition:
364 ret
365
366 #endif /* RAMDISKCNT */
367