Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add prototypical SDL support. #403

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft

Conversation

ecraven
Copy link
Collaborator

@ecraven ecraven commented Oct 20, 2021

This is just a Merge Request to discuss, it is not ready to be merged in any way.

UPDATE: read along, all of the following is not true any longer ;)

Build with cmake. This will create a new backend (ldesdl).

  • Resolution can only be set by editing the variables in sdl.c (UPDATE: edit the init_SDL call in main.c)
  • Key repeat does not work.
  • Still problems with keysyms that implicitly contain modifiers.
  • The entire screen is bitblted onto the SDL display every frame.

Build with cmake. This will create a new backend (ldesdl).
- Resolution can only be set by editing the variables in sdl.c.
- Key repeat does not work.
- Still problems with keysyms that implicitly contain modifiers.
- The entire screen is bitblted onto the SDL display every frame.

Support keyboard, and work on mouse.

Kind of working...

Fix display resolution problems.
@ecraven
Copy link
Collaborator Author

ecraven commented Oct 20, 2021

Open points:

  • Right now, the framebuffer is "manually" copied into the SDL surface. Ideally, SDL would just directly use it, but SDL does not seem to support 1-bit per pixel data, so unless we switch to the color display code in maiko, I think we always need to copy the data. It seems to be fast enough, so there might be no need to optimize this with only copying the dirty rectangle. (UPDATE: see last bullet point about "fast enough")
  • Key repeating doesn't work, I haven't investigated closely, but I don't actually see how it would work, because the bit is already set, setting it again won't do anything? I need to look at the XWINDOW code some more to understand how it works there.
  • Right now there is no support for moving the area you see of the screen (the right and bottom scrollbar are missing, as well as the bit gravity thing). The window can be resized, but it will always anchor on the upper left.
  • If you have keys that directly produce "shifted" keysyms, those won't work correctly. There's a problem here with the order in which SDL sends the keydown events (for example, it seems to send 9 down, shift, 9 down, the second of which is ignored because it is already pressed, so the key seen by Medley is 9, not '('), still need to find out how to fix this.
    UPDATE: turns out this is due to the "bitblt" being so slow that it sometimes makes SDL read all keyboard input at the same time. SDL does not add the OS timestamps correctly, but uses its own, so it sometimes reorders them. I'd consider this a bug in SDL, but it should be possible to work around this by just making the bitblt faster ;)

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 20, 2021

UPDATE: new commit added, which is a bit faster at bitblting, and also supports pixel scaling (doubling, trippling, etc.)

@masinter masinter marked this pull request as draft October 20, 2021 19:24
@masinter
Copy link
Member

Is key repeating done in Lisp? On the D-machines it must have been...

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 20, 2021

@nbriggs I think with the last push it should now only update the damaged parts. I didn't look into expose events in SDL yet, not sure how well those are supported.
If you have a bit of time, could you maybe try whether this works for you on a mac and even possibly on windows?
If it seems to work ok, I'll refactor everything so that the diffs are easier to understand ;)

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 20, 2021

I can try on MacOS, assuming I can install/compile SDL without having to use "brew" (or anything like it). I don't have a Windows box.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 20, 2021

I can try on MacOS, assuming I can install/compile SDL without having to use "brew" (or anything like it). I don't have a Windows box.

That would be great! Please take care to use SDL2, not any of the older versions ;)

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 20, 2021

After installing the macOS SDL development framework...

CMake Error at CMakeLists.txt:77 (FIND_PACKAGE):
  By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SDL2", but
  CMake did not find one.

  Could not find a package configuration file provided by "SDL2" with any of
  the following names:

    SDL2Config.cmake
    sdl2-config.cmake

  Add the installation prefix of "SDL2" to CMAKE_PREFIX_PATH or set
  "SDL2_DIR" to a directory containing one of the above files.  If "SDL2"
  provides a separate development package or SDK, be sure it has been
  installed.

