	TITLE 'Testprogramm zur LED-Anzeige'

; MC80 Version 1.0
; 14.09.89

    ; Z80 macro library instruction definitions

	maclib z80

    ; common control characters

cr	equ 13
lf	equ 10
bell	equ 7

;**************************************************************
; Vereinbarungen
;**************************************************************

bdos	equ	5

ledctc	equ	0dh
ledpio	equ	80h
pioadat	equ	ledpio
pioactr	equ	ledpio+1
piobdat	equ	ledpio+2
piobctr	equ	ledpio+3

;**************************************************************
; Programm
;**************************************************************

anf:				; Initialisieren der PIO
	mvi a,4fh ! out pioactr ! out piobctr
	mvi a,0 ! out pioadat ! out piobdat
	mvi a,0ffh ! out pioactr ! mvi a,0fh ! out pioactr
	mvi a,0ffh ! out piobctr ! xra a ! out piobctr

	mvi a,0 ! sta lednr
	lxi h,ledint ! shld 0e66ah
	mvi a,0a5h ! out ledctc ! mvi a,40 ! out ledctc
wait:
	in 06h ! cpi 30h
	jnz wait
	mvi a,3 ! out ledctc
	xra a ! out piobdat
	ret

ledint:
	push psw ! push h ! push d ! push b
	mvi a,0 ! out piobdat
	lda lednr ! mov b,a
	srlr a
	mov e,a ! mvi d,0
	lxi h,0e5f6h ! dad d ! mov a,m
	bit 0,b
	jrz norot
	rlc ! rlc ! rlc ! rlc
norot:
	out pioadat
	mvi a,40h ! mov e,b ! inr b
rotbi:	rrc
	djnz rotbi
	ori 80h
	mov b,a
	bit 0,e
	jrz aus
	mov a,e ! cpi 5
	jrz aus
	setb 6,b
aus:
	mov a,b
	out piobdat
	lda lednr ! inr a
	cpi 6
	jrnz nonew
	xra a
nonew:	sta lednr
	pop b ! pop d ! pop h ! pop psw
	ei
	reti

lednr:	db	0

	ds	64
stack:
	end
