all repos — mgba @ 510a539a504ea914d7ea6f30ece1e15d11c02b39

mGBA Game Boy Advance Emulator

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	debugger->d.commandAliases = NULL;
35
36	debugger->core = core;
37
38	return debugger;
39}
40
41static void _DSCLIDebuggerInit(struct CLIDebuggerSystem* debugger) {
42	struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger;
43
44	dsDebugger->frameAdvance = false;
45}
46
47static bool _DSCLIDebuggerCustom(struct CLIDebuggerSystem* debugger) {
48	return false;
49}
50
51static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
52	UNUSED(dv);
53	debugger->d.state = DEBUGGER_CUSTOM;
54
55	struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger->system;
56	dsDebugger->frameAdvance = true;
57}
58
59static void _switchCpu(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
60	UNUSED(dv);
61	struct DSCLIDebugger* dsDebugger = (struct DSCLIDebugger*) debugger->system;
62	struct mCore* core = dsDebugger->core;
63	struct DS* ds = core->board;
64	debugger->d.platform->deinit(debugger->d.platform);
65	if (core->cpu == ds->ds9.cpu) {
66		core->cpu = ds->ds7.cpu;
67		core->timing = &ds->ds7.timing;
68	} else {
69		core->cpu = ds->ds9.cpu;
70		core->timing = &ds->ds9.timing;
71	}
72	debugger->d.platform->init(core->cpu, debugger->d.platform);
73	debugger->system->printStatus(debugger->system);
74}