--- title: "Anatomy" id: 53826 type: "computer_media" slug: "anatomy" url: "http://localhost/computer_media/anatomy/" markdown_url: "http://localhost/computer_media/anatomy.md" published_at: "2024-05-13T19:02:00+00:00" modified_at: "2026-03-30T21:40:57+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "Peek inside a BASIC program's raw byte structure — every address, decimal value, and printable character laid out line by line." 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: "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: "Programming" slug: "programming" taxonomy: "genre" url: "http://localhost/type/programming/" media_contents: - id: 55361 title: "SINCUS Exchange Tape 102 – Utilities & Business" type: "computer_media" url: "http://localhost/computer_media/sincus-exchange-tape-102-utilities-business/" media_type: "Program" mediadate: "198" images: - url: "http://localhost/wp-content/uploads/2024/05/anatomy.png" article_media: - id: 24149 title: "The Anatomy of a Program Line" type: "article" url: "http://localhost/article/the-anatomy-of-a-program-line/" media_type_tags: "Programming" --- This program dumps the contents of a TS2068 BASIC program area to the screen, printing each byte’s address, decimal value, and — where the byte represents a printable character (value greater than 31) — its character representation. It iterates from the start of the BASIC program area, whose address is held in system variables at addresses 23635–23636 (PROG), up to the end, whose address is stored at 23627–23628 (VARS, marking the boundary). The loop uses PEEK on the system variables to calculate the 16-bit start and end addresses via the standard low-byte + 256 × high-byte formula. The technique gives hobbyists a way to inspect the raw token and data bytes that make up a BASIC program file, including keyword tokens and line-length fields. *** ## Program Analysis ### Program Structure The program is a straightforward five-line memory dumper. A `FOR`/`NEXT` loop at lines `20`–`50` walks through every byte of the resident BASIC program area, and line `30` prints the diagnostic information for each byte. Lines `10` and `100` are `REM` statements providing a title and a source attribution (SYNC magazine, March 1984). ### System Variable Usage The loop bounds are derived entirely from system variables using `PEEK`: - `PEEK 23635 + 256*PEEK 23636` — reconstructs the 16-bit value of **PROG**, the address of the first byte of the BASIC program in memory. - `PEEK 23627 + 256*PEEK 23628` — reconstructs the 16-bit value of **VARS**, the address of the variables area, which immediately follows the program area and therefore serves as the exclusive upper bound. Both addresses are stored in RAM in the conventional little-endian format (low byte first, high byte second), so the formula `low + 256 * high` is the standard idiom for reading a two-byte system variable. ### Output Format For each byte address `x`, line `30` prints three fields separated by spaces: 1. The decimal address (`x`). 2. The decimal byte value (`PEEK x`). 3. The corresponding character (`CHR$ PEEK x`), but only if `PEEK x > 31` — i.e., the byte is in the printable/token range and not a control code. The trailing comma after the first two `PRINT` items on line `30` suppresses a newline, keeping all three fields on the same row. Line `40` then emits a bare `PRINT` to advance to the next line before the loop increments. ### Key BASIC Idioms - **16-bit address reconstruction:**`PEEK lo + 256 * PEEK hi` is the canonical way to read a two-byte pointer from system variables in BASIC. - **Conditional inline print:** The `IF PEEK x > 31 THEN PRINT CHR$ PEEK x;` on the same line as the unconditional print items is a space-saving single-line conditional common in short utility programs. - **Semicolon vs. comma:** Semicolons are used throughout to suppress spacing between printed items, giving compact columnar output. ### Notable Techniques and Observations Because BASIC keyword tokens are single bytes with values above 127, many of them will pass the `> 31` test and attempt to display via `CHR$`. On screen this will render the keyword glyph (or a graphics character) rather than the token’s ASCII mnemonic — which is technically correct behavior but means the character column is more useful for identifying embedded string literals and variable names than for reading keyword tokens. The decimal value column remains unambiguous for all bytes. The loop visits the program’s own bytes as it runs, meaning the dump includes this very program’s tokens — a self-referential property that makes it a useful illustration of how BASIC source is stored as tokenized bytes rather than plain ASCII text. ### Potential Anomalies The upper bound uses **VARS** as the loop’s `TO` value, but `FOR x = start TO end` is inclusive on both ends. The byte at address `VARS` is actually the first byte of the variables area, not the last byte of the program. This means the dump includes one extra byte beyond the true end of the program. In practice this is a minor off-by-one that typically reveals the `0x80` sentinel byte that marks the start of the variables area, so it is informative rather than harmful. ## Source Code ``` 10 REM 2068 anatomy 20 FOR x=PEEK 23635+256*PEEK 23636 TO PEEK 23627+256*PEEK 23628 30 PRINT x;" ";PEEK x,: IF PEEK x>31 THEN PRINT CHR$ PEEK x; 40 PRINT 50 NEXT x 100 REM Program File - See SYNC March 84 ```