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>
48 extrn @ctbl ; physical character device table
50 ; disk communication data items
52 extrn @dtbl ; table of pointers to XDPHs
53 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
54 public @dma,@dbnk,@cnt ; '' '' '' ''
59 public @cbnk ; current bank
60 extrn ?xmove,?move ; select move bank, and block move
61 extrn ?bank ; select CPU bank
65 extrn ?time ; signal time operation
67 extrn ijphl ; vectored call
69 maclib modebaud.inc ; define mode bits
72 ; External names for BIOS entry points
74 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
75 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
77 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
78 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
85 ; All BIOS routines are invoked by calling these
88 ?boot: jp boot ; initial entry on cold start
89 ?wboot: jp wboot ; reentry on program exit, warm start
91 ?const: jp const ; return console input status
92 ?conin: jp conin ; return console input character
93 ?cono: jp conout ; send console output character
94 ?list: jp list ; send list output character
95 ?auxo: jp auxout ; send auxiliary output character
96 ?auxi: jp auxin ; return auxiliary input character
98 ?home: jp home ; set disks to logical home
99 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
100 ?sttrk: jp settrk ; set disk track
101 ?stsec: jp setsec ; set disk sector
102 ?stdma: jp setdma ; set disk I/O memory address
103 ?read: jp read ; read physical block(s)
104 ?write: jp write ; write physical block(s)
106 ?lists: jp listst ; return list device status
107 ?sctrn: jp sectrn ; translate logical to physical sector
109 ?conos: jp conost ; return console output status
110 ?auxis: jp auxist ; return aux input status
111 ?auxos: jp auxost ; return aux output status
112 ?dvtbl: jp devtbl ; return address of device def table
113 ?devin: jp ?cinit ; change baud rate of device
115 ?drtbl: jp getdrv ; return address of disk drive table
116 ?mltio: jp multio ; set multiple record count for disk I/O
117 ?flush: jp flush ; flush BIOS maintained disk caching
119 ?mov: jp ?move ; block move memory to memory
120 ?tim: jp ?time ; Signal Time and Date operation
121 ?bnksl: jp bnksel ; select bank for code execution and default DMA
122 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
123 ?xmov: jp ?xmove ; set source and destination banks for one operation
125 jp 0 ; reserved for system implementor
126 jp 0 ; reserved for future expansion
127 jp 0 ; reserved for future expansion
132 ; Initial entry point for system startup.
134 dseg ; this part can be banked
143 call hwinit ; first time hardware initialisation
145 ld bc,16*256 + 0 ; initialize all 16 character devices
153 call ?init ; perform any additional system initialization
154 ; and print signon message
157 ld hl,@dtbl ; init all 16 logical disk drives
159 push bc ; save remaining count and abs drive
163 inc hl ; grab @drv entry
166 jr z,d$init$next ; if null, no drive
167 push hl ; save @drv pointer
169 pop ix ; XDPH address in <DE>
171 ld (@ADRV),bc ; save absolute and relative drive code
173 ld h,(ix-3) ; get init pointer
174 call ijphl ; call init routine
175 pop hl ; recover @drv pointer
177 pop bc ; recover counter and drive #
179 djnz d$init$loop ; and loop for each drive
182 cseg ; following in resident memory
186 call ?ldccp ; fetch CCP for first time
191 ; Entry for system restarts.
195 call set$jumps ; initialize page zero
196 call ?rlccp ; reload CCP
197 jp ccp ; then reset jmp vectors and exit to ccp
207 ld a,0C3h ; jp opcode
209 ld (5),a ; set up jumps in page zero
211 ld (1),hl ; BIOS warm start entry
213 ld (6),hl ; BDOS system call entry
222 ; Return address of character device table
230 ; Return address of drive table
239 ; List Output. Send character in <C>
240 ; to all selected devices.
243 ld hl,(@lovec) ; fetch list output bit vector
248 ; Auxiliary Output. Send character in <C>
249 ; to all selected devices
252 ld hl,(@aovec) ; fetch aux output bit vector
257 ; Console Output. Send character in <C>
258 ; to all selected devices
262 ld hl,(@covec) ; fetch console output bit vector
265 ld b,0 ; start with device 0
267 add hl,hl ; shift out next bit
269 push hl ; save the vector
270 push bc ; save device num and the character
271 call ?co ; if device selected, print it
272 pop bc ; recover count and character
273 pop hl ; recover the rest of the vector
275 inc b ; next device number
277 or l ; see if any devices left
278 jr nz,co$next ; and go find them...
283 ; List Output Status. Return true if
284 ; all selected list output devices
288 ld hl,(@lovec) ; get list output bit vector
293 ; Auxiliary Output Status. Return true if
294 ; all selected auxiliary output devices
298 ld hl,(@aovec) ; get aux output bit vector
303 ; Console Output Status. Return true if
304 ; all selected console output devices
308 ld hl,(@covec) ; get console output bit vector
311 ld b,0 ; start with device 0
313 add hl,hl ; check next bit
314 push hl ; save the vector
315 push bc ; save the count
316 ld a,0FFh ; assume device ready
317 call c,?cost ; check status for this device
318 pop bc ; recover count
319 pop hl ; recover bit vector
320 or a ; see if device ready
321 ret z ; if any not ready, return false
322 inc b ; drop device number
324 or l ; see if any more selected devices
326 or 0FFh ; all selected were ready, return true
330 cist1: ; get input status with <BC> and <HL> saved
341 ; Auxiliary Input Status. Return true if
342 ; any selected auxiliary input device
343 ; has an available character.
346 ld hl,(@aivec) ; get aux input bit vector
351 ; Console Input Status. Return true if
352 ; any selected console input device
353 ; has an available character.
356 ld hl,(@civec) ; get console input bit vector
359 ld b,0 ; start with device 0
361 xor a ; assume next device not ready
362 add hl,hl ; check next bit (lets z flag unaffected)
363 call c,cist1 ; check status for this device
364 ret nz ; if any ready, return true
365 inc b ; next device number
367 or l ; see if any more selected devices
368 ret z ; all selected were not ready, return false
373 ; Auxiliary Input. Return character from first
374 ; ready auxiliary input device.
382 ; Console Input. Return character from first
383 ; ready console input device.
388 ;check if only one device assigned
390 push hl ; save bit vector
394 adc hl,hl ; shift out next bit
396 jr z,ci$rdy ; single device
400 inc b ; else, next device
402 or l ; see if any more devices
407 push hl ; save bit vector
410 xor a ; assume next device not ready
411 add hl,hl ; shift out next bit
413 call c,cist1 ; see if the device has a character
414 jr nz,ci$rdy ; this device has a character
415 inc b ; else, next device
417 or l ; see if any more devices
418 jr nz,ci$next ; go look at them
419 pop hl ; recover bit vector
420 jr in$scan ; loop til we find a character
423 pop hl ; discard extra stack
427 ;-------------------------------------------------------------------------------
428 ; Utility Subroutines
431 ; Bank Select. Select CPU bank for further execution.
434 ld (@cbnk),a ; remember current bank
435 jp ?bank ; and go exit through users
436 ; physical bank select routine
438 dseg ; following resides in banked memory
440 ; Disk I/O interface routines
444 ; Select Disk Drive. Drive code in <C>.
445 ; Invoke login procedure for drive
446 ; if this is first select. Return
447 ; address of disk parameter header
451 ld a,c ; save drive select code
456 ld b,a ; create index from drive code
458 add hl,bc ; get pointer to dispatch table
463 ld l,a ; point at disk descriptor
464 ld (@xdph),hl ; save descriptor pointer
466 ret z ; if no entry in table, no disk
468 bit 0,e ; login bit to zero flag
470 ld hl,-2 ; get relative drive
474 jr nz,notfirst ; examine login bit
481 call ijphl ; call LOGIN
482 ld hl,(@xdph) ; recover DPH pointer
487 ; Home selected drive. Treated as SETTRK(0).
490 ld bc,0 ; same as set track zero
494 ; Set Track. Saves track address from <BC>
495 ; in @TRK for further operations.
503 ; Set Sector. Saves sector number from <BC>
504 ; in @sect for further operations.
512 ; Set Disk Memory Address. Saves DMA address
513 ; from <BC> in @DMA and sets @DBNK to @CBNK
514 ; so that further disk operations take place
520 ld a,(@cbnk) ; default DMA bank is current bank
521 ; fall through to set DMA bank
524 ; Set Disk Memory Bank. Saves bank number
525 ; in @DBNK for future disk data
534 ; Sector Translate. Indexes skew table in <DE>
535 ; with sector in <BC>. Returns physical sector
536 ; in <HL>. If no skew table (<DE>=0) then
537 ; returns physical=logical.
553 ; Read physical record from currently selected drive.
554 ; Finds address of proper read routine from
555 ; extended disk parameter header (XDPH).
560 ld ix,(@xdph) ; get drive descriptor pointer
561 ld l,(ix-8) ; get read routine entry
567 ; Write physical sector from currently selected drive.
568 ; Finds address of proper write routine from
569 ; extended disk parameter header (XDPH).
574 ld ix,(@xdph) ; get drive descriptor pointer
575 ld l,(ix-10) ; get write routine entry
582 ; Set multiple sector count. Saves passed count in
591 ; BIOS deblocking buffer flush. Not implemented.
595 ret ; return with no error
598 ; disk communication data items
599 ; do not change order. sd driver depends on this
601 @xdph: ds 2 ; pointer to currently selected drives dph
602 @op ds 1 ; current disk operation 0:select, 1:read, 2 write
603 @adrv: ds 1 ; currently selected disk drive
604 @rdrv: ds 1 ; controller relative disk drive
605 @trk: ds 2 ; current track number
606 @sect: ds 2 ; current sector number
607 @dma: ds 2 ; current DMA address
608 @dbnk: db 0 ; bank for DMA operations
609 @cnt: db 0 ; record count for multisector transfer
614 @cbnk: db 0 ; bank for processor operations