decompiled_code:
__int64 __fastcall quantum_snd_w(unsigned int a1)
{
bool v1; // zf
__int64 v2; // rdi
__int64 result; // rax

v1 = (a1 & 0x20) == 0;
v2 = (a1 >> 1) & 0xF;
if ( v1 )
result = pokey1_w(v2);
else
result = pokey2_w(v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
bool v1; // zf
__int64 v2; // rdi
__int64 result; // rax

v1 = (a1 & 0x20) == 0;
v2 = (a1 >> 1) & 0xF;
if ( v1 )
result = pokey1_w(v2);
else
result = pokey2_w(v2);
return result;
}

original_code:
void quantum_snd_w(offs_t offset,data_t data)
{
 if (offset & 0x20)
  pokey2_w((offset >> 1) % 0x10,data);
 else
  pokey1_w((offset >> 1) % 0x10,data);
}

canonical_original_code:
void quantum_snd_w(unsigned int offset, unsigned int data)
{
 if (offset & 0x20)
  pokey2_w((offset >> 1) % 0x10,data);
 else
  pokey1_w((offset >> 1) % 0x10,data);
}


decompiled_code:
__int64 __fastcall quantum_snd_r(unsigned int a1)
{
bool v1; // zf
__int64 v2; // rdi
__int64 result; // rax

v1 = (a1 & 0x20) == 0;
v2 = (a1 >> 1) & 0xF;
if ( v1 )
result = pokey1_r(v2);
else
result = pokey2_r(v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
bool v1; // zf
__int64 v2; // rdi
__int64 result; // rax

v1 = (a1 & 0x20) == 0;
v2 = (a1 >> 1) & 0xF;
if ( v1 )
result = pokey1_r(v2);
else
result = pokey2_r(v2);
return result;
}

original_code:
data_t quantum_snd_r(offs_t offset)
{
 if (offset & 0x20)
  return pokey2_r((offset >> 1) % 0x10);
 else
  return pokey1_r((offset >> 1) % 0x10);
}

canonical_original_code:
unsigned int quantum_snd_r(unsigned int offset)
{
 if (offset & 0x20)
  return pokey2_r((offset >> 1) % 0x10);
 else
  return pokey1_r((offset >> 1) % 0x10);
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall quantum_trackball_r(unsigned int a1)
{
int v1; // ebx

v1 = input_port_4_r();
return 16 * v1 + (unsigned int)input_port_3_r(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v1; // ebx

v1 = input_port_4_r();
return 16 * v1 + (unsigned int)input_port_3_r(a1);
}

original_code:
data_t quantum_trackball_r(offs_t offset)
{
 int x, y;
 x = input_port_4_r (offset);
 y = input_port_3_r (offset);
 return (x << 4) + y;
}

canonical_original_code:
unsigned int quantum_trackball_r(unsigned int offset)
{
 int x; int y;
 x = input_port_4_r (offset);
 y = input_port_3_r (offset);
 return (x << 4) + y;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall quantum_input_1_r(char a1)
{
return ((unsigned int)input_port_1_r(0LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return ((unsigned int)input_port_1_r(0LL) << (7 - a1)) & 0x80;
}

original_code:
data_t quantum_input_1_r(offs_t offset)
{
 return (input_port_1_r (0) << (7 - (offset - 0x00))) & 0x80;
}

canonical_original_code:
unsigned int quantum_input_1_r(unsigned int offset)
{
 return (input_port_1_r (0) << (7 - (offset - 0x00))) & 0x80;
}


decompiled_code:
__int64 __fastcall quantum_input_2_r(char a1)
{
return ((unsigned int)input_port_2_r(0LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return ((unsigned int)input_port_2_r(0LL) << (7 - a1)) & 0x80;
}

original_code:
data_t quantum_input_2_r(offs_t offset)
{
 return (input_port_2_r (0) << (7 - (offset - 0x00))) & 0x80;
}

canonical_original_code:
unsigned int quantum_input_2_r(unsigned int offset)
{
 return (input_port_2_r (0) << (7 - (offset - 0x00))) & 0x80;
}


decompiled_code:
__int64 __fastcall simpsons_nvram_handler(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

original_code:
void simpsons_nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

canonical_original_code:
void simpsons_nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

variable_types:
file
void *

return_type: void


decompiled_code:
__int64 simpsons_eeprom_r()
{
int v0; // ebx
int v1; // ebx

v0 = EEPROM_read_bit();
v1 = readinputport(5LL) & 1 | (16 * v0);
if ( init_eeprom_count )
{
v1 &= 0xFEu;
--init_eeprom_count;
}
return v1 | 0x20u;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx
int v1; // ebx

v0 = EEPROM_read_bit();
v1 = readinputport(5LL) & 1 | (16 * v0);
if ( init_eeprom_count )
{
v1 &= 0xFEu;
--init_eeprom_count;
}
return v1 | 0x20u;
}

original_code:
data_t simpsons_eeprom_r(offs_t offset)
{
 int res;
 res = (EEPROM_read_bit() << 4);
 res |= 0x20;
 res |= readinputport( 5 ) & 1;
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xfe;
 }
 return res;
}

canonical_original_code:
unsigned int simpsons_eeprom_r(unsigned int offset)
{
 int res;
 res = (EEPROM_read_bit() << 4);
 res |= 0x20;
 res |= readinputport( 5 ) & 1;
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xfe;
 }
 return res;
}

variable_types: res int


decompiled_code:
__int64 __fastcall simpsons_coin_counter_w(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
K052109_set_RMRD_line((a2 >> 3) & 1);
return K053246_set_OBJCHA_line(((unsigned __int8)(a2 >> 5) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
K052109_set_RMRD_line((a2 >> 3) & 1);
return K053246_set_OBJCHA_line(((unsigned __int8)(a2 >> 5) ^ 1) & 1);
}

original_code:
void simpsons_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x08) ? 1 : 0);
 K053246_set_OBJCHA_line((~data & 0x20) ? 1 : 0);
}

canonical_original_code:
void simpsons_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x08) ? 1 : 0);
 K053246_set_OBJCHA_line((~data & 0x20) ? 1 : 0);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 simpsons_sound_interrupt_r()
{
cpu_cause_interrupt(1LL, 255LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
cpu_cause_interrupt(1LL, 255LL);
return 0LL;
}

original_code:
data_t simpsons_sound_interrupt_r(offs_t offset)
{
 cpu_cause_interrupt( 1, 0xff );
 return 0x00;
}

canonical_original_code:
unsigned int simpsons_sound_interrupt_r(unsigned int offset)
{
 cpu_cause_interrupt( 1, 0xff );
 return 0x00;
}


decompiled_code:
__int64 __fastcall simpsons_sound_r(int a1)
{
int v1; // edx
__int64 result; // rax

if ( *(_DWORD *)(Machine + 836LL) )
return K053260_r((unsigned int)(a1 + 2));
v1 = res_0 & 0xFC;
result = v1 | ((_BYTE)res_0 + 1) & 3u;
res_0 = v1 | ((_BYTE)res_0 + 1) & 3;
if ( !a1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // edx
__int64 result; // rax

if ( *(_DWORD *)(Machine + 836LL) )
return K053260_r((unsigned int)(a1 + 2));
v1 = res_0 & 0xFC;
result = v1 | ((_BYTE)res_0 + 1) & 3u;
res_0 = v1 | ((_BYTE)res_0 + 1) & 3;
if ( !a1 )
result = 0LL;
return result;
}

original_code:
data_t simpsons_sound_r(offs_t offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else
 {
  static int res = 0x80;
  res = (res & 0xfc) | ((res + 1) & 0x03);
  return offset ? res : 0x00;
 }
}

canonical_original_code:
unsigned int simpsons_sound_r(unsigned int offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else
 {
  static int res = 0x80;
  res = (res & 0xfc) | ((res + 1) & 0x03);
  return offset ? res : 0x00;
 }
}


original_code:
data_t simpsons_speedup1_r(offs_t offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int data1 = RAM[0x486a];
 if ( data1 == 0 )
 {
  int data2 = ( RAM[0x4942] << 8 ) | RAM[0x4943];
  if ( data2 < memory_region_length(REGION_CPU1) )
  {
   data2 = ( RAM[data2] << 8 ) | RAM[data2 + 1];
   if ( data2 == 0xffff )
    cpu_spinuntil_int();
   return RAM[0x4942];
  }
  return RAM[0x4942];
 }
 if ( data1 == 1 )
  RAM[0x486a]--;
 return RAM[0x4942];
}

canonical_original_code:
unsigned int simpsons_speedup1_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int data1 = RAM[0x486a];
 if ( data1 == 0 )
 {
  int data2 = ( RAM[0x4942] << 8 ) | RAM[0x4943];
  if ( data2 < memory_region_length(REGION_CPU1) )
  {
   data2 = ( RAM[data2] << 8 ) | RAM[data2 + 1];
   if ( data2 == 0xffff )
    cpu_spinuntil_int();
   return RAM[0x4942];
  }
  return RAM[0x4942];
 }
 if ( data1 == 1 )
  RAM[0x486a]--;
 return RAM[0x4942];
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 simpsons_speedup2_r()
{
unsigned __int8 v0; // bl

v0 = *(_BYTE *)(memory_region(129LL) + 18518);
if ( v0 != 1 )
return v0;
cpu_spinuntil_int();
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int8 v0; // bl

v0 = *(_BYTE *)(memory_region(129LL) + 18518);
if ( v0 != 1 )
return v0;
cpu_spinuntil_int();
return 1LL;
}

original_code:
data_t simpsons_speedup2_r(offs_t offset)
{
 int data = memory_region(REGION_CPU1)[0x4856];
 if ( data == 1 )
  cpu_spinuntil_int();
 return data;
}

canonical_original_code:
unsigned int simpsons_speedup2_r(unsigned int offset)
{
 int data = memory_region(REGION_CPU1)[0x4856];
 if ( data == 1 )
  cpu_spinuntil_int();
 return data;
}

variable_types: data int


decompiled_code:
void *__fastcall simpsons_banking(char a1)
{
__int64 v1; // rdx
int v2; // eax
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = a1 & 0xF0;
if ( v2 == 32 )
{
v1 += ((a1 & 0xF) + 40) << 13;
}
else if ( (a1 & 0xF0u) > 0x20 )
{
if ( v2 == 48 )
v1 += ((a1 & 0xF) + 56) << 13;
}
else if ( (a1 & 0xF0) != 0 )
{
if ( v2 == 16 )
v1 += ((a1 & 0xF) + 24) << 13;
}
else
{
v1 += ((a1 & 0xF) + 8) << 13;
}
cpu_bankbase[1] = v1;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
static void simpsons_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 switch ( lines & 0xf0 )
 {
  case 0x00:
   offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x10:
   offs = 0x30000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x20:
   offs = 0x50000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x30:
   offs = 0x70000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  default:
  break;
 }
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void simpsons_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 switch ( lines & 0xf0 )
 {
  case 0x00:
   offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x10:
   offs = 0x30000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x20:
   offs = 0x50000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x30:
   offs = 0x70000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  default:
  break;
 }
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int

variable_types: offs int


decompiled_code:
void *__fastcall z80_bankswitch_w(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[2] = memory_region(130LL) + (((a2 & 7u) + 2) << 14);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[2] = memory_region(130LL) + (((a2 & 7u) + 2) << 14);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
static void z80_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 offset = 0x10000 + ( ( ( data & 7 ) - 2 ) * 0x4000 );
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[ offset ]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void z80_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 offset = 0x10000 + ( ( ( data & 7 ) - 2 ) * 0x4000 );
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[ offset ]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


decompiled_code:
__int64 simpsons_vh_start()
{
int v0; // er8
__int64 result; // rax

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // er8
__int64 result; // rax

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int simpsons_vh_start( void )
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int simpsons_vh_start()
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 simpsons_vh_stop()
{
K052109_vh_stop();
return K053247_vh_stop();
}

original_code:
void simpsons_vh_stop( void )
{
 K052109_vh_stop();
 K053247_vh_stop();
}

canonical_original_code:
void simpsons_vh_stop()
{
 K052109_vh_stop();
 K053247_vh_stop();
}


decompiled_code:
__int64 __fastcall simpsons_K052109_r(int a1)
{
return K052109_r((unsigned int)(a1 + 0x2000));
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return K052109_r((unsigned int)(a1 + 0x2000));
}

original_code:
static data_t simpsons_K052109_r(offs_t offset)
{
 return K052109_r(offset + 0x2000);
}

canonical_original_code:
static unsigned int simpsons_K052109_r(unsigned int offset)
{
 return K052109_r(offset + 0x2000);
}


decompiled_code:
__int64 __fastcall simpsons_K052109_w(int a1)
{
return K052109_w((unsigned int)(a1 + 0x2000));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return K052109_w((unsigned int)(a1 + 0x2000));
}

original_code:
static void simpsons_K052109_w(offs_t offset,data_t data)
{
 K052109_w(offset + 0x2000,data);
}

canonical_original_code:
static void simpsons_K052109_w(unsigned int offset, unsigned int data)
{
 K052109_w(offset + 0x2000,data);
}


decompiled_code:
__int64 __fastcall simpsons_K053247_r(unsigned int a1)
{
__int64 result; // rax

if ( a1 <= 0xFFF )
result = K053247_r();
else
result = *(unsigned __int8 *)(simpsons_xtraram + a1 - 4096);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
__int64 result; // rax

if ( a1 <= 0xFFF )
result = K053247_r();
else
result = *(unsigned __int8 *)(simpsons_xtraram + a1 - 4096);
return result;
}

original_code:
static data_t simpsons_K053247_r(offs_t offset)
{
 if (offset < 0x1000) return K053247_r(offset);
 else return simpsons_xtraram[offset - 0x1000];
}

canonical_original_code:
static unsigned int simpsons_K053247_r(unsigned int offset)
{
 if (offset < 0x1000) return K053247_r(offset);
 else return simpsons_xtraram[offset - 0x1000];
}


decompiled_code:
__int64 init_simpsons()
{
konami_rom_deinterleave_2(137LL);
return konami_rom_deinterleave_4(138LL);
}

canonical_decompiled_code:
__int64 func17()
{
konami_rom_deinterleave_2(137LL);
return konami_rom_deinterleave_4(138LL);
}

original_code:
static void init_simpsons(void)
{
 konami_rom_deinterleave_2(REGION_GFX1);
 konami_rom_deinterleave_4(REGION_GFX2);
}

canonical_original_code:
static void init_simpsons()
{
 konami_rom_deinterleave_2(REGION_GFX1);
 konami_rom_deinterleave_4(REGION_GFX2);
}


decompiled_code:
__int64 simpsons_irq()
{
if ( !(unsigned int)cpu_getiloops() )
{
if ( simpsons_firq_enabled && (unsigned int)K053247_is_IRQ_enabled() )
return 2LL;
return ignore_interrupt();
}
if ( !(unsigned int)K052109_is_IRQ_enabled() )
return ignore_interrupt();
return 1LL;
}

canonical_decompiled_code:
__int64 func20()
{
if ( !(unsigned int)cpu_getiloops() )
{
if ( simpsons_firq_enabled && (unsigned int)K053247_is_IRQ_enabled() )
return 2LL;
return ignore_interrupt();
}
if ( !(unsigned int)K052109_is_IRQ_enabled() )
return ignore_interrupt();
return 1LL;
}

original_code:
static int simpsons_irq(void)
{
 if (cpu_getiloops() == 0)
 {
  if (simpsons_firq_enabled && K053247_is_IRQ_enabled())
   return 2;
 }
 else
 {
  if (K052109_is_IRQ_enabled())
   return 1;
 }
 return ignore_interrupt();
}

canonical_original_code:
static int simpsons_irq()
{
 if (cpu_getiloops() == 0)
 {
  if (simpsons_firq_enabled && K053247_is_IRQ_enabled())
   return 2;
 }
 else
 {
  if (K052109_is_IRQ_enabled())
   return 1;
 }
 return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall simpsons_vh_screenrefresh(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_9EC = K053251_get_palette_index(3LL);
dword_9F0 = K053251_get_palette_index(4LL);
K052109_tilemap_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
v3 = 1;
layerpri = K053251_get_priority(2LL);
v4 = 2;
dword_9DC = K053251_get_priority(3LL);
dword_9E0 = K053251_get_priority(4LL);
sortlayers_constprop_0((int *)&v2);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053247_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_9EC = K053251_get_palette_index(3LL);
dword_9F0 = K053251_get_palette_index(4LL);
K052109_tilemap_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
v3 = 1;
layerpri = K053251_get_priority(2LL);
v4 = 2;
dword_9DC = K053251_get_priority(3LL);
dword_9E0 = K053251_get_priority(4LL);
func21((int *)&v2);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053247_sprites_draw(a1);
}

original_code:
void simpsons_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI3);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI4);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053247_sprites_draw(bitmap);
}

canonical_original_code:
void simpsons_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI3);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI4);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053247_sprites_draw(bitmap);
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types:
layer
int [3]


decompiled_code:
__int64 __fastcall simpsons_video_banking(char a1)
{
if ( (a1 & 1) != 0 )
{
cpu_setbankhandler_r(3LL, &paletteram_r);
cpu_setbankhandler_w(3LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
if ( (a1 & 2) != 0 )
{
LABEL_3:
cpu_setbankhandler_r(4LL, simpsons_K053247_r);
return cpu_setbankhandler_w(4LL, simpsons_K053247_w);
}
}
else
{
cpu_setbankhandler_r(3LL, &K052109_r);
cpu_setbankhandler_w(3LL, &K052109_w);
if ( (a1 & 2) != 0 )
goto LABEL_3;
}
cpu_setbankhandler_r(4LL, simpsons_K052109_r);
return cpu_setbankhandler_w(4LL, simpsons_K052109_w);
}

canonical_decompiled_code:
__int64 __fastcall func23(char a1)
{
if ( (a1 & 1) != 0 )
{
cpu_setbankhandler_r(3LL, &paletteram_r);
cpu_setbankhandler_w(3LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
if ( (a1 & 2) != 0 )
{
LABEL_3:
cpu_setbankhandler_r(4LL, simpsons_K053247_r);
return cpu_setbankhandler_w(4LL, simpsons_K053247_w);
}
}
else
{
cpu_setbankhandler_r(3LL, &K052109_r);
cpu_setbankhandler_w(3LL, &K052109_w);
if ( (a1 & 2) != 0 )
goto LABEL_3;
}
cpu_setbankhandler_r(4LL, simpsons_K052109_r);
return cpu_setbankhandler_w(4LL, simpsons_K052109_w);
}

original_code:
void simpsons_video_banking(int bank)
{
 if (bank & 1)
 {
  cpu_setbankhandler_r(3,paletteram_r);
  cpu_setbankhandler_w(3,paletteram_xBBBBBGGGGGRRRRR_swap_w);
 }
 else
 {
  cpu_setbankhandler_r(3,K052109_r);
  cpu_setbankhandler_w(3,K052109_w);
 }
 if (bank & 2)
 {
  cpu_setbankhandler_r(4,simpsons_K053247_r);
  cpu_setbankhandler_w(4,simpsons_K053247_w);
 }
 else
 {
  cpu_setbankhandler_r(4,simpsons_K052109_r);
  cpu_setbankhandler_w(4,simpsons_K052109_w);
 }
}

variable_types: bank int


decompiled_code:
__int64 simpsons_init_machine()
{
__int64 v0; // rax
bool v1; // zf
__int64 v2; // rax
unsigned int v4; // eax
unsigned int v5; // eax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = simpsons_banking;
paletteram = v0 + 557056;
v1 = ophw == 1;
cpu_bankbase[1] = v0 + 0x10000;
simpsons_xtraram = v0 + 561152;
simpsons_firq_enabled[0] = 0;
if ( v1 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
v2 = memory_region(130LL);
v1 = ophw == 2;
cpu_bankbase[2] = v2 + 0x10000;
if ( v1 )
{
ophw = -1;
v5 = cpu_get_pc();
cpu_setOPbase16(v5);
}
return simpsons_video_banking(0);
}

canonical_decompiled_code:
__int64 func24()
{
__int64 v0; // rax
bool v1; // zf
__int64 v2; // rax
unsigned int v4; // eax
unsigned int v5; // eax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = simpsons_banking;
paletteram = v0 + 557056;
v1 = ophw == 1;
cpu_bankbase[1] = v0 + 0x10000;
simpsons_xtraram = v0 + 561152;
simpsons_firq_enabled[0] = 0;
if ( v1 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
v2 = memory_region(130LL);
v1 = ophw == 2;
cpu_bankbase[2] = v2 + 0x10000;
if ( v1 )
{
ophw = -1;
v5 = cpu_get_pc();
cpu_setOPbase16(v5);
}
return func23(0);
}

original_code:
void simpsons_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = simpsons_banking;
 paletteram = &RAM[0x88000];
 simpsons_xtraram = &RAM[0x89000];
 simpsons_firq_enabled = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 RAM = memory_region(REGION_CPU2);
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[0x10000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 simpsons_video_banking( 0 );
}

canonical_original_code:
void simpsons_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = simpsons_banking;
 paletteram = &RAM[0x88000];
 simpsons_xtraram = &RAM[0x89000];
 simpsons_firq_enabled = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 RAM = memory_region(REGION_CPU2);
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[0x10000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 simpsons_video_banking( 0 );
}


decompiled_code:
__int64 ccastles_bitmode_r()
{
unsigned int v0; // er8
_BYTE *v1; // rcx
char v2; // si
int v3; // eax
_BYTE *v4; // rdx
char v5; // dl
char v6; // dl
char v7; // al

v0 = 0;
v1 = ccastles_screen_addr;
v2 = *ccastles_screen_addr;
v3 = ((*ccastles_screen_addr >> 1) | ((unsigned __int8)ccastles_screen_addr[1] << 7)) - 3072;
if ( (unsigned int)v3 > 0x73FF )
return v0;
v4 = ccastles_screen_inc_enable;
if ( !*ccastles_screen_inc_enable )
{
if ( *ccastles_screen_inc )
{
*ccastles_screen_addr = v2 - 1;
v1 = ccastles_screen_addr;
if ( !ccastles_screen_inc_enable[1] )
goto LABEL_6;
goto LABEL_9;
}
*ccastles_screen_addr = v2 + 1;
v4 = ccastles_screen_inc_enable;
v1 = ccastles_screen_addr;
}
if ( !v4[1] )
{
LABEL_6:
v5 = v1[1];
if ( ccastles_screen_inc[1] )
v6 = v5 - 1;
else
v6 = v5 + 1;
v1[1] = v6;
v1 = ccastles_screen_addr;
}
LABEL_9:
v7 = *(_BYTE *)(videoram + v3);
v0 = v7 & 0xF0;
if ( (*v1 & 1) != 0 )
v0 = (unsigned __int8)(16 * v7);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er8
_BYTE *v1; // rcx
char v2; // si
int v3; // eax
_BYTE *v4; // rdx
char v5; // dl
char v6; // dl
char v7; // al

v0 = 0;
v1 = ccastles_screen_addr;
v2 = *ccastles_screen_addr;
v3 = ((*ccastles_screen_addr >> 1) | ((unsigned __int8)ccastles_screen_addr[1] << 7)) - 3072;
if ( (unsigned int)v3 > 0x73FF )
return v0;
v4 = ccastles_screen_inc_enable;
if ( !*ccastles_screen_inc_enable )
{
if ( *ccastles_screen_inc )
{
*ccastles_screen_addr = v2 - 1;
v1 = ccastles_screen_addr;
if ( !ccastles_screen_inc_enable[1] )
goto LABEL_6;
goto LABEL_9;
}
*ccastles_screen_addr = v2 + 1;
v4 = ccastles_screen_inc_enable;
v1 = ccastles_screen_addr;
}
if ( !v4[1] )
{
LABEL_6:
v5 = v1[1];
if ( ccastles_screen_inc[1] )
v6 = v5 - 1;
else
v6 = v5 + 1;
v1[1] = v6;
v1 = ccastles_screen_addr;
}
LABEL_9:
v7 = *(_BYTE *)(videoram + v3);
v0 = v7 & 0xF0;
if ( (*v1 & 1) != 0 )
v0 = (unsigned __int8)(16 * v7);
return v0;
}

original_code:
data_t ccastles_bitmode_r(offs_t offset)
{
 int addr;
 addr = (ccastles_screen_addr[1]<<7) | (ccastles_screen_addr[0]>>1);
 if ((addr >= 0x0c00) && (addr < 0x8000))
 {
  if (!ccastles_screen_inc_enable[0])
  {
   if (!ccastles_screen_inc[0])
    ccastles_screen_addr[0] ++;
   else
    ccastles_screen_addr[0] --;
  }
  if (!ccastles_screen_inc_enable[1])
  {
   if (!ccastles_screen_inc[1])
    ccastles_screen_addr[1] ++;
   else
    ccastles_screen_addr[1] --;
  }
  addr -= 0xc00;
  if (ccastles_screen_addr[0] & 0x01)
   return ((videoram[addr] & 0x0f) << 4);
  else
   return (videoram[addr] & 0xf0);
 }
 return 0;
}

canonical_original_code:
unsigned int ccastles_bitmode_r(unsigned int offset)
{
 int addr;
 addr = (ccastles_screen_addr[1]<<7) | (ccastles_screen_addr[0]>>1);
 if ((addr >= 0x0c00) && (addr < 0x8000))
 {
  if (!ccastles_screen_inc_enable[0])
  {
   if (!ccastles_screen_inc[0])
    ccastles_screen_addr[0] ++;
   else
    ccastles_screen_addr[0] --;
  }
  if (!ccastles_screen_inc_enable[1])
  {
   if (!ccastles_screen_inc[1])
    ccastles_screen_addr[1] ++;
   else
    ccastles_screen_addr[1] --;
  }
  addr -= 0xc00;
  if (ccastles_screen_addr[0] & 0x01)
   return ((videoram[addr] & 0x0f) << 4);
  else
   return (videoram[addr] & 0xf0);
 }
 return 0;
}

variable_types: addr int


variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 ccastles_vh_start()
{
unsigned int v0; // er12

v0 = 1;
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap )
return v0;
maskbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( maskbitmap )
{
v0 = 0;
sprite_bm = bitmap_alloc(16LL, 16LL);
if ( !sprite_bm )
{
v0 = 1;
bitmap_free(maskbitmap);
bitmap_free(tmpbitmap);
}
return v0;
}
bitmap_free(tmpbitmap);
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12

v0 = 1;
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap )
return v0;
maskbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( maskbitmap )
{
v0 = 0;
sprite_bm = bitmap_alloc(16LL, 16LL);
if ( !sprite_bm )
{
v0 = 1;
bitmap_free(maskbitmap);
bitmap_free(tmpbitmap);
}
return v0;
}
bitmap_free(tmpbitmap);
return 1LL;
}

original_code:
int ccastles_vh_start(void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((maskbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 if ((sprite_bm = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(maskbitmap);
  bitmap_free(tmpbitmap);
  return 1;
 }
 return 0;
}

canonical_original_code:
int ccastles_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((maskbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 if ((sprite_bm = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(maskbitmap);
  bitmap_free(tmpbitmap);
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 ccastles_vh_stop()
{
bitmap_free(sprite_bm);
bitmap_free(maskbitmap);
return bitmap_free(tmpbitmap);
}

canonical_decompiled_code:
__int64 func5()
{
bitmap_free(sprite_bm);
bitmap_free(maskbitmap);
return bitmap_free(tmpbitmap);
}

original_code:
void ccastles_vh_stop(void)
{
 bitmap_free(sprite_bm);
 bitmap_free(maskbitmap);
 bitmap_free(tmpbitmap);
}

canonical_original_code:
void ccastles_vh_stop()
{
 bitmap_free(sprite_bm);
 bitmap_free(maskbitmap);
 bitmap_free(tmpbitmap);
}


decompiled_code:
void *__fastcall ccastles_bankswitch_w(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
if ( a2 )
v3 = v2 + 0x10000;
else
v3 = v2 + 40960;
cpu_bankbase[1] = v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
if ( a2 )
v3 = v2 + 0x10000;
else
v3 = v2 + 40960;
cpu_bankbase[1] = v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void ccastles_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (data) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0xa000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

canonical_original_code:
static void ccastles_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (data) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0xa000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall ccastles_coin_counter_w(int a1, int a2)
{
return coin_counter_w(a1 ^ 1u, (unsigned int)~a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return coin_counter_w(a1 ^ 1u, (unsigned int)~a2);
}

original_code:
static void ccastles_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(offset^1, ~data);
}

canonical_original_code:
static void ccastles_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(offset^1, ~data);
}


decompiled_code:
__int64 __fastcall ccastles_led_w(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2);
}

original_code:
static void ccastles_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset,~data);
}

canonical_original_code:
static void ccastles_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,~data);
}


decompiled_code:
_BYTE *redraw_bitmap()
{
int v0; // ebx
char v1; // r15
char v2; // r14
char v3; // dl
char v4; // cl
int v5; // er13
unsigned __int8 v6; // al
_BYTE *result; // rax
char v8; // [rsp+Eh] [rbp-3Ah]
char v9; // [rsp+Fh] [rbp-39h]

v0 = 0;
v1 = *ccastles_screen_addr;
v2 = ccastles_screen_addr[1];
v3 = *ccastles_screen_inc_enable;
v4 = ccastles_screen_inc_enable[1];
ccastles_screen_inc_enable[1] = 1;
v8 = v3;
v9 = v4;
*ccastles_screen_inc_enable = 1;
do
{
v5 = 0;
ccastles_screen_addr[1] = v0;
do
{
*ccastles_screen_addr = v5++;
v6 = ccastles_bitmode_r(0LL);
ccastles_bitmode_w(0LL, v6);
}
while ( v5 != 256 );
++v0;
}
while ( v0 != 256 );
*ccastles_screen_addr = v1;
ccastles_screen_addr[1] = v2;
*ccastles_screen_inc_enable = v8;
result = ccastles_screen_inc_enable;
ccastles_screen_inc_enable[1] = v9;
return result;
}

canonical_decompiled_code:
_BYTE *func2()
{
int v0; // ebx
char v1; // r15
char v2; // r14
char v3; // dl
char v4; // cl
int v5; // er13
unsigned __int8 v6; // al
_BYTE *result; // rax
char v8; // [rsp+Eh] [rbp-3Ah]
char v9; // [rsp+Fh] [rbp-39h]

v0 = 0;
v1 = *ccastles_screen_addr;
v2 = ccastles_screen_addr[1];
v3 = *ccastles_screen_inc_enable;
v4 = ccastles_screen_inc_enable[1];
ccastles_screen_inc_enable[1] = 1;
v8 = v3;
v9 = v4;
*ccastles_screen_inc_enable = 1;
do
{
v5 = 0;
ccastles_screen_addr[1] = v0;
do
{
*ccastles_screen_addr = v5++;
v6 = func0(0LL);
func1(0LL, v6);
}
while ( v5 != 256 );
++v0;
}
while ( v0 != 256 );
*ccastles_screen_addr = v1;
ccastles_screen_addr[1] = v2;
*ccastles_screen_inc_enable = v8;
result = ccastles_screen_inc_enable;
ccastles_screen_inc_enable[1] = v9;
return result;
}

original_code:
static void redraw_bitmap(void)
{
 int x, y;
 int screen_addr0_save, screen_addr1_save, screen_inc_enable0_save, screen_inc_enable1_save;
 screen_addr0_save = ccastles_screen_addr[0];
 screen_addr1_save = ccastles_screen_addr[1];
 screen_inc_enable0_save = ccastles_screen_inc_enable[0];
 screen_inc_enable1_save = ccastles_screen_inc_enable[1];
 ccastles_screen_inc_enable[0] = ccastles_screen_inc_enable[1] = 1;
 for (y = 0; y < 256; y++)
 {
  ccastles_screen_addr[1] = y;
  for (x = 0; x < 256; x++)
  {
   ccastles_screen_addr[0] = x;
   ccastles_bitmode_w(0, ccastles_bitmode_r(0));
  }
 }
 ccastles_screen_addr[0] = screen_addr0_save;
 ccastles_screen_addr[1] = screen_addr1_save;
 ccastles_screen_inc_enable[0] = screen_inc_enable0_save;
 ccastles_screen_inc_enable[1] = screen_inc_enable1_save;
}

canonical_original_code:
static void redraw_bitmap()
{
 int x; int y;
 int screen_addr0_save; int screen_addr1_save; int screen_inc_enable0_save; int screen_inc_enable1_save;
 screen_addr0_save = ccastles_screen_addr[0];
 screen_addr1_save = ccastles_screen_addr[1];
 screen_inc_enable0_save = ccastles_screen_inc_enable[0];
 screen_inc_enable1_save = ccastles_screen_inc_enable[1];
 ccastles_screen_inc_enable[0] = ccastles_screen_inc_enable[1] = 1;
 for (y = 0; y < 256; y++)
 {
  ccastles_screen_addr[1] = y;
  for (x = 0; x < 256; x++)
  {
   ccastles_screen_addr[0] = x;
   ccastles_bitmode_w(0, ccastles_bitmode_r(0));
  }
 }
 ccastles_screen_addr[0] = screen_addr0_save;
 ccastles_screen_addr[1] = screen_addr1_save;
 ccastles_screen_inc_enable[0] = screen_inc_enable0_save;
 ccastles_screen_inc_enable[1] = screen_inc_enable1_save;
}

variable_types: x int


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, nvram_size);
return memset(nvram, 0, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, nvram_size);
return memset(nvram, 0, nvram_size);
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}


decompiled_code:
void cchip1_init_machine()
{
cchip = 0LL;
dword_218 = 0;
cchip1_bank = 0;
}

canonical_decompiled_code:
void func0()
{
cchip = 0LL;
dword_218 = 0;
cchip1_bank = 0;
}

original_code:
void cchip1_init_machine(void)
{
 cchip[0] = cchip[1] = cchip[2] = 0;
 cchip1_bank = 0;
}

canonical_original_code:
void cchip1_init_machine()
{
 cchip[0] = cchip[1] = cchip[2] = 0;
 cchip1_bank = 0;
}


decompiled_code:
__int64 __fastcall cchip1_r(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 4 )
{
if ( cchip1_bank == 1 )
{
result = 128LL;
}
else
{
result = (unsigned int)dword_218;
if ( dword_218 )
dword_218 = 0;
else
result = readinputport(6LL);
}
}
else if ( a1 <= 4 )
{
if ( a1 )
{
if ( a1 != 2 )
{
LABEL_21:
result = 255LL;
if ( cchip1_bank == 1 )
result = cchip1_code[a1 >> 1];
return result;
}
if ( cchip1_bank == 1 )
{
result = 231LL;
}
else
{
result = HIDWORD(cchip);
if ( HIDWORD(cchip) )
HIDWORD(cchip) = 0;
else
result = readinputport(5LL);
}
}
else if ( cchip1_bank == 1 )
{
result = 72LL;
}
else
{
result = (unsigned int)cchip;
if ( (_DWORD)cchip )
LODWORD(cchip) = 0;
else
result = readinputport(4LL);
}
}
else
{
result = 1LL;
if ( a1 != 2050 )
{
if ( a1 == 3072 )
return (unsigned int)cchip1_bank;
result = 255LL;
if ( a1 <= 0x1EF )
goto LABEL_21;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 4 )
{
if ( cchip1_bank == 1 )
{
result = 128LL;
}
else
{
result = (unsigned int)dword_218;
if ( dword_218 )
dword_218 = 0;
else
result = readinputport(6LL);
}
}
else if ( a1 <= 4 )
{
if ( a1 )
{
if ( a1 != 2 )
{
LABEL_21:
result = 255LL;
if ( cchip1_bank == 1 )
result = cchip1_code[a1 >> 1];
return result;
}
if ( cchip1_bank == 1 )
{
result = 231LL;
}
else
{
result = HIDWORD(cchip);
if ( HIDWORD(cchip) )
HIDWORD(cchip) = 0;
else
result = readinputport(5LL);
}
}
else if ( cchip1_bank == 1 )
{
result = 72LL;
}
else
{
result = (unsigned int)cchip;
if ( (_DWORD)cchip )
LODWORD(cchip) = 0;
else
result = readinputport(4LL);
}
}
else
{
result = 1LL;
if ( a1 != 2050 )
{
if ( a1 == 3072 )
return (unsigned int)cchip1_bank;
result = 255LL;
if ( a1 <= 0x1EF )
goto LABEL_21;
}
}
return result;
}

original_code:
data_t cchip1_r(offs_t offset)
{
 int ret = 0;
 switch (offset)
 {
  case 0x000:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[0])
    {
     ret = cchip[0];
     cchip[0] = 0;
    }
    else
     ret = readinputport (4);
   break;
  case 0x002:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[1])
    {
     ret = cchip[1];
     cchip[1] = 0;
    }
    else
     ret = readinputport (5);
   break;
  case 0x004:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[2])
    {
     ret = cchip[2];
     cchip[2] = 0;
    }
    else
     ret = readinputport (6);
   break;
  case 0x802:
   ret = 0x01;
   break;
  case 0xc00:
   ret = cchip1_bank;
   break;
  default:
   if (offset < 0x1f0 && cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
   {
    ret = 0xff;
   }
   break;
 }
 return ret;
}

canonical_original_code:
unsigned int cchip1_r(unsigned int offset)
{
 int ret = 0;
 switch (offset)
 {
  case 0x000:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[0])
    {
     ret = cchip[0];
     cchip[0] = 0;
    }
    else
     ret = readinputport (4);
   break;
  case 0x002:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[1])
    {
     ret = cchip[1];
     cchip[1] = 0;
    }
    else
     ret = readinputport (5);
   break;
  case 0x004:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[2])
    {
     ret = cchip[2];
     cchip[2] = 0;
    }
    else
     ret = readinputport (6);
   break;
  case 0x802:
   ret = 0x01;
   break;
  case 0xc00:
   ret = cchip1_bank;
   break;
  default:
   if (offset < 0x1f0 && cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
   {
    ret = 0xff;
   }
   break;
 }
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall cchip1_w(unsigned int a1, int a2)
{
__int64 result; // rax

if ( a1 == 4 )
{
result = 75LL;
if ( (_BYTE)a2 == 52 )
a2 = 75;
dword_218 = a2;
}
else if ( a1 > 4 )
{
if ( a1 == 3072 )
cchip1_bank = a2 & 7;
}
else if ( a1 )
{
if ( a1 == 2 )
{
result = 87LL;
if ( (_BYTE)a2 == 70 )
a2 = 87;
HIDWORD(cchip) = a2;
}
}
else
{
result = 71LL;
if ( (_BYTE)a2 == 74 )
a2 = 71;
LODWORD(cchip) = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
__int64 result; // rax

if ( a1 == 4 )
{
result = 75LL;
if ( (_BYTE)a2 == 52 )
a2 = 75;
dword_218 = a2;
}
else if ( a1 > 4 )
{
if ( a1 == 3072 )
cchip1_bank = a2 & 7;
}
else if ( a1 )
{
if ( a1 == 2 )
{
result = 87LL;
if ( (_BYTE)a2 == 70 )
a2 = 87;
HIDWORD(cchip) = a2;
}
}
else
{
result = 71LL;
if ( (_BYTE)a2 == 74 )
a2 = 71;
LODWORD(cchip) = a2;
}
return result;
}

original_code:
void cchip1_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0x0000:
   if ((data & 0xff) == 0x4a)
    cchip[0] = 0x47;
   else cchip[0] = data;
   break;
  case 0x0002:
   if ((data & 0xff) == 0x46)
    cchip[1] = 0x57;
   else cchip[1] = data;
   break;
  case 0x0004:
   if ((data & 0xff) == 0x34)
    cchip[2] = 0x4b;
   else cchip[2] = data;
   break;
  case 0xc00:
   cchip1_bank = data & 0x07;
   break;
  default:
   break;
 }
}

canonical_original_code:
void cchip1_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0x0000:
   if ((data & 0xff) == 0x4a)
    cchip[0] = 0x47;
   else cchip[0] = data;
   break;
  case 0x0002:
   if ((data & 0xff) == 0x46)
    cchip[1] = 0x57;
   else cchip[1] = data;
   break;
  case 0x0004:
   if ((data & 0xff) == 0x34)
    cchip[2] = 0x4b;
   else cchip[2] = data;
   break;
  case 0xc00:
   cchip1_bank = data & 0x07;
   break;
  default:
   break;
 }
}


decompiled_code:
__int64 __fastcall cchip2_r(unsigned int a1)
{
__int64 result; // rax

result = 1LL;
if ( a1 != 2050 )
result = *(unsigned __int8 *)(cchip_ram + a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax

result = 1LL;
if ( a1 != 2050 )
result = *(unsigned __int8 *)(cchip_ram + a1);
return result;
}

original_code:
data_t cchip2_r(offs_t offset)
{
    int ret = 0;
    switch (offset)
    {
        case 0x802:
            ret = 0x01;
            break;
        default:
            ret = cchip_ram[offset];
            break;
    }
    return ret;
}

canonical_original_code:
unsigned int cchip2_r(unsigned int offset)
{
    int ret = 0;
    switch (offset)
    {
        case 0x802:
            ret = 0x01;
            break;
        default:
            ret = cchip_ram[offset];
            break;
    }
    return ret;
}


decompiled_code:
__int64 __fastcall get_bgram0_tile_info(int a1)
{
int v1; // eax
int v2; // esi
__int64 v3; // rcx
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
BYTE1(v1) = BYTE1(a1) | 4;
v2 = *(unsigned __int8 *)(xain_bgram0 + v1);
v3 = *(_QWORD *)(Machine + 528LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(xain_bgram0 + a1)) % *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 4) & 7);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = v2 >> 7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
int v2; // esi
__int64 v3; // rcx
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
BYTE1(v1) = BYTE1(a1) | 4;
v2 = *(unsigned __int8 *)(xain_bgram0 + v1);
v3 = *(_QWORD *)(Machine + 528LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(xain_bgram0 + a1)) % *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 4) & 7);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = v2 >> 7;
return result;
}

