X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fgp2x.c;h=ca915bc133915a1e0dd3e889716caf3771fd3868;hb=fa5e045bdc817112c1abf19e65e2d3481d51c48a;hp=0c251c862727982a8f042f7fad752fa435ab0de4;hpb=13b692eb4ee66fd0c7d4d45bdead750a4defa90e;p=libpicofe.git diff --git a/linux/gp2x.c b/linux/gp2x.c index 0c251c8..ca915bc 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 @@ -13,21 +13,20 @@ #include #include "../gp2x/emu.h" -#include "../gp2x/gp2x.h" +//#include "../gp2x/gp2x.h" #include "../gp2x/version.h" +#include "../common/emu.h" #include "sndout_oss.h" -#include "usbjoy.h" #include "log_io.h" -void *gp2x_screen; unsigned long current_keys = 0; 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; // dummies -char *ext_menu = 0, *ext_state = 0; int mix_32_to_16l_level; /* gtk */ @@ -48,6 +47,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) @@ -111,6 +116,16 @@ static gint key_release_event (GtkWidget *widget, GdkEventKey *event) return 0; } +static void size_allocate_event(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) +{ + // printf("%dx%d\n", allocation->width, allocation->height); + 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) { int argc = 0; @@ -137,7 +152,10 @@ static void *gtk_threadf(void *targ) g_signal_connect (G_OBJECT (gtk_items.window), "key_release_event", G_CALLBACK (key_release_event), NULL); - gtk_container_set_border_width (GTK_CONTAINER (gtk_items.window), 2); + g_signal_connect (G_OBJECT (gtk_items.window), "size_allocate", + G_CALLBACK (size_allocate_event), NULL); + + gtk_container_set_border_width (GTK_CONTAINER (gtk_items.window), 1); gtk_window_set_title ((GtkWindow *) gtk_items.window, verstring); box = gtk_hbox_new(FALSE, 0); @@ -182,28 +200,35 @@ void finalize_image(guchar *pixels, gpointer data) /* --- */ -void gp2x_init(void) +static void realloc_screen(void) +{ + void *old = g_screen_ptr; + g_screen_width = scr_w; + g_screen_height = scr_h; + g_screen_ptr = calloc(g_screen_width * g_screen_height * 2, 1); + free(old); + scr_changed = 0; +} + +void plat_init(void) { printf("entering init()\n"); fflush(stdout); - gp2x_screen = malloc(320*240*2 + 320*2); - memset(gp2x_screen, 0, 320*240*2 + 320*2); + realloc_screen(); + memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); // snd sndout_oss_init(); gtk_initf(); - usbjoy_init(); - printf("exitting init()\n"); fflush(stdout); } -void gp2x_deinit(void) +void plat_finish(void) { - free(gp2x_screen); + free(g_screen_ptr); sndout_oss_exit(); - usbjoy_deinit(); } /* video */ @@ -211,11 +236,13 @@ void gp2x_video_flip(void) { GdkPixbuf *pixbuf; unsigned char *image; - int i; + int pixel_count, i; + + pixel_count = g_screen_width * g_screen_height; gdk_threads_enter(); - image = malloc (320*240*3); + image = malloc(pixel_count * 3); if (image == NULL) { gdk_threads_leave(); @@ -224,10 +251,10 @@ void gp2x_video_flip(void) if (current_bpp == 8) { - unsigned char *pixels = gp2x_screen; + unsigned char *pixels = g_screen_ptr; int pix; - for (i = 0; i < 320*240; i++) + for (i = 0; i < pixel_count; i++) { pix = current_pal[pixels[i]]; image[3 * i + 0] = pix >> 16; @@ -237,9 +264,9 @@ void gp2x_video_flip(void) } else { - unsigned short *pixels = gp2x_screen; + unsigned short *pixels = g_screen_ptr; - for (i = 0; i < 320*240; i++) + for (i = 0; i < pixel_count; i++) { /* in: rrrr rggg gggb bbbb */ /* out: rrrr r000 gggg gg00 bbbb b000 */ @@ -250,11 +277,15 @@ void gp2x_video_flip(void) } pixbuf = gdk_pixbuf_new_from_data (image, GDK_COLORSPACE_RGB, - FALSE, 8, 320, 240, 320*3, finalize_image, NULL); + FALSE, 8, g_screen_width, g_screen_height, + g_screen_width * 3, finalize_image, NULL); gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_items.pixmap1), pixbuf); g_object_unref (pixbuf); gdk_threads_leave(); + + if (scr_changed) + realloc_screen(); } void gp2x_video_flip2(void) @@ -277,52 +308,16 @@ void gp2x_video_setpalette(int *pal, int len) memcpy(current_pal, pal, len*4); } -void gp2x_video_flush_cache(void) -{ -} - void gp2x_video_RGB_setscaling(int v_offs, int W, int H) { } -void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len) -{ - if ((char *)gp2x_screen + offset != data) - memcpy((char *)gp2x_screen + offset, data, len); -} - -void gp2x_memcpy_all_buffers(void *data, int offset, int len) -{ - memcpy((char *)gp2x_screen + offset, data, len); -} - - void gp2x_memset_all_buffers(int offset, int byte, int len) { - memset((char *)gp2x_screen + offset, byte, len); -} - -void gp2x_pd_clone_buffer2(void) -{ - memset(gp2x_screen, 0, 320*240*2); + memset((char *)g_screen_ptr + offset, byte, len); } /* joy */ -unsigned long gp2x_joystick_read(int allow_usb_joy) -{ - unsigned long value = current_keys; - int i; - - if (allow_usb_joy && num_of_joys > 0) { - // check the usb joy as well.. - usbjoy_update(); - for (i = 0; i < num_of_joys; i++) - value |= usbjoy_check(i); - } - - return value; -} - int gp2x_touchpad_read(int *x, int *y) { return -1; @@ -330,28 +325,11 @@ int gp2x_touchpad_read(int *x, int *y) /* 940 */ int crashed_940 = 0; -void Pause940(int yes) -{ -} - -void Reset940(int yes, int bank) -{ -} - -/* faking gp2x cpuctrl.c */ -void cpuctrl_init(void) -{ -} - -void cpuctrl_deinit(void) -{ -} - -void set_FCLK(unsigned MHZ) +void pause940(int yes) { } -void Disable_940(void) +void reset940(int yes, int bank) { } @@ -359,35 +337,18 @@ void gp2x_video_wait_vsync(void) { } -void set_RAM_Timings(int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD) -{ -} - void set_gamma(int g100, int A_SNs_curve) { } -void set_LCD_custom_rate(int rate) +void set_lcd_custom_rate(int rate) { } -void unset_LCD_custom_rate(void) +void unset_lcd_custom_rate(void) { } -/* squidgehack.c */ -int mmuhack(void) -{ - return 0; -} - - -int mmuunhack(void) -{ - return 0; -} - - /* misc */ void spend_cycles(int c) {