Well, we don't have linked lists, we don't have structs, we don't have pointers, so what else can you use? Peeking and poking?
Erm, well not
quite true. Just infernally cumbersome.
AMOSPro.Lib has full linked list handling functions, they were just never exposed as AMOS Basic instructions. Something for the version after bugfix and docs?
Structures can be defined - see
AMOSPro_Productivity1:Equates/Equates.Doc and
AMOSPro_Productivity1:Equates/AMOSPro_System_Equates. But it's a cumbersome task to use an assembler and the
Make_Equates.AMOS program to make the
AMOSPro_System_Equates file. Easier to edit by hand... And whatever you happen to need for a particular program effectively becomes global across all your programs. It would be so much more user friendly to be able to define data structures on the fly. Another wish list item for after bugfix, etc.
I think the AmosPro sort command only works on single-dimension arrays. Thus it is almost completely worthless.
Agreed! The only use I could ever dream up for it is to use a string array where each element is effectively a 'record' using fixed-length 'fields'. Then use
Mid$() to extract the individual 'fields'. The 'field' at the start of the string can then be reserved as a sort key 'field' and initialised with a value from one of the other fields in the record. The
Sort statement then becomes a little bit useful. However, changing keys for the sort involves iterating the entire array moving the new sort 'field' to the sort key 'field' at the head of the string. It would work but a bit cumbersome again.
For the curious:The linked list functions in
AMOSPro.Lib are these:
All these functions use a
very simple list element:
Lst_Next rs.l 1 ; pointer to next element
Lst_Length rs.l 1 ; length of user data
Lst_UserData rs.b|w|l nnn ; user data
To use them from assembler code, just load the registers and
JJsr L_Lst.xxxx.
(Where
L_Lst,xxxx is the name of the function - the assembler picks this up from the
+LEqu.s file in the includes.)
To use them from AMOS Basic, you need to load the registers using the
Areg() and/or
Dreg() statements. Then emulate what the
JJsr macro does:
G_ADDR=(Leek(Areg(5)+$20)-(FunctionNumber*4)-40)
Call Leek(G_ADDR)
(Where
FunctionNumber is the number in brackets alongside each function below.)
This converts
FunctionNumber into the correct offset from the library base:
Leek(Areg(5)+$20) is the base address of AMOSPro.Lib.
-40 is needed to skip over the library's header data.
FunctionNumber*4 indexes into the library's table of longword addresses to get to the entry for
FunctionNumber.
Call Leek(G_ADDR) calls the function pointed to at that location.
L_Lst.ChipNew (89)
Create a new list element in Chip memory (
Chip|Clear|Public).
Will be initialised as the head element of an empty list.
IN: D0 = element length in bytes.
OUT: A0 = pointer to element address, D0 = length allocated (0=failed!).
L_Lst.New (90)
Create a new list element in Fast memory (
Clear|Public).
Will be initialised as the head element of an empty list.
IN: D0 = element length in bytes.
OUT: A0 = pointer to element address, D0 = length allocated (0=failed!).
L_Lst.Cree (91)
Create a new list element in specified memory.
Will be initialised as the head element of an empty list.
IN: D0 = element length in bytes, D1 = memory flags (as for system
AllocMem()).
OUT: A0 = pointer to element address, D0 = length allocated (0=failed!).
L_Lst.DelAll (92)
Delete an entire list.
IN: A0 = pointer to head element.
L_Lst.Del (93)
Delete a list element and free its memory.
IN: A0 = pointer to head element, A1 = pointer to list element to delete.
L_Lst.Insert (94)
Insert a list element at the head of an existing list.
IN: A0 = pointer to head element, A1 = pointer to list element to be inserted.
L_Lst.Remove (95)
Remove a list element (DOES NOT free its memory).
IN: A0 = pointer to head element, A1 = pointer to list element to remove.