decompiled_code:
__int64 __fastcall avalnche_output_w(char a1, char a2)
{
__int64 result; // rax

switch ( a1 & 7 )
{
case 0:
result = osd_led_w(0LL, a2 & 1);
break;
case 1:
attract = a2 & 1;
break;
case 2:
if ( (a2 & 1) != 0 )
{
palette_change_color(0LL, 0LL, 0LL, 0LL);
result = palette_change_color(1LL, 255LL, 255LL, 255LL);
}
else
{
palette_change_color(0LL, 255LL, 255LL, 255LL);
result = palette_change_color(1LL, 0LL, 0LL, 0LL);
}
break;
case 3:
result = osd_led_w(1LL, a2 & 1);
break;
case 4:
aud0 = a2 & 1;
break;
case 5:
aud1 = a2 & 1;
break;
case 6:
aud2 = a2 & 1;
break;
case 7:
result = osd_led_w(2LL, a2 & 1);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, char a2)
{
__int64 result; // rax

switch ( a1 & 7 )
{
case 0:
result = osd_led_w(0LL, a2 & 1);
break;
case 1:
attract = a2 & 1;
break;
case 2:
if ( (a2 & 1) != 0 )
{
palette_change_color(0LL, 0LL, 0LL, 0LL);
result = palette_change_color(1LL, 255LL, 255LL, 255LL);
}
else
{
palette_change_color(0LL, 255LL, 255LL, 255LL);
result = palette_change_color(1LL, 0LL, 0LL, 0LL);
}
break;
case 3:
result = osd_led_w(1LL, a2 & 1);
break;
case 4:
aud0 = a2 & 1;
break;
case 5:
aud1 = a2 & 1;
break;
case 6:
aud2 = a2 & 1;
break;
case 7:
result = osd_led_w(2LL, a2 & 1);
break;
}
return result;
}

original_code:
void avalnche_output_w(offs_t offset,data_t data)
{
 switch (offset & 0x07)
 {
  case 0x00:
         osd_led_w(0,(data & 0x01));
   break;
  case 0x01:
   attract = data & 0x01;
   break;
  case 0x02:
   if (data & 0x01)
   {
    palette_change_color(0,0,0,0);
    palette_change_color(1,255,255,255);
   }
   else
   {
    palette_change_color(0,255,255,255);
    palette_change_color(1,0,0,0);
   }
   break;
  case 0x03:
         osd_led_w(1,(data & 0x01));
   break;
  case 0x04:
   aud0 = data & 0x01;
   break;
  case 0x05:
   aud1 = data & 0x01;
   break;
  case 0x06:
   aud2 = data & 0x01;
   break;
  case 0x07:
         osd_led_w(2,(data & 0x01));
   break;
 }
}

canonical_original_code:
void avalnche_output_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x07)
 {
  case 0x00:
         osd_led_w(0,(data & 0x01));
   break;
  case 0x01:
   attract = data & 0x01;
   break;
  case 0x02:
   if (data & 0x01)
   {
    palette_change_color(0,0,0,0);
    palette_change_color(1,255,255,255);
   }
   else
   {
    palette_change_color(0,255,255,255);
    palette_change_color(1,0,0,0);
   }
   break;
  case 0x03:
         osd_led_w(1,(data & 0x01));
   break;
  case 0x04:
   aud0 = data & 0x01;
   break;
  case 0x05:
   aud1 = data & 0x01;
   break;
  case 0x06:
   aud2 = data & 0x01;
   break;
  case 0x07:
         osd_led_w(2,(data & 0x01));
   break;
 }
}


decompiled_code:
__int64 avalnche_interrupt()
{
int v0; // edx
int v1; // eax
int v2; // eax
__int64 result; // rax

v0 = ((_BYTE)time_8V_2 + 1) & 1;
time_8V_2 = v0;
time_16V_1 = ((_BYTE)time_16V_1 + 1) & 3;
v1 = ((_BYTE)time_32V_0 + 1) & 7;
time_32V_0 = v1;
if ( attract || (aud2 != 1 || v0) && (aud1 != 1 || v1) )
DAC_data_w(0LL, 0LL);
else
DAC_data_w(0LL, 255LL);
if ( !(time_16V_1 | attract) )
{
v2 = noise_l4;
noise_l4 = (unsigned __int8)((2 * noise_l4) | ((((unsigned __int8)noise_l4 ^ (unsigned __int8)(noise_k4 >> 6)) & 1) == 0));
noise_k4 = (unsigned __int8)((2 * noise_k4) | (v2 >> 7) & 1);
noise = noise_k4 >> 7;
}
if ( !aud0 && noise )
DAC_data_w(1LL, (unsigned int)volume);
else
DAC_data_w(1LL, 0LL);
result = 0LL;
if ( !time_16V_1 )
result = nmi_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // edx
int v1; // eax
int v2; // eax
__int64 result; // rax

v0 = ((_BYTE)time_8V_2 + 1) & 1;
time_8V_2 = v0;
time_16V_1 = ((_BYTE)time_16V_1 + 1) & 3;
v1 = ((_BYTE)time_32V_0 + 1) & 7;
time_32V_0 = v1;
if ( attract || (aud2 != 1 || v0) && (aud1 != 1 || v1) )
DAC_data_w(0LL, 0LL);
else
DAC_data_w(0LL, 255LL);
if ( !(time_16V_1 | attract) )
{
v2 = noise_l4;
noise_l4 = (unsigned __int8)((2 * noise_l4) | ((((unsigned __int8)noise_l4 ^ (unsigned __int8)(noise_k4 >> 6)) & 1) == 0));
noise_k4 = (unsigned __int8)((2 * noise_k4) | (v2 >> 7) & 1);
noise = noise_k4 >> 7;
}
if ( !aud0 && noise )
DAC_data_w(1LL, (unsigned int)volume);
else
DAC_data_w(1LL, 0LL);
result = 0LL;
if ( !time_16V_1 )
result = nmi_interrupt();
return result;
}

original_code:
int avalnche_interrupt(void)
{
 static int time_8V = 0;
 static int time_16V = 0;
 static int time_32V = 0;
 int k4_input;
 int l4_input;
 time_8V = (time_8V + 1) & 0x01;
 time_16V = (time_16V + 1) & 0x03;
 time_32V = (time_32V + 1) & 0x07;
 if ((attract==0) && (aud2==1) && (time_8V==0))
  DAC_data_w(0,255);
 else if ((attract==0) && (aud1==1) && (time_32V==0))
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if ((attract==0) && (time_16V==0))
 {
  l4_input = 0x01 ^ ((noise_l4 & 0x01) ^ (((noise_k4) & 0x40) >> 6));
  k4_input = (noise_l4 & 0x80) >> 7;
  noise_l4 = ((noise_l4 << 1) | l4_input) & 0xFF;
  noise_k4 = ((noise_k4 << 1) | k4_input) & 0xFF;
  noise = (noise_k4 & 0x80) >> 7;
 }
 if ((aud0==0) && (noise))
  DAC_data_w(1,volume);
 else
  DAC_data_w(1,0);
 if (time_16V==0)
  return nmi_interrupt();
 else
  return 0;
}

canonical_original_code:
int avalnche_interrupt()
{
 static int time_8V = 0;
 static int time_16V = 0;
 static int time_32V = 0;
 int k4_input;
 int l4_input;
 time_8V = (time_8V + 1) & 0x01;
 time_16V = (time_16V + 1) & 0x03;
 time_32V = (time_32V + 1) & 0x07;
 if ((attract==0) && (aud2==1) && (time_8V==0))
  DAC_data_w(0,255);
 else if ((attract==0) && (aud1==1) && (time_32V==0))
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if ((attract==0) && (time_16V==0))
 {
  l4_input = 0x01 ^ ((noise_l4 & 0x01) ^ (((noise_k4) & 0x40) >> 6));
  k4_input = (noise_l4 & 0x80) >> 7;
  noise_l4 = ((noise_l4 << 1) | l4_input) & 0xFF;
  noise_k4 = ((noise_k4 << 1) | k4_input) & 0xFF;
  noise = (noise_k4 & 0x80) >> 7;
 }
 if ((aud0==0) && (noise))
  DAC_data_w(1,volume);
 else
  DAC_data_w(1,0);
 if (time_16V==0)
  return nmi_interrupt();
 else
  return 0;
}

return_type: int


decompiled_code:
_BYTE *init_avalnche()
{
__int64 v0; // rcx
_BYTE *result; // rax
_BYTE *v2; // rcx
char v3; // dl

v0 = memory_region(129LL);
result = (_BYTE *)(v0 + 24576);
v2 = (_BYTE *)(v0 + 0x8000);
do
{
v3 = result[0x4000] + 16 * result[0x2000];
*result = v3;
result[0x8000] = v3;
++result;
}
while ( result != v2 );
return result;
}

canonical_decompiled_code:
_BYTE *func6()
{
__int64 v0; // rcx
_BYTE *result; // rax
_BYTE *v2; // rcx
char v3; // dl

v0 = memory_region(129LL);
result = (_BYTE *)(v0 + 24576);
v2 = (_BYTE *)(v0 + 0x8000);
do
{
v3 = result[0x4000] + 16 * result[0x2000];
*result = v3;
result[0x8000] = v3;
++result;
}
while ( result != v2 );
return result;
}

