-
Notifications
You must be signed in to change notification settings - Fork 0
/
apu2A03.h
104 lines (84 loc) · 2.51 KB
/
apu2A03.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2021-2022 Dwight Studio's Team <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// Created by maxime on 19/02/2022.
//
#ifndef NES_EMU_APU2A03_H
#define NES_EMU_APU2A03_H
#include <cstdint>
#include "sound//PulseWave.h"
class apu2A03 {
public:
apu2A03();
~apu2A03();
public:
void cpuWrite(uint16_t addr, uint8_t data);
uint8_t cpuRead(uint16_t addr);
void clock();
void reset();
private:
void play();
uint8_t counter = 0x00;
private:
union {
struct {
uint8_t channelPulse1 : 1;
uint8_t channelPulse2 : 1;
uint8_t channelTriangle : 1;
uint8_t channelNoise : 1;
uint8_t channelDMC : 1;
uint8_t unused : 3;
};
uint8_t rawData;
} apuStatus{};
// Pulse 1 channel register
union {
union {
struct {
uint8_t envelopeDivider : 4;
uint8_t envelopeFlag : 1;
uint8_t lengthCounterHalt : 1;
uint8_t dutyCycle : 2;
};
uint8_t rawData;
} status;
union {
struct {
uint8_t shiftCount : 3;
uint8_t negateFlag : 1;
uint8_t deviderPeriod : 3;
uint8_t enabledFlag : 1;
};
uint8_t rawData;
} sweep;
uint8_t timerLo;
union {
struct {
uint8_t timerHi : 3;
uint8_t lenghtCounterLoad : 5;
};
uint8_t rawData;
} timerHi;
} channelPulse1;
PulseWave pulseWave{44100};
// Pulse 2 channel registers
uint8_t channelPulse2Status = 0x00;
uint8_t channelPulse2Sweep = 0x00;
uint8_t channelPulse2TimerLo = 0x00;
uint8_t channelPulse2TimerHi = 0x00; // It also contains the length counter load
// Triangle channel registers
uint8_t channelTriangleLinearCounter = 0x00;
uint8_t channelTriangleTimerLo = 0x00;
uint8_t channelTriangleTimerHi = 0x00; // It also contains the length counter load
// Noise channel registers
uint8_t channelNoiseStatus = 0x00;
uint8_t channelNoiseModePeriod = 0x00;
uint8_t channelNoiseLengthCounterLoad = 0x00;
// Frame counter
uint8_t frameCounterData = 0x00;
uint8_t sequencer = 0x01;
};
#endif //NES_EMU_APU2A03_H