; B5DEC1.INS - Morrow Decision 1 insert for BYE5 - 08/06/88
;
;	     8250 I/O with built-in baudrate generator
;
;	      Note:  This is an insert not an overlay
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
; 08/06/88  Modified B5H8-2.INS - Heath H89 insert for 
;           use with Morrow Wunderbuss I/O S100 board.
;	    Renamed B5DEC1.INS                          - Ronald E. Jacobs
; 07/27/85  Fixed LOADBD code so it will work with BYE5.  Used stuff
;           from M7H8-7.                	   	- Bill Wood
; 06/16/85  Put in missing RET just before MDINP.       - Bill Wood	
; 06/10/85  Written for use with BYE335 or later	- Irv Hoff
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
;-----------------------------------------------------------------------
;
; The following define the port address to use.
;
base	EQU	048H		; Data port
MDCTL3	EQU	base+3		; Line control register
MDCTL4	EQU	base+4		; Modem control register
MDCTL5	EQU	base+5		; Line status register
MDCTL6	EQU	base+6		; Modem status register
grpctl	EQU	base+7		;group select port
group2	EQU	2		;use second serial port for modem
;
BD300:	DW	0180H		; 300 baud
BD1200:	DW	0060H		; 1200 bps
BD2400:	DW	0030H		; 2400 bps
;
;
;-----------------------------------------------------------------------
;
; See if we still have a carrier - if not, return with the zero flag set
;
MDCARCK:mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	IN	MDCTL6		; Get modem status
	ANI	80H		; Got a carrier?
	RET
;.....
;
;
; Disconnect and wait for an incoming call
;
MDINIT:	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	XRA	A		; Shut off DTR & RTS
	OUT	MDCTL4		; Which turns off modem.
	PUSH	B		; Preserve since we need it
	MVI	B,20		; 2 seconds delay to drop any carrier
;
OFFTI:	CALL	DELAY		; .1 second delay
	DCR	B
	JNZ	OFFTI		; Loop until done
	POP	B		; Restore BC
	MVI	A,03H		; 8-level, 1 stop bit, no parity
	OUT	base+3		; Line control register (03=1, 07=2)
	MVI	A,03H		; Turn on DTR and RTS & wait for call
	OUT	MDCTL4
;
	 IF	IMODEM
	CALL	IMINIT		; Init smartmodem
	 ENDIF			; IMODEM
;
	RET
;.....
;
;
; Input a character from the modem port
;
MDINP:	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	IN	base		; Get character
	RET
;.....
;
;
; Check the status to see if a character is available.	if not, return
; with the zero flag set.  If yes, use 0FFH to clear the flag.
;
MDINST:	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	IN	MDCTL5		; Get status
	ANI	01H		; Check receive ready bit
	RZ			; Return if not ready
	ORI	0FFH		; We have a character
	RET
;.....
;
;
; Send a character to the modem
;
MDOUTP:	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	OUT	base		; Send it
	RET
;.....
;
;
; See if the output is ready for another character
;
MDOUTST:mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	IN	MDCTL5
	ANI	20H		; Check transmit ready bit
	RET
;.....
;
;
; Reinitialize the modem and hang up the phone by dropping DTR and
; leaving it inactive.
;
MDQUIT:	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	 IF	IMODEM
	CALL	IMQUIT
	 ENDIF			; IMODEM
;
;
; Called by the main program after caller types BYE
;
MDSTOP:	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	XRA	A		; Turn off DTR (in case NORING was on)
	OUT	MDCTL4
	RET
;.....
;
;
; The following routine sets the baudrate.  BYE3 asks for the maximum
; speed you have available.
;
;
SETINV:	ORI	0FFH
	RET
;.....
;
;
SET300:	LHLD	BD300		; Get 300 baud parameters in HL
	JMP	LOADBD		; Go load them
;
SET1200:LHLD	BD1200
	JMP	LOADBD
;
SET2400:LHLD	BD2400
;
LOADBD:	DI			; Turn off interrupts for initialization
	mvi	a,group2	;select second serial port
	out	grpctl		;output to group select port
	XRA	A
	OUT	base+1		; Interrupt enable register
	MVI	A,80H		; Insure out of mode to set baud rate
	OUT	base+3		; Line control register
	MOV	A,L		; Get least significant baud rate byte
	OUT	base
	MOV	A,H		; Get most signifcant baud rate byte
	OUT	base+1
	MVI	A,03H		; 8-level, 1 stop bit, no parity
	OUT	base+3		; Line control register (03=1, 07=2)
	MVI	A,01H		; Set 'DTR' nromal
	OUT	base+4		; Modem control register
	EI			; Restore interrupts to normal
	RET
;.....
;
;			       end
;-----------------------------------------------------------------------
