/* TestData.c

This program is meant to be loaded via the SerialIO.exe
It will test the data bus and the lower 15 bits of the address bus.
The program begins writing in RAM just beyond the end of the program
and continues up to and including 0x7FFF.  It starts over when it
detects that address bit 15 is going to be accessed.

Program outline:
A: pulse PB7
	initialize RAM address and data value
B: write data to RAM
	read data from same RAM and output to Parallel Port A
	increment address and data value
	if address != 0x8000 goto B
	goto A
*/

main () {
;
#asm
TestData::
; These I/O registers are to be loaded directly via SerialIO

			ld		a, 0x51					; disable the watch dog timer
	ioi	ld		(WDTTR), a
			ld		a, 0x54
	ioi	ld		(WDTTR), a

			ld		a, 0x05					; bank 0 = CS1 WE1/OE1 (RAM)
	ioi	ld		(MB0CR), a
			ld		a, 0						; bank 1 = CS0 WE0/OE0 (flash)
	ioi	ld		(MB1CR), a

			ld		a, 0x08					; clock use full clock speed
	ioi	ld		(GOCR), a
			ld		a, 0x03					; clock doubler enabled at 20MHz
	ioi	ld		(GCDR), a

; These instructions are to be loaded into RAM and then executed

Start:	ld		a, 0x80					; PB7 = 1
	ioi	ld		(PBDR), a
			xor	a							; PB7 = 0
	ioi	ld		(PBDR), a

			ld		hl, RAMaddr-Start		; get address of RAM to use
			ld		b, 0						; initial value to write

MemLoop:
			ld		(hl), b					; write to RAM
			ld		a, (hl)					; read value back
	ioi	ld		(PADR), a				; display on A
			inc	b							; next output value

			inc	hl							; point to next address
			bit	7, h						; reached 0x8000?
			jr		z, MemLoop				; jump if no
			jr		Start						; start over

; This I/O register is to be loaded directly via SerialIO

			ld		a, 0x84					;terminate bootstrap
	ioi	ld		(SPCR), a

RAMaddr:
#endasm
}
