Mercurial > audlegacy-plugins
annotate src/console/Spc_Dsp.h @ 2363:5eb15f6cf71e
Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Tue, 05 Feb 2008 09:14:14 +0300 |
parents | c31e94fefd2a |
children |
rev | line source |
---|---|
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
1 // Fast SNES SPC-700 DSP emulator (about 3x speed of accurate one) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
2 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
3 // snes_spc 0.9.0 |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
4 #ifndef SPC_DSP_H |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
5 #define SPC_DSP_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 "blargg_common.h" |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
8 |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
9 class Spc_Dsp { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
10 public: |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
11 typedef BOOST::uint8_t uint8_t; |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
12 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
13 // Setup |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
14 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
15 // Initializes DSP and has it use the 64K RAM provided |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
16 void init( void* ram_64k ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
17 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
18 // Sets destination for output samples. If out is NULL or out_size is 0, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
19 // doesn't generate any. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
20 typedef short sample_t; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
21 void set_output( sample_t* out, int out_size ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
22 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
23 // Number of samples written to output since it was last set, always |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
24 // a multiple of 2. Undefined if more samples were generated than |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
25 // output buffer could hold. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
26 int sample_count() const; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
27 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
28 // Emulation |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
29 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
30 // Resets DSP to power-on state |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
31 void reset(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
32 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
33 // Emulates pressing reset switch on SNES |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
34 void soft_reset(); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
35 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
36 // Reads/writes DSP registers. For accuracy, you must first call spc_run_dsp() |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
37 // to catch the DSP up to present. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
38 int read ( int addr ) const; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
39 void write( int addr, int data ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
40 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
41 // Runs DSP for specified number of clocks (~1024000 per second). Every 32 clocks |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
42 // a pair of samples is be generated. |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
43 void run( int clock_count ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
44 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
45 // Sound control |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
46 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
47 // Mutes voices corresponding to non-zero bits in mask (overrides VxVOL with 0). |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
48 // Reduces emulation accuracy. |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
49 enum { voice_count = 8 }; |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
50 void mute_voices( int mask ); |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
51 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
52 // If true, prevents channels and global volumes from being phase-negated |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
53 void disable_surround( bool disable = true ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
54 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
55 enum { gain_unit = 0x100 }; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
56 void set_gain( int gain ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
57 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
58 // State |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
59 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
60 // Resets DSP and uses supplied values to initialize registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
61 enum { register_count = 128 }; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
62 void load( uint8_t const regs [register_count] ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
63 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
64 // DSP register addresses |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
65 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
66 // Global registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
67 enum { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
68 r_mvoll = 0x0C, r_mvolr = 0x1C, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
69 r_evoll = 0x2C, r_evolr = 0x3C, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
70 r_kon = 0x4C, r_koff = 0x5C, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
71 r_flg = 0x6C, r_endx = 0x7C, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
72 r_efb = 0x0D, r_pmon = 0x2D, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
73 r_non = 0x3D, r_eon = 0x4D, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
74 r_dir = 0x5D, r_esa = 0x6D, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
75 r_edl = 0x7D, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
76 r_fir = 0x0F // 8 coefficients at 0x0F, 0x1F ... 0x7F |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
77 }; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
78 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
79 // Voice registers |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
80 enum { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
81 v_voll = 0x00, v_volr = 0x01, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
82 v_pitchl = 0x02, v_pitchh = 0x03, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
83 v_srcn = 0x04, v_adsr0 = 0x05, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
84 v_adsr1 = 0x06, v_gain = 0x07, |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
85 v_envx = 0x08, v_outx = 0x09 |
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 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
88 public: |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
89 enum { extra_size = 16 }; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
90 sample_t* extra() { return m.extra; } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
91 sample_t const* out_pos() const { return m.out; } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
92 public: |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
93 BLARGG_DISABLE_NOTHROW |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
94 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
95 typedef BOOST::int8_t int8_t; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
96 typedef BOOST::int16_t int16_t; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
97 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
98 enum { echo_hist_size = 8 }; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
99 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
100 enum env_mode_t { env_release, env_attack, env_decay, env_sustain }; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
101 enum { brr_buf_size = 12 }; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
102 struct voice_t |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
103 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
104 int buf [brr_buf_size*2];// decoded samples (twice the size to simplify wrap handling) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
105 int* buf_pos; // place in buffer where next samples will be decoded |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
106 int interp_pos; // relative fractional position in sample (0x1000 = 1.0) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
107 int brr_addr; // address of current BRR block |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
108 int brr_offset; // current decoding offset in BRR block |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
109 int kon_delay; // KON delay/current setup phase |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
110 env_mode_t env_mode; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
111 int env; // current envelope level |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
112 int hidden_env; // used by GAIN mode 7, very obscure quirk |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
113 int volume [2]; // copy of volume from DSP registers, with surround disabled |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
114 int enabled; // -1 if enabled, 0 if muted |
341 | 115 }; |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
116 private: |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
117 struct state_t |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
118 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
119 uint8_t regs [register_count]; |
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 // Echo history keeps most recent 8 samples (twice the size to simplify wrap handling) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
122 int echo_hist [echo_hist_size * 2] [2]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
123 int (*echo_hist_pos) [2]; // &echo_hist [0 to 7] |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
124 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
125 int every_other_sample; // toggles every sample |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
126 int kon; // KON value when last checked |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
127 int noise; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
128 int echo_offset; // offset from ESA in echo buffer |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
129 int echo_length; // number of bytes that echo_offset will stop at |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
130 int phase; // next clock cycle to run (0-31) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
131 unsigned counters [4]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
132 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
133 int new_kon; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
134 int t_koff; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
135 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
136 voice_t voices [voice_count]; |
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 unsigned* counter_select [32]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
139 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
140 // non-emulation state |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
141 uint8_t* ram; // 64K shared RAM between DSP and SMP |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
142 int mute_mask; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
143 int gain; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
144 int surround_threshold; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
145 sample_t* out; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
146 sample_t* out_end; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
147 sample_t* out_begin; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
148 sample_t extra [extra_size]; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
149 }; |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
150 state_t m; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
151 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
152 void init_counter(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
153 void run_counter( int ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
154 void soft_reset_common(); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
155 void write_outline( int addr, int data ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
156 void update_voice_vol( int addr ); |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
157 }; |
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 #include <assert.h> |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
160 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
161 inline int Spc_Dsp::sample_count() const { return m.out - m.out_begin; } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
162 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
163 inline int Spc_Dsp::read( int addr ) const |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
164 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
165 assert( (unsigned) addr < register_count ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
166 return m.regs [addr]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
167 } |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
168 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
169 inline void Spc_Dsp::update_voice_vol( int addr ) |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
170 { |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
171 int l = (int8_t) m.regs [addr + v_voll]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
172 int r = (int8_t) m.regs [addr + v_volr]; |
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 if ( l * r < m.surround_threshold ) |
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 // signs differ, so negate those that are negative |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
177 l ^= l >> 7; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
178 r ^= r >> 7; |
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 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
181 voice_t& v = m.voices [addr >> 4]; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
182 int enabled = v.enabled; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
183 v.volume [0] = l & enabled; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
184 v.volume [1] = r & enabled; |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
185 } |
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
186 |
1037
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
187 inline void Spc_Dsp::write( int addr, int data ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
188 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
189 assert( (unsigned) addr < register_count ); |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
190 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
191 m.regs [addr] = (uint8_t) data; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
192 int low = addr & 0x0F; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
193 if ( low < 0x2 ) // voice volumes |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
194 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
195 update_voice_vol( low ^ addr ); |
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 else if ( low == 0xC ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
198 { |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
199 if ( addr == r_kon ) |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
200 m.new_kon = (uint8_t) data; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
201 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
202 if ( addr == r_endx ) // always cleared, regardless of data written |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
203 m.regs [r_endx] = 0; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
204 } |
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 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
207 inline void Spc_Dsp::set_gain( int gain ) { m.gain = gain; } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
208 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
209 inline void Spc_Dsp::disable_surround( bool disable ) |
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 m.surround_threshold = disable ? 0 : -0x4000; |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
212 } |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
213 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
214 #define SPC_NO_COPY_STATE_FUNCS 1 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
215 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
216 #define SPC_LESS_ACCURATE 1 |
c31e94fefd2a
[svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents:
341
diff
changeset
|
217 |
0
13389e613d67
[svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff
changeset
|
218 #endif |