
                                   KJS V0.1
                                   ========     

                              © 2011 David Given
                                  2011-04-10



INTRODUCTION
============

KJS is a port of the Rhino Javascript engine for the Kindle, with an
interactive shell and terminal emulator. It's intended as a debugging and
development toy. Rhino's LiveConnect feature allows direct access to Java
APIs, which makes it excellent for experimenting with development on the
Kindle.

You can, for example, type this:

  var home = kjs.getHomeDirectory();
  var f = new java.io.File(home, "test.txt");
  var ps = new java.io.PrintStream(f);
  ps.println("Hello, world!");
  ps.close();
  
...and it'll open and write a file.

The Kindle runs applications under heavy security, so it's not actually
possible to, e.g., access files outside your application's own storage area;
but it's useful nevertheless.

Unfortunately the Kindle also disallows useful stuff like creating our own
class loaders, which means that Rhino isn't able to compile class files on the
fly to speed up the Javascript interpreter; which means it's dog slow. 



INSTALLATION
============

If this is the binary release, then to install:

1. Jailbreak your Kindle.

2. Install my developer public keys, if you have not already done so:

   Copy one of the three update_PublicKeys* files to the root directory
   of your Kindle. Then, after unplugging it from the computer, pick
   Menu -> Settings -> Update Your Kindle. Your device will install the keys
   and reboot.
   
   Which file you need depends on what device you have:
   
     k3w:  Kindle 3 WiFi only 
     k3g:  Kindle 3 US 3G & WiFi
     k3gb: Kindle 3 UK 3G & WiFi
   
   Sorry, I only have binaries for the Kindle 3 so far. If anyone gets this
   working on another model, please get in touch.
   
3. Copy the enclosed KJS.azw2 file to the /documents directory on your Kindle.



BUILDING
========

The supplied antfile and makekindlet scripts will build the application,
sign it, and construct an .azw2 file suitable for installation on the Kindle.
It's set up for a jailbroken development environment; you'll need a copy of
the Kindlet-1.1.jar file from the device in ../kindle/Kindlet-1.1.jar, and
a set of developer private keys in ~/.kindle/kindle.keystore.

See http://www.cowlark.com/kindle on how to build these. 



RUNNING
=======

When run, KJS will show you a basic terminal emulator which you can type into.
Number keys are obtained by using Alt+the top row of the keyboard, as usual,
but Shift, Sym and Aa are non-standard: Shift and Sym are modifier keys; hold
them for a guide as to what key does what. Aa is the control key.

Note that you get a comma with the Shift+. combination.

The command line has got history and full editing; you can use the 5-way,
or else standard Emacsish control sequences: ^N and ^P for previous and next,
^B and ^F for back and forwards, ^A and ^E to move to the beginning and end of
a line, and ^U to clear a complete line.

Lines beginning with a * are passed to 'the shell'. This is a very simple
mechanism for running external Javascript programs. Place this in /bin in
the KJS application's home directory (use *help to tell you where this is).
There are some built in commands which will be installed as needed.



DANGER
======

Right now it's not possible to break out of infinite loops. If you get into
one of these, your Kindle will hang indefinitely. The only way out is to reset
it by holding the power switch for about 20 seconds.

This program is a HIDEOUS HACK, and I have lost count of the number of times
I have crashed my Kindle working on it. I haven't lost any files. I've been
lucky. You may not be so lucky, and I am not to be held responsible for any
damage caused by the program to your data and your device.

YOU HAVE BEEN WARNED.



LICENSE
=======

The package contains software from a variety of sources.

src/org.mozilla: this is the Rhino engine. This is dual licensed as MPL 1.1 and
GPL 2.0.

src/com.cowlark.eventbus: this is a heavily hacked version of GWT's event bus
mechanism. This is Apache 2.0 licensed.

lib/retroweaver*: retroweaver is covered by the BSD license.

lib/asm*: ASM is covered by the BSD license.

Everything else: was written by me and is MIT licensed.


The package as a whole is covered by the MPL 1.1.


The full text of all these licenses are enclosed in the doc folder.



AUTHOR
======

WordGrinder was written by me, David Given. You may contact me at
dg@cowlark.com, or visit my website at http://www.cowlark.com. There may or
may not be anything interesting there.
