Skip to content

Commit

Permalink
Misc tweaks and fixes
Browse files Browse the repository at this point in the history
* Imagine: Add [[nodiscard]] to functions in bit.hh to catch incorrect usage
* Imagine: Add gzipUncompressedSize()
* Imagine: Update Android Gradle plugin to 8.2.0 to fix warning with compileSdk = 34
* Imagine: Use the default pipe size when constructing PipeMessagePort
* Imagine: Add ArchiveIO::forEachEntry()/forAllEntries() and update utility functions in ArchiveFS.hh to take ArchiveIO parameter
* EmuFramework: Dynamically allocate player menu items in InputManagerDeviceView
* EmuFramework: Verify and use uncompressed size from gzip header in uncompressGzipState()
* EmuFramework: Add functions for saving media state in MDFN_StateAction() for future use
* EmuFramework: Improve support for multiple Mednafen CD interfaces
* EmuFramework: Allow passing in custom key map for gamepad app codes in genericKeyConfigs()
* C64.emu: Add option to set default True Drive Emulation
* NES.emu: Update Mapper 45 from FCEUmm
* PCE.emu: Fix handling of save states that may change sizes based on emulation options (Arcade card, etc)
* PCE.emu: Don't return error if CHD file is missing content path and allow loading CHDs inside archives
* Various code clean up
  • Loading branch information
Robert Broglia committed Jan 12, 2024
1 parent 6276bdc commit 1d7de88
Show file tree
Hide file tree
Showing 54 changed files with 330 additions and 219 deletions.
2 changes: 1 addition & 1 deletion 2600.emu/src/main/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace EmuEx
{

constexpr size_t MAX_ROM_SIZE = 512 * 1024;
const char *EmuSystem::creditsViewStr = CREDITS_INFO_STRING "(c) 2011-2023\nRobert Broglia\nwww.explusalpha.com\n\nPortions (c) the\nStella Team\nstella-emu.github.io";
const char *EmuSystem::creditsViewStr = CREDITS_INFO_STRING "(c) 2011-2024\nRobert Broglia\nwww.explusalpha.com\n\nPortions (c) the\nStella Team\nstella-emu.github.io";
bool EmuSystem::hasPALVideoSystem = true;
bool EmuSystem::hasResetModes = true;
IG::Audio::SampleFormat EmuSystem::audioSampleFormat = IG::Audio::SampleFormats::f32;
Expand Down
11 changes: 11 additions & 0 deletions C64.emu/src/main/EmuMenuViews.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ class CustomSystemOptionView : public SystemOptionView, public MainAppHelper<Cus
defaultModelItem
};

BoolMenuItem defaultTrueDriveEmu
{
"Default True Drive Emulation", attachParams(),
system().defaultDriveTrueEmulation,
[this](BoolMenuItem &item)
{
system().defaultDriveTrueEmulation = item.flipBoolValue(*this);
}
};

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

Expand Down
2 changes: 1 addition & 1 deletion C64.emu/src/main/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace EmuEx
{

constexpr SystemLogger log{"main"};
const char *EmuSystem::creditsViewStr = CREDITS_INFO_STRING "(c) 2013-2023\nRobert Broglia\nwww.explusalpha.com\n\nPortions (c) the\nVice Team\nvice-emu.sourceforge.io";
const char *EmuSystem::creditsViewStr = CREDITS_INFO_STRING "(c) 2013-2024\nRobert Broglia\nwww.explusalpha.com\n\nPortions (c) the\nVice Team\nvice-emu.sourceforge.io";
bool EmuSystem::hasPALVideoSystem = true;
bool EmuSystem::hasResetModes = true;
bool EmuSystem::handlesGenericIO = false;
Expand Down
6 changes: 4 additions & 2 deletions C64.emu/src/main/MainSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum
CFGKEY_DEFAULT_MODEL = 282, CFGKEY_DEFAULT_PALETTE_NAME = 283,
CFGKEY_DRIVE8_TYPE = 284, CFGKEY_DRIVE9_TYPE = 285,
CFGKEY_DRIVE10_TYPE = 286, CFGKEY_DRIVE11_TYPE = 287,
CFGKEY_DEFAULT_DRIVE_TRUE_EMULATION = 288
};

