• Please review our updated Terms and Rules here

Commander Keen 4 Tandy 320x200 16 color version

Frenkel

Member
Joined
Jan 1, 2022
Messages
46
K1n9_Duk3 has recreated the Keen 4-6 source code. It's possible to create executables that are byte for byte 100% identical to the Keen 4 v1.4 EGA and CGA executables.
I've been working on a Tandy 320x200 16 color version. It's based on the CGA code and the EGA graphics.

Watch some gameplay footage or listen to the Tandy 3 Voice soundtrack on YouTube.
And download the game and source code from GitHub.
You need to provide your own copy of GAMEMAPS.CK4 from Commander Keen 4 CGA or EGA v1.4 to play this game.

I had to replace the Huffman compression by ZX0 compression to make it fit on a 720 KB floppy disk.
You can press Backspace to disable the score box to make the game faster, just like in Bio Menace.

BTW, I've only tested this in DOSBox with machine set to tandy and in PCem, not on a real Tandy 1000 computer.
To make it work in PCem emulating a Tandy 1000 with 640 KB of RAM or less, you need to run ADJMEM -16 before running the game.
 
This is great! Thank you for sharing it. How did you adapt the CGA code to Tandy?

4 scanlines are needed instead of two for 320x200x16. Is there a way to make it relatively easy without changing significantly the CGA code? I know the source code is available to analize it but I would appreciate an explanation of your method.

Thanks!
 
Here's a video of how the CGA version uses a buffer of 64 KB that wraps around for the graphics. You see no 2 scanline CGA shenanigans. That comes into play when it's copied to video memory. So for the Tandy version just make sure the buffer is filled with 16 color graphics. Unfortunately 64 KB is not enough for 2 full Tandy screens plus some extra rows of tiles. That's why the bottom is black during gameplay. I thought about adding a status bar like in Wolfenstein 3-D or Doom, including Keen's face, but memory is already tight. And you would immediately see it's not the original EGA version :)
 
Nice! Thanks!

Reading that portion of code I saw something just curious: I saw than they used add 80-0x2000 to jump from one scanline to another. This trick simplifies a lot of things, avoiding having to calculate what buffer offset or segment to write (i.e. B800 for 1st scanline, BA000 for the 2dn and so on). This was used at Richard Wilton's book on video systems. I'm pretty sure they read it, as their graphic card detection routine is letter by letter (they left even the comment!) the one by Wilton.
 
Every Keen assembly routine is written in TASM Ideal Mode, except for the video detection routine, which is in the MASM dialect :)
 
I've recreated the music in TNDY-Tracker and then I played it in DOSBox-VGM to create VGM files. Those files were converted to an IMF like format: 2 bytes to send to the Tandy 3-voice sound chip followed by a UINT16LE for the delay.

I've probably should have used a different tracker: a tracker that runs in Windows, supports the Tandy 3-voice sound chip and can export to VGM.

I'm thinking about porting Catacomb 3D to the Tandy; the music and music player are already done :D
But the target audience for a Tandy version of Catacomb 3D is probably a lot smaller than for Commander Keen.
 
Last edited:
How did you convert the Adlib music into Tandy 3 voice? Thanks!

In that same vein, what would be the chances of getting a binary built that does EGA graphics but uses the Tandy sound chip?