While they provide a development setup with a Framework to install, they forgot to include any cmake configuration stuff in there, so it'll take a while to sort that out.

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

The CMake vs SDL answer is: While the SDL (version 2) disk image installs it as SDL2.framework, the CMake application for macOS, which is distributed with a .cmake file for SDL, believes that it is always called "SDL" not "SDL2" but is happy to locate that and tell you it's version 2. So... I renamed everything to just plain SDL and it configured fine.
However -- it won't compile because:

src/main.c:519:3: warning: implicit declaration of function 'init_SDL' is invalid in C99 [-Wimplicit-function-declaration]
  init_SDL(1600, 1024, 1);
  ^

and

src/initdsp.c:277:3: warning: implicit declaration of function 'sdl_bitblt_to_screen' is invalid in C99 [-Wimplicit-function-declaration]
  sdl_bitblt_to_screen(0, 0, sdl_displaywidth, sdl_displayheight);
  ^
1 warning generated.

and the actual fatal one:

src/keyevent.c.o
In file included from /Users/briggs/Projects/maiko-ecraven/src/keyevent.c:61:
/Users/briggs/Projects/maiko-ecraven/inc/xwinmandefs.h:3:10: fatal error: 'X11/X.h' file not found
#include <X11/X.h>     /* for Window */
         ^
1 error generated.

But after I fixed that, and a few more similar, something still knows that it used to call itself SDL2. Perhaps I can take the opposite approach, which is to copy /Applications/CMake.app/Contents/share/cmake-3.19/Modules/FindSDL.cmake to FindSDL2.cmake and fix up bits there to reflect the SDL2 name where appropriate. I'll also check and see if cmake-3.22 (RC1) has updated anything to do with SDL(2).

@masinter
Copy link
Member

smilar problems in Windows
https://www.matsson.com/prog/sdl2-mingw-w64-tutorial.php
still didn't solve the cmake lacunae.

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

I haven't got all the kinks out of the SDL2.cmake (copied/modified from the CMake distributed SDL.cmake) but I got it far enough that lde and ldesdl link and run

Even with the selective update, the sdl_bitblt_to_screen() is way way too slow.
Try doing FB *.*;* or bringing up a TEdit window on a moderate size file.
The Maiko "color" code isn't the answer -- that's for a separate color window which isn't the main screen.
Basically, the display code needs to do 1-bpp bitblt screamingly fast, which seems to be where XPutImage has an advantage over SDL.

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

The includes in sdl.c for SDL files should be just "SDL.h" and "SDL_keycode.h" -- the SDL/ is deprecated (according to the CMake people) because FreeBSD doesn't put these includes in an SDL subdirectory.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021 via email

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

Yeah, I've been following along. It works much better now. FB *.*;* in the Lispusers directory is a good test for how it's doing on single character BLTCHAR, and that seems to be acceptably fast now.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021 via email

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

If we can sort out the input (and things such as doing the 3-button mouse emulation) it's probably worthwhile pursuing.
When I do a bunch of FB redisplays, over a period of 35s runtime, the sdl_bitblt_to_screen() is responsible for 36% of the execution time -- so it's still more than it should be. Under X11, clipping_Xbitblt() which is the equivalent, is too small to show up.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021 via email

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021

OK, finally got an mxe setup working for cross-compiling. From what it looks like, this codebase has never been compiled on anything like windows before, right? So we would need to add all those #ifdef _WIN32 all over the place?

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

No #ifdef _WIN32 in the source files -- it already has, in maiko/platform.h

#if defined(_WIN32) || defined(__WINDOWS__)
#  define MAIKO_OS_WINDOWS 1
#  define MAIKO_OS_NAME "Windows"
#  define MAIKO_OS_DETECTED 1
#endif

The last time it was compiled on a Windows-like system it wasn't Windows, it was MSDOS, so there would be a lot of stuff to adjust, and there are things that will likely be MAIKO_OS_UNIX_LIKE (or not).

