PCM sound, refactored code940
authornotaz <notasas@gmail.com>
Sun, 4 Feb 2007 17:15:31 +0000 (17:15 +0000)
committernotaz <notasas@gmail.com>
Sun, 4 Feb 2007 17:15:31 +0000 (17:15 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@27 be3aeb3a-fb24-0410-a615-afba39da0efa

gp2x/940ctl_ym2612.c
gp2x/940ctl_ym2612.h
gp2x/Makefile
gp2x/asmutils.h
gp2x/asmutils.s
gp2x/emu.c
gp2x/emu.h
gp2x/menu.c
linux/940ctl_ym2612.c
linux/Makefile

index 63d1e48..3502b82 100644 (file)
@@ -14,6 +14,9 @@
 #include "asmutils.h"\r
 #include "../../Pico/PicoInt.h"\r
 \r
+// tmp\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
@@ -223,6 +226,7 @@ int YM2612PicoTick_940(int n)
        return 0;\r
 }\r
 \r
+static int g_busy = 10;\r
 \r
 static void wait_busy_940(void)\r
 {\r
@@ -239,8 +243,9 @@ static void wait_busy_940(void)
        }\r
        printf("wait iterations: %i\n", i);\r
 #else\r
-       for (i = 0; shared_ctl->busy && i < 0x10000; i++)\r
+       for (i = 0; /*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1] && i < 0x10000; i++)\r
                spend_cycles(8*1024); // tested to be best for mp3 dec\r
+       //printf("i = 0x%x\n", i);\r
        if (i < 0x10000) return;\r
 \r
        /* 940 crashed */\r
@@ -248,6 +253,19 @@ static void wait_busy_940(void)
        for (i = 0; i < 8; i++)\r
                printf("%i ", shared_ctl->vstarts[i]);\r
        printf(")\n");\r
+       printf("irq pending flags: DUALCPU %04x (see 15?), SRCPND %08lx (see 26), INTPND %08lx\n",\r
+               gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]);\r
+       printf("last irq PC: %08x, lastjob: 0x%03x, busy: %x, lastbusy: %x, g_busy: %x\n", shared_ctl->last_irq_pc,\r
+                       shared_ctl->lastjob, gp2x_memregs[0x3B3E>>1]/*shared_ctl->busy*/, shared_ctl->lastbusy, g_busy);\r
+       printf("trying to interrupt..\n");\r
+       gp2x_memregs[0x3B3E>>1] = 0xffff;\r
+       for (i = 0; /*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1] && i < 0x10000; i++)\r
+               spend_cycles(8*1024);\r
+       printf("i = 0x%x\n", i);\r
+       printf("irq pending flags: DUALCPU %04x (see 15?), SRCPND %08lx (see 26), INTPND %08lx\n",\r
+               gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]);\r
+       printf("last irq PC: %08x, lastjob: 0x%03x, busy: %x\n", shared_ctl->last_irq_pc, shared_ctl->lastjob, gp2x_memregs[0x3B3E>>1]/*shared_ctl->busy*/);\r
+\r
        strcpy(menuErrorMsg, "940 crashed.");\r
        engineState = PGS_Menu;\r
        crashed_940 = 1;\r
@@ -257,10 +275,17 @@ static void wait_busy_940(void)
 \r
 static void add_job_940(int job0, int job1)\r
 {\r
+/*     if (gp2x_memregs[0x3b46>>1] || shared_ctl->busy)\r
+       {\r
+               printf("!!add_job_940: irq pending flags: DUALCPU %04x (see 15?), SRCPND %08lx (see 26), INTPND %08lx, busy: %x\n",\r
+                               gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2], shared_ctl->busy);\r
+       }\r
+*/\r
        shared_ctl->jobs[0] = job0;\r
        shared_ctl->jobs[1] = job1;\r
-       shared_ctl->busy = 1;\r
-       gp2x_memregs[0x3B3E>>1] = 0xffff; // cause an IRQ for 940\r
+       //shared_ctl->busy = ++g_busy; // 1;\r
+       gp2x_memregs[0x3B3E>>1] = ++g_busy; // set busy flag\r
+//     gp2x_memregs[0x3B3E>>1] = 0xffff; // cause interrupt\r
 }\r
 \r
 \r
@@ -268,7 +293,7 @@ void YM2612PicoStateLoad_940(void)
 {\r
        int i, old_A1 = addr_A1;\r
 \r
-       if (shared_ctl->busy) wait_busy_940();\r
+       if (/*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1]) wait_busy_940();\r
 \r
        // feed all the registers and update internal state\r
        for(i = 0; i < 0x100; i++) {\r
@@ -310,10 +335,8 @@ void YM2612Init_940(int baseclock, int rate)
        Reset940(1, 2);\r
        Pause940(1);\r
 \r
-       gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940\r
-       gp2x_memregs[0x3B42>>1] = 0xffff; // enable DUALCPU interrupts for 940\r
-\r
-       gp2x_memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller\r
+       gp2x_memregs[0x3B40>>1] = 0;      // disable DUALCPU interrupts for 920\r
+       gp2x_memregs[0x3B42>>1] = 1;      // enable  DUALCPU interrupts for 940\r
 \r
        if (shared_mem == NULL)\r
        {\r
@@ -388,7 +411,13 @@ void YM2612Init_940(int baseclock, int rate)
        shared_ctl->rate = rate;\r
        shared_ctl->jobs[0] = JOB940_INITALL;\r
        shared_ctl->jobs[1] = 0;\r
-       shared_ctl->busy = 1;\r
+       //shared_ctl->busy = 1;\r
+       gp2x_memregs[0x3B3E>>1] = 1; // set busy flag\r
+\r
+       gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940\r
+       gp2x_memregl[0x4500>>2] = 0; // clear pending IRQs in SRCPND\r
+       gp2x_memregl[0x4510>>2] = 0; // clear pending IRQs in INTPND\r
+       gp2x_memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller\r
 \r
        /* start the 940 */\r
        Reset940(0, 2);\r
@@ -406,7 +435,7 @@ void YM2612ResetChip_940(void)
                return;\r
        }\r
 \r
-       if (shared_ctl->busy) wait_busy_940();\r
+       if (/*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1]) wait_busy_940();\r
 \r
        internal_reset();\r
 \r
@@ -414,104 +443,93 @@ void YM2612ResetChip_940(void)
 }\r
 \r
 \r
-static void mix_samples(short *dest_buf, int *ym_buf, short *mp3_buf, int len, int stereo)\r
+//extern int pcm_buffer[2*44100/50];\r
+/*\r
+static void mix_samples(int *dest_buf, short *mp3_buf, int len, int stereo)\r
 {\r
-       if (mp3_buf)\r
+//     int *pcm = pcm_buffer + offset * 2;\r
+\r
+       if (stereo)\r
        {\r
-               if (stereo)\r
+               for (; len > 0; len--)\r
                {\r
-                       for (; len > 0; len--)\r
-                       {\r
-                               int l, r, lm, rm;\r
-                               l = r = *dest_buf;\r
-                               l += *ym_buf++;  r += *ym_buf++;\r
-                               lm = *mp3_buf++; rm = *mp3_buf++;\r
-                               l += lm - lm/2; r += rm - rm/2;\r
-                               Limit( l, MAXOUT, MINOUT );\r
-                               Limit( r, MAXOUT, MINOUT );\r
-                               *dest_buf++ = l; *dest_buf++ = r;\r
-                       }\r
-               } else {\r
-                       for (; len > 0; len--)\r
-                       {\r
-                               // TODO: normalize\r
-                               int l = *ym_buf++;\r
-                               l += *dest_buf;\r
-                               l += *mp3_buf++;\r
-                               Limit( l, MAXOUT, MINOUT );\r
-                               *dest_buf++ = l;\r
-                       }\r
+                       int lm, rm;\r
+                       lm = *mp3_buf++; rm = *mp3_buf++;\r
+                       *dest_buf++ += lm - lm/2; *dest_buf++ += rm - rm/2;\r
                }\r
-       }\r
-       else\r
-       {\r
-               if (stereo)\r
+       } else {\r
+               for (; len > 0; len--)\r
                {\r
-                       for (; len > 0; len--)\r
-                       {\r
-                               int l, r;\r
-                               l = r = *dest_buf;\r
-                               l += *ym_buf++, r += *ym_buf++;\r
-                               Limit( l, MAXOUT, MINOUT );\r
-                               Limit( r, MAXOUT, MINOUT );\r
-                               *dest_buf++ = l; *dest_buf++ = r;\r
-                       }\r
-               } else {\r
-                       for (; len > 0; len--)\r
-                       {\r
-                               int l = *ym_buf++;\r
-                               l += *dest_buf;\r
-                               Limit( l, MAXOUT, MINOUT );\r
-                               *dest_buf++ = l;\r
-                       }\r
+                       int l = *mp3_buf++;\r
+                       *dest_buf++ = l - l/2;\r
                }\r
        }\r
 }\r
-\r
+*/\r
 \r
 // here we assume that length is different between games, but constant in one game\r
 \r
 static int mp3_samples_ready = 0, mp3_buffer_offs = 0;\r
 static int mp3_play_bufsel = 0;\r
 \r
-void YM2612UpdateOne_940(short *buffer, int length, int stereo)\r
+int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)\r
 {\r
-       int cdda_on, *ym_buffer = shared_data->mix_buffer, mp3_job = 0;\r
+       int length_mp3 = Pico.m.pal ? 44100/50 : 44100/60; // mp3s are locked to 44100Hz stereo\r
+       int *ym_buf = shared_data->mix_buffer;\r
+//     int *dest_buf = buffer;\r
+       int cdda_on, mp3_job = 0;\r
+//     int len;\r
+\r
+       // emulating CD, enabled in opts, not data track, CDC is reading, playback was started, track not ended\r
+       cdda_on = (PicoMCD & 1) && (PicoOpt & 0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&\r
+               (Pico_mcd->scd.Status_CDC & 1) && loaded_mp3;\r
 \r
        //printf("YM2612UpdateOne_940()\n");\r
-       if (shared_ctl->busy) wait_busy_940();\r
+       if (/*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1]) wait_busy_940();\r
 \r
-       //printf("940 (cnt: %i, wc: %i, ve: ", shared_ctl->loopc, shared_ctl->waitc);\r
-       //for (i = 0; i < 8; i++)\r
-       //      printf("%i ", shared_ctl->vstarts[i]);\r
-       //printf(")\n");\r
+       // track ended?\r
+       cdda_on = cdda_on && shared_ctl->mp3_offs < shared_ctl->mp3_len;\r
 \r
-       // emulatind MCD, cdda enabled in config, not data track, CDC is reading, playback was started, track not ended\r
-       cdda_on = (PicoMCD & 1) && (currentConfig.EmuOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&\r
-                       (Pico_mcd->scd.Status_CDC & 1) && loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len;\r
+       // mix in ym buffer\r
+       if (is_buf_empty) memcpy32(buffer, ym_buf, length<<stereo);\r
+       // else TODO\r
+\r
+//     for (len = length << stereo; len > 0; len--)\r
+//     {\r
+//             *dest_buf++ += *ym_buf++;\r
+//     }\r
 \r
-       /* mix data from previous go */\r
-       if (cdda_on && mp3_samples_ready >= length)\r
+       /* mix mp3 data, only stereo */\r
+       if (cdda_on && mp3_samples_ready >= length_mp3)\r
        {\r
-               if (1152 - mp3_buffer_offs >= length) {\r
-                       mix_samples(buffer, ym_buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length, stereo);\r
+               int shr = 0;\r
+               void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;\r
+               if (PsndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; }\r
+               else if (PsndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; }\r
 \r
-                       mp3_buffer_offs += length;\r
+               if (1152 - mp3_buffer_offs >= length_mp3) {\r
+                       mix_samples(buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, (length_mp3>>shr)<<1);\r
+\r
+                       mp3_buffer_offs += length_mp3;\r
                } else {\r
                        // collect from both buffers..\r
                        int left = 1152 - mp3_buffer_offs;\r
-                       mix_samples(buffer, ym_buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, left, stereo);\r
-                       mp3_play_bufsel ^= 1;\r
-                       mp3_buffer_offs = length - left;\r
-                       mix_samples(buffer + left * 2, ym_buffer + left * 2,\r
-                               shared_data->mp3_buffer[mp3_play_bufsel], mp3_buffer_offs, stereo);\r
+                       if (mp3_play_bufsel == 0)\r
+                       {\r
+                               mix_samples(buffer, shared_data->mp3_buffer[0] + mp3_buffer_offs*2, (length_mp3>>shr)<<1);\r
+                               mp3_buffer_offs = length_mp3 - left;\r
+                               mp3_play_bufsel = 1;\r
+                       } else {\r
+                               mix_samples(buffer, shared_data->mp3_buffer[1] + mp3_buffer_offs*2, (left>>shr)<<1);\r
+                               mp3_buffer_offs = length_mp3 - left;\r
+                               mix_samples(buffer + ((left>>shr)<<1),\r
+                                       shared_data->mp3_buffer[0], (mp3_buffer_offs>>shr)<<1);\r
+                               mp3_play_bufsel = 0;\r
+                       }\r
                }\r
-               mp3_samples_ready -= length;\r
-       } else {\r
-               mix_samples(buffer, ym_buffer, 0, length, stereo);\r
+               mp3_samples_ready -= length_mp3;\r
        }\r
 \r
-       //printf("new writes: %i\n", writebuff_ptr);\r
        if (shared_ctl->writebuffsel == 1) {\r
                shared_ctl->writebuff0[writebuff_ptr] = 0xffff;\r
        } else {\r
@@ -525,7 +543,7 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo)
        shared_ctl->stereo = stereo;\r
 \r
        // make sure we will have enough mp3 samples next frame\r
-       if (cdda_on && mp3_samples_ready < length)\r
+       if (cdda_on && mp3_samples_ready < length_mp3)\r
        {\r
                shared_ctl->mp3_buffsel ^= 1;\r
                mp3_job = JOB940_MP3DECODE;\r
@@ -536,6 +554,8 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo)
        //spend_cycles(512);\r
        //printf("SRCPND: %08lx, INTMODE: %08lx, INTMASK: %08lx, INTPEND: %08lx\n",\r
        //      gp2x_memregl[0x4500>>2], gp2x_memregl[0x4504>>2], gp2x_memregl[0x4508>>2], gp2x_memregl[0x4510>>2]);\r
+\r
+       return 1;\r
 }\r
 \r
 \r
@@ -551,11 +571,11 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
 \r
        if (loaded_mp3 != f)\r
        {\r
-               printf("loading mp3... "); fflush(stdout);\r
+               // printf("loading mp3... "); fflush(stdout);\r
                fseek(f, 0, SEEK_SET);\r
                fread(mp3_mem, 1, MP3_SIZE_MAX, f);\r
-               if (feof(f)) printf("done.\n");\r
-               else printf("done. mp3 too large, not all data loaded.\n");\r
+               // if (feof(f)) printf("done.\n");\r
+               // else printf("done. mp3 too large, not all data loaded.\n");\r
                shared_ctl->mp3_len = ftell(f);\r
                loaded_mp3 = f;\r
        }\r
@@ -566,7 +586,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
                byte_offs *= pos;\r
                byte_offs >>= 6;\r
        }\r
-       printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);\r
+       // printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);\r
 \r
        shared_ctl->mp3_offs = byte_offs;\r
 \r
index 7d94c13..bf9b528 100644 (file)
@@ -1,6 +1,6 @@
 void YM2612Init_940(int baseclock, int rate);\r
 void YM2612ResetChip_940(void);\r
-void YM2612UpdateOne_940(short *buffer, int length, int stereo);\r
+int  YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty);\r
 \r
 int  YM2612Write_940(unsigned int a, unsigned int v);\r
 unsigned char YM2612Read_940(void);\r
index d253dcc..5efe302 100644 (file)
@@ -41,7 +41,7 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory
 # Pico - CD\r
 OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \\r
                ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \\r
-               ../../Pico/cd/Area.o ../../Pico/cd/Misc.o\r
+               ../../Pico/cd/Area.o ../../Pico/cd/Misc.o ../../Pico/cd/pcm.o\r
 # asm stuff\r
 ifeq "$(asm_render)" "1"\r
 DEFINC += -D_ASM_DRAW_C\r
@@ -56,6 +56,7 @@ DEFINC += -D_ASM_YM2612_C
 OBJS += ../../Pico/sound/ym2612_asm.o\r
 endif\r
 # Pico - sound\r
+OBJS += ../../Pico/sound/mix_asm.o\r
 OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o\r
 # zlib\r
 OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \\r
@@ -94,7 +95,7 @@ ifeq "$(up)" "1"
        @cmd //C copy $@ \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\\r
 endif\r
 \r
-up:\r
+up: PicoDrive.gpe\r
        @cp -v PicoDrive.gpe /mnt/gp2x/mnt/sd/games/PicoDrive/\r
 \r
 #      @cmd //C copy PicoDrive.gpe \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\\r
@@ -124,6 +125,9 @@ testrefr.gpe : test.o gp2x.o asmutils.o
 ../../Pico/sound/ym2612_asm.o : ../../Pico/sound/ym2612.s\r
        @echo $<\r
        @$(AS) $(ASOPT) $< -o $@\r
+../../Pico/sound/mix_asm.o : ../../Pico/sound/mix.s\r
+       @echo $<\r
+       @$(AS) $(ASOPT) $< -o $@\r
 \r
 # build Cyclone\r
 ../../cpu/Cyclone/proj/Cyclone.s :\r
index d922690..cade08c 100644 (file)
@@ -10,3 +10,5 @@ void vidCpyM2_40col(void *dest, void *src);
 void vidCpyM2_32col(void *dest, void *src);\r
 void vidCpyM2_32col_nobord(void *dest, void *src);\r
 void spend_cycles(int c); // utility\r
+void flushcache(void);\r
+\r
index e1e0945..92226b3 100644 (file)
@@ -3,6 +3,7 @@
 @ (c) Copyright 2006, notaz\r
 @ All Rights Reserved\r
 \r
+@ vim:filetype=armasm\r
 \r
 @ Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0\r
 @ to      00000000 rrr00000 ggg00000 bbb00000 ...\r
@@ -197,7 +198,6 @@ vidCpyM2_32col_nobord:
     b       vidCpyM2_32_loop_out\r
 \r
 \r
-@ test\r
 .global spend_cycles @ c\r
 \r
 spend_cycles:\r
@@ -208,3 +208,12 @@ spend_cycles:
     bpl     .sc_loop\r
 \r
     bx      lr\r
+\r
+\r
+@ test\r
+.global flushcache\r
+\r
+flushcache:                                                                                                                                \r
+    swi #0x9f0002                                                                                                                      \r
+    mov pc, lr                                                                                                                         \r
+                               \r
index 633a780..e564dfb 100644 (file)
@@ -276,6 +276,7 @@ int emu_ReloadRom(void)
                // bios_help() ?\r
                return 0;\r
        } else {\r
+               if (PicoMCD & 1) PicoExitMCD();\r
                PicoMCD &= ~1;\r
        }\r
 \r
