Fix error swapping global variables with negation

This commit is contained in:
drmortalwombat 2022-01-25 21:45:33 +01:00
parent 0ea87ea322
commit 792751e3a4
3 changed files with 43 additions and 14 deletions

View File

@ -9102,7 +9102,7 @@ void InterCodeProcedure::Disassemble(FILE* file)
void InterCodeProcedure::Disassemble(const char* name, bool dumpSets)
{
#if 1
#if 0
#ifdef _WIN32
FILE* file;
static bool initial = true;

View File

@ -10069,6 +10069,7 @@ bool NativeCodeBasicBlock::MoveAbsoluteLoadStoreUp(int at)
{
mIns[j].mLive |= LIVE_CPU_REG_A;
mIns.Insert(j + 1, mIns[at + 1]);
mIns[j + 1].mLive |= LIVE_CPU_REG_A;
mIns[at + 2].mType = ASMIT_NOP;
mIns[at + 2].mMode = ASMIM_IMPLIED;
return true;
@ -10077,6 +10078,8 @@ bool NativeCodeBasicBlock::MoveAbsoluteLoadStoreUp(int at)
return false;
if (mIns[j].ChangesGlobalMemory())
return false;
if (mIns[j].SameEffectiveAddress(mIns[at + 1]))
return false;
j--;
}
@ -13420,6 +13423,26 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(int pass)
mIns[i + 2].mType = ASMIT_NOP; mIns[i + 2].mMode = ASMIM_IMPLIED;
progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_TAX &&
!mIns[i + 1].ChangesXReg() && !mIns[i + 1].UsesAccu() &&
mIns[i + 2].mType == ASMIT_STX && !(mIns[i + 2].mLive & LIVE_CPU_REG_X))
{
mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED;
mIns[i + 2].mType = ASMIT_STA;
mIns[i + 1].mLive |= LIVE_CPU_REG_A;
progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_TAY &&
!mIns[i + 1].ChangesYReg() && !mIns[i + 1].UsesAccu() &&
mIns[i + 2].mType == ASMIT_STY && !(mIns[i + 2].mLive & LIVE_CPU_REG_Y))
{
mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED;
mIns[i + 2].mType = ASMIT_STA;
mIns[i + 1].mLive |= LIVE_CPU_REG_A;
progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_SEC &&
mIns[i + 1].mType == ASMIT_TXA &&

View File

@ -35,7 +35,8 @@ void maze_init(void)
}
static char zxdist[] = {18, 6, 3, 2, 1, 0};
static char zxdist0[] = {18, 6, 4, 3, 2, 1, 0};
static char zxdist1[] = { 9, 5, 3, 2, 1, 0, 0};
// Put one char on screen
inline void screen_put(byte x, byte y, char ch, char color)
@ -56,11 +57,11 @@ inline char screen_get(byte x, byte y)
sbyte px = 1, py = 3, dx = 1, dy = 0;
void maze_draw(void)
void maze_draw(const char * zxdist)
{
sbyte ix = px, iy = py;
sbyte sx = 0;
for(char i=0; i<6; i++)
for(char i=0; i<7; i++)
{
sbyte tx = 20 - zxdist[i];
@ -167,17 +168,19 @@ int main(void)
{
float z = 0.5 + i;
float x = 9.0 / z;
printf("%d : %f / %f : %d\n", i, z, x, (int)x);
printf("%d : %f / %f : %d\n", i, z, x, (int)(x + 0.5));
}
return 0;
#endif
#else
bool rotate = false;
for(;;)
{
maze_draw();
maze_draw(zxdist0);
joy_poll(1);
if (joyy[1])
{
sbyte tx = px - dx * joyy[1];
sbyte ty = py - dy * joyy[1];
@ -185,13 +188,15 @@ int main(void)
{
px = tx;
py = ty;
maze_draw(zxdist1);
}
}
if (!rotate)
{
if (joyx[1] == 1)
{
sbyte t = dx; dx = - dy; dy = t;
sbyte t = dx; dx = -dy; dy = t;
rotate = true;
}
else if (joyx[1] == -1)
@ -205,6 +210,7 @@ int main(void)
rotate = false;
}
}
#endif
return 0;
}