What is the significance of hi and lo variables?

jorotroid

Member
I have noticed in the scripts there are many variables that have a hi version and a lo version. Some examples include Object_h_speed_lo and Object_h_speed_hi, xHold_lo and xHold_y, and gameTimerLo and gameTimerHi. What is the concept behind having these two versions of a variable? I am currently attempting to write a script that affects the acceleration of an object, and this appears to be a topic I should understand with respect to Object_h_speed_lo and Object_h_speed_hi.
 

MistSonata

Moderator
Usually what this means is that it's a 16 bit variable, but since it's an 8 bit system it has to split 16 bit variables in half to store them. Usually this is to point to memory addresses, which are referred to with 16 bits despite being an 8 bit system, but it can also be used to store a variable that's more than 256.

There are other applications for something like this, though, such as storing the highest and lowest point of a bounding box for collision, or other such things.
 

jorotroid

Member
Thanks for pointing me in that direction! Yeah, 16 bit values are what's going on here. From that I did some testing and found that an object's Normal Max Speed variable in the NESMaker editor translated to x8 in the code. So if you set the Normal Max Speed to 1 in the code it treats it as an 8, 100 as 800, 255 as 2040. In addition to that, I also discovered that the screen position is also has a 16 bit "resolution." So in the code an object's x position can be between 0 and 65535. This means that each tile has 4096 units of position points. Of course this all gets rounded at some point to fit graphical resolution limitations, but having this internal resolution gives more control over an objects speed and acceleration. This knowledge will definitely help me with what I am tying to do right now.
 
Top Bottom