gregdivis / Aeon

C# x86/DOS emulator
Apache License 2.0
50 stars 7 forks source link

Linux and Mac support #5

Open maximilien-noal opened 2 years ago

maximilien-noal commented 2 years ago

Hello

Thank you for this very impressive emulator.

I already started working on replacing WPF with AvaloniaUI, to make it work with Mac and Linux too.

One issue is sound, it seems that TinyAudio would have to use OpenAL on macOS (I don't have a mac to test this), and ALSA on Linux (I use Linux daily, but I barely know anything about ALSA's API)

I've seen a lot of examples for both, but it's a lot of work.

Some other NativeMethods classes are also Windows specific.

For now, I labelled them with

[SupportedOSPlatform("windows")]

and return null on non-Windows OSes in Audio.CreatePlayer...

Anyway, I'm trying to see right now if I easily and quickly can add an AvaloniaUI client. Should be relatively simple.

If you are interested to see the action, it's happenning at Aeon-Staging. :)

gregdivis commented 2 years ago

Thanks!

I wrote most of Aeon over ten years ago, starting it on a whim after I got annoyed that I couldn't resize the window in DOSBox (seriously). At the time I just wanted to see if a similar emulator would be fast enough in .net, and ended up taking it a lot farther than I thought I would. I kind of revived the project a couple years ago and started making a few improvements and moving to .net core.

Anyway, I'd love to see it taken cross platform. I honestly just have almost no time to work on this anymore, so I'm happy to see someone else able to use it for something. AvaloniaUI looks interesting, I'll be sure to follow your progress there.

As for TinyAudio, that was something I threw together with the eventual goal of getting Aeon more cross platform. Before that, I just had it call into DirectSound directly from the audio emulation layer -- so it's a bit better :) I had every intention of adding ALSA support to it at least, but never got to it (I also have no experience with it). If you know of something better to use, by all means give it a try. I pulled that stuff into its own library so it would be easier to replace.

I tried to keep Aeon.Emulator itself OS independent at least. If you can figure out the UI, sound, and gamepad/input, it should be pretty portable. Well, to a point. I can't imagine it working on a big endian architecture as written.

-Greg

maximilien-noal commented 2 years ago

:)

I'm glad to report the following update:

Still, it looks promising (testing Dune here):

image

-Maximilien

maximilien-noal commented 2 years ago

Guess I have this partially fixed : image

What was wrong :

Once this Presenter is fixed, all others will have to be fixed in a similar way, too.

Guess this will break the WPF client...

Avalonia's WriteableBitmap is always such a headache...

maximilien-noal commented 2 years ago

Fixed.

(I intend to provide PR once everything is fixed, even sound, but it might take a while, but that's far, far into the future)

image

And I'll stop spamming for now. :)

gregdivis commented 2 years ago

Very cool! Impressive progress so far! WPF's WriteableBitmap was not very great to deal with either, which is why I ended up cheating and using InteropBitmap instead. Of course, that makes more headaches now with portability, but it seemed like a good idea at the time :)

maximilien-noal commented 2 years ago

Thank you ! :)

Another massive update (well, not in number of lines, but the number of headaches beforehand...) -> TinyAudio uses OpenAL instead of WasApi on non-Windows OSes.

https://github.com/maximilien-noal/TinyAudio-Staging/commit/14b369d00012246f73427c268192cf70427f485d

As usual, I test this with Dune.

I'm glad to have working MIDI music, but sound is clearly a massive headache... Why won't PCM work ??

OpenAL seems to have a lot of undocumented areas... One that is documented however, is that several instances are permitted, so I don't have a clue at the moment about the PCM issue.

maximilien-noal commented 2 years ago

Welp, here's why...

/// <summary>
/// FIXME:
/// We must use a multiple of 16 or else _al.BufferData will return InvalidValue...
/// But at the same time, refusing too small buffers makes PCM not work at all, since we constantly do not buffer anything more...
/// </summary>
private static int GetRemainingLength(ReadOnlySpan<byte> input)
{
    int value = input.Length - (input.Length % OpenALBufferModulo);
    return value;
}
gregdivis commented 2 years ago

Heh, that is...inconvenient :)

Sound is indeed a headache. There's just so many ways for that to break down.

Let me know if there's anything I can do to help!