Skip to content

Commit

Permalink
Add 4 Pak All Action mapper. Fix #115
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 5, 2025
1 parent 6b2523d commit e0763fb
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 1 deletion.
1 change: 1 addition & 0 deletions platforms/desktop-shared/Makefile.sources
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ SOURCES_CXX := \
$(SRC_DIR)/KoreanBFFCMemoryRule.cpp \
$(SRC_DIR)/KoreanFFF3FFFCMemoryRule.cpp \
$(SRC_DIR)/KoreanMDFFF5MemoryRule.cpp \
$(SRC_DIR)/Multi4PAKAllActionMemoryRule.cpp \
$(SRC_DIR)/Memory.cpp \
$(SRC_DIR)/MemoryRule.cpp \
$(SRC_DIR)/MSXMemoryRule.cpp \
Expand Down
1 change: 1 addition & 0 deletions platforms/libretro/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SOURCES_CXX := $(CORE_DIR)/libretro.cpp \
$(SOURCE_DIR)/KoreanBFFCMemoryRule.cpp \
$(SOURCE_DIR)/KoreanFFF3FFFCMemoryRule.cpp \
$(SOURCE_DIR)/KoreanMDFFF5MemoryRule.cpp \
$(SOURCE_DIR)/Multi4PAKAllActionMemoryRule.cpp \
$(SOURCE_DIR)/Memory.cpp \
$(SOURCE_DIR)/MemoryRule.cpp \
$(SOURCE_DIR)/MSXMemoryRule.cpp \
Expand Down
2 changes: 2 additions & 0 deletions platforms/windows/Gearsystem.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<ClCompile Include="..\..\src\KoreanBFFCMemoryRule.cpp" />
<ClCompile Include="..\..\src\KoreanFFF3FFFCMemoryRule.cpp" />
<ClCompile Include="..\..\src\KoreanMDFFF5MemoryRule.cpp" />
<ClCompile Include="..\..\src\Multi4PAKAllActionMemoryRule.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\miniz\miniz.h" />
Expand Down Expand Up @@ -158,6 +159,7 @@
<ClInclude Include="..\..\src\KoreanBFFCMemoryRule.h" />
<ClInclude Include="..\..\src\KoreanFFF3FFFCMemoryRule.h" />
<ClInclude Include="..\..\src\KoreanMDFFF5MemoryRule.h" />
<ClInclude Include="..\..\src\Multi4PAKAllActionMemoryRule.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\desktop-shared\gui_events.def" />
Expand Down
10 changes: 10 additions & 0 deletions src/Cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ void Cartridge::ForceConfig(Cartridge::ForceConfiguration config)
m_Type = config.type;
Log("Forcing Mapper: Janggun");
break;
case Cartridge::CartridgeMulti4PAKAllActionMapper:
m_Type = config.type;
Log("Forcing Mapper: Multi 4PAK All Action");
break;
default:
Log("Not forcing Mapper: Auto");
break;
Expand Down Expand Up @@ -651,6 +655,9 @@ bool Cartridge::GatherMetadata(u32 crc)
case Cartridge::CartridgeJanggunMapper:
Log("Janggun mapper found");
break;
case Cartridge::CartridgeMulti4PAKAllActionMapper:
Log("Multi 4PAK All Action mapper found");
break;
case Cartridge::CartridgeNotSupported:
Log("Cartridge not supported!!");
break;
Expand Down Expand Up @@ -740,6 +747,9 @@ void Cartridge::GetInfoFromDB(u32 crc)
case GS_DB_JANGGUN_MAPPER:
m_Type = Cartridge::CartridgeJanggunMapper;
break;
case GS_DB_MULTI_4PAK_ALL_ACTION_MAPPER:
m_Type = Cartridge::CartridgeMulti4PAKAllActionMapper;
break;
}

if (kGameDatabase[i].features & GS_DB_FEATURE_SMS_MODE)
Expand Down
1 change: 1 addition & 0 deletions src/Cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Cartridge
CartridgeKoreanMDFFF5Mapper,
CartridgeMSXMapper,
CartridgeJanggunMapper,
CartridgeMulti4PAKAllActionMapper,
CartridgeNotSupported
};

