From e82ad21704bf4df1806195d30d8fa2bf65f0d812 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 7 Apr 2020 21:15:55 +0200 Subject: [PATCH] Use a single byte for alignment --- src/asm/output.c | 2 +- src/asm/section.c | 18 +++++++++--------- src/link/object.c | 8 ++++---- src/rgbds.5 | 3 +-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/asm/output.c b/src/asm/output.c index 33e944ba..f445a1bd 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -180,7 +180,7 @@ static void writesection(struct Section const *pSect, FILE *f) 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); diff --git a/src/asm/section.c b/src/asm/section.c index a919d759..d3ac304f 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -86,7 +86,7 @@ struct Section *out_FindSectionByName(const char *pzName) */ 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 @@ static struct Section *getSection(char const *pzName, enum SectionType type, 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 @@ static struct Section *getSection(char const *pzName, enum SectionType type, 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 @@ static struct Section *getSection(char const *pzName, enum SectionType type, 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 @@ void out_NewSection(char const *pzName, uint32_t type, uint32_t org, 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 @@ void out_SetLoadSection(char const *name, uint32_t type, uint32_t org, 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; */ diff --git a/src/link/object.c b/src/link/object.c index 437aeca2..69043f47 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -279,10 +279,10 @@ static void readSection(FILE *file, struct Section *section, 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 */ diff --git a/src/rgbds.5 b/src/rgbds.5 index a5479c56..c8af1f3f 100644 --- a/src/rgbds.5 +++ b/src/rgbds.5 @@ -92,8 +92,7 @@ REPT NumberOfSections ; 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.