NAME	serfem(18)
	RSEG	CODE(0)
	RSEG	CSTR(0)
	RSEG	CONST(0)
	RSEG	X_UDATA(0)
	RSEG	X_IDATA(0)
	RSEG	X_CDATA(0)
	PUBLIC	EPROG
	PUBLIC	ERROR
	$DEFFN	ERROR(256,0,0,0,0,0,2,0),test_fun,cmd_rec,mem_dump,scan_net,main
	PUBLIC	FNP
	EXTERN	INP
	$DEFFN	INP(0,0,1,0),cmd_rec
	EXTERN	OUTP
	$DEFFN	OUTP(0,0,2,0),cmd_rec
	PUBLIC	SWRESET
	PUBLIC	UFUN
	EXTERN	arc51_init
	$DEFFN	arc51_init(0,0,0,0),test_fun,main
	EXTERN	arc51_nodeid
	EXTERN	arc51_port
	EXTERN	arc51_read
	$DEFFN	arc51_read(0,0,3,0),test_fun,mem_dump,scan_net
	EXTERN	arc51_write
	$DEFFN	arc51_write(0,0,3,0),testsend,readback
	PUBLIC	buf
	PUBLIC	cmd_rec
	$DEFFN	cmd_rec(256,0,7,0,0,0,0,0),scan_net
	PUBLIC	copy_code
	$DEFFN	copy_code(0,0,2,0,0,0,0,0),cmd_rec
	PUBLIC	fblock
	PUBLIC	gen_cs
	$DEFFN	gen_cs(0,0,0,0,0,0,2,0),test_fun
	PUBLIC	grpid
	PUBLIC	main
	$DEFFN	main(256,0,12,0,0,0,0,0)
	PUBLIC	mem_dump
	$DEFFN	mem_dump(0,0,8,0,0,0,0,0),scan_net
	PUBLIC	nid
	PUBLIC	node_wake
	$DEFFN	node_wake(0,0,0,0,0,0,0,0),test_fun,main
	PUBLIC	pckt
	PUBLIC	pktsize
	$DEFFN	pktsize(0,0,2,0,0,0,0,0),mem_dump
	EXTERN	printf
	$DEFFN	printf(0,0,5,0),test_fun
	PUBLIC	readback
	$DEFFN	readback(0,0,6,0,0,0,2,0),node_wake,ERROR,cmd_rec
	PUBLIC	scan_net
	$DEFFN	scan_net(256,0,2,0,0,0,0,0),main
	PUBLIC	setup_pckt
	$DEFFN	setup_pckt(0,0,0,0,0,0,0,0),scan_net
	PUBLIC	temp
	PUBLIC	test_fun
	$DEFFN	test_fun(0,0,15,0,0,0,0,0),main
	PUBLIC	testsend
	$DEFFN	testsend(0,0,8,0,0,0,2,0),test_fun
	PUBLIC	time_out
	$DEFFN	time_out(0,0,0,0,0,0,2,0),mem_dump
	PUBLIC	userbuf
	EXTERN	?SI_DIV_L00
	EXTERN	?IADD_ASG_R567_AR3_L00
	EXTERN	?ST_A_R123_L17
	EXTERN	?A_S_SWITCH_L05
	EXTERN	?AR5_SC_SWITCH_L05
	EXTERN	?LOAD_IND_DPTR2_L20
	EXTERN	?LCALL_IND_L20
	EXTERN	?CL8051L_5_12_L17
	RSEG	CODE
main:
; 1.	
; 2.	/* ------------------------------------------------------------------------*/
; 3.	/* Project:       FEM BOOT PROGRAM                                         */
; 4.	/* Filename:      FEM.C                                                    */
; 5.	/* Description:   BOOT PROGRAM FOR THE GENERIC ARCNET FEM BOARD            */
; 6.	/* Version:       1.01                                                     */
; 7.	/* Author:        Jack Fried;                                              */
; 8.	/* History:       ORIGINAL 7/17/97  for com200510                          */
; 9.	/*                         11/20/97  edited for built in self test         */
; 10.	/*                         2/13/98   edited for active network map         */
; 11.	/*                         3/25/98   edited for delfault load after 30 sec */
; 12.	/*                         3/26/98   user program readback feature added   */
; 13.	/*                         4/10/98   Node id reversed due to board error   */
; 14.	/*                         5/06/98   user selectable group ids             */ 
; 15.	/*                         5/08/98   clean up and comments                 */
; 16.	/* ------------------------------------------------------------------------*/
; 17.	/*                                                                         */
; 18.	/*                                                                         */
; 19.	/*   This program is the main boot program for the FEM. It initilizes      */
; 20.	/*   the arcnet core and decodes the packet header information.            */
; 21.	/*   It then runs the appriate function.                                   */
; 22.	/*                                                                         */
; 23.	/* ------------------------------------------------------------------------*/
; 24.	/*
; 25.	DATE: 7/17/97
; 26.	
; 27.	       The software on this disk Has NOT been fully tested.  In no way is
; 28.	   BNL responsible for the use of this software or any damage resulting in its
; 29.	   use.  If any bugs are found in this software  please send me E-mail 
; 30.	   stating the problem and solution if you have one.   
; 31.	                                                Jack Fried      
; 32.	                                                jfried@inst.inst.bnl.gov
; 33.	
; 34.	*/
; 35.	
; 36.	
; 37.	
; 38.	#include  <serfem.h>
; 39.	#define   PKT_size      500             /*packet size normal value  500 bytes */
; 40.	#define   debug        if (1) 
; 41.	
; 42.	
; 43.	
; 44.	/* --------------------------------------------------------------------------*/
; 45.	/* external variable definitions                                             */
; 46.	/* ------------------------------------------------------------------------- */
; 47.	extern USIGN16 arc51_port;
; 48.	extern USIGN16 arc51_swport;
; 49.	extern USIGN8  arc51_nodeid;
; 50.	extern USIGN16 arc51_port;
; 51.	
; 52.	
; 53.	
; 54.	/* ------------------------------------------------------------------------- */
; 55.	/* global variable definition                                                */
; 56.	/* ------------------------------------------------------------------------- */
; 57.	USIGN8 buf[512];
; 58.	USIGN8 userbuf[512];
; 59.	int nid = 0x15;
; 60.	int grpid =0;
; 61.	int temp;
; 62.	
; 63.	
; 64.	/*****************************************************************************
; 65.	 *
; 66.	 * FUNCTION NAME: main
; 67.	 *
; 68.	 * DESCRIPTION  : This function calls the arcnet core setup function.
; 69.	 *
; 70.	 * RETURN VALUE : NONE
; 71.	 ******************************************************************************/
; 72.	
; 73.	void main(void)
; 74.	{  
; 75.	   int status,nid1,nid2,m1,m2,i;
; 76.	   
; 77.	  GUF[0] = (int) readback;;
	MOV	A,#LOW $IFREF readback
	MOV	R5,#HIGH $IFREF readback
	MOV	DPTR,#2032
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 78.	  GUF[1] = (int) ERROR;
	MOV	A,#LOW $IFREF ERROR
	MOV	R5,#HIGH $IFREF ERROR
	MOV	DPTR,#2034
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 79.	  GUF[2] = 1;
	MOV	DPTR,#2036
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
; 80.	  GUF[3] = 30;
	MOV	DPTR,#2038
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#30
	MOVX	@DPTR,A
; 81.	  GUF[4] = 0;
	MOV	DPTR,#2040
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 82.	  GUF[5] = 0;
	MOV	DPTR,#2042
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 83.	
; 84.	  HOPDATA[0] = 0x88;
	MOV	A,#136
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 85.	                                /*  read in node ID */
; 86.	     nid1 = (* (char xdata *) 0xfeff);
	MOV	DPTR,#65279
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	DPTR,#$LOCBX main+2
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 87.	     m1= 0x80;
	MOV	DPTR,#$LOCBX main+6
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#128
	MOVX	@DPTR,A
; 88.	     m2= 0x01;
	MOV	DPTR,#$LOCBX main+8
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
; 89.	     nid2 = 0;
	MOV	DPTR,#$LOCBX main+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 90.	     for(i=0;i<=7;i++)  /* fix reverse node id */
	MOV	DPTR,#$LOCBX main+10
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0001:
	SETB	C
	MOV	DPTR,#$LOCBX main+11
	MOVX	A,@DPTR
	SUBB	A,#7
	MOV	DPTR,#$LOCBX main+10
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#128
	JNC	?0000
?0002:
; 91.	     {
; 92.	       if((nid1 & m1) != 0)
	MOV	DPTR,#$LOCBX main+2
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX main+7
	MOV	R6,A
	MOVX	A,@DPTR
	ANL	A,R6
	MOV	R4,A
	MOV	DPTR,#$LOCBX main+6
	MOVX	A,@DPTR
	ANL	A,R5
	ORL	A,R4
	JZ	?0005
?0004:
; 93.	          nid2 = nid2 |  m2;
	MOV	DPTR,#$LOCBX main+4
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	DPTR,#$LOCBX main+9
	MOVX	A,@DPTR
	ORL	A,R6
	MOV	R6,A
	MOV	DPTR,#$LOCBX main+8
	MOVX	A,@DPTR
	ORL	A,R7
	MOV	DPTR,#$LOCBX main+4
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R6
	MOVX	@DPTR,A
	XCH	A,R6
?0005:
; 94.	       m1 =  m1 >> 1;
	MOV	DPTR,#$LOCBX main+6
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R7
	MOV	C,ACC.7
	RRC	A
	MOV	R7,A
	MOV	A,R6
	RRC	A
	MOV	DPTR,#$LOCBX main+6
	XCH	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R7
	MOVX	@DPTR,A
; 95.	       m2 =  m2 << 1;
	MOV	DPTR,#$LOCBX main+8
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R6
	ADD	A,ACC
	XCH	A,R7
	RLC	A
	XCH	A,R7
	MOV	DPTR,#$LOCBX main+8
	XCH	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R7
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX main+11
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX main+10
	JNZ	?0231
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0231:
	SJMP	?0001
?0000:
; 96.	     }
; 97.	     nid = nid2;
	MOV	DPTR,#$LOCBX main+4
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
; 98.	
; 99.	     /* nid = 0x8;*/
; 100.	     grpid = nid & (0xf0);
	MOV	DPTR,#nid
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	ANL	A,#240
	MOV	R5,#0
	MOV	DPTR,#grpid
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 101.	     arc51_nodeid = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#arc51_nodeid
	MOVX	@DPTR,A
; 102.	     GUF[6] = nid;      
	MOV	DPTR,#nid
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#2044
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 103.	   if (nid == 0x02)
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	XRL	A,#2
	JNZ	?0232
	MOV	DPTR,#nid
	MOVX	A,@DPTR
?0232:
	JNZ	?0007
?0006:
; 104.	   {
; 105.	      nid = 0x01;
	MOV	DPTR,#nid
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
; 106.	      grpid = nid & (0xf0);
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	ANL	A,#240
	MOV	R5,#0
	MOV	DPTR,#grpid
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 107.	      arc51_nodeid = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#arc51_nodeid
	MOVX	@DPTR,A
; 108.	      test_fun();
	LCALL	$REFFN test_fun
?0009:
; 109.	      while(1);
	NOP
; 110.	   }
	SJMP	?0009
?0007:
; 111.	   if (nid == 0x04)
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	XRL	A,#4
	JNZ	?0233
	MOV	DPTR,#nid
	MOVX	A,@DPTR
?0233:
	JNZ	?0012
?0011:
; 112.	   {
; 113.	      nid = 0x04;
	MOV	DPTR,#nid
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#4
	MOVX	@DPTR,A
; 114.	      grpid = nid & (0xf0);
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	ANL	A,#240
	MOV	R5,#0
	MOV	DPTR,#grpid
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 115.	      arc51_nodeid = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#arc51_nodeid
	MOVX	@DPTR,A
; 116.	      if ((* (char code *) PGB) == 0x77)
	MOV	DPTR,#65279
	CLR	A
	MOVC	A,@A+DPTR
	CJNE	A,#119,?0014
?0013:
; 117.	        USR_FUNC;
	MOV	R5,#LOW(UFUN)
	MOV	R6,#HIGH(UFUN)
	MOV	R7,#2
	MOV	DPTR,#FNP
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#FNP+1
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#fblock
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#fblock
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPL,A
	MOV	DPH,R7
	LCALL	?LOAD_IND_DPTR2_L20
	LCALL	?LCALL_IND_L20
?0014:
?0012:
; 118.	   }
; 119.	   status = arc51_init();           /* init the arcnet core */
	LCALL	$REFFN arc51_init
	MOV	A,R4
	MOV	R5,#0
; 120.	   if(status == E_OK) 
	MOV	DPTR,#$LOCBX main
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	ORL	A,R5
	JNZ	?0016
?0015:
; 121.	        node_wake();
	LCALL	$REFFN node_wake
; 122.	   else
	SJMP	?0017
?0016:
; 123.	         ERROR(0);
	CLR	A
	MOV	R4,A
	MOV	R5,A
	LCALL	$REFFN ERROR
?0017:
; 124.	   scan_net();
	LCALL	$REFFN scan_net
; 125.	}
	RET
