]> cloudbase.mooo.com Git - avrcpm.git/blob - cpm/BIOS.MAC
Tag for Version 3.2
[avrcpm.git] / cpm / BIOS.MAC
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: bios.asm 71 2010-08-06 19:38:10Z leo $
18 ;
19
20 maclib CFGACPM.LIB
21
22 cr equ 0dh
23 lf equ 0ah
24
25 aseg
26 org 100h
27 .phase bios
28 .z80
29
30 nsects equ ($-ccp)/128 ;warm start sector count
31
32 jp boot
33 wboote:
34 jp wboot
35 jp const
36 jp conin
37 jp conout
38 jp list
39 jp punch
40 jp reader
41 jp home
42 jp seldsk
43 jp settrk
44 jp setsec
45 jp setdma
46 jp read
47 jp write
48 jp listst
49 jp sectran
50 jp 0 ;zsdos (?)
51 jp 0 ;zsdos (?)
52 jp 0 ;zsdos (?)
53 jp clock ;zsdos compatible clock set/get
54
55
56 .8080
57 maclib AVRCPM.LIB
58
59 ;Drive A B C D E F G H I J K L
60 ;drvtbl:dtbl <dpha,dphb,dphc,dphd, , , , ,dphi,dphj,dphk,dphl>
61 ;drvtbl:dtbl <dpha, , , , , , , ,dphi,dphj,dphk,dphl>
62 ;drvtbl: dtbl < , , , , , , , ,dphi,dphj,dphk,dphl>
63 drvtbl:dtbl < , , , , , , , ,dphi>
64
65 ; Name spt bls dks dir cks off
66 ; dpb dpb243, 26, 1024, 243, 64, 64, 2
67 ; dpb dp8192s,32, 4096,2046, 512, 512, 2
68 ; dpb dp8192, 32, 4096,2046,1024,1024, 2
69 ; dpb dpbrd, 32, 1024, 56, 32, 0, 2
70 dpb rd192, 32, 1024, 192, 32, 0, 0
71 ; dpb rd1016, 32, 2048, 508, 192, 0, 2
72 ; dpb rd1024, 32, 2048, 512, 192, 0, 0
73 ; dpb rd0960, 32, 2048, 480, 192, 0, 0
74
75 ;dpha: dph dpb243
76 ;dphb: dph dpb243
77 ;dphc: dph dpb243
78 ;dphd: dph dpb243
79 ;dpha: dph dp8192s
80 ;dphb: dph dp8192s
81 ;dphc: dph dp8192
82 ;dphd: dph dp8192
83 ;dphi: dph rd1016
84 dphi: dph rd192
85 ;dphj: dph rd1024
86 ;dphk: dph rd1024
87 ;dphl: dph rd0960
88
89 .z80
90
91 signon:
92 db cr,lf
93 db msize/10+'0'
94 db msize - (msize/10)*10 + '0' ;modulo doesn't work?
95 db "k cp/m vers 2.2"
96 msgnl: db cr,lf,0
97
98 msgnodisk:
99 db "No disk!"
100 db cr,lf,0
101
102 const:
103 in a,(UARTCSR)
104 and UARTRXRDY
105 ret z
106 or 0ffh
107 ret
108
109 conin:
110 in a,(UARTCSR)
111 rra
112 jp nc,conin
113
114 in a,(UARTDR)
115 ret
116
117 conout:
118 ld a,c
119 out (UARTDR),a
120 ret
121
122 list:
123 ret
124
125 listst:
126 ld a,0
127 ret
128
129 punch:
130 ret
131
132 reader:
133 ld a,01Fh
134 ret
135
136 prmsg:
137 ld a,(hl)
138 or a
139 ret z
140 push hl
141 ld c,a
142 call conout
143 pop hl
144 inc hl
145 jp prmsg
146
147 prhex:
148 ld a,c
149 push af
150 rra
151 rra
152 rra
153 rra
154 call prhexdigit
155 pop af
156 ; fall thru
157
158 prhexdigit:
159 and 00fh
160 cp 10
161 jp c,prd1
162 add a,7
163 prd1:
164 add a,'0'
165 ld c,a
166 jp conout
167
168 boot:
169 ld sp,buff
170 ld hl,signon
171 call prmsg
172
173 ld a,low bcb
174 out (13),a
175 ld a, high bcb
176 out (14),a
177
178 xor a
179 ld (bootdsk),a
180 ld e,a
181 ld c,a
182 call seldsk
183 jp nz,boot0
184 ld hl,msgnodisk
185 call prmsg
186 halt
187 boot0:
188 call getdpb
189 ld a,(de) ;dpb[0] is sectors_per_track
190 ld (bootspt),a
191 ld e,0
192 ld c,'I'-'A'
193 call seldsk
194 jp z,boot1 ;no ram disk
195
196 call getdpb ;de = dpb of first ram disk
197
198 ; Check, if we have reserved tracks.
199
200 ld hl,13
201 add hl,de
202
203 ld a,(hl) ;# of reserved tracks
204 inc hl
205 or (hl)
206 jp z,boot1 ;Skip if not.
207
208 ; Save CPM to ram disk.
209
210 ld a,(de) ;sectors per track
211 ld (bootspt),a
212 ld a,'I'-'A'
213 ld (bootdsk),a
214 call home
215 ld b,nsects
216 ld c,0 ;track
217 ld d,1 ;sektor (0 based, skip ipl)
218 ld hl,ccp
219 store1:
220 push bc
221 push de
222 push hl
223 ld c,d
224 ld b,0
225 call setsec
226 pop bc ;dma
227 push bc
228 call setdma
229 ld c,0
230 call write
231
232 pop hl ;dma
233 ld de,128
234 add hl,de
235 pop de ;d = sec
236 pop bc ;b = # of secs, c = track
237 dec b
238 jp z,boot1
239
240 inc d
241 ld a,(bootspt)
242 dec a
243 cp d ;if sector >= spt then change tracks
244 jp nc,store1
245
246 ld d,0
247 inc c
248 push bc
249 push de
250 push hl
251 ld b,0
252 call settrk
253 pop hl
254 pop de
255 pop bc
256 jp store1
257
258 boot1:
259 xor a
260 ld (iobyte),a
261 ld (cdisk),a
262 jp gocpm
263
264 wboot: ;re-load CP/M
265 ld sp,buff
266 ld a,1 shl BOOT_FUNC ;init (de)blocking
267 out (22),a
268 ld a,(bootdsk)
269 ld c,a
270 ld e,0 ;clear reselection flag
271 call seldsk
272 call home
273 ld b,nsects
274 ld c,0 ;track
275 ld d,1 ;sektor (0 based)
276 ld hl,ccp
277 load1:
278 push bc
279 push de
280 push hl
281 ld c,d
282 ld b,0
283 call setsec
284 pop bc
285 push bc
286 call setdma
287 call read
288 cp 0 ;read error?
289 jp nz,wboot
290
291 pop hl
292 ld de,128
293 add hl,de
294 pop de
295 pop bc
296 dec b
297 jp z,gocpm
298
299 inc d
300 ld a,(bootspt)
301 dec a
302 cp d ;if sector >= spt then change tracks
303 jp nc,load1
304
305 ld d,0
306 inc c
307 push bc
308 push de
309 push hl
310 ld b,0
311 call settrk
312 pop hl
313 pop de
314 pop bc
315 jp load1
316
317 gocpm:
318 ld a,0c3h
319 ld (0),a
320 ld hl,wboote
321 ld (1),hl
322 ld (5),a
323 ld hl,bdos
324 ld (6),hl
325
326 ld bc,buff
327 call setdma
328 ld a,(cdisk)
329 ld c,a
330 jp ccp
331
332 msgSel: db 13,10,"Sel: ",0
333
334 getdpb:
335 ld de,10
336 add hl,de
337 ld e,(hl)
338 inc hl
339 ld d,(hl) ;de = dpb
340 ret
341
342 seldsk:
343 ld a,c
344 out (15),a
345
346 ld a,e ;reselection bit
347 rrca
348 jp c,getdph ;skip, if disk already active
349 ld hl,0
350 in a,(15) ;querry, if disk exists
351 or a
352 ret z
353 getdph:
354 ld hl,drvtbl
355 ld b,0
356 add hl,bc
357 add hl,bc
358 ld a,(hl) ;get table entry for selected disk
359 inc hl
360 ld h,(hl)
361 ld l,a
362 or h ;return zero, if no entry (no disk)
363 ret
364
365
366 home:
367 ld a,1 shl HOME_FUNC
368 out (22),a
369
370 ld bc,0 ; same as seek to track 0
371 settrk:
372 ld a,c
373 out (16),a
374 ld a,b
375 out (17),a
376 ret
377
378 setsec:
379 ld a,c
380 out (18),a
381 ret
382
383 setdma:
384 ld a,c
385 out (20),a
386 ld a,b
387 out (21),a
388 ret
389
390 read:
391 ld a,1 shl READ_FUNC
392 out (22),a
393 in a,(22)
394 and 1
395 ret
396
397 write:
398 ld a,c
399 and 3 ;mask write type
400 or 1 shl WRITE_FUNC
401 out (22),a
402 in a,(22)
403 and 1
404 ret
405
406 sectran:
407 ;translate sector bc using table at de, res into hl
408 ld h,b
409 ld l,c
410 ld a,d
411 or e
412 ret z
413 ex de,hl
414 add hl,bc
415 ld l,(hl)
416 ld h,0
417 ret
418
419 ;------------------------------------------------------------------------
420 ; ZSDOS clock drivers may use registers BC and D without restoring them,
421 ; but must preserve the Z80's alternate and index registers.
422 ; Other registers must be used exactly as follows:
423 ;
424 ; Enter: C = 00H to Read the Clock, 01H to Set the Clock
425 ; DE = Address of a 6-byte field to Receive or from which
426 ; to Set time in DateStamper format (BCD digits as:
427 ; YY MM DD HH MM SS). 24-hour operation is assumed.
428 ;
429 ; Exit : A = 01H for a successful operation,
430 ; 0FFH for a failure of any sort (Can't set, etc.)
431 ;
432 ; When Reading the Clock:
433 ; E = Original contents of Entry value of DE plus 5
434 ; HL = Entry value of DE plus 5 (Seconds field)
435
436 clock:
437 dec c
438 jr z,clk_set
439 inc c
440 ret nz
441
442 clk_get:
443 ld hl,5
444 add hl,de
445 push hl
446 ld bc,6*256 + CLOCKPORT-1
447 ld e,(hl)
448 clk_gl:
449 inc c
450 ind
451 jr nz,clk_gl
452 pop hl
453 jr clk_e
454
455
456 clk_set:
457 ld a,(hl)
458 cp 78h
459 ld a,19h
460 jr nc,clk_s1
461 ld a,20h
462 clk_s1:
463 out (CLOCKPORT+6),a
464 ld bc,6*256 + CLOCKPORT+6
465 clk_sl:
466 dec c
467 outi
468 jr nz,clk_sl
469 dec hl
470 clk_e:
471 ld a,1
472 ret
473
474 ;------------------------------------------------------------------------
475
476 bcb: dw drvtbl
477 dw dirbuf
478 dw enddat
479
480 bootdsk:ds 1
481 bootspt:ds 1
482
483 .8080
484 endef
485
486 end
487