Mesen - NES Emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Paul_Atreides
Posts: 12
Joined: Mon Apr 13, 2020 5:24 am

Re: Mesen - NES Emulator

Post by Paul_Atreides » Tue May 05, 2020 11:03 pm

This is a very general question and I'd appreciate it if someone took the time to answer.

I'm working on an emulator core and can already correctly emulate some mapper0 games.
I'm using OLC's pixel game engine for rendering the frames, but want to progress to something more powerful.

I want to integrate the emulator's video in a GUI which allows menu items, buttons, and your typical GUI elements. I can see MESEN uses C# with WindowsForms for that.

My question: what technology / library is used by MESEN to render the game's frames?
How's this integrated in the WindowsForms main window (frmMain.cs)?

I came across the SDL library, but it's complicated to integrate into good-looking GUIs, and you have to use a number of alternative solutions, not WFs.

Sour
Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Wed May 06, 2020 6:49 pm

za909 wrote:
Mon May 04, 2020 11:28 pm
Thank you! I have "upgraded" the header to 2.0 and it works perfectly.
No problem, happy to hear you got it working!
Paul_Atreides wrote:
Tue May 05, 2020 11:03 pm
what technology / library is used by MESEN to render the game's frames?
On Windows, Mesen uses DirectX11, on Linux, it uses SDL2. Any graphic library should just let you specify any control as its rendering "window", but I don't really have too much experience there. I wouldn't necessarily recommend going the DX11 route - it's a lot more code to get something on the screen compared to SDL2, in my experience.

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 501
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Mesen - NES Emulator

Post by Jarhmander » Thu May 07, 2020 4:50 am

Simple question: why is SDL not used on Windows? Is it because it's harder to integrate into window controls? I ask because SDL should be usable on Windows and there would be no need to maintain 2 different rendering codes.
((λ (x) (x x)) (λ (x) (x x)))

Sour
Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Thu May 07, 2020 3:21 pm

Jarhmander wrote:
Thu May 07, 2020 4:50 am
Simple question: why is SDL not used on Windows?
There are a few reasons. Mesen did not have a Linux port for its first 2.5 years of development, for one. I also want to keep both distribution and compilation as simple as possible, so it's easier to rely on Windows APIs that are available on all modern Windows PCs, without requiring external stuff. Plus, it all currently seems to work well for the vast majority of users, so I'm not too keen on changing anything video/audio/input related and risk making something worse for some PCs, and there's virtually no maintenance cost to keeping DX11, as it is all code that I barely ever touch at this point.

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

Re: Mesen - NES Emulator

Post by mkwong98 » Sat May 23, 2020 4:04 am

Hi Sour, several people working with HD packs find it useful to have one of these:
set loop points in the music track in the hires.txt file
set two music files as a single track with one as introduction and one as looping
use specific tags in the ogg file as loop points info like https://rpgmaker.net/tutorials/1341/
Please have a look when you have time. Thanks.

User avatar
Controllerhead
Posts: 102
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Mesen - NES Emulator

Post by Controllerhead » Thu Jun 04, 2020 5:09 am

Is there a good way to determine PPU nametable mirroring in the Lua API?

I can get xCameraPosition, yCameraPosition, and top left corner nametable info just fine. Mirroring info doesn't seem to be anywhere. I can kind of understand why, from what i gather, cartridges do it through mapping or physically wiring pins to the address lines, and the PPU is kind of oblivious to the situation, so there are no internal registers for it or anything ...is that right?

Anyway, right now, i am writing bytes to the PPU, testing if they change in the mirrored positions, and then changing them back to the original each frame. It works fine, but it's probably not efficient, and i'm wondering if there is a better way or if i am missing something obvious in emu.getState().ppu.state or elsewhere. Now, before you say just check the header, many games change mirroring on the fly, such as Metroid, and i need that information on each frame. Any suggestions / help are appreciated. Thanks!

Sour
Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Thu Jun 04, 2020 1:34 pm

mkwong98 wrote:
Sat May 23, 2020 4:04 am
set loop points in the music track in the hires.txt file
This has been requested before in another thread here, iirc. It's on my list, but like so many other things on my list, I don't always have the time to get to them very quickly. It will hopefully be added before the next major release, though.
Controllerhead wrote:
Thu Jun 04, 2020 5:09 am
Is there a good way to determine PPU nametable mirroring in the Lua API?
There isn't at the moment, from what I can tell (other than reading and comparing the memory)
I thought state.cart.selectedChrPages might work, but it's an old API and only exposes the mappings from $0000-$1FFF. I could probably add another more precise set of values that could give proper access to all the mappings for the PPU, though.