scan_net:
; 126.	
; 127.	
; 128.	/*****************************************************************************
; 129.	 *
; 130.	 * FUNCTION NAME: scan_net
; 131.	 *
; 132.	 * DESCRIPTION  : This function is in a loop waiting for a packet to arrive.
; 133.	 *                When a packet arrives it determines what to do with it and 
; 134.	 *                acts accordinly.
; 135.	 *
; 136.	 * RETURN VALUE : NONE
; 137.	 ******************************************************************************/
; 138.	
; 139.	void scan_net()
; 140.	{
; 141.	int i=0;
	MOV	DPTR,#$LOCBX scan_net
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0019:
; 142.	
; 143.	   while(1)
	NOP
; 144.	   {
; 145.	      if (arc51_read(&buf[0]) == E_OK)        /* if status = 0 a packet was recived */
	MOV	R5,#LOW(buf)
	MOV	R6,#HIGH(buf)
	MOV	R7,#1
	LCALL	$REFFN arc51_read
	CJNE	R4,#0,?0022
?0021:
; 146.	        if((buf[NODEID+4] == nid) || (buf[GRPCMD+4] == PUB) || (buf[GRPCMD+4] == grpid))
	MOV	DPTR,#buf+4
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	R4,A
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	XRL	A,R4
	JNZ	?0234
	MOV	DPTR,#nid
	MOVX	A,@DPTR
	XRL	A,R5
	JZ	?0023
?0234:
	MOV	DPTR,#buf+7
	MOVX	A,@DPTR
	DEC	A
	JZ	?0023
	MOV	DPTR,#buf+7
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	R4,A
	MOV	DPTR,#grpid+1
	MOVX	A,@DPTR
	XRL	A,R4
	JNZ	?0235
	MOV	DPTR,#grpid
	MOVX	A,@DPTR
	XRL	A,R5
?0235:
	JNZ	?0024
?0025:
?0026:
?0023:
; 147.	            if (buf[ERR+4] == 0)
	MOV	DPTR,#buf+8
	MOVX	A,@DPTR
	JNZ	?0028
?0027:
; 148.	            {
; 149.	              setup_pckt();                /* read in packet header info */
	LCALL	$REFFN setup_pckt
; 150.	              if(pckt.cmd == ECHO)
	MOV	DPTR,#pckt
	MOVX	A,@DPTR
	CJNE	A,#4,?0030
?0029:
; 151.	                 cmd_rec();
	LCALL	$REFFN cmd_rec
	SJMP	?0031
?0030:
; 152.	              else if (mem_dump() == E_OK)
	LCALL	$REFFN mem_dump
	MOV	A,R4
	ORL	A,R5
	JNZ	?0033
?0032:
; 153.	                   cmd_rec();
	LCALL	$REFFN cmd_rec
?0033:
?0031:
; 154.	            }
; 155.	            else
	SJMP	?0034
?0028:
; 156.	              ERROR(2);
	CLR	A
	MOV	R5,A
	MOV	R4,#2
	LCALL	$REFFN ERROR
?0034:
?0024:
?0022:
; 157.	
; 158.	      if (GUF[2] == 1)
	MOV	DPTR,#2037
	MOVX	A,@DPTR
	DEC	A
	JNZ	?0236
	MOV	DPTR,#2036
	MOVX	A,@DPTR
?0236:
	JZ	$+5
	LJMP	?0036
?0035:
; 159.	      {i++;
	MOV	DPTR,#$LOCBX scan_net+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX scan_net
	JNZ	?0237
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0237:
; 160.	        if (i==3100)
	MOV	DPTR,#$LOCBX scan_net+1
	MOVX	A,@DPTR
	XRL	A,#28
	JNZ	?0238
	MOV	DPTR,#$LOCBX scan_net
	MOVX	A,@DPTR
	XRL	A,#12
?0238:
	JZ	$+5
	LJMP	?0038
?0037:
; 161.	        {
; 162.	          GUF[3]--;
	MOV	R7,#1
	MOV	R6,#7
	MOV	R5,#246
	MOV	A,#255
	MOV	R3,A
	LCALL	?IADD_ASG_R567_AR3_L00
; 163.	          i=0;
	MOV	DPTR,#$LOCBX scan_net
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 164.	          if(GUF[3] == 0)
	MOV	DPTR,#2038
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	ORL	A,R5
	JZ	$+5
	LJMP	?0040
?0039:
; 165.	          {
; 166.	             GUF[2] = 0;
	MOV	DPTR,#2036
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 167.	             GUF[3] = 30;
	MOV	DPTR,#2038
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#30
	MOVX	@DPTR,A
; 168.	             if ((* (char code *) PGB) == 0x77)
	MOV	DPTR,#65279
	CLR	A
	MOVC	A,@A+DPTR
	CJNE	A,#119,?0042
?0041:
; 169.	             {
; 170.	                HOPDATA[CMD] = DEF_RTN;
	MOV	A,#10
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 171.	                HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 172.	                USR_FUNC;
	MOV	R5,#LOW(UFUN)
	MOV	R6,#HIGH(UFUN)
	MOV	R7,#2
	MOV	DPTR,#FNP
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#FNP+1
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#fblock
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#fblock
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPL,A
	MOV	DPH,R7
	LCALL	?LOAD_IND_DPTR2_L20
	LCALL	?LCALL_IND_L20
; 173.	                if (GUF[5] != 0)
	MOV	DPTR,#2042
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	ORL	A,R5
	JZ	?0044
?0043:
; 174.	                   grpid = GUF[5];
	MOV	DPTR,#2042
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#grpid
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
?0044:
; 175.	             }
; 176.	             else
	SJMP	?0045
?0042:
; 177.	             {
; 178.	               pckt.error = 77;
	MOV	A,#77
	MOV	DPTR,#pckt+6
	MOVX	@DPTR,A
; 179.	               ERROR(9);
	CLR	A
	MOV	R5,A
	MOV	R4,#9
	LCALL	$REFFN ERROR
?0045:
?0040:
?0038:
?0036:
; 180.	             }
; 181.	           }
; 182.	        }
; 183.	     }
; 184.	   }
; 185.	}
	LJMP	?0019
