From 1530351408e88d60bd9c5f73927181cfee4c1500 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 14 Oct 2019 23:36:31 -0400 Subject: fix screen size and comment draw code --- chip8.c | 7 +++++++ chip8.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/chip8.c b/chip8.c index 821d75f..b79bc3a 100644 --- a/chip8.c +++ b/chip8.c @@ -197,6 +197,8 @@ void vm_step() { vm.Vx[0xF] = 0; for (u32 i = 0; i < (in&0xF); i++) { for (u32 s = 0; s < 8; s++) { + + // 0x80 = 10000000 u8 pix = (vm.ram[vm.I + i] & (0x80 >> s)) != 0; if (pix) { @@ -204,8 +206,13 @@ void vm_step() { u8 x = (vm.Vx[in>>8&0xF] + s)&0x3F; u32 byte = y * 64 + x; + + // put the single 1 bit in the position + // that is relative to the pixel u32 bit = 1 << (byte & 0x07); + // byte>>3 ~ byte / 8 + // used to get the index of byte to xor if (vm.screen[byte>>3] & bit) { vm.Vx[0xF] = 1; } diff --git a/chip8.h b/chip8.h index 2c7eb45..ce02394 100644 --- a/chip8.h +++ b/chip8.h @@ -23,7 +23,7 @@ typedef struct { u8 keyboard[16]; - u8 screen[0x3F*0x1F]; + u8 screen[250]; } chip8_vm; extern chip8_vm vm; -- cgit v1.2.3-101-g0448