Porting my game to NES, some newbie questions

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Haplo
Posts: 16
Joined: Wed Jan 18, 2023 1:14 am

Porting my game to NES, some newbie questions

Post by Haplo »

Hi all,

I'm porting my popular game Tenebra to NES. It has been an interesting adventure so far, mostly involving a lot of head-scratching. I have coded on C64/Plus-4, ZX Spectrum, Amstrad CPC, Atari ST, Amiga and some other systems, but NES is so different!
Definitely a lot to learn. I am quite enjoying it so far.

First quick question: I have the basic level loading working. Everything looks fine on FCEUX 2.3.0, but No$nes v1.2 gives me a grey screen. Judging by the debugger status it has run my code, just nothing is displayed.

How should I go about debugging this? Or should I even bother? Which emulators should I test with?

Thanks and wish me luck!
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Porting my game to NES, some newbie questions

Post by Fiskbit »

For development, we usually recommend Mesen as the gold standard. It is one of the most accurate emulators, has the best tools, and has a lot of options. Its debugger is able to use ca65 symbols, which is extremely convenient, and it has a very useful tool called the event viewer that lets you see where events such as PPU reads or writes (or even breakpoints that are configured to mark instead of break) happen on the screen. Under Options -> Emulation -> Advanced, there are also a lot of developer options (the top half of the menu) that are very helpful for ensuring your code is correct; in particular, I recommend using random values for default power on state for RAM. A new version of Mesen is coming within the next few months with a completely rewritten GUI that maintains roughly the same interface, too.

Mesen can be a bit heavy, so if it doesn't work on your system, FCEUX has equivalents for most of Mesen's tools and accuracy that is usually good enough, but not great. I'd still recommend doing some testing in Mesen or perhaps something like BizHawk's NEShawk core (but definitely not the QuickNES core).

I'm not sure what the issue is with no$nes, but I'm not sure if anyone is using that emulator seriously today, anyway. It never really comes up in any emulator discussions that I'm aware of and I suspect it hasn't been updated in some time, so it won't have incorporated any more modern discoveries and I'd be worried about bugs that haven't been found because it doesn't see widespread use.

Finally, there really is no replacement for doing at least some testing on real hardware. You often can get by without doing this, but as soon as you start doing things that rely on precise timing, or if you're turning rendering on or off in the middle of the screen, emulators just don't have the accuracy necessary to be confident the code is going to work. There are also things emulators just generally don't support, such as the approximately 30,000 cycles of warmup time after boot where the PPU ignores most writes. Flash cartridges are usually good enough for this task, though in some rare situations they can introduce problems of their own.
User avatar
Individualised
Posts: 310
Joined: Mon Sep 05, 2022 6:46 am

Re: Porting my game to NES, some newbie questions

Post by Individualised »

No$NES has not been supported for many years and is very inaccurate, use Mesen for debugging
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Porting my game to NES, some newbie questions

Post by Dwedit »

PuNES, Nintendulator, and Mesen are the gold standard for accurate emulators. FCEUX has a lot of comfortable debugging features, but its accuracy has fallen behind by comparison.

The big thing to watch out for is drawing too much during vblank time. If you do, less accurate emulators may make it look like everything is okay, and have illegal writes succeed.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Porting my game to NES, some newbie questions

Post by Oziphantom »

good luck with 2K of RAM. VBlank is going to be your main killer, and not having memory mapped VRAM. Mesen is the best, it's almost as good as VICE :D
Haplo
Posts: 16
Joined: Wed Jan 18, 2023 1:14 am

Re: Porting my game to NES, some newbie questions

Post by Haplo »

Thanks everyone. I didn't know Mesen even existed until now. It looks quite fancy, and the good news is my code works perfectly on it!

The VBlank timing already caught me off-guard a few times; it was the main source of the head-scratching I mentioned before. 2K of RAM should be fine, I should not need more thank 1.2K in total. I hope. We'll see.

