--- title: "Setype" id: 55070 type: "computer_media" slug: "setype" url: "http://localhost/computer_media/setype/" markdown_url: "http://localhost/computer_media/setype.md" published_at: "2024-06-14T01:24:05+00:00" modified_at: "2026-03-30T21:45:18+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "This clever font utility installs 80 bytes of machine code to let any BASIC program switch between Regular, Bold, Modern, and Italic type styles with a single GOSUB call." 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/" indiv: - name: "Ron Ruegg" slug: "ron-ruegg" taxonomy: "indiv" url: "http://localhost/indiv/ron-ruegg/" genre: - name: "Font" slug: "font" taxonomy: "genre" url: "http://localhost/type/font/" media_contents: - id: 56277 title: "Timex Sinclair Public Domain Library Tape 2001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-2001/" media_type: "Program" programmers: - name: "Ron Ruegg" slug: "ron-ruegg" taxonomy: "indiv" url: "http://localhost/indiv/ron-ruegg/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Setype%20%28198x%29%28Ruegg%2C%20Ron%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" media_type_tags: "Font" --- SETYPE is a font-style utility that installs a small machine code routine enabling four different text rendering modes — Regular, Bold, Modern, and Italics — for BASIC programs. The machine code (80 bytes) is POKEd into high memory at address 255*256, and the system variable at 23607 (CHARS) is manipulated to switch between character rendering styles. Four BASIC line numbers (9323–9326) serve as callable subroutines, with GOSUB BLD, GOSUB MOD, GOSUB ITAL, and GOSUB REG switching type styles by calling RANDOMIZE USR into the installed routine and updating CHARS. The program uses CLEAR to protect the machine code area, sets torg=255 as the high-memory page, and stores subroutine entry-point line numbers in both lower- and upper-case variable names (reg/REG, bld/BLD, mod/MOD, ital/ITAL) for user convenience. *** ## Program Analysis ### Program Structure SETYPE is organized into two logical regions. Lines 9323–9326 are the callable style-switching subroutines intended to remain in any host program’s BASIC. Lines 9977–9999 are the installation and demonstration routine, which POKEs the machine code, shows a sample of each typeface, and optionally SAVEs the package to tape. | Lines | Purpose | | --- | --- | | 9323 | REG — restore regular character set (POKE 23607,60; RETURN) | | 9324 | BLD — set typ=2, configure machine code entry | | 9325 | MOD — set typ=1, configure machine code entry | | 9326 | ITAL — set typ=0, call RANDOMIZE USR to activate style, update CHARS | | 9977–9979 | REM credits block | | 9980 | Initialization: set system variables, assign subroutine line numbers to variables | | 9981–9983 | Machine code DATA and POKE loop | | 9984–9993 | Demo display using all four styles | | 9994–9999 | Keypress handling, optional COPY, optional SAVE | ### Machine Code Installation Line 9980 sets `torg=255` and uses `CLEAR (256*torg-769)` to protect memory from address 64,767 upward, reserving space at page 255 (address 65,280). The 80-byte routine is POKEd via the FOR/READ loop in line 9981 using `POKE (i+256*torg),k`. The DATA at line 9982 contains a token reference to `torg-3` (i.e., 252) rather than a literal constant, which is unusual — this means the DATA statement encodes an expression that is evaluated at READ time, dynamically computing the correct high-memory destination address without hardcoding it. ### Type Style Switching Mechanism The system variable at address 23607 is CHARS, which points (offset by −256) to the character set used for display. The REG subroutine (line 9323) restores CHARS to 60, pointing to the ROM character set. The other styles call into the installed machine code via `RANDOMIZE USR (torg*256+2-typ)`, where `typ` selects the entry point offset (0, 1, or 2) within the routine. After the USR call returns, line 9326 sets CHARS to `torg-4` (251), pointing to the newly modified character bitmap area in high memory. System variables at 23618–23620 are also written; these correspond to UDG-related pointers (UDG at 23675 is standard, but 23618–23620 in this range point to the printer buffer / STRMS area — their use here appears to pass parameters to the machine code rather than configure standard system behavior). ### Subroutine Line Number Variables Line 9980 assigns the four style-switching line numbers to both lower-case and upper-case variable names: `reg=9323`, `bld=9324`, `mod=9325`, `ital=9326`, and identically `REG=9323`, `BLD=9324`, `MOD=9325`, `ITAL=9326`. On the Spectrum/TS2068, variable names longer than one character are case-sensitive in storage but the UI documentation uses upper-case for clarity. This dual assignment ensures the subroutines are accessible regardless of which case convention a user’s program employs. ### Demo and User Interface Lines 9985–9992 demonstrate each style by calling the appropriate subroutine (via `GO SUB bld`, `GO SUB mod`, etc.) then PRINTing the style name. The BORDER, PAPER, and INK are set to produce a yellow-on-yellow scheme with INK 9 (transparent), giving a clean presentation. Line 9993 provides on-screen usage instructions. The keypress loop at line 9994 uses the standard busy-wait idiom `IF INKEY$="" THEN GO TO 9994`. Line 9995 checks specifically for “C” or “c” to trigger a `COPY` (screen print to ZX Printer). Line 9997 uses a `FLASH 1` prompt and a similar INKEY$ loop to ask about saving, and line 9998 SAVEs with `LINE 9980` so the program auto-runs from the initialization routine. ### Notable Techniques - Dynamic DATA value: `torg-3` inside the DATA statement is evaluated at READ time, avoiding a hardcoded address. - Entry-point selection via arithmetic: `torg*256+2-typ` allows three machine code entry points to be addressed with a single expression by varying `typ` (0, 1, or 2). - CHARS manipulation (address 23607) is the standard technique for custom or modified character sets without altering the ROM. - The installation routine is entirely self-contained in the high-numbered lines, designed to be merged into any existing BASIC program without line number conflicts. - `RESTORE 9982` in line 9984 resets the DATA pointer after the machine code has already been loaded, ensuring any subsequent READ operations in a host program are unaffected. ### Potential Anomalies The subroutine flow for BLD (line 9324) and MOD (line 9325) sets `typ` and POKEs 23618–23620, then falls through to the next line rather than RETURNing — execution continues sequentially into ITAL (line 9326) which performs the USR call and RETURN. This fall-through is intentional: BLD sets `typ=2`, MOD sets `typ=1`, and both rely on ITAL’s line to complete the action. REG (line 9323) is the only standalone subroutine that does not fall through. This design means `GO SUB bld` and `GO SUB mod` must be called with no intervening lines between 9324–9326 in the target program. ## Source Code ``` 8325 LET typ=1: POKE 23618,110: POKE 23619,36: POKE 23620,2 8999 STOP 9323 POKE 23607,60: RETURN 9324 LET typ=2: POKE 23618,110: POKE 23619,36: POKE 23620,2 9325 LET typ=1: POKE 23618,110: POKE 23619,36: POKE 23620,2 9326 LET typ=0: RANDOMIZE USR (torg*256+2-typ): POKE 23607,torg-4: RETURN 9977 REM SETYPE by RRRuegg 9978 REM Public domain program 9979 REM ********************* 9980 POKE 23562,1: LET torg=255: CLEAR (256*torg-769): LET torg=255: LET reg=9323: LET bld=9324: LET mod=9325: LET ital=9326: LET REG=9323: LET BLD=9324: LET MOD=9325: LET ITAL=9326 9981 FOR i=0 TO 79: READ k: POKE (i+256*torg),k: NEXT i 9982 DATA 0,0,121,203,39,203,39,50,21,255,33,0,61,17,0,torg-3 9983 DATA 1,0,3,126,24,48,203,63,24,44,230,112,24,37,121,230,7,203,39,50,40,255,126,24,30,24,28,24,16,24,14,24,14,24,20,24,18,24,2,203,63,203,63,24,10,203,39,203,39,24,4,183,203,39,182,18,35,19,11,120,177,32,196,201 9984 RESTORE 9982: BORDER 6: PAPER 6: INK 9: CLS : POKE 23607,60 9985 PRINT AT 0,1;"SETYPE offers you a choice of";TAB 8;"four type styles"''TAB 12;"Regular"'' 9986 GO SUB bld 9987 PRINT TAB 12;"Bold"'' 9988 GO SUB mod 9989 PRINT TAB 12;"Modern"'' 9990 GO SUB ital 9991 PRINT TAB 12;"Italics"'' 9992 GO SUB reg 9993 PRINT TAB 4;"To choose your type style";TAB 4;"after leaving this screen"'';TAB 6;"Press GOSUB REG";TAB 9;"or GOSUB BLD";TAB 9;"or GOSUB MOD";TAB 9;"or GOSUB ITAL"''TAB 2;"Press C to copy this screen"''TAB 2;"Press any other key to exit" 9994 IF INKEY$="" THEN GO TO 9994 9995 IF INKEY$="C" OR INKEY$="c" THEN COPY 9996 CLS : PAUSE 30 9997 PRINT AT 0,0;"SAVE TO TAPE"; FLASH 1;"?": IF INKEY$="" THEN GO TO 9997 9998 IF INKEY$="y" OR INKEY$="Y" THEN SAVE "SETYPE" LINE 9980 9999 CLS ```