Skip to content(if available)orjump to list(if available)

Writing FreeDOS Programs in C

Writing FreeDOS Programs in C

29 comments

·November 2, 2025

1313ed01

To the list of compiler listed I want to mention this one as well, that is my compiler of choice for 16-bit C in (Free)DOS these days (because it has a MIT license, it's very small, and it runs great inside of DOS itself so no need to mess with cross-compilation and I know if I have an environment like FreeDOS or DOSBox set up I can both compile and run my code, and I will never have to re-install or reconfigure anything when moving between different host systems):

https://github.com/microsoft/MS-DOS/tree/main/v4.0/src/TOOLS

(Not only Microsoft's C compiler in that directory, but also MASM, MAKE, and a bunch of other tools. 1-2 MB of files and you have an entire toolchain for 16-bit DOS.)

kragen

Interesting, "All files within this repo are released under the MIT License as per the LICENSE file stored in the root of this repo," but did they include the source for the toolchain? I may be looking in the wrong place...

1313ed01

No, but that MIT license does not say anything about sharing the source code, so just sharing the binaries should be fine. (Not a lawyer.)

( * Also thanks for mentioning MIT. My comment said BSD, but I fixed that now.)

kragen

Yeah, I didn't mean it was illegal, just that you might have an unnecessarily hard time fixing compiler bugs and understanding how the toolchain works.

hedora

Tangentially related: I was getting awful screen tearing in dosbox with a gl @ 4K@60hz rendering target.

Switching to 1080p@240Hz fixed it. The problem was that 60Hz was close to, but not the framerate the old game asked for.

Narishma

The typical 320x200 mode that games used back then ran at 70Hz.

Dwedit

Is there really a difference between writing a DOS program and writing a FreeDOS program? You just need a period-accurate compiler that can target DOS. Maybe OpenWatcom, maybe DJGPP.

With HXDOS, you can also write a Win32 console-mode program and run it on DOS. 7-zip is an example of a program compatible with HXDOS.

johannes1234321

The "difference" is, that this is the FreeDOS project, thus they focus on that environment.

QuercusMax

I confess I don't know anything about FreeDOS, but are they trying to evolve DOS for the future, or just make a free bug-for-bug compatible version? Those are very different things.

johannes1234321

I think the goal is compatibility, but not being afraid of extensions (like power management support and some other "modern" hardware features)

In the context of this tutorial: They use their own "fed" editor.

WalterBright

The Digital Mars compiler for DOS is available for free.

https://www.digitalmars.com/

kragen

But the GCC, OpenWatcom, and DJGPP compilers the FreeDOS folks recommend are additionally free software, which is of real value to some of us. Zortech C had a reputation for producing better code IIRC, and it could run on an 80286, which I'm not sure the others can?

Narishma

I don't know about OpenWatcom but I used the original Watcom on my old 286 just fine. Even the Windows 3.1 IDE ran fine on it IIRC.

1313ed01

I guess it made a lot of sense to implement compilers in 32-bit protected mode to get more space to work with easier? Free Pascal's compiler also requires 32-bit even if it can generate 16-bit DOS code as well (at least when cross-compiling from some other OS; I have not tried to cross-compile from DOS 32-bit compiler to DOS 16-bit executable).

Some people (and by that I mean Debian people; not sure about anyone else) disagree about OpenWatcom being free software. The license has some unusual requirement(s). There has been talk for a long time about possibly fixing that, but I do not know how on track that is (or how much it matters, in practice): https://github.com/open-watcom/open-watcom-v2/discussions/27...

sgt

Vibe coders are just going to be staring at this and go... where'd you get that blue mode in Cursor?

grg0

From the soydev extension.

dardeaup

Curious as to whether there are any real-world use cases for doing this (other than curiosity) in DOS. If so, I'd love to hear about them.

actuallyalys

I suppose there could be a use for programming for computers that would otherwise be ewaste, although I'm not sure how much ewaste is out there that can run DOS but not, say, Linux or a BSD. Lots has already been trashed or recycled, and my impression is that retrocomputing enthusiasts are thinning out the market as well.

comprev

I used FreeDOS once to run ancient software which controlled an industrial size oven. The client was having an ever increasing challenge of sourcing IDE disks (in 2008) so I was contracted to find a solution.

Eventually we settled on industrial PCs, solid state media and FreeDOS.

It was significantly cheaper than replacing the oven at £1M each.... in 50 of their factories worldwide.

LeFantome

Lots of solid state to IDE adapties out there too. But great example.

1313ed01

I hobby-code for DOS, partly because of nostalgia, but much also because it (specifically DOSBox, or DOSBox-X) is such a fantastic and stable virtual machine. No one is going to deprecate even some minor part of the API. And some emulators give you fun features like allowing any screen resolution to be set up to run in fullscreen on a modern monitor (exposed using standard VESA API inside of DOS).

There are some other retro computer or consoles that could probably be just as useful for this. But DOSBox (as well as QEMU+FreeDOS, for those that prefer that) are nice because they have fully open source implementation from the CPU-level up to the user utilities, so there is no need to mess with dodgy ROM downloads or such to get things working.

kragen

MS-DOS was a reasonable bootloader for Linux and Windows 95; I imagine FreeDOS might be a better one if you wanted to do hobby OSDev. Historically you could get hard real time performance for things like controlling steppers from your parallel port under MS-DOS, but nowadays you'd just use Freeduino or an iCE40. Also maybe brushless motors.

1313ed01

FreeDOS is no good at all for booting anymore, since BIOS support is increasingly rare. No way to boot FreeDOS (or MS-DOS) from UEFI. And of course also no point in trying to run it on ARM or any other non-x86 CPU. Looks like the future for FreeDOS will be to run in virtual machines only. A bit sad, since running FreeDOS on the bare metal of a 21st century computer (even one from 10-20 years ago) has been a nice way to experience just how fast modern hardware is.

grg0

I have it on my to-do list to install FreeDOS on bare metal to set up a retro gaming box. Tried once, but for some reason the installer failed writing to disk. Anyway, if anyone is making new FreeDOS games, I'll gladly pay for them, and it'll give me an excuse to go down that avenue again.

dlcarrier

If enabling CSM in your BIOS isn't an option or isn't enough for FreeDOS, there is a translation layer that can get it to run on UEFI hardware: https://github.com/FlyGoat/CSMWrap

1313ed01

OK, I just posted a comment saying FreeDOS will no longer run on hardware because of lack of BIOS support, but that might change things I guess. Hope it can be made to work.

Another big problem for FreeDOS is the lack of sound card support. I do not know if anyone has solved that yet.

grg0

That had not occurred to me and I'm also not sure. FreeDOS was able to boot just fine into the live environment. It was the disk part that failed.