original_code:
static void get_bgram0_tile_info(int tile_index)
{
 int attr = xain_bgram0[tile_index | 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (xain_bgram0[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

canonical_original_code:
static void get_bgram0_tile_info(int tile_index)
{
 int attr = xain_bgram0[tile_index | 0x400];
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (xain_bgram0[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

variable_types: attr int

variable_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *


decompiled_code:
__int64 __fastcall get_bgram1_tile_info(int a1)
{
int v1; // eax
int v2; // esi
__int64 v3; // rcx
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
BYTE1(v1) = BYTE1(a1) | 4;
v2 = *(unsigned __int8 *)(xain_bgram1 + v1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(xain_bgram1 + a1)) % *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 4) & 7);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = v2 >> 7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax
int v2; // esi
__int64 v3; // rcx
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
BYTE1(v1) = BYTE1(a1) | 4;
v2 = *(unsigned __int8 *)(xain_bgram1 + v1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(xain_bgram1 + a1)) % *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 4) & 7);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = v2 >> 7;
return result;
}

original_code:
static void get_bgram1_tile_info(int tile_index)
{
 int attr = xain_bgram1[tile_index | 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (xain_bgram1[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

canonical_original_code:
static void get_bgram1_tile_info(int tile_index)
{
 int attr = xain_bgram1[tile_index | 0x400];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (xain_bgram1[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

user_defined_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; }


decompiled_code:
__int64 __fastcall xain_sharedram_r(unsigned int a1)
{
return *(unsigned __int8 *)(xain_sharedram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return *(unsigned __int8 *)(xain_sharedram + a1);
}

original_code:
data_t xain_sharedram_r(offs_t offset)
{
 return xain_sharedram[offset];
}

canonical_original_code:
unsigned int xain_sharedram_r(unsigned int offset)
{
 return xain_sharedram[offset];
}


canonical_decompiled_code:
__int64 func5()
{
return 77LL;
}

original_code:
static data_t xain_68705_r(offs_t offset)
{
 return 0x4d;
}

canonical_original_code:
static unsigned int xain_68705_r(unsigned int offset)
{
 return 0x4d;
}


canonical_decompiled_code:
void func6()
{
;
}

original_code:
static void xain_68705_w(offs_t offset,data_t data)
{
}

canonical_original_code:
static void xain_68705_w(unsigned int offset, unsigned int data)
{
}

variable_types:
data
unsigned int


decompiled_code:
__int64 xain_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-18h]
__int64 v5; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_bgram0_tile_info, back_scan, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v4) = 32;
bgram0_tilemap = v0;
v1 = tilemap_create(get_bgram1_tile_info, back_scan, 1LL, 16LL, 16LL, 32LL, v4);
LODWORD(v5) = 32;
bgram1_tilemap = v1;
v2 = tilemap_create(get_char_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v5);
char_tilemap = v2;
if ( !bgram0_tilemap || !v2 || !bgram1_tilemap )
return 1LL;
*(_DWORD *)(bgram1_tilemap + 132) = 0;
*(_DWORD *)(v2 + 132) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-18h]
__int64 v5; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_bgram0_tile_info, back_scan, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v4) = 32;
bgram0_tilemap = v0;
v1 = tilemap_create(get_bgram1_tile_info, back_scan, 1LL, 16LL, 16LL, 32LL, v4);
LODWORD(v5) = 32;
bgram1_tilemap = v1;
v2 = tilemap_create(get_char_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v5);
char_tilemap = v2;
if ( !bgram0_tilemap || !v2 || !bgram1_tilemap )
return 1LL;
*(_DWORD *)(bgram1_tilemap + 132) = 0;
*(_DWORD *)(v2 + 132) = 0;
return 0LL;
}

original_code:
int xain_vh_start(void)
{
 bgram0_tilemap = tilemap_create(get_bgram0_tile_info,back_scan, 0x00, 16,16,32,32);
 bgram1_tilemap = tilemap_create(get_bgram1_tile_info,back_scan, 0x01,16,16,32,32);
 char_tilemap = tilemap_create(get_char_tile_info,tilemap_scan_rows,0x01, 8, 8,32,32);
 if (!bgram0_tilemap || !bgram1_tilemap || !char_tilemap)
  return 1;
 bgram1_tilemap->transparent_pen = 0;
 char_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int xain_vh_start()
{
 bgram0_tilemap = tilemap_create(get_bgram0_tile_info,back_scan, 0x00, 16,16,32,32);
 bgram1_tilemap = tilemap_create(get_bgram1_tile_info,back_scan, 0x01,16,16,32,32);
 char_tilemap = tilemap_create(get_char_tile_info,tilemap_scan_rows,0x01, 8, 8,32,32);
 if (!bgram0_tilemap || !bgram1_tilemap || !char_tilemap)
  return 1;
 bgram1_tilemap->transparent_pen = 0;
 char_tilemap->transparent_pen = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall xain_scrollxP0_w(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollxP0_3 + a1) = a2;
return tilemap_set_scrollx(bgram0_tilemap, 0LL, (unsigned __int16)xain_scrollxP0_3);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollxP0_3 + a1) = a2;
return tilemap_set_scrollx(bgram0_tilemap, 0LL, (unsigned __int16)xain_scrollxP0_3);
}

original_code:
void xain_scrollxP0_w(offs_t offset,data_t data)
{
 static unsigned char xain_scrollxP0[2];
 xain_scrollxP0[offset] = data;
 tilemap_set_scrollx(bgram0_tilemap, 0, xain_scrollxP0[0]|(xain_scrollxP0[1]<<8));
}

canonical_original_code:
void xain_scrollxP0_w(unsigned int offset, unsigned int data)
{
 static unsigned char xain_scrollxP0[2];
 xain_scrollxP0[offset] = data;
 tilemap_set_scrollx(bgram0_tilemap, 0, xain_scrollxP0[0]|(xain_scrollxP0[1]<<8));
}


decompiled_code:
__int64 __fastcall xain_scrollxP1_w(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollxP1_1 + a1) = a2;
return tilemap_set_scrollx(bgram1_tilemap, 0LL, (unsigned __int16)xain_scrollxP1_1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollxP1_1 + a1) = a2;
return tilemap_set_scrollx(bgram1_tilemap, 0LL, (unsigned __int16)xain_scrollxP1_1);
}

original_code:
void xain_scrollxP1_w(offs_t offset,data_t data)
{
 static unsigned char xain_scrollxP1[2];
 xain_scrollxP1[offset] = data;
 tilemap_set_scrollx(bgram1_tilemap, 0, xain_scrollxP1[0]|(xain_scrollxP1[1]<<8));
}

canonical_original_code:
void xain_scrollxP1_w(unsigned int offset, unsigned int data)
{
 static unsigned char xain_scrollxP1[2];
 xain_scrollxP1[offset] = data;
 tilemap_set_scrollx(bgram1_tilemap, 0, xain_scrollxP1[0]|(xain_scrollxP1[1]<<8));
}


decompiled_code:
__int64 __fastcall xain_scrollyP0_w(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollyP0_2 + a1) = a2;
return tilemap_set_scrolly(bgram0_tilemap, 0LL, (unsigned __int16)xain_scrollyP0_2);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollyP0_2 + a1) = a2;
return tilemap_set_scrolly(bgram0_tilemap, 0LL, (unsigned __int16)xain_scrollyP0_2);
}

original_code:
void xain_scrollyP0_w(offs_t offset,data_t data)
{
 static unsigned char xain_scrollyP0[2];
 xain_scrollyP0[offset] = data;
 tilemap_set_scrolly(bgram0_tilemap, 0, xain_scrollyP0[0]|(xain_scrollyP0[1]<<8));
}

canonical_original_code:
void xain_scrollyP0_w(unsigned int offset, unsigned int data)
{
 static unsigned char xain_scrollyP0[2];
 xain_scrollyP0[offset] = data;
 tilemap_set_scrolly(bgram0_tilemap, 0, xain_scrollyP0[0]|(xain_scrollyP0[1]<<8));
}


decompiled_code:
__int64 __fastcall xain_scrollyP1_w(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollyP1_0 + a1) = a2;
return tilemap_set_scrolly(bgram1_tilemap, 0LL, (unsigned __int16)xain_scrollyP1_0);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, char a2)
{
*((_BYTE *)&xain_scrollyP1_0 + a1) = a2;
return tilemap_set_scrolly(bgram1_tilemap, 0LL, (unsigned __int16)xain_scrollyP1_0);
}

original_code:
void xain_scrollyP1_w(offs_t offset,data_t data)
{
 static unsigned char xain_scrollyP1[2];
 xain_scrollyP1[offset] = data;
 tilemap_set_scrolly(bgram1_tilemap, 0, xain_scrollyP1[0]|(xain_scrollyP1[1]<<8));
}

canonical_original_code:
void xain_scrollyP1_w(unsigned int offset, unsigned int data)
{
 static unsigned char xain_scrollyP1[2];
 xain_scrollyP1[offset] = data;
 tilemap_set_scrolly(bgram1_tilemap, 0, xain_scrollyP1[0]|(xain_scrollyP1[1]<<8));
}


decompiled_code:
__int64 __fastcall xain_flipscreen_w(__int64 a1, char a2)
{
return flip_screen_w(0LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char a2)
{
return flip_screen_w(0LL, a2 & 1);
}

original_code:
void xain_flipscreen_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 1);
}

