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