]>
Commit | Line | Data |
---|---|---|
64219415 FZ |
1 | ; Filesystem functions for the Interaction with BIOS and Disks |
2 | ; | |
3 | ; Copyright (C) 2010 Frank Zoll | |
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$ | |
b741422e L |
21 | ; |
22 | ||
29ce189c | 23 | .equ DSKSEL_DEBUG = 0 |
b741422e | 24 | |
64219415 FZ |
25 | ; ---------------- Defines for the Filesystem Interface ------- |
26 | ||
64219415 FZ |
27 | ;***************************************************** |
28 | ;* Disk-Manager constants * | |
29 | ;***************************************************** | |
dd7aea8c L |
30 | |
31 | ; Fields in the parttabl | |
32 | ||
33 | .equ MAXDISKS = 8 ;Max number of Disks (partitions) | |
34 | .equ PARTENTRY_SIZE = 9 ;Size of a Partitiontableentry | |
35 | ||
36 | .equ PTAB_TYPE = 0 | |
37 | .equ PTAB_START = 1 | |
38 | .equ PTAB_SIZE = 5 | |
39 | .equ PTAB_SPT = 7 | |
40 | .equ PTAB_BSH = 8 | |
41 | ||
42 | .equ dskType_None = 0 << 4 | |
43 | .equ dskType_CPM = 1 << 4 | |
44 | .equ dskType_FAT = 2 << 4 | |
45 | ; .equ dskType_RAM = 3 << 4 | |
46 | .equ dskType_MASK = 0xf << 4 | |
64219415 FZ |
47 | |
48 | ;***************************************************** | |
49 | ;* CP/M to host disk constants * | |
50 | ;***************************************************** | |
dd7aea8c L |
51 | ; .equ blksize = 1024 ;CP/M allocation size |
52 | ; .equ CPMSPT = 26 ; | |
53 | ||
54 | .equ HOSTSIZE = 512 ;host disk sector size | |
55 | .equ HOSTBLK = HOSTSIZE/128 ;CP/M sects/host buff | |
56 | .equ SECMSK = HOSTBLK-1 ;sector mask | |
57 | .equ SECSHF = log2(HOSTBLK) ;sector shift | |
64219415 FZ |
58 | |
59 | ;***************************************************** | |
60 | ;* BDOS constants on entry to write * | |
61 | ;***************************************************** | |
62 | .equ WRALL = 0 ;write to allocated | |
63 | .equ WRDIR = 1 ;write to directory | |
64 | .equ WRUAL = 2 ;write to unallocated | |
b741422e | 65 | .equ WRTMSK= 3 ;write type mask |
eb85ce65 L |
66 | |
67 | .equ READ_FUNC = 7 | |
68 | .equ WRITE_FUNC = 6 | |
69 | .equ BOOT_FUNC = 5 | |
70 | .equ HOME_FUNC = 4 | |
71 | ||
64219415 FZ |
72 | ;----------------------------------------------- Start of Data Segment |
73 | ||
b741422e L |
74 | .dseg |
75 | ||
29ce189c L |
76 | ; The following 3 variables are copied from DRAM. |
77 | ; Don't change order. | |
78 | ||
79 | biosdrvtbl: .byte 2 ; | |
80 | biosdirbuf: .byte 2 ; | |
81 | biosenddat: .byte 2 ; | |
82 | ||
83 | ndisks: .byte 1 ;Number of CP/M disks | |
64219415 | 84 | |
29ce189c L |
85 | ; The following 5 variables are accessed from 8080/z80 via the |
86 | ; virtual port interface. Don't change order. | |
64219415 | 87 | |
29ce189c L |
88 | biospar_base: |
89 | bcbadr: .byte 2 ;adr of BiosControlBlock | |
90 | seekdsk: .byte 1 ;seek disk number | |
91 | seektrk: .byte 2 ;seek track number | |
92 | seeksec: .byte 2 ;seek sector number | |
93 | dmaadr: .byte 2 ;last dma address | |
64219415 | 94 | |
dd7aea8c L |
95 | hdrsize: .byte 1 ;Image header size (offset) |
96 | cpmspt: .byte 1 ;CP/M sectors per track | |
97 | secpblk: .byte 1 ;sectors per block (alloc size) | |
29ce189c L |
98 | unacnt: .byte 1 ;unalloc rec cnt |
99 | unadsk: .byte 1 ;last unalloc disk | |
100 | unatrk: .byte 2 ;last unalloc track | |
5482d75f | 101 | unasec: .byte 2 ;last unalloc sector |
64219415 | 102 | |
29ce189c L |
103 | erflag: .byte 1 ;error reporting |
104 | wrtype: .byte 1 ;write operation type | |
105 | ||
29ce189c | 106 | hostdsk: .byte 1 ;host disk number |
5482d75f | 107 | hostlba: .byte 2 ;host sector number (relative to partition start) |
dd7aea8c L |
108 | hostparttbl: .byte PARTENTRY_SIZE*MAXDISKS ;host partition table (type, start sector, sector count) |
109 | hostparttbltop: | |
110 | hostbuf: .byte HOSTSIZE ;host buffer (from/to SD-card) | |
b741422e L |
111 | |
112 | ||
64219415 | 113 | ; ------------------------------- Start of Code Segment |
b741422e L |
114 | .cseg |
115 | ||
29ce189c L |
116 | ;--------------------------------------------------------------------- |
117 | ||
118 | .if DSKSEL_DEBUG | |
119 | ||
120 | dbg_prdrvtbl: | |
121 | push xh | |
122 | push xl | |
123 | push temp3 | |
124 | push temp2 | |
125 | push temp | |
126 | printnewline | |
127 | printstring "drvtbl (" | |
128 | lds xl,biosdrvtbl | |
129 | lds xh,biosdrvtbl+1 | |
130 | movw temp,x | |
131 | rcall printhexw | |
132 | printstring "): " | |
133 | ldi temp3,16 | |
134 | dbg_pcpel: | |
135 | rcall dram_readw_pp | |
136 | rcall printhexw | |
137 | printstring " " | |
138 | dec temp3 | |
139 | brne dbg_pcpel | |
140 | pop temp | |
141 | pop temp2 | |
142 | pop temp3 | |
143 | pop xl | |
144 | pop xh | |
145 | ret | |
146 | ||
147 | dbg_print_biosd: | |
148 | printnewline | |
149 | lds temp,bcbadr | |
150 | lds temp2,bcbadr+1 | |
151 | rcall printhexw | |
152 | printstring " " | |
153 | lds temp,biosdrvtbl | |
154 | lds temp2,biosdrvtbl+1 | |
155 | rcall printhexw | |
156 | printstring " " | |
157 | lds temp,biosdirbuf | |
158 | lds temp2,biosdirbuf+1 | |
159 | rcall printhexw | |
160 | printstring " " | |
161 | lds temp,biosenddat | |
162 | lds temp2,biosenddat+1 | |
163 | rcall printhexw | |
164 | printstring " " | |
165 | ret | |
166 | .endif | |
167 | ||
5482d75f | 168 | ; ==================================================================== |
b741422e | 169 | ; ==================================================================== |
1eeb9cbe | 170 | ; Function: Get a Pointer to a Partitiontable entry |
b741422e L |
171 | ; ==================================================================== |
172 | ; Parameters | |
173 | ; -------------------------------------------------------------------- | |
1eeb9cbe | 174 | ; Registers : [w] z Pointer to the Partitionentry |
dd7aea8c | 175 | ; [r] zl Number of Diskentry to Read |
29ce189c L |
176 | ; [w] _tmp0 scratch |
177 | ; [w] _tmp1 " | |
b741422e L |
178 | ; -------------------------------------------------------------------- |
179 | ; Description: | |
180 | ; ==================================================================== | |
1eeb9cbe L |
181 | dsk_getpartentry: |
182 | ||
dd7aea8c L |
183 | ldi zh,PARTENTRY_SIZE |
184 | mul zh,zl | |
1eeb9cbe | 185 | ldiw z,hostparttbl |
eb85ce65 | 186 | add zl,_tmp0 |
dcd7e502 | 187 | adc zh,_tmp1 |
64219415 | 188 | ret |
b741422e | 189 | |
5482d75f | 190 | ; ==================================================================== |
1eeb9cbe | 191 | ; ==================================================================== |
29ce189c | 192 | ; Function: Virtual Port Interface |
1eeb9cbe L |
193 | ; ==================================================================== |
194 | ; Parameters | |
195 | ; -------------------------------------------------------------------- | |
29ce189c L |
196 | ; Registers : |
197 | ; Variables : | |
198 | ; | |
199 | ; -------------------------------------------------------------------- | |
200 | ; Description: | |
201 | ; ==================================================================== | |
202 | ||
203 | dsk_param_getadr: | |
204 | ldiw z,biospar_base | |
205 | add zl,temp3 | |
206 | adc zh,_0 | |
207 | ret | |
208 | ||
5482d75f | 209 | dsk_param_set: |
29ce189c L |
210 | rcall dsk_param_getadr |
211 | st z,temp | |
29ce189c L |
212 | cpi temp3,bcbadr+1-biospar_base |
213 | breq SetBCB | |
214 | ret | |
215 | ||
5482d75f | 216 | dsk_param_get: |
29ce189c L |
217 | cpi temp3,seekdsk-biospar_base |
218 | breq dskDiskCheck | |
219 | rcall dsk_param_getadr | |
220 | ld temp,z | |
221 | ret | |
222 | ||
223 | SetBCB: | |
224 | lds xl,bcbadr | |
225 | mov xh,temp | |
226 | ldiw z,biosdrvtbl | |
227 | ldi temp3,6 | |
228 | sbcb_l: | |
229 | rcall dram_read_pp | |
230 | st z+,temp | |
231 | dec temp3 | |
232 | brne sbcb_l | |
233 | ||
234 | ; rcall dbg_print_biosd | |
5482d75f | 235 | rcall dpb_drvtblclear |
29ce189c L |
236 | ; rcall dbg_prdrvtbl |
237 | ||
238 | ret | |
239 | ||
240 | ; ==================================================================== | |
241 | ; Function: Check if disk exists | |
242 | ; ==================================================================== | |
243 | ; Parameters | |
244 | ; -------------------------------------------------------------------- | |
245 | ; Registers : | |
246 | ; Variables : | |
247 | ; return 0, if selected disk not exist. | |
248 | ; return !0, if disk exist | |
1eeb9cbe L |
249 | ; -------------------------------------------------------------------- |
250 | ; Description: | |
251 | ; ==================================================================== | |
64219415 | 252 | dskDiskCheck: |
637689de L |
253 | lds temp2,ndisks |
254 | lds temp,seekdsk | |
29ce189c L |
255 | .if DSKSEL_DEBUG |
256 | printnewline | |
257 | printstring "DiskCheck: " | |
258 | rcall printhexw | |
259 | .endif | |
637689de | 260 | cpi temp,RAMDISKNR |
64219415 FZ |
261 | brsh dsk_dchrd ;maybe ramdisk |
262 | ||
637689de | 263 | tst temp2 ;0 disks? |
64219415 FZ |
264 | brne dsk_dchpart1 |
265 | ||
eb85ce65 | 266 | ; No disks yet, need to init |
64219415 | 267 | |
5482d75f L |
268 | rcall dpb_drvtblclear |
269 | .if 0 | |
270 | ldi temp2,0x40 | |
271 | ldi temp,1 | |
272 | lcall clockput | |
273 | .endif | |
29ce189c | 274 | rcall mgr_init_partitions ;disk chanched? |
5482d75f L |
275 | push temp |
276 | .if 0 | |
277 | ldi temp2,0x40 | |
278 | ldi temp,2 | |
279 | lcall clockput | |
29ce189c L |
280 | ; sbrs temp,7 |
281 | ; rjmp dsk_dchpart0 | |
5482d75f L |
282 | |
283 | lcall mgr_prnt_parttbl | |
284 | printnewline | |
285 | .endif | |
286 | ||
29ce189c | 287 | ; rcall dbg_prdrvtbl |
637689de | 288 | pop temp2 |
29ce189c | 289 | dsk_dchpart0: |
637689de L |
290 | cbr temp2,0x80 |
291 | lds temp,seekdsk | |
64219415 | 292 | |
5482d75f L |
293 | ; Check if selected disk # is less then # of disks. |
294 | ||
64219415 | 295 | dsk_dchpart1: |
637689de | 296 | cp temp,temp2 |
29ce189c L |
297 | brsh dsk_dch_err |
298 | ||
299 | .if DSKSEL_DEBUG | |
300 | printnewline | |
301 | printstring "Select: " | |
29ce189c L |
302 | rcall printhex |
303 | .endif | |
637689de | 304 | rcall dpb_drvtbl_entry_get |
29ce189c L |
305 | or temp,temp2 ;if !0, drive is allready initialized |
306 | brne dsk_dchend | |
5482d75f L |
307 | lds temp3,seekdsk |
308 | mov temp,temp3 | |
309 | rcall dpb_biosdph_get | |
64219415 | 310 | dsk_dchend: |
5482d75f | 311 | |
29ce189c L |
312 | .if DSKSEL_DEBUG |
313 | push temp | |
29ce189c | 314 | lds temp,seekdsk |
637689de L |
315 | rcall dpb_drvtbl_entry_get |
316 | ||
29ce189c L |
317 | printstring ", " |
318 | rcall printhexw | |
319 | pop temp | |
320 | .endif | |
321 | ||
64219415 FZ |
322 | ret |
323 | ||
29ce189c L |
324 | dsk_dch_err: |
325 | ldi temp,0 ;error return | |
326 | ret | |
327 | ||
328 | ; Check RAMDISK | |
329 | ||
64219415 FZ |
330 | dsk_dchrd: |
331 | #if RAMDISKCNT | |
29ce189c L |
332 | cpi temp,RAMDISKNR+RAMDISKCNT |
333 | brsh dsk_dchrd_err | |
334 | ||
335 | ldi temp,0xff ;return ok | |
336 | ret | |
64219415 | 337 | #endif |
29ce189c L |
338 | dsk_dchrd_err: |
339 | ldi temp,0 ;error return | |
64219415 | 340 | ret |
29ce189c L |
341 | |
342 | ||
343 | ; ==================================================================== | |
344 | ; Function: Return status of last disk i/o function | |
345 | ; ==================================================================== | |
346 | ; Parameters | |
347 | ; -------------------------------------------------------------------- | |
348 | ; Registers : | |
349 | ; Variables : | |
350 | ; -------------------------------------------------------------------- | |
351 | ; Description: | |
352 | ; ==================================================================== | |
64219415 | 353 | dskErrorRet: |
29ce189c | 354 | lds temp,erflag |
64219415 FZ |
355 | ret |
356 | ||
29ce189c | 357 | |
5482d75f L |
358 | ; ==================================================================== |
359 | ; ==================================================================== | |
64219415 | 360 | |
64219415 | 361 | |
29ce189c | 362 | .dseg |
dd7aea8c | 363 | tmpdpb: .byte 16 |
29ce189c L |
364 | |
365 | .cseg | |
366 | ||
dcd7e502 L |
367 | str_CPM_Disk: |
368 | .db 10,"<CPM_Disk>",0 | |
369 | ||
dd7aea8c L |
370 | ; DPBs for varios fixed formats |
371 | ; dpb data starts at 2. byte | |
372 | ||
373 | dpbdat_avrcpm: ;(dpb243) | |
374 | .db 0x00,0x1A ;sector offset, low(spt) | |
375 | .db 0x00,0x03 ;high (spt), block shift | |
376 | .db 0x07,0x00 ;bock mask, extent mask | |
377 | .db 0xF2,0x00 ;disk size - 1, | |
378 | .db 0x3F,0x00 ;dir max | |
379 | .db 0xC0,0x00 ;alloc0, alloc1 | |
380 | .db 0x10,0x00 ;chk size | |
381 | .db 0x02,0x00 ;offset | |
382 | ||
dd7aea8c L |
383 | dpbdat_myz80: ; |
384 | .db 0x02,0x80 ;sector offset, low(spt) | |
385 | .db 0x00,0x05 ;high (spt), block shift | |
386 | .db 0x1F,0x01 ;bock mask, extent mask | |
387 | .db 0xFF,0x07 ;disk size - 1, | |
388 | .db 0xFF,0x03 ;dir max | |
389 | .db 0xFF,0x00 ;alloc0, alloc1 | |
390 | .db 0x00,0x01 ;chk size | |
391 | .db 0x00,0x00 ;offset | |
29ce189c | 392 | |
b165699b L |
393 | dpbdat_simhd: ; |
394 | .db 0x00,0x20 ;sector offset, low(spt) | |
395 | .db 0x00,0x05 ;high (spt), block shift | |
396 | .db 0x1F,0x01 ;bock mask, extent mask | |
397 | .db 0xF9,0x07 ;disk size - 1, | |
398 | .db 0xFF,0x03 ;dir max | |
399 | .db 0xFF,0x00 ;alloc0, alloc1 | |
400 | .db 0x00,0x01 ;chk size | |
401 | .db 0x06,0x00 ;offset | |
402 | ||
29ce189c L |
403 | #if 0 |
404 | ;rd1016 | |
405 | .db 0x20,0x00 ;spt | |
406 | .db 0x04,0x0F ;block shift, bock mask | |
407 | .db 0x00,0xFB ;extent mask, low(disk size -1), | |
408 | .db 0x01,0xBF ;high(disk size -1), low(dir max) | |
409 | .db 0x00,0xE0 ;high(dir max), alloc0 | |
410 | .db 0x00,0x30 ;alloc1, low(chk size) | |
411 | .db 0x00,0x02 ;high(chk size), low(offset) | |
412 | .db 0x00,0x00 ;high(offset), fill | |
413 | ;rd9192s | |
414 | .db 0x20,0x00 ;spt | |
415 | .db 0x05,0x1F ;block shift, bock mask | |
416 | .db 0x01,0xFD ;extent mask, low(disk size -1), | |
417 | .db 0x07,0xFF ;high(disk size -1), low(dir max) | |
418 | .db 0x01,0xF0 ;high(dir max), alloc0 | |
419 | .db 0x00,0x80 ;alloc1, low(chk size) | |
420 | .db 0x00,0x02 ;high(chk size), low(offset) | |
421 | .db 0x00,0x00 ;high(offset), fill | |
422 | #endif | |
423 | ||
dd7aea8c | 424 | |
5482d75f | 425 | ; Copy the dpb data from flash memory, pointed to by Z, to temp ram. |
dd7aea8c L |
426 | |
427 | dpb_copy_p: | |
29ce189c L |
428 | push yh |
429 | push yl | |
29ce189c | 430 | ldi temp2,16 |
29ce189c | 431 | ldiw y,tmpdpb |
dd7aea8c | 432 | cpydpb_pl: |
29ce189c L |
433 | lpm temp,z+ |
434 | st y+,temp | |
dd7aea8c L |
435 | dec temp2 |
436 | brne cpydpb_pl | |
29ce189c L |
437 | pop yl |
438 | pop yh | |
64219415 | 439 | ret |
dd7aea8c L |
440 | |
441 | ; Copy the dpb data, pointed to by Z to temp ram. | |
442 | ||
443 | dpb_copy: | |
444 | st y+,temp | |
445 | ldi temp2,15 | |
446 | cpydpb_l: | |
447 | ld temp,z+ | |
448 | st y+,temp | |
449 | dec temp2 | |
450 | brne cpydpb_l | |
451 | ret | |
452 | ||
453 | ||
637689de L |
454 | ; ==================================================================== |
455 | ; Function: get drive table entry pointer for drive # in temp | |
456 | ; ==================================================================== | |
457 | ; Parameters | |
458 | ; -------------------------------------------------------------------- | |
459 | ; Registers : | |
460 | ; Variables : | |
461 | ; | |
462 | ; -------------------------------------------------------------------- | |
463 | ; Description: | |
464 | ; ==================================================================== | |
465 | ||
466 | dpb_drvtbl_entry_p: | |
467 | ||
468 | ldsw x,biosdrvtbl | |
469 | lsl temp ;drive # | |
470 | add xl,temp | |
471 | adc xh,_0 | |
472 | ret | |
473 | ||
474 | ||
475 | ; ==================================================================== | |
476 | ; Function: get drive table entry for drive # in temp | |
477 | ; ==================================================================== | |
478 | ; Parameters | |
479 | ; -------------------------------------------------------------------- | |
480 | ; Registers : | |
481 | ; Variables : | |
482 | ; | |
483 | ; -------------------------------------------------------------------- | |
484 | ; Description: | |
485 | ; ==================================================================== | |
486 | ||
487 | dpb_drvtbl_entry_get: | |
488 | ||
489 | rcall dpb_drvtbl_entry_p | |
490 | ljmp dram_readw_pp | |
491 | ||
492 | ||
29ce189c | 493 | ; ==================================================================== |
dd7aea8c | 494 | ; Function: Clear drive table (entries 0 to 7) |
29ce189c L |
495 | ; ==================================================================== |
496 | ; Parameters | |
497 | ; -------------------------------------------------------------------- | |
498 | ; Registers : | |
499 | ; Variables : | |
500 | ; | |
501 | ; -------------------------------------------------------------------- | |
502 | ; Description: | |
503 | ; ==================================================================== | |
64219415 | 504 | |
dd7aea8c | 505 | ; |
29ce189c | 506 | |
5482d75f | 507 | dpb_drvtblclear: |
29ce189c | 508 | ldsw x,biosdrvtbl |
5482d75f L |
509 | sbiw x,0 |
510 | breq dpb_drvi_ex | |
511 | ||
512 | dpb_drvi_1: | |
dd7aea8c | 513 | ldi temp3,8 |
5482d75f | 514 | dpb_drvi_lp: |
29ce189c L |
515 | ldi temp,0 |
516 | ldi temp2,0 | |
517 | rcall dram_writew_pp | |
518 | dec temp3 | |
5482d75f | 519 | brne dpb_drvi_lp |
29ce189c L |
520 | |
521 | lds temp,biosenddat | |
522 | lds temp2,biosenddat+1 | |
5482d75f L |
523 | cp temp,_0 |
524 | cpc temp2,_0 | |
525 | breq dpb_drvi_ex | |
526 | ||
29ce189c | 527 | rcall heap_init |
5482d75f | 528 | dpb_drvi_ex: |
29ce189c | 529 | clr temp |
64219415 FZ |
530 | ret |
531 | ||
dd7aea8c | 532 | ; ==================================================================== |
5482d75f | 533 | ; Function: Test disk format: avrcpmhd |
dd7aea8c L |
534 | ; ==================================================================== |
535 | ; Parameters | |
536 | ; -------------------------------------------------------------------- | |
537 | ; Registers : temp drive # | |
538 | ; | |
539 | ; -------------------------------------------------------------------- | |
5482d75f | 540 | ; Description: Not implemented yet. |
dd7aea8c L |
541 | ; ==================================================================== |
542 | ||
543 | dsk_tst_avrcpmhd: | |
5482d75f | 544 | clr temp ; Test, return 'not found' for now. |
dd7aea8c L |
545 | ret |
546 | ||
547 | ||
548 | ; ==================================================================== | |
549 | ; Function: Test disk format: YAZE | |
550 | ; ==================================================================== | |
551 | ; Parameters | |
552 | ; -------------------------------------------------------------------- | |
553 | ; Registers : temp drive # | |
554 | ; | |
555 | ; -------------------------------------------------------------------- | |
556 | ; Description: From the YAZE Doc: | |
557 | ; | |
558 | ; The new disk header occupies the first 128 BYTES of the file and has the | |
559 | ; new format: | |
560 | ; | |
561 | ; 0 - 9 <CPM_Disk> | |
562 | ; 10 - 15 a null-terminated ascii comment (may be empty) | |
563 | ; new 16 version (0 = yaze-1.06/1.10, 1 = yaze-ag-2.xx) | |
564 | ; 17 - 31 a null-terminated ascii comment (may be empty) | |
565 | ; 32 - 33 sectors per track | |
566 | ; 34 block shift factor | |
567 | ; 35 block mask | |
568 | ; 36 extent mask | |
569 | ; 37 - 38 disk size max | |
570 | ; 39 - 40 directory max | |
571 | ; 41 al0 | |
572 | ; 42 al1 | |
573 | ; 43 - 44 check size (always zero) | |
574 | ; 45 - 46 track offset | |
575 | ; new 47 psh (used if version=1 and CP/M 3.1 is running) | |
576 | ; new 48 phm ( " " " " " " " " " ) | |
577 | ; 49 - 127 unused (zeros) | |
578 | ; ==================================================================== | |
579 | ||
580 | ||
dd7aea8c L |
581 | dsk_tst_yaze: |
582 | ||
583 | ldiw y,hostbuf | |
dcd7e502 | 584 | ldiw z,str_CPM_Disk*2 |
dd7aea8c | 585 | lpm temp2,z+ ; get length |
623dd899 | 586 | lcall strncmp_p |
dd7aea8c L |
587 | brne dsk_tyze_not |
588 | ||
589 | ldiw z,hostbuf+32 | |
590 | ldiw y,tmpdpb | |
591 | ldi temp,1 ;1 sector header size | |
592 | rcall dpb_copy | |
593 | ||
5482d75f | 594 | ori temp,0xff |
dd7aea8c L |
595 | ret |
596 | ||
597 | dsk_tyze_not: | |
5482d75f | 598 | clr temp ;Not a YAZE disk image. |
dd7aea8c | 599 | ret |
29ce189c | 600 | |
dd7aea8c L |
601 | ; ==================================================================== |
602 | ; Function: Test disk format: MyZ80 | |
603 | ; ==================================================================== | |
604 | ; Parameters | |
605 | ; -------------------------------------------------------------------- | |
606 | ; Registers : temp drive # | |
607 | ; | |
608 | ; -------------------------------------------------------------------- | |
609 | ; Description: Test, if first 2 Sectors are filled with 0xE5, | |
b165699b | 610 | ; and Size = 8192KB + 256Bytes. |
dd7aea8c L |
611 | ; ==================================================================== |
612 | dsk_tst_myz80: | |
613 | ||
614 | mov zl,temp3 | |
615 | rcall dsk_getpartentry ;get partition entry | |
616 | ldd temp,z+PTAB_SIZE | |
b165699b L |
617 | ldd temp2,z+PTAB_SIZE+1 ;check, if size is 16385 phys. sectors |
618 | cpi temp,low(16385) | |
619 | ldi temp,high(16385) | |
dd7aea8c L |
620 | cpc temp2,temp |
621 | brne dsk_tmyz80_not ;wrong size | |
622 | ||
623 | ldiw z,hostbuf | |
624 | ldi temp2,0 | |
625 | ||
626 | dsk_tmyz80_loop: | |
627 | ld temp,z+ | |
628 | cpi temp,0xE5 | |
629 | brne dsk_tmyz80_not | |
630 | dec temp2 | |
631 | brne dsk_tmyz80_loop | |
632 | ||
5482d75f | 633 | ori temp,0xff |
dd7aea8c L |
634 | ret |
635 | ||
636 | dsk_tmyz80_not: | |
5482d75f | 637 | clr temp ;Not a MyZ80 hard disk image. |
dd7aea8c L |
638 | ret |
639 | ||
b165699b L |
640 | ; ==================================================================== |
641 | ; Function: Test disk format: simhd, simh altair 8800 hard disk format | |
642 | ; ==================================================================== | |
643 | ; Parameters | |
644 | ; -------------------------------------------------------------------- | |
645 | ; Registers : temp drive # | |
646 | ; | |
647 | ; -------------------------------------------------------------------- | |
dcd7e502 L |
648 | ; Description: Test, if Size = 8192 KB and |
649 | ; first 6 tracks are filled with 0xE5. | |
b165699b L |
650 | ; Actually, only the first phys. sector is tested, since |
651 | ; the other 47 sectors are not in memory at this time. | |
652 | ; ==================================================================== | |
653 | dsk_tst_simhd: | |
654 | ||
655 | mov zl,temp3 | |
656 | rcall dsk_getpartentry ;get partition entry | |
657 | ldd temp,z+PTAB_SIZE | |
658 | ldd temp2,z+PTAB_SIZE+1 ;check, if size is 16384 phys. sectors | |
659 | cpi temp,low(16384) | |
660 | ldi temp,high(16384) | |
661 | cpc temp2,temp | |
662 | brne dsk_tsimhd_not ;wrong size | |
663 | ||
dcd7e502 L |
664 | ldiw y,hostbuf+128-10 |
665 | ldiw z,str_CPM_Disk*2 | |
666 | lpm temp2,z+ ; get length | |
623dd899 | 667 | lcall strncmp_p |
dcd7e502 L |
668 | breq dsk_tsimhd_found |
669 | ||
b165699b L |
670 | ldiw z,hostbuf |
671 | ldi temp2,high(512) | |
672 | clr _tmp0 ;low(512) | |
b165699b L |
673 | dsk_tsimhd_loop: |
674 | ld temp,z+ | |
675 | cpi temp,0xE5 | |
676 | brne dsk_tsimhd_not | |
677 | dec _tmp0 | |
678 | brne dsk_tsimhd_loop | |
679 | dec temp2 | |
680 | brne dsk_tsimhd_loop | |
681 | ||
dcd7e502 | 682 | dsk_tsimhd_found: |
5482d75f | 683 | ori temp,0xff |
b165699b L |
684 | ret |
685 | ||
686 | dsk_tsimhd_not: | |
5482d75f | 687 | clr temp ;Not a simhd hard disk image. |
b165699b L |
688 | ret |
689 | ||
dd7aea8c L |
690 | ; ==================================================================== |
691 | ; Function: | |
692 | ; ==================================================================== | |
693 | ; Parameters | |
694 | ; -------------------------------------------------------------------- | |
5482d75f | 695 | ; Registers : temp3 drive # |
dd7aea8c L |
696 | ; |
697 | ; -------------------------------------------------------------------- | |
698 | ; Description: | |
699 | ; ==================================================================== | |
700 | ||
5482d75f | 701 | dsk_format_get: |
dd7aea8c L |
702 | |
703 | ; Get first sector (512 byte) of current drive into hostbuf. | |
704 | ||
5482d75f | 705 | push temp3 |
dd7aea8c L |
706 | ldi temp,0 |
707 | ldi temp2,0 ; | |
708 | rcall dsk_readhost_lba | |
709 | ||
dd7aea8c L |
710 | ; Test for variable format avrcpmhd. |
711 | ||
712 | rcall dsk_tst_avrcpmhd | |
5482d75f | 713 | brne dsk_imgt_done |
dd7aea8c L |
714 | |
715 | ; Test for YAZE formats. | |
716 | ||
717 | rcall dsk_tst_yaze | |
5482d75f | 718 | brne dsk_imgt_done |
dd7aea8c | 719 | |
b165699b L |
720 | ; Test for simhd format. |
721 | ||
722 | rcall dsk_tst_simhd | |
723 | ldiw z,dpbdat_simhd*2 | |
5482d75f | 724 | brne dsk_imgt_fixed |
b165699b | 725 | |
dd7aea8c L |
726 | ; Test for MyZ80 format. |
727 | ||
728 | rcall dsk_tst_myz80 | |
729 | ldiw z,dpbdat_myz80*2 | |
5482d75f | 730 | brne dsk_imgt_fixed |
dd7aea8c L |
731 | |
732 | ; No special image found. Use avrcpm. | |
733 | ||
734 | ldiw z,dpbdat_avrcpm*2 | |
735 | ||
5482d75f | 736 | dsk_imgt_fixed: |
dd7aea8c | 737 | rcall dpb_copy_p |
5482d75f L |
738 | ori temp,0xff |
739 | dsk_imgt_done: | |
740 | pop temp3 | |
741 | ret | |
dd7aea8c | 742 | |
5482d75f L |
743 | ; ==================================================================== |
744 | ; Function: Add CP/M image format data to partition table data | |
745 | ; ==================================================================== | |
746 | ; Parameters | |
747 | ; -------------------------------------------------------------------- | |
748 | ; Registers : temp3 drive # | |
749 | ; | |
750 | ; -------------------------------------------------------------------- | |
751 | ; Description: | |
752 | ; ==================================================================== | |
753 | ||
754 | dpb_imgdata_get: | |
755 | ||
756 | ; Test for known CP/M formats | |
757 | ||
758 | rcall dsk_format_get | |
759 | breq dpb_imgd_err ;no known format detected | |
760 | ||
761 | ; | |
dd7aea8c L |
762 | mov zl,temp3 |
763 | rcall dsk_getpartentry ;get partition entry | |
764 | ldiw y,tmpdpb | |
765 | ||
766 | ; std y+12,_0 ;Test: set check size to 0 | |
767 | ; std y+13,_0 | |
768 | ||
769 | ldd temp,y+0 | |
770 | andi temp,~dskType_MASK | |
771 | ldd temp2,z+PTAB_TYPE | |
772 | andi temp2,dskType_MASK | |
773 | or temp,temp2 | |
774 | std z+PTAB_TYPE,temp | |
775 | ldd temp,y+1 | |
776 | std z+PTAB_SPT,temp | |
777 | ldd temp,y+2 | |
778 | tst temp ;more then 256 sectors per track? | |
779 | brne dsk_imgprp_err ;todo: support 16 bit sector numbers | |
780 | ldd temp2,y+3 | |
781 | andi temp2,0x0f | |
782 | swap temp2 | |
783 | std z+PTAB_BSH,temp2 | |
784 | ||
785 | ori temp,255 | |
786 | ret | |
787 | ||
788 | dsk_imgprp_err: | |
789 | printnewline | |
790 | ldi temp,'A' | |
791 | add temp,temp3 | |
08716d4f | 792 | lcall uartputc |
dd7aea8c L |
793 | printstring ": Format not supported: Too much sectors per track! " |
794 | printnewline | |
795 | ||
5482d75f | 796 | dpb_imgd_err: |
dd7aea8c L |
797 | clr temp |
798 | ret | |
799 | ||
5482d75f L |
800 | ; ==================================================================== |
801 | ; Function: | |
802 | ; ==================================================================== | |
803 | ; Parameters | |
804 | ; -------------------------------------------------------------------- | |
805 | ; Registers : temp drive # | |
806 | ; | |
807 | ; return !0 if ok | |
808 | ; 0 on error | |
809 | ; -------------------------------------------------------------------- | |
810 | ; Description: Init CP/M data structures | |
29ce189c | 811 | ; |
5482d75f L |
812 | ; ----------------------------------------------------------------- |
813 | ; DPH: | XLT | | | |DIRBUF | DPB | CSV | ALV | | |
814 | ; ----------------------------------------------------------------- | |
815 | ;offset: 0 2 4 6 8 10 12 14 | |
816 | ; | |
817 | ; ------------------------------------------------------------- | |
818 | ; DPB: | SPT |BSH|BLM|EXM| DSM | DRM |AL0|AL1| CKS | OFF | | |
819 | ; ------------------------------------------------------------- | |
820 | ;offset: 0 5 7 11 13 | |
821 | ; ==================================================================== | |
29ce189c | 822 | |
5482d75f | 823 | dpb_biosdph_get: |
29ce189c L |
824 | mov temp3,temp ;save disk # |
825 | ||
5482d75f | 826 | rcall dsk_format_get |
dd7aea8c L |
827 | brne dpb_di_0 |
828 | rjmp dpb_di_err | |
29ce189c | 829 | |
dd7aea8c | 830 | dpb_di_0: |
29ce189c L |
831 | |
832 | ; get mem for DPH | |
29ce189c L |
833 | |
834 | ldi temp, low (16) | |
835 | ldi temp2,high(16) | |
5482d75f | 836 | rcall heap_get ;returns ptr to dph mem |
637689de L |
837 | brne dpb_di_1 |
838 | rjmp dpb_di_err ; | |
839 | dpb_di_1: | |
29ce189c | 840 | movw x,temp |
637689de | 841 | movw y,temp ;save dph pointer |
29ce189c L |
842 | ldi temp,0 |
843 | ldi temp2,0 | |
844 | rcall dram_writew_pp ;XLT | |
845 | adiw x,6 | |
846 | lds temp,biosdirbuf | |
847 | lds temp2,biosdirbuf+1 | |
848 | rcall dram_writew_pp ;DIRBUF | |
849 | ||
850 | ; get mem for DPB | |
29ce189c L |
851 | |
852 | ldi temp, low (15) | |
853 | ldi temp2,high(15) | |
854 | rcall heap_get | |
637689de | 855 | breq dpb_di_err_p1 |
29ce189c L |
856 | movw x,temp |
857 | ||
dd7aea8c | 858 | ldiw z,tmpdpb+1 ;skip sector offset byte |
637689de | 859 | dpb_dicpl: |
29ce189c L |
860 | ld temp,z+ |
861 | rcall dram_write_pp | |
dd7aea8c | 862 | cpi zl,low(tmpdpb + 16) |
637689de | 863 | brne dpb_dicpl |
29ce189c L |
864 | sbiw x,15 |
865 | movw temp,x | |
866 | movw x,y | |
867 | adiw x,10 | |
868 | rcall dram_writew_pp ;DPB | |
869 | ||
870 | ; get mem for dir check vector | |
871 | ||
dd7aea8c L |
872 | lds temp,tmpdpb+12 ;cks |
873 | lds temp2,tmpdpb+12+1 | |
29ce189c L |
874 | cp temp,_0 |
875 | cpc temp2,_0 | |
637689de | 876 | breq dpb_dicks0 |
29ce189c | 877 | rcall heap_get |
637689de L |
878 | breq dpb_di_err_p1 |
879 | dpb_dicks0: | |
29ce189c L |
880 | rcall dram_writew_pp ;CSV |
881 | ||
882 | ; get mem for alloc vector | |
883 | ||
dd7aea8c L |
884 | lds temp,tmpdpb+6 ;dsm |
885 | lds temp2,tmpdpb+6+1 | |
29ce189c L |
886 | subi temp, low (-8) |
887 | sbci temp2,high(-8) | |
888 | lsr temp2 | |
889 | ror temp | |
890 | lsr temp2 | |
891 | ror temp | |
892 | lsr temp2 | |
893 | ror temp ;(dsm+1+7)/8 | |
894 | rcall heap_get | |
637689de | 895 | breq dpb_di_err_p1 |
29ce189c L |
896 | rcall dram_writew_pp ;ALV |
897 | ||
898 | ; success, insert DPH into drvtbl | |
899 | ||
637689de L |
900 | mov temp,temp3 |
901 | rcall dpb_drvtbl_entry_p | |
29ce189c L |
902 | movw temp,y |
903 | rcall dram_writew_pp | |
dd7aea8c | 904 | |
29ce189c | 905 | ori temp,0xff ;return ok |
64219415 FZ |
906 | ret |
907 | ||
29ce189c L |
908 | ; error, free mem |
909 | ||
637689de | 910 | dpb_di_err_p1: |
29ce189c L |
911 | movw temp,y |
912 | rcall heap_release | |
637689de | 913 | dpb_di_err: |
29ce189c | 914 | eor temp,temp ;return 0 (+ Z-flag) |
b741422e | 915 | ret |
29ce189c | 916 | |
dd7aea8c L |
917 | ; ==================================================================== |
918 | ; Function: | |
919 | ; ==================================================================== | |
920 | ; Parameters | |
921 | ; -------------------------------------------------------------------- | |
922 | ; Registers : | |
923 | ; | |
924 | ; -------------------------------------------------------------------- | |
925 | ; Description: | |
926 | ; ==================================================================== | |
927 | dsk_setdrvparam: | |
928 | ldd temp2,z+PTAB_TYPE | |
929 | andi temp2,~dskType_MASK ;Lower nibble is image header size | |
930 | sts hdrsize,temp2 | |
931 | ldd temp2,z+PTAB_SPT | |
932 | sts cpmspt,temp2 | |
933 | ldd temp2,z+PTAB_BSH | |
934 | swap temp2 | |
935 | andi temp2,0x0f | |
936 | clr _tmp0 | |
937 | inc _tmp0 | |
938 | dsk_sdrvpl: | |
939 | lsl _tmp0 | |
940 | dec temp2 | |
941 | brne dsk_sdrvpl | |
942 | sts secpblk,_tmp0 | |
943 | ret | |
944 | ||
64219415 | 945 | |
b741422e | 946 | ; ==================================================================== |
64219415 | 947 | ; Function: Does a Disk interaction |
b741422e L |
948 | ; ==================================================================== |
949 | ; Parameters | |
950 | ; -------------------------------------------------------------------- | |
951 | ; Registers : none | |
952 | ; Variables : [r] seeksec Sector to read | |
953 | ; [r] seektrk Track to read | |
954 | ; -------------------------------------------------------------------- | |
955 | ; Description: | |
64219415 FZ |
956 | ; ==================================================================== |
957 | dskDoIt: | |
958 | .if DISK_DEBUG | |
959 | push temp | |
960 | sbrc temp,READ_FUNC | |
961 | rjmp dskdbgr | |
962 | sbrc temp,WRITE_FUNC | |
963 | rjmp dskdbgw | |
964 | rjmp dskdbge | |
965 | ||
966 | dskdbgr: | |
967 | printnewline | |
968 | printstring "Disk read: " | |
969 | rjmp dskdbg1 | |
970 | dskdbgw: | |
971 | printnewline | |
972 | printstring "Disk write: " | |
973 | dskdbg1: | |
974 | lds temp,seekdsk | |
975 | subi temp,-('A') | |
976 | rcall uartputc | |
977 | printstring ": track " | |
978 | lds temp2,seektrk+1 | |
979 | lds temp,seektrk | |
980 | rcall printhexw | |
981 | printstring ", sector " | |
982 | lds temp,seeksec | |
983 | rcall printhex | |
984 | printstring ", dma-addr " | |
985 | lds temp2,dmaadr+1 | |
986 | lds temp,dmaadr | |
987 | rcall printhexw | |
988 | pop temp | |
989 | push temp | |
990 | sbrs temp,WRITE_FUNC | |
991 | rjmp dskdbge | |
992 | printstring " wrtype " | |
993 | andi temp,3 | |
994 | rcall printhex | |
995 | dskdbge: | |
996 | pop temp | |
997 | .endif | |
998 | ;See what has to be done. | |
999 | sbrc temp,READ_FUNC | |
1000 | rjmp dsk_read | |
1001 | sbrc temp,WRITE_FUNC | |
1002 | rjmp dsk_write | |
1003 | sbrc temp,HOME_FUNC | |
1004 | rjmp dsk_home | |
1005 | sbrc temp,BOOT_FUNC | |
1006 | rjmp dsk_boot | |
1007 | ||
1008 | printstring "DISK I/O: Invalid Function code: " | |
08716d4f | 1009 | lcall printhex |
64219415 FZ |
1010 | rjmp haltinv |
1011 | ||
1012 | dsk_boot: | |
dd7aea8c L |
1013 | sts ndisks,_0 ;no active partitions |
1014 | dsk_inval_hostbuf: | |
1015 | cbi flags,hostact ;host buffer inactive | |
1016 | sts unacnt,_0 ;clear unalloc count | |
64219415 FZ |
1017 | ret |
1018 | ||
1019 | dsk_home: | |
dd7aea8c L |
1020 | sbis flags,hostwrt ;check for pending write |
1021 | cbi flags,hostact ;clear host active flag | |
64219415 | 1022 | ret |
64219415 | 1023 | |
b741422e L |
1024 | |
1025 | ||
1026 | ; ==================================================================== | |
64219415 | 1027 | ; Function: Does a Disk read operation |
b741422e L |
1028 | ; ==================================================================== |
1029 | ; Parameters | |
1030 | ; -------------------------------------------------------------------- | |
eb85ce65 | 1031 | ; Registers : in: temp |
b741422e | 1032 | ; Variables : [r] seekdsk Number of Disk to Read |
1eeb9cbe | 1033 | ; [r] seeksec Sector to read |
b741422e L |
1034 | ; [r] seektrk Track to read |
1035 | ; -------------------------------------------------------------------- | |
1036 | ; Description: | |
64219415 FZ |
1037 | ; ==================================================================== |
1038 | dsk_read: | |
637689de L |
1039 | sts erflag,_0 |
1040 | sbi flags,readop ; Set read operation flag | |
29ce189c | 1041 | |
eb85ce65 | 1042 | ;RAM disk? |
dd7aea8c | 1043 | lds zl,seekdsk |
eb85ce65 | 1044 | #if RAMDISKCNT |
dd7aea8c | 1045 | cpi zl,RAMDISKNR |
eb85ce65 L |
1046 | brlt PC+2 |
1047 | rjmp rdsk_read | |
1048 | #endif | |
b741422e | 1049 | rcall dsk_getpartentry ; Get Paritiontableentry |
637689de L |
1050 | ld temp,z ; Get Partitiontype |
1051 | andi temp,dskType_MASK | |
b741422e L |
1052 | |
1053 | ; Isn't it a Disk ? | |
1eeb9cbe | 1054 | cpi temp,dskType_None |
b741422e L |
1055 | brne PC+2 |
1056 | rjmp dsk_read_err | |
dd7aea8c | 1057 | |
b741422e | 1058 | ; It must be a FAT16-Imagefile or CP/M Partition. |
dd7aea8c L |
1059 | |
1060 | rcall dsk_setdrvparam ;todo: do this only if needed (disk change) | |
1061 | ||
637689de L |
1062 | sts unacnt,_0 |
1063 | sbi flags,rsflag ;must read data | |
1064 | ldi temp,WRUAL ;write type | |
1065 | sts wrtype,temp ;treat as unalloc | |
dd7aea8c | 1066 | |
637689de | 1067 | rjmp dsk_rwoper ;to perform the read |
64219415 | 1068 | |
b741422e L |
1069 | dsk_read_err: |
1070 | ret | |
64219415 | 1071 | |
b741422e | 1072 | ; ==================================================================== |
64219415 | 1073 | ; Function: Does a Disk write operation |
b741422e L |
1074 | ; ==================================================================== |
1075 | ; Parameters | |
1076 | ; -------------------------------------------------------------------- | |
eb85ce65 | 1077 | ; Registers : in: temp Write type |
1eeb9cbe L |
1078 | ; Variables : [r] seekdsk Number of Disk to Read |
1079 | ; [r] seeksec Sector to read | |
1080 | ; [r] seektrk Track to read | |
b741422e L |
1081 | ; -------------------------------------------------------------------- |
1082 | ; Description: | |
64219415 FZ |
1083 | ; ==================================================================== |
1084 | dsk_write: | |
1085 | ;write the selected sector | |
637689de L |
1086 | sts erflag,_0 |
1087 | cbi flags,readop ; not a read operation | |
eb85ce65 | 1088 | ;RAM disk? |
dd7aea8c | 1089 | lds zl,seekdsk |
eb85ce65 | 1090 | #if RAMDISKCNT |
dd7aea8c | 1091 | cpi zl,RAMDISKNR |
eb85ce65 L |
1092 | brlt PC+2 |
1093 | rjmp rdsk_write | |
1094 | #endif | |
b741422e | 1095 | rcall dsk_getpartentry ; Get Paritiontableentry |
dd7aea8c | 1096 | ld temp2,z ; Get Partitiontype |
5482d75f | 1097 | andi temp2,dskType_MASK |
b741422e L |
1098 | |
1099 | ; Isn't it a Disk ? | |
eb85ce65 | 1100 | cpi temp2,dskType_None |
b741422e L |
1101 | brne PC+2 |
1102 | rjmp dsk_write_err | |
1103 | ||
1eeb9cbe | 1104 | |
b741422e | 1105 | ; It must be a FAT16-Imagefile or CP/M Partition. |
64219415 | 1106 | |
dd7aea8c L |
1107 | rcall dsk_setdrvparam ;todo: do this only if needed (disk change) |
1108 | ||
64219415 | 1109 | andi temp,WRTMSK |
dd7aea8c | 1110 | sts wrtype,temp ;save write type |
64219415 | 1111 | |
dd7aea8c L |
1112 | cpi temp,WRUAL ;write unallocated? |
1113 | brne dsk_chkuna ;check for unalloc | |
64219415 FZ |
1114 | |
1115 | ; write to unallocated, set parameters | |
dd7aea8c L |
1116 | lds temp,secpblk ;next unalloc recs (blocksize/128) |
1117 | sts unacnt,temp | |
1118 | lds temp,seekdsk ;disk to seek | |
1119 | sts unadsk,temp ;unadsk = sekdsk | |
1120 | lds temp,seektrk | |
1121 | sts unatrk,temp ;unatrk = sectrk | |
1122 | lds temp,seektrk+1 | |
1123 | sts unatrk+1,temp ;unatrk = sectrk | |
1124 | lds temp,seeksec | |
1125 | sts unasec,temp ;unasec = seksec | |
64219415 FZ |
1126 | ; |
1127 | dsk_chkuna: | |
1128 | ;check for write to unallocated sector | |
dd7aea8c L |
1129 | lds temp,unacnt ;any unalloc remain? |
1130 | tst temp | |
1131 | breq dsk_alloc ;skip if not | |
64219415 FZ |
1132 | |
1133 | ; more unallocated records remain | |
dd7aea8c L |
1134 | dec temp ;unacnt = unacnt-1 |
1135 | sts unacnt,temp | |
1136 | lds temp,seekdsk ;same disk? | |
1137 | lds temp2,unadsk | |
1138 | cp temp,temp2 ;seekdsk = unadsk? | |
1139 | brne dsk_alloc ;skip if not | |
64219415 FZ |
1140 | |
1141 | ; disks are the same | |
dd7aea8c L |
1142 | lds temp,unatrk |
1143 | lds temp2,unatrk+1 | |
1144 | lds temp3,seektrk | |
1145 | lds temp4,seektrk+1 | |
1146 | cp temp,temp3 ;seektrk = unatrk? | |
1147 | cpc temp2,temp4 | |
1148 | brne dsk_alloc ;skip if not | |
64219415 FZ |
1149 | |
1150 | ; tracks are the same | |
dd7aea8c L |
1151 | lds temp,seeksec ;same sector? |
1152 | lds temp2,unasec | |
1153 | cp temp,temp2 ;seeksec = unasec? | |
1154 | brne dsk_alloc ;skip if not | |
64219415 FZ |
1155 | |
1156 | ; match, move to next sector for future ref | |
dd7aea8c L |
1157 | inc temp2 ;unasec = unasec+1 |
1158 | sts unasec,temp2 | |
1159 | lds _tmp0,cpmspt | |
1160 | cp temp2,_tmp0 ;end of track? (count CP/M sectors) | |
1161 | brlo dsk_noovf ;skip if no overflow | |
64219415 FZ |
1162 | |
1163 | ; overflow to next track | |
dd7aea8c L |
1164 | sts unasec,_0 ;unasec = 0 |
1165 | lds temp,unatrk | |
1166 | lds temp2,unatrk+1 | |
64219415 FZ |
1167 | subi temp, low(-1) ;unatrk = unatrk+1 |
1168 | sbci temp2,high(-1) | |
dd7aea8c L |
1169 | sts unatrk,temp |
1170 | sts unatrk+1,temp2 | |
64219415 FZ |
1171 | ; |
1172 | dsk_noovf: | |
dd7aea8c L |
1173 | cbi flags,rsflag ;rsflag = 0 |
1174 | rjmp dsk_rwoper ;to perform the write | |
64219415 FZ |
1175 | ; |
1176 | dsk_alloc: | |
1177 | ;not an unallocated record, requires pre-read | |
dd7aea8c L |
1178 | sts unacnt,_0 ;unacnt = 0 |
1179 | sbi flags,rsflag ;rsflag = 1 | |
b741422e L |
1180 | rjmp dsk_rwoper |
1181 | ||
1182 | dsk_write_err: | |
1183 | ret | |
1184 | ||
1185 | ; ==================================================================== | |
64219415 | 1186 | ; Function: Does a Disk read/write operation |
b741422e L |
1187 | ; ==================================================================== |
1188 | ; Parameters | |
1189 | ; -------------------------------------------------------------------- | |
1190 | ; Registers : none | |
1191 | ; Variables : [r] seekdsk Number of Disk to Read | |
1192 | ; [r] seeksec Sector to read | |
1193 | ; [r] seektrk Track to read | |
1194 | ; -------------------------------------------------------------------- | |
1195 | ; Description: | |
1196 | ; ==================================================================== | |
1197 | dsk_rwoper: | |
64219415 FZ |
1198 | ;enter here to perform the read/write |
1199 | .if DISK_DEBUG | |
1200 | printstring ", flags: " | |
dd7aea8c | 1201 | in temp,flags |
64219415 FZ |
1202 | rcall printhex |
1203 | .endif | |
64219415 FZ |
1204 | ;Convert track/sector to an LBA address (in 128byte blocks) |
1205 | ||
dd7aea8c L |
1206 | lds xl,seeksec ; |
1207 | ldi xh,0 ; | |
1208 | ldi yl,0 ; | |
1209 | lds temp,hdrsize ;add image header size | |
1210 | add xl,temp ; | |
1211 | adc xh,_0 ; | |
1212 | lds temp3,seektrk ; | |
1213 | lds temp4,seektrk+1 ; | |
1214 | lds temp,cpmspt ; | |
1215 | mul temp3,temp ; | |
1216 | add xl,r0 ; | |
1217 | adc xh,r1 ; | |
1218 | mul temp4,temp ; | |
1219 | add xh,r0 ;yl:xh:xl := sec + trk * SectorsPerTrack | |
1220 | adc yl,r1 ; | |
1221 | ||
1222 | mov temp,xl | |
1223 | andi temp,SECMSK ;mask buffer number | |
1224 | push temp ;save for later | |
64219415 FZ |
1225 | |
1226 | ;Convert from CP/M LBA blocks to host LBA blocks | |
dd7aea8c | 1227 | ldi temp,SECSHF |
64219415 | 1228 | dsk_sh1: |
dd7aea8c L |
1229 | lsr yl |
1230 | ror xh | |
1231 | ror xl | |
1232 | dec temp | |
64219415 | 1233 | brne dsk_sh1 |
5482d75f L |
1234 | ;todo: yl should be 0 here. |
1235 | ;xh:xl = host block to seek | |
1236 | movw temp,x | |
1237 | lds temp3,seekdsk | |
1238 | rcall dsk_rw_hostbuf | |
64219415 FZ |
1239 | |
1240 | ;copy data to or from buffer | |
1241 | ldiw z,hostbuf | |
dd7aea8c L |
1242 | ldi temp,128 |
1243 | pop temp2 ;get buffer number (which part of hostbuf) | |
1244 | mul temp2,temp | |
1245 | add zl,r0 ;offset in hostbuf | |
1246 | adc zh,r1 | |
64219415 FZ |
1247 | |
1248 | .if DISK_DEBUG > 2 | |
5482d75f | 1249 | movw temp,r0 |
64219415 | 1250 | printstring "; host buf adr: " |
64219415 FZ |
1251 | rcall printhexw |
1252 | .endif | |
1253 | ||
dd7aea8c L |
1254 | lds xl,dmaadr |
1255 | lds xh,dmaadr+1 | |
1256 | ldi temp3,128 ;length of move | |
64219415 | 1257 | sbic flags,readop ;which way? |
dd7aea8c | 1258 | rjmp dsk_rmove ;skip if read |
64219415 FZ |
1259 | |
1260 | ; mark write operation | |
dd7aea8c | 1261 | sbi flags,hostwrt ;hostwrt = 1 |
64219415 FZ |
1262 | dsk_wmove: |
1263 | mem_read | |
dd7aea8c | 1264 | st z+,temp |
64219415 | 1265 | adiw xl,1 |
dd7aea8c | 1266 | dec temp3 |
64219415 FZ |
1267 | brne dsk_wmove |
1268 | rjmp dsk_rwmfin | |
1269 | ||
1270 | dsk_rmove: | |
dd7aea8c | 1271 | ld temp,z+ |
64219415 FZ |
1272 | mem_write |
1273 | adiw xl,1 | |
dd7aea8c | 1274 | dec temp3 |
64219415 FZ |
1275 | brne dsk_rmove |
1276 | dsk_rwmfin: | |
1277 | ; data has been moved to/from host buffer | |
dd7aea8c L |
1278 | lds temp,wrtype ;write type |
1279 | cpi temp,WRDIR ;to directory? | |
64219415 | 1280 | breq dsk_wdir |
dd7aea8c | 1281 | ret ;no further processing |
64219415 FZ |
1282 | dsk_wdir: |
1283 | ; clear host buffer for directory write | |
dd7aea8c L |
1284 | lds temp,erflag |
1285 | tst temp ;errors? | |
64219415 | 1286 | breq dsk_wdir1 |
dd7aea8c | 1287 | ret ;skip if so |
64219415 FZ |
1288 | dsk_wdir1: |
1289 | rcall dsk_writehost ;clear host buff | |
dd7aea8c | 1290 | cbi flags,hostwrt ;buffer written |
b741422e L |
1291 | ret |
1292 | ||
dd7aea8c L |
1293 | ; ==================================================================== |
1294 | ; Function: | |
1295 | ; ==================================================================== | |
1296 | ; Parameters | |
1297 | ; -------------------------------------------------------------------- | |
1298 | ; Registers : temp2:temp block to read (lba) | |
1299 | ; temp3 disk # | |
1300 | ; | |
1301 | ; -------------------------------------------------------------------- | |
1302 | ; Description: | |
1303 | ; ==================================================================== | |
1304 | dsk_readhost_lba: | |
5482d75f | 1305 | #if 0 |
dd7aea8c L |
1306 | printnewline |
1307 | printstring "readhst lba" | |
1308 | #endif | |
5482d75f L |
1309 | sbi flags,rsflag ;must read data |
1310 | rcall dsk_rw_hostbuf | |
1311 | lds temp,erflag ;returns 0, if ok | |
1312 | tst temp | |
1313 | ret | |
dd7aea8c | 1314 | |
5482d75f L |
1315 | ; ==================================================================== |
1316 | ; Function: Get physical disk sector in hostbuf. | |
1317 | ; ==================================================================== | |
1318 | ; Parameters | |
1319 | ; -------------------------------------------------------------------- | |
1320 | ; Registers : temp2:temp host block to read/write (lba) | |
1321 | ; temp3 disk # | |
1322 | ; | |
1323 | ; -------------------------------------------------------------------- | |
1324 | ; Description: | |
1325 | ; ==================================================================== | |
1326 | dsk_rw_hostbuf: | |
1327 | ;xh:xl = host block to seek | |
1328 | sts erflag,_0 ;no errors (yet) | |
1329 | ||
1330 | ; active host sector? | |
1331 | in _tmp0,flags ;host active flag | |
1332 | sbi flags,hostact ;always becomes 1 | |
1333 | sbrs _tmp0,hostact ;was it already? | |
1334 | rjmp dsk_filhst ;fill host if not | |
1335 | ||
1336 | ; host buffer active, same as seek buffer? | |
1337 | lds _tmp0,hostdsk ;same disk? | |
1338 | cp temp3,_tmp0 ;seekdsk = hostdsk? | |
1339 | brne dsk_nomatch | |
1340 | ||
1341 | ; same disk, same block? | |
1342 | lds _tmp0,hostlba | |
1343 | lds _tmp1,hostlba+1 | |
1344 | cp temp,_tmp0 | |
1345 | cpc temp2,_tmp1 | |
1346 | breq dsk_match | |
1347 | ||
1348 | dsk_nomatch: | |
1349 | ;proper disk, but not correct sector | |
1350 | sbis flags,hostwrt ;host written? | |
1351 | rjmp dsk_filhst | |
1352 | push temp3 | |
1353 | push temp2 | |
1354 | push temp | |
1355 | rcall dsk_writehost ;clear host buff | |
1356 | pop temp | |
1357 | pop temp2 | |
1358 | pop temp3 | |
1359 | ||
1360 | dsk_filhst: | |
1361 | ;may have to fill the host buffer | |
1362 | sts hostlba,temp | |
1363 | sts hostlba+1,temp2 | |
1364 | sts hostdsk,temp3 | |
1365 | ||
1366 | sbic flags,rsflag ;need to read? | |
1367 | rcall dsk_readhost ;yes, if 1 | |
1368 | cbi flags,hostwrt ;no pending write | |
1369 | ||
1370 | dsk_match: | |
1371 | ret | |
dd7aea8c | 1372 | |
b741422e | 1373 | ; ==================================================================== |
64219415 | 1374 | ; Function: Does a Disk write operation |
b741422e L |
1375 | ; ==================================================================== |
1376 | ; Parameters | |
1377 | ; -------------------------------------------------------------------- | |
1378 | ; Registers : none | |
1379 | ; Variables : [r] seekdsk Number of Disk to Read | |
1380 | ; [r] seeksec Sector to read | |
1381 | ; [r] seektrk Track to read | |
1382 | ; -------------------------------------------------------------------- | |
1383 | ; Description: | |
1384 | ; ==================================================================== | |
1385 | dsk_writehost: | |
dd7aea8c | 1386 | lds zl,hostdsk |
637689de L |
1387 | rcall dsk_getpartentry |
1388 | ld temp,z | |
1389 | andi temp,dskType_MASK | |
b741422e L |
1390 | |
1391 | #if FAT16_SUPPORT | |
64219415 | 1392 | ; Is it a FAT16 Diskimage ? |
637689de | 1393 | cpi temp,dskType_FAT |
b741422e L |
1394 | brne PC+2 |
1395 | rjmp fat_writehost | |
1396 | #endif | |
1397 | ||
64219415 | 1398 | ; Is it a CP/M Partition ? |
637689de | 1399 | cpi temp,dskType_CPM |
b741422e L |
1400 | brne PC+2 |
1401 | rjmp cpm_writehost | |
1402 | ; Disktype not supported -> Return | |
1403 | ret | |
1404 | ||
1405 | ; ==================================================================== | |
64219415 | 1406 | ; Function: Does a Disk read operation |
b741422e L |
1407 | ; ==================================================================== |
1408 | ; Parameters | |
1409 | ; -------------------------------------------------------------------- | |
1410 | ; Registers : none | |
1411 | ; Variables : [r] seekdsk Number of Disk to Read | |
1412 | ; [r] seeksec Sector to read | |
1413 | ; [r] seektrk Track to read | |
1414 | ; -------------------------------------------------------------------- | |
1415 | ; Description: | |
1416 | ; ==================================================================== | |
1417 | dsk_readhost: | |
dd7aea8c L |
1418 | |
1419 | #if 0 | |
1420 | printnewline | |
1421 | printstring "readhost" | |
1422 | ldiw z,biosdrvtbl | |
1423 | rcall dbg_hexdump_line | |
1424 | adiw z,16 | |
1425 | rcall dbg_hexdump_line | |
1426 | #endif | |
1427 | ||
1428 | lds zl,hostdsk | |
b741422e L |
1429 | rcall dsk_getpartentry |
1430 | ld temp,z | |
637689de | 1431 | andi temp,dskType_MASK |
b741422e L |
1432 | |
1433 | #if FAT16_SUPPORT | |
64219415 | 1434 | ; Is it a FAT16 Diskimage ? |
637689de | 1435 | cpi temp,dskType_FAT |
b741422e L |
1436 | brne PC+2 |
1437 | rjmp fat_readhost | |
1438 | #endif | |
1439 | ||
64219415 | 1440 | ; Is it a CP/M Partition ? |
637689de | 1441 | cpi temp,dskType_CPM |
b741422e L |
1442 | brne PC+2 |
1443 | rjmp cpm_readhost | |
1444 | ; Disktype not supported -> Return | |
1445 | ret | |
1446 | ||
5482d75f L |
1447 | |
1448 | ; vim:set ts=8 noet nowrap | |
1449 |