=== Reverse Engineering the Keyboard of Family Computer === date: 1998/3/15 by goroh mail: goroh_kun@geocities.co.jp date: 2000/07/15 English translation by Ki mail: iskk@geocities.co.jp 1. The key composition The keyboard employs early "scanning" method. Its key matrix is 8x10. [ 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][@][[][RETURN] [CLR][INS][DEL] [CTR][A][S][D][F][G][H][J][K][L][;][:][]][ƒJƒi] [ UP ] [ SHIFT][Z][X][C][V][B][N][M][,][.][/][ ][ SHIFT ] [ LEFT ][ RIGHT ] [GRPH][ SPACE ] [ DOWN ] It also has tape read/write port. 2. The composition of the keyboard port 01:GND 04:PORT1-D4 05:PORT1-D3 06:PORT1-D2 07:PORT1-D1 10:OUT2 NOT‚Ì3pin(IN2) switch keyboard input / tape recorder input 0:tape recorder 1:keyboard 11:OUT1 switch keyboard input, start next key scan 0:input A 1:input B the next key scan starts when the bit changes from 1 to 0. 12:OUT0 initialize keyboard 0:don't initialize 1:initialize 13:PORT0-D1 data from the tape recorder 15: +5V 3.How to control the keyboard (1)Initialization the next read after initializing keyboard will be the first scan. $4016 <- #$05 (2) the 1st scan $4016 <- #$04 $4016 -> D1a $4016 <- #$06 $4016 -> D1b (3) 2nd - 10th scan same as (2) $4016 <- #$04 at this point it will automatically moves on to the next scan $4016 -> D2a $4016 <- #$06 $4016 -> D2b 4. The keyboard scan-code S1-S0 shows the current scan number. A1-A4 shows the values of PORT1-D1,D2,D3,D4 when OUT1 is 0. B1-B4 shows the values of PORT1-D1,D2,D3,D4 when OUT1 is 1. the bit corresponding to the position of the pressed key will be set to 0. for example, when only '@' key is pressed, after reset, data read on the 3rd scan when OUT1=0, will be D1=1,D2=0,D3=1,D4=1. Otherwise it will be D1=1,D2=1,D3=1,D4=1. A1 A2 A3 A4 B1 B2 B3 B4 | | | | | | | | S1----[F8]---[RETURN]-[ [ ]---[ ] ]---[kana]-[SHIFT-R]-[\]----[STOP] | | | | | | | | S2----[F8]---[RETURN]-[ [ ]---[ ] ]----[_]-----[/]-----[-]-----[^] | | | | | | | | S3----[F7]-----[@]-----[:]-----[;]----[. _]----[,]-----[P]-----[0] | | | | | | | | S4----[F6]-----[O]-----[L]-----[K]-----[M]-----[N]-----[9]-----[8] | | | | | | | | S5----[F5]-----[I]-----[U]-----[J]-----[B]-----[V]-----[7]-----[6] | | | | | | | | S6----[F4]-----[Y]-----[G]-----[H]-----[F]-----[C]-----[5]-----[4] | | | | | | | | S7----[F3]-----[T]-----[R]-----[D]-----[X]-----[Z]-----[E]-----[3] | | | | | | | | S8----[F2]-----[W]-----[S]-----[A]-[X SHIFT-L]-[GRPH]--[1]-----[2] | | | | | | | | S9----[F1]----[ESC]----[Q]----[CTR]--[DOWN ][SPACE]-[1 DEL]-[2 INS] | | | | [SHIFT-L][GRPH ] | | S0----[CLR]----[UP]--[RIGHT]--[LEFT]--[DOWN]--[G+SP]--[1+DEL]-[2+INS] 5.Discussion Upon reading from $4017, the first bit shows data from control pad. But when reading more than 8 times after reset of the control pad, the first bit will always return 1. On the other hand, keyboard will return back to the first scan after 10th read from the port. 6.Appendix (i) Spec of the exapansion port controlling registers 4016 WR R: 0100000A A:port0-D0 W: -----ABC A:out2 B:out1 C:out0 4017 R: 010ABCDE A:port1-D4 B:port1-D3 C:port1-D2 D:port1-D1 E:port1-D0 W: ???????? Delta sound channel related settings (ii)Expansion port pin-outs 01 GND 02 SOUND 03 IRQ 04 port1-D4 05 port1-D3 06 port1-D2 07 port1-D1 08 port1-D0 09 port1-CLK 10 OUT2 11 OUT1 12 OUT0 13 port0-D0 14 port0-CLK 15 +5V