Tiny BASIC guide

OrbitDeck for iOS includes a self-contained Tiny BASIC interpreter (Operating Tools → Tiny BASIC). It is source-compatible with the BASIC on the OrbitDeck desktop app and CardSat, and adds live satellite, station, pass, space-weather and geomagnetic data as read-only variables, a 240 × 135 graphics display, and a sandboxed file store. This guide documents the full dialect as implemented in the app.

The workspace

The Tiny BASIC screen has two panes — a program editor and a graphics display — side by side on a wide iPad and stacked on iPhone.

  • Program — a monospaced editor. Type or paste your program here.
  • Run — executes the program from the top. Text output appears in the Output box and drawing appears on the Display.
  • Clear — empties the Output box and the Display (it does not change your program).
  • Actions menu — Open file… loads a .txt program from the Files app, Load sample restores the built-in demo, and Share source exports your program text via the iOS share sheet.
  • Output — everything PRINT produces, selectable for copying. A status line below reports how many statements ran and how many graphics calls were made, or the error if one occurred.
  • Display · 240 × 135 — the graphics surface (see Graphics).
  • INPUT values — if your program uses INPUT, a panel appears listing each prompt so you can fill in the values before you press Run (see INPUT).
Errors are reported in the Output box beginning with ?, mirroring classic BASIC — for example ?divide by zero. The status line repeats the message.

Program structure

A program is a list of numbered lines, lowest number first:

10 PRINT "HELLO, ORBIT"
20 FOR I=1 TO 3
30 PRINT I
40 NEXT
50 END
  • Line numbers order the program and are the targets of GOTO, GOSUB, IF…THEN n and ON…GOTO.
  • Several statements per line may be separated by a colon : — for example 10 A=1: B=2: PRINT A+B.
  • Keywords are case-insensitive (print = PRINT). Variable and function names are treated as upper-case.
  • Comments use REM; everything to the end of the line is ignored. DATA lines are likewise skipped during normal execution and read only by READ.
  • Immediate mode — a program with no line numbers runs its statements top to bottom, but flow-control statements that need line targets (GOTO, GOSUB, RETURN, DATA, READ, RESTORE) require a numbered program and will report an error in immediate mode.
Because the colon splits a line into independent statements, only the statement immediately after THEN is guarded by an IF. In 10 IF X>0 THEN PRINT "POS" : PRINT "ALWAYS", the second PRINT runs regardless of X. Put conditional work on its own line or branch with THEN lineNumber.

Variables & arrays

Numeric variables

Numeric variables are a single letter AZ and hold double-precision floating-point values. Assignment may use LET or omit it:

10 LET A=3.5
20 B=A*2
30 PRINT B

String variables

String variables are a single letter followed by $A$Z$. Join strings with +:

10 N$="OSCAR"
20 PRINT N$ + "-100"

Arrays

Arrays are declared with DIM and are zero-basedDIM A(12) creates indices 011. Two kinds exist:

  • Named arrays share the letter namespace with functions but are separate from the same-letter scalar: DIM A(10) then A(3)=7. A scalar A and the array A(…) are independent.
  • The anonymous array @() — a single unnamed array: DIM @(6) then @(0)=2.
  • Clear a named array with ERASE name.

A named array may hold up to 1024 elements and the anonymous array up to 256, with a combined budget of 2048 elements across all arrays.

10 DIM A(12),@(6)
20 DATA 2,3,5,7,11,13
30 FOR I=0 TO 5: READ @(I): NEXT
40 A(0)=100
50 PRINT @(2), A(0)

Operators & expressions

Numeric operators, from lowest to highest precedence:

LevelOperatorsNotes
Logical ORORResult is 1 (true) or 0 (false)
Logical ANDAND1 or 0
Comparison= <> < > <= >=Return 1 or 0
Add / subtract+ -
Multiply / divide / modulo* / % MOD% and MOD are the same truncating remainder
Power^Right-associative
Unary- + NOTNOT yields 1 for a zero operand, else 0

Comparison and logical operators produce 1 for true and 0 for false, so they can be used directly in arithmetic. Parentheses group as usual. Dividing or taking a remainder by zero raises ?divide by zero.

Strings concatenate with + and compare with the same relational operators (=, <>, ordering by Unicode). A relation is treated as a string comparison when either side looks like a string (a literal in quotes or a $ variable/function).

Trigonometric functions work in degrees, not radians — SIN(30) is 0.5. Use the RAD and DEG constants to convert if you need radians.

