Applesoft BASIC in JavaScript
Go to file
2013-08-20 22:29:47 -07:00
cm Simplify tokenizers; remove jslint cruft 2013-08-16 19:53:09 -07:00
samples New samples, updated docs 2013-08-18 21:26:39 -07:00
tools Squish the font bitmaps 2013-08-18 15:30:55 -07:00
vfs Snapshot 2012-02-08 22:13:44 -05:00
.gitignore Remove old ignore entry 2013-05-08 00:00:56 -04:00
basic.js Parse error cleanup. Don't tokenize digraphs. 2013-08-17 16:00:23 -07:00
bell.js Inline audio snippets via data: URLs 2013-08-17 22:40:29 -07:00
bell.wav Snapshot 2012-02-08 22:13:44 -05:00
cbasic.js New samples, updated docs 2013-08-18 21:26:39 -07:00
CHANGELOG Added CHANGELOG of pre-git changes 2013-05-06 23:23:50 -04:00
display.css Squish the font bitmaps 2013-08-18 15:30:55 -07:00
dos.js Drop underscores in named function expressions 2013-08-17 15:30:46 -07:00
favicon.ico favicon and doc tweaks 2013-08-19 20:36:28 -07:00
font-40col.png Squish the font bitmaps 2013-08-18 15:30:55 -07:00
font-80col.png Squish the font bitmaps 2013-08-18 15:30:55 -07:00
font.png Squish the font bitmaps 2013-08-18 15:30:55 -07:00
hires.js Make sure all display styles are prefixed with jsb- 2013-08-17 15:28:40 -07:00
index.htm favicon and doc tweaks 2013-08-19 20:36:28 -07:00
index.js Style separation 2013-08-17 15:15:54 -07:00
LICENSE.md Create LICENSE.md 2013-05-07 21:31:47 -07:00
lores.js Make sure all display styles are prefixed with jsb- 2013-08-17 15:28:40 -07:00
lpt.jpg Revamp printer mechanism 2013-08-16 01:37:54 -07:00
printer.js Revamp printer mechanism 2013-08-16 01:37:54 -07:00
README.md Update README.md 2013-08-20 22:29:47 -07:00
reference.htm favicon and doc tweaks 2013-08-19 20:36:28 -07:00
script.js Report compile/runtime errors to TTY in script usage 2013-08-17 21:56:51 -07:00
script.md Ditch the name basicscript 2013-08-17 21:39:36 -07:00
styles.css Style separation 2013-08-17 15:15:54 -07:00
tty.js Drop underscores in named function expressions 2013-08-17 15:30:46 -07:00

jsbasic - Applesoft BASIC in JavaScript

This is hosted for playing with at http://calormen.com/applesoft/

For older browsers, the code depends on various polyfills. For syntax highlighting, the editor optionally uses CodeMirror and custom BASIC parser/styles. Clone these into sibling directories, so you end up with a structure like:

jsbasic/
polyfill/
CodeMirror/

Notes & Known Issues

  • The BASIC program is compiled to JavaScript before execution. Syntax errors are therefore detected at compile-time rather than at run-time as on a traditional interpreter. For example, the following program would run without errors on an Apple since the erroneous second statement is never reached. 10 END : CHR$(PRINT)
  • Handling of BASIC code that does not match the canonical LIST output format may not behave as on an Apple:
    • Keyword parsing differs from Applesoft command line. For example FOR I = S TO P doesn't collapse into FOR I = STOP.
    • The interpreter doesn't actually care about line numbers for statement ordering (just for GOTO/GOSUB targets and IF statements). So 20 PRINT "A", 10 PRINT "B" will just print A, then B
  • Limitations:
    • Floating point overflow is only detected on variable assignment.
    • Only a subset of DOS 3.3 and ProDOS useful for basic file I/O are implemented.
    • Only a small number of common PEEK, POKE and CALL locations are supported.
    • Commands that refer to assembly routines (&, USR() etc.), shape tables, and tape I/O are not implemented.
  • Commands that operate on the program itself (LIST, RUN, DEL, etc.) are not implemented.
  • A handful of extensions are made beyond Applesoft BASIC:
    • To improve readability, lines may start with : and continue the previously numbered line.
    • DEF FN can define string functions
    • == can be used as =
    • CHR$() values > 255 do interesting things
    • HSCRN(x, y) allows probing the hi-res screen
    • hexadecimal literals e.g. $C010 can be used as numbers

You can run your basic programs from the command line (with only basic text input and output, and no graphics or DOS commands):

  • Clone the repository locally
  • On Windows, run from a command prompt via: cscript.exe cbasic.js your_program.txt
  • On Mac/Linux, install Mozilla Rhino, run from the command prompt via: java -jar PATH_TO/js.jar cbasic.js your_program.txt