Skip to content

Commit

Permalink
1.5.74 release
Browse files Browse the repository at this point in the history
* EmuFramework: Fix writing input device configs when no saved key config is present and write them at the end of the file
* EmuFramework: Add option to reset a category to defaults in ButtonConfigView
* C64.emu: Recognize headerless VIC-20 cart file extensions (.20, .40, etc.)
* C64.emu: Test more filename patterns when checking for split VIC-20 cart path
* C64.emu: Default loading headerless 16KB VIC-20 carts to 0x6000-0xBFFF
* Various code clean up
  • Loading branch information
Robert Broglia committed Aug 27, 2023
1 parent ff7d2ce commit 44e5610
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 178 deletions.
71 changes: 41 additions & 30 deletions C64.emu/src/main/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ bool hasC64TapeExtension(std::string_view name)

bool hasC64CartExtension(std::string_view name)
{
return IG::endsWithAnyCaseless(name, ".bin", ".crt");
return endsWithAnyCaseless(name, ".bin", ".crt",
".20", ".40", ".60", ".70", ".a0", ".b0"); // VIC-20 headerless carts
}

static bool hasC64Extension(std::string_view name)
Expand Down Expand Up @@ -353,21 +354,19 @@ bool C64App::willCreateSystem(ViewAttachParams attach, const Input::Event &e)
return false;
}

