🕹️
nesdoug-nes-guide
  • README
  • How to program an NES game in C
  • Introduction
  • What you need
  • How cc65 works
  • 01. Our first program
  • 02. What's a v-blank?
  • 03. VRAM buffer
  • 04. Full background
  • 05. Palettes
  • 06. Sprites
  • 07. Controllers
  • 08. BG collisions
  • 09. Scrolling
  • 10. Game loop
  • 11. Metatiles
  • 12. Scrolling right
  • 13. Scrolling up
  • 14. Platformer
  • 15. Music
  • 16. Sound effects
  • 17. DPCM Sound
  • 18. Sprite Zero
  • 19. More things
  • 20. Platformer again
  • 21. Finished Platformer
  • 22. Zapper / Power Pad
  • 23. Advanced mapper MMC1
  • 24. Advanced Mapper
  • Downloads, free games
  • Links and misc
  • Appendix, nesdoug library
  • Appendix, neslib library
Powered by GitBook
On this page

Was this helpful?

13. Scrolling up

Previous12. Scrolling rightNext14. Platformer

Last updated 4 years ago

Was this helpful?

This was much harder than scrolling right. If I had chosen to scroll downward, it might have been easier, because scrolling up is like going backwards in the code.

Skipping over the y values of 0xf0-ff wasn’t that bad as long as you use my functions add_scroll_y() and sub_scroll_y() that handles this for you. But, I also had to add them to the BG collision code, since you can be half in one nametable and half in another. And, the code assumes that Y position is between 0 and $ef.

Since scrolling up is going backwards, I’m starting at the maximum scroll position, and going backwards to 0.

I had to build the array of room arrays backwards too.

const unsigned char * const Rooms[]= { Room5, Room4, Room3, Room2, Room1 };

Anyway, I made 5 more rooms, in Tiled, and exported 5 more csv files, converted to C arrays, and imported those into the code.

16_Tiled

And after a few days of debugging (yikes) it finally works. I have to give some due respect to the guys who made games like Kid Icarus, or Metroid, or Ice Climber, because scrolling upward is not easy.

16_scroll_up

https://github.com/nesdoug/16_Scroll_Up/blob/master/scroll_up.c
https://github.com/nesdoug/16_Scroll_Up