enum Vic20Ram : uint8_t
Expand Down Expand Up @@ -92,7 +93,7 @@ public:
struct video_canvas_s *activeCanvas{};
const char *sysFileDir{};
VicePlugin plugin{};
mutable FS::ArchiveIterator firmwareArchiveIt;
mutable ArchiveIO firmwareArch;
std::string defaultPaletteName{};
std::string lastMissingSysFile;
IG::PixmapView canvasSrcPix{};
Expand All @@ -104,6 +105,7 @@ public:
std::array <FS::PathString, Config::envIsLinux ? 3 : 1> sysFilePath{};
std::array<char, 21> externalPaletteResStr{};
std::array<char, 17> paletteFileResStr{};
bool defaultDriveTrueEmulation{};
Byte1Option optionDriveTrueEmulation{CFGKEY_DRIVE_TRUE_EMULATION, 0};
Byte1Option optionCropNormalBorders{CFGKEY_CROP_NORMAL_BORDERS, 1};
Byte1Option optionAutostartWarp{CFGKEY_AUTOSTART_WARP, 1};
Expand Down Expand Up @@ -184,7 +186,7 @@ public:
bool currSystemIsC64Or128() const;
void setRuntimeReuSize(int size);
void resetCanvasSourcePixmap(struct video_canvas_s *c);
FS::ArchiveIterator &firmwareArchiveIterator(CStringView path) const;
ArchiveIO &firmwareArchive(CStringView path) const;
void setSystemFilesPath(CStringView path, FS::file_type);
void execC64Frame();

