JavaScript can be used to write emulations of games. This may be helpful since the C development tools are more difficult. This guide will help you get started.
Your HTML file must include the scripts firmware.js
, font.js
machine.js
, game.js
, and player.js
in that order; and it must include div#Game
in body
. Example code: game-demo/index.html.
Your JavaScript file must have the functions reset()
, do_logic()
, and fill_vram()
. Example code: game-demo.js.
reset()
: run once at the beginning of the codedo_logic()
: run 60 times a second. Put as much game logic here as you can. However, do not touch the VRAMfill_vram()
: run after do_logic()
, once in the vertical blanking area. Here, you can touch the VRAM
The 65C02 does not have any built-in floating-point functionality. Therefore, we will instead use fixed-point numbers for continuous values.
We have a Q9_6 implementation in firmware.js
. You can see its usage in game-demo.js
.
Never use floating point numbers! If you need non-integers, use Q9_6.
JavaScript is run by opening an html file in a browser. The easiest way to open html files is through VSCode and Live Server. Install it here:
To include a JavaScript file in an html file, you need to add a script:src
tag to the head
section, and provide the source path/link. Observe this code block:
Note: Append defer
to all script elements.
CDN stands for content delivery network. We use a CDN to retrieve JavaScript files from https links instead of paths. A JS Deliver CDN link has this structure: https://cdn.jsdelivr.net/gh/<org/user name>/<repository>@main/<path>
. Any changes to files that are pointed to by a CDN link will take ~2 hours to show up.