# Classic BASIC 1.3.1 — browser device extensions These are modern Classic BASIC extensions, not historical GW-BASIC commands. Use HTTPS (localhost is suitable for local QA). Hardware access is explicit and feature-detected. END, STOP, BREAK and errors release owned resources. ## GPS `GPS LAT,LON[,ALT,ACC,HDG,SPD,ALTACC,STAMP]` Reads one fresh location fix. ALT and ACC are metres; HDG is degrees clockwise from north; SPD is the device-reported speed in metres/second; ALTACC is metres; STAMP is Unix milliseconds. Missing speed/heading/altitude accuracy is -1; missing altitude is -999999. Requires location permission and HTTPS. No values are assigned on denial, timeout or BREAK. ```basic GPS A,B,C,D,E,F PRINT F*2.236936 ``` ## SCAN `SCAN CODE$[,FILE$]` Scans QR and common barcodes using the camera or a selected image. An optional filename scans a previously imported image. Camera needs permission and HTTPS; the bundled decoder also works without BarcodeDetector. Cancel or no code returns an empty string. Images stay on this device. The terminal offers Return for camera, I for an image file, or Q to cancel. During camera scanning, Return cancels. No camera buttons or modal are added. ```basic SCAN C$ PRINT C$ ``` ## FLASH `FLASH ON / FLASH OFF` Controls the actual camera torch. FLASHLIGHT is an alias. Requires HTTPS and camera permission; support is confirmed on the acquired camera track. OFF, END, STOP, BREAK, errors and backgrounding release the torch. In direct mode ON stays active until OFF or cleanup. There is no added off button or overlay. The FLASH demo waits at BASIC INPUT; pressing Return executes FLASH OFF. ```basic FLASH ON FLASH OFF ``` ## PHOTO `PHOTO P$ / PHOTO "PIC.JPG"` Captures a photo into a local session file. Returns the filename in P$, or uses the supplied name. EXPORT downloads it. Camera permission and HTTPS required. Cancel returns an empty P$; no file is created. Files are lost on reload or RESTART. Captures are JPEG, limited to 1600 pixels on the longest edge. Explicit capture filenames must end in .JPG or .JPEG. Press Return at the terminal prompt to capture, or type Q to cancel. The camera image appears in the terminal graphics area without added controls. ```basic PHOTO P$ EXPORT P$ ``` ## CAMERA `CAMERA P$[,"front"|"back"]` PHOTO with a choice of camera facing. Uses a filename/reference rather than a Cortex image handle. Same permission, cancellation and export behavior as PHOTO. ```basic CAMERA P$,"front" ``` ## PICKPHOTO `PICKPHOTO P$` Selects an existing image and saves a JPEG session copy; no camera access. Cancel returns an empty string. EXPORT downloads the result. ```basic PICKPHOTO P$ EXPORT P$ ``` ## ACCEL `ACCEL X,Y,Z` Reads one acceleration sample excluding gravity, in metres/second². ACCELEROMETER is an alias. Requires supported motion events, HTTPS and motion permission where prompted. Listeners stop after each reading, timeout or BREAK; unavailable components are never replaced with fake zeroes. ```basic ACCEL X,Y,Z PRINT X;Y;Z ``` ## GYRO `GYRO A,B,C` Reads rotation rates alpha/beta/gamma in degrees/second. GYROSCOPE is an alias. Same permission and cleanup rules as ACCEL. ```basic GYRO A,B,C ``` ## TILT `TILT A,B,C` Reads orientation alpha/beta/gamma in degrees (yaw 0–360, pitch -180–180, roll -90–90). MOTION is an alias. Relative alpha is not a compass. Requires supported orientation events and motion permission where prompted. ```basic TILT A,B,C ``` ## HEADING `HEADING H` Reads an absolute compass heading in degrees, 0 inclusive to 360 exclusive. COMPASS is an alias. Requires an absolute sensor reference and permission where prompted; relative orientation is never passed off as compass data. ```basic HEADING H PRINT H ``` ## BATTERY `BATTERY LEVEL[,CHARGING,FULL,EMPTY]` Reads percentage 0–100, charging flag (-1 yes, 0 no), and seconds until full/empty (-1 unknown). Browsers without Battery API, including Safari, report unavailable. ```basic BATTERY B,C PRINT B;C ``` ## TOUCH `TOUCH X,Y,DOWN[,GESTURE$]` Reads graphics-canvas coordinates and a down flag (-1/0). Gestures include tap, swipe-left/right/up/down, pinch-in/out and cancel. Call after SCREEN to enable input; read again to consume gestures. Listeners stop at program end. Editor and keyboard controls are excluded. ```basic SCREEN 1 TOUCH X,Y,D,G$ ``` ## GAMEPAD `GAMEPAD(INDEX,KEY$[,CONTROL]) / GAMEPAD$(INDEX)` Reads a connected gamepad or its name. Index/control are zero-based. Keys: CONNECTED, AXES, BUTTONS, AXIS, BUTTON, PRESSED, TOUCHED. Axes are -1–1, button values 0–1, flags -1/0. Disconnected CONNECTED is 0 and name is empty; other reads report unavailable. Press a controller button to make it visible to the browser. ```basic PRINT GAMEPAD(0,"CONNECTED") ``` ## SPEAK `SPEAK TEXT$[,LANG$]` Speaks text through browser speech synthesis after pressing Return at the terminal prompt. Optional language is a language tag such as en-US. Waits for completion; Cancel, BREAK or timeout stops speech. Voices vary by platform. ```basic SPEAK "HELLO FROM BASIC" ``` ## DICTATE `DICTATE TEXT$[,LANG$]` Recognizes a phrase. LISTEN is an alias. Requires a supported recognition service, microphone permission and an explicit terminal Return. The browser/OS speech service may process audio remotely. Cancel or no speech returns empty text; denial is an error. BREAK cancels recognition. ```basic DICTATE A$ PRINT A$ ``` ## VIBRATE `VIBRATE [MS]` Requests vibration (default 200 ms, integer 0–5000). 0 stops it. Requires browser Vibration API and sometimes a tap. iOS Safari does not expose vibration; unsupported requests report unavailable. ```basic VIBRATE 200 ``` ## CLIPBOARD `CLIPBOARD TEXT$ / SETCLIP TEXT$` Reads or writes text after an an explicit terminal Return action. CLIPWRITE aliases SETCLIP. Requires HTTPS and a supported clipboard API; denial is an error. Cancelled read returns empty text; cancelled write leaves the clipboard alone. ```basic SETCLIP "HELLO" CLIPBOARD A$ ``` ## SHARE `SHARE TEXT$ / SHAREFILE FILE$` SHARE opens the browser share sheet for text after pressing Return at the terminal prompt; unsupported browsers report unavailable. SHAREFILE shares an imported/captured file where file sharing is supported, otherwise offers a clearly labeled download. Cancel leaves the program usable. SHAREFILE accepts up to 4 MiB; use EXPORT for larger files. ```basic SHARE "HELLO FROM CLASSIC BASIC" ``` ## IMPORT `IMPORT F$ / EXPORT F$` IMPORT selects a local file up to 4 MiB, returns its filename, and stores it for this session. Cancel returns empty text. EXPORT downloads a session file; an unsaved .BAS name exports the current program. There is no server upload. Session file storage is bounded to 32 MiB / 100 files. Existing LOAD/SAVE still edit and save BASIC programs. Use Return at the terminal prompt to open the native picker or download; no confirmation panel is added. ```basic IMPORT F$ EXPORT F$ ``` ## AUDIORECORD `AUDIORECORD F$ / AUDIORECORDSTOP / AUDIORECORDEXT$()` Records microphone audio to a session file. Use AUDIORECORDEXT$() for the supported .webm/.m4a/.ogg suffix. Requires HTTPS, microphone permission. Stops at 5 minutes / 25 MiB, BREAK or backgrounding. AUDIORECORDSTOP finalizes the file; EXPORT downloads it. MICSTART / MICSTOP F$ are aliases with an automatically chosen filename. ```basic F$="VOICE"+AUDIORECORDEXT$() AUDIORECORD F$ INPUT "PRESS RETURN TO STOP";A$ AUDIORECORDSTOP EXPORT F$ ``` ## NOTIFY `NOTIFY TEXT$[,TITLE$]` Requests notification permission after pressing Return at the terminal prompt and shows a local notification where supported. Browser installation/OS restrictions may make this unavailable. No background push service is added. ```basic NOTIFY "PROGRAM FINISHED" ``` ## DEVICEAVAILABLE `DEVICEAVAILABLE(NAME$)` Returns -1 when the required browser API is present in a suitable context, else 0. This is feature detection, not proof of permission or attached hardware. The actual command can still report denied or unavailable. ```basic PRINT DEVICEAVAILABLE("GPS") ``` ## DEVICEINFO$ `DEVICEINFO$(KEY$) / SCREENINFO(KEY$)` Device keys: PLATFORM, LANGUAGE, USERAGENT. Screen keys: WIDTH, HEIGHT, AVAILABLEWIDTH, AVAILABLEHEIGHT, PIXELRATIO, VIEWPORTWIDTH, VIEWPORTHEIGHT, ANGLE. Dimensions are CSS pixels; ANGLE is degrees. No serial number or persistent device identifier is exposed. ```basic PRINT DEVICEINFO$("PLATFORM") PRINT SCREENINFO("WIDTH") ``` ## OPENURL `OPENURL URL$ / ONLINE()` Opens an HTTPS destination only after pressing Return at the terminal prompt. ONLINE() reports the browser's network flag (-1/0), not proof that any remote service is reachable. ```basic PRINT ONLINE() ```