Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Core/PCE/PceConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ LoadRomResult PceConsole::LoadRom(VirtualFile& romFile)
return LoadRomResult::Failure;
}

if(consoleType == PceConsoleType::Auto && IsSuperGrafxCd(disc)) {
consoleType = PceConsoleType::SuperGrafx;
}

_cdrom.reset(new PceCdRom(_emu, this, disc));
_romFormat = RomFormat::PceCdRom;
cdromUnitEnabled = true;
Expand Down Expand Up @@ -136,6 +140,9 @@ LoadRomResult PceConsole::LoadRom(VirtualFile& romFile)

MessageManager::Log("-----------------");
MessageManager::Log("Loaded: " + romFile.GetFileName());
if(consoleType == PceConsoleType::SuperGrafx && cfg.ConsoleType == PceConsoleType::Auto) {
MessageManager::Log("Enabled SuperGrafx mode (auto-detect)");
}
MessageManager::Log("-----------------");

return LoadRomResult::Success;
Expand All @@ -161,6 +168,25 @@ bool PceConsole::IsPopulousCard(uint32_t crc32)
return crc32 == 0x083C956A;
}

bool PceConsole::IsSuperGrafxCd(DiscInfo& disc)
{
int32_t track = disc.GetFirstDataTrack();
if(track < 0) {
return false;
}

int32_t sector = disc.GetTrackFirstSector(track);
if(sector < 0) {
return false;
}

//Check for custom homebrew marker to automatically enable SuperGrafx mode for CD games
//This should be in the 2nd sector of the first data track, at offset 0x80
vector<uint8_t> sectorData;
disc.ReadDataSector(sector + 1, sectorData);
return memcmp(sectorData.data() + 0x80, "(for SuperGRAFX)", 16) == 0;
}

bool PceConsole::IsSuperGrafxCard(uint32_t crc32)
{
//These are the 5 SuperGrafx-exclusive games
Expand Down
1 change: 1 addition & 0 deletions Core/PCE/PceConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PceConsole final : public IConsole
RomFormat _romFormat = RomFormat::Pce;

static bool IsPopulousCard(uint32_t crc32);
static bool IsSuperGrafxCd(DiscInfo& disc);
static bool IsSuperGrafxCard(uint32_t crc32);

bool LoadHesFile(VirtualFile& hesFile);
Expand Down
11 changes: 11 additions & 0 deletions Core/Shared/CdReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ struct DiscInfo
return -1;
}

int32_t GetFirstDataTrack()
{
for(size_t i = 0; i < Tracks.size(); i++) {
if(Tracks[i].Format != TrackFormat::Audio) {
return (int32_t)i;
}
}
return -1;
}

int32_t GetTrackFirstSector(int32_t track)
{
if(track < Tracks.size()) {
Expand Down Expand Up @@ -135,6 +145,7 @@ struct DiscInfo
uint32_t byteOffset = trk.FileOffset + (sector - trk.FirstSector) * sectorSize;
if(!Files[trk.FileIndex].ReadChunk(outData, byteOffset + sectorHeaderSize, 2048)) {
LogDebug("Invalid read offsets");
outData.insert(outData.end(), 2048, 0);
}
}
}
Expand Down