






























































































































































































































































































































setbaud 1,9600,8,n,1
mode_opus300
setc    3,5
sett    10
wait    tf_sign
movd    "@D/n",s15,250
movd    "10101000101010001010100010101000",0xd080,0
movd    "10101000n",0xcf80,0




movd    " Alcatel AHL-EDV Interface Emulation                V3.2/n",s6,100
out     s6,100,c4
movd    " *4200AH32.DW2* BY HOERHAGER JOSEF AOCE          07//2008/n",s6,100
out     s6,100,c4
movd    " Ready for working !/l/n",s6,100
out     s6,100,c4
setc    2,0
error_main:
mode_opus300
call    init_ahl
sendsig ans_sign,c2       
jmp     main


main:
main_t1:

sett    20              
maint1_loop:
main_loop:
compd   "0",s14,249
jz      main_t0

buffst                  

wait    im_sign,tf_sign,rx_sign,ans_sign,cntl_sign

case    tf_sign,testt1_cntl_state
got1_test_send:
wrchar  enq
decc    3
jnz     main

jmp     main

testt1_cntl_state:
case    cntl_sign,testt1_rx_state

compc   14,5
jnz     no_enq
setc    3,5

compc   2,0
jnz     got1_send
movd    "T2                                                                                 /n",s9,0

readb   s9,2,5          
jnz     sendt1_reply_first

buffrd  s9,2
compd   "E/n",s9,2
jz      main_t1l

sendt1_reply_first:
setc    2,10
got1_send:



call    opus_txstate
jnz     main_t1l

setc    2,0
jmp     main_t1l


no_enq:
call    opus_cntlstate
jmp     main

main_t1l:
sett    1


jmp     maint1_loop

testt1_rx_state:
case    rx_sign,testt1_ans_state
call    opus_rxstate
jmp     main_loop

testt1_ans_state:
case    ans_sign,test_im_state
jmp     main_loop



main_t0:


buffst                  

wait    im_sign,tf_sign,rx_sign,ans_sign,cntl_sign

case    tf_sign,test_rx_state
go_test_send:
compc   2,0
jnz     go_send
movd    "T2                                                                                 /n",s9,0

readb   s9,2,5          
jnz     send_reply_first

buffrd  s9,2
compd   "E/n",s9,2
jz      main

send_reply_first:
setc    2,10
go_send:



call    opus_txstate
jnz     main_loop
sendsig ans_sign,c2
setc    2,0
jmp     main

test_rx_state:
case    rx_sign,test_cntl_state
call    opus_rxstate
jmp     main_loop

test_cntl_state:
case    cntl_sign,test_ans_state
call    opus_cntlstate
jmp     go_test_send


test_ans_state:
case    ans_sign,test_im_state
jmp     go_test_send














init_ahl:
setp    0x7f00,0x03
setp	0x7f01,0x00
setp    0x7f03,0x00     ;select crc-calculation AHL

mode_opus300

movd    "EDV-RX_TX2          /n",s6,0
movd    " AHL-State IDLE/n",s6,11

setc    1,30     
ret




mode_opus300                    

opus_txstate:

movd    " AHL-State TRANSMIT/n",s6,11
out     s6,0,c4

out     s9,0,c4
setc    12,5

l_data_stx:
clear   cntl_sign               

compd   "1",s14,244
jnz     skip_db1
writeb  s9,0,4
sendsig ans_sign,c3
skip_db1:

opuswrs s9,2,150      
jz      wait_ackn_data          



mode_opus300                    
movd    " TIMEOUT ERROR ON WRITE TO CHANNEL AHL (xoff)!/n",s6,11
out     s6,0,c4

compd   "1",s14,244
jnz     skip_db2
writeb  s6,0,4
sendsig ans_sign,c3
skip_db2:

decc    12
jnz     l_data_stx
opus_err_timeout:
mess_max_retry:
movd    " Max retry reached!/n",s6,11
out     s6,0,c4
movd    "EERR_TO/n",s6,11
out     s6,0,c4

compd   "1",s14,244
jnz     skip_db3
writeb  s6,0,4
sendsig ans_sign,c3
skip_db3:

mode_opus300
jmp     nz_ret

wait_ackn_data:
sett    40          
wait    cntl_sign,tf_sign,rx_sign
case    rx_sign,do_cntl_stx
call    opus_rxstate
jmp     wait_ackn_data

do_cntl_stx:
case    cntl_sign,to_data_stx
compc   14,6                    
jnz     data_nak
movd    "RECEIVED *ACK*/n",s6,11

jmp     z_ret

data_nak:
compc   14,21                   
jnz     data_wrong
movd    " ERROR ON DATA-SEND: RECEIVED *NAK*!/n",s6,11
out     s6,0,c4

compd   "1",s14,244
jnz     skip_db4
writeb  s6,0,4
sendsig ans_sign,c3
skip_db4:

decc    12          
jnz     l_data_stx              
jmp     mess_max_retry

data_wrong:
movd    " ERROR ON DATA-SEND: RECEIVED *   *!/n",s6,11
movc    14,s6,42        
out     s6,0,c4

compd   "1",s14,244
jnz     skip_db5
writeb  s6,0,4
sendsig ans_sign,c3
skip_db5:

mode_opus300
decc    12          
jnz     l_data_stx
jmp     mess_max_retry

to_data_stx:
movd    " ERROR ON DATA-SEND: WAIT ACKN. TIMEOUT!/n",s6,11
out     s6,0,c4

compd   "1",s14,244
jnz     skip_db6
writeb  s6,0,4
sendsig ans_sign,c3
skip_db6:

decc    12          
jnz     l_data_stx
jmp     mess_max_retry





opus_cntlstate:
movd    " ERROR CNTL-SIGN:    RECEIVED *   *!/n",s6,11
movc    14,s6,42        
out     s6,0,c4

compd   "1",s14,244
jnz     skip_db7
writeb  s6,0,4
sendsig ans_sign,c3
skip_db7:

ret




opus_rxstate:
movd    "R2",s2,0       
movd    " AHL-State RECEIVE/n",s6,11
out     s6,0,c4
opusrds s2,2
jz      nz_ret
compc   15,0                    
jnz     error_rxopus



movd    " Sending *ACK*/n",s6,11
out     s2,0,c4

writeb  s2,2,3
sendsig ans_sign,c3

compd   "1",s14,244
jnz     skip_db8
writeb  s6,0,4
sendsig ans_sign,c3
skip_db8:

wrchar  ack
jmp     z_ret

error_rxopus:
movd    " Sending *NAK*/n",s6,11
out     s2,0,c4
out     s6,0,c4

wrchar  nak
jmp     nz_ret




z_ret:
setc    0,255
incc    0
ret

nz_ret:	
setc    0,0
incc    0
ret



test_im_state:
case    im_sign,main_loop      


in      s6,100





compd   "tx",s6,100
jz      sendto_ser
compd   "rx",s6,100
jz      sendto_buffer

movd    " command not found/n",s6,100
anss    s6,100
jmp     main

main_message:
movd    "OK/n",s6,200
anss    s6,200
jmp	main

main_error:
movd    "Error/n",s6,200
anss    s6,200
jmp	main

sendto_ser:
buffwr  s6,102
sendsig ans_sign,c2
jmp     main_message

sendto_buffer:
writeb  s2,2,3
sendsig ans_sign,c3
jmp     main_message



































































































































zzz:

end

