Ejemplo n.º 1
0
void MainMenu::onEvent(Event e)
{
	if(strcmp(e.getID(), m_pStartSPButton.getName())== 0)
	{
		Event load_state("changestate", 2);
		load_state[0] = EventArg("game");
		load_state[1] = EventArg("customgame"); 

		postEvent(load_state);
	}
	else if(strcmp(e.getID(), m_pEditorButton.getName()) == 0)
	{		
		Event load_state("changestate", 2);
		load_state[0] = EventArg("editor");
		load_state[1] = EventArg("customgame"); 

		postEvent(load_state);
	}
	else if(strcmp(e.getID(), m_pQuitButton.getName()) == 0)
	{
		Event quit("quit", 0);

		postEvent(quit);
	}
}
Ejemplo n.º 2
0
bool app_viewer::on_key(int key) {
	switch (key) {
	case Qt::Key_Escape:
		get_wnd()->close();
		break;
	case Qt::Key_Space:
		if (!is_polygon_draw_state)
			return on_polygon_drawing_start();
		else
			return on_polygon_drawing_stop();
	case Qt::Key_H:
		if (!is_hole_draw_state)
			return on_hole_drawing_start();
		else
			return on_hole_drawing_stop();
	case Qt::Key_Return:
		return on_triangulate();
		break;
	case Qt::Key_S:
		return save_state();

	case Qt::Key_L:
		return load_state();
	}
	return false;
}
Ejemplo n.º 3
0
/* The cannonball sim's integration job */
int cannon_integ( CANNON* C ) {

    int ipass;
    /* LOAD THE POSITION AND VELOCITY STATES */
    load_state(
        &C->pos[0], &C->pos[1] ,
        &C->vel[0], &C->vel[1] ,
        &C->time,
        NULL
    );
    /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
    load_deriv(
        &C->vel[0], &C->vel[1] ,
        &C->acc[0], &C->acc[1] ,
        &C->timeRate,
        NULL
    );
    /* CALL THE TRICK INTEGRATION SERVICE */
    ipass = integrate();
    /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
    unload_state(
        &C->pos[0], &C->pos[1] ,
        &C->vel[0], &C->vel[1] ,
        &C->time,
        NULL
    );
    /* RETURN */
    return( ipass );
}
Ejemplo n.º 4
0
/*!
 * @brief Bouncing ball state Trick compliant integration routine.
 *
 * This routine performs the following:
 *
 *   - Loads position into the integrator states.
 *   - Loads velocity into the integrator states.
 *   - Loads velocity into the integrator derivatives.
 *   - Loads acceleration into the integrator derivatives.
 *   - Calls the Trick integration service.
 *   - Unloads the propagated position and velocity from the integrator states.
 *
 * @job_class{ integration }
 *
 * @return Returns the Trick integration pass for the selected integration method.
 * @param [inout] state Ball EOM state parameters.
 */
