Page 1 of 2

Back to the source: ReDMCSB

Posted: Sat Jan 18, 2014 9:26 pm
by ChristopheF
I've been working for nearly 5 years to reverse engineer the Atari ST versions of DM and CSB, and today I release the result of my work, named ReDMCSB (Reverse Engineered Dungeon Master/Chaos Strikes Back).
It contains source code (C language and a few parts in assembly) for all executable code on the game disk of all known Atari ST versions:
  • Dungeon Master for Atari ST 1.0a English (no version visible in dialog boxes)
  • Dungeon Master for Atari ST 1.0b English (version '1.0' visible in dialog boxes)
  • Dungeon Master for Atari ST 1.1 English
  • Dungeon Master for Atari ST 1.2 English
  • Dungeon Master for Atari ST 1.2 German
  • Dungeon Master for Atari ST 1.3a French (version 1.3 visible in dialog boxes)
  • Dungeon Master for Atari ST 1.3b French (variant, version 1.3 also visible in dialog boxes)
  • Chaos Strikes Back for Atari ST 2.0 English
  • Chaos Strikes Back for Atari ST 2.1 English
The source code is as accurate as possible: once compiled with the Megamax C compiler version 1.1 (also supplied in the package) it generates machine code nearly identical to the one in the original games. All the differences come from the fact that I used a different version of the compiler than the one FTL used and not because the source code is 'wrong'. If I can get my hands on version 1.2 of the Megamax C compiler, I'm pretty sure the source code will be proved to be 'perfect' by generating executables strictly identical to the originals.

The source code contains:
  • Meaningful and consistent names for all functions and their parameters, global and local variables, constants and macros.
  • Comments.
  • Conditional compilation directives allowing compilation of each version from the same source code. They also provide easy identification of the differences between versions
  • Conditional compilation directives allowing compilation without the copy protection. They also provide easy identification of all code related to the copy protection

The package does not contain as much documentation as I would like because it is very time consuming to write accurate documentation, but you will find the list of all known bugs and all changes between versions as well as a detailed description of the copy protection, and some more.

Download the package, and check the readme in the DOC folder for more information.
http://dmweb.free.fr/Stuff/ReDMCSB_Release2.7z

Previous release: http://dmweb.free.fr/Stuff/ReDMCSB_Release1.7z

Re: Back to the source: ReDMCSB

Posted: Sat Jan 18, 2014 11:43 pm
by Paul Stevens
I've been working for nearly 5 years to reverse engineer
does not contain as much documentation as I would like because it is very time consuming
I see. The reverse engineering went pretty quickly then.

Oh my goodness! What a monumental effort. Did you
deal with the Hint Oracle? I looked a bit and did not see it.

Re: Back to the source: ReDMCSB

Posted: Sun Jan 19, 2014 12:11 am
by ChristopheF
I have only worked on the game disk and not the utility disk, so there is no hint oracle. On the utility disk, there is a start.prg that was developed with Megamax C (I have the source code for this one too although it is not part of this package). Other executable files use a custom 'FTL' format (start.prg contains the code to load these files) and they were not compiled with Megamax C.
They were developed and cross compiled on Macintosh, but I have not yet worked on these FTL files to identify the compiler that was used.

Re: Back to the source: ReDMCSB

Posted: Sun Jan 19, 2014 12:15 am
by Sophia
:shock: :shock: :shock: :shock: :shock:

Re: Back to the source: ReDMCSB

Posted: Sun Jan 19, 2014 1:34 am
by ebeneezergude
Sophia, 'Concise and Honest' I get, but what does :shock: :shock: :shock: :shock: :shock: mean....?! ;-) Penny for your thoughts?

Re: Back to the source: ReDMCSB

Posted: Sun Jan 19, 2014 3:52 am
by sixfourfour
WOW. Had a quick look around. I'll do more for sure. THANKS for sharing what you know. That original game, for me, was and is a timeless classic.

THANKS!

Re: Back to the source: ReDMCSB

Posted: Sun Jan 19, 2014 8:45 pm
by Sophia
It means I am impressed.
This is quite an effort!

Re: Back to the source: ReDMCSB

Posted: Mon Jan 20, 2014 12:47 am
by Chaos-Shaman
5 years is a long time, pure devotion and love for the magical game.

Re: Back to the source: ReDMCSB

Posted: Mon Jan 20, 2014 10:33 am
by Bit
Just amazing!
Matching up with the compiler... so, digging out all the compiler's patterns in all their dependencies...
Paul told me I'm nuts when I started the recompilation of DM2 (and I'm still in the nuts trees, but there is light in the end of the tunnel) - and kentaro pointed me to the Watcom compiler. But that deep that it matches...
/me bows!!!