canonical_original_code:
void xain_flipscreen_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 1);
}


decompiled_code:
__int64 __fastcall xain_vh_screenrefresh(__int64 a1)
{
__m128i v1; // xmm0
_OWORD *v2; // rdx

tilemap_update(0LL);
palette_init_used_colors();
v1 = _mm_load_si128((const __m128i *)&LC0);
v2 = (_OWORD *)palette_used_colors;
*(__m128i *)(palette_used_colors + 128LL) = v1;
v2[9] = v1;
v2[10] = v1;
v2[11] = v1;
v2[12] = v1;
v2[13] = v1;
v2[14] = v1;
v2[15] = v1;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bgram0_tilemap);
tilemap_draw(a1, bgram1_tilemap);
draw_sprites(a1);
return tilemap_draw(a1, char_tilemap);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__m128i v1; // xmm0
_OWORD *v2; // rdx

tilemap_update(0LL);
palette_init_used_colors();
v1 = _mm_load_si128((const __m128i *)&LC0);
v2 = (_OWORD *)palette_used_colors;
*(__m128i *)(palette_used_colors + 128LL) = v1;
v2[9] = v1;
v2[10] = v1;
v2[11] = v1;
v2[12] = v1;
v2[13] = v1;
v2[14] = v1;
v2[15] = v1;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bgram0_tilemap);
tilemap_draw(a1, bgram1_tilemap);
draw_sprites(a1);
return tilemap_draw(a1, char_tilemap);
}