@@ -374,7 +375,7 @@ int emu_ReloadRom(void)
                }\r
        }\r
        gettimeofday(&noticeMsgTime, 0);\r
-printf("PicoMCD: %x\n", PicoMCD);\r
+\r
        // load SRAM for this ROM\r
        if(currentConfig.EmuOpt & 1)\r
                emu_SaveLoadGame(1, 1);\r
@@ -452,8 +453,8 @@ int emu_ReadConfig(int game)
                // set default config\r
                memset(&currentConfig, 0, sizeof(currentConfig));\r
                currentConfig.lastRomFile[0] = 0;\r
-               currentConfig.EmuOpt  = 0x1f | 0xc00; // | cd_leds | cd_cdda\r
-               currentConfig.PicoOpt = 0x0f | 0x200; // | use_940\r
+               currentConfig.EmuOpt  = 0x1f | 0x400; // | cd_leds\r
+               currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940 | cd_pcm | cd_cdda\r
                currentConfig.PsndRate = 44100;\r
                currentConfig.PicoRegion = 0; // auto\r
                currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
@@ -599,20 +600,20 @@ static void cd_leds(void)
                // 8-bit modes\r
                unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
                unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
-               *(unsigned int *)((char *)gp2x_screen + 320*2+306) =\r
-               *(unsigned int *)((char *)gp2x_screen + 320*3+306) =\r
-               *(unsigned int *)((char *)gp2x_screen + 320*4+306) = col_g;\r
-               *(unsigned int *)((char *)gp2x_screen + 320*2+312) =\r
-               *(unsigned int *)((char *)gp2x_screen + 320*3+312) =\r
-               *(unsigned int *)((char *)gp2x_screen + 320*4+312) = col_r;\r
+               *(unsigned int *)((char *)gp2x_screen + 320*2+ 4) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*3+ 4) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*4+ 4) = col_g;\r
+               *(unsigned int *)((char *)gp2x_screen + 320*2+12) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*3+12) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*4+12) = col_r;\r
        } else {\r
                // 16-bit modes\r
-               unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+306);\r
+               unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+4);\r
                unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
                unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
