1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
Index: apps/codecs/libcook/cook.h
===================================================================
--- apps/codecs/libcook/cook.h  (revision 29879)
+++ apps/codecs/libcook/cook.h  (working copy)
@@ -86,13 +86,13 @@

     /* data buffers */

-    uint8_t             decoded_bytes_buffer[1024];
-    REAL_T mono_mdct_output[2048] __attribute__ ((aligned(16)));
-    REAL_T              mono_previous_buffer1[1024];
-    REAL_T              mono_previous_buffer2[1024];
-    REAL_T              decode_buffer_1[1024];
-    REAL_T              decode_buffer_2[1024];
-    REAL_T              decode_buffer_0[1060]; /* static allocation for joint decode */
+    uint8_t             decoded_bytes_buffer[1024] MEM_ALIGN_ATTR;
+    REAL_T              mono_mdct_output[2048] MEM_ALIGN_ATTR;
+    REAL_T              mono_previous_buffer1[1024] MEM_ALIGN_ATTR;
+    REAL_T              mono_previous_buffer2[1024] MEM_ALIGN_ATTR;
+    REAL_T              decode_buffer_1[1024] MEM_ALIGN_ATTR;
+    REAL_T              decode_buffer_2[1024] MEM_ALIGN_ATTR;
+    REAL_T              decode_buffer_0[1060] MEM_ALIGN_ATTR; /* static allocation for joint decode */
 } COOKContext;

 int cook_decode_init(RMContext *rmctx, COOKContext *q);
Index: apps/codecs/libcook/cookdata_fixpoint.h
===================================================================
--- apps/codecs/libcook/cookdata_fixpoint.h  (revision 29879)
+++ apps/codecs/libcook/cookdata_fixpoint.h  (working copy)
@@ -39,7 +39,7 @@
 typedef struct {
 } realvars_t;

-static const FIXPU pow128_tab[128] = {
+static const FIXPU pow128_tab[128] ICONST_ATTR = {
     /* x_i = 2^(15+i/128) */
     0x8000, 0x80b2, 0x8165, 0x8219, 0x82ce, 0x8383, 0x843a, 0x84f2, 0x85ab,
     0x8665, 0x871f, 0x87db, 0x8898, 0x8956, 0x8a15, 0x8ad5, 0x8b96, 0x8c58,
@@ -131,27 +131,27 @@
     0x00000000, 0x00000000
 }}};

