;----------------------------------------------------
;OSBORNE ONE SERIAL PORT CONTROL UTILITY
;COPYRIGHT 1983 BY GEORGE SCOTT 
;PERMISSION GRANTED FOR PRIVATE USE
;CONTACT AUTHOR FOR COMMERICAL USE
;
;
;VERSION 2.3       JAN 1983
;
;PROGRAM IS MENU DRIVEN AND ALLOWS FOR SELECTION
;OF CLOCK DIVISION (AND HENCE BAUD RATE) WORD
;FORMATTING (LENGTH, STOP BITS, PARITY) AND VARIOUS
;HARDWARE HANDSHAKE HANDLING.  EXITING EARLY, FROM
;ANY MENU, ABORTS THE PROCESS.  THE LAST OPPORTUNITY
;TO DO THIS IS FROM THE RECEIVE INTERRUPT MENU.  A
;BELL IS SOUNDED TO WARN THAT THIS IS THE LAST MENU 
;BEFORE THE CONTROL WORD IS WRITTEN.
;----------------------------------------------------
;
;SETUP CALL AND DATA EQUATES
;
CLEAR	EQU	26
PBUFF	EQU	9
CR	EQU	0DH
LF	EQU	0AH
MBUFF	EQU	4010H
RGET	EQU	1
BZY	EQU	0BH
FLAGPOS	EQU	0EF08H
BDOS	EQU	5
ACIA	EQU	2A00H	;ADDRESS OF ACIA
SLSP	EQU	10B 	;CLOCK DIVISION WORDS
HISP	EQU	01B	;DEFAULT (DIVIDE BY 16)
UHSP	EQU	00B
BELL	EQU	07
RESET	EQU	11B
WRITE	EQU	5000H
F7BE2	EQU	00000B	;WORD LENGTH/STOP BIT/PARITY
F7BO2	EQU	00100B	;WORDS
F7BE1	EQU	01000B	;NEXT COMMENT SHOWS WHAT VARIABLE NAME MEANS:
F7BO1	EQU	01100B	;F=FORMAT,7B=7 BIT,O=ODD,1=1 STOP BIT
F8BN2	EQU	10000B
F8BN1	EQU	10100B	;DEFAULT
F8BE1	EQU	11000B	
F8BO1	EQU	11100B
LTID	EQU	0000000B;RTS LINE HANDLING WORDS	 
LTIE	EQU	0100000B
HTID	EQU	1000000B;DEFAULT
LTBR	EQU	1100000B
RIE	EQU	10000000B;RECEIVE INTERRUPT HANDLING WORDS
RID	EQU	0B	;DEFAULT
;
;
	ORG	0100H
;
;
	LXI	D,WRITE	;SET PARMS FOR BLOCK MOVE
	LXI	H,SOURCE
	MVI	B,21
	CALL	LIFTER	;XEQ BLOCK MOVE TO COPY SWITCH
			;ROUTINE TO HIGH MEMORY (5000H)
			;TO ALLOW BANK SWITCHING
			;TO XEQ PROPERLY
	MVI	B,0	 
;
;CLOCK DIVISION (BAUD RATE) SELECTION MENU
;	
SMENU	CALL	SAVR
	LXI	D,SPEED
	CALL	PRINT	;DISPLAY SPEED SELECT MENU
	CALL	INPUT
	CALL	RSTR
	CPI	'U'
	JZ	ULTRA
	CPI	'F'
	JZ	FAST
	CPI	'S'
	JZ	SLOW 
	CPI	CR
	JZ	FAST
	CPI	'E'
	JZ	00
	JMP	SMENU	;NO VALID KEYBOARD INPUT BRANCH
;
;WORD LENGTH/PARITY/STOP BIT SELECT MENU
;
WMENU	CALL	SAVR
	LXI	D,WORD
	CALL	PRINT
	CALL	INPUT
	CALL	RSTR
	CPI	'1'
	JZ	WORD1
	CPI	'2'
	JZ	WORD2
	CPI	'3'
	JZ	WORD3
	CPI	'4'
	JZ	WORD4
	CPI	'5'
	JZ	WORD5
	CPI	'6'
	JZ	WORD6
	CPI	'7'
	JZ	WORD7
	CPI	'8'
	JZ	WORD8
	CPI	CR
	JZ	WORD6
	CPI	'E'
	JZ	00
	JMP	WMENU