original_code:
static void init_avalnche(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for(i=0;i<0x2000;i++)
 {
  rom[0x6000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
  rom[0xE000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
 }
}

canonical_original_code:
static void init_avalnche()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for(i=0;i<0x2000;i++)
 {
  rom[0x6000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
  rom[0xE000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
 }
}

variable_types:
rom
unsigned char *

variable_types: i int

return_type: void


original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
}


decompiled_code:
__int64 __fastcall OPL_WRITE(unsigned int a1, unsigned int a2)
{
YM3812_control_port_0_w(0LL, a1);
return YM3812_write_port_0_w(0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
YM3812_control_port_0_w(0LL, a1);
return YM3812_write_port_0_w(0LL, a2);
}

original_code:
static inline void OPL_WRITE(int reg, int data)
{
 YM3812_control_port_0_w(0, reg);
 YM3812_write_port_0_w(0, data);
}

variable_types: reg int

variable_types: data int


decompiled_code:
__int64 __fastcall OPL_WRITE_DATA2(int a1, int a2, unsigned int a3)
{
return OPL_WRITE(order_1[a2] + a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, unsigned int a3)
{
return func0(order_1[a2] + a1, a3);
}

original_code:
static inline void OPL_WRITE_DATA2(int offset, int channel, int data)
{
 static const int order[9]={0x03,0x04,0x05,0x0b,0x0c,0x0d,0x13,0x14,0x15};
 OPL_WRITE(offset+order[channel], data);
}

canonical_original_code:
static inline void OPL_WRITE_DATA2(int offset, int channel, int data)
{
 static int order[9] = {0x03,0x04,0x05,0x0b,0x0c,0x0d,0x13,0x14,0x15};
 OPL_WRITE(offset+order[channel], data);
}

variable_types: offset int

variable_types: channel int

variable_types:
order
int [9]


decompiled_code:
__int64 __fastcall OPL_WRITE_DATA1(int a1, int a2, unsigned int a3)
{
return OPL_WRITE(order_0[a2] + a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, unsigned int a3)
{
return func0(order_0[a2] + a1, a3);
}

original_code:
static inline void OPL_WRITE_DATA1(int offset, int channel, int data)
{
 static const int order[9]={0x00,0x01,0x02,0x08,0x09,0x0a,0x10,0x11,0x12};
 OPL_WRITE(offset+order[channel], data);
}

canonical_original_code:
static inline void OPL_WRITE_DATA1(int offset, int channel, int data)
{
 static int order[9] = {0x00,0x01,0x02,0x08,0x09,0x0a,0x10,0x11,0x12};
 OPL_WRITE(offset+order[channel], data);
}


decompiled_code:
__int64 __fastcall ym2413_setinstrument(int a1, int a2, int a3)
{
int *v3; // rbp
__int64 i; // rbx
__int64 result; // rax

if ( a3 )
v3 = (int *)((char *)&ym2413_instruments + 48 * a3);
else
v3 = &ym2413_state[24 * a1 + 3];
for ( i = 0LL; i != 10; ++i )
{
if ( (i & 1) != 0 )
result = OPL_WRITE_DATA2(reg_2[i], a2, v3[i]);
else
result = OPL_WRITE_DATA1(reg_2[i], a2, v3[i]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3)
{
int *v3; // rbp
__int64 i; // rbx
__int64 result; // rax

if ( a3 )
v3 = (int *)((char *)&ym2413_instruments + 48 * a3);
else
v3 = &ym2413_state[24 * a1 + 3];
for ( i = 0LL; i != 10; ++i )
{
if ( (i & 1) != 0 )
result = func1(reg_2[i], a2, v3[i]);
else
result = func2(reg_2[i], a2, v3[i]);
}
return result;
}

original_code:
void ym2413_setinstrument(int chip, int channel, int inst)
{
 static const int reg[10]=
 {
  0x20,0x20,0x40,0x40,0x60,0x60,0x80,0x80,0xe0,0xe0
 };
 int *pn;
 int i;
 if (!inst)
 {
  pn=&ym2413_state[chip].user_instrument[0];
 }
 else
 {
  pn=&(ym2413_instruments[inst][0]);
 }
 for (i=0; i<10; i++)
 {
  if (i & 0x01)
  {
   OPL_WRITE_DATA2(reg[i], channel, *pn);
  }
  else
  {
   OPL_WRITE_DATA1(reg[i], channel, *pn);
  }
  pn++;
 }
}

canonical_original_code:
void ym2413_setinstrument(int chip, int channel, int inst)
{
 static int reg[10] = {
  0x20,0x20,0x40,0x40,0x60,0x60,0x80,0x80,0xe0,0xe0
 };
 int *pn;
 int i;
 if (!inst)
 {
  pn=&ym2413_state[chip].user_instrument[0];
 }
 else
 {
  pn=&(ym2413_instruments[inst][0]);
 }
 for (i=0; i<10; i++)
 {
  if (i & 0x01)
  {
   OPL_WRITE_DATA2(reg[i], channel, *pn);
  }
  else
  {
   OPL_WRITE_DATA1(reg[i], channel, *pn);
  }
  pn++;
 }
}

variable_types: chip int

variable_types: inst int

variable_types:
reg
int [10]

variable_types:
pn
int *


decompiled_code:
__int64 __fastcall YM2413_sh_start(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
int *v3; // rsi
__int64 v4; // rdx

v1 = 0LL;
memset(ym2413_state, 0, sizeof(ym2413_state));
do
{
ym2413_state[v1 + 3] = *(_DWORD *)((char *)&ym2413_instruments + v1 * 4);
++v1;
}
while ( v1 != 12 );
ym2413_state[0] = 50000;
v2 = 0LL;
memset(dword_7C0, 0, sizeof(dword_7C0));
v3 = &dword_7C0[3];
do
{
v4 = *(unsigned int *)((char *)&ym2413_instruments + v2 * 4);
v3[v2++] = v4;
}
while ( v2 != 12 );
dword_7C0[0] = 50000;
return YM3812_sh_start(a1, v3, v4, &ym2413_instruments);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
int *v3; // rsi
__int64 v4; // rdx

v1 = 0LL;
memset(ym2413_state, 0, sizeof(ym2413_state));
do
{
ym2413_state[v1 + 3] = *(_DWORD *)((char *)&ym2413_instruments + v1 * 4);
++v1;
}
while ( v1 != 12 );
ym2413_state[0] = 50000;
v2 = 0LL;
memset(dword_7C0, 0, sizeof(dword_7C0));
v3 = &dword_7C0[3];
do
{
v4 = *(unsigned int *)((char *)&ym2413_instruments + v2 * 4);
v3[v2++] = v4;
}
while ( v2 != 12 );
dword_7C0[0] = 50000;
return YM3812_sh_start(a1, v3, v4, &ym2413_instruments);
}

original_code:
int YM2413_sh_start(const struct MachineSound *msound)
{
 int i, j;
 for (i=0; i<2; i++)
 {
  memset(&ym2413_state[i], 0, sizeof(ym2413_state[0]));
  for (j=0; j<12; j++)
  {
   ym2413_state[i].user_instrument[j]=ym2413_instruments[0][j];
  }
        ym2413_state[i].fsam = ym2413_clock / 72;
 }
 return YM3812_sh_start(msound);
}

canonical_original_code:
int YM2413_sh_start(struct MachineSound *msound)
{
 int i; int j;
 for (i=0; i<2; i++)
 {
  memset(&ym2413_state[i], 0, sizeof(ym2413_state[0]));
  for (j=0; j<12; j++)
  {
   ym2413_state[i].user_instrument[j]=ym2413_instruments[0][j];
  }
        ym2413_state[i].fsam = ym2413_clock / 72;
 }
 return YM3812_sh_start(msound);
}

variable_types: struct MachineSound { int sound_type; void *sound_interface; } *

variable_types: j int


decompiled_code:
__int64 YM2413_sh_stop()
{
unsigned int i; // ebx

for ( i = 0; i != 245; ++i )
OPL_WRITE(i, 0);
return YM3812_sh_stop();
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int i; // ebx

for ( i = 0; i != 245; ++i )
func0(i, 0);
return YM3812_sh_stop();
}

original_code:
void YM2413_sh_stop(void)
{
 int i;
 for (i=0; i<0xf5; i++)
 {
  OPL_WRITE(i, 0);
 }
 YM3812_sh_stop();
}

canonical_original_code:
void YM2413_sh_stop()
{
 int i;
 for (i=0; i<0xf5; i++)
 {
  OPL_WRITE(i, 0);
 }
 YM3812_sh_stop();
}


decompiled_code:
__int64 YM2413_status_port_0_r()
{
return YM3812_status_port_0_r();
}

canonical_decompiled_code:
__int64 func6()
{
return YM3812_status_port_0_r();
}

original_code:
data_t YM2413_status_port_0_r(offs_t offset)
{
 return YM3812_status_port_0_r(offset);
}

canonical_original_code:
unsigned int YM2413_status_port_0_r(unsigned int offset)
{
 return YM3812_status_port_0_r(offset);
}

variable_types:
offset
unsigned int

return_type: unsigned int


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

result = 24LL * a1;
ym2413_state[result + 2] = a2;
return result * 4;
}

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

result = 24LL * a1;
ym2413_state[result + 2] = a2;
return result * 4;
}

original_code:
void YM2413_register_port_0_w(offs_t offset,data_t data)
{
 int chip = offset;
 ym2413_state[chip].pending_register=data;
}

canonical_original_code:
void YM2413_register_port_0_w(unsigned int offset, unsigned int data)
{
 int chip = offset;
 ym2413_state[chip].pending_register=data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall YM2413_data_port_0_w(int a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned __int8 v3; // bp
__int64 result; // rax
int v5; // eax
int v6; // kr00_4
int v7; // ebp
int v8; // esi

v2 = ym2413_state[24 * a1 + 2];
v3 = a2;
switch ( v2 )
{
case 0u:
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
result = (__int64)ym2413_state;
ym2413_state[24 * a1 + 3 + v2] = a2;
break;
case 0xEu:
ym2413_state[24 * a1 + 1] = a2 & 0x20;
if ( (a2 & 0x20) != 0 )
{
OPL_WRITE(0xB6u, 0);
OPL_WRITE(0xB7u, 0);
OPL_WRITE(0xB8u, 0);
ym2413_setinstrument(a1, 6, 16);
ym2413_setinstrument(a1, 7, 17);
ym2413_setinstrument(a1, 8, 18);
}
result = OPL_WRITE(0xBDu, a2 & 0x3F);
break;
case 0x10u:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
result = (__int64)ym2413_state;
ym2413_state[24 * a1 + 15 + v2 - 16] = a2;
break;
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x27u:
case 0x28u:
v6 = ym2413_state[24 * a1]
* (2 << (((a2 >> 1) & 7) - 1))
* (ym2413_state[24 * a1 + 15 + v2 - 32] | ((_WORD)a2 << 8) & 0x100);
v5 = v6 + (v6 < 0 ? 0x7FFFF : 0);
v7 = (4 * ((v5 >> 29) & 0xF) + 12) | (2 * (_BYTE)a2) & 0x20 | (v5 >> 27) & 3;
OPL_WRITE(v2 + 128, (unsigned __int8)(v6 / 0x80000));
result = OPL_WRITE(v2 + 144, v7);
break;
case 0x30u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
v8 = v2 - 48;
result = 96LL * a1;
if ( !*(int *)((char *)&ym2413_state[1] + result) || v8 <= 5 )
result = ym2413_setinstrument(a1, v8, v3 >> 4);
break;
default:
result = logerror("YM2413: Write to register %02x\n", v2);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned __int8 v3; // bp
__int64 result; // rax
int v5; // eax
int v6; // kr00_4
int v7; // ebp
int v8; // esi

v2 = ym2413_state[24 * a1 + 2];
v3 = a2;
switch ( v2 )
{
case 0u:
case 1u:
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
result = (__int64)ym2413_state;
ym2413_state[24 * a1 + 3 + v2] = a2;
break;
case 0xEu:
ym2413_state[24 * a1 + 1] = a2 & 0x20;
if ( (a2 & 0x20) != 0 )
{
func0(0xB6u, 0);
func0(0xB7u, 0);
func0(0xB8u, 0);
func3(a1, 6, 16);
func3(a1, 7, 17);
func3(a1, 8, 18);
}
result = func0(0xBDu, a2 & 0x3F);
break;
case 0x10u:
case 0x11u:
case 0x12u:
case 0x13u:
case 0x14u:
case 0x15u:
case 0x16u:
case 0x17u:
case 0x18u:
result = (__int64)ym2413_state;
ym2413_state[24 * a1 + 15 + v2 - 16] = a2;
break;
case 0x20u:
case 0x21u:
case 0x22u:
case 0x23u:
case 0x24u:
case 0x25u:
case 0x26u:
case 0x27u:
case 0x28u:
v6 = ym2413_state[24 * a1]
* (2 << (((a2 >> 1) & 7) - 1))
* (ym2413_state[24 * a1 + 15 + v2 - 32] | ((_WORD)a2 << 8) & 0x100);
v5 = v6 + (v6 < 0 ? 0x7FFFF : 0);
v7 = (4 * ((v5 >> 29) & 0xF) + 12) | (2 * (_BYTE)a2) & 0x20 | (v5 >> 27) & 3;
func0(v2 + 128, (unsigned __int8)(v6 / 0x80000));
result = func0(v2 + 144, v7);
break;
case 0x30u:
case 0x31u:
case 0x32u:
case 0x33u:
case 0x34u:
case 0x35u:
case 0x36u:
case 0x37u:
case 0x38u:
v8 = v2 - 48;
result = 96LL * a1;
if ( !*(int *)((char *)&ym2413_state[1] + result) || v8 <= 5 )
result = func3(a1, v8, v3 >> 4);
break;
default:
result = logerror("YM2413: Write to register %02x\n", v2);
break;
}
return result;
}

original_code:
void YM2413_data_port_0_w(offs_t offset,data_t data)
{
 int chip = offset;
    int value, channel, instrument, i, block, volume, frq, fnumber, octave;
 int pending=ym2413_state[chip].pending_register;
 switch(pending)
 {
  case 0x00:
  case 0x01:
  case 0x02:
  case 0x03:
  case 0x04:
  case 0x05:
  case 0x06:
  case 0x07:
    ym2413_state[chip].user_instrument[pending] = data;
    break;
  case 0x0e:
    ym2413_state[chip].rhythm_mode=data&0x20;
    if (data & 0x20 )
    {
     for (i=6; i<9; i++)
     {
      OPL_WRITE(0xb0+i, 0);
     }
     ym2413_setinstrument(chip, 6, 16);
     ym2413_setinstrument(chip, 7, 17);
     ym2413_setinstrument(chip, 8, 18);
    }
    OPL_WRITE(0xbd, data & 0x3f);
    break;
  case 0x10:
  case 0x11:
  case 0x12:
  case 0x13:
  case 0x14:
  case 0x15:
  case 0x16:
  case 0x17:
  case 0x18:
    channel=pending-0x10;
                ym2413_state[chip].fnumberlow[channel]=data;
    break;
  case 0x20:
  case 0x21:
  case 0x22:
  case 0x23:
  case 0x24:
  case 0x25:
  case 0x26:
  case 0x27:
  case 0x28:
    channel=pending-0x20;
                fnumber=ym2413_state[chip].fnumberlow[channel]|(data&0x01)<<8;
                block = (data >> 1) & 0x07;
                frq=fnumber * ( 2 << (block-1) ) *
                              ym2413_state[chip].fsam / (2<<18);
                octave = ((frq >> 10) & 0x0f) + 3;
                frq &= 0x3ff;
                value = ( data & 0x10) << 1;
                value |= (frq >> 8) & 0x03;
                value |= octave << 2;
                OPL_WRITE(0xa0+channel, frq & 0xff);
                OPL_WRITE(0xb0+channel, value);
    break;
  case 0x30:
  case 0x31:
  case 0x32:
  case 0x33:
  case 0x34:
  case 0x35:
  case 0x36:
  case 0x37:
  case 0x38:
    channel=pending-0x30;
    if (ym2413_state[chip].rhythm_mode && channel >= 6)
    {
    }
    else
    {
     instrument=(data >> 4) & 0x0f;
     ym2413_setinstrument(chip, channel, instrument);
     volume=data & 0x0f;
    }
    break;
  default:
    logerror("YM2413: Write to register %02x\n", pending);
    break;
 }
}

canonical_original_code:
void YM2413_data_port_0_w(unsigned int offset, unsigned int data)
{
 int chip = offset;
    int value; int channel; int instrument; int i; int block; int volume; int frq; int fnumber; int octave;
 int pending = ym2413_state[chip].pending_register;
 switch(pending)
 {
  case 0x00:
  case 0x01:
  case 0x02:
  case 0x03:
  case 0x04:
  case 0x05:
  case 0x06:
  case 0x07:
    ym2413_state[chip].user_instrument[pending] = data;
    break;
  case 0x0e:
    ym2413_state[chip].rhythm_mode=data&0x20;
    if (data & 0x20 )
    {
     for (i=6; i<9; i++)
     {
      OPL_WRITE(0xb0+i, 0);
     }
     ym2413_setinstrument(chip, 6, 16);
     ym2413_setinstrument(chip, 7, 17);
     ym2413_setinstrument(chip, 8, 18);
    }
    OPL_WRITE(0xbd, data & 0x3f);
    break;
  case 0x10:
  case 0x11:
  case 0x12:
  case 0x13:
  case 0x14:
  case 0x15:
  case 0x16:
  case 0x17:
  case 0x18:
    channel=pending-0x10;
                ym2413_state[chip].fnumberlow[channel]=data;
    break;
  case 0x20:
  case 0x21:
  case 0x22:
  case 0x23:
  case 0x24:
  case 0x25:
  case 0x26:
  case 0x27:
  case 0x28:
    channel=pending-0x20;
                fnumber=ym2413_state[chip].fnumberlow[channel]|(data&0x01)<<8;
                block = (data >> 1) & 0x07;
                frq=fnumber * ( 2 << (block-1) ) *
                              ym2413_state[chip].fsam / (2<<18);
                octave = ((frq >> 10) & 0x0f) + 3;
                frq &= 0x3ff;
                value = ( data & 0x10) << 1;
                value |= (frq >> 8) & 0x03;
                value |= octave << 2;
                OPL_WRITE(0xa0+channel, frq & 0xff);
                OPL_WRITE(0xb0+channel, value);
    break;
  case 0x30:
  case 0x31:
  case 0x32:
  case 0x33:
  case 0x34:
  case 0x35:
  case 0x36:
  case 0x37:
  case 0x38:
    channel=pending-0x30;
    if (ym2413_state[chip].rhythm_mode && channel >= 6)
    {
    }
    else
    {
     instrument=(data >> 4) & 0x0f;
     ym2413_setinstrument(chip, channel, instrument);
     volume=data & 0x0f;
    }
    break;
  default:
    logerror("YM2413: Write to register %02x\n", pending);
    break;
 }
}

variable_types: value int

variable_types: instrument int

variable_types: block int

variable_types: volume int

variable_types: frq int

variable_types: fnumber int

variable_types: octave int

variable_types: pending int


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

result = addr_1 ^ 2u;
addr_1 ^= 2u;
return result;
}

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

result = addr_1 ^ 2u;
addr_1 ^= 2u;
return result;
}

original_code:
int airbustr_interrupt(void)
{
static int addr = 0xff;
 addr ^= 0x02;
 return addr;
}

canonical_original_code:
int airbustr_interrupt()
{
static int addr = 0xff;
 addr ^= 0x02;
 return addr;
}

variable_types: addr int


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

result = addr_0 ^ 2u;
addr_0 ^= 2u;
return result;
}

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

result = addr_0 ^ 2u;
addr_0 ^= 2u;
return result;
}

original_code:
int airbustr_interrupt2(void)
{
static int addr = 0xfd;
 addr ^= 0x02;
 return addr;
}

canonical_original_code:
int airbustr_interrupt2()
{
static int addr = 0xfd;
 addr ^= 0x02;
 return addr;
}


decompiled_code:
__int64 soundcommand_status_r()
{
return (unsigned int)(1 - soundlatch2_status + 2 * soundlatch_status + 4);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)(1 - soundlatch2_status + 2 * soundlatch_status + 4);
}

original_code:
static data_t soundcommand_status_r(offs_t offset)
{
 return 4 + soundlatch_status * 2 + (1-soundlatch2_status);
}

canonical_original_code:
static unsigned int soundcommand_status_r(unsigned int offset)
{
 return 4 + soundlatch_status * 2 + (1-soundlatch2_status);
}


decompiled_code:
__int64 airbustr_vh_start()
{
__int64 v1; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v1) = 32;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, v1);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v1; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v1) = 32;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, v1);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

