Android

From x11-basic

Jump to: navigation, search
Start screen of the Android User Interface of X11-Basic

Contents

[hide]

The Android version of X11-Basic

The Android version of X11-Basic comes as a regular app and can be downloaded from the Android Market. In contrast to the other versions of X11-Basic, the interpreter and virtal machine is embedded in a little IDE which allows the user to load, run, edit and compile the programs. Also a text console needed to be added, which handles the stdout. The stdin was implemented to take the keyboard actions of the device.

The idea is to have a simple user interface after startup, to allow for single line commands to be entered and excecuted, as well as to load and run .bas programs. Also the excecution of the faster bytecode (ending .b) should be possible.

Your programs have to deal with multiple different screen sizes. For console programs you can use the ROWS and COLS system variables to ask for the size of the textscreen (Example: console-clock.bas). The screen dimensions of the graphics screen can be retreived with the GET_GEOMETRY command (Example: kugel.bas).

Be careful with the use of the QUIT command: QUIT will really finish the app, so one cannot read the console output anymore (this is unlike the console stdout on standard UNIX systems.). Better use END.

Usage

Android deviced usually have a BACK Butten, a HOME button and a MENU Button.

  • The HOME Button suspends X11-Basic and returns to the Android desktop. Selecting the X11-Basic app again will resume it.
  • With the BACK button, a running BASIC program will be stopped. If you press the back button again, the X11-Basic interpreter quits.
  • The MENU Button opens a menu with following options: About, LOAD Program, RUN program, STOP/CONT program, NEW, Keyboard, Paste from Clipboard, Info/Settings, Editor, Compile, Help and Quit.
    • About: Show information about the current version of X11-Basic, news and an impressum.
    • Load ... opens a fileselector which displays all .bas and all .b programs in the directory /mnt/sdcard/bas. The selected program will be loaded into memory. A program eventiually stored there before will be overwritten. You can display the sourcecode by entering LIST.
    • Run will simply start the excecution of a program which has been loaded before. (You can also enter RUN)
    • STOP/CONT will interrupt the excecution of the program or resume it. (You can also press the BACK button once to stop the program, and you can enter CONT to continue it).
    • New will delete the program from memory (same as typing NEW at the command line).
    • Keyboard will show or hide the on-screen virtual keyboard. If you have a hardware or external USB/bluetooth keyboard, you can also enter commands with that.
    • Paste from Clipboard will paste any text you have copied to the clipboard (from any other application) before.
    • Info/Settings will open a dialog with additional information, links, and preference settings.
      • Show Splash Screen at X11-Basic startup. This can be switched off here
      • Select Font size. If the screen is small but the resolution is high, you want to change the font size to LARGE. This setting affects the console font (text mode) as well as the graphics/user-Interface.
    • Editor will excecute a 3rd party text editor app (e.g. Ted if installed) to edit the program currently loaded. If no program was loaded, the default file name will be new.bas.
    • Compile will compile the basic source code into bytecode which can be excecuted about 20 times faster. The bytecode will be saved with .b extension in the bas/ folder.
    • Help will open a window in which you can search the command reference.
    • Quit will terminate the X11-Basic interpreter.

Editing a program

Press Menu --> More to get this extended menu.
Press Menu --> More --> Editor to run your favorite text editor.
  1. Load an existing program with Menu --> Load
  2. Choose Menu --> Editor to edit the program
  3. finish editing (and save it in the editor)
  4. Program gets automatically reload
  5. choose menu --> run to run it

Installing a text editor

If you get this error message, you need to install a text editor app.

If you get an error when calling the text editor, you need to install one. There are plenty around, e.g. 920 Text Editor or Ted (tiny text editor). Install them from the market. You can install multiple editors. Then you are asked which one you like to use, every time you call the editor.

LOAD file select functions

Press menu --> load to get this file list.

To load a program, press menu --> load. You can now select a program file (either .bas or .b) to load. If you touch the filename long you get another menu with advanced functions:

Press menu --> load and longtouch a file, then you get this extra options.
  • LOAD -- load the program
  • MERGE -- merge the program to the one already loaded (works only with .bas files)
  • LOAD + RUN -- load the program and immediately run it
  • LOAD + LIST -- load the program an list it
  • LOAD + edit -- load the program and immediately start the editor
  • LOAD + compile -- load the program and compile it
  • compile + RUN -- compile the program and immediately run the compiled program
  • delete -- delete the selected file (you will be asked to confirm)
  • CANCEL -- return to the file menu

These functions are here for convinience only. You probably want to use LOAD+RUN or compile+RUN more often.

Desktop shortcuts

