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 ; check for output device ready, including optional
354 ld h,0 ; make device code 16 bits
355 push hl ; save it in stack
358 add hl,hl ; create offset into device characteristics tbl
360 add hl,de ; make address of mode byte
363 pop hl ; recover console number in <HL>
364 jp z,?cost ; not a xon device, go get output status direct
366 add hl,de ; make pointer to proper xon/xoff flag
367 call cist1 ; see if this keyboard has character
369 call nz,ci1 ; get flag or read key if any
371 jr nz,not$q ; if its a ctl-Q,
372 ld a,0FFh ; set the flag ready
375 jr nz,not$s ; if its a ctl-S,
376 ld a,00h ; clear the flag
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
383 cist1: ; get input status with <BC> and <HL> saved
392 cost1: ; get output status, saving <BC> & <HL>
401 ci1: ; get input, saving <BC> & <HL>
411 ; Console Input Status. Return true if
412 ; any selected console input device
413 ; has an available character.
416 ld hl,(@civec) ; get console input bit vector
421 ; Auxiliary Input Status. Return true if
422 ; any selected auxiliary input device
423 ; has an available character.
426 ld hl,(@aivec) ; get aux input bit vector
429 ld b,0 ; start with device 0
431 add hl,hl ; check next bit
432 ld a,0 ; assume device not ready
433 call c,cist1 ; check status for this device
435 ret nz ; if any ready, return true
436 inc b ; next device number
438 or l ; see if any more selected devices
440 xor a ; all selected were not ready, return false
445 ; Console Input. Return character from first
446 ; ready console input device.
454 ; Auxiliary Input. Return character from first
455 ; ready auxiliary input device.
461 push hl ; save bit vector
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
468 jr nz,ci$rdy ; this device has a character
469 inc b ; else, next device
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
477 pop hl ; discard extra stack
481 ;-------------------------------------------------------------------------------
482 ; Utility Subroutines
485 ipchl: ; vectored CALL point
489 ;-------------------------------------------------------------------------------
490 ; print message @<HL> up to a null
511 ;-------------------------------------------------------------------------------
512 ; print message inline up to a null
513 ; saves all registers
523 ;-------------------------------------------------------------------------------
524 ; print hl as a 4 digit hexadecimal number
525 ; saves all registers
533 ;-------------------------------------------------------------------------------
534 ; print a as a 2 digit hexadecimal number
535 ; saves all registers
566 ;-------------------------------------------------------------------------------
568 ?pdec: ; print binary number 0-65535 from <HL>
602 dw -1000,-100,-10,-1,0
606 call ?pmsg ; error header
610 call ?cono ; drive code
612 call ?pmsg ; track header
614 call ?pdec ; track number
616 call ?pmsg ; sector header
618 call ?pdec ; sector number
623 ; Bank Select. Select CPU bank for further execution.
626 ld (@cbnk),a ; remember current bank
627 jp ?bank ; and go exit through users
628 ; physical bank select routine
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
637 dseg ; following resides in banked memory
641 ; Disk I/O interface routines
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
652 ld a,c ; save drive select code
654 ld b,0 ; create index from drive code
656 add hl,bc ; get pointer to dispatch table
661 ld l,a ; point at disk descriptor
662 ld (@xdph),hl ; save descriptor pointer
664 ret z ; if no entry in table, no disk
666 ld a,e ; examine login bit
673 ld (@RDRV),a ; get relative drive
674 ld l,(ix-6) ; get address of LOGIN routine
678 call ipchl ; call LOGIN
679 ld hl,(@xdph) ; recover DPH pointer
684 ; Home selected drive. Treated as SETTRK(0).
687 ld bc,0 ; same as set track zero
691 ; Set Track. Saves track address from <BC>
692 ; in @TRK for further operations.
700 ; Set Sector. Saves sector number from <BC>
701 ; in @sect for further operations.
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
717 ld a,(@cbnk) ; default DMA bank is current bank
718 ; fall through to set DMA bank
721 ; Set Disk Memory Bank. Saves bank number
722 ; in @DBNK for future disk data
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.
750 ; Read physical record from currently selected drive.
751 ; Finds address of proper read routine from
752 ; extended disk parameter header (XDPH).
755 ld ix,(@xdph) ; get drive descriptor pointer
756 ld l,(ix-8) ; get read routine entry
762 ; Write physical sector from currently selected drive.
763 ; Finds address of proper write routine from
764 ; extended disk parameter header (XDPH).
767 ld ix,(@xdph) ; get drive descriptor pointer
768 ld l,(ix-10) ; get write routine entry
775 ; Set multiple sector count. Saves passed count in
784 ; BIOS deblocking buffer flush. Not implemented.
788 ret ; return with no error
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
798 ; disk communication data items
799 ; do not change order. sd driver depends on this
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
813 @cbnk: db 0 ; bank for processor operations