Have you ever wanted to go back in time when computers cost over $5,000 and they could barely draw a pie chart? Well, I know I have! I miss the ol' days of DOS and being able to easily impress your nerd friends by typing "cd mystuf~1\games" and then entering "dir" to list all of the contents! Pretty exciting stuff. But seriously, it is fun going back and messing with DOS and maybe even writing some old school C/C++ programs that directly access your VGA card. Gasp! :)The great thing is that you can still do all of this and the best part is... you can do it on a Mac!
The tools we'll be using to get the job done are the great DJGPP development tool and the awesome DOSBox emulator.
The first thing to do is download DOSBox by visiting this site and downloading the Mac OS X version. http://www.dosbox.com/download.php?main=1. Once you've downloaded and installed DOSBox leave it alone for now and we'll revisit it again later.
Now we need to download DJGPP by going to http://www.delorie.com/djgpp/zip-picker.html. Since DJGPP is a pretty advanced tool that comes with lots of features, we're only going to download the specific files we need using their handy Zip Picker tool. This will help us only get the files we actually need. You can see all of the things I chose in the picture on the right. I'm only going to write programs that run in DOS and I'm going to be writing C/C++ programs and maybe even some assembly! :)
Here's a picture on the left of the other settings I chose. After all of that, click on the "Tell me which files I need" button. Go ahead and download all of the files you see and move them to some directory. I moved mine to /Users/(username)/Tools/DJGPP/. Once you have all the files, open up a terminal window and navigate to your folder. Once inside your folder, type "unzip \*.zip" to unzip all the files. If your prompted to overwrite some files just say yes. After that, you can delete all of the zip files in that directory because we won't need them anymore. You should now have a nice directory structure that looks like the picture on the right.
We're almost done! Now we just have to configure DOSBox to recognize DJGPP so we can get to programming! To accomplish this, we need to edit DOSBox's preference file which is created the first time you run DOSBox so make sure you at least run it once. The file we need to edit it located in /Users/(username)/Library/Preferences and the file is called "DOSBox 0.74 Preferences". Your version number may vary. So go ahead and open up that file in your favorite text editor and scroll all the way down to the bottom. Add these lines:mount c /Users/(username)
set PATH=z:\;c:\Tools\DJGPP\bin
set DJGPP=c:\Tools\DJGPP\djgpp.env
After that, save the file and we're done! Now let's try to compile something cool. Create a folder somewhere on your computer for this little C demo and navigate to it IN DOSBox. For example I created a folder in my /Users/(username)/documents/myprojects/ called "Lines" and I navigated to it by entering into DOSBox:
Z:\>c:\
C:\>cd docume~1\myproj~1\Lines
Since DOS doesn't support long file names, you have to use that ~1 after six characters of the folder/file name. Weird.
Now that we're in our new directory inside DOSBox, head on over to http://www.brackeen.com/vga/shapes.html and download the file called "lines.c" into your new directory. Then in DOSBox type "gcc lines.c -o lines.exe" and press enter. Your program should compile successfully and now you can run it! Just type "lines" and press enter and you should see a bunch of multi-color lines being drawn like crazy! Check out the screen shot below.

Congratulations! You can now compile C/C++ code inside DOSBox using DJGPP for free! One quick note, if you want to compile C++ code you need to use "gxx" instead of "gcc". To learn more about this, just check on the docs on DJGPP's website. And also, if you want to learn more about VGA programming, visit the site where we downloaded the "lines.c" file and read the tutorial at http://www.brackeen.com/vga/.
Have fun and if you have any questions just leave a comment and I'll try to help even though I'm not really an expert! :P
3 comments:
Thanks for this, saved me half an hour and took me right back at least 15 years :)
when i'm running gcc or gpp on DOSBox or Boxer an error appears:
Exiting due to signal SIGKILL
(...registers...) program=[...]\DJGPP\4.61\CC1PLUS.exe
(...registers...)
Hey Lukasz, I was having the same problem. It looks like it's a problem with GCC 4.6: (see the comments section)
http://virtuallyfun.superglobalmegacorp.com/?p=199
Using GCC 4.44 instead solved the problem for me.
Post a Comment