I forgot to mention the #if defined(XWINDOWS) around #include "xwinmandefs.h" that was necessary.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021

I think I already added and pushed that, ran across that too.. so, what's the best way to proceed here? I'm no windows programmer, but I can try to fix things up.
However, this is mostly unrelated to SDL, so maybe we should try to separate those two changesets.
Should we discuss the next steps on monday?

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

I think a Windows change set is orthogonal to SDL, though enabled by it.
The last change you made to the CMake configuration stopped it from compiling on macOS

[  2%] Linking C executable lde
ld: library not found for -lSDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I think I need to make more changes in the FindSDL2.cmake. I believe all the variables it creates have to be SDL2_... instead of SDL_...

Yes, we should talk about it on Monday. I'll continue to poke at getting things working properly on the mac between now and then, though.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021

Sorry, it's the SDL2::SDL2 vs. SDL2 alone thing.. for windows, only SDL2 alone worked, on linux I need SDL2::SDL2 too.. I need to learn more cmake
If there's anything I can help with to make things easier for you, please tell me. If that seems like a reasonable approach, I'll let you work on MacOS stuff, and not touch things too much for now. If it works satisfactorily on MacOS too, I'll try to clean up this entire changeset.
What are the things that are still missing, apart from the following?

  • 3 button emulation: is there code for this? how should it work?
  • command line parameters: I'll just add three parameters, width, height and pixelscale, ok?
  • input: as the "problem" only appears in my very specific setup, I don't think this will be an actual problem for others.. does keyboard and mouse input work ok for you? any glitches there?

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

These two changes broke compilation on macOS and FreeBSD --

-  SET(MAIKO_DISPLAY_SDL_LIBRARIES SDL2::SDL2)
+  SET(MAIKO_DISPLAY_SDL_LIBRARIES SDL2)

-  TARGET_LINK_LIBRARIES(lde SDL2::SDL2)
+  TARGET_LINK_LIBRARIES(lde SDL2)

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

  • 3 button emulation: is there code for this? how should it work?
    On the mac, XQuartz does this outside of any of our code. One can configure (for example) rCommand and rOption to make the mouse left button click come through as middle or right button. Usually you'd just have a 3-button mouse, but a mac trackpad or "normal" mouse has only one button (but can be configured for right button on two-finger click)
  • command line parameters: I'll just add three parameters, width, height and pixelscale, ok?
    That would work for a few days. It should match the existing options for things like -t "window title" and -m memorysize and the same -sc WxH syntax for window size, otherwise we end up having to special case everything in the run-medley script for no good reason.
  • input...
    There seem to be some glitches, but I can't characterize them yet. I need to systematically explore. It will be easier when I have all the mouse buttons.

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

BTW -- on FreeBSD, with default SDL2 install, it relies on the X11 back end, compiles/links without error, but generates

$ lde
requested width: 1888, height: 1088
initialised
Window created
Creating renderer...
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  144
  Current serial number in output stream:  145

if you try to run it when ssh'd into the box with X11 forwarding back to an XQuartz mac.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021

BTW -- on FreeBSD, with default SDL2 install, it relies on the X11 back end, compiles/links without error, but generates

$ lde
requested width: 1888, height: 1088
initialised
Window created
Creating renderer...
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  144
  Current serial number in output stream:  145

if you try to run it when ssh'd into the box with X11 forwarding back to an XQuartz mac.

It looks like it is trying to open an OpenGL context, and I'm not sure how well that would work over the network :-/ This is probably something that SDL cannot support.

@ecraven
Copy link
Collaborator Author

ecraven commented Oct 21, 2021

ok, fixed the build on ubuntu. still trying to understand how that SDL2::SDL2 stuff in cmake works exactly, so that we can make it work on macos and ubuntu and other linuxen. might be related to old versions of libsdl2 not shipping all the correct cmake files :-/

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

Well all the references to X11 libraries are X11::X11 so with no understanding of what it's really doing I'm not surprised that the SDL2 libraries are SDL2::SDL2

