
Created by Robert Hannan (emerson)


NES Keyboard Adapter - Rev 1 (December 29, 2017)

=====INTRODUCTION=====

The NES Keyboard Adapter allows the user to connect a standard ps/2 keyboard and 
ps/2 mouse to the NES or Famicom via the expansion port. The adapter can both
emulate the Family Basic keyboard, as well as provide full enhanced 
keyboard and mouse support for future game development.



=====DISCLAIMER=====

The information provided in this and the other included documents is correct
to the best of my knowledge. Being said, please double check your work as well as mine,
and use this information at your own risk. I cannot be held responsible for damages
of any kind.



=====FEATURES=====

-Support for all 3 keyboard scan codes
-Automatic scroll wheel detection for mouse
-Power led error blink codes
-Serial debug data available
-Adapter is automatically reset when console reset is pressed
-Save/Load functionality with PC compatibility



=====LIMITATIONS OF CURRENT REVISION=====

-'Pause' and 'Print Screen' supported for scan code 3 only
-The serial port is only used to transmit debug data to a serial terminal program.
-Pressing 'Print Screen' while using scan codes 1 or 2 will lock the adapter, requiring a reset.



=====USAGE NOTES=====

-Do not hot-plug devices while console is powered on.
-The configuration switches need to be set accordingly before power-up. 
-A ps/2 splitter cable is required to use the mouse



=====CONFIGURATION SWITCH SETTINGS=====

1:		0 = family basic keyboard emulation
		1 = full enhanced keyboard/mouse support
		
2,3:	00 = use default keyboard scan code on power-up
		01 = force scan code 1
		10 = force scan code 2
		11 = force scan code 3
		
4:		0 = disable ps/2 mouse
		1 = enable ps/2 mouse
		
		
		
=====SERIAL PORT=====
The serial port is enabled via the solder jumper (J2). The 4 pin header (J6) is used to connect to an external serial device.
If connecting to a PC, a MAX232 circuit is required for proper level conversions. 

The header pinout is as follows:
		1: VCC
		2: GND
		3: Receive
		4: Transmit

		
Serial Port Configuration:
		115200 Baud, no parity, 8 data bits, 1 stop bit, no flow control

		
The debug data packet format is as follows:

Family Basic:	
		ex:		5a 00 00 20 00 00 00 00 00 00 00 00		;press enter using scan code 2
				f0 5a 00 00 00 00 00 00 00 00 00 00		;release enter using scan code 2
				
		data packet structure:
				00 00 00 00 00 00 00 00 00 00 00 00
				1  2  3  4  5  6  7  8  9  A  B  C
				|  |  |  |  |  |  |  |  |  |  |  |
				|  |  |  |  |  |  |  |  |  |  |  famicom byte 8
				|  |  |  |  |  |  |  |  |  |  famicom byte 7
				|  |  |  |  |  |  |  |  |  famicom byte 6
				|  |  |  |  |  |  |  |  famicom byte 5
				|  |  |  |  |  |  |  famicom byte 4
				|  |  |  |  |  |  famicom byte 3
				|  |  |  |  |  famicom byte 2
				|  |  |  |  famicom byte 1
				|  |  |  famicom byte 0
				|  |  ps2_keyboard byte 2
				|  ps2_keyboard byte 1
				ps2_keyboard byte 0
				
		famicom byte structure:	bits 7-4 = row0 columns 4-1
								bits 3-0 = row1 columns 4-1
								
		-ps2_keyboard bytes are relative to the selected scan code
		-famicom bytes represent the status of J2 D4-D1 and are not equal to the values in the test program
		
Full Enhanced Support:
		ex:		5a 00 00 08 00 00 00	;press enter using scan code 2
				f0 5a 00 08 00 00 00	;release enter using scan code 2
				00 00 00 09 00 00 00	;left mouse click
				00 00 00 0A 00 00 00	;right mouse click
				
		data packet structure:
				00 00 00 08 00 00 00
				1  2  3  4  5  6  7 
				|  |  |  |  |  |  | 
				|  |  |  |  |  |  ps2_mouse byte 3
				|  |  |  |  |  ps2_mouse byte 2
				|  |  |  |  ps2_mouse byte 1
				|  |  |  ps2_mouse byte 0
				|  |  ps2_keyboard byte 2
				|  ps2_keyboard byte 1
				ps2_keyboard byte 0

		-ps2_keyboard bytes are relative to the selected scan code
		
		mouse byte data structure:
				byte 0 - 7 6 5 4 3 2 1 0 
						 | | | | | | | |
						 | | | | | | | left button
						 | | | | | | right button
						 | | | | | middle button
						 | | | | always 1
						 | | | x sign
						 | | y sign
						 | x overflow
						 y overflow
						 
				byte 1 - change in x since last read
				byte 2 - change in y since last read
				byte 3 - change in z since last read (always 00 if scroll wheel not present)
				
		
		
=====POWER LED ERROR BLINK CODES=====

The power led will be red during initialization (power-on/reset), then turn green when ready for use.
If an error occurs, the power led will turn red for two seconds, blink green at 500ms
intervals to indicate the current error, and return red for two seconds, repeating the cycle. 
The adapter must be reset to clear the error. The led error codes are as follows:

1 blink:	keyboard POST fail or not connected at power-on
2 blinks:	mouse POST fail or not connected at power-on
3 blinks:	keyboard transmit error or forced scan code not supported
4 blinks:	keyboard receive error
5 blinks:	mouse transmit error
6 blinks:	mouse receive error



=====SAVE/LOAD FUNCTIONS=====

Two 3.5mm jacks are present for connection to a PC other recording device that supports line input. If using a PC, 
be sure to set the line input as the default audio input device, as well as the input level. The audio recording 
provided was made using a freeware audio editing program called WaveShop. Removing the non-data portions at 
the end of the recording is suggested.

Save file - Excitebike track design, contains one of every track obstacle.
		
PC line input level	- 25%
PC playback volume	- 100%

WaveShop recording settings:
		channels - 1
		sample rate - 44100
		sample size - 8
















