Skip to content
Clément Gallet edited this page Jun 25, 2014 · 1 revision
for (X=0; X<0x20; X++)
  $(822D+X) = 0;

if ($81AC & 0x40) == 0 // 8-High Monster
{
  X = $81AA * 8 + $D2A820 // contains 0xA824
  for (Y = 0; Y < 0x10; Y += 2, X++)
    $(822D+Y) = $(D20000+X)
}
else // 16-High Monster
{
  X = $81AA * 32 + $D2A822 // contains 0xAC24
  for (Y = 0; Y < 0x20; Y++, X++)
    $(822D+Y) = $(D20000+X)
}

/* Get the OR of all elements in $822D - $824D */
Z = 0;
for (X=0; X<0x20; X+=2)
{
  if ($(822D+X) == 0)
    break;
  Z = Z | $(822D+X);
}

Z = (Z >> 8) & (Z & 0x00FF << 8); // swap low and high bytes in Z

// Set $12 to be the position of the lowest 1 in Z?
for (Y = 0; Y < 0x10; Y++){
  Z <<= 1;
  if (Z >= 0x10000){ // Carry set
    Z -= 0x10000;
    $12 = Y;
}

$8253 = min(X, $8257); // Yes, the X from before. It probably contains the size of the array $822D - $824D
$8251 = $8252 = min($12, $8256);
$824D = $824E = 0;
Clone this wiki locally