mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Unify all section declarations
This commit is contained in:
@@ -17,12 +17,14 @@ struct Section {
|
|||||||
uint8_t *tData;
|
uint8_t *tData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SectionSpec {
|
||||||
|
int32_t bank;
|
||||||
|
int32_t alignment;
|
||||||
|
};
|
||||||
|
|
||||||
struct Section *out_FindSectionByName(const char *pzName);
|
struct Section *out_FindSectionByName(const char *pzName);
|
||||||
void out_NewSection(char const *pzName, uint32_t secttype);
|
void out_NewSection(char const *pzName, uint32_t secttype, int32_t org,
|
||||||
void out_NewAbsSection(char const *pzName, uint32_t secttype, int32_t org,
|
struct SectionSpec const *attributes);
|
||||||
int32_t bank);
|
|
||||||
void out_NewAlignedSection(char const *pzName, uint32_t secttype,
|
|
||||||
int32_t alignment, int32_t bank);
|
|
||||||
|
|
||||||
void out_AbsByte(int32_t b);
|
void out_AbsByte(int32_t b);
|
||||||
void out_AbsByteGroup(char const *s, int32_t length);
|
void out_AbsByteGroup(char const *s, int32_t length);
|
||||||
|
|||||||
@@ -37,20 +37,6 @@ char *tzNewMacro;
|
|||||||
uint32_t ulNewMacroSize;
|
uint32_t ulNewMacroSize;
|
||||||
int32_t nPCOffset;
|
int32_t nPCOffset;
|
||||||
|
|
||||||
static void bankrangecheck(char *name, uint32_t secttype, int32_t org,
|
|
||||||
int32_t bank)
|
|
||||||
{
|
|
||||||
if (secttype != SECTTYPE_ROMX && secttype != SECTTYPE_VRAM
|
|
||||||
&& secttype != SECTTYPE_SRAM && secttype != SECTTYPE_WRAMX)
|
|
||||||
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
|
|
||||||
else if (bank < bankranges[secttype][0] || bank > bankranges[secttype][1])
|
|
||||||
yyerror("%s bank value $%x out of range ($%x to $%x)",
|
|
||||||
typeNames[secttype], bank, bankranges[secttype][0],
|
|
||||||
bankranges[secttype][1]);
|
|
||||||
|
|
||||||
out_NewAbsSection(name, secttype, org, bank);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t symvaluetostring(char *dest, size_t maxLength, char *symName,
|
size_t symvaluetostring(char *dest, size_t maxLength, char *symName,
|
||||||
const char *mode)
|
const char *mode)
|
||||||
{
|
{
|
||||||
@@ -509,6 +495,7 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
|
|||||||
char tzString[MAXSTRLEN + 1];
|
char tzString[MAXSTRLEN + 1];
|
||||||
struct Expression sVal;
|
struct Expression sVal;
|
||||||
int32_t nConstValue;
|
int32_t nConstValue;
|
||||||
|
struct SectionSpec sectSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
%type <sVal> relocconst
|
%type <sVal> relocconst
|
||||||
@@ -521,6 +508,9 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
|
|||||||
|
|
||||||
%type <tzString> string
|
%type <tzString> string
|
||||||
|
|
||||||
|
%type <nConstValue> sectorg
|
||||||
|
%type <sectSpec> sectattrs
|
||||||
|
|
||||||
%token <nConstValue> T_NUMBER
|
%token <nConstValue> T_NUMBER
|
||||||
%token <tzString> T_STRING
|
%token <tzString> T_STRING
|
||||||
|
|
||||||
@@ -1384,38 +1374,9 @@ string : T_STRING
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
section : T_POP_SECTION string comma sectiontype
|
section : T_POP_SECTION string comma sectiontype sectorg sectattrs
|
||||||
{
|
{
|
||||||
out_NewSection($2, $4);
|
out_NewSection($2, $4, $5, &$6);
|
||||||
}
|
|
||||||
| T_POP_SECTION string comma sectiontype '[' uconst ']'
|
|
||||||
{
|
|
||||||
if (($6 >= 0) && ($6 < 0x10000))
|
|
||||||
out_NewAbsSection($2, $4, $6, -1);
|
|
||||||
else
|
|
||||||
yyerror("Address $%x not 16-bit", $6);
|
|
||||||
}
|
|
||||||
| T_POP_SECTION string comma sectiontype comma T_OP_ALIGN '[' uconst ']'
|
|
||||||
{
|
|
||||||
out_NewAlignedSection($2, $4, $8, -1);
|
|
||||||
}
|
|
||||||
| T_POP_SECTION string comma sectiontype comma T_OP_BANK '[' uconst ']'
|
|
||||||
{
|
|
||||||
bankrangecheck($2, $4, -1, $8);
|
|
||||||
}
|
|
||||||
| T_POP_SECTION string comma sectiontype '[' uconst ']' comma T_OP_BANK '[' uconst ']'
|
|
||||||
{
|
|
||||||
if (($6 < 0) || ($6 > 0x10000))
|
|
||||||
yyerror("Address $%x not 16-bit", $6);
|
|
||||||
bankrangecheck($2, $4, $6, $11);
|
|
||||||
}
|
|
||||||
| T_POP_SECTION string comma sectiontype comma T_OP_ALIGN '[' uconst ']' comma T_OP_BANK '[' uconst ']'
|
|
||||||
{
|
|
||||||
out_NewAlignedSection($2, $4, $8, $13);
|
|
||||||
}
|
|
||||||
| T_POP_SECTION string comma sectiontype comma T_OP_BANK '[' uconst ']' comma T_OP_ALIGN '[' uconst ']'
|
|
||||||
{
|
|
||||||
out_NewAlignedSection($2, $4, $13, $8);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1449,6 +1410,36 @@ sectiontype : T_SECT_WRAM0 { $$ = SECTTYPE_WRAM0; }
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
sectorg : { $$ = -1; }
|
||||||
|
| '[' uconst ']'
|
||||||
|
{
|
||||||
|
if ($2 < 0 || $2 >= 0x10000)
|
||||||
|
yyerror("Address $%x is not 16-bit", $2);
|
||||||
|
else
|
||||||
|
$$ = $2;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
sectattrs :
|
||||||
|
{
|
||||||
|
$$.alignment = 0;
|
||||||
|
$$.bank = -1;
|
||||||
|
}
|
||||||
|
| sectattrs comma T_OP_ALIGN '[' uconst ']'
|
||||||
|
{
|
||||||
|
if ($5 < 0 || $5 > 16)
|
||||||
|
yyerror("Alignment must be between 0 and 16 bits, not %u",
|
||||||
|
$5);
|
||||||
|
else
|
||||||
|
$$.alignment = $5;
|
||||||
|
}
|
||||||
|
| sectattrs comma T_OP_BANK '[' uconst ']'
|
||||||
|
{
|
||||||
|
/* We cannot check the validity of this now */
|
||||||
|
$$.bank = $5;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
cpu_command : z80_adc
|
cpu_command : z80_adc
|
||||||
| z80_add
|
| z80_add
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/section.h"
|
||||||
#include "asm/symbol.h"
|
#include "asm/symbol.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
#include "asm/main.h"
|
#include "asm/main.h"
|
||||||
#include "asm/rpn.h"
|
#include "asm/rpn.h"
|
||||||
|
#include "asm/section.h"
|
||||||
#include "asm/warning.h"
|
#include "asm/warning.h"
|
||||||
|
|
||||||
#include "extern/err.h"
|
#include "extern/err.h"
|
||||||
|
|||||||
@@ -156,31 +156,23 @@ static void setCurrentSection(struct Section *pSect)
|
|||||||
/*
|
/*
|
||||||
* Set the current section by name and type
|
* Set the current section by name and type
|
||||||
*/
|
*/
|
||||||
void out_NewSection(char const *pzName, uint32_t secttype)
|
void out_NewSection(char const *pzName, uint32_t secttype, int32_t org,
|
||||||
|
struct SectionSpec const *attributes)
|
||||||
{
|
{
|
||||||
setCurrentSection(findSection(pzName, secttype, -1, -1, 1));
|
if (attributes->bank != -1) {
|
||||||
}
|
if (secttype != SECTTYPE_ROMX && secttype != SECTTYPE_VRAM
|
||||||
|
&& secttype != SECTTYPE_SRAM && secttype != SECTTYPE_WRAMX)
|
||||||
|
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
|
||||||
|
else if (attributes->bank < bankranges[secttype][0]
|
||||||
|
|| attributes->bank > bankranges[secttype][1])
|
||||||
|
yyerror("%s bank value $%x out of range ($%x to $%x)",
|
||||||
|
typeNames[secttype], attributes->bank,
|
||||||
|
bankranges[secttype][0],
|
||||||
|
bankranges[secttype][1]);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
setCurrentSection(findSection(pzName, secttype, org, attributes->bank,
|
||||||
* Set the current section by name and type
|
1 << attributes->alignment));
|
||||||
*/
|
|
||||||
void out_NewAbsSection(char const *pzName, uint32_t secttype, int32_t org,
|
|
||||||
int32_t bank)
|
|
||||||
{
|
|
||||||
setCurrentSection(findSection(pzName, secttype, org, bank, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the current section by name and type, using a given byte alignment
|
|
||||||
*/
|
|
||||||
void out_NewAlignedSection(char const *pzName, uint32_t secttype,
|
|
||||||
int32_t alignment, int32_t bank)
|
|
||||||
{
|
|
||||||
if (alignment < 0 || alignment > 16)
|
|
||||||
yyerror("Alignment must be between 0-16 bits.");
|
|
||||||
|
|
||||||
setCurrentSection(findSection(pzName, secttype, -1, bank,
|
|
||||||
1 << alignment));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user