ref: ef2bfe4ea0cd6d91edc9baec999506721d28439c
parent: 14731c0a1dc7f4e0154a46e823dfca7c1ea2b522
author: ISSOtm <[email protected]>
date: Wed Feb 19 04:51:40 EST 2020
Store patch file line in the file name It's more consistent with how it's stored for all other entries in the stack
--- a/include/link/section.h
+++ b/include/link/section.h
@@ -26,7 +26,6 @@
struct Patch {
char *fileName;
- int32_t lineNo;
int32_t offset;
enum PatchType type;
int32_t rpnSize;
--- a/include/linkdefs.h
+++ b/include/linkdefs.h
@@ -14,7 +14,7 @@
#define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu"
#define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)9
-#define RGBDS_OBJECT_REV 0
+#define RGBDS_OBJECT_REV 1
enum RPNCommand {
RPN_ADD = 0x00,
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -281,7 +281,8 @@
pLastFile = pLastFile->pNext;
}
- retcode = snprintf(&buf[buflen - len], len, "%s", tzCurrentFileName);
+ retcode = snprintf(&buf[buflen - len], len, "%s(%d)", tzCurrentFileName,
+ nLineNo);
if (retcode < 0)
fatalerror("Failed to dump file stack to string: %s",
strerror(errno));
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -33,7 +33,6 @@
struct Patch {
char tzFilename[_MAX_PATH + 1];
- uint32_t nLine;
uint32_t nOffset;
uint8_t nType;
uint32_t nRPNSize;
@@ -152,7 +151,6 @@
static void writepatch(struct Patch *pPatch, FILE *f)
{
fputstring(pPatch->tzFilename, f);
- fputlong(pPatch->nLine, f);
fputlong(pPatch->nOffset, f);
fputc(pPatch->nType, f);
fputlong(pPatch->nRPNSize, f);
@@ -328,7 +326,6 @@
pPatch = allocpatch();
pPatch->nType = type;
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
- pPatch->nLine = nLineNo;
pPatch->nOffset = pCurrentSection->nPC;
while ((rpndata = rpn_PopByte(expr)) != 0xDEAD) {
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -209,9 +209,6 @@
tryReadstr(patch->fileName, file,
"%s: Unable to read \"%s\"'s patch #%u's name: %s",
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,
"%s: Unable to read \"%s\"'s patch #%u's offset: %s",
fileName, sectName, i);
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -93,11 +93,10 @@
stack.size++;
}
-static int32_t popRPN(char const *fileName, int32_t lineNo)
+static int32_t popRPN(char const *fileName)
{
if (stack.size == 0)
- errx(1, "%s(%d): Internal error, RPN stack empty", fileName,
- lineNo);
+ errx(1, "%s: Internal error, RPN stack empty", fileName);
stack.size--;
return stack.buf[stack.size];
@@ -111,10 +110,10 @@
/* RPN operators */
static uint32_t getRPNByte(uint8_t const **expression, int32_t *size,
- char const *fileName, int32_t lineNo)
+ char const *fileName)
{
if (!(*size)--)
- errx(1, "%s(%d): RPN expression overread", fileName, lineNo);
+ errx(1, "%s: RPN expression overread", fileName);
return *(*expression)++;
}
@@ -128,7 +127,7 @@
struct Section const *section)
{
/* 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;
int32_t size = patch->rpnSize;
@@ -137,8 +136,7 @@
while (size > 0) {
enum RPNCommand command = getRPNByte(&expression, &size,
- patch->fileName,
- patch->lineNo);
+ patch->fileName);
int32_t value;
/*
@@ -236,8 +234,7 @@
value = 0;
for (uint8_t shift = 0; shift < 32; shift += 8)
value |= getRPNByte(&expression, &size,
- patch->fileName,
- patch->lineNo) << shift;
+ patch->fileName) << shift;
symbol = section->fileSymbols[value];
@@ -247,8 +244,7 @@
sym_GetSymbol(symbol->name);
if (!symbolDefinition)
errx(1, "%s(%d): Unknown symbol \"%s\"",
- patch->fileName, patch->lineNo,
- symbol->name);
+ patch->fileName, symbol->name);
symbol = symbolDefinition;
}
@@ -257,15 +253,14 @@
case RPN_BANK_SECT:
name = (char const *)expression;
- while (getRPNByte(&expression, &size, patch->fileName,
- patch->lineNo))
+ while (getRPNByte(&expression, &size, patch->fileName))
;
sect = sect_GetSection(name);
if (!sect)
- errx(1, "%s(%d): Requested BANK() of section \"%s\", which was not found",
- patch->fileName, patch->lineNo, name);
+ errx(1, "%s: Requested BANK() of section \"%s\", which was not found",
+ patch->fileName, name);
value = sect->bank;
break;
@@ -279,8 +274,8 @@
if (value < 0
|| (value > 0xFF && value < 0xFF00)
|| value > 0xFFFF)
- errx(1, "%s(%d): Value %d is not in HRAM range",
- patch->fileName, patch->lineNo, value);
+ errx(1, "%s: Value %d is not in HRAM range",
+ patch->fileName, value);
value &= 0xFF;
break;
@@ -290,8 +285,8 @@
* They can be easily checked with a bitmask
*/
if (value & ~0x38)
- errx(1, "%s(%d): Value %d is not a RST vector",
- patch->fileName, patch->lineNo, value);
+ errx(1, "%s: Value %d is not a RST vector",
+ patch->fileName, value);
value |= 0xC7;
break;
@@ -299,8 +294,7 @@
value = 0;
for (uint8_t shift = 0; shift < 32; shift += 8)
value |= getRPNByte(&expression, &size,
- patch->fileName,
- patch->lineNo) << shift;
+ patch->fileName) << shift;
break;
case RPN_SYM:
@@ -307,8 +301,7 @@
value = 0;
for (uint8_t shift = 0; shift < 32; shift += 8)
value |= getRPNByte(&expression, &size,
- patch->fileName,
- patch->lineNo) << shift;
+ patch->fileName) << shift;
symbol = section->fileSymbols[value];
@@ -317,9 +310,8 @@
struct Symbol const *symbolDefinition =
sym_GetSymbol(symbol->name);
if (!symbolDefinition)
- errx(1, "%s(%d): Unknown symbol \"%s\"",
- patch->fileName, patch->lineNo,
- symbol->name);
+ errx(1, "%s: Unknown symbol \"%s\"",
+ patch->fileName, symbol->name);
symbol = symbolDefinition;
}
@@ -338,8 +330,8 @@
}
if (stack.size > 1)
- warnx("%s(%d): RPN stack has %lu entries on exit, not 1",
- patch->fileName, patch->lineNo, stack.size);
+ warnx("%s: RPN stack has %lu entries on exit, not 1",
+ patch->fileName, stack.size);
return popRPN();
@@ -370,8 +362,8 @@
int16_t offset = value - address;
if (offset < -128 || offset > 127)
- errx(1, "%s(%d): jr target out of reach (expected -129 < %d < 128)",
- patch->fileName, patch->lineNo, offset);
+ errx(1, "%s: jr target out of reach (expected -129 < %d < 128)",
+ patch->fileName, offset);
section->data[patch->offset] = offset & 0xFF;
} else {
/* Patch a certain number of bytes */
@@ -387,8 +379,8 @@
if (value < types[patch->type].min
|| value > types[patch->type].max)
- errx(1, "%s(%d): Value %#x%s is not %u-bit",
- patch->fileName, patch->lineNo, value,
+ errx(1, "%s: Value %#x%s is not %u-bit",
+ patch->fileName, value,
value < 0 ? " (maybe negative?)" : "",
types[patch->type].size * 8);
for (uint8_t i = 0; i < types[patch->type].size; i++) {
--- a/src/rgbds.5
+++ b/src/rgbds.5
@@ -106,8 +106,6 @@
STRING SourceFile ; Name of the source file (for printing error
; messages).
- LONG Line ; The line of the source file.
-
LONG Offset ; Offset into the section where patch should
; be applied (in bytes).