Sharp logo
Independent Key-Scanning on SHARP's 
written by Maurice Hawes / SUC/UK 
Source: SUC-magazine July 2001, Volume 21, Number 2, p. 7  

Independent Key Scanning on Sharp MZ-Computers

An Overview compiled by Maurice Hawes


In principle, the keyboard-scanning routines work in the same way on all Sharp MZ-Computers. That is to say, all the keys on the keyboard are connected in a matrix with 8 keys per row and as many rows are needed to accommodate the number of keys on the keyboard; and each row of the matrix is ‘strobed‘ by special software that returns the ‘key data‘ for that row as 1 byte of 8 bits ( ‘lows‘ for keys that are pressed, ‘highs‘ for keys that are not pressed).

In other words, if there are no keys down in the scanned row the software returns $FF; but in any other case the software returns a value less than $FF and the positions of the low bits indicate the positions of the depressed keys in that row of the matrix.

On most early MZ-machines, a matrix containing 10 rows of 8 keys is enough; but the MZ-80B needs 12 rows, and the MZ-2500 needs 14 rows ( though with a lot of positions unused ). This does not affect the above principles; it merely means that, in order to scan the whole keyboard, 10 software loops will cover early machines, but 12 are needed on the MZ-80B, and 14 are needed on the MZ-2500.

On all machines, the scanning process is controlled by an 8255 chip, which is connected to certain ‘ports‘ on the master Z80 CPU. And this is where differences of detail start to occur; on the MZ-80K, MZ-80A, MZ-700, and MZ-800 in ‘MZ-700 Mode‘ these ports are 'memory-mapped‘ to addresses $E000 - $E001, and are accessed, as far as key-scanmng is concerned, by writing the ‘strobe row‘ to address $E000, and reading the ‘key data‘ from address $E001.

But on the MZ-80B, the MZ-2500, and the MZ-800 in ‘MZ-800 Mode‘, the relevant ports are not memory-mapped, and they have to be addressed directly by the appropriate Z80 ‘IN‘ and ‘OUT‘ codes, sending the ‘strobe row‘ OUT to one port, and reading the ‘key data‘ IN from another port. The full details are as follows:

Machine Strobe
instruction
Strobe
row no's
Read key data
instruction
MZ-80K LD ($E000),A $F0 - $F9 LD A,($E001)
MZ-80A LD ($E000),A $F0 - $F9 LD A,($E001)
MZ-700 LD ($E000),A $F0 - $F9 LD A,($E001)
MZ-800
( 700 mode )
LD ($E000),A $F0 - $F9 LD A,($E001)
 
MZ-80B OUT ($E8),A $00 - $0B* IN A,($EA)
MZ-2500 OUT ($E8),A $00 - $0D* IN A,($EA)
MZ-800
( 800 mode )
OUT ($D0),A $F0 - $F9 IN A,($D1)

* N.B. On the MZ-80B and MZ-2500, bits 7 - 6 - 5 of $E8 are used to control other devices and bit 4 ‘high‘ opens the keystrobe ‘gate‘. Therefore the value at PORT $E8 must first be READ IN, and then sent back OUT with bits 7 - 6 - 5 unaltered, bit 4 set ‘high‘, and bits 3 - 2 - 1 - 0 set to the selected Strobe Row No.

Volumes 5/2, 6/2 and 18/1 carried detailed articles all the above machines except the MZ-800, with full key matrix diagrams. In order to bring them all under one roof and include the MZ-800, these articles are updated and reprinted on the following pages.


Go to the top of this page      Get next page - part 2      Home     

last updated September 2, 2002
SUC / UK: Maurice Hawes

khmweb barrierefreies webdesign Berchtesgaden