Chocolate Keen (a "port" of Commander Keen 1-3)

Here is where to post about the latest Commander Keen fangame or modification you've finished, a new website you've made, or another Keen-related creation.
NY00123
Vorticon Elite
Posts: 508
Joined: Sun Sep 06, 2009 19:36

Chocolate Keen (a "port" of Commander Keen 1-3)

Post by NY00123 »

UPDATE (Dec 24th, 2016): Edited download links since Dropbox' "Public" folder is expected to become private by March 2017.

UPDATE (May 12th, 2013): Support for Keen 3 has just been added, meaning Chocolate Keen has full support for the Invasion of the Vorticons trilogy. Thanks again to Lemm for his assistance!

UPDATE (April 11th, 2013): Support for Keen 2 has just been added, hence the project is renamed "Chocolate Keen" now with no numbers involved. Thanks to Lemm for Keen 2 support!

Links for the most current version:
- Windows executable, packed with Keen 1: https://www.dropbox.com/s/5e1sqvbjzq1i7 ... 9.zip?dl=0
- Source code (for GNU/Linux, Windows and maybe more), again packed with Keen 1: https://www.dropbox.com/s/14ouagaqamc1i ... r.bz2?dl=0

Links for an earlier version (without the launcher and cfg file, looks for some game data files in another place):
- Windows executable, packed with Keen 1: https://www.dropbox.com/s/b16l3l37cegp9 ... 5.zip?dl=0
- Source code (with Keen 1): https://www.dropbox.com/s/ejohb3d7nlegb ... r.bz2?dl=0


Original post contents (with a few edits):

Hey all,

Let me first add that the following would not be possible without the great work of QuantumG and Lemm.
Basically, what I am talking about is a "port" of Commander Keen 1 to modern platforms, using SDL (and SDL_mixer). I cannot say it is complete, but you should be able to play through all levels, at least. I also can't promise it's stable, though! :) (Actually, that can *never* be promised...)

UPDATE (November 23th, 2012): I think that we now have a complete "port" of Commander Keen 1 v1.31. A few parts of the original code may not be ported in case they are never actually used (with no modification applied).

Please see the included README.TXT file for more details, along with things that may or may not be supported.

A short list of points describing the way this has been done:
- First, QuantomG figured out a lot of stuff about Keen 1 itself. Here is a link to a version of the file posted by him: http://www.quantumg.net/keen1.c.txt
Basically, it is C code which actually seems to have an implementation of x86 Assembly code.
- Secondly, Lemm came out, got the Keen 1 exe in ASM form and used QuantumG's work in order to give names to stuff.
- Finally, I have "ported" Lemm's work to a mixed C/C++ app using SDL. A few uncompression routines from Commander Genius have been used to the rescue.

Chances are that I won't be working on it any time soon. If someone wants to step up and improve it, be warned that a lot of the work, well... Either something is not so trivial (probably not so much now), or it's trivial but also "robotic" in a way...

P.S. About the name, I've thought that it makes sense since I aim to replicate vanilla Keen1 (including compatibility with files like SCORES.CK1). I've had other thoughts and the name *may* change later. For instance, if someone actually gets to add support for Keen 2 or 3...

For now, though, it is called Chocolate Keen1. NOT Chocolate Keen, nor Chocolate Keen Vorticons, Chocolate KeenV or anything else. (Hey wait, Chocolate KeenV may refer to Keen 5...)
The current name is simply Chocolate Keen1.

Hope you have fun while trying this out!
Last edited by NY00123 on Sat Dec 24, 2016 8:37, edited 27 times in total.
Benvolio
Vorticon Elite
Posts: 976
Joined: Sun May 29, 2011 12:43
Location: Ireland
Contact:

Post by Benvolio »

wow this is quite stunning... works perfectly in a window on win7 but on my 'widescreen' (normal) laptop the graphics distort when I go fullscreen. Edit: nvm I tried the overlay batch file and that dealt with that problem!

