swissChili | 6264a3b | 2020-07-30 19:02:07 -0700 | [diff] [blame^] | 1 | #include "dbg.h" |
| 2 | #include "cpu.h" |
| 3 | |
| 4 | #include <readline/readline.h> |
| 5 | #include <readline/history.h> |
| 6 | #include <string.h> |
| 7 | #include <stdlib.h> |
| 8 | |
| 9 | void debug(cpu_t *cpu) |
| 10 | { |
| 11 | while (true) |
| 12 | { |
| 13 | char *input = readline("\033[33m> \033[0m"); |
| 14 | if (!input) |
| 15 | continue; |
| 16 | |
| 17 | char *tok = strtok(input, " \t\r\n\v"); |
| 18 | |
| 19 | if (!strcmp(tok, "step") || !strcmp(tok, "s")) |
| 20 | { |
| 21 | step(cpu); |
| 22 | } |
| 23 | else if (!strcmp(tok, "show") || !strcmp(tok, "print")) |
| 24 | { |
| 25 | if ((tok = strtok(NULL, " "))) |
| 26 | { |
| 27 | char *ok = 0; |
| 28 | if (tok[0] == '$') |
| 29 | { |
| 30 | uint16_t addr = strtol(tok + 1, &ok, 16); |
| 31 | |
| 32 | if (ok == 0) |
| 33 | { |
| 34 | printf("Memory:\n"); |
| 35 | printf("\t$%x %x\n", addr, cpu->mem[addr]); |
| 36 | printf("\t$%x %x\n", addr + 1, cpu->mem[addr + 1]); |
| 37 | } |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | printf("Registers:\n"); |
| 42 | |
| 43 | #define R(r) printf("\t" #r ": %x\n", cpu->regs[r]); |
| 44 | REGISTERS |
| 45 | #undef R |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | add_history(input); |
| 51 | } |
| 52 | } |