How was CSBWin created?

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Adamo
Italodance spammer
Posts: 1534
Joined: 22-Apr-05 09:59
Location: Poland
Contact:

How was CSBWin created?

Post by Adamo » 3-Aug-10 13:13

Paul dissembled the machine code for atari to covert for PC
I would like to know more about HOW did Paul do it? I read his statement that he wrote a disasembler and worked over it about 6 months (!) on it ("crazy thing to do. But it works"). I`d like to read more about the process of translating the machine code.
SpoilerShow
(\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/)
SpoilerShow
(@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@)
SpoilerShow
(>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<)

User avatar
Paul Stevens
CSBwin Guru
Posts: 4099
Joined: 8-Apr-01 16:00
Location: Madison, Wisconsin, USA

Re: How was CSBWin created?

Post by Paul Stevens » 3-Aug-10 14:17

You cannot believe it until you try it.
I did it manually. Bit did it more mechanically.
Bit is a bit more loquacious than I. Perhaps he can
outline his methods for you.

If you have some Atari binary code you want to translate,
I am willing to help get you started.

User avatar
ChristopheF
Encyclopedist
Posts: 1259
Joined: 24-Oct-99 12:36
Location: France
Contact:

Re: How was CSBWin created?

Post by ChristopheF » 3-Aug-10 17:12

I made my own disassemblies of all versions of DM & CSB for Atari ST using the following method:
On Atari ST versions, the program is compressed in START.PAK. You can use SCK to uncompress the START.PAK file or write your own tool as the PAK format is described here: http://greatstone.free.fr/dm/d_pak.html
The result is a standard Atari executable file (.PRG).
In order to disassemble the .prg files I used a freeware disassembler called TTDigger: http://members.chello.nl/h.robbers/TTD.html
The resulting assembler code must be tweaked a bit as there are a few data sections inside the code that are treated as instructions by default.

User avatar
Adamo
Italodance spammer
Posts: 1534
Joined: 22-Apr-05 09:59
Location: Poland
Contact:

Re: How was CSBWin created?

Post by Adamo » 3-Aug-10 18:02

If you have some Atari binary code you want to translate,
I am willing to help get you started.
haha, I don`t have anything like that. :)
I did it manually.
Manually? Did you do it in first half of 2002?
I would like to know more about the process, but I don`t even know what to ask, because I don`t know much about that.
Did you have to understand CSB machine code deeply to translate it into something else? I guess translating machine code is a hard task?
As far as I remember, there was 60000+ lines of code, wasn`t it?
Could you give an example line of machine code and its translation into the format used in CSBwin? I`m just curious..
SpoilerShow
(\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/)
SpoilerShow
(@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@)
SpoilerShow
(>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<)

User avatar
Paul Stevens
CSBwin Guru
Posts: 4099
Joined: 8-Apr-01 16:00
Location: Madison, Wisconsin, USA

Re: How was CSBWin created?

Post by Paul Stevens » 3-Aug-10 20:20

Go fetch

http://dianneandpaul.net/CSBwin/CSBwin_ ... Source.zip

It is pretty much the whole thing. Example:
What we started with:
528a
200a
2640

What the disassembler did ( I wrote my own disassembler. And yes, I was
very familiar with both the binary and assembly machine language.)

528a ADDQ.L #1,A2
200a MOVE.L A2,D0
2640 MOVE.L D0,A3

What I did manually:

//528a ADDQ.L #1,A2
//200a MOVE.L A2,D0
//2640 MOVE.L D0,A3
A3 = A2 + 1;

But that is the easy part. Figuring out why we added
a 1 to A2 and put it in A3 while destroying D0 and discarding
the value in A2 was the hard part.
Last edited by Paul Stevens on 3-Aug-10 20:39, edited 1 time in total.

User avatar
zoom
Grand Master
Posts: 1819
Joined: 22-Sep-03 23:27
Location: far away but close enough

Re: How was CSBWin created?

Post by zoom » 3-Aug-10 20:29

Well, you explained it quite well Paul , interesting.
but I typed the following so I post it..maybe it helps Adamo further if it is correct

As I see it , assembler is a programming language that is made for a specific computer/Processor. so you have ATari ST assembler, Amiga Assembler, 64000 Assembler(MSdos) so there is not one assembly language and assembler is not equal to some other assembler. Exchange Amiga, Atari etc with the corresponding processor name, it is just for getting the picture.

