Mesen - Emulator

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
ISSOtm
Posts: 58
Joined: Fri Jan 04, 2019 5:31 pm
Location: France, right of a pile of consoles
Contact:

Re: Mesen - Emulator

Post by ISSOtm »

Thank you very much Sour!! I'm glad GB Mesen is not dead—SGB LLE is already hard to come by, but one with such debugging tools is gonna be awesome.

I'm currently packaging it for Arch Linux (edit: done!), so installing there will be simpler; I just opened a PR that fixes some build errors I encountered along the way. Thank you for the lighter dependencies, by the way!

If I can suggest one thing: currently, "Store the data in my user profile" sets the data path to `~/Mesen2`, which is fine; however, it would be ideal to follow the "XDG base directories" spec (digest), and instead place the `Mesen2` directory in `$XDG_CONFIG_DIR/`, or `~./config/` if the env var doesn't exist.)
The French Lord of Laziness (and a huge Legend of Zelda fan)
https://github.com/ISSOtm
ASMu is laifu <3
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Mesen - Emulator

Post by creaothceann »

Since it's a multi-system emulator now, should the thread perhaps be moved to "Other Retro Dev"?
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Mesen - Emulator

Post by Fiskbit »

This is the primary emulator subforum here, and moving it to 'Other Retro Dev' would suggest it is for non-NES use cases. I think this is the best place for this thread to be.
User avatar
ISSOtm
Posts: 58
Joined: Fri Jan 04, 2019 5:31 pm
Location: France, right of a pile of consoles
Contact:

Re: Mesen - Emulator

Post by ISSOtm »

Here is my own feedback about the emulator itself. Given my background, it will all be related to GB, even when I fail to mention it.

It seems much faster than Mesen-S! I used to get lag with a bunch of windows open, but that seems to be a thing no more. Neat!
Also the new debugger code overlays are quite useful.

Here is a QoL feature request for GB:
Currently, the debugger breaks when writing to BGPD / OBPD during Mode 3; however, doing so with auto-increment enabled still performs the increment. I wrote an Evil™ palette engine that does this to skip colour #0 of OBJ palettes, and does not bother to check for Mode 3 (since the values are unused anyway).
The request is thus: *not* breaking on OBPD writes during Mode 3 if OBPI points to a "colour #0" byte.

I'm also not sure if you have seen the .sym file specification? We've created one recently to encourage consistency across implementations; feedback is welcome as well.

The GB register viewer's LCD panel does not seem to show GBC palette registers? (Arguably BGPD and OBPD are redundant with the palette viewer, but BGPI and OBPI aren't.)

For the monospace fonts, on Linux, I'd recommend defaulting to `monospace`. That's (AFAIK always) an alias to the system's preferred monospace font.

I got the debugger to break on an "Invalid VRAM access" (great!), but then clicking the "resume" or "step" buttons didn't do anything visible besides increasing the cycle counter; in particular, PC didn't move. Unfocusing the application to type this then coming back apparently locked it up entirely around 60% CPU usage (plus 80 from X11, for some reason).

The "call stack" functionality seems to be confused by stack manipulation functions. These two in particular:

Code: Select all

ChangeBank:
    pop hl
    push af
    jr SaveBank
RestoreBank::
    pop hl
    pop af
SaveBank:
    ldh [rCurBank], a
    ld [$2000], a
    jp hl
I also seem to be able to somewhat reliably make Mesen unresponsive through loading a ROM and marking regions of memory as code or data.
The French Lord of Laziness (and a huge Legend of Zelda fan)
https://github.com/ISSOtm
ASMu is laifu <3
bogaa
Posts: 8
Joined: Sat Oct 20, 2018 9:55 pm

Re: Mesen - Emulator

Post by bogaa »

Sour wrote: Sat Jan 28, 2023 10:27 am
bogaa wrote: Sat Jan 28, 2023 12:21 amHere are the once I tried.
Thanks for the info - it's possible that there's an issue with the .cue sheet parser or something akin, I'll try to find the problem.
If it helps here is the .cue file that failed:
https://www.dropbox.com/s/rd33n8irl208n ... D.cue?dl=0

I also had a issue setting up 6 button controller for the PC engine. I selected PS4 controller setup initially. No problem with the 2 button controller. But with 6 I can even clear all buttons and it will still rapid-fire D-Pad inputs in the 2 games I tried.

Image
https://imgur.com/zsGou59
User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 569
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Mesen - Emulator

Post by Jarhmander »

ISSOtm wrote: Sat Jan 28, 2023 11:24 am I'm currently packaging it for Arch Linux (edit: done!), so installing there will be simpler; I just opened a PR that fixes some build errors I encountered along the way. Thank you for the lighter dependencies, by the way!
Nice, thank you! Will vote for your package once I install it and play around a bit.
((λ (x) (x x)) (λ (x) (x x)))
User avatar
Gilbert
Posts: 564
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Mesen - Emulator

