Skip to content

Commit

Permalink
Add new debugger commands to disable PPU layers or APU channels.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Mar 15, 2024
1 parent 8c77e5c commit 5a3045a
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 84 deletions.
16 changes: 15 additions & 1 deletion include/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ struct ui_notification {
struct ui_notification *next;
};

struct app_config {
struct {
bool enable_bg_layers[4];
bool enable_oam;
} video;

struct {
bool enable_psg_channels[4];
bool enable_fifo_channels[2];
} audio;
};

struct app {
atomic_bool run;

Expand Down Expand Up @@ -369,6 +381,8 @@ struct app {
SDL_GameControllerButton controller_alt[BIND_MAX];
} binds;

struct app_config config;

#if WITH_DEBUGGER
struct {
bool is_running;
Expand Down Expand Up @@ -460,7 +474,7 @@ void app_emulator_run(struct app *app);
void app_emulator_pause(struct app *app);
void app_emulator_exit(struct app *app);
void app_emulator_key(struct app *app, enum keys key, bool pressed);
void app_emulator_speed(struct app *app, bool, float);
void app_emulator_settings(struct app *app);
void app_emulator_update_backup(struct app *app);
void app_emulator_screenshot(struct app *app);
void app_emulator_screenshot_path(struct app *app, char const *);
Expand Down
8 changes: 8 additions & 0 deletions include/app/dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ enum commands_list {
CMD_IO,
CMD_KEY,
CMD_SCREENSHOT,
CMD_PPU,
CMD_APU,
};

struct io_bitfield {
Expand Down Expand Up @@ -168,6 +170,9 @@ extern struct command g_commands[];
extern struct io_register g_io_registers[];
extern size_t g_io_registers_len;

/* app/dbg/cmd/apu.c */
void debugger_cmd_apu(struct app *, size_t, struct arg const *);

/* app/dbg/cmd/break.c */
void debugger_cmd_break(struct app *, size_t, struct arg const *);

Expand Down Expand Up @@ -201,6 +206,9 @@ void debugger_cmd_io(struct app *, size_t, struct arg const *);
/* app/dbg/cmd/key.c */
void debugger_cmd_key(struct app *, size_t, struct arg const *);

/* app/dbg/cmd/ppu.c */
void debugger_cmd_ppu(struct app *, size_t, struct arg const *);

/* app/dbg/cmd/print.c */
void debugger_cmd_print(struct app *, size_t, struct arg const *);
void debugger_cmd_print_u8(struct app const *, uint32_t, size_t, size_t);
Expand Down
7 changes: 3 additions & 4 deletions include/gba/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ enum message_kind {
MESSAGE_PAUSE,
MESSAGE_STOP,
MESSAGE_KEY,
MESSAGE_SPEED,
MESSAGE_QUICKSAVE,
MESSAGE_QUICKLOAD,
MESSAGE_SETTINGS,

#ifdef WITH_DEBUGGER
MESSAGE_FRAME,
Expand All @@ -49,10 +49,9 @@ struct message_reset {
struct launch_config config;
};

struct message_speed {
struct message_settings {
struct event_header header;
bool fast_forward;
float speed;
struct emulation_settings settings;
};

struct message_key {
Expand Down
33 changes: 28 additions & 5 deletions include/gba/gba.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ struct shared_data {
pthread_mutex_t audio_rbuffer_mutex;
};

/*
** Settings that can be altered while the game is running.
*/
struct emulation_settings {
// Fast forward
bool fast_forward;

// Speed. 0.5 = 30fps, 1 = 60fps, 2 = 120fps, etc.
// Can't be 0 unless `fast_forward` is true.
float speed;

struct {
bool enable_bg_layers[4];
bool enable_oam;
} ppu;

struct {
bool enable_psg_channels[4];
bool enable_fifo_channels[2];
} apu;
};

struct game_entry {
char *code;
enum backup_storage_types storage;
Expand All @@ -93,6 +115,9 @@ struct gba {
// Shared data with the frontend, mainly the framebuffer and audio channels.
struct shared_data shared_data;

// A set of settings the frontend can update during the emulator's execution (speed, etc.)
struct emulation_settings settings;

// The different components of the GBA
struct core core;
struct scheduler scheduler;
Expand Down Expand Up @@ -123,11 +148,6 @@ struct launch_config {
// True if the BIOS should be skipped
bool skip_bios;

bool fast_forward; // Fast forward

float speed; // Speed. 0.5 = 30fps, 1 = 60fps, 2 = 120fps, etc.
// Can't be 0 unless `fast_forward` is true.

// Set to the frontend's audio frequency.
// Can be 0 if the frontend has no audio.
uint32_t audio_frequency;
Expand All @@ -141,6 +161,9 @@ struct launch_config {
uint8_t *data;
size_t size;
} backup_storage;

// Initial value for all runtime-settings (speed, etc.)
struct emulation_settings settings;
};

struct notification;
Expand Down
7 changes: 1 addition & 6 deletions include/gba/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ struct scheduler {
struct scheduler_event *events;
size_t events_size;

bool fast_forward; // Fast forward

float speed; // Speed. 0.5 = 30fps, 1 = 60fps, 2 = 120fps, etc.
// Can't be 0 unless `fast_forward` is true.

uint64_t time_per_frame; // In usec
uint64_t time_last_frame; // In usec
uint64_t accumulated_time;
Expand Down Expand Up @@ -138,4 +133,4 @@ void sched_process_events(struct gba *gba);
void sched_run_for(struct gba *gba, uint64_t cycles);
void sched_frame_limiter(struct gba *gba,struct event_args args);
void sched_reset_frame_limiter(struct gba *gba);
void sched_update_speed(struct gba *gba, bool fast_forward, float speed);
void sched_update_speed(struct gba *gba);
6 changes: 3 additions & 3 deletions source/app/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ app_bindings_handle(
case BIND_GBA_START: app_emulator_key(app, KEY_START, pressed); break;
case BIND_EMULATOR_FAST_FORWARD_HOLD: {
app->emulation.fast_forward = pressed;
app_emulator_speed(app, app->emulation.fast_forward, app->emulation.speed);
app_emulator_settings(app);
break;
};
default: break;
Expand Down Expand Up @@ -167,12 +167,12 @@ app_bindings_handle(
};
app->emulation.fast_forward = false;
app->emulation.speed = speeds[bind - BIND_EMULATOR_SPEED_X0_25];
app_emulator_speed(app, app->emulation.fast_forward, app->emulation.speed);
app_emulator_settings(app);
break;
};
case BIND_EMULATOR_FAST_FORWARD_TOGGLE: {
app->emulation.fast_forward ^= true;
app_emulator_speed(app, app->emulation.fast_forward, app->emulation.speed);
app_emulator_settings(app);
break;
}
case BIND_EMULATOR_QUICKSAVE_1:
Expand Down
81 changes: 81 additions & 0 deletions source/app/dbg/cmd/apu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/******************************************************************************\
**
** This file is part of the Hades GBA Emulator, and is made available under
** the terms of the GNU General Public License version 2.
**
** Copyright (C) 2021-2024 - The Hades Authors
**
\******************************************************************************/

#include <string.h>
#include "hades.h"
#include "app/app.h"
#include "app/dbg.h"
#include "log.h"

void
debugger_cmd_apu(
struct app *app,
size_t argc,
struct arg const *argv
) {
char const * const names[] = {
"psg0",
"psg1",
"psg2",
"psg3",
"fifo1",
"fifo2",
};

bool *values[] = {
&app->config.audio.enable_psg_channels[0],
&app->config.audio.enable_psg_channels[1],
&app->config.audio.enable_psg_channels[2],
&app->config.audio.enable_psg_channels[3],
&app->config.audio.enable_fifo_channels[0],
&app->config.audio.enable_fifo_channels[1],
};

if (argc == 0) {
size_t i;

for (i = 0; i < array_length(names); ++i) {
printf("%s%s%s: %s%s%s\n",
g_light_magenta,
names[i],
g_reset,
*values[i] ? g_light_green : g_light_red,
*values[i] ? "true" : "false",
g_reset
);
}
} else if (argc == 1) {
size_t i;

if (debugger_check_arg_type(CMD_APU, &argv[0], ARGS_STRING)) {
return ;
}

for (i = 0; i < array_length(values); ++i) {
if (!strcmp(argv[0].value.s, names[i])) {
*values[i] ^= true;
printf("%s%s%s set to %s%s%s\n",
g_light_magenta,
names[i],
g_reset,
*values[i] ? g_light_green : g_light_red,
*values[i] ? "true" : "false",
g_reset
);
app_emulator_settings(app);
return ;
}
}

printf("Unknown APU settings \"%s\".", argv[0].value.s);
} else {
printf("Usage: %s\n", g_commands[CMD_APU].usage);
}
}

79 changes: 79 additions & 0 deletions source/app/dbg/cmd/ppu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/******************************************************************************\
**
** This file is part of the Hades GBA Emulator, and is made available under
** the terms of the GNU General Public License version 2.
**
** Copyright (C) 2021-2024 - The Hades Authors
**
\******************************************************************************/

#include <string.h>
#include "hades.h"
#include "app/app.h"
#include "app/dbg.h"
#include "log.h"

void
debugger_cmd_ppu(
struct app *app,
size_t argc,
struct arg const *argv
) {
char const * const names[] = {
"bg0",
"bg1",
"bg2",
"bg3",
"oam",
};

bool *values[] = {
&app->config.video.enable_bg_layers[0],
&app->config.video.enable_bg_layers[1],
&app->config.video.enable_bg_layers[2],
&app->config.video.enable_bg_layers[3],
&app->config.video.enable_oam,
};

if (argc == 0) {
size_t i;

for (i = 0; i < array_length(names); ++i) {
printf("%s%s%s: %s%s%s\n",
g_light_magenta,
names[i],
g_reset,
*values[i] ? g_light_green : g_light_red,
*values[i] ? "true" : "false",
g_reset
);
}
} else if (argc == 1) {
size_t i;

if (debugger_check_arg_type(CMD_PPU, &argv[0], ARGS_STRING)) {
return ;
}

for (i = 0; i < array_length(values); ++i) {
if (!strcmp(argv[0].value.s, names[i])) {
*values[i] ^= true;
printf("%s%s%s set to %s%s%s\n",
g_light_magenta,
names[i],
g_reset,
*values[i] ? g_light_green : g_light_red,
*values[i] ? "true" : "false",
g_reset
);
app_emulator_settings(app);
return ;
}
}

printf("Unknown PPU settings \"%s\".", argv[0].value.s);
} else {
printf("Usage: %s\n", g_commands[CMD_PPU].usage);
}
}

12 changes: 12 additions & 0 deletions source/app/dbg/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ struct command g_commands[] = {
.description = "Store a screenshot of the screen in FILE.",
.func = debugger_cmd_screenshot
},
[CMD_PPU] = {
.name = "ppu",
.usage = "ppu OPTION VALUE",
.description = "Set options for the ppu.",
.func = debugger_cmd_ppu
},
[CMD_APU] = {
.name = "apu",
.usage = "apu OPTION VALUE",
.description = "Set options for the apu.",
.func = debugger_cmd_apu
},
{
.name = NULL,
}
Expand Down

0 comments on commit 5a3045a

Please sign in to comment.