int bounce_state_integ( /* RETURN: -- Integration multi-step id */
  BounceState * state ) /* INOUT:  -- Bounce EOM state parameters */
{

   int ipass;

   /* LOAD THE POSITION AND VELOCITY STATES */
   load_state(
      &state->position,
      &state->velocity,
      NULL
   );

   /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
   load_deriv(
      &state->velocity,
      &state->acceleration,
      NULL
   );

   /* CALL THE TRICK INTEGRATION SERVICE */
   ipass = integrate();

   /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
   unload_state(
      &state->position,
      &state->velocity,
      NULL
   );

   /* RETURN */
   return( ipass );
}
Ejemplo n.º 5
0
int sched_integ(  /* RETURN: -- Always return zero */
  SCHEDULE *S )   /* INOUT:  -- Schedule struct */
{

    int ipass;

    /* LOAD THE POSITION AND VELOCITY STATES */
    load_state(
        &S->pos ,
        &S->vel ,
        NULL
    );

    /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
    load_deriv(
        &S->vel ,
        &S->acc ,
        NULL
    );

    /* CALL THE TRICK INTEGRATION SERVICE */
    ipass = integrate();

    /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
    unload_state(
        &S->pos ,
        &S->vel ,
        NULL
    );

    /* RETURN */
    return( ipass );
}
Ejemplo n.º 6
0
static void event_load_auto_state(void)
{
   bool ret;
   char msg[PATH_MAX_LENGTH]                 = {0};
   char savestate_name_auto[PATH_MAX_LENGTH] = {0};
   settings_t *settings = config_get_ptr();
   global_t   *global   = global_get_ptr();

#ifdef HAVE_NETPLAY
   if (global->netplay_enable && !global->netplay_is_spectate)
      return;
#endif

   if (!settings->savestate_auto_load)
      return;

   fill_pathname_noext(savestate_name_auto, global->savestate_name,
         ".auto", sizeof(savestate_name_auto));

   if (!path_file_exists(savestate_name_auto))
      return;

   ret = load_state(savestate_name_auto);

   RARCH_LOG("Found auto savestate in: %s\n", savestate_name_auto);

   snprintf(msg, sizeof(msg), "Auto-loading savestate from \"%s\" %s.",
         savestate_name_auto, ret ? "succeeded" : "failed");
   rarch_main_msg_queue_push(msg, 1, 180, false);
   RARCH_LOG("%s\n", msg);
}
Ejemplo n.º 7
0
// Runs from emulation thread
void handle_ui_keys() {
	SDL_LockMutex(event_lock);

	if (keys[SDL_SCANCODE_ESCAPE])
		exit(0);


	if (keys[SDL_SCANCODE_F3]) {
		if (!cc_held) { corrupt_chance += 0x1000; printf("New corrupt chance is %u\n", corrupt_chance); }
		cc_held = 1; }
	else if (keys[SDL_SCANCODE_F4]) {
		if (!cc_held) { corrupt_chance -= 0x1000; printf("New corrupt chance is %u\n", corrupt_chance); }
		cc_held = 1; }
	else cc_held = 0;

	if (keys[SDL_SCANCODE_F5])
		save_state();
	else if (keys[SDL_SCANCODE_F8])
		load_state();

	handle_rewind(keys[SDL_SCANCODE_BACKSPACE]);

	if (reset_pushed)
		soft_reset();

	SDL_UnlockMutex(event_lock);
}
Ejemplo n.º 8
0
bool GONG_CORE_PREFIX(retro_unserialize)(const void *data, size_t size)
{
   if (size != STATE_SIZE)
      return false;

   load_state(data, size);
   return true;
}
Ejemplo n.º 9
0
 void menu_load_state()
 {
   if(!first_load)
   {
     load_state(current_savestate_filename);
     return_value = 1;
     repeat = 0;
   }
 }
Ejemplo n.º 10
0
void permutation(WORDSIZE* state){
    WORDSIZE a, b, c, d;
    unsigned int index;
    load_state(state, a, b, c, d);    
    for (index = 0; index < ROUNDS; index++){
        a ^= index;
        a ^= choice(f(b), f(c), f(d)); b ^= choice(f(c), f(d), f(a));
        c ^= choice(f(d), f(a), f(b)); d ^= choice(f(a), f(b), f(c));}
    store_state(state, a, b, c, d);}
Ejemplo n.º 11
0
void new_game(void) {
	char c = 0;
	cancel_software_timer(foodTimerNum);
	cancel_software_timer(ratsTimerNum);
	empty_display();

	//wait for space
	while(c != ' ' && c != 'l' && c != 'L'){
		if(input_available())
			c = fgetc(stdin);

		if(c == 'M' || c == 'm'){
			toggle_sound();
			display_sound_status();
			c = 0;
		}
	}
	
	init_display();
	
	if(c == 'l' || c == 'L'){
		if(load_state())
			render_board();
		else {
			/* Initialise internal representations. */
			init_board();
			init_score();
		}
	}
	else {
		/* Initialise internal representations. */
		init_board();
		init_score();
	}
	clear_terminal();

	//Place scores
	update_score();

	//place sound status
	display_sound_status();

	show_instruction(PLAYING);

	/* Make food blink 5 times a second. We should call blink_food
	** 10 times a second which is 100ms
	*/
	foodTimerNum = execute_function_periodically(BLINKRATE, blink_food);
	ratsTimerNum = execute_function_periodically(RATSPEED, move_rats);

	/* Debug *
	move_cursor(0, TITLEY-1);
	printf_P(PSTR("new_game %u"), get_score());
	wait_for(1000);
	//*/
}
Ejemplo n.º 12
0
blargg_err_t Nes_Emu::load_state( Auto_File_Reader in )
{
    Nes_State* state = BLARGG_NEW Nes_State;
    CHECK_ALLOC( state );
    blargg_err_t err = state->read( in );
    if ( !err )
        load_state( *state );
    delete state;
    return err;
}
Ejemplo n.º 13
0
/* *********************************************************************
    Returns the best action index from the set of possible actions
 ******************************************************************** */
