Fix local variable array member forwarding

This commit is contained in:
drmortalwombat 2022-01-29 16:06:47 +01:00
parent 60165a7fc3
commit 08d6358932
7 changed files with 144 additions and 11 deletions

View File

@ -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;
}

View File

@ -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],

View File

@ -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:

View File

@ -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) &&

125
samples/hires/cube3d.c Normal file
View File

@ -0,0 +1,125 @@
#include <c64/memmap.h>
#include <c64/vic.h>
#include <gfx/bitmap.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <gfx/vector3d.h>
#include <math.h>
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;
}

View File

@ -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<SIZE; ix++)
{
for(int iy=0; iy<SIZE; iy++)

View File

@ -3,3 +3,4 @@ call ..\..\bin\oscar64 func3d.c -n
call ..\..\bin\oscar64 lines.c -n
call ..\..\bin\oscar64 polygon.c -n
call ..\..\bin\oscar64 bitblit.c -n
call ..\..\bin\oscar64 cube3d.c -n