annotate src/console/Snes_Spc.h @ 3203:f5456241bff9 default tip

changed include path from audacious to audlegacy.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 10 Nov 2009 05:19:25 +0900
parents c31e94fefd2a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
1 // SNES SPC-700 APU emulator
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 SNES_SPC_H
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 #define 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 "Spc_Dsp.h"
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
8 #include "blargg_endian.h"
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
10 struct Snes_Spc {
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 public:
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
12 typedef BOOST::uint8_t uint8_t;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
13
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
14 // Must be called once before using
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
15 blargg_err_t init();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
17 // Sample pairs generated per second
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
18 enum { sample_rate = 32000 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
19
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
20 // Emulator use
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
21
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
22 // Sets IPL ROM data. Library does not include ROM data. Most SPC music files
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
23 // don't need ROM, but a full emulator must provide this.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
24 enum { rom_size = 0x40 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
25 void init_rom( uint8_t const rom [rom_size] );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
26
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
27 // Sets destination for output samples
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
28 typedef short sample_t;
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
29 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
30
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
31 // Number of samples written to output since last set
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
32 int sample_count() const;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
33
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
34 // Resets SPC to power-on state. This resets your output buffer, so you must
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
35 // call set_output() after this.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
36 void reset();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
37
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
38 // Emulates pressing reset switch on SNES. This resets your output buffer, so
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
39 // you must call set_output() after this.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
40 void soft_reset();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
41
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
42 // 1024000 SPC clocks per second, sample pair every 32 clocks
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
43 typedef int time_t;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
44 enum { clock_rate = 1024000 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
45 enum { clocks_per_sample = 32 };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
46
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
47 // Emulated port read/write at specified time
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
48 enum { port_count = 4 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
49 int read_port ( time_t, int port );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
50 void write_port( time_t, int port, int data );
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 // Runs SPC to end_time and starts a new time frame at 0
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
53 void end_frame( time_t end_time );
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 // Sound control
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
56
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
57 // Mutes voices corresponding to non-zero bits in mask (issues repeated KOFF events).
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
58 // Reduces emulation accuracy.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
59 enum { voice_count = 8 };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 void mute_voices( int mask );
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
62 // 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
63 // Only supported by fast DSP.
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
64 void disable_surround( bool disable = true );
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
65
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
66 // Sets tempo, where tempo_unit = normal, tempo_unit / 2 = half speed, etc.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
67 enum { tempo_unit = 0x100 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
68 void set_tempo( int );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
69
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
70 enum { gain_unit = Spc_Dsp::gain_unit };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
71 void set_gain( int gain );
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
72
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
73 // SPC music files
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
74
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
75 // Loads SPC data into emulator
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
76 enum { spc_min_file_size = 0x10180 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
77 enum { spc_file_size = 0x10200 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
78 blargg_err_t load_spc( void const* in, long size );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
79
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
80 // Clears echo region. Useful after loading an SPC as many have garbage in echo.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
81 void clear_echo();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
82
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
83 // Plays for count samples and write samples to out. Discards samples if out
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
84 // is NULL. Count must be a multiple of 2 since output is stereo.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
85 blargg_err_t play( int count, sample_t* out );
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 // Skips count samples. Several times faster than play() when using fast DSP.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
88 blargg_err_t skip( int count );
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
89
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
90 // State save/load (only available with accurate DSP)
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
91
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
92 #if !SPC_NO_COPY_STATE_FUNCS
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
93 // Saves/loads state
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
94 enum { state_size = 67 * 1024L }; // maximum space needed when saving
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
95 typedef Spc_Dsp::copy_func_t copy_func_t;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
96 void copy_state( unsigned char** io, copy_func_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 // Writes minimal header to spc_out
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
99 static void init_header( void* spc_out );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
100
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
101 // Saves emulator state as SPC file data. Writes spc_file_size bytes to spc_out.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
102 // Does not set up SPC header; use init_header() for that.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
103 void save_spc( void* spc_out );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
104
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
105 // Returns true if new key-on events occurred since last check. Useful for
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
106 // trimming silence while saving an SPC.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
107 bool check_kon();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
108 #endif
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
109
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
110 public:
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
111 BLARGG_DISABLE_NOTHROW
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
112
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
113 typedef BOOST::uint16_t uint16_t;
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 // Time relative to m_spc_time. Speeds up code a bit by eliminating need to
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
116 // constantly add m_spc_time to time from CPU. CPU uses time that ends at
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
117 // 0 to eliminate reloading end time every instruction. It pays off.
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
118 typedef int rel_time_t;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
119
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
120 struct Timer
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
121 {
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
122 rel_time_t next_time; // time of next event
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
123 int prescaler;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
124 int period;
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
125 int divider;
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
126 int enabled;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
127 int counter;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
128 };
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
129 enum { reg_count = 0x10 };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
130 enum { timer_count = 3 };
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
131 enum { extra_size = Spc_Dsp::extra_size };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
132
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
133 enum { signature_size = 35 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
134
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
135 private:
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
136 Spc_Dsp dsp;
1037
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 #if SPC_LESS_ACCURATE
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
139 static signed char const reg_times_ [256];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
140 signed char reg_times [256];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
141 #endif
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
142
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
143 struct state_t
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 Timer timers [timer_count];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
146
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
147 uint8_t smp_regs [2] [reg_count];
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 struct
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
150 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
151 int pc;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
152 int a;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
153 int x;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
154 int y;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
155 int psw;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
156 int sp;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
157 } cpu_regs;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
158
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
159 rel_time_t dsp_time;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
160 time_t spc_time;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
161 bool echo_accessed;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
162
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
163 int tempo;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
164 int skipped_kon;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
165 int skipped_koff;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
166 const char* cpu_error;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
167
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
168 int extra_clocks;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
169 sample_t* buf_begin;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
170 sample_t const* buf_end;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
171 sample_t* extra_pos;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
172 sample_t extra_buf [extra_size];
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 int rom_enabled;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
175 uint8_t rom [rom_size];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
176 uint8_t hi_ram [rom_size];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
177
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
178 unsigned char cycle_table [256];
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 struct
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 // padding to neutralize address overflow
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
183 union {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
184 uint8_t padding1 [0x100];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
185 uint16_t align; // makes compiler align data for 16-bit access
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
186 } padding1 [1];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
187 uint8_t ram [0x10000];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
188 uint8_t padding2 [0x100];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
189 } ram;
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 state_t m;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
192
316
fb513e10174e [svn] - merge libconsole-blargg into mainline libconsole:
nenolod
parents: 12
diff changeset
193 enum { rom_addr = 0xFFC0 };
1037
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 enum { skipping_time = 127 };
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 // Value that padding should be filled with
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
198 enum { cpu_pad_fill = 0xFF };
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 enum {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
201 r_test = 0x0, r_control = 0x1,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
202 r_dspaddr = 0x2, r_dspdata = 0x3,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
203 r_cpuio0 = 0x4, r_cpuio1 = 0x5,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
204 r_cpuio2 = 0x6, r_cpuio3 = 0x7,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
205 r_f8 = 0x8, r_f9 = 0x9,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
206 r_t0target = 0xA, r_t1target = 0xB, r_t2target = 0xC,
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
207 r_t0out = 0xD, r_t1out = 0xE, r_t2out = 0xF
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
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
210 void timers_loaded();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
211 void enable_rom( int enable );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
212 void reset_buf();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
213 void save_extra();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
214 void load_regs( uint8_t const in [reg_count] );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
215 void ram_loaded();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
216 void regs_loaded();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
217 void reset_time_regs();
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
218 void reset_common( int timer_counter_init );
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
219
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
220 Timer* run_timer_ ( Timer* t, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
221 Timer* run_timer ( Timer* t, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
222 int dsp_read ( rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
223 void dsp_write ( int data, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
224 void cpu_write_smp_reg_( int data, rel_time_t, int addr );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
225 void cpu_write_smp_reg ( int data, rel_time_t, int addr );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
226 void cpu_write_high ( int data, int i, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
227 void cpu_write ( int data, int addr, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
228 int cpu_read_smp_reg ( int i, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
229 int cpu_read ( int addr, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
230 unsigned CPU_mem_bit ( uint8_t const* pc, rel_time_t );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
231
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
232 bool check_echo_access ( int addr );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
233 uint8_t* run_until_( time_t end_time );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
234
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
235 struct spc_file_t
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
236 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
237 char signature [signature_size];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
238 uint8_t has_id666;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
239 uint8_t version;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
240 uint8_t pcl, pch;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
241 uint8_t a;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
242 uint8_t x;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
243 uint8_t y;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
244 uint8_t psw;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
245 uint8_t sp;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
246 char text [212];
341
986f098da058 [svn] - merge in blargg's changes
nenolod
parents: 316
diff changeset
247 uint8_t ram [0x10000];
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
248 uint8_t dsp [128];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
249 uint8_t unused [0x40];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
250 uint8_t ipl_rom [0x40];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
251 };
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
252
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
253 static char const signature [signature_size + 1];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
254
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
255 void save_regs( uint8_t out [reg_count] );
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
258 #include <assert.h>
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
259
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
260 inline int Snes_Spc::sample_count() const { return (m.extra_clocks >> 5) * 2; }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
261
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
262 inline int Snes_Spc::read_port( time_t t, int port )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
263 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
264 assert( (unsigned) port < port_count );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
265 return run_until_( t ) [port];
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
266 }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
267
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
268 inline void Snes_Spc::write_port( time_t t, int port, int data )
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
269 {
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
270 assert( (unsigned) port < port_count );
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
271 run_until_( t ) [0x10 + port] = data;
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
272 }
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 inline void Snes_Spc::set_gain( int gain ) { dsp.set_gain( gain ); }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
275
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
276 inline void Snes_Spc::mute_voices( int mask ) { dsp.mute_voices( mask ); }
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
277
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
278 inline void Snes_Spc::disable_surround( bool disable ) { dsp.disable_surround( disable ); }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279
1037
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
280 #if !SPC_NO_COPY_STATE_FUNCS
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
281 inline bool Snes_Spc::check_kon() { return dsp.check_kon(); }
c31e94fefd2a [svn] - upstream updates regarding handling of SPC700 instructions and runtime
nenolod
parents: 341
diff changeset
282 #endif
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
283
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
284 #endif