annotate debug.c @ 1931:374a5ae694e8 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 18 Apr 2020 11:42:53 -0700
parents 0a26f3657295 23394a890508
children a7b753e260a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include "debug.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
2 #include "genesis.h"
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "68kinst.h"
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <stdlib.h>
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include <string.h>
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
6 #ifndef _WIN32
723
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
7 #include <sys/select.h>
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
8 #endif
723
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
9 #include "render.h"
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 747
diff changeset
10 #include "util.h"
794
792be135d3af Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
11 #include "terminal.h"
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
12 #include "z80inst.h"
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
13
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
14 #ifdef NEW_CORE
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
15 #define Z80_OPTS opts
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
16 #else
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
17 #define Z80_OPTS options
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
18 #endif
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19
525
62860044337d Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents: 524
diff changeset
20 static bp_def * breakpoints = NULL;
62860044337d Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents: 524
diff changeset
21 static bp_def * zbreakpoints = NULL;
62860044337d Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents: 524
diff changeset
22 static uint32_t bp_index = 0;
62860044337d Support single stepping in gdb remote debugger
Mike Pavone <pavone@retrodev.com>
parents: 524
diff changeset
23 static uint32_t zbp_index = 0;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 bp_def ** find_breakpoint(bp_def ** cur, uint32_t address)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 while (*cur) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 if ((*cur)->address == address) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 cur = &((*cur)->next);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 return cur;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 bp_def ** find_breakpoint_idx(bp_def ** cur, uint32_t index)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 while (*cur) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 if ((*cur)->index == index) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 cur = &((*cur)->next);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 return cur;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
46
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 disp_def * displays = NULL;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 disp_def * zdisplays = NULL;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 uint32_t disp_index = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 uint32_t zdisp_index = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 void add_display(disp_def ** head, uint32_t *index, char format_char, char * param)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 disp_def * ndisp = malloc(sizeof(*ndisp));
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 ndisp->format_char = format_char;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 ndisp->param = strdup(param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 ndisp->next = *head;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 ndisp->index = *index++;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 *head = ndisp;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 void remove_display(disp_def ** head, uint32_t index)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 while (*head) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 if ((*head)->index == index) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 disp_def * del_disp = *head;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 *head = del_disp->next;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 free(del_disp->param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 free(del_disp);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 head = &(*head)->next;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
75
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 char * find_param(char * buf)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 for (; *buf; buf++) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
79 if (*buf == ' ') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 if (*(buf+1)) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81 return buf+1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
85 return NULL;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 void strip_nl(char * buf)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 for(; *buf; buf++) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 if (*buf == '\n') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92 *buf = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 return;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
94 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97
1313
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
98 uint16_t m68k_read_word(uint32_t address, m68k_context *context)
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
99 {
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
100 return read_word(address, (void **)context->mem_pointers, &context->options->gen, context);
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
101 }
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
102
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
103 uint32_t m68k_read_long(uint32_t address, m68k_context *context)
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
104 {
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
105 return m68k_read_word(address, context) << 16 | m68k_read_word(address + 2, context);
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
106 }
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
107
1923
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
108 void debugger_print(m68k_context *context, char format_char, char *param, uint32_t address)
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
109 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
110 uint32_t value;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
111 char format[8];
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
112 strcpy(format, "%s: %d\n");
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
113 switch (format_char)
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
114 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
115 case 'x':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
116 case 'X':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
117 case 'd':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
118 case 'c':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
119 format[5] = format_char;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
120 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
121 case '\0':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
122 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
123 default:
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
124 fprintf(stderr, "Unrecognized format character: %c\n", format_char);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
125 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
126 if (param[0] == 'd' && param[1] >= '0' && param[1] <= '7') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
127 value = context->dregs[param[1]-'0'];
1312
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
128 if (param[2] == '.') {
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
129 if (param[3] == 'w') {
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
130 value &= 0xFFFF;
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
131 } else if (param[3] == 'b') {
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
132 value &= 0xFF;
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
133 }
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
134 }
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
135 } else if (param[0] == 'a' && param[1] >= '0' && param[1] <= '7') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
136 value = context->aregs[param[1]-'0'];
1312
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
137 if (param[2] == '.') {
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
138 if (param[3] == 'w') {
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
139 value &= 0xFFFF;
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
140 } else if (param[3] == 'b') {
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
141 value &= 0xFF;
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
142 }
9ab3f6781202 Allow adding .w or .b to select just the low word or byte of a register in a 68K debugger print command
Michael Pavone <pavone@retrodev.com>
parents: 1311
diff changeset
143 }
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
144 } else if (param[0] == 's' && param[1] == 'r') {
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
145 value = (context->status << 8);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
146 for (int flag = 0; flag < 5; flag++) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
147 value |= context->flags[flag] << (4-flag);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
148 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
149 } else if(param[0] == 'c') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
150 value = context->current_cycle;
1311
26bdbf1f7e33 Allow printing current frame number in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1310
diff changeset
151 } else if(param[0] == 'f') {
26bdbf1f7e33 Allow printing current frame number in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1310
diff changeset
152 genesis_context *gen = context->system;
26bdbf1f7e33 Allow printing current frame number in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1310
diff changeset
153 value = gen->vdp->frame;
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
154 } else if (param[0] == 'p' && param[1] == 'c') {
1923
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
155 value = address;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
156 } else if ((param[0] == '0' && param[1] == 'x') || param[0] == '$') {
1314
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
157 char *after;
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
158 uint32_t p_addr = strtol(param+(param[0] == '0' ? 2 : 1), &after, 16);
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
159 if (after[0] == '.' && after[1] == 'l') {
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
160 value = m68k_read_long(p_addr, context);
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
161 } else {
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
162 value = m68k_read_word(p_addr, context);
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
163 }
1313
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
164 } else if(param[0] == '(' && (param[1] == 'a' || param[1] == 'd') && param[2] >= '0' && param[2] <= '7' && param[3] == ')') {
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
165 uint8_t reg = param[2] - '0';
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
166 uint32_t p_addr = param[1] == 'a' ? context->aregs[reg] : context->dregs[reg];
1314
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
167 if (param[4] == '.' && param[5] == 'l') {
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
168 value = m68k_read_long(p_addr, context);
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
169 } else {
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
170 value = m68k_read_word(p_addr, context);
ae932ca28282 Allow a .l suffix to a memory print command to allow fetching and printing a longword
Michael Pavone <pavone@retrodev.com>
parents: 1313
diff changeset
171 }
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
172 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
173 fprintf(stderr, "Unrecognized parameter to p: %s\n", param);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
174 return;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
175 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
176 printf(format, param, value);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
177 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
178
565
9324f721efa6 Add a separate flag/define for disabling the Z80 at compile time to ease refactoring
Michael Pavone <pavone@retrodev.com>
parents: 548
diff changeset
179 #ifndef NO_Z80
548
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 525
diff changeset
180
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
181 void zdebugger_print(z80_context * context, char format_char, char * param)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
182 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
183 uint32_t value;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
184 char format[8];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
185 strcpy(format, "%s: %d\n");
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
186 genesis_context *system = context->system;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 switch (format_char)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 case 'x':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
190 case 'X':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
191 case 'd':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192 case 'c':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
193 format[5] = format_char;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 case '\0':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 default:
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
198 fprintf(stderr, "Unrecognized format character: %c\n", format_char);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
199 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
200 switch (param[0])
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
201 {
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
202 #ifndef NEW_CORE
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
203 case 'a':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
204 if (param[1] == 'f') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
205 if(param[2] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
206 value = context->alt_regs[Z80_A] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
207 value |= context->alt_flags[ZF_S] << 7;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
208 value |= context->alt_flags[ZF_Z] << 6;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
209 value |= context->alt_flags[ZF_H] << 4;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
210 value |= context->alt_flags[ZF_PV] << 2;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
211 value |= context->alt_flags[ZF_N] << 1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 value |= context->alt_flags[ZF_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
214 value = context->regs[Z80_A] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215 value |= context->flags[ZF_S] << 7;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 value |= context->flags[ZF_Z] << 6;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
217 value |= context->flags[ZF_H] << 4;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
218 value |= context->flags[ZF_PV] << 2;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
219 value |= context->flags[ZF_N] << 1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
220 value |= context->flags[ZF_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
221 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
222 } else if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
223 value = context->alt_regs[Z80_A];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
224 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
225 value = context->regs[Z80_A];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
226 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
227 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
228 case 'b':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
229 if (param[1] == 'c') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
230 if(param[2] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
231 value = context->alt_regs[Z80_B] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
232 value |= context->alt_regs[Z80_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
233 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
234 value = context->regs[Z80_B] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
235 value |= context->regs[Z80_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
236 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
237 } else if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
238 value = context->alt_regs[Z80_B];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
239 } else if(param[1] == 'a') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
240 value = context->bank_reg << 15;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
241 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 value = context->regs[Z80_B];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
244 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
245 case 'c':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
246 if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
247 value = context->alt_regs[Z80_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
248 } else if(param[1] == 'y') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
249 value = context->current_cycle;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
250 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
251 value = context->regs[Z80_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
252 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
253 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
254 case 'd':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
255 if (param[1] == 'e') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
256 if(param[2] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
257 value = context->alt_regs[Z80_D] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
258 value |= context->alt_regs[Z80_E];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
259 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
260 value = context->regs[Z80_D] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
261 value |= context->regs[Z80_E];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
262 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
263 } else if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
264 value = context->alt_regs[Z80_D];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
265 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
266 value = context->regs[Z80_D];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
268 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
269 case 'e':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
270 if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
271 value = context->alt_regs[Z80_E];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
272 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
273 value = context->regs[Z80_E];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
274 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
275 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
276 case 'f':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
277 if(param[2] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278 value = context->alt_flags[ZF_S] << 7;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
279 value |= context->alt_flags[ZF_Z] << 6;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
280 value |= context->alt_flags[ZF_H] << 4;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
281 value |= context->alt_flags[ZF_PV] << 2;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
282 value |= context->alt_flags[ZF_N] << 1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
283 value |= context->alt_flags[ZF_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
284 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
285 value = context->flags[ZF_S] << 7;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
286 value |= context->flags[ZF_Z] << 6;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
287 value |= context->flags[ZF_H] << 4;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
288 value |= context->flags[ZF_PV] << 2;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
289 value |= context->flags[ZF_N] << 1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
290 value |= context->flags[ZF_C];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
291 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
292 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
293 case 'h':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
294 if (param[1] == 'l') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
295 if(param[2] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
296 value = context->alt_regs[Z80_H] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
297 value |= context->alt_regs[Z80_L];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
298 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
299 value = context->regs[Z80_H] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
300 value |= context->regs[Z80_L];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
301 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
302 } else if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
303 value = context->alt_regs[Z80_H];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
304 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
305 value = context->regs[Z80_H];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
306 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
307 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
308 case 'l':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
309 if(param[1] == '\'') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
310 value = context->alt_regs[Z80_L];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
311 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
312 value = context->regs[Z80_L];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
313 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
314 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
315 case 'i':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
316 if(param[1] == 'x') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
317 if (param[2] == 'h') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
318 value = context->regs[Z80_IXH];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
319 } else if(param[2] == 'l') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
320 value = context->regs[Z80_IXL];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
321 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
322 value = context->regs[Z80_IXH] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
323 value |= context->regs[Z80_IXL];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
324 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
325 } else if(param[1] == 'y') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
326 if (param[2] == 'h') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
327 value = context->regs[Z80_IYH];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
328 } else if(param[2] == 'l') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
329 value = context->regs[Z80_IYL];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
330 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
331 value = context->regs[Z80_IYH] << 8;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
332 value |= context->regs[Z80_IYL];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
333 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
334 } else if(param[1] == 'n') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
335 value = context->int_cycle;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
336 } else if(param[1] == 'f' && param[2] == 'f' && param[3] == '1') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
337 value = context->iff1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
338 } else if(param[1] == 'f' && param[2] == 'f' && param[3] == '2') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
339 value = context->iff2;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
340 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
341 value = context->im;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
342 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
343 break;
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
344 #endif
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
345 case 's':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
346 if (param[1] == 'p') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
347 value = context->sp;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
348 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
349 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
350 case '0':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
351 if (param[1] == 'x') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
352 uint16_t p_addr = strtol(param+2, NULL, 16);
1920
7b41cb36e7df Use proper memory map in Z80 debugger for memory printing
Michael Pavone <pavone@retrodev.com>
parents: 1752
diff changeset
353 value = read_byte(p_addr, (void **)context->mem_pointers, &context->options->gen, context);
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
354 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
355 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
356 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
357 printf(format, param, value);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
358 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
359
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
360 z80_context * zdebugger(z80_context * context, uint16_t address)
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
361 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
362 static char last_cmd[1024];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
363 char input_buf[1024];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
364 static uint16_t branch_t;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
365 static uint16_t branch_f;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
366 z80inst inst;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
367 genesis_context *system = context->system;
794
792be135d3af Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
368 init_terminal();
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
369 //Check if this is a user set breakpoint, or just a temporary one
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
370 bp_def ** this_bp = find_breakpoint(&zbreakpoints, address);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
371 if (*this_bp) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
372 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
373 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
374 zremove_breakpoint(context, address);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
375 }
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
376 uint8_t * pc = get_native_pointer(address, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
377 if (!pc) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
378 fatal_error("Failed to get native pointer on entering Z80 debugger at address %X\n", address);
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
379 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
380 for (disp_def * cur = zdisplays; cur; cur = cur->next) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
381 zdebugger_print(context, cur->format_char, cur->param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
382 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
383 uint8_t * after_pc = z80_decode(pc, &inst);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
384 z80_disasm(&inst, input_buf, address);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
385 printf("%X:\t%s\n", address, input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
386 uint16_t after = address + (after_pc-pc);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
387 int debugging = 1;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
388 while(debugging) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
389 fputs(">", stdout);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
390 if (!fgets(input_buf, sizeof(input_buf), stdin)) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
391 fputs("fgets failed", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
392 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
393 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
394 strip_nl(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
395 //hitting enter repeats last command
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
396 if (input_buf[0]) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
397 strcpy(last_cmd, input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
398 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
399 strcpy(input_buf, last_cmd);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
400 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
401 char * param;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
402 char format[8];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
403 uint32_t value;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
404 bp_def * new_bp;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
405 switch(input_buf[0])
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
406 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
407 case 'a':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
408 param = find_param(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
409 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
410 fputs("a command requires a parameter\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
411 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
412 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
413 value = strtol(param, NULL, 16);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
414 zinsert_breakpoint(context, value, (uint8_t *)zdebugger);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
415 debugging = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
416 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
417 case 'b':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
418 param = find_param(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
419 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
420 fputs("b command requires a parameter\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
421 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
422 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
423 value = strtol(param, NULL, 16);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
424 zinsert_breakpoint(context, value, (uint8_t *)zdebugger);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
425 new_bp = malloc(sizeof(bp_def));
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
426 new_bp->next = zbreakpoints;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
427 new_bp->address = value;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
428 new_bp->index = zbp_index++;
867
bacd67a82d58 Properly initialize commands when adding a new breakpoint
Michael Pavone <pavone@retrodev.com>
parents: 865
diff changeset
429 new_bp->commands = NULL;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
430 zbreakpoints = new_bp;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
431 printf("Z80 Breakpoint %d set at %X\n", new_bp->index, value);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
432 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
433 case 'c':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
434 puts("Continuing");
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
435 debugging = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
436 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
437 case 'd':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
438 if (input_buf[1] == 'i') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
439 char format_char = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
440 for(int i = 2; input_buf[i] != 0 && input_buf[i] != ' '; i++) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
441 if (input_buf[i] == '/') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
442 format_char = input_buf[i+1];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
443 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
444 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
445 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
446 param = find_param(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
447 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
448 fputs("display command requires a parameter\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
449 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
450 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
451 zdebugger_print(context, format_char, param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
452 add_display(&zdisplays, &zdisp_index, format_char, param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
453 } else if (input_buf[1] == 'e' || input_buf[1] == ' ') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
454 param = find_param(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
455 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
456 fputs("delete command requires a parameter\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
457 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
458 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
459 if (param[0] >= '0' && param[0] <= '9') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
460 value = atoi(param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
461 this_bp = find_breakpoint_idx(&zbreakpoints, value);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
462 if (!*this_bp) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
463 fprintf(stderr, "Breakpoint %d does not exist\n", value);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
464 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
465 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
466 new_bp = *this_bp;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
467 zremove_breakpoint(context, new_bp->address);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
468 *this_bp = new_bp->next;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
469 free(new_bp);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
470 } else if (param[0] == 'd') {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
471 param = find_param(param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
472 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
473 fputs("delete display command requires a parameter\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
474 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
475 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
476 remove_display(&zdisplays, atoi(param));
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
477 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
478 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
479 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
480 case 'n':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
481 //TODO: Handle conditional branch instructions
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
482 if (inst.op == Z80_JP) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
483 if (inst.addr_mode == Z80_IMMED) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
484 after = inst.immed;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
485 } else if (inst.ea_reg == Z80_HL) {
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
486 #ifndef NEW_CORE
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
487 after = context->regs[Z80_H] << 8 | context->regs[Z80_L];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
488 } else if (inst.ea_reg == Z80_IX) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
489 after = context->regs[Z80_IXH] << 8 | context->regs[Z80_IXL];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
490 } else if (inst.ea_reg == Z80_IY) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
491 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL];
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
492 #endif
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
493 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
494 } else if(inst.op == Z80_JR) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
495 after += inst.immed;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
496 } else if(inst.op == Z80_RET) {
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
497 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
498 if (sp) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
499 after = *sp;
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
500 sp = get_native_pointer((context->sp + 1) & 0xFFFF, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
501 if (sp) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
502 after |= *sp << 8;
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
503 }
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
504 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
505 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
506 zinsert_breakpoint(context, after, (uint8_t *)zdebugger);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
507 debugging = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
508 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
509 case 'p':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
510 param = find_param(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
511 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
512 fputs("p command requires a parameter\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
513 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
514 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
515 zdebugger_print(context, input_buf[1] == '/' ? input_buf[2] : 0, param);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
516 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
517 case 'q':
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
518 puts("Quitting");
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
519 exit(0);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
520 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
521 case 's': {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
522 param = find_param(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
523 if (!param) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
524 fputs("s command requires a file name\n", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
525 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
526 }
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
527 memmap_chunk const *ram_chunk = NULL;
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
528 for (int i = 0; i < context->Z80_OPTS->gen.memmap_chunks; i++)
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
529 {
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
530 memmap_chunk const *cur = context->Z80_OPTS->gen.memmap + i;
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
531 if (cur->flags & MMAP_WRITE) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
532 ram_chunk = cur;
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
533 break;
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
534 }
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
535 }
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
536 if (ram_chunk) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
537 uint32_t size = ram_chunk->end - ram_chunk->start;
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
538 if (size > ram_chunk->mask) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
539 size = ram_chunk->mask+1;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
540 }
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
541 uint8_t *buf = get_native_pointer(ram_chunk->start, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
542 FILE * f = fopen(param, "wb");
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
543 if (f) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
544 if(fwrite(buf, 1, size, f) != size) {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
545 fputs("Error writing file\n", stderr);
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
546 }
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
547 fclose(f);
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
548 printf("Wrote %d bytes to %s\n", size, param);
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
549 } else {
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
550 fprintf(stderr, "Could not open %s for writing\n", param);
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
551 }
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
552 } else {
1129
6b5c92b6205c Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
553 fputs("Failed to find a RAM memory chunk\n", stderr);
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
554 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
555 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
556 }
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
557 case '?':
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
558 print_z80_help();
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
559 break;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
560 default:
1149
6b0da6021544 Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
561 if (
1752
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
562 !context->Z80_OPTS->gen.debug_cmd_handler
d6d4c006a7b3 Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents: 1630
diff changeset
563 || !context->Z80_OPTS->gen.debug_cmd_handler(&system->header, input_buf)
1149
6b0da6021544 Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
564 ) {
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
565 fprintf(stderr, "Unrecognized debugger command %s\nUse '?' for help.\n", input_buf);
1149
6b0da6021544 Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
566 }
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
567 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
568 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
569 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
570 return context;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
571 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
572
548
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 525
diff changeset
573 #endif
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 525
diff changeset
574
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
575 static uint32_t branch_t;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
576 static uint32_t branch_f;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
577
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
578 int run_debugger_command(m68k_context *context, uint32_t address, char *input_buf, m68kinst inst, uint32_t after)
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
579 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
580 char * param;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
581 char format_char;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
582 genesis_context *system = context->system;
849
1416c4261d5b Fix some debug commands that got broken when I added support for the command command
Michael Pavone <pavone@retrodev.com>
parents: 831
diff changeset
583 uint32_t value;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
584 bp_def *new_bp, **this_bp;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
585 switch(input_buf[0])
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
586 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
587 case 'c':
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
588 if (input_buf[1] == 0 || input_buf[1] == 'o' && input_buf[2] == 'n')
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
589 {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
590 puts("Continuing");
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
591 return 0;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
592 } else if (input_buf[1] == 'o' && input_buf[2] == 'm') {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
593 param = find_param(input_buf);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
594 if (!param) {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
595 fputs("com command requires a parameter\n", stderr);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
596 break;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
597 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
598 bp_def **target = find_breakpoint_idx(&breakpoints, atoi(param));
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
599 if (!target) {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
600 fprintf(stderr, "Breakpoint %s does not exist!\n", param);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
601 break;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
602 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
603 printf("Enter commands for breakpoing %d, type end when done\n", atoi(param));
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
604 char cmd_buf[1024];
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
605 char *commands = NULL;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
606 for (;;)
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
607 {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
608 fputs(">>", stdout);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
609 fflush(stdout);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
610 fgets(cmd_buf, sizeof(cmd_buf), stdin);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
611 if (strcmp(cmd_buf, "end\n")) {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
612 if (commands) {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
613 char *tmp = commands;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
614 commands = alloc_concat(commands, cmd_buf);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
615 free(tmp);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
616 } else {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
617 commands = strdup(cmd_buf);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
618 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
619 } else {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
620 break;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
621 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
622 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
623 (*target)->commands = commands;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
624 } else {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
625 }
1310
de742a7bd9f7 Fix accidental fallthrough on com debugger command
Michael Pavone <pavone@retrodev.com>
parents: 1149
diff changeset
626 break;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
627 case 'b':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
628 if (input_buf[1] == 't') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
629 uint32_t stack = context->aregs[7];
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
630 if (stack >= 0xE00000) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
631 stack &= 0xFFFF;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
632 uint8_t non_adr_count = 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
633 do {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
634 uint32_t bt_address = system->work_ram[stack/2] << 16 | system->work_ram[stack/2+1];
1130
8f14767661fa Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents: 1129
diff changeset
635 bt_address = get_instruction_start(context->options, bt_address - 2);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
636 if (bt_address) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
637 stack += 4;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
638 non_adr_count = 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
639 uint16_t *bt_pc = NULL;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
640 if (bt_address < 0x400000) {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
641 bt_pc = system->cart + bt_address/2;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
642 } else if(bt_address > 0xE00000) {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
643 bt_pc = system->work_ram + (bt_address & 0xFFFF)/2;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
644 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
645 m68k_decode(bt_pc, &inst, bt_address);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
646 m68k_disasm(&inst, input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
647 printf("%X: %s\n", bt_address, input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
648 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
649 //non-return address value on stack can be word wide
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
650 stack += 2;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
651 non_adr_count++;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
652 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
653 stack &= 0xFFFF;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
654 } while (stack && non_adr_count < 6);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
655 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
656 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
657 param = find_param(input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
658 if (!param) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
659 fputs("b command requires a parameter\n", stderr);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
660 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
661 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
662 value = strtol(param, NULL, 16);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
663 insert_breakpoint(context, value, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
664 new_bp = malloc(sizeof(bp_def));
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
665 new_bp->next = breakpoints;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
666 new_bp->address = value;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
667 new_bp->index = bp_index++;
919
38dca41f151d Initialize commands field of breakpoint struct to NULL. Remove a debug printf
Michael Pavone <pavone@retrodev.com>
parents: 867
diff changeset
668 new_bp->commands = NULL;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
669 breakpoints = new_bp;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
670 printf("68K Breakpoint %d set at %X\n", new_bp->index, value);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
671 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
672 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
673 case 'a':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
674 param = find_param(input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
675 if (!param) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
676 fputs("a command requires a parameter\n", stderr);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
677 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
678 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
679 value = strtol(param, NULL, 16);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
680 insert_breakpoint(context, value, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
681 return 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
682 case 'd':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
683 if (input_buf[1] == 'i') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
684 format_char = 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
685 for(int i = 2; input_buf[i] != 0 && input_buf[i] != ' '; i++) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
686 if (input_buf[i] == '/') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
687 format_char = input_buf[i+1];
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
688 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
689 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
690 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
691 param = find_param(input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
692 if (!param) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
693 fputs("display command requires a parameter\n", stderr);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
694 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
695 }
1923
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
696 debugger_print(context, format_char, param, address);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
697 add_display(&displays, &disp_index, format_char, param);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
698 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
699 param = find_param(input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
700 if (!param) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
701 fputs("d command requires a parameter\n", stderr);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
702 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
703 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
704 value = atoi(param);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
705 this_bp = find_breakpoint_idx(&breakpoints, value);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
706 if (!*this_bp) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
707 fprintf(stderr, "Breakpoint %d does not exist\n", value);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
708 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
709 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
710 new_bp = *this_bp;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
711 *this_bp = (*this_bp)->next;
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
712 if (new_bp->commands) {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
713 free(new_bp->commands);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
714 }
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
715 free(new_bp);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
716 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
717 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
718 case 'p':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
719 format_char = 0;
831
079eb395ddd1 Fix handling of formatting character for 68K debug command p
Michael Pavone <pavone@retrodev.com>
parents: 830
diff changeset
720 for(int i = 1; input_buf[i] != 0 && input_buf[i] != ' '; i++) {
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
721 if (input_buf[i] == '/') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
722 format_char = input_buf[i+1];
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
723 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
724 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
725 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
726 param = find_param(input_buf);
1923
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
727 if (param) {
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
728 debugger_print(context, format_char, param, address);
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
729 } else {
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
730 m68k_disasm(&inst, input_buf);
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
731 printf("%X: %s\n", address, input_buf);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
732 }
1923
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
733
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
734 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
735 case 'n':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
736 if (inst.op == M68K_RTS) {
1313
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
737 after = m68k_read_long(context->aregs[7], context);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
738 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) {
1313
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
739 after = m68k_read_long(context->aregs[7] + 2, context);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
740 } else if(m68k_is_noncall_branch(&inst)) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
741 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
742 branch_f = after;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
743 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
744 insert_breakpoint(context, branch_t, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
745 } else if(inst.op == M68K_DBCC) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
746 if ( inst.extra.cond == COND_FALSE) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
747 if (context->dregs[inst.dst.params.regs.pri] & 0xFFFF) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
748 after = m68k_branch_target(&inst, context->dregs, context->aregs);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
749 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
750 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
751 branch_t = after;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
752 branch_f = m68k_branch_target(&inst, context->dregs, context->aregs);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
753 insert_breakpoint(context, branch_f, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
754 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
755 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
756 after = m68k_branch_target(&inst, context->dregs, context->aregs);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
757 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
758 }
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
759 insert_breakpoint(context, after, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
760 return 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
761 case 'o':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
762 if (inst.op == M68K_RTS) {
1313
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
763 after = m68k_read_long(context->aregs[7], context);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
764 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) {
1313
b27d7bf1107e Improved printing of word at absolute address to support reading from all address types. Implemented support for printing the value pointed to by a register. Removed abuse of read_dma_value in internal debugger.
Michael Pavone <pavone@retrodev.com>
parents: 1312
diff changeset
765 after = m68k_read_long(context->aregs[7] + 2, context);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
766 } else if(m68k_is_noncall_branch(&inst)) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
767 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
768 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
769 if (branch_t < after) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
770 branch_t = 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
771 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
772 branch_f = after;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
773 insert_breakpoint(context, branch_t, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
774 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
775 } else if(inst.op == M68K_DBCC) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
776 uint32_t target = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
777 if (target > after) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
778 if (inst.extra.cond == COND_FALSE) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
779 after = target;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
780 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
781 branch_f = target;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
782 branch_t = after;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
783 insert_breakpoint(context, branch_f, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
784 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
785 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
786 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
787 after = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
788 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
789 }
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
790 insert_breakpoint(context, after, debugger);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
791 return 0;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
792 case 's':
1630
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
793 if (input_buf[1] == 'e') {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
794 param = find_param(input_buf);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
795 if (!param) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
796 fputs("Missing destination parameter for set\n", stderr);
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
797 return 1;
1630
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
798 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
799 char *val = find_param(param);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
800 if (!val) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
801 fputs("Missing value parameter for set\n", stderr);
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
802 return 1;
1630
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
803 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
804 long int_val;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
805 int reg_num;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
806 switch (val[0])
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
807 {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
808 case 'd':
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
809 case 'a':
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
810 reg_num = val[1] - '0';
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
811 if (reg_num < 0 || reg_num > 8) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
812 fprintf(stderr, "Invalid register %s\n", val);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
813 return 1;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
814 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
815 int_val = (val[0] == 'd' ? context->dregs : context->aregs)[reg_num];
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
816 break;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
817 case '$':
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
818 int_val = strtol(val+1, NULL, 16);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
819 break;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
820 case '0':
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
821 if (val[1] == 'x') {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
822 int_val = strtol(val+2, NULL, 16);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
823 break;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
824 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
825 default:
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
826 int_val = strtol(val, NULL, 10);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
827 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
828 switch(param[0])
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
829 {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
830 case 'd':
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
831 case 'a':
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
832 reg_num = param[1] - '0';
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
833 if (reg_num < 0 || reg_num > 8) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
834 fprintf(stderr, "Invalid register %s\n", param);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
835 return 1;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
836 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
837 (param[0] == 'd' ? context->dregs : context->aregs)[reg_num] = int_val;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
838 break;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
839 default:
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
840 fprintf(stderr, "Invalid destinatino %s\n", param);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
841 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
842 break;
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
843 } else if (input_buf[1] == 'r') {
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
844 system->header.soft_reset(&system->header);
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
845 return 0;
1630
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
846 } else {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
847 if (inst.op == M68K_RTS) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
848 after = m68k_read_long(context->aregs[7], context);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
849 } else if (inst.op == M68K_RTE || inst.op == M68K_RTR) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
850 after = m68k_read_long(context->aregs[7] + 2, context);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
851 } else if(m68k_is_branch(&inst)) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
852 if (inst.op == M68K_BCC && inst.extra.cond != COND_TRUE) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
853 branch_f = after;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
854 branch_t = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
855 insert_breakpoint(context, branch_t, debugger);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
856 } else if(inst.op == M68K_DBCC) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
857 if (inst.extra.cond == COND_FALSE) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
858 if (context->dregs[inst.dst.params.regs.pri] & 0xFFFF) {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
859 after = m68k_branch_target(&inst, context->dregs, context->aregs);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
860 }
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
861 } else {
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
862 branch_t = after;
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
863 branch_f = m68k_branch_target(&inst, context->dregs, context->aregs);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
864 insert_breakpoint(context, branch_f, debugger);
1424
4f96103b4b47 Fix s(tep) debug command for the case of dbra with an expired counter reg
Michael Pavone <pavone@retrodev.com>
parents: 1329
diff changeset
865 }
4f96103b4b47 Fix s(tep) debug command for the case of dbra with an expired counter reg
Michael Pavone <pavone@retrodev.com>
parents: 1329
diff changeset
866 } else {
1630
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
867 after = m68k_branch_target(&inst, context->dregs, context->aregs) & 0xFFFFFF;
1424
4f96103b4b47 Fix s(tep) debug command for the case of dbra with an expired counter reg
Michael Pavone <pavone@retrodev.com>
parents: 1329
diff changeset
868 }
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
869 }
1630
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
870 insert_breakpoint(context, after, debugger);
5aa0c3c43b97 Added a 68K debugger command for setting a register
Michael Pavone <pavone@retrodev.com>
parents: 1629
diff changeset
871 return 0;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
872 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
873 case 'v': {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
874 genesis_context * gen = context->system;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
875 //VDP debug commands
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
876 switch(input_buf[1])
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
877 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
878 case 's':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
879 vdp_print_sprite_table(gen->vdp);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
880 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
881 case 'r':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
882 vdp_print_reg_explain(gen->vdp);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
883 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
884 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
885 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
886 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
887 case 'y': {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
888 genesis_context * gen = context->system;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
889 //YM-2612 debug commands
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
890 switch(input_buf[1])
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
891 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
892 case 'c':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
893 if (input_buf[2] == ' ') {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
894 int channel = atoi(input_buf+3)-1;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
895 ym_print_channel_info(gen->ym, channel);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
896 } else {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
897 for (int i = 0; i < 6; i++) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
898 ym_print_channel_info(gen->ym, i);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
899 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
900 }
930
f33e8d88ab6f Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents: 919
diff changeset
901 break;
f33e8d88ab6f Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents: 919
diff changeset
902 case 't':
f33e8d88ab6f Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents: 919
diff changeset
903 ym_print_timer_info(gen->ym);
f33e8d88ab6f Add yt debug command for printing YM-2612 timer info. Fix AMS shift values.
Michael Pavone <pavone@retrodev.com>
parents: 919
diff changeset
904 break;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
905 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
906 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
907 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
908 #ifndef NO_Z80
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
909 case 'z': {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
910 genesis_context * gen = context->system;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
911 //Z80 debug commands
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
912 switch(input_buf[1])
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
913 {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
914 case 'b':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
915 param = find_param(input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
916 if (!param) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
917 fputs("zb command requires a parameter\n", stderr);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
918 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
919 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
920 value = strtol(param, NULL, 16);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
921 zinsert_breakpoint(gen->z80, value, (uint8_t *)zdebugger);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
922 new_bp = malloc(sizeof(bp_def));
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
923 new_bp->next = zbreakpoints;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
924 new_bp->address = value;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
925 new_bp->index = zbp_index++;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
926 zbreakpoints = new_bp;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
927 printf("Z80 Breakpoint %d set at %X\n", new_bp->index, value);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
928 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
929 case 'p':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
930 param = find_param(input_buf);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
931 if (!param) {
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
932 fputs("zp command requires a parameter\n", stderr);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
933 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
934 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
935 zdebugger_print(gen->z80, input_buf[2] == '/' ? input_buf[3] : 0, param);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
936 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
937 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
938 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
939 #endif
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
940 case '?':
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
941 print_m68k_help();
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
942 break;
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
943 case 'q':
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
944 puts("Quitting");
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
945 exit(0);
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
946 break;
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
947 default:
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
948 fprintf(stderr, "Unrecognized debugger command %s\nUse '?' for help.\n", input_buf);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
949 break;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
950 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
951 return 1;
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
952 }
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
953
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
954 void print_m68k_help()
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
955 {
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
956 printf("M68k Debugger Commands\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
957 printf(" b ADDRESS - Set a breakpoint at ADDRESS\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
958 printf(" d BREAKPOINT - Delete a 68K breakpoint\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
959 printf(" co BREAKPOINT - Run a list of debugger commands each time\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
960 printf(" BREAKPOINT is hit\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
961 printf(" a ADDRESS - Advance to address\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
962 printf(" n - Advance to next instruction\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
963 printf(" o - Advance to next instruction ignoring branches to\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
964 printf(" lower addresses (good for breaking out of loops)\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
965 printf(" s - Advance to next instruction (follows bsr/jsr)\n");
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
966 printf(" se REG|ADDRESS VALUE - Set value\n");
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
967 printf(" sr - Soft reset\n");
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
968 printf(" c - Continue\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
969 printf(" bt - Print a backtrace\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
970 printf(" p[/(x|X|d|c)] VALUE - Print a register or memory location\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
971 printf(" di[/(x|X|d|c)] VALUE - Print a register or memory location each time\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
972 printf(" a breakpoint is hit\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
973 printf(" vs - Print VDP sprite list\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
974 printf(" vr - Print VDP register info\n");
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
975 printf(" yc [CHANNEL NUM] - Print YM-2612 channel info\n");
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
976 printf(" yt - Print YM-2612 timer info\n");
1921
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
977 printf(" zb ADDRESS - Set a Z80 breakpoint\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
978 printf(" zp[/(x|X|d|c)] VALUE - Display a Z80 value\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
979 printf(" ? - Display help\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
980 printf(" q - Quit BlastEm\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
981 }
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
982
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
983 void print_z80_help()
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
984 {
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
985 printf("Z80 Debugger Commands\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
986 printf(" b ADDRESS - Set a breakpoint at ADDRESS\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
987 printf(" de BREAKPOINT - Delete a Z80 breakpoint\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
988 printf(" a ADDRESS - Advance to address\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
989 printf(" n - Advance to next instruction\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
990 printf(" c - Continue\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
991 printf(" p[/(x|X|d|c)] VALUE - Print a register or memory location\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
992 printf(" di[/(x|X|d|c)] VALUE - Print a register or memory location each time\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
993 printf(" a breakpoint is hit\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
994 printf(" q - Quit BlastEm\n");
5d028088e320 Added help commands to debugger
Eric Fry <yuv422@users.noreply.github.com>
parents: 1920
diff changeset
995 }
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
996
1329
85a90964b557 Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents: 1314
diff changeset
997 void debugger(m68k_context * context, uint32_t address)
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
998 {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
999 static char last_cmd[1024];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1000 char input_buf[1024];
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1001 m68kinst inst;
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1002
794
792be135d3af Spawn a terminal for the debugger when needed if we are not already attached to one
Michael Pavone <pavone@retrodev.com>
parents: 792
diff changeset
1003 init_terminal();
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1004
707
8aa9aacefe12 Sync machine state before entering debugger
Michael Pavone <pavone@retrodev.com>
parents: 652
diff changeset
1005 sync_components(context, 0);
1629
079e5b9d59ce Forcefully update the display when entering the 68K debugger so you can see it update in realtime as you step through the code
Michael Pavone <pavone@retrodev.com>
parents: 1424
diff changeset
1006 genesis_context *gen = context->system;
079e5b9d59ce Forcefully update the display when entering the 68K debugger so you can see it update in realtime as you step through the code
Michael Pavone <pavone@retrodev.com>
parents: 1424
diff changeset
1007 vdp_force_update_framebuffer(gen->vdp);
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1008 //probably not necessary, but let's play it safe
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1009 address &= 0xFFFFFF;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1010 if (address == branch_t) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1011 bp_def ** f_bp = find_breakpoint(&breakpoints, branch_f);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1012 if (!*f_bp) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1013 remove_breakpoint(context, branch_f);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1014 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1015 branch_t = branch_f = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1016 } else if(address == branch_f) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1017 bp_def ** t_bp = find_breakpoint(&breakpoints, branch_t);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1018 if (!*t_bp) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1019 remove_breakpoint(context, branch_t);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1020 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1021 branch_t = branch_f = 0;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1022 }
849
1416c4261d5b Fix some debug commands that got broken when I added support for the command command
Michael Pavone <pavone@retrodev.com>
parents: 831
diff changeset
1023
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
1024 uint16_t * pc = get_native_pointer(address, (void **)context->mem_pointers, &context->options->gen);
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 985
diff changeset
1025 if (!pc) {
849
1416c4261d5b Fix some debug commands that got broken when I added support for the command command
Michael Pavone <pavone@retrodev.com>
parents: 831
diff changeset
1026 fatal_error("Entered 68K debugger at address %X\n", address);
1416c4261d5b Fix some debug commands that got broken when I added support for the command command
Michael Pavone <pavone@retrodev.com>
parents: 831
diff changeset
1027 }
1416c4261d5b Fix some debug commands that got broken when I added support for the command command
Michael Pavone <pavone@retrodev.com>
parents: 831
diff changeset
1028 uint16_t * after_pc = m68k_decode(pc, &inst, address);
1416c4261d5b Fix some debug commands that got broken when I added support for the command command
Michael Pavone <pavone@retrodev.com>
parents: 831
diff changeset
1029 uint32_t after = address + (after_pc-pc)*2;
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1030 int debugging = 1;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1031 //Check if this is a user set breakpoint, or just a temporary one
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1032 bp_def ** this_bp = find_breakpoint(&breakpoints, address);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1033 if (*this_bp) {
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1034
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1035 if ((*this_bp)->commands)
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1036 {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1037 char *commands = strdup((*this_bp)->commands);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1038 char *copy = commands;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1039
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1040 while (debugging && *commands)
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1041 {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1042 char *cmd = commands;
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1043 strip_nl(cmd);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1044 commands += strlen(cmd) + 1;
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
1045 debugging = run_debugger_command(context, address, cmd, inst, after);
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1046 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1047 free(copy);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1048 }
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1049 if (debugging) {
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1050 printf("68K Breakpoint %d hit\n", (*this_bp)->index);
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1051 } else {
1329
85a90964b557 Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents: 1314
diff changeset
1052 return;
830
5a3ac6093ea2 Add support for executing a list of debugger commands when a breakpoint is hit
Michael Pavone <pavone@retrodev.com>
parents: 829
diff changeset
1053 }
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1054 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1055 remove_breakpoint(context, address);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1056 }
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
1057 for (disp_def * cur = displays; cur; cur = cur->next) {
1923
23394a890508 Added implementation of printing PC in 68K debugger
Michael Pavone <pavone@retrodev.com>
parents: 1922
diff changeset
1058 debugger_print(context, cur->format_char, cur->param, address);
829
cc05444a4a4e WIP debugger improvements. Partial support for display command in 68K debugger. Minor refactor to support commands on a breakpoint.
Michael Pavone <pavone@retrodev.com>
parents: 794
diff changeset
1059 }
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1060 m68k_disasm(&inst, input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1061 printf("%X: %s\n", address, input_buf);
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
1062 #ifdef _WIN32
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
1063 #define prompt 1
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
1064 #else
723
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1065 int prompt = 1;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1066 fd_set read_fds;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1067 FD_ZERO(&read_fds);
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1068 struct timeval timeout;
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
1069 #endif
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1070 while (debugging) {
723
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1071 if (prompt) {
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1072 fputs(">", stdout);
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1073 fflush(stdout);
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1074 }
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1075 process_events();
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
1076 #ifndef _WIN32
723
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1077 timeout.tv_sec = 0;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1078 timeout.tv_usec = 16667;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1079 FD_SET(fileno(stdin), &read_fds);
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1080 if(select(fileno(stdin) + 1, &read_fds, NULL, NULL, &timeout) < 1) {
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1081 prompt = 0;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1082 continue;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1083 } else {
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1084 prompt = 1;
7178d750efbd Process events while waiting for 68K debugger input. This prevents "not responsive" dialogs when sitting in the debugger
Michael Pavone <pavone@retrodev.com>
parents: 707
diff changeset
1085 }
745
daa31ee7d8cd Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents: 723
diff changeset
1086 #endif
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1087 if (!fgets(input_buf, sizeof(input_buf), stdin)) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1088 fputs("fgets failed", stderr);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1089 break;
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1090 }
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1091 strip_nl(input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1092 //hitting enter repeats last command
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1093 if (input_buf[0]) {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1094 strcpy(last_cmd, input_buf);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1095 } else {
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1096 strcpy(input_buf, last_cmd);
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1097 }
1922
4a811fd1fb6f Added soft reset command to debugger. Added more debugger help
Eric Fry <yuv422@users.noreply.github.com>
parents: 1921
diff changeset
1098 debugging = run_debugger_command(context, address, input_buf, inst, after);
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1099 }
1329
85a90964b557 Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents: 1314
diff changeset
1100 return;
524
fb39534b6604 Move debugging code outside of main source file
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1101 }