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 device num and the character
266 call ?co ; if device selected, print it
267 pop bc ; recover count and character
268 pop hl ; recover the rest of the vector
270 inc b ; next device number
272 or l ; see if any devices left
273 jr nz,co$next ; and go find them...
278 ; List Output Status. Return true if
279 ; all selected list output devices
283 ld hl,(@lovec) ; get list output bit vector
288 ; Auxiliary Output Status. Return true if
289 ; all selected auxiliary output devices
293 ld hl,(@aovec) ; get aux output bit vector
298 ; Console Output Status. Return true if
299 ; all selected console output devices
303 ld hl,(@covec) ; get console output bit vector
306 ld b,0 ; start with device 0
308 add hl,hl ; check next bit
309 push hl ; save the vector
310 push bc ; save the count
311 ld a,0FFh ; assume device ready
312 call c,?cost ; check status for this device
313 pop bc ; recover count
314 pop hl ; recover bit vector
315 or a ; see if device ready
316 ret z ; if any not ready, return false
317 inc b ; drop device number
319 or l ; see if any more selected devices
321 or 0FFh ; all selected were ready, return true
325 cist1: ; get input status with <BC> and <HL> saved
336 ; Auxiliary Input Status. Return true if
337 ; any selected auxiliary input device
338 ; has an available character.
341 ld hl,(@aivec) ; get aux input bit vector
346 ; Console Input Status. Return true if
347 ; any selected console input device
348 ; has an available character.
351 ld hl,(@civec) ; get console input bit vector
354 ld b,0 ; start with device 0
356 xor a ; assume next device not ready
357 add hl,hl ; check next bit (lets z flag unaffected)
358 call c,cist1 ; check status for this device
359 ret nz ; if any ready, return true
360 inc b ; next device number
362 or l ; see if any more selected devices
363 ret z ; all selected were not ready, return false
368 ; Auxiliary Input. Return character from first
369 ; ready auxiliary input device.
377 ; Console Input. Return character from first
378 ; ready console input device.
384 push hl ; save bit vector
387 xor a ; assume next device not ready
388 add hl,hl ; shift out next bit
389 call c,cist1 ; see if the device has a character
390 jr nz,ci$rdy ; this device has a character
391 inc b ; else, next device
393 or l ; see if any more devices
394 jr nz,ci$next ; go look at them
395 pop hl ; recover bit vector
396 jr in$scan ; loop til we find a character
399 pop hl ; discard extra stack
403 ;-------------------------------------------------------------------------------
404 ; Utility Subroutines
407 ipchl: ; vectored CALL point
413 ; Bank Select. Select CPU bank for further execution.
416 ld (@cbnk),a ; remember current bank
417 jp ?bank ; and go exit through users
418 ; physical bank select routine
420 dseg ; following resides in banked memory
422 ; Disk I/O interface routines
426 ; Select Disk Drive. Drive code in <C>.
427 ; Invoke login procedure for drive
428 ; if this is first select. Return
429 ; address of disk parameter header
433 ld a,c ; save drive select code
435 ld b,0 ; create index from drive code
437 add hl,bc ; get pointer to dispatch table
442 ld l,a ; point at disk descriptor
443 ld (@xdph),hl ; save descriptor pointer
445 ret z ; if no entry in table, no disk
447 bit 0,e ; login bit to zero flag
449 ld hl,-2 ; get relative drive
453 jr nz,notfirst ; examine login bit
460 call ipchl ; call LOGIN
462 ld hl,(@xdph) ; recover DPH pointer
467 ; Home selected drive. Treated as SETTRK(0).
470 ld bc,0 ; same as set track zero
474 ; Set Track. Saves track address from <BC>
475 ; in @TRK for further operations.
483 ; Set Sector. Saves sector number from <BC>
484 ; in @sect for further operations.
492 ; Set Disk Memory Address. Saves DMA address
493 ; from <BC> in @DMA and sets @DBNK to @CBNK
494 ; so that further disk operations take place
500 ld a,(@cbnk) ; default DMA bank is current bank
501 ; fall through to set DMA bank
504 ; Set Disk Memory Bank. Saves bank number
505 ; in @DBNK for future disk data
514 ; Sector Translate. Indexes skew table in <DE>
515 ; with sector in <BC>. Returns physical sector
516 ; in <HL>. If no skew table (<DE>=0) then
517 ; returns physical=logical.
533 ; Read physical record from currently selected drive.
534 ; Finds address of proper read routine from
535 ; extended disk parameter header (XDPH).
538 ld ix,(@xdph) ; get drive descriptor pointer
539 ld l,(ix-8) ; get read routine entry
545 ; Write physical sector from currently selected drive.
546 ; Finds address of proper write routine from
547 ; extended disk parameter header (XDPH).
550 ld ix,(@xdph) ; get drive descriptor pointer
551 ld l,(ix-10) ; get write routine entry
558 ; Set multiple sector count. Saves passed count in
567 ; BIOS deblocking buffer flush. Not implemented.
571 ret ; return with no error
574 ; disk communication data items
575 ; do not change order. sd driver depends on this
577 @xdph: ds 2 ; pointer to currently selected drives dph
578 @adrv: ds 1 ; currently selected disk drive
579 @rdrv: ds 1 ; controller relative disk drive
580 @trk: ds 2 ; current track number
581 @sect: ds 2 ; current sector number
582 @dma: ds 2 ; current DMA address
583 @dbnk: db 0 ; bank for DMA operations
584 @cnt: db 0 ; record count for multisector transfer
589 @cbnk: db 0 ; bank for processor operations