gl: clear w, h on reinit
[libpicofe.git] / gp2x / plat.c
index 16fa183..e80b0fb 100644 (file)
+/*
+ * (C) notaz, 2013
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ *  - GNU GPL, version 2 or later.
+ *  - GNU LGPL, version 2.1 or later.
+ *  - MAME license.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <linux/input.h>
+#include <errno.h>
+
+#include "../plat.h"
+#include "../input.h"
+#include "plat_gp2x.h"
+#include "soc.h"
+
+int default_cpu_clock;
+int gp2x_dev_id;
 
-#include "gp2x.h"
-#include "../common/plat.h"
-#include "../common/readpng.h"
-#include "../common/menu.h"
+static const char * const caanoo_keys[KEY_MAX + 1] = {
+       [0 ... KEY_MAX] = NULL,
+       [KEY_UP]        = "Up",
+       [KEY_LEFT]      = "Left",
+       [KEY_RIGHT]     = "Right",
+       [KEY_DOWN]      = "Down",
+       [BTN_TRIGGER]   = "A",
+       [BTN_THUMB]     = "X",
+       [BTN_THUMB2]    = "B",
+       [BTN_TOP]       = "Y",
+       [BTN_TOP2]      = "L",
+       [BTN_PINKIE]    = "R",
+       [BTN_BASE]      = "Home",
+       [BTN_BASE2]     = "Lock",
+       [BTN_BASE3]     = "I",
+       [BTN_BASE4]     = "II",
+       [BTN_BASE5]     = "Push",
+};
 
+/* to be filled by mmsp2/pollux _init */
+struct plat_target plat_target;
 
-void plat_video_menu_enter(int is_rom_loaded)
+int plat_target_init(void)
 {
-       if (is_rom_loaded)
-       {
-               // darken the active framebuffer
-               memset(gp2x_screen, 0, 320*8*2);
-               menu_darken_bg((char *)gp2x_screen + 320*8*2, 320*224, 1);
-               memset((char *)gp2x_screen + 320*232*2, 0, 320*8*2);
-       }
-       else
+       gp2x_soc_t soc;
+       FILE *f;
+
+       soc = soc_detect();
+       switch (soc)
        {
-               // should really only happen once, on startup..
-               readpng(gp2x_screen, "skin/background.png", READPNG_BG);
+       case SOCID_MMSP2:
+               mmsp2_init();
+               default_cpu_clock = 200;
+               gp2x_dev_id = GP2X_DEV_GP2X;
+               break;
+       case SOCID_POLLUX:
+               pollux_init();
+               default_cpu_clock = 533;
+               f = fopen("/dev/accel", "rb");
+               if (f) {
+                       printf("detected Caanoo\n");
+                       gp2x_dev_id = GP2X_DEV_CAANOO;
+                       fclose(f);
+               }
+               else {
+                       printf("detected Wiz\n");
+                       gp2x_dev_id = GP2X_DEV_WIZ;
+               }
+               break;
+       default:
+               printf("could not recognize SoC.\n");
+               break;
        }
 
-       // copy to buffer2
-       gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);
-
-       // switch to 16bpp
-       gp2x_video_changemode2(16);
-       gp2x_video_RGB_setscaling(0, 320, 240);
-       gp2x_video_flip2();
+       return 0;
 }
 
-void plat_video_menu_begin(void)
+/* to be called after in_probe */
+void plat_target_setup_input(void)
 {
-       gp2x_pd_clone_buffer2();
+       if (gp2x_dev_id == GP2X_DEV_CAANOO)
+               in_set_config(in_name_to_id("evdev:pollux-analog"),
+                       IN_CFG_KEY_NAMES,
+                       caanoo_keys, sizeof(caanoo_keys));
 }
 
-void plat_video_menu_end(void)
+void plat_target_finish(void)
 {
-       gp2x_video_flush_cache();
-       gp2x_video_flip2();
-}
+       gp2x_soc_t soc;
 
+       soc = soc_detect();
+       switch (soc)
+       {
+       case SOCID_MMSP2:
+               mmsp2_finish();
+               break;
+       case SOCID_POLLUX:
+               pollux_finish();
+               break;
+       default:
+               break;
+       }
+}