diff --git a/include/cpu.h b/include/cpu.h index 6f56735..72bfc33 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -19,5 +19,6 @@ typedef struct CPU_s CPU; CPU create_cpu(AddressSpace *addressSpace); int cpu_cycle(CPU *cpu); +void print_registers(CPU *cpu); #endif \ No newline at end of file diff --git a/src/cpu.c b/src/cpu.c index 6903aeb..599f8f1 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "address_space.h" #include "instruction_executor.h" @@ -28,4 +30,63 @@ int cpu_cycle(CPU *cpu) { cpu->programCounter += 4; return result; +} + +void print_registers(CPU *cpu) { + uint32_t *registers = cpu->registers; + + // "%d: \033[1m0x%X\033[0m (%u)" + + int columns = 8; + int rows = 4; + + int *colSize = malloc(columns * sizeof(int)); + int totalWidth = 0; + + for (int coln=0; coln mlen) { + mlen = len; + } + } + colSize[coln] = mlen; + totalWidth += mlen; + } + + printf("┌"); + for (int coln=0; colnromSize + addressSpace->ramSize; // make jumping to x1 end the program - int lres = load_to_rom(argv[1], addressSpace); if (lres == -1) { @@ -48,61 +47,7 @@ int main(int argc, char *argv[]) { printf(" Program exit code: \033[1m%d\033[0m (x10)\n", cpu.registers[10]); printf(" Cycles: \033[1m%u\033[0m\n\n", cycles); - // TODO don't - - int cols[8] = {0}; - int total = 0; - - for (int col=0; col<8; col++) { - int len; - for (int row=0; row<4; row++) { - int i = 8 * row + col; - len = snprintf(NULL, 0, "%d: \033[1m0x%X\033[0m (%u)", i, cpu.registers[i], cpu.registers[i]); - if (len > cols[col]) { - cols[col] = len; - } - } - total += len; - } - - printf("+"); - for (int i=0; i<8; i++) { - for (int j=0; j