Mesen - NES Emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

darkhog
Posts: 192
Joined: Tue Jun 28, 2011 2:39 pm

Re: Mesen - NES Emulator

Post by darkhog »

Sour wrote:
darkhog wrote:It goes to about 200fps on maximum speed. I'm plugged in (using the computer as a workstation rather than a laptop as I can't afford a real pc at the moment) and not in power saving mode.

//edit: Do you plan adding support for the .deb files (debug symbols used by fceux)?
I think I may know what's causing it to run slower than 60fps at times. Essentially if your PC wakes up too late from the sleep calls used to regulate the speed, it never tries to make up for that lost time and the code can end up running at less than 60fps. If that's what's causing the issue, this build should hopefully fix it: https://www.mesen.ca/MesenRunSpeedFix.zip Let me know if this build changes anything on your end.

As for .deb files, I had never actually taken a look at them before, but they appear to be binary files, and only contain the breakpoints/bookmarks and a few other options - none of these can really be imported into Mesen reliably. The labels are in the .nl files, which can't be imported either, but it might be possible to add support for those, but I'm not sure they can be perfectly mapped to Mesen's way of managing labels, I'll take a another look at this when I get a chance.
Nope, if anything it made it run even worse, sometimes now it runs TOO fast (i.e. over 60fps) which leads to sound skipping. And the original problem persists. I've noticed it is more likely to happen after alt-tabbing.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

rainwarrior wrote:An NES + DBG file is attached. (github source) A similar example to above can be found at the label "menu_title_redraw".
This should be fixed as of the latest commit (and the X register should properly return 1 for PAL NSF files). Haven't implemented the NSFe extension yet, though.
Let me know if there's anything else!
darkhog wrote:Nope, if anything it made it run even worse, sometimes now it runs TOO fast (i.e. over 60fps) which leads to sound skipping. And the original problem persists. I've noticed it is more likely to happen after alt-tabbing.
Yea, in hindsight, I should probably have spent a bit more time thinking about this before posting that build. Here's another build that should be better: https://www.mesen.ca/MesenTiming.zip
At the very least, when adding random 1-25 ms delays between frames, it's able to keep a fairly stable framerate (59-61fps) and the sound is mostly fine. The same delays with the 0.9.6 code causes a lot of static and the FPS drops to < 55, so hopefully that's a good sign.
Rahsennor wrote:Bottom line is, assume nothing. If you want stutter-free play, the only sure-fire solution is to sync to vsync and variable-rate-resample the audio, with no external clock.
The problem with vsync is that then you're not actually emulating the NES' actual speed (unless you process 2 frames between a vsync at some point to catch up, etc.), although I agree the difference is pretty small. That being said, Mesen's video/audio sync (obviously) needs some work still - the problem is that all the computers I have access to tend to run it properly, it's always on someone else's computer that the problems show up, which makes it pretty hard to debug things on my end.
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Re: Mesen - NES Emulator

Post by Rahsennor »

Sour wrote:The problem with vsync is that then you're not actually emulating the NES' actual speed (unless you process 2 frames between a vsync at some point to catch up, etc.), although I agree the difference is pretty small. That being said, Mesen's video/audio sync (obviously) needs some work still - the problem is that all the computers I have access to tend to run it properly, it's always on someone else's computer that the problems show up, which makes it pretty hard to debug things on my end.
I did say 'if you want stutter-free play.' My entire project is one giant war on stutter, up to and including rolling my own MC-FRUC lib to actually increase the framerate. Your needs/goals are different. For one thing, most of your users are probably less OCD about it than me.

But my point is, timers will always stutter. There is nothing you can do but accept that the CPU and GPU aren't on the same clock - even if it works on your machine, it won't on someone else's. If you're after 100% accurate-to-hardware speed you can either live with it or tell the user to set a custom modeline for 60.1 hz - if their hardware even supports it.
User avatar
James
Posts: 431
Joined: Sat Jan 22, 2005 8:51 am
Location: Chicago, IL
Contact:

Re: Mesen - NES Emulator

Post by James »

Sour wrote:I'm not too sure what nemulator syncs itself against, though (e.g vsync or a timer).
vsync, by default, but a timer can be used as well (especially useful for gsync/freesync).
Sour wrote:The only thing Mesen does at the moment is force the Windows-wide timer resolution to 1ms (only while the emulation is actually running), to help reduce the chances of sleeps being way off target (default resolution is 16ms, which is pretty horrible).
There are a couple of other things that help to varying degrees: 1) Increasing thread/process priority. 2) Using the Multimedia Class Scheduling Service (look at AvSetMmThreadCharacteristics()). Setting power settings to high performance does seem to have the biggest impact on jitter but, as koitsu pointed out, changing that from the emulator is a bad idea.
get nemulator
http://nemulator.com
darkhog
Posts: 192
Joined: Tue Jun 28, 2011 2:39 pm

Re: Mesen - NES Emulator

Post by darkhog »

