The Star Trek IP has spawned numerous movies, novels, and games over the course of several decades, in various fields. Since the launch of the Star Trek game series, there have been several series that have attracted many loyal fans.

Emanuele Bolognesi is a big fan of retro games and retro programming. In the past few days, he has devoted all his free time to rewriting the original 1978 Super Star Trek.

Super Star Trek is an old plain text game that is an example of turn-based space strategy simulation written in Basic. In this game, you are the captain of the Enterprise starship, and your mission is to scout Alliance space and destroy all the invading Klingon ships.

You must carefully manage the ship’s power throughout the game, destroying the Klingon ship with phase cannons and torpedoes, and finding the Star Base to repair the damage and replenish your power. All of this, through a few characters on the screen and a rich imagination.

Despite its simplicity, it is a good example of programming and game design. You can control the input of commands at the prompt: NAV moves the ship, PHA fires with a phase gun, LRS scans the quadrant with a remote sensor, and so on.

Started in 1974, Super Star Trek was an improved version written by Bob Leedom in 1978 and became a hit after it was published in the book Basic Computer Games.

Super Star Trek was not a game that was released on disk, the book contained code that people had to type into a computer. Since BASIC was a general-purpose language at the time, the game code could run on many different machines.

Revisiting a classic game after 37 years

In 1983, Emanuele Bolognesi bought a book published in Italy called Zap! Pow! Boom! Arcade Games for the VIC-20 by Mark Ramshaw. It contained 30 VIC-20 games written in BASIC, the eighth of which was called Star Trek.

Emanuele Bolognesi copied it all onto his VIC-20. He said: ‘It was simple, but I loved it immediately. It was probably the best game I’ve ever played on that computer.” It took Emanuele Bolognesi 37 years to realize that the program was actually an adaptation of Leedom’s Super Star Trek. He immediately decided to try the original Super Star Trek. He downloaded the BASIC interpreter from the Vintage Basic website, the game’s source code and started running it.

Rewrite the code, restore the classic

Rekindled interest in the classic game, Emanuele Bolognesi began researching whether anyone had rewritten it over the years in a more readable format. But the 1978 code looks mysterious, with few comments explaining its algorithms.

Emanuele Bolognesi found many game ports on the Internet, but none of them were Super Star Trek from 1978. These new versions feature cloaking devices, supernovae, death rays and more. But these were not the original versions, so Emanuele Bolognesi rewrote the code himself.

Initially, he chose to write in Perl because it is a scripting language that can run on any Mac or Linux, and because Perl has goto statements. According to Emanuele Bolognesi, at least initially, it would have been impossible to port all the original BASIC code without using any Goto.

But even simple translation turned out to be harder than he expected, porting 500 lines of BASIC (packaged as much as possible) to save memory, which meant that each line contained several instructions separated by semicolons and no space. Such as:

Emanuele Bolognesi patiently rewrote each line, trying to avoid any mistakes, because missing a point could change everything. He initially adopted 1:1 translation, but soon realized that this might make it unreadable. So he started converting some if-then-goto blocks into if-then-else blocks.

From the above code, you can see “THEN3500” on line 3170, which stops the “for” loop starting at the beginning of the line (for loops that are not programmed in BASIC, You can type IF THEN instead of IF THEN GOTO so Emanuele Bolognesi in his code changed it to (“last” in Perl).

Emanuele Bolognesi quickly realized that some Gotos had jumped into unexpected places, like the middle of a function, or the middle of a block.

Patiently identifying and separating all the blocks of code is the most difficult part of this work, but it can be very useful for understanding game mechanics. As long as Emanuele Bolognesi is familiar with code, he will also give variables meaningful names, such as “EnergyLevel” instead of “e” or “TotalKlingonShips” instead of “K3”.

After the Perl version, Emanuele Bolognesi decided to port the game to Lua. To do this he basically checks all the code from scratch. Rewrote most of the loops. “I have to admit that the code is much better now, and I know all the parts pretty well,” he says. At the time of writing, Emanuele Bolognesi left many comments for people who wanted to understand the program.

Obviously, this work is never done, and the code could be improved more. But now it’s fully functional, and the game looks and behaves exactly like the original game.

For fans of retro games, it makes more sense to revisit the classics than to add more experiences, as there are many newer versions that already do just that. Retaining the original and recreating the classic in such a simple way also has a special taste.

The original link: https://hackernoon.com/rewrit… Making address: https://github.com/emabolo?re…