mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 11:12:07 +00:00
@@ -774,6 +774,26 @@ simple_pseudoop : include
|
||||
| popo
|
||||
| pusho
|
||||
| opt
|
||||
| align
|
||||
;
|
||||
|
||||
align : T_OP_ALIGN uconst {
|
||||
if ($2 > 16)
|
||||
yyerror("Alignment must be between 0 and 16, not %u",
|
||||
$2);
|
||||
else
|
||||
sect_AlignPC($2, 0);
|
||||
}
|
||||
| T_OP_ALIGN uconst ',' uconst {
|
||||
if ($2 > 16)
|
||||
yyerror("Alignment must be between 0 and 16, not %u",
|
||||
$2);
|
||||
else if ($4 >= 1 << $2)
|
||||
yyerror("Offset must be between 0 and %u, not %u",
|
||||
(1 << $2) - 1, $4);
|
||||
else
|
||||
sect_AlignPC($2, $4);
|
||||
}
|
||||
;
|
||||
|
||||
opt : T_POP_OPT {
|
||||
|
||||
@@ -354,6 +354,28 @@ uint32_t sect_GetOutputOffset(void)
|
||||
return curOffset + loadOffset;
|
||||
}
|
||||
|
||||
void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
||||
{
|
||||
struct Section *sect = sect_GetSymbolSection();
|
||||
|
||||
if (sect->nOrg != -1) {
|
||||
if ((sym_GetValue(pPCSymbol) - offset) % (1 << alignment))
|
||||
yyerror("Section's fixed address fails required alignment (PC = $%04x)",
|
||||
sym_GetValue(pPCSymbol));
|
||||
} else if (sect->nAlign != 0) {
|
||||
if ((((sect->alignOfs + curOffset) % (1 << sect->nAlign)) - offset) % (1 << alignment)) {
|
||||
yyerror("Section's alignment fails required alignment (offset from section start = $%04x)",
|
||||
curOffset);
|
||||
} else if (alignment > sect->nAlign) {
|
||||
sect->nAlign = alignment;
|
||||
sect->alignOfs = (offset - curOffset) % (1 << alignment);
|
||||
}
|
||||
} else {
|
||||
sect->nAlign = alignment;
|
||||
sect->alignOfs = offset;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void growSection(uint32_t growth)
|
||||
{
|
||||
curOffset += growth;
|
||||
|
||||
Reference in New Issue
Block a user