diff options
Diffstat (limited to 'apps/codecs/libgme/nes_namco_apu.h')
-rw-r--r-- | apps/codecs/libgme/nes_namco_apu.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/apps/codecs/libgme/nes_namco_apu.h b/apps/codecs/libgme/nes_namco_apu.h new file mode 100644 index 0000000000..b53b69808b --- /dev/null +++ b/apps/codecs/libgme/nes_namco_apu.h | |||
@@ -0,0 +1,71 @@ | |||
1 | // Namco 106 sound chip emulator | ||
2 | |||
3 | // Nes_Snd_Emu 0.1.8 | ||
4 | #ifndef NES_NAMCO_APU_H | ||
5 | #define NES_NAMCO_APU_H | ||
6 | |||
7 | #include "blargg_common.h" | ||
8 | #include "blip_buffer.h" | ||
9 | |||
10 | struct namco_state_t; | ||
11 | |||
12 | enum { namco_osc_count = 8 }; | ||
13 | enum { namco_addr_reg_addr = 0xF800 }; | ||
14 | enum { namco_data_reg_addr = 0x4800 }; | ||
15 | enum { namco_reg_count = 0x80 }; | ||
16 | |||
17 | struct Namco_Osc { | ||
18 | blargg_long delay; | ||
19 | struct Blip_Buffer* output; | ||
20 | short last_amp; | ||
21 | short wave_pos; | ||
22 | }; | ||
23 | |||
24 | struct Nes_Namco_Apu { | ||
25 | struct Namco_Osc oscs [namco_osc_count]; | ||
26 | |||
27 | blip_time_t last_time; | ||
28 | int addr_reg; | ||
29 | |||
30 | uint8_t reg [namco_reg_count]; | ||
31 | |||
32 | struct Blip_Synth synth; | ||
33 | }; | ||
34 | |||
35 | // See Nes_Apu.h for reference. | ||
36 | void Namco_init( struct Nes_Namco_Apu* this ); | ||
37 | void Namco_output( struct Nes_Namco_Apu* this, struct Blip_Buffer* ); | ||
38 | |||
39 | void Namco_reset( struct Nes_Namco_Apu* this ); | ||
40 | void Namco_end_frame( struct Nes_Namco_Apu* this, blip_time_t ) ICODE_ATTR; | ||
41 | |||
42 | static inline uint8_t* namco_access( struct Nes_Namco_Apu* this ) | ||
43 | { | ||
44 | int addr = this->addr_reg & 0x7F; | ||
45 | if ( this->addr_reg & 0x80 ) | ||
46 | this->addr_reg = (addr + 1) | 0x80; | ||
47 | return &this->reg [addr]; | ||
48 | } | ||
49 | |||
50 | static inline void Namco_volume( struct Nes_Namco_Apu* this, double v ) { Synth_volume( &this->synth, 0.10 / namco_osc_count * v / 15.0 ); } | ||
51 | |||
52 | // Write-only address register is at 0xF800 | ||
53 | static inline void Namco_write_addr( struct Nes_Namco_Apu* this, int v ) { this->addr_reg = v; } | ||
54 | |||
55 | static inline int Namco_read_data( struct Nes_Namco_Apu* this ) { return *namco_access( this ); } | ||
56 | |||
57 | static inline void Namco_osc_output( struct Nes_Namco_Apu* this, int i, struct Blip_Buffer* buf ) | ||
58 | { | ||
59 | assert( (unsigned) i < namco_osc_count ); | ||
60 | this->oscs [i].output = buf; | ||
61 | } | ||
62 | |||
63 | // Read/write data register is at 0x4800 | ||
64 | void Namco_run_until( struct Nes_Namco_Apu* this, blip_time_t ) ICODE_ATTR; | ||
65 | static inline void Namco_write_data( struct Nes_Namco_Apu* this, blip_time_t time, int data ) | ||
66 | { | ||
67 | Namco_run_until( this, time ); | ||
68 | *namco_access( this ) = data; | ||
69 | } | ||
70 | |||
71 | #endif | ||