flyinghead / flycast

Flycast is a multiplatform Sega Dreamcast, Naomi, Naomi 2 and Atomiswave emulator
GNU General Public License v2.0
1.33k stars 168 forks source link

iOS Port #168

Closed dunx93 closed 2 years ago

dunx93 commented 3 years ago

Would really love for there to be an iOS port if anyone is willing.

vkedwardli commented 3 years ago

No JIT support is the main drawback, and Apple closed the JIT on iOS 14.4 again: https://twitter.com/altstoreio/status/1354096048650809349

dunx93 commented 3 years ago

what if just made for the lower verisons for now and jailbreaks?

dunx93 commented 3 years ago

that's why i'm still on 14.3

vkedwardli commented 3 years ago

It is always a development nightmare, being an iOS dev, users often report errors on latest version since Apple patched something. For example I just got a report today: iOS 14.5 beta

If I want to test the latest bug, I will need to sacrifice the jailbreakable device...

And installation + distribution is a mess also

dunx93 commented 3 years ago

sounds crappy

dunx93 commented 3 years ago

i'm just used to ios is my reasoning

dunx93 commented 3 years ago

phone wise

dunx93 commented 3 years ago

still i would be willing to put a bounty on this in bountysource

vkedwardli commented 3 years ago

If I understand correctly:

Before iOS 13.6, psychicpaper exploit can be used Before iOS 14, PT_TRACE_ME can be used (W^X JIT only) On iOS 14.2 ~ 14.3 with A12 and newer CPU, CS_EXECSEG_ALLOW_UNSIGNED can be used

From iOS 14 onwards without jailbreaking, tethered launch to enable the CS_DEBUGGED is the last resort. (W^X JIT only)

So in order to play this reliably, you must be using a jailbroken device, tethering to a computer and playing on mobile phone seems a little bit nonsense.

dunx93 commented 3 years ago

i just use signulous to be honest to sign my apps

Spidy123222 commented 3 years ago

If I understand correctly:

Before iOS 13.6, psychicpaper exploit can be used

Before iOS 14, PT_TRACE_ME can be used (W^X JIT only)

On iOS 14.2 ~ 14.3 with A12 and newer CPU, CS_EXECSEG_ALLOW_UNSIGNED can be used

From iOS 14 onwards without jailbreaking, tethered launch to enable the CS_DEBUGGED is the last resort. (W^X JIT only)

So in order to play this reliably, you must be using a jailbroken device, tethering to a computer and playing on mobile phone seems a little bit nonsense.

All of this is not jailbroken jit.

You can use tether launch. Once you tether launch and use detach it will allow you to use it anywhere. There is even a new program for altstore to automatically do it over network instead manually over the network.

It's called altjit and it's part of their altkit system where it will send a command to altserver and it will activate ver the WiFi the computer is on. Once it's activated it detached debugger from computer and after that it will allow you to use jit outside of network or anywhere until the background task is ended so not closing the app in background.

Altjit: https://github.com/rileytestut/AltKit

It's in beta so it is behind patreon atm (comes out later publicly once tested more) but you can also use this lovely workaround that me and jkcoxson made to activate with any computer manually rn. I use it everyday and it is not that bad.

Manual Workaround: https://github.com/jkcoxson/DiOS-Instructions

There is also another method with tether launching using a app called jitterbug where it can activate jit on other iOS devices or it's self if you have a paid developer account to apple.

Jitterbug: https://github.com/osy/Jitterbug

If you don't know where to sign apps ofc you can use altstore to sign apps.

Altstore: https://altstore.io

All of these don't need a cable to use every time it's all wireless. Jitterbug works anywhere if your have that paid dev account for self activation. I talk to a dev that might make it better on signing apps and jit by using a vpn method.

iOS works best on metal backend and that's not crossplay Latvian so one would need to use MoltenVK(Vulkan) which is open source. iOS supports OpenGLES 3.0 latest which is unmaintained. Some emulators uses OpenGLES well on iOS like play!. But play!'s experimental Vulkan backend on iOS runs better on quite a few games.

lonkelle commented 3 years ago

I just spoke with the PPSSPP and Play! Devs about this on GitHub. It’s much easier to just follow those train of comments to understand Altkit / AltJIT for Jailed users (which is wireless and automatic) - https://github.com/hrydgard/ppsspp/issues/14570

vkedwardli commented 3 years ago

All of this is not jailbroken jit.

@Spidy123222 yes, jailbroken devices wouldn't need those extra exploit. Never heard of AltKit before, seems jitterbug is easier

@flyinghead Actually the slowest component is the ARM7TDMI (ARMv4) sound emulation, is it technically possible to improve the interpreter so that it can run at full speed on the arm64/arm64e (ARMv8.3)?

flyinghead commented 3 years ago

