	.IF	LIST2
	.LIST
	.PAGE
	.ELSE
	.NOLIST
	.ENDC
;****************************************************************************
;
;	BIOS Initialization.
;
;	File:	SAGE.BIOS2.TEXT
;	Date:	 7-Nov-83
;	Issue:	2D
;
;
;	COPYRIGHT (c) 1982, 1983 SAGE Computer Technology
;	All Rights Reserved
;
;****************************************************************************
;
;	History:
;
;	2     23-Mar-83 Initial SAGE IV release.
;	2A    16-May-83 Updated version number to 2.1.
;	2B     2-Jun-83 Updated version number to 2.2.
;			Added DEVINFO & WDEVINFO tables.
;			Improved test for Winchester board equipped.
;			Initialize SIGEVENT with JMP to SIGNAL.
;			Changed seek delay factors.  Set up floppys for
;			read after write.
;	2C     3-Aug-83 Updated version number to 2.3.
;			Added WT_RBWB.
;			Added new Winchester Configuration variables.
;			Revised order of buffer variables.
;			Set terminal default to XON/XOFF.
;			Delete Winchester and Extra Remote storage for floppy
;			only systems.
;	2D     7-Nov-83 Set base of RAMDisk to 23400H.
;			Updated version number to 2.4.
;			Changed serial channels to logical devices 28-31.
;			Set up logical devices 10 & 12-24 to Winchester
;			partitions.
;
;****************************************************************************



.PAGE
;****************************************************************************
;
;	Ram Variable Allocation:
;
;	  BUFFERS		Used for driver buffer storage.
;				Does not occupy space in code file.
;
;	  CONFIG		At block 1 of code file.
;				This area may be maintained by a configuration
;				maintenance routine.
;
;	  RAMWORK		Main scratch area for BIOS is in the user
;				interrupt vector tables (never used with this
;				hardware).  This allows the usage of the
;				short direct addressing mode.
;
;****************************************************************************

CONFIG	.EQU	*		;Base of configuration storage area

;	Define buffers below CONFIG
;	Note:  This buffer area is defined with Equates previous to the
;	       base of the file to keep it from creating space in the
;	       code file.  The area must be considered when allocating
;	       room for the BIOS.  The size in bytes of the buffer area
;	       is contained in the second word of the files code area.
;
;	BIOS data areas (always accessed via an address register)

WDEVINFO.EQU	CONFIG-128.	;Winchester Device Information Table
DEVINFO .EQU	WDEVINFO-32.	;Device Information Table
BIOSMAP .EQU	DEVINFO-64.	;BIOS Device map
FI_DRV0 .EQU	BIOSMAP-36.	;Floppy drive 0 information
FI_DRV1 .EQU	FI_DRV0-36.	;Floppy drive 1 information
FT_SCHED.EQU	FI_DRV1-12.	;Floppy scheduler entry
FT_DLY	.EQU	FT_SCHED-12.	;Floppy task delay schedule
FC_GCMD .EQU	FT_DLY-10.	;General floppy command area
FI_DRVMT.EQU	FC_GCMD-20.	;Floppy motor control variables
KEYSCH	.EQU	FI_DRVMT-12.	;Keyboard runaway lockout schedule
PRTSCHD .EQU	KEYSCH-12.	;Printer schedule for polling
EVNTCTR .EQU	PRTSCHD-64.	;Event counter table
ATCHTBL .EQU	EVNTCTR-64.	;Attach enabled table
SCHEV63 .EQU	ATCHTBL-18.	;Scheduled event #63.
SCHEV39 .EQU	SCHEV63-18.	;Scheduled event #39.
SCHEV38 .EQU	SCHEV39-18.	;Scheduled event #38.
SCHEV37 .EQU	SCHEV38-18.	;Scheduled event #37.
SCHEV36 .EQU	SCHEV37-18.	;Scheduled event #36.

KEYBUF	.EQU	SCHEV36-256.	;Keyboard input buffer
TRMBUF	.EQU	KEYBUF-256.	;Console terminal output buffer
PRTBUF	.EQU	TRMBUF-256.	;Printer buffer
RINBUF0 .EQU	PRTBUF-256.	;Remote input buffer
ROTBUF0 .EQU	RINBUF0-256.	;Remote output buffer
REMDAT0 .EQU	ROTBUF0-REMDATSZ ;Remote channel #0 variables


SMALLBUF.EQU	REMDAT0		;Base of buffers for floppy system


