From adfe30cf4c3ebf0f5e757cf07f043364911fdbaf Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 23 Apr 2020 11:46:34 +0200 Subject: [PATCH] osx: allow exit with button. clean exit terminate network in dc_term to avoid static init order issues osx: call dc_term before exit osx: exit app when exit button is pressed (dc_exit) osx: ignore -NSDoc... app args --- core/cfg/cl.cpp | 7 +++++++ core/hw/naomi/naomi.cpp | 3 +++ core/hw/naomi/naomi_m3comm.cpp | 6 ------ core/hw/naomi/naomi_m3comm.h | 1 - .../apple/emulator-osx/emulator-osx/AppDelegate.swift | 2 +- shell/apple/emulator-osx/emulator-osx/EmuGLView.swift | 10 ++++------ .../emulator-osx/emulator-osx-Bridging-Header.h | 2 ++ shell/apple/emulator-osx/emulator-osx/osx-main.mm | 11 +++++++++++ 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/core/cfg/cl.cpp b/core/cfg/cl.cpp index 385c10425..5752ad111 100644 --- a/core/cfg/cl.cpp +++ b/core/cfg/cl.cpp @@ -129,6 +129,13 @@ bool ParseCommandLine(int argc,char* argv[]) cl-=as; arg+=as; } +#ifdef __MACH__ + else if (!strncmp(*arg, "-NSDocumentRevisions", 20)) + { + arg++; + cl--; + } +#endif else { char* extension = strrchr(*arg, '.'); diff --git a/core/hw/naomi/naomi.cpp b/core/hw/naomi/naomi.cpp index 6d1aca66b..376ab687e 100644 --- a/core/hw/naomi/naomi.cpp +++ b/core/hw/naomi/naomi.cpp @@ -14,6 +14,7 @@ #include "naomi_cart.h" #include "naomi_regs.h" #include "naomi_m3comm.h" +#include "network/naomi_network.h" //#define NAOMI_COMM @@ -539,6 +540,7 @@ void naomi_reg_Term() } #endif m3comm.closeNetwork(); + naomiNetwork.terminate(); } void naomi_reg_Reset(bool hard) @@ -571,6 +573,7 @@ void naomi_reg_Reset(bool hard) reg_dimm_parameterh = 0; reg_dimm_status = 0x11; m3comm.closeNetwork(); + naomiNetwork.terminate(); } static u8 aw_maple_devs; diff --git a/core/hw/naomi/naomi_m3comm.cpp b/core/hw/naomi/naomi_m3comm.cpp index 898815172..7fface33c 100644 --- a/core/hw/naomi/naomi_m3comm.cpp +++ b/core/hw/naomi/naomi_m3comm.cpp @@ -83,12 +83,6 @@ void NaomiM3Comm::sendNetwork() } } -NaomiM3Comm::~NaomiM3Comm() -{ - closeNetwork(); - naomiNetwork.terminate(); -} - u32 NaomiM3Comm::ReadMem(u32 address, u32 size) { switch (address & 255) diff --git a/core/hw/naomi/naomi_m3comm.h b/core/hw/naomi/naomi_m3comm.h index 420647c04..c865386e2 100644 --- a/core/hw/naomi/naomi_m3comm.h +++ b/core/hw/naomi/naomi_m3comm.h @@ -28,7 +28,6 @@ class NaomiM3Comm { public: - ~NaomiM3Comm(); u32 ReadMem(u32 address, u32 size); void WriteMem(u32 address, u32 data, u32 size); bool DmaStart(u32 addr, u32 data); diff --git a/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift b/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift index 5aeee8c4b..ee497e805 100644 --- a/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift +++ b/shell/apple/emulator-osx/emulator-osx/AppDelegate.swift @@ -21,7 +21,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func applicationWillTerminate(_ aNotification: Notification) { - emu_dc_exit() + emu_dc_term() } func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { diff --git a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift index 26642e87f..fea5c6752 100644 --- a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift +++ b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift @@ -67,8 +67,10 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate { @objc func timerTick() { - if (emu_frame_pending()) - { + if (!emu_renderer_enabled()) { + NSApplication.shared.terminate(self) + } + else if (emu_frame_pending()) { self.needsDisplay = true } } @@ -154,8 +156,4 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate { self.window!.delegate = self self.window!.acceptsMouseMovedEvents = true } - - func windowWillClose(_ notification: Notification) { - emu_dc_exit() - } } 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 af76f7d2b..ebd3fc233 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 @@ -11,6 +11,8 @@ #include void emu_dc_exit(); +void emu_dc_term(); +bool emu_renderer_enabled(); int emu_single_frame(int w, int h); void emu_gles_init(int width, int height); int emu_reicast_init(); diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index 8060f27d4..237ba6fc0 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -25,6 +25,7 @@ #include "stdclass.h" #include "wsi/context.h" #include "emulator.h" +#include "hw/pvr/Renderer_if.h" OSXKeyboardDevice keyboard(0); static std::shared_ptr kb_gamepad(0); @@ -94,6 +95,11 @@ extern "C" void emu_dc_exit() dc_exit(); } +extern "C" void emu_dc_term() +{ + dc_term(); +} + extern "C" void emu_dc_resume() { dc_resume(); @@ -108,6 +114,11 @@ extern "C" bool emu_frame_pending() return rend_framePending() || gui_is_open(); } +extern "C" bool emu_renderer_enabled() +{ + return renderer_enabled; +} + extern "C" int emu_single_frame(int w, int h) { if (!emu_frame_pending()) return 0;