diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-31 19:19:49 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-31 19:19:49 +0000 |
commit | 13cbade08a07296d92e7a7d3e20475de0032cba1 (patch) | |
tree | 731a1a4a99d86632a719ae49e3b3d2a12e764a3a /apps/codecs/libgme/nsf_emu.h | |
parent | d089e104034fdf5562bea125d2cacf4ee486782a (diff) | |
download | rockbox-13cbade08a07296d92e7a7d3e20475de0032cba1.tar.gz rockbox-13cbade08a07296d92e7a7d3e20475de0032cba1.zip |
Update libgme to Blargg's Game_Music_Emu 0.6-pre.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30397 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libgme/nsf_emu.h')
-rw-r--r-- | apps/codecs/libgme/nsf_emu.h | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/apps/codecs/libgme/nsf_emu.h b/apps/codecs/libgme/nsf_emu.h index dccfa8c5d5..00bdad4a4e 100644 --- a/apps/codecs/libgme/nsf_emu.h +++ b/apps/codecs/libgme/nsf_emu.h | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "nes_cpu.h" | 10 | #include "nes_cpu.h" |
11 | #include "nsfe_info.h" | 11 | #include "nsfe_info.h" |
12 | #include "m3u_playlist.h" | 12 | #include "m3u_playlist.h" |
13 | #include "track_filter.h" | ||
13 | 14 | ||
14 | #ifndef NSF_EMU_APU_ONLY | 15 | #ifndef NSF_EMU_APU_ONLY |
15 | #include "nes_namco_apu.h" | 16 | #include "nes_namco_apu.h" |
@@ -17,11 +18,11 @@ | |||
17 | #include "nes_fme7_apu.h" | 18 | #include "nes_fme7_apu.h" |
18 | #include "nes_fds_apu.h" | 19 | #include "nes_fds_apu.h" |
19 | #include "nes_mmc5_apu.h" | 20 | #include "nes_mmc5_apu.h" |
20 | #include "nes_vrc7_apu.h" | 21 | #ifndef NSF_EMU_NO_VRC7 |
22 | #include "nes_vrc7_apu.h" | ||
23 | #endif | ||
21 | #endif | 24 | #endif |
22 | 25 | ||
23 | typedef short sample_t; | ||
24 | |||
25 | // Sound chip flags | 26 | // Sound chip flags |
26 | enum { | 27 | enum { |
27 | vrc6_flag = 1 << 0, | 28 | vrc6_flag = 1 << 0, |
@@ -50,8 +51,7 @@ enum { fdsram_size = 0x6000 }; | |||
50 | enum { fdsram_offset = 0x2000 + page_size + 8 }; | 51 | enum { fdsram_offset = 0x2000 + page_size + 8 }; |
51 | enum { sram_addr = 0x6000 }; | 52 | enum { sram_addr = 0x6000 }; |
52 | enum { unmapped_size= page_size + 8 }; | 53 | enum { unmapped_size= page_size + 8 }; |
53 | 54 | enum { max_voices = 32 }; | |
54 | enum { buf_size = 2048 }; | ||
55 | 55 | ||
56 | // NSF file header | 56 | // NSF file header |
57 | enum { header_size = 0x80 }; | 57 | enum { header_size = 0x80 }; |
@@ -82,37 +82,21 @@ struct Nsf_Emu { | |||
82 | int play_extra; | 82 | int play_extra; |
83 | int play_delay; | 83 | int play_delay; |
84 | struct registers_t saved_state; // of interrupted init routine | 84 | struct registers_t saved_state; // of interrupted init routine |
85 | |||
86 | int track_count; | ||
87 | 85 | ||
88 | // general | 86 | // general |
89 | int max_initial_silence; | ||
90 | int voice_count; | 87 | int voice_count; |
88 | int voice_types [32]; | ||
91 | int mute_mask_; | 89 | int mute_mask_; |
92 | int tempo; | 90 | int tempo; |
93 | int gain; | 91 | int gain; |
94 | 92 | ||
95 | long sample_rate; | 93 | int sample_rate; |
96 | 94 | ||
97 | // track-specific | 95 | // track-specific |
96 | int track_count; | ||
98 | int current_track; | 97 | int current_track; |
99 | blargg_long out_time; // number of samples played since start of track | ||
100 | blargg_long emu_time; // number of samples emulator has generated since start of track | ||
101 | bool emu_track_ended_; // emulator has reached end of track | ||
102 | volatile bool track_ended; | ||
103 | |||
104 | // fading | ||
105 | blargg_long fade_start; | ||
106 | int fade_step; | ||
107 | 98 | ||
108 | // silence detection | 99 | int clock_rate__; |
109 | int silence_lookahead; // speed to run emulator when looking ahead for silence | ||
110 | bool ignore_silence; | ||
111 | long silence_time; // number of samples where most recent silence began | ||
112 | long silence_count; // number of samples of silence to play before using buf | ||
113 | long buf_remain; // number of samples left in silence buffer | ||
114 | |||
115 | long clock_rate__; | ||
116 | unsigned buf_changed_count; | 100 | unsigned buf_changed_count; |
117 | 101 | ||
118 | // M3u Playlist | 102 | // M3u Playlist |
@@ -127,7 +111,9 @@ struct Nsf_Emu { | |||
127 | struct Nes_Namco_Apu namco; | 111 | struct Nes_Namco_Apu namco; |
128 | struct Nes_Vrc6_Apu vrc6; | 112 | struct Nes_Vrc6_Apu vrc6; |
129 | struct Nes_Fme7_Apu fme7; | 113 | struct Nes_Fme7_Apu fme7; |
130 | struct Nes_Vrc7_Apu vrc7; | 114 | #ifndef NSF_EMU_NO_VRC7 |
115 | struct Nes_Vrc7_Apu vrc7; | ||
116 | #endif | ||
131 | #endif | 117 | #endif |
132 | 118 | ||
133 | struct Nes_Cpu cpu; | 119 | struct Nes_Cpu cpu; |
@@ -136,13 +122,15 @@ struct Nsf_Emu { | |||
136 | // Header for currently loaded file | 122 | // Header for currently loaded file |
137 | struct header_t header; | 123 | struct header_t header; |
138 | 124 | ||
139 | struct Stereo_Buffer stereo_buf; | 125 | struct setup_t tfilter; |
126 | struct Track_Filter track_filter; | ||
127 | |||
128 | struct Multi_Buffer stereo_buf; | ||
140 | struct Rom_Data rom; | 129 | struct Rom_Data rom; |
141 | 130 | ||
142 | // Extended nsf info | 131 | // Extended nsf info |
143 | struct Nsfe_Info info; | 132 | struct Nsfe_Info info; |
144 | 133 | ||
145 | sample_t buf [buf_size]; | ||
146 | byte high_ram[fdsram_size + fdsram_offset]; | 134 | byte high_ram[fdsram_size + fdsram_offset]; |
147 | byte low_ram [low_ram_size]; | 135 | byte low_ram [low_ram_size]; |
148 | }; | 136 | }; |
@@ -150,18 +138,18 @@ struct Nsf_Emu { | |||
150 | // Basic functionality (see Gme_File.h for file loading/track info functions) | 138 | // Basic functionality (see Gme_File.h for file loading/track info functions) |
151 | 139 | ||
152 | void Nsf_init( struct Nsf_Emu* this ); | 140 | void Nsf_init( struct Nsf_Emu* this ); |
153 | blargg_err_t Nsf_load( struct Nsf_Emu* this, void* data, long size ); | 141 | blargg_err_t Nsf_load_mem( struct Nsf_Emu* this, void* data, long size ); |
154 | blargg_err_t Nsf_post_load( struct Nsf_Emu* this ); | 142 | blargg_err_t Nsf_post_load( struct Nsf_Emu* this ); |
155 | 143 | ||
156 | // Set output sample rate. Must be called only once before loading file. | 144 | // Set output sample rate. Must be called only once before loading file. |
157 | blargg_err_t Nsf_set_sample_rate( struct Nsf_Emu* this, long sample_rate ); | 145 | blargg_err_t Nsf_set_sample_rate( struct Nsf_Emu* this, int sample_rate ); |
158 | 146 | ||
159 | // Start a track, where 0 is the first track. Also clears warning string. | 147 | // Start a track, where 0 is the first track. Also clears warning string. |
160 | blargg_err_t Nsf_start_track( struct Nsf_Emu* this , int ); | 148 | blargg_err_t Nsf_start_track( struct Nsf_Emu* this , int ); |
161 | 149 | ||
162 | // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation | 150 | // Generate 'count' samples info 'buf'. Output is in stereo. Any emulation |
163 | // errors set warning string, and major errors also end track. | 151 | // errors set warning string, and major errors also end track. |
164 | blargg_err_t Nsf_play( struct Nsf_Emu* this, long count, sample_t* buf ); | 152 | blargg_err_t Nsf_play( struct Nsf_Emu* this, int count, sample_t* buf ); |
165 | 153 | ||
166 | void Nsf_clear_playlist( struct Nsf_Emu* this ); | 154 | void Nsf_clear_playlist( struct Nsf_Emu* this ); |
167 | void Nsf_disable_playlist( struct Nsf_Emu* this, bool b ); // use clear_playlist() | 155 | void Nsf_disable_playlist( struct Nsf_Emu* this, bool b ); // use clear_playlist() |
@@ -169,20 +157,32 @@ void Nsf_disable_playlist( struct Nsf_Emu* this, bool b ); // use clear_playlist | |||
169 | // Track status/control | 157 | // Track status/control |
170 | 158 | ||
171 | // Number of milliseconds (1000 msec = 1 second) played since beginning of track | 159 | // Number of milliseconds (1000 msec = 1 second) played since beginning of track |
172 | long Track_tell( struct Nsf_Emu* this ); | 160 | int Track_tell( struct Nsf_Emu* this ); |
173 | 161 | ||
174 | // Seek to new time in track. Seeking backwards or far forward can take a while. | 162 | // Seek to new time in track. Seeking backwards or far forward can take a while. |
175 | blargg_err_t Track_seek( struct Nsf_Emu* this, long msec ); | 163 | blargg_err_t Track_seek( struct Nsf_Emu* this, int msec ); |
176 | 164 | ||
177 | // Skip n samples | 165 | // Skip n samples |
178 | blargg_err_t Track_skip( struct Nsf_Emu* this, long n ); | 166 | blargg_err_t Track_skip( struct Nsf_Emu* this, int n ); |
179 | 167 | ||
180 | // Set start time and length of track fade out. Once fade ends track_ended() returns | 168 | // Set start time and length of track fade out. Once fade ends track_ended() returns |
181 | // true. Fade time can be changed while track is playing. | 169 | // true. Fade time can be changed while track is playing. |
182 | void Track_set_fade( struct Nsf_Emu* this, long start_msec, long length_msec ); | 170 | void Track_set_fade( struct Nsf_Emu* this, int start_msec, int length_msec ); |
171 | |||
172 | // True if a track has reached its end | ||
173 | static inline bool Track_ended( struct Nsf_Emu* this ) | ||
174 | { | ||
175 | return track_ended( &this->track_filter ); | ||
176 | } | ||
177 | |||
178 | // Disables automatic end-of-track detection and skipping of silence at beginning | ||
179 | static inline void Track_ignore_silence( struct Nsf_Emu* this, bool disable ) | ||
180 | { | ||
181 | this->track_filter.silence_ignored_ = disable; | ||
182 | } | ||
183 | 183 | ||
184 | // Get track length in milliseconds | 184 | // Get track length in milliseconds |
185 | long Track_length( struct Nsf_Emu* this, int n ); | 185 | int Track_length( struct Nsf_Emu* this, int n ); |
186 | 186 | ||
187 | // Sound customization | 187 | // Sound customization |
188 | 188 | ||
@@ -217,28 +217,28 @@ bool run_cpu_until( struct Nsf_Emu* this, nes_time_t end ); | |||
217 | 217 | ||
218 | // Sets clocks between calls to play routine to p + 1/2 clock | 218 | // Sets clocks between calls to play routine to p + 1/2 clock |
219 | static inline void set_play_period( struct Nsf_Emu* this, int p ) { this->play_period = p; } | 219 | static inline void set_play_period( struct Nsf_Emu* this, int p ) { this->play_period = p; } |
220 | 220 | ||
221 | // Time play routine will next be called | 221 | // Time play routine will next be called |
222 | static inline nes_time_t play_time( struct Nsf_Emu* this ) { return this->next_play; } | 222 | static inline nes_time_t play_time( struct Nsf_Emu* this ) { return this->next_play; } |
223 | 223 | ||
224 | // Emulates to at least time t. Might emulate a few clocks extra. | 224 | // Emulates to at least time t. Might emulate a few clocks extra. |
225 | void run_until( struct Nsf_Emu* this, nes_time_t t ); | 225 | void run_until( struct Nsf_Emu* this, nes_time_t t ); |
226 | 226 | ||
227 | // Runs cpu to at least time t and returns false, or returns true | 227 | // Runs cpu to at least time t and returns false, or returns true |
228 | // if it encounters illegal instruction (halt). | 228 | // if it encounters illegal instruction (halt). |
229 | bool run_cpu_until( struct Nsf_Emu* this, nes_time_t t ); | 229 | bool run_cpu_until( struct Nsf_Emu* this, nes_time_t t ); |
230 | 230 | ||
231 | // cpu calls through to these to access memory (except instructions) | 231 | // cpu calls through to these to access memory (except instructions) |
232 | int read_mem( struct Nsf_Emu* this, addr_t ); | 232 | int read_mem( struct Nsf_Emu* this, addr_t ); |
233 | void write_mem( struct Nsf_Emu* this, addr_t, int ); | 233 | void write_mem( struct Nsf_Emu* this, addr_t, int ); |
234 | 234 | ||
235 | // Address of play routine | 235 | // Address of play routine |
236 | static inline addr_t play_addr( struct Nsf_Emu* this ) { return get_addr( this->header.play_addr ); } | 236 | static inline addr_t play_addr( struct Nsf_Emu* this ) { return get_addr( this->header.play_addr ); } |
237 | 237 | ||
238 | // Same as run_until, except emulation stops for any event (routine returned, | 238 | // Same as run_until, except emulation stops for any event (routine returned, |
239 | // play routine called, illegal instruction). | 239 | // play routine called, illegal instruction). |
240 | void run_once( struct Nsf_Emu* this, nes_time_t ); | 240 | void run_once( struct Nsf_Emu* this, nes_time_t ); |
241 | 241 | ||
242 | // Reads byte as cpu would when executing code. Only works for RAM/ROM, | 242 | // Reads byte as cpu would when executing code. Only works for RAM/ROM, |
243 | // NOT I/O like sound chips. | 243 | // NOT I/O like sound chips. |
244 | int read_code( struct Nsf_Emu* this, addr_t addr ); | 244 | int read_code( struct Nsf_Emu* this, addr_t addr ); |
@@ -248,12 +248,14 @@ static inline byte* sram( struct Nsf_Emu* this ) { return this->high_ | |||
248 | static inline byte* unmapped_code( struct Nsf_Emu* this ) { return &this->high_ram [sram_size]; } | 248 | static inline byte* unmapped_code( struct Nsf_Emu* this ) { return &this->high_ram [sram_size]; } |
249 | 249 | ||
250 | #ifndef NSF_EMU_APU_ONLY | 250 | #ifndef NSF_EMU_APU_ONLY |
251 | static inline int fds_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & fds_flag; } | 251 | static inline int fds_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & fds_flag; } |
252 | static inline int vrc6_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & vrc6_flag; } | 252 | static inline int vrc6_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & vrc6_flag; } |
253 | static inline int vrc7_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & vrc7_flag; } | 253 | #ifndef NSF_EMU_NO_VRC7 |
254 | static inline int mmc5_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & mmc5_flag; } | 254 | static inline int vrc7_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & vrc7_flag; } |
255 | static inline int namco_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & namco_flag; } | 255 | #endif |
256 | static inline int fme7_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & fme7_flag; } | 256 | static inline int mmc5_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & mmc5_flag; } |
257 | static inline int namco_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & namco_flag; } | ||
258 | static inline int fme7_enabled( struct Nsf_Emu* this ) { return this->header.chip_flags & fme7_flag; } | ||
257 | #endif | 259 | #endif |
258 | 260 | ||
259 | #endif | 261 | #endif |