@nbriggs
Copy link
Collaborator

nbriggs commented Oct 21, 2021

In all of these (CMake driven) builds it needs to do both X11 and SDL

@ecraven
Copy link
Collaborator Author

ecraven commented Nov 9, 2021

@nbriggs I've tried it, but the code (strangely) only displays entirely black... still investigating what's wrong here, I think it's related to the RGB332 pixelformat..
I've tried to run FB and noticed that the initial display seems fast enough, but Shaping the window is abysmally slow.. any ideas as to why this is?
From looking at the damage notifications, it seems that each character is drawn one by one, and we get two damage notifications per character?

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 9, 2021

@ecraven -- I'll look at the FB speed, I suspect it's mostly in enumerating the files (again) when its reshaping, and it handles it differently the first time around.

I compiled on FreeBSD 13.0, and over an SSH connection it used X back to my mac, with a correct display, but too slow to do much.

You'll have noticed that I used the same pixel format that you did. I'll tidy up the allocation of the intermediate display buffer so that it's easier to change the pixel size and still get the buffer the right size.

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 9, 2021

@ecraven -- While looking at the buffer related things I also looked at what textures the renderer supports (on a mac), and it says it's an "opengl" renderer, with support for textures

"SDL_PIXELFORMAT_ARGB8888"
"SDL_PIXELFORMAT_ABGR8888"
"SDL_PIXELFORMAT_RGB888"
"SDL_PIXELFORMAT_BGR888"
"SDL_PIXELFORMAT_YV12"
"SDL_PIXELFORMAT_IYUV"
"SDL_PIXELFORMAT_NV12"
"SDL_PIXELFORMAT_NV21"
"SDL_PIXELFORMAT_UYVY"

so I guess choosing one of those would result in less conversion overhead? I'm setting up a version which picks up the first format returned and then asks for the black & white pixel values for that format, and the width of a pixel (in that format) in order to create the intermediate buffer. That way it should adapt a little to the underlying machine.

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 9, 2021

@ecraven -- Was there a reason not to do SDL_TextureLock()..SDL_TextureUnlock() and update from the Lisp screen bitmap directly into the texture pixels? This avoids having any intermediate buffer, as far as I can see. You have to get the locking region exactly correct because anything that is locked MUST be updated.
I've got an almost working version that does this (and am tracking down the "almost")

@ecraven
Copy link
Collaborator Author

ecraven commented Nov 9, 2021

@nbriggs just my lack of knowledge ;D thanks for working on this!

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 9, 2021

The SDL documentation does not give the clearest examples... I ran across the LockTexture stuff by accident as I was looking for something else, and it suggested that if you were using streaming textures you should lock and update the texture pixels directly. I'll push a new version, possibly as a separate branch, as soon as I've got something that gets the displayed bitmap correct, even if it's not the cleanest!

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 9, 2021

@ecraven -- I've pushed a branch named sdl-texture-direct, started from the current sdl branch.
Totally messy. Defaults to the SDLRENDERING version. In the case of streaming textures, I don't understand the function of SDL_RenderCopy & SDL_RenderPresent -- but they seem to be necessary.

With these changes, at least on my Mac, an idling Medley which is just flashing the cursor takes very little CPU time (also has background-yield loaded, though).

Compile it after configuring with cmake .. -DCMAKE_BUILD_TYPE=Release if you want to see the actual speed, since ...=Debug will have it spend all its time in sdl_bitblt_to_texture() twiddling bits.

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 16, 2021

Things to think about:
- cursors need to honor the pixelscale if we're going to have pixelscale
- setting the cursor position needs to clip to screen size
- access to the cursor bitmap needs to account for host byte ordering with the (predefined) access macros, as with the access to the display memory, GETBASEWORD and friends

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 22, 2021

