src/gb/cli.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.h"
7
8#include "core/core.h"
9#include "core/serialize.h"
10#include "gb/gb.h"
11#include "gb/io.h"
12#include "gb/video.h"
13#include "lr35902/debugger/cli-debugger.h"
14
15#ifdef USE_CLI_DEBUGGER
16
17static void _GBCLIDebuggerInit(struct CLIDebuggerSystem*);
18static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*);
19
20static void _frame(struct CLIDebugger*, struct CLIDebugVector*);
21
22struct CLIDebuggerCommandSummary _GBCLIDebuggerCommands[] = {
23 { "frame", _frame, 0, "Frame advance" },
24 { 0, 0, 0, 0 }
25};
26
27struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore* core) {
28 UNUSED(core);
29 struct GBCLIDebugger* debugger = malloc(sizeof(struct GBCLIDebugger));
30 LR35902CLIDebuggerCreate(&debugger->d);
31 debugger->d.init = _GBCLIDebuggerInit;
32 debugger->d.deinit = NULL;
33 debugger->d.custom = _GBCLIDebuggerCustom;
34 debugger->d.lookupIdentifier = NULL;
35
36 debugger->d.name = "Game Boy";
37 debugger->d.commands = _GBCLIDebuggerCommands;
38
39 debugger->core = core;
40
41 return &debugger->d;
42}
43
44static void _GBCLIDebuggerInit(struct CLIDebuggerSystem* debugger) {
45 struct GBCLIDebugger* gbDebugger = (struct GBCLIDebugger*) debugger;
46
47 gbDebugger->frameAdvance = false;
48}
49
50static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem* debugger) {
51 struct GBCLIDebugger* gbDebugger = (struct GBCLIDebugger*) debugger;
52
53 if (gbDebugger->frameAdvance) {
54 if (!gbDebugger->inVblank && GBRegisterSTATGetMode(((struct GB*) gbDebugger->core->board)->memory.io[REG_STAT]) == 1) {
55 mDebuggerEnter(&gbDebugger->d.p->d, DEBUGGER_ENTER_MANUAL, 0);
56 gbDebugger->frameAdvance = false;
57 return false;
58 }
59 gbDebugger->inVblank = GBRegisterSTATGetMode(((struct GB*) gbDebugger->core->board)->memory.io[REG_STAT]) == 1;
60 return true;
61 }
62 return false;
63}
64
65static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
66 UNUSED(dv);
67 debugger->d.state = DEBUGGER_CUSTOM;
68
69 struct GBCLIDebugger* gbDebugger = (struct GBCLIDebugger*) debugger->system;
70 gbDebugger->frameAdvance = true;
71 gbDebugger->inVblank = GBRegisterSTATGetMode(((struct GB*) gbDebugger->core->board)->memory.io[REG_STAT]) == 1;
72}
73
74#endif