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