         TITLE "MODEM1"

;Z80 - ASSEMBLERBEFEHLE BENUTZEN

         .Z80

;ABSOLUTEN MASCHINENCODE ERZEUGEN

         ASEG
         ORG     0100H


SYSRES   EQU     00
BDOS     EQU     05
CONOUT   EQU     03                     
CONIN    EQU     02
COSTAT   EQU     11
CTCCH0   EQU     04
CTCCTL   EQU     45H
CTCTC    EQU     0C0H 
SIOACM   EQU     02
SIOADA   EQU     00
TXEMPT   EQU     00000100B
RXFULL   EQU     00000001B
COUNT    EQU     07
ESC      EQU     1BH


;CTC INITIALISIERUNG

START:   LD      A,CTCCTL        ;CTC CONTROL WORT
         OUT     (CTCCH0),A      ;PORT 04
         LD      A,CTCTC         ;CTC TIME CONST. WORT
         OUT     (CTCCH0),A      ;PORT 04
       
;SIO INITIALISIERUNG

         LD      HL,NITMSG
         LD      B,COUNT
         LD      C,SIOACM        
         OTIR
	 JP	 ANFANG
NITMSG:  DEFB    18H,14H,84H,13H 
         DEFB    0C1H,15H,68H,80H

KENN:	DEFB	030H,0B1H,030H,0B4H,0B8H,0B4H,0B4H,036H
	DEFB	030H,030H,0B1H,03AH,024H

ANFANG:	IN	A,(SIOACM)
	AND	20H
	JR	Z,START
	CALL	WAIT
	LD	HL,KENN
OLOOP:	IN	A,(SIOACM)
	AND	4
	JR	Z,OLOOP
	LD	A,(HL)
	CP	24H
	JR	Z,LOOP
	OUT	(SIOADA),A
	INC	HL
	JR	OLOOP	
     
LOOP:   IN	A,(SIOACM)
	AND     RXFULL
         CALL    NZ,CHRIN
	 CALL	 NZ,CHROUT
	LD	C,6
	LD	E,-1
	CALL	BDOS
	CP	3
	JP	Z,0
         JP      LOOP

CHRIN:   IN      A,(SIOADA)
         RET

CHROUT:	 OUT     (SIOADA),A
         RET

WAIT:	LD	BC,0
	LD	E,3
WAIT1:	DEC	BC
	LD	A,B
	OR	C
	JR	NZ,WAIT1
	DEC	E
	JR	NZ,WAIT1
	END
