#include "record.h"
#include "gvalue.h"
#include "RtUserCode.h"

void TRtUserCode::Init()
{
	BackIndexClear();
}

void TRtUserCode::BackIndexClear()
{
	int i;
	for(i=0; i<10240; i++){
		Context.Local.Body[i].uCode=0;
		Context.Local.Body[i].Path.Full=0;
	}
	Context.Local.BackEndPst = 0;
	for(i=0; i<100; i++)Context.Local.BackIndex[i]=0;
	
	Context.Nw.BackEndPst = 0;
	for(i=0; i<1600; i++)Context.Nw.BackIndex[i]=0;
}



unsigned int TRtUserCode::NwGetUserCode(unsigned int aNum, unsigned int aP0, unsigned int aP1)
{
	unsigned int aAddr;
	
	if( (aNum == 0) || (aNum > 16) )return 0;
	if(aP0 == 0)return 0;
	if(aP1 == 0)return 0;
	
	if(aP0 <= dPORT_MAX_COUNT){
		aP0--;
		aP1--;
		aAddr = dAddrSdram_NwUserCodeAbs + (aP0 * 1024) + ( aP1*4 );
		return *(volatile unsigned int *)aAddr;
	}else
	if( (aP0 >= dADDR_DIRECTPAD_START) && (aP0 <= dADDR_DIRECTPAD_END) && (aP1 <= dDIRECTCTL_KEY_MAX_COUNT) ){
		aP0 -= dADDR_DIRECTPAD_START;
		aP1--;
		aP1 = aP0 * 8 + aP1;
		aAddr = dAddrSdram_NwUserCodeAbs + (40 * 1024) + ( aP1*4 );
		return *(volatile unsigned int *)aAddr;
	}
	
     
	return 0;
}



