summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/hes_emu.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/hes_emu.h')
-rw-r--r--lib/rbcodec/codecs/libgme/hes_emu.h195
1 files changed, 195 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/hes_emu.h b/lib/rbcodec/codecs/libgme/hes_emu.h
new file mode 100644
index 0000000000..a1dd048498
--- /dev/null
+++ b/lib/rbcodec/codecs/libgme/hes_emu.h
@@ -0,0 +1,195 @@
1// TurboGrafx-16/PC Engine HES music file emulator
2
3// Game_Music_Emu 0.5.2
4#ifndef HES_EMU_H
5#define HES_EMU_H
6
7#include "blargg_source.h"
8
9#include "multi_buffer.h"
10#include "rom_data.h"
11#include "hes_apu.h"
12#include "hes_apu_adpcm.h"
13#include "hes_cpu.h"
14#include "m3u_playlist.h"
15#include "track_filter.h"
16
17// HES file header
18enum { info_offset = 0x20 };
19enum { header_size = 0x20 };
20struct header_t
21{
22 byte tag [4];
23 byte vers;
24 byte first_track;
25 byte init_addr [2];
26 byte banks [8];
27 byte data_tag [4];
28 byte size [4];
29 byte addr [4];
30 byte unused [4];
31};
32
33
34struct timer_t {
35 hes_time_t last_time;
36 int count;
37 int load;
38 int raw_load;
39 byte enabled;
40 byte fired;
41};
42
43struct vdp_t {
44 hes_time_t next_vbl;
45 byte latch;
46 byte control;
47};
48
49struct irq_t {
50 hes_time_t timer;
51 hes_time_t vdp;
52 byte disables;
53};
54
55struct Hes_Emu {
56 hes_time_t play_period;
57 int timer_base;
58
59 struct timer_t timer;
60 struct vdp_t vdp;
61 struct irq_t irq;
62
63 // Sound
64 int clock_rate_;
65 int sample_rate_;
66 unsigned buf_changed_count;
67 int voice_count_;
68 int const* voice_types_;
69 int mute_mask_;
70 int tempo_;
71 int gain_;
72
73 // track-specific
74 byte track_count;
75 int current_track_;
76
77 // Larger files at the end
78 // Header for currently loaded file
79 struct header_t header;
80
81 // M3u Playlist
82 struct M3u_Playlist m3u;
83
84 struct setup_t tfilter;
85 struct Track_Filter track_filter;
86
87 // Hes Cpu
88 struct Hes_Cpu cpu;
89 struct Rom_Data rom;
90
91 struct Hes_Apu apu;
92 struct Hes_Apu_Adpcm adpcm;
93
94 struct Multi_Buffer stereo_buf;
95
96 // rom & ram
97 byte* write_pages [page_count + 1]; // 0 if unmapped or I/O space
98 byte ram [page_size];
99 byte sgx [3 * page_size + cpu_padding];
100};
101
102
103// Basic functionality
104// Initializes Hes_Emu structure
105void Hes_init( struct Hes_Emu* this );
106
107// Stops (clear) Hes_Emu structure
108void Hes_stop( struct Hes_Emu* this );
109
110// Loads a file from memory
111blargg_err_t Hes_load_mem( struct Hes_Emu* this, void* data, long size );
112
113// Set output sample rate. Must be called only once before loading file.
114blargg_err_t Hes_set_sample_rate( struct Hes_Emu* this, int sample_rate );
115
116// Start a track, where 0 is the first track. Also clears warning string.
117blargg_err_t Hes_start_track( struct Hes_Emu* this, int );
118
119// Generate 'count' samples info 'buf'. Output is in stereo. Any emulation
120// errors set warning string, and major errors also end track.
121blargg_err_t Hes_play( struct Hes_Emu* this, int count, sample_t* buf );
122
123// Track status/control
124// Number of milliseconds (1000 msec = 1 second) played since ning of track
125int Track_tell( struct Hes_Emu* this );
126
127// Seek to new time in track. Seeking backwards or far forward can take a while.
128blargg_err_t Track_seek( struct Hes_Emu* this, int msec );
129
130// Skip n samples
131blargg_err_t Track_skip( struct Hes_Emu* this, int n );
132
133// Set start time and length of track fade out. Once fade ends track_ended() returns
134// true. Fade time can be changed while track is playing.
135void Track_set_fade( struct Hes_Emu* this, int start_msec, int length_msec );
136
137// True if a track has reached its end
138static inline bool Track_ended( struct Hes_Emu* this )
139{
140 return track_ended( &this->track_filter );
141}
142
143// Disables automatic end-of-track detection and skipping of silence at beginning
144static inline void Track_ignore_silence( struct Hes_Emu* this, bool disable )
145{
146 this->track_filter.silence_ignored_ = disable;
147}
148
149// Get track length in milliseconds
150static inline int Track_get_length( struct Hes_Emu* this, int n )
151{
152 int length = 120 * 1000; /* 2 minutes */
153 if ( (this->m3u.size > 0) && (n < this->m3u.size) ) {
154 struct entry_t* entry = &this->m3u.entries [n];
155 length = entry->length;
156 }
157
158 return length;
159}
160
161
162// Sound customization
163// Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed.
164// Track length as returned by track_info() assumes a tempo of 1.0.
165void Sound_set_tempo( struct Hes_Emu* this, int );
166
167// Mute/unmute voice i, where voice 0 is first voice
168void Sound_mute_voice( struct Hes_Emu* this, int index, bool mute );
169
170// Set muting state of all voices at once using a bit mask, where -1 mutes them all,
171// 0 unmutes them all, 0x01 mutes just the first voice, etc.
172void Sound_mute_voices( struct Hes_Emu* this, int mask );
173
174// Change overall output amplitude, where 1.0 results in minimal clamping.
175// Must be called before set_sample_rate().
176static inline void Sound_set_gain( struct Hes_Emu* this, int g )
177{
178 assert( !this->sample_rate_ ); // you must set gain before setting sample rate
179 this->gain_ = g;
180}
181
182// Emulation (You shouldn't touch these)
183
184void irq_changed( struct Hes_Emu* this );
185void run_until( struct Hes_Emu* this, hes_time_t );
186bool run_cpu( struct Hes_Emu* this, hes_time_t end );
187int read_mem_( struct Hes_Emu* this, hes_addr_t );
188int read_mem( struct Hes_Emu* this, hes_addr_t );
189void write_mem_( struct Hes_Emu* this, hes_addr_t, int data );
190void write_mem( struct Hes_Emu* this, hes_addr_t, int );
191void write_vdp( struct Hes_Emu* this, int addr, int data );
192void set_mmr( struct Hes_Emu* this, int reg, int bank );
193int cpu_done( struct Hes_Emu* this );
194
195#endif