An n64 emulator in JavaScript
Go to file
Paul Holden 4e89d41399 Automated build 2024-01-07 10:13:26 +00:00
.github/workflows Ignore empty commits. 2023-10-15 22:19:19 +01:00
build Automated build 2024-01-07 10:13:26 +00:00
js externs/ is no longer used. 2023-10-29 19:56:06 +00:00
roms Update n64-systemtest rom 2023-11-07 22:25:52 +00:00
src Add more details to EmulatedException. 2024-01-07 10:13:10 +00:00
tools Move syncserver.js out of src/ 2016-12-03 16:04:37 +00:00
.babelrc Add simple tests for format 2016-11-25 22:54:14 -05:00
.eslintrc.cjs Add eslint config. 2023-09-06 21:32:00 +01:00
.gitattributes LFS for .z64 files. 2023-09-30 22:14:23 +01:00
.gitignore Serve minified version. 2023-09-26 09:10:42 +01:00
LICENSE Format to 80 columns 2012-08-22 07:13:17 +01:00
README.md Fix stray ' 2024-01-07 10:13:10 +00:00
TODO.md Remove all the signed versions of memory read accessors and just do this as needed in memaccess. 2024-01-07 10:13:09 +00:00
index.html Tidy attribute names. 2023-10-25 23:07:32 +01:00
n64js.css Format. 2023-10-15 13:53:04 +01:00
package.json Add a benchmark for RSP accumulator 2023-11-15 08:13:22 +00:00

README.md

n64js

n64js is an n64 emulator written in (mostly) pure ES6 JavaScript. It runs many roms at full framerate.

Why?

Mostly for the challenge. I've spent ~25 years (on and off) working on N64 emulators and writing one in JavaScript gives me the opportunity to expand my comfort zone and learn something new. It's a good showcase for how powerful modern browsers have become.

How To Run

A hosted version is available on GitHub pages at https://hulkholden.github.io/n64js/.

Development

Install bun: https://bun.sh/.

Compile sources (pass --watch to automatically recompile on any change):

bun run build --watch

Run a local webserver in the root directory:

python3 -m http.server

Navigate to http://localhost:8000/.

If you want to run without installing bun, you can change the importmap in index.html to point at src/n64.js instead of build/n64.min.js.

Compatibility

Compatibility has improved a lot over the past few months.

As of 2023-09-23 95% of n64-systemtest tests now pass.

The areas where tests are failing are:

  • 64-bit memory access (rarely/never used by roms)
  • RDP (shouldn't be a problem, as n64js uses HLE)
  • Floating point accuracy

The floating point issues are largely edge cases with rounding values close to the numerical limits for 32 bit floats.

Beyond the things n64-systemtest covers, the main compatibility issues I'm aware of are:

  • imprecise cycle counting
  • graphics

Imprecise cycle counting affects some roms more than others. GoldenEye in particular seems to hang when LLE audio emulation is enabled on the RSP. I suspect this is due to the CPU running faster than it should be and causing the game to overflow audio buffers.

Graphics are rendered using high-level emulation and there are still a lot of TODOs. Many roms are playable but most have graphical issues of some kind.

Browser Compatibility

  • Chrome 116.0.5845.140 - I've been doing most of my development in Chrome so this is the preferred option
  • Firefox 117.0 - runs, but is slower than Chrome.
  • Safari 16.6 - runs, but is slower than Chrome.
  • Edge - untested. Please let me know how you get on.

Performance

I've been testing on an Apple M2 Max and most roms run at full framerate most of the time. LLE audio emulation seems to be the biggest performance hit. To date I've mostly been focussed compatibility so there are likely a lot of improvements to be made here.

Implementation Status

  • CPU
    • cop0 instructions
    • cop1 instructions
    • TLB
    • Cycle accuracy
  • RSP
  • Controller
    • Static key bindings
    • Configurable bindings
    • Gamepad API
  • Graphics
    • HLE
      • GBI0 - mostly implemented
      • GBI1 - partially implemented
      • GIB2 - partially immplemented
    • LLE - not implemented
  • Audio
    • HLE - not implemented
    • LLE - implemented
  • Save
    • Persistance (via localStorage)
    • Import/Export
    • Mempack
    • Eeprom 4k
    • Eeprom 16k
    • SRAM
    • FlashRAM

TODOs

Here's some things I'd like to get around to:

  • Fix graphics issues
  • Save game import/export
  • Savestates
  • Gamepad support.

History

n6js is derived from Daedalus, an emulator I started working on around 1999 and continued working on periodically for many years. Around 2012 I made a bet with @mmalex that I could write a port in JavaScript, and n64js was born!