programs have code which in turn sends instructions to the processor via the language of the processor, which is its assembly language. The code of the program, its source code (maybe) is not visible. It is built=compiled, more or less installed for a specific computer.
There are several layers of deepness of programming languages. Assembler is very direct communication with the processor, therefore it is very hard to read. It can take days to get to know what one line does or means. You can alter or direct the usage of memory for programs, you even have to . More upper level programming languages have not as much power maybe, but are easier to read and are faster to do. Since Processors tend to get overhauled very quickly, it does not yield much to learn assembler anymore, maybe.erm.

So Paul did probably take all the instructions the processor of the Atari St did receive while the game was running (I guess, however that may have worked) and tried to get head or tails of the numbers that got stored in memory and changed in memory. a very large puzzle that changed over time...
This could all be wrong in parts<.>, very likely, but the best effort to represent my understanding of your question Adamo

User avatar
Bit
Mon Master
Posts: 1021
Joined: 3-Mar-08 09:53
Location: Nuts trees

Re: How was CSBWin created?

Post by Bit » 4-Aug-10 01:21

I got the assembler-code from DM right out of the Atari.
It was a confusing process to launch the disassembler (a tool called IDEAL I think), then launch the game and finally catch the code right after it was expanded and relocated in memory, saving it then disassembled.
However, for DM that was relatively easy, it just has very few data within code areas - in other cases that fools a disassembler pretty good.

Bringing that disassembler-listing with its 52000 lines of code to a working clone - that's a longer story...

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 4-Aug-10 16:37

I must say that I have fullly never understood what it meant when paul and bit said that they disassembled the code for the atari to pc. But I can now see what hard work it is behind this, and I am really impressed with both your work and paticence!!

A question to both Bit and Paul..
Why did you use the atari for CSB, why not the PC?
Is it more hard work or is it because CSB has more functions that DM doesn't have.. And why not the amiga in that case?

User avatar
Paul Stevens
CSBwin Guru
Posts: 4099
Joined: 8-Apr-01 16:00
Location: Madison, Wisconsin, USA

Re: How was CSBWin created?

Post by Paul Stevens » 4-Aug-10 20:46

I could not get my hands on a PC version of CSB. ;-)

Moreover.....the PC has 'banked' memory and Atari
was a much more powerful linear memory. And no
swapping and such nonsense. The Atari code is much
easier to disassemble into something meaningful.

I wanted to play CSB after my Atari quit me. There
were Atari emulators (Steem and such) but they were slow.

I never thought that my program (CSBwin) could also play
DM!!!!! Someone else discovered that after I released it!!

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 4-Aug-10 21:15

I never thought that my program (CSBwin) could also play
DM!!!!! Someone else discovered that after I released it!!
How was that discovered? By replacing the graphic and dungeon.dat files? Sorry for my ignorance.. Only curious :)

User avatar
Sophia
Concise and Honest
Posts: 3978
Joined: 12-Sep-02 19:50
Location: Nowhere in particular
Contact:

Re: How was CSBWin created?

Post by Sophia » 4-Aug-10 21:20

The Atari code is much easier to disassemble into something meaningful.
Recently I had the experience of having to reverse-engineer a small bit of 286 (i.e., 16-bit x86) code. It's not a fun experience, and for something on the order of DM-- forget it. Bill Gates famously called the 286 "brain damaged" and he pretty much got it right. Not being able to deference a pointer in any sane fashion and having a cripplingly small array of registers to work with makes your brain melt.

User avatar
beowuuf
Archmastiff
Posts: 20660
Joined: 16-Sep-00 12:00
Location: Basingstoke, UK

Re: How was CSBWin created?

Post by beowuuf » 4-Aug-10 21:42

I believe it was Sphenx who fiorst discovered that the endian of CSB and DM was the only difference between the two. Certainly I played his CSB dungeon converted into PC DM format. Christophe and Paul were the ones to make official programmes/routines to convert the files around easily.

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 4-Aug-10 22:32

Gates famously called the 286 "brain damaged"
Is it the same with newer version, lets say 386, 486, pentium? What version does dm for pc have? Is there some tutorials/manuals on the net that describes disassembled code and how it is translated?
Thousands of question, but I find this very interesting :)

User avatar
Paul Stevens
CSBwin Guru
Posts: 4099
Joined: 8-Apr-01 16:00
Location: Madison, Wisconsin, USA

Re: How was CSBWin created?

Post by Paul Stevens » 4-Aug-10 23:03

The 386 introduced the 32-bit register and pointer, allowing
a linear address space up to 4 gigabytes. But the newer processors
maintained the ability to run the old code and inherited a great
deal of the brain-deadness of the older. But it is possible
to write reasonable programs on the pentium. Until you get
to 4 gigabytes, of course.

DM for PC asssumes an old, old processor.....8088 perhaps
would suffice. It certainly works on my 286.

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 4-Aug-10 23:30

Okey then.. I see what you mean. But isn't possible to sort out the braindamaged code in a program, so that is will be less braindamaged? Or is it simular to what you described here:
It is pretty much the whole thing. Example:
What we started with:
528a
200a
2640

What the disassembler did ( I wrote my own disassembler. And yes, I was
very familiar with both the binary and assembly machine language.)

528a ADDQ.L #1,A2
200a MOVE.L A2,D0
2640 MOVE.L D0,A3
But only more twisted? Is a example possible?

User avatar
Sophia
Concise and Honest
Posts: 3978
Joined: 12-Sep-02 19:50
Location: Nowhere in particular
Contact:

Re: How was CSBWin created?

Post by Sophia » 4-Aug-10 23:41

Paul Stevens wrote:But it is possible to write reasonable programs on the pentium. Until you get to 4 gigabytes, of course.
Part of this limitation is Microsoft's fault, not the processor itself. The 32-bit Pentium has had a 36-bit address bus for quite some time, and actually can address 64GB of memory, not 4GB. The idea behind this was that the 4GB limit to a 32-bit pointer could apply on a per-application basis. Each application would get, essentially, its own 4GB of address space, and the operating system and MMU would reconcile 32-bit application pointers into the 36-bit address space. It's a bit like the old segmented memory model, but at least this time it's done in OS-land and applications wouldn't have to suffer. Microsoft refused to support this in XP for some reason or other, though. Probably something to do with backward compatibility back to 1992. So 32-bit Windows users get stuck with 4GB for the whole system. I guess they wanted everyone buying 64 bit anyway. :P
Rasmus wrote:But isn't possible to sort out the braindamaged code in a program, so that is will be less braindamaged?
As you may already know, the reason a processor that uses 32-bit addressing runs into the 4GB limit is because 4GB=2^32 is simply the largest number that can be represented with 32 bits. On a processor that uses 16-bit addressing, the largest number is 2^16 = 65536, so you're stuck with 64K of RAM unless you start doing really weird tricks. And that's where the brain damage comes in. You can undo all this garbage, of course, but it just takes time and work.

User avatar
Bit
Mon Master
Posts: 1021
Joined: 3-Mar-08 09:53
Location: Nuts trees

Re: How was CSBWin created?

Post by Bit » 5-Aug-10 01:20

I thought I did buy the PC-version of DM too, but - can't find it anymore. Also, I started that process on the Atari long time ago and that was like an open bill, so I was glad to find this site. I never had started a disassembling process for the PC-version, because my knowledge of the x86-processors is just enough that I know that I don't like that them. For the Amiga - that's another thing. Didn't I already write that I took a look into UAE's frozen memory and find that there is something very odd with the code?

@Rasmus:
That's all about lifetime of variables. The compiler has to make the things a safe way, and we can be glad that this compiler wasn't really optimizing the code. Let's just take that little sample of Paul. There's much between the lines! Try to figure it out - i.e. D0-value is same to A2 of line 200a. Means, at that point you can track back and free the responsibility to care for the contents of the old D0 value. This compiler i.e. carries the return-value of a C-function by writing it to D0. Then again, the D0-register is the first one to be used as a temporary variable. There are zillions of commands with D0 that die if you make a C-code out of it. But - you can first delete it, if you can be sure that it isn't used the other way.
Then data-structures. There are really bad traps. You never know, if a variable is bound into a structure, an array of this structure, or maybe that's just part of another higher structure and you can't simply cut this out of the 'starting spaghetti'.
Some of the offsets are precalculated by the compiler that you think - ah, that variable I already know - but wrong - it's because it's just some added value of different offsets within a higher structure and another index will be added and you are in a completely other area of the memory. (Now combine that with the endianness-problem...)
I won't even talk about how they arranged the linked list of the graphics... those are the things you spot when you already reached a higher level. All those are the reasons why you somehow have to do loops in redeveloping the code.
After all - that's a challenge. Maybe even worth to do it in a team - and discuss how to continue. But hey - whom one could bug with that?

