mirror of
https://github.com/gbdev/rgbds.git
synced 2026-11-24 05:48:39 +00:00
Allow empty one-past-the-end sections (#2221)
This commit is contained in:
1 parent
72c9171216
commit
85f96d671f
12 files changed
+26
-16
No files matched your search
+5
-6
@@ -261,10 +261,10 @@ static void
|
||||
static void assignSection(Section §ion, MemoryLocation const &location) {
|
||||
assume(location.address >= section.typeInfo().startAddr);
|
||||
// Zero-sized sections can start one past the end of their region.
|
||||
assume(location.address <= section.typeInfo().endAddr() + 1);
|
||||
assume(location.address <= section.typeInfo().onePastEndAddr());
|
||||
// This one is not redundant, it guards against overflow!
|
||||
assume(location.address + section.size >= section.typeInfo().startAddr);
|
||||
assume(location.address + section.size <= section.typeInfo().endAddr() + 1);
|
||||
assume(location.address + section.size <= section.typeInfo().onePastEndAddr());
|
||||
|
||||
if (section.isAddressFixed) {
|
||||
assume(location.address == section.org);
|
||||
@@ -345,7 +345,7 @@ static void placeSection(Section §ion) {
|
||||
// range for its `section`, which would violate an assumption in `assignSection`.
|
||||
// Note that sections with fixed addresses are handled earlier by `sect_DoSanityChecks`,
|
||||
// but this check would safely handle them too if they ever reached it.
|
||||
if (location.address <= section.typeInfo().endAddr() + 1) {
|
||||
if (location.address <= section.typeInfo().onePastEndAddr()) {
|
||||
assignSection(section, location);
|
||||
return;
|
||||
}
|
||||
@@ -363,14 +363,13 @@ static void placeSection(Section §ion) {
|
||||
if (!section.isBankFixed || !section.isAddressFixed) {
|
||||
// If a section failed to go to several places, nothing we can report
|
||||
fatal("Unable to place %s", describeConstraintsOf(section).c_str());
|
||||
} else if (uint16_t onePastEnd = section.typeInfo().endAddr() + 1;
|
||||
section.org + section.size > onePastEnd) {
|
||||
} else if (section.org + section.size > section.typeInfo().onePastEndAddr()) {
|
||||
// If the section just can't fit the bank, report that
|
||||
fatal(
|
||||
"Unable to place %s: section runs past end of region ($%04x > $%04x)",
|
||||
describeConstraintsOf(section).c_str(),
|
||||
section.org + section.size,
|
||||
onePastEnd
|
||||
section.typeInfo().onePastEndAddr()
|
||||
);
|
||||
} else {
|
||||
// Otherwise there is overlap with another section
|
||||
|
||||
+3
-3
@@ -92,7 +92,7 @@ void layout_SetAddr(uint32_t addr) {
|
||||
|
||||
if (uint16_t &pc = curAddr[activeType][activeBankIdx]; addr < pc) {
|
||||
scriptError("Cannot decrease the current address (from $%04x to $%04x)", pc, addr);
|
||||
} else if (addr > typeInfo.endAddr() + 1u) { // Allow "one past the end" zero-sized sections.
|
||||
} else if (addr > typeInfo.onePastEndAddr()) { // Allow "one past the end" zero-sized sections.
|
||||
scriptError(
|
||||
"Cannot set the current address to $%04" PRIx32 ": %s ends at $%04" PRIx16,
|
||||
addr,
|
||||
@@ -182,7 +182,7 @@ void layout_AlignTo(uint32_t alignment, uint32_t alignOfs) {
|
||||
", past $%04" PRIx16,
|
||||
pc,
|
||||
static_cast<uint16_t>(pc + length),
|
||||
static_cast<uint16_t>(typeInfo.endAddr() + 1)
|
||||
typeInfo.onePastEndAddr()
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ void layout_Pad(uint32_t length) {
|
||||
"Cannot increase the current address by %u bytes: only %u bytes to $%04" PRIx16,
|
||||
length,
|
||||
typeInfo.size - offset,
|
||||
static_cast<uint16_t>(typeInfo.endAddr() + 1)
|
||||
typeInfo.onePastEndAddr()
|
||||
);
|
||||
} else {
|
||||
pc += length;
|
||||
|
||||
+1
-2
@@ -493,8 +493,7 @@ static void writeMapBank(SortedSections const §List, SectionType type, uint3
|
||||
if (used == 0) {
|
||||
fputs("\tEMPTY\n", mapFile);
|
||||
} else {
|
||||
uint16_t bankEndAddr = sectionTypeInfo[type].endAddr() + 1;
|
||||
writeEmptySpace(prevEndAddr, bankEndAddr);
|
||||
writeEmptySpace(prevEndAddr, sectionTypeInfo[type].onePastEndAddr());
|
||||
|
||||
uint16_t slack = sectionTypeInfo[type].size - used;
|
||||
fprintf(mapFile, "\tTOTAL EMPTY: $%04" PRIx16 " byte%s\n", slack, slack == 1 ? "" : "s");
|
||||
|
||||
@@ -325,21 +325,21 @@ static void doSanityChecks(Section §ion) {
|
||||
}
|
||||
|
||||
// Ensure the target address is valid
|
||||
if (section.org < typeInfo.startAddr || section.org > typeInfo.endAddr()) {
|
||||
if (section.org < typeInfo.startAddr || section.org > typeInfo.onePastEndAddr()) {
|
||||
error(
|
||||
"Section \"%s\"'s fixed address $%04" PRIx16 " is outside of range [$%04" PRIx16
|
||||
"; $%04" PRIx16 "]",
|
||||
section.name.c_str(),
|
||||
section.org,
|
||||
typeInfo.startAddr,
|
||||
typeInfo.endAddr()
|
||||
typeInfo.onePastEndAddr()
|
||||
);
|
||||
} else if (section.org + section.size > typeInfo.endAddr() + 1) {
|
||||
} else if (section.org + section.size > typeInfo.onePastEndAddr()) {
|
||||
error(
|
||||
"Section \"%s\"'s end address $%04x is greater than last address $%04x",
|
||||
section.name.c_str(),
|
||||
section.org + section.size,
|
||||
typeInfo.endAddr() + 1
|
||||
typeInfo.onePastEndAddr()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user