Esempio n. 1
0
static int set_joystick_fire(int value, void *param)
{
    ULONG portstate;
    int port_idx = vice_ptr_to_int(param);
    int joy_dev = joystick_port_map[port_idx];

    joy_arch_init();

    if (joy_dev != JOYDEV_NONE) {
        if (joy_dev >= JOYDEV_JOY0 && joy_dev <= JOYDEV_JOY3) {
            portstate = ReadJoyPort(joy_dev - JOYDEV_JOY0);
            if ((portstate & JP_TYPE_MASK) != JP_TYPE_GAMECTLR) {
                if (value != JPF_BUTTON_RED) {
                    ui_error(translate_text(IDMES_DEVICE_NOT_GAMEPAD));
                    value = JPF_BUTTON_RED;
                }
            }
        } else {
            ui_error(translate_text(IDMES_NOT_MAPPED_TO_AMIGA_PORT));
            return -1;
        }
    } else {
        if (value != JPF_BUTTON_RED) {
            ui_error(translate_text(IDMES_NOT_MAPPED_TO_AMIGA_PORT));
            return -1;
        }
    }
    joystick_fire[port_idx] = value;

    return 0;
}
Esempio n. 2
0
static void joyll_update(ULONG amiga_dev, int port_idx)
{
    ULONG portstate;
    BYTE value = 0;

    if (!lowlevel_lib_loaded) {
        return;
    }

    portstate = ReadJoyPort(amiga_dev);

    if (portstate & JPF_JOY_UP) {
        value |= 1;
    }
    if (portstate & JPF_JOY_DOWN) {
        value |= 2;
    }
    if (portstate & JPF_JOY_LEFT) {
        value |= 4;
    }
    if (portstate & JPF_JOY_RIGHT) {
        value |= 8;
    }
    if (portstate & joystick_fire[port_idx]) {
        value |= 16;
    }

    joystick_set_value_absolute(port_idx + 1, value);
}
Esempio n. 3
0
int joy_arch_set_device(int port_idx, int joy_dev)
{
    ULONG portstate;

    switch (joy_dev) {
        case JOYDEV_NONE:
        case JOYDEV_NUMPAD:
        case JOYDEV_KEYSET1:
        case JOYDEV_KEYSET2:
        case JOYDEV_JOY0:
        case JOYDEV_JOY1:
        case JOYDEV_JOY2:
        case JOYDEV_JOY3:
            break;
        default:
            return -1;
    }

    joy_arch_init();

    if (joy_dev >= JOYDEV_JOY0) {
        portstate = ReadJoyPort(joy_dev - JOYDEV_JOY0);
        if ((portstate & JP_TYPE_MASK) == JP_TYPE_JOYSTK) {
            joystick_fire[port_idx] = JPF_BUTTON_RED;
        }
    }

    return 0;
}
Esempio n. 4
0
static void read_joy (uint32_t nr)
{
    if (LowLevelBase != NULL) {
	ULONG state = ReadJoyPort (nr);

	if ((state & JP_TYPE_MASK) != JP_TYPE_NOTAVAIL) {
	    int32_t x = 0, y = 0;

	    if (state & JPF_JOY_UP)
		y = -1;
	    else if (state & JPF_JOY_DOWN)
		y = 1;
	    if (state & JPF_JOY_LEFT)
		x = -1;
	    else if (state & JPF_JOY_RIGHT)
		x = 1;

	    setjoystickstate (nr, 0, x, 1);
	    setjoystickstate (nr, 1, y, 1);

	    setjoybuttonstate (nr, 0, state & JPF_BUTTON_RED);
	    setjoybuttonstate (nr, 1, state & JPF_BUTTON_BLUE);
	}
    }
}
Esempio n. 5
0
static int set_joystick_fire_4(int value, void *param)
{
    ULONG portstate;

    joy_arch_init();

    if (joystick_device[3] != JOYDEV_NONE) {
        if (joystick_device[3] >= JOYDEV_JOY0 && joystick_device[3] <= JOYDEV_JOY3) {
            portstate = ReadJoyPort(joystick_device[3] - JOYDEV_JOY0);
            if ((portstate & JP_TYPE_MASK) != JP_TYPE_GAMECTLR) {
                if (value != JPF_BUTTON_RED) {
                    ui_error(translate_text(IDMES_DEVICE_NOT_GAMEPAD));
                    value = JPF_BUTTON_RED;
                }
            }
        } else {
            ui_error(translate_text(IDMES_NOT_MAPPED_TO_AMIGA_PORT));
            return -1;
        }
    } else {
        if (value != JPF_BUTTON_RED) {
            ui_error(translate_text(IDMES_NOT_MAPPED_TO_AMIGA_PORT));
            return -1;
        }
    }
    joystick_fire[3] = value;

    return 0;
}
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
{
	ULONG temp,i;
	D(bug("Opening joystick %ld\n",joystick->index));

	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata))))
		return -1;

