r/retrocomputing • • 23d 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

130 Upvotes

28 comments sorted by

20

u/saraseitor 23d 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

12

u/abedegno 23d ago

hold my beer!

5

u/planecity 23d 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?

4

u/saraseitor 23d 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.

1

u/mercnz 17d ago

i've been messing with rust for windows and os/2, and it does irk me a little that i can't get quite as small as i'd like, but it's so tempting to want to make rapid progress. depends how old you want to go, and how low ram how much it matters though. one of the things i found when trying to look at a lot of legacy stuff is that a lot of the times the code was quite condensed as a general rule of thumb, and on modern cpus we often worry a lot more about code alignment etc than was done back then. potentially can mess with some more modern compilers to get things tighter, for legacy stuff i'm mixing watcom c, clang, rust generally. watcom c is easier to interface with older system libraries, pascal calling convention etc.

3

u/suhcoR 23d ago

That would be fasctinating.

1

u/stevensixkiller 20d ago

Same with msvc5/msvc6 on arm env

1

u/mercnz 17d ago

is native really that big a deal? one of my many projects has involved a dos emulator, that's running turbo pascal amongst one of the few tests cases, and partially it's to create test programs using it to test dos stuff :) but my dos emulator is doing a few novel things, like it's picking up when turbo pascal executables are being loaded and is replacing the overlay loader system with it's own... it's also replacing delay, random, some crt stuff etc. it started from wondering if i could the bbs door game BRE going more efficiently. it starts way faster than dosemu, and i have benchmark scripts etc, and it's a bit slower on ivy bridge than newer cpus, but on 64 bit cpus i'm doing pretty well with cpu performance for that kind of workload. dosemu is faster at running fastdoom though (which does complex dynamic code changing which messes with simple jit systems)

1

u/saraseitor 17d ago

it is too me! the whole point that powers my interest on this is nostalgia. Interfacing VS Code with TP7 using a script was a pain

6

u/suhcoR 23d ago

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

6

u/abedegno 23d ago

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

4

u/suhcoR 23d 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 23d 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 23d 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] 23d ago

[deleted] — view deleted comment

1

u/suhcoR 23d 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.

5

u/splicer13 22d 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.

3

u/abedegno 22d 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 22d ago

Cool! How did you do it?

2

u/PolicyPopular1349 19d ago

Very good work! Was the Ghidra decompiler used to obtain the source code?

1

u/psykotyk 23d ago

This is really neat.

1

u/Linestorix 21d 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 21d 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).

1

u/66659hi 17d ago

My dad still uses the Brief macros to this day 

1

u/joolzg67_b 17d ago

Are you going to do 3.1 as that is what I spent 4 years writing programs with

0

u/cheater00 22d 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 21d 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?

3

u/kassett43 20d ago

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

2

u/cheater00 21d ago

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