mirror of
https://github.com/gbdev/rgbds.git
synced 2026-08-25 08:14:31 +00:00
+6
-3
@@ -585,12 +585,15 @@ static void applyFilePatches(Section §ion, Section &dataSection) {
|
|||||||
rpnErrorAt(patch, "PC has no value outside of a section");
|
rpnErrorAt(patch, "PC has no value outside of a section");
|
||||||
dataSection.data[offset] = 0;
|
dataSection.data[offset] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
// A `jr` is *encoded* in ROM as a 1-byte (8-bit) offset, so here `typeSize == 8`,
|
||||||
|
// but the object's *value* size is a 16-bit absolute address, so we pass 16 here.
|
||||||
|
checkPatchSize(patch, value, 16);
|
||||||
// Offset 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
|
// PC as operand to `jr` is lower than reference PC by 2
|
||||||
uint16_t address = patch.pcSection->org + patch.pcOffset + 2;
|
uint16_t address = patch.pcSection->org + patch.pcOffset + 2;
|
||||||
// The truncation of `value - address` is intentional, since
|
// The 16-bit truncation of `value - address` is intentional, since
|
||||||
// a low ROM0 address may `jr` to a high HRAM one.
|
// a low ROM0 address may `jr` backwards to a high HRAM one.
|
||||||
int16_t jumpOffset = value - address;
|
int16_t jumpOffset = static_cast<int16_t>(value - address);
|
||||||
|
|
||||||
if (jumpOffset < -128 || jumpOffset > 127) {
|
if (jumpOffset < -128 || jumpOffset > 127) {
|
||||||
firstErrorAt(
|
firstErrorAt(
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
SECTION "jr", ROM0
|
||||||
|
jr CONSTANT
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
EXPORT DEF CONSTANT EQU $1234_0078
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Value $12340078 is not 16-bit [-Wtruncation]
|
||||||
|
at jr-truncation/a.asm(2)
|
||||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
|||||||
|
; File generated by rgblink
|
||||||
|
12340078 CONSTANT
|
||||||
@@ -201,6 +201,17 @@ tryCmpRom "$test"/ref.out.bin
|
|||||||
tryDiff "$test"/ref.out.sym "$outtemp2"
|
tryDiff "$test"/ref.out.sym "$outtemp2"
|
||||||
evaluateTest
|
evaluateTest
|
||||||
|
|
||||||
|
test="jr-truncation"
|
||||||
|
startTest
|
||||||
|
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||||
|
"$RGBASM" -o "$outtemp" "$test"/b.asm
|
||||||
|
continueTest
|
||||||
|
rgblinkQuiet -o "$gbtemp" -n "$outtemp2" "$otemp" "$outtemp" 2>"$outtemp3"
|
||||||
|
tryDiff "$test"/out.err "$outtemp3"
|
||||||
|
tryCmpRom "$test"/ref.out.bin
|
||||||
|
tryDiff "$test"/ref.out.sym "$outtemp2"
|
||||||
|
evaluateTest
|
||||||
|
|
||||||
test="high-low"
|
test="high-low"
|
||||||
startTest
|
startTest
|
||||||
"$RGBASM" -o "$otemp" "$test"/a.asm
|
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||||
|
|||||||
Reference in New Issue
Block a user