-               *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
-               *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
-               *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2;\r
+               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2;\r
+               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2;\r
        }\r
 }\r
 \r
index e5a7f30..674929b 100644 (file)
@@ -19,8 +19,8 @@ typedef struct {
        char lastRomFile[512];\r
        int EmuOpt;             // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,\r
                                        // squidgehack, save_cfg_on_exit, <unused>, 16_bit_mode\r
-                                       // craigix_ram, confirm_save, show_cd_leds, enable_cdda\r
-                                       // enable_pcm\r
+                                       // craigix_ram, confirm_save, show_cd_leds\r
+                                       //\r
        int PicoOpt;  // used for config saving only, see Pico.h\r
        int PsndRate; // ditto\r
        int PicoRegion; // ditto\r
index 16c9ab5..2433742 100644 (file)
@@ -574,7 +574,8 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j
        gp2x_text_out8(tl_x, (y+=10), "EUR BIOS:     %s", b_eu); // 1\r
        gp2x_text_out8(tl_x, (y+=10), "JAP BIOS:     %s", b_jp); // 2\r
        gp2x_text_out8(tl_x, (y+=10), "CD LEDs                    %s", (currentConfig.EmuOpt &0x400)?"ON":"OFF"); // 3\r
-       gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s)    %s", (currentConfig.EmuOpt &0x800)?"ON":"OFF"); // 4\r
+       gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s)    %s", (currentConfig.PicoOpt&0x800)?"ON":"OFF"); // 4\r
+       gp2x_text_out8(tl_x, (y+=10), "PCM audio                  %s", (currentConfig.PicoOpt&0x400)?"ON":"OFF"); // 5\r
        gp2x_text_out8(tl_x, (y+=10), "Done");\r
 \r
        // draw cursor\r
