From c632fc6619d41205c0c016e8fb1f0ee2736a4d69 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 1 Aug 2018 16:16:27 +0200 Subject: [PATCH] OSX: Avoid hanging the UI thread when waiting for rendering. Use cursor keys for keyboard. IOS: Add dip interpreter to build. --- .../emulator-ios/emulator/EmulatorView.h | 23 ++++++++++++++++++ .../emulator-ios/emulator/EmulatorView.mm | 22 ----------------- .../reicast-ios.xcodeproj/project.pbxproj | 6 ++++- .../emulator-osx/emulator-osx/EmuGLView.swift | 12 ++++++---- .../emulator-osx-Bridging-Header.h | 1 + .../emulator-osx/emulator-osx/osx-main.mm | 24 ++++++++++++------- 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/shell/apple/emulator-ios/emulator/EmulatorView.h b/shell/apple/emulator-ios/emulator/EmulatorView.h index b8e7ccba7..534129088 100644 --- a/shell/apple/emulator-ios/emulator/EmulatorView.h +++ b/shell/apple/emulator-ios/emulator/EmulatorView.h @@ -16,3 +16,26 @@ @property (nonatomic, strong) UIViewController *controllerView; @end + +#define DC_BTN_C (1) +#define DC_BTN_B (1<<1) +#define DC_BTN_A (1<<2) +#define DC_BTN_START (1<<3) +#define DC_DPAD_UP (1<<4) +#define DC_DPAD_DOWN (1<<5) +#define DC_DPAD_LEFT (1<<6) +#define DC_DPAD_RIGHT (1<<7) +#define DC_BTN_Z (1<<8) +#define DC_BTN_Y (1<<9) +#define DC_BTN_X (1<<10) +#define DC_BTN_D (1<<11) +#define DC_DPAD2_UP (1<<12) +#define DC_DPAD2_DOWN (1<<13) +#define DC_DPAD2_LEFT (1<<14) +#define DC_DPAD2_RIGHT (1<<15) + +#define DC_AXIS_LT (0X10000) +#define DC_AXIS_RT (0X10001) +#define DC_AXIS_X (0X20000) +#define DC_AXIS_Y (0X20001) + diff --git a/shell/apple/emulator-ios/emulator/EmulatorView.mm b/shell/apple/emulator-ios/emulator/EmulatorView.mm index af9f2a9bf..3f39e9e22 100644 --- a/shell/apple/emulator-ios/emulator/EmulatorView.mm +++ b/shell/apple/emulator-ios/emulator/EmulatorView.mm @@ -16,28 +16,6 @@ extern u32 vks[4]; extern s8 joyx[4],joyy[4]; extern u8 rt[4],lt[4]; -#define DC_BTN_C (1) -#define DC_BTN_B (1<<1) -#define DC_BTN_A (1<<2) -#define DC_BTN_START (1<<3) -#define DC_DPAD_UP (1<<4) -#define DC_DPAD_DOWN (1<<5) -#define DC_DPAD_LEFT (1<<6) -#define DC_DPAD_RIGHT (1<<7) -#define DC_BTN_Z (1<<8) -#define DC_BTN_Y (1<<9) -#define DC_BTN_X (1<<10) -#define DC_BTN_D (1<<11) -#define DC_DPAD2_UP (1<<12) -#define DC_DPAD2_DOWN (1<<13) -#define DC_DPAD2_LEFT (1<<14) -#define DC_DPAD2_RIGHT (1<<15) - -#define DC_AXIS_LT (0X10000) -#define DC_AXIS_RT (0X10001) -#define DC_AXIS_X (0X20000) -#define DC_AXIS_Y (0X20001) - @implementation EmulatorView /* diff --git a/shell/apple/emulator-ios/reicast-ios.xcodeproj/project.pbxproj b/shell/apple/emulator-ios/reicast-ios.xcodeproj/project.pbxproj index dd6496a9f..8c44edb1d 100644 --- a/shell/apple/emulator-ios/reicast-ios.xcodeproj/project.pbxproj +++ b/shell/apple/emulator-ios/reicast-ios.xcodeproj/project.pbxproj @@ -226,6 +226,7 @@ 9C7A3B4E18C806E00070BB5F /* stdclass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9C7A3A9918C806E00070BB5F /* stdclass.cpp */; }; 9C7A3B5918C81A4F0070BB5F /* SWRevealViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C7A3B5818C81A4F0070BB5F /* SWRevealViewController.m */; }; 9C7A3BC418C84EA10070BB5F /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9C7A3BC318C84EA10070BB5F /* MainStoryboard.storyboard */; }; + AE8C27372111EA0200D4D8F4 /* dsp_interp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE8C27352111EA0200D4D8F4 /* dsp_interp.cpp */; }; EBDF37561BB96E1B001191B5 /* audiobackend_coreaudio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EBDF37541BB96E1B001191B5 /* audiobackend_coreaudio.cpp */; }; EBDF375A1BB96ECD001191B5 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBDF37591BB96ECD001191B5 /* AudioToolbox.framework */; }; /* End PBXBuildFile section */ @@ -605,6 +606,7 @@ 9C7A3B5718C81A4F0070BB5F /* SWRevealViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWRevealViewController.h; sourceTree = ""; }; 9C7A3B5818C81A4F0070BB5F /* SWRevealViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWRevealViewController.m; sourceTree = ""; }; 9C7A3BC318C84EA10070BB5F /* MainStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MainStoryboard.storyboard; sourceTree = ""; }; + AE8C27352111EA0200D4D8F4 /* dsp_interp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dsp_interp.cpp; sourceTree = ""; }; EBDF37541BB96E1B001191B5 /* audiobackend_coreaudio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = audiobackend_coreaudio.cpp; sourceTree = ""; }; EBDF37551BB96E1B001191B5 /* audiobackend_coreaudio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = audiobackend_coreaudio.h; sourceTree = ""; }; EBDF37571BB96E75001191B5 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; @@ -1104,6 +1106,7 @@ 9C7A39E518C806DF0070BB5F /* aica_mem.h */, 9C7A39E618C806DF0070BB5F /* dsp.cpp */, 9C7A39E718C806DF0070BB5F /* dsp.h */, + AE8C27352111EA0200D4D8F4 /* dsp_interp.cpp */, 9C7A39E818C806DF0070BB5F /* sgc_if.cpp */, 9C7A39E918C806DF0070BB5F /* sgc_if.h */, ); @@ -1428,7 +1431,7 @@ ORGANIZATIONNAME = reicast; TargetAttributes = { 87078A8218A47FE90034C7A0 = { - DevelopmentTeam = QRT73U549N; + DevelopmentTeam = QRT73U549N; }; }; }; @@ -1615,6 +1618,7 @@ 9C7A3ACB18C806E00070BB5F /* zip_file_error_clear.c in Sources */, 9C7A3ACE18C806E00070BB5F /* zip_file_strerror.c in Sources */, 9C7A3AED18C806E00070BB5F /* zip_unchange.c in Sources */, + AE8C27372111EA0200D4D8F4 /* dsp_interp.cpp in Sources */, 877652C31B6157BD00437F10 /* audiobackend_directsound.cpp in Sources */, 9C7A3B1F18C806E00070BB5F /* driver.cpp in Sources */, 9C7A3B2018C806E00070BB5F /* shil.cpp in Sources */, diff --git a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift index 089600798..75fe24995 100644 --- a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift +++ b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift @@ -26,9 +26,10 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate { openGLContext!.makeCurrentContext() - while 0==emu_single_frame(Int32(dirtyRect.width), Int32(dirtyRect.height)) { } - - openGLContext!.flushBuffer() + if (emu_single_frame(Int32(dirtyRect.width), Int32(dirtyRect.height)) != 0) + { + openGLContext!.flushBuffer() + } } override func awakeFromNib() { @@ -61,7 +62,10 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate { func timerTick() { - self.needsDisplay = true; + if (emu_frame_pending()) + { + self.needsDisplay = true; + } } override func keyDown(with e: NSEvent) { diff --git a/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h b/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h index 9c05def99..b86280d51 100644 --- a/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h +++ b/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h @@ -15,4 +15,5 @@ int emu_single_frame(int w, int h); void emu_gles_init(); void emu_key_input(UInt16 keyCode, int state); void emu_shutdown(); +bool emu_frame_pending(); #endif diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index 40be940c9..7ffb71523 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -127,11 +127,14 @@ extern "C" void emu_main() { extern int screen_width,screen_height; bool rend_single_frame(); +bool rend_framePending(); bool gles_init(); extern "C" int emu_single_frame(int w, int h) { if (!has_init) return true; + if (!rend_framePending()) + return 0; screen_width = w; screen_height = h; @@ -142,6 +145,11 @@ extern "C" void emu_gles_init() { gles_init(); } +extern "C" bool emu_frame_pending() +{ + return rend_framePending(); +} + enum DCPad { Btn_C = 1, Btn_B = 1<<1, @@ -196,14 +204,14 @@ extern "C" void emu_key_input(UInt16 keyCode, int state) { // S case 0x01: handle_trig(rt, state); break; - // J - case 0x26: handle_key(DPad_Left, state); break; - // K - case 0x28: handle_key(DPad_Down, state); break; - // L - case 0x25: handle_key(DPad_Right, state); break; - // I - case 0x22: handle_key(DPad_Up, state); break; + // Left arrow + case 0x7b: handle_key(DPad_Left, state); break; + // Down arrow + case 0x7d: handle_key(DPad_Down, state); break; + // Right arrow + case 0x7c: handle_key(DPad_Right, state); break; + // Up arrow + case 0x7e: handle_key(DPad_Up, state); break; // Enter case 0x24: handle_key(Btn_Start, state); break; }