Beispiel #1
0
/* poll joystick */
void joystick(void)
{
    int i;

    /* handle both virtual cbm joystick ports */
    for (i = 0; i < 4; i++) {
        /* what kind of device is connected to the virtual port? */ 
        int joy_port = joystick_port_map[i];
    
        /* is HID joystick A mapped? */
        if (joy_port == JOYDEV_HID_0) {
            if (joy_a.mapped) {
                BYTE joy_bits = read_joystick(&joy_a);
                joystick_set_value_absolute(i + 1, joy_bits);
            }
        }
        /* is HID joystick B mapped? */
        else if (joy_port == JOYDEV_HID_1) {
            if (joy_b.mapped) {
                BYTE joy_bits = read_joystick(&joy_b);
                joystick_set_value_absolute(i + 1, joy_bits);
            }
        }
    }
}
Beispiel #2
0
/* called on key-up event */
int joystick_check_clr(signed long key, int keysetnum, unsigned int joyport)
{
    int column, value;

    /* if joykeys are disabled then ignore key sets */
    if (!joykeys_enable) {
        return 0;
    }

    for (column = 0; column < JOYSTICK_KEYSET_NUM_KEYS; column++) {
        if (key == joykeys[keysetnum][column]) {
            joypad_status[keysetnum][column] = 0;
            value = getjoyvalue(joypad_status[keysetnum]);

            if (!joystick_opposite_enable) {
                /* if two opposite directions are set, mask out the opposite side of
                 * the last pressed key */
                if ((value & joypad_bits[JOYSTICK_KEYSET_N]) && (value & joypad_bits[JOYSTICK_KEYSET_S])) {
                    value &= joypad_vmask[keysetnum];
                }
                if ((value & joypad_bits[JOYSTICK_KEYSET_E]) && (value & joypad_bits[JOYSTICK_KEYSET_W])) {
                    value &= joypad_hmask[keysetnum];
                }
            }

            joystick_set_value_absolute(joyport, (BYTE)value);

            DBG(("joystick_check_clr:"));
            DBGSTATUS(keysetnum, value, joyport, key, 1);
            return 1;
        }
    }
    return 0;
}
Beispiel #3
0
int joystick_check_set(signed long key, int keysetnum, unsigned int joyport)
{
    int column;

    /* if joykeys are disabled then ignore key sets */
    if (!joykeys_enable) {
        return 0;
    }

    for (column = 0; column < 9; column++) {
        if (key == joykeys[keysetnum][column]) {
            if (joypad_bits[column]) {
                /*joystick_value[joyport] |= joypad_bits[column];*/
                joystick_set_value_or(joyport, (BYTE)joypad_bits[column]);
                joypad_status[keysetnum][column] = 1;
            } else {
                /*joystick_value[joyport] = 0;*/
                joystick_set_value_absolute(joyport, 0);
                memset(joypad_status[keysetnum], 0, sizeof(joypad_status[keysetnum]));
            }
            return 1;
        }
    }
    return 0;
}
Beispiel #4
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);
}
Beispiel #5
0
static void handle_joystick_movement(const GAME_2DPOS_STRUCT *joy, joycal_t *cal, const int pc_device, const int buttons)
{
    int value = buttons ? CBM_FIRE : 0;

    if (!(number_joysticks & pc_device & (cbm_joystick[0] | cbm_joystick[1] | cbm_joystick[2] | cbm_joystick[3]))) {
        return;
    }

    if (cal->start) {
        cal->xmin = cal->xmax = joy->x;
        cal->ymin = cal->ymax = joy->y;
        cal->direction[KEYSET_N] = 9 * joy->y / 10;
        cal->direction[KEYSET_S] = 11 * joy->y / 10;
        cal->direction[KEYSET_W] = 9 * joy->x / 10;
        cal->direction[KEYSET_E] = 11 * joy->x / 10;
        cal->start = FALSE;
    }

    if (joy->y < cal->direction[KEYSET_N]) {
        value |= CBM_NORTH;
        if (cal->autocal && joy->y < cal->ymin) {
            cal->ymin = joy->y;
            cal->direction[KEYSET_N] = (3 * cal->ymin + cal->ymax) / 4;
            cal->direction[KEYSET_S] = 3 * (cal->ymin + cal->ymax) / 4;
        }
    }

    if (joy->y > cal->direction[KEYSET_S]) {
        value |= CBM_SOUTH;
        if (cal->autocal && joy->y > cal->ymax) {
            cal->ymax = joy->y;
            cal->direction[KEYSET_N] = (3 * cal->ymin + cal->ymax) / 4;
            cal->direction[KEYSET_S] = 3 * (cal->ymin + cal->ymax) / 4;
        }
    }

    if (joy->x < cal->direction[KEYSET_W]) {
        value |= CBM_WEST;
        if (cal->autocal && joy->x < cal->xmin) {
            cal->xmin = joy->x;
            cal->direction[KEYSET_W] = (3 * cal->xmin + cal->xmax) / 4;
            cal->direction[KEYSET_E] = 3 * (cal->xmin + cal->xmax) / 4;
        }
    }

    if (joy->x > cal->direction[KEYSET_E]) {
        value |= CBM_EAST;
        if (cal->autocal && joy->x > cal->xmax) {
            cal->xmax = joy->x;
            cal->direction[KEYSET_W] = (3 * cal->xmin + cal->xmax) / 4;
            cal->direction[KEYSET_E] = 3 * (cal->xmin + cal->xmax) / 4;
        }
    }

    if (cbm_joystick[0] & pc_device) {
        joystick_set_value_absolute(1, value);
    }

    if (cbm_joystick[1] & pc_device) {
        joystick_set_value_absolute(2, value);
    }

    if (cbm_joystick[2] & pc_device) {
        joystick_set_value_absolute(3, value);
    }

    if (cbm_joystick[3] & pc_device) {
        joystick_set_value_absolute(4, value);
    }
}
Beispiel #6
0
int joystick(void)
{
	static bool key_cursorup    = false;
	static bool key_cursordown  = false;
	static bool key_cursorleft  = false;
	static bool key_cursorright = false;

	static bool warp_mode=false;

	// osk_active_bufferlen == The OSK is entering characters, don't interrupt it.
	// autostart_in_progress() == 
	// Autostart is running. Don't allow the joystick to interrupt.
	// In particular this can break the actual autostart script that tests the basic prompt due to interference

	if (osk_active_bufferlen || autostart_in_progress())
	{
		return 0;
	} 

	uint8_t pads_connected = CellInput->NumberPadsConnected();
	for (uint8_t i = 0; i < pads_connected; ++i)
	{
		int value = 0;

		// Do PS3 pads
		CellInput->UpdateDevice(i);

		// Set the joystick values

		if (CellInput->IsButtonPressed(i,CTRL_LEFT) | CellInput->IsAnalogPressedLeft(i,CTRL_LSTICK))
			value |= 4;

		if (CellInput->IsButtonPressed(i,CTRL_RIGHT) | CellInput->IsAnalogPressedRight(i,CTRL_LSTICK))
			value |= 8;

		if (CellInput->IsButtonPressed(i,CTRL_UP) | CellInput->IsAnalogPressedUp(i,CTRL_LSTICK))
			value |= 1;

		if (CellInput->IsButtonPressed(i,CTRL_DOWN) | CellInput->IsAnalogPressedDown(i,CTRL_LSTICK))
			value |= 2;


		// Process re-definable controls
		process_button (i, CTRL_CROSS, &value);
		process_button (i, CTRL_CIRCLE, &value);
		process_button (i, CTRL_SQUARE, &value);
		process_button (i, CTRL_TRIANGLE, &value);
		process_button (i, CTRL_L1, &value);
		process_button (i, CTRL_L2, &value);
		process_button (i, CTRL_R1, &value);
		process_button (i, CTRL_R2, &value);


		// Emulator cursor keys
		if (CellInput->IsAnalogPressedUp(i,CTRL_RSTICK))
		{
			if (!key_cursorup)
			{
				keyboard_key_pressed((signed long)  32850);  // Cursor Up key pressed
				key_cursorup = true;
			}
		}
		else
		{
			if (key_cursorup)
			{
				keyboard_key_released((signed long) 32850);  // Cursor Up key released
				key_cursorup = false;
			}
		}

		if (CellInput->IsAnalogPressedDown(i,CTRL_RSTICK))
		{
			if (!key_cursordown) {
				keyboard_key_pressed((signed long)  32849);  // Cursor Down key pressed
				key_cursordown = true;
			}
		}
		else
		{
			if (key_cursordown)
			{
				keyboard_key_released((signed long) 32849);  // Cursor Down key released
				key_cursordown = false;
			}
		}

		if (CellInput->IsAnalogPressedLeft(i,CTRL_RSTICK))
		{
			if (!key_cursorleft)
			{
				keyboard_key_pressed((signed long)  32848);  // Cursor Left key pressed
				key_cursorleft = true;
			}
		}
		else
		{
			if (key_cursorleft)
			{
				keyboard_key_released((signed long) 32848);  // Cursor Left key released
				key_cursorleft = false;
			}
		}

		if (CellInput->IsAnalogPressedRight(i,CTRL_RSTICK))
		{
			if (!key_cursorright)
			{
				keyboard_key_pressed((signed long)  32847);  // Cursor Right key pressed
				key_cursorright = true;
			}
		} else {
			if (key_cursorright) {
				keyboard_key_released((signed long) 32847);  // Cursor Right key released
				key_cursorright = false;
			}
		}

		if ((CellInput->IsButtonPressed(0,CTRL_R2) && CellInput->IsButtonPressed(0,CTRL_L2)) || (CellInput->IsButtonPressed(1,CTRL_R2) && CellInput->IsButtonPressed(1,CTRL_L2)))
		{
			if (!warp_mode)
			{
				// Disable sound (makes warp mode infinitely faster)
				resources_set_int("Sound", 0);

				// Enable Warp Mode
				resources_set_int("WarpMode", 1);
				warp_mode=true;
			}
		}
		else
		{
			if (warp_mode)
			{
				resources_set_int("WarpMode", 0);
				resources_set_int("Sound", 1);
				warp_mode=false;
			}
		}


		if (CellInput->IsButtonPressed(i,CTRL_L1) && CellInput->IsButtonPressed(i,CTRL_R1) && CellInput->IsButtonPressed(i,CTRL_L2) && CellInput->IsButtonPressed(i,CTRL_R2) )
			machine_trigger_reset(MACHINE_RESET_MODE_HARD);


		/*
		// Swap joysticks
		if (CellInput->WasButtonPressed(i,CTRL_SELECT)) {
		// Do nothing
		}
		// Required because keyloop kills us
		if (CellInput->WasButtonReleased(i,CTRL_SELECT)) {
		if (pads_connected == 1)
		// Only allow us to swap joystick ports if there is only one controller
		// Otherwise, multiplayer madness and much punching will ensue.
		joyswap=!joyswap;
		}
		 */

		if (CellInput->WasButtonPressed(i,CTRL_SELECT))
			InGameMenuLoop();

		if(CellInput->WasButtonPressed(i,CTRL_START))
		{
			menu(MODE_MENU);
			// Stop the clock (effectively, tells the emulator we were paused)
			vsync_suspend_speed_eval();
			// Apply any changes as necessary.
		}

		if(CellInput->WasButtonPressed(i,CTRL_L3))
		{
			// Vice OSK
			menu(MODE_OSK);
			// Stop the clock (effectively, tells the emulator we were paused)
			vsync_suspend_speed_eval();
			// Apply any changes as necessary.
		}

		if(CellInput->WasButtonPressed(i,CTRL_R3))
		{
			osk->Start(L"Characters entered here will be relayed to the emulator ", L"");

			#ifdef CELL_DEBUG
			printf("OSK started\n");
			#endif
			// Just in case. This ensures we check to see if the screen has updated, and if not.. force one
			// The OSK fails to draw if the screen doesn't update.
		}

		cellSysutilCheckCallback();

		if (sysutil_drawing)
			sysutil_callback_redraw();

		ui_callback();


		// pad 0 becomes port 2
		// pad 1 becomes port 1
		if (joyswap)
			joystick_set_value_absolute( ((i+1) % 2 ) + 1, value);  
		else
			joystick_set_value_absolute(i+1, value); 

		// pad 0 becomes port 1
		// pad 1 becomes port 2
	}

	return 0;
}
Beispiel #7
0
int joyai_update(int joy, int dst)
{
    void *ptr;
    keysym_type *keysym = (joy == 2) ? keysym_2 : keysym_1;
    BYTE value = 0;

    if (!amigainput_lib_loaded) {
        return -1;
    }

    if ((CTX == NULL) || (ai_handle[joy - 1] == NULL)) {
        return -1;
    }

    if (AIN_ReadDevice(CTX, ai_handle[joy - 1], &ptr) == TRUE) {
        unsigned int i, *data = ptr;

        for (i = 0; i < NUM_KEYSYM; i++) {
            switch (keysym[i].type) {

                /* Axis and hats use values between -32768 and 32767. Digital Buttons use
                 * values between 0 and 1 (1 is "pressed"), while analog buttons use
                 * values between 0 and 32767.
                 */
                case TYPE_BUTTON:
                    value = (1 << keysym[i].bitnum);
                    if (data[keysym[i].offset]) {
                        joystick_set_value_or(dst, value);
                    } else {
                        joystick_set_value_and(dst, (BYTE) ~value);
                    }
                    break;
                case TYPE_AXES:
                    value = (1 << keysym[i].bitnum);
                    switch (keysym[i].bitnum) {
                        case DIGITAL_UP: /* neg value */
                        case DIGITAL_LEFT: /* neg value */
                            if (data[keysym[i].offset] <= (-(ONOFF_VALUE))) {
                                joystick_set_value_or(dst, value);
                            } else {
                                joystick_set_value_and(dst, (BYTE) ~value);
                            }
                            break;
                        case DIGITAL_DOWN: /* pos value */
                        case DIGITAL_RIGHT: /* pos value */
                            if (data[keysym[i].offset] >= (ONOFF_VALUE)) {
                                joystick_set_value_or(dst, value);
                            } else {
                                joystick_set_value_and(dst, (BYTE) ~value);
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                case TYPE_HAT:
                    value = 0;
                    switch (data[keysym[i].offset]) {
                        case 1: /* N */
                            value = (1 << DIGITAL_UP);
                            break;
                        case 2: /* NE */
                            value = ((1 << DIGITAL_UP) | (1 << DIGITAL_RIGHT));
                            break;
                        case 3: /* E */
                            value = (1 << DIGITAL_RIGHT);
                            break;
                        case 4: /* SE */
                            value = ((1 << DIGITAL_DOWN) | (1 << DIGITAL_RIGHT));
                            break;
                        case 5: /* S */
                            value = (1 << DIGITAL_DOWN);
                            break;
                        case 6: /* SW */
                            value = ((1 << DIGITAL_DOWN) | (1 << DIGITAL_LEFT));
                            break;
                        case 7: /* W */
                            value = (1 << DIGITAL_LEFT);
                            break;
                        case 8: /* NW */
                            value = ((1 << DIGITAL_UP) | (1 << DIGITAL_LEFT));
                            break;
                        default: /* none */
                            break;
                    }

                    joystick_set_value_absolute(dst, value);
                    break;
                default:
                    break;
            }
        }

        return 0;
    }

    return -1;
}