         TITLE "MODEM2"

;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     00CH 
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
	.8080
	XRA	A
	STA	ECHO
	.Z80 
	 JP	 LOOP 
NITMSG:  DEFB    18H,14H,84H,13H 
         DEFB    0C1H,15H,68H,80H



     
LOOP:   IN      A,(SIOACM)          
	 AND     RXFULL
         CALL    NZ,CHRIN
         LD      C,COSTAT
         CALL    BDOS
         CP      00
         CALL    NZ,CHROUT
         JP      LOOP
CHRIN:   IN      A,(SIOADA)
         LD      C,CONIN
         LD      E,A
         CALL    BDOS
         RET
CHROUT:	LD      C,CONOUT
         CALL    BDOS
         CP      3
         CALL    Z,WRMSRT
	.8080
	PUSH	D
	PUSH	B
	PUSH	H  
	PUSH	PSW
	LDA	ECHO
	ANA	A
	JZ	AAA
	LXI	D,HION
	MVI	C,9
	CALL	BDOS
	MVI	C,CONIN
	POP	PSW
	PUSH	PSW
	MOV	E,A
	CALL	BDOS
	LXI	D,HIOFF
	MVI	C,9
	CALL	BDOS
AAA:	POP	PSW
	CPI	5
	JNZ	NOTOGG
	PUSH	PSW
	LDA	ECHO
	XRI	0FFH
	STA	ECHO
       	POP	PSW
NOTOGG:	POP	H
	POP	B
	POP	D
	CPI	5
	RZ
	.Z80
         OUT     (SIOADA),A
         RET
WRMSRT:	.8080
	LXI	H,TXT2
	LXI	D,80H
	LXI	B,9
	.Z80
	LDIR
	.8080
CHAIN:	MVI	A,0
	STAX	D
	MVI	C,47
	CALL	5
	JMP	0
TXT2:	DEFB	'MODEM    '
ECHO:	DEFB	0
HION:	DEFB	1BH,')$'
HIOFF:	DEFB	1BH,'($'
	END
