* Self Modifying Code
*
* Every processor seems to have a few weaknesses.  For example, with
* the 6805 series of processors, I have always been frustrated with
* the difficulty in operating on the X (or Y) registers.
*
* For example, wouldn't it be nice to;
*
*       LDAA VAR,X   where VAR is a variable.
*
* This can, of course be done by
*
*       XGDX
*       ADDB VAR
*       ADCA #$00
*       XGDX
*       LDAA 00,X
*
* One technique, is to hard code a subroutine which writes a temporary
* subroutine in RAM.
*
* Routine gets switches and maps into an array of characters.  Prints
* the character to the terminal.  Note that main calls a subroutine to write
* a subroutine in RAM to LDAA VAR,X
*
* P. H. Anderson, MSU, 19 March 93
**********

PSCT		EQU $C000
DSCT		EQU $D000
IDSCT		EQU $D300

STACKTP		EQU $0045
REG_BASE	EQU $1000

SUBR_VAR_X	EQU $D500

DDRC		EQU $07
PORTC		EQU $03
PORTB		EQU $04

OUT_CHAR	EQU $E3B3
* Buffalo - outputs char in A to the terminal

	ORG PSCT

	LDS #STACKTP
	LDY #REG_BASE

	LDAA PORTC,Y
	STAA INDEX
	
	BSR WRITE_VAR_X

	LDX #TEXT	* base address of the array
	JSR SUBR_VAR_X
	JSR OUT_CHAR
	SWI

WRITE_VAR_X
	PSHX
	PSHA
	LDX  #SUBR_VAR_X
	LDAA #$A6		* LDAA vv,X
	STAA 00,X
	INX
	LDAA INDEX
	STAA 00,X
	INX
	LDAA #$39		* RTS
	STAA 00,X
	PULA
	PULX
	RTS

	ORG DSCT
INDEX	RMB 1

	ORG IDSCT
TEXT
	FCC 'The quick brown fox jumped over the lazy dog.'
	FCB $0A, $0D
	FCC 'Morgan State University School of Engineering'
	FCB $0A, $0D
	FCC 'ABCDEFGHIJKLMNOP ... 1234567890'
	FCB $0A, $0D


