mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Make writing patches not affect the expression
This also removes one int member from the struct that shouldn't be there
This commit is contained in:
@@ -19,7 +19,7 @@ extern char *tzObjectname;
|
||||
extern struct Section *pSectionList, *pCurrentSection;
|
||||
|
||||
void out_SetFileName(char *s);
|
||||
void out_CreatePatch(uint32_t type, struct Expression *expr);
|
||||
void out_CreatePatch(uint32_t type, struct Expression const *expr);
|
||||
void out_WriteObject(void);
|
||||
|
||||
#endif /* RGBDS_ASM_OUTPUT_H */
|
||||
|
||||
@@ -25,8 +25,6 @@ struct Expression {
|
||||
uint32_t nRPNCapacity; // Size of the `tRPN` buffer
|
||||
uint32_t nRPNLength; // Used size of the `tRPN` buffer
|
||||
uint32_t nRPNPatchSize; // Size the expression will take in the obj file
|
||||
// FIXME: does this need to be part of the struct?
|
||||
uint32_t nRPNOut; // How many bytes have been written
|
||||
};
|
||||
|
||||
/* FIXME: Should be defined in `asmy.h`, but impossible with POSIX Yacc */
|
||||
@@ -44,7 +42,6 @@ void rpn_HIGH(struct Expression *expr, const struct Expression *src);
|
||||
void rpn_LOW(struct Expression *expr, const struct Expression *src);
|
||||
void rpn_UNNEG(struct Expression *expr, const struct Expression *src);
|
||||
void rpn_UNNOT(struct Expression *expr, const struct Expression *src);
|
||||
uint16_t rpn_PopByte(struct Expression *expr);
|
||||
void rpn_BankSymbol(struct Expression *expr, char *tzSym);
|
||||
void rpn_BankSection(struct Expression *expr, char *tzSectionName);
|
||||
void rpn_BankSelf(struct Expression *expr);
|
||||
|
||||
@@ -310,10 +310,9 @@ struct Patch *allocpatch(void)
|
||||
/*
|
||||
* Create a new patch (includes the rpn expr)
|
||||
*/
|
||||
void out_CreatePatch(uint32_t type, struct Expression *expr)
|
||||
void out_CreatePatch(uint32_t type, struct Expression const *expr)
|
||||
{
|
||||
struct Patch *pPatch;
|
||||
uint16_t rpndata;
|
||||
uint8_t *rpnexpr;
|
||||
char tzSym[512];
|
||||
uint32_t rpnptr = 0, symptr;
|
||||
@@ -328,19 +327,22 @@ void out_CreatePatch(uint32_t type, struct Expression *expr)
|
||||
fstk_DumpToStr(pPatch->tzFilename, sizeof(pPatch->tzFilename));
|
||||
pPatch->nOffset = pCurrentSection->nPC;
|
||||
|
||||
while ((rpndata = rpn_PopByte(expr)) != 0xDEAD) {
|
||||
for (size_t offset = 0; offset < expr->nRPNLength; ) {
|
||||
#define popbyte(expr) (expr)->tRPN[offset++]
|
||||
uint8_t rpndata = popbyte(expr);
|
||||
|
||||
switch (rpndata) {
|
||||
case RPN_CONST:
|
||||
rpnexpr[rpnptr++] = RPN_CONST;
|
||||
rpnexpr[rpnptr++] = rpn_PopByte(expr);
|
||||
rpnexpr[rpnptr++] = rpn_PopByte(expr);
|
||||
rpnexpr[rpnptr++] = rpn_PopByte(expr);
|
||||
rpnexpr[rpnptr++] = rpn_PopByte(expr);
|
||||
rpnexpr[rpnptr++] = popbyte(expr);
|
||||
rpnexpr[rpnptr++] = popbyte(expr);
|
||||
rpnexpr[rpnptr++] = popbyte(expr);
|
||||
rpnexpr[rpnptr++] = popbyte(expr);
|
||||
break;
|
||||
case RPN_SYM:
|
||||
{
|
||||
symptr = 0;
|
||||
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0)
|
||||
while ((tzSym[symptr++] = popbyte(expr)) != 0)
|
||||
;
|
||||
|
||||
struct sSymbol const *sym = sym_FindSymbol(tzSym);
|
||||
@@ -371,7 +373,7 @@ void out_CreatePatch(uint32_t type, struct Expression *expr)
|
||||
struct sSymbol *sym;
|
||||
|
||||
symptr = 0;
|
||||
while ((tzSym[symptr++] = rpn_PopByte(expr)) != 0)
|
||||
while ((tzSym[symptr++] = popbyte(expr)) != 0)
|
||||
;
|
||||
|
||||
sym = sym_FindSymbol(tzSym);
|
||||
@@ -393,7 +395,7 @@ void out_CreatePatch(uint32_t type, struct Expression *expr)
|
||||
rpnexpr[rpnptr++] = RPN_BANK_SECT;
|
||||
|
||||
do {
|
||||
b = rpn_PopByte(expr);
|
||||
b = popbyte(expr);
|
||||
rpnexpr[rpnptr++] = b & 0xFF;
|
||||
} while (b != 0);
|
||||
break;
|
||||
@@ -402,6 +404,7 @@ void out_CreatePatch(uint32_t type, struct Expression *expr)
|
||||
rpnexpr[rpnptr++] = rpndata;
|
||||
break;
|
||||
}
|
||||
#undef popbyte
|
||||
}
|
||||
|
||||
assert(rpnptr == expr->nRPNPatchSize);
|
||||
|
||||
@@ -81,7 +81,6 @@ void rpn_Init(struct Expression *expr)
|
||||
expr->nRPNCapacity = 0;
|
||||
expr->nRPNLength = 0;
|
||||
expr->nRPNPatchSize = 0;
|
||||
expr->nRPNOut = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -94,17 +93,6 @@ void rpn_Free(struct Expression *expr)
|
||||
rpn_Init(expr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the next rpn byte in expression
|
||||
*/
|
||||
uint16_t rpn_PopByte(struct Expression *expr)
|
||||
{
|
||||
if (expr->nRPNOut == expr->nRPNLength)
|
||||
return 0xDEAD;
|
||||
|
||||
return expr->tRPN[expr->nRPNOut++];
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine if the current expression is known at assembly time
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user