Fastest NES emulator in roblox

A NES emulator is legal because it recreates the hardware behavior of the Nintendo Entertainment System. However, distributing emulators or ROMs through Roblox may violate the Roblox TOS, so this project is tested locally only.

Github | LuauNES

Mostly inspired by Mesen2. ( aka one of the most accurate NES emulators )

Anyone can run the emulator locally (even without ID verification - like me) and use their own ROM dumps or homebrew games.

Old post:


Features

  • 2-player support.
  • zapper support ( or mouse ).
  • Full noises sequences, pulses (with extra ones) , triangles for sounds.
  • PPU dot-based
  • Almost cycle-accurate CPU
  • No DMC channels (sorry!)

Performance

  • ~120–150 FPS (VRC/MMC5 games) or ~240 FPS (Mapper 0, 1, …) on mid-range laptops, specs:

    • CPU: 13th Gen Intel(R) Core™ i7-13620H 2.40 GHz ( 10 cores / 16 threads )
    • RAM: 24 GB
  • ~30–80 FPS on low-end laptops, specs:

    • CPU: Intel Core i3-1005G1 @ 1.20 GHz ( 2 cores / 4 threads )
    • RAM: 4 GB

Supported Mappers (45+)

Nintendo

  • 0 - NROM
  • 1 - MMC1 / SxROM
  • 2 - UxROM (UNROM/UOROM)
  • 3 - CNROM
  • 4 - MMC3 / TxROM
  • 5 - MMC5 / ExROM
  • 7 - AxROM / AOROM
  • 9 - MMC2 / PxROM
  • 10 - MMC4 / FxROM
  • 13 - CPROM
  • 37 - MMC3 multicart variant
  • 47 - MMC3 multicart variant
  • 66 - GxROM
  • 94 - UN1ROM
  • 105 - NES-EVENT (MMC1)
  • 118 - TxSROM (TKSROM/TLSROM)
  • 155 - MMC1A variant
  • 180 - UxROM (inverted)
  • 185 - CNROM security / CHR-disable variant

Namco

  • 19 - Namco 163 family
  • 76 - NAMCOT-3446
  • 88 - Namco 108 variant
  • 95 - NAMCOT-3425
  • 154 - NAMCOT-3453
  • 206 - Namco 108 / Namco 118 / MIMIC-1 / DxROM
  • 210 - Namco 175 / Namco 340

Konami

  • 21 - VRC2 / VRC4 family
  • 22 - VRC2 / VRC4 family
  • 23 - VRC2 / VRC4 family
  • 24 - VRC6
  • 25 - VRC2 / VRC4 family
  • 26 - VRC6
  • 27 - VRC2 / VRC4 family
  • 73 - VRC3
  • 75 - VRC1
  • 85 - VRC7

Sunsoft

  • 67 - Sunsoft-3
  • 68 - Sunsoft-4
  • 69 - FME-7
  • 89 - Sunsoft-2 on Sunsoft-3 board
  • 93 - Sunsoft-2 on Sunsoft-3R board
  • 184 - Sunsoft-1

Homebrew

  • 30 - UNROM 512

Unlicensed

  • 11 - Color Dreams
  • 71 - Camerica / Codemasters
  • 79 - NINA-03 / NINA-06
  • 116 - Huang / Gouder SOMARI-P
  • 163 - Nanjing FC-001
Video examples

Weird Mario Bros (41 KB | Mapper 0)

A patched version of Super Mario Bros, eating the mushroom make you looks cursed


Bad Apple!! (786 KB | Mapper 4)

The legendary song that everyone knows


Famidash (2 MB+ | Mapper 4)

Geometry dash but in NES, Why I am playing so bad here :sob:


Kirby’s Adventure (768 KB | Mapper 4)

One of the largest licensed NES games


Pokemon Yellow in NES (2 MB | Mapper 163)

An english translation of “Lei Dian Huang: Bi Ka Qiu Chuan Shuo”

Duck Hunt! (8 KB | Mapper 0)