the sound is amazing, i havent heard keen1 sound so good since my Amstrad was done away with.

hmmm the function keys aren't doing anything for me... any idea why??

overall, well done - this is a big step in the history of keen!! (in parallel to Commander Genius, of course!)
User avatar
lemm
Blorb
Posts: 696
Joined: Fri Jul 03, 2009 10:18
Location: canada lol

Post by lemm »

The source code to the CKCM might be of interest. I think some of the original keen code might have been reversed for that project.
NY00123
Vorticon Elite
Posts: 508
Joined: Sun Sep 06, 2009 19:36

Post by NY00123 »

Benvolio wrote:wow this is quite stunning... works perfectly in a window on win7 but on my 'widescreen' (normal) laptop the graphics distort when I go fullscreen. Edit: nvm I tried the overlay batch file and that dealt with that problem!
Thanks for trying this out! Yeah, currently the overlay way is the one where the proper aspect ratio of 4:3 is forced, adding black bars if needed. In theory, it can also be done with software rendering and no hardware overlays used, although without linear interpolation applied (as this would consume too much CPU power).
OpenGL is a better possibility, but if it is implemented then I think it won't be done by me any time soon.
Benvolio wrote:the sound is amazing, i havent heard keen1 sound so good since my Amstrad was done away with.
While I actually don't know about the Amstrad and more (:confused), I agree there is currently a difference in comparison to DOSBox. I can assure you that this is one of the few things that, actually, DOSBox does not yet emulate correctly for Keen 1. However, let's say the reason for that has been found... and that's it.
Benvolio wrote:hmmm the function keys aren't doing anything for me... any idea why??
If you're talking about Alt+F4, then yeah I agree. It appears to work on Linux in a window, but not on Windows 7 I think. Maybe a minor modification to SDL should be applied in order to catch that key combo, although the current behavior is probably done on purpose.
If you rather refer to any in-game usage of function keys, well:
- On the loading screen (with the Apogee logo), vanilla Keen doesn't respond to these while it does respond to others. The "port" attempts to replicate this.
- Some keyboard short-cuts (like re-configuring keys) are currently not in use, and the respective functions are probably unimplemented.
lemm wrote:The source code to the CKCM might be of interest. I think some of the original keen code might have been reversed for that project.
Are you by chance talking about this? http://keenmodding.org/viewtopic.php?t=1331

Right now, as I see it, the way to support MODs is modifying the sources. I guess that the sprite behaviors and relevant functions could be split into separate source files, in order to make things somewhat simpler in terms of playing with these.
User avatar
Roobar
Vorticon Elite
Posts: 3267
Joined: Tue Jan 08, 2008 16:12
Contact:

Post by Roobar »

Benvolio wrote:the sound is amazing, i havent heard keen1 sound so good since my Amstrad was done away with.
I downloaded it because of this. It really makes a difference! Amazing! Why Keen1 does not sound like this in DosBox?
NY00123
Vorticon Elite
Posts: 508
Joined: Sun Sep 06, 2009 19:36

Post by NY00123 »

wiivn wrote:
Benvolio wrote:the sound is amazing, i havent heard keen1 sound so good since my Amstrad was done away with.
I downloaded it because of this. It really makes a difference! Amazing! Why Keen1 does not sound like this in DosBox?
Thanks to both! Well, let's say that an inspection of a Dangerous Dave sound effect or more has revealed the following:
- On a real PC with DOS and a built-in speaker, if an app like KEEN1.EXE attempts to play a few successive beeps of the exact same frequency, this is what you hear.
- On the most recent DOSBox release (v0.74), the beeps are basically "fused" into one long beep of the same frequency.
- Note that even if the beeps have different frequencies, some kind of fusion is done, although it may be less noticeable.
- This explains why the differences may sound greater in Keen1 than they are in Keen4 (with PC Speaker sound effects). On Keen1, a sound is made of a series of beeps, and each of them is started on its own. On Keen4, though, successive beeps of the same frequency are basically treated as one long beep.
User avatar
Flaose
Vorticon Elder
Posts: 568
Joined: Sat Oct 27, 2007 20:30
Location: The Frozen Hell
Contact:

Post by Flaose »

Oh man, the cyan border! I haven't seen you in a decade! (Though I thought it flashed brown when you killed a Vorticon, not yellow. Hmm...) I did run into a serious bug though (unless you're going for a peaceful run), Raygun charges aren't stacking! Makes the game super intense!
Cerebral Cortex 314 - For All of your Commander Keen Needs.
Eat at Joe's
NY00123
Vorticon Elite
Posts: 508
Joined: Sun Sep 06, 2009 19:36

Post by NY00123 »

Flaose wrote:Oh man, the cyan border! I haven't seen you in a decade! (Though I thought it flashed brown when you killed a Vorticon, not yellow. Hmm...)
Ouch, been hard to tell it since I think I haven't seen it for too long... It also shows that I still don't understand how does the EGA palette color indexing work. [My guess is that two stages are used: One to pick 16 colors out of 64 hardwired ones, and another one to re-map the 16 colors as done by Keen for the fading effects. The way the second mapping is done is a bit unclear to me at the moment.]

Anyway, I have corrected this. Since it is quite short, I hope that I'd post a fix very soon.
I did run into a serious bug though (unless you're going for a peaceful run), Raygun charges aren't stacking! Makes the game super intense!
I wonder what are you referring to here. At least I think I can use the raygun just like in DOSBox. I need to press once for every shot.
User avatar
fantomx11
Vortininja
Posts: 77
Joined: Tue Aug 14, 2012 18:21

Post by fantomx11 »

NY00123 wrote:Ouch, been hard to tell it since I think I haven't seen it for too long... It also shows that I still don't understand how does the EGA palette color indexing work. [My guess is that two stages are used: One to pick 16 colors out of 64 hardwired ones, and another one to re-map the 16 colors as done by Keen for the fading effects. The way the second mapping is done is a bit unclear to me at the moment.]
As I recall, in the EGA mode that is used in Keen, you could not alter the palette that was used. The colors are:

0 – black (#000000)
1 – blue (#0000AA)
2 – green (#00AA00)
3 – cyan (#00AAAA)
4 – red (#AA0000)
5 – magenta (#AA00AA)
6 – brown (#AA5500)
7 – white / light gray (#AAAAAA)
8 – dark gray / bright black (#555555)
9 – bright blue (#5555FF)
10 – bright green (#55FF55)
11 – bright cyan (#55FFFF)
12 – bright red (#FF5555)
13 – bright magenta (#FF55FF)
14 – bright yellow (#FFFF55)
15 – bright white (#FFFFFF)

As far as selecting the index, I'm pretty sure I remember there were 4 planes and you had to set a bit on each plane for each pixel. So it was faster if your graphics were already stored in a multi-plane format so you could select the plane, blit the bits for that plane, select the next plane, blit the bits for that plane, etc. I could be thinking of another graphics mode though.
User avatar
fantomx11
Vortininja
Posts: 77
Joined: Tue Aug 14, 2012 18:21

Post by fantomx11 »

Oh, I guess I didn't quite complete my thought. From my knowledge, I would assume that the fading effect is accomplished by subtracting 8 from the index used.
User avatar
lemm
Blorb
Posts: 696
Joined: Fri Jul 03, 2009 10:18
Location: canada lol

Post by lemm »

There's an interrupt you can call to switch the ega palettes around.

http://www.ctyme.com/intr/rb-0116.htm

So if you set all 17 bytes to 0, you would get a completely black screen.
If you set the first byte to 0xF and the other 16 bytes to 0, then you would get white where there was previously black, and a black border.


I'm pretty sure there are some arrays of 17-bytes in the the IDA disassembly that correpsond to the partially faded palettes.
NY00123
Vorticon Elite
Posts: 508
Joined: Sun Sep 06, 2009 19:36

Post by NY00123 »

lemm wrote:There's an interrupt you can call to switch the ega palettes around.

http://www.ctyme.com/intr/rb-0116.htm

So if you set all 17 bytes to 0, you would get a completely black screen.
If you set the first byte to 0xF and the other 16 bytes to 0, then you would get white where there was previously black, and a black border.


I'm pretty sure there are some arrays of 17-bytes in the the IDA disassembly that correpsond to the partially faded palettes.
Yeah, it is the case indeed. I've also modified the Chocolate-Keen1 sources yesterday so when an update to the palette is done, the overscan border color is also updated (although you wouldn't see any change, at least usually and without patching).

I still wonder about the format of the color number given for the palette registers. Its bits have descriptions like "Red" and "Secondary Red", as given here: http://www.cs.ubbcluj.ro/~forest/HtmlFo ... 74cc7.html

However, it does not seem to be a way to select one color out of 64 possible EGA colors the way one could think (e.g. an RGB value with 2 bits for each channel). Indeed, a few tests done by patching the common Keen1 palette show the following:
- The value of 6 ("Green" and "Red" bits toggled on) actually results in a brown color (rather than dark yellow).
- As for hex value 26h ("Green"+"Red"+"Secondary Red"), it results in exactly the same color...

Hence, I really don't understand what happens. For now I just use this method:
- Take the given color value to set for a palette register, named "color", and let parsedColor = (color & 7) | ((color & 16) >> 1).
- Now, pick color number "parsedColor" from a palette of 16 actual RGB (or YUV) colors.
- That last palette can be changed with the fading effects and similar, but it does not have an impact on the choice of the overscan border color (where the default palette is still used).
User avatar
Snortimer
Vortininja
Posts: 267
Joined: Wed Jul 22, 2009 8:04
Location: Toronto, Canada
Contact:

Post by Snortimer »

Seems quite nice.

It froze when I tried to click on "previews" in the title screen (it went to the "previews" page but the content was all black and I couldn't escape it).

Also, my sound seems to be coming from the speakers rather than directly from the computer. Is this because newer computers can no longer make those beeps? (or because I'm using Windows 7?)
Last edited by Snortimer on Tue Oct 30, 2012 5:47, edited 1 time in total.
Member since at least 1998 with... ah... some long absences. I was even a moderator at one point. I'll probably keep coming back here and there as long as this place still exists.
User avatar
VikingBoyBilly
Vorticon Elite
Posts: 4158
Joined: Sat Jan 05, 2008 2:06
Location: The spaghetti island of the faces of dinosaur world for a vacation

Post by VikingBoyBilly »

Holy freaking garg! :eek
What a monumental event!
Image
"I don't trust players. Not one bit." - Levellass
Dr. Kylstein
Vortininja
Posts: 151
Joined: Sat Feb 14, 2009 4:39

Post by Dr. Kylstein »

NY00123 wrote: I still wonder about the format of the color number given for the palette registers. Its bits have descriptions like "Red" and "Secondary Red", as given here: http://www.cs.ubbcluj.ro/~forest/HtmlFo ... 74cc7.html

However, it does not seem to be a way to select one color out of 64 possible EGA colors the way one could think (e.g. an RGB value with 2 bits for each channel). Indeed, a few tests done by patching the common Keen1 palette show the following:
- The value of 6 ("Green" and "Red" bits toggled on) actually results in a brown color (rather than dark yellow).
- As for hex value 26h ("Green"+"Red"+"Secondary Red"), it results in exactly the same color...
In 200-line modes, two of the color signals are shut off so as not to interfere with CGA monitors. The mode set might map them to corresponding 6-bit colors for upward compatibility with high-res modes, but the extra data is lost on its way to the monitor. Custom colors in mods are only possible on VGA cards, and only through VGA-specific registers.

Edit: The 4th signal is redefined as "brightness" in keeping with the CGA standard. Also, dark yellow was hardwired to brown in CGA monitors, so any emulation of them (including VGA cards or EGA monitors using these modes) will show the same.
Post Reply