RINBUF4 .EQU	SMALLBUF-256.	;Remote input buffer
ROTBUF4 .EQU	RINBUF4-256.	;Remote output buffer
RINBUF3 .EQU	ROTBUF4-256.	;Remote input buffer
ROTBUF3 .EQU	RINBUF3-256.	;Remote output buffer
RINBUF2 .EQU	ROTBUF3-256.	;Remote input buffer
ROTBUF2 .EQU	RINBUF2-256.	;Remote output buffer
RINBUF1 .EQU	ROTBUF2-256.	;Remote input buffer
ROTBUF1 .EQU	RINBUF1-256.	;Remote output buffer
REMDAT4 .EQU	ROTBUF1-REMDATSZ ;Remote channel #4 variables
REMDAT3 .EQU	REMDAT4-REMDATSZ ;Remote channel #3 variables
REMDAT2 .EQU	REMDAT3-REMDATSZ ;Remote channel #2 variables
REMDAT1 .EQU	REMDAT2-REMDATSZ ;Remote channel #1 variables
WG_VTBL .EQU	REMDAT1-16.	;Winchester Variable pointers
WG_VAR3 .EQU	WG_VTBL-WI_SIZE ;Winchester #3 table
WG_VAR2 .EQU	WG_VAR3-WI_SIZE ;Winchester #2 table
WG_VAR1 .EQU	WG_VAR2-WI_SIZE ;Winchester #1 table
WG_VAR0 .EQU	WG_VAR1-WI_SIZE ;Winchester #0 table
WT_TIMO .EQU	WG_VAR0-12.	;Winchester transfer timeout schedule
WT_RBWB .EQU	WT_TIMO-9728.	;Winchester Read Before Write Buffer

BUFFERS .EQU	WT_RBWB		;Base of buffer area

;	Configuration area
	.ASCII	"BIOS"		;Offset:  0 is the BIOS code file
				;identification.  This should be
				;checked by loaders and configuration
				;maintenance routines to insure that
				;the file is an actual BIOS file.
				
	.WORD	ENDLABEL-CONFIG ;Offset:  4 is the size of the BIOS
				;code file (configuration, and actual code).
				;This may be accessed by loaders.
				
	.WORD	CONFIG-BUFFERS	;Offset:  6 is the size of the buffer area.
				;This may be accessed by loaders to help
				;determine the true BIOS memory requirements.

	.WORD	INITBIOS-CONFIG ;Offset:  8 is the offset of the starting
				;address of the BIOS initialization.

VERSION .BYTE	4		;Offset: 10. is BIOS Subsidiary version
	.BYTE	2		;Offset: 11. is BIOS Major Version
	
FLCONF0				;Offset: 12. is Floppy #0 information
	.BYTE	2		;Number of sides
	.BYTE	80.		;Number of cylinders
	.BYTE	8		;Number of sectors per track
	.BYTE	42.		;Gap3 parameter
	.BYTE	0		;Track to track skew (not used yet)
	.BYTE	0FFH		;Data length factor (DTL)
	.WORD	512.		;Bytes per sector
	.WORD	9600H		;Motor On delay (600 milliseconds)
	.BYTE	0D1H		;Step rate (6 milliseconds)
	.BYTE	7		;Head load time (16 milliseconds)
	.BYTE	40H		;MFM (double density flag)
	.BYTE	4		;IBM track format flag
				;Bit 0 - IBM cylinder orientation
				;Bit 1 - NCI sector numbering
				;Bit 2 - read after write
	.BYTE	4		;Retry count + main attempt
	.BYTE	0		;Ignore errors flag
	.BYTE	0		;Soft error counter
	.BYTE	0		;Double step flag
	.BYTE	0E5H		;Format data pattern
	.BYTE	80.		;Format Gap 3
	.BLOCK	12.		;Reserved for expansion

