revive GP2X build, update
[picodrive.git] / platform / gp2x / emu.c
index 825ab5b..7db89c2 100644 (file)
 #include <stdlib.h>\r
 #include <unistd.h>\r
 \r
-#include "plat_gp2x.h"\r
-#include "soc.h"\r
-#include "soc_pollux.h"\r
-#include "../common/plat.h"\r
-#include "../common/menu.h"\r
+#include "../libpicofe/gp2x/plat_gp2x.h"\r
+#include "../libpicofe/gp2x/soc.h"\r
+#include "../libpicofe/input.h"\r
+#include "../libpicofe/plat.h"\r
+#include "../libpicofe/gp2x/soc_pollux.h"\r
+#include "../common/menu_pico.h"\r
 #include "../common/arm_utils.h"\r
-#include "../common/fonts.h"\r
 #include "../common/emu.h"\r
-#include "../common/config.h"\r
-#include "../common/input.h"\r
-#include "../linux/sndout_oss.h"\r
-#include "version.h"\r
+#include "../common/config_file.h"\r
+#include "../common/version.h"\r
+#include "plat.h"\r
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
@@ -40,9 +39,8 @@
 #endif\r
 \r
 \r
-extern int crashed_940;\r
+//extern int crashed_940;\r
 \r
-static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50];\r
 static int osd_fps_x, osd_y, doing_bg_frame;\r
 const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };\r
 const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };\r
@@ -51,8 +49,6 @@ enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
 static int (*emu_scan_begin)(unsigned int num) = NULL;\r
 static int (*emu_scan_end)(unsigned int num) = NULL;\r
 \r
-extern void *gp2x_screens[4];\r
-\r
 \r
 void pemu_prep_defconfig(void)\r
 {\r
@@ -670,8 +666,8 @@ static void RunEventsPico(unsigned int events)
 void plat_update_volume(int has_changed, int is_up)\r
 {\r
        static int prev_frame = 0, wait_frames = 0;\r
-       int vol = currentConfig.volume;\r
        int need_low_volume = 0;\r
+       int vol = currentConfig.volume;\r
        gp2x_soc_t soc;\r
 \r
        soc = soc_detect();\r
@@ -683,14 +679,9 @@ void plat_update_volume(int has_changed, int is_up)
                if (need_low_volume && vol < 5 && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r
                        wait_frames++;\r
                else {\r
-                       if (is_up) {\r
-                               if (vol < 99) vol++;\r
-                       } else {\r
-                               if (vol >  0) vol--;\r
-                       }\r
                        wait_frames = 0;\r
-                       sndout_oss_setvol(vol, vol);\r
-                       currentConfig.volume = vol;\r
+                       plat_target_step_volume(&currentConfig.volume, is_up ? 1 : -1);\r
+                       vol = currentConfig.volume;\r
                }\r
                emu_status_msg("VOL: %02i", vol);\r
                prev_frame = Pico.m.frame_count;\r
@@ -708,17 +699,13 @@ void plat_update_volume(int has_changed, int is_up)
        }\r
 }\r
 \r
-static void oss_write_nonblocking(int len)\r
+void pemu_sound_start(void)\r
 {\r
-       // sndout_oss_can_write() is not reliable, only use with no_frmlimit\r
-       if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))\r
-               return;\r
+       emu_sound_start();\r
 \r
-       sndout_oss_write_nb(PsndOut, len);\r
-}\r
+       plat_target_step_volume(&currentConfig.volume, 0);\r
 \r
-void pemu_sound_start(void)\r
-{\r
+#if 0\r
        static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
 \r
        PsndOut = NULL;\r
@@ -754,6 +741,7 @@ void pemu_sound_start(void)
                PicoOpt_old  = PicoOpt;\r
                pal_old = Pico.m.pal;\r
        }\r
+#endif\r
 }\r
 \r
 static const int sound_rates[] = { 44100, 32000, 22050, 16000, 11025, 8000 };\r
@@ -772,11 +760,6 @@ void pemu_sound_stop(void)
        }\r
 }\r
 \r
