Skip to content

Commit

Permalink
Misc updates and fixes
Browse files Browse the repository at this point in the history
* Imagine: Add IOAccessHint into OpenFlags to simplify constructors for IO classes
* Imagine: Fix issues handling the elapsed time in PausableTimer::pause()
* C64.emu: Rename "Joystick Mode" option to clarify which port the P1 joystick is mapped to
* C64.emu: Add option to set the default main joystick mode
* C64.emu: Rename "Autostart Basic Load" option to "Load To BASIC Start (Disk)" for consistency with VICE
* C64.emu: Properly test the default value of AutostartBasicLoad since it varies based on core
  • Loading branch information
Robert Broglia committed Mar 10, 2024
1 parent 79f9a83 commit e98e388
Show file tree
Hide file tree
Showing 38 changed files with 180 additions and 130 deletions.
2 changes: 1 addition & 1 deletion 2600.emu/src/stella/emucore/Serializer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Serializer::Serializer(const string& filename, Mode m)
FilesystemNode node(filename);
if(node.isFile() && node.isReadable())
{
auto str = make_unique<IG::FStream>(EmuEx::gAppContext().openFileUri(filename, IG::IOAccessHint::All), ios::in | ios::binary);
auto str = make_unique<IG::FStream>(EmuEx::gAppContext().openFileUri(filename), ios::in | ios::binary);
if(str && str->is_open())
{
myStream = std::move(str);
Expand Down
45 changes: 35 additions & 10 deletions C64.emu/src/main/EmuMenuViews.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ class CustomSystemOptionView : public SystemOptionView, public MainAppHelper<Cus
}
};

TextMenuItem joystickModeItems[3]
{
{toString(JoystickMode::Port1), attachParams(), {.id = JoystickMode::Port1}},
{toString(JoystickMode::Port2), attachParams(), {.id = JoystickMode::Port2}},
{toString(JoystickMode::Keyboard), attachParams(), {.id = JoystickMode::Keyboard}},
};

MultiChoiceMenuItem joystickMode
{
"Default Main Joystick Mode", attachParams(),
MenuId{system().defaultJoystickMode},
joystickModeItems,
{
.defaultItemOnSelect = [this](MenuItem &item)
{
system().defaultJoystickMode = JoystickMode(item.id.val);
}
}
};

public:
CustomSystemOptionView(ViewAttachParams attach):
SystemOptionView{attach, true},
Expand All @@ -320,6 +340,7 @@ class CustomSystemOptionView : public SystemOptionView, public MainAppHelper<Cus
loadStockItems();
item.emplace_back(&defaultModel);
item.emplace_back(&defaultTrueDriveEmu);
item.emplace_back(&joystickMode);
}
};

Expand Down Expand Up @@ -956,12 +977,12 @@ class MachineOptionView : public TableView, public MainAppHelper<MachineOptionVi

BoolMenuItem autostartBasicLoad
{
"Autostart Basic Load (Omit ',1')", attachParams(),
system().autostartBasicLoad(),
"Load To BASIC Start (Disk)", attachParams(),
bool(system().intResource("AutostartBasicLoad")),
[this](BoolMenuItem &item, View &, Input::Event e)
{
system().sessionOptionSet();
system().setAutostartBasicLoad(item.flipBoolValue(*this));
system().setIntResource("AutostartBasicLoad", item.flipBoolValue(*this));
}
};

Expand Down Expand Up @@ -1170,23 +1191,26 @@ class CustomSystemActionsView : public SystemActionsView, public MainAppHelper<C
}
};

TextMenuItem joystickModeItems[3]
TextMenuItem joystickModeItems[4]
{
{"Normal", attachParams(), {.id = JoystickMode::NORMAL}},
{"Swapped", attachParams(), {.id = JoystickMode::SWAPPED}},
{"Keyboard Cursor", attachParams(), {.id = JoystickMode::KEYBOARD}},
{toString(JoystickMode::Auto), attachParams(), {.id = JoystickMode::Auto}},
{toString(JoystickMode::Port1), attachParams(), {.id = JoystickMode::Port1}},
{toString(JoystickMode::Port2), attachParams(), {.id = JoystickMode::Port2}},
{toString(JoystickMode::Keyboard), attachParams(), {.id = JoystickMode::Keyboard}},
};

