#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;
return r;
}
-void gp2x_init()
+void gpsp_plat_init(void)
{
char buff[256];
gp2x_sound_volume(1);
}
-void gp2x_quit()
+void gpsp_plat_quit(void)
{
char buff1[256], buff2[256];
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;
#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)
{
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();
#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;
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);
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,
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);
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;
}
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)
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
u32 random_skip = 0;
u32 fps_debug = 0;
-#ifdef GP2X_BUILD
u32 frameskip_value = 2;
-u64 frame_count_initial_timestamp = 0;
u64 last_frame_interval_timestamp;
-void gp2x_init(void);
-void gp2x_quit(void);
-#else
-
-u32 frameskip_value = 4;
-#endif
u32 skip_next_frame = 0;
u32 frameskip_counter = 0;
delay_us(2500000);
#endif
-#ifdef GP2X_BUILD
- // Overclocking GP2X and MMU patch goes here
- gp2x_init();
+#ifndef PC_BUILD
+ gpsp_plat_init();
#endif
init_video();
{
if(load_gamepak(argv[1]) == -1)
{
-#ifdef PC_BUILD
+#ifndef PSP_BUILD
printf("Failed to load gamepak %s, exiting.\n", load_filename);
#endif
exit(-1);
{
if(load_gamepak(load_filename) == -1)
{
-#ifdef PC_BUILD
+#ifndef PSP_BUILD
printf("Failed to load gamepak %s, exiting.\n", load_filename);
#endif
exit(-1);
execute_arm_translate(execute_cycles);
#else
-#ifdef GP2X_BUILD
- get_ticks_us(&frame_count_initial_timestamp);
-#endif
-
/* u8 current_savestate_filename[512];
get_savestate_filename_noshot(savestate_slot,
current_savestate_filename);
if(fps_debug)
{
char print_buffer[32];
- sprintf(print_buffer, "%d (%d)", fps, frames_drawn);
+ sprintf(print_buffer, "%2d (%2d)", fps, frames_drawn);
print_string(print_buffer, 0xFFFF, 0x000, 0, 0);
}
+ if(!synchronize_flag)
+ print_string("-FF-", 0xFFFF, 0x000, 216, 0);
update_screen();
return execute_cycles;
}
-u64 last_screen_timestamp = 0;
-u32 frame_speed = 15000;
-
-
#ifdef PSP_BUILD
u32 real_frame_count = 0;
if(!synchronize_flag)
{
- print_string("--FF--", 0xFFFF, 0x000, 0, 0);
used_frameskip = 4;
virtual_frame_count = real_frame_count - 1;
}
#else
SDL_Quit();
-#ifdef GP2X_BUILD
- gp2x_quit();
+#ifndef PC_BUILD
+ gpsp_plat_quit();
#endif
exit(0);
void get_ticks_us(u64 *ticks_return)
{
- *ticks_return = (SDL_GetTicks() * 1000);
+ *ticks_return = (u64)SDL_GetTicks() * 1000;
}
#else
u32 file_length(u8 *filename, s32 dummy);
-extern u32 real_frame_count;
-extern u32 virtual_frame_count;
-extern u32 max_frameskip;
-extern u32 num_skipped_frames;
-
#else
u32 file_length(u8 *dummy, FILE *fp);
#endif
-
-#ifdef GP2X_BUILD
-
-extern u64 frame_count_initial_timestamp;
extern u32 real_frame_count;
extern u32 virtual_frame_count;
extern u32 max_frameskip;
extern u32 num_skipped_frames;
-#endif
-
-
#define count_timer(timer_number) \
timer[timer_number].reload = 0x10000 - value; \
if(timer_number < 2) \
u32 pitch = get_screen_pitch();
u16 *dest_ptr = get_screen_pixels() + dest_x + (dest_y * pitch);
+ s32 w1 = dest_x + w > pitch ? pitch - dest_x : w;
u16 *src_ptr = src;
- u32 line_skip = pitch - w;
- u32 x, y;
+ s32 x, y;
for(y = 0; y < h; y++)
{
- for(x = 0; x < w; x++, src_ptr++, dest_ptr++)
+ for(x = 0; x < w1; x++)
{
- *dest_ptr = *src_ptr;
+ dest_ptr[x] = src_ptr[x];
}
- dest_ptr += line_skip;
+ src_ptr += w;
+ dest_ptr += pitch;
}
}