; piotest.asm: Test port A of the Z80 PIO
; PIO is on I/0 port %1111 1100 (FC) - to %1111 1111 (FF)
; FC = Port A, Data mode
; FD = Port A, Command mode
; FE = Port B, Data mode
; FF = Port B, Command Mode

; Port and function - place one of these on the address bus.
		DEFINE PortA_DATA #FC
		DEFINE PortA_CMD  #FD
		DEFINE PortB_DATA #FE
		DEFINE PortB_CMD  #FF

; Port mode - place on data bus. Bits 5 and 4 are ignored. Bit 7 (MSB) and 6
; are Mode, and the lower 4 bits indicate a mode selection command.
		DEFINE Output	%00001111
		DEFINE Input	%01001111
		DEFINE Bi	%10001111
		DEFINE Control	%11001111

; The program - put port A into output mode, and send it a value. Start from
; 0 and just count up to FF ad infinitum.

		org #0000
		ld sp, #0400	; call stack - need it to return from NMI
PIOSetup	
		ld a, Output
		out (PortA_CMD), a
PIOWrite
		ld a, 1
loop		out (PortA_DATA), a
		halt		; Wait for an interrupt
		inc a
		jp loop

; NMI handler - does nothing, but an NMI will unhalt the program.
		ASSERT $ <= #66
		BLOCK #66 - $, 0
NMI		retn
		nop


