diff --git a/include/linkdefs.h b/include/linkdefs.h index fa33b636..f917ad81 100644 --- a/include/linkdefs.h +++ b/include/linkdefs.h @@ -14,6 +14,7 @@ #define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu" #define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)9 +#define RGBDS_OBJECT_REV 0 enum RPNCommand { RPN_ADD = 0x00, diff --git a/src/asm/output.c b/src/asm/output.c index 80833db1..e1839d08 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -542,6 +542,7 @@ void out_WriteObject(void) fatalerror("Couldn't write file '%s'\n", tzObjectname); fprintf(f, RGBDS_OBJECT_VERSION_STRING, RGBDS_OBJECT_VERSION_NUMBER); + fputlong(RGBDS_OBJECT_REV, f); fputlong(countsymbols(), f); fputlong(countsections(), f); diff --git a/src/link/object.c b/src/link/object.c index 82c8f099..01f520c7 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -340,6 +340,14 @@ static void linkSymToSect(struct Symbol const *symbol, struct Section *section) */ static void readRGB7File(FILE *file, char const *fileName) { + uint32_t revNum; + + tryReadlong(revNum, file, "%s: Cannot read revision number: %s", + fileName); + if (revNum != RGBDS_OBJECT_REV) + errx(1, "%s is a revision 0x%04x object file, only 0x%04x is supported", + fileName, revNum, RGBDS_OBJECT_REV); + uint32_t nbSymbols; uint32_t nbSections; @@ -434,10 +442,8 @@ void obj_ReadFile(char const *fileName) { FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin; - if (!file) { + if (!file) err(1, "Could not open file %s", fileName); - return; - } /* Begin by reading the magic bytes and version number */ uint8_t versionNumber; @@ -450,7 +456,7 @@ void obj_ReadFile(char const *fileName) verbosePrint("Reading object file %s, version %hhu\n", fileName, versionNumber); - if (versionNumber != 7) + if (versionNumber != RGBDS_OBJECT_VERSION_NUMBER) errx(1, "\"%s\" is an incompatible version %hhu object file", fileName, versionNumber);