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