; That is my 2 routines I use to send and to receive a byte via link-port

; They are maybe not optimized , but they are free bugs : I use them in several
; prog (SEND92 / ZPONG / SEND-ROM ...)

; You must write a break routine , in case of error. If you want I can send an
; example , but it's very easy to do !

; Pascal

;-------------------------------------------------
;                   Rece_byte
;-------------------------------------------------
; INPUT   : NONE
; OUTPUT  : a           = Read byte value
Rece_By:
	  push bc
          push de
                ld    e,1       ; for the OR
                ld    c,0       ; byte receive
	        ld    b,8       ; counter
                ld    a,$C0
                out   (7),a
rb_w_Start:
		in    a,(7)
		and 3
                cp  3
                jr    nz,rb_get_bit
		CALL_(Test_ON)
                jr    rb_w_Start
rb_get_bit:
                cp    2
                jr    z,rb_receive_zero
                ld    a,c
                or    e
                ld    c,a
                ld    a,$D4
                out   (7),a
                jr    rb_waitStop

rb_receive_zero:
                ld    a,$E8
                out   (7),a
rb_waitStop:
                CALL_(Test_ON)
		in    a,(7)
		and   3
                jr    z,rb_waitStop
                ld    a,$c0
                out   (7),a
                rl    e
	        djnz	rb_w_Start
                ld    a,c
	  pop de
          pop bc
          ret

;-------------------------------------------------
;                    Send_byte
;-------------------------------------------------
; INPUT   : a
; OUTPUT  : NONE
Send_By:
	  push  bc
	        ld    b,8
                ld    c,a	;byte to send
                ld    a,$C0
                out   (7),a
w_setport3:
		in    a,(7)
		and 3
                cp  3
                jr    z,calc_bit
		CALL_(Test_ON)
                jr    w_setport3
calc_bit:
                ld    a,c
	        and   1
	        jr    z,send_one
send_zero:
	        ld    a,$E8
	        out   (7),A
                jr    wait_setport
send_one:
	        ld    a,$D4
	        out   (7),A
wait_setport:
		CALL_(Test_ON)
                in    a,(7)
		and   3
                jr    nz,wait_setport
 	        ld    a,$C0
	        out   (7),A
	        srl c
	        djnz w_setport3
          pop bc
          ret

Test_ON :

; [Insert here your break routine]

