]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/bioskrnl.180
disable mulit sector i/0 because it triggers a bug
[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 cr equ 13
24 lf equ 10
25 bell equ 7
26 ctlQ equ 'Q'-'@'
27 ctlS equ 'S'-'@'
28
29 ccp equ 0100h ; Console Command Processor gets loaded
30 ; into the TPA
31
32 cseg ; GENCPM puts CSEG stuff in common memory
33
34
35 ; variables in system data page
36
37 extrn @covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
38 extrn @mxtpa ; addr of system entry point
39 extrn @bnkbf ; 128 byte scratch buffer
40
41 ; initialization
42
43 extrn hwinit,?init ; general initialization and signon
44 extrn ?ldccp,?rlccp ; load & reload CCP for BOOT & WBOOT
45
46 ; user defined character I/O routines
47
48 extrn ?ci,?co,?cist,?cost ; each take device in <B>
49 extrn ?cinit ; (re)initialize device in <C>
50 extrn @ctbl ; physical character device table
51
52 ; disk communication data items
53
54 extrn @dtbl ; table of pointers to XDPHs
55 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
56 public @dma,@dbnk,@cnt ; '' '' '' ''
57
58 ; memory control
59
60 public @cbnk ; current bank
61 extrn ?xmove,?move ; select move bank, and block move
62 extrn ?bank ; select CPU bank
63
64 ; clock support
65
66 extrn ?time ; signal time operation
67
68 ; general utility routines
69
70 public ?pmsg,?pdec ; print message, print number from 0 to 65535
71 public ?pderr ; print BIOS disk error message header
72 public pmsg.in ; print message inline
73 public phex4,phex2 ; print 4 digit hex (HL), or 2 digit hex (A)
74
75 include modebaud.inc ; define mode bits
76
77
78 ; External names for BIOS entry points
79
80 public ?boot,?wboot,?const,?conin,?cono,?list,?auxo,?auxi
81 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
82 public ?lists,?sctrn
83 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
84 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
85
86 public bs$stack
87
88
89 ; BIOS Jump vector.
90
91 ; All BIOS routines are invoked by calling these
92 ; entry points.
93
94 ?boot: jp boot ; initial entry on cold start
95 ?wboot: jp wboot ; reentry on program exit, warm start
96
97 ?const: jp const ; return console input status
98 ?conin: jp conin ; return console input character
99 ?cono: jp conout ; send console output character
100 ?list: jp list ; send list output character
101 ?auxo: jp auxout ; send auxiliary output character
102 ?auxi: jp auxin ; return auxiliary input character
103
104 ?home: jp home ; set disks to logical home
105 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
106 ?sttrk: jp settrk ; set disk track
107 ?stsec: jp setsec ; set disk sector
108 ?stdma: jp setdma ; set disk I/O memory address
109 ?read: jp read ; read physical block(s)
110 ?write: jp write ; write physical block(s)
111
112 ?lists: jp listst ; return list device status
113 ?sctrn: jp sectrn ; translate logical to physical sector
114
115 ?conos: jp conost ; return console output status
116 ?auxis: jp auxist ; return aux input status
117 ?auxos: jp auxost ; return aux output status
118 ?dvtbl: jp devtbl ; return address of device def table
119 ?devin: jp ?cinit ; change baud rate of device
120
121 ?drtbl: jp getdrv ; return address of disk drive table
122 ?mltio: jp multio ; set multiple record count for disk I/O
123 ?flush: jp flush ; flush BIOS maintained disk caching
124
125 ?mov: jp ?move ; block move memory to memory
126 ?tim: jp ?time ; Signal Time and Date operation
127 ?bnksl: jp bnksel ; select bank for code execution and default DMA
128 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
129 ?xmov: jp ?xmove ; set source and destination banks for one operation
130
131 jp 0 ; reserved for future expansion
132 jp 0 ; reserved for future expansion
133 jp 0 ; reserved for future expansion
134
135
136 ; BOOT
137 ; Initial entry point for system startup.
138
139 dseg ; this part can be banked
140
141 boot:
142 ld sp,bs$stack
143
144 call hwinit ; first time hardware initialisation
145
146 ld c,15 ; initialize all 16 character devices
147 c$init$loop:
148 push bc
149 call ?cinit
150 pop bc
151 dec c
152 jp p,c$init$loop
153
154 call ?init ; perform any additional system initialization
155 ; and print signon message
156
157 ld bc,16*256+0
158 ld hl,@dtbl ; init all 16 logical disk drives
159 d$init$loop:
160 push bc ; save remaining count and abs drive
161 ld e,(hl)
162 inc hl
163 ld d,(hl)
164 inc hl ; grab @drv entry
165 ld a,e
166 or d
167 jr z,d$init$next ; if null, no drive
168 push hl ; save @drv pointer
169 if 0
170 ex de,hl ; XDPH address in <HL>
171 dec hl
172 dec hl
173 ld b,(hl) ; get relative drive code
174 ld (@ADRV),bc ; save absolute and relative drive code
175 dec hl ; point to init pointer
176 ld d,(hl)
177 dec hl
178 ld e,(hl) ; get init pointer
179 ex de,hl
180 call ipchl ; call init routine
181 else
182 push de
183 pop ix
184 ld b,(ix-2)
185 ld (@ADRV),bc ; save absolute and relative drive code
186 ld l,(ix-4)
187 ld h,(ix-3) ; get init pointer
188 call ipchl ; call init routine
189 endif
190 pop hl ; recover @drv pointer
191 d$init$next:
192 pop bc ; recover counter and drive #
193 inc c
194 djnz d$init$loop ; and loop for each drive
195 jp boot$1
196
197 cseg ; following in resident memory
198
199 boot$1:
200 call set$jumps
201 call ?ldccp ; fetch CCP for first time
202 jp ccp
203
204
205 ; WBOOT
206 ; Entry for system restarts.
207
208 wboot:
209 ld sp,bs$stack
210 call set$jumps ; initialize page zero
211 call ?rlccp ; reload CCP
212 jp ccp ; then reset jmp vectors and exit to ccp
213
214
215 set$jumps:
216
217 if banked
218 ld a,1
219 call ?bnksl
220 endif
221
222 ld a,0C3h ; jp opcode
223 ld (0),a
224 ld (5),a ; set up jumps in page zero
225 ld hl,?wboot
226 ld (1),hl ; BIOS warm start entry
227 ld hl,(@MXTPA)
228 ld (6),hl ; BDOS system call entry
229 ret
230
231
232 ds 64
233 bs$stack equ $
234
235
236 ; DEVTBL
237 ; Return address of character device table
238
239 devtbl:
240 ld hl,@ctbl
241 ret
242
243
244 ; GETDRV
245 ; Return address of drive table
246
247 getdrv:
248 ld hl,@dtbl
249 ret
250
251
252
253 ; CONOUT
254 ; Console Output. Send character in <C>
255 ; to all selected devices
256
257 conout:
258
259 ld hl,(@covec) ; fetch console output bit vector
260 jr out$scan
261
262
263 ; AUXOUT
264 ; Auxiliary Output. Send character in <C>
265 ; to all selected devices
266
267 auxout:
268 ld hl,(@aovec) ; fetch aux output bit vector
269 jr out$scan
270
271
272 ; LIST
273 ; List Output. Send character in <C>
274 ; to all selected devices.
275
276 list:
277 ld hl,(@lovec) ; fetch list output bit vector
278
279 out$scan:
280 ld b,0 ; start with device 0
281 co$next:
282 add hl,hl ; shift out next bit
283 jr nc,not$out$device
284 push hl ; save the vector
285 push bc ; save the count and character
286 not$out$ready:
287 call coster
288 or a
289 jp z,not$out$ready
290 pop bc
291 push bc ; restore and resave the character and device
292 call ?co ; if device selected, print it
293 pop bc ; recover count and character
294 pop hl ; recover the rest of the vector
295 not$out$device:
296 inc b ; next device number
297 ld a,h
298 or l ; see if any devices left
299 jr nz,co$next ; and go find them...
300 ret
301
302
303 ; CONOST
304 ; Console Output Status. Return true if
305 ; all selected console output devices
306 ; are ready.
307
308 conost:
309 ld hl,(@covec) ; get console output bit vector
310 jr ost$scan
311
312
313 ; AUXOST
314 ; Auxiliary Output Status. Return true if
315 ; all selected auxiliary output devices
316 ; are ready.
317
318 auxost:
319 ld hl,(@aovec) ; get aux output bit vector
320 jr ost$scan
321
322
323 ; LISTST
324 ; List Output Status. Return true if
325 ; all selected list output devices
326 ; are ready.
327
328 listst:
329 ld hl,(@lovec) ; get list output bit vector
330
331 ost$scan:
332 ld b,0 ; start with device 0
333 cos$next:
334 add hl,hl ; check next bit
335 push hl ; save the vector
336 push bc ; save the count
337 ld a,0FFh ; assume device ready
338 call c,coster ; check status for this device
339 pop bc ; recover count
340 pop hl ; recover bit vector
341 or a ; see if device ready
342 ret z ; if any not ready, return false
343 inc b ; drop device number
344 ld a,h
345 or l ; see if any more selected devices
346 jr nz,cos$next
347 or 0FFh ; all selected were ready, return true
348 ret
349
350 ; check for output device ready, including optional
351 ; xon/xoff support
352 coster:
353 ld l,b
354 ld h,0 ; make device code 16 bits
355 push hl ; save it in stack
356 add hl,hl
357 add hl,hl
358 add hl,hl ; create offset into device characteristics tbl
359 ld de,@ctbl+6
360 add hl,de ; make address of mode byte
361 ld a,(hl)
362 and mb$xon$xoff
363 pop hl ; recover console number in <HL>
364 jp z,?cost ; not a xon device, go get output status direct
365 ld de,xofflist
366 add hl,de ; make pointer to proper xon/xoff flag
367 call cist1 ; see if this keyboard has character
368 ld a,(hl)
369 call nz,ci1 ; get flag or read key if any
370 cp ctlq
371 jr nz,not$q ; if its a ctl-Q,
372 ld a,0FFh ; set the flag ready
373 not$q:
374 cp ctls
375 jr nz,not$s ; if its a ctl-S,
376 ld a,00h ; clear the flag
377 not$s:
378 ld (hl),a ; save the flag
379 call cost1 ; get the actual output status,
380 and (hl) ; and mask with ctl-Q/ctl-S flag
381 ret ; return this as the status
382
383 cist1: ; get input status with <BC> and <HL> saved
384 push bc
385 push hl
386 call ?cist
387 pop hl
388 pop bc
389 or a
390 ret
391
392 cost1: ; get output status, saving <BC> & <HL>
393 push bc
394 push hl
395 call ?cost
396 pop hl
397 pop bc
398 or a
399 ret
400
401 ci1: ; get input, saving <BC> & <HL>
402 push bc
403 push hl
404 call ?ci
405 pop hl
406 pop bc
407 ret
408
409
410 ; CONST
411 ; Console Input Status. Return true if
412 ; any selected console input device
413 ; has an available character.
414
415 const:
416 ld hl,(@civec) ; get console input bit vector
417 jr ist$scan
418
419
420 ; AUXIST
421 ; Auxiliary Input Status. Return true if
422 ; any selected auxiliary input device
423 ; has an available character.
424
425 auxist:
426 ld hl,(@aivec) ; get aux input bit vector
427
428 ist$scan:
429 ld b,0 ; start with device 0
430 cis$next:
431 add hl,hl ; check next bit
432 ld a,0 ; assume device not ready
433 call c,cist1 ; check status for this device
434 or a
435 ret nz ; if any ready, return true
436 inc b ; next device number
437 ld a,h
438 or l ; see if any more selected devices
439 jr nz,cis$next
440 xor a ; all selected were not ready, return false
441 ret
442
443
444 ; CONIN
445 ; Console Input. Return character from first
446 ; ready console input device.
447
448 conin:
449 ld hl,(@civec)
450 jr in$scan
451
452
453 ; AUXIN
454 ; Auxiliary Input. Return character from first
455 ; ready auxiliary input device.
456
457 auxin:
458 ld hl,(@aivec)
459
460 in$scan:
461 push hl ; save bit vector
462 ld b,0
463 ci$next:
464 add hl,hl ; shift out next bit
465 ld a,0 ; insure zero a (nonexistant device not ready).
466 call c,cist1 ; see if the device has a character
467 or a
468 jr nz,ci$rdy ; this device has a character
469 inc b ; else, next device
470 ld a,h
471 or l ; see if any more devices
472 jr nz,ci$next ; go look at them
473 pop hl ; recover bit vector
474 jr in$scan ; loop til we find a character
475
476 ci$rdy:
477 pop hl ; discard extra stack
478 jp ?ci
479
480
481 ;-------------------------------------------------------------------------------
482 ; Utility Subroutines
483
484
485 ipchl: ; vectored CALL point
486 jp (hl)
487
488
489 ;-------------------------------------------------------------------------------
490 ; print message @<HL> up to a null
491 ; saves <BC> & <DE>
492
493 ?pmsg:
494 push bc
495 push de
496 pmsg$loop:
497 ld a,(hl)
498 or a
499 jr z,pmsg$exit
500 ld c,a
501 push hl
502 call ?cono
503 pop hl
504 inc hl
505 jr pmsg$loop
506 pmsg$exit:
507 pop de
508 pop bc
509 ret
510
511 ;-------------------------------------------------------------------------------
512 ; print message inline up to a null
513 ; saves all registers
514
515 pmsg.in:
516 ex (sp),hl
517 push af
518 call ?pmsg
519 pop af
520 ex (sp),hl
521 ret
522
523 ;-------------------------------------------------------------------------------
524 ; print hl as a 4 digit hexadecimal number
525 ; saves all registers
526
527 phex4:
528 ld a,h
529 call phex2
530 ld a,l
531 ; fall thru
532
533 ;-------------------------------------------------------------------------------
534 ; print a as a 2 digit hexadecimal number
535 ; saves all registers
536
537 phex2:
538 push af
539 rra
540 rra
541 rra
542 rra
543 call print.digit
544 pop af
545
546 print.digit:
547 push hl
548 push de
549 push bc
550 push af
551 and 00fh
552 cp 10
553 jr c,prd_1
554 add a,007h
555 prd_1:
556 add a,'0'
557
558 ld c,a
559 call ?cono
560 pop af
561 pop bc
562 pop de
563 pop hl
564 ret
565
566 ;-------------------------------------------------------------------------------
567
568 ?pdec: ; print binary number 0-65535 from <HL>
569 ld bc,table10
570 ld de,-10000
571 next:
572 ld a,'0'-1
573 pdecl:
574 push hl
575 inc a
576 add hl,de
577 jp nc,stoploop
578 inc sp
579 inc sp
580 jp pdecl
581 stoploop:
582 push de
583 push bc
584 ld c,a
585 call ?cono
586 pop bc
587 pop de
588 nextdigit:
589 pop hl
590 ld a,(bc)
591 ld e,a
592 inc bc
593 ld a,(bc)
594 ld d,a
595 inc bc
596 ld a,e
597 or d
598 jp nz,next
599 ret
600
601 table10:
602 dw -1000,-100,-10,-1,0
603
604 ?pderr:
605 ld hl,drive$msg
606 call ?pmsg ; error header
607 ld a,(@adrv)
608 add a,'A'
609 ld c,a
610 call ?cono ; drive code
611 ld hl,track$msg
612 call ?pmsg ; track header
613 ld hl,(@trk)
614 call ?pdec ; track number
615 ld hl,sector$msg
616 call ?pmsg ; sector header
617 ld hl,(@sect)
618 call ?pdec ; sector number
619 ret
620
621
622 ; BNKSEL
623 ; Bank Select. Select CPU bank for further execution.
624
625 bnksel:
626 ld (@cbnk),a ; remember current bank
627 jp ?bank ; and go exit through users
628 ; physical bank select routine
629
630
631 xofflist:
632 db -1,-1,-1,-1,-1,-1,-1,-1 ; ctl-s clears to zero
633 db -1,-1,-1,-1,-1,-1,-1,-1
634
635
636
637 dseg ; following resides in banked memory
638
639
640
641 ; Disk I/O interface routines
642
643
644 ; SELDSK
645 ; Select Disk Drive. Drive code in <C>.
646 ; Invoke login procedure for drive
647 ; if this is first select. Return
648 ; address of disk parameter header
649 ; in <HL>
650
651 seldsk:
652 ld a,c ; save drive select code
653 ld (@adrv),a
654 ld b,0 ; create index from drive code
655 ld hl,@dtbl
656 add hl,bc ; get pointer to dispatch table
657 add hl,bc
658 ld a,(hl)
659 inc hl
660 ld h,(hl)
661 ld l,a ; point at disk descriptor
662 ld (@xdph),hl ; save descriptor pointer
663 or h
664 ret z ; if no entry in table, no disk
665
666 ld a,e ; examine login bit
667 and 1
668 ret nz
669
670 push ix
671 ld ix,(@xdph)
672 ld a,(ix-2)
673 ld (@RDRV),a ; get relative drive
674 ld l,(ix-6) ; get address of LOGIN routine
675 ld h,(ix-5)
676 ex (sp),ix
677 pop de
678 call ipchl ; call LOGIN
679 ld hl,(@xdph) ; recover DPH pointer
680 ret
681
682
683 ; HOME
684 ; Home selected drive. Treated as SETTRK(0).
685
686 home:
687 ld bc,0 ; same as set track zero
688
689
690 ; SETTRK
691 ; Set Track. Saves track address from <BC>
692 ; in @TRK for further operations.
693
694 settrk:
695 ld (@trk),bc
696 ret
697
698
699 ; SETSEC
700 ; Set Sector. Saves sector number from <BC>
701 ; in @sect for further operations.
702
703 setsec:
704 ld (@sect),bc
705 ret
706
707
708 ; SETDMA
709 ; Set Disk Memory Address. Saves DMA address
710 ; from <BC> in @DMA and sets @DBNK to @CBNK
711 ; so that further disk operations take place
712 ; in current bank.
713
714 setdma:
715 ld (@dma),bc
716
717 ld a,(@cbnk) ; default DMA bank is current bank
718 ; fall through to set DMA bank
719
720 ; SETBNK
721 ; Set Disk Memory Bank. Saves bank number
722 ; in @DBNK for future disk data
723 ; transfers.
724
725 setbnk:
726 ld (@dbnk),a
727 ret
728
729
730 ; SECTRN
731 ; Sector Translate. Indexes skew table in <DE>
732 ; with sector in <BC>. Returns physical sector
733 ; in <HL>. If no skew table (<DE>=0) then
734 ; returns physical=logical.
735
736 sectrn:
737 ld l,c
738 ld h,b
739 ld a,d
740 or e
741 ret z
742 ex de,hl
743 add hl,bc
744 ld l,(hl)
745 ld h,0
746 ret
747
748
749 ; READ
750 ; Read physical record from currently selected drive.
751 ; Finds address of proper read routine from
752 ; extended disk parameter header (XDPH).
753
754 read:
755 ld ix,(@xdph) ; get drive descriptor pointer
756 ld l,(ix-8) ; get read routine entry
757 ld h,(ix-7)
758 jp (hl)
759
760
761 ; WRITE
762 ; Write physical sector from currently selected drive.
763 ; Finds address of proper write routine from
764 ; extended disk parameter header (XDPH).
765
766 write:
767 ld ix,(@xdph) ; get drive descriptor pointer
768 ld l,(ix-10) ; get write routine entry
769 ld h,(ix- 9)
770 jp (hl)
771
772
773
774 ; MULTIO
775 ; Set multiple sector count. Saves passed count in
776 ; @CNT
777
778 multio:
779 ld (@cnt),a
780 ret
781
782
783 ; FLUSH
784 ; BIOS deblocking buffer flush. Not implemented.
785
786 flush:
787 xor a
788 ret ; return with no error
789
790
791
792 ; error message components
793 drive$msg: db cr,lf,bell,'BIOS Error on ',0
794 track$msg: db ': T-',0
795 sector$msg: db ', S-',0
796
797
798 ; disk communication data items
799 ; do not change order. sd driver depends on this
800
801 @xdph: ds 2 ; pointer to currently selected drives dph
802 @adrv: ds 1 ; currently selected disk drive
803 @rdrv: ds 1 ; controller relative disk drive
804 @trk: ds 2 ; current track number
805 @sect: ds 2 ; current sector number
806 @dma: ds 2 ; current DMA address
807 @dbnk: db 0 ; bank for DMA operations
808 @cnt: db 0 ; record count for multisector transfer
809
810
811 cseg ; common memory
812
813 @cbnk: db 0 ; bank for processor operations
814
815
816 end