mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-22 13:47:05 +00:00
Respect zero-size sections' align offsets
Fixes #2095 This code pre-dates the introduction of alignment offsets, so it was never updated to take it into account. That said, some of the code that I have factored out is a little awkward because it will be used in an upcoming refactoring of the whole assignment loop, since that turns out to be more byzantine than it ought to be due to trying to handle a too disparate set of cases in a single loop.
This commit is contained in:
+12
-7
@@ -138,6 +138,14 @@ struct MemoryLocation {
|
||||
++bank;
|
||||
return true;
|
||||
}
|
||||
|
||||
void makeAddressAligned(uint16_t alignMask, uint16_t alignOfs) {
|
||||
// By how much the address is past the target offset within the current alignment "page".
|
||||
uint16_t offset = (address - alignOfs) & alignMask;
|
||||
// Move by one page *minus* that "overshoot" offset.
|
||||
// If it's 0, then this would move by a whole page, but `& alignMask` resets it back to 0.
|
||||
address += ((alignMask + 1) - offset) & alignMask;
|
||||
}
|
||||
};
|
||||
|
||||
// Checks whether a given location is suitable for placing a given section
|
||||
@@ -289,13 +297,10 @@ static void placeSection(Section §ion) {
|
||||
|
||||
// Specially handle 0-byte SECTIONs, as they can't overlap anything
|
||||
if (section.size == 0) {
|
||||
// Unless the SECTION has a fixed address or non-zero alignment offset, the starting
|
||||
// address is fine for any alignment, as checked in `sect_DoSanityChecks`.
|
||||
location.address = section.isAddressFixed ? section.org : section.typeInfo().startAddr;
|
||||
if (section.isAlignFixed && !section.isAddressFixed) {
|
||||
if (uint16_t offset = (location.address - section.alignOfs) & section.alignMask;
|
||||
offset != 0) {
|
||||
location.address += section.alignMask + 1 - offset;
|
||||
if (!section.isAddressFixed) {
|
||||
location.address = section.typeInfo().startAddr;
|
||||
if (section.isAlignFixed) {
|
||||
location.makeAddressAligned(section.alignMask, section.alignOfs);
|
||||
}
|
||||
}
|
||||
assignSection(section, location);
|
||||
|
||||
Reference in New Issue
Block a user