original_code:
int airbustr_vh_start(void)
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int airbustr_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall airbustr_scrollregs_w(int a1, int a2)
{
int v2; // ebx
int v3; // ebp

v2 = (unsigned __int8)-(flipscreen == 0) - 511;
v3 = flipscreen == 0 ? -148 : -106;
switch ( a1 )
{
case 0:
fg_scrolly_6 = a2;
break;
case 2:
fg_scrollx_5 = a2;
break;
case 4:
bg_scrolly_4 = a2;
break;
case 6:
bg_scrollx_3 = a2;
break;
case 8:
highbits_2 = ~a2;
break;
default:
break;
}
tilemap_set_scrollx(bg_tilemap, 0LL, v3 + bg_scrollx_3 + (((_WORD)highbits_2 << 6) & 0x100u));
tilemap_set_scrolly(bg_tilemap, 0LL, v2 + bg_scrolly_4 + ((32 * (_WORD)highbits_2) & 0x100u));
tilemap_set_scrollx(fg_tilemap, 0LL, v3 + fg_scrollx_5 + (((_WORD)highbits_2 << 8) & 0x100u));
return tilemap_set_scrolly(fg_tilemap, 0LL, v2 + fg_scrolly_6 + (((_WORD)highbits_2 << 7) & 0x100u));
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
int v2; // ebx
int v3; // ebp

v2 = (unsigned __int8)-(flipscreen == 0) - 511;
v3 = flipscreen == 0 ? -148 : -106;
switch ( a1 )
{
case 0:
fg_scrolly_6 = a2;
break;
case 2:
fg_scrollx_5 = a2;
break;
case 4:
bg_scrolly_4 = a2;
break;
case 6:
bg_scrollx_3 = a2;
break;
case 8:
highbits_2 = ~a2;
break;
default:
break;
}
tilemap_set_scrollx(bg_tilemap, 0LL, v3 + bg_scrollx_3 + (((_WORD)highbits_2 << 6) & 0x100u));
tilemap_set_scrolly(bg_tilemap, 0LL, v2 + bg_scrolly_4 + ((32 * (_WORD)highbits_2) & 0x100u));
tilemap_set_scrollx(fg_tilemap, 0LL, v3 + fg_scrollx_5 + (((_WORD)highbits_2 << 8) & 0x100u));
return tilemap_set_scrolly(fg_tilemap, 0LL, v2 + fg_scrolly_6 + (((_WORD)highbits_2 << 7) & 0x100u));
}

original_code:
void airbustr_scrollregs_w(offs_t offset,data_t data)
{
static int bg_scrollx, bg_scrolly, fg_scrollx, fg_scrolly, highbits;
int xoffs, yoffs;
 if (flipscreen) { xoffs = -0x06a; yoffs = -0x1ff;}
 else { xoffs = -0x094; yoffs = -0x100;}
 switch (offset)
 {
  case 0x00: fg_scrolly = data; break;
  case 0x02: fg_scrollx = data; break;
  case 0x04: bg_scrolly = data; break;
  case 0x06: bg_scrollx = data; break;
  case 0x08: highbits = ~data; break;
  default:
      break;
 }
 tilemap_set_scrollx(bg_tilemap, 0, ((highbits << 6) & 0x100) + bg_scrollx + xoffs );
 tilemap_set_scrolly(bg_tilemap, 0, ((highbits << 5) & 0x100) + bg_scrolly + yoffs );
 tilemap_set_scrollx(fg_tilemap, 0, ((highbits << 8) & 0x100) + fg_scrollx + xoffs );
 tilemap_set_scrolly(fg_tilemap, 0, ((highbits << 7) & 0x100) + fg_scrolly + yoffs );
}

canonical_original_code:
void airbustr_scrollregs_w(unsigned int offset, unsigned int data)
{
static int bg_scrollx; static int bg_scrolly; static int fg_scrollx; static int fg_scrolly; static int highbits;
int xoffs; int yoffs;
 if (flipscreen) { xoffs = -0x06a; yoffs = -0x1ff;}
 else { xoffs = -0x094; yoffs = -0x100;}
 switch (offset)
 {
  case 0x00: fg_scrolly = data; break;
  case 0x02: fg_scrollx = data; break;
  case 0x04: bg_scrolly = data; break;
  case 0x06: bg_scrollx = data; break;
  case 0x08: highbits = ~data; break;
  default:
      break;
 }
 tilemap_set_scrollx(bg_tilemap, 0, ((highbits << 6) & 0x100) + bg_scrollx + xoffs );
 tilemap_set_scrolly(bg_tilemap, 0, ((highbits << 5) & 0x100) + bg_scrolly + yoffs );
 tilemap_set_scrollx(fg_tilemap, 0, ((highbits << 8) & 0x100) + fg_scrollx + xoffs );
 tilemap_set_scrolly(fg_tilemap, 0, ((highbits << 7) & 0x100) + fg_scrolly + yoffs );
}

variable_types: highbits int

variable_types: xoffs int

variable_types: yoffs int


