Fix collision flag resetting prematurely

This commit is contained in:
Doyle Thai 2017-04-07 15:06:00 +10:00
parent d997f1e945
commit 1a3ce032ac
2 changed files with 11 additions and 15 deletions

View File

@ -287,7 +287,7 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
if (cpu.state == chip8state_load_file)
{
PlatformFile file = {};
if (platform_open_file(L"roms/PONG", &file))
if (platform_open_file(L"roms/brix", &file))
{
DQNT_ASSERT((cpu.INIT_ADDRESS + file.size) <=
memory.permanentMemSize);
@ -597,13 +597,16 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
const i32 BYTES_PER_PIXEL = renderBuffer.bytesPerPixel;
i32 pitch = renderBuffer.width * BYTES_PER_PIXEL;
bool collisionFlag = false;
for (i32 i = 0; i < readNumBytesFromMem; i++)
{
u8 spriteBytes = mainMem[cpu.indexRegister + i];
u8 posY = initPosY + (u8)i;
if (posY >= renderBuffer.height) posY = 0;
// NOTE: Flip the Y
posY = ((u8)(renderBuffer.height-1) - posY);
const i32 ALPHA_BYTE_INTERVAL = renderBuffer.bytesPerPixel;
const i32 BITS_IN_BYTE = 8;
i32 baseBitShift = BITS_IN_BYTE - 1;
@ -629,14 +632,7 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
// NOTE: If caused a pixel to XOR into off, then this is
// known as a "collision" in chip8
if (pixelWasOn && !pixelIsOn)
{
cpu.VF = 1;
}
else
{
cpu.VF = 0;
}
if (pixelWasOn && !pixelIsOn) collisionFlag = true;
if (pixelIsOn)
{
@ -648,6 +644,8 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
}
}
}
cpu.VF = collisionFlag;
}
break;

View File

@ -43,9 +43,8 @@ FILE_SCOPE void win32_display_render_bitmap(Win32RenderBitmap renderBitmap,
{
HDC stretchDC = CreateCompatibleDC(deviceContext);
SelectObject(stretchDC, renderBitmap.handle);
StretchBlt(deviceContext, 0, 0, width, height, stretchDC, 0,
0, renderBitmap.width, renderBitmap.height, SRCCOPY);
StretchBlt(deviceContext, 0, 0, width, height, stretchDC, 0, 0,
renderBitmap.width, renderBitmap.height, SRCCOPY);
// NOTE: Win32 AlphaBlend requires the RGB components to be premultiplied
// with alpha.
@ -382,7 +381,6 @@ u32 platform_read_file(PlatformFile file, void *buffer, u32 numBytesToRead)
return numBytesRead;
}
FILE_SCOPE u32 buffer[15000];
bool platform_open_file(const wchar_t *const file, PlatformFile *platformFile)
{
HANDLE handle = CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL,