	.Z80
	ENTRY SIO

SIO:	JP START

;--------------- Konstanten und Variablen ---------

BDOS	EQU 5		;BDOS EINSPRUNG
PIOBC	EQU 3		;PIO-B CONTROL PORT
PIOBD	EQU 1		;PIO-B DATA PORT
SIOAC	EQU 6		;SIO-A CONTROL PORT
SIOAD	EQU 4		;SIO-A DATA PORT

SIOREG:	DB 11011000B	;RESET
	DB 1,00000000B	;NO INTERRUPTS
	DB 3,11000001B	;RCV 8 BIT/CHAR 
	DB 4,01001100B	;x16 CLOCK, 2 STOP BITS
	DB 5,01101000B	;NO DTR, TSM 8 BIT/CHAR, TRANSMIT ENABLE, NO RTS
SIOLEN	EQU $-SIOREG

	DB 0DH,0AH
STRING:	DB '0123456789'
	DB '$'
CNTDWN:	DB 7		;STRING OUTPUT COUNT DOWN
CNT:	DB 7

;--------------- PROGRAMM-ANFANG ------------------
		
START:	
	LD A,0FH	;PIO-B MODE = OUTPUT
	OUT (PIOBC),A
	LD A,00		;PIO-B BIT 0 = 0
	OUT (PIOBD),A

	LD HL,SIOREG	;SIO-A INIT.
	LD B,SIOLEN
	LD C,SIOAC
	OTIR

	LD HL,STRING
	PUSH HL
MLOOP:	
	IN A,(SIOAC)
	BIT 2,A		;TX BUFFER EMPTY?
	JP Z, WLOOP

	POP HL
NEXT:	LD A,(HL)
	CP '$'
	JP NZ,RAUS

	LD HL,STRING
	LD A,(CNT)
	DEC A
	JP NZ,SAMELN
	DEC HL
	DEC HL
	LD A,(CNTDWN)
SAMELN:	LD (CNT),A
	JP NEXT

RAUS:	INC HL
	PUSH HL
	OUT (SIOAD),A

	LD E,A
	JP PRINT

WLOOP:	LD E,'#'

PRINT:	LD C,2
	CALL BDOS
	
	LD C,6
	LD E,255
	CALL BDOS

	OR A
	JP Z,MLOOP

	POP HL
	DB 0FFH
	JP 0

	END