User avatar
Paul Stevens
CSBwin Guru
Posts: 4099
Joined: 8-Apr-01 16:00
Location: Madison, Wisconsin, USA

Re: How was CSBWin created?

Post by Paul Stevens » 5-Aug-10 01:48

The 32-bit Pentium has had a 36-bit address bus
And the 16-bit 8088 had a 20-bit address bus. Lot of good that
did for the poor assembly-language programmer who needed
a 65537 byte array. DS, ES, SS, CS. What a treat.

I remember an IBM fellow quoted as saying that no
personal-computer application would ever need more
than 65K of memory.

User avatar
Bit
Mon Master
Posts: 1021
Joined: 3-Mar-08 09:53
Location: Nuts trees

Re: How was CSBWin created?

Post by Bit » 5-Aug-10 01:54

First one breaking the limits was the WATCOM-compiler with DOS4GW if I remember right.
Did you ever wrote a bank-switching-routine using VESA to fill a 640*400-truecolor-screen?
That was as evil as programming interrupt 2 to get access to the interrupts 9+...
And for all that crap they say today you're too old to be up-to-date and you can drive a cab,,,
pffft-

I *did* use assembler-commands within C-code for DJGPP without having to struggle much with data-segment-stuff etc.
That was not that bad, and I could do real 3D-calculations with transparent-bitmaps without 3dfx-hardware-support.
To optimize that was also a lot of work - Rasmus' generation just has to checkout which function has to be used.
That's necessary to reach a somewhat higher level for that software develops at all, but compared to the bit-biting. that is some kind of another world.

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 5-Aug-10 17:21

Okey.. I think I got most of the stuff you wrote Bit (mostly because Sophia gave me an 2 hour lesson yesterday on the chat). This have gotten me in the mode to learn more about disassembleing..

As for my question about disassembleing a 16 bit cpu into a readable language, I have understand that it isn't impossible. But that the assemble program for 16 bit systems take on evil tricks (that involves alot of confusion for the human brain) to beeing able to reach memory outside the 65k limit. And because programs/games is all about getting information from the memory into the cpu, calculate it there and then return the new values to the same/new spots in the memory.. So I can understand that every command made in high assemble language and converted into low assemble language for a 16 bit system will requier alot of more commands in the low assemble language than if it were converted into a 32 bit system..

Correct me if I am wrong :)

User avatar
zoom
Grand Master
Posts: 1819
Joined: 22-Sep-03 23:27
Location: far away but close enough

Re: How was CSBWin created?

Post by zoom » 5-Aug-10 19:43

Rasmus wrote: gotten me in the mode to learn more about disassembleing..
uh uh. I fear the Worst! ;)

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 5-Aug-10 19:57

Hehe, nothing too fear ;) But I have read that the more I understand low assemble language the better I can write high assemble language (c++). But I guess it is like a whole science and nothing I can learn in a month.

User avatar
Sophia
Concise and Honest
Posts: 3978
Joined: 12-Sep-02 19:50
Location: Nowhere in particular
Contact:

Re: How was CSBWin created?

Post by Sophia » 6-Aug-10 00:31

Paul Stevens wrote:And the 16-bit 8088 had a 20-bit address bus. Lot of good that did for the poor assembly-language programmer who needed a 65537 byte array.
It let that programmer actually have a 65537 byte array. If the address bus was only 16 bits wide, there would be no way to address that 65537th byte, period.

User avatar
Hajo
Craftsman
Posts: 106
Joined: 2-Mar-10 10:33
Location: Between chair and keyboard

Re: How was CSBWin created?

Post by Hajo » 6-Aug-10 08:36

Some systems could switch "memory banks". Like the upper 16k of the total 64k, you could tell the hardware which addresses of your ram should be visible there and then access it. Or something.

Some systems also did address multiplexing. First here were the low 16 bit of the address put on the bus, then came the upper 16 bits (or vice versa). The memory controller could translate that into a memory access.

