summaryrefslogtreecommitdiff
path: root/chip8.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip8.c')
-rw-r--r--chip8.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/chip8.c b/chip8.c
index a6dfbd5..f057c3c 100644
--- a/chip8.c
+++ b/chip8.c
@@ -7,7 +7,7 @@
#ifdef _WIN32
#include <winsock.h>
-#else
+#else
#include <arpa/inet.h>
#include <unistd.h>
#endif
@@ -58,7 +58,7 @@ void load_rom(char *path) {
vm.ram = (u8*)malloc(0xFFF);
memset(vm.ram, 0, 0xFFF);
-
+
#ifdef _WIN32
size_t res = read(fd, &vm.ram[0x200], fsize);
#else
@@ -90,7 +90,7 @@ void vm_step(void) {
// ^^^
switch ((in>>12&0xF)) {
- case 0x0:
+ case 0x0:
switch (in&0xFF) {
case 0xE0: // CLS
memset(&vm.screen, 0, sizeof(vm.screen));
@@ -98,7 +98,7 @@ void vm_step(void) {
case 0xEE: // RET
vm.PC = vm.stack[vm.SP--];
break;
- }
+ }
break;
case 0x1: // JP addr
vm.PC = (in&0xFFF) - 0x2;
@@ -128,21 +128,21 @@ void vm_step(void) {
case 0x7: // ADD Vx, byte
vm.Vx[in>>8&0xF] += in&0xFF;
break;
- case 0x8:
+ case 0x8:
switch(in&0xF) {
- case 0x0: // LD Vx, Vy
+ case 0x0: // LD Vx, Vy
vm.Vx[in>>8&0xF] = vm.Vx[in>>4&0xF];
break;
- case 0x1: // OR Vx, Vy
+ case 0x1: // OR Vx, Vy
vm.Vx[in>>8&0xF] |= vm.Vx[in>>4&0xF];
break;
case 0x2: // AND Vx, Vy
vm.Vx[in>>8&0xF] &= vm.Vx[in>>4&0xF];
break;
- case 0x3: // XOR Vx, Vy
+ case 0x3: // XOR Vx, Vy
vm.Vx[in>>8&0xF] ^= vm.Vx[in>>4&0xF];
break;
- case 0x4: // ADD Vx, Vy
+ case 0x4: // ADD Vx, Vy
if ((vm.Vx[in>>8&0xF] + vm.Vx[in>>4&0xF]) > 0xFF) {
vm.Vx[0xF] = 1;
} else {
@@ -150,7 +150,7 @@ void vm_step(void) {
}
vm.Vx[in>>8&0xF] = (vm.Vx[in>>8&0xF] + vm.Vx[in>>4&0xF])&0xFF;
break;
- case 0x5: // SUB Vx, Vy
+ case 0x5: // SUB Vx, Vy
if (vm.Vx[in>>8&0xF] > vm.Vx[in>>4&0xF]) {
vm.Vx[0xF] = 1;
} else {
@@ -159,7 +159,7 @@ void vm_step(void) {
vm.Vx[in>>8&0xF] -= vm.Vx[in>>4&0xF];
break;
case 0x6: // SHR Vx {, Vy}
- vm.Vx[0xF] = (vm.Vx[in>>8&0xF] & 1);
+ vm.Vx[0xF] = (vm.Vx[in>>8&0xF] & 1);
// TODO: toggle for Vx /= 2
vm.Vx[in>>8&0xF] = vm.Vx[in>>8&0xF]>>1;
break;
@@ -171,14 +171,14 @@ void vm_step(void) {
}
vm.Vx[in>>8&0xF] = vm.Vx[in>>4&0xF] - vm.Vx[in>>8&0xF];
break;
- case 0xE: // SHL Vx {, Vy}
+ case 0xE: // SHL Vx {, Vy}
vm.Vx[0xF] = ((vm.Vx[in>>8&0xF]>>7) & 1);
// TODO: toggle for Vx *= 2;
vm.Vx[in>>8&0xF] = vm.Vx[in>>8&0xF]<<1;
break;
}
break;
- case 0x9: // SNE Vx, Vy
+ case 0x9: // SNE Vx, Vy
if (vm.Vx[(in>>8&0xF)] != vm.Vx[(in>>4&0xF)]) {
vm.PC += 0x2;
}
@@ -203,14 +203,14 @@ void vm_step(void) {
if (pix) {
u8 y = (vm.Vx[in>>4&0xF] + i)&0x1F;
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
u8 bit = 1 << (byte & 0x07);
- // byte>>3 ~ byte / 8
+ // byte>>3 ~ byte / 8
// used to get the index of the byte
// containing the bit to change
if (vm.screen[byte>>3] & bit) {
@@ -237,7 +237,7 @@ void vm_step(void) {
break;
case 0xF:
switch (in&0xFF) {
- case 0x07: // LD Vx, DT
+ case 0x07: // LD Vx, DT
vm.Vx[in>>8&0xF] = vm.DT;
break;
case 0x0A: // LD Vx, K