Exemplo n.º 1
0
static void report_buttons()
{
   static int frame = 0;
   int _x, _y;
   for (int port = SNES_PORT_1; port <= SNES_PORT_2; port++)
   {
      switch (snes_devices[port])
      {
         case SNES_DEVICE_JOYPAD:
            for (int i = BTN_FIRST; i <= BTN_LAST; i++)
               S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JOYPAD, 0, i));
            break;

         case SNES_DEVICE_MULTITAP:
            for (int j = 0; j < 4; j++)
               for (int i = BTN_FIRST; i <= BTN_LAST; i++)
                  S9xReportButton(MAKE_BUTTON(j + 2, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MULTITAP, j, i));
            break;

         case SNES_DEVICE_MOUSE:
            _x = s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MOUSE, 0, SNES_DEVICE_ID_MOUSE_X);
            _y = s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MOUSE, 0, SNES_DEVICE_ID_MOUSE_Y);
            snes_mouse_state[port][0] += _x;
            snes_mouse_state[port][1] += _y;
            fprintf(stderr, "Frame: %d, _x: %d, _y: %d, Mouse state: %d, %d\n", frame++, _x, _y, (int)snes_mouse_state[port][0], (int)snes_mouse_state[port][1]);
            S9xReportPointer(BTN_POINTER + port, snes_mouse_state[port][0], snes_mouse_state[port][1]);
            for (int i = MOUSE_LEFT; i <= MOUSE_LAST; i++)
               S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MOUSE, 0, i));
            break;

         case SNES_DEVICE_SUPER_SCOPE:
            snes_scope_state[0] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_SUPER_SCOPE, 0, SNES_DEVICE_ID_SUPER_SCOPE_X);
            snes_scope_state[1] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_SUPER_SCOPE, 0, SNES_DEVICE_ID_SUPER_SCOPE_Y);
            S9xReportPointer(BTN_POINTER, snes_scope_state[0], snes_scope_state[1]);
            for (int i = SCOPE_TRIGGER; i <= SCOPE_LAST; i++)
               S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_SUPER_SCOPE, 0, i));
            break;

         case SNES_DEVICE_JUSTIFIER:
         case SNES_DEVICE_JUSTIFIERS:
            snes_justifier_state[0][0] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JUSTIFIER, 0, SNES_DEVICE_ID_JUSTIFIER_X);
            snes_justifier_state[0][1] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JUSTIFIER, 0, SNES_DEVICE_ID_JUSTIFIER_Y);
            S9xReportPointer(BTN_POINTER, snes_justifier_state[0][0], snes_justifier_state[0][1]);
            for (int i = JUSTIFIER_TRIGGER; i <= JUSTIFIER_LAST; i++)
               S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JUSTIFIER, 0, i));
            break;
            
         default:
            fprintf(stderr, "[libsnes]: Unknown device...\n");

      }
   }
}
Exemplo n.º 2
0
void
S9xProcessEvents (bool8 block)
{
#ifdef USE_JOYSTICK
    JoyEvent event;
    Binding  binding;

    if (S9xGrabJoysticks ())
    {
        for (int i = 0; gui_config->joystick[i]; i++)
        {
            while (gui_config->joystick[i]->get_event (&event))
            {
                binding = Binding (i, event.parameter, 0);
                S9xReportButton (binding.hex (), event.state == JOY_PRESSED ? 1 : 0);
                gui_config->screensaver_needs_reset = TRUE;
            }
        }

        S9xReleaseJoysticks ();
    }
#endif

    return;
}
Exemplo n.º 3
0
void S9xProcessEvents (bool8 block)
{
    #ifdef USE_SDL
	SDL_Event event;
	bool8 quit_state = FALSE;

	while ((block) || (SDL_PollEvent (&event) != 0))
	{
		switch (event.type) {
		case SDL_KEYDOWN:
		case SDL_KEYUP:
			// domaemon: not sure it's the best idea, but reserving the SDLK_q for quit.
			if (event.key.keysym.sym == SDLK_q)
			{
				quit_state = TRUE;
			}
			else
			{
				S9xReportButton(event.key.keysym.mod << 16 | // keyboard mod
						event.key.keysym.sym, // keyboard ksym
						event.type == SDL_KEYDOWN); // press or release
			}
			break;


		case SDL_QUIT:
			// domaemon: we come here when the window is getting closed.
			quit_state = TRUE;
			break;
		}
	}

	if (quit_state == TRUE)
	{
		printf ("Quit Event. Bye.\n");
		S9xExit();
	}
    #endif
}
Exemplo n.º 4
0
static void report_buttons()
{
	int i, j, _x, _y, port;
	for ( port = SNES_PORT_1; port <= SNES_PORT_2; port++)
	{
		switch (snes_devices[port])
		{
			case SNES_DEVICE_JOYPAD:
				for ( i = BTN_FIRST; i <= BTN_LAST; i++)
				{
					s9xcommand_t cmd = keymap[MAKE_BUTTON(port + 1, i)];
					uint16 r = cmd.commandunion.button.joypad;
					bool pressed = s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JOYPAD, 0, i);

					if (pressed)
						joypad[port] |= r;
					else
						joypad[port] &= ~r;
				}
				break;
			case SNES_DEVICE_MULTITAP:
				for ( j = 0; j < 4; j++)
				{
					for ( i = BTN_FIRST; i <= BTN_LAST; i++)
					{
						s9xcommand_t cmd = keymap[MAKE_BUTTON(j + 2, i)];
						uint16 r = cmd.commandunion.button.joypad;
						bool pressed = s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MULTITAP, j, i);

						if (pressed)
							joypad[j] |= r;
						else
							joypad[j] &= ~r;
					}
				}
				break;

			case SNES_DEVICE_MOUSE:
				_x = s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MOUSE, 0, SNES_DEVICE_ID_MOUSE_X);
				_y = s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MOUSE, 0, SNES_DEVICE_ID_MOUSE_Y);
				snes_mouse_state[port][0] += _x;
				snes_mouse_state[port][1] += _y;
				S9xReportPointer(BTN_POINTER + port, snes_mouse_state[port][0], snes_mouse_state[port][1]);
				for ( i = MOUSE_LEFT; i <= MOUSE_LAST; i++)
					S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_MOUSE, 0, i));
				break;

			case SNES_DEVICE_SUPER_SCOPE:
				snes_scope_state[0] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_SUPER_SCOPE, 0, SNES_DEVICE_ID_SUPER_SCOPE_X);
				snes_scope_state[1] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_SUPER_SCOPE, 0, SNES_DEVICE_ID_SUPER_SCOPE_Y);
				S9xReportPointer(BTN_POINTER, snes_scope_state[0], snes_scope_state[1]);
				for ( i = SCOPE_TRIGGER; i <= SCOPE_LAST; i++)
					S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_SUPER_SCOPE, 0, i));
				break;

			case SNES_DEVICE_JUSTIFIER:
			case SNES_DEVICE_JUSTIFIERS:
				snes_justifier_state[0][0] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JUSTIFIER, 0, SNES_DEVICE_ID_JUSTIFIER_X);
				snes_justifier_state[0][1] += s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JUSTIFIER, 0, SNES_DEVICE_ID_JUSTIFIER_Y);
				S9xReportPointer(BTN_POINTER, snes_justifier_state[0][0], snes_justifier_state[0][1]);
				for ( i = JUSTIFIER_TRIGGER; i <= JUSTIFIER_LAST; i++)
					S9xReportButton(MAKE_BUTTON(port + 1, i), s9x_input_state_cb(port == SNES_PORT_2, SNES_DEVICE_JUSTIFIER, 0, i));
				break;

			default:
				fprintf(stderr, "[libsnes]: Unknown device...\n");

		}
	}
}
Exemplo n.º 5
0
extern "C" void SISetControllerReleaseButton(unsigned long button)
{
  S9xReportButton((uint32)button, (bool)0);
}
Exemplo n.º 6
0
extern "C" void SISetControllerPushButton(unsigned long button)
{
  S9xReportButton((uint32)button, (bool)1);
}
Exemplo n.º 7
0
void decodepad (int pad)
{
  int i, offset;
  float t;

  signed char pad_x = PAD_StickX (pad);
  signed char pad_y = PAD_StickY (pad);
  u32 jp = PAD_ButtonsHeld (pad);

#ifdef HW_RVL
  signed char wm_ax = 0;
  signed char wm_ay = 0;
  u32 wp = 0;
  wm_ax = WPAD_StickX ((u8)pad, 0);
  wm_ay = WPAD_StickY ((u8)pad, 0);
  wp = WPAD_ButtonsHeld (pad);

  u32 exp_type;
  if ( WPAD_Probe(pad, &exp_type) != 0 ) exp_type = WPAD_EXP_NONE;
#endif

	/***
	Gamecube Joystick input
	***/
	// Is XY inside the "zone"?
	if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL)
	{
		/*** we don't want division by zero ***/
	    if (pad_x > 0 && pad_y == 0)
			jp |= PAD_BUTTON_RIGHT;
	    if (pad_x < 0 && pad_y == 0)
			jp |= PAD_BUTTON_LEFT;
	    if (pad_x == 0 && pad_y > 0)
			jp |= PAD_BUTTON_UP;
	    if (pad_x == 0 && pad_y < 0)
			jp |= PAD_BUTTON_DOWN;

	    if (pad_x != 0 && pad_y != 0)
		{

			/*** Recalc left / right ***/
			t = (float) pad_y / pad_x;
			if (t >= -2.41421356237 && t < 2.41421356237)
			{
				if (pad_x >= 0)
					jp |= PAD_BUTTON_RIGHT;
				else
					jp |= PAD_BUTTON_LEFT;
			}

			/*** Recalc up / down ***/
			t = (float) pad_x / pad_y;
			if (t >= -2.41421356237 && t < 2.41421356237)
			{
				if (pad_y >= 0)
					jp |= PAD_BUTTON_UP;
				else
					jp |= PAD_BUTTON_DOWN;
			}
		}
	}