;
;RTS LINE HANDLING SELECT MENU
;
RMENU	CALL	SAVR
	LXI	D,RTSP
	CALL	PRINT
	CALL	INPUT
	CALL	RSTR
	CPI	'1'
	JZ	RTS1
	CPI	'2'
	JZ	RTS2
	CPI	'3'	
	JZ	RTS3
	CPI	'4'
	JZ	RTS4
	CPI	CR
	JZ	RTS3
	CPI	'E'
	JZ	00
	JMP	RMENU
;
;RECEIVE INTERRUPT ENABLE/DISABLE
;
DMENU	CALL	SAVR
	LXI	D,DCDP
	CALL	PRINT
	CALL	INPUT
	CALL	RSTR
	CPI	'1'
	JZ	DCD1
	CPI	'2'
	JZ	DCD2
	CPI	CR
	JZ	DCD1
	CPI	'E'
	JZ	00
	JMP	DMENU
;
;WRITE CONTROL BYTE TO RESET ACIA THEN WRITE
;CONTROL BYTE NOW STORED IN REGISTER B
; 
WINDUP	CALL	SAVR
	MVI	B,RESET	;SET B FOR ACIA RESET
	CALL	WRITE	;XEQ WRITE ROUTINE IN HIGH MEMORY
	CALL	RSTR	;MOVE CONTROL BYTE TO B REGISTER
	CALL	WRITE	;WRITE IT TO ACIA
	JMP	00	;GO AWAY
;
;
;THE FOLLOWING ROUTINES BUILD THE CONTROL WORD AND 
;STORE IT IN THE B REGISTER AS DATA IS SELECTED FROM
; THE KEYBOARD
;
;SPEED SUBROUTINES
;
ULTRA	MOV	A,B
	ORI	UHSP
	JMP	SPLT
FAST	MOV	A,B
	ORI	HISP
	JMP	SPLT
SLOW	MOV	A,B
	ORI	SLSP
SPLT	MOV	B,A
	JMP	WMENU
;
;WORD PARAMETER ROUTINES
;
WORD1	MOV	A,B
	ORI	F7BE2
	JMP	WSPLT
WORD2	MOV	A,B
	ORI	F7BO2
	JMP	WSPLT
WORD3	MOV	A,B
	ORI	F7BE1
	JMP	WSPLT
WORD4	MOV	A,B
	ORI	F7BO1
	JMP	WSPLT
WORD5	MOV	A,B
	ORI	F8BN2
	JMP 	WSPLT
WORD6	MOV	A,B
	ORI	F8BN1
	JMP	WSPLT
WORD7	MOV	A,B
	ORI	F8BE1
	JMP	WSPLT
WORD8	MOV	A,B
	ORI	F8BO1
WSPLT 	MOV	B,A
	JMP	RMENU
;
;RTS LINE HANDLING SELECT ROUTINES
;
RTS1	MOV	A,B
	ORI	LTID
	JMP	RSPLT
RTS2	MOV	A,B
	ORI	LTIE
	JMP	RSPLT
RTS3	MOV	A,B
	ORI	HTID  
	JMP	RSPLT
RTS4	MOV	A,B
	ORI	LTBR
RSPLT	MOV	B,A
	JMP	DMENU
;
;DCD HANDLING ROUTINES
;
DCD1	MOV	A,B
	ORI	RID
	JMP	DSPLT
DCD2	MOV	A,B
	ORI	RIE
DSPLT	MOV	B,A
	JMP	WINDUP     
;
;CODE TO BE COPIED TO HI MEMORY BY LIFTER
;THAT WILL FORM THE BANK SWITCH/WRITE ROUTINE 
;AT 5000H
;
SOURCE	DI
	OUT	00H
	MVI	A,00
	STA	FLAGPOS
	LXI	H,ACIA 
	MOV	M,B
	OUT	01H
	MVI	A,01H
	STA	FLAGPOS
	EI
	RET
;
;CONSOLE OUTPUT UTILITY
;
PRINT	MVI	C,PBUFF
	CALL	BDOS
	RET
