Exemplo n.º 1
0
/* apply Q-permutation to x */
void Q(hashState *ctx, u8 x[ROWS][COLS1024]) {
  u8 i;
  Variant v = ctx->columns==8?Q512:Q1024;
#ifndef TURN_OFF_PRINTING
  printf(":: BEGIN Q\n");
  printf("Input:\n");
  PrintState(ctx, x);
#endif
  for (i = 0; i < ctx->rounds; i++) {
    AddRoundConstant(x, ctx->columns, i, v);
#ifndef TURN_OFF_PRINTING
    printf("t=%d (AddRoundConstant):\n", i);
    PrintState(ctx, x);
#endif
    SubBytes(x, ctx->columns);
#ifndef TURN_OFF_PRINTING
    printf("t=%d (SubBytes):\n", i);
    PrintState(ctx, x);
#endif
    ShiftBytes(x, ctx->columns, v);
#ifndef TURN_OFF_PRINTING
    printf("t=%d (ShiftBytes):\n", i);
    PrintState(ctx, x);
#endif
    MixBytes(x, ctx->columns);
#ifndef TURN_OFF_PRINTING
    printf("t=%d (MixBytes):\n", i);
    PrintState(ctx, x);
#endif
  }
#ifndef TURN_OFF_PRINTING
  printf(":: END Q\n\n");
#endif
}
Exemplo n.º 2
0
void Solve( PiecesLeft pl, const PuzzleState &ps ) {
	if(!Solvable(ps)) {
		return;
	}
	if( pl.size() == 0 ) {
		printf( "Solution:\n" );
		PrintState( ps );
		PrintState( ps, fopen( solutionfilename, "w" ) );
		exit( 0 );
	}
	int i = *(pl.begin());
	Piece piece = pieces[i];
	//printf( "Attempting to fit in piece: %c\n", piece.id );

	pl.erase( i );
	for( int r = 0; r < 8; ++r ) {
		Piece newPiece = Rot( piece, r );
		//printf( "Trying this way:\n" );
		//PrintPiece( newPiece );
		for( int y = -2; y < HEIGHT; ++y ) {
			for( int x = -2; x < WIDTH; ++x ) {
				if( PieceFits( ps, newPiece, x, y ) ) {
					PuzzleState newState = FillState( ps, newPiece, x, y );
					Solve( pl, newState );
				}
			}
		}
	}
}
Exemplo n.º 3
0
void LoadState( PuzzleState &state, PiecesLeft &remains, const char *filename ) {
	PuzzleState ps = Clear();
	PiecesLeft pl = StartingSet();
	if( FILE *fp = fopen( filename, "r" ) ) {
		char linebuf[256];
		for( int row = 0; row < HEIGHT; ++row ) {
			char *line = fgets( linebuf, sizeof( linebuf ), fp );
			if( !line ) {
				break;
			}
			for( int col = 0; col < WIDTH; ++col ) {
				char c = line[col];
				if( c == 0 || c == '\n' || c == '\r' )
					break;
				if( c != '.' ) {
					int i = GetPieceIDFromChar( c );
					pl.erase(i);
					ps.filled[row*WIDTH + col] = c;
				}
			}
		}
	}
	printf( "loaded %s\n", filename );
	PrintState( ps );
	printf( "\n" );
	state = ps;
	remains = pl;
}
void AMXStackFramePrinter::Print(const AMXStackFrame &frame) {
  PrintReturnAddress(frame);
  *stream_ << " in ";

  AMXDebugSymbol caller = GetCallerSymbol(frame);
  if (caller) {
    PrintCallerName(frame, caller);
  } else {
    PrintCallerName(frame);
  }

  *stream_ << " (";
  PrintArgumentList(frame);
  *stream_ << ")";

  if (HaveDebugInfo() && UsesAutomata(frame)) {
    *stream_ << " ";
    PrintState(frame);
  }

  if (HaveDebugInfo() && frame.return_address() != 0) {
    *stream_ << " at ";
    PrintSourceLocation(frame.return_address());
  }
}
Exemplo n.º 5
0
void StdinThread()
{
    char str[MAX_CMD_LENGTH];
    while (gets(str))
    {
        if (strcmp(str, "quit") == 0)
        {
            if (ReadMPDRegistry("RevertToMultiUser", str, false))
            {
                if (stricmp(str, "yes") == 0)
                    WriteMPDRegistry("SingleUser", "no");
                DeleteMPDRegistry("RevertToMultiUser");
            }
            dbg_printf("StdinThread: Exiting.\n");
            ExitProcess(0);
        }
        if (strcmp(str, "stop") == 0)
        {
            ServiceStop();
        }
        if (strcmp(str, "print") == 0)
        {
            PrintState(stdout);
        }
    }
}
Exemplo n.º 6
0
void PrintBad(P &out,const Lang &lang,const StateCompress<LR1Estimate> &compress)
 {
  ExtLangOpt extopt(lang,compress.getAtomCount());

  Printf(out,"#;\n",Title("Bad States"));

  ulen state_count=compress.getStateCount();

  DynArray<Trace> trace_table(state_count);

  for(ulen i=0; i<state_count ;i++) trace_table[i]=compress.buildTrace(i);

  for(auto p=compress.getStateTable(); +p ;++p)
    {
     ulen prop_index=p->prop_index;

     auto &prop=compress.getProps()[prop_index];

     if( prop.hasConflict() )
       {
        Printf(out,"\n#; = #;\n\n",BindOpt(extopt,PrintState(p->index,trace_table)),prop_index);

        Printf(out,"#;) #.b;",prop_index,prop);
       }
    }

  Printf(out,"\n#;\n",TextDivider());
 }
