;============================================================================
;
; translate this with 
; 	cat pseudocode | sed -f act2num |  awk -f compile.awk >pseudocode.h
;
; actionname	pseudocode
;
;============================================================================
ADM1		SEND_SABME_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		RETRY_COUNT:=0
		S_FLAG:=0
;
; instructions in ADM2 have been changed:
; 1. 	P_FLAG:=P is probably wrong in doc...
; 	I think it should be F_FLAG:=P the way it is in CONN3
; 2.	CONNECT_RESPONSE has been wired in here,
;	CONN1 is no longer referenced
;
ADM2		F_FLAG:=P
		SEND_UA_RSP(F=X)
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		P_FLAG:=0
		REMOTE_BUSY:=0
		CONNECT_INDICATION
ADM3		SEND_DM_RSP(F=X)
ADM4		SEND_DM_RSP(F=X)
ADM5		NOP
;============================================================================
;CONN1		SEND_UA_RSP(F=X)
;		V(S):=0
;		V(R):=0
;		RETRY_COUNT:=0
;		P_FLAG:=0
;		REMOTE_BUSY:=0
CONN2		SEND_DM_RSP(F=X)
CONN3		F_FLAG:=P
CONN4		DISCONNECT_INDICATION
CONN5		NOP
;============================================================================
RESWAIT1	SEND_SABME_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		RETRY_COUNT:=0
RESWAIT2	SEND_UA_RSP(F=X)
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		P_FLAG:=0
		REMOTE_BUSY:=0
		RESET_CONFIRM
RESWAIT3	SEND_DISC_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		RETRY_COUNT:=0
RESWAIT4	SEND_DM_RSP(F=X)		
RESWAIT5	DISCONNECT_INDICATION
RESWAIT6	S_FLAG:=1
		F_FLAG:=P
RESWAIT7	SEND_DM_RSP(F=X)
		DISCONNECT_INDICATION
RESWAIT8	NOP
;============================================================================
RESCHK1		SEND_UA_RSP(F=X)
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		P_FLAG:=0
		REMOTE_BUSY:=0
RESCHK2		SEND_DM_RSP(F=X)
RESCHK3		DISCONNECT_INDICATION
RESCHK4		F_FLAG:=P
RESCHK5		SEND_DM_RSP(F=X)
		DISCONNECT_INDICATION
RESCHK6		NOP
;============================================================================
SETUP1		SEND_UA_RSP(F=X)
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		S_FLAG:=1
SETUP2		STOP_ACK_TIMER
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		UPDATE_P_FLAG
		CONNECT_CONFIRM
		REMOTE_BUSY:=0
SETUP3		P_FLAG:=0
		CONNECT_CONFIRM
		REMOTE_BUSY:=0
SETUP4		SEND_DM_RSP(F=X)
		DISCONNECT_INDICATION
		STOP_ACK_TIMER
SETUP5		DISCONNECT_INDICATION
		STOP_ACK_TIMER
SETUP6		NOP
SETUP7		SEND_SABME_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
SETUP8		DISCONNECT_INDICATION
;============================================================================
RESET1		SEND_UA_RSP(F=X)
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		S_FLAG:=1
RESET2		STOP_ACK_TIMER
		V(S):=0
		V(R):=0
		RETRY_COUNT:=0
		UPDATE_P_FLAG
		RESET_CONFIRM
		REMOTE_BUSY:=0
RESET3		P_FLAG:=0
		RESET_CONFIRM
		REMOTE_BUSY:=0
RESET4		SEND_DM_RSP(F=X)
		DISCONNECT_INDICATION
		STOP_ACK_TIMER
RESET5		DISCONNECT_INDICATION
		STOP_ACK_TIMER
RESET6		NOP
RESET7		SEND_SABME_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
RESET8		DISCONNECT_INDICATION
;============================================================================
D_CONN1		SEND_DM_RSP(F=X)
		STOP_ACK_TIMER
D_CONN2		STOP_ACK_TIMER
D_CONN3		SEND_UA_RSP(F=X)
D_CONN4		STOP_ACK_TIMER
D_CONN5		NOP
D_CONN6		SEND_DISC_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
D_CONN7		NOP
;============================================================================
ERR1		RESET_INDICATION(REMOTE)
		STOP_ACK_TIMER
		F_FLAG:=P
