Deduplicate value output function code

This commit is contained in:
ISSOtm
2020-02-09 16:10:58 +01:00
parent 2f60e0a59e
commit d9c1b66931

View File

@@ -261,15 +261,11 @@ void out_String(char const *s)
*/ */
void out_RelByte(struct Expression *expr) void out_RelByte(struct Expression *expr)
{ {
checkcodesection();
checksectionoverflow(1);
if (!rpn_isKnown(expr)) { if (!rpn_isKnown(expr)) {
pCurrentSection->tData[nPC] = 0;
out_CreatePatch(PATCHTYPE_BYTE, expr); out_CreatePatch(PATCHTYPE_BYTE, expr);
pCurrentSection->nPC++; out_AbsByte(0);
nPC++;
} else { } else {
absByteBypassCheck(expr->nVal); out_AbsByte(expr->nVal);
} }
rpn_Free(expr); rpn_Free(expr);
} }
@@ -293,14 +289,9 @@ static void absWord(uint16_t b)
*/ */
void out_RelWord(struct Expression *expr) void out_RelWord(struct Expression *expr)
{ {
checkcodesection();
checksectionoverflow(2);
if (!rpn_isKnown(expr)) { if (!rpn_isKnown(expr)) {
pCurrentSection->tData[nPC] = 0;
pCurrentSection->tData[nPC + 1] = 0;
out_CreatePatch(PATCHTYPE_WORD, expr); out_CreatePatch(PATCHTYPE_WORD, expr);
pCurrentSection->nPC += 2; absWord(0);
nPC += 2;
} else { } else {
absWord(expr->nVal); absWord(expr->nVal);
} }
@@ -313,7 +304,7 @@ void out_RelWord(struct Expression *expr)
static void absLong(uint32_t b) static void absLong(uint32_t b)
{ {
checkcodesection(); checkcodesection();
checksectionoverflow(sizeof(int32_t)); checksectionoverflow(4);
pCurrentSection->tData[nPC] = b & 0xFF; pCurrentSection->tData[nPC] = b & 0xFF;
pCurrentSection->tData[nPC + 1] = b >> 8; pCurrentSection->tData[nPC + 1] = b >> 8;
pCurrentSection->tData[nPC + 2] = b >> 16; pCurrentSection->tData[nPC + 2] = b >> 16;
@@ -328,16 +319,9 @@ static void absLong(uint32_t b)
*/ */
void out_RelLong(struct Expression *expr) void out_RelLong(struct Expression *expr)
{ {
checkcodesection();
checksectionoverflow(4);
if (!rpn_isKnown(expr)) { if (!rpn_isKnown(expr)) {
pCurrentSection->tData[nPC] = 0;
pCurrentSection->tData[nPC + 1] = 0;
pCurrentSection->tData[nPC + 2] = 0;
pCurrentSection->tData[nPC + 3] = 0;
out_CreatePatch(PATCHTYPE_LONG, expr); out_CreatePatch(PATCHTYPE_LONG, expr);
pCurrentSection->nPC += 4; absLong(0);
nPC += 4;
} else { } else {
absLong(expr->nVal); absLong(expr->nVal);
} }