@ecraven -- Looking at the frame-rate: the process_SDLevents() call, driving the display update, is from the part of the emulator code where the Lisp periodic interrupt handling happens. I trigger the Lisp interrupt checks off the ITIMER_VIRTUAL which is set at 10 ms of process execution time. There are a very few situations where it could reenter this code in under 10 ms (experimentally, about 0.2% of cases), so I agree with your comment that we could remove the timing check.

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 24, 2021

How about this for situations where we have both SDL and X11 available -- in ldeboot.c if both SDL and XWINDOW are defined accept the "-d"/"-display"/DISPLAY environment variable, and if it's "SDL|sdl" then try to start ldesdl, otherwise pull out the display name and check it as it currently does and if the X connection succeeds start ldex. If only one is defined there's no choice, just do it.
[edit:] Except that that would preclude using SDL+X11 backend, since you would be overriding the DISPLAY that SDL+X11 backend would connect to. On the other hand, if you've got X11 on a remote connection it's way faster than SDL+X11. Maybe we should just add "-sdl" as an option. Opinions?

@lassik
Copy link

lassik commented Nov 25, 2021

How about this for situations where we have both SDL and X11 available

Nowadays there exist at least two alternative X environment variables, DISPLAY and WAYLAND_DISPLAY. If you want both in the same executable, it's best to have a separate command line flag like --display sdl or --display x.

Note that other backends besides X and SDL will probably be added some years down the line.

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 25, 2021

OPTIONS
       Most X programs attempt to use the same names for command line  options
       and  arguments.  All applications written with the X Toolkit Intrinsics
       automatically accept the following options:

       -display display
               This option specifies the name of the X server to use.

this would preclude using -display x, since in the direct to X11 case we use the X toolkit to parse the command line for all the other X related options. I looked at the SDL source and we'd be OK with -display sdl since it passes NULL to XOpenDisplay and (from XOpenDisplay doc) "On a POSIX-conformant system, if the display_name is NULL, it defaults to the value of the DISPLAY environment variable." (that is, nobody is helpfully parsing any command line args behind the scenes).

@lassik
Copy link

lassik commented Nov 26, 2021

Good point.

Or alternative names:

  • -backend sdl
  • -ui sdl

@masinter
Copy link
Member

If we're considering changing the structure of lde, ldex, command line invoaction etc. in order to account for a new backend, now that there's a PoC for this, let's take a moment to consider the context. The scripts around run-medley and lde and etc. were all pretty ad hoc. I thought I heard there was some possibility of having just one executable instead of two. And changing the name from "lde" to "medley", I think. And doing a better job of invoking pixel scaling ... And...

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 26, 2021

possibility of having just one executable instead of two.

This makes it a bit more difficult to have a setuid root executable that can open the network device and then drop privs and fork the rest of the emulator. People would be rightly suspicious of depending on a larger piece of code that may or may not correctly drop (and not attempt to regain) root privs.

However, if we think that it's possible on all the systems we care about to assign network access capability to either the user or the program, without giving root access, it's certainly worth considering.

There's also the possibility of getting rid of the initial fork/exec and pipe communication for the external processes -- CREATE-PROCESS-STREAM and the like, if posix_spawn() is available on all the systems we care about (is it available on Cygwin? Windows?)

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 27, 2021

Updated the sdl-texture-direct branch with some cursor cleanups.
Now moves the cursor up the cursor linked list only if it's past the first two items -- Medley tends to flip back-and-forth so there's no reason to reorder if it was there because it will probably go back shortly. Fixes up type usage to match emulator types and accounts for host byte order when accessing the emulator cursor bytes.

@masinter
Copy link
Member

