/[projet1]/users/chema/1337/1337intro/disk.s
Defence Force logotype

Contents of /users/chema/1337/1337intro/disk.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 496 - (show annotations)
Mon May 23 18:53:23 2011 UTC (7 years, 11 months ago) by Chema
File size: 8154 byte(s)
New location
1 #define LOW(x) <(x)
2 #define HIGH(x) >(x)
3
4 ;;;;;;;;;;;;;;;; Routines to manage disk...
5
6 __sectors_per_track .byt 17
7 __double_sided .byt $00
8 __stepping_rate .byt 0 ; 6 ms
9 sectors_per_cyl .byt 0
10
11 diskcntrl .byt $86
12
13 ;oldirq .word 0
14
15 .zero
16 pbufl .byt 0
17 pbufh .byt 0
18
19 .text
20
21
22 _load_overlay
23 .(
24 php
25 sei
26
27 ; Sector to read
28 lda #100
29 ldy #0
30 sta (sp),y
31 tya
32 iny
33 sta (sp),y
34
35 ; Address of buffer
36 iny
37 lda #<$c000
38 sta (sp),y
39 lda #>$c000
40 iny
41 sta (sp),y
42
43 ; Load everything into overlay
44 lda #10
45 sta tmp
46 loop
47 jsr _sect_read
48 jsr inc_disk_params
49
50 dec tmp
51 bne loop
52 .)
53 .(
54 ; Sector to read
55 lda #114
56 ldy #0
57 sta (sp),y
58 tya
59 iny
60 sta (sp),y
61
62 ; Address of buffer
63 iny
64 lda #<$ca00
65 sta (sp),y
66 lda #>$ca00
67 iny
68 sta (sp),y
69
70 ; Load everything into overlay
71 lda #5
72 sta tmp
73 loop
74 jsr _sect_read
75 jsr inc_disk_params
76
77 dec tmp
78 bne loop
79 .)
80 ; Load 12 sectors from 100+32
81
82 .(
83 ; Sector to read
84 lda #132
85 ldy #0
86 sta (sp),y
87 tya
88 iny
89 sta (sp),y
90
91 ; Address of buffer
92 iny
93 lda #<$cea0
94 sta (sp),y
95 lda #>$cea0
96 iny
97 sta (sp),y
98
99 ; Load everything into overlay
100 lda #13
101 sta tmp
102 loop
103 jsr _sect_read
104 jsr inc_disk_params
105
106 dec tmp
107 bne loop
108
109
110 plp
111 rts
112 .)
113
114
115
116 ; Routine to increment disk reading/writting parameters
117 inc_disk_params
118 .(
119 ; Increment address in 256 bytes
120 ldy #3
121 lda (sp),y
122 clc
123 adc #1
124 sta (sp),y
125
126 ; Increment sector to read
127 ldy #0
128 lda (sp),y
129 clc
130 adc #1
131 sta (sp),y
132 //#ifdef 0
133 pha
134 //#endif
135 iny
136 lda (sp),y
137 adc #0
138 sta (sp),y
139 //#ifdef 0
140 ;Sedoric bug workaround
141 pla
142 cmp #225 ;$f3
143 bne nosedbug
144 dey
145 lda #226; $f4
146 sta (sp),y
147 iny
148 nosedbug
149 //#endif
150 rts
151 .)
152
153
154
155
156 _switch_ovl
157 php
158 pha
159 sei
160 lda diskcntrl
161 eor #2
162 sta diskcntrl
163 sta $0314
164 lda #0
165 sta $032F
166 pla
167 plp
168 rts
169
170 _init_disk
171 php
172 sei
173 //#ifdef OLDROUTINES
174 lda #LOW(irq_handler)
175 sta $fffe
176 lda #HIGH(irq_handler)
177 sta $ffff
178 //#endif
179 jsr restore_track0
180 plp
181 rts
182
183 _sect_write
184 lda #$a0 ; write command
185 bne sect_rw
186 _sect_read
187 lda #$80 ; read command
188 sect_rw
189 sta readwrite
190
191 ldy #2
192 lda (sp),y
193 sta __buffer
194 iny
195 lda (sp),y
196 sta __buffer+1
197
198 jsr __linear_to_physical_sector
199 jsr __sector_readwrite
200
201 ldx #0
202 rts
203
204 __linear_to_physical_sector
205 ldy #0
206 lda (sp),y
207 tax
208 iny
209 lda (sp),y
210 tay
211 txa
212
213 ldx __sectors_per_track
214 stx sectors_per_cyl
215 ldx #$ff
216 bit __double_sided
217 bpl compute_cylinder
218 asl sectors_per_cyl
219 compute_cylinder
220 inx
221 sec
222 sbc sectors_per_cyl
223 bcs compute_cylinder
224 dey
225 bpl compute_cylinder
226 adc sectors_per_cyl
227
228 stx __cylinder
229 ldy #0
230 cmp __sectors_per_track
231 bcc store_side
232 ldy #$10
233 sbc __sectors_per_track
234 store_side
235 sty __side
236 tay
237 iny
238 sty __sector
239
240 rts
241
242
243 __sector .byt 0
244 __cylinder .byt 0
245 __side .byt 0
246 __status .byt 0
247 __buffer .word 0
248
249 restart_counter .byt 0
250 readwrite .byt 0
251 old_ier .byt 0
252
253 save_ier
254 ldy $030e
255 sty old_ier
256 ldy #$7f
257 sty $030e
258 rts
259
260 restore_ier
261 ldy old_ier
262 sty $030e
263 rts
264
265 wait_completion
266 lda $0314
267 bmi wait_completion
268 .dsb (($0310&3)-((*+3)&3))&3,$ea
269 lda $0310
270 _chk_310a
271 rts
272
273 restore_track0
274 lda #$0C
275 .dsb (($0310&3)-((*+3)&3))&3,$ea
276 sta $0310
277 _chk_310b
278 jsr wait_completion
279 and #$10 ; seek error ?
280 bne restore_track0
281 rts
282
283 seek_track
284 lda #$1C
285 ora __stepping_rate
286 .dsb (($0310&3)-((*+3)&3))&3,$ea
287 sta $0310
288 _chk_310c
289 jsr wait_completion
290 and #$18 ; seek error or CRC error ?
291 beq seek_ok
292 jsr restore_track0
293 beq seek_track
294 seek_ok
295 rts
296
297 __select_sector
298 lda diskcntrl ; current drive/side selection
299 and #$ef
300 ora __side
301 sta diskcntrl ; side updated
302 ;ora #$01 ; enables FDC interrupts
303 sta $0314
304
305 lda __cylinder
306 .dsb (($0313&3)-((*+3)&3))&3,$ea
307 sta $0313
308 _chk_313a
309 .dsb (($0311&3)-((*+3)&3))&3,$ea
310 cmp $0311
311 _chk_311a
312 beq *+5
313 jsr seek_track
314 lda __sector
315 .dsb (($0312&3)-((*+3)&3))&3,$ea
316 sta $0312
317 _chk_312a
318 rts
319
320 readwrite_data
321 #ifdef OLDROUTINES
322 cli
323 #endif
324 lda #0
325 sta pbufl
326 lda __buffer+1
327 sta pbufh
328 ldy __buffer
329 lda readwrite
330 cmp #$a0
331 beq write_data
332
333 #ifdef OLDROUTINES
334 read_data
335 lda $0318
336 bmi read_data
337 .dsb (($0313&3)-((*+3)&3))&3,$ea
338 lda $0313
339 _chk_313b
340 sta (pbufl),y
341 iny
342 bne read_data
343 inc pbufh
344 jmp read_data
345
346
347 write_data
348 lda $0318
349 bmi write_data
350 lda (pbufl),y
351 .dsb (($0313&3)-((*+3)&3))&3,$ea
352 sta $0313
353 _chk_313c
354 iny
355 bne write_data
356 inc pbufh
357 jmp write_data
358
359 #else
360
361
362 read_data
363 /*
364 lda $0310
365 lsr
366 bcc end_read
367 lda $0318
368 bmi read_data
369 */
370
371 bit $0314
372 bpl end_read
373 bit $0318
374 bmi read_data
375
376 .dsb (($0313&3)-((*+3)&3))&3,$ea
377 lda $0313
378 _chk_313d
379 sta (pbufl),y
380 iny
381 bne read_data
382 inc pbufh
383 jmp read_data
384 end_read
385 .dsb (($0310&3)-((*+3)&3))&3,$ea
386 lda $0310
387 _chk_al_2
388 rts
389
390 write_data
391 /*
392 lda $0310
393 lsr
394 bcc end_write
395 lda $0318
396 bmi write_data
397 */
398
399 bit $0314
400 bpl end_write
401 bit $0318
402 bmi write_data
403
404 lda (pbufl),y
405 .dsb (($0313&3)-((*+3)&3))&3,$ea
406 sta $0313
407 _chk_313e
408 iny
409 bne write_data
410 inc pbufh
411 jmp write_data
412 end_write
413 rts
414 #endif
415
416
417 __sector_readwrite
418 php
419 sei
420 jsr save_ier
421 ldy #8
422 sty restart_counter
423 again
424 jsr __select_sector
425 lda readwrite
426 .dsb (($0310&3)-((*+3)&3))&3,$ea
427 sta $0310
428 _chk_310d
429 jsr readwrite_data
430
431 #ifndef OLDROUTINES
432 /* As there is no more IRQ, we have to do this differently */
433 /* instead of simply lda __status, we need to read it here. */
434 .dsb (($0310&3)-((*+3)&3))&3,$ea
435 lda $0310 ; gets status
436 _chk_310e
437 and #$7c
438 sta __status
439 #else
440 lda __status
441 #endif
442
443 beq success
444 dec restart_counter
445 bne again
446 success
447
448 jsr restore_ier
449 plp
450 rts
451
452
453 irq_handler
454 .(
455 #ifdef OLDROUTINES
456 bit $030D
457 bpl fdc_irq
458 pha ; cancel any VIA interrupt when overlay ram is active
459 lda #$7F
460 sta $030D
461 lda #2
462 sta $031F
463 lda $031D ; clear any pending ACIA interrupt
464 pla
465 rti
466 fdc_irq
467 pla ; get rid of IRQ context
468 pla
469 pla
470 lda diskcntrl
471 sta $0314 ; disables disk irq
472 .dsb (($0310&3)-((*+3)&3))&3,$ea
473 lda $0310 ; gets status and resets irq
474 _chk_310f
475 and #$7c
476 sta __status
477 rts
478 #else
479 pha
480 test_via1
481 bit $030D
482 bpl test_via2
483 lda #$7F
484 sta $030D ; cancel any VIA interrupt
485 test_via2
486 bit $032D ; on the Oric1/Atmos, this will test via1 again
487 bpl test_acia
488 lda #$7F
489 sta $032D ; cancel any VIA2 interrupt (VIA1 on the Atmos)
490 test_acia
491 bit $031D ; on the Oric1/Atmos, this will test via1 again !
492 bpl test_fdc
493 ; reading the ACIA status has already cleared the interrupt, so no need to do anything
494 ; if it is a VIA interrupt on the Atmos, it has happened between the first via test and now,
495 ; so we ignore it: it will raise another interrupt that will be cleared during the second interrupt handler test_fdc
496 bit $0314 ; $0314 reflects INTRQ state in negative logic
497 bmi all_tests_done
498 test_fdc
499 .dsb (($0310&3)-((*+3)&3))&3,$ea
500 lda $0310 ; read FDC status and clears interrupt request
501 _chk_310g
502 all_tests_done
503 pla
504 rti
505 #endif
506 .)
507

  ViewVC Help
Powered by ViewVC 1.1.26