]> cloudbase.mooo.com Git - avrcpm.git/blob - cpm/bios.mac
* cpm/ipl.mac
[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 aseg
23 org 100h
24 .phase bios
25 .z80
26
27 nsects equ ($-ccp)/128 ;warm start sector count
28
29 jp boot
30 wboote:
31 jp wboot
32 jp const
33 jp conin
34 jp conout
35 jp list
36 jp punch
37 jp reader
38 jp home
39 jp seldsk
40 jp settrk
41 jp setsec
42 jp setdma
43 jp read
44 jp write
45 jp listst
46 jp sectran
47
48 .8080
49 maclib AVRCPM.LIB
50
51 ;Drive A B C D E F G H I J K L
52 ;drvtbl: dtbl <dpha,dphb,dphc,dphd, , , , ,dphi,dphj,dphk,dphl>
53 ;drvtbl: dtbl <dpha, , , , , , , ,dphi,dphj,dphk,dphl>
54 drvtbl: dtbl < , , , , , , , ,dphi,dphj,dphk,dphl>
55
56 ; Name spt bls dks dir cks off
57 ; dpb dpb243, 26, 1024, 243, 64, 64, 2
58 ; dpb dp8192s,32, 4096,2046, 512, 512, 2
59 ; dpb dp8192, 32, 4096,2046,1024,1024, 2
60 ; dpb dpbrd, 32, 1024, 56, 32, 0, 2
61 dpb rd1016, 32, 2048, 508, 192, 0, 2
62 dpb rd1024, 32, 2048, 512, 192, 0, 0
63 dpb rd0960, 32, 2048, 480, 192, 0, 0
64
65 ;dpha: dph dpb243
66 ;dphb: dph dpb243
67 ;dphc: dph dpb243
68 ;dphd: dph dpb243
69 ;dpha: dph dp8192s
70 ;dphb: dph dp8192s
71 ;dphc: dph dp8192
72 ;dphd: dph dp8192
73 dphi: dph rd1016
74 dphj: dph rd1024
75 dphk: dph rd1024
76 dphl: dph rd0960
77
78 .z80
79
80 signon:
81 db cr,lf
82 db msize/10+'0'
83 db msize - (msize/10)*10 + '0' ;modulo doesn't work?
84 db "k cp/m vers 2.2"
85 msgnl: db cr,lf,0
86
87 msgnodisk:
88 db "No disk!"
89 db cr,lf,0
90
91 const:
92 in a,(0)
93 ret
94
95 conin:
96 in a,(0)
97 cp 0ffh
98 jp nz,conin
99
100 in a,(1)
101 ret
102
103 conout:
104 ld a,c
105 out (1),a
106 ret
107
108 list:
109 ret
110
111 listst:
112 ld a,0
113 ret
114
115 punch:
116 ret
117
118 reader:
119 ld a,01Fh
120 ret
121
122 prmsg:
123 ld a,(hl)
124 or a
125 ret z
126 push hl
127 ld c,a
128 call conout
129 pop hl
130 inc hl
131 jp prmsg
132
133 prhex:
134 ld a,c
135 push af
136 rra
137 rra
138 rra
139 rra
140 call prhexdigit
141 pop af
142 ; fall thru
143
144 prhexdigit:
145 and 00fh
146 cp 10
147 jp c,prd1
148 add a,7
149 prd1:
150 add a,'0'
151 ld c,a
152 jp conout
153
154 boot:
155 ld sp,buff
156 ld hl,signon
157 call prmsg
158
159 ld a,low bcb
160 out (13),a
161 ld a, high bcb
162 out (14),a
163
164 xor a
165 ld (bootdsk),a
166 ld e,a
167 ld c,a
168 call seldsk
169 jp nz,boot0
170 ld hl,msgnodisk
171 call prmsg
172 halt
173 boot0:
174 call getdpb
175 ld a,(de) ;dpb[0] is sectors_per_track
176 ld (bootspt),a
177 ld e,0
178 ld c,'I'-'A'
179 call seldsk
180 jp z,boot1 ;no ram disk
181
182 call getdpb ;de = dpb of first ram disk
183
184 ; Check, if we have reserved tracks.
185
186 ld hl,13
187 add hl,de
188
189 ld a,(hl) ;# of reserved tracks
190 inc hl
191 or (hl)
192 jp z,boot1 ;Skip if not.
193
194 ; Save CPM to ram disk.
195
196 ld a,(de) ;sectors per track
197 ld (bootspt),a
198 ld a,'I'-'A'
199 ld (bootdsk),a
200 call home
201 ld b,nsects
202 ld c,0 ;track
203 ld d,1 ;sektor (0 based, skip ipl)
204 ld hl,ccp
205 store1:
206 push bc
207 push de
208 push hl
209 ld c,d
210 ld b,0
211 call setsec
212 pop bc ;dma
213 push bc
214 call setdma
215 ld c,0
216 call write
217
218 pop hl ;dma
219 ld de,128
220 add hl,de
221 pop de ;d = sec
222 pop bc ;b = # of secs, c = track
223 dec b
224 jp z,boot1
225
226 inc d
227 ld a,(bootspt)
228 dec a
229 cp d ;if sector >= spt then change tracks
230 jp nc,store1
231
232 ld d,0
233 inc c
234 push bc
235 push de
236 push hl
237 ld b,0
238 call settrk
239 pop hl
240 pop de
241 pop bc
242 jp store1
243
244 boot1:
245 xor a
246 ld (iobyte),a
247 ld (cdisk),a
248 jp gocpm
249
250 wboot: ;re-load CP/M
251 ld sp,buff
252 ld a,1 shl BOOT_FUNC ;init (de)blocking
253 out (22),a
254 ld a,(bootdsk)
255 ld c,a
256 call seldsk
257 call home
258 ld b,nsects
259 ld c,0 ;track
260 ld d,1 ;sektor (0 based)
261 ld hl,ccp
262 load1:
263 push bc
264 push de
265 push hl
266 ld c,d
267 ld b,0
268 call setsec
269 pop bc
270 push bc
271 call setdma
272 call read
273 cp 0 ;read error?
274 jp nz,wboot
275
276 pop hl
277 ld de,128
278 add hl,de
279 pop de
280 pop bc
281 dec b
282 jp z,gocpm
283
284 inc d
285 ld a,(bootspt)
286 dec a
287 cp d ;if sector >= spt then change tracks
288 jp nc,load1
289
290 ld d,0
291 inc c
292 push bc
293 push de
294 push hl
295 ld b,0
296 call settrk
297 pop hl
298 pop de
299 pop bc
300 jp load1
301
302 gocpm:
303 ld a,0c3h
304 ld (0),a
305 ld hl,wboote
306 ld (1),hl
307 ld (5),a
308 ld hl,bdos
309 ld (6),hl
310
311 ld bc,buff
312 call setdma
313 ld a,(cdisk)
314 ld c,a
315 jp ccp
316
317 msgSel: db 13,10,"Sel: ",0
318
319 getdpb:
320 ld de,10
321 add hl,de
322 ld e,(hl)
323 inc hl
324 ld d,(hl) ;de = dpb
325 ret
326
327 seldsk:
328 ld a,c
329 out (15),a
330
331 ld a,e ;reselection bit
332 rrca
333 jp c,getdph ;skip, if disk already active
334 ld hl,0
335 in a,(15) ;querry, if disk exists
336 or a
337 ret z
338 getdph:
339 ld hl,drvtbl
340 ld b,0
341 add hl,bc
342 add hl,bc
343 ld a,(hl) ;get table entry for selected disk
344 inc hl
345 ld h,(hl)
346 ld l,a
347 or h ;return zero, if no entry (no disk)
348 ret
349
350
351 home:
352 ld a,1 shl HOME_FUNC
353 out (22),a
354
355 ld bc,0 ; same as seek to track 0
356 settrk:
357 ld a,c
358 out (16),a
359 ld a,b
360 out (17),a
361 ret
362
363 setsec:
364 ld a,c
365 out (18),a
366 ret
367
368 setdma:
369 ld a,c
370 out (20),a
371 ld a,b
372 out (21),a
373 ret
374
375 read:
376 ld a,1 shl READ_FUNC
377 out (22),a
378 in a,(22)
379 and 1
380 ret
381
382 write:
383 ld a,c
384 and 3 ;mask write type
385 or 1 shl WRITE_FUNC
386 out (22),a
387 in a,(22)
388 and 1
389 ret
390
391 sectran:
392 ;translate sector bc using table at de, res into hl
393 ld h,b
394 ld l,c
395 ld a,d
396 or e
397 ret z
398 ex de,hl
399 add hl,bc
400 ld l,(hl)
401 ld h,0
402 ret
403
404 bcb: dw drvtbl
405 dw dirbuf
406 dw enddat
407
408 bootdsk:ds 1
409 bootspt:ds 1
410
411 .8080
412 endef
413
414 end
415