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 »

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: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

za909 wrote: Mon May 04, 2020 11:28 pmThank 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 pmwhat 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: 569
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Mesen - NES Emulator

Post by Jarhmander »

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: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

Jarhmander wrote: Thu May 07, 2020 4:50 amSimple 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: 282
Joined: Mon May 30, 2011 9:01 pm

Re: Mesen - NES Emulator

Post by mkwong98 »

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: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Mesen - NES Emulator

Post by Controllerhead »

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!
Image
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

mkwong98 wrote: Sat May 23, 2020 4:04 amset 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 »

Sour wrote: Thu Jun 04, 2020 1:34 pm
mkwong98 wrote: Sat May 23, 2020 4:04 amset 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: 314
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Mesen - NES Emulator

Post by Controllerhead »

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!
Image
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Mesen - NES Emulator

Post by lidnariq »

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: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

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: 569
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Mesen - NES Emulator

Post by Jarhmander »

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: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Mesen - NES Emulator

Post by lidnariq »

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: 552
Joined: Wed Mar 09, 2005 9:08 am
Contact:

Re: Mesen - NES Emulator

Post by Bananmos »

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. :)
yaros
Posts: 47
Joined: Tue Aug 28, 2018 8:54 am

Re: Mesen - NES Emulator

Post by yaros »

Hey Sour, or maybe someone else know. I got back to using Mesen recently. If I remember correctly, when I used Mesen Ctrl+T power cycle used to reload ROM (or maybe I used another hotkey...), but now it doesn't. I have to manually go to File->Reload ROM in main menu. Is there something I'm missing or is my memory faulty?
Post Reply