Unverified Commit fa1e2dd7 authored by Ignacio Sanchez Gines's avatar Ignacio Sanchez Gines
Browse files

Add support for choosing eye in 3D games (glasses). #43

parent b8a1d1ee
Pipeline #40983 failed with stages
in 1 minute and 40 seconds
......@@ -135,6 +135,7 @@ void config_read(void)
config_video.scanlines = read_bool("Video", "Scanlines", true);
config_video.scanlines_intensity = read_float("Video", "ScanlinesIntensity", 0.40f);
config_video.sync = read_bool("Video", "Sync", true);
config_video.glasses = read_int("Video", "3DGlasses", 0);
config_audio.enable = read_bool("Audio", "Enable", true);
config_audio.sync = read_bool("Audio", "Sync", true);
......@@ -219,6 +220,7 @@ void config_write(void)
write_bool("Video", "Scanlines", config_video.scanlines);
write_float("Video", "ScanlinesIntensity", config_video.scanlines_intensity);
write_bool("Video", "Sync", config_video.sync);
write_int("Video", "3DGlasses", config_video.glasses);
write_bool("Audio", "Enable", config_audio.enable);
write_bool("Audio", "Sync", config_audio.sync);
......
......@@ -66,6 +66,7 @@ struct config_Video
bool scanlines = true;
float scanlines_intensity = 0.40f;
bool sync = true;
int glasses = 0;
};
struct config_Audio
......
......@@ -331,26 +331,44 @@ void emu_enable_bootrom_gg(bool enable)
void emu_set_media_slot(int slot)
{
Memory::MediaSlots media_slot = Memory::MediaSlots::CartridgeSlot;
Memory::MediaSlots media_slot = Memory::CartridgeSlot;
switch (slot)
{
case 1:
media_slot = Memory::MediaSlots::CardSlot;
media_slot = Memory::CardSlot;
break;
case 2:
media_slot = Memory::MediaSlots::ExpansionSlot;
media_slot = Memory::ExpansionSlot;
break;
case 3:
media_slot = Memory::MediaSlots::NoSlot;
media_slot = Memory::NoSlot;
break;
default:
media_slot = Memory::MediaSlots::CartridgeSlot;
media_slot = Memory::CartridgeSlot;
}
gearsystem->GetMemory()->SetMediaSlot(media_slot);
}
void emu_set_3d_glasses_config(int config)
{
GearsystemCore::GlassesConfig glasses = GearsystemCore::GlassesBothEyes;
switch (config)
{
case 1:
glasses = GearsystemCore::GlassesLeftEye;
break;
case 2:
glasses = GearsystemCore::GlassesRightEye;
break;
default:
glasses = GearsystemCore::GlassesBothEyes;
}
gearsystem->SetGlassesConfig(glasses);
}
static void save_ram(void)
{
#ifdef DEBUG_GEARSYSTEM
......
......@@ -73,6 +73,7 @@ EXTERN void emu_load_bootrom_gg(const char* file_path);
EXTERN void emu_enable_bootrom_sms(bool enable);
EXTERN void emu_enable_bootrom_gg(bool enable);
EXTERN void emu_set_media_slot(int slot);
EXTERN void emu_set_3d_glasses_config(int config);
#undef EMU_IMPORT
#undef EXTERN
......
......@@ -570,6 +570,19 @@ static void main_menu(void)
ImGui::EndMenu();
}
ImGui::Separator();
if (ImGui::BeginMenu("3D Glasses"))
{
ImGui::PushItemWidth(160.0f);
if (ImGui::Combo("##glasess", &config_video.glasses, "Both Eyes / OFF\0Only Left Eye\0Only Right Eye\0\0"))
{
emu_set_3d_glasses_config(config_video.glasses);
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}
ImGui::EndMenu();
}
......
......@@ -55,6 +55,7 @@ static bool libretro_supports_bitmasks;
static GearsystemCore* core;
static u8* frame_buffer;
static Cartridge::ForceConfiguration config;
static GearsystemCore::GlassesConfig glasses_config;
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
......@@ -72,6 +73,7 @@ static const struct retro_variable vars[] = {
{ "gearsystem_timing", "Refresh Rate (restart); Auto|NTSC (60 Hz)|PAL (50 Hz)" },
{ "gearsystem_bios_sms", "Master System BIOS (restart); Disabled|Enabled" },
{ "gearsystem_bios_gg", "Game Gear BIOS (restart); Disabled|Enabled" },
{ "gearsystem_glasses", "3D Glasses; Both Eyes / OFF|Left Eye|Right Eye" },
{ "gearsystem_up_down_allowed", "Allow Up+Down / Left+Right; Disabled|Enabled" },
{ NULL }
};
......@@ -106,6 +108,8 @@ void retro_init(void)
config.region = Cartridge::CartridgeUnknownRegion;
config.system = Cartridge::CartridgeUnknownSystem;
glasses_config = GearsystemCore::GlassesBothEyes;
libretro_supports_bitmasks = environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL);
}
......@@ -395,6 +399,23 @@ static void check_variables(void)
else
bootrom_gg = false;
}
var.key = "gearsystem_glasses";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "Both Eyes / OFF") == 0)
glasses_config = GearsystemCore::GlassesBothEyes;
else if (strcmp(var.value, "Left Eye") == 0)
glasses_config = GearsystemCore::GlassesLeftEye;
else if (strcmp(var.value, "Right Eye") == 0)
glasses_config = GearsystemCore::GlassesRightEye;
else
glasses_config = GearsystemCore::GlassesBothEyes;
core->SetGlassesConfig(glasses_config);
}
}
void retro_run(void)
......
......@@ -21,7 +21,7 @@
#include "Memory.h"
#include "Cartridge.h"
BootromMemoryRule::BootromMemoryRule(Memory* pMemory, Cartridge* pCartridge) : MemoryRule(pMemory, pCartridge)
BootromMemoryRule::BootromMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput) : MemoryRule(pMemory, pCartridge, pInput)
{
Reset();
}
......
......@@ -25,7 +25,7 @@
class BootromMemoryRule : public MemoryRule
{
public:
BootromMemoryRule(Memory* pMemory, Cartridge* pCartridge);
BootromMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput);
virtual ~BootromMemoryRule();
virtual u8 PerformRead(u16 address);
virtual void PerformWrite(u16 address, u8 value);
......
......@@ -21,7 +21,7 @@
#include "Memory.h"
#include "Cartridge.h"
CodemastersMemoryRule::CodemastersMemoryRule(Memory* pMemory, Cartridge* pCartridge) : MemoryRule(pMemory, pCartridge)
CodemastersMemoryRule::CodemastersMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput) : MemoryRule(pMemory, pCartridge, pInput)
{
m_pCartRAM = new u8[0x2000];
Reset();
......
......@@ -25,7 +25,7 @@
class CodemastersMemoryRule : public MemoryRule
{
public:
CodemastersMemoryRule(Memory* pMemory, Cartridge* pCartridge);
CodemastersMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput);
virtual ~CodemastersMemoryRule();
virtual u8 PerformRead(u16 address);
virtual void PerformWrite(u16 address, u8 value);
......
......@@ -54,6 +54,7 @@ GearsystemCore::GearsystemCore()
InitPointer(m_pBootromMemoryRule);
m_bPaused = true;
m_pixelFormat = GS_PIXEL_RGB888;
m_GlassesConfig = GlassesConfig::GlassesBothEyes;
}
GearsystemCore::~GearsystemCore()
......@@ -283,6 +284,11 @@ Video* GearsystemCore::GetVideo()
return m_pVideo;
}
void GearsystemCore::SetGlassesConfig(GlassesConfig config)
{
m_GlassesConfig = config;
}
void GearsystemCore::KeyPressed(GS_Joypads joypad, GS_Keys key)
{
m_pInput->KeyPressed(joypad, key);
......@@ -826,13 +832,13 @@ void GearsystemCore::SetRamModificationCallback(RamChangedCallback callback)
void GearsystemCore::InitMemoryRules()
{
m_pSG1000MemoryRule = new SG1000MemoryRule(m_pMemory, m_pCartridge);
m_pCodemastersMemoryRule = new CodemastersMemoryRule(m_pMemory, m_pCartridge);
m_pSegaMemoryRule = new SegaMemoryRule(m_pMemory, m_pCartridge);
m_pRomOnlyMemoryRule = new RomOnlyMemoryRule(m_pMemory, m_pCartridge);
m_pKoreanMemoryRule = new KoreanMemoryRule(m_pMemory, m_pCartridge);
m_pMSXMemoryRule = new MSXMemoryRule(m_pMemory, m_pCartridge);
m_pBootromMemoryRule = new BootromMemoryRule(m_pMemory, m_pCartridge);
m_pSG1000MemoryRule = new SG1000MemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pCodemastersMemoryRule = new CodemastersMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pSegaMemoryRule = new SegaMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pRomOnlyMemoryRule = new RomOnlyMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pKoreanMemoryRule = new KoreanMemoryRule(m_pMemory, m_pCartridge, m_pInput);
m_pMSXMemoryRule = new MSXMemoryRule(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);
......@@ -909,6 +915,16 @@ void GearsystemCore::RenderFrameBuffer(u8* finalFrameBuffer)
{
int size = GS_RESOLUTION_MAX_WIDTH * GS_RESOLUTION_MAX_HEIGHT;
if (m_GlassesConfig != GlassesConfig::GlassesBothEyes)
{
bool left = IsSetBit(m_pInput->GetGlassesRegistry(), 0);
if ((m_GlassesConfig == GlassesConfig::GlassesLeftEye) && !left)
return;
else if ((m_GlassesConfig == GlassesConfig::GlassesRightEye) && left)
return;
}
switch (m_pixelFormat)
{
case GS_PIXEL_RGB555:
......
......@@ -41,6 +41,14 @@ class BootromMemoryRule;
class GearsystemCore
{
public:
enum GlassesConfig
{
GlassesBothEyes,
GlassesLeftEye,
GlassesRightEye
};
public:
GearsystemCore();
~GearsystemCore();
......@@ -80,6 +88,7 @@ public:
Processor* GetProcessor();
Audio* GetAudio();
Video* GetVideo();
void SetGlassesConfig(GlassesConfig config);
private:
void InitMemoryRules();
......@@ -106,6 +115,7 @@ private:
bool m_bPaused;
RamChangedCallback m_pRamChangedCallback;
GS_Color_Format m_pixelFormat;
GlassesConfig m_GlassesConfig;
};
#endif /* CORE_H */
......@@ -46,6 +46,7 @@ void Input::Reset(bool bGameGear)
m_IOPortDC = 0xFF;
m_IOPortDD = 0xFF;
m_IOPort00 = 0xFF;
m_GlassesRegistry = 0;
m_iInputCycles = 0;
}
......@@ -96,6 +97,16 @@ u8 Input::GetPort00()
return m_IOPort00;
}
u8 Input::GetGlassesRegistry()
{
return m_GlassesRegistry;
}
void Input::SetGlassesRegistry(u8 value)
{
m_GlassesRegistry = value;
}
void Input::Update()
{
m_IOPortDC = (m_Joypad1 & 0x3F) + ((m_Joypad2 << 6) & 0xC0);
......
......@@ -37,6 +37,8 @@ public:
u8 GetPortDC();
u8 GetPortDD();
u8 GetPort00();
u8 GetGlassesRegistry();
void SetGlassesRegistry(u8 value);
void SaveState(std::ostream& stream);
void LoadState(std::istream& stream);
......@@ -50,6 +52,7 @@ private:
u8 m_IOPortDC;
u8 m_IOPortDD;
u8 m_IOPort00;
u8 m_GlassesRegistry;
int m_iInputCycles;
bool m_bGameGear;
};
......
......@@ -21,7 +21,7 @@
#include "Memory.h"
#include "Cartridge.h"
KoreanMemoryRule::KoreanMemoryRule(Memory* pMemory, Cartridge* pCartridge) : MemoryRule(pMemory, pCartridge)
KoreanMemoryRule::KoreanMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput) : MemoryRule(pMemory, pCartridge, pInput)
{
Reset();
}
......
......@@ -25,7 +25,7 @@
class KoreanMemoryRule : public MemoryRule
{
public:
KoreanMemoryRule(Memory* pMemory, Cartridge* pCartridge);
KoreanMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput);
virtual ~KoreanMemoryRule();
virtual u8 PerformRead(u16 address);
virtual void PerformWrite(u16 address, u8 value);
......
......@@ -21,7 +21,7 @@
#include "Memory.h"
#include "Cartridge.h"
MSXMemoryRule::MSXMemoryRule(Memory* pMemory, Cartridge* pCartridge) : MemoryRule(pMemory, pCartridge)
MSXMemoryRule::MSXMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput) : MemoryRule(pMemory, pCartridge, pInput)
{
Reset();
}
......
......@@ -25,7 +25,7 @@
class MSXMemoryRule : public MemoryRule
{
public:
MSXMemoryRule(Memory* pMemory, Cartridge* pCartridge);
MSXMemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput);
virtual ~MSXMemoryRule();
virtual u8 PerformRead(u16 address);
virtual void PerformWrite(u16 address, u8 value);
......
......@@ -19,10 +19,11 @@
#include "MemoryRule.h"
MemoryRule::MemoryRule(Memory* pMemory, Cartridge* pCartridge)
MemoryRule::MemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput)
{
m_pMemory = pMemory;
m_pCartridge = pCartridge;
m_pInput = pInput;
}
MemoryRule::~MemoryRule()
......
......@@ -24,11 +24,12 @@
class Memory;
class Cartridge;
class Input;
class MemoryRule
{
public:
MemoryRule(Memory* pMemory, Cartridge* pCartridge);
MemoryRule(Memory* pMemory, Cartridge* pCartridge, Input* pInput);
virtual ~MemoryRule();
virtual u8 PerformRead(u16 address) = 0;
virtual void PerformWrite(u16 address, u8 value) = 0;
......@@ -48,6 +49,7 @@ public:
protected:
Memory* m_pMemory;
Cartridge* m_pCartridge;
Input* m_pInput;
RamChangedCallback m_pRamChangedCallback;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment