Hello, thanks for read, ok, my problem is my first emulator don't working. Just in the final stage, when i think is al ready finished, appears this problem. :down:
don't know how fix it, i try different algorithms, but none worked. This is the code:
i using c#.
CPU:
Code:
int opcode = this.memory[this.PC] << 8 | this.memory[this.PC+ 1];
this.X = (opcode & 0x0F00) >> 8;
this.Y = (opcode & 0x00F0) >> 4;
switch(opcode & 0xF000) {
case 0xD000:
int spr;
int h = opcode & 0x000F;
this.V[0xF] = 0;
for (var y = 0; y < h; y++)
{
spr = this.memory.read(this.I + y);
for (var x = 0; x < 8; x++)
{
if ((spr & 0x80) > 0)
{
x = this.V[this.X] + x;
y = this.V[this.Y] + y;
if (this.display.setPixel(x, y) == 1)
{
this.V[0xF] = 1;
}
}
spr <<= 1;
}
}
this.DRAW_FLAG = true;
break;
}
Display:
Code:
public int setPixel(int x, int y)
{
if (x > 64)
{
x -= this.primitiveWidth;
}
else if (x < 0)
{
x += this.primitiveWidth;
}
if (y > 32)
{
y -= this.primitiveHeight;
}
else if (y < 0)
{
y += this.primitiveHeight;
}
var pos = x + (y * this.primitiveWidth);
this.display[pos] ^= 1;
return this.display[pos];
}
Render Display:
Code:
public void renderDisplay(int[] display)
{
Bitmap flag = new Bitmap(pic1.Width, pic1.Height);
Graphics flagGraphics = Graphics.FromImage(flag);
flagGraphics.Clear(Color.Black);
for (int i = 0; i < display.Length; i++)
{
double x = (i % 64) * 8;
double y = Math.Floor((double)i / 64) * 8;
if (display[i] == 1)
{
flagGraphics.FillRectangle(Brushes.White, (float)x, (float)y, 8, 8);
}
}
pic1.Image = flag;
}
- - - Updated - - -
![]()