Exemplo n.º 7
0
void qdplusPrintState(FILE *fp, QDPLUS *handle)
{
LNKLST_NODE *crnt;
QDPLUS_DIGITIZER *digitizer;

    if (fp == NULL || handle == NULL) return;

    if (handle->par.path.state != NULL) {
        fprintf(fp, "%s\n", handle->par.path.state);
    } else {
        fprintf(fp, "qdplusPrintState called with NULL par.path.state!\n");
    }

    if ((crnt = listFirstNode(handle->list.digitizer)) == NULL) {
        fprintf(fp, "empty file\n");
        return;
    }

    while (crnt != NULL) {
        digitizer = (QDPLUS_DIGITIZER *) crnt->payload;
        fprintf(fp, "S/N %016llX\n", digitizer->serialno);
        PrintState(fp, digitizer->state);
        crnt = listNextNode(crnt);
    }

    fflush(fp);
}
Exemplo n.º 8
0
/* do output transformation, P(h)+h */
void OutputTransformation(hashState *ctx) {
  int i, j;
  u8 temp[ROWS][COLS1024];

  /* store chaining ("h") in temp */
  for (i = 0; i < ROWS; i++) {
    for (j = 0; j < ctx->columns; j++) {
      temp[i][j] = ctx->chaining[i][j];
    }
  }

#ifndef TURN_OFF_PRINTING
    printf("========================================\n\n");
  printf("Output transformation:\n\n");
#endif

  /* compute P(temp) = P(h) */
  P(ctx, temp);

  /* feed chaining forward, yielding P(h)+h */
  for (i = 0; i < ROWS; i++) {
    for (j = 0; j < ctx->columns; j++) {
      ctx->chaining[i][j] ^= temp[i][j];
    }
  }
#ifndef TURN_OFF_PRINTING
    printf("P(h) + h =\n");
    PrintState(ctx, ctx->chaining);
#endif
}
void PrintBufferAll(){
  //printf("buf[n ...]\n");
  int index = 0;
  for(int i = 0; i < NHASH; i++){
    for(buf *p = h_head[i].hash_fp; p != &h_head[i]; p = p -> hash_fp){
      PrintRoutine(p, index);
      /*
      if(index >= 10){
	if(p -> blkno >= 10){
	  printf("[%d : %d ", index, p -> blkno);
	}
	else{
	  printf("[%d :  %d ", index, p -> blkno);
	}
      }
      else{
	if(p -> blkno >= 10){
	  printf("[ %d : %d ", index, p -> blkno);
	}
	else{
	  printf("[ %d :  %d ", index, p -> blkno);
	}
      }
      */
      PrintState(p);
      printf("]\n");
      index++; 
    }
  }
}
void PrintHashLine(int hkey){
  int index = hkey * 4;
  for(buf *p = hash_head[hkey].hash_fp; p != &hash_head[hkey]; p = p -> hash_fp){
    printf("\t[ %d : %d ", index, p -> blkno);
    PrintState(p);
    printf("]");
    index++;
  }
}
void PrintFree(){
  int index = 0; 
  for(buf *p = f_head.free_fp; p != &f_head; p = p -> free_fp){
    index = SearchNum(p -> blkno);
    printf("\t[ %d : %d ", index, p -> blkno);
    PrintState(p);
    printf("]");
  }
}
Exemplo n.º 12
0
/* digest (up to) msglen bytes */
void Transform(hashState* ctx, 
	       const BitSequence *input, 
	       u32 msglen) { 
  int i, j;
  u8 temp1[ROWS][COLS1024], temp2[ROWS][COLS1024];

  /* digest one message block at the time */
  for (; msglen >= ctx->statesize; 
       msglen -= ctx->statesize, input += ctx->statesize) {
    /* store message block (m) in temp2, and xor of chaining (h) and
       message block in temp1 */
    for (i = 0; i < ROWS; i++) {
      for (j = 0; j < ctx->columns; j++) {
	temp1[i][j] = ctx->chaining[i][j]^input[j*ROWS+i];
	temp2[i][j] = input[j*ROWS+i];
      }
    }

#ifndef TURN_OFF_PRINTING
    printf("========================================\n\n");
    printf("Block Contents:\n");
    PrintState(ctx, temp2);
    printf("\n");
#endif

    P(ctx, temp1); /* P(h+m) */
    Q(ctx, temp2); /* Q(m) */

    /* xor P(h+m) and Q(m) onto chaining, yielding P(h+m)+Q(m)+h */
    for (i = 0; i < ROWS; i++) {
      for (j = 0; j < ctx->columns; j++) {
	ctx->chaining[i][j] ^= temp1[i][j]^temp2[i][j];
      }
    }
#ifndef TURN_OFF_PRINTING
    printf("P(h+m) + Q(m) + h =\n");
    PrintState(ctx, ctx->chaining);
    printf("\n\n");
#endif
    /* increment block counter */
    ctx->block_counter++;
  }
}
void PrintBufferOne(int index){
  int hkey = index % 4;
  buf *p = hash_head[hkey].hash_fp;
  for(int i = index / 4; i > 0; i++){
    p = p -> hash_fp;
  }
  printf("\t[ %d : %d ", index, p -> blkno);
  PrintState(p);
  printf("]");
}
void PrintHashLine(int hkey){
  int index = hkey * 3;
  for(buf *p = h_head[hkey].hash_fp; p != &h_head[hkey]; p = p -> hash_fp){
    //printf("\t[ %d : %d ", index, p -> blkno);
    PrintRoutine(p, index);
    PrintState(p);
    printf("]  ");
    index++;
  }
  printf("\n");
}
void PrintBufferOne(int index){
  int hkey = index / 3;
  buf *p = &h_head[hkey];
  for(int i = index % 3; i >= 0; i--){
    p = p -> hash_fp;
  }
  PrintRoutine(p, index);
  //printf("[ %d : %d ", index, p -> blkno);
  PrintState(p);
  printf("]\n");
}
Exemplo n.º 16
0
void StreamPower::Start()
{
	char fname[100];
	sprintf_s(fname, "erosion_initial.asc");
	PrintState(fname);

	time = 0;
	while (time < duration)
	{
		Step();
	}
}
void PrintBufferAll(){
  //printf("buf[n ...]\n");
  int index = 0;
  for(int i = 0; i < NHASH; i++){
    for(buf *p = hash_head[i].hash_fp; p != &hash_head[i]; p = p -> hash_fp){
      printf("\t[ %d : %d ", index, p -> blkno);
      PrintState(p);
      printf("]");
      index++; 
    }
  }
}
Exemplo n.º 18
0
static void
Key(unsigned char key, int x, int y)
{
   const GLfloat step = 3.0;
   (void) x;
   (void) y;
   switch (key) {
   case 'a':
   case ' ':
      Anim = !Anim;
      if (Anim)
         glutIdleFunc(Idle);
      else
         glutIdleFunc(NULL);
      break;
   case 'b':
      Blend = !Blend;
      break;
   case 's':
      Scale /= 1.1;
      break;
   case 'S':
      Scale *= 1.1;
      break;
   case 'f':
      Filter = (Filter + 1) % NUM_FILTERS;
      SetTexParams();
      break;      
   case 'r':
      Randomize();
      break;
#if TEST_CLAMP
   case 'c':
      Clamp = !Clamp;
      SetTexParams();
      break;
#endif
   case 'z':
      Zrot -= step;
      break;
   case 'Z':
      Zrot += step;
      break;
   case 27:
      glutDestroyWindow(Win);
      exit(0);
      break;
   }

   PrintState();

   glutPostRedisplay();
}
Exemplo n.º 19
0
int main(){
	char state = -2, stopped = 1; //bools
	char command[20];

	PrintState(state, stopped);
	while(scanf("%[^\n]%*c", command) != EOF){
		if(strcmp(command, "button_clicked") == 0){
			if(stopped == 1){
				if(state == -2){
					state = 1;
				}else if(state == -1){
					state = 1;
				}else if(state == 1){
					state = -1;
				}else if(state == 2){
					state = -1;
				}
				stopped = 0;
			}else{
				stopped = 1;
			}
		}else if(strcmp(command, "cycle_complete") == 0){
			if(stopped == 0){
				if(state == 1){
					state = 2;
				}else if(state == -1){
					state = -2;
				}
				stopped = 1;
			}
		}

		printf("\n");
		PrintState(state, stopped);
	}

	return 0;
}
void PrintHashAll(){
  printf("Hash[n ...]\n");
  int index = 0;
  for(int i = 0; i < NHASH; i++){
    printf("%d :", i);
    for(buf *p = hash_head[i].hash_fp; p != &hash_head[i]; p = p -> hash_fp){
      printf("\t[ %d : %d ", index, p -> blkno);
      PrintState(p);
      printf("]");
      index++; 
    }
    printf("\n");
  }
}
Exemplo n.º 21
0
void SolveCube2::MakeRandomCube(Cube *cube)
{
	
	//step 1
	MakeRandomCubeCore();
	PrintState();
	assert(solvable());	

	//step2
	assert(cube->n()==2);
	fill_corner_pointer(cube);
	GetColorData();
	corner2cube();
}
Exemplo n.º 22
0
Arquivo: Utils.c Projeto: zhshr/CS502
void my_Timer_Interrupt() {
	/*TODO:
	 * Get current time T
	 * Move everything with waketime before T from TimerQueue to ReadyQueue
	 * Get next item in TimerQueue
	 * Reset Timer
	 */
	PrintState();
	ReadyQueue_Lock("Timer Interrupt");
	TimerQueue_Lock("Timer Interrupt");

	currentTimer = 0;
	INT32 time = 0;
	time = my_GET_TIME_OF_DAY();
	debug(GREY, "Timer Queue, Current Time: %d", time);
	debug(YELLOW, "Timer Queue Lock in interrupt");

	if (!TimerQueueHead->Next) {
		debug(RED, "Bug in Timer Queue\n");
	} else {
		INT32 currentTime = my_GET_TIME_OF_DAY();
		if (TimerQueueHead->Next != NULL) {
			debug(GREY, "Timer Queue Item: %d, waketime %d",
					TimerQueueHead->Next->PCB->PID,
					TimerQueueHead->Next->WakeTime);
		} else {
			debug(RED, "Timer Item is NULL");
		}

		while (TimerQueueHead->Next != NULL
				&& TimerQueueHead->Next->WakeTime < currentTime) {
			//move it to the ready Q
			TimerQueueItem * temp = TimerQueue_Pop();
			debug(GREEN, "Move PID %d from Timer Q to Ready Q", temp->PCB->PID);
			if (temp != NULL) {
				ReadyQueue_Add(temp->PCB);
				Printer("Ready", temp->PCB->PID, FALSE);
			}
		}
	}
	if (TimerQueueHead->Next != NULL) {
		//reset Timer
		currentTimer = TimerQueueHead->Next->WakeTime;
		setTimer(TimerQueueHead->Next->WakeTime - time);
		debug(YELLOW, "reset timer to %d", currentTimer,
				TimerQueueHead->Next->WakeTime - time);
	}
	TimerQueue_Unlock("Timer Interrupt");
	ReadyQueue_Unlock("Timer Interrupt");
}
Exemplo n.º 23
0
/**
 * This program tests the RectInsert() functionality by calling
 * RectInsert() with various testdata and after each call comparing
 * the current state with a predefied set of expected states.
 */
