]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/bioskrnl.180
daa4610e69045b9a83866c5be1e9f24bbbd707b2
[z180-stamp-cpm3.git] / cbios / bioskrnl.180
1 title 'Root module of relocatable BIOS for CP/M 3.0'
2
3 ; version 1.0 15 Sept 82
4
5 include config.inc
6 include z180reg.inc
7
8
9 ; Copyright (C), 1982
10 ; Digital Research, Inc
11 ; P.O. Box 579
12 ; Pacific Grove, CA 93950
13
14
15 ; This is the invariant portion of the modular BIOS and is
16 ; distributed as source for informational purposes only.
17 ; All desired modifications should be performed by
18 ; adding or changing externally defined modules.
19 ; This allows producing "standard" I/O modules that
20 ; can be combined to support a particular system
21 ; configuration.
22
23 ctlQ equ 'Q'-'@'
24 ctlS equ 'S'-'@'
25
26 ccp equ 0100h ; Console Command Processor gets loaded
27 ; into the TPA
28
29 cseg ; GENCPM puts CSEG stuff in common memory
30
31
32 ; variables in system data page
33
34 extrn @covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
35 extrn @mxtpa ; addr of system entry point
36 extrn @bnkbf ; 128 byte scratch buffer
37
38 ; initialization
39
40 extrn hwinit,?init ; general initialization and signon
41 extrn ?ldccp,?rlccp ; load & reload CCP for BOOT & WBOOT
42
43 ; user defined character I/O routines
44
45 extrn ?ci,?co,?cist,?cost ; each take device in <B>
46 extrn ?cinit ; (re)initialize device in <C>
47 extrn @ctbl ; physical character device table
48
49 ; disk communication data items
50
51 extrn @dtbl ; table of pointers to XDPHs
52 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
53 public @dma,@dbnk,@cnt ; '' '' '' ''
54
55 ; memory control
56
57 public @cbnk ; current bank
58 extrn ?xmove,?move ; select move bank, and block move
59 extrn ?bank ; select CPU bank
60
61 ; clock support
62
63 extrn ?time ; signal time operation
64
65 include modebaud.inc ; define mode bits
66
67
68 ; External names for BIOS entry points
69
70 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
71 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
72 public ?lists,?sctrn
73 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
74 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
75
76 public bs$stack
77
78
79 ; BIOS Jump vector.
80
81 ; All BIOS routines are invoked by calling these
82 ; entry points.
83
84 ?boot: jp boot ; initial entry on cold start
85 ?wboot: jp wboot ; reentry on program exit, warm start
86
87 ?const: jp const ; return console input status
88 ?conin: jp conin ; return console input character
89 ?cono: jp conout ; send console output character
90 ?list: jp list ; send list output character
91 ?auxo: jp auxout ; send auxiliary output character
92 ?auxi: jp auxin ; return auxiliary input character
93
94 ?home: jp home ; set disks to logical home
95 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
96 ?sttrk: jp settrk ; set disk track
97 ?stsec: jp setsec ; set disk sector
98 ?stdma: jp setdma ; set disk I/O memory address
99 ?read: jp read ; read physical block(s)
100 ?write: jp write ; write physical block(s)
101
102 ?lists: jp listst ; return list device status
103 ?sctrn: jp sectrn ; translate logical to physical sector
104
105 ?conos: jp conost ; return console output status
106 ?auxis: jp auxist ; return aux input status
107 ?auxos: jp auxost ; return aux output status
108 ?dvtbl: jp devtbl ; return address of device def table
109 ?devin: jp ?cinit ; change baud rate of device
110
111 ?drtbl: jp getdrv ; return address of disk drive table
112 ?mltio: jp multio ; set multiple record count for disk I/O
113 ?flush: jp flush ; flush BIOS maintained disk caching
114
115 ?mov: jp ?move ; block move memory to memory
116 ?tim: jp ?time ; Signal Time and Date operation
117 ?bnksl: jp bnksel ; select bank for code execution and default DMA
118 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
119 ?xmov: jp ?xmove ; set source and destination banks for one operation
120
121 jp 0 ; reserved for future expansion
122 jp 0 ; reserved for future expansion
123 jp 0 ; reserved for future expansion
124
125
126 ; BOOT
127 ; Initial entry point for system startup.
128
129 dseg ; this part can be banked
130
131 boot:
132 ld a,SYS$CBR
133 out0 (cbr),a
134 ld a,USR$CBAR
135 out0 (cbar),a
136 ld sp,bs$stack
137
138 call hwinit ; first time hardware initialisation
139
140 ld bc,16*256 + 0 ; initialize all 16 character devices
141 c$init$loop:
142 push bc
143 call ?cinit
144 pop bc
145 inc c
146 djnz c$init$loop
147
148 call ?init ; perform any additional system initialization
149 ; and print signon message
150
151 ld bc,16*256+0
152 ld hl,@dtbl ; init all 16 logical disk drives
153 d$init$loop:
154 push bc ; save remaining count and abs drive
155 ld e,(hl)
156 inc hl
157 ld d,(hl)
158 inc hl ; grab @drv entry
159 ld a,e
160 or d
161 jr z,d$init$next ; if null, no drive
162 push hl ; save @drv pointer
163 push de
164 pop ix ; XDPH address in <DE>
165 ld b,(ix-2)
166 ld (@ADRV),bc ; save absolute and relative drive code
167 ld l,(ix-4)
168 ld h,(ix-3) ; get init pointer
169 call ipchl ; call init routine
170 pop hl ; recover @drv pointer
171 d$init$next:
172 pop bc ; recover counter and drive #
173 inc c
174 djnz d$init$loop ; and loop for each drive
175 jp boot$1
176
177 cseg ; following in resident memory
178
179 boot$1:
180 call set$jumps
181 call ?ldccp ; fetch CCP for first time
182 jp ccp
183
184
185 ; WBOOT
186 ; Entry for system restarts.
187
188 wboot:
189 ld sp,bs$stack
190 call set$jumps ; initialize page zero
191 call ?rlccp ; reload CCP
192 jp ccp ; then reset jmp vectors and exit to ccp
193
194
195 set$jumps:
196
197 if banked
198 ld a,1
199 call ?bnksl
200 endif
201
202 ld a,0C3h ; jp opcode
203 ld (0),a
204 ld (5),a ; set up jumps in page zero
205 ld hl,?wboot
206 ld (1),hl ; BIOS warm start entry
207 ld hl,(@MXTPA)
208 ld (6),hl ; BDOS system call entry
209 ret
210
211
212 ds bs$stack$size
213 bs$stack equ $
214
215
216 ; DEVTBL
217 ; Return address of character device table
218
219 devtbl:
220 ld hl,@ctbl
221 ret
222
223
224 ; GETDRV
225 ; Return address of drive table
226
227 getdrv:
228 ld hl,@dtbl
229 ret
230
231
232
233 ; LIST
234 ; List Output. Send character in <C>
235 ; to all selected devices.
236
237 list:
238 ld hl,(@lovec) ; fetch list output bit vector
239 jr out$scan
240
241
242 ; AUXOUT
243 ; Auxiliary Output. Send character in <C>
244 ; to all selected devices
245
246 auxout:
247 ld hl,(@aovec) ; fetch aux output bit vector
248 jr out$scan
249
250
251 ; CONOUT
252 ; Console Output. Send character in <C>
253 ; to all selected devices
254
255 conout:
256
257 ld hl,(@covec) ; fetch console output bit vector
258
259 out$scan:
260 ld b,0 ; start with device 0
261 co$next:
262 add hl,hl ; shift out next bit
263 jr nc,not$out$device
264 push hl ; save the vector
265 push bc ; save device num and the character
266 call ?co ; if device selected, print it
267 pop bc ; recover count and character
268 pop hl ; recover the rest of the vector
269 not$out$device:
270 inc b ; next device number
271 ld a,h
272 or l ; see if any devices left
273 jr nz,co$next ; and go find them...
274 ret
275
276
277 ; LISTST
278 ; List Output Status. Return true if
279 ; all selected list output devices
280 ; are ready.
281
282 listst:
283 ld hl,(@lovec) ; get list output bit vector
284 jr ost$scan
285
286
287 ; AUXOST
288 ; Auxiliary Output Status. Return true if
289 ; all selected auxiliary output devices
290 ; are ready.
291
292 auxost:
293 ld hl,(@aovec) ; get aux output bit vector
294 jr ost$scan
295
296
297 ; CONOST
298 ; Console Output Status. Return true if
299 ; all selected console output devices
300 ; are ready.
301
302 conost:
303 ld hl,(@covec) ; get console output bit vector
304
305 ost$scan:
306 ld b,0 ; start with device 0
307 cos$next:
308 add hl,hl ; check next bit
309 push hl ; save the vector
310 push bc ; save the count
311 ld a,0FFh ; assume device ready
312 call c,?cost ; check status for this device
313 pop bc ; recover count
314 pop hl ; recover bit vector
315 or a ; see if device ready
316 ret z ; if any not ready, return false
317 inc b ; drop device number
318 ld a,h
319 or l ; see if any more selected devices
320 jr nz,cos$next
321 or 0FFh ; all selected were ready, return true
322 ret
323
324
325 cist1: ; get input status with <BC> and <HL> saved
326 push bc
327 push hl
328 call ?cist
329 pop hl
330 pop bc
331 or a
332 ret
333
334
335 ; AUXIST
336 ; Auxiliary Input Status. Return true if
337 ; any selected auxiliary input device
338 ; has an available character.
339
340 auxist:
341 ld hl,(@aivec) ; get aux input bit vector
342 jr ist$scan
343
344
345 ; CONST
346 ; Console Input Status. Return true if
347 ; any selected console input device
348 ; has an available character.
349
350 const:
351 ld hl,(@civec) ; get console input bit vector
352
353 ist$scan:
354 ld b,0 ; start with device 0
355 cis$next:
356 xor a ; assume next device not ready
357 add hl,hl ; check next bit (lets z flag unaffected)
358 call c,cist1 ; check status for this device
359 ret nz ; if any ready, return true
360 inc b ; next device number
361 ld a,h
362 or l ; see if any more selected devices
363 ret z ; all selected were not ready, return false
364 jr cis$next
365
366
367 ; AUXIN
368 ; Auxiliary Input. Return character from first
369 ; ready auxiliary input device.
370
371 auxin:
372 ld hl,(@aivec)
373 jr in$scan
374
375
376 ; CONIN
377 ; Console Input. Return character from first
378 ; ready console input device.
379
380 conin:
381 ld hl,(@civec)
382
383 in$scan:
384 push hl ; save bit vector
385 ld b,0
386 ci$next:
387 xor a ; assume next device not ready
388 add hl,hl ; shift out next bit
389 call c,cist1 ; see if the device has a character
390 jr nz,ci$rdy ; this device has a character
391 inc b ; else, next device
392 ld a,h
393 or l ; see if any more devices
394 jr nz,ci$next ; go look at them
395 pop hl ; recover bit vector
396 jr in$scan ; loop til we find a character
397
398 ci$rdy:
399 pop hl ; discard extra stack
400 jp ?ci
401
402
403 ;-------------------------------------------------------------------------------
404 ; Utility Subroutines
405
406
407 ipchl: ; vectored CALL point
408 jp (hl)
409
410
411
412 ; BNKSEL
413 ; Bank Select. Select CPU bank for further execution.
414
415 bnksel:
416 ld (@cbnk),a ; remember current bank
417 jp ?bank ; and go exit through users
418 ; physical bank select routine
419
420 dseg ; following resides in banked memory
421
422 ; Disk I/O interface routines
423
424
425 ; SELDSK
426 ; Select Disk Drive. Drive code in <C>.
427 ; Invoke login procedure for drive
428 ; if this is first select. Return
429 ; address of disk parameter header
430 ; in <HL>
431
432 seldsk:
433 ld a,c ; save drive select code
434 ld (@adrv),a
435 ld b,0 ; create index from drive code
436 ld hl,@dtbl
437 add hl,bc ; get pointer to dispatch table
438 add hl,bc
439 ld a,(hl)
440 inc hl
441 ld h,(hl)
442 ld l,a ; point at disk descriptor
443 ld (@xdph),hl ; save descriptor pointer
444 or h
445 ret z ; if no entry in table, no disk
446
447 bit 0,e ; login bit to zero flag
448 ex de,hl
449 ld hl,-2 ; get relative drive
450 add hl,de
451 ld a,(hl)
452 ld (@RDRV),a
453 jr nz,notfirst ; examine login bit
454 ld hl,-6
455 add hl,de
456 ld a,(hl)
457 inc hl
458 ld h,(hl)
459 ld l,a
460 call ipchl ; call LOGIN
461 notfirst:
462 ld hl,(@xdph) ; recover DPH pointer
463 ret
464
465
466 ; HOME
467 ; Home selected drive. Treated as SETTRK(0).
468
469 home:
470 ld bc,0 ; same as set track zero
471
472
473 ; SETTRK
474 ; Set Track. Saves track address from <BC>
475 ; in @TRK for further operations.
476
477 settrk:
478 ld (@trk),bc
479 ret
480
481
482 ; SETSEC
483 ; Set Sector. Saves sector number from <BC>
484 ; in @sect for further operations.
485
486 setsec:
487 ld (@sect),bc
488 ret
489
490
491 ; SETDMA
492 ; Set Disk Memory Address. Saves DMA address
493 ; from <BC> in @DMA and sets @DBNK to @CBNK
494 ; so that further disk operations take place
495 ; in current bank.
496
497 setdma:
498 ld (@dma),bc
499
500 ld a,(@cbnk) ; default DMA bank is current bank
501 ; fall through to set DMA bank
502
503 ; SETBNK
504 ; Set Disk Memory Bank. Saves bank number
505 ; in @DBNK for future disk data
506 ; transfers.
507
508 setbnk:
509 ld (@dbnk),a
510 ret
511
512
513 ; SECTRN
514 ; Sector Translate. Indexes skew table in <DE>
515 ; with sector in <BC>. Returns physical sector
516 ; in <HL>. If no skew table (<DE>=0) then
517 ; returns physical=logical.
518
519 sectrn:
520 ld l,c
521 ld h,b
522 ld a,d
523 or e
524 ret z
525 ex de,hl
526 add hl,bc
527 ld l,(hl)
528 ld h,0
529 ret
530
531
532 ; READ
533 ; Read physical record from currently selected drive.
534 ; Finds address of proper read routine from
535 ; extended disk parameter header (XDPH).
536
537 read:
538 ld ix,(@xdph) ; get drive descriptor pointer
539 ld l,(ix-8) ; get read routine entry
540 ld h,(ix-7)
541 jp (hl)
542
543
544 ; WRITE
545 ; Write physical sector from currently selected drive.
546 ; Finds address of proper write routine from
547 ; extended disk parameter header (XDPH).
548
549 write:
550 ld ix,(@xdph) ; get drive descriptor pointer
551 ld l,(ix-10) ; get write routine entry
552 ld h,(ix- 9)
553 jp (hl)
554
555
556
557 ; MULTIO
558 ; Set multiple sector count. Saves passed count in
559 ; @CNT
560
561 multio:
562 ld (@cnt),a
563 ret
564
565
566 ; FLUSH
567 ; BIOS deblocking buffer flush. Not implemented.
568
569 flush:
570 xor a
571 ret ; return with no error
572
573
574 ; disk communication data items
575 ; do not change order. sd driver depends on this
576
577 @xdph: ds 2 ; pointer to currently selected drives dph
578 @adrv: ds 1 ; currently selected disk drive
579 @rdrv: ds 1 ; controller relative disk drive
580 @trk: ds 2 ; current track number
581 @sect: ds 2 ; current sector number
582 @dma: ds 2 ; current DMA address
583 @dbnk: db 0 ; bank for DMA operations
584 @cnt: db 0 ; record count for multisector transfer
585
586
587 cseg ; common memory
588
589 @cbnk: db 0 ; bank for processor operations
590
591
592 end