extend mmap wrapper functionality
[libpicofe.git] / gp2x / 940ctl.c
index 083036e..4bfd043 100644 (file)
 #include "code940/940shared.h"\r
 #include "soc_mmsp2.h"\r
 #include "soc.h"\r
-#include "emu.h"\r
 #include "../common/mp3.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/menu.h"\r
 #include "../common/emu.h"\r
+#include "../common/input.h"\r
 #include "../../pico/pico_int.h"\r
 #include "../../pico/sound/ym2612.h"\r
 #include "../../pico/sound/mix.h"\r
 \r
-extern int reset_timing;\r
 static unsigned char *shared_mem = 0;\r
 static _940_data_t *shared_data = 0;\r
 _940_ctl_t *shared_ctl = 0;\r
@@ -243,7 +242,7 @@ static void internal_reset(void)
 \r
 \r
 /* this must be called after mmu hack, the allocated regions must not get cached */\r
-void sharedmem_init(void)\r
+void sharedmem940_init(void)\r
 {\r
        if (shared_mem != NULL) return;\r
 \r
@@ -266,7 +265,7 @@ void sharedmem_init(void)
 }\r
 \r
 \r
-void sharedmem_deinit(void)\r
+void sharedmem940_finish(void)\r
 {\r
        munmap(shared_mem, 0x210000);\r
        munmap(mp3_mem, MP3_SIZE_MAX);\r
@@ -276,8 +275,6 @@ void sharedmem_deinit(void)
 }\r
 \r
 \r
-extern char **g_argv;\r
-\r
 void YM2612Init_940(int baseclock, int rate)\r
 {\r
        printf("YM2612Init_940()\n");\r
@@ -296,16 +293,11 @@ void YM2612Init_940(int baseclock, int rate)
        if (crashed_940)\r
        {\r
                unsigned char ucData[1024];\r
-               int nRead, i, nLen = 0;\r
-               char binpath[1024];\r
+               int nRead, nLen = 0;\r
+               char binpath[512];\r
                FILE *fp;\r
 \r
-               strncpy(binpath, g_argv[0], 1023);\r
-               binpath[1023] = 0;\r
-               for (i = strlen(binpath); i > 0; i--)\r
-                       if (binpath[i] == '/') { binpath[i] = 0; break; }\r
-               strcat(binpath, "/" CODE940_FILE);\r
-\r
+               emu_make_path(binpath, CODE940_FILE, sizeof(binpath));\r
                fp = fopen(binpath, "rb");\r
                if(!fp)\r
                {\r
@@ -313,6 +305,7 @@ void YM2612Init_940(int baseclock, int rate)
                        text_out16(10, 100, "failed to open required file:");\r
                        text_out16(10, 110, CODE940_FILE);\r
                        gp2x_video_flip2();\r
+                       in_menu_wait(PBTN_MOK|PBTN_MBACK, 100);\r
                        printf("failed to open %s\n", binpath);\r
                        exit(1);\r
                }\r
@@ -410,24 +403,24 @@ int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
 }\r
 \r
 \r
+/***********************************************************/\r
+\r
 static int mp3_samples_ready = 0, mp3_buffer_offs = 0;\r
 static int mp3_play_bufsel = 0, mp3_job_started = 0;\r
 \r
 void mp3_update(int *buffer, int length, int stereo)\r
 {\r
        int length_mp3;\r
-       int cdda_on;\r
-\r
-       // playback was started, track not ended\r
-       cdda_on = loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len;\r
-\r
-       if (!cdda_on) return;\r
 \r
-       if (!(PicoOpt&0x200)) {\r
+       if (!(PicoOpt & POPT_EXT_FM)) {\r
                mp3_update_local(buffer, length, stereo);\r
                return;\r
        }\r
 \r
+       // check if playback was started, track not ended\r
+       if (loaded_mp3 == NULL || shared_ctl->mp3_offs >= shared_ctl->mp3_len)\r
+               return;\r
+\r
        length_mp3 = length;\r
        if (PsndRate == 22050) length_mp3 <<= 1;        // mp3s are locked to 44100Hz stereo\r
        else if (PsndRate == 11025) length_mp3 <<= 2;   // so make length 44100ish\r
@@ -480,13 +473,16 @@ void mp3_update(int *buffer, int length, int stereo)
 }\r
 \r
 \r
-/***********************************************************/\r
-\r
-void mp3_start_play(FILE *f, int pos) // pos is 0-1023\r
+void mp3_start_play(void *f_, int pos) // pos is 0-1023\r
 {\r
        int byte_offs = 0;\r
+       FILE *f = f_;\r
+\r
+       if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL)\r
+               return;\r
 \r
-       if (!(PicoOpt&0x800)) { // cdda disabled?\r
+       if (!(PicoOpt & POPT_EXT_FM)) {\r
+               mp3_start_play_local(f, pos);\r
                return;\r
        }\r
 \r
@@ -527,31 +523,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
        mp3_job_started = 0;\r
        shared_ctl->mp3_buffsel = 1; // will change to 0 on first decode\r
 \r
-       if (PicoOpt & POPT_EXT_FM)\r
-       {\r
-               add_job_940(JOB940_MP3RESET);\r
-               if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET);\r
-       }\r
-       else\r
-               mp3_start_local();\r
+       add_job_940(JOB940_MP3RESET);\r
+       if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET);\r
 }\r
 \r
-\r
-int mp3_get_offset(void)\r
-{\r
-       unsigned int offs1024 = 0;\r
-       int cdda_on;\r
-\r
-       cdda_on = (PicoAHW & PAHW_MCD) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&\r
-                       (Pico_mcd->scd.Status_CDC & 1) && loaded_mp3;\r
-\r
-       if (cdda_on) {\r
-               offs1024  = shared_ctl->mp3_offs << 7;\r
-               offs1024 /= shared_ctl->mp3_len  >> 3;\r
-       }\r
-       printf("offs1024=%u (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len);\r
-\r
-       return offs1024;\r
-}\r
-\r
-\r