4 ms·
A side question, any recommendation on emulator and books if I want to replicate what Carmack did for Commander Keen? The keen dream source code uses C and asse
by markus_zhang 3y ago
A side question, any recommendation on emulator and books if I want to replicate what Carmack did for Commander Keen? The keen dream source code uses C and assembly so I'll do the same.
I guess Dosbox is accurate enough for a 386dx with an ega card, and this book ( https://www.amazon.ca/Programmers-Guide-Ega-Vga-Cards/dp https://www.amazon.ca/Programmers-Guide-Ega-Vga-Cards/dp) is good enough for the guide?
For development tool I plan to use vscode with openwatcom C compiler.
Any other book I should take to learn assembly and DOS C? I already know some C but I guess it's a bit different than the old C.
- jandrese 3y agoC isn't C++. Most of what you know today applies to older compilers as well, with only a handful of features added over the years. You aren't going all the way back to K&R calling syntax here, I'm assuming you will target C89. You will just have to remember to declare all of your variables at the top of each function and the stdint types won't be available. There are a few other things added over the years, but its going to be pretty much the C you know and love.
- lockhouse 3y agoPedantically you are correct, but it is and was common to use C++ compilers as a slightly more convenient dialect of C. This gives you the performance and simplicity of the C language with some very nice quality of life improvements. With few exceptions, C++ can mostly be treated as a superset of C.
- jandrese 3y agoWhat I was trying to say is that if you're comfortable using modern C++ and try to switch back to a C++ compiler from the early 90s you are going to find a lot of the features you regularly use suddenly being absent. With C this is much less of an issue.
- lockhouse 3y agoSorry, I misread your comment, that makes a lot more sense now!
- duskwuff 3y agoThe newer C features that you're most likely to feel the lack of in an older compiler are: 1) Mixed declarations and code. All variables must be declared at the top of a basic block. 2) Along similar lines, declaring variables in control statements like for(). 3) // comments. (Hardly a critical feature, but you're probably used to having them.) Perhaps not coincidentally, I think these were all features which began their life in C++, and were backported to C in C99.
- ido 3y agoIIRC they were also available as “non-standard” feature in compilers at the time before being added to c99 (e.g. I’m pretty sure gcc in the late 90s supported all of these if you didn’t force c89 compatibility).
- badsectoracula 3y ago> I'm assuming you will target C89 OpenWatcom (the compiler the parent post mentioned) supports C99.
- aninteger 3y agoNot by default, it does require a flag (-za99).
- badsectoracula 3y agoYeah but that doesn't really mean anything, the compiler still supports C99 if one wants to write in it.
- deaddodo 3y ago> You will just have to remember to declare all of your variables at the top of each function This is still idiomatic to the C community, even if it isn't strictly required any longer. About the only place it's ignored is inline variables for loops.
- vkoskiv 3y agoI write C primarily for hobby projects, and I only started with C ~10 years ago, so I'm likely in the minority that considers this a code smell for new C code. I don't want to needlessly extend the scope of my local variables! Different story of course if you're targeting C89 or older, which I'm actually doing in my current project. I'm writing software on and for my old 68k Macintosh.
- deaddodo 3y ago<< Edited out for being unnecessarily combative >>
- jandrese 3y agoWe might be saying the same thing here, but modern C scopes variables down to the block. So if you have a variable declared for instance inside of a for loop or if statement, that variable is out of scope once you exit the block. This will fail to compile with an "undeclared identifier" error: if ( x > 0 ) { int y = 1; } printf("%d", y); It is a feature that was long overdue in C IMHO.
- lockhouse 3y agoFabian Sanglard’s books are excellent! I highly recommend them for retro DOS game engine programming. https://fabiensanglard.net/ https://fabiensanglard.net/
- markus_zhang 3y agoThanks, I actually got the idea after reading his adapt refresh article as I didn't understand it.
- fabiensanglard 3y agoSnap, my incomprehensible article made you want to program the whole thing? Sorry about that! As a side note, if you want to go Commander Keen style, you won't have the pleasure to use DOS/4G. CK, alike Wolfenstein 3D, use real mode. Personnaly, I find having to deal with near/far pointers a huge turn off from programming this way.
- markus_zhang 3y agoHi Fabien thanks a lot for the books and articles! TBF I only understand a small part of them but I find them fascinating. I'll try out real mode and see what happens. I read about near/far pointers some 30+ years ago in one of my father's programming books so that's the only thing I know about them -- I heard about them :D
- bluedino 3y agoI would check out the Andre Lamothe DOS game programming books You will also want to start with a 16-bit C compiler like Borland Turbo C or Microsoft C, a lot of the code is very different from the 32 but protected mode versions There's always DJGPP which Quake was written in, but again 16-bit DOS code isn't going to run as-is.
- markus_zhang 3y agoThanks. I used to do some C++/sdl2 game programming just for fun but I think this project needs more study. TBH I don't know if Commander Keen is using protected mode. I do not understand the code and I assume not. I need to know how to program and compile for DOS 16-bit, as you said, and how to inline assembly, and how to use assembly to put pixels on screen using a virtual ega card provided by dosbox.
- bluedino 3y agoIt did not use protected mode https://github.com/keendreams/keen https://github.com/keendreams/keen https://fabiensanglard.net/ega/ https://fabiensanglard.net/ega/
- myth_drannon 3y agoLamothe or Michael Abrash. Archive.org has books from both authors.
- badsectoracula 3y ago> You will also want to start with a 16-bit C compiler like Borland Turbo C or Microsoft C The parent post mentioned they're going to use OpenWatcom which is an actively developed[0] C and C++ compiler that targets 16bit DOS (among others). [0] https://github.com/open-watcom/open-watcom-v2 https://github.com/open-watcom/open-watcom-v2
- bluedino 3y agoAhhh I thought it was 32-bit only, not sure if I ever used their DOS compiler in the old days or not.
- rzzzt 3y agoSome useful tutorials can be found in PC-GPE: http://qzx.com/pc-gpe/ http://qzx.com/pc-gpe/
- markus_zhang 3y agoAh, thanks a lot. I used to have this page bookmarked but lost due to unforeseen consequences.
- rzzzt 3y agoI think this one is already a mirror, with the original lost in time, but not sure... I had the .txt files as a collection downloaded in 2004 or so, the readme file in it says the previous location was on an Oulu University FTP site.
- nickt 3y agoThat link to the book isn’t working for me, any chance you can post the details please?
- markus_zhang 3y agoSorry here you go: https://www.amazon.ca/Programmers-Guide-Ega-Vga-Cards/dp/0201126923/ref=mp_s_a_1_1?keywords=Programmers+guide+for+ega&qid=1693340378&sr=8-1 https://www.amazon.ca/Programmers-Guide-Ega-Vga-Cards/dp/020...
- simcop2387 3y agoAbsolutely check out PCem for a closer to hardware emulation than dosbox, https://pcem-emulator.co.uk/ https://pcem-emulator.co.uk/
- markus_zhang 3y agoThanks will download. Is there any particular reason this one is more accurate than dosbox?
- mysterydip 3y agopcem/86box emulate an entire system (cpu, memory, bus, drives, ports, etc) while dosbox simulates a system below DOS. It may seem pedantic, but a simulation in essence "displays the right answer" while an emulator "shows your work". Especially with old games where devs were trying to squeeze performance out of systems, there are many timing or undocumented behavior tricks they used that a simulator may not replicate properly.
- badsectoracula 3y agoPCem is dead, use 86Box[0] (forked off PCem) instead. [0] https://86box.net/ https://86box.net/
- badsectoracula 3y agoCheck out 86Box[0], unlike Dosbox it does full system emulation and tries to be cycle accurate (or cycle accurate enough) so that you will notice little to no discrepancies between the emulated hardware and the real one. 86Box was forked from PCem which is kinda similar but PCem development has practically stopped and all development nowadays goes towards 86Box. Also FWIW do not use plain Dosbox, it has longstanding bugs that haven't been fixed in years (some have been fixed in SVN but they haven't made a new major release for a very long time). Use Dosbox-X or at least Dosbox Staging instead (Dosbos-X is more accurate). As an example Post Apocalyptic Petra[1], a game i made ~3 years ago for a DOS game jam doesn't work on plain Dosbox because of some timing issues (you may get a black screen or visual glitches) - you need either Dosbox-X or Dosbox Staging. Also note that these projects have slightly different goals: 86Box tries to emulate the hardware as precisely as it can whereas Dosbox(-X/Staging/etc) tries to provide a compatibility layer for running older software (plain Dosbox is only focused on games but other forks expand that to include all software). This means that Dosbox(/etc) will be more likely to ignore "bad" programming that wouldn't work on (or only work on some) real hardware - e.g. its Sound Blaster emulation is very forgiving and if you write some SB code and test it only on Dosbox chances are it wont work on the real hardware. [0] https://86box.net/ https://86box.net/ [1] https://bad-sector.itch.io/post-apocalyptic-petra https://bad-sector.itch.io/post-apocalyptic-petra
- markus_zhang 3y agoThanks, will do! Glad that I learn about other emulators.
- andrewf 3y agoRead up to page 20 of http://bitsavers.informatik.uni-stuttgart.de/pdf/borland/borland_C++/Borland_C++_Version_4.0_DOS_Reference_Oct93.pdf http://bitsavers.informatik.uni-stuttgart.de/pdf/borland/bor... - it'll apply to 16-bit Watcom as well. I know you said you're using openwatcom, but if you're not familiar with DOS, I'd suggest running through https://fabiensanglard.net/Compile_Like_Its_1992/index.php https://fabiensanglard.net/Compile_Like_Its_1992/index.php to build Wolfenstein with Borland C 3.1. The public Keen Dreams repo is very similarly structured and will build with BC3.1 as well. Others have mentioned the Abrash black book. The example code is available in OCR'd form (and compiled!) at https://github.com/othieno/GPBB/tree/master/codebase/source https://github.com/othieno/GPBB/tree/master/codebase/source . Some scrolling examples (but not in color mode!) are in https://github.com/othieno/GPBB/tree/master/codebase/source/chapter.30 https://github.com/othieno/GPBB/tree/master/codebase/source/... - you can use them to see the difference between Virtualbox (which doesn't emulate the finer details of a VGA) and emulators like 86box/PCem/DosBox. Getting data into and out of the more accurate emulators can be a pain. Personally I use VirtualBox with a 32-bit Windows image to do builds. It has network access and VirtualBox shared folders connect it to my desktop. It can run DOS and 32-bit windows toolchains, which covers everything that existed in the DOS programming days. To get things to either PCem, or my real 386sx, I mount a virtual floppy image in VirtualBox, or connect a Sabrent USB drive to write a real floppy, respectively. (Something like PC-NFS or Microsoft's DOS SMB client would be the easiest way to get data into PCem/86box/etc. I'm yet to set it up).
- markus_zhang 3y agoThanks a lot. The near/far pointer seem to require some attention whenever one intends to use them. I'll read Abrash's book too but I'll go very slowly. First step is to compile a Hello World using the dev env, and I'll go from there.