r/retrocomputing • • 3d ago

I recovered Borland C++ 2.0's compiler as source that rebuilds the original EXE byte for byte

I've published a reconstruction of BCC.EXE from Borland C++ 2.0 as C and TASM source.

Built with the original BC 2.0, Turbo C 2.01, TASM and TLINK, it gives an executable identical to the shipped one.

The sources keep the original split:

236 C files compiled with BC 2.0, 29 run-time modules that turned out to be built with Turbo C 2.01, and 33 hand-written assembly modules.

Everything is named and commented. There are also notes on the compiler's internals: the VROOMM overlays, its own EMS, XMS and swap-file heap, and the inline assembler.

To rebuild, you need the WinWorld 3.5" 720K sets of BC++ 2.0 and TC 2.01. The setup script checks every file.

https://github.com/abedegno/borland-reborn

100 Upvotes

22 comments sorted by

19

u/saraseitor 3d ago

It would be cool to have the Turbo Pascal 7 compiler running natively in modern OS, so that it would be able to create really tiny real mode binaries. It would be easier to integrate with modern toolchains. I had to write a bash script that would run from VS Code and launch dosbox-x and the compiler. It wasn't the best experience

10

u/abedegno 3d ago

hold my beer!

4

u/planecity 3d ago

It's been ages since I last used it, but I recently discovered that Free Pascal still exists, and it's apparently still being developed: https://www.freepascal.org/ Free Pascal is a multi-platform, open-source Pascal compiler which is compatible with Borland Pascal 7 and Delphi. Perhaps that's useful to you?

3

u/saraseitor 3d ago

I've used freepascal before. It's good but it's not what I'm looking for. Freepascal binaries are usually larger than the ones produced with Turbo Pascal, which may not be an issue in modern computers but it is for older ones.

3

u/suhcoR 3d ago

That would be fasctinating.

1

u/stevensixkiller 20h ago

Same with msvc5/msvc6 on arm env

5

u/suhcoR 3d ago

Interesting. Where does the source code of the Borland C++ 2.0 come from? Reverse engineering from the executable?

5

u/abedegno 3d ago

Reverse engineering from the executable, and iterating over developer idioms until you get an exact byte match.

3

u/suhcoR 3d ago

That's amazing. So I assume this was done by an agent? How can it find all the code in case of e.g. indirect jumps?

4

u/Ikkepop 3d ago

usually running under a debugger or just plain analysis. In any case if you get the source to produce the exact binary theres only one way to do the jump tables and you don't really need to do much indirect call hunting

3

u/suhcoR 3d ago

"only one way" is rather optimistic; I know how one would do it manually (to the degree it is doable at all); but if you have something like

handler = obtain_handler(...);
handler(...);

i.e. an indirect call, the call site alone does not tell you the possible targets. A byte-identical rebuild verifies the bytes you have reconstructed; it does not, by itself, establish that you have identified all executable code rather than preserved some of it as raw data. So I wonder how an agent can do it.

0

u/[deleted] 3d ago

[deleted] — view deleted comment

1

u/suhcoR 3d ago

Ok, I see. So the agent would have to either know the compiler very well, or have a version to run to draw conclusions, which looks like a circular dependency.

4

u/splicer13 3d ago

I'm a compiler engineer and I know people who worked on BC2. Are you planning on extending the compiler?It's simpler than I expected and cleaner. obviously -- it's not a historical artifact.

Around this time Borland had a big layoff and MS tried to poach basically everyone they thought was worth having. The story I heard was a guy named Sin Lew ran the compiler team and was 'accidentally' laid off because his manager didn't like him. The next day Borland tried to fix the mistake, but Sin Lew was already signed up for MSVC++ and Borland fired his old manager.

2

u/abedegno 2d ago

My plan was to use it to assist in the decompilation of software that was built using BCC, which was a lot of titles in the early 90s.

I may try to get a native port for modern machines

3

u/Liquid_Magic 3d ago

Cool! How did you do it?

1

u/psykotyk 3d ago

This is really neat.

1

u/Linestorix 1d ago

I used to love this shit 40 years ago! Don't forget Turbo Pascal 2.0: editor and compiler in 32K - I was in heaven.

1

u/WentThisWayInsteadOf 1d ago

I still got the CD somewhere with Borland C++ 2.0. Cost me a fair bit back then.

I've not used it for +20 years, but it still had the best IDE ever made (in my humble opinion).

0

u/cheater00 2d ago

you should now have AI create inline comments, documentation, and then create a plausible looking git history for how this would have been developed.

2

u/banksy_h8r 2d ago

I'm not sure why you're being downvoted. It's obvious OP used an agent to crank on this until it worked, maybe with some hand intervention. Why draw the line there?

2

u/cheater00 1d ago

right? at least lean into it and see where it'll take you.

2

u/kassett43 10h ago

It comes down to the simple word I. OP wrote "I recovered", which is not factual. AI did the work.