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 ; '' '' '' ''
58 public @cbnk ; current bank
59 extrn ?xmove,?move ; select move bank, and block move
60 extrn ?bank ; select CPU bank
64 extrn ?time ; signal time operation
66 include modebaud.inc ; define mode bits
69 ; External names for BIOS entry points
71 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
72 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
74 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
75 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
82 ; All BIOS routines are invoked by calling these
85 ?boot: jp boot ; initial entry on cold start
86 ?wboot: jp wboot ; reentry on program exit, warm start
88 ?const: jp const ; return console input status
89 ?conin: jp conin ; return console input character
90 ?cono: jp conout ; send console output character
91 ?list: jp list ; send list output character
92 ?auxo: jp auxout ; send auxiliary output character
93 ?auxi: jp auxin ; return auxiliary input character
95 ?home: jp home ; set disks to logical home
96 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
97 ?sttrk: jp settrk ; set disk track
98 ?stsec: jp setsec ; set disk sector
99 ?stdma: jp setdma ; set disk I/O memory address
100 ?read: jp read ; read physical block(s)
101 ?write: jp write ; write physical block(s)
103 ?lists: jp listst ; return list device status
104 ?sctrn: jp sectrn ; translate logical to physical sector
106 ?conos: jp conost ; return console output status
107 ?auxis: jp auxist ; return aux input status
108 ?auxos: jp auxost ; return aux output status
109 ?dvtbl: jp devtbl ; return address of device def table
110 ?devin: jp ?cinit ; change baud rate of device
112 ?drtbl: jp getdrv ; return address of disk drive table
113 ?mltio: jp multio ; set multiple record count for disk I/O
114 ?flush: jp flush ; flush BIOS maintained disk caching
116 ?mov: jp ?move ; block move memory to memory
117 ?tim: jp ?time ; Signal Time and Date operation
118 ?bnksl: jp bnksel ; select bank for code execution and default DMA
119 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
120 ?xmov: jp ?xmove ; set source and destination banks for one operation
122 jp 0 ; reserved for future expansion
123 jp 0 ; reserved for future expansion
124 jp 0 ; reserved for future expansion
128 ; Initial entry point for system startup.
130 dseg ; this part can be banked
139 call hwinit ; first time hardware initialisation
141 ld bc,16*256 + 0 ; initialize all 16 character devices
149 call ?init ; perform any additional system initialization
150 ; and print signon message
153 ld hl,@dtbl ; init all 16 logical disk drives
155 push bc ; save remaining count and abs drive
159 inc hl ; grab @drv entry
162 jr z,d$init$next ; if null, no drive
163 push hl ; save @drv pointer
165 pop ix ; XDPH address in <DE>
167 ld (@ADRV),bc ; save absolute and relative drive code
169 ld h,(ix-3) ; get init pointer
170 call ipchl ; call init routine
171 pop hl ; recover @drv pointer
173 pop bc ; recover counter and drive #
175 djnz d$init$loop ; and loop for each drive
178 cseg ; following in resident memory
182 call ?ldccp ; fetch CCP for first time
187 ; Entry for system restarts.
191 call set$jumps ; initialize page zero
192 call ?rlccp ; reload CCP
193 jp ccp ; then reset jmp vectors and exit to ccp
203 ld a,0C3h ; jp opcode
205 ld (5),a ; set up jumps in page zero
207 ld (1),hl ; BIOS warm start entry
209 ld (6),hl ; BDOS system call entry
218 ; Return address of character device table
226 ; Return address of drive table
235 ; List Output. Send character in <C>
236 ; to all selected devices.
239 ld hl,(@lovec) ; fetch list output bit vector
244 ; Auxiliary Output. Send character in <C>
245 ; to all selected devices
248 ld hl,(@aovec) ; fetch aux output bit vector
253 ; Console Output. Send character in <C>
254 ; to all selected devices
258 ld hl,(@covec) ; fetch console output bit vector
261 ld b,0 ; start with device 0
263 add hl,hl ; shift out next bit
265 push hl ; save the vector
266 push bc ; save device num and the character
267 call ?co ; if device selected, print it
268 pop bc ; recover count and character
269 pop hl ; recover the rest of the vector
271 inc b ; next device number
273 or l ; see if any devices left
274 jr nz,co$next ; and go find them...
279 ; List Output Status. Return true if
280 ; all selected list output devices
284 ld hl,(@lovec) ; get list output bit vector
289 ; Auxiliary Output Status. Return true if
290 ; all selected auxiliary output devices
294 ld hl,(@aovec) ; get aux output bit vector
299 ; Console Output Status. Return true if
300 ; all selected console output devices
304 ld hl,(@covec) ; get console output bit vector
307 ld b,0 ; start with device 0
309 add hl,hl ; check next bit
310 push hl ; save the vector
311 push bc ; save the count
312 ld a,0FFh ; assume device ready
313 call c,?cost ; check status for this device
314 pop bc ; recover count
315 pop hl ; recover bit vector
316 or a ; see if device ready
317 ret z ; if any not ready, return false
318 inc b ; drop device number
320 or l ; see if any more selected devices
322 or 0FFh ; all selected were ready, return true
326 cist1: ; get input status with <BC> and <HL> saved
337 ; Auxiliary Input Status. Return true if
338 ; any selected auxiliary input device
339 ; has an available character.
342 ld hl,(@aivec) ; get aux input bit vector
347 ; Console Input Status. Return true if
348 ; any selected console input device
349 ; has an available character.
352 ld hl,(@civec) ; get console input bit vector
355 ld b,0 ; start with device 0
357 xor a ; assume next device not ready
358 add hl,hl ; check next bit (lets z flag unaffected)
359 call c,cist1 ; check status for this device
360 ret nz ; if any ready, return true
361 inc b ; next device number
363 or l ; see if any more selected devices
364 ret z ; all selected were not ready, return false
369 ; Auxiliary Input. Return character from first
370 ; ready auxiliary input device.
378 ; Console Input. Return character from first
379 ; ready console input device.
385 push hl ; save bit vector
388 xor a ; assume next device not ready
389 add hl,hl ; shift out next bit
390 call c,cist1 ; see if the device has a character
391 jr nz,ci$rdy ; this device has a character
392 inc b ; else, next device
394 or l ; see if any more devices
395 jr nz,ci$next ; go look at them
396 pop hl ; recover bit vector
397 jr in$scan ; loop til we find a character
400 pop hl ; discard extra stack
404 ;-------------------------------------------------------------------------------
405 ; Utility Subroutines
408 ipchl: ; vectored CALL point
414 ; Bank Select. Select CPU bank for further execution.
417 ld (@cbnk),a ; remember current bank
418 jp ?bank ; and go exit through users
419 ; physical bank select routine
421 dseg ; following resides in banked memory
423 ; Disk I/O interface routines
427 ; Select Disk Drive. Drive code in <C>.
428 ; Invoke login procedure for drive
429 ; if this is first select. Return
430 ; address of disk parameter header
434 ld a,c ; save drive select code
439 ld b,a ; create index from drive code
441 add hl,bc ; get pointer to dispatch table
446 ld l,a ; point at disk descriptor
447 ld (@xdph),hl ; save descriptor pointer
449 ret z ; if no entry in table, no disk
451 bit 0,e ; login bit to zero flag
453 ld hl,-2 ; get relative drive
457 jr nz,notfirst ; examine login bit
464 call ipchl ; call LOGIN
466 ld hl,(@xdph) ; recover DPH pointer
471 ; Home selected drive. Treated as SETTRK(0).
474 ld bc,0 ; same as set track zero
478 ; Set Track. Saves track address from <BC>
479 ; in @TRK for further operations.
487 ; Set Sector. Saves sector number from <BC>
488 ; in @sect for further operations.
496 ; Set Disk Memory Address. Saves DMA address
497 ; from <BC> in @DMA and sets @DBNK to @CBNK
498 ; so that further disk operations take place
504 ld a,(@cbnk) ; default DMA bank is current bank
505 ; fall through to set DMA bank
508 ; Set Disk Memory Bank. Saves bank number
509 ; in @DBNK for future disk data
518 ; Sector Translate. Indexes skew table in <DE>
519 ; with sector in <BC>. Returns physical sector
520 ; in <HL>. If no skew table (<DE>=0) then
521 ; returns physical=logical.
537 ; Read physical record from currently selected drive.
538 ; Finds address of proper read routine from
539 ; extended disk parameter header (XDPH).
544 ld ix,(@xdph) ; get drive descriptor pointer
545 ld l,(ix-8) ; get read routine entry
551 ; Write physical sector from currently selected drive.
552 ; Finds address of proper write routine from
553 ; extended disk parameter header (XDPH).
558 ld ix,(@xdph) ; get drive descriptor pointer
559 ld l,(ix-10) ; get write routine entry
566 ; Set multiple sector count. Saves passed count in
575 ; BIOS deblocking buffer flush. Not implemented.
579 ret ; return with no error
582 ; disk communication data items
583 ; do not change order. sd driver depends on this
585 @xdph: ds 2 ; pointer to currently selected drives dph
586 @op ds 1 ; current disk operation 0:select, 1:read, 2 write
587 @adrv: ds 1 ; currently selected disk drive
588 @rdrv: ds 1 ; controller relative disk drive
589 @trk: ds 2 ; current track number
590 @sect: ds 2 ; current sector number
591 @dma: ds 2 ; current DMA address
592 @dbnk: db 0 ; bank for DMA operations
593 @cnt: db 0 ; record count for multisector transfer
598 @cbnk: db 0 ; bank for processor operations