Skip to content

Make the instructions fit

  • Sinclair ZX Spectrum
  • Assembly

A game needs to explain its controls and rewards before the player has to guess them. We will finish the title so it presents those rules, and let the program work out where each line goes.

Unit 11’s title placed four lines at columns we counted by hand. Adding lines that way means counting again, and editing a line means counting it again too. The finished title adds three lines, for held double speed, star values and the faster-finish bonus, and places all seven with a new routine, text_center. In the title, each ld bc,$RRCC and call text pair becomes ld b,$RR and call text_center: the row stays in the source and the column is calculated. The HUD keeps time, speed and score visible during flight. A result names the outcome, bonus, records and retry controls. None of these screens changes the contact rule.

Source · view and edit
ZX Spectrum
Companion file: assets.inc

The include line reads this editable data when you assemble. Keep it beside your source for a local build.

Edit the source, then assemble.

Edits are saved in this browser. Keep a downloaded copy of work you want to keep.

Focus the Spectrum screen to use the keyboard, or hold these buttons. Assemble again for a fresh machine.

Run the program to inspect it. Editing source does not change the running machine.

phase
—

Draw characters without borrowing print state

text takes B=character row, C=column and DE=a zero-terminated string. Each character code selects eight bytes of ROM-font data. The routine computes the character’s bitmap position using pixel_address, copies its eight rows, then advances to the next character column.

The address calculation uses 8*character + $3C00. This places printable character 32 at the font’s first space glyph. It is an address formula for the supplied Spectrum ROM font, not permission to draw arbitrary control codes as useful text. Our strings contain printable characters and a zero terminator.

The routine saves the text pointer and B/C while the glyph-copying work uses those registers, then restores them before continuing. Its caller should nevertheless treat all primary registers as changed after the complete text call.

Centre from the actual length

text_center counts characters until the zero byte, subtracts the count from 32 and divides by two with a right shift. Integer division rounds down, which is the chosen centring rule when an odd spare column remains.

meteor-storm.asm, excerpt
text_center:
 ld h,d
 ld l,e
 ld c,0
text_measure:
 ld a,(hl)
 or a
 jr z,text_measured
 inc hl
 inc c
 jr text_measure
text_measured:
 ld a,32
 sub c
 jr nc,text_centre_column
 xor a
text_centre_column:
 srl a
 ld c,a
 jp text

METEOR STORM has twelve characters including its space. (32-12)/2 gives column 10, the same column we counted by hand in unit 11. Counting only letters, or treating a character coordinate as a pixel coordinate, would position it incorrectly.

text separately checks row and column bounds. It returns if row is at least 24 or column is at least 32, so a long string is clipped instead of wrapping into another row. An overlong centred string starts at column zero before that clipping.

Would centring a 33-character instruction make all of it readable?

Show the explanation

No. There are only 32 character columns. Bounds checks prevent unwanted writes, but they cannot create room. Shorten the instruction or split it deliberately over two rows. Clipping is a guard, not a layout strategy.

Change only the quoted title in name_text, preserving its final zero. Predict the new starting column and run. Try a short title and a deliberately overlong one, then restore METEOR STORM. Review the result at the actual displayed size, not only by counting source characters.

For a final play review, ask someone to launch, boost, collect a star and retry using the on-screen instructions. A correct keyboard routine cannot make an unexplained control discoverable.

Sources

Sinclair Research, ZX Spectrum BASIC Programming, chapter 24, display-file and attribute layout. Zilog, Z80 CPU User Manual, UM008011-0816, instruction descriptions for shifts, logical operations and loads.

Run it here

This unit's program, built for you.

Program
meteor-storm.tap
Machine
ZX Spectrum 48K (PAL)

Download meteor-storm.tap