-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCNesCalculations.h
53 lines (41 loc) · 1.77 KB
/
CNesCalculations.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
// NES hardware related calculations
#include <cstdint>
#include <cassert>
#include <cstddef>
#include "DNesConsts.h"
namespace PurrFX
{
class CNesCalculations
{
public:
/////////
// DMC //
/////////
static uint16_t dpcmSampleAddressUnpack(uint8_t i_nPackedAddress);
static uint8_t dpcmSampleAddressPack(uint16_t i_nPackedAddress);
static uint16_t dpcmSampleLengthUnpack(uint8_t i_nPackedLength);
static uint8_t dpcmSampleLengthPack(uint16_t i_nPackedLength);
// For unpacked length (real size in bytes)
static bool isDpcmSampleLengthCorrect(size_t i_nSize);
static uint16_t closestDpcmDataLength(size_t i_nSize);
static size_t dpcm2pcmDataLength(size_t i_nDpcmDataLength);
static size_t pcm2dpcmDataLength(size_t i_nPcmDataLength);
///////////
// Pitch //
///////////
// APU
static double apuPulseFrequency (uint16_t i_nTimer , double i_nCpuClockSpeed = NesConsts::cpuClockSpeedNTSC);
static double apuTriangleFrequency(uint16_t i_nTimer , double i_nCpuClockSpeed = NesConsts::cpuClockSpeedNTSC);
static uint16_t apuPulseTimer (double i_nFrequency, double i_nCpuClockSpeed = NesConsts::cpuClockSpeedNTSC);
static uint16_t apuTriangleTimer (double i_nFrequency, double i_nCpuClockSpeed = NesConsts::cpuClockSpeedNTSC);
///////////
// Timer //
///////////
// APU
static uint16_t makeApuPulseTimer (uint8_t i_nRegisterTimerLow, uint8_t i_nRegisterTimerHigh);
static uint16_t makeApuTriangleTimer(uint8_t i_nRegisterTimerLow, uint8_t i_nRegisterTimerHigh);
static void decomposeApuPulseTimer (uint8_t& o_rLowPart, uint8_t& o_rHighPart, uint16_t i_nTimer, uint8_t i_nL = 0x00);
static void decomposeApuTriangleTimer(uint8_t& o_rLowPart, uint8_t& o_rHighPart, uint16_t i_nTimer, uint8_t i_nL = 0x00);
};
}