]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/bioskrnl.180
file reorg. move routines, that are mainly used in initialization to banked area
[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,?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 sp,bs$stack
133
134 call hwinit ; first time hardware initialisation
135
136 ld bc,16*256 + 0 ; initialize all 16 character devices
137 c$init$loop:
138 push bc
139 call ?cinit
140 pop bc
141 inc c
142 djnz c$init$loop
143
144 call ?init ; perform any additional system initialization
145 ; and print signon message
146
147 ld bc,16*256+0
148 ld hl,@dtbl ; init all 16 logical disk drives
149 d$init$loop:
150 push bc ; save remaining count and abs drive
151 ld e,(hl)
152 inc hl
153 ld d,(hl)
154 inc hl ; grab @drv entry
155 ld a,e
156 or d
157 jr z,d$init$next ; if null, no drive
158 push hl ; save @drv pointer
159 if 0
160 ex de,hl ; XDPH address in <HL>
161 dec hl
162 dec hl
163 ld b,(hl) ; get relative drive code
164 ld (@ADRV),bc ; save absolute and relative drive code
165 dec hl ; point to init pointer
166 ld d,(hl)
167 dec hl
168 ld e,(hl) ; get init pointer
169 ex de,hl
170 call ipchl ; call init routine
171 else
172 push de
173 pop ix
174 ld b,(ix-2)
175 ld (@ADRV),bc ; save absolute and relative drive code
176 ld l,(ix-4)
177 ld h,(ix-3) ; get init pointer
178 call ipchl ; call init routine
179 endif
180 pop hl ; recover @drv pointer
181 d$init$next:
182 pop bc ; recover counter and drive #
183 inc c
184 djnz d$init$loop ; and loop for each drive
185 jp boot$1
186
187 cseg ; following in resident memory
188
189 boot$1:
190 call set$jumps
191 call ?ldccp ; fetch CCP for first time
192 jp ccp
193
194
195 ; WBOOT
196 ; Entry for system restarts.
197
198 wboot:
199 ld sp,bs$stack
200 call set$jumps ; initialize page zero
201 call ?rlccp ; reload CCP
202 jp ccp ; then reset jmp vectors and exit to ccp
203
204
205 set$jumps:
206
207 if banked
208 ld a,1
209 call ?bnksl
210 endif
211
212 ld a,0C3h ; jp opcode
213 ld (0),a
214 ld (5),a ; set up jumps in page zero
215 ld hl,?wboot
216 ld (1),hl ; BIOS warm start entry
217 ld hl,(@MXTPA)
218 ld (6),hl ; BDOS system call entry
219 ret
220
221
222 ds bs$stack$size
223 bs$stack equ $
224
225
226 ; DEVTBL
227 ; Return address of character device table
228
229 devtbl:
230 ld hl,@ctbl
231 ret
232
233
234 ; GETDRV
235 ; Return address of drive table
236
237 getdrv:
238 ld hl,@dtbl
239 ret
240
241
242
243 ; CONOUT
244 ; Console Output. Send character in <C>
245 ; to all selected devices
246
247 conout:
248
249 ld hl,(@covec) ; fetch console output bit vector
250 jr out$scan
251
252
253 ; AUXOUT
254 ; Auxiliary Output. Send character in <C>
255 ; to all selected devices
256
257 auxout:
258 ld hl,(@aovec) ; fetch aux output bit vector
259 jr out$scan
260
261
262 ; LIST
263 ; List Output. Send character in <C>
264 ; to all selected devices.
265
266 list:
267 ld hl,(@lovec) ; fetch list output bit vector
268
269 out$scan:
270 ld b,0 ; start with device 0
271 co$next:
272 add hl,hl ; shift out next bit
273 jr nc,not$out$device
274 push hl ; save the vector
275 ; push bc ; save the count and character
276 ;not$out$ready:
277 ; call coster
278 ; or a
279 ; jr z,not$out$ready
280 ; pop bc
281 push bc ; restore and resave the character and device
282 call ?co ; if device selected, print it
283 pop bc ; recover count and character
284 pop hl ; recover the rest of the vector
285 not$out$device:
286 inc b ; next device number
287 ld a,h
288 or l ; see if any devices left
289 jr nz,co$next ; and go find them...
290 ret
291
292
293 ; CONOST
294 ; Console Output Status. Return true if
295 ; all selected console output devices
296 ; are ready.
297
298 conost:
299 ld hl,(@covec) ; get console output bit vector
300 jr ost$scan
301
302
303 ; AUXOST
304 ; Auxiliary Output Status. Return true if
305 ; all selected auxiliary output devices
306 ; are ready.
307
308 auxost:
309 ld hl,(@aovec) ; get aux output bit vector
310 jr ost$scan
311
312
313 ; LISTST
314 ; List Output Status. Return true if
315 ; all selected list output devices
316 ; are ready.
317
318 listst:
319 ld hl,(@lovec) ; get list output bit vector
320
321 ost$scan:
322 ld b,0 ; start with device 0
323 cos$next:
324 add hl,hl ; check next bit
325 push hl ; save the vector
326 push bc ; save the count
327 ld a,0FFh ; assume device ready
328 call c,coster ; check status for this device
329 pop bc ; recover count
330 pop hl ; recover bit vector
331 or a ; see if device ready
332 ret z ; if any not ready, return false
333 inc b ; drop device number
334 ld a,h
335 or l ; see if any more selected devices
336 jr nz,cos$next
337 or 0FFh ; all selected were ready, return true
338 ret
339
340 ; check for output device ready, including optional
341 ; xon/xoff support
342 coster:
343 ld l,b
344 ld h,0 ; make device code 16 bits
345 push hl ; save it in stack
346 add hl,hl
347 add hl,hl
348 add hl,hl ; create offset into device characteristics tbl
349 ld de,@ctbl+6
350 add hl,de ; make address of mode byte
351 ld a,(hl)
352 and mb$xon$xoff
353 pop hl ; recover console number in <HL>
354 jp z,?cost ; not a xon device, go get output status direct
355 ld de,xofflist
356 add hl,de ; make pointer to proper xon/xoff flag
357 call cist1 ; see if this keyboard has character
358 ld a,(hl)
359 call nz,ci1 ; get flag or read key if any
360 cp ctlq
361 jr nz,not$q ; if its a ctl-Q,
362 ld a,0FFh ; set the flag ready
363 not$q:
364 cp ctls
365 jr nz,not$s ; if its a ctl-S,
366 ld a,00h ; clear the flag
367 not$s:
368 ld (hl),a ; save the flag
369 call cost1 ; get the actual output status,
370 and (hl) ; and mask with ctl-Q/ctl-S flag
371 ret ; return this as the status
372
373 cist1: ; get input status with <BC> and <HL> saved
374 push bc
375 push hl
376 call ?cist
377 pop hl
378 pop bc
379 or a
380 ret
381
382 cost1: ; get output status, saving <BC> & <HL>
383 push bc
384 push hl
385 call ?cost
386 pop hl
387 pop bc
388 or a
389 ret
390
391 ci1: ; get input, saving <BC> & <HL>
392 push bc
393 push hl
394 call ?ci
395 pop hl
396 pop bc
397 ret
398
399
400 ; CONST
401 ; Console Input Status. Return true if
402 ; any selected console input device
403 ; has an available character.
404
405 const:
406 ld hl,(@civec) ; get console input bit vector
407 jr ist$scan
408
409
410 ; AUXIST
411 ; Auxiliary Input Status. Return true if
412 ; any selected auxiliary input device
413 ; has an available character.
414
415 auxist:
416 ld hl,(@aivec) ; get aux input bit vector
417
418 ist$scan:
419 ld b,0 ; start with device 0
420 cis$next:
421 add hl,hl ; check next bit
422 ld a,0 ; assume device not ready
423 call c,cist1 ; check status for this device
424 or a
425 ret nz ; if any ready, return true
426 inc b ; next device number
427 ld a,h
428 or l ; see if any more selected devices
429 jr nz,cis$next
430 xor a ; all selected were not ready, return false
431 ret
432
433
434 ; CONIN
435 ; Console Input. Return character from first
436 ; ready console input device.
437
438 conin:
439 ld hl,(@civec)
440 jr in$scan
441
442
443 ; AUXIN
444 ; Auxiliary Input. Return character from first
445 ; ready auxiliary input device.
446
447 auxin:
448 ld hl,(@aivec)
449
450 in$scan:
451 push hl ; save bit vector
452 ld b,0
453 ci$next:
454 add hl,hl ; shift out next bit
455 ld a,0 ; insure zero a (nonexistant device not ready).
456 call c,cist1 ; see if the device has a character
457 or a
458 jr nz,ci$rdy ; this device has a character
459 inc b ; else, next device
460 ld a,h
461 or l ; see if any more devices
462 jr nz,ci$next ; go look at them
463 pop hl ; recover bit vector
464 jr in$scan ; loop til we find a character
465
466 ci$rdy:
467 pop hl ; discard extra stack
468 jp ?ci
469
470
471 ;-------------------------------------------------------------------------------
472 ; Utility Subroutines
473
474
475 ipchl: ; vectored CALL point
476 jp (hl)
477
478
479
480 ; BNKSEL
481 ; Bank Select. Select CPU bank for further execution.
482
483 bnksel:
484 ld (@cbnk),a ; remember current bank
485 jp ?bank ; and go exit through users
486 ; physical bank select routine
487
488
489 xofflist:
490 db -1,-1,-1,-1,-1,-1,-1,-1 ; ctl-s clears to zero
491 db -1,-1,-1,-1,-1,-1,-1,-1
492
493 dseg ; following resides in banked memory
494
495 ; Disk I/O interface routines
496
497
498 ; SELDSK
499 ; Select Disk Drive. Drive code in <C>.
500 ; Invoke login procedure for drive
501 ; if this is first select. Return
502 ; address of disk parameter header
503 ; in <HL>
504
505 seldsk:
506 ld a,c ; save drive select code
507 ld (@adrv),a
508 ld b,0 ; create index from drive code
509 ld hl,@dtbl
510 add hl,bc ; get pointer to dispatch table
511 add hl,bc
512 ld a,(hl)
513 inc hl
514 ld h,(hl)
515 ld l,a ; point at disk descriptor
516 ld (@xdph),hl ; save descriptor pointer
517 or h
518 ret z ; if no entry in table, no disk
519
520 ld a,e ; examine login bit
521 and 1
522 ret nz
523
524 push ix
525 ld ix,(@xdph)
526 ld a,(ix-2)
527 ld (@RDRV),a ; get relative drive
528 ld l,(ix-6) ; get address of LOGIN routine
529 ld h,(ix-5)
530 ex (sp),ix
531 pop de
532 call ipchl ; call LOGIN
533 ld hl,(@xdph) ; recover DPH pointer
534 ret
535
536
537 ; HOME
538 ; Home selected drive. Treated as SETTRK(0).
539
540 home:
541 ld bc,0 ; same as set track zero
542
543
544 ; SETTRK
545 ; Set Track. Saves track address from <BC>
546 ; in @TRK for further operations.
547
548 settrk:
549 ld (@trk),bc
550 ret
551
552
553 ; SETSEC
554 ; Set Sector. Saves sector number from <BC>
555 ; in @sect for further operations.
556
557 setsec:
558 ld (@sect),bc
559 ret
560
561
562 ; SETDMA
563 ; Set Disk Memory Address. Saves DMA address
564 ; from <BC> in @DMA and sets @DBNK to @CBNK
565 ; so that further disk operations take place
566 ; in current bank.
567
568 setdma:
569 ld (@dma),bc
570
571 ld a,(@cbnk) ; default DMA bank is current bank
572 ; fall through to set DMA bank
573
574 ; SETBNK
575 ; Set Disk Memory Bank. Saves bank number
576 ; in @DBNK for future disk data
577 ; transfers.
578
579 setbnk:
580 ld (@dbnk),a
581 ret
582
583
584 ; SECTRN
585 ; Sector Translate. Indexes skew table in <DE>
586 ; with sector in <BC>. Returns physical sector
587 ; in <HL>. If no skew table (<DE>=0) then
588 ; returns physical=logical.
589
590 sectrn:
591 ld l,c
592 ld h,b
593 ld a,d
594 or e
595 ret z
596 ex de,hl
597 add hl,bc
598 ld l,(hl)
599 ld h,0
600 ret
601
602
603 ; READ
604 ; Read physical record from currently selected drive.
605 ; Finds address of proper read routine from
606 ; extended disk parameter header (XDPH).
607
608 read:
609 ld ix,(@xdph) ; get drive descriptor pointer
610 ld l,(ix-8) ; get read routine entry
611 ld h,(ix-7)
612 jp (hl)
613
614
615 ; WRITE
616 ; Write physical sector from currently selected drive.
617 ; Finds address of proper write routine from
618 ; extended disk parameter header (XDPH).
619
620 write:
621 ld ix,(@xdph) ; get drive descriptor pointer
622 ld l,(ix-10) ; get write routine entry
623 ld h,(ix- 9)
624 jp (hl)
625
626
627
628 ; MULTIO
629 ; Set multiple sector count. Saves passed count in
630 ; @CNT
631
632 multio:
633 ld (@cnt),a
634 ret
635
636
637 ; FLUSH
638 ; BIOS deblocking buffer flush. Not implemented.
639
640 flush:
641 xor a
642 ret ; return with no error
643
644
645 ; disk communication data items
646 ; do not change order. sd driver depends on this
647
648 @xdph: ds 2 ; pointer to currently selected drives dph
649 @adrv: ds 1 ; currently selected disk drive
650 @rdrv: ds 1 ; controller relative disk drive
651 @trk: ds 2 ; current track number
652 @sect: ds 2 ; current sector number
653 @dma: ds 2 ; current DMA address
654 @dbnk: db 0 ; bank for DMA operations
655 @cnt: db 0 ; record count for multisector transfer
656
657
658 cseg ; common memory
659
660 @cbnk: db 0 ; bank for processor operations
661
662
663 end