-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathTypes.h
170 lines (144 loc) · 6.51 KB
/
Types.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
** FamiTracker - NES/Famicom sound tracker
** Copyright (C) 2005-2014 Jonathan Liss
**
** 0CC-FamiTracker is (C) 2014-2018 HertzDevil
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Library General Public License for more details. To obtain a
** copy of the GNU Library General Public License, write to the Free
** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** Any permitted reproduction of these routines, in whole or in part,
** must bear this legend.
*/
#pragma once
#include "APU/Types_fwd.h"
#include "ft0cc/enum_traits.h" // // //
#include "StrongOrdering.h" // // //
// // // moved from FamiTrackerTypes.h
ENUM_CLASS_STANDARD(machine_t, std::uint8_t) {
NTSC, PAL,
min = NTSC, max = PAL, none = static_cast<std::uint8_t>(-1),
};
inline constexpr machine_t DEFAULT_MACHINE_TYPE = machine_t::NTSC; // // //
inline constexpr unsigned MASTER_CLOCK_NTSC = 1789773; // // // moved from CAPU
inline constexpr unsigned MASTER_CLOCK_PAL = 1662607;
inline constexpr unsigned FRAME_RATE_NTSC = 60;
inline constexpr unsigned FRAME_RATE_PAL = 50;
ENUM_CLASS_STANDARD(sound_chip_t, std::uint8_t) { // // //
APU, VRC6, VRC7, FDS, MMC5, N163, S5B,
min = APU, max = S5B, none = static_cast<std::uint8_t>(-1),
};
inline constexpr std::size_t SOUND_CHIP_COUNT = enum_count<sound_chip_t>();
ENUM_CLASS_STANDARD(apu_subindex_t, std::uint8_t) {
pulse1, pulse2, triangle, noise, dpcm,
min = pulse1, max = dpcm, none = static_cast<std::uint8_t>(-1),
};
ENUM_CLASS_STANDARD(vrc6_subindex_t, std::uint8_t) {
pulse1, pulse2, sawtooth,
min = pulse1, max = sawtooth, none = static_cast<std::uint8_t>(-1),
};
ENUM_CLASS_STANDARD(mmc5_subindex_t, std::uint8_t) {
pulse1, pulse2, pcm,
min = pulse1, max = pcm, none = static_cast<std::uint8_t>(-1),
};
ENUM_CLASS_STANDARD(n163_subindex_t, std::uint8_t) {
ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8,
min = ch1, max = ch8, none = static_cast<std::uint8_t>(-1),
};
ENUM_CLASS_STANDARD(fds_subindex_t, std::uint8_t) {
wave,
min = wave, max = wave, none = static_cast<std::uint8_t>(-1),
};
ENUM_CLASS_STANDARD(vrc7_subindex_t, std::uint8_t) {
ch1, ch2, ch3, ch4, ch5, ch6,
min = ch1, max = ch6, none = static_cast<std::uint8_t>(-1),
};
ENUM_CLASS_STANDARD(s5b_subindex_t, std::uint8_t) {
square1, square2, square3,
min = square1, max = square3, none = static_cast<std::uint8_t>(-1),
};
// // // moved from FamiTrackerTypes.h
inline constexpr std::size_t MAX_CHANNELS_2A03 = enum_count<apu_subindex_t>();
inline constexpr std::size_t MAX_CHANNELS_VRC6 = enum_count<vrc6_subindex_t>();
inline constexpr std::size_t MAX_CHANNELS_VRC7 = enum_count<vrc7_subindex_t>();
inline constexpr std::size_t MAX_CHANNELS_FDS = enum_count<fds_subindex_t>();
inline constexpr std::size_t MAX_CHANNELS_MMC5 = enum_count<mmc5_subindex_t>(); // includes pcm
inline constexpr std::size_t MAX_CHANNELS_N163 = enum_count<n163_subindex_t>();
inline constexpr std::size_t MAX_CHANNELS_S5B = enum_count<s5b_subindex_t>();
inline constexpr std::size_t CHANID_COUNT =
MAX_CHANNELS_2A03 +
MAX_CHANNELS_VRC6 +
MAX_CHANNELS_VRC7 +
MAX_CHANNELS_FDS +
MAX_CHANNELS_MMC5 +
MAX_CHANNELS_N163 +
MAX_CHANNELS_S5B;
struct stChannelID { // // //
sound_chip_t Chip = sound_chip_t::none;
std::uint8_t Subindex = 0u;
std::uint8_t Ident = 0u;
constexpr stChannelID() noexcept = default;
constexpr stChannelID(sound_chip_t chip, std::uint8_t subindex) noexcept : Chip(chip), Subindex(subindex) { }
constexpr stChannelID(std::uint8_t id, sound_chip_t chip, std::uint8_t subindex) noexcept : Chip(chip), Subindex(subindex), Ident(id) { }
static constexpr stChannelID FromInteger(std::uint32_t x) noexcept {
return {
static_cast<std::uint8_t>(x & 0xFF),
enum_cast<sound_chip_t>(x >> 16),
static_cast<std::uint8_t>((x >> 8) & 0xFF),
};
}
constexpr std::uint32_t ToInteger() const noexcept {
return Ident | (Subindex << 8) | (value_cast(Chip) << 16);
}
constexpr stChannelID(apu_subindex_t subindex) noexcept : stChannelID(sound_chip_t::APU , value_cast(subindex)) { }
constexpr stChannelID(vrc6_subindex_t subindex) noexcept : stChannelID(sound_chip_t::VRC6, value_cast(subindex)) { }
constexpr stChannelID(vrc7_subindex_t subindex) noexcept : stChannelID(sound_chip_t::VRC7, value_cast(subindex)) { }
constexpr stChannelID(fds_subindex_t subindex) noexcept : stChannelID(sound_chip_t::FDS , value_cast(subindex)) { }
constexpr stChannelID(mmc5_subindex_t subindex) noexcept : stChannelID(sound_chip_t::MMC5, value_cast(subindex)) { }
constexpr stChannelID(n163_subindex_t subindex) noexcept : stChannelID(sound_chip_t::N163, value_cast(subindex)) { }
constexpr stChannelID(s5b_subindex_t subindex) noexcept : stChannelID(sound_chip_t::S5B , value_cast(subindex)) { }
constexpr int compare(const stChannelID &other) const noexcept {
if (Chip > other.Chip)
return 1;
if (Chip < other.Chip)
return -1;
if (Chip == sound_chip_t::none)
return 0;
if (Subindex > other.Subindex)
return 1;
if (Subindex < other.Subindex)
return -1;
if (Ident > other.Ident)
return 1;
if (Ident < other.Ident)
return -1;
return 0;
}
// constexpr std::strong_ordering operator<=>(const stChannelID &other) const noexcept = default;
};
ENABLE_STRONG_ORDERING(stChannelID);
constexpr bool IsAPUPulse(stChannelID id) noexcept {
return id.Chip == sound_chip_t::APU && (
id.Subindex == value_cast(apu_subindex_t::pulse1) || id.Subindex == value_cast(apu_subindex_t::pulse2));
}
constexpr bool IsAPUTriangle(stChannelID id) noexcept {
return id.Chip == sound_chip_t::APU && id.Subindex == value_cast(apu_subindex_t::triangle);
}
constexpr bool IsAPUNoise(stChannelID id) noexcept {
return id.Chip == sound_chip_t::APU && id.Subindex == value_cast(apu_subindex_t::noise);
}
constexpr bool IsDPCM(stChannelID id) noexcept {
return id.Chip == sound_chip_t::APU && id.Subindex == value_cast(apu_subindex_t::dpcm);
}
constexpr bool IsVRC6Sawtooth(stChannelID id) noexcept {
return id.Chip == sound_chip_t::VRC6 && id.Subindex == value_cast(vrc6_subindex_t::sawtooth);
}