//
// AFS Version D2.0
//
#include "gdcglob.txt"
//
//*********************************************************
// local parameter
//*********************************************************
// counter
// used counter 14
//      counter 15
//
//*********************************************************
//
        setbaud H,1,9600,8,n,1
        setp    0x7f02,0x01
        mode_reco
//
        setrts  on
        sett    10
        wait    tf_sign
#ifdef small_gdc
        movd    "^L Small-G-D-C V0.9c (Modul 0) *GDC09c.DW0* by J. Hoerhager AOPE/l/n",wstr_m04,0
#else
        movd    "^L G-D-C  V0.9c (Modul 0) *GDC09c.DW0* by J. Hoerhager AOPE/l/n",wstr_m04,0
#endif
        out     wstr_m04,0,c4
        wrs     wstr_m04,0,100
        //
error_main:
        setp    0x7f02,0x01     // kein Sendeabbruch nach Timeout
        mode_reco
//
main_1:
        sett    50
//
main:
        setl    8,1
        setrts  on
        wait    rx_sign,ans_sign,tf_sign
        case    ans_sign,test_rx_sign
loop_out_b:
        setl    8,2
        readb   wstr_m0,0,out_b
        jz      get_from_mess
#ifdef replace_ff
        compd   "^L",wstr_m0,0
        jnz     print_l1
        movd    "^J",wstr_m0,0
        movd    " Replace FormFeed with LF/n",wstr_m04,100
        out     wstr_m04,100,c4
print_l1:
#endif
        wrs     wstr_m0,0,220
        jnz     error_write_out
        call    copy_to_buffer
        wrchar  ^J
        jmp     loop_out_b
//
get_from_mess:
        jmp     main_1
//
error_write_out:
        movd    "ERROR on printing data to serialport 0/n",wstr_m04,0
        writeb  wstr_m04,0,mess_b
        sendsig ans_sign,c0
        setc    0,10
wait_again:
        sett    10
        wait    tf_sign,ans_sign
//
test1_tf_sign:
        case    tf_sign,wait_again
        sett    10
        decc    0
        jnz     wait_again
        wrs     wstr_m0,0,220
        jnz     error_write_out
        call    copy_to_buffer
        wrchar  ^J
        jmp     main_1
//
test_rx_sign:
        case    rx_sign,test_tf_sign
        rds     wstr_m04,0
        out     wstr_m04,0,c4
        jmp     main_1
//
test_tf_sign:
        case    tf_sign,main
        jmp     loop_out_b
//
//*********************************************************
// copy output to buffer
//
// first test if buffer should be print
//
copy_to_buffer:
        compd   "copy buffer1",wstr_m0,0
        jnz     store_buffer
        movd    "end_copy1/n",wstr_m0,0
        call    write_hist
        movd    "COPY BUFFER 1!/n",wstr_m0,0
        wrs     wstr_m0,0,220
        wrchar  ^J
//
copy_loop:
        readb   wstr_m0,0,copy1
        wrs     wstr_m0,0,220
        wrchar  ^J
        compd   "end_copy1/n",wstr_m0,0
        jz      copy_end
        call    write_hist
        jmp     copy_loop
//
copy_end:
        ret
//**********************************************************
//
store_buffer:
write_hist:
        writeb  wstr_m0,0,copy1
        jz      wr_hist1
        readb   wstr_m04,0,copy1
        jmp     write_hist
wr_hist1:
        ret
zzz:
//
end

