Exemplo n.º 1
0
void sound_gui() {
//	SDL_Event ev;
    u32 keys; 
	int action;
	
	set_yesno_string(quiet_data, quiet);
	set_dsp_string();
	set_sq_string();
	
	exit_sound = 0;
	while( !exit_sound ) {
		status_timer = 0;

		sprintf(msg, "Sound Options");
		draw_gui(sound_gui_items, sound_current);
		
//		SDL_WaitEvent(&ev);	/* TODO: respond to SDL_QUIT events */
		hidScanInput();
		while(!hidKeysHeld()) hidScanInput();
		keys = hidKeysHeld();
		action = gui_navigation(keys); //&ev);
		if(action == GUI_NO_ACTION) continue;
		
		sound_current = gui_handle_action(action, &exit_sound, sound_gui_items, sound_current);
	}
}
Exemplo n.º 2
0
void tweaks_gui() {
//	SDL_Event ev;
    u32 keys; 
	int action;
	
	set_mpx_string();
	set_mpy_string();
	set_paddle_sensitivity_string();
	set_paddle_adjust_string();
	set_lightgun_cycles_string();
	set_lightgun_scanlines_string();
	
	exit_tweaks = 0;
	while( !exit_tweaks ) {
		status_timer = 0;

		sprintf(msg, "Controller Tweaks");
		draw_gui(tweaks_gui_items, tweaks_current);
		
//		SDL_WaitEvent(&ev);	/* TODO: respond to SDL_QUIT events */
		hidScanInput();
		while(!hidKeysHeld()) hidScanInput();
		keys = hidKeysHeld();
		action = gui_navigation(keys); //&ev);
		if(action == GUI_NO_ACTION) continue;
		
		tweaks_current = gui_handle_action(action, &exit_tweaks, tweaks_gui_items, tweaks_current);
	}
}
Exemplo n.º 3
0
// --------------------------------------------------
ViewState Viewer::startMainLoop(Viewer* viewer)
// --------------------------------------------------
{
	viewer->initialize();

	u32 kDown, kHeld, kUp;
	touchPosition touch;
	while(viewer->isRunning() && aptMainLoop())
	{
		hidScanInput();
		kDown = hidKeysDown();
		kHeld = hidKeysHeld();
		kUp = hidKeysUp();
		hidTouchRead(&touch);

		sf2d_start_frame(GFX_TOP, GFX_LEFT);
			viewer->drawTopScreen();
		sf2d_end_frame();
		sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
			viewer->drawBotScreen();
		sf2d_end_frame();
		sf2d_swapbuffers();

		viewer->updateControls(kDown, kHeld, kUp, &touch);
	}

	return viewer->state();
}
Exemplo n.º 4
0
void InputImpl::poll_inputs() {
    // Read and store inputs

    m_prev_joystick = m_curr_joystick;
    m_prev_buttons = m_curr_buttons;

    m_curr_joystick = 0x00;
    m_curr_buttons = 0x00;

    u32 keys = hidKeysHeld();

    // Joystick
    if (keys & KEY_DUP)
        m_curr_joystick |= UP_BIT | RAW_UP_BIT;
    if (keys & KEY_DDOWN)
        m_curr_joystick |= DOWN_BIT | RAW_DOWN_BIT;
    if (keys & KEY_DLEFT)
        m_curr_joystick |= LEFT_BIT | RAW_LEFT_BIT;
    if (keys & KEY_DRIGHT)
        m_curr_joystick |= RIGHT_BIT | RAW_RIGHT_BIT;

    // Buttons
    if (keys & KEY_Y)
        m_curr_buttons |= A_BIT;
    if (keys & KEY_X || keys & KEY_B)
        m_curr_buttons |= B_BIT;
    if (keys & KEY_A)
        m_curr_buttons |= C_BIT;
    if (keys & KEY_START)
        m_curr_buttons |= START_BIT;
    if (keys & KEY_SELECT)
        m_curr_buttons |= SETTINGS_BIT;

    process();
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: yuriks/mgba
static int _pollInput(void) {
	hidScanInput();
	int keys = 0;
	int activeKeys = hidKeysHeld();
	if (activeKeys & KEY_X) {
		keys |= 1 << GUI_INPUT_CANCEL;
	}
	if (activeKeys & KEY_B) {
		keys |= 1 << GUI_INPUT_BACK;
	}
	if (activeKeys & KEY_A) {
		keys |= 1 << GUI_INPUT_SELECT;
	}
	if (activeKeys & KEY_LEFT) {
		keys |= 1 << GUI_INPUT_LEFT;
	}
	if (activeKeys & KEY_RIGHT) {
		keys |= 1 << GUI_INPUT_RIGHT;
	}
	if (activeKeys & KEY_UP) {
		keys |= 1 << GUI_INPUT_UP;
	}
	if (activeKeys & KEY_DOWN) {
		keys |= 1 << GUI_INPUT_DOWN;
	}
	return keys;
}
Exemplo n.º 6
0
int joystickIsGamepadDown(lua_State *L) { //joystick:isGamepadDown()
	
	//Check first argument is Joystick type
	love_joystick *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	
	//Get input
	hidScanInput();
	u32 kHeld = hidKeysHeld();
	
	//Check arguments given
	int numBtnsCheck = lua_gettop(L);
	for (int i = 2; i <= numBtnsCheck; i++) {
		const char *str = luaL_checkstring(L, i);
		
		bool result = false;
		
		for( int i = 0; i < 32; i++ ) {
			if(kHeld & BIT(i)) {
				if( strcmp( gamepadMapping[i], "touch" ) != 0 ) {
					if( strcmp(str, gamepadMapping[i]) == 0) {
						result = true;
					}
				}
			}
		}
		
		lua_pushboolean(L, result);
	}
	return numBtnsCheck-1;

}
Exemplo n.º 7
0
/*
    Name                :     handy_3ds_rom_info
    Parameters          :     N/A
    Function            :   Game Image information function for Handy 3ds

    Uses                :   N/A

    Information            :    Basic function for getting information of the
                            Atari Lynx game image and for setting up the
                            Handy core concerning rotation.
*/
void handy_3ds_rom_info(void)
{

    printf("Atari Lynx ROM Information\n");

    /* Retrieving Game Image information */
    printf("Cartname      : %s\n"   , mpLynx->CartGetName()         );
    printf("ROM Size      : %d kb\n", (int)mpLynx->CartSize()      );
    printf("Manufacturer  : %s\n"   , mpLynx->CartGetManufacturer() );

    /* Retrieving Game Image Rotatation */
    printf("Lynx Rotation : ");
    switch(mpLynx->CartGetRotate())
    {
        case CART_NO_ROTATE:
            LynxRotate = MIKIE_NO_ROTATE;
            printf("NO\n");
            break;
        case CART_ROTATE_LEFT:
            LynxRotate = MIKIE_ROTATE_L;
            printf("LEFT\n");
            break;
        case CART_ROTATE_RIGHT:
            LynxRotate = MIKIE_ROTATE_R;
            printf("RIGHT\n");
            break;
        default:
            // Allright, this shouldn't be necassary. But in case the user is using a
            // bad dump, we use the default rotation as in no rotation.
            LynxRotate = MIKIE_NO_ROTATE;
            printf("NO (forced)\n");
            break;
    }

    /* Retrieving Game Image type */
    printf("ROM Type      : ");
    switch(mpLynx->mFileType)
    {
        case HANDY_FILETYPE_HOMEBREW:
            printf("Homebrew\n");
            break;
        case HANDY_FILETYPE_LNX:
            printf("Commercial and/or .LNX-format\n");
            break;
        case HANDY_FILETYPE_SNAPSHOT:
            printf("Snapshot\n");
            break;
        default:
            // Allright, this shouldn't be necessary, but just in case.
            printf("Unknown format!\n");
            if (mydebug) do {
                hidScanInput();
            } while (!(hidKeysHeld() & KEY_TOUCH));
            exit(EXIT_FAILURE);
            break;
    }

}
Exemplo n.º 8
0
u32 getKeyState()
{
    static u32 last_held = 0;
    u32 held = hidKeysHeld();

    u32 ret = (~last_held) & held;
    last_held = held;
    return ret;
}
Exemplo n.º 9
0
static int lua_readC(lua_State *L)
{
    int argc = lua_gettop(L);
	#ifndef SKIP_ERROR_HANDLING
		if (argc != 0) return luaL_error(L, "wrong number of arguments.");
	#endif
	hidScanInput();
	irrstScanInput();
	lua_pushnumber(L, hidKeysHeld());
	return 1;
}
Exemplo n.º 10
0
//Handles input relating to in-game.
void game_controller_game_input(GameController self) {
	hidScanInput();
	u32 kDown = hidKeysDown();
	u32 kHeld = hidKeysHeld();


	if (kHeld & KEY_A) { //A
		player_shoot(self->player, self->bullet_storage);
	}
	if (kHeld & KEY_B) { //B
	}
	if (kHeld & KEY_B) { //B
	}
	if (kDown & KEY_X) { //X
	}
	if (kDown & KEY_Y) { //Y
	} 
	
	
	
	if (kHeld & KEY_L) { //Controls player focus mode.
		self->player->flag_focus = true;
	} else {
		self->player->flag_focus = false;
	}
	
	
	
	if (kHeld & KEY_UP) { //up
		player_move(self->player, NORTH);
	} 
	if (kHeld & KEY_DOWN) { //down
		player_move(self->player, SOUTH);
	} 
	if (kHeld & KEY_LEFT) { //left
		player_move(self->player, WEST);
	} 
	if (kHeld & KEY_RIGHT) { //right
		player_move(self->player, EAST);
	} 
	
	
	
	if (kDown & KEY_START) { //start
		self->is_paused = !self->is_paused;
	} 
	if (kDown & KEY_SELECT) { //select
		//ZZZ
		self->flag_external_state = MAIN_MENU;
	}

}
Exemplo n.º 11
0
int hidCollectData(struct hidInfo *info)
{
    info->keys.up   = hidKeysUp();
    info->keys.down = hidKeysDown();
    info->keys.held = hidKeysHeld();

    hidTouchRead(&info->touchscreen);
    hidCircleRead(&info->circlepad);
    hidGyroRead(&info->gyro);
    hidCstickRead(&info->cstick);

    return 0;
}
Exemplo n.º 12
0
static void ctr_joypad_poll(void)
{
   int32_t ret;
   uint32_t state_tmp;
   circlePosition state_tmp_analog;

   global_t *global          = global_get_ptr();
   uint64_t *lifecycle_state = (uint64_t*)&global->lifecycle_state;

   hidScanInput();

   state_tmp = hidKeysHeld();
   hidCircleRead(&state_tmp_analog);

   analog_state[0][0][0] = analog_state[0][0][1] =
      analog_state[0][1][0] = analog_state[0][1][1] = 0;
   pad_state = 0;
   pad_state |= (state_tmp & KEY_DLEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
   pad_state |= (state_tmp & KEY_DDOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
   pad_state |= (state_tmp & KEY_DRIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
   pad_state |= (state_tmp & KEY_DUP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
   pad_state |= (state_tmp & KEY_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0;
   pad_state |= (state_tmp & KEY_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
   pad_state |= (state_tmp & KEY_X) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0;
   pad_state |= (state_tmp & KEY_Y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
   pad_state |= (state_tmp & KEY_B) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0;
   pad_state |= (state_tmp & KEY_A) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0;
   pad_state |= (state_tmp & KEY_R) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0;
   pad_state |= (state_tmp & KEY_L) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0;

   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] =  (state_tmp_analog.dx * 200);
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = -(state_tmp_analog.dy * 200);

   for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
         if (analog_state[0][i][j] == -0x8000)
            analog_state[0][i][j] = -0x7fff;

   *lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE));

   if(state_tmp & KEY_TOUCH)
      *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);

   /* panic button */
   if((state_tmp & KEY_START) &&
      (state_tmp & KEY_SELECT) &&
      (state_tmp & KEY_L) &&
      (state_tmp & KEY_R))
      event_command(EVENT_CMD_QUIT);

}
Exemplo n.º 13
0
static void ctr_joypad_poll(void)
{
   int32_t ret;
   unsigned i, j;
   uint32_t state_tmp;
   circlePosition state_tmp_analog;

   hidScanInput();

   state_tmp = hidKeysHeld();
   hidCircleRead(&state_tmp_analog);

   analog_state[0][0][0] = analog_state[0][0][1] =
      analog_state[0][1][0] = analog_state[0][1][1] = 0;
   pad_state = 0;
   pad_state |= (state_tmp & KEY_DLEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
   pad_state |= (state_tmp & KEY_DDOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
   pad_state |= (state_tmp & KEY_DRIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
   pad_state |= (state_tmp & KEY_DUP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
   pad_state |= (state_tmp & KEY_START) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0;
   pad_state |= (state_tmp & KEY_SELECT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
   pad_state |= (state_tmp & KEY_X) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0;
   pad_state |= (state_tmp & KEY_Y) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
   pad_state |= (state_tmp & KEY_B) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0;
   pad_state |= (state_tmp & KEY_A) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0;
   pad_state |= (state_tmp & KEY_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0;
   pad_state |= (state_tmp & KEY_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0;

   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] =  (state_tmp_analog.dx * 200);
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = -(state_tmp_analog.dy * 200);

   for (i = 0; i < 2; i++)
      for (j = 0; j < 2; j++)
         if (analog_state[0][i][j] == -0x8000)
            analog_state[0][i][j] = -0x7fff;

   BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE);

   if(state_tmp & KEY_TOUCH)
      BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE);

   /* panic button */
   if((state_tmp & KEY_START) &&
      (state_tmp & KEY_SELECT) &&
      (state_tmp & KEY_L) &&
      (state_tmp & KEY_R))
      event_command(EVENT_CMD_QUIT);

}
Exemplo n.º 14
0
void yetiUpdateKeyboard(yeti_t* y)
{
	hidScanInput();
	u32 keys=hidKeysHeld();

	y->keyboard.a       = (keys&KEY_A)!=0;
	y->keyboard.b       = (keys&KEY_B)!=0;
	y->keyboard.select  = (keys&KEY_SELECT)!=0;
	y->keyboard.left    = (keys&KEY_DLEFT)!=0;
	y->keyboard.right   = (keys&KEY_DRIGHT)!=0;
	y->keyboard.up      = (keys&KEY_DUP)!=0;
	y->keyboard.down    = (keys&KEY_DDOWN)!=0;
	y->keyboard.r       = (keys&KEY_R)!=0;
	y->keyboard.l       = (keys&KEY_L)!=0;
}
Exemplo n.º 15
0
void hang(char *message) {
	while(aptMainLoop()) {
		hidScanInput();
		
		clearScreen();
		drawString(10, 10, "%s", message);
		drawString(10, 20, "Start and Select to exit");
		
		u32 kHeld = hidKeysHeld();
		if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
		
		gfxFlushBuffers();
		gspWaitForVBlank();
		gfxSwapBuffers();
	}
}
Exemplo n.º 16
0
static void ctr_joypad_poll(void)
{
   uint32_t state_tmp;
   circlePosition state_tmp_left_analog, state_tmp_right_analog;
   touchPosition state_tmp_touch;

   hidScanInput();

   state_tmp = hidKeysHeld();
   hidCircleRead(&state_tmp_left_analog);
   irrstCstickRead(&state_tmp_right_analog);
   hidTouchRead(&state_tmp_touch);

   pad_state = 0;
   pad_state |= (state_tmp & KEY_DLEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
   pad_state |= (state_tmp & KEY_DDOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
   pad_state |= (state_tmp & KEY_DRIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
   pad_state |= (state_tmp & KEY_DUP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
   pad_state |= (state_tmp & KEY_START) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0;
   pad_state |= (state_tmp & KEY_SELECT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
   pad_state |= (state_tmp & KEY_X) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0;
   pad_state |= (state_tmp & KEY_Y) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
   pad_state |= (state_tmp & KEY_B) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0;
   pad_state |= (state_tmp & KEY_A) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0;
   pad_state |= (state_tmp & KEY_R) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0;
   pad_state |= (state_tmp & KEY_L) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0;
   pad_state |= (state_tmp & KEY_ZR) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
   pad_state |= (state_tmp & KEY_ZL) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0;

   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X]  =  ctr_joypad_fix_range(state_tmp_left_analog.dx);
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y]  = -ctr_joypad_fix_range(state_tmp_left_analog.dy);
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_X] =  ctr_joypad_fix_range(state_tmp_right_analog.dx);
   analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT] [RETRO_DEVICE_ID_ANALOG_Y] = -ctr_joypad_fix_range(state_tmp_right_analog.dy);

   BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE);

   if((state_tmp & KEY_TOUCH) && (state_tmp_touch.py > 120))
      BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE);

   /* panic button */
   if((state_tmp & KEY_START) &&
      (state_tmp & KEY_SELECT) &&
      (state_tmp & KEY_L) &&
      (state_tmp & KEY_R))
      command_event(CMD_EVENT_QUIT, NULL);

}
Exemplo n.º 17
0
void CtrUi::ProcessEvents() {
	
	hidScanInput();
	u32 input = hidKeysHeld();
	keys[Input::Keys::Z] = (input & KEY_A);
	keys[Input::Keys::X] = (input & KEY_B);
	keys[Input::Keys::N8] = (input & KEY_X);
	keys[Input::Keys::SHIFT] = (input & KEY_Y);
	keys[Input::Keys::F12] = (input & KEY_SELECT);
	keys[Input::Keys::ESCAPE] = (input & KEY_START);
	keys[Input::Keys::RIGHT] = (input & KEY_DRIGHT);
	keys[Input::Keys::LEFT] = (input & KEY_DLEFT);
	keys[Input::Keys::UP] = (input & KEY_DUP);
	keys[Input::Keys::DOWN] = (input & KEY_DDOWN);
	keys[Input::Keys::F2] = (input & KEY_L);
	
	//Fullscreen mode support
	bool old_state = trigger_state;
	trigger_state = (input & KEY_R);
	if ((trigger_state != old_state) && trigger_state) fullscreen = !fullscreen;
	
	//CirclePad support
	circlePosition circlepad;
	hidCircleRead(&circlepad);
	
	if (circlepad.dy > 25) keys[Input::Keys::UP] = true;
	else if (circlepad.dy < -25) keys[Input::Keys::DOWN] = true;
	else if (circlepad.dx > 25) keys[Input::Keys::RIGHT] = true;
	else if (circlepad.dx < -25) keys[Input::Keys::LEFT] = true;
	
	#ifdef NO_DEBUG
	//Touchscreen support
	if (input & KEY_TOUCH){
		touchPosition pos;
		hidTouchRead(&pos);
		u8 row = pos.px>>6;
		u8 col = pos.py / 60;
		u32 keys_tbl[16] = {Input::Keys::N7, Input::Keys::N8, Input::Keys::N9,
						Input::Keys::DIVIDE, Input::Keys::N4, Input::Keys::N5,
						Input::Keys::N6, Input::Keys::MULTIPLY, Input::Keys::N1,
						Input::Keys::N2, Input::Keys::N3, Input::Keys::SUBTRACT,
						Input::Keys::N0, Input::Keys::N0, Input::Keys::PERIOD,
						Input::Keys::ADD
						};
		keys[keys_tbl[row + (col*4)]] = true;
	}else{
Exemplo n.º 18
0
int cursorController()
{
	//hidKeysHeld returns information about which buttons have are held down in this frame
	u32 kHeld = hidKeysHeld();
	
	//Read the touch screen coordinates
	if (kHeld & KEY_TOUCH) 
	{
		hidTouchRead(&touch);
		touch_x = touch.px;
		touch_y = touch.py;
	}

	sf2d_draw_texture(cursor, touch_x, touch_y);
	
	return 0;
}
Exemplo n.º 19
0
static void I_GetInput() {
	event_t event;
	event.data2 = event.data3 = 0;
	
	uint32_t down = hidKeysDown();
	uint32_t held = hidKeysHeld();
	uint32_t up = hidKeysUp();

	// iterate over other possible key values
	int i;
	for (i = 0; i < (usejoystick ? 28 : 32); i++) {
		uint32_t key = 1<<i;
		
		if (down & key) {
			event.data1 = I_TranslateKey(key);
			event.type = ev_keydown;
			D_PostEvent(&event);
		} else if (up & key) {
			event.data1 = I_TranslateKey(key);
			event.type = ev_keyup;
			D_PostEvent(&event);
		}
	}

	// handle touch pad movement
	if (usemouse) {
		static int px = 0;
		static int py = 0;
		touchPosition touch;
		hidTouchRead(&touch);
		if (down & KEY_TOUCH) {
			px = touch.px;
			py = touch.py;
			
		} else if (held & KEY_TOUCH && (touch.px != px || touch.py != py)) {
			event.type = ev_mouse;
			event.data1 = -1;
			event.data2 = (touch.px - px) << 5;
			event.data3 = -(touch.py - py) << 5;
			D_PostEvent(&event);
			
			px = touch.px;
			py = touch.py;
		}
	}
}
Exemplo n.º 20
0
void IN_Move (usercmd_t *cmd)
{
  if(hidKeysHeld() & KEY_TOUCH){
    hidTouchRead(&touch);
    touch.px =  (touch.px + oldtouch.px) / 2;
    touch.py =  (touch.py + oldtouch.py) / 2;
    cl.viewangles[YAW] -= (touch.px - oldtouch.px) * sensitivity.value/2;
    if(in_mlook.state & 1)
      cl.viewangles[PITCH] += (touch.py - oldtouch.py) * sensitivity.value/2;
    oldtouch = touch;
  }

  hidCircleRead(&circlepad);
  //CirclePad deadzone to fix ghost movements
  if(abs(circlepad.dy) > 15){
    cmd->forwardmove += m_forward.value * circlepad.dy * 2;
  }
  if(abs(circlepad.dx) > 15){
    if((in_strafe.state & 1) || (lookstrafe.value))
      cmd->sidemove += m_side.value * circlepad.dx * 2;
    else
      cl.viewangles[YAW] -= m_side.value * circlepad.dx * 0.03;
  }

  //cStick is only available on N3DS... Until libctru implements support for circlePad Pro
  if(isN3DS){

    hidCstickRead(&cstick);

    if(m_pitch.value < 0)
      cstick.dy = -cstick.dy;

    cstick.dx = abs(cstick.dx) < 10 ? 0 : cstick.dx * csensitivity.value * 0.01;
    cstick.dy = abs(cstick.dy) < 10 ? 0 : cstick.dy * csensitivity.value * 0.01;

    cl.viewangles[YAW] -= cstick.dx;
    cl.viewangles[PITCH] -= cstick.dy;
  }

  V_StopPitchDrift ();

}
Exemplo n.º 21
0
void inputUpdateVBlank() {
    hidScanInput();
    lastKeysPressed = keysPressed;
    keysPressed = hidKeysHeld();

    for (int i=0; i<32; i++) {
        if (keysForceReleased & (1<<i)) {
            if (!(keysPressed & (1<<i)))
                keysForceReleased &= ~(1<<i);
        }
    }
    keysPressed &= ~keysForceReleased;

    keysJustPressed = (lastKeysPressed ^ keysPressed) & keysPressed;

    if (repeatTimer > 0)
        repeatTimer--;
    if (repeatStartTimer > 0)
        repeatStartTimer--;
}
Exemplo n.º 22
0
static void ctr_input_poll(void *data)
{   
   (void)data;
   global_t   *global   = global_get_ptr();
   uint64_t *lifecycle_state = (uint64_t*)&global->lifecycle_state;

   hidScanInput();
   kDown = hidKeysHeld();

   pad_state = 0;
   pad_state |= (kDown & KEY_DLEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
   pad_state |= (kDown & KEY_DDOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
   pad_state |= (kDown & KEY_DRIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
   pad_state |= (kDown & KEY_DUP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
   pad_state |= (kDown & KEY_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0;
   pad_state |= (kDown & KEY_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
   pad_state |= (kDown & KEY_X) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0;
   pad_state |= (kDown & KEY_Y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
   pad_state |= (kDown & KEY_B) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0;
   pad_state |= (kDown & KEY_A) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0;
   pad_state |= (kDown & KEY_R) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0;
   pad_state |= (kDown & KEY_L) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0;


   *lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE));

   if(kDown & KEY_TOUCH)
      *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);

   /* panic button */
   if((kDown & KEY_START) &&
      (kDown & KEY_SELECT) &&
      (kDown & KEY_L) &&
      (kDown & KEY_R))
      rarch_main_command(RARCH_CMD_QUIT);

}
Exemplo n.º 23
0
bool isButtonPressed(char button, bool wait = true) {
	std::tuple<u32, u32, u32> input = dsIn();
	kDown = std::get<0>(input);
	kHeld = std::get<1>(input);
	kUp	  = std::get<2>(input);
	while (!kDown && wait) {hidScanInput(); u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); u32 kUp = hidKeysUp();}
	if (kDown && KEY_A && button == 'a') return 0;
	else if (kDown && KEY_B && button == 'b') return 0;
	else if (kDown && KEY_X && button == 'x') return 0;
	else if (kDown && KEY_Y && button == 'y') return 0;
	else if (kDown && KEY_L && button == 'l') return 0;
	else if (kDown && KEY_R && button == 'r') return 0;
	else if (kDown && KEY_START && button == 't') return 0;
	else if (kDown && KEY_SELECT && button == 'e') return 0;
	else if (kDown && KEY_UP && button == 'u') return 0;
	else if (kDown && KEY_DOWN && button == 'd') return 0;
	else if (kDown && KEY_LEFT && button == 'q') return 0;
	else if (kDown && KEY_RIGHT && button == 'e') return 0;
	else if (consoletype) {
		if (kDown && KEY_ZR && button == 'c') return 0;
		else if (kDown && KEY_ZL && button == 'z') return 0;
	}
	return 1;
}
Exemplo n.º 24
0
int main() {
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();
	fsInit();
	sdmcInit();
	hbInit();
	qtmInit();
	hidScanInput();
	u32 kDown = hidKeysDown();
	u32 kHeld = hidKeysHeld();

	//Load the configuration
	loadConfiguration();

    //Check kernel version
	getSystemVersion();
	
	//checks if the CFW has to boot right away or open the GUI
	if(auto_boot == '2') auto_boot = '2'; //here it checks if the "force GUI" is set, and preservs it if it is set
	else if(kHeld & KEY_L) auto_boot = '0'; //here it will start the GUI only this time
	else auto_boot = '1'; //here it won't show the GUI

	//checks if the CFW has to disable firmlaunch
	if (kHeld & KEY_R && firmlaunch == '0') firmlaunch = '2'; //here we enable the firmlaunch only this time
	else if (kHeld & KEY_R && firmlaunch == '1')firmlaunch = '3'; //here we disable the firmlaunch only this time
	
	//Then we save the configuration
	saveConfiguration();

	//Proceeds to launch the loader.bin
	bootCFW_FirstStage();

	}
Exemplo n.º 25
0
Arquivo: main.c Projeto: Jeflux/3DSC
int main(int argc, char **argv) {
	gfxInitDefault();
	socInit((u32 *)memalign(0x1000, 0x100000), 0x100000);

	// Check wifi status
	u32 wifiStatus = 0;
	ACU_GetWifiStatus(&wifiStatus);
	if (!wifiStatus) {
		printf("\x1b[1;1HNo WiFi! Is your wireless slider on?");
	}

	// Use printf on top screen
	consoleInit(GFX_TOP, NULL);

	// Stuff for network magic
	int recvlen;
	unsigned char buf[BUFSIZE];
	unsigned char IDBuf[BUFSIZE];

	// Try create socket
	int err = 0;
	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		err = 1;
	}

	// Setup socket addresses
	out.sin_family = in.sin_family = AF_INET;
	out.sin_port = in.sin_port = htons(PORT); // Set port
	in.sin_addr.s_addr = INADDR_ANY;

	// Try to bind socket to port
	if (err == 0 && bind(sock, (struct sockaddr *)&in, sizeof(in)) < 0)
		err = 2;

	// If any errors
	if (err != 0)
		printf("\x1b[4;1HError opening connection: %i", err);

	// Set socket receive to non-blocking to be able to exit while listening for broadcast
	fcntl(sock, F_SETFL, O_NONBLOCK);


	bool connected = false;

	// Main loop
	while (aptMainLoop()) {

		if (err == 0) {
			// If not connected, listen for broadcast
			if (!connected) {
				printf("\x1b[1;1HListening for broadcast on port %d", PORT);

				// Listen for packets. Returns packet size
				recvlen = recvfrom(sock, buf, BUFSIZE, 0, (struct sockaddr *)&out, &addrlen);

				// Check if correct packet. recvlen < 0 -> Error
				if (recvlen > 0) {
					printf("\x1b[2;1Hr"); // Debug print. Writes r for any packet received
					buf[recvlen] = 0; // Don't remember what this is for. Oops

									  // Check if message is connection port (Broadcast sends out port number as broadcast)
					int i = atoi(buf);
					if (i == PORT) {
						// If broadcast message, assign send address to received address
						in.sin_addr.s_addr = out.sin_addr.s_addr;

						// Prepare program; Setting flag, turning of backlight, etc
						connected = true;
						consoleClear();
						printf("\x1b[1;1HConnected");
						if (backlightOff == false)
							disableBacklight();
						backlightOff = true;
					}
				}
			}
		}

		printf("\x1b[28;1HPlayer ID: %i", playerID);
		printf("\x1b[29;1HPress START and SELECT to exit");

		// Scan input
		hidScanInput();
		// Save keystate
		u32 kDown = hidKeysHeld();

		if ((kDown & KEY_START) && (kDown & KEY_SELECT)) break; // break in order to return to hbmenu

		// If no errors and connected. Contruct input message
		if (err == 0 && connected) {
			// Get circle pad state
			circlePosition pos;
			hidCircleRead(&pos);

			// Construct message
			message.ID = playerID;
			message.pdx = pos.dx;
			message.pdy = pos.dy;
			message.btn = kDown;

			// Query for touchscreen information
			touchPosition touch;
			hidTouchRead(&touch);

			message.touch_px = touch.px;
			message.touch_py = touch.py;

			// Send packet to address broadcast came from
			sendto(sock, &message, sizeof(message), 0, (struct sockaddr *)&in, sizeof(in));

			int recv = 0;
			int count = 0;
			do {
				count++;
				// Send packet to address broadcast came from
				sendto(sock, &message, sizeof(message), 0, (struct sockaddr *)&in, sizeof(in));
				// Listen for packet to get player ID and check if server is alive
				//int recv = read(sock, IDBuf, sizeof(IDBuf));
				recv = recvfrom(sock, IDBuf, BUFSIZE, 0, (struct sockaddr *)&out, &addrlen);
			} while (atoi(IDBuf) == PORT && count < 5);

			if (count < 5 && recv > 0)
				playerID = IDBuf[0] | IDBuf[1] << 1;
			else {
				connected = false;
				playerID = 0;
				consoleClear();
				printf("\x1b[2;1HDisconnected");

				if (backlightOff == true) {
					enableBacklight();
					backlightOff = false;
				}
			}
		}

		u64 sleepDuration = 16000000ULL;
		svcSleepThread(sleepDuration);

		// Draw stuff
		gfxFlushBuffers();
		gfxSwapBuffers();
		gspWaitForVBlank();
	}

	// On exit
	if (backlightOff == true)
		enableBacklight();
	socExit();
	gfxExit();
	return 0;
}
Exemplo n.º 26
0
int main(void) {
	irmemloc = (u32*) memalign(0x1000, 0x1000);
	resultStartup = IRU_Initialize(irmemloc, 0x1000);
	resultSetBit = IRU_SetBitRate(0xB);
	recordedIR = (u32*) malloc(REC_SIZE * NUM_OF_BUTTONS); //Currently there are 11(NUM_OF_BUTTONS) recordable buttons. (start switches mode)
	recentIR = (u32*) calloc(REC_SIZE, 0x1); //Whatever was last viewed in memory
	resultGetStatus = irucmd_GetTransferState(&StatusIR);
	srvInit();        // services
	aptInit();        // applets
	hidInit(NULL);    // input
	gfxInitDefault(); // gfx
	
	gfxSetDoubleBuffering(GFX_TOP, true);
	gfxSetDoubleBuffering(GFX_BOTTOM, true);
	bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
	top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
	
	if(setjmp(exitJmp)) goto exit;
	
	clearScreen();
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	bool startToggle = false;
	bool upToggle = false;
	bool downToggle = false;
	
	while(aptMainLoop()) {
		bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
		top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
		hidScanInput();
		irrstScanInput();
		
		u32 kHeld = hidKeysHeld();
		circlePosition circlePad;
		circlePosition cStick;
		hidCstickRead(&cStick);
		hidCircleRead(&circlePad);
		touchPosition touch;
		touchRead(&touch);
		
		clearScreen();
		
		char keys[30] = "ABXY URDL SEST LR ZLZR";
		
		if(kHeld & KEY_A) {
			keys[0] = '*';
			ir('A');
		}
		if(kHeld & KEY_B) {
			keys[1] = '*';
			ir('B');
		}
		if(kHeld & KEY_X) {
			keys[2] = '*';
			ir('X');
		}
		if(kHeld & KEY_Y) {
			keys[3] = '*';
			ir('Y');
		}
		if(kHeld & KEY_DUP) {
			keys[5] = '*';
			if(upToggle) {
				if(bitrate < 18) {
					bitrate++;
					resultSetBit = IRU_SetBitRate(bitrate);
				}
				upToggle = false;
			}
		} else {
			upToggle = true;
		}
		if(kHeld & KEY_DRIGHT) {
			keys[6] = '*';
			ir('R');
		}
		if(kHeld & KEY_DDOWN) {
			keys[7] = '*';
			if(downToggle) {
				if(bitrate > 3) {
					bitrate--;
					resultSetBit = IRU_SetBitRate(bitrate);
				}
				downToggle = false;
			}
		} else {
			downToggle = true;
		}
		if(kHeld & KEY_DLEFT) {
			keys[8] = '*';
			ir('L');
		}
		if(kHeld & KEY_SELECT) {
			keys[10] = '*';
			keys[11] = '*';
			ir('S');
		}
		if(kHeld & KEY_START) {
			keys[12] = '*';
			keys[13] = '*';
			if(startToggle) {
				rec = !rec;
				startToggle = false;
			}
		} else {
			startToggle = true;
		}
		if(kHeld & KEY_L) {
			keys[15] = '*';
			ir('L');
		}
		if(kHeld & KEY_R) {
			keys[16] = '*';
			ir('R');
		}
		if(kHeld & KEY_ZL) {
			keys[18] = '*';
			keys[19] = '*';
			ir('1');
		}
		if(kHeld & KEY_ZR) {
			keys[20] = '*';
			keys[21] = '*';
			ir('2');
		}
		drawString(top, 10, 10, keys);
		drawString(top, 10, 20, "Circle Pad   x: %04+d, y: %04+d", circlePad.dx, circlePad.dy);
		drawString(top, 10, 30, "Touch        x: %04d, y: %04d", touch.px, touch.py );
		if(resultStartup == 0) {
			drawString(top, 10, 40, "IR started!");
		} else {
			drawString(top, 10, 40, "IR Init     |Error: %x", resultStartup);
		}
		if(resultSetBit == 0) {
			drawString(top, 10, 50, "IR bit rate works!");
		} else {
			drawString(top, 10, 50, "IR bit rate |Error: %x", resultSetBit);
		}
		if(resultTransferIR == 0) {
			drawString(top, 10, 60, "IR transfer works!");
		} else {
			drawString(top, 10, 60, "IR transfer |Error: %x", resultTransferIR);
		}
		irucmd_GetTransferState(&StatusIR);
		drawString(top, 10, 70, "IR mode: %x", StatusIR);
		drawString(top, 10, 80, "Got %d bytes", TransIR);
		drawString(top, 10, 90, "Bitrate: %d (see IRU:SetBitRate)", bitrate);
		printMemory(NULL,REC_SIZE,10, false); //might be dangerous?
		
		if(rec) {
			drawString(top, 10, 210, "Recording mode active.");
		}else{
			drawString(top, 10, 210, "Sending mode active.");
		}
		drawString(top, 10, 220, "Start + Select to exit.");
		
		if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
		gfxFlushBuffers();
		gspWaitForVBlank();
		gfxSwapBuffers();
	}
	
	exit: //I should really be fixing these.
	
	free(recordedIR); //Crashes the program. Should free on release.
	free(irmemloc); //Crashes the program. Should free on release.
	free(recentIR); //Crashes the program. Should free on release.
	
	IRU_Shutdown(); //Crashes the program. Should free on release.
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	
	return 0;
}
Exemplo n.º 27
0
std::tuple<u32, u32, u32> dsIn() {
	hidScanInput();
	return std::make_tuple(hidKeysDown(), hidKeysHeld(), hidKeysUp());
}
Exemplo n.º 28
0
int main(int argc, char* argv[]) {
	gfxInitDefault();
	//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
	consoleInit(GFX_TOP, &topScreen);
	consoleInit(GFX_BOTTOM,&bottomScreen);
	consoleSelect(&topScreen);
	APT_CheckNew3DS(&consoletype);
	printf("Console type:%s\n",consoletype?"New3DS. Good job!":"Old3DS. This may be a bit slow.");
	// Main loop
	while (aptMainLoop())
	{
		printf("Welcome to the adventure. Press A to continue, or any other key to exit.\n");
		hidScanInput();

		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
		u32 kDown = hidKeysDown();
		//hidKeysHeld returns information about which buttons have are held down in this frame
		u32 kHeld = hidKeysHeld();
		//hidKeysUp returns information about which buttons have been just released
		u32 kUp = hidKeysUp();
		while (!kDown) {hidScanInput(); u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); u32 kUp = hidKeysUp(); if (kDown || kHeld || kUp) printf("Down:%d Held:%d Up:%d", kDown, kHeld, kUp);}
		if (kDown & !KEY_A) break;
		else if (kDown) {
			notknow:
			rendscreen("\n\nYou are walking in a forest. You come to a part you don't know. You can go three ways. Do you go left, right, or straight? (Use the D-Pad to select) ");
			hidScanInput();

			//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
			kDown = hidKeysDown();
			//hidKeysHeld returns information about which buttons have are held down in this frame
			kHeld = hidKeysHeld();
			//hidKeysUp returns information about which buttons have been just released
			kUp = hidKeysUp();
			while (!kDown) {hidScanInput(); u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); u32 kUp = hidKeysUp();}
			if (kDown & KEY_LEFT) {
				if (ldone) {
					rendscreen("You've already gone here! (A)");
					isButtonPressed('a');
					move="0";
					goto notknow;
				}
				else {
					rendscreen("You found a chest! Inside it was 5 bars of gold. (A to continue)");
					if (input()) goto exit;
					gold +=5;
					rendscreen("It's at a dead end, however. You walk back.");
					if (input()) goto exit;
					move="0";
					ldone=true;
					goto notknow;
				}
			}
			else if (kDown & KEY_RIGHT) {
				if (rdone) {
					rendscreen("You've already gone here!");
					if (input()) goto exit;
					move="0";
				}
				else {
					rendscreen("You walk into a trap and lose a life.(A to continue)");
					if (input()) goto exit;
					lives+=-1;
					rendscreen("You walk back.");
					if (input()) goto exit;
					move="0";
					rdone=true;
				}
			}
			else if (kDown & KEY_UP) continue;
			else if (kDown & KEY_START) goto exit;
			else goto notknow;
			rendscreen("You walk forward for a while.(A to continue)");
			if (input()) goto exit;
			rendscreen("The ground begins to shake...(A to continue)");
			if (input()) goto exit;
			cls();
			print("Louder...");
			usleep(1000);
			rendscreen("You come up to a monster!");
			usleep(1000);
			rendscreen("'I will eat you!'");
			usleep(1000);
			rendscreen("How to fight: Press A to kick and B to punch.");
			if (input()) goto exit;
			rendscreen("When it's your enemy's turn, hope for the best!");
			if (input()) goto exit;
			rendscreen("Press A to start.");
			if (input()) goto exit;
			
			while (enemyh>0) {
				rendscreenf();
				char fmove='0';
				printf("Kick or punch? \n");
				while (fmove != 'K' && fmove != 'P' && fmove != 'a') {
					if (isButtonPressed('a')) fmove = 'K';
					else if (isButtonPressed('b')) fmove = 'P';
					else if (isButtonPressed('e')) {
						if (isButtonPressed('l')) fmove = 'a';
					}
					else if (isButtonPressed('t')) goto exit;
				}
				if (fmove=='K') {
					sub=floor(random()*10)+5;
					enemyh=enemyh-sub*10;
					printf("Damage dealt: %i\n",sub*10);
					if (input()) goto exit;
				}
				else if (fmove=='a') {
					enemyh=0;
				}
				else {
					sub=floor(random()*10);
					enemyh+=-sub*18;
					printf("Damage dealt: %i\n", sub*18);
					if (input()) goto exit;
				}
				rendscreenf();
				usleep(200);
				if (enemyh>0) {
					health+=-floor(random()*100);
					health+=-60;
					printf("Monster attacks! Damage dealt: %i\n", sub+60);
					if (input()) goto exit;
				}
			}
			rendscreen("You won the battle!");
			if (input()) goto exit;
			rendscreen("The monster had 20 gold and you gained two lives from defeating him!");
			gold+=20;
			lives+=2;
			if (input()) goto exit;
			rendscreen("You continue along the path.");
			if (input()) goto exit;
			char berries = 'x';
			// Entrypoint 2																											===============
			rendscreen("You find some berries.  Do you eat them? (A/B) ");
			while (berries != 'y' && berries != 'n') {
				if (isButtonPressed('a')) berries = 'y';
				else if (isButtonPressed('b')) berries = 'n';
				else if (isButtonPressed('t')) goto exit;
			}
			if (berries=='y') {
				rendscreen("Under the leaves, you found a glove!  It grants +50 health in all battles!");
				ebhealth+=50;
				special.push_back("Glove");
				if (input()) goto exit;
				rendscreen("After eating some berries, you continue walking.");
			}
			else {
				rendscreen("You continue walking.");
			}
			if (input()) goto exit;
			char river='0';
			rendscreen("After walking for quite some time, you come to a river.  There's a bear right behind you.  Do you try to cross the river? (A/B) ");
			while (river!='y' && river!='n') {
				if (isButtonPressed('a')) river = 'y';
				else if (isButtonPressed('b')) river = 'n';
				else if (isButtonPressed('t')) goto exit;
			}
			if (river=='y') {
				rendscreen("You manage to cross the river, but you get sick and lose a life.");
				lives+=-1;
			}
			else {
				rendscreen("You stay and fight the bear!");
				if (input()) goto exit;
				health=1000+ebhealth;
				enemyh=400;
				while (enemyh>0) {
					rendscreenf();
					char fmove='0';
					printf("Kick or punch? \n");
					while (fmove!='k' && fmove!='p' && fmove!='a') {
						if (isButtonPressed('a')) fmove = 'k';
						else if (isButtonPressed('b')) fmove = 'p';
						else if (isButtonPressed('e')) {if (isButtonPressed('l')) fmove = 'a';}
						else if (kDown & KEY_START) goto exit;
					}
					if (fmove=='k') {
						sub=floor(random()*10)+6;
						enemyh=enemyh-sub*10;
						printf("Damage dealt: %i\n", sub*10);
						if (input()) goto exit;
					}
					else if (fmove=='a') enemyh=0;
					else {
						sub=floor(random()*10);
						enemyh+=-sub*1.85*10;
						printf("Damage dealt: %d\n", sub*1.85*10);
						if (input()) goto exit;
					}
					rendscreenf();
					usleep(200);
					if (enemyh>0) {
						sub=floor(random()*10)*1.4*10;
						health+=-sub;
						health+=-4*10;
						printf("Bear attacks! Damage dealt: %d\n", sub+4*10);
						if (input()) goto exit;
					}
					if (health<0) {
						lives+=-1;
						health=1000+ebhealth;
					}
				}
				rendscreen("You won the battle!");
				if (input()) goto exit;
				rendscreen("You keep the fur coat from the bear.  It gives you +200 health in all battles!");
				if (input()) goto exit;
				ebhealth+=200;
				special.push_back("Fur Coat");
				rendscreen("You decide to put down a log and cross the river.");
			}
			if (input()) goto exit;
			printf("Unfortunately, this is an *alpha* release for debugging only. This is the end of the program.\n\n\n");
			usleep(2000);
			printf("Exiting...\n");
			usleep(500);
			goto exit;
		}
	}
exit:
	// Exit services
	gfxExit();
	return 0;
}
Exemplo n.º 29
0
static void eventThreadFunc(void *arg) {
	OSystem_3DS *osys = (OSystem_3DS *)g_system;
	auto eventQueue = (Common::Queue<Common::Event> *)arg;

	uint32 touchStartTime = osys->getMillis();
	touchPosition lastTouch = {0, 0};
	bool isRightClick = false;
	float cursorX = 0;
	float cursorY = 0;
	float cursorDeltaX = 0;
	float cursorDeltaY = 0;
	int circleDeadzone = 20;
	int borderSnapZone = 6;
	Common::Event event;

	while (!osys->exiting) {
		do {
			osys->delayMillis(10);
		} while (osys->sleeping && !osys->exiting);

		hidScanInput();
		touchPosition touch;
		circlePosition circle;
		u32 held = hidKeysHeld();
		u32 keysPressed = hidKeysDown();
		u32 keysReleased = hidKeysUp();

		// C-Pad used to control the cursor
		hidCircleRead(&circle);
		if (circle.dx < circleDeadzone && circle.dx > -circleDeadzone)
			circle.dx = 0;
		if (circle.dy < circleDeadzone && circle.dy > -circleDeadzone)
			circle.dy = 0;
		cursorDeltaX = (0.0002f + config.sensitivity / 100000.f) * circle.dx * abs(circle.dx);
		cursorDeltaY = (0.0002f + config.sensitivity / 100000.f) * circle.dy * abs(circle.dy);

		// Touch screen events
		if (held & KEY_TOUCH) {
			hidTouchRead(&touch);
			if (config.snapToBorder) {
				if (touch.px < borderSnapZone)
					touch.px = 0;
				if (touch.px > 319 - borderSnapZone)
					touch.px = 319;
				if (touch.py < borderSnapZone)
					touch.py = 0;
				if (touch.py > 239 - borderSnapZone)
					touch.py = 239;
			}
			cursorX = touch.px;
			cursorY = touch.py;
			osys->transformPoint(touch);

			osys->warpMouse(touch.px, touch.py);
			event.mouse.x = touch.px;
			event.mouse.y = touch.py;

			if (keysPressed & KEY_TOUCH) {
				touchStartTime = osys->getMillis();
				isRightClick = (held & KEY_X || held & KEY_DUP);
				if (inputMode == MODE_DRAG) {
					event.type = isRightClick ? Common::EVENT_RBUTTONDOWN : Common::EVENT_LBUTTONDOWN;
					pushEventQueue(eventQueue, event);
				}
			} else if (touch.px != lastTouch.px || touch.py != lastTouch.py) {
				event.type = Common::EVENT_MOUSEMOVE;
				pushEventQueue(eventQueue, event);
			}

			lastTouch = touch;
		} else if (keysReleased & KEY_TOUCH) {
			event.mouse.x = lastTouch.px;
			event.mouse.y = lastTouch.py;
			if (inputMode == MODE_DRAG) {
				event.type = isRightClick ? Common::EVENT_RBUTTONUP : Common::EVENT_LBUTTONUP;
				pushEventQueue(eventQueue, event);
			} else if (osys->getMillis() - touchStartTime < 200) {
				// Process click in MODE_HOVER
				event.type = Common::EVENT_MOUSEMOVE;
				pushEventQueue(eventQueue, event);
				event.type = isRightClick ? Common::EVENT_RBUTTONDOWN : Common::EVENT_LBUTTONDOWN;
				pushEventQueue(eventQueue, event);
				event.type = isRightClick ? Common::EVENT_RBUTTONUP : Common::EVENT_LBUTTONUP;
				pushEventQueue(eventQueue, event);
			}
		} else if (cursorDeltaX != 0 || cursorDeltaY != 0) {
			cursorX += cursorDeltaX;
			cursorY -= cursorDeltaY;
			if (cursorX < 0) cursorX = 0;
			if (cursorY < 0) cursorY = 0;
			if (cursorX > 320) cursorX = 320;
			if (cursorY > 240) cursorY = 240;
			lastTouch.px = cursorX;
			lastTouch.py = cursorY;
			osys->transformPoint(lastTouch);
			osys->warpMouse(lastTouch.px, lastTouch.py);
			event.mouse.x = lastTouch.px;
			event.mouse.y = lastTouch.py;
			event.type = Common::EVENT_MOUSEMOVE;
			pushEventQueue(eventQueue, event);
		}

		// Button events
		if (keysPressed & KEY_R) {
			if (inputMode == MODE_DRAG) {
				inputMode = MODE_HOVER;
				osys->displayMessageOnOSD("Hover Mode");
			} else {
				inputMode = MODE_DRAG;
				osys->displayMessageOnOSD("Drag Mode");
			}
		}
		if (keysPressed & KEY_A || keysPressed & KEY_DLEFT || keysReleased & KEY_A || keysReleased & KEY_DLEFT) {
			// SIMULATE LEFT CLICK
			event.mouse.x = lastTouch.px;
			event.mouse.y = lastTouch.py;
			if (keysPressed & KEY_A || keysPressed & KEY_DLEFT)
				event.type = Common::EVENT_LBUTTONDOWN;
			else
				event.type = Common::EVENT_LBUTTONUP;
			pushEventQueue(eventQueue, event);
		}
		if (keysPressed & KEY_X || keysPressed & KEY_DUP || keysReleased & KEY_X || keysReleased & KEY_DUP) {
			// SIMULATE RIGHT CLICK
			event.mouse.x = lastTouch.px;
			event.mouse.y = lastTouch.py;
			if (keysPressed & KEY_X || keysPressed & KEY_DUP)
				event.type = Common::EVENT_RBUTTONDOWN;
			else
				event.type = Common::EVENT_RBUTTONUP;
			pushEventQueue(eventQueue, event);
		}
		if (keysPressed & KEY_L) {
			event.type = Common::EVENT_VIRTUAL_KEYBOARD;
			pushEventQueue(eventQueue, event);
		}
		if (keysPressed & KEY_START) {
			event.type = Common::EVENT_MAINMENU;
			pushEventQueue(eventQueue, event);
		}
		if (keysPressed & KEY_SELECT) {
			if (!optionMenuOpened)
				optionMenuOpening = true;
		}
		if (keysPressed & KEY_B || keysReleased & KEY_B || keysPressed & KEY_DDOWN || keysReleased & KEY_DDOWN) {
			if (keysPressed & KEY_B || keysPressed & KEY_DDOWN)
				event.type = Common::EVENT_KEYDOWN;
			else
				event.type = Common::EVENT_KEYUP;
			event.kbd.keycode = Common::KEYCODE_ESCAPE;
			event.kbd.ascii = Common::ASCII_ESCAPE;
			event.kbd.flags = 0;
			pushEventQueue(eventQueue, event);
		}

		// TODO: EVENT_PREDICTIVE_DIALOG
		// EVENT_SCREEN_CHANGED
	}
}
Exemplo n.º 30
0
int main()
{
	gfxInitDefault();
        gfxSet3D(true); // uncomment if using stereoscopic 3D

        gfxFlushBuffers();

        transparent = BLACK;
	 gfxSetScreenFormat(GFX_TOP, GSP_BGR8_OES);
	 gfxSetScreenFormat(GFX_BOTTOM, GSP_BGR8_OES);
        InitParx(BLACK);
/*
	ParxLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 
	ParxRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); 
	ParxBot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); 

	ClrParx(ParxLeft, BLACK); 
	ClrParx(ParxRight, BLACK); 
	ClrParx(ParxBot, BLACK);
*/

	char* str[256];
        int l, k, j, i=20, posx = 100, posy = 100;
        TBGR rgbsam;
        TBGR rgb;
	u64 time; 

	// Main loop
	while (aptMainLoop())
	{
//		gspWaitForVBlank();

//		  	ParxLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 
//			ParxRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL); 
//			ParxBot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); 

		hidScanInput();              
		u32 kDown = hidKeysHeld();

		if (kDown & KEY_START)
			break; // break in order to return to hbmenu
                if (kDown & KEY_A)
			{
                          CanvasString(ParxBot, CopyRight(), 10,10, LIGHT_GREEN);
			}
                if (kDown & KEY_B)
			{
                          time= osGetTime();
			
			rgb.r= 0xCC;
			rgb.g= 0x33;
			rgb.b= 0xCC;
			
                        for (k=0;k<400;k++)
                          for (l=0;l<240;l++)
{
  SetPixL(k,l,rgb); //TopLCD
  SetPixR(k,l,rgb);
  if (k<320) SetPixB(k,l,rgb); //BotLCD
}

time = osGetTime() - time; 
sprintf(str, "%i:ms ParxPro SetPix L/R/B,kdl", time);
CanvasString(ParxBot, str, 10,10, GREEN);  

			}
                if (kDown & KEY_X)
			{
                          TestPattern();
			}
                if (kDown & KEY_Y)
			{
			InitParx(BLACK);
		  	
//			  PasBotfill(ParxBot);
			rgb.r= 0xFF;
			rgb.g= 0x00;
			rgb.b= 0x8F;
			  PasClrSrc(ParxBot, rgb);
			  CanvasString(ParxBot, "InitParx", 10,10, GREEN);  
			}
                if(kDown & KEY_CPAD_DOWN)
                        {	     
			rgb.r= 0x00;
			rgb.g= 0x00;
			rgb.b= 0XFF;
			PasTopfill(ParxLeft, rgb);
			PasTopfill(ParxRight, rgb);
			}

                if(kDown & KEY_CPAD_UP) 
                        {	
                        
			rgb.r= 0xFF;
			rgb.g= 0x00;
			rgb.b= 0x00;		
			PasTopfill(ParxLeft, rgb);
			PasTopfill(ParxRight, rgb);
			}
                if(kDown & KEY_CPAD_RIGHT) 
                        {	
                        
			rgb.r= 0x00;
			rgb.g= 0xFF;
			rgb.b= 0x00;
time= osGetTime();
			PasTopfill(ParxLeft, rgb);
			PasTopfill(ParxRight, rgb);

time = osGetTime() - time; 
sprintf(str, "%i:ms L&R BGRTop,kdl", time);
CanvasString(ParxBot, str, 10,10, GREEN);  
			}

                if(kDown & KEY_CPAD_LEFT)
                        {
                        
			rgb.r= 0x00;
			rgb.g= 0x11;
			rgb.b= 0x00;
time= osGetTime();					
						
			HexTopfill(ParxLeft);
			HexTopfill(ParxRight);

time = osGetTime() - time; 
sprintf(str, "%i:ms L&R TopMapLED,kdl", time);
CanvasString(ParxBot, str, 10,10, GREEN);  
			}               
                if(kDown & KEY_R)
                        {	
                              	InitBufSingle(BLACK);
                                Topfill2;
                              //  ClrParx(ParxBot, BLACK);
                               // sprintf(str, "Dergibal Rad:%i  X:%i  Y:%i", i, posx, posy);
			//	CanvasString(ParxBot, str, 0, 0, RED);
			}

                if(kDown & KEY_L) 
                        {	
                        	InitBufDub(BLACK);		
			        Topfill1;
                             //   ClrParx(ParxBot, BLACK);
                              //  sprintf(str, "Dergibal Rad:%i  X:%i  Y:%i", i, posx, posy);
			//	CanvasString(ParxBot, str, 0, 0, RED);
			}
                if(kDown & KEY_DUP)
                        {	
                        for (k=0;k<400;k++)
                          for (l=0;l<240;l++)
{
  if (k<320) PSetPixT(ParxRight,k,l, GetPixB(k,l));
} 

			}

                if(kDown & KEY_DDOWN)
                        {	
time= osGetTime();
			
			rgb.r= 0xCC;
			rgb.g= 0x11;
			rgb.b= 0xCC;
			
                        for (k=0;k<400;k++)
                          for (l=0;l<240;l++)
{
  PSetPixT(ParxRight,k,l, rgb); //TopLCD
  PSetPixT(ParxLeft,k,l, rgb);
  if (k<320) PSetPixB(ParxBot,k,l, rgb); //BotLCD
}

time = osGetTime() - time; 
sprintf(str, "%i:ms ParxPro,kdl", time);
CanvasString(ParxBot, str, 10,10, GREEN);  
		
			}                
		if(kDown & KEY_DRIGHT)
                        {

                         ClrParx(ParxBot, BLACK);    
                          
			rgb.r= 0xEE;
			rgb.g= 0x00;
			rgb.b= 0xCC;
		
time= osGetTime();			
                       for (k=0;k<400;k++)
                          for (l=0;l<240;l++) SetPixL(k,l,rgb); //TopLCD
time = osGetTime() - time; 
sprintf(str, "Left %i:ms ParxPro,kdl", time);
CanvasString(ParxBot, str, 10,10, LIGHT_GREEN); 

time= osGetTime();			
                       for (k=0;k<400;k++)
                          for (l=0;l<240;l++) SetPixR(k,l,rgb);                       
time = osGetTime() - time; 
sprintf(str, "Right %i:ms ParxPro,kdl", time);
CanvasString(ParxBot, str, 10,20, LIGHT_GREEN); 
			}

                if(kDown & KEY_DLEFT)
                        {				
                     //   SetTopFramebuffers(0);  
time= osGetTime();
			
                        for (k=0;k<400;k++)
                          for (l=0;l<240;l++)
{
  SetPix(ParxRight,k,l,BLACK);
  SetPix(ParxLeft,k,l,BLACK);
  if (k<320) SetPix(ParxBot,k,l,BLACK);
}

time = osGetTime() - time; 
sprintf(str, "%i:ms Parx-GDI,kdl", time);
CanvasString(ParxBot, str, 10,10, GREEN);  
		}
//gfxString(ParxRight, str, 30,30, 3, rgb); 
//gfxString(ParxLeft, str, 30,30, 3, rgb);   
//for (l=1;l<16;l++) print3d(rgb,10*l,10*l,l-1,3,str);



		//render rainbow
//		renderEffect();
		//copy buffer to lower screen (don't have to do it every frame)
//		memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size);
		//wait & swap
//		gfxSwapBuffersGpu();
//		gspWaitForEvent(GSPGPU_EVENT_VBlank0, false);

		// Flush and swap framebuffers
	//	gfxFlushBuffers();
	//	gfxSwapBuffers();
        	RefreshBuffer();
		//Wait for VBlank
		gspWaitForVBlank();
	}

	gfxExit();
	return 0;
}