Skip to content

Commit 6d68e58

Browse files
committed
Add back initial support for loading and configuring OctoCartridge files (drag&drop only).
1 parent 86bf139 commit 6d68e58

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

src/editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,10 @@ void Editor::recompile()
431431
_compiler.reset();
432432
if(_text.empty() || _text.back() != '\n') {
433433
auto text = _text + '\n';
434-
_compiler.compile(_filename, text.data(), text.data() + text.size() + 1);
434+
_compiler.compile(_filename, text);
435435
}
436436
else {
437-
_compiler.compile(_filename, _text.data(), _text.data() + _text.size() + 1);
437+
_compiler.compile(_filename, _text);
438438
}
439439
auto time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start).count();
440440
TraceLog(LOG_INFO, "Recompilation took %dms", (int)time_ms);

src/emuhostex.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,37 @@ bool EmuHostEx::loadRom(std::string_view filename, LoadOptions loadOpt)
269269
unsigned int size = 0;
270270
_customPalette = false;
271271
_colorPalette = _defaultPalette;
272+
// TODO: Refactor this
273+
if (filename.ends_with(".gif")) {
274+
auto cart = emu::OctoCartridge(std::string(filename));
275+
if (cart.loadCartridge()) {
276+
auto options = cart.getOptions();
277+
auto properties = CoreRegistry::propertiesFromOctoOptions(options);
278+
auto source = cart.getSource();
279+
updateEmulatorOptions(properties);
280+
auto c8c = std::make_unique<emu::OctoCompiler>();
281+
if (c8c->compile(filename, source).resultType == emu::CompileResult::eOK) {
282+
auto loadAddress = _chipEmu->defaultLoadAddress();
283+
if (c8c->codeSize() < _chipEmu->memSize() - loadAddress) {
284+
_chipEmu->reset();
285+
auto binary = std::span<const uint8_t>(c8c->code(), c8c->code() + c8c->codeSize());
286+
if (_chipEmu->loadData(binary, loadAddress)) {
287+
_romImage.assign(c8c->code(), c8c->code() + c8c->codeSize());
288+
_romSha1 = c8c->sha1();
289+
_romName = filename;
290+
_romIsWellKnown = false;
291+
}
292+
}
293+
whenRomLoaded(_romName, loadOpt & LoadOptions::SetToRun, c8c.get(), source);
294+
return true;
295+
}
296+
else {
297+
_romName = filename;
298+
whenRomLoaded(_romName, false, c8c.get(), source);
299+
return true;
300+
}
301+
}
302+
}
272303
auto fileData = loadFile(filename, Librarian::MAX_ROM_SIZE);
273304
if (fileData) {
274305
resetAllBreakpoints();
@@ -319,8 +350,8 @@ bool EmuHostEx::loadBinary(std::string_view filename, ghc::span<const uint8_t> b
319350
TraceLog(LOG_INFO, "Loading %s file with sha1: %s", isKnown ? "known" : "unknown", calculateSha1(fileData).to_hex().c_str());
320351
auto knownProperties = _librarian.getPropertiesForFile(fileData);
321352
if (endsWith(filename, ".8o")) {
322-
c8c = std::make_unique<emu::OctoCompiler>();
323353
source.assign((const char*)fileData.data(), fileData.size());
354+
c8c = std::make_unique<emu::OctoCompiler>();
324355
if (c8c->compile(filename).resultType == emu::CompileResult::eOK) {
325356
auto loadAddress = _chipEmu->defaultLoadAddress();
326357
if (c8c->codeSize() < _chipEmu->memSize() - loadAddress) {

src/emulation/coreregistry.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
#include "coreregistry.hpp"
2828

2929
#include <chiplet/utility.hpp>
30+
#include <chiplet/octocartridge.hpp>
3031

3132
#include <set>
3233

34+
#include <nlohmann/json.hpp>
35+
3336
namespace emu {
3437

3538
void CoreRegistry::IFactoryInfo::cacheVariantMappings() const
@@ -58,6 +61,34 @@ Properties CoreRegistry::IFactoryInfo::variantProperties(const std::string& vari
5861
return {};
5962
}
6063

64+
Properties CoreRegistry::propertiesFromOctoOptions(const OctoOptions& options)
65+
{
66+
Properties result;
67+
auto pXO = propertiesForPreset("XO-CHIP");
68+
auto j = nlohmann::json::object();
69+
to_json(j, pXO);
70+
j["class"] = "CHIP-8 GENERIC";
71+
j["behaviorBase"] = "XO-CHIP";
72+
j["memory"] = "65536";
73+
j["cleanRam"] = true;
74+
j["frameRate"] = 60;
75+
j["instructionsPerFrame"] = options.tickrate;
76+
j["justShiftVx"] = options.qShift;
77+
j["loadStoreIncIByXPlus1"] = !options.qLoadStore;
78+
j["loadStoreIncIByX"] = false;
79+
j["jump0Bxnn"] = options.qJump0;
80+
j["dontResetVf"] = !options.qLogic;
81+
j["wrapSprites"] = !options.qClip;
82+
j["instantDxyn"] = !options.qVBlank;
83+
auto palette = nlohmann::json::array();
84+
for (auto col : options.colors) {
85+
palette.push_back(Palette::Color::fromRGB(col).toStringRGB());
86+
}
87+
j["palette"] = palette;
88+
from_json(j, result);
89+
return result;
90+
}
91+
6192
CoreRegistry::CoreRegistry()
6293
{
6394
for(auto& [key, info] : factoryMap()) {

src/emulation/coreregistry.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
namespace emu {
4343

44+
class OctoOptions;
45+
4446
enum PropertySelector {PropertiesFromVariant, PropertiesAsGiven};
4547
class CoreRegistry {
4648
public:
@@ -263,6 +265,8 @@ class CoreRegistry {
263265
return {};
264266
}
265267

268+
static Properties propertiesFromOctoOptions(const OctoOptions& options);
269+
266270
Iterator begin() const
267271
{
268272
return Iterator(orderedFactories.begin());

src/knownfiles.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static KnownRomInfo g_knownRoms[] = {
123123
{"3450e0d92e0bbf8e9d3065fd088cd6dfa5f9441d"_sha1, "chip-8", "Octo Bird (Cody Hoover, 2016)",nullptr, nullptr},
124124
{"346f2760ca55bb6d45b1f255fe4960a7d244191e"_sha1, "vip-chip-8", "Bingo (Andrew Modla)",nullptr, nullptr},
125125
{"35158696bd94ea22ef34e899fff1f15f7154d4fd"_sha1, "chip-8", "Craps (Camerlo Cortez, 1978)",nullptr, nullptr},
126-
{"36363ecdd850dd1a099e272fae6d9b786c2a7d36"_sha1, "xo-chip", "Raycaster (A-KouZ1, 2018)",R"({"instructionsPerFrame":100000,"palette":{"border":"#000000","colors":["#000000","#555555","#aaaaaa","#ffffff"],"signal":"#888888"}})", nullptr},
126+
{"36363ecdd850dd1a099e272fae6d9b786c2a7d36"_sha1, "xo-chip", "Raycaster (A-KouZ1, 2018)",R"({"instructionsPerFrame":50000,"palette":{"border":"#000000","colors":["#000000","#555555","#aaaaaa","#ffffff"],"signal":"#888888"}})", nullptr},
127127
{"3643118e2e237deab98151b742f34caf9533dc05"_sha1, "chip-8", "Mandelbrot Program (A-KouZ1, 2018)",nullptr, nullptr},
128128
{"39970ccfd3a3f00180d53464d4fd7862193eaf0f"_sha1, "chip-8", "Octo: A Chip 8 Story (SystemLogoff, 2015-10-29)",R"({"instructionsPerFrame":7,"palette":{"border":"#222222","colors":["#111111","#eeeeee"],"signal":"#ffff00"}})", nullptr},
129129
{"3a840c33442ad9e912df1fa2aa61833bf571af34"_sha1, "chip-8", "Private Eye (TCNJ S.572.37)",nullptr, nullptr},

0 commit comments

Comments
 (0)