PAGE	66,132
	TITLE	Daffodil Test Code
	INCLUDE	DaffEQs.d
Stack	SEGMENT	STACK
	ASSUME	SS:Stack
	DB	StackSize DUP (?)
TopOfStack	EQU	StackSize
Stack	ENDS

Data	SEGMENT	PUBLIC 'Data'
; Save some room for the Interrupt Vector Table
InterruptTable	LABEL	FAR
	DD	256 DUP (?)
EndOfIntVector	LABEL	FAR
EndOfData	LABEL	WORD
Data	ENDS

Code	SEGMENT	PUBLIC 'Code'
	ASSUME	CS:Code
	ASSUME	DS:Data
	ASSUME	SS:Data

; Data in the code segment.
unknownIntVector	DD	UnknownInt


Init	LABEL	FAR
	MOV	DX, LMCSreg	; Set up lower chip select
	MOV	AX, LMCSval
	OUT	DX, AX

	MOV	DX, MMCSreg	; Set up mid range chip select
	MOV	AX, MMCSval
	OUT	DX, AX

	MOV	DX, MPCSreg	; Set up mid range size
	MOV	AX, MPCSval
	OUT	DX, AX

	MOV	DX, PACSreg	; Set up periphrial chip select
	MOV	AX, PACSval
	OUT	DX, AX

	MOV	AX, RamStart	; Establish addressing.
	MOV	DS, AX
	MOV	AX, RamSize - StackSize
	MOV	SS, AX
	MOV	SP, StackSize

Init10:				; Set up to clear the Ram at low core.
	MOV	CX, OFFSET EndOfData
	SHR	CX, 1
	MOV	AX, SEG Data
	MOV	ES, AX		; ES should point to location 0 in
				; the Daffodil.
	XOR	BX, BX
Init20:
	MOV	WORD PTR ES:[BX], 0	; Set the location to 0
	ADD	BX, 2
	LOOP	Init20

	MOV	CX, OFFSET EndOfIntVector	; This code sets all
	SHR	CX, 1
	SHR	CX, 1
	XOR	SI, SI				;  int vectors to point to
	MOV	AX, CS:unknownIntVector		;  the unknown int handler
	MOV	BX, CS:unknownIntVector + 2
Init30:
	MOV	ES:[SI], AX	; move segment of vector
	MOV	ES:[SI + 2], BX	; move offset
	ADD	SI, 4
	LOOP	Init30
	PAGE
InitCom:
	MOV	AX, 26	; Set baud rate time
	MOV	DX, comBRMaxCntB
	OUT	DX, AX
	MOV	DX, comBRMaxCntA
	OUT	DX, AX
	MOV	DX, comBRCtl
	MOV	AX, 0C003h	; Cont, Alternate
	OUT	DX, AX

; Set up 8274
	MOV	AL, 1		; Point to WR1
	OUT	comCtl, AL
	MOV	AL, 0
	OUT	comCtl, AL	; Set WR1 to 0
	MOV	AL, 2		; Point to WR2
	OUT	comCtl, AL
	MOV	AL, 0
	OUT	comCtl, AL	; Set WR2 to 0
	MOV	AL, 3		; Point to WR3
	OUT	comCtl, AL
	MOV	AL, 0C1h	; ENable Rx
	OUT	comCtl, AL
	MOV	AL, 4		; Point to WR4
	OUT	comCtl, AL
	MOV	AL, 44h		; 8 bit no parity clk/16
	OUT	comCtl, AL
	MOV	AL, 5		; Point to WR5
	OUT	comCtl, AL
	MOV	AL, 64h		; 8 bit no parity enable Tx
	OUT	comCtl, AL

;echo characters forever
main:	CALL	PutChar
	CALL	GetChar
	JMP	Main

GetChar	PROC	NEAR
	IN	AL, comCtl	; Get com channel status
	TEST	AL, comRxAvail
	JZ	GetChar	; Wait for character
	IN	AL, comData	; Get the byte
	RET
GetChar	ENDP


PutChar	PROC	NEAR
	PUSH	AX		; Save the regs
PutChar10:
	IN	AL, comCtl	; See if there is a place to put byte
	TEST	AL, comTxEmpty
	JZ	PutChar10
	POP	AX		; Get the char back
	OUT	comData, AL	; Put it out
	RET
PutChar	ENDP

UnknownInt	LABEL	FAR
	IRET

	ORG	3FF0h  ;16 bytes before the end of the 16kByte ROM
Init80186:
	MOV	DX, UMCSreg	; Set up upper chip select
	MOV	AX, UMCSval
	OUT	DX, AX
	JMP	FAR PTR Init	; Jump to start of ROM.

Code	ENDS
	END