mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Avoid hard-coding a redundant "FATAL:" in RGBFIX
This commit is contained in:
@@ -24,7 +24,7 @@ enum WarningID {
|
|||||||
|
|
||||||
extern Diagnostics<WarningLevel, WarningID> warnings;
|
extern Diagnostics<WarningLevel, WarningID> warnings;
|
||||||
|
|
||||||
// Warns the user about problems that don't prevent fixing the ROM
|
// Warns the user about problems that don't prevent fixing the ROM header
|
||||||
[[gnu::format(printf, 2, 3)]]
|
[[gnu::format(printf, 2, 3)]]
|
||||||
void warning(WarningID id, char const *fmt, ...);
|
void warning(WarningID id, char const *fmt, ...);
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ void warning(WarningID id, char const *fmt, ...);
|
|||||||
[[gnu::format(printf, 1, 2)]]
|
[[gnu::format(printf, 1, 2)]]
|
||||||
void error(char const *fmt, ...);
|
void error(char const *fmt, ...);
|
||||||
|
|
||||||
// Prints a fatal error and exits
|
// Prints an error, and exits with failure
|
||||||
[[gnu::format(printf, 1, 2)]]
|
[[gnu::format(printf, 1, 2), noreturn]]
|
||||||
void fatal(char const *fmt, ...);
|
void fatal(char const *fmt, ...);
|
||||||
|
|
||||||
uint32_t checkErrors(char const *filename);
|
uint32_t checkErrors(char const *filename);
|
||||||
|
|||||||
@@ -57,43 +57,29 @@ static std::unordered_map<MbcType, std::pair<char const *, bool>> mbcData{
|
|||||||
{TPP1_BATTERY_TIMER_MULTIRUMBLE_RUMBLE, {"TPP1+BATTERY+TIMER+MULTIRUMBLE", false}},
|
{TPP1_BATTERY_TIMER_MULTIRUMBLE_RUMBLE, {"TPP1+BATTERY+TIMER+MULTIRUMBLE", false}},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printAcceptedMbcNames(FILE *file) {
|
static char const *acceptedMBCNames =
|
||||||
fputs("Accepted MBC names:\n", file);
|
"Accepted MBC names:\n"
|
||||||
fputs("\tROM ($00) [aka ROM_ONLY]\n", file);
|
"\tROM ($00) [aka ROM_ONLY]\n"
|
||||||
fputs("\tMBC1 ($01), MBC1+RAM ($02), MBC1+RAM+BATTERY ($03)\n", file);
|
"\tMBC1 ($01), MBC1+RAM ($02), MBC1+RAM+BATTERY ($03)\n"
|
||||||
fputs("\tMBC2 ($05), MBC2+BATTERY ($06)\n", file);
|
"\tMBC2 ($05), MBC2+BATTERY ($06)\n"
|
||||||
fputs("\tROM+RAM ($08) [deprecated], ROM+RAM+BATTERY ($09) [deprecated]\n", file);
|
"\tROM+RAM ($08) [deprecated], ROM+RAM+BATTERY ($09) [deprecated]\n"
|
||||||
fputs("\tMMM01 ($0B), MMM01+RAM ($0C), MMM01+RAM+BATTERY ($0D)\n", file);
|
"\tMMM01 ($0B), MMM01+RAM ($0C), MMM01+RAM+BATTERY ($0D)\n"
|
||||||
fputs("\tMBC3+TIMER+BATTERY ($0F), MBC3+TIMER+RAM+BATTERY ($10)\n", file);
|
"\tMBC3+TIMER+BATTERY ($0F), MBC3+TIMER+RAM+BATTERY ($10)\n"
|
||||||
fputs("\tMBC3 ($11), MBC3+RAM ($12), MBC3+RAM+BATTERY ($13)\n", file);
|
"\tMBC3 ($11), MBC3+RAM ($12), MBC3+RAM+BATTERY ($13)\n"
|
||||||
fputs("\tMBC5 ($19), MBC5+RAM ($1A), MBC5+RAM+BATTERY ($1B)\n", file);
|
"\tMBC5 ($19), MBC5+RAM ($1A), MBC5+RAM+BATTERY ($1B)\n"
|
||||||
fputs("\tMBC5+RUMBLE ($1C), MBC5+RUMBLE+RAM ($1D), MBC5+RUMBLE+RAM+BATTERY ($1E)\n", file);
|
"\tMBC5+RUMBLE ($1C), MBC5+RUMBLE+RAM ($1D), MBC5+RUMBLE+RAM+BATTERY ($1E)\n"
|
||||||
fputs("\tMBC6 ($20)\n", file);
|
"\tMBC6 ($20)\n"
|
||||||
fputs("\tMBC7+SENSOR+RUMBLE+RAM+BATTERY ($22)\n", file);
|
"\tMBC7+SENSOR+RUMBLE+RAM+BATTERY ($22)\n"
|
||||||
fputs("\tPOCKET_CAMERA ($FC)\n", file);
|
"\tPOCKET_CAMERA ($FC)\n"
|
||||||
fputs("\tBANDAI_TAMA5 ($FD) [aka TAMA5]\n", file);
|
"\tBANDAI_TAMA5 ($FD) [aka TAMA5]\n"
|
||||||
fputs("\tHUC3 ($FE)\n", file);
|
"\tHUC3 ($FE)\n"
|
||||||
fputs("\tHUC1+RAM+BATTERY ($FF)\n", file);
|
"\tHUC1+RAM+BATTERY ($FF)\n"
|
||||||
|
"\n"
|
||||||
fputs("\n\tTPP1_1.0, TPP1_1.0+RUMBLE, TPP1_1.0+MULTIRUMBLE, TPP1_1.0+TIMER,\n", file);
|
"\tTPP1_1.0, TPP1_1.0+RUMBLE, TPP1_1.0+MULTIRUMBLE, TPP1_1.0+TIMER,\n"
|
||||||
fputs("\tTPP1_1.0+TIMER+RUMBLE, TPP1_1.0+TIMER+MULTIRUMBLE, TPP1_1.0+BATTERY,\n", file);
|
"\tTPP1_1.0+TIMER+RUMBLE, TPP1_1.0+TIMER+MULTIRUMBLE, TPP1_1.0+BATTERY,\n"
|
||||||
fputs("\tTPP1_1.0+BATTERY+RUMBLE, TPP1_1.0+BATTERY+MULTIRUMBLE,\n", file);
|
"\tTPP1_1.0+BATTERY+RUMBLE, TPP1_1.0+BATTERY+MULTIRUMBLE,\n"
|
||||||
fputs("\tTPP1_1.0+BATTERY+TIMER, TPP1_1.0+BATTERY+TIMER+RUMBLE,\n", file);
|
"\tTPP1_1.0+BATTERY+TIMER, TPP1_1.0+BATTERY+TIMER+RUMBLE,\n"
|
||||||
fputs("\tTPP1_1.0+BATTERY+TIMER+MULTIRUMBLE\n", file);
|
"\tTPP1_1.0+BATTERY+TIMER+MULTIRUMBLE"; // No trailing newline
|
||||||
}
|
|
||||||
|
|
||||||
[[gnu::format(printf, 1, 2), noreturn]]
|
|
||||||
static void fatalWithMBCNames(char const *fmt, ...) {
|
|
||||||
va_list ap;
|
|
||||||
fputs("FATAL: ", stderr);
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
putc('\n', stderr);
|
|
||||||
|
|
||||||
printAcceptedMbcNames(stderr);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
char const *mbc_Name(MbcType type) {
|
char const *mbc_Name(MbcType type) {
|
||||||
auto search = mbcData.find(type);
|
auto search = mbcData.find(type);
|
||||||
@@ -138,19 +124,19 @@ static bool readMBCSlice(char const *&name, char const *expected) {
|
|||||||
|
|
||||||
[[noreturn]]
|
[[noreturn]]
|
||||||
static void fatalUnknownMBC(char const *fullName) {
|
static void fatalUnknownMBC(char const *fullName) {
|
||||||
fatalWithMBCNames("Unknown MBC \"%s\"", fullName);
|
fatal("Unknown MBC \"%s\"\n%s", fullName, acceptedMBCNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]]
|
[[noreturn]]
|
||||||
static void fatalWrongMBCFeatures(char const *fullName) {
|
static void fatalWrongMBCFeatures(char const *fullName) {
|
||||||
fatalWithMBCNames("Features incompatible with MBC (\"%s\")", fullName);
|
fatal("Features incompatible with MBC (\"%s\")\n%s", fullName, acceptedMBCNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor) {
|
MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor) {
|
||||||
char const *fullName = name;
|
char const *fullName = name;
|
||||||
|
|
||||||
if (!strcasecmp(name, "help") || !strcasecmp(name, "list")) {
|
if (!strcasecmp(name, "help") || !strcasecmp(name, "list")) {
|
||||||
printAcceptedMbcNames(stdout);
|
puts(acceptedMBCNames); // Outputs to stdout and appends a newline
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user