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

@@ -37,9 +37,13 @@ uint32_t read_mem32(CPU *cpu, uint32_t addr) {
return read_mem16(cpu, addr) | (read_mem16(cpu, addr + 2) << 16);
}
uint32_t read_mem24(CPU *cpu, uint32_t addr) {
return read_mem16(cpu, addr) | (read_mem(cpu, addr + 2) << 16);
}
uint32_t read_address_argument(CPU *cpu) {
uint32_t out = read_mem32(cpu, cpu->pc);
cpu->pc += 4;
uint32_t out = read_mem24(cpu, cpu->pc);
cpu->pc += 3;
if (out >= MEM_SIZE) {
out = MEM_SIZE - 1;
}
@@ -58,8 +62,7 @@ void write_stack(CPU *cpu) {
for (uint32_t reg = 0; reg < REG_COUNT; reg += 4) {
uint32_t packed = cpu->regs[reg] |
((reg + 1 < REG_COUNT) ? (cpu->regs[reg + 1] << 8) : 0) |
((reg + 2 < REG_COUNT) ? (cpu->regs[reg + 2] << 16) : 0) |
((reg + 3 < REG_COUNT) ? (cpu->regs[reg + 3] << 24) : 0);
((reg + 2 < REG_COUNT) ? (cpu->regs[reg + 2] << 16) : 0);
cpu->stack[++cpu->stack_ptr] = packed;
}
cpu->stack[++cpu->stack_ptr] = cpu->flags;
@@ -83,7 +86,6 @@ void read_stack(CPU *cpu) {
cpu->regs[reg] = (packed & 0xFF);
if (reg - 1 >= 0) cpu->regs[reg - 1] = ((packed >> 8) & 0xFF);
if (reg - 2 >= 0) cpu->regs[reg - 2] = ((packed >> 16) & 0xFF);
if (reg - 3 >= 0) cpu->regs[reg - 3] = ((packed >> 24) & 0xFF);
}
// Restore PC