A game that uses zapper for its core gameplay, like using mouse to shoot the ducks

34 Likes

I never thought I’d see the day where you can emulate the NES on Roblox. This is surprisingly well made! I absolutely love it.

3 Likes

Great project

4 Likes

This is absolutely the most legendary I have ever seen a person do on ROBLOX Studio! I expect a recreation, BUT A ACCURATE, FAST EMULATOR!? It’s like a generational leap in technology. I can imagine a actual ROBLOX inside of ROBLOX by 2050 or something! :face_with_spiral_eyes:

3 Likes

actually there was a roblox inside roblox game before lol, and web emulation. I don’t remember the project name or where I’ve seen it, but flamingo played it before, although it was laggy :sob:

2 Likes

This is actually insane, it’s awesome to see stuff like this being done on Roblox. Well done!

1 Like

Incredible! I am going to mess around with this, will you accept PRs because I would love to contribute to this project.

1 Like

Feel free to contribute to the project. I originally didn’t plan to maintain it, but improvements from others would be helpful!

It’s kind of like remotely streaming on the web server outside roblox that runs an virtual machine. I’m not exactly sure how they set it up, but I think it used HTTP kind of stuff. Just guessing, I could be wrong.

Cool~

1 Like

i decided to test LuauNES to see how accurate it is to the original console. here’s the simple results (using AccuracyCoin)

In the current version of LuauNES, it actually crashes on the Interrupt Flag Latency test, though in my version I modified this line:

elseif not bit32.btest(status, 4) and (apu_irq_pending() or (mapper_has_cpu_clock and mapper_cpu_irq_prev) or ((not mapper_has_cpu_clock) and mapper_irq_pending_fast())) then

to be this

elseif not bit32.btest(status, 4) and (apu_irq_pending() or (mapper_has_cpu_clock and mapper_cpu_irq_prev) or ((not mapper_has_cpu_clock) and mapper_has_irq_pending and mapper_irq_pending_fast())) then

anyways here’s the list of each page that contained fails and why

AccuracyCoin test results

Page 1 - CPU Behavior

Test Reason
Dummy Write Cycles 1: PPU Open Bus should exist
Open Bus 4: Moving the program counter to open bus should read instructions from the floating data bus values. Write cycles should update the data bus.

Page 6 - Unofficial Instructions: RRA

Test Reason
All Tests On This Page 1: The target address of the instruction was not correct.

Page 10 - Unofficial Instructions: SH*

Test Reason
SHA Indirect,Y 1: The target address of the instruction was not correct.
SHA Absolute,Y 1: The target address of the instruction was not correct.
SHS Absolute,Y 1: The target address of the instruction was not correct.
SHY Absolute,X 1: The target address of the instruction was not correct.
SHX Absolute,Y 1: The target address of the instruction was not correct.

Page 12 - CPU Interrupts

(NOTE: Interrupt Flag Latency will crash the emulator without applying the patch I explained)

Test Reason
Interrupt Flag Latency 2: The IRQ should occur 2 instructions after the CLI instruction. (The CLI instruction polls for interrupts before cycle 2.)
NMI Overlap BRK 2: Either NMI timing is off, or interrupt hijacking is incorrectly handled.
NMI Overlap IRQ 2: Either NMI timing is off, IRQ timing is off, or interrupt hijacking is incorrectly handled.

Page 13 - APU Registers and DMA Tests

(NOTE: DMA stuff mostly fails here early because there is a lack of DMA at all)

