
Previously we looked at how AMOS can load images and configure screens, setting up screen resolution and number of colours.
I also left you with a tease about this lesson, where I mentioned that AMOS has a feature where you can have layered scrolling via a feature called “Dual Playfield”.
Let’s dig into that now …
Parallax Scrolling AMOS Dual Playfields
Now we can load in images, we can extend that to load two images, layered, with the bottom image visible through gaps in the top image. This is used to great effect in many shoot ’em up games where it offers a 3D depth effect called Parallax Scrolling. It feels like the top layer is closer, because it is moving faster than the bottom layer.
To get a “parallax effect”, each screen can be scrolled individually by setting its offset.
If you have ever tried to achieve this in other languages, you know that this is not usually an easy task!
Now, there are limitations and issues with this approach, which we will get into. Fortunately, this is not the only way to achieve scrolling in AMOS.
Setting Up AMOS Screens
On a regular, original chipset Amiga, we can have 8 colours per layer, so we set up a full low res screen for each:
' Turn off cursor, mouse, clear screen Flash Off : Curs Off : Hide On : Cls 0 ' Foreground image 8 colours, low res Screen Open 2,320,200,8,Lowres ' Load the foreground image Load Iff "foreground.lbm",2 ' Background image 8 colours, low res Screen Open 1,320,200,8,Lowres ' Load Background Load Iff "background.lbm",1 ' Dual playfield = show both front/back Dual Playfield 2,1 ' Wait for keypress Wait Key
Here is the result …

Ugh, what happened?
A couple of things went wrong that we need to fix.
First, the colours are way off. Second, and it might not be immediately apparent from my image but would probably be in yours, my picture appears to be a bit squished.
The second issue is caused by an apparent need for AMOS to be given some time to set up things, so we can add a wait after each image load. A wait of 5 seems to work for me, but feel free to play with numbers.
Colours being off is caused by the palette and is an opportunity to discuss how colours work in AMOS
Colours in AMOS
Note in AMOS the spelling of Colour is with a U. As a Canadian with a British Passport this comes naturally, but you might need to keep an eye on that 😉
AMOS stores a colour palette in memory, then any time you use a colour you then select it via its index. For example, we can print “Hello World” in white on blue text like so:

Colours are set as hex values, 000 to FFF, giving 4096 possible choices.
You can also read the value of a certain index, either as decimal or, using Hex$, in hex.

Knowing this allows us to store and display the current palette on screen, perhaps to set the colours that were wrong above:
' Turn off cursor, mouse, clear screen Curs Off : Hide On : Cls 0 ' Foreground image 8 colours, low res Screen Open 2,320,200,8,Lowres ' Load the foreground image Load Iff "foreground.lbm",2 ' Set up a list of colours Dim MY_PAL(8) ' Go through the colours show + copy them X=0 ' loop from 0 to 7 For I=0 To 7 Ink I,I,I X=X+8 ' draw a filled box Bar X,20 To X+8,28 ' Store the colour MY_PAL(I)=Colour(I) ' go round the loop again Next I

This is a perfect time to explain variables, loops and arrays!
AMOS Variables, Loops and Arrays
Variables are like little boxes where you can store information. They can store numbers or text (known as “strings” in the trade).

When we say X = 0 we are telling AMOS that we want to store the number 0 in the box labelled X.
We can then perform math on that value, so X=X+8 means “whatever you have stored within X, add 8 to it, then store the result in X”.
Arrays take that concept and extend it so instead of one box called X, we have a whole set of boxes.

' Set up a list of colours Dim MY_PAL(8)
This sets up an Array, that is a a set or list of variables, with 8 slots. Each can be addressed individually and the array or list can be addressed as a unit.
We can then store each colour we find in its own slot within our list of colours. That is done using a Loop.
Loops are a way for our AMOS program to repeat an action. The particular loop we use here is a For loop, and that does the action a number of times, incrementing a counter each time. When the counter reaches the limit we set, it stops looping and continues with the rest of the program.
Try something like this and see how it works:

AMOS Palette
Setting or storing each colour individually can get a bit laborious, so AMOS also provides a feature where you can set a palette, whole or in part, all at once using, naturally, the Palette command:

(Any colours that you do not want to set can be skipped, hence the ,,, )
Of course you could use Colour(1) etc as before, but then I wouldn’t have been able to talk about Arrays 🙂
Scrolling, Finally!
Now we finally can scroll with the correct colours.
' Scroll the background 10x For REPETITIONS=0 To 10 ' Count down from 400 to 0 For Y=400 To 0 Step -1' Display the background at offset
Screen Offset 1,0,Y
'wait for vertical blank
Wait Vbl
Next Y Next REPETITIONS
This consists of two loops, one “nested” within the other.
The outer loop tells AMOS to do the inner loop 10 times.
In our inner loop we scroll the background by setting its offset from 400 pixels to 0. You will notice our previous loops counted up so we need to set Step -1 to tell AMOS to decrement rather than increment the counter.
So now our background essentially gets pushed down until it has gone then repeats another 9 times.
By setting the background picture much taller than the screen, this gives the impression it is one long field rather than the same image looping over and over!
Full Code
Rem ------------------------
Rem Maker Hacks 2020
Rem AMOS BASIC tutorial
Rem Part 2: Two Screens
Rem ------------------------
' Turn off cursor, mouse, clear screen
Flash Off : Curs Off : Hide On : Cls 0
' Foreground image 8 colours, low res
Screen Open 2,320,200,8,Lowres
' Load the foreground image
Load Iff "foreground.lbm",2
Wait 5
' Background image 8 colours, low res
Screen Open 1,320,200,8,Lowres
' Load Background
Load Iff "background.lbm",1
Wait 5
' Dual playfield = show both front/back
Dual Playfield 2,1
Wait 5
' Set up a list of colours
Dim MY_PAL(8)
' Go back to screen 1
Screen 1
' Go through the colours show + copy them
X=0
For I=0 To 7
Ink I,I,I
X=X+8
Bar X,20 To X+8,28
MY_PAL(I)=Colour(I)
Next I
' Switch to screen 2
Screen 2
' Use the screen 1 colours we grabbed earlier
' Note the first set are not changed!
Palette $0,,,,,,,,MY_PAL(0),MY_PAL(1),MY_PAL(2),MY_PAL(3),MY_PAL(4),MY_PAL(5),MY_PAL(6),MY_PAL(7)
' Display palette to show same
X=0
For I=0 To 7
Ink I,I,I
X=X+8
Bar X,30 To X+8,38
Next I
' Wait for keypress
Wait Key
' Scroll the background 10x
For REPETITIONS=0 To 10
' Count down from 400 to 0
For Y=400 To 0 Step -1
' Display the background at offset Screen Offset 1,0,Y ' wait for vertical blank Wait Vbl
Next Y
Next REPETITIONS
' Wait for key before ending
Wait Key