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
68 extrn ijphl ; vectored call
70 maclib modebaud.inc ; define mode bits
73 ; External names for BIOS entry points
75 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
76 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
78 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
79 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
86 ; All BIOS routines are invoked by calling these
89 ?boot: jp boot ; initial entry on cold start
90 ?wboot: jp wboot ; reentry on program exit, warm start
92 ?const: jp const ; return console input status
93 ?conin: jp conin ; return console input character
94 ?cono: jp conout ; send console output character
95 ?list: jp list ; send list output character
96 ?auxo: jp auxout ; send auxiliary output character
97 ?auxi: jp auxin ; return auxiliary input character
99 ?home: jp home ; set disks to logical home
100 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
101 ?sttrk: jp settrk ; set disk track
102 ?stsec: jp setsec ; set disk sector
103 ?stdma: jp setdma ; set disk I/O memory address
104 ?read: jp read ; read physical block(s)
105 ?write: jp write ; write physical block(s)
107 ?lists: jp listst ; return list device status
108 ?sctrn: jp sectrn ; translate logical to physical sector
110 ?conos: jp conost ; return console output status
111 ?auxis: jp auxist ; return aux input status
112 ?auxos: jp auxost ; return aux output status
113 ?dvtbl: jp devtbl ; return address of device def table
114 ?devin: jp ?cinit ; change baud rate of device
116 ?drtbl: jp getdrv ; return address of disk drive table
117 ?mltio: jp multio ; set multiple record count for disk I/O
118 ?flush: jp flush ; flush BIOS maintained disk caching
120 ?mov: jp ?move ; block move memory to memory
121 ?tim: jp ?time ; Signal Time and Date operation
122 ?bnksl: jp bnksel ; select bank for code execution and default DMA
123 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
124 ?xmov: jp ?xmove ; set source and destination banks for one operation
126 jp stampf ; stamp system specific functions
127 ; reserved for system implementor
128 jp 0 ; reserved for future expansion
129 jp 0 ; reserved for future expansion
134 ; Initial entry point for system startup.
136 dseg ; this part can be banked
145 call hwinit ; first time hardware initialisation
147 ld bc,16*256 + 0 ; initialize all 16 character devices
155 call ?init ; perform any additional system initialization
156 ; and print signon message
159 ld hl,@dtbl ; init all 16 logical disk drives
161 push bc ; save remaining count and abs drive
165 inc hl ; grab @drv entry
168 jr z,d$init$next ; if null, no drive
169 push hl ; save @drv pointer
171 pop ix ; XDPH address in <DE>
173 ld (@ADRV),bc ; save absolute and relative drive code
175 ld h,(ix-3) ; get init pointer
176 call ijphl ; call init routine
177 pop hl ; recover @drv pointer
179 pop bc ; recover counter and drive #
181 djnz d$init$loop ; and loop for each drive
184 cseg ; following in resident memory
188 call ?ldccp ; fetch CCP for first time
193 ; Entry for system restarts.
197 call set$jumps ; initialize page zero
198 call ?rlccp ; reload CCP
199 jp ccp ; then reset jmp vectors and exit to ccp
209 ld a,0C3h ; jp opcode
211 ld (5),a ; set up jumps in page zero
213 ld (1),hl ; BIOS warm start entry
215 ld (6),hl ; BDOS system call entry
224 ; Return address of character device table
232 ; Return address of drive table
241 ; List Output. Send character in <C>
242 ; to all selected devices.
245 ld hl,(@lovec) ; fetch list output bit vector
250 ; Auxiliary Output. Send character in <C>
251 ; to all selected devices
254 ld hl,(@aovec) ; fetch aux output bit vector
259 ; Console Output. Send character in <C>
260 ; to all selected devices
264 ld hl,(@covec) ; fetch console output bit vector
267 ld b,0 ; start with device 0
269 add hl,hl ; shift out next bit
271 push hl ; save the vector
272 push bc ; save device num and the character
273 call ?co ; if device selected, print it
274 pop bc ; recover count and character
275 pop hl ; recover the rest of the vector
277 inc b ; next device number
279 or l ; see if any devices left
280 jr nz,co$next ; and go find them...
285 ; List Output Status. Return true if
286 ; all selected list output devices
290 ld hl,(@lovec) ; get list output bit vector
295 ; Auxiliary Output Status. Return true if
296 ; all selected auxiliary output devices
300 ld hl,(@aovec) ; get aux output bit vector
305 ; Console Output Status. Return true if
306 ; all selected console output devices
310 ld hl,(@covec) ; get console output bit vector
313 ld b,0 ; start with device 0
315 add hl,hl ; check next bit
316 push hl ; save the vector
317 push bc ; save the count
318 ld a,0FFh ; assume device ready
319 call c,?cost ; check status for this device
320 pop bc ; recover count
321 pop hl ; recover bit vector
322 or a ; see if device ready
323 ret z ; if any not ready, return false
324 inc b ; drop device number
326 or l ; see if any more selected devices
328 or 0FFh ; all selected were ready, return true
332 cist1: ; get input status with <BC> and <HL> saved
343 ; Auxiliary Input Status. Return true if
344 ; any selected auxiliary input device
345 ; has an available character.
348 ld hl,(@aivec) ; get aux input bit vector
353 ; Console Input Status. Return true if
354 ; any selected console input device
355 ; has an available character.
358 ld hl,(@civec) ; get console input bit vector
361 ld b,0 ; start with device 0
363 xor a ; assume next device not ready
364 add hl,hl ; check next bit (lets z flag unaffected)
365 call c,cist1 ; check status for this device
366 ret nz ; if any ready, return true
367 inc b ; next device number
369 or l ; see if any more selected devices
370 ret z ; all selected were not ready, return false
375 ; Auxiliary Input. Return character from first
376 ; ready auxiliary input device.
384 ; Console Input. Return character from first
385 ; ready console input device.
390 ;check if only one device assigned
392 push hl ; save bit vector
396 adc hl,hl ; shift out next bit
398 jr z,ci$rdy ; single device
402 inc b ; else, next device
404 or l ; see if any more devices
409 push hl ; save bit vector
412 xor a ; assume next device not ready
413 add hl,hl ; shift out next bit
415 call c,cist1 ; see if the device has a character
416 jr nz,ci$rdy ; this device has a character
417 inc b ; else, next device
419 or l ; see if any more devices
420 jr nz,ci$next ; go look at them
421 pop hl ; recover bit vector
422 jr in$scan ; loop til we find a character
425 pop hl ; discard extra stack
429 ;-------------------------------------------------------------------------------
430 ; Utility Subroutines
433 ; Bank Select. Select CPU bank for further execution.
436 ld (@cbnk),a ; remember current bank
437 jp ?bank ; and go exit through users
438 ; physical bank select routine
440 dseg ; following resides in banked memory
442 ; Disk I/O interface routines
446 ; Select Disk Drive. Drive code in <C>.
447 ; Invoke login procedure for drive
448 ; if this is first select. Return
449 ; address of disk parameter header
453 ld a,c ; save drive select code
458 ld b,a ; create index from drive code
460 add hl,bc ; get pointer to dispatch table
465 ld l,a ; point at disk descriptor
466 ld (@xdph),hl ; save descriptor pointer
468 ret z ; if no entry in table, no disk
470 bit 0,e ; login bit to zero flag
472 ld hl,-2 ; get relative drive
476 jr nz,notfirst ; examine login bit
483 call ijphl ; call LOGIN
485 ld hl,(@xdph) ; recover DPH pointer
490 ; Home selected drive. Treated as SETTRK(0).
493 ld bc,0 ; same as set track zero
497 ; Set Track. Saves track address from <BC>
498 ; in @TRK for further operations.
506 ; Set Sector. Saves sector number from <BC>
507 ; in @sect for further operations.
515 ; Set Disk Memory Address. Saves DMA address
516 ; from <BC> in @DMA and sets @DBNK to @CBNK
517 ; so that further disk operations take place
523 ld a,(@cbnk) ; default DMA bank is current bank
524 ; fall through to set DMA bank
527 ; Set Disk Memory Bank. Saves bank number
528 ; in @DBNK for future disk data
537 ; Sector Translate. Indexes skew table in <DE>
538 ; with sector in <BC>. Returns physical sector
539 ; in <HL>. If no skew table (<DE>=0) then
540 ; returns physical=logical.
556 ; Read physical record from currently selected drive.
557 ; Finds address of proper read routine from
558 ; extended disk parameter header (XDPH).
563 ld ix,(@xdph) ; get drive descriptor pointer
564 ld l,(ix-8) ; get read routine entry
570 ; Write physical sector from currently selected drive.
571 ; Finds address of proper write routine from
572 ; extended disk parameter header (XDPH).
577 ld ix,(@xdph) ; get drive descriptor pointer
578 ld l,(ix-10) ; get write routine entry
585 ; Set multiple sector count. Saves passed count in
594 ; BIOS deblocking buffer flush. Not implemented.
598 ret ; return with no error
601 ; disk communication data items
602 ; do not change order. sd driver depends on this
604 @xdph: ds 2 ; pointer to currently selected drives dph
605 @op ds 1 ; current disk operation 0:select, 1:read, 2 write
606 @adrv: ds 1 ; currently selected disk drive
607 @rdrv: ds 1 ; controller relative disk drive
608 @trk: ds 2 ; current track number
609 @sect: ds 2 ; current sector number
610 @dma: ds 2 ; current DMA address
611 @dbnk: db 0 ; bank for DMA operations
612 @cnt: db 0 ; record count for multisector transfer
617 @cbnk: db 0 ; bank for processor operations