Maple: Reworked the way controllers are created

A new function was introduced to abstract the setup of input devices for each os: os_SetupInput().
I hope I implemented this everywhere correctly and the behaviour is identical to before.

The new function mcfg_CreateNAOMIJamma() creates the NAOMI Jamma interface and is hidden behind a compile flag (same as before).
The previous function mcfg_CreateDevices() was renamed to mcfg_CreateDevicesFromConfig() because it creates the devices based on the configuration (``nb`` setting).
This commit is contained in:
Christoph "baka0815" Schwerdtfeger 2018-08-20 13:36:34 +02:00 committed by Ender's Games
parent 8212be4850
commit 638a97d1ae
10 changed files with 151 additions and 122 deletions

View File

@ -73,18 +73,26 @@ void mcfg_Create(MapleDeviceType type, u32 bus, u32 port)
MapleDevices[bus][port] = dev;
}
void mcfg_CreateNAOMIJamma()
{
mcfg_Create(MDT_NaomiJamma, 0, 5);
}
void mcfg_CreateController(u32 bus, MapleDeviceType maple_type1, MapleDeviceType maple_type2)
{
mcfg_Create(MDT_SegaController, bus, 5);
if (maple_type1 != MDT_None)
mcfg_Create(maple_type1, bus, 0);
if (maple_type2 != MDT_None)
mcfg_Create(maple_type2, bus, 1);
}
void mcfg_CreateDevices()
void mcfg_CreateDevicesFromConfig()
{
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
// if using evdev they will be created later on
#if !defined(USE_EVDEV)
// Create the configure controller count
int numberOfControl = cfgLoadInt("players", "nb", 1);
if (numberOfControl <= 0)
@ -96,13 +104,9 @@ void mcfg_CreateDevices()
mcfg_Create(MDT_SegaController, i, 5);
}
// Default to two VMUs on controller 1
mcfg_Create(MDT_SegaVMU, 0, 0);
mcfg_Create(MDT_SegaVMU, 0, 1);
#endif
#else
mcfg_Create(MDT_NaomiJamma, 0, 5);
#endif
}
void mcfg_DestroyDevices()

View File

@ -64,11 +64,11 @@ struct IMapleConfigMap
virtual ~IMapleConfigMap() {}
};
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
void mcfg_CreateDevicesFromConfig();
void mcfg_CreateController(u32 bus, MapleDeviceType maple_type1, MapleDeviceType maple_type2);
#ifndef _ANDROID
void mcfg_CreateDevices();
#else
void mcfg_CreateDevices();
void mcfg_CreateNAOMIJamma();
#endif
void mcfg_DestroyDevices();

View File

@ -131,7 +131,7 @@ MapleDeviceType GetMapleDeviceType(int value)
return MDT_SegaVMU;
}
void SetupInput()
void os_SetupInput()
{
#if defined(USE_EVDEV)
int evdev_device_id[4] = { -1, -1, -1, -1 };
@ -500,8 +500,6 @@ int main(int argc, wchar* argv[])
dc_init(argc,argv);
SetupInput();
#if !defined(TARGET_EMSCRIPTEN)
#if FEAT_HAS_NIXPROF
install_prof_handler(0);

View File

@ -15,6 +15,7 @@
#include "ppapi/utility/completion_callback_factory.h"
#include "types.h"
#include "maple_cfg.h"
#include <GLES2/gl2.h>
@ -252,6 +253,9 @@ void os_DoEvents() {
}
void os_SetupInput() {
mcfg_CreateDevicesFromConfig();
}
void UpdateInputState(u32 port) {

View File

@ -40,7 +40,7 @@ settings_t settings;
#include <windows.h>
#endif
int GetFile(char *szFileName, char *szParse=0,u32 flags=0)
int GetFile(char *szFileName, char *szParse=0, u32 flags=0)
{
cfgLoadStr("config","image",szFileName,"null");
if (strcmp(szFileName,"null")==0)
@ -196,16 +196,15 @@ int dc_init(int argc,wchar* argv[])
mem_map_default();
#ifndef _ANDROID
mcfg_CreateDevices();
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
os_SetupInput();
#else
mcfg_CreateDevices();
mcfg_CreateNAOMIJamma();
#endif
plugins_Reset(false);
mem_Reset(false);
sh4_cpu.Reset(false);
#ifndef _ANDROID

View File

@ -7,6 +7,7 @@ double os_GetSeconds();
void os_DoEvents();
void os_CreateWindow();
void os_SetupInput();
void WriteSample(s16 right, s16 left);
#if BUILD_COMPILER==COMPILER_VC

View File

@ -6,6 +6,7 @@
#include <windows.h>
#include <Xinput.h>
#include "maple_cfg.h"
#pragma comment(lib, "XInput9_1_0.lib")
PCHAR*
@ -109,6 +110,11 @@ bool ngen_Rewrite(unat& addr,unat retadr,unat acc);
bool BM_LockedWrite(u8* address);
void UpdateController(u32 port);
void os_SetupInput()
{
mcfg_CreateDevicesFromConfig();
}
LONG ExeptionHandler(EXCEPTION_POINTERS *ExceptionInfo)
{
EXCEPTION_POINTERS* ep = ExceptionInfo;

View File

@ -10,6 +10,7 @@
#include <GLES2/gl2.h>
#include "types.h"
#include "maple_cfg.h"
#include "profiler/profiler.h"
#include "rend/TexCache.h"
#include "hw/maple/maple_devs.h"
@ -221,13 +222,6 @@ static void *ThreadHandler(void *UserData)
strcat(Args[2],P);
}
// Add additonal controllers
for (int i = 0; i < 3; i++)
{
if (add_controllers[i])
mcfg_Create(MDT_SegaController,i+1,5);
}
// Run nullDC emulator
dc_init(Args[2]? 3:1,Args);
return 0;
@ -262,6 +256,19 @@ void *libPvr_GetRenderSurface()
void common_linux_setup();
void os_SetupInput()
{
// Create first controller
mcfg_CreateController(0, MDT_SegaVMU, MDT_SegaVMU);
// Add additonal controllers
for (int i = 0; i < 3; i++)
{
if (add_controllers[i])
mcfg_CreateController(i+1, MDT_None, MDT_None);
}
}
void os_SetWindowText(char const *Text)
{
putinf("%s",Text);

View File

@ -21,6 +21,7 @@
#include <sys/time.h>
#include "hw/sh4/dyna/blockmanager.h"
#include <unistd.h>
#include "maple_cfg.h"
int msgboxf(const wchar* text,unsigned int type,...)
@ -102,6 +103,10 @@ void os_CreateWindow() {
}
void os_SetupInput() {
mcfg_CreateDevicesFromConfig();
}
void UpdateInputState(u32 port) {
}

View File

@ -8,6 +8,7 @@
#import <Carbon/Carbon.h>
#include "types.h"
#include "maple_cfg.h"
#include <sys/stat.h>
#include <OpenGL/gl3.h>
@ -67,6 +68,10 @@ void os_CreateWindow() {
}
void os_SetupInput() {
mcfg_CreateDevicesFromConfig();
}
void* libPvr_GetRenderTarget() {
return 0;
}