Skip to content
CPCBasic - Run CPC BASIC in a Browser
JavaScript HTML CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
img
.editorconfig
.eslintrc.js
BasicParser.js
Canvas.js
CommonEventHandler.js
Controller.js
CpcVm.js
Model.js
README.md
Random.js
Sound.js
Utils.js
View.js
cpcCharset.js
cpcbasic.css
cpcbasic.html
cpcbasic.js
cpcconfig.js
index.html
package.json

README.md

CPCBasic Unchained - Run CPC BASIC in a Browser

CPCBasic lets you run CPC BASIC programs in a browser. The supported BASIC style is known as Amstrad CPC 6128 Locomotive BASIC 1.1. BASIC programs are compiled to JavaScript which can be run in the browser. A library provides the functionality of the commands that are not directly available in JavaScript.

CPCBasic Links: CpcBasic Demo, Colors CPC Demo, Source code, HTML Readme,

Features

  • Run old an new BASIC programs in a browser
  • "Wrap factor" Speed: Frame Fly and other events in real-time, calculations as fast as possible
  • CPC Basic Unchained: Less restrictions, extended by new features, breaking out of the CPC box
  • BASIC compiler and not just interpreter
  • Lots of memory, no memory full
  • Runs locally without a server (even on mobile devices, but without input)
  • HTML5 / JavaScript without external libraries

A sample with cpcbasic]

Art] Graphics] Labyrinth] Landscape]

Why CPCBasic

There are several great CPC emulators which emulate a complete CPC with exact timing and allow demos to run, pushing CPC hardware to its limits.

With CPC Basic we do not get that accuracy. But if we compile it to JavaScript, can we achieve a similar or faster speed than the assembler programmed functionality that runs on a CPC or emulator?

Usage

  • Just open cpcbasic.html in a browser. The user interface shows several boxes, which can be reduced and expanded by pressing the green buttons.

  • Use the selection field to select a sample program, reset the CPC, and run the program.

  • If you change the BASIC program, press the Run button to compile and run the BASIC program in JavaScript. The Compile only button compiles the program without running it.

  • If the focus is on the CPC screen, keystrokes will be detected by a running program. The Input window is an alternative way to send input to the CPC. This works also on mobile devices.

  • The Break button stops the simulation. You can continue with the "Continue" button.

  • The Reset button resets the CPC.

  • Textual output is also written to the Console Window. This is useful for copying and pasting the output.

  • The Variables window allows you to see the variables used by the program.

  • In the JavaScript window you will see the compiled JavaScript code. It can be changed and then executed with the Run button in this window. So it is possible to use the simulated CPC directly with JavaScript.

  • The Reload button reloads the page with the current settings. (Please note that changes to the script are lost!)

  • The Help button opens the readme file on the server.

Restrictions

  • CPCBasic is still in progress and not complete or accurate
  • It is BASIC only and can not execute Z80 machine code
  • Unimplemented commands, eg. KEY, KEY DEF, ...
  • RESTORE on lines without DATA
  • Sound: No ENT (tone envelopes); no hardware volume envelopes or tones with sepcial ENV syntax "="
  • No direct input mode for BASIC commands, e.g. LIST, RENUM,...; no visible cursor
  • Few checks of the program
  • Almost no type checking
  • Variables typed with DEFINT, DEFREAL or DEFSTR are different from those with type extension: defint a: a=1: a%=2: ?a,a%
  • Resulting JavaScript looks ugly because there is no GOTO in JavaScript. Control structures need to be converted to GOTO because for some commands and events it is necessary to jump out a block
  • Interpreted CPC BASIC may contain lines of arbitrary content if they are not executed, e.g. comments without marking them as comments. The CPCBasic compiler does not allow this.
  • That is CPC BASIC: a(3]=6: ?a[3). Do we really want to allow that?
  • A lot more

Fixed Restrictions

  • [fixed: TEST, TESTR can not distinguish between pens of the same color]
  • [fixed: Changing the color with INK, existing drawings will not be changed and the colors will not flash. Currently you have to redraw the screen with another color to get a flashing effect.]
  • [fixed: Comparison with equal in assignment is possible now: a=0: x=(a=0): ?x, returns -1 for true as on the CPC]
  • [fixed: No sound]

Extensions

  • MODE 3: High resolution with real 640x400 pixel and 16 colors; 8x8 pixel characters: Rectangles
  • Computations are not limited to 16 bits
  • Peek&Poke can access "large" memory, not only 64K or 512K.

Programming hints

  • It is BASIC with "wrap factor". However, do not use busy waiting. Put in FRAME or CALL &BD19 commands.

Possible Future Enhancements

  • Drag and drop BASIC programs (tokenized or ASCII) into CPCBasic
  • Separate sample library; sample category
  • DSK images support
  • Pause key
  • Create buttons for the keys that the BASIC program checks (useful for e.g. mobile devices)
  • RSX extension libraries / plugins programmed in JavaScript
  • Can we detect Busy Loops and insert FRAME automatically?
  • Extension: More colors, e.g. 256
  • Optimizations of the resulting JavaScript code
  • Further checks during compile time
  • Smooth characters from 8x8 to 8x16

Links

mv, 09/2019

You can’t perform that action at this time.