Projects, files, and local storage
Save your workspace in Projects for local storage. Export a backup to keep elsewhere.
Cortex BASIC reference · language features and browser requirements.
Git
Clone a GitHub repository or connect the current project. Review changes, commit locally, then push when ready.
Use a GitHub token scoped to your repository: Contents read for private cloning; Contents write for pushing and creating branches. Public cloning works without a token.
Git requests go directly from this browser to GitHub. Cortex servers do not receive your GitHub token.
A home for source and assets
A Cortex project can contain several BASIC files and related assets. The native reference recommends this layout:
MyProject/
Main.bas
Source/
Lib/
Images/
Documents/
Data/
Sounds/
Video/
Exports/One BASIC file is the startup program. Paths are project-relative and must stay inside the project sandbox.
More than one BASIC file
Shared source is available with a standalone '$INCLUDE: 'Lib/Shared.bas' comment. The included BASIC file can declare SUB, FUNCTION, TYPE and CONST definitions, and can include other project files. Run snapshots current project drafts; edits made during a run take effect on the next run. RUN "Source/Menu.bas" replaces the current program with fresh variables; CHAIN "Source/Game.bas" preserves values declared in unnamed COMMON blocks, matched by order and type. Neither returns to the calling program. COMMON SHARED also exposes those variables to procedures. Paths start at the project root; explicit ./ or ../ paths resolve relative to the current file and cannot escape the project. Include cycles, missing files and transfer limits report located errors. Include files currently use the project's .bas format; native executable chaining is unsupported.
Compatibility Lab and LIST
The developer regression suite includes Compatibility Lab. Ten checks written in BASIC exercise numeric rounding, procedure calls, recursion, strings, arrays, records, error recovery and sequential/random/binary files. Expect Passed: 10 and Failed: 0. The project also includes 24 small application programs under Programs.
LOAD Programs/Primes.bas
LIST
RUNExpect Primes=25 Sum=1060. LIST shows the whole source selected for RUN as read-only text, including unsaved edits. It preserves existing source line numbers and wraps long lines. OPEN opens the source in Editor. The listing is not editable and does not execute the code.
card$="Cortex 0000"
MID$(card$,8)="2026"
PRINT card$MID$ assignment replaces characters without extending the string; it also works with array elements and record fields. The first corpus checks outputs, files and located errors. Unsupported DOS operations report explicit errors. Only the isolated keyboard-flags byte is supported by PEEK/POKE. The separate Game Lab and Gorillas projects exercise graphics, sound and games; full release conformance remains in progress.
Images, audio and video
Choose Projects → Media Studio → Run startup. Turn, Fade and Crop transform an original landscape. Save picture writes Images/Postcard.png in your local project. Sound and Video use project assets. The BASIC sample explicitly requests players with AUDIO CONTROLS and VIDEO CONTROLS; tap their Play control if your browser requires it. Loading media alone adds no controls. Exit or Stop releases playback.
SCREEN 12
h&=LOADIMAGE("Images/Landscape.png")
DRAWIMAGE h&,20,60,200,120,30,.5
SAVEIMAGE "Images/Output.png"
FREEIMAGE h&IMAGEWIDTH(h&) and IMAGEHEIGHT(h&) return dimensions. DRAWIMAGE accepts x,y, optional width,height, optional clockwise degrees,opacity (0–1), then optional cropX,cropY,cropWidth,cropHeight. SAVEIMAGE exports the composited active screen as PNG/JPEG/WebP; an optional second handle exports the loaded image. PNG/JPEG/WebP and GIF first frame use the browser decoder; HEIC/AVIF work only where decoding is supported. Invalid images report error 1001. Images are bounded to four million pixels each. FREEIMAGE releases a handle.
a&=LOADAUDIO("Audio/Chime.wav")
AUDIO PLAY a&
AUDIO PAUSE a&
AUDIO VOLUME a&,.5
AUDIO STOP a&
AUDIO FREE a&LOADVIDEO and VIDEO provide the same controls. MEDIASTATE$(handle) reports playback state. Local assets and same-origin HTTPS media are supported; cross-origin networking remains planned. Unsupported codecs report error 1002, blocked playback 1003. Classic POINT/GET continue to read indexed graphics, while SAVEIMAGE includes modern true-color images.
Select VoiceRecorder.bas in Editor to try recording. AUDIOFORMAT$() and AUDIOEXT$() report the supported recording type and extension. AUDIO RECORD path$ requests microphone permission; AUDIO RECORDSTOP saves the result. Recording requires HTTPS or localhost and browser permission. An insecure HTTP connection reports error 1005; denial reports 1004. Hiding the app interrupts recording (1006); Stop, a new Editor run and completion release microphone/media resources. Existing saved copies retain their source. HELP IMAGE and HELP MEDIA summarize the API.
Rooftop Rivals and Game Lab
Choose Projects → Rooftop Rivals for an original two-player robot rooftop duel. Tap Play, enter optional names, then choose points to win. Each turn, set angle (0–90) and power (1–140); Enter accepts the displayed default. Wind changes the arc, impacts reshape roofs, and the first robot to the target score wins. Mute and Exit come from its editable BASIC source.
Choose Projects → Game Lab → Run startup for Paddle Ball, Star Flight, Pocket Piano or Orbit Plot. Enter 1–4 and use the BASIC-created controls or your keyboard. Finish returns to the command line.
Gorillas starts GorillaPlay.bas, an attributed presentation copy of the Microsoft sample with a still title and one setup question at a time. Continue, enter player names, rounds and gravity in the Terminal field, then tap Play. The numeric keypad appears during gameplay. GORILLA.BAS is included separately as the unchanged benchmark. Use the keypad digits and Enter for angle and velocity; Backspace corrects a digit. The IDE Stop remains available. Select GORILLA.BAS in Editor to run the original directly with your keyboard.
All gameplay, drawing, sound and touch bindings run from BASIC source. WIDTH text screens and VIEW PRINT support classic cursor redraws; sprites use classic bit-plane layouts. Imported examples create new saved projects and leave existing source intact.
Sound and game keys
Choose Projects → Sound and Keys → Run startup to import a fresh copy. Saved copies retain their source. Hear a melody and use the BASIC-created arrow buttons or external arrows/WASD to move the yellow square. Space beeps; Esc / Stop finishes. The BASIC source declares every button, handles mute state and clears controls on exit. Touch buttons supply INKEY$ values without opening the phone keyboard.
UI BUTTON "left", "←"
UI SET "left", "KEY", CHR$(0)+CHR$(75)
UI SET "left", "REPEAT", -1
SLEEP
k$=INKEY$
PRINT ASC(RIGHT$(k$,1))
UI CLEARUI BUTTON and UI LABEL create controls. UI SET changes TEXT, VISIBLE and ENABLED; buttons also support KEY and REPEAT. UI REMOVE removes one control and UI CLEAR removes all. IDs are case-insensitive; up to 64 controls. More controls, dialogs and callbacks remain planned. The interpreter adds no sound panel or game keyboard. The example starts with sound on. Disable sound / Enable sound and Mute / Unmute toggle the same BASIC variable and update both captions. Turning sound off calls SOUND 0,0 and prevents later tones; Enable sound plays a BASIC melody.
BEEP plays a short tone. SOUND takes hertz and duration in 18.2 ticks per second. PLAY supports A–G notes, sharps/flats, O0–6, L1–64, T32–255, N0–84, rests, dots, octave shifts, articulation and MB/MF background/foreground music. PLAY(0) reports pending notes. Browser timing is approximate.
INKEY$ returns an empty string, a Latin-1 character or NUL plus a scan code for extended keys. INPUT$(count) reads keyboard characters; its file form is unchanged. SLEEP waits for seconds or a key and preserves the wake key. External keys remain available. The existing Terminal field also accepts phone typing immediately during key input and returns to the REPL on completion. Polling never opens/closes the software keyboard. Editor typing and ordinary INPUT retain their normal behavior.
Run and BASIC button gestures attempt to resume audio. Missing or blocked audio leaves execution available without injecting controls. Stop/restart and leaving the app silence active notes. Device volume, audio routing and browser/OS shortcuts still apply. PLAY pointer macros, chords, volume extensions, event traps and raw DOS hardware input are unavailable. Full corpus compatibility remains in progress.
Draw with classic BASIC
Choose Projects → Graphics, then Run startup. The image appears above Terminal text and remains available in More → Runtime → Graphics and the wide Editor Runtime pane. It scales to your screen without changing BASIC coordinates.
SCREEN 12
LINE (20,20)-(200,150), 11, B
CIRCLE (320,200), 80, 14
PAINT (320,200), 4, 14
COLOR 15
LOCATE 2, 4
PRINT "Hello, graphics"SCREEN 1, 2 and 7–13 use their classic logical dimensions and indexed colors; SCREEN 0 returns to text. PSET/PRESET, POINT, LINE B/BF and line styles, CIRCLE arcs/aspect, solid PAINT, DRAW movement strings, VIEW/WINDOW, PMAP, PALETTE/USING, PCOPY and graphics GET/PUT are available. GET/PUT use one-dimensional INTEGER or LONG arrays and PSET/PRESET/AND/OR/XOR actions; XOR is the default. Array image data uses a bounded Web raster layout, not native planar video-memory bytes. Graphics and file GET/PUT are distinguished by their coordinate or file-handle syntax.
Stop ends drawing and leaves the last delivered image visible. A new Editor run starts fresh. Immediate Terminal graphics commands share the current screen. Text uses a basic Latin bitmap font; extended glyphs render as ?. Hardware video memory, blinking, tiled PAINT and DRAW VARPTR$ macros are unavailable. Sound and game input are available below.
Read and write BASIC data files
In a saved project, BASIC can read and write files in INPUT, OUTPUT, APPEND, RANDOM and BINARY modes. Data appears in Projects and is included in project backups. Each completed write saves locally. Stop closes handles and keeps completed writes. Unsaved workspaces use temporary files until the runtime is restarted; save a project first for durable files.
OPEN "Data/Score.txt" FOR OUTPUT AS #1
WRITE #1, "Nate", 1700
CLOSE #1
OPEN "Data/Score.txt" FOR INPUT AS #1
INPUT #1, player$, score%
PRINT player$; " scored "; score%
CLOSEUse PRINT # or WRITE # to write text; INPUT # and LINE INPUT # read it. FREEFILE finds a handle; EOF, LOF, LOC and SEEK inspect positions. RANDOM uses fixed records with GET/PUT, TYPE variables or FIELD with LSET/RSET. BINARY uses one-based byte positions and GET/PUT or INPUT$. MKI$/MKL$/MKS$/MKD$ and CVI/CVL/CVS/CVD convert numeric bytes. FILEATTR(n,1) reports the mode.
Paths start at project root; CHDIR changes the BASIC file directory. MKDIR, RMDIR, NAME and KILL manage data. FILES lists data; FILES/KILL accept filename wildcards within one folder. BASIC source files can be read but are protected against modification. No OS paths or network files are opened. Strings store bytes 0–255, text output uses CRLF, and typed numbers use little-endian integer or IEEE floating-point bytes. For GET into a variable string, initialize its desired length with SPACE$. Projects keep their 25 MB / 200-entry limits. Missing files, EOF, mode, storage and conflict errors support ON ERROR. DOS devices, native OS handles and shared cross-process record locking are unavailable; local LOCK/UNLOCK ranges are tracked within this runtime.
Local work comes first
Open Projects → Save workspace as project to keep your current drafts, or New project for a blank Main.bas and the default folders. Edits autosave in this browser on this device without an account. Open a saved project from On this device. Use Manage beside a file or folder to rename, move or delete it; mark a BASIC file as startup and use Run startup. Import files accepts .bas source and binary assets. If storage fails, your edits stay in memory: export a backup, free space, then Retry save. Changes from another tab require reopening the saved version or saving a separate copy. Clearing website data removes projects; private browsing may be temporary. Request persistent storage is optional and the browser decides whether to grant it. Open More → Offline & updates and wait for Ready to reopen offline before disconnecting. The editor, BASIC runtime, examples and searchable guides can then reopen without a connection. AI, Git sync and network services still need a connection. Updates wait until all Cortex tabs are closed; save your work first. Repair offline copy restores downloaded app files without deleting projects.
A portable project format
Export backup downloads a versioned .cortex package containing source, assets, empty folders and the startup path. Export JSON backup retains the older .cortex-web.json format. Share backup prepares the package and then asks for another Share backup tap to open the system share sheet; unsupported file sharing downloads it. Import project backup creates a separate project without overwriting existing work; older Cortex draft JSON bundles are accepted. Projects are limited to 25 MB, 200 files/folders and 40 BASIC files (200,000 characters each; 1,000,000 total source characters). The Web package format is implemented and independently checked with a Python ZIP reader/writer. Native application interoperability awaits native support for that format. Imports validate bounded archives, reject unsafe paths and create a separate project without running it. Processing can be cancelled. IDE credentials are excluded. Download example .cortex in Projects provides a complete BASIC sample package.