mirror of
https://github.com/gbdev/rgbds.git
synced 2026-10-06 04:05:38 +00:00
Allow STARTOF(SECTTYPE) and SIZEOF(SECTTYPE) to be constant when possible (#2131)
This commit is contained in:
1 parent
548a11c3ef
commit
e0ee6c9013
6 files changed
+45
-6
No files matched your search
+11
-2
@@ -772,7 +772,15 @@ and no longer the current section).
|
||||
If
|
||||
.Ar arg
|
||||
is a section type keyword, it returns the size of that section type.
|
||||
The result is not constant, since only RGBLINK can compute its value.
|
||||
The result is a known constant except for
|
||||
.Ic ROM0
|
||||
and
|
||||
.Ic WRAM0 ,
|
||||
since their sizes may be affected by RGBLINK options
|
||||
.Fl t
|
||||
and
|
||||
.Fl w
|
||||
respectively.
|
||||
.Pp
|
||||
If
|
||||
.Ar arg
|
||||
@@ -786,7 +794,8 @@ The result is a known constant if the section has a fixed address.
|
||||
If
|
||||
.Ar arg
|
||||
is a section type keyword, it returns the starting address of that section type.
|
||||
The result is not constant, since only RGBLINK can compute its value.
|
||||
.Pp
|
||||
The result is always a known constant at assembly time.
|
||||
.El
|
||||
.Sh SECTIONS
|
||||
Before you can start writing code, you must define a section.
|
||||
|
||||
+10
-4
@@ -142,14 +142,20 @@ void Expression::makeStartOfSection(std::string const §Name) {
|
||||
|
||||
void Expression::makeSizeOfSectionType(SectionType type) {
|
||||
assume(rpn.empty());
|
||||
data = "Section type's size is not known";
|
||||
rpn.emplace_back(RPN_SIZEOF_SECTTYPE, static_cast<uint8_t>(type));
|
||||
if (type == SECTTYPE_WRAM0) {
|
||||
data = "Section type WRAM0's size is not known (can be affected by RGBLINK '-w/--wramx')";
|
||||
rpn.emplace_back(RPN_SIZEOF_SECTTYPE, static_cast<uint8_t>(type));
|
||||
} else if (type == SECTTYPE_ROM0) {
|
||||
data = "Section type ROM0's size is not known (can be affected by RGBLINK '-t/--tiny')";
|
||||
rpn.emplace_back(RPN_SIZEOF_SECTTYPE, static_cast<uint8_t>(type));
|
||||
} else {
|
||||
data = static_cast<int32_t>(sectionTypeInfo[type].size);
|
||||
}
|
||||
}
|
||||
|
||||
void Expression::makeStartOfSectionType(SectionType type) {
|
||||
assume(rpn.empty());
|
||||
data = "Section type's start is not known";
|
||||
rpn.emplace_back(RPN_STARTOF_SECTTYPE, static_cast<uint8_t>(type));
|
||||
data = static_cast<int32_t>(sectionTypeInfo[type].startAddr);
|
||||
}
|
||||
|
||||
static bool tryConstZero(Expression const &lhs, Expression const &rhs) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
SECTION "ROM0", ROM0[STARTOF(ROM0)]
|
||||
Label:: ds SIZEOF(ROM0)
|
||||
|
||||
SECTION "WRAM0", WRAM0[STARTOF(WRAM0)]
|
||||
wLabel:: ds SIZEOF(WRAM0)
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Expected constant expression: Section type ROM0's size is not known (can be affected by RGBLINK '-t/--tiny')
|
||||
at secttype-sizeof-startof-unknown.asm(2)
|
||||
error: Expected constant expression: Section type WRAM0's size is not known (can be affected by RGBLINK '-w/--wramx')
|
||||
at secttype-sizeof-startof-unknown.asm(5)
|
||||
Assembly aborted with 2 errors
|
||||
@@ -0,0 +1,13 @@
|
||||
SECTION "ROMX", ROMX[STARTOF(ROMX)], BANK[1]
|
||||
xLabel:: ds SIZEOF(ROMX), $22
|
||||
|
||||
SECTION "VRAM", VRAM[STARTOF(VRAM)], BANK[0]
|
||||
vLabel:: ds SIZEOF(VRAM)
|
||||
|
||||
SECTION "ROM0", ROM0[STARTOF(ROM0)]
|
||||
ASSERT !ISCONST(SIZEOF(ROM0)) ; rgblink may have -t/--tiny
|
||||
Label:: ds $4000, $11
|
||||
|
||||
SECTION "WRAM0", WRAM0[STARTOF(WRAM0)]
|
||||
ASSERT !ISCONST(SIZEOF(WRAM0)) ; rgblink may have -w/--wramx
|
||||
wLabel:: ds $1000
|
||||
@@ -0,0 +1 @@
|
||||
Line truncated
|
||||
Reference in new issue
Block a user