A web-based NES emulator in WebAssembly
The core features are still under development, thanks for watching it.
- CPU instrcutions
- Rendering
- Audio
- Controller
- Mapper000
- Mapper001
- Mapper002
- Mapper003
The project is written in Rust and built by wasm-pack. Setup the deleopment tool chains according the link
https://rustwasm.github.io/docs/book/game-of-life/setup.html
And execute the command under project root folder to build it
wasm-pack buildThe output is a NPM package, which is located in pkg folder.
The unit tests is ran by standard cargo command
cargo testNote: wasm-pack test can also exeute the unit tests but will encounter some memory issue with the default configuration.
The output is a standard NPM package, which can be imported to your Javascript project.
import * as wasm from "pixel-hero";Create an emulator object with the function
function create_emulator(element: HTMLElement, conf: any): Emulator;Parameter element is a div html element, may be got by document.getElementById. Anything in the div will be cleared and a <canvas> will be created in it to display the game video.
Parameter conf is a Javascript object for game configuration, the detail fields are descriped here.
The returned value is called emulator object, which is in fact an Javascript containing two functions
class Emulator {
insert(cartridge: Uint8Array): void;
stop(): void;
}Function insert accepts the NES file data in the format of Uint8Array, and start the game.
Function stop can stop the running game.
The configuration object to create an emulator object is
{
// To be implemented
}A simple example is under folder example.
Considering the copyright issue, no game file is published. If you are willing to run the example, please find a NES file, put it under the example folder and rename it as game.nes.
The exampe is hosted by webpack-dev-server. Run the following commands to start it.
npm install
npm startThen access http://localhost:8080 via your browser to enjoy the game.