[
  {
    "path": ".gitignore",
    "content": "version.lua\nlibvncclient.so\ndist/\nlibjpeg-turbo-1.3.0/*\nluajit-2.0/*\nzlib/*\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"libvncserver\"]\n\tpath = libvncserver\n\turl = https://github.com/LibVNC/libvncserver.git\n[submodule \"luajit-2.0\"]\n\tpath = luajit-2.0\n\turl = http://luajit.org/git/luajit-2.0.git\n[submodule \"zlib\"]\n\tpath = zlib\n\turl = https://github.com/madler/zlib.git\n"
  },
  {
    "path": "COPYING",
    "content": "\t\t    GNU GENERAL PUBLIC LICENSE\n\t\t       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n                          59 Temple Place - Suite 330, Boston, MA\n                          02111-1307, USA.\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n\t\t    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n\tAppendix: How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) 19yy  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) 19yy name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "Makefile",
    "content": "ifdef ARCH\nCC=$(ARCH)-gcc\nCROSS=$(ARCH)-\n# for luajit:\nHOST_CC=\"gcc -m32\"\nSTRIP?=$(ARCH)-strip\nelse\nSTRIP?=strip\nARCH=$(shell $(CC) -dumpmachine)\nendif\nCFLAGS?=\"-D_GNU_SOURCE=1\"\n\nVERSION=$(shell git describe HEAD)\n#VERSION=$(shell date +'%Y-%m-%d_%H-%m')\n\nLIBVNCCLIENT_DIR=libvncserver/libvncclient\nLIBVNCCLIENT=libvncclient.so\n\nLUAJIT_DIR=luajit-2.0\nLUAJIT=$(LUAJIT_DIR)/src/luajit\n\nLIBJPEG_DIR=libjpeg-turbo-1.3.0\nLIBJPEG=$(LIBJPEG_DIR)/.libs/libjpeg.so.62\nLIBJPEG_CONFIG=-without-simd\n\nZLIB_DIR=zlib\nZLIB=$(ZLIB_DIR)/libz.so.1\n\nFFI_CDECL=../koreader-misc/ffi-cdecl/ffi-cdecl $(CC) -I$(LIBVNCCLIENT_DIR)/../\n\nOBJECTS= \\\n\t$(LUAJIT) \\\n\t$(LIBVNCCLIENT) \\\n\t$(ZLIB) \\\n\t$(LIBJPEG)\n\nDISTRIBUTE=ffi config.lua keys.lua rfbkeys.lua vncviewer.lua \\\n\tREADME COPYING \\\n\t$(OBJECTS)\n\nall: dist/kvncviewer-$(ARCH)-$(VERSION).zip\n\n$(LUAJIT):\nifdef CROSS\n\tsed -i -e \"s/CC= gcc/CC= gcc -D_GNU_SOURCE=1/\" $(LUAJIT_DIR)/src/Makefile\n\t$(MAKE) -C $(LUAJIT_DIR) HOST_CC=$(HOST_CC) CROSS=$(CROSS)\nelse\n\t$(MAKE) -C $(LUAJIT_DIR)\nendif\n\n\nLIBVNCCLIENT_SOURCES=\\\n\t$(LIBVNCCLIENT_DIR)/cursor.c \\\n\t$(LIBVNCCLIENT_DIR)/listen.c \\\n\t$(LIBVNCCLIENT_DIR)/rfbproto.c \\\n\t$(LIBVNCCLIENT_DIR)/sockets.c \\\n\t$(LIBVNCCLIENT_DIR)/vncviewer.c \\\n\t$(LIBVNCCLIENT_DIR)/tls_none.c \\\n\t$(LIBVNCCLIENT_DIR)/../common/minilzo.c\n\nLIBVNCCLIENT_CFLAGS=-D_GNU_SOURCE=1 -fPIC -shared \\\n\t-DLIBVNCSERVER_HAVE_LIBZ -DLIBVNCSERVER_HAVE_LIBJPEG \\\n\t-I$(LIBVNCCLIENT_DIR)/.. -I$(LIBVNCCLIENT_DIR)/../common/ -I$(LIBVNCCLIENT) \\\n\t-I$(ZLIB_DIR)/ -I$(LIBJPEG_DIR)/ \\\n\t-Wl,-E -Wl,-rpath,'$$ORIGIN'\n\n$(LIBVNCCLIENT): $(LIBVNCCLIENT_SOURCES) $(LIBJPEG) $(ZLIB)\n\ttouch $(LIBVNCCLIENT_DIR)/../rfb/rfbconfig.h\n\techo '#include <stdint.h>' > $(LIBVNCCLIENT_DIR)/../rfb/rfbint.h\n\t$(CC) $(LIBVNCCLIENT_CFLAGS) -o $@ $(LIBVNCCLIENT_SOURCES) $(ZLIB) $(LIBJPEG)\n\n$(LIBJPEG):\n\tcd $(LIBJPEG_DIR) && \\\n\t\tCC=$(CC) CFLAGS=\"$(CFLAGS)\" \\\n\t\t./configure --disable-static --enable-shared \\\n\t\t\t\t$(LIBJPEG_CONFIG) \\\n\t\t\t\t--host=$(ARCH)\n\t$(MAKE) -C $(LIBJPEG_DIR)\n\n$(ZLIB):\n\tcd $(ZLIB_DIR) && \\\n\t\tCC=$(CC) CFLAGS=\"$(CFLAGS)\" \\\n\t\t./configure\n\t$(MAKE) -C $(ZLIB_DIR)\n\ncdecl: \\\n\tffi/posix_h.lua \\\n\tffi/linux_fb_h.lua \\\n\tffi/einkfb_h.lua \\\n\tffi/mxcfb_kindle_h.lua \\\n\tffi/mxcfb_kobo_h.lua \\\n\tffi/linux_input_h.lua \\\n\tffi/rfbclient_h.lua\n\nffi/%_h.lua: ffi-cdecl/%_decl.c\n\t$(FFI_CDECL) $< > $@\n\nversion.lua: $(DISTRIBUTE)\n\techo 'return \"$(VERSION)\"' > version.lua\n\ndist/kvncviewer-$(ARCH)-$(VERSION).zip: $(DISTRIBUTE) version.lua cdecl\n\t-rm $@\n\t-rm -rf dist/$(ARCH)\n\tmkdir -p dist/$(ARCH)/kvncviewer\n\tcp -rL $(DISTRIBUTE) dist/$(ARCH)/kvncviewer/\n\tcd dist/$(ARCH)/kvncviewer && $(STRIP) --strip-unneeded *.so* luajit\n\tcd dist/$(ARCH) && zip -r9 ../../$@ kvncviewer\n\nclean:\n\t$(MAKE) -C $(LUAJIT_DIR) clean\n\t$(MAKE) -C $(LIBJPEG_DIR) clean\n\t$(MAKE) -C $(ZLIB_DIR) clean\n\t-rm $(LIBVNCCLIENT)\n\n"
  },
  {
    "path": "README.md",
    "content": "## About\n\nThis is a VNC viewer for eReaders.\nCopyright (c) 2013 Hans-Werner Hilse <hilse@web.de>\n\nIt works on the framebuffer, using the einkfb API from e-ink devices (einkfb.h) to do screen refreshes.\nThis is based on LibVNCClient, part of the [LibVNCServer project](https://libvnc.github.io/).\n\n\nThere is a discussion thread on MobileRead:\nhttp://www.mobileread.com/forums/showthread.php?t=150434\n\nNote that the current version is a major rewrite of the original version.\nThe current version is implemented in Lua, targeted at LuaJIT.\n\n\n## Configuration\n\nInput handling is configurable/customizable in \"config.lua\".\n\nkVNCviewer supports many options that determine various settings. Run it without arguments to show a list of supported options. In addition, LibVNCClient parses options, which allows for additional configuration. Look into the [documentation of LibVNCClient](https://libvnc.github.io/doc/html/group__libvncclient__api.html#gabb2299d1644f3cf38544eb97d2356475) to see the options it accepts.\n\n\n## Building\n\nIn order to build kVNCViewer, you can use GNU make. A Kindle (and other eReaders)-specific toolchain can be found at [@koreader/koxtoolchain](https://github.com/koreader/koxtoolchain). Specify a toolchain prefix as the \"ARCH\" variable, and it should build luajit, zlib, libjpeg and finally libvncclient. E.g., for legacy Kindles:\n\n```\nmake ARCH=arm-kindle-linux-gnueabi\n```\n\nYou can find the result in the \"dist/<ARCH>\" subdirectory. Also, a .zip file is created for distribution.\n\n\n## Running\n\nYou need to copy the program and the libraries it needs onto your eReader (you can try running it without and it will show you which libraries are missing). Then, from a launcher app or shell, call:\n\n```\n./luajit vncviewer.lua 192.168.1.1:5900\n```\n\nYou will need to enter the correct server address or name and screen number.\n\n\n## Licensing/Copying\n\nThis software is licensed under the GPLv2 (see file COPYING).\n"
  },
  {
    "path": "Xvnc-start.sh",
    "content": "#!/bin/sh -xe\n\norientation=`ssh root@192.168.2.2 cat /sys/module/eink_fb_hal_broads/parameters/bs_orientation`\nif [ $orientation == 1 ] ; then\n\tgeometry=1200x824\nelse\n\tgeometry=824x1200\nfi\n\n/usr/bin/Xvnc --SecurityTypes=None -geometry $geometry -depth 16 -dpi 160 -alwaysshared :1 &\nsleep 1\nDISPLAY=:1 xterm &\nDISPLAY=:1 dwm &\nvncviewer :1 &\nx2vnc -west 127.0.0.1:1 &\nssh root@192.168.2.2 /mnt/us/kindlevncviewer/kvncviewer.sh 192.168.2.1:1\n\n"
  },
  {
    "path": "config.lua",
    "content": "require \"keys\"\nrequire \"rfbkeys\"\n\n-- comment out the following line on a KDX\nset_k3_keycodes()\n\n\n-- variables client_width and client_height will be available when handleInput() is called\nclient_width = 0\nclient_height = 0\n\n--[[\n   you have also the following API functions:\n\n   Quit( [status] )\n      will quit the application. optional: return code (must be positive)\n\n   SendKeyEvent( keyCode, pressed )\n      sends a key event to the rfb server. \"pressed\" is a bool value\n      telling whether the key was pressed (true) or released (false)\n\n   SendPointerEvent( x, y, buttonMask )\n      sends a pointer event to the rfb server\n]]--\n\n\n-- globals for remembering key state\nshift = false\nsym = false\n\n-- this handler will be called upon key presses (input events, actually)\nfunction handleInput(channel, itype, code, value)\n\t--print(\"input:\", channel, itype, code, value)\n\tif itype == EV_KEY then\n\t\tlocal pressed = false\n\t\tif value == EVENT_VALUE_KEY_PRESS then\n\t\t\tpressed = true\n\t\telseif value == EVENT_VALUE_KEY_RELEASE then\n\t\t\tpressed = false\n\t\telse\n\t\t\treturn -- we don't know how to handle this.\n\t\tend\n\n\t\t-- will toggle state \n\t\tif code == KEY_SYM then sym = pressed\n\t\telseif code == KEY_SHIFT then shift = pressed\n\n\t\t-- number keys, not present on K3\n\t\telseif code == KEY_1 then SendKeyEvent(XK_1, pressed)\n\t\telseif code == KEY_2 then SendKeyEvent(XK_2, pressed)\n\t\telseif code == KEY_3 then SendKeyEvent(XK_3, pressed)\n\t\telseif code == KEY_4 then SendKeyEvent(XK_4, pressed)\n\t\telseif code == KEY_5 then SendKeyEvent(XK_5, pressed)\n\t\telseif code == KEY_6 then SendKeyEvent(XK_6, pressed)\n\t\telseif code == KEY_7 then SendKeyEvent(XK_7, pressed)\n\t\telseif code == KEY_8 then SendKeyEvent(XK_8, pressed)\n\t\telseif code == KEY_9 then SendKeyEvent(XK_9, pressed)\n\t\telseif code == KEY_0 then SendKeyEvent(XK_0, pressed)\n\n\t\t-- letter keys\n\t\telseif not shift and code == KEY_Q then SendKeyEvent(XK_q, pressed)\n\t\telseif not shift and code == KEY_W then SendKeyEvent(XK_w, pressed)\n\t\telseif not shift and code == KEY_E then SendKeyEvent(XK_e, pressed)\n\t\telseif not shift and code == KEY_R then SendKeyEvent(XK_r, pressed)\n\t\telseif not shift and code == KEY_T then SendKeyEvent(XK_t, pressed)\n\t\telseif not shift and code == KEY_Y then SendKeyEvent(XK_y, pressed)\n\t\telseif not shift and code == KEY_U then SendKeyEvent(XK_u, pressed)\n\t\telseif not shift and code == KEY_I then SendKeyEvent(XK_i, pressed)\n\t\telseif not shift and code == KEY_O then SendKeyEvent(XK_o, pressed)\n\t\telseif not shift and code == KEY_P then SendKeyEvent(XK_p, pressed)\n\t\telseif not shift and code == KEY_A then SendKeyEvent(XK_a, pressed)\n\t\telseif not shift and code == KEY_S then SendKeyEvent(XK_s, pressed)\n\t\telseif not shift and code == KEY_D then SendKeyEvent(XK_d, pressed)\n\t\telseif not shift and code == KEY_F then SendKeyEvent(XK_f, pressed)\n\t\telseif not shift and code == KEY_G then SendKeyEvent(XK_g, pressed)\n\t\telseif not shift and code == KEY_H then SendKeyEvent(XK_h, pressed)\n\t\telseif not shift and code == KEY_J then SendKeyEvent(XK_j, pressed)\n\t\telseif not shift and code == KEY_K then SendKeyEvent(XK_k, pressed)\n\t\telseif not shift and code == KEY_L then SendKeyEvent(XK_l, pressed)\n\t\telseif not shift and code == KEY_Z then SendKeyEvent(XK_z, pressed)\n\t\telseif not shift and code == KEY_X then SendKeyEvent(XK_x, pressed)\n\t\telseif not shift and code == KEY_C then SendKeyEvent(XK_c, pressed)\n\t\telseif not shift and code == KEY_V then SendKeyEvent(XK_v, pressed)\n\t\telseif not shift and code == KEY_B then SendKeyEvent(XK_b, pressed)\n\t\telseif not shift and code == KEY_N then SendKeyEvent(XK_n, pressed)\n\t\telseif not shift and code == KEY_M then SendKeyEvent(XK_m, pressed)\n\t\telseif shift and code == KEY_Q then SendKeyEvent(XK_Q, pressed)\n\t\telseif shift and code == KEY_W then SendKeyEvent(XK_W, pressed)\n\t\telseif shift and code == KEY_E then SendKeyEvent(XK_E, pressed)\n\t\telseif shift and code == KEY_R then SendKeyEvent(XK_R, pressed)\n\t\telseif shift and code == KEY_T then SendKeyEvent(XK_T, pressed)\n\t\telseif shift and code == KEY_Y then SendKeyEvent(XK_Y, pressed)\n\t\telseif shift and code == KEY_U then SendKeyEvent(XK_U, pressed)\n\t\telseif shift and code == KEY_I then SendKeyEvent(XK_I, pressed)\n\t\telseif shift and code == KEY_O then SendKeyEvent(XK_O, pressed)\n\t\telseif shift and code == KEY_P then SendKeyEvent(XK_P, pressed)\n\t\telseif shift and code == KEY_A then SendKeyEvent(XK_A, pressed)\n\t\telseif shift and code == KEY_S then SendKeyEvent(XK_S, pressed)\n\t\telseif shift and code == KEY_D then SendKeyEvent(XK_D, pressed)\n\t\telseif shift and code == KEY_F then SendKeyEvent(XK_F, pressed)\n\t\telseif shift and code == KEY_G then SendKeyEvent(XK_G, pressed)\n\t\telseif shift and code == KEY_H then SendKeyEvent(XK_H, pressed)\n\t\telseif shift and code == KEY_J then SendKeyEvent(XK_J, pressed)\n\t\telseif shift and code == KEY_K then SendKeyEvent(XK_K, pressed)\n\t\telseif shift and code == KEY_L then SendKeyEvent(XK_L, pressed)\n\t\telseif shift and code == KEY_Z then SendKeyEvent(XK_Z, pressed)\n\t\telseif shift and code == KEY_X then SendKeyEvent(XK_X, pressed)\n\t\telseif shift and code == KEY_C then SendKeyEvent(XK_C, pressed)\n\t\telseif shift and code == KEY_V then SendKeyEvent(XK_V, pressed)\n\t\telseif shift and code == KEY_B then SendKeyEvent(XK_B, pressed)\n\t\telseif shift and code == KEY_N then SendKeyEvent(XK_N, pressed)\n\t\telseif shift and code == KEY_M then SendKeyEvent(XK_M, pressed)\n\n\t\t-- other keys\n\t\telseif not shift and code == KEY_DEL then SendKeyEvent(XK_Delete, pressed)\n\t\telseif shift and code == KEY_DEL then SendKeyEvent(XK_BackSpace, pressed)\n\t\telseif code == KEY_DOT then SendKeyEvent(XK_period, pressed)\n\t\telseif code == KEY_SLASH then SendKeyEvent(XK_slash, pressed)\n\t\telseif code == KEY_ENTER then SendKeyEvent(XK_Return, pressed)\n\t\telseif code == KEY_SPACE then SendKeyEvent(XK_space, pressed)\n\n\t\telseif code == KEY_ALT then SendKeyEvent(XK_Alt_L, pressed)\n\t\telseif code == KEY_AA then SendKeyEvent(XK_Control_L, pressed)\n\n\t\t-- special keys\n\t\t--elseif code == KEY_VPLUS then SendKeyEvent(XK_, pressed)\n\t\t--elseif code == KEY_VMINUS then SendKeyEvent(XK_, pressed)\n\t\telseif code == KEY_HOME then\n\t\t\tQuit()\n\t\telseif code == KEY_PGBCK then SendKeyEvent(XK_Escape, pressed)\n\t\telseif code == KEY_PGFWD then SendKeyEvent(XK_Tab, pressed)\n\t\t-- the following two exist only on K3\n\t\telseif code == KEY_LPGBCK then SendKeyEvent(XK_Escape, pressed)\n\t\telseif code == KEY_LPGFWD then SendKeyEvent(XK_Tab, pressed)\n\t\t--elseif code == KEY_MENU then SendKeyEvent(XK_, pressed)\n\t\t--elseif code == KEY_BACK then SendKeyEvent(XK_, pressed)\n\t\telseif code == KEY_FW_LEFT then SendKeyEvent(XK_Left, pressed)\n\t\telseif code == KEY_FW_RIGHT then SendKeyEvent(XK_Right, pressed)\n\t\telseif code == KEY_FW_UP then SendKeyEvent(XK_Up, pressed)\n\t\telseif code == KEY_FW_DOWN then SendKeyEvent(XK_Down, pressed)\n\t\telseif code == KEY_FW_PRESS then SendKeyEvent(XK_Return, pressed)\n\t\tend\n\tend\nend\n"
  },
  {
    "path": "ffi/SDL.lua",
    "content": "--[[\nModule for interfacing SDL video/input facilities\n\nThis module is intended to provide input/output facilities on a\ntypical desktop (rather than a dedicated e-ink reader, for which\nthere would probably be raw framebuffer/input device access\ninstead).\n]]\n\nlocal ffi = require(\"ffi\")\n\nlocal dummy = require(\"ffi/SDL1_2_h\")\nlocal dummy = require(\"ffi/linux_input_h\")\n\n-----------------------------------------------------------------\n\nlocal SDL = ffi.load(\"SDL\")\n\nlocal S = {\n\tscreen = nil,\n\tSDL = SDL\n}\n\n-- initialization for both input and eink output\nfunction S.open()\n\tif SDL.SDL_WasInit(SDL.SDL_INIT_VIDEO) ~= 0 then\n\t\t-- already initialized\n\t\treturn true\n\tend\n\tif SDL.SDL_Init(SDL.SDL_INIT_VIDEO) ~= 0 then\n\t\terror(\"cannot initialize SDL\")\n\tend\n\n\t-- set up screen (window)\n\tS.screen = SDL.SDL_SetVideoMode(\n\t\ttonumber(os.getenv(\"EMULATE_READER_W\")) or 600,\n\t\ttonumber(os.getenv(\"EMULATE_READER_H\")) or 800,\n\t\t32, SDL.SDL_HWSURFACE)\n\n\t-- init keyboard delay/repeat rate\n\tSDL.SDL_EnableKeyRepeat(500, 10)\nend\n\nreturn S\n"
  },
  {
    "path": "ffi/SDL1_2_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\ntypedef unsigned int Uint32;\ntypedef int Sint32;\ntypedef short unsigned int Uint16;\ntypedef short int Sint16;\ntypedef unsigned char Uint8;\ntypedef signed char Sint8;\nstruct SDL_keysym {\n  unsigned char scancode;\n  enum {\n    SDLK_UNKNOWN = 0,\n    SDLK_FIRST = 0,\n    SDLK_BACKSPACE = 8,\n    SDLK_TAB = 9,\n    SDLK_CLEAR = 12,\n    SDLK_RETURN = 13,\n    SDLK_PAUSE = 19,\n    SDLK_ESCAPE = 27,\n    SDLK_SPACE = 32,\n    SDLK_EXCLAIM = 33,\n    SDLK_QUOTEDBL = 34,\n    SDLK_HASH = 35,\n    SDLK_DOLLAR = 36,\n    SDLK_AMPERSAND = 38,\n    SDLK_QUOTE = 39,\n    SDLK_LEFTPAREN = 40,\n    SDLK_RIGHTPAREN = 41,\n    SDLK_ASTERISK = 42,\n    SDLK_PLUS = 43,\n    SDLK_COMMA = 44,\n    SDLK_MINUS = 45,\n    SDLK_PERIOD = 46,\n    SDLK_SLASH = 47,\n    SDLK_0 = 48,\n    SDLK_1 = 49,\n    SDLK_2 = 50,\n    SDLK_3 = 51,\n    SDLK_4 = 52,\n    SDLK_5 = 53,\n    SDLK_6 = 54,\n    SDLK_7 = 55,\n    SDLK_8 = 56,\n    SDLK_9 = 57,\n    SDLK_COLON = 58,\n    SDLK_SEMICOLON = 59,\n    SDLK_LESS = 60,\n    SDLK_EQUALS = 61,\n    SDLK_GREATER = 62,\n    SDLK_QUESTION = 63,\n    SDLK_AT = 64,\n    SDLK_LEFTBRACKET = 91,\n    SDLK_BACKSLASH = 92,\n    SDLK_RIGHTBRACKET = 93,\n    SDLK_CARET = 94,\n    SDLK_UNDERSCORE = 95,\n    SDLK_BACKQUOTE = 96,\n    SDLK_a = 97,\n    SDLK_b = 98,\n    SDLK_c = 99,\n    SDLK_d = 100,\n    SDLK_e = 101,\n    SDLK_f = 102,\n    SDLK_g = 103,\n    SDLK_h = 104,\n    SDLK_i = 105,\n    SDLK_j = 106,\n    SDLK_k = 107,\n    SDLK_l = 108,\n    SDLK_m = 109,\n    SDLK_n = 110,\n    SDLK_o = 111,\n    SDLK_p = 112,\n    SDLK_q = 113,\n    SDLK_r = 114,\n    SDLK_s = 115,\n    SDLK_t = 116,\n    SDLK_u = 117,\n    SDLK_v = 118,\n    SDLK_w = 119,\n    SDLK_x = 120,\n    SDLK_y = 121,\n    SDLK_z = 122,\n    SDLK_DELETE = 127,\n    SDLK_WORLD_0 = 160,\n    SDLK_WORLD_1 = 161,\n    SDLK_WORLD_2 = 162,\n    SDLK_WORLD_3 = 163,\n    SDLK_WORLD_4 = 164,\n    SDLK_WORLD_5 = 165,\n    SDLK_WORLD_6 = 166,\n    SDLK_WORLD_7 = 167,\n    SDLK_WORLD_8 = 168,\n    SDLK_WORLD_9 = 169,\n    SDLK_WORLD_10 = 170,\n    SDLK_WORLD_11 = 171,\n    SDLK_WORLD_12 = 172,\n    SDLK_WORLD_13 = 173,\n    SDLK_WORLD_14 = 174,\n    SDLK_WORLD_15 = 175,\n    SDLK_WORLD_16 = 176,\n    SDLK_WORLD_17 = 177,\n    SDLK_WORLD_18 = 178,\n    SDLK_WORLD_19 = 179,\n    SDLK_WORLD_20 = 180,\n    SDLK_WORLD_21 = 181,\n    SDLK_WORLD_22 = 182,\n    SDLK_WORLD_23 = 183,\n    SDLK_WORLD_24 = 184,\n    SDLK_WORLD_25 = 185,\n    SDLK_WORLD_26 = 186,\n    SDLK_WORLD_27 = 187,\n    SDLK_WORLD_28 = 188,\n    SDLK_WORLD_29 = 189,\n    SDLK_WORLD_30 = 190,\n    SDLK_WORLD_31 = 191,\n    SDLK_WORLD_32 = 192,\n    SDLK_WORLD_33 = 193,\n    SDLK_WORLD_34 = 194,\n    SDLK_WORLD_35 = 195,\n    SDLK_WORLD_36 = 196,\n    SDLK_WORLD_37 = 197,\n    SDLK_WORLD_38 = 198,\n    SDLK_WORLD_39 = 199,\n    SDLK_WORLD_40 = 200,\n    SDLK_WORLD_41 = 201,\n    SDLK_WORLD_42 = 202,\n    SDLK_WORLD_43 = 203,\n    SDLK_WORLD_44 = 204,\n    SDLK_WORLD_45 = 205,\n    SDLK_WORLD_46 = 206,\n    SDLK_WORLD_47 = 207,\n    SDLK_WORLD_48 = 208,\n    SDLK_WORLD_49 = 209,\n    SDLK_WORLD_50 = 210,\n    SDLK_WORLD_51 = 211,\n    SDLK_WORLD_52 = 212,\n    SDLK_WORLD_53 = 213,\n    SDLK_WORLD_54 = 214,\n    SDLK_WORLD_55 = 215,\n    SDLK_WORLD_56 = 216,\n    SDLK_WORLD_57 = 217,\n    SDLK_WORLD_58 = 218,\n    SDLK_WORLD_59 = 219,\n    SDLK_WORLD_60 = 220,\n    SDLK_WORLD_61 = 221,\n    SDLK_WORLD_62 = 222,\n    SDLK_WORLD_63 = 223,\n    SDLK_WORLD_64 = 224,\n    SDLK_WORLD_65 = 225,\n    SDLK_WORLD_66 = 226,\n    SDLK_WORLD_67 = 227,\n    SDLK_WORLD_68 = 228,\n    SDLK_WORLD_69 = 229,\n    SDLK_WORLD_70 = 230,\n    SDLK_WORLD_71 = 231,\n    SDLK_WORLD_72 = 232,\n    SDLK_WORLD_73 = 233,\n    SDLK_WORLD_74 = 234,\n    SDLK_WORLD_75 = 235,\n    SDLK_WORLD_76 = 236,\n    SDLK_WORLD_77 = 237,\n    SDLK_WORLD_78 = 238,\n    SDLK_WORLD_79 = 239,\n    SDLK_WORLD_80 = 240,\n    SDLK_WORLD_81 = 241,\n    SDLK_WORLD_82 = 242,\n    SDLK_WORLD_83 = 243,\n    SDLK_WORLD_84 = 244,\n    SDLK_WORLD_85 = 245,\n    SDLK_WORLD_86 = 246,\n    SDLK_WORLD_87 = 247,\n    SDLK_WORLD_88 = 248,\n    SDLK_WORLD_89 = 249,\n    SDLK_WORLD_90 = 250,\n    SDLK_WORLD_91 = 251,\n    SDLK_WORLD_92 = 252,\n    SDLK_WORLD_93 = 253,\n    SDLK_WORLD_94 = 254,\n    SDLK_WORLD_95 = 255,\n    SDLK_KP0 = 256,\n    SDLK_KP1 = 257,\n    SDLK_KP2 = 258,\n    SDLK_KP3 = 259,\n    SDLK_KP4 = 260,\n    SDLK_KP5 = 261,\n    SDLK_KP6 = 262,\n    SDLK_KP7 = 263,\n    SDLK_KP8 = 264,\n    SDLK_KP9 = 265,\n    SDLK_KP_PERIOD = 266,\n    SDLK_KP_DIVIDE = 267,\n    SDLK_KP_MULTIPLY = 268,\n    SDLK_KP_MINUS = 269,\n    SDLK_KP_PLUS = 270,\n    SDLK_KP_ENTER = 271,\n    SDLK_KP_EQUALS = 272,\n    SDLK_UP = 273,\n    SDLK_DOWN = 274,\n    SDLK_RIGHT = 275,\n    SDLK_LEFT = 276,\n    SDLK_INSERT = 277,\n    SDLK_HOME = 278,\n    SDLK_END = 279,\n    SDLK_PAGEUP = 280,\n    SDLK_PAGEDOWN = 281,\n    SDLK_F1 = 282,\n    SDLK_F2 = 283,\n    SDLK_F3 = 284,\n    SDLK_F4 = 285,\n    SDLK_F5 = 286,\n    SDLK_F6 = 287,\n    SDLK_F7 = 288,\n    SDLK_F8 = 289,\n    SDLK_F9 = 290,\n    SDLK_F10 = 291,\n    SDLK_F11 = 292,\n    SDLK_F12 = 293,\n    SDLK_F13 = 294,\n    SDLK_F14 = 295,\n    SDLK_F15 = 296,\n    SDLK_NUMLOCK = 300,\n    SDLK_CAPSLOCK = 301,\n    SDLK_SCROLLOCK = 302,\n    SDLK_RSHIFT = 303,\n    SDLK_LSHIFT = 304,\n    SDLK_RCTRL = 305,\n    SDLK_LCTRL = 306,\n    SDLK_RALT = 307,\n    SDLK_LALT = 308,\n    SDLK_RMETA = 309,\n    SDLK_LMETA = 310,\n    SDLK_LSUPER = 311,\n    SDLK_RSUPER = 312,\n    SDLK_MODE = 313,\n    SDLK_COMPOSE = 314,\n    SDLK_HELP = 315,\n    SDLK_PRINT = 316,\n    SDLK_SYSREQ = 317,\n    SDLK_BREAK = 318,\n    SDLK_MENU = 319,\n    SDLK_POWER = 320,\n    SDLK_EURO = 321,\n    SDLK_UNDO = 322,\n    SDLK_LAST = 323,\n  } sym;\n  enum {\n    KMOD_NONE = 0,\n    KMOD_LSHIFT = 1,\n    KMOD_RSHIFT = 2,\n    KMOD_LCTRL = 64,\n    KMOD_RCTRL = 128,\n    KMOD_LALT = 256,\n    KMOD_RALT = 512,\n    KMOD_LMETA = 1024,\n    KMOD_RMETA = 2048,\n    KMOD_NUM = 4096,\n    KMOD_CAPS = 8192,\n    KMOD_MODE = 16384,\n    KMOD_RESERVED = 32768,\n  } mod;\n  short unsigned int unicode;\n};\ntypedef enum {\n  SDL_NOEVENT = 0,\n  SDL_ACTIVEEVENT = 1,\n  SDL_KEYDOWN = 2,\n  SDL_KEYUP = 3,\n  SDL_MOUSEMOTION = 4,\n  SDL_MOUSEBUTTONDOWN = 5,\n  SDL_MOUSEBUTTONUP = 6,\n  SDL_JOYAXISMOTION = 7,\n  SDL_JOYBALLMOTION = 8,\n  SDL_JOYHATMOTION = 9,\n  SDL_JOYBUTTONDOWN = 10,\n  SDL_JOYBUTTONUP = 11,\n  SDL_QUIT = 12,\n  SDL_SYSWMEVENT = 13,\n  SDL_EVENT_RESERVEDA = 14,\n  SDL_EVENT_RESERVEDB = 15,\n  SDL_VIDEORESIZE = 16,\n  SDL_VIDEOEXPOSE = 17,\n  SDL_EVENT_RESERVED2 = 18,\n  SDL_EVENT_RESERVED3 = 19,\n  SDL_EVENT_RESERVED4 = 20,\n  SDL_EVENT_RESERVED5 = 21,\n  SDL_EVENT_RESERVED6 = 22,\n  SDL_EVENT_RESERVED7 = 23,\n  SDL_USEREVENT = 24,\n  SDL_NUMEVENTS = 32,\n} SDL_EventType;\ntypedef enum {\n  SDL_ACTIVEEVENTMASK = 2,\n  SDL_KEYDOWNMASK = 4,\n  SDL_KEYUPMASK = 8,\n  SDL_KEYEVENTMASK = 12,\n  SDL_MOUSEMOTIONMASK = 16,\n  SDL_MOUSEBUTTONDOWNMASK = 32,\n  SDL_MOUSEBUTTONUPMASK = 64,\n  SDL_MOUSEEVENTMASK = 112,\n  SDL_JOYAXISMOTIONMASK = 128,\n  SDL_JOYBALLMOTIONMASK = 256,\n  SDL_JOYHATMOTIONMASK = 512,\n  SDL_JOYBUTTONDOWNMASK = 1024,\n  SDL_JOYBUTTONUPMASK = 2048,\n  SDL_JOYEVENTMASK = 3968,\n  SDL_VIDEORESIZEMASK = 65536,\n  SDL_VIDEOEXPOSEMASK = 131072,\n  SDL_QUITMASK = 4096,\n  SDL_SYSWMEVENTMASK = 8192,\n} SDL_EventMask;\nstruct SDL_ActiveEvent {\n  unsigned char type;\n  unsigned char gain;\n  unsigned char state;\n};\nstruct SDL_KeyboardEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char state;\n  struct SDL_keysym keysym;\n};\nstruct SDL_MouseMotionEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char state;\n  short unsigned int x;\n  short unsigned int y;\n  short int xrel;\n  short int yrel;\n};\nstruct SDL_MouseButtonEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char button;\n  unsigned char state;\n  short unsigned int x;\n  short unsigned int y;\n};\nstruct SDL_JoyAxisEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char axis;\n  short int value;\n};\nstruct SDL_JoyBallEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char ball;\n  short int xrel;\n  short int yrel;\n};\nstruct SDL_JoyHatEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char hat;\n  unsigned char value;\n};\nstruct SDL_JoyButtonEvent {\n  unsigned char type;\n  unsigned char which;\n  unsigned char button;\n  unsigned char state;\n};\nstruct SDL_ResizeEvent {\n  unsigned char type;\n  int w;\n  int h;\n};\nstruct SDL_ExposeEvent {\n  unsigned char type;\n};\nstruct SDL_QuitEvent {\n  unsigned char type;\n};\nstruct SDL_UserEvent {\n  unsigned char type;\n  int code;\n  void *data1;\n  void *data2;\n};\nstruct SDL_SysWMEvent {\n  unsigned char type;\n  struct SDL_SysWMmsg *msg;\n};\nunion SDL_Event {\n  unsigned char type;\n  struct SDL_ActiveEvent active;\n  struct SDL_KeyboardEvent key;\n  struct SDL_MouseMotionEvent motion;\n  struct SDL_MouseButtonEvent button;\n  struct SDL_JoyAxisEvent jaxis;\n  struct SDL_JoyBallEvent jball;\n  struct SDL_JoyHatEvent jhat;\n  struct SDL_JoyButtonEvent jbutton;\n  struct SDL_ResizeEvent resize;\n  struct SDL_ExposeEvent expose;\n  struct SDL_QuitEvent quit;\n  struct SDL_UserEvent user;\n  struct SDL_SysWMEvent syswm;\n};\nstruct SDL_Rect {\n  short int x;\n  short int y;\n  short unsigned int w;\n  short unsigned int h;\n};\nstruct SDL_Color {\n  unsigned char r;\n  unsigned char g;\n  unsigned char b;\n  unsigned char unused;\n};\nstruct SDL_Palette {\n  int ncolors;\n  struct SDL_Color *colors;\n};\nstruct SDL_PixelFormat {\n  struct SDL_Palette *palette;\n  unsigned char BitsPerPixel;\n  unsigned char BytesPerPixel;\n  unsigned char Rloss;\n  unsigned char Gloss;\n  unsigned char Bloss;\n  unsigned char Aloss;\n  unsigned char Rshift;\n  unsigned char Gshift;\n  unsigned char Bshift;\n  unsigned char Ashift;\n  unsigned int Rmask;\n  unsigned int Gmask;\n  unsigned int Bmask;\n  unsigned int Amask;\n  unsigned int colorkey;\n  unsigned char alpha;\n};\nstruct SDL_Surface {\n  unsigned int flags;\n  struct SDL_PixelFormat *format;\n  int w;\n  int h;\n  short unsigned int pitch;\n  void *pixels;\n  int offset;\n  struct private_hwdata *hwdata;\n  struct SDL_Rect clip_rect;\n  unsigned int unused1;\n  unsigned int locked;\n  struct SDL_BlitMap *map;\n  unsigned int format_version;\n  int refcount;\n};\nint SDL_Init(unsigned int) __attribute__((visibility(\"default\")));\nunsigned int SDL_WasInit(unsigned int) __attribute__((visibility(\"default\")));\nvoid SDL_Quit(void) __attribute__((visibility(\"default\")));\nstruct SDL_Surface *SDL_SetVideoMode(int, int, int, unsigned int) __attribute__((visibility(\"default\")));\nint SDL_EnableKeyRepeat(int, int) __attribute__((visibility(\"default\")));\nint SDL_WaitEvent(union SDL_Event *) __attribute__((visibility(\"default\")));\nint SDL_PollEvent(union SDL_Event *) __attribute__((visibility(\"default\")));\nunsigned int SDL_GetTicks(void) __attribute__((visibility(\"default\")));\nvoid SDL_Delay(unsigned int) __attribute__((visibility(\"default\")));\nint SDL_LockSurface(struct SDL_Surface *) __attribute__((visibility(\"default\")));\nvoid SDL_UnlockSurface(struct SDL_Surface *) __attribute__((visibility(\"default\")));\nint SDL_FillRect(struct SDL_Surface *, struct SDL_Rect *, unsigned int) __attribute__((visibility(\"default\")));\nint SDL_Flip(struct SDL_Surface *) __attribute__((visibility(\"default\")));\nunsigned int SDL_MapRGB(const struct SDL_PixelFormat *const, const unsigned char, const unsigned char, const unsigned char) __attribute__((visibility(\"default\")));\nstatic const int SDL_INIT_TIMER = 1;\nstatic const int SDL_INIT_AUDIO = 16;\nstatic const int SDL_INIT_VIDEO = 32;\nstatic const int SDL_INIT_CDROM = 256;\nstatic const int SDL_INIT_JOYSTICK = 512;\nstatic const int SDL_INIT_NOPARACHUTE = 1048576;\nstatic const int SDL_INIT_EVENTTHREAD = 16777216;\nstatic const int SDL_INIT_EVERYTHING = 65535;\nstatic const int SDL_SWSURFACE = 0;\nstatic const int SDL_HWSURFACE = 1;\nstatic const int SDL_ASYNCBLIT = 4;\nstatic const int SDL_ANYFORMAT = 268435456;\nstatic const int SDL_HWPALETTE = 536870912;\nstatic const int SDL_DOUBLEBUF = 1073741824;\nstatic const int SDL_FULLSCREEN = 2147483648;\nstatic const int SDL_OPENGL = 2;\nstatic const int SDL_OPENGLBLIT = 10;\nstatic const int SDL_RESIZABLE = 16;\nstatic const int SDL_NOFRAME = 32;\nstatic const int SDL_HWACCEL = 256;\nstatic const int SDL_SRCCOLORKEY = 4096;\nstatic const int SDL_RLEACCELOK = 8192;\nstatic const int SDL_RLEACCEL = 16384;\nstatic const int SDL_SRCALPHA = 65536;\nstatic const int SDL_PREALLOC = 16777216;\n]]\n"
  },
  {
    "path": "ffi/blitbuffer.lua",
    "content": "--[[\nGeneric blitbuffer/GFX stuff that works on memory buffers\n--]]\n\nlocal ffi = require(\"ffi\")\nlocal util = require(\"ffi/util\")\n\n-- we will use this extensively\nlocal floor = math.floor\nlocal rshift = bit.rshift\nlocal lshift = bit.lshift\nlocal band = bit.band\nlocal bor = bit.bor\nlocal bxor = bit.bxor\n\nlocal intt = ffi.typeof(\"int\")\nlocal uint32pt = ffi.typeof(\"uint32_t*\")\nlocal uint8pt = ffi.typeof(\"uint8_t*\")\nlocal posix = require(\"ffi/posix_h\")\n\n-- the following definitions are redundant.\n-- they need to be since only this way we can set\n-- different metatables for them.\nffi.cdef[[\ntypedef struct Color4L {\n    uint8_t a;\n} Color4L;\ntypedef struct Color4U {\n    uint8_t a;\n} Color4U;\ntypedef struct Color8 {\n    uint8_t a;\n} Color8;\ntypedef struct Color8A {\n    uint8_t a;\n    uint8_t dummy; // only support pre-multiplied for now\n} Color8A;\ntypedef struct ColorRGB16 {\n    uint16_t v;\n} ColorRGB16;\ntypedef struct ColorRGB24 {\n    uint8_t r;\n    uint8_t g;\n    uint8_t b;\n} ColorRGB24;\ntypedef struct ColorRGB32 {\n    uint8_t r;\n    uint8_t g;\n    uint8_t b;\n    uint8_t a;\n} ColorRGB32;\ntypedef struct ColorBGR32 {\n    uint8_t r;\n    uint8_t g;\n    uint8_t b;\n    uint8_t a;\n} ColorBGR32;\n\ntypedef struct BlitBuffer4 {\n    int w;\n    int h;\n    int pitch;\n    uint8_t *data;\n    uint8_t config;\n} BlitBuffer4;\ntypedef struct BlitBuffer8 {\n    int w;\n    int h;\n    int pitch;\n    Color8 *data;\n    uint8_t config;\n} BlitBuffer8;\ntypedef struct BlitBuffer8A {\n    int w;\n    int h;\n    int pitch;\n    Color8A *data;\n    uint8_t config;\n} BlitBuffer8A;\ntypedef struct BlitBufferRGB16 {\n    int w;\n    int h;\n    int pitch;\n    ColorRGB16 *data;\n    uint8_t config;\n} BlitBufferRGB16;\ntypedef struct BlitBufferRGB24 {\n    int w;\n    int h;\n    int pitch;\n    ColorRGB24 *data;\n    uint8_t config;\n} BlitBufferRGB24;\ntypedef struct BlitBufferRGB32 {\n    int w;\n    int h;\n    int pitch;\n    ColorRGB32 *data;\n    uint8_t config;\n} BlitBufferRGB32;\ntypedef struct BlitBufferBGR32 {\n    int w;\n    int h;\n    int pitch;\n    ColorBGR32 *data;\n    uint8_t config;\n} BlitBufferBGR32;\n\nvoid *malloc(int size);\nvoid free(void *ptr);\n]]\n\n-- color value types\nlocal Color4U = ffi.typeof(\"Color4U\")\nlocal Color4L = ffi.typeof(\"Color4L\")\nlocal Color8 = ffi.typeof(\"Color8\")\nlocal Color8A = ffi.typeof(\"Color8A\")\nlocal ColorRGB16 = ffi.typeof(\"ColorRGB16\")\nlocal ColorRGB24 = ffi.typeof(\"ColorRGB24\")\nlocal ColorRGB32 = ffi.typeof(\"ColorRGB32\")\nlocal ColorBGR32 = ffi.typeof(\"ColorBGR32\")\n\n-- color value pointer types\nlocal P_Color4U = ffi.typeof(\"Color4U*\")\nlocal P_Color4L = ffi.typeof(\"Color4L*\")\nlocal P_Color8 = ffi.typeof(\"Color8*\")\nlocal P_Color8A = ffi.typeof(\"Color8A*\")\nlocal P_ColorRGB16 = ffi.typeof(\"ColorRGB16*\")\nlocal P_ColorRGB24 = ffi.typeof(\"ColorRGB24*\")\nlocal P_ColorRGB32 = ffi.typeof(\"ColorRGB32*\")\nlocal P_ColorBGR32 = ffi.typeof(\"ColorBGR32*\")\n\n-- metatables for color types:\nlocal Color4L_mt = {__index={}}\nlocal Color4U_mt = {__index={}}\nlocal Color8_mt = {__index={}}\nlocal Color8A_mt = {__index={}}\nlocal ColorRGB16_mt = {__index={}}\nlocal ColorRGB24_mt = {__index={}}\nlocal ColorRGB32_mt = {__index={}}\nlocal ColorBGR32_mt = {__index={}}\n\n-- color setting\nfunction Color4L_mt.__index:set(color)\n    self.a = bor(band(0xF0, self.a), color:getColor4L().a)\nend\nfunction Color4U_mt.__index:set(color)\n    self.a = bor(band(0x0F, self.a), color:getColor4U().a)\nend\nfunction Color8_mt.__index:set(color) self.a = color:getColor8().a end\nfunction Color8A_mt.__index:set(color) self.a = color:getColor8A().a end\nfunction ColorRGB16_mt.__index:set(color) self.v = color:getColorRGB16().v end\nfunction ColorRGB24_mt.__index:set(color)\n    local c = color:getColorRGB24()\n    self.r = c.r\n    self.g = c.g\n    self.b = c.b\nend\nfunction ColorRGB32_mt.__index:set(color)\n    local c = color:getColorRGB32()\n    self.r = c.r\n    self.g = c.g\n    self.b = c.b\nend\nfunction ColorBGR32_mt.__index:set(color)\n    local c = color:getColorBGR32()\n    self.r = c.r\n    self.g = c.g\n    self.b = c.b\nend\n-- adding two colors:\nfunction Color4L_mt.__index:add(color, intensity)\n    local value = tonumber(self.a) * (1-intensity) + tonumber(color:getColor4L().a) * intensity\n    if value > 0x0F then value = 0x0F end\n    self:set(Color4L(value))\nend\nfunction Color4U_mt.__index:add(color, intensity)\n    local orig = band(self.a, 0xF0)\n    local value = tonumber(orig) * (1-intensity) + tonumber(color:getColor4U().a) * intensity\n    if value > 0xF0 then value = 0xF0 end\n    self:set(Color4U(band(0xF0, value)))\nend\nfunction Color8_mt.__index:add(color, intensity)\n    local value = tonumber(self.a) * (1-intensity) + tonumber(color:getColor8().a) * intensity\n    if value > 0xFF then value = 0xFF end\n    self:set(Color8(value))\nend\nColor8A_mt.__index.add = Color8_mt.__index.add\nfunction ColorRGB16_mt.__index:add(color, intensity)\n    local r = tonumber(self:getR()) * (1-intensity) + tonumber(color:getR()) * intensity\n    if r > 255 then r = 255 end\n    local g = tonumber(self:getG()) * (1-intensity) + tonumber(color:getG()) * intensity\n    if g > 255 then g = 255 end\n    local b = tonumber(self:getB()) * (1-intensity) + tonumber(color:getB()) * intensity\n    if b > 255 then b = 255 end\n    self:set(ColorRGB24(r, g, b))\nend\nColorRGB24_mt.__index.add = ColorRGB16_mt.__index.add\nColorRGB32_mt.__index.add = ColorRGB16_mt.__index.add\nColorBGR32_mt.__index.add = ColorRGB16_mt.__index.add\n\n-- dimming\nfunction Color4L_mt.__index:dim()\n    return Color8(rshift(self:getColor8().a, 1))\nend\nColor4U_mt.__index.dim = Color4L_mt.__index.dim\nColor8_mt.__index.dim = Color4L_mt.__index.dim\nColor8A_mt.__index.dim = Color4L_mt.__index.dim\nColorRGB16_mt.__index.dim = Color4L_mt.__index.dim\nColorRGB24_mt.__index.dim = Color4L_mt.__index.dim\nColorRGB32_mt.__index.dim = Color4L_mt.__index.dim\nColorBGR32_mt.__index.dim = Color4L_mt.__index.dim\n-- lighten up\nfunction Color4L_mt.__index:lighten(low)\n    local value = self:getColor4L().a\n    low = low * 0x0F\n    if value < low then\n        return Color4L(low)\n    else\n        return self\n    end\nend\nColor4U_mt.__index.lighten = Color4L_mt.__index.lighten\nColor8_mt.__index.lighten = Color4L_mt.__index.lighten\nColor8A_mt.__index.lighten = Color4L_mt.__index.lighten\nColorRGB16_mt.__index.lighten = Color4L_mt.__index.lighten\nColorRGB24_mt.__index.lighten = Color4L_mt.__index.lighten\nColorRGB32_mt.__index.lighten = Color4L_mt.__index.lighten\nColorBGR32_mt.__index.lighten = Color4L_mt.__index.lighten\n\n-- color conversions:\n-- to Color4L:\nfunction Color4L_mt.__index:getColor4L() return Color4L(band(0x0F, self.a)) end\nfunction Color4U_mt.__index:getColor4L() return Color4L(rshift(self.a, 4)) end\nfunction Color8_mt.__index:getColor4L() return Color4L(rshift(self.a, 4)) end\nfunction Color8A_mt.__index:getColor4L() return Color4L(rshift(self.a, 4)) end\n--[[\nUses luminance match for approximating the human perception of colour, as per\nhttp://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale\n\nL = 0.299*Red + 0.587*Green + 0.114*Blue\n--]]\nfunction ColorRGB16_mt.__index:getColor4L()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5, 0x3F))\n    local b = band(self.v, 0x001F)\n    return Color4L(rshift(39190*r + 38469*g + 14942*b, 18))\nend\nfunction ColorRGB24_mt.__index:getColor4L()\n    return Color4L(rshift(4897*self.r + 9617*self.g + 1868*self.b, 18))\nend\nColorRGB32_mt.__index.getColor4L = ColorRGB24_mt.__index.getColor4L\nColorBGR32_mt.__index.getColor4L = ColorRGB24_mt.__index.getColor4L\n\n-- to Color4U:\nfunction Color4L_mt.__index:getColor4U() return Color4U(lshift(self.a, 4)) end\nfunction Color4U_mt.__index:getColor4U() return Color4U(band(0xF0, self.a)) end\nfunction Color8_mt.__index:getColor4U() return Color4U(band(0xF0, self.a)) end\nfunction Color8A_mt.__index:getColor4U() return Color4U(band(0xF0, self.a)) end\nfunction ColorRGB16_mt.__index:getColor4U()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5, 0x3F))\n    local b = band(self.v, 0x001F)\n    return Color4U(band(0xF0, rshift(39190*r + 38469*g + 14942*b, 14)))\nend\nfunction ColorRGB24_mt.__index:getColor4U()\n    return Color4U(band(0xF0, rshift(4897*self.r + 9617*self.g + 1868*self.b, 14)))\nend\nColorRGB32_mt.__index.getColor4U = ColorRGB24_mt.__index.getColor4U\nColorBGR32_mt.__index.getColor4U = ColorRGB24_mt.__index.getColor4U\n\n-- to Color8:\nfunction Color4L_mt.__index:getColor8()\n    local v = band(0x0F, self.a)\n    return Color8(v*0x11)\nend\nfunction Color4U_mt.__index:getColor8()\n    local v = band(0xF0, self.a)\n    return Color8(bor(rshift(v, 4), v))\nend\nfunction Color8_mt.__index:getColor8() return self end\nfunction Color8A_mt.__index:getColor8() return Color8(self.a) end\nfunction ColorRGB16_mt.__index:getColor8()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5, 0x3F))\n    local b = band(self.v, 0x001F)\n    return Color8(rshift(39190*r + 38469*g + 14942*b, 14))\nend\nfunction ColorRGB24_mt.__index:getColor8()\n    return Color8(rshift(4897*self:getR() + 9617*self:getG() + 1868*self:getB(), 14))\nend\nColorRGB32_mt.__index.getColor8 = ColorRGB24_mt.__index.getColor8\nColorBGR32_mt.__index.getColor8 = ColorRGB24_mt.__index.getColor8\n\n-- to Color8A:\nfunction Color4L_mt.__index:getColor8A()\n    local v = band(0x0F, self.a)\n    return Color8A(v*0x11)\nend\nfunction Color4U_mt.__index:getColor8A()\n    local v = band(0xF0, self.a)\n    return Color8A(bor(rshift(v, 4), v))\nend\nfunction Color8_mt.__index:getColor8A() return Color8A(self.a) end\nfunction Color8A_mt.__index:getColor8A() return self end\nfunction ColorRGB16_mt.__index:getColor8A()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5, 0x3F))\n    local b = band(self.v, 0x001F)\n    return Color8A(rshift(39190*r + 38469*g + 14942*b, 14))\nend\nfunction ColorRGB24_mt.__index:getColor8A()\n    return Color8A(rshift(4897*self:getR() + 9617*self:getG() + 1868*self:getB(), 14))\nend\nColorRGB32_mt.__index.getColor8A = ColorRGB24_mt.__index.getColor8A\nColorBGR32_mt.__index.getColor8A = ColorRGB24_mt.__index.getColor8A\n\n-- to ColorRGB16:\nfunction Color4L_mt.__index:getColorRGB16()\n    local v = self:getColor8().a\n    local v5bit = rshift(v, 3)\n    return ColorRGB16(lshift(v5bit, 11) + lshift(band(v, 0xFC), 3) + v5bit)\nend\nColor4U_mt.__index.getColorRGB16 = Color4L_mt.__index.getColorRGB16\nColor8_mt.__index.getColorRGB16 = Color4L_mt.__index.getColorRGB16\nColor8A_mt.__index.getColorRGB16 = Color4L_mt.__index.getColorRGB16\nfunction ColorRGB16_mt.__index:getColorRGB16() return self end\nfunction ColorRGB24_mt.__index:getColorRGB16()\n    return ColorRGB16(lshift(band(self.r, 0xF8), 8) + lshift(band(self.g, 0xFC), 3)  + rshift(self.b, 3))\nend\nColorRGB32_mt.__index.getColorRGB16 = ColorRGB24_mt.__index.getColorRGB16\nColorBGR32_mt.__index.getColorRGB16 = ColorRGB24_mt.__index.getColorRGB16\n\n-- to ColorRGB24:\nfunction Color4L_mt.__index:getColorRGB24()\n    local v = self:getColor8()\n    return ColorRGB24(v.a, v.a, v.a)\nend\nColor4U_mt.__index.getColorRGB24 = Color4L_mt.__index.getColorRGB24\nColor8_mt.__index.getColorRGB24 = Color4L_mt.__index.getColorRGB24\nColor8A_mt.__index.getColorRGB24 = Color4L_mt.__index.getColorRGB24\nfunction ColorRGB16_mt.__index:getColorRGB24()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5), 0x3F)\n    local b = band(self.v, 0x001F)\n    return ColorRGB24(lshift(r, 3) + rshift(r, 2), lshift(g, 2) + rshift(g, 4), lshift(b, 3) + rshift(b, 2))\nend\nfunction ColorRGB24_mt.__index:getColorRGB24() return self end\nfunction ColorRGB32_mt.__index:getColorRGB24() return ColorRGB24(self.r, self.g, self.b) end\nColorBGR32_mt.__index.getColorRGB24 = ColorRGB32_mt.__index.getColorRGB24\n\n-- to ColorRGB32:\nfunction Color4L_mt.__index:getColorRGB32()\n    local v = self:getColor8()\n    return ColorRGB32(v.a, v.a, v.a, 0)\nend\nColor4U_mt.__index.getColorRGB32 = Color4L_mt.__index.getColorRGB32\nColor8_mt.__index.getColorRGB32 = Color4L_mt.__index.getColorRGB32\nColor8A_mt.__index.getColorRGB32 = Color4L_mt.__index.getColorRGB32\nfunction ColorRGB16_mt.__index:getColorRGB32()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5), 0x3F)\n    local b = band(self.v, 0x001F)\n    return ColorRGB32(lshift(r, 3) + rshift(r, 2), lshift(g, 2) + rshift(g, 4), lshift(b, 3) + rshift(b, 2), 0)\nend\nfunction ColorRGB24_mt.__index:getColorRGB32() return ColorRGB32(self.r, self.g, self.b) end\nfunction ColorRGB32_mt.__index:getColorRGB32() return self end\nfunction ColorBGR32_mt.__index:getColorRGB32() return ColorRGB32(self.r, self.g, self.b) end\n\n-- to ColorBGR32:\nfunction Color4L_mt.__index:getColorBGR32()\n    local v = self:getColor8()\n    return ColorBGR32(v.a, v.a, v.a, 0)\nend\nColor4U_mt.__index.getColorBGR32 = Color4L_mt.__index.getColorBGR32\nColor8_mt.__index.getColorBGR32 = Color4L_mt.__index.getColorBGR32\nColor8A_mt.__index.getColorBGR32 = Color4L_mt.__index.getColorBGR32\nfunction ColorRGB16_mt.__index:getColorBGR32()\n    local r = rshift(self.v, 11)\n    local g = band(rshift(self.v, 5), 0x3F)\n    local b = band(self.v, 0x001F)\n    return ColorBGR32(lshift(b, 3) + rshift(b, 2), lshift(g, 2) + rshift(g, 4), lshift(r, 3) + rshift(r, 2), 0)\nend\nfunction ColorRGB24_mt.__index:getColorBGR32() return ColorBGR32(self.b, self.g, self.r) end\nfunction ColorRGB32_mt.__index:getColorBGR32() return ColorBGR32(self.b, self.g, self.r) end\nfunction ColorBGR32_mt.__index:getColorBGR32() return self end\n\n-- RGB getters (special case for 4bpp mode)\nfunction Color4L_mt.__index:getR() return self:getColor8().a end\nColor4L_mt.__index.getG = Color4L_mt.__index.getR\nColor4L_mt.__index.getB = Color4L_mt.__index.getR\nColor4U_mt.__index.getR = Color4L_mt.__index.getR\nColor4U_mt.__index.getG = Color4L_mt.__index.getR\nColor4U_mt.__index.getB = Color4L_mt.__index.getR\nColor8_mt.__index.getR = Color4L_mt.__index.getR\nColor8_mt.__index.getG = Color4L_mt.__index.getR\nColor8_mt.__index.getB = Color4L_mt.__index.getR\nColor8A_mt.__index.getR = Color4L_mt.__index.getR\nColor8A_mt.__index.getG = Color4L_mt.__index.getR\nColor8A_mt.__index.getB = Color4L_mt.__index.getR\nfunction ColorRGB16_mt.__index:getR()\n    local r = rshift(self.v, 11)\n    return lshift(r, 3) + rshift(r, 2)\nend\nfunction ColorRGB16_mt.__index:getG()\n    local g = band(rshift(self.v, 5, 0x3F))\n    return lshift(g, 2) + rshift(g, 4)\nend\nfunction ColorRGB16_mt.__index:getB()\n    local b = band(self.v, 0x001F)\n    return lshift(b, 3) + rshift(b, 2)\nend\nfunction ColorRGB24_mt.__index:getR() return self.r end\nfunction ColorRGB24_mt.__index:getG() return self.g end\nfunction ColorRGB24_mt.__index:getB() return self.b end\nColorRGB32_mt.__index.getR = ColorRGB24_mt.__index.getR\nColorRGB32_mt.__index.getG = ColorRGB24_mt.__index.getG\nColorRGB32_mt.__index.getB = ColorRGB24_mt.__index.getB\nfunction ColorRGB32_mt.__index:getAlpha() return self.a end\nColorBGR32_mt.__index.getR = ColorRGB24_mt.__index.getR\nColorBGR32_mt.__index.getG = ColorRGB24_mt.__index.getG\nColorBGR32_mt.__index.getB = ColorRGB24_mt.__index.getB\nfunction ColorBGR32_mt.__index:getAlpha() return self.a end\n\n-- modifications:\n-- inversion:\nfunction Color4L_mt.__index:invert() return Color4L(bxor(self.a, 0x0F)) end\nfunction Color4U_mt.__index:invert() return Color4U(bxor(self.a, 0xF0)) end\nfunction Color8_mt.__index:invert() return Color8(bxor(self.a, 0xFF)) end\nfunction Color8A_mt.__index:invert() return Color8A(bxor(self.a, 0xFF)) end\nfunction ColorRGB16_mt.__index:invert() return ColorRGB16(bxor(self.v, 0xFFFF)) end\nfunction ColorRGB24_mt.__index:invert()\n    return ColorRGB24(bxor(self.r, 0xFF), bxor(self.g, 0xFF), bxor(self.b, 0xFF))\nend\nfunction ColorRGB32_mt.__index:invert()\n    return ColorRGB32(bxor(self.r, 0xFF), bxor(self.g, 0xFF), bxor(self.b, 0xFF))\nend\nfunction ColorBGR32_mt.__index:invert()\n    return ColorBGR32(bxor(self.b, 0xFF), bxor(self.g, 0xFF), bxor(self.r, 0xFF))\nend\n\n-- comparison:\nfunction Color4L_mt.__index:isEqual(c)\n    return self:getR() == c:getR()\nend\nColor4U_mt.__index.isEqual = Color4L_mt.__index.isEqual\nColor8_mt.__index.isEqual = Color4L_mt.__index.isEqual\nColor8A_mt.__index.isEqual = Color4L_mt.__index.isEqual\nfunction ColorRGB24_mt.__index:isEqual(c)\n    return (self:getR() == c:getR())\n    and (self:getG() == c:getG())\n    and (self:getB() == c:getB())\nend\nColorRGB16_mt.__index.isEqual = ColorRGB24_mt.__index.isEqual\nfunction ColorRGB32_mt.__index:isEqual(c)\n    return (self:getR() == c:getR())\n    and (self:getG() == c:getG())\n    and (self:getB() == c:getB())\n    and (self:getAlpha() == c:getAlpha())\nend\nColorBGR32_mt.__index.isEqual = ColorRGB32_mt.__index.isEqual\n\nlocal MASK_ALLOCATED = 0x01\nlocal SHIFT_ALLOCATED = 0\nlocal MASK_INVERSE = 0x02\nlocal SHIFT_INVERSE = 1\nlocal MASK_ROTATED = 0x0C\nlocal SHIFT_ROTATED = 2\nlocal MASK_TYPE = 0xF0\nlocal SHIFT_TYPE = 4\n\nlocal TYPE_BB4 = 0\nlocal TYPE_BB8 = 1\nlocal TYPE_BB8A = 2\nlocal TYPE_BBRGB16 = 3\nlocal TYPE_BBRGB24 = 4\nlocal TYPE_BBRGB32 = 5\nlocal TYPE_BBBGR32 = 6\n\nlocal BB = {}\n\n-- metatables for BlitBuffer objects:\nlocal BB4_mt = {__index={}}\nlocal BB8_mt = {__index={}}\nlocal BB8A_mt = {__index={}}\nlocal BBRGB16_mt = {__index={}}\nlocal BBRGB24_mt = {__index={}}\nlocal BBRGB32_mt = {__index={}}\nlocal BBBGR32_mt = {__index={}}\n\n-- this is like a metatable for the others,\n-- but we don't make it a metatable because LuaJIT\n-- doesn't cope well with ctype metatables with\n-- metatables on them\n-- we just replicate what's in the following table\n-- when we set the other metatables for their types\nlocal BB_mt = {__index={}}\n\nfunction BB_mt.__index:getRotation()\n    return rshift(band(MASK_ROTATED, self.config), SHIFT_ROTATED)\nend\nfunction BB_mt.__index:setRotation(rotation_mode)\n    self.config = bor(band(self.config, bxor(MASK_ROTATED, 0xFF)), lshift(rotation_mode, SHIFT_ROTATED))\nend\nfunction BB_mt.__index:rotateAbsolute(degree)\n    local mode = (degree % 360) / 90\n    self:setRotation(mode)\n    return self\nend\nfunction BB_mt.__index:rotate(degree)\n    degree = degree + self:getRotation()*90\n    return self:rotateAbsolute(degree)\nend\nfunction BB_mt.__index:getInverse()\n    return rshift(band(MASK_INVERSE, self.config), SHIFT_INVERSE)\nend\nfunction BB_mt.__index:setInverse(inverse)\n    self.config = bor(band(self.config, bxor(MASK_INVERSE, 0xFF)), lshift(inverse, SHIFT_INVERSE))\nend\nfunction BB_mt.__index:invert()\n    self:setInverse((self:getInverse() + 1) % 2)\n    return self\nend\nfunction BB_mt.__index:getAllocated()\n    return rshift(band(MASK_ALLOCATED, self.config), SHIFT_ALLOCATED)\nend\nfunction BB_mt.__index:setAllocated(allocated)\n    self.config = bor(band(self.config, bxor(MASK_ALLOCATED, 0xFF)), lshift(allocated, SHIFT_ALLOCATED))\nend\nfunction BB_mt.__index:getType()\n    return rshift(band(MASK_TYPE, self.config), SHIFT_TYPE)\nend\nfunction BB4_mt.__index:getBpp() return 4 end\nfunction BB8_mt.__index:getBpp() return 8 end\nfunction BB8A_mt.__index:getBpp() return 8 end\nfunction BBRGB16_mt.__index:getBpp() return 16 end\nfunction BBRGB24_mt.__index:getBpp() return 24 end\nfunction BBRGB32_mt.__index:getBpp() return 32 end\nfunction BBBGR32_mt.__index:getBpp() return 32 end\nfunction BB_mt.__index:isRGB()\n    local bb_type = self:getType()\n    if bb_type == TYPE_BBRGB16\n        or bb_type == TYPE_BBRGB24\n        or bb_type == TYPE_BBRGB32 then\n        return true\n    end\n    return false\nend\nfunction BB_mt.__index:setType(type_id)\n    self.config = bor(band(self.config, bxor(MASK_TYPE, 0xFF)), lshift(type_id, SHIFT_TYPE))\nend\nfunction BB_mt.__index:getPhysicalCoordinates(x, y)\n    local rotation = self:getRotation()\n    if rotation == 0 then\n        return x, y\n    elseif rotation == 1 then\n        return self.w - y - 1, x\n    elseif rotation == 2 then\n        return self.w - x - 1, self.h - y - 1\n    elseif rotation == 3 then\n        return y, self.h - x - 1\n    end\nend\nfunction BB_mt.__index:getPhysicalRect(x, y, w, h)\n    local px1, py1 = self:getPhysicalCoordinates(x, y)\n    local px2, py2 = self:getPhysicalCoordinates(x+w-1, y+h-1)\n    if self:getRotation() % 2 == 1 then w, h = h, w end\n    return math.min(px1, px2), math.min(py1, py2), w, h\nend\n\n-- physical coordinate checking\nfunction BB_mt.__index:checkCoordinates(x, y)\n    assert(x >= 0, \"x coordinate >= 0\")\n    assert(y >= 0, \"y coordinate >= 0\")\n    assert(x < self.w, \"x coordinate < width\")\n    assert(y < self.h, \"y coordinate < height\")\nend\n\n-- getPixelP (pointer) routines, working on physical coordinates\nfunction BB_mt.__index:getPixelP(x, y)\n    --self:checkCoordinates(x, y)\n    return ffi.cast(self.data, ffi.cast(uint8pt, self.data) + self.pitch*y) + x\nend\nfunction BB4_mt.__index:getPixelP(x, y)\n    --self:checkCoordinates(x, y)\n    local p = self.data + self.pitch*y + rshift(x, 1)\n    if band(x, 1) == 0 then\n        return ffi.cast(P_Color4U, p)\n    else\n        return ffi.cast(P_Color4L, p)\n    end\nend\n\nfunction BB_mt.__index:getPixel(x, y)\n    local px, py = self:getPhysicalCoordinates(x, y)\n    local color = self:getPixelP(px, py)[0]\n    if self:getInverse() == 1 then color = color:invert() end\n    return color\nend\n\n-- blitbuffer specific color conversions\nfunction BB4_mt.__index.getMyColor(color) return color:getColor4L() end\nfunction BB8_mt.__index.getMyColor(color) return color:getColor8() end\nfunction BB8A_mt.__index.getMyColor(color) return color:getColor8A() end\nfunction BBRGB16_mt.__index.getMyColor(color) return color:getColorRGB16() end\nfunction BBRGB24_mt.__index.getMyColor(color) return color:getColorRGB24() end\nfunction BBRGB32_mt.__index.getMyColor(color) return color:getColorRGB32() end\nfunction BBBGR32_mt.__index.getMyColor(color) return color:getColorBGR32() end\n\n-- set pixel values\nfunction BB_mt.__index:setPixel(x, y, color)\n    local px, py = self:getPhysicalCoordinates(x, y)\n    if self:getInverse() == 1 then color = color:invert() end\n    self:getPixelP(px, py)[0]:set(color)\nend\nfunction BB_mt.__index:setPixelAdd(x, y, color, intensity)\n    local px, py = self:getPhysicalCoordinates(x, y)\n    if self:getInverse() == 1 then color = color:invert() end\n    self:getPixelP(px, py)[0]:add(color, intensity)\nend\nfunction BB_mt.__index:setPixelInverted(x, y, color)\n    self:setPixel(x, y, color:invert())\nend\n\n-- checked Pixel setting:\nfunction BB_mt.__index:setPixelClamped(x, y, color)\n    if x >= 0 and x < self:getWidth() and y >= 0 and y < self:getHeight() then\n        self:setPixel(x, y, color)\n    end\nend\n\n-- functions for accessing dimensions\nfunction BB_mt.__index:getWidth()\n    if 0 == bit.band(1, self:getRotation()) then\n        return self.w\n    else\n        return self.h\n    end\nend\nfunction BB_mt.__index:getHeight()\n    if 0 == bit.band(1, self:getRotation()) then\n        return self.h\n    else\n        return self.w\n    end\nend\n\n-- names of optimized blitting routines\nBB_mt.__index.blitfunc = \"blitDefault\" -- not optimized\nBB4_mt.__index.blitfunc = \"blitTo4\"\nBB8_mt.__index.blitfunc = \"blitTo8\"\nBB8A_mt.__index.blitfunc = \"blitTo8A\"\nBBRGB16_mt.__index.blitfunc = \"blitToRGB16\"\nBBRGB24_mt.__index.blitfunc = \"blitToRGB24\"\nBBRGB32_mt.__index.blitfunc = \"blitToRGB32\"\nBBBGR32_mt.__index.blitfunc = \"blitToBGR32\"\n\n--[[\ngeneric boundary check for copy operations\n\n@param length length of copy operation\n@param target_offset where to place part into target\n@param source_offset where to take part from in source\n@param target_size length of target buffer\n@param source_size length of source buffer\n\n@return adapted length that actually fits\n@return adapted target offset, guaranteed within range 0..(target_size-1)\n@return adapted source offset, guaranteed within range 0..(source_size-1)\n--]]\nfunction BB.checkBounds(length, target_offset, source_offset, target_size, source_size)\n    -- deal with negative offsets\n    if target_offset < 0 then\n        length = length + target_offset\n        source_offset = source_offset - target_offset\n        target_offset = 0\n    end\n    if source_offset < 0 then\n        length = length + source_offset\n        target_offset = target_offset - source_offset\n        source_offset = 0\n    end\n    -- calculate maximum lengths (size left starting at offset)\n    local target_left = target_size - target_offset\n    local source_left = source_size - source_offset\n    -- return corresponding values\n    if target_left <= 0 or source_left <= 0 then\n        return 0, 0, 0\n    elseif length <= target_left and length <= source_left then\n        -- length is the smallest value\n        return floor(length), floor(target_offset), floor(source_offset)\n    elseif target_left < length and target_left < source_left then\n        -- target_left is the smalles value\n        return floor(target_left), floor(target_offset), floor(source_offset)\n    else\n        -- source_left must be the smallest value\n        return floor(source_left), floor(target_offset), floor(source_offset)\n    end\nend\n\nfunction BB_mt.__index:blitDefault(dest, dest_x, dest_y, offs_x, offs_y, width, height, setter, set_param)\n    -- slow default variant:\n    local o_y = offs_y\n    for y = dest_y, dest_y+height-1 do\n        local o_x = offs_x\n        for x = dest_x, dest_x+width-1 do\n            setter(dest, x, y, self:getPixel(o_x, o_y), set_param)\n            o_x = o_x + 1\n        end\n        o_y = o_y + 1\n    end\nend\n-- no optimized blitting by default:\nBB_mt.__index.blitTo4 = BB_mt.__index.blitDefault\nBB_mt.__index.blitTo8 = BB_mt.__index.blitDefault\nBB_mt.__index.blitTo8A = BB_mt.__index.blitDefault\nBB_mt.__index.blitToRGB16 = BB_mt.__index.blitDefault\nBB_mt.__index.blitToRGB24 = BB_mt.__index.blitDefault\nBB_mt.__index.blitToRGB32 = BB_mt.__index.blitDefault\nBB_mt.__index.blitToBGR32 = BB_mt.__index.blitDefault\n\nfunction BB_mt.__index:blitFrom(source, dest_x, dest_y, offs_x, offs_y, width, height, setter, set_param)\n    width, height = width or source:getWidth(), height or source:getHeight()\n    width, dest_x, offs_x = BB.checkBounds(width, dest_x or 0, offs_x or 0, self:getWidth(), source:getWidth())\n    height, dest_y, offs_y = BB.checkBounds(height, dest_y or 0, offs_y or 0, self:getHeight(), source:getHeight())\n    if not setter then setter = self.setPixel end\n\n    if width <= 0 or height <= 0 then return end\n    return source[self.blitfunc](source, self, dest_x, dest_y, offs_x, offs_y, width, height, setter, set_param)\nend\nBB_mt.__index.blitFullFrom = BB_mt.__index.blitFrom\n\nfunction BB_mt.__index:addblitFrom(source, dest_x, dest_y, offs_x, offs_y, width, height, intensity)\n    self:blitFrom(source, dest_x, dest_y, offs_x, offs_y, width, height, self.setPixelAdd, intensity)\nend\n\nfunction BB_mt.__index:blitFromRotate(source, degree)\n    self:rotate(degree)\n    self:blitFrom(source, dest_x, dest_y, offs_x, offs_y, width, height, self.setPixel, intensity)\n    self:rotate(-degree)\nend\n\n-- scale method does not modify the original blitbuffer, instead, it allocates\n-- and returns a new scaled blitbuffer.\nfunction BB_mt.__index:scale(new_width, new_height)\n    local self_w, self_h = self:getWidth(), self:getHeight()\n    local scaled_bb = BB.new(new_width, new_height, self:getType())\n    -- uses very simple nearest neighbour scaling\n    for y=0, new_height-1 do\n        for x=0, new_width-1 do\n            scaled_bb:setPixel(x, y,\n            self:getPixel(util.idiv(x*self_w, new_width),\n                          util.idiv(y*self_h, new_height)))\n        end\n    end\n    return scaled_bb\nend\n\n--[[\nexplicit unset\n\nwill free resources immediately\nthis is also called upon garbage collection\n--]]\nfunction BB_mt.__index:free()\n    if band(lshift(1, SHIFT_ALLOCATED), self.config) ~= 0 then\n        self.config = band(self.config, bxor(0xFF, lshift(1, SHIFT_ALLOCATED)))\n        ffi.C.free(self.data)\n    end\nend\n\n--[[\nmemory management\n--]]\nBB_mt.__gc = BB_mt.__index.free\n\n\n--[[\nPAINTING\n--]]\n\n--[[\ninvert a rectangle within the buffer\n\n@param x X coordinate\n@param y Y coordinate\n@param w width\n@param h height\n--]]\nfunction BB_mt.__index:invertRect(x, y, w, h)\n    self:blitFrom(self, x, y, x, y, w, h, self.setPixelInverted)\nend\n\n--[[\npaint a rectangle onto this buffer\n\n@param x X coordinate\n@param y Y coordinate\n@param w width\n@param h height\n@param value color value\n--]]\nfunction BB_mt.__index:paintRect(x, y, w, h, value)\n    -- compatibility:\n    if type(value) == \"number\" then value = Color4L(value) end\n    if w <= 0 or h <= 0 then return end\n    w, x = BB.checkBounds(w, x, 0, self:getWidth(), 0xFFFF)\n    h, y = BB.checkBounds(h, y, 0, self:getHeight(), 0xFFFF)\n    for y = y, y+h-1 do\n        for x = x, x+w-1 do\n            self:setPixel(x, y, value)\n        end\n    end\nend\n\n--[[\npaint a circle onto this buffer\n\n@param x1 X coordinate of the circle's center\n@param y1 Y coordinate of the circle's center\n@param r radius\n@param c color value (defaults to black)\n@param w width of line (defaults to radius)\n--]]\nfunction BB_mt.__index:paintCircle(center_x, center_y, r, c, w)\n    -- compatibility:\n    if type(c) == \"number\" then c = Color4L(c) end\n    if r == 0 then return end\n    if w == nil then w = r end\n    if w > r then w = r end\n\n    -- for outer circle\n    local x = 0\n    local y = r\n    local delta = 5/4 - r\n\n    -- for inner circle\n    local r2 = r - w\n    local x2 = 0\n    local y2 = r2\n    local delta2 = 5/4 - r\n\n    -- draw two axles\n    for tmp_y = r, r2+1, -1 do\n        self:setPixelClamped(center_x+0, center_y+tmp_y, c)\n        self:setPixelClamped(center_x-0, center_y-tmp_y, c)\n        self:setPixelClamped(center_x+tmp_y, center_y+0, c)\n        self:setPixelClamped(center_x-tmp_y, center_y-0, c)\n    end\n\n    while x < y do\n        -- decrease y if we are out of circle\n        x = x + 1;\n        if delta > 0 then\n            y = y - 1\n            delta = delta + 2*x - 2*y + 2\n        else\n            delta = delta + 2*x + 1\n        end\n\n        -- inner circle finished drawing, increase y linearly for filling\n        if x2 > y2 then\n            y2 = y2 + 1\n            x2 = x2 + 1\n        else\n            x2 = x2 + 1\n            if delta2 > 0 then\n                y2 = y2 - 1\n                delta2 = delta2 + 2*x2 - 2*y2 + 2\n            else\n                delta2 = delta2 + 2*x2 + 1\n            end\n        end\n\n        for tmp_y = y, y2+1, -1 do\n            self:setPixelClamped(center_x+x, center_y+tmp_y, c)\n            self:setPixelClamped(center_x+tmp_y, center_y+x, c)\n\n            self:setPixelClamped(center_x+tmp_y, center_y-x, c)\n            self:setPixelClamped(center_x+x, center_y-tmp_y, c)\n\n            self:setPixelClamped(center_x-x, center_y-tmp_y, c)\n            self:setPixelClamped(center_x-tmp_y, center_y-x, c)\n\n            self:setPixelClamped(center_x-tmp_y, center_y+x, c)\n            self:setPixelClamped(center_x-x, center_y+tmp_y, c)\n        end\n    end\n    if r == w then\n        self:setPixelClamped(center_x, center_y, c)\n    end\nend\n\nfunction BB_mt.__index:paintRoundedCorner(off_x, off_y, w, h, bw, r, c)\n    -- compatibility:\n    if type(c) == \"number\" then c = Color4L(c) end\n    if 2*r > h\n        or 2*r > w\n        or r == 0\n        then\n            -- no operation\n            return\n        end\n\n        r = math.min(r, h, w)\n        if bw > r then\n            bw = r\n        end\n\n        -- for outer circle\n        local x = 0\n        local y = r\n        local delta = 5/4 - r\n\n        -- for inner circle\n        local r2 = r - bw\n        local x2 = 0\n        local y2 = r2\n        local delta2 = 5/4 - r\n\n        while x < y do\n            -- decrease y if we are out of circle\n            x = x + 1\n            if delta > 0 then\n                y = y - 1\n                delta = delta + 2*x - 2*y + 2\n            else\n                delta = delta + 2*x + 1\n            end\n\n            -- inner circle finished drawing, increase y linearly for filling\n            if x2 > y2 then\n                y2 = y2 + 1\n                x2 = x2 + 1\n            else\n                x2 = x2 + 1\n                if delta2 > 0 then\n                    y2 = y2 - 1\n                    delta2 = delta2 + 2*x2 - 2*y2 + 2\n                else\n                    delta2 = delta2 + 2*x2 + 1\n                end\n            end\n\n            for tmp_y = y, y2+1, -1 do\n                self:setPixelClamped((w-r)+off_x+x-1, (h-r)+off_y+tmp_y-1, c)\n                self:setPixelClamped((w-r)+off_x+tmp_y-1, (h-r)+off_y+x-1, c)\n\n                self:setPixelClamped((w-r)+off_x+tmp_y-1, (r)+off_y-x, c)\n                self:setPixelClamped((w-r)+off_x+x-1, (r)+off_y-tmp_y, c)\n\n                self:setPixelClamped((r)+off_x-x, (r)+off_y-tmp_y, c)\n                self:setPixelClamped((r)+off_x-tmp_y, (r)+off_y-x, c)\n\n                self:setPixelClamped((r)+off_x-tmp_y, (h-r)+off_y+x-1, c)\n                self:setPixelClamped((r)+off_x-x, (h-r)+off_y+tmp_y-1, c)\n            end\n        end\n    end\n\n    --[[\n    Draw a border\n\n    @x:  start position in x axis\n    @y:  start position in y axis\n    @w:  width of the border\n    @h:  height of the border\n    @bw: line width of the border\n    @c:  color for loading bar\n    @r:  radius of for border's corner (nil or 0 means right corner border)\n    --]]\n    function BB_mt.__index:paintBorder(x, y, w, h, bw, c, r)\n        x, y = math.ceil(x), math.ceil(y)\n        h, w = math.ceil(h), math.ceil(w)\n        if not r or r == 0 then\n            self:paintRect(x, y, w, bw, c)\n            self:paintRect(x, y+h-bw, w, bw, c)\n            self:paintRect(x, y+bw, bw, h - 2*bw, c)\n            self:paintRect(x+w-bw, y+bw, bw, h - 2*bw, c)\n        else\n            if h < 2*r then r = math.floor(h/2) end\n            if w < 2*r then r = math.floor(w/2) end\n            self:paintRoundedCorner(x, y, w, h, bw, r, c)\n            self:paintRect(r+x, y, w-2*r, bw, c)\n            self:paintRect(r+x, y+h-bw, w-2*r, bw, c)\n            self:paintRect(x, r+y, bw, h-2*r, c)\n            self:paintRect(x+w-bw, r+y, bw, h-2*r, c)\n        end\n    end\n\n\n    --[[\n    Fill a rounded corner rectangular area\n\n    @x:  start position in x axis\n    @y:  start position in y axis\n    @w:  width of the area\n    @h:  height of the area\n    @c:  color used to fill the area\n    @r:  radius of for four corners\n    --]]\n    function BB_mt.__index:paintRoundedRect(x, y, w, h, c, r)\n        x, y = math.ceil(x), math.ceil(y)\n        h, w = math.ceil(h), math.ceil(w)\n        if not r or r == 0 then\n            self:paintRect(x, y, w, h, c)\n        else\n            if h < 2*r then r = math.floor(h/2) end\n            if w < 2*r then r = math.floor(w/2) end\n            self:paintBorder(x, y, w, h, r, c, r)\n            self:paintRect(x+r, y+r, w-2*r, h-2*r, c)\n        end\n    end\n\n\n    --[[\n    Draw a progress bar according to following args:\n\n    @x:  start position in x axis\n    @y:  start position in y axis\n    @w:  width for progress bar\n    @h:  height for progress bar\n    @load_m_w: width margin for loading bar\n    @load_m_h: height margin for loading bar\n    @load_percent: progress in percent\n    @c:  color for loading bar\n    --]]\n    function BB_mt.__index:progressBar(x, y, w, h, load_m_w, load_m_h, load_percent, c)\n        if load_m_h*2 > h then\n            load_m_h = h/2\n        end\n        self:paintBorder(x, y, w, h, 2, 15)\n        self:paintRect(x+load_m_w, y+load_m_h,\n        (w-2*load_m_w)*load_percent, (h-2*load_m_h), c)\n    end\n\n\n    --[[\n    dim color values in rectangular area\n\n    @param x X coordinate\n    @param y Y coordinate\n    @param w width\n    @param h height\n    --]]\n    function BB_mt.__index:dimRect(x, y, w, h)\n        if w <= 0 or h <= 0 then return end\n        w, x = BB.checkBounds(w, x, 0, self:getWidth(), 0xFFFF)\n        h, y = BB.checkBounds(h, y, 0, self:getHeight(), 0xFFFF)\n        for y = y, y+h-1 do\n            for x = x, x+w-1 do\n                self:setPixel(x, y, self:getPixel(x, y):dim())\n            end\n        end\n    end\n\n    --[[\n    lighten color values in rectangular area\n\n    @param x X coordinate\n    @param y Y coordinate\n    @param w width\n    @param h height\n    --]]\n    function BB_mt.__index:lightenRect(x, y, w, h, low)\n        if w <= 0 or h <= 0 then return end\n        w, x = BB.checkBounds(w, x, 0, self:getWidth(), 0xFFFF)\n        h, y = BB.checkBounds(h, y, 0, self:getHeight(), 0xFFFF)\n        for y = y, y+h-1 do\n            for x = x, x+w-1 do\n                self:setPixel(x, y, self:getPixel(x, y):lighten(low))\n            end\n        end\n    end\n\n    function BB_mt.__index:copy()\n        local mytype = ffi.typeof(self)\n        local buffer = ffi.C.malloc(self.pitch * self.h)\n        assert(buffer, \"cannot allocate buffer\")\n        ffi.copy(buffer, self.data, self.pitch * self.h)\n        local copy = mytype(self.w, self.h, self.pitch, buffer, self.config)\n        copy:setAllocated(1)\n        return copy\n    end\n\n    --[[\n    write blitbuffer contents to a PAM file\n\n    see http://netpbm.sourceforge.net/doc/pam.html for PAM file specs.\n\n    @param filename the name of the file to be created\n    --]]\n    function BB_mt.__index:writePAM(filename)\n        local f = io.open(filename, \"w\")\n        f:write(\"P7\\n\")\n        f:write(\"# written by blitbuffer.lua\\n\")\n        f:write(\"WIDTH \", self:getWidth(), \"\\n\")\n        f:write(\"HEIGHT \", self:getHeight(), \"\\n\")\n        local bb_type = self:getType()\n        if bb_type == TYPE_BB4 then\n            f:write(\"DEPTH 1\\n\", \"MAXVAL 15\\n\", \"TUPLTYPE GRAYSCALE\\n\")\n        elseif bb_type == TYPE_BB8 then\n            f:write(\"DEPTH 1\\n\", \"MAXVAL 255\\n\", \"TUPLTYPE GRAYSCALE\\n\")\n        elseif bb_type == TYPE_BB8A then\n            f:write(\"DEPTH 2\\n\", \"MAXVAL 255\\n\", \"TUPLTYPE GRAYSCALE_ALPHA\\n\")\n        elseif bb_type == TYPE_BBRGB16 then\n            -- this is not supported by PAM since the tuple consists of different bit widths\n            -- so we convert to RGB24 in this case\n            f:write(\"DEPTH 3\\n\", \"MAXVAL 255\\n\", \"TUPLTYPE RGB\\n\")\n        elseif bb_type == TYPE_BBRGB24 then\n            f:write(\"DEPTH 3\\n\", \"MAXVAL 255\\n\", \"TUPLTYPE RGB\\n\")\n        elseif bb_type == TYPE_BBRGB32 or bb_type == TYPE_BBBGR32 then\n            f:write(\"DEPTH 4\\n\", \"MAXVAL 255\\n\", \"TUPLTYPE RGB_ALPHA\\n\")\n        end\n        f:write(\"ENDHDR\\n\")\n        for y = 0, self:getHeight()-1 do\n            for x = 0, self:getWidth()-1 do\n                local v = self:getPixel(x, y)\n                if bb_type == TYPE_BB4 or bb_type == TYPE_BB8 then\n                    ffi.C.fputc(v.a, f)\n                elseif bb_type == TYPE_BB8A then\n                    ffi.C.fputc(v.a, f)\n                    -- note that other functions do not support\n                    -- alpha values for now\n                    -- TODO: use correct alpha value of struct here\n                    ffi.C.fputc(255, f)\n                elseif bb_type == TYPE_BBRGB16 then\n                    v = v:getColorRGB24()\n                    ffi.C.fputc(v.r, f)\n                    ffi.C.fputc(v.g, f)\n                    ffi.C.fputc(v.b, f)\n                elseif bb_type == TYPE_BBRGB24 then\n                    ffi.C.fputc(v.r, f)\n                    ffi.C.fputc(v.g, f)\n                    ffi.C.fputc(v.b, f)\n                elseif bb_type == TYPE_BBRGB32 or bb_type == TYPE_BBBGR32 then\n                    ffi.C.fputc(v.r, f)\n                    ffi.C.fputc(v.g, f)\n                    ffi.C.fputc(v.b, f)\n                    -- note that other functions do not support\n                    -- alpha values for now\n                    -- TODO: use correct alpha value of struct here\n                    ffi.C.fputc(255, f)\n                end\n            end\n        end\n        f:close()\n    end\n\n    -- if no special case in BB???_mt exists, use function from BB_mt\n    -- (we do not use BB_mt as metatable for BB???_mt since this causes\n    --  a major slowdown and would not get properly JIT-compiled)\n    for name, func in pairs(BB_mt.__index) do\n        if not BB4_mt.__index[name] then BB4_mt.__index[name] = func end\n        if not BB8_mt.__index[name] then BB8_mt.__index[name] = func end\n        if not BB8A_mt.__index[name] then BB8A_mt.__index[name] = func end\n        if not BBRGB16_mt.__index[name] then BBRGB16_mt.__index[name] = func end\n        if not BBRGB24_mt.__index[name] then BBRGB24_mt.__index[name] = func end\n        if not BBRGB32_mt.__index[name] then BBRGB32_mt.__index[name] = func end\n        if not BBBGR32_mt.__index[name] then BBBGR32_mt.__index[name] = func end\n    end\n\n    -- set metatables for the BlitBuffer types\n    local BlitBuffer4 = ffi.metatype(\"BlitBuffer4\", BB4_mt)\n    local BlitBuffer8 = ffi.metatype(\"BlitBuffer8\", BB8_mt)\n    local BlitBuffer8A = ffi.metatype(\"BlitBuffer8A\", BB8A_mt)\n    local BlitBufferRGB16 = ffi.metatype(\"BlitBufferRGB16\", BBRGB16_mt)\n    local BlitBufferRGB24 = ffi.metatype(\"BlitBufferRGB24\", BBRGB24_mt)\n    local BlitBufferRGB32 = ffi.metatype(\"BlitBufferRGB32\", BBRGB32_mt)\n    local BlitBufferBGR32 = ffi.metatype(\"BlitBufferBGR32\", BBBGR32_mt)\n\n    -- set metatables for the Color types\n    ffi.metatype(\"Color4L\", Color4L_mt)\n    ffi.metatype(\"Color4U\", Color4U_mt)\n    ffi.metatype(\"Color8\", Color8_mt)\n    ffi.metatype(\"Color8A\", Color8A_mt)\n    ffi.metatype(\"ColorRGB16\", ColorRGB16_mt)\n    ffi.metatype(\"ColorRGB24\", ColorRGB24_mt)\n    ffi.metatype(\"ColorRGB32\", ColorRGB32_mt)\n    ffi.metatype(\"ColorBGR32\", ColorBGR32_mt)\n\n    function BB.new(width, height, buffertype, dataptr, pitch)\n        local bb = nil\n        buffertype = buffertype or TYPE_BB4\n        if pitch == nil then\n            if buffertype == TYPE_BB4 then pitch = band(1, width) + rshift(width, 1)\n            elseif buffertype == TYPE_BB8 then pitch = width\n            elseif buffertype == TYPE_BB8A then pitch = lshift(width, 1)\n            elseif buffertype == TYPE_BBRGB16 then pitch = lshift(width, 1)\n            elseif buffertype == TYPE_BBRGB24 then pitch = width * 3\n            elseif buffertype == TYPE_BBRGB32 or buffertype == TYPE_BBBGR32 then pitch = lshift(width, 2)\n            end\n        end\n        if buffertype == TYPE_BB4 then bb = BlitBuffer4(width, height, pitch, nil, 0)\n        elseif buffertype == TYPE_BB8 then bb = BlitBuffer8(width, height, pitch, nil, 0)\n        elseif buffertype == TYPE_BB8A then bb = BlitBuffer8A(width, height, pitch, nil, 0)\n        elseif buffertype == TYPE_BBRGB16 then bb = BlitBufferRGB16(width, height, pitch, nil, 0)\n        elseif buffertype == TYPE_BBRGB24 then bb = BlitBufferRGB24(width, height, pitch, nil, 0)\n        elseif buffertype == TYPE_BBRGB32 then bb = BlitBufferRGB32(width, height, pitch, nil, 0)\n        elseif buffertype == TYPE_BBBGR32 then bb = BlitBufferBGR32(width, height, pitch, nil, 0)\n        else error(\"unknown blitbuffer type\")\n        end\n        bb:setType(buffertype)\n        if dataptr == nil then\n            dataptr = ffi.C.malloc(pitch*height)\n            assert(dataptr, \"cannot allocate memory for blitbuffer\")\n            ffi.fill(dataptr, pitch*height)\n            bb:setAllocated(1)\n        end\n        bb.data = ffi.cast(bb.data, dataptr)\n        return bb\n    end\n\n    function BB.compat(oldbuffer)\n        return ffi.cast(\"BlitBuffer4*\", oldbuffer)[0]\n    end\n\n    function BB.fromstring(width, height, buffertype, str, pitch)\n        local dataptr = ffi.C.malloc(#str)\n        ffi.copy(dataptr, str, #str)\n        return BB.new(width, height, buffertype, dataptr, pitch)\n    end\n\n    function BB.tostring(bb)\n        return ffi.string(bb.data, bb.pitch * bb.h)\n    end\n\n    -- accessors for color types:\n    BB.Color4 = Color4L\n    BB.Color4L = Color4L\n    BB.Color4U = Color4U\n    BB.Color8 = Color8\n    BB.ColorRGB16 = ColorRGB16\n    BB.ColorRGB24 = ColorRGB24\n    BB.ColorRGB32 = ColorRGB32\n    BB.ColorBGR32 = ColorBGR32\n\n    -- accessors for Blitbuffer types\n    BB.BlitBuffer4 = BlitBuffer4\n    BB.BlitBuffer8 = BlitBuffer8\n    BB.BlitBuffer8A = BlitBuffer8A\n    BB.BlitBufferRGB16 = BlitBufferRGB16\n    BB.BlitBufferRGB24 = BlitBufferRGB24\n    BB.BlitBufferRGB32 = BlitBufferRGB32\n    BB.BlitBufferBGR32 = BlitBufferBGR32\n    BB.TYPE_BB4 = TYPE_BB4\n    BB.TYPE_BB8 = TYPE_BB8\n    BB.TYPE_BB8A = TYPE_BB8A\n    BB.TYPE_BBRGB16 = TYPE_BBRGB16\n    BB.TYPE_BBRGB24 = TYPE_BBRGB24\n    BB.TYPE_BBRGB32 = TYPE_BBRGB32\n    BB.TYPE_BBBGR32 = TYPE_BBBGR32\n\n    return BB\n"
  },
  {
    "path": "ffi/einkfb_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\nenum fx_type {\n  fx_mask = 11,\n  fx_buf_is_mask = 14,\n  fx_none = -1,\n  fx_flash = 20,\n  fx_invert = 21,\n  fx_update_partial = 0,\n  fx_update_full = 1,\n};\nstruct update_area_t {\n  int x1;\n  int y1;\n  int x2;\n  int y2;\n  enum fx_type which_fx;\n  unsigned char *buffer;\n};\nenum orientation_t {\n  orientation_portrait = 0,\n  orientation_portrait_upside_down = 1,\n  orientation_landscape = 2,\n  orientation_landscape_upside_down = 3,\n};\nenum einkfb_events_t {\n  einkfb_event_update_display = 0,\n  einkfb_event_update_display_area = 1,\n  einkfb_event_blank_display = 2,\n  einkfb_event_rotate_display = 3,\n  einkfb_event_null = -1,\n};\nstruct einkfb_event_t {\n  enum einkfb_events_t event;\n  enum fx_type update_mode;\n  int x1;\n  int y1;\n  int x2;\n  int y2;\n  enum orientation_t orientation;\n};\nstatic const int FBIO_EINK_UPDATE_DISPLAY = 18139;\nstatic const int FBIO_EINK_UPDATE_DISPLAY_AREA = 18141;\nstatic const int FBIO_EINK_SET_DISPLAY_ORIENTATION = 18160;\nstatic const int FBIO_EINK_GET_DISPLAY_ORIENTATION = 18161;\n]]\n"
  },
  {
    "path": "ffi/eventloop.lua",
    "content": "-- dependencies\nlocal ffi = require(\"ffi\")\nlocal bit = require(\"bit\")\nlocal posix = require(\"ffi/posix_h\")\n\n-- this module\nlocal events = {}\n\n-- Lua table storing file descriptors and callbacks\nlocal fds = {}\n-- Lua table storing timers and their callbacks\nlocal timers = nil\n\n-- C array for poll()\nlocal poll_fds = nil\n-- counter for that C array\nlocal open_fds = 0\n\n-- flag for the event loop\nlocal running = true\n\n--[[\nregister a file descriptor to get monitored\n\nexpects a table with functions that are called\nupon events for the given file descriptor\nall functions are optional, however you should\ndefine at least \"read\" or \"write\".\n\nfunction names:\n  read: will get called when data can be read\n  write: will get called when data can be written\n  err: will get called upon errors\n  hup: will get called upon a hangup\n\n@parm fd file descriptor (integer)\n@parm callback table\n--]]\nfunction events.register_fd(fd, callbacks)\n\tassert(not fds[fd], \"fd is already registered\")\n\tfds[fd] = callbacks\n\t-- invalidate cache\n\tpoll_fds = nil\nend\n\n--[[\nregister a timer\n\nregisters a callback to be called at a given time.\nthe time is given as a \"struct timeval\"\n--]]\nfunction events.register_timer(timeval, callback, id)\n\t-- append to the end of the list\n\t-- this is needed to properly calculate times\n\t-- in the loop: new timers must be taken into account\n\tlocal timer = { next = nil, tv = timeval, cb = callback, id = id }\n\tif not timers then\n\t\ttimers = timer\n\telse\n\t\tlocal tail = timers\n\t\twhile tail.next do tail = tail.next end\n\t\ttail.next = timer\n\tend\nend\n\n--[[\nregister a timer to fire in n milliseconds\n\nthis is a convenience wrapper that does all the calculating\n--]]\nfunction events.register_timer_in_ms(milliseconds, callback, id)\n\tlocal tv = ffi.new(\"struct timeval\")\n\tffi.C.gettimeofday(tv, nil)\n\twhile milliseconds > 1000 do\n\t\ttv.tv_sec = tv.tv_sec + 1\n\t\tmilliseconds = milliseconds - 1000\n\tend\n\ttv.tv_usec = tv.tv_usec + milliseconds * 1000\n\tif tv.tv_usec > 1000000 then\n\t\ttv.tv_sec = tv.tv_sec + 1\n\t\ttv.tv_usec = tv.tv_usec - 1000000\n\tend\n\tevents.register_timer(tv, callback, id)\nend\n\n--[[\ncheck if a timer exists (and is running)\n--]]\nfunction events.timer_running(id)\n\tif not timers then return false end\n\tlocal tail = timers\n\trepeat\n\t\tif tail.id == id then return true end\n\t\ttail = tail.next\n\tuntil not tail\n\treturn false\nend\n\n--[[\nremove a filedescriptor from being monitored\n--]]\nfunction events.unregister_fd(fd)\n\tassert(fds[fd], \"fd is not registered, cannot unregister\")\n\ttable.remove(fds, fd)\n\tpoll_fds = nil\nend\n\n--[[\nremove a named timer\n--]]\nfunction events.unregister_timer(id)\n\tassert(id, \"only timers with ID can be unregistered\")\n\tlocal prev = nil\n\tlocal timer = timers\n\twhile timer do\n\t\tif timer.id == id then\n\t\t\tif not prev then timers = timer.next else prev.next = timer.next end\n\t\t\tbreak\n\t\tend\n\t\tprev = timer\n\t\ttimer = timer.next\n\tend\nend\n\n-- internal helper to recreate poll_fd array\nlocal function check_poll_fds()\n\t-- check if we have a valid cache\n\tif poll_fds then return end\n\t-- otherwise, rescan\n\tpoll_fds = nil\n\topen_fds = 0\n\tfor _, _ in pairs(fds) do open_fds = open_fds + 1 end\n\tif open_fds > 0 then\n\t\tpoll_fds = ffi.new(\"struct pollfd[?]\", open_fds)\n\t\tlocal c = 0\n\t\tfor fd, callbacks in pairs(fds) do\n\t\t\tpoll_fds[c].fd = fd\n\t\t\tif callbacks.read then\n\t\t\t\tpoll_fds[c].events = bit.bor(poll_fds[c].events, ffi.C.POLLIN)\n\t\t\tend\n\t\t\tif callbacks.write then\n\t\t\t\tpoll_fds[c].events = bit.bor(poll_fds[c].events, ffi.C.POLLOUT)\n\t\t\tend\n\t\t\tc = c + 1\n\t\tend\n\tend\nend\n\n--[[\nconvenience wrapper that exits after a timeout\n--]]\nfunction events.loopusecs(timeout)\n\treturn events.loop(timeout / 1000)\nend\n\n--[[\nabort routine that will stop the event loop\n--]]\nfunction events.abort_loop()\n\trunning = false\nend\n\n-- allocate these only once\nlocal now = ffi.new(\"struct timeval\")\nlocal up_to = ffi.new(\"struct timeval\")\n\n--[[\nmain event loop\n--]]\nfunction events.loop(timeout)\n\tif timeout then\n\t\tevents.register_timer_in_ms(timeout, events.abort_loop)\n\tend\n\trunning = true\n\tlocal poll_duration\n\twhile running do\n\t\t-- check and update poll_fd cache\n\t\tcheck_poll_fds()\n\t\t\n\t\t-- get time to check timers\n\t\tffi.C.gettimeofday(now, nil)\n\t\tup_to.tv_sec = 0\n\t\tlocal timer = timers\n\t\tlocal prev = nil\n\t\twhile timer do\n\t\t\tif now.tv_sec > timer.tv.tv_sec\n\t\t\tor ( now.tv_sec == timer.tv.tv_sec and now.tv_usec >= timer.tv.tv_usec) then\n\t\t\t\ttimer.cb()\n\t\t\t\t-- remove from list\n\t\t\t\tif not prev then timers = timer.next else prev.next = timer.next end\n\t\t\telse\n\t\t\t\tif up_to.tv_sec == 0\n\t\t\t\tor timer.tv.tv_sec < up_to.tv_sec\n\t\t\t\tor (timer.tv.tv_sec == up_to.tv_sec and timer.tv.tv_usec < up_to.tv_usec) then\n\t\t\t\t\tup_to.tv_sec = timer.tv.tv_sec\n\t\t\t\t\tup_to.tv_usec = timer.tv.tv_usec\n\t\t\t\tend\n\t\t\t\tprev = timer\n\t\t\tend\n\t\t\ttimer = timer.next\n\t\tend\n\n\t\t-- intermediate check after doing the timer work\n\t\tif not running then break end\n\n\t\t-- calculate wait time\n\t\tif up_to.tv_sec == 0 then\n\t\t\tif open_fds == 0 then\n\t\t\t\terror(\"got no timers waiting, got no input fds\")\n\t\t\tend\n\t\t\tpoll_duration = -1\n\t\telse\n\t\t\tpoll_duration = (up_to.tv_usec - now.tv_usec) / 1000\n\t\t\tpoll_duration = poll_duration + (up_to.tv_sec - now.tv_sec) * 1000 + 1\n\t\tend\n\n\t\t-- do the poll()\n\t\tlocal ret = ffi.C.poll(poll_fds, open_fds, poll_duration)\n\t\tif ret > 0 then\n\t\t\tfor i = 0, open_fds-1 do\n\t\t\t\tlocal fd = poll_fds[i].fd\n\t\t\t\tif bit.band(poll_fds[i].revents, ffi.C.POLLIN) ~= 0 then\n\t\t\t\t\tfds[fd].read(fd)\n\t\t\t\tend\n\t\t\t\tif bit.band(poll_fds[i].revents, ffi.C.POLLOUT) ~= 0 then\n\t\t\t\t\tfds[fd].write(fd)\n\t\t\t\tend\n\t\t\t\tif bit.band(poll_fds[i].revents, ffi.C.POLLERR) ~= 0 then\n\t\t\t\t\tif fds[fd].err then fds[fd].err(fd) end\n\t\t\t\tend\n\t\t\t\tif bit.band(poll_fds[i].revents, ffi.C.POLLHUP) ~= 0 then\n\t\t\t\t\tif fds[fd].hup then fds[fd].hup(fd) end\n\t\t\t\tend\n\t\t\tend\n\t\telseif ret < 0 then\n\t\t\tlocal errno = ffi.errno()\n\t\t\tif errno == ffi.C.EINTR then\n\t\t\t\t-- unhandled signal, ignore this for now...\n\t\t\telse\n\t\t\t\terror(\"poll(): \" .. ffi.string(ffi.C.strerror(errno)))\n\t\t\tend\n\t\tend\n\tend\nend\n\nreturn events\n"
  },
  {
    "path": "ffi/framebuffer.lua",
    "content": "local util = require(\"ffi/util\")\n\nif util.isEmulated() then\n\treturn require(\"ffi/framebuffer_SDL\")\nelse\n\treturn require(\"ffi/framebuffer_linux\")\nend\n\n"
  },
  {
    "path": "ffi/framebuffer_SDL.lua",
    "content": "local ffi = require(\"ffi\")\nlocal bit = require(\"bit\")\n-- load common SDL input/video library\nlocal SDL = require(\"ffi/SDL\")\n\nlocal BB = require(\"ffi/blitbuffer\")\n\nlocal fb = {}\n\nfunction fb.open()\n\tSDL.open()\n\n\t-- we present this buffer to the outside\n\tfb.bb = BB.new(SDL.screen.w, SDL.screen.h)\n\n\tfb.real_bb = BB.new(SDL.screen.w, SDL.screen.h, BB.TYPE_BBRGB32,\n\t\tSDL.screen.pixels, SDL.screen.pitch)\n\tfb.real_bb:invert()\n\n\tfb:refresh()\n\n\treturn fb\nend\n\nfunction fb:getSize()\n\treturn self.bb.w, self.bb.h\nend\n\nfunction fb:getPitch()\n\treturn self.bb.pitch\nend\n\nfunction fb:setOrientation(mode)\n\tif mode == 1 or mode == 3 then\n\t\t-- TODO: landscape setting\n\telse\n\t\t-- TODO: flip back to portrait\n\tend\nend\n\nfunction fb:getOrientation()\n\tif SDL.screen.w > SDL.screen.h then\n\t\treturn 1\n\telse\n\t\treturn 0\n\tend\nend\n\nfunction fb:refresh(refreshtype, waveform_mode, x1, y1, w, h)\n\tif x1 == nil then x1 = 0 end\n\tif y1 == nil then y1 = 0 end\n\n\t-- adapt to possible rotation changes\n\tself.real_bb:setRotation(self.bb:getRotation())\n\t\n\tif SDL.SDL.SDL_LockSurface(SDL.screen) < 0 then\n\t\terror(\"Locking screen surface\")\n\tend\n\tself.real_bb:blitFrom(self.bb, x1, y1, x1, y1, w, h)\n\n\tSDL.SDL.SDL_UnlockSurface(SDL.screen)\n\tSDL.SDL.SDL_Flip(SDL.screen)\nend\n\nfunction fb:close()\n\t-- for now, we do nothing when in emulator mode\nend\n\nreturn fb\n"
  },
  {
    "path": "ffi/framebuffer_linux.lua",
    "content": "local ffi = require(\"ffi\")\nlocal bit = require(\"bit\")\nlocal BB = require(\"ffi/blitbuffer\")\n\nlocal dummy = require(\"ffi/linux_fb_h\")\nlocal dummy = require(\"ffi/posix_h\")\n\nlocal framebuffer = {}\nlocal framebuffer_mt = {__index={}}\n-- Init our marker to 0, which happens to be an invalid value, so we can detect our first update\nlocal update_marker = ffi.new(\"uint32_t[1]\", 0)\n\nlocal function einkfb_update(fb, refreshtype, waveform_mode, x, y, w, h)\n\tlocal refarea = ffi.new(\"struct update_area_t[1]\")\n\n\trefarea[0].x1 = x or 0\n\trefarea[0].y1 = y or 0\n\trefarea[0].x2 = x + (w or (fb.vinfo.xres-x))\n\trefarea[0].y2 = y + (h or (fb.vinfo.yres-y))\n\trefarea[0].buffer = nil\n\tif refreshtype == 0 then\n\t\trefarea[0].which_fx = ffi.C.fx_update_partial\n\telse\n\t\trefarea[0].which_fx = ffi.C.fx_update_full\n\tend\n\n\treturn ffi.C.ioctl(fb.fd, ffi.C.FBIO_EINK_UPDATE_DISPLAY_AREA, refarea);\nend\n\nlocal function mxc_new_update_marker()\n\t-- Simply increment our current marker\n\tlocal new_update_marker = ffi.new(\"uint32_t[1]\", update_marker[0] + 1)\n\t-- 1 to 16, strictly clamped.\n\tif new_update_marker[0] > 16 or new_update_marker[0] < 1 then\n\t\tnew_update_marker[0] = 1\n\tend\n\t-- Keep track of it, and return it\n\tupdate_marker[0] = new_update_marker[0]\n\treturn new_update_marker[0]\nend\n\n-- Kindle's MXCFB_WAIT_FOR_UPDATE_COMPLETE_PEARL == 0x4004462f\nlocal function kindle_pearl_mxc_wait_for_update_complete(fb)\n\t-- Wait for the previous update to be completed\n\treturn ffi.C.ioctl(fb.fd, ffi.C.MXCFB_WAIT_FOR_UPDATE_COMPLETE_PEARL, update_marker)\nend\n\n-- Kindle's MXCFB_WAIT_FOR_UPDATE_COMPLETE == 0xc008462f\nlocal function kindle_carta_mxc_wait_for_update_complete(fb)\n\t-- Wait for the previous update to be completed\n\tlocal carta_update_marker = ffi.new(\"struct mxcfb_update_marker_data[1]\")\n\tcarta_update_marker[0].update_marker = update_marker[0];\n\t-- We're not using EPDC_FLAG_TEST_COLLISION, assume 0 is okay.\n\tcarta_update_marker[0].collision_test = 0;\n\treturn ffi.C.ioctl(fb.fd, ffi.C.MXCFB_WAIT_FOR_UPDATE_COMPLETE, carta_update_marker)\nend\n\n-- Kobo's MXCFB_WAIT_FOR_UPDATE_COMPLETE == 0x4004462f\n\n-- Kindle's MXCFB_SEND_UPDATE == 0x4048462e | Kobo's MXCFB_SEND_UPDATE == 0x4044462e\nlocal function mxc_update(fb, refarea, refreshtype, waveform_mode, x, y, w, h)\n\trefarea[0].update_mode = refreshtype or 0\n\trefarea[0].waveform_mode = waveform_mode or 2\n\trefarea[0].update_region.left = x or 0\n\trefarea[0].update_region.top = y or 0\n\trefarea[0].update_region.width = w or fb.vinfo.xres\n\trefarea[0].update_region.height = h or fb.vinfo.yres\n\t-- Get a new update marker\n\trefarea[0].update_marker = mxc_new_update_marker()\n\t-- TODO: make the flag configurable from UI,\n\t-- e.g., the EPDC_FLAG_ENABLE_INVERSION flag inverts all the pixels on display  09.01 2013 (houqp)\n\trefarea[0].flags = 0\n\t-- NOTE: We're not using EPDC_FLAG_USE_ALT_BUFFER\n\trefarea[0].alt_buffer_data.phys_addr = 0\n\trefarea[0].alt_buffer_data.width = 0\n\trefarea[0].alt_buffer_data.height = 0\n\trefarea[0].alt_buffer_data.alt_update_region.top = 0\n\trefarea[0].alt_buffer_data.alt_update_region.left = 0\n\trefarea[0].alt_buffer_data.alt_update_region.width = 0\n\trefarea[0].alt_buffer_data.alt_update_region.height = 0\n\treturn ffi.C.ioctl(fb.fd, ffi.C.MXCFB_SEND_UPDATE, refarea)\nend\n\n-- Kindle's MXCFB_WAIT_FOR_UPDATE_SUBMISSION == 0x40044637\nlocal function kindle_mxc_wait_for_update_submission(fb)\n\t-- Wait for the current (the one we just sent) update to be submitted\n\treturn ffi.C.ioctl(fb.fd, ffi.C.MXCFB_WAIT_FOR_UPDATE_SUBMISSION, update_marker)\nend\n\nlocal function k51_update(fb, refreshtype, waveform_mode, x, y, w, h)\n\tlocal refarea = ffi.new(\"struct mxcfb_update_data[1]\")\n\t-- only for Amazon's driver (NOTE: related to debugPaint prefbw & prefgray?):\n\trefarea[0].hist_bw_waveform_mode = 0\n\trefarea[0].hist_gray_waveform_mode = 0\n\t-- TEMP_USE_PAPYRUS on Touch/PW1, TEMP_USE_AUTO on PW2\n\trefarea[0].temp = 0x1001\n\n\treturn mxc_update(fb, refarea, refreshtype, waveform_mode, x, y, w, h)\nend\n\nlocal function kobo_update(fb, refreshtype, waveform_mode, x, y, w, h)\n\tlocal refarea = ffi.new(\"struct mxcfb_update_data[1]\")\n\t-- only for Kobo's driver:\n\trefarea[0].alt_buffer_data.virt_addr = nil\n\t-- TEMP_USE_AMBIENT\n\trefarea[0].temp = 0x1000\n\n\treturn mxc_update(fb, refarea, refreshtype, waveform_mode, x, y, w, h)\nend\n\nfunction framebuffer.open(device)\n\tlocal fb = {\n\t\tfd = -1,\n\t\tfinfo = ffi.new(\"struct fb_fix_screeninfo\"),\n\t\tvinfo = ffi.new(\"struct fb_var_screeninfo\"),\n\t\tfb_size = -1,\n\t\teinkWaitForCompleteFunc = nil,\n\t\teinkUpdateFunc = nil,\n\t\teinkWaitForSubmissionFunc = nil,\n\t\twait_for_full_updates = false,\n\t\twait_for_every_updates = false,\n\t\tbb = nil,\n\t\tdata = nil\n\t}\n\tsetmetatable(fb, framebuffer_mt)\n\n\tfb.fd = ffi.C.open(device, ffi.C.O_RDWR)\n\tassert(fb.fd ~= -1, \"cannot open framebuffer\")\n\n\t-- Get fixed screen information\n\tassert(ffi.C.ioctl(fb.fd, ffi.C.FBIOGET_FSCREENINFO, fb.finfo) == 0,\n\t\t\"cannot get screen info\")\n\n\tassert(ffi.C.ioctl(fb.fd, ffi.C.FBIOGET_VSCREENINFO, fb.vinfo) == 0,\n\t\t\"cannot get variable screen info\")\n\n\tassert(fb.finfo.type == ffi.C.FB_TYPE_PACKED_PIXELS,\n\t\t\"video type not supported\")\n\n\t--Kindle Paperwhite doesn't set this properly?\n\t--assert(fb.vinfo.grayscale == 0, \"only grayscale is supported but framebuffer says it isn't\")\n\tassert(fb.vinfo.xres_virtual > 0 and fb.vinfo.yres_virtual > 0, \"invalid framebuffer resolution\")\n\n\t-- it seems that fb.finfo.smem_len is unreliable on kobo\n\t-- Figure out the size of the screen in bytes\n\tfb.fb_size = fb.vinfo.xres_virtual * fb.vinfo.yres_virtual * fb.vinfo.bits_per_pixel / 8\n\n\tfb.data = ffi.C.mmap(nil, fb.fb_size, bit.bor(ffi.C.PROT_READ, ffi.C.PROT_WRITE), ffi.C.MAP_SHARED, fb.fd, 0)\n\tassert(fb.data ~= ffi.C.MAP_FAILED, \"can not mmap() framebuffer\")\n\n\tif ffi.string(fb.finfo.id, 11) == \"mxc_epdc_fb\" then\n\t\t-- TODO: implement a better check for Kobo\n\t\tif fb.vinfo.bits_per_pixel == 16 then\n\t\t\t-- this ought to be a Kobo\n\t\t\tlocal dummy = require(\"ffi/mxcfb_kobo_h\")\n\t\t\tfb.einkUpdateFunc = kobo_update\n\t\t\tfb.bb = BB.new(fb.vinfo.xres, fb.vinfo.yres, BB.TYPE_BBRGB16, fb.data, fb.finfo.line_length)\n\t\t\tfb.bb:invert()\n\t\t\tif fb.vinfo.xres > fb.vinfo.yres then\n\t\t\t\t-- Kobo framebuffers need to be rotated counter-clockwise (they start in landscape mode)\n\t\t\t\tfb.bb:rotate(-90)\n\t\t\tend\n\t\telseif fb.vinfo.bits_per_pixel == 8 then\n\t\t\t-- Kindle PaperWhite and KT with 5.1 or later firmware\n\t\t\tlocal dummy = require(\"ffi/mxcfb_kindle_h\")\n\t\t\t-- NOTE: We need to differentiate the PW2 from the Touch/PW1... I hope this check is solid enough... (cf #550).\n\t\t\tif fb.finfo.smem_len == 3145728 then\n\t\t\t\t-- We're a PW2! Use the correct function, and ask to wait for every update.\n\t\t\t\tfb.wait_for_every_updates = true\n\t\t\t\tfb.einkWaitForCompleteFunc = kindle_carta_mxc_wait_for_update_complete\n\t\t\telseif fb.finfo.smem_len == 2179072 or fb.finfo.smem_len == 4718592 then\n\t\t\t\t-- We're a Touch/PW1\n\t\t\t\tfb.wait_for_full_updates = true\n\t\t\t\tfb.einkWaitForCompleteFunc = kindle_pearl_mxc_wait_for_update_complete\n\t\t\telse\n\t\t\t\terror(\"unknown smem_len value for the Kindle mxc eink driver\")\n\t\t\tend\n\t\t\tfb.einkUpdateFunc = k51_update\n\t\t\tfb.einkWaitForSubmissionFunc = kindle_mxc_wait_for_update_submission\n\t\t\tfb.bb = BB.new(fb.vinfo.xres, fb.vinfo.yres, BB.TYPE_BB8, fb.data, fb.finfo.line_length)\n\t\t\tfb.bb:invert()\n\t\telse\n\t\t\terror(\"unknown bpp value for the mxc eink driver\")\n\t\tend\n\telseif ffi.string(fb.finfo.id, 7) == \"eink_fb\" then\n\t\tlocal dummy = require(\"ffi/einkfb_h\")\n\t\tfb.einkUpdateFunc = einkfb_update\n\n\t\tif fb.vinfo.bits_per_pixel == 8 then\n\t\t\tfb.bb = BB.new(fb.vinfo.xres, fb.vinfo.yres, BB.TYPE_BB8, fb.data, fb.finfo.line_length)\n\t\telseif fb.vinfo.bits_per_pixel == 4 then\n\t\t\tfb.bb = BB.new(fb.vinfo.xres, fb.vinfo.yres, BB.TYPE_BB4, fb.data, fb.finfo.line_length)\n\t\telse\n\t\t\terror(\"unknown bpp value for the classic eink driver\")\n\t\tend\n\telse\n\t\terror(\"eink model not supported\");\n\tend\n\n\treturn fb\nend\n\nfunction framebuffer_mt:getOrientation()\n\tlocal mode = ffi.new(\"int[1]\")\n\tffi.C.ioctl(self.fd, ffi.C.FBIO_EINK_GET_DISPLAY_ORIENTATION, mode)\n\n\t-- adjust ioctl's rotate mode definition to KPV's\n\t-- refer to screen.lua\n\tif mode == 2 then\n\t\treturn 1\n\telseif mode == 1 then\n\t\treturn 2\n\tend\n\treturn mode\nend\n\nfunction framebuffer_mt:setOrientation(mode)\n\tmode = ffi.cast(\"int\", mode or 0)\n\tif mode < 0 or mode > 3 then\n\t\terror(\"Wrong rotation mode given!\")\n\tend\n\n\t--[[\n         ioctl has a different definition for rotation mode.\n\t \t          1\n\t \t   +--------------+\n\t \t   | +----------+ |\n\t \t   | |          | |\n\t \t   | | Freedom! | |\n\t \t   | |          | |\n\t \t   | |          | |\n\t \t 3 | |          | | 2\n\t \t   | |          | |\n\t \t   | |          | |\n\t \t   | +----------+ |\n\t \t   |              |\n\t \t   |              |\n\t \t   +--------------+\n\t \t          0\n\t--]]\n\tif mode == 1 then\n\t\tmode = 2\n\telseif mode == 2 then\n\t\tmode = 1\n\tend\n\n\tffi.C.ioctl(self.fd, ffi.C.FBIO_EINK_SET_DISPLAY_ORIENTATION, mode)\nend\n\nfunction framebuffer_mt.__index:refresh(refreshtype, waveform_mode, x, y, w, h)\n\t-- The Touch/PW1 only do this for full updates\n\tif refreshtype == 1 and self.wait_for_full_updates or self.wait_for_every_updates then\n\t\t-- Start by checking that our previous update has completed\n\t\tif self.einkWaitForCompleteFunc then\n\t\t\t-- We have nothing to check on our first refresh() call!\n\t\t\tif update_marker[0] ~= 0 then\n\t\t\t\tself:einkWaitForCompleteFunc()\n\t\t\tend\n\t\tend\n\tend\n\n\tw, x = BB.checkBounds(w or self.bb:getWidth(), x or 0, 0, self.bb:getWidth(), 0xFFFF)\n\th, y = BB.checkBounds(h or self.bb:getHeight(), y or 0, 0, self.bb:getHeight(), 0xFFFF)\n\tx, y, w, h = self.bb:getPhysicalRect(x, y, w, h)\n\tself:einkUpdateFunc(refreshtype, waveform_mode, x, y, w, h)\n\n\t-- Finish by waiting for our curren tupdate to be submitted\n\tif refreshtype == 1 and self.wait_for_full_updates or self.wait_for_every_updates then\n\t\tif self.einkWaitForSubmissionFunc then\n\t\t\tself:einkWaitForSubmissionFunc()\n\t\tend\n\tend\nend\n\nfunction framebuffer_mt.__index:getSize()\n\treturn self.bb:getWidth(), self.bb:getHeight()\nend\n\nfunction framebuffer_mt.__index:getPitch()\n\treturn self.bb.pitch\nend\n\nfunction framebuffer_mt.__index:close()\n\tffi.C.munmap(self.data, self.fb_size)\n\tffi.C.close(self.fd)\n\tself.fd = -1\n\tself.data = nil\n\tself.bb = nil\nend\n\nreturn framebuffer\n"
  },
  {
    "path": "ffi/input.lua",
    "content": "local util = require(\"ffi/util\")\n\nif util.isEmulated() then\n\treturn require(\"ffi/input_SDL\")\nelse\n\treturn require(\"ffi/input_kindle\")\nend\n"
  },
  {
    "path": "ffi/input_SDL.lua",
    "content": "local ffi = require(\"ffi\")\nlocal evloop = require(\"ffi/eventloop\")\n\nlocal dummy = require(\"ffi/posix_h\")\nlocal dummy = require(\"ffi/linux_input_h\")\n\nlocal SDL = require(\"ffi/SDL\")\n\n-- this module\nlocal input = {}\n\n-- the input event buffer\nlocal input_queue = {}\n\nlocal poll_time = 50 -- 50 ms\nlocal event = ffi.new(\"union SDL_Event\")\n\nlocal function genEmuEvent(evtype, code, value)\n\tlocal ev = ffi.new(\"struct input_event\")\n\tev.type = evtype\n\tev.code = code\n\tev.value = value\n\tffi.C.gettimeofday(ev.time, nil)\n\ttable.insert(input_queue, ev)\nend\n\nlocal is_in_touch = false\nfunction input.poller()\n\tlocal got_event = SDL.SDL.SDL_PollEvent(event)\n\tif got_event == 0 then\n\t\tevloop.register_timer_in_ms(poll_time, input.poller)\n\telse\n\t\twhile got_event > 0 do\n\t\t\t-- if we got an event, examine it here and generate\n\t\t\t-- events for koreader\n\t\t\tif event.type == SDL.SDL.SDL_KEYDOWN then\n\t\t\t\tgenEmuEvent(ffi.C.EV_KEY, event.key.keysym.scancode, 1)\n\t\t\telseif event.type == SDL.SDL.SDL_KEYUP then\n\t\t\t\tgenEmuEvent(ffi.C.EV_KEY, event.key.keysym.scancode, 0)\n\t\t\telseif event.type == SDL.SDL.SDL_MOUSEMOTION then\n\t\t\t\tif is_in_touch then\n\t\t\t\t\tif event.motion.xrel ~= 0 then\n\t\t\t\t\t\tgenEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X, event.button.x)\n\t\t\t\t\tend\n\t\t\t\t\tif event.motion.yrel ~= 0 then\n\t\t\t\t\t\tgenEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y, event.button.y)\n\t\t\t\t\tend\n\t\t\t\t\tgenEmuEvent(ffi.C.EV_SYN, ffi.C.SYN_REPORT, 0)\n\t\t\t\tend\n\t\t\telseif event.type == SDL.SDL.SDL_MOUSEBUTTONUP then\n\t\t\t\tis_in_touch = false;\n\t\t\t\tgenEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_TRACKING_ID, -1)\n\t\t\t\tgenEmuEvent(ffi.C.EV_SYN, ffi.C.SYN_REPORT, 0)\n\t\t\telseif event.type == SDL.SDL.SDL_MOUSEBUTTONDOWN then\n\t\t\t\t-- use mouse click to simulate single tap\n\t\t\t\tis_in_touch = true\n\t\t\t\tgenEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_TRACKING_ID, 0)\n\t\t\t\tgenEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X, event.button.x)\n\t\t\t\tgenEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y, event.button.y)\n\t\t\t\tgenEmuEvent(ffi.C.EV_SYN, ffi.C.SYN_REPORT, 0)\n\t\t\telseif event.type == SDL.SDL.SDL_QUIT then\n\t\t\t\terror(\"application forced to quit\")\n\t\t\tend\n\n\t\t\t-- check if there are more events to flush\n\t\t\tgot_event = SDL.SDL.SDL_PollEvent(event)\n\t\tend\n\t\tevloop.abort_loop()\n\tend\nend\n\nfunction input.open()\n\tSDL.open()\nend\n\nfunction input.waitForEvent()\n\twhile #input_queue == 0 do\n\t\tevloop.register_timer_in_ms(poll_time, input.poller)\n\t\tevloop.loop()\n\tend\n\treturn table.remove(input_queue, 1)\nend\n\nreturn input\n"
  },
  {
    "path": "ffi/input_kindle.lua",
    "content": "local ffi = require(\"ffi\")\nlocal evloop = require(\"ffi/eventloop\")\n\nlocal dummy = require(\"ffi/posix_h\")\nlocal dummy = require(\"ffi/linux_input_h\")\n\n-- this module\nlocal input = {}\n\n-- the input event buffer\nlocal input_queue = {}\n\nfunction input.read(fd)\n\tlocal event = ffi.new(\"struct input_event\")\n\tlocal n = ffi.C.read(fd, event, ffi.sizeof(event))\n\tif n ~= ffi.sizeof(event) then error(\"could not read full input_event\") end\n\ttable.insert(input_queue, event)\n\tevloop.abort_loop()\nend\n\nfunction input.err(fd)\n\tio.stderr:write(\"problem reading from fd \"..fd..\", closing.\\n\")\n\tevloop.unregister_fd(fd)\nend\n\nfunction input.hup(fd)\n\tio.stderr:write(\"hangup on fd \"..fd..\", closing.\\n\")\n\tevloop.unregister_fd(fd)\nend\n\nfunction input.open(device)\n\tlocal fd = ffi.C.open(device, bit.bor(ffi.C.O_RDONLY, ffi.C.O_NONBLOCK))\n\tif fd == -1 then\n\t\terror(\"cannot open device \" .. device .. \", error \" .. ffi.errno())\n\tend\n\tffi.C.ioctl(fd, ffi.C.EVIOCGRAB, ffi.new(\"uint64_t\", 1))\n\tevloop.register_fd(fd, input)\nend\n\nfunction input.waitForEvent()\n\tif #input_queue == 0 then\n\t\tevloop.loop()\n\tend\n\tassert(#input_queue > 0, \"no input events could be aquired\")\n\treturn table.remove(input_queue, 1)\nend\n\nreturn input\n"
  },
  {
    "path": "ffi/linux_fb_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\nstatic const int FBIOGET_FSCREENINFO = 17922;\nstatic const int FBIOGET_VSCREENINFO = 17920;\nstatic const int FB_TYPE_PACKED_PIXELS = 0;\nstruct fb_bitfield {\n  unsigned int offset;\n  unsigned int length;\n  unsigned int msb_right;\n};\nstruct fb_fix_screeninfo {\n  char id[16];\n  long unsigned int smem_start;\n  unsigned int smem_len;\n  unsigned int type;\n  unsigned int type_aux;\n  unsigned int visual;\n  short unsigned int xpanstep;\n  short unsigned int ypanstep;\n  short unsigned int ywrapstep;\n  unsigned int line_length;\n  long unsigned int mmio_start;\n  unsigned int mmio_len;\n  unsigned int accel;\n  short unsigned int capabilities;\n  short unsigned int reserved[2];\n};\nstruct fb_var_screeninfo {\n  unsigned int xres;\n  unsigned int yres;\n  unsigned int xres_virtual;\n  unsigned int yres_virtual;\n  unsigned int xoffset;\n  unsigned int yoffset;\n  unsigned int bits_per_pixel;\n  unsigned int grayscale;\n  struct fb_bitfield red;\n  struct fb_bitfield green;\n  struct fb_bitfield blue;\n  struct fb_bitfield transp;\n  unsigned int nonstd;\n  unsigned int activate;\n  unsigned int height;\n  unsigned int width;\n  unsigned int accel_flags;\n  unsigned int pixclock;\n  unsigned int left_margin;\n  unsigned int right_margin;\n  unsigned int upper_margin;\n  unsigned int lower_margin;\n  unsigned int hsync_len;\n  unsigned int vsync_len;\n  unsigned int sync;\n  unsigned int vmode;\n  unsigned int rotate;\n  unsigned int colorspace;\n  unsigned int reserved[4];\n};\n]]\n"
  },
  {
    "path": "ffi/linux_input_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\nstatic const int EVIOCGRAB = 1074021776;\nstatic const int EV_SYN = 0;\nstatic const int EV_KEY = 1;\nstatic const int EV_REL = 2;\nstatic const int EV_ABS = 3;\nstatic const int EV_MSC = 4;\nstatic const int EV_SW = 5;\nstatic const int EV_LED = 17;\nstatic const int EV_SND = 18;\nstatic const int EV_REP = 20;\nstatic const int EV_FF = 21;\nstatic const int EV_PWR = 22;\nstatic const int EV_FF_STATUS = 23;\nstatic const int EV_MAX = 31;\nstatic const int SYN_REPORT = 0;\nstatic const int SYN_CONFIG = 1;\nstatic const int SYN_MT_REPORT = 2;\nstatic const int SYN_DROPPED = 3;\nstatic const int ABS_MT_SLOT = 47;\nstatic const int ABS_MT_TOUCH_MAJOR = 48;\nstatic const int ABS_MT_TOUCH_MINOR = 49;\nstatic const int ABS_MT_WIDTH_MAJOR = 50;\nstatic const int ABS_MT_WIDTH_MINOR = 51;\nstatic const int ABS_MT_ORIENTATION = 52;\nstatic const int ABS_MT_POSITION_X = 53;\nstatic const int ABS_MT_POSITION_Y = 54;\nstatic const int ABS_MT_TOOL_TYPE = 55;\nstatic const int ABS_MT_BLOB_ID = 56;\nstatic const int ABS_MT_TRACKING_ID = 57;\nstatic const int ABS_MT_PRESSURE = 58;\nstatic const int ABS_MT_DISTANCE = 59;\nstatic const int ABS_MT_TOOL_X = 60;\nstatic const int ABS_MT_TOOL_Y = 61;\nstruct input_event {\n  struct timeval time;\n  short unsigned int type;\n  short unsigned int code;\n  int value;\n};\n]]\n"
  },
  {
    "path": "ffi/mxcfb_kindle_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\nstruct mxcfb_rect {\n  unsigned int top;\n  unsigned int left;\n  unsigned int width;\n  unsigned int height;\n};\nstruct mxcfb_alt_buffer_data {\n  unsigned int phys_addr;\n  unsigned int width;\n  unsigned int height;\n  struct mxcfb_rect alt_update_region;\n};\nstruct mxcfb_alt_buffer_data_kobo;\nstruct mxcfb_update_data {\n  struct mxcfb_rect update_region;\n  unsigned int waveform_mode;\n  unsigned int update_mode;\n  unsigned int update_marker;\n  unsigned int hist_bw_waveform_mode;\n  unsigned int hist_gray_waveform_mode;\n  int temp;\n  unsigned int flags;\n  struct mxcfb_alt_buffer_data alt_buffer_data;\n};\nstruct mxcfb_update_data_kobo;\nstatic const int MXCFB_SEND_UPDATE = 1078478382;\n]]\n"
  },
  {
    "path": "ffi/mxcfb_kobo_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\nstruct mxcfb_rect {\n  unsigned int top;\n  unsigned int left;\n  unsigned int width;\n  unsigned int height;\n};\nstruct mxcfb_alt_buffer_data {\n  void *virt_addr;\n  unsigned int phys_addr;\n  unsigned int width;\n  unsigned int height;\n  struct mxcfb_rect alt_update_region;\n};\nstruct mxcfb_alt_buffer_data_kobo;\nstruct mxcfb_update_data {\n  struct mxcfb_rect update_region;\n  unsigned int waveform_mode;\n  unsigned int update_mode;\n  unsigned int update_marker;\n  int temp;\n  unsigned int flags;\n  struct mxcfb_alt_buffer_data alt_buffer_data;\n};\nstruct mxcfb_update_data_kobo;\nstatic const int MXCFB_SEND_UPDATE = 0x4044462e;\n]]\n"
  },
  {
    "path": "ffi/posix_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\ntypedef long unsigned int size_t;\ntypedef long int off_t;\nstruct timeval {\n  long int tv_sec;\n  long int tv_usec;\n};\nstruct statvfs {\n  long unsigned int f_bsize;\n  long unsigned int f_frsize;\n  long unsigned int f_blocks;\n  long unsigned int f_bfree;\n  long unsigned int f_bavail;\n  long unsigned int f_files;\n  long unsigned int f_ffree;\n  long unsigned int f_favail;\n  long unsigned int f_fsid;\n  long unsigned int f_flag;\n  long unsigned int f_namemax;\n  int __f_spare[6];\n};\nint pipe(int *) __attribute__((__nothrow__, __leaf__));\nint fork(void) __attribute__((nothrow));\nint dup(int) __attribute__((__nothrow__, __leaf__));\nint dup2(int, int) __attribute__((__nothrow__, __leaf__));\nstatic const int O_RDWR = 2;\nstatic const int O_RDONLY = 0;\nstatic const int O_NONBLOCK = 2048;\nint open(const char *, int, ...);\nint close(int);\nint fcntl(int, int, ...);\nint execl(const char *, const char *, ...) __attribute__((__nothrow__, __leaf__));\nint execlp(const char *, const char *, ...) __attribute__((__nothrow__, __leaf__));\nint execv(const char *, char *const *) __attribute__((__nothrow__, __leaf__));\nint execvp(const char *, char *const *) __attribute__((__nothrow__, __leaf__));\nlong int write(int, const void *, long unsigned int);\nlong int read(int, void *, long unsigned int);\nint kill(int, int) __attribute__((__nothrow__, __leaf__));\nint waitpid(int, int *, int);\nstruct pollfd {\n  int fd;\n  short int events;\n  short int revents;\n};\nstatic const int POLLIN = 1;\nstatic const int POLLOUT = 4;\nstatic const int POLLERR = 8;\nstatic const int POLLHUP = 16;\nint poll(struct pollfd *, long unsigned int, int);\nstatic const int PROT_READ = 1;\nstatic const int PROT_WRITE = 2;\nstatic const int MAP_SHARED = 1;\nstatic const int MAP_FAILED = -1;\nvoid *mmap(void *, long unsigned int, int, int, int, long int) __attribute__((__nothrow__, __leaf__));\nint ioctl(int, long unsigned int, ...) __attribute__((__nothrow__, __leaf__));\nunsigned int sleep(unsigned int);\nint usleep(unsigned int);\nint statvfs(const char *restrict, struct statvfs *restrict) __attribute__((__nothrow__, __leaf__));\nint gettimeofday(struct timeval *restrict, struct timezone *restrict) __attribute__((__nothrow__, __leaf__));\nchar *realpath(const char *restrict, char *restrict) __attribute__((__nothrow__, __leaf__));\nvoid *malloc(long unsigned int) __attribute__((malloc, leaf, nothrow));\nvoid free(void *) __attribute__((__nothrow__, __leaf__));\nchar *strdup(const char *) __attribute__((malloc, leaf, nothrow));\nchar *strndup(const char *, long unsigned int) __attribute__((malloc, leaf, nothrow));\nstruct _IO_FILE *fopen(const char *restrict, const char *restrict);\nint fclose(struct _IO_FILE *);\nint printf(const char *, ...);\nint sprintf(char *, const char *, ...) __attribute__((nothrow));\nint fprintf(struct _IO_FILE *restrict, const char *restrict, ...);\nint fputc(int, struct _IO_FILE *);\nchar *strerror(int) __attribute__((__nothrow__, __leaf__));\nstatic const int EINTR = 4;\n]]\n"
  },
  {
    "path": "ffi/rfbclient.lua",
    "content": "local ffi = require(\"ffi\")\n\nrequire(\"ffi/rfbclient_h\")\n\nlocal rfb = ffi.load(\"./libvncclient.so\")\n\nreturn rfb\n"
  },
  {
    "path": "ffi/rfbclient_h.lua",
    "content": "local ffi = require(\"ffi\")\nffi.cdef[[\nstruct z_stream_s {\n  unsigned char *next_in;\n  unsigned int avail_in;\n  long unsigned int total_in;\n  unsigned char *next_out;\n  unsigned int avail_out;\n  long unsigned int total_out;\n  char *msg;\n  struct internal_state *state;\n  void *(*zalloc)(void *, unsigned int, unsigned int);\n  void (*zfree)(void *, void *);\n  void *opaque;\n  int data_type;\n  long unsigned int adler;\n  long unsigned int reserved;\n};\nstruct rfbClientData {\n  void *tag;\n  void *data;\n  struct rfbClientData *next;\n};\ntypedef struct _rfbClient rfbClient;\ntypedef signed char rfbBool;\nstruct _rfbClient {\n  unsigned char *frameBuffer;\n  int width;\n  int height;\n  int endianTest;\n  struct {\n    signed char shareDesktop;\n    signed char viewOnly;\n    const char *encodingsString;\n    signed char useBGR233;\n    int nColours;\n    signed char forceOwnCmap;\n    signed char forceTrueColour;\n    int requestedDepth;\n    int compressLevel;\n    int qualityLevel;\n    signed char enableJPEG;\n    signed char useRemoteCursor;\n    signed char palmVNC;\n    int scaleSetting;\n  } appData;\n  const char *programName;\n  char *serverHost;\n  int serverPort;\n  signed char listenSpecified;\n  int listenPort;\n  int flashPort;\n  struct {\n    int x;\n    int y;\n    int w;\n    int h;\n  } updateRect;\n  char buffer[307200];\n  int sock;\n  signed char canUseCoRRE;\n  signed char canUseHextile;\n  char *desktopName;\n  struct {\n    unsigned char bitsPerPixel;\n    unsigned char depth;\n    unsigned char bigEndian;\n    unsigned char trueColour;\n    short unsigned int redMax;\n    short unsigned int greenMax;\n    short unsigned int blueMax;\n    unsigned char redShift;\n    unsigned char greenShift;\n    unsigned char blueShift;\n    unsigned char pad1;\n    short unsigned int pad2;\n  } format;\n  struct {\n    short unsigned int framebufferWidth;\n    short unsigned int framebufferHeight;\n    struct {\n      unsigned char bitsPerPixel;\n      unsigned char depth;\n      unsigned char bigEndian;\n      unsigned char trueColour;\n      short unsigned int redMax;\n      short unsigned int greenMax;\n      short unsigned int blueMax;\n      unsigned char redShift;\n      unsigned char greenShift;\n      unsigned char blueShift;\n      unsigned char pad1;\n      short unsigned int pad2;\n    } format;\n    unsigned int nameLength;\n  } si;\n  char buf[8192];\n  char *bufoutptr;\n  int buffered;\n  int ultra_buffer_size;\n  char *ultra_buffer;\n  int raw_buffer_size;\n  char *raw_buffer;\n  struct z_stream_s decompStream;\n  signed char decompStreamInited;\n  char zlib_buffer[30000];\n  struct z_stream_s zlibStream[4];\n  signed char zlibStreamActive[4];\n  signed char cutZeros;\n  int rectWidth;\n  int rectColors;\n  char tightPalette[1024];\n  unsigned char tightPrevRow[12288];\n  signed char jpegError;\n  struct jpeg_source_mgr *jpegSrcManager;\n  void *jpegBufferPtr;\n  long unsigned int jpegBufferLen;\n  unsigned char *rcSource;\n  unsigned char *rcMask;\n  struct rfbClientData *clientData;\n  struct {\n    struct _IO_FILE *file;\n    struct timeval tv;\n    signed char readTimestamp;\n    signed char doNotSleep;\n  } *vncRec;\n  int KeyboardLedStateEnabled;\n  int CurrentKeyboardLedState;\n  int canHandleNewFBSize;\n  void (*HandleTextChat)(struct _rfbClient *, int, char *);\n  void (*HandleKeyboardLedState)(struct _rfbClient *, int, int);\n  signed char (*HandleCursorPos)(struct _rfbClient *, int, int);\n  void (*SoftCursorLockArea)(struct _rfbClient *, int, int, int, int);\n  void (*SoftCursorUnlockScreen)(struct _rfbClient *);\n  void (*GotFrameBufferUpdate)(struct _rfbClient *, int, int, int, int);\n  char *(*GetPassword)(struct _rfbClient *);\n  signed char (*MallocFrameBuffer)(struct _rfbClient *);\n  void (*GotXCutText)(struct _rfbClient *, const char *, int);\n  void (*Bell)(struct _rfbClient *);\n  void (*GotCursorShape)(struct _rfbClient *, int, int, int, int, int);\n  void (*GotCopyRect)(struct _rfbClient *, int, int, int, int, int, int);\n  struct {\n    unsigned char client2server[32];\n    unsigned char server2client[32];\n  } supportedMessages;\n  int major;\n  int minor;\n  unsigned int authScheme;\n  unsigned int subAuthScheme;\n  void *tlsSession;\n  union _rfbCredential *(*GetCredential)(struct _rfbClient *, int);\n  unsigned int *clientAuthSchemes;\n  char *destHost;\n  int destPort;\n  int QoS_DSCP;\n  void (*HandleXvpMsg)(struct _rfbClient *, unsigned char, unsigned char);\n  int listenSock;\n  void (*FinishedFrameBufferUpdate)(struct _rfbClient *);\n  char *listenAddress;\n  int listen6Sock;\n  char *listen6Address;\n  int listen6Port;\n  long unsigned int outputWindow;\n};\nstruct _rfbClient *rfbGetClient(int, int, int);\nsigned char rfbInitClient(struct _rfbClient *, int *, char **);\nextern void (*rfbClientLog)(const char *, ...);\nsigned char SendKeyEvent(struct _rfbClient *, unsigned int, signed char);\nsigned char SendPointerEvent(struct _rfbClient *, int, int, int);\nsigned char SendFramebufferUpdateRequest(struct _rfbClient *, int, int, int, int, signed char);\nsigned char SendIncrementalFramebufferUpdateRequest(struct _rfbClient *);\nsigned char SendScaleSetting(struct _rfbClient *, int);\nsigned char SetFormatAndEncodings(struct _rfbClient *);\nvoid rfbClientCleanup(struct _rfbClient *);\nsigned char HandleRFBServerMessage(struct _rfbClient *);\n]]\n"
  },
  {
    "path": "ffi/util.lua",
    "content": "--[[\nModule for various utility functions\n]]\n\nlocal ffi = require \"ffi\"\nlocal bit = require \"bit\"\n\nrequire(\"ffi/posix_h\")\n\nlocal util = {}\n\nlocal timeval = ffi.new(\"struct timeval\")\nfunction util.gettime()\n\tffi.C.gettimeofday(timeval, nil)\n\treturn tonumber(timeval.tv_sec),\n\t\ttonumber(timeval.tv_usec)\nend\n\nutil.sleep=ffi.C.sleep\nutil.usleep=ffi.C.usleep\n\nlocal statvfs = ffi.new(\"struct statvfs\")\nfunction util.df(path)\n\tffi.C.statvfs(path, statvfs)\n\treturn tonumber(statvfs.f_blocks * statvfs.f_bsize),\n\t\ttonumber(statvfs.f_bfree * statvfs.f_bsize)\nend\n\nfunction util.realpath(path)\n\tlocal path_ptr = ffi.C.realpath(path, nil)\n\tif path_ptr == nil then\n\t\treturn nil\n\tend\n\tpath = ffi.string(path_ptr)\n\tffi.C.free(path_ptr)\n\treturn path\nend\n\nfunction util.utf8charcode(charstring)\n\tlocal ptr = ffi.cast(\"uint8_t *\", charstring)\n\tlocal len = #charstring\n\tlocal result = 0\n\tif len == 1 then\n\t\treturn bit.band(ptr[0], 0x7F)\n\telseif len == 2 then \n\t\treturn bit.lshift(bit.band(ptr[0], 0x1F), 6) +\n\t\t\tbit.band(ptr[1], 0x3F)\n\telseif len == 3 then\n\t\treturn bit.lshift(bit.band(ptr[0], 0x0F), 12) +\n\t\t\tbit.lshift(bit.band(ptr[1], 0x3F), 6) +\n\t\t\tbit.band(ptr[2], 0x3F)\n\tend\nend\n\nfunction util.isEmulated()\n\treturn (ffi.arch ~= \"arm\")\nend\n\nreturn util\n"
  },
  {
    "path": "ffi-cdecl/SDL1_2_decl.c",
    "content": "#include <SDL/SDL.h>\n\n#include \"cdecl.h\"\n\ncdecl_type(Uint32)\ncdecl_type(Sint32)\ncdecl_type(Uint16)\ncdecl_type(Sint16)\ncdecl_type(Uint8)\ncdecl_type(Sint8)\n\n//cdecl_type(SDLKey)\n//cdecl_type(SDLMod)\ncdecl_struct(SDL_keysym)\n\ncdecl_type(SDL_EventType)\ncdecl_type(SDL_EventMask)\n\ncdecl_struct(SDL_ActiveEvent)\ncdecl_struct(SDL_KeyboardEvent)\ncdecl_struct(SDL_MouseMotionEvent)\ncdecl_struct(SDL_MouseButtonEvent)\ncdecl_struct(SDL_JoyAxisEvent)\ncdecl_struct(SDL_JoyBallEvent)\ncdecl_struct(SDL_JoyHatEvent)\ncdecl_struct(SDL_JoyButtonEvent)\ncdecl_struct(SDL_ResizeEvent)\ncdecl_struct(SDL_ExposeEvent)\ncdecl_struct(SDL_QuitEvent)\ncdecl_struct(SDL_UserEvent)\ncdecl_struct(SDL_SysWMEvent)\ncdecl_union(SDL_Event)\n\ncdecl_struct(SDL_Rect)\ncdecl_struct(SDL_Color)\ncdecl_struct(SDL_Palette)\ncdecl_struct(SDL_PixelFormat)\ncdecl_struct(SDL_Surface)\n\ncdecl_func(SDL_Init)\ncdecl_func(SDL_WasInit)\ncdecl_func(SDL_Quit)\ncdecl_func(SDL_SetVideoMode)\ncdecl_func(SDL_EnableKeyRepeat)\ncdecl_func(SDL_WaitEvent)\ncdecl_func(SDL_PollEvent)\ncdecl_func(SDL_GetTicks)\ncdecl_func(SDL_Delay)\ncdecl_func(SDL_LockSurface)\ncdecl_func(SDL_UnlockSurface)\ncdecl_func(SDL_FillRect)\ncdecl_func(SDL_Flip)\ncdecl_func(SDL_MapRGB)\n\ncdecl_const(SDL_INIT_TIMER)\ncdecl_const(SDL_INIT_AUDIO)\ncdecl_const(SDL_INIT_VIDEO)\ncdecl_const(SDL_INIT_CDROM)\ncdecl_const(SDL_INIT_JOYSTICK)\ncdecl_const(SDL_INIT_NOPARACHUTE)\ncdecl_const(SDL_INIT_EVENTTHREAD)\ncdecl_const(SDL_INIT_EVERYTHING)\n\ncdecl_const(SDL_SWSURFACE)\ncdecl_const(SDL_HWSURFACE)\ncdecl_const(SDL_ASYNCBLIT)\n\ncdecl_const(SDL_ANYFORMAT)\ncdecl_const(SDL_HWPALETTE)\ncdecl_const(SDL_DOUBLEBUF)\ncdecl_const(SDL_FULLSCREEN)\ncdecl_const(SDL_OPENGL)\ncdecl_const(SDL_OPENGLBLIT)\ncdecl_const(SDL_RESIZABLE)\ncdecl_const(SDL_NOFRAME)\n\ncdecl_const(SDL_HWACCEL)\ncdecl_const(SDL_SRCCOLORKEY)\ncdecl_const(SDL_RLEACCELOK)\ncdecl_const(SDL_RLEACCEL)\ncdecl_const(SDL_SRCALPHA)\ncdecl_const(SDL_PREALLOC)\n"
  },
  {
    "path": "ffi-cdecl/einkfb_decl.c",
    "content": "// standard Linux framebuffer headers\n#include <linux/fb.h>\n\n#include <linux/ioctl.h>\n// specialized eink framebuffer headers\ntypedef unsigned int u_int;\ntypedef unsigned long u_long;\n#include \"include/einkfb.h\"\n\n#include \"cdecl.h\"\n\ncdecl_enum(fx_type)\ncdecl_struct(update_area_t)\ncdecl_enum(orientation_t)\n\ncdecl_enum(einkfb_events_t)\ncdecl_struct(einkfb_event_t)\n\ncdecl_const(FBIO_EINK_UPDATE_DISPLAY)\ncdecl_const(FBIO_EINK_UPDATE_DISPLAY_AREA)\ncdecl_const(FBIO_EINK_SET_DISPLAY_ORIENTATION)\ncdecl_const(FBIO_EINK_GET_DISPLAY_ORIENTATION)\n\n"
  },
  {
    "path": "ffi-cdecl/include/README",
    "content": "The include file \"einkfb.h\" is distributed with Amazons Linux kernel sources\nfor the Kindle. It has no further copyright notice, so it's assumed to be\nreleased under the GPLv2 originally. Under the \"any later version\" clause, it\nshould be OK to include it in this GPLv3 application.\n\n"
  },
  {
    "path": "ffi-cdecl/include/einkfb.h",
    "content": "#ifndef _EINKFB_H\n#define _EINKFB_H\n\n#define EINK_1BPP               1\n#define EINK_2BPP               2\n#define EINK_4BPP               4\n#define EINK_8BPP               8\n#define EINK_BPP_MAX            EINK_8BPP\n\n#define EINK_WHITE              0x00    // For whacking all the pixels in a...\n#define EINK_BLACK              0xFF    // ...byte (8, 4, 2, or 1) at once.\n\n// Replace EINK_WHITE & EINK_BLACK with the following macros.\n//\n#define eink_white(b)           EINK_WHITE\n#define eink_black(b)           EINK_BLACK\n\n// For pixels (at bytes at a time) other than white/black, the following holds.\n//\n#define eink_pixels(b, p)       (p)\n\n#define EINK_ORIENT_LANDSCAPE   1\n#define EINK_ORIENT_PORTRAIT    0\n\n#define BPP_SIZE(r, b)          (((r)*(b))/8)\n#define BPP_MAX(b)              (1 << (b))\n\n#define U_IN_RANGE(n, m, M)     ((((n) == 0) && ((m) == 0)) || (((n) > (m)) && ((n) <= (M))))\n#define IN_RANGE(n, m, M)       (((n) >= (m)) && ((n) <= (M)))\n\n#define ORIENTATION(x, y)       (((y) > (x)) ? EINK_ORIENT_PORTRAIT : EINK_ORIENT_LANDSCAPE)\n\nstruct raw_image_t\n{\n    int xres,\t\t// image's width, in pixels\n        yres,\t\t// image's height\n        bpp;\t\t// image's pixel (bit) depth\n    \n    __u8  start[]; \t// actual start of image\n};\ntypedef struct raw_image_t raw_image_t;\n\nstruct image_t\n{\n    int xres,       // image's visual width, in pixels\n        xlen,       // image's actual width, used for rowbyte & memory size calculations\n        yres,       // image's height\n        bpp;        // image's pixel (bit) depth\n        \n    __u8  *start;     // pointer to start of image\n};\ntypedef struct image_t image_t;\n\n#define INIT_IMAGE_T() { 0, 0, 0, 0, NULL }\n\nenum splash_screen_type\n{\n    // Simple (non-composite) splash screens.\n    //\n    //splash_screen_powering_off = 0,        // Deprecated.\n    //splash_screen_powering_on,             // Deprecated.\n\n    //splash_screen_powering_off_wireless,   // Deprecated.\n    //splash_screen_powering_on_wireless,    // Deprecated.\n    \n    //splash_screen_exit,                    // Deprecated.\n    splash_screen_logo = 5,\n    \n    //splash_screen_usb_internal,            // Deprecated.\n    //splash_screen_usb_external,            // Deprecated.\n    //splash_screen_usb,                     // Deprecated.\n    \n    //splash_screen_sleep,                   // Deprecated.\n    //splash_screen_update,                  // Deprecated.\n    \n    //num_splash_screens,                    // Deprecated.\n\n    // Composite splash screens & messages.\n    //\n    //splash_screen_drivemode_0,              // Deprecated.\n    //splash_screen_drivemode_1,              // Deprecated.\n    //splash_screen_drivemode_2,              // Deprecated.\n    //splash_screen_drivemode_3,              // Deprecated.\n    \n    splash_screen_power_off_clear_screen = 16,// Message: clear screen and power down controller.\n    //splash_screen_screen_saver_picture,     // Deprecated.\n    \n    splash_screen_shim_picture = 18,          // Message: shim wants a picture displayed.\n\n    splash_screen_lowbatt,                    // Picture: Not composite, post-legacy ordering (Mario only).\n    splash_screen_reboot,                     // Picture: Composite (not used on Fiona).\n    \n    splash_screen_update_initial,             // Composite software-update screens. \n    splash_screen_update_success,             //\n    splash_screen_update_failure,             //\n    splash_screen_update_failure_no_wait,     //\n    \n    splash_screen_repair_needed,              // More composite screens.\n    splash_screen_boot,                       // \n\n    splash_screen_invalid = -1\n};\ntypedef enum splash_screen_type splash_screen_type;\n\n// Alias some of the legacy enumerations for Mario.\n//\n#define splash_screen_usb_recovery_util ((splash_screen_type)8) // splash_screen_usb\n\nstruct power_override_t\n{\n    u_int   cmd;\n    u_long  arg;\n};\ntypedef struct power_override_t power_override_t;\n\nenum fx_type\n{\n    // Deprecated from the HAL, but still supported by the Shim.\n    //\n    fx_mask = 11,                           // Only for use with update_area_t's non-NULL buffer which_fx.\n    fx_buf_is_mask = 14,                    // Same as fx_mask, but doesn't require a doubling (i.e., the buffer & mask are the same).\n    \n    fx_none = -1,                           // No legacy-FX to apply.\n    \n    // Screen-update FX, supported by HAL.\n    //\n    fx_flash = 20,                          // Only for use with update_area_t (for faking a flashing update).\n    fx_invert = 21,                         // Only for use with update_area_t (only inverts output data).\n    \n    fx_update_partial = 0,                  // eInk GU/PU/MU-style (non-flashing) update.\n    fx_update_full = 1                      // eInk GC-style (slower, flashing) update.\n};\ntypedef enum fx_type fx_type;\n\n// The only valid legacy-FX types for area updates are fx_mask and fx_buf_is_mask.\n//\n#define UPDATE_AREA_FX(f)                   \\\n    ((fx_mask == (f))                   ||  \\\n     (fx_buf_is_mask == (f)))\n\n// The default (\"none\") for area updates is partial (non-flashing); full (flashing) updates\n// are for FX and such (i.e., explicit completion is desired).\n//\n#define UPDATE_AREA_PART(f)                 \\\n    ((fx_none == (f))           ||          \\\n     (fx_update_partial == (f)))\n     \n#define UPDATE_AREA_FULL(f)                 \\\n    (UPDATE_AREA_FX(f)          ||          \\\n     (fx_update_full == (f)))\n\n#define UPDATE_AREA_MODE(f)                 \\\n    (UPDATE_AREA_FULL(f) ? fx_update_full   \\\n                         : fx_update_partial)\n\n// For use with the FBIO_EINK_UPDATE_DISPLAY ioctl.\n//\n#define UPDATE_PART(f)                      \\\n    (fx_update_partial == (f))\n#define UPDATE_FULL(f)                      \\\n    (fx_update_full == (f))\n#define UPDATE_MODE(f)                      \\\n    (UPDATE_FULL(f) ? fx_update_full        \\\n                    : fx_update_partial)\n\nstruct rect_t\n{\n    // Note:  The bottom-right (x2, y2) coordinate is actually such that (x2 - x1) and (y2 - y1)\n    //        are xres and yres, respectively, when normally xres and yres would be\n    //        (x2 - x1) + 1 and (y2 - y1) + 1, respectively.\n    //\n    int x1, y1, x2, y2;\n};\ntypedef struct rect_t rect_t;\n\n#define INIT_RECT_T() { 0, 0, 0, 0 }\n#define MAX_EXCLUDE_RECTS 8\n\nstruct fx_t\n{\n    fx_type     update_mode,                // Screen-update FX:  fx_update_full | fx_update_partial.\n                which_fx;                   // Shim (legacy) FX.\n    \n    int         num_exclude_rects;          // 0..MAX_EXCLUDE_RECTS.\n    rect_t      exclude_rects[MAX_EXCLUDE_RECTS];\n};\ntypedef struct fx_t fx_t;\n\n#define INIT_FX_T()                     \\\n    { fx_update_partial, fx_none, 0, {  \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T(),                    \\\n      INIT_RECT_T()} }\n\nstruct update_area_t\n{\n    // Note:  The bottom-right (x2, y2) coordinate is actually such that (x2 - x1) and (y2 - y1)\n    //        are xres and yres, respectively, when normally xres and yres would be\n    //        (x2 - x1) + 1 and (y2 - y1) + 1, respectively.\n    //\n    int         x1, y1,                     // Top-left...\n                x2, y2;                     // ...bottom-right.\n    \n    fx_type     which_fx;                   // FX to use.\n        \n    __u8        *buffer;                    // If NULL, extract from framebuffer, top-left to bottom-right, by rowbytes.\n};\ntypedef struct update_area_t update_area_t;\n\n#define INIT_UPDATE_AREA_T() { 0, 0, 0, 0, fx_none, NULL }\n\nstruct progressbar_xy_t\n{\n    int         x, y;                       // Top-left corner of progressbar's position (ignores x for now).\n};\ntypedef struct progressbar_xy_t progressbar_xy_t;\n\nenum screen_saver_t\n{\n    screen_saver_invalid = 0,\n    screen_saver_valid\n};\ntypedef enum screen_saver_t screen_saver_t;\n\nenum orientation_t\n{\n    orientation_portrait,\n    orientation_portrait_upside_down,\n    orientation_landscape,\n    orientation_landscape_upside_down\n};\ntypedef enum orientation_t orientation_t;\n\n#define num_orientations (orientation_landscape_upside_down + 1)\n\n#define ORIENTATION_PORTRAIT(o)     \\\n    ((orientation_portrait == (o))  || (orientation_portrait_upside_down == (o)))\n    \n#define ORIENTATION_LANDSCAPE(o)    \\\n    ((orientation_landscape == (o)) || (orientation_landscape_upside_down == (o)))\n    \n#define ORIENTATION_SAME(o1, o2)    \\\n    ((ORIENTATION_PORTRAIT(o1)  && ORIENTATION_PORTRAIT(o2)) || \\\n     (ORIENTATION_LANDSCAPE(o1) && ORIENTATION_LANDSCAPE(o2)))\n\nenum einkfb_events_t\n{\n    einkfb_event_update_display = 0,        // FBIO_EINK_UPDATE_DISPLAY\n    einkfb_event_update_display_area,       // FBIO_EINK_UPDATE_DISPLAY_AREA\n    \n    einkfb_event_blank_display,             // FBIOBLANK (fb.h)\n    einkfb_event_rotate_display,            // FBIO_EINK_SET_DISPLAY_ORIENTATION\n    \n    einkfb_event_null = -1\n};\ntypedef enum einkfb_events_t einkfb_events_t;\n\nstruct einkfb_event_t\n{\n    einkfb_events_t event;                  // Not all einkfb_events_t use all of the einkfb_event_t fields.\n    \n    fx_type         update_mode;            // Screen-update FX:  fx_update_full | fx_update_partial.\n    \n    // Note:  The bottom-right (x2, y2) coordinate is actually such that (x2 - x1) and (y2 - y1)\n    //        are xres and yres, respectively, when normally xres and yres would be\n    //        (x2 - x1) + 1 and (y2 - y1) + 1, respectively.\n    //\n    int             x1, y1,                 // Top-left...\n                    x2, y2;                 // ...bottom-right.\n                    \n    orientation_t   orientation;            // Display rotated into this orientation.\n};\ntypedef struct einkfb_event_t einkfb_event_t;\n\nenum reboot_behavior_t\n{\n    reboot_screen_asis,\n    reboot_screen_clear,\n    reboot_screen_splash\n};\ntypedef enum reboot_behavior_t reboot_behavior_t;\n\nenum progressbar_badge_t\n{\n    progressbar_badge_success,\n    progressbar_badge_failure,\n    \n    progressbar_badge_none\n};\ntypedef enum progressbar_badge_t progressbar_badge_t;\n\nenum sleep_behavior_t\n{\n    sleep_behavior_allow_sleep,\n    sleep_behavior_prevent_sleep\n};\ntypedef enum sleep_behavior_t sleep_behavior_t;\n\n#define EINK_FRAME_BUFFER                   \"/dev/fb/0\"\n\n#define SIZEOF_EINK_EVENT                   sizeof(einkfb_event_t)\n#define EINK_EVENTS                         \"/dev/misc/eink_events\"\n\n#define EINK_ROTATE_FILE                    \"/sys/devices/platform/eink_fb.0/send_fake_rotate\"\n#define EINK_ROTATE_FILE_LEN                1\n#define ORIENT_PORTRAIT                     orientation_portrait\n#define ORIENT_PORTRAIT_UPSIDE_DOWN         orientation_portrait_upside_down\n#define ORIENT_LANDSCAPE                    orientation_landscape\n#define ORIENT_LANDSCAPE_UPSIDE_DOWN        orientation_landscape_upside_down\n#define ORIENT_ASIS                         (-1)\n\n#define EINK_USID_FILE                      \"/var/local/eink/usid\"\n\n#define EINK_CLEAR_SCREEN                   0\n#define EINK_CLEAR_BUFFER                   1\n\n#define FBIO_EINK_SCREEN_CLEAR              FBIO_EINK_CLEAR_SCREEN, EINK_CLEAR_SCREEN\n#define FBIO_EINK_BUFFER_CLEAR              FBIO_EINK_CLEAR_SCREEN, EINK_CLEAR_BUFFER\n\n#define FBIO_MIN_SCREEN                     splash_screen_powering_off\n#define FBIO_MAX_SCREEN                     num_splash_screens\n#define FBIO_SCREEN_IN_RANGE(s)             \\\n    ((FBIO_MIN_SCREEN <= (s)) && (FBIO_MAX_SCREEN > (s)))\n\n#define FBIO_MAGIC_NUMBER                   'F'\n\n// Implemented in the eInk HAL.\n//\n#define FBIO_EINK_UPDATE_DISPLAY            _IO(FBIO_MAGIC_NUMBER, 0xdb) // 0x46db (fx_type)\n#define FBIO_EINK_UPDATE_DISPLAY_AREA       _IO(FBIO_MAGIC_NUMBER, 0xdd) // 0x46dd (update_area_t *)\n\n#define FBIO_EINK_RESTORE_DISPLAY           _IO(FBIO_MAGIC_NUMBER, 0xef) // 0x46ef (fx_type)\n\n#define FBIO_EINK_SET_REBOOT_BEHAVIOR       _IO(FBIO_MAGIC_NUMBER, 0xe9) // 0x46e9 (reboot_behavior_t)\n#define FBIO_EINK_GET_REBOOT_BEHAVIOR       _IO(FBIO_MAGIC_NUMBER, 0xed) // 0x46ed (reboot_behavior_t *)\n\n#define FBIO_EINK_SET_DISPLAY_ORIENTATION   _IO(FBIO_MAGIC_NUMBER, 0xf0) // 0x46f0 (orientation_t)\n#define FBIO_EINK_GET_DISPLAY_ORIENTATION   _IO(FBIO_MAGIC_NUMBER, 0xf1) // 0x46f1 (orientation_t *)\n\n#define FBIO_EINK_SET_SLEEP_BEHAVIOR        _IO(FBIO_MAGIC_NUMBER, 0xf2) // 0x46f2 (sleep_behavior_t)\n#define FBIO_EINK_GET_SLEEP_BEHAVIOR        _IO(FBIO_MAGIC_NUMBER, 0xf3) // 0x46f3 (sleep_behavior_t *)\n\n// Implemented in the eInk Shim.\n//\n#define FBIO_EINK_UPDATE_DISPLAY_FX         _IO(FBIO_MAGIC_NUMBER, 0xe4) // 0x46e4 (fx_t *)\n#define FBIO_EINK_SPLASH_SCREEN             _IO(FBIO_MAGIC_NUMBER, 0xdc) // 0x46dc (splash_screen_type)\n#define FBIO_EINK_SPLASH_SCREEN_SLEEP       _IO(FBIO_MAGIC_NUMBER, 0xe0) // 0x46e0 (splash_screen_type)\n#define FBIO_EINK_OFF_CLEAR_SCREEN          _IO(FBIO_MAGIC_NUMBER, 0xdf) // 0x46df (EINK_CLEAR_SCREEN || EINK_CLEAR_BUFFER)\n#define FBIO_EINK_CLEAR_SCREEN              _IO(FBIO_MAGIC_NUMBER, 0xe1) // 0x46e1 (no args)\n#define FBIO_EINK_POWER_OVERRIDE            _IO(FBIO_MAGIC_NUMBER, 0xe3) // 0x46e3 (power_override_t *)\n\n#define FBIO_EINK_PROGRESSBAR               _IO(FBIO_MAGIC_NUMBER, 0xea) // 0x46ea (int: 0..100 -> draw progressbar || !(0..100) -> clear progressbar)\n#define FBIO_EINK_PROGRESSBAR_SET_XY        _IO(FBIO_MAGIC_NUMBER, 0xeb) // 0x46eb (progressbar_xy_t *)\n#define FBIO_EINK_PROGRESSBAR_BADGE         _IO(FBIO_MAGIC_NUMBER, 0xec) // 0x46ec (progressbar_badge_t);\n#define FBIO_EINK_PROGRESSBAR_BACKGROUND    _IO(FBIO_MAGIC_NUMBER, 0xf4) // 0x46f4 (int: EINKFB_WHITE || EINKFB_BLACK)\n\n// Deprecated from the HAL & Shim.\n//\n//#define FBIO_EINK_UPDATE_DISPLAY_ASYNC    _IO(FBIO_MAGIC_NUMBER, 0xde) // 0x46de (fx_type: fx_update_full || fx_update_partial)\n//#define FBIO_EINK_FAKE_PNLCD              _IO(FBIO_MAGIC_NUMBER, 0xe8) // 0x46e8 (char *)\n\n// For use with /proc/eink_fb/update_display.\n//\n#define PROC_EINK_UPDATE_DISPLAY_CLS        0   // FBIO_EINK_CLEAR_SCREEN\n#define PROC_EINK_UPDATE_DISPLAY_PART       1   // FBIO_EINK_UPDATE_DISPLAY(fx_update_partial)\n#define PROC_EINK_UPDATE_DISPLAY_FULL       2   // FBIO_EINK_UPDATE_DISPLAY(fx_update_full)\n#define PROC_EINK_UPDATE_DISPLAY_AREA       3   // FBIO_EINK_UPDATE_DISPLAY_AREA\n//#define PROC_EINK_UPDATE_DISPLAY_REST     4   // FBIO_EINK_RESTORE_SCREEN\n#define PROC_EINK_UPDATE_DISPLAY_SCRN       5   // FBIO_EINK_SPLASH_SCREEN\n#define PROC_EINK_UPDATE_DISPLAY_OVRD       6   // FBIO_EINK_FPOW_OVERRIDE\n#define PROC_EINK_UPDATE_DISPLAY_FX         7   // FBIO_EINK_UPDATE_DISPLAY_FX\n//#define PROC_EINK_UPDATE_DISPLAY_SYNC     8   // FBIO_EINK_SYNC_BUFFERS\n//#define PROC_EINK_UPDATE_DISPLAY_PNLCD    9   // FBIO_EINK_FAKE_PNLCD\n#define PROC_EINK_SET_REBOOT_BEHAVIOR      10   // FBIO_EINK_SET_REBOOT_BEHAVIOR\n#define PROC_EINK_SET_PROGRESSBAR_XY       11   // FBIO_EINK_PROGRESSBAR_SET_XY\n#define PROC_EINK_UPDATE_DISPLAY_SCRN_SLP  12   // FBIO_EINK_SPLASH_SCREEN_SLEEP\n#define PROC_EINK_PROGRESSBAR_BADGE        13   // FBIO_EINK_PROGRESSBAR_BADGE\n#define PROC_EINK_SET_DISPLAY_ORIENTATION  14   // FBIO_EINK_SET_DISPLAY_ORIENTATION\n#define PROC_EINK_RESTORE_DISPLAY          15   // FBIO_EINK_RESTORE_DISPLAY\n#define PROC_EINK_SET_SLEEP_BEHAVIOR       16   // FBIO_EINK_SET_SLEEP_BEHAVIOR\n#define PROC_EINK_PROGRESSBAR_BACKGROUND   17   // FBIO_EINK_PROGRESSBAR_BACKGROUND\n#define PROC_EINK_UPDATE_DISPLAY_WHICH     18   // FBIO_EINK_UPDATE_DISPLAY\n\n//#define PROC_EINK_FAKE_PNLCD_TEST       100   // Programmatically drive FBIO_EINK_FAKE_PNLCD (not implemented).\n#define PROC_EINK_GRAYSCALE_TEST          101   // Fills display with white-to-black ramp at current bit depth.\n\n// Inter-module/inter-driver eink ioctl access.\n//\nextern int fiona_eink_ioctl_stub(unsigned int cmd, unsigned long arg);\n\n#define eink_sys_ioctl(cmd, arg)            (get_fb_ioctl() ? (*get_fb_ioctl())((unsigned int)cmd, (unsigned long)arg)      \\\n                                                            : fiona_eink_ioctl_stub((unsigned int)cmd, (unsigned long)arg))\n\n#endif // _EINKFB_H\n"
  },
  {
    "path": "ffi-cdecl/include/mxcfb-kindle.h",
    "content": "/*\n * Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.\n *\n * - Modified by houqp, added mxcfb_update_data struct from GeekMaster's\n *   video player, refer to:\n *   http://www.mobileread.com/forums/showthread.php?t=177455&page=10\n *\n * - Modified mxcfb_alt_buffer_data struct according to include/linux/mxcfb.h\n *   from Kindle 5.3.0 firmware. Thanks to eureka@mobileread.\n *   http://www.mobileread.com/forums/showpost.php?p=2337118&postcount=818\n */\n\n/*\n * The code contained herein is licensed under the GNU Lesser General\n * Public License.  You may obtain a copy of the GNU Lesser General\n * Public License Version 2.1 or later at the following locations:\n *\n * http://www.opensource.org/licenses/lgpl-license.html\n * http://www.gnu.org/copyleft/lgpl.html\n */\n\n/*\n * @file arch-mxc/   mxcfb.h\n *\n * @brief Global header file for the MXC Frame buffer\n *\n * @ingroup Framebuffer\n */\n#ifndef __ASM_ARCH_MXCFB_H__\n#define __ASM_ARCH_MXCFB_H__\n\n//#include <linux/fb.h>\n\n#define FB_SYNC_OE_LOW_ACT\t0x80000000\n#define FB_SYNC_CLK_LAT_FALL\t0x40000000\n#define FB_SYNC_DATA_INVERT\t0x20000000\n#define FB_SYNC_CLK_IDLE_EN\t0x10000000\n#define FB_SYNC_SHARP_MODE\t0x08000000\n#define FB_SYNC_SWAP_RGB\t0x04000000\n\nstruct mxcfb_gbl_alpha {\n\tint enable;\n\tint alpha;\n};\n\nstruct mxcfb_loc_alpha {\n\tint enable;\n\tint alpha_in_pixel;\n\tunsigned long alpha_phy_addr0;\n\tunsigned long alpha_phy_addr1;\n};\n\nstruct mxcfb_color_key {\n\tint enable;\n\t__u32 color_key;\n};\n\nstruct mxcfb_pos {\n\t__u16 x;\n\t__u16 y;\n};\n\nstruct mxcfb_gamma {\n\tint enable;\n\tint constk[16];\n\tint slopek[16];\n};\n\nstruct mxcfb_rect {\n\t__u32 top;\n\t__u32 left;\n\t__u32 width;\n\t__u32 height;\n};\n\n#define GRAYSCALE_8BIT\t\t\t\t0x1\n#define GRAYSCALE_8BIT_INVERTED\t\t\t0x2\n\n#define AUTO_UPDATE_MODE_REGION_MODE\t\t0\n#define AUTO_UPDATE_MODE_AUTOMATIC_MODE\t\t1\n\n#define UPDATE_SCHEME_SNAPSHOT\t\t\t0\n#define UPDATE_SCHEME_QUEUE\t\t\t1\n#define UPDATE_SCHEME_QUEUE_AND_MERGE\t\t2\n\n#define UPDATE_MODE_PARTIAL\t\t\t0x0\n#define UPDATE_MODE_FULL\t\t\t0x1\n\n#define WAVEFORM_MODE_INIT\t\t\t0x0\t/* Screen goes to white (clears) */\n#define WAVEFORM_MODE_DU\t\t\t0x1\t/* Grey->white/grey->black */\n#define WAVEFORM_MODE_GC16\t\t\t0x2\t/* High fidelity (flashing) */\n#define WAVEFORM_MODE_GC4\t\t\tWAVEFORM_MODE_GC16 /* For compatibility */\n#define WAVEFORM_MODE_GC16_FAST\t\t0x3\t/* Medium fidelity */\n#define WAVEFORM_MODE_A2\t\t\t0x4\t/* Faster but even lower fidelity */\n#define WAVEFORM_MODE_GL16\t\t\t0x5\t/* High fidelity from white transition */\n#define WAVEFORM_MODE_GL16_FAST\t\t0x6\t/* Medium fidelity from white transition */\n\n#define WAVEFORM_MODE_AUTO\t\t\t257\n\n#define TEMP_USE_AMBIENT\t\t\t0x1000\n\n#define EPDC_FLAG_ENABLE_INVERSION\t\t0x01\n#define EPDC_FLAG_FORCE_MONOCHROME\t\t0x02\n#define EPDC_FLAG_USE_ALT_BUFFER\t\t0x100\n\n#define FB_POWERDOWN_DISABLE\t\t\t-1\n#define FB_TEMP_AUTO_UPDATE_DISABLE     -1\n\nstruct mxcfb_alt_buffer_data {\n\t__u32 phys_addr;\n\t__u32 width;\t/* width of entire buffer */\n\t__u32 height;\t/* height of entire buffer */\n\tstruct mxcfb_rect alt_update_region;\t/* region within buffer to update */\n};\n\nstruct mxcfb_update_data {\n\tstruct mxcfb_rect update_region;\n\t__u32 waveform_mode;\n\t__u32 update_mode;\n\t__u32 update_marker;\n\t/* these two fields have been added by amazon */\n\t__u32 hist_bw_waveform_mode;\n\t__u32 hist_gray_waveform_mode;\n\tint temp;\n\tuint flags;\n\tstruct mxcfb_alt_buffer_data alt_buffer_data;\n};\ntypedef struct mxcfb_update_data mxcfb_update_data;\n\n/* this is only used in kindle firmware 5.0, later version (5.1) has changed\n * the struct to mxcfb_update_data (see above) */\nstruct mxcfb_update_data_50x {\n\tstruct mxcfb_rect update_region;\n\t__u32 waveform_mode;\n\t__u32 update_mode;\n\t__u32 update_marker;\n\tint temp;\n\tuint flags;\n\tstruct mxcfb_alt_buffer_data alt_buffer_data;\n};\n\n/*\n * Structure used to define waveform modes for driver\n * Needed for driver to perform auto-waveform selection\n */\nstruct mxcfb_waveform_modes {\n\tint mode_init;\n\tint mode_du;\n\tint mode_gc4;\n\tint mode_gc8;\n\tint mode_gc16;\n\tint mode_gc32;\n};\n\n#define MXCFB_WAIT_FOR_VSYNC\t_IOW('F', 0x20, u_int32_t)\n#define MXCFB_SET_GBL_ALPHA     _IOW('F', 0x21, struct mxcfb_gbl_alpha)\n#define MXCFB_SET_CLR_KEY       _IOW('F', 0x22, struct mxcfb_color_key)\n#define MXCFB_SET_OVERLAY_POS   _IOWR('F', 0x24, struct mxcfb_pos)\n#define MXCFB_GET_FB_IPU_CHAN \t_IOR('F', 0x25, u_int32_t)\n#define MXCFB_SET_LOC_ALPHA     _IOWR('F', 0x26, struct mxcfb_loc_alpha)\n#define MXCFB_SET_LOC_ALP_BUF    _IOW('F', 0x27, unsigned long)\n#define MXCFB_SET_GAMMA\t       _IOW('F', 0x28, struct mxcfb_gamma)\n#define MXCFB_GET_FB_IPU_DI \t_IOR('F', 0x29, u_int32_t)\n#define MXCFB_GET_DIFMT\t       _IOR('F', 0x2A, u_int32_t)\n#define MXCFB_GET_FB_BLANK     _IOR('F', 0x2B, u_int32_t)\n#define MXCFB_SET_DIFMT\t\t_IOW('F', 0x2C, u_int32_t)\n\n/* IOCTLs for E-ink panel updates */\n#define MXCFB_SET_WAVEFORM_MODES\t_IOW('F', 0x2B, struct mxcfb_waveform_modes)\n#define MXCFB_SET_TEMPERATURE\t\t_IOW('F', 0x2C, int32_t)\n#define MXCFB_SET_AUTO_UPDATE_MODE\t_IOW('F', 0x2D, __u32)\n#define MXCFB_SEND_UPDATE_50X\t\t_IOW('F', 0x2E, struct mxcfb_update_data_50x)\n#define MXCFB_WAIT_FOR_UPDATE_COMPLETE\t_IOW('F', 0x2F, __u32)\n#define MXCFB_SET_PWRDOWN_DELAY\t\t_IOW('F', 0x30, int32_t)\n#define MXCFB_GET_PWRDOWN_DELAY\t\t_IOR('F', 0x31, int32_t)\n#define MXCFB_SET_UPDATE_SCHEME\t\t_IOW('F', 0x32, __u32)\n#define MXCFB_GET_PMIC_TEMPERATURE\t_IOR('F', 0x32, int32_t)\n#define MXCFB_SET_BORDER_MODE\t\t_IOR('F', 0x33, int32_t)\n#define MXCFB_SET_EPD_PWR0_CTRL\t\t_IOR('F', 0x34, int32_t)\n#define MXCFB_SET_EPD_PWR2_CTRL\t\t_IOR('F', 0x35, int32_t)\n#define MXCFB_SET_TEMP_AUTO_UPDATE_PERIOD     _IOR('F', 0x36, int32_t)\n#define MXCFB_SET_MERGE_ON_WAVEFORM_MISMATCH\t_IOW('F', 0x37, int32_t)\n\n/* IOCTLs for E-ink panel updates, kindle firmware version >= 5.1 */\n#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)\n\n#ifdef __KERNEL__\n\nextern struct fb_videomode mxcfb_modedb[];\nextern int mxcfb_modedb_sz;\n\nenum {\n\tMXCFB_REFRESH_OFF,\n\tMXCFB_REFRESH_AUTO,\n\tMXCFB_REFRESH_PARTIAL,\n};\n\nint mxcfb_set_refresh_mode(struct fb_info *fbi, int mode,\n\t\t\t   struct mxcfb_rect *update_region);\n\nint mxc_elcdif_frame_addr_setup(dma_addr_t phys);\n#endif\t\t\t\t/* __KERNEL__ */\n#endif\n"
  },
  {
    "path": "ffi-cdecl/include/mxcfb-kobo.h",
    "content": "/*\n * Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.\n *\n * - slightly modified (commented out include of fb.h) for Lua integration\n */\n\n/*\n * The code contained herein is licensed under the GNU Lesser General\n * Public License.  You may obtain a copy of the GNU Lesser General\n * Public License Version 2.1 or later at the following locations:\n *\n * http://www.opensource.org/licenses/lgpl-license.html\n * http://www.gnu.org/copyleft/lgpl.html\n */\n\n/*\n * @file arch-mxc/   mxcfb.h\n *\n * @brief Global header file for the MXC Frame buffer\n *\n * @ingroup Framebuffer\n */\n#ifndef __ASM_ARCH_MXCFB_H__\n#define __ASM_ARCH_MXCFB_H__\n\n//#include <linux/fb.h>\n\n#define FB_SYNC_OE_LOW_ACT\t0x80000000\n#define FB_SYNC_CLK_LAT_FALL\t0x40000000\n#define FB_SYNC_DATA_INVERT\t0x20000000\n#define FB_SYNC_CLK_IDLE_EN\t0x10000000\n#define FB_SYNC_SHARP_MODE\t0x08000000\n#define FB_SYNC_SWAP_RGB\t0x04000000\n\nstruct mxcfb_gbl_alpha {\n\tint enable;\n\tint alpha;\n};\n\nstruct mxcfb_loc_alpha {\n\tint enable;\n\tint alpha_in_pixel;\n\tunsigned long alpha_phy_addr0;\n\tunsigned long alpha_phy_addr1;\n};\n\nstruct mxcfb_color_key {\n\tint enable;\n\t__u32 color_key;\n};\n\nstruct mxcfb_pos {\n\t__u16 x;\n\t__u16 y;\n};\n\nstruct mxcfb_gamma {\n\tint enable;\n\tint constk[16];\n\tint slopek[16];\n};\n\nstruct mxcfb_rect {\n\t__u32 top;\n\t__u32 left;\n\t__u32 width;\n\t__u32 height;\n};\n\n#define GRAYSCALE_8BIT\t\t\t\t0x1\n#define GRAYSCALE_8BIT_INVERTED\t\t\t0x2\n\n#define AUTO_UPDATE_MODE_REGION_MODE\t\t0\n#define AUTO_UPDATE_MODE_AUTOMATIC_MODE\t\t1\n\n#define UPDATE_SCHEME_SNAPSHOT\t\t\t0\n#define UPDATE_SCHEME_QUEUE\t\t\t1\n#define UPDATE_SCHEME_QUEUE_AND_MERGE\t\t2\n\n#define UPDATE_MODE_PARTIAL\t\t\t0x0\n#define UPDATE_MODE_FULL\t\t\t0x1\n\n#define WAVEFORM_MODE_AUTO\t\t\t257\n\n#define TEMP_USE_AMBIENT\t\t\t0x1000\n\n#define EPDC_FLAG_ENABLE_INVERSION\t\t0x01\n#define EPDC_FLAG_FORCE_MONOCHROME\t\t0x02\n#define EPDC_FLAG_USE_ALT_BUFFER\t\t0x100\n\n#define FB_POWERDOWN_DISABLE\t\t\t-1\n#define FB_TEMP_AUTO_UPDATE_DISABLE     -1\n\nstruct mxcfb_alt_buffer_data {\n\tvoid *virt_addr;\n\t__u32 phys_addr;\n\t__u32 width;\t/* width of entire buffer */\n\t__u32 height;\t/* height of entire buffer */\n\tstruct mxcfb_rect alt_update_region;\t/* region within buffer to update */\n};\n\nstruct mxcfb_update_data {\n\tstruct mxcfb_rect update_region;\n\t__u32 waveform_mode;\n\t__u32 update_mode;\n\t__u32 update_marker;\n\tint temp;\n\tuint flags;\n\tstruct mxcfb_alt_buffer_data alt_buffer_data;\n};\n\n/*\n * Structure used to define waveform modes for driver\n * Needed for driver to perform auto-waveform selection\n */\nstruct mxcfb_waveform_modes {\n\tint mode_init;\n\tint mode_du;\n\tint mode_gc4;\n\tint mode_gc8;\n\tint mode_gc16;\n\tint mode_gc32;\n};\n\n#define MXCFB_WAIT_FOR_VSYNC\t_IOW('F', 0x20, u_int32_t)\n#define MXCFB_SET_GBL_ALPHA     _IOW('F', 0x21, struct mxcfb_gbl_alpha)\n#define MXCFB_SET_CLR_KEY       _IOW('F', 0x22, struct mxcfb_color_key)\n#define MXCFB_SET_OVERLAY_POS   _IOWR('F', 0x24, struct mxcfb_pos)\n#define MXCFB_GET_FB_IPU_CHAN \t_IOR('F', 0x25, u_int32_t)\n#define MXCFB_SET_LOC_ALPHA     _IOWR('F', 0x26, struct mxcfb_loc_alpha)\n#define MXCFB_SET_LOC_ALP_BUF    _IOW('F', 0x27, unsigned long)\n#define MXCFB_SET_GAMMA\t       _IOW('F', 0x28, struct mxcfb_gamma)\n#define MXCFB_GET_FB_IPU_DI \t_IOR('F', 0x29, u_int32_t)\n#define MXCFB_GET_DIFMT\t       _IOR('F', 0x2A, u_int32_t)\n#define MXCFB_GET_FB_BLANK     _IOR('F', 0x2B, u_int32_t)\n#define MXCFB_SET_DIFMT\t\t_IOW('F', 0x2C, u_int32_t)\n\n/* IOCTLs for E-ink panel updates */\n#define MXCFB_SET_WAVEFORM_MODES\t_IOW('F', 0x2B, struct mxcfb_waveform_modes)\n#define MXCFB_SET_TEMPERATURE\t\t_IOW('F', 0x2C, int32_t)\n#define MXCFB_SET_AUTO_UPDATE_MODE\t_IOW('F', 0x2D, __u32)\n#define MXCFB_SEND_UPDATE\t\t_IOW('F', 0x2E, struct mxcfb_update_data)\n#define MXCFB_WAIT_FOR_UPDATE_COMPLETE\t_IOW('F', 0x2F, __u32)\n#define MXCFB_SET_PWRDOWN_DELAY\t\t_IOW('F', 0x30, int32_t)\n#define MXCFB_GET_PWRDOWN_DELAY\t\t_IOR('F', 0x31, int32_t)\n#define MXCFB_SET_UPDATE_SCHEME\t\t_IOW('F', 0x32, __u32)\n#define MXCFB_GET_PMIC_TEMPERATURE\t_IOR('F', 0x32, int32_t)\n#define MXCFB_SET_BORDER_MODE\t\t_IOR('F', 0x33, int32_t)\n#define MXCFB_SET_EPD_PWR0_CTRL\t\t_IOR('F', 0x34, int32_t)\n#define MXCFB_SET_EPD_PWR2_CTRL\t\t_IOR('F', 0x35, int32_t)\n#define MXCFB_SET_TEMP_AUTO_UPDATE_PERIOD     _IOR('F', 0x36, int32_t)\n#define MXCFB_SET_MERGE_ON_WAVEFORM_MISMATCH\t_IOW('F', 0x37, int32_t)\n\n#ifdef __KERNEL__\n\nextern struct fb_videomode mxcfb_modedb[];\nextern int mxcfb_modedb_sz;\n\nenum {\n\tMXCFB_REFRESH_OFF,\n\tMXCFB_REFRESH_AUTO,\n\tMXCFB_REFRESH_PARTIAL,\n};\n\nint mxcfb_set_refresh_mode(struct fb_info *fbi, int mode,\n\t\t\t   struct mxcfb_rect *update_region);\n\nint mxc_elcdif_frame_addr_setup(dma_addr_t phys);\n#endif\t\t\t\t/* __KERNEL__ */\n#endif\n"
  },
  {
    "path": "ffi-cdecl/include/mxcfb.h",
    "content": "/*\n * Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.\n *\n * - Modified by houqp, added mxcfb_update_data struct from GeekMaster's\n *   video player, refer to:\n *   http://www.mobileread.com/forums/showthread.php?t=177455&page=10\n *\n * - Modified mxcfb_alt_buffer_data struct according to include/linux/mxcfb.h\n *   from Kindle 5.3.0 firmware. Thanks to eureka@mobileread.\n *   http://www.mobileread.com/forums/showpost.php?p=2337118&postcount=818\n *\n *\n * The code contained herein is licensed under the GNU Lesser General\n * Public License.  You may obtain a copy of the GNU Lesser General\n * Public License Version 2.1 or later at the following locations:\n *\n * http://www.opensource.org/licenses/lgpl-license.html\n * http://www.gnu.org/copyleft/lgpl.html\n */\n\n\n/*\n * @file arch-mxc/   mxcfb.h\n *\n * @brief Global header file for the MXC Frame buffer\n *\n * @ingroup Framebuffer\n */\n\n#ifndef __ASM_ARCH_MXCFB_H__\n#define __ASM_ARCH_MXCFB_H__\n\n//#include <linux/fb.h>\n\n#define FB_SYNC_OE_LOW_ACT\t0x80000000\n#define FB_SYNC_CLK_LAT_FALL\t0x40000000\n#define FB_SYNC_DATA_INVERT\t0x20000000\n#define FB_SYNC_CLK_IDLE_EN\t0x10000000\n#define FB_SYNC_SHARP_MODE\t0x08000000\n#define FB_SYNC_SWAP_RGB\t0x04000000\n\nstruct mxcfb_gbl_alpha {\n\tint enable;\n\tint alpha;\n};\n\nstruct mxcfb_loc_alpha {\n\tint enable;\n\tint alpha_in_pixel;\n\tunsigned long alpha_phy_addr0;\n\tunsigned long alpha_phy_addr1;\n};\n\nstruct mxcfb_color_key {\n\tint enable;\n\t__u32 color_key;\n};\n\nstruct mxcfb_pos {\n\t__u16 x;\n\t__u16 y;\n};\n\nstruct mxcfb_gamma {\n\tint enable;\n\tint constk[16];\n\tint slopek[16];\n};\n\nstruct mxcfb_rect {\n\t__u32 top;\n\t__u32 left;\n\t__u32 width;\n\t__u32 height;\n};\n\n#define GRAYSCALE_8BIT\t\t\t\t0x1\n#define GRAYSCALE_8BIT_INVERTED\t\t\t0x2\n\n#define AUTO_UPDATE_MODE_REGION_MODE\t\t0\n#define AUTO_UPDATE_MODE_AUTOMATIC_MODE\t\t1\n\n#define UPDATE_SCHEME_SNAPSHOT\t\t\t0\n#define UPDATE_SCHEME_QUEUE\t\t\t1\n#define UPDATE_SCHEME_QUEUE_AND_MERGE\t\t2\n\n#define UPDATE_MODE_PARTIAL\t\t\t0x0\n#define UPDATE_MODE_FULL\t\t\t0x1\n\n#define WAVEFORM_MODE_INIT\t\t\t0x0\t/* Screen goes to white (clears) */\n#define WAVEFORM_MODE_DU\t\t\t0x1\t/* Grey->white/grey->black */\n#define WAVEFORM_MODE_GC16\t\t\t0x2\t/* High fidelity (flashing) */\n#define WAVEFORM_MODE_GC4\t\t\tWAVEFORM_MODE_GC16 /* For compatibility */\n#define WAVEFORM_MODE_GC16_FAST\t\t0x3\t/* Medium fidelity */\n#define WAVEFORM_MODE_A2\t\t\t0x4\t/* Faster but even lower fidelity */\n#define WAVEFORM_MODE_GL16\t\t\t0x5\t/* High fidelity from white transition */\n#define WAVEFORM_MODE_GL16_FAST\t\t0x6\t/* Medium fidelity from white transition */\n\n#define WAVEFORM_MODE_AUTO\t\t\t257\n\n#define TEMP_USE_AMBIENT\t\t\t0x1000\n\n#define EPDC_FLAG_ENABLE_INVERSION\t\t0x01\n#define EPDC_FLAG_FORCE_MONOCHROME\t\t0x02\n#define EPDC_FLAG_USE_ALT_BUFFER\t\t0x100\n\n#define FB_POWERDOWN_DISABLE\t\t\t-1\n#define FB_TEMP_AUTO_UPDATE_DISABLE     -1\n\nstruct mxcfb_alt_buffer_data {\n#ifdef KOBO_PLATFORM\n\t/* virt_addr is not included in amazon's source */\n\tvoid *virt_addr;\n#endif\n\t__u32 phys_addr;\n\t__u32 width;\t/* width of entire buffer */\n\t__u32 height;\t/* height of entire buffer */\n\tstruct mxcfb_rect alt_update_region;\t/* region within buffer to update */\n};\n\nstruct mxcfb_update_data {\n\tstruct mxcfb_rect update_region;\n\t__u32 waveform_mode;\n\t__u32 update_mode;\n\t__u32 update_marker;\n#ifndef KOBO_PLATFORM\n\t/* these two fields have been added by amazon */\n\t__u32 hist_bw_waveform_mode;\n\t__u32 hist_gray_waveform_mode;\n#endif\n\tint temp;\n\tuint flags;\n\tstruct mxcfb_alt_buffer_data alt_buffer_data;\n};\ntypedef struct mxcfb_update_data mxcfb_update_data;\n\n/* this is only used in kindle firmware 5.0, later version (5.1) has changed\n * the struct to mxcfb_update_data (see above) */\nstruct mxcfb_update_data_50x {\n\tstruct mxcfb_rect update_region;\n\t__u32 waveform_mode;\n\t__u32 update_mode;\n\t__u32 update_marker;\n\tint temp;\n\tuint flags;\n\tstruct mxcfb_alt_buffer_data alt_buffer_data;\n};\n\n/*\n * Structure used to define waveform modes for driver\n * Needed for driver to perform auto-waveform selection\n */\nstruct mxcfb_waveform_modes {\n\tint mode_init;\n\tint mode_du;\n\tint mode_gc4;\n\tint mode_gc8;\n\tint mode_gc16;\n\tint mode_gc32;\n};\n\n#define MXCFB_WAIT_FOR_VSYNC\t_IOW('F', 0x20, u_int32_t)\n#define MXCFB_SET_GBL_ALPHA     _IOW('F', 0x21, struct mxcfb_gbl_alpha)\n#define MXCFB_SET_CLR_KEY       _IOW('F', 0x22, struct mxcfb_color_key)\n#define MXCFB_SET_OVERLAY_POS   _IOWR('F', 0x24, struct mxcfb_pos)\n#define MXCFB_GET_FB_IPU_CHAN \t_IOR('F', 0x25, u_int32_t)\n#define MXCFB_SET_LOC_ALPHA     _IOWR('F', 0x26, struct mxcfb_loc_alpha)\n#define MXCFB_SET_LOC_ALP_BUF    _IOW('F', 0x27, unsigned long)\n#define MXCFB_SET_GAMMA\t       _IOW('F', 0x28, struct mxcfb_gamma)\n#define MXCFB_GET_FB_IPU_DI \t_IOR('F', 0x29, u_int32_t)\n#define MXCFB_GET_DIFMT\t       _IOR('F', 0x2A, u_int32_t)\n#define MXCFB_GET_FB_BLANK     _IOR('F', 0x2B, u_int32_t)\n#define MXCFB_SET_DIFMT\t\t_IOW('F', 0x2C, u_int32_t)\n\n/* IOCTLs for E-ink panel updates */\n#define MXCFB_SET_WAVEFORM_MODES\t_IOW('F', 0x2B, struct mxcfb_waveform_modes)\n#define MXCFB_SET_TEMPERATURE\t\t_IOW('F', 0x2C, int32_t)\n#define MXCFB_SET_AUTO_UPDATE_MODE\t_IOW('F', 0x2D, __u32)\n#define MXCFB_SEND_UPDATE_50X\t\t_IOW('F', 0x2E, struct mxcfb_update_data_50x)\n#define MXCFB_WAIT_FOR_UPDATE_COMPLETE\t_IOW('F', 0x2F, __u32)\n#define MXCFB_SET_PWRDOWN_DELAY\t\t_IOW('F', 0x30, int32_t)\n#define MXCFB_GET_PWRDOWN_DELAY\t\t_IOR('F', 0x31, int32_t)\n#define MXCFB_SET_UPDATE_SCHEME\t\t_IOW('F', 0x32, __u32)\n#define MXCFB_GET_PMIC_TEMPERATURE\t_IOR('F', 0x32, int32_t)\n#define MXCFB_SET_BORDER_MODE\t\t_IOR('F', 0x33, int32_t)\n#define MXCFB_SET_EPD_PWR0_CTRL\t\t_IOR('F', 0x34, int32_t)\n#define MXCFB_SET_EPD_PWR2_CTRL\t\t_IOR('F', 0x35, int32_t)\n#define MXCFB_SET_TEMP_AUTO_UPDATE_PERIOD     _IOR('F', 0x36, int32_t)\n#define MXCFB_SET_MERGE_ON_WAVEFORM_MISMATCH\t_IOW('F', 0x37, int32_t)\n\n/* IOCTLs for E-ink panel updates, kindle firmware version >= 5.1 */\n#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)\n\n#ifdef __KERNEL__\n\nextern struct fb_videomode mxcfb_modedb[];\nextern int mxcfb_modedb_sz;\n\nenum {\n\tMXCFB_REFRESH_OFF,\n\tMXCFB_REFRESH_AUTO,\n\tMXCFB_REFRESH_PARTIAL,\n};\n\nint mxcfb_set_refresh_mode(struct fb_info *fbi, int mode,\n\t\t\t   struct mxcfb_rect *update_region);\n\nint mxc_elcdif_frame_addr_setup(dma_addr_t phys);\n#endif\t\t\t\t/* __KERNEL__ */\n#endif\n"
  },
  {
    "path": "ffi-cdecl/linux_fb_decl.c",
    "content": "// standard Linux framebuffer headers\n#include <linux/fb.h>\n\n#include <linux/ioctl.h>\n\n#include \"cdecl.h\"\n\ncdecl_const(FBIOGET_FSCREENINFO)\ncdecl_const(FBIOGET_VSCREENINFO)\n\ncdecl_const(FB_TYPE_PACKED_PIXELS)\n\ncdecl_struct(fb_bitfield)\ncdecl_struct(fb_fix_screeninfo)\ncdecl_struct(fb_var_screeninfo)\n"
  },
  {
    "path": "ffi-cdecl/linux_input_decl.c",
    "content": "#include <linux/input.h>\n\n#include \"cdecl.h\"\n\ncdecl_const(EVIOCGRAB)\n\ncdecl_const(EV_SYN)\ncdecl_const(EV_KEY)\ncdecl_const(EV_REL)\ncdecl_const(EV_ABS)\ncdecl_const(EV_MSC)\ncdecl_const(EV_SW)\ncdecl_const(EV_LED)\ncdecl_const(EV_SND)\ncdecl_const(EV_REP)\ncdecl_const(EV_FF)\ncdecl_const(EV_PWR)\ncdecl_const(EV_FF_STATUS)\ncdecl_const(EV_MAX)\n\ncdecl_const(SYN_REPORT)\ncdecl_const(SYN_CONFIG)\ncdecl_const(SYN_MT_REPORT)\ncdecl_const(SYN_DROPPED)\n\ncdecl_const(ABS_MT_SLOT)\ncdecl_const(ABS_MT_TOUCH_MAJOR)\ncdecl_const(ABS_MT_TOUCH_MINOR)\ncdecl_const(ABS_MT_WIDTH_MAJOR)\ncdecl_const(ABS_MT_WIDTH_MINOR)\ncdecl_const(ABS_MT_ORIENTATION)\ncdecl_const(ABS_MT_POSITION_X)\ncdecl_const(ABS_MT_POSITION_Y)\ncdecl_const(ABS_MT_TOOL_TYPE)\ncdecl_const(ABS_MT_BLOB_ID)\ncdecl_const(ABS_MT_TRACKING_ID)\ncdecl_const(ABS_MT_PRESSURE)\ncdecl_const(ABS_MT_DISTANCE)\ncdecl_const(ABS_MT_TOOL_X)\ncdecl_const(ABS_MT_TOOL_Y)\n\ncdecl_struct(input_event)\n"
  },
  {
    "path": "ffi-cdecl/mxcfb_kindle_decl.c",
    "content": "// standard Linux framebuffer headers\n#include <linux/fb.h>\n\n#include <linux/ioctl.h>\n// specialized eink framebuffer headers\ntypedef unsigned int uint;\n#include \"include/mxcfb-kindle.h\"\n\n#include \"cdecl.h\"\n\ncdecl_struct(mxcfb_rect)\ncdecl_struct(mxcfb_alt_buffer_data)\ncdecl_struct(mxcfb_alt_buffer_data_kobo)\ncdecl_struct(mxcfb_update_data)\ncdecl_struct(mxcfb_update_data_kobo)\n\ncdecl_const(MXCFB_SEND_UPDATE)\n\n"
  },
  {
    "path": "ffi-cdecl/mxcfb_kobo_decl.c",
    "content": "// standard Linux framebuffer headers\n#include <linux/fb.h>\n\n#include <linux/ioctl.h>\n// specialized eink framebuffer headers\ntypedef unsigned int uint;\n#include \"include/mxcfb-kobo.h\"\n\n#include \"cdecl.h\"\n\ncdecl_struct(mxcfb_rect)\ncdecl_struct(mxcfb_alt_buffer_data)\ncdecl_struct(mxcfb_alt_buffer_data_kobo)\ncdecl_struct(mxcfb_update_data)\ncdecl_struct(mxcfb_update_data_kobo)\n\ncdecl_const(MXCFB_SEND_UPDATE)\n\n"
  },
  {
    "path": "ffi-cdecl/posix_decl.c",
    "content": "#include <sys/mman.h>\n#include <stropts.h>\n#include <unistd.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <sys/wait.h>\n#include <poll.h>\n#include <sys/statvfs.h>\n#include <sys/time.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <errno.h>\n\n#include \"cdecl.h\"\n\ncdecl_type(size_t)\ncdecl_type(off_t)\n\ncdecl_struct(timeval)\ncdecl_struct(statvfs)\n\ncdecl_func(pipe)\ncdecl_func(fork)\ncdecl_func(dup)\ncdecl_func(dup2)\n\ncdecl_const(O_RDWR)\ncdecl_const(O_RDONLY)\ncdecl_const(O_NONBLOCK)\ncdecl_func(open)\ncdecl_func(close)\ncdecl_func(fcntl)\ncdecl_func(execl)\ncdecl_func(execlp)\ncdecl_func(execv)\ncdecl_func(execvp)\ncdecl_func(write)\ncdecl_func(read)\ncdecl_func(kill)\ncdecl_func(waitpid)\n\ncdecl_struct(pollfd)\ncdecl_const(POLLIN)\ncdecl_const(POLLOUT)\ncdecl_const(POLLERR)\ncdecl_const(POLLHUP)\ncdecl_func(poll)\n\ncdecl_const(PROT_READ)\ncdecl_const(PROT_WRITE)\ncdecl_const(MAP_SHARED)\ncdecl_const(MAP_FAILED)\ncdecl_func(mmap)\n\ncdecl_func(ioctl)\ncdecl_func(sleep)\ncdecl_func(usleep)\ncdecl_func(statvfs)\ncdecl_func(gettimeofday)\ncdecl_func(realpath)\n\ncdecl_func(malloc)\ncdecl_func(free)\n\ncdecl_func(strdup)\ncdecl_func(strndup)\n\ncdecl_func(fopen)\ncdecl_func(fclose)\ncdecl_func(printf)\ncdecl_func(sprintf)\ncdecl_func(fprintf)\ncdecl_func(fputc)\n\ncdecl_func(strerror)\ncdecl_const(EINTR)\n"
  },
  {
    "path": "ffi-cdecl/rfbclient_decl.c",
    "content": "#include <rfb/rfbclient.h>\n\n#include \"cdecl.h\"\n\ncdecl_struct(z_stream_s)\ncdecl_struct(rfbClientData)\ncdecl_type(rfbClient)\ncdecl_type(rfbBool)\ncdecl_struct(_rfbClient)\ncdecl_func(rfbGetClient)\ncdecl_func(rfbInitClient)\ncdecl_func(rfbClientLog)\ncdecl_func(SendKeyEvent)\ncdecl_func(SendPointerEvent)\ncdecl_func(SendFramebufferUpdateRequest)\ncdecl_func(SendIncrementalFramebufferUpdateRequest)\ncdecl_func(SendScaleSetting)\ncdecl_func(SetFormatAndEncodings)\ncdecl_func(rfbClientCleanup)\ncdecl_func(HandleRFBServerMessage)\n"
  },
  {
    "path": "keys.lua",
    "content": "--[[\n    This file contains settings related to key codes\n\n    Copyright (C) 2010 Andy M. aka h1uke\th1ukeguy @ gmail.com\n    Copyright (C) 2012 Hans-Werner Hilse <hilse@web.de>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n]]--\n\nKEY_1 = 2\nKEY_2 = 3\nKEY_3 = 4\nKEY_4 = 5\nKEY_5 = 6\nKEY_6 = 7\nKEY_7 = 8\nKEY_8 = 9\nKEY_9 = 10\nKEY_0 = 11\nKEY_Q = 16\nKEY_W = 17\nKEY_E = 18\nKEY_R = 19\nKEY_T = 20\nKEY_Y = 21\nKEY_U = 22\nKEY_I = 23\nKEY_O = 24\nKEY_P = 25\nKEY_A = 30\nKEY_S = 31\nKEY_D = 32\nKEY_F = 33\nKEY_G = 34\nKEY_H = 35\nKEY_J = 36\nKEY_K = 37\nKEY_L = 38\nKEY_DEL = 14\nKEY_Z = 44\nKEY_X = 45\nKEY_C = 46\nKEY_V = 47\nKEY_B = 48\nKEY_N = 49\nKEY_M = 50\nKEY_DOT = 52\nKEY_SLASH = 53\nKEY_ENTER = 28\nKEY_SHIFT = 42\nKEY_ALT = 56\nKEY_SPACE = 57\nKEY_AA = 90\nKEY_SYM = 94\nKEY_VPLUS = 115\nKEY_VMINUS = 114\nKEY_HOME = 98\nKEY_PGBCK = 109\nKEY_PGFWD = 124\nKEY_MENU = 139\nKEY_BACK = 91\nKEY_FW_LEFT = 105\nKEY_FW_RIGHT = 106\nKEY_FW_UP = 122\nKEY_FW_DOWN = 123\nKEY_FW_PRESS = 92\n\n-- constants from <linux/input.h>\nEV_KEY = 1\n\n-- event values\nEVENT_VALUE_KEY_PRESS = 1\nEVENT_VALUE_KEY_REPEAT = 2\nEVENT_VALUE_KEY_RELEASE = 0\n \nfunction set_k3_keycodes()\n\tKEY_AA = 190\n\tKEY_SYM = 126\n\tKEY_HOME = 102\n\tKEY_BACK = 158\n\tKEY_PGFWD = 191\n\tKEY_LPGBCK = 193\n\tKEY_LPGFWD = 104\n\tKEY_VPLUS = 115\n\tKEY_VMINUS = 114\n\tKEY_FW_UP = 103\n\tKEY_FW_DOWN = 108\n\tKEY_FW_PRESS = 194\nend\n\n"
  },
  {
    "path": "kvncviewer.ini",
    "content": "[Actions]\n;; start kvncviewer, connect to 192.168.2.1:1\nV U = !/mnt/us/kvncviewer/kvncviewer.sh 192.168.2.1:1 &\n;; start kvncviewer, connect to somehostviawifi:1\nV W = !/mnt/us/kvncviewer/kvncviewer.sh somehostviawifi:1 &\n;; example with a password:\n;V W = !/mnt/us/kvncviewer/kvncviewer.sh -password this_is_the_password somehostviawifi:1 &\n;; stop kvncviewer\nV Q = !killall kvncviewer\n"
  },
  {
    "path": "kvncviewer.sh",
    "content": "#!/bin/sh\ncd $(dirname \"$0\")\nLD_LIBRARY_PATH=.\nexport LD_LIBRARY_PATH\n\nlipc-set-prop com.lab126.powerd preventScreenSaver 1\n./luajit vncviewer -config config.lua \"$@\"\nlipc-set-prop com.lab126.powerd preventScreenSaver 0\n\n# send menu key twice to refresh display\necho \"send 139\" > /proc/keypad\necho \"send 139\" > /proc/keypad\n"
  },
  {
    "path": "rfbkeys.lua",
    "content": "--[[**********************************************************\nCopyright (c) 1987, 1994  X Consortium\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR\nOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\nExcept as contained in this notice, the name of the X Consortium shall\nnot be used in advertising or otherwise to promote the sale, use or\nother dealings in this Software without prior written authorization\nfrom the X Consortium.\n\n\nCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts\n\n                        All Rights Reserved\n\nPermission to use, copy, modify, and distribute this software and its\ndocumentation for any purpose and without fee is hereby granted,\nprovided that the above copyright notice appear in all copies and that\nboth that copyright notice and this permission notice appear in\nsupporting documentation, and that the name of Digital not be\nused in advertising or publicity pertaining to distribution of the\nsoftware without specific, written prior permission.\n\nDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\nALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL\nDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\nANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,\nWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\nARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\nSOFTWARE.\n\n*****************************************************************]]--\n\nXK_VoidSymbol = 0xFFFFFF\t--[[ void symbol ]]--\n\nXK_BackSpace = 0xFF08\t--[[ back space, back char ]]--\nXK_Tab = 0xFF09\nXK_Linefeed = 0xFF0A\t--[[ Linefeed, LF ]]--\nXK_Clear = 0xFF0B\nXK_Return = 0xFF0D\t--[[ Return, enter ]]--\nXK_Pause = 0xFF13\t--[[ Pause, hold ]]--\nXK_Scroll_Lock = 0xFF14\nXK_Sys_Req = 0xFF15\nXK_Escape = 0xFF1B\nXK_Delete = 0xFFFF\t--[[ Delete, rubout ]]--\n\n\n\n--[[ International & multi-key character composition ]]--\n\nXK_Multi_key = 0xFF20  --[[ Multi-key character compose ]]--\nXK_SingleCandidate = 0xFF3C\nXK_MultipleCandidate = 0xFF3D\nXK_PreviousCandidate = 0xFF3E\n\n--[[ Japanese keyboard support ]]--\n\nXK_Kanji = 0xFF21\t--[[ Kanji, Kanji convert ]]--\nXK_Muhenkan = 0xFF22  --[[ Cancel Conversion ]]--\nXK_Henkan_Mode = 0xFF23  --[[ Start/Stop Conversion ]]--\nXK_Henkan = 0xFF23  --[[ Alias for Henkan_Mode ]]--\nXK_Romaji = 0xFF24  --[[ to Romaji ]]--\nXK_Hiragana = 0xFF25  --[[ to Hiragana ]]--\nXK_Katakana = 0xFF26  --[[ to Katakana ]]--\nXK_Hiragana_Katakana = 0xFF27  --[[ Hiragana/Katakana toggle ]]--\nXK_Zenkaku = 0xFF28  --[[ to Zenkaku ]]--\nXK_Hankaku = 0xFF29  --[[ to Hankaku ]]--\nXK_Zenkaku_Hankaku = 0xFF2A  --[[ Zenkaku/Hankaku toggle ]]--\nXK_Touroku = 0xFF2B  --[[ Add to Dictionary ]]--\nXK_Massyo = 0xFF2C  --[[ Delete from Dictionary ]]--\nXK_Kana_Lock = 0xFF2D  --[[ Kana Lock ]]--\nXK_Kana_Shift = 0xFF2E  --[[ Kana Shift ]]--\nXK_Eisu_Shift = 0xFF2F  --[[ Alphanumeric Shift ]]--\nXK_Eisu_toggle = 0xFF30  --[[ Alphanumeric toggle ]]--\nXK_Zen_Koho = 0xFF3D\t--[[ Multiple/All Candidate(s) ]]--\nXK_Mae_Koho = 0xFF3E\t--[[ Previous Candidate ]]--\n\n--[[ 0xFF31 thru 0xFF3F are under XK_KOREAN = ]]--\n\n--[[ Cursor control & motion ]]--\n\nXK_Home = 0xFF50\nXK_Left = 0xFF51\t--[[ Move left, left arrow ]]--\nXK_Up = 0xFF52\t--[[ Move up, up arrow ]]--\nXK_Right = 0xFF53\t--[[ Move right, right arrow ]]--\nXK_Down = 0xFF54\t--[[ Move down, down arrow ]]--\nXK_Prior = 0xFF55\t--[[ Prior, previous ]]--\nXK_Page_Up = 0xFF55\nXK_Next = 0xFF56\t--[[ Next ]]--\nXK_Page_Down = 0xFF56\nXK_End = 0xFF57\t--[[ EOL ]]--\nXK_Begin = 0xFF58\t--[[ BOL ]]--\n\n\n--[[ Misc Functions ]]--\n\nXK_Select = 0xFF60\t--[[ Select, mark ]]--\nXK_Print = 0xFF61\nXK_Execute = 0xFF62\t--[[ Execute, run, do ]]--\nXK_Insert = 0xFF63\t--[[ Insert, insert here ]]--\nXK_Undo = 0xFF65\t--[[ Undo, oops ]]--\nXK_Redo = 0xFF66\t--[[ redo, again ]]--\nXK_Menu = 0xFF67\nXK_Find = 0xFF68\t--[[ Find, search ]]--\nXK_Cancel = 0xFF69\t--[[ Cancel, stop, abort, exit ]]--\nXK_Help = 0xFF6A\t--[[ Help ]]--\nXK_Break = 0xFF6B\nXK_Mode_switch = 0xFF7E\t--[[ Character set switch ]]--\nXK_script_switch = 0xFF7E  --[[ Alias for mode_switch ]]--\nXK_Num_Lock = 0xFF7F\n\n--[[ Keypad Functions, keypad numbers cleverly chosen to map to ascii ]]--\n\nXK_KP_Space = 0xFF80\t--[[ space ]]--\nXK_KP_Tab = 0xFF89\nXK_KP_Enter = 0xFF8D\t--[[ enter ]]--\nXK_KP_F1 = 0xFF91\t--[[ PF1, KP_A, ... ]]--\nXK_KP_F2 = 0xFF92\nXK_KP_F3 = 0xFF93\nXK_KP_F4 = 0xFF94\nXK_KP_Home = 0xFF95\nXK_KP_Left = 0xFF96\nXK_KP_Up = 0xFF97\nXK_KP_Right = 0xFF98\nXK_KP_Down = 0xFF99\nXK_KP_Prior = 0xFF9A\nXK_KP_Page_Up = 0xFF9A\nXK_KP_Next = 0xFF9B\nXK_KP_Page_Down = 0xFF9B\nXK_KP_End = 0xFF9C\nXK_KP_Begin = 0xFF9D\nXK_KP_Insert = 0xFF9E\nXK_KP_Delete = 0xFF9F\nXK_KP_Equal = 0xFFBD\t--[[ equals ]]--\nXK_KP_Multiply = 0xFFAA\nXK_KP_Add = 0xFFAB\nXK_KP_Separator = 0xFFAC\t--[[ separator, often comma ]]--\nXK_KP_Subtract = 0xFFAD\nXK_KP_Decimal = 0xFFAE\nXK_KP_Divide = 0xFFAF\n\nXK_KP_0 = 0xFFB0\nXK_KP_1 = 0xFFB1\nXK_KP_2 = 0xFFB2\nXK_KP_3 = 0xFFB3\nXK_KP_4 = 0xFFB4\nXK_KP_5 = 0xFFB5\nXK_KP_6 = 0xFFB6\nXK_KP_7 = 0xFFB7\nXK_KP_8 = 0xFFB8\nXK_KP_9 = 0xFFB9\n\n\n\n--[[\n * Auxilliary Functions; note the duplicate definitions for left and right\n * function keys;  Sun keyboards and a few other manufactures have such\n * function key groups on the left and/or right sides of the keyboard.\n * We've not found a keyboard with more than 35 function keys total.\n ]]--\n\nXK_F1 = 0xFFBE\nXK_F2 = 0xFFBF\nXK_F3 = 0xFFC0\nXK_F4 = 0xFFC1\nXK_F5 = 0xFFC2\nXK_F6 = 0xFFC3\nXK_F7 = 0xFFC4\nXK_F8 = 0xFFC5\nXK_F9 = 0xFFC6\nXK_F10 = 0xFFC7\nXK_F11 = 0xFFC8\nXK_L1 = 0xFFC8\nXK_F12 = 0xFFC9\nXK_L2 = 0xFFC9\nXK_F13 = 0xFFCA\nXK_L3 = 0xFFCA\nXK_F14 = 0xFFCB\nXK_L4 = 0xFFCB\nXK_F15 = 0xFFCC\nXK_L5 = 0xFFCC\nXK_F16 = 0xFFCD\nXK_L6 = 0xFFCD\nXK_F17 = 0xFFCE\nXK_L7 = 0xFFCE\nXK_F18 = 0xFFCF\nXK_L8 = 0xFFCF\nXK_F19 = 0xFFD0\nXK_L9 = 0xFFD0\nXK_F20 = 0xFFD1\nXK_L10 = 0xFFD1\nXK_F21 = 0xFFD2\nXK_R1 = 0xFFD2\nXK_F22 = 0xFFD3\nXK_R2 = 0xFFD3\nXK_F23 = 0xFFD4\nXK_R3 = 0xFFD4\nXK_F24 = 0xFFD5\nXK_R4 = 0xFFD5\nXK_F25 = 0xFFD6\nXK_R5 = 0xFFD6\nXK_F26 = 0xFFD7\nXK_R6 = 0xFFD7\nXK_F27 = 0xFFD8\nXK_R7 = 0xFFD8\nXK_F28 = 0xFFD9\nXK_R8 = 0xFFD9\nXK_F29 = 0xFFDA\nXK_R9 = 0xFFDA\nXK_F30 = 0xFFDB\nXK_R10 = 0xFFDB\nXK_F31 = 0xFFDC\nXK_R11 = 0xFFDC\nXK_F32 = 0xFFDD\nXK_R12 = 0xFFDD\nXK_F33 = 0xFFDE\nXK_R13 = 0xFFDE\nXK_F34 = 0xFFDF\nXK_R14 = 0xFFDF\nXK_F35 = 0xFFE0\nXK_R15 = 0xFFE0\n\n--[[ Modifiers ]]--\n\nXK_Shift_L = 0xFFE1\t--[[ Left shift ]]--\nXK_Shift_R = 0xFFE2\t--[[ Right shift ]]--\nXK_Control_L = 0xFFE3\t--[[ Left control ]]--\nXK_Control_R = 0xFFE4\t--[[ Right control ]]--\nXK_Caps_Lock = 0xFFE5\t--[[ Caps lock ]]--\nXK_Shift_Lock = 0xFFE6\t--[[ Shift lock ]]--\n\nXK_Meta_L = 0xFFE7\t--[[ Left meta ]]--\nXK_Meta_R = 0xFFE8\t--[[ Right meta ]]--\nXK_Alt_L = 0xFFE9\t--[[ Left alt ]]--\nXK_Alt_R = 0xFFEA\t--[[ Right alt ]]--\nXK_Super_L = 0xFFEB\t--[[ Left super ]]--\nXK_Super_R = 0xFFEC\t--[[ Right super ]]--\nXK_Hyper_L = 0xFFED\t--[[ Left hyper ]]--\nXK_Hyper_R = 0xFFEE\t--[[ Right hyper ]]--\n\n--[[\n * ISO 9995 Function and Modifier Keys\n * Byte 3 = 0xFE\n ]]--\n\nXK_ISO_Lock = 0xFE01\nXK_ISO_Level2_Latch = 0xFE02\nXK_ISO_Level3_Shift = 0xFE03\nXK_ISO_Level3_Latch = 0xFE04\nXK_ISO_Level3_Lock = 0xFE05\nXK_ISO_Group_Shift = 0xFF7E\t--[[ Alias for mode_switch ]]--\nXK_ISO_Group_Latch = 0xFE06\nXK_ISO_Group_Lock = 0xFE07\nXK_ISO_Next_Group = 0xFE08\nXK_ISO_Next_Group_Lock = 0xFE09\nXK_ISO_Prev_Group = 0xFE0A\nXK_ISO_Prev_Group_Lock = 0xFE0B\nXK_ISO_First_Group = 0xFE0C\nXK_ISO_First_Group_Lock = 0xFE0D\nXK_ISO_Last_Group = 0xFE0E\nXK_ISO_Last_Group_Lock = 0xFE0F\n\nXK_ISO_Left_Tab = 0xFE20\nXK_ISO_Move_Line_Up = 0xFE21\nXK_ISO_Move_Line_Down = 0xFE22\nXK_ISO_Partial_Line_Up = 0xFE23\nXK_ISO_Partial_Line_Down = 0xFE24\nXK_ISO_Partial_Space_Left = 0xFE25\nXK_ISO_Partial_Space_Right = 0xFE26\nXK_ISO_Set_Margin_Left = 0xFE27\nXK_ISO_Set_Margin_Right = 0xFE28\nXK_ISO_Release_Margin_Left = 0xFE29\nXK_ISO_Release_Margin_Right = 0xFE2A\nXK_ISO_Release_Both_Margins = 0xFE2B\nXK_ISO_Fast_Cursor_Left = 0xFE2C\nXK_ISO_Fast_Cursor_Right = 0xFE2D\nXK_ISO_Fast_Cursor_Up = 0xFE2E\nXK_ISO_Fast_Cursor_Down = 0xFE2F\nXK_ISO_Continuous_Underline = 0xFE30\nXK_ISO_Discontinuous_Underline = 0xFE31\nXK_ISO_Emphasize = 0xFE32\nXK_ISO_Center_Object = 0xFE33\nXK_ISO_Enter = 0xFE34\n\nXK_dead_grave = 0xFE50\nXK_dead_acute = 0xFE51\nXK_dead_circumflex = 0xFE52\nXK_dead_tilde = 0xFE53\nXK_dead_macron = 0xFE54\nXK_dead_breve = 0xFE55\nXK_dead_abovedot = 0xFE56\nXK_dead_diaeresis = 0xFE57\nXK_dead_abovering = 0xFE58\nXK_dead_doubleacute = 0xFE59\nXK_dead_caron = 0xFE5A\nXK_dead_cedilla = 0xFE5B\nXK_dead_ogonek = 0xFE5C\nXK_dead_iota = 0xFE5D\nXK_dead_voiced_sound = 0xFE5E\nXK_dead_semivoiced_sound = 0xFE5F\nXK_dead_belowdot = 0xFE60\n\nXK_First_Virtual_Screen = 0xFED0\nXK_Prev_Virtual_Screen = 0xFED1\nXK_Next_Virtual_Screen = 0xFED2\nXK_Last_Virtual_Screen = 0xFED4\nXK_Terminate_Server = 0xFED5\n\nXK_AccessX_Enable = 0xFE70\nXK_AccessX_Feedback_Enable = 0xFE71\nXK_RepeatKeys_Enable = 0xFE72\nXK_SlowKeys_Enable = 0xFE73\nXK_BounceKeys_Enable = 0xFE74\nXK_StickyKeys_Enable = 0xFE75\nXK_MouseKeys_Enable = 0xFE76\nXK_MouseKeys_Accel_Enable = 0xFE77\nXK_Overlay1_Enable = 0xFE78\nXK_Overlay2_Enable = 0xFE79\nXK_AudibleBell_Enable = 0xFE7A\n\nXK_Pointer_Left = 0xFEE0\nXK_Pointer_Right = 0xFEE1\nXK_Pointer_Up = 0xFEE2\nXK_Pointer_Down = 0xFEE3\nXK_Pointer_UpLeft = 0xFEE4\nXK_Pointer_UpRight = 0xFEE5\nXK_Pointer_DownLeft = 0xFEE6\nXK_Pointer_DownRight = 0xFEE7\nXK_Pointer_Button_Dflt = 0xFEE8\nXK_Pointer_Button1 = 0xFEE9\nXK_Pointer_Button2 = 0xFEEA\nXK_Pointer_Button3 = 0xFEEB\nXK_Pointer_Button4 = 0xFEEC\nXK_Pointer_Button5 = 0xFEED\nXK_Pointer_DblClick_Dflt = 0xFEEE\nXK_Pointer_DblClick1 = 0xFEEF\nXK_Pointer_DblClick2 = 0xFEF0\nXK_Pointer_DblClick3 = 0xFEF1\nXK_Pointer_DblClick4 = 0xFEF2\nXK_Pointer_DblClick5 = 0xFEF3\nXK_Pointer_Drag_Dflt = 0xFEF4\nXK_Pointer_Drag1 = 0xFEF5\nXK_Pointer_Drag2 = 0xFEF6\nXK_Pointer_Drag3 = 0xFEF7\nXK_Pointer_Drag4 = 0xFEF8\nXK_Pointer_Drag5 = 0xFEFD\n\nXK_Pointer_EnableKeys = 0xFEF9\nXK_Pointer_Accelerate = 0xFEFA\nXK_Pointer_DfltBtnNext = 0xFEFB\nXK_Pointer_DfltBtnPrev = 0xFEFC\n\n--[[\n * 3270 Terminal Keys\n * Byte 3 = 0xFD\n ]]--\n\nXK_3270_Duplicate = 0xFD01\nXK_3270_FieldMark = 0xFD02\nXK_3270_Right2 = 0xFD03\nXK_3270_Left2 = 0xFD04\nXK_3270_BackTab = 0xFD05\nXK_3270_EraseEOF = 0xFD06\nXK_3270_EraseInput = 0xFD07\nXK_3270_Reset = 0xFD08\nXK_3270_Quit = 0xFD09\nXK_3270_PA1 = 0xFD0A\nXK_3270_PA2 = 0xFD0B\nXK_3270_PA3 = 0xFD0C\nXK_3270_Test = 0xFD0D\nXK_3270_Attn = 0xFD0E\nXK_3270_CursorBlink = 0xFD0F\nXK_3270_AltCursor = 0xFD10\nXK_3270_KeyClick = 0xFD11\nXK_3270_Jump = 0xFD12\nXK_3270_Ident = 0xFD13\nXK_3270_Rule = 0xFD14\nXK_3270_Copy = 0xFD15\nXK_3270_Play = 0xFD16\nXK_3270_Setup = 0xFD17\nXK_3270_Record = 0xFD18\nXK_3270_ChangeScreen = 0xFD19\nXK_3270_DeleteWord = 0xFD1A\nXK_3270_ExSelect = 0xFD1B\nXK_3270_CursorSelect = 0xFD1C\nXK_3270_PrintScreen = 0xFD1D\nXK_3270_Enter = 0xFD1E\n\n--[[\n *  Latin 1\n *  Byte 3 = 0\n ]]--\nXK_space = 0x020\nXK_exclam = 0x021\nXK_quotedbl = 0x022\nXK_numbersign = 0x023\nXK_dollar = 0x024\nXK_percent = 0x025\nXK_ampersand = 0x026\nXK_apostrophe = 0x027\nXK_quoteright = 0x027\t--[[ deprecated ]]--\nXK_parenleft = 0x028\nXK_parenright = 0x029\nXK_asterisk = 0x02a\nXK_plus = 0x02b\nXK_comma = 0x02c\nXK_minus = 0x02d\nXK_period = 0x02e\nXK_slash = 0x02f\nXK_0 = 0x030\nXK_1 = 0x031\nXK_2 = 0x032\nXK_3 = 0x033\nXK_4 = 0x034\nXK_5 = 0x035\nXK_6 = 0x036\nXK_7 = 0x037\nXK_8 = 0x038\nXK_9 = 0x039\nXK_colon = 0x03a\nXK_semicolon = 0x03b\nXK_less = 0x03c\nXK_equal = 0x03d\nXK_greater = 0x03e\nXK_question = 0x03f\nXK_at = 0x040\nXK_A = 0x041\nXK_B = 0x042\nXK_C = 0x043\nXK_D = 0x044\nXK_E = 0x045\nXK_F = 0x046\nXK_G = 0x047\nXK_H = 0x048\nXK_I = 0x049\nXK_J = 0x04a\nXK_K = 0x04b\nXK_L = 0x04c\nXK_M = 0x04d\nXK_N = 0x04e\nXK_O = 0x04f\nXK_P = 0x050\nXK_Q = 0x051\nXK_R = 0x052\nXK_S = 0x053\nXK_T = 0x054\nXK_U = 0x055\nXK_V = 0x056\nXK_W = 0x057\nXK_X = 0x058\nXK_Y = 0x059\nXK_Z = 0x05a\nXK_bracketleft = 0x05b\nXK_backslash = 0x05c\nXK_bracketright = 0x05d\nXK_asciicircum = 0x05e\nXK_underscore = 0x05f\nXK_grave = 0x060\nXK_quoteleft = 0x060\t--[[ deprecated ]]--\nXK_a = 0x061\nXK_b = 0x062\nXK_c = 0x063\nXK_d = 0x064\nXK_e = 0x065\nXK_f = 0x066\nXK_g = 0x067\nXK_h = 0x068\nXK_i = 0x069\nXK_j = 0x06a\nXK_k = 0x06b\nXK_l = 0x06c\nXK_m = 0x06d\nXK_n = 0x06e\nXK_o = 0x06f\nXK_p = 0x070\nXK_q = 0x071\nXK_r = 0x072\nXK_s = 0x073\nXK_t = 0x074\nXK_u = 0x075\nXK_v = 0x076\nXK_w = 0x077\nXK_x = 0x078\nXK_y = 0x079\nXK_z = 0x07a\nXK_braceleft = 0x07b\nXK_bar = 0x07c\nXK_braceright = 0x07d\nXK_asciitilde = 0x07e\n\nXK_nobreakspace = 0x0a0\nXK_exclamdown = 0x0a1\nXK_cent = 0x0a2\nXK_sterling = 0x0a3\nXK_currency = 0x0a4\nXK_yen = 0x0a5\nXK_brokenbar = 0x0a6\nXK_section = 0x0a7\nXK_diaeresis = 0x0a8\nXK_copyright = 0x0a9\nXK_ordfeminine = 0x0aa\nXK_guillemotleft = 0x0ab\t--[[ left angle quotation mark ]]--\nXK_notsign = 0x0ac\nXK_hyphen = 0x0ad\nXK_registered = 0x0ae\nXK_macron = 0x0af\nXK_degree = 0x0b0\nXK_plusminus = 0x0b1\nXK_twosuperior = 0x0b2\nXK_threesuperior = 0x0b3\nXK_acute = 0x0b4\nXK_mu = 0x0b5\nXK_paragraph = 0x0b6\nXK_periodcentered = 0x0b7\nXK_cedilla = 0x0b8\nXK_onesuperior = 0x0b9\nXK_masculine = 0x0ba\nXK_guillemotright = 0x0bb\t--[[ right angle quotation mark ]]--\nXK_onequarter = 0x0bc\nXK_onehalf = 0x0bd\nXK_threequarters = 0x0be\nXK_questiondown = 0x0bf\nXK_Agrave = 0x0c0\nXK_Aacute = 0x0c1\nXK_Acircumflex = 0x0c2\nXK_Atilde = 0x0c3\nXK_Adiaeresis = 0x0c4\nXK_Aring = 0x0c5\nXK_AE = 0x0c6\nXK_Ccedilla = 0x0c7\nXK_Egrave = 0x0c8\nXK_Eacute = 0x0c9\nXK_Ecircumflex = 0x0ca\nXK_Ediaeresis = 0x0cb\nXK_Igrave = 0x0cc\nXK_Iacute = 0x0cd\nXK_Icircumflex = 0x0ce\nXK_Idiaeresis = 0x0cf\nXK_ETH = 0x0d0\nXK_Eth = 0x0d0\t--[[ deprecated ]]--\nXK_Ntilde = 0x0d1\nXK_Ograve = 0x0d2\nXK_Oacute = 0x0d3\nXK_Ocircumflex = 0x0d4\nXK_Otilde = 0x0d5\nXK_Odiaeresis = 0x0d6\nXK_multiply = 0x0d7\nXK_Ooblique = 0x0d8\nXK_Ugrave = 0x0d9\nXK_Uacute = 0x0da\nXK_Ucircumflex = 0x0db\nXK_Udiaeresis = 0x0dc\nXK_Yacute = 0x0dd\nXK_THORN = 0x0de\nXK_Thorn = 0x0de\t--[[ deprecated ]]--\nXK_ssharp = 0x0df\nXK_agrave = 0x0e0\nXK_aacute = 0x0e1\nXK_acircumflex = 0x0e2\nXK_atilde = 0x0e3\nXK_adiaeresis = 0x0e4\nXK_aring = 0x0e5\nXK_ae = 0x0e6\nXK_ccedilla = 0x0e7\nXK_egrave = 0x0e8\nXK_eacute = 0x0e9\nXK_ecircumflex = 0x0ea\nXK_ediaeresis = 0x0eb\nXK_igrave = 0x0ec\nXK_iacute = 0x0ed\nXK_icircumflex = 0x0ee\nXK_idiaeresis = 0x0ef\nXK_eth = 0x0f0\nXK_ntilde = 0x0f1\nXK_ograve = 0x0f2\nXK_oacute = 0x0f3\nXK_ocircumflex = 0x0f4\nXK_otilde = 0x0f5\nXK_odiaeresis = 0x0f6\nXK_division = 0x0f7\nXK_oslash = 0x0f8\nXK_ugrave = 0x0f9\nXK_uacute = 0x0fa\nXK_ucircumflex = 0x0fb\nXK_udiaeresis = 0x0fc\nXK_yacute = 0x0fd\nXK_thorn = 0x0fe\nXK_ydiaeresis = 0x0ff\n\n--[[\n *   Latin 2\n *   Byte 3 = 1\n ]]--\n\nXK_Aogonek = 0x1a1\nXK_breve = 0x1a2\nXK_Lstroke = 0x1a3\nXK_Lcaron = 0x1a5\nXK_Sacute = 0x1a6\nXK_Scaron = 0x1a9\nXK_Scedilla = 0x1aa\nXK_Tcaron = 0x1ab\nXK_Zacute = 0x1ac\nXK_Zcaron = 0x1ae\nXK_Zabovedot = 0x1af\nXK_aogonek = 0x1b1\nXK_ogonek = 0x1b2\nXK_lstroke = 0x1b3\nXK_lcaron = 0x1b5\nXK_sacute = 0x1b6\nXK_caron = 0x1b7\nXK_scaron = 0x1b9\nXK_scedilla = 0x1ba\nXK_tcaron = 0x1bb\nXK_zacute = 0x1bc\nXK_doubleacute = 0x1bd\nXK_zcaron = 0x1be\nXK_zabovedot = 0x1bf\nXK_Racute = 0x1c0\nXK_Abreve = 0x1c3\nXK_Lacute = 0x1c5\nXK_Cacute = 0x1c6\nXK_Ccaron = 0x1c8\nXK_Eogonek = 0x1ca\nXK_Ecaron = 0x1cc\nXK_Dcaron = 0x1cf\nXK_Dstroke = 0x1d0\nXK_Nacute = 0x1d1\nXK_Ncaron = 0x1d2\nXK_Odoubleacute = 0x1d5\nXK_Rcaron = 0x1d8\nXK_Uring = 0x1d9\nXK_Udoubleacute = 0x1db\nXK_Tcedilla = 0x1de\nXK_racute = 0x1e0\nXK_abreve = 0x1e3\nXK_lacute = 0x1e5\nXK_cacute = 0x1e6\nXK_ccaron = 0x1e8\nXK_eogonek = 0x1ea\nXK_ecaron = 0x1ec\nXK_dcaron = 0x1ef\nXK_dstroke = 0x1f0\nXK_nacute = 0x1f1\nXK_ncaron = 0x1f2\nXK_odoubleacute = 0x1f5\nXK_udoubleacute = 0x1fb\nXK_rcaron = 0x1f8\nXK_uring = 0x1f9\nXK_tcedilla = 0x1fe\nXK_abovedot = 0x1ff\n\n--[[\n *   Latin 3\n *   Byte 3 = 2\n ]]--\n\nXK_Hstroke = 0x2a1\nXK_Hcircumflex = 0x2a6\nXK_Iabovedot = 0x2a9\nXK_Gbreve = 0x2ab\nXK_Jcircumflex = 0x2ac\nXK_hstroke = 0x2b1\nXK_hcircumflex = 0x2b6\nXK_idotless = 0x2b9\nXK_gbreve = 0x2bb\nXK_jcircumflex = 0x2bc\nXK_Cabovedot = 0x2c5\nXK_Ccircumflex = 0x2c6\nXK_Gabovedot = 0x2d5\nXK_Gcircumflex = 0x2d8\nXK_Ubreve = 0x2dd\nXK_Scircumflex = 0x2de\nXK_cabovedot = 0x2e5\nXK_ccircumflex = 0x2e6\nXK_gabovedot = 0x2f5\nXK_gcircumflex = 0x2f8\nXK_ubreve = 0x2fd\nXK_scircumflex = 0x2fe\n\n\n--[[\n *   Latin 4\n *   Byte 3 = 3\n ]]--\n\nXK_kra = 0x3a2\nXK_kappa = 0x3a2\t--[[ deprecated ]]--\nXK_Rcedilla = 0x3a3\nXK_Itilde = 0x3a5\nXK_Lcedilla = 0x3a6\nXK_Emacron = 0x3aa\nXK_Gcedilla = 0x3ab\nXK_Tslash = 0x3ac\nXK_rcedilla = 0x3b3\nXK_itilde = 0x3b5\nXK_lcedilla = 0x3b6\nXK_emacron = 0x3ba\nXK_gcedilla = 0x3bb\nXK_tslash = 0x3bc\nXK_ENG = 0x3bd\nXK_eng = 0x3bf\nXK_Amacron = 0x3c0\nXK_Iogonek = 0x3c7\nXK_Eabovedot = 0x3cc\nXK_Imacron = 0x3cf\nXK_Ncedilla = 0x3d1\nXK_Omacron = 0x3d2\nXK_Kcedilla = 0x3d3\nXK_Uogonek = 0x3d9\nXK_Utilde = 0x3dd\nXK_Umacron = 0x3de\nXK_amacron = 0x3e0\nXK_iogonek = 0x3e7\nXK_eabovedot = 0x3ec\nXK_imacron = 0x3ef\nXK_ncedilla = 0x3f1\nXK_omacron = 0x3f2\nXK_kcedilla = 0x3f3\nXK_uogonek = 0x3f9\nXK_utilde = 0x3fd\nXK_umacron = 0x3fe\n\n--[[\n * Katakana\n * Byte 3 = 4\n ]]--\n\nXK_overline = 0x47e\nXK_kana_fullstop = 0x4a1\nXK_kana_openingbracket = 0x4a2\nXK_kana_closingbracket = 0x4a3\nXK_kana_comma = 0x4a4\nXK_kana_conjunctive = 0x4a5\nXK_kana_middledot = 0x4a5  --[[ deprecated ]]--\nXK_kana_WO = 0x4a6\nXK_kana_a = 0x4a7\nXK_kana_i = 0x4a8\nXK_kana_u = 0x4a9\nXK_kana_e = 0x4aa\nXK_kana_o = 0x4ab\nXK_kana_ya = 0x4ac\nXK_kana_yu = 0x4ad\nXK_kana_yo = 0x4ae\nXK_kana_tsu = 0x4af\nXK_kana_tu = 0x4af  --[[ deprecated ]]--\nXK_prolongedsound = 0x4b0\nXK_kana_A = 0x4b1\nXK_kana_I = 0x4b2\nXK_kana_U = 0x4b3\nXK_kana_E = 0x4b4\nXK_kana_O = 0x4b5\nXK_kana_KA = 0x4b6\nXK_kana_KI = 0x4b7\nXK_kana_KU = 0x4b8\nXK_kana_KE = 0x4b9\nXK_kana_KO = 0x4ba\nXK_kana_SA = 0x4bb\nXK_kana_SHI = 0x4bc\nXK_kana_SU = 0x4bd\nXK_kana_SE = 0x4be\nXK_kana_SO = 0x4bf\nXK_kana_TA = 0x4c0\nXK_kana_CHI = 0x4c1\nXK_kana_TI = 0x4c1  --[[ deprecated ]]--\nXK_kana_TSU = 0x4c2\nXK_kana_TU = 0x4c2  --[[ deprecated ]]--\nXK_kana_TE = 0x4c3\nXK_kana_TO = 0x4c4\nXK_kana_NA = 0x4c5\nXK_kana_NI = 0x4c6\nXK_kana_NU = 0x4c7\nXK_kana_NE = 0x4c8\nXK_kana_NO = 0x4c9\nXK_kana_HA = 0x4ca\nXK_kana_HI = 0x4cb\nXK_kana_FU = 0x4cc\nXK_kana_HU = 0x4cc  --[[ deprecated ]]--\nXK_kana_HE = 0x4cd\nXK_kana_HO = 0x4ce\nXK_kana_MA = 0x4cf\nXK_kana_MI = 0x4d0\nXK_kana_MU = 0x4d1\nXK_kana_ME = 0x4d2\nXK_kana_MO = 0x4d3\nXK_kana_YA = 0x4d4\nXK_kana_YU = 0x4d5\nXK_kana_YO = 0x4d6\nXK_kana_RA = 0x4d7\nXK_kana_RI = 0x4d8\nXK_kana_RU = 0x4d9\nXK_kana_RE = 0x4da\nXK_kana_RO = 0x4db\nXK_kana_WA = 0x4dc\nXK_kana_N = 0x4dd\nXK_voicedsound = 0x4de\nXK_semivoicedsound = 0x4df\nXK_kana_switch = 0xFF7E  --[[ Alias for mode_switch ]]--\n\n--[[\n *  Arabic\n *  Byte 3 = 5\n ]]--\n\nXK_Arabic_comma = 0x5ac\nXK_Arabic_semicolon = 0x5bb\nXK_Arabic_question_mark = 0x5bf\nXK_Arabic_hamza = 0x5c1\nXK_Arabic_maddaonalef = 0x5c2\nXK_Arabic_hamzaonalef = 0x5c3\nXK_Arabic_hamzaonwaw = 0x5c4\nXK_Arabic_hamzaunderalef = 0x5c5\nXK_Arabic_hamzaonyeh = 0x5c6\nXK_Arabic_alef = 0x5c7\nXK_Arabic_beh = 0x5c8\nXK_Arabic_tehmarbuta = 0x5c9\nXK_Arabic_teh = 0x5ca\nXK_Arabic_theh = 0x5cb\nXK_Arabic_jeem = 0x5cc\nXK_Arabic_hah = 0x5cd\nXK_Arabic_khah = 0x5ce\nXK_Arabic_dal = 0x5cf\nXK_Arabic_thal = 0x5d0\nXK_Arabic_ra = 0x5d1\nXK_Arabic_zain = 0x5d2\nXK_Arabic_seen = 0x5d3\nXK_Arabic_sheen = 0x5d4\nXK_Arabic_sad = 0x5d5\nXK_Arabic_dad = 0x5d6\nXK_Arabic_tah = 0x5d7\nXK_Arabic_zah = 0x5d8\nXK_Arabic_ain = 0x5d9\nXK_Arabic_ghain = 0x5da\nXK_Arabic_tatweel = 0x5e0\nXK_Arabic_feh = 0x5e1\nXK_Arabic_qaf = 0x5e2\nXK_Arabic_kaf = 0x5e3\nXK_Arabic_lam = 0x5e4\nXK_Arabic_meem = 0x5e5\nXK_Arabic_noon = 0x5e6\nXK_Arabic_ha = 0x5e7\nXK_Arabic_heh = 0x5e7  --[[ deprecated ]]--\nXK_Arabic_waw = 0x5e8\nXK_Arabic_alefmaksura = 0x5e9\nXK_Arabic_yeh = 0x5ea\nXK_Arabic_fathatan = 0x5eb\nXK_Arabic_dammatan = 0x5ec\nXK_Arabic_kasratan = 0x5ed\nXK_Arabic_fatha = 0x5ee\nXK_Arabic_damma = 0x5ef\nXK_Arabic_kasra = 0x5f0\nXK_Arabic_shadda = 0x5f1\nXK_Arabic_sukun = 0x5f2\nXK_Arabic_switch = 0xFF7E  --[[ Alias for mode_switch ]]--\n\n--[[\n * Cyrillic\n * Byte 3 = 6\n ]]--\nXK_Serbian_dje = 0x6a1\nXK_Macedonia_gje = 0x6a2\nXK_Cyrillic_io = 0x6a3\nXK_Ukrainian_ie = 0x6a4\nXK_Ukranian_je = 0x6a4  --[[ deprecated ]]--\nXK_Macedonia_dse = 0x6a5\nXK_Ukrainian_i = 0x6a6\nXK_Ukranian_i = 0x6a6  --[[ deprecated ]]--\nXK_Ukrainian_yi = 0x6a7\nXK_Ukranian_yi = 0x6a7  --[[ deprecated ]]--\nXK_Cyrillic_je = 0x6a8\nXK_Serbian_je = 0x6a8  --[[ deprecated ]]--\nXK_Cyrillic_lje = 0x6a9\nXK_Serbian_lje = 0x6a9  --[[ deprecated ]]--\nXK_Cyrillic_nje = 0x6aa\nXK_Serbian_nje = 0x6aa  --[[ deprecated ]]--\nXK_Serbian_tshe = 0x6ab\nXK_Macedonia_kje = 0x6ac\nXK_Byelorussian_shortu = 0x6ae\nXK_Cyrillic_dzhe = 0x6af\nXK_Serbian_dze = 0x6af  --[[ deprecated ]]--\nXK_numerosign = 0x6b0\nXK_Serbian_DJE = 0x6b1\nXK_Macedonia_GJE = 0x6b2\nXK_Cyrillic_IO = 0x6b3\nXK_Ukrainian_IE = 0x6b4\nXK_Ukranian_JE = 0x6b4  --[[ deprecated ]]--\nXK_Macedonia_DSE = 0x6b5\nXK_Ukrainian_I = 0x6b6\nXK_Ukranian_I = 0x6b6  --[[ deprecated ]]--\nXK_Ukrainian_YI = 0x6b7\nXK_Ukranian_YI = 0x6b7  --[[ deprecated ]]--\nXK_Cyrillic_JE = 0x6b8\nXK_Serbian_JE = 0x6b8  --[[ deprecated ]]--\nXK_Cyrillic_LJE = 0x6b9\nXK_Serbian_LJE = 0x6b9  --[[ deprecated ]]--\nXK_Cyrillic_NJE = 0x6ba\nXK_Serbian_NJE = 0x6ba  --[[ deprecated ]]--\nXK_Serbian_TSHE = 0x6bb\nXK_Macedonia_KJE = 0x6bc\nXK_Byelorussian_SHORTU = 0x6be\nXK_Cyrillic_DZHE = 0x6bf\nXK_Serbian_DZE = 0x6bf  --[[ deprecated ]]--\nXK_Cyrillic_yu = 0x6c0\nXK_Cyrillic_a = 0x6c1\nXK_Cyrillic_be = 0x6c2\nXK_Cyrillic_tse = 0x6c3\nXK_Cyrillic_de = 0x6c4\nXK_Cyrillic_ie = 0x6c5\nXK_Cyrillic_ef = 0x6c6\nXK_Cyrillic_ghe = 0x6c7\nXK_Cyrillic_ha = 0x6c8\nXK_Cyrillic_i = 0x6c9\nXK_Cyrillic_shorti = 0x6ca\nXK_Cyrillic_ka = 0x6cb\nXK_Cyrillic_el = 0x6cc\nXK_Cyrillic_em = 0x6cd\nXK_Cyrillic_en = 0x6ce\nXK_Cyrillic_o = 0x6cf\nXK_Cyrillic_pe = 0x6d0\nXK_Cyrillic_ya = 0x6d1\nXK_Cyrillic_er = 0x6d2\nXK_Cyrillic_es = 0x6d3\nXK_Cyrillic_te = 0x6d4\nXK_Cyrillic_u = 0x6d5\nXK_Cyrillic_zhe = 0x6d6\nXK_Cyrillic_ve = 0x6d7\nXK_Cyrillic_softsign = 0x6d8\nXK_Cyrillic_yeru = 0x6d9\nXK_Cyrillic_ze = 0x6da\nXK_Cyrillic_sha = 0x6db\nXK_Cyrillic_e = 0x6dc\nXK_Cyrillic_shcha = 0x6dd\nXK_Cyrillic_che = 0x6de\nXK_Cyrillic_hardsign = 0x6df\nXK_Cyrillic_YU = 0x6e0\nXK_Cyrillic_A = 0x6e1\nXK_Cyrillic_BE = 0x6e2\nXK_Cyrillic_TSE = 0x6e3\nXK_Cyrillic_DE = 0x6e4\nXK_Cyrillic_IE = 0x6e5\nXK_Cyrillic_EF = 0x6e6\nXK_Cyrillic_GHE = 0x6e7\nXK_Cyrillic_HA = 0x6e8\nXK_Cyrillic_I = 0x6e9\nXK_Cyrillic_SHORTI = 0x6ea\nXK_Cyrillic_KA = 0x6eb\nXK_Cyrillic_EL = 0x6ec\nXK_Cyrillic_EM = 0x6ed\nXK_Cyrillic_EN = 0x6ee\nXK_Cyrillic_O = 0x6ef\nXK_Cyrillic_PE = 0x6f0\nXK_Cyrillic_YA = 0x6f1\nXK_Cyrillic_ER = 0x6f2\nXK_Cyrillic_ES = 0x6f3\nXK_Cyrillic_TE = 0x6f4\nXK_Cyrillic_U = 0x6f5\nXK_Cyrillic_ZHE = 0x6f6\nXK_Cyrillic_VE = 0x6f7\nXK_Cyrillic_SOFTSIGN = 0x6f8\nXK_Cyrillic_YERU = 0x6f9\nXK_Cyrillic_ZE = 0x6fa\nXK_Cyrillic_SHA = 0x6fb\nXK_Cyrillic_E = 0x6fc\nXK_Cyrillic_SHCHA = 0x6fd\nXK_Cyrillic_CHE = 0x6fe\nXK_Cyrillic_HARDSIGN = 0x6ff\n\n--[[\n * Greek\n * Byte 3 = 7\n ]]--\n\nXK_Greek_ALPHAaccent = 0x7a1\nXK_Greek_EPSILONaccent = 0x7a2\nXK_Greek_ETAaccent = 0x7a3\nXK_Greek_IOTAaccent = 0x7a4\nXK_Greek_IOTAdieresis = 0x7a5\nXK_Greek_OMICRONaccent = 0x7a7\nXK_Greek_UPSILONaccent = 0x7a8\nXK_Greek_UPSILONdieresis = 0x7a9\nXK_Greek_OMEGAaccent = 0x7ab\nXK_Greek_accentdieresis = 0x7ae\nXK_Greek_horizbar = 0x7af\nXK_Greek_alphaaccent = 0x7b1\nXK_Greek_epsilonaccent = 0x7b2\nXK_Greek_etaaccent = 0x7b3\nXK_Greek_iotaaccent = 0x7b4\nXK_Greek_iotadieresis = 0x7b5\nXK_Greek_iotaaccentdieresis = 0x7b6\nXK_Greek_omicronaccent = 0x7b7\nXK_Greek_upsilonaccent = 0x7b8\nXK_Greek_upsilondieresis = 0x7b9\nXK_Greek_upsilonaccentdieresis = 0x7ba\nXK_Greek_omegaaccent = 0x7bb\nXK_Greek_ALPHA = 0x7c1\nXK_Greek_BETA = 0x7c2\nXK_Greek_GAMMA = 0x7c3\nXK_Greek_DELTA = 0x7c4\nXK_Greek_EPSILON = 0x7c5\nXK_Greek_ZETA = 0x7c6\nXK_Greek_ETA = 0x7c7\nXK_Greek_THETA = 0x7c8\nXK_Greek_IOTA = 0x7c9\nXK_Greek_KAPPA = 0x7ca\nXK_Greek_LAMDA = 0x7cb\nXK_Greek_LAMBDA = 0x7cb\nXK_Greek_MU = 0x7cc\nXK_Greek_NU = 0x7cd\nXK_Greek_XI = 0x7ce\nXK_Greek_OMICRON = 0x7cf\nXK_Greek_PI = 0x7d0\nXK_Greek_RHO = 0x7d1\nXK_Greek_SIGMA = 0x7d2\nXK_Greek_TAU = 0x7d4\nXK_Greek_UPSILON = 0x7d5\nXK_Greek_PHI = 0x7d6\nXK_Greek_CHI = 0x7d7\nXK_Greek_PSI = 0x7d8\nXK_Greek_OMEGA = 0x7d9\nXK_Greek_alpha = 0x7e1\nXK_Greek_beta = 0x7e2\nXK_Greek_gamma = 0x7e3\nXK_Greek_delta = 0x7e4\nXK_Greek_epsilon = 0x7e5\nXK_Greek_zeta = 0x7e6\nXK_Greek_eta = 0x7e7\nXK_Greek_theta = 0x7e8\nXK_Greek_iota = 0x7e9\nXK_Greek_kappa = 0x7ea\nXK_Greek_lamda = 0x7eb\nXK_Greek_lambda = 0x7eb\nXK_Greek_mu = 0x7ec\nXK_Greek_nu = 0x7ed\nXK_Greek_xi = 0x7ee\nXK_Greek_omicron = 0x7ef\nXK_Greek_pi = 0x7f0\nXK_Greek_rho = 0x7f1\nXK_Greek_sigma = 0x7f2\nXK_Greek_finalsmallsigma = 0x7f3\nXK_Greek_tau = 0x7f4\nXK_Greek_upsilon = 0x7f5\nXK_Greek_phi = 0x7f6\nXK_Greek_chi = 0x7f7\nXK_Greek_psi = 0x7f8\nXK_Greek_omega = 0x7f9\nXK_Greek_switch = 0xFF7E  --[[ Alias for mode_switch ]]--\n\n--[[\n * Technical\n * Byte 3 = 8\n ]]--\n\nXK_leftradical = 0x8a1\nXK_topleftradical = 0x8a2\nXK_horizconnector = 0x8a3\nXK_topintegral = 0x8a4\nXK_botintegral = 0x8a5\nXK_vertconnector = 0x8a6\nXK_topleftsqbracket = 0x8a7\nXK_botleftsqbracket = 0x8a8\nXK_toprightsqbracket = 0x8a9\nXK_botrightsqbracket = 0x8aa\nXK_topleftparens = 0x8ab\nXK_botleftparens = 0x8ac\nXK_toprightparens = 0x8ad\nXK_botrightparens = 0x8ae\nXK_leftmiddlecurlybrace = 0x8af\nXK_rightmiddlecurlybrace = 0x8b0\nXK_topleftsummation = 0x8b1\nXK_botleftsummation = 0x8b2\nXK_topvertsummationconnector = 0x8b3\nXK_botvertsummationconnector = 0x8b4\nXK_toprightsummation = 0x8b5\nXK_botrightsummation = 0x8b6\nXK_rightmiddlesummation = 0x8b7\nXK_lessthanequal = 0x8bc\nXK_notequal = 0x8bd\nXK_greaterthanequal = 0x8be\nXK_integral = 0x8bf\nXK_therefore = 0x8c0\nXK_variation = 0x8c1\nXK_infinity = 0x8c2\nXK_nabla = 0x8c5\nXK_approximate = 0x8c8\nXK_similarequal = 0x8c9\nXK_ifonlyif = 0x8cd\nXK_implies = 0x8ce\nXK_identical = 0x8cf\nXK_radical = 0x8d6\nXK_includedin = 0x8da\nXK_includes = 0x8db\nXK_intersection = 0x8dc\nXK_union = 0x8dd\nXK_logicaland = 0x8de\nXK_logicalor = 0x8df\nXK_partialderivative = 0x8ef\nXK_function = 0x8f6\nXK_leftarrow = 0x8fb\nXK_uparrow = 0x8fc\nXK_rightarrow = 0x8fd\nXK_downarrow = 0x8fe\n\n--[[\n *  Special\n *  Byte 3 = 9\n ]]--\n\nXK_blank = 0x9df\nXK_soliddiamond = 0x9e0\nXK_checkerboard = 0x9e1\nXK_ht = 0x9e2\nXK_ff = 0x9e3\nXK_cr = 0x9e4\nXK_lf = 0x9e5\nXK_nl = 0x9e8\nXK_vt = 0x9e9\nXK_lowrightcorner = 0x9ea\nXK_uprightcorner = 0x9eb\nXK_upleftcorner = 0x9ec\nXK_lowleftcorner = 0x9ed\nXK_crossinglines = 0x9ee\nXK_horizlinescan1 = 0x9ef\nXK_horizlinescan3 = 0x9f0\nXK_horizlinescan5 = 0x9f1\nXK_horizlinescan7 = 0x9f2\nXK_horizlinescan9 = 0x9f3\nXK_leftt = 0x9f4\nXK_rightt = 0x9f5\nXK_bott = 0x9f6\nXK_topt = 0x9f7\nXK_vertbar = 0x9f8\n\n--[[\n *  Publishing\n *  Byte 3 = a\n ]]--\n\nXK_emspace = 0xaa1\nXK_enspace = 0xaa2\nXK_em3space = 0xaa3\nXK_em4space = 0xaa4\nXK_digitspace = 0xaa5\nXK_punctspace = 0xaa6\nXK_thinspace = 0xaa7\nXK_hairspace = 0xaa8\nXK_emdash = 0xaa9\nXK_endash = 0xaaa\nXK_signifblank = 0xaac\nXK_ellipsis = 0xaae\nXK_doubbaselinedot = 0xaaf\nXK_onethird = 0xab0\nXK_twothirds = 0xab1\nXK_onefifth = 0xab2\nXK_twofifths = 0xab3\nXK_threefifths = 0xab4\nXK_fourfifths = 0xab5\nXK_onesixth = 0xab6\nXK_fivesixths = 0xab7\nXK_careof = 0xab8\nXK_figdash = 0xabb\nXK_leftanglebracket = 0xabc\nXK_decimalpoint = 0xabd\nXK_rightanglebracket = 0xabe\nXK_marker = 0xabf\nXK_oneeighth = 0xac3\nXK_threeeighths = 0xac4\nXK_fiveeighths = 0xac5\nXK_seveneighths = 0xac6\nXK_trademark = 0xac9\nXK_signaturemark = 0xaca\nXK_trademarkincircle = 0xacb\nXK_leftopentriangle = 0xacc\nXK_rightopentriangle = 0xacd\nXK_emopencircle = 0xace\nXK_emopenrectangle = 0xacf\nXK_leftsinglequotemark = 0xad0\nXK_rightsinglequotemark = 0xad1\nXK_leftdoublequotemark = 0xad2\nXK_rightdoublequotemark = 0xad3\nXK_prescription = 0xad4\nXK_minutes = 0xad6\nXK_seconds = 0xad7\nXK_latincross = 0xad9\nXK_hexagram = 0xada\nXK_filledrectbullet = 0xadb\nXK_filledlefttribullet = 0xadc\nXK_filledrighttribullet = 0xadd\nXK_emfilledcircle = 0xade\nXK_emfilledrect = 0xadf\nXK_enopencircbullet = 0xae0\nXK_enopensquarebullet = 0xae1\nXK_openrectbullet = 0xae2\nXK_opentribulletup = 0xae3\nXK_opentribulletdown = 0xae4\nXK_openstar = 0xae5\nXK_enfilledcircbullet = 0xae6\nXK_enfilledsqbullet = 0xae7\nXK_filledtribulletup = 0xae8\nXK_filledtribulletdown = 0xae9\nXK_leftpointer = 0xaea\nXK_rightpointer = 0xaeb\nXK_club = 0xaec\nXK_diamond = 0xaed\nXK_heart = 0xaee\nXK_maltesecross = 0xaf0\nXK_dagger = 0xaf1\nXK_doubledagger = 0xaf2\nXK_checkmark = 0xaf3\nXK_ballotcross = 0xaf4\nXK_musicalsharp = 0xaf5\nXK_musicalflat = 0xaf6\nXK_malesymbol = 0xaf7\nXK_femalesymbol = 0xaf8\nXK_telephone = 0xaf9\nXK_telephonerecorder = 0xafa\nXK_phonographcopyright = 0xafb\nXK_caret = 0xafc\nXK_singlelowquotemark = 0xafd\nXK_doublelowquotemark = 0xafe\nXK_cursor = 0xaff\n\n--[[\n *  APL\n *  Byte 3 = b\n ]]--\n\nXK_leftcaret = 0xba3\nXK_rightcaret = 0xba6\nXK_downcaret = 0xba8\nXK_upcaret = 0xba9\nXK_overbar = 0xbc0\nXK_downtack = 0xbc2\nXK_upshoe = 0xbc3\nXK_downstile = 0xbc4\nXK_underbar = 0xbc6\nXK_jot = 0xbca\nXK_quad = 0xbcc\nXK_uptack = 0xbce\nXK_circle = 0xbcf\nXK_upstile = 0xbd3\nXK_downshoe = 0xbd6\nXK_rightshoe = 0xbd8\nXK_leftshoe = 0xbda\nXK_lefttack = 0xbdc\nXK_righttack = 0xbfc\n\n--[[\n * Hebrew\n * Byte 3 = c\n ]]--\n\nXK_hebrew_doublelowline = 0xcdf\nXK_hebrew_aleph = 0xce0\nXK_hebrew_bet = 0xce1\nXK_hebrew_beth = 0xce1  --[[ deprecated ]]--\nXK_hebrew_gimel = 0xce2\nXK_hebrew_gimmel = 0xce2  --[[ deprecated ]]--\nXK_hebrew_dalet = 0xce3\nXK_hebrew_daleth = 0xce3  --[[ deprecated ]]--\nXK_hebrew_he = 0xce4\nXK_hebrew_waw = 0xce5\nXK_hebrew_zain = 0xce6\nXK_hebrew_zayin = 0xce6  --[[ deprecated ]]--\nXK_hebrew_chet = 0xce7\nXK_hebrew_het = 0xce7  --[[ deprecated ]]--\nXK_hebrew_tet = 0xce8\nXK_hebrew_teth = 0xce8  --[[ deprecated ]]--\nXK_hebrew_yod = 0xce9\nXK_hebrew_finalkaph = 0xcea\nXK_hebrew_kaph = 0xceb\nXK_hebrew_lamed = 0xcec\nXK_hebrew_finalmem = 0xced\nXK_hebrew_mem = 0xcee\nXK_hebrew_finalnun = 0xcef\nXK_hebrew_nun = 0xcf0\nXK_hebrew_samech = 0xcf1\nXK_hebrew_samekh = 0xcf1  --[[ deprecated ]]--\nXK_hebrew_ayin = 0xcf2\nXK_hebrew_finalpe = 0xcf3\nXK_hebrew_pe = 0xcf4\nXK_hebrew_finalzade = 0xcf5\nXK_hebrew_finalzadi = 0xcf5  --[[ deprecated ]]--\nXK_hebrew_zade = 0xcf6\nXK_hebrew_zadi = 0xcf6  --[[ deprecated ]]--\nXK_hebrew_qoph = 0xcf7\nXK_hebrew_kuf = 0xcf7  --[[ deprecated ]]--\nXK_hebrew_resh = 0xcf8\nXK_hebrew_shin = 0xcf9\nXK_hebrew_taw = 0xcfa\nXK_hebrew_taf = 0xcfa  --[[ deprecated ]]--\nXK_Hebrew_switch = 0xFF7E  --[[ Alias for mode_switch ]]--\n\n--[[\n * Thai\n * Byte 3 = d\n ]]--\n\nXK_Thai_kokai = 0xda1\nXK_Thai_khokhai = 0xda2\nXK_Thai_khokhuat = 0xda3\nXK_Thai_khokhwai = 0xda4\nXK_Thai_khokhon = 0xda5\nXK_Thai_khorakhang = 0xda6  \nXK_Thai_ngongu = 0xda7  \nXK_Thai_chochan = 0xda8  \nXK_Thai_choching = 0xda9   \nXK_Thai_chochang = 0xdaa  \nXK_Thai_soso = 0xdab\nXK_Thai_chochoe = 0xdac\nXK_Thai_yoying = 0xdad\nXK_Thai_dochada = 0xdae\nXK_Thai_topatak = 0xdaf\nXK_Thai_thothan = 0xdb0\nXK_Thai_thonangmontho = 0xdb1\nXK_Thai_thophuthao = 0xdb2\nXK_Thai_nonen = 0xdb3\nXK_Thai_dodek = 0xdb4\nXK_Thai_totao = 0xdb5\nXK_Thai_thothung = 0xdb6\nXK_Thai_thothahan = 0xdb7\nXK_Thai_thothong = 0xdb8\nXK_Thai_nonu = 0xdb9\nXK_Thai_bobaimai = 0xdba\nXK_Thai_popla = 0xdbb\nXK_Thai_phophung = 0xdbc\nXK_Thai_fofa = 0xdbd\nXK_Thai_phophan = 0xdbe\nXK_Thai_fofan = 0xdbf\nXK_Thai_phosamphao = 0xdc0\nXK_Thai_moma = 0xdc1\nXK_Thai_yoyak = 0xdc2\nXK_Thai_rorua = 0xdc3\nXK_Thai_ru = 0xdc4\nXK_Thai_loling = 0xdc5\nXK_Thai_lu = 0xdc6\nXK_Thai_wowaen = 0xdc7\nXK_Thai_sosala = 0xdc8\nXK_Thai_sorusi = 0xdc9\nXK_Thai_sosua = 0xdca\nXK_Thai_hohip = 0xdcb\nXK_Thai_lochula = 0xdcc\nXK_Thai_oang = 0xdcd\nXK_Thai_honokhuk = 0xdce\nXK_Thai_paiyannoi = 0xdcf\nXK_Thai_saraa = 0xdd0\nXK_Thai_maihanakat = 0xdd1\nXK_Thai_saraaa = 0xdd2\nXK_Thai_saraam = 0xdd3\nXK_Thai_sarai = 0xdd4   \nXK_Thai_saraii = 0xdd5   \nXK_Thai_saraue = 0xdd6    \nXK_Thai_sarauee = 0xdd7    \nXK_Thai_sarau = 0xdd8    \nXK_Thai_sarauu = 0xdd9   \nXK_Thai_phinthu = 0xdda\nXK_Thai_maihanakat_maitho = 0xdde\nXK_Thai_baht = 0xddf\nXK_Thai_sarae = 0xde0    \nXK_Thai_saraae = 0xde1\nXK_Thai_sarao = 0xde2\nXK_Thai_saraaimaimuan = 0xde3   \nXK_Thai_saraaimaimalai = 0xde4  \nXK_Thai_lakkhangyao = 0xde5\nXK_Thai_maiyamok = 0xde6\nXK_Thai_maitaikhu = 0xde7\nXK_Thai_maiek = 0xde8   \nXK_Thai_maitho = 0xde9\nXK_Thai_maitri = 0xdea\nXK_Thai_maichattawa = 0xdeb\nXK_Thai_thanthakhat = 0xdec\nXK_Thai_nikhahit = 0xded\nXK_Thai_leksun = 0xdf0 \nXK_Thai_leknung = 0xdf1  \nXK_Thai_leksong = 0xdf2 \nXK_Thai_leksam = 0xdf3\nXK_Thai_leksi = 0xdf4  \nXK_Thai_lekha = 0xdf5  \nXK_Thai_lekhok = 0xdf6  \nXK_Thai_lekchet = 0xdf7  \nXK_Thai_lekpaet = 0xdf8  \nXK_Thai_lekkao = 0xdf9 \n\n--[[\n *   Korean\n *   Byte 3 = e\n ]]--\n\nXK_Hangul = 0xff31    --[[ Hangul start/stop(toggle) ]]--\nXK_Hangul_Start = 0xff32    --[[ Hangul start ]]--\nXK_Hangul_End = 0xff33    --[[ Hangul end, English start ]]--\nXK_Hangul_Hanja = 0xff34    --[[ Start Hangul->Hanja Conversion ]]--\nXK_Hangul_Jamo = 0xff35    --[[ Hangul Jamo mode ]]--\nXK_Hangul_Romaja = 0xff36    --[[ Hangul Romaja mode ]]--\nXK_Hangul_Codeinput = 0xff37    --[[ Hangul code input mode ]]--\nXK_Hangul_Jeonja = 0xff38    --[[ Jeonja mode ]]--\nXK_Hangul_Banja = 0xff39    --[[ Banja mode ]]--\nXK_Hangul_PreHanja = 0xff3a    --[[ Pre Hanja conversion ]]--\nXK_Hangul_PostHanja = 0xff3b    --[[ Post Hanja conversion ]]--\nXK_Hangul_SingleCandidate = 0xff3c    --[[ Single candidate ]]--\nXK_Hangul_MultipleCandidate = 0xff3d    --[[ Multiple candidate ]]--\nXK_Hangul_PreviousCandidate = 0xff3e    --[[ Previous candidate ]]--\nXK_Hangul_Special = 0xff3f    --[[ Special symbols ]]--\nXK_Hangul_switch = 0xFF7E    --[[ Alias for mode_switch ]]--\n\n--[[ Hangul Consonant Characters ]]--\nXK_Hangul_Kiyeog = 0xea1\nXK_Hangul_SsangKiyeog = 0xea2\nXK_Hangul_KiyeogSios = 0xea3\nXK_Hangul_Nieun = 0xea4\nXK_Hangul_NieunJieuj = 0xea5\nXK_Hangul_NieunHieuh = 0xea6\nXK_Hangul_Dikeud = 0xea7\nXK_Hangul_SsangDikeud = 0xea8\nXK_Hangul_Rieul = 0xea9\nXK_Hangul_RieulKiyeog = 0xeaa\nXK_Hangul_RieulMieum = 0xeab\nXK_Hangul_RieulPieub = 0xeac\nXK_Hangul_RieulSios = 0xead\nXK_Hangul_RieulTieut = 0xeae\nXK_Hangul_RieulPhieuf = 0xeaf\nXK_Hangul_RieulHieuh = 0xeb0\nXK_Hangul_Mieum = 0xeb1\nXK_Hangul_Pieub = 0xeb2\nXK_Hangul_SsangPieub = 0xeb3\nXK_Hangul_PieubSios = 0xeb4\nXK_Hangul_Sios = 0xeb5\nXK_Hangul_SsangSios = 0xeb6\nXK_Hangul_Ieung = 0xeb7\nXK_Hangul_Jieuj = 0xeb8\nXK_Hangul_SsangJieuj = 0xeb9\nXK_Hangul_Cieuc = 0xeba\nXK_Hangul_Khieuq = 0xebb\nXK_Hangul_Tieut = 0xebc\nXK_Hangul_Phieuf = 0xebd\nXK_Hangul_Hieuh = 0xebe\n\n--[[ Hangul Vowel Characters ]]--\nXK_Hangul_A = 0xebf\nXK_Hangul_AE = 0xec0\nXK_Hangul_YA = 0xec1\nXK_Hangul_YAE = 0xec2\nXK_Hangul_EO = 0xec3\nXK_Hangul_E = 0xec4\nXK_Hangul_YEO = 0xec5\nXK_Hangul_YE = 0xec6\nXK_Hangul_O = 0xec7\nXK_Hangul_WA = 0xec8\nXK_Hangul_WAE = 0xec9\nXK_Hangul_OE = 0xeca\nXK_Hangul_YO = 0xecb\nXK_Hangul_U = 0xecc\nXK_Hangul_WEO = 0xecd\nXK_Hangul_WE = 0xece\nXK_Hangul_WI = 0xecf\nXK_Hangul_YU = 0xed0\nXK_Hangul_EU = 0xed1\nXK_Hangul_YI = 0xed2\nXK_Hangul_I = 0xed3\n\n--[[ Hangul syllable-final (JongSeong) Characters ]]--\nXK_Hangul_J_Kiyeog = 0xed4\nXK_Hangul_J_SsangKiyeog = 0xed5\nXK_Hangul_J_KiyeogSios = 0xed6\nXK_Hangul_J_Nieun = 0xed7\nXK_Hangul_J_NieunJieuj = 0xed8\nXK_Hangul_J_NieunHieuh = 0xed9\nXK_Hangul_J_Dikeud = 0xeda\nXK_Hangul_J_Rieul = 0xedb\nXK_Hangul_J_RieulKiyeog = 0xedc\nXK_Hangul_J_RieulMieum = 0xedd\nXK_Hangul_J_RieulPieub = 0xede\nXK_Hangul_J_RieulSios = 0xedf\nXK_Hangul_J_RieulTieut = 0xee0\nXK_Hangul_J_RieulPhieuf = 0xee1\nXK_Hangul_J_RieulHieuh = 0xee2\nXK_Hangul_J_Mieum = 0xee3\nXK_Hangul_J_Pieub = 0xee4\nXK_Hangul_J_PieubSios = 0xee5\nXK_Hangul_J_Sios = 0xee6\nXK_Hangul_J_SsangSios = 0xee7\nXK_Hangul_J_Ieung = 0xee8\nXK_Hangul_J_Jieuj = 0xee9\nXK_Hangul_J_Cieuc = 0xeea\nXK_Hangul_J_Khieuq = 0xeeb\nXK_Hangul_J_Tieut = 0xeec\nXK_Hangul_J_Phieuf = 0xeed\nXK_Hangul_J_Hieuh = 0xeee\n\n--[[ Ancient Hangul Consonant Characters ]]--\nXK_Hangul_RieulYeorinHieuh = 0xeef\nXK_Hangul_SunkyeongeumMieum = 0xef0\nXK_Hangul_SunkyeongeumPieub = 0xef1\nXK_Hangul_PanSios = 0xef2\nXK_Hangul_KkogjiDalrinIeung = 0xef3\nXK_Hangul_SunkyeongeumPhieuf = 0xef4\nXK_Hangul_YeorinHieuh = 0xef5\n\n--[[ Ancient Hangul Vowel Characters ]]--\nXK_Hangul_AraeA = 0xef6\nXK_Hangul_AraeAE = 0xef7\n\n--[[ Ancient Hangul syllable-final (JongSeong) Characters ]]--\nXK_Hangul_J_PanSios = 0xef8\nXK_Hangul_J_KkogjiDalrinIeung = 0xef9\nXK_Hangul_J_YeorinHieuh = 0xefa\n\n--[[ Korean currency symbol ]]--\nXK_Korean_Won = 0xeff\n\n--[[ Euro currency symbol ]]--\nXK_EuroSign = 0x20ac\n\n"
  },
  {
    "path": "vncviewer.lua",
    "content": "#!./luajit\nlocal ffi = require(\"ffi\")\nlocal blitbuffer = require(\"ffi/blitbuffer\")\nlocal fb = require(\"ffi/framebuffer\").open(\"/dev/fb0\")\nlocal evloop = require(\"ffi/eventloop\")\nlocal input = require(\"ffi/input\")\nlocal posix = require(\"ffi/posix_h\")\nlocal rfb = require(\"ffi/rfbclient\")\n\nlocal password = nil\nlocal client = nil\nlocal rfbFramebuffer = nil\nlocal configfile = \"config.lua\"\n\nlocal waitRefresh = 250\nlocal rotateFB = 0\nlocal reconnecting = false\nlocal debug = false\nlocal blitfunc = nil\n\nlocal update_x1 = nil\nlocal update_x2 = 0\nlocal update_y1 = 0\nlocal update_y2 = 0\n\nlocal refresh_full_every_256th_pxup = 512\nlocal refresh_full_ctr = 0\n\n-- this is just an ID value\nlocal TIMER_REFRESH = 10\n\n-- constants for screen updates\nlocal WAVEFORM_MODE_INIT      = 0x0   -- Screen goes to white (clears)\nlocal WAVEFORM_MODE_DU        = 0x1   -- Grey->white/grey->black\nlocal WAVEFORM_MODE_GC16      = 0x2   -- High fidelity (flashing)\nlocal WAVEFORM_MODE_GC4       = WAVEFORM_MODE_GC16 -- For compatibility\nlocal WAVEFORM_MODE_GC16_FAST = 0x3   -- Medium fidelity\nlocal WAVEFORM_MODE_A2        = 0x4   -- Faster but even lower fidelity\nlocal WAVEFORM_MODE_GL16      = 0x5   -- High fidelity from white transition\nlocal WAVEFORM_MODE_GL16_FAST = 0x6   -- Medium fidelity from white transition\nlocal WAVEFORM_MODE_AUTO      = 0x101\n\nlocal waveform_default_fast = WAVEFORM_MODE_GC16\nlocal waveform_default_slow = WAVEFORM_MODE_GC16\n\n-- this is a \"public\" API to be used by a \"config\" file\nfunction SendKeyEvent(key, pressed)\n\trfb.SendKeyEvent(client, key, pressed)\nend\nfunction SendPointerEvent(x, y, buttonMask)\n\trfb.SendPointerEvent(client, x, y, buttonMask)\nend\nfunction Quit()\n\tos.exit(0)\nend\n\nlocal function do_refresh_full(w, h)\n\t-- return false when full refresh is disabled\n\tif refresh_full_every_256th_pxup == 0 then\n\t\treturn false\n\tend\n\t-- otherwise count number of pixels updated\n\trefresh_full_ctr = refresh_full_ctr + w*h\n\tif refresh_full_ctr >= bit.rshift(fb.bb:getWidth() * fb.bb:getHeight() * refresh_full_every_256th_pxup, 8) then\n\t\trefresh_full_ctr = 0\n\t\treturn true\n\tend\n\treturn false\nend\n\nlocal function refreshTimerFunc()\n\t-- not sure how this could happen but it does.\n\t-- TODO: find race condition\n\t--if not update_x1 then return end\n\n\tlocal x = update_x1\n\tlocal y = update_y1\n\tlocal w = update_x2 - update_x1\n\tlocal h = update_y2 - update_y1\n\n\tif debug then\n\t\tio.stdout:write(\n\t\t\t\"eink update \", x, \",\", y, \" \",\n\t\t\tw, \"x\", h, \"\\n\")\n\tend\n\n\tfb.bb:blitFrom(rfbFramebuffer,\n\t\tx, y, x, y, w, h, blitfunc)\n\n\tif do_refresh_full(w, h) then\n\t\tif debug then\n\t\t\tio.stdout:write(\"slow eink refresh\\n\")\n\t\tend\n\t\tfb:refresh(1, waveform_default_slow)\n\telse\n\t\tif debug then\n\t\t\tio.stdout:write(\"fast eink refresh\\n\")\n\t\tend\n\t\tfb:refresh(0, waveform_default_fast, x, y, w, h)\n\tend\n\tupdate_x1 = nil\nend\n\nlocal function updateFromRFB(client, x, y, w, h)\n\t-- this would reset the timer, which we probably do not\n\t-- want since this might hold a eink refresh\n\t-- indefinitely:\n\t--evloop.unregister_timer(TIMER_REFRESH)\n\n\tif debug then\n\t\tio.stdout:write(\n\t\t\t\"RFB update \", x, \",\", y, \" \",\n\t\t\tw, \"x\", h, \"\\n\")\n\tend\n\n\tif not update_x1 then\n\t\tupdate_x1 = x\n\t\tupdate_x2 = x+w\n\t\tupdate_y1 = y\n\t\tupdate_y2 = y+h\n\telse\n\t\tif update_x1 > x then update_x1 = x end\n\t\tif update_x2 < x+w then update_x2 = x+w end\n\t\tif update_y1 > y then update_y1 = y end\n\t\tif update_y2 < y+h then update_y2 = y+h end\n\tend\n\n\tif not evloop.timer_running(TIMER_REFRESH) then\n\t\tevloop.register_timer_in_ms(waitRefresh,\n\t\t\trefreshTimerFunc, TIMER_REFRESH)\n\tend\nend\n\nlocal function passwordCallback(client)\n\tif password then\n\t\t-- we need a copy that libvncclient can free()\n\t\treturn ffi.C.strndup(ffi.cast(\"char*\", password), 8192)\n\tend\n\tio.stderr:write(\"got request for password, but no password was configured.\\n\")\n\treturn nil\nend\n\nlocal function connect()\n\tlocal client = rfb.rfbGetClient(8,3,4) -- 24bpp\n\n\tclient.GetPassword = passwordCallback\n\tclient.canHandleNewFBSize = 0\n\tclient.GotFrameBufferUpdate = updateFromRFB\n\n\tlocal argc = ffi.new(\"int[1]\")\n\targc[0] = #arg + 1\n\tlocal argv = ffi.new(\"char*[?]\", #arg+1)\n\targv[0] = ffi.cast(\"char*\", \"kindlevncviewer\")\n\tfor k, v in ipairs(arg) do\n\t\targv[k] = ffi.cast(\"char*\", v)\n\tend\n\n\tassert(rfb.rfbInitClient(client,argc,argv) ~= 0, \"cannot initialize client\")\n\n\t-- set \"public\" configuration parameters:\n\tclient_width = client.width\n\tclient_height = client.height\n\n\trfbFramebuffer = blitbuffer.new(\n\t\tclient.width, client.height,\n\t\tblitbuffer.TYPE_BBBGR32,\n\t\tclient.frameBuffer)\n\trfbFramebuffer:invert()\n\n\treturn client\nend\n\nlocal function usage()\n\tio.stderr:write([[\nkVNCViewer\nA VNC viewer for e-ink devices\nThis is free software (GPLv2)\n(c) 2013 Hans-Werner Hilse <hilse@web.de>\n\nUsage:\n\n  luajit kindlevncviewer.lua [options...] <server>:<display>\n\nServer is the VNC server's domain name or its IP address\nDisplay is the VNC display number (i.e. not the TCP port number)\n\nAvailable options:\n\n-password <password>\n   specify a password\n\n-config <file>\n   load configuration from <file>. Default is \"config.lua\".\n\n-rotateFB <degree>\n   rotate local framebuffer by <degree> degrees (multiple of 90)\n\n-waitRefresh <milliseconds>\n   wait specified number of milliseconds after receiving an update\n   before refreshing the screen. Default value is 150.\n\n-refreshFullAfterPixels <n>\n   after updating <n> times the screen's pixels, a full eink\n   refresh is issued. Default is 2.0\n   If you specify 0 here, it won't do a full refresh at all.\n\n-dither_bw\n   dither to black/white (speeds up display on eink, but looks ugly)\n\n-medium\n   a bit lower quality, but also a tad bit faster\n\n-fast\n   low quality but fast\n\n-debug\n   output some debug information\n\n-reconnecting\n   always try to reconnect when we get connection errors\n\n-version\n   output version number\n\n(and some more that stem from libvncclient, to be documented)\n\n]])\n\tos.exit(1)\nend\n\nlocal function try_open_input(device)\n\tlocal ok, err = pcall(input.open, device)\n\tif not ok then\n\t\tio.stderr:write(\"could not open input device \", device, \" (possibly harmless)\\n\")\n\tend\nend\n\nif #arg == 0 then usage() end\nfor i,value in ipairs(arg) do\n\tif value == \"-h\" or value == \"-?\" or value == \"--help\" then usage() end\n\tif value == \"-password\" and arg[i+1] then\n\t\tpassword = arg[i+1]\n\t\targ[i+1] = \"\"\n\telseif value == \"-config\" and arg[i+1] then\n\t\tconfigfile = arg[i+1]\n\t\targ[i+1] = \"\"\n\telseif value == \"-rotateFB\" and arg[i+1] then\n\t\trotateFB = tonumber(arg[i+1])\n\t\targ[i+1] = \"\"\n\telseif value == \"-waitRefresh\" and arg[i+1] then\n\t\twaitRefresh = tonumber(arg[i+1])\n\t\targ[i+1] = \"\"\n\telseif value == \"-refreshFullAfterPixels\" and arg[i+1] then\n\t\trefresh_full_every_256th_pxup = 256 * tonumber(arg[i+1])\n\t\targ[i+1] = \"\"\n\telseif value == \"-fast\" then\n\t\tlocal waveform_default_fast = WAVEFORM_MODE_A2\n\t\tlocal waveform_default_slow = WAVEFORM_MODE_GL16\n\telseif value == \"-medium\" then\n\t\tlocal waveform_default_fast = WAVEFORM_MODE_GL16\n\t\tlocal waveform_default_slow = WAVEFORM_MODE_GL16\n\telseif value == \"-dither_bw\" then\n\t\tblitfunc = fb.bb.setPixelDithered\n\telseif value == \"-debug\" then\n\t\tdebug = true\n\telseif value == \"-reconnecting\" then\n\t\treconnecting = true\n\telseif value == \"-version\" then\n\t\tio.stdout:write(\"KindleVNCviewer version \", require(\"version\"), \"\\n\",\n\t\t\t\t\"see http://github.com/hwhw/kindlevncviewer for source code\\n\")\n\t\tos.exit(0)\n\tend\nend\n\n-- open the \"config\" file\ndofile(configfile)\n\nfb.bb:rotate(rotateFB)\n\ntry_open_input(\"/dev/input/event0\")\ntry_open_input(\"/dev/input/event1\")\ntry_open_input(\"/dev/input/event2\")\n\nrepeat\n\tclient = connect()\n\n\tlocal running = true\n\n\t-- register socket handlers\n\tevloop.register_fd(client.sock, {\n\t\tread = function()\n\t\t\tassert(rfb.HandleRFBServerMessage(client) ~= 0, \"Error handling RFB server message.\")\n\t\tend,\n\t\terr = function()\n\t\t\tif not reconnecting then\n\t\t\t\tio.stderr:write(\"connection error, quitting.\\n\")\n\t\t\t\tos.exit(1)\n\t\t\telse\n\t\t\t\tio.stderr:write(\"connection error, retrying in 1s...\\n\")\n\t\t\t\trunning = false\n\t\t\tend\n\t\tend,\n\t\thup = function()\n\t\t\tif not reconnecting then\n\t\t\t\tio.stderr:write(\"remote party hung up, quitting.\\n\")\n\t\t\t\tos.exit(1)\n\t\t\telse\n\t\t\t\tio.stderr:write(\"remote party hung up, retrying in 1s...\\n\")\n\t\t\t\trunning = false\n\t\t\tend\n\t\tend\n\t})\n\n\twhile running do\n\t\tlocal event = input.waitForEvent()\n\t\thandleInput(0, event.type, event.code, event.value)\n\tend\n\n\tffi.C.sleep(1) -- so we don't hammer when the connection is down\nuntil not reconnecting\n"
  }
]