Mesen - NES Emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Jiggers
Posts: 4
Joined: Mon Mar 19, 2018 12:44 pm

Re: Mesen - NES Emulator

Post by Jiggers »

It seems like whenever I make significant changes to my rom, that the cheat window adds a new entry for it with the same name. I haven't tested to see if its making a new entry every single time I make any changes, or if it only makes a new entry if I open the cheat window after a change or what...

I'm also not sure if I'm using it correctly. But no matter what exporting or importing I do, I can't get old cheats to show up on a "new" game's entry. I have to manually add them in all over again. So my best guess is its doing the same thing save states were doing, where when loading cheats from a file, it makes a new game entry if the old game entry doesn't match? Perhaps the check for that could be merged with the save state check, if that's not too much trouble.

Anyway its not that big a deal at the moment, just a weird quirk I noticed!
spiiin
Posts: 3
Joined: Sun Apr 22, 2018 4:37 am

Re: Mesen - NES Emulator

Post by spiiin »

Hi!
I want to discuss scripting in emulators (in Mesen, at first, I think it's Lua system is best now).

I know, why authors of emulators choose Lua, it's minimalistic and lightweight, but, in fact, Lua is a language for non-programmers. Game developers use it for very limited scripting inside gaming, but the real power of scripting need more powerful languages like Python (for example, script system in IDA or Maya). But there is heavy language, embedding of python can cost size, so no emulator supports it now.

Other problem with Lua - there is hard to find extension modules and many of them created in c, so script author must compile it, with the right version of Lua developer headers, with 5.1 vs 5.3 difference, C compiler formats, 32 bit vs 64 bit hell - Mesen and Fceux, for example, use different Lua versions. This is definitely not what the author of the script wants to do.

Another way to solve a problem - we can communicate with Python via Lua. I made proof-of-concept example of python server communicate to Fceux (it already has statically linked LuaSocket package with low-level socket wrappers for Lua). I must create simple RPC-system over json - it's only protocol, that I could find a small working implementation on pure Lua. It really VERY simple and not good for real projects.

Now I implemented almost all functions from fceua Lua API except small not significant ones, so I have interactive python server for control fceux via sockets. Callbacks from Lua to python implemented, pause/unpause emulator from python implemented - it use bad documented ability of fceux to update lua sockets when emulator paused via gui.register callback. I'll post demo video after a day or two.

So I think, if Sour will agree to include even just LuaSocket module, I can port Lua-python bridge for Mesen.

Even better, if someone could find some working protocol for serialization for lua - protobuf is good one and some realizations implemented as static compilers from shared .proto files to pure Lua files, so no additional binaries needed to package with emulator, but I not found any solutions, working without any fixes.

P.s. sorry for possible mistakes, my English is poor.
spiiin
Posts: 3
Joined: Sun Apr 22, 2018 4:37 am

Re: Mesen - NES Emulator

Post by spiiin »

User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Mesen - NES Emulator

Post by zeroone »

spiiin wrote:Other problem with Lua - there is hard to find extension modules and many of them created in c, so script author must compile it, with the right version of Lua developer headers, with 5.1 vs 5.3 difference, C compiler formats, 32 bit vs 64 bit hell - Mesen and Fceux, for example, use different Lua versions. This is definitely not what the author of the script wants to do.
You might want to check out Nintaco. It provides programmatic control using C, C#, Java, Lua and Python.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

I wasn't even aware that Lua did not support sockets by default, to be perfectly honest. I can look into adding that.

As for Python, you pretty much guessed right - it's just way too big to embed directly into an emulator. I compared a few potential candidates (Lua, JS, Python) before settling on Lua due to its size/simplicity in terms of integration. Python was something like 30x bigger than Lua, if I recall correctly.

But realistically, except for very complex scripts built for a very specific purpose, I imagine Lua is good enough for the majority of use cases. Still, if you do make a Python bridge, I'm more than happy to add it to the built-in scripts I've started adding to the script window, since it could definitely be useful for other people too.
Jiggers wrote:It seems like whenever I make significant changes to my rom, that the cheat window adds a new entry for it with the same name.
Cheats are stored based on the game's CRC32 (iirc, it only checks the CRC32 for the PRG ROM, so modifications to CHR ROM won't cause any issues). It's done this way mostly because typically if the PRG ROM doesn't match, cheats won't work (if you ignore homebrew dev or rom hacking). I could probably add an option to "match by rom name" if no CRC match is found (or like you said, use the save state option to toggle this behavior)
spiiin
Posts: 3
Joined: Sun Apr 22, 2018 4:37 am

