src/ds/extra/cli.c (view raw)
1/* Copyright (c) 2013-2017 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 <mgba/internal/ds/extra/cli.h>
7
8#include <mgba/internal/arm/debugger/cli-debugger.h>
9#include <mgba/core/core.h>
10#include <mgba/ds/core.h>
11#include <mgba/internal/ds/ds.h>
12
13static void _DSCLIDebuggerInit(struct CLIDebuggerSystem*);
14static bool _DSCLIDebuggerCustom(struct CLIDebuggerSystem*);
15
16static void _frame(struct CLIDebugger*, struct CLIDebugVector*);
17static void _switchCpu(struct CLIDebugger*, struct CLIDebugVector*);
18
19struct CLIDebuggerCommandSummary _DSCLIDebuggerCommands[] = {
20 { "frame", _frame, 0, "Frame advance" },
21 { "cpu", _switchCpu, 0 , "Switch active CPU" },
22 { 0, 0, 0, 0 }
23};
24
25struct DSCLIDebugger* DSCLIDebuggerCreate(struct mCore* core) {
26 struct DSCLIDebugger* debugger = malloc(sizeof(struct DSCLIDebugger));
27 ARMCLIDebuggerCreate(&debugger->d);
28 debugger->d.init = _DSCLIDebuggerInit;
29 debugger->d.deinit = NULL;
30 debugger->d.custom = _DSCLIDebuggerCustom;
31
32 debugger->d.name = "DS";
33 debugger->d.commands = _DSCLIDebuggerCommands;
34
35 debugger->core = core;
36
37 return debugger;
38}
39
40static void _DSCLIDebuggerInit(struct CLIDebuggerSystem* debugger) {
41 struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger;
42
43 dsDebugger->frameAdvance = false;
44}
45
46static bool _DSCLIDebuggerCustom(struct CLIDebuggerSystem* debugger) {
47 return false;
48}
49
50static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
51 UNUSED(dv);
52 debugger->d.state = DEBUGGER_CUSTOM;
53
54 struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger->system;
55 dsDebugger->frameAdvance = true;
56}
57
58static void _switchCpu(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
59 UNUSED(dv);
60 struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger->system;
61 struct mCore* core = dsDebugger->core;
62 struct DS* ds = core->board;
63 debugger->d.platform->deinit(debugger->d.platform);
64 if (core->cpu == ds->ds9.cpu) {
65 core->cpu = ds->ds7.cpu;
66 } else {
67 core->cpu = ds->ds9.cpu;
68 }
69 debugger->d.platform->init(core->cpu, debugger->d.platform);
70 debugger->system->printStatus(debugger->system);
71}