sgikbd initial commit (based on a500kbd: https://github.com/jtsiomb/a500kbd)
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 30 Jun 2022 04:23:56 +0000 (07:23 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 30 Jun 2022 04:23:56 +0000 (07:23 +0300)
18 files changed:
.gitignore [new file with mode: 0644]
LICENSE [new file with mode: 0644]
README.md [new file with mode: 0644]
doc/sgi_man7_keyboard [new file with mode: 0644]
doc/sgi_man7_mouse [new file with mode: 0644]
fw/Makefile [new file with mode: 0644]
fw/src/defs.h [new file with mode: 0644]
fw/src/main.c [new file with mode: 0644]
fw/src/ps2kbd.c [new file with mode: 0644]
fw/src/ps2kbd.h [new file with mode: 0644]
fw/src/scantbl.h [new file with mode: 0644]
fw/src/serial.c [new file with mode: 0644]
fw/src/serial.h [new file with mode: 0644]
fw/src/timer.c [new file with mode: 0644]
fw/src/timer.h [new file with mode: 0644]
hw/sgikbd.lib [new file with mode: 0644]
hw/sgikbd.pro [new file with mode: 0644]
hw/sgikbd.sch [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..d6308d9
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.swp
+*.d
+*.bak
+*.bck
+*.dcm
+*-cache.lib
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..94a9ed0
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..467696b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,52 @@
+SGI - PS/2 keyboard and mouse converter
+=======================================
+
+About
+-----
+This project is a converter for connecting PS/2 keyboards and mice to old
+Silicon Graphics computers which had a proprietary keyboard/mouse interface. It
+should work on:
+
+  - 4D series machines
+  - Indigo
+  - Crimson
+  - Onyx
+
+This converter is not necessary, and will not work, for any later SGI machines,
+like the indy, O2, indigo2, Octane, and so on, because they use PS/2 keyboards
+and mice directly.
+
+It's based on an AVR atmega 88/168/328 microcontroller, which reads the PS/2
+keyboard and mouse ports, and translates scancodes and events to the protocol
+and electrical signalling used by the SGI computers. For details on the
+SGI signalling and protocols, see the copy of the keyboard and mouse manpages
+from the section 7 of the IRIX manual, under `doc/`.
+
+Directory structure:
+
+  - `hw` - hardware: kicad files and pdf schematics.
+  - `fw` - firmware for the AVR microcontroller.
+  - `doc` - relevant documentation.
+
+Project website: http://nuclear.mutantstargoat.com/hw/sgikbd
+
+The hardware design and firmware used my previous
+[a500kbd](https://github.com/jtsiomb/a500kbd) project as a base, so if you see
+any leftover references to the Amiga anywhere don't be confused.
+
+License
+-------
+Copyright (C) 2017-2022 John Tsiombikas <nuclear@mutantstargoat.com>
+
+You are free to use, reproduce, modify, and redistribute any part of this
+project, provided you make any derivative work you release, freely available
+under the same terms.
+
+Both hardware designs, and software parts of this project, are released under
+the terms of the GNU General Public License v3, or at your option any later
+version published by the Free Software Foundation. See `LICENSE` for details.
+
+To comply with the license, when releasing derivative hardware designs, you must
+provide the full EDA project files, and of course firmware/software source code.
+Releasing only images of schematics, gerbers, and firmware binaries is *not*
+sufficient for compliance.
diff --git a/doc/sgi_man7_keyboard b/doc/sgi_man7_keyboard
new file mode 100644 (file)
index 0000000..38d576d
--- /dev/null
@@ -0,0 +1,449 @@
+keyboard(7)
+
+ NAME
+
+     keyboard - keyboard specifications
+
+ DESCRIPTION
+
+     The keyboard used on the 4D series, Indigo, Crimson and Onyx systems is
+     an up-down encoded 101-key keyboard.
+
+     The keyboard connects to the main electronics cabinet through a shielded
+     partially coiled cord and is detachable at the system cabinet only.  The
+     mouse plugs into either side of the keyboard.  Ports are provided on both
+     sides of the enclosure to allow access to left-handed and right-handed
+     mouse connectors.  The keyboard cord contains low voltage direct current
+     power feeds and two serial links; one for the mouse and one for the
+     keyboard.  The keyboard serial link is bidirectional, allowing for
+     control of indicator lights and other keyboard functions.  Each time a
+     key is pressed or released, a code is sent via the keyboard serial link.
+     Every key has a different upcode and downcode.  All keys function the
+     same way, allowing the system software to use keys in any manner.  Auto-
+     repeat is the only function that treats keys differently.  When auto-
+     repeat is enabled, a subset of the keys repeat when held down.  Multiple
+     key presses/releases result in all key transitions being reported.
+
+   Electrical Interface
+     The keyboard serial I/O interface uses RS423 levels and communicates
+     asynchronously to the system at 600 baud.  The format used is one start
+     bit followed by eight data bits, an odd parity bit and one stop bit, with
+     one byte sent per key up or down transition.  The idle state and true
+     data bits for the interface are Mark level or -5V, whereas false data
+     bits and the start bit are spaces or +5V.
+
+     The pin assignments for the keyboard connector on machines with DB-15
+     connectors are shown in the following table:
+
+                            KEYBOARD CONNECTOR PINOUT
+                         ________________________________
+                         Pin |_Signal |_Description      
+                          1  | GND    | Ground
+                          2  | GND    | Ground
+                          3  | GND    | Ground
+                          4  | KTXD   | Keyboard Transmit
+                          5  | KRCD   | Keyboard Receive
+                          7  | +12Vdc | Power
+                          8  | +12Vdc | Power
+                          9  | +12Vdc | Power
+                         10  | MTXD   | Mouse Transmit
+                         11  | NC     | Reserved
+                         12  | NC     | Reserved
+                         15  | -12Vdc | Power
+
+     The pin assignments for the DB-9 keyboard connector on the Personal IRIS
+     4D/20 and 4D/25 machines are shown in the following table for both the
+     CPU connector and the connectors on the keyboard itself.  The connectors
+     on each side of the keyboard are identical, so the mouse can be attached
+     on either side.
+
+                              KEYBOARD CABLE PINOUT
+               ____________________________________________________
+               Pin |_CPU Signal |_Keyboard Signal |_Description    
+                1  | NC         | +5Vdc           | Power
+                2  | KRCD       | KTXD            | Keyboard to CPU
+                3  | NC         | -5Vdc           | Power
+                4  | -12Vdc     | -12Vdc          | Power
+                5  | MRCD       | MTXD            | Mouse to CPU
+                6  | GND        | GND             | Ground
+                7  | +12Vdc     | +12Vdc          | Power
+                8  | KTXD       | KRCD            | CPU to Keyboard
+                9  | GND        | GND             | Ground
+
+     The pin assignments for the DIN-6 keyboard connector on the CPU board of
+     some of the newer systems are shown in the following table:
+
+                              KEYBOARD CABLE PINOUT
+                         ________________________________
+                         Pin |_Signal |_Description      
+                          1  | KRCD   | Keyboard Receive
+                          2  | MRCD   | Mouse Receive
+                          3  | GND    | Ground
+                          4  | +8Vdc  | Power
+                          5  | KTXD   | Keyboard Transmit
+                          6  | -8Vdc  | Power
+
+     The pin assignments for the mouse port connector (on the keyboard, not on
+     the CPU) for keyboards with DB9 connector are shown in the following
+     table; either connector on the keyboard can be used for the mouse or for
+     the keyboard cable.
+
+                                    MOUSE PORT
+                           ____________________________
+                           Pin |_Signal |_Description  
+                            1  | +5V    | Power
+                            3  | -5V    | Power
+                            5  | MTXD   | Transmit Data
+                            9  | GND    | Ground
+
+     For machines whose keyboards have the DIN-6 connector on the keyboard, as
+     well as on the CPU, the pinout is shown in the following table.  The
+     connectors on both sides of the keyboard have identical pinout, either
+     can be used for the mouse and the cable to the CPU.
+
+                            KEYBOARD CONNECTOR PINOUT
+                         ____|________|__________________
+                         Pin |_Signal |_Description      
+
+                          1    KTXD     Keyboard Transmit
+                          2  | MTXD   | Mouse Transmit
+                          3  | GND    | Ground
+                          4  | +8Vdc  | Power
+                          5  | KRCD   | Keyboard Receive
+                          6  | NC     | Not Connected
+
+   Software Interface
+     The interface between the keyboard and the system is 600 baud
+     asynchronous.  The format used is one start bit followed by eight data
+     bits, an odd parity bit and one stop bit, with one byte sent per key up
+     or down transition.  The MSB of the byte is a 0 for a downstroke and a 1
+     for an upstroke.  Control bytes are sent to the keyboard with the same
+     speed and format.  The system software does all the processing needed to
+     support functions such as capitalization, control characters, and numeric
+     lock.  Auto-repeat for a specified set of characters can be turned on or
+     off by the system software by sending a control byte to the keyboard.
+     When auto-repeat is enabled, a pressed key begins auto-repeating after
+     0.65 seconds and repeats 28 times per second.  The keyboard initializes
+     upon power-up.  The configuration request control byte causes the
+     keyboard to send a two-byte sequence to the system.  The second byte
+     contains the eight-bit value set on a DIP switch in the keyboard.  All
+     keyboard lights (if any; some newer systems have keyboards without user
+     controllable lights) are controlled by the system software by sending
+     control bytes to the keyboard to turn them on or off.  Control bytes are
+     also used for long and short beep control and key click disable.  When
+     key click is enabled, the keys click when they are pressed.  The long
+     beep duration is 1 second and the short beep duration is 0.2 second.
+     There are three lights labeled NUM LOCK, CAPS LOCK, and SCROLL LOCK that
+     are under software control.  On older keyboards there are also four
+     general-purpose keyboard lights labeled L1 through L4.  The required
+     keycode mappings and control byte formats are shown in the following
+     tables.  Note that the legend names prefixed by two asterisks are
+     reserved and not implemented on the keyboard.  Legend names prefixed by
+     two exclamation marks do NOT have the auto-repeat enable capability.
+     Legend names prefixed by two dollar signs do NOT have the key click
+     enable capability.
+
+                          LEGENDS VS KEYCODES IN DECIMAL
+                   _____________________________________________
+                   ________Legend          |________Code        
+                            AKEY           |         10
+                            BKEY           |         35
+                            CKEY           |         27
+                            DKEY           |         17
+                            EKEY           |         16
+                            FKEY           |         18
+                            GKEY           |         25
+                            HKEY           |         26
+                            IKEY           |         39
+                            JKEY                     33
+                            KKEY           |         34
+                            LKEY           |         41
+                            MKEY           |         43
+                            NKEY           |         36
+                            OKEY           |         40
+                            PKEY           |         47
+                            QKEY           |          9
+                            RKEY           |         23
+                            SKEY           |         11
+                            TKEY           |         24
+                            UKEY           |         32
+                            VKEY           |         28
+                            WKEY           |         15
+                            XKEY           |         20
+                            YKEY           |         31
+                            ZKEY           |         19
+                           ZEROKEY         |         45
+                           ONEKEY          |          7
+                           TWOKEY          |         13
+                          THREEKEY         |         14
+                           FOURKEY         |         21
+                           FIVEKEY         |         22
+                           SIXKEY          |         29
+                          SEVENKEY         |         30
+                          EIGHTKEY         |         37
+                           NINEKEY         |         38
+
+                          LEGENDS VS KEYCODES IN DECIMAL
+                       ____________________________________
+                       ________Legend          |____Code   
+                            **!!BREAKKEY       |     0
+                            **!!SETUPKEY       |     1
+                            $$!!LEFTCTRL       |     2
+                           $$!!CAPSLOCKKEY     |     3
+                          $$!!RIGHTSHIFTKEY    |     4
+                          $$!!LEFTSHIFTKEY     |     5
+                            **!!NOSCRLKEY      |     12
+                              !!ESCKEY         |     6
+                              !!TABKEY         |     8
+                            RETURN.ENTER       |     50
+                              SPACEKEY         |     82
+                            **LINEFEEDKEY      |     59
+                            BACKSPACEKEY       |     60
+                               DELKEY          |     61
+                            SEMICOLONKEY       |     42
+                              PERIODKEY        |     51
+                              COMMAKEY         |     44
+                              QUOTEKEY"        |     49
+                           ACCENTGRAVEKEY~     |     54
+
+                              MINUSKEY               46
+                             VIRGULEKEY?       |     52
+                            BACKSLASHKEY       |     56
+                              EQUALKEY         |     53
+                           LEFTBRACKETKEY      |     48
+                           RIGHTBRACKETKEY     |     55
+                            LEFTARROWKEY       |     72
+                            DOWNARROWKEY       |     73
+                            RIGHTARROWKEY      |     79
+                             UPARROWKEY        |     80
+                                PAD0           |     58
+                                PAD1           |     57
+                                PAD2           |     63
+                                PAD3           |     64
+                                PAD4           |     62
+                                PAD5           |     68
+                                PAD6           |     69
+
+                          LEGENDS VS KEYCODES IN DECIMAL
+                      ______________________________________
+                      ________Legend          |_____Code    
+                               PAD7           |      66
+                               PAD8           |      67
+                               PAD9           |      74
+                             **PADPF1         |      71
+                             **PADPF2         |      70
+                             **PADPF3         |      78
+                             **PADPF4         |      77
+                             PADPERIOD        |      65
+                             PADMINUS         |      75
+                            **PADCOMMA        |      76
+                            !!PADENTER        |      81
+                            $$!!LEFTALT       |      83
+                           $$!!RIGHTALT       |      84
+                           $$!!RIGHTCTRL      |      85
+                                F1            |      86
+                                F2            |      87
+                                F3            |      88
+                                F4            |      89
+                                F5            |      90
+                                F6            |      91
+                                F7            |      92
+                                F8            |      93
+                                F9            |      94
+                                F10           |      95
+                                F11           |      96
+                                F12           |      97
+                          !!PRINT.SCREEN      |      98
+                          $$!!SCROLL.LOCK     |      99
+                              !!PAUSE         |     100
+
+                             !!INSERT               101
+                              !!HOME          |     102
+                             !!PAGEUP         |     103
+                               !!END          |     104
+                            !!PAGEDOWN        |     105
+                           $$!!NUM.LOCK       |     106
+                           PAD.BKSLASH/       |     107
+
+                          LEGENDS VS KEYCODES IN DECIMAL
+                       ____________________________________
+                       __________Legend            |__Code 
+                               PAD.ASTER*          |  108
+                                PAD.PLUS+          |  109
+                       config byte(1st of 2 bytes) |  110
+                       config byte(2nd of 2 bytes) | DIP SW
+                               GERlessThan         |  111
+                                 spare1            |  112
+                                 spare2            |  113
+                                 spare3            |  114
+                                 spare4            |  115
+                                 spare6            |  117
+                                 spare7            |  118
+                                 spare8            |  119
+                                 spare9            |  120
+                                 spare10           |  121
+
+                          KEYCODES IN DECIMAL VS LEGENDS
+                       ____________________________________
+                       ___Code    |_________Legend         
+                           0      |       **BREAKKEY
+                           1      |      **!!SETUPKEY
+                           2      |      $$!!LEFTCTRL
+                           3      |     $$!!CAPSLOCKKEY
+                           4      |    $$!!RIGHTSHIFTKEY
+                           5      |    $$!!LEFTSHIFTKEY
+                           6      |        !!ESCKEY
+                           7      |         ONEKEY
+                           8      |        !!TABKEY
+                           9      |          QKEY
+                           10     |          AKEY
+                           11     |          SKEY
+                           12     |      **!!NOSCRLKEY
+                           13     |         TWOKEY
+                           14     |        THREEKEY
+                           15     |          WKEY
+                           16     |          EKEY
+                           17     |          DKEY
+                           18     |          FKEY
+                           19     |          ZKEY
+                           20     |          XKEY
+
+                           21               FOURKEY
+                           22     |         FIVEKEY
+                           23     |          RKEY
+                           24     |          TKEY
+                           25     |          GKEY
+                           26     |          HKEY
+                           27     |          CKEY
+                           28     |          VKEY
+                           29     |         SIXKEY
+                           30     |        SEVENKEY
+                           31     |          YKEY
+                           32     |          UKEY
+                           33     |          JKEY
+                           34     |          KKEY
+                           35     |          BKEY
+
+                          KEYCODES IN DECIMAL VS LEGENDS
+                      ______________________________________
+                      ____Code     |_________Legend         
+                           36      |          NKEY
+                           37      |        EIGHTKEY
+                           38      |         NINEKEY
+                           39      |          IKEY
+                           40      |          OKEY
+                           41      |          LKEY
+                           42      |      SEMICOLONKEY
+                           43      |          MKEY
+                           44      |        COMMAKEY
+                           45      |         ZEROKEY
+                           46      |        MINUSKEY
+                           47      |          PKEY
+                           48      |       LEFTBRACKET
+                           49      |        QUOTEKEY
+                           50      |      RETURN.ENTER
+                           51      |        PERIODKEY
+                           52      |       VIRGULEKEY
+                           53      |        EQUALKEY
+                           54      |     ACCENTGRAVEKEY
+                           55      |     RIGHTBRACKETKEY
+                           56      |      BACKSLASHKEY
+                           57      |        PADONEKEY
+                           58      |       PADZEROKEY
+                           59      |      **LINEFEEDKEY
+                           60      |      BACKSPACEKEY
+                           61      |        DELETEKEY
+                           62      |       PADFOURKEY
+                           63      |        PADTWOKEY
+                           64      |       PADTHREEKEY
+                           65      |      PADPERIODKEY
+                           66      |       PADSEVENKEY
+
+                           67              PADEIGHTKEY
+                           68      |       PADFIVEKEY
+                           69      |        PADSIXKEY
+                           70      |       **PADPF2KEY
+                           71      |       **PADPF1KEY
+
+                          KEYCODES IN DECIMAL VS LEGENDS
+                      ______________________________________
+                      ____Code     |_________Legend         
+                           72      |      LEFTARROWKEY
+                           73      |      DOWNARROWKEY
+                           74      |       PADNINEKEY
+                           75      |       PADMINUSKEY
+                           76      |      **PADCOMMAKEY
+                           77      |       **PADPF4KEY
+                           78      |       **PADPF3KEY
+                           79      |      RIGHTARROWKEY
+                           80      |       UPARROWKEY
+                           81      |      !!PADENTERKEY
+                           82      |        SPACEKEY
+                           83      |       $$!!LEFTALT
+                           84      |      $$!!RIGHTALT
+                           85      |      $$!!RIGHTCTRL
+                           86      |           F1
+                           87      |           F2
+                           88      |           F3
+                           89      |           F4
+                           90      |           F5
+                           91      |           F6
+                           92      |           F7
+                           93      |           F8
+                           94      |           F9
+                           95      |           F10
+                           96      |           F11
+                           97      |           F12
+                           98      |     !!PRINT.SCREEN
+                           99      |     $$!!SCROLL.LOCK
+                          100      |         !!PAUSE
+                          101      |        !!INSERT
+                          102      |         !!HOME
+                          103      |        !!PAGEUP
+                          104      |          !!END
+                          105      |       !!PAGEDOWN
+                          106      |      $$!!NUM.LOCK
+                          107      |      PAD.BKSLASH/
+
+                          KEYCODES IN DECIMAL VS LEGENDS
+                       ____________________________________
+                       _Code  |___________Legend           
+                        108   |         PAD.ASTER*
+
+                        109              PAD.PLUS+
+                        110   | config byte(1st of 2 bytes)
+                       DIP SW | config byte(2nd of 2 bytes)
+
+                       CONTROL BYTES RECOGNIZED BY KEYBOARD
+             _________________________________________________________
+             BIT  |                    DESCRIPTION
+             TRUE |_________BIT 0 = 0         |_______BIT 0 = 1       
+              1   |        short beep         | complement ds1 and ds2
+              2   |         long beep         |          ds3
+              3   |       click disable       |          ds4
+              4   | return configuration byte |          ds5
+              5   |            ds1            |          ds6
+              6   |            ds2            |          ds7
+              7   |    enable auto-repeat     |        not used
+
+                                  DISPLAY LABELS
+                         _________________________________
+                         DISPLAY DESIGNATION |____LABEL   
+                                 ds1         |  NUM LOCK
+                                 ds2         |  CAPS LOCK
+                                 ds3         | SCROLL LOCK
+                                 ds4         |     L1
+                                 ds5         |     L2
+                                 ds6         |     L3
+                                 ds7         |     L4
+
+ NOTE
+
+     Indy, Indigo2, O2, OCTANE and Onyx2 use a PS/2 style keyboard (detailed
+     in pckeyboard(7)) that uses a different scan code set.  This difference
+     may break compatibility for some programs that operate with raw scan
+     codes.
+
+ SEE ALSO
+
+     keyboard(1), mouse(7), pckeyboard(7), pcmouse(7).
diff --git a/doc/sgi_man7_mouse b/doc/sgi_man7_mouse
new file mode 100644 (file)
index 0000000..ee216cd
--- /dev/null
@@ -0,0 +1,41 @@
+mouse(7)
+
+ NAME
+
+     mouse - mouse specifications
+
+ DESCRIPTION
+
+     A serial mouse is used on the SGI 4D series, Indigo, Crimson and Onyx
+     systems.  This mouse differs from other systems which use the mouse
+     described in pcmouse(7).
+
+   Signals
+     The serial data interface signal level is compatible with RS-423, which
+     has roughly a 10V swing centered about ground.  The idle state and true
+     data bits for the interface are Mark level or -5V whereas false data bits
+     and the start bit are spaces or +5V.  The serial data is transmitted at
+     4800 baud with one start bit, eight data bits, and no parity.
+
+   Protocol
+     The mouse provides a five-byte data block whenever there is a change of
+     position or button state.  The first byte is a sync byte that has its
+     upper five bits set to 10000 and its lower three bits indicating the
+     button states where a 0 indicates depression.  The sync byte looks like
+     this: 10000LMR.  The next four bytes contain two difference updates of
+     the mouse's change in position: X1, Y1, X2, and Y2.  Positive values
+     indicate movement to the right or upward.  System software ignores bytes
+     beyond the first five until reception of the next sync byte.
+
+   Pinout
+     The pinout of the mouse connector on the keyboard is on the keyboard(7)
+     reference page.
+
+ NOTE
+
+     Indy, Indigo2, O2, OCTANE and Onyx2 use a PS/2 style mouse, which is
+     described in pcmouse(7).
+
+ SEE ALSO
+
+     keyboard(7), pckeyboard(7), pcmouse(7).
diff --git a/fw/Makefile b/fw/Makefile
new file mode 100644 (file)
index 0000000..76aa14b
--- /dev/null
@@ -0,0 +1,38 @@
+src = $(wildcard src/*.c)
+obj = $(src:.c=.o)
+bin = sgikbd
+hex = $(bin).hex
+eep = $(bin).eep
+
+mcu_gcc = atmega168
+mcu_dude = m168
+
+CC = avr-gcc
+OBJCOPY = avr-objcopy
+
+CFLAGS = -Os -pedantic -Wall -mmcu=$(mcu_gcc) -DF_CPU=14745600
+LDFLAGS = -Wl,-Map,$(bin).map -mmcu=$(mcu_gcc) -lprintf_min
+
+.PHONY: all
+all: $(hex) $(eep)
+
+$(bin): $(obj)
+       $(CC) -o $@ $(obj) $(LDFLAGS)
+
+$(hex): $(bin)
+       $(OBJCOPY) -j .text -j .data -O ihex -R .eeprom $< $@
+
+$(eep): $(bin)
+       $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
+
+.PHONY: fuses
+fuses:
+       avrdude -c usbtiny -p $(mcu_dude) -U lfuse:w:0xe6:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m
+
+.PHONY: program
+program: $(hex)
+       avrdude -c usbtiny -p $(mcu_dude) -e -U flash:w:$(hex)
+
+.PHONY: clean
+clean:
+       rm -f $(bin) $(obj) $(hex) $(eep) $(bin).map
diff --git a/fw/src/defs.h b/fw/src/defs.h
new file mode 100644 (file)
index 0000000..8fe204e
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef DEFS_H_
+#define DEFS_H_
+
+#include <avr/io.h>
+
+/* pin assignments:
+ * D2  PS/2 clock (INT0)
+ * D3  amikbd clock (INT1)
+ * D4  PS/2 data
+ * D5  amikbd data
+ * D6  amiga reset
+ * D7  amiga drvled in
+ */
+
+#define PCLK   2
+#define ACLK   3
+#define PDATA  4
+#define ADATA  5
+#define ARST   6
+#define ADRVLED        7
+
+#define PCLK_BIT       (1 << PCLK)
+#define ACLK_BIT       (1 << ACLK)
+#define PDATA_BIT      (1 << PDATA)
+#define ADATA_BIT      (1 << ADATA)
+#define ARST_BIT       (1 << ARST)
+#define ADRVLED_BIT    (1 << ADRVLED)
+
+#endif /* DEFS_H_ */
diff --git a/fw/src/main.c b/fw/src/main.c
new file mode 100644 (file)
index 0000000..9563de4
--- /dev/null
@@ -0,0 +1,152 @@
+#include <stdio.h>
+#include <ctype.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include "serial.h"
+#include "scantbl.h"
+#include "ps2kbd.h"
+#include "amigakb.h"
+#include "defs.h"
+#include "timer.h"
+
+enum {
+       KF_BRK = 1,
+       KF_EXT = 2,
+       KF_EXT1 = 4,
+
+       KF_CTRL         = 16,
+       KF_LAMIGA       = 32,
+       KF_RAMIGA       = 64
+};
+#define KF_TRANSIENT   0x0f
+#define KF_STICKY              0xf0
+
+#define RESET_WAIT 1000
+
+static unsigned char led_state;
+
+int main(void)
+{
+       unsigned int keyflags = 0;
+       unsigned char c, keycode, prev_drvled = 0;
+       int press;
+
+       /* disable all pullups globally */
+       MCUCR |= 1 << PUD;
+
+       DDRD = 0;
+       PORTD = 0;
+       EIMSK = 0;      /* mask external interrupts */
+       EICRA = (1 << ISC11) | (1 << ISC01);    /* falling edge interrupts */
+
+       init_timer();
+
+       /* initialize the UART and enable interrupts */
+       init_serial(9600);
+       sei();
+
+       printf("PS/2 keyboard controller - John Tsiombikas <nuclear@member.fsf.org>\r\n");
+
+       EIMSK = (1 << INT0) | (1 << INT1);      /* enable ps/2 clock interrupt */
+
+       ps2setled(0);   /* start with all LEDs off */
+
+       for(;;) {
+               while(!ps2pending()) {
+                       unsigned char drvled = PIND & ADRVLED_BIT;
+                       if(drvled != prev_drvled) {
+                               prev_drvled = drvled;
+                               if(drvled) {
+                                       led_state |= PS2LED_SCRLK;
+                               } else {
+                                       led_state &= ~PS2LED_SCRLK;
+                               }
+                               ps2setled(led_state);
+                       }
+               }
+
+               c = ps2read();
+               switch(c) {
+               case 0xe0:      /* extended */
+                       keyflags |= KF_EXT;
+                       break;
+
+               case 0xe1:      /* extended */
+                       keyflags |= KF_EXT1;
+                       break;
+
+               case 0xf0:      /* break code */
+                       keyflags |= KF_BRK;
+                       break;
+
+               default:
+                       press = !(keyflags & KF_BRK);
+
+                       keycode = 0xff;
+                       if(keyflags & KF_EXT) {
+                               if(c < KEYMAP_EXT_SIZE) {
+                                       keycode = keymap_ext[(int)c];
+                               }
+                       } else if(keyflags & KF_EXT1) {
+                       } else {
+                               if(c < KEYMAP_NORMAL_SIZE) {
+                                       keycode = keymap_normal[(int)c];
+                               }
+                       }
+
+                       switch(keycode) {
+                       case AMIKEY_CTRL:
+                               if(press)
+                                       keyflags |= KF_CTRL;
+                               else
+                                       keyflags &= ~KF_CTRL;
+                               break;
+
+                       case AMIKEY_LAMI:
+                               if(press)
+                                       keyflags |= KF_LAMIGA;
+                               else
+                                       keyflags &= ~KF_LAMIGA;
+                               break;
+
+                       case AMIKEY_RAMI:
+                               if(press)
+                                       keyflags |= KF_RAMIGA;
+                               else
+                                       keyflags &= ~KF_RAMIGA;
+                               break;
+
+                       default:
+                               break;
+                       }
+
+                       if((keyflags & (KF_CTRL | KF_RAMIGA | KF_LAMIGA)) == (KF_CTRL | KF_RAMIGA | KF_LAMIGA)) {
+                               printf("CTRL - AMIGA - AMIGA!\r\n");
+                               amikb_reset();
+
+                               keyflags = 0;
+
+                               reset_timer();
+                               while(get_msec() < RESET_WAIT);
+                               ps2clearbuf();
+
+                               break;
+                       }
+
+                       if(keycode != 0xff) {
+                               int press = ~keyflags & KF_BRK;
+                               amikb_sendkey(keycode, press);
+                               if(keycode == 0x62 && press) {
+                                       led_state ^= PS2LED_CAPSLK;
+                                       ps2setled(led_state);
+                               }
+                               /*printf("scancode %x -> [%s] amiga key %xh\r\n", (unsigned int)c, press ? "press" : "release", keycode);*/
+                       } else {
+                               printf("PS/2 unknown command or keycode: %x\r\n", (unsigned int)c);
+                       }
+                       keyflags &= ~KF_TRANSIENT;
+               }
+       }
+       return 0;
+}
diff --git a/fw/src/ps2kbd.c b/fw/src/ps2kbd.c
new file mode 100644 (file)
index 0000000..98d2ae1
--- /dev/null
@@ -0,0 +1,199 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include "ps2kbd.h"
+#include "defs.h"
+#include "timer.h"
+
+#define TIMEOUT        100
+
+#define BUF_SZ 32
+#define BUF_IDX_MASK   (BUF_SZ - 1)
+#define NEXT_IDX(x) (((x) + 1) & BUF_IDX_MASK)
+static volatile unsigned char keybuf[BUF_SZ];
+static volatile unsigned char key_rd, key_wr;
+
+static volatile int send_nbits, wait_ack;
+static volatile unsigned char send_val, send_par;
+
+static void abort_send(void);
+
+int ps2write(unsigned char c)
+{
+       cli();
+       send_nbits = 10;
+       send_val = c;
+       send_par = 0;   /* init to 0, will be calculated while sending */
+
+       /* inhibit transmission, hold at least 100us */
+       PORTD &= ~PCLK_BIT;
+       DDRD |= PCLK_BIT;
+       EIFR |= (1 << INTF0);   /* clear pending interrupt due to clock transition */
+       sei();
+       _delay_us(100);
+
+       /* RTS by data low & release clock (this counts as start bit?) */
+       PORTD &= ~PDATA_BIT;
+       DDRD |= PDATA_BIT;
+       DDRD &= ~PCLK_BIT;
+
+       reset_timer();
+       while(send_nbits > 0) {
+               if(get_msec() > TIMEOUT) {
+                       abort_send();
+                       return -1;
+               }
+       }
+       _delay_us(5);
+
+       /* release data line and wait for ack */
+       cli();
+       wait_ack = 1;
+       sei();
+       DDRD &= ~PDATA_BIT;
+       reset_timer();
+       while(wait_ack) {
+               if(get_msec() > TIMEOUT) {
+                       abort_send();
+                       return -1;
+               }
+       }
+       return 0;
+}
+
+static void abort_send(void)
+{
+       cli();
+       send_nbits = 0;
+       wait_ack = 0;
+       /* hold clock low for 100us */
+       PORTD &= ~PCLK_BIT;
+       DDRD |= PCLK_BIT;
+       _delay_us(100);
+       DDRD &= ~(PCLK_BIT | PDATA_BIT);
+       EIFR |= (1 << INTF0);   /* clear pending interrupt */
+       sei();
+}
+
+unsigned char ps2read(void)
+{
+       unsigned char key;
+
+       while(key_rd == key_wr) {
+       }
+
+       cli();
+       key = keybuf[key_rd];
+       key_rd = NEXT_IDX(key_rd);
+       sei();
+
+       return key;
+}
+
+int ps2pending(void)
+{
+       return key_rd != key_wr;
+}
+
+int ps2wait(unsigned int timeout)
+{
+       reset_timer();
+       while(key_rd == key_wr) {
+               if(get_msec() >= timeout) return -1;
+       }
+       return 0;
+}
+
+#define PS2_ACK                0xfa
+#define PS2_RESEND     0xfe
+#define PS2_ECHO       0xee
+
+int ps2setled(unsigned char state)
+{
+       unsigned char c;
+
+       ps2write(0xed);
+       reset_timer();
+       while(!ps2pending()) {
+               if(get_msec() >= TIMEOUT) return -1;
+       }
+       c = ps2read();
+       /*printf("ps2setled 1st response: %x\r\n", (unsigned int)c);*/
+       if(c != PS2_ACK) return -1;
+
+       ps2write(state);
+       reset_timer();
+       while(!ps2pending()) {
+               if(get_msec() >= TIMEOUT) return -1;
+       }
+       c = ps2read();
+       /*printf("ps2setled 2nd response: %x\r\n", (unsigned int)c);*/
+       if(c != PS2_ACK) return -1;
+
+       return 0;
+}
+
+void ps2clearbuf(void)
+{
+       key_rd = key_wr;
+}
+
+ISR(INT0_vect)
+{
+       static unsigned char value, parity;
+       /*static unsigned char valp;*/
+       static int nbits;
+
+       if(wait_ack) {
+               if(!(PIND & PDATA_BIT)) {
+                       wait_ack = 0;
+               }
+               return;
+       }
+
+       if(send_nbits > 0) {
+               --send_nbits;
+               switch(send_nbits) {
+               case 1:         /* parity bit */
+                       if(send_par & 1) {      /* odd number of ones: parity 0 */
+                               PORTD &= ~PDATA_BIT;
+                       } else {        /* even number of ones: parity 1 */
+                               PORTD |= PDATA_BIT;
+                       }
+                       break;
+               case 0: /* stop bit: 1 */
+                       PORTD |= PDATA_BIT;
+                       break;
+               default:
+                       if(send_val & 1) {
+                               PORTD |= PDATA_BIT;
+                               ++send_par;
+                       } else {
+                               PORTD &= ~PDATA_BIT;
+                       }
+                       send_val >>= 1;
+               }
+
+       } else {
+               if(nbits > 0 && nbits < 9) {
+                       value >>= 1;
+                       if(PIND & PDATA_BIT) {
+                               value |= 0x80;
+                               parity ^= 1;
+                       }
+               }/* else if(nbits == 9) {
+                       valp = (PIND >> PDATA) & 1;
+               }*/
+               if(++nbits >= 11) {
+                       nbits = 0;
+
+                       /* check parity */
+                       /*if((parity & 1) == (valp & 1)) {}*/
+                       keybuf[key_wr] = (unsigned char)value;
+                       key_wr = NEXT_IDX(key_wr);
+
+                       value = 0;
+                       parity = 0;
+               }
+       }
+}
diff --git a/fw/src/ps2kbd.h b/fw/src/ps2kbd.h
new file mode 100644 (file)
index 0000000..0e79cb6
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef PS2KBD_H_
+#define PS2KBD_H_
+
+enum {
+       PS2LED_SCRLK = 1,
+       PS2LED_NUMLK = 2,
+       PS2LED_CAPSLK = 4
+};
+
+int ps2write(unsigned char c);
+unsigned char ps2read(void);
+int ps2pending(void);
+int ps2wait(unsigned int timeout);
+void ps2clearbuf(void);
+
+int ps2setled(unsigned char state);
+
+#endif /* PS2KBD_H_ */
diff --git a/fw/src/scantbl.h b/fw/src/scantbl.h
new file mode 100644 (file)
index 0000000..22828e7
--- /dev/null
@@ -0,0 +1,129 @@
+#ifndef SCANTBL_H_
+#define SCANTBL_H_
+
+/*
+enum {
+       KEY_ESC = 27,
+
+       KEY_F1 = 256,
+       KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8,
+       KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_SYSRQ, KEY_BRK,
+       KEY_SCRLK, KEY_CAPSLK, KEY_NUMLK,
+
+       KEY_LSHIFT, KEY_RSHIFT,
+       KEY_LCTRL, KEY_RCTRL,
+       KEY_LALT, KEY_RALT,
+       KEY_LWIN, KEY_RWIN, KEY_MENU,
+
+       KEY_INS, KEY_DEL, KEY_HOME, KEY_END, KEY_PGUP, KEY_PGDOWN,
+       KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
+
+       KEY_KP_0, KEY_KP_1, KEY_KP_2, KEY_KP_3, KEY_KP_4,
+       KEY_KP_5, KEY_KP_6, KEY_KP_7, KEY_KP_8, KEY_KP_9,
+       KEY_KP_DIV, KEY_KP_MUL, KEY_KP_MINUS, KEY_KP_PLUS,
+       KEY_KP_DOT, KEY_KP_ENTER,
+
+       KEY_MM_WWW_SEARCH, KEY_MM_WWW_FAV, KEY_MM_WWW_REFRESH, KEY_MM_WWW_STOP,
+       KEY_MM_WWW_FWD, KEY_MM_WWW_BACK, KEY_MM_WWW_HOME,
+       KEY_MM_PREV, KEY_MM_NEXT, KEY_MM_PLAY, KEY_MM_STOP, KEY_MM_VOLUP, KEY_MM_VOLDOWN,
+       KEY_MM_MUTE, KEY_MM_CALC, KEY_MM_MYCOMP, KEY_MM_EMAIL, KEY_MM_SELECT,
+       KEY_APPS,
+       KEY_ACPI_POWER, KEY_ACPI_SLEEP, KEY_ACPI_WAKEUP
+};
+*/
+
+#define KEYMAP_NORMAL_SIZE     (sizeof keymap_normal / sizeof *keymap_normal)
+#if 0
+static int keymap_normal[] = {
+       0, KEY_F9, 0, KEY_F5, KEY_F3, KEY_F1, KEY_F2, KEY_F12,  /* 00 - 07 */
+       0, KEY_F10, KEY_F8, KEY_F6,     KEY_F4, '\t', '`', 0,           /* 08 - 0f */
+       0, KEY_LALT, KEY_LSHIFT, 0, KEY_LCTRL, 'Q', '1', 0,             /* 10 - 17 */
+       0, 0, 'Z', 'S', 'A', 'W', '2', 0,                                               /* 18 - 1f */
+       0, 'C', 'X', 'D', 'E', '4', '3', 0,                                             /* 20 - 27 */
+       0, ' ', 'V', 'F', 'T', 'R', '5', 0,                                             /* 28 - 2f */
+       0, 'N', 'B', 'H', 'G', 'Y', '6', 0,                                             /* 30 - 37 */
+       0, 0, 'M', 'J', 'U', '7', '8', 0,                                               /* 38 - 3f */
+       0, ',', 'K', 'I', 'O', '0', '9', 0,                                             /* 40 - 47 */
+       0, '.', '/', 'L', ';', 'P', '-', 0,                                             /* 48 - 4f */
+       0, 0, '\'', 0, '[', '=', 0, 0,                                                  /* 50 - 57 */
+       KEY_CAPSLK, KEY_RSHIFT, '\n', ']', 0, '\\', 0, 0,               /* 58 - 5f */
+       0, 0, 0, 0, 0, 0, '\b', 0,                                                              /* 60 - 67 */
+       0, KEY_KP_1, 0, KEY_KP_4, KEY_KP_7, 0, 0, 0,                            /* 68 - 6f */
+       KEY_KP_0, KEY_KP_DOT, KEY_KP_2, KEY_KP_5, KEY_KP_6, KEY_KP_8, KEY_ESC, KEY_NUMLK, /* 70 - 77 */
+       KEY_F11, KEY_KP_PLUS, KEY_KP_3, KEY_KP_MINUS, KEY_KP_MUL, KEY_KP_9, KEY_SCRLK, 0,/* 78 - 7f */
+       0, 0, 0, KEY_F7                                                                                 /* 80 - 83 */
+};
+#endif
+
+/* converts a normal (non-extended) PS/2 scancode to an amiga rawkey value
+ * caps lock -> control
+ * ctrl -> amiga
+ * F12 -> help
+ */
+static unsigned char keymap_normal[] = {
+       0xff, 0x58, 0xff, 0x54, 0x52, 0x50, 0x51, 0x5f,         /* 00 - 07: - f9 - f5 f3 f1 f2 f12 */
+       0xff, 0x59, 0x57, 0x55, 0x53, 0x42, 0x00, 0xff,         /* 08 - 0f: - f10 f8 f6 f4 tab ` - */
+       0xff, 0x64, 0x60, 0xff, 0x66, 0x10, 0x01, 0xff,         /* 10 - 17: - lalt lshift - lctrl(lamiga) Q 1 - */
+       0xff, 0xff, 0x31, 0x21, 0x20, 0x11, 0x02, 0xff,         /* 18 - 1f: - - Z S A W 2 - */
+       0xff, 0x33, 0x32, 0x22, 0x12, 0x04, 0x03, 0xff,         /* 20 - 27: - C X D E 4 3 - */
+       0xff, 0x40, 0x34, 0x23, 0x14, 0x13, 0x05, 0xff,         /* 28 - 2f: - space V F T R 5 - */
+       0xff, 0x36, 0x35, 0x25, 0x24, 0x15, 0x06, 0xff,         /* 30 - 37: - N B H G Y 6 - */
+       0xff, 0xff, 0x37, 0x26, 0x16, 0x07, 0x08, 0xff,         /* 38 - 3f: - - M J U 7 8 - */
+       0xff, 0x38, 0x27, 0x17, 0x18, 0x0a, 0x09, 0xff,         /* 40 - 47: - , K I O 0 9 - */
+       0xff, 0x39, 0x3a, 0x28, 0x29, 0x19, 0x0b, 0xff,         /* 48 - 4f: - . / L ; P minus - */
+       0xff, 0xff, 0x2a, 0xff, 0x1a, 0x0c, 0xff, 0xff,         /* 50 - 57: - - \ - [ = - - */
+       0x63, 0x61, 0x44, 0x1b, 0xff, 0x0d, 0xff, 0xff,         /* 58 - 5f: caps rshift enter ] - \ - - */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x41, 0xff,         /* 60 - 67: - - - - - - backsp - */
+       0xff, 0x1d, 0xff, 0x2d, 0x3d, 0xff, 0xff, 0xff,         /* 68 - 6f: - KP1 - KP4 KP7 - - - */
+       0x0f, 0x3c, 0x1e, 0x2e, 0x2f, 0x3e, 0x45, 0x5a,         /* 70 - 77: KP0 KP. KP2 KP5 KP6 KP8 esc numlk */
+       0xff, 0x5e, 0x1f, 0x4a, 0x5d, 0x3f, 0x62, 0xff,         /* 78 - 7f: f11 KP+ KP3 KP- KP* KP9 scrlk(capslock) - */
+       0xff, 0xff, 0xff, 0x56                                                          /* 80 - 83: - - - f7 */
+};
+
+#define KEYMAP_EXT_SIZE        (sizeof keymap_ext / sizeof *keymap_ext)
+#if 0
+static int keymap_ext[] = {
+       0, 0, 0, 0, 0, 0, 0, 0,                                                                 /* 00 - 07 */
+       0, 0, 0, 0, 0, 0, 0, 0,                                                                 /* 08 - 0f */
+       KEY_MM_WWW_SEARCH, KEY_RALT, 0, 0, KEY_RCTRL, KEY_MM_PREV, 0, 0,        /* 10 - 17 */
+       KEY_MM_WWW_FAV, 0, 0, 0, 0, 0, 0, KEY_LWIN,                             /* 18 - 1f */
+       KEY_MM_WWW_REFRESH, KEY_MM_VOLDOWN, 0, KEY_MM_MUTE, 0, 0, 0, KEY_RWIN,  /* 20 - 27 */
+       KEY_MM_STOP, 0, 0, KEY_MM_CALC, 0, 0, 0, KEY_APPS,              /* 28 - 2f */
+       KEY_MM_WWW_FWD, 0, KEY_MM_VOLUP, 0, KEY_MM_PLAY, 0, 0, KEY_ACPI_POWER,  /* 30 - 37 */
+       KEY_MM_WWW_BACK, 0, KEY_MM_WWW_HOME, KEY_MM_STOP, 0, 0, 0, KEY_ACPI_SLEEP,      /* 38 - 3f */
+       KEY_MM_MYCOMP, 0, 0, 0, 0, 0, 0, 0,                                             /* 40 - 47 */
+       KEY_MM_EMAIL, 0, KEY_KP_DIV, 0, 0, KEY_MM_NEXT, 0, 0,   /* 48 - 4f */
+       KEY_MM_SELECT, 0, 0, 0, 0, 0, 0, 0,                                             /* 50 - 57 */
+       0, 0, KEY_KP_ENTER, 0, 0, 0, KEY_ACPI_WAKEUP, 0,                /* 58 - 5f */
+       0, 0, 0, 0, 0, 0, 0, 0,                                                                 /* 60 - 67 */
+       0, KEY_END, 0, KEY_LEFT, KEY_HOME, 0, 0, 0,                             /* 68 - 6f */
+       KEY_INS, KEY_DEL, KEY_DOWN, 0, KEY_RIGHT, KEY_UP, 0, 0, /* 70 - 77 */
+       0, 0, KEY_PGDOWN, 0, 0, KEY_PGUP, 0, 0,                                 /* 78 - 7f */
+};
+#endif
+
+static unsigned char keymap_ext[] = {
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 00 - 07: - - - - - - - - */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 08 - 0f: - - - - - - - - */
+       0xff, 0x65, 0xff, 0xff, 0x67, 0xff, 0xff, 0xff,         /* 10 - 17: - ralt - - rctrl(ramiga) - - - */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x66,         /* 18 - 1f: - - - - - - - lwin(lamiga) */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x67,         /* 20 - 27: - - - - - - - rwin(ramiga) */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 28 - 2f */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 30 - 37 */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 38 - 3f */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 40 - 47 */
+       0xff, 0xff, 0x5c, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 48 - 4f: - - KP/ - - - - - */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 50 - 57 */
+       0xff, 0xff, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 58 - 5f: - - KP_enter - - - - - */
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,         /* 60 - 67 */
+       0xff, 0x1d, 0xff, 0x4f, 0x3d, 0xff, 0xff, 0xff,         /* 68 - 6f: - end - left home - - - */
+       0x0f, 0x46, 0x4d, 0xff, 0x4e, 0x4c, 0xff, 0xff,         /* 70 - 77: ins del down - right up - - */
+       0xff, 0xff, 0x1f, 0xff, 0xff, 0x3f, 0xff, 0xff          /* 78 - 7f: - - pgdown - - pgup - - */
+};
+
+/* some useful keycodes */
+#define AMIKEY_CTRL            0x63
+#define AMIKEY_LAMI            0x66
+#define AMIKEY_RAMI            0x67
+
+#endif /* SCANTBL_H_ */
diff --git a/fw/src/serial.c b/fw/src/serial.c
new file mode 100644 (file)
index 0000000..e318b68
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef F_CPU
+#ifdef XTAL
+#define F_CPU  XTAL
+#else
+#warning "compiled for 1mhz internal rc osc. serial comms won't work"
+#define F_CPU  1000000
+#endif
+#endif
+
+#include <stdio.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/power.h>
+
+static int uart_send_char(char c, FILE *fp);
+static int uart_get_char(FILE *fp);
+
+#define BUF_SZ 16
+#define BUF_IDX_MASK   (BUF_SZ - 1)
+#define NEXT_IDX(x)    (((x) + 1) & BUF_IDX_MASK)
+static char outbuf[BUF_SZ];
+static volatile unsigned char out_rd, out_wr;
+static char inbuf[BUF_SZ];
+static volatile unsigned char in_rd, in_wr;
+
+static FILE std_stream = FDEV_SETUP_STREAM(uart_send_char, uart_get_char, _FDEV_SETUP_RW);
+
+
+
+void init_serial(long baud)
+{
+       unsigned int ubrr_val = F_CPU / 16 / baud - 1;
+
+       power_usart0_enable();
+
+       /* set baud generator timer reset value */
+       UBRR0H = (unsigned char)(ubrr_val >> 8);
+       UBRR0L = (unsigned char)ubrr_val;
+
+       /* enable rx/tx and recv interrupt */
+       UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
+       /* set frame format: 8n1 */
+       UCSR0C = 3 << UCSZ00;
+
+       stdin = stdout = stderr = &std_stream;
+}
+
+int have_input(void)
+{
+       return in_wr != in_rd;
+}
+
+static int uart_send_char(char c, FILE *fp)
+{
+       /*int next;*/
+
+       while((UCSR0A & (1 << UDRE0)) == 0);
+       UDR0 = (unsigned char)c;
+#if 0
+       next = NEXT_IDX(out_wr);
+       while(next == out_rd);
+
+       outbuf[out_wr] = c;
+       out_wr = next;
+
+       /* enable the Tx data register empty interrupt */
+       UCSR0B |= 1 << UDRIE0;
+#endif
+       return 0;
+}
+
+static int uart_get_char(FILE *fp)
+{
+       char c;
+
+       while(in_rd == in_wr);
+
+       c = inbuf[in_rd];
+       in_rd = NEXT_IDX(in_rd);
+       return c;
+}
+
+ISR(USART_RX_vect)
+{
+       char c = UDR0;
+
+       inbuf[in_wr] = c;
+       in_wr = NEXT_IDX(in_wr);
+}
+
+/* USART Tx data register empty (can send more data) */
+ISR(USART_UDRE_vect)
+{
+       if(out_rd != out_wr) {
+               UDR0 = outbuf[out_rd];
+               out_rd = NEXT_IDX(out_rd);
+       } else {
+               /* no more data to send for now, disable the interrupt */
+               UCSR0B &= ~(1 << UDRIE0);
+       }
+}
diff --git a/fw/src/serial.h b/fw/src/serial.h
new file mode 100644 (file)
index 0000000..615626e
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef SERIAL_H_
+#define SERIAL_H_
+
+void init_serial(long baud);
+int have_input(void);
+
+#endif /* SERIAL_H_ */
diff --git a/fw/src/timer.c b/fw/src/timer.c
new file mode 100644 (file)
index 0000000..c73326e
--- /dev/null
@@ -0,0 +1,35 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/power.h>
+#include "timer.h"
+
+#define PRESCL_256     4
+/* 256 ticks per interrupt, 256 clock divisor */
+#define TICKS_PER_SEC  (F_CPU / 256 / 256)
+
+static volatile unsigned long ticks;
+
+void init_timer(void)
+{
+       power_timer0_enable();
+
+       TCCR0A = 0;
+       TCCR0B = PRESCL_256;
+
+       TIMSK0 |= (1 << TOIE0); /* enable ovf intr. */
+}
+
+void reset_timer(void)
+{
+       ticks = 0;
+}
+
+unsigned long get_msec(void)
+{
+       return 1000 * ticks / TICKS_PER_SEC;
+}
+
+ISR(TIMER0_OVF_vect)
+{
+       ++ticks;
+}
diff --git a/fw/src/timer.h b/fw/src/timer.h
new file mode 100644 (file)
index 0000000..76a4ad1
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef TIMER_H_
+#define TIMER_H_
+
+void init_timer(void);
+void reset_timer(void);
+unsigned long get_msec(void);
+
+#endif /* TIMER_H_ */
diff --git a/hw/sgikbd.lib b/hw/sgikbd.lib
new file mode 100644 (file)
index 0000000..35a5402
--- /dev/null
@@ -0,0 +1,39 @@
+EESchema-LIBRARY Version 2.3
+#encoding utf-8
+#
+# a500kbd_conn
+#
+DEF a500kbd_conn U 0 40 Y Y 1 F N
+F0 "U" -250 -400 60 H V C CNN
+F1 "a500kbd_conn" 250 50 60 V V C CNN
+F2 "" 300 -650 60 H I C CNN
+F3 "" 300 -650 60 H I C CNN
+DRAW
+S -300 250 200 -350 0 1 0 N
+X CLK 1 -500 100 200 R 50 50 1 1 P
+X DATA 2 -500 200 200 R 50 50 1 1 P
+X RESET 3 -500 -50 200 R 50 50 1 1 P
+X +5v 4 100 450 200 D 50 50 1 1 P
+X GND 6 100 -550 200 U 50 50 1 1 P
+X STLED 7 -500 -200 200 R 50 50 1 1 P
+X DRVLED 8 -500 -300 200 R 50 50 1 1 P
+ENDDRAW
+ENDDEF
+#
+# ps2conn
+#
+DEF ps2conn U 0 40 Y Y 1 F N
+F0 "U" -250 -250 60 H V C CNN
+F1 "ps2conn" 150 0 60 V V C CNN
+F2 "" 0 0 60 H I C CNN
+F3 "" 0 0 60 H I C CNN
+DRAW
+S -300 200 100 -200 0 1 0 N
+X DATA 1 -500 100 200 R 50 50 1 1 P
+X GND 3 0 -400 200 U 50 50 1 1 P
+X VCC 4 0 400 200 D 50 50 1 1 P
+X CLK 5 -500 -100 200 R 50 50 1 1 P
+ENDDRAW
+ENDDEF
+#
+#End Library
diff --git a/hw/sgikbd.pro b/hw/sgikbd.pro
new file mode 100644 (file)
index 0000000..2c35962
--- /dev/null
@@ -0,0 +1,30 @@
+update=Mon 05 Oct 2020 01:13:11 PM EEST
+version=1
+last_client=kicad
+[pcbnew]
+version=1
+LastNetListRead=
+UseCmpFile=1
+PadDrill=0.600000000000
+PadDrillOvalY=0.600000000000
+PadSizeH=1.500000000000
+PadSizeV=1.500000000000
+PcbTextSizeV=1.500000000000
+PcbTextSizeH=1.500000000000
+PcbTextThickness=0.300000000000
+ModuleTextSizeV=1.000000000000
+ModuleTextSizeH=1.000000000000
+ModuleTextSizeThickness=0.150000000000
+SolderMaskClearance=0.000000000000
+SolderMaskMinWidth=0.000000000000
+DrawSegmentWidth=0.200000000000
+BoardOutlineThickness=0.100000000000
+ModuleOutlineThickness=0.150000000000
+[cvpcb]
+version=1
+NetIExt=net
+[general]
+version=1
+[eeschema]
+version=1
+LibDir=
diff --git a/hw/sgikbd.sch b/hw/sgikbd.sch
new file mode 100644 (file)
index 0000000..488d10c
--- /dev/null
@@ -0,0 +1,609 @@
+EESchema Schematic File Version 4
+EELAYER 30 0
+EELAYER END
+$Descr A4 11693 8268
+encoding utf-8
+Sheet 1 1
+Title "SGI - PS/2 keyboard and mouse converter"
+Date "2017-10-11"
+Rev "1"
+Comp "Mutant Stargoat"
+Comment1 "Creative Commons Attribution Share-Alike (CC BY-SA)"
+Comment2 "Copyright (C) 2017-2022 John Tsiombikas <nuclear@member.fsf.org>"
+Comment3 ""
+Comment4 ""
+$EndDescr
+$Comp
+L sgikbd-rescue:ps2conn U3
+U 1 1 59DD9993
+P 7700 3950
+F 0 "U3" H 7450 3700 60  0000 C CNN
+F 1 "ps2conn" V 7850 3950 60  0000 C CNN
+F 2 "" H 7700 3950 60  0001 C CNN
+F 3 "" H 7700 3950 60  0001 C CNN
+       1    7700 3950
+       0    1    -1   0   
+$EndComp
+$Comp
+L sgikbd-rescue:ATMEGA88-20PU U1
+U 1 1 59DD9A9D
+P 4800 3800
+F 0 "U1" H 3950 5100 50  0000 L BNN
+F 1 "ATMEGA88-20PU" H 5150 2450 50  0000 L BNN
+F 2 "DIL28" H 4800 3800 50  0001 C CIN
+F 3 "" H 4800 3800 50  0001 C CNN
+       1    4800 3800
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:GND #PWR12
+U 1 1 59DD9D4A
+P 7100 3950
+F 0 "#PWR12" H 7100 3700 50  0001 C CNN
+F 1 "GND" H 7100 3800 50  0000 C CNN
+F 2 "" H 7100 3950 50  0001 C CNN
+F 3 "" H 7100 3950 50  0001 C CNN
+       1    7100 3950
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:VCC #PWR14
+U 1 1 59DD9DD3
+P 8100 3950
+F 0 "#PWR14" H 8100 3800 50  0001 C CNN
+F 1 "VCC" H 8100 4100 50  0000 C CNN
+F 2 "" H 8100 3950 50  0001 C CNN
+F 3 "" H 8100 3950 50  0001 C CNN
+       1    8100 3950
+       1    0    0    -1  
+$EndComp
+Text Label 5800 4450 0    60   ~ 0
+PCLK
+$Comp
+L sgikbd-rescue:AVR-ISP-6 CON1
+U 1 1 59DD9E89
+P 6750 3150
+F 0 "CON1" H 6645 3390 50  0000 C CNN
+F 1 "ISP" H 6485 2920 50  0000 L BNN
+F 2 "AVR-ISP-6" V 6230 3190 50  0001 C CNN
+F 3 "" H 6725 3150 50  0001 C CNN
+       1    6750 3150
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:VCC #PWR11
+U 1 1 59DD9F46
+P 7100 3050
+F 0 "#PWR11" H 7100 2900 50  0001 C CNN
+F 1 "VCC" H 7100 3200 50  0000 C CNN
+F 2 "" H 7100 3050 50  0001 C CNN
+F 3 "" H 7100 3050 50  0001 C CNN
+       1    7100 3050
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:GND #PWR10
+U 1 1 59DD9F84
+P 6850 3300
+F 0 "#PWR10" H 6850 3050 50  0001 C CNN
+F 1 "GND" H 6850 3150 50  0000 C CNN
+F 2 "" H 6850 3300 50  0001 C CNN
+F 3 "" H 6850 3300 50  0001 C CNN
+       1    6850 3300
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:Crystal Y1
+U 1 1 59DDA0C7
+P 6050 3400
+F 0 "Y1" H 6050 3550 50  0000 C CNN
+F 1 "Crystal" H 6050 3250 50  0000 C CNN
+F 2 "" H 6050 3400 50  0001 C CNN
+F 3 "" H 6050 3400 50  0001 C CNN
+       1    6050 3400
+       0    1    1    0   
+$EndComp
+$Comp
+L sgikbd-rescue:C C3
+U 1 1 59DDA1C6
+P 6050 3700
+F 0 "C3" H 6075 3800 50  0000 L CNN
+F 1 "22pF" H 6075 3600 50  0000 L CNN
+F 2 "" H 6088 3550 50  0001 C CNN
+F 3 "" H 6050 3700 50  0001 C CNN
+       1    6050 3700
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:C C4
+U 1 1 59DDA28B
+P 6300 3700
+F 0 "C4" H 6325 3800 50  0000 L CNN
+F 1 "22pF" H 6325 3600 50  0000 L CNN
+F 2 "" H 6338 3550 50  0001 C CNN
+F 3 "" H 6300 3700 50  0001 C CNN
+       1    6300 3700
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:GND #PWR8
+U 1 1 59DDA306
+P 6300 3850
+F 0 "#PWR8" H 6300 3600 50  0001 C CNN
+F 1 "GND" H 6300 3700 50  0000 C CNN
+F 2 "" H 6300 3850 50  0001 C CNN
+F 3 "" H 6300 3850 50  0001 C CNN
+       1    6300 3850
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:VCC #PWR3
+U 1 1 59DDA579
+P 3800 2650
+F 0 "#PWR3" H 3800 2500 50  0001 C CNN
+F 1 "VCC" H 3800 2800 50  0000 C CNN
+F 2 "" H 3800 2650 50  0001 C CNN
+F 3 "" H 3800 2650 50  0001 C CNN
+       1    3800 2650
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:GND #PWR4
+U 1 1 59DDA5C3
+P 3800 4950
+F 0 "#PWR4" H 3800 4700 50  0001 C CNN
+F 1 "GND" H 3800 4800 50  0000 C CNN
+F 2 "" H 3800 4950 50  0001 C CNN
+F 3 "" H 3800 4950 50  0001 C CNN
+       1    3800 4950
+       1    0    0    -1  
+$EndComp
+NoConn ~ 3800 3250
+$Comp
+L sgikbd-rescue:C C2
+U 1 1 59DDA7B2
+P 3600 4000
+F 0 "C2" H 3625 4100 50  0000 L CNN
+F 1 "0.1uF" H 3625 3900 50  0000 L CNN
+F 2 "" H 3638 3850 50  0001 C CNN
+F 3 "" H 3600 4000 50  0001 C CNN
+       1    3600 4000
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:GND #PWR2
+U 1 1 59DDAB03
+P 3600 4150
+F 0 "#PWR2" H 3600 3900 50  0001 C CNN
+F 1 "GND" H 3600 4000 50  0000 C CNN
+F 2 "" H 3600 4150 50  0001 C CNN
+F 3 "" H 3600 4150 50  0001 C CNN
+       1    3600 4150
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:VCC #PWR1
+U 1 1 59DDABEE
+P 3600 3850
+F 0 "#PWR1" H 3600 3700 50  0001 C CNN
+F 1 "VCC" H 3600 4000 50  0000 C CNN
+F 2 "" H 3600 3850 50  0001 C CNN
+F 3 "" H 3600 3850 50  0001 C CNN
+       1    3600 3850
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:C C1
+U 1 1 59DDADD5
+P 3300 4000
+F 0 "C1" H 3325 4100 50  0000 L CNN
+F 1 "0.1uF" H 3325 3900 50  0000 L CNN
+F 2 "" H 3338 3850 50  0001 C CNN
+F 3 "" H 3300 4000 50  0001 C CNN
+       1    3300 4000
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:sgikbd_conn U2
+U 1 1 59DDBCD1
+P 6150 5500
+F 0 "U2" H 5900 5100 60  0000 C CNN
+F 1 "intkbd" V 6400 5550 60  0000 C CNN
+F 2 "" H 6450 4850 60  0001 C CNN
+F 3 "" H 6450 4850 60  0001 C CNN
+       1    6150 5500
+       -1   0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:GND #PWR7
+U 1 1 59DDC6E9
+P 6050 6050
+F 0 "#PWR7" H 6050 5800 50  0001 C CNN
+F 1 "GND" H 6050 5900 50  0000 C CNN
+F 2 "" H 6050 6050 50  0001 C CNN
+F 3 "" H 6050 6050 50  0001 C CNN
+       1    6050 6050
+       1    0    0    -1  
+$EndComp
+Text Label 5700 2950 0    60   ~ 0
+MOSI
+Text Label 5700 3050 0    60   ~ 0
+MISO
+Text Label 5700 3150 0    60   ~ 0
+SCK
+Text Label 5900 4100 0    60   ~ 0
+~RESET
+Text Label 5700 3250 0    60   ~ 0
+XTAL0
+Text Label 5700 3350 0    60   ~ 0
+XTAL1
+NoConn ~ 5700 3700
+NoConn ~ 5700 3800
+NoConn ~ 5700 3900
+NoConn ~ 5700 4000
+$Comp
+L sgikbd-rescue:CONN_01X04 J1
+U 1 1 59DDD3D1
+P 6950 3750
+F 0 "J1" H 6950 4000 50  0000 C CNN
+F 1 "SERIAL" V 7050 3750 50  0000 C CNN
+F 2 "" H 6950 3750 50  0001 C CNN
+F 3 "" H 6950 3750 50  0001 C CNN
+       1    6950 3750
+       0    -1   -1   0   
+$EndComp
+$Comp
+L sgikbd-rescue:VCC #PWR9
+U 1 1 59DDD4D2
+P 6650 3750
+F 0 "#PWR9" H 6650 3600 50  0001 C CNN
+F 1 "VCC" H 6650 3900 50  0000 C CNN
+F 2 "" H 6650 3750 50  0001 C CNN
+F 3 "" H 6650 3750 50  0001 C CNN
+       1    6650 3750
+       1    0    0    -1  
+$EndComp
+Text Label 6650 4150 0    60   ~ 0
+RXD
+Text Label 6650 4250 0    60   ~ 0
+TXD
+Wire Wire Line
+       7200 2950 7200 3150
+Wire Wire Line
+       7200 3150 6850 3150
+Wire Wire Line
+       6850 3050 7100 3050
+Wire Wire Line
+       6850 3250 6850 3300
+Wire Wire Line
+       6600 3250 6550 3250
+Wire Wire Line
+       6550 4100 6550 3500
+Wire Wire Line
+       5700 3250 6050 3250
+Wire Wire Line
+       6300 3250 6300 3550
+Connection ~ 6050 3250
+Connection ~ 6050 3550
+Wire Wire Line
+       6050 3850 6300 3850
+Connection ~ 6300 3850
+Wire Wire Line
+       3800 2650 3800 2950
+Connection ~ 3800 2650
+Wire Wire Line
+       3800 4950 3800 4850
+Connection ~ 3800 4950
+Wire Wire Line
+       3300 3850 3600 3850
+Wire Wire Line
+       3300 4150 3600 4150
+Connection ~ 3600 4150
+Connection ~ 3600 3850
+Wire Wire Line
+       6050 3550 5800 3550
+Wire Wire Line
+       5800 3550 5800 3350
+Wire Wire Line
+       5800 3350 5700 3350
+Wire Wire Line
+       5700 4100 5850 4100
+Wire Wire Line
+       6600 3150 5700 3150
+Wire Wire Line
+       6600 3050 5700 3050
+Wire Wire Line
+       7200 2950 5700 2950
+Wire Wire Line
+       6800 3950 6650 3950
+Wire Wire Line
+       6650 3950 6650 3750
+Wire Wire Line
+       5700 4250 5700 4150
+Wire Wire Line
+       5700 4150 6900 4150
+Wire Wire Line
+       6900 4150 6900 3950
+Wire Wire Line
+       5700 4350 5750 4350
+Wire Wire Line
+       5750 4350 5750 4250
+Wire Wire Line
+       5750 4250 7000 4250
+Wire Wire Line
+       7000 4250 7000 3950
+Wire Wire Line
+       5700 4450 7600 4450
+Wire Wire Line
+       7100 3950 7300 3950
+Connection ~ 7100 3950
+Wire Wire Line
+       7800 4450 7800 4650
+Wire Wire Line
+       7800 4650 5700 4650
+NoConn ~ 5700 3500
+NoConn ~ 5700 3600
+NoConn ~ 5700 2750
+NoConn ~ 5700 2850
+Wire Wire Line
+       5700 4550 7350 4550
+$Comp
+L sgikbd-rescue:VCC #PWR6
+U 1 1 59E2D903
+P 6050 5050
+F 0 "#PWR6" H 6050 4900 50  0001 C CNN
+F 1 "VCC" H 6050 5200 50  0000 C CNN
+F 2 "" H 6050 5050 50  0001 C CNN
+F 3 "" H 6050 5050 50  0001 C CNN
+       1    6050 5050
+       1    0    0    -1  
+$EndComp
+Text Label 5800 4550 0    60   ~ 0
+ACLK
+Text Label 5800 4650 0    60   ~ 0
+PDATA
+Text Label 5800 4750 0    60   ~ 0
+ADATA
+Wire Wire Line
+       5700 4750 7450 4750
+$Comp
+L sgikbd-rescue:R R2
+U 1 1 59E3CD35
+P 8100 4400
+F 0 "R2" V 8180 4400 50  0000 C CNN
+F 1 "4.7k" V 8100 4400 50  0000 C CNN
+F 2 "" V 8030 4400 50  0001 C CNN
+F 3 "" H 8100 4400 50  0001 C CNN
+       1    8100 4400
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:SW_DPDT_x2 SW2
+U 1 1 59E3D07D
+P 7900 5050
+F 0 "SW2" H 7900 5220 50  0000 C CNN
+F 1 "SW_DPDT_x2" H 7700 4950 50  0000 C CNN
+F 2 "" H 7900 5050 50  0001 C CNN
+F 3 "" H 7900 5050 50  0001 C CNN
+       1    7900 5050
+       -1   0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:SW_DPDT_x2 SW2
+U 2 1 59E3D417
+P 7900 5450
+F 0 "SW2" H 7900 5620 50  0000 C CNN
+F 1 "SW_DPDT_x2" H 7700 5350 50  0000 C CNN
+F 2 "" H 7900 5450 50  0001 C CNN
+F 3 "" H 7900 5450 50  0001 C CNN
+       2    7900 5450
+       -1   0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:sgikbd_conn U4
+U 1 1 59E3D757
+P 9000 5500
+F 0 "U4" H 8750 5100 60  0000 C CNN
+F 1 "kbout" V 9250 5550 60  0000 C CNN
+F 2 "" H 9300 4850 60  0001 C CNN
+F 3 "" H 9300 4850 60  0001 C CNN
+       1    9000 5500
+       1    0    0    -1  
+$EndComp
+Wire Wire Line
+       8100 5050 8350 5050
+Wire Wire Line
+       8350 5050 8350 5300
+Wire Wire Line
+       8350 5300 8500 5300
+Wire Wire Line
+       8100 5450 8350 5450
+Wire Wire Line
+       8350 5450 8350 5400
+Wire Wire Line
+       8350 5400 8500 5400
+Wire Wire Line
+       7350 4550 7350 5350
+Wire Wire Line
+       7350 5350 7700 5350
+Wire Wire Line
+       7450 4750 7450 4950
+Wire Wire Line
+       7450 4950 7700 4950
+Connection ~ 7350 4550
+$Comp
+L sgikbd-rescue:R R3
+U 1 1 59E3E98A
+P 8300 4400
+F 0 "R3" V 8380 4400 50  0000 C CNN
+F 1 "4.7k" V 8300 4400 50  0000 C CNN
+F 2 "" V 8230 4400 50  0001 C CNN
+F 3 "" H 8300 4400 50  0001 C CNN
+       1    8300 4400
+       1    0    0    -1  
+$EndComp
+Wire Wire Line
+       8300 4750 8300 4550
+Connection ~ 7450 4750
+$Comp
+L sgikbd-rescue:VCC #PWR15
+U 1 1 59E3EAB6
+P 8200 4250
+F 0 "#PWR15" H 8200 4100 50  0001 C CNN
+F 1 "VCC" H 8200 4400 50  0000 C CNN
+F 2 "" H 8200 4250 50  0001 C CNN
+F 3 "" H 8200 4250 50  0001 C CNN
+       1    8200 4250
+       1    0    0    -1  
+$EndComp
+Wire Wire Line
+       8100 4250 8200 4250
+Connection ~ 8200 4250
+Wire Wire Line
+       6650 5300 7200 5300
+Wire Wire Line
+       7200 5300 7200 5150
+Wire Wire Line
+       7200 5150 7700 5150
+Text Label 6650 5300 0    60   ~ 0
+INTKB_DATA
+Text Label 6650 5400 0    60   ~ 0
+INTKB_CLOCK
+Wire Wire Line
+       6650 5400 7200 5400
+Wire Wire Line
+       7200 5400 7200 5550
+Wire Wire Line
+       7200 5550 7700 5550
+Wire Wire Line
+       5700 4850 5800 4850
+Wire Wire Line
+       5800 4850 5800 6300
+Wire Wire Line
+       8500 6300 6850 6300
+Wire Wire Line
+       6850 6300 6850 5550
+Wire Wire Line
+       6850 5550 6650 5550
+Wire Wire Line
+       8500 5550 8500 6300
+Connection ~ 6850 6300
+Text Label 6950 6300 0    60   ~ 0
+AMIGA_RESET
+$Comp
+L sgikbd-rescue:GND #PWR17
+U 1 1 59E3F2E8
+P 9100 6050
+F 0 "#PWR17" H 9100 5800 50  0001 C CNN
+F 1 "GND" H 9100 5900 50  0000 C CNN
+F 2 "" H 9100 6050 50  0001 C CNN
+F 3 "" H 9100 6050 50  0001 C CNN
+       1    9100 6050
+       1    0    0    -1  
+$EndComp
+$Comp
+L sgikbd-rescue:VCC #PWR16
+U 1 1 59E3F32F
+P 9100 5050
+F 0 "#PWR16" H 9100 4900 50  0001 C CNN
+F 1 "VCC" H 9100 5200 50  0000 C CNN
+F 2 "" H 9100 5050 50  0001 C CNN
+F 3 "" H 9100 5050 50  0001 C CNN
+       1    9100 5050
+       1    0    0    -1  
+$EndComp
+Wire Wire Line
+       6650 5700 8500 5700
+Wire Wire Line
+       6650 5800 6750 5800
+Wire Wire Line
+       5700 4950 5850 4950
+Wire Wire Line
+       5850 4950 5850 6250
+Wire Wire Line
+       5850 6250 6750 6250
+Wire Wire Line
+       6750 6250 6750 5800
+Connection ~ 6750 5800
+$Comp
+L sgikbd-rescue:R R1
+U 1 1 59E40996
+P 5850 3950
+F 0 "R1" V 5930 3950 50  0000 C CNN
+F 1 "4.7k" V 5850 3950 50  0000 C CNN
+F 2 "" V 5780 3950 50  0001 C CNN
+F 3 "" H 5850 3950 50  0001 C CNN
+       1    5850 3950
+       1    0    0    -1  
+$EndComp
+Connection ~ 5850 4100
+$Comp
+L sgikbd-rescue:VCC #PWR5
+U 1 1 59E40D4F
+P 5850 3800
+F 0 "#PWR5" H 5850 3650 50  0001 C CNN
+F 1 "VCC" H 5850 3950 50  0000 C CNN
+F 2 "" H 5850 3800 50  0001 C CNN
+F 3 "" H 5850 3800 50  0001 C CNN
+       1    5850 3800
+       1    0    0    -1  
+$EndComp
+NoConn ~ 5700 2650
+Text Label 7050 5800 0    60   ~ 0
+DRVLED
+Text Label 7050 5700 0    60   ~ 0
+STLED
+Text Label 8100 5050 0    60   ~ 0
+ODAT
+Text Label 8100 5450 0    60   ~ 0
+OCLK
+$Comp
+L sgikbd-rescue:SW_Push SW1
+U 1 1 59E5C5FC
+P 7450 3500
+F 0 "SW1" H 7500 3600 50  0000 L CNN
+F 1 "RESET" H 7450 3440 50  0000 C CNN
+F 2 "" H 7450 3700 50  0001 C CNN
+F 3 "" H 7450 3700 50  0001 C CNN
+       1    7450 3500
+       1    0    0    -1  
+$EndComp
+Wire Wire Line
+       7250 3500 6550 3500
+Connection ~ 6550 3500
+$Comp
+L sgikbd-rescue:GND #PWR13
+U 1 1 59E5C78A
+P 7650 3500
+F 0 "#PWR13" H 7650 3250 50  0001 C CNN
+F 1 "GND" H 7650 3350 50  0000 C CNN
+F 2 "" H 7650 3500 50  0001 C CNN
+F 3 "" H 7650 3500 50  0001 C CNN
+       1    7650 3500
+       1    0    0    -1  
+$EndComp
+Wire Notes Line
+       7700 5650 7700 4800
+Wire Notes Line
+       7700 4800 8400 4800
+Wire Notes Line
+       8400 4800 8400 5650
+Wire Notes Line
+       8400 5650 7700 5650
+Wire Wire Line
+       6050 3250 6300 3250
+Wire Wire Line
+       7350 4550 8100 4550
+Wire Wire Line
+       7450 4750 8300 4750
+Wire Wire Line
+       8200 4250 8300 4250
+Wire Wire Line
+       6850 6300 5800 6300
+Wire Wire Line
+       6750 5800 8500 5800
+Wire Wire Line
+       5850 4100 6550 4100
+Wire Wire Line
+       6550 3500 6550 3250
+$EndSCHEMATC