ref: e82ad21704bf4df1806195d30d8fa2bf65f0d812
parent: e098bf47bae28c2e0ed83291b5ddde35b1da0c26
author: ISSOtm <[email protected]>
date: Tue Apr 7 17:15:55 EDT 2020
Use a single byte for alignment
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -180,7 +180,7 @@
fputlong(pSect->nOrg, f);
fputlong(pSect->nBank, f);
- fputlong(pSect->nAlign, f);
+ fputc(pSect->nAlign, f);
if (sect_HasData(pSect->nType)) {
fwrite(pSect->tData, 1, pSect->size, f);
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -86,7 +86,7 @@
*/
static struct Section *getSection(char const *pzName, enum SectionType type,
uint32_t org, uint32_t bank,
- uint32_t alignment, bool isUnion)
+ uint8_t alignment, bool isUnion)
{
if (bank != -1) {
if (type != SECTTYPE_ROMX && type != SECTTYPE_VRAM
@@ -99,15 +99,15 @@
bankranges[type][0], bankranges[type][1]);
}
- if (alignment != 1) {
+ if (alignment != 0) {
/* 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 & mask)
yyerror("Section \"%s\"'s fixed address doesn't match its alignment",
pzName);
- alignment = 1; /* Ignore it if it's satisfied */
+ alignment = 0; /* Ignore it if it's satisfied */
} else if (startaddr[type] & mask) {
yyerror("Section \"%s\"'s alignment cannot be attained in %s",
pzName, typeNames[type]);
@@ -158,9 +158,9 @@
fail("Section \"%s\" already declared as fixed at different address $%x",
pSect->pzName, pSect->nOrg);
else if (pSect->nAlign != 0
- && ((pSect->nAlign - 1) & org))
+ && (((1 << pSect->nAlign) - 1) & org))
fail("Section \"%s\" already declared as aligned to %u bytes",
- pSect->pzName, pSect->nAlign);
+ pSect->pzName, 1 << pSect->nAlign);
else
/* Otherwise, just override */
pSect->nOrg = org;
@@ -214,7 +214,7 @@
pSect->pzName);
else
fail("Section \"%s\" already declared as aligned to %u bytes",
- pSect->pzName, pSect->nAlign);
+ pSect->pzName, 1 << pSect->nAlign);
}
}
@@ -286,7 +286,7 @@
fatalerror("Cannot change the section within a `LOAD` block");
struct Section *pSect = getSection(pzName, type, org, attributes->bank,
- 1 << attributes->alignment, isUnion);
+ attributes->alignment, isUnion);
setSection(pSect);
curOffset = isUnion ? 0 : pSect->size;
@@ -305,7 +305,7 @@
fatalerror("`LOAD` blocks cannot be nested");
struct Section *pSect = getSection(name, type, org, attributes->bank,
- 1 << attributes->alignment, false);
+ attributes->alignment, false);
loadOffset = curOffset;
curOffset = 0; /* curOffset -= loadOffset; */
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -279,10 +279,10 @@
fileName, section->name);
section->isBankFixed = tmp >= 0;
section->bank = tmp;
- tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s alignment: %s",
- fileName, section->name);
- section->isAlignFixed = tmp != 1;
- section->alignMask = tmp - 1;
+ tryGetc(tmp, file, "%s: Cannot read \"%s\"'s alignment: %s",
+ fileName, section->name);
+ section->isAlignFixed = tmp != 0;
+ section->alignMask = (1 << tmp) - 1;
if (sect_HasData(section->type)) {
/* Ensure we never allocate 0 bytes */
--- a/src/rgbds.5
+++ b/src/rgbds.5
@@ -92,8 +92,7 @@
; decide (floating bank). This field is only valid for ROMX,
; VRAM, WRAMX and SRAM sections.
- LONG Align ; Alignment of this section, expressed as 1 << align. 1 if
- ; not specified.
+ BYTE Align ; Alignment of this section, as N bits. 0 when not specified.
IF (Type == ROMX) || (Type == ROM0) ; Sections that can contain data.