/MoonbitNES

A NES emulator in MoonBit

Primary LanguageJavaScriptMIT LicenseMIT

MoonBitNES: NES emulator and playground in MoonBit

This projects started as a personal experiment for the MoonBit language in Oct. 2023 and luckily became a showcase in IDEA conference in Nov. 2023.

Based on Dennis Felsing's Exellent nimes, which itself is based on fogleman's excellent NES emulator in Go.

Compared to the nim/go versions, this version implements enough unofficial opcodes to pass the nestest suggested in nesdev wiki.

This version is very different (changed ~800 lines) from the original version because MoonBit has evolved a loooot since then. At that time, there was no for loops, no pipes, and we can define methods for built-in types etc.

We make it open-source to encourage people mess with it. PRs are welcome!

Usage

To build the project, one will need

moon build --target wasm-gc # for the wasm-gc backend
# or
moon build --target js # for the js backend

To run the project, one will need

python3 -m http.server 8080 # or other ways to start a static server

Notice that the wasm-gc backend uses GC proposal of WebAssembly, thus requiring Chrome 119 and later, Firefox 120 and later. One may check if it's available with feature extensions. One may configure the backend at the beginning of main.mjs.

Known issues & future work:

  • Refactor to more idiomatic moonbit (remember that most codes are written in Oct. 2023 and they're better described as ported than written!)
  • Fix broken audio for some games (e.g. Kage, Batman)
  • More mappers beyond 0,1,2,3,4,7
  • Cycle-accurate CPU emulation
  • Debugger GUI (the current instruction formatter is already close to Mesen2's trace logger)

Contributors

Thanks