8 #define BYTES_PER_LINE 16
10 extern int debug_mode;
11 void dump_6502(int full);
12 void dump_vram(unsigned short addr, int size);
13 void dump_mem(unsigned short addr, int size);
14 unsigned char vram_data_get(unsigned short addr);
15 unsigned char dbg_get_byte(unsigned short addr);
16 unsigned short dbg_get_short(unsigned short addr);
17 void dump_ppu_reg(void);
18 void d1_set(int on_off);
19 void d2_set(int on_off);
20 void d3_set(int on_off);
21 void d4_set(int on_off);
23 #define MAX_HISTORY 10
30 static struct cmd_list* debug_history;
32 unsigned short break_point;
34 static void print_debug(void) {
35 printf(" command:\n");
37 printf(" c: continue\n");
38 printf(" b addr: set break point\n");
39 printf(" (break point can be set only 1 address.)\n");
40 printf(" del: delete break point\n");
41 printf(" m addr size: memory dump\n");
42 printf(" show: show registers\n");
43 printf(" pshow: show ppu registers\n");
44 printf(" v addr size: vram dump\n");
45 printf(" da addr size: disassemble\n");
46 printf(" d1 on/off: debug log level 1 (dump instruction on execution)\n");
47 printf(" d2 on/off: debug log level 2 (dump reg status for each instruction)\n");
48 printf(" d3 on/off: debug log level 3 (dump load/store data value)\n");
49 printf(" d4 on/off: debug log level 4 (dump vram data write)\n");
50 printf(" q: quit emulator\n");
54 static int read_cmd(char* buf) {
85 printf("motonesemu: ");
86 memset(buf, 0, sizeof(buf));
90 if (!strcmp(buf, "s")){
93 else if (!strcmp(buf, "q")){
94 extern int critical_error;
98 critical_error = TRUE;
102 else if (!strcmp(buf, "c")){
106 else if (!strcmp(buf, "show")){
109 else if (!strcmp(buf, "d1")){
111 if (!strcmp(buf, "on")){
114 else if (!strcmp(buf, "off")){
118 printf("log parameter must be either [on] or [off].\n");
121 else if (!strcmp(buf, "d2")){
123 if (!strcmp(buf, "on")){
126 else if (!strcmp(buf, "off")){
130 printf("d2 parameter must be either [on] or [off].\n");
133 else if (!strcmp(buf, "d3")){
135 if (!strcmp(buf, "on")){
138 else if (!strcmp(buf, "off")){
142 printf("d3 parameter must be either [on] or [off].\n");
145 else if (!strcmp(buf, "d4")){
147 if (!strcmp(buf, "on")){
150 else if (!strcmp(buf, "off")){
154 printf("d4 parameter must be either [on] or [off].\n");
157 else if (!strcmp(buf, "b")){
162 else if (!strcmp(buf, "del")){
165 else if (!strcmp(buf, "m")){
170 dump_mem(addr, size);
172 else if (!strcmp(buf, "v")){
177 dump_vram(addr, size);
179 else if (!strcmp(buf, "da")){
182 int disas_inst(unsigned short addr);
186 int l = disas_inst(addr);
188 printf("...(not an instruction)\n");
189 dump_mem(addr, size);
196 else if (!strcmp(buf, "pshow")){
200 printf("unknown command [%s].\n", buf);
208 void disasm(const char* mnemonic, int addr_mode, unsigned short pc) {
212 printf("%04x: %02x %02x %-5s $%02x\n", pc,
213 dbg_get_byte(pc), dbg_get_byte(pc + 1),
214 mnemonic, dbg_get_byte(pc + 1));
217 printf("%04x: %02x %02x %-5s $%02x, x\n", pc,
218 dbg_get_byte(pc), dbg_get_byte(pc + 1),
219 mnemonic, dbg_get_byte(pc + 1));
222 printf("%04x: %02x %02x %-5s $%02x, y\n", pc,
223 dbg_get_byte(pc), dbg_get_byte(pc + 1),
224 mnemonic, dbg_get_byte(pc + 1));
227 printf("%04x: %02x %02x %02x %-5s $%04x\n", pc,
228 dbg_get_byte(pc), dbg_get_byte(pc + 1), dbg_get_byte(pc + 2),
229 mnemonic, dbg_get_short(pc + 1));
231 case ADDR_MODE_ABS_X:
232 printf("%04x: %02x %02x %02x %-5s $%04x, x\n", pc,
233 dbg_get_byte(pc), dbg_get_byte(pc + 1), dbg_get_byte(pc + 2),
234 mnemonic, dbg_get_short(pc + 1));
236 case ADDR_MODE_ABS_Y:
237 printf("%04x: %02x %02x %02x %-5s $%04x, y\n", pc,
238 dbg_get_byte(pc), dbg_get_byte(pc + 1), dbg_get_byte(pc + 2),
239 mnemonic, dbg_get_short(pc + 1));
242 printf("%04x: %02x %02x %-5s ($%04x)\n", pc,
243 dbg_get_byte(pc), dbg_get_byte(pc + 1),
244 mnemonic, dbg_get_short(pc + 1));
248 printf("%04x: %02x %-5s \n", pc,
253 printf("%04x: %02x %02x %-5s #$%02x\n", pc,
254 dbg_get_byte(pc), dbg_get_byte(pc + 1),
255 mnemonic, dbg_get_byte(pc + 1));
258 printf("%04x: %02x %02x %-5s #%+d\n", pc,
259 dbg_get_byte(pc), dbg_get_byte(pc + 1),
260 mnemonic, (char)dbg_get_byte(pc + 1));
262 case ADDR_MODE_INDEX_INDIR:
263 printf("%04x: %02x %02x %-5s ($%02x, x), y\n", pc,
264 dbg_get_byte(pc), dbg_get_byte(pc + 1),
265 mnemonic, dbg_get_byte(pc + 1));
267 case ADDR_MODE_INDIR_INDEX:
268 printf("%04x: %02x %02x %-5s ($%02x), y\n", pc,
269 dbg_get_byte(pc), dbg_get_byte(pc + 1),
270 mnemonic, dbg_get_byte(pc + 1));
275 void dump_vram(unsigned short addr, int size) {
278 if (addr % BYTES_PER_LINE)
279 printf("%04x: ", addr % BYTES_PER_LINE);
281 for (i = 0; i < addr % BYTES_PER_LINE; i++) {
284 for (i = 0; i < size; i++) {
285 if (addr % BYTES_PER_LINE == 0)
286 printf("%04x: ", addr);
288 printf("%02x ", vram_data_get(addr));
290 if (addr % BYTES_PER_LINE == (BYTES_PER_LINE / 2) - 1)
293 if (addr % BYTES_PER_LINE == (BYTES_PER_LINE - 1))
301 void dump_mem(unsigned short addr, int size) {
303 unsigned char vram_data_get(unsigned short addr);
305 if (addr % BYTES_PER_LINE)
306 printf("%04x: ", addr);
308 for (i = 0; i < addr % BYTES_PER_LINE; i++) {
310 if (i % BYTES_PER_LINE == (BYTES_PER_LINE / 2) - 1)
313 for (i = 0; i < size; i++) {
314 if (addr % BYTES_PER_LINE == 0)
315 printf("%04x: ", addr);
317 printf("%02x ", dbg_get_byte(addr));
319 if (addr % BYTES_PER_LINE == (BYTES_PER_LINE / 2) - 1)
322 if (addr % BYTES_PER_LINE == (BYTES_PER_LINE - 1))
330 void break_hit(void) {
331 printf("------------------\nbreak...\n");
337 int init_debug(void) {
338 //dprint("init debug..\n");
339 debug_history = NULL;
341 //initscr(); /* Start curses mode */
346 void clean_debug(void) {
347 //dprint("clean debug..\n");
348 //endwin(); /* End curses mode */