## Grumpy NES emulator

Show off your games, demos and other (playable) creations.
grump
Party member
Posts: 945
Joined: Sat Jul 22, 2017 7:43 pm

### Grumpy NES emulator

smb.png (59.88 KiB) Viewed 16211 times
galaxian.png (44.77 KiB) Viewed 16211 times

It's far from complete and has some bugs. Sound emulation is not implemented. About ~75% of all NES games are technically playable, for the rest the required mappers are not yet implemented.

Play .nes ROM files by dropping them onto the emulator window. Only NTSC ROMs are supported, others will crash the emulator. A free game is included - do not ask here for copyrighted ROM files.

I'm releasing it in this incomplete WIP state because I'm frustrated with LuaJIT's crazy shenanigans. Sometimes performance is superb, other times it slows down to a crawl. It accumulates more garbage per second than a neckbeard in his nest in a month, for reasons unknown. I don't know if this can be fixed and don't think I will ever finish it. The MoonScript code will be on Github soonis on GitHub now.

The default game that runs when the emulator starts is 2048, Copyright 2013,2014 Valtteri "tsone" Heikkilä.

Keyboard controls (US layout)
Arrow keys: up/down/left/right
X: A Button
C: B Button
Return: Start Button
Space: Select Button
P: Pause emulator
F1: toggle scanline/screen blur
F2: toggle bilinear blur
F3: toggle overscan area

v0.2: Gamepad can be used now!

Edit: updated to version 0.2
Attachments
gnes-0.2.love
Last edited by grump on Sat Oct 23, 2021 4:29 am, edited 1 time in total.
pgimeno
Party member
Posts: 2938
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Grumpy NES emulator

Lovely.

Is there any way to disable the scanlines effect?

Would it be possible to have support for command line files? I have to explicitly fire a DnD file browser in order to drop games.

How many mappers are supported?

Here's another possible default game, Escape from Pong (license: BSD 3-clause): http://www.formauri.es/personal/pgimeno ... fp-rev.nes (Debian users may be familiar with it)
Copyright (c) 2004 Halley's Comet Software

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
https://hcs64.com/efp.html
grump
Party member
Posts: 945
Joined: Sat Jul 22, 2017 7:43 pm

### Re: Grumpy NES emulator

pgimeno wrote: Wed Jun 02, 2021 10:47 pm Is there any way to disable the scanlines effect?

Would it be possible to have support for command line files? I have to explicitly fire a DnD file browser in order to drop games.
Those are numbers 2 and 3 on the list of essential things I wanted to add before releasing the first version, but forgot about in my fit of rage over LuaJIT's neverending efforts to trample on my hopes and dreams.

As a quick workaround you could just remove the setShader call on line 94 in gnes/Display.lua to disable the scanline effect.
How many mappers are supported?
The seven most used mappers are currently supported. From my incomplete collection list of 1,091 games, 871 are covered by those 7 mappers. The next mapper to implement would be #79 - required by 14 games. Talk about diminishing returns.
Jasoco
Inner party member
Posts: 3689
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: Grumpy NES emulator

This is kind of amazing TBH.

But yeah, the frame rate does seem to fluctuate.

But for me it seems to be weird getting games to load. I have to open the .love file so it loads the 2048 game. Then drag the .nes file onto it which gives me the Löve No Game screen. So I quit Löve and relaunch the .love file and it opens the ROM.

Except in the case of StarTropics which gives a Löve error screen. Shame. Love that game. I guess I'll have to play it on my NES Classic or my Switch or my NES itself or my Wii.

Edit: Also Zelda freezes when you try to start the game and Zelda II glitches out at the file select. lol
grump
Party member
Posts: 945
Joined: Sat Jul 22, 2017 7:43 pm

### Re: Grumpy NES emulator

Yeah, it's not really in a finished state that would be fit for release. The ROM loader alone is a bad hack that restarts LÖVE when you drop a file, because the JIT shits the bed really badly if you run different ROMs in the same session. Never even tested it on Windows or MacOS.

I had to "fight the system" too much and just stopped working on it after a certain point. Thanks for giving it a try though
GVovkiv
Party member
Posts: 265
Joined: Fri Jan 15, 2021 7:29 am

### Re: Grumpy NES emulator