btw: didn't look into the source yet, but if it is pretty pure C (without Windows-API like CSBwin is), I probably can spend the extensions to handle true-color-graphic. I went through that when doing my recompilation - there are more different parts than one would think, including such things as fluxcage/teleporter-graphic on the sideview etc. It's just - I had to kill the old caching system for that...

Re: Back to the source: ReDMCSB

Posted: Mon Jan 20, 2014 3:23 pm
by Gambit37
An amazing effort Christophe! And there was I thinking that only Mr Stevens was crazy enough to undertake such an effort...

It's amazing what one can achieve with dedication and focus. I'm altogether too easily distracted to finish things.

Well done. :-)

Re: Back to the source: ReDMCSB

Posted: Mon Jan 20, 2014 8:27 pm
by ChristopheF
Thanks everybody! I agree with 'nuts' and 'crazy' :)

@Bit
I'm sure the methods I've used would also work on DM2 if you have the correct compiler version. The DM2 program is much larger, though.

About the 5 years, I want to add that it has not been a full time job at all, it is just that I started around 5 years ago. I don't know how many hours I spent on all this... probably several hundreds.
When I started, I knew nothing about 68000 assembly and the inner workings of the Atari ST, compilers/linkers. I learned a lot.
I spent less than 3 years working on the disassembled code. Around 8 months working with Megamax C and converting all assembly code to C code. Then more than one year to understand how everything worked, give nice names to functions and variables, and write the documentation (the list of bugs took me a lot of time to build).

Re: Back to the source: ReDMCSB

Posted: Mon Jan 20, 2014 8:55 pm
by dungeon.master
Bravo Christophe ! :D

Amazing work, I started to read the protection and bugs sections : it's really impressive.

About the protection I remember that it was very nasty : a friend who mades a copy from my original has a lot of troubles with it :lol:
He said that its party was killed by giant fireballs coming from nowhere, some areas or weapons were not avalaible, the games hangs after 1 or 2 hours playing etc ... Just enough to make you buy the original :lol: :lol:

I also appreciate the efforts you put to list and explains the several bugs.

THANKS !

Re: Back to the source: ReDMCSB

Posted: Tue Jan 21, 2014 9:49 am
by terkio
Many thanks. :D
An outstanding professional work. The ultimate knowledge on DM and CSB.
I recently said, the Dungeon Master Encyclopedia has everything....Now, it has everything including the source code and all to build.

Re: Back to the source: ReDMCSB

Posted: Tue Jan 21, 2014 12:38 pm
by Bit
Gave the 'make' a work - takes some time (even with Altgr-X), but completed!
Still, that work is more incredible than anyone of us can imagine.

Re: Back to the source: ReDMCSB

Posted: Tue Aug 05, 2014 11:00 am
by ChristopheF
Release 2 is now available (Updated link in the first post of this thread)

This minor release has updates to the documentation (mainly additional bugs are documented) and a few minor changes here and there. Check the History section in Readme.htm

Re: Back to the source: ReDMCSB

Posted: Sat Oct 17, 2015 8:53 pm
by zoinkers
As an ex-Amiga user, I'm interested in looking over the source code of the Amiga versions you did. I see in the quora post by Doug Bell, you even did the PC version. Is there a v3 release coming? :-)

Re: Back to the source: ReDMCSB

Posted: Sun Oct 18, 2015 3:28 pm
by ChristopheF
Doug Bell mentioned my work on ReDMCSB here: https://www.quora.com/Is-it-possible-to ... ource-code

There is definitely a Release 3 package in the works. In the past weeks, I have been working on merging my Amiga source code with the Atari ST source code from Releases 1 and 2. I had to update quite a lot of small details here and there and split the source code over more files so that things are consistent and also to avoid code duplication. I still have a lot of work though to make the code cleaner, but right now I can compile both Atari ST and Amiga versions from the same set of source code (using conditional compilation directives). Note that for Amiga, this only covers versions 2.x as versions 3.x are quite different (cross compiled on Macintosh, and with some major differences in the code itself).

If you want to have a glimpse into the source code in its current state, send me an email and I'll reply with a preview package.

Re: Back to the source: ReDMCSB

Posted: Sun Oct 18, 2015 8:11 pm
by zoinkers
Thanks for the info. I'm happy to wait for the final polished release :-)

Re: Back to the source: ReDMCSB

Posted: Sun Mar 19, 2017 10:08 pm
by zoinkers
How's things going Christophe?

Re: Back to the source: ReDMCSB

Posted: Mon Mar 20, 2017 7:46 am
by ChristopheF
I have been working for some months on the versions that were compiled on Macintosh (the ones that have .FTL executable files = X68000 and Amiga 3.x versions). Each of these versions contains several .FTL files: one for the game engine and others containing 'drivers' or other programs (swoosh FTL logo, champion editor, anim engine, etc.).
As of now, I have only completed the main program of DM/CSB for X68000 and I will soon complete the one from CSB 3.1 Amiga (the other amiga versions should follow quickly as they are very similar).
I still have a few months of work though before this is completed.

