--- title: "Joystick" id: 71254 type: "computer_media" slug: "joystick-2" url: "http://localhost/computer_media/joystick-2/" markdown_url: "http://localhost/computer_media/joystick-2.md" published_at: "2026-08-30T17:34:10+00:00" modified_at: "2026-08-30T17:34:11+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "Guide a randomly colored symbol anywhere on screen using joystick directional values, with boundary checking and a second button to randomize the character itself." 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: "Joystick" slug: "joystick" taxonomy: "genre" url: "http://localhost/type/joystick/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/joystick%20%28198x%29%28-%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" media_type_tags: "Joystick" --- # Joystick This program moves a copyright symbol (©) around the screen using a joystick, reading STICK values to detect directional input. The cursor position is tracked in variables A (row) and B (column), with boundary clamping applied to keep within the 22-row by 32-column display area. Each iteration redraws the character with a randomly chosen INK color (0–6) via `INT(RND*7)`. A second joystick trigger (STICK 2) allows the displayed character to be changed to a random printable character in the range CHR$(91)–CHR$(143). *** ### Program Structure The program is a short main loop that reads joystick input and repositions a character on the screen. Initialization at lines 10–20 sets the row (`A`), column (`B`), and display character (`Z$`) to their starting values. Lines 30–80 form the core loop: print, then test each directional STICK value and update position accordingly. Line 90 handles a fire/button event on a second joystick port to randomize the character. Line 100 jumps back to line 30 unconditionally. ### STICK Value Decoding The `STICK(1,2)` call returns a bitmask representing the joystick directions. The values tested correspond to the following directional combinations: | STICK value | Meaning | | --- | --- | | 1 | Up | | 2 | Down | | 4 | Left | | 8 | Right | | 5 | Up + Left | | 6 | Down + Left | | 9 | Up + Right | | 10 | Down + Right | Each directional line (50–80) tests three STICK values: the cardinal direction and two diagonals that include that component. This correctly handles diagonal joystick movement by updating both axes independently across consecutive IF checks. ### Boundary Clamping After each position update, the new value is checked against the display limits: row `A` is clamped to 0–21 and column `B` to 0–31, matching the 22×32 character grid. When a boundary is hit, the value is reset to the limit and execution jumps directly to line 30 via `GO TO 30`, skipping the remaining directional checks for that frame. ### Display Technique Line 30 prints `Z$` at position (`A`,`B`) with a randomly selected INK color on every iteration. Because there is no `PRINT AT` to erase the previous position, the character trail remains on screen, progressively painting the display as the symbol moves. The `FLASH 0` at line 40 ensures flashing is suppressed each cycle, though it has no functional effect unless FLASH was previously set. ### Character Randomization Line 90 reads a second joystick port via `STICK(2,2)` and, when value 1 is detected, replaces `Z$` with a random character using `CHR$(INT(RND*53)+91)`. This generates characters in the range CHR$(91) to CHR$(143), which spans symbols, lowercase letters, and the lower block graphics characters. ### Notable Anomalies - Line 50 checks `STICK(1,2)=5` (Up+Left) for the Up handler, and line 60 also checks `STICK(1,2)=5` for the Left handler. When the joystick is at Up+Left (value 5), both A and B are decremented correctly because each IF is evaluated independently. - The display is never cleared between frames, so the moving character leaves a colored trail across the screen rather than appearing to move cleanly. - The initial value of `Z$` is set to the © character (the zmakebas `\*` escape), which is a block graphic rather than a printable ASCII symbol. ## Source Code ``` 10 LET A=0:LET B=A 20 LET Z$="\*" 30 PRINT AT A,B; INK INT (RND*7);Z$ 40 FLASH 0 50 IF STICK (1,2)=1 OR STICK (1,2)=5 OR STICK (1,2)=9 THEN LET A=A-1:IF A<0 THEN LET A=0:GO TO 30 60 IF STICK (1,2)=4 OR STICK (1,2)=6 OR STICK (1,2)=5 THEN LET B=B-1:IF B<0 THEN LET B=0:GO TO 30 70 IF STICK (1,2)=2 OR STICK (1,2)=10 OR STICK (1,2)=6 THEN LET A=A+1:IF A>21 THEN LET A=21:GO TO 30 80 IF STICK (1,2)=8 OR STICK (1,2)=10 OR STICK (1,2)=9 THEN LET B=B+1:IF B>31 THEN LET B=31:GO TO 30 90 IF STICK (2,2)=1 THEN LET Z$= CHR$ (INT (RND*53)+91) 100 GO TO 30 ```