Scrolling and Bitmasks

Not a great deal done today, just trying to clean up some problems that occurred when the playfield wrapped. I noticed that the scanner was jumping a couple of pixels to the left or right when the environment passed the start point, and the mountains didn’t quite join up properly. The landers jumped about a pixel or so too.

I worked out that it’s something to do with the way I’m wrapping the playfield. I was going for the obvious:

void increaseScroll(u16 scroll) {
    // Add value
    this->scrollX += scroll;

    // Wrap around
    if (this->scrollX > 2047) {
        this->scrollX -= 2047;
    } else if (this->scrollX < 0) {
        this->scrollX += 2047;

This was a more efficient solution, though, and it seems to have solved the jitter problem (and removed a significant amount of code):

void increaseScroll(u16 scroll) {
    this->scrollX = (this->scrollX + scroll) & 2047;

(A little later)

Heh, realised that the problem with the original was that I was deleting or adding 2047 from the scroll value, when I should have been deleting/adding 2048 (since scroll value is greater than 2047). Duh!

Also started adding the landers to the scanner - the x positions are right, but the y positions are wrong. Need to take into account the y position of the mountains in the playfield and the y position of the mountains in the scanner before that’ll work properly.

Finally, had a quick play with WiFi in PALib. It crashed the DS the first two times I tried it, but the third time it worked fine. Might be something to do with having to acquire an IP address from the DHCP server - first two times the DHCP server was too slow; third time it had already got an address ready when the DS came back on-line. Just a guess, though.

It seems that I was wrong about needing to recompile PALib with a WiFi switch - to enable WiFi support, you just need to alter your makefile. Find this line:

LIBSPA  := -lpa9

Change it to this:

LIBSPA  := -lpa9 -ldswifi9

WiFi now works.