Star Spangled Banner

Developer(s): Oleg D. Jefimenko
Date: 1986
Type: Program
Platform(s): TS 2068
Tags: Music

This program displays a graphical American flag on screen and plays “The Star-Spangled Banner” melody using the BEEP command with frequency and duration data encoded across multiple DATA statements. The flag is constructed using Spectrum block graphics characters, with UDG “C” redefined via POKE USR to render star shapes in the canton. The music data consists of semitone-offset and duration divisor pairs, with a sentinel value of F=100 used to change the base tempo multiplier mid-song from 1.9 to 2.5. Error trapping via ON ERR GO TO 400 elegantly handles the end-of-DATA condition, branching to a final PAUSE 0 instead of crashing with an error.


Program Analysis

Program Structure

The program is divided into four logical phases:

  1. Title screen (lines 20–110): Displays a title banner with credits for the “Musician Royal” software used to compose the music data.
  2. Flag construction (lines 120–210): Sets up the screen, defines a UDG star character, and draws the flag using block graphics and UDG characters.
  3. Music playback (lines 220–300): Reads frequency/duration pairs from DATA and plays them with BEEP, using ON ERR to detect end-of-data.
  4. Termination (lines 310, 400): Saves the program with auto-run, and the error-trap landing pad halts on PAUSE 0.

UDG Star Definition

Lines 130–140 define UDG character "C" (character code 144+2 = 146) by POKEing eight bytes into the UDG area starting at USR "C". The data 0,8,8,127,28,54,34,0 encodes a simple star-like shape in an 8×8 pixel grid. This UDG is subsequently used in lines 190–200 to populate the blue canton of the flag.

Flag Rendering

The flag is drawn entirely with PAPER/INK color attributes and block graphic characters. The red and white stripes are rendered using \..\.. (▄ repeated) and \::\:: (█ repeated) characters in INK 2 (red) on alternating rows, creating a striped effect. The canton (upper-left blue field) is drawn with PAPER 1; INK 7 (blue background, white stars) using the redefined UDG \c references in lines 190–200. A FOR L=1 TO 4 loop staggers two rows of stars per iteration, producing the offset star-row pattern of the flag.

Music Data Format

Music data is stored as pairs F, V across lines 250–300, where F is a semitone offset (relative pitch) and V is a divisor applied to the current tempo value T, so the actual BEEP duration is T/V. This compact representation was likely exported from the “Musician Royal” composition utility mentioned in the credits.

The sentinel pair 100,100 at line 300 does not represent a note — it is intercepted by the IF F=100 check in line 230, which changes T from 1.9 to 2.5 (slowing the tempo) for the final few notes before the true end-of-data triggers the ON ERR handler.

End-of-Data Error Trapping

Line 220 sets ON ERR GO TO 400 before beginning music playback. When READ exhausts the DATA statements, a “Out of DATA” error is generated, and execution jumps cleanly to line 400 (PAUSE 0) rather than crashing. This is a common and idiomatic TS2068 technique, exploiting the structured error handler as a loop-termination mechanism.

Key Variables

VariablePurpose
ILoop counter for POKEing UDG bytes (0–7)
CHolds each UDG byte read from DATA
JLoop counter for drawing stripe rows (1–6)
LLoop counter for drawing star rows in canton (1–4)
TBase tempo multiplier; 1.9 initially, 2.5 after sentinel
FSemitone offset for BEEP
VDuration divisor for BEEP

Notable Techniques and Anomalies

  • The PAUSE 0 at line 120 acts as a keypress gate between the title screen and the flag display, a standard idiom.
  • Line 150 prints an entire row of block graphic characters in a single PRINT statement combining both \..\.. (▄) and \::\:: (█) segments — the color change from yellow paper to red ink is handled inline with INK 2.
  • The GO TO 230 at the end of the sentinel-handling branch skips re-reading F and V, correctly advancing to the next DATA pair after updating T.
  • The loop in line 190 uses two AT positions within a single PRINT to draw two offset star rows per iteration, reducing line count.
  • Line 210 prints a short PAPER 1 string to close out the canton’s bottom edge cleanly.

