VarAction2: Detect and replace reverse subtract via temp storage

This commit is contained in:
Jonathan G Rennison
2022-05-27 03:14:07 +01:00
parent 381aa04660
commit 145536e1fd
3 changed files with 18 additions and 0 deletions

View File

@@ -5739,6 +5739,21 @@ static void NewSpriteGroup(ByteReader *buf)
replace_with_constant_load(0);
} else {
switch (adjust.operation) {
case DSGA_OP_SUB:
if (adjust.variable == 0x7D && adjust.shift_num == 0 && adjust.and_mask == 0xFFFFFFFF) {
DeterministicSpriteGroupAdjust &prev = group->adjusts[group->adjusts.size() - 2];
if (group->adjusts.size() >= 3 && prev.operation == DSGA_OP_RST) {
const DeterministicSpriteGroupAdjust &prev2 = group->adjusts[group->adjusts.size() - 3];
if (prev2.operation == DSGA_OP_STO && prev2.type == DSGA_TYPE_NONE && prev2.variable == 0x1A &&
prev2.shift_num == 0 && prev2.and_mask == adjust.parameter) {
/* Convert: store, load var, subtract stored --> (dead) store, reverse subtract var */
prev.operation = DSGA_OP_RSUB;
group->adjusts.pop_back();
break;
}
}
}
break;
case DSGA_OP_SMIN:
if (adjust.variable == 0x1A && adjust.shift_num == 0 && adjust.and_mask == 1) {
DeterministicSpriteGroupAdjust &prev = group->adjusts[group->adjusts.size() - 2];