readback:
; 186.	
; 187.	
; 188.	/*****************************************************************************
; 189.	 *
; 190.	 * FUNCTION NAME: readback
; 191.	 *
; 192.	 * DESCRIPTION  : Used to send data to node 1 it can send up to 1 hopper full of 
; 193.	 *                data. The user program calls this function with an absolute 
; 194.	 *                memory address.
; 195.	 *
; 196.	 * RETURN VALUE : NONE
; 197.	 ******************************************************************************/
; 198.	
; 199.	
; 200.	void  readback(USIGN16 dlen)
; 201.	{
; 202.	     int count,i,ii;
; 203.	     count = 0; 
	MOV	DPTR,#$LOCBX readback
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 204.	                         /* calculate the number of bytes to send */
; 205.	     dlen =dlen+8;
	MOV	A,R4
	ADD	A,#8
	MOV	R4,A
	CLR	A
	ADDC	A,R5
; 206.	     HOPDATA[DLEN] =   (USIGN8) ((0xFF00 & dlen) >> 8);
	MOV	DPTR,#$LOCBX readback+6
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R4
	MOVX	@DPTR,A
	XCH	A,R4
	MOV	R5,A
	CLR	A
	MOV	A,R5
	MOV	R5,#0
	MOV	DPTR,#24574
	MOVX	@DPTR,A
; 207.	     HOPDATA[DLEN+1] = (USIGN8) (0x00FF & dlen);
	MOV	DPTR,#$LOCBX readback+7
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	DPTR,#24575
	MOVX	@DPTR,A
?0047:
; 208.	        
; 209.	     while (dlen > count)
	MOV	DPTR,#$LOCBX readback+6
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX readback+1
	MOVX	A,@DPTR
	CLR	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX readback
	MOVX	A,@DPTR
	SUBB	A,R5
	JC	$+5
	LJMP	?0046
?0048:
; 210.	     {
; 211.	        i= 0;
	MOV	DPTR,#$LOCBX readback+2
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0050:
; 212.	                        /* break up the hopper memory into packets */
; 213.	        while ((i < PKT_size) && (dlen > count))  
	CLR	C
	MOV	DPTR,#$LOCBX readback+3
	MOVX	A,@DPTR
	SUBB	A,#244
	MOV	DPTR,#$LOCBX readback+2
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#129
	JNC	?0049
	MOV	DPTR,#$LOCBX readback+6
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX readback+1
	MOVX	A,@DPTR
	CLR	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX readback
	MOVX	A,@DPTR
	SUBB	A,R5
	JNC	?0049
?0053:
?0052:
?0051:
; 214.	        {
; 215.	         userbuf[i] = HOPDATA[count];
	MOV	DPTR,#$LOCBX readback+1
	MOVX	A,@DPTR
	ADD	A,#248
	MOV	R4,A
	MOV	DPTR,#$LOCBX readback
	MOVX	A,@DPTR
	ADDC	A,#95
	MOV	DPL,R4
	MOV	DPH,A
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	DPTR,#$LOCBX readback+3
	MOVX	A,@DPTR
	ADD	A,#LOW(userbuf)
	MOV	R4,A
	MOV	DPTR,#$LOCBX readback+2
	MOVX	A,@DPTR
	ADDC	A,#HIGH(userbuf)
	MOV	R5,A
	MOV	A,R6
	MOV	DPL,R4
	MOV	DPH,R5
	MOVX	@DPTR,A
; 216.	         count++;
	MOV	DPTR,#$LOCBX readback+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX readback
	JNZ	?0239
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0239:
; 217.	         i++;
	MOV	DPTR,#$LOCBX readback+3
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX readback+2
	JNZ	?0240
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0240:
	SJMP	?0050
?0049:
; 218.	        }
; 219.	        buf[0] = 0x01;
	MOV	A,#1
	MOV	DPTR,#buf
	MOVX	@DPTR,A
; 220.	        buf[1] = 0x01;
	MOV	A,#1
	MOV	DPTR,#buf+1
	MOVX	@DPTR,A
; 221.	        buf[2] = 0;
	MOV	A,#0
	MOV	DPTR,#buf+2
	MOVX	@DPTR,A
; 222.	        buf[3] = i;
	MOV	DPTR,#$LOCBX readback+3
	MOVX	A,@DPTR
	MOV	DPTR,#buf+3
	MOVX	@DPTR,A
; 223.	        if ( i >=256) buf[2] =1;        /* for long packet */
	MOV	DPTR,#$LOCBX readback+2
	MOVX	A,@DPTR
	XRL	A,#128
	CLR	C
	SUBB	A,#129
	JC	?0055
?0054:
	MOV	A,#1
	MOV	DPTR,#buf+2
	MOVX	@DPTR,A
?0055:
; 224.	        for(ii=0;ii<i;ii++) buf[4+ii] = userbuf[ii];    
	MOV	DPTR,#$LOCBX readback+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0057:
	MOV	DPTR,#$LOCBX readback+4
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX readback+3
	MOVX	A,@DPTR
	SETB	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX readback+2
	MOVX	A,@DPTR
	XRL	A,#128
	XCH	A,R5
	XRL	A,#128
	XCH	A,R5
	SUBB	A,R5
	JC	?0056
?0058:
	MOV	DPTR,#$LOCBX readback+4
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R7
	MOV	R5,A
	MOV	A,R6
	ADD	A,#LOW(userbuf)
	MOV	DPL,A
	MOV	A,R5
	ADDC	A,#HIGH(userbuf)
	MOV	DPH,A
	MOVX	A,@DPTR
	XCH	A,R6
	MOV	R4,A
	XCH	A,R6
	XCH	A,R7
	MOV	R5,A
	XCH	A,R7
	MOV	R2,A
	MOV	A,R4
	ADD	A,#LOW(buf+4)
	MOV	DPL,A
	MOV	A,R5
	ADDC	A,#HIGH(buf+4)
	MOV	DPH,A
	MOV	A,R2
	MOVX	@DPTR,A
	INC	R6
	MOV	A,R6
	JNZ	?0241
	INC	R7
?0241:
	MOV	DPTR,#$LOCBX readback+4
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	SJMP	?0057
?0056:
; 225.	        i = arc51_write(&buf[0]);
	MOV	R5,#LOW(buf)
	MOV	R6,#HIGH(buf)
	MOV	R7,#1
	LCALL	$REFFN arc51_write
	MOV	A,R4
	MOV	R5,#0
	MOV	DPTR,#$LOCBX readback+2
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 226.	     }
; 227.	}
	LJMP	?0047
?0046:
	RET
pktsize:
; 228.	
; 229.	
; 230.	/*****************************************************************************
; 231.	 *
; 232.	 * FUNCTION NAME: pktsize
; 233.	 *
; 234.	 * DESCRIPTION  : returns packet size stored in buf
; 235.	 *
; 236.	 * RETURN VALUE : packet size
; 237.	 ******************************************************************************/
; 238.	
; 239.	
; 240.	int   pktsize()
; 241.	{  int count=0;
	MOV	DPTR,#$LOCBX pktsize
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 242.	                        
; 243.	        count = buf[3];
	MOV	DPTR,#buf+3
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	DPTR,#$LOCBX pktsize
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 244.	        if(buf[2] > 0) count += 256;
	MOV	DPTR,#buf+2
	MOVX	A,@DPTR
	JZ	?0061
?0060:
	MOV	DPTR,#$LOCBX pktsize
	MOVX	A,@DPTR
	ADD	A,#1
	MOVX	@DPTR,A
?0061:
; 245.	        return(count);
	MOV	DPTR,#$LOCBX pktsize
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
; 246.	}
	RET
mem_dump:
; 247.	
; 248.	
; 249.	
; 250.	/*****************************************************************************
; 251.	 *
; 252.	 * FUNCTION NAME: mem_dump
; 253.	 *
; 254.	 * DESCRIPTION  : This function recives the remaining packets over  arcnet and 
; 255.	 *                stores it in xdata memory (hopper memory). (39K MAX)
; 256.	 *
; 257.	 * RETURN VALUE : status
; 258.	 ******************************************************************************/
; 259.	
; 260.	
; 261.	int mem_dump()
; 262.	{  int status;
; 263.	   unsigned int i,j,count;
; 264.	 
; 265.	   temp=0;
	MOV	DPTR,#temp
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 266.	   count = pktsize();
	LCALL	$REFFN pktsize
	MOV	DPTR,#$LOCBX mem_dump+6
	MOV	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R4
	MOVX	@DPTR,A
; 267.	   i=0;
	MOV	DPTR,#$LOCBX mem_dump+2
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0063:
; 268.	   while(temp< count)            /* copy first packet to xdata */
	MOV	DPTR,#temp
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX mem_dump+7
	MOVX	A,@DPTR
	SETB	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX mem_dump+6
	MOVX	A,@DPTR
	SUBB	A,R5
	JC	?0062
?0064:
; 269.	   {      
; 270.	      HOPDATA[temp] = buf[temp+4];
	MOV	DPTR,#temp
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R7
	MOV	R5,A
	MOV	A,R6
	ADD	A,#LOW(buf+4)
	MOV	DPL,A
	MOV	A,R5
	ADDC	A,#HIGH(buf+4)
	MOV	DPH,A
	MOVX	A,@DPTR
	XCH	A,R6
	MOV	R4,A
	XCH	A,R6
	XCH	A,R7
	MOV	R5,A
	XCH	A,R7
	MOV	R2,A
	MOV	A,R4
	ADD	A,#248
	MOV	DPL,A
	MOV	A,R5
	ADDC	A,#95
	MOV	DPH,A
	MOV	A,R2
	MOVX	@DPTR,A
; 271.	      i++;
	MOV	DPTR,#$LOCBX mem_dump+3
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX mem_dump+2
	JNZ	?0242
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0242:
; 272.	      temp++;
	INC	R6
	MOV	A,R6
	JNZ	?0243
	INC	R7
?0243:
	MOV	DPTR,#temp
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	SJMP	?0063
?0062:
; 273.	   }
; 274.	
; 275.	   time_out(1);                   /* setup timers */
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
	LCALL	$REFFN time_out
?0066:
; 276.	   while(temp < pckt.dlen)           /* repeat  till all data recived (i == dlen)*/
	MOV	DPTR,#temp
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#pckt+5
	MOVX	A,@DPTR
	SETB	C
	SUBB	A,R4
	MOV	DPTR,#pckt+4
	MOVX	A,@DPTR
	SUBB	A,R5
	JNC	$+5
	LJMP	?0065
?0067:
; 277.	   {
; 278.	      if (time_out(0))           /* check for time out */
	CLR	A
	MOV	R4,A
	MOV	R5,A
	LCALL	$REFFN time_out
	MOV	A,R4
	ORL	A,R5
	JZ	?0069
?0068:
; 279.	      {
; 280.	            ERROR(3);
	CLR	A
	MOV	R5,A
	MOV	R4,#3
	LCALL	$REFFN ERROR
; 281.	            return(1);
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
; 282.	      }
	RET
?0069:
; 283.	      status = arc51_read(&buf[0]);      /* check if next packet recived */
	MOV	R5,#LOW(buf)
	MOV	R6,#HIGH(buf)
	MOV	R7,#1
	LCALL	$REFFN arc51_read
	MOV	A,R4
	MOV	R5,#0
; 284.	      if (status == E_OK)                          /* if data was recived */
	MOV	DPTR,#$LOCBX mem_dump
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	ORL	A,R5
	JZ	$+5
	LJMP	?0071
?0070:
; 285.	      {
; 286.	        time_out(1);            /* reset counters  */
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
	LCALL	$REFFN time_out
; 287.	        count = pktsize()-8;
	LCALL	$REFFN pktsize
	MOV	A,R4
	ADD	A,#248
	MOV	R4,A
	MOV	A,R5
	ADDC	A,#255
	MOV	DPTR,#$LOCBX mem_dump+6
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R4
	MOVX	@DPTR,A
	XCH	A,R4
; 288.	        j=0;
	MOV	DPTR,#$LOCBX mem_dump+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0073:
; 289.	        while(j<count)                       /* copy packet to xdata memory */
	MOV	DPTR,#$LOCBX mem_dump+4
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX mem_dump+7
	MOVX	A,@DPTR
	SETB	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX mem_dump+6
	MOVX	A,@DPTR
	SUBB	A,R5
	JC	?0072
?0074:
; 290.	        {
; 291.	            HOPDATA[temp] = buf[j+12];
	MOV	DPTR,#$LOCBX mem_dump+5
	MOVX	A,@DPTR
	ADD	A,#LOW(buf+12)
	MOV	R4,A
	MOV	DPTR,#$LOCBX mem_dump+4
	MOVX	A,@DPTR
	ADDC	A,#HIGH(buf+12)
	MOV	DPL,R4
	MOV	DPH,A
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	DPTR,#temp+1
	MOVX	A,@DPTR
	ADD	A,#248
	MOV	R4,A
	MOV	DPTR,#temp
	MOVX	A,@DPTR
	ADDC	A,#95
	MOV	R5,A
	MOV	A,R6
	MOV	DPL,R4
	MOV	DPH,R5
	MOVX	@DPTR,A
; 292.	            i++;
	MOV	DPTR,#$LOCBX mem_dump+3
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX mem_dump+2
	JNZ	?0244
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0244:
; 293.	            j++;
	MOV	DPTR,#$LOCBX mem_dump+5
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX mem_dump+4
	JNZ	?0245
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0245:
; 294.	            temp++;
	MOV	DPTR,#temp+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#temp
	JNZ	?0246
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0246:
; 295.	        }
; 296.	      }
	SJMP	?0073
?0072:
?0071:
	LJMP	?0066
?0065:
; 297.	   }
; 298.	    if(i != pckt.dlen)
	MOV	DPTR,#$LOCBX mem_dump+2
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#pckt+5
	MOVX	A,@DPTR
	XRL	A,R4
	JNZ	?0247
	MOV	DPTR,#pckt+4
	MOVX	A,@DPTR
	XRL	A,R5
	JZ	?0076
?0247:
?0075:
; 299.	   {
; 300.	       ERROR(6);
	CLR	A
	MOV	R5,A
	MOV	R4,#6
	LCALL	$REFFN ERROR
; 301.	       return(1);
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
; 302.	   }
	RET
?0076:
; 303.	   return(E_OK);
	CLR	A
	MOV	R4,A
	MOV	R5,A
; 304.	}
?0077:
	RET
