isbas BASIC help

"isbas" is derived from "ippleSoft BASIC", an AppleSoft-compatible BASIC interpreter which runs on the iPhone's web browser. The original source (alternate location) is available under GPL v2. This version has been modified to operate on the Sony COM-2 "mylo" communicator.

Changes from the original version include...

The COM-2 does not issue key events for space and backspace via the usual onkeydown and onkeypress events, these are defined and work fine in Firefox, Mozilla etc but aliases have been defined for the COM-2 to permit using the back arrow for backspace and the forward arrow for space.

Statements

:
Separates multiple statements on the same line.
REM
Indicates a REMark, or comment. Any remaining text on the line is not executed.
NEW
Erases the current program and clears all variables
CLEAR
Resets all variables.
LIST
Displays the entire current program.
LIST lineno
Displays the line at lineno.
LIST start-end
Displays the lines from start to end.
RUN
Executes the current program.
LET A=expr
Stores the value of expr in A. LET is optional.
GOTO lineno
Branch to line lineno.
IF expr THEN s1:s2:s3
Executes statements s1:s2:s3 if expr is true.
FOR v=x TO y STEP z
Loop across all values of v from x to y, incrementing by z. If STEP is omitted, 1 is used.
NEXT
Repeats last loop.
NEXT x
Repeats last loop for variable x.
GOSUB lineno
Branch to subroutine at line lineno.
RETURN
Returns to point of call from a subroutine.
POP
Removes one address from the return stack.
RESUME
Re-executes statement causing an error.
STOP
Halts program and prints line number.
CONT
Resumes program execution.
END
Halts program execution.
HOME
Clears the screen.
PRINT expr
Prints strings and/or mathematical expressions, use ; to separate strings or suppress newline.
INPUT A
Sets a variable to an entered number or expression. If nothing entered 0 is assumed.
INPUT A$
Sets a string variable to an entered string. Quotes (") are not permitted.
GET A$
Captures a single keystroke into a string variable. If enter pressed sets to empty string.

Variables

AB
Real number in the range +/- 9.9999999 E+37
AB%
Integer in the range +/- 32767
AB$
String from 0 to 255 characters

Expressions

-
Subtraction
+
Addition or string concatenation
/
Division
*
Multiplication
^
Exponentiation
AND
Logical AND
OR
Logical OR
NOT
Logical NOT
=
Equal to
<>
Not equal to
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
ABS(x)
Absolute value of x
SGN(x)
Sign of x: -1 if x<0, 0 if x=0, 1 if x>0
INT(x)
Integer portion of x
SQR(x)
Square root of x
SIN(x)
Sine of x
COS(x)
Cosine of x
TAN(x)
Tangent of x
ATN(x)
Arctangent of x
EXP(x)
Euler's constant e to the xth power
LOG(x)
Natural logarithm of x
RND(x)
If x>0, random number between 0 and 1. If x=0, repeat last random number. If x<0, set new random seed.
FN A(x)
Executes function A previously defined by DEF FN.
LEN(A$)
Length of string A$
LEFT$(A$,x)
Leftmost x characters of string A$
MID$(A$,x,y)
y characters of string A$, beginning at position x
RIGHT$(A$,x)
Rightmost x characters of string A$
STR$(x)
String representing x
VAL(A$)
Numeric value of string A$
CHR$(x)
Character with ASCII code x
ASC(A$)
ASCII code of first character in string A$

File Commands

Programs can be saved and loaded from browser cookies, file size is limited to 4000 bytes after encoding. Due to the nature of cookies DO NOT TRUST them to be permanent! Some way needs to be devised to permit saving and loading files in a more permanent fashion but at the moment the only reliable way to do this is to edit the javascript source itself to replace the built-in program. Note that the COM-2 with the NetFront 3.4 browser is able to "run" an HTML app such as this with a .txt extension to permit editing using the built-in text editor, just manually specify the page in a form like file:///c/path/to/isbas.txt then bookmark it, or add a .html file that links to the .txt file.

CAT
          Lists available programs.
LOAD name
          Loads a program.
RUN name
          Loads and runs a program.
SAVE name
          Saves a program.
DELETE name
          Deletes a program.
RENAME name,newname
          Renames a program.
INIT
          Erases all stored programs.

Other Notes

INPUT and GET were added by me to get by but they are not proper implementations. INPUT cannot print prompt text, use a PRINT before it to print the prompt. INPUT and GET must be the last statements on a line, additional statements afterwards will be ignored due to the way they work - they halt execution then set the requested variables in immediate mode then continue running the program. Best I can figure out at the moment but they're much better than having to enter data by setting variables in immediate mode. Also required no modification to the interpreter code itself other than adding code for the commands, so was the least risky way to hook it in.

All numbers must begin with 0 to 9 or minus, not period. Enter numbers between 0 and 1 as 0.something.

To specify a number in scientific notation such as 1.5E-25, enter it as 1.5*10^(-25). Note that the exponent must be in parenthesis if fractional or negative.

DIM is not implemented. Starting code for it is present in the source but no idea how to finish it.

The screen elements have been formatted to fit the COM-2 screen with minimum text size set to 18 or less. To use bigger text or to format for other mobile devices adjust the rows and cols setting in the initial textarea html tag. Not sure how it works now on an iPhone, in particular if the key handlers will function in that environment.


iPhone is a registered trademark of Apple Inc.
"mylo" is a registered trademark of the Sony Corporation.
These notes last modified 5/19/08.