mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Use a single byte for alignment
This commit is contained in:
@@ -180,7 +180,7 @@ static void writesection(struct Section const *pSect, FILE *f)
|
|||||||
|
|
||||||
fputlong(pSect->nOrg, f);
|
fputlong(pSect->nOrg, f);
|
||||||
fputlong(pSect->nBank, f);
|
fputlong(pSect->nBank, f);
|
||||||
fputlong(pSect->nAlign, f);
|
fputc(pSect->nAlign, f);
|
||||||
|
|
||||||
if (sect_HasData(pSect->nType)) {
|
if (sect_HasData(pSect->nType)) {
|
||||||
fwrite(pSect->tData, 1, pSect->size, f);
|
fwrite(pSect->tData, 1, pSect->size, f);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ struct Section *out_FindSectionByName(const char *pzName)
|
|||||||
*/
|
*/
|
||||||
static struct Section *getSection(char const *pzName, enum SectionType type,
|
static struct Section *getSection(char const *pzName, enum SectionType type,
|
||||||
uint32_t org, uint32_t bank,
|
uint32_t org, uint32_t bank,
|
||||||
uint32_t alignment, bool isUnion)
|
uint8_t alignment, bool isUnion)
|
||||||
{
|
{
|
||||||
if (bank != -1) {
|
if (bank != -1) {
|
||||||
if (type != SECTTYPE_ROMX && type != SECTTYPE_VRAM
|
if (type != SECTTYPE_ROMX && type != SECTTYPE_VRAM
|
||||||
@@ -99,15 +99,15 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
|
|||||||
bankranges[type][0], bankranges[type][1]);
|
bankranges[type][0], bankranges[type][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alignment != 1) {
|
if (alignment != 0) {
|
||||||
/* It doesn't make sense to have both set */
|
/* It doesn't make sense to have both set */
|
||||||
uint32_t mask = alignment - 1;
|
uint32_t mask = (1 << alignment) - 1;
|
||||||
|
|
||||||
if (org != -1) {
|
if (org != -1) {
|
||||||
if (org & mask)
|
if (org & mask)
|
||||||
yyerror("Section \"%s\"'s fixed address doesn't match its alignment",
|
yyerror("Section \"%s\"'s fixed address doesn't match its alignment",
|
||||||
pzName);
|
pzName);
|
||||||
alignment = 1; /* Ignore it if it's satisfied */
|
alignment = 0; /* Ignore it if it's satisfied */
|
||||||
} else if (startaddr[type] & mask) {
|
} else if (startaddr[type] & mask) {
|
||||||
yyerror("Section \"%s\"'s alignment cannot be attained in %s",
|
yyerror("Section \"%s\"'s alignment cannot be attained in %s",
|
||||||
pzName, typeNames[type]);
|
pzName, typeNames[type]);
|
||||||
@@ -158,9 +158,9 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
|
|||||||
fail("Section \"%s\" already declared as fixed at different address $%x",
|
fail("Section \"%s\" already declared as fixed at different address $%x",
|
||||||
pSect->pzName, pSect->nOrg);
|
pSect->pzName, pSect->nOrg);
|
||||||
else if (pSect->nAlign != 0
|
else if (pSect->nAlign != 0
|
||||||
&& ((pSect->nAlign - 1) & org))
|
&& (((1 << pSect->nAlign) - 1) & org))
|
||||||
fail("Section \"%s\" already declared as aligned to %u bytes",
|
fail("Section \"%s\" already declared as aligned to %u bytes",
|
||||||
pSect->pzName, pSect->nAlign);
|
pSect->pzName, 1 << pSect->nAlign);
|
||||||
else
|
else
|
||||||
/* Otherwise, just override */
|
/* Otherwise, just override */
|
||||||
pSect->nOrg = org;
|
pSect->nOrg = org;
|
||||||
@@ -214,7 +214,7 @@ static struct Section *getSection(char const *pzName, enum SectionType type,
|
|||||||
pSect->pzName);
|
pSect->pzName);
|
||||||
else
|
else
|
||||||
fail("Section \"%s\" already declared as aligned to %u bytes",
|
fail("Section \"%s\" already declared as aligned to %u bytes",
|
||||||
pSect->pzName, pSect->nAlign);
|
pSect->pzName, 1 << pSect->nAlign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ void out_NewSection(char const *pzName, uint32_t type, uint32_t org,
|
|||||||
fatalerror("Cannot change the section within a `LOAD` block");
|
fatalerror("Cannot change the section within a `LOAD` block");
|
||||||
|
|
||||||
struct Section *pSect = getSection(pzName, type, org, attributes->bank,
|
struct Section *pSect = getSection(pzName, type, org, attributes->bank,
|
||||||
1 << attributes->alignment, isUnion);
|
attributes->alignment, isUnion);
|
||||||
|
|
||||||
setSection(pSect);
|
setSection(pSect);
|
||||||
curOffset = isUnion ? 0 : pSect->size;
|
curOffset = isUnion ? 0 : pSect->size;
|
||||||
@@ -305,7 +305,7 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org,
|
|||||||
fatalerror("`LOAD` blocks cannot be nested");
|
fatalerror("`LOAD` blocks cannot be nested");
|
||||||
|
|
||||||
struct Section *pSect = getSection(name, type, org, attributes->bank,
|
struct Section *pSect = getSection(name, type, org, attributes->bank,
|
||||||
1 << attributes->alignment, false);
|
attributes->alignment, false);
|
||||||
|
|
||||||
loadOffset = curOffset;
|
loadOffset = curOffset;
|
||||||
curOffset = 0; /* curOffset -= loadOffset; */
|
curOffset = 0; /* curOffset -= loadOffset; */
|
||||||
|
|||||||
@@ -279,10 +279,10 @@ static void readSection(FILE *file, struct Section *section,
|
|||||||
fileName, section->name);
|
fileName, section->name);
|
||||||
section->isBankFixed = tmp >= 0;
|
section->isBankFixed = tmp >= 0;
|
||||||
section->bank = tmp;
|
section->bank = tmp;
|
||||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s alignment: %s",
|
tryGetc(tmp, file, "%s: Cannot read \"%s\"'s alignment: %s",
|
||||||
fileName, section->name);
|
fileName, section->name);
|
||||||
section->isAlignFixed = tmp != 1;
|
section->isAlignFixed = tmp != 0;
|
||||||
section->alignMask = tmp - 1;
|
section->alignMask = (1 << tmp) - 1;
|
||||||
|
|
||||||
if (sect_HasData(section->type)) {
|
if (sect_HasData(section->type)) {
|
||||||
/* Ensure we never allocate 0 bytes */
|
/* Ensure we never allocate 0 bytes */
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ REPT NumberOfSections
|
|||||||
; decide (floating bank). This field is only valid for ROMX,
|
; decide (floating bank). This field is only valid for ROMX,
|
||||||
; VRAM, WRAMX and SRAM sections.
|
; VRAM, WRAMX and SRAM sections.
|
||||||
|
|
||||||
LONG Align ; Alignment of this section, expressed as 1 << align. 1 if
|
BYTE Align ; Alignment of this section, as N bits. 0 when not specified.
|
||||||
; not specified.
|
|
||||||
|
|
||||||
IF (Type == ROMX) || (Type == ROM0) ; Sections that can contain data.
|
IF (Type == ROMX) || (Type == ROM0) ; Sections that can contain data.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user