]>
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 L |
186 | add zl,_tmp0 |
187 | add 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 | ||
dd7aea8c L |
367 | ; DPBs for varios fixed formats |
368 | ; dpb data starts at 2. byte | |
369 | ||
370 | dpbdat_avrcpm: ;(dpb243) | |
371 | .db 0x00,0x1A ;sector offset, low(spt) | |
372 | .db 0x00,0x03 ;high (spt), block shift | |
373 | .db 0x07,0x00 ;bock mask, extent mask | |
374 | .db 0xF2,0x00 ;disk size - 1, | |
375 | .db 0x3F,0x00 ;dir max | |
376 | .db 0xC0,0x00 ;alloc0, alloc1 | |
377 | .db 0x10,0x00 ;chk size | |
378 | .db 0x02,0x00 ;offset | |
379 | ||
dd7aea8c L |
380 | dpbdat_myz80: ; |
381 | .db 0x02,0x80 ;sector offset, low(spt) | |
382 | .db 0x00,0x05 ;high (spt), block shift | |
383 | .db 0x1F,0x01 ;bock mask, extent mask | |
384 | .db 0xFF,0x07 ;disk size - 1, | |
385 | .db 0xFF,0x03 ;dir max | |
386 | .db 0xFF,0x00 ;alloc0, alloc1 | |
387 | .db 0x00,0x01 ;chk size | |
388 | .db 0x00,0x00 ;offset | |
29ce189c | 389 | |
b165699b L |
390 | dpbdat_simhd: ; |
391 | .db 0x00,0x20 ;sector offset, low(spt) | |
392 | .db 0x00,0x05 ;high (spt), block shift | |
393 | .db 0x1F,0x01 ;bock mask, extent mask | |
394 | .db 0xF9,0x07 ;disk size - 1, | |
395 | .db 0xFF,0x03 ;dir max | |
396 | .db 0xFF,0x00 ;alloc0, alloc1 | |
397 | .db 0x00,0x01 ;chk size | |
398 | .db 0x06,0x00 ;offset | |
399 | ||
29ce189c L |
400 | #if 0 |
401 | ;rd1016 | |
402 | .db 0x20,0x00 ;spt | |
403 | .db 0x04,0x0F ;block shift, bock mask | |
404 | .db 0x00,0xFB ;extent mask, low(disk size -1), | |
405 | .db 0x01,0xBF ;high(disk size -1), low(dir max) | |
406 | .db 0x00,0xE0 ;high(dir max), alloc0 | |
407 | .db 0x00,0x30 ;alloc1, low(chk size) | |
408 | .db 0x00,0x02 ;high(chk size), low(offset) | |
409 | .db 0x00,0x00 ;high(offset), fill | |
410 | ;rd9192s | |
411 | .db 0x20,0x00 ;spt | |
412 | .db 0x05,0x1F ;block shift, bock mask | |
413 | .db 0x01,0xFD ;extent mask, low(disk size -1), | |
414 | .db 0x07,0xFF ;high(disk size -1), low(dir max) | |
415 | .db 0x01,0xF0 ;high(dir max), alloc0 | |
416 | .db 0x00,0x80 ;alloc1, low(chk size) | |
417 | .db 0x00,0x02 ;high(chk size), low(offset) | |
418 | .db 0x00,0x00 ;high(offset), fill | |
419 | #endif | |
420 | ||
dd7aea8c | 421 | |
5482d75f | 422 | ; Copy the dpb data from flash memory, pointed to by Z, to temp ram. |
dd7aea8c L |
423 | |
424 | dpb_copy_p: | |
29ce189c L |
425 | push yh |
426 | push yl | |
29ce189c | 427 | ldi temp2,16 |
29ce189c | 428 | ldiw y,tmpdpb |
dd7aea8c | 429 | cpydpb_pl: |
29ce189c L |
430 | lpm temp,z+ |
431 | st y+,temp | |
dd7aea8c L |
432 | dec temp2 |
433 | brne cpydpb_pl | |
29ce189c L |
434 | pop yl |
435 | pop yh | |
64219415 | 436 | ret |
dd7aea8c L |
437 | |
438 | ; Copy the dpb data, pointed to by Z to temp ram. | |
439 | ||
440 | dpb_copy: | |
441 | st y+,temp | |
442 | ldi temp2,15 | |
443 | cpydpb_l: | |
444 | ld temp,z+ | |
445 | st y+,temp | |
446 | dec temp2 | |
447 | brne cpydpb_l | |
448 | ret | |
449 | ||
450 | ||
451 | ; String compare (z, y), one z-string in flash. | |
452 | ||
453 | strcmp_p: | |
454 | lpm _tmp0,z+ | |
455 | tst _tmp0 | |
456 | breq strcmp_pex | |
457 | ||
458 | ld temp, y+ | |
459 | lpm _tmp0, z+ | |
460 | sub temp,_tmp0 | |
461 | brne strcmp_pex | |
462 | tst _tmp0 | |
463 | brne strcmp_p | |
464 | strcmp_pex: | |
465 | ret | |
466 | ||
467 | ; String compare (x, y, temp2). Max temp2 bytes are compared. | |
468 | ||
469 | strncmp_p: | |
470 | subi temp2,1 | |
471 | brcs strncmp_peq | |
472 | ld temp,y+ | |
473 | lpm _tmp0, z+ | |
474 | sub temp,_tmp0 | |
475 | brne strncmp_pex | |
476 | tst _tmp0 | |
477 | brne strncmp_p | |
478 | strncmp_peq: | |
479 | sub temp,temp | |
480 | strncmp_pex: | |
481 | ret | |
482 | ||
637689de L |
483 | ; ==================================================================== |
484 | ; Function: get drive table entry pointer for drive # in temp | |
485 | ; ==================================================================== | |
486 | ; Parameters | |
487 | ; -------------------------------------------------------------------- | |
488 | ; Registers : | |
489 | ; Variables : | |
490 | ; | |
491 | ; -------------------------------------------------------------------- | |
492 | ; Description: | |
493 | ; ==================================================================== | |
494 | ||
495 | dpb_drvtbl_entry_p: | |
496 | ||
497 | ldsw x,biosdrvtbl | |
498 | lsl temp ;drive # | |
499 | add xl,temp | |
500 | adc xh,_0 | |
501 | ret | |
502 | ||
503 | ||
504 | ; ==================================================================== | |
505 | ; Function: get drive table entry for drive # in temp | |
506 | ; ==================================================================== | |
507 | ; Parameters | |
508 | ; -------------------------------------------------------------------- | |
509 | ; Registers : | |
510 | ; Variables : | |
511 | ; | |
512 | ; -------------------------------------------------------------------- | |
513 | ; Description: | |
514 | ; ==================================================================== | |
515 | ||
516 | dpb_drvtbl_entry_get: | |
517 | ||
518 | rcall dpb_drvtbl_entry_p | |
519 | ljmp dram_readw_pp | |
520 | ||
521 | ||
29ce189c | 522 | ; ==================================================================== |
dd7aea8c | 523 | ; Function: Clear drive table (entries 0 to 7) |
29ce189c L |
524 | ; ==================================================================== |
525 | ; Parameters | |
526 | ; -------------------------------------------------------------------- | |
527 | ; Registers : | |
528 | ; Variables : | |
529 | ; | |
530 | ; -------------------------------------------------------------------- | |
531 | ; Description: | |
532 | ; ==================================================================== | |
64219415 | 533 | |
dd7aea8c | 534 | ; |
29ce189c | 535 | |
5482d75f | 536 | dpb_drvtblclear: |
29ce189c | 537 | ldsw x,biosdrvtbl |
5482d75f L |
538 | sbiw x,0 |
539 | breq dpb_drvi_ex | |
540 | ||
541 | dpb_drvi_1: | |
dd7aea8c | 542 | ldi temp3,8 |
5482d75f | 543 | dpb_drvi_lp: |
29ce189c L |
544 | ldi temp,0 |
545 | ldi temp2,0 | |
546 | rcall dram_writew_pp | |
547 | dec temp3 | |
5482d75f | 548 | brne dpb_drvi_lp |
29ce189c L |
549 | |
550 | lds temp,biosenddat | |
551 | lds temp2,biosenddat+1 | |
5482d75f L |
552 | cp temp,_0 |
553 | cpc temp2,_0 | |
554 | breq dpb_drvi_ex | |
555 | ||
29ce189c | 556 | rcall heap_init |
5482d75f | 557 | dpb_drvi_ex: |
29ce189c | 558 | clr temp |
64219415 FZ |
559 | ret |
560 | ||
dd7aea8c | 561 | ; ==================================================================== |
5482d75f | 562 | ; Function: Test disk format: avrcpmhd |
dd7aea8c L |
563 | ; ==================================================================== |
564 | ; Parameters | |
565 | ; -------------------------------------------------------------------- | |
566 | ; Registers : temp drive # | |
567 | ; | |
568 | ; -------------------------------------------------------------------- | |
5482d75f | 569 | ; Description: Not implemented yet. |
dd7aea8c L |
570 | ; ==================================================================== |
571 | ||
572 | dsk_tst_avrcpmhd: | |
5482d75f | 573 | clr temp ; Test, return 'not found' for now. |
dd7aea8c L |
574 | ret |
575 | ||
576 | ||
577 | ; ==================================================================== | |
578 | ; Function: Test disk format: YAZE | |
579 | ; ==================================================================== | |
580 | ; Parameters | |
581 | ; -------------------------------------------------------------------- | |
582 | ; Registers : temp drive # | |
583 | ; | |
584 | ; -------------------------------------------------------------------- | |
585 | ; Description: From the YAZE Doc: | |
586 | ; | |
587 | ; The new disk header occupies the first 128 BYTES of the file and has the | |
588 | ; new format: | |
589 | ; | |
590 | ; 0 - 9 <CPM_Disk> | |
591 | ; 10 - 15 a null-terminated ascii comment (may be empty) | |
592 | ; new 16 version (0 = yaze-1.06/1.10, 1 = yaze-ag-2.xx) | |
593 | ; 17 - 31 a null-terminated ascii comment (may be empty) | |
594 | ; 32 - 33 sectors per track | |
595 | ; 34 block shift factor | |
596 | ; 35 block mask | |
597 | ; 36 extent mask | |
598 | ; 37 - 38 disk size max | |
599 | ; 39 - 40 directory max | |
600 | ; 41 al0 | |
601 | ; 42 al1 | |
602 | ; 43 - 44 check size (always zero) | |
603 | ; 45 - 46 track offset | |
604 | ; new 47 psh (used if version=1 and CP/M 3.1 is running) | |
605 | ; new 48 phm ( " " " " " " " " " ) | |
606 | ; 49 - 127 unused (zeros) | |
607 | ; ==================================================================== | |
608 | ||
609 | ||
610 | pstrn_YAZE: | |
611 | .db 10,"<CPM_Disk>",0 | |
612 | ||
613 | ||
614 | dsk_tst_yaze: | |
615 | ||
616 | ldiw y,hostbuf | |
617 | ldiw z,pstrn_YAZE*2 | |
618 | lpm temp2,z+ ; get length | |
619 | rcall strncmp_p | |
620 | brne dsk_tyze_not | |
621 | ||
622 | ldiw z,hostbuf+32 | |
623 | ldiw y,tmpdpb | |
624 | ldi temp,1 ;1 sector header size | |
625 | rcall dpb_copy | |
626 | ||
5482d75f | 627 | ori temp,0xff |
dd7aea8c L |
628 | ret |
629 | ||
630 | dsk_tyze_not: | |
5482d75f | 631 | clr temp ;Not a YAZE disk image. |
dd7aea8c | 632 | ret |
29ce189c | 633 | |
dd7aea8c L |
634 | ; ==================================================================== |
635 | ; Function: Test disk format: MyZ80 | |
636 | ; ==================================================================== | |
637 | ; Parameters | |
638 | ; -------------------------------------------------------------------- | |
639 | ; Registers : temp drive # | |
640 | ; | |
641 | ; -------------------------------------------------------------------- | |
642 | ; Description: Test, if first 2 Sectors are filled with 0xE5, | |
b165699b | 643 | ; and Size = 8192KB + 256Bytes. |
dd7aea8c L |
644 | ; ==================================================================== |
645 | dsk_tst_myz80: | |
646 | ||
647 | mov zl,temp3 | |
648 | rcall dsk_getpartentry ;get partition entry | |
649 | ldd temp,z+PTAB_SIZE | |
b165699b L |
650 | ldd temp2,z+PTAB_SIZE+1 ;check, if size is 16385 phys. sectors |
651 | cpi temp,low(16385) | |
652 | ldi temp,high(16385) | |
dd7aea8c L |
653 | cpc temp2,temp |
654 | brne dsk_tmyz80_not ;wrong size | |
655 | ||
656 | ldiw z,hostbuf | |
657 | ldi temp2,0 | |
658 | ||
659 | dsk_tmyz80_loop: | |
660 | ld temp,z+ | |
661 | cpi temp,0xE5 | |
662 | brne dsk_tmyz80_not | |
663 | dec temp2 | |
664 | brne dsk_tmyz80_loop | |
665 | ||
5482d75f | 666 | ori temp,0xff |
dd7aea8c L |
667 | ret |
668 | ||
669 | dsk_tmyz80_not: | |
5482d75f | 670 | clr temp ;Not a MyZ80 hard disk image. |
dd7aea8c L |
671 | ret |
672 | ||
b165699b L |
673 | ; ==================================================================== |
674 | ; Function: Test disk format: simhd, simh altair 8800 hard disk format | |
675 | ; ==================================================================== | |
676 | ; Parameters | |
677 | ; -------------------------------------------------------------------- | |
678 | ; Registers : temp drive # | |
679 | ; | |
680 | ; -------------------------------------------------------------------- | |
681 | ; Description: Test, if first 6 tracks are filled with 0xE5, | |
682 | ; and Size = 8192 KB. | |
683 | ; Actually, only the first phys. sector is tested, since | |
684 | ; the other 47 sectors are not in memory at this time. | |
685 | ; ==================================================================== | |
686 | dsk_tst_simhd: | |
687 | ||
688 | mov zl,temp3 | |
689 | rcall dsk_getpartentry ;get partition entry | |
690 | ldd temp,z+PTAB_SIZE | |
691 | ldd temp2,z+PTAB_SIZE+1 ;check, if size is 16384 phys. sectors | |
692 | cpi temp,low(16384) | |
693 | ldi temp,high(16384) | |
694 | cpc temp2,temp | |
695 | brne dsk_tsimhd_not ;wrong size | |
696 | ||
697 | ldiw z,hostbuf | |
698 | ldi temp2,high(512) | |
699 | clr _tmp0 ;low(512) | |
700 | ||
701 | dsk_tsimhd_loop: | |
702 | ld temp,z+ | |
703 | cpi temp,0xE5 | |
704 | brne dsk_tsimhd_not | |
705 | dec _tmp0 | |
706 | brne dsk_tsimhd_loop | |
707 | dec temp2 | |
708 | brne dsk_tsimhd_loop | |
709 | ||
5482d75f | 710 | ori temp,0xff |
b165699b L |
711 | ret |
712 | ||
713 | dsk_tsimhd_not: | |
5482d75f | 714 | clr temp ;Not a simhd hard disk image. |
b165699b L |
715 | ret |
716 | ||
dd7aea8c L |
717 | ; ==================================================================== |
718 | ; Function: | |
719 | ; ==================================================================== | |
720 | ; Parameters | |
721 | ; -------------------------------------------------------------------- | |
5482d75f | 722 | ; Registers : temp3 drive # |
dd7aea8c L |
723 | ; |
724 | ; -------------------------------------------------------------------- | |
725 | ; Description: | |
726 | ; ==================================================================== | |
727 | ||
5482d75f | 728 | dsk_format_get: |
dd7aea8c L |
729 | |
730 | ; Get first sector (512 byte) of current drive into hostbuf. | |
731 | ||
5482d75f | 732 | push temp3 |
dd7aea8c L |
733 | ldi temp,0 |
734 | ldi temp2,0 ; | |
735 | rcall dsk_readhost_lba | |
736 | ||
dd7aea8c L |
737 | ; Test for variable format avrcpmhd. |
738 | ||
739 | rcall dsk_tst_avrcpmhd | |
5482d75f | 740 | brne dsk_imgt_done |
dd7aea8c L |
741 | |
742 | ; Test for YAZE formats. | |
743 | ||
744 | rcall dsk_tst_yaze | |
5482d75f | 745 | brne dsk_imgt_done |
dd7aea8c | 746 | |
b165699b L |
747 | ; Test for simhd format. |
748 | ||
749 | rcall dsk_tst_simhd | |
750 | ldiw z,dpbdat_simhd*2 | |
5482d75f | 751 | brne dsk_imgt_fixed |
b165699b | 752 | |
dd7aea8c L |
753 | ; Test for MyZ80 format. |
754 | ||
755 | rcall dsk_tst_myz80 | |
756 | ldiw z,dpbdat_myz80*2 | |
5482d75f | 757 | brne dsk_imgt_fixed |
dd7aea8c L |
758 | |
759 | ; No special image found. Use avrcpm. | |
760 | ||
761 | ldiw z,dpbdat_avrcpm*2 | |
762 | ||
5482d75f | 763 | dsk_imgt_fixed: |
dd7aea8c | 764 | rcall dpb_copy_p |
5482d75f L |
765 | ori temp,0xff |
766 | dsk_imgt_done: | |
767 | pop temp3 | |
768 | ret | |
dd7aea8c | 769 | |
5482d75f L |
770 | ; ==================================================================== |
771 | ; Function: Add CP/M image format data to partition table data | |
772 | ; ==================================================================== | |
773 | ; Parameters | |
774 | ; -------------------------------------------------------------------- | |
775 | ; Registers : temp3 drive # | |
776 | ; | |
777 | ; -------------------------------------------------------------------- | |
778 | ; Description: | |
779 | ; ==================================================================== | |
780 | ||
781 | dpb_imgdata_get: | |
782 | ||
783 | ; Test for known CP/M formats | |
784 | ||
785 | rcall dsk_format_get | |
786 | breq dpb_imgd_err ;no known format detected | |
787 | ||
788 | ; | |
dd7aea8c L |
789 | mov zl,temp3 |
790 | rcall dsk_getpartentry ;get partition entry | |
791 | ldiw y,tmpdpb | |
792 | ||
793 | ; std y+12,_0 ;Test: set check size to 0 | |
794 | ; std y+13,_0 | |
795 | ||
796 | ldd temp,y+0 | |
797 | andi temp,~dskType_MASK | |
798 | ldd temp2,z+PTAB_TYPE | |
799 | andi temp2,dskType_MASK | |
800 | or temp,temp2 | |
801 | std z+PTAB_TYPE,temp | |
802 | ldd temp,y+1 | |
803 | std z+PTAB_SPT,temp | |
804 | ldd temp,y+2 | |
805 | tst temp ;more then 256 sectors per track? | |
806 | brne dsk_imgprp_err ;todo: support 16 bit sector numbers | |
807 | ldd temp2,y+3 | |
808 | andi temp2,0x0f | |
809 | swap temp2 | |
810 | std z+PTAB_BSH,temp2 | |
811 | ||
812 | ori temp,255 | |
813 | ret | |
814 | ||
815 | dsk_imgprp_err: | |
816 | printnewline | |
817 | ldi temp,'A' | |
818 | add temp,temp3 | |
819 | call uartputc | |
820 | printstring ": Format not supported: Too much sectors per track! " | |
821 | printnewline | |
822 | ||
5482d75f | 823 | dpb_imgd_err: |
dd7aea8c L |
824 | clr temp |
825 | ret | |
826 | ||
5482d75f L |
827 | ; ==================================================================== |
828 | ; Function: | |
829 | ; ==================================================================== | |
830 | ; Parameters | |
831 | ; -------------------------------------------------------------------- | |
832 | ; Registers : temp drive # | |
833 | ; | |
834 | ; return !0 if ok | |
835 | ; 0 on error | |
836 | ; -------------------------------------------------------------------- | |
837 | ; Description: Init CP/M data structures | |
29ce189c | 838 | ; |
5482d75f L |
839 | ; ----------------------------------------------------------------- |
840 | ; DPH: | XLT | | | |DIRBUF | DPB | CSV | ALV | | |
841 | ; ----------------------------------------------------------------- | |
842 | ;offset: 0 2 4 6 8 10 12 14 | |
843 | ; | |
844 | ; ------------------------------------------------------------- | |
845 | ; DPB: | SPT |BSH|BLM|EXM| DSM | DRM |AL0|AL1| CKS | OFF | | |
846 | ; ------------------------------------------------------------- | |
847 | ;offset: 0 5 7 11 13 | |
848 | ; ==================================================================== | |
29ce189c | 849 | |
5482d75f | 850 | dpb_biosdph_get: |
29ce189c L |
851 | mov temp3,temp ;save disk # |
852 | ||
5482d75f | 853 | rcall dsk_format_get |
dd7aea8c L |
854 | brne dpb_di_0 |
855 | rjmp dpb_di_err | |
29ce189c | 856 | |
dd7aea8c | 857 | dpb_di_0: |
29ce189c L |
858 | |
859 | ; get mem for DPH | |
29ce189c L |
860 | |
861 | ldi temp, low (16) | |
862 | ldi temp2,high(16) | |
5482d75f | 863 | rcall heap_get ;returns ptr to dph mem |
637689de L |
864 | brne dpb_di_1 |
865 | rjmp dpb_di_err ; | |
866 | dpb_di_1: | |
29ce189c | 867 | movw x,temp |
637689de | 868 | movw y,temp ;save dph pointer |
29ce189c L |
869 | ldi temp,0 |
870 | ldi temp2,0 | |
871 | rcall dram_writew_pp ;XLT | |
872 | adiw x,6 | |
873 | lds temp,biosdirbuf | |
874 | lds temp2,biosdirbuf+1 | |
875 | rcall dram_writew_pp ;DIRBUF | |
876 | ||
877 | ; get mem for DPB | |
29ce189c L |
878 | |
879 | ldi temp, low (15) | |
880 | ldi temp2,high(15) | |
881 | rcall heap_get | |
637689de | 882 | breq dpb_di_err_p1 |
29ce189c L |
883 | movw x,temp |
884 | ||
dd7aea8c | 885 | ldiw z,tmpdpb+1 ;skip sector offset byte |
637689de | 886 | dpb_dicpl: |
29ce189c L |
887 | ld temp,z+ |
888 | rcall dram_write_pp | |
dd7aea8c | 889 | cpi zl,low(tmpdpb + 16) |
637689de | 890 | brne dpb_dicpl |
29ce189c L |
891 | sbiw x,15 |
892 | movw temp,x | |
893 | movw x,y | |
894 | adiw x,10 | |
895 | rcall dram_writew_pp ;DPB | |
896 | ||
897 | ; get mem for dir check vector | |
898 | ||
dd7aea8c L |
899 | lds temp,tmpdpb+12 ;cks |
900 | lds temp2,tmpdpb+12+1 | |
29ce189c L |
901 | cp temp,_0 |
902 | cpc temp2,_0 | |
637689de | 903 | breq dpb_dicks0 |
29ce189c | 904 | rcall heap_get |
637689de L |
905 | breq dpb_di_err_p1 |
906 | dpb_dicks0: | |
29ce189c L |
907 | rcall dram_writew_pp ;CSV |
908 | ||
909 | ; get mem for alloc vector | |
910 | ||
dd7aea8c L |
911 | lds temp,tmpdpb+6 ;dsm |
912 | lds temp2,tmpdpb+6+1 | |
29ce189c L |
913 | subi temp, low (-8) |
914 | sbci temp2,high(-8) | |
915 | lsr temp2 | |
916 | ror temp | |
917 | lsr temp2 | |
918 | ror temp | |
919 | lsr temp2 | |
920 | ror temp ;(dsm+1+7)/8 | |
921 | rcall heap_get | |
637689de | 922 | breq dpb_di_err_p1 |
29ce189c L |
923 | rcall dram_writew_pp ;ALV |
924 | ||
925 | ; success, insert DPH into drvtbl | |
926 | ||
637689de L |
927 | mov temp,temp3 |
928 | rcall dpb_drvtbl_entry_p | |
29ce189c L |
929 | movw temp,y |
930 | rcall dram_writew_pp | |
dd7aea8c | 931 | |
29ce189c | 932 | ori temp,0xff ;return ok |
64219415 FZ |
933 | ret |
934 | ||
29ce189c L |
935 | ; error, free mem |
936 | ||
637689de | 937 | dpb_di_err_p1: |
29ce189c L |
938 | movw temp,y |
939 | rcall heap_release | |
637689de | 940 | dpb_di_err: |
29ce189c | 941 | eor temp,temp ;return 0 (+ Z-flag) |
b741422e | 942 | ret |
29ce189c | 943 | |
dd7aea8c L |
944 | ; ==================================================================== |
945 | ; Function: | |
946 | ; ==================================================================== | |
947 | ; Parameters | |
948 | ; -------------------------------------------------------------------- | |
949 | ; Registers : | |
950 | ; | |
951 | ; -------------------------------------------------------------------- | |
952 | ; Description: | |
953 | ; ==================================================================== | |
954 | dsk_setdrvparam: | |
955 | ldd temp2,z+PTAB_TYPE | |
956 | andi temp2,~dskType_MASK ;Lower nibble is image header size | |
957 | sts hdrsize,temp2 | |
958 | ldd temp2,z+PTAB_SPT | |
959 | sts cpmspt,temp2 | |
960 | ldd temp2,z+PTAB_BSH | |
961 | swap temp2 | |
962 | andi temp2,0x0f | |
963 | clr _tmp0 | |
964 | inc _tmp0 | |
965 | dsk_sdrvpl: | |
966 | lsl _tmp0 | |
967 | dec temp2 | |
968 | brne dsk_sdrvpl | |
969 | sts secpblk,_tmp0 | |
970 | ret | |
971 | ||
64219415 | 972 | |
b741422e | 973 | ; ==================================================================== |
64219415 | 974 | ; Function: Does a Disk interaction |
b741422e L |
975 | ; ==================================================================== |
976 | ; Parameters | |
977 | ; -------------------------------------------------------------------- | |
978 | ; Registers : none | |
979 | ; Variables : [r] seeksec Sector to read | |
980 | ; [r] seektrk Track to read | |
981 | ; -------------------------------------------------------------------- | |
982 | ; Description: | |
64219415 FZ |
983 | ; ==================================================================== |
984 | dskDoIt: | |
985 | .if DISK_DEBUG | |
986 | push temp | |
987 | sbrc temp,READ_FUNC | |
988 | rjmp dskdbgr | |
989 | sbrc temp,WRITE_FUNC | |
990 | rjmp dskdbgw | |
991 | rjmp dskdbge | |
992 | ||
993 | dskdbgr: | |
994 | printnewline | |
995 | printstring "Disk read: " | |
996 | rjmp dskdbg1 | |
997 | dskdbgw: | |
998 | printnewline | |
999 | printstring "Disk write: " | |
1000 | dskdbg1: | |
1001 | lds temp,seekdsk | |
1002 | subi temp,-('A') | |
1003 | rcall uartputc | |
1004 | printstring ": track " | |
1005 | lds temp2,seektrk+1 | |
1006 | lds temp,seektrk | |
1007 | rcall printhexw | |
1008 | printstring ", sector " | |
1009 | lds temp,seeksec | |
1010 | rcall printhex | |
1011 | printstring ", dma-addr " | |
1012 | lds temp2,dmaadr+1 | |
1013 | lds temp,dmaadr | |
1014 | rcall printhexw | |
1015 | pop temp | |
1016 | push temp | |
1017 | sbrs temp,WRITE_FUNC | |
1018 | rjmp dskdbge | |
1019 | printstring " wrtype " | |
1020 | andi temp,3 | |
1021 | rcall printhex | |
1022 | dskdbge: | |
1023 | pop temp | |
1024 | .endif | |
1025 | ;See what has to be done. | |
1026 | sbrc temp,READ_FUNC | |
1027 | rjmp dsk_read | |
1028 | sbrc temp,WRITE_FUNC | |
1029 | rjmp dsk_write | |
1030 | sbrc temp,HOME_FUNC | |
1031 | rjmp dsk_home | |
1032 | sbrc temp,BOOT_FUNC | |
1033 | rjmp dsk_boot | |
1034 | ||
1035 | printstring "DISK I/O: Invalid Function code: " | |
1036 | rcall printhex | |
1037 | rjmp haltinv | |
1038 | ||
1039 | dsk_boot: | |
dd7aea8c L |
1040 | sts ndisks,_0 ;no active partitions |
1041 | dsk_inval_hostbuf: | |
1042 | cbi flags,hostact ;host buffer inactive | |
1043 | sts unacnt,_0 ;clear unalloc count | |
64219415 FZ |
1044 | ret |
1045 | ||
1046 | dsk_home: | |
dd7aea8c L |
1047 | sbis flags,hostwrt ;check for pending write |
1048 | cbi flags,hostact ;clear host active flag | |
64219415 | 1049 | ret |
64219415 | 1050 | |
b741422e L |
1051 | |
1052 | ||
1053 | ; ==================================================================== | |
64219415 | 1054 | ; Function: Does a Disk read operation |
b741422e L |
1055 | ; ==================================================================== |
1056 | ; Parameters | |
1057 | ; -------------------------------------------------------------------- | |
eb85ce65 | 1058 | ; Registers : in: temp |
b741422e | 1059 | ; Variables : [r] seekdsk Number of Disk to Read |
1eeb9cbe | 1060 | ; [r] seeksec Sector to read |
b741422e L |
1061 | ; [r] seektrk Track to read |
1062 | ; -------------------------------------------------------------------- | |
1063 | ; Description: | |
64219415 FZ |
1064 | ; ==================================================================== |
1065 | dsk_read: | |
637689de L |
1066 | sts erflag,_0 |
1067 | sbi flags,readop ; Set read operation flag | |
29ce189c | 1068 | |
eb85ce65 | 1069 | ;RAM disk? |
dd7aea8c | 1070 | lds zl,seekdsk |
eb85ce65 | 1071 | #if RAMDISKCNT |
dd7aea8c | 1072 | cpi zl,RAMDISKNR |
eb85ce65 L |
1073 | brlt PC+2 |
1074 | rjmp rdsk_read | |
1075 | #endif | |
b741422e | 1076 | rcall dsk_getpartentry ; Get Paritiontableentry |
637689de L |
1077 | ld temp,z ; Get Partitiontype |
1078 | andi temp,dskType_MASK | |
b741422e L |
1079 | |
1080 | ; Isn't it a Disk ? | |
1eeb9cbe | 1081 | cpi temp,dskType_None |
b741422e L |
1082 | brne PC+2 |
1083 | rjmp dsk_read_err | |
dd7aea8c | 1084 | |
b741422e | 1085 | ; It must be a FAT16-Imagefile or CP/M Partition. |
dd7aea8c L |
1086 | |
1087 | rcall dsk_setdrvparam ;todo: do this only if needed (disk change) | |
1088 | ||
637689de L |
1089 | sts unacnt,_0 |
1090 | sbi flags,rsflag ;must read data | |
1091 | ldi temp,WRUAL ;write type | |
1092 | sts wrtype,temp ;treat as unalloc | |
dd7aea8c | 1093 | |
637689de | 1094 | rjmp dsk_rwoper ;to perform the read |
64219415 | 1095 | |
b741422e L |
1096 | dsk_read_err: |
1097 | ret | |
64219415 | 1098 | |
b741422e | 1099 | ; ==================================================================== |
64219415 | 1100 | ; Function: Does a Disk write operation |
b741422e L |
1101 | ; ==================================================================== |
1102 | ; Parameters | |
1103 | ; -------------------------------------------------------------------- | |
eb85ce65 | 1104 | ; Registers : in: temp Write type |
1eeb9cbe L |
1105 | ; Variables : [r] seekdsk Number of Disk to Read |
1106 | ; [r] seeksec Sector to read | |
1107 | ; [r] seektrk Track to read | |
b741422e L |
1108 | ; -------------------------------------------------------------------- |
1109 | ; Description: | |
64219415 FZ |
1110 | ; ==================================================================== |
1111 | dsk_write: | |
1112 | ;write the selected sector | |
637689de L |
1113 | sts erflag,_0 |
1114 | cbi flags,readop ; not a read operation | |
eb85ce65 | 1115 | ;RAM disk? |
dd7aea8c | 1116 | lds zl,seekdsk |
eb85ce65 | 1117 | #if RAMDISKCNT |
dd7aea8c | 1118 | cpi zl,RAMDISKNR |
eb85ce65 L |
1119 | brlt PC+2 |
1120 | rjmp rdsk_write | |
1121 | #endif | |
b741422e | 1122 | rcall dsk_getpartentry ; Get Paritiontableentry |
dd7aea8c | 1123 | ld temp2,z ; Get Partitiontype |
5482d75f | 1124 | andi temp2,dskType_MASK |
b741422e L |
1125 | |
1126 | ; Isn't it a Disk ? | |
eb85ce65 | 1127 | cpi temp2,dskType_None |
b741422e L |
1128 | brne PC+2 |
1129 | rjmp dsk_write_err | |
1130 | ||
1eeb9cbe | 1131 | |
b741422e | 1132 | ; It must be a FAT16-Imagefile or CP/M Partition. |
64219415 | 1133 | |
dd7aea8c L |
1134 | rcall dsk_setdrvparam ;todo: do this only if needed (disk change) |
1135 | ||
64219415 | 1136 | andi temp,WRTMSK |
dd7aea8c | 1137 | sts wrtype,temp ;save write type |
64219415 | 1138 | |
dd7aea8c L |
1139 | cpi temp,WRUAL ;write unallocated? |
1140 | brne dsk_chkuna ;check for unalloc | |
64219415 FZ |
1141 | |
1142 | ; write to unallocated, set parameters | |
dd7aea8c L |
1143 | lds temp,secpblk ;next unalloc recs (blocksize/128) |
1144 | sts unacnt,temp | |
1145 | lds temp,seekdsk ;disk to seek | |
1146 | sts unadsk,temp ;unadsk = sekdsk | |
1147 | lds temp,seektrk | |
1148 | sts unatrk,temp ;unatrk = sectrk | |
1149 | lds temp,seektrk+1 | |
1150 | sts unatrk+1,temp ;unatrk = sectrk | |
1151 | lds temp,seeksec | |
1152 | sts unasec,temp ;unasec = seksec | |
64219415 FZ |
1153 | ; |
1154 | dsk_chkuna: | |
1155 | ;check for write to unallocated sector | |
dd7aea8c L |
1156 | lds temp,unacnt ;any unalloc remain? |
1157 | tst temp | |
1158 | breq dsk_alloc ;skip if not | |
64219415 FZ |
1159 | |
1160 | ; more unallocated records remain | |
dd7aea8c L |
1161 | dec temp ;unacnt = unacnt-1 |
1162 | sts unacnt,temp | |
1163 | lds temp,seekdsk ;same disk? | |
1164 | lds temp2,unadsk | |
1165 | cp temp,temp2 ;seekdsk = unadsk? | |
1166 | brne dsk_alloc ;skip if not | |
64219415 FZ |
1167 | |
1168 | ; disks are the same | |
dd7aea8c L |
1169 | lds temp,unatrk |
1170 | lds temp2,unatrk+1 | |
1171 | lds temp3,seektrk | |
1172 | lds temp4,seektrk+1 | |
1173 | cp temp,temp3 ;seektrk = unatrk? | |
1174 | cpc temp2,temp4 | |
1175 | brne dsk_alloc ;skip if not | |
64219415 FZ |
1176 | |
1177 | ; tracks are the same | |
dd7aea8c L |
1178 | lds temp,seeksec ;same sector? |
1179 | lds temp2,unasec | |
1180 | cp temp,temp2 ;seeksec = unasec? | |
1181 | brne dsk_alloc ;skip if not | |
64219415 FZ |
1182 | |
1183 | ; match, move to next sector for future ref | |
dd7aea8c L |
1184 | inc temp2 ;unasec = unasec+1 |
1185 | sts unasec,temp2 | |
1186 | lds _tmp0,cpmspt | |
1187 | cp temp2,_tmp0 ;end of track? (count CP/M sectors) | |
1188 | brlo dsk_noovf ;skip if no overflow | |
64219415 FZ |
1189 | |
1190 | ; overflow to next track | |
dd7aea8c L |
1191 | sts unasec,_0 ;unasec = 0 |
1192 | lds temp,unatrk | |
1193 | lds temp2,unatrk+1 | |
64219415 FZ |
1194 | subi temp, low(-1) ;unatrk = unatrk+1 |
1195 | sbci temp2,high(-1) | |
dd7aea8c L |
1196 | sts unatrk,temp |
1197 | sts unatrk+1,temp2 | |
64219415 FZ |
1198 | ; |
1199 | dsk_noovf: | |
dd7aea8c L |
1200 | cbi flags,rsflag ;rsflag = 0 |
1201 | rjmp dsk_rwoper ;to perform the write | |
64219415 FZ |
1202 | ; |
1203 | dsk_alloc: | |
1204 | ;not an unallocated record, requires pre-read | |
dd7aea8c L |
1205 | sts unacnt,_0 ;unacnt = 0 |
1206 | sbi flags,rsflag ;rsflag = 1 | |
b741422e L |
1207 | rjmp dsk_rwoper |
1208 | ||
1209 | dsk_write_err: | |
1210 | ret | |
1211 | ||
1212 | ; ==================================================================== | |
64219415 | 1213 | ; Function: Does a Disk read/write operation |
b741422e L |
1214 | ; ==================================================================== |
1215 | ; Parameters | |
1216 | ; -------------------------------------------------------------------- | |
1217 | ; Registers : none | |
1218 | ; Variables : [r] seekdsk Number of Disk to Read | |
1219 | ; [r] seeksec Sector to read | |
1220 | ; [r] seektrk Track to read | |
1221 | ; -------------------------------------------------------------------- | |
1222 | ; Description: | |
1223 | ; ==================================================================== | |
1224 | dsk_rwoper: | |
64219415 FZ |
1225 | ;enter here to perform the read/write |
1226 | .if DISK_DEBUG | |
1227 | printstring ", flags: " | |
dd7aea8c | 1228 | in temp,flags |
64219415 FZ |
1229 | rcall printhex |
1230 | .endif | |
64219415 FZ |
1231 | ;Convert track/sector to an LBA address (in 128byte blocks) |
1232 | ||
dd7aea8c L |
1233 | lds xl,seeksec ; |
1234 | ldi xh,0 ; | |
1235 | ldi yl,0 ; | |
1236 | lds temp,hdrsize ;add image header size | |
1237 | add xl,temp ; | |
1238 | adc xh,_0 ; | |
1239 | lds temp3,seektrk ; | |
1240 | lds temp4,seektrk+1 ; | |
1241 | lds temp,cpmspt ; | |
1242 | mul temp3,temp ; | |
1243 | add xl,r0 ; | |
1244 | adc xh,r1 ; | |
1245 | mul temp4,temp ; | |
1246 | add xh,r0 ;yl:xh:xl := sec + trk * SectorsPerTrack | |
1247 | adc yl,r1 ; | |
1248 | ||
1249 | mov temp,xl | |
1250 | andi temp,SECMSK ;mask buffer number | |
1251 | push temp ;save for later | |
64219415 FZ |
1252 | |
1253 | ;Convert from CP/M LBA blocks to host LBA blocks | |
dd7aea8c | 1254 | ldi temp,SECSHF |
64219415 | 1255 | dsk_sh1: |
dd7aea8c L |
1256 | lsr yl |
1257 | ror xh | |
1258 | ror xl | |
1259 | dec temp | |
64219415 | 1260 | brne dsk_sh1 |
5482d75f L |
1261 | ;todo: yl should be 0 here. |
1262 | ;xh:xl = host block to seek | |
1263 | movw temp,x | |
1264 | lds temp3,seekdsk | |
1265 | rcall dsk_rw_hostbuf | |
64219415 FZ |
1266 | |
1267 | ;copy data to or from buffer | |
1268 | ldiw z,hostbuf | |
dd7aea8c L |
1269 | ldi temp,128 |
1270 | pop temp2 ;get buffer number (which part of hostbuf) | |
1271 | mul temp2,temp | |
1272 | add zl,r0 ;offset in hostbuf | |
1273 | adc zh,r1 | |
64219415 FZ |
1274 | |
1275 | .if DISK_DEBUG > 2 | |
5482d75f | 1276 | movw temp,r0 |
64219415 | 1277 | printstring "; host buf adr: " |
64219415 FZ |
1278 | rcall printhexw |
1279 | .endif | |
1280 | ||
dd7aea8c L |
1281 | lds xl,dmaadr |
1282 | lds xh,dmaadr+1 | |
1283 | ldi temp3,128 ;length of move | |
64219415 | 1284 | sbic flags,readop ;which way? |
dd7aea8c | 1285 | rjmp dsk_rmove ;skip if read |
64219415 FZ |
1286 | |
1287 | ; mark write operation | |
dd7aea8c | 1288 | sbi flags,hostwrt ;hostwrt = 1 |
64219415 FZ |
1289 | dsk_wmove: |
1290 | mem_read | |
dd7aea8c | 1291 | st z+,temp |
64219415 | 1292 | adiw xl,1 |
dd7aea8c | 1293 | dec temp3 |
64219415 FZ |
1294 | brne dsk_wmove |
1295 | rjmp dsk_rwmfin | |
1296 | ||
1297 | dsk_rmove: | |
dd7aea8c | 1298 | ld temp,z+ |
64219415 FZ |
1299 | mem_write |
1300 | adiw xl,1 | |
dd7aea8c | 1301 | dec temp3 |
64219415 FZ |
1302 | brne dsk_rmove |
1303 | dsk_rwmfin: | |
1304 | ; data has been moved to/from host buffer | |
dd7aea8c L |
1305 | lds temp,wrtype ;write type |
1306 | cpi temp,WRDIR ;to directory? | |
64219415 | 1307 | breq dsk_wdir |
dd7aea8c | 1308 | ret ;no further processing |
64219415 FZ |
1309 | dsk_wdir: |
1310 | ; clear host buffer for directory write | |
dd7aea8c L |
1311 | lds temp,erflag |
1312 | tst temp ;errors? | |
64219415 | 1313 | breq dsk_wdir1 |
dd7aea8c | 1314 | ret ;skip if so |
64219415 FZ |
1315 | dsk_wdir1: |
1316 | rcall dsk_writehost ;clear host buff | |
dd7aea8c | 1317 | cbi flags,hostwrt ;buffer written |
b741422e L |
1318 | ret |
1319 | ||
dd7aea8c L |
1320 | ; ==================================================================== |
1321 | ; Function: | |
1322 | ; ==================================================================== | |
1323 | ; Parameters | |
1324 | ; -------------------------------------------------------------------- | |
1325 | ; Registers : temp2:temp block to read (lba) | |
1326 | ; temp3 disk # | |
1327 | ; | |
1328 | ; -------------------------------------------------------------------- | |
1329 | ; Description: | |
1330 | ; ==================================================================== | |
1331 | dsk_readhost_lba: | |
5482d75f | 1332 | #if 0 |
dd7aea8c L |
1333 | printnewline |
1334 | printstring "readhst lba" | |
1335 | #endif | |
5482d75f L |
1336 | sbi flags,rsflag ;must read data |
1337 | rcall dsk_rw_hostbuf | |
1338 | lds temp,erflag ;returns 0, if ok | |
1339 | tst temp | |
1340 | ret | |
dd7aea8c | 1341 | |
5482d75f L |
1342 | ; ==================================================================== |
1343 | ; Function: Get physical disk sector in hostbuf. | |
1344 | ; ==================================================================== | |
1345 | ; Parameters | |
1346 | ; -------------------------------------------------------------------- | |
1347 | ; Registers : temp2:temp host block to read/write (lba) | |
1348 | ; temp3 disk # | |
1349 | ; | |
1350 | ; -------------------------------------------------------------------- | |
1351 | ; Description: | |
1352 | ; ==================================================================== | |
1353 | dsk_rw_hostbuf: | |
1354 | ;xh:xl = host block to seek | |
1355 | sts erflag,_0 ;no errors (yet) | |
1356 | ||
1357 | ; active host sector? | |
1358 | in _tmp0,flags ;host active flag | |
1359 | sbi flags,hostact ;always becomes 1 | |
1360 | sbrs _tmp0,hostact ;was it already? | |
1361 | rjmp dsk_filhst ;fill host if not | |
1362 | ||
1363 | ; host buffer active, same as seek buffer? | |
1364 | lds _tmp0,hostdsk ;same disk? | |
1365 | cp temp3,_tmp0 ;seekdsk = hostdsk? | |
1366 | brne dsk_nomatch | |
1367 | ||
1368 | ; same disk, same block? | |
1369 | lds _tmp0,hostlba | |
1370 | lds _tmp1,hostlba+1 | |
1371 | cp temp,_tmp0 | |
1372 | cpc temp2,_tmp1 | |
1373 | breq dsk_match | |
1374 | ||
1375 | dsk_nomatch: | |
1376 | ;proper disk, but not correct sector | |
1377 | sbis flags,hostwrt ;host written? | |
1378 | rjmp dsk_filhst | |
1379 | push temp3 | |
1380 | push temp2 | |
1381 | push temp | |
1382 | rcall dsk_writehost ;clear host buff | |
1383 | pop temp | |
1384 | pop temp2 | |
1385 | pop temp3 | |
1386 | ||
1387 | dsk_filhst: | |
1388 | ;may have to fill the host buffer | |
1389 | sts hostlba,temp | |
1390 | sts hostlba+1,temp2 | |
1391 | sts hostdsk,temp3 | |
1392 | ||
1393 | sbic flags,rsflag ;need to read? | |
1394 | rcall dsk_readhost ;yes, if 1 | |
1395 | cbi flags,hostwrt ;no pending write | |
1396 | ||
1397 | dsk_match: | |
1398 | ret | |
dd7aea8c | 1399 | |
b741422e | 1400 | ; ==================================================================== |
64219415 | 1401 | ; Function: Does a Disk write operation |
b741422e L |
1402 | ; ==================================================================== |
1403 | ; Parameters | |
1404 | ; -------------------------------------------------------------------- | |
1405 | ; Registers : none | |
1406 | ; Variables : [r] seekdsk Number of Disk to Read | |
1407 | ; [r] seeksec Sector to read | |
1408 | ; [r] seektrk Track to read | |
1409 | ; -------------------------------------------------------------------- | |
1410 | ; Description: | |
1411 | ; ==================================================================== | |
1412 | dsk_writehost: | |
dd7aea8c | 1413 | lds zl,hostdsk |
637689de L |
1414 | rcall dsk_getpartentry |
1415 | ld temp,z | |
1416 | andi temp,dskType_MASK | |
b741422e L |
1417 | |
1418 | #if FAT16_SUPPORT | |
64219415 | 1419 | ; Is it a FAT16 Diskimage ? |
637689de | 1420 | cpi temp,dskType_FAT |
b741422e L |
1421 | brne PC+2 |
1422 | rjmp fat_writehost | |
1423 | #endif | |
1424 | ||
64219415 | 1425 | ; Is it a CP/M Partition ? |
637689de | 1426 | cpi temp,dskType_CPM |
b741422e L |
1427 | brne PC+2 |
1428 | rjmp cpm_writehost | |
1429 | ; Disktype not supported -> Return | |
1430 | ret | |
1431 | ||
1432 | ; ==================================================================== | |
64219415 | 1433 | ; Function: Does a Disk read operation |
b741422e L |
1434 | ; ==================================================================== |
1435 | ; Parameters | |
1436 | ; -------------------------------------------------------------------- | |
1437 | ; Registers : none | |
1438 | ; Variables : [r] seekdsk Number of Disk to Read | |
1439 | ; [r] seeksec Sector to read | |
1440 | ; [r] seektrk Track to read | |
1441 | ; -------------------------------------------------------------------- | |
1442 | ; Description: | |
1443 | ; ==================================================================== | |
1444 | dsk_readhost: | |
dd7aea8c L |
1445 | |
1446 | #if 0 | |
1447 | printnewline | |
1448 | printstring "readhost" | |
1449 | ldiw z,biosdrvtbl | |
1450 | rcall dbg_hexdump_line | |
1451 | adiw z,16 | |
1452 | rcall dbg_hexdump_line | |
1453 | #endif | |
1454 | ||
1455 | lds zl,hostdsk | |
b741422e L |
1456 | rcall dsk_getpartentry |
1457 | ld temp,z | |
637689de | 1458 | andi temp,dskType_MASK |
b741422e L |
1459 | |
1460 | #if FAT16_SUPPORT | |
64219415 | 1461 | ; Is it a FAT16 Diskimage ? |
637689de | 1462 | cpi temp,dskType_FAT |
b741422e L |
1463 | brne PC+2 |
1464 | rjmp fat_readhost | |
1465 | #endif | |
1466 | ||
64219415 | 1467 | ; Is it a CP/M Partition ? |
637689de | 1468 | cpi temp,dskType_CPM |
b741422e L |
1469 | brne PC+2 |
1470 | rjmp cpm_readhost | |
1471 | ; Disktype not supported -> Return | |
1472 | ret | |
1473 | ||
5482d75f L |
1474 | |
1475 | ; vim:set ts=8 noet nowrap | |
1476 |