setup_pckt:
; 305.	
; 306.	/*****************************************************************************
; 307.	 *
; 308.	 * FUNCTION NAME: setup_pckt
; 309.	 *
; 310.	 * DESCRIPTION  : Copy the paccket header information  into the pckt structure.
; 311.	 *                
; 312.	 * RETURN VALUE : NONE
; 313.	 ******************************************************************************/
; 314.	
; 315.	
; 316.	void setup_pckt()
; 317.	{
; 318.	  pckt.cmd = buf[CMD+4];
	MOV	DPTR,#buf+5
	MOVX	A,@DPTR
	MOV	DPTR,#pckt
	MOVX	@DPTR,A
; 319.	  pckt.node = buf[NODEID+4];
	MOV	DPTR,#buf+4
	MOVX	A,@DPTR
	MOV	DPTR,#pckt+1
	MOVX	@DPTR,A
; 320.	  pckt.devtype=buf[DEVTYPE+4];
	MOV	DPTR,#buf+6
	MOVX	A,@DPTR
	MOV	DPTR,#pckt+2
	MOVX	@DPTR,A
; 321.	  pckt.grpcmd=buf[GRPCMD+4];
	MOV	DPTR,#buf+7
	MOVX	A,@DPTR
	MOV	DPTR,#pckt+3
	MOVX	@DPTR,A
; 322.	  pckt.dlen= ((buf[DLEN+4] << 8) + buf[DLEN+5]);
	MOV	DPTR,#buf+10
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	R4,#0
	MOV	R5,A
	MOV	DPTR,#buf+11
	MOVX	A,@DPTR
	MOV	R7,#0
	MOV	R6,A
	MOV	A,R4
	ADD	A,R6
	MOV	R4,A
	MOV	A,R5
	ADDC	A,R7
	MOV	DPTR,#pckt+4
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R4
	MOVX	@DPTR,A
	XCH	A,R4
; 323.	  pckt.error=  buf[ERR+4];
	MOV	DPTR,#buf+8
	MOVX	A,@DPTR
	MOV	DPTR,#pckt+6
	MOVX	@DPTR,A
; 324.	  return;
; 325.	}
	RET
copy_code:
; 326.	
; 327.	
; 328.	
; 329.	
; 330.	/*****************************************************************************
; 331.	 *
; 332.	 * FUNCTION NAME: copy_code
; 333.	 *
; 334.	 * DESCRIPTION  : This fuction copies the CODE to reprogram the flash memory to 
; 335.	 *                RAM  (CODE -> XDATA) so that swaping memory space is possable.
; 336.	 *                
; 337.	 * RETURN VALUE : NONE
; 338.	 ******************************************************************************/
; 339.	
; 340.	
; 341.	void copy_code(void)
; 342.	{ int i;
; 343.	    for (i=0;i<=500;i++)
	MOV	DPTR,#$LOCBX copy_code
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0079:
	SETB	C
	MOV	DPTR,#$LOCBX copy_code+1
	MOVX	A,@DPTR
	SUBB	A,#244
	MOV	DPTR,#$LOCBX copy_code
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#129
	JNC	?0078
?0080:
; 344.	     (* (char xdata *) (FPROG+i))  = (* (char code *) (FPROG+i));   /* copy code */
	MOV	DPTR,#$LOCBX copy_code
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R7
	MOV	R5,A
	MOV	A,R6
	MOV	R4,A
	MOV	A,R5
	ADD	A,#56
	MOV	DPL,R4
	MOV	DPH,A
	CLR	A
	MOVC	A,@A+DPTR
	XCH	A,R6
	MOV	R4,A
	XCH	A,R6
	XCH	A,R7
	MOV	R5,A
	XCH	A,R7
	MOV	R2,A
	MOV	A,R5
	ADD	A,#56
	MOV	R5,A
	MOV	A,R2
	MOV	DPL,R4
	MOV	DPH,R5
	MOVX	@DPTR,A
	INC	R6
	MOV	A,R6
	JNZ	?0248
	INC	R7
?0248:
	MOV	DPTR,#$LOCBX copy_code
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
; 345.	}
	SJMP	?0079
?0078:
	RET
cmd_rec:
; 346.	
; 347.	
; 348.	/*****************************************************************************
; 349.	 *
; 350.	 * FUNCTION NAME: cmd_rec
; 351.	 *
; 352.	 * DESCRIPTION  : This function directs the program were to go after the hopper 
; 353.	 *                memory is transfer into XDATA. IT will either call NEW_CODE and 
; 354.	 *                reprogram the flash memory or call UFUN the user function located 
; 355.	 *                at an absolute address  or ic can call on of the boot code 
; 356.	 *                functions
; 357.	 *                
; 358.	 * RETURN VALUE : status
; 359.	 ******************************************************************************/
; 360.	
; 361.	
; 362.	
; 363.	int  cmd_rec()
; 364.	{
; 365.	
; 366.	   USIGN16 arc51_setup_reg;             /* variable decloration */
; 367.	   USIGN16 arc51_config_reg,i=0;
	MOV	DPTR,#$LOCBX cmd_rec+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 368.	   USIGN8  arc51_config;
; 369.	   arc51_config_reg =  6;
	MOV	DPTR,#$LOCBX cmd_rec+2
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#6
	MOVX	@DPTR,A
; 370.	   arc51_setup_reg = 7;
	MOV	DPTR,#$LOCBX cmd_rec
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#7
	MOVX	@DPTR,A
; 371.	
; 372.	
; 373.	   GUF[0] = (int) readback;             /* copy absolute memory locations in to registers*/
	MOV	A,#LOW $IFREF readback
	MOV	R5,#HIGH $IFREF readback
	MOV	DPTR,#2032
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 374.	   GUF[1] = (int) ERROR;
	MOV	A,#LOW $IFREF ERROR
	MOV	R5,#HIGH $IFREF ERROR
	MOV	DPTR,#2034
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 375.	
; 376.	   switch (pckt.cmd)
	MOV	DPTR,#pckt
	MOVX	A,@DPTR
	LCALL	?A_S_SWITCH_L05
	DB	1
	DB	8
	DW	?0101
	DW	?0083
	DW	?0089
	DW	?0090
	DW	?0091
	DW	?0092
	DW	?0093
	DW	?0094
	DW	?0095
	DW	?0096
?0083:
; 377.	   {
; 378.	       case  NEW_CODE:                  /* reprogram the flash */
; 379.	             copy_code(); 
	LCALL	$REFFN copy_code
; 380.	             PRG_ROM;                   /* call function */
	MOV	R5,#LOW(EPROG)
	MOV	R6,#HIGH(EPROG)
	MOV	R7,#2
	MOV	DPTR,#FNP
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#FNP+1
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#fblock
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#fblock
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPL,A
	MOV	DPH,R7
	LCALL	?LOAD_IND_DPTR2_L20
	LCALL	?LCALL_IND_L20
; 381.	             if ((* (char code *) PGB) == 0x77)    /* check for errors */
	MOV	DPTR,#65279
	CLR	A
	MOVC	A,@A+DPTR
	CJNE	A,#119,?0085
?0084:
; 382.	             {
; 383.	                 if(((char *) 0x000000) != 0)
; 384.	                     ERROR(4);
; 385.	             }
; 386.	             else
	SJMP	?0088
?0085:
; 387.	                ERROR(4);
	CLR	A
	MOV	R5,A
	MOV	R4,#4
	LCALL	$REFFN ERROR
?0088:
; 388.	             HOPDATA[CMD] = 01;
	MOV	A,#1
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 389.	             HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 390.	             HOPDATA[ERR] =  0;
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 391.	             HOPDATA[8]  = 0x77;
	MOV	A,#119
	MOV	DPTR,#24576
	MOVX	@DPTR,A
; 392.	             readback(1);               /* reply to node 1  status */
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
	LCALL	$REFFN readback
; 393.	             break;
	LJMP	?0082
?0089:
; 394.	       case  RESET_SW:                  /* software reset */
; 395.	             SW_RESET;
	MOV	R5,#LOW(SWRESET)
	MOV	R6,#HIGH(SWRESET)
	MOV	R7,#2
	MOV	DPTR,#FNP
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#FNP+1
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#fblock
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#fblock
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPL,A
	MOV	DPH,R7
	LCALL	?LOAD_IND_DPTR2_L20
	LCALL	?LCALL_IND_L20
; 396.	             break;
	LJMP	?0082
?0090:
; 397.	       case  RESPOND:                   /* have node respond to check it is alive */
; 398.	             HOPDATA[CMD] = RESPOND;
	MOV	A,#3
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 399.	             HOPDATA[NODEID] = nid;     /* set up values to send back */
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 400.	             HOPDATA[ERR] =  0;
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 401.	             readback(0);               
	CLR	A
	MOV	R4,A
	MOV	R5,A
	LCALL	$REFFN readback
; 402.	             break;
	LJMP	?0082
?0091:
; 403.	       case  ECHO:                      /* echos back the hopper memory */
; 404.	             HOPDATA[CMD] = ECHO;
	MOV	A,#4
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 405.	             HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 406.	             HOPDATA[ERR] = 0;
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 407.	             readback(pckt.dlen);
	MOV	DPTR,#pckt+4
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	LCALL	$REFFN readback
; 408.	             break;
	LJMP	?0082
?0092:
; 409.	       case  TOKEN_OFF:                 /* turns off the token */
; 410.	                                        /* turns off transmiter and turns on recive all */
; 411.	             arc51_config = (USIGN8)INP(arc51_config_reg);
	MOV	DPTR,#$LOCBX cmd_rec+3
	MOVX	A,@DPTR
	MOV	R4,A
	LCALL	$REFFN INP
; 412.	             arc51_config = (USIGN8)(((arc51_config & SUB_AD) | SETUP_REG) & ~TXEN);
	MOV	A,R4
	MOV	DPTR,#$LOCBX cmd_rec+6
	MOVX	@DPTR,A
	MOV	A,R4
	ANL	A,#252
	ORL	A,#2
	ANL	A,#223
	MOV	R4,A
; 413.	             OUTP(arc51_config_reg, arc51_config);
	MOV	A,R4
	MOV	DPTR,#$LOCBX cmd_rec+6
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX cmd_rec+3
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX cmd_rec+6
	MOVX	A,@DPTR
	MOV	R5,A
	LCALL	$REFFN OUTP
; 414.	             OUTP(arc51_setup_reg, (0X80 | 0x10));
	MOV	DPTR,#$LOCBX cmd_rec+1
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	R5,#144
	LCALL	$REFFN OUTP
; 415.	             break;
	LJMP	?0082
?0093:
; 416.	
; 417.	       case  TOKEN_ON:                  /* wake up node. turn token on */
; 418.	                                        /* restart transmiter and turn off recive all */
; 419.	
; 420.	             arc51_config = (USIGN8)INP(arc51_config_reg);
	MOV	DPTR,#$LOCBX cmd_rec+3
	MOVX	A,@DPTR
	MOV	R4,A
	LCALL	$REFFN INP
; 421.	             arc51_config = (USIGN8)(arc51_config | TXEN);
	MOV	A,R4
	ORL	A,#32
; 422.	             OUTP(arc51_config_reg, arc51_config);
	MOV	DPTR,#$LOCBX cmd_rec+6
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX cmd_rec+3
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX cmd_rec+6
	MOVX	A,@DPTR
	MOV	R5,A
	LCALL	$REFFN OUTP
; 423.	             OUTP(arc51_setup_reg, 0X80);
	MOV	DPTR,#$LOCBX cmd_rec+1
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	R5,#128
	LCALL	$REFFN OUTP
; 424.	             break;     
	LJMP	?0082
?0094:
; 425.	       case  NET_MAP:                   /* acive memory map */
; 426.	             HOPDATA[CMD] = NET_MAP;    /*node responds with its node id */
	MOV	A,#7
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 427.	             HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 428.	             HOPDATA[ERR] =  0;
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 429.	             readback(0);     
	CLR	A
	MOV	R4,A
	MOV	R5,A
	LCALL	$REFFN readback
; 430.	             break;
	LJMP	?0082
?0095:
; 431.	       case  FEM_VER:                   /* boot code version number */
; 432.	             HOPDATA[CMD] = 0x08;
	MOV	A,#8
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 433.	             HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 434.	             HOPDATA[ERR] =  0;
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 435.	             HOPDATA[8] = 0x9;
	MOV	A,#9
	MOV	DPTR,#24576
	MOVX	@DPTR,A
; 436.	             HOPDATA[9] = ' ';
	MOV	A,#32
	MOV	DPTR,#24577
	MOVX	@DPTR,A
; 437.	             HOPDATA[10] = 's';
	MOV	A,#115
	MOV	DPTR,#24578
	MOVX	@DPTR,A
; 438.	             HOPDATA[11] = 'e';
	MOV	A,#101
	MOV	DPTR,#24579
	MOVX	@DPTR,A
; 439.	             HOPDATA[12] = 'r';
	MOV	A,#114
	MOV	DPTR,#24580
	MOVX	@DPTR,A
; 440.	
; 441.	             readback(5);     
	CLR	A
	MOV	R5,A
	MOV	R4,#5
	LCALL	$REFFN readback
; 442.	             break;
	LJMP	?0082
?0096:
; 443.	       case  GET_PRG:                   /*read back user program form flash */
; 444.	             HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 445.	             HOPDATA[ERR] =  0;
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 446.	             for(i=0;i<=(0x9c00);i++)   
	MOV	DPTR,#$LOCBX cmd_rec+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0098:
	SETB	C
	MOV	DPTR,#$LOCBX cmd_rec+5
	MOVX	A,@DPTR
	SUBB	A,#0
	MOV	DPTR,#$LOCBX cmd_rec+4
	MOVX	A,@DPTR
	SUBB	A,#156
	JNC	?0097
?0099:
; 447.	               HOPDATA[8+i] = (* (char code *) (0x4000+i));
	MOV	DPTR,#$LOCBX cmd_rec+4
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R7
	MOV	R5,A
	MOV	A,R6
	MOV	R4,A
	MOV	A,R5
	ADD	A,#64
	MOV	DPL,R4
	MOV	DPH,A
	CLR	A
	MOVC	A,@A+DPTR
	MOV	R1,#248
	MOV	R2,#95
	MOV	R3,#1
	MOV	R4,A
	MOV	A,R1
	ADD	A,R6
	MOV	R1,A
	MOV	A,R2
	ADDC	A,R7
	MOV	R2,A
	MOV	A,R1
	ADD	A,#8
	MOV	R1,A
	MOV	A,R2
	ADDC	A,#0
	MOV	R2,A
	MOV	A,R4
	LCALL	?ST_A_R123_L17
	INC	R6
	MOV	A,R6
	JNZ	?0249
	INC	R7
?0249:
	MOV	DPTR,#$LOCBX cmd_rec+4
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	SJMP	?0098
?0097:
; 448.	             readback(0x9c00);     
	CLR	A
	MOV	R4,A
	MOV	R5,#156
	LCALL	$REFFN readback
; 449.	             break;
	SJMP	?0082
?0101:
; 450.	       default :                        /* call user function */
; 451.	
; 452.	             if ((* (char code *) PGB) == 0x77) /* check to see if there is a user program */
	MOV	DPTR,#65279
	CLR	A
	MOVC	A,@A+DPTR
	CJNE	A,#119,?0103
?0102:
; 453.	             {
; 454.	                USR_FUNC;
	MOV	R5,#LOW(UFUN)
	MOV	R6,#HIGH(UFUN)
	MOV	R7,#2
	MOV	DPTR,#FNP
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#FNP+1
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#fblock
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#fblock
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPL,A
	MOV	DPH,R7
	LCALL	?LOAD_IND_DPTR2_L20
	LCALL	?LCALL_IND_L20
; 455.	                if (GUF[5] != 0)        /* set up group id if necesary */
	MOV	DPTR,#2042
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	ORL	A,R5
	JZ	?0105
?0104:
; 456.	                   grpid = GUF[5];
	MOV	DPTR,#2042
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPTR,#grpid
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
?0105:
; 457.	             }
; 458.	             else
	SJMP	?0106
?0103:
; 459.	             {
; 460.	               pckt.error = 77;
	MOV	A,#77
	MOV	DPTR,#pckt+6
	MOVX	@DPTR,A
; 461.	               ERROR(5);
	CLR	A
	MOV	R5,A
	MOV	R4,#5
	LCALL	$REFFN ERROR
; 462.	               return(1);
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
; 463.	              }
	RET
?0106:
?0082:
; 464.	   }
; 465.	    return(0);
	CLR	A
	MOV	R4,A
	MOV	R5,A
; 466.	}
?0107:
	RET
