Looking for NES emulator with custom break/log

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Looking for NES emulator with custom break/log

Post by Myself086 »

Is there an emulator that can log and break on the following?
- PC naturally crossing specific page boundaries
- PC branching (not jumping) over specific page boundaries
- Pulling data from stack that was written by non stack related opcodes (low priority)
- Wrapping zero page or stack
- Direct indexed access to I/O outside of page $40

This is for the development of Project Nested.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Looking for NES emulator with custom break/log

Post by Dwedit »

I can't think of any emulators that do that, but if you can build emulators from source, you might be able to modify the fetch loop to add those features.

When you say "Page", are you talking about switchable ROM banks (like 8k or 16k), or just 256 byte boundaries? (which are also called Pages)

The Magic of Scheherazade is known to cross bank boundaries without the banks being contiguous. You see it happen when enemies use a damaging spell against you in the RPG style battles. When the lower half of the screen displays the shaking animation, it is crossing the noncontiguous rom banks.
You can reproduce it quickly by using a password (like 5W) to start on a later world. Even QuickNES messes this up, fetching the second instruction byte from the wrong bank, and shaking the screen incorrectly.

I suggest identifying that game specifically, and rearranging the bank order so the banks are contiguous.




I can't think of any games that use popslides to read multiple values from the stack, but I've written some code that uses one.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Re: Looking for NES emulator with custom break/log

Post by Myself086 »

Dwedit wrote: Mon Jul 18, 2022 2:07 pm When you say "Page", are you talking about switchable ROM banks (like 8k or 16k), or just 256 byte boundaries? (which are also called Pages)
Crossing "specific" pages such as: $80, $a0, $c0, $e0, $00 and maybe $08, $10, $18, $20 though extremely unlikely.
Dwedit wrote: Mon Jul 18, 2022 2:07 pm The Magic of Scheherazade is known to cross bank boundaries without the banks being contiguous. You see it happen when enemies use a damaging spell against you in the RPG style battles. When the lower half of the screen displays the shaking animation, it is crossing the noncontiguous rom banks.
You can reproduce it quickly by using a password (like 5W) to start on a later world. Even QuickNES messes this up, fetching the second instruction byte from the wrong bank, and shaking the screen incorrectly.
I'll have to check that game out, though my issue will be much more pronounced than incorrect shake because even the next opcode will execute from the wrong bank. My current debugging tools can't show the exact value of the PC register, it can only show the entry point for the current sub-routine.
Dwedit wrote: Mon Jul 18, 2022 2:07 pm I can't think of any emulators that do that, but if you can build emulators from source, you might be able to modify the fetch loop to add those features.
I'm thinking of adding this to Mesen once I finish other fixes that I'm currently working on. I also want to see if anyone is interested in helping me on my project, not that I expect nor demand help.
Dwedit wrote: Mon Jul 18, 2022 2:07 pm I suggest identifying that game specifically, and rearranging the bank order so the banks are contiguous.
I'm not too far from being able to rearrange banks. There's already an option to force ROM ranges to be static and making $c000-$dfff static on MMC3 fixed a few games. I map MMC3 with contiguous banks while MMC1 just mirrors the current bank after crossing.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Looking for NES emulator with custom break/log

Post by Dwedit »

Sonic 1 on Game Gear does something where it branches past the SMS cartridge header to some more code. This is somewhat unusual, as this is data stuck right in the middle of code. I know this isn't a NES game, but it's basically the same kind of thing.

When I was working on SMSAdvance (The GBA Movie Player version), I decided to rearrange the memory layout, so that the first 32K ended up in GBA's Video RAM instead of EWRAM. But this caused the ROM file to no longer be contiguous. A branch past the second bank (where the cartridge header was) into the third bank jumped into bad memory. A backward branch from the third bank to the second bank jumped into bad memory.

So I needed to put something into memory there, both after the second bank, and before the third bank. I think I ended up copying the first/last 128 bytes of the bank (or was it 256, I forget). This gave the game something to execute when it did the branch into bad memory. If the game executed a Call, Jump, or Return (not a branch), then the program counter got moved back to its proper location again. The small piece of memory (128 or 256) was enough to make the game work.

An alternative was to put in a special dummy byte (some illegal instruction) that when the emulator executed it, it forced the program counter to move back into its proper location, and took 0 cycles to execute.


Meanwhile, my workaround for Scheherazade was to identify the game, then literally swap the memory around to make the specific bank it needed be contiguous with the last 16K.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Looking for NES emulator with custom break/log

Post by Fiskbit »

I asked Sour about this and he thinks this could be done in Mesen with Lua scripting, if you wanted to go that route.
Myself086
Posts: 158
Joined: Sat Nov 10, 2018 2:49 pm

Re: Looking for NES emulator with custom break/log

Post by Myself086 »

Fiskbit wrote: Tue Jul 19, 2022 4:06 pm I asked Sour about this and he thinks this could be done in Mesen with Lua scripting, if you wanted to go that route.
It looks possible to me too but my only nitpick is state.cpu.pc returns the address for the next opcode.
Definitely giving this a try!
Post Reply