I'm currently analysing and documenting the AMOS Pro loader -
AMOSPro (relevant sources
+B.s,
+Verif.s,
+InternalJumps.s and
+LibOffsets.s). This is fascinating stuff and has thrown up some possibilities we maybe hadn't considered before.
At the same time, james666 has been looking into AGA for AMOS. And run into the usual problems associated with the AMOS Pro screen and associated data structures being incompatible with AGA structures. We've been corresponding on this subject for a while and discussing possible solutions.
If you haven't had a look at how
AMOSPro starts everything up, this is a quick high-level overview:
The loader is in two code hunks. One is permanent (the interpreter and some internal library functions) and one is discarded after use (the loader and linker).
The loader/linker hunk takes care of:
- Loading and initialising amos.library plus a few of the essential Amiga libraries.
- Allocating and initialising the AMOS data structures (base address pointed to by a5 with both positive and negative offsets).
- Iterates through the AMOS Extensions listed in the editor config file. It pays particular attention to AMOSPro.Lib (for obvious reasons). But I haven't yet figured out what the heck it's doing with those codes in the source that generate Toktab_Verif.Bin. It all takes time...
- It calls Library_Patch, which adds the library functions to AMOSPro.Lib's list of functions. This is needed as that library is split between the library itself (+Lib.s and +ILib.s) and the loader (the permanent hunk of +B.s). So those functions are added here. They're the ones defined using the Lib_Int macro.
- Each loaded library is then subjected to a relocation pass which looks for those AFLINE instructions (as tokens). Each is decoded and, as all the necessary libraries are in memory at that stage, the appropriate instruction and absolute address are inserted as replacements for the original AFLINE instructions and the one or two words following them.
- The relocation action taken depends on whether the library is AMOS Pro V2.0 or an earlier one. This is identified by the AP20 token in the 'new' libraries.
- The earlier libraries are just relocated as above. In addition, a table is used to re-map and replace any 'old' system instruction numbers with 'new' ones.
- The V2.0 libraries also have each instruction's parameters examined (if any) and the appropriate parameter jump addresses are inserted into the functions. These jumps replace those GetP markers in a V2.0 library put there by the Lib_Par macro.
- I haven't looked at the compiler yet (I'm leaving it until last) but comments in +equ.s suggest it does a similar load and link. But against discrete code chunks for each instruction and using relative addressing instead of absolute.
From the above, you can see that AMOS Pro is already doing re-mapping depending on context. The interpreter also does similar re-mapping when it encounters instructions like
Double Precision.
From the work that james666 has done, we know that the existing AMOS screen, window and associated data structures can't cope with the extra data storage required for AGA. At least, not without a very messy solution and the inevitable slow down as new storage areas are re-mapped "on the fly".
So, to get around the problem of retaining compatibility with previous AMOS programs and extensions, there would appear to be two courses we can take:
- Give up on compatibility and rewrite an AGA-only version of AMOS.
- Explore the possibilities presented by re-mapping screen structures "on demand'.
We don't like the idea of option 1 as I think the appeal would be very limited.
Option 2 would use techniques already present in the loader and interpreter. (And presumably also in the compiler. But note that I haven't analysed that yet.)
So how would it work?
I've been thinking it over from the programmer's point of view. I.e. the real AMOS User. They're used to context switching in their existing instruction sets. So giving the choice of AGA or non-AGA with something like a
Set Aga command at the start of a program would come as no real surprise. We're already used to
Set Buffer,
Set Accessory, etc.
From the programmer's perspective:
Advantages- Existing software and extensions would still work (non-AGA) without any changes. This includes any system calls and/or direct access to the AMOS data structures. They would remain as they are.
- The existing AMOS Pro included libraries can be easily converted as we have the sources. Only +B.s, +ILib.s and +Lib.s would require any major surgery anyway.
- Authors of any new extensions can make the choice between AGA and non-AGA simply by choosing the appropriate "compatibility token" - we would suggest using the existing AP20 for non-AGA compatible and AP21 for AGA compatible. If they choose AGA, then the new AMOS AGA data structures would be automatically re-mapped for them. As this is done by the loader, there's no impact on performance. The AGA structures just sit there until the interpreter sees a Set Aga instruction. Then it just switches the structures and remaps any related calls. Note that this is done at program Test time, so again, there's no performance impact when a program is actually running.
- Most existing 3rd-party extensions could convert to AGA compatible as long as they don't use any graphics (to be defined!). The conversion could easily be achieved even if the sources are not available (simply change the AP20 token to AP21 with a hex editor, or insert it for an earlier library).
- Whatever the programmer's choice, hardware AGA availability is the governing factor. If the loader does not detect an AGA chipset, the Set Aga instruction throws an error at Test time.
Disadvantages- Some significant existing third-party software would need re-writing if it wanted to take advantage of AGA. Eg. TOME.
- More complex environment for the hard-core programmers, extension writers and assembler fans. But at least the structures and code would be available and documented.
- Some memory size bloat. But as we all seem to agree, that's not really an issue these days.
We (james666 and I) are very much in favour of this approach for the post-bug-fixing phase of development.
What does the forum think?