ERROR:
; 467.	
; 468.	
; 469.	
; 470.	/*****************************************************************************
; 471.	 *
; 472.	 * FUNCTION NAME: ERROR
; 473.	 *
; 474.	 * DESCRIPTION  : This function controls the responce of an error.
; 475.	 *                if an error type is 0 this is a critical error such as network 
; 476.	 *                not working. this would cause the FEM to reset
; 477.	 *                if an error type is 1-255 this is a software error and  information 
; 478.	 *                is sent back over the network. the number is the error code.
; 479.	 *                
; 480.	 * RETURN VALUE : NONE
; 481.	 ******************************************************************************/
; 482.	
; 483.	
; 484.	void ERROR(int type)
; 485.	{ 
; 486.	     if(type ==0)
	MOV	DPTR,#$LOCBX ERROR
	MOV	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R4
	MOVX	@DPTR,A
	MOV	A,R4
	ORL	A,R5
	JNZ	?0109
?0108:
; 487.	     {
; 488.	             FNP = &SWRESET;    /* generate a reset */
	MOV	R5,#LOW(SWRESET)
	MOV	R6,#HIGH(SWRESET)
	MOV	R7,#2
	MOV	DPTR,#FNP
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R5
	MOVX	@DPTR,A
; 489.	             fblock = FNP;
	MOV	DPTR,#FNP+1
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
; 490.	             (*fblock) ();
	MOV	DPTR,#fblock
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#fblock
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	DPL,A
	MOV	DPH,R7
	LCALL	?LOAD_IND_DPTR2_L20
	LCALL	?LCALL_IND_L20
; 491.	     }
; 492.	     else
	SJMP	?0110
?0109:
; 493.	     {
; 494.	        HOPDATA[CMD] = 250;
	MOV	A,#250
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 495.	        HOPDATA[NODEID] = nid;
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 496.	        HOPDATA[ERR] = type;
	MOV	DPTR,#$LOCBX ERROR+1
	MOVX	A,@DPTR
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 497.	        readback(0);  
	CLR	A
	MOV	R4,A
	MOV	R5,A
	LCALL	$REFFN readback
; 498.	        HOPDATA[ERR] = 0; 
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
?0110:
; 499.	     }
; 500.	}
	RET
node_wake:
; 501.	
; 502.	
; 503.	/*****************************************************************************
; 504.	 *
; 505.	 * FUNCTION NAME: node_wake
; 506.	 *
; 507.	 * DESCRIPTION  : This is sent over the network to the control node stating 
; 508.	 *                this node was just reset due to a power up or  a critical error.
; 509.	 *                
; 510.	 * RETURN VALUE : NONE
; 511.	 ******************************************************************************/
; 512.	
; 513.	
; 514.	void node_wake()
; 515.	{
; 516.	        
; 517.	           HOPDATA[CMD] = 251;
	MOV	A,#251
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 518.	           HOPDATA[NODEID] = arc51_nodeid;
	MOV	DPTR,#arc51_nodeid
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 519.	        if(nid == arc51_nodeid)
	MOV	DPTR,#arc51_nodeid
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	R4,A
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	XRL	A,R4
	JNZ	?0250
	MOV	DPTR,#nid
	MOVX	A,@DPTR
	XRL	A,R5
?0250:
	JNZ	?0112
?0111:
; 520.	           HOPDATA[ERR] =  1;
	MOV	A,#1
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 521.	        else
	SJMP	?0113
?0112:
; 522.	           HOPDATA[ERR] =  7;   /* duplicate node id detected */
	MOV	A,#7
	MOV	DPTR,#24572
	MOVX	@DPTR,A
?0113:
; 523.	           readback(0); 
	CLR	A
	MOV	R4,A
	MOV	R5,A
	LCALL	$REFFN readback
; 524.	        HOPDATA[ERR] = 0;    
	MOV	A,#0
	MOV	DPTR,#24572
	MOVX	@DPTR,A
; 525.	}
	RET
time_out:
; 526.	
; 527.	
; 528.	
; 529.	/*****************************************************************************
; 530.	 *
; 531.	 * FUNCTION NAME: time_out
; 532.	 *
; 533.	 * DESCRIPTION  : this function conts to see if there is a time out;
; 534.	 *                about 5 sec, (3 counters);
; 535.	 *
; 536.	 * VARIABLE :   x = 0:  inc counters and check for time out return 1 if time out
; 537.	 *              x = 1:  reset counters for a new run
; 538.	 *                
; 539.	 * RETURN VALUE : time out
; 540.	 ******************************************************************************/
; 541.	
; 542.	
; 543.	int time_out(int x)
; 544.	{
; 545.	 static int c1,c2,c3;
; 546.	
; 547.	switch(x)
	MOV	DPTR,#$LOCBX time_out
	MOV	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R4
	MOVX	@DPTR,A
	MOV	A,R4
	CJNE	R5,#0,$+5
	SJMP	$+5
	LJMP	?0117
	JZ	$+5
	LJMP	?0125
?0118:
; 548.	{
; 549.	
; 550.	     case   0:          /* count mode */
; 551.	                c1++;                   /*   counters */
	MOV	DPTR,#?0114+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#?0114
	JNZ	?0251
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0251:
; 552.	                if (c1 == 10000)
	MOV	DPTR,#?0114+1
	MOVX	A,@DPTR
	XRL	A,#16
	JNZ	?0252
	MOV	DPTR,#?0114
	MOVX	A,@DPTR
	XRL	A,#39
?0252:
	JNZ	?0120
?0119:
; 553.	                {
; 554.	                   c2++;
	MOV	DPTR,#?0115+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#?0115
	JNZ	?0253
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0253:
; 555.	                   c1 = 0;
	MOV	DPTR,#?0114
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0120:
; 556.	                }
; 557.	                if (c2 == 2)
	MOV	DPTR,#?0115+1
	MOVX	A,@DPTR
	XRL	A,#2
	JNZ	?0254
	MOV	DPTR,#?0115
	MOVX	A,@DPTR
?0254:
	JNZ	?0122
?0121:
; 558.	                {
; 559.	                   c3++;
	MOV	DPTR,#?0116+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#?0116
	JNZ	?0255
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0255:
; 560.	                   c2=0;
	MOV	DPTR,#?0115
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0122:
; 561.	                }
; 562.	                if (c3 == 1)
	MOV	DPTR,#?0116+1
	MOVX	A,@DPTR
	DEC	A
	JNZ	?0256
	MOV	DPTR,#?0116
	MOVX	A,@DPTR
?0256:
	JNZ	?0124
?0123:
; 563.	                        return(1);
	CLR	A
	MOV	R5,A
	INC	A
	MOV	R4,A
; 564.	                break;
	RET
?0124:
	SJMP	?0117
?0125:
	CJNE	A,#1,?0117
; 565.	    case  1:            /* reset counters */
; 566.	                c1=0;
	MOV	DPTR,#?0114
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 567.	                c2=0;
	MOV	DPTR,#?0115
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 568.	                c3=0;
	MOV	DPTR,#?0116
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 569.	                break;
	SJMP	?0117
?0117:
; 570.	}
; 571.	return(0);
	CLR	A
	MOV	R4,A
	MOV	R5,A
; 572.	}
?0126:
	RET
