]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/dsk_ram.asm
SVN --> GIT
[avrcpm.git] / avr / dsk_ram.asm
CommitLineData
abeec861 1; RAM disk driver
64219415 2;
abeec861 3; Copyright (C) 2010 Leo C.
64219415
FZ
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$
92202636
L
21;
22
abeec861 23#ifndef RAMDISKCNT
4bd49b80 24 #define RAMDISKCNT 0
92202636
L
25#endif
26
abeec861
L
27#if RAMDISKCNT
28
162601ca 29#if DRAM_8BIT
abeec861
L
30
31; -------------- RAM disk (8-bit DRAM) --------------
32
33 .dseg
34rdskbuf:
35 .byte 32
4bd49b80 36
abeec861
L
37 .cseg
38; ----------------------------------------------
39
40rdsk_adr:
41 ldi zl,0
42 lds zh,seeksec
43 lds temp2,seektrk
44 lsr zh
45 ror zl ;Col 0..7
4bd49b80 46
abeec861
L
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
4bd49b80 56
abeec861
L
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
73rdsk_read:
74 lds xl,dmaadr
75 lds xh,dmaadr+1
76 rcall rdsk_adr
77 ldi temp3,4
78rdsk_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
90rdsk_rdli:
91 out PORTD,zl ;1 Col 0..7
4bd49b80
L
92 out PORTC,_CAS0 ;1
93 out DDRD,_0 ;1
abeec861
L
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)
4bd49b80 109 ldi temp2,32
abeec861
L
110rdsk_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
4bd49b80 121
abeec861
L
122
123rdsk_write:
124 lds xl,dmaadr
125 lds xh,dmaadr+1
126 rcall rdsk_adr
127 ldi temp3,4
128 push yh
129 push yl
130rdsk_wrlo:
131 ldi yl,low (rdskbuf)
132 ldi yh,high(rdskbuf)
133 ldi temp2,32
134rdsk_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)
153rdsk_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
4bd49b80 163
abeec861
L
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
92202636 175
64219415 176;-------------------------------------- Defines for RAMDISK Structures
92202636 177
64219415
FZ
178;----------------------------------------------- Start of Data Segment
179
92202636
L
180 .dseg
181
182rdskbuf: .byte 128 ; Buffer for RAM-Disk interaktions
183
64219415 184; ---------------------------------------------- Start of Code Segment
92202636 185 .cseg
64219415 186
92202636 187; ====================================================================
64219415 188; Function: Calculate an sets the adress of Sector within the RAMDISK
92202636
L
189; ====================================================================
190; Parameters
191; --------------------------------------------------------------------
192; Registers : none
193; Variables : [r] seeksec Sector to read
194; [r] seektrk Track to read
4bd49b80 195; [w] temp3 Number of Bytes per Sector (128)
92202636
L
196; --------------------------------------------------------------------
197; Description:
198; ====================================================================
64219415
FZ
199
200
201rdsk_adr:
202 ldi xl,0
203 lds xh,seeksec
204 lds temp2,seektrk
4bd49b80 205
64219415
FZ
206 lsr xh
207 ror xl ;Col 0..7
4bd49b80 208
64219415
FZ
209 mov temp,temp2
210 andi temp,0x0f
211 swap temp
212 or xh,temp ;Row 0..7
4bd49b80 213
64219415 214 ldiw z,rdskbuf
abeec861 215 ldi temp3,128
64219415
FZ
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
abeec861 220 printstring " "
64219415
FZ
221 mov temp,xh
222 rcall printhex
223 printstring " "
224 mov temp,xl
225 rcall printhex
226 printstring " "
227.endif
228 ret
229
92202636 230; ====================================================================
64219415 231; Function: Does a read opperation on a RAMDISK
92202636
L
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; ====================================================================
64219415
FZ
243
244
245rdsk_read:
92202636 246
64219415
FZ
247.if DISK_DEBUG > 1
248 printnewline
249 printstring "rd-adr: "
250.endif
251 rcall rdsk_adr
92202636 252
64219415
FZ
253rdsk_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
4bd49b80 280 ldi temp3,128
64219415
FZ
281rdsk_rdstl:
282 ld temp,z+
283 mem_write
284 adiw x,1
285 dec temp3
286 brne rdsk_rdstl
287 ret
4bd49b80 288
92202636 289; ====================================================================
64219415 290; Function: Does a write opperation on a RAMDISK
92202636
L
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; ====================================================================
64219415
FZ
302
303rdsk_write:
304.if DISK_DEBUG > 1
305 printnewline
306 printstring "wr-adr: "
4bd49b80 307.endif
64219415
FZ
308 lds xl,dmaadr
309 lds xh,dmaadr+1
310 ldiw z,rdskbuf
4bd49b80 311 ldi temp3,128
64219415
FZ
312rdsk_wrldl:
313 mem_read
314 st z+,temp
315 adiw x,1
316 dec temp3
4bd49b80 317 brne rdsk_wrldl
64219415
FZ
318
319 ldi temp2,RAM_DQ_MASK | (1<<ram_w) | (1<<ram_cas)
320 out DDRC,temp2
321 rcall rdsk_adr
322rdsk_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
92202636
L
346 ret
347
348
349rdsk_add_partition:
350 ret
351
352
abeec861
L
353
354#endif /* DRAM_8BIT */
355
356
357#else /* no ram disk */
92202636
L
358
359rdsk_read:
360 ret
361rdsk_write:
362 ret
363rdsk_add_partition:
364 ret
365
abeec861 366#endif /* RAMDISKCNT */