X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fgp2x.c;h=c00671aa6ee2cded93f9a76719e8559ae1b4951c;hb=0d6fbb2c33a0b9eee5fcc1162f5c799bdae9e89a;hp=4f24ca9e4c2bbe3589ff01c24b157695e6ed5a4e;hpb=e31266dd116b6bea59ce3f2036feeb6725c45a72;p=libpicofe.git diff --git a/linux/gp2x.c b/linux/gp2x.c index 4f24ca9..c00671a 100644 --- a/linux/gp2x.c +++ b/linux/gp2x.c @@ -1,4 +1,4 @@ -/* faking/emulating gp2x.c by using gtk */ +/* faking/emulating gp2x by using gtk */ #include #include #include @@ -12,10 +12,10 @@ #include #include -#include "../gp2x/emu.h" -#include "../gp2x/gp2x.h" #include "../gp2x/version.h" #include "../common/emu.h" +#include "../common/menu.h" +#include "../common/readpng.h" #include "sndout_oss.h" #include "log_io.h" @@ -25,10 +25,13 @@ static int current_bpp = 8; static int current_pal[256]; static const char *verstring = "PicoDrive " VERSION; static int scr_changed = 0, scr_w = SCREEN_WIDTH, scr_h = SCREEN_HEIGHT; +void *gp2x_screens[4]; // dummies -char *ext_menu = 0, *ext_state = 0; int mix_32_to_16l_level; +int crashed_940 = 0; +int default_cpu_clock = 123; +void *gp2x_memregs = NULL; /* gtk */ struct gtk_global_struct @@ -48,6 +51,12 @@ static void destroy (GtkWidget *widget, gpointer data) gtk_main_quit (); } +/* faking GP2X pad */ +enum { GP2X_UP=0x1, GP2X_LEFT=0x4, GP2X_DOWN=0x10, GP2X_RIGHT=0x40, + GP2X_START=1<<8, GP2X_SELECT=1<<9, GP2X_L=1<<10, GP2X_R=1<<11, + GP2X_A=1<<12, GP2X_B=1<<13, GP2X_X=1<<14, GP2X_Y=1<<15, + GP2X_VOL_UP=1<<23, GP2X_VOL_DOWN=1<<22, GP2X_PUSH=1<<27 }; + static gint key_press_event (GtkWidget *widget, GdkEventKey *event) { switch (event->hardware_keycode) @@ -114,9 +123,11 @@ static gint key_release_event (GtkWidget *widget, GdkEventKey *event) static void size_allocate_event(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) { // printf("%dx%d\n", allocation->width, allocation->height); - scr_w = allocation->width - 2; - scr_h = allocation->height - 2; - scr_changed = 1; + if (scr_w != allocation->width - 2 || scr_h != allocation->height - 2) { + scr_w = allocation->width - 2; + scr_h = allocation->height - 2; + scr_changed = 1; + } } static void *gtk_threadf(void *targ) @@ -196,36 +207,19 @@ void finalize_image(guchar *pixels, gpointer data) static void realloc_screen(void) { void *old = g_screen_ptr; + int i; g_screen_width = scr_w; g_screen_height = scr_h; - g_screen_ptr = malloc(g_screen_width * g_screen_height * 2); + g_screen_ptr = calloc(g_screen_width * g_screen_height * 2, 1); free(old); scr_changed = 0; -} - -void gp2x_init(void) -{ - printf("entering init()\n"); fflush(stdout); - realloc_screen(); - memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); - - // snd - sndout_oss_init(); - - gtk_initf(); - - printf("exitting init()\n"); fflush(stdout); -} - -void gp2x_deinit(void) -{ - free(g_screen_ptr); - sndout_oss_exit(); + for (i = 0; i < 4; i++) + gp2x_screens[i] = g_screen_ptr; } -/* video */ -void gp2x_video_flip(void) +/* gp2x/emu.c stuff, most to be rm'd */ +static void gp2x_video_flip_(void) { GdkPixbuf *pixbuf; unsigned char *image; @@ -281,131 +275,147 @@ void gp2x_video_flip(void) realloc_screen(); } -void gp2x_video_flip2(void) -{ - gp2x_video_flip(); -} - -void gp2x_video_changemode(int bpp) +static void gp2x_video_changemode_ll_(int bpp) { current_bpp = bpp; } -void gp2x_video_changemode2(int bpp) +static void gp2x_video_setpalette_(int *pal, int len) { - current_bpp = bpp; + memcpy(current_pal, pal, len*4); } -void gp2x_video_setpalette(int *pal, int len) +void gp2x_memcpy_all_buffers(void *data, int offset, int len) { - memcpy(current_pal, pal, len*4); } -void gp2x_video_flush_cache(void) +void gp2x_memset_all_buffers(int offset, int byte, int len) { + memset((char *)g_screen_ptr + offset, byte, len); } -void gp2x_video_RGB_setscaling(int v_offs, int W, int H) +void gp2x_video_changemode(int bpp) { + gp2x_video_changemode_ll_(bpp); } -void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len) +void gp2x_make_fb_bufferable(int yes) { - if ((char *)g_screen_ptr + offset != data) - memcpy((char *)g_screen_ptr + offset, data, len); } -void gp2x_memcpy_all_buffers(void *data, int offset, int len) +int soc_detect(void) { - memcpy((char *)g_screen_ptr + offset, data, len); + return 0; } +/* plat */ +static char menu_bg_buffer[320*240*2]; +char cpu_clk_name[16] = "GP2X CPU clocks"; -void gp2x_memset_all_buffers(int offset, int byte, int len) +void plat_video_menu_enter(int is_rom_loaded) { - memset((char *)g_screen_ptr + offset, byte, len); -} + if (is_rom_loaded) + { + // darken the active framebuffer + memset(g_screen_ptr, 0, 320*8*2); + menu_darken_bg((char *)g_screen_ptr + 320*8*2, 320*224, 1); + memset((char *)g_screen_ptr + 320*232*2, 0, 320*8*2); + } + else + { + char buff[256]; -void gp2x_pd_clone_buffer2(void) -{ - memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); -} + // should really only happen once, on startup.. + emu_make_path(buff, "skin/background.png", sizeof(buff)); + if (readpng(g_screen_ptr, buff, READPNG_BG) < 0) + memset(g_screen_ptr, 0, 320*240*2); + } -/* joy */ -unsigned long gp2x_joystick_read(int allow_usb_joy) -{ - return current_keys; -} + memcpy(menu_bg_buffer, g_screen_ptr, 320*240*2); -int gp2x_touchpad_read(int *x, int *y) -{ - return -1; + // switch to 16bpp + gp2x_video_changemode_ll_(16); + gp2x_video_flip_(); } -/* 940 */ -int crashed_940 = 0; -void Pause940(int yes) +void plat_video_menu_begin(void) { + memcpy(g_screen_ptr, menu_bg_buffer, 320*240*2); } -void Reset940(int yes, int bank) +void plat_video_menu_end(void) { + gp2x_video_flip_(); } -/* faking gp2x cpuctrl.c */ -void cpuctrl_init(void) +void plat_validate_config(void) { +// PicoOpt &= ~POPT_EXT_FM; } -void cpuctrl_deinit(void) +void plat_early_init(void) { } -void set_FCLK(unsigned MHZ) +void plat_init(void) { -} + realloc_screen(); + memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); -void Disable_940(void) -{ -} + // snd + sndout_oss_init(); -void gp2x_video_wait_vsync(void) -{ + gtk_initf(); } -void set_RAM_Timings(int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD) +void plat_finish(void) { + free(g_screen_ptr); + sndout_oss_exit(); } -void set_gamma(int g100, int A_SNs_curve) +/* nasty */ +static void do_nothing() { } -void set_LCD_custom_rate(int rate) +void *gp2x_video_flip = gp2x_video_flip_; +void *gp2x_video_flip2 = gp2x_video_flip_; +void *gp2x_video_changemode_ll = gp2x_video_changemode_ll_; +void *gp2x_video_setpalette = gp2x_video_setpalette_; + +void *gp2x_video_RGB_setscaling = do_nothing; +void *gp2x_video_wait_vsync = do_nothing; +void *gp2x_set_cpuclk = do_nothing; +void *set_lcd_custom_rate = do_nothing; +void *unset_lcd_custom_rate = do_nothing; +void *set_lcd_gamma = do_nothing; +void *set_ram_timings = do_nothing; +void *unset_ram_timings = do_nothing; + +/* joy */ +int gp2x_touchpad_read(int *x, int *y) { + return -1; } -void unset_LCD_custom_rate(void) +/* misc */ +void spend_cycles(int c) { + usleep(c/200); } -/* squidgehack.c */ -int mmuhack(void) +int mp3_get_bitrate(FILE *f, int size) { - return 0; + return 128; } - -int mmuunhack(void) +void mp3_start_play(FILE *f, int pos) { - return 0; } - -/* misc */ -void spend_cycles(int c) +void mp3_update(int *buffer, int length, int stereo) { - usleep(c/200); } /* lprintf */