Statements

StatementPurpose
LET v=exprAssign a value. LET is optional. Targets: scalars, A$Z$, A(i), @(i).
PRINT items · ?Print text and numbers. ? is shorthand. See below for separators.
LPRINT itemsLike PRINT but the line is prefixed with [LPRINT] (a stand-in for a printer).
INPUT v[,v…]Read values supplied in the INPUT panel before the run. Numeric or $ variables.
IF cond THEN If the condition is non-zero, run the statement after THEN; if THEN is followed by a bare line number, jump there.
FOR v=a TO b [STEP s]NEXTCounted loop; default step 1. Negative steps count down.
GOTO nJump to line n.
GOSUB nRETURNCall a subroutine and return to the following statement.
ON expr GOTO n1,n2,…Jump to the expr-th line number (1-based); out-of-range falls through.
DIM name(n) · DIM @(n)Declare arrays. Multiple declarations may be comma-separated.
ERASE nameDiscard a named array.
DATA v1,v2,…Inline numeric constants read by READ.
READ v[,v…]Read the next DATA value(s) into variables or array elements.
RESTORERewind the DATA pointer to the beginning.
REM textComment to end of line.
END · STOPEnd the program.
CLS PSET LINE CIRCLE TEXT SHOWGraphics — see Graphics.
FOPEN FPRINT FCLOSE FILESSandboxed files — see Files.
SATSEL i · TXSEL iChoose a satellite / transponder for the live variables — see below.

PRINT formatting

Separate PRINT items with commas or semicolons:

  • Comma inserts two spaces between items (a light column effect).
  • Semicolon joins items with no space.
  • A trailing comma or semicolon suppresses the line break, so the next PRINT continues the same line. A PRINT with no arguments flushes the pending line.
  • Whole numbers print without a decimal point; other values use a compact general format.
10 A=42: N$="ISS"
20 PRINT "SAT ", N$, "CODE"; A

produces SAT ISS CODE42.

INPUT

OrbitDeck collects INPUT values before the program runs rather than pausing mid-run. When your program contains INPUT statements, an INPUT values panel lists each prompt (its label text and the target variable); fill them in, then press Run. Values are consumed in order. A missing numeric value is 0; a missing string is empty.

10 INPUT "YOUR ALTITUDE KM"; A
20 INPUT "CALLSIGN"; C$
30 PRINT C$ + " AT " ; A ; " KM"

Functions

Numeric functions

FunctionReturns
ABS(x)Absolute value
INT(x)Floor (largest integer ≤ x)
ROUND(x)Nearest integer
FRAC(x)Fractional part
SGN(x)−1, 0, or 1
SQR(x)Square root (of max(0, x))
EXP(x), LOG(x), LOG10(x)Exponential and natural / base-10 logs
SIN(x), COS(x), TAN(x)Trig, argument in degrees
ASN(x), ACS(x), ATN(x)Inverse trig, result in degrees
ATN2(y,x)Two-argument arctangent, degrees 0…360 range via atan2
MIN(a,b), MAX(a,b), HYP(a,b)Minimum, maximum, hypotenuse
RND · RND(n)Random 0…1; with an argument, a random integer 0…n−1

String functions

FunctionReturns
LEFT$(s,n), RIGHT$(s,n)First / last n characters
MID$(s,start[,len])Substring from 1-based start, optional length
CHR$(n)Character for byte value n
STR$(x)Number formatted as text
UCASE$(s), LCASE$(s), TRIM$(s)Upper / lower case, trim whitespace
GRID$(lat,lon)Four-character Maidenhead locator
DXCC$(code)Name of the DXCC entity for an ARRL numeric code
TIME$, DATE$Current UTC HH:MM:SS and YYYY-MM-DD

String-to-number functions

FunctionReturns
LEN(s)Character count
ASC(s)Byte value of the first character
VAL(s)Number parsed from text (0 if none)
INSTR(hay,needle)1-based position of needle in hay, or 0

Geo & RF helpers

FunctionReturns
GCDIST(lat1,lon1,lat2,lon2)Great-circle distance in km
GCAZ(lat1,lon1,lat2,lon2)Initial great-circle bearing in degrees
FSPL(freqMHz,distKm)Free-space path loss in dB
DXCCLAT(code), DXCCLON(code)Reference latitude / longitude for a DXCC entity
PASSAOS(k), PASSLOS(k), PASSMAX(k)For the k-th upcoming pass of the selected satellite: minutes to AOS, minutes to LOS, and maximum elevation (degrees). Index 1…PASSN.

