MACRO

Developer(s): Michael DiRienzo
Date: 1990
Type: Program
Platform(s): TS 2068

MACRO turns any alphanumeric key into a user-defined function key. The functions live in REM statements at the start of the BASIC program: REM, the key, a colon, then the BASIC to be typed. When that key is pressed the text after the colon appears on the edit line; if it ends in #, ENTER is simulated as well and the line runs straight away. A REM with * after it is an ordinary comment. RANDOMIZE USR 64381 turns the keys on and RANDOMIZE USR 64399 turns them off.

The demo assigns three keys: ! prints a flashing message, @ asks for a number and shows its low and high bytes, and the CAT key catalogues a Larken disk. Michael J. DiRienzo adapted the routine from a Spectrum utility in an old SINC TIMES newsletter for the Mike’s Notebook column of May 1990.

Program Analysis

Structure

  • Lines 1–3: the three demo function definitions.
  • Lines 10–20: the prompt.
  • Lines 9900–9960: loader. CLEAR 64249, POKE 156 bytes into 64250–64405, check that they total 19476, switch the keys on and RUN.

Machine code

Switching on fills a 257-byte vector table at 65024 and puts the Z80 into interrupt mode 2 with I=254; switching off sets I back to 62 and returns to IM 1. On each interrupt the handler appears to check whether a key has just been pressed, scan the program from PROG for a REM whose first character matches LAST_K followed by a colon, and copy the rest of that line into the edit line through the ROM, simulating ENTER if the copied text ends in #.

Notable Techniques

  • Interrupt mode 2 lets the routine run on every frame without changing the ROM keyboard handling.
  • Function text is stored as tokenized BASIC inside REM lines, so it is edited like any other program line.
  • A checksum in line 9920 catches typing errors in the DATA.

Potential Issues

  • The CAT demo in line 3 runs RANDOMIZE USR 100: CAT "",, a Larken disk command; on a TS2068 without the Larken system, don’t press CAT.
  • The code is not relocatable; the column notes that it can be moved anywhere above 32767 only by someone who understands IM 2.

Typed in from the Mike’s Notebook column on RMG Enterprises’ monthly RMG UPDATES disk for May 1990, where the program exists only as a listing in the column’s text. The DATA total matches the checksum in line 9920. It was tokenized for tape and tested in ZEsarUX.

Related Articles

Did you ever do a lot of repetitive keying or wish you had programmable function keys?
Did you ever do a lot of repetitive keying or wish you had programmable function keys?
Did you ever do a lot of repetitive keying or wish you had programmable function keys?

Related Content

Image Gallery

Source Code

    1 REM !: PRINT INK 2; FLASH 1;AT 10,5;"This is a DEMO...": BEEP .1,.1: PRINT : PRINT "Hit '@' For Another DEMO"#
    2 REM @: INPUT "Input Number (0 TO 65535) ";N: RANDOMIZE N: PRINT "Lo Byte=";PEEK 23670,"Hi byte=";PEEK 23671#
    3 REM CAT : RANDOMIZE USR 100: CAT "",
   10 PRINT "Press '!' or '@' or ' CAT ' For DEMO"
   20 STOP 
 9900 CLEAR 64249: LET on=64381: LET off=64399: LET c=0
 9910 FOR n=64250 TO 64405: READ a: POKE n,a: LET c=c+a
 9920 NEXT n: IF c<>19476 THEN PRINT "DATA error!": STOP 
 9930 RANDOMIZE USR on: RUN 
 9940 DATA 255,243,229,213,197,245,205,9,251,241,193,209,225,251,201,253,203,1,110,200,33,0,0,57,235,237,123,61,92,225,1,229,11,167,237,66,235,249,192,42,83,92,24,2,235,9,35,35,78,35
 9950 DATA 70,35,84,93,126,254,234,192,35,58,8,92,190,32,235,35,126,254,58,32,229,35,126,254,13,40,223,11,11,11,11,197,229,42,91,92,205,187,18,19,237,83,91,92,35,235,225
 9960 DATA 193,237,176,235,43,126,254,35,40,8,205,131,12,253,203,1,174,201,1,1,0,205,80,23,62,13,50,8,92,253,203,1,238,201,33,0,254,1,250,0,113,35,16,252,113,62,254,237,71,237,94,201,62,62,237,71,237,86,201

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.