Mercurial > audlegacy-plugins
annotate src/console/Snes_Spc.cxx @ 3148:d443c917dab9
Remove stale library variable from Makefile, as pointed out by RafaŠČ MuŤ÷yŠČo on #audacious.
author | Tony Vroon <chainsaw@gentoo.org> |
---|---|
date | Mon, 11 May 2009 17:32:04 +0100 |
parents | c31e94fefd2a |
children |
rev | line source |
---|---|
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
1 // SPC emulation support: init, sample buffering, reset, SPC loading |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
2 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
3 // snes_spc 0.9.0. http://www.slack.net/~ant/ |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
4 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
5 #include "Snes_Spc.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
6 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
7 #include <string.h> |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
8 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
9 /* Copyright (C) 2004-2007 Shay Green. This module is free software; you |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
10 can redistribute it and/or modify it under the terms of the GNU Lesser |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
11 General Public License as published by the Free Software Foundation; either |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
12 version 2.1 of the License, or (at your option) any later version. This |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
13 module is distributed in the hope that it will be useful, but WITHOUT ANY |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
16 details. You should have received a copy of the GNU Lesser General Public |
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
17 License along with this module; if not, write to the Free Software Foundation, |
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
19 |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
20 #include "blargg_source.h" |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
21 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
22 #define RAM (m.ram.ram) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
23 #define REGS (m.smp_regs [0]) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
24 #define REGS_IN (m.smp_regs [1]) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
25 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
26 // (n ? n : 256) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
27 #define IF_0_THEN_256( n ) ((uint8_t) ((n) - 1) + 1) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
28 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
29 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
30 //// Init |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
31 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
32 blargg_err_t Snes_Spc::init() |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
33 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
34 memset( &m, 0, sizeof m ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
35 dsp.init( RAM ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
36 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
37 m.tempo = tempo_unit; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
38 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
39 // Most SPC music doesn't need ROM, and almost all the rest only rely |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
40 // on these two bytes |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
41 m.rom [0x3E] = 0xFF; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
42 m.rom [0x3F] = 0xC0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
43 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
44 static unsigned char const cycle_table [128] = |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
45 {// 01 23 45 67 89 AB CD EF |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
46 0x28,0x47,0x34,0x36,0x26,0x54,0x54,0x68, // 0 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
47 0x48,0x47,0x45,0x56,0x55,0x65,0x22,0x46, // 1 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
48 0x28,0x47,0x34,0x36,0x26,0x54,0x54,0x74, // 2 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
49 0x48,0x47,0x45,0x56,0x55,0x65,0x22,0x38, // 3 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
50 0x28,0x47,0x34,0x36,0x26,0x44,0x54,0x66, // 4 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
51 0x48,0x47,0x45,0x56,0x55,0x45,0x22,0x43, // 5 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
52 0x28,0x47,0x34,0x36,0x26,0x44,0x54,0x75, // 6 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
53 0x48,0x47,0x45,0x56,0x55,0x55,0x22,0x36, // 7 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
54 0x28,0x47,0x34,0x36,0x26,0x54,0x52,0x45, // 8 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
55 0x48,0x47,0x45,0x56,0x55,0x55,0x22,0xC5, // 9 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
56 0x38,0x47,0x34,0x36,0x26,0x44,0x52,0x44, // A |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
57 0x48,0x47,0x45,0x56,0x55,0x55,0x22,0x34, // B |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
58 0x38,0x47,0x45,0x47,0x25,0x64,0x52,0x49, // C |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
59 0x48,0x47,0x56,0x67,0x45,0x55,0x22,0x83, // D |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
60 0x28,0x47,0x34,0x36,0x24,0x53,0x43,0x40, // E |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
61 0x48,0x47,0x45,0x56,0x34,0x54,0x22,0x60, // F |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
62 }; |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
63 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
64 // unpack cycle table |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
65 for ( int i = 0; i < 128; i++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
66 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
67 int n = cycle_table [i]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
68 m.cycle_table [i * 2 + 0] = n >> 4; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
69 m.cycle_table [i * 2 + 1] = n & 0x0F; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
70 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
71 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
72 #if SPC_LESS_ACCURATE |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
73 memcpy( reg_times, reg_times_, sizeof reg_times ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
74 #endif |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
75 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
76 reset(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
77 return 0; |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
78 } |
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
79 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
80 void Snes_Spc::init_rom( uint8_t const in [rom_size] ) |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
81 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
82 memcpy( m.rom, in, sizeof m.rom ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
83 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
84 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
85 void Snes_Spc::set_tempo( int t ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
86 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
87 m.tempo = t; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
88 int const timer2_shift = 4; // 64 kHz |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
89 int const other_shift = 3; // 8 kHz |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
90 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
91 #if SPC_DISABLE_TEMPO |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
92 m.timers [2].prescaler = timer2_shift; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
93 m.timers [1].prescaler = timer2_shift + other_shift; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
94 m.timers [0].prescaler = timer2_shift + other_shift; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
95 #else |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
96 if ( !t ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
97 t = 1; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
98 int const timer2_rate = 1 << timer2_shift; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
99 int rate = (timer2_rate * tempo_unit + (t >> 1)) / t; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
100 if ( rate < timer2_rate / 4 ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
101 rate = timer2_rate / 4; // max 4x tempo |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
102 m.timers [2].prescaler = rate; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
103 m.timers [1].prescaler = rate << other_shift; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
104 m.timers [0].prescaler = rate << other_shift; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
105 #endif |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
106 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
107 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
108 // Timer registers have been loaded. Applies these to the timers. Does not |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
109 // reset timer prescalers or dividers. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
110 void Snes_Spc::timers_loaded() |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
111 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
112 int i; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
113 for ( i = 0; i < timer_count; i++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
114 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
115 Timer* t = &m.timers [i]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
116 t->period = IF_0_THEN_256( REGS [r_t0target + i] ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
117 t->enabled = REGS [r_control] >> i & 1; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
118 t->counter = REGS_IN [r_t0out + i] & 0x0F; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
119 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
120 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
121 set_tempo( m.tempo ); |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
122 } |
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
123 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
124 // Loads registers from unified 16-byte format |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
125 void Snes_Spc::load_regs( uint8_t const in [reg_count] ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
126 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
127 memcpy( REGS, in, reg_count ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
128 memcpy( REGS_IN, REGS, reg_count ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
129 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
130 // These always read back as 0 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
131 REGS_IN [r_test ] = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
132 REGS_IN [r_control ] = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
133 REGS_IN [r_t0target] = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
134 REGS_IN [r_t1target] = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
135 REGS_IN [r_t2target] = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
136 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
137 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
138 // RAM was just loaded from SPC, with $F0-$FF containing SMP registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
139 // and timer counts. Copies these to proper registers. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
140 void Snes_Spc::ram_loaded() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
141 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
142 m.rom_enabled = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
143 load_regs( &RAM [0xF0] ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
144 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
145 // Put STOP instruction around memory to catch PC underflow/overflow |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
146 memset( m.ram.padding1, cpu_pad_fill, sizeof m.ram.padding1 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
147 memset( m.ram.padding2, cpu_pad_fill, sizeof m.ram.padding2 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
148 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
149 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
150 // Registers were just loaded. Applies these new values. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
151 void Snes_Spc::regs_loaded() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
152 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
153 enable_rom( REGS [r_control] & 0x80 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
154 timers_loaded(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
155 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
156 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
157 void Snes_Spc::reset_time_regs() |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
158 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
159 m.cpu_error = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
160 m.echo_accessed = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
161 m.spc_time = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
162 m.dsp_time = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
163 #if SPC_LESS_ACCURATE |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
164 m.dsp_time = clocks_per_sample + 1; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
165 #endif |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
166 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
167 for ( int i = 0; i < timer_count; i++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
168 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
169 Timer* t = &m.timers [i]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
170 t->next_time = 1; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
171 t->divider = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
172 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
173 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
174 regs_loaded(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
175 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
176 m.extra_clocks = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
177 reset_buf(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
178 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
179 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
180 void Snes_Spc::reset_common( int timer_counter_init ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
181 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
182 int i; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
183 for ( i = 0; i < timer_count; i++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
184 REGS_IN [r_t0out + i] = timer_counter_init; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
185 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
186 // Run IPL ROM |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
187 memset( &m.cpu_regs, 0, sizeof m.cpu_regs ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
188 m.cpu_regs.pc = rom_addr; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
189 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
190 REGS [r_test ] = 0x0A; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
191 REGS [r_control] = 0xB0; // ROM enabled, clear ports |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
192 for ( i = 0; i < port_count; i++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
193 REGS_IN [r_cpuio0 + i] = 0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
194 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
195 reset_time_regs(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
196 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
197 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
198 void Snes_Spc::soft_reset() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
199 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
200 reset_common( 0 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
201 dsp.soft_reset(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
202 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
203 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
204 void Snes_Spc::reset() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
205 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
206 memset( RAM, 0xFF, 0x10000 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
207 ram_loaded(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
208 reset_common( 0x0F ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
209 dsp.reset(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
210 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
211 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
212 char const Snes_Spc::signature [signature_size + 1] = |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
213 "SNES-SPC700 Sound File Data v0.30\x1A\x1A"; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
214 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
215 blargg_err_t Snes_Spc::load_spc( void const* data, long size ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
216 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
217 spc_file_t const* const spc = (spc_file_t const*) data; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
218 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
219 // be sure compiler didn't insert any padding into fle_t |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
220 assert( sizeof (spc_file_t) == spc_min_file_size + 0x80 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
221 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
222 // Check signature and file size |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
223 if ( size < signature_size || memcmp( spc, signature, 27 ) ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
224 return "Not an SPC file"; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
225 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
226 if ( size < spc_min_file_size ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
227 return "Corrupt SPC file"; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
228 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
229 // CPU registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
230 m.cpu_regs.pc = spc->pch * 0x100 + spc->pcl; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
231 m.cpu_regs.a = spc->a; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
232 m.cpu_regs.x = spc->x; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
233 m.cpu_regs.y = spc->y; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
234 m.cpu_regs.psw = spc->psw; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
235 m.cpu_regs.sp = spc->sp; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
236 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
237 // RAM and registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
238 memcpy( RAM, spc->ram, 0x10000 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
239 ram_loaded(); |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
240 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
241 // DSP registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
242 dsp.load( spc->dsp ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
243 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
244 reset_time_regs(); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
245 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
246 return 0; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
247 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
248 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
249 void Snes_Spc::clear_echo() |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
250 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
251 if ( !(dsp.read( Spc_Dsp::r_flg ) & 0x20) ) |
316
fb513e10174e
[svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents:
12
diff
changeset
|
252 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
253 int addr = 0x100 * dsp.read( Spc_Dsp::r_esa ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
254 int end = addr + 0x800 * (dsp.read( Spc_Dsp::r_edl ) & 0x0F); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
255 if ( end > 0x10000 ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
256 end = 0x10000; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
257 memset( &RAM [addr], 0xFF, end - addr ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
258 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
259 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
260 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
261 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
262 //// Sample output |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
263 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
264 void Snes_Spc::reset_buf() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
265 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
266 // Start with half extra buffer of silence |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
267 sample_t* out = m.extra_buf; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
268 while ( out < &m.extra_buf [extra_size / 2] ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
269 *out++ = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
270 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
271 m.extra_pos = out; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
272 m.buf_begin = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
273 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
274 dsp.set_output( 0, 0 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
275 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
276 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
277 void Snes_Spc::set_output( sample_t* out, int size ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
278 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
279 require( (size & 1) == 0 ); // size must be even |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
280 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
281 m.extra_clocks &= clocks_per_sample - 1; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
282 if ( out ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
283 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
284 sample_t const* out_end = out + size; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
285 m.buf_begin = out; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
286 m.buf_end = out_end; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
287 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
288 // Copy extra to output |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
289 sample_t const* in = m.extra_buf; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
290 while ( in < m.extra_pos && out < out_end ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
291 *out++ = *in++; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
292 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
293 // Handle output being full already |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
294 if ( out >= out_end ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
295 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
296 // Have DSP write to remaining extra space |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
297 out = dsp.extra(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
298 out_end = &dsp.extra() [extra_size]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
299 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
300 // Copy any remaining extra samples as if DSP wrote them |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
301 while ( in < m.extra_pos ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
302 *out++ = *in++; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
303 assert( out <= out_end ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
304 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
305 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
306 dsp.set_output( out, out_end - out ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
307 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
308 else |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
309 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
310 reset_buf(); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
311 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
312 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
313 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
314 void Snes_Spc::save_extra() |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
315 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
316 // Get end pointers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
317 sample_t const* main_end = m.buf_end; // end of data written to buf |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
318 sample_t const* dsp_end = dsp.out_pos(); // end of data written to dsp.extra() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
319 if ( m.buf_begin <= dsp_end && dsp_end <= main_end ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
320 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
321 main_end = dsp_end; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
322 dsp_end = dsp.extra(); // nothing in DSP's extra |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
323 } |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
324 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
325 // Copy any extra samples at these ends into extra_buf |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
326 sample_t* out = m.extra_buf; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
327 sample_t const* in; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
328 for ( in = m.buf_begin + sample_count(); in < main_end; in++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
329 *out++ = *in; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
330 for ( in = dsp.extra(); in < dsp_end ; in++ ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
331 *out++ = *in; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
332 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
333 m.extra_pos = out; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
334 assert( out <= &m.extra_buf [extra_size] ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
335 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
336 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
337 blargg_err_t Snes_Spc::play( int count, sample_t* out ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
338 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
339 require( (count & 1) == 0 ); // must be even |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
340 if ( count ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
341 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
342 set_output( out, count ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
343 end_frame( count * (clocks_per_sample / 2) ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
344 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
345 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
346 const char* err = m.cpu_error; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
347 m.cpu_error = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
348 return err; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
349 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
350 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
351 blargg_err_t Snes_Spc::skip( int count ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
352 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
353 #if SPC_LESS_ACCURATE |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
354 if ( count > 2 * sample_rate * 2 ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
355 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
356 set_output( 0, 0 ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
357 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
358 // Skip a multiple of 4 samples |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
359 time_t end = count; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
360 count = (count & 3) + 1 * sample_rate * 2; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
361 end = (end - count) * (clocks_per_sample / 2); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
362 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
363 m.skipped_kon = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
364 m.skipped_koff = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
365 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
366 // Preserve DSP and timer synchronization |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
367 // TODO: verify that this really preserves it |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
368 int old_dsp_time = m.dsp_time + m.spc_time; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
369 m.dsp_time = end - m.spc_time + skipping_time; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
370 end_frame( end ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
371 m.dsp_time = m.dsp_time - skipping_time + old_dsp_time; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
372 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
373 dsp.write( Spc_Dsp::r_koff, m.skipped_koff & ~m.skipped_kon ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
374 dsp.write( Spc_Dsp::r_kon , m.skipped_kon ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
375 clear_echo(); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
376 } |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
377 #endif |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
378 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
379 return play( count, 0 ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
380 } |