MultiChoiceMenuItem joystickMode
{
"Joystick Mode", attachParams(),
MenuId{system().optionSwapJoystickPorts},
"Main Joystick Mode", attachParams(),
MenuId{system().effectiveJoystickMode},
joystickModeItems,
{
.defaultItemOnSelect = [this](MenuItem &item)
.defaultItemOnSelect = [this](MenuItem &item, View &view, const Input::Event &)
{
system().sessionOptionSet();
system().setJoystickMode(JoystickMode(item.id.val));
view.dismiss();
return false; // active item is set in onShow()
}
}
};
Expand Down Expand Up @@ -1236,6 +1260,7 @@ class CustomSystemActionsView : public SystemActionsView, public MainAppHelper<C
c64IOControl.setActive(system().hasContent());
options.setActive(system().hasContent());
warpMode.setBoolValue(*system().plugin.warp_mode_enabled, *this);
joystickMode.setSelected(MenuId{system().effectiveJoystickMode}, *this);
}
};

Expand Down
53 changes: 41 additions & 12 deletions C64.emu/src/main/MainSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <imagine/fs/FS.hh>
#include <imagine/fs/ArchiveFS.hh>
#include <emuframework/EmuSystem.hh>
#include <emuframework/EmuOptions.hh>
#include <vector>
#include <string>
#include <string_view>
Expand All @@ -37,13 +38,44 @@ extern "C"
namespace EmuEx
{

enum JoystickMode : uint8_t
{
Auto, Port1, Port2, Keyboard
};

constexpr auto toString(JoystickMode v)
{
using enum JoystickMode;
switch(v)
{
case Auto: return "Auto";
case Port1: return "Port 1";
case Port2: return "Port 2";
case Keyboard: return "Keyboard Cursor";
}
}

}


namespace IG
{

template<>
constexpr bool isValidProperty(const EmuEx::JoystickMode &v) { return v <= EmuEx::JoystickMode::Keyboard; }

}

namespace EmuEx
{

class EmuAudio;

enum
{
CFGKEY_DRIVE_TRUE_EMULATION = 256, CFGKEY_AUTOSTART_WARP = 257,
CFGKEY_AUTOSTART_TDE = 258, CFGKEY_C64_MODEL = 259,
CFGKEY_BORDER_MODE = 260, CFGKEY_SWAP_JOYSTICK_PORTS = 261,
CFGKEY_BORDER_MODE = 260, CFGKEY_JOYSTICK_MODE = 261,
CFGKEY_SID_ENGINE = 262, CFGKEY_CROP_NORMAL_BORDERS = 263,
CFGKEY_SYSTEM_FILE_PATH = 264, CFGKEY_DTV_MODEL = 265,
CFGKEY_C128_MODEL = 266, CFGKEY_SUPER_CPU_MODEL = 267,
Expand All @@ -59,7 +91,8 @@ enum
CFGKEY_DRIVE10_TYPE = 286, CFGKEY_DRIVE11_TYPE = 287,
CFGKEY_DEFAULT_DRIVE_TRUE_EMULATION = 288, CFGKEY_COLOR_SATURATION = 289,
CFGKEY_COLOR_CONTRAST = 290, CFGKEY_COLOR_BRIGHTNESS = 291,
CFGKEY_COLOR_GAMMA = 292, CFGKEY_COLOR_TINT = 293
CFGKEY_COLOR_GAMMA = 292, CFGKEY_COLOR_TINT = 293,
CFGKEY_DEFAULT_JOYSTICK_MODE = 294
};

enum Vic20Ram : uint8_t
Expand All @@ -71,13 +104,6 @@ enum Vic20Ram : uint8_t
BLOCK_5 = 1 << 5
};

enum JoystickMode : uint8_t
{
NORMAL = 0,
SWAPPED = 1,
KEYBOARD = 2,
};