@nbriggs cygwin` isn't important if we have Windows/SDL. Whether Windows implements copy-on-write isn't clear. (Interlilsp-10 on Tenex had copy-on-write).

https://news.ycombinator.com/item?id=19621973
https://news.ycombinator.com/item?id=18073906

@lassik
Copy link

lassik commented Nov 27, 2021

This makes it a bit more difficult to have a setuid root executable that can open the network device and then drop privs and fork the rest of the emulator.

Setuid is perhaps the biggest anti-pattern in Unix programming - it should only be used for a handful of system programs like su and sudo. Applications should never use it.

If the ethernet device needs to be opened, it would probably be best for the sysadmin to create a group for users who need access to the device, then chown the device file such that the group owns it. Would this work?

If that doesn't work, there should be a minimally small daemon program that runs as root (but is not setuid) and gives other programs access to the device.

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 27, 2021

If the ethernet device needs to be opened, it would probably be best for the sysadmin to create a group for users who need access to the device, then chown the device file such that the group owns it. Would this work?

That's the second choice if your system lacks a security capability architecture such as Solaris' role-based access control.

If you install Wireshark on a Mac, using libpcap, it does the group setup etc. for you -- installing /Library/Application Support/Wireshark/ChmodBPF/ChmodBPF that is run by launchd to create and set group access on the /dev/bpfNNN devices to group access_bpf. I haven't investigated whether ChmodBPF was distributed with libpcap or wireshark.

Related stuff: We've used the DLPI and NIT interfaces in the past, but if we're going to do raw ethernet access now then libpcap/BPF is probably the way to go. I think that BPF is now available on all systems where DLPI/NIT are (or were), so we can simplify the code.

@lassik
Copy link

lassik commented Nov 27, 2021

Neat! You know much more than I do about this stuff. libpcap is indeed popular nowadays. Whatever Wireshark does is probably a reasonable starting point.

@nbriggs
Copy link
Collaborator

nbriggs commented Dec 7, 2021

Updated the sdl-texture-direct branch with the code to fully deal with cursors in pixel-scaled presentation.

@orcmid
Copy link

orcmid commented Dec 20, 2021

I do mostly desktop Windows, and the amount of tacit knowledge there is about Maiko and Medley melts my brain.

I am interested in graphic systems for gaming and took a deeper look at SDL2 because of this conversation. I have run into much chatter about raylib/SDL2/OpenGL/Vulkan and have been sticking with raylib for my own education at this point. My way ahead is by reverse-engineering sources (and CMakes) down to where I can do it all with command-line builds, getting the individual modules to compile, and then attempt integrated builds of .exe files. (I am looking to see how I can understand maiko that way, using procedures I am using elsewhere anyhow.)

With regard to SDL2, this is what put me off.

The best way to learn how to use SDL is to check out the header files in the "include" subdirectory and the programs in the "test" subdirectory. The header files and test programs are well commented and always up to date.

I don't believe that statement. The README for Windows is out of date and also peculiar concerning Visual Studio version dependencies. I followed an #include chain looking for where things like SDL_NO_RETURN and a bunch of others are introduced and got lost, the so-called well-commented being elusive. I also saw somewhere that SDL2 builds as a DLL only; t can't remember where I saw it. There are some consistencies where SDL_Mumbles are used and C/C++ types are used. Sometimes specfic-size number types, other times not. Much to tease out.

I appreciate that configuring for different platforms is tricky. I was never very happy about how that worked when Unix flavors were the platform everywhere that EBCDIC wasn't. It's more difficult now, and having code uncluttered by the platform dependencies everywhere is seriously tricky.

I don't have an answer. I just want to complain and prey that #ifdef and `#elif' not be the answer running through all the code. (This from a guy who only does release builds too :)). It is regretable that SDL2 does not smell better.

@masinter
Copy link
Member

bump will recent changes to maiko make this harder or easier to complete?
Were we waiting for a bugfix from SDL?
Do @devhawala 's dodo changes reduce the need for root or special group access?

@nbriggs
Copy link
Collaborator

nbriggs commented Sep 29, 2022

It means there is a lot of editing to do. We were waiting for the SDL people to fix an integration with CMake issue, they may have got around to releasing that, I haven't checked recently as they were moving very slowly. Re: dodo changes -- not sure, I haven't read the code.

@devhawala
Copy link
Contributor

