comparison Plugins/Input/console/Snes_Spc.h @ 493:c04dff121e1d trunk

[svn] hostile merge, phase 2: reimport based on new plugin code
author nenolod
date Tue, 24 Jan 2006 20:19:01 -0800
parents
children
comparison
equal deleted inserted replaced
492:ccb68bad47b2 493:c04dff121e1d
1
2 // Super Nintendo (SNES) SPC-700 APU Emulator
3
4 // Game_Music_Emu 0.3.0
5
6 #ifndef SNES_SPC_H
7 #define SNES_SPC_H
8
9 #include "blargg_common.h"
10 #include "Spc_Cpu.h"
11 #include "Spc_Dsp.h"
12
13 class Snes_Spc {
14 public:
15 typedef BOOST::uint8_t uint8_t;
16
17 Snes_Spc();
18
19 // Load copy of SPC data into emulator. Clear echo buffer if 'clear_echo' is true.
20 enum { spc_file_size = 0x10180 };
21 blargg_err_t load_spc( const void* spc, long spc_size, bool clear_echo = 1 );
22
23 // Load copy of state into emulator.
24 typedef Spc_Cpu::registers_t registers_t;
25 blargg_err_t load_state( const registers_t& cpu_state, const void* ram_64k,
26 const void* dsp_regs_128 );
27
28 // Clear echo buffer
29 void clear_echo();
30
31 // Mute voice n if bit n (1 << n) of mask is set
32 enum { voice_count = Spc_Dsp::voice_count };
33 void mute_voices( int mask );
34
35 // Generate 'count' samples and optionally write to 'buf'. Count must be even.
36 // Sample output is 16-bit 32kHz, signed stereo pairs with the left channel first.
37 typedef short sample_t;
38 blargg_err_t play( long count, sample_t* buf = NULL );
39
40 // Skip forward by the specified number of samples (64000 samples = 1 second)
41 blargg_err_t skip( long count );
42
43 // Set gain, where 1.0 is normal. When greater than 1.0, output is clamped the
44 // 16-bit sample range.
45 void set_gain( double );
46
47 // If true, prevent channels and global volumes from being phase-negated
48 void disable_surround( bool disable );
49
50 // End of public interface
51 private:
52 // timers
53 struct Timer
54 {
55 spc_time_t next_tick;
56 int period;
57 int count;
58 int shift;
59 int counter;
60 int enabled;
61
62 void run_until_( spc_time_t );
63 void run_until( spc_time_t time )
64 {
65 if ( time >= next_tick )
66 run_until_( time );
67 }
68 };
69 enum { timer_count = 3 };
70 Timer timer [timer_count];
71
72 // hardware
73 int extra_cycles;
74 spc_time_t time() const;
75 int read( spc_addr_t );
76 void write( spc_addr_t, int );
77 friend class Spc_Cpu;
78
79 // dsp
80 sample_t* sample_buf;
81 sample_t* buf_end; // to do: remove this once possible bug resolved
82 spc_time_t next_dsp;
83 Spc_Dsp dsp;
84 int keys_pressed;
85 int keys_released;
86 sample_t skip_sentinel [1]; // special value for play() passed by skip()
87 void run_dsp( spc_time_t );
88 void run_dsp_( spc_time_t );
89 bool echo_accessed;
90 void check_for_echo_access( spc_addr_t );
91
92 // boot rom
93 enum { rom_size = 64 };
94 enum { rom_addr = 0xffc0 };
95 bool rom_enabled;
96 uint8_t extra_ram [rom_size];
97 static const uint8_t boot_rom [rom_size];
98 void enable_rom( bool );
99
100 // CPU and RAM (at end because it's large)
101 Spc_Cpu cpu;
102 enum { ram_size = 0x10000 };
103 uint8_t ram [ram_size + 0x100]; // padding for catching jumps past end
104 };
105
106 inline void Snes_Spc::disable_surround( bool disable ) { dsp.disable_surround( disable ); }
107
108 inline void Snes_Spc::mute_voices( int mask ) { dsp.mute_voices( mask ); }
109
110 inline void Snes_Spc::set_gain( double v ) { dsp.set_gain( v ); }
111
112 #endif
113