audetto / AppleWin

Apple II emulator for Linux
GNU General Public License v2.0
50 stars 12 forks source link

MacOsX Build #39

Closed jvernet closed 11 months ago

jvernet commented 3 years ago

Hello,

I'm trying to build on MacOsX (10.13). cmake ask for libevdev and libglesv2. None of them seems to exist on MacOsX.

Are they totally mandatory ?

jvernet commented 3 years ago

After some tweak and using an XCode project created from cmake stuff to ease work, here i am. I do not understand how to load a disk image with ImbGui, but we are close; from then, writing a native cocoa interface should be easy. Screen is far too blury, too much opengl filter ;) gotit

audetto commented 3 years ago

Works. Great! Did you have to change anything? If yes, push the code so I can integrate it.

I do not understand how to load a disk image with ImbGui

You can drag a drop file on the window. Using the D&D radio button you decide where to insert it (there could be HD slots or 2 floppies in Slot 5 too)

from then, writing a native cocoa interface should be easy.

There are already 3 frontends, you can try to add a cocoa version if you want: best is to look at the others and learn what to implement.

Screen is far too blury, too much opengl filter ;)

If you refer to the Apple screen, then this is a feature. Try F9 to switch Video mode or ask AppleWin devs: what you see is pixel by pixel the exact same output as the Windows version.

sh95014 commented 2 years ago

Hi, I'm also trying to build for macOS (Monterey, M1 Pro), using brew to resolve various dependencies...

brew install cmake pkgconfig libyaml minizip libslirp libpcap Boost sdl2 sdl2_image

It was going pretty smoothly until OpenGL:

-- Checking for one of the modules 'opengl'
CMake Error at /opt/homebrew/Cellar/cmake/3.22.1/share/cmake/Modules/FindPkgConfig.cmake:890 (message):
  None of the required 'opengl' found
Call Stack (most recent call first):
  source/frontends/sdl/CMakeLists.txt:20 (pkg_search_module)

I then commented out the pkg_search_module() for OpenGL in ../source/frontends/sdl/CMakeLists.txt

if (SA2_OPENGL)
  # pkg_search_module(GLES2 REQUIRED opengl)
else()

and manually added a -framework OpenGL to AppleWin/build/source/frontends/sdl/CMakeFiles/sa2.dir/link.txt and it was able to build and run.

What I don't know is how to turn this into a PR that lets cmake do the right thing without the makefile hacking.

While I'm here, thank you so much @audetto for this work so far! (Totally hear you about the multitudes of existing front-ends, but I'm really just not a fan of cross-platform UI so my interest is also in a native macOS frontend.)

Cheers!

Screen Shot 2021-12-27 at 5 56 10 PM
audetto commented 2 years ago

I then commented out the pkg_search_module() for OpenGL in ../source/frontends/sdl/CMakeLists.txt

and manually added a -framework OpenGL to AppleWin/build/source/frontends/sdl/CMakeFiles/sa2.dir/link.txt and it was able to build and run.

I am trying to keep this as neat as possible. Try this branch and see if it improves the situation: https://github.com/audetto/AppleWin/tree/cmake

While I'm here, thank you so much @audetto for this work so far! (Totally hear you about the multitudes of existing front-ends, but I'm really just not a fan of cross-platform UI so my interest is also in a native macOS frontend.)

I have tried to split the library in a way that adding a frontend is easy and can reuse a lot of existing code.

Your best option it to mimic the SDL2 frontend and use libcommon2 for some common stuff. What remains in https://github.com/audetto/AppleWin/tree/cmake/source/frontends/sdl and https://github.com/audetto/AppleWin/tree/cmake/source/frontends/sdl/imgui is what you need to rewrite for macOS.

The main issue I see is that without an easy-to-use cross compiler for macos in Linux, your code (if merged) will break often.

sh95014 commented 2 years ago

Your cmake branch works great! Thanks!

I am indeed going down the path of trying to reuse common2. I haven't quite decided how much (if any) of SDL to keep. The display seemed easy enough to replace with Metal (~100 LOC) and I hooked up a rudimentary keyboard because the SDL one was dropping a lot of events (unlike with your build, which is pretty responsive). I don't intend to fork any more than necessary because I do want to take advantage of your merges from upstream AppleWin.