Expand Down
8 changes: 8 additions & 0 deletions src/GearsystemCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "KoreanMDFFF5MemoryRule.h"
#include "MSXMemoryRule.h"
#include "JanggunMemoryRule.h"
#include "Multi4PAKAllActionMemoryRule.h"
#include "SG1000MemoryRule.h"
#include "SmsIOPorts.h"
#include "GameGearIOPorts.h"
Expand Down Expand Up @@ -73,6 +74,7 @@ GearsystemCore::GearsystemCore()
InitPointer(m_pKoreanMDFFF5MemoryRule);
InitPointer(m_pMSXMemoryRule);
InitPointer(m_pJanggunMemoryRule);
InitPointer(m_pMulti4PAKAllActionMemoryRule);
InitPointer(m_pSmsIOPorts);
InitPointer(m_pGameGearIOPorts);
InitPointer(m_pBootromMemoryRule);
Expand Down Expand Up @@ -104,6 +106,7 @@ GearsystemCore::~GearsystemCore()
SafeDelete(m_pKoreanMDFFF5MemoryRule);
SafeDelete(m_pMSXMemoryRule);
SafeDelete(m_pJanggunMemoryRule);
SafeDelete(m_pMulti4PAKAllActionMemoryRule);
SafeDelete(m_pCartridge);
SafeDelete(m_pInput);
SafeDelete(m_pVideo);
Expand Down Expand Up @@ -928,6 +931,7 @@ void GearsystemCore::InitMemoryRules()
m_pKoreanMDFFF5MemoryRule = new KoreanMDFFF5MemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pMSXMemoryRule = new MSXMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pJanggunMemoryRule = new JanggunMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pMulti4PAKAllActionMemoryRule = new Multi4PAKAllActionMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pBootromMemoryRule = new BootromMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pMemory->SetCurrentRule(m_pRomOnlyMemoryRule);
m_pMemory->SetBootromRule(m_pBootromMemoryRule);
Expand Down Expand Up @@ -996,6 +1000,9 @@ bool GearsystemCore::AddMemoryRules()
case Cartridge::CartridgeJanggunMapper:
m_pMemory->SetCurrentRule(m_pJanggunMemoryRule);
break;
case Cartridge::CartridgeMulti4PAKAllActionMapper:
m_pMemory->SetCurrentRule(m_pMulti4PAKAllActionMemoryRule);
break;
case Cartridge::CartridgeNotSupported:
notSupported = true;
break;
Expand Down Expand Up @@ -1042,6 +1049,7 @@ void GearsystemCore::Reset()
m_pKoreanMDFFF5MemoryRule->Reset();
m_pMSXMemoryRule->Reset();
m_pJanggunMemoryRule->Reset();
m_pMulti4PAKAllActionMemoryRule->Reset();
m_pBootromMemoryRule->Reset();
m_pGameGearIOPorts->Reset();
m_pSmsIOPorts->Reset();
Expand Down
4 changes: 3 additions & 1 deletion src/GearsystemCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#ifndef CORE_H
#define CORE_H
#define CORE_H

#include "definitions.h"
#include "Cartridge.h"
Expand Down Expand Up @@ -46,6 +46,7 @@ class KoreanFFF3FFFCMemoryRule;
class KoreanMDFFF5MemoryRule;
class MSXMemoryRule;
class JanggunMemoryRule;
class Multi4PAKAllActionMemoryRule;
class MemoryRule;
class SmsIOPorts;
class GameGearIOPorts;
Expand Down Expand Up @@ -135,6 +136,7 @@ class GearsystemCore
KoreanMDFFF5MemoryRule* m_pKoreanMDFFF5MemoryRule;
MSXMemoryRule* m_pMSXMemoryRule;
JanggunMemoryRule* m_pJanggunMemoryRule;
Multi4PAKAllActionMemoryRule* m_pMulti4PAKAllActionMemoryRule;
SmsIOPorts* m_pSmsIOPorts;
GameGearIOPorts* m_pGameGearIOPorts;
BootromMemoryRule* m_pBootromMemoryRule;
Expand Down
131 changes: 131 additions & 0 deletions src/Multi4PAKAllActionMemoryRule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Gearsystem - Sega Master System / Game Gear Emulator
* Copyright (C) 2013 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

#include "Multi4PAKAllActionMemoryRule.h"
#include "Memory.h"
#include "Cartridge.h"

Multi4PAKAllActionMemoryRule::Multi4PAKAllActionMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput) : MemoryRule(pMemory, pCartridge, pInput)
{
Reset();
}

Multi4PAKAllActionMemoryRule::~Multi4PAKAllActionMemoryRule()
{
}

u8 Multi4PAKAllActionMemoryRule::PerformRead(u16 address)
{
if (address < 0xC000)
{
int slot = (address >> 14) & 0x03;
if (slot > 3)
{
Debug("--> ** Invalid slot %d", slot);
return 0xFF;
}
return m_pCartridge->GetROM()[m_iMapperSlotAddress[slot] + (address & 0x3FFF)];
}
else
{
// RAM + RAM mirror
return m_pMemory->Retrieve(address);
}
}