-void pemu_sound_wait(void)\r
-{\r
-       // don't need to do anything, writes will block by themselves\r
-}\r
-\r
 void pemu_forced_frame(int no_scale, int do_emu)\r
 {\r
        doing_bg_frame = 1;\r
@@ -794,110 +777,23 @@ void plat_debug_cat(char *str)
 {\r
 }\r
 \r
-#if 0\r
-static void tga_dump(void)\r
+void plat_video_loop_prepare(void) \r
 {\r
-#define BYTE unsigned char\r
-#define WORD unsigned short\r
-       struct\r
-       {\r
-               BYTE IDLength;        /* 00h  Size of Image ID field */\r
-               BYTE ColorMapType;    /* 01h  Color map type */\r
-               BYTE ImageType;       /* 02h  Image type code */\r
-               WORD CMapStart;       /* 03h  Color map origin */\r
-               WORD CMapLength;      /* 05h  Color map length */\r
-               BYTE CMapDepth;       /* 07h  Depth of color map entries */\r
-               WORD XOffset;         /* 08h  X origin of image */\r
-               WORD YOffset;         /* 0Ah  Y origin of image */\r
-               WORD Width;           /* 0Ch  Width of image */\r
-               WORD Height;          /* 0Eh  Height of image */\r
-               BYTE PixelDepth;      /* 10h  Image pixel size */\r
-               BYTE ImageDescriptor; /* 11h  Image descriptor byte */\r
-       } __attribute__((packed)) TGAHEAD;\r
-       static unsigned short oldscr[320*240];\r
-       FILE *f; char name[128]; int i;\r
-\r
-       memset(&TGAHEAD, 0, sizeof(TGAHEAD));\r
-       TGAHEAD.ImageType = 2;\r
-       TGAHEAD.Width = 320;\r
-       TGAHEAD.Height = 240;\r
-       TGAHEAD.PixelDepth = 16;\r
-       TGAHEAD.ImageDescriptor = 2<<4; // image starts at top-left\r
-\r
-#define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555?\r
-\r
-       for (i = 0; i < 320*240; i++)\r
-               if(oldscr[i] != CONV(((unsigned short *)g_screen_ptr)[i])) break;\r
-       if (i < 320*240)\r
-       {\r
-               for (i = 0; i < 320*240; i++)\r
-                       oldscr[i] = CONV(((unsigned short *)g_screen_ptr)[i]);\r
-               sprintf(name, "%05i.tga", Pico.m.frame_count);\r
-               f = fopen(name, "wb");\r
-               if (!f) { printf("!f\n"); exit(1); }\r
-               fwrite(&TGAHEAD, 1, sizeof(TGAHEAD), f);\r
-               fwrite(oldscr, 1, 320*240*2, f);\r
-               fclose(f);\r
-       }\r
+       // make sure we are in correct mode\r
+       change_renderer(0);\r
+       vid_reset_mode();\r
 }\r
-#endif\r
 \r
 void pemu_loop_prep(void)\r
 {\r
-       static int gp2x_old_clock = -1, EmuOpt_old = 0, pal_old = 0;\r
-       static int gp2x_old_gamma = 100;\r
-       gp2x_soc_t soc;\r
-\r
-       soc = soc_detect();\r
-\r
-       if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_RAM_TIMINGS) {\r
-               if (currentConfig.EmuOpt & EOPT_RAM_TIMINGS)\r
-                       set_ram_timings();\r
-               else\r
-                       unset_ram_timings();\r
-       }\r
-\r
-       if (gp2x_old_clock < 0)\r
-               gp2x_old_clock = default_cpu_clock;\r
-       if (gp2x_old_clock != currentConfig.CPUclock && gp2x_set_cpuclk != NULL) {\r
-               printf("changing clock to %i...", currentConfig.CPUclock); fflush(stdout);\r
-               gp2x_set_cpuclk(currentConfig.CPUclock);\r
-               gp2x_old_clock = currentConfig.CPUclock;\r
-               printf(" done\n");\r
-       }\r
-\r
-       if (gp2x_old_gamma != currentConfig.gamma || ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_A_SN_GAMMA)) {\r
-               set_lcd_gamma(currentConfig.gamma, !!(currentConfig.EmuOpt & EOPT_A_SN_GAMMA));\r
-               gp2x_old_gamma = currentConfig.gamma;\r
-               printf("updated gamma to %i, A_SN's curve: %i\n", currentConfig.gamma, !!(currentConfig.EmuOpt&0x1000));\r
-       }\r
-\r
-       if (((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_VSYNC) || Pico.m.pal != pal_old) {\r
-               if ((currentConfig.EmuOpt & EOPT_VSYNC) || soc == SOCID_POLLUX)\r
-                       set_lcd_custom_rate(Pico.m.pal);\r
-               else if (EmuOpt_old & EOPT_VSYNC)\r
-                       unset_lcd_custom_rate();\r
-       }\r
-\r
        if (gp2x_dev_id == GP2X_DEV_CAANOO)\r
-               in_set_config_int(in_name_to_id("evdev:pollux-analog"), IN_CFG_ABS_DEAD_ZONE,\r
-                               currentConfig.analog_deadzone);\r
-\r
-       if ((EmuOpt_old ^ currentConfig.EmuOpt) & EOPT_MMUHACK)\r
-               gp2x_make_fb_bufferable(currentConfig.EmuOpt & EOPT_MMUHACK);\r
-\r
-       EmuOpt_old = currentConfig.EmuOpt;\r
-       pal_old = Pico.m.pal;\r
-\r
-       // make sure we are in correct mode\r
-       change_renderer(0);\r
-       vid_reset_mode();\r
+               in_set_config_int(in_name_to_id("evdev:pollux-analog"),\r
+                       IN_CFG_ABS_DEAD_ZONE,\r
+                       currentConfig.analog_deadzone);\r
 \r
        // dirty buffers better go now than during gameplay\r
        sync();\r
        sleep(0);\r
-\r
-       pemu_sound_start();\r
 }\r
 \r
 void pemu_loop_end(void)\r