What makes you think the aica arm emulation is slow? The original armv4 cpu runs at very low clock speed so, even when interpreted, it shouldn't impact performance that much. I'm not sure the interpreter can be optimized (it's borrowed from VisualBoyAdvance). However there are dynarecs for all platforms except x86.

Spidy123222 commented 3 years ago

All of this is not jailbroken jit.

@Spidy123222 yes, jailbroken devices wouldn't need those extra exploit.

Never heard of AltKit before, seems jitterbug is easier

@flyinghead

Actually the slowest component is the ARM7TDMI (ARMv4) sound emulation, is it technically possible to improve the interpreter so that it can run at full speed on the arm64/arm64e (ARMv8.3)?

@vkedwardli You are assuming that they are exploits. They are not exploits, it uses methods Xcode uses to get a debugger. Libimobiledevice is what is used in all of them and is used for things like iTunes and Xcode. Xcode also has a attach and detach feature that all of these methods use. It's more of a workaround of a problem like other things. Using intended behavior on detach which is being utilized for ability to use jit anywhere away from a computer instead of being on same network whole time.

Keep in mind developers uses these features also so it's most likely not going away.

Libimobiledevice: https://libimobiledevice.org/

Clarification on altkit having the altjit system it's just a automated system to do jit like how all the others are doing it.

Before iOS 13.6, psychicpaper exploit can be used

Was iOS 13.5 that broke it so highest version was 14.4.1

From iOS 14 onwards without jailbreaking, tethered launch to enable the CS_DEBUGGED is the last resort. (W^X JIT only)

I wouldn't use iOS deploy for this but I guess for some prefer it.

From what I remember you can use other forms of jit but needs to be separated. I'm not quite sure on it but here is a thing about how Dolphin got ported to iOS for its jit and other stuff. Great port btw especially latest version. You prob can ask them in their discord for latest information (it's in the dolphin pull) or something like that.

https://github.com/dolphin-emu/dolphin/pull/8492

https://github.com/dolphin-emu/dolphin/pull/8492#issuecomment-560082703

Also has a site for people https://dolphinios.oatmealdome.me/

vkedwardli commented 3 years ago

@Spidy123222 I didn't assume they are exploits, I only stated that psychicpaper is an exploit...

Was iOS 13.5 that broke it

yea my bad, you are right, it is patched in iOS 13.5 beta 3

Anyways, JIT won't work without attaching a debugger for non jailbroken devices, unless an app can attach itself (which it can't without some weird VPN, for paid dev account only)

So in order to play this reliably, you must be using a jailbroken device, tethering to a computer and playing on mobile phone seems a little bit nonsense.

I don't think any workaround could change my understanding on this situation, yes you can find a PC to attach the debugger, but why don't we play on the PC directly then?

vkedwardli commented 3 years ago

@flyinghead

What makes you think the aica arm emulation is slow?

I didn't investigate at all, but I can run the game near to 60fps without sound on recent iOS devices (meaning the SH4 interpreter is fast enough?), once sound is enabled, fps is dropped to 2x fps.

lonkelle commented 3 years ago

yes you can find a PC to attach the debugger, but why don't we play on the PC directly then?

AltJIT (enabled via a single function in AltKit) is wireless and automatic. It runs the debugger and immediately detaches. Keeping any jailed app in a "JIT Enabled" state until iOS terminates it (background or foreground).

This technique to enable JIT isn't going away for jailed users given it's an integral part of the dev toolset. It's wireless, it's automatic, and it lasts after close (until it terminates from memory which can be elongated - my longest is 13 hours in testing). I'm working on enabling it from anywhere (because you're right that attaching itself works but only from a paid account). It is possible to enable it from anywhere (completely untethered) but the library won't change, you'd still use AltKit to enable it.

Jitterbug is not easier because it's all manual. AltKit literally handles everything for the user. It's up to you how much you ease you want to give jailed users to run your app. But, AltKit is really only the one function which enables JIT wirelessly and automatically if it detects that it can.

vkedwardli commented 3 years ago

@lonkle if AltKit can work over the internet then it doesn’t require any local PC setup

lonkelle commented 3 years ago

@vkedwardli Working over the internet is a WIP. It’s possible, but it’s not what I have currently available.

AltJIT requires the user to be on their home network (or any network that has an AltServer) for just a few seconds and it activates + detaches instantly and the user can then turn off WiFi if they want to and leave their bourse, play for hours. It’ll stay enabled as long as the app stays in memory.

And tho this is possible OTA, it’s a lot harder - but it doesn’t matter since for the end developer to use AltJIT in their project, they’ll use AltKit and it’ll always be the same function to enable JIT. Right now it has the limitation of being home for a few seconds. Later on, that could very well change to activate anywhere which is being experimented with by me.

I personally don’t mind if you use AltKit or not. This was made for the iOS app dev community who had jailed users that needed JIT and they wanted options. This is just one option. Jitterbug is the other.

