; program to test user buzzer/speaker on Z80 MBC clock board
; by Andrew Lynch, 6 Jul 2021

	org $0100

	LD	HL,$7FFF	; INITIALIZE OUTER LOOP
	LD	DE,$0001	; DECREMENT VALUE

START:

	LD	A,%00000100
	OUT	($70),A		; TURN ON SPEAKER

	LD	B,$80		; HOLD SPEAKER ON FOR 128 COUNTS
LOOP1:	DJNZ	LOOP1

	LD	A,%00000000
	OUT	($70),A		; TURN OFF SPEAKER

	LD	B,$80		; HOLD SPEAKER OFF FOR 128 COUNTS
LOOP2:	DJNZ	LOOP2

	SBC	HL,DE		; REDUCE OUTER LOOP BY 1

	JR	NZ,START	; LOOP 32768 TIMES, ABOUT 15 SECONDS

	LD	A,%00000011
	OUT	($70),A		; TURN ON BOTH USER LEDS

;	HALT			; HALT & TURN ON HALT LED

    RET

	end

