Skip to content

Commit

Permalink
higan: fix WonderSwan bios and EEPROM loading
Browse files Browse the repository at this point in the history
The WonderSwan system(s) include a BIOS ROM and EEPROM data. According to the
higan model, this data should be stored in the folder representing a given
system. Previously, higan would try to load those files along with everything
else in the system folder, however at the time System::load() is called we
haven't associated a filesystem path with the system - that's part of the whole
loading process.

Instead, we load that system data at power-on, after the loading process has
sorted out all the filesystem paths we'd need. This matches what the GBA and
ColecoVision cores do.

Hat tip to @LukeUsher for the suggestion.

Fixes higan-emu#160, higan-emu#161.
  • Loading branch information
Screwtapello committed Mar 13, 2021
1 parent 3b4e6c0 commit e51d3c1
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions higan/ws/system/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ auto System::load(Node::Object& root) -> void {
//the model names are confirmed from video recordings of real hardware booting.
//the other settings bytes are based on how the IPLROMs configure the EEPROMs after changing settings.
//none of this can be considered 100% verified; direct EEPROM dumps from new-old stock would be required.
//
//note that these default contents may be overridden later in System::power()
auto initializeName = [&](string name) {
//16-character limit, 'A'-'Z' only!
for(uint index : range(name.size())) {
Expand All @@ -49,10 +51,6 @@ auto System::load(Node::Object& root) -> void {
};

if(WonderSwan::Model::WonderSwan()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(4_KiB);
bootROM.load(fp);
}
eeprom.allocate(128, 16, 0x00);
eeprom.program(0x76, 0x01);
eeprom.program(0x77, 0x00);
Expand All @@ -62,10 +60,6 @@ auto System::load(Node::Object& root) -> void {
}

if(WonderSwan::Model::WonderSwanColor()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(8_KiB);
bootROM.load(fp);
}
eeprom.allocate(2048, 16, 0x00);
eeprom.program(0x76, 0x01);
eeprom.program(0x77, 0x01);
Expand All @@ -79,10 +73,6 @@ auto System::load(Node::Object& root) -> void {
}

if(WonderSwan::Model::SwanCrystal()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(8_KiB);
bootROM.load(fp);
}
eeprom.allocate(2048, 16, 0x00);
//unverified; based on WonderSwan Color IPLROM
eeprom.program(0x76, 0x01);
Expand All @@ -103,17 +93,9 @@ auto System::load(Node::Object& root) -> void {
}

if(WonderSwan::Model::PocketChallengeV2()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(4_KiB);
bootROM.load(fp);
}
//the internal EEPROM has been removed from the Pocket Challenge V2 PCB.
}

if(auto fp = platform->open(node, "save.eeprom", File::Read)) {
fp->read(eeprom.data, eeprom.size);
}

scheduler.reset();
controls.load(node);
cpu.load(node);
Expand Down Expand Up @@ -147,6 +129,42 @@ auto System::unload() -> void {
}

auto System::power() -> void {
// We have to load boot.rom and save.eeprom at power-on,
// because at load-time we don't yet know the filesystem path
// associated with the given node.

if(WonderSwan::Model::WonderSwan()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(4_KiB);
bootROM.load(fp);
}
}

if(WonderSwan::Model::WonderSwanColor()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(8_KiB);
bootROM.load(fp);
}
}

if(WonderSwan::Model::SwanCrystal()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(8_KiB);
bootROM.load(fp);
}
}

if(WonderSwan::Model::PocketChallengeV2()) {
if(auto fp = platform->open(node, "boot.rom", File::Read, File::Required)) {
bootROM.allocate(4_KiB);
bootROM.load(fp);
}
}

if(auto fp = platform->open(node, "save.eeprom", File::Read)) {
fp->read(eeprom.data, eeprom.size);
}

for(auto& setting : node->find<Node::Setting>()) setting->setLatch();

bus.power();
Expand Down

0 comments on commit e51d3c1

Please sign in to comment.