FLCONF1				;Offset: 44. is Floppy #1 information
	.BYTE	2		;Number of sides
	.BYTE	80.		;Number of cylinders
	.BYTE	8		;Number of sectors per track
	.BYTE	42.		;Gap3 parameter
	.BYTE	0		;Track to track skew (not used yet)
	.BYTE	0FFH		;Data length factor (DTL)
	.WORD	512.		;Bytes per sector
	.WORD	9600H		;Motor On delay (600 milliseconds)
	.BYTE	0D1H		;Step rate (6 milliseconds)
	.BYTE	7		;Head load time (16 milliseconds)
	.BYTE	40H		;MFM (double density flag)
	.BYTE	4		;IBM track format flag
				;Bit 0 - IBM cylinder orientation
				;Bit 1 - NCI sector numbering
				;Bit 2 - read after write
	.BYTE	4		;Retry count + main attempt
	.BYTE	0		;Ignore errors flag
	.BYTE	0		;Soft error counter
	.BYTE	0		;Double step flag
	.BYTE	0E5H		;Format data pattern
	.BYTE	80.		;Format Gap 3
	.BLOCK	12.		;Reserved for expansion
	
TRMCONF .WORD	0		;Offset: 76. is the terminal baud rate
				;parameter (0 defaults to switches)
				
	.BYTE	6EH		;Offset: 78. is the terminal USART parameter
				;(1 stop bit, 8 data bits, and even parity
				; disabled - may be enabled by switch option)

	.BYTE	2		;Offset: 79. is Terminal type flags
				;Bit 0 on means Debugger Break enabled
				;Bit 1 on means use XON/XOFF for output.

RMTCONF .WORD	0		;Offset: 80. is the Remote baud
				;rate parameter (0 defaults to 9600 baud)
				
	.BYTE	7AH		;Offset: 82. is the Remote USART parameter
				;(1 stop bit, 7 data bits, and even parity)

	.BYTE	0		;Offset: 83. is the Remote channel control
				;byte.
				;Bit 0 set indicates use XON/XOFF on input.
				;Bit 1 set indicates use XON/XOFF on output.
	
	.WORD	4000H		;Offset 84. is Remote Transmit delay (2 bytes)
	
	.BYTE	1		;Offset 86. is flag to check DSR (1 byte)
	
	.BYTE	0		;Unused
	
RAMDISK				;Offset: 88. is RAM disk address base & top
	.WORD	2,3400H		;Base: 23400H
	.WORD	0,0		;Top: (0 = default below BIOS)
	
	.BYTE	0		;Offset: 96. is RAM Disk Boot Flag
				;  0 = don't boot from RAM Disk
				;  1 = copy diskette to RAM Disk and
				;	boot from RAM Disk
	
	.BYTE	0		;CPM block format flag
	
	
PRTCONF				;Offset: 98. is Printer poll timeout
	.WORD	500.		;  This is the number of 4.25 microsecond
				;  polling tries the driver tries before
				;  scheduling a poll delay.
				;  (236. = 1 millisecond)

	.WORD	236.		;Offset: 100. is Printer poll delay
				;  This is the number of 1/64000 ths of
				;  a second that should be delayed before
				;  trying to re-poll the printer channel.
				
				;Offset: 102. is Printer mode
	.BYTE	2		;  0 = no printer
				;  1 = use serial (remote) channel
				;  2 = parallel port using interrupts
				;  3 = parallel port with scheduled polling
	
	.BYTE	0		;Offset: 103. is Printer Option Flags
				;  Bit 0 = inhibit LF after CR
	
	.BYTE	0		;Offset: 104. is Time adjustment x days
	
	.BYTE	0		;Offset: 105. is Time adjustment # seconds
	
;	Area reserved for operating system dependent configuration
OPSYS	.BLOCK	32.
	
;	Channel Map
CHMAP	.BYTE	0,0		; 0
	.BYTE	0,1		; 1
	.BYTE	0,2		; 2
	.BYTE	0,3		; 3
	.BYTE	0,4		; 4
	.BYTE	0,5		; 5
	.BYTE	0,6		; 6
	.BYTE	0,7		; 7
	.BYTE	0,8		; 8
	.BYTE	1,9.		; 9
	.BYTE	2,9.		;10
	.BYTE	0,11.		;11
	.BYTE	3,9.		;12
	.BYTE	4,9.		;13
	.BYTE	5,9.		;14
	.BYTE	6,9.		;15
	.BYTE	7,9.		;16
	.BYTE	8,9.		;17
	.BYTE	9.,9.		;18
	.BYTE	10.,9.		;19
	.BYTE	11.,9.		;20
	.BYTE	12.,9.		;21
	.BYTE	13.,9.		;22
	.BYTE	14.,9.		;23
	.BYTE	15.,9.		;24
	.BYTE	0,0		;25
	.BYTE	0,0		;26
	.BYTE	0,0		;27
	.BYTE	0,13.		;28
	.BYTE	0,14.		;29
	.BYTE	0,15.		;30
	.BYTE	0,16.		;31

