Fix collision flag resetting prematurely
This commit is contained in:
parent
d997f1e945
commit
1a3ce032ac
@ -287,7 +287,7 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
|
|||||||
if (cpu.state == chip8state_load_file)
|
if (cpu.state == chip8state_load_file)
|
||||||
{
|
{
|
||||||
PlatformFile 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) <=
|
DQNT_ASSERT((cpu.INIT_ADDRESS + file.size) <=
|
||||||
memory.permanentMemSize);
|
memory.permanentMemSize);
|
||||||
@ -597,13 +597,16 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
|
|||||||
const i32 BYTES_PER_PIXEL = renderBuffer.bytesPerPixel;
|
const i32 BYTES_PER_PIXEL = renderBuffer.bytesPerPixel;
|
||||||
i32 pitch = renderBuffer.width * BYTES_PER_PIXEL;
|
i32 pitch = renderBuffer.width * BYTES_PER_PIXEL;
|
||||||
|
|
||||||
|
bool collisionFlag = false;
|
||||||
for (i32 i = 0; i < readNumBytesFromMem; i++)
|
for (i32 i = 0; i < readNumBytesFromMem; i++)
|
||||||
{
|
{
|
||||||
u8 spriteBytes = mainMem[cpu.indexRegister + i];
|
u8 spriteBytes = mainMem[cpu.indexRegister + i];
|
||||||
u8 posY = initPosY + (u8)i;
|
u8 posY = initPosY + (u8)i;
|
||||||
|
|
||||||
if (posY >= renderBuffer.height) posY = 0;
|
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 ALPHA_BYTE_INTERVAL = renderBuffer.bytesPerPixel;
|
||||||
const i32 BITS_IN_BYTE = 8;
|
const i32 BITS_IN_BYTE = 8;
|
||||||
i32 baseBitShift = BITS_IN_BYTE - 1;
|
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
|
// NOTE: If caused a pixel to XOR into off, then this is
|
||||||
// known as a "collision" in chip8
|
// known as a "collision" in chip8
|
||||||
if (pixelWasOn && !pixelIsOn)
|
if (pixelWasOn && !pixelIsOn) collisionFlag = true;
|
||||||
{
|
|
||||||
cpu.VF = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cpu.VF = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pixelIsOn)
|
if (pixelIsOn)
|
||||||
{
|
{
|
||||||
@ -648,6 +644,8 @@ void dchip8_update(PlatformRenderBuffer renderBuffer, PlatformInput input,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpu.VF = collisionFlag;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -43,11 +43,10 @@ FILE_SCOPE void win32_display_render_bitmap(Win32RenderBitmap renderBitmap,
|
|||||||
{
|
{
|
||||||
HDC stretchDC = CreateCompatibleDC(deviceContext);
|
HDC stretchDC = CreateCompatibleDC(deviceContext);
|
||||||
SelectObject(stretchDC, renderBitmap.handle);
|
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,
|
// NOTE: Win32 AlphaBlend requires the RGB components to be premultiplied
|
||||||
0, renderBitmap.width, renderBitmap.height, SRCCOPY);
|
|
||||||
|
|
||||||
// NOTE: Win32 AlphaBlend requires the RGB components to be premultiplied
|
|
||||||
// with alpha.
|
// with alpha.
|
||||||
#if 0
|
#if 0
|
||||||
BLENDFUNCTION blend = {};
|
BLENDFUNCTION blend = {};
|
||||||
@ -382,7 +381,6 @@ u32 platform_read_file(PlatformFile file, void *buffer, u32 numBytesToRead)
|
|||||||
return numBytesRead;
|
return numBytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE_SCOPE u32 buffer[15000];
|
|
||||||
bool platform_open_file(const wchar_t *const file, PlatformFile *platformFile)
|
bool platform_open_file(const wchar_t *const file, PlatformFile *platformFile)
|
||||||
{
|
{
|
||||||
HANDLE handle = CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
HANDLE handle = CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||||
|
Loading…
Reference in New Issue
Block a user