]> cloudbase.mooo.com Git - avrcpm.git/blob - cpm/BIOS.MAC
* RAMDISK (re)integrated
[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 call seldsk
260 call home
261 ld b,nsects
262 ld c,0 ;track
263 ld d,1 ;sektor (0 based)
264 ld hl,ccp
265 load1:
266 push bc
267 push de
268 push hl
269 ld c,d
270 ld b,0
271 call setsec
272 pop bc
273 push bc
274 call setdma
275 call read
276 cp 0 ;read error?
277 jp nz,wboot
278
279 pop hl
280 ld de,128
281 add hl,de
282 pop de
283 pop bc
284 dec b
285 jp z,gocpm
286
287 inc d
288 ld a,(bootspt)
289 dec a
290 cp d ;if sector >= spt then change tracks
291 jp nc,load1
292
293 ld d,0
294 inc c
295 push bc
296 push de
297 push hl
298 ld b,0
299 call settrk
300 pop hl
301 pop de
302 pop bc
303 jp load1
304
305 gocpm:
306 ld a,0c3h
307 ld (0),a
308 ld hl,wboote
309 ld (1),hl
310 ld (5),a
311 ld hl,bdos
312 ld (6),hl
313
314 ld bc,buff
315 call setdma
316 ld a,(cdisk)
317 ld c,a
318 jp ccp
319
320 msgSel: db 13,10,"Sel: ",0
321
322 getdpb:
323 ld de,10
324 add hl,de
325 ld e,(hl)
326 inc hl
327 ld d,(hl) ;de = dpb
328 ret
329
330 seldsk:
331 ld a,c
332 out (15),a
333
334 ld a,e ;reselection bit
335 rrca
336 jp c,getdph ;skip, if disk already active
337 ld hl,0
338 in a,(15) ;querry, if disk exists
339 or a
340 ret z
341 getdph:
342 ld hl,drvtbl
343 ld b,0
344 add hl,bc
345 add hl,bc
346 ld a,(hl) ;get table entry for selected disk
347 inc hl
348 ld h,(hl)
349 ld l,a
350 or h ;return zero, if no entry (no disk)
351 ret
352
353
354 home:
355 ld a,1 shl HOME_FUNC
356 out (22),a
357
358 ld bc,0 ; same as seek to track 0
359 settrk:
360 ld a,c
361 out (16),a
362 ld a,b
363 out (17),a
364 ret
365
366 setsec:
367 ld a,c
368 out (18),a
369 ret
370
371 setdma:
372 ld a,c
373 out (20),a
374 ld a,b
375 out (21),a
376 ret
377
378 read:
379 ld a,1 shl READ_FUNC
380 out (22),a
381 in a,(22)
382 and 1
383 ret
384
385 write:
386 ld a,c
387 and 3 ;mask write type
388 or 1 shl WRITE_FUNC
389 out (22),a
390 in a,(22)
391 and 1
392 ret
393
394 sectran:
395 ;translate sector bc using table at de, res into hl
396 ld h,b
397 ld l,c
398 ld a,d
399 or e
400 ret z
401 ex de,hl
402 add hl,bc
403 ld l,(hl)
404 ld h,0
405 ret
406
407 bcb: dw drvtbl
408 dw dirbuf
409 dw enddat
410
411 bootdsk:ds 1
412 bootspt:ds 1
413
414 .8080
415 endef
416
417 end
418