Test Reason
DMA + Open Bus 2: The DMC DMA was either on the wrong cycle, or it did not update the data bus.
DMA + $2002 Read 2: The DMC DMA was either on the wrong cycle, or the halt/alignment cycles did not read from $2002.
DMA + $2007 Read 2: The DMC DMA was either on the wrong cycle, or the halt/alignment cycles did not read from $2007.
DMA + $2007 Write 1: DMA + $2007 Read did not pass.
DMA + $4015 Read 2: The DMC DMA was either on the wrong cycle, or the halt/alignment cycles did not read from $4015, which should have cleared the APU Frame Timer Interrupt Flag.
DMA + $4016 Read 1: The DMC DMA was either on the wrong cycle, or the halt/alignment cycles did not read from $4016, which otherwise should have clocked the controller port.
DMC DMA Bus Conflicts 1: The DMA did not occur on the correct CPU cycle.
DMC DMA + OAM DMA 1: The DMC DMA timing in your emulator is off.
Explicit DMA Abort 1: The DMC DMA timing in your emulator is off.
Implicit DMA Abort 1: The DMC DMA timing in your emulator is off.

Page 14 - APU Tests

Test Reason
Frame Counter IRQ 7: The IRQ flag should not be cleared yet the APU transitions from a “get” cycle to a “put” cycle.
Frame Counter 4-step 1: The first clock of the length counters was early.
Frame Counter 5-step 1: The first clock of the length counters was early.
Delta Modulation Channel J: The DMA occurred on the wrong CPU cycle.
APU Register Activation 1: A series of prerequisite tests failed. CPU and PPU open bus, PPU Read Buffer, DMA + Open Bus, and DMA + $2007 Read.
Controller Strobing 4: Controllers should not be strobed when the CPU transitions from a “put” cycle to a “get” cycle.

Page 16 - PPU Behavior

Test Reason
PPU Register Open Bus 1: Reading from a write-only register PPU should return the most recently written value to the PPU data bus.
Palette RAM Quirks 5: The values read from Palette RAM should only be 6-bit, with the upper 2 bits being PPU open bus.
Rendering Flag Behavior 2: Background shift registers should be initialized and clocked when only rendering sprites.
$2007 Read w/ Rendering 2: Reading from $2007 while rendering is enabled should result in a vertical increment of v.

Page 17 - PPU VBlank Timing

Test Reason
VBlank Beginning 1: The PPU Register $2002 VBlank flag was not set at the correct PPU cycle.
NMI Control 8: The NMI should occur 2 instructions after the NMI is enabled. (See Interrupt flag latency.)
NMI Timing 1: The NMI did not occur on the correct PPU cycle.
NMI Suppression 1: The NMI did not occur on the correct PPU cycle, or the NMI was not suppressed by a precisely timed read of address $2002.
NMI at VBlank End 1: The NMI could occur too late or was disabled too early.
NMI Disabled at VBlank 1: The NMI could occur too late or was disabled too early.

Page 18 - Sprite Evaluation

Test Reason
$2002 Flag Timing 1: The flags were not cleared on the correct ppu cycle.
Suddenly Resize Sprite 4: Writing to $2000 to disable 16 pixel tall sprites at the beginning of HBlank should properly prevent an otherwise in-range 16 pixel tall sprite from extending into the current scanline.
Arbitrary Sprite Zero 2: The first processed sprite of a scanline should be treated as “sprite zero”.
Misaligned OAM Behavior 1: Misaligned OAM should be able to trigger a sprite zero hit.
Address $2004 Behavior 1: Writes to $2004 should update OAM and increment the OAM address by 1.
OAM Corruption 2: OAM Corruption should “corrupt” a row in OAM by copying the 8 values from row 0 to another row.
INC $4014 1: The DMC DMA should update the data bus.

Page 19 - PPU Misc.