Action SearchAgent::agent_step_cb(  const IntMatrix* screen_matrix, 
                                    const IntVect* console_ram, 
									int frame_number){

    /*Action special_action = PlayerAgent::agent_step(screen_matrix, console_ram,
													frame_number);
    if (special_action != UNDEFINED) {
    	action_idx = -1;
        return special_action;  // We are resettign or in a delay 
    }*/
    i_frame_counter = frame_number;
    pm_curr_screen_matrix = screen_matrix; 
    pv_curr_console_ram = console_ram;  

    
	i_curr_num_sim_steps = 0;
	if (i_frame_counter >= i_next_act_frame) {
		// Run a new simulation to find the next action
		i_next_act_frame = i_frame_counter + i_sim_steps_per_node;
		str_curr_state = save_state();
		if (str_search_method == "fulltree") {
			p_search_tree->clear();	// The current full-tree implementation
									// does not support rebuilding the tree
		}
		cout << "Frame: " << i_frame_counter << ", ";
		if (p_search_tree->is_built) {
			// Re-use the old tree
			p_search_tree->move_to_best_sub_branch();
			assert (p_search_tree->get_root_frame_number() == i_frame_counter);
			p_search_tree->update_tree();
			cout << "Tree Updated: ";
		} else {
			// Build a new Search-Tree
			p_search_tree->clear(); 
			p_search_tree->build(str_curr_state, i_frame_counter);
			cout << "Tree Re-Constructed: ";
		}
		cout << "Reward: " << f_episode_reward << endl;
		action_idx = p_search_tree->get_best_action_index();
		e_curr_action = (*(p_game_settings->pv_possible_actions))[action_idx];
		cout << " Root Value = " << p_search_tree->get_root_value();  
		cout << " - Deepest Node Frame: " 
			 << p_search_tree->i_deepest_node_frame_num << endl;
		load_state(str_curr_state);
		// deal with the bloody bug, where the screen doesnt get updated
		// after restoring the state for one turn. This *hack* allows 
		// basically skips exporting teh screen for one turn
		i_skip_export_on_frame = i_frame_counter + 1;


	}
	return e_curr_action;
}
Ejemplo n.º 14
0
/* ***************************************************************************
 *  This is a temporary method, used for preparing a demo video.
 *  It should be pretty much ignored!
 * ***************************************************************************/
Action SearchAgent::tmp_prepare_demo_vid(void) {
	if (i_frame_counter < 1250) {
		return PLAYER_A_NOOP;
	}
	if (i_frame_counter < 1300) {
		return PLAYER_A_DOWN;
	}
	str_curr_state = save_state();
	// initilize the screen_matrix
	if (pm_sim_scr_matrix == NULL) {
		pm_sim_scr_matrix = new IntMatrix;
		assert(i_screen_height > 0);
		assert(i_screen_width > 0);
		for (int i = 0; i < i_screen_height; i++) {
			IntVect row;
			for (int j = 0; j < i_screen_width; j++) {
				row.push_back(-1);
			}
			pm_sim_scr_matrix->push_back(row);
		}
	}
	char buffer [50];
	ostringstream filename;
	MediaSource& mediasrc = p_osystem->console().mediaSource();
	for (int a = 0; a < i_num_actions; a++) {
		load_state(str_curr_state);
		GameController::apply_action(p_sim_event_obj, PLAYER_A_NOOP, PLAYER_B_NOOP);
		p_osystem->myTimingInfo.start = p_osystem->getTicks();
		mediasrc.update(); 
		Action curr_act = (*p_game_settings->pv_possible_actions)[a];
		filename.str("");
		filename << "action_" << action_to_string(curr_act)  << "_00.png";
		p_osystem->p_export_screen->save_png(pm_sim_scr_matrix, filename.str());
		for (int i = 0; i < 15; i++) {
			GameController::apply_action(p_sim_event_obj, curr_act, PLAYER_B_NOOP);
			p_osystem->myTimingInfo.start = p_osystem->getTicks();
			mediasrc.update(); 
			copy_simulated_framebuffer();
			sprintf (buffer, "%02d", i + 1);
			filename.str("");
			filename << "action_" << action_to_string(curr_act) << "_" 
					 << buffer << ".png";
			p_osystem->p_export_screen->save_png(pm_sim_scr_matrix, filename.str());
		}
	}
	end_game();
	return UNDEFINED;
	
}
Ejemplo n.º 15
0
 void menu_load_state_file()
 {
   u8 *file_ext[] = { ".svs", NULL };
   u8 load_filename[512];
   if(load_file(file_ext, load_filename) != -1)
   {
     load_state(load_filename);
     return_value = 1;
     repeat = 0;
   }
   else
   {
     choose_menu(current_menu);
   }
 }
