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
87 ; All BIOS routines are invoked by calling these
90 ?boot: jp boot ; initial entry on cold start
91 ?wboot: jp wboot ; reentry on program exit, warm start
93 ?const: jp const ; return console input status
94 ?conin: jp conin ; return console input character
95 ?cono: jp conout ; send console output character
96 ?list: jp list ; send list output character
97 ?auxo: jp auxout ; send auxiliary output character
98 ?auxi: jp auxin ; return auxiliary input character
100 ?home: jp home ; set disks to logical home
101 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
102 ?sttrk: jp settrk ; set disk track
103 ?stsec: jp setsec ; set disk sector
104 ?stdma: jp setdma ; set disk I/O memory address
105 ?read: jp read ; read physical block(s)
106 ?write: jp write ; write physical block(s)
108 ?lists: jp listst ; return list device status
109 ?sctrn: jp sectrn ; translate logical to physical sector
111 ?conos: jp conost ; return console output status
112 ?auxis: jp auxist ; return aux input status
113 ?auxos: jp auxost ; return aux output status
114 ?dvtbl: jp devtbl ; return address of device def table
115 ?devin: jp ?cinit ; change baud rate of device
117 ?drtbl: jp getdrv ; return address of disk drive table
118 ?mltio: jp multio ; set multiple record count for disk I/O
119 ?flush: jp flush ; flush BIOS maintained disk caching
121 ?mov: jp ?move ; block move memory to memory
122 ?tim: jp ?time ; Signal Time and Date operation
123 ?bnksl: jp bnksel ; select bank for code execution and default DMA
124 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
125 ?xmov: jp ?xmove ; set source and destination banks for one operation
127 jp stampf ; stamp system specific functions
128 ; reserved for system implementor
129 jp 0 ; reserved for future expansion
130 jp 0 ; reserved for future expansion
141 ; Initial entry point for system startup.
143 dseg ; this part can be banked
152 call hwinit ; first time hardware initialisation
154 ld bc,16*256 + 0 ; initialize all 16 character devices
162 call ?init ; perform any additional system initialization
163 ; and print signon message
166 ld hl,@dtbl ; init all 16 logical disk drives
168 push bc ; save remaining count and abs drive
172 inc hl ; grab @drv entry
175 jr z,d$init$next ; if null, no drive
176 push hl ; save @drv pointer
178 pop ix ; XDPH address in <DE>
180 ld (@ADRV),bc ; save absolute and relative drive code
182 ld h,(ix-3) ; get init pointer
183 call ijphl ; call init routine
184 pop hl ; recover @drv pointer
186 pop bc ; recover counter and drive #
188 djnz d$init$loop ; and loop for each drive
191 cseg ; following in resident memory
196 call ?ldccp ; fetch CCP for first time
201 ; Entry for system restarts.
205 call set$jumps ; initialize page zero
206 call ?rlccp ; reload CCP
207 jp ccp ; then reset jmp vectors and exit to ccp
217 ld a,0C3h ; jp opcode
219 ld (5),a ; set up jumps in page zero
221 ld (1),hl ; BIOS warm start entry
223 ld (6),hl ; BDOS system call entry
229 ; Return address of character device table
237 ; Return address of drive table
246 ; List Output. Send character in <C>
247 ; to all selected devices.
250 ld hl,(@lovec) ; fetch list output bit vector
255 ; Auxiliary Output. Send character in <C>
256 ; to all selected devices
259 ld hl,(@aovec) ; fetch aux output bit vector
264 ; Console Output. Send character in <C>
265 ; to all selected devices
269 ld hl,(@covec) ; fetch console output bit vector
272 ld b,0 ; start with device 0
274 add hl,hl ; shift out next bit
276 push hl ; save the vector
277 push bc ; save device num and the character
278 call ?co ; if device selected, print it
279 pop bc ; recover count and character
280 pop hl ; recover the rest of the vector
282 inc b ; next device number
284 or l ; see if any devices left
285 jr nz,co$next ; and go find them...
290 ; List Output Status. Return true if
291 ; all selected list output devices
295 ld hl,(@lovec) ; get list output bit vector
300 ; Auxiliary Output Status. Return true if
301 ; all selected auxiliary output devices
305 ld hl,(@aovec) ; get aux output bit vector
310 ; Console Output Status. Return true if
311 ; all selected console output devices
315 ld hl,(@covec) ; get console output bit vector
318 ld b,0 ; start with device 0
320 add hl,hl ; check next bit
321 push hl ; save the vector
322 push bc ; save the count
323 ld a,0FFh ; assume device ready
324 call c,?cost ; check status for this device
325 pop bc ; recover count
326 pop hl ; recover bit vector
327 or a ; see if device ready
328 ret z ; if any not ready, return false
329 inc b ; drop device number
331 or l ; see if any more selected devices
333 or 0FFh ; all selected were ready, return true
337 cist1: ; get input status with <BC> and <HL> saved
348 ; Auxiliary Input Status. Return true if
349 ; any selected auxiliary input device
350 ; has an available character.
353 ld hl,(@aivec) ; get aux input bit vector
358 ; Console Input Status. Return true if
359 ; any selected console input device
360 ; has an available character.
363 ld hl,(@civec) ; get console input bit vector
366 ld b,0 ; start with device 0
368 xor a ; assume next device not ready
369 add hl,hl ; check next bit (lets z flag unaffected)
370 call c,cist1 ; check status for this device
371 ret nz ; if any ready, return true
372 inc b ; next device number
374 or l ; see if any more selected devices
375 ret z ; all selected were not ready, return false
380 ; Auxiliary Input. Return character from first
381 ; ready auxiliary input device.
389 ; Console Input. Return character from first
390 ; ready console input device.
395 ;check if only one device assigned
397 push hl ; save bit vector
401 adc hl,hl ; shift out next bit
403 jr z,ci$rdy ; single device
407 inc b ; else, next device
409 or l ; see if any more devices
414 push hl ; save bit vector
417 xor a ; assume next device not ready
418 add hl,hl ; shift out next bit
420 call c,cist1 ; see if the device has a character
421 jr nz,ci$rdy ; this device has a character
422 inc b ; else, next device
424 or l ; see if any more devices
425 jr nz,ci$next ; go look at them
426 pop hl ; recover bit vector
427 jr in$scan ; loop til we find a character
430 pop hl ; discard extra stack
434 ;-------------------------------------------------------------------------------
435 ; Utility Subroutines
438 ; Bank Select. Select CPU bank for further execution.
441 ld (@cbnk),a ; remember current bank
442 jp ?bank ; and go exit through users
443 ; physical bank select routine
445 dseg ; following resides in banked memory
447 ; Disk I/O interface routines
451 ; Select Disk Drive. Drive code in <C>.
452 ; Invoke login procedure for drive
453 ; if this is first select. Return
454 ; address of disk parameter header
458 ld a,c ; save drive select code
463 ld b,a ; create index from drive code
465 add hl,bc ; get pointer to dispatch table
470 ld l,a ; point at disk descriptor
471 ld (@xdph),hl ; save descriptor pointer
473 ret z ; if no entry in table, no disk
475 bit 0,e ; login bit to zero flag
477 ld hl,-2 ; get relative drive
481 jr nz,notfirst ; examine login bit
483 ld hl,-6 ; call LOGIN
492 ld hl,(@xdph) ; recover DPH pointer
497 ; Home selected drive. Treated as SETTRK(0).
500 ld bc,0 ; same as set track zero
504 ; Set Track. Saves track address from <BC>
505 ; in @TRK for further operations.
513 ; Set Sector. Saves sector number from <BC>
514 ; in @sect for further operations.
522 ; Set Disk Memory Address. Saves DMA address
523 ; from <BC> in @DMA and sets @DBNK to @CBNK
524 ; so that further disk operations take place
530 ld a,(@cbnk) ; default DMA bank is current bank
531 ; fall through to set DMA bank
534 ; Set Disk Memory Bank. Saves bank number
535 ; in @DBNK for future disk data
544 ; Sector Translate. Indexes skew table in <DE>
545 ; with sector in <BC>. Returns physical sector
546 ; in <HL>. If no skew table (<DE>=0) then
547 ; returns physical=logical.
563 ; Read physical record from currently selected drive.
564 ; Finds address of proper read routine from
565 ; extended disk parameter header (XDPH).
570 ld ix,(@xdph) ; get drive descriptor pointer
571 ld l,(ix-8) ; get read routine entry
578 ; Write physical sector from currently selected drive.
579 ; Finds address of proper write routine from
580 ; extended disk parameter header (XDPH).
585 ld ix,(@xdph) ; get drive descriptor pointer
586 ld l,(ix-10) ; get write routine entry
595 ; Set multiple sector count. Saves passed count in
604 ; BIOS deblocking buffer flush. Not implemented.
608 ret ; return with no error
611 ; disk communication data items
612 ; do not change order. sd driver depends on this
614 @xdph: ds 2 ; pointer to currently selected drives dph
615 @op ds 1 ; current disk operation 0:select, 1:read, 2 write
616 @adrv: ds 1 ; currently selected disk drive
617 @rdrv: ds 1 ; controller relative disk drive
618 @trk: ds 2 ; current track number
619 @sect: ds 2 ; current sector number
620 @dma: ds 2 ; current DMA address
621 @dbnk: db 0 ; bank for DMA operations
622 @cnt: db 0 ; record count for multisector transfer
627 @cbnk: db 0 ; bank for processor operations