diff --git a/c/main.c b/c/main.c index ba87e78..3990c1e 100644 --- a/c/main.c +++ b/c/main.c @@ -6,8 +6,71 @@ #include "state.h" #include "exception.h" #include "execute.h" +#include "state_helpers.h" +#include "operations.h" #include "decode_print.h" +void render(struct architectural_state * state, struct memory_map * map) +{ + char const * instruction_buf; + char operand_buf[128]; + + printf("\e[1;1H\e[2J"); + + for (int i = 0; i < 8; i++) { + int ra = i; + int rb = i+8; + int rc = i+16; + printf(" r%-2d 0x%08x r%-2d 0x%08x xr%-2d 0x%08x\n", + ra, state->general_register[ra], + rb, state->general_register[rb], + (rc-16), state->general_register[rc] + ); + } + + printf("\n"); + for (int i = 0; i < 8; i++) { + int ra = i; + int rb = i+8; + int rc = i+16; + int rd = i+24; + printf(" fr%-2d 0x%08x fr%-2d 0x%08x xf%-2d 0x%08x xf%-2d 0x%08x\n", + ra, state->floating_point_register.fr[ra], + rb, state->floating_point_register.fr[rb], + (rc-16), state->floating_point_register.fr[rc], + (rd-16), state->floating_point_register.fr[rd] + ); + } + + printf("\n"); + printf(" pc 0x%08x pr 0x%08x\n", state->pc[0], state->pr[0]); + printf(" mach 0x%08x macl 0x%08x\n", state->mach, state->macl ); + printf(" fpscr 0x%08x fpul 0x%08x\n", state->fpscr.value, state->fpul); + printf(" sr 0x%08x\n", state->sr.value); + + + printf("md:%d ", state->sr.bits.md); + printf("rb:%d ", state->sr.bits.rb); + printf("bl:%d ", state->sr.bits.bl); + printf("fd:%d ", state->sr.bits.fd); + printf("m:%d ", state->sr.bits.m); + printf("q:%d ", state->sr.bits.q); + printf("imask:%d ", state->sr.bits.imask); + printf("s:%d ", state->sr.bits.s); + printf("t:%d ", state->sr.bits.t); + printf("\n"); + + uint32_t instruction_code; + printf("\n\n"); + for (int i = -1; i < 8; i++) { + uint32_t address = zero_extend32(sign_extend32(state->pc[0]) + i * 2); + instruction_code = read_memory16(map, address); + decode_and_print_instruction(state, map, instruction_code, &instruction_buf, operand_buf, 128); + const char p = i == 0 ? '>' : ' '; + printf(" %c %08x %-7s %-20s\n", p, address, instruction_buf, operand_buf); + } +} + int main(int argc, char *argv[]) { assert(argc > 1); @@ -40,21 +103,27 @@ int main(int argc, char *argv[]) struct architectural_state state = { 0 }; POWERON(&state); + state.pc[2] = state.pc[0] + 2; + state.pr[2] = state.pr[0]; + render(&state, &map); - char const * instruction_buf; - char operand_buf[128]; - + bool free = 1; + int ix = 0; while (1) { - uint32_t instruction_code = fetch(&state, &map); - decode_and_print_instruction(&state, &map, instruction_code, &instruction_buf, operand_buf, 128); - printf("pc %08x %-7s %-20s\n", state.pc[0], instruction_buf, operand_buf); - - if (physical_address(state.pc[0]) == 0x38) + if (physical_address(state.pc[0]) == 0x96) break; + if (!free) + getchar(); + step(&state, &map); + + if (!free || (ix % 1000) == 0) + render(&state, &map); + + ix++; } - printf("part1 %d\n", state.gbr); - printf("part2 %d %d\n", state.mach, state.macl); + render(&state, &map); + printf("part1 %x\n", state.floating_point_register.fr[9]); }