Ejemplo n.º 16
0
int main(){
	BYTE i=0;
	char euro[10];
	load_items();
	load_state();
	for (i=0; i < status.num_items; ++i) {
		cprintf("%x: %s (%s, %d mal)\n",
			i, status.status[i].item_name, format_euro(euro, 9, status.status[i].price),
			status.status[i].times_sold);
		status.status[i].times_sold += 10;
	}

	save_state();
	load_items();
	load_state();
	for (i=0; i < status.num_items; ++i) {
		cprintf("%x: %s (%s, %d mal)\n",
			i, status.status[i].item_name, format_euro(euro, 9, status.status[i].price),
			status.status[i].times_sold);
	}
	
	cprintf("strlen(%s)==%d\n", status.status[1].item_name, strlen(status.status[1].item_name));
	cprintf("%d %d %d\n", status.status[1].item_name[0], '\r', '\n');
}
Ejemplo n.º 17
0
static inline void state_handling(int save,int load) {
	if (save) {
		//if (conf.sound) SDL_LockAudio();
		save_state(conf.game, save - 1);
		//if (conf.sound) SDL_UnlockAudio();
		reset_frame_skip();
	}
	if (load) {
		//if (conf.sound) SDL_LockAudio();
		load_state(conf.game, load - 1);
		//if (conf.sound) SDL_UnlockAudio();
		reset_frame_skip();
	}
	pending_load_state = pending_save_state = 0;
}
Ejemplo n.º 18
0
int cannon_integ_aero(
  CANNON_AERO* C)
{

    int ipass;

    /* GET SHORTHAND NOTATION FOR DATA STRUCTURES */
    CANNON_AERO_OUT *CAO = &(C->out) ;

    /* LOAD THE POSITION AND VELOCITY STATES */
    load_state(
        &CAO->position[0] ,
        &CAO->position[1] ,
        &CAO->position[2] ,
        &CAO->velocity[0] ,
        &CAO->velocity[1] ,
        &CAO->velocity[2] ,
        NULL
    );

    /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
    load_deriv(
        &CAO->velocity[0] ,
        &CAO->velocity[1] ,
        &CAO->velocity[2] ,
        &CAO->acceleration[0] ,
        &CAO->acceleration[1] ,
        &CAO->acceleration[2] ,
        NULL
    );

    /* CALL THE TRICK INTEGRATION SERVICE */
    ipass = integrate();

    /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
    unload_state(
        &CAO->position[0] ,
        &CAO->position[1] ,
        &CAO->position[2] ,
        &CAO->velocity[0] ,
        &CAO->velocity[1] ,
        &CAO->velocity[2] ,
        NULL
    );

    /* RETURN */
    return( ipass );
}
Ejemplo n.º 19
0
/**
 * event_load_state
 * @path            : Path to state.
 * @s               : Message.
 * @len             : Size of @s.
 *
 * Loads a state with path being @path.
 **/
static void event_load_state(const char *path, char *s, size_t len)
{
   settings_t *settings = config_get_ptr();

   if (!load_state(path))
   {
      snprintf(s, len, "Failed to load state from \"%s\".", path);
      return;

   }

   if (settings->state_slot < 0)
      snprintf(s, len, "Loaded state from slot #-1 (auto).");
   else
      snprintf(s, len, "Loaded state from slot #%d.", settings->state_slot);
}
Ejemplo n.º 20
0
Archivo: emu.c Proyecto: gillotte/gxgeo
static inline void state_handling(save,load) {
#if 0 /* NOSTATE */
    if (save) {
        if (conf.sound) SDL_LockAudio();
        save_state(conf.game,save-1);
        if (conf.sound) SDL_UnlockAudio();
        reset_frame_skip();
    }
    if (load) {
        if (conf.sound) SDL_LockAudio();
        load_state(conf.game,load-1);
        if (conf.sound) SDL_UnlockAudio();
        reset_frame_skip();
    }
    pending_load_state=pending_save_state=0;
#endif
}
Ejemplo n.º 21
0
/**
 * event_load_state
 * @path            : Path to state.
 * @s               : Message.
 * @len             : Size of @s.
 *
 * Loads a state with path being @path.
 **/
