// fff1f8 sram__validate_slot ok 78 ms, 30 lines, 745 chars

/* Validate save slot $0479 (0-2): signature $E41B at $30:7FF8+2s and checksum $30:7FF0+2s ==
   sram__slot_checksum. Result in DP $00: $0000 valid, $8080 no signature (empty), $4040 bad
   checksum. */

void __jsl sram__validate_slot(void)

{
  ushort uVar1;
  undefined2 uVar2;
  ushort uVar3;
  ushort in_D;
  
  sram__slot_base();
  uVar3 = (*(ushort *)(uint3)(ushort)(in_D + 0x79) & 3) << 1;
  if (*(short *)((int3)sram__image.signature + (uint3)uVar3) == SRAM_SLOT_SIGNATURE) {
    uVar1 = sram__slot_checksum();
    if (uVar1 == *(ushort *)((int3)sram__image.checksum + (uint3)uVar3)) {
      uVar2 = 0;
    }
    else {
      uVar2 = 0x4040;
    }
  }
  else {
    uVar2 = 0x8080;
  }
  *(undefined2 *)(uint3)in_D = uVar2;
  return;
}
// c18a9d btl__timer_06_null ok 6 ms, 9 lines, 155 chars

/* Battle timer channel 6 (table $C1B92D): per-unit countdown; bit $0040 of $B186 marks it pending.
    */

void btl__timer_06_null(void)

{
  return;
}
// c18461 btl_ai__decide ok 239 ms, 269 lines, 8997 chars

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */
/* Enemy AI decision: timer channel 12. For the enemy whose turn came up ($B252/$AEC8) walks its
   script in bank CC (pointer $B1D2): blocks of <=2 four-byte conditions, FE, actions, FE; section
   ends FF. Conditions dispatch through the condition table; the first block whose conditions leave
   $AF24=0 is chosen and its current action is prepared (btl_ai__prep_action). Skipped blocks are
   stepped over by scanning for FE/FE. */

void btl_ai__decide(void)

{
  char cVar1;
  byte bVar2;
  undefined1 extraout_AH;
  undefined1 extraout_AH_00;
  undefined1 extraout_AH_01;
  undefined1 extraout_AH_02;
  undefined2 uVar3;
  undefined1 uVar4;
  undefined1 extraout_AH_03;
  undefined1 extraout_AH_04;
  undefined1 extraout_AH_05;
  ushort uVar5;
  
  DAT_7eb2c0 = '\0';
  DAT_7eb3b9 = 0;
  uVar5 = (ushort)DAT_7e0027;
  if ((DAT_7e0027 & 1) != 0) {
    uVar5 = 0;
    do {
      (&DAT_7eaeb2)[uVar5] = 0;
      uVar5 = uVar5 + 1;
    } while (uVar5 < 9);
    cVar1 = cRam7eb185;
    if (cRam7eb185 == '\0') {
      cVar1 = DAT_7eaec7;
    }
    bVar2 = (&DAT_7eb163)[(byte)(cVar1 - 1)];
    uVar5 = (ushort)bVar2;
    _DAT_7e0022 = uVar5;
    if (bVar2 < 3) {
      if (-1 < (char)(&DAT_7eb03a)[uVar5]) goto LAB_c1860a;
      FUN_fdab30(0,(ushort)bVar2 << 7,uVar5);
      if (DAT_7eaf23 != '\0') {
        DAT_7eb3f4 = DAT_7e0022;
        _DAT_7e0014 = _DAT_7e0022 & 0xff;
        FUN_c1b575();
        FUN_c1bce1();
        goto LAB_c1860a;
      }
      _DAT_7e0014 = _DAT_7e0022;
      uVar4 = 0;
      if ((&DAT_7e93ee)[(ushort)(byte)(DAT_7e0022 * '\a')] == '\0') {
        if ((btl__flags_2989 & 0x20) == 0) {
          (&DAT_7e93ee)[(ushort)(byte)(DAT_7e0022 * '\a')] = 1;
          DAT_7e00a1 = DAT_7e0014;
          btl__dispatch(1);
          uVar4 = extraout_AH_00;
          goto LAB_c18570;
        }
// c1aed3 dead__btl_ai__activate_reserve_enemy ok 7 ms, 27 lines, 1012 chars

/* Unreferenced (no pointer, no flow, 0 executions in the MAME session). Activates the reserve enemy
   whose formation id ($AF0D,X) equals $0E: $AF02,X=id, clears $AF15,X bit 7; none found -> $AF24=1.
   Shape of an AI action EXEC handler; no action op points here (JP actions 08/0E are RTS stubs). */

void dead__btl_ai__activate_reserve_enemy(void)

{
  char cVar1;
  ushort in_D;
  byte in_DBR;
  
  *(char *)((uint3)in_DBR << 0x10 | 0xaf24) = (char)in_D;
  cVar1 = *(char *)(uint3)(ushort)(in_D + 0xe);
  while ((cVar1 != *(char *)(((uint3)in_DBR << 0x10 | 0xaf0d) + (uint3)in_D) ||
         (cVar1 == *(char *)(((uint3)in_DBR << 0x10 | 0xaf02) + (uint3)in_D)))) {
    in_D = in_D + 1;
    if (7 < in_D) {
      *(undefined1 *)((uint3)in_DBR << 0x10 | 0xaf24) = 1;
      return;
    }
  }
  *(char *)(((uint3)in_DBR << 0x10 | 0xaf02) + (uint3)in_D) = cVar1;
  *(byte *)(((uint3)in_DBR << 0x10 | 0xaf15) + (uint3)in_D) =
       *(byte *)(((uint3)in_DBR << 0x10 | 0xaf15) + (uint3)in_D) & 0x7f;
  return;
}
