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*);
15static uint32_t _DSCLIDebuggerLookupIdentifier(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv);
16
17static void _frame(struct CLIDebugger*, struct CLIDebugVector*);
18static void _switchCpu(struct CLIDebugger*, struct CLIDebugVector*);
19
20struct CLIDebuggerCommandSummary _DSCLIDebuggerCommands[] = {
21 { "frame", _frame, 0, "Frame advance" },
22 { "cpu", _switchCpu, 0 , "Switch active CPU" },
23 { 0, 0, 0, 0 }
24};
25
26struct DSCLIDebugger* DSCLIDebuggerCreate(struct mCore* core) {
27 struct DSCLIDebugger* debugger = malloc(sizeof(struct DSCLIDebugger));
28 ARMCLIDebuggerCreate(&debugger->d);
29 debugger->d.init = _DSCLIDebuggerInit;
30 debugger->d.deinit = NULL;
31 debugger->d.custom = _DSCLIDebuggerCustom;
32 debugger->d.lookupIdentifier = _DSCLIDebuggerLookupIdentifier;
33
34 debugger->d.name = "DS";
35 debugger->d.commands = _DSCLIDebuggerCommands;
36
37 debugger->core = core;
38
39 return debugger;
40}
41
42static void _DSCLIDebuggerInit(struct CLIDebuggerSystem* debugger) {
43 struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger;
44
45 dsDebugger->frameAdvance = false;
46}
47
48static bool _DSCLIDebuggerCustom(struct CLIDebuggerSystem* debugger) {
49 return false;
50}
51
52static uint32_t _DSCLIDebuggerLookupIdentifier(struct CLIDebuggerSystem* debugger, const char* name, struct CLIDebugVector* dv) {
53 UNUSED(debugger);
54 dv->type = CLIDV_ERROR_TYPE;
55 return 0;
56}
57
58static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
59 UNUSED(dv);
60 debugger->d.state = DEBUGGER_CUSTOM;
61
62 struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger->system;
63 dsDebugger->frameAdvance = true;
64}
65
66static void _switchCpu(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
67 UNUSED(dv);
68 struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger->system;
69 struct mCore* core = dsDebugger->core;
70 struct DS* ds = core->board;
71 debugger->d.platform->deinit(debugger->d.platform);
72 if (core->cpu == ds->ds9.cpu) {
73 core->cpu = ds->ds7.cpu;
74 } else {
75 core->cpu = ds->ds9.cpu;
76 }
77 debugger->d.platform->init(core->cpu, debugger->d.platform);
78 debugger->system->printStatus(debugger->system);
79}