back

JavaScript

Table of Contents

JavaScript Code Structure

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.

HTML

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.

JavaScript

Your JavaScript file must have the functions reset(), do_logic(), and fill_vram(). Example code: game-demo.js.

Floating Point vs. Fixed Point

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.

Running JavaScript

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.

CDNs

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.