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

DOS backend #98

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

DOS backend #98

wants to merge 12 commits into from

Conversation

badlogic
Copy link
Contributor

After adding the Web backend, I figured why not try DOS as well. This PR adds support for DOS, to be more specific, minifb applications compiled with DJGPP, a popular 32-bit DOS compiler based on GCC, running on DOS hardware or emulators that support VESA.

The backend has a couple of limitations:

  • There can only ever be one window open at a time.
  • Window sizes provided to mfb_window_open() must match a VESA mode available on the "machine" the app is running on. 320x240, 640x480, 800x600 work in DOSBox, but may not work on real hardware depending on the graphics card.
  • Character input is limited to ASCII characters. A US keyboard layout is assumed.
  • Key input is limited to the keys as found here: https://github.com/badlogic/minifb/blob/dos-pr/src/dos/DOSMiniFB.c#L18
  • The buffer dimensions passed to mfb_update_ex() must either be a perfect match of the window dimensions, or 1/2 the window dimensions. E.g.:
    • Window 320x240, buffer 320x240: works
    • Window 640x480, buffer 320x240: works
    • Window 640x480, buffer 512x512: fails silently
  • Viewports are not supported.

The current minifb tests do not adhere to these limitations, so I added tests/dos/dos.c.

To compile and run this test, you'll need DJGPP and DOSBox-x. The tests/dos/tools/download-dos-tools.sh script will download all the dependencies (and also a GDB version that understand COFF binaries) to tests/dos/tools/:

./tests/dos/tools/download-dos-tools.sh 

You can then build for DOS via:

cmake -DCMAKE_TOOLCHAIN_FILE=$(pwd)/tests/dos/tools/toolchain-djgpp.cmake -S . -B build
cmake --build build

You can run then run thedos.c test via DOSBox-x:

./tests/dos/tools/dosbox-x/dosbox-x -fastlaunch -exit build/dos.exe

This is what it looks like in DOSBox :)
75c66044b7eff325

I know this has a super low probability to be merged, but I figured someone else who wants to use minifb for little DOS experiments may find this PR and use it.

@Darky-Lucera
Copy link
Collaborator

I’m wondering why is this
Window 640x480, buffer 512x512: fails silently
happening?

@Darky-Lucera
Copy link
Collaborator

There are functions to scale content, with and without bilinear filtering

@badlogic
Copy link
Contributor Author

The silent fail is merely due to me having only implemented a 1:1 blit and a very bad 1:2 blit.

You mean minifb has functions to scale buffers? I shall amend the PR then!

@badlogic
Copy link
Contributor Author

Oh, how did I not see these before? Thanks for the pointer!

https://github.com/emoon/minifb/blob/master/src/MiniFB_internal.c

@badlogic
Copy link
Contributor Author

Alrighty, I fixed it up using stretch_image(). Also adjusted dos.c to test if it actually works. noise.c, input_events and input_events_cpp work too now. The other tests do not, as they require multi-window support.

@Darky-Lucera
Copy link
Collaborator

Darky-Lucera commented Dec 29, 2022

Nice to know.

I'm a little afraid of maintaining so many backends in the future 😅

@badlogic
Copy link
Contributor Author

I totally understand. For what it's worth, I'm actively using minifb in a bunch of projects that also require the web and DOS backend to keep working. I'd be happy to maintain them. If you want a track record of my OSS work, I'm the creator of libGDX, which has a track record of 12 years of maintenance :)

@Darky-Lucera
Copy link
Collaborator

Nice to know.
Thanks for the track record but I was sure you knew what you were doing.

@Darky-Lucera
Copy link
Collaborator

Darky-Lucera commented Dec 30, 2022

Let me know when this PR is finished (solve the conflicts)

# Conflicts:
#	.gitignore
#	CMakeLists.txt
@badlogic
Copy link
Contributor Author

I've fixed up the merge conflicts. I still need to modify the README.md file to document usage and limitations, and also do some testing on Linux. I'll ping you here once I think it's ready.

@Darky-Lucera
Copy link
Collaborator

Ok

@badlogic
Copy link
Contributor Author

Update README.md with (hopefully) extensive instructions. Tested everything on Windows, Linux, and macOS, including the debugging. Looks good to go on my end.

Note: on Windows you need Ninja as the build generator again, just like with Emscripten. Wished MSBuild could handle it :/

@badlogic
Copy link
Contributor Author

badlogic commented Jan 2, 2023

Alright, I think I've fixed it all up well. Also tested on 86Box in vanilla MS-DOS 6.22, which does actual cycle accurate hardware emulation. Works well! I believe this is ready, if you think it's a nice addition to MiniFB.

@Darky-Lucera
Copy link
Collaborator

Excuse me for the long delay.
Could you please fix the problem in MakeLists.txt to merge this PR?

Thanks in advance!

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

Successfully merging this pull request may close these issues.

2 participants