decompiled_code:
__int64 __fastcall airbustr_vh_screenrefresh(__int64 a1)
{
_BYTE *v1; // rdx
__int64 v2; // rsi
__int64 v3; // rax
_BYTE *v4; // rdx
__int64 v5; // rsi
__int64 v6; // rcx
__int64 v7; // rax

tilemap_update(0LL);
palette_init_used_colors();
v1 = (_BYTE *)(spriteram + 768LL);
v2 = spriteram + 1024LL;
do
{
v3 = palette_used_colors + (*v1 & 0xF0) + 513LL;
*(_QWORD *)v3 = 0x303030303030303LL;
*(_DWORD *)(v3 + 8) = 50529027;
*(_WORD *)(v3 + 12) = 771;
*(_BYTE *)(v3 + 14) = 3;
++v1;
}
while ( v1 != (_BYTE *)v2 );
v4 = (_BYTE *)(spriteram + 2816LL);
v5 = spriteram + 3072LL;
do
{
v6 = palette_used_colors;
v7 = palette_used_colors + (*v4 & 0xF0) + 513LL;
*(_QWORD *)v7 = 0x303030303030303LL;
*(_DWORD *)(v7 + 8) = 50529027;
*(_WORD *)(v7 + 12) = 771;
*(_BYTE *)(v7 + 14) = 3;
++v4;
}
while ( v4 != (_BYTE *)v5 );
if ( palette_recalc(0x303030303030303LL, v5, v4, v6, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
return draw_sprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_BYTE *v1; // rdx
__int64 v2; // rsi
__int64 v3; // rax
_BYTE *v4; // rdx
__int64 v5; // rsi
__int64 v6; // rcx
__int64 v7; // rax

tilemap_update(0LL);
palette_init_used_colors();
v1 = (_BYTE *)(spriteram + 768LL);
v2 = spriteram + 1024LL;
do
{
v3 = palette_used_colors + (*v1 & 0xF0) + 513LL;
*(_QWORD *)v3 = 0x303030303030303LL;
*(_DWORD *)(v3 + 8) = 50529027;
*(_WORD *)(v3 + 12) = 771;
*(_BYTE *)(v3 + 14) = 3;
++v1;
}
while ( v1 != (_BYTE *)v2 );
v4 = (_BYTE *)(spriteram + 2816LL);
v5 = spriteram + 3072LL;
do
{
v6 = palette_used_colors;
v7 = palette_used_colors + (*v4 & 0xF0) + 513LL;
*(_QWORD *)v7 = 0x303030303030303LL;
*(_DWORD *)(v7 + 8) = 50529027;
*(_WORD *)(v7 + 12) = 771;
*(_BYTE *)(v7 + 14) = 3;
++v4;
}
while ( v4 != (_BYTE *)v5 );
if ( palette_recalc(0x303030303030303LL, v5, v4, v6, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
return func10(a1);
}

original_code:
void airbustr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
unsigned char *ram;
int i, offs;
 tilemap_update(0);
 palette_init_used_colors();
 for (i = 0 ; i < 2 ; i++)
 {
  ram = &spriteram[i * 0x800 + 0x300];
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int color = 256 * 2 + (ram[offs] & 0xf0);
   memset(&palette_used_colors[color+1],(1|2),16-1);
  }
 }
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 draw_sprites(bitmap);
}

canonical_original_code:
void airbustr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
unsigned char *ram;
int i; int offs;
 tilemap_update(0);
 palette_init_used_colors();
 for (i = 0 ; i < 2 ; i++)
 {
  ram = &spriteram[i * 0x800 + 0x300];
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int color = 256 * 2 + (ram[offs] & 0xf0);
   memset(&palette_used_colors[color+1],(1|2),16-1);
  }
 }
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 draw_sprites(bitmap);
}

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

variable_types:
ram
unsigned char *

variable_types: i int

variable_types: offs int

variable_types: color int


decompiled_code:
int __fastcall devram_r(unsigned int a1)
{
int result; // eax
__int16 v2; // cx

if ( a1 > 0xFF3 )
{
if ( a1 == 4084 )
return rand();
return *(unsigned __int8 *)(devram + a1);
}
if ( a1 <= 0xFF1 )
{
result = 0;
if ( a1 == 4064 )
return result;
return *(unsigned __int8 *)(devram + a1);
}
v2 = *(unsigned __int8 *)(devram + 4082LL);
result = (unsigned __int8)((unsigned __int16)((v2 + (*(unsigned __int8 *)(devram + 4083LL) << 8))
* (*(unsigned __int8 *)(devram + 4080LL)
+ (*(unsigned __int8 *)(devram + 4081LL) << 8))) >> 8);
if ( a1 == 4082 )
result = (unsigned __int8)(v2 * *(_BYTE *)(devram + 4080LL));
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1)
{
int result; // eax
__int16 v2; // cx

if ( a1 > 0xFF3 )
{
if ( a1 == 4084 )
return rand();
return *(unsigned __int8 *)(devram + a1);
}
if ( a1 <= 0xFF1 )
{
result = 0;
if ( a1 == 4064 )
return result;
return *(unsigned __int8 *)(devram + a1);
}
v2 = *(unsigned __int8 *)(devram + 4082LL);
result = (unsigned __int8)((unsigned __int16)((v2 + (*(unsigned __int8 *)(devram + 4083LL) << 8))
* (*(unsigned __int8 *)(devram + 4080LL)
+ (*(unsigned __int8 *)(devram + 4081LL) << 8))) >> 8);
if ( a1 == 4082 )
result = (unsigned __int8)(v2 * *(_BYTE *)(devram + 4080LL));
return result;
}

original_code:
data_t devram_r(offs_t offset)
{
 switch (offset)
 {
  case 0xfe0:
   return 0 ;
   break;
  case 0xff2:
  case 0xff3:
  {
   int x = (devram[0xff0] + devram[0xff1] * 256) *
     (devram[0xff2] + devram[0xff3] * 256);
   if (offset == 0xff2) return (x & 0x00FF) >> 0;
   else return (x & 0xFF00) >> 8;
  } break;
  case 0xff4:
  {
   return rand();
  } break;
  default: { return devram[offset]; break;}
 }
}

canonical_original_code:
unsigned int devram_r(unsigned int offset)
{
 switch (offset)
 {
  case 0xfe0:
   return 0 ;
   break;
  case 0xff2:
  case 0xff3:
  {
   int x = (devram[0xff0] + devram[0xff1] * 256) *
     (devram[0xff2] + devram[0xff3] * 256);
   if (offset == 0xff2) return (x & 0x00FF) >> 0;
   else return (x & 0xFF00) >> 8;
  } break;
  case 0xff4:
  {
   return rand();
  } break;
  default: { return devram[offset]; break;}
 }
}

variable_types:
offset
unsigned int

variable_types: x int


decompiled_code:
__int64 __fastcall airbustr_paletteram_w(unsigned int a1, char a2)
{
int v2; // ecx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFFFFFFE));
return palette_change_color(
a1 >> 1,
(unsigned int)((int)(255
* (((unsigned int)(v2 | (*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8)) >> 5) & 0x1F))
/ 31),
(unsigned int)((int)(255 * (((unsigned int)(*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8) >> 10) & 0x1F))
/ 31),
(unsigned int)(255 * (v2 & 0x1F) / 31));
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, char a2)
{
int v2; // ecx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFFFFFFE));
return palette_change_color(
a1 >> 1,
(unsigned int)((int)(255
* (((unsigned int)(v2 | (*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8)) >> 5) & 0x1F))
/ 31),
(unsigned int)((int)(255 * (((unsigned int)(*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8) >> 10) & 0x1F))
/ 31),
(unsigned int)(255 * (v2 & 0x1F) / 31));
}

original_code:
void airbustr_paletteram_w(offs_t offset,data_t data)
{
int r,g,b;
 paletteram[offset] = data;
 data = (paletteram[offset | 1] << 8) | paletteram[offset & ~1];
 g = (data >> 10) & 0x1f;
 r = (data >> 5) & 0x1f;
 b = (data >> 0) & 0x1f;
 palette_change_color(offset/2, (r * 0xff) / 0x1f,
         (g * 0xff) / 0x1f,
         (b * 0xff) / 0x1f );
}

canonical_original_code:
void airbustr_paletteram_w(unsigned int offset, unsigned int data)
{
int r; int g; int b;
 paletteram[offset] = data;
 data = (paletteram[offset | 1] << 8) | paletteram[offset & ~1];
 g = (data >> 10) & 0x1f;
 r = (data >> 5) & 0x1f;
 b = (data >> 0) & 0x1f;
 palette_change_color(offset/2, (r * 0xff) / 0x1f,
         (g * 0xff) / 0x1f,
         (b * 0xff) / 0x1f );
}

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 soundcommand_r()
{
soundlatch_status = 0;
return soundlatch_r(0LL);
}

canonical_decompiled_code:
__int64 func14()
{
soundlatch_status = 0;
return soundlatch_r(0LL);
}

original_code:
data_t soundcommand_r(offs_t offset)
{
 soundlatch_status = 0;
 return soundlatch_r(0);
}

canonical_original_code:
unsigned int soundcommand_r(unsigned int offset)
{
 soundlatch_status = 0;
 return soundlatch_r(0);
}


decompiled_code:
__int64 soundcommand2_w()
{
soundlatch2_status = 1;
return soundlatch2_w(0LL);
}

canonical_decompiled_code:
__int64 func15()
{
soundlatch2_status = 1;
return soundlatch2_w(0LL);
}

original_code:
void soundcommand2_w(offs_t offset,data_t data)
{
 soundlatch2_status = 1;
 soundlatch2_w(0,data);
}

canonical_original_code:
void soundcommand2_w(unsigned int offset, unsigned int data)
{
 soundlatch2_status = 1;
 soundlatch2_w(0,data);
}


original_code:
void init_airbustr(void)
{
int i;
unsigned char *RAM;
 RAM = memory_region(REGION_GFX1) + 0x000000;
 for (i = 0; i < 0x80000; i ++)
 {
  RAM[i] = ((RAM[i] & 0xF0)>>4) + ((RAM[i] & 0x0F)<<4);
 }
 RAM = memory_region(REGION_CPU1);
 RAM[0x37f4] = 0x00; RAM[0x37f5] = 0x00;
 RAM = memory_region(REGION_CPU2);
 RAM[0x0258] = 0x53;
}

canonical_original_code:
void init_airbustr()
{
int i;
unsigned char *RAM;
 RAM = memory_region(REGION_GFX1) + 0x000000;
 for (i = 0; i < 0x80000; i ++)
 {
  RAM[i] = ((RAM[i] & 0xF0)>>4) + ((RAM[i] & 0x0F)<<4);
 }
 RAM = memory_region(REGION_CPU1);
 RAM[0x37f4] = 0x00; RAM[0x37f5] = 0x00;
 RAM = memory_region(REGION_CPU2);
 RAM[0x0258] = 0x53;
}

variable_types:
RAM
unsigned char *


decompiled_code:
_DWORD *airbustr_init_machine()
{
soundlatch2_status = 0;
soundlatch_status = 0;
bankswitch_w(0LL, 2);
bankswitch2_w(0LL, 2);
return sound_bankswitch_w(0LL, 2);
}

canonical_decompiled_code:
_DWORD *func17()
{
soundlatch2_status = 0;
soundlatch_status = 0;
bankswitch_w(0LL, 2);
bankswitch2_w(0LL, 2);
return sound_bankswitch_w(0LL, 2);
}

original_code:
static void airbustr_init_machine (void)
{
 soundlatch_status = soundlatch2_status = 0;
 bankswitch_w(0,2);
 bankswitch2_w(0,2);
 sound_bankswitch_w(0,2);
}

canonical_original_code:
static void airbustr_init_machine()
{
 soundlatch_status = soundlatch2_status = 0;
 bankswitch_w(0,2);
 bankswitch2_w(0,2);
 sound_bankswitch_w(0,2);
}


decompiled_code:
__int64 cause_nmi_w()
{
return cpu_cause_interrupt(1LL, 4294967294LL);
}

canonical_decompiled_code:
__int64 func19()
{
return cpu_cause_interrupt(1LL, 4294967294LL);
}

original_code:
static void cause_nmi_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(1,-2);
}

canonical_original_code:
static void cause_nmi_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(1,-2);
}


decompiled_code:
__int64 soundcommand2_r()
{
soundlatch2_status = 0;
return soundlatch2_r(0LL);
}

canonical_decompiled_code:
__int64 func20()
{
soundlatch2_status = 0;
return soundlatch2_r(0LL);
}

original_code:
static data_t soundcommand2_r(offs_t offset)
{
 soundlatch2_status = 0;
 return soundlatch2_r(0);
}