original_code:
void xain_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 memset(palette_used_colors+128,(1|2),128);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 switch (xain_pri&0x7)
 {
 case 0:
  tilemap_draw(bitmap,bgram0_tilemap,0);
  tilemap_draw(bitmap,bgram1_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 case 1:
  tilemap_draw(bitmap,bgram1_tilemap,0);
  tilemap_draw(bitmap,bgram0_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 case 2:
  tilemap_draw(bitmap,char_tilemap,0);
  tilemap_draw(bitmap,bgram0_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram1_tilemap,0);
 break;
 case 3:
  tilemap_draw(bitmap,char_tilemap,0);
  tilemap_draw(bitmap,bgram1_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram0_tilemap,0);
 break;
 case 4:
  tilemap_draw(bitmap,bgram0_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram1_tilemap,0);
 break;
 case 5:
  tilemap_draw(bitmap,bgram1_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram0_tilemap,0);
 break;
 case 6:
  tilemap_draw(bitmap,bgram0_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram1_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 case 7:
  tilemap_draw(bitmap,bgram1_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram0_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 }
}

canonical_original_code:
void xain_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 memset(palette_used_colors+128,(1|2),128);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 switch (xain_pri&0x7)
 {
 case 0:
  tilemap_draw(bitmap,bgram0_tilemap,0);
  tilemap_draw(bitmap,bgram1_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 case 1:
  tilemap_draw(bitmap,bgram1_tilemap,0);
  tilemap_draw(bitmap,bgram0_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 case 2:
  tilemap_draw(bitmap,char_tilemap,0);
  tilemap_draw(bitmap,bgram0_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram1_tilemap,0);
 break;
 case 3:
  tilemap_draw(bitmap,char_tilemap,0);
  tilemap_draw(bitmap,bgram1_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram0_tilemap,0);
 break;
 case 4:
  tilemap_draw(bitmap,bgram0_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram1_tilemap,0);
 break;
 case 5:
  tilemap_draw(bitmap,bgram1_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram0_tilemap,0);
 break;
 case 6:
  tilemap_draw(bitmap,bgram0_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram1_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 case 7:
  tilemap_draw(bitmap,bgram1_tilemap,0);
  draw_sprites(bitmap);
  tilemap_draw(bitmap,bgram0_tilemap,0);
  tilemap_draw(bitmap,char_tilemap,0);
 break;
 }
}

user_defined_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; }


decompiled_code:
__int64 init_xsleena()
{
__int64 result; // rax

result = memory_region(129LL);
*(_DWORD *)(result + 54408) = 303174162;
*(_WORD *)(result + 54412) = 4626;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax

result = memory_region(129LL);
*(_DWORD *)(result + 54408) = 303174162;
*(_WORD *)(result + 54412) = 4626;
return result;
}

original_code:
void init_xsleena(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0xd488] = 0x12;
 RAM[0xd489] = 0x12;
 RAM[0xd48a] = 0x12;
 RAM[0xd48b] = 0x12;
 RAM[0xd48c] = 0x12;
 RAM[0xd48d] = 0x12;
}

canonical_original_code:
void init_xsleena()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0xd488] = 0x12;
 RAM[0xd489] = 0x12;
 RAM[0xd48a] = 0x12;
 RAM[0xd48b] = 0x12;
 RAM[0xd48c] = 0x12;
 RAM[0xd48d] = 0x12;
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 init_solarwar()
{
__int64 result; // rax

result = memory_region(129LL);
*(_DWORD *)(result + 54398) = 303174162;
*(_WORD *)(result + 54402) = 4626;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax

result = memory_region(129LL);
*(_DWORD *)(result + 54398) = 303174162;
*(_WORD *)(result + 54402) = 4626;
return result;
}

original_code:
void init_solarwar(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0xd47e] = 0x12;
 RAM[0xd47f] = 0x12;
 RAM[0xd480] = 0x12;
 RAM[0xd481] = 0x12;
 RAM[0xd482] = 0x12;
 RAM[0xd483] = 0x12;
}

canonical_original_code:
void init_solarwar()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0xd47e] = 0x12;
 RAM[0xd47f] = 0x12;
 RAM[0xd480] = 0x12;
 RAM[0xd481] = 0x12;
 RAM[0xd482] = 0x12;
 RAM[0xd483] = 0x12;
}


