Skip to content

Obscure commands, part 5

1 message · 2002-12-09 → 2002-12-09 · Yahoo Group era · View archive on archive.org

Participants: ekrampitzjr

Preserved from the Timex/Sinclair 2068 Yahoo Group (2001–2019), which is no longer online. Text reproduced from the archive.org archive; email addresses masked.

Messages

1. Obscure commands, part 5

ekrampitzjr · Mon, 09 Dec 2002 17:41

5.  IN #n  [n = 0-65535]

IN scans an input device and returns a value based on the output.  
OUT is related but is covered in the manual.  n takes the form 256
(BIN bbbbbbbb) + y, where b is a binary number from 00000000 to 
11111111 (0-255).  y is the port number of the device being read; for 
the keyboard y = 254.

The keyboard is scanned by half-rows.  Each half-row has 5 keys.  The 
base value for each scan when reading the keyboard is 31, but some 
Spectrum ROMs use 255 instead.  The keys in each half-row have the 
values 1, 2, 4, 8, and 16 as you move from the outside toward the 
center.  Each key pressed in a row subtracts its value from this base 
value of 31.  If all five keys in a half-row are pressed, the value 
returned is 0: 31 - 16 - 8 - 4 - 2 - 1.  This chart sums it up:

BIN #     Value   Keys of values       Half-
for n     of n     1:  2:  4:  8: 16   row #
--------------------------------------------
11111110  65278   cs:  Z:  X:  C:  V    1
11111101  65022    A:  S:  D:  F:  G    2
11111011  64510    Q:  W:  E:  R:  T    3
11110111  63486    1:  2:  3:  4:  5    4
11101111  61438    0:  9:  8:  7:  6    5
11011111  57342    P:  O:  I:  U:  Y    6
10111111  49150   en:  L:  K:  J:  H    7
01111111  32766   br: ss:  M:  N:  B    8

cs = caps shift; en = enter; br = break; ss = symbol shift
Both cs keys are considered to be in the same half-row.

Here is an example of use:
5>FOR g=1 TO 100:PRINT IN 65022;" ";:PAUSE 20:NEXT g
Press various keys in half-row 2, ASDFG, as this runs.  None pressed 
will give 31 every third of a second (note PAUSE line).  Pressing A 
gives 30, etc.; pressing all five keys gives 0.

IN must be used within a statement and cannot stand alone.  IN n by 
itself gives the ? cursor.

Indexed under

BASIC programming