enum class ColorSetting
{
Saturation, Contrast, Brightness, Gamma, Tint
Expand Down Expand Up @@ -108,7 +134,11 @@ public:
ViceSystem currSystem{};
bool viceThreadSignaled{};
bool inCPUTrap{};
JoystickMode optionSwapJoystickPorts{JoystickMode::NORMAL};
Property<JoystickMode, CFGKEY_DEFAULT_JOYSTICK_MODE,
PropertyDesc<JoystickMode>{.defaultValue = JoystickMode::Port2}> defaultJoystickMode;
Property<JoystickMode, CFGKEY_JOYSTICK_MODE,
PropertyDesc<JoystickMode>{.defaultValue = JoystickMode::Auto}> joystickMode;
JoystickMode effectiveJoystickMode{};
bool ctrlLock{};
bool c64IsInit{}, c64FailedInit{};
std::array <FS::PathString, Config::envIsLinux ? 3 : 1> sysFilePath{};
Expand Down Expand Up @@ -149,8 +179,6 @@ public:
bool autostartWarp() const;
void setAutostartTDE(bool on);
bool autostartTDE() const;
void setAutostartBasicLoad(bool on);
bool autostartBasicLoad() const;
void setModel(int model);
int model() const;
void setDriveType(int idx, int type);
Expand Down Expand Up @@ -215,6 +243,7 @@ public:
// optional API functions
FS::FileString configName() const;
void onOptionsLoaded();
void onSessionOptionsLoaded(EmuApp &);
bool resetSessionOptions(EmuApp &);
VController::KbMap vControllerKeyboardMap(VControllerKbMode mode);
void onVKeyboardShown(VControllerKeyboard &, bool shown);
Expand Down
18 changes: 10 additions & 8 deletions C64.emu/src/main/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ void C64System::handleInputAction(EmuApp *app, InputAction a)
{
case C64Key::Up ... C64Key::JSTrigger:
{
if(optionSwapJoystickPorts == JoystickMode::KEYBOARD)
if(effectiveJoystickMode == JoystickMode::Keyboard)
{
if(key == C64Key::Right)
handleKeyboardInput({KeyCode(C64Key::KeyboardRight), {}, a.state, a.metaState}, positionalShift);
Expand All @@ -639,7 +639,7 @@ void C64System::handleInputAction(EmuApp *app, InputAction a)
{
auto &joystick_value = *plugin.joystick_value;
auto player = a.flags.deviceId;
if(optionSwapJoystickPorts == JoystickMode::SWAPPED)
if(effectiveJoystickMode == JoystickMode::Port2)
{
player = (player == 1) ? 0 : 1;
}
Expand All @@ -666,13 +666,14 @@ void C64System::handleInputAction(EmuApp *app, InputAction a)
}
case C64Key::SwapJSPorts:
{
if(a.isPushed() && optionSwapJoystickPorts != JoystickMode::KEYBOARD)
if(a.isPushed() && effectiveJoystickMode != JoystickMode::Keyboard)
{
EmuSystem::sessionOptionSet();
if(optionSwapJoystickPorts == JoystickMode::SWAPPED)
optionSwapJoystickPorts = JoystickMode::NORMAL;
if(effectiveJoystickMode == JoystickMode::Port2)
joystickMode = JoystickMode::Port1;
else
optionSwapJoystickPorts = JoystickMode::SWAPPED;
joystickMode = JoystickMode::Port2;
effectiveJoystickMode = joystickMode;
IG::fill(*plugin.joystick_value);
if(app)
app->postMessage(1, false, "Swapped Joystick Ports");
Expand Down Expand Up @@ -749,14 +750,15 @@ void C64System::onVKeyboardShown(VControllerKeyboard &kb, bool shown)

void C64System::setJoystickMode(JoystickMode mode)
{
optionSwapJoystickPorts = mode;
joystickMode = mode;
effectiveJoystickMode = mode == JoystickMode::Auto ? defaultJoystickMode : mode;
updateJoystickDevices();
}

void C64System::updateJoystickDevices()
{
enterCPUTrap();
if(optionSwapJoystickPorts == JoystickMode::KEYBOARD)
if(effectiveJoystickMode == JoystickMode::Keyboard)
{
setIntResource("JoyPort1Device", JOYPORT_ID_NONE);
setIntResource("JoyPort2Device", JOYPORT_ID_NONE);
Expand Down
19 changes: 13 additions & 6 deletions C64.emu/src/main/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,20 @@ void C64System::onOptionsLoaded()
setReSidSampling(defaultReSidSampling);
}

void C64System::onSessionOptionsLoaded(EmuApp &)
{
setJoystickMode(joystickMode);
}

bool C64System::resetSessionOptions(EmuApp &)
{
initC64(EmuApp::get(appContext()));
enterCPUTrap();
setModel(defaultModel);
setJoystickMode(JoystickMode::NORMAL);
setJoystickMode(JoystickMode::Auto);
setAutostartWarp(true);
setAutostartTDE(false);
setAutostartBasicLoad(false);
resetIntResource("AutostartBasicLoad");
optionAutostartOnLaunch = true;
if(currSystem == ViceSystem::VIC20)
{
Expand Down Expand Up @@ -176,6 +181,7 @@ bool C64System::readConfig(ConfigType type, MapIO &io, unsigned key)
case CFGKEY_COLOR_BRIGHTNESS: return readOptionValue<int16_t>(io, [&](auto v){ setColorSetting(ColorSetting::Brightness, v); });
case CFGKEY_COLOR_GAMMA: return readOptionValue<int16_t>(io, [&](auto v){ setColorSetting(ColorSetting::Gamma, v); });
case CFGKEY_COLOR_TINT: return readOptionValue<int16_t>(io, [&](auto v){ setColorSetting(ColorSetting::Tint, v); });
case CFGKEY_DEFAULT_JOYSTICK_MODE: return readOptionValue(io, defaultJoystickMode);
}
}
else if(type == ConfigType::SESSION)
Expand All @@ -187,8 +193,8 @@ bool C64System::readConfig(ConfigType type, MapIO &io, unsigned key)
case CFGKEY_DRIVE_TRUE_EMULATION: return readOptionValue<bool>(io, [&](auto v){ setDriveTrueEmulation(v); });
case CFGKEY_AUTOSTART_WARP: return readOptionValue<bool>(io, [&](auto v){ setAutostartWarp(v); });
case CFGKEY_AUTOSTART_TDE: return readOptionValue<bool>(io, [&](auto v){ setAutostartTDE(v); });
case CFGKEY_AUTOSTART_BASIC_LOAD: return readOptionValue<bool>(io, [&](auto v){ setAutostartBasicLoad(v); });
case CFGKEY_SWAP_JOYSTICK_PORTS: return readOptionValue<JoystickMode>(io, [&](auto v){ if(v <= JoystickMode::KEYBOARD) setJoystickMode(v); });
case CFGKEY_AUTOSTART_BASIC_LOAD: return readOptionValue<bool>(io, [&](auto v){ setIntResource("AutostartBasicLoad", v); });
case CFGKEY_JOYSTICK_MODE: return readOptionValue(io, joystickMode);
case CFGKEY_AUTOSTART_ON_LOAD: return readOptionValue(io, optionAutostartOnLaunch);
case CFGKEY_VIC20_RAM_EXPANSIONS: return readOptionValue<uint8_t>(io, [&](auto blocks)
{
Expand Down Expand Up @@ -249,14 +255,15 @@ void C64System::writeConfig(ConfigType type, FileIO &io)
writeOptionValueIfNotDefault(io, CFGKEY_COLOR_BRIGHTNESS, int16_t(colorSetting(ColorSetting::Brightness)), 1000);
writeOptionValueIfNotDefault(io, CFGKEY_COLOR_GAMMA, int16_t(colorSetting(ColorSetting::Gamma)), 1000);
writeOptionValueIfNotDefault(io, CFGKEY_COLOR_TINT, int16_t(colorSetting(ColorSetting::Tint)), 1000);
writeOptionValueIfNotDefault(io, defaultJoystickMode);
}
else if(type == ConfigType::SESSION)
{
writeOptionValueIfNotDefault(io, CFGKEY_MODEL, model(), defaultModel);
writeOptionValueIfNotDefault(io, CFGKEY_AUTOSTART_WARP, autostartWarp(), true);
writeOptionValueIfNotDefault(io, CFGKEY_AUTOSTART_TDE, autostartTDE(), false);
writeOptionValueIfNotDefault(io, CFGKEY_AUTOSTART_BASIC_LOAD, autostartBasicLoad(), false);
writeOptionValueIfNotDefault(io, CFGKEY_SWAP_JOYSTICK_PORTS, optionSwapJoystickPorts, JoystickMode::NORMAL);
writeOptionValueIfNotDefault(io, CFGKEY_AUTOSTART_BASIC_LOAD, intResource("AutostartBasicLoad"), defaultIntResource("AutostartBasicLoad"));
writeOptionValueIfNotDefault(io, joystickMode);
writeOptionValueIfNotDefault(io, CFGKEY_AUTOSTART_ON_LOAD, optionAutostartOnLaunch, true);
if(currSystem == ViceSystem::VIC20) // save RAM expansion settings
{
Expand Down
13 changes: 3 additions & 10 deletions C64.emu/src/main/resources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bool C64System::updateIntResourceInCPUTrap(const char *name, int val)
{
if(intResource(name) == val)
return false;
log.info("updating resource:{} to:{}", name, val);
enterCPUTrap();
setIntResource(name, val);
return true;
Expand Down Expand Up @@ -110,16 +111,6 @@ bool C64System::autostartTDE() const
return intResource("AutostartHandleTrueDriveEmulation");
}

void C64System::setAutostartBasicLoad(bool on)
{
setIntResource("AutostartBasicLoad", on);
}

bool C64System::autostartBasicLoad() const
{
return intResource("AutostartBasicLoad");
}

void C64System::setBorderMode(int mode)
{
if(!plugin.borderModeStr)
Expand Down Expand Up @@ -224,6 +215,8 @@ void C64System::setColorSetting(ColorSetting s, int v)

void C64System::setReuSize(int size)
{
if(!currSystemIsC64Or128())
return;
enterCPUTrap();
if(size)
{
Expand Down
4 changes: 2 additions & 2 deletions C64.emu/src/main/sysfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static ArchiveIO *archiveIOForSysFile(C64System &system, IG::CStringView archive
static AssetIO assetIOForSysFile(IG::ApplicationContext ctx, std::string_view sysFileName, std::string_view subPath, char **complete_path_return)
{
auto fullPath = FS::pathString(subPath, sysFileName);
auto file = ctx.openAsset(fullPath, IOAccessHint::All, {.test = true});
auto file = ctx.openAsset(fullPath, {.test = true, .accessHint = IOAccessHint::All});
if(!file)
return {};
if(complete_path_return)
Expand Down Expand Up @@ -343,7 +343,7 @@ CLINK int sysfile_load(const char *name, const char *subPath, uint8_t *dest, int
}
else
{
auto file = appContext.openFileUri(FS::uriString(basePath, subPath, name), IOAccessHint::All, {.test = true});
auto file = appContext.openFileUri(FS::uriString(basePath, subPath, name), {.test = true, .accessHint = IOAccessHint::All});
if(!file)
continue;
auto size = loadSysFile(file, name, dest, minsize, maxsize);
Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/src/AutosaveManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool AutosaveManager::load(AutosaveActionSource src, LoadAutosaveMode mode)
if(saveOnlyBackupMemory && src == AutosaveActionSource::Auto)
return true;
if(!stateIO)
stateIO = appContext().openFileUri(statePath(), {}, OpenFlags::createFile());
stateIO = appContext().openFileUri(statePath(), OpenFlags::createFile());
if(stateIO.getExpected<uint8_t>(0)) // check if state contains data
{
if(mode == LoadAutosaveMode::NoState)
Expand Down
Loading

0 comments on commit e98e388

Please sign in to comment.