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.
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!
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
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.
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)
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
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.
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
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
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!