*-----------------------------------------------------------
* MEMTEST (SUMTEST)
*   BYTES STORED IN MEMORY ARE THE SUM OF THE
*   MSB AND LSB OF THE MEMORY POINTER, THEREFORE
*   ADJACENT MEMORY LOCATIONS AND ADJACENT
*   PAGES CONTAIN UNIQUE CONTENT.
*-----------------------------------------------------------
	ORG	0

INCH	EQU	$FF00		INPUT CHAR INTO A
INHEX	EQU	$FF0F		INPUT ONE HEX DIGIT TO B
BYTE	EQU	$FF53		INPUT TWO DIGIT BYTE TO B
BADDR	EQU	$FF62		INPUT ADDRESS TO X

OUT2H	EQU	$FF6D		DISPLAY 2 DIGIT HEX BYTE FROM A
OUTCH	EQU	$FF81		DISPLAY CHAR FROM B
OUTS	EQU	$FF82		DISPLAY A SPACE
MONITR	EQU	$FFAB		RE-ENTER PROM MONITOR

SIOCSR	EQU	$F000
SIODR	EQU	$F001

CR	EQU	$0D
LF	EQU	$0A

	BRA	MEMTST

CTR	RMB	1      		PASS COUNTER
STORE	RMB	1      		BIT MISMATCHED
INXMSB	RMB	1
INXLSB	RMB	1
LOTEMP	RMB	2		START ADDRESS OF TEST
HITEMP	RMB	2		END ADDRESS+1 OF TEST
	RMB	16
STACK	RMB	1

MEMTST	LDS	#STACK
	BSR	CRLF
	LDAB	#'*'
	JSR	OUTCH

	JSR	BADDR		GET START ADDRESS OF TEST
	STX	LOTEMP
	JSR	OUTS
	JSR	BADDR		GET END ADDRESS OF TEST
	STX	HITEMP

	LDAA	LOTEMP		STARTING ON PAGE ZERO?
	BNE	NOTPG0		NO
	LDX	#ENDADDR
	STX	LOTEMP		DON'T CLOBBER THIS CODE

NOTPG0	LDX	#0		INITIALIZE DATA
	STX	CTR
	STX	INXMSB

MTSTRT	LDX	LOTEMP

MTLP1	BSR	INCRX		INCREMENT INDEX
	STAA	0,X
	INX
	CPX	HITEMP		END OF MEMORY?
	BNE	MTLP1

	LDAA	SIOCSR		KEY PRESSED?
	ASRA
	BCS	EXIT		YES

	LDX	LOTEMP

MTLP2	BSR	INCRX
	EORA	0,X
	BNE	ERROR

MTRET	INX
	CPX	HITEMP
	BNE	MTLP2

	LDAB	#'+'
	JSR	OUTCH
	INC	CTR
	JMP	MTSTRT

INCRX 	STX	INXMSB
	LDAA	INXMSB
	ADDA	INXLSB		ADD IN ADDR LSB
	ADDA	CTR		ADD IN COUNTER
	RTS

ERROR	STAA	STORE		STORE ERRANT BIT
	BSR	CRLF

	LDAA	CTR		DISPLAY COUNTER
	JSR	OUT2H
	JSR	OUTS

	LDAA	STORE		DISPLAY ERROR VALUE
	JSR	OUT2H
	JSR	OUTS

	LDAA	INXMSB		DISPLAY ERROR ADDRESS
	JSR	OUT2H
	LDAA	INXLSB
	JSR	OUT2H

	LDX	INXMSB
	BRA	MTRET

CRLF	LDAB	#CR		DO CR/LF
	JSR	OUTCH
	LDAB	#LF
	JMP	OUTCH

EXIT	LDAA	SIODR		GET RID OF CHARACTER
	LDX	$FFFE
	JMP	0,X

ENDADDR	EQU	*

	END
