Game 5 Unit 21 of 128 1 hr learning time
Title Music
Add a simple beeper melody that plays on the title screen, creating atmosphere and a sense of completeness.
16% of Ink War
Music sets the mood. Even a simple beeper melody makes the title screen feel complete.
Run It
Assemble and run:
pasmonext --sna inkwar.asm inkwar.sna

Version shows “PHASE 2 V0.5”. Listen for the melody on the title screen.
Beeper Music Challenges
The Spectrum beeper has limitations:
| Challenge | Solution |
|---|---|
| No hardware timer | Software timing loops |
| Single channel | One note at a time |
| CPU-bound | Brief notes, gaps for input checking |
| No volume control | Rhythm through silence |
Non-Blocking Music
The key is playing short notes with gaps:
play_title_music:
; Check timer
ld a, (music_timer)
or a
jr z, .play_note
; Still waiting - decrement and return
dec a
ld (music_timer), a
ret
.play_note:
; Reset timer for next note
ld a, 12 ; 12 frames = 0.24 sec
ld (music_timer), a
; Play current note...
This allows the game to remain responsive between notes.
Melody Data
Store pitch values in a table:
title_melody:
defb 30, 35, 30, 40 ; Rising/falling pattern
defb 35, 30, 40, 35
defb 30, 35, 30, 45
defb 40, 35, 30, 25
defb 0 ; End marker (loops)
Higher values = lower pitch (longer delay between beeper toggles).
Note Playback
Play a brief tone without blocking too long:
ld c, a ; Pitch value
ld b, 8 ; Very short duration
.tone:
push bc
ld a, $10
out (KEY_PORT), a ; Beeper on
ld b, c
.d1: djnz .d1 ; Pitch delay
xor a
out (KEY_PORT), a ; Beeper off
ld b, c
.d2: djnz .d2
pop bc
djnz .tone
Eight cycles keeps each note brief.
The Complete Code
This code sample could not be loaded. The file may be missing or the path may be incorrect.
What You’ve Learnt
- Non-blocking music - Play notes without freezing input
- Timer-based sequencing - Use frame counters for note timing
- Melody data format - Simple pitch tables with loop markers
- Beeper limitations - Working within hardware constraints
What’s Next
Unit 22 adds an options menu for configuring game settings.
What Changed
Unit 20 → Unit 21