schellingb / dosbox-pure

DOSBox Pure is a new fork of DOSBox built for RetroArch/Libretro aiming for simplicity and ease of use.
GNU General Public License v2.0
752 stars 61 forks source link

Is it technically possible to Netplay a DOS game which doesn't support multiplayer? #42

Open pemre opened 3 years ago

pemre commented 3 years ago

Hi all! Sorry in advance if this is a dumb question. Is it possible to play a DOS game over network even if it doesn't have a network multiplayer option?

For example Arcade Volleyball is a 2 player game (fantastic game btw :smile:), but there is no other option than playing on the same machine with keyboard/mouse.

I see there are some efforts like https://yang-online.com/ but I'd love to be able to play them in RA with Netplay.

Experiment 1: I played a SNES game (Contra III) with snes9x core on my local network with 2 machines.

Result 1: Netplay works, games are fast, there is no lag.

Experiment 2: With same machines, same RA versions and DosBox Pure 0.4:

  1. I loaded Arcade Volleyball on host and enabled Netplay.
  2. Other machine is connected over LAN (I see it after "Refresh Netplay Host List") Note: I had to enable DMZ setting for host machine on my router.
  3. It warns me to load the content manually on client machine.
  4. I load the game from my DOS playlist and I see the notification saying host-client connected.

Result 2: There is no sync in video/keyboard whatsoever. I feel a bit lag. Both games are working separately and slow.

Note: I tried the same with DosBox SVN core and the result is same.

Maybe there is a technical limitation here, I just wonder possibilites. I could help by providing more experiments. I'm also a JS developer with weak C background, I could also try to help on coding in C/C++/Objective C if you can give me some assistance. Thanks for reading so far :sweat_smile:.

schellingb commented 3 years ago

Technically I think it should be possible, but not with the DOS cores we have at the moment. Or any PC emulator out there as far as I know.

The following explanation is based on my loose understanding of how DOSBox internally works. It might be way off.

DOSBox inherently is non-deterministic. What that means is, even if two identical PCs start out with the same save-state, the state of the next "frame"will not be the same. I put frame into quotes because a frame is not very defined when it comes to DOS PCs or DOSBox. An emulator of a console of that era can usually count on two things being fixed. The display refresh frequency and the console CPU frequency (as well as audio output frequency, etc). All these things are in flux when it comes to DOS emulation. All kinds of emulated hardware tick at their own pace, managed by a programmable interrupt controller that bases itself on amount of real-time passed. And by default the emulated CPU tries to be as fast as the host CPU can run it, which means it isn't fixed at all, its performance fluctuates all the time because outside of the emulator is a non-realtime operating system that gives CPU time to the emulator whenever it feels like.

It would be interesting to lock this down in ways that would enable savestate/rollback based netplay but I can only speculate where to start or how long this would take.

Darknior commented 3 years ago

Yes complicated feature ... LAN gaming ... i never try it on DosBox But i remember when i live it for real by the past <3 If it will be possible one day to play old lan games, in netplay like we do on libretro console emulators, it will be a dream. Playing Warcraft 2 in lan with friends ... dune 2 ... like when we where young LOL

pemre commented 3 years ago

Still digging in old VOGONS threads... There is this "infused multiplayer" question which was redirected to a discussion where original devs were a bit skeptical and suggesting to use a VNC software to achieve our purpose: "Kaillera and Dos Box". It's sad to read the way they've discussed it and after 15 years, we couldn't make a step forward.

I'm glad that @schellingb is answering this question with possible solutions and terms like "save-states" and "CPU frequency" instead of discouraging sentences with "security", "scope of DosBox" etc... I know that a PC is more complex than an arcade machine and it's emulator but when I read "this is impossible" in those forum threads, it makes more eager to find a solution :sweat_smile:.

Also in DOSBox Feature Request Thread, under "NOT FOR THE FORSEEABLE FUTURE" header, you can see both solutions are not considered to be implemented:

Anyways I won't read that forum any further, it makes me sad and angry :smile:.

A silly question but can't we just use the "fixed CPU cycle" option and somehow only share keyboard input over network?

Darknior commented 3 years ago

A silly question but can't we just use the "fixed CPU cycle" option and somehow only share keyboard input over network?

It's a good idea, but we must also stream the screen ...

schellingb commented 3 years ago

@Darknior DOS LAN/Modem gaming is a different thing though. Overall I think that is the more interesting multiplayer option when it comes to DOS games. Games that already support non-local networking options like IPX or modem play can somewhat easily be adapted to be playable over internet. The original DOSBox and the other libretro DOSBox cores out there do that to some extent as far as I know.

Sadly there isn't an libretro API for that. Would be really cool to have for sure. Have a UI in RetroArch for starting a server or joining one, and emulating modem/IPX sockets over TCP or UDP inside the frontend without the core having to do any actual networking.

I think what RetroArch currently does for multiplayer is aimed at SNES style console emulators which synchronize a point via save state and from there on do rollback networking. What that means is, when a player receives an input from another player, they can roll back the state of the game (a few frames) and re-simulate the game from the point when that input happened. The rest then plays like a local game.

This in theory could work for DOS emulation as well (just need a 100% deterministic emulation where one step (frame) is exactly defined to have the exact same outcome on different machines (which can be very complicated if different CPUs are in play). But how many DOS games are there really that would make use of this? Local multiplayer on one screen or split-screen. The games I remember playing multiplayer on DOS all were modem/IPX games like Warcraft or DOOM. Maybe Micro Machines 2 :-)

@pemre Nowadays there are services like Parsec or Steam Remote Play that operate like that. Stream the entire screen and just have joining players accept the input lag. No rollback, not even code change needed, any game just "works". As long as the input lag is acceptable. Technically not a "cool" solution but certainly a very practical one in the age of fiber optics.

