
;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     60H 
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	 LOOP 
NITMSG:  DEFB    18H,14H,4CH,13H 
         DEFB    0C1H,15H,68H,80H

LOOP:	.8080
	XRA	A
	STA	VERZ
	MVI	C,9
	LXI	D,TXT8
	CALL	BDOS
	MVI	C,1
	CALL	BDOS
	CPI	'Y'
	JZ	FULL
	CPI	'y'
	JZ	FULL
	MVI	A,1
	STA	VERZ
FULL:	LXI	D,FCB
	LXI	H,5CH
	LXI	B,24H
	.Z80
	LDIR
     	.8080
	LXI	D,5CH
	MVI 	B,11
WILD:	INX	D
	LDAX	D
	CPI	'*'
	JZ	CONFIR 
	CPI	'?'
	JZ	CONFIR
	DCR	B
	JNZ	WILD
NFIRM:	MVI	A,0
	STA	FIRM
SEND:	MVI	C,26
	LXI	D,80H
	CALL	BDOS
	LXI	D,5CH
	MVI	C,17
	CALL	BDOS
	CPI	-1
	JZ	NFOUND
NXTFIL:	LXI	H,80H
	LXI	D,20H
LOOP1:	DCR	A
	JM	WRTNAM
	DAD	D
	JMP	LOOP1
WRTNAM:	PUSH	H
	CALL	COPY
	POP	H
	PUSH	H
	LXI	D,5CH
	INX	D
	INX	H
	LXI	B,11
	.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ND:	MVI	C,9
	LXI	D,TXT2
	CALL	BDOS
CHAIN:	LXI	H,TXT6
	LXI	D,80H
LOOP6:	MOV	A,M
	STAX 	D
	ANA	A
	INX	D
	INX	H
	JNZ	LOOP6
	LXI	B,0FFFH
WAIT:	DCX	B
	MOV	A,B
	ORA	C
	JNZ	WAIT
	MVI	C,47
	CALL	BDOS
	JMP	0
TXT6:	DEFB	'MODEM1   ',0
TXT3:	DEFB	1BH,66H,'Ambiguous Filename. Confirm individual Files (y/n)? ',0DH,1BH,67H,24H
CONFIR:	MVI	C,9
	LXI	D,TXT3
	CALL	BDOS
	MVI	C,1
	CALL	BDOS
	CPI	'Y'
	JZ	FIRM1
	CPI	'y'
	JZ	FIRM1
	JMP	NFIRM
FIRM1:	MVI	A,1
	STA	FIRM
	JMP	SEND
FIRM:	DEFB	0
TXT4:	DEFB	1BH,66H,'       OK to transmit (y/n)? ',0DH,1BH,67H,24H
NOTOK:	POP	H
	JMP	EOF1
END3:	POP	PSW
	JMP	EOF
END2:	POP	PSW
	MVI	C,9
	LXI	D,TXT7
	CALL	BDOS
	JMP	CHAIN
TXT7:	DEFB	1BH,66H,'       transmit aborted',0DH,1BH,67H,24H
TXT8:	DEFB	1BH,66H,'Transmit at full speed (y/n)? ',0DH,1BH,67H,24H
VERZ:	DEFB	0
XOFF:	PUSH	D
	MVI	C,6
	MVI	E,-1
	CALL	BDOS
	POP	D
	CPI	3
	JZ	END2
	IN	SIOACM
	ANI	RXFULL
	PUSH	B
	CNZ	INPUT
	POP	B
	CPI	18H
	JZ	END6
	CPI	11H
	JNZ	XOFF
	JMP	CONTIN
END4:	POP	PSW
	LXI	D,TXT11
	CALL	SENDST
	MVI	C,9
	LXI	D,TXT11
	CALL	BDOS
	JMP	EOF1 
END5:	LXI	D,TXT12
	CALL	SENDST	
	LXI	D,TXT12
	MVI	C,9
	CALL	BDOS
	JMP	CHAIN
END6:	POP	PSW
	LXI	D,TXT12
	CALL	SENDST
	LXI	D,TXT12
	MVI	C,9
	CALL	BDOS
	LXI	D,TXT13
	CALL	SENDST
	LXI	D,TXT13
	MVI	C,9
	CALL	BDOS
	JMP	CHAIN
TXT13:	DEFB	'Bitte warten!',13,10,10,'$'
TXT12:	DEFB	13,10,10,'Download abgebrochen!',13,10,10,'$'
TXT10:	DEFB	13,10,10,'                 Zum Starten der ]bertragung <RETURN> dr}cken.',13,10,10,'$'
TXT11:	DEFB	13,10,10,'Timeout erreicht.',13,10,10,'$'
SENDST:	LDAX	D
	CPI	'$'
	RZ
	CALL	OUTCHR
	INX	D
	JMP	SENDST
	END
