1 #include "940shared.h"
\r
3 static _940_data_t *shared_data = (_940_data_t *) 0x00100000;
\r
4 static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x00200000;
\r
5 static unsigned char *mp3_data = (unsigned char *) 0x01000000;
\r
9 int wait_get_job(int oldjob);
\r
10 void spend_cycles(int c);
\r
11 void dcache_clean(void);
\r
12 void dcache_clean_flush(void);
\r
13 void drain_wb(void);
\r
14 // this should help to resolve race confition where shared var
\r
15 // is changed by other core just before we update it
\r
16 void set_if_not_changed(int *val, int oldval, int newval);
\r
18 // asm volatile ("mov r0, #0" ::: "r0");
\r
19 // asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */
\r
20 // asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */
\r
23 static void mp3_decode(void)
\r
25 int mp3_offs = shared_ctl->mp3_offs;
\r
26 unsigned char *readPtr = mp3_data + mp3_offs;
\r
27 int bytesLeft = shared_ctl->mp3_len - mp3_offs;
\r
28 int offset; // frame offset from readPtr
\r
31 if (bytesLeft <= 0) return; // EOF, nothing to do
\r
33 offset = MP3FindSyncWord(readPtr, bytesLeft);
\r
35 set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
\r
39 bytesLeft -= offset;
\r
41 err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,
\r
42 shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);
\r
44 if (err == ERR_MP3_INDATA_UNDERFLOW) {
\r
45 set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
\r
47 } else if (err <= -6 && err >= -12) {
\r
48 // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*
\r
49 // just try to skip the offending frame..
\r
52 shared_ctl->mp3_errors++;
\r
53 shared_ctl->mp3_lasterr = err;
\r
55 set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data);
\r
61 int *ym_buffer = shared_data->ym_buffer;
\r
63 ym2612_940 = &shared_data->ym2612;
\r
68 job = wait_get_job(job);
\r
70 shared_ctl->lastjob = job;
\r
74 case JOB940_INITALL:
\r
76 shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff;
\r
77 YM2612Init_(shared_ctl->baseclock, shared_ctl->rate);
\r
78 /* Helix mp3 decoder */
\r
79 shared_data->mp3dec = MP3InitDecoder();
\r
82 case JOB940_INVALIDATE_DCACHE:
\r
84 dcache_clean_flush();
\r
87 case JOB940_YM2612RESETCHIP:
\r
91 case JOB940_PICOSTATELOAD:
\r
92 YM2612PicoStateLoad_();
\r
95 case JOB940_YM2612UPDATEONE: {
\r
97 if (shared_ctl->writebuffsel == 1) {
\r
98 wbuff = (int *) shared_ctl->writebuff1;
\r
100 wbuff = (int *) shared_ctl->writebuff0;
\r
103 /* playback all writes */
\r
104 for (i = 2048/2; i > 0; i--) {
\r
108 if (d == 0xffff) break;
\r
109 YM2612Write_(d >> 8, d);
\r
111 if (d == 0xffff) break;
\r
112 YM2612Write_(d >> 8, d);
\r
115 shared_ctl->ym_active_chs =
\r
116 YM2612UpdateOne_(ym_buffer, shared_ctl->length, shared_ctl->stereo, 1);
\r
120 case JOB940_MP3DECODE:
\r
125 shared_ctl->loopc++;
\r