#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
return 0;\r
}\r
\r
+static int g_busy = 10;\r
\r
static void wait_busy_940(void)\r
{\r
}\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
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
\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
{\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
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
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
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
}\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
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
//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
\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
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