some ts support, currently for Pico only
[libpicofe.git] / linux / gp2x.c
index f5da167..ef21a67 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
+#include <semaphore.h>
 #include <gtk/gtk.h>
 
 #include <unistd.h>
@@ -29,6 +30,7 @@ static const char *verstring = "PicoDrive " VERSION;
 
 // dummies
 char *ext_menu = 0, *ext_state = 0;
+int mix_32_to_16l_level;
 
 /* gtk */
 struct gtk_global_struct
@@ -69,6 +71,11 @@ static gint key_press_event (GtkWidget *widget, GdkEventKey *event)
                case 0x19: current_keys |= GP2X_VOL_UP;break; // w
                case 0x2d: log_io_clear(); break; // k
                case 0x2e: log_io_dump();  break; // l
+               case 0x17: { // tab
+                       extern int PicoReset(void);
+                       PicoReset();
+                       break;
+               }
        }
 
        return 0;
@@ -98,22 +105,12 @@ static gint key_release_event (GtkWidget *widget, GdkEventKey *event)
        return 0;
 }
 
-static void *gtk_threadf(void *none)
-{
-       gtk_main();
-
-       printf("linux: gtk thread finishing\n");
-       engineState = PGS_Quit;
-
-       return NULL;
-}
-
-static void gtk_initf(void)
+static void *gtk_threadf(void *targ)
 {
        int argc = 0;
        char *argv[] = { "" };
        GtkWidget *box;
-       pthread_t gtk_thread;
+       sem_t *sem = targ;
 
        g_thread_init (NULL);
        gdk_threads_init ();
@@ -149,11 +146,27 @@ static void gtk_initf(void)
 
        gtk_widget_show  (gtk_items.window);
 
-       // pthread_mutex_init (&thr_mutex, NULL);
-       // pthread_mutex_lock (&thr_mutex);
-       // pthread_mutex_init (&scanner_muttex, NULL);
+       sem_post(sem);
+
+       gtk_main();
+
+       printf("linux: gtk thread finishing\n");
+       exit(1);
+
+       return NULL;
+}
+
+static void gtk_initf(void)
+{
+       pthread_t gtk_thread;
+       sem_t sem;
+       sem_init(&sem, 0, 0);
+
+       pthread_create(&gtk_thread, NULL, gtk_threadf, &sem);
+       pthread_detach(gtk_thread);
 
-       pthread_create(&gtk_thread, NULL, gtk_threadf, NULL);
+       sem_wait(&sem);
+       sem_close(&sem);
 }
 
 void finalize_image(guchar *pixels, gpointer data)
@@ -355,6 +368,11 @@ unsigned long gp2x_joystick_read(int allow_usb_joy)
        return value;
 }
 
+int gp2x_touchpad_read(int *x, int *y)
+{
+       return -1;
+}
+
 /* 940 */
 int crashed_940 = 0;
 void Pause940(int yes)
@@ -421,5 +439,13 @@ void spend_cycles(int c)
        usleep(c/200);
 }
 
+/* lprintf */
+void lprintf(const char *fmt, ...)
+{
+       va_list vl;
 
+       va_start(vl, fmt);
+       vprintf(fmt, vl);
+       va_end(vl);
+}