--- title: "Screen Machine" id: 56710 type: "computer_media" slug: "screen-machine" url: "http://localhost/computer_media/screen-machine/" markdown_url: "http://localhost/computer_media/screen-machine.md" published_at: "2024-09-22T23:31:48+00:00" modified_at: "2026-03-30T21:21:33+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/09/Screen-Machine.jpg" excerpt: "Machine language sub-routine that allows inputs anywhere on screen, complete error checking, automatic formatting (dates, decimals), and advance directly to next prompt." 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: "SyncMaster" slug: "syncmaster" taxonomy: "post_tag" url: "http://localhost/tag/syncmaster/" - 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: "Programming" slug: "programming" taxonomy: "genre" url: "http://localhost/type/programming/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Screen%20Machine%20%281983%29%28SyncMaster%29%28TS1000%29%28US%29%28Cassette%29.zip" mediadate: "1983" producer_company: - id: 11369 title: "SyncMaster" type: "company" url: "http://localhost/company/syncmaster/" images: - url: "http://localhost/wp-content/uploads/2024/09/Screen-Machine.jpg" related_products: - id: 13872 title: "Screen Machine" type: "product" url: "http://localhost/product/screen-machine/" media_type_tags: "Programming" --- Machine language sub-routine that allows inputs anywhere on screen, complete error checking, automatic formatting (dates, decimals), and advance directly to next prompt. *** ## Program Analysis This program implements a data entry routine, using an embedded machine code routine stored in a REM statement at line 1. The machine code begins at address 16384 (0x4000) and is invoked via RAND USR 16729, handling screen and keyboard input operations. The BASIC shell (lines 10–25) acts as a wrapper, using PEEK and POKE at addresses 16514–16520 to pass parameters to and from the machine code, including a string P$ for control parameters and Q$ for data. The routine includes logic for a “V” mode (line 21) that skips writing results back to Q$, suggesting a verify or view-only pass. ### Program Structure The program is organized into two distinct layers. The BASIC shell occupies lines 1–100, while the heavy lifting is performed by Z80 machine code embedded in the `REM` statement at line 1. Line 9 uses the `GO TO VAL "100"` idiom to jump past the data and REM metadata to the actual program entry point. Lines 10–29 form a subroutine (returned from at line 29) that acts as the interface between BASIC and the machine code. ### REM-Embedded Machine Code Line 1’s `REM` statement contains several hundred bytes of Z80 machine code. Because the Spectrum/TS2068 BASIC system stores the REM text starting at a known offset into the program area, the machine code lands at a predictable address in RAM. The entry point is called via `RAND USR 16729` at line 20, placing the start of executable code at address 16729 (0x4179) within the block. Line 2 contains a short secondary `REM`, likely acting as padding or a data table. ### Parameter Passing Convention The BASIC wrapper communicates with the machine code through a set of fixed memory locations POKEd before the `RAND USR` call: - `POKE 16514, CODE P$(1)` — passes the first character of the control string as a command byte. - `POKE 16515, VAL P$(2)` — passes a numeric sub-parameter. - Lines 14–16 (`FOR Q=2 TO 5`) pack additional two-character numeric fields from `P$` into addresses 16516–16519. - Lines 17–19 copy up to `PEEK 16519` characters from `Q$` (offset by `PEEK 16518`) into addresses starting at 16521, providing the data buffer. After the machine code returns, lines 22–24 read the (possibly modified) buffer back into `Q$`, closing the round-trip data exchange. ### Notable BASIC Techniques - **VAL for line numbers:**`GO TO VAL "100"` at line 9 is a memory-saving technique; storing the target as a string constant avoids the five-byte floating-point number representation. - **Conditional skip on “V” mode:** Line 21 checks `P$(1)="V"` and jumps to line 25, bypassing the write-back loop (lines 22–24). This implements a view/verify mode where the buffer is not flushed back to `Q$`. - **Null-guard on P$(2):** Line 12 replaces a space in `P$(2)` with `"0"` before calling `VAL`, preventing a runtime error on an empty field. - **PEEK 16520 result read-back:** Line 25 (`LET Q=PEEK 16520`) retrieves a return value left by the machine code in the data buffer area. ### Machine Code Overview The Z80 code is extensive (over 400 bytes). Key patterns visible in the hex dump include: - Frequent use of `ED 42` / `ED 52` (`SBC HL,BC` / `SBC HL,DE`) for 16-bit arithmetic, suggesting cursor position or string length calculations. - `CD BB 02` — repeated calls to address 0x02BB, which is the TS2068/Spectrum ROM routine for scanning the keyboard. - `CD 2B 0F` — calls to 0x0F2B, the ROM’s “wait for keypress” or display routine. - `EF` bytes — `RST 0x28`, the floating-point calculator, used for numeric display formatting. - A jump table near the start of the code (based on the series of `FE xx 28 yy` sequences) dispatches on the command byte stored at 0x4082, handling command codes including `0x0A`, `0x08`, `0x06`, `0x33`, `0x38`, `0x29`, `0x28`, and `0x3B`. ### Address Map | Address | Role | | --- | --- | | `0x4000` (16384) | Start of REM machine code block | | `0x4082` (16514) | Command byte (from `P$(1)`) | | `0x4083` (16515) | Sub-parameter 1 | | `0x4084–0x4087` | Additional parameters from `P$(4..10)` | | `0x4088` (16520) | Data buffer start / return value | | `0x4179` (16729) | Machine code entry point (`RAND USR` target) | ### Metadata and Provenance REM statements at lines 91–96 identify the routine as *SCREEN / 2D.02 / 3140*, copyright 1983 by Management Services Co. This version/build numbering suggests the machine code was part of a larger commercial library of data entry utilities distributed as BASIC programs with embedded Z80 routines. ## Source Code ``` 1 REM \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\1B\42\64\43\B9\42\B9\42\B9\42\D3\42\E8\42\03\43\B9\42\46\45\A7\45\46\45\A7\45\1D\46\28\46\46\45\00\88\80\B2\B2\A9\A9\BE\BE\28\34\37\37\2A\28\39\0F\00\10\33\1A\3E\1A\33\1A\29\11\0E\18\0D\1B\1C\00\16\1C\1D\CF\18\E5\21\82\40\7E\16\00\5F\E1\19\5E\23\56\EB\E9\3A\AF\40\CB\8F\CB\97\CB\9F\32\AF\40\C9\06\02\11\AB\40\D5\E5\EB\5E\23\56\E1\7E\4F\EB\7E\FE\76\3A\AF\40\20\0F\CB\47\20\05\CB\C7\23\18\03\CB\87\2B\32\AF\40\71\CB\4F\20\03\23\18\01\2B\EB\CB\57\20\08\CB\5F\20\03\23\18\01\2B\10\CE\C1\E5\60\69\73\23\72\E1\C9\21\82\40\06\00\3A\82\40\FE\38\28\22\FE\33\28\1B\00\00\28\16\FE\29\28\11\FE\28\28\0C\FE\3B\28\07\00\00\00\00\18\08\04\04\04\04\04\04\CB\00\70\78\FE\0A\20\1A\06\03\21\85\40\3A\83\40\FE\03\30\04\0E\17\18\02\0E\18\71\0E\01\23\10\FA\18\10\FE\06\20\0C\3A\87\40\FE\04\28\05\FE\06\C2\F4\40\21\5A\00\22\23\40\22\0A\40\3A\87\40\FE\21\D2\F4\40\FE\01\DA\F4\40\3A\84\40\FE\17\D2\F4\40\CD\1D\15\3E\21\CD\1D\15\EF\04\34\CD\A7\0E\03\3A\85\40\FE\20\D2\F4\40\6F\26\00\09\E5\3A\87\40\4F\06\00\09\01\F8\02\A7\ED\42\E1\D2\F4\40\ED\4B\0C\40\09\22\A9\40\22\AB\40\3A\3B\40\CB\7F\3E\80\20\02\3E\00\32\AF\40\3A\82\40\FE\0A\28\11\3A\87\40\47\C5\21\89\40\7E\FE\01\30\0F\23\10\F8\C1\CD\05\41\21\B4\40\CD\F6\40\18\28\CD\05\41\CB\E7\32\AF\40\21\89\40\3A\82\40\FE\08\28\22\C1\CD\14\41\CB\6F\C0\3A\83\40\D6\01\D8\2A\A9\40\7E\D6\80\77\18\06\3A\83\40\D6\01\D8\21\B2\40\C3\00\41\E5\7E\6F\26\00\E5\CD\1D\15\3E\0A\CD\1D\15\EF\05\24\34\CD\A7\0E\21\1C\00\09\7D\32\F2\40\CD\20\15\3E\0A\CD\1D\15\EF\04\34\CD\A7\0E\E1\A7\ED\42\01\1C\00\09\7D\32\F3\40\21\F2\40\CD\12\41\E1\C1\05\28\A3\C5\23\E5\18\BA\06\01\21\D1\40\CD\14\41\3A\87\40\3D\C8\47\3A\AF\40\CB\D7\32\AF\40\CD\14\41\C9\78\FE\04\21\D3\40\20\09\CD\12\41\23\23\CD\12\41\C9\CD\14\41\C9\21\D1\40\CD\12\41\3A\87\40\3D\C8\47\CB\00\3A\AF\40\CB\D7\32\AF\40\2B\CD\14\41\C9\21\D9\40\E5\2A\AB\40\06\00\0E\0F\A7\ED\42\3A\83\40\FE\03\38\02\2B\2B\22\AB\40\E1\FE\03\30\20\FE\01\20\13\06\0A\CD\14\41\06\03\23\23\CD\14\41\23\23\CD\12\41\18\22\06\0D\CD\14\41\23\23\18\F0\FE\03\20\09\06\0A\CD\14\41\06\07\18\07\06\0D\CD\14\41\06\04\23\23\CD\14\41\21\D1\40\06\01\CD\14\41\C9\3A\AF\40\CB\87\32\AF\40\2A\AB\40\22\AD\40\2A\A9\40\22\AB\40\CD\2B\0F\CD\BB\02\2C\20\FA\CD\BB\02\44\4D\51\14\28\F7\CD\BD\07\7E\CB\77\32\D0\40\20\50\CD\05\41\CB\67\28\1D\CB\A7\32\AF\40\3A\87\40\47\21\B4\40\CD\F6\40\2A\A9\40\22\AB\40\CD\05\41\CB\87\32\AF\40\CB\6F\28\07\3A\D0\40\D6\80\18\03\3A\D0\40\21\D0\40\77\CD\12\41\1B\ED\53\AB\40\2A\AD\40\EB\A7\ED\52\38\9F\3E\7A\32\D0\40\18\02\18\96\FE\77\20\23\ED\5B\A9\40\2A\AB\40\A7\ED\52\28\EE\CD\05\41\CB\CF\CB\DF\32\AF\40\21\D2\40\CD\12\41\13\ED\53\AB\40\18\2E\FE\74\20\60\3A\82\40\FE\01\30\CC\3A\AF\40\CB\6F\28\09\CB\AF\32\AF\40\3E\88\18\07\CB\EF\32\AF\40\3E\8A\32\D1\40\ED\5B\AB\40\12\18\02\18\A9\2A\A9\40\A7\ED\52\38\F6\3A\D0\40\FE\74\21\B0\40\3A\AF\40\28\0D\CB\AF\32\AF\40\3E\88\32\D1\40\C3\00\41\CB\6F\CA\00\41\21\B4\40\CD\05\41\CD\F6\40\21\B2\40\C3\00\41\FE\E3\20\17\CD\BB\02\2C\20\FA\3A\AF\40\CB\7F\20\03\CD\23\0F\3E\88\32\D1\40\CF\0C\06\00\FE\7A\28\18\FE\76\28\14\FE\73\28\0F\FE\70\28\0A\FE\71\28\05\FE\72\20\93\04\04\04\04\78\32\88\40\CD\23\0F\2A\AB\40\3A\AF\40\CB\67\28\13\7E\D6\80\77\3A\AF\40\CB\6F\28\12\21\B0\40\CD\00\41\18\0A\3E\00\77\EB\21\C2\40\CD\F6\40\CD\2B\0F\CD\BB\02\2C\20\FA\3A\AF\40\CB\7F\20\03\CD\23\0F\3E\88\32\D1\40\3A\82\40\FE\0A\C8\FE\08\3A\87\40\47\CD\05\41\21\89\40\22\AB\40\2A\A9\40\28\04\CD\14\41\C9\C5\11\89\40\D5\11\F2\40\ED\53\AB\40\CD\12\41\E5\3A\F2\40\D6\1C\CD\1D\15\3E\0A\CD\1D\15\EF\04\34\CD\A7\0E\3A\F3\40\D6\1C\6F\26\00\09\7D\D1\E1\C1\77\05\C8\23\C5\E5\EB\18\CC\11\F0\40\3A\82\40\FE\08\20\01\1B\ED\4B\AB\40\2A\AD\40\A7\ED\42\C8\D8\3A\83\40\FE\02\CD\05\41\28\0B\CB\D7\32\AF\40\45\EB\CD\14\41\C9\3A\82\40\FE\08\3A\87\40\20\03\A7\CB\07\45\90\47\3A\AF\40\28\E0\CB\CF\CB\DF\D5\E5\32\AF\40\2A\AB\40\2B\ED\5B\AD\40\1B\ED\53\AB\40\CD\14\41\E1\D1\3A\AF\40\18\C0\ED\5B\A9\40\2A\AB\40\A7\ED\52\28\02\30\12\3E\1C\ED\5B\A9\40\12\13\ED\53\AB\40\21\C2\40\C3\00\41\45\0E\04\3A\82\40\FE\02\28\02\CB\C1\1A\FE\1C\30\25\CB\41\20\14\FE\01\38\2D\FE\16\28\29\FE\1B\20\08\CB\49\20\04\CB\C9\18\1D\E1\2A\A9\40\22\AB\40\21\B0\40\C3\00\41\FE\76\28\0C\FE\26\30\EB\3A\AF\40\CB\91\32\AF\40\13\10\C3\3A\AF\40\CB\51\20\9E\21\C2\40\C3\00\41\3E\02\32\83\40\21\C4\40\C3\00\41\06\07\2A\A9\40\7E\FE\33\28\0A\FE\3E\28\05\FE\29\20\06\04\04\78\32\88\40\CD\05\41\CB\D7\32\AF\40\06\00\0E\11\A7\ED\42\22\AB\40\06\12\21\F0\40\CD\14\41\C9\24\25\21 2 REM 9 GOTO VAL "100" 10 REM ** SCREEN ** 11 POKE 16514,CODE P$(1) 12 IF P$(2)=" " THEN LET P$(2)="0" 13 POKE 16515,VAL P$(2) 14 FOR Q=2 TO 5 15 POKE 16514+Q,VAL P$(2*Q-1 TO 2*Q) 16 NEXT Q 17 FOR Q=1 TO PEEK 16519 18 POKE 16520+Q,CODE Q$(Q+PEEK 16518-1) 19 NEXT Q 20 RAND USR 16729 21 IF P$(1)="V" THEN GOTO VAL "25" 22 FOR Q=1 TO PEEK 16519 23 LET Q$(Q+PEEK 16518-1)=CHR$ PEEK (Q+16520) 24 NEXT Q 25 LET Q=PEEK 16520 29 RETURN 90 REM DATA ENTRY ROUTINE 91 REM SCREEN / 2D.02 / 3140 95 REM COPYRIGHT (C) 1983 BY: 96 REM MANAGEMENT SERVICES CO. 100 REM ** START PROGRAM HERE ```