How to Re-map the Keyboard/Read the Keyboard Hardware

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

How to Re-map the Keyboard/Read the Keyboard Hardware

Post by David G »

This article come from September 1982 magazine "ORDI-5". Thanks to original author Igor Bourdain and to XavSnap for the scans on abandonlistings.free.fr

That program "Changer la signification des touches de votre clavier" (Change the meaning of keys on your keyboard) interactively shows the keyboard state .Changer la signification des
touches de votre clavier
( click "Telecharger" to download)

The actual remapping (to enable a non-QWERTY keyboard, perhaps a Dvorak or French layout) is an excercise left to the reader. The article instead explains how to keyboard hardware interacts with the software

The original French text first, followed by English translation
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by David G »

30 -- ORDI-5 N 1° -- Septembre 82
=================================

technique -----------------------
Changer la signification des touches de votre clavier
Ordi-5 1-1982 - FR V2_page_030_ZX81.jpg
Comment le ZX sait-il que telle ou telle touch a été pressée par l'utilisateur ? C'est une routine spécialisée du programme moniteur du système qui se charge de l'interprétation du clavier. Elle commence à l'adresse 02BB (dec.699). C'est uner routine particuliérement intéressante ; correctement récupéree par l'utilisateur, elle permet á celui-ci modifier dans le sens qu'il souhaite la signification de toutes les touches du clavier ZX81. Nous donnerons une illustration de ces possibilités de déteournment avec un pettit programme purement démenstratif de jeu de fléchettes, mais les application peuvent être beaucoup plus vastes : quand un lecteur judicieux nous présentera-t-il un programme basé sur cette méthode por transformer le clavier QWERTY en clavier AZERTY ?

LA ROUTINE DE DECODAGE DU CLAVIER
---------------------------------
Chaque touche du clavier a une position unique en hateur et en largeur ; elle appartient à une certaine ligne et à une certaine colonne. Si l'on associe au numéro de colonne le registre double HL du microprocessor Z80, il est facile par ce moyen de faire correspondre à chaque touche un nombre unique dans HL résultant d'une combinaison unique colonne/H, ligne/L.

Plutôt qu'en ligne et colonne, pour des raison simples (ne pas dépasser le chiffre 8 pour la valeur de l'indice), le clavier du ZX est divisé en zones de répartition calquées sur les lignes et colonnes selon le découpage représenté ci-après.
Ordi-5 1-1982 - FR V2_page_030_Fig_1.jpg

Code: Select all

ZONE 3   1 2 3 4 5 | 6 7 8 9 0    ZONE 4
ZONE 2    Q W E R T | Y U I O P   ZONE 5
ZONE 1     A S D F G | H J K L □  ZONE 6
ZONE 0    □ Z X C V | B N M . □   ZONE 7

REGISTRE L             Fig. 1
----------
Ordi-5 1-1982 - FR V2_page_030_Fig_2.jpg

Code: Select all

ZONES  0 1 2 3 4 5 5 4 3 2 1

         1 2 3 4 5 6 7 8 9 0
          Q W E R T Y U I O P
           A S D F G H J K L □
          □ Z X C V B N M . □

ZONES   0 1 2 3 4 5 5 4 3 2 1
        
REGISTRE H             Fig. 2
----------
Last edited by David G on Mon Feb 01, 2021 12:56 pm, edited 1 time in total.
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

first page - English

Post by David G »

30 -- ORDI-5 N 1° -- September 82
=================================

technique -----------------------
Change the meaning of the keys on your keyboard

How does the ZX know that such and such a key has been pressed by the user? It is a specialized routine of the system monitor program [ZX81 ROM] which takes care of the interpretation of the keyboard. It begins at the address 02BB (Dec.699). It is a particularly interesting routine; correctly retrieved by the user, it allows the user to modify the meaning of all the keys of the ZX81 keyboard in the direction he wishes. We will give an illustration of these possibilities of diversion with a small purely demonstrative darts game program, but the applications can be much larger: when will a judicious reader present us with a program based on this method to transform the QWERTY keyboard? in AZERTY keyboard?

THE KEYBOARD DECODING ROUTINE
---------------------------------
Each key on the keyboard has a unique position in height and width; it belongs to a certain row and to a certain column. If the double register HL of the Z80 microprocessor is associated with the column number, it is easy by this means to make each key correspond to a unique number in HL resulting from a unique combination of column / H, row / L.

