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