src/lr35902/debugger/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#include "core/core.h"
9#include "debugger/cli-debugger.h"
10#include "lr35902/lr35902.h"
11
12static void _printStatus(struct CLIDebuggerSystem*);
13
14static struct CLIDebuggerCommandSummary _lr35902Commands[] = {
15 { 0, 0, 0, 0 }
16};
17
18static inline void _printFlags(struct CLIDebuggerBackend* be, union FlagRegister f) {
19 be->printf(be, "[%c%c%c%c]\n",
20 f.z ? 'Z' : '-',
21 f.n ? 'N' : '-',
22 f.h ? 'H' : '-',
23 f.c ? 'C' : '-');
24}
25
26static void _printStatus(struct CLIDebuggerSystem* debugger) {
27 struct CLIDebuggerBackend* be = debugger->p->backend;
28 struct LR35902Core* cpu = debugger->p->d.core->cpu;
29 be->printf(be, "A: %02X F: %02X (AF: %04X)\n", cpu->a, cpu->f.packed, cpu->af);
30 be->printf(be, "B: %02X C: %02X (BC: %04X)\n", cpu->b, cpu->c, cpu->bc);
31 be->printf(be, "D: %02X E: %02X (DE: %04X)\n", cpu->d, cpu->e, cpu->de);
32 be->printf(be, "H: %02X L: %02X (HL: %04X)\n", cpu->h, cpu->l, cpu->hl);
33 be->printf(be, "PC: %04X SP: %04X\n", cpu->pc, cpu->sp);
34 _printFlags(be, 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->sp;
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 = _lr35902Commands;
91}