Skip to content

Commit

Permalink
GG: Fixed freeze at boot in BIOS code (when a bios is provided)
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed Dec 26, 2024
1 parent eed94fd commit 1063146
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
12 changes: 8 additions & 4 deletions Core/SMS/SmsBiosMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ void SmsBiosMapper::WriteRegister(uint16_t addr, uint8_t value)
}
}

void SmsBiosMapper::RefreshMappings()
void SmsBiosMapper::RefreshMappings(bool cartridgeEnabled)
{
_memoryManager->MapRegisters(0xFFFD, 0xFFFF, SmsRegisterAccess::Write);

_memoryManager->Map(0x0000, 0x3FFF, MemoryType::SmsBootRom, _prgBanks[0] * 0x4000, true);
if(!cartridgeEnabled) {
_memoryManager->Map(0x0000, 0x3FFF, MemoryType::SmsBootRom, _prgBanks[0] * 0x4000, true);
}

//First 1kb is fixed?
_memoryManager->Map(0x0000, 0x03FF, MemoryType::SmsBootRom, 0, true);

_memoryManager->Map(0x4000, 0x7FFF, MemoryType::SmsBootRom, _prgBanks[1] * 0x4000, true);
_memoryManager->Map(0x8000, 0xBFFF, MemoryType::SmsBootRom, _prgBanks[2] * 0x4000, true);
if(!cartridgeEnabled) {
_memoryManager->Map(0x4000, 0x7FFF, MemoryType::SmsBootRom, _prgBanks[1] * 0x4000, true);
_memoryManager->Map(0x8000, 0xBFFF, MemoryType::SmsBootRom, _prgBanks[2] * 0x4000, true);
}
}

void SmsBiosMapper::Serialize(Serializer& s)
Expand Down
2 changes: 1 addition & 1 deletion Core/SMS/SmsBiosMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SmsBiosMapper final : public ISerializable
SmsBiosMapper(SmsMemoryManager* memoryManager);

void WriteRegister(uint16_t addr, uint8_t value);
void RefreshMappings();
void RefreshMappings(bool cartridgeEnabled);

void Serialize(Serializer& s) override;
};
28 changes: 19 additions & 9 deletions Core/SMS/SmsMemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ void SmsMemoryManager::Init(Emulator* emu, SmsConsole* console, vector<uint8_t>&
_state.WorkRamEnabled = true;
_state.IoEnabled = true;

//Power on values unverified, probably incorrect?
_state.GgExtConfig = 0x7F;
_state.GgExtData = 0xFF;

RefreshMappings();
}

Expand Down Expand Up @@ -129,7 +133,8 @@ void SmsMemoryManager::RefreshMappings()
}

if(_biosMapper && _state.BiosEnabled && (_model == SmsModel::GameGear || !_state.CartridgeEnabled)) {
_biosMapper->RefreshMappings();
bool enableCart = _model == SmsModel::GameGear;
_biosMapper->RefreshMappings(enableCart);
}
}
}
Expand Down Expand Up @@ -386,11 +391,11 @@ void SmsMemoryManager::WriteGameGearPort(uint8_t port, uint8_t value)
case 0: break; //read-only

//TODOSMS GG - input/output ext port
case 1: break;
case 2: break;
case 3: break;
case 1: _state.GgExtData = value & 0x7F; break;
case 2: _state.GgExtConfig = value; break;
case 3: _state.GgSendData = value; break;
case 4: break; //read-only
case 5: break;
case 5: _state.GgSerialConfig = value; break;

//Sound panning - write-only
case 6:
Expand Down Expand Up @@ -457,11 +462,11 @@ uint8_t SmsMemoryManager::ReadGameGearPort(uint8_t port)
}

//TODOSMS GG - input/output ext port
case 1: return 0x7F;
case 2: return 0xFF;
case 3: return 0x00;
case 1: return _state.GgExtData;
case 2: return _state.GgExtConfig;
case 3: return _state.GgSendData;
case 4: return 0xFF;
case 5: return 0x00;
case 5: return _state.GgSerialConfig;

//Sound panning - write-only
case 6: return 0xFF;
Expand Down Expand Up @@ -532,6 +537,11 @@ void SmsMemoryManager::Serialize(Serializer& s)
SV(_state.BiosEnabled);
SV(_state.IoEnabled);

SV(_state.GgExtData);
SV(_state.GgExtConfig);
SV(_state.GgSendData);
SV(_state.GgSerialConfig);

if(_cartRamSize > 0) {
SVArray(_cartRam, _cartRamSize);
}
Expand Down
4 changes: 4 additions & 0 deletions Core/SMS/SmsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ struct SmsMemoryManagerState
bool IsWriteRegister[0x100];

uint8_t OpenBus;
uint8_t GgExtData;
uint8_t GgExtConfig;
uint8_t GgSendData;
uint8_t GgSerialConfig;

bool ExpEnabled;
bool CartridgeEnabled;
Expand Down
4 changes: 4 additions & 0 deletions UI/Interop/ConsoleState/SmsState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ public struct SmsMemoryManagerState
public byte[] IsWriteRegister;

public byte OpenBus;
public byte GgExtData;
public byte GgExtConfig;
public byte GgSendData;
public byte GgSerialConfig;

[MarshalAs(UnmanagedType.I1)] public bool ExpEnabled;
[MarshalAs(UnmanagedType.I1)] public bool CartridgeEnabled;
Expand Down
2 changes: 1 addition & 1 deletion UI/Utilities/FileDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class FileDialogHelper
filter.Add(new FilePickerFileType("ColecoVision ROM files") { Patterns = new List<string>() { "*.col" } });
filter.Add(new FilePickerFileType("WonderSwan ROM files") { Patterns = new List<string>() { "*.ws", "*.wsc" } });
} else if(ext == FileDialogHelper.FirmwareExt) {
filter.Add(new FilePickerFileType("All firmware files") { Patterns = new List<string>() { "*.sfc", "*.pce", "*.nes", "*.bin", "*.rom", "*.col", "*.sms", "*.gba" } });
filter.Add(new FilePickerFileType("All firmware files") { Patterns = new List<string>() { "*.sfc", "*.pce", "*.nes", "*.bin", "*.rom", "*.col", "*.sms", "*.gg", "*.gba" } });
} else if(ext == FileDialogHelper.LabelFileExt) {
filter.Add(new FilePickerFileType("All label files") { Patterns = new List<string>() { "*.mlb", "*.sym", "*.dbg", "*.fns", "*.elf", "*.cdb" } });
} else {
Expand Down

0 comments on commit 1063146

Please sign in to comment.