mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Parse base tile IDs
This commit is contained in:
@@ -187,8 +187,8 @@ static uint16_t parseNumber(char *&string, char const *errPrefix) {
|
|||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (charIndex(*string) == -1) {
|
if (charIndex(*string) == (uint8_t)-1) {
|
||||||
error("%s: expected number after base, but found nothing", errPrefix);
|
error("%s: expected digit%s, but found nothing", errPrefix, base != 10 ? " after base" : "");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uint16_t number = 0;
|
uint16_t number = 0;
|
||||||
@@ -196,7 +196,7 @@ static uint16_t parseNumber(char *&string, char const *errPrefix) {
|
|||||||
// Read a character, and check if it's valid in the given base
|
// Read a character, and check if it's valid in the given base
|
||||||
number *= base;
|
number *= base;
|
||||||
uint8_t index = charIndex(*string);
|
uint8_t index = charIndex(*string);
|
||||||
if (index == -1) {
|
if (index == (uint8_t)-1) {
|
||||||
break; // Found an invalid character, end
|
break; // Found an invalid character, end
|
||||||
}
|
}
|
||||||
++string;
|
++string;
|
||||||
@@ -212,7 +212,11 @@ static uint16_t parseNumber(char *&string, char const *errPrefix) {
|
|||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parsePaletteSpec(char *arg) {
|
static void skipWhitespace(char *&arg) {
|
||||||
|
arg += strcspn(arg, " \t");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void parsePaletteSpec(char const *arg) {
|
||||||
if (arg[0] == '#') {
|
if (arg[0] == '#') {
|
||||||
// List of #rrggbb/#rgb colors, comma-separated, palettes are separated by colons
|
// List of #rrggbb/#rgb colors, comma-separated, palettes are separated by colons
|
||||||
options.palSpecType = Options::EXPLICIT;
|
options.palSpecType = Options::EXPLICIT;
|
||||||
@@ -243,7 +247,30 @@ int main(int argc, char *argv[]) {
|
|||||||
options.attrmap = musl_optarg;
|
options.attrmap = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
options.baseTileIDs = {0, 0}; // TODO
|
options.baseTileIDs[0] = parseNumber(arg, "Bank 0 base tile ID");
|
||||||
|
if (options.baseTileIDs[0] >= 256) {
|
||||||
|
error("Bank 0 base tile ID must be below 256");
|
||||||
|
}
|
||||||
|
if (*arg == '\0') {
|
||||||
|
options.baseTileIDs[1] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
skipWhitespace(arg);
|
||||||
|
if (*arg != ',') {
|
||||||
|
error("Base tile IDs must be one or two comma-separated numbers, not \"%s\"",
|
||||||
|
musl_optarg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
skipWhitespace(arg);
|
||||||
|
options.baseTileIDs[1] = parseNumber(arg, "Bank 1 base tile ID");
|
||||||
|
if (options.baseTileIDs[1] >= 256) {
|
||||||
|
error("Bank 1 base tile ID must be below 256");
|
||||||
|
}
|
||||||
|
if (*arg != '\0') {
|
||||||
|
error("Base tile IDs must be one or two comma-separated numbers, not \"%s\"",
|
||||||
|
musl_optarg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
options.useColorCurve = true;
|
options.useColorCurve = true;
|
||||||
@@ -257,7 +284,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case 'd':
|
case 'd':
|
||||||
options.bitDepth = parseNumber(arg, "Bit depth");
|
options.bitDepth = parseNumber(arg, "Bit depth");
|
||||||
if (*arg != '\0') {
|
if (*arg != '\0') {
|
||||||
error("Bit depth (-b) argument must be a valid number, not %s", musl_optarg);
|
error("Bit depth (-b) argument must be a valid number, not \"%s\"", musl_optarg);
|
||||||
} else if (options.bitDepth != -1 && options.bitDepth != 1 && options.bitDepth != 2) {
|
} else if (options.bitDepth != -1 && options.bitDepth != 1 && options.bitDepth != 2) {
|
||||||
error("Bit depth must be 1 or 2, not %" PRIu8);
|
error("Bit depth must be 1 or 2, not %" PRIu8);
|
||||||
options.bitDepth = 2;
|
options.bitDepth = 2;
|
||||||
@@ -295,7 +322,10 @@ int main(int argc, char *argv[]) {
|
|||||||
options.palettes = musl_optarg;
|
options.palettes = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
options.nbColorsPerPal = 0; // TODO
|
options.nbColorsPerPal = parseNumber(arg, "Number of colors per palette");
|
||||||
|
if (*arg != '\0') {
|
||||||
|
error("Palette size (-s) argument must be a valid number, not \"%s\"", musl_optarg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
autoTilemap = true;
|
autoTilemap = true;
|
||||||
@@ -315,7 +345,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case 'x':
|
case 'x':
|
||||||
options.trim = parseNumber(arg, "Number of tiles to trim");
|
options.trim = parseNumber(arg, "Number of tiles to trim");
|
||||||
if (*arg != '\0') {
|
if (*arg != '\0') {
|
||||||
error("Tile trim (-x) argument must be a valid number, not %s", musl_optarg);
|
error("Tile trim (-x) argument must be a valid number, not \"%s\"", musl_optarg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -331,7 +361,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.nbColorsPerPal == 0) {
|
if (options.nbColorsPerPal == 0) {
|
||||||
options.nbColorsPerPal = 1 << options.bitDepth;
|
options.nbColorsPerPal = 1u << options.bitDepth;
|
||||||
} else if (options.nbColorsPerPal > 1u << options.bitDepth) {
|
} else if (options.nbColorsPerPal > 1u << options.bitDepth) {
|
||||||
error("%" PRIu8 "bpp palettes can only contain %u colors, not %" PRIu8, options.bitDepth,
|
error("%" PRIu8 "bpp palettes can only contain %u colors, not %" PRIu8, options.bitDepth,
|
||||||
1u << options.bitDepth, options.nbColorsPerPal);
|
1u << options.bitDepth, options.nbColorsPerPal);
|
||||||
|
|||||||
Reference in New Issue
Block a user