Skip to content

Commit

Permalink
Revamp the protocol between the GUI and the emulator.
Browse files Browse the repository at this point in the history
This commit also provides a new graphical pipeline with shaders for the color correction, and a lot of small improvements here and there.
  • Loading branch information
Arignir committed Dec 9, 2023
1 parent 9ae346e commit 54689d2
Show file tree
Hide file tree
Showing 57 changed files with 4,508 additions and 3,613 deletions.
91 changes: 68 additions & 23 deletions include/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define MAX_RECENT_ROMS 5
#define MAX_QUICKSAVES 5
#define POWER_SAVE_FRAME_DELAY 30
#define MAX_GFX_PROGRAMS 10

struct ImGuiIO;

Expand Down Expand Up @@ -88,11 +89,20 @@ extern char const * const binds_slug[];
struct app {
atomic_bool run;

struct args {
char const *rom_path;
char const *bios_path;
} args;

struct {
struct gba *gba;
struct launch_config *launch_config;
struct game_entry const *game_entry;

FILE *backup_file;

bool started;
bool running;
bool is_started;
bool is_running;

// Current FPS
uint32_t fps;
Expand All @@ -105,18 +115,33 @@ struct app {
bool skip_bios;

// Backup storage
enum backup_storage_types backup_type;
struct {
bool autodetect;
enum backup_storage_types type;
} backup_storage;

// RTC
bool rtc_autodetect;
bool rtc_force_enabled;
struct {
bool autodetect;
bool enabled;
} rtc;

// The current quicksave request
struct {
bool enabled;
size_t idx;
} quicksave_request;

// The current quickload request
struct {
bool enabled;
void *data;
} quickload_request;
} emulation;

struct {
SDL_Window *window;
SDL_GLContext gl_context;
SDL_AudioDeviceID audio_device;
GLuint game_texture;

/* Game controller */
struct {
Expand All @@ -132,41 +157,48 @@ struct app {
} controller;
} sdl;

struct {
SDL_GLContext gl_context;

enum texture_filter_kind texture_filter;
GLuint game_texture_in;
GLuint game_texture_out;
GLuint fbo;
GLuint vao;
GLuint vbo;

GLuint program_color_correction;

GLuint active_programs[MAX_GFX_PROGRAMS];
size_t active_programs_length;
} gfx;

struct {
char *config_path;

char *bios_path;
char *game_path;
char *recent_roms[MAX_RECENT_ROMS];

char *backup_path;
FILE *backup_file;

struct {
char *path;
char *mtime;
bool exist;
} qsaves[MAX_QUICKSAVES];

bool flush_qsaves_cache;
bool flush_qsaves_cache; // Set to true if the `mtime` and `exist` field of `qsaves` needs to be refreshed.
} file;

struct {
uint32_t display_size;
enum aspect_ratio aspect_ratio;
bool vsync;
bool color_correction;

struct {
enum texture_filter_kind kind;
bool refresh;
} texture_filter;

} video;

struct {
bool mute;
float level;
uint32_t resample_frequency;
} audio;

struct {
Expand Down Expand Up @@ -244,6 +276,9 @@ struct app {

#if WITH_DEBUGGER
struct {
bool is_running;
bool is_started;

csh handle_arm; // Capstone handle for ARM mode
csh handle_thumb; // Capstone handle for Thumb mode

Expand All @@ -260,17 +295,27 @@ struct app {
};

/* common/game.c */
void app_game_reset(struct app *app);
void app_game_process_all_notifs(struct app *app);
void app_game_configure(struct app *app, char const *rom_path);
void app_game_stop(struct app *app);
void app_game_run(struct app *app);
void app_game_pause(struct app *app);
void app_game_write_backup(struct app *app);
void app_game_reset(struct app *app);
void app_game_exit(struct app *app);
void app_game_key(struct app *app, enum keys key, bool pressed);
void app_game_speed(struct app *app, uint32_t);
void app_game_update_backup(struct app *app);
void app_game_screenshot(struct app *app);
void app_game_quicksave(struct app *, size_t);
void app_game_quickload(struct app *, size_t);
void app_game_quicksave(struct app *app, size_t idx);
void app_game_quickload(struct app *app, size_t idx);

#ifdef WITH_DEBUGGER

void app_game_frame(struct app *app);
void app_game_trace(struct app *app, size_t, void (*)(struct app *));
void app_game_step(struct app *app, bool over, size_t cnt);
void app_game_step_in(struct app *app, size_t cnt);
void app_game_step_over(struct app *app, size_t cnt);
void app_game_set_breakpoints_list(struct app *app, struct breakpoint *breakpoints, size_t len);
void app_game_set_watchpoints_list(struct app *app, struct watchpoint *watchpoints, size_t len);

#endif
44 changes: 44 additions & 0 deletions include/common/channel/channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************\
**
** 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-2023 - The Hades Authors
**
\******************************************************************************/

#pragma once

#include "hades.h"

struct event_header {
int32_t kind;
size_t size;
};

struct channel {
struct event_header *events; // An array of events.
size_t length; // The number of event in `events`
size_t size; // The sum of the size of all the events in `events`
size_t allocated_size; // The size of the allocation of `events`

pthread_mutex_t lock;
pthread_cond_t ready;
};

struct channels {
struct channel messages; // Sent by the frontned to the emulator
struct channel notifications; // Sent by the emulator to the frontend
#ifdef WITH_DEBUGGER
struct channel debug; // Sent by the emulator to the debugger
#endif
};

/* channel.c */
void channel_init(struct channel *channel);
void channel_lock(struct channel *channel);
void channel_release(struct channel *channel);
void channel_push(struct channel *channel, struct event_header const *event);
void channel_wait(struct channel *channel);
struct event_header const *channel_next(struct channel const *channel, struct event_header const *event);
void channel_clear(struct channel *channel);
153 changes: 153 additions & 0 deletions include/common/channel/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/******************************************************************************\
**
** 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-2023 - The Hades Authors
**
\******************************************************************************/

#pragma once

#include "hades.h"
#include "gba/gba.h"

/*
** Messages
*/

enum message_kind {
MESSAGE_EXIT,
MESSAGE_RESET,
MESSAGE_RUN,
MESSAGE_PAUSE,
MESSAGE_STOP,
MESSAGE_KEY,
MESSAGE_SPEED,
MESSAGE_QUICKSAVE,
MESSAGE_QUICKLOAD,

#ifdef WITH_DEBUGGER
MESSAGE_FRAME,
MESSAGE_TRACE,
MESSAGE_STEP_IN,
MESSAGE_STEP_OVER,
MESSAGE_SET_BREAKPOINTS_LIST,
MESSAGE_SET_WATCHPOINTS_LIST,
#endif

MESSAGE_MAX,
MESSAGE_MIN = 0,
MESSAGE_LEN = MESSAGE_MAX + 1,
};

struct message {
struct event_header header;
};

struct message_reset {
struct event_header header;
struct launch_config config;
};

struct message_speed {
struct event_header header;
uint32_t speed;
};

struct message_key {
struct event_header header;
enum keys key;
bool pressed;
};

struct message_quickload {
struct event_header header;
uint8_t *data;
size_t size;
};

#ifdef WITH_DEBUGGER

struct message_step {
struct event_header header;
size_t count;
};

struct message_trace {
struct event_header header;
size_t count;
void (*tracer_cb)(void *);
void *arg;
};

struct message_set_breakpoints_list {
struct event_header header;
struct breakpoint *breakpoints;
size_t len;
};

struct message_set_watchpoints_list {
struct event_header header;
struct watchpoint *watchpoints;
size_t len;
};

#endif

/*
** Notifications
*/

enum notification_kind {
NOTIFICATION_RESET,
NOTIFICATION_RUN,
NOTIFICATION_PAUSE,
NOTIFICATION_STOP,

// Only sent to the frontend
NOTIFICATION_QUICKSAVE,
NOTIFICATION_QUICKLOAD,

// Only sent to the debuger
#ifdef WITH_DEBUGGER
NOTIFICATION_BREAKPOINT,
NOTIFICATION_WATCHPOINT,
NOTIFICATION_BREAKPOINTS_LIST_SET,
NOTIFICATION_WATCHPOINTS_LIST_SET,
#endif

NOTIFICATION_MAX,
NOTIFICATION_MIN = 0,
NOTIFICATION_LEN = NOTIFICATION_MAX + 1,
};

struct notification {
struct event_header header;
};

struct notification_quicksave {
struct event_header header;
uint8_t *data;
size_t size;
};

#ifdef WITH_DEBUGGER

struct notification_breakpoint {
struct event_header header;
uint32_t addr;
};

struct notification_watchpoint {
struct event_header header;
uint32_t addr;
struct {
uint32_t addr;
uint32_t val;
uint32_t size;
bool write;
} access;
};

#endif
4 changes: 2 additions & 2 deletions include/compat.h → include/common/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ hs_usleep(

static inline
uint64_t
hs_tick_count(void)
hs_time(void)
{
FILETIME ts;
uint64_t time;
Expand Down Expand Up @@ -196,7 +196,7 @@ hs_basename(

static inline
uint64_t
hs_tick_count(void)
hs_time(void)
{
struct timespec ts;

Expand Down
Loading

0 comments on commit 54689d2

Please sign in to comment.