From 40f82ba6ec694d10dda2a8fd98aac19e31a5a131 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 1 Nov 2021 21:22:02 +0100 Subject: [PATCH] Fix byte table access --- autotest/autotest.bat | 3 + autotest/testint8cmp.c | 316 ++++++++++++++++++++++++++++++++ include/c64/keyboard.c | 3 + include/c64/types.h | 2 + include/c64/vic.c | 10 + include/c64/vic.h | 3 + oscar64/NativeCodeGenerator.cpp | 20 +- 7 files changed, 342 insertions(+), 15 deletions(-) create mode 100644 autotest/testint8cmp.c diff --git a/autotest/autotest.bat b/autotest/autotest.bat index 4eb3ce9..f4063a8 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -48,6 +48,9 @@ if %errorlevel% neq 0 goto :error call :test testint16cmp.c if %errorlevel% neq 0 goto :error +call :test testint8cmp.c +if %errorlevel% neq 0 goto :error + call :test testint32cmp.c if %errorlevel% neq 0 goto :error diff --git a/autotest/testint8cmp.c b/autotest/testint8cmp.c new file mode 100644 index 0000000..60416bc --- /dev/null +++ b/autotest/testint8cmp.c @@ -0,0 +1,316 @@ +#include +#include + +typedef signed char int8; + +bool beq(int8 a, int8 b) +{ + return a == b; +} + +bool blt(int8 a, int8 b) +{ + return a < b; +} + +bool bgt(int8 a, int8 b) +{ + return a > b; +} + +bool ble(int8 a, int8 b) +{ + return a <= b; +} + +bool bge(int8 a, int8 b) +{ + return a >= b; +} + +bool neq(int8 a, int8 b) +{ + return a == b; +} + +#pragma native(neq) + +bool nlt(int8 a, int8 b) +{ + return a < b; +} + +#pragma native(nlt) + +bool ngt(int8 a, int8 b) +{ + return a > b; +} + +#pragma native(ngt) + +bool nle(int8 a, int8 b) +{ + return a <= b; +} + +#pragma native(nle) + +bool nge(int8 a, int8 b) +{ + return a >= b; +} + +#pragma native(nge) + + + +bool beqz(int8 a) +{ + return a == 0; +} + +bool bltz(int8 a) +{ + return a < 0; +} + +bool bgtz(int8 a) +{ + return a > 0; +} + +bool blez(int8 a) +{ + return a <= 0; +} + +bool bgez(int8 a) +{ + return a >= 0; +} + +bool neqz(int8 a) +{ + return a == 0; +} + +#pragma native(neqz) + +bool nltz(int8 a) +{ + return a < 0; +} + +#pragma native(nltz) + +bool ngtz(int8 a) +{ + return a > 0; +} + +#pragma native(ngtz) + +bool nlez(int8 a) +{ + return a <= 0; +} + +#pragma native(nlez) + +bool ngez(int8 a) +{ + return a >= 0; +} + +#pragma native(ngez) + + + + +bool beq1(int8 a) +{ + return a == 1; +} + +bool blt1(int8 a) +{ + return a < 1; +} + +bool bgt1(int8 a) +{ + return a > 1; +} + +bool ble1(int8 a) +{ + return a <= 1; +} + +bool bge1(int8 a) +{ + return a >= 1; +} + +bool neq1(int8 a) +{ + return a == 1; +} + +#pragma native(neq1) + +bool nlt1(int8 a) +{ + return a < 1; +} + +#pragma native(nlt1) + +bool ngt1(int8 a) +{ + return a > 1; +} + +#pragma native(ngt1) + +bool nle1(int8 a) +{ + return a <= 1; +} + +#pragma native(nle1) + +bool nge1(int8 a) +{ + return a >= 1; +} + +#pragma native(nge1) + + + +void cmp(int8 a, int8 b) +{ + bool beqf = beq(a, b), bltf = blt(a, b), bgtf = bgt(a, b), blef = ble(a, b), bgef = bge(a, b); + bool neqf = neq(a, b), nltf = nlt(a, b), ngtf = ngt(a, b), nlef = nle(a, b), ngef = nge(a, b); + + printf("BYTE %d, %d : EQ %d LT %d GT %d\r", a, b, beqf, bltf, bgtf); + printf("NATIVE %d, %d : EQ %d LT %d GT %d\r", a, b, neqf, nltf, ngtf); + + assert(beqf == neqf); + assert(bltf == nltf); + assert(bgtf == ngtf); + assert(blef == nlef); + assert(bgef == ngef); +} + +void cmpz(int8 a) +{ + bool beqf = beqz(a), bltf = bltz(a), bgtf = bgtz(a), blef = blez(a), bgef = bgez(a); + bool neqf = neqz(a), nltf = nltz(a), ngtf = ngtz(a), nlef = nlez(a), ngef = ngez(a); + + printf("BYTE %d, 0 : EQ %d LT %d GT %d\r", a, beqf, bltf, bgtf); + printf("NATIVE %d, 0 : EQ %d LT %d GT %d\r", a, neqf, nltf, ngtf); + + assert(beqf == neqf); + assert(bltf == nltf); + assert(bgtf == ngtf); + assert(blef == nlef); + assert(bgef == ngef); +} + +void cmp1(int8 a) +{ + bool beqf = beq1(a), bltf = blt1(a), bgtf = bgt1(a), blef = ble1(a), bgef = bge1(a); + bool neqf = neq1(a), nltf = nlt1(a), ngtf = ngt1(a), nlef = nle1(a), ngef = nge1(a); + + printf("BYTE %d, 1 : EQ %d LT %d GT %d LE %d GE %d\r", a, beqf, bltf, bgtf, blef, bgef); + printf("NATIVE %d, 1 : EQ %d LT %d GT %d LE %d GE %d\r", a, neqf, nltf, ngtf, nlef, ngef); + + assert(beqf == neqf); + assert(bltf == nltf); + assert(bgtf == ngtf); + assert(blef == nlef); + assert(bgef == ngef); +} + +int main(void) +{ + cmp( 0, 1); + cmp( 0, -1); + cmp( 1, 0); + cmp(-1, 0); + + cmp(1, 1); + cmp(1, 2); + cmp(2, 1); + + cmp(-1, -1); + cmp(-1, -2); + cmp(-2, -1); + + cmp( 1, -1); + cmp( 1, -2); + cmp( 2, -1); + + cmp(-1, 1); + cmp(-1, 2); + cmp(-2, 1); + + + cmp( 0, 100); + cmp( 0, -100); + cmp( 100, 0); + cmp(-100, 0); + + cmp(10, 10); + cmp(10, 20); + cmp(20, 10); + + cmp(-10, -10); + cmp(-10, -20); + cmp(-20, -10); + + cmp( 10, -10); + cmp( 10, -20); + cmp( 20, -10); + + cmp(-10, 10); + cmp(-10, 20); + cmp(-20, 10); + + cmp(-30, 30); + cmp(-30, -30); + cmp( 30, 30); + cmp( 30, -30); + + cmp( 0, 127); + cmp( 0, -128); + cmp( 127, 0); + cmp(-128, 0); + + cmp( 127, 127); + cmp( 127, -128); + cmp(-128, 127); + cmp(-128, -128); + + cmpz(0); + cmpz(1); + cmpz(127); + cmpz(-1); + cmpz(-128); + + cmp1(0); + cmp1(1); + cmp1(2); + cmp1(3); + cmp1(127); + cmp1(-1); + cmp1(-2); + cmp1(-3); + cmp1(-128); + + return 0; + +} diff --git a/include/c64/keyboard.c b/include/c64/keyboard.c index a7ee115..5a7ad2f 100644 --- a/include/c64/keyboard.c +++ b/include/c64/keyboard.c @@ -38,6 +38,9 @@ void keyb_poll(void) if (cia1.prb != 0xff) { + keyb_matrix[6] &= 0xef; + keyb_matrix[1] &= 0x7f; + byte a = 0xfe; for(byte i=0; i<8; i++) { diff --git a/include/c64/types.h b/include/c64/types.h index 860e764..436d07c 100644 --- a/include/c64/types.h +++ b/include/c64/types.h @@ -5,4 +5,6 @@ typedef unsigned char byte; typedef unsigned short word; typedef unsigned long dword; +typedef signed char sbyte; + #endif diff --git a/include/c64/vic.c b/include/c64/vic.c index 6921f25..843b5b5 100644 --- a/include/c64/vic.c +++ b/include/c64/vic.c @@ -5,3 +5,13 @@ void vic_setbank(char bank) { cia2.pra = (cia2.pra & 0xfc) | (bank ^ 0x03); } + +void vic_sprxy(byte s, int x, int y) +{ + vic.spr_pos[0].y = y; + vic.spr_pos[0].x = x & 0xff; + if (x & 0x100) + vic.spr_msbx |= 1 << s; + else + vic.spr_msbx &= ~(1 << s); +} diff --git a/include/c64/vic.h b/include/c64/vic.h index 2786d14..b8596c7 100644 --- a/include/c64/vic.h +++ b/include/c64/vic.h @@ -75,6 +75,9 @@ struct VIC void vic_setbank(char bank); +inline void vic_sprxy(byte s, int x, int y); + + #define vic (*((struct VIC *)0xd000)) #pragma compile("vic.c") diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index eaa326b..3313ca0 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -2571,18 +2571,17 @@ void NativeCodeBasicBlock::CheckFrameIndex(int& reg, int& index, int size, int t { if (index < 0 || index + size > 256) { + if (treg == 0) + treg = BC_REG_ADDR; mIns.Push(NativeCodeInstruction(ASMIT_CLC, ASMIM_IMPLIED)); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, reg)); mIns.Push(NativeCodeInstruction(ASMIT_ADC, ASMIM_IMMEDIATE, index & 0xff)); - mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ADDR)); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg)); mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, reg + 1)); mIns.Push(NativeCodeInstruction(ASMIT_ADC, ASMIM_IMMEDIATE, (index >> 8) & 0xff)); - mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ADDR + 1)); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1)); index = 0; - if (treg == 0) - reg = BC_REG_ADDR; - else - reg = treg; + reg = treg; } } @@ -10667,15 +10666,6 @@ void NativeCodeProcedure::CompileInterBlock(InterCodeProcedure* iproc, InterCode break; case IC_LOAD: if (i + 1 < iblock->mInstructions.Size() && - iblock->mInstructions[i + 1]->mCode == IC_STORE && - iblock->mInstructions[i + 1]->mSrc[0].mTemp == ins->mDst.mTemp && - iblock->mInstructions[i + 1]->mSrc[0].mFinal && - InterTypeSize[ins->mDst.mType] == 1) - { - block->LoadStoreValue(iproc, ins, iblock->mInstructions[i + 1]); - i++; - } - else if (i + 1 < iblock->mInstructions.Size() && iblock->mInstructions[i + 1]->mCode == IC_STORE && iblock->mInstructions[i + 1]->mSrc[0].mTemp == ins->mDst.mTemp && iblock->mInstructions[i + 1]->mSrc[0].mFinal)