;
;VERSION UAPPLE 	(revised JUL 20, 1981)
;
;User routines for BSTAM version 4.3 or 4.4, for use with
;Apple CP/M with an Apple Communications Interface or
;a CCS 7710A Serial Interface in slot 2.
;	By Keith Petersen, W8SDZ
;
;DEFINE PORT ADDRESSES
;
STATUS	EQU	0E0A0H	;COM. OR CCS CARD STATUS LOC.
DATA	EQU	0E0A1H	;COM. CARD DATA - SLOT 2
;
;DEFINE ASCII CHARACTERS USED
;
CR	EQU	0DH
LF	EQU	0AH
;
;	IF YOU WISH TO USE OTHER REGISTERS SUCH AS HL,BC,DE
;	(NOT INCLUDING  SP  REGISTER)
;	BE SURE TO PUSH BSTAM'S REGISTERS ON TO STACK AND POP
;	THEM BACK OFF BEFORE RETURNING TO BSTAM.
;	THERE IS AMPLE ROOM TO PUSH ALL REGISTERS ONTO BSTAM'S
;	STACK, PLUS ROOM FOR 10 LEVELS OF CALL'S.
;
;	THERE ARE 300 BYTES OF USER SPACE AVAILABLE TO YOU.
;
;	THE JUMP'S CODED AT THE BEGINNING OF THIS PROGRAM
;	CANNOT BE MOVED IN ANY WAY.
;
BEGIN	ORG	103H
;
INITIL	JMP	INITIU	;UART/USART INITIALATION ENTRY POINT
INSPORT	JMP	INSPRU	;STATUS PORT READ ENTRY POINT
ERRSET	JMP	ERRSTU	;UART/USART ERROR RESET ENTRY POINT
INPORT	JMP	INPRTU	;READ DATA PORT ENTRY POINT
OUTPORT	JMP	OUTPRU	;WRITE DATA PORT ENTRY POINT
;
INITIU	EQU	$
;	THIS IS THE UART/USART INITIALATION ROUTINE.
;	TO BE COMPATIBLE WITH MOST BSTAM USERS USE FOLLOWING
;	INITIALATION GUIDE LINES:
;	1. USE 1 STOP BIT	(OPTIONAL - 2)
;	2. USE 8 DATA BITS	(MUST)
;	3. USE 1 START BIT	(MUST)
;	4. USE 16X FOR CLOCK RATE 	(MUST)
;	5. USE ASYNCHRONOUS MODE ONLY	(MUST)
;
	LDA	DATA	;CLEAR DATA PORT
	LDA	DATA	;AGAIN TO MAKE SURE
	CALL	SIGNON	;TELL USER WHAT'S IMPLEMENTED
	RET		;RETURN TO BSTAM
;
INSPRU	EQU	$
;	THIS IS THE STATUS READ PORT ROUTINE.
;	WHEN EXITING THIS ROUTINE BSTAM EXPECTS IN REGISTER A
;	THE FOLLOWING BITS TO BE SET IF NEEDED:
;	1. 20 BIT SET IF FRAMING ERROR
;	2. 10 BIT SET IF OVERRUN ERROR
;	3. 08 BIT SET IF PARITY  ERROR
;	4. 04 BIT SET IF TRANSMITTER EMPTY
;		IF YOUR UART/USART DOES NOT HAVE TRANSMITTER
;		EMPTY FEATURE, THEN ALLWAYS SET THIS BIT ON.
;	5. 02 BIT SET IF RECEIVER READY
;	6. 01 BIT SET IF TRANSMITTER READY
;	7. DO NOT SET THE 80 BIT OR 40 BIT
;
	LDA	STATUS	;TBE = 02H, RDA = 01H
	RLC
	ANI	6	;MASK OFF UNWANTED BITS
	ORI	1	;BOGUS TBE BIT
	RET
;
ERRSTU	EQU	$
;	THIS IS THE ERROR RESET FOR UART/USART ROUTINE.
;	YOUR UART/USART MAY NOT NEED TO BE RESET IF FRAMING,
;	OVERRUN, OR PARITY ERROR IS FOUND. IF THIS IS YOUR
;	CASE, JUST DO A RETURN.
;
	RET		;RETURN TO BSTAM
;
INPRTU	EQU	$
;	THIS IS THE READ DATA PORT ROUTINE.
;	BEFORE THIS ROUTINE IS ENTERED THE 02 BIT OF
;	STATUS READ ROUTINE MUST HAVE BEEN SET.
;	DO NOT CLEAR THE 80 BIT FROM THE DATA INPUT PORT.
;	RETURN WITH REGISTER A LOADED WITH INPUT DATA.
;
	LDA	DATA	;GET DATA FROM PORT
	RET		;RETURN TO BSTAM
;
OUTPRU	EQU	$
;	THIS IS THE WRITE DATA PORT ROUTINE.
;	BEFORE THIS ROUTINE IS ENTERED THE 04 BIT AND 01 BIT
;	OF STATUS READ MUST BE SET.
;	DO NOT CLEAR THE 80 BIT FROM THE DATA OUTPUT PORT.
;	REGISTER A CONTAINS THE OUTPUT DATA.
;
	STA	DATA	;SEND DATA TO REMOTE CPU
	RET		;RETURN TO BSTAM
;
MESSGE:	DB	CR,LF,CR,LF
	DB	'Version for Apple II as of 7/20/81.',CR,LF
	DB	'For Apple Communications Interface or',CR,LF
	DB	'CCS 7710A Serial Interface in slot 2.',CR,LF,'$'
;
SIGNON:	PUSH	B
	PUSH	D
	PUSH	H
	LXI	D,MESSGE
	MVI	C,9
	CALL	5		;ANNOUNCE VERSION TO USER
	POP	H
	POP	D
	POP	B
	RET
;
	END
