更新使用检测到的存档类型重启游戏

This commit is contained in:
root 2024-05-23 21:49:33 +08:00
parent 9f25b321d9
commit 279bde6988
3 changed files with 43 additions and 13 deletions

View File

@ -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 \

View File

@ -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* {

View File

@ -175,6 +175,36 @@ void go( u32 framecount, u32 input )
run(framecount * cyclePerFrame(), input);
}
void replay()
{
// new backup
auto backup = std::unique_ptr<nba::Backup>{};
auto gpio = std::unique_ptr<nba::GPIO>{};
if( backup_value[0] == 0 ) return;
vm->Reset();
if( backup_value[0] == 1 )
{
backup = std::make_unique<nba::SRAM>( fs::path{"/"} );
}
else if( backup_value[0] == 2 )
{
backup = std::make_unique<nba::FLASH>( 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<nba::EEPROM>( 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<u8>(game_data, game_data+data_size), std::move(backup), std::move(gpio), 0xffff'ffff) );
vm->Reset();
}
}
#if __EMSCRIPTEN__