int main(int argc, char **argv) {
    boolean current_state[STATE_WIDTH * STATE_HEIGHT];
    RectArea *root = NULL;
    int i = 0;
    int result = 0;

    printf("== Testing RectInsert() ==\n");

    // Run until there we find end of tests data
    while (rectinsert_test_data[i].description != NULL) {

        printf("Test #%d: %s\n", i + 1, rectinsert_test_data[i].description);
        RectInsert(&root, &rectinsert_test_data[i].new_rect);
        GetState(root, current_state);

        if (!StatesEqual(current_state, rectinsert_test_data[i].expected_state)) {
            printf("  FAILURE!\n");
            printf("  Current state:\n");
            PrintState(current_state);
                
            printf("  Expected state:\n");
            PrintState(rectinsert_test_data[i].expected_state);

            // Just set to failure and keep going...
            result = -1;
        }
        else {
            printf("  PASS\n");
        }

        // Run next test
        printf("\n");
        i++;
    }
  
    return result;
}
void AMXStackFramePrinter::Print(const AMXStackFrame &frame) {
  PrintReturnAddress(frame);
  stream_ << " in ";

  PrintCallerNameAndArguments(frame);

  if (debug_info_.IsLoaded() && UsesAutomata(frame)) {
    stream_ << " ";
    PrintState(frame);
  }

  if (debug_info_.IsLoaded() && frame.return_address() != 0) {
    stream_ << " at ";
    PrintSourceLocation(frame.return_address());
  }
}
Exemplo n.º 25
0
void SolveCube2::GetData(Cube *cube)//kind of color less then 32
{
	assert(cube->n()==2);
	
	fill_corner_pointer(cube);
	GetColorData();
	for(int i=0;i<8;i++)
	{
		corner_permutation_[i]=get_corner_id_from_cube(*corner_pointer_[i][0],*corner_pointer_[i][1],*corner_pointer_[i][2]);
	}
	for(int i=0;i<8;i++)
	{
		corner_twist_[i]=get_corner_twist_from_cube(*corner_pointer_[i][0],*corner_pointer_[i][1],*corner_pointer_[i][2]);
	}
	
	PrintState();
	assert(solvable());
}
Exemplo n.º 26
0
State_t Striker::RunState(State_t cur_state)
{
#ifdef DEBUG_STRIKER_STATE_MACHINE
	cout << "[Striker]:current state [" << PrintState(cur_state) << "] time: "
			<< GetCurrentTime() << "\n";
#endif

	switch (cur_state)
	{
	case STATE_INITIALIZE:
		return DoStateInitialize();
	case STATE_LOOK_FOR_THE_BALL:
		return DoStateLookForTheBall();
	case STATE_GO_TO_THE_BALL:
		return DoStateGoToTheBall();
	case STATE_SHOULD_I_GO_TO_THE_BALL:
		return DoStateShouldIGoToTheBall();
	case STATE_POSITION_YOURSELF:
		return DoStatePositionYourself();
	case STATE_IS_IT_POSSIBLE_TO_KICK:
		return DoStateIsItPossibleToKick();
	case STATE_KICK:
		return DoStateKick();
	case STATE_DRIBBLE:
		//return DoStateDribble();
		return DoStateKick();
	case STATE_PASS_AWAY:
		return DoStatePassAway();
	case STATE_HANDLE_GAME_CONTROLLER_STATES:
		return DoStateHandleGameControllerStates();
	case STATE_GAME_CONTROLLER_INITIAL:
		return DoStateGameControllerInitial();
	case STATE_GAME_CONTROLLER_SET:
		return DoStateGameControllerSet();
	case STATE_GAME_CONTROLLER_READY:
		return DoStateGameControllerReady();
	case STATE_GAME_CONTROLLER_PLAYING:
		return DoStateGameControllerPlaying();
	case STATE_GAME_CONTROLLER_FINISHED:
		return DoStateGameControllerFinished();
	default:
		throw "[Striker::RunState]: Unknown state\n";
	}
}
Exemplo n.º 27
0
/* hash bit sequence */
HashReturn Hash(int hashbitlen,
		const BitSequence* data, 
		DataLength databitlen,
		BitSequence* hashval) {
  HashReturn ret;
  hashState ctx;

  /* initialise */
  if ((ret = Init(&ctx, hashbitlen)))
    return ret;

#ifndef TURN_OFF_PRINTING
  char str[1+(databitlen+7)/8];
  str[(databitlen+7)/8] = 0;
  memcpy(str, data, (databitlen+7)/8);
  printf("########################################\n\n");
  printf("Groestl\n");
  printf("  Message Digest Length = %d\n\n", hashbitlen);
  printf("########################################\n\n\n");
  printf("%d-Block Message Sample\n\n", 
	 (int)(1+(databitlen+8*LENGTHFIELDLEN)/(8*ctx.statesize)));
  printf("  Input Message = \"%s\"\n\n", str);
  printf("========================================\n\n");
  printf("Initial state:\n");
  PrintState(&ctx, ctx.chaining);
  printf("\n");
#endif

  /* process message */
  if ((ret = Update(&ctx, data, databitlen)))
    return ret;

  /* finalise */
  ret = Final(&ctx, hashval);

#ifndef TURN_OFF_PRINTING
  printf("\n----------------------------------------\n\n");
  printf("Message Digest is\n");
  PrintHash(hashval, hashbitlen);
#endif

  return ret;
}
Exemplo n.º 28
0
int
main(int argc, char *argv[])
{
   glutInitWindowSize(700, 700);
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
   Win = glutCreateWindow(argv[0]);
   glewInit();
   glutReshapeFunc(Reshape);
   glutKeyboardFunc(Key);
   glutSpecialFunc(SpecialKey);
   glutDisplayFunc(Draw);
   if (Anim)
      glutIdleFunc(Idle);
   Init(argc, (const char **) argv);
   Usage();
   PrintState();
   glutMainLoop();
   return 0;
}
Exemplo n.º 29
0
void StreamPower::Step()
{

	int i, j, t;
	double max, deltah;
	char fname[100];

	//perform landsliding
	for (j = 0; j < lattice_size_y; j++)
	{
		for (i = 0; i < lattice_size_x; i++)
		{
			topovec[j * lattice_size_x + i] = topo[i][j];
		}
	}
	topovecind = Indexx(topovec);



	// todo
	for (int t = 0; t < lattice_size_x * lattice_size_y; t++)
	{
		i = topovecind[t] % lattice_size_x;
		j = topovecind[t] / lattice_size_x;
		Avalanche(i, j);
	}

	for (j = 0; j < lattice_size_y; j++)
	{
		for (i = 0; i < lattice_size_x; i++)
		{
			topoold[i][j] = topo[i][j];
		}
	}

	Flood();

	for (j = 0; j < lattice_size_y; j++)
	{
		for (i = 0; i < lattice_size_x; i++)
		{
			flow[i][j] = 1;
			topovec[j * lattice_size_x + i] = topo[i][j];
		}
	}

	topovecind = Indexx(topovec);

	for (t = lattice_size_x * lattice_size_y - 1; t >= 0; t--)
	{
		i = topovecind[t] % lattice_size_x;
		j = topovecind[t] / lattice_size_x;
		MFDFlowRoute(i, j);
	}


	// perform uplift
	for (i = 1; i < lattice_size_x - 1; i++)
	{
		for (j = 1; j < lattice_size_y - 1; j++)
		{
			topo[i][j] += U[i][j] * timestep; // u(i,j)
			topoold[i][j] += U[i][j] * timestep;
		}
	}

	//perform upwind erosion
	max = 0;
	for (i = 1; i < lattice_size_x - 1; i++)
	{
		for (j = 1; j < lattice_size_y - 1; j++)
		{
			CalculateAlongChannelSlope(i, j);
			deltah = timestep * K * sqrt(flow[i][j]) * deltax * slope[i][j];

			//std::cout << i << ", " << j << ", time: " << time << ", dh: " << deltah << ", " << "ts: " << timestep << ", K:" << K << ", sqrtflow " << sqrt(flow[i][j]) << ", dx:" << deltax << ", slope: " << slope[i][j] << "\n";
			//exit(0);

			topo[i][j] -= deltah;

			if (topo[i][j] < 0)
			{
				topo[i][j] = 0;
			}
			if (K * sqrt(flow[i][j]) * deltax > max)
			{
				max = K * sqrt(flow[i][j]) * deltax;
			}
		}
	}



	time += timestep;
	if (max > 0.3 * deltax / timestep)
	{
		time -= timestep;
		timestep /= 2.0;
		//std::cout << "First time modification" << "\n";
		for (i = 1; i < lattice_size_x - 1; i++)
		{
			for (j = 1; j < lattice_size_y - 1; j++)
			{
				topo[i][j] = topoold[i][j] - U[i][j] * timestep;
			}
		}
	}
	else
	{
		if (max < 0.03 * deltax / timestep)
		{
			timestep *= 1.2;
			//std::cout << "Second time modification" << "\n";
		}
		for (j = 0; j < lattice_size_y; j++)
		{
			for (i = 0; i < lattice_size_x; i++)
			{
				topoold[i][j] = topo[i][j];
			}

		}

	}
	//if (time > printinterval)
	//{
	sprintf_s(fname, "erosion_%f.asc", time);
	PrintState(fname);
	//printinterval += printstep;
	//}
	std::cout << "Time: " << time << std::endl;
}
Exemplo n.º 30
0
bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize)
{
  int MaxOpCount=25000000;
  VM_PreparedCommand *Cmd=PreparedCode;
  while (1)
  {
    unsigned int *Op1=GetOperand(&Cmd->Op1);
    unsigned int *Op2=GetOperand(&Cmd->Op2);
    switch(Cmd->OpCode)
    {
#ifndef NORARVM
      case VM_MOV:
        SET_VALUE(Cmd->ByteMode,Op1,GET_VALUE(Cmd->ByteMode,Op2));
        break;
#ifdef VM_OPTIMIZE
      case VM_MOVB:
        SET_VALUE(true,Op1,GET_VALUE(true,Op2));
        break;
      case VM_MOVD:
        SET_VALUE(false,Op1,GET_VALUE(false,Op2));
        break;
#endif
      case VM_CMP:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int Result=UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS);
        }
        break;
#ifdef VM_OPTIMIZE
      case VM_CMPB:
        {
          unsigned int Value1=GET_VALUE(true,Op1);
          unsigned int Result=UINT32(Value1-GET_VALUE(true,Op2));
          Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS);
        }
        break;
      case VM_CMPD:
        {
          unsigned int Value1=GET_VALUE(false,Op1);
          unsigned int Result=UINT32(Value1-GET_VALUE(false,Op2));
          Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS);
        }
        break;
