mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Have jr offset wrap with 16 bits
Overflow with `int16_t` is defined to two's complement so it's OK This could trigger when jumping from the top of ROM0 to HRAM
This commit is contained in:
@@ -299,11 +299,11 @@ static void applyPatches(struct Section *section, void *arg)
|
|||||||
struct Patch *patch = §ion->patches[patchID];
|
struct Patch *patch = §ion->patches[patchID];
|
||||||
int32_t value = computeRPNExpr(patch, section);
|
int32_t value = computeRPNExpr(patch, section);
|
||||||
|
|
||||||
if (patch->type == PATCHTYPE_JR) {
|
|
||||||
/* `jr` is quite unlike the others... */
|
/* `jr` is quite unlike the others... */
|
||||||
uint16_t address = section->org + patch->offset;
|
if (patch->type == PATCHTYPE_JR) {
|
||||||
/* Target is relative to the byte *after* the operand */
|
/* Target is relative to the byte *after* the operand */
|
||||||
int32_t offset = value - (address + 1);
|
uint16_t address = section->org + patch->offset + 1;
|
||||||
|
int16_t offset = value - address;
|
||||||
|
|
||||||
if (offset < -128 || offset > 127)
|
if (offset < -128 || offset > 127)
|
||||||
errx(1, "%s(%d): jr target out of reach (%d)",
|
errx(1, "%s(%d): jr target out of reach (%d)",
|
||||||
|
|||||||
Reference in New Issue
Block a user