						;*****************************
						;Datenübertragung AMIGA -> C64
						;
						;Daten empfangen
						;*****************************


receive_data		?print 200,"WAITING FOR DATA"
						sei

						;====================
						;auf Startbyte warten
						;====================

wait_byte			inx
						stx SCREEN_ADR

						lda #$10				;Maske für BIT 4 laden
						bit CIA_ICR			;liegt Byte an?
						bne get_byte		;ja, Byte holen
						lda CIA_PORT		;Signal auf Port-Controll-Ltg. ausgeben
						bne wait_byte
						beq wait_byte


						;===================
						;Byte vom Port holen
						;===================

get_byte				lda CIA_PORT		;Byte vom Port holen
						sta SCREEN_ADR+2	;und zur Kontrolle ausgeben
						ldy #$00
						sta (BUFF_PTR),y	;und in den Buffer schreiben
						?print 200,"RECEIVING DATA  "
						inc BUFF_PTR		;Bufferptr. low erhöhen
						bne time_out		;kein Überlauf
						inc BUFF_PTR+1		;Bufferptr. high erhöhen


						;=======
						;Timeout
						;=======

time_out				lda #$40				;high Byte des Timeout Zählers
						sta $02
						ldx #$00				;low Byte Timeout

time_out1			lda #$10				;Maske für BIT 4 laden
						bit CIA_ICR			;liegt Byte an?
						bne get_byte		;ja, Byte holen
						dex					;Timeout Zähler-1
						bne time_out1
						dec $02				;Timeout high Byte-1
						bne time_out1

						;======================================
						;Timeout erreicht, Rücksprung zum Basic
						;======================================

						lda #$37
						sta $01				;Basicinterpreter wieder einschalten
						cli
						?print 240,"ALLRIGHT"
						lda #10				;Curor auf Zeile setzen
						sta $d6
						rts					;zum Basic
