igwgames / nes-starter-kit

A Beginner's Guide and toolkit for NES game creation.
MIT License
214 stars 24 forks source link

Issues when using pal_bg(); #33

Closed mpdunlop closed 1 year ago

mpdunlop commented 1 year ago

Apologies - I'm not sure if this is an issue with my code, nes-starter-kit or with create-nes-game.

After creating the default template game using the create-nes-game command I'm attempting to change the background palette using neslib's pal_bg(*char). Once I call ppu_on_all(); the palette is updated but to incorrect colours. Setting the palette data in vram memory manually using vram_put() works so I'm not sure what I'm doing wrong.

The sample code using vram_put(): vram_put example

My alteration using pal_bg(): pal_bg_result

I've uploaded a repro to https://github.com/Dunnymeister/pal_bg_repro

I have tested using create-nes-game 1.0.10 and also after updating to 1.0.11.

potatolain commented 1 year ago

Hey there!

This looks like a quirk of neslib. There's an internal brightness tracker it has, and it seems like nothing initializes it for us. It's also possible create-nes-game isn't doing a setup step that neslib expects, though I can't find anything.

In short, you'll need to set the brightness to default somewhere before turning on the ppu. Do that with pal_bright(4). documentation for what that does - You can also use this in a loop to animate the screen fading in and out, for a nice transition.

I hope that helps, and sorry it's not super clear! Please let me know if you need more help.

ps: For the future, your example is just using create-nes-game. nes-starter-kit is a (very) short functioning game in C that can be customized. The name isn't great, I know.

mpdunlop commented 1 year ago

Thank you so much for looking into this for me, especially when it’s outside the domain of your project. Much appreciated!

potatolain commented 1 year ago

Glad to help! create-nes-game is also my project, so feel free to reach out if you hit more trouble