@@ -590,7 +591,7 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j
 \r
 static void cd_menu_loop_options(void)\r
 {\r
-       int menu_sel = 0, menu_sel_max = 5;\r
+       int menu_sel = 0, menu_sel_max = 6;\r
        unsigned long inp = 0;\r
        char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;\r
 \r
@@ -618,8 +619,9 @@ static void cd_menu_loop_options(void)
                if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
                        switch (menu_sel) {\r
                                case  3: currentConfig.EmuOpt ^=0x400; break;\r
-                               case  4: currentConfig.EmuOpt ^=0x800; break;\r
-                               case  5: return;\r
+                               case  4: currentConfig.PicoOpt^=0x800; break;\r
+                               case  5: currentConfig.PicoOpt^=0x400; break;\r
+                               case  6: return;\r
                        }\r
                }\r
                if(inp & (GP2X_X|GP2X_A)) return;\r
index 2cfa57b..915ac0a 100644 (file)
@@ -20,8 +20,6 @@
 static YM2612 ym2612;
 
 YM2612 *ym2612_940 = &ym2612;
-int  mix_buffer_[44100/50*2];  /* this is where the YM2612 samples will be mixed to */
-int *mix_buffer = mix_buffer_;
 
 // static _940_data_t  shared_data_;
 static _940_ctl_t   shared_ctl_;
