]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/bioskrnl.180
seldsk/read/write: remove b0call
[z180-stamp-cpm3.git] / cbios / bioskrnl.180
1 title 'Root module of relocatable BIOS for CP/M 3.0'
2
3 ; version 1.0 15 Sept 82
4
5 include config.inc
6 include z180reg.inc
7
8
9 ; Copyright (C), 1982
10 ; Digital Research, Inc
11 ; P.O. Box 579
12 ; Pacific Grove, CA 93950
13
14
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
21 ; configuration.
22
23 ctlQ equ 'Q'-'@'
24 ctlS equ 'S'-'@'
25
26 ccp equ 0100h ; Console Command Processor gets loaded
27 ; into the TPA
28
29 cseg ; GENCPM puts CSEG stuff in common memory
30
31
32 ; variables in system data page
33
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
37
38 ; initialization
39
40 extrn hwinit,?init ; general initialization and signon
41 extrn ?ldccp,?rlccp ; load & reload CCP for BOOT & WBOOT
42
43 ; user defined character I/O routines
44
45 extrn ?ci,?co,?cist,?cost ; each take device in <B>
46 extrn ?cinit ; (re)initialize device in <C>
47 extrn ioctl
48 extrn @ctbl ; physical character device table
49
50 ; disk communication data items
51
52 extrn @dtbl ; table of pointers to XDPHs
53 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
54 public @dma,@dbnk,@cnt ; '' '' '' ''
55 public @xdph,@op
56
57 ; memory control
58
59 public @cbnk ; current bank
60 extrn ?xmove,?move ; select move bank, and block move
61 extrn ?bank ; select CPU bank
62
63 ; clock support
64
65 extrn ?time ; signal time operation
66
67 extrn stampf
68 extrn ijphl ; vectored call
69
70 maclib modebaud.inc ; define mode bits
71
72
73 ; External names for BIOS entry points
74
75 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
76 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
77 public ?lists,?sctrn
78 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
79 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
80
81 extrn bs$stack
82 extrn _b0call
83
84
85 ; BIOS Jump vector.
86
87 ; All BIOS routines are invoked by calling these
88 ; entry points.
89
90 ?boot: jp boot ; initial entry on cold start
91 ?wboot: jp wboot ; reentry on program exit, warm start
92
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
99
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)
107
108 ?lists: jp listst ; return list device status
109 ?sctrn: jp sectrn ; translate logical to physical sector
110
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
116
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
120
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
126
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
131 ?ioctl jp ioctl ;
132
133
134 rept 48
135 db '|'
136 endm
137 boot$stack:
138
139
140 ; BOOT
141 ; Initial entry point for system startup.
142
143 dseg ; this part can be banked
144
145 boot:
146 ld a,SYS$CBR
147 out0 (cbr),a
148 ld a,USR$CBAR
149 out0 (cbar),a
150 ld sp,boot$stack
151
152 call hwinit ; first time hardware initialisation
153
154 ld bc,16*256 + 0 ; initialize all 16 character devices
155 c$init$loop:
156 push bc
157 call ?cinit
158 pop bc
159 inc c
160 djnz c$init$loop
161
162 call ?init ; perform any additional system initialization
163 ; and print signon message
164
165 ld bc,16*256+0
166 ld hl,@dtbl ; init all 16 logical disk drives
167 d$init$loop:
168 push bc ; save remaining count and abs drive
169 ld e,(hl)
170 inc hl
171 ld d,(hl)
172 inc hl ; grab @drv entry
173 ld a,e
174 or d
175 jr z,d$init$next ; if null, no drive
176 push hl ; save @drv pointer
177 push de
178 pop ix ; XDPH address in <DE>
179 ld b,(ix-2)
180 ld (@ADRV),bc ; save absolute and relative drive code
181 ld l,(ix-4)
182 ld h,(ix-3) ; get init pointer
183 call ijphl ; call init routine
184 pop hl ; recover @drv pointer
185 d$init$next:
186 pop bc ; recover counter and drive #
187 inc c
188 djnz d$init$loop ; and loop for each drive
189 jp boot$1
190
191 cseg ; following in resident memory
192
193 boot$1:
194 call set$jumps
195 call ?ldccp ; fetch CCP for first time
196 jp ccp
197
198
199 ; WBOOT
200 ; Entry for system restarts.
201
202 wboot:
203 ld sp,boot$stack
204 call set$jumps ; initialize page zero
205 call ?rlccp ; reload CCP
206 jp ccp ; then reset jmp vectors and exit to ccp
207
208
209 set$jumps:
210
211 if banked
212 ld a,1
213 call ?bnksl
214 endif
215
216 ld a,0C3h ; jp opcode
217 ld (0),a
218 ld (5),a ; set up jumps in page zero
219 ld hl,?wboot
220 ld (1),hl ; BIOS warm start entry
221 ld hl,(@MXTPA)
222 ld (6),hl ; BDOS system call entry
223 ret
224
225
226
227 ; DEVTBL
228 ; Return address of character device table
229
230 devtbl:
231 ld hl,@ctbl
232 ret
233
234
235 ; GETDRV
236 ; Return address of drive table
237
238 getdrv:
239 ld hl,@dtbl
240 ret
241
242
243
244 ; LIST
245 ; List Output. Send character in <C>
246 ; to all selected devices.
247
248 list:
249 ld hl,(@lovec) ; fetch list output bit vector
250 jr out$scan
251
252
253 ; AUXOUT
254 ; Auxiliary Output. Send character in <C>
255 ; to all selected devices
256
257 auxout:
258 ld hl,(@aovec) ; fetch aux output bit vector
259 jr out$scan
260
261
262 ; CONOUT
263 ; Console Output. Send character in <C>
264 ; to all selected devices
265
266 conout:
267
268 ld hl,(@covec) ; fetch console output bit vector
269
270 out$scan:
271 ld b,0 ; start with device 0
272 co$next:
273 add hl,hl ; shift out next bit
274 jr nc,not$out$device
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
280 not$out$device:
281 inc b ; next device number
282 ld a,h
283 or l ; see if any devices left
284 jr nz,co$next ; and go find them...
285 ret
286
287
288 ; LISTST
289 ; List Output Status. Return true if
290 ; all selected list output devices
291 ; are ready.
292
293 listst:
294 ld hl,(@lovec) ; get list output bit vector
295 jr ost$scan
296
297
298 ; AUXOST
299 ; Auxiliary Output Status. Return true if
300 ; all selected auxiliary output devices
301 ; are ready.
302
303 auxost:
304 ld hl,(@aovec) ; get aux output bit vector
305 jr ost$scan
306
307
308 ; CONOST
309 ; Console Output Status. Return true if
310 ; all selected console output devices
311 ; are ready.
312
313 conost:
314 ld hl,(@covec) ; get console output bit vector
315
316 ost$scan:
317 ld b,0 ; start with device 0
318 cos$next:
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
329 ld a,h
330 or l ; see if any more selected devices
331 jr nz,cos$next
332 or 0FFh ; all selected were ready, return true
333 ret
334
335
336 cist1: ; get input status with <BC> and <HL> saved
337 push bc
338 push hl
339 call ?cist
340 pop hl
341 pop bc
342 or a
343 ret
344
345
346 ; AUXIST
347 ; Auxiliary Input Status. Return true if
348 ; any selected auxiliary input device
349 ; has an available character.
350
351 auxist:
352 ld hl,(@aivec) ; get aux input bit vector
353 jr ist$scan
354
355
356 ; CONST
357 ; Console Input Status. Return true if
358 ; any selected console input device
359 ; has an available character.
360
361 const:
362 ld hl,(@civec) ; get console input bit vector
363
364 ist$scan:
365 ld b,0 ; start with device 0
366 cis$next:
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
372 ld a,h
373 or l ; see if any more selected devices
374 ret z ; all selected were not ready, return false
375 jr cis$next
376
377
378 ; AUXIN
379 ; Auxiliary Input. Return character from first
380 ; ready auxiliary input device.
381
382 auxin:
383 ld hl,(@aivec)
384 jr in$scan
385
386
387 ; CONIN
388 ; Console Input. Return character from first
389 ; ready console input device.
390
391 conin:
392 ld hl,(@civec)
393
394 ;check if only one device assigned
395
396 push hl ; save bit vector
397 ld b,0
398 insc_0:
399 or a ; clear carry
400 adc hl,hl ; shift out next bit
401 jr nc,insc_1 ;
402 jr z,ci$rdy ; single device
403 jr ci$check ;
404
405 insc_1:
406 inc b ; else, next device
407 ld a,h
408 or l ; see if any more devices
409 jr nz,insc_0 ; no,
410 pop hl
411
412 in$scan:
413 push hl ; save bit vector
414 ld b,0
415 ci$next:
416 xor a ; assume next device not ready
417 add hl,hl ; shift out next bit
418 ci$check:
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
422 ld a,h
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
427
428 ci$rdy:
429 pop hl ; discard extra stack
430 jp ?ci
431
432
433 ;-------------------------------------------------------------------------------
434 ; Utility Subroutines
435
436 ; BNKSEL
437 ; Bank Select. Select CPU bank for further execution.
438
439 bnksel:
440 ld (@cbnk),a ; remember current bank
441 jp ?bank ; and go exit through users
442 ; physical bank select routine
443
444 dseg ; following resides in banked memory
445
446 ; Disk I/O interface routines
447
448
449 ; SELDSK
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
454 ; in <HL>
455
456 seldsk:
457 ld a,c ; save drive select code
458 ld (@adrv),a
459 xor a
460 ld (@op),a
461 ld (@cnt),a
462 ld b,a ; create index from drive code
463 ld hl,@dtbl
464 add hl,bc ; get pointer to dispatch table
465 add hl,bc
466 ld a,(hl)
467 inc hl
468 ld h,(hl)
469 ld l,a ; point at disk descriptor
470 ld (@xdph),hl ; save descriptor pointer
471 or h
472 ret z ; if no entry in table, no disk
473
474 bit 0,e ; login bit to zero flag
475 ex de,hl
476 ld hl,-2 ; get relative drive
477 add hl,de
478 ld a,(hl)
479 ld (@RDRV),a
480 jr nz,notfirst ; examine login bit
481 ld hl,-6
482 add hl,de
483 ld a,(hl)
484 inc hl
485 ld h,(hl)
486 ld l,a
487 ld (bs$stack),sp
488 ld sp,bs$stack
489 call ijphl ; call LOGIN
490 ld sp,(bs$stack)
491 notfirst:
492 ld hl,(@xdph) ; recover DPH pointer
493 ret
494
495
496 ; HOME
497 ; Home selected drive. Treated as SETTRK(0).
498
499 home:
500 ld bc,0 ; same as set track zero
501
502
503 ; SETTRK
504 ; Set Track. Saves track address from <BC>
505 ; in @TRK for further operations.
506
507 settrk:
508 ld (@trk),bc
509 ret
510
511
512 ; SETSEC
513 ; Set Sector. Saves sector number from <BC>
514 ; in @sect for further operations.
515
516 setsec:
517 ld (@sect),bc
518 ret
519
520
521 ; SETDMA
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
525 ; in current bank.
526
527 setdma:
528 ld (@dma),bc
529
530 ld a,(@cbnk) ; default DMA bank is current bank
531 ; fall through to set DMA bank
532
533 ; SETBNK
534 ; Set Disk Memory Bank. Saves bank number
535 ; in @DBNK for future disk data
536 ; transfers.
537
538 setbnk:
539 ld (@dbnk),a
540 ret
541
542
543 ; SECTRN
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.
548
549 sectrn:
550 ld l,c
551 ld h,b
552 ld a,d
553 or e
554 ret z
555 ex de,hl
556 add hl,bc
557 ld l,(hl)
558 ld h,0
559 ret
560
561
562 ; READ
563 ; Read physical record from currently selected drive.
564 ; Finds address of proper read routine from
565 ; extended disk parameter header (XDPH).
566
567 read:
568 ld (bs$stack),sp
569 ld sp,bs$stack
570 ld a,1
571 ld (@op),a
572 ld ix,(@xdph) ; get drive descriptor pointer
573 ld l,(ix-8) ; get read routine entry
574 ld h,(ix-7)
575 call ijphl ; call LOGIN
576 ld sp,(bs$stack)
577 ret
578
579 ; WRITE
580 ; Write physical sector from currently selected drive.
581 ; Finds address of proper write routine from
582 ; extended disk parameter header (XDPH).
583
584 write:
585 ld (bs$stack),sp
586 ld sp,bs$stack
587 ld a,2
588 ld (@op),a
589 ld ix,(@xdph) ; get drive descriptor pointer
590 ld l,(ix-10) ; get write routine entry
591 ld h,(ix- 9)
592 call ijphl ; call LOGIN
593 ld sp,(bs$stack)
594 ret
595
596
597
598 ; MULTIO
599 ; Set multiple sector count. Saves passed count in
600 ; @CNT
601
602 multio:
603 ld (@cnt),a
604 ret
605
606
607 ; FLUSH
608 ; BIOS deblocking buffer flush. Not implemented.
609
610 flush:
611 xor a
612 ret ; return with no error
613
614
615 ; disk communication data items
616 ; do not change order. sd driver depends on this
617
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
627
628
629 cseg ; common memory
630
631 @cbnk: db 0 ; bank for processor operations
632
633 end