ERR2		SEND_UA_RSP(F=X)
		DISCONNECT_INDICATION
		STOP_ACK_TIMER
ERR3		DISCONNECT_INDICATION
		STOP_ACK_TIMER
ERR4		RESET_INDICATION(LOCAL)
		STOP_ACK_TIMER
		REPORT_STATUS(FRMR_RECEIVED)
		S_FLAG:=0
ERR5		RE-SEND_FRMR_RSP(F=P)
		START_ACK_TIMER
ERR6		NOP
ERR7		RE-SEND_FRMR_RSP(F=0)
		START_ACK_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
ERR8		S_FLAG:=0
		RESET_INDICATION(LOCAL)
;============================================================================
; the shared actions are common to states NORMAL, BUSY, REJECT,
; AWAIT, AWAIT_BUSY and AWAIT_REJECT.
;============================================================================
SH1		SEND_DISC_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		STOP_OTHER_TIMERS
		RETRY_COUNT:=0
SH2		SEND_SABME_CMD(P=X)
		P_FLAG:=P
		START_ACK_TIMER
		STOP_OTHER_TIMERS
		RETRY_COUNT:=0
		S_FLAG:=0
SH3		RESET_INDICATION(REMOTE)
		F_FLAG:=P
		STOP_ALL_TIMERS
SH4		SEND_UA_RSP(F=X)
		DISCONNECT_INDICATION
		STOP_ALL_TIMERS
SH5		STOP_ALL_TIMERS
		RESET_INDICATION(LOCAL)
		REPORT_STATUS(FRMR_RECEIVED)
		S_FLAG:=0
SH6		DISCONNECT_INDICATION
		STOP_ALL_TIMERS
SH7		SEND_FRMR_RSP(F=X)
		REPORT_STATUS(FRMR_SENT)
		START_ACK_TIMER
		STOP_OTHER_TIMERS
		RETRY_COUNT:=0
SH8		SEND_FRMR_RSP(F=0)
		REPORT_STATUS(FRMR_SENT)
		START_ACK_TIMER
		STOP_OTHER_TIMERS
		RETRY_COUNT:=0
SH9		SEND_FRMR_RSP(F=0)
		REPORT_STATUS(FRMR_SENT)
		START_ACK_TIMER
		STOP_OTHER_TIMERS
		RETRY_COUNT:=0
SH10		SEND_FRMR_RSP(F=X)
		REPORT_STATUS(FRMR_SENT)
		START_ACK_TIMER
		STOP_OTHER_TIMERS
		RETRY_COUNT:=0
SH11		STOP_ALL_TIMERS
		RESET_INDICATION(LOCAL)
		S_FLAG:=0
;============================================================================
NORMAL1		SEND_I_CMD(P=1)
		START_P_TIMER
		START_ACK_TIMER_IF_NOT_RUNNING
;		SEND_I_XXX(X=0)
;		START_ACK_TIMER_IF_NOT_RUNNING
NORMAL2		SEND_I_XXX(X=0)
		START_ACK_TIMER_IF_NOT_RUNNING
NORMAL3		SEND_RNR_CMD(F=1)
		START_P_TIMER
		DATA_FLAG:=0
;		SEND_RNR_XXX(X=0)
;		DATA_FLAG:=0
NORMAL4		SEND_RNR_XXX(X=0)
		DATA_FLAG:=0
NORMAL5		SEND_REJ_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		UPDATE_P_FLAG
		START_REJ_TIMER
		IF_F=1_CLEAR_REMOTE_BUSY
;		SEND_REJ_CMD(P=1)
;		UPDATE_N(R)_RECEIVED
;		START_P_TIMER
;		START_REJ_TIMER
;		IF_F=1_CLEAR_REMOTE_BUSY
NORMAL6		SEND_REJ_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		START_REJ_TIMER
NORMAL7		SEND_REJ_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		START_REJ_TIMER
;
; the order of opcodes in NORMAL8 is changed.
; the transition table will execute NORMAL8A for incomming pdus
; with p/f 1, pdus with pf 0 are treated in NORMAL8B.
;   
NORMAL8A	V(R):=V(R)+1
		SEND_ACKNOWLEDGE_CMD(P=1)
		START_P_TIMER
		UPDATE_N(R)_RECEIVED
		IF_F=1_CLEAR_REMOTE_BUSY
		DATA_INDICATION
