Skip to content

Commit

Permalink
Reorganize the repository's architecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Dec 18, 2023
1 parent 0bc7a23 commit ca29276
Show file tree
Hide file tree
Showing 73 changed files with 936 additions and 1,017 deletions.
94 changes: 73 additions & 21 deletions include/app.h → include/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "hades.h"
#include "gba/gba.h"

#define GLSL(src) "#version 330 core\n" #src

#define MAX_RECENT_ROMS 5
#define MAX_QUICKSAVES 5
#define POWER_SAVE_FRAME_DELAY 30
Expand Down Expand Up @@ -320,29 +322,79 @@ struct app {
#endif
};

/* common/game.c */
void app_game_process_all_notifs(struct app *app);
bool 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_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_screenshot_path(struct app *app, char const *);
void app_game_quicksave(struct app *app, size_t idx);
void app_game_quickload(struct app *app, size_t idx);
/* app/sdl/audio.c */
void app_sdl_audio_init(struct app *app);
void app_sdl_audio_cleanup(struct app *app);

/* app/sdl/event.c */
void app_sdl_handle_events(struct app *app);

/* app/sdl/init.c */
void app_sdl_init(struct app *app);
void app_sdl_cleanup(struct app *app);

/* app/sdl/video.c */
void app_sdl_video_init(struct app *app);
void app_sdl_video_cleanup(struct app *app);
void app_sdl_video_render_frame(struct app *app);
void app_sdl_video_rebuild_pipeline(struct app *app);

/* app/shaders/frag-color-correction.c */
extern char const *SHADER_FRAG_COLOR_CORRECTION;

/* app/shaders/frag-lcd-grid.c */
extern char const *SHADER_FRAG_LCD_GRID;

/* app/shaders/vertex-common.c */
extern char const *SHADER_VERTEX_COMMON;

/* app/windows/game.c */
void app_win_game(struct app *app);

/* app/windows/keybinds.c */
void app_win_keybinds_editor(struct app *app);

/* app/windows/menubar.c */
void app_win_menubar(struct app *app);

/* app/windows/notif.c */
void app_new_notification(struct app *app, enum ui_notification_kind, char const *msg, ...);
void app_win_notifications(struct app *app);

/* config.c */
void app_config_load(struct app *app);
void app_config_save(struct app *app);
void app_config_push_recent_rom(struct app *app, char const *path);

/* emulator.c */
void app_emulator_process_all_notifs(struct app *app);
bool app_emulator_configure(struct app *app, char const *rom_path);
void app_emulator_stop(struct app *app);
void app_emulator_run(struct app *app);
void app_emulator_pause(struct app *app);
void app_emulator_reset(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, uint32_t);
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 *);
void app_emulator_quicksave(struct app *app, size_t idx);
void app_emulator_quickload(struct app *app, size_t idx);

#ifdef WITH_DEBUGGER

void app_game_frame(struct app *app, size_t);
void app_game_trace(struct app *app, size_t, void (*)(struct app *));
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);
void app_emulator_frame(struct app *app, size_t);
void app_emulator_trace(struct app *app, size_t, void (*)(struct app *));
void app_emulator_step_in(struct app *app, size_t cnt);
void app_emulator_step_over(struct app *app, size_t cnt);
void app_emulator_set_breakpoints_list(struct app *app, struct breakpoint *breakpoints, size_t len);
void app_emulator_set_watchpoints_list(struct app *app, struct watchpoint *watchpoints, size_t len);

#endif

/* bindings.c */
void app_bindings_setup_default(struct app *app);
void app_bindings_keyboard_clear(struct app *app, SDL_KeyCode key);
void app_bindings_controller_clear(struct app *app, SDL_GameControllerButton btn);
void app_bindings_handle(struct app *app, enum bind_actions bind, bool pressed);
40 changes: 20 additions & 20 deletions include/dbg/dbg.h → include/app/dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <stdbool.h>
#include "hades.h"
#include "common/channel/event.h"
#include "gba/event.h"
#include "gba/gba.h"

struct app;
Expand Down Expand Up @@ -168,76 +168,76 @@ extern struct command g_commands[];
extern struct io_register g_io_registers[];
extern size_t g_io_registers_len;

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

/* dbg/cmd/context.c */
/* app/dbg/cmd/context.c */
void debugger_dump_context(struct app *);
void debugger_dump_context_auto(struct app *);
void debugger_dump_context_compact(struct app *);
void debugger_dump_context_compact_header(void);
void debugger_cmd_context(struct app *, size_t, struct arg const *);
void debugger_cmd_context_compact(struct app *, size_t, struct arg const *);

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

/* dbg/cmd/disas.c */
/* app/dbg/cmd/disas.c */
void debugger_cmd_disas(struct app *, size_t, struct arg const *);
void debugger_cmd_disas_at(struct app *app, uint32_t ptr, bool);

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

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

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

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

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

/* dbg/cmd/print.c */
/* 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);
void debugger_cmd_print_u16(struct app const *, uint32_t, size_t, size_t);
void debugger_cmd_print_u32(struct app const *, uint32_t, size_t, size_t);

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

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

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

/* dbg/cmd/step.c */
/* app/dbg/cmd/step.c */
void debugger_cmd_step_in(struct app *, size_t, struct arg const *);
void debugger_cmd_step_over(struct app *, size_t, struct arg const *);

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

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

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

/* dbg/debugger.c */
/* app/dbg/debugger.c */
void debugger_run(struct app *app);
void debugger_reset_terminal(void);
bool debugger_check_arg_type(enum commands_list command, struct arg const *arg, enum args_type expected);
void debugger_process_all_notifs(struct app *);
void debugger_wait_for_emulator(struct app *);
void debugger_wait_for_notif(struct app *, enum notification_kind kind);

/* dbg/io.c */
/* app/dbg/io.c */
void debugger_io_init(struct gba *);
struct io_register *debugger_io_lookup_reg(uint32_t address);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
182 changes: 182 additions & 0 deletions include/gba/core/helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/******************************************************************************\
**
** 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"

/*
** Sign-extend a 8-bits value to a signed 32-bit value.
*/
static inline
int32_t
sign_extend8(
uint32_t value
) {
if ((value & 0x80) != 0) {
return ((int32_t)(value | 0xFFFFFF00));
} else {
return ((int32_t)value);
}
}

/*
** Sign-extend a 9-bits value to a signed 32-bit value.
*/
static inline
int32_t
sign_extend9(
uint32_t value
) {
if ((value & 0x100) != 0) {
return ((int32_t)(value | 0xFFFFFF00));
} else {
return ((int32_t)value);
}
}

/*
** Sign-extend a 11-bits value to a signed 32-bit value.
*/
static inline
int32_t
sign_extend11(
uint32_t value
) {
if ((value & 0x400) != 0) {
return ((int32_t)(value | 0xFFFFF800));
} else {
return ((int32_t)value);
}
}

/*
** Sign-extend a 12-bits value to a signed 32-bit value.
*/
static inline
int32_t
sign_extend12(
uint32_t value
) {
if ((value & 0x800) != 0) {
return ((int32_t)(value | 0xFFFFF000));
} else {
return ((int32_t)value);
}
}

/*
** Sign-extend a 24-bits value to a signed 32-bit value.
*/
static inline
int32_t
sign_extend24(
uint32_t value
) {
if ((value & 0x800000) != 0) {
return ((int32_t)(value | 0xFF000000));
} else {
return ((int32_t)value);
}
}

/*
** Sign-extend a 28-bits value to a signed 32-bit value.
*/
static inline
int32_t
sign_extend28(
uint32_t value
) {
if ((value & 0x08000000) != 0) {
return ((int32_t)(value | 0xF0000000));
} else {
return ((int32_t)value);
}
}

/*
** Return the value of the carry bit when performing `a + b + c`.
*/
static inline
bool
uadd32(
uint32_t a,
uint32_t b,
uint32_t c
) {
uint64_t r;

r = (uint64_t)a + (uint64_t)b + (uint64_t)c;
return (r > UINT32_MAX);
}

/*
** Return the value of the overflow bit when performing `a + b + c`.
*/
static inline
bool
iadd32(
int32_t a,
int32_t b,
int32_t c
) {
int64_t r;

r = (int64_t)a + (int64_t)b + (int64_t)c;
return ((r < INT32_MIN) | (r > INT32_MAX));
}

/*
** Return the value of the borrow bit when performing `a - b - c`.
*/
static inline
bool
usub32(
uint32_t a,
uint32_t b,
uint32_t c
) {
uint64_t r;

r = (uint64_t)a - (uint64_t)b -(uint64_t)c;
return (r <= UINT32_MAX);
}

/*
** Return the value of the overflow bit when performing `a - b - c`.
*/
static inline
bool
isub32(
int32_t a,
int32_t b,
int32_t c
) {
int64_t r;

r = (int64_t)a - (int64_t)b - (int64_t)c;
return ((r < INT32_MIN) | (r > INT32_MAX));
}

/*
** Return the value of value after being wrapped by `shift` amount.
*/
static inline
uint32_t
ror32(
uint32_t value,
uint32_t shift
) {
if (shift) {
return ((value >> shift) | (value << (32 - shift)));
} else {
return (value);
}
}
File renamed without changes.
Loading

0 comments on commit ca29276

Please sign in to comment.