I'm creating a NES emulator.

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
Individualised
Posts: 310
Joined: Mon Sep 05, 2022 6:46 am

Re: I'm creating a NES emulator.

Post by Individualised »

Just to be clear, are you aware that memory-mapped registers (including those belonging to mappers) don't actually act as memory, and that some addresses can be written to but they don't actually "store" that value and the same address may read a different value belonging to i.e. ROM? I feel you may have a misunderstanding about how that works but I also may just be being stupid and didn't read the thread properly, my explanation is not the greatest either.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: I'm creating a NES emulator.

Post by tokumaru »

To clarify things a bit: NES games, the ones that come in cartridges, have the game program stored in ROM (read-only memory), and that memory is NEVER writable. There are a few obscure mappers (and also the Famicom Disk System) that are able to map RAM to the $8000-$FFFF memory area, but ROM is the most common type of memory by far.

Most cartridges, in addition to the memories (PRG and CHR), also contain a mapper, but since the cartridge connector doesn't have any dedicated connections for communicating with mappers, they needed to find an alternative way to do that. The solution they found was to "write to ROM" and have the cartridge hardware intercept those writes and redirect them to the mapper chips instead. Sometimes they're still routed to the ROM chip as well, but since it's ROM, nothing happens (except for something called a "bus conflict", which can be emulated but is generally not necessary).

Whenever you see a game attempting to write to $8000-$FFFF, that's actually meant to control a mapper, and you should NEVER allow those writes to go through and modify the ROM data. You can't completely ignore the writes though, you still need to redirect the written values to the appropriate mapper registers, or games with mappers will just not work.
User avatar
LordEmilio
Posts: 18
Joined: Sat Oct 01, 2022 11:39 am

Re: I'm creating a NES emulator.

Post by LordEmilio »

Well I fixed it... Last time, I prohibited writings AND readings from the upper banks, which was a real mistake.

Now it works better. I've removed the "wrong read address" error message, and rather am bringing < $0000 pointing addresses forward to $0000, and > $FFFF back to $FFFF. And you know what? Now I've got one more ROM displaying something on screen. :D :beer:

Others like Donkey Kong or SMB still are displaying blank screens, I don't know which string to pull to fix that issue.

The JMP instruction using opcode $6C is however acting funny, it jumps to odd addresses. I don't know how this opcode could get any jump address using Implied addressing mode, as this mode doesn't take any parameter. That makes me a bit puzzled. :|

When this is fixed, I could start adding some MMC routines, mappers, and even APU. I'm studying WinMM library to play waveform sounds, because VS' basic classes are not fast enough to play a buffer in real time, there are gaps between any played sounds.

Thank you,
LordEmilio.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: I'm creating a NES emulator.

Post by Fiskbit »

The $6C JMP is not implied, it's indirect. It takes a 2-byte operand. For JMP ($8000), for example, you jump to whatever address is contained at $8000-8001 (so you read those 2 bytes to get the address to jump to).

If your address goes under $0000, it actually wraps to $FFFF; it doesn't clamp at $0000. Similarly, if it goes above $FFFF, it wraps to $0000. You can simply AND your address by $FFFF to keep it into the 16-bit space. (And the zero page addressing mode wraps within zero page, so $00 wraps to $FF and $FF wraps to $00.)
User avatar
LordEmilio
Posts: 18
Joined: Sat Oct 01, 2022 11:39 am

Re: I'm creating a NES emulator.

Post by LordEmilio »

Hello guys,

Just to tell you that JadeNES is still alive. I've been on some real programming issues with this project.

Actually, I was very confused with what's "opcode cycle length" and "opcode byte length" and inverted them both, that's why some ROMs run funny.

Plus the fact reading from the PPU Register $2007 would transfer the value to the PPU Latch variable, which is prone to modifications between instructions. So ROMs like CART.NES would not work. Again, it was right under my nose, and I did not want to see it. :oops: Still nothing with Super Mario Bros and Donkey Kong though, and Ice Climber is displaying a broken title screen. :idea:

I've fixed other bugs and now, I'm working on another NES emulator project written in pure C++. Not sure about the name, I'm calling it EmptyNES right now, I'm still trying to enhance JadeNES anyway (VB), and that's the fact of re-writing an emulator from scratch that led me to find and solve huge core bugs.

Plus EmptyNES is entirely in English this time, even if the CPU loop is not perfect (infinite loop with STA and BMI near the reset address), and it's still not rendering anything, except a gray screen.

Image

I don't know what's wrong this time, I'm going to modify the debugger to display more values, and maybe find what's wrong with the CPU loop.

Thanks for your answers.

LordEmilio
Post Reply