;
NORMAL8B	V(R):=V(R)+1
		UPDATE_P_FLAG
		SEND_ACKNOWLEDGE_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		IF_F=1_CLEAR_REMOTE_BUSY
		DATA_INDICATION
;
; the order of opcodes in NORMAL9 is changed 
NORMAL9		V(R):=V(R)+1
		SEND_ACKNOWLEDGE_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		DATA_INDICATION
;
; the order of opcodes in NORMAL10 is changed 
NORMAL10	V(R):=V(R)+1
		SEND_ACKNOWLEDGE_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		DATA_INDICATION
NORMAL11	UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
NORMAL12	SEND_ACKNOWLEDGE_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
NORMAL13	UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
NORMAL14	SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
NORMAL15	V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		UPDATE_P_FLAG
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
;		V(S):=N(R)
;		UPDATE_N(R)_RECEIVED
;		START_P_TIMER
;		RE-SEND_I_CMD(P=1)
;		CLEAR_REMOTE_BUSY
NORMAL16	V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
NORMAL17	V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		RE-SEND_I_RSP(F=1)
		CLEAR_REMOTE_BUSY
NORMAL18	SEND_RR_CMD(P=1)
		START_P_TIMER
NORMAL19	P_FLAG:=0
;		SEND_RR_CMD(P=1)
;		START_P_TIMER
;		RETRY_COUNT:=RETRY_COUNT+1
NORMAL20	SEND_RR_CMD(P=1)
		START_P_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
;============================================================================
BUSY1		SEND_I_CMD(P=1)
		START_P_TIMER
		START_ACK_TIMER_IF_NOT_RUNNING
;		SEND_I_XXX(X=0)
;		START_ACK_TIMER_IF_NOT_RUNNING
BUSY2		SEND_I_XXX(X=0)
		START_ACK_TIMER_IF_NOT_RUNNING
BUSY3		SEND_REJ_CMD(P=1)
		START_REJ_TIMER
		START_P_TIMER
;		SEND_REJ_XXX(X=0)
;		START_REJ_TIMER
BUSY4		SEND_REJ_XXX(X=0)
		START_REJ_TIMER
BUSY5		SEND_RR_CMD(P=1)
		START_P_TIMER
		SEND_RR_XXX(X=0)
BUSY6		SEND_RR_XXX(X=0)
BUSY7		SEND_RR_CMD(P=1)
		START_P_TIMER
		SEND_RR_XXX(X=0)
BUSY8		SEND_RR_XXX(X=0)
BUSY9		OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		IF_DATA_FLAG_=0_THEN_DATA_FLAG:=1
		IF_F=1_CLEAR_REMOTE_BUSY
;		SEND_RNR_CMD(P=1)
;		START_P_TIMER
;		UPDATE_N(R)_RECEIVED
;		IF_DATA_FLAG_=0_THEN_DATA_FLAG:=1
;		IF_F=1_CLEAR_REMOTE_BUSY
BUSY10		OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		IF_DATA_FLAG_=0_THEN_DATA_FLAG:=1
BUSY11		SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		IF_DATA_FLAG_=0_THEN_DATA_FLAG:=1
BUSY12		SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		IF_DATA_FLAG=2_STOP_REJ_TIMER
		DATA_FLAG:=1
;		V(R):=V(R)+1
;		DATA_INDICATION
;		SEND_RNR_RSP(F=1)
;		UPDATE_N(R)_RECEIVED
;		IF_DATA_FLAG=2_STOP_REJ_TIMER
;		DATA_FLAG:=0
BUSY13		OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		IF_DATA_FLAG=2_STOP_REJ_TIMER
		DATA_FLAG:=1
		IF_F=1_CLEAR_REMOTE_BUSY
