Make @ relative to the start of a ds even at link time

Fix #737
This commit is contained in:
Rangi
2021-02-14 20:53:44 -05:00
committed by Eldred Habert
parent 2bc12447e2
commit ee20d9010e
13 changed files with 74 additions and 72 deletions

View File

@@ -286,8 +286,7 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName, cha
tryGetc(type, file,
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s type: %s",
fileName, sectName, i);
patch->type = type & 0x7F;
patch->isOperand = type & PATCH_ISOPERAND;
patch->type = type;
tryReadlong(patch->rpnSize, file,
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s RPN size: %s",
fileName, sectName, i);

View File

@@ -421,10 +421,6 @@ static int32_t computeRPNExpr(struct Patch const *patch,
isError = true;
} else {
value = patch->pcOffset + patch->pcSection->org;
// If the patch is an operand, PC is not at the patch's
// location, but at the (opcode) byte right before it
if (patch->isOperand)
value--;
}
} else {
symbol = getSymbol(fileSymbols, value);
@@ -520,9 +516,10 @@ static void applyFilePatches(struct Section *section, struct Section *dataSectio
/* `jr` is quite unlike the others... */
if (patch->type == PATCHTYPE_JR) {
/* Target is relative to the byte *after* the operand */
// Offset is relative to the byte *after* the operand
// PC as operand to `jr` is lower than reference PC by 2
uint16_t address = patch->pcSection->org
+ patch->pcOffset + 1;
+ patch->pcOffset + 2;
int16_t jumpOffset = value - address;
if (!isError && (jumpOffset < -128 || jumpOffset > 127))