#endif
      case VM_ADD:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int Result=UINT32(Value1+GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:(Result<Value1)|(Result&VM_FS);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
#ifdef VM_OPTIMIZE
      case VM_ADDB:
        SET_VALUE(true,Op1,GET_VALUE(true,Op1)+GET_VALUE(true,Op2));
        break;
      case VM_ADDD:
        SET_VALUE(false,Op1,GET_VALUE(false,Op1)+GET_VALUE(false,Op2));
        break;
#endif
      case VM_SUB:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int Result=UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
#ifdef VM_OPTIMIZE
      case VM_SUBB:
        SET_VALUE(true,Op1,GET_VALUE(true,Op1)-GET_VALUE(true,Op2));
        break;
      case VM_SUBD:
        SET_VALUE(false,Op1,GET_VALUE(false,Op1)-GET_VALUE(false,Op2));
        break;
#endif
      case VM_JZ:
        if ((Flags & VM_FZ)!=0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_JNZ:
        if ((Flags & VM_FZ)==0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_INC:
        {
          unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)+1);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
          Flags=Result==0 ? VM_FZ:Result&VM_FS;
        }
        break;
#ifdef VM_OPTIMIZE
      case VM_INCB:
        SET_VALUE(true,Op1,GET_VALUE(true,Op1)+1);
        break;
      case VM_INCD:
        SET_VALUE(false,Op1,GET_VALUE(false,Op1)+1);
        break;
#endif
      case VM_DEC:
        {
          unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)-1);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
          Flags=Result==0 ? VM_FZ:Result&VM_FS;
        }
        break;