test_fun:
; 573.	
; 574.	
; 575.	/*****************************************************************************
; 576.	 *
; 577.	 * FUNCTION NAME: test_fun
; 578.	 *
; 579.	 * DESCRIPTION  : this function is used with the arcnet test board to test most of
; 580.	 *                the boards function.
; 581.	 *                
; 582.	 * RETURN VALUE : NONE
; 583.	 ******************************************************************************/
; 584.	
; 585.	
; 586.	void test_fun()
; 587.	{
; 588.	
; 589.	int i,j,k,status,t1=0,t2=0,t3=0;
	MOV	DPTR,#$LOCBX test_fun+8
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+10
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+12
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 590.	char look;
; 591.	
; 592.	/* set up serial port */   
; 593.	     PCON = 0x80;
	MOV	PCON,#128
; 594.	     TH1  = 0xDD; 
	MOV	TH1,#221
; 595.	     SCON = 0x52;
	MOV	SCON,#82
; 596.	     TMOD = 0x22;
	MOV	TMOD,#34
; 597.	     TCON = 0x50;
	MOV	TCON,#80
; 598.	   
; 599.	
; 600.	 status = arc51_init();           /* init the arcnet core */
	LCALL	$REFFN arc51_init
	MOV	A,R4
	MOV	R5,#0
; 601.	   if(status == E_OK) 
	MOV	DPTR,#$LOCBX test_fun+6
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	ORL	A,R5
	JNZ	?0128
?0127:
; 602.	   {
; 603.	        node_wake();
	LCALL	$REFFN node_wake
; 604.	        t1 = 1;
	MOV	DPTR,#$LOCBX test_fun+8
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
; 605.	        printf("init ok");
	MOV	R5,#LOW(?0129)
	MOV	R6,#HIGH(?0129)
	MOV	R7,#2
	LCALL	$REFFN printf
	SJMP	?0130
?0128:
; 606.	   }
; 607.	   else printf("error");
	MOV	R5,#LOW(?0131)
	MOV	R6,#HIGH(?0131)
	MOV	R7,#2
	LCALL	$REFFN printf
?0130:
; 608.	
; 609.	
; 610.	/* set register on test card*/
; 611.	(* (char xdata *) (0xfef9 )) = 0x00;
	MOV	A,#0
	MOV	DPTR,#65273
	MOVX	@DPTR,A
; 612.	/* led test */
; 613.	j=1;
	MOV	DPTR,#$LOCBX test_fun+2
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
; 614.	for(i= 0;i<=40;i++)
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0133:
	SETB	C
	MOV	DPTR,#$LOCBX test_fun+1
	MOVX	A,@DPTR
	SUBB	A,#40
	MOV	DPTR,#$LOCBX test_fun
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#128
	JC	$+5
	LJMP	?0132
?0134:
; 615.	{
; 616.	P3.3=1;
	SETB	P3.3
; 617.	if (j > 200 )
	SETB	C
	MOV	DPTR,#$LOCBX test_fun+3
	MOVX	A,@DPTR
	SUBB	A,#200
	MOV	DPTR,#$LOCBX test_fun+2
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#128
	JC	?0137
?0136:
?0139:
; 618.	   while ( j != 1)
	MOV	DPTR,#$LOCBX test_fun+3
	MOVX	A,@DPTR
	DEC	A
	JNZ	?0257
	MOV	DPTR,#$LOCBX test_fun+2
	MOVX	A,@DPTR
	JZ	?0138
?0257:
?0140:
; 619.	   {
; 620.	       P3.3=1;
	SETB	P3.3
; 621.	       j=j/2;
	MOV	DPTR,#$LOCBX test_fun+2
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	CLR	A
	MOV	R3,A
	MOV	R2,#2
	MOV	A,R6
	MOV	R0,A
	MOV	A,R7
	MOV	R1,A
	LCALL	?SI_DIV_L00
	MOV	A,R0
	MOV	R6,A
	MOV	A,R1
	MOV	R7,A
; 622.	       (* (char xdata *) (0xfefa )) = j;
	MOV	DPTR,#$LOCBX test_fun+2
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	MOV	A,R6
	MOV	DPTR,#65274
	MOVX	@DPTR,A
; 623.	       for(k=0;k<=6000;k++);
	MOV	DPTR,#$LOCBX test_fun+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0142:
	SETB	C
	MOV	DPTR,#$LOCBX test_fun+5
	MOVX	A,@DPTR
	SUBB	A,#112
	MOV	DPTR,#$LOCBX test_fun+4
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#151
	JNC	?0141
?0143:
	MOV	DPTR,#$LOCBX test_fun+5
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+4
	JNZ	?0258
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0258:
	SJMP	?0142
?0141:
; 624.	       P3.3=0;
	CLR	P3.3
	SJMP	?0139
?0138:
?0137:
; 625.	   }
; 626.	   (* (char xdata *) (0xfefa )) = j;
	MOV	DPTR,#$LOCBX test_fun+3
	MOVX	A,@DPTR
	MOV	DPTR,#65274
	MOVX	@DPTR,A
; 627.	for(k=0;k<=6000;k++);
	MOV	DPTR,#$LOCBX test_fun+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0146:
	SETB	C
	MOV	DPTR,#$LOCBX test_fun+5
	MOVX	A,@DPTR
	SUBB	A,#112
	MOV	DPTR,#$LOCBX test_fun+4
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#151
	JNC	?0145
?0147:
	MOV	DPTR,#$LOCBX test_fun+5
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+4
	JNZ	?0259
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0259:
	SJMP	?0146
?0145:
; 628.	P3.3=0;
	CLR	P3.3
; 629.	   j=j*2;
	MOV	DPTR,#$LOCBX test_fun+2
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R6
	ADD	A,ACC
	XCH	A,R7
	RLC	A
	XCH	A,R7
	MOV	DPTR,#$LOCBX test_fun+2
	XCH	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R7
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun
	JNZ	?0260
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0260:
	LJMP	?0133
?0132:
; 630.	}
; 631.	
; 632.	     printf("\n<--------------------------------->\n");
	MOV	R5,#LOW(?0149)
	MOV	R6,#HIGH(?0149)
	MOV	R7,#2
	LCALL	$REFFN printf
; 633.	     printf(  "<             BNL  (BOOT)         >\n");
	MOV	R5,#LOW(?0150)
	MOV	R6,#HIGH(?0150)
	MOV	R7,#2
	LCALL	$REFFN printf
; 634.	     printf(  "<            FEM.C  ver 1.00      >\n");
	MOV	R5,#LOW(?0151)
	MOV	R6,#HIGH(?0151)
	MOV	R7,#2
	LCALL	$REFFN printf
; 635.	     printf(  "<           TEST ROUTINE          >\n");
	MOV	R5,#LOW(?0152)
	MOV	R6,#HIGH(?0152)
	MOV	R7,#2
	LCALL	$REFFN printf
; 636.	     printf(  "<--------------------------------->\n");
	MOV	R5,#LOW(?0153)
	MOV	R6,#HIGH(?0153)
	MOV	R7,#2
	LCALL	$REFFN printf
; 637.	
; 638.	
; 639.	
; 640.	printf("\n  NODE 2 test routine starting\n ");
	MOV	R5,#LOW(?0154)
	MOV	R6,#HIGH(?0154)
	MOV	R7,#2
	LCALL	$REFFN printf
; 641.	
; 642.	
; 643.	
; 644.	/* set test board reg */
; 645.	(* (char xdata *) (0xfef9 )) = 0x20;
	MOV	A,#32
	MOV	DPTR,#65273
	MOVX	@DPTR,A
; 646.	
; 647.	
; 648.	/*set port write */
; 649.	   P3.3 = 0;
	CLR	P3.3
; 650.	   P1= 0x77;
	MOV	P1,#119
; 651.	
; 652.	/* toggel prr to reset the d-flip flops on test board */
; 653.	   P3.2 = 1;
	SETB	P3.2
; 654.	   P3.2 = 0;
	CLR	P3.2
; 655.	
; 656.	
; 657.	/*   check the adress lines */
; 658.	  i =  (* (char xdata *) (0xfefb ));
	MOV	DPTR,#65275
	MOVX	A,@DPTR
	MOV	R5,#0
; 659.	  (* (char xdata *) (0xfefb )) = i;
	MOV	DPTR,#$LOCBX test_fun
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	DPTR,#65275
	MOVX	@DPTR,A
; 660.	
; 661.	
; 662.	printf(" got in the user program\n\n");
	MOV	R5,#LOW(?0155)
	MOV	R6,#HIGH(?0155)
	MOV	R7,#2
	LCALL	$REFFN printf
; 663.	
; 664.	/* check port write, data read
; 665.	   address lines and data lines
; 666.	*/
; 667.	
; 668.	i = 0;
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 669.	    P1 = 0x77;  
	MOV	P1,#119
; 670.	    printf(" 0x77--> %x    \n", look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0156)
	MOV	R6,#HIGH(?0156)
	MOV	R7,#2
	LCALL	$REFFN printf
; 671.	    if (look != 0x77)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	XRL	A,#119
	JZ	?0158
?0157:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0158:
; 672.	    P1 = 0x55;  
	MOV	P1,#85
; 673.	    printf(" 0x55 --> %x    \n",  look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0159)
	MOV	R6,#HIGH(?0159)
	MOV	R7,#2
	LCALL	$REFFN printf
; 674.	    if (look != 0x55)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	XRL	A,#85
	JZ	?0161
?0160:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0161:
; 675.	    P1 = 0x33;  
	MOV	P1,#51
; 676.	    printf(" 0x33 --> %x    \n",  look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0162)
	MOV	R6,#HIGH(?0162)
	MOV	R7,#2
	LCALL	$REFFN printf
; 677.	    if (look != 0x33)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	XRL	A,#51
	JZ	?0164
?0163:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0164:
; 678.	    P1 = 0x44;  
	MOV	P1,#68
; 679.	    printf(" 0x44 --> %x    \n", look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0165)
	MOV	R6,#HIGH(?0165)
	MOV	R7,#2
	LCALL	$REFFN printf
; 680.	    if (look != 0x44)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	XRL	A,#68
	JZ	?0167
?0166:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0167:
; 681.	    P1 = 0xaa;  
	MOV	P1,#170
; 682.	    printf(" 0xaa --> %x    \n", look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0168)
	MOV	R6,#HIGH(?0168)
	MOV	R7,#2
	LCALL	$REFFN printf
; 683.	    if (look != 0xaa)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	XRL	A,#170
	JZ	?0170
?0169:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0170:
; 684.	    P1 = 0x00;  
	MOV	P1,#0
; 685.	    printf(" 0x00 --> %x    \n", look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0171)
	MOV	R6,#HIGH(?0171)
	MOV	R7,#2
	LCALL	$REFFN printf
; 686.	    if (look != 0x00)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	JZ	?0173
?0172:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0173:
; 687.	    P1 = 0xff;  
	MOV	P1,#255
; 688.	    printf(" 0xff --> %x    \n", look = (* (char xdata *) (0xfefa )));
	MOV	DPTR,#65274
	MOVX	A,@DPTR
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	@DPTR,A
	MOV	R5,#0
	MOV	DPTR,#$PRMBX printf+3
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
	MOV	R5,#LOW(?0174)
	MOV	R6,#HIGH(?0174)
	MOV	R7,#2
	LCALL	$REFFN printf
; 689.	    if (look != 0xff)  i = 1;
	MOV	DPTR,#$LOCBX test_fun+14
	MOVX	A,@DPTR
	INC	A
	JZ	?0176
?0175:
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
?0176:
; 690.	
; 691.	
; 692.	if (i != 1)
	MOV	DPTR,#$LOCBX test_fun+1
	MOVX	A,@DPTR
	DEC	A
	JNZ	?0261
	MOV	DPTR,#$LOCBX test_fun
	MOVX	A,@DPTR
	JZ	?0178
?0261:
?0177:
; 693.	{
; 694.	 t3 = 1;
	MOV	DPTR,#$LOCBX test_fun+12
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	INC	A
	MOVX	@DPTR,A
; 695.	 printf("\n data and port check ok\n");
	MOV	R5,#LOW(?0179)
	MOV	R6,#HIGH(?0179)
	MOV	R7,#2
	LCALL	$REFFN printf
?0178:
; 696.	}
; 697.	
; 698.	/*
; 699.	check data line and write
; 700.	*/
; 701.	
; 702.	for(j=0;j<=500;j++)
	MOV	DPTR,#$LOCBX test_fun+2
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0181:
	SETB	C
	MOV	DPTR,#$LOCBX test_fun+3
	MOVX	A,@DPTR
	SUBB	A,#244
	MOV	DPTR,#$LOCBX test_fun+2
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#129
	JNC	?0180
?0182:
; 703.	   (* (char xdata *) (0xfefa )) = j;
	MOV	DPTR,#$LOCBX test_fun+3
	MOVX	A,@DPTR
	MOV	DPTR,#65274
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+3
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun+2
	JNZ	?0262
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0262:
	SJMP	?0181
?0180:
; 704.	
; 705.	/*
; 706.	togal P3.5 for PR 
; 707.	
; 708.	*/
; 709.	P3.5 = 0;
	CLR	P3.5
; 710.	P3.5 = 1;   
	SETB	P3.5
; 711.	P3.5 = 0;
	CLR	P3.5
; 712.	
; 713.	/* check each chip select */
; 714.	
; 715.	for (i=0;i<=20;i++)
	MOV	DPTR,#$LOCBX test_fun
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0185:
	SETB	C
	MOV	DPTR,#$LOCBX test_fun+1
	MOVX	A,@DPTR
	SUBB	A,#20
	MOV	DPTR,#$LOCBX test_fun
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#128
	JNC	?0184
?0186:
; 716.	    gen_cs(i);
	MOV	DPTR,#$LOCBX test_fun
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	LCALL	$REFFN gen_cs
	MOV	DPTR,#$LOCBX test_fun+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX test_fun
	JNZ	?0263
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0263:
	SJMP	?0185
?0184:
; 717.	
; 718.	/* check data write compare */
; 719.	(* (char xdata *) (0xfef9 )) = 0x25;
	MOV	A,#37
	MOV	DPTR,#65273
	MOVX	@DPTR,A
; 720.	
; 721.	/*togal port write*/
; 722.	P3.3=1;
	SETB	P3.3
; 723.	P3.3=0;
	CLR	P3.3
; 724.	
; 725.	testsend(0x03);
	CLR	A
	MOV	R5,A
	MOV	R4,#3
	LCALL	$REFFN testsend
?0189:
; 726.	
; 727.	while(1)
	NOP
; 728.	   {
; 729.	      if (arc51_read(&buf[0]) == E_OK)        /* if status = 0 a packet was recived */
	MOV	R5,#LOW(buf)
	MOV	R6,#HIGH(buf)
	MOV	R7,#1
	LCALL	$REFFN arc51_read
	CJNE	R4,#0,?0192
?0191:
; 730.	        if((buf[NODEID+4] == nid) || (buf[GRPCMD+4] == PUB) || (buf[GRPCMD+4] == grpid))
	MOV	DPTR,#buf+4
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	R4,A
	MOV	DPTR,#nid+1
	MOVX	A,@DPTR
	XRL	A,R4
	JNZ	?0264
	MOV	DPTR,#nid
	MOVX	A,@DPTR
	XRL	A,R5
	JZ	?0193
?0264:
	MOV	DPTR,#buf+7
	MOVX	A,@DPTR
	DEC	A
	JZ	?0193
	MOV	DPTR,#buf+7
	MOVX	A,@DPTR
	MOV	R5,#0
	MOV	R4,A
	MOV	DPTR,#grpid+1
	MOVX	A,@DPTR
	XRL	A,R4
	JNZ	?0265
	MOV	DPTR,#grpid
	MOVX	A,@DPTR
	XRL	A,R5
?0265:
	JNZ	?0194
?0195:
?0196:
?0193:
; 731.	            if (buf[ERR+4] == 0)
	MOV	DPTR,#buf+8
	MOVX	A,@DPTR
	JNZ	?0198
?0197:
; 732.	            {           
; 733.	                testsend(0x03);
	CLR	A
	MOV	R5,A
	MOV	R4,#3
	LCALL	$REFFN testsend
; 734.	                (* (char xdata *) (0xfef9 )) = 0x2f;
	MOV	A,#47
	MOV	DPTR,#65273
	MOVX	@DPTR,A
; 735.	                /*togal port write*/
; 736.	                P3.3=1;
	SETB	P3.3
; 737.	                P3.3=0;
	CLR	P3.3
; 738.	            }
; 739.	            else
	SJMP	?0199
?0198:
; 740.	              ERROR(2);
	CLR	A
	MOV	R5,A
	MOV	R4,#2
	LCALL	$REFFN ERROR
?0199:
?0194:
?0192:
; 741.	   }
; 742.	
; 743.	 /* printf("the test is compleate");*/
; 744.	}
	SJMP	?0189
