started opcodes

This commit is contained in:
Lauchmelder 2021-10-21 19:24:53 +02:00
parent 4b22287ad0
commit 458500bd59
8 changed files with 240 additions and 5 deletions

View file

@ -13,6 +13,9 @@ struct CPU* createCPU(struct Bus* parent)
exit(1);
}
// TODO: THIS IS JUST FOR THE TEST ROM
cpu->pc = 0xC000;
cpu->bus = parent;
return cpu;
}
@ -21,3 +24,39 @@ void destroyCPU(struct CPU* cpu)
{
free(cpu);
}
void tickCPU(struct CPU* cpu)
{
if (cpu->fetchedVal != 0)
{
cpu->fetchedVal--;
return;
}
fetch(cpu);
execute(cpu);
}
void tickInstr(struct CPU* cpu)
{
while (cpu->remainingCycles > 1)
tickCPU(cpu);
}
void fetch(struct CPU* cpu)
{
Byte opcodeVal = readBus(cpu->bus, cpu->pc);
cpu->currentOpcode = OPCODE_TABLE + opcodeVal;
if (cpu->currentOpcode->op == Unknown)
{
fprintf(stderr, "Unknown opcode: %x", opcodeVal);
exit(1);
}
}
void execute(struct CPU* cpu)
{
}