]>
Commit | Line | Data |
---|---|---|
1 | ; CP/M BIOS for avrcpm | |
2 | ; Copyright (C) 2010 Sprite_tm | |
3 | ; | |
4 | ; This program is free software: you can redistribute it and/or modify | |
5 | ; it under the terms of the GNU General Public License as published by | |
6 | ; the Free Software Foundation, either version 3 of the License, or | |
7 | ; (at your option) any later version. | |
8 | ; | |
9 | ; This program is distributed in the hope that it will be useful, | |
10 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | ; GNU General Public License for more details. | |
13 | ; | |
14 | ; You should have received a copy of the GNU General Public License | |
15 | ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ; | |
17 | ; $Id$ | |
18 | ; | |
19 | ||
20 | msize: equ 62 ;size of available RAM in k | |
21 | ||
22 | bias: equ (msize-20) * 1024 | |
23 | ccp: equ 3400h+bias ;base of cpm ccp | |
24 | bdos: equ ccp+806h ;base of bdos | |
25 | bios: equ ccp+1600h ;base of bios | |
26 | cdisk: equ 0004h ;current disk number (0 ... 15) | |
27 | iobyte: equ 0003h ;intel iobyte | |
28 | buff: equ 0080h ;default buffer address | |
29 | retry: equ 3 ;max retries on disk i/o before error | |
30 | ||
31 | cr: equ 13 | |
32 | lf: equ 10 | |
33 | ||
34 | READ_FUNC: equ 7 | |
35 | WRITE_FUNC: equ 6 | |
36 | BOOT_FUNC: equ 5 | |
37 | HOME_FUNC: equ 4 | |
38 | ||
39 | org bios | |
40 | nsects: equ ($-ccp)/128 ;warm start sector count | |
41 | ||
42 | jp boot | |
43 | wboote: | |
44 | jp wboot | |
45 | jp const | |
46 | jp conin | |
47 | jp conout | |
48 | jp list | |
49 | jp punch | |
50 | jp reader | |
51 | jp home | |
52 | jp seldsk | |
53 | jp settrk | |
54 | jp setsec | |
55 | jp setdma | |
56 | jp read | |
57 | jp write | |
58 | jp listst | |
59 | jp sectran | |
60 | ||
61 | signon: | |
62 | db cr,lf | |
63 | db msize/10+'0' | |
64 | db msize - (msize/10)*10 + '0' ;modulo doesn't work? | |
65 | db "k cp/m vers 2.2" | |
66 | msgnl: db cr,lf,0 | |
67 | ||
68 | const: | |
69 | in a,(0) | |
70 | ret | |
71 | ||
72 | conin: | |
73 | in a,(0) | |
74 | cp 0ffh | |
75 | jp nz,conin | |
76 | ||
77 | in a,(1) | |
78 | ret | |
79 | ||
80 | conout: | |
81 | ld a,c | |
82 | out (2),a | |
83 | ret | |
84 | ||
85 | list: | |
86 | ret | |
87 | ||
88 | listst: | |
89 | ld a,0 | |
90 | ret | |
91 | ||
92 | punch: | |
93 | ret | |
94 | ||
95 | reader: | |
96 | ld a,01Fh | |
97 | ret | |
98 | ||
99 | prmsg: | |
100 | ld a,(hl) | |
101 | or a | |
102 | ret z | |
103 | push hl | |
104 | ld c,a | |
105 | call conout | |
106 | pop hl | |
107 | inc hl | |
108 | jp prmsg | |
109 | ||
110 | prhex: | |
111 | ld a,c | |
112 | push af | |
113 | rra | |
114 | rra | |
115 | rra | |
116 | rra | |
117 | call prhexdigit | |
118 | pop af | |
119 | ; fall thru | |
120 | ||
121 | prhexdigit: | |
122 | and 00fh | |
123 | cp 10 | |
124 | jp c,prd1 | |
125 | add a,7 | |
126 | prd1: | |
127 | add a,'0' | |
128 | ld c,a | |
129 | jp conout | |
130 | ||
131 | ||
132 | boot: | |
133 | ld sp,buff | |
134 | ld hl,signon | |
135 | call prmsg | |
136 | ||
137 | xor a | |
138 | ld (bootdsk),a | |
139 | ld a,(dpb) | |
140 | ld (bootspt),a | |
141 | ||
142 | ld c,'I'-'A' | |
143 | call seldsk | |
144 | ld a,h | |
145 | or l | |
146 | jp z,boot1 | |
147 | ||
148 | ld de,10 | |
149 | add hl,de | |
150 | ld e,(hl) | |
151 | inc hl | |
152 | ld d,(hl) ;de = dpb of first ram disk | |
153 | ||
154 | ld hl,7 | |
155 | add hl,de | |
156 | ld a,(hl) ;get drm | |
157 | inc a | |
158 | and 0fch | |
159 | rrca ;4 dir entries per sector | |
160 | rrca ;Number of sectors to init | |
161 | push af | |
162 | ||
163 | ld bc,6 | |
164 | add hl,bc | |
165 | ld c,(hl) ;Start track | |
166 | push bc ;Save track | |
167 | ||
168 | ; Check, if we have reserved tracks. | |
169 | ld a,c | |
170 | or a | |
171 | jp z,boot0 ;Skip if not. | |
172 | ||
173 | ; Save CPM to ram disk. | |
174 | ||
175 | ld a,(de) ;sectors per track | |
176 | ld (bootspt),a | |
177 | ld a,'I'-'A' | |
178 | ld (bootdsk),a | |
179 | call home | |
180 | ld b,nsects | |
181 | ld c,0 ;track | |
182 | ld d,1 ;sektor (0 based) | |
183 | ld hl,ccp | |
184 | store1: | |
185 | push bc | |
186 | push de | |
187 | push hl | |
188 | ld c,d | |
189 | ld b,0 | |
190 | call setsec | |
191 | pop bc | |
192 | push bc | |
193 | call setdma | |
194 | ld c,0 | |
195 | call write | |
196 | ||
197 | pop hl | |
198 | ld de,128 | |
199 | add hl,de | |
200 | pop de | |
201 | pop bc | |
202 | dec b | |
203 | jp z,boot0 | |
204 | ||
205 | inc d | |
206 | ld a,(bootspt) | |
207 | dec a | |
208 | cp d ;if sector >= spt then change tracks | |
209 | jp nc,store1 | |
210 | ||
211 | ld d,0 | |
212 | inc c | |
213 | push bc | |
214 | push de | |
215 | push hl | |
216 | ld b,0 | |
217 | call settrk | |
218 | pop hl | |
219 | pop de | |
220 | pop bc | |
221 | jp store1 | |
222 | ||
223 | ; Clear directory area of ram disk. | |
224 | ||
225 | boot0: | |
226 | pop bc | |
227 | call settrk | |
228 | pop af | |
229 | ld d,a ;d = # of sectors | |
230 | ld e,0 ;e = sector | |
231 | push de | |
232 | ld hl,dirbuf ;Clear dirbuf | |
233 | ld c,128 | |
234 | ld a,0E5h | |
235 | boot_cl: | |
236 | ld (hl),a | |
237 | inc hl | |
238 | dec c | |
239 | jp nz,boot_cl | |
240 | ||
241 | ld bc,dirbuf | |
242 | call setdma | |
243 | pop de | |
244 | boot_cl2: | |
245 | push de | |
246 | ld c,e | |
247 | ld b,0 | |
248 | call setsec | |
249 | ld c,0 | |
250 | call write | |
251 | pop de | |
252 | inc e | |
253 | dec d | |
254 | jp nz,boot_cl2 | |
255 | ||
256 | boot1: | |
257 | xor a | |
258 | ld (iobyte),a | |
259 | ld (cdisk),a | |
260 | jp gocpm | |
261 | ||
262 | wboot: ;re-load CP/M | |
263 | ld sp,buff | |
264 | ld a,1<<BOOT_FUNC ;init (de)blocking | |
265 | out (22),a | |
266 | ld a,(bootdsk) | |
267 | ld c,a | |
268 | call seldsk | |
269 | call home | |
270 | ld b,nsects | |
271 | ld c,0 ;track | |
272 | ld d,1 ;sektor (0 based) | |
273 | ld hl,ccp | |
274 | load1: | |
275 | push bc | |
276 | push de | |
277 | push hl | |
278 | ld c,d | |
279 | ld b,0 | |
280 | call setsec | |
281 | pop bc | |
282 | push bc | |
283 | call setdma | |
284 | call read | |
285 | cp 0 ;read error? | |
286 | jp nz,wboot | |
287 | ||
288 | pop hl | |
289 | ld de,128 | |
290 | add hl,de | |
291 | pop de | |
292 | pop bc | |
293 | dec b | |
294 | jp z,gocpm | |
295 | ||
296 | inc d | |
297 | ld a,(bootspt) | |
298 | dec a | |
299 | cp d ;if sector >= spt then change tracks | |
300 | jp nc,load1 | |
301 | ||
302 | ld d,0 | |
303 | inc c | |
304 | push bc | |
305 | push de | |
306 | push hl | |
307 | ld b,0 | |
308 | call settrk | |
309 | pop hl | |
310 | pop de | |
311 | pop bc | |
312 | jp load1 | |
313 | ||
314 | gocpm: | |
315 | ld a,0c3h | |
316 | ld (0),a | |
317 | ld hl,wboote | |
318 | ld (1),hl | |
319 | ld (5),a | |
320 | ld hl,bdos | |
321 | ld (6),hl | |
322 | ||
323 | ld bc,buff | |
324 | call setdma | |
325 | ld a,(cdisk) | |
326 | ld c,a | |
327 | jp ccp | |
328 | ||
329 | seldsk: | |
330 | ld hl,dphtab | |
331 | ld b,0 | |
332 | add hl,bc | |
333 | add hl,bc | |
334 | ld a,(hl) ;get table entry for selected disk | |
335 | inc hl | |
336 | ld h,(hl) | |
337 | ld l,a | |
338 | or h ;no entry, no disk | |
339 | ret z ; | |
340 | ||
341 | ld a,c | |
342 | out (15),a | |
343 | in a,(15) ;querry, if disk exists | |
344 | or a ;0 = disk is ok | |
345 | ret z | |
346 | ld hl,0 ;error return code | |
347 | ret | |
348 | ||
349 | home: | |
350 | ld a,1<<HOME_FUNC | |
351 | out (22),a | |
352 | ||
353 | ld bc,0 ; same as seek to track 0 | |
354 | settrk: | |
355 | ld a,c | |
356 | out (16),a | |
357 | ld a,b | |
358 | out (17),a | |
359 | ret | |
360 | ||
361 | setsec: | |
362 | ld a,c | |
363 | out (18),a | |
364 | ret | |
365 | ||
366 | setdma: | |
367 | ld a,c | |
368 | out (20),a | |
369 | ld a,b | |
370 | out (21),a | |
371 | ret | |
372 | ||
373 | read: | |
374 | ld a,1<<READ_FUNC | |
375 | out (22),a | |
376 | in a,(22) | |
377 | and 1 | |
378 | ret | |
379 | ||
380 | write: | |
381 | ld a,c | |
382 | and 3 ;mask write type | |
383 | or 1<<WRITE_FUNC | |
384 | out (22),a | |
385 | in a,(22) | |
386 | and 1 | |
387 | ret | |
388 | ||
389 | sectran: | |
390 | ;translate sector bc using table at de, res into hl | |
391 | ld h,b | |
392 | ld l,c | |
393 | ld a,d | |
394 | or e | |
395 | ret z | |
396 | ex de,hl | |
397 | add hl,bc | |
398 | ld l,(hl) | |
399 | ld h,0 | |
400 | ret | |
401 | ||
402 | dphtab: | |
403 | dw dpe0 | |
404 | dw dpe1 | |
405 | dw dpe2 | |
406 | dw dpe3 | |
407 | dw 0 | |
408 | dw 0 | |
409 | dw 0 | |
410 | dw 0 | |
411 | dw dperd0 | |
412 | dw 0 | |
413 | dw 0 | |
414 | dw 0 | |
415 | dw 0 | |
416 | dw 0 | |
417 | dw 0 | |
418 | dw 0 | |
419 | ||
420 | ||
421 | ||
422 | ;Disk Parameter Header | |
423 | dpbase: | |
424 | dpe0: dw 0 ;XLT: No sector translation table | |
425 | dw 0 ;000: Scratchpad | |
426 | dw 0 ;000: Scratchpad | |
427 | dw 0 ;000: Scratchpad | |
428 | dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad | |
429 | dw dpb ;DPB: Address of a disk parameter block | |
430 | dw chk0 ;CSV: Address of scratchpad area for changed disks | |
431 | dw all0 ;ALV: Address of an allocation info sratchpad | |
432 | dpe1: dw 0 ;XLT: No sector translation table | |
433 | dw 0 ;000: Scratchpad | |
434 | dw 0 ;000: Scratchpad | |
435 | dw 0 ;000: Scratchpad | |
436 | dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad | |
437 | dw dpb ;DPB: Address of a disk parameter block | |
438 | dw chk1 ;CSV: Address of scratchpad area for changed disks | |
439 | dw all1 ;ALV: Address of an allocation info sratchpad | |
440 | dpe2: dw 0 ;XLT: No sector translation table | |
441 | dw 0 ;000: Scratchpad | |
442 | dw 0 ;000: Scratchpad | |
443 | dw 0 ;000: Scratchpad | |
444 | dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad | |
445 | dw dpb ;DPB: Address of a disk parameter block | |
446 | dw chk2 ;CSV: Address of scratchpad area for changed disks | |
447 | dw all2 ;ALV: Address of an allocation info sratchpad | |
448 | dpe3: dw 0 ;XLT: No sector translation table | |
449 | dw 0 ;000: Scratchpad | |
450 | dw 0 ;000: Scratchpad | |
451 | dw 0 ;000: Scratchpad | |
452 | dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad | |
453 | dw dpb ;DPB: Address of a disk parameter block | |
454 | dw chk3 ;CSV: Address of scratchpad area for changed disks | |
455 | dw all3 ;ALV: Address of an allocation info sratchpad | |
456 | ||
457 | dperd0: dw 0 ;XLT: No sector translation table | |
458 | dw 0 ;000: Scratchpad | |
459 | dw 0 ;000: Scratchpad | |
460 | dw 0 ;000: Scratchpad | |
461 | dw dirbuf ;DIRBUF: Address of a dirbuff scratchpad | |
462 | dw dpbrd ;DPB: Address of a disk parameter block | |
463 | dw chkrd0 ;CSV: Address of scratchpad area for changed disks | |
464 | dw allrd0 ;ALV: Address of an allocation info sratchpad | |
465 | ||
466 | ||
467 | dpb: dw 26 ;SPT: sectors per track | |
468 | db 3 ;BSH: data allocation block shift factor | |
469 | db 7 ;BLM: Data Allocation Mask | |
470 | db 0 ;Extent mask | |
471 | dw 242 ;DSM: Disk storage capacity | |
472 | dw 63 ;DRM, no of directory entries | |
473 | db 192 ;AL0 | |
474 | db 0 ;AL1 | |
475 | dw 16 ;CKS, size of dir check vector | |
476 | dw 2 ;OFF, no of reserved tracks | |
477 | ||
478 | dpbrd: dw 32 ;SPT: sectors per track | |
479 | db 3 ;BSH: data allocation block shift factor | |
480 | db 7 ;BLM: Data Allocation Mask | |
481 | db 0 ;Extent mask | |
482 | dw 55 ;DSM: Disk storage capacity | |
483 | dw 31 ;DRM, no of directory entries | |
484 | db 128 ;AL0 | |
485 | db 0 ;AL1 | |
486 | dw 0 ;CKS, size of dir check vector | |
487 | dw 2 ;OFF, no of reserved tracks | |
488 | ||
489 | bootdsk:ds 1 | |
490 | bootspt:ds 1 | |
491 | ||
492 | dirbuf: | |
493 | ds 128 | |
494 | ||
495 | chk0: ds 16 | |
496 | all0: ds 31 | |
497 | chk1: ds 16 | |
498 | all1: ds 31 | |
499 | chk2: ds 16 | |
500 | all2: ds 31 | |
501 | chk3: ds 16 | |
502 | all3: ds 31 | |
503 | chkrd0: ds 0 | |
504 | allrd0: ds 7 | |
505 | ||
506 | end | |
507 |