comparison src/console/Nsf_Emu.h @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Input/console/Nsf_Emu.h@13389e613d67
children fb513e10174e
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
1
2 // Nintendo Entertainment System (NES) NSF music file emulator
3
4 // Game_Music_Emu 0.3.0
5
6 #ifndef NSF_EMU_H
7 #define NSF_EMU_H
8
9 #include "Classic_Emu.h"
10 #include "Nes_Apu.h"
11 #include "Nes_Cpu.h"
12
13 typedef Nes_Emu Nsf_Emu;
14
15 class Nes_Emu : public Classic_Emu {
16 public:
17
18 // Set internal gain, where 1.0 results in almost no clamping. Default gain
19 // roughly matches volume of other emulators.
20 Nes_Emu( double gain = 1.4 );
21
22 // NSF file header
23 struct header_t
24 {
25 char tag [5];
26 byte vers;
27 byte track_count;
28 byte first_track;
29 byte load_addr [2];
30 byte init_addr [2];
31 byte play_addr [2];
32 char game [32];
33 char author [32];
34 char copyright [32];
35 byte ntsc_speed [2];
36 byte banks [8];
37 byte pal_speed [2];
38 byte speed_flags;
39 byte chip_flags;
40 byte unused [4];
41
42 enum { song = 0 }; // no song titles
43 };
44 BOOST_STATIC_ASSERT( sizeof (header_t) == 0x80 );
45
46 // Load NSF data
47 blargg_err_t load( Data_Reader& );
48
49 // Load NSF using already-loaded header and remaining data
50 blargg_err_t load( header_t const&, Data_Reader& );
51
52 // Header for currently loaded NSF
53 header_t const& header() const { return header_; }
54
55 // Equalizer profiles for US NES and Japanese Famicom
56 static equalizer_t const nes_eq;
57 static equalizer_t const famicom_eq;
58
59 public:
60 ~Nes_Emu();
61 void start_track( int );
62 Nes_Apu* apu_() { return &apu; }
63 const char** voice_names() const;
64 protected:
65 void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* );
66 void update_eq( blip_eq_t const& );
67 blip_time_t run_clocks( blip_time_t, bool* );
68 virtual void call_play();
69 protected:
70 // initial state
71 enum { bank_count = 8 };
72 byte initial_banks [bank_count];
73 int initial_pcm_dac;
74 double gain;
75 bool needs_long_frames;
76 bool pal_only;
77 unsigned init_addr;
78 unsigned play_addr;
79 int exp_flags;
80
81 // timing
82 nes_time_t next_play;
83 long play_period;
84 int play_extra;
85 nes_time_t clock() const;
86 nes_time_t next_irq( nes_time_t end_time );
87 static void irq_changed( void* );
88
89 // rom
90 int total_banks;
91 blargg_vector<byte> rom;
92 static int read_code( Nsf_Emu*, nes_addr_t );
93 void unload();
94
95 blargg_err_t init_sound();
96
97 // expansion sound
98
99 class Nes_Namco_Apu* namco;
100 static int read_namco( Nsf_Emu*, nes_addr_t );
101 static void write_namco( Nsf_Emu*, nes_addr_t, int );
102 static void write_namco_addr( Nsf_Emu*, nes_addr_t, int );
103
104 class Nes_Vrc6_Apu* vrc6;
105 static void write_vrc6( Nsf_Emu*, nes_addr_t, int );
106
107 class Nes_Fme7_Apu* fme7;
108 static void write_fme7( Nsf_Emu*, nes_addr_t, int );
109
110 // large objects
111
112 header_t header_;
113
114 // cpu
115 Nes_Cpu cpu;
116 void cpu_jsr( unsigned pc, int adj );
117 static int read_low_mem( Nsf_Emu*, nes_addr_t );
118 static void write_low_mem( Nsf_Emu*, nes_addr_t, int );
119 static int read_unmapped( Nsf_Emu*, nes_addr_t );
120 static void write_unmapped( Nsf_Emu*, nes_addr_t, int );
121 static void write_exram( Nsf_Emu*, nes_addr_t, int );
122
123 // apu
124 Nes_Apu apu;
125 static int read_snd( Nsf_Emu*, nes_addr_t );
126 static void write_snd( Nsf_Emu*, nes_addr_t, int );
127 static int pcm_read( void*, nes_addr_t );
128
129 // sram
130 enum { sram_size = 0x2000 };
131 byte sram [sram_size];
132 static int read_sram( Nsf_Emu*, nes_addr_t );
133 static void write_sram( Nsf_Emu*, nes_addr_t, int );
134 };
135
136 #endif
137