You can create desktop shortcuts to your BASIC programs. You can easily place an application shortcut on the home screen by simply pressing anywhere (and hold for 1 second) on the background of the desktop screen (On Android 4.x devices go to Apps-->Widgets).
The X11-Basic create shortcut widget
You first are asked to place the shortcut somewhere on the desktop. The X11-Basic launcher then asks for a .bas or .b file and places the link on the desktop. Pressing this link will automatically load X11-Basic and the .bas program and run it.

Configuring X11-Basic

With the font size settings (Menu --> More --> Info/Settings --> Select font size) you can adjust the size of the characters of the text screen output.

There is really not much to configure. If you do not like the splash text which appears after starting the X11-Basic interpreter, you can switch it off (Menu --> More --> Info/Settings --> Splash screen). And you can specify a font size, in case the characters if the text screen appear to be too tiny to read. By default, X11-Basic trys to automatically set a readable font depending of your display resolution.

Sensors

You can get the values from the devices Sensors with new SENSOR commands. See sensortest.bas.

 SENSOR ON
 PRINT SENSOR(0)

GPS Service

 GPS ON
 print GPS_LAT,GPS_LON,GPS_ALT
 GET_LOCATION

Sound

X11-Basic supports sound, soundfile playback and tone generation. Also the text-to-speach feature of Android devices is supported. You can use the following commands:

 
PLAYSOUNDFILE   -- playback a sound file, like .mp3 or .ogg
SPEAK	        -- speak out a text. The language and different voices can be selected
SOUND	        -- generate a sound 
WAVE	        -- program the sound synthesizer and sounc channel mixer

Text-Console

X11-Basic on Android implements a full featured coloured VT100/ANSI Terminal emulation for text output (e.g. with PRINT). It implements five different font sizes (5x7, 8x16, 16x32, 24x48 and 32x64) and a changeable 8x16 bit graphics font. It uses the ESC-[-...-z extension which you may know from vt100emu.30c on ATARI ST, TTconsole on the Tomtom devices and other terminal emulation implementations.

There is no distinction between the text console and the graphics screen. Text and graphics are drawn to the same framebuffer. Unlike the text size of the graphics commands (e.g. TEXT), the console font size can be changed only by user settings.

Shell access

With the commands SYSTEM, SYSTEM$() and SHELL you can access all native linux tools and make them part of your basic program. With SHELL you can also start a shell session and use the X11-Basic console to enter UNIX commands. Do a

 shell "/system/bin/sh"

It appears, that on unrooted Android devices the internal shell has only a limited functionallity. However, this can be extended by installing additionally ARM binary files in the /data/local/ directories. This way, a busybox can be used or any other (text mode/console) application. E.g. pico or nano are known to work, unproven yet but very likely: pine and mc (midnight commander). Simply try it out and let us know.

Benchmarking

You can run a benchmark-Program (Whets.bas) to see, how fast the programs get excecuted. On a Tablet PC I get 0.8 MWIPS (for interpreted bas file) and 17 MWIPS (for the compiled .b version). On my Pencium 3GHz I get 2 MWIPS and 60 MWIPS.

It also was reported that bytecode compiled X11Basic programs run 40 times faster than similar ones implemented in another free popular basic interpreter for Android. Speed is really one of X11-Basics strengths!

Internet connections

X11-Basic programs can connect to UDP and/or TCP/IP sockets anywhere on the network and as well can open a socket on the device to run a program as a server. A good example on how to make UDP connections from one device to another is given with udp_send.bas and udp_receive.bas.

For an example of how to program a TCP/IP server, see iserver.bas. It opens a socket on a port, waits for connections and serves the clients on a ASCII command based protocol.

Getting Online Help on syntax

getting a verbose help and description of each command in X11-Basic (Menu --> More --> Help).

The X11-basic app has a builtin (offline) help on all commands and functions (Menu --> More --> Help). If you need information on a specific keyword, try to type in the word (first letter is enough) into the search field.

Examples of working programs

Following is a list of example Programs, which do already work nearly perfect on Android:

Updates of example programs

Hint: X11-Basic App comes with a small selection of example programs. They are copied into the /bas/ directory. The X11-Basic app will never overwrite a file in bas/ which is already there. If you want a specific example program be updated (replaced with a potentially newer version, which has come with an update of the X11-Basic app), simply delete the file. It will be restored after the next excecution of X11-basic.

Bugs

  • GET_LOCATION is not working on every device
  • Screen-refresh is not working on some SAMSUNG tablets.
  • Crashes soimtimes right after start of the app on SAMSUNG devices.
  • Syntax checking should be done in PROCEDURE and FUNCTION definitions.
  • crash in FILESELECT with title
  • we see sometimes a crash when the device is turned by 90 degrees while a program is still running.
  • EXEC on android intents does not take the extra arguments.
  • crash after pasting something from the clipboard.
  • add some more here

Please also read the compatibility issues.