/* This loop is to check if the controller is a joypad */

	for(i=0;i<20;i++)
	{
		temp=ReadJoyPort(joystick->index^1); // fix to invert amiga joyports
		WaitTOF();
	}

	if((temp&JP_TYPE_MASK)==JP_TYPE_GAMECTLR)
		joystick->nbuttons=7;
	else
		joystick->nbuttons=3;

	joystick->nhats=0;
	joystick->nballs=0;
	joystick->naxes=2;
	joystick->hwdata->joystate=0L;

	return 0;
}
Esempio n. 7
0
static int set_joystick_device_2(int val, void *param)
{
    ULONG portstate;

    joy_arch_init();

    if (val >= JOYDEV_JOY0 && val <= JOYDEV_JOY3) {
        portstate = ReadJoyPort(val - JOYDEV_JOY0);
        if ((portstate & JP_TYPE_MASK) == JP_TYPE_JOYSTK) {
            joystick_fire[1] = JPF_BUTTON_RED;
        }
    }
    joystick_device[1] = val;

    return 0;
}
Esempio n. 8
0
static void IN_HandleJoystick (void)
{
	ULONG joyflag;

	if (!LowLevelBase || joy_port == -1)
		return;

	joyflag = ReadJoyPort(joy_port);

	if (joyflag != oldjoyflag)
	{
		switch (joyflag & JP_TYPE_MASK)
		{
		case JP_TYPE_GAMECTLR:
			Check_Joy_Event(K_JOY1, joyflag, oldjoyflag, JPF_BUTTON_BLUE);
			Check_Joy_Event(K_JOY2, joyflag, oldjoyflag, JPF_BUTTON_RED);
			Check_Joy_Event(K_JOY3, joyflag, oldjoyflag, JPF_BUTTON_YELLOW);
			Check_Joy_Event(K_JOY4, joyflag, oldjoyflag, JPF_BUTTON_GREEN);
			Check_Joy_Event(K_AUX1, joyflag, oldjoyflag, JPF_BUTTON_FORWARD);
			Check_Joy_Event(K_AUX2, joyflag, oldjoyflag, JPF_BUTTON_REVERSE);
			Check_Joy_Event(K_AUX3, joyflag, oldjoyflag, JPF_BUTTON_PLAY);
			Check_Joy_Event(K_AUX29, joyflag, oldjoyflag, JPF_JOY_UP);
			Check_Joy_Event(K_AUX30, joyflag, oldjoyflag, JPF_JOY_DOWN);
			Check_Joy_Event(K_AUX31, joyflag, oldjoyflag, JPF_JOY_LEFT);
			Check_Joy_Event(K_AUX32, joyflag, oldjoyflag, JPF_JOY_RIGHT);
			break;
		case JP_TYPE_JOYSTK:
			Check_Joy_Event(K_JOY1, joyflag, oldjoyflag, JPF_BUTTON_BLUE);
			Check_Joy_Event(K_JOY2, joyflag, oldjoyflag, JPF_BUTTON_RED);
			Check_Joy_Event(K_AUX29, joyflag, oldjoyflag, JPF_JOY_UP);
			Check_Joy_Event(K_AUX30, joyflag, oldjoyflag, JPF_JOY_DOWN);
			Check_Joy_Event(K_AUX31, joyflag, oldjoyflag, JPF_JOY_LEFT);
			Check_Joy_Event(K_AUX32, joyflag, oldjoyflag, JPF_JOY_RIGHT);
			break;
		default:
			/* nothing to do here */
			break;
		}
		oldjoyflag = joyflag;
	}
}
Esempio n. 9
0
static struct InputEvent *IN_KeyboardHandlerFunc()
{
	struct InputEvent *moo = (struct InputEvent *)REG_A0;
	struct inputdata *id = (struct inputdata *)REG_A1;
#else
HANDLERPROTO(IN_KeyboardHandler, struct InputEvent *, struct InputEvent *moo, APTR id)
{
#endif
	struct InputEvent *coin;

	ULONG screeninfront;

	if (!window || !(window->Flags & WFLG_WINDOWACTIVE))
		return moo;

	if (window->WScreen)
	{
#ifdef __MORPHOS__
		if (IntuitionBase->LibNode.lib_Version > 50 || (IntuitionBase->LibNode.lib_Version == 50 && IntuitionBase->LibNode.lib_Revision >= 56))
			GetAttr(SA_Displayed, window->WScreen, &screeninfront);
		else
#endif
			screeninfront = (window->WScreen == IntuitionBase->FirstScreen);
	}
	else
		screeninfront = 1;

	for (coin = moo; coin; coin = coin->ie_NextEvent)
	{
		if (coin->ie_Class == IECLASS_RAWKEY)
		{
			int code;
			
			// mouse button 4, mouse wheel and keyboard
			code = coin->ie_Code & ~IECODE_UP_PREFIX;
			if (code >= NM_WHEEL_UP && code <= NM_BUTTON_FOURTH)
			{
				// we don't need these, they will be handled under IECLASS_NEWMOUSE
				/*if (mouseactive && screeninfront)
				{
					IN_AddEvent(coin);
					coin->ie_Code = IECODE_NOBUTTON;
				}*/
			}
			else
			{
				IN_AddEvent(coin);
			}
		}
		else if (coin->ie_Class == IECLASS_RAWMOUSE && mouseactive && screeninfront)
		{
			// mouse buttons 1-3
			if (coin->ie_Code != IECODE_NOBUTTON)
			{
				IN_AddEvent(coin);
				coin->ie_Code = IECODE_NOBUTTON;
			}

			// mouse movement
			mx += coin->ie_position.ie_xy.ie_x;
			my += coin->ie_position.ie_xy.ie_y;
			coin->ie_position.ie_xy.ie_x = 0;
			coin->ie_position.ie_xy.ie_y = 0;
		}
		else if (coin->ie_Class == IECLASS_NEWMOUSE && mouseactive && screeninfront)
		{
			// mouse button 4, mouse wheel
			IN_AddEvent(coin);
			coin->ie_Code = IECODE_NOBUTTON;
		}
	}

	return moo;
}
//MakeHandlerPri(InputHandler, &IN_KeyboardHandler, "Hexen II input handler", NULL, 100);

/*
===========
IN_Init
===========
*/
void IN_Init (void)
{
	static char handler_name[] = "Hexen II input handler";

	/* mouse variables */
	Cvar_RegisterVariable (&m_filter);
	/* joystick variables */
	Cvar_RegisterVariable (&in_joystick);
	Cvar_RegisterVariable (&joy_index);

	Cvar_SetCallback (&in_joystick, IN_Callback_JoyEnable);
	Cvar_SetCallback (&joy_index, IN_Callback_JoyIndex);

	Cmd_AddCommand ("force_centerview", Force_CenterView_f);

	pointermem = (UWORD *) AllocVec(2 * 6, MEMF_CHIP | MEMF_CLEAR);

	IN_StartupMouse ();
	IN_StartupJoystick ();

	imsglow = imsghigh = 0;

	inputport = CreateMsgPort();
	if (inputport)
	{
		//inputreq = (struct IOStdReq *) CreateIORequest(inputport, sizeof(*inputreq));
		inputreq = CreateStdIO(inputport);
		if (inputreq)
		{
			if (!OpenDevice("input.device", 0, (struct IORequest *)inputreq, 0))
			{
				InputHandler.is_Node.ln_Type = NT_INTERRUPT;
				InputHandler.is_Node.ln_Pri = 100;
				InputHandler.is_Node.ln_Name = handler_name;
				InputHandler.is_Code = (void (*)())&IN_KeyboardHandler;
				inputreq->io_Data = (void *)&InputHandler;
				inputreq->io_Command = IND_ADDHANDLER;
				DoIO((struct IORequest *)inputreq);
				return;
			}
			//DeleteIORequest(inputreq);
			DeleteStdIO(inputreq);
		}
		DeleteMsgPort(inputport);
	}

	Sys_Error ("Couldn't install input handler");
}

/*
===========
IN_Shutdown
===========
*/
void IN_Shutdown (void)
{
	if (inputreq)
	{
		inputreq->io_Data = (void *)&InputHandler;
		inputreq->io_Command = IND_REMHANDLER;
		DoIO((struct IORequest *)inputreq);

		CloseDevice((struct IORequest *)inputreq);
		//DeleteIORequest(inputreq);
		DeleteStdIO(inputreq);
	}

	if (inputport)
	{
		DeleteMsgPort(inputport);
	}

	IN_DeactivateMouse ();
	/*IN_ShowMouse ();*/

	if (pointermem)
	{
		FreeVec(pointermem);
	}

	mouseinitialized = false;

	if (LowLevelBase)
	{
		CloseLibrary(LowLevelBase);
		LowLevelBase = NULL;
	}

	joy_port = -1;
	joy_available = 0;
	oldjoyflag = 0;

#ifdef __CLIB2__
	if (KeymapBase) {
		CloseLibrary(KeymapBase);
		KeymapBase = NULL;
	}
#endif
}

/*
===========
IN_ReInit
===========
*/
void IN_ReInit (void)
{
	IN_StartupMouse ();
}


/*
===========
IN_MouseMove
===========
*/
static void IN_MouseMove (usercmd_t *cmd/*, int mx, int my*/)
{
	if (m_filter.integer)
	{
		mouse_x = (mx + old_mouse_x) * 0.5;
		mouse_y = (my + old_mouse_y) * 0.5;
	}
	else
	{
		mouse_x = mx;
		mouse_y = my;
	}

	old_mouse_x = mx;
	old_mouse_y = my;

	mouse_x *= sensitivity.value;
	mouse_y *= sensitivity.value;

/* add mouse X/Y movement to cmd */
	if ( (in_strafe.state & 1) || (lookstrafe.integer && (in_mlook.state & 1) ))
		cmd->sidemove += m_side.value * mouse_x;
	else
		cl.viewangles[YAW] -= m_yaw.value * mouse_x;

	if (in_mlook.state & 1)
	{
		if (mx || my)
			V_StopPitchDrift ();
	}

	if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
	{
		cl.viewangles[PITCH] += m_pitch.value * mouse_y;
		if (cl.viewangles[PITCH] > 80)
			cl.viewangles[PITCH] = 80;
		if (cl.viewangles[PITCH] < -70)
			cl.viewangles[PITCH] = -70;
	}
	else
	{
		if ((in_strafe.state & 1) && (cl.v.movetype == MOVETYPE_NOCLIP))
			cmd->upmove -= m_forward.value * mouse_y;
		else
			cmd->forwardmove -= m_forward.value * mouse_y;
	}

	if (cl.idealroll == 0) /* Did keyboard set it already?? */
	{
		if (cl.v.movetype == MOVETYPE_FLY)
		{
			if (mouse_x < 0)
				cl.idealroll = -10;
			else if (mouse_x > 0)
				cl.idealroll = 10;
		}
	}
}

static void IN_DiscardMove (void)
{
	if (mouseinitialized)
	{
		mx = my = old_mouse_x = old_mouse_y = 0;
	}
}

/*
===========
IN_Move
===========
*/
void IN_Move (usercmd_t *cmd)
{
	if (cl.v.cameramode)
	{
	/* stuck in a different camera so don't move */
		memset (cmd, 0, sizeof(*cmd));
	/* ignore any mouse movements in camera mode */
		IN_DiscardMove ();
		return;
	}

	if (mx != 0 || my != 0)
	{
		IN_MouseMove (cmd/*, x, y*/);
		mx = my = 0;
	}
}

static const char *JoystickName(int port)
{
	ULONG joyflag = ReadJoyPort(port);

	switch (joyflag & JP_TYPE_MASK)
	{
	case JP_TYPE_GAMECTLR:
		return "game controller";
	case JP_TYPE_JOYSTK:
		return "joystick controller";
	case JP_TYPE_MOUSE:
		return "mouse";
	case JP_TYPE_NOTAVAIL:
		return "not available";
	case JP_TYPE_UNKNOWN:
		return "unknown device";
	default:
		return "<unknown>";
	}
}
Esempio n. 10
0
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
{
	ULONG data;
	int i;

	if(joystick->index<2)
	{
		data=ReadJoyPort(joystick->index);

		if(data&JP_DIRECTION_MASK)
		{
			if(data&JPF_JOY_DOWN)
			{
				if(!(joystick->hwdata->joystate&JPF_JOY_DOWN))
					SDL_PrivateJoystickAxis(joystick,0,127);
			}
			else if(data&JPF_JOY_UP)
			{
				if(!(joystick->hwdata->joystate&JPF_JOY_UP))
					SDL_PrivateJoystickAxis(joystick,0,-127);
			}
			else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN))
				SDL_PrivateJoystickAxis(joystick,0,0);

			if(data&JPF_JOY_LEFT)
			{
				if(!(joystick->hwdata->joystate&JPF_JOY_LEFT))
					SDL_PrivateJoystickAxis(joystick,1,-127);
			}
			else if(data&JPF_JOY_RIGHT)
			{
				if(!(joystick->hwdata->joystate&JPF_JOY_RIGHT))
					SDL_PrivateJoystickAxis(joystick,1,127);
			}
			else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT))
				SDL_PrivateJoystickAxis(joystick,1,0);
		}
		else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT))
		{
				SDL_PrivateJoystickAxis(joystick,1,0);
		}
		else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN))
		{
				SDL_PrivateJoystickAxis(joystick,0,0);
		}

		for(i=0;i<joystick->nbuttons;i++)
		{
			if( (data&joybut[i]) )
			{
				if(i==1)
					data&=(~(joybut[2]));

				if(!(joystick->hwdata->joystate&joybut[i]))
					SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
			}
			else if(joystick->hwdata->joystate&joybut[i])
				SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
		}

		joystick->hwdata->joystate=data;
	}

	return;
}