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