Intelligent Keyboard (ikbd) Protocol Revised: 02/26/85 1. Introduction The Atari Corp. Intelligent Keyboard (ikbd) is a gen- eral purpose keyboard controller that is flexible enough that it can be used in a variety of products without modifi- cation. The keyboard, with its microcontroller, provides a convenient connection point for a mouse and switch-type joysticks. The ikbd processor also maintains a time-of-day clock with one second resolution. The ikbd has been designed to be general enough that it can be used with a variety of new computer products. Pro- Guct variations in number of keyswitches, mouse resolution, etc. can be accommodated. The ikbd communicates with the main processor over a high speed bi-directional serial interface. It can function in a variety of modes to facilitate different applications of the keyboard, joysticks, or mouse. Limited use of the controller is possible in applications in which only a uni- directional communications medium is available by carefully designing the default modes. 2. Related Documents Atari Corp. RBP/GHU/SD Keyboard Schematic (9/14/84). Atari Corp. RBP/GHU/SD Keyboard Layout (unnumbered, no date ) 3. Keyboard The keyboard always returns Key make/break scan codes. The ikbd generates keyboard scan codes for each key press and release. The Key scan make (key closure) codes start at 1, and are defined in Appendix A. For example, the ISO Key position in the scan code table should exist even if no keyswitch exists in that position on a particular keyboard. The break code for each key is obtained by ORing 0x80 with the make code. The special codes OxF6 through OxFF are reserved for use as follows: 26 February 1985 OxF6 status report OxF7 absolute mouse position record OxF8-OxFB relative mouse position records (lsbs determined by mouse button states) OxFC time-of-day OxFD joystick report (both sticks) OxFE joystick O event OxFF joystick 1 event The two shift keys return different scan codes in this mode. The ENTER key and the RETurn key are also distinct. A. Mouse The mouse port should be capable of supporting a mouse with resolution of approximately 200 counts (phase changes or "clicks") per inch of travel. The mouse should be scanned at a rate that will permit accurate tracking at velocities up to 10 inches per second. The ikbd can report mouse motion in three distinctly different ways. It can report relative motion, absolute motion in a coordinate system maintained within the ikbd, or by converting mouse motion into keyboard cursor control key equivalents. The mouse buttons can be treated as part of the mouse or as additional keyboard keys. 4.1. Relative Position Reporting In relative position mode, the ikbd will return rela- tive mouse position records whenever a mouse event occurs. A mouse event consists of a mouse button being pressed or released, or motion in either axis exceeding a settable threshold of motion. Regardless of the threshold, all bits of resolution are returned to the host computer. Note that the ikbd may return mouse relative position reports with significantly more than the threshold delta x or y. This may happen since no relative mouse motion events will be generated: (a) while the keyboard has been "paused" (the event will be stored until keyboard communications is resumed) (b) while any event is being transmitted. The relative mouse position record is a three byte record of the form (regardless of keyboard mode): 26 February 1985 $111110xx ;mouse position record flag ------- ;right button state —e mee ,left button state X ;delta x as a twos complement integer Y ;delta y as a twos complement integer Note that the value of the button state bits should be valid even if the MOUSE BUTTON ACTION has set the buttons to act like part of the keyboard. If the accumulated motion before the report packet is generated exceeds the +127..-128 range, the motion is broken into multiple packets. Note that the sign of the delta y reported is a func- tion of the Y origin selected. 4.2. Absolute Position Reporting The ikbd can also maintain absolute mouse position. Commands exist for reseting the mouse position, setting X%/Y scaling, and interrogating the current mouse position. 4.3. Mouse Cursor Key Mode The ikbd can translate mouse motion into the equivalent cursor keystrokes. The number of mouse clicks per keystroke is independently programable in each axis. The ikbd inter- nally maintains mouse motion information to the highest resolution available, and merely generates aa pair of cur- sor key events for each multiple of the scale factor. Mouse motion produces the cursor key make code immedi- ately followed by the break code for the appropriate cursor key. The mouse buttons produce scan codes above those nor- mally assigned for the largest envisioned keyboard (i.e. LEFT=0x74 & RIGHT=0x75). 5. Joystick 5.1. Joystick Event Reporting In this mode, the ikbd generates a record whenever the joystick position is changed (i.e. for each opening or clos- ing of a joystick switch or trigger). 26 February 1985 The joystick event record is two bytes of the form: S1111111x ; Joystick event marker aalemiasieentant ,Joystick O or 1 sa lau anhedieeieettae ;stick position Sattar ; trigger 5.2. Joystick Interrogation The current state of the joystick ports may be interro- gated at any time in this mode by sending an "Interrogate Joystick" command to the ikbd. The ikbd response to joystick interrogation is a three byte report of the form: OxFD ; joystick report header Sx000yyyy ; Joystick 0O $xO000yyyy ; Joystick 1 NO where x is the trigger te and yyyy is the stick -~e position 9.3. Joystick Monitoring A mode is available that devotes nearly all of the kKey- board communications time to reporting the state of the joystick ports at a user specifiable rate. It remains in this mode until reset or commanded into another mode. The PAUSE command in this mode not only stops the output but also temporarily stops scanning the joysticks (samples are not queued). 5.4. Fire Button Monitoring A mode is provided to permit monitoring a single input bit at a high rate. In this mode the ikbd monitors the state of the Joystick 1 fire button at the maximum rate per- mitted by the serial communications channel. The data is packed 8 bits per byte for transmission to the host. The ikbd remains in this mode until reset or commanded into another mode. The PAUSE command in this mode not only stops the output but also temporarily stops scanning the button (samples are not queued). 5.5. Joystick Key Code Mode The ikbd may be commanded to translate the use of 26 February 1985 either joystick into the equivalent cursor control keystroke(s). The ikbd provides a single breakpoint velo- city joystick cursor. Joystick events produce the make code, immediately fol- lowed by the break code for the appropriate cursor motion keys. The trigger or fire buttons of the joysticks produce pseudo key scan codes above those used by the largest key matrix envisioned (i.e. JOYSTICKO=0x74, JOYSTICK1=0x75). 6. Time-of-Day Clock The ikbd also maintains a time-of-day clock for the system. Commands are available to set and interrogate the time-of-day clock. Time-kKeeping is maintained down to a resolution of one second. 7. Status Inquiries The current state of ikbd modes and parameters may be found by sending status inquiry commands that correspond to the ikbd set commands. 8. Power-Up Mode The keyboard controller will perform a simple self-test on power-up to detect major controller faults (ROM checksum and RAM test) and such things as stuck Keys. Any keys down at power-up are presumed to be stuck, and their BREAK (sic) code is returned (which without the preceding MAKE code is a flag for a keyboard error). If the controller self-test completes without error, the code OxFO is returned. (This code will be used to indicate the version/release of the ikbd controller. The first release of the ikbd is version OxFO, should there be a second release it will be OxFl, and SO on.) The ikbd defaults to mouse position reporting with threshold of 1 unit in either axis and the Y=O origin at the top of the screen, and joystick event reporting mode for joystick 1, with both buttons being logically assigned to the mouse. After any joystick command, the ikbd assumes that joysticks are connected to both JoystickO and Joys- tickl. Any mouse command (except MOUSE DISABLE) then causes port O to again be scanned as if it were a mouse, and both buttons are logically connected to it. If a mouse disable command is received while port O is presumed to be a mouse, the button is logically assigned to Joystickl (until the mouse is reenabled by another mouse command). 26 February 1985 9. ikbd Command Set This section contains a list of commands that can be sent to the ikbd. Command codes (such as 0x00) which are not specified should perform no operation (NOPs). 9.1. RESET Ox80 Ox01 N.B. The RESET command is the only two byte command understood by the ikbd. Any byte following an Ox80 command byte other than Ox0l1 is ignored (and causes the 0x80 to be ignored). A reset may also be caused by sending a break lasting at least 200 mS to the to the ikbd. Executing the RESET command returns the keyboard to its default (power-up) mode and parameter settings. It does not affect the time-of-day clock. The RESET command or function causes the ikbd to per- form a simple self-test. If the test is successful, the ikbd will send the code of OxFO within 300 mS of receipt of the RESET command (or the end of the break, or power-up). The ikbd will then scan the key matrix for any stuck (closed) keys. Any keys found closed will cause the break scan code to be generated (the break code arriving without being preceded by the make code is a flag for a key matrix error). 26 February 1985 9.2. SET MOUSE BUTTON ACTION 0x07 %00000mss ;mouse button action VS (m is presumed = 1 when in WO MOUSE KEYCODE mode) ------ NO Owx mouse button press or release Ve causes mouse position report Noe (wx only relevant if in Ne absolute mouse positioning mode) Ne -- 1 -> mouse key press causes NE absolute position report NO --- 1 -> mouse Key release causes Ne absolute position report Neo 100 = mouse buttons act like keys se This command sets how the ikbd should treat the buttons on the mouse. The default mouse button action mode is *00000000, the buttons are treated as part of the mouse log- ically. 9.3. SET RELATIVE MOUSE POSITION REPORTING 0x08 Set relative mouse position reporting. (DEFAULT) Mouse position packets are generated asynchronously by the ikbd whenever motion exceeds the setable threshold in either axis (see SET MOUSE THRESHOLD). Depending upon the mouse key mode, mouse position reports may also be generated when ei- ther mouse button is pressed or released. Otherwise the mouse buttons behave as if they were keyboard keys. 26 February 1985 9.4. SET ABSOLUTE MOUSE POSITIONING 0x09 XMSB 7X maximum (in scaled mouse clicks) XLSB YMSB 7;Y maximum (in scaled mouse clicks) YLSB Set absolute mouse position maintenance. Resets'7 the ikbd maintained X and Y coordinates. In this mode, the value of the internally maintained coordinates does NOT wrap between O and large positive numbers. Excess motion below O iS ignored. The command sets the maximum positive value that can be attained in the scaled coordinate system. Motion beyond that value is also ignored. 9.5. SET MOUSE KEYCODE MODE OxOA deltax ;distance in X clicks ; to return {LEFT} or {RIGHT} deltay ;distance in Y clicks ; to return {UP} or {DOWN} Set mouse monitoring routines to return cursor motion keycodes instead of either RELATIVE or ABSOLUTE motion records. The ikbd returns the appropriate cursor keycode after mouse travel exceeding the user specified deltas in either axis. When the keyboard is in key scan code _ wmode, mouse motion will cause the make code immediately followed by the break code. Note that this command is not affected by the mouse motion origin. 9.6. SET MOUSE THRESHOLD OxOB X ,;x threshold in mouse ticks ; (positive integers) Y zy threshold in mouse ticks ; (positive integers) This command sets the threshold before a mouse event is generated. Note that it does NOT affect the resolution of the data returned to the host. This command is valid only in RELATIVE MOUSE POSITIONING mode. The thresholds default to 1 at RESET (or power-up). 26 February 1985 9.7. SET MOUSE SCALE Ox0C X ;horizontal mouse ticks per internal X Y ,;vertical mouse ticks per internal Y This command sets the scale factor for the ABSOLUTE MOUSE POSTIONING mode. In this mode, the specified number of mouse phase changes ("clicks") must occur before the internally maintained coordinate is changed by one (indepen- dently scaled for each axis). Remember that the mouse posi- tion information is available only by interrogating the ikbd in the ABSOLUTE MOUSE POSITIONING mode unless the ikbd has been commanded to report on button press or release (see SET MOUSE BUTTON ACTION). 9.8. INTERROGATE MOUSE POSITION OxOD Returns: OxF7 ;absolute mouse position header BUTTONS OOOOxxxx --- right button down Since last interrogation -~--- right button up Since last report -<-<--- left button down Since last report ------ left button up Since last report XMSB 7x coordinate XLSB YMSB 7Y coordinate YLSB The INTERROGATE MOUSE POSITION command is valid when in the ABSOLUTE MOUSE POSITIONING mode, regardless of the set- ting of the MOUSE BUTTON ACTION. 26 February 1985 9.9. LOAD MOUSE POSITION OxOE 0x00 ;filler XMSB 7X coordinate XLSB , (in scaled coordinate system) YMSB 7Y coordinate YLSB This command allows the user to preset the internally maintained absolute mouse position. 9.10. SET Y=0 AT BOTTOM OxOF This command makes the origin of the Y axis to be at the bottom of the logical coordinate system internal to the ikbd for all relative or absolute mouse motion. This causes mouse motion toward the user to be negative in Sign and away from the user to be positive. 9.11. SET Y=O AT TOP Ox10 Makes the origin of the Y axis to be at the top of the logical coordinate system within the ikbd for all relative or absolute mouse motion. (DEFAULT) This causes mouse motion toward the user to be positive in sign and away from the user to be negative. 9.12. RESUME Ox11 Resume sending data to the host. Since any command re- ceived by the ikbd after its output has been paused also causes an implicit RESUME this command can be thought of as a NO OPERATION command. If this command is received by the ikbd and it is not PAUSEd, it is simply ignored. 26 February 1985 -~l1- 9.13. DISABLE MOUSE Ox12 All mouse event reporting is disabled (and scanning may be internally disabled). Any valid mouse mode command resumes mouse motion monitoring. (The valid mouse mode com- mands are SET RELATIVE MOUSE POSITION REPORTING, SET ABSO- LUTE MOUSE POSITIONING, and SET MOUSE KEYCODE MODE. ) N.B. If the mouse buttons have been commanded to _ act like keyboard keys, this command DOES affect their actions. 9.14. PAUSE OUTPUT Ox13 Stop sending data to the host until another valid com- mand is received. Key matrix activity is still monitored and scan codes or ASCII characters enqueued (up to the max- imum supported by the microcontroller) to be sent when the host allows the output to be resumed. If in the JOYSTICK EVENT REPORTING mode, joystick events are also queued. Mouse motion should be accumulated while the output is paused. If the ikbd is in RELATIVE MOUSE POSITION REPORTING mode, motion is accumulated beyond the normal threshold lim- its to produce the minimum number of packets necessary for transmission when output is resumed. Pressing or releasing either mouse button causes any accumulated motion to be im- mediately queued as packets, if the mouse is in RELATIVE MOUSE POSITION REPORTING mode. | Because of the limitations of the microcontroller memory this command should be used sparingly, and the output should not be shut off for more than milliseconds at a time. The output is stopped only at the end of the current "event". If the PAUSE OUTPUT command is received in the middie of a multiple byte report, the packet will still be transmitted to conclusion and then the PAUSE will take ef- fect. When the ikbd is in either the JOYSTICK MONITORING mode or the FIRE BUTTON MONITORING mode, the PAUSE OUTPUT command also temporarily stops the monitoring process (i.e. the sam- ples are not enqueued for transmission). 26 February 1985 - 12 - 9.15. SET JOYSTICK EVENT REPORTING 0x14 Enter JOYSTICK EVENT REPORTING mode (DEFAULT). Each opening or closure of a joystick switch or trigger causes a joystick event record to be generated. 9.16. SET JOYSTICK INTERROGATION MODE Ox15 Disables JOYSTICK EVENT REPORTING. Host must send in- dividual JOYSTICK INTERROGATE commands to sense joystick state. 9.17. JOYSTICK INTERROGATION 0x16 Return a record indicating the current state of the joysticks. This command is valid in either the JOYSTICK EVENT REPORTING mode or the JOYSTICK INTERROGATION MODE. 9.18. SET JOYSTICK MONITORING 0x17 rate s;time between samples in hundredths of a second Returns: (in packets of two as long as in mode) emmy --- ;JOYSTICK1 Fire button ---- ;JOYSTICKO Fire button $nnnnmmmm LTT | ---- s JOYSTICK1 state ; JOYSTICKO state Sets the ikbd to do nothing but monitor the serial com- mand line, maintain the time-of-day clock, and monitor the joystick. The rate sets the interval between joystick sam- ples. N.B. The user should not set the rate higher than the serial communications channel will allow the 2 byte packets to be transmitted. 26 February 1985 -~13- 9.19. SET FIRE BUTTON MONITORING 0x18 Returns: (as long as in mode) Sbbbbbbbb s;state of the JOYSTICK1 fire ; button packed 8 bits per byte, ; the first sample is the MSB Sets the ikbd to do nothing but monitor the serial com- mand line, maintain the time-of-day clock, and monitor the fire button on Joystick 1. The fire button is scanned at a rate that causes 8 samples to be made in the time it takes for the previous byte to be sent to the host (i.e. scan rate = 8/10 * baud rate). The sample interval should be as con- stant as possible. 9.20. SET JOYSTICK KEYCODE MODE Ox19 RX zlength of time (in tenths of seconds) until ; horizontal velocity breakpoint is reached RY zlength of time (in tenths of seconds) until ,; vertical velocity breakpoint is reached TX zlength (in tenths of seconds) of joystick closure ; until horizontal cursor key is generated before , RX has elapsed TY zlength (in tenths of seconds) of joystick closure ,; until vertical cursor key is generated before ,; RY has elapsed VX z;length (in tenths of seconds) of joystick closure ; until horizontal cursor keystrokes are generated ; after RX has elapsed VY zlength (in tenths of seconds) of joystick closure until vertical cursor keystrokes are generated after RY has elapsed In this mode, joystick O is scanned in a way that simu- lates cursor keystrokes. On initial closure, a keystroke pair (make/break) is generated. Then up to Rn tenths of seconds later, keystroke pairs are generated every Tn tenths of seconds. After the Rn breakpoint is reached, keystroke pairs are generated every Vn tenths of seconds. This pro- vides a velocity (auto-repeat) breakpoint feature. Note that by setting RX and/or RY to zero, the velocity feature can be disabled. The values of TX and TY then be- come meaningless, and the generation of cursor "keystrokes" is set by VX and VY. 26 February 1985 ~ 14 - 9.21. DISABLE JOYSTICKS Ox1A Disable the generation of any joystick events (and scanning may be internally disabled). Any valid joystick mode command resumes joystick monitoring. (The joystick mode commands are SET JOYSTICK EVENT REPORTING, SET JOYSTICK INTERROGATION MODE, SET JOYSTICK MONITORING, SET FIRE BUTTON MONITORING, and SET JOYSTICK KEYCODE MODE. ) 26 February 1985 9.22. TIME-OF-DAY CLOCK SET Ox1B YY s;year (2 least significant digits) MM smonth DD ; day hh z;hour mm sminute ss ;second All time-of-day data should be sent to the ikbd in packed BCD format. | Any digit that is not a valid BCD digit should be treated as a "don't care" and not alter that particular field of the date or time. This permits setting only some subfields of the time-of-day clock. 9.23. INTERROGATE TIME-OF-DAY CLOCK Ox1C Returns: OxFC ;time-of-day event header YY ;year (2 least significant ; digits) MM ;month DD ; day hh shour mm ;minute ss 7second All time-of-day data is sent in packed BCD format. 26 February 1985 ~ 16 - 9.24. MEMORY LOAD 0x20 ADRMSB ;address in controller ADRLSB ; memory to be loaded NUM ;number of bytes (0-128) {data} This command permits the host to load arbitrary values into the ikbd controller memory. The time between data bytes must be less than 20 mS. 9.25. MEMORY READ Ox21 ADRMSB ;address in controller ADRLSB ; memory to be read Returns: OxF6 ,;status header Ox20 ,memory access data 76 data bytes data , Starting at ADR data data data data This command permits the host to read from the ikbd controller memory. 9.26. CONTROLLER EXECUTE Ox22 ADRMSB' ;address of subroutine in ADRLSB ; controller memory to be ; called This command allows the host to command the execution of a subroutine in the ikbd controller memory. 26 February 1985 9.27. STATUS INQUIRIES status commands are formed by inclusively ORing Ox80 with the relevant SET command Example: Ox88 (or 0x89 or Ox8A) ;request mouse mode Returns: OxF6 7;status response header mode 70x08 if RELATIVE -0x09 if ABSOLUTE ;O0x0A if KEYCODE paraml °O0 if RELATIVE > XMSB X maximum if ; ABSOLUTE ;DELTAX if KEYCODE param2 -O if RELATIVE > XLSB if ABSOLUTE ;DELTAY if KEYCODE param3 70 if RELATIVE ; or KEYCODE > YMSB if ABSOLUTE param4 70 if RELATIVE > or KEYCODE 7 YLSB if ABSOLUTE O pad O The STATUS INQUIRY commands request the ikbd to return either the current mode or the parameters associated with a given command. All status reports are padded to form 8 byte long return packets. The responses to the status requests are designed so that the host may store them away (after stripping off the status report header byte) and later send them back as commands to the ikbd to restore its state. The O pad bytes will be treated as NOPs by the ikbd. 26 February 1985 ~ 18 - Valid STATUS INQUIRY commands are: 0x87 mouse button action 0x88 mouse mode 0x89 Ox8A Ox8B mouse threshold Ox8C mouse scale Ox8F mouse vertical coordinates 0x90 (returns OxOF Y=0O at bottom Ox10 Y=O at top) 0x92 mouse enable/disable (returns Ox00 enabled Ox12 disabled) 0x94 joystick mode 0x95 0x99 Ox9A joystick enable/disable (returns 0x00 enabled Ox1A disabled) It is the (host) programmer's responsibility to have only one unanswered inquiry in process at a time. STATUS INQUIRY commands are not valid if the ikbd is in JOYSTICK MONITORING mode or FIRE BUTTON MONITORING mode. 26 February 1985 - 19 - 10. Appendix A -- Scan Codes The key scan codes returned by the ikbd are chosen to Simplify the implementation of GSX. GSX Standard Keyboard Mapping Hex Keytop Ol Esc OODNATAWNE | oO br] RD! bo HODOHCKEAMEO z, tt YO) rH to bstO EP RUTAMON NO O1 ee LEFT) SHIFT QOMNK OS 26 February 1985 ~ 20 - s2Z20< a o / (RIGHT) SHIFT {NOT USED} ALT SPACE BAR CAPS LOCK Fl F2 F3 F4 F10 {NOT USED } {NOT USED } HOME UP ARROW {NOT USED } KEYPAD - LEFT ARROW {NOT USED } RIGHT ARROW KEYPAD + {NOT USED} DOWN ARROW {NOT USED} INSERT DEL {NOT USED} {NOT USED} ISO KEY UNDO HELP KEYPAD KEYPAD Ym KEYPAD KEYPAD KEYPAD WOON KEYPAD KEYPAD KEYPAD KEYPAD KEYPAD OOP KEYPAD KEYPAD NF 26 February 1985 - 21- KEYPAD 3 KEYPAD 0O KEYPAD KEYPAD ENTER 26 February 1985