Skip to content

Commit

Permalink
Build in ROMs
Browse files Browse the repository at this point in the history
Add the ROM contents as header files, with necessary changes.
Builtin ROMs are used as a default, if ROM files not found.
  • Loading branch information
zoltanvb committed Oct 5, 2022
1 parent e16e6a8 commit 71a846e
Show file tree
Hide file tree
Showing 7 changed files with 30,238 additions and 52 deletions.
12 changes: 9 additions & 3 deletions core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include "core.hpp"
#include "libretro_keys_reverse.h"
namespace Ep128Emu
{
#include "roms/roms.hpp"
namespace Ep128Emu {

LibretroCore::LibretroCore(retro_log_printf_t log_cb_, int machineDetailedType_, int contentLocale, bool canSkipFrames_, const char* romDirectory_, const char* saveDirectory_,
const char* startSequence_, const char* cfgFile, bool useHalfFrame_, bool enhancedRom)
Expand Down Expand Up @@ -398,7 +398,13 @@ LibretroCore::LibretroCore(retro_log_printf_t log_cb_, int machineDetailedType_,
if(!romFound)
{
log_cb(RETRO_LOG_ERROR, "ROM file or any alternative not found: %s \n",config->memory.rom[i].file.c_str());
throw Ep128Emu::Exception("ROM file not found!");
replacementFullName = "_default_" + romShortName;
config->memory.rom[i].file = replacementFullName;
std::map<std::string, const unsigned char*>::const_iterator iter_builtin_rom;
iter_builtin_rom = Ep128Emu::builtin_rom.find(replacementFullName);
if (iter_builtin_rom == Ep128Emu::builtin_rom.end()) {
throw Ep128Emu::Exception("ROM file not found!");
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ep128emu_core_libretro.info
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ firmware_count = 22

firmware0_desc = "exos21.rom (Enterprise 128 Expandible OS 2.1)"
firmware0_path = "ep128emu/roms/exos21.rom";
firmware0_opt = "false"
firmware0_opt = "true"

firmware1_desc = "basic21.rom (Enterprise 128 BASIC Interpreter v2.1)"
firmware1_path = "ep128emu/roms/basic21.rom";
firmware1_opt = "false"
firmware1_opt = "true"

firmware2_desc = "exdos13.rom (Enterprise 128 Disk Controller v1.3)"
firmware2_path = "ep128emu/roms/exdos13.rom";
firmware2_opt = "false"
firmware2_opt = "true"

firmware3_desc = "exos20.rom (Enterprise 64 Expandible OS 2.0)"
firmware3_path = "ep128emu/roms/exos20.rom";
Expand Down
30,142 changes: 30,142 additions & 0 deletions roms/roms.hpp

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/cpc464vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "videorec.hpp"
#include "fdc765.hpp"
#include "cpcdisk.hpp"
#include "roms/roms.hpp"

#include <vector>

Expand Down Expand Up @@ -1167,18 +1168,25 @@ namespace CPC464 {
}
// load file into memory
std::vector<uint8_t> buf;
buf.resize(0x4000);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
if (std::ftell(f) < long(offs + 0x4000)) {
std::map<std::string, const unsigned char*>::const_iterator iter_builtin_rom;
iter_builtin_rom = Ep128Emu::builtin_rom.find(fileName);
if (iter_builtin_rom != Ep128Emu::builtin_rom.end()) {
buf.insert(buf.begin(), (*iter_builtin_rom).second+offs, (*iter_builtin_rom).second + offs + 0x4000);
} else {
buf.resize(0x4000);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
if (std::ftell(f) < long(offs + 0x4000)) {
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
std::fseek(f, long(offs), SEEK_SET);
if(!std::fread(&(buf.front()), 1, 0x4000, f))
throw Ep128Emu::Exception("ROM file read error");
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
std::fseek(f, long(offs), SEEK_SET);
std::fread(&(buf.front()), 1, 0x4000, f);
std::fclose(f);
// load new segment, or replace existing ROM
memory.loadROMSegment(n, &(buf.front()), 0x4000);
}
Expand Down
29 changes: 19 additions & 10 deletions src/epmemcfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "ep128emu.hpp"
#include "ep128vm.hpp"
#include "roms/roms.hpp"
#ifdef ENABLE_SDEXT
# include "sdext.hpp"
#endif
Expand Down Expand Up @@ -72,18 +73,26 @@ namespace Ep128 {
}
// load file into memory
std::vector<uint8_t> buf;
buf.resize(0x4000, 0xFF);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
if (std::ftell(f) < long(offs + 11)) {
std::map<std::string, const unsigned char*>::const_iterator iter_builtin_rom;
iter_builtin_rom = Ep128Emu::builtin_rom.find(fileName);
if (iter_builtin_rom != Ep128Emu::builtin_rom.end()) {
buf.insert(buf.begin(), (*iter_builtin_rom).second+offs, (*iter_builtin_rom).second + offs + 0x4000);
} else {
buf.resize(0x4000, 0xFF);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
if (std::ftell(f) < long(offs + 11)) {
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
std::fseek(f, long(offs), SEEK_SET);
if(!std::fread(&(buf.front()), 1, 0x4000, f))
throw Ep128Emu::Exception("ROM file read error");
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
std::fseek(f, long(offs), SEEK_SET);
std::fread(&(buf.front()), 1, 0x4000, f);
std::fclose(f);

if (memory.isSegmentRAM(n)) {
memory.loadSegment(n, true, &(buf.front()), 0x4000);
// if there was RAM at the specified segment, relocate it
Expand Down
44 changes: 29 additions & 15 deletions src/tvc64vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "tvc64vm.hpp"
#include "debuglib.hpp"
#include "videorec.hpp"
#include "roms/roms.hpp"
#ifdef ENABLE_SDEXT
# include "sdext.hpp"
#endif
Expand Down Expand Up @@ -1484,23 +1485,36 @@ namespace TVC64 {
}
// load file into memory
std::vector<uint8_t> buf;
buf.resize(0x4000, 0xFF);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
long dataSize = std::ftell(f) - long(offs);
if (dataSize < 0x0400L) {
long dataSize;
std::map<std::string, const unsigned char*>::const_iterator iter_builtin_rom;
iter_builtin_rom = Ep128Emu::builtin_rom.find(fileName);
if (iter_builtin_rom != Ep128Emu::builtin_rom.end()) {
dataSize = Ep128Emu::builtin_rom_length.at(fileName) - offs;
if (n == 0x02 || n == 0x04)
dataSize = (dataSize < 0x2000L ? dataSize : 0x2000L);
else
dataSize = (dataSize < 0x4000L ? dataSize : 0x4000L);
buf.insert(buf.begin(), (*iter_builtin_rom).second+offs, (*iter_builtin_rom).second + offs + dataSize);
} else {
buf.resize(0x4000, 0xFF);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
dataSize = std::ftell(f) - long(offs);
if (dataSize < 0x0400L) {
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
if (n == 0x02 || n == 0x04)
dataSize = (dataSize < 0x2000L ? dataSize : 0x2000L);
else
dataSize = (dataSize < 0x4000L ? dataSize : 0x4000L);
std::fseek(f, long(offs), SEEK_SET);
if(!std::fread(&(buf.front()), sizeof(uint8_t), size_t(dataSize), f))
throw Ep128Emu::Exception("ROM file read error");
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
if (n == 0x02 || n == 0x04)
dataSize = (dataSize < 0x2000L ? dataSize : 0x2000L);
else
dataSize = (dataSize < 0x4000L ? dataSize : 0x4000L);
std::fseek(f, long(offs), SEEK_SET);
std::fread(&(buf.front()), sizeof(uint8_t), size_t(dataSize), f);
std::fclose(f);
// load new segment, or replace existing ROM
memory.loadROMSegment(n, &(buf.front()), size_t(dataSize));
}
Expand Down
29 changes: 18 additions & 11 deletions src/zx128vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "zx128vm.hpp"
#include "debuglib.hpp"
#include "videorec.hpp"

#include "roms/roms.hpp"
#include <vector>

static const uint8_t keyboardConvTable[256] = {
Expand Down Expand Up @@ -1052,18 +1052,25 @@ namespace ZX128 {
}
// load file into memory
std::vector<uint8_t> buf;
buf.resize(0x4000);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
if (std::ftell(f) < long(offs + 0x4000)) {
std::map<std::string, const unsigned char*>::const_iterator iter_builtin_rom;
iter_builtin_rom = Ep128Emu::builtin_rom.find(fileName);
if (iter_builtin_rom != Ep128Emu::builtin_rom.end()) {
buf.insert(buf.begin(), (*iter_builtin_rom).second+offs, (*iter_builtin_rom).second + offs + 0x4000);
} else {
buf.resize(0x4000);
std::FILE *f = Ep128Emu::fileOpen(fileName, "rb");
if (!f)
throw Ep128Emu::Exception("cannot open ROM file");
std::fseek(f, 0L, SEEK_END);
if (std::ftell(f) < long(offs + 0x4000)) {
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
std::fseek(f, long(offs), SEEK_SET);
if(!std::fread(&(buf.front()), 1, 0x4000, f))
throw Ep128Emu::Exception("ROM file read error");
std::fclose(f);
throw Ep128Emu::Exception("ROM file is shorter than expected");
}
std::fseek(f, long(offs), SEEK_SET);
std::fread(&(buf.front()), 1, 0x4000, f);
std::fclose(f);
// load new segment, or replace existing ROM
memory.loadSegment(n, true, &(buf.front()), 0x4000);
}
Expand Down

0 comments on commit 71a846e

Please sign in to comment.