summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/nes_namco_apu.h
diff options
context:
space:
mode:
authorSean Bartell <wingedtachikoma@gmail.com>2011-06-25 21:32:25 -0400
committerNils Wallménius <nils@rockbox.org>2012-04-25 22:13:20 +0200
commitf40bfc9267b13b54e6379dfe7539447662879d24 (patch)
tree9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/nes_namco_apu.h
parenta0009907de7a0107d49040d8a180f140e2eff299 (diff)
downloadrockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz
rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97 Reviewed-on: http://gerrit.rockbox.org/137 Reviewed-by: Nils Wallménius <nils@rockbox.org> Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libgme/nes_namco_apu.h')
-rw-r--r--lib/rbcodec/codecs/libgme/nes_namco_apu.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/nes_namco_apu.h b/lib/rbcodec/codecs/libgme/nes_namco_apu.h
new file mode 100644
index 0000000000..c428c894c3
--- /dev/null
+++ b/lib/rbcodec/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
10struct namco_state_t;
11
12enum { namco_osc_count = 8 };
13enum { namco_addr_reg_addr = 0xF800 };
14enum { namco_data_reg_addr = 0x4800 };
15enum { namco_reg_count = 0x80 };
16
17struct Namco_Osc {
18 int delay;
19 struct Blip_Buffer* output;
20 short last_amp;
21 short wave_pos;
22};
23
24struct 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.
36void Namco_init( struct Nes_Namco_Apu* this );
37void Namco_output( struct Nes_Namco_Apu* this, struct Blip_Buffer* );
38
39void Namco_reset( struct Nes_Namco_Apu* this );
40void Namco_end_frame( struct Nes_Namco_Apu* this, blip_time_t );
41
42static 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
50static inline void Namco_volume( struct Nes_Namco_Apu* this, int v ) { Synth_volume( &this->synth, v / 10 / namco_osc_count / 15 ); }
51
52// Write-only address register is at 0xF800
53static inline void Namco_write_addr( struct Nes_Namco_Apu* this, int v ) { this->addr_reg = v; }
54
55static inline int Namco_read_data( struct Nes_Namco_Apu* this ) { return *namco_access( this ); }
56
57static 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
64void Namco_run_until( struct Nes_Namco_Apu* this, blip_time_t );
65static 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