(There's also something pretty cool about sa2 being able to share settings with my app.)

Thanks again!

audetto commented 2 years ago

Your cmake branch works great! Thanks!

will merge.

I am indeed going down the path of trying to reuse common2. I haven't quite decided how much (if any) of SDL to keep. The display seemed easy enough to replace with Metal (~100 LOC) and I hooked up a rudimentary keyboard because the SDL one was dropping a lot of events (unlike with your build, which is pretty responsive). I don't intend to fork any more than necessary because I do want to take advantage of your merges from upstream AppleWin.

What do you want to replace with what?

  1. Video: now using either generic SDL (the renderer) or SDL + OpenGL (for ImGui)
  2. Keyboard: SDL
  3. Gamepad: SDL
  4. Audio: SDL
  5. Config: ImGui
sh95014 commented 2 years ago

What do you want to replace with what?

  1. Video: now using either generic SDL (the renderer) or SDL + OpenGL (for ImGui)
  2. Keyboard: SDL
  3. Gamepad: SDL
  4. Audio: SDL
  5. Config: ImGui

I'm still just experimenting. The video I'm most sure about replacing because I had a pretty hard time trying to get it into a NSView (instead of being the whole window). I'm less sure about the keyboard and other bits. The config I've been rebuilding in native Cocoa using your ImGui code as a guide.

The other problem I just came across is that brew seemed to not want to build universal (x86 and ARM) libraries for their packages, so building a universal binary might be an ordeal...

audetto commented 2 years ago

... The config I've been rebuilding in native Cocoa using your ImGui code as a guide.

Cool. Remember that in ImGui I try to allow for live config changes. This is not supported in the real AppleWin, which runs the config as a modal dialog, and forces a restart if needed.

sh95014 commented 2 years ago

Just updating for posterity... I ended up building a separate native macOS frontend at https://github.com/sh95014/AppleWin, but you should be able to build a working sa2 (at least with imgui) in this repo as well.

sh95014 commented 1 year ago

@audetto sa2 no longer builds on macOS because:

CMake Error at source/frontends/sdl/CMakeLists.txt:4 (add_executable):
  Cannot find source file:

    imgui/imgui/backends/imgui_impl_sdl2.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc

I haven’t looked deeply into it, and I seem to be able to work around the problem by hacking:

/source/frontends/sdl/CMakeLists.txt
-  ${IMGUI_PATH}/backends/imgui_impl_sdl2.cpp
+  ${IMGUI_PATH}/backends/imgui_impl_sdl.cpp

/source/frontends/sdl/imgui/glselector.h
-#include "imgui_impl_sdl2.h"
+#include "imgui_impl_sdl.h"

Any idea why the sdl2 files don’t seem to exist? Thanks!

audetto commented 1 year ago

Nope.

for some unknown (to me) reason, git's default behaviour wrt submodules is really counter-intuitive.

I set submodule.recurse=true in my git options, but I have not fully understood the issue.

sh95014 commented 1 year ago

I think I know why...

I'm picking up https://github.com/ocornut/imgui/tree/8731cc2914a4c08f555bf70d93b54658d5d942ce/backends from July 2022, which doesn't have imgui_impl_sdl2.

You're picking up https://github.com/ocornut/imgui/tree/bfce7750b168b5a857b4379596236dda7b58bd39/backends, which does.

I think I somehow screwed up a merge and ended up pinning an old version of imgui...

...

Following the instructions at https://stackoverflow.com/questions/18770545/why-is-my-git-submodule-head-detached-from-master/55570998#55570998 seems to have fixed things. 🤞

Sorry for the noise!

webspacecreations commented 1 year ago

I never investigated this on a Mac as there are already lots of good A2 emulators there, but I'd be thinking along the lines of Vulkan.

@audetto I haven't been in the loop for sometime, but just compiled on a new Orange Pi 5+ SBC board w/ Armbian and audio latency seems much more in line with an actual Apple II (woohoo!).

sh95014 commented 11 months ago

This one probably should just be closed. Both sa2 and my port now work well under macOS.