@@ -96,58 +94,6 @@ void YM2612ResetChip_940(void)
 }
 
 
-static void mix_samples(short *dest_buf, int *ym_buf, short *mp3_buf, int len, int stereo)
-{
-       if (mp3_buf)
-       {
-               if (stereo)
-               {
-                       for (; len > 0; len--)
-                       {
-                               int l, r;
-                               l = r = *dest_buf;
-                               l += *ym_buf++;  r += *ym_buf++;
-                               l += *mp3_buf++; r += *mp3_buf++;
-                               Limit( l, MAXOUT, MINOUT );
-                               Limit( r, MAXOUT, MINOUT );
-                               *dest_buf++ = l; *dest_buf++ = r;
-                       }
-               } else {
-                       for (; len > 0; len--)
-                       {
-                               int l = *ym_buf++;
-                               l += *dest_buf;
-                               l += *mp3_buf++;
-                               Limit( l, MAXOUT, MINOUT );
-                               *dest_buf++ = l;
-                       }
-               }
-       }
-       else
-       {
-               if (stereo)
-               {
-                       for (; len > 0; len--)
-                       {
-                               int l, r;
-                               l = r = *dest_buf;
-                               l += *ym_buf++, r += *ym_buf++;
-                               Limit( l, MAXOUT, MINOUT );
-                               Limit( r, MAXOUT, MINOUT );
-                               *dest_buf++ = l; *dest_buf++ = r;
-                       }
-               } else {
-                       for (; len > 0; len--)
-                       {
-                               int l = *ym_buf++;
-                               l += *dest_buf;
-                               Limit( l, MAXOUT, MINOUT );
-                               *dest_buf++ = l;
-                       }
-               }
-       }
-}
-
 #if 0
 static void local_decode(void)
 {
@@ -190,7 +136,7 @@ static void local_decode(void)
 
 static FILE *loaded_mp3 = 0;
 
-void YM2612UpdateOne_940(short *buffer, int length, int stereo)
+int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
 {
 #if 0
        int cdda_on, *ym_buffer = mix_buffer;
@@ -233,9 +179,7 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo)
                mp3_samples_ready += 1152;
        }
 #else
-       YM2612UpdateOne_(buffer, length, stereo); // really writes to mix_buffer
-
-       mix_samples(buffer, mix_buffer, 0, length, stereo);
+       return YM2612UpdateOne_(buffer, length, stereo, is_buf_empty);
 #endif
 }
 
index e8d740e..b5f7133 100644 (file)
@@ -31,9 +31,9 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory
 # Pico - CD
 OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \
                ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \
-               ../../Pico/cd/Area.o ../../Pico/cd/Misc.o
+               ../../Pico/cd/Area.o ../../Pico/cd/Misc.o ../../Pico/cd/pcm.o
 # Pico - sound
-OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o
+OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o ../../Pico/sound/mix.o
 # zlib
 OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \
        ../../zlib/deflate.o ../../zlib/crc32.o ../../zlib/adler32.o ../../zlib/zutil.o ../../zlib/compress.o