Atari ST and Amiga both had 68000 CPUs and therefore used the same assembly code. But all OS calls, hardware registers and such differed. This CPU was internally a 32bit CPU with 32 bit registers for address and data calculations. I don't remember the address bus details though, just that all 16 and 32 data had to be aligned on even addresses.

I'd assume that the most tricky thing to disassemble is self-modifying code. Some games of that era used that, but I have no idea if DM did.

I'd think, that if today someone tries to write a clone, it is better to start newly with a high level language and implement the reverse-engineered game mechanics instead of trying to lift disassembled code to a higher level.

Edit: And next time I read the whole thread before boring people with already mentioned facts. Sorry :(

User avatar
Bit
Mon Master
Posts: 1021
Joined: 3-Mar-08 09:53
Location: Nuts trees

Re: How was CSBWin created?

Post by Bit » 6-Aug-10 11:01

@Rasmus: I need to read your question some times more - I still don't get it. Think I reply better in PM then - that's all much too boring for non-programmers. I'd say a CPU with two modes - 16 bit and more - is doomed, but well...
Today the chip-power is that high, that they could hide a complete P2 including DOS for backward-compatibility in a modern CPU. But they better make a Java-processor that's machine commands are the Java tokens itself...

@Hajo: DM/CSB has no self-modifying code, but the original copy protection does checksums from routines. But - there is code to load pieces of code from graphics.dat into three buffers and execute this (short jumps only, no relocation stuff).
Graphics.dat is the wrong name anyways, that's just kind of a zipped directory with files of different formats.
And hey - for checking out all game mechanics, you need this higher level. Without CSBwin, I'd be doomed ;)

@Sophia: When did you make this hardware-crash-course? Some months ago you refused to know anything about assembler. ;)

User avatar
Sophia
Concise and Honest
Posts: 3978
Joined: 12-Sep-02 19:50
Location: Nowhere in particular
Contact:

Re: How was CSBWin created?

Post by Sophia » 6-Aug-10 19:57

Bit wrote:When did you make this hardware-crash-course? Some months ago you refused to know anything about assembler. ;)
Just now we were talking about x86 architecture. Back then, you were trying to show me some of your DM disassembly which was for the 68k. I don't know nearly as much about the 68k. :)

User avatar
Rasmus
Ee Master
Posts: 714
Joined: 7-May-09 23:44
Location: Sweden
Contact:

Re: How was CSBWin created?

Post by Rasmus » 7-Aug-10 01:29

@bit: As I only got a somewhat extremly basic view on how it works and have probably used the wrong terms explaining what it is that I maybe understand, it is not supprising that you may not understand me ;)
I will send you a PM later this week when I have more time over too get into it..

User avatar
zoom
Grand Master
Posts: 1819
Joined: 22-Sep-03 23:27
Location: far away but close enough

Re: How was CSBWin created?

Post by zoom » 7-Aug-10 11:56

´Good old´ Bit wrote:- that's all much too boring for non-programmers.
I like to read it. and Adamo -it looks like it, too! After all, it is a programming related thread.
Non interessants may skip it.. Then again, the thread could become too detailed...just wanted to say this

User avatar
Bit
Mon Master
Posts: 1021
Joined: 3-Mar-08 09:53
Location: Nuts trees

Re: How was CSBWin created?

Post by Bit » 8-Aug-10 03:35

zoom, those are just the very common things of the details - you won't know how deep those details can be.

Maybe there's one interesting page for all those who still seach details about the Atari ST: (the link goes randomly into that wiki - in that case it's about the floppy controller, which was pretty important for the original)
http://www.atari-forum.com/wiki/index.php/WD1772

and yup - studying all those stuff was surely pretty important to create CSBwin.
And it's not that you get correct informations on every link you find - and it's not that you understand everything on a quick view ;)

User avatar
Sphenx
Lo Master
Posts: 399
Joined: 9-Sep-01 09:23
Contact:

Re: How was CSBWin created?

Post by Sphenx » 6-Oct-10 20:14

Paul Stevens wrote:I never thought that my program (CSBwin) could also play
DM!!!!! Someone else discovered that after I released it!!
Just because DM and CSB are nearly 100% the same engine (I don't talk about the hint oracle). Just have to switch dungeon.dat and graphics.dat and it's done!
That's also why Theron Quests maps could be extracted then playable with DM engine.

Now, I let you go on with CPU talk.

Post Reply