void Multi4PAKAllActionMemoryRule::PerformWrite(u16 address, u8 value)
{
if (address < 0xC000)
{
switch (address)
{
case 0x3FFE:
Debug("--> ** Writing to register $%X %X", address, value);
m_iMapperSlot[0] = value;
m_iMapperSlotAddress[0] = 0x4000 * (m_iMapperSlot[0] & (m_pCartridge->GetROMBankCount() - 1));
return;
case 0x7FFF:
Debug("--> ** Writing to register $%X %X", address, value);
m_iMapperSlot[1] = value;
m_iMapperSlotAddress[1] = 0x4000 * (m_iMapperSlot[1] & (m_pCartridge->GetROMBankCount() - 1));
return;
case 0xBFFF:
Debug("--> ** Writing to register $%X %X", address, value);
m_iMapperSlot[2] = value;
m_iMapperSlotAddress[2] = 0x4000 * (((m_iMapperSlot[0] & 0x30) + value) & (m_pCartridge->GetROMBankCount() - 1));
return;
default:
Debug("--> ** Attempting to write on ROM address $%X %X", address, value);
return;
}
}
else if (address < 0xE000)
{
// RAM
m_pMemory->Load(address, value);
m_pMemory->Load(address + 0x2000, value);
}
else
{
// RAM (mirror)
m_pMemory->Load(address, value);
m_pMemory->Load(address - 0x2000, value);
}
}

void Multi4PAKAllActionMemoryRule::Reset()
{
m_iMapperSlot[0] = 0;
m_iMapperSlot[1] = 1;
m_iMapperSlot[2] = 2;

m_iMapperSlotAddress[0] = 0x0000;
m_iMapperSlotAddress[1] = 0x4000;
m_iMapperSlotAddress[2] = 0x8000;
}

u8* Multi4PAKAllActionMemoryRule::GetPage(int index)
{
if (index < 0 || index > 2)
return m_pCartridge->GetROM();

return m_pCartridge->GetROM() + (m_iMapperSlot[index] * 0x4000);
}

int Multi4PAKAllActionMemoryRule::GetBank(int index)
{
if (index < 0 || index > 2)
return 0;

return m_iMapperSlot[index];
}

void Multi4PAKAllActionMemoryRule::SaveState(std::ostream& stream)
{
stream.write(reinterpret_cast<const char*> (m_iMapperSlotAddress), sizeof(m_iMapperSlotAddress));
stream.write(reinterpret_cast<const char*> (m_iMapperSlot), sizeof(m_iMapperSlot));
}

void Multi4PAKAllActionMemoryRule::LoadState(std::istream& stream)
{
using namespace std;

stream.read(reinterpret_cast<char*> (m_iMapperSlotAddress), sizeof(m_iMapperSlotAddress));
stream.read(reinterpret_cast<char*> (m_iMapperSlot), sizeof(m_iMapperSlot));
}
43 changes: 43 additions & 0 deletions src/Multi4PAKAllActionMemoryRule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Gearsystem - Sega Master System / Game Gear Emulator
* Copyright (C) 2013 Ignacio Sanchez
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
*
*/

#ifndef MULTI4PAKALLACTIONMEMORYRULE_H
#define MULTI4PAKALLACTIONMEMORYRULE_H

#include "MemoryRule.h"

class Multi4PAKAllActionMemoryRule : public MemoryRule
{
public:
Multi4PAKAllActionMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput);
virtual ~Multi4PAKAllActionMemoryRule();
virtual u8 PerformRead(u16 address);
virtual void PerformWrite(u16 address, u8 value);
virtual void Reset();
virtual u8* GetPage(int index);
virtual int GetBank(int index);
virtual void SaveState(std::ostream& stream);
virtual void LoadState(std::istream& stream);

private:
int m_iMapperSlot[3];
int m_iMapperSlotAddress[3];
};

#endif /* MULTI4PAKALLACTIONMEMORYRULE_H */
3 changes: 3 additions & 0 deletions src/game_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define GS_DB_KOREAN_BFFC_MAPPER 14
#define GS_DB_KOREAN_FFF3_FFFC_MAPPER 15
#define GS_DB_KOREAN_MD_FFF5_MAPPER 16
#define GS_DB_MULTI_4PAK_ALL_ACTION_MAPPER 17

#define GS_DB_FEATURE_NONE 0x00
#define GS_DB_FEATURE_PAL 0x01
Expand Down Expand Up @@ -407,6 +408,8 @@ const GS_GameDBEntry kGameDatabase[] =
{0x7F667485, GS_DB_KOREAN_MD_FFF5_MAPPER, GS_DB_FEATURE_NONE, "Mega Mode Super Game 138"},
{0xC0AC6956, GS_DB_KOREAN_MD_FFF5_MAPPER, GS_DB_FEATURE_NONE, "Pigu-Wang 7 Hap - Jaemiiss-neun Game Mo-eumjip"},

{0xA67F2A5C, GS_DB_MULTI_4PAK_ALL_ACTION_MAPPER, GS_DB_FEATURE_NONE, "4 PAK All Action"},

// Requires vint flag on boot
{0xD9096263, GS_DB_DEFAULT_MAPPER, GS_DB_FEATURE_INITIAL_VINT, "Sonic's Edusoft [Proto]"},

Expand Down

0 comments on commit e0763fb

Please sign in to comment.