Expose some variable to retroarch.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-12-28 15:04:24 +00:00
parent 2c9e4561df
commit 87ddb8033f
5 changed files with 172 additions and 12 deletions

View file

@ -16,6 +16,7 @@ if (EXISTS ${LIBRETRO_COMMON_PATH}/include/libretro.h)
joypad.cpp
analog.cpp
rdirectsound.cpp
retroregistry.cpp
)
target_include_directories(applewin_libretro PRIVATE

View file

@ -1,5 +1,6 @@
#include "StdAfx.h"
#include "frontends/libretro/game.h"
#include "frontends/libretro/retroregistry.h"
#include "Common.h"
#include "CardManager.h"
@ -14,9 +15,8 @@
#include "Interface.h"
#include "linux/keyboard.h"
#include "linux/registry.h"
#include "linux/paddle.h"
#include "frontends/common2/programoptions.h"
#include "frontends/common2/fileregistry.h"
#include "frontends/common2/utils.h"
#include "libretro.h"
@ -32,21 +32,14 @@ namespace
}
unsigned Game::input_devices[MAX_PADS] = {0};
unsigned Game::ourInputDevices[MAX_PADS] = {RETRO_DEVICE_NONE};
Game::Game()
: mySpeed(true), myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1)
{
EmulatorOptions options;
options.memclear = g_nMemoryClearType;
options.log = true;
LogInit();
InitialiseRetroRegistry();
if (options.log)
{
LogInit();
}
InitializeFileRegistry(options);
initialiseEmulator();
myBorderlessWidth = GetFrameBufferBorderlessWidth();

View file

@ -14,6 +14,7 @@
#include "frontends/libretro/joypad.h"
#include "frontends/libretro/analog.h"
#include "frontends/libretro/rdirectsound.h"
#include "frontends/libretro/retroregistry.h"
namespace
{
@ -138,6 +139,8 @@ void retro_set_environment(retro_environment_t cb)
retro_frame_time_callback timeCallback = {&Game::frameTimeCallback, 1000000 / Game::FPS};
cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, &timeCallback);
SetupRetroVariables();
}
void retro_set_audio_sample(retro_audio_sample_t cb)

View file

@ -0,0 +1,159 @@
#include "StdAfx.h"
#include "frontends/common2/ptreeregistry.h"
#include "frontends/libretro/environment.h"
#include "Common.h"
#include "Card.h"
#include "Video.h"
#include "libretro.h"
#include <list>
#include <vector>
#include <sstream>
namespace
{
const std::string ourScope = "applewin_";
struct Variable
{
std::string name;
std::string description;
std::string section;
std::string key;
std::vector<std::pair<std::string, DWORD> > values;
};
const std::vector<Variable> ourVariables =
{
{
"machine",
"Apple ][ type",
"Configuration",
"Apple2 Type",
{
{"Enhanced Apple //e", A2TYPE_APPLE2EENHANCED},
{"Apple ][ (Original)", A2TYPE_APPLE2},
{"Apple ][+", A2TYPE_APPLE2PLUS},
{"Apple ][ J-Plus", A2TYPE_APPLE2JPLUS},
{"Apple //e", A2TYPE_APPLE2E},
{"Pravets 82", A2TYPE_PRAVETS82},
{"Pravets 8M", A2TYPE_PRAVETS8M},
{"Pravets 8A", A2TYPE_PRAVETS8A},
{"Base64A", A2TYPE_BASE64A},
{"TK3000 //e", A2TYPE_TK30002E},
}
},
{
"slot4",
"Card in slot 4",
"Configuration",
"Slot 4",
{
{"Empty", CT_Empty},
{"Mouse", CT_MouseInterface},
{"Mockingboard", CT_MockingboardC},
{"Phasor", CT_Phasor},
}
},
{
"slot5",
"Card in slot 5",
"Configuration",
"Slot 5",
{
{"Empty", CT_Empty},
{"CP/M", CT_Z80},
{"Mockingboard", CT_MockingboardC},
{"SAM/DAC", CT_SAM},
}
},
{
"video",
"Video mode",
"Configuration",
"Video Emulation",
{
{"Color (Composite Idealized)", VT_COLOR_IDEALIZED},
{"Color (RGB Card/Monitor)", VT_COLOR_VIDEOCARD_RGB},
{"Color (Composite Monitor)", VT_COLOR_MONITOR_NTSC},
{"Color TV", VT_COLOR_TV},
{"B&W TV", VT_MONO_TV},
{"Monochrome (Amber)", VT_MONO_AMBER},
{"Monochrome (Green)", VT_MONO_GREEN},
{"Monochrome (White)", VT_MONO_WHITE},
}
},
};
std::string getKey(const Variable & var)
{
std::ostringstream ss;
ss << var.description << "; ";
for (size_t i = 0; i < var.values.size(); ++i)
{
if (i > 0)
{
ss << "|";
}
ss << var.values[i].first;
}
return ss.str();
}
}
void SetupRetroVariables()
{
const size_t numberOfVariables = ourVariables.size();
std::vector<retro_variable> retroVariables(numberOfVariables + 1);
std::list<std::string> workspace; // so objects do not move when it resized
// we need to keep the char * alive till after the call to RETRO_ENVIRONMENT_SET_VARIABLES
const auto c_str = [&workspace] (const auto & s)
{
workspace.push_back(s);
return workspace.back().c_str();
};
for (size_t i = 0; i < numberOfVariables; ++i)
{
const Variable & variable = ourVariables[i];
retro_variable & retroVariable = retroVariables[i];
retroVariable.key = c_str(ourScope + variable.name);
retroVariable.value = c_str(getKey(variable));
}
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, retroVariables.data());
}
void InitialiseRetroRegistry()
{
const auto registry = std::make_shared<PTreeRegistry>();
for (const Variable & variable : ourVariables)
{
const std::string retroKey = ourScope + variable.name;
retro_variable retroVariable;
retroVariable.key = retroKey.c_str();
retroVariable.value = nullptr;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &retroVariable) && retroVariable.value)
{
const std::string value(retroVariable.value);
const auto check = [&value] (const auto & x)
{
return x.first == value;
};
const auto it = std::find_if(variable.values.begin(), variable.values.end(), check);
if (it != variable.values.end())
{
registry->putDWord(variable.section, variable.key, it->second);
}
}
}
Registry::instance = registry;
}

View file

@ -0,0 +1,4 @@
#pragma once
void SetupRetroVariables();
void InitialiseRetroRegistry();