From 08d635893221f7e7fcfdd3f39548f80f5b2d4c9d Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 29 Jan 2022 16:06:47 +0100 Subject: [PATCH] Fix local variable array member forwarding --- include/math.c | 12 +-- oscar64/Emulator.cpp | 4 +- oscar64/InterCode.cpp | 2 +- oscar64/NativeCodeGenerator.cpp | 9 +++ samples/hires/cube3d.c | 125 ++++++++++++++++++++++++++++++++ samples/hires/func3d.c | 2 - samples/hires/make.bat | 1 + 7 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 samples/hires/cube3d.c diff --git a/include/math.c b/include/math.c index 8ae35c2..f493791 100644 --- a/include/math.c +++ b/include/math.c @@ -217,23 +217,23 @@ float sqrt(float f) bool isinf(float f) { union { - float f; - int i[2]; + float f; + unsigned i[2]; } x; x.f = f; - return ((x.i[0] >> 7) & 0xff) == 0xff; + return ((x.i[1] >> 7) & 0xff) == 0xff; } bool isfinite(float f) { union { - float f; - int i[2]; + float f; + unsigned i[2]; } x; x.f = f; - return ((x.i[0] >> 7) & 0xff) != 0xff; + return ((x.i[1] >> 7) & 0xff) != 0xff; } diff --git a/oscar64/Emulator.cpp b/oscar64/Emulator.cpp index 187b134..940db68 100644 --- a/oscar64/Emulator.cpp +++ b/oscar64/Emulator.cpp @@ -647,10 +647,10 @@ int Emulator::Emulate(int startIP) if ((trace & 1) && ip == 0x0855) { - int accu = mMemory[BC_REG_ACCU] + 256 * mMemory[BC_REG_ACCU + 1]; + unsigned accu = mMemory[BC_REG_ACCU] + (mMemory[BC_REG_ACCU + 1] << 8) + (mMemory[BC_REG_ACCU + 2] << 16) + (mMemory[BC_REG_ACCU + 3] << 24); int ptr = mMemory[BC_REG_ADDR] + 256 * mMemory[BC_REG_ADDR + 1]; int sp = mMemory[BC_REG_STACK] + 256 * mMemory[BC_REG_STACK + 1]; - printf("%04x (A:%04x P:%04x S:%04x) %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x : %04x\n", addr, accu, ptr, sp, + printf("%04x (A:%08x P:%04x S:%04x) %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x : %04x\n", addr, accu, ptr, sp, mMemory[BC_REG_TMP + 0] + 256 * mMemory[BC_REG_TMP + 1], mMemory[BC_REG_TMP + 2] + 256 * mMemory[BC_REG_TMP + 3], mMemory[BC_REG_TMP + 4] + 256 * mMemory[BC_REG_TMP + 5], diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 9816254..bb485b4 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -5701,7 +5701,7 @@ static bool MatchingMem(const InterOperand& op1, const InterOperand& op2) case IM_LOCAL: case IM_FPARAM: case IM_PARAM: - return op1.mVarIndex == op2.mVarIndex; + return op1.mVarIndex == op2.mVarIndex && op1.mIntConst < op2.mIntConst + op2.mOperandSize && op2.mIntConst < op1.mIntConst + op1.mOperandSize; case IM_ABSOLUTE: return op1.mIntConst < op2.mIntConst + op2.mOperandSize && op2.mIntConst < op1.mIntConst + op1.mOperandSize; case IM_GLOBAL: diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 6f38db5..4e17919 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -14023,6 +14023,15 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(int pass) mIns[i + 2].mMode = ASMIM_ABSOLUTE_X; progress = true; } + else if ( + mIns[i + 0].mType == ASMIT_TAY && + mIns[i + 1].mType == ASMIT_TAX && + mIns[i + 2].mMode == ASMIM_ABSOLUTE_Y && (mIns[i + 2].mLive & LIVE_CPU_REG_X) && !(mIns[i + 2].mLive & LIVE_CPU_REG_Y)) + { + mIns[i + 0].mType = ASMIT_NOP; mIns[i + 0].mMode = ASMIM_IMPLIED; + mIns[i + 2].mMode = ASMIM_ABSOLUTE_X; + progress = true; + } else if ( mIns[i + 0].mType == ASMIT_LDA && (mIns[i + 0].mMode == ASMIM_ZERO_PAGE || mIns[i + 0].mMode == ASMIM_ABSOLUTE) && mIns[i + 1].mType == ASMIT_STA && (mIns[i + 1].mMode == ASMIM_ZERO_PAGE || mIns[i + 1].mMode == ASMIM_ABSOLUTE) && diff --git a/samples/hires/cube3d.c b/samples/hires/cube3d.c new file mode 100644 index 0000000..ff04fc6 --- /dev/null +++ b/samples/hires/cube3d.c @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +char * const Color = (char *)0xd000; +char * const Hires = (char *)0xe000; + +Bitmap Screen; + +void init(void) +{ + mmap_trampoline(); + mmap_set(MMAP_RAM); + + memset(Color, 0x01, 1000); + memset(Hires, 0x00, 8000); + + mmap_set(MMAP_NO_ROM); + + vic_setmode(VICM_HIRES, Color, Hires); + + vic.color_border = VCOL_WHITE; + + bm_init(&Screen, Hires, 40, 25); +} + +void done(void) +{ + mmap_set(MMAP_ROM); + + getch(); + + vic_setmode(VICM_TEXT, (char *)0x0400, (char *)0x1000); +} + +Matrix4 wmat, pmat, tmat, rmat; +Vector3 corners[8]; +ClipRect cr = {0, 0, 320, 200}; + + +struct Point +{ + int x, y; +}; + +Point tcorners[8], pcorners[8]; + +void drawCube(void) +{ + for(char i=0; i<8; i++) + { + if (!(i & 1)) + bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 1].x, tcorners[i | 1].y, 0xff, LINOP_XOR); + if (!(i & 2)) + bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 2].x, tcorners[i | 2].y, 0xff, LINOP_XOR); + if (!(i & 4)) + bm_line(&Screen, &cr, tcorners[i].x, tcorners[i].y, tcorners[i | 4].x, tcorners[i | 4].y, 0xff, LINOP_XOR); + pcorners[i] = tcorners[i]; + } +} + +void hideCube(void) +{ + for(char i=0; i<8; i++) + { + if (!(i & 1)) + bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 1].x, pcorners[i | 1].y, 0xff, LINOP_XOR); + if (!(i & 2)) + bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 2].x, pcorners[i | 2].y, 0xff, LINOP_XOR); + if (!(i & 4)) + bm_line(&Screen, &cr, pcorners[i].x, pcorners[i].y, pcorners[i | 4].x, pcorners[i | 4].y, 0xff, LINOP_XOR); + } +} + +int main(void) +{ + init(); + + mat4_ident(&wmat); + mat4_make_perspective(&pmat, 0.5 * PI, 1.0, 0.0, 200.0); + + mat4_scale(&wmat, 1); + + for(int k=0; k<100; k++) + { + mat4_set_rotate_x(&rmat, 0.1 * k); + mat4_set_rotate_y(&tmat, 0.06 * k); + mat4_rmmul(&rmat, &tmat); + + mat4_rmmul(&rmat, &wmat); + rmat.m[14] += 5.0; + + tmat = pmat; + mat4_mmul(&tmat, &rmat); + + for(char i=0; i<8; i++) + { + vec3_set(corners + i, + (i & 1) ? -1.0 : 1.0, + (i & 2) ? -1.0 : 1.0, + (i & 4) ? -1.0 : 1.0); + } + + + for(char i=0; i<8; i++) + { + Vector3 vd; + vec3_project(&vd, &rmat, corners + i); + tcorners[i].x = (int)(vd.v[0] * 100) + 160; + tcorners[i].y = (int)(vd.v[1] * 100) + 100; + } + + hideCube(); + drawCube(); + } + + done(); + + return 0; +} \ No newline at end of file diff --git a/samples/hires/func3d.c b/samples/hires/func3d.c index fdb8b04..243e763 100644 --- a/samples/hires/func3d.c +++ b/samples/hires/func3d.c @@ -107,8 +107,6 @@ int main(void) mat4_ident(&wmat); mat4_make_perspective(&pmat, 0.5 * PI, 1.0, 0.0, 200.0); - bm_put - for(int ix=0; ix