--- title: "States & Capitals" id: 51780 type: "computer_media" slug: "states-capitals" url: "http://localhost/computer_media/states-capitals/" markdown_url: "http://localhost/computer_media/states-capitals.md" published_at: "2023-08-13T23:14:31+00:00" modified_at: "2026-03-31T22:24:03+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "A 50-question geography quiz on U.S. states and capitals that draws map location markers and tracks first-try, second-try, and incorrect answers separately." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "Timex Computer Corporation" slug: "timex-computer-corporation" taxonomy: "post_tag" url: "http://localhost/tag/timex-computer-corporation/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Education" slug: "education" taxonomy: "genre" url: "http://localhost/type/education/" media_type: "Cartridge" download_url: "https://archive.org/download/timex-sinclair-software-archive/States & Capitals (1983)(Timex)(US)(TS2068)(Cartridge).zip" mediadate: "1983" producer_company: - id: 11401 title: "Timex Computer Corporation" type: "company" url: "http://localhost/company/timex-computer-corporation/" images: - url: "http://localhost/wp-content/uploads/2023/08/SCR-20260331-qasj.png" - url: "http://localhost/wp-content/uploads/2023/08/SCR-20260331-qaug.png" related_products: - id: 35358 title: "States and Capitals (cart)" type: "product" url: "http://localhost/product/states-and-capitals-cart/" media_type_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: | Field | Variable | Description | | --- | --- | --- | | 1 | `s$` | State name | | 2 | `c$` | Capital city name | | 3 | `x1` | PLOT/CIRCLE x coordinate (location marker) | | 4 | `y1` | PLOT/CIRCLE y coordinate (location marker) | | 5 | `y2` | PRINT AT row for capital label | | 6 | `x2` | PRINT 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