Skip to content

Commit

Permalink
MegaCart support. Partial SGM support(except sound). #11 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Dec 28, 2023
1 parent 48eaab5 commit 7ad976c
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 60 deletions.
3 changes: 3 additions & 0 deletions platforms/desktop-shared/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ static const char* get_mapper(Cartridge::CartridgeTypes type)
case Cartridge::CartridgeColecoVision:
return "ColecoVision";
break;
case Cartridge::CartridgeMegaCart:
return "MegaCart";
break;
case Cartridge::CartridgeNotSupported:
return "Not Supported";
break;
Expand Down
5 changes: 5 additions & 0 deletions platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static void menu_ffwd(void);
static void show_info(void);
static void show_fps(void);
static Cartridge::CartridgeRegions get_region(int index);
//static Cartridge::CartridgeTypes get_mapper(int index);

void gui_init(void)
{
Expand Down Expand Up @@ -1418,6 +1419,10 @@ static void show_fps(void)
// return Cartridge::CartridgeNotSupported;
// case 1:
// return Cartridge::CartridgeColecoVision;
// case 2:
// return Cartridge::CartridgeMegaCart;
// case 3:
// return Cartridge::CartridgeActivisionCart;
// default:
// return Cartridge::CartridgeNotSupported;
// }
Expand Down
29 changes: 26 additions & 3 deletions platforms/desktop-shared/gui_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ static void debug_window_memory(void)
Cartridge* cart = core->GetCartridge();
Video* video = core->GetVideo();

ImGui::PushFont(gui_default_font);

ImGui::TextColored(cyan, " ROM: ");ImGui::SameLine();

ImGui::TextColored(magenta, "BANK");ImGui::SameLine();
ImGui::Text("$%02X", memory->GetRomBank()); ImGui::SameLine();
ImGui::TextColored(magenta, " ADDRESS");ImGui::SameLine();
ImGui::Text("$%05X", memory->GetRomBankAddress());

ImGui::PopFont();

if (ImGui::BeginTabBar("##memory_tabs", ImGuiTabBarFlags_None))
{
if (ImGui::BeginTabItem("BIOS"))
Expand All @@ -213,10 +224,18 @@ static void debug_window_memory(void)
ImGui::EndTabItem();
}

if (ImGui::BeginTabItem("SGM RAM"))
{
ImGui::PushFont(gui_default_font);
mem_edit.DrawContents(memory->GetSGMRam(), 0x8000, 0x0000);
ImGui::PopFont();
ImGui::EndTabItem();
}

if (IsValidPointer(cart->GetROM()) && ImGui::BeginTabItem("ROM"))
{
ImGui::PushFont(gui_default_font);
mem_edit.DrawContents(cart->GetROM(), 0x8000, 0x8000);
mem_edit.DrawContents(cart->GetROM(), cart->GetROMSize(), 0x0000);
ImGui::PopFont();
ImGui::EndTabItem();
}
Expand Down Expand Up @@ -576,11 +595,15 @@ static void debug_window_disassembler(void)
if (show_segment)
{
ImGui::SameLine();
ImGui::TextColored(color_segment, "%s ", vec[item].record->segment);
ImGui::TextColored(color_segment, "%s", vec[item].record->segment);
}

ImGui::SameLine();
ImGui::TextColored(color_addr, "%04X ", vec[item].record->address);
if (strcmp(vec[item].record->segment, "ROM") == 0)
ImGui::TextColored(color_addr, "%02X:%04X ", vec[item].record->bank, vec[item].record->address);
else
ImGui::TextColored(color_addr, " %04X ", vec[item].record->address);


if (show_mem)
{
Expand Down
25 changes: 25 additions & 0 deletions src/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Audio
void SetSampleRate(int rate);
void SetVolume(float volume);
void WriteAudioRegister(u8 value);
void SGMWrite(u8 value);
u8 SGMRead();
void SGMRegister(u8 reg);
void Tick(unsigned int clockCycles);
void EndFrame(s16* pSampleBuffer, int* pSampleCount);
void SaveState(std::ostream& stream);
Expand All @@ -46,6 +49,8 @@ class Audio
int m_iSampleRate;
blip_sample_t* m_pSampleBuffer;
bool m_bPAL;
u8 m_SGMRegister;
u8 m_SGMRegisters[16];
};

inline void Audio::Tick(unsigned int clockCycles)
Expand All @@ -58,4 +63,24 @@ inline void Audio::WriteAudioRegister(u8 value)
m_pApu->write_data(m_ElapsedCycles, value);
}

inline void Audio::SGMWrite(u8 value)
{
uint8_t mask[16] = {
0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0x1F, 0xFF,
0x1F, 0x1F, 0x1F, 0xFF, 0xFF, 0x0F, 0xFF, 0xFF,
};

m_SGMRegisters[m_SGMRegister] = value & mask[m_SGMRegister];
}

inline u8 Audio::SGMRead()
{
return m_SGMRegisters[m_SGMRegister];
}

inline void Audio::SGMRegister(u8 reg)
{
m_SGMRegister = reg & 0x0F;
}

