From 9430a173011566fef961145943cdffb81a5a0fb7 Mon Sep 17 00:00:00 2001 From: Todd Laney Date: Mon, 22 Apr 2024 09:25:01 -0700 Subject: [PATCH] update to MAME 264 --- make-ios.sh | 7 +- scripts/src/osd/ios.lua | 2 + src/osd/ios/input.cpp | 138 ++++++++++++++++++++++++++++++------ src/osd/ios/iosmain.cpp | 19 +++-- src/osd/ios/iososd.h | 10 ++- src/osd/ios/osdlib.cpp | 152 ++++++++++++++++------------------------ 6 files changed, 206 insertions(+), 122 deletions(-) diff --git a/make-ios.sh b/make-ios.sh index edc4f847f3ab7..81880e0ab890a 100755 --- a/make-ios.sh +++ b/make-ios.sh @@ -36,7 +36,7 @@ fi if [ "$1" == "ios" ]; then shift export BUILDDIR=build-ios - export ARCHOPTS="-arch arm64 -isysroot `xcodebuild -version -sdk iphoneos Path` -miphoneos-version-min=$VERSION_MIN" + export ARCHOPTS="-arch arm64 -isysroot `xcodebuild -version -sdk iphoneos Path` -miphoneos-version-min=$VERSION_MIN -target arm64-apple-ios$VERSION_MIN" LIBMAME=libmame-ios fi @@ -162,6 +162,11 @@ fi ## common OPTS export ARCHOPTS="$ARCHOPTS -fPIC" +## add -mcrc for arm64 +if [[ $ARCHOPTS == *arm64* ]]; then + export ARCHOPTS="$ARCHOPTS -mcrc" +fi + ## hack to get sqlite to build export ARCHOPTS="$ARCHOPTS -DHAVE_GETHOSTUUID=0" diff --git a/scripts/src/osd/ios.lua b/scripts/src/osd/ios.lua index c6ba1b287625c..605fd90aebf4b 100644 --- a/scripts/src/osd/ios.lua +++ b/scripts/src/osd/ios.lua @@ -42,6 +42,8 @@ project ("osd_" .. _OPTIONS["osd"]) MAME_DIR .. "src/osd/osdnet.h", MAME_DIR .. "src/osd/watchdog.cpp", MAME_DIR .. "src/osd/watchdog.h", + MAME_DIR .. "src/osd/interface/nethandler.cpp", + MAME_DIR .. "src/osd/interface/nethandler.h", } includedirs { diff --git a/src/osd/ios/input.cpp b/src/osd/ios/input.cpp index 327b13d7c2e6a..c8aaea8c5232e 100644 --- a/src/osd/ios/input.cpp +++ b/src/osd/ios/input.cpp @@ -335,7 +335,8 @@ void input_profile_init(running_machine &machine) //============================================================ void ios_osd_interface::input_update(bool relative_reset) { - osd_printf_verbose("ios_osd_interface::input_update\n"); + // TODO: handle relative_reset!! + osd_printf_verbose("ios_osd_interface::input_update relative_reset=%d\n", relative_reset); // fill in the input profile the first time if (g_input.num_ways == 0) { @@ -354,9 +355,11 @@ void ios_osd_interface::input_update(bool relative_reset) // determine if we should disable the rest of the UI bool has_keyboard = g_input.num_keyboard != 0; // machine_info().has_keyboard(); +// TODO: need way to get ui_active() state, for NOW just assume ui_active==true //mame_ui_manager *ui = dynamic_cast(&machine.ui()); //bool ui_disabled = (has_keyboard && !ui->ui_active()); bool ui_disabled = (has_keyboard && false); +// TODO: need way to get ui_active() state, for NOW just assume ui_active==true // set the current input mode g_input.input_mode = in_menu ? MYOSD_INPUT_MODE_MENU : (ui_disabled ? MYOSD_INPUT_MODE_KEYBOARD : MYOSD_INPUT_MODE_NORMAL); @@ -385,12 +388,6 @@ void ios_osd_interface::check_osd_inputs() // customize_input_type_list //============================================================ -// joystick D-Pad -#define JOYCODE_HATUP(n) input_code(DEVICE_CLASS_JOYSTICK, n, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, ITEM_ID_HAT1UP) -#define JOYCODE_HATDOWN(n) input_code(DEVICE_CLASS_JOYSTICK, n, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, ITEM_ID_HAT1DOWN) -#define JOYCODE_HATLEFT(n) input_code(DEVICE_CLASS_JOYSTICK, n, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, ITEM_ID_HAT1LEFT) -#define JOYCODE_HATRIGHT(n) input_code(DEVICE_CLASS_JOYSTICK, n, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, ITEM_ID_HAT1RIGHT) - void ios_osd_interface::customize_input_type_list(std::vector &typelist) { // This function is called on startup, before reading the @@ -398,12 +395,12 @@ void ios_osd_interface::customize_input_type_list(std::vector // default control mappings you want. It is quite possible // you won't need to change a thing. - //osd_printf_debug("INPUT TYPE LIST\n"); + osd_printf_verbose("INPUT TYPE LIST\n"); // loop over the defaults for (input_type_entry &entry : typelist) { - //osd_printf_debug(" %s TYPE:%d PLAYER:%d\n", entry.name() ?: "", entry.type(), entry.player()); + osd_printf_verbose(" %s TYPE:%d PLAYER:%d\n", entry.name().c_str(), entry.type(), entry.player()); switch (entry.type()) { @@ -431,18 +428,29 @@ void ios_osd_interface::customize_input_type_list(std::vector // allow the DPAD to move the UI case IPT_UI_UP: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATUP(0); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1UP; + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_Y_UP_SWITCH; break; case IPT_UI_DOWN: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATDOWN(0); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1DOWN; + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_Y_DOWN_SWITCH; break; case IPT_UI_LEFT: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATLEFT(0); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1LEFT_INDEXED(0); // JOYCODE_HAT1LEFT + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_X_LEFT_SWITCH; break; case IPT_UI_RIGHT: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATRIGHT(0); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1RIGHT; + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_X_RIGHT_SWITCH; break; - + case IPT_UI_SELECT: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON1; + break; + //case IPT_UI_CANCEL: + case IPT_UI_BACK: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON2; + break; + /* allow L1 and R1 to move pages in MAME UI */ case IPT_UI_PAGE_UP: entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON5; @@ -451,25 +459,111 @@ void ios_osd_interface::customize_input_type_list(std::vector entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON6; break; - /* these are mostly the same as MAME defaults, except we add dpad to them */ + /* left joystick, these are mostly the same as MAME defaults, except we add dpad to them */ case IPT_JOYSTICK_UP: case IPT_JOYSTICKLEFT_UP: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATUP(entry.player()); - break; + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1UP_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_Y_UP_SWITCH_INDEXED(entry.player()); + break; case IPT_JOYSTICK_DOWN: case IPT_JOYSTICKLEFT_DOWN: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATDOWN(entry.player()); - break; + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1DOWN_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_Y_DOWN_SWITCH_INDEXED(entry.player()); + break; case IPT_JOYSTICK_LEFT: case IPT_JOYSTICKLEFT_LEFT: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATLEFT(entry.player()); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1LEFT_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_X_LEFT_SWITCH_INDEXED(entry.player()); break; case IPT_JOYSTICK_RIGHT: case IPT_JOYSTICKLEFT_RIGHT: - entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HATRIGHT(entry.player()); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_HAT1RIGHT_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_X_RIGHT_SWITCH_INDEXED(entry.player()); + break; + + // right joystick + case IPT_JOYSTICKRIGHT_UP: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_U_NEG_SWITCH_INDEXED(entry.player()); + break; + case IPT_JOYSTICKRIGHT_DOWN: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_U_POS_SWITCH_INDEXED(entry.player()); + break; + case IPT_JOYSTICKRIGHT_RIGHT: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_V_POS_SWITCH_INDEXED(entry.player()); + break; + case IPT_JOYSTICKRIGHT_LEFT: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_V_NEG_SWITCH_INDEXED(entry.player()); + break; + + // analog joystick + case IPT_AD_STICK_X: + case IPT_TRACKBALL_X: + case IPT_LIGHTGUN_X: + case IPT_PEDAL: + case IPT_DIAL: + case IPT_PADDLE: + case IPT_POSITIONAL: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_X_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_DECREMENT) |= JOYCODE_HAT1LEFT_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_INCREMENT) |= JOYCODE_HAT1RIGHT_INDEXED(entry.player()); + break; + case IPT_AD_STICK_Y: + case IPT_TRACKBALL_Y: + case IPT_LIGHTGUN_Y: + case IPT_DIAL_V: + case IPT_PADDLE_V: + case IPT_POSITIONAL_V: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_Y_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_DECREMENT) |= JOYCODE_HAT1UP_INDEXED(entry.player()); + entry.defseq(SEQ_TYPE_INCREMENT) |= JOYCODE_HAT1DOWN_INDEXED(entry.player()); + break; + + case IPT_AD_STICK_Z: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_Z_INDEXED(entry.player()); + break; + + // A,B,X,Y + case IPT_BUTTON1: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON1_INDEXED(entry.player()); + break; + case IPT_BUTTON2: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON2_INDEXED(entry.player()); + break; + case IPT_BUTTON3: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON3_INDEXED(entry.player()); + break; + case IPT_BUTTON4: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON4_INDEXED(entry.player()); + break; + // L,R + case IPT_BUTTON5: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON5_INDEXED(entry.player()); + break; + case IPT_BUTTON6: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON6_INDEXED(entry.player()); + break; + // L2,R2,L3,R3 + case IPT_BUTTON7: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON7_INDEXED(entry.player()); + break; + case IPT_BUTTON8: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON8_INDEXED(entry.player()); + break; + case IPT_BUTTON9: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON9_INDEXED(entry.player()); + break; + case IPT_BUTTON10: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_BUTTON10_INDEXED(entry.player()); + break; + // Select, Start + case IPT_SELECT: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_SELECT_INDEXED(entry.player()); + break; + case IPT_START: + entry.defseq(SEQ_TYPE_STANDARD) |= JOYCODE_START_INDEXED(entry.player()); break; - // leave everything else alone + // leave everything else alone default: break; } diff --git a/src/osd/ios/iosmain.cpp b/src/osd/ios/iosmain.cpp index d1128e53ccbe6..3df70da156f95 100644 --- a/src/osd/ios/iosmain.cpp +++ b/src/osd/ios/iosmain.cpp @@ -70,7 +70,7 @@ extern "C" int myosd_main(int argc, char** argv, myosd_callbacks* callbacks, siz memset(&host_callbacks, 0, sizeof(host_callbacks)); memcpy(&host_callbacks, callbacks, MIN(sizeof(host_callbacks), sizeof(myosd_callbacks))); - if (argc == 0) { + if (argc == 0 || argv == NULL) { static const char* args[] = {"myosd"}; argc = 1; argv = (char**)args; @@ -579,6 +579,9 @@ void osd_setup_osd_specific_emu_options(emu_options &opts) opts.add_entries(s_option_entries); } +// TODO: the 7z library has changed, this is removed for now. +#if 0 + //============================================================ // myosd_enumerate_7z // give the host the ability to enumerate the file names in a 7z file @@ -595,7 +598,7 @@ extern "C" int myosd_enumerate_7z(const char* path, int load_data_flag, void* ca { CSzArEx db; CFileInStream archiveStream; - CLookToRead lookStream; + CLookToRead2 lookStream; ISzAlloc alloc = {SzAlloc, SzFree}; ISzAlloc alloc_temp = {SzAllocTemp, SzFreeTemp}; @@ -603,16 +606,16 @@ extern "C" int myosd_enumerate_7z(const char* path, int load_data_flag, void* ca return -1; FileInStream_CreateVTable(&archiveStream); - LookToRead_CreateVTable(&lookStream, False); + LookToRead2_CreateVTable(&lookStream, False); - lookStream.realStream = &archiveStream.s; - LookToRead_Init(&lookStream); + lookStream.realStream = &archiveStream.vt; + LookToRead2_INIT(&lookStream); if (g_CrcTable[1] == 0) CrcGenerateTable(); // *YES* this is needed!! SzArEx_Init(&db); - int err = SzArEx_Open(&db, &lookStream.s, &alloc, &alloc_temp); + int err = SzArEx_Open(&db, &lookStream.vt, &alloc, &alloc_temp); if (err == 0) { uint32_t blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ @@ -635,7 +638,7 @@ extern "C" int myosd_enumerate_7z(const char* path, int load_data_flag, void* ca size_t offset = 0; size_t outSizeProcessed = 0; - int res = SzArEx_Extract(&db, &lookStream.s, i, + int res = SzArEx_Extract(&db, &lookStream.vt, i, &blockIndex, &outBuffer, &outBufferSize, &offset, &outSizeProcessed, &alloc, &alloc_temp); @@ -656,4 +659,6 @@ extern "C" int myosd_enumerate_7z(const char* path, int load_data_flag, void* ca return err; } +#endif + diff --git a/src/osd/ios/iososd.h b/src/osd/ios/iososd.h index 383ae2e1b626b..a2c127ad29260 100644 --- a/src/osd/ios/iososd.h +++ b/src/osd/ios/iososd.h @@ -11,7 +11,7 @@ //============================================================ // DebugLog //============================================================ -#define DebugLog 1 +#define DebugLog 0 #if DebugLog == 0 #define osd_printf_debug(...) (void)0 #endif @@ -40,6 +40,11 @@ extern int myosd_display_height; // TYPE DEFINITIONS //============================================================ +// forward references +class input_type_entry; +namespace osd { class midi_input_port; class midi_output_port; } +namespace ui { class menu_item; } + class ios_osd_interface : public osd_interface, osd_output { public: @@ -80,7 +85,8 @@ class ios_osd_interface : public osd_interface, osd_output virtual bool execute_command(const char *command) override {return true;} // midi interface - virtual std::unique_ptr create_midi_device() override {return nullptr;} + virtual std::unique_ptr create_midi_input(std::string_view name) override {return nullptr;} + virtual std::unique_ptr create_midi_output(std::string_view name) override {return nullptr;} // osd_output virtual void output_callback(osd_output_channel channel, const util::format_argument_pack &args) override; diff --git a/src/osd/ios/osdlib.cpp b/src/osd/ios/osdlib.cpp index 3ef2800f149fd..e8d3df75c116f 100644 --- a/src/osd/ios/osdlib.cpp +++ b/src/osd/ios/osdlib.cpp @@ -51,30 +51,6 @@ void osd_process_kill(void) kill(getpid(), SIGKILL); } - -//============================================================ -// osd_alloc_executable -// -// allocates "size" bytes of executable memory. this must take -// things like NX support into account. -//============================================================ - -void *osd_alloc_executable(size_t size) -{ - return (void *)mmap(0, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); -} - -//============================================================ -// osd_free_executable -// -// frees memory allocated with osd_alloc_executable -//============================================================ - -void osd_free_executable(void *ptr, size_t size) -{ - munmap(ptr, size); -} - //============================================================ // osd_break_into_debugger //============================================================ @@ -105,7 +81,7 @@ std::string osd_get_clipboard_text(void) // osd_getpid //============================================================ -int osd_getpid(void) +int osd_getpid(void) noexcept { return getpid(); } @@ -115,68 +91,7 @@ int osd_getpid(void) //============================================================ namespace osd { -#if !defined(OSD_IOS) -namespace { - -class dynamic_module_posix_impl : public dynamic_module -{ -public: - dynamic_module_posix_impl(std::vector &&libraries) : m_libraries(std::move(libraries)) - { - } - - virtual ~dynamic_module_posix_impl() override - { - if (m_module) - dlclose(m_module); - } - -protected: - virtual generic_fptr_t get_symbol_address(char const *symbol) override - { - /* - * given a list of libraries, if a first symbol is successfully loaded from - * one of them, all additional symbols will be loaded from the same library - */ - if (m_module) - return reinterpret_cast(dlsym(m_module, symbol)); - - for (auto const &library : m_libraries) - { - void *const module = dlopen(library.c_str(), RTLD_LAZY); - - if (module != nullptr) - { - generic_fptr_t const function = reinterpret_cast(dlsym(module, symbol)); - - if (function) - { - m_module = module; - return function; - } - else - { - dlclose(module); - } - } - } - - return nullptr; - } - -private: - std::vector m_libraries; - void * m_module = nullptr; -}; -} // anonymous namespace - -dynamic_module::ptr dynamic_module::open(std::vector &&names) -{ - return std::make_unique(std::move(names)); -} -#endif - -bool invalidate_instruction_cache(void const *start, std::size_t size) +bool invalidate_instruction_cache(void const *start, std::size_t size) noexcept { #if !defined(OSD_IOS) char const *const begin(reinterpret_cast(start)); @@ -186,8 +101,10 @@ bool invalidate_instruction_cache(void const *start, std::size_t size) return true; } -void *virtual_memory_allocation::do_alloc(std::initializer_list blocks, unsigned intent, std::size_t &size, std::size_t &page_size) +void *virtual_memory_allocation::do_alloc(std::initializer_list blocks, unsigned intent, std::size_t &size, std::size_t &page_size) noexcept { + osd_printf_debug("virtual_memory_allocation::do_alloc(%d)\n", size); + long const p(sysconf(_SC_PAGE_SIZE)); if (0 >= p) return nullptr; @@ -211,13 +128,16 @@ void *virtual_memory_allocation::do_alloc(std::initializer_list blo return result; } -void virtual_memory_allocation::do_free(void *start, std::size_t size) +void virtual_memory_allocation::do_free(void *start, std::size_t size) noexcept { + osd_printf_debug("virtual_memory_allocation::do_free\n"); munmap(reinterpret_cast(start), size); } -bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access) +bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access) noexcept { + osd_printf_debug("virtual_memory_allocation::do_set_access(%s%s%s)\n", (access & READ) ? "R" : "-", (access & WRITE) ? "W" : "-", (access & EXECUTE) ? "X" : "-"); + int prot((NONE == access) ? PROT_NONE : 0); if (access & READ) prot |= PROT_READ; @@ -225,7 +145,59 @@ bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, uns prot |= PROT_WRITE; if (access & EXECUTE) prot |= PROT_EXEC; + +#if defined(OSD_IOS) + if (prot & PROT_EXEC) + { + osd_printf_debug("virtual_memory_allocation::do_set_access -- FAIL\n"); + return false; + } +#endif + return mprotect(reinterpret_cast(start), size, prot) == 0; } } // namespace osd + +//============================================================ +// mmap +// munmap +// mprotect +//============================================================ + +#if 0 +extern "C" void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { + osd_printf_verbose("mmap(%s%s%s)\n", (flags & PROT_READ) ? "R" : "-", (flags & PROT_WRITE) ? "W" : "-", (flags & PROT_EXEC) ? "X" : "-"); + return MAP_FAILED; +} + +extern "C" int munmap(void *addr, size_t len) { + osd_printf_verbose("munmap()\n"); + return 0; +} + +extern "C" int mprotect(void *addr, size_t len, int flags) { + osd_printf_verbose("mprotect(%s%s%s)\n", (flags & PROT_READ) ? "R" : "-", (flags & PROT_WRITE) ? "W" : "-", (flags & PROT_EXEC) ? "X" : "-"); + return 0; +} +#endif + +//============================================================ +// dlopen +// dlclose +// dlsym +//============================================================ +extern "C" void* dlopen(const char* path, int mode) { + osd_printf_verbose("dlopen(%s)\n", path); + return NULL; +} + +extern "C" int dlclose(void* handle) { + osd_printf_verbose("dlclose\n"); + return 0; +} + +extern "C" void* dlsym(void* handle, const char* symbol) { + osd_printf_verbose("dlsym(%s)\n", symbol); + return NULL; +}