Use a single byte for alignment

This commit is contained in:
ISSOtm
2020-04-07 21:15:55 +02:00
parent e098bf47ba
commit e82ad21704
4 changed files with 15 additions and 16 deletions

View File

@@ -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);

View File

@@ -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; */

View File

@@ -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 */

View File

@@ -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.