From: notaz Date: Sun, 31 May 2009 20:10:24 +0000 (+0300) Subject: working tripple buffering X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cdfc0bc7b3dd2051b8027da4e2f35bbb9897307;p=gpsp.git working tripple buffering --- diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 88f1731..a8ec704 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -38,8 +38,6 @@ static volatile u16 *gpsp_gp2x_memregs; static volatile u32 *gpsp_gp2x_memregl; unsigned short *gp2x_memregs; -static volatile u16 *MEM_REG; - s32 gp2x_load_mmuhack() { s32 mmufd = open("/dev/mmuhack", O_RDWR); @@ -57,6 +55,89 @@ s32 gp2x_load_mmuhack() return 0; } +#ifdef WIZ_BUILD +#include +void *gpsp_gp2x_screen; +static u32 fb_paddr[3]; +static void *fb_vaddr[3]; +static u32 fb_work_buf; +const int fb_buf_count = 3; +static int fb_buf_use = 3; + +static void fb_video_init() +{ + struct fb_fix_screeninfo fbfix; + int i, ret; + int fbdev; + + fbdev = open("/dev/fb0", O_RDWR); + if (fbdev < 0) { + perror("can't open fbdev"); + exit(1); + } + + ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix); + if (ret == -1) + { + perror("ioctl(fbdev) failed"); + exit(1); + } + + printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start); + fb_paddr[0] = fbfix.smem_start; + close(fbdev); + + fb_vaddr[0] = mmap(0, 320*240*2*fb_buf_count, PROT_READ|PROT_WRITE, + MAP_SHARED, gpsp_gp2x_dev, fb_paddr[0]); + if (fb_vaddr[0] == MAP_FAILED) + { + perror("mmap(fb_vaddr) failed"); + exit(1); + } + memset(fb_vaddr[0], 0, 320*240*2*fb_buf_count); + + printf(" %p -> %08x\n", fb_vaddr[0], fb_paddr[0]); + for (i = 1; i < fb_buf_count; i++) + { + fb_paddr[i] = fb_paddr[i-1] + 320*240*2; + fb_vaddr[i] = (char *)fb_vaddr[i-1] + 320*240*2; + printf(" %p -> %08x\n", fb_vaddr[i], fb_paddr[i]); + } + fb_work_buf = 0; + fb_buf_use = fb_buf_count; + + pollux_video_flip(); + warm_change_cb_upper(WCB_C_BIT|WCB_B_BIT, 1); +} + +void pollux_video_flip() +{ + warm_cache_op_all(WOP_D_CLEAN); + gpsp_gp2x_memregl[0x406C>>2] = fb_paddr[fb_work_buf]; + gpsp_gp2x_memregl[0x4058>>2] |= 0x10; + fb_work_buf++; + if (fb_work_buf >= fb_buf_use) + fb_work_buf = 0; + gpsp_gp2x_screen = fb_vaddr[fb_work_buf]; +} + +void fb_use_buffers(int count) +{ + if (count < 1) + count = 1; + else if (count > fb_buf_count) + count = fb_buf_count; + fb_buf_use = count; +} + +static void fb_video_exit() +{ + /* switch to default fb mem */ + gpsp_gp2x_memregl[0x406C>>2] = fb_paddr[0]; + gpsp_gp2x_memregl[0x4058>>2] |= 0x10; +} +#endif + void gp2x_init() { gpsp_gp2x_dev = open("/dev/mem", O_RDWR); @@ -67,10 +148,11 @@ void gp2x_init() gpsp_gp2x_memregs = (unsigned short *)gpsp_gp2x_memregl; #ifdef WIZ_BUILD gpsp_gp2x_gpiodev = open("/dev/GPIO", O_RDONLY); -#endif warm_init(); + fb_video_init(); +#endif - clear_screen(0); +// clear_screen(0); // main_cpuspeed(0, NULL); gp2x_memregs = (void *)gpsp_gp2x_memregs; cpuctrl_init(); @@ -79,12 +161,13 @@ void gp2x_init() void gp2x_quit() { - munmap((void *)gpsp_gp2x_memregl, 0x10000); - close(gpsp_gp2x_dev_audio); - close(gpsp_gp2x_dev); #ifdef WIZ_BUILD close(gpsp_gp2x_gpiodev); + fb_video_exit(); #endif + munmap((void *)gpsp_gp2x_memregl, 0x10000); + close(gpsp_gp2x_dev_audio); + close(gpsp_gp2x_dev); //chdir("/usr/gp2x"); //execl("gp2xmenu", "gp2xmenu", NULL); diff --git a/gp2x/gp2x.h b/gp2x/gp2x.h index 15b4a90..df7d141 100644 --- a/gp2x/gp2x.h +++ b/gp2x/gp2x.h @@ -51,4 +51,9 @@ void set_940_Div(u16 div); s32 gp2x_load_mmuhack(); +/* wiz only */ +extern void *gpsp_gp2x_screen; +void fb_use_buffers(int count); +void pollux_video_flip(); + #endif diff --git a/gui.c b/gui.c index 8a90aac..18170f7 100644 --- a/gui.c +++ b/gui.c @@ -1226,7 +1226,12 @@ u32 menu(u16 *original_screen) menu_option_type graphics_sound_options[] = { string_selection_option(NULL, "Display scaling", scale_options, - (u32 *)(&screen_scale), 3, + (u32 *)(&screen_scale), +#ifdef WIZ_BUILD + 2, +#else + 3, +#endif #ifndef GP2X_BUILD "Determines how the GBA screen is resized in relation to the entire\n" "screen. Select unscaled 3:2 for GBA resolution, scaled 3:2 for GBA\n" @@ -1244,14 +1249,14 @@ u32 menu(u16 *original_screen) #endif string_selection_option(NULL, "Frameskip type", frameskip_options, (u32 *)(¤t_frameskip_type), 3, - "Determines what kind of frameskipping to use.\n" #ifndef GP2X_BUILD + "Determines what kind of frameskipping to use.\n" "Frameskipping may improve emulation speed of many games.\n" +#endif "Off: Do not skip any frames.\n" - "Auto: Skip up to N frames (see next option) as needed.\n" + "Auto: Skip up to N frames (see next opt) as needed.\n" "Manual: Always render only 1 out of N + 1 frames." -#endif - "", 5), + , 5), numeric_selection_option(NULL, "Frameskip value", &frameskip_value, 100, #ifndef GP2X_BUILD "For auto frameskip, determines the maximum number of frames that\n" @@ -1414,9 +1419,15 @@ u32 menu(u16 *original_screen) gamepad_config_option("Y ", 7), gamepad_config_option("Left Trigger ", 8), gamepad_config_option("Right Trigger", 9), +#ifdef WIZ_BUILD + gamepad_config_option("Menu ", 10), +#else gamepad_config_option("Start ", 10), +#endif gamepad_config_option("Select ", 11), +#ifndef WIZ_BUILD gamepad_config_option("Stick Push ", 12), +#endif submenu_option(NULL, "Back", "Return to the main menu.", 14) }; diff --git a/input.c b/input.c index 3eee0b0..cfaff69 100644 --- a/input.c +++ b/input.c @@ -509,6 +509,13 @@ u32 update_input() buttons |= GP2X_VOL_MIDDLE; } + /* for Wiz */ + if((buttons & GP2X_VOL_DOWN) && (buttons & GP2X_SELECT)) + { + buttons &= ~(GP2X_VOL_DOWN | GP2X_SELECT); + buttons |= GP2X_VOL_MIDDLE; + } + handled_buttons = ((last_buttons ^ buttons) | GP2X_VOL_DOWN | GP2X_VOL_UP) & buttons; last_buttons = buttons; diff --git a/main.c b/main.c index 64329d0..571336f 100644 --- a/main.c +++ b/main.c @@ -226,13 +226,13 @@ int main(int argc, char *argv[]) delay_us(2500000); #endif - init_video(); - #ifdef GP2X_BUILD // Overclocking GP2X and MMU patch goes here gp2x_init(); #endif + init_video(); + #ifdef GP2X_BUILD sprintf(bios_filename, "%s/%s", main_path, "gba_bios.bin"); if(load_bios(bios_filename) == -1) diff --git a/video.c b/video.c index 5a1181f..7415c76 100644 --- a/video.c +++ b/video.c @@ -79,6 +79,18 @@ static void Ge_Finish_Callback(int id, void *arg) { } +#define get_screen_pixels() \ + screen_pixels \ + +#define get_screen_pitch() \ + screen_pitch \ + +#elif defined(WIZ_BUILD) + +static u32 screen_offset = 0; +static u16 *screen_pixels = NULL; +const u32 screen_pitch = 320; + #define get_screen_pixels() \ screen_pixels \ @@ -88,13 +100,8 @@ static void Ge_Finish_Callback(int id, void *arg) #else #ifdef GP2X_BUILD - #ifdef WIZ_BUILD - static void SDL_GP2X_AllowGfxMemory() {} - #include - #else - #include "SDL_gp2x.h" - #endif - SDL_Surface *hw_screen; +#include "SDL_gp2x.h" +SDL_Surface *hw_screen; #endif SDL_Surface *screen; const u32 video_scale = 1; @@ -3328,6 +3335,14 @@ void flip_screen() } } +#elif defined(WIZ_BUILD) + +void flip_screen() +{ + pollux_video_flip(); + screen_pixels = (u16 *)gpsp_gp2x_screen + screen_offset; +} + #else #define integer_scale_copy_2() \ @@ -3528,6 +3543,12 @@ void init_video() GE_CMD(NOP, 0); } +#elif defined(WIZ_BUILD) + +void init_video() +{ +} + #else void init_video() @@ -3656,6 +3677,44 @@ void clear_screen(u16 color) sceGuSync(0, 0); */ } +#elif defined(WIZ_BUILD) + +void video_resolution_large() +{ + screen_offset = 0; + resolution_width = 320; + resolution_height = 240; + + fb_use_buffers(1); + flip_screen(); + clear_screen(0); +} + +void video_resolution_small() +{ + screen_offset = 320*40 + 40; + resolution_width = 240; + resolution_height = 160; + + fb_use_buffers(999); + clear_screen(0); + flip_screen(); +} + +void set_gba_resolution(video_scale_type scale) +{ + screen_scale = scale; +} + +void clear_screen(u16 color) +{ + u32 col = ((u32)color << 16) | color; + u32 *p = gpsp_gp2x_screen; + int c = 320*240/2; + while (c-- > 0) + *p++ = col; +} + #else void video_resolution_large()