;
;INPUT UTILITY ROUTINE RETURNS ONE CHARACTER FROM
;KEYBOARD IN THE A REGISTER
;
INPUT	MVI	C,BZY
	CALL	BDOS
	CPI	00
	JZ	INPUT
	MVI	C,RGET
	CALL	BDOS
	RET
;
;BLOCK MOVE UTILITY
;
LIFTER	MOV	A,M
	STAX	D
	DCR	B
	RZ
	INX	H
	INX	D
	JMP	LIFTER
;
;THIS SUBROUTINE WILL SAVE THE CONTROL WORD AT
;MEMORY LOCATION MBUFF
;
SAVR	PUSH	H
	LXI	H,MBUFF
	MOV	M,B
	POP	H
	RET 
;
;THIS SUBROUTINE REVERSES THE ABOVE PROCESS
;THIS IS NECCESSARY BECAUSE THE NEEDED CALLS
;TO BDOS CORRUPT THE REGISTERS
;
RSTR	PUSH	H
	LXI	H,MBUFF
	MOV	B,M
	POP	H
	RET
;
;MENU SELECT ITEMS
;
SPEED	DB	CLEAR
	DB	'RS-232 CONTROL UTILITY',CR,LF,LF
	DB	'SELECT MENU ITEMS BY INPUTTING FIRST LETTER',CR,LF
	DB	'OF DESIRED FUNCTION.  ',CR,LF 
	DB	'CARRIAGE RETURN SELECTS DEFAULT VALUE WHICH IS',CR,LF
	DB	'THE ITEM ENCLOSED IN BRACES: [...]',CR,LF
	DB	'SELECTING EXIT FROM ANY MENU ABORTS THIS TASK',CR,LF,LF
	DB	'BAUD RATE SELECT MENU',CR,LF,LF
	DB	'(U)LTRAFAST	19,200/38,400 BAUD  <XMIT ONLY>',CR,LF
	DB	'[F]AST		1,200/2,400 BAUD',CR,LF
	DB	'(S)LOW		300/600	BAUD',CR,LF,LF
	DB	'(E)XIT	',CR,LF,LF
	DB	'INPUT SELECTION:$'
WORD	DB	CLEAR
	DB	'DATA FORMAT SELECT MENU',CR,LF,LF
	DB	'   DATA BITS	PARITY       STOP BITS',CR,LF
	DB	'   +++++++++    ++++++       +++++++++',CR,LF
	DB	'(1) SEVEN	EVEN		TWO',CR,LF
	DB	'(2) SEVEN	ODD		TWO',CR,LF
	DB	'(3) SEVEN	EVEN		ONE',CR,LF
	DB	'(4) SEVEN	ODD		ONE',CR,LF
	DB	'(5) EIGHT	NONE		TWO',CR,LF
	DB	'[6] EIGHT	NONE		ONE',CR,LF
	DB	'(7) EIGHT	EVEN		ONE',CR,LF
	DB	'(8) EIGHT	ODD		ONE',CR,LF,LF
	DB	'(E)XIT',CR,LF,LF
	DB	'INPUT SELECTION:$'
RTSP    DB	CLEAR
	DB	'RTS HANDLING SELECTION MENU',CR,LF,LF
	DB	'(1) LOW DISABLES XMIT INTERRUPT',CR,LF
	DB	'(2) LOW  ENABLES XMIT INTERRUPT <NOT FOR OSBORNE!>',CR,LF
	DB	'[3] HIGH DISABLES XMIT INTERRUPT',CR,LF
	DB	'(4) LOW TRANSMITS BREAK',CR,LF,LF
	DB	'(E)XIT',CR,LF,LF
	DB	'INPUT SELECTION:$'
DCDP	DB	CLEAR,BELL
	DB	'DCD HANDLING MENU',CR,LF,LF
	DB	'[1] RECEIVE INTERRUPT DISABLED',CR,LF
	DB	'(2) RECEIVE INTERRUPT ENABLED',CR,LF,LF
	DB	'(E)XIT  <LAST CHANCE TO ABORT>',CR,LF,LF
	DB	'INPUT SELECTION:$'
	END
