From 1ab93a194e7242912929b08798447f91e831a090 Mon Sep 17 00:00:00 2001 From: Ben10do Date: Thu, 23 Feb 2017 15:00:57 +0000 Subject: [PATCH] Implement ALIGN keyword in rgbasm The ALIGN keyword specifies the number of bits that should be zero at the start of a section. It works in a simliar fashion to BANK. --- src/asm/asmy.y | 14 +++++++++++++- src/asm/globlex.c | 1 + src/asm/output.c | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/asm/asmy.y b/src/asm/asmy.y index a8b96f50..8d9f7e7a 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -442,7 +442,7 @@ void if_skip_to_endc( void ) %left T_OP_MUL T_OP_DIV T_OP_MOD %left T_OP_NOT %left T_OP_DEF -%left T_OP_BANK +%left T_OP_BANK T_OP_ALIGN %left T_OP_SIN %left T_OP_COS %left T_OP_TAN @@ -1095,6 +1095,10 @@ section: else yyerror("Address $%x not 16-bit", $6); } + | T_POP_SECTION string ',' sectiontype ',' T_OP_ALIGN '[' const ']' + { + out_NewAlignedSection($2, $4, $8, -1); + } | T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']' { bankrangecheck($2, $4, -1, $8); @@ -1106,6 +1110,14 @@ section: } bankrangecheck($2, $4, $6, $11); } + | T_POP_SECTION string ',' sectiontype ',' T_OP_ALIGN '[' const ']' ',' T_OP_BANK '[' const ']' + { + out_NewAlignedSection($2, $4, $8, $13); + } + | T_POP_SECTION string ',' sectiontype ',' T_OP_BANK '[' const ']' ',' T_OP_ALIGN '[' const ']' + { + out_NewAlignedSection($2, $4, $13, $8); + } ; sectiontype: diff --git a/src/asm/globlex.c b/src/asm/globlex.c index 9f9523a8..dd379277 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -267,6 +267,7 @@ struct sLexInitString staticstrings[] = { {"def", T_OP_DEF}, {"bank", T_OP_BANK}, + {"align", T_OP_ALIGN}, {"round", T_OP_ROUND}, {"ceil", T_OP_CEIL}, diff --git a/src/asm/output.c b/src/asm/output.c index 601dff76..e40f92c8 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -631,7 +631,10 @@ out_NewAbsSection(char *pzName, ULONG secttype, SLONG org, SLONG bank) void out_NewAlignedSection(char *pzName, ULONG secttype, SLONG alignment, SLONG bank) { - out_SetCurrentSection(out_FindSection(pzName, secttype, -1, bank, alignment)); + if (alignment < 0) { + yyerror("Alignment must not be negative."); + } + out_SetCurrentSection(out_FindSection(pzName, secttype, -1, bank, 1 << alignment)); } /*