Rather than in row and column, for simple reasons (do not exceed the number 8 for the value of the index), the ZX keyboard is divided into distribution zones modeled on the rows and columns according to the division shown below.

Code: Select all

ZONE 3   1 2 3 4 5 | 6 7 8 9 0    ZONE 4
ZONE 2    Q W E R T | Y U I O P   ZONE 5
ZONE 1     A S D F G | H J K L □  ZONE 6
ZONE 0    □ Z X C V | B N M . □   ZONE 7

REGISTER L             Fig. 1
----------

Code: Select all

ZONES  0 1 2 3 4 5 5 4 3 2 1

         1 2 3 4 5 6 7 8 9 0
          Q W E R T Y U I O P
           A S D F G H J K L □
          □ Z X C V B N M . □

ZONES   0 1 2 3 4 5 5 4 3 2 1
        
REGISTER H             Fig. 2
----------
Last edited by David G on Mon Feb 01, 2021 12:57 pm, edited 1 time in total.
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by David G »

ORDI-5 N 1° -- Septembre 82 -- 31
=================================
Ceci donne 5 zones pour les colonnes (10/2) et 8 zones pour les lignes. Lecteur vérifiera aisément que suivant ce principe, il est impossible que deux lettres ou signes graphiques ou mots BASIC donnent la même combinaison HL, ceci pour chaque niveau (avec ou sans SHIFT, notamment) car, et c'est une des propriétés du ZX, chaque toucher peut avoir plusieurs niveaux de signification ; mais nous allons voir que ce niveau, également, est indiqué dans HL.

Les codes binaires produits dans HL par la pression d'une touche sont représentés dans le tableau ci-dessous :
Ordi-5 1-1982 - FR V2_page_031_Tab.jpg

Code: Select all

ZONE DU  CONTENU DU   CONTENU DU     CONTENU DU
CLAVIER  REGISTRE L  REGISTRE (H)   REGISTRE (H)
                     (après avoir   (sans avoir
                     pressé SHIFT)  pressé SHIFT)
   0      11111110
   1      11111101     11111100       11111101
   2      11111011     11111010       11111011
   3      11110111     11110110       11110111
   4      11101111     11101110       11101111
   5      11011111     11011110       11011111
   6      10111111
   7      01111111
 AUCUNE   11111111     11111110       11111111
Chaque valeur correspond à l'équivalent binaire de l'expression qu'il est facile de calculer et de mettre en oevre dans un programme : N=2^8-1-2 (n° zone). Si SHIFT a été pressé on soustrait un 1 supplémentaire.

UN PROGRAMME COURT MAIS INDISPENSABLE
-------------------------------------
Le petit programme ci-dessous comporte un trés court développement en langage machine d'une demi-douzaine d'instructions : il a pour objet de transférer les contenus de registres H et L du Z80 dans les registres B et C après avoir appelé
la routine de décodage du clavier. Ceci est obligatoire pour le ZX81 parce que le retour de la fonction USR se fait automatequement par la lecure de ces deaus registres.

Ce programme est assez lent parce que, pour ne pas déconcerter le lecteur dan les déduts, la durée de la PAUSE a été fixée assiz longue. Mais il est susceptible de nombreus aménagements.

Code: Select all

  10 REM _asm
     KEYBOARD EQU $02BB
     TOUCHE: CALL  KEYBOARD
             LD    B,H
             LD    C,L
             RET
     END _asm
La courte section en langage machine a la signification suivante : aller chercher la routine commençant au pas 02BB (CALL BB 02) soit en décimal 205, 187, 2, transférer H dans B (68), L dans C (77) et retour au système BASIC.

Code: Select all

  10 REM 123456
  20 PRINT "GARDER LE DOIGT SUR
UNE TOUCHE"
  50 LET A=16514
  60 POKE A,205
  70 POKE A+1,187
  80 POKE A+2,2
  90 POKE A+3,68 
 100 POKE A+4,77 
 110 POKE A+5,201
 115 PAUSE 1000
 140 PRINT "KV=";USR 16514
Si l'on renvoyait les registres H et L à la routine d'impression de la ROM, on verrait s'afficher sur l'écran le caractère porté par la touche. On pourrait naturellement faire subir au contenu de H et L un traitement approprié avant le revoi à la routine d'impression pour, par exemple, transformer la valeur représentative de Q en valeur représentative de A, dans l'idée de faire un clavier français : nous n'avons pas tenté l'expérience car il est difficile d'utiliser le ZX comme une machine à écrire, mais ceci doit normalement être possible : tout lecteur parvenu à la conclusion inverse est prié de nous le faire savoir au plus vite... il nous rendrait service.

