21#define ATTR_PACKED __attribute__((packed))
37 using Fn = std::function<void()>;
44 ScopeGuard(Fn &&fn) : run(
true), exit_fn(fn) {}
52 inline void Cancel() {
59#define NTR_R_SUCCEED() return ::ntr::ResultSuccess
61#define NTR_R_FAIL(rc) { \
62 const auto _tmp_rc = (rc); \
66#define NTR_R_TRY(rc) { \
67 const auto _tmp_rc = (rc); \
68 if(_tmp_rc.IsFailure()) { \
80 static constexpr BaseType SuccessValue = BaseType();
82 constexpr Result() : value() {}
83 constexpr Result(
const BaseType val) : value(val) {}
85 inline constexpr bool IsSuccess()
const {
86 return this->value == SuccessValue;
89 inline constexpr bool IsFailure()
const {
90 return !this->IsSuccess();
93 inline std::string GetDescription()
const;
96 constexpr Result ResultSuccess = 0;
97 constexpr Result ResultUnknownResult = 0x0002;
99 constexpr Result ResultUnsupportedPixelFormat = 0x0101;
100 constexpr Result ResultInvalidSizeForPixelFormat = 0x0102;
101 constexpr Result ResultColorPaletteAllocationFailure = 0x0103;
102 constexpr Result ResultInvalidPixelFormat = 0x0104;
103 constexpr Result ResultInvalidCharacterFormat = 0x0105;
104 constexpr Result ResultInvalidScreenData = 0x0106;
105 constexpr Result ResultScreenDataGenerationUnimplemented = 0x0107;
106 constexpr Result ResultUnexpectedBannerIconDimensions = 0x0108;
108 constexpr Result ResultInvalidFile = 0x0201;
109 constexpr Result ResultEndOfData = 0x0202;
110 constexpr Result ResultReadNotSupported = 0x0203;
111 constexpr Result ResultWriteNotSupported = 0x0204;
112 constexpr Result ResultUnexpectedReadSize = 0x0205;
113 constexpr Result ResultFileNotCompressed = 0x0206;
114 constexpr Result ResultInvalidEndSeekOffset = 0x0207;
115 constexpr Result ResultInvalidFileOpenMode = 0x0208;
116 constexpr Result ResultUnableToOpenStdioFile = 0x0209;
117 constexpr Result ResultInvalidSeekPosition = 0x020a;
118 constexpr Result ResultUnableToSeekStdioFile = 0x020b;
119 constexpr Result ResultUnableToReadStdioFile = 0x020c;
120 constexpr Result ResultUnableToWriteStdioFile = 0x020d;
121 constexpr Result ResultUnableToCloseStdioFile = 0x020e;
122 constexpr Result ResultUnableToCreateStdioDirectory = 0x020f;
123 constexpr Result ResultUnableToDeleteStdioFile = 0x0210;
125 constexpr Result ResultNitroFsDirectoryNotFound = 0x0301;
126 constexpr Result ResultNitroFsFileNotFound = 0x0302;
128 constexpr Result ResultBMGInvalidHeader = 0x0401;
129 constexpr Result ResultBMGInvalidInfoSection = 0x0402;
130 constexpr Result ResultBMGInvalidDataSection = 0x0403;
131 constexpr Result ResultBMGInvalidUnsupportedEncoding = 0x0404;
132 constexpr Result ResultBMGInvalidMessageAttributeSize = 0x0405;
133 constexpr Result ResultBMGInvalidEscapeSequence = 0x0406;
134 constexpr Result ResultBMGUnexpectedSectionCount = 0x0407;
135 constexpr Result ResultBMGInvalidMessageIdSection = 0x0408;
137 constexpr Result ResultNCGRInvalidHeader = 0x0501;
138 constexpr Result ResultNCGRInvalidCharacterDataBlock = 0x0502;
139 constexpr Result ResultNCGRInvalidCharacterPositionBlock = 0x0503;
141 constexpr Result ResultNCLRInvalidHeader = 0x0601;
142 constexpr Result ResultNCLRInvalidPaletteDataBlock = 0x0602;
144 constexpr Result ResultNSCRInvalidHeader = 0x0701;
145 constexpr Result ResultNSCRInvalidScreenDataBlock = 0x0702;
146 constexpr Result ResultNSCRWriteNotSupported = 0x0703;
148 constexpr Result ResultNARCInvalidHeader = 0x0801;
149 constexpr Result ResultNARCInvalidFileAllocationTableBlock = 0x0802;
150 constexpr Result ResultNARCInvalidFileNameTableBlock = 0x0803;
151 constexpr Result ResultNARCInvalidFileImageBlock = 0x0804;
153 constexpr Result ResultSDATInvalidHeader = 0x0901;
154 constexpr Result ResultSDATInvalidSymbolBlock = 0x0902;
155 constexpr Result ResultSDATInvalidInfoBlock = 0x0903;
156 constexpr Result ResultSDATInvalidFileAllocationTableBlock = 0x0904;
157 constexpr Result ResultSDATInvalidFileBlock = 0x0905;
158 constexpr Result ResultSDATInvalidSymbols = 0x0906;
159 constexpr Result ResultSDATEntryNotFound = 0x0907;
160 constexpr Result ResultSDATInvalidEntryFormat = 0x0908;
162 constexpr Result ResultSSEQInvalidHeader = 0x0a01;
163 constexpr Result ResultSSEQInvalidDataSection = 0x0a02;
164 constexpr Result ResultSSEQWriteNotSupported = 0x0a03;
166 constexpr Result ResultSBNKInvalidHeader = 0x0b01;
167 constexpr Result ResultSBNKInvalidDataSection = 0x0b02;
168 constexpr Result ResultSBNKWriteNotSupported = 0x0b03;
170 constexpr Result ResultSWARInvalidHeader = 0x0c01;
171 constexpr Result ResultSWARInvalidDataSection = 0x0c02;
172 constexpr Result ResultSWARWriteNotSupported = 0x0c03;
174 constexpr Result ResultSTRMInvalidHeader = 0x0d01;
175 constexpr Result ResultSTRMInvalidHeadSection = 0x0d02;
176 constexpr Result ResultSTRMInvalidDataSection = 0x0d03;
177 constexpr Result ResultSTRMWriteNotSupported = 0x0d04;
179 constexpr Result ResultROMInvalidUnitCode = 0x0e01;
180 constexpr Result ResultROMInvalidNintendoLogoCRC16 = 0x0e02;
182 constexpr Result ResultCompressionInvalidLzFormat = 0x0f01;
183 constexpr Result ResultCompressionTooBigCompressSize = 0x0f02;
184 constexpr Result ResultCompressionInvalidRepeatSize = 0x0f03;
186 constexpr Result ResultUtilityInvalidSections = 0x1001;
188 using ResultDescriptionEntry = std::pair<Result, const char*>;
190 constexpr ResultDescriptionEntry ResultDescriptionTable[] = {
191 { ResultSuccess,
"Success" },
192 { ResultUnknownResult,
"Unknown result value" },
194 { ResultUnsupportedPixelFormat,
"Unsupported pixel format" },
195 { ResultInvalidSizeForPixelFormat,
"Invalid size for given pixel format" },
196 { ResultColorPaletteAllocationFailure,
"Unable to allocate color in palette" },
197 { ResultInvalidPixelFormat,
"Invalid pixel format" },
198 { ResultInvalidCharacterFormat,
"Invalid (graphics) character format" },
199 { ResultInvalidScreenData,
"Invalid screen (NSCR) data" },
200 { ResultScreenDataGenerationUnimplemented,
"Unimplemented feature: screen data saving/generation" },
201 { ResultUnexpectedBannerIconDimensions,
"Unexpected banner icon dimensions" },
203 { ResultInvalidFile,
"Invalid file" },
204 { ResultEndOfData,
"End of data (EOF)" },
205 { ResultReadNotSupported,
"Read not supported in file" },
206 { ResultWriteNotSupported,
"Write not supported in file" },
207 { ResultUnexpectedReadSize,
"Got unexpected read size" },
208 { ResultFileNotCompressed,
"File is not compressed" },
209 { ResultInvalidEndSeekOffset,
"Invalid offset for end seeking (must be 0)" },
210 { ResultInvalidFileOpenMode,
"Invalid file open mode" },
211 { ResultUnableToOpenStdioFile,
"Unable to open stdio file" },
212 { ResultInvalidSeekPosition,
"Invalid seek position" },
213 { ResultUnableToSeekStdioFile,
"Unable to seek stdio file" },
214 { ResultUnableToReadStdioFile,
"Unable to read stdio file" },
215 { ResultUnableToWriteStdioFile,
"Unable to write stdio file" },
216 { ResultUnableToCloseStdioFile,
"Unable to close stdio file" },
217 { ResultUnableToCreateStdioDirectory,
"Unable to create stdio directory" },
218 { ResultUnableToDeleteStdioFile,
"Unable to delete stdio file" },
220 { ResultNitroFsDirectoryNotFound,
"NitroFs directory not found" },
221 { ResultNitroFsFileNotFound,
"NitroFs file not found" },
223 { ResultBMGInvalidHeader,
"Invalid BMG header" },
224 { ResultBMGInvalidInfoSection,
"Invalid BMG INF1 section" },
225 { ResultBMGInvalidDataSection,
"Invalid BMG DAT1 section" },
226 { ResultBMGInvalidUnsupportedEncoding,
"Invalid or unsupported BMG encoding" },
227 { ResultBMGInvalidMessageAttributeSize,
"Invalid BMG message attribute size" },
228 { ResultBMGInvalidEscapeSequence,
"Invalid BMG escape sequence" },
229 { ResultBMGUnexpectedSectionCount,
"Unexpected BMG section count (< 2)" },
230 { ResultBMGInvalidMessageIdSection,
"Invalid BMG MID1 section" },
232 { ResultNCGRInvalidHeader,
"Invalid NCGR header" },
233 { ResultNCGRInvalidCharacterDataBlock,
"Invalid NCGR character data block" },
234 { ResultNCGRInvalidCharacterPositionBlock,
"Invalid NCGR character position block" },
236 { ResultNCLRInvalidHeader,
"Invalid NCLR header" },
237 { ResultNCLRInvalidPaletteDataBlock,
"Invalid NCGR palette data block" },
239 { ResultNSCRInvalidHeader,
"Invalid NSCR header" },
240 { ResultNSCRInvalidScreenDataBlock,
"Invalid NSCR screen data block" },
241 { ResultNSCRWriteNotSupported,
"Unsupported feature: writing to NSCR" },
243 { ResultNARCInvalidHeader,
"Invalid NARC header" },
244 { ResultNARCInvalidFileAllocationTableBlock,
"Invalid NARC file allocation table block" },
245 { ResultNARCInvalidFileNameTableBlock,
"Invalid NARC file name table block" },
246 { ResultNARCInvalidFileImageBlock,
"Invalid NARC file image block" },
248 { ResultSDATInvalidHeader,
"Invalid SDAT header" },
249 { ResultSDATInvalidSymbolBlock,
"Invalid SDAT symbol block" },
250 { ResultSDATInvalidInfoBlock,
"Invalid SDAT info block" },
251 { ResultSDATInvalidFileAllocationTableBlock,
"Invalid SDAT file allocation table block" },
252 { ResultSDATInvalidFileBlock,
"Invalid SDAT file block" },
253 { ResultSDATInvalidSymbols,
"Invalid SDAT symbols" },
254 { ResultSDATEntryNotFound,
"SDAT entry not found" },
255 { ResultSDATInvalidEntryFormat,
"Invalid SDAT entry format" },
257 { ResultSSEQInvalidHeader,
"Invalid SSEQ header" },
258 { ResultSSEQInvalidDataSection,
"Invalid SSEQ data section" },
259 { ResultSSEQWriteNotSupported,
"Unsupported feature: writing to SSEQ" },
261 { ResultSBNKInvalidHeader,
"Invalid SBNK header" },
262 { ResultSBNKInvalidDataSection,
"Invalid SBNK data section" },
263 { ResultSBNKWriteNotSupported,
"Unsupported feature: writing to SBNK" },
265 { ResultSWARInvalidHeader,
"Invalid SWAR header" },
266 { ResultSWARInvalidDataSection,
"Invalid SWAR data section" },
267 { ResultSWARWriteNotSupported,
"Unsupported feature: writing to SWAR" },
269 { ResultSTRMInvalidHeader,
"Invalid STRM header" },
270 { ResultSTRMInvalidHeadSection,
"Invalid STRM head section" },
271 { ResultSTRMInvalidDataSection,
"Invalid STRM data section" },
272 { ResultSTRMWriteNotSupported,
"Unsupported feature: writing to STRM" },
274 { ResultUtilityInvalidSections,
"Invalid DWC utility sections" }
277 inline constexpr Result GetResultDescription(
const Result rc, std::string &out_desc) {
278 for(u32 i = 0; i < std::size(ResultDescriptionTable); i++) {
279 if(ResultDescriptionTable[i].first.value == rc.value) {
280 out_desc = ResultDescriptionTable[i].second;
285 NTR_R_FAIL(ResultUnknownResult);
288 inline std::string Result::GetDescription()
const {
289 std::string desc =
"<unknown result: " + std::to_string(this->value) +
">";
290 GetResultDescription(*
this, desc);
296inline constexpr size_t operator ""_KB(
unsigned long long n) {
300inline constexpr size_t operator ""_MB(
unsigned long long n) {
301 return operator ""_KB(n) * 0x400;
304inline constexpr size_t operator ""_GB(
unsigned long long n) {
305 return operator ""_MB(n) * 0x400;
308#define NTR_ENUM_BIT_OPERATORS(enum_type, base_type) \
309inline constexpr enum_type operator|(enum_type lhs, enum_type rhs) { \
310 return static_cast<enum_type>(static_cast<base_type>(lhs) | static_cast<base_type>(rhs)); \
312inline constexpr enum_type operator&(enum_type lhs, enum_type rhs) { \
313 return static_cast<enum_type>(static_cast<base_type>(lhs) & static_cast<base_type>(rhs)); \
316#define NTR_BITMASK(n) (1 << n)
Definition ntr_Include.hpp:35
Definition ntr_Include.hpp:75