Mercurial > audlegacy
comparison Plugins/Input/console/Nes_Namco_Apu.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 // Namco 106 sound chip emulator | |
3 | |
4 // Nes_Snd_Emu 0.1.7 | |
5 | |
6 #ifndef NES_NAMCO_APU_H | |
7 #define NES_NAMCO_APU_H | |
8 | |
9 #include "Nes_Apu.h" | |
10 | |
11 struct namco_snapshot_t; | |
12 | |
13 class Nes_Namco_Apu { | |
14 public: | |
15 Nes_Namco_Apu(); | |
16 ~Nes_Namco_Apu(); | |
17 | |
18 // See Nes_Apu.h for reference. | |
19 void volume( double ); | |
20 void treble_eq( const blip_eq_t& ); | |
21 void output( Blip_Buffer* ); | |
22 enum { osc_count = 8 }; | |
23 void osc_output( int index, Blip_Buffer* ); | |
24 void reset(); | |
25 void end_frame( nes_time_t ); | |
26 | |
27 // Read/write data register is at 0x4800 | |
28 enum { data_reg_addr = 0x4800 }; | |
29 void write_data( nes_time_t, int ); | |
30 int read_data(); | |
31 | |
32 // Write-only address register is at 0xF800 | |
33 enum { addr_reg_addr = 0xF800 }; | |
34 void write_addr( int ); | |
35 | |
36 // to do: implement save/restore | |
37 void save_snapshot( namco_snapshot_t* out ) const; | |
38 void load_snapshot( namco_snapshot_t const& ); | |
39 | |
40 private: | |
41 // noncopyable | |
42 Nes_Namco_Apu( const Nes_Namco_Apu& ); | |
43 Nes_Namco_Apu& operator = ( const Nes_Namco_Apu& ); | |
44 | |
45 struct Namco_Osc { | |
46 long delay; | |
47 Blip_Buffer* output; | |
48 short last_amp; | |
49 short wave_pos; | |
50 }; | |
51 | |
52 Namco_Osc oscs [osc_count]; | |
53 | |
54 nes_time_t last_time; | |
55 int addr_reg; | |
56 | |
57 enum { reg_count = 0x80 }; | |
58 BOOST::uint8_t reg [reg_count]; | |
59 Blip_Synth<blip_good_quality,15> synth; | |
60 | |
61 BOOST::uint8_t& access(); | |
62 void run_until( nes_time_t ); | |
63 }; | |
64 /* | |
65 struct namco_snapshot_t | |
66 { | |
67 BOOST::uint8_t regs [0x80]; | |
68 BOOST::uint8_t addr; | |
69 BOOST::uint8_t unused; | |
70 BOOST::uint8_t positions [8]; | |
71 BOOST::uint32_t delays [8]; | |
72 }; | |
73 */ | |
74 | |
75 inline BOOST::uint8_t& Nes_Namco_Apu::access() | |
76 { | |
77 int addr = addr_reg & 0x7f; | |
78 if ( addr_reg & 0x80 ) | |
79 addr_reg = (addr + 1) | 0x80; | |
80 return reg [addr]; | |
81 } | |
82 | |
83 inline void Nes_Namco_Apu::volume( double v ) { synth.volume( 0.10 / osc_count * v ); } | |
84 | |
85 inline void Nes_Namco_Apu::treble_eq( const blip_eq_t& eq ) { synth.treble_eq( eq ); } | |
86 | |
87 inline void Nes_Namco_Apu::write_addr( int v ) { addr_reg = v; } | |
88 | |
89 inline int Nes_Namco_Apu::read_data() { return access(); } | |
90 | |
91 inline void Nes_Namco_Apu::osc_output( int i, Blip_Buffer* buf ) | |
92 { | |
93 assert( (unsigned) i < osc_count ); | |
94 oscs [i].output = buf; | |
95 } | |
96 | |
97 inline void Nes_Namco_Apu::write_data( nes_time_t time, int data ) | |
98 { | |
99 run_until( time ); | |
100 access() = data; | |
101 } | |
102 | |
103 #endif | |
104 |