Do I need to do anything about this 30,000 cycles of warm-up time? Do I need to sit in a tight loop at the start-up just in case?
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Porting my game to NES, some newbie questions

Post by Oziphantom »

init everything else, then wait for 2 Vblanks to be "sure sure" or 1 if you do a lot of other setup.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Porting my game to NES, some newbie questions

Post by Fiskbit »

We have example init code on the wiki. I recommend that yours look something like this.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Porting my game to NES, some newbie questions

Post by tokumaru »

Haplo wrote: Thu Jan 19, 2023 4:20 amI didn't know Mesen even existed until now. It looks quite fancy, and the good news is my code works perfectly on it!
Unless you're doing something fancy that pushes the limits of the hardware, it's generally a good idea to not ignore failures that happen even on inaccurate emulators. Even though FCEUX for example is well behind Mesen and Nintendulator in accurately, it's still a very popular emulator that runs thousands of games perfectly, so if your game doesn't run on it, that can still be a sign that something isn't right. Similarly, just because a program runs as intended on an accurate emulator, that alone isn't enough to guarantee that all is well. If you find your games misbehaving on any decent emulator, it's always a good idea to investigate.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Porting my game to NES, some newbie questions

Post by Dwedit »

Uninitialized mapper registers can also be a source of trouble, and if you're using something like mapper 2, also bus conflicts. FCEUX simulates those, other emulators might not.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Porting my game to NES, some newbie questions

Post by Pokun »

Mesen has a lot of options to randomize uninitialized hardware which are OFF by default. You should at least turn randomize RAM ON (FCEUX and Nintendulator NRS has this option as well). This usually shows up as garbage on the screen if you haven't initialized all VRAM. Basically don't leave anything in an unknown state except things like OAM which will decay right away anyway (and will be taken care of by the OAM-DMA before any garbage is displayed).

If you want your game to work with external controllers on a Famicom (which is a good thing for us Famicom users) you will want to make sure to read both bit 0 and 1 of $4016/$4017 and merge them, this is one of the things homebrew (and even some licensed games) tends to neglect. The wiki has examples of this too.


The NES is actually quite similar to many other consoles, computers and arcade systems, though none of them are in your list which are mostly systems that shares RAM between the CPU and the video hardware AFAIK.
Haplo
Posts: 16
Joined: Wed Jan 18, 2023 1:14 am

Re: Porting my game to NES, some newbie questions

Post by Haplo »

Again thanks a lot for your help. A lot of good information here.
@tokumaru: The code works fine on FCEUX. It is NO$NES that I am having trouble with.

I just realised the 6502 "shader" (for lack of a better word, the code that decides which parts of the screen need to be illuminated) I had written for C64/Plus4 depends heavily on having 40 characters/tiles per row. Which means I'll have to rewrite for NES. I already rewrote it once on Z80 for Spectrum and then extended it for CPC, I guess another rewrite won't kill me. And possibly another rewrite on 68000 in the future...

On the topic of initialisation...can I depend on Attribute Table 0 ($23C0-$23FF) being 0 at start-up, or better initialise it? Although initialising is not much effort anyway, so maybe I should just do it.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Porting my game to NES, some newbie questions

Post by Oziphantom »

init everything(PPU/OAM/RAM/Mapper registers) to a known safe value. Because they could run from a flash cart which has set up some menu and modified some value before it boots your game etc.
Haplo
Posts: 16
Joined: Wed Jan 18, 2023 1:14 am

Re: Porting my game to NES, some newbie questions

Post by Haplo »

Makes sense, thanks.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Porting my game to NES, some newbie questions

Post by tokumaru »

Haplo wrote: Fri Jan 20, 2023 2:53 amcan I depend on Attribute Table 0 ($23C0-$23FF) being 0 at start-up, or better initialise it?
Don't rely on anything being anything! :wink:
Post Reply