Test Reason
Stale BG Shift Registers 3: The background shift registers should not be clocked during H-Blank or F-Blank. After re-enabling rendering, a sprite zero hit should be able to occur entirely on stale background shift register data.
BG Serial In 2: Background shift registers should bring in a 1 into bit 0 when shifted. These can be drawn on screen with carefully timed writes to $2001 to enable/disable rendering to skip reloading the shift registers.
Sprites On Scanline 0 2: A sprite should be able to be drawn at Y=0 via the pre-render scanline’s sprite evaluation with stale secondary OAM data.
$2004 Stress Test 1: Reading from $2004 (with rendering enabled) should read from the “OAM Buffer” used during OAM Evaluation. Your results did not match the expected results of the test where OAMADDR overflows. See TEST_2004_Stress_Evaluate in the .asm code for details.
$2007 Stress Test 1: Reading from $2007 should set up the PPU Read Buffer two ppu cycles after the CPU Read ends. Reading from $2007 (with rendering enabled) should set up the PPU Read Buffer with the same value as the resulting read from the background or sprite fetch that occured on the same ppu cycle as the read for the PPU Read Buffer. If you fail this test, you are likely reading from memory to set up the PPU Read Buffer on the wrong ppu cycle, missing dummy nametable reads during sprite fetch, or missing dummy nametable reads at the end of a scanline.

Page 20 - CPU Behavior 2

Test Reason
Instruction Timing 1: The DMA should update the data bus.
Implied Dummy Reads 3: Your emulator did not update the data bus when the DMC DMA occured, or your DMA timing is off.
Branch Dummy Reads 2: Your emulator does not accurately emulate the PPU Open Bus.
JSR Edge Cases 2: JSR should push the return address to the stack between reading the first and second operand.

a good chunk of the errors noted by AccuracyCoin come from not implementing DMC (which is OK, because LuauNES doesnt implement DMC on purpose) but the main one that sticks out is open bus not being implemented (correctly?). i think some games rely on this behavior implemented correctly but I could be wrong.

Another thing which did not appear in the AccuracyCoin errors is a few bugs in the homebrew game MicroMages. Small score graphics do not appear correctly sometimes, and the magic bullet button (B) is for some reason mapped to A (Jump button). I have verified this is not an issue with how the configuration is setup and is not a bug in other emulators like Mesen.

Overall, though, this is quite an accurate emulator (minus the DMC support but that’s to be expected)

3 Likes

I have tested AccuracyCoin in my emulator before uploading this, the accuracy was only 71/137.

Thank’s for finding this bug!

But did you meant

mapper_irq_pending_fast and mapper_irq_pending_fast()

not

mapper_has_irq_pending and mapper_irq_pending_fast()

mapper_irq_pending_fast is different from mapper_irq_pending, so this would breaks a lots of stuffs

I never tested that game before, would be helpful if you could found more games that appear the same bugs

EDIT: just fixed it now, so there’s a bug on the opcodes like I just simplify things too much.
NOTE: This is a performance-focused emulator ( not accurate )

How do I properly store the insides of a ROM? Do I just open the .nes dump in a notepad and copy everything? If yes, then how do I store it without roblox erroring
image

1 Like

Now, run DOOM.

2 Likes

My account got locked out of devforum because of country restriction
And yea, It could be my website rom converter fails to load some ROMs ( roblox strings are really weird ), I may fix it immediately.

2 step ahead

Bruh?! :skull: Bro, just did the impossible.

1 Like

hi there, do you have any idea why this runs so terribly for me? i have a ryzen 5 5500 and on your luau doom port im easily hitting ~120 fps, but on famidash on this nes port im barely getting 6 fps, im using your example code from github to create the screen and everything, im on linux running roblox studio through vinegar

1 Like

It’s probably because you have Linux, because on my PC with Windows 11 that is a bit worse than yours it runs perfectly

2 Likes

The Doom port only getting around 120 FPS on a pretty strong CPU probably because Studio running through vinegar, somehow disables Luau native codegen like @KnownAsGlzk said. I’m not fully sure tho

And yea, the NES emulator is very laggy without native codegen. I cant even get Mario running at 30 FPS on my computer when it gets disabled

also the FamiDash port uses the MMC3 mapper, which are heavy to emulate, probably makes the performance even worse :face_with_spiral_eyes:

1 Like

makes sense, thank you both btw, native codegen worked in some of my other projects so im not sure why it doesnt now (could be due to some weird wine stuff), i also gave the NES emulator to a friend running windows 11 and he saw similar results (around 3-4 more fps than me). either way, very awesome project, and thank you for such a quick reply!

1 Like