Re: Mesen - NES Emulator

Post by spiiin »

zeroone wrote: You might want to check out Nintaco. It provides programmatic control using C, C#, Java, Lua and Python.
Thanks, I'll check it and answer to thread about your emulator. I didn't know about it before.
Sour wrote: Still, if you do make a Python bridge, I'm more than happy to add it to the built-in scripts I've started adding to the script window, since it could definitely be useful for other people too.
Currently, my text rpc-json protocol is only for tests, it's not fast or robust, it's not very useful. But I'll post sources, at least for example for others, it's better than nothing.

Alsoe, if you want some examples to bundle with the emulator, feel free to use and modification my scripts even without mention to me:
https://github.com/spiiin/CadEditor/blo ... rallax.lua
Show lines when game doing horizontal scrolling changes
https://github.com/spiiin/CadEditor/blo ... Screen.lua
Simple "shaders" post-effects for any game, maybe I'll add some other shaders later - it's a good start for make other shaders, but need some fixes to gui press keys notifications.
gif - https://spiiin.dreamwidth.org/file/17583.gif
and video (bad quality :( ) - https://www.youtube.com/watch?v=04KOJmRYwko
mkwong98
Posts: 282
Joined: Mon May 30, 2011 9:01 pm

Re: Mesen - NES Emulator

Post by mkwong98 »

Sour, please can you add the "frameRange" condition type to the documentation? Also can you clarify which integer values in the conditions need to be in hex format? And what does "disableContours" option do? The description appears to be incomplete. Thank you.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Mesen - NES Emulator

Post by unregistered »

Hi Sour again,

It would be so helpful to me if you could add a check box on the Trace log file screen that would cause the registers and frame count to appear on the left when the file is generated. That would make them all alligned when using the indent with stack pointer and it would be more convenient to comment.

Thank you for reading my request. :)

edit: if you could just add a line like <SwitchRegistersLeft>false</SwitchRegistersLeft> under the TraceLoggerOptions in your setting.xml file that would be just as helpful for me because I plan to never switch back if you make the change. :)
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

spiiin wrote:Alsoe, if you want some examples to bundle with the emulator, feel free to use and modification my scripts
Thanks, I've added these to the dropdown. I haven't been able to sit down and take a look at enabling sockets yet, though (did some research a couple of weeks ago but got sidetracked and didn't get back to it yet).
mkwong98 wrote:can you add the "frameRange" condition type to the documentation? Also can you clarify which integer values in the conditions need to be in hex format? And what does "disableContours" option do? The description appears to be incomplete.
frameRange isn't in there mostly because I couldn't find a suitable way to describe it with words :) It's something kya needed for his HD Pack, and essentially it defines a fraction of frames during which the condition is valid, iirc. So if you put 1 and 3 as the parameters, 1 frame out of every 3 frames, the condition is true.
The fields marked as "integer" as meant to be decimal, and the ones marked as "hex" are supposed to be hex. I messed this up with the memoryCheck* conditions though, which all say "integer" even though it should all be "hex" instead.
disableContours disables a background-color outline around sprites when a HD background is enabled (otherwise sprites that contain transparent pixels that rely on the background being a specific color did not show up properly).
It's a bit of a pain to update the documentation in-between releases without including stuff that's not in 0.9.5, I'll try to get these fixed when the next version is released.
unregistered wrote:It would be so helpful to me if you could add a check box on the Trace log file screen that would cause the registers and frame count to appear on the left when the file is generated.
Hey, I read your PM, too - I understand you want to customize the trace log's output, but I'd prefer not to add too many options that just change how the information is displayed (rather than what is displayed) since the trace logger is already filled with options to control what's shown. I might be able to add some sort of "templating" that you can use to customize the output to be more or less whatever you want it to be (e.g by writing the format you want to use in a textbox), but I'm unsure how easy this would be considering the trace logger has to output 450+k lines per second to keep the emulation running at 60+fps.
mkwong98
Posts: 282
Joined: Mon May 30, 2011 9:01 pm

Re: Mesen - NES Emulator

Post by mkwong98 »

Sour wrote:frameRange isn't in there mostly because I couldn't find a suitable way to describe it with words :) It's something kya needed for his HD Pack, and essentially it defines a fraction of frames during which the condition is valid, iirc. So if you put 1 and 3 as the parameters, 1 frame out of every 3 frames, the condition is true.
I see something like this in kya's pack:

Code: Select all

