From 792751e3a45055360057fdf22a5fefcbf6ad3f2a Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 25 Jan 2022 21:45:33 +0100 Subject: [PATCH] Fix error swapping global variables with negation --- oscar64/InterCode.cpp | 2 +- oscar64/NativeCodeGenerator.cpp | 23 +++++++++++++++++++++++ samples/games/maze3d.c | 32 +++++++++++++++++++------------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 818815e..5d7704e 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -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; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index b6cb5e6..3b5a995 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -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 && diff --git a/samples/games/maze3d.c b/samples/games/maze3d.c index 870c904..2afe5c5 100644 --- a/samples/games/maze3d.c +++ b/samples/games/maze3d.c @@ -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,31 +168,35 @@ 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); - sbyte tx = px - dx * joyy[1]; - sbyte ty = py - dy * joyy[1]; - - if (maze[ty][tx] != '#') + if (joyy[1]) { - px = tx; - py = ty; + sbyte tx = px - dx * joyy[1]; + sbyte ty = py - dy * joyy[1]; + + if (maze[ty][tx] != '#') + { + 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; }