#ifdef VM_OPTIMIZE
      case VM_DECB:
        SET_VALUE(true,Op1,GET_VALUE(true,Op1)-1);
        break;
      case VM_DECD:
        SET_VALUE(false,Op1,GET_VALUE(false,Op1)-1);
        break;
#endif
      case VM_JMP:
        SET_IP(GET_VALUE(false,Op1));
        continue;
      case VM_XOR:
        {
          unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)^GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:Result&VM_FS;
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_AND:
        {
          unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)&GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:Result&VM_FS;
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_OR:
        {
          unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)|GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:Result&VM_FS;
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_TEST:
        {
          unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)&GET_VALUE(Cmd->ByteMode,Op2));
          Flags=Result==0 ? VM_FZ:Result&VM_FS;
        }
        break;
      case VM_JS:
        if ((Flags & VM_FS)!=0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_JNS:
        if ((Flags & VM_FS)==0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_JB:
        if ((Flags & VM_FC)!=0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_JBE:
        if ((Flags & (VM_FC|VM_FZ))!=0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_JA:
        if ((Flags & (VM_FC|VM_FZ))==0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_JAE:
        if ((Flags & VM_FC)==0)
        {
          SET_IP(GET_VALUE(false,Op1));
          continue;
        }
        break;
      case VM_PUSH:
        R[7]-=4;
        SET_VALUE(false,(unsigned int *)&Mem[R[7]&VM_MEMMASK],GET_VALUE(false,Op1));
        break;
      case VM_POP:
        SET_VALUE(false,Op1,GET_VALUE(false,(unsigned int *)&Mem[R[7] & VM_MEMMASK]));
        R[7]+=4;
        break;
      case VM_CALL:
        R[7]-=4;
        SET_VALUE(false,(unsigned int *)&Mem[R[7]&VM_MEMMASK],Cmd-PreparedCode+1);
        SET_IP(GET_VALUE(false,Op1));
        continue;
      case VM_NOT:
        SET_VALUE(Cmd->ByteMode,Op1,~GET_VALUE(Cmd->ByteMode,Op1));
        break;
      case VM_SHL:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int Value2=GET_VALUE(Cmd->ByteMode,Op2);
          unsigned int Result=UINT32(Value1<<Value2);
          Flags=(Result==0 ? VM_FZ:(Result&VM_FS))|((Value1<<(Value2-1))&0x80000000 ? VM_FC:0);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_SHR:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int Value2=GET_VALUE(Cmd->ByteMode,Op2);
          unsigned int Result=UINT32(Value1>>Value2);
          Flags=(Result==0 ? VM_FZ:(Result&VM_FS))|((Value1>>(Value2-1))&VM_FC);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_SAR:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int Value2=GET_VALUE(Cmd->ByteMode,Op2);
          unsigned int Result=UINT32(((int)Value1)>>Value2);
          Flags=(Result==0 ? VM_FZ:(Result&VM_FS))|((Value1>>(Value2-1))&VM_FC);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_NEG:
        {
          unsigned int Result=UINT32(-GET_VALUE(Cmd->ByteMode,Op1));
          Flags=Result==0 ? VM_FZ:VM_FC|(Result&VM_FS);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
#ifdef VM_OPTIMIZE
      case VM_NEGB:
        SET_VALUE(true,Op1,-GET_VALUE(true,Op1));
        break;
      case VM_NEGD:
        SET_VALUE(false,Op1,-GET_VALUE(false,Op1));
        break;
#endif
      case VM_PUSHA:
        {
          const int RegCount=sizeof(R)/sizeof(R[0]);
          for (int I=0,SP=R[7]-4;I<RegCount;I++,SP-=4)
            SET_VALUE(false,(unsigned int *)&Mem[SP & VM_MEMMASK],R[I]);
          R[7]-=RegCount*4;
        }
        break;
      case VM_POPA:
        {
          const int RegCount=sizeof(R)/sizeof(R[0]);
          for (unsigned int I=0,SP=R[7];I<RegCount;I++,SP+=4)
            R[7-I]=GET_VALUE(false,(unsigned int *)&Mem[SP & VM_MEMMASK]);
        }
        break;
      case VM_PUSHF:
        R[7]-=4;
        SET_VALUE(false,(unsigned int *)&Mem[R[7]&VM_MEMMASK],Flags);
        break;
      case VM_POPF:
        Flags=GET_VALUE(false,(unsigned int *)&Mem[R[7] & VM_MEMMASK]);
        R[7]+=4;
        break;
      case VM_MOVZX:
        SET_VALUE(false,Op1,GET_VALUE(true,Op2));
        break;
      case VM_MOVSX:
        SET_VALUE(false,Op1,(signed char)GET_VALUE(true,Op2));
        break;
      case VM_XCHG:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          SET_VALUE(Cmd->ByteMode,Op1,GET_VALUE(Cmd->ByteMode,Op2));
          SET_VALUE(Cmd->ByteMode,Op2,Value1);
        }
        break;
      case VM_MUL:
        {
          unsigned int Result=GET_VALUE(Cmd->ByteMode,Op1)*GET_VALUE(Cmd->ByteMode,Op2);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_DIV:
        {
          unsigned int Divider=GET_VALUE(Cmd->ByteMode,Op2);
          if (Divider!=0)
          {
            unsigned int Result=GET_VALUE(Cmd->ByteMode,Op1)/Divider;
            SET_VALUE(Cmd->ByteMode,Op1,Result);
          }
        }
        break;
      case VM_ADC:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int FC=(Flags&VM_FC);
          unsigned int Result=UINT32(Value1+GET_VALUE(Cmd->ByteMode,Op2)+FC);
          Flags=Result==0 ? VM_FZ:(Result<Value1 || Result==Value1 && FC)|(Result&VM_FS);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
      case VM_SBB:
        {
          unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1);
          unsigned int FC=(Flags&VM_FC);
          unsigned int Result=UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2)-FC);
          Flags=Result==0 ? VM_FZ:(Result>Value1 || Result==Value1 && FC)|(Result&VM_FS);
          SET_VALUE(Cmd->ByteMode,Op1,Result);
        }
        break;
#endif
      case VM_RET:
        if (R[7]>=VM_MEMSIZE)
          return(true);
        SET_IP(GET_VALUE(false,(unsigned int *)&Mem[R[7] & VM_MEMMASK]));
        R[7]+=4;
        continue;
#ifdef VM_STANDARDFILTERS
      case VM_STANDARD:
        ExecuteStandardFilter((VM_StandardFilters)Cmd->Op1.Data);
        break;
#endif
      case VM_PRINT:
#ifdef DEBUG
        PrintState(Cmd-PreparedCode);
#endif
        break;
    }
    Cmd++;
    --MaxOpCount;
  }
}