canonical_original_code:
static unsigned int soundcommand2_r(unsigned int offset)
{
 soundlatch2_status = 0;
 return soundlatch2_r(0);
}


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(airbustr_fgram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(airbustr_fgram + a1) + ((v1 << 8) & 0xF00u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 4);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(airbustr_fgram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(airbustr_fgram + a1) + ((v1 << 8) & 0xF00u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 4);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_fgram[tile_index + 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_fgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_fgram[tile_index + 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_fgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types:
attr
unsigned char

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_bg_tile_info(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(airbustr_bgram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(airbustr_bgram + a1) + ((v1 << 8) & 0xF00u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (unsigned __int8)((v1 >> 4) + 16);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(airbustr_bgram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(airbustr_bgram + a1) + ((v1 << 8) & 0xF00u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (unsigned __int8)((v1 >> 4) + 16);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_bgram[tile_index + 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_bgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_bgram[tile_index + 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_bgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]: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 sharedram_r(unsigned int a1)
{
return *(unsigned __int8 *)(sharedram + a1);
}

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

original_code: static data_t sharedram_r(offs_t offset) { return sharedram[offset]; }

canonical_original_code: static unsigned int sharedram_r(unsigned int offset) { return sharedram[offset]; }


original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
int i, offs;
 for (i = 0 ; i < 2 ; i++)
 {
  unsigned char *ram = &spriteram[i * 0x800];
  int sx = 0;
  int sy = 0;
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int attr = ram[offs + 0x300];
   int x = ram[offs + 0x400] - ((attr << 8) & 0x100);
   int y = ram[offs + 0x500] - ((attr << 7) & 0x100);
   int gfx = ram[offs + 0x700];
   int code = ram[offs + 0x600] + ((gfx & 0x1f) << 8);
   int flipx = gfx & 0x80;
   int flipy = gfx & 0x40;
   if (attr & 0x04) { sx += x; sy += y;}
   else { sx = x; sy = y;}
   if (flipscreen)
   {
    sx = 240 - sx; sy = 240 - sy;
    flipx = !flipx; flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,
     attr >> 4,
     flipx, flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (flipscreen) {sx = 240 - sx; sy = 240 - sy;}
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
int i; int offs;
 for (i = 0 ; i < 2 ; i++)
 {
  unsigned char *ram = &spriteram[i * 0x800];
  int sx = 0;
  int sy = 0;
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int attr = ram[offs + 0x300];
   int x = ram[offs + 0x400] - ((attr << 8) & 0x100);
   int y = ram[offs + 0x500] - ((attr << 7) & 0x100);
   int gfx = ram[offs + 0x700];
   int code = ram[offs + 0x600] + ((gfx & 0x1f) << 8);
   int flipx = gfx & 0x80;
   int flipy = gfx & 0x40;
   if (attr & 0x04) { sx += x; sy += y;}
   else { sx = x; sy = y;}
   if (flipscreen)
   {
    sx = 240 - sx; sy = 240 - sy;
    flipx = !flipx; flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,
     attr >> 4,
     flipx, flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (flipscreen) {sx = 240 - sx; sy = 240 - sy;}
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: attr int

variable_types: y int

variable_types: gfx int

variable_types: code int

variable_types: flipx int

variable_types: flipy int

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


decompiled_code:
__int64 soundcommand_w()
{
soundlatch_w(0LL);
soundlatch_status = 1;
return cpu_cause_interrupt(2LL, 4294967294LL);
}

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

original_code:
static void soundcommand_w(offs_t offset,data_t data)
{
 soundlatch_w(0,data);
 soundlatch_status = 1;
 cpu_cause_interrupt(2,-2);
}

canonical_original_code:
static void soundcommand_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(0,data);
 soundlatch_status = 1;
 cpu_cause_interrupt(2,-2);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall ddrible_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 24LL));
if ( (int)result > 0 )
{
result = 0LL;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v3 + 824) + 688LL) + 88LL) + (int)result)) = *(_BYTE *)(a3 + result) & 0xF;
v3 = Machine;
++result;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 24LL) > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax

v3 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 24LL));
if ( (int)result > 0 )
{
result = 0LL;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v3 + 824) + 688LL) + 88LL) + (int)result)) = *(_BYTE *)(a3 + result) & 0xF;
v3 = Machine;
++result;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 24LL) > (int)result );
}
return result;
}

original_code:
void ddrible_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < (Machine->gfx[3]->total_colors * Machine->gfx[3]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[3].color_codes_start + i]) = (*(color_prom++) & 0x0f);
}

canonical_original_code:
void ddrible_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < (Machine->gfx[3]->total_colors * Machine->gfx[3]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[3].color_codes_start + i]) = (*(color_prom++) & 0x0f);
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


original_code:
static UINT32 tilemap_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 6);
}

canonical_original_code:
static unsigned int tilemap_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 6);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


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

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

original_code:
static data_t ddrible_sharedram_r(offs_t offset)
{
 return ddrible_sharedram[offset];
}

canonical_original_code:
static unsigned int ddrible_sharedram_r(unsigned int offset)
{
 return ddrible_sharedram[offset];
}


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

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

original_code:
static data_t ddrible_snd_sharedram_r(offs_t offset)
{
 return ddrible_snd_sharedram[offset];
}

canonical_original_code:
static unsigned int ddrible_snd_sharedram_r(unsigned int offset)
{
 return ddrible_snd_sharedram[offset];
}