#endif /* AUDIO_H */
61 changes: 44 additions & 17 deletions src/Cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ void Cartridge::ForceConfig(Cartridge::ForceConfiguration config)
m_Type = config.type;
Log("Forcing Mapper: Colecovision");
break;
case Cartridge::CartridgeMegaCart:
m_Type = config.type;
Log("Forcing Mapper: MegaCart");
break;
case Cartridge::CartridgeActivisionCart:
m_Type = config.type;
Log("Forcing Mapper: Activision");
break;
default:
break;
}
Expand Down Expand Up @@ -304,7 +312,9 @@ bool Cartridge::LoadFromBuffer(const u8* buffer, int size)

m_iCRC = CalculateCRC32(0, m_pROM, m_iROMSize);

return GatherMetadata(m_iCRC);
GatherMetadata(m_iCRC);

return true;
}
else
return false;
Expand All @@ -317,45 +327,62 @@ bool Cartridge::GatherMetadata(u32 crc)

Log("ROM Size: %d KB", m_iROMSize / 1024);

m_iROMBankCount = (m_iROMSize / 0x2000) + (m_iROMSize % 0x2000 ? 1 : 0);
m_iROMBankCount = (m_iROMSize / 0x4000) + (m_iROMSize % 0x4000 ? 1 : 0);

Log("ROM Bank Count: %d", m_iROMBankCount);

m_Type = Cartridge::CartridgeNotSupported;

int headerOffset = 0;
u16 header = m_pROM[headerOffset + 1] | (m_pROM[headerOffset + 0] << 8);
m_bValidROM = (header == 0xAA55) || (header == 0x55AA);

if (m_iROMSize > 0x8000)
if (header == 0x6699)
{
Log("Cartridge is probably Mega Cart. ROM size: %d bytes", m_iROMSize);
headerOffset = m_iROMSize - 0x4000;
Log("Cartridge is a Colec Adam expansion ROM. Header: %X", header);
}

u16 header = m_pROM[headerOffset + 1] | (m_pROM[headerOffset + 0] << 8);
m_bValidROM = (header == 0xAA55) || (header == 0x55AA);

if (m_bValidROM)
if (m_bValidROM && (m_iROMSize <= 0x8000))
{
Log("ROM is Valid. Header found: %X", header);
m_Type = Cartridge::CartridgeColecoVision;
Log("Cartridge is Colecovision. ROM size: %d bytes.", m_iROMSize);
}
else
else if (m_bValidROM && (m_iROMSize > 0x8000))
{
Log("ROM is NOT Valid. No header found.");
m_Type = Cartridge::CartridgeActivisionCart;
Log("Cartridge is Mega Cart. ROM size: %d bytes. Banks %d.", m_iROMSize, m_iROMBankCount);
}
else if (!m_bValidROM && (m_iROMSize > 0x8000))
{
headerOffset = m_iROMSize - 0x4000;
header = m_pROM[headerOffset + 1] | (m_pROM[headerOffset + 0] << 8);
m_bValidROM = (header == 0xAA55) || (header == 0x55AA);

if (header == 0x6699)
if (m_bValidROM)
{
m_Type = Cartridge::CartridgeMegaCart;
Log("Cartridge is Mega Cart. ROM size: %d bytes. Banks %d.", m_iROMSize, m_iROMBankCount);
}
}
else
{
Log("Cartridge is a Colec Adam expansion ROM. Header: %X", header);
m_Type = Cartridge::CartridgeNotSupported;
Log("ROM is NOT Valid. No header found.");
}

//m_Type = m_bValidROM ? Cartridge::CartridgeColecoVision : Cartridge::CartridgeNotSupported;
m_Type = Cartridge::CartridgeColecoVision;

GetInfoFromDB(crc);

switch (m_Type)
{
case Cartridge::CartridgeColecoVision:
Log("ColecoVision mapper found");
break;
case Cartridge::CartridgeMegaCart:
Log("MegaCart mapper found");
break;
case Cartridge::CartridgeActivisionCart:
Log("Activision mapper found");
break;
case Cartridge::CartridgeNotSupported:
Log("Cartridge not supported!!");
break;
Expand Down
2 changes: 2 additions & 0 deletions src/Cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Cartridge
enum CartridgeTypes
{
CartridgeColecoVision,
CartridgeMegaCart,
CartridgeActivisionCart,
CartridgeNotSupported
};

Expand Down
32 changes: 31 additions & 1 deletion src/ColecoVisionIOPorts.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ inline u8 ColecoVisionIOPorts::In(u8 port)
{
return m_pInput->ReadInput(port);
}
default:
{
if (port == 0x52)
{
return m_pAudio->SGMRead();
return 0xAA;
}
return 0xFF;
}
}

Log("--> ** Attempting to read from port $%X", port);
Expand Down Expand Up @@ -112,7 +121,28 @@ inline void ColecoVisionIOPorts::Out(u8 port, u8 value)
}
default:
{
Log("--> ** Output to port $%X: %X", port, value);
if (port == 0x50)
{
m_pAudio->SGMRegister(value);
break;
}
else if (port == 0x51)
{
m_pAudio->SGMWrite(value);
break;
}
else if (port == 0x53)
{
m_pMemory->EnableSGMUpper(value & 0x01);
}
else if (port == 0x7F)
{
m_pMemory->EnableSGMLower(~value & 0x02);
}
else
{
Log("--> ** Output to port $%X: %X", port, value);
}
}
}
}
Expand Down
Loading

0 comments on commit 7ad976c

Please sign in to comment.