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