;		SEND_RNR_CMD(F=1)
;		START_P_TIMER
;		UPDATE_N(R)_RECEIVED
;		IF_DATA_FLAG=2_STOP_REJ_TIMER
;		DATA_FLAG:=1
;		IF_F=1_CLEAR_REMOTE_BUSY
;		V(R):=V(R)+1
;		DATA_INDICATION
;		SEND_RNR_CMD(F=1)
;		START_P_TIMER
;		UPDATE_N(R)_RECEIVED
;		IF_DATA_FLAG=2_STOP_REJ_TIMER
;		DATA_FLAG:=0
;		IF_F=1_CLEAR_REMOTE_BUSY
;		V(R):=V(R)+1
;		DATA_INDICATION
;		UPDATE_P_FLAG
;		OPTIONAL_SEND_RNR_XXX(X=0)
;		UPDATE_N(R)_RECEIVED
;		IF_DATA_FLAG=2_STOP_REJ_TIMER
;		DATA_FLAG:=0
;		IF_F=1_CLEAR_REMOTE_BUSY
BUSY14		OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		IF_DATA_FLAG=2_STOP_REJ_TIMER
		DATA_FLAG:=1
;		V(R):=V(R)+1
;		DATA_INDICATION
;		OPTIONAL_SEND_RNR_XXX(X=0)
;		UPDATE_N(R)_RECEIVED
;		IF_DATA_FLAG=2_STOP_REJ_TIMER
;		DATA_FLAG:=0
BUSY15		UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
BUSY16		SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
BUSY17		UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
BUSY18		SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
BUSY19		V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		UPDATE_P_FLAG
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
;		V(S):=N(R)
;		UPDATE_N(R)_RECEIVED
;		RE-SEND_I_CMD(P=1)
;		CLEAR_REMOTE_BUSY
BUSY20		V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
BUSY21		V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		SEND_RNR_RSP(F=1)
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
BUSY22		SEND_RNR_CMD(F=1)
		START_P_TIMER
BUSY23		P_FLAG:=0
;		SEND_RNR_CMD(F=1)
;		START_P_TIMER
;		RETRY_COUNT:=RETRY_COUNT+1
BUSY24		SEND_RNR_CMD(F=1)
		START_P_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
BUSY25		DATA_FLAG:=1
;		SEND_RNR_CMD(F=1)
;		START_P_TIMER
;		RETRY_COUNT:=RETRY_COUNT+1
;		DATA_FLAG:=1
BUSY26		DATA_FLAG:=1
;============================================================================
REJECT1		SEND_I_CMD(P=1)
		START_P_TIMER
		START_ACK_TIMER_IF_NOT_RUNNING
;		SEND_I_XXX(X=0)
;		START_ACK_TIMER_IF_NOT_RUNNING
REJECT2		SEND_I_XXX(X=0)
		START_ACK_TIMER_IF_NOT_RUNNING
REJECT3		SEND_RNR_CMD(F=1)
		START_P_TIMER
		DATA_FLAG:=2
;		SEND_RNR_XXX(X=0)
;		DATA_FLAG:=2
REJECT4		SEND_RNR_XXX(X=0)
		DATA_FLAG:=2
REJECT5		UPDATE_N(R)_RECEIVED
		UPDATE_P_FLAG
		IF_F=1_CLEAR_REMOTE_BUSY
REJECT6		SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
;
; order of opcodes in REJECT7 is changed 
REJECT7		V(R):=V(R)+1
		SEND_ACKNOWLEDGE_CMD(P=1)
		START_P_TIMER
		UPDATE_N(R)_RECEIVED
		IF_F=1_CLEAR_REMOTE_BUSY
		STOP_REJ_TIMER
		DATA_INDICATION
;		V(R):=V(R)+1
;		DATA_INDICATION
;		UPDATE_P_FLAG
;		SEND_ACKNOWLEDGE_XXX(X=0)
;		UPDATE_N(R)_RECEIVED
;		IF_F=1_CLEAR_REMOTE_BUSY
;		STOP_REJ_TIMER
;
; order of opcodes in REJECT8 is changed 
REJECT8		V(R):=V(R)+1
		SEND_ACKNOWLEDGE_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		STOP_REJ_TIMER
		DATA_INDICATION
