; NUDV-1.INS - DATAVUE 3000 insert for NUBYE - 04/21/86
;
; DART I/O and CTC timer.
;
; Note:  This is an insert, not an overlay.
;
; This version is for the DATAVUE 3000 using channel "A" of the
; Z80 DART.  The Z80-CTC is used as the baud rate generator.
;
;
; ========
;
; 04/21/86  Modified for NUBYE
; 09/10/85  Minor modifications	for BYE5xx		- Tom Brady
; 07/06/85  Modified for DATAVUE 3000			- Jim Gooch
; 06/10/85  Written for use with BYE335 and later	- Irv Hoff
; 02/08/84  Initial Version				- Jerry Haigwood
;
; ========
;
PORT	EQU	0B0H		; Data port
MDCTL1	EQU	PORT+1		; Status/control port
BRPORT	EQU	071H		; Baud rate port
;
BD300:	DB	80H	;(first half is CTC count)
BD1200:	DB	20H	;(second is CTC command)
BD2400:	DB	10H
BD9600:	DB	4
;
; See if we still have a carrier - if not, return with the zero flag set
;
MDCARCK:
	MVI	A,10H		; Reset status, RR0
	OUT	MDCTL1
	IN	MDCTL1		; Get status
	ANI	8		; Check for data carrier
	RET
;
; Disconnect and wait for an incoming call
;
MDINIT:	DI
	MVI	A,18H		; ERR RESET, WREG 0
	OUT	MDCTL1
	MVI	A,11H		; RST EXT/STAT INT, WREG 1
	OUT	MDCTL1
	XRA	A		; DISABLE ALL INTERRUPTS
	OUT	MDCTL1
	MVI	A,4		; WREG 4
	OUT	MDCTL1
	MVI	A,44H		; 16X,8,N,1
	OUT	MDCTL1
	MVI	A,5		; WREG 5
	OUT	MDCTL1
	MVI	A,68H		; Clear RTS causing hangup
	OUT	MDCTL1
	PUSH	B		; Save in case it's being used elsewhere
	MVI	B,20		; 2 seconds delay to drop any carrier
	CALL	DLP1		
	MVI	A,3		; Setup to write register 3
	OUT	MDCTL1
	MVI	A,0C1H		; Initialize receive register
	OUT	MDCTL1
	MVI	A,5		; Setup to write register 5
	OUT	MDCTL1
	MVI	A,0EAH		; Turn on RTS so modem can answer phone
	OUT	MDCTL1		; DTR, 8 BITS, TX ENA, RTS
	MVI	A,10H		; Reset status, RR0
	OUT	MDCTL1
	MVI	B,2		; slight additional delay
	CALL	DLP1
	POP	B
;
	 IF	IMODEM		; If using intelligent modem
	CALL	IMINIT		; Go initialize
	 ENDIF			; IMODEM
;
	EI			; enable interrupts
	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:
	MVI	A,10H		; Reset status, RR0
	OUT	MDCTL1
	IN	MDCTL1		; Get status
	ANI	1		; Check receive ready bit
	RZ			; Return if none
	ORI	0FFH		; Otherwise, set the proper flag
	RET
;
; Send a character to the modem
;
MDOUTP:	OUT	PORT		; Send it
	RET
;
; See if the output is ready for another character
;
MDOUTST:
	MVI	A,10H		; Reset status, RR0
	OUT	MDCTL1
	IN	MDCTL1		; Get status
	ANI	4		; Check transmit ready bit
	RET
;
; Reinitialize the modem and hang up the phone by dropping DTR and
; leaving it inactive.
;
MDQUIT:
	 IF	IMODEM		; If using a smartmodem
	CALL	IMQUIT		; Tell it to shut down
	 ENDIF			; IMODEM
;
; Called by the main program after caller types BYE
;
MDSTOP:	MVI	A,5		; Setup to write register 5
	OUT	MDCTL1
	MVI	A,68H		; Clear RTS causing shutdown
	OUT	MDCTL1
	RET
;
; The following routine sets the baudrate.  NUBYE asks for the maximum
; speed you have available.
;
SETINV:
	ORI	0FFH		; Make sure zero flag is not set
	RET			; Return
;
SET300:
	DI
	LXI	H,BD300		; Get 300 bps parameters in 'HL'
	JMP	SETBAUD		; Go load them
;
SET1200:
	DI
	LXI	H,BD1200
	JMP	SETBAUD
;
SET2400:
	DI
	LHLD	BD2400
;
SETBAUD:	
	MVI	A,47H		; CTC command word
	OUT	BRPORT
	MOV	A,M	; Baudrate
	OUT	BRPORT
	EI
	RET
;
; end of insert
; -------------