#ifdef HW_RVL
	/***
	Wii Joystick (classic, nunchuk) input
	***/
	// Is XY inside the "zone"?
	if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL)
	{
		/*** we don't want division by zero ***/
	    if (wm_ax > 0 && wm_ay == 0)
			wp |= WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT;
	    if (wm_ax < 0 && wm_ay == 0)
			wp |= WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT;
	    if (wm_ax == 0 && wm_ay > 0)
			wp |= WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP;
	    if (wm_ax == 0 && wm_ay < 0)
			wp |= WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN;

	    if (wm_ax != 0 && wm_ay != 0)
		{

			/*** Recalc left / right ***/
			t = (float) wm_ay / wm_ax;
			if (t >= -2.41421356237 && t < 2.41421356237)
			{
				if (wm_ax >= 0)
					wp |= WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT;
				else
					wp |= WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT;
			}

			/*** Recalc up / down ***/
			t = (float) wm_ax / wm_ay;
			if (t >= -2.41421356237 && t < 2.41421356237)
			{
				if (wm_ay >= 0)
					wp |= WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP;
				else
					wp |= WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN;
			}
		}
	}
#endif

	/*** Fix offset to pad ***/
	offset = ((pad + 1) << 4);

	/*** Report pressed buttons (gamepads) ***/
	for (i = 0; i < MAXJP; i++)
    {
		if ( (jp & gcpadmap[i])											// gamecube controller
#ifdef HW_RVL
		|| ( (exp_type == WPAD_EXP_NONE) && (wp & wmpadmap[i]) )	// wiimote
		|| ( (exp_type == WPAD_EXP_CLASSIC) && (wp & ccpadmap[i]) )	// classic controller
		|| ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & ncpadmap[i]) )	// nunchuk + wiimote
