Skip to content

Commit

Permalink
refactor GP2X stuff for pandora reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Sep 4, 2011
1 parent 2455b6a commit 43c24b3
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 141 deletions.
90 changes: 82 additions & 8 deletions gp2x/gp2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,57 @@
#include <unistd.h>
#include <ctype.h>
#include "gp2x.h"
#include "warm.h"
#include "pollux_dpc_set.h"

u32 gp2x_audio_volume = 74/2;
u32 gpsp_gp2x_dev_audio = 0;
u32 gpsp_gp2x_dev = 0;
u32 gpsp_gp2x_gpiodev = 0;
static u32 gpsp_gp2x_dev_audio;
static u32 gpsp_gp2x_dev;
static u32 gpsp_gp2x_gpiodev;

static u32 gp2x_audio_volume = 74/2;

static volatile u16 *gpsp_gp2x_memregs;
static volatile u32 *gpsp_gp2x_memregl;

u32 button_plat_mask_to_config[] =
{
GP2X_UP,
GP2X_LEFT,
GP2X_DOWN,
GP2X_RIGHT,
GP2X_START,
GP2X_SELECT,
GP2X_L,
GP2X_R,
GP2X_A,
GP2X_B,
GP2X_X,
GP2X_Y,
GP2X_VOL_DOWN,
GP2X_VOL_UP,
GP2X_PUSH,
GP2X_VOL_MIDDLE
};

u32 gamepad_config_map[16] =
{
BUTTON_ID_UP, // Up
BUTTON_ID_LEFT, // Left
BUTTON_ID_DOWN, // Down
BUTTON_ID_RIGHT, // Right
BUTTON_ID_START, // Start
BUTTON_ID_SELECT, // Select
BUTTON_ID_L, // Ltrigger
BUTTON_ID_R, // Rtrigger
BUTTON_ID_FPS, // A
BUTTON_ID_A, // B
BUTTON_ID_B, // X
BUTTON_ID_MENU, // Y
BUTTON_ID_VOLDOWN, // Vol down
BUTTON_ID_VOLUP, // Vol up
BUTTON_ID_FPS, // Push
BUTTON_ID_MENU // Vol middle
};

#ifdef WIZ_BUILD
#include <linux/fb.h>
void *gpsp_gp2x_screen;
Expand Down Expand Up @@ -224,7 +264,7 @@ static int get_romdir(char *buff, size_t size)
return r;
}

void gp2x_init()
void gpsp_plat_init(void)
{
char buff[256];

Expand All @@ -245,7 +285,7 @@ void gp2x_init()
gp2x_sound_volume(1);
}

void gp2x_quit()
void gpsp_plat_quit(void)
{
char buff1[256], buff2[256];

Expand Down Expand Up @@ -292,7 +332,7 @@ void gp2x_sound_volume(u32 volume_up)
ioctl(gpsp_gp2x_dev_audio, SOUND_MIXER_WRITE_PCM, &volume);
}

u32 gpsp_gp2x_joystick_read(void)
u32 gpsp_plat_joystick_read(void)
{
#ifdef WIZ_BUILD
u32 value = 0;
Expand Down Expand Up @@ -323,6 +363,40 @@ u32 gpsp_gp2x_joystick_read(void)
#endif
}

u32 gpsp_plat_buttons_to_cursor(u32 buttons)
{
gui_action_type new_button = CURSOR_NONE;

if(buttons & GP2X_A)
new_button = CURSOR_BACK;

if(buttons & GP2X_X)
new_button = CURSOR_EXIT;

if(buttons & GP2X_B)
new_button = CURSOR_SELECT;

if(buttons & GP2X_UP)
new_button = CURSOR_UP;

if(buttons & GP2X_DOWN)
new_button = CURSOR_DOWN;

if(buttons & GP2X_LEFT)
new_button = CURSOR_LEFT;

if(buttons & GP2X_RIGHT)
new_button = CURSOR_RIGHT;

if(buttons & GP2X_L)
new_button = CURSOR_L;

if(buttons & GP2X_R)
new_button = CURSOR_R;

return new_button;
}

// Fout = (m * Fin) / (p * 2^s)
void set_FCLK(u32 MHZ)
{
Expand Down
9 changes: 7 additions & 2 deletions gp2x/gp2x.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ enum
GP2X_VOL_UP = 1 << 23,
GP2X_PUSH = 1 << 27,
#endif
GP2X_VOL_MIDDLE = (1 << 24), // fake, menu enter
};

void gpsp_plat_init(void);
void gpsp_plat_quit(void);

extern u32 gpsp_gp2x_dev_audio;
extern u32 gpsp_gp2x_dev;
u32 gpsp_plat_joystick_read(void);
u32 gpsp_plat_buttons_to_cursor(u32 buttons);

extern u32 button_plat_mask_to_config[];

void gp2x_sound_volume(u32 volume_up);
void gp2x_quit();
Expand Down
96 changes: 13 additions & 83 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,40 +347,14 @@ void init_input()
#endif


#ifdef GP2X_BUILD

// GP2X SDL requires a user made input method
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "gp2x/gp2x.h"

u32 gamepad_config_map[16] =
{
BUTTON_ID_UP, // Up
BUTTON_ID_LEFT, // Left
BUTTON_ID_DOWN, // Down
BUTTON_ID_RIGHT, // Right
BUTTON_ID_START, // Start
BUTTON_ID_SELECT, // Select
BUTTON_ID_L, // Ltrigger
BUTTON_ID_R, // Rtrigger
BUTTON_ID_FPS, // A
BUTTON_ID_A, // B
BUTTON_ID_B, // X
BUTTON_ID_MENU, // Y
BUTTON_ID_VOLDOWN, // Vol down
BUTTON_ID_VOLUP, // Vol up
BUTTON_ID_FPS, // Push
BUTTON_ID_MENU // Vol middle
};
#if defined(GP2X_BUILD) || defined(PND_BUILD)

extern u32 fps_debug;
extern u32 gpsp_gp2x_joystick_read(void);

gui_action_type get_gui_input()
{
gui_action_type new_button = CURSOR_NONE;
u32 buttons = gpsp_gp2x_joystick_read();
u32 buttons = gpsp_plat_joystick_read();
u32 new_buttons;

static u32 last_buttons = 0;
Expand All @@ -391,34 +365,7 @@ gui_action_type get_gui_input()
new_buttons = (last_buttons ^ buttons) & buttons;
last_buttons = buttons;

if(new_buttons & GP2X_A)
new_button = CURSOR_BACK;

if(new_buttons & GP2X_X)
new_button = CURSOR_EXIT;

if(new_buttons & GP2X_B)
new_button = CURSOR_SELECT;

if(new_buttons & GP2X_UP)
new_button = CURSOR_UP;

if(new_buttons & GP2X_DOWN)
new_button = CURSOR_DOWN;

if(new_buttons & GP2X_LEFT)
new_button = CURSOR_LEFT;

if(new_buttons & GP2X_RIGHT)
new_button = CURSOR_RIGHT;

if(new_buttons & GP2X_L)
new_button = CURSOR_L;

if(new_buttons & GP2X_R)
new_button = CURSOR_R;


new_button = gpsp_plat_buttons_to_cursor(new_buttons);
if(new_button != CURSOR_NONE)
{
get_ticks_us(&button_repeat_timestamp);
Expand Down Expand Up @@ -459,28 +406,6 @@ gui_action_type get_gui_input()
return new_button;
}

#define GP2X_VOL_MIDDLE (1 << 24)

u32 button_gp2x_mask_to_config[] =
{
GP2X_UP,
GP2X_LEFT,
GP2X_DOWN,
GP2X_RIGHT,
GP2X_START,
GP2X_SELECT,
GP2X_L,
GP2X_R,
GP2X_A,
GP2X_B,
GP2X_X,
GP2X_Y,
GP2X_VOL_DOWN,
GP2X_VOL_UP,
GP2X_PUSH,
GP2X_VOL_MIDDLE
};

u32 button_id_to_gba_mask[] =
{
BUTTON_UP,
Expand All @@ -506,9 +431,10 @@ u32 update_input()
u32 handled_buttons;
u32 button_id;
u32 new_key = 0;
u32 buttons = gpsp_gp2x_joystick_read();
u32 buttons = gpsp_plat_joystick_read();
u32 i;

#ifdef GP2X_BUILD
if((buttons & GP2X_VOL_DOWN) && (buttons & GP2X_VOL_UP))
{
buttons &= ~(GP2X_VOL_DOWN | GP2X_VOL_UP);
Expand All @@ -522,12 +448,15 @@ u32 update_input()
buttons |= GP2X_VOL_MIDDLE;
}

handled_buttons = ((last_buttons ^ buttons) | GP2X_VOL_DOWN | GP2X_VOL_UP) & buttons;
last_buttons &= ~(GP2X_VOL_DOWN | GP2X_VOL_UP);
#endif

handled_buttons = (last_buttons ^ buttons) & buttons;
last_buttons = buttons;

for(i = 0; i < 16; i++)
{
if(handled_buttons & button_gp2x_mask_to_config[i])
if(handled_buttons & button_plat_mask_to_config[i])
button_id = gamepad_config_map[i];
else
button_id = BUTTON_ID_NONE;
Expand Down Expand Up @@ -564,24 +493,25 @@ u32 update_input()
}

case BUTTON_ID_FASTFORWARD:
print_string("FASTFORWARD", 0xFFFF, 0x0000, 0, 50);
synchronize_flag ^= 1;
return 0;

#ifdef GP2X_BUILD
case BUTTON_ID_VOLUP:
gp2x_sound_volume(1);
break;

case BUTTON_ID_VOLDOWN:
gp2x_sound_volume(0);
break;
#endif

case BUTTON_ID_FPS:
fps_debug ^= 1;
break;
}

if(buttons & button_gp2x_mask_to_config[i])
if(buttons & button_plat_mask_to_config[i])
{
button_id = gamepad_config_map[i];
if(button_id < BUTTON_ID_MENU)
Expand Down
6 changes: 1 addition & 5 deletions input.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,9 @@ gui_action_type get_gui_input_fs_hold(u32 button_id);
void input_write_mem_savestate(file_tag_type savestate_file);
void input_read_savestate(file_tag_type savestate_file);

extern u32 gamepad_config_map[16];
extern u32 gamepad_config_map[];
extern u32 global_enable_analog;
extern u32 analog_sensitivity_level;

#if defined(GP2X_BUILD)
u32 gpsp_gp2x_joystick_read(void);
#endif

#endif

Loading

0 comments on commit 43c24b3

Please sign in to comment.