--- title: "Flag" id: 57251 type: "computer_media" slug: "flag" url: "http://localhost/computer_media/flag/" markdown_url: "http://localhost/computer_media/flag.md" published_at: "2024-10-04T07:18:55+00:00" modified_at: "2026-03-30T21:18:59+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/141_Flag.png" excerpt: "A three-phase flag-drawing routine combines striped block graphics, a solid canton overlay, and UNPLOT pixel clearing to render a decorative national-flag pattern." 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 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" - name: "Holiday" slug: "holiday" taxonomy: "genre" url: "http://localhost/type/holiday/" media_contents: - id: 56734 title: "Timex Sinclair Public Domain Library Tape 1003" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1003/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/141_Flag.png" media_type_tags: "Demo, Holiday" --- This program draws a stylized flag graphic on screen using PRINT AT positioning and block graphics characters. It works in three phases: first rendering alternating striped rows across columns 1–26 (rows 5–16), then overlaying a solid region in the upper-left canton (rows 6–10, columns 1–13), and finally using UNPLOT to punch circular or dot patterns into the flag in a grid arrangement. The program uses the ZX81’s UNPLOT command to clear individual pixels, creating a decorative pattern over the stripes. A SAVE command at line 300 stores the program before RUN at line 310 re-executes it. *** ## Program Analysis ### Program Structure The program is divided into four logical sections separated by line-number gaps: 1. **Lines 5–70:** Draw the main body of the flag — a horizontal stripe at row 5 and alternating filled/blank rows from 6 to 16 across all 26 columns. 2. **Lines 100–140:** Overlay the canton (upper-left rectangle, rows 6–10, columns 1–13) with solid block characters, overwriting the stripe pattern. 3. **Lines 200–270:** Use `UNPLOT` in nested loops to clear individual pixels, creating a decorative dot or star-like pattern across the flag. 4. **Lines 280–310:**`STOP` halts execution; `SAVE` and `RUN` follow but are not reached in normal flow. ### Flag Rendering — Phase 1 (Lines 10–70) The outer loop `FOR I=1 TO 26` iterates over columns. At each column, line 20 prints a space character (`"% "` — inverse space, i.e. a filled block) at row 5. The inner loop `FOR J=6 TO 16 STEP 2` then prints a block graphic `"\##"` (a solid 2×2 block character) at even rows and an inverse space at odd rows (`J+1`), producing a horizontal stripe effect down the flag body. ### Canton Overlay — Phase 2 (Lines 100–140) A second nested loop fills rows 6, 8, and 10 (STEP 2) in columns 1–13 with inverse spaces, creating a solid rectangular canton in the top-left quadrant. This overwrites the stripe pattern laid down in phase 1 for that region. ### UNPLOT Decoration — Phase 3 (Lines 200–270) The outer loop `FOR J=23 TO 31 STEP 2` and inner loop `FOR I=5 TO 21 STEP 4` address pixel coordinates (note ZX81 pixel addressing). `UNPLOT` clears individual pixels to create a spaced dot grid. Line 230 conditionally skips line 240 when `J=23`; line 240 contains a likely bug: `UNPLOT I=2,J-1` — the expression `I=2` evaluates as a boolean (0 or 1 in ZX81 BASIC) rather than `I-2` as presumably intended. This means the second UNPLOT always plots at pixel column 0 or 1 rather than offset from `I`. Line 260 adds an additional UNPLOT at a fixed column 25 for each `J` value. ### Notable Techniques - **Inverse space as filled block:**`"% "` (inverse space character) is used as a solid fill — a common ZX81 idiom for drawing filled rectangles without block graphics. - **Block graphic character:**`"\##"` represents a fully-filled 2×2 block graphic, used for the stripe rows. - **STEP 2 loops:** Both the stripe loop (`J=6 TO 16 STEP 2`) and the UNPLOT loop (`J=23 TO 31 STEP 2`) use STEP 2 to address alternating rows/pixels, a space-efficient way to produce patterns. - **Conditional branching within inner loop:**`IF J=23 THEN GOTO 250` skips the second UNPLOT on the first pass of the outer loop only. ### Bugs and Anomalies | Line | Issue | Effect | | --- | --- | --- | | `240` | `UNPLOT I=2,J-1` — `I=2` is a boolean expression | Always UNPLOTs at x-coordinate 0 (false) or 1 (true when I=2), not at `I-2` as likely intended | The `STOP` at line 280 means lines 300 (`SAVE`) and 310 (`RUN`) are never executed during normal program flow and appear to be remnants or setup lines. ## Source Code ``` 5 REM FLAG 10 FOR I=1 TO 26 20 PRINT AT 5,I;"% " 30 FOR J=6 TO 16 STEP 2 40 PRINT AT J,I;"\##" 50 PRINT AT J+1,I;"% " 60 NEXT J 70 NEXT I 100 FOR I=1 TO 13 110 FOR J=6 TO 10 STEP 2 120 PRINT AT J,I;"% " 130 NEXT J 140 NEXT I 200 FOR J=23 TO 31 STEP 2 210 FOR I=5 TO 21 STEP 4 220 UNPLOT I,J 230 IF J=23 THEN GOTO 250 240 UNPLOT I=2,J-1 250 NEXT I 260 UNPLOT 25,J 270 NEXT J 280 STOP 300 SAVE "1014%1" 310 RUN ```