This is the code read read the keyboard on the Famicom. SUBOR may have a similar keyboard. This information is based on information from the emubase website.
Controllers - Keyboard
Keyboard with 72 Keys, and tape read/write port, connected to 15-pin Famicom Expansion port. Used by Famicom BASIC. Also, the Study and Game 32-in-1 and Education 18-in-1 cartridges use an identical protocol, but with different keyboard matrix.
Keyboard Access Pseudo Code
[4016h]=05h:WAIT(16clks) ;reset (force row 0)
FOR i=0 TO 8 ;loop 9 rows
[4016h]=04h:WAIT(56clks) ;request LSB of NEXT row
Row[i]=(([4017h] SHR 1) AND 0Fh) ;read LSB
[4016h]=06h:WAIT(56clks) ;request MSB of SAME row
Row[i]=(([4017h] SHL 3) AND F0h)+Row[i] ;read MSB
NEXT ;loop next
Column 0-7 are then in Bit0-7 of each row. Bits are 0=Pressed, 1=Released (unlike for most other NES/Famicom controllers, which are 1=Pressed).
When reading more than 9 rows, the 10th read (row 9) returns garbage data, and then starts over at row 0.
Famicom Keyboard Matrix
Row Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7
0 F8 RETURN [ ] KANA R-SHFT \(Yen) STOP
1 F7 @ : ; _ / - ^
2 F6 O L K . , P 0
3 F5 I U J M N 9 8
4 F4 Y G H B V 7 6
5 F3 T R D F C 5 4
6 F2 W S A X Z E 3
7 F1 ESC Q CTRL L-SHFT GRPH 1 2
8 CLR UP RIGHT LEFT DOWN SPACE DEL INS
Famicom Keyboard Layout
________________________________________________
| F1 F2 F3 F4 F5 F6 F7 F8 |
| 1 2 3 4 5 6 7 8 9 0 - ^ \ STOP |
| ESC Q W E R T Y U I O P @ [ ENTER CLR INS DEL |
| CTRL A S D F G H J K L ; : ] KANA UP |
| SHIFT Z X C V B N M , . / _ SHIFT LEFT RIGHT |
|______GRPH____SPACE____________________DOWN_____|
32-in-1 Study and Game / Education Keyboard Matrix
Row Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7
0 4 G F C F2 E 5 V
1 2 D S END F1 W 3 X
2 INS BS PGDN RIGHT F8 PGUP ESC HOME
3 9 I L , F5 O 0 .
4 ] ENTER UP LEFT F7 [ \ DOWN
5 Q CAPS Z Pa ESC A 1 CTRL
6 7 Y K M F4 U 8 J
7 - ; ' / F6 P = SHIFT
8 T H N SPACE F3 R 6 B
The 32-in-1 menu also checks Bit4 in Row 9, if that bit is zero then it does additionally read row 0Ah..0Ch. Aside from the menu, most or all games in the 32-in-1 cartridge don't seem to use that extra rows though.
32-in-1 Study and Game Keyboard Layout (as shown in Typing School I)
____________________________________________________________
| ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Pa. Br Nu Re. |
| ~ 1 2 3 4 5 6 7 8 9 0 - + BS HOME |
| TAB Q W E R T Y U I O P [ ] \ END |
| CAPS A S D F G H J K L ; ' ENTER PGUP |
| SHIFT Z X C V B N M , . / SHIFT UP PGDN |
|_###_CTRL_ALT_##_[______SPACE______]_ALT_INS_DEL_LT_DN_RIGH_|
Keyboard I/O Signals
OUT.0 Keyboard Strobe/Reset (0=Normal, 1=Initialize)
OUT.1 Keyboard Clock (0=LSB, 1=MSB) (1-to-0=Next Row)
OUT.2 Tape Output? (Should be 1 when accessing Keyboard)
PORT0-1 Tape Input
PORT1-4..1 Keyboard Input Bit3..0 (either MSB or LSB of current row)
Comments (0)
You don't have permission to comment on this page.