<condition>Frame14PlusOf16,frameRange,10,e
<condition>Frame12PlusOf16,frameRange,10,c
<condition>Frame10PlusOf16,frameRange,10,a
<condition>Frame8PlusOf16,frameRange,10,8
<condition>Frame6PlusOf16,frameRange,10,6
<condition>Frame4PlusOf16,frameRange,10,4
<condition>Frame2PlusOf16,frameRange,10,2
It seems "frameRange,x,y" mean:

Code: Select all

result = ((frame % x) >= y);
Is this correct?
Sour wrote:disableContours disables a background-color outline around sprites when a HD background is enabled (otherwise sprites that contain transparent pixels that rely on the background being a specific color did not show up properly).
Sorry, still can't get me head around this, can you give an example?

The background tag has two optional values, what are the default values? 0.0 or 1.0?

Thanks.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Mesen - NES Emulator

Post by unregistered »

Sour wrote:
unregistered wrote:It would be so helpful to me if you could add a check box on the Trace log file screen that would cause the registers and frame count to appear on the left when the file is generated.
Hey, I read your PM, too - I understand you want to customize the trace log's output, but I'd prefer not to add too many options that just change how the information is displayed (rather than what is displayed) since the trace logger is already filled with options to control what's shown. I might be able to add some sort of "templating" that you can use to customize the output to be more or less whatever you want it to be (e.g by writing the format you want to use in a textbox), but I'm unsure how easy this would be considering the trace logger has to output 450+k lines per second to keep the emulation running at 60+fps.
I understand what you are saying. Well, if you do try and add "'templating'", that would be extreemly incredible, just don't worry about your emulator not running at 60fps during the trace log creation because running trace logs at 100% emulation speed isn't helpful, for me at least. Those files become way too big and using them is a huge chore. I usually build trace log files at 1% emulation speed. :)

edit: Hmm... I've never used a condition when making a trace log file; maybe utilizing condition(s) could warrant recording trace log files at 100% emulation speed. That's a really cool feature! :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Mesen - NES Emulator

Post by unregistered »

In Mesen's Trace Logger, after selecting "Text" display for the processor Status Flag Format, it appears, to me, that your text is incorrect. It could be nv-bdizc, instead of your nvb-dizc, to make more sense, I think. :) http://wiki.nesdev.com/w/index.php/CPU_ ... g_behavior (see lower B flag section :))

edit.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - NES Emulator

Post by Sour »

mkwong98 wrote:

Code: Select all

result = ((frame % x) >= y);
Is this correct?
That's how it's implemented in the code, yes.
mkwong98 wrote:Sorry, still can't get me head around this, can you give an example?
The black outline around the sprites in this screenshot is caused by this:
Image
Otherwise all the black on the sprites would end up showing the background instead - you can tell this solution isn't perfect if you look at the top right sprite's cape, the background's blue shows through it. If disableContours is turned on, the black disappears and the background will be shown for those pixels instead.
mkwong98 wrote:The background tag has two optional values, what are the default values? 0.0 or 1.0?
0.0 so that the background doesn't scroll - "1.0" would mean the background scrolls at the same speed as the PPU's scrolling registers change.
unregistered wrote:In Mesen's Trace Logger, after selecting "Text" display for the processor Status Flag Format, it appears, to me, that your text is incorrect. It could be nv-bdizc, instead of your nvb-dizc
It should probably always be "nv--dizc", actually, since the B flag does not exist on the CPU itself. Thanks - I'll fix it along with the other trace logger changes I am slowly working on.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Mesen - NES Emulator

Post by unregistered »

Sour wrote:
unregistered wrote:In Mesen's Trace Logger, after selecting "Text" display for the processor Status Flag Format, it appears, to me, that your text is incorrect. It could be nv-bdizc, instead of your nvb-dizc
It should probably always be "nv--dizc", actually, since the B flag does not exist on the CPU itself. Thanks - I'll fix it along with the other trace logger changes I am slowly working on.
That's a great idea! :D Was unsure about suggesting "nv--dizc" earlier, but now that makes a lot of sense after carefully reading and being blessed with finally understanding this nesdev wiki line:
(nesdev wiki) wrote:This is the only time and place where the B flag actually exists: not in the status register itself, but in bit 4 of the copy that is written to the stack.
"... along with the other trace logger changes I am... working on." :mrgreen: :shock: :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Mesen - NES Emulator

Post by unregistered »

Sour, when you have some free time, could you make your blue and black pause logo somewhat transparent? :) (It covers some white text from Lua Script and it would be very nice if I could read that text when Mesen is paused.)

:idea: Maybe think about adding a "Toggle Pause Logo" line under Shortcut Keys instead. Whatever takes the smallest amount of your time. I'm sorry for all of these requests.
Post Reply