;
; order of opcodes in REJECT9 is changed 
REJECT9		V(R):=V(R)+1
		SEND_ACKNOWLEDGE_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		STOP_REJ_TIMER
		DATA_INDICATION
REJECT10	UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
REJECT11	SEND_ACKNOWLEDGE_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
REJECT12	UPDATE_P_FLAG
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
REJECT13	SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
REJECT14	V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		UPDATE_P_FLAG
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
;		V(S):=N(R)
;		UPDATE_N(R)_RECEIVED
;		RE-SEND_I_CMD(P=1)
;		START_P_TIMER
;		CLEAR_REMOTE_BUSY
REJECT15	V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
REJECT16	V(S):=N(R)
		UPDATE_N(R)_RECEIVED
		RE-SEND_I_RSP(F=1)
		CLEAR_REMOTE_BUSY
REJECT17	SEND_RR_CMD(P=1)
		START_P_TIMER
REJECT18	SEND_REJ_CMD(P=1)
		START_P_TIMER
		START_REJ_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
REJECT19	P_FLAG:=0
;		SEND_RR_CMD(P=1)
;		START_P_TIMER
;		START_REJ_TIMER
;		RETRY_COUNT:=RETRY_COUNT+1
REJECT20	SEND_RR_CMD(P=1)
		START_P_TIMER
		START_REJ_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
;============================================================================
AWAIT1		SEND_RNR_XXX(X=0)
		DATA_FLAG:=0
AWAIT2		SEND_REJ_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		RE-SEND_I_XXX(X=0)
		START_REJ_TIMER
		CLEAR_REMOTE_BUSY
;		SEND_REJ_CMD(P=1)
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		RE-SEND_I_XXX(X=0)
;		START_P_TIMER
;		START_REJ_TIMER
;		CLEAR_REMOTE_BUSY
AWAIT3		SEND_REJ_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		START_REJ_TIMER
AWAIT4		SEND_REJ_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		START_REJ_TIMER
;
; order of opcode in AWAIT5 changed
AWAIT5		V(R):=V(R)+1
		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		RE-SEND_I_CMD(P=1)_OR_SEND_RR
		START_P_TIMER
		CLEAR_REMOTE_BUSY
		DATA_INDICATION
;		V(R):=V(R)+1
;		DATA_INDICATION
;		STOP_P_TIMER
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		RE-SEND_I_XXX(X=0)_OR_SEND_RR
;		CLEAR_REMOTE_BUSY
;
; order of opcode in AWAIT6 changed
AWAIT6		V(R):=V(R)+1
		SEND_RR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		DATA_INDICATION
;
; order of opcode in AWAIT7 changed
AWAIT7		V(R):=V(R)+1
		SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		DATA_INDICATION
AWAIT8		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		RE-SEND_I_CMD(P=1)
;		START_P_TIMER
;		CLEAR_REMOTE_BUSY
AWAIT9		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
AWAIT10		SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
AWAIT11		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		SET_REMOTE_BUSY
AWAIT12		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
AWAIT13		SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
AWAIT14		SEND_RR_CMD(P=1)
		START_P_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
;============================================================================
AWAIT_BUSY1	SEND_REJ_XXX(X=0)
		START_REJ_TIMER		
AWAIT_BUSY2	SEND_RR_XXX(X=0)
AWAIT_BUSY3	SEND_RR_XXX(X=0)
AWAIT_BUSY4	OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		DATA_FLAG:=1
		CLEAR_REMOTE_BUSY
		RE-SEND_I_XXX(X=0)
;		SEND_RNR_CMD(F=1)
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		START_P_TIMER
;		DATA_FLAG:=1
;		CLEAR_REMOTE_BUSY
;		RE-SEND_I_XXX(X=0)
AWAIT_BUSY5	OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		DATA_FLAG:=1
AWAIT_BUSY6	SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		DATA_FLAG:=1
AWAIT_BUSY7	OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		DATA_FLAG:=1
		STOP_P_TIMER
		CLEAR_REMOTE_BUSY
		RE-SEND_I_XXX(X=0)