Leonheart
Posts: 3
Joined: Thu Jun 04, 2020 2:33 pm

Re: Mesen - NES Emulator

Post by Leonheart » Thu Jun 04, 2020 2:44 pm

Sour wrote:
Thu Jun 04, 2020 1:34 pm
mkwong98 wrote:
Sat May 23, 2020 4:04 am
set loop points in the music track in the hires.txt file
This has been requested before in another thread here, iirc. It's on my list, but like so many other things on my list, I don't always have the time to get to them very quickly. It will hopefully be added before the next major release, though.
Controllerhead wrote:
Thu Jun 04, 2020 5:09 am
Is there a good way to determine PPU nametable mirroring in the Lua API?
There isn't at the moment, from what I can tell (other than reading and comparing the memory)
I thought state.cart.selectedChrPages might work, but it's an old API and only exposes the mappings from $0000-$1FFF. I could probably add another more precise set of values that could give proper access to all the mappings for the PPU, though.

Hey, sir. I gotta question. I love mesen very much but I have a problem playing a translated rom on it. When it's raw or not patched it plays but as I soon as I patched it.... the screen goes black. The game is DBZ - Kyoushou! Saiyajin. Nes

User avatar
Controllerhead
Posts: 102
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Mesen - NES Emulator

Post by Controllerhead » Thu Jun 04, 2020 4:30 pm

Sour wrote:
Thu Jun 04, 2020 1:34 pm
Controllerhead wrote:
Thu Jun 04, 2020 5:09 am
Is there a good way to determine PPU nametable mirroring in the Lua API?
There isn't at the moment, from what I can tell (other than reading and comparing the memory)
It's cool man, no worries, what i have works just fine. I just wanted to make sure i wasn't missing something obvious in the emu.getState() tables. It may be helpful to add in the future, but it's not important. Thanks for everything you do!

lidnariq
Posts: 9509
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Mesen - NES Emulator

Post by lidnariq » Thu Jul 02, 2020 8:45 pm

I've been having problems with clang builds being crashy. Extra crashy if compiled with -O3, or pgo, but still crashy (and slower than real-time) even at -O0. Mostly in the debugger.

A gcc build seems ok.

Since this sounds like "compiler bug" I don't even think you're the right person to mention this to, but ... I haven't the foggiest idea how to start weaving this down to something reproducible to report to the clang team either.

Sour
Posts: 815
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour » Thu Jul 02, 2020 9:45 pm

Is this recent? I haven't changed too much in the code in the past month or 2 that could affect this I think.
Did you try building the 0.9.9 or 0.9.8 releases to see if it changes anything vs latest? Any call stack when it crashes? How often does it happen?

It's entirely possible it's a real bug in my code, I don't test a whole lot in Linux in general, but always test using clang when I do (I think I'm still using clang 6.0 or something akin to build)

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 501
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Mesen - NES Emulator

Post by Jarhmander » Fri Jul 03, 2020 6:11 am

lidnariq wrote:
Thu Jul 02, 2020 8:45 pm
I've been having problems with clang builds being crashy. Extra crashy if compiled with -O3, or pgo, but still crashy (and slower than real-time) even at -O0. Mostly in the debugger.

A gcc build seems ok.

Since this sounds like "compiler bug" I don't even think you're the right person to mention this to, but ... I haven't the foggiest idea how to start weaving this down to something reproducible to report to the clang team either.
Is link-time optimization used? It tends to be crashy in my experience if not careful, and linking clang binaries with LTO using ld could be very unreliable. To be honest I haven't tried in years so it may be better than it used to be.
((λ (x) (x x)) (λ (x) (x x)))

lidnariq
Posts: 9509
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Mesen - NES Emulator

Post by lidnariq » Fri Jul 03, 2020 11:55 am

The crashes definitely started after 0.98. I don't remember what they looked like, unfortunately - all I remember is a CLR backtrace. Recent builds have been with clang 9, apparently. I'll try rebuilding HEAD with pgo and without pgo using a bunch of different versions of clang as soon as I have a little time to do this.

(As I understand it, PGO is LTO++, so yes, that's probably tickling that. However, it at least used to work, so there's a regression somewhere)

Bananmos
Posts: 532
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Mesen - NES Emulator

Post by Bananmos » Sat Aug 01, 2020 8:21 am

Non-technical stuff: Why did the Patreon get put on pause today? :shock:

I hope I speak not only for myself when saying I'm happy to keep donating monthly to this awesome tool, even if progress might slow in these sunny summer months. :)

Post Reply