gen_cs:
; 745.	
; 746.	
; 747.	
; 748.	
; 749.	
; 750.	/*****************************************************************************
; 751.	 *
; 752.	 * FUNCTION NAME: gen_cs
; 753.	 *
; 754.	 * DESCRIPTION  : this function is used to generate chip selects on the arcnet board
; 755.	 *                used with the test fucntion
; 756.	 *                
; 757.	 * RETURN VALUE : NONE
; 758.	 ******************************************************************************/
; 759.	
; 760.	
; 761.	void gen_cs(int x)   
; 762.	{ 
; 763.	
; 764.	switch (x) {
	MOV	DPTR,#$LOCBX gen_cs
	MOV	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R4
	MOVX	@DPTR,A
	MOV	A,R4
	LCALL	?AR5_SC_SWITCH_L05
	DW	0
	DB	15
	DW	?0200
	DW	?0201
	DW	?0202
	DW	?0203
	DW	?0204
	DW	?0205
	DW	?0206
	DW	?0207
	DW	?0208
	DW	?0209
	DW	?0210
	DW	?0211
	DW	?0212
	DW	?0213
	DW	?0214
	DW	?0215
	DW	?0216
?0201:
; 765.	
; 766.	        case 0: (* (char xdata *) 0xfefd) = 0xfe;   /* chip select 0*/
	MOV	A,#254
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 767.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 768.	                break;
	LJMP	?0200
?0202:
; 769.	        case 1: (* (char xdata *) 0xfefd) = 0xfd;   /* chip select 1*/
	MOV	A,#253
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 770.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 771.	                break;
	LJMP	?0200
?0203:
; 772.	        case 2: (* (char xdata *) 0xfefd) = 0xfb;   /* chip select 2*/
	MOV	A,#251
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 773.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 774.	                break;
	LJMP	?0200
?0204:
; 775.	        case 3: (* (char xdata *) 0xfefd) = 0xf7;   /* chip select 3*/
	MOV	A,#247
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 776.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 777.	                break;
	LJMP	?0200
?0205:
; 778.	        case 4: (* (char xdata *) 0xfefd) = 0xef;   /* chip select 4*/
	MOV	A,#239
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 779.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 780.	                break;
	LJMP	?0200
?0206:
; 781.	        case 5: (* (char xdata *) 0xfefd) = 0xdf;   /* chip select 5*/
	MOV	A,#223
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 782.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 783.	                break;
	LJMP	?0200
?0207:
; 784.	        case 6: (* (char xdata *) 0xfefd) = 0xbf;   /* chip select 6*/
	MOV	A,#191
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 785.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 786.	                break;
	LJMP	?0200
?0208:
; 787.	        case 7: (* (char xdata *) 0xfefd) = 0x7f;   /* chip select 7*/
	MOV	A,#127
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 788.	                (* (char xdata *) 0xfefd) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65277
	MOVX	@DPTR,A
; 789.	                break;
	SJMP	?0200
?0209:
; 790.	
; 791.	        case 8: (* (char xdata *) 0xfefe) = 0xfe;   /* chip select 8*/
	MOV	A,#254
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 792.	                (* (char xdata *) 0xfefe) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 793.	                break;
	SJMP	?0200
?0210:
; 794.	        case 9: (* (char xdata *) 0xfefe) = 0xfd;   /* chip select 9*/
	MOV	A,#253
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 795.	                (* (char xdata *) 0xfefe) = 0xff;   /* clear        */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 796.	                break;
	SJMP	?0200
?0211:
; 797.	        case 10: (* (char xdata *) 0xfefe) = 0xfb;   /* chip select 10*/
	MOV	A,#251
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 798.	                 (* (char xdata *) 0xfefe) = 0xff;   /* clear       */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 799.	                 break;
	SJMP	?0200
?0212:
; 800.	        case 11: (* (char xdata *) 0xfefe) = 0xf7;   /* chip select 11*/
	MOV	A,#247
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 801.	                 (* (char xdata *) 0xfefe) = 0xff;   /* clear       */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 802.	                 break;
	SJMP	?0200
?0213:
; 803.	        case 12: (* (char xdata *) 0xfefe) = 0xef;   /* chip select 12*/
	MOV	A,#239
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 804.	                 (* (char xdata *) 0xfefe) = 0xff;   /* clear       */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 805.	                 break;
	SJMP	?0200
?0214:
; 806.	        case 13: (* (char xdata *) 0xfefe) = 0xdf;   /* chip select 13*/
	MOV	A,#223
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 807.	                 (* (char xdata *) 0xfefe) = 0xff;   /* clear       */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 808.	                 break;
	SJMP	?0200
?0215:
; 809.	        case 14: (* (char xdata *) 0xfefe) = 0xbf;   /* chip select 14*/
	MOV	A,#191
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 810.	                 (* (char xdata *) 0xfefe) = 0xff;   /* clear       */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 811.	                 break;
	SJMP	?0200
?0216:
; 812.	        case 15: (* (char xdata *) 0xfefe) = 0x7f;   /* chip select 15*/
	MOV	A,#127
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 813.	                 (* (char xdata *) 0xfefe) = 0xff;   /* clear       */
	MOV	A,#255
	MOV	DPTR,#65278
	MOVX	@DPTR,A
; 814.	                 break;
	SJMP	?0200
?0200:
; 815.	    }
; 816.	}
	RET