decompiled_code:
int *__fastcall K005885_0_w(int a1, int a2)
{
int *result; // rax

if ( a1 == 3 )
{
result = (int *)(a2 & 2);
if ( (_DWORD)result != dword_132C )
{
dword_132C = a2 & 2;
result = (int *)tilemap_mark_all_tiles_dirty(fg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_0;
ddrible_int_enable_0 = a2 & 2;
dword_1330 = a2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1] = a2;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func8(int a1, int a2)
{
int *result; // rax

if ( a1 == 3 )
{
result = (int *)(a2 & 2);
if ( (_DWORD)result != dword_132C )
{
dword_132C = a2 & 2;
result = (int *)tilemap_mark_all_tiles_dirty(fg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_0;
ddrible_int_enable_0 = a2 & 2;
dword_1330 = a2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1] = a2;
}
return result;
}

original_code:
void K005885_0_w(offs_t offset,data_t data)
{
 switch (offset){
  case 0x03:
   if ((data & 0x02) != ddribble_vregs[0][3]){
    ddribble_vregs[0][3] = (data & 0x02);
    tilemap_mark_all_tiles_dirty( fg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_0 = data & 0x02;
   ddribble_vregs[0][4] = data;
   break;
  default:
   ddribble_vregs[0][offset] = data;
 }
}

canonical_original_code:
void K005885_0_w(unsigned int offset, unsigned int data)
{
 switch (offset){
  case 0x03:
   if ((data & 0x02) != ddribble_vregs[0][3]){
    ddribble_vregs[0][3] = (data & 0x02);
    tilemap_mark_all_tiles_dirty( fg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_0 = data & 0x02;
   ddribble_vregs[0][4] = data;
   break;
  default:
   ddribble_vregs[0][offset] = data;
 }
}

variable_types:
data
unsigned int


decompiled_code:
int *__fastcall K005885_1_w(int a1, int a2)
{
int *result; // rax
char v3; // si

if ( a1 == 3 )
{
v3 = 2 * a2;
result = (int *)(v3 & 6);
if ( (_DWORD)result != dword_1340 )
{
dword_1340 = v3 & 6;
result = (int *)tilemap_mark_all_tiles_dirty(bg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_1;
ddrible_int_enable_1 = a2 & 2;
dword_1344 = a2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1 + 5] = a2;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func9(int a1, int a2)
{
int *result; // rax
char v3; // si

if ( a1 == 3 )
{
v3 = 2 * a2;
result = (int *)(v3 & 6);
if ( (_DWORD)result != dword_1340 )
{
dword_1340 = v3 & 6;
result = (int *)tilemap_mark_all_tiles_dirty(bg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_1;
ddrible_int_enable_1 = a2 & 2;
dword_1344 = a2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1 + 5] = a2;
}
return result;
}

original_code:
void K005885_1_w(offs_t offset,data_t data)
{
 switch (offset){
  case 0x03:
   if (((data & 0x03) << 1) != ddribble_vregs[1][3]){
    ddribble_vregs[1][3] = (data & 0x03) << 1;
    tilemap_mark_all_tiles_dirty( bg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_1 = data & 0x02;
   ddribble_vregs[1][4] = data;
   break;
  default:
   ddribble_vregs[1][offset] = data;
 }
}

canonical_original_code:
void K005885_1_w(unsigned int offset, unsigned int data)
{
 switch (offset){
  case 0x03:
   if (((data & 0x03) << 1) != ddribble_vregs[1][3]){
    ddribble_vregs[1][3] = (data & 0x03) << 1;
    tilemap_mark_all_tiles_dirty( bg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_1 = data & 0x02;
   ddribble_vregs[1][4] = data;
   break;
  default:
   ddribble_vregs[1][offset] = data;
 }
}


decompiled_code:
__int64 ddrible_vh_start()
{
__int64 v1; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v1) = 32;
bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan, 0LL, 8LL, 8LL, 64LL, v1);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v1; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v1) = 32;
bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan, 0LL, 8LL, 8LL, 64LL, v1);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

original_code:
int ddrible_vh_start ( void )
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan,0x00, 8,8,64,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int ddrible_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan,0x00, 8,8,64,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}


original_code:
static void ddribble_draw_sprites( struct osd_bitmap *bitmap, unsigned char* source, int lenght, int gfxset, int flipscreen )
{
 struct GfxElement *gfx = Machine->gfx[gfxset];
 const unsigned char *finish = source + lenght;
 while( source < finish )
 {
  int number = source[0] | ((source[1] & 0x07) << 8);
  int attr = source[4];
  int sx = source[3] | ((attr & 0x01) << 8);
  int sy = source[2];
  int flipx = attr & 0x20;
  int flipy = attr & 0x40;
  int color = (source[1] & 0xf0) >> 4;
  int width,height;
  if (flipscreen){
    flipx = !flipx;
    flipy = !flipy;
    sx = 240 - sx;
    sy = 240 - sy;
    if ((attr & 0x1c) == 0x10){
     sx -= 0x10;
     sy -= 0x10;
    }
  }
  switch (attr & 0x1c){
   case 0x10:
    width = height = 2; number &= (~3); break;
   case 0x08:
    width = 1; height = 2; number &= (~2); break;
   case 0x04:
    width = 2; height = 1; number &= (~1); break;
   default:
    width = height = 1; break;
  }
  {
   static int x_offset[2] = { 0x00, 0x01 };
   static int y_offset[2] = { 0x00, 0x02 };
   int x,y, ex, ey;
   for( y=0; y < height; y++ ){
    for( x=0; x < width; x++ ){
     ex = flipx ? (width-1-x) : x;
     ey = flipy ? (height-1-y) : y;
     drawgfx(bitmap,gfx,
      (number)+x_offset[ex]+y_offset[ey],
      color,
      flipx, flipy,
      sx+x*16,sy+y*16,
      &Machine->visible_area,
      TRANSPARENCY_PEN, 0);
    }
   }
  }
  source += 5;
 }
}

canonical_original_code:
static void ddribble_draw_sprites(struct osd_bitmap *bitmap, unsigned char *source, int lenght, int gfxset, int flipscreen)
{
 struct GfxElement *gfx = Machine->gfx[gfxset];
 unsigned char *finish = source + lenght;
 while( source < finish )
 {
  int number = source[0] | ((source[1] & 0x07) << 8);
  int attr = source[4];
  int sx = source[3] | ((attr & 0x01) << 8);
  int sy = source[2];
  int flipx = attr & 0x20;
  int flipy = attr & 0x40;
  int color = (source[1] & 0xf0) >> 4;
  int width; int height;
  if (flipscreen){
    flipx = !flipx;
    flipy = !flipy;
    sx = 240 - sx;
    sy = 240 - sy;
    if ((attr & 0x1c) == 0x10){
     sx -= 0x10;
     sy -= 0x10;
    }
  }
  switch (attr & 0x1c){
   case 0x10:
    width = height = 2; number &= (~3); break;
   case 0x08:
    width = 1; height = 2; number &= (~2); break;
   case 0x04:
    width = 2; height = 1; number &= (~1); break;
   default:
    width = height = 1; break;
  }
  {
   static int x_offset[2] = { 0x00, 0x01 };
   static int y_offset[2] = { 0x00, 0x02 };
   int x; int y; int ex; int ey;
   for( y=0; y < height; y++ ){
    for( x=0; x < width; x++ ){
     ex = flipx ? (width-1-x) : x;
     ey = flipy ? (height-1-y) : y;
     drawgfx(bitmap,gfx,
      (number)+x_offset[ex]+y_offset[ey],
      color,
      flipx, flipy,
      sx+x*16,sy+y*16,
      &Machine->visible_area,
      TRANSPARENCY_PEN, 0);
    }
   }
  }
  source += 5;
 }
}

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

variable_types:
source
unsigned char *

variable_types: lenght int

variable_types: gfxset int

variable_types: flipscreen int

variable_types:
finish
unsigned char *

variable_types: number int

variable_types: color int

variable_types: width int

variable_types: height int

variable_types: x int

variable_types: ex int

variable_types: ey int


decompiled_code:
__int64 __fastcall ddrible_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rsi

v1 = dword_1330 & 8;
if ( (dword_1330 & 8) != 0 )
v1 = 3LL;
tilemap_set_flip(fg_tilemap, v1);
v2 = dword_1344 & 8;
if ( (dword_1344 & 8) != 0 )
v2 = 3LL;
tilemap_set_flip(bg_tilemap, v2);
tilemap_set_scrollx(fg_tilemap, 0LL, dword_1324 | ((_WORD)dword_1328 << 8) & 0x100u);
tilemap_set_scrollx(bg_tilemap, 0LL, dword_1338 | ((_WORD)dword_133C << 8) & 0x100u);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned int)ddribble_vregs[0]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)dword_1334);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
ddribble_draw_sprites(a1, ddrible_spriteram_1, 125, 2, dword_1330 & 8);
ddribble_draw_sprites(a1, ddrible_spriteram_2, 320, 3, dword_1344 & 8);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rsi

v1 = dword_1330 & 8;
if ( (dword_1330 & 8) != 0 )
v1 = 3LL;
tilemap_set_flip(fg_tilemap, v1);
v2 = dword_1344 & 8;
if ( (dword_1344 & 8) != 0 )
v2 = 3LL;
tilemap_set_flip(bg_tilemap, v2);
tilemap_set_scrollx(fg_tilemap, 0LL, dword_1324 | ((_WORD)dword_1328 << 8) & 0x100u);
tilemap_set_scrollx(bg_tilemap, 0LL, dword_1338 | ((_WORD)dword_133C << 8) & 0x100u);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned int)ddribble_vregs[0]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)dword_1334);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func11(a1, ddrible_spriteram_1, 125, 2, dword_1330 & 8);
func11(a1, ddrible_spriteram_2, 320, 3, dword_1344 & 8);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void ddrible_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh )
{
 tilemap_set_flip(fg_tilemap, (ddribble_vregs[0][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_flip(bg_tilemap, (ddribble_vregs[1][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_scrollx(fg_tilemap,0,ddribble_vregs[0][1] | ((ddribble_vregs[0][2] & 0x01) << 8));
 tilemap_set_scrollx(bg_tilemap,0,ddribble_vregs[1][1] | ((ddribble_vregs[1][2] & 0x01) << 8));
 tilemap_set_scrolly(fg_tilemap,0,ddribble_vregs[0][0]);
 tilemap_set_scrolly(bg_tilemap,0,ddribble_vregs[1][0]);
 tilemap_update( 0 );
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 tilemap_draw(bitmap,bg_tilemap,0);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_1,0x07d,2,ddribble_vregs[0][4] & 0x08);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_2,0x140,3,ddribble_vregs[1][4] & 0x08);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void ddrible_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_set_flip(fg_tilemap, (ddribble_vregs[0][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_flip(bg_tilemap, (ddribble_vregs[1][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_scrollx(fg_tilemap,0,ddribble_vregs[0][1] | ((ddribble_vregs[0][2] & 0x01) << 8));
 tilemap_set_scrollx(bg_tilemap,0,ddribble_vregs[1][1] | ((ddribble_vregs[1][2] & 0x01) << 8));
 tilemap_set_scrolly(fg_tilemap,0,ddribble_vregs[0][0]);
 tilemap_set_scrolly(bg_tilemap,0,ddribble_vregs[1][0]);
 tilemap_update( 0 );
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 tilemap_draw(bitmap,bg_tilemap,0);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_1,0x07d,2,ddribble_vregs[0][4] & 0x08);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_2,0x140,3,ddribble_vregs[1][4] & 0x08);
 tilemap_draw(bitmap,fg_tilemap,0);
}


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

result = 2LL;
if ( !ddrible_int_enable_1 )
result = ignore_interrupt();
return result;
}

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

result = 2LL;
if ( !ddrible_int_enable_1 )
result = ignore_interrupt();
return result;
}

original_code:
static int ddrible_interrupt_1( void )
{
 if (ddrible_int_enable_1)
  return 2;
 return ignore_interrupt();
}

canonical_original_code:
static int ddrible_interrupt_1()
{
 if (ddrible_int_enable_1)
  return 2;
 return ignore_interrupt();
}


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

result = 2LL;
if ( !ddrible_int_enable_0 )
result = ignore_interrupt();
return result;
}

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

result = 2LL;
if ( !ddrible_int_enable_0 )
result = ignore_interrupt();
return result;
}

original_code:
static int ddrible_interrupt_0( void )
{
 if (ddrible_int_enable_0)
  return 2;
 return ignore_interrupt();
}

canonical_original_code:
static int ddrible_interrupt_0()
{
 if (ddrible_int_enable_0)
  return 2;
 return ignore_interrupt();
}


canonical_original_code:
static void ddrible_vlm5030_ctrl_w(unsigned int offset, unsigned int data)
{
 unsigned char *SPEECH_ROM = memory_region(REGION_SOUND1);
 VLM5030_RST( data & 0x40 ? 1 : 0 );
 VLM5030_ST( data & 0x20 ? 1 : 0 );
 VLM5030_VCU( data & 0x10 ? 1 : 0 );
 VLM5030_set_rom(&SPEECH_ROM[data & 0x08 ? 0x10000 : 0]);
 set_RC_filter(2,1000,2200,1000,data & 0x04 ? 150000 : 0);
 set_RC_filter(1,1000,2200,1000,data & 0x02 ? 150000 : 0);
 set_RC_filter(0,1000,2200,1000,data & 0x01 ? 150000 : 0);
}

variable_types:
offset
unsigned int


decompiled_code:
int ddrible_vlm5030_busy_r()
{
return rand();
}

canonical_decompiled_code:
int func16()
{
return rand();
}

original_code:
static data_t ddrible_vlm5030_busy_r(offs_t offset)
{
 return rand();
 if (VLM5030_BSY()) return 1;
 else return 0;
}

canonical_original_code:
static unsigned int ddrible_vlm5030_busy_r(unsigned int offset)
{
 return rand();
 if (VLM5030_BSY()) return 1;
 else return 0;
}


decompiled_code:
__int64 __fastcall ddrible_coin_counter_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, (a2 & 2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, (a2 & 2) != 0);
}

original_code:
static void ddrible_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(0,(data) & 0x01);
 coin_counter_w(1,(data >> 1) & 0x01);
}

canonical_original_code:
static void ddrible_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,(data) & 0x01);
 coin_counter_w(1,(data >> 1) & 0x01);
}


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

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

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
_DWORD *ddrible_init_machine()
{
_DWORD *result; // rax

ddrible_int_enable_1 = 0;
result = &ddrible_int_enable_0;
ddrible_int_enable_0 = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func19()
{
_DWORD *result; // rax

ddrible_int_enable_1 = 0;
result = &ddrible_int_enable_0;
ddrible_int_enable_0 = 0;
return result;
}

original_code:
void ddrible_init_machine( void )
{
 ddrible_int_enable_0 = ddrible_int_enable_1 = 0;
}

canonical_original_code:
void ddrible_init_machine()
{
 ddrible_int_enable_0 = ddrible_int_enable_1 = 0;
}


decompiled_code:
void *__fastcall get_fg_tile_info(int a1)
{
unsigned __int8 v1; // al
int v2; // ecx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

v1 = *(_BYTE *)(ddrible_fg_videoram + a1);
v2 = v1;
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(ddrible_fg_videoram + a1 + 1024LL)
+ (((v1 >> 6) + 4 * (dword_132C | ((int)v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v6;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 3;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
unsigned __int8 v1; // al
int v2; // ecx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

v1 = *(_BYTE *)(ddrible_fg_videoram + a1);
v2 = v1;
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(ddrible_fg_videoram + a1 + 1024LL)
+ (((v1 >> 6) + 4 * (dword_132C | ((int)v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v6;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 3;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_fg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[0][3]);
 int num = ddrible_fg_videoram[tile_index + 0x400] + 256*bank;
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_fg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[0][3]);
 int num = ddrible_fg_videoram[tile_index + 0x400] + 256*bank;
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

variable_types:
attr
unsigned char

variable_types: bank int

variable_types: num 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:
void *__fastcall get_bg_tile_info(int a1)
{
unsigned __int8 v1; // al
int v2; // ecx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

v1 = *(_BYTE *)(ddrible_bg_videoram + a1);
v2 = v1;
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(ddrible_bg_videoram + a1 + 1024LL)
+ (((v1 >> 6) + 4 * (dword_1340 | ((int)v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v6;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 3;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(int a1)
{
unsigned __int8 v1; // al
int v2; // ecx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

v1 = *(_BYTE *)(ddrible_bg_videoram + a1);
v2 = v1;
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(ddrible_bg_videoram + a1 + 1024LL)
+ (((v1 >> 6) + 4 * (dword_1340 | ((int)v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v6;
*((_DWORD *)&tile_info + 5) = (v2 >> 4) & 3;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_bg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[1][3]);
 int num = ddrible_bg_videoram[tile_index + 0x400] + 256*bank;
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_bg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[1][3]);
 int num = ddrible_bg_videoram[tile_index + 0x400] + 256*bank;
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}


decompiled_code:
void missile_init_machine()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void missile_init_machine(void)
{
 h_pos = v_pos = 0;
}

canonical_original_code:
void missile_init_machine()
{
 h_pos = v_pos = 0;
}


decompiled_code:
__int64 missile_vh_start()
{
void *v0; // rdi

v0 = malloc(0x10000uLL);
missile_videoram = v0;
if ( !v0 )
return 1LL;
memset(v0, 0, 0x10000uLL);
missile_flipscreen = 64;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
void *v0; // rdi

v0 = malloc(0x10000uLL);
missile_videoram = v0;
if ( !v0 )
return 1LL;
memset(v0, 0, 0x10000uLL);
missile_flipscreen = 64;
return 0LL;
}

original_code:
int missile_vh_start(void)
{
 if ((missile_videoram = (unsigned char*)malloc(256 * 256)) == 0)
  return 1;
 memset (missile_videoram, 0, 256 * 256);
 missile_flipscreen = 0x40;
 return 0;
}

canonical_original_code:
int missile_vh_start()
{
 if ((missile_videoram = (unsigned char *)malloc(256 * 256)) == 0)
  return 1;
 memset (missile_videoram, 0, 256 * 256);
 missile_flipscreen = 0x40;
 return 0;
}


decompiled_code:
void missile_vh_stop()
{
free(missile_videoram);
}

canonical_decompiled_code:
void func2()
{
free(missile_videoram);
}

original_code:
void missile_vh_stop(void)
{
 free(missile_videoram);
}


decompiled_code:
__int64 missile_IN0_r()
{
char v0; // bl
__int64 result; // rax
char v2; // bl

if ( !ctrld )
return readinputport(0LL);
if ( missile_flipscreen )
{
v2 = readinputport(7LL);
result = readinputport(6LL) & 0xF | (unsigned int)(unsigned __int8)(16 * v2);
}
else
{
v0 = readinputport(5LL);
result = readinputport(4LL) & 0xF | (unsigned int)(unsigned __int8)(16 * v0);
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
char v0; // bl
__int64 result; // rax
char v2; // bl

if ( !ctrld )
return readinputport(0LL);
if ( missile_flipscreen )
{
v2 = readinputport(7LL);
result = readinputport(6LL) & 0xF | (unsigned int)(unsigned __int8)(16 * v2);
}
else
{
v0 = readinputport(5LL);
result = readinputport(4LL) & 0xF | (unsigned int)(unsigned __int8)(16 * v0);
}
return result;
}

original_code:
data_t missile_IN0_r(offs_t offset)
{
 if (ctrld)
 {
  if (!missile_flipscreen)
        return ((readinputport(5) << 4) & 0xf0) | (readinputport(4) & 0x0f);
  else
        return ((readinputport(7) << 4) & 0xf0) | (readinputport(6) & 0x0f);
 }
 else
  return (readinputport(0));
}

canonical_original_code:
unsigned int missile_IN0_r(unsigned int offset)
{
 if (ctrld)
 {
  if (!missile_flipscreen)
        return ((readinputport(5) << 4) & 0xf0) | (readinputport(4) & 0x0f);
  else
        return ((readinputport(7) << 4) & 0xf0) | (readinputport(6) & 0x0f);
 }
 else
  return (readinputport(0));
}


decompiled_code:
__int64 __fastcall missile_video_r(int a1)
{
return *(_BYTE *)(missile_videoram + a1) & 0xE0;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return *(_BYTE *)(missile_videoram + a1) & 0xE0;
}

original_code:
int missile_video_r (int address)
{
 return (missile_videoram[address] & 0xe0);
}

canonical_original_code:
int missile_video_r(int address)
{
 return (missile_videoram[address] & 0xe0);
}

variable_types: address int


decompiled_code:
__int64 __fastcall missile_r(int a1)
{
int v1; // ebp
__int64 result; // rax

v1 = a1 + 6400;
if ( *(_BYTE *)(OP_ROM + (int)cpu_get_reg(0xFFFFFFFFLL)) == 0xA1 )
return missile_video_r(v1);
if ( v1 > 20479 )
return *(unsigned __int8 *)(missile_video2ram + v1 - 20480LL);
switch ( a1 )
{
case 12032:
return missile_IN0_r(0LL);
case 12288:
return readinputport(1LL);
case 12544:
return readinputport(2LL);
}
result = 0LL;
if ( (unsigned int)(a1 - 9984) <= 0xF )
result = pokey1_r(a1 & 0xF);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebp
__int64 result; // rax

v1 = a1 + 6400;
if ( *(_BYTE *)(OP_ROM + (int)cpu_get_reg(0xFFFFFFFFLL)) == 0xA1 )
return func4(v1);
if ( v1 > 20479 )
return *(unsigned __int8 *)(missile_video2ram + v1 - 20480LL);
switch ( a1 )
{
case 12032:
return func3(0LL);
case 12288:
return readinputport(1LL);
case 12544:
return readinputport(2LL);
}
result = 0LL;
if ( (unsigned int)(a1 - 9984) <= 0xF )
result = pokey1_r(a1 & 0xF);
return result;
}

original_code:
data_t missile_r(offs_t offset)
{
 int pc, opcode;
 int address = offset + 0x1900;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0xa1)
 {
  return (missile_video_r(address));
 }
 if (address >= 0x5000)
  return missile_video2ram[address - 0x5000];
 if (address == 0x4800)
  return (missile_IN0_r(0));
 if (address == 0x4900)
  return (readinputport (1));
 if (address == 0x4a00)
  return (readinputport (2));
 if ((address >= 0x4000) && (address <= 0x400f))
  return (pokey1_r (address & 0x0f));
 return 0;
}

canonical_original_code:
unsigned int missile_r(unsigned int offset)
{
 int pc; int opcode;
 int address = offset + 0x1900;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0xa1)
 {
  return (missile_video_r(address));
 }
 if (address >= 0x5000)
  return missile_video2ram[address - 0x5000];
 if (address == 0x4800)
  return (missile_IN0_r(0));
 if (address == 0x4900)
  return (readinputport (1));
 if (address == 0x4a00)
  return (readinputport (2));
 if ((address >= 0x4000) && (address <= 0x400f))
  return (pokey1_r (address & 0x0f));
 return 0;
}

variable_types: pc int

variable_types: opcode int


decompiled_code:
void missile_flip_screen()
{
screen_flipped = 1;
}

canonical_decompiled_code:
void func6()
{
screen_flipped = 1;
}

original_code:
void missile_flip_screen (void)
{
 screen_flipped = 1;
}


decompiled_code:
__int64 __fastcall missile_blit_w(int a1)
{
unsigned int v1; // esi
unsigned __int8 v2; // al

v1 = (a1 >> 8) - 25;
if ( missile_flipscreen )
v1 = *(_DWORD *)(*(_QWORD *)(Machine + 768LL) + 4LL) + ~v1;
v2 = *(_BYTE *)(missile_videoram + a1) >> 5;
if ( (a1 >> 8) - 25 < 199 )
v2 &= 6u;
return plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned __int8)a1,
v1,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v2));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // esi
unsigned __int8 v2; // al

v1 = (a1 >> 8) - 25;
if ( missile_flipscreen )
v1 = *(_DWORD *)(*(_QWORD *)(Machine + 768LL) + 4LL) + ~v1;
v2 = *(_BYTE *)(missile_videoram + a1) >> 5;
if ( (a1 >> 8) - 25 < 199 )
v2 &= 6u;
return plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned __int8)a1,
v1,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v2));
}

original_code:
void missile_blit_w (int offset)
{
 int x, y;
 int bottom;
 int color;
 y = (offset >> 8) - 25;
 x = offset & 0xff;
 if( y < 231 - 32)
  bottom = 1;
 else
  bottom = 0;
 if (missile_flipscreen)
 {
  y = Machine->scrbitmap->height - 1 - y;
 }
 color = (missile_videoram[offset] >> 5);
 if (bottom) color &= 0x06;
 plot_pixel(Machine->scrbitmap, x, y, Machine->pens[color]);
}

canonical_original_code:
void missile_blit_w(int offset)
{
 int x; int y;
 int bottom;
 int color;
 y = (offset >> 8) - 25;
 x = offset & 0xff;
 if( y < 231 - 32)
  bottom = 1;
 else
  bottom = 0;
 if (missile_flipscreen)
 {
  y = Machine->scrbitmap->height - 1 - y;
 }
 color = (missile_videoram[offset] >> 5);
 if (bottom) color &= 0x06;
 plot_pixel(Machine->scrbitmap, x, y, Machine->pens[color]);
}

variable_types: offset int

variable_types: y int

variable_types: bottom int


decompiled_code:
__int64 __fastcall missile_video_3rd_bit_w(int a1, int a2)
{
int v2; // ebp
int i; // ebx
__int64 result; // rax

*(_BYTE *)(memory_region(129LL) + a1 + 1024) = a2;
v2 = 4 * a1 + 63484;
for ( i = 0; i != 8; ++i )
{
if ( (a2 & (1 << i)) != 0 )
*(_BYTE *)(missile_videoram + v2) |= 0x20u;
else
*(_BYTE *)(missile_videoram + v2) &= 0xC0u;
result = missile_blit_w(v2++);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
int v2; // ebp
int i; // ebx
__int64 result; // rax

*(_BYTE *)(memory_region(129LL) + a1 + 1024) = a2;
v2 = 4 * a1 + 63484;
for ( i = 0; i != 8; ++i )
{
if ( (a2 & (1 << i)) != 0 )
*(_BYTE *)(missile_videoram + v2) |= 0x20u;
else
*(_BYTE *)(missile_videoram + v2) &= 0xC0u;
result = func7(v2++);
}
return result;
}

original_code:
void missile_video_3rd_bit_w(offs_t offset,data_t data)
{
 int i;
 unsigned char *RAM = memory_region(REGION_CPU1);
 int address = offset + 0x400;
 RAM[address] = data;
 address = ((address - 0x401) << 2) + 0xf800;
 for (i=0; i<8; i++)
 {
  if (data & (1 << i))
   missile_videoram[address + i] |= 0x20;
  else
   missile_videoram[address + i] &= 0xc0;
  missile_blit_w (address + i);
 }
}

canonical_original_code:
void missile_video_3rd_bit_w(unsigned int offset, unsigned int data)
{
 int i;
 unsigned char *RAM = memory_region(REGION_CPU1);
 int address = offset + 0x400;
 RAM[address] = data;
 address = ((address - 0x401) << 2) + 0xf800;
 for (i=0; i<8; i++)
 {
  if (data & (1 << i))
   missile_videoram[address + i] |= 0x20;
  else
   missile_videoram[address + i] &= 0xc0;
  missile_blit_w (address + i);
 }
}

variable_types:
data
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall missile_vh_screenrefresh(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ebx

result = palette_recalc();
v3 = 6400;
if ( result || screen_flipped | a2 )
{
do
result = missile_blit_w(v3++);
while ( v3 != 0x10000 );
screen_flipped = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // ebx

result = palette_recalc();
v3 = 6400;
if ( result || screen_flipped | a2 )
{
do
result = func7(v3++);
while ( v3 != 0x10000 );
screen_flipped = 0;
}
return result;
}

original_code:
void missile_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int address;
 if (palette_recalc() || full_refresh || screen_flipped)
 {
  for (address = 0x1900; address <= 0xffff; address++)
   missile_blit_w (address);
  screen_flipped = 0;
 }
}

canonical_original_code:
void missile_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int address;
 if (palette_recalc() || full_refresh || screen_flipped)
 {
  for (address = 0x1900; address <= 0xffff; address++)
   missile_blit_w (address);
  screen_flipped = 0;
 }
}

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


decompiled_code:
__int64 __fastcall missile_video_mult_w(int a1, char a2)
{
char v2; // si
int v3; // ebx

v2 = (8 * a2) & 0x40 | a2 & 0x80;
v3 = 4 * a1;
if ( 4 * a1 > 63487 )
v2 |= 0x20u;
*(_BYTE *)(missile_videoram + v3) = v2;
*(_BYTE *)(missile_videoram + v3 + 1LL) = v2;
*(_BYTE *)(missile_videoram + v3 + 2LL) = v2;
*(_BYTE *)(missile_videoram + v3 + 3LL) = v2;
missile_blit_w(v3);
missile_blit_w(v3 + 1);
missile_blit_w(v3 + 2);
return missile_blit_w(v3 + 3);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, char a2)
{
char v2; // si
int v3; // ebx

v2 = (8 * a2) & 0x40 | a2 & 0x80;
v3 = 4 * a1;
if ( 4 * a1 > 63487 )
v2 |= 0x20u;
*(_BYTE *)(missile_videoram + v3) = v2;
*(_BYTE *)(missile_videoram + v3 + 1LL) = v2;
*(_BYTE *)(missile_videoram + v3 + 2LL) = v2;
*(_BYTE *)(missile_videoram + v3 + 3LL) = v2;
func7(v3);
func7(v3 + 1);
func7(v3 + 2);
return func7(v3 + 3);
}

original_code:
void missile_video_mult_w (int address, int data)
{
 data = (data & 0x80) + ((data & 8) << 3);
 address = address << 2;
 if (address >= 0xf800) data |= 0x20;
 missile_videoram[address] = data;
 missile_videoram[address + 1] = data;
 missile_videoram[address + 2] = data;
 missile_videoram[address + 3] = data;
 missile_blit_w (address);
 missile_blit_w (address + 1);
 missile_blit_w (address + 2);
 missile_blit_w (address + 3);
}

canonical_original_code:
void missile_video_mult_w(int address, int data)
{
 data = (data & 0x80) + ((data & 8) << 3);
 address = address << 2;
 if (address >= 0xf800) data |= 0x20;
 missile_videoram[address] = data;
 missile_videoram[address + 1] = data;
 missile_videoram[address + 2] = data;
 missile_videoram[address + 3] = data;
 missile_blit_w (address);
 missile_blit_w (address + 1);
 missile_blit_w (address + 2);
 missile_blit_w (address + 3);
}

variable_types: data int


decompiled_code:
__int64 __fastcall missile_w(int a1, unsigned int a2)
{
int v2; // er12
__int64 result; // rax
__int64 v4; // rdi

v2 = a1 + 1600;
result = (int)cpu_get_reg(0xFFFFFFFFLL);
if ( *(_BYTE *)(OP_ROM + (int)result) == 0x81 )
return missile_video_w(v2, a2);
if ( v2 <= 0x3FFF )
return missile_video_mult_w(v2, a2);
if ( a1 == 17856 )
return watchdog_reset_w(19456LL, a2);
if ( a1 == 16832 )
{
if ( (((unsigned __int8)(a2 >> 6) ^ 1) & 1) != missile_flipscreen )
missile_flip_screen();
missile_flipscreen = ((unsigned __int8)(a2 >> 6) ^ 1) & 1;
coin_counter_w(0LL, a2 & 0x20);
coin_counter_w(1LL, a2 & 0x10);
coin_counter_w(2LL, a2 & 8);
osd_led_w(0LL, ~a2 >> 1);
result = osd_led_w(1LL, ~a2 >> 2);
ctrld = a2 & 1;
}
else if ( a1 != 18112 )
{
result = (unsigned int)(a1 - 14784);
if ( (unsigned int)result <= 0xF )
{
result = pokey1_w((unsigned int)v2, a2);
}
else
{
v4 = (unsigned int)(a1 - 17600);
if ( (unsigned int)v4 <= 7 )
result = palette_change_color(v4, 255 * ((~a2 >> 3) & 1), 255 * ((~a2 >> 2) & 1), 255 * ((~a2 >> 1) & 1));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, unsigned int a2)
{
int v2; // er12
__int64 result; // rax
__int64 v4; // rdi

v2 = a1 + 1600;
result = (int)cpu_get_reg(0xFFFFFFFFLL);
if ( *(_BYTE *)(OP_ROM + (int)result) == 0x81 )
return func10(v2, a2);
if ( v2 <= 0x3FFF )
return func12(v2, a2);
if ( a1 == 17856 )
return watchdog_reset_w(19456LL, a2);
if ( a1 == 16832 )
{
if ( (((unsigned __int8)(a2 >> 6) ^ 1) & 1) != missile_flipscreen )
func6();
missile_flipscreen = ((unsigned __int8)(a2 >> 6) ^ 1) & 1;
coin_counter_w(0LL, a2 & 0x20);
coin_counter_w(1LL, a2 & 0x10);
coin_counter_w(2LL, a2 & 8);
osd_led_w(0LL, ~a2 >> 1);
result = osd_led_w(1LL, ~a2 >> 2);
ctrld = a2 & 1;
}
else if ( a1 != 18112 )
{
result = (unsigned int)(a1 - 14784);
if ( (unsigned int)result <= 0xF )
{
result = pokey1_w((unsigned int)v2, a2);
}
else
{
v4 = (unsigned int)(a1 - 17600);
if ( (unsigned int)v4 <= 7 )
result = palette_change_color(v4, 255 * ((~a2 >> 3) & 1), 255 * ((~a2 >> 2) & 1), 255 * ((~a2 >> 1) & 1));
}
}
return result;
}

original_code:
void missile_w(offs_t offset,data_t data)
{
 int pc, opcode;
 int address = offset + 0x640;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0x81)
 {
  missile_video_w (address, data);
  return;
 }
 if (address <= 0x3fff)
 {
  missile_video_mult_w (address, data);
  return;
 }
 if (address == 0x4c00)
 {
  watchdog_reset_w (address, data);
  return;
 }
 if (address == 0x4800)
 {
  if (missile_flipscreen != (!(data & 0x40)))
   missile_flip_screen ();
  missile_flipscreen = !(data & 0x40);
  coin_counter_w (0, data & 0x20);
  coin_counter_w (1, data & 0x10);
  coin_counter_w (2, data & 0x08);
  osd_led_w (0, ~data >> 1);
  osd_led_w (1, ~data >> 2);
  ctrld = data & 1;
  return;
 }
 if (address == 0x4d00)
 {
  return;
 }
 if (address >= 0x4000 && address <= 0x400f)
 {
  pokey1_w (address, data);
  return;
 }
 if (address >= 0x4b00 && address <= 0x4b07)
 {
  int r,g,b;
  r = 0xff * ((~data >> 3) & 1);
  g = 0xff * ((~data >> 2) & 1);
  b = 0xff * ((~data >> 1) & 1);
  palette_change_color(address - 0x4b00,r,g,b);
  return;
 }
}

canonical_original_code:
void missile_w(unsigned int offset, unsigned int data)
{
 int pc; int opcode;
 int address = offset + 0x640;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0x81)
 {
  missile_video_w (address, data);
  return;
 }
 if (address <= 0x3fff)
 {
  missile_video_mult_w (address, data);
  return;
 }
 if (address == 0x4c00)
 {
  watchdog_reset_w (address, data);
  return;
 }
 if (address == 0x4800)
 {
  if (missile_flipscreen != (!(data & 0x40)))
   missile_flip_screen ();
  missile_flipscreen = !(data & 0x40);
  coin_counter_w (0, data & 0x20);
  coin_counter_w (1, data & 0x10);
  coin_counter_w (2, data & 0x08);
  osd_led_w (0, ~data >> 1);
  osd_led_w (1, ~data >> 2);
  ctrld = data & 1;
  return;
 }
 if (address == 0x4d00)
 {
  return;
 }
 if (address >= 0x4000 && address <= 0x400f)
 {
  pokey1_w (address, data);
  return;
 }
 if (address >= 0x4b00 && address <= 0x4b07)
 {
  int r; int g; int b;
  r = 0xff * ((~data >> 3) & 1);
  g = 0xff * ((~data >> 2) & 1);
  b = 0xff * ((~data >> 1) & 1);
  palette_change_color(address - 0x4b00,r,g,b);
  return;
 }
}

variable_types:
offset
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall get_tile_info_screen0(int a1)
{
__int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = HIBYTE(*(_WORD *)(splash_videoram + 2 * a1));
v2 = *(_QWORD *)(Machine + 512LL);
v3 = ((unsigned __int8)*(_WORD *)(splash_videoram + 2 * a1)
+ (((HIBYTE(*(_WORD *)(splash_videoram + 2 * a1)) & 0xFu) + 32) << 8))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * ((unsigned __int8)v1 >> 4);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = HIBYTE(*(_WORD *)(splash_videoram + 2 * a1));
v2 = *(_QWORD *)(Machine + 512LL);
v3 = ((unsigned __int8)*(_WORD *)(splash_videoram + 2 * a1)
+ (((HIBYTE(*(_WORD *)(splash_videoram + 2 * a1)) & 0xFu) + 32) << 8))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * ((unsigned __int8)v1 >> 4);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info_screen0(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code + ((0x20 + (attr & 0x0f)) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info_screen0(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code + ((0x20 + (attr & 0x0f)) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types:
data
unsigned short

variable_types:
attr
unsigned char

variable_types:
code
unsigned char


decompiled_code:
__int64 __fastcall get_tile_info_screen1(int a1)
{
unsigned __int16 v1; // dx
__int16 v2; // cx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = *(_WORD *)(splash_videoram + 2 * a1 + 4096LL);
v2 = HIBYTE(v1);
*((_DWORD *)&tile_info + 5) = ((int)(unsigned __int8)v1 >> 1) & 1 | (2 * (_BYTE)v1) & 2;
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (((unsigned __int8)v1 >> 2) + (((HIBYTE(v1) & 0xFu) + 48) << 6)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * ((unsigned __int8)v2 >> 4);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned __int16 v1; // dx
__int16 v2; // cx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = *(_WORD *)(splash_videoram + 2 * a1 + 4096LL);
v2 = HIBYTE(v1);
*((_DWORD *)&tile_info + 5) = ((int)(unsigned __int8)v1 >> 1) & 1 | (2 * (_BYTE)v1) & 2;
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (((unsigned __int8)v1 >> 2) + (((HIBYTE(v1) & 0xFu) + 48) << 6)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * ((unsigned __int8)v2 >> 4);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info_screen1(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index+0x1000]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 tile_info.flags = ((((code & 0x03)>>1)|((code & 0x03)<<1))&3);
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((code >> 2) + ((0x30 + (attr & 0x0f)) << 6)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info_screen1(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index+0x1000]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 tile_info.flags = ((((code & 0x03)>>1)|((code & 0x03)<<1))&3);
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((code >> 2) + ((0x30 + (attr & 0x0f)) << 6)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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 splash_vram_r(unsigned int a1)
{
return *(unsigned __int16 *)(splash_videoram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return *(unsigned __int16 *)(splash_videoram + a1);
}

original_code:
data_t splash_vram_r(offs_t offset)
{
 return (*(UINT16 *)(&splash_videoram[offset]));
}

canonical_original_code:
unsigned int splash_vram_r(unsigned int offset)
{
 return (*(unsigned short *)(&splash_videoram[offset]));
}


decompiled_code:
__int64 __fastcall splash_pixelram_r(unsigned int a1)
{
return *(unsigned __int16 *)(splash_pixelram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return *(unsigned __int16 *)(splash_pixelram + a1);
}

original_code:
data_t splash_pixelram_r(offs_t offset)
{
 return (*(UINT16 *)(&splash_pixelram[offset]));
}

canonical_original_code:
unsigned int splash_pixelram_r(unsigned int offset)
{
 return (*(unsigned short *)(&splash_pixelram[offset]));
}


decompiled_code:
__int64 __fastcall splash_pixelram_w(unsigned int a1, int a2)
{
*(_WORD *)(splash_pixelram + a1) = a2 | *(_WORD *)(splash_pixelram + a1) & HIWORD(a2);
return plot_pixel(
screen2,
((a1 >> 1) & 0x1FF) - 9,
a1 >> 10,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *(unsigned __int8 *)(splash_pixelram + a1) + 1536));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2)
{
*(_WORD *)(splash_pixelram + a1) = a2 | *(_WORD *)(splash_pixelram + a1) & HIWORD(a2);
return plot_pixel(
screen2,
((a1 >> 1) & 0x1FF) - 9,
a1 >> 10,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *(unsigned __int8 *)(splash_pixelram + a1) + 1536));
}

original_code:
void splash_pixelram_w(offs_t offset,data_t data)
{
 int sx,sy,color;
 ((*(UINT16 *)((&splash_pixelram[offset])) = (((*(UINT16 *)(&splash_pixelram[offset])) & ((data) >> 16)) | (data))));
 sx = (offset >> 1) & 0x1ff;
 sy = (offset >> 10);
 color = (*(UINT16 *)(&splash_pixelram[offset]));
 plot_pixel(screen2, sx-9, sy, Machine->pens[0x300 + (color & 0xff)]);
}

canonical_original_code:
void splash_pixelram_w(unsigned int offset, unsigned int data)
{
 int sx; int sy; int color;
 ((*(unsigned short *)((&splash_pixelram[offset])) = (((*(unsigned short *)(&splash_pixelram[offset])) & ((data) >> 16)) | (data))));
 sx = (offset >> 1) & 0x1ff;
 sy = (offset >> 10);
 color = (*(unsigned short *)(&splash_pixelram[offset]));
 plot_pixel(screen2, sx-9, sy, Machine->pens[0x300 + (color & 0xff)]);
}

variable_types: sx int

variable_types: sy int

variable_types: color int


decompiled_code:
void __fastcall splash_adpcm_data_w(__int64 a1, int a2)
{
adpcm_data = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
adpcm_data = a2;
}

original_code:
static void splash_adpcm_data_w(offs_t offset,data_t data){
 adpcm_data = data;
}

canonical_original_code:
static void splash_adpcm_data_w(unsigned int offset, unsigned int data){
 adpcm_data = data;
}