//
// AFS Version D2.0
//
#include "gdcglob.txt"
//
//*********************************************************
// Funktion: Modul liest Strings von der Schnittstelle
//           und speichert diese im buffer "input_b".
//*********************************************************
// local parameter
//*********************************************************
// counter
// used counter 14
//      counter 15
//
//*********************************************************
//
        setbaud 1,9600,8,n,1
        setl    9,2
        setrts  off
        wrchar  xoff
        setp    0x7f02,0x01
        mode_reco
        setc    2,0             // counter 2 for status
//
        setrts  off
        wrchar  xoff
        sett    50
        wait    tf_sign
#ifdef small_gdc
        movd    " Small-G-D-C  V0.9c (Modul 1) *GDC09c.DW1* by J. Hoerhager AOPE/n",wstr_m15,0
#else
        movd    " G-D-C  V0.9c (Modul 1) *GDC09c.DW1* by J. Hoerhager AOPE/n",wstr_m15,0
#endif
        out     wstr_m15,0,c4
//
        setrts  on
        sett    20
        wait    tf_sign
//
error_main:
        setp    0x7f02,0x01
        mode_reco
        wrchar  xon
//
main:
        sett    100
        sendsig ans_sign,c3           // send sign to recohandler
//
main_1:
        setl    9,1
//        wrchar  xon
        wait    rx_sign,cntl_sign,tf_sign
	case	cntl_sign,test_rx_sign
	compc	14,255
	jz	overrun
        jmp     main_1
overrun:
        movd    "ERROR Buffer overrun on input CHANNEL 1/n",wstr_m15,150
        writeb  wstr_m15,150,mess_b
	jmp	error_main
test_rx_sign:
	case	rx_sign,test_tf_sign
//
// stop transmitter of dhs 2
//
//       wrchar  xoff
        setl    9,2
        rds     wstr_m1,0
        jz      main_1
	compc	15,0
	jz	read_okay
        movd    "ERROR          on input from CHANNEL 1/n",wstr_m15,150
        movc    15,wstr_m15,156
        writeb  wstr_m15,150,mess_b
	compc	15,128		//test for break only
	jz	read_okay
	jmp	error_main
//
//***********************************************
//
test_tf_sign:
	case	tf_sign,main
        setc    2,0
        jmp     main
	//
read_okay:
//           1         2         3         4         5         6         7
// 01234567890123456789012345678901234567890123456789012345678901234567890
//" ***** N4    --> N00 27/02/01 15:41 00:00:08    1 ST        1562...................... M 00:00 1.056      ................ ................
//" ***** N0    <-- N04 27/02/01 15:41 00:00:08    0 ST        220....................... M 00:00 0.000      ................ ................
//
        compd   " ????? N????",wstr_m1,0
        jnz     read_send
        compd   "-->",wstr_m1,13        // Calldirektion outgoing ?
        jnz     inc_call
//
        compc   2,1                     // state == 1
        jnz     state_out0
//
        movd    "A",wstr_m1,7
        movs    wstr_m15,60,wstr_m1,8,4
        replace ". ",wstr_m1,8,4
        setc    2,0
        jmp     read_send
//
state_out0:
        movs    wstr_m1,0,wstr_m15,0,149
        setc    2,2                     // State =2
        jmp     main
//
inc_call:
        compc   2,2                     // state == 2
        jnz     state_in0
//
        movd    "A",wstr_m15,7
        movs    wstr_m1,60,wstr_m15,8,4
        replace ". ",wstr_m15,8,4
        setc    2,0
        movs    wstr_m15,0,wstr_m1,0,149
        jmp     read_send
//
state_in0:
        movs    wstr_m1,0,wstr_m15,0,149        // save reco
        setc    2,1                     //state = 1 incomming reco saved
        jmp     main
//
read_send:
        writeb  wstr_m1,0,input_b       // to m3
        jnz     wait_write
        sendsig ans_sign,c3
        jmp     main_1
//
wait_write:
        wrchar  xoff
wait1_write:
        movd    "ERROR input_b is full/n",wstr_m15,150
        writeb  wstr_m15,150,mess_b
        sett    50
        wait    tf_sign
        writeb  wstr_m1,0,input_b       // to m3
        jnz     wait1_write
        wrchar  xon
        sendsig ans_sign,c3
        jmp     main
//
zzz:
//
end

