1 title 'Root module of relocatable BIOS for CP/M 3.0'
3 ; version 1.0 15 Sept 82
10 ; Digital Research, Inc
12 ; Pacific Grove, CA 93950
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
29 ccp equ 0100h ; Console Command Processor gets loaded
32 cseg ; GENCPM puts CSEG stuff in common memory
35 ; variables in system data page
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
43 extrn hwinit,?init ; general initialization and signon
44 extrn ?ldccp,?rlccp ; load & reload CCP for BOOT & WBOOT
46 ; user defined character I/O routines
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
52 ; disk communication data items
54 extrn @dtbl ; table of pointers to XDPHs
55 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
56 public @dma,@dbnk,@cnt ; '' '' '' ''
60 public @cbnk ; current bank
61 extrn ?xmove,?move ; select move bank, and block move
62 extrn ?bank ; select CPU bank
66 extrn ?time ; signal time operation
68 ; general utility routines
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)
75 include modebaud.inc ; define mode bits
78 ; External names for BIOS entry points
80 public ?boot,?wboot,?const,?conin,?cono,?list,?auxo,?auxi
81 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
83 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
84 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
91 ; All BIOS routines are invoked by calling these
94 ?boot: jp boot ; initial entry on cold start
95 ?wboot: jp wboot ; reentry on program exit, warm start
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
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)
112 ?lists: jp listst ; return list device status
113 ?sctrn: jp sectrn ; translate logical to physical sector
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
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
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
131 jp 0 ; reserved for future expansion
132 jp 0 ; reserved for future expansion
133 jp 0 ; reserved for future expansion
137 ; Initial entry point for system startup.
139 dseg ; this part can be banked
144 call hwinit ; first time hardware initialisation
146 ld c,15 ; initialize all 16 character devices
154 call ?init ; perform any additional system initialization
155 ; and print signon message
158 ld hl,@dtbl ; init all 16 logical disk drives
160 push bc ; save remaining count and abs drive
164 inc hl ; grab @drv entry
167 jr z,d$init$next ; if null, no drive
168 push hl ; save @drv pointer
170 ex de,hl ; XDPH address in <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
178 ld e,(hl) ; get init pointer
180 call ipchl ; call init routine
185 ld (@ADRV),bc ; save absolute and relative drive code
187 ld h,(ix-3) ; get init pointer
188 call ipchl ; call init routine
190 pop hl ; recover @drv pointer
192 pop bc ; recover counter and drive #
194 djnz d$init$loop ; and loop for each drive
197 cseg ; following in resident memory
201 call ?ldccp ; fetch CCP for first time
206 ; Entry for system restarts.
210 call set$jumps ; initialize page zero
211 call ?rlccp ; reload CCP
212 jp ccp ; then reset jmp vectors and exit to ccp
222 ld a,0C3h ; jp opcode
224 ld (5),a ; set up jumps in page zero
226 ld (1),hl ; BIOS warm start entry
228 ld (6),hl ; BDOS system call entry
237 ; Return address of character device table
245 ; Return address of drive table
254 ; Console Output. Send character in <C>
255 ; to all selected devices
259 ld hl,(@covec) ; fetch console output bit vector
264 ; Auxiliary Output. Send character in <C>
265 ; to all selected devices
268 ld hl,(@aovec) ; fetch aux output bit vector
273 ; List Output. Send character in <C>
274 ; to all selected devices.
277 ld hl,(@lovec) ; fetch list output bit vector
280 ld b,0 ; start with device 0
282 add hl,hl ; shift out next bit
284 push hl ; save the vector
285 push bc ; save the count and character
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
296 inc b ; next device number
298 or l ; see if any devices left
299 jr nz,co$next ; and go find them...
304 ; Console Output Status. Return true if
305 ; all selected console output devices
309 ld hl,(@covec) ; get console output bit vector
314 ; Auxiliary Output Status. Return true if
315 ; all selected auxiliary output devices
319 ld hl,(@aovec) ; get aux output bit vector
324 ; List Output Status. Return true if
325 ; all selected list output devices
329 ld hl,(@lovec) ; get list output bit vector
332 ld b,0 ; start with device 0
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
345 or l ; see if any more selected devices
347 or 0FFh ; all selected were ready, return true
350 coster: ; check for output device ready, including optional
353 ld h,0 ; make device code 16 bits
354 push hl ; save it in stack
357 add hl,hl ; create offset into device characteristics tbl
359 add hl,de ; make address of mode byte
362 pop hl ; recover console number in <HL>
363 jp z,?cost ; not a xon device, go get output status direct
365 add hl,de ; make pointer to proper xon/xoff flag
366 call cist1 ; see if this keyboard has character
368 call nz,ci1 ; get flag or read key if any
370 jr nz,not$q ; if its a ctl-Q,
371 ld a,0FFh ; set the flag ready
374 jr nz,not$s ; if its a ctl-S,
375 ld a,00h ; clear the flag
377 ld (hl),a ; save the flag
378 call cost1 ; get the actual output status,
379 and (hl) ; and mask with ctl-Q/ctl-S flag
380 ret ; return this as the status
382 cist1: ; get input status with <BC> and <HL> saved
391 cost1: ; get output status, saving <BC> & <HL>
400 ci1: ; get input, saving <BC> & <HL>
410 ; Console Input Status. Return true if
411 ; any selected console input device
412 ; has an available character.
415 ld hl,(@civec) ; get console input bit vector
420 ; Auxiliary Input Status. Return true if
421 ; any selected auxiliary input device
422 ; has an available character.
425 ld hl,(@aivec) ; get aux input bit vector
428 ld b,0 ; start with device 0
430 add hl,hl ; check next bit
431 ld a,0 ; assume device not ready
432 call c,cist1 ; check status for this device
434 ret nz ; if any ready, return true
435 inc b ; next device number
437 or l ; see if any more selected devices
439 xor a ; all selected were not ready, return false
444 ; Console Input. Return character from first
445 ; ready console input device.
453 ; Auxiliary Input. Return character from first
454 ; ready auxiliary input device.
460 push hl ; save bit vector
463 add hl,hl ; shift out next bit
464 ld a,0 ; insure zero a (nonexistant device not ready).
465 call c,cist1 ; see if the device has a character
467 jr nz,ci$rdy ; this device has a character
468 inc b ; else, next device
470 or l ; see if any more devices
471 jr nz,ci$next ; go look at them
472 pop hl ; recover bit vector
473 jr in$scan ; loop til we find a character
476 pop hl ; discard extra stack
480 ;-------------------------------------------------------------------------------
481 ; Utility Subroutines
484 ipchl: ; vectored CALL point
488 ;-------------------------------------------------------------------------------
489 ; print message @<HL> up to a null
510 ;-------------------------------------------------------------------------------
511 ; print message inline up to a null
512 ; saves all registers
522 ;-------------------------------------------------------------------------------
523 ; print hl as a 4 digit hexadecimal number
524 ; saves all registers
532 ;-------------------------------------------------------------------------------
533 ; print a as a 2 digit hexadecimal number
534 ; saves all registers
565 ;-------------------------------------------------------------------------------
567 ?pdec: ; print binary number 0-65535 from <HL>
601 dw -1000,-100,-10,-1,0
605 call ?pmsg ; error header
609 call ?cono ; drive code
611 call ?pmsg ; track header
613 call ?pdec ; track number
615 call ?pmsg ; sector header
617 call ?pdec ; sector number
622 ; Bank Select. Select CPU bank for further execution.
625 ld (@cbnk),a ; remember current bank
626 jp ?bank ; and go exit through users
627 ; physical bank select routine
631 db -1,-1,-1,-1,-1,-1,-1,-1 ; ctl-s clears to zero
632 db -1,-1,-1,-1,-1,-1,-1,-1
636 dseg ; following resides in banked memory
640 ; Disk I/O interface routines
644 ; Select Disk Drive. Drive code in <C>.
645 ; Invoke login procedure for drive
646 ; if this is first select. Return
647 ; address of disk parameter header
651 ld a,c ; save drive select code
653 ld b,0 ; create index from drive code
655 add hl,bc ; get pointer to dispatch table
660 ld l,a ; point at disk descriptor
661 ld (@xdph),hl ; save descriptor pointer
663 ret z ; if no entry in table, no disk
665 ld a,e ; examine login bit
672 ld (@RDRV),a ; get relative drive
673 ld l,(ix-6) ; get address of LOGIN routine
677 call ipchl ; call LOGIN
678 ld hl,(@xdph) ; recover DPH pointer
683 ; Home selected drive. Treated as SETTRK(0).
686 ld bc,0 ; same as set track zero
690 ; Set Track. Saves track address from <BC>
691 ; in @TRK for further operations.
699 ; Set Sector. Saves sector number from <BC>
700 ; in @sect for further operations.
708 ; Set Disk Memory Address. Saves DMA address
709 ; from <BC> in @DMA and sets @DBNK to @CBNK
710 ; so that further disk operations take place
716 ld a,(@cbnk) ; default DMA bank is current bank
717 ; fall through to set DMA bank
720 ; Set Disk Memory Bank. Saves bank number
721 ; in @DBNK for future disk data
730 ; Sector Translate. Indexes skew table in <DE>
731 ; with sector in <BC>. Returns physical sector
732 ; in <HL>. If no skew table (<DE>=0) then
733 ; returns physical=logical.
749 ; Read physical record from currently selected drive.
750 ; Finds address of proper read routine from
751 ; extended disk parameter header (XDPH).
754 ld ix,(@xdph) ; get drive descriptor pointer
755 ld l,(ix-8) ; get read routine entry
761 ; Write physical sector from currently selected drive.
762 ; Finds address of proper write routine from
763 ; extended disk parameter header (XDPH).
766 ld ix,(@xdph) ; get drive descriptor pointer
767 ld l,(ix-10) ; get write routine entry
774 ; Set multiple sector count. Saves passed count in
783 ; BIOS deblocking buffer flush. Not implemented.
787 ret ; return with no error
791 ; error message components
792 drive$msg: db cr,lf,bell,'BIOS Error on ',0
793 track$msg: db ': T-',0
794 sector$msg: db ', S-',0
797 ; disk communication data items
798 ; do not change order. sd driver depends on this
800 @xdph: ds 2 ; pointer to currently selected drives dph
801 @adrv: ds 1 ; currently selected disk drive
802 @rdrv: ds 1 ; controller relative disk drive
803 @cnt: db 0 ; record count for multisector transfer
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
812 @cbnk: db 0 ; bank for processor operations