all repos — mgba @ 72b826dd2077dcc4affe3dc0388750c3b7b13d7c

mGBA Game Boy Advance Emulator

src/lr35902/cli-debugger.c (view raw)

 1/* Copyright (c) 2013-2016 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "cli-debugger.h"
 7
 8#ifdef USE_CLI_DEBUGGER
 9#include "core/core.h"
10#include "debugger/cli-debugger.h"
11#include "lr35902/lr35902.h"
12
13static void _printStatus(struct CLIDebuggerSystem*);
14
15static struct CLIDebuggerCommandSummary _lr35902Commands[] = {
16	{ 0, 0, 0, 0 }
17};
18
19static inline void _printFlags(union FlagRegister f) {
20	printf("[%c%c%c%c]\n",
21	       f.z ? 'Z' : '-',
22	       f.n ? 'N' : '-',
23	       f.h ? 'H' : '-',
24	       f.c ? 'C' : '-');
25}
26
27static void _printStatus(struct CLIDebuggerSystem* debugger) {
28	struct LR35902Core* cpu = debugger->p->d.core->cpu;
29	printf("A: %02X F: %02X (AF: %04X)\n", cpu->a, cpu->f.packed, cpu->af);
30	printf("B: %02X C: %02X (BC: %04X)\n", cpu->b, cpu->c, cpu->bc);
31	printf("D: %02X E: %02X (DE: %04X)\n", cpu->d, cpu->e, cpu->de);
32	printf("H: %02X L: %02X (HL: %04X)\n", cpu->h, cpu->l, cpu->hl);
33	printf("PC: %04X SP: %04X\n", cpu->pc, cpu->sp);
34	_printFlags(cpu->f);
35}
36
37static uint32_t _lookupPlatformIdentifier(struct CLIDebuggerSystem* debugger, const char* name, struct CLIDebugVector* dv) {
38	struct LR35902Core* cpu = debugger->p->d.core->cpu;
39	if (strcmp(name, "a") == 0) {
40		return cpu->a;
41	}
42	if (strcmp(name, "b") == 0) {
43		return cpu->b;
44	}
45	if (strcmp(name, "c") == 0) {
46		return cpu->c;
47	}
48	if (strcmp(name, "d") == 0) {
49		return cpu->d;
50	}
51	if (strcmp(name, "e") == 0) {
52		return cpu->e;
53	}
54	if (strcmp(name, "h") == 0) {
55		return cpu->h;
56	}
57	if (strcmp(name, "l") == 0) {
58		return cpu->l;
59	}
60	if (strcmp(name, "bc") == 0) {
61		return cpu->bc;
62	}
63	if (strcmp(name, "de") == 0) {
64		return cpu->de;
65	}
66	if (strcmp(name, "hl") == 0) {
67		return cpu->hl;
68	}
69	if (strcmp(name, "af") == 0) {
70		return cpu->af;
71	}
72	if (strcmp(name, "pc") == 0) {
73		return cpu->pc;
74	}
75	if (strcmp(name, "sp") == 0) {
76		return cpu->pc;
77	}
78	if (strcmp(name, "f") == 0) {
79		return cpu->f.packed;
80	}
81	dv->type = CLIDV_ERROR_TYPE;
82	return 0;
83}
84
85void LR35902CLIDebuggerCreate(struct CLIDebuggerSystem* debugger) {
86	debugger->printStatus = _printStatus;
87	debugger->disassemble = NULL;
88	debugger->lookupPlatformIdentifier = _lookupPlatformIdentifier;
89	debugger->platformName = "GB-Z80";
90	debugger->platformCommands = NULL;
91}
92
93#endif