From 279bde6988f2b1906782cb906c1fcdb04eb6b1a2 Mon Sep 17 00:00:00 2001 From: root <182859762@qq.com> Date: Thu, 23 May 2024 21:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BD=BF=E7=94=A8=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=88=B0=E7=9A=84=E5=AD=98=E6=A1=A3=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 +-- .../include/nba/rom/backup/backup_file.hpp | 22 +++++++------- src/wasm/module.cpp | 30 +++++++++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) 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__