Constants

NameValue
PIπ
TWOPI
DEGDegrees per radian (180/π)
RADRadians per degree (π/180)
CLIGHTSpeed of light, 299 792 458 m/s
KBOLTBoltzmann constant, 1.380649×10−23
REARTHEarth radius, 6378.137 km

Live data variables

The interpreter exposes OrbitDeck's live state as read-only numeric variables. They are populated from your station, the selected satellite, the current pass prediction, the Sun and Moon, space weather, and a planning-grade geomagnetic model at run time. Many "OK" flags are 1 when the corresponding data is available and 0 otherwise, so you can guard on them.

Time (UTC)

VariableMeaning
UTCH UTCM UTCSHour, minute, second
UTCDAY UTCMON UTCYRDay, month, year
LSTHRLocal sidereal time, hours
TIMEOK1 when the clock is set (also gates TIME$/DATE$)

Station

VariableMeaning
MYLAT MYLON MYALTObserver latitude, longitude, altitude (m)
MAGDECLApproximate magnetic declination (degrees, east positive)
NSAT NFAVCatalog size and number of favorites
POSOK1 when the station position is known

Selected satellite

VariableMeaning
SATAZ SATELAzimuth and elevation (degrees)
SATRNG SATRRSlant range (km) and range rate (km/s)
SATLAT SATLON SATALTSub-point latitude, longitude, altitude (km)
SATSUN1 if the satellite is sunlit
SATINC SATECC SATRAAN SATMMInclination, eccentricity, RAAN, mean motion
SATNORNORAD catalog number
GPAGEElement-set age in days
DECAYD DECAYSRCEstimated decay lifetime (days) and its source (1 n-dot, 2 B*)
SATOK1 when satellite look angles are valid

Next pass

VariableMeaning
AOSIN LOSINMinutes to AOS / LOS of the next pass
PASSELMaximum elevation of the next pass (degrees)
PASSVIS1 if the next pass is optically visible (satellite sunlit, Sun below −6°)
PASSNNumber of upcoming passes found (up to 8)
PASSOK1 when a pass was found

Use PASSAOS(k), PASSLOS(k) and PASSMAX(k) to read individual passes 1…PASSN.

Sun & Moon

VariableMeaning
SUNAZ SUNELSun azimuth and elevation (degrees)
MOONAZ MOONELMoon azimuth and elevation (degrees)

Space weather

VariableMeaning
SFI10.7 cm solar flux
SSNSunspot number
KP AINDEXPlanetary Kp and A index
MUFModeled daytime MUF
SPWXOK1 when space-weather values are available

Transponder (after TXSEL)

VariableMeaning
NTXNumber of transponders on the satellite
TXDL TXUL TXBWDownlink center, uplink center, bandwidth (Hz)
TXINV TXLIN1 if inverting / linear
DOPPRX DOPPTXDoppler-corrected downlink / uplink dial frequencies (Hz)
TXOK1 when a transponder is selected

Geomagnetic (planning-grade dipole)

VariableMeaning
LSHELLMcIlwain L-shell at the sub-point
BFIELD BRATIOField magnitude (nT) and B/B0 ratio
INBELT INSAA1 inside a radiation belt / South Atlantic Anomaly
Several host variables are defined for source-compatibility with CardSat firmware (for example GPS, battery, heap and additional space-weather fields such as FLARE, BZ, SWSPEED). On iOS these read 0 unless OrbitDeck has a value for them; guard on the matching "OK" flag where one exists. The geomagnetic figures use the same centered-dipole model as Orbital Zones, not a full IGRF model.

Selecting satellites & transponders

By default the live variables describe OrbitDeck's currently selected satellite. Inside a program you can switch context:

  • SATSEL i — select catalog index i (0-based) and refresh all SAT…, pass and geomagnetic variables, plus the PASSAOS/PASSLOS/PASSMAX tables. It clears any transponder selection.
  • TXSEL i — select transponder index i (0-based) on the current satellite and populate TX… and DOPPRX/DOPPTX.
10 REM Report the next pass of catalog entry 0
20 SATSEL 0
30 IF PASSOK=0 THEN 60
40 PRINT "SAT ", SATNOR, " NEXT AOS ", ROUND(AOSIN), " MIN, MAX EL ", ROUND(PASSEL)
50 END
60 PRINT "NO PASS FOUND"