grump wrote: Thu Jul 15, 2021 7:53 pm Yeah, it's not really in a finished state that would be fit for release. The ROM loader alone is a bad hack that restarts LÖVE when you drop a file, because the JIT shits the bed really badly if you run different ROMs in the same session. Never even tested it on Windows or MacOS.

I had to "fight the system" too much and just stopped working on it after a certain point. Thanks for giving it a try though
Uh, anyway, good job
Wish i can program things like that
grump
Party member
Posts: 945
Joined: Sat Jul 22, 2017 7:43 pm

### Re: Grumpy NES emulator

I finally made some small but important improvements, so this can be a wonky but proper release:

Code is on GitHub now btw: https://github.com/megagrump/gnes
• Performance
A few tweaks have been applied since the first release and things should run a bit smoother now. LuaJIT is still unpredictable and performance often varies wildly between emulation invocations.
Only tested with Xbox Controller
Controller A -> NES A
Controller X -> NES B
Controller Start -> NES Start
Controller Back -> NES Select
• ROM filename can be passed on command line
• Display options (options are not saved yet)
F1 to toggle scanline/blur effect
F2 to toggle bilinear filter
F12 to toggle debug display
• Debug display
MEM: memory in use by Lua
T: shows the time it takes to emulate one NES frame
• Still no sound emulation
Performance is still not great but many games seem to run pretty well on a 4-year old laptop.

If a game runs too slowly
1. Give the JIT a minute to warm up
2. If it doesn't speed up: close the emulator, blow on the ROM file (optional), and try again
3. Try 1 and 2 one more time.
4. Watch debug display (F12):
• MEM: rapidly growing (> .1 MiB/s to > 50 MiB total, even growing after warm up)?; T: > 16 ms (||||||||||)?
1. Emulation code too weak
2. LuaJIT might not know how to JIT today. Goto 1 a few more times, then try another game.
• MEM: (almost) constant, T: > 16 ms (||||||||||)?
1. Emulation code too weak
• MEM: (almost) constant, T: < 16 ms (||||||||||)
1. Emulation code too weak or computer too weird
strop.png (104.5 KiB) Viewed 5484 times
zodaperf.png (9.03 KiB) Viewed 5437 times
top: bad performance in StarTropics, but low memory count ¯\_(ツ)_/¯
center: good performance in StarTropics 2, low memory count
bottom: bad performance in StarTropics 2, high memory count

Note: Mapper 1 is currently broken, that's why are lot of games (e.g. Zelda) are not working. I will go hunt this down eventually, but not before I'm done implementing sound support.
Attachments
gnes-0.2.love
ReFreezed
Party member
Posts: 347
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

### Re: Grumpy NES emulator

This is some cool stuff! I tried some random games (on ~8 year old Windows desktop computer) and here's a selection of experiences.

The games that could load at all seemed to mostly work (with occasional moments of lag, as expected). The up and down buttons however seem to randomly get released. E.g. in Super Mario Bros. 2 and Ninja Gaiden 2 the character will randomly stand up when trying to crouch, or stop climbing. Contra cancels the buttons immediately.

In Final Fantasy I only got past the initial menus before the screen turned black.

Battle Toads crashed after a while on the first level, possibly because I died, and froze on the second level on the second try.

Megaman 6 had graphical glitches in some rooms. In one room the background was jumping when I jumped. Trippy! Then I died to spikes. lol
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Gunroar:Cannon()
Party member
Posts: 718
Joined: Thu Dec 10, 2020 1:57 am

### Re: Grumpy NES emulator

ReFreezed wrote: Sun Oct 24, 2021 12:09 am Then I died to spikes. lol
Heheh...megaman.
-It might look like nonsense but there's so much proof.
-Some more if you pls... .
It has to be real then, all that talk about the end .
-How to be saved
grump
Party member
Posts: 945
Joined: Sat Jul 22, 2017 7:43 pm

### Re: Grumpy NES emulator

ReFreezed wrote: Sun Oct 24, 2021 12:09 am The up and down buttons however seem to randomly get released. E.g. in Super Mario Bros. 2 and Ninja Gaiden 2 the character will randomly stand up when trying to crouch, or stop climbing. Contra cancels the buttons immediately.