Finally, a small handheld computer with a keyboard that isn't a cell
phone! I was almost to the point of building a small 8052-based
computer just so I could have BASIC on the go, but the COM-2 is smaller
and faster than anything I can make, plus it plays music and video and
surfs the web via WiFi. Mainly though, it is possible to program the
thing in HTML and javascript, even using its built-in text editor.
The COM-2 uses the NetFront 3.4 browser and has decent javascript
and flash support, but like all mobile browsers something's gotta give
to make it fit. In this case it only has a single resizeable
proportional font, supports only a subset of javascript "ECMA-262"
commands, no fancy stuff (iframes innerHTML scrollTop etc), focusing
has limitations, and certain key events are not passed to the usual
onkeydown/onkeypress event handlers, in particular space and backspace.
Unless a workaround for the focus behavior can be found, either you've
got to click on the input field the first time the app is loaded, or
key handling methods have to be used with other keys substituted for
space and backspace. Right and left arrows make sense. Granted I'm
probably expecting too much but HTML/javascript is the only native
COM-2 user programming language available and this thing is way cool
and needs to be programmed. So whatever it takes to make it go. Besides
it not being a cell phone, I chose the COM-2 because Sony encourages
user programming and provides documentation on the mylo(tm)Labs site. A lot can be
done using plain javascript but built-in libraries make it possible to
write applications
that read and write data files and access COM-2-specific features.
Simplicity cuts both ways... whereas most browsers are smart and
display files that don't have .htm[l] extensions as plain text or using
another application, the COM-2 NetFront 3.4 doesn't care, an html file
can be named txt and still display html and run javascript just fine.
This makes it possible to use the text editor to compose code, since
only .txt files can be edited and the file manager does not permit
changing the extension. This is something I hope doesn't get "fixed",
if the browser couldn't "run" .txt files that would make it impossible
to program it without using a PC unless other editor/file manager
changes were also made, it's nice to be able to make a code change then
in seconds test it. The last update added a GAME folder on the main
screen, so any text files placed there can be quickly edited without
invoking the file manager. Then I go back to the main screen, Web,
Bookmarks, select the text file containing the thing I'm working on and
there it is. To make a bookmark specify file:///c/GAME/filename.txt in
the location box. Quickly accessing folders besides GAME would be nice
but figuring out this javascript stuff is a game - there's a rush when
it works! Of course all I've got to do is plug the thing into my PC and
the file system opens and I can do whatever, but being able to program
stuff without using any other facilities but the gadget puts it into a
higher level of system functionality - self contained computer. Nice,
and unexpected for a stock consumer-oriented device.
The COM-2 works fine with Ubuntu 8.04 or any other OS which
recognizes standard fat-based media file systems. Don't be swayed by
Windows-specific instructions, the COM-2 itself runs a
version of Qt Linux
and works fine with Linux systems. The COM-2
doesn't have a PDF reader but Ubuntu has a pdftohtml command (use the
-c option) which does a fair to good job of converting documents into
.html/image files which can be copied to and read on the COM-2.
The original code had no INPUT statement, no wonder since
event-driven "web and windows" programming doesn't provide a way to
simply wait for a keystroke then keep going. Instead of fighting it
(and to avoid having to do major mods) I implemented INPUT and GET so
they simply set a javascript variable with the name of the variable to
INPUT or GET user input into, then halt the program. When the user
enters (or in the case of GET types) something the glue code sees that
it's an input request, and in immediate mode (without echoing to the
screen) issues "var=[number or string] : CONT" and the program resumes
at the next line. It ain't right but works quite well provided there
are no commands following the input request on the same line. Also the
form INPUT "prompt", var is not supported, only simple INPUT|GET
var[%|$]. Normally GET is only used with a string but I didn't bother
to add code to prevent GET A (in which case pressing a non-numeric key
returns 0).
Now that I can enter stuff I added buttons to operate numerical
programs and do immediate calculations without having to use the
keyboard. This part was easy, just had to arrange my handlers so button
events could call them too. They might have to be made larger, but for
now they're functional and permit 14 lines in the text area when the
default text size is set to 18.
Finally I can now program the COM-2 for common electronics
calculations...
A closer view...
Click Here to Run or right click link to
download (6/13/08). Here's the help file.
This is a work in progress, subject to change. Note that per GPL
terms the authors are not responsible for any errors or other
consequences resulting from the use of this software. To view the
source use your browser's view source function, or view or download isbas.txt.
The included BASIC "shop" program can be easily removed and replaced
with
other BASIC code, follow the form of the existing code and remember to
write ' as \' to avoid ending the string early. Short programs can be
entered in immediate mode and saved to browser cookies, click stop,
enter new, enter the code, run, etc, then save filename (must not start
with the name of a command). Load filename to reload, run filename to
load and run, cat to list files. See the help file. On a PC this seems
to be reliable but once on the COM-2 after surfing the web I found my
programs gone so I don't trust it. The safest and most convienient
storage method is to directly encode the program into copies of the
interpreter script, this results in about 50K overhead per thing but
compared to the size of other things that's not much.
Implementation and other notes...
This version is adapted to the COM-2, and does not support pasting
code. For use on a PC the original input box method or some other
method that uses the text area might be better since that would permit
pasting in BASIC programs. I didn't do it that way since 1) not
possible on the COM-2 so not an issue, 2) the COM-2 seems to be unable
to focus text input fields in a way that can be immediately typed into
without clicking on first, was able to make it sort of work using the
original Enter button but not if the enter key was pressed, and 3) when
using a single text area for both input and output it always returned
the cursor to the top. So I opted for a single read-only text area
using key handlers to deposit typed keystrokes into it.
There is no cursor, but text is always added to the end of the text
area so it's fairly predictable where the invisible cursor is (just no
feedback for space and backspace - which have to be entered either
using the on-screen buttons or using arrow key substitutes). I'd like
to add a cursor but doing that is a bit more difficult than it sounds
as the cursor character would have to be removed from all input
operations and added to all output operations (including error
messages), and only if in immediate or input mode. If not done very
carefully something will get it wrong under some condition, every code
path and state would have to be considered. I can use it just fine
without a cursor so at the moment doesn't seem worth the effort unless
I get in the mood for some extreme programming.
Presently there is no DIM for arrays. I don't really need it for
programming calculations, and presently I don't know enough about how
the core interpreter code works to implement it. For the kind of stuff
I run having DIM would only permit some games to work but as the
COM-2 has no fixed-pitch font it really wouldn't do any good. To
support BASIC board games on the COM-2 the console area would have to
be implemented as a table array rather than a simple text area and it
starts to get really complicated fast. I'm thrilled just to be able to
program calculations.
Printing table data... make sure numeric data is rounded off to less than 8 characters using an expression like for example INT(N*1000+0.5)/1000 to round to 3 decimal places. PRINT I,J etc will approximately line up data into columns, PRINT I;"[tab]";J works better ([tab] means press the tab key).
6/20/08 - Updated isbas.htm/.txt to 6/13/08 code with added functions for calculating capacitor charge time. No change to the interpreter itself. While writing the code (using FireFox 2) I had problems including IF statements following GOSUB statements on the same line so used separate lines, oddly I can no longer duplicate the problem with a test case. Possibly a javascript error that got fixed with some update but still avoiding IF after GOSUB in case that triggers a glitch in some browsers. I can't help but notice javascript isn't exactly a precise language, more like a moving target subject to change behavior with each new version or update. FireFox 3 actually displays a cursor.. was considering hard-programming that but now I won't as then FF3 would show double cursors. I use ISBAS frequently (both running the shop program and punching in equations in immediate mode) and lack of a cursor on the COM-2 has not been a problem.