Files
RomWBW/Source/BPBIOS/bpbio-dx.z80
2015-08-19 17:34:42 +00:00

577 lines
17 KiB
Z80 Assembly
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;*****************************************************************************
; BP-BIOS. Banked, Portable BIOS.
; Copyright (c) 1989-93 by Cameron W. Cotrill and Harold F. Bower
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or (at
; your option) any later version.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
;----------------------------------------------------------------------------
; This BIOS is broken into modules that allow it to be ported across a
; wide variety of Z80 compatible systems. All hardware specific drivers
; are isolated to separate modules. All hardware independent modules (such
; as deblocking and IO redirection) are similarly broken out.
;
; The BP BIOS supports IOBYTE, but in a unique manner. Four physical devices
; are defined - COM1, COM2, PIO, and NULL. These are assigned to the CON,
; AUXIN, AUXOUT, and LST logical devices by the I/O byte. The NULL device is
; a bit bucket for output, and returns nulls for input.
;
; IOBYTE DESCRIPTION: LIST AUXOUT AUXIN CON
; D7->D0 XX XX XX XX
;
; XX: 00=COM1 01=COM2 10=PIO 11=NULL
;
;+++++++++++++++++ D-X Designs Pty Ltd P112 Version ++++++++++++++++++
;
; This configuration of the B/P Bios is for Dave Brooks' Project 112 Single
; board computer. Multifunction chips on the board provide the services
; needed by a CP/M BIOS. The primary chips and the functions provided are:
;
; Zilog Z80182 Z180 Core CPU, MMU, DMA
; ESCC #1 COM1 Serial Port w/handshake signals, RS-232
; ESCC #2 (available on header, coded as expansion)
; ASCI0, ASCI1 (Serial async, available on header, expansion)
; CTC1 Optional 'heartbeat' clock, GP timer
;
; SMC FDC37C665 Enhanced 765-derivative Floppy Disk Controller
; COM2 - 16550-compatible Serial, RS-232
; PAR1 - Centronics Parallel port (Printer)
;
; Dallas DS-1202 Primary Realtime clock
; Non-volatile battery-backed RAM (config data)
;
; 28F256 Flash ROM Boot code, device initialization
; (onboard programmable)
; 32/128/512 KB Static RAM
;
; Ver Date Revision Description
; --- --------- ------------------------
; 1.3 28 Aug 01 - Scrubbed for GPL Release. HFB
; 1.2 - 30 Aug 97 - Expanded SCSI CDB length to 12 bytes for CDROM. HFB
; 1.1 - 11 May 97 - Added IDE Hard Drive instead of Normal SCSI, updated
; files to latest version. HFB
; 1.0 - 13 Aug 96 - Initial Release for P112 from YASBEC release. HFB
;*****************************************************************************
NAME BPBIO
FALSE EQU 0
TRUE EQU NOT FALSE
NO EQU FALSE
YES EQU TRUE
; << ****** SYSTEM SPECIFIC ****** >>
; << Insert DEF-xxxx.LIB definition >>
INCLUDE DEF-DX.LIB ; << file for your configuration. >>
CSEG
;.....
; Ascii Character Equates
ETX EQU 03H ; End-of-Text
ACK EQU 06H ; Acknowledge
BELL EQU 07H ; Bell Character
CR EQU 0DH
LF EQU 0AH
XON EQU 11H ; X-On (Control-Q)
XOFF EQU 13H ; X-Off (Control-S)
ESC EQU 1BH
; Miscellaneous Equates
WRUAL EQU 2 ; DOS code for unallocated write
LOCKF EQU LOW [NOT AUTOSL] ;Lock flag for format default
ALONE EQU FALSE ; Boot code equate
IF Z3
MACLIB Z3BASE ; Include ENV definitions
ENDIF
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; BIOS Entry Jump Table - This MUST be in Common Memory
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
CSEG
BIOSJT: JP CBOOT ; 00 Cold Boot
JP WBOOT ; 01 Warm Boot
JP CONST ; 02 console input status * (IOP+12)
JP CONIN ; 03 console input * (IOP+15)
JP CONOUT ; 04 console output * (IOP+18)
JP LIST ; 05 list output * (IOP+21)
JP AUXOUT ; 06 aux out (punch) * (IOP+24)
JP AUXIN ; 07 aux in (reader) * (IOP+27)
JP HOME ; 08 seek track 0
JP SELDSK ; 09 select logical drive
JP SETTRK ; 10 select track
JP SETSEC ; 11 select sector
JP SETDMA ; 12 set dma address for disk xfer
JP READ ; 13 disk read
JP WRITE ; 14 disk write
JP LISTST ; 15 list output status * (IOP+30)
JP SECTRN ; 16 logical -> physical sector xlate
; --- <<< End of CP/M 2.2 Vectors >>>
JP CONOST ; 17 Console Output Status
JP AUXIST ; 18 Aux Input Status
JP AUXOST ; 19 Aux Output Status
JP DEVTBL ; 20 CP/M 3 Device Table
JP DEVINI ; 21 Character Device Init (Near CP/M 3)
JP DRVTBL ; 22 DPH Pointer Table for A-P
JP 0 ; 23 RESERVED FOR MULTIO
JP FLUSH ; 24 Flush Deblocker
JP MOVE ; 25 Perform possible Inter-Bank Move
IF CLOCK
JP TIME ; 26 Get/Set RTC (Zsdos params)
ELSE
JP ISTRUE ; 26..return 0FFH (No Clock) if No code
ENDIF ;clock
JP SELMEM ; 27 Select Alternate Memory Bank
JP SETBNK ; 28 Select DMA Memory bank
JP XMOVE ; 29 Set Source/Destination Banks for Move
; --- <<< End of CP/M 3 Vectors >>>
JP RETBIO ; 30 Return BIOS Addresses
JP DIRDIO ; 31 Direct Disk I/O
JP STFARC ; 32 Set Bank for FRJP and FRCALL
JP FRJP ; 33 Jump to (HL) in Alternate Bank
JP FRCLR ; 34 Clear Stack switcher from Alt Bank Jumps
; (used for error exits)
JP FRGETB ; 35 Load A,(HL) from Alternate Bank
JP FRGETW ; 36 Load DE,(HL) from Alternate Bank
JP FRPUTB ; 37 Load (HL),A to Alternate Bank
JP FRPUTW ; 38 Load (HL),DE to Alternate Bank
JP RETMEM ; 39 Return Current Active Memory Bank
CPR EQU BIOSJT-800H-0E00H
DOS EQU BIOSJT-0E00H
; End of BIOS Jump Table
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; Boot / Banked Routine Linkage
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
IF BANKED
COMMON /BANK2/
ROMJT:
IF INROM
JP INSYNC
INSYNC: JP BOOTER ; Cold start loader
ELSE
JP 0 ; Reserved
JP 0
ENDIF ; Inrom
JDIRIO: JP DIRIO ; Low Level HDC/FDC Functions
JHDCIO: JP DIRIO ; Low Level HDC Functions (combined w/FDCIO)
JBREAD: JP BREAD ; BIOS Read
JBWRT: JP BWRT ; BIOS Write
JBSTRN: JP BSTRN ; BIOS Sectran
IF INROM
INCLUDE BOOTROM.Z80 ; Boot Routines
ENDIF ; Inrom
ENDIF ; Banked
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; C o n f i g u r a t i o n A r e a
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; << ****** HARDWARE SPECIFIC ****** >>
; << Insert ICFG-xxx to initialize >>
INCLUDE ICFG-DX.Z80 ; << your computer's IO system >>
PAGE
; << ****** Hardware Specific ****** >>
; << Enter Low level Byte I/O driver >>
INCLUDE IIO-DX.Z80 ; << routines in file IIO-xxxx.Z80 >>
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; Cold Start Code
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
DSEG
; << ***** Hardware Specific ***** >>
; << Insert the Cold boot routines >>
INCLUDE CBOOT-DX.Z80 ; << in file CBOOT-xx.Z80 >>
; Deblocking Buffer Allocation
IF [BANKED OR INROM]
COMMON /B2RAM/
IF INROM
HSTBUF: DEFS INITCS ; Use a 1k buffer w/below
ELSE
HSTBUF EQU CBOOT0 ; Use CBOOT0 code for part of buffer w/below
ENDIF ;inrom
ELSE
DSEG
HSTBUF EQU CBOOT
ENDIF ;not banked
DEFS 1024-(INITCS) ; Use a 1 k buffer
HSTSIZ EQU HSTBUF+1024 ; Added label for Hard Drive ext. interface
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; Disk Data Structures
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MXFDIR EQU 255 ; Max number of dir entries-1 for floppy
MXFALC EQU 880 ; If High Density or 8" drives can be handled,
; set this for 880 (1.76 MB), otherwise the
; value can be reduced to 400 (800 KB), the
; maximum for 80 track, Double-Sided formats.
CSEG
IF BANKED
COMMON /BANK2/
ENDIF
DPB: ; Marker for DPB start
.XLIST ; Don't print these due to size
IF AUTOSL
INCLUDE DPB.LIB ; Default selection of common DD formats
IF FLOPYH
INCLUDE DPB-H.LIB ; If "High-Density" Disk formats desired,
ENDIF
IF FLOPY8
INCLUDE DPB-8.LIB ; If 8" or HD Floppy Disks can be handled,
ENDIF ; add default Autoselect DPB's
IF MORDPB
INCLUDE DPB2.LIB ; Additional assignable DPB's (4+4 unused)
ENDIF ;mordpb
ELSE ;Not autosl
INCLUDE DPBRAM.LIB ; RAM-based DPB's, 1 per physical Format
ENDIF
NRDPB EQU [$-DPB]/DPBSIZ ; Calc number of DPB's
CSEG ; Hard & Ramdisk DPBs and DPHs go in Code Seg
.xlist
IF HARDDSK
; << ****** Hardware Specific ****** >>
; << Insert DPB Info for Hard Disk >>
INCLUDE DPBHD-DX.LIB ; << Drives as DPBHD-xx.LIB >>
ENDIF
.list
IF RAMDSK
; << ****** Hardware Specific ****** >>
; << Insert DPB Info for RAM Disk >>
INCLUDE DPBM-DX.LIB ; << in file DPBM-xxx.LIB >>
ENDIF
PAGE
INCLUDE DPH.LIB ; Disk parameter headers
.xlist
IF HARDDSK
INCLUDE DPHHD.LIB ; Insert DPH Info for Hard Disk Partitions
ENDIF
.list
IF RAMDSK
INCLUDE DPHM.LIB ; Insert DPH Info for RAM Disk
ENDIF
.LIST
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; Disk Driver Low - Level Function Links
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Direct Disk I / O
; Call with: Function Number in C, Driver number in B,
; Args in A, DE, HL
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CSEG
DIRDIO:
IF BANKED
CALL BIOSTK
CALL GOSYSB ; Bank in the system bank
JP JDIRIO ; And jump to Banked-BIOS function
COMMON /BANK2/
ENDIF
DIRIO: PUSH HL ; Save user's HL
PUSH AF ; ..and A reg for range checks
LD A,B
CP MAXDDA ; Legal Driver #?
JR NC,DIRIOX ; ..jump Error Exit if Not
PUSH BC
LD HL,DDIOTB
LD C,B ; Driver number
LD B,0
ADD HL,BC
ADD HL,BC ; Index into table
ADD HL,BC
LD A,(HL) ; Max call number
INC HL
LD C,(HL)
INC HL
LD H,(HL)
LD L,C ; Service vector table address in HL
POP BC ; Requested call
DEC A ; Correct Max Call # for Testing
JP M,DIRIOX ; ..jump Error exit if 0 --> FF (No Calls)
CP C ; Greater than Maximum Function?
JR C,DIRIOX ; ..jump Error exit if so
PUSH BC ; Else Save BC
LD B,0
ADD HL,BC
ADD HL,BC ; Add twice for Word index
LD B,(HL)
INC HL
LD H,(HL)
LD L,B ; Put vector in HL
POP BC ; Restore User's BC register
POP AF ; .Restore A and Flags
EX (SP),HL ; ..restore HL, Vector to TOS
RET ; Jump to Routine
DIRIOX: POP AF ; Clear stack
POP HL
OR 0FFH ; Set Error return
RET ; ..and quit
; Direct Disk Access Table Pointer Table
DDIOTB: DEFB 0
DEFW 00 ; No Driver 0
DEFB MAXFFN
DEFW FDFUNC ; 1 is Primary Floppy Driver
IF HARDDSK
DEFB MAXHFN
DEFW HDFUNC ; 2 is Primary Hard Disk Driver
ENDIF ;harddsk
IF [RAMDSK AND NOT HARDDSK]
DEFB 0
DEFW 00 ; (Dummy 2 if not installed)
ENDIF ;ramdsk and not harddsk
IF RAMDSK
DEFB 0
DEFW 00 ; 3 is Primary RAM Disk Driver (No Functions)
ENDIF ;ramdsk
MAXDDA EQU ($-DDIOTB)/3 ; Number of entries in pointer table
; Floppy Drive Function Table and Numbers
FDFUNC: DEFW STMODE ; 00 set mode
DEFW STSIZE ; 01 set drive size
DEFW STHDRV ; 02 set head and drive
DEFW STSECT ; 03 set sector #, size and eot
DEFW SPEC ; 04 specify srt, hlt, hut
DEFW RECAL ; 05 home the floppy
DEFW SEEK ; 06 seek track
DEFW SREAD ; 07 read
DEFW SWRITE ; 08 write
DEFW READID ; 09 read id
DEFW RETDST ; 10 return drive status & result ptr
DEFW FMTTRK ; 11 format a track
MAXFFN EQU [$-FDFUNC]/2
; Hard Disk Function Table and Numbers
IF HARDDSK
HDFUNC: DEFW HDVALS ; 00 Set Xfer Address, Return Interface Parms
DEFW HDSLCT ; 01 Select Device (& Logical Unit w/SCSI)
DEFW HD_RW ; 02 Direct Hard Disk Driver
MAXHFN EQU [$-HDFUNC]/2
ENDIF ;harddsk
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; Banked Memory Support Routines
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Bank Control Routines. Used only in Banked Systems
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
IF BANKED ; << ****** HARDWARE SPECIFIC ****** >>
; << Enter the Inter-Bank Movement >>
INCLUDE IBMV-DX.Z80 ; << routines in IBMV-xxx.Z80 >>
ELSE ; If Not Banked, Use these hooks
MOVE: LDIR
RET
SETBNK:
SELMEM:
RETMEM:
XMOVE:
GOSYSB:
FRCLR:
STFARC: RET
FRJP: JP (HL)
FRGETB: LD A,(HL)
RET
FRGETW: LD E,(HL)
INC HL
LD D,(HL)
DEC HL
RET
FRPUTB: LD (HL),A
RET
FRPUTW: LD (HL),E
INC HL
LD (HL),D
DEC HL
RET
ENDIF ;(not) banked
PAGE
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; Core BIOS Code
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Return BIOS Addresses
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CSEG
RETBIO: LD BC,BIOSJT ; Get address of bios base
LD DE,CONFIG ; Point to configuration area
LD HL,DEVCFG ; Point to Char IO Device Table
LD A,VERS ; Return BIOS Version
RET
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Return DPH Table Address
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DRVTBL: LD HL,DPHTBL ; Point to DPH table
RET
PAGE
INCLUDE BYTEIO.Z80 ; Con:, aux:, lst: redirection
PAGE
INCLUDE SELRWD.Z80 ; Physical driver link for disks
PAGE
INCLUDE DEBLOCK.Z80 ; Hstbuf deblocker
PAGE
INCLUDE SECTRAN.Z80 ; Sector translation
PAGE
IF AUTOSL
INCLUDE SELFLP2.Z80 ; Floppy disk select
ELSE
INCLUDE SELFLP1.Z80
ENDIF
PAGE
INCLUDE FLOPPY.Z80 ; Hardware independent floppy routines
PAGE
; << ****** Hardware Specific ****** >>
; << This Driver is for the Standard >>
INCLUDE FDC-DX.Z80 ; << MicroSystems (SMC) FDC37C665 >>
PAGE
; << ****** Hardware Specific ****** >>
; << Enter routines for your timer >>
INCLUDE TIM-DX.Z80 ; << and clock in TIM-xxxx.Z80 >>
PAGE
IF HARDDSK ; << ****** Hardware Specific ****** >>
IF IDE ; << Enter driver routines for your >>
INCLUDE HARDIDE.Z80 ; << Hard Disk in HARD-xxx.Z80 >>
ELSE
INCLUDE HARD-DX.Z80
ENDIF
PAGE
ENDIF
IF RAMDSK ; << ****** Hardware Specific ****** >>
INCLUDE RAMD-DX.Z80 ; << Enter driver routines for RAM >>
PAGE ; << Disk in RAMD-xxx.Z80 >>
ENDIF
; << ****** Hardware Specific ****** >>
; << Enter Warm Boot routines in >>
INCLUDE WBOOT-DX.Z80 ; << WBOOT-xx.Z80 >>
;.....
; Status bytes of general use placed at end of Data area
DSEG
HDONE: DEFS 1 ; HDC Flag 0=Ready, 1=Busy, 0FFH=Done
ERFLAG: DEFS 1 ; Disk Operation Error Code
DEFS 3 ; Reserved
; Add Character IO buffers here to insure they are at end of DSEG
IF BUFFA0 AND MORDEV AND NOT MOVCPM
COM4Q: DEFS 1 ; Char count in Queue
DEFS QSIZE ; 1 to 255 character type-ahead buffer
ENDIF
IF BUFFA1 AND MORDEV AND NOT MOVCPM
COM5Q: DEFS 1 ; Char count in Queue
DEFS QSIZE ; 1 to 255 character type-ahead buffer
ENDIF
IF (BUFFA0 OR BUFFA1) AND MORDEV AND NOT MOVCPM
DEFS 12 ; Stack for Buffered char IO routines
INTSP: DEFS 2 ; Storage for entry Stack Ptr
ENDIF
; Flags Bytes for Com1/Com2 Flow Control
IF XONOFF
COM1WT: DEFS 1 ; B7=0 - Output Ok, B7=1 - Output Stopped
COM2WT: DEFS 1 ; B0=0 - Input Ok, B0=1 - Input Halted
IF ESCC_B AND MORDEV AND NOT MOVCPM
COM3WT: DEFS 1 ; Flags for Expansion devices
ENDIF
IF ASCI_0 AND MORDEV AND NOT MOVCPM
COM4WT: DEFS 1
ENDIF
IF ASCI_1 AND MORDEV AND NOT MOVCPM
COM5WT: DEFS 1
ENDIF
ENDIF ;XonOff
PAOR: DEFS 1 ; Parallel Output Ready Flag
IF [BANKED AND ZSDOS2]
COMMON /B2RAM/ ; Put this label in Banked Memory
ENDIF ; ..else in Dseg
BRAME: DEFS 2 ; Use as dynamic sizing label for Hard Drive
; ALV buffers, and storage area for sizing.
; ALV Buffers build up from here in memory
CSEG
; Display warning if we are assembling for MOVCPM integration and the
; combined CSEG/Initialized DSEG size exceeds 1 or 2 Boot Records
PRINTX MACRO %NN
.printx %NN
ENDM
LIMIT EQU $-BIOSJT+INITCS
IF MOVCPM AND LIMIT > 4480
.printx
.printx **** BIOS too big (>4480) for Boot Tracks! ****
PRINTX %LIMIT
.printx
ELSE
IF MOVCPM AND LIMIT > 4352
.printx
.printx ++++ BIOS exceeds (>4352) 2-Sector Boot Record ++++
PRINTX %LIMIT
.printx
ENDIF
ENDIF
NSECTS EQU ($+INITCS-BIOSJT)/128+1
IF INROM
INCLUDE BOOTRAM.Z80
ENDIF
END