; A Level Computing Science Project: Car Burglar Alarm.
;
; This program tests the hardware.  After initialising
; the hardware, the program waits in an infinite loop
; waiting for an interrupt, either with an IRQ or an NMI.
; In the interrupt service routine, the output port is
; inverted, thereby causing the LEDs attached to it to
; "blink" when an interrupt occurs.  The nature of this
; program tests all the hardware with the exception of
; the keypad, which was tested using a different method
; which didn't involve any system hardware.
;
; (C) 1987, 2026 Rich Teer.


flags	*		&0000			; Various flags.
tries	*		&0001			; Number of attempts at entering code number.
sec100	*		&0002			; 1/100 second timer.
secs	*		&0003			; Number of seconds before timeout.
pclo	*		&0004			; PC lo.
pchi	*		&0005			; PC hi.
acc		*		&0006			; Accumulator store.
xreg	*		&0007			; X Register store.
yreg	*		&0008			; Y Register store.
temp	*		&0009			; Temporary storage.
enterd	*		&0200			; Entered password stored from here.

v1iorb	*		&8000			; VIA 1 I/O Register B.
v1iora	*		&8001			; VIA 1 I/O Register A.
v1ddrb	*		&8002			; VIA 1 Data Direction Register B.
v1ddra	*		&8003			; VIA 1 Data Direction Register A.
v1t1cl	*		&8006			; VIA 1 Timer1 Counter Low.
v1t1ch	*		&8007			; VIA 1 Timer1 Counter High.
v1acr	*		&800B			; VIA 1 Auxiliary Control Register.
v1ifr	*		&800D			; VIA 1 Interrupt Flag Register.
v1ier	*		&800E			; VIA 1 Interrupt Enable Register.


		ORG		&F000			; Assemebled code to start at &F000.

reset	SEI						; Disable interrupts.
		CLD						; Clear Decimal mode.
		LDXIM	&FF				; Load X Register with 255,
		TXS						; and reset Stack Pointer.
		LDAIM	&80				; Load Accumulator with 128,
		STA		v1ier			; and disable interrupts from VIA.
		LDAIM	&1F				; Load Accumulator with 31,
		STA		v1ddra			; and initialise DDRA.
		LDAIM	&F0				; Load Accumulator with 240,
		STA		v1ddrb			; and initialise DDRB.
		LDAIM	&00				; Load Accumulator with 0 to
		STAZ	flags			; zero all flags,
		STA		v1iora			; zero I/O port A, and
		STA		v1iorb			; zero I/O port B.
		LDAIM	&10				; Load Accumulator with 16, i.e., 10,000 MOD 256,
		STA		v1t1cl			; and store in counter low.
		LDAIM	&27				; Load Accumulator with 39, i.e., 10,000 DIV 256,
		STA		v1t1ch			; to set up Timer 1 to count for 10,000 cycles.
		LDAIM	&40				; Load Accumulator with 64, and
		STA		v1acr			; set Timer1 to continuous operation.
		CLI						; Enable interrupts.
goto	JMP		goto			; Infinite loop for the purposes of testing.

timout
nmi		LDA		v1iorb			; Load Accumulator with I/O port B.
		EORIM	&FF				; Perform a one's complement on it,
		STA		v1iorb			; and store back in I/O port B.
		RTI						; Return from interrupt.

		LNK		bugos2			; Continue assembly with the vectors.
