Skip to content

Put it somewhere

Place a marker using a row and column, then store its position.

A position can be data. We’ll put a single letter on the screen, then change its location by changing two numbers. This is the start of a small movement experiment.

Save Oracle Stone, then reset the Spectrum. Begin in the same 48K setup with an empty program. Resetting prevents leftover lines from becoming part of this experiment.

Choose a row and column

Enter:

10 PAPER 0
20 INK 7
30 BORDER 0
40 CLS
50 PRINT "A MARKER ON THE SCREEN"
60 PRINT AT 10,5;"O"

The first four lines select white ink, black paper and a black border, then clear the display. The title uses ordinary PRINT. Line 60 adds AT to choose where the letter O appears.

PRINT AT 10,5;"O" uses row first, column second. The top-left character cell is row 0, column 0. Rows increase downwards; columns increase to the right. Row 10 is therefore the eleventh row, and column 5 the sixth column.

Enter PRINT with P after the line number, then left Option/Alt+I for AT. Type 10,5;"O" using your normal punctuation keys in Host Keyboard mode. The comma separates the coordinates; the semicolon separates the position from the text to print.

The Spectrum display has 32 character columns and 24 rows. Ordinary BASIC printing uses rows 0–21; the lower part is reserved for input and reports. Use columns 0–31 with PRINT AT. Our eventual movement area will stay inside columns 1–30, leaving a margin at each side.

Run it. The marker should sit away from the instructions. This O is an ordinary character, not a hardware sprite; BASIC prints it into the display like a letter in a sentence.

Store the position

Add lines 55 and 56 and replace line 60:

10 PAPER 0
20 INK 7
30 BORDER 0
40 CLS
50 PRINT "A MARKER ON THE SCREEN"
55 LET row=10
56 LET col=5
60 PRINT AT row,col;"O"

row and col are numeric variables. PRINT AT reads their current values when it executes. The screen does not stay linked to them automatically: a later change to a variable needs another printing instruction to change the picture.

Foundations: A Place to Remember explores variables as stored state. Here those values have a concrete use: they select a screen cell.

The letter O is drawn at row 10, column 5, below the instructions.
The letter O is drawn at row 10, column 5, below the instructions.

Change line 56 to 56 LET col=30 and run again. The marker moves right. Now change line 55 to 55 LET row=2: it moves upwards while keeping its column. Restore row 10 and column 5 for the next lesson.

Which single value moves the marker down one row?

Increase row from 10 to 11. Changing col would move it sideways. We chose row-first coordinates because that is what Spectrum PRINT AT expects; another API may name or order coordinates differently.

Try the legal corners (0,0) and (21,31) in separate runs if you want to explore the bounds. Printing on the title’s row can overwrite a letter; valid coordinates do not guarantee a good layout. Restore the working values before continuing.

Next, Make it move continues this program.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 15, “More about PRINT and INPUT”, AT; chapter 16, “Colours”.