1 // The top-level functions for the ARM940
\r
2 // (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas
\r
4 #include "940shared.h"
\r
6 static _940_data_t *shared_data = (_940_data_t *) 0x00100000;
\r
7 static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x00200000;
\r
8 static unsigned char *mp3_data = (unsigned char *) 0x00400000;
\r
12 int wait_get_job(int oldjob);
\r
13 void spend_cycles(int c);
\r
14 void dcache_clean(void);
\r
15 void dcache_clean_flush(void);
\r
16 void drain_wb(void);
\r
17 // this should help to resolve race confition where shared var
\r
18 // is changed by other core just before we update it
\r
19 void set_if_not_changed(int *val, int oldval, int newval);
\r
21 // asm volatile ("mov r0, #0" ::: "r0");
\r
22 // asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */
\r
23 // asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */
\r
26 static void mp3_decode(void)
\r
28 int mp3_offs = shared_ctl->mp3_offs;
\r
29 unsigned char *readPtr = mp3_data + mp3_offs;
\r
30 int bytesLeft = shared_ctl->mp3_len - mp3_offs;
\r
31 int offset; // frame offset from readPtr
\r
34 if (bytesLeft <= 0) return; // EOF, nothing to do
\r
36 offset = MP3FindSyncWord(readPtr, bytesLeft);
\r
38 set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
\r
42 bytesLeft -= offset;
\r
44 err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,
\r
45 shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);
\r
47 if (err == ERR_MP3_INDATA_UNDERFLOW) {
\r
48 set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
\r
50 } else if (err <= -6 && err >= -12) {
\r
51 // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*
\r
52 // just try to skip the offending frame..
\r
55 shared_ctl->mp3_errors++;
\r
56 shared_ctl->mp3_lasterr = err;
\r
58 set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data);
\r
61 static void ym_update(int *ym_buffer)
\r
67 if (shared_ctl->writebuffsel == 1) {
\r
68 wbuff = shared_ctl->writebuff1;
\r
70 wbuff = shared_ctl->writebuff0;
\r
73 /* playback all writes */
\r
74 for (i = 2048/2; i > 0; i--) {
\r
79 if (d == 0xffff) break;
\r
80 if (d == 0xfffe) { two_upds=1; break; }
\r
81 YM2612Write_(d >> 8, d);
\r
84 if (d == 0xffff) break;
\r
85 if (d == 0xfffe) { two_upds=1; break; }
\r
86 YM2612Write_(d >> 8, d);
\r
90 int len1 = shared_ctl->length / 2;
\r
91 shared_ctl->ym_active_chs =
\r
92 YM2612UpdateOne_(ym_buffer, len1, shared_ctl->stereo, 1);
\r
94 for (i *= 2; i > 0; i--) {
\r
95 UINT16 d = *wbuff++;
\r
96 if (d == 0xffff) break;
\r
97 YM2612Write_(d >> 8, d);
\r
100 ym_buffer += shared_ctl->stereo ? len1*2 : len1;
\r
101 len1 = shared_ctl->length - len1;
\r
103 shared_ctl->ym_active_chs =
\r
104 YM2612UpdateOne_(ym_buffer, len1, shared_ctl->stereo, 1);
\r
106 shared_ctl->ym_active_chs =
\r
107 YM2612UpdateOne_(ym_buffer, shared_ctl->length, shared_ctl->stereo, 1);
\r
114 int *ym_buffer = shared_data->ym_buffer;
\r
116 ym2612_940 = &shared_data->ym2612;
\r
121 job = wait_get_job(job);
\r
123 shared_ctl->lastjob = job;
\r
127 case JOB940_INITALL:
\r
129 shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff;
\r
130 YM2612Init_(shared_ctl->baseclock, shared_ctl->rate);
\r
131 /* Helix mp3 decoder */
\r
132 shared_data->mp3dec = MP3InitDecoder();
\r
135 case JOB940_INVALIDATE_DCACHE:
\r
137 dcache_clean_flush();
\r
140 case JOB940_YM2612RESETCHIP:
\r
141 YM2612ResetChip_();
\r
144 case JOB940_PICOSTATELOAD:
\r
145 YM2612PicoStateLoad_();
\r
148 case JOB940_YM2612UPDATEONE:
\r
149 ym_update(ym_buffer);
\r
152 case JOB940_MP3DECODE:
\r
157 shared_ctl->loopc++;
\r