diff --git a/Makefile b/Makefile index 95a9007..fb02c44 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ CC := emcc CXX := emcc -CXXFLAGS := -c -fbracket-depth=4800 -O3 -std=c++17 -D NDEBUG=1 -msimd128 +CXXFLAGS := -c -fbracket-depth=4800 -O3 -std=c++17 -msimd128 INCLUDES := -I src/nba/include/ -I src/nba/src LDFLAGS := -s ENVIRONMENT=web -s ASSERTIONS=0 -s FILESYSTEM=0 -s STANDALONE_WASM=1 -s ALLOW_MEMORY_GROWTH\ - -s EXPORTED_FUNCTIONS=[_getOutput,_cyclePerFrame,_getRom,_getIRam,_getWRam,_go,_run,_main] --lto + -s EXPORTED_FUNCTIONS=[_replay,_getOutput,_cyclePerFrame,_getRom,_getIRam,_getWRam,_go,_run,_main] --lto BUILD := build OBJECTS := $(BUILD)/000-serialization.o $(BUILD)/001-tablegen.o $(BUILD)/002-bus.o \ $(BUILD)/003-io.o $(BUILD)/004-serialization.o $(BUILD)/005-timing.o \ diff --git a/src/nba/include/nba/rom/backup/backup_file.hpp b/src/nba/include/nba/rom/backup/backup_file.hpp index 6ba8cdf..9f472fb 100644 --- a/src/nba/include/nba/rom/backup/backup_file.hpp +++ b/src/nba/include/nba/rom/backup/backup_file.hpp @@ -40,14 +40,14 @@ struct BackupFile { auto end = valid_sizes.end(); if(std::find(begin, end, save_size) != end) { - file->stream.open(save_path.c_str(), flags); - if(file->stream.fail()) { - throw std::runtime_error("BackupFile: unable to open file: " + save_path.string()); - } + // file->stream.open(save_path.c_str(), flags); + // if(file->stream.fail()) { + // throw std::runtime_error("BackupFile: unable to open file: " + save_path.string()); + // } default_size = save_size; file->save_size = save_size; file->memory.reset(new u8[file_size]); - file->stream.read((char*)file->memory.get(), file_size); + // file->stream.read((char*)file->memory.get(), file_size); create = false; } } @@ -57,10 +57,10 @@ struct BackupFile { */ if(create) { file->save_size = default_size; - file->stream.open(save_path, flags | std::ios::trunc); - if(file->stream.fail()) { - throw std::runtime_error("BackupFile: unable to create file: " + save_path.string()); - } + // file->stream.open(save_path, flags | std::ios::trunc); + // if(file->stream.fail()) { + // throw std::runtime_error("BackupFile: unable to create file: " + save_path.string()); + // } file->memory.reset(new u8[default_size]); file->MemorySet(0, default_size, 0xFF); } @@ -99,8 +99,8 @@ struct BackupFile { if((index + length) > save_size) { throw std::runtime_error("BackupFile: out-of-bounds index while updating file."); } - stream.seekg(index); - stream.write((char*)&memory[index], length); + // stream.seekg(index); + // stream.write((char*)&memory[index], length); } auto Buffer() -> u8* { diff --git a/src/wasm/module.cpp b/src/wasm/module.cpp index d51adf6..7be7a9a 100644 --- a/src/wasm/module.cpp +++ b/src/wasm/module.cpp @@ -175,6 +175,36 @@ void go( u32 framecount, u32 input ) run(framecount * cyclePerFrame(), input); } +void replay() +{ + // new backup + auto backup = std::unique_ptr{}; + auto gpio = std::unique_ptr{}; + + if( backup_value[0] == 0 ) return; + + vm->Reset(); + if( backup_value[0] == 1 ) + { + backup = std::make_unique( fs::path{"/"} ); + } + else if( backup_value[0] == 2 ) + { + backup = std::make_unique( fs::path{"/"}, backup_value[1] > 64*1024 ? nba::FLASH::Size::SIZE_128K : nba::FLASH::Size::SIZE_128K ); + } + else if( backup_value[0] == 3 ) + { + backup = std::make_unique( fs::path{"/"}, backup_value[1] > 8*1024 ? nba::EEPROM::Size::SIZE_64K : nba::EEPROM::Size::SIZE_4K, vm->GetScheduler() ); + } + + if( backup_value[2] ){ + gpio->Attach( vm->CreateRTC() ); + } + + vm->Attach( nba::ROM(std::vector(game_data, game_data+data_size), std::move(backup), std::move(gpio), 0xffff'ffff) ); + vm->Reset(); +} + } #if __EMSCRIPTEN__