Content

Appears On

The biggest LIST tape yet — play poker accompanied by chip-tune renditions of classic songs, diagnose illnesses with a Bayesian expert system, master Z80 opcodes with a quiz, or unscramble anagrams before the cauldron boils over. Four custom fonts included.
A little of everything — play Battleship with adjustable AI, solve Klondike Solitaire with custom card graphics, guide Santa's reindeer into their pen, or track your stock portfolio on tape. The potpourri tape lives up to its name.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

   10 REM *** This program was   written by Oleg D. Jefimenko on         August 12, 1986.
   20 PAPER 6: BORDER 4: CLS 
   30 PRINT PAPER 5;"***** STAR SPANGLED BANNER *****"
   40 PRINT PAPER 5;AT 21,0;"***** STAR SPANGLED BANNER *****"
   50 PRINT AT 7,1 ;"THE MUSIC PART OF THIS PROGRAM"
   60 PRINT TAB 6;"WAS CREATED BY USING"
   70 PRINT TAB 8;"""MUSICIAN ROYAL"""
   80 PRINT TAB 8;" SOFTWARE  FROM"
   90 PRINT TAB 2;"THE ELECTRET SCIENTIFIC CO."
  100 PRINT TAB 1;"BOX 4132, STAR CITY, WV 26505"
  110 PRINT AT 20,0; PAPER 7;"     PRESS ANY KEY TO START     "
  120 PAUSE 0: PAPER 7: BORDER 5: CLS 
  130 FOR I=0 TO 7: READ C: POKE USR "C"+I,C: NEXT I
  140 DATA 0,8,8,127,28,54,34,0
  150 PRINT PAPER 5;"                                "; INK 2;"\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::"
  160 FOR J=1 TO 6: PRINT INK 2;AT J*3+1,0;"\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\..\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::": NEXT J
  170 PRINT PAPER 5;"                                "
  180 PRINT PAPER 5; INK 1;AT 1,0;"\..\..\..\..\..\..\..\..\..\..\..\..\.."
  190 FOR L=1 TO 4: PRINT PAPER 1; INK 7;AT 2*L,0;" \c \c \c \c \c \c ";AT 2*L+1,0;"  \c \c \c \c \c  ": NEXT L
  200 PRINT PAPER 1; INK 7;" \c \c \c \c \c \c "
  210 PRINT PAPER 1;"             "
  220 ON ERR GO TO 400: LET T=1.9
  230 READ F,V: IF F=100 THEN LET T=2.5: GO TO 230
  240 BEEP T/V,F: GO TO 230
  250 DATA 3,8,0,8,-4,4,0,4,3,4,8,2,12,8,10,8,8,4,0,4,2,4,3,2,3,8,3,8,12,2.67,10,8,8,4,7,2,5,8
  260 DATA 7,8,8,4,8,4,3,4,0,4,-4,4,3,8,0,8,-4,4,0,4,3,4,8,2,12,8,10,8,8,4,0,4,2,4,3,2,3,8
  270 DATA 3,8,12,2.67,10,8,8,4,7,2,5,8,7,8,8,4,8,4,3,4,0,4,-4,4,12,8,12,8,12,4,13,4,15,4,15,2,13,8
  280 DATA 12,8,10,4,12,4,13,4,13,2,13,4,12,2,10,8,8,8,7,2,5,8,7,8,8,4,0,4,2,4,3,1.33,3,4,8,4,8,4
  290 DATA 8,8,7,8,5,4,5,4,5,4,10,4,13,8,12,8,10,8,8,8,8,4,7,2,3,8,3,8,8,2.67,10,8,12,8,13,8,15,1
  300 DATA 100,100,8,8,10,8,12,2.67,13,8,10,4,8,2
  310 SAVE "ANTHEM" LINE 10
  400 PAUSE 0

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top