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,?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
134 call hwinit ; first time hardware initialisation
136 ld bc,16*256 + 0 ; initialize all 16 character devices
144 call ?init ; perform any additional system initialization
145 ; and print signon message
148 ld hl,@dtbl ; init all 16 logical disk drives
150 push bc ; save remaining count and abs drive
154 inc hl ; grab @drv entry
157 jr z,d$init$next ; if null, no drive
158 push hl ; save @drv pointer
160 ex de,hl ; XDPH address in <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
168 ld e,(hl) ; get init pointer
170 call ipchl ; call init routine
175 ld (@ADRV),bc ; save absolute and relative drive code
177 ld h,(ix-3) ; get init pointer
178 call ipchl ; call init routine
180 pop hl ; recover @drv pointer
182 pop bc ; recover counter and drive #
184 djnz d$init$loop ; and loop for each drive
187 cseg ; following in resident memory
191 call ?ldccp ; fetch CCP for first time
196 ; Entry for system restarts.
200 call set$jumps ; initialize page zero
201 call ?rlccp ; reload CCP
202 jp ccp ; then reset jmp vectors and exit to ccp
212 ld a,0C3h ; jp opcode
214 ld (5),a ; set up jumps in page zero
216 ld (1),hl ; BIOS warm start entry
218 ld (6),hl ; BDOS system call entry
227 ; Return address of character device table
235 ; Return address of drive table
244 ; Console Output. Send character in <C>
245 ; to all selected devices
249 ld hl,(@covec) ; fetch console output bit vector
254 ; Auxiliary Output. Send character in <C>
255 ; to all selected devices
258 ld hl,(@aovec) ; fetch aux output bit vector
263 ; List Output. Send character in <C>
264 ; to all selected devices.
267 ld hl,(@lovec) ; fetch list output bit vector
270 ld b,0 ; start with device 0
272 add hl,hl ; shift out next bit
274 push hl ; save the vector
275 ; push bc ; save the count and character
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
286 inc b ; next device number
288 or l ; see if any devices left
289 jr nz,co$next ; and go find them...
294 ; Console Output Status. Return true if
295 ; all selected console output devices
299 ld hl,(@covec) ; get console output bit vector
304 ; Auxiliary Output Status. Return true if
305 ; all selected auxiliary output devices
309 ld hl,(@aovec) ; get aux output bit vector
314 ; List Output Status. Return true if
315 ; all selected list output devices
319 ld hl,(@lovec) ; get list output bit vector
322 ld b,0 ; start with device 0
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
335 or l ; see if any more selected devices
337 or 0FFh ; all selected were ready, return true
340 ; check for output device ready, including optional
344 ld h,0 ; make device code 16 bits
345 push hl ; save it in stack
348 add hl,hl ; create offset into device characteristics tbl
350 add hl,de ; make address of mode byte
353 pop hl ; recover console number in <HL>
354 jp z,?cost ; not a xon device, go get output status direct
356 add hl,de ; make pointer to proper xon/xoff flag
357 call cist1 ; see if this keyboard has character
359 call nz,ci1 ; get flag or read key if any
361 jr nz,not$q ; if its a ctl-Q,
362 ld a,0FFh ; set the flag ready
365 jr nz,not$s ; if its a ctl-S,
366 ld a,00h ; clear the flag
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
373 cist1: ; get input status with <BC> and <HL> saved
382 cost1: ; get output status, saving <BC> & <HL>
391 ci1: ; get input, saving <BC> & <HL>
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
411 ; Auxiliary Input Status. Return true if
412 ; any selected auxiliary input device
413 ; has an available character.
416 ld hl,(@aivec) ; get aux input bit vector
419 ld b,0 ; start with device 0
421 add hl,hl ; check next bit
422 ld a,0 ; assume device not ready
423 call c,cist1 ; check status for this device
425 ret nz ; if any ready, return true
426 inc b ; next device number
428 or l ; see if any more selected devices
430 xor a ; all selected were not ready, return false
435 ; Console Input. Return character from first
436 ; ready console input device.
444 ; Auxiliary Input. Return character from first
445 ; ready auxiliary input device.
451 push hl ; save bit vector
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
458 jr nz,ci$rdy ; this device has a character
459 inc b ; else, next device
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
467 pop hl ; discard extra stack
471 ;-------------------------------------------------------------------------------
472 ; Utility Subroutines
475 ipchl: ; vectored CALL point
481 ; Bank Select. Select CPU bank for further execution.
484 ld (@cbnk),a ; remember current bank
485 jp ?bank ; and go exit through users
486 ; physical bank select routine
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
493 dseg ; following resides in banked memory
495 ; Disk I/O interface routines
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
506 ld a,c ; save drive select code
508 ld b,0 ; create index from drive code
510 add hl,bc ; get pointer to dispatch table
515 ld l,a ; point at disk descriptor
516 ld (@xdph),hl ; save descriptor pointer
518 ret z ; if no entry in table, no disk
520 ld a,e ; examine login bit
527 ld (@RDRV),a ; get relative drive
528 ld l,(ix-6) ; get address of LOGIN routine
532 call ipchl ; call LOGIN
533 ld hl,(@xdph) ; recover DPH pointer
538 ; Home selected drive. Treated as SETTRK(0).
541 ld bc,0 ; same as set track zero
545 ; Set Track. Saves track address from <BC>
546 ; in @TRK for further operations.
554 ; Set Sector. Saves sector number from <BC>
555 ; in @sect for further operations.
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
571 ld a,(@cbnk) ; default DMA bank is current bank
572 ; fall through to set DMA bank
575 ; Set Disk Memory Bank. Saves bank number
576 ; in @DBNK for future disk data
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.
604 ; Read physical record from currently selected drive.
605 ; Finds address of proper read routine from
606 ; extended disk parameter header (XDPH).
609 ld ix,(@xdph) ; get drive descriptor pointer
610 ld l,(ix-8) ; get read routine entry
616 ; Write physical sector from currently selected drive.
617 ; Finds address of proper write routine from
618 ; extended disk parameter header (XDPH).
621 ld ix,(@xdph) ; get drive descriptor pointer
622 ld l,(ix-10) ; get write routine entry
629 ; Set multiple sector count. Saves passed count in
638 ; BIOS deblocking buffer flush. Not implemented.
642 ret ; return with no error
645 ; disk communication data items
646 ; do not change order. sd driver depends on this
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
660 @cbnk: db 0 ; bank for processor operations