(I ask because I have a particularly unusual Tandy at my disposal, a 1000 HX with a VGA card hacked onto the Plus Bus. I've been kind of shocked to discover that Keen 4 EGA is *pretty much* playable on that machine's 7.16mhz CPU, but of course that's with no music. I also have a 1000 EX, basically identical, but without VGA, it might be interesting to see how the performance compares between the Tandy and EGA graphics with all else being equal.)
 
... Re: the above request about the possibility of getting Tandy sound mixed with EGA graphics, in addition to 1000s with VGA cards added there are a couple of actual Tandy 1000 models that came with VGA. (The most relevant one is probably the 1000 RLX. There are also Tandy sound cards for regular PCs, although I think to support those you'd need to allow for an alternate I/O location... same as the 1000 RSX?)
 
Awesome work, @Frenkel. That's an extremely well-done conversion... and with manually recreated music - impressive!

If I had that source code back then, my 16-color composite CGA mods for Keen 4 and 5 would've been easier. Maybe I should use that to do #6 one day...
 
Don't forget about Keen Dreams. That game also has a CGA version. ;)
Right now, I don't have plans to create Tandy versions of Keen 5, 6 and Dreams. I want to spend more time on Doom.

I've put EGA, CGA and MCGA (16 colors only) versions on [urlhttps://github.com/FrenkelS/keensource456tandy/releases/tag/v20220122]GitHub[/url].
I've removed the checks on available memory, graphics card and audio device, so use at your own risk.

The performance of those versions is different from the official id Software versions:
I've replaced the Huffman compression by ZX0 compression to make it fit on a 720 KB floppy disk. This improved loading times.
But then I refactored the memory manager so it uses ordinary array access instead of pointers to save some memory, and then the loading times got worse.

I've also added extra unrolled sprite drawing routines. The EGA version has special drawing routines for sprites of up to 80 pixels wide. I've added an extra routine for the biggest sprites which are 88 pixels wide, like the Dopefish. The same goes for the CGA version which originally has special routines for sprites of up to 72 pixels wide and I made that 88. So now the score box is also drawn faster. BTW, you can press Backspace to disable the score box: one less sprite to draw makes the game feel faster.

For the Tandy version I removed some calls to clear the screen: It's not necessary to clear the screen when the next frame draws a full screen. Now that I've compiled the code to create an EGA version, I've noticed that sometimes it is necessary to clear the screen. For example, alternate pressing F1 and Escape during the demo to go to the help screen and back. I'm probably not going to fix that.
 
BTW, for the CGA version I've made some sprites smaller so they're drawn faster. When there are 4 transparent pixels on either side of a sprite, I removed them.
 
Hmm... any chance for fade in/out routines for the Tandy version, like the EGA version? Tandy video supports playing with the palette registers for that (although the specifics naturally aren't the same as EGA).

A couple of other ideas that popped into my head way back when:
- A Hercules version, either in a 640x200 window or at the native 720x352 resultion, although the latter would increase the viewport. that should have roughly the same performance as Tandy modes, at least from a video memory standpoint.
- a 256-color VGA version, although that would of course mean a huge graphical touch-up project.
 
I didn't know it was possible to change the palette on a Tandy machine. I have thought about adding fade in/out when I read you added it to your 16-color composite CGA mod.

You need to change one byte in the CGA version to go from 320x200 4 colors to 640x200 2 colors :)

Here's a video of id Software's Commander Keen 7 Tech Demo running in 256-color VGA mode.
 
It turns out setting all palette registers is exactly the same with ax = 1002h; int 10h;.
 
Whoa, that's incredibly slow in PCem.
 

Attachments

  • keen4.gif
    keen4.gif
    976.4 KB · Views: 22
Whoa, that's incredibly slow in PCem.
And PCem is a little faster than the real machines it emulates... (while I used it, sometimes I thought that it looked too good/too fast to be true... Unfortunately, I was right).

Don't know if you are aware of 86Box: it's a fork on PCem. One of it's advantages over PCem is that it's time accurate. Another one is that it is more actively maintained.
 
@Frenkel: Not sure why the fades specifically would be slow... in fact they seem to 'stutter' which looks like an issue with timing accuracy. IIRC the fade routines are timed using vblanks, so I'd start looking there. And/or try to replace the BIOS calls with direct register output.

And that's pretty cool, first time I've seen that Keen 7 demo!

Don't know if you are aware of 86Box: it's a fork on PCem. One of it's advantages over PCem is that it's time accurate. Another one is that it is more actively maintained.
It's true that 86box has more accurate CPU emulation, but it also seems to have issues with video rendering - I was never able to get perfectly smooth screen updates/scrolling with it (PCem doesn't do it perfectly either, but it gets much closer). If that one issue ever gets fixed, I'll happily switch over...
 
It's true that 86box has more accurate CPU emulation, but it also seems to have issues with video rendering - I was never able to get perfectly smooth screen updates/scrolling with it (PCem doesn't do it perfectly either, but it gets much closer). If that one issue ever gets fixed, I'll happily switch over..
Yeap. I also liked more how PCem rendered video. In my case, I changed to 86Box mainly due to the slightly wrong CPU timing of PCem: I had confusing results with my code, thinking that I optimized the code better than I really did... 😂 Now, I'm used to 86Box and also like the new interface, and I enjoy a lot the new machines they added. Nevertheless, another point plus point of PCem over 86Box is that the OpenGL shaders work right on this, while on 86Box still have many issues. I still haven't made them work on my computer.
 
Fading is also slow in 86Box, so I've removed the BIOS call and program the registers directly. The MCGA version uses more colors for the fading than the other versions. It looks really nice and smooth.

I've been made aware of another advantage of the Tandy version over the EGA version: The Dopefish moves in steps of 2 pixels instead of 8, so it's more smooth.
 
Back
Top