------------------- Igor BOURDAIN
Last edited by David G on Mon Feb 01, 2021 1:30 pm, edited 2 times in total.
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Read the Keyboard -- Page 2 - English

Post by David G »

ORDI-5 N 1° -- September 82 -- 31
=================================
This gives 5 areas for the columns (10/2) and 8 areas for the rows. The reader will easily verify that, following this principle, it is impossible for two letters or graphic signs or BASIC words to give the same HL combination, this for each level (with or without SHIFT, in particular) because, and this is one of the properties of ZX, each touch can have several levels of meaning; but we will see that this level, too, is indicated in HL.

The binary codes produced in HL by the press of a key are shown in the table below:

Code: Select all

KEYBOARD  CONTENT OF   CONTENT OF    CONTENT OF
ZONE      REGISTER L   REGISTER H    REGISTER H
		       (with SHIFT   (without 
                       pressed)      SHIFT)
   0      11111110
   1      11111101     11111100       11111101
   2      11111011     11111010       11111011
   3      11110111     11110110       11110111
   4      11101111     11101110       11101111
   5      11011111     11011110       11011111
   6      10111111
   7      01111111
  NULL    11111111     11111110       11111111
Each value corresponds to the binary equivalent of the expression which it is easy to calculate and to implement in a program: N = 2 ^ 8-1-2 (n ° zone). If SHIFT was pressed we subtract an additional 1.

A SHORT BUT ESSENTIAL PROGRAM
-------------------------------------
The small program below comprises a very short development in machine language of half a dozen instructions: its purpose is to transfer the contents of H and L registers of the Z80 into the B and C registers after calling the routine. keyboard decoding. This is compulsory for the ZX81 because the return of the USR function is done automatically by reading these other registers.

This program is quite slow because, in order not to confuse the reader in the deductions, the duration of the PAUSE has been set to be long. But it is susceptible to numerous adjustments.

Code: Select all

  10 REM _asm
     KEYBOARD EQU $02BB
     TOUCHE: CALL  KEYBOARD
             LD    B,H
             LD    C,L
             RET
     END _asm
The short section in machine language has the following meaning: fetch the routine starting at step 02BB (CALL BB 02) either in decimal 205, 187, 2, transfer H to B (68), L to C (77) and return to BASIC system.

Code: Select all

  10 REM 123456
  20 PRINT "KEEP YOUR FINGER ON 
A KEY"
  50 LET A=16514
  60 POKE A,205
  70 POKE A+1,187
  80 POKE A+2,2
  90 POKE A+3,68 
 100 POKE A+4,77 
 110 POKE A+5,201
 115 PAUSE 1000
 140 PRINT "KV=";USR 16514
If we returned the H and L registers to the ROM printing routine, the character carried by the key would be displayed on the screen. We could naturally subject the contents of H and L to an appropriate treatment before returning to the printing routine to, for example, transform the representative value of Q into a representative value of A, with the idea of making a French keyboard: we did not attempt the experiment because it is difficult to use the ZX as a typewriter, but this should normally be possible: any reader who has come to the opposite conclusion is kindly requested to let us know as soon as possible...he would do us a favor.

------------------- Igor BOURDAIN
Last edited by David G on Mon Feb 01, 2021 1:37 pm, edited 3 times in total.
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by 1024MAK »

Fig 1 has an error. Zone 3 is mislabelled as zone 1...

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by David G »

Thanks. I have now corrected Fig. 1 text
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by 1024MAK »

Line 140 cannot be entered, as it will not pass the syntax checker. Remove the forward slash, then it will work.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by 1024MAK »

I also suggest that line 10 has six characters after the REM because we are poking in six bytes not five.

Screen shots:
Listing as entered
Listing as entered
Listing after RUNning it
Listing after RUNning it
Output after T key pressed
Output after T key pressed
The text in the PRINT statement in line 20 could be replaced with “PRESS A KEY”

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
David G
Posts: 387
Joined: Thu Jul 17, 2014 7:58 am
Location: 21 North, 156 West

Re: How to Re-map the Keyboard/Read the Keyboard Hardware

Post by David G »

Line 140 corrected now
Post Reply