States & Capitals

Date: 1983
Type: Cartridge
Platform(s): TS 2068
Tags: Education

States & Capitals is an educational quiz program covering all 50 U.S. states and their capital cities. The program loads a machine code “expand” routine and a separately saved “flag” binary, suggesting a map or graphical display is rendered using PLOT, DRAW, and CIRCLE commands to mark capital locations using stored x/y coordinates from DATA statements. Three quiz modes are offered: identify the state from its capital, identify the capital from its state, or a randomly mixed mode where even/odd random numbers determine which question type appears. Each DATA record stores the state name, capital name, and four coordinate values used to draw location markers on the map display.


Program Analysis

Program Structure

The program is split across two BASIC files. The loader (lines 10–50) loads machine code blocks and a second BASIC file called “states.” The main program (lines 9–9999 in “states”) handles all quiz logic, scoring, and display. A SAVE "states" LINE 1 at line 9999 packages it as an auto-running file, while SAVE "loader" LINE 10 packages the loader similarly.

Program flow is divided into distinct functional regions:

  • Lines 9–90: Initialization, shuffle, and entry point dispatch
  • Lines 2000–2175: Main question loop (capitals or states mode)
  • Lines 2800–2916: Mixed-mode controller
  • Lines 3000–3099: Correct-answer (first try) handler
  • Lines 3501–3555: Correct-answer (second try) handler
  • Lines 4000–4520: Wrong-answer handler with retry logic
  • Lines 5000–5555: Scoring summary and 100% celebration
  • Lines 5950–5999: Post-quiz menu
  • Lines 6005–6034: Topic selection menu
  • Lines 6900–7250: Utility subroutines (map display, drawing)
  • Lines 8000–8250: “Quiz the computer” reverse-lookup mode
  • Lines 9000–9050: DATA records for all 50 states

Machine Code Usage

Two machine code blocks are loaded by the loader: “flag” at address 44830 (4235 bytes) and “expand” at address 49080 (67 bytes). The expand routine is called immediately via RANDOMIZE USR 49080 after loading. Within the main program, USR 49080 (line 6925) and USR 49113 (line 7000) are called as subroutines, with the return value assigned to c1. The offset of 33 bytes into the expand block (49113 = 49080 + 33) suggests the “flag” block is a bitmap map image and the machine code provides display or decompression services, with the two entry points performing different rendering tasks.

DATA Format and Map Coordinates

Each DATA record at lines 9001–9050 contains six fields:

FieldVariableDescription
1s$State name
2c$Capital city name
3x1PLOT/CIRCLE x coordinate (location marker)
4y1PLOT/CIRCLE y coordinate (location marker)
5y2PRINT AT row for capital label
6x2PRINT AT column for capital label

The PLOT coordinates use the standard 256×176 pixel system. The PRINT AT coordinates are in character-cell units (rows 0–21, columns 0–31), allowing capital names to be placed as text overlays near their map positions.

Question Shuffling

Lines 20–80 implement a Fisher-Yates-style random ordering without a dedicated swap. A string array x$(50) acts as a “used” flags table, initialized to spaces. The loop picks random indices until it finds an unmarked slot, marks it with "1", and records the order in p(n). This is a rejection-sampling shuffle and can be slow toward the end of the 50-element set, but is functionally correct.

Quiz Modes

Three modes are selectable from the topic menu:

  • Mode 1 (m=1): Given a capital, name the state
  • Mode 2 (m=2): Given a state, name the capital
  • Mode 3 (mixed, q=1): The mixed-mode controller at line 2800 generates a random number 1–99 and uses f=b/2-INT(b/2) to test odd/even, randomly selecting m=1 or m=2 per question

A fourth option (line 8000) lets the user type any state or capital and the program performs a linear search through all DATA records to return the matching pair and display its map location.

Scoring System

Three counters track performance: u (correct first try), s (correct second try), and i (incorrect after two attempts). The variable t tracks retry count per question and is reset to 0 at the start of each question. The percentage score is computed as f=INT((C-i)/C*100) at line 5200. A perfect score of 100% on all 50 questions triggers a special celebration with alternating BORDER colors.

Two-Try Retry Logic

The wrong-answer handler at line 4000 increments t. When t=1, a gentle hint (“try again”) is shown via line 4500 and the user returns to the INPUT prompt. When t=2, the full answer is revealed (line 4010) and the question moves on. Lines 2072 and 2111 check t=1 to route back to retry before revealing the answer, implementing the two-chance system cleanly.

Key BASIC Idioms

  • VAL "number" in PRINT AT, INK, PAPER, and GO TO arguments throughout lines 9–9000 — a standard memory-saving technique that stores numbers as strings rather than floating-point constants in the BASIC token stream
  • ON ERR GO TO 9995 and ON ERR RESET used at multiple points for error trapping and clean exit
  • RESTORE 9000+p(o) at line 2020 directly seeks to the DATA record for the shuffled question index, avoiding a sequential scan
  • Line 7030 draws a small question-mark glyph using PLOT and DRAW primitives to indicate the unknown capital location on the map
  • Line 7200 draws three concentric circles of increasing radius using a FOR loop over CIRCLE x1,y1,v, creating a target/bullseye marker for correct answers

Content

Appears On

Related Products

Find out how well you know the states and capitals. Self-teaching tool. Draws map of the US, shows where each...

Related Articles

Related Content

Image Gallery

States & Capitals

Source Code

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

People

No people associated with this content.

Scroll to Top