Graphics & display

The display is 240 × 135 pixels; (0,0) is the top-left corner. Colors are an index 0…9 into the palette:

IndexColorIndexColor
0Black5Yellow
1White6Teal
2Red7Orange
3Green8Gray
4Blue9Dark green
StatementEffect
CLSClear the display to black
PSET x,y[,c]Plot a point (color defaults to 1)
LINE x1,y1,x2,y2[,c]Draw a line
CIRCLE x,y,r[,c]Draw a circle outline
TEXT x,y,valueDraw text (a string or a number) at x,y
SHOWMarker to present the frame (drawing is shown after the run regardless)

Files & storage

Programs can write small text files, confined to OrbitDeck's private Application Support/OrbitDeck/Basic directory. Programs cannot supply paths or escape that sandbox.

StatementEffect
FOPEN "name"Open (creating if needed) a file for appending
FPRINT itemsAppend a line to the open file (same item rules as PRINT)
FCLOSEClose the open file
FILESPrint the list of files in the sandbox

File names may be up to 40 characters of letters, digits and _ . -; they may not start with a dot or contain a slash.

Limits & safety

Execution is bounded so a runaway program cannot hang the app:

LimitValue
Statements per run2,000,000 (then too many statements)
Wall-clock time~10 seconds (then program ran too long)
Nested FOR loops8
GOSUB depth16
Total array elements2048 (named ≤ 1024, anonymous ≤ 256)

Division or modulo by zero, out-of-range array indices, RETURN without GOSUB, NEXT without FOR, and unknown names all raise a descriptive ? error.

Worked examples

The built-in sample

The Load sample action loads this program, which exercises arrays, DATA/READ, graphics and live variables:

10 REM OrbitDeck Tiny BASIC
20 DIM A(12),@(6)
30 DATA 2,3,5,7,11,13
40 FOR I=0 TO 5: READ @(I): NEXT
50 CLS
60 FOR I=0 TO 11
70 A(I)=50+20*SIN(I*30)
80 LINE 120,67,120+95*COS(I*30),67+A(I)*SIN(I*30),3
90 NEXT
100 CIRCLE 120,67,30,5
110 TEXT 70,4,"ORBITDECK BASIC"
120 PRINT "MY GRID DATA: LAT=",MYLAT," LON=",MYLON
130 IF SATOK=0 THEN 160
140 PRINT "SAT ",SATNOR," AZ=",ROUND(SATAZ)," EL=",ROUND(SATEL)
150 PRINT "NEXT AOS IN ",ROUND(AOSIN)," MIN"
160 SHOW
170 END

A pass table for the selected satellite

10 IF PASSOK=0 THEN 70
20 PRINT "PASS  AOS(MIN)  LOS(MIN)  MAXEL"
30 FOR K=1 TO PASSN
40 PRINT K, ROUND(PASSAOS(K)), ROUND(PASSLOS(K)), ROUND(PASSMAX(K))
50 NEXT
60 END
70 PRINT "NO PASSES IN THE WINDOW"

Great-circle distance to a DXCC entity

10 REM 291 = United States reference point
20 D=GCDIST(MYLAT,MYLON,DXCCLAT(291),DXCCLON(291))
30 B=GCAZ(MYLAT,MYLON,DXCCLAT(291),DXCCLON(291))
40 PRINT DXCC$(291)
50 PRINT "RANGE ", ROUND(D), " KM  BEARING ", ROUND(B), " DEG"

Logging to a file

10 FOPEN "log.txt"
20 FPRINT DATE$, " ", TIME$, " SFI=", SFI, " KP=", KP
30 FCLOSE
40 FILES

Compatibility notes

This interpreter is designed to run the same programs as the OrbitDeck desktop app and CardSat. A few platform notes:

  • INPUT is collected up front through the INPUT panel rather than pausing execution.
  • PASSAOS/PASSLOS/PASSMAX accept indices 1…PASSN; index 0 is accepted as an alias for the first pass for compatibility with early program versions.
  • Host variables that OrbitDeck cannot supply on iOS (some CardSat hardware telemetry) read 0; check the relevant "OK" flag.
  • The geomagnetic variables use OrbitDeck's centered-dipole planning model, not CardSat's IGRF precision.

Share your programs with Actions → Share source, and reopen saved .txt programs with Actions → Open file….