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
26 ccp equ 0100h ; Console Command Processor gets loaded
29 cseg ; GENCPM puts CSEG stuff in common memory
32 ; variables in system data page
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
40 extrn hwinit,?init ; general initialization and signon
41 extrn ?ldccp,?rlccp ; load & reload CCP for BOOT & WBOOT
43 ; user defined character I/O routines
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
49 ; disk communication data items
51 extrn @dtbl ; table of pointers to XDPHs
52 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
53 public @dma,@dbnk,@cnt ; '' '' '' ''
57 public @cbnk ; current bank
58 extrn ?xmove,?move ; select move bank, and block move
59 extrn ?bank ; select CPU bank
63 extrn ?time ; signal time operation
65 include modebaud.inc ; define mode bits
68 ; External names for BIOS entry points
70 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
71 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
73 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
74 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
81 ; All BIOS routines are invoked by calling these
84 ?boot: jp boot ; initial entry on cold start
85 ?wboot: jp wboot ; reentry on program exit, warm start
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
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)
102 ?lists: jp listst ; return list device status
103 ?sctrn: jp sectrn ; translate logical to physical sector
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
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
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
121 jp 0 ; reserved for future expansion
122 jp 0 ; reserved for future expansion
123 jp 0 ; reserved for future expansion
127 ; Initial entry point for system startup.
129 dseg ; this part can be banked
138 call hwinit ; first time hardware initialisation
140 ld bc,16*256 + 0 ; initialize all 16 character devices
148 call ?init ; perform any additional system initialization
149 ; and print signon message
152 ld hl,@dtbl ; init all 16 logical disk drives
154 push bc ; save remaining count and abs drive
158 inc hl ; grab @drv entry
161 jr z,d$init$next ; if null, no drive
162 push hl ; save @drv pointer
164 pop ix ; XDPH address in <DE>
166 ld (@ADRV),bc ; save absolute and relative drive code
168 ld h,(ix-3) ; get init pointer
169 call ipchl ; call init routine
170 pop hl ; recover @drv pointer
172 pop bc ; recover counter and drive #
174 djnz d$init$loop ; and loop for each drive
177 cseg ; following in resident memory
181 call ?ldccp ; fetch CCP for first time
186 ; Entry for system restarts.
190 call set$jumps ; initialize page zero
191 call ?rlccp ; reload CCP
192 jp ccp ; then reset jmp vectors and exit to ccp
202 ld a,0C3h ; jp opcode
204 ld (5),a ; set up jumps in page zero
206 ld (1),hl ; BIOS warm start entry
208 ld (6),hl ; BDOS system call entry
217 ; Return address of character device table
225 ; Return address of drive table
234 ; List Output. Send character in <C>
235 ; to all selected devices.
238 ld hl,(@lovec) ; fetch list output bit vector
243 ; Auxiliary Output. Send character in <C>
244 ; to all selected devices
247 ld hl,(@aovec) ; fetch aux output bit vector
252 ; Console Output. Send character in <C>
253 ; to all selected devices
257 ld hl,(@covec) ; fetch console output bit vector
260 ld b,0 ; start with device 0
262 add hl,hl ; shift out next bit
264 push hl ; save the vector
265 ; push bc ; save the count and character
271 push bc ; restore and resave the character and device
272 call ?co ; if device selected, print it
273 pop bc ; recover count and character
274 pop hl ; recover the rest of the vector
276 inc b ; next device number
278 or l ; see if any devices left
279 jr nz,co$next ; and go find them...
284 ; List Output Status. Return true if
285 ; all selected list output devices
289 ld hl,(@lovec) ; get list output bit vector
294 ; Auxiliary Output Status. Return true if
295 ; all selected auxiliary output devices
299 ld hl,(@aovec) ; get aux output bit vector
304 ; Console Output Status. Return true if
305 ; all selected console output devices
309 ld hl,(@covec) ; get console output bit vector
312 ld b,0 ; start with device 0
314 add hl,hl ; check next bit
315 push hl ; save the vector
316 push bc ; save the count
317 ld a,0FFh ; assume device ready
318 call c,coster ; check status for this device
319 pop bc ; recover count
320 pop hl ; recover bit vector
321 or a ; see if device ready
322 ret z ; if any not ready, return false
323 inc b ; drop device number
325 or l ; see if any more selected devices
327 or 0FFh ; all selected were ready, return true
330 ; check for output device ready, including optional
334 ld h,0 ; make device code 16 bits
335 push hl ; save it in stack
338 add hl,hl ; create offset into device characteristics tbl
340 add hl,de ; make address of mode byte
343 pop hl ; recover console number in <HL>
344 jp z,?cost ; not a xon device, go get output status direct
346 add hl,de ; make pointer to proper xon/xoff flag
347 call cist1 ; see if this keyboard has character
349 call nz,ci1 ; get flag or read key if any
351 jr nz,not$q ; if its a ctl-Q,
352 ld a,0FFh ; set the flag ready
355 jr nz,not$s ; if its a ctl-S,
356 ld a,00h ; clear the flag
358 ld (hl),a ; save the flag
359 call cost1 ; get the actual output status,
360 and (hl) ; and mask with ctl-Q/ctl-S flag
361 ret ; return this as the status
363 cist1: ; get input status with <BC> and <HL> saved
372 cost1: ; get output status, saving <BC> & <HL>
381 ci1: ; get input, saving <BC> & <HL>
391 ; Auxiliary Input Status. Return true if
392 ; any selected auxiliary input device
393 ; has an available character.
396 ld hl,(@aivec) ; get aux input bit vector
401 ; Console Input Status. Return true if
402 ; any selected console input device
403 ; has an available character.
406 ld hl,(@civec) ; get console input bit vector
409 ld b,0 ; start with device 0
411 add hl,hl ; check next bit
412 ld a,0 ; assume device not ready
413 call c,cist1 ; check status for this device
415 ret nz ; if any ready, return true
416 inc b ; next device number
418 or l ; see if any more selected devices
420 xor a ; all selected were not ready, return false
425 ; Auxiliary Input. Return character from first
426 ; ready auxiliary input device.
434 ; Console Input. Return character from first
435 ; ready console input device.
441 push hl ; save bit vector
444 add hl,hl ; shift out next bit
445 ld a,0 ; insure zero a (nonexistant device not ready).
446 call c,cist1 ; see if the device has a character
448 jr nz,ci$rdy ; this device has a character
449 inc b ; else, next device
451 or l ; see if any more devices
452 jr nz,ci$next ; go look at them
453 pop hl ; recover bit vector
454 jr in$scan ; loop til we find a character
457 pop hl ; discard extra stack
461 ;-------------------------------------------------------------------------------
462 ; Utility Subroutines
465 ipchl: ; vectored CALL point
471 ; Bank Select. Select CPU bank for further execution.
474 ld (@cbnk),a ; remember current bank
475 jp ?bank ; and go exit through users
476 ; physical bank select routine
480 db -1,-1,-1,-1,-1,-1,-1,-1 ; ctl-s clears to zero
481 db -1,-1,-1,-1,-1,-1,-1,-1
483 dseg ; following resides in banked memory
485 ; Disk I/O interface routines
489 ; Select Disk Drive. Drive code in <C>.
490 ; Invoke login procedure for drive
491 ; if this is first select. Return
492 ; address of disk parameter header
496 ld a,c ; save drive select code
498 ld b,0 ; create index from drive code
500 add hl,bc ; get pointer to dispatch table
505 ld l,a ; point at disk descriptor
506 ld (@xdph),hl ; save descriptor pointer
508 ret z ; if no entry in table, no disk
510 ld a,e ; examine login bit
517 ld (@RDRV),a ; get relative drive
518 ld l,(ix-6) ; get address of LOGIN routine
522 call ipchl ; call LOGIN
523 ld hl,(@xdph) ; recover DPH pointer
528 ; Home selected drive. Treated as SETTRK(0).
531 ld bc,0 ; same as set track zero
535 ; Set Track. Saves track address from <BC>
536 ; in @TRK for further operations.
544 ; Set Sector. Saves sector number from <BC>
545 ; in @sect for further operations.
553 ; Set Disk Memory Address. Saves DMA address
554 ; from <BC> in @DMA and sets @DBNK to @CBNK
555 ; so that further disk operations take place
561 ld a,(@cbnk) ; default DMA bank is current bank
562 ; fall through to set DMA bank
565 ; Set Disk Memory Bank. Saves bank number
566 ; in @DBNK for future disk data
575 ; Sector Translate. Indexes skew table in <DE>
576 ; with sector in <BC>. Returns physical sector
577 ; in <HL>. If no skew table (<DE>=0) then
578 ; returns physical=logical.
594 ; Read physical record from currently selected drive.
595 ; Finds address of proper read routine from
596 ; extended disk parameter header (XDPH).
599 ld ix,(@xdph) ; get drive descriptor pointer
600 ld l,(ix-8) ; get read routine entry
606 ; Write physical sector from currently selected drive.
607 ; Finds address of proper write routine from
608 ; extended disk parameter header (XDPH).
611 ld ix,(@xdph) ; get drive descriptor pointer
612 ld l,(ix-10) ; get write routine entry
619 ; Set multiple sector count. Saves passed count in
628 ; BIOS deblocking buffer flush. Not implemented.
632 ret ; return with no error
635 ; disk communication data items
636 ; do not change order. sd driver depends on this
638 @xdph: ds 2 ; pointer to currently selected drives dph
639 @adrv: ds 1 ; currently selected disk drive
640 @rdrv: ds 1 ; controller relative disk drive
641 @trk: ds 2 ; current track number
642 @sect: ds 2 ; current sector number
643 @dma: ds 2 ; current DMA address
644 @dbnk: db 0 ; bank for DMA operations
645 @cnt: db 0 ; record count for multisector transfer
650 @cbnk: db 0 ; bank for processor operations