Re: Back to the source: ReDMCSB

Posted: Tue Mar 21, 2017 7:17 am
by zoinkers
Crikey, that's dedication. Is there any chance of a point release to scrape through?

Re: Back to the source: ReDMCSB

Posted: Tue Mar 21, 2017 7:58 am
by ChristopheF
If you want to have a look, I can share my work-in-progress unified source code for Atari, Amiga, PC, PC-98 and X68000.
If you're interested in Amiga versions, I'd wait a few weeks so I can at least complete the work on the game engine in these versions.

Re: Back to the source: ReDMCSB

Posted: Sat Jun 17, 2017 4:06 pm
by FGoset
Many thanks for your work. I'm currently writing a clone of DM and this will be very helpful to understand many of the hidden aspects of this game.

Re: Back to the source: ReDMCSB

Posted: Sun Apr 11, 2021 8:04 pm
by zosodk69
ChristopheF wrote: Tue Mar 21, 2017 7:58 am If you want to have a look, I can share my work-in-progress unified source code for Atari, Amiga, PC, PC-98 and X68000.
If you're interested in Amiga versions, I'd wait a few weeks so I can at least complete the work on the game engine in these versions.
Christophe, I'm very interested in seeing the progress you've made on reversing the Amiga versions. I recently made a personal hack of the WHDLoad DM slave to incorporate WASD keys for movement (similar to a modern FPS). While reversing the binary, I was greatly aided by the ST code you published in Release 2. I was tripped up by some of the differences I encountered in the Amiga version, however. I'd like to further expand this to hack to include more complicated actions like spellcasting with the keyboard. A while back you'd indicated your willingness to share a preview of the work you've completed. Does this offer still stand?

Re: Back to the source: ReDMCSB

Posted: Mon Apr 12, 2021 8:24 am
by ChristopheF
You can check this archive: http://dmweb.free.fr/Stuff/ReDMCSB_WIP20210206.7z

It contains:
- the source code for all programs from all known versions of DM/CSB except the SNES console versions
- emulators, compilers, tools and scripts to fully automate the build of all the executables

Re: Back to the source: ReDMCSB

Posted: Wed Apr 14, 2021 11:13 pm
by Gambit37
Hi Christophe, in your research for ReDMCSB, did you determine if creating Ful Bombs was possible in any version? I know that Doug Bell said it's possible in an early version of DM, but I'm still not sure if he's mistaken?

Re: Back to the source: ReDMCSB

Posted: Wed Apr 14, 2021 11:56 pm
by ChristopheF
Definitely not possible in any of the versions I have studied. He was probably referring to early beta versions and not any released one.

Re: Back to the source: ReDMCSB

Posted: Thu Apr 15, 2021 1:30 am
by Gambit37
Great, thanks for the confirmation :)

Re: Back to the source: ReDMCSB

Posted: Sun May 02, 2021 7:36 pm
by zosodk69
ChristopheF wrote: Mon Apr 12, 2021 8:24 am You can check this archive: http://dmweb.free.fr/Stuff/ReDMCSB_WIP20210206.7z

It contains:
- the source code for all programs from all known versions of DM/CSB except the SNES console versions
- emulators, compilers, tools and scripts to fully automate the build of all the executables
Most of the Amiga 3.x binaries are compiled on an Apple Macintosh with Think C? Why do you suppose that is?

One of the neat things about the source compiled with Aztec C is that we get the .ASM artifacts with symbols intact. I'm not familiar with the Mac compile workflow. Is there a way to get the compiled assembly for, say, KAOS.FTL?

Re: Back to the source: ReDMCSB

Posted: Mon May 03, 2021 12:45 am
by ChristopheF
Trust me, I do not "suppose": I know that cross-compilation with the Think C compiler running on Macintosh was used for all .FTL files (that is all Amiga 3.x, Atari ST CSB Utility disk, and X68000 binaries, except the loaders that were compiled on the native platform).
The initial clue was that each FTL file contains a few Macintosh specific instructions (Line A instructions of the 68000 processor that translate to Macintosh toolbox calls). These instructions are part of the Think C loader that the compiler adds at the very beginning of all compiled programs. Of course it is bypassed in FTL files as they run on other platforms: this is part of the conversion from the compiled Macintosh executable file format to the proprietary .FTL executable file format.
Then the fact that ReDMCSB executables are so close to the original .FTL files (and even perfectly identical for the smallest ones) proves that the compilers I have used are the correct ones (Think C 4 and 5, that last one being used only for the KAOS.FTL in DM 3.6).

Think C does not have any feature to output the assembly corresponding to the compiled code. The only way for that is to use a disassembler on the generated executable.