;		SEND_RNR_CMD(F=1)
;		V(R):=V(R)+1
;		DATA_INDICATION
;		START_P_TIMER
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		DATA_FLAG:=0
;		CLEAR_REMOTE_BUSY
;		RE-SEND_I_XXX(X=0)
;		OPTIONAL_SEND_RNR_XXX(X=0)
;		V(R):=V(R)+1
;		DATA_INDICATION
;		STOP_P_TIMER
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		DATA_FLAG:=0
;		CLEAR_REMOTE_BUSY
;		RE-SEND_I_XXX(X=0)
AWAIT_BUSY8	OPTIONAL_SEND_RNR_XXX(X=0)
		UPDATE_N(R)_RECEIVED
		DATA_FLAG:=1
;		OPTIONAL_SEND_RNR_XXX(X=0)
;		V(R):=V(R)+1
;		DATA_INDICATION
;		UPDATE_N(R)_RECEIVED
;		DATA_FLAG:=0
AWAIT_BUSY9	SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		DATA_FLAG:=1
;		SEND_RNR_RSP(F=1)
;		V(R):=V(R)+1
;		DATA_INDICATION
;		UPDATE_N(R)_RECEIVED
;		DATA_FLAG:=0
AWAIT_BUSY10	UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		RE-SEND_I_CMD(P=1)
;		START_P_TIMER
;		CLEAR_REMOTE_BUSY
AWAIT_BUSY11	UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
AWAIT_BUSY12	SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
AWAIT_BUSY13	UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		SET_REMOTE_BUSY
AWAIT_BUSY14	UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
AWAIT_BUSY15	SEND_RNR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
AWAIT_BUSY16	SEND_RNR_CMD(F=1)
		START_P_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
;============================================================================
AWAIT_REJECT1	SEND_RNR_XXX(X=0)
		DATA_FLAG:=2
AWAIT_REJECT2	UPDATE_N(R)_RECEIVED
AWAIT_REJECT3	SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
;
; order of opcodes in AWAIT_REJECT4 changed
AWAIT_REJECT4	V(R):=V(R)+1
		UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		RE-SEND_I_CMD(P=1)_OR_SEND_RR
		START_P_TIMER
		STOP_REJ_TIMER
		CLEAR_REMOTE_BUSY
		DATA_INDICATION
;		V(R):=V(R)+1
;		DATA_INDICATION
;		STOP_P_TIMER
;		STOP_REJ_TIMER
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		RE-SEND_I_CMD(P=1)_OR_SEND_RR
;		CLEAR_REMOTE_BUSY
;
; order of opcodes in AWAIT_REJECT5 changed
AWAIT_REJECT5	V(R):=V(R)+1
		SEND_RR_XXX(X=0)
		STOP_REJ_TIMER
		UPDATE_N(R)_RECEIVED
		DATA_INDICATION
;
; order of opcodes in AWAIT_REJECT6 changed
AWAIT_REJECT6	V(R):=V(R)+1
		SEND_RR_RSP(F=1)
		STOP_REJ_TIMER
		UPDATE_N(R)_RECEIVED
		DATA_INDICATION
AWAIT_REJECT7	UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		RE-SEND_I_XXX(X=0)
		CLEAR_REMOTE_BUSY
;		UPDATE_N(R)_RECEIVED
;		V(S):=N(R)
;		RE-SEND_I_CMD(P=1)
;		START_P_TIMER
;		CLEAR_REMOTE_BUSY
AWAIT_REJECT8	UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
AWAIT_REJECT9	SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		CLEAR_REMOTE_BUSY
AWAIT_REJECT10	UPDATE_N(R)_RECEIVED
		V(S):=N(R)
		STOP_P_TIMER
		SET_REMOTE_BUSY
AWAIT_REJECT11	UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
AWAIT_REJECT12	SEND_RR_RSP(F=1)
		UPDATE_N(R)_RECEIVED
		SET_REMOTE_BUSY
AWAIT_REJECT13	SEND_REJ_CMD(P=1)
		START_P_TIMER
		RETRY_COUNT:=RETRY_COUNT+1
;============================================================================