Expand Down
4 changes: 3 additions & 1 deletion C64.emu/src/main/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void C64System::onSessionOptionsLoaded(EmuApp &)
bool C64System::resetSessionOptions(EmuApp &app)
{
optionModel.reset();
optionDriveTrueEmulation.reset();
optionDriveTrueEmulation = defaultDriveTrueEmulation;
optionAutostartWarp.reset();
optionAutostartTDE.reset();
optionAutostartBasicLoad.reset();
Expand Down Expand Up @@ -183,6 +183,7 @@ bool C64System::readConfig(ConfigType type, MapIO &io, unsigned key, size_t read
case CFGKEY_SYSTEM_FILE_PATH:
return readStringOptionValue<FS::PathString>(io, readSize, [&](auto &&path){sysFilePath[0] = IG_forward(path);});
case CFGKEY_RESID_SAMPLING: return optionReSidSampling.readFromIO(io, readSize);
case CFGKEY_DEFAULT_DRIVE_TRUE_EMULATION: readOptionValue(io, readSize, defaultDriveTrueEmulation);
}
}
else if(type == ConfigType::CORE)
Expand Down Expand Up @@ -232,6 +233,7 @@ void C64System::writeConfig(ConfigType type, FileIO &io)
{
if(type == ConfigType::MAIN)
{
writeOptionValueIfNotDefault(io, CFGKEY_DEFAULT_DRIVE_TRUE_EMULATION, defaultDriveTrueEmulation, false);
optionViceSystem.writeWithKeyIfNotDefault(io);
optionBorderMode.writeWithKeyIfNotDefault(io);
optionCropNormalBorders.writeWithKeyIfNotDefault(io);
Expand Down
85 changes: 42 additions & 43 deletions C64.emu/src/main/sysfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ constexpr SystemLogger log{"sysfile"};

static int loadSysFile(Readable auto &file, const char *name, uint8_t *dest, int minsize, int maxsize)
{
//logMsg("loading system file: %s", complete_path);
//log.debug("loading system file:{}", name);
ssize_t rsize = file.size();
bool load_at_end;
if(minsize < 0)
Expand All @@ -51,12 +51,12 @@ static int loadSysFile(Readable auto &file, const char *name, uint8_t *dest, int
}
if(rsize < (minsize))
{
logErr("ROM %s: short file", name);
log.error("ROM {}: short file", name);
return -1;
}
if(rsize == (maxsize + 2))
{
logWarn("ROM `%s': two bytes too large - removing assumed start address", name);
log.warn("ROM {}: two bytes too large - removing assumed start address", name);
if(file.read((char*)dest, 2) < 2)
{
return -1;
Expand All @@ -69,7 +69,7 @@ static int loadSysFile(Readable auto &file, const char *name, uint8_t *dest, int
}
else if(rsize > (maxsize))
{
logWarn("ROM `%s': long file, discarding end.", name);
log.warn("ROM {}: long file, discarding end.", name);
rsize = maxsize;
}
if((rsize = file.read((char *)dest, rsize)) < minsize)
Expand All @@ -83,28 +83,31 @@ static ArchiveIO *archiveIOForSysFile(C64System &system, IG::CStringView archive
auto sysFilePath = FS::pathString(subPath, sysFileName);
try
{
for(auto &entry : system.firmwareArchiveIterator(archivePath))
auto &arch = system.firmwareArchive(archivePath);
if(FS::seekFileInArchive(arch, [&](auto &entry)
{
if(entry.type() == FS::file_type::directory)
{
continue;
}
auto name = entry.name();
if(!name.ends_with(sysFilePath))
continue;
logMsg("archive file entry:%s", name.data());
return false;
log.info("found file in archive:{}", name);
if(complete_path_return)
{
*complete_path_return = strdup(name.data());
assert(*complete_path_return);
}
return &entry;
return true;
}))
{
return &arch;
}
else
{
log.error("not found in archive:{}", archivePath);
}
logErr("not found in archive:%s", archivePath.data());
}
catch(...)
{
logErr("error opening archive:%s", archivePath.data());
log.error("error opening archive:{}", archivePath);
}
return {};
}
Expand All @@ -123,18 +126,18 @@ static AssetIO assetIOForSysFile(IG::ApplicationContext ctx, std::string_view sy
return file;
}

FS::ArchiveIterator &C64System::firmwareArchiveIterator(CStringView path) const
ArchiveIO &C64System::firmwareArchive(CStringView path) const
{
if(!firmwareArchiveIt.hasArchive())
if(!firmwareArch)
{
log.info("{} not cached, opening archive", path);
firmwareArchiveIt = {appContext().openFileUri(path)};
firmwareArch = {appContext().openFileUri(path)};
}
else
{
firmwareArchiveIt.rewind();
firmwareArch.rewind();
}
return firmwareArchiveIt;
return firmwareArch;
}

static bool archiveHasDrivesDirectory(ApplicationContext ctx, CStringView path)
Expand All @@ -152,12 +155,12 @@ void C64System::setSystemFilesPath(CStringView path, FS::file_type type)
throw std::runtime_error{"Path is missing DRIVES folder"};
}
sysFilePath[0] = path;
firmwareArchiveIt = {};
firmwareArch = {};
}

std::vector<std::string> C64System::systemFilesWithExtension(const char *ext) const
{
logMsg("looking for system files with extension:%s", ext);
log.info("looking for system files with extension:{}", ext);
std::vector<std::string> filenames{};
try
{
Expand All @@ -170,21 +173,18 @@ std::vector<std::string> C64System::systemFilesWithExtension(const char *ext) co
continue;
if(EmuApp::hasArchiveExtension(displayName))
{
for(auto &entry : firmwareArchiveIterator(basePath))
firmwareArchive(basePath).forAllEntries([&](auto &entry)
{
if(entry.type() == FS::file_type::directory)
{
continue;
}
auto name = entry.name();
if(FS::basename(FS::dirname(name)) != sysFileDir)
continue;
if(name.ends_with(ext))
if(entry.type() == FS::file_type::directory
|| !name.ends_with(ext)
|| FS::basename(FS::dirname(name)) != sysFileDir)
{
logMsg("archive file entry:%s", name.data());
filenames.emplace_back(FS::basename(name));
return;
}
}
log.info("found file in archive:{}", name);
filenames.emplace_back(FS::basename(name));
});
}
else
{
Expand All @@ -194,7 +194,7 @@ std::vector<std::string> C64System::systemFilesWithExtension(const char *ext) co
auto name = entry.name();
if(name.ends_with(ext))
{
logMsg("file entry:%s", name.data());
log.info("found file:{}", name);
filenames.emplace_back(name);
}
return true;
Expand All @@ -204,7 +204,7 @@ std::vector<std::string> C64System::systemFilesWithExtension(const char *ext) co
}
catch(...)
{
logErr("error while getting system files");
log.error("error while getting system files");
}
std::sort(filenames.begin(), filenames.end());
return filenames;
Expand All @@ -222,7 +222,7 @@ CLINK int sysfile_init(const char *emu_id)

CLINK FILE *sysfile_open(const char *name, const char *subPath, char **complete_path_return, const char *open_mode)
{
logMsg("sysfile open:%s subPath:%s", name, subPath);
EmuEx::log.info("sysfile open:{} subPath:{}", name, subPath);
auto appContext = gAppContext();
auto &system = static_cast<C64System&>(gSystem());
for(const auto &basePath : system.sysFilePath)
Expand Down Expand Up @@ -262,14 +262,14 @@ CLINK FILE *sysfile_open(const char *name, const char *subPath, char **complete_
return io.toFileStream(open_mode);
}
}
logErr("can't open %s in system paths", name);
EmuEx::log.error("can't open {} in system paths", name);
system.lastMissingSysFile = name;
return nullptr;
}

CLINK int sysfile_locate(const char *name, const char *subPath, char **complete_path_return)
{
logMsg("sysfile locate:%s subPath:%s", name, subPath);
EmuEx::log.info("sysfile locate:{} subPath:{}", name, subPath);
auto appContext = gAppContext();
auto &system = static_cast<C64System&>(gSystem());
for(const auto &basePath : system.sysFilePath)
Expand Down Expand Up @@ -307,7 +307,7 @@ CLINK int sysfile_locate(const char *name, const char *subPath, char **complete_
return 0;
}
}
logErr("%s not found in system paths", name);
EmuEx::log.error("{} not found in system paths", name);
if(complete_path_return)
{
*complete_path_return = nullptr;
Expand All @@ -317,7 +317,7 @@ CLINK int sysfile_locate(const char *name, const char *subPath, char **complete_

CLINK int sysfile_load(const char *name, const char *subPath, uint8_t *dest, int minsize, int maxsize)
{
logMsg("sysfile load:%s subPath:%s", name, subPath);
EmuEx::log.info("sysfile load:{} subPath:{}", name, subPath);
auto appContext = gAppContext();
auto &system = static_cast<C64System&>(gSystem());
for(const auto &basePath : system.sysFilePath)
Expand All @@ -335,7 +335,7 @@ CLINK int sysfile_load(const char *name, const char *subPath, uint8_t *dest, int
auto size = loadSysFile(*ioPtr, name, dest, minsize, maxsize);
if(size == -1)
{
logErr("failed loading system file:%s from:%s", name, basePath.data());
EmuEx::log.error("failed loading system file:{} from:{}", name, basePath);
return -1;
}
return size;
Expand All @@ -345,17 +345,16 @@ CLINK int sysfile_load(const char *name, const char *subPath, uint8_t *dest, int
auto file = appContext.openFileUri(FS::uriString(basePath, subPath, name), IOAccessHint::All, {.test = true});
if(!file)
continue;
//logMsg("loading system file: %s", complete_path);
auto size = loadSysFile(file, name, dest, minsize, maxsize);
if(size == -1)
{
logErr("failed loading system file:%s from:%s", name, basePath.data());
EmuEx::log.error("failed loading system file:{} from:{}", name, basePath);
continue;
}
return size;
}
}
logErr("can't load %s in system paths", name);
EmuEx::log.error("can't load {} in system paths", name);
system.lastMissingSysFile = name;
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion EmuFramework/include/emuframework/EmuApp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ public:
auto &showOnSecondScreenOption() { return optionShowOnSecondScreen; }
auto &textureBufferModeOption() { return optionTextureBufferMode; }
void setContentRotation(IG::Rotation);
IG::Rotation contentRotation() const { return contentRotation_; }
Rotation contentRotation() const { return contentRotation_; }
void updateVideoContentRotation();
void updateContentRotation();
float videoBrightness(ImageChannel) const;
const Gfx::Vec3 &videoBrightnessAsRGB() const { return videoBrightnessRGB; }
Expand Down
7 changes: 1 addition & 6 deletions EmuFramework/include/emuframework/EmuSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ struct SaveStateFlags
uint8_t uncompressed:1{};
};

struct UncompressStateFlags
{
uint8_t estimatedExpectedSize:1{};
};

class EmuSystem
{
public:
Expand Down Expand Up @@ -252,7 +247,7 @@ public:
void loadState(EmuApp &, CStringView uri);
void saveState(CStringView uri);
DynArray<uint8_t> saveState();
DynArray<uint8_t> uncompressGzipState(std::span<uint8_t> buff, size_t expectedSize, UncompressStateFlags flags = {});
DynArray<uint8_t> uncompressGzipState(std::span<uint8_t> buff, size_t expectedSize = 0);
bool stateExists(int slot) const;
static std::string_view stateSlotName(int slot);
std::string_view stateSlotName() { return stateSlotName(stateSlot()); }
Expand Down
3 changes: 2 additions & 1 deletion EmuFramework/include/emuframework/InputManagerView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <imagine/gfx/GfxText.hh>
#include <imagine/gfx/Quads.hh>
#include <imagine/util/container/ArrayList.hh>
#include <imagine/util/memory/DynArray.hh>
#include <vector>
#include <array>
#include <string>
Expand Down Expand Up @@ -104,7 +105,7 @@ public:
private:
InputManager &inputManager;
InputManagerView &rootIMView;
TextMenuItem playerItem[6];
DynArray<TextMenuItem> playerItems;
MultiChoiceMenuItem player;
TextMenuItem loadProfile;
TextMenuItem renameProfile;
Expand Down
Loading

0 comments on commit 1d7de88

Please sign in to comment.