src/gb/debugger/debugger.c (view raw)
1/* Copyright (c) 2013-2019 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/gb/debugger/debugger.h>
7
8 #include <mgba/core/core.h>
9 #include <mgba/internal/debugger/cli-debugger.h>
10 #include <mgba/internal/gb/gb.h>
11 #include <mgba/internal/gb/io.h>
12 #include <mgba/internal/gb/memory.h>
13 #include <mgba/internal/sm83/debugger/debugger.h>
14
15static const struct SM83Segment _GBSegments[] = {
16 { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM },
17 { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 },
18 { 0 }
19};
20
21static const struct SM83Segment _GBCSegments[] = {
22 { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM },
23 { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 },
24 { .name = "WRAM", .start = GB_BASE_WORKING_RAM_BANK1, .end = 0xE000 },
25 { .name = "VRAM", .start = GB_BASE_VRAM, .end = GB_BASE_EXTERNAL_RAM },
26 { 0 }
27};
28
29static void _printStatus(struct CLIDebuggerSystem* debugger) {
30 struct CLIDebuggerBackend* be = debugger->p->backend;
31 struct GB* gb = debugger->p->d.core->board;
32 be->printf(be, "IE: %02X IF: %02X IME: %i\n", gb->memory.ie, gb->memory.io[GB_REG_IF], gb->memory.ime);
33 be->printf(be, "LCDC: %02X STAT: %02X LY: %02X\n", gb->memory.io[GB_REG_LCDC], gb->memory.io[GB_REG_STAT] | 0x80, gb->memory.io[GB_REG_LY]);
34 be->printf(be, "Next video mode: %i\n", mTimingUntil(&gb->timing, &gb->video.modeEvent) / 4);
35}
36
37struct mDebuggerPlatform* GBDebuggerCreate(struct GB* gb) {
38 struct SM83Debugger* platform = (struct SM83Debugger*) SM83DebuggerPlatformCreate();
39 if (gb->model >= GB_MODEL_CGB) {
40 platform->segments = _GBCSegments;
41 } else {
42 platform->segments = _GBSegments;
43 }
44 platform->printStatus = _printStatus;
45 return &platform->d;
46}