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