	NAM	DEMO
	OPT	M,NOG
* PROMPT FOR A MESSAGE AND THE NUMBER OF TIMES TO
* PRINT THE MESSAGE.
*
SIOCSR	EQU	$F000		;CONTROL/STATUS REGISTER
SIODR	EQU	$F001		;DATA REGISTER
CR	EQU	$0D		;ASCII CARRIAGE RETURN
LF	EQU	$0A		;ASCII LINE FEED
*
	ORG	$5000
*
* PROMPT FOR AND INPUT A MESSAGE STRING
*
START	LDX	#MMSG		;PROMPT TO ENTER A MESSAGE
	BSR	DISPMSG
*
	LDX	#MSGBUF+2	;X->WHERE TO PUT CHARACTERS
INLOOP	BSR	GETCHAR		;GET CHARACTER
	BSR	OUTCHAR		;ECHO
	STAA	0,X		;SAVE NEXT BYTE OF NAME
	INX
	CMPA	#CR		;CR ENTERED?
	BNE	INLOOP		;NO, KEEP GOING
*
	CLR	0,X		;END OF STRING
*
* PROMPT FOR AND INPUT NUMBER OF TIMES TO DISPLAY THE MESSAGE 
*
TIMES	LDX	#MTIMES		;DISPLAY "# TIMES?"
	BSR	DISPMSG

	BSR	GETCHAR		;GET COUNT
	BSR	OUTCHAR
	SUBA	#'0		;CONVERT TO BINARY 0-9
	CMPA	#9
	BHI	TIMES		;INVALID
*
	STAA	MSGCNT
*
* DISPLAY THE MESSAGE THE SPECIFIED NUMBER OF TIMES
*
DSPLOOP	LDX	#MSGBUF		;DISPLAY THE MESSAGE
	BSR	DISPMSG
	DEC	MSGCNT		;DECREMENT THE MSGCNT
	BNE	DSPLOOP
*
	JMP	$FFAB		;RETURN TO MONITOR
*
* DISPMSG - DISPLAY NULL TERMINATED STRING
*
DISPMSG	LDAA	0,X
	BEQ	DMEXIT		;DONE
	BSR	OUTCHAR
	INX
	BRA	DISPMSG
*
* OUTCHAR - OUTPUT CHARACTER TO CONSOLE
*
OUTCHAR	LDAB	SIOCSR
	BITB	#02
	BEQ	OUTCHAR
*
	STAA	SIODR
DMEXIT	RTS
*
* GETCHAR - GET CHARACTER FROM CONSOLE
*
GETCHAR	LDAA	SIOCSR
	BITA	#1
	BEQ	GETCHAR
*
	LDAA	SIODR
	ANDA	#$7F
	RTS
*
MSGCNT	FCB	0
*
* MESSAGES
*
MMSG	FCB	CR,LF,LF
	FCC	'ENTER A MESSAGE: '
	FCB	0
MTIMES	FCB	CR,LF
	FCC	'REPEAT COUNT: '
	FCB	0
MSGBUF	FCB	CR,LF
	END

