SGB revision selection in the SDL port

This commit is contained in:
Lior Halphon 2019-05-18 20:37:41 +03:00
parent 3e724afb0a
commit e12e03d9c2
3 changed files with 55 additions and 11 deletions

View File

@ -307,6 +307,31 @@ const char *current_model_string(unsigned index)
[configuration.model]; [configuration.model];
} }
static void cycle_sgb_revision(unsigned index)
{
configuration.sgb_revision++;
if (configuration.sgb_revision == SGB_MAX) {
configuration.sgb_revision = 0;
}
pending_command = GB_SDL_RESET_COMMAND;
}
static void cycle_sgb_revision_backwards(unsigned index)
{
if (configuration.sgb_revision == 0) {
configuration.sgb_revision = SGB_MAX;
}
configuration.sgb_revision--;
pending_command = GB_SDL_RESET_COMMAND;
}
const char *current_sgb_revision_string(unsigned index)
{
return (const char *[]){"Super Game Boy NTSC", "Super Game Boy PAL", "Super Game Boy 2"}
[configuration.sgb_revision];
}
static const uint32_t rewind_lengths[] = {0, 10, 30, 60, 60 * 2, 60 * 5, 60 * 10}; static const uint32_t rewind_lengths[] = {0, 10, 30, 60, 60 * 2, 60 * 5, 60 * 10};
static const char *rewind_strings[] = {"Disabled", static const char *rewind_strings[] = {"Disabled",
"10 Seconds", "10 Seconds",
@ -355,6 +380,7 @@ const char *current_rewind_string(unsigned index)
static const struct menu_item emulation_menu[] = { static const struct menu_item emulation_menu[] = {
{"Emulated Model:", cycle_model, current_model_string, cycle_model_backwards}, {"Emulated Model:", cycle_model, current_model_string, cycle_model_backwards},
{"SGB Revision:", cycle_sgb_revision, current_sgb_revision_string, cycle_sgb_revision_backwards},
{"Rewind Length:", cycle_rewind, current_rewind_string, cycle_rewind_backwards}, {"Rewind Length:", cycle_rewind, current_rewind_string, cycle_rewind_backwards},
{"Back", return_to_root_menu}, {"Back", return_to_root_menu},
{NULL,} {NULL,}

View File

@ -86,6 +86,14 @@ typedef struct {
SDL_Scancode keys_2[32]; /* Rewind and underclock, + padding for the future */ SDL_Scancode keys_2[32]; /* Rewind and underclock, + padding for the future */
uint8_t joypad_configuration[32]; /* 12 Keys + padding for the future*/; uint8_t joypad_configuration[32]; /* 12 Keys + padding for the future*/;
uint8_t joypad_axises[JOYPAD_AXISES_MAX]; uint8_t joypad_axises[JOYPAD_AXISES_MAX];
/* v0.12 */
enum {
SGB_NTSC,
SGB_PAL,
SGB_2,
SGB_MAX
} sgb_revision;
} configuration_t; } configuration_t;
extern configuration_t configuration; extern configuration_t configuration;

View File

@ -35,14 +35,6 @@ static char *battery_save_path_ptr;
SDL_AudioDeviceID device_id; SDL_AudioDeviceID device_id;
static const GB_model_t sdl_to_internal_model[] =
{
[MODEL_DMG] = GB_MODEL_DMG_B,
[MODEL_CGB] = GB_MODEL_CGB_E,
[MODEL_AGB] = GB_MODEL_AGB,
[MODEL_SGB] = GB_MODEL_SGB,
};
void set_filename(const char *new_filename, bool new_should_free) void set_filename(const char *new_filename, bool new_should_free)
{ {
if (filename && should_free_filename) { if (filename && should_free_filename) {
@ -407,13 +399,27 @@ static bool handle_pending_command(void)
static void run(void) static void run(void)
{ {
GB_model_t model;
pending_command = GB_SDL_NO_COMMAND; pending_command = GB_SDL_NO_COMMAND;
restart: restart:
model = (GB_model_t [])
{
[MODEL_DMG] = GB_MODEL_DMG_B,
[MODEL_CGB] = GB_MODEL_CGB_E,
[MODEL_AGB] = GB_MODEL_AGB,
[MODEL_SGB] = (GB_model_t [])
{
[SGB_NTSC] = GB_MODEL_SGB_NTSC,
[SGB_PAL] = GB_MODEL_SGB_PAL,
[SGB_2] = GB_MODEL_SGB2,
}[configuration.sgb_revision],
}[configuration.model];
if (GB_is_inited(&gb)) { if (GB_is_inited(&gb)) {
GB_switch_model_and_reset(&gb, sdl_to_internal_model[configuration.model]); GB_switch_model_and_reset(&gb, model);
} }
else { else {
GB_init(&gb, sdl_to_internal_model[configuration.model]); GB_init(&gb, model);
GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank); GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank);
GB_set_pixels_output(&gb, active_pixel_buffer); GB_set_pixels_output(&gb, active_pixel_buffer);
@ -434,7 +440,11 @@ restart:
bool error = false; bool error = false;
start_capturing_logs(); start_capturing_logs();
const char * const boot_roms[] = {"dmg_boot.bin", "cgb_boot.bin", "agb_boot.bin", "sgb_boot.bin"}; const char * const boot_roms[] = {"dmg_boot.bin", "cgb_boot.bin", "agb_boot.bin", "sgb_boot.bin"};
error = GB_load_boot_rom(&gb, resource_path(boot_roms[configuration.model])); const char *boot_rom = boot_roms[configuration.model];
if (configuration.model == GB_MODEL_SGB && configuration.sgb_revision == SGB_2) {
boot_rom = "sgb2_boot.bin";
}
error = GB_load_boot_rom(&gb, resource_path(boot_rom));
end_capturing_logs(true, error); end_capturing_logs(true, error);
start_capturing_logs(); start_capturing_logs();