Mercurial > audlegacy
annotate Plugins/Input/console/Nsf_Emu.h @ 352:f13ab2d8e9cf trunk
[svn] various fixes :(
author | nenolod |
---|---|
date | Mon, 26 Dec 2005 14:12:35 -0800 |
parents | 252843aac42f |
children | 0b9507985f0d |
rev | line source |
---|---|
90
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
1 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
2 // Nintendo Entertainment System (NES) NSF-format game music file emulator |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
3 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
4 // Game_Music_Emu 0.2.4. Copyright (C) 2003-2005 Shay Green. GNU LGPL license. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
5 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
6 #ifndef NSF_EMU_H |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
7 #define NSF_EMU_H |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
8 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
9 #include "Classic_Emu.h" |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
10 #include "Nes_Apu.h" |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
11 #include "Nes_Cpu.h" |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
12 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
13 // If NSF_EMU_APU_ONLY is non-zero, external sound chip support is disabled |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
14 #if !NSF_EMU_APU_ONLY |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
15 #include "Nes_Vrc6.h" |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
16 #include "Nes_Namco.h" |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
17 #endif |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
18 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
19 class Nsf_Emu : public Classic_Emu { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
20 public: |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
21 // Set internal gain, where 1.0 results in almost no clamping. Default gain |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
22 // roughly matches volume of other emulators. |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
23 Nsf_Emu( double gain = 1.4 ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
24 ~Nsf_Emu(); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
25 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
26 struct header_t { |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
27 char tag [5]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
28 byte vers; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
29 byte track_count; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
30 byte first_track; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
31 byte load_addr [2]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
32 byte init_addr [2]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
33 byte play_addr [2]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
34 char game [32]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
35 char author [32]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
36 char copyright [32]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
37 byte ntsc_speed [2]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
38 byte banks [8]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
39 byte pal_speed [2]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
40 byte speed_flags; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
41 byte chip_flags; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
42 byte unused [4]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
43 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
44 enum { song = 0 }; // no song titles |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
45 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
46 BOOST_STATIC_ASSERT( sizeof (header_t) == 0x80 ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
47 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
48 // Load NSF, given its header and reader for remaining data |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
49 blargg_err_t load( const header_t&, Emu_Reader& ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
50 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
51 blargg_err_t start_track( int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
52 Nes_Apu* apu_() { return &apu; } |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
53 const char** voice_names() const; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
54 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
55 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
56 // End of public interface |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
57 protected: |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
58 void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
59 void update_eq( blip_eq_t const& ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
60 blip_time_t run( int, bool* ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
61 private: |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
62 // initial state |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
63 enum { bank_count = 8 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
64 byte initial_banks [bank_count]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
65 int initial_pcm_dac; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
66 double gain; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
67 bool needs_long_frames; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
68 bool pal_only; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
69 unsigned init_addr; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
70 unsigned play_addr; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
71 int exp_flags; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
72 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
73 // timing |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
74 double clocks_per_msec; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
75 nes_time_t next_play; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
76 long play_period; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
77 int play_extra; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
78 nes_time_t clock() const; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
79 nes_time_t next_irq( nes_time_t end_time ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
80 static void irq_changed( void* ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
81 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
82 // rom |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
83 int total_banks; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
84 byte* rom; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
85 static int read_code( Nsf_Emu*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
86 void unload(); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
87 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
88 // cpu |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
89 Nes_Cpu cpu; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
90 void cpu_jsr( unsigned pc, int adj ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
91 static int read_low_mem( Nsf_Emu*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
92 static void write_low_mem( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
93 static int read_unmapped( Nsf_Emu*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
94 static void write_unmapped( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
95 static void write_exram( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
96 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
97 blargg_err_t init_sound(); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
98 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
99 // apu |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
100 Nes_Apu apu; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
101 static int read_snd( Nsf_Emu*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
102 static void write_snd( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
103 static int pcm_read( void*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
104 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
105 #if !NSF_EMU_APU_ONLY |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
106 // namco |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
107 Nes_Namco namco; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
108 static int read_namco( Nsf_Emu*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
109 static void write_namco( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
110 static void write_namco_addr( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
111 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
112 // vrc6 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
113 Nes_Vrc6 vrc6; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
114 static void write_vrc6( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
115 #endif |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
116 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
117 // sram |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
118 enum { sram_size = 0x2000 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
119 byte sram [sram_size]; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
120 static int read_sram( Nsf_Emu*, nes_addr_t ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
121 static void write_sram( Nsf_Emu*, nes_addr_t, int ); |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
122 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
123 friend class Nsf_Remote_Emu; // hack |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
124 }; |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
125 |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
126 #endif |
252843aac42f
[svn] Import the initial sources for console music support.
nenolod
parents:
diff
changeset
|
127 |