mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Store patch file line in the file name
It's more consistent with how it's stored for all other entries in the stack
This commit is contained in:
@@ -26,7 +26,6 @@ struct AttachedSymbol {
|
|||||||
|
|
||||||
struct Patch {
|
struct Patch {
|
||||||
char *fileName;
|
char *fileName;
|
||||||
int32_t lineNo;
|
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
enum PatchType type;
|
enum PatchType type;
|
||||||
int32_t rpnSize;
|
int32_t rpnSize;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu"
|
#define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu"
|
||||||
#define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)9
|
#define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)9
|
||||||
#define RGBDS_OBJECT_REV 0
|
#define RGBDS_OBJECT_REV 1
|
||||||
|
|
||||||
enum RPNCommand {
|
enum RPNCommand {
|
||||||
RPN_ADD = 0x00,
|
RPN_ADD = 0x00,
|
||||||
|
|||||||
@@ -281,7 +281,8 @@ void fstk_DumpToStr(char *buf, size_t buflen)
|
|||||||
pLastFile = pLastFile->pNext;
|
pLastFile = pLastFile->pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
retcode = snprintf(&buf[buflen - len], len, "%s", tzCurrentFileName);
|
retcode = snprintf(&buf[buflen - len], len, "%s(%d)", tzCurrentFileName,
|
||||||
|
nLineNo);
|
||||||
if (retcode < 0)
|
if (retcode < 0)
|
||||||
fatalerror("Failed to dump file stack to string: %s",
|
fatalerror("Failed to dump file stack to string: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
struct Patch {
|
struct Patch {
|
||||||
char tzFilename[_MAX_PATH + 1];
|
char tzFilename[_MAX_PATH + 1];
|
||||||
uint32_t nLine;
|
|
||||||
uint32_t nOffset;
|
uint32_t nOffset;
|
||||||
uint8_t nType;
|
uint8_t nType;
|
||||||
uint32_t nRPNSize;
|
uint32_t nRPNSize;
|
||||||
@@ -152,7 +151,6 @@ static uint32_t getsectid(struct Section *pSect)
|
|||||||
static void writepatch(struct Patch *pPatch, FILE *f)
|
static void writepatch(struct Patch *pPatch, FILE *f)
|
||||||
{
|
{
|
||||||
fputstring(pPatch->tzFilename, f);
|
fputstring(pPatch->tzFilename, f);
|
||||||
fputlong(pPatch->nLine, f);
|
|
||||||
fputlong(pPatch->nOffset, f);
|
fputlong(pPatch->nOffset, f);
|
||||||
fputc(pPatch->nType, f);
|
fputc(pPatch->nType, f);
|
||||||
fputlong(pPatch->nRPNSize, f);
|
fputlong(pPatch->nRPNSize, f);
|
||||||
@@ -328,7 +326,6 @@ void out_CreatePatch(uint32_t type, struct Expression *expr)
|
|||||||
pPatch = allocpatch();
|
pPatch = allocpatch();
|
||||||
pPatch->nType = type;
|
pPatch->nType = type;
|
||||||
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
|
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
|
||||||
pPatch->nLine = nLineNo;
|
|
||||||
pPatch->nOffset = pCurrentSection->nPC;
|
pPatch->nOffset = pCurrentSection->nPC;
|
||||||
|
|
||||||
while ((rpndata = rpn_PopByte(expr)) != 0xDEAD) {
|
while ((rpndata = rpn_PopByte(expr)) != 0xDEAD) {
|
||||||
|
|||||||
@@ -209,9 +209,6 @@ static void readPatch(FILE *file, struct Patch *patch,
|
|||||||
tryReadstr(patch->fileName, file,
|
tryReadstr(patch->fileName, file,
|
||||||
"%s: Unable to read \"%s\"'s patch #%u's name: %s",
|
"%s: Unable to read \"%s\"'s patch #%u's name: %s",
|
||||||
fileName, sectName, i);
|
fileName, sectName, i);
|
||||||
tryReadlong(patch->lineNo, file,
|
|
||||||
"%s: Unable to read \"%s\"'s patch #%u's line number: %s",
|
|
||||||
fileName, sectName, i);
|
|
||||||
tryReadlong(patch->offset, file,
|
tryReadlong(patch->offset, file,
|
||||||
"%s: Unable to read \"%s\"'s patch #%u's offset: %s",
|
"%s: Unable to read \"%s\"'s patch #%u's offset: %s",
|
||||||
fileName, sectName, i);
|
fileName, sectName, i);
|
||||||
|
|||||||
@@ -93,11 +93,10 @@ static void pushRPN(int32_t value)
|
|||||||
stack.size++;
|
stack.size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t popRPN(char const *fileName, int32_t lineNo)
|
static int32_t popRPN(char const *fileName)
|
||||||
{
|
{
|
||||||
if (stack.size == 0)
|
if (stack.size == 0)
|
||||||
errx(1, "%s(%d): Internal error, RPN stack empty", fileName,
|
errx(1, "%s: Internal error, RPN stack empty", fileName);
|
||||||
lineNo);
|
|
||||||
|
|
||||||
stack.size--;
|
stack.size--;
|
||||||
return stack.buf[stack.size];
|
return stack.buf[stack.size];
|
||||||
@@ -111,10 +110,10 @@ static inline void freeRPNStack(void)
|
|||||||
/* RPN operators */
|
/* RPN operators */
|
||||||
|
|
||||||
static uint32_t getRPNByte(uint8_t const **expression, int32_t *size,
|
static uint32_t getRPNByte(uint8_t const **expression, int32_t *size,
|
||||||
char const *fileName, int32_t lineNo)
|
char const *fileName)
|
||||||
{
|
{
|
||||||
if (!(*size)--)
|
if (!(*size)--)
|
||||||
errx(1, "%s(%d): RPN expression overread", fileName, lineNo);
|
errx(1, "%s: RPN expression overread", fileName);
|
||||||
return *(*expression)++;
|
return *(*expression)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +127,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
struct Section const *section)
|
struct Section const *section)
|
||||||
{
|
{
|
||||||
/* Small shortcut to avoid a lot of repetition */
|
/* Small shortcut to avoid a lot of repetition */
|
||||||
#define popRPN() popRPN(patch->fileName, patch->lineNo)
|
#define popRPN() popRPN(patch->fileName)
|
||||||
|
|
||||||
uint8_t const *expression = patch->rpnExpression;
|
uint8_t const *expression = patch->rpnExpression;
|
||||||
int32_t size = patch->rpnSize;
|
int32_t size = patch->rpnSize;
|
||||||
@@ -137,8 +136,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
enum RPNCommand command = getRPNByte(&expression, &size,
|
enum RPNCommand command = getRPNByte(&expression, &size,
|
||||||
patch->fileName,
|
patch->fileName);
|
||||||
patch->lineNo);
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -236,8 +234,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
value = 0;
|
value = 0;
|
||||||
for (uint8_t shift = 0; shift < 32; shift += 8)
|
for (uint8_t shift = 0; shift < 32; shift += 8)
|
||||||
value |= getRPNByte(&expression, &size,
|
value |= getRPNByte(&expression, &size,
|
||||||
patch->fileName,
|
patch->fileName) << shift;
|
||||||
patch->lineNo) << shift;
|
|
||||||
|
|
||||||
symbol = section->fileSymbols[value];
|
symbol = section->fileSymbols[value];
|
||||||
|
|
||||||
@@ -247,8 +244,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
sym_GetSymbol(symbol->name);
|
sym_GetSymbol(symbol->name);
|
||||||
if (!symbolDefinition)
|
if (!symbolDefinition)
|
||||||
errx(1, "%s(%d): Unknown symbol \"%s\"",
|
errx(1, "%s(%d): Unknown symbol \"%s\"",
|
||||||
patch->fileName, patch->lineNo,
|
patch->fileName, symbol->name);
|
||||||
symbol->name);
|
|
||||||
symbol = symbolDefinition;
|
symbol = symbolDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,15 +253,14 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
|
|
||||||
case RPN_BANK_SECT:
|
case RPN_BANK_SECT:
|
||||||
name = (char const *)expression;
|
name = (char const *)expression;
|
||||||
while (getRPNByte(&expression, &size, patch->fileName,
|
while (getRPNByte(&expression, &size, patch->fileName))
|
||||||
patch->lineNo))
|
|
||||||
;
|
;
|
||||||
|
|
||||||
sect = sect_GetSection(name);
|
sect = sect_GetSection(name);
|
||||||
|
|
||||||
if (!sect)
|
if (!sect)
|
||||||
errx(1, "%s(%d): Requested BANK() of section \"%s\", which was not found",
|
errx(1, "%s: Requested BANK() of section \"%s\", which was not found",
|
||||||
patch->fileName, patch->lineNo, name);
|
patch->fileName, name);
|
||||||
|
|
||||||
value = sect->bank;
|
value = sect->bank;
|
||||||
break;
|
break;
|
||||||
@@ -279,8 +274,8 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
if (value < 0
|
if (value < 0
|
||||||
|| (value > 0xFF && value < 0xFF00)
|
|| (value > 0xFF && value < 0xFF00)
|
||||||
|| value > 0xFFFF)
|
|| value > 0xFFFF)
|
||||||
errx(1, "%s(%d): Value %d is not in HRAM range",
|
errx(1, "%s: Value %d is not in HRAM range",
|
||||||
patch->fileName, patch->lineNo, value);
|
patch->fileName, value);
|
||||||
value &= 0xFF;
|
value &= 0xFF;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -290,8 +285,8 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
* They can be easily checked with a bitmask
|
* They can be easily checked with a bitmask
|
||||||
*/
|
*/
|
||||||
if (value & ~0x38)
|
if (value & ~0x38)
|
||||||
errx(1, "%s(%d): Value %d is not a RST vector",
|
errx(1, "%s: Value %d is not a RST vector",
|
||||||
patch->fileName, patch->lineNo, value);
|
patch->fileName, value);
|
||||||
value |= 0xC7;
|
value |= 0xC7;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -299,16 +294,14 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
value = 0;
|
value = 0;
|
||||||
for (uint8_t shift = 0; shift < 32; shift += 8)
|
for (uint8_t shift = 0; shift < 32; shift += 8)
|
||||||
value |= getRPNByte(&expression, &size,
|
value |= getRPNByte(&expression, &size,
|
||||||
patch->fileName,
|
patch->fileName) << shift;
|
||||||
patch->lineNo) << shift;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RPN_SYM:
|
case RPN_SYM:
|
||||||
value = 0;
|
value = 0;
|
||||||
for (uint8_t shift = 0; shift < 32; shift += 8)
|
for (uint8_t shift = 0; shift < 32; shift += 8)
|
||||||
value |= getRPNByte(&expression, &size,
|
value |= getRPNByte(&expression, &size,
|
||||||
patch->fileName,
|
patch->fileName) << shift;
|
||||||
patch->lineNo) << shift;
|
|
||||||
|
|
||||||
symbol = section->fileSymbols[value];
|
symbol = section->fileSymbols[value];
|
||||||
|
|
||||||
@@ -317,9 +310,8 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
struct Symbol const *symbolDefinition =
|
struct Symbol const *symbolDefinition =
|
||||||
sym_GetSymbol(symbol->name);
|
sym_GetSymbol(symbol->name);
|
||||||
if (!symbolDefinition)
|
if (!symbolDefinition)
|
||||||
errx(1, "%s(%d): Unknown symbol \"%s\"",
|
errx(1, "%s: Unknown symbol \"%s\"",
|
||||||
patch->fileName, patch->lineNo,
|
patch->fileName, symbol->name);
|
||||||
symbol->name);
|
|
||||||
symbol = symbolDefinition;
|
symbol = symbolDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,8 +330,8 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stack.size > 1)
|
if (stack.size > 1)
|
||||||
warnx("%s(%d): RPN stack has %lu entries on exit, not 1",
|
warnx("%s: RPN stack has %lu entries on exit, not 1",
|
||||||
patch->fileName, patch->lineNo, stack.size);
|
patch->fileName, stack.size);
|
||||||
|
|
||||||
return popRPN();
|
return popRPN();
|
||||||
|
|
||||||
@@ -370,8 +362,8 @@ static void applyPatches(struct Section *section, void *arg)
|
|||||||
int16_t offset = value - address;
|
int16_t offset = value - address;
|
||||||
|
|
||||||
if (offset < -128 || offset > 127)
|
if (offset < -128 || offset > 127)
|
||||||
errx(1, "%s(%d): jr target out of reach (expected -129 < %d < 128)",
|
errx(1, "%s: jr target out of reach (expected -129 < %d < 128)",
|
||||||
patch->fileName, patch->lineNo, offset);
|
patch->fileName, offset);
|
||||||
section->data[patch->offset] = offset & 0xFF;
|
section->data[patch->offset] = offset & 0xFF;
|
||||||
} else {
|
} else {
|
||||||
/* Patch a certain number of bytes */
|
/* Patch a certain number of bytes */
|
||||||
@@ -387,8 +379,8 @@ static void applyPatches(struct Section *section, void *arg)
|
|||||||
|
|
||||||
if (value < types[patch->type].min
|
if (value < types[patch->type].min
|
||||||
|| value > types[patch->type].max)
|
|| value > types[patch->type].max)
|
||||||
errx(1, "%s(%d): Value %#x%s is not %u-bit",
|
errx(1, "%s: Value %#x%s is not %u-bit",
|
||||||
patch->fileName, patch->lineNo, value,
|
patch->fileName, value,
|
||||||
value < 0 ? " (maybe negative?)" : "",
|
value < 0 ? " (maybe negative?)" : "",
|
||||||
types[patch->type].size * 8);
|
types[patch->type].size * 8);
|
||||||
for (uint8_t i = 0; i < types[patch->type].size; i++) {
|
for (uint8_t i = 0; i < types[patch->type].size; i++) {
|
||||||
|
|||||||
@@ -106,8 +106,6 @@ REPT NumberOfSections
|
|||||||
STRING SourceFile ; Name of the source file (for printing error
|
STRING SourceFile ; Name of the source file (for printing error
|
||||||
; messages).
|
; messages).
|
||||||
|
|
||||||
LONG Line ; The line of the source file.
|
|
||||||
|
|
||||||
LONG Offset ; Offset into the section where patch should
|
LONG Offset ; Offset into the section where patch should
|
||||||
; be applied (in bytes).
|
; be applied (in bytes).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user