Do some stuff
This commit is contained in:
42
cpu/core.c
42
cpu/core.c
@@ -7,9 +7,10 @@
|
||||
#include "string.h"
|
||||
|
||||
// Initialize CPU
|
||||
void init_cpu(CPU *cpu) {
|
||||
void init_cpu(CPU *cpu, SDL_Renderer *renderer) {
|
||||
memset(cpu, 0, sizeof(CPU));
|
||||
cpu->mode = CPU_MODE_HALTED | CPU_MODE_SECOND;
|
||||
cpu->renderer = renderer;
|
||||
}
|
||||
|
||||
// Helper function for setting flags in the CPU (here we assume bit0 is the Zero flag,
|
||||
@@ -41,15 +42,15 @@ void step(CPU *cpu) {
|
||||
oldPC = cpu->pc;
|
||||
newPC = oldPC;
|
||||
|
||||
uint8_t opcode = read_mem(cpu, cpu->pc++);
|
||||
|
||||
|
||||
const uint32_t differenceAlignment = oldPC % CPU_INSTRUCTION_SIZE;
|
||||
|
||||
if (differenceAlignment) {
|
||||
cpu->pc += differenceAlignment;
|
||||
}
|
||||
|
||||
uint8_t opcode = read_mem(cpu, cpu->pc++);
|
||||
|
||||
|
||||
switch (opcode) {
|
||||
case NOP:
|
||||
//Don't do anything
|
||||
@@ -386,7 +387,7 @@ void step(CPU *cpu) {
|
||||
}
|
||||
temp |= (1 << bit);
|
||||
write_reg(cpu, reg1, temp);
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -402,9 +403,10 @@ void step(CPU *cpu) {
|
||||
if (bit > 7) {
|
||||
bit = 7;
|
||||
}
|
||||
|
||||
temp &= ~(1 << bit);
|
||||
write_reg(cpu, reg1, temp);
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -425,7 +427,8 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
cpu->pc -= 2;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -439,7 +442,7 @@ void step(CPU *cpu) {
|
||||
}
|
||||
temp |= (1 << bit);
|
||||
write_mem(cpu, addrTemp, temp);
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -454,7 +457,7 @@ void step(CPU *cpu) {
|
||||
}
|
||||
temp &= ~(1 << bit);
|
||||
write_mem(cpu, addrTemp, temp);
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -470,7 +473,8 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
cpu->pc -= 2;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -482,7 +486,7 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -499,7 +503,8 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
cpu->pc -= 2;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -515,7 +520,8 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
cpu->pc -= 2;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -526,7 +532,7 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -537,7 +543,7 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -548,7 +554,7 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -559,7 +565,7 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -570,7 +576,7 @@ void step(CPU *cpu) {
|
||||
cpu->pc = newPC;
|
||||
break;
|
||||
}
|
||||
cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
//cpu->pc += CPU_INSTRUCTION_SIZE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user