1
2// Namco 106 sound chip emulator
3
4// Nes_Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
5
6#ifndef NES_NAMCO_H
7#define NES_NAMCO_H
8
9#include "Nes_Apu.h"
10
11struct namco_snapshot_t;
12
13class Nes_Namco {
14public:
15 Nes_Namco();
16 ~Nes_Namco();
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( cpu_time_t );
26
27 // Read/write data register is at 0x4800
28 enum { data_reg_addr = 0x4800 };
29 void write_data( cpu_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 );
38 void load_snapshot( namco_snapshot_t const& );
39
40private:
41 // noncopyable
42 Nes_Namco( const Nes_Namco& );
43 Nes_Namco& operator = ( const Nes_Namco& );
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 cpu_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( cpu_time_t );
63};
64
65inline void Nes_Namco::volume( double v ) { synth.volume( 0.10 / osc_count * v ); }
66
67inline void Nes_Namco::treble_eq( const blip_eq_t& eq ) { synth.treble_eq( eq ); }
68
69inline void Nes_Namco::write_addr( int v ) { addr_reg = v; }
70
71inline int Nes_Namco::read_data() { return access(); }
72
73inline void Nes_Namco::osc_output( int i, Blip_Buffer* buf )
74{
75 assert( (unsigned) i < osc_count );
76 oscs [i].output = buf;
77}
78
79inline void Nes_Namco::write_data( cpu_time_t time, int data )
80{
81 run_until( time );
82 access() = data;
83}
84
85#endif
86
87