mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Implement HIGH() and LOW() operators
They work with the 16-bit registers BC, DE and HL, returning the corresponding 8-bit register. HIGH() works with AF as well, returning A. They also work with any kind of constant or symbol, generating a RPN patch in the object file if the value is not defined at assembly time. They work with macro arguments as well. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -182,6 +182,46 @@ rpn_LOGAND(struct Expression * expr, struct Expression * src1,
|
||||
pushbyte(expr, RPN_LOGAND);
|
||||
}
|
||||
|
||||
void
|
||||
rpn_HIGH(struct Expression * expr, struct Expression * src)
|
||||
{
|
||||
*expr = *src;
|
||||
|
||||
expr->nVal = (expr->nVal >> 8) & 0xFF;
|
||||
|
||||
pushbyte(expr, RPN_CONST);
|
||||
pushbyte(expr, 8);
|
||||
pushbyte(expr, 0);
|
||||
pushbyte(expr, 0);
|
||||
pushbyte(expr, 0);
|
||||
|
||||
pushbyte(expr, RPN_SHR);
|
||||
|
||||
pushbyte(expr, RPN_CONST);
|
||||
pushbyte(expr, 0xFF);
|
||||
pushbyte(expr, 0);
|
||||
pushbyte(expr, 0);
|
||||
pushbyte(expr, 0);
|
||||
|
||||
pushbyte(expr, RPN_AND);
|
||||
}
|
||||
|
||||
void
|
||||
rpn_LOW(struct Expression * expr, struct Expression * src)
|
||||
{
|
||||
*expr = *src;
|
||||
|
||||
expr->nVal = expr->nVal & 0xFF;
|
||||
|
||||
pushbyte(expr, RPN_CONST);
|
||||
pushbyte(expr, 0xFF);
|
||||
pushbyte(expr, 0);
|
||||
pushbyte(expr, 0);
|
||||
pushbyte(expr, 0);
|
||||
|
||||
pushbyte(expr, RPN_AND);
|
||||
}
|
||||
|
||||
void
|
||||
rpn_LOGEQU(struct Expression * expr, struct Expression * src1,
|
||||
struct Expression * src2)
|
||||
|
||||
Reference in New Issue
Block a user