The Nethub extension to Maiko does not need any root/setuid/setgid priviledges: connecting to the Dodo Nethub uses plain TCP/IP client system calls.

The purpose of the Nethub is to avoid any special APIs or executable rights if possible. The only exception may be the NethubGateway which is a Nethub-client connecting to a PCap device, allowing client machines (real or emulations) to connect to Dodo XNS services (see Dodo - Topology), this one may need root rights to use the PCap device (at least on Linux).
But this is not the case for Maiko with Nethub support, as Maiko connects "natively" (directly through TCP/IP) to the Nethub.

BTW: some months ago i stumbled over the Nano-X Window System, which allows programs using one out of several UI-APIs to have their UI running on many other platforms (i did'nt have time to play with it yet, so no idea if it really works or which requirements must really be fulfilled)

@nbriggs
Copy link
Collaborator

nbriggs commented Nov 13, 2022

I have successfully rebased the interlisp/maiko SDL branch onto the most recent master and rebuilt with current SDL2 (2.24.2) on the Mac.

Required a fix to the SDL2 installation because the installed framework include files refer to an SDL2 subdirectory (#include <SDL2/SDL_...>), but the the include files are all at the same level in /Library/Frameworks/SDL2.framework/Headers. Temporary fix is to ln -s . SDL2 in the Headers directory. Problem reported as libsdl-org/SDL#6513

@masinter
Copy link
Member

masinter commented Dec 2, 2022

I wanted to try this on Windows, but I was left pretty confused about which SDL configuration to try.
Do we still need cygwin even if we don't need X?
Which config of SDL should I start with, out of the many available in
https://github.com/libsdl-org/SDL/releases/tag/release-2.26.1

@nbriggs
Copy link
Collaborator

nbriggs commented Dec 2, 2022

Maiko depends on POSIX system calls for things as well as needing to talk to the keyboard/mouse/display.

  • MINGW lets you use gcc to compile programs that use Windows APIs (not POSIX) so that's not obviously what we want, unless the Windows APIs are source compatible with the POSIX APIs (and some of them might be)
  • Cygwin gives you a runtime library that translates between the POSIX and Windows APIs, so we'd probably want that
  • SDL used to be built/packaged by someone for Cygwin, but they appear to have abandoned that in 2015 or so
  • So you'll need to install the SDL2 source and compile it in a cygwin environment and then use the library that that produces to link with Maiko (plus installing the include files where a Maiko compile will find them) and SDL will presumably use some graphics output and keyboard input that I don't have any way of identifying.

@orcmid
Copy link

orcmid commented Dec 2, 2022

@nbriggs Maiko depends on POSIX system calls for things as well as needing to talk to the keyboard/mouse/display.

I don't understand enough about connecting the dots. I do wonder if using the Windows Subsystem for Linux (WSL) would give you a more direct level of POSIX substrate. SDL should work in that case.

A farther reach: The Standard C libraries are supported for native Windows builds. That may not be enough of POSIX and there is the question about SDL atop it, including how display loops and whatnot are accomplished at that level. I suspect there might be a show-stopper or simply too much work. I didn't check to know what the dependencies on Windows APIs might be presumed by the SDL distributions for Windows.

@nbriggs
Copy link
Collaborator

nbriggs commented Dec 2, 2022

@orcmid -- Maiko does work on WSL with no problem. Larry would like to have an option to be more Windows-native, for reasons I don't understand except for reducing friction for people to run it on Windows without the overhead of installing WSL and (potentially) an X server. SDL was promoted as a way to avoid having to have X and to have native display windows on many systems, and it does that, but that's not the only thing that needs to be solved to get to that state.

It's entirely possible that Windows has got close enough to source compatibility with the simple POSIX functionality Maiko needs that it would be trivial to compile for it, if we can drive the compilation using either "make" or "CMake" -- neither setting up VSCode projects for Windows, nor XCode projects for the Mac seem like good investments of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants