Idioma…
9 usuários online: Golden Yoshi, GrenCarret, k0nk4r4, MorrieTheMagpie, pakkie, schema_tuna, xen_gamer, ZAGESAW, Zavok - Visitantes: 99 - Bots: 198
Usuários: 55.618 (2.425 ativos)
Último usuário: CrazilyNutty

$00DC4F - How it works

Mario's position data is formatted like this in binary:
PPPPPPPPPPPPPPPP.ssss0000

ssss0000: Position fraction bits, Stored in RAM $13DA and $13DC
ssss = subpixels, this ranges from 0-15.

PPPPPPPPPPPPPPPP: Position, in pixels (stored in $94 and $96). Ranges from 0-65535 (or (-32768) to 32767 in the signed context)


Mario's speed data ($7B and $7D) is formatted like this in binary:
SPPPssss

ssss = subpixels
PPP = pixels. When the S bit is clear, this is treated as 0000000000000PPP, otherwise 1111111111111PPP. Therefore increasing the size and keeping the value it represents.
S = sign bit


To perform movement:
  1. First take the speed value's SPPPssss, move it to the high nybble (4 ASLs, SPPPssss becomes ssss0000) and add it with the fraction bits, store that as the new fraction bits. The carry bit after adding will be used later (if the addition exceeds 15, carry is set, otherwise clear).

  2. Second, we are handling the P bits. The speed value is only 3-bit and the pixel position is 16-bit, so we need to expand the number of bits so that we can correctly adjust to the 16-bit position. We take the speed value, and move the upper nybble to the lower (4 LSRs) so that the PPP bits are at the lowest bit position (it is now 0000SPPP). Check if the S bit is set (CMP #$08), and if not (less than 8), treat it as 0000000000000PPP otherwise (≥ 8) 1111111111111PPP. This handles the data using two's complement when handling signed values.

  3. Finally, perform movement in pixels. We take the expanded value from the previous step, and add by the pixel position, adding with the carry obtained from the first step (so that if enough fractional movement are made, move an additional pixel).