Pages: 1
Posted on 02-01-19, 09:18 am

Karma: 457
Posts: 27/33
Since: 01-17-15
Posted by ray
But still, the X and Y position can sometimes be buggy. Often its different how they work. Sometimes you have to make some complicated things, sometimes not.

Posted by Arisotura
Perhaps those files support setting a certain origin for coordinates, like, position this from the top-left corner, position that from the center... That may explain the 'subtraction with 128'.

Posted by skawo
It should be said about the BNBL that the "0x10 Y position - 2 Bytes" is actually counted from the bottom.
Also, 0x09 and 0x11 are something else.

There's been a lot of speculation in the past about the confusing x/y position values in BNBL files. (As it turns out, BNCL also works the same way in this regard, so everything I'm about to explain applies to both file formats.) As part of the process of adding support for these files to ndspy, I RE'd the functions that parse them (02055A0C and 20042D8 for BNBL and BNCL, respectively) to finally settle the matter once and for all. Turns out it's pretty simple once you understand what's going on:
  • As was already known, there's a 2-byte value that defines the x position, and another one for the y position. (The y position is relative to the top of the screen, despite Skawo's claim to the contrary in 2014.)
  • However, these are not just raw coordinate values. Each of them contains both a coordinate and an alignment value:
  • value & 0xFFF yields the true raw coordinate value, and
  • (value >> 12) & 3 yields the alignment value.

And here are what the alignment values mean:
  • 0: the coordinate defines the left (or top) edge of the rectangle.
  • 1: the coordinate defines the center of the rectangle. To calculate the left (or top) edge, subtract (width + 1) / 2 from the coordinate. (For y coordinates, replace "width" with "height".) (The division is integer division, of course.)
  • 2: the coordinate defines the right (or bottom) edge of the rectangle. To calculate the left (or top) edge, subtract the width (or height) from the coordinate.
  • 3: same as 0.

Some miscellaneous notes:
  • In case it wasn't clear, x and y each have their own alignment value. Thus, you can combine them however you want, in order to position a rectangle by, say, the center of its right edge.
  • BNCL files don't contain any width/height values; these are obtained from the corresponding BNCD file.
  • The most significant two bits of each coordinate value are unused and ignored.

And that's all there is to it. In my opinion, alignment options like this should really be resolved at compile-time rather than at runtime, but this is how Nintendo chose to do it in this case. Hopefully this discovery will be useful!
The Newer Team
Posted on 03-13-19, 03:22 pm
Red Goomba
Who needs a title?

Karma: 188
Posts: 20/41
Since: 07-19-18
It really was, thank you:
Pages: 1