PlayBasic LIVE : Intro Converting Amos To PlayBasic (2017-12-03)
Welcome... Today we'll take a look back at a free tool created to help Amos & AmosPro programmers begin the conversion process to PlayBasic. The tool is simply called AmosToPlayBasic and can be found on our forums and includes conversion support for the core Amos to PlayBasic syntax through to exporting the various hidden data banks within Amos such as Sprites/Pictures/Samples and Music modules.
Note: Later in the video we go through how to improve the conversion by adding your own Amos command tokens to the instruction sets.
Programming has enough annoying problems as it is, let alone trying to covert legacy source code around between languages. Bizarrely the problem hasn't really improved that much since when I started programming back in 1982, at least then there was a good reason, like.. you know... assembly - Today, there's lots of conversion tools between main stream languages, but there's just so many languages out there, lots of legacy code just ends up sitting gathering dust.
I dunno about other programmers, but I always try to hang onto my legacy source codes in one big retro collection. The oldest stuff dates back to the 90's (lost my 8bit stuff ;( ). The code is mostly AMOS and 68k Assembly from the Amiga days. The assembly code isn't much use, but a lot of legacy BASIC code can be. The trouble with languages like AMOS, is that the source code files aren't raw text, they're stored in a tokenized format. So you either need AMOS to view them, or a conversion tool.
Converting AMOS / AMOSPRO source code to PlayBasic
Those with a long memories might recall I've had a few tinkers with writing translation programs over the years, even getting a 'mock up' translator to produce actually working conversion of some simple AMOS programs (and a few other dialects) programs. While the Amos convertor worked (to a point) it was basically a brute force solution, since that translator was working at string level making it very hit and miss.
Normally when parsing source code, you'd translate the text stream into a tokenized state, then decipher what's going on from the tokens. But for AMOS programs, it makes sense to load the tokenized code and decode that directly. I'd looked at doing this before and got a fair way into it, only to find a tool that already convert AMOS V1.2V1.3 codes, but not AMOS PRO. So the decision was made to drag out my older attempt and cut'n'pasted that into new project from it's ashes.
Only took a few hours to get it a reasonable translation of a real world binary Amos program working. But what you have to remember, is that AMOS is huge language and I've absolutely NO intention of building a one stop shop convertor. Rather, the objective was to make the tool spit out a reasonable translation that any programmer can then use as a basis for the PlayBasic version. Meaning the program LOGIC should be in tact, but of course there's no easy way of mapping the entire AMOS command sets to PlayBasic without writing an abstraction layer. Which is possible for simple programs (since that's how the previous test worked) but somewhat unrealistic for medium to large AMOS programs.
What's Supported ?
The tool currently supports all versions of AMOS including 3rd party extensions. However, not all the Amos command sets are mapped though, but these can be defined externally by the user. This can mean a little messing around initially, in particular if the code you want to covert uses extensions heavily, but unfortunately Amos source files don't include such mappings in them, so we can't do it automatically.
Beyond just loading the Amos sources, the program applies a number of translations to the original input code prior to saving the PlayBasic styled version. Ranging from the simple declarations, converts procedures to functions (supports encrypted procedures), variable name collisions and any number of core Memory.Math/String function & operator level conversions. Now depending upon what command sets the original AMOS code uses, will dictate how 'ready to run' the translation is. But it's highly unlikely that programs will run first go however.
One of the nice things about using a binary format for your source code, is that AMOS programs often had data hunks attached to them. These hunks range from SPRITES, ICONS, PICTURES, SAMPLES, MUSIC etc etc. The user can exported them (optionally) with the translated source code.
For More Information: See Amos To PlayBasic Work in progress thread for downloads.