; NUR3-1.INS - TRS-80 Model III insert for NUBYE - 04/21/86
;
; TR1602 I/O and BR19411 baudrate generator
;
; Note:  This is an insert not an overlay
;
; There were a few different suppliers of hardware modifications to
; enable CP/M support on the TRS-80 Mod III.  If you have trouble
; with this insert, try the insert for the Mod IV (NUR4-x.INS).
;
; ========
;
; 04/21/86  Modified for NUBYE.  The above description was also wrong --
;	    Only the Model III required a hardware mod for CP/M support,
;	    NOT the Mod IV which runs Montezuma Micro CP/M...
;						- Tom Brady
; 07/17/85  Written to work with BYE5		- Irv Hoff
;
; ========
;
; Modem port equates
;
PORT	EQU	0EBH		; Modem port
MDCTL1	EQU	PORT-1		; Status port
MDCTL2	EQU	PORT-2		; Baud rate port
MDCTL3	EQU	PORT-3		; Reset port
;
MDRCV	EQU	80H		; Data available
MDSND	EQU	40H		; Xmit buffer empty
MDDCD	EQU	20H		; Data carrier detect
;
B300	EQU	55H		; 300 baud
B1200	EQU	77H		; 1200 bps
B2400	EQU	0AAH		; 2400 bps
;
; See if we still have a carrier - if not, return with the zero flat set
;
MDCARCK:IN	MDCTL3		; Read port
	ANI	MDDCD		; Mask carrier detect
	RET
;
; Disconnect and wait for an incoming call
;
MDINIT:	MVI	A,01		; Reset UART, enable modem control
	OUT	MDCTL3
	MVI	A,68H		; DTR, RTS off to hang up phone
	OUT	MDCTL1
	PUSH	B
	MVI	B,20		; 2 seconds to let modem settle down
;
MDINIT1:CALL	DELAY
	DCR	B
	JNZ	MDINIT1
	POP	B
	MVI	A,6BH		; Turn DTR back on
	OUT	MDCTL1
;
	 IF	IMODEM
	CALL	IMINIT
	 ENDIF			; IMODEM
;
	RET
;
; Input a character from the modem port
;
MDINP:	IN	PORT		; 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:	IN	MDCTL1		; Read port
	ANI	MDRCV		; Mask crap
	RZ			; Nope, nothing there
	ORI	0FFH		; We got something...
	RET
;
; Send a character to the modem
;
MDOUTP:	OUT	PORT		; Send it
	RET
;
; See if the output is ready for another character
;
MDOUTST:IN	MDCTL1		; Read port
	ANI	MDSND		; Mask crap
	RET
;
; Reinitialize the modem and hang up the phone by dropping DTR and
; leaving it inactive.
;
MDQUIT:	 IF	IMODEM
	CALL	IMQUIT		; Tell smartmodem to shut down
	 ENDIF			; IMODEM
;
; Called by main program after caller has typed BYE
;
MDSTOP:	MVI	A,68H		; Turn off DTR so that modem will quit
	OUT	MDCTL1
	RET
;
; The following routine sets the baudrate.  NUBYE asks for the maximum
; speed you have available.
;
SETINV:	ORI	0FFH		; Make sure the zero flag is not set
	RET
;
SET300:	MVI	A,B300
	JMP	SETBAUD
;
SET1200:MVI	A,B1200
	JMP	SETBAUD
;
SET2400:MVI	A,B2400
;
SETBAUD:OUT	MDCTL2
	XRA	A
	RET
;
; end of insert
; -------------
