************
* Program SUB_RTNE (6811)
*
* Provides prompt for a character (A-Z).  Gets character.  If lower
* case converts to upper case.  Displays character.  If not valid, 
* (not alphabetical character beeps terminal.  Repeats until switch S7 
* is set to one.
*
* Intended to illustrate the use of BUFFALO subroutines.  Note that each 
* subroutine performs a specific task.
*
* Note the following Buffalo ROM utilities;
*
*  INPUT  reads char from terminal and returns in ACCA.  Returns 00
*     if no character.
*  OUT_CHAR outputs ACCA to the terminal
*  OUT_CR_LF outputs CR and LF to terminal
*
* P. H. Anderson, MSU, 26 Nov 91; 19 Jan 93
*************

PSCT		EQU $C000
DSCT		EQU $D000
IDSCT		EQU $D300

STACKTP 	EQU $0045
REG_BASE	EQU $1000

INPUT		EQU $E387
OUT_CHAR	EQU $E3B3
OUT_CR_LF	EQU $E4ED
OUT_STRING	EQU $E4FA

PORTB		EQU $04 	* output
PORTC		EQU $03 	* input
DDRC		EQU $07

	ORG PSCT

	LDS #STACKTP
	LDY #REG_BASE		* to allow indexed addressing

	CLR DDRC,Y

PROMPT
	LDAA #'>'			* provide prompt
	JSR OUT_CHAR
GET
	BRSET PORTC,Y %10000000 DONE
*if S7 at logic one - done
	JSR INPUT		* get the character
	TSTA
	BEQ GET			* loop until S7 or there is a char

	BSR TO_UPPER		* passes char in A; upper returned in A
	BSR IS_CHAR		* passes char in A; result returned in VALID
	TST VALID
	BNE AROUND

	BSR BEEP		* beeps terminal if invalid character
	JSR OUT_CR_LF
	BRA PROMPT
AROUND
	JSR OUT_CHAR
	JSR OUT_CR_LF
	BRA PROMPT

DONE
	SWI

TO_UPPER
* if character in range 'a' - 'z', converts to upper case.
	
	CMPA #'a'		* < a
	BCS TO_UPPER_DN
	CMPA #'z+1'		* >= z+1
	BCC TO_UPPER_DN
	SUBA #$20		* convert to upper case
TO_UPPER_DN
	RTS

IS_CHAR
	CMPA #'A'
	BCS IS_CHAR_DN		* not valid
	CMPA #'Z'+1
	BCC IS_CHAR_DN
	CLR VALID
	INC VALID		* VALID is true
	RTS
	
IS_CHAR_DN
	CLR VALID		* VALID is false
	RTS

BEEP
	PSHA
	LDAA #$07
	JSR OUT_CHAR
	PULA
	RTS

	ORG DSCT

VALID	RMB 1

	ORG IDSCT

