diff options
Diffstat (limited to 'apps/codecs/libgme/nes_mmc5_apu.h')
-rw-r--r-- | apps/codecs/libgme/nes_mmc5_apu.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/codecs/libgme/nes_mmc5_apu.h b/apps/codecs/libgme/nes_mmc5_apu.h new file mode 100644 index 0000000000..b696b49e97 --- /dev/null +++ b/apps/codecs/libgme/nes_mmc5_apu.h | |||
@@ -0,0 +1,61 @@ | |||
1 | // NES MMC5 sound chip emulator | ||
2 | |||
3 | // Nes_Snd_Emu 0.2.0-pre | ||
4 | #ifndef NES_MMC5_APU_H | ||
5 | #define NES_MMC5_APU_H | ||
6 | |||
7 | #include "blargg_common.h" | ||
8 | #include "nes_apu.h" | ||
9 | |||
10 | enum { mmc5_regs_addr = 0x5000 }; | ||
11 | enum { mmc5_regs_size = 0x16 }; | ||
12 | enum { mmc5_osc_count = 3 }; | ||
13 | enum { mmc5_exram_size = 1024 }; | ||
14 | |||
15 | struct Nes_Mmc5_Apu { | ||
16 | struct Nes_Apu apu; | ||
17 | unsigned char exram [mmc5_exram_size]; | ||
18 | }; | ||
19 | |||
20 | static inline void Mmc5_init( struct Nes_Mmc5_Apu* this ) | ||
21 | { | ||
22 | Apu_init( &this->apu ); | ||
23 | } | ||
24 | |||
25 | static inline void Mmc5_set_output( struct Nes_Mmc5_Apu* this, int i, struct Blip_Buffer* b ) | ||
26 | { | ||
27 | // in: square 1, square 2, PCM | ||
28 | // out: square 1, square 2, skipped, skipped, PCM | ||
29 | if ( i > 1 ) | ||
30 | i += 2; | ||
31 | Apu_osc_output( &this->apu, i, b ); | ||
32 | } | ||
33 | |||
34 | static inline void Mmc5_write_register( struct Nes_Mmc5_Apu* this, blip_time_t time, unsigned addr, int data ) | ||
35 | { | ||
36 | switch ( addr ) | ||
37 | { | ||
38 | case 0x5015: // channel enables | ||
39 | data &= 0x03; // enable the square waves only | ||
40 | // fall through | ||
41 | case 0x5000: // Square 1 | ||
42 | case 0x5002: | ||
43 | case 0x5003: | ||
44 | case 0x5004: // Square 2 | ||
45 | case 0x5006: | ||
46 | case 0x5007: | ||
47 | case 0x5011: // DAC | ||
48 | Apu_write_register( &this->apu, time, addr - 0x1000, data ); | ||
49 | break; | ||
50 | |||
51 | case 0x5010: // some things write to this for some reason | ||
52 | break; | ||
53 | |||
54 | #ifdef BLARGG_DEBUG_H | ||
55 | default: | ||
56 | dprintf( "Unmapped MMC5 APU write: $%04X <- $%02X\n", addr, data ); | ||
57 | #endif | ||
58 | } | ||
59 | } | ||
60 | |||
61 | #endif | ||