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
195 call ?ldccp ; fetch CCP for first time
200 ; Entry for system restarts.
204 call set$jumps ; initialize page zero
205 call ?rlccp ; reload CCP
206 jp ccp ; then reset jmp vectors and exit to ccp
216 ld a,0C3h ; jp opcode
218 ld (5),a ; set up jumps in page zero
220 ld (1),hl ; BIOS warm start entry
222 ld (6),hl ; BDOS system call entry
228 ; Return address of character device table
236 ; Return address of drive table
245 ; List Output. Send character in <C>
246 ; to all selected devices.
249 ld hl,(@lovec) ; fetch list output bit vector
254 ; Auxiliary Output. Send character in <C>
255 ; to all selected devices
258 ld hl,(@aovec) ; fetch aux output bit vector
263 ; Console Output. Send character in <C>
264 ; to all selected devices
268 ld hl,(@covec) ; fetch console output bit vector
271 ld b,0 ; start with device 0
273 add hl,hl ; shift out next bit
275 push hl ; save the vector
276 push bc ; save device num and the character
277 call ?co ; if device selected, print it
278 pop bc ; recover count and character
279 pop hl ; recover the rest of the vector
281 inc b ; next device number
283 or l ; see if any devices left
284 jr nz,co$next ; and go find them...
289 ; List Output Status. Return true if
290 ; all selected list output devices
294 ld hl,(@lovec) ; get list output bit vector
299 ; Auxiliary Output Status. Return true if
300 ; all selected auxiliary output devices
304 ld hl,(@aovec) ; get aux output bit vector
309 ; Console Output Status. Return true if
310 ; all selected console output devices
314 ld hl,(@covec) ; get console output bit vector
317 ld b,0 ; start with device 0
319 add hl,hl ; check next bit
320 push hl ; save the vector
321 push bc ; save the count
322 ld a,0FFh ; assume device ready
323 call c,?cost ; check status for this device
324 pop bc ; recover count
325 pop hl ; recover bit vector
326 or a ; see if device ready
327 ret z ; if any not ready, return false
328 inc b ; drop device number
330 or l ; see if any more selected devices
332 or 0FFh ; all selected were ready, return true
336 cist1: ; get input status with <BC> and <HL> saved
347 ; Auxiliary Input Status. Return true if
348 ; any selected auxiliary input device
349 ; has an available character.
352 ld hl,(@aivec) ; get aux input bit vector
357 ; Console Input Status. Return true if
358 ; any selected console input device
359 ; has an available character.
362 ld hl,(@civec) ; get console input bit vector
365 ld b,0 ; start with device 0
367 xor a ; assume next device not ready
368 add hl,hl ; check next bit (lets z flag unaffected)
369 call c,cist1 ; check status for this device
370 ret nz ; if any ready, return true
371 inc b ; next device number
373 or l ; see if any more selected devices
374 ret z ; all selected were not ready, return false
379 ; Auxiliary Input. Return character from first
380 ; ready auxiliary input device.
388 ; Console Input. Return character from first
389 ; ready console input device.
394 ;check if only one device assigned
396 push hl ; save bit vector
400 adc hl,hl ; shift out next bit
402 jr z,ci$rdy ; single device
406 inc b ; else, next device
408 or l ; see if any more devices
413 push hl ; save bit vector
416 xor a ; assume next device not ready
417 add hl,hl ; shift out next bit
419 call c,cist1 ; see if the device has a character
420 jr nz,ci$rdy ; this device has a character
421 inc b ; else, next device
423 or l ; see if any more devices
424 jr nz,ci$next ; go look at them
425 pop hl ; recover bit vector
426 jr in$scan ; loop til we find a character
429 pop hl ; discard extra stack
433 ;-------------------------------------------------------------------------------
434 ; Utility Subroutines
437 ; Bank Select. Select CPU bank for further execution.
440 ld (@cbnk),a ; remember current bank
441 jp ?bank ; and go exit through users
442 ; physical bank select routine
444 dseg ; following resides in banked memory
446 ; Disk I/O interface routines
450 ; Select Disk Drive. Drive code in <C>.
451 ; Invoke login procedure for drive
452 ; if this is first select. Return
453 ; address of disk parameter header
457 ld a,c ; save drive select code
462 ld b,a ; create index from drive code
464 add hl,bc ; get pointer to dispatch table
469 ld l,a ; point at disk descriptor
470 ld (@xdph),hl ; save descriptor pointer
472 ret z ; if no entry in table, no disk
474 bit 0,e ; login bit to zero flag
476 ld hl,-2 ; get relative drive
480 jr nz,notfirst ; examine login bit
489 call ijphl ; 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).
572 ld ix,(@xdph) ; get drive descriptor pointer
573 ld l,(ix-8) ; get read routine entry
575 call ijphl ; call LOGIN
580 ; Write physical sector from currently selected drive.
581 ; Finds address of proper write routine from
582 ; extended disk parameter header (XDPH).
589 ld ix,(@xdph) ; get drive descriptor pointer
590 ld l,(ix-10) ; get write routine entry
592 call ijphl ; call LOGIN
599 ; Set multiple sector count. Saves passed count in
608 ; BIOS deblocking buffer flush. Not implemented.
612 ret ; return with no error
615 ; disk communication data items
616 ; do not change order. sd driver depends on this
618 @xdph: ds 2 ; pointer to currently selected drives dph
619 @op ds 1 ; current disk operation 0:select, 1:read, 2 write
620 @adrv: ds 1 ; currently selected disk drive
621 @rdrv: ds 1 ; controller relative disk drive
622 @trk: ds 2 ; current track number
623 @sect: ds 2 ; current sector number
624 @dma: ds 2 ; current DMA address
625 @dbnk: db 0 ; bank for DMA operations
626 @cnt: db 0 ; record count for multisector transfer
631 @cbnk: db 0 ; bank for processor operations