gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Weird Affine BG disappearing unless WrapAround enabled

#27205 - DiscoStew - Wed Oct 06, 2004 9:18 am

I'm using Cearn's method of implementing Mode7 with BG 2, so if you need references to how Mode7 is implemented his way, go here.

This is one of the weirdest things I've ever seen. I've got my background loaded correctly with the necessary map and tile cel data, and everything displays correctly. When the WrapAround bit is set, I can change the 'phi' value to whatever value I want, and the background will rotate to that specific value when ANDing it with 511 (the sin and cos tables are based off 512 = 2pi, not 360 = 2pi). However, when the WrapAround bit is not set, it will still work, except that once the 'phi' value is not between and including 0 to 128, the BG disappears.

The only thing I'm changing is the WrapAround bit in the BG control register. Just a thought, I'm thinking that once 'phi' goes beyond the range of 0 and 128, the actual X/Y position of the BG goes off in some direction, leaving the screen blank with no BG to display. However, wherever that position is, it is lined up perfectly whereever it is that when the WrapAround bit is set, the BG, in a sense, wraps itself back around to where it should be, making it look like it was there all along.

Any thoughts on this? Hopefully Cearn will see this.
_________________
DS - It's all about DiscoStew

#27242 - DiscoStew - Thu Oct 07, 2004 10:05 am

Well, I finally found the problem. I had tested the code to an extent that I pinpointed the problem right to where the displacements are calculated for each scanline. It seemed that a very large gap was made once 'phi' was out-of-range of 0 to 128, which would explain why the BG was disappearing. It was off somewhere in the distance. After checking, I saw that the calculation was correct according to Cearn's own code. I went even further to check each calculation and found out it had something to do with PA and PC. After thinking for a little bit, I went to check how I stored these values, and then I saw it. DX/DY/PA/PC were all unsigned! I was using unsigned values to calculate signed values! I went and made the correction, and now everything works as it should. I am very happy now. I can now continue with my project. =)

So all in all, if something doesn't work, perhaps a quick look at your variable types wouldn't hurt.
_________________
DS - It's all about DiscoStew