Independent Key-Scanning on SHARP's
written by Maurice Hawes
Source: SUC-magazine July 2001, Volume 21, Number 2, p. 13 & 16
Independent Key Scanning on the MZ-80B and MZ-2500
Reprinted with alterations from SUC-magazine Volume 6 and Volume 18, No. 1
To begin with, the tables on p. 53 for Ports A and B do not give the addresses of those ports, and there is a bad misprint on p. 54 regarding key data. Also, the assembly language example on p. 55 has more to do with interrupts than keyboard scanning. However, one thing is clear; on the MZ-80B, keyboard scanning, like all other I/O operation, is done by directly addressing I/O ports, and not by addressing locations around $E000 as on the MZ-80K / 80A / 700.
As far as keyboard scanning is concerned, Port A is $E8, and Port B is $EA. Bits 0, 1, 2, 3 of Port A are used to strobe the keyboard, whilst bit 4 has to be set to turn the strobe on. The remaining bits of Port A ( 5 - 7 ) have nothing to do with keyboard scanning AND THEY MUST NOT BE CHANGED WHEN PORT A IS ADDRESSED IN ORDER TO SCAN THE KEYBOARD. As will be seen later, this makes the process more involved than on the other machines. All 8 bits of Port B are used to handle key data inputs resulting from a strobe.
The key data bits from Port B are coded in the normal Sharp way i.e. if the strobe finds a depressed key, the corresponding bit of key data is set LOW. Thus, on page 54, paragraph two should read For instance, when the strobe is $06 and key data _$F7_ then it is found that key S is being depressed. ( N.B. Key data $FF11 as printed would indicate that no key was being pressed !! )
The assembly-language example on page 55 is unfinished, which is very confusing. Nevertheless, the last four lines show the method used to strobe row 3 of the keyboard; it begins by reading from $E8 and then ANDing the result with $E0 to leave the top three bits o fPort A unchanged; then an OR with $13 sets bit 4 high AND sets the strobe bits to row 3. The result, returned to $E8, leaves the top 3 bits as they were and performs the required strobe.
The key data from row 3 is read in from Port B ( $EA ), and can be dealt with as you choose. This is not explained in the Owners Manual, but if you look at BRKEY on page 56 of the MONITOR SB-1510 REFERENCE MANUAL you will see how it sets ZERO if the BREAK key is pressed. For clarity, BRKEY ( $0562 ) is rewritten below with the CALL to the subroutine KBSET replaced by the corresponding code:
IN A,(E8H) ; read current setting of E8 AND E0H ; isolate top three bits to leave as is OR 13H ; set bits to open gate (10H) and set row (03H) OUT (E8H),A ; strobe selected row (03H) IN A,(EAH) ; read key data (too soon, should be NOP NOP?) IN A,(EAH) ; so read it again to make sure! AND 80H ; check bit 7 (i.e. column 7) RET ; return (zero flag set if BREAK pressed)
This routine could be used to set the zero flag for any other specific
keypress, by changing the values used with OR and AND. For example,
to detect the RVS key, OR with $1B to scan row $0B, and then AND with
$08 to detect column 3.
|MZ-2500 normal keys - minor changes cf. MZ-80B|
|MZ-2500 special keys - changes and additions cf. MZ-80B|
KANA toggles the keyboard to Japanese KANA characters, as per the added keytop markings. ( KANA characters represent syllables e.g. the two characters on this key represent KA and NA ).
GRPH toggles a mode in which SOME keys, after 2 presses, display a Japanese graphics character.
The KJ1 and KJ2 keys, on the SUC machine, appear to do nothing. I would guess that they require optional extra KANJI character ROMS.
The LOGO key ( Sharps Viking Ship, top right alongside
F1 key ) when used from MZ-2500 BASIC with a following CR, invokes a
drop-down calculator on the VDU, with the number pad redefined to act
as its keys. ( From this drop-down calculator mode, LOGO alone returns
to BASIC ).
|MZ-2500 Basic Program to Check Keyboard Matrix|
10 CLEAR $A500
20 POKE $A500,$DB,$E8 $E6,$F0,$F6,$10,$D3,$E8,$0,$0,$DB,$EA,
30 INPUT Strobe whith keyboard row (0-13);R
35 FOR TD = 0 TO 2500:NEXT
40 POKE $A505,(R+16): REM add $10 to R to open strobe gate (Bit 4)
50 CALL $A500
60 KD = PEEK($A520)
70 FOR TD = 0 TO 5000:NEXT
75 INPUT Which key was that;KY$
80 PRINT:PRINT KY$; Key was Row ;HEX$(R); Key Data ;HEX$(KD)
90 INPUT Same Row again";Q$
95 FOR TD = 0 TO 2500:NEXT
100 IF Q$ = Y THEN 50
110 INPUT Which Row;R
115 FOR TD = 0 TO 2500:NEXT
120 IF R>13 THEN END
130 GOTO 40
This program, with added code to convert variables R and KD to HEX strings before reaching LINE 80, and with the maximum value of R set to 11 instead of 13, should also work on the MZ-80B.
With further modifications, to add 240 instead of 16 to the Strobe
Row R, to address locations $E000/1 instead of ports $E8 / $EA, and
to set the maximum value of R to 9, it should also work with the other
MZ-Machines mentioned in this article.
khmweb barrierefreies webdesign Berchtesgaden