testsend:
; 817.	
; 818.	
; 819.	
; 820.	/*****************************************************************************
; 821.	 *
; 822.	 * FUNCTION NAME: gen_cs
; 823.	 *
; 824.	 * DESCRIPTION  : this function is used to generate a packet set to all nodes 
; 825.	 *                to generate a responce from them. used with the test function
; 826.	 *                
; 827.	 * RETURN VALUE : NONE
; 828.	 ******************************************************************************/
; 829.	
; 830.	
; 831.	void  testsend(int x)
; 832.	{
; 833.	     int count,i,ii,dlen;
; 834.	     count = 0; 
	MOV	DPTR,#$LOCBX testsend
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
; 835.	                         /* calculate the number of bytes to send */
; 836.	     dlen =9;
	MOV	DPTR,#$LOCBX testsend+6
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,#9
	MOVX	@DPTR,A
; 837.	     HOPDATA[DLEN] =   (USIGN8) ((0xFF00 & dlen) >> 8);
	CLR	A
	MOV	R7,A
	MOV	DPTR,#$LOCBX testsend+6
	MOVX	A,@DPTR
	XCH	A,R7
	MOV	A,R7
	MOV	R7,#0
	MOV	DPTR,#24574
	MOVX	@DPTR,A
; 838.	     HOPDATA[DLEN+1] = (USIGN8) (0x00FF & dlen);
	MOV	DPTR,#$LOCBX testsend+7
	MOVX	A,@DPTR
	MOV	R7,#0
	MOV	DPTR,#24575
	MOVX	@DPTR,A
; 839.	     HOPDATA[CMD] = (USIGN8) x; /*send command x*/
	MOV	DPTR,#$LOCBX testsend+8
	MOV	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R4
	MOVX	@DPTR,A
	MOV	A,R4
	MOV	DPTR,#24569
	MOVX	@DPTR,A
; 840.	     HOPDATA[NODEID] = arc51_nodeid;
	MOV	DPTR,#arc51_nodeid
	MOVX	A,@DPTR
	MOV	DPTR,#24568
	MOVX	@DPTR,A
; 841.	     HOPDATA[8] = 0x03;         /* send a command 3 (respond) */
	MOV	A,#3
	MOV	DPTR,#24576
	MOVX	@DPTR,A
?0218:
; 842.	     while (dlen > count)
	MOV	DPTR,#$LOCBX testsend+6
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX testsend+1
	MOVX	A,@DPTR
	CLR	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX testsend
	MOVX	A,@DPTR
	XRL	A,#128
	XCH	A,R5
	XRL	A,#128
	XCH	A,R5
	SUBB	A,R5
	JC	$+5
	LJMP	?0217
?0219:
; 843.	     {
; 844.	        i= 0;
	MOV	DPTR,#$LOCBX testsend+2
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0221:
; 845.	
; 846.	                        /* break up the hopper memory into packets */
; 847.	        while ((i < PKT_size) && (dlen > count))  
	CLR	C
	MOV	DPTR,#$LOCBX testsend+3
	MOVX	A,@DPTR
	SUBB	A,#244
	MOV	DPTR,#$LOCBX testsend+2
	MOVX	A,@DPTR
	XRL	A,#128
	SUBB	A,#129
	JNC	?0220
	MOV	DPTR,#$LOCBX testsend+6
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX testsend+1
	MOVX	A,@DPTR
	CLR	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX testsend
	MOVX	A,@DPTR
	XRL	A,#128
	XCH	A,R5
	XRL	A,#128
	XCH	A,R5
	SUBB	A,R5
	JNC	?0220
?0224:
?0223:
?0222:
; 848.	        {
; 849.	         userbuf[i] = HOPDATA[count];
	MOV	DPTR,#$LOCBX testsend+1
	MOVX	A,@DPTR
	ADD	A,#248
	MOV	R4,A
	MOV	DPTR,#$LOCBX testsend
	MOVX	A,@DPTR
	ADDC	A,#95
	MOV	DPL,R4
	MOV	DPH,A
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	DPTR,#$LOCBX testsend+3
	MOVX	A,@DPTR
	ADD	A,#LOW(userbuf)
	MOV	R4,A
	MOV	DPTR,#$LOCBX testsend+2
	MOVX	A,@DPTR
	ADDC	A,#HIGH(userbuf)
	MOV	R5,A
	MOV	A,R6
	MOV	DPL,R4
	MOV	DPH,R5
	MOVX	@DPTR,A
; 850.	         count++;
	MOV	DPTR,#$LOCBX testsend+1
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX testsend
	JNZ	?0266
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0266:
; 851.	         i++;
	MOV	DPTR,#$LOCBX testsend+3
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
	MOV	DPTR,#$LOCBX testsend+2
	JNZ	?0267
	MOVX	A,@DPTR
	INC	A
	MOVX	@DPTR,A
?0267:
	SJMP	?0221
?0220:
; 852.	        }
; 853.	        buf[0] = 0x00;
	MOV	A,#0
	MOV	DPTR,#buf
	MOVX	@DPTR,A
; 854.	        buf[1] = 0x00;
	MOV	A,#0
	MOV	DPTR,#buf+1
	MOVX	@DPTR,A
; 855.	        buf[2] = 0;
	MOV	A,#0
	MOV	DPTR,#buf+2
	MOVX	@DPTR,A
; 856.	        buf[3] = i;
	MOV	DPTR,#$LOCBX testsend+3
	MOVX	A,@DPTR
	MOV	DPTR,#buf+3
	MOVX	@DPTR,A
; 857.	        if ( i >=256) buf[2] =1;        /* for long packet */
	MOV	DPTR,#$LOCBX testsend+2
	MOVX	A,@DPTR
	XRL	A,#128
	CLR	C
	SUBB	A,#129
	JC	?0226
?0225:
	MOV	A,#1
	MOV	DPTR,#buf+2
	MOVX	@DPTR,A
?0226:
; 858.	        for(ii=0;ii<i;ii++) buf[4+ii] = userbuf[ii];    
	MOV	DPTR,#$LOCBX testsend+4
	CLR	A
	MOVX	@DPTR,A
	INC	DPTR
	MOVX	@DPTR,A
?0228:
	MOV	DPTR,#$LOCBX testsend+4
	MOVX	A,@DPTR
	MOV	R5,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R4,A
	MOV	DPTR,#$LOCBX testsend+3
	MOVX	A,@DPTR
	SETB	C
	SUBB	A,R4
	MOV	DPTR,#$LOCBX testsend+2
	MOVX	A,@DPTR
	XRL	A,#128
	XCH	A,R5
	XRL	A,#128
	XCH	A,R5
	SUBB	A,R5
	JC	?0227
?0229:
	MOV	DPTR,#$LOCBX testsend+4
	MOVX	A,@DPTR
	MOV	R7,A
	INC	DPTR
	MOVX	A,@DPTR
	MOV	R6,A
	MOV	A,R7
	MOV	R5,A
	MOV	A,R6
	ADD	A,#LOW(userbuf)
	MOV	DPL,A
	MOV	A,R5
	ADDC	A,#HIGH(userbuf)
	MOV	DPH,A
	MOVX	A,@DPTR
	XCH	A,R6
	MOV	R4,A
	XCH	A,R6
	XCH	A,R7
	MOV	R5,A
	XCH	A,R7
	MOV	R2,A
	MOV	A,R4
	ADD	A,#LOW(buf+4)
	MOV	DPL,A
	MOV	A,R5
	ADDC	A,#HIGH(buf+4)
	MOV	DPH,A
	MOV	A,R2
	MOVX	@DPTR,A
	INC	R6
	MOV	A,R6
	JNZ	?0268
	INC	R7
?0268:
	MOV	DPTR,#$LOCBX testsend+4
	MOV	A,R7
	MOVX	@DPTR,A
	INC	DPTR
	MOV	A,R6
	MOVX	@DPTR,A
	SJMP	?0228
?0227:
; 859.	        i = arc51_write(&buf[0]);
	MOV	R5,#LOW(buf)
	MOV	R6,#HIGH(buf)
	MOV	R7,#1
	LCALL	$REFFN arc51_write
	MOV	A,R4
	MOV	R5,#0
	MOV	DPTR,#$LOCBX testsend+2
	XCH	A,R5
	MOVX	@DPTR,A
	INC	DPTR
	XCH	A,R5
	MOVX	@DPTR,A
; 860.	     }
; 861.	}
	LJMP	?0218
?0217:
	RET
	RSEG	CSTR
?0129:
	DB	'init ok',0
?0131:
	DB	'error',0
?0149:
	DB	10,'<--------------------------------->',10,0
?0150:
	DB	'<             BNL  (BOOT)         >',10,0
?0151:
	DB	'<            FEM.C  ver 1.00      >',10,0
?0152:
	DB	'<           TEST ROUTINE          >',10,0
?0153:
	DB	'<--------------------------------->',10,0
?0154:
	DB	10,'  NODE 2 test routine starting',10,' ',0
?0155:
	DB	' got in the user program',10,10,0
?0156:
	DB	' 0x77--> %x    ',10,0
?0159:
	DB	' 0x55 --> %x    ',10,0
?0162:
	DB	' 0x33 --> %x    ',10,0
?0165:
	DB	' 0x44 --> %x    ',10,0
?0168:
	DB	' 0xaa --> %x    ',10,0
?0171:
	DB	' 0x00 --> %x    ',10,0
?0174:
	DB	' 0xff --> %x    ',10,0
?0179:
	DB	10,' data and port check ok',10,0
	RSEG	CONST
UFUN:
	DW	16384
SWRESET:
	DW	0
EPROG:
	DW	14336
	RSEG	X_UDATA
pckt:
	DS	7
FNP:
	DS	3
fblock:
	DS	2
buf:
	DS	512
userbuf:
	DS	512
temp:
	DS	2
?0114:
	DS	2
?0115:
	DS	2
?0116:
	DS	2
	RSEG	X_IDATA
nid:
	DS	2
grpid:
	DS	2
	RSEG	X_CDATA
	DW	21
	DW	0
	END