Setting and Resetting Caps Lock

Author(s): David Solly
Publication: ZXir QLive Alive!
Pub Details: ZXir QLive Alive! v11 n1 (Volume 11, Issue 1)
Date: Spring 2001
Pages: 8

It is sometimes useful to be able to switch the ZX Spectrum keyboard’s cap mode on and off so as to control the keys for which a program is testing. Caps mode is controlled by the system variable FLAGS2 at location 23658 (#5C6A). The instruction POKE 23658,8 sets caps mode but also resets all the other flags in that register.

There is a ROM routine which can be called using RANDOMIZE USR 4317 but if caps mode is already set, this call will reset it.

The solution is a short machine code routine that can be loaded anywhere in memory. It consists of just three instructions:

LD HL,23658
SET E,(HL)
RET

A suitable program to set up this routine would look like this:

1000 LET start = any suitable address
1010 FOR a = start TO start+5
1020 READ b: POKE a,b
1030 NEXT a
1040 DATA 33,106,92,203,222,201

Caps mode can then be set by RANDOMIZE USR (start). To force the Spectrum into lower case mode change 222 to 158 in the data in line 1040.

This machine code routine renders itself nicely into the HiSoft Pascal procedure listed below. If the value passed to the Boolean variable ON is TRUE then the caps lock is switched on. If the value passed is FALSE then the caps lock is switched off.

PROCEDURE CAPSLOCK(ON : BOOLEAN);

{
This procedure will set the ZX Spectrum
and the T/S 2068 caps lock on when ON
is TRUE and off when ON is FALSE.
}
BEGIN

IF ON = TRUE THEN
INLINE(#21, #6A, #5C, {LD HL, 5C6A}
#CB, #DE); {SET 3, (HL)}

IF ON = FALSE THEN
INLINE(#21, #6A, #5C, {LD HL, 5C6A}
#CB, #9E); {RES 3, (HL)}

END;

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