/* TestSerA.c

This program is meant to be loaded via the SerialIO.exe
*/

main () {
;
#asm
TestData::
; These I/O registers are to be loaded directly via SerialIO.  The first two
; of these instructions should probably be included in every program which
; is downloaded using 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		(GCSR), a
			ld		a, 0x07					; clock doubler enabled at 12MHz
	ioi	ld		(GCDR), a
*/
; These instructions are the program and are loaded into RAM and then executed

			ld		a, 4						; timer = /5
	ioi	ld		(TAT5R), a
;	ioi	ld		(TACSR), a				; enable timer A

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

WaitRCV:
;	ioi	ld		a, (SBSR)				; read status register
;			and	0x80						; char available?
;			jr		nz, WaitRCV				; jump if no
;	ioi	ld		a, (SBDR)				; get the byte
;
WaitXMT:
			ld		a, 0x55					; dummy char
	ioi	ld		(SBDR), a				; transmit it
	ioi	ld		a, (SBSR)				; read status register
			and	0x4						; char done?
			jr		nz, WaitXMT				; jump if no
			xor	a							; PB7 = 0
	ioi	ld		(PBDR), a
	
			jr		Start

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

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

#endasm
}