static void event_load_state(const char *path, char *s, size_t len)
{
   settings_t *settings = config_get_ptr();

   if (!load_state(path))
   {
      snprintf(s, len, "%s \"%s\".",
            msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE),
            path);
      return;
   }

   if (settings->state_slot < 0)
      snprintf(s, len, "%s #-1 (auto).", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT));
   else
      snprintf(s, len, "%s #%d.", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT),
            settings->state_slot);
}
Ejemplo n.º 22
0
int VehicleOne::state_integ() {
    int integration_step;

    load_state(
                &heading,
                &headingRate,
                &position[0],
                &position[1],
                &velocity[0],
                &velocity[1],
                (double*)0
              );

    load_deriv(
                &headingRate,
                &headingAccel,
                &velocity[0],
                &velocity[1],
                &acceleration[0],
                &acceleration[1],
                (double*)0
              );

    integration_step = integrate();

    unload_state(
                &heading,
                &headingRate,
                &position[0],
                &position[1],
                &velocity[0],
                &velocity[1],
                (double*)0
              );

    if (!integration_step) {
        if (heading < -PI) heading +=  2*PI;
        if (heading >  PI) heading += -2*PI;
    }

    return(integration_step);

}
Ejemplo n.º 23
0
/* ENTRY POINT */
int ball_state_integ( /* RETURN: -- Integration multi-step id */
  BSTATE *S )         /* INOUT:  -- Ball EOM state parameters */
{

    int ipass;

    /* GET SHORTHAND NOTATION FOR DATA STRUCTURES */
    BSTATE_OUT *SO = &(S->output) ;

    /* LOAD THE POSITION AND VELOCITY STATES */
    load_state(
        &SO->position[0] ,
        &SO->position[1] ,
        &SO->velocity[0] ,
        &SO->velocity[1] ,
        NULL
    );

    /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
    load_deriv(
        &SO->velocity[0] ,
        &SO->velocity[1] ,
        &SO->acceleration[0] ,
        &SO->acceleration[1] ,
        NULL
    );

    /* CALL THE TRICK INTEGRATION SERVICE */
    ipass = integrate();

    /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
    unload_state(
        &SO->position[0] ,
        &SO->position[1] ,
        &SO->velocity[0] ,
        &SO->velocity[1] ,
        NULL
    );

    /* RETURN */
    return( ipass );
}
Ejemplo n.º 24
0
PRIVATE bool setupSession(auto_handle * session) {
   bool sessionOk = true;

   if(session != NULL) {
      if(listCount(session->feeds) == 0) {
         dbg_printf(P_ERROR, "No feeds specified in automatic.conf!");
         sessionOk = false;
      }

      if(listCount(session->filters) == 0) {
         dbg_printf(P_ERROR, "No filters specified in automatic.conf!");
         sessionOk = false;
      }

      if(sessionOk) {
         // There's been a previous session.
         // Copy over some of its values, and properly free its memory.
         if(mySession != NULL) {
            session->match_only = mySession->match_only;
            if(mySession->bucket_changed) {
               save_state(mySession->statefile, mySession->downloads);
            }

            session_free(mySession);
         }

         mySession = session;

         /* check if Prowl API key is given, and if it is valid */
         if(mySession->prowl_key && verifyProwlAPIKey(mySession->prowl_key) == 1 ) {
            mySession->prowl_key_valid = 1;
         }

         load_state(mySession->statefile, &mySession->downloads);
         printSessionSettings();
      }
   } else {
      sessionOk = false;
   }

   return sessionOk;
}
Ejemplo n.º 25
0
/* ENTRY POINT */
int Ball::state_integ() {

   int ipass;

   /* GET SHORTHAND NOTATION FOR DATA STRUCTURES */
   BallStateOutput * state_out = &(this->state.output);

   /* LOAD THE POSITION AND VELOCITY STATES */
   load_state(
       &state_out->position[0] ,
       &state_out->position[1] ,
       &state_out->velocity[0] ,
       &state_out->velocity[1] ,
       NULL
   );

   /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
   load_deriv(
       &state_out->velocity[0] ,
       &state_out->velocity[1] ,
       &state_out->acceleration[0] ,
       &state_out->acceleration[1] ,
       NULL
   );

   /* CALL THE TRICK INTEGRATION SERVICE */
   ipass = integrate();

   /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
   unload_state(
       &state_out->position[0] ,
       &state_out->position[1] ,
       &state_out->velocity[0] ,
       &state_out->velocity[1] ,
       NULL
   );

   /* RETURN */
   return( ipass );

}
Ejemplo n.º 26
0
/*!
 * @brief Ball state Trick compliant integration routine.
 *
 * This routine performs the following:
 *
 *   - Loads position into the integrator states.
 *   - Loads velocity into the integrator states.
 *   - Loads velocity into the integrator derivatives.
 *   - Loads acceleration into the integrator derivatives.
 *   - Calls the Trick integration service.
 *   - Unloads the propagated position and velocity from the integrator states.
 *
 * @job_class{ integration }
 *
 * @return Returns the Trick integration pass for the selected integration method.
 * @param [inout] state Ball EOM state parameters.
 */
int ball_state_integ(
  BallState * state )
{

   int ipass;

   /* LOAD THE POSITION AND VELOCITY STATES */
   load_state(
      &state->position[0],
      &state->position[1],
      &state->velocity[0],
      &state->velocity[1],
      NULL
   );

   /* LOAD THE POSITION AND VELOCITY STATE DERIVATIVES */
   load_deriv(
      &state->velocity[0],
      &state->velocity[1],
      &state->acceleration[0],
      &state->acceleration[1],
      NULL
   );

   /* CALL THE TRICK INTEGRATION SERVICE */
   ipass = integrate();

   /* UNLOAD THE NEW POSITION AND VELOCITY STATES */
   unload_state(
      &state->position[0],
      &state->position[1],
      &state->velocity[0],
      &state->velocity[1],
      NULL
   );

   /* RETURN */
   return( ipass );
}
Ejemplo n.º 27
0
int main(int argc, char** argv) {
    srand(unsigned(time(NULL)));
    init();

    if (argc == 2) {
        load_state(argv[1]);
    }

    FrameRateLockTimer timer(DT);

    while (true) {
        timer.lock();
        events();
        step();
        step_reaction();
        step_diffusion();

        glClear(GL_COLOR_BUFFER_BIT);
        draw();
        SDL_GL_SwapBuffers();
    }
}
Ejemplo n.º 28
0
void poll_buttons(void) {
  SDL_Event event;
  while(SDL_PollEvent(&event)) {
    if (event.type == SDL_KEYDOWN) {
      switch (event.key.keysym.sym) {
        case SDLK_DOWN:
        #ifdef PAD_DEBUG
        printf("debug [%d]: DOWN key (down) press detected\n",debug_cnt);
        #endif
        set_input(1);
        break;

        case SDLK_UP:
        #ifdef PAD_DEBUG
        printf("debug [%d]: UP key press (down) detected\n",debug_cnt);
        #endif
        set_input(2);
        break;

        case SDLK_LEFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LEFT key press (down) detected\n",debug_cnt);
        #endif
        set_input(3);
        break;

        case SDLK_RIGHT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: RIGHT key press (down) detected\n",debug_cnt);
        #endif
        set_input(4);
        break;

        case SDLK_LCTRL:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LCTRL (NES -> start) key (down) press detected\n",debug_cnt);
        #endif
        set_input(5);
        break;

        case SDLK_LSHIFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LSHIFT (NES -> select) key (down) press detected\n",debug_cnt);
        #endif
        set_input(6);
        break;

        case SDLK_p:
        if(pause_emulation) {
          printf("[*] LameNES continue emulation!\n");
          CPU_is_running = 1;
          pause_emulation = 0;
        } else if(!pause_emulation) {
          printf("[*] LameNES paused!\n");
          CPU_is_running = 0;
          pause_emulation = 1;
        }
        break;

        case SDLK_x:
        #ifdef PAD_DEBUG
        printf("debug [%d]: Z (NES -> A) key (down) press detected\n",debug_cnt);
        #endif
        set_input(7);
        break;

        case SDLK_z:
        #ifdef PAD_DEBUG
        printf("debug [%d]: X (NES -> B) key (down) press detected\n",debug_cnt);
        #endif
        set_input(8);
        break;

        case SDLK_q:
        #ifdef PAD_DEBUG
        printf("debug [%d]: Q (quit lamenes) key (down) press detected\n",debug_cnt);
        #endif
        quit_emulation();
        break;

        case SDLK_ESCAPE:
        #ifdef PAD_DEBUG
        printf("debug [%d]: ESC (quit lamenes) key (down) press detected\n",debug_cnt);
        #endif
        quit_emulation();
        break;

        case SDLK_F1:
        /* reset */
        reset_emulation();
        break;

        case SDLK_F3:
        /* load state */
        load_state();
        break;

        case SDLK_F6:
        /* save state */
        save_state();
        break;

        case SDLK_F10:
        if(enable_background == 1) {
          enable_background = 0;
        } else {
          enable_background = 1;
        }
        break;

        case SDLK_F11:
        if(enable_sprites == 1) {
          enable_sprites = 0;
        } else {
          enable_sprites = 1;
        }
        break;

        case SDLK_F12:
        if(startdebugger > 0) {
          disassemble = 1;
          hit_break = 1;
          debugger();
        }
        break;

        default:
        break;
      }
    }

    if(event.type == SDL_KEYUP) {
      switch(event.key.keysym.sym){
        case SDLK_DOWN:
        #ifdef PAD_DEBUG
        printf("debug [%d]: DOWN key (up) press detected\n",debug_cnt);
        #endif
        clear_input(1);
        break;

        case SDLK_UP:
        #ifdef PAD_DEBUG
        printf("debug [%d]: UP key (up) press detected\n",debug_cnt);
        #endif
        clear_input(2);
        break;

        case SDLK_LEFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LEFT key (up) press detected\n",debug_cnt);
        #endif
        clear_input(3);
        break;

        case SDLK_RIGHT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: RIGHT key (up) press detected\n",debug_cnt);
        #endif
        clear_input(4);
        break;

        case SDLK_LCTRL:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LCTRL (NES -> start) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(5);
        break;

        case SDLK_LSHIFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LSHIFT (NES -> select) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(6);
        break;

        case SDLK_x:
        #ifdef PAD_DEBUG
        printf("debug [%d]: Z (NES -> A) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(7);
        break;

        case SDLK_z:
        #ifdef PAD_DEBUG
        printf("debug [%d]: X (NES -> B) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(8);
        break;

        default:
        break;
      }
    }
  }
}
Ejemplo n.º 29
0
void init_work(char *base_dir) {
	FILE *fp;
	char *fn;
	char line[100];
	int i,j,k;
	
	load_state();
	
	/* read config file */
	fprintf(stderr, "reading flynn config tree from directory %s\n", base_dir);

	chdir(base_dir);
	
	fn = g_strconcat("gamelist", NULL);
	fp = fopen(fn, "rb");
	g_free(fn);
	
	if (!fp) {
		fprintf(stderr, "could not open game list file.\n");
		flynn_exit(-1);
	}
	
	while (fgets(line, 100, fp)) {
		int len;
		
		if (!(len = strlen(line)))
		continue;
		
		if (line[0] == '#')
		continue;
		
		for (i=0; i<len; i++)
		if (line[i] != '\n' && line[i] != '\t' && line[i] != ' ')
		goto found_non_whitespace;
		
		continue;
		
		found_non_whitespace:
		
		line[--len] = '\0';
		/* fprintf(stderr, "adding game %s\n", line); */
		
		game[num_games].mnemonic = g_strdup(line);
		
		if (isrotated()) {
			game[num_games].ppm_name = g_strconcat("images_106x154/", line, ".ppm", NULL);
		}
		else {
			game[num_games].ppm_name = g_strconcat("images_154x106/", line, ".ppm", NULL);	
		}				
		game[num_games].conf_name = g_strconcat("images_154x106/", line, ".conf", NULL);
		game[num_games].exec_cmd = g_strconcat("./run_game", NULL);
		game[num_games].ppm_loaded = 0;
		
		//printf("loaded %s\n",game[num_games].ppm_name);
		
		num_games++;
	}
	
	fclose(fp);
	
	for (i=0; i<num_games; i++) {
		unsigned char *temp_data;
		int w, h, r;		
		PnmPixformat pf = PNM_RGB;
		printf("Trying to read in %s\n",game[i].ppm_name);		
		r = read_pnm(game[i].ppm_name, &game[i].ppm_data, &w, &h, &pf);
		fn = g_strconcat("default.ppm", NULL);
		
		//printf("%d\n",r);
		
		if (r != 0) {
			printf("Reading in default.ppm\n");
			r = read_pnm(fn, &game[i].ppm_data, &w, &h, &pf); 
		}
		/*if (w != PPM_WIDTH || h != PPM_HEIGHT) {
			if (game[i].ppm_data) {
				free(game[i].ppm_data);
				game[i].ppm_data = NULL;
			}
			printf("Reading in default.ppm\n");
			r = read_pnm(fn, &game[i].ppm_data, &w, &h, &pf);
		}*/
		
		if (w == PPM_HEIGHT && h == PPM_WIDTH && isrotated()) {
			//printf("Trying to rotate %s 90 degrees\n",game[i].mnemonic);			
			r = read_pnm(game[i].ppm_name, &temp_data, &w, &h, &pf);					
			//temp_data = malloc(sizeof(game[i].ppm_data));
			//memcpy(&temp_data,&game[i].ppm_data,sizeof(game[i].ppm_data));
			for (j=h; j>0; j--) {
				for(k=1; k<w+1; k++) {					
					/*game[i].ppm_data[(k*h*3+j*3)-0] = temp_data[(j*w*3+k*3)-0];
					game[i].ppm_data[(k*h*3+j*3)-1] = temp_data[(j*w*3+k*3)-1];
					game[i].ppm_data[(k*h*3+j*3)-2] = temp_data[(j*w*3+k*3)-2];*/
					
					game[i].ppm_data[k*h*3-j*3-0] = temp_data[j*w*3+k*3-0];
					game[i].ppm_data[k*h*3-j*3-1] = temp_data[j*w*3+k*3-1];
					game[i].ppm_data[k*h*3-j*3-2] = temp_data[j*w*3+k*3-2];
				}
			}
			/*free(temp_data);
			temp_data = NULL;*/
		}		
		
		if (game[i].ppm_data && !r) {
			game[i].ppm_loaded = 1;	  
		}
		else {			
			fprintf(stderr, "ppm for %s is missing or inappropriate\n", game[i].mnemonic);
		}		
	}
	
	idle_restart();
	timeout_restart();
}
Ejemplo n.º 30
0
int main(int argc, char *argv[])
{
	struct option long_option[] =
	{
		{"help", 0, NULL, 'h'},
		{"file", 1, NULL, 'f'},
		{"force", 0, NULL, 'F'},
		{"debug", 0, NULL, 'd'},
		{"version", 0, NULL, 'v'},
		{NULL, 0, NULL, 0},
	};
	char *cfgfile = SYS_ASOUNDRC;
	int res;

	command = argv[0];
	while (1) {
		int c;

		if ((c = getopt_long(argc, argv, "hf:Fdv", long_option, NULL)) < 0)
			break;
		switch (c) {
		case 'h':
			help();
			return EXIT_SUCCESS;
		case 'f':
			cfgfile = optarg;
			break;
		case 'F':
			force_restore = 1;
			break;
		case 'd':
			debugflag = 1;
			break;
		case 'v':
			printf("alsactl version " SND_UTIL_VERSION_STR "\n");
			return EXIT_SUCCESS;
		case '?':		// error msg already printed
			help();
			return EXIT_FAILURE;
			break;
		default:		// should never happen
			fprintf(stderr, 
			"Invalid option '%c' (%d) not handled??\n", c, c);
		}
	}
	if (argc - optind <= 0) {
		fprintf(stderr, "alsactl: Specify command...\n");
		return 0;
	}

	if (!strcmp(argv[optind], "store")) {
		res =  save_state(cfgfile,
		   argc - optind > 1 ? argv[optind + 1] : NULL);
	} else if (!strcmp(argv[optind], "restore")) {
		res = load_state(cfgfile, 
		   argc - optind > 1 ? argv[optind + 1] : NULL);
	} else if (!strcmp(argv[optind], "names")) {
		if (!strcmp(cfgfile, SYS_ASOUNDRC))
			cfgfile = SYS_ASOUNDNAMES;
		res = generate_names(cfgfile);
	} else {
		fprintf(stderr, "alsactl: Unknown command '%s'...\n", 
			argv[optind]);
		res = -ENODEV;
	}

	return res < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}