From 638a97d1ae17216f5bfc2917a21c9277f98ce472 Mon Sep 17 00:00:00 2001 From: "Christoph \"baka0815\" Schwerdtfeger" Date: Mon, 20 Aug 2018 13:36:34 +0200 Subject: [PATCH] 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). --- core/hw/maple/maple_cfg.cpp | 26 ++++--- core/hw/maple/maple_cfg.h | 8 +- core/linux-dist/main.cpp | 4 +- core/nacl/nacl.cpp | 18 +++-- core/nullDC.cpp | 27 ++++--- core/oslib/oslib.h | 3 +- core/windows/winmain.cpp | 76 ++++++++++--------- .../reicast/src/main/jni/src/Android.cpp | 25 +++--- shell/apple/emulator-ios/emulator/ios_main.mm | 43 ++++++----- .../emulator-osx/emulator-osx/osx-main.mm | 43 ++++++----- 10 files changed, 151 insertions(+), 122 deletions(-) diff --git a/core/hw/maple/maple_cfg.cpp b/core/hw/maple/maple_cfg.cpp index e0a71cd2a..96a4e8d87 100644 --- a/core/hw/maple/maple_cfg.cpp +++ b/core/hw/maple/maple_cfg.cpp @@ -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); - mcfg_Create(maple_type1, bus, 0); - mcfg_Create(maple_type2, bus, 1); + + 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() diff --git a/core/hw/maple/maple_cfg.h b/core/hw/maple/maple_cfg.h index 8f90998b7..78f8dd328 100644 --- a/core/hw/maple/maple_cfg.h +++ b/core/hw/maple/maple_cfg.h @@ -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(); diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index 244b082d9..18466d17e 100755 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -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); diff --git a/core/nacl/nacl.cpp b/core/nacl/nacl.cpp index d9bc137db..4f65a4714 100644 --- a/core/nacl/nacl.cpp +++ b/core/nacl/nacl.cpp @@ -15,6 +15,7 @@ #include "ppapi/utility/completion_callback_factory.h" #include "types.h" +#include "maple_cfg.h" #include @@ -47,7 +48,7 @@ void* emuthread(void* ) { printf("Emu thread starting up"); char *Args[3]; Args[0] = "dc"; - + set_user_config_dir("/http"); set_user_data_dir("/http"); @@ -161,7 +162,7 @@ class HelloWorldInstance : public pp::Instance { glClearColor(0.65f, 0.65f, 0.65f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - + if (rend_framePending()) { while (!rend_single_frame()) ; printf("Rendered frame\n"); @@ -194,7 +195,7 @@ void HelloWorldInstance::HandleMessage(const pp::Var& var_message) { class HelloWorldModule : public pp::Module { public: HelloWorldModule() : pp::Module() { - + } virtual ~HelloWorldModule() {} @@ -252,6 +253,9 @@ void os_DoEvents() { } +void os_SetupInput() { + mcfg_CreateDevicesFromConfig(); +} void UpdateInputState(u32 port) { @@ -275,7 +279,7 @@ void* libPvr_GetRenderTarget() { void* libPvr_GetRenderSurface() { return 0; - + } bool gl_init(void*, void*) { @@ -283,9 +287,9 @@ bool gl_init(void*, void*) { } void gl_term() { - + } void gl_swap() { - -} \ No newline at end of file + +} diff --git a/core/nullDC.cpp b/core/nullDC.cpp index 03c66bb76..026a43968 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -40,7 +40,7 @@ settings_t settings; #include #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) @@ -68,7 +68,7 @@ int GetFile(char *szFileName, char *szParse=0,u32 flags=0) #endif } - return 1; + return 1; } @@ -87,10 +87,10 @@ s32 plugins_Init() if (s32 rv = libAICA_Init()) return rv; - + if (s32 rv = libARM_Init()) return rv; - + //if (s32 rv = libExtDevice_Init()) // return rv; @@ -165,7 +165,7 @@ int dc_init(int argc,wchar* argv[]) #else #define DATA_PATH "/" #endif - + if (settings.bios.UseReios || !LoadRomFiles(get_readonly_data_path(DATA_PATH))) { if (!LoadHle(get_readonly_data_path(DATA_PATH))) @@ -193,18 +193,17 @@ int dc_init(int argc,wchar* argv[]) mem_Init(); plugins_Init(); - + 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); @@ -230,7 +229,7 @@ void dc_term() SaveSettings(); #endif SaveRomFiles(get_writable_data_path("/data/")); - + TermAudio(); } @@ -265,9 +264,9 @@ void LoadSettings() settings.rend.WideScreen = cfgLoadInt("config","rend.WideScreen",0); settings.rend.ModifierVolumes = cfgLoadInt("config","rend.ModifierVolumes",1); settings.rend.Clipping = cfgLoadInt("config","rend.Clipping",1); - + settings.pvr.subdivide_transp = cfgLoadInt("config","pvr.Subdivide",0); - + settings.pvr.ta_skip = cfgLoadInt("config","ta.skip",0); settings.pvr.rend = cfgLoadInt("config","pvr.rend",0); @@ -337,4 +336,4 @@ void SaveSettings() cfgSaveInt("config","Dreamcast.RTC", settings.dreamcast.RTC); cfgSaveInt("config","Dreamcast.Region", settings.dreamcast.region); cfgSaveInt("config","Dreamcast.Broadcast", settings.dreamcast.broadcast); -} \ No newline at end of file +} diff --git a/core/oslib/oslib.h b/core/oslib/oslib.h index 8e8782380..da7d41745 100644 --- a/core/oslib/oslib.h +++ b/core/oslib/oslib.h @@ -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 @@ -27,4 +28,4 @@ u32 static INLINE bitscanrev(u32 v) //FIX ME #define __assume(x) -void os_DebugBreak(); \ No newline at end of file +void os_DebugBreak(); diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index 3c01f4617..efba21f94 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -2,10 +2,11 @@ #include "oslib\audiostream.h" #include "imgread\common.h" -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0500 #include #include +#include "maple_cfg.h" #pragma comment(lib, "XInput9_1_0.lib") PCHAR* @@ -45,7 +46,7 @@ PCHAR* { if(in_QM) { - if(a == '\"') + if(a == '\"') { in_QM = FALSE; } @@ -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; @@ -254,12 +260,12 @@ void UpdateInputState(u32 port) void UpdateController(u32 port) { XINPUT_STATE state; - + if (XInputGetState(port, &state) == 0) { WORD xbutton = state.Gamepad.wButtons; - if (xbutton & XINPUT_GAMEPAD_A) + if (xbutton & XINPUT_GAMEPAD_A) kcode[port] &= ~key_CONT_A; if (xbutton & XINPUT_GAMEPAD_B) kcode[port] &= ~key_CONT_B; @@ -381,34 +387,34 @@ void os_CreateWindow() window_win=hWnd; } -void* libPvr_GetRenderTarget() -{ - return window_win; +void* libPvr_GetRenderTarget() +{ + return window_win; } -void* libPvr_GetRenderSurface() -{ +void* libPvr_GetRenderSurface() +{ return GetDC((HWND)window_win); } -BOOL CtrlHandler( DWORD fdwCtrlType ) -{ - switch( fdwCtrlType ) +BOOL CtrlHandler( DWORD fdwCtrlType ) +{ + switch( fdwCtrlType ) { case CTRL_SHUTDOWN_EVENT: case CTRL_LOGOFF_EVENT: - // Pass other signals to the next handler. + // Pass other signals to the next handler. case CTRL_BREAK_EVENT: - // CTRL-CLOSE: confirm that the user wants to exit. + // CTRL-CLOSE: confirm that the user wants to exit. case CTRL_CLOSE_EVENT: - // Handle the CTRL-C signal. + // Handle the CTRL-C signal. case CTRL_C_EVENT: SendMessageA((HWND)libPvr_GetRenderTarget(),WM_CLOSE,0,0); //FIXEM return( TRUE ); - default: + default: return FALSE; - } -} + } +} void os_SetWindowText(const char* text) @@ -472,12 +478,12 @@ void ReserveBottomMemory() if ( s_initialized ) return; s_initialized = true; - + // Start by reserving large blocks of address space, and then // gradually reduce the size in order to capture all of the // fragments. Technically we should continue down to 64 KB but // stopping at 1 MB is sufficient to keep most allocators out. - + const size_t LOW_MEM_LINE = 0x100000000LL; size_t totalReservation = 0; size_t numVAllocs = 0; @@ -490,19 +496,19 @@ void ReserveBottomMemory() void* p = VirtualAlloc(0, size, MEM_RESERVE, PAGE_NOACCESS); if (!p) break; - + if ((size_t)p >= LOW_MEM_LINE) { // We don't need this memory, so release it completely. VirtualFree(p, 0, MEM_RELEASE); break; } - + totalReservation += size; ++numVAllocs; } } - + // Now repeat the same process but making heap allocations, to use up // the already reserved heap blocks that are below the 4 GB line. HANDLE heap = GetProcessHeap(); @@ -513,19 +519,19 @@ void ReserveBottomMemory() void* p = HeapAlloc(heap, 0, blockSize); if (!p) break; - + if ((size_t)p >= LOW_MEM_LINE) { // We don't need this memory, so release it completely. HeapFree(heap, 0, p); break; } - + totalReservation += blockSize; ++numHeapAllocs; } } - + // Perversely enough the CRT doesn't use the process heap. Suck up // the memory the CRT heap has already reserved. for (size_t blockSize = 64 * 1024; blockSize >= 16; blockSize /= 2) @@ -535,19 +541,19 @@ void ReserveBottomMemory() void* p = malloc(blockSize); if (!p) break; - + if ((size_t)p >= LOW_MEM_LINE) { // We don't need this memory, so release it completely. free(p); break; } - + totalReservation += blockSize; ++numHeapAllocs; } } - + // Print diagnostics showing how many allocations we had to make in // order to reserve all of low memory, typically less than 200. char buffer[1000]; @@ -600,7 +606,7 @@ struct _CONTEXT* ContextRecord, EXCEPTION_POINTERS ep; ep.ContextRecord = ContextRecord; ep.ExceptionRecord = ExceptionRecord; - + return (EXCEPTION_DISPOSITION)ExeptionHandler(&ep); } @@ -646,7 +652,7 @@ void setup_seh() { unwind_info[0].UnwindCode[0].CodeOffset = 0; unwind_info[0].UnwindCode[0].UnwindOp = 2;// UWOP_ALLOC_SMALL; unwind_info[0].UnwindCode[0].OpInfo = 0x20 / 8; - + //unwind_info[0].ExceptionHandler = //(DWORD)((u8 *)__gnat_SEH_error_handler - CodeCache); /* Set its scope to the entire program. */ @@ -708,7 +714,7 @@ int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine } - + LARGE_INTEGER qpf; double qpfd; //Helper functions @@ -757,7 +763,7 @@ cThread::cThread(ThreadEntryFP* function,void* prm) param=prm; } - + void cThread::Start() { hThread=CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)Entry,param,0,NULL); @@ -773,7 +779,7 @@ void cThread::WaitToEnd() //cResetEvent Calss cResetEvent::cResetEvent(bool State,bool Auto) { - hEvent = CreateEvent( + hEvent = CreateEvent( NULL, // default security attributes Auto?FALSE:TRUE, // auto-reset event? State?TRUE:FALSE, // initial state is State @@ -831,4 +837,4 @@ void VArray2::UnLockRegion(u32 offset,u32 size) } int get_mic_data(u8* buffer) { return 0; } -int push_vmu_screen(u8* buffer) { return 0; } \ No newline at end of file +int push_vmu_screen(u8* buffer) { return 0; } diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index bae3db770..b187b9fbd 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -10,6 +10,7 @@ #include #include "types.h" +#include "maple_cfg.h" #include "profiler/profiler.h" #include "rend/TexCache.h" #include "hw/maple/maple_devs.h" @@ -221,15 +222,8 @@ 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); + // 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); diff --git a/shell/apple/emulator-ios/emulator/ios_main.mm b/shell/apple/emulator-ios/emulator/ios_main.mm index efd613b36..151efb2d8 100644 --- a/shell/apple/emulator-ios/emulator/ios_main.mm +++ b/shell/apple/emulator-ios/emulator/ios_main.mm @@ -21,17 +21,18 @@ #include #include "hw/sh4/dyna/blockmanager.h" #include +#include "maple_cfg.h" int msgboxf(const wchar* text,unsigned int type,...) { va_list args; - + wchar temp[2048]; va_start(args, type); vsprintf(temp, text, args); va_end(args); - + //printf(NULL,temp,VER_SHORTNAME,type | MB_TASKMODAL); puts(temp); return 0; @@ -39,14 +40,14 @@ int msgboxf(const wchar* text,unsigned int type,...) int darw_printf(const wchar* text,...) { va_list args; - + wchar temp[2048]; va_start(args, text); vsprintf(temp, text, args); va_end(args); - + NSLog(@"%s", temp); - + return 0; } @@ -64,29 +65,29 @@ extern "C" int reicast_main(int argc, wchar* argv[]) { //if (argc==2) //ndcid=atoi(argv[1]); - + string homedir = [ [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0] path] UTF8String]; set_user_config_dir(homedir); set_user_data_dir(homedir); - + freopen( (homedir + "/log.txt").c_str(), "wb", stdout); - + printf("Config dir is: %s\n", get_writable_config_path("/").c_str()); printf("Data dir is: %s\n", get_writable_data_path("/").c_str()); - + common_linux_setup(); - + settings.profile.run_counts=0; - + dc_init(argc,argv); - + dc_run(); - + return 0; } void os_DoEvents() { - + } @@ -102,8 +103,12 @@ void os_CreateWindow() { } +void os_SetupInput() { + mcfg_CreateDevicesFromConfig(); +} + void UpdateInputState(u32 port) { - + } void UpdateVibration(u32 port, u32 value) { @@ -120,7 +125,7 @@ void* libPvr_GetRenderTarget() { void* libPvr_GetRenderSurface() { return 0; - + } bool gl_init(void*, void*) { @@ -128,9 +133,9 @@ bool gl_init(void*, void*) { } void gl_term() { - + } void gl_swap() { - -} \ No newline at end of file + +} diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index caca6dcc6..b00a59e4a 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -8,6 +8,7 @@ #import #include "types.h" +#include "maple_cfg.h" #include #include @@ -15,26 +16,26 @@ int msgboxf(const wchar* text,unsigned int type,...) { va_list args; - + wchar temp[2048]; va_start(args, type); vsprintf(temp, text, args); va_end(args); - + puts(temp); return 0; } int darw_printf(const wchar* text,...) { va_list args; - + wchar temp[2048]; va_start(args, text); vsprintf(temp, text, args); va_end(args); - + NSLog(@"%s", temp); - + return 0; } @@ -51,12 +52,12 @@ void os_SetWindowText(const char * text) { } void os_DoEvents() { - + } void UpdateInputState(u32 port) { - + } void UpdateVibration(u32 port, u32 value) { @@ -64,7 +65,11 @@ void UpdateVibration(u32 port, u32 value) { } void os_CreateWindow() { - + +} + +void os_SetupInput() { + mcfg_CreateDevicesFromConfig(); } void* libPvr_GetRenderTarget() { @@ -73,7 +78,7 @@ void* libPvr_GetRenderTarget() { void* libPvr_GetRenderSurface() { return 0; - + } bool gl_init(void*, void*) { @@ -81,11 +86,11 @@ bool gl_init(void*, void*) { } void gl_term() { - + } void gl_swap() { - + } int dc_init(int argc,wchar* argv[]); @@ -110,15 +115,15 @@ void* emuthread(void*) { set_user_data_dir("."); } char* argv[] = { "reicast" }; - + dc_init(1,argv); - + has_init = true; - + dc_run(); - + has_init = false; - + dc_term(); return 0; @@ -167,7 +172,7 @@ enum DCPad { DPad2_Down = 1<<13, DPad2_Left = 1<<14, DPad2_Right = 1<<15, - + Axis_LT= 0x10000, Axis_RT= 0x10001, Axis_X= 0x20000, @@ -195,10 +200,10 @@ extern "C" void emu_key_input(char* keyt, int state) { case 'x': handle_key(Btn_Y, state); break; case 'c': handle_key(Btn_B, state); break; case 'v': handle_key(Btn_A, state); break; - + case 'a': handle_trig(lt, state); break; case 's': handle_trig(rt, state); break; - + case 'j': handle_key(DPad_Left, state); break; case 'k': handle_key(DPad_Down, state); break; case 'l': handle_key(DPad_Right, state); break;