From 43c24b301dc8c0c5952e1d22bad865f4304d01f8 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 4 Sep 2011 19:51:03 +0300 Subject: [PATCH] refactor GP2X stuff for pandora reuse --- gp2x/gp2x.c | 90 ++++++++++++++++++++++++++++++++++++++++++++----- gp2x/gp2x.h | 9 +++-- input.c | 96 ++++++++--------------------------------------------- input.h | 6 +--- main.c | 36 ++++++-------------- main.h | 12 ------- video.c | 11 +++--- 7 files changed, 119 insertions(+), 141 deletions(-) diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index d36dd08..8bad610 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -28,17 +28,57 @@ #include #include #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 void *gpsp_gp2x_screen; @@ -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]; @@ -245,7 +285,7 @@ void gp2x_init() gp2x_sound_volume(1); } -void gp2x_quit() +void gpsp_plat_quit(void) { char buff1[256], buff2[256]; @@ -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; @@ -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) { diff --git a/gp2x/gp2x.h b/gp2x/gp2x.h index ab8dd4c..9218704 100644 --- a/gp2x/gp2x.h +++ b/gp2x/gp2x.h @@ -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(); diff --git a/input.c b/input.c index e4c48fd..4b908bb 100644 --- a/input.c +++ b/input.c @@ -347,40 +347,14 @@ void init_input() #endif -#ifdef GP2X_BUILD - -// GP2X SDL requires a user made input method -#include -#include -#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; @@ -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); @@ -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, @@ -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); @@ -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; @@ -564,10 +493,10 @@ 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; @@ -575,13 +504,14 @@ u32 update_input() 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) diff --git a/input.h b/input.h index 1d0bd74..c5636bf 100644 --- a/input.h +++ b/input.h @@ -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 diff --git a/main.c b/main.c index b9606db..0d88b37 100644 --- a/main.c +++ b/main.c @@ -43,18 +43,10 @@ u32 global_cycles_per_instruction = 1; 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; @@ -219,9 +211,8 @@ int main(int argc, char *argv[]) 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(); @@ -296,7 +287,7 @@ int main(int argc, char *argv[]) { 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); @@ -318,7 +309,7 @@ int main(int argc, char *argv[]) { 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); @@ -341,10 +332,6 @@ int main(int argc, char *argv[]) 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); @@ -614,9 +601,11 @@ u32 update_gba() 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(); @@ -670,10 +659,6 @@ u32 update_gba() return execute_cycles; } -u64 last_screen_timestamp = 0; -u32 frame_speed = 15000; - - #ifdef PSP_BUILD u32 real_frame_count = 0; @@ -693,7 +678,6 @@ void synchronize() if(!synchronize_flag) { - print_string("--FF--", 0xFFFF, 0x000, 0, 0); used_frameskip = 4; virtual_frame_count = real_frame_count - 1; } @@ -868,8 +852,8 @@ void quit() #else SDL_Quit(); -#ifdef GP2X_BUILD - gp2x_quit(); +#ifndef PC_BUILD + gpsp_plat_quit(); #endif exit(0); @@ -928,7 +912,7 @@ void delay_us(u32 us_count) void get_ticks_us(u64 *ticks_return) { - *ticks_return = (SDL_GetTicks() * 1000); + *ticks_return = (u64)SDL_GetTicks() * 1000; } #else diff --git a/main.h b/main.h index c5725b3..9475e61 100644 --- a/main.h +++ b/main.h @@ -106,29 +106,17 @@ void main_read_savestate(file_tag_type savestate_file); 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) \ diff --git a/video.c b/video.c index d3dd399..59f3e69 100644 --- a/video.c +++ b/video.c @@ -3903,17 +3903,18 @@ void blit_to_screen(u16 *src, u32 w, u32 h, u32 dest_x, u32 dest_y) 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; } } -- 2.39.2