;	Device Information Table
	.BLOCK	32.


;	First extra serial channel
RMTCONF1.WORD	0		;Offset: 106. is the Remote baud
				;rate parameter (0 defaults to 9600 baud)
				
	.BYTE	7AH		;Offset: 108. is the Remote USART parameter
				;(1 stop bit, 7 data bits, and even parity)

	.BYTE	0		;Offset: 109. is the Remote channel control
				;byte.
				;Bit 0 set indicates use XON/XOFF on input.
				;Bit 1 set indicates use XON/XOFF on output.
	
	.WORD	0		;Offset 110. is Remote Transmit delay (2 bytes)
	
	.BYTE	0		;Offset 112. is flag to check DSR (1 byte)
	
	.BYTE	0		;Unused
	
;	Second extra channel
	.WORD	0		;Offset: 114. is the Remote baud
				;rate parameter (0 defaults to 9600 baud)
				
	.BYTE	7AH		;Offset: 116. is the Remote USART parameter
				;(1 stop bit, 7 data bits, and even parity)

	.BYTE	0		;Offset: 117. is the Remote channel control
				;byte.
				;Bit 0 set indicates use XON/XOFF on input.
				;Bit 1 set indicates use XON/XOFF on output.

	.WORD	0		;Offset 118. is Remote Transmit delay (2 bytes)

	.BYTE	0		;Offset 120. is flag to check DSR (1 byte)

	.BYTE	0		;Unused

;	Third extra channel
	.WORD	0		;Offset: 122. is the Remote baud
				;rate parameter (0 defaults to 9600 baud)

	.BYTE	7AH		;Offset: 124. is the Remote USART parameter
				;(1 stop bit, 7 data bits, and even parity)

	.BYTE	0		;Offset: 125. is the Remote channel control
				;byte.
				;Bit 0 set indicates use XON/XOFF on input.
				;Bit 1 set indicates use XON/XOFF on output.

	.WORD	0		;Offset 126. is Remote Transmit delay (2 bytes)

	.BYTE	0		;Offset 128. is flag to check DSR (1 byte)

	.BYTE	0		;Unused

;	Fourth extra serial channel
	.WORD	0		;Offset: 130. is the Remote baud
				;rate parameter (0 defaults to 9600 baud)

	.BYTE	7AH		;Offset: 132. is the Remote USART parameter
				;(1 stop bit, 7 data bits, and even parity)

	.BYTE	0		;Offset: 133. is the Remote channel control
				;byte.
				;Bit 0 set indicates use XON/XOFF on input.
				;Bit 1 set indicates use XON/XOFF on output.

	.WORD	0		;Offset 134. is Remote Transmit delay (2 bytes)

	.BYTE	0		;Offset 136. is flag to check DSR (1 byte)

	.BYTE	0		;Unused

				;Next offset is 138.


;	Winchester configurations
WI_CONF0
	.WORD	306.		;Number of tracks
	.WORD	512.		;Number of bytes per sector
	.WORD	250.		;Step Time (gives 4 milliseconds)
	.WORD	20.		;Slew Time (306 microseconds)
	.WORD	16.		;Counter step time (16 microseconds)
	.WORD	840.		;Head settle time
	.WORD	306.		;Cylinder for beginning precomp
	.WORD	0		;Special type flags
	.WORD	0		;Special test flags
	.WORD	329.		;Shipping track
	.WORD	400.		;Header count
	.WORD	1100.		;Low read count
	.WORD	1140.		;High read count
	.BYTE	2		;Number of heads
	.BYTE	19.		;Number of sectors per track
	.BYTE	1		;Drive select bit
	.BYTE	11.		;Number of retries
	.BYTE	0		;Reserved for first error code
	.BYTE	0		;Reserved for last error code
	.BYTE	0		;Reserved for last hard error
	.BYTE	0		;Soft errors
	.WORD	0		;Seek under time count
	.WORD	0		;CRC value
	.WORD	4000H		;Sync bit
	.WORD	0		;Extra head settle time
	.BYTE	5		;Read after Write retry count
	.BYTE	3		;Write retry count
	.BLOCK	16.		;Reserved for expansion

WI_CONFS.EQU	*-WI_CONF0	;Size of configuration area

WI_CONF1
	.WORD	0		;Number of tracks
	.WORD	512.		;Number of bytes per sector
	.WORD	250.		;Step Time (gives 4 milliseconds)
	.WORD	20.		;Slew Time (306 microseconds)
	.WORD	16.		;Counter step time (4 microseconds)
	.WORD	840.		;Head settle time
	.WORD	306.		;Cylinder for beginning precomp
	.WORD	0		;Special type flags
	.WORD	0		;Special test flags
	.WORD	329.		;Shipping track
	.WORD	400.		;Header count
	.WORD	1100.		;Low read count
	.WORD	1140.		;High read count
	.BYTE	2		;Number of heads
	.BYTE	19.		;Number of sectors per track
	.BYTE	2		;Drive select bit
	.BYTE	11.		;Number of retries
	.BYTE	0		;Reserved for first error code
	.BYTE	0		;Reserved for last error code
	.BYTE	0		;Reserved for last hard error
	.BYTE	0		;Soft error count
	.WORD	0		;Seek under time count
	.WORD	0		;CRC value
	.WORD	4000H		;Sync bit
	.WORD	0		;Extra head settle time
	.BYTE	5		;Read after Write retry count
	.BYTE	3		;Write retry count
	.BLOCK	16.		;Reserved for expansion

WI_CONF2
	.WORD	0		;Number of tracks
	.WORD	512.		;Number of bytes per sector
	.WORD	250.		;Step Time (gives 4 milliseconds)
	.WORD	20.		;Slew Time (306 microseconds)
	.WORD	16.		;Counter step time (4 microseconds)
	.WORD	840.		;Head settle time (19 milliseconds)
	.WORD	306.		;Cylinder for beginning precomp
	.WORD	0		;Special type flags
	.WORD	0		;Special test flags
	.WORD	329.		;Shipping track
	.WORD	400.		;Header count
	.WORD	1100.		;Low read count
	.WORD	1140.		;High read count
	.BYTE	2		;Number of heads
	.BYTE	19.		;Number of sectors per track
	.BYTE	4		;Drive select bit
	.BYTE	11.		;Number of retries
	.BYTE	0		;Reserved for first error code
	.BYTE	0		;Reserved for last error code
	.BYTE	0		;Reserved for last hard error
	.BYTE	0		;Soft error count
	.WORD	0		;Seek under time count
	.WORD	0		;CRC value
	.WORD	4000H		;Sync bit
	.WORD	0		;Extra head settle time
	.BYTE	5		;Read after Write retry count
	.BYTE	3		;Write retry count
	.BLOCK	16.		;Reserved for expansion

WI_CONF3
	.WORD	0		;Number of tracks
	.WORD	512.		;Number of bytes per sector
	.WORD	250.		;Step Time (gives 4 milliseconds)
	.WORD	20.		;Slew Time (306 microseconds)
	.WORD	16.		;Counter step time (4 microseconds)
	.WORD	840.		;Head settle time
	.WORD	306.		;Cylinder for beginning precomp
	.WORD	0		;Special type flags
	.WORD	0		;Special test flags
	.WORD	329.		;Shipping track
	.WORD	400.		;Header count
	.WORD	1100.		;Low read count
	.WORD	1140.		;High read count
	.BYTE	2		;Number of heads
	.BYTE	19.		;Number of sectors per track
	.BYTE	8		;Drive select bit
	.BYTE	11.		;Number of retries
	.BYTE	0		;Reserved for first error code
	.BYTE	0		;Reserved for last error code
	.BYTE	0		;Reserved for last hard error
	.BYTE	0		;Soft error count
	.WORD	0		;Seek under time count
	.WORD	0		;CRC value
	.WORD	4000H		;Sync bit
	.WORD	0		;Extra head settle time
	.BYTE	5		;Read after Write retry count
	.BYTE	3		;Write retry count
	.BLOCK	16.		;Reserved for expansion

WDEVTBL .BLOCK	128.		;Winchester Device Table

	.ASCII	"Copyright (c) 1983  Sage Computer Technology, "
	.ASCII	"All Rights Reserved"
	.ALIGN	2


.PAGE
;****************************************************************************
;
;	Startup initialization
;
;	Uses register A0
;
;****************************************************************************

INITBIOS
	MOVEM.L D0/D1/A0-A2,-(A7) ;Save registers
	MOVEQ	#-1,D0		;Set up delay for USART to finish
$10	DBF	D0,$10		;  any previous output.
	MOVE	#2700H,SR	;Disable all interrupts

