13. Scrolling up

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.  The code assumes that Y position is between 0 and $ef… so you need to skip over the values 0xf0-0xff. These 2 functions can do that for you.

int add_scroll_y(unsigned char add, unsigned int scroll);

This adds an 8 bit value with the 16 bit scroll value, and returns a new scroll value.


int sub_scroll_y(unsigned char add, unsigned int scroll);

This subtracts an 8 bit value from the 16 bit scroll value, and returns a new scroll value.


But, I also had to use them with the BG collision code, since you can be half in one nametable and half in another.


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.


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 without bugs was not easy.

Note: we are using the horizontal mirroring (vertical scrolling) cfg file.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s