
; B3TV-2.INS - BYE3 insert for TeleVideo TS-802 - 08/01/85
;
;	     SIO I/O and CTC baudrate generator
;
;	    Note:  This is an insert, not an overlay.
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
; 04/16/83  TS802 code created from B3SIO	- Kevin Robesky
;
; =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
;
;
; Modem port equates
;
DPORT	EQU	20H		; Modem data port
SPORT	EQU	DPORT+2		; Modem status port
BDPORT	EQU	08H		; Modem baud rate port
;
; Status port masks
;
DAV	EQU	00000001B	; Data available
TBMT	EQU	00000100B	; Transmit buffer empty
DCD	EQU	00001000B	; Data carrier detect
;
; First Byte of CTC Command:
;
BDCMD	EQU	47H
;
; Baudrate table
;
BD300	EQU	80H		; 300 baud
BD1200	EQU	20H		; 1200 bps
BD2400	EQU	10H		; 2400 bps
;
;-----------------------------------------------------------------------
;
; See if we still have a carrier - if not, return with the zero flag set
;
MDCARCK:MVI	A,10H		; Reset status
	OUT	SPORT
	IN	SPORT		; Get status
	ANI	DCD		; Check for carrier detect
	RZ
	ORI	255
	RET
;
; Disconnect and wait for an incoming call
;
MDINIT:	MVI	A,18H		; Reset channel
	OUT	SPORT
	MVI	A,4		; Setup to write register 4
	OUT	SPORT
	MVI	A,44H		; 1 stop, 8 bits, no parity
	OUT	SPORT
	MVI	A,1		; Setup to write register 1
	OUT	SPORT
	MVI	A,00H
	OUT	SPORT
	MVI	A,5		; Setup to write register 5
	OUT	SPORT
	MVI	A,68H		; Clear DTR causing hangup
	OUT	SPORT
;
	PUSH	B		; In case it is being used elsewhere
	MVI	B,20		; 2 seconds delay to drop any carrier
OFFTI:	CALL	DELAY		; 0.1 second delay
	DCR	B
	JNZ	OFFTI		; Keep looping until finished
	POP	B		; Restore BC
;
	MVI	A,3		; Setup to write register 3
	OUT	SPORT
	MVI	A,0C1H		; Initialize receive register
	OUT	SPORT
	MVI	A,5		; Setup to write register 5
	OUT	SPORT
	MVI	A,0EAH		; Turn on DTR so modem can answer phone
	OUT	SPORT
;
	 IF	IMODEM
	CALL	IMINIT		; Initialize smartmodem
	 ENDIF			; IMODEM
;
	RET
;
; Input a character from the modem port
;
MDINP:	IN	DPORT		; 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	SPORT		; Get status
	ANI	DAV		; Check receive ready bit
	RZ			; Return if none
	ORI	255		; Otherwise, set the flags
	RET
;
; Send a character to the modem
;
MDOUTP:	OUT	DPORT		; Send it
	RET
;
; See if the output is ready for another character
;
MDOUTST:IN	SPORT		; Read port
	ANI	TBMT		; Check transmit ready bit
	RZ
	ORI	255
	RET
;
; Reinitialize the modem and hang up the phone by dropping DTR and
; leaving it inactive
;
MDQUIT:	 IF	IMODEM
	CALL	IMQUIT		; If a smartmodem, 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	SPORT
	MVI	A,68H		; Clear DTR causing shutdown
	OUT	SPORT
	RET
;
; The following routine sets the baudrate.  BYE3 asks for the maximum
; speed you have available.
;
SET300:	MVI	B,BD300		; 2nd byte of command
	JMP	STBAUD
;
SET1200:MVI	B,BD1200	; 2nd byte of command
	JMP	STBAUD
;
SET2400:MVI	B,BD2400

STBAUD:	MVI	A,BDCMD
	OUT	BDPORT		; Send 1st byte of command
	MOV	A,B		; Get the speed byte back again
	OUT	BDPORT		; Send it
	XRA	A		; Say rate is OK
	RET
;			       end
;-----------------------------------------------------------------------