Post by Gilbert »

bogaa wrote: Sat Jan 28, 2023 1:33 pm I also had a issue setting up 6 button controller for the PC engine. I selected PS4 controller setup initially. No problem with the 2 button controller. But with 6 I can even clear all buttons and it will still rapid-fire D-Pad inputs in the 2 games I tried.
Not all PCE games support the 6 button controllers. In fact, most don't.
It's just normal that if you use a 6 button controller in a game that doesn't support it (including the CD System/Bios interface), you'll end up with erratic behaviour.
The real 6 button controller for the PCE contains a switch to switch back to 2 button mode, so you may still use it in games that support only the original controller. So, you should keep using 2 button mode unless the game supports it.
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - Emulator

Post by Sour »

ISSOtm wrote: Sat Jan 28, 2023 11:24 amIf I can suggest one thing: currently, "Store the data in my user profile" sets the data path to `~/Mesen2`
I've changed this to be like the original Mesen (stored in .config instead), didn't even realize it was different until now :p

Also changed the default fonts to use DejaVu Sans (Mono) or Noto Sans (Mono) if they are found (to be able to properly populate the dropdowns) and then fall back "monospace" and "sans-serif" if they can't (which makes the dropdown look empty, but at least uses a more appropriate font)
ISSOtm wrote: Sat Jan 28, 2023 1:27 pm but then clicking the "resume" or "step" buttons didn't do anything visible besides increasing the cycle counter; in particular, PC didn't move.
[...]
I also seem to be able to somewhat reliably make Mesen unresponsive through loading a ROM and marking regions of memory as code or data.
I've fixed a crash that occurred when debugging the GB core while in SGB mode, and fixed another bug that could crash the game when the debugger tried to access some values in memory. I'm not sure if these fixes are related to what you were experiencing though - I couldn't reproduce the exact issues you described. Can you still reproduce the crashes? I wasn't able to reproduce any crash via the "Invalid VRAM access" breakpoints, nor did it crash while I was spamming the mark as code/data shortcuts. (I didn't test this on Linux, though, if you're still getting the crashes with the latest commit on your end, I'll try reproducing it on my Linux VM)

Re: the call stack, it's likely I can't fix it - stack manipulation will always cause issues with it, it tries its best to keep up, but a lot of scenarios will confuse it. I haven't forgotten the other points you've mentioned, but haven't gotten to any of them yet.

Thanks again for the PR and also the Arch package!

bogaa wrote: Sat Jan 28, 2023 1:33 pmIf it helps here is the .cue file that failed:
Thanks, I'll take a look.
User avatar
ISSOtm
Posts: 58
Joined: Fri Jan 04, 2019 5:31 pm
Location: France, right of a pile of consoles
Contact:

Re: Mesen - Emulator

Post by ISSOtm »

Sour wrote: Sat Jan 28, 2023 11:17 pm
ISSOtm wrote: Sat Jan 28, 2023 11:24 amIf I can suggest one thing: currently, "Store the data in my user profile" sets the data path to `~/Mesen2`
I've changed this to be like the original Mesen (stored in .config instead), didn't even realize it was different until now :p
On one hand, thank you! On the other (maybe unrelated) hand, Mesen now crashes with the following when configuration exists (the "first start" dialog opens if appropriate, and the exception occurs after closing it). I have tried wiping the directory, but that doesn't fix it.

Code: Select all

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Mesen.Config.ConfigManager.LoadConfig()
   at Mesen.Config.ConfigManager.get_Config()
   at Mesen.ViewModels.MainWindowViewModel..ctor()
   at Mesen.Windows.MainWindow..ctor()
   at Mesen.App.OnFrameworkInitializationCompleted()
   at Avalonia.Controls.AppBuilderBase`1.Setup() in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 289
   at Avalonia.Controls.AppBuilderBase`1.SetupWithLifetime(IApplicationLifetime lifetime) in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 148
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 208
   at Mesen.Program.Main(String[] args)
Sour wrote: Sat Jan 28, 2023 11:17 pm (I didn't test this on Linux, though, if you're still getting the crashes with the latest commit on your end, I'll try reproducing it on my Linux VM)
I will see if I can figure out a setup to debug on my Linux machine; that should simplify troubleshooting. If you have any pointers regarding how to debug the program, though, that would be very appreciated.
Sour wrote: Sat Jan 28, 2023 11:17 pm Re: the call stack, it's likely I can't fix it - stack manipulation will always cause issues with it, it tries its best to keep up, but a lot of scenarios will confuse it. I haven't forgotten the other points you've mentioned, but haven't gotten to any of them yet.
The most annoying problem in that case was that the call stack showed a bunch of functions that weren't on it anymore; the best thing that I think can be done, I believe, is to pop off entries when SP goes past them, even if not by `ret`. That said, this can be taken care of later, there are likely more urgent things to take care of :P
Sour wrote: Sat Jan 28, 2023 11:17 pm Thanks again for the PR and also the Arch package!
Oh yeah, speaking of, there is now another PR waiting for you. That one adds CI for Windows and Linux ^^
The French Lord of Laziness (and a huge Legend of Zelda fan)
https://github.com/ISSOtm
ASMu is laifu <3
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Mesen - Emulator

Post by Dwedit »

Did the debugger BRK fix ever make it into Mesen2? I had added "BRK" to the list of control flow instructions, so that the debugger would not try to continue disassembling past a BRK instruction. This helped when disassembling Dragon Warrior 4.

I had also added in a ";" shortcut key for adding comments to a disassembly, that PR got merged into mkwong's and novasquirrel's fork.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: Mesen - Emulator

Post by Sour »

ISSOtm wrote: Sun Jan 29, 2023 7:03 amMesen now crashes with the following when configuration exists
Thanks, this is fixed now.
ISSOtm wrote: Sun Jan 29, 2023 7:03 amIf you have any pointers regarding how to debug the program, though, that would be very appreciated.
Generally, when I'm investigating crashes on Linux, I build with -O0 -g to get debug symbols, and then launch Mesen through GDB and trigger the crash. This usually lets GDB print out the current call stack, etc. (I forgot the exact commands - "bt" I think? I'm assuming you probably know this better than I do)

Although, I think I figured out what you were describing with the cycle counter only incrementing each time you pressed resume, since I just got the same behavior. On the CGB, if a DMA is causing multiple invalid vram accesses, each access will cause the debugger to break once. This isn't exactly a bug, but I realize it might be a bit annoying to deal with, as is.
ISSOtm wrote: Sun Jan 29, 2023 7:03 amOh yeah, speaking of, there is now another PR waiting for you. That one adds CI for Windows and Linux ^^
Thank you! I've updated the builds a bit and linked to the Windows & Linux (clang - ubuntu 20.04) builds from the readme (+ updated mesen.ca to link to the new repo instead) Also, I checked again, and as usual, clang seems to be produce code that's about 20% faster than GCC (for reasons I will never understand :p)

Dwedit wrote: Sun Jan 29, 2023 12:21 pm I had added "BRK" to the list of control flow instructions, so that the debugger would not try to continue disassembling past a BRK instruction
This should be fixed already - BRK is marked as an unconditional jump in NesDisUtils.cpp, so the disassembler should stop whenever it sees one. The shortcut to add comments isn't there at the moment, but I do have it on my list of things to add in the future.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Mesen - Emulator

Post by rainwarrior »

When changing the "hexadecimal display" to "decimal display" in the watch panel of the debugger, the value does not update if currently paused. Execution must resume for it to apply.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Mesen - Emulator

Post by Pokun »

bogaa wrote: Sat Jan 28, 2023 12:21 am
sour wrote: Fri Jan 27, 2023 6:01 pmHard to be sure what you did, but like Gilbert suggested, it sounds like you selected the basic "CD-ROM" addon instead of using the super/arcade cd-rom which are required for this game (that's what the text in your screenshot says)
- I did try CD ROM and it worked.
- Super CD ROM did not work
- Arcade CD ROM did not work

I did get a other iso and that worked flawless :D Is there a data base to verify your iso?

Here are the once I tried. I had no issue running it with Bizhawk.. But I should investigate more before I do posts sry

Only CD ROM worked
No database match. Akumajou_Dracula_X_-_Chi_no_Rinne_(NTSC-J)_[KMCD3005]
File/ROM SHA-1: 980682ADE83FF82314AECC91C04092EE1848DFDB
File/ROM CRC32: 68789807

Everything worked
No database match. Akumajou Dracula X - Chi no Rondo (JP) Worked
File/ROM SHA-1: 8728C4600691F31768FBEB75B2F508A00A758A18
File/ROM CRC32: A62E216F
I tried the first one (CRC32: 68789807) and it worked flawlessly for me with the arcade card set.
You not only have to set system card, you also have to specify a super CD system card 3 ROM (arcade card uses the same ROM as super CD system card 3). It will prompt for it when you try to load the game that needs it, I can't find a way to do it manually though (this goes for other BIOS/bootstrap-ROMs as well like the Game Boy boot-ROM or FDS BIOS).

The system card error screen in Akumajou Dracula X is one of the coolest in any PC-Engine game as you get to play an (intentionally) "broken" version of the game called Akumajyo Dracula X (peke).
User avatar
ISSOtm
Posts: 58
Joined: Fri Jan 04, 2019 5:31 pm
Location: France, right of a pile of consoles
Contact:

Re: Mesen - Emulator

Post by ISSOtm »

Sour wrote: Sun Jan 29, 2023 2:15 pm Generally, when I'm investigating crashes on Linux, I build with -O0 -g to get debug symbols, and then launch Mesen through GDB and trigger the crash. This usually lets GDB print out the current call stack, etc. (I forgot the exact commands - "bt" I think? I'm assuming you probably know this better than I do)
Well, the problem is that it's not a crash, but rather a lock-up, so no definitive stack trace; what's more, the entire UI becomes unresponsive, which seems to point at the lock-up occurring in the C# code. My research into how to debug C# on Linux seems to point at having to use either VS (therefore Windows, over SSH) or VS Code, neither option being really viable for me at the moment. *grumbles something about Microsoft dropping support for LLDB in favour of their own programs*

(Your remark about GDB reminds me that I ought to translate my GDB tutorial one day...)
Sour wrote: Sun Jan 29, 2023 2:15 pm Although, I think I figured out what you were describing with the cycle counter only incrementing each time you pressed resume, since I just got the same behavior. On the CGB, if a DMA is causing multiple invalid vram accesses, each access will cause the debugger to break once. This isn't exactly a bug, but I realize it might be a bit annoying to deal with, as is.
Ah, but the ROM in question wasn't involving DMAs at all. It was writing to OBPD (`ldh [c], a`) during Mode 3, which (correctly) broke on "bad VRAM access", but any command to resume execution (Escape to resume, step instruction, etc.) only reported "executed 2 cycles", increased the "elapsed cycles" count by 2, however PC did not move from the offending instruction.

It may have been related to the bug you just fixed, but unfortunately a recent new build error means I am not able to test at this moment. The shiny new CI seems to have caught it as well, at least. (I also left you a note about how to simplify the Linux jobs a bit.)
Sour wrote: Sun Jan 29, 2023 2:15 pm I've updated the builds a bit and linked to the Windows & Linux (clang - ubuntu 20.04) builds from the readme (+ updated mesen.ca to link to the new repo instead) Also, I checked again, and as usual, clang seems to be produce code that's about 20% faster than GCC (for reasons I will never understand :p)
Great! Just checked it out, and it looks good. It's hard to say why Clang may be generating more performant code than GCC without profiling, but it may involve e.g. more aggressive optimisation passes in LLVM, or squeezing more out of LTO.
The French Lord of Laziness (and a huge Legend of Zelda fan)
https://github.com/ISSOtm
ASMu is laifu <3
gzip
Posts: 23
Joined: Sat Mar 13, 2021 2:29 pm
Contact:

Re: Mesen - Emulator

Post by gzip »

This is looking great! A few things I noted (and some feature requests that might be obvious/easy):

Tilemap Viewer:
  • No longer called Nametable Viewer, is that because it's NES only language?
  • Missing field: Attribute Data
Tile Viewer:
  • Missing the tile editor (edit: I see it now in right click menu, the various Edit tiles options are nice!)
  • Hide Unused Tiles doesn't seem to work
  • Missing option: Display using last know palette
  • Feature Request: Click and drag for selection, then F2 opens Tile Editor with everything in the selection
  • Feature Request: Arrows navigate the current selection (increments of 8px)
  • Feature Request: Copy/paste tile/selection
Tile Editor:
  • Feature Request: Keys 1-4 select the corresponding palette entry for the current palette
  • Feature Request: Shift + Up/Down/Left/Right = Nudge everything 1 px in that direction
  • Feature Request: Ctrl + Up/Down = flip vertical
  • Feature Request: Ctrl + Left/Right = flip horizontal
  • Feature Request: Ctrl + Shift + Left/Right = Rotate 90 deg left/right
Palette Viewer:
  • Missing field: Pallete Address
  • Color Selector is missing (edit: I see it now in right-click menu, makes sense since click now selects a color)
Debugger:
  • Workspace is now JSON, need an option to import the old XML format
  • Exporting labels as mlb from 0.9.9 and then importing them into 2.0.0 produces errors with no labels imported
  • Missing option: Byte Code Display > Under
  • Missing option: PRG Address Display > Below CPU Address
General Feature Request:
  • Any time a memory address is double clicked (or maybe right clicked) in any of the above viewers then jump to that address in Memory Viewer
I have a few more feature requests for the Tile Editor that might not be as easy or obvious. I'll save those for later.
Post Reply