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.

DS development > Meaning of BGn_X0 & BGn_Y0 values

#160404 - koryspansel - Tue Jul 15, 2008 6:18 am

Evening,

gbatek has the following to say about the text scroll registers: "Specifies the coordinate of the upperleft first visible dot of BG0 background layer, ie. used to scroll the BG0 area."

However, that's not what I'm seeing. It seems to me that it's actually the translation from the BG origin to the screen origin. Anyone care to shed some light? Thanks

#160408 - Cydrak - Tue Jul 15, 2008 9:01 am

I think you have it right, but aren't those equivalent? :-)

If you prefer math,
Code:
Tv = S - B = <X0, Y0>   ; the BG=>screen translation you mention
S  = B + Tv             ; Screen origin
B  = S - Tv             ; BG origin

Setting B = (0, 0), you get S = Tv = (X0, Y0), the screen origin in BG coordinates. Which is what GBAtek tries to say: BG pixel (X0, Y0) appears in the upper-left onscreen.

If instead you use S = (0, 0), that gives B = -Tv = (-X0, -Y0), the BG origin relative to the screen. Increasing X0/Y0 pushes the BG the "other" way (here left/upward), which is also true.

In more basic terms, one could say that what you're moving is the camera (S = Tv), not the world (B = -Tv).

#160409 - koryspansel - Tue Jul 15, 2008 9:57 am

Inversely related anyway, depending on which coordinate system your talking about. That's essentially what I was confused about. I agree with the math 100%.

I guess the problem was here: "coordinate of the upperleft first visible dot of BG0." To me that means (0,0) of BG0 maps to (x,y) on screen (in a strangely worded manner, perhaps), but now I understand that he meant that coordinate (x,y) of BG0 that is the first one visible on the screen (0,0).

Thanks for the clarification!

#160419 - tepples - Tue Jul 15, 2008 1:30 pm

koryspansel wrote:
To me that means (0,0) of BG0 maps to (x,y) on screen (in a strangely worded manner, perhaps)

But that is how it works for sprites.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.