mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-23 03:22:08 +00:00
Allow to request BANK() of sections and PC
The bank of a section can be requested with `BANK("Section Name")`, and
the bank of the current section with `BANK(@)`. In both cases, the bank
number is resolved by the linker.
New commands have been added to the list of RPN commands of object
files, and the rest has been moved so that new additions don't force a
new change in the number of the enumerations.
Increase object file version, as it is now incompatible with the old
format.
Update manpages to reflect the new ways of using `BANK()` and the new
format of the object files.
Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -1173,7 +1173,13 @@ relocconst : T_ID
|
||||
| T_OP_LOW '(' relocconst ')' { rpn_LOW(&$$, &$3); }
|
||||
| T_OP_BANK '(' T_ID ')'
|
||||
{
|
||||
rpn_Bank(&$$, $3);
|
||||
/* '@' is also a T_ID, it is handled here. */
|
||||
rpn_BankSymbol(&$$, $3);
|
||||
$$.nVal = 0;
|
||||
}
|
||||
| T_OP_BANK '(' string ')'
|
||||
{
|
||||
rpn_BankSection(&$$, $3);
|
||||
$$.nVal = 0;
|
||||
}
|
||||
| T_OP_DEF {
|
||||
|
||||
@@ -419,7 +419,7 @@ void createpatch(uint32_t type, struct Expression *expr)
|
||||
rpnexpr[rpnptr++] = symptr >> 24;
|
||||
}
|
||||
break;
|
||||
case RPN_BANK:
|
||||
case RPN_BANK_SYM:
|
||||
{
|
||||
struct sSymbol *sym;
|
||||
|
||||
@@ -432,13 +432,25 @@ void createpatch(uint32_t type, struct Expression *expr)
|
||||
break;
|
||||
|
||||
symptr = addsymbol(sym);
|
||||
rpnexpr[rpnptr++] = RPN_BANK;
|
||||
rpnexpr[rpnptr++] = RPN_BANK_SYM;
|
||||
rpnexpr[rpnptr++] = symptr & 0xFF;
|
||||
rpnexpr[rpnptr++] = symptr >> 8;
|
||||
rpnexpr[rpnptr++] = symptr >> 16;
|
||||
rpnexpr[rpnptr++] = symptr >> 24;
|
||||
break;
|
||||
}
|
||||
case RPN_BANK_SECT:
|
||||
{
|
||||
uint16_t b;
|
||||
|
||||
rpnexpr[rpnptr++] = RPN_BANK_SECT;
|
||||
|
||||
do {
|
||||
b = rpn_PopByte(expr);
|
||||
rpnexpr[rpnptr++] = b & 0xFF;
|
||||
} while (b != 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
rpnexpr[rpnptr++] = rpndata;
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.\" Copyright (c) 2017 Antonio Nino Diaz <antonio_nd@outlook.com>
|
||||
.\" Copyright (c) 2017-2018 Antonio Nino Diaz <antonio_nd@outlook.com>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -12,7 +12,7 @@
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd July 22, 2017
|
||||
.Dd January 7, 2018
|
||||
.Dt RGBASM 5
|
||||
.Os RGBDS Manual
|
||||
.Sh NAME
|
||||
@@ -969,9 +969,15 @@ There are a few other functions that do various useful things:
|
||||
.Pp
|
||||
.Bl -column ".Sy String" ".Sy String"
|
||||
.It Sy Name Ta Ta Ta Sy Operation
|
||||
.It Li BANK(label) Ta Returns the bank number label is in.
|
||||
The linker will have to resolve this so it can't be used when the expression has
|
||||
to be constant.
|
||||
.It Li BANK(\@/str/lbl) Ta Returns a bank number.
|
||||
If the argument is the symbol
|
||||
.Ic \@,
|
||||
this function returns the bank of the current section.
|
||||
If the argument is a string, it returns the bank of the section that has that
|
||||
name.
|
||||
If the argument is a label, it returns the bank number the label is in.
|
||||
For labels, as the linker has to resolve this, it can't be used when the
|
||||
expression has to be constant.
|
||||
.It Li DEF(label) Ta Returns TRUE if label has been defined.
|
||||
.It Li HIGH(r16/cnst/lbl) Ta Returns the top 8 bits of the operand if it is a
|
||||
label or constant, or the top 8-bit register if it is a 16-bit register.
|
||||
|
||||
@@ -108,8 +108,27 @@ void rpn_Symbol(struct Expression *expr, char *tzSym)
|
||||
}
|
||||
}
|
||||
|
||||
void rpn_Bank(struct Expression *expr, char *tzSym)
|
||||
void rpn_BankSelf(struct Expression *expr)
|
||||
{
|
||||
rpn_Reset(expr);
|
||||
|
||||
/*
|
||||
* This symbol is not really relocatable, but this makes the assembler
|
||||
* write this expression as a RPN patch to the object file.
|
||||
*/
|
||||
expr->isReloc = 1;
|
||||
|
||||
pushbyte(expr, RPN_BANK_SELF);
|
||||
}
|
||||
|
||||
void rpn_BankSymbol(struct Expression *expr, char *tzSym)
|
||||
{
|
||||
/* The @ symbol is treated differently. */
|
||||
if (sym_FindSymbol(tzSym) == pPCSymbol) {
|
||||
rpn_BankSelf(expr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sym_isConstant(tzSym)) {
|
||||
rpn_Reset(expr);
|
||||
|
||||
@@ -120,7 +139,7 @@ void rpn_Bank(struct Expression *expr, char *tzSym)
|
||||
sym_GetValue(tzSym);
|
||||
|
||||
expr->isReloc = 1;
|
||||
pushbyte(expr, RPN_BANK);
|
||||
pushbyte(expr, RPN_BANK_SYM);
|
||||
while (*tzSym)
|
||||
pushbyte(expr, *tzSym++);
|
||||
pushbyte(expr, 0);
|
||||
@@ -129,6 +148,22 @@ void rpn_Bank(struct Expression *expr, char *tzSym)
|
||||
}
|
||||
}
|
||||
|
||||
void rpn_BankSection(struct Expression *expr, char *tzSectionName)
|
||||
{
|
||||
rpn_Reset(expr);
|
||||
|
||||
/*
|
||||
* This symbol is not really relocatable, but this makes the assembler
|
||||
* write this expression as a RPN patch to the object file.
|
||||
*/
|
||||
expr->isReloc = 1;
|
||||
|
||||
pushbyte(expr, RPN_BANK_SECT);
|
||||
while (*tzSectionName)
|
||||
pushbyte(expr, *tzSectionName++);
|
||||
pushbyte(expr, 0);
|
||||
}
|
||||
|
||||
void rpn_CheckHRAM(struct Expression *expr, const struct Expression *src)
|
||||
{
|
||||
*expr = *src;
|
||||
|
||||
Reference in New Issue
Block a user