;	Clear BIOS storage area (except BIOSBASE)
	MOVE.W	#<<RAMSTOP-BIOSADDR>/2>-1,D0
	LEA	BIOSADDR,A0
$20	CLR.W	(A0)+
	DBF	D0,$20
	
	LEA	CONFIG,A0	;Define the start of the BIOS for debugging
	MOVE.L	A0,BIOSADDR	;Store at location 200H

;	Set up TRAP vectors
	LEA	POLL,A0
	MOVE.L	A0,T8_TRAP
	LEA	BIOS_L,A0
	MOVE.L	A0,T14_TRAP
	
;	Set up Floppy & Dip switch 8255
;	  A = mode 0 input
;	  B = mode 0 input
;	  C (upper) = output
;	  C (lower) = output
	MOVE.B	#092H,F8255
	MOVE.B	#0F8H,DIPSWT+4	;Initial C bits

;	Set up Centronics 8255
;	  A = mode 0 output
;	  B = mode 0 input
;	  C (upper) = output
;	  C (lower) = output
	MOVE.B	#082H,C8255+6
	MOVE.B	#030H,C8255+4	;Initial C bits
	
;	Set up 8259 interrupt encoder
	LEA	INT8259,A1	;Set up 8259 interrupt vector
	MOVE.L	A1,A1_TRAP
	MOVE.B	#12H,P8259	;Initialize 8259
	MOVE.B	#0,P8259+2
	MOVE.B	#30H,P8259+2	;Initial interrupt mask

;	Check if machine is SAGE IV (one with Winchester vs Floppy Only)
	BSR	TSTSAGE4
	MOVE.B	D0,SAGE4	;Set up SAGE IV flag
	BEQ.S	$30		;Bypass SAGE IV interrupt encoder

;	Set up 8259 interrupt encoder for extra serial channels
	LEA	I8259SER,A1	;Set up 8259 interrupt vector
	MOVE.L	A1,A2_TRAP
	MOVE.B	#12H,SER8259	;Initialize 8259
	MOVE.B	#0,SER8259+2
	MOVE.B	#0,SER8259+2	;Initial interrupt mask

;	Set up 8255's on winchester board
	MOVE.B	#90H,WP_1CB	;Init 8255 #1
	MOVE.B	#90H,WP_2CB	;Init 8255 #2
	MOVE.B	#0,WP_1B
	MOVE.B	#0C9H,WP_2B
	MOVE.B	#0,WP_1C
	MOVE.B	#5,WP_2C

$30	MOVE.B	#0EH,F8255	;Turn off floppy controller reset strobe

;	Initialize real time clock
	MOVE.B	#34H,BRATE+6	;First counter stage into mode 2
	MOVE.B	#30H,TIMER+6	;Second counter stage into mode 0
	CLR.B	D1
	MOVE.B	#2,BRATE	;Set up fastest count to first stage = 2
	MOVE.B	D1,TIMER	;Low count to second stage = 0
	MOVE.B	D1,BRATE	;High count to first stage
	MOVE.B	D1,TIMER	;High count to second stage
	
;	Delay for 80 microseconds to allow time for first stage to
;	generate an output pulse so that the second stage count will be loaded.
	MOVEQ	#64.,D1
$40	DBF	D1,$40

;	Now apply final divide by 64000 to first stage
	MOVE.W	C64000,D0
	MOVE.B	D0,BRATE	;Low count to first stage
	LSR.W	#8,D0
	MOVE.B	D0,BRATE	;High count to first stage


;	Now Initialize Tables
;	Set up for Winchester system
TBLINIT LEA	BUFFERS,A0
	MOVE.W	#<<CONFIG-BUFFERS>/2>-1,D0
	TST.B	SAGE4		;Check if full machine
	BNE.S	$10		;Was Winchester system
	LEA	SMALLBUF,A0 ;Set up for floppy only
	MOVE.W	#<<CONFIG-SMALLBUF>/2>-1,D0
$10	MOVEA.L A0,A1		;Save base of area
	SUBA.W	#512.,A1

$20	CLR.W	(A0)+		;Clear this BIOS Data Area
	DBF	D0,$20

;	Set up BIOSBASE if not using old bootstrap
	LEA	BUFFERS-512.,A0
	CMPA.L	BIOSBASE,A0
	BEQ.S	$30		;May be using old boot
	MOVE.L	A1,BIOSBASE

