mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix alignment compatibility with current lower alignment
This commit is contained in:
@@ -583,30 +583,33 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
|
|||||||
actualOffset
|
actualOffset
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (uint32_t actualOffset =
|
} else {
|
||||||
((sect->alignOfs + curOffset) % (1u << sect->align)) % alignSize;
|
if (uint32_t actualOffset = (sect->alignOfs + curOffset) % alignSize,
|
||||||
sect->align != 0 && actualOffset != offset) {
|
sectAlignSize = 1 << sect->align;
|
||||||
error(
|
sect->align != 0 && actualOffset % sectAlignSize != offset % sectAlignSize) {
|
||||||
"Section is misaligned ($%04" PRIx32 " bytes into the section, expected ALIGN[%" PRIu32
|
error(
|
||||||
", %" PRIu32 "], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n",
|
"Section is misaligned ($%04" PRIx32
|
||||||
curOffset,
|
" bytes into the section, expected ALIGN[%" PRIu32 ", %" PRIu32
|
||||||
alignment,
|
"], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n",
|
||||||
offset,
|
curOffset,
|
||||||
alignment,
|
alignment,
|
||||||
actualOffset
|
offset,
|
||||||
);
|
alignment,
|
||||||
} else if (alignment >= 16) {
|
actualOffset
|
||||||
// Treat an alignment large enough as fixing the address.
|
);
|
||||||
// Note that this also ensures that a section's alignment never becomes 16 or greater.
|
} else if (alignment >= 16) {
|
||||||
if (alignment > 16) {
|
// Treat an alignment large enough as fixing the address.
|
||||||
error("Alignment must be between 0 and 16, not %u\n", alignment);
|
// Note that this also ensures that a section's alignment never becomes 16 or greater.
|
||||||
|
if (alignment > 16) {
|
||||||
|
error("Alignment must be between 0 and 16, not %u\n", alignment);
|
||||||
|
}
|
||||||
|
sect->align = 0; // Reset the alignment, since we're fixing the address.
|
||||||
|
sect->org = offset - curOffset;
|
||||||
|
} else if (alignment > sect->align) {
|
||||||
|
sect->align = alignment;
|
||||||
|
// We need `(sect->alignOfs + curOffset) % alignSize == offset`
|
||||||
|
sect->alignOfs = (offset - curOffset) % alignSize;
|
||||||
}
|
}
|
||||||
sect->align = 0; // Reset the alignment, since we're fixing the address.
|
|
||||||
sect->org = offset - curOffset;
|
|
||||||
} else if (alignment > sect->align) {
|
|
||||||
sect->align = alignment;
|
|
||||||
// We need `(sect->alignOfs + curOffset) % alignSize == offset`
|
|
||||||
sect->alignOfs = (offset - curOffset) % alignSize;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
test/asm/align-increasing.asm
Normal file
15
test/asm/align-increasing.asm
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
SECTION "test1", ROM0
|
||||||
|
align 4 ; PC = $xxx0
|
||||||
|
dw $0123
|
||||||
|
align 4, 2 ; PC = $xxx2
|
||||||
|
ds align [8, $C2] ; PC = $xxC2 (ds 0)
|
||||||
|
align 8, $C2 ; PC = $xxC2
|
||||||
|
dw $4567
|
||||||
|
|
||||||
|
SECTION "test2", ROM0[$01C0]
|
||||||
|
align 4 ; PC = $01C0
|
||||||
|
dw $89ab
|
||||||
|
align 4, 2 ; PC = $01C2
|
||||||
|
ds align [8, $C2] ; PC = $01C2 (ds 0)
|
||||||
|
align 8, $C2 ; PC = $01C2
|
||||||
|
dw $cdef
|
||||||
BIN
test/asm/align-increasing.out.bin
Normal file
BIN
test/asm/align-increasing.out.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user