-static const FIXPU cplscale2[3] = {
+static const FIXPU cplscale2[3] ICONST_ATTR = {
     /* 2^16 C_ij */
     0xf3f9, 0xb505, 0x4d8b
 };
-static const FIXPU cplscale3[7] = {
+static const FIXPU cplscale3[7] ICONST_ATTR = {
     /* 2^16 C_ij */
     0xfb35, 0xefdf, 0xe03d, 0xb505, 0x7b81, 0x596e, 0x314d
 };
-static const FIXPU cplscale4[15] = {
+static const FIXPU cplscale4[15] ICONST_ATTR = {
     /* 2^16 C_ij */
     0xfdd2, 0xf927, 0xf3f9, 0xee1d, 0xe749, 0xdee9, 0xd381, 0xb505, 0x903b,
     0x7de2, 0x6dbe, 0x5e02, 0x4d8b, 0x3ad1, 0x2155
 };
-static const FIXPU cplscale5[31] = {
+static const FIXPU cplscale5[31] ICONST_ATTR = {
     /* 2^16 C_ij */
     0xfef5, 0xfcce, 0xfa8e, 0xf832, 0xf5b5, 0xf314, 0xf049, 0xed4c, 0xea12,
     0xe68e, 0xe2ab, 0xde4b, 0xd938, 0xd30b, 0xcab6, 0xb505, 0x9c59, 0x90e8,
     0x8778, 0x7ef9, 0x76fc, 0x6f45, 0x67ab, 0x600e, 0x5850, 0x504d, 0x47db,
     0x3ebd, 0x3486, 0x2853, 0x1715
 };
-static const FIXPU cplscale6[63] = {
+static const FIXPU cplscale6[63] ICONST_ATTR = {
     /* 2^16 C_ij */
     0xff7d, 0xfe74, 0xfd65, 0xfc50, 0xfb35, 0xfa14, 0xf8eb, 0xf7bb, 0xf683,
     0xf543, 0xf3f9, 0xf2a6, 0xf148, 0xefdf, 0xee6a, 0xece6, 0xeb54, 0xe9b2,
Index: apps/codecs/asap.c
===================================================================
--- apps/codecs/asap.c  (revision 29879)
+++ apps/codecs/asap.c  (working copy)
@@ -27,7 +27,7 @@
 #define CHUNK_SIZE (1024*2)

 static byte samples[CHUNK_SIZE] IBSS_ATTR;   /* The sample buffer */
-static ASAP_State asap;         /* asap codec state */
+static ASAP_State asap IBSS_ATTR;         /* asap codec state */

 /* this is the codec entry point */
 enum codec_status codec_main(enum codec_entry_call_reason reason)
@@ -76,7 +76,7 @@
     /* Sample depth is 16 bit little endian */
     ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
     /* Stereo or Mono output ? */
-    if(asap.module_info.channels ==1)
+    if(asap.module_info->channels ==1)
     {
         ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
         bytesPerSample = 2;
@@ -89,8 +89,8 @@
     /* reset eleapsed */
     ci->set_elapsed(0);

-    song = asap.module_info.default_song;
-    duration = asap.module_info.durations[song];
+    song = asap.module_info->default_song;
+    duration = asap.module_info->durations[song];
     if (duration < 0)
         duration = 180 * 1000;

Index: apps/codecs/nsf.c
===================================================================
--- apps/codecs/nsf.c  (revision 29879)
+++ apps/codecs/nsf.c  (working copy)
@@ -29,20 +29,35 @@

 CODEC_HEADER

-/* arm doesn't benefit from IRAM? */
-#ifdef CPU_ARM
-#undef ICODE_ATTR
-#define ICODE_ATTR
-#undef IDATA_ATTR
-#define IDATA_ATTR
+#if   (CONFIG_CPU == MCF5250)
+#define ICODE_INSTEAD_OF_INLINE
+/* Enough IRAM but performance suffers with ICODE_ATTR. */
+#define IBSS_ATTR_NSF_LARGE_IRAM    IBSS_ATTR
+#define ICONST_ATTR_NSF_LARGE_IRAM  ICONST_ATTR
+
+#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
+#define ICODE_INSTEAD_OF_INLINE
+/* Enough IRAM to move additional data and code to it. */
+#define IBSS_ATTR_NSF_LARGE_IRAM    IBSS_ATTR
+#define ICONST_ATTR_NSF_LARGE_IRAM  ICONST_ATTR
+
+#elif defined(CPU_S5L870X)
+#define ICODE_INSTEAD_OF_INLINE
+/* Very large IRAM. Move even more data to it. */
+#define IBSS_ATTR_NSF_LARGE_IRAM    IBSS_ATTR
+#define ICONST_ATTR_NSF_LARGE_IRAM  ICONST_ATTR
+
 #else
 #define ICODE_INSTEAD_OF_INLINE
+/* Not enough IRAM available. */
+#define IBSS_ATTR_NSF_LARGE_IRAM
+#define ICONST_ATTR_NSF_LARGE_IRAM
 #endif

 /* Maximum number of bytes to process in one iteration */
 #define WAV_CHUNK_SIZE (1024*2)

-static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR;
+static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR MEM_ALIGN_ATTR;

 #define ZEROMEMORY(addr,size) memset(addr,0,size)

@@ -172,7 +187,7 @@

 /****************** tables */
 static const int32_t ModulationTable[8] ICONST_ATTR = {0,1,2,4,0,-4,-2,-1};
-const uint16_t  DMC_FREQ_TABLE[2][0x10] = {
+const uint16_t  DMC_FREQ_TABLE[2][0x10] ICONST_ATTR_NSF_LARGE_IRAM = {
     /* NTSC */
     {0x1AC,0x17C,0x154,0x140,0x11E,0x0FE,0x0E2,0x0D6,0x0BE,0x0A0,0x08E,0x080,
     0x06A,0x054,0x048,0x036},
@@ -181,15 +196,15 @@
     0x062,0x04E,0x042,0x032}
 };

-const uint8_t DUTY_CYCLE_TABLE[4] = {2,4,8,12};
+const uint8_t DUTY_CYCLE_TABLE[4] ICONST_ATTR_NSF_LARGE_IRAM = {2,4,8,12};

-const uint8_t LENGTH_COUNTER_TABLE[0x20] = {
+const uint8_t LENGTH_COUNTER_TABLE[0x20] ICONST_ATTR_NSF_LARGE_IRAM = {
     0x0A,0xFE,0x14,0x02,0x28,0x04,0x50,0x06,0xA0,0x08,0x3C,0x0A,0x0E,0x0C,0x1A,
     0x0E,0x0C,0x10,0x18,0x12,0x30,0x14,0x60,0x16,0xC0,0x18,0x48,0x1A,0x10,0x1C,
     0x20,0x1E
 };

-const uint16_t NOISE_FREQ_TABLE[0x10] = {
+const uint16_t NOISE_FREQ_TABLE[0x10] ICONST_ATTR_NSF_LARGE_IRAM = {
     0x004,0x008,0x010,0x020,0x040,0x060,0x080,0x0A0,0x0CA,0x0FE,0x17C,0x1FC,
     0x2FA,0x3F8,0x7F2,0xFE4
 };
@@ -589,7 +604,7 @@
     int32_t     nPopCount;

 };
-int16_t     FDS_nOutputTable_L[4][0x21][0x40];
+int16_t     FDS_nOutputTable_L[4][0x21][0x40] IBSS_ATTR_NSF_LARGE_IRAM MEM_ALIGN_ATTR;

 struct FME07Wave
 {
@@ -610,7 +625,7 @@
     int32_t     nMixL;
 };

-int16_t     FME07_nOutputTable_L[0x10] IDATA_ATTR;
+int16_t     FME07_nOutputTable_L[0x10] IDATA_ATTR MEM_ALIGN_ATTR;

 struct N106Wave
 {
@@ -650,7 +665,7 @@
     int32_t     nMixL[8];
 };

-int16_t     N106_nOutputTable_L[0x10][0x10];
+int16_t     N106_nOutputTable_L[0x10][0x10] IBSS_ATTR_NSF_LARGE_IRAM MEM_ALIGN_ATTR;

 struct VRC6PulseWave
 {
@@ -675,7 +690,7 @@

 };

-int16_t     VRC6Pulse_nOutputTable_L[0x10] IDATA_ATTR;
+int16_t     VRC6Pulse_nOutputTable_L[0x10] IDATA_ATTR MEM_ALIGN_ATTR;

 struct VRC6SawWave
 {
@@ -697,7 +712,7 @@

 };

-int16_t     VRC6Saw_nOutputTable_L[0x20] IDATA_ATTR;
+int16_t     VRC6Saw_nOutputTable_L[0x20] IDATA_ATTR MEM_ALIGN_ATTR;

 struct Wave_Squares
 {
@@ -735,7 +750,7 @@
     int32_t         nMixL;
 };

-int16_t     Squares_nOutputTable_L[0x10][0x10] IDATA_ATTR;
+int16_t     Squares_nOutputTable_L[0x10][0x10] IDATA_ATTR MEM_ALIGN_ATTR;

 struct Wave_TND
 {
@@ -1161,16 +1176,16 @@
  *  Memory
  */
 /* RAM:      0x0000 - 0x07FF */
-uint8_t     pRAM[0x800] IDATA_ATTR;
+uint8_t     pRAM[0x800] IBSS_ATTR_NSF_LARGE_IRAM MEM_ALIGN_ATTR;
 /* SRAM:     0x6000 - 0x7FFF (non-FDS only) */
-uint8_t     pSRAM[0x2000];
+uint8_t     pSRAM[0x2000] IBSS_ATTR_NSF_LARGE_IRAM MEM_ALIGN_ATTR;
 /* ExRAM:    0x5C00 - 0x5FF5 (MMC5 only)
  * Also holds NSF player code (at 0x5000 - 0x500F) */
-uint8_t     pExRAM[0x1000];
+uint8_t     pExRAM[0x1000] IBSS_ATTR_NSF_LARGE_IRAM MEM_ALIGN_ATTR;
 /* Full ROM buffer */
 uint8_t*    pROM_Full IDATA_ATTR;

-uint16_t    main_nOutputTable_L[0x8000];
+uint16_t    main_nOutputTable_L[0x8000] MEM_ALIGN_ATTR;

 uint8_t*    pROM[10] IDATA_ATTR;/* ROM banks (point to areas in pROM_Full) */
                                 /* 0x8000 - 0xFFFF */
@@ -1188,8 +1203,8 @@

 typedef uint8_t ( *ReadProc)(uint16_t);
 typedef void ( *WriteProc)(uint16_t,uint8_t);
-ReadProc    ReadMemory[0x10] IDATA_ATTR;
-WriteProc   WriteMemory[0x10] IDATA_ATTR;
+ReadProc    ReadMemory[0x10] IDATA_ATTR MEM_ALIGN_ATTR;
+WriteProc   WriteMemory[0x10] IDATA_ATTR MEM_ALIGN_ATTR;

 /*
  *  6502 Registers / Mode
@@ -3541,7 +3556,7 @@
 /*  Lookup Tables */

 /* the number of CPU cycles used for each instruction */
-static const uint8_t CPU_Cycles[0x100] = {
+static const uint8_t CPU_Cycles[0x100] ICONST_ATTR_NSF_LARGE_IRAM = {
 7,6,0,8,3,3,5,5,3,2,2,2,4,4,6,6,
 2,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7,
 6,6,0,8,3,3,5,5,4,2,2,2,4,4,6,6,
@@ -3560,7 +3575,7 @@
 2,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7     };

 /* the status of the NZ flags for the given value */
-static const uint8_t NZTable[0x100] = {
+static const uint8_t NZTable[0x100] ICONST_ATTR_NSF_LARGE_IRAM = {
 Z_FLAG,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
Index: apps/codecs/libasap/asap.c
===================================================================
--- apps/codecs/libasap/asap.c  (revision 29879)
+++ apps/codecs/libasap/asap.c  (working copy)
@@ -23,6 +23,9 @@

 #include "asap_internal.h"

+static byte s_memory[65536];
+static ASAP_ModuleInfo s_module_info;
+
 #ifdef ASAP_ONLY_INFO

 #define GET_PLAYER(name)  NULL
@@ -35,7 +38,7 @@
 {
     switch (addr & 0xff1f) {
     case 0xd014:
-        return ast _ module_info.ntsc ? 0xf : 1;
+        return ast _ module_info->ntsc ? 0xf : 1;
     case 0xd20a:
     case 0xd21a:
         return PokeySound_GetRandom(ast, addr, ast _ cycle);
@@ -91,7 +94,7 @@
         else
             ast _ cycle = ast _ next_scanline_cycle + 106;
     }
-    else if ((addr & 0xff00) == ast _ module_info.covox_addr) {
+    else if ((addr & 0xff00) == ast _ module_info->covox_addr) {
         V(PokeyState PTR, pst);
         addr &= 3;
         if (addr == 0 || addr == 3)
@@ -1379,8 +1382,11 @@
     P(ASAP_State PTR, ast), P(STRING, filename),
     P(CONST BYTEARRAY, module), P(int, module_len)))
 {
+    /* Set up ast */
+    ast _ memory = s_memory;
+    ast _ module_info = &s_module_info;
     ast _ silence_cycles = 0;
-    return parse_file(ast, ADDRESSOF ast _ module_info, filename, module, module_len);
+    return parse_file(ast, ast _ module_info, filename, module, module_len);
 }

 FUNC(void, ASAP_DetectSilence, (P(ASAP_State PTR, ast), P(int, seconds)))
@@ -1416,7 +1422,7 @@
     ast _ current_duration = duration;
     ast _ blocks_played = 0;
     ast _ silence_cycles_counter = ast _ silence_cycles;
-    ast _ extra_pokey_mask = ast _ module_info.channels > 1 ? 0x10 : 0;
+    ast _ extra_pokey_mask = ast _ module_info->channels > 1 ? 0x10 : 0;
     ast _ consol = 8;
     ast _ covox[0] = CAST(byte) 0x80;
     ast _ covox[1] = CAST(byte) 0x80;
@@ -1433,9 +1439,9 @@
     ast _ timer2_cycle = NEVER;
     ast _ timer4_cycle = NEVER;
     ast _ irqst = 0xff;
-    switch (ast _ module_info.type) {
+    switch (ast _ module_info->type) {
     case ASAP_TYPE_SAP_B:
-        call_6502_init(ast, ast _ module_info.init, song, 0, 0);
+        call_6502_init(ast, ast _ module_info->init, song, 0, 0);
         break;
     case ASAP_TYPE_SAP_C:
 #ifndef ASAP_ONLY_SAP
@@ -1444,8 +1450,8 @@
     case ASAP_TYPE_CMR:
     case ASAP_TYPE_CMS:
 #endif
-        call_6502_init(ast, ast _ module_info.player + 3, 0x70, ast _ module_info.music, ast _ module_info.music >> 8);
-        call_6502_init(ast, ast _ module_info.player + 3, 0x00, song, 0);
+        call_6502_init(ast, ast _ module_info->player + 3, 0x70, ast _ module_info->music, ast _ module_info->music >> 8);
+        call_6502_init(ast, ast _ module_info->player + 3, 0x00, song, 0);
         break;
     case ASAP_TYPE_SAP_D:
     case ASAP_TYPE_SAP_S:
@@ -1453,23 +1459,23 @@
         ast _ cpu_x = 0x00;
         ast _ cpu_y = 0x00;
         ast _ cpu_s = 0xff;
-        ast _ cpu_pc = ast _ module_info.init;
+        ast _ cpu_pc = ast _ module_info->init;
         break;
 #ifndef ASAP_ONLY_SAP
     case ASAP_TYPE_DLT:
-        call_6502_init(ast, ast _ module_info.player + 0x100, 0x00, 0x00, ast _ module_info.song_pos[song]);
+        call_6502_init(ast, ast _ module_info->player + 0x100, 0x00, 0x00, ast _ module_info->song_pos[song]);
         break;
     case ASAP_TYPE_MPT:
-        call_6502_init(ast, ast _ module_info.player, 0x00, ast _ module_info.music >> 8, ast _ module_info.music);
-        call_6502_init(ast, ast _ module_info.player, 0x02, ast _ module_info.song_pos[song], 0);
+        call_6502_init(ast, ast _ module_info->player, 0x00, ast _ module_info->music >> 8, ast _ module_info->music);
+        call_6502_init(ast, ast _ module_info->player, 0x02, ast _ module_info->song_pos[song], 0);
         break;
     case ASAP_TYPE_RMT:
-        call_6502_init(ast, ast _ module_info.player, ast _ module_info.song_pos[song], ast _ module_info.music, ast _ module_info.music >> 8);
+        call_6502_init(ast, ast _ module_info->player, ast _ module_info->song_pos[song], ast _ module_info->music, ast _ module_info->music >> 8);
         break;
     case ASAP_TYPE_TMC:
     case ASAP_TYPE_TM2:
-        call_6502_init(ast, ast _ module_info.player, 0x70, ast _ module_info.music >> 8, ast _ module_info.music);
-        call_6502_init(ast, ast _ module_info.player, 0x00, song, 0);
+        call_6502_init(ast, ast _ module_info->player, 0x70, ast _ module_info->music >> 8, ast _ module_info->music);
+        call_6502_init(ast, ast _ module_info->player, 0x00, song, 0);
         ast _ tmc_per_frame_counter = 1;
         break;
 #endif
@@ -1485,11 +1491,11 @@

 FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
 {
-    V(int, player) = ast _ module_info.player;
+    V(int, player) = ast _ module_info->player;
     PokeySound_StartFrame(ast);
-    switch (ast _ module_info.type) {
+    switch (ast _ module_info->type) {
     case ASAP_TYPE_SAP_B:
-        call_6502(ast, player, ast _ module_info.fastplay);
+        call_6502(ast, player, ast _ module_info->fastplay);
         break;
     case ASAP_TYPE_SAP_C:
 #ifndef ASAP_ONLY_SAP
@@ -1498,7 +1504,7 @@
     case ASAP_TYPE_CMR:
     case ASAP_TYPE_CMS:
 #endif
-        call_6502(ast, player + 6, ast _ module_info.fastplay);
+        call_6502(ast, player + 6, ast _ module_info->fastplay);
         break;
     case ASAP_TYPE_SAP_D:
         if (player >= 0) {
@@ -1525,10 +1531,10 @@
             dPutByte(RETURN_FROM_PLAYER_ADDR + 5, 0x40); /* RTI */
             ast _ cpu_pc = player;
         }
-        Cpu_RunScanlines(ast, ast _ module_info.fastplay);
+        Cpu_RunScanlines(ast, ast _ module_info->fastplay);
         break;
     case ASAP_TYPE_SAP_S:
-        Cpu_RunScanlines(ast, ast _ module_info.fastplay);
+        Cpu_RunScanlines(ast, ast _ module_info->fastplay);
         {
             V(int, i) = dGetByte(0x45) - 1;
             dPutByte(0x45, i);
@@ -1538,28 +1544,28 @@
         break;
 #ifndef ASAP_ONLY_SAP
     case ASAP_TYPE_DLT:
-        call_6502(ast, player + 0x103, ast _ module_info.fastplay);
+        call_6502(ast, player + 0x103, ast _ module_info->fastplay);
         break;
     case ASAP_TYPE_MPT:
     case ASAP_TYPE_RMT:
     case ASAP_TYPE_TM2:
-        call_6502(ast, player + 3, ast _ module_info.fastplay);
+        call_6502(ast, player + 3, ast _ module_info->fastplay);
         break;
     case ASAP_TYPE_TMC:
         if (--ast _ tmc_per_frame_counter <= 0) {
             ast _ tmc_per_frame_counter = ast _ tmc_per_frame;
-            call_6502(ast, player + 3, ast _ module_info.fastplay);
+            call_6502(ast, player + 3, ast _ module_info->fastplay);
         }
         else
-            call_6502(ast, player + 6, ast _ module_info.fastplay);
+            call_6502(ast, player + 6, ast _ module_info->fastplay);
         break;
 #endif
     }
-    PokeySound_EndFrame(ast, ast _ module_info.fastplay * 114);
+    PokeySound_EndFrame(ast, ast _ module_info->fastplay * 114);
     if (ast _ silence_cycles > 0) {
         if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey)
          && PokeySound_IsSilent(ADDRESSOF ast _ extra_pokey)) {
-            ast _ silence_cycles_counter -= ast _ module_info.fastplay * 114;
+            ast _ silence_cycles_counter -= ast _ module_info->fastplay * 114;
             if (ast _ silence_cycles_counter <= 0)
                 return FALSE;
         }
@@ -1606,7 +1612,7 @@
     P(CONST ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(ASAP_SampleFormat, format)))
 {
     V(int, use_16bit) = format != ASAP_FORMAT_U8 ? 1 : 0;
-    V(int, block_size) = ast _ module_info.channels << use_16bit;
+    V(int, block_size) = ast _ module_info->channels << use_16bit;
     V(int, bytes_per_second) = ASAP_SAMPLE_RATE * block_size;
     V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration);
     V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size;
@@ -1629,7 +1635,7 @@
     buffer[19] = 0;
     buffer[20] = 1;
     buffer[21] = 0;
-    buffer[22] = CAST(byte) ast _ module_info.channels;
+    buffer[22] = CAST(byte) ast _ module_info->channels;
     buffer[23] = 0;
     serialize_int(buffer, 24, ASAP_SAMPLE_RATE);
     serialize_int(buffer, 28, bytes_per_second);
@@ -1656,7 +1662,7 @@
 #ifdef ACTIONSCRIPT
     block_shift = 0;
 #else
-    block_shift = (ast _ module_info.channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0);
+    block_shift = (ast _ module_info->channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0);
 #endif
     buffer_blocks = buffer_len >> block_shift;
     if (ast _ current_duration > 0) {
Index: apps/codecs/libasap/asap_internal.h
===================================================================
--- apps/codecs/libasap/asap_internal.h  (revision 29879)
+++ apps/codecs/libasap/asap_internal.h  (working copy)
@@ -109,7 +109,7 @@
 #define PutByte(addr, data)     do { if (((addr) & 0xf900) == 0xd000) ASAP_PutByte(ast, addr, data); else dPutByte(addr, data); } while (FALSE)
 #define RMW_GetByte(dest, addr) do { if (((addr) >> 8) == 0xd2) { dest = ASAP_GetByte(ast, addr); ast _ cycle--; ASAP_PutByte(ast, addr, dest); ast _ cycle++; } else dest = dGetByte(addr); } while (FALSE)

-#define ASAP_MAIN_CLOCK(ast)    ((ast) _ module_info.ntsc ? 1789772 : 1773447)
+#define ASAP_MAIN_CLOCK(ast)    ((ast) _ module_info->ntsc ? 1789772 : 1773447)
 #define CYCLE_TO_SAMPLE(cycle)  TO_INT(((cycle) * ASAP_SAMPLE_RATE + ast _ sample_offset) / ASAP_MAIN_CLOCK(ast))

 #endif /* _ASAP_INTERNAL_H_ */
Index: apps/codecs/libasap/acpu.c
===================================================================
--- apps/codecs/libasap/acpu.c  (revision 29879)
+++ apps/codecs/libasap/acpu.c  (working copy)
@@ -286,7 +286,7 @@
         cycle = ast _ cycle;
         if (cycle >= ast _ nearest_event_cycle) {
             if (cycle >= ast _ next_scanline_cycle) {
-                if (++ast _ scanline_number == (ast _ module_info.ntsc ? 262 : 312))
+                if (++ast _ scanline_number == (ast _ module_info->ntsc ? 262 : 312))
                     ast _ scanline_number = 0;
                 ast _ cycle = cycle += 9;
                 ast _ next_scanline_cycle += 114;
@@ -337,7 +337,7 @@
         case 0xb2:
         case 0xd2:
         case 0xf2:
-            ast _ scanline_number = (ast _ scanline_number + scanlines - 1) % (ast _ module_info.ntsc ? 262 : 312);
+            ast _ scanline_number = (ast _ scanline_number + scanlines - 1) % (ast _ module_info->ntsc ? 262 : 312);
             scanlines = 1;
             ast _ cycle = cycle_limit;
             break;
Index: apps/codecs/libasap/asap.h
===================================================================
--- apps/codecs/libasap/asap.h  (revision 29879)
+++ apps/codecs/libasap/asap.h  (working copy)
@@ -179,7 +179,7 @@
     int samples;
     int iir_acc_left;
     int iir_acc_right;
-    ASAP_ModuleInfo module_info;
+    ASAP_ModuleInfo *module_info;
     int tmc_per_frame;
     int tmc_per_frame_counter;
     int current_song;
@@ -189,7 +189,7 @@
     int silence_cycles_counter;
     byte poly9_lookup[511];
     byte poly17_lookup[16385];
-    byte memory[65536];
+    byte *memory;
 } ASAP_State;

 /* Parses the string in the "mm:ss.xxx" format
Index: apps/codecs/libspc/spc_codec.h
===================================================================
--- apps/codecs/libspc/spc_codec.h  (revision 29879)
+++ apps/codecs/libspc/spc_codec.h  (working copy)
@@ -71,7 +71,7 @@
     #define SPC_NOECHO 0
 #elif defined (CPU_PP) && SPC_DUAL_CORE
     /* Cache BRR waves */
-    #define SPC_BRRCACHE 1 
+    #define SPC_BRRCACHE 1

     /* Disable gaussian interpolation */
     #define SPC_NOINTERP 1
@@ -89,20 +89,33 @@
     #define SPC_NOECHO 1
 #endif

-#ifdef CPU_ARM
+#if   (CONFIG_CPU == MCF5250)
+#define IBSS_ATTR_SPC               IBSS_ATTR
+#define ICODE_ATTR_SPC              ICODE_ATTR
+#define ICONST_ATTR_SPC             ICONST_ATTR
+/* Not enough IRAM available to move further data to it. */
+#define IBSS_ATTR_SPC_LARGE_IRAM

-#if CONFIG_CPU != PP5002
-    #undef  ICODE_ATTR
-    #define ICODE_ATTR
+#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
+#define IBSS_ATTR_SPC               IBSS_ATTR
+#define ICODE_ATTR_SPC              ICODE_ATTR
+#define ICONST_ATTR_SPC             ICONST_ATTR
+/* Not enough IRAM available to move further data to it. */
+#define IBSS_ATTR_SPC_LARGE_IRAM

-    #undef  IDATA_ATTR
-    #define IDATA_ATTR
+#elif defined(CPU_S5L870X)
+#define IBSS_ATTR_SPC               IBSS_ATTR
+#define ICODE_ATTR_SPC              ICODE_ATTR
+#define ICONST_ATTR_SPC             ICONST_ATTR
+/* Very large IRAM. Move even more data to it. */
+#define IBSS_ATTR_SPC_LARGE_IRAM    IBSS_ATTR

-    #undef  ICONST_ATTR
-    #define ICONST_ATTR
-
-    #undef  IBSS_ATTR
-    #define IBSS_ATTR
+#else
+#define IBSS_ATTR_SPC               IBSS_ATTR
+#define ICODE_ATTR_SPC              ICODE_ATTR
+#define ICONST_ATTR_SPC             ICONST_ATTR
+/* Not enough IRAM available to move further data to it. */
+#define IBSS_ATTR_SPC_LARGE_IRAM
 #endif

 #if SPC_DUAL_CORE
@@ -111,7 +124,6 @@
     #undef SHAREDDATA_ATTR
     #define SHAREDDATA_ATTR __attribute__((section(".idata")))
 #endif
-#endif

 /* Samples per channel per iteration */
 #if defined(CPU_PP) && NUM_CORES == 1
@@ -192,7 +204,7 @@
 #define RAM ram.ram
 extern struct cpu_ram_t ram;

-long CPU_run( THIS, long start_time ) ICODE_ATTR;
+long CPU_run( THIS, long start_time ) ICODE_ATTR_SPC;
 void CPU_Init( THIS );

 /* The DSP portion (awe!) */
@@ -375,7 +387,7 @@
 #endif
 };

-void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) ICODE_ATTR;
+void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) ICODE_ATTR_SPC;
 void DSP_reset( struct Spc_Dsp* this );

 static inline void DSP_run( struct Spc_Dsp* this, long count, int32_t* out )
@@ -412,7 +424,7 @@
     int counter;
 };

-void Timer_run_( struct Timer* t, long time ) ICODE_ATTR;
+void Timer_run_( struct Timer* t, long time ) ICODE_ATTR_SPC;

 static inline void Timer_run( struct Timer* t, long time )
 {
@@ -461,7 +473,7 @@
 int SPC_load_spc( THIS, const void* data, long size );

 /**************** DSP interaction ****************/
-void DSP_write( struct Spc_Dsp* this, int i, int data ) ICODE_ATTR;
+void DSP_write( struct Spc_Dsp* this, int i, int data ) ICODE_ATTR_SPC;

 static inline int DSP_read( struct Spc_Dsp* this, int i )
 {
@@ -469,7 +481,7 @@
     return this->r.reg [i];
 }

-void SPC_run_dsp_( THIS, long time ) ICODE_ATTR;
+void SPC_run_dsp_( THIS, long time ) ICODE_ATTR_SPC;

 static inline void SPC_run_dsp( THIS, long time )
 {
@@ -477,10 +489,10 @@
         SPC_run_dsp_( this, time );
 }

-int SPC_read( THIS, unsigned addr, long const time ) ICODE_ATTR;
-void SPC_write( THIS, unsigned addr, int data, long const time ) ICODE_ATTR;
+int SPC_read( THIS, unsigned addr, long const time ) ICODE_ATTR_SPC;
+void SPC_write( THIS, unsigned addr, int data, long const time ) ICODE_ATTR_SPC;

 /**************** Sample generation ****************/
-int SPC_play( THIS, long count, int32_t* out ) ICODE_ATTR;
+int SPC_play( THIS, long count, int32_t* out ) ICODE_ATTR_SPC;

 #endif /* _SPC_CODEC_H_ */
Index: apps/codecs/libspc/spc_dsp.c
===================================================================
--- apps/codecs/libspc/spc_dsp.c  (revision 29879)
+++ apps/codecs/libspc/spc_dsp.c  (working copy)
@@ -28,8 +28,7 @@
 #include "spc_profiler.h"

 #if defined(CPU_COLDFIRE) || defined (CPU_ARM)
-int32_t fir_buf[FIR_BUF_CNT]
-    __attribute__ ((aligned (FIR_BUF_ALIGN*1))) IBSS_ATTR;
+int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC MEM_ALIGN_ATTR;
 #endif
 #if SPC_BRRCACHE
 /* a little extra for samples that go past end */
@@ -80,7 +79,7 @@
 #if SPC_BRRCACHE
 static void decode_brr( struct Spc_Dsp* this, unsigned start_addr,
                         struct voice_t* voice,
-                        struct raw_voice_t const* const raw_voice ) ICODE_ATTR;
+                        struct raw_voice_t const* const raw_voice ) ICODE_ATTR_SPC;
 static void decode_brr( struct Spc_Dsp* this, unsigned start_addr,
                         struct voice_t* voice,
                         struct raw_voice_t const* const raw_voice )
@@ -248,7 +247,7 @@
 static void key_on(struct Spc_Dsp* const this, struct voice_t* const voice,
                    struct src_dir const* const sd,
                    struct raw_voice_t const* const raw_voice,
-                   const int key_on_delay, const int vbit) ICODE_ATTR;
+                   const int key_on_delay, const int vbit) ICODE_ATTR_SPC;
 static void key_on(struct Spc_Dsp* const this, struct voice_t* const voice,
                    struct src_dir const* const sd,
                    struct raw_voice_t const* const raw_voice,
@@ -385,7 +384,7 @@

     /* each rate divides exactly into 0x7800 without remainder */
     int const env_rate_init = 0x7800;
-    static unsigned short const env_rates [0x20] ICONST_ATTR =
+    static unsigned short const env_rates [0x20] ICONST_ATTR_SPC =
     {
         0x0000, 0x000F, 0x0014, 0x0018, 0x001E, 0x0028, 0x0030, 0x003C,
         0x0050, 0x0060, 0x0078, 0x00A0, 0x00C0, 0x00F0, 0x0140, 0x0180,
@@ -767,7 +766,7 @@
         #if !SPC_NOINTERP
             /* Interleved gauss table (to improve cache coherency). */
             /* gauss [i * 2 + j] = normal_gauss [(1 - j) * 256 + i] */
-            static short const gauss [512] =
+            static short const gauss [512] ICONST_ATTR_SPC =
             {
 370,1305, 366,1305, 362,1304, 358,1304, 354,1304, 351,1304, 347,1304, 343,1303,
 339,1303, 336,1303, 332,1302, 328,1302, 325,1301, 321,1300, 318,1300, 314,1299,
Index: apps/codecs/libspc/spc_emu.c
===================================================================
--- apps/codecs/libspc/spc_emu.c  (revision 29879)
+++ apps/codecs/libspc/spc_emu.c  (working copy)
@@ -28,7 +28,7 @@
 /* DSP Based on Brad Martin's OpenSPC DSP emulator */
 /* tag reading from sexyspc by John Brawn (John_Brawn@yahoo.com) and others */

-struct cpu_ram_t ram CACHEALIGN_ATTR;
+struct cpu_ram_t ram IBSS_ATTR_SPC_LARGE_IRAM CACHEALIGN_ATTR;

 /**************** Timers ****************/

Index: apps/codecs/libspc/spc_cpu.c
===================================================================
--- apps/codecs/libspc/spc_cpu.c  (revision 29879)
+++ apps/codecs/libspc/spc_cpu.c  (working copy)
@@ -65,7 +65,7 @@
 #define MEM_BIT() CPU_mem_bit( this, pc, spc_time_ )

 static unsigned CPU_mem_bit( THIS, uint8_t const* pc, long const spc_time_ )
-    ICODE_ATTR;
+    ICODE_ATTR_SPC;

 static unsigned CPU_mem_bit( THIS, uint8_t const* pc, long const spc_time_ )
 {