; Demo Assembly Program - Edward Cheung
; Demo System 11 Assembly Program 
; March 2021 - ed@edcheung.com
; Typical Assemble command c:\Progra~1\a68\a68 full.asm -l full.lst -o full.hex
; 3/11/21 - fully functional version

; Data section
		ORG $0000	; Bottom of ROM
		FCB $11,$22,$33,$44,$55,$66,$77,$88
		
; Top of main to demo read/writes
MAIN	ORG	$3000		;@B000 to CPU
		LDA A $8000	; Read bottom of ROM and write to RAM
		STA A $0001	;   0001 <- 8000 (memory location)
		LDA A $0001	;   0001?
		LDA A #$55	; Write constant to RAM
		STA A $0001	;   0001 <- 0x55 (literal)
		LDA A $0001	;   0001?
		LDS #$07FF	; Set location of Stack
		JMP $B000

; Interrupt to light LED2 on pushbutton
NMI_HANDLER	ORG $4000	;@C000 to CPU
		LDA A #$30	; Access DDR Port A
		STA A $2801	;   2801 <- 0x30 (literal)
		LDA A #$FF	; All as outputs
		STA A $2800	;   2800 <- 0xFF (literal)
		LDA A #$00	; Access Data Port
		STA A $2801	;   2801 <- 0x00 (literal)
		LDA A #$FF	; All outputs high to light LED2
		STA A $2800	;   2800 <- 0xFF (literal)
		CLI		; Allow IRQ to fire
		JMP $B000	; Back to MAIN

; Interrupt to clear LED2
IRQ_HANDLER	ORG $2000	;@A000 to CPU
		LDA A #$00	; All outputs low to off LED2
		STA A $2800	;  2800 <- 0x00
		JMP $B000	; Back to MAIN

; Set up Vectors
		ORG $7FF8
		FCB $A0,$00	; Periodic Int: IRQ Vector @ $2000
		FCB $B0,$00	; SW int (not used)
		FCB $C0,$00	; Push button: NMI @ $4000
		FCB $B0,$00	; Power Up: RESET @ $3000
		END
