mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Make object file magic string a common define
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
6
include/common.h
Normal file
6
include/common.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef RGBDS_COMMON_H
|
||||||
|
#define RGBDS_COMMON_H
|
||||||
|
|
||||||
|
#define RGBDS_OBJECT_VERSION_STRING "RGB5"
|
||||||
|
|
||||||
|
#endif /* RGBDS_COMMON_H */
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/fstack.h"
|
#include "asm/fstack.h"
|
||||||
|
#include "common.h"
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
|
||||||
void out_SetCurrentSection(struct Section * pSect);
|
void out_SetCurrentSection(struct Section * pSect);
|
||||||
@@ -504,7 +505,9 @@ out_WriteObject(void)
|
|||||||
struct PatchSymbol *pSym;
|
struct PatchSymbol *pSym;
|
||||||
struct Section *pSect;
|
struct Section *pSect;
|
||||||
|
|
||||||
fwrite("RGB5", 1, 4, f);
|
fwrite(RGBDS_OBJECT_VERSION_STRING, 1,
|
||||||
|
strlen(RGBDS_OBJECT_VERSION_STRING), f);
|
||||||
|
|
||||||
fputlong(countsymbols(), f);
|
fputlong(countsymbols(), f);
|
||||||
fputlong(countsections(), f);
|
fputlong(countsections(), f);
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
#include "link/assign.h"
|
#include "link/assign.h"
|
||||||
#include "link/mylink.h"
|
#include "link/mylink.h"
|
||||||
@@ -332,20 +334,22 @@ obj_ReadRGB(FILE * pObjfile, char *tzObjectfile)
|
|||||||
void
|
void
|
||||||
obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
||||||
{
|
{
|
||||||
char tzHeader[8];
|
char tzHeader[strlen(RGBDS_OBJECT_VERSION_STRING) + 1];
|
||||||
|
|
||||||
fread(tzHeader, sizeof(char), 4, pObjfile);
|
fread(tzHeader, sizeof(char), strlen(RGBDS_OBJECT_VERSION_STRING),
|
||||||
tzHeader[4] = 0;
|
pObjfile);
|
||||||
if (strncmp(tzHeader, "RGB", 3) == 0) {
|
|
||||||
switch (tzHeader[3]) {
|
tzHeader[strlen(RGBDS_OBJECT_VERSION_STRING)] = 0;
|
||||||
case '5':
|
|
||||||
|
if (strncmp(tzHeader, RGBDS_OBJECT_VERSION_STRING,
|
||||||
|
strlen(RGBDS_OBJECT_VERSION_STRING)) == 0) {
|
||||||
obj_ReadRGB(pObjfile, tzObjectfile);
|
obj_ReadRGB(pObjfile, tzObjectfile);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errx(1, "'%s' uses an unsupported object file version (%s). Please reassemble it.", tzObjectfile, tzHeader);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
errx(1, "'%s' is not a valid object", tzObjectfile);
|
for (int i = 0; i < strlen(RGBDS_OBJECT_VERSION_STRING); i++)
|
||||||
|
if (!isprint(tzHeader[i]))
|
||||||
|
tzHeader[i] = '?';
|
||||||
|
errx(1, "%s: Invalid file or object file version [%s]",
|
||||||
|
tzObjectfile, tzHeader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user