Some users will prefer this, others will prefer Jitterbug.

lonkelle commented 3 years ago

And installation + distribution is a mess also

This is exactly why we developed https://altstore.io for apps like yours. Installation and distribution is handled all by AltStore and AltServer, and works for free accounts and re-signs the apps in the background so they never need to refresh.

If JIT is genuinely your only barrier, then distributing via AltStore (where we also need JIT and will continuously keep AltJIT up to date - as it broke in 15.0b2, fixing it now).

It just takes most of the strain off of ya because we handle so much. Def think about it and cool project! ☺️

lonkelle commented 3 years ago

Wanted to update this that this method is so stable that it even works on jailed mode on the bleeding edge iOS 15b3. This is the only officially supported JIT implementation and it supports 13.3+ -15.0 onwards. It could support below 13.3 but we don’t have a device to test below 13.3.

Here’s a link of PPSSPP using its JIT core on jailed iOS 15.0b3: https://github.com/hrydgard/ppsspp/issues/14570#issuecomment-882574749

flyinghead commented 3 years ago

@lonkle I tried to use AltStore and AltServer to enable JIT code in Flycast but I'm getting an error. I created an IPA of Flycast and sideloaded it with AltStore. It installs and runs fine but it fails when authorizing unsigned code execution. The error I get is unknownUDID.

I also installed Delta through the same channel a test NDS game runs fine so I assume everything is installed and configured properly.

Can you help?

lonkelle commented 3 years ago

@flyinghead Actually that's a promising error.

You see, since AltJIT (AltKit) is in beta - we have yet to update AltStore to embed the iOS device's UDID to the apps AltStore installs.

That will be fixed in an upcoming released. But can do this manually until we make it automatic.

You have to unzip the IPA you're going to install, open the Info.plist and add a new "key" called ALTDeviceID with the value of your devices's UDID.

After doing that, AltKit should work for ya! Let me know if you run into any other issues with it! ☺️

flyinghead commented 3 years ago

I added the ALTDeviceID to Info.plist and I get a new error: Could not enable JIT compilation. Error Domain=com.rileytestut.AltServer Code=11 "AltServer does not support this request."

flyinghead commented 3 years ago

There is a new iOS port on the libretro branch. You can find it in the github action artifacts for this branch: https://github.com/flyinghead/flycast/actions/workflows/c-cpp.yml

You will need to use AltStore to install it and enable JIT, or use another method of your choosing.

For AltStore, you need the latest beta (1.5b5 as of this writing) and you need to add the ALTDeviceIDkey with your device UDID to the app Info.plist (see previous comments). Hopefully this won't be necessary with future AltStore versions.

eduo commented 3 years ago

Is the libretro core the only way to run Flycast in iOS at this moment? Not demanding anything here, but I wanted to recommend it to a friend who only wants to emulate Dreamcast, and I thought having them trying to get the whole retroarch set-up just for it could be a bit on the sadist side :)

Now that altjit seems to be supported, speed in jailed devices should be acceptable enough to recommend it, should a standalone app (or dedicated flycast IOS front-end) exist.

flyinghead commented 3 years ago

Despite the name of the branch, this is a standalone iOS app, not a libretro core.

eduo commented 3 years ago

You're right. I missed the pointer.

I'm happy to confirm it works. Will it become a compiled target in upcoming releases in the future? Wondering if there's documentation I could share as well regarding gestures and file locations allowed (support for files outside the bundle, for example)

JoeMatt commented 3 years ago

I added the ALTDeviceID to Info.plist and I get a new error: Could not enable JIT compilation. Error Domain=com.rileytestut.AltServer Code=11 "AltServer does not support this request."

I was getting the same error testing my app fwiw. I wasn't sure if it was because of our use of iCloud and extensions, but I don' think flycast uses those so that fact helps dwindle down what it is.

https://github.com/Provenance-Emu/Provenance/pull/1544

lonkelle commented 3 years ago

@JoeMatt I contacted @flyinghead on Discord and helped them work out the issue. I'll send you a friend request there and see if I can help figure out your issue with it as well. ☺️

JoeMatt commented 3 years ago

@JoeMatt I contacted @flyinghead on Discord and helped them work out the issue. I'll send you a friend request there and see if I can help figure out your issue with it as well. ☺️

Sounds good, I'm in the discord too. No rush atm, we need to do bug fix in the next few days so I may not be able to respond immediately.

flyinghead commented 3 years ago

Will it become a compiled target in upcoming releases in the future?

Yes

Wondering if there's documentation I could share as well regarding gestures and file locations allowed (support for files outside the bundle, for example)

There's no iOS documentation for now. Press DPad UP+DOWN or LEFT+RIGHT to open the in-game menu. For now, only files in the bundle are accessible but I hope to provide more options in the future.

flyinghead commented 2 years ago

Done