Add highlighting, fixed len instructions and more

This commit is contained in:
2025-02-09 21:15:50 +01:00
parent 45653b6372
commit e133c2df3a
17 changed files with 753 additions and 338 deletions

View File

@@ -34,11 +34,22 @@ void step(CPU *cpu) {
cpu->mode |= CPU_MODE_HALTED;
}
}
uint8_t opcode = read_mem(cpu, cpu->pc++);
uint8_t reg1, reg2, imm, temp, temp2;
uint32_t newPC, addrTemp;
uint32_t newPC, addrTemp, oldPC;
int32_t cmpResult;
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;
}
switch (opcode) {
case NOP:
//Don't do anything
@@ -491,5 +502,12 @@ void step(CPU *cpu) {
printf("Unknown opcode: %d\n", opcode);
cpu->mode |= CPU_MODE_ERROR;
}
if (oldPC == newPC) {
const uint32_t remainingBytes = CPU_INSTRUCTION_SIZE - (cpu->pc - oldPC);
if (remainingBytes > CPU_INSTRUCTION_SIZE) {
printf("HELP, INSTRUCTION SIZE SMALLER THAN INSTRUCTION");
}
cpu->pc += remainingBytes;
}
cpu->cycle++;
}