#endif
		)
			S9xReportButton (offset + i, true);
		else
			S9xReportButton (offset + i, false);
    }

	/*** Superscope ***/
	if (Settings.SuperScopeMaster && pad == GCSettings.Superscope-1)	// report only once
	{
		// buttons
		offset = 0x50;
		for (i = 0; i < 6; i++)
		{
		  if ( jp & gcscopemap[i]
#ifdef HW_RVL
				|| wp & wmscopemap[i]
#endif
		  )
			S9xReportButton (offset + i, true);
		  else
			S9xReportButton (offset + i, false);
		}
		// pointer
		offset = 0x80;
		UpdateCursorPosition (pad, cursor_x[0], cursor_y[0]);
		S9xReportPointer(offset, (u16)cursor_x[0], (u16)cursor_y[0]);
	}
	/*** Mouse ***/
	else if (Settings.MouseMaster && pad < GCSettings.Mouse)
	{
		// buttons
		offset = 0x60+(2*pad);
		for (i = 0; i < 2; i++)
		{
		  if ( jp & gcmousemap[i]
#ifdef HW_RVL
				|| wp & wmmousemap[i]
#endif
		  )
			S9xReportButton (offset + i, true);
		  else
			S9xReportButton (offset + i, false);
		}
		// pointer
		offset = 0x81;
		UpdateCursorPosition (pad, cursor_x[1+pad], cursor_y[1+pad]);
		S9xReportPointer(offset+pad, (u16)cursor_x[1+pad], (u16)cursor_y[1+pad]);
	}
	/*** Justifier ***/
	else if (Settings.JustifierMaster && pad < GCSettings.Justifier)
	{
		// buttons
		offset = 0x70+(3*pad);
		for (i = 0; i < 3; i++)
		{
		  if ( jp & gcjustmap[i]
#ifdef HW_RVL
				|| wp & wmjustmap[i]
#endif
		  )
			S9xReportButton (offset + i, true);
		  else
			S9xReportButton (offset + i, false);
		}
		// pointer
		offset = 0x83;
		UpdateCursorPosition (pad, cursor_x[3+pad], cursor_y[3+pad]);
		S9xReportPointer(offset+pad, (u16)cursor_x[3+pad], (u16)cursor_y[3+pad]);
	}
}