Sour wrote:
rainwarrior wrote:An NES + DBG file is attached. (github source) A similar example to above can be found at the label "menu_title_redraw".
This should be fixed as of the latest commit (and the X register should properly return 1 for PAL NSF files). Haven't implemented the NSFe extension yet, though.
Let me know if there's anything else!
darkhog wrote:Nope, if anything it made it run even worse, sometimes now it runs TOO fast (i.e. over 60fps) which leads to sound skipping. And the original problem persists. I've noticed it is more likely to happen after alt-tabbing.
Yea, in hindsight, I should probably have spent a bit more time thinking about this before posting that build. Here's another build that should be better: https://www.mesen.ca/MesenTiming.zip
At the very least, when adding random 1-25 ms delays between frames, it's able to keep a fairly stable framerate (59-61fps) and the sound is mostly fine. The same delays with the 0.9.6 code causes a lot of static and the FPS drops to < 55, so hopefully that's a good sign.
Rahsennor wrote:Bottom line is, assume nothing. If you want stutter-free play, the only sure-fire solution is to sync to vsync and variable-rate-resample the audio, with no external clock.
The problem with vsync is that then you're not actually emulating the NES' actual speed (unless you process 2 frames between a vsync at some point to catch up, etc.), although I agree the difference is pretty small. That being said, Mesen's video/audio sync (obviously) needs some work still - the problem is that all the computers I have access to tend to run it properly, it's always on someone else's computer that the problems show up, which makes it pretty hard to debug things on my end.
Thanks, played few games that proved problematic in particular (such as Sachen's Pyramid, great puzzler and nice spin on Tetris formula, wish someone did a modern version of it, Pyramid 2 on the other hand... it sucked) and they work well on this build. FPS drops by themselves never bothered me, but the sound thing did.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

James wrote:1) Increasing thread/process priority. 2) Using the Multimedia Class Scheduling Service (look at AvSetMmThreadCharacteristics())
Yea, I seem to recall someone else mentioning that increasing thread/process priority right before sleeping helps reduce the odds of Windows waking up the thread far too late (although since most of the time is spent sleeping, probably simpler to always keep the priority higher).
Never heard of AvSetMmThreadCharacteristics() before, I'll take a look when I get a chance, thanks for the suggestion!
darkhog wrote:Thanks, played few games that proved problematic in particular and they work well on this build
Great, thanks for the confirmation! I'll update the code on Github with those timing changes.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Mesen - NES Emulator

Post by koitsu »

mkwong98
Posts: 282
Joined: Mon May 30, 2011 9:01 pm

Re: Mesen - NES Emulator

Post by mkwong98 »

Is it possible to dump the nametables and OAM in a file using the same format as the "Copy Nametable" function when that frame has new tiles? This way I can see how the tiles are used and don't need to play the game up to that point again. Thanks.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

mkwong98 wrote:Is it possible to dump the nametables and OAM in a file using the same format as the "Copy Nametable" function when that frame has new tiles?
What do you mean by "when that frame has new tiles"? New tiles compared to what?
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

I just released 0.9.7, which is mostly a bug fix release, along with a number of small improvements/fixes for the debugging tools (mostly based on bug reports/feedback on the forums).

Slightly related, but after some testing & talking with gauauu earlier, it looks like Mono 4.2.2 (which was the minimum requirement I used to list for Linux) is pretty terrible at running Mesen. Using Mono 4.6.2 seems to improve the UI's performance a decent amount and seems to fix some of the crashes that could occur while using the debugging tools. I mention 4.6.2 because it's the default version for Mono on Ubuntu 18, but I imagine any other more recent version should work just as well (or better). So, if anybody on Linux is currently using a relatively old version of Mono, I'd recommend upgrading if you can.

Also, just a heads up, 0.9.7 is most likely going to be the last release for 2018 - I'm leaving on a 10-week trip to Japan in a little over a week, so I will not have any time to spend on Mesen until I get back home in December. I'll still be checking the forums from time to time while I'm away, though.
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Mesen - NES Emulator

Post by Banshaku »

I didn't realize that for ubuntu but yes, it was quite fast with that version. If there was a way to make mono work on osx... :lol:

As for a trip to Japan, you are coming when the strongest typhoon occurs, hopefully there is not much left of them but this year is many, many weather related issues. The mid-south was affected by intense rain and Hokaido with a huge earthquake recently. If you go to Tokyo only then should be fine in general. Fukuoka if fine too :)

Downloading 0.9.7 now!
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

With some luck, there will be some progress with Winforms support on macOS eventually. I still want to investigate and try fixing the Wine performance issue eventually, too.

I'm landing in Tokyo on the 28th, so I'm hoping typhoon season ends before that (as far as I know, they're usually not too frequent in October, at least). I'll mostly be traveling back and forth between Tokyo & Kansai for the first few weeks, and then spending the last ~6 weeks or so in Fukuoka, so I should be fine for the most part (hopefully.) At the very least, the other 2 trips to Japan I went on around September/October weren't too bad, typhoon-wise (but maybe I got lucky!)
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Mesen - NES Emulator

Post by Banshaku »

For now I'm happy to use it on my windows box since it allows to debug raster effect quite easily. The new build now show me a possible issue while animating palette that I saw on nintendulator but not on mesen until now so maybe this is an actual bug in my code then ^^;;;

When you pass by Fukuoka, depending on your schedule, we can go out for a coffee after work and talk nes related stuff since I'm working downtown ;)
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Mesen - NES Emulator

Post by tepples »

User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Mesen - NES Emulator

Post by Banshaku »

Hopefully some day but now it is only carbon based and because it is 32 bits, it is an issue with the latest version of macOS. The fun of macs... If it finally becomes available, it will help for mesen, that's for sure.
Post Reply