pemre commented 3 years ago

Why also the screen? :thinking: Assuming that the network has 0 delay, I thought fixing the CPU cycle would make both machines "deterministic"...

From RA FAQ, "Which cores work for netplay? On a technical level, every core that supports save states should work but the performance requirements may be too high for it to work in any practical level."

I don't know how it works internally (maybe I should ask RA devs too) but I imagined like:

  1. The host sends the first "state" of memory over internet once the client connects.
  2. Then they only share input data
  3. Time to time (e.g. every half second) host sends another "state" snapshot to sync again :grimacing:

Probably what I suggest would be the worst implementation due to bad network efficiency :smile:.

pemre commented 3 years ago

But how many DOS games are there really that would make use of this? Local multiplayer on one screen or split-screen.

Some FTF "Face-To-Face" games that I play: (I could find more actually :grimacing:)

  1. 4D Sports Boxing
  2. Alien Breed
  3. Arcade Volleyball
  4. Battle Chess
  5. Brutal
  6. Dyna Blaster
  7. Golden Axe
  8. Liero
  9. Lotus
  10. Scorched Earth
  11. She Bo (Chinese-made clone of Pang/Buster Bros)
  12. Street Fighter games
  13. Volfied
  14. Wacky Wheels
  15. Worms

We could also play many 1 player games as coop, like:

  1. Adventure and puzzle games (e.g. Mah Jongg)
  2. Platform games (each player would use 1 life each turn)
  3. Some turn based strategy games

There is also an old list for FTF games: https://cyber.dabamos.de/mirrors/multiplayergames/#ftf

Briefly, it has a potential :)


About "every core that supports save states should work" statement, I already "connected" host and client with DBP and it has "save-states" support, right? Even if it would go out of sync at some point, I should have seen some kind of input from my client (or vice versa). I didn't see anything like that :cry:. Maybe I should try another game.


  1. Parsec doesn't have Linux host option.
  2. Steam doesn't have Retroarch (yet) and Dos cores are not in the first 10 cores list :disappointed:.
  3. Maybe I could try USE Together for Linux (Alpha) as I already use it. It accepts user input from clients (even from browser) but I have no idea about latency/video quality for a game. Cons: Remote control of your screen is limited to 30 minutes per day on free account.
Darknior commented 3 years ago

@schellingb thanks a lot for explanation. Very complicated task :(

And for TCP UDP games, if i use them like 20 years ago it will work fine ?? Really surprised, but cool to read it, maybe i will can try a local lan network with children ... like by the past ...

schellingb commented 3 years ago

@pemre That's not a bad list :-) Some games might exist on other platforms in better versions, but I see some unique gems for sure! I think instead of "every core that supports save states should work" it should be "every core that supports runahead should work". Maybe keyboard/mouse input is not synchronized at all, just retropad input? Not sure, never looked at the function in RetroArch.

Monkey Island co-op would be fun, haha!

@Darknior As far as I know, networked games from that era used lock-step style multiplayer architecture. What that means is, if a packet doesn't arrive in time, the game just freezes up until it does. Unlike modern multiplayer games which can usually deal with plenty of lag (100ms and more) by having an authoritative side that rules over the users, and predictive clients that try to guess as good as possible where and in what state things should be.

yonailo commented 3 years ago

“Lakers vs Celtics and the NBA playoffs” !! excellent game to play in two players mode and much much fun than the megadrive version .

In my opinion we should make an effort to make this happen it would really make a big difference

launchtile commented 1 year ago

Any movement on this at all? Netplay or some type of LAN would be so good.

yonailo commented 1 year ago

Nobody else is interested in this feature ?

schellingb commented 1 year ago

As explained above DOSBox is inherently not designed in a way to support this. Unless someone were to deeply analyze and fix the behavior I doubt it will happen. I think in theory something like PCem or even a VM solution like VMWare or VirtualBox could do it if there was a means of sending input events across a network.

Nowadays we have video streaming based solutions like Parsec or Steam's Remote Play Together which makes things like that trivial (albeit at a higher latency/traffic cost) and I'd agree that it's a less "cool" technical solution.

So with commit 91f3504 I chose the "easier" (for me) of the two approaches to NetPlay support in this libretro core. It will route networking packets over the RetroArch netplay feature and that generally should just work. It supports IPX networking and modem play for DOS games as well as TCP/IP and IPX based networking for Win9x games. While obviously different from what was asked in this issue, I still think it's pretty cool. Being able to play some of the very first online games like Gemini 2 from 1985 (Modem), classics like DOS DOOM (IPX) all the way up to something like FireFight on Windows 98 (TCP/IP) through RetroArch's super easy to use NetPlay feature is pretty cool.

https://cdn.discordapp.com/attachments/432657353775513631/1118965046702252093/DOSBoxPure-DOOM-IPX.mp4 https://cdn.discordapp.com/attachments/432657353775513631/1119642311052251286/DOSBoxPure-FireFight-Win98-TCPIP.mp4

yonailo commented 1 year ago

I am impressed with your work and I agree that routing networking packets through netplay is really cool and clever.

But at the same time I feel a bit disappointed. As far as I know, Parsec does not support Raspberry Pis any more as a server… I don’t know any other solution that would make this possible between 2 Raspberry Pis, except the RetroArch netplay feature.

Maybe this is something to be reconsidered if someone dares to make the big work that we all imagine that would be needed. As Styve Jobs used to say:

“The only way to do great work is to love what you do and embrace the challenges that come with it."

Thank you again for everything you do.

schellingb commented 1 year ago

If you pay me the salary of an engineer at Apple I might try harder.