Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/genesis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ idf_component_register(
# target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-char-subscripts -Wno-attributes -Wno-implicit-fallthrough -Wno-unused-function -Wno-unused-variable -Wno-discarded-qualifiers)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-const-variable -Wno-unused-value -Ofast)
# target_compile_definitions(${COMPONENT_LIB} PRIVATE GWENESIS_AUDIO_ACCURATE=0 BUILD_TABLES=0 TABLES_FULL=0)
target_compile_definitions(${COMPONENT_LIB} PRIVATE GWENESIS_AUDIO_ACCURATE=0)
# M68K_OVERCLOCK_SHIFT: the 68000 clock setting (genesis_set_cpu_percent());
# M68K_IDLE_SKIP: skip the 68000's wait-for-frame loops (see m68k_run())
target_compile_definitions(${COMPONENT_LIB} PRIVATE GWENESIS_AUDIO_ACCURATE=0 M68K_OVERCLOCK_SHIFT=8 M68K_IDLE_SKIP)
6 changes: 6 additions & 0 deletions components/gui/include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Gui {

void set_resume_last_save(bool on);

/// Genesis 68000 clock, % of stock (100 or 125)
void set_genesis_cpu_percent(int percent);

void clear_rom_list();

void add_rom(const RomInfo& rom);
Expand Down Expand Up @@ -168,6 +171,7 @@ class Gui {
set_brightness(box.brightness());
set_video_setting(BoxEmu::get().video_setting());
set_resume_last_save(AppSettings::get().get_settings().resume_last_save);
set_genesis_cpu_percent(AppSettings::get().get_settings().genesis_cpu_percent);
}

VideoSetting get_video_setting();
Expand Down Expand Up @@ -266,6 +270,8 @@ class Gui {

lv_obj_t *resume_button_{nullptr};
lv_obj_t *resume_label_{nullptr};
lv_obj_t *genesis_cpu_button_{nullptr};
lv_obj_t *genesis_cpu_label_{nullptr};

// style for buttons
lv_style_t button_style_;
Expand Down
42 changes: 42 additions & 0 deletions components/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ void Gui::set_video_setting(VideoSetting setting) {
AppSettings::get().modify([setting](Settings &s) { s.video_setting = static_cast<uint8_t>(setting); });
}

void Gui::set_genesis_cpu_percent(int percent) {
const uint8_t choice = Settings::genesis_cpu_choice(percent);
AppSettings::get().modify([choice](Settings &s) { s.genesis_cpu_percent = choice; });
if (genesis_cpu_label_) {
lv_label_set_text(genesis_cpu_label_, choice > 100 ? "125%" : "Normal");
}
}

void Gui::set_resume_last_save(bool on) {
AppSettings::get().modify([on](Settings &s) { s.resume_last_save = on; });
if (resume_label_) {
Expand Down Expand Up @@ -323,6 +331,33 @@ void Gui::init_ui() {
lv_obj_add_event_cb(resume_button_, &Gui::event_callback, LV_EVENT_KEY, static_cast<void*>(this));
}

// settings: the Genesis 68000 clock (125% removes most in-game slowdown,
// e.g. Sonic losing rings, at the cost of fewer frames drawn)
{
auto *panel = lv_obj_create(ui_settingspanel);
lv_obj_set_height(panel, 50);
lv_obj_set_width(panel, lv_pct(100));
lv_obj_set_y(panel, 350);
lv_obj_set_align(panel, LV_ALIGN_TOP_MID);
lv_obj_remove_flag(panel, LV_OBJ_FLAG_SCROLLABLE);
auto *label = lv_label_create(panel);
lv_obj_set_align(label, LV_ALIGN_LEFT_MID);
lv_label_set_text(label, "Genesis CPU");
genesis_cpu_button_ = lv_button_create(panel);
lv_obj_set_height(genesis_cpu_button_, 32);
lv_obj_set_width(genesis_cpu_button_, LV_SIZE_CONTENT);
lv_obj_set_align(genesis_cpu_button_, LV_ALIGN_RIGHT_MID);
lv_obj_add_flag(genesis_cpu_button_, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_remove_flag(genesis_cpu_button_, LV_OBJ_FLAG_SCROLLABLE);
genesis_cpu_label_ = lv_label_create(genesis_cpu_button_);
lv_obj_set_align(genesis_cpu_label_, LV_ALIGN_CENTER);
lv_label_set_text(genesis_cpu_label_,
Settings::genesis_cpu_choice(AppSettings::get().get_settings().genesis_cpu_percent) > 100
? "125%" : "Normal");
lv_obj_add_event_cb(genesis_cpu_button_, &Gui::event_callback, LV_EVENT_PRESSED, static_cast<void*>(this));
lv_obj_add_event_cb(genesis_cpu_button_, &Gui::event_callback, LV_EVENT_KEY, static_cast<void*>(this));
}

// now do the same events for all the same buttons but for the LV_EVENT_KEY
lv_obj_add_event_cb(ui_settingsbutton, &Gui::event_callback, LV_EVENT_KEY, static_cast<void*>(this));
lv_obj_add_event_cb(ui_playbutton, &Gui::event_callback, LV_EVENT_KEY, static_cast<void*>(this));
Expand Down Expand Up @@ -354,6 +389,7 @@ void Gui::init_ui() {
lv_group_add_obj(settings_screen_group_, ui_hapticplaybutton);
lv_group_add_obj(settings_screen_group_, ui_usb_button);
lv_group_add_obj(settings_screen_group_, resume_button_);
lv_group_add_obj(settings_screen_group_, genesis_cpu_button_);

// set the focused style for all the buttons to have a red border
lv_style_init(&button_style_);
Expand All @@ -374,6 +410,7 @@ void Gui::init_ui() {
lv_obj_add_style(ui_videosettingdropdown, &button_style_, LV_STATE_FOCUSED);
lv_obj_add_style(ui_usb_button, &button_style_, LV_STATE_FOCUSED);
lv_obj_add_style(resume_button_, &button_style_, LV_STATE_FOCUSED);
lv_obj_add_style(genesis_cpu_button_, &button_style_, LV_STATE_FOCUSED);

update_rom_list();

Expand Down Expand Up @@ -492,6 +529,11 @@ void Gui::on_pressed(lv_event_t *e) {
set_resume_last_save(!AppSettings::get().get_settings().resume_last_save);
return;
}
if (genesis_cpu_button_ && target == genesis_cpu_button_) {
set_genesis_cpu_percent(Settings::genesis_cpu_choice(AppSettings::get().get_settings().genesis_cpu_percent) > 100
? 100 : 125);
return;
}
}

void Gui::on_volume(const std::vector<uint8_t>& data) {
Expand Down
33 changes: 31 additions & 2 deletions components/settings/include/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,37 @@ struct SettingsV1 {
uint8_t haptic_waveform{12}; ///< DRV2605 effect played when a game starts
};

/// Version 2: adds the Genesis 68000 clock.
struct SettingsV2 {
static constexpr uint32_t VERSION = 2;
uint8_t volume{60}; ///< 0..100
bool muted{false};
uint8_t brightness{80}; ///< 0..100
uint8_t video_setting{1}; ///< VideoSetting (0 original, 1 fit, 2 fill)
bool resume_last_save{true}; ///< starting a game loads the slot it was last saved to / loaded from
std::string last_rom; ///< rom_path of the last game started (selected again at boot)
std::map<std::string, uint8_t> last_slot; ///< rom_path -> the save slot last saved to / loaded from
uint8_t haptic_waveform{12}; ///< DRV2605 effect played when a game starts
uint8_t genesis_cpu_percent{100}; ///< Genesis 68000 clock, % of stock (125 removes most in-game lag)

/// The supported Genesis clocks are Normal (100) and 125%; a stored value is
/// read through this so anything else (an older or hand-edited file) maps to one
static constexpr uint8_t genesis_cpu_choice(int percent) { return percent > 100 ? 125 : 100; }

static SettingsV2 migrate(const SettingsV1 &v1) {
return {.volume = v1.volume,
.muted = v1.muted,
.brightness = v1.brightness,
.video_setting = v1.video_setting,
.resume_last_save = v1.resume_last_save,
.last_rom = v1.last_rom,
.last_slot = v1.last_slot,
.haptic_waveform = v1.haptic_waveform};
}
};

/// The current settings version.
using Settings = SettingsV1;
using Settings = SettingsV2;

/// The settings file and an in-RAM copy of it. Changes are made in RAM
/// (modify()) and written when save() is called; the launcher calls save()
Expand Down Expand Up @@ -81,7 +110,7 @@ class AppSettings {
AppSettings() = default;
static bool same(const Settings &a, const Settings &b);

using Store = espp::PersistentData<Settings>;
using Store = espp::PersistentData<SettingsV2, SettingsV1>;
mutable std::mutex mutex_;
std::unique_ptr<Store> data_;
Settings fallback_{}; ///< used when init() was not called (no SD card)
Expand Down
4 changes: 2 additions & 2 deletions components/settings/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

bool AppSettings::same(const Settings &a, const Settings &b) {
return std::tie(a.volume, a.muted, a.brightness, a.video_setting, a.resume_last_save, a.last_rom, a.last_slot,
a.haptic_waveform) ==
a.haptic_waveform, a.genesis_cpu_percent) ==
std::tie(b.volume, b.muted, b.brightness, b.video_setting, b.resume_last_save, b.last_rom, b.last_slot,
b.haptic_waveform);
b.haptic_waveform, b.genesis_cpu_percent);
}

bool AppSettings::init(const std::string &file_path, const Settings &defaults) {
Expand Down
1 change: 1 addition & 0 deletions main/genesis_cart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class GenesisCart : public Cart {
case Emulator::SEGA_GENESIS:
case Emulator::SEGA_MEGA_DRIVE:
logger_.info("genesis::init()");
genesis_set_cpu_percent(Settings::genesis_cpu_choice(AppSettings::get().get_settings().genesis_cpu_percent));
init_genesis(romdata_, rom_size_bytes_);
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ extern "C" void app_main(void) {
emu.mute(s.muted);
emu.brightness(std::max<int>(10, s.brightness));
emu.video_setting(static_cast<VideoSetting>(std::min<int>(s.video_setting, 2)));
logger.info("settings: volume {}{}, brightness {}, video {}, resume {}, haptic {}, last game '{}'", s.volume,
s.muted ? " (muted)" : "", s.brightness, s.video_setting, s.resume_last_save, s.haptic_waveform,
s.last_rom);
logger.info("settings: volume {}{}, brightness {}, video {}, resume {}, haptic {}, genesis cpu {}%, last game '{}'",
s.volume, s.muted ? " (muted)" : "", s.brightness, s.video_setting, s.resume_last_save,
s.haptic_waveform, s.genesis_cpu_percent, s.last_rom);
Comment on lines +116 to +117

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change here: fmt formats unsigned char / signed char (so uint8_t) as integers; only plain char is formatted as a character. The values print as numbers.

}

logger.info("initializing gui...");
Expand Down
Loading