summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/nes_defs.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/sound/nes_defs.h')
-rw-r--r--src/devices/sound/nes_defs.h121
1 files changed, 40 insertions, 81 deletions
diff --git a/src/devices/sound/nes_defs.h b/src/devices/sound/nes_defs.h
index 0abe5b4666e..7756a9b3d18 100644
--- a/src/devices/sound/nes_defs.h
+++ b/src/devices/sound/nes_defs.h
@@ -4,16 +4,12 @@
MAME/MESS NES APU CORE
- Based on the Nofrendo/Nosefart NES N2A03 sound emulation core written by
+ Based on the Nofrendo/Nosefart NES RP2A03 sound emulation core written by
Matthew Conte (matt@conte.com) and redesigned for use in MAME/MESS by
Who Wants to Know? (wwtk@mail.com)
This core is written with the advise and consent of Matthew Conte and is
- released under the GNU Public License. This core is freely available for
- use in any freeware project, subject to the following terms:
-
- Any modifications to this code must be duly noted in the source and
- approved by Matthew Conte and myself prior to public submission.
+ released under the GNU Public License.
*****************************************************************************
@@ -32,15 +28,6 @@
/* APU type */
struct apu_t
{
- /* REGULAR TYPE DEFINITIONS */
- typedef int8_t int8;
- typedef int16_t int16;
- typedef int32_t int32;
- typedef uint8_t uint8;
- typedef uint16_t uint16;
- typedef uint32_t uint32;
-
-
/* CHANNEL TYPE DEFINITIONS */
/* Square Wave */
@@ -52,16 +39,16 @@ struct apu_t
elem = 0;
}
- uint8 regs[4];
+ u8 regs[4];
int vbl_length = 0;
int freq = 0;
float phaseacc = 0.0;
- float output_vol = 0.0;
float env_phase = 0.0;
float sweep_phase = 0.0;
- uint8 adder = 0;
- uint8 env_vol = 0;
+ u8 adder = 0;
+ u8 env_vol = 0;
bool enabled = false;
+ u8 output = 0;
};
/* Triangle Wave */
@@ -73,15 +60,16 @@ struct apu_t
elem = 0;
}
- uint8 regs[4]; /* regs[1] unused */
+ u8 regs[4]; /* regs[1] unused */
int linear_length = 0;
+ bool linear_reload = false;
int vbl_length = 0;
int write_latency = 0;
float phaseacc = 0.0;
- float output_vol = 0.0;
- uint8 adder = 0;
+ u8 adder = 0;
bool counter_started = false;
bool enabled = false;
+ u8 output = 0;
};
/* Noise Wave */
@@ -93,14 +81,14 @@ struct apu_t
elem = 0;
}
- uint8 regs[4]; /* regs[1] unused */
- int cur_pos = 0;
+ u8 regs[4]; /* regs[1] unused */
+ u16 lfsr = 1;
int vbl_length = 0;
float phaseacc = 0.0;
- float output_vol = 0.0;
float env_phase = 0.0;
- uint8 env_vol = 0;
+ u8 env_vol = 0;
bool enabled = false;
+ u8 output = 0;
};
/* DPCM Wave */
@@ -112,16 +100,16 @@ struct apu_t
elem = 0;
}
- uint8 regs[4];
- uint32 address = 0;
- uint32 length = 0;
+ u8 regs[4];
+ u32 address = 0;
+ u32 length = 0;
int bits_left = 0;
float phaseacc = 0.0;
- float output_vol = 0.0;
- uint8 cur_byte = 0;
+ u8 cur_byte = 0;
bool enabled = false;
bool irq_occurred = false;
- signed char vol = 0;
+ s16 vol = 0;
+ u8 output = 0;
};
@@ -147,60 +135,24 @@ struct apu_t
static constexpr unsigned SMASK = 0x15;
static constexpr unsigned IRQCTRL = 0x17;
- static constexpr unsigned NOISE_LONG = 0x4000;
- static constexpr unsigned NOISE_SHORT = 93;
-
-
- apu_t()
- {
- memset(regs, 0, sizeof(regs));
- }
-
/* Sound channels */
square_t squ[2];
triangle_t tri;
noise_t noi;
dpcm_t dpcm;
- /* APU registers */
- unsigned char regs[0x18];
-
- /* Sound pointers */
- void *buffer = nullptr;
-
-#ifdef USE_QUEUE
-
- static constexpr unsigned QUEUE_SIZE = 0x2000;
- static constexpr unsigned QUEUE_MAX = QUEUE_SIZE - 1;
-
- struct queue_t
- {
- queue_t() { }
-
- int pos = 0;
- unsigned char reg = 0, val = 0;
- };
-
- /* Event queue */
- queue_t queue[QUEUE_SIZE];
- int head, tail;
-
-#else
-
- int buf_pos = 0;
-
-#endif
-
- int step_mode = 0;
+ u8 step_mode = 0;
+ bool frame_irq_enabled = false;
+ bool frame_irq_occurred = false;
};
/* CONSTANTS */
/* vblank length table used for squares, triangle, noise */
-static const apu_t::uint8 vbl_length[32] =
+static const u8 vbl_length[32] =
{
- 5, 127, 10, 1, 19, 2, 40, 3, 80, 4, 30, 5, 7, 6, 13, 7,
- 6, 8, 12, 9, 24, 10, 48, 11, 96, 12, 36, 13, 8, 14, 16, 15
+ 10, 254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14,
+ 12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30
};
/* frequency limit of square channels */
@@ -209,23 +161,30 @@ static const int freq_limit[8] =
0x3FF, 0x555, 0x666, 0x71C, 0x787, 0x7C1, 0x7E0, 0x7F0,
};
-/* table of noise frequencies */
-static const int noise_freq[16] =
+// table of noise period
+// each fundamental is determined as: freq = master / period / 93
+static const int noise_freq[2][16] =
{
- 4, 8, 16, 32, 64, 96, 128, 160, 202, 254, 380, 508, 762, 1016, 2034, 2046
+ { 4, 8, 16, 32, 64, 96, 128, 160, 202, 254, 380, 508, 762, 1016, 2034, 4068 }, // NTSC
+ { 4, 8, 14, 30, 60, 88, 118, 148, 188, 236, 354, 472, 708, 944, 1890, 3778 } // PAL
};
-/* dpcm transfer freqs */
-static const int dpcm_clocks[16] =
+// dpcm (cpu) cycle period
+// each frequency is determined as: freq = master / period
+static const int dpcm_clocks[2][16] =
{
- 428, 380, 340, 320, 286, 254, 226, 214, 190, 160, 142, 128, 106, 85, 72, 54
+ { 428, 380, 340, 320, 286, 254, 226, 214, 190, 160, 142, 128, 106, 84, 72, 54 }, // NTSC
+ { 398, 354, 316, 298, 276, 236, 210, 198, 176, 148, 132, 118, 98, 78, 66, 50 } // PAL
};
/* ratios of pos/neg pulse for square waves */
/* 2/16 = 12.5%, 4/16 = 25%, 8/16 = 50%, 12/16 = 75% */
static const int duty_lut[4] =
{
- 2, 4, 8, 12
+ 0b01000000, // 01000000 (12.5%)
+ 0b01100000, // 01100000 (25%)
+ 0b01111000, // 01111000 (50%)
+ 0b10011111, // 10011111 (25% negated)
};
#endif // MAME_SOUND_NES_DEFS_H