decompiled_code:
void *__fastcall xainCPUA_bankswitch_w(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
xain_pri = a2 & 7;
if ( (a2 & 8) != 0 )
v3 = v2 + 0x10000;
else
v3 = v2 + 0x4000;
cpu_bankbase[1] = v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func16(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
xain_pri = a2 & 7;
if ( (a2 & 8) != 0 )
v3 = v2 + 0x10000;
else
v3 = v2 + 0x4000;
cpu_bankbase[1] = v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
void xainCPUA_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 xain_pri=data&0x7;
 if (data & 0x08) {{ if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
 else {{ if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x4000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
}

canonical_original_code:
void xainCPUA_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 xain_pri=data&0x7;
 if (data & 0x08) {{ if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
 else {{ if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x4000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
}


decompiled_code:
void *__fastcall xainCPUB_bankswitch_w(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(130LL);
if ( (a2 & 1) != 0 )
v3 = v2 + 0x10000;
else
v3 = v2 + 0x4000;
cpu_bankbase[2] = v3;
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func17(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(130LL);
if ( (a2 & 1) != 0 )
v3 = v2 + 0x10000;
else
v3 = v2 + 0x4000;
cpu_bankbase[2] = v3;
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
void xainCPUB_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 0x01) {{ if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[0x10000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
 else {{ if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[0x4000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
}

canonical_original_code:
void xainCPUB_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 0x01) {{ if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[0x10000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
 else {{ if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[0x4000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };}
}


decompiled_code:
__int64 xain_sound_command_w()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, 1LL);
}

canonical_decompiled_code:
__int64 func18()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, 1LL);
}

original_code:
void xain_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 cpu_cause_interrupt(2,1);
}

canonical_original_code:
void xain_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 cpu_cause_interrupt(2,1);
}


decompiled_code:
__int64 xain_irqB_clear_w()
{
return cpu_set_irq_line(1LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func20()
{
return cpu_set_irq_line(1LL, 0LL, 0LL);
}

original_code:
static void xain_irqB_clear_w(offs_t offset,data_t data)
{
 cpu_set_irq_line(1,0,0);
}

canonical_original_code:
static void xain_irqB_clear_w(unsigned int offset, unsigned int data)
{
 cpu_set_irq_line(1,0,0);
}


decompiled_code:
__int64 xain_irqA_assert_w()
{
return cpu_set_irq_line(0LL, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 func21()
{
return cpu_set_irq_line(0LL, 0LL, 1LL);
}

original_code:
static void xain_irqA_assert_w(offs_t offset,data_t data)
{
 cpu_set_irq_line(0,0,1);
}

canonical_original_code:
static void xain_irqA_assert_w(unsigned int offset, unsigned int data)
{
 cpu_set_irq_line(0,0,1);
}


decompiled_code:
__int64 xain_irqB_assert_w()
{
return cpu_set_irq_line(1LL, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 func22()
{
return cpu_set_irq_line(1LL, 0LL, 1LL);
}

original_code:
static void xain_irqB_assert_w(offs_t offset,data_t data)
{
 cpu_set_irq_line(1,0,1);
}

canonical_original_code:
static void xain_irqB_assert_w(unsigned int offset, unsigned int data)
{
 cpu_set_irq_line(1,0,1);
}


decompiled_code:
__int64 xain_irqA_clear_w()
{
return cpu_set_irq_line(0LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func23()
{
return cpu_set_irq_line(0LL, 0LL, 0LL);
}

original_code:
static void xain_irqA_clear_w(offs_t offset,data_t data)
{
 cpu_set_irq_line(0,0,0);
}

canonical_original_code:
static void xain_irqA_clear_w(unsigned int offset, unsigned int data)
{
 cpu_set_irq_line(0,0,0);
}


decompiled_code:
__int64 xain_firqA_clear_w()
{
return cpu_set_irq_line(0LL, 1LL, 0LL);
}

canonical_decompiled_code:
__int64 func24()
{
return cpu_set_irq_line(0LL, 1LL, 0LL);
}

original_code:
static void xain_firqA_clear_w(offs_t offset,data_t data)
{
 cpu_set_irq_line(0,1,0);
}

canonical_original_code:
static void xain_firqA_clear_w(unsigned int offset, unsigned int data)
{
 cpu_set_irq_line(0,1,0);
}


decompiled_code:
__int64 xainA_interrupt()
{
if ( (unsigned int)cpu_getiloops() == 2 )
cpu_set_nmi_line(0LL, 3LL);
else
cpu_set_irq_line(0LL, 1LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func25()
{
if ( (unsigned int)cpu_getiloops() == 2 )
cpu_set_nmi_line(0LL, 3LL);
else
cpu_set_irq_line(0LL, 1LL, 1LL);
return 0LL;
}

original_code:
static int xainA_interrupt(void)
{
 if (cpu_getiloops() == 2)
  cpu_set_nmi_line(0,3);
 else
  cpu_set_irq_line(0,1,1);
 return 0;
}

canonical_original_code:
static int xainA_interrupt()
{
 if (cpu_getiloops() == 2)
  cpu_set_nmi_line(0,3);
 else
  cpu_set_irq_line(0,1,1);
 return 0;
}


original_code:
static UINT32 back_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x10) << 4) + ((row & 0x10) << 5);
}

canonical_original_code:
static unsigned int back_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x10) << 4) + ((row & 0x10) << 5);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


decompiled_code:
__int64 __fastcall get_char_tile_info(int a1)
{
int v1; // eax
int v2; // ecx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
BYTE1(v1) = BYTE1(a1) | 4;
v2 = *(unsigned __int8 *)(xain_charram + v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (((_WORD)v2 << 8) & 0x300 | (unsigned int)*(unsigned __int8 *)(xain_charram + a1)) % *(_DWORD *)(v3 + 8);
v5 = *(_DWORD *)(v3 + 12) * (v2 >> 5);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // eax
int v2; // ecx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
BYTE1(v1) = BYTE1(a1) | 4;
v2 = *(unsigned __int8 *)(xain_charram + v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (((_WORD)v2 << 8) & 0x300 | (unsigned int)*(unsigned __int8 *)(xain_charram + a1)) % *(_DWORD *)(v3 + 8);
v5 = *(_DWORD *)(v3 + 12) * (v2 >> 5);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_char_tile_info(int tile_index)
{
 int attr = xain_charram[tile_index | 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (xain_charram[tile_index] | ((attr & 3) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xe0) >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_char_tile_info(int tile_index)
{
 int attr = xain_charram[tile_index | 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (xain_charram[tile_index] | ((attr & 3) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xe0) >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}


irqhandler

decompiled_code:
__int64 __fastcall irqhandler(int a1)
{
return cpu_set_irq_line(2LL, 1LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1)
{
return cpu_set_irq_line(2LL, 1LL, a1 != 0);
}

original_code:
static void irqhandler(int irq)
{
 cpu_set_irq_line(2,1,irq ? 1 : 0);
}

variable_types: irq int


original_code:
void mrdo_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 256;i++)
 {
  int a1,a2;
  int bit0,bit1,bit2,bit3;
  a1 = ((i >> 3) & 0x1c) + (i & 0x03) + 32;
  a2 = ((i >> 0) & 0x1c) + (i & 0x03);
  bit0 = (color_prom[a1] >> 1) & 0x01;
  bit1 = (color_prom[a1] >> 0) & 0x01;
  bit2 = (color_prom[a2] >> 1) & 0x01;
  bit3 = (color_prom[a2] >> 0) & 0x01;
  *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  bit0 = (color_prom[a1] >> 3) & 0x01;
  bit1 = (color_prom[a1] >> 2) & 0x01;
  bit2 = (color_prom[a2] >> 3) & 0x01;
  bit3 = (color_prom[a2] >> 2) & 0x01;
  *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  bit0 = (color_prom[a1] >> 5) & 0x01;
  bit1 = (color_prom[a1] >> 4) & 0x01;
  bit2 = (color_prom[a2] >> 5) & 0x01;
  bit3 = (color_prom[a2] >> 4) & 0x01;
  *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
 }
 color_prom += 64;
 for (i = 0;i < (Machine->gfx[2]->total_colors * Machine->gfx[2]->color_granularity);i++)
 {
  int bits;
  if (i < 32)
   bits = color_prom[i] & 0x0f;
  else
   bits = color_prom[i & 0x1f] >> 4;
  (colortable[Machine->drv->gfxdecodeinfo[2].color_codes_start + i]) = bits + ((bits & 0x0c) << 3);
 }
}

canonical_original_code:
void mrdo_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 256;i++)
 {
  int a1; int a2;
  int bit0; int bit1; int bit2; int bit3;
  a1 = ((i >> 3) & 0x1c) + (i & 0x03) + 32;
  a2 = ((i >> 0) & 0x1c) + (i & 0x03);
  bit0 = (color_prom[a1] >> 1) & 0x01;
  bit1 = (color_prom[a1] >> 0) & 0x01;
  bit2 = (color_prom[a2] >> 1) & 0x01;
  bit3 = (color_prom[a2] >> 0) & 0x01;
  *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  bit0 = (color_prom[a1] >> 3) & 0x01;
  bit1 = (color_prom[a1] >> 2) & 0x01;
  bit2 = (color_prom[a2] >> 3) & 0x01;
  bit3 = (color_prom[a2] >> 2) & 0x01;
  *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
  bit0 = (color_prom[a1] >> 5) & 0x01;
  bit1 = (color_prom[a1] >> 4) & 0x01;
  bit2 = (color_prom[a2] >> 5) & 0x01;
  bit3 = (color_prom[a2] >> 4) & 0x01;
  *(palette++) = 0x2c * bit0 + 0x37 * bit1 + 0x43 * bit2 + 0x59 * bit3;
 }
 color_prom += 64;
 for (i = 0;i < (Machine->gfx[2]->total_colors * Machine->gfx[2]->color_granularity);i++)
 {
  int bits;
  if (i < 32)
   bits = color_prom[i] & 0x0f;
  else
   bits = color_prom[i & 0x1f] >> 4;
  (colortable[Machine->drv->gfxdecodeinfo[2].color_codes_start + i]) = bits + ((bits & 0x0c) << 3);
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: bits int


decompiled_code:
__int64 mrdo_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 32LL, v3);
fg_tilemap = v1;
if ( !v1 || !bg_tilemap )
return 1LL;
*(_QWORD *)(bg_tilemap + 136) = 1LL;
*(_QWORD *)(v1 + 136) = 1LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 32LL, v3);
fg_tilemap = v1;
if ( !v1 || !bg_tilemap )
return 1LL;
*(_QWORD *)(bg_tilemap + 136) = 1LL;
*(_QWORD *)(v1 + 136) = 1LL;
return 0LL;
}

original_code:
int mrdo_vh_start(void)
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x02,8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x02,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0x01;
 bg_tilemap->transmask[1] = 0x00;
 fg_tilemap->transmask[0] = 0x01;
 fg_tilemap->transmask[1] = 0x00;
 return 0;
}

canonical_original_code:
int mrdo_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x02,8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x02,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0x01;
 bg_tilemap->transmask[1] = 0x00;
 fg_tilemap->transmask[0] = 0x01;
 fg_tilemap->transmask[1] = 0x00;
 return 0;
}


decompiled_code:
__int64 __fastcall mrdo_scrollx_w(__int64 a1, unsigned int a2)
{
return tilemap_set_scrollx(bg_tilemap, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return tilemap_set_scrollx(bg_tilemap, 0LL, a2);
}

original_code:
void mrdo_scrollx_w(offs_t offset,data_t data)
{
 tilemap_set_scrollx(bg_tilemap,0,data);
}

canonical_original_code:
void mrdo_scrollx_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrollx(bg_tilemap,0,data);
}


decompiled_code:
__int64 __fastcall mrdo_scrolly_w(__int64 a1, unsigned int a2)
{
return tilemap_set_scrolly(bg_tilemap, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
return tilemap_set_scrolly(bg_tilemap, 0LL, a2);
}

original_code:
void mrdo_scrolly_w(offs_t offset,data_t data)
{
 tilemap_set_scrolly(bg_tilemap,0,data);
}

canonical_original_code:
void mrdo_scrolly_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrolly(bg_tilemap,0,data);
}


decompiled_code:
__int64 __fastcall mrdo_flipscreen_w(__int64 a1, char a2)
{
__int64 v2; // rsi

v2 = a2 & 1;
if ( (_DWORD)v2 )
v2 = 3LL;
return tilemap_set_flip(0LL, v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
__int64 v2; // rsi

v2 = a2 & 1;
if ( (_DWORD)v2 )
v2 = 3LL;
return tilemap_set_flip(0LL, v2);
}

original_code:
void mrdo_flipscreen_w(offs_t offset,data_t data)
{
 flipscreen = data & 0x01;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
}

canonical_original_code:
void mrdo_flipscreen_w(unsigned int offset, unsigned int data)
{
 flipscreen = data & 0x01;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
}


decompiled_code:
void *__fastcall mrdo_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
tilemap_draw(a1, bg_tilemap, 64LL);
tilemap_draw(a1, fg_tilemap, 64LL);
return draw_sprites(a1);
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
tilemap_draw(a1, bg_tilemap, 64LL);
tilemap_draw(a1, fg_tilemap, 64LL);
return func7(a1);
}

original_code:
void mrdo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0x40);
 draw_sprites(bitmap);
}

canonical_original_code:
void mrdo_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0x40);
 draw_sprites(bitmap);
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *


decompiled_code:
__int64 mrdo_SECRE_r()
{
__int64 v0; // rbx

v0 = memory_region(129LL);
return *(unsigned __int8 *)(v0 + (unsigned int)cpu_get_reg(6LL));
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbx

v0 = memory_region(129LL);
return *(unsigned __int8 *)(v0 + (unsigned int)cpu_get_reg(6LL));
}

original_code:
data_t mrdo_SECRE_r(offs_t offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 return RAM[ cpu_get_reg(Z80_HL) ];
}

canonical_original_code:
unsigned int mrdo_SECRE_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 return RAM[ cpu_get_reg(Z80_HL) ];
}


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rax
unsigned int v2; // edi
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
v2 = *(unsigned __int8 *)(mrdo_bgvideoram + a1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(mrdo_bgvideoram + v1 + 1024) + ((2 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
v5 = (int)(*(_DWORD *)(v3 + 12) * (v2 & 0x3F));
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rax
unsigned int v2; // edi
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
v2 = *(unsigned __int8 *)(mrdo_bgvideoram + a1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(mrdo_bgvideoram + v1 + 1024) + ((2 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
v5 = (int)(*(_DWORD *)(v3 + 12) * (v2 & 0x3F));
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 4;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = mrdo_bgvideoram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (mrdo_bgvideoram[tile_index+0x400] + ((attr & 0x80) << 1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x40) >> 6)<<2);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = mrdo_bgvideoram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (mrdo_bgvideoram[tile_index+0x400] + ((attr & 0x80) << 1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x40) >> 6)<<2);
}

variable_types:
attr
unsigned char


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rax
unsigned int v2; // edi
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
v2 = *(unsigned __int8 *)(mrdo_fgvideoram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(mrdo_fgvideoram + v1 + 1024) + ((2 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
v5 = (int)(*(_DWORD *)(v3 + 12) * (v2 & 0x3F));
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rax
unsigned int v2; // edi
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1;
v2 = *(unsigned __int8 *)(mrdo_fgvideoram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(mrdo_fgvideoram + v1 + 1024) + ((2 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
v5 = (int)(*(_DWORD *)(v3 + 12) * (v2 & 0x3F));
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 4;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = mrdo_fgvideoram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (mrdo_fgvideoram[tile_index+0x400] + ((attr & 0x80) << 1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x40) >> 6)<<2);
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = mrdo_fgvideoram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (mrdo_fgvideoram[tile_index+0x400] + ((attr & 0x80) << 1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x40) >> 6)<<2);
}


decompiled_code:
void *__fastcall draw_sprites(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v3; // rbx
int v4; // edx
__int64 v5; // r8
unsigned int v6; // er11
__int64 v7; // r9
__int64 v8; // rcx
__int64 v9; // rdx
__int64 v10; // rax

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v3 = v2 + 1LL;
do
{
while ( 1 )
{
result = (void *)spriteram;
v4 = *(unsigned __int8 *)(spriteram + v3);
if ( (_BYTE)v4 )
break;
v3 -= 4LL;
v2 -= 4;
if ( v2 < 0 )
return result;
}
v5 = *(_BYTE *)(spriteram + v3 + 1) & 0x10;
v6 = *(_BYTE *)(spriteram + v3 + 1) & 0xF;
v7 = *(_BYTE *)(spriteram + v3 + 1) & 0x20;
v8 = (unsigned int)(256 - v4);
v9 = *(unsigned __int8 *)(spriteram + v3 - 1);
v10 = *(unsigned __int8 *)(spriteram + v3 + 2);
v3 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 528LL), v9, v6, v5, v7, v10, v8, Machine + 776LL, 2LL, 0LL);
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v3; // rbx
int v4; // edx
__int64 v5; // r8
unsigned int v6; // er11
__int64 v7; // r9
__int64 v8; // rcx
__int64 v9; // rdx
__int64 v10; // rax

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v3 = v2 + 1LL;
do
{
while ( 1 )
{
result = (void *)spriteram;
v4 = *(unsigned __int8 *)(spriteram + v3);
if ( (_BYTE)v4 )
break;
v3 -= 4LL;
v2 -= 4;
if ( v2 < 0 )
return result;
}
v5 = *(_BYTE *)(spriteram + v3 + 1) & 0x10;
v6 = *(_BYTE *)(spriteram + v3 + 1) & 0xF;
v7 = *(_BYTE *)(spriteram + v3 + 1) & 0x20;
v8 = (unsigned int)(256 - v4);
v9 = *(unsigned __int8 *)(spriteram + v3 - 1);
v10 = *(unsigned __int8 *)(spriteram + v3 + 2);
v3 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 528LL), v9, v6, v5, v7, v10, v8, Machine + 776LL, 2LL, 0LL);
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  if (spriteram[offs + 1] != 0)
  {
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs],spriteram[offs + 2] & 0x0f,
     spriteram[offs + 2] & 0x10,spriteram[offs + 2] & 0x20,
     spriteram[offs + 3],256 - spriteram[offs + 1],
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

variable_types: offs int


decompiled_code:
__int64 solomon_vh_start()
{
__int64 v1; // rbp
size_t v2; // r13
__int64 i; // rax

if ( (unsigned int)generic_vh_start() )
return 1LL;
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v1 = tmpbitmap2;
if ( !tmpbitmap2 )
{
LABEL_9:
generic_vh_stop();
return 1LL;
}
v2 = videoram_size;
dirtybuffer2 = malloc(videoram_size);
if ( !dirtybuffer2 )
{
bitmap_free(v1);
goto LABEL_9;
}
memset(dirtybuffer2, 1, v2);
for ( i = 0LL; i != 128; i += 16LL )
*(_BYTE *)(palette_used_colors + i) = 7;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v1; // rbp
size_t v2; // r13
__int64 i; // rax

if ( (unsigned int)generic_vh_start() )
return 1LL;
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v1 = tmpbitmap2;
if ( !tmpbitmap2 )
{
LABEL_9:
generic_vh_stop();
return 1LL;
}
v2 = videoram_size;
dirtybuffer2 = malloc(videoram_size);
if ( !dirtybuffer2 )
{
bitmap_free(v1);
goto LABEL_9;
}
memset(dirtybuffer2, 1, v2);
for ( i = 0LL; i != 128; i += 16LL )
*(_BYTE *)(palette_used_colors + i) = 7;
return 0LL;
}

original_code:
int solomon_vh_start(void)
{
 int i;
 if (generic_vh_start() != 0)
  return 1;
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 if ((dirtybuffer2 = (unsigned char*)malloc(videoram_size)) == 0)
 {
  bitmap_free(tmpbitmap2);
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 for (i = 0;i < 8;i++) palette_used_colors[16 * i] = (4|(1|2));
 return 0;
}

canonical_original_code:
int solomon_vh_start()
{
 int i;
 if (generic_vh_start() != 0)
  return 1;
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 if ((dirtybuffer2 = (unsigned char *)malloc(videoram_size)) == 0)
 {
  bitmap_free(tmpbitmap2);
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 for (i = 0;i < 8;i++) palette_used_colors[16 * i] = (4|(1|2));
 return 0;
}


decompiled_code:
void *__fastcall solomon_flipscreen_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 1;
if ( v2 != flipscreen )
{
flipscreen = v2;
memset(dirtybuffer, 1, videoram_size);
result = memset(dirtybuffer2, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 1;
if ( v2 != flipscreen )
{
flipscreen = v2;
memset(dirtybuffer, 1, videoram_size);
result = memset(dirtybuffer2, 1, videoram_size);
}
return result;
}

original_code:
void solomon_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
}

canonical_original_code:
void solomon_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 solomon_vh_stop()
{
bitmap_free(tmpbitmap2);
free(dirtybuffer2);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func2()
{
bitmap_free(tmpbitmap2);
free(dirtybuffer2);
return generic_vh_stop();
}

original_code:
void solomon_vh_stop(void)
{
 bitmap_free(tmpbitmap2);
 free(dirtybuffer2);
 generic_vh_stop();
}

canonical_original_code:
void solomon_vh_stop()
{
 bitmap_free(tmpbitmap2);
 free(dirtybuffer2);
 generic_vh_stop();
}