$30	LEA	TRMCONF,A0	;Transfer device configuration to tables
	LEA	TBAUD,A1
	MOVE.W	#<<RDISKB-TBAUD>/2>-1,D0
$40	MOVE.W	(A0)+,(A1)+
	DBF	D0,$40
	LEA	RAMDISK,A0
	MOVE.W	#<<CONFEND-RDISKB>/2>-1,D0
$50	MOVE.W	(A0)+,(A1)+
	DBF	D0,$50
	

;	Set up BIOSMAP & DEVINFO
	LEA	BIOSMAP,A0
	LEA	CHMAP,A1
	MOVEQ	#24.-1,D0	;Includes DEVINFO
$60	MOVE.L	(A1)+,(A0)+
	DBF	D0,$60

	BSR	INSTALLTP	;Install TRAPs

;	Set up floppy driver
	LEA	FDNOINT,A0	;Establish default floppy interrupt routine
	MOVE.L	A0,A6_TRAP

;	Set up main terminal channel
	LEA	KEYINT,A0	;Set up keyboard interrupt vector
	MOVE.L	A0,A5_TRAP
	LEA	BREAKDF,A0	;Set up default Break routine
	MOVE.L	A0,BREAKV
	LEA	SPECCHDF,A0	;Set up default special characters
	MOVE.L	A0,SPECCHAR
	ADDQ.L	#1,A0		;Set up default No Break flag pointer
	MOVE.L	A0,NOBREAKP
	BSR	TERMINIT	;Initialize Terminal USART

;	Set up Remote (auxillary) channels
RMTINIT MOVE.L	A4,-(SP)
	LEA	REMDAT0,A4	;Set up fixed data table area
	LEA	ROTBUF0,A0	;Buffer address
	LEA	IREMTBL,A1	;Init info address
	LEA	RMTCONF,A2	;Configuration address
	MOVEQ	#5-1,D0
$10	MOVE.L	(A1)+,REMUSD(A4)
	MOVE.L	(A1)+,RINATCH(A4)
	MOVE.L	(A2)+,RBAUD(A4)
	MOVE.L	(A2)+,RMTDTM(A4)
	MOVE.L	A0,ROTBUF(A4)
	ADDA.W	#256.,A0
	MOVE.L	A0,RINBUF(A4)
	ADDA.W	#256.,A0
	ST	REMEQU(A4)
	PEA	RAMDISK
	CMPA.L	(SP)+,A2
	BNE.S	$20		;Not first channel
	BSR	AUXINIT
	TST.B	SAGE4		;Check if other channels exist
	BEQ.S	$40		;Channels do not exist
	LEA	RMTCONF1,A2
	LEA	ROTBUF1,A0
	LEA	REMDAT1,A4
	BRA.S	$30

$20	MOVE.B	#1,REMCHN(A4)	;Set up extra channel type
	BSR	AUXINIT
	ADDA.W	#REMDATSZ,A4
$30	DBF	D0,$10

$40	MOVEA.L (SP)+,A4

;	Initialize floppy disk drive tables
	LEA	FLCONF0,A0	;Default table values
	LEA	FI_DRV0,A1
	MOVEQ	#8-1,D0		;Set up long word count
$50	MOVE.L	(A0)+,(A1)+
	DBF	D0,$50
	
	LEA	FLCONF1,A0	;Now same for second drive
	LEA	FI_DRV1,A1
	MOVEQ	#8-1,D0
$60	MOVE.L	(A0)+,(A1)+
	DBF	D0,$60

;	Initialize RAM disk
	BSR	SSCHN11		;System startup channel 11

;	Disable second board devices if no second board
	TST.B	SAGE4
	BNE.S	$70		;Have second board
	BSR	NOSAGE4		;Disable second board drivers
	BRA.S	$90
	
;	Initialize the Winchester driver
$70	BSR	SSCHN9
;	Set up Winchester Device Information Table
	LEA	WDEVINFO,A0
	LEA	WDEVTBL,A1
	MOVEQ	#32.-1,D0
$80	MOVE.L	(A1)+,(A0)+
	DBF	D0,$80


	
;	Initialize the Event system
$90	CLR.B	DISABLE
	LEA	$100,A0		;Default event routine is just return
	MOVE.L	A0,EVENTA
	MOVE.L	A0,IOCONFA	;Also default I/O configuration in interp
	MOVE.W	#4EF9H,SIGEVENT ;Set up jump to long direct address
	LEA	SIGNAL,A0
	MOVE.L	A0,SIGEVENT+2
	

;	Done with BIOS initialization
	MOVEM.L (A7)+,D0/D1/A0-A2 ;Restore registers
	MOVE	#2000H,SR	;Enable all interrupts
	
$100	RTS			;Default Event routine



;	Test for responce from Winchester board
;	D0 = 0 for non existant, 1 for existant
TSTSAGE4
	MOVEQ	#1,D0
	MOVE.L	BE_TRAP,-(SP)	;Redirect the Bus Error Trap
	PEA	TSTDTACX
	MOVE.L	(SP)+,BE_TRAP
	MOVE.B	#90H,WP_2CB
	TST.B	D0
	BEQ.S	$10		;Must have gotten Bus error
	MOVE.B	#0C9H,WP_2B	;Write to a port
	MOVE.B	#90H,WP_1CB	;Disturb the pattern
	CMPI.B	#0C9H,WP_2B	;Verify data
	BEQ.S	$10		;Must exist
	MOVEQ	#0,D0		;Does not exist
$10	MOVE.L	(SP)+,BE_TRAP	;Restore Bus Error Trap
	RTS
	
;	Bus Error routine for non-existant location
TSTDTACX
	ADDQ.L	#8,SP		;Bypass extra info on stack
	MOVEQ	#0,D0
	RTE


;	Install TRAPs
INSTALLTP
	MOVEM.L A1/D1,-(SP)
	LEA	BIOSMAP,A1
	MOVE.B	3(A1),D0
	ST	D1		;Indicate input
	BSR.S	$10		;Get keyboard vector
	MOVE.L	A0,T9_TRAP
	MOVE.B	5(A1),D0
	CLR.B	D1		;Indicate output
	BSR.S	$10		;Get terminal vector
	MOVE.L	A0,T10_TRAP
	MOVE.B	13.(A1),D0
	BSR.S	$10		;Get Printer vector
	MOVE.L	A0,T11_TRAP
	MOVE.B	15.(A1),D0
	ST	D1		;Indicate input
	BSR.S	$10		;Get Remote-in vector
	MOVE.L	A0,T12_TRAP
	MOVE.B	17.(A1),D0
	CLR.B	D1		;Indicate output
	BSR.S	$10		;Get Remote-Out vector
	MOVE.L	A0,T13_TRAP
	MOVEM.L (SP)+,A1/D1
	RTS

;	Fetch devices vector
$10	CMP.B	#1,D0
	BNE.S	$20		;Not physical keyboard channel
	LEA	KEYIN,A0
	RTS
	
$20	CMP.B	#2,D0
	BNE.S	$30		;Not physical terminal channel
	LEA	TRMOUT,A0
	RTS
	
$30	CMP.B	#6,D0
	BNE.S	$40		;Not physical parallel printer channel
	LEA	PRTOUT,A0
	RTS

$40	CMP.B	#7,D0
	BNE.S	$50		;Not physical remote-in channel
	LEA	REMINT,A0
	RTS
	
$50	CMP.B	#8,D0
	BNE.S	$60		;Not physical remote-out channel
	LEA	REMOUTT,A0
	RTS
	
$60	CMP.B	#13.,D0
	BNE.S	$70		;Not Extra Serial #1 channel
	LEA	REMINT1,A0	;Default to input
	TST.B	D1
	BNE.S	$65		;Was input direction
	LEA	REMOUTT1,A0
$65	RTS
	
$70	CMP.B	#14.,D0
	BNE.S	$80		;Not Extra Serial #2 channel
	LEA	REMINT2,A0	;Default to input
	TST.B	D1
	BNE.S	$75		;Was input direction
	LEA	REMOUTT2,A0
$75	RTS

$80	CMP.B	#15.,D0
	BNE.S	$90		;Not Extra Serial #3 channel
	LEA	REMINT3,A0	;Default to input
	TST.B	D1
	BNE.S	$85		;Was input direction
	LEA	REMOUTT3,A0
$85	RTS

$90	CMP.B	#16.,D0
	BNE.S	$100		;Not Extra Serial #4 channel
	LEA	REMINT4,A0	;Default to input
	TST.B	D1
	BNE.S	$95		;Was input direction
	LEA	REMOUTT4,A0
$95	RTS
	

;	Failed
$100	LEA	$110,A0		;TRAP default
	RTS
	
;	Default TRAP routine
$110	RTE


                                                                                                                       