extend mmap wrapper functionality
[libpicofe.git] / gp2x / 940ctl.c
index f01ffa3..4bfd043 100644 (file)
 #include <errno.h>\r
 \r
 #include "code940/940shared.h"\r
-#include "gp2x.h"\r
-#include "emu.h"\r
-#include "menu.h"\r
+#include "soc_mmsp2.h"\r
+#include "soc.h"\r
 #include "../common/mp3.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/menu.h"\r
 #include "../common/emu.h"\r
-#include "../../Pico/PicoInt.h"\r
-#include "../../Pico/sound/ym2612.h"\r
-#include "../../Pico/sound/mix.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
-/* we will need some gp2x internals here */\r
-extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */\r
-extern volatile unsigned long  *gp2x_memregl;\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
@@ -150,7 +145,7 @@ static void wait_busy_940(int job)
                gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]);\r
        printf("last lr: %08x, lastjob: %i\n", shared_ctl->last_lr, shared_ctl->lastjob);\r
 \r
-       strcpy(menuErrorMsg, "940 crashed, too much overclock?");\r
+       me_update_msg("940 crashed, too much overclock?");\r
        engineState = PGS_Menu;\r
        crashed_940 = 1;\r
 }\r
@@ -247,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
@@ -270,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
@@ -280,15 +275,13 @@ 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
        printf("Mem usage: shared_data: %i, shared_ctl: %i\n", sizeof(*shared_data), sizeof(*shared_ctl));\r
 \r
-       Reset940(1, 2);\r
-       Pause940(1);\r
+       reset940(1, 2);\r
+       pause940(1);\r
 \r
        gp2x_memregs[0x3B40>>1] = 0;      // disable DUALCPU interrupts for 920\r
        gp2x_memregs[0x3B42>>1] = 1;      // enable  DUALCPU interrupts for 940\r
@@ -300,23 +293,19 @@ 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
-                       memset(gp2x_screen, 0, 320*240*2);\r
+                       memset(g_screen_ptr, 0, 320*240*2);\r
                        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
@@ -348,8 +337,8 @@ void YM2612Init_940(int baseclock, int rate)
        gp2x_memregl[0x4510>>2] = 0xffffffff; // clear pending IRQs in INTPND\r
 \r
        /* start the 940 */\r
-       Reset940(0, 2);\r
-       Pause940(0);\r
+       reset940(0, 2);\r
+       pause940(0);\r
 \r
        // YM2612ResetChip_940(); // will be done on JOB940_YM2612INIT\r
 \r
@@ -414,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
@@ -484,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
@@ -531,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
-}\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
+       add_job_940(JOB940_MP3RESET);\r
+       if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET);\r
 }\r
 \r
-\r