static FS::PathString vic20ExtraCartPath(IG::ApplicationContext ctx, std::string_view baseCartName, std::string_view searchPath)
static FS::PathString vic20ExtraCartPath(ApplicationContext ctx, std::string_view baseCartName, std::string_view searchPath)
{
auto findAddrSuffixOffset =
[](std::string_view baseCartName) -> uintptr_t
auto findAddrSuffixOffset = [](std::string_view baseCartName) -> uintptr_t
{
constexpr std::array<std::string_view, 5> addrSuffixStr
{
"-2000.", "-4000.", "-6000.", "-a000.", "-b000."
};
for(auto suffixStr : addrSuffixStr)
for(auto suffixStr : std::array{
"-2000.", "-4000.", "-6000.", "-a000.", "-b000.",
"[2000]", "[4000]", "[6000]", "[A000]", "[B000]", // TOSEC names
".20", ".40", ".60", ".a0", ".b0"})
{
if(auto offset = baseCartName.rfind(suffixStr);
offset != baseCartName.npos)
{
return offset;
return offset + 1; // skip '-', '[', or '.'
}
}
return 0;
Expand All @@ -377,17 +376,14 @@ static FS::PathString vic20ExtraCartPath(IG::ApplicationContext ctx, std::string
{
return {};
}
addrSuffixOffset++; // skip '-'
constexpr std::array<char, 5> addrSuffixChar
{
'2', '4', '6', 'a', 'b'
};
for(auto suffixChar : addrSuffixChar) // looks for a matching file with a valid memory address suffix
const auto &addrSuffixChar = baseCartName[addrSuffixOffset];
bool addrCharIsUpper = addrSuffixChar == 'A' || addrSuffixChar == 'B';
for(auto c : std::array{'2', '4', '6', 'a', 'b'}) // looks for a matching file with a valid memory address suffix
{
if(suffixChar == baseCartName[addrSuffixOffset])
if(c == tolower(addrSuffixChar))
continue; // skip original filename
FS::FileString cartName{baseCartName};
cartName[addrSuffixOffset] = suffixChar;
cartName[addrSuffixOffset] = addrCharIsUpper ? toupper(c) : c;
auto cartPath = FS::uriString(searchPath, cartName);
if(ctx.fileUriExists(cartPath))
{
Expand All @@ -397,6 +393,21 @@ static FS::PathString vic20ExtraCartPath(IG::ApplicationContext ctx, std::string
return {};
}

void C64System::tryLoadingSplitVic20Cart()
{
if(!contentDirectory().size())
return;
auto extraCartPath = vic20ExtraCartPath(appContext(), contentFileName(), contentDirectory());
if(extraCartPath.size())
{
logMsg("loading extra cart image:%s", extraCartPath.data());
if(plugin.cartridge_attach_image(CARTRIDGE_VIC20_DETECT, extraCartPath.data()) != 0)
{
EmuSystem::throwFileReadError();
}
}
}

void C64System::loadContent(IO &, EmuSystemCreateParams params, OnLoadProgressDelegate)
{
initC64(EmuApp::get(appContext()));
Expand All @@ -405,12 +416,20 @@ void C64System::loadContent(IO &, EmuSystemCreateParams params, OnLoadProgressDe
if(shouldAutostart && plugin.autostart_autodetect_)
{
logMsg("loading & autostarting:%s", contentLocation().data());
if(IG::endsWithAnyCaseless(contentFileName(), ".prg"))
if(endsWithAnyCaseless(contentFileName(), ".prg"))
{
// needed to store AutostartPrgDisk.d64
fallbackSaveDirectory(true);
}
if(plugin.autostart_autodetect(contentLocation().data(), nullptr, 0, AUTOSTART_MODE_RUN) != 0)
if(currSystem == ViceSystem::VIC20 && hasC64CartExtension(contentFileName()))
{
if(plugin.cartridge_attach_image(CARTRIDGE_VIC20_DETECT, contentLocation().data()) != 0)
{
EmuSystem::throwFileReadError();
}
tryLoadingSplitVic20Cart();
}
else if(plugin.autostart_autodetect(contentLocation().data(), nullptr, 0, AUTOSTART_MODE_RUN) != 0)
{
EmuSystem::throwFileReadError();
}
Expand Down Expand Up @@ -440,17 +459,9 @@ void C64System::loadContent(IO &, EmuSystemCreateParams params, OnLoadProgressDe
{
EmuSystem::throwFileReadError();
}
if(currSystem == ViceSystem::VIC20 && contentDirectory().size()) // check if the cart is part of a *-x000.prg pair
if(currSystem == ViceSystem::VIC20)
{
auto extraCartPath = vic20ExtraCartPath(appContext(), contentFileName(), contentDirectory());
if(extraCartPath.size())
{
logMsg("loading extra cart image:%s", extraCartPath.data());
if(plugin.cartridge_attach_image(systemCartType(currSystem), extraCartPath.data()) != 0)
{
EmuSystem::throwFileReadError();
}
}
tryLoadingSplitVic20Cart();
}
}
optionAutostartOnLaunch = false;
Expand Down
1 change: 1 addition & 0 deletions C64.emu/src/main/MainSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ protected:
void startCanvasRunningFrame();
void setCanvasSkipFrame(bool on);
bool updateCanvasPixelFormat(struct video_canvas_s *, PixelFormat);
void tryLoadingSplitVic20Cart();
};

using MainSystem = C64System;
Expand Down
3 changes: 2 additions & 1 deletion C64.emu/src/vice/vic20/cart/vic20-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ static int attach_image(int type, const char *filename)
} else if (addr == 0x6000) {
type = CARTRIDGE_VIC20_16KB_6000;
} else {
log_error(LOG_DEFAULT, "could not determine type of cartridge.");
type = CARTRIDGE_VIC20_16KB_6000;
log_message(LOG_DEFAULT, "could not determine type of cartridge, defaulting to 16KiB $6000-$bfff");
}
} else if (len == 0x2000) {
/* 8K image */
Expand Down
4 changes: 3 additions & 1 deletion EmuFramework/include/emuframework/ButtonConfigView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ public:
private:
InputManagerView &rootIMView;
TextMenuItem reset;
TextMenuItem resetDefaults;
std::unique_ptr<DualTextMenuItem[]> btn;
const KeyCategory &cat;
InputDeviceConfig *devConf{};
InputDeviceConfig &devConf;
SteadyClockTimePoint leftKeyPushTime{};

void onSet(int catIdx, MappedKeys);
void updateKeyNames(const KeyConfig &);
};

}
2 changes: 1 addition & 1 deletion EmuFramework/include/emuframework/EmuInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public:
void unbindCategory(const KeyCategory &category);
void resetCategory(const KeyCategory &category, KeyConfigDesc defaultConf);
constexpr auto find(KeyInfo key) { return std::ranges::find_if(keyMap, [&](auto &val){ return val.key == key; }); }
constexpr MappedKeys get(KeyInfo key) { return desc().get(key); }
constexpr MappedKeys get(KeyInfo key) const { return desc().get(key); }
static KeyConfig readConfig(MapIO &);
void writeConfig(FileIO &) const;

Expand Down
2 changes: 1 addition & 1 deletion EmuFramework/metadata/conf.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata_version = 1.5.73
metadata_version = 1.5.74
metadata_supportedMIMETypes = application/zip
metadata_supportedFileExtensions = rar 7z
android_metadata_versionCodeExtra = 16
Expand Down
8 changes: 3 additions & 5 deletions EmuFramework/src/ConfigFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <imagine/io/FileIO.hh>
#include <imagine/fs/FS.hh>
#include <imagine/input/config.hh>
#include <imagine/bluetooth/sys.hh>
#include <imagine/util/ScopeGuard.hh>

namespace EmuEx
Expand Down Expand Up @@ -150,15 +151,12 @@ void EmuApp::saveConfigFile(FileIO &io)
writeOptionValueIfNotDefault(io, CFGKEY_RENDERER_PRESENT_MODE, presentMode, Gfx::PresentMode::Auto);
if(used(usePresentationTime) && renderer.supportsPresentationTime())
writeOptionValueIfNotDefault(io, CFGKEY_RENDERER_PRESENTATION_TIME, usePresentationTime, true);

inputManager.writeCustomKeyConfigs(io);
inputManager.writeSavedInputDevices(appContext(), io);

writeStringOptionValue(io, CFGKEY_LAST_DIR, contentSearchPath());
writeStringOptionValue(io, CFGKEY_SAVE_PATH, system().userSaveDirectory());
writeStringOptionValue(io, CFGKEY_SCREENSHOTS_PATH, userScreenshotPath);

system().writeConfig(ConfigType::MAIN, io);
inputManager.writeCustomKeyConfigs(io);
inputManager.writeSavedInputDevices(appContext(), io);
}

EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx)
Expand Down
1 change: 1 addition & 0 deletions EmuFramework/src/EmuApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <imagine/util/format.hh>
#include <imagine/util/string.h>
#include <imagine/thread/Thread.hh>
#include <imagine/bluetooth/BluetoothInputDevScanner.hh>
#include <cmath>

namespace EmuEx
Expand Down
8 changes: 1 addition & 7 deletions EmuFramework/src/EmuInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ void InputManager::writeSavedInputDevices(ApplicationContext ctx, FileIO &io) co
// write to config file
logMsg("saving %d input device configs, %d bytes", (int)savedInputDevs.size(), (int)bytes);
io.put(uint16_t(bytes));
auto startOffset = io.tell();
io.put(uint16_t(CFGKEY_INPUT_DEVICE_CONFIGS));
io.put(uint8_t(savedInputDevs.size()));
for(auto &ePtr : savedInputDevs)
Expand All @@ -146,19 +145,14 @@ void InputManager::writeSavedInputDevices(ApplicationContext ctx, FileIO &io) co
auto devPtr = ctx.inputDevice(e.name, e.enumId);
uint8_t keyConfMap = devPtr ? (uint8_t)devPtr->map() : 0;
io.put(keyConfMap);
if(keyConfMap)
if(e.keyConfName.size())
{
logMsg("has key conf %s, map %d", e.keyConfName.data(), keyConfMap);
uint8_t keyConfNameLen = e.keyConfName.size();
io.put(keyConfNameLen);
io.write(e.keyConfName.data(), keyConfNameLen);
}
}
if(auto writtenBytes = io.tell() - startOffset;
writtenBytes != bytes)
{
logErr("expected %d bytes written, got %d", (int)bytes, (int)writtenBytes);
}
}

bool InputManager::readCustomKeyConfig(MapIO &io)
Expand Down

0 comments on commit 44e5610

Please sign in to comment.