; NUOS-1.INS - Osborne OS-1 insert for NUBYE - 04/21/86
;
; 6850 ACIA
;
; Note:  This is an insert, not an overlay.
;
; If your OS-1 does not have have the hardware mod to support DTR,
; (shown below) then set the NODTR option in NUBYE to "YES".
; Also set:
;		    IMODEM   EQU   YES
;		    NORING   EQU   YES
;
; ========
;
; 04/21/86  Modified for NUBYE
; 08/07/85  Program now runs properly with BYE5 program.  Renamed several
; 	    labels to more closely match BYE5 conventions.  Changed MDOUTP
;	    routine with addition of PUSH PSW and POP PSW statements.
;	    MDOUTP routine for Osborne 1 clobbers accumulator register when
;	    called.  Changed MDQUIT routine, program now calls RTSNBL and
;	    IMQUIT if IMODEM equate is set true.  Changed MDINIT routine,
;	    program now calls IMINIT if IMODEM equate is set true.  Changed
;	    MDCARCK routine. 				- Roy Robinson
; 07/17/85  Revised for use with BYE5			- Kevin Murphy
;
; =========
;
; NOTE:
;	IF YOU USE THE HARWARE MODIFICATION TO THE OZZIE 1.
;	When the Sysop terminates the NUBYE program with a control C fol-
;	lowed by any other key except 'E' or 'R' from the local console
;	keyboard to go off-line, the Sysop must press the RESET button
;	at the front of the Ozzie and reboot the computer before running
;	the NUBYE program again. This is due to the nature of the 6821
;	PIA input, CB2, which is used for carrier detect in the hardware
;	mod.  Pushing the RESET button triggers the CB2 input for proper
;	use with NUBYE.	This reboot should be a minor inconvenience as
;	it is initiated only when the computer is off-line.
;
;						- Roy Robinson
;
; The following hardware (your OCC-1) configuration is assumed:
;
;	DTR (pin 20) is supported
;	DCD (pin 8) is supported
;	RI  (pin 22) is not supported
;
; MAIN LOGIC BOARD TRACE CUTS:
; --------------------------
; Solder Side:
;
; 	Cut trace running from pin 5 to pin 6 on inner row of pads
; 	used in mounting the RS-232 female serial connector at the
;	front  of main logic board.  Pin 1 is pad with wide ground
;	trace.
;
; Component side:
;
; 	Cut trace from pin 5 of UC4 (6850) to R20 (10K ohm).
; 	Cut trace that runs between pins 3 and 4 of UC4 (6850).
;
; PART ADDITIONS:
; --------------
; Solder side:
;
; 	Add jumper from pin 1 of UE3 (MC1458) to pin 5 of inner row of
;     	    RS-232 serial port pads.  Pin 1 has wide ground trace.
; 	Add jumper from pin 3 to pin 5 of UE3 (MC1458).
; 	Add jumper from pin 10 of UD4 (LM3400) to pin 5 of UC1 (74LS08).
; 	Add jumper from pin 4 of UC1 (74LS08) to pin 1 of UE20 (74LS04).
; 	Add jumper from pin 6 of UC1 (74LS08) to pin 5 of UA11 (74S04).
; 	Add jumper from pin 6 of UA11 (74S04) to pin 19 of UC15 (6821).
;
; 	Component side or solder side (whichever side you feel more
; 	comfortable using for mounting components):
;
;	Add 10K ohm resistor from Vcc (+5 volts) to pin 2 of UE3 (MC1458).
; 	Add 220 ohm resistor from pin 5 of UC4 (6850) to pin 2 of UE3 (MC1458).
; 	Add 1k ohm resistor from pin 19 of UC15 (6821) to Vcc (+5 volts).
;
; NEW RS-232 MODEM CABLE:
; ----------------------
;
;	  OCC-1 		       MODEM
;
;	 2    RXD		      3    RXD
;	 3    TXD		      2    TXD
;	 4    DCD (new function)      8    DCD
;	 5    DTR (new function)     20    DTR
;	 7    GND		      7    GND
;
; ----------
;
WRKBAUD:DB	16H	; [*] OCC1 ++
SSTAT:	DB	0	; RAM location serves as a secondary status reg-
			;   ister for the 6850 ACIA status register.
			;   This secondary RAM register is used because
			;   the  6850 ACIA clobbers its own status reg-
			;   ister (with regard to TBE and RDA status
			;   bits) when data is traveling in both direc-
			;   tions via the serial port.	This is illus-
			;   trated with data being output during a dis-
			;   play listing to the remote user, and the re-
			;   mote user wishes to suspend or abort the
			;   screen display by typing a ^S, ^C,	or ^K.
HARDMOD	EQU	YES	; YES, if hardware mods have been installed in
			;   Osborne O-1 to support DTR and modified DCD.
			;   (see installation procedure above)
			; NO,  if the O-1 is standard (no mods).  If NO,
			;   you must set NODTR equate to YES in the main
			;   body of the NUBYE program.
STATM	EQU	2A00H
DATA	EQU	2A01H
CDATA	EQU	2C02H
CSTAT	EQU	2C03H
;
	 IF	HARDMOD
MDDCD	EQU	40H
	 ENDIF
;
	 IF	NOT HARDMOD
MDDCD	EQU	4
	 ENDIF
;
RRDA	EQU	0FEH
MRDA	EQU	1
RTBE	EQU	0FDH
MTBE	EQU	2
BD300	EQU	22
BD1200	EQU	21
;
; See if we still have a carrier - if not, return with the zero flag set
;
MDCARCK:
	 IF	HARDMOD
	DI		; Disable interrupts
	OUT	0
	LDA	CSTAT	; Read video PIA status register
	OUT	1
	EI
	 ENDIF		; HARDMOD
;
	 IF	NOT HARDMOD
	CALL	BNKINS	; Get modem status
	 ENDIF		; NOT HARDMOD
;
	CMA		; Complement register, DCD bit set with LOSS of carrier
			; This is opposite of most I/O devices.
	ANI	MDDCD	; Mask out everything but carrier LOSS bit
			; Z=1 Lost carrier
			; Z=0 Carrier present
	RET
;
; Disconnect and wait for an incoming call
;
MDINIT:	CALL	RTSDIS	; Clear RTS causing hangup
	CALL	RTSNBL	; Turn on DTR so modem can answer phone
	CALL	OFFTIM	; Wait 2 seconds
;
	 IF	 IMODEM
	CALL	IMINIT	; Initialize smartmodem
	 ENDIF		; IMODEM
;
	 IF	HARDMOD
	CALL	INITCAR	; Reset carrier detect input on 6821 video PIA
	 ENDIF		; HARDMOD
;
	RET
;
; Input a character from the modem port
;
MDINP:	CALL	BNKIND	; Input data from RS-232 serial port
	PUSH	PSW	; Save the character
	LDA	SSTAT	; Load secondary ACIA status register from RAM
	ANI	RRDA	; Mask the RDA bit (reset RDA bit in secondary register)
	STA	SSTAT	; Save our updated status register in RAM
	POP	PSW	; Recover the character
	RET		; Return to sender
;
; 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:	PUSH	B	; Save BC registers
	LDA	SSTAT	; Load secondary ACIA status register
			;   (contains status of ACIA from last ACIA operation)
	MOV	B,A	; Save it in register B
	CALL	BNKINS	; Input current ACIA status register
	ORA	B	; Perform an OR operation on both former
			;   as well as present ACIA register states.
	STA	SSTAT	; Save updated ACIA register state in secondary ACIA
			;   register
	ANI	MRDA	; Mask RDA bit
	POP	B	; Recover former BC registers
	RZ		; Nothing?  Return to sender with Z-flag set
	ORI	0FFH	; We got something....
	RET		; Return to sender with Z-flag not set
;
; Send a character to the modem
;
MDOUTP:	PUSH	PSW
	CALL	BNKOUTD	; Output data to RS-232 serial port
	LDA	SSTAT	; Load secondary ACIA register
	ANI	RTBE	; Mask the TBE bit
	STA	SSTAT	; Save secondary ACIA register (now updated)
	POP	PSW
	RET		; Return to sender
;
; Check the status to see if ACIA can output a character.  If not, return
; with the zero flag set.  If yes, use 0FFH to clear the flag.
;
MDOUTST:PUSH	B	; Save BC registers
	CALL	BNKINS	; Get present ACIA status register
	MOV	B,A	; Move it to 'B' register
	LDA	SSTAT	; Get secondary ACIA status register
	ORA	B	; Perform an OR operation on present and former
			;   ACIA status register states
	STA	SSTAT	; Save updated ACIA status register in secondary
			;   ACIA status register
	ANI	MTBE	; Mask the TBE bit
	POP	B	; Recover the former BC registers
	RZ		; Transmit buffer not empty so return
			;   to sender with Z-flag set
	ORI	0FFH	; If empty...
	RET		; Ready to send character
;
; Reinitialize the modem and hang up the phone by dropping RTS and
; leaving it inactive
;
MDQUIT:	CALL	RTSDIS	; Disable RTS output which forces modem to hang-up
;
	 IF	IMODEM
	CALL	RTSNBL	; Turn on RTS so modem can be
	CALL	IMQUIT	; If a smartmodem, tell it to shut down
	 ENDIF		; IMODEM
;
; Called by the main program after caller types BYE
;
MDSTOP:	CALL	RTSDIS	; Clear RTS causing shutdown
;
	RET
;
; Initialize the 6850 ACIA and disable RTS line which serves as DTR
; control for the modem
;
RTSDIS:	MVI	A,57H	 ; IRQ disabled, RTS disabled, 8bits/1stop, MRESET
	CALL	BNKOUTS
;
OFFTIM:	PUSH	B	;2 second delay after dropping the ACIA RTS line
	MVI	B,20	;(which is DTR to the modem)
;
OFFTI:
	CALL	DELAY
	DCR	B
	JNZ	OFFTI
	POP	B
	RET
;
; Reset video 6820 PIA register for future detection of lost carrier
;
INITCAR:
	DI
	OUT	0
	LDA	CDATA	; Read video pia data register to reset cb2 bit
	OUT	1
	EI
	RET
;
RTSNBL:	LDA	WRKBAUD	; ACIA reset and enable RTS
	ANI	0BFH	;
	CALL	BNKOUTS
	RET
;
BNKINS:	DI		; Disable interrupts
	OUT	0	; Switch banks to shadow memory bank
	LDA	STATM	; Read ACIA status register (memory mapped)
	OUT	1	; Switch banks back to program memory bank
	EI		; Re-enable interrupts
	RET		; Go home
;
BNKIND:	DI		; Disable interrupts
	OUT	0	; Switch banks to shadow memory bank
	LDA	DATA	; Read ACIA data register (memory mapped)
	OUT	1	; Switch banks back to program memory bank
	EI		; Reenable interrupts
	RET		; Go home
;
BNKOUTS:DI		; Disable interrupts
	OUT	0	; Switch banks to shadow memory bank
	STA	STATM	; Write data to ACIA control register (memory mapped)
	OUT	1	; Switch banks to program memory bank
	EI		; Reenable interrupts
	RET		; Go home
;
BNKOUTD:DI		; Disable interrupts
	OUT	0	; Switch banks to shadow memory bank
	STA	DATA	; Write data to ACIA data register (memory mapped)
	OUT	1	; Switch banks to program memory bank
	EI		; Reenable interrupts
	RET		; Go home
;
; The following routine sets the baudrate.  NUBYE would like the maximum
; speed you have available for controlling your modem.
;
SET300:	MVI	A,BD300	; IRQ disable, RTS disable
			; 8 data bits, 1 stop bit, 64X clock
	JMP	SETBAUD
;
SET1200:MVI	A,BD1200
;
SETBAUD:CALL	BNKOUTS
	STA	WRKBAUD	; Save incoming baud rate
	XRA	A	; Show baudrate was ok
	RET
;
SET2400	EQU	$	; The OS-1 doesn't like 2400 -- yet
;
SETINV:	MVI	A,0FFH	; Return bad
	ORA	A	; Show baudrate was unacceptable
	RET
;
; end of insert
; -------------
