Family BASIC Keyboard
The Family Basic Keyboard (HVC-007) was a peripheral released with the Family Basic package in 1984. With the data recorder that could be attached to it, it allowed the Famicom to have the abilities of the average home computer of around that time. It is a generic 72 button keyboard using common matrix logic, and can be connected to the Famicom at the expansion port.
In text format:
F1 F2 F3 F4 F5 F6 F7 F8 1 2 3 4 5 6 7 8 9 0 - ^ ¥ STOP CH* INS DEL ESC Q W E R T Y U I O P @ [ RETURN UP CTR A S D F G H J K L ; : ] KANA LEFT RIGHT SHIFT Z X C V B N M , . / _ SHIFT DOWN GRPH SPACE * CH = CLR HOME
If you have proper font support, with full-width spaces (i.e. "=" is above "-"):
Ｆ１ Ｆ２ Ｆ３ Ｆ４ Ｆ５ Ｆ６ Ｆ７ Ｆ８ ！ ＂ ＃ ＄ ％ ＆ ＇ （ ） ＝ １ ァ ２ ィ ３ ゥ ４ ェ ５ ォ ６ ７ ８ ９ ０ － ＾ ￥ STOP ア イ ウ エ オ ナ ニ ヌ ネ ノ ラ リ ル ＣＬＲ ＩＮＳ ＤＥＬ ＥＳＣ Ｑ Ｗ Ｅ Ｒ Ｔ Ｙ パ Ｕ ピ Ｉ プ Ｏ ペ Ｐ ポ ＠ ［ 「 ＲＥＴＵＲＮ HOME カ キ ク ケ コ ハ ヒ フ ヘ ホ レ ロ ＋ ＊ ▲ ＣＴＲ Ａ Ｓ Ｄ Ｆ Ｇ Ｈ Ｊ Ｋ Ｌ ； ： ］ 」 カナ サ シ ス セ ソ マ ミ ム メ モ ー 。 〈 〉 ？ ␣ ◀ ▶ ＳＨＩＦＴ Ｚ Ｘ Ｃ Ｖ Ｂ Ｎ Ｍ ， ． ／ ＳＨＩＦＴ タ チ ツ テ ト ヤ ユ ヨ ワ ヲ ン ▼ GRPH ［．．．．．．．．．．．．ＳＰＡＣＥ．．．．．．．．．．．．］
Mind that the DEL key function is actually that of Backspace we all know and love.
Input ($4016 write)
7 bit 0 ---- ---- xxxx xKCR ||| ||+-- Reset the keyboard to the first row. |+--- Select column, row is incremented if this bit goes from high to low. +---- Enable keyboard matrix (if 0, all voltages inside the keyboard will be 5V, reading back as logical 0 always)
Incrementing the row from the (keyless) 10th row will cause it to wrap back to the first row.
Output ($4017 read)
7 bit 0 ---- ---- xxxK KKKx | ||| +-+++--- Receive key status of currently selected row/column.
Any key that is held down, will read back as 0.
($4016 reads from the data recorder.)
Similar to the Family Trainer Mat, there are parasitic capacitances that the program must wait for to get a valid result. Family BASIC waits approximately 50 cycles after advancing rows before assuming the output is valid.
Family BASIC reads the keyboard state with the following procedure:
- Write $05 to $4016 (reset to row 0, column 0)
- Write $04 to $4016 (select column 0, next row if not just reset)
- Read column 0 data from $4017
- Write $06 to $4016 (select column 1)
- Read column 1 data from $4017
- Repeat steps 2-5 eight more times
Note that Family BASIC never writes to $4016 with bit 2 clear, there is no need to disable the keyboard matrix.
|Column 0||Column 1|
|Row 8||LEFT||RIGHT||UP||CLR HOME||INS||DEL||SPACE||DOWN|
The Family BASIC Keyboard is implemented using a CD4017 decade counter (to scan the rows of the keyboard matrix), a CD4019 quad AND-OR gate, and one sixth of a CD4069 hex inverter. The latter two are combined to make a quad 1-of-2 selector, equivalent to a CD4519 or a 74'157. (Another three inverters are used to interface to the Family BASIC Data Recorder)
- Unlike the PC keyboard, but similar to the Commodore 64 keyboard, the sixteen keys corresponding to ASCII $2C-$3B all specify the ASCII code point should be XORed with $10 when the SHIFT key is pressed. This can be used to simplify the keyboard decoding logic in your program.
- There is no backslash key, however, historical reasons have given to using the yen key and symbol for the same meaning.
- The kana are arranged in (grid) alphabetical order, not in the way that modern Japanese computers are.
The game Lode Runner allows saving level data to tape by pressing SELECT during Edit Mode, but will only provide that option if it detects the Family BASIC Keyboard. The detection procedure (CPU $E9B8) selects the tenth row and expects $4017 AND $1E to return $1E, then writes $00 to $4016 to disable the keyboard and expects $4017 AND $1E to return $00.