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 pop ix ; XDPH address in <DE>
162 ld (@ADRV),bc ; save absolute and relative drive code
164 ld h,(ix-3) ; get init pointer
165 call ipchl ; call init routine
166 pop hl ; recover @drv pointer
168 pop bc ; recover counter and drive #
170 djnz d$init$loop ; and loop for each drive
173 cseg ; following in resident memory
177 call ?ldccp ; fetch CCP for first time
182 ; Entry for system restarts.
186 call set$jumps ; initialize page zero
187 call ?rlccp ; reload CCP
188 jp ccp ; then reset jmp vectors and exit to ccp
198 ld a,0C3h ; jp opcode
200 ld (5),a ; set up jumps in page zero
202 ld (1),hl ; BIOS warm start entry
204 ld (6),hl ; BDOS system call entry
213 ; Return address of character device table
221 ; Return address of drive table
230 ; List Output. Send character in <C>
231 ; to all selected devices.
234 ld hl,(@lovec) ; fetch list output bit vector
239 ; Auxiliary Output. Send character in <C>
240 ; to all selected devices
243 ld hl,(@aovec) ; fetch aux output bit vector
248 ; Console Output. Send character in <C>
249 ; to all selected devices
253 ld hl,(@covec) ; fetch console output bit vector
256 ld b,0 ; start with device 0
258 add hl,hl ; shift out next bit
260 push hl ; save the vector
261 ; push bc ; save the count and character
267 push bc ; restore and resave the character and device
268 call ?co ; if device selected, print it
269 pop bc ; recover count and character
270 pop hl ; recover the rest of the vector
272 inc b ; next device number
274 or l ; see if any devices left
275 jr nz,co$next ; and go find them...
280 ; List Output Status. Return true if
281 ; all selected list output devices
285 ld hl,(@lovec) ; get list output bit vector
290 ; Auxiliary Output Status. Return true if
291 ; all selected auxiliary output devices
295 ld hl,(@aovec) ; get aux output bit vector
300 ; Console Output Status. Return true if
301 ; all selected console output devices
305 ld hl,(@covec) ; get console output bit vector
308 ld b,0 ; start with device 0
310 add hl,hl ; check next bit
311 push hl ; save the vector
312 push bc ; save the count
313 ld a,0FFh ; assume device ready
314 call c,coster ; check status for this device
315 pop bc ; recover count
316 pop hl ; recover bit vector
317 or a ; see if device ready
318 ret z ; if any not ready, return false
319 inc b ; drop device number
321 or l ; see if any more selected devices
323 or 0FFh ; all selected were ready, return true
326 ; check for output device ready, including optional
330 ld h,0 ; make device code 16 bits
331 push hl ; save it in stack
334 add hl,hl ; create offset into device characteristics tbl
336 add hl,de ; make address of mode byte
339 pop hl ; recover console number in <HL>
340 jp z,?cost ; not a xon device, go get output status direct
342 add hl,de ; make pointer to proper xon/xoff flag
343 call cist1 ; see if this keyboard has character
345 call nz,ci1 ; get flag or read key if any
347 jr nz,not$q ; if its a ctl-Q,
348 ld a,0FFh ; set the flag ready
351 jr nz,not$s ; if its a ctl-S,
352 ld a,00h ; clear the flag
354 ld (hl),a ; save the flag
355 call cost1 ; get the actual output status,
356 and (hl) ; and mask with ctl-Q/ctl-S flag
357 ret ; return this as the status
359 cist1: ; get input status with <BC> and <HL> saved
368 cost1: ; get output status, saving <BC> & <HL>
377 ci1: ; get input, saving <BC> & <HL>
387 ; Auxiliary Input Status. Return true if
388 ; any selected auxiliary input device
389 ; has an available character.
392 ld hl,(@aivec) ; get aux input bit vector
397 ; Console Input Status. Return true if
398 ; any selected console input device
399 ; has an available character.
402 ld hl,(@civec) ; get console input bit vector
405 ld b,0 ; start with device 0
407 add hl,hl ; check next bit
408 ld a,0 ; assume device not ready
409 call c,cist1 ; check status for this device
411 ret nz ; if any ready, return true
412 inc b ; next device number
414 or l ; see if any more selected devices
416 xor a ; all selected were not ready, return false
421 ; Auxiliary Input. Return character from first
422 ; ready auxiliary input device.
430 ; Console Input. Return character from first
431 ; ready console input device.
437 push hl ; save bit vector
440 add hl,hl ; shift out next bit
441 ld a,0 ; insure zero a (nonexistant device not ready).
442 call c,cist1 ; see if the device has a character
444 jr nz,ci$rdy ; this device has a character
445 inc b ; else, next device
447 or l ; see if any more devices
448 jr nz,ci$next ; go look at them
449 pop hl ; recover bit vector
450 jr in$scan ; loop til we find a character
453 pop hl ; discard extra stack
457 ;-------------------------------------------------------------------------------
458 ; Utility Subroutines
461 ipchl: ; vectored CALL point
467 ; Bank Select. Select CPU bank for further execution.
470 ld (@cbnk),a ; remember current bank
471 jp ?bank ; and go exit through users
472 ; physical bank select routine
476 db -1,-1,-1,-1,-1,-1,-1,-1 ; ctl-s clears to zero
477 db -1,-1,-1,-1,-1,-1,-1,-1
479 dseg ; following resides in banked memory
481 ; Disk I/O interface routines
485 ; Select Disk Drive. Drive code in <C>.
486 ; Invoke login procedure for drive
487 ; if this is first select. Return
488 ; address of disk parameter header
492 ld a,c ; save drive select code
494 ld b,0 ; create index from drive code
496 add hl,bc ; get pointer to dispatch table
501 ld l,a ; point at disk descriptor
502 ld (@xdph),hl ; save descriptor pointer
504 ret z ; if no entry in table, no disk
506 ld a,e ; examine login bit
513 ld (@RDRV),a ; get relative drive
514 ld l,(ix-6) ; get address of LOGIN routine
518 call ipchl ; call LOGIN
519 ld hl,(@xdph) ; recover DPH pointer
524 ; Home selected drive. Treated as SETTRK(0).
527 ld bc,0 ; same as set track zero
531 ; Set Track. Saves track address from <BC>
532 ; in @TRK for further operations.
540 ; Set Sector. Saves sector number from <BC>
541 ; in @sect for further operations.
549 ; Set Disk Memory Address. Saves DMA address
550 ; from <BC> in @DMA and sets @DBNK to @CBNK
551 ; so that further disk operations take place
557 ld a,(@cbnk) ; default DMA bank is current bank
558 ; fall through to set DMA bank
561 ; Set Disk Memory Bank. Saves bank number
562 ; in @DBNK for future disk data
571 ; Sector Translate. Indexes skew table in <DE>
572 ; with sector in <BC>. Returns physical sector
573 ; in <HL>. If no skew table (<DE>=0) then
574 ; returns physical=logical.
590 ; Read physical record from currently selected drive.
591 ; Finds address of proper read routine from
592 ; extended disk parameter header (XDPH).
595 ld ix,(@xdph) ; get drive descriptor pointer
596 ld l,(ix-8) ; get read routine entry
602 ; Write physical sector from currently selected drive.
603 ; Finds address of proper write routine from
604 ; extended disk parameter header (XDPH).
607 ld ix,(@xdph) ; get drive descriptor pointer
608 ld l,(ix-10) ; get write routine entry
615 ; Set multiple sector count. Saves passed count in
624 ; BIOS deblocking buffer flush. Not implemented.
628 ret ; return with no error
631 ; disk communication data items
632 ; do not change order. sd driver depends on this
634 @xdph: ds 2 ; pointer to currently selected drives dph
635 @adrv: ds 1 ; currently selected disk drive
636 @rdrv: ds 1 ; controller relative disk drive
637 @trk: ds 2 ; current track number
638 @sect: ds 2 ; current sector number
639 @dma: ds 2 ; current DMA address
640 @dbnk: db 0 ; bank for DMA operations
641 @cnt: db 0 ; record count for multisector transfer
646 @cbnk: db 0 ; bank for processor operations