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