decompiled_code:
unsigned __int64 __fastcall C140_w(__int16 a1, unsigned int a2)
{
unsigned __int64 result; // rax
__int64 v3; // rax
unsigned __int8 *v4; // rbx
int v5; // ecx
int v6; // edx
int v7; // edx
int v8; // ecx
int v9; // edx
int v10; // edx
int v11; // ecx

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
result = a1 & 0x1FF;
REG[result] = a2;
if ( (unsigned int)result <= 0x17F && (a1 & 0xF) == 5 )
{
v3 = (unsigned int)result >> 4;
if ( (a2 & 0x80u) == 0 )
{
result = (unsigned __int64)&voi + 112 * v3;
*(_QWORD *)(result + 16) = 0LL;
}
else
{
v4 = &REG[a1 & 0x1F0];
v5 = v4[11];
result = (unsigned __int64)&voi + 112 * v3;
*(_QWORD *)(result + 72) = v4[4];
v6 = v4[10];
*(_QWORD *)(result + 16) = 1LL;
*(_QWORD *)result = 0LL;
v7 = v5 + (v6 << 8);
v8 = v4[7];
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
*(_QWORD *)(result + 104) = v7;
v9 = v4[6];
*(_QWORD *)(result + 32) = 0LL;
*(_QWORD *)(result + 40) = 0LL;
v10 = v8 + (v9 << 8);
v11 = v4[9];
*(_QWORD *)(result + 80) = a2;
*(_QWORD *)(result + 88) = v10;
*(_QWORD *)(result + 96) = v11 + (v4[8] << 8);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int16 a1, unsigned int a2)
{
unsigned __int64 result; // rax
__int64 v3; // rax
unsigned __int8 *v4; // rbx
int v5; // ecx
int v6; // edx
int v7; // edx
int v8; // ecx
int v9; // edx
int v10; // edx
int v11; // ecx

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
result = a1 & 0x1FF;
REG[result] = a2;
if ( (unsigned int)result <= 0x17F && (a1 & 0xF) == 5 )
{
v3 = (unsigned int)result >> 4;
if ( (a2 & 0x80u) == 0 )
{
result = (unsigned __int64)&voi + 112 * v3;
*(_QWORD *)(result + 16) = 0LL;
}
else
{
v4 = &REG[a1 & 0x1F0];
v5 = v4[11];
result = (unsigned __int64)&voi + 112 * v3;
*(_QWORD *)(result + 72) = v4[4];
v6 = v4[10];
*(_QWORD *)(result + 16) = 1LL;
*(_QWORD *)result = 0LL;
v7 = v5 + (v6 << 8);
v8 = v4[7];
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
*(_QWORD *)(result + 104) = v7;
v9 = v4[6];
*(_QWORD *)(result + 32) = 0LL;
*(_QWORD *)(result + 40) = 0LL;
v10 = v8 + (v9 << 8);
v11 = v4[9];
*(_QWORD *)(result + 80) = a2;
*(_QWORD *)(result + 88) = v10;
*(_QWORD *)(result + 96) = v11 + (v4[8] << 8);
}
}
return result;
}

original_code:
void C140_w(offs_t offset,data_t data)
{
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream, 0);
    }
 offset&=0x1ff;
 REG[offset]=data;
 if( offset<0x180 )
 {
  VOICE *v = &voi[offset>>4];
  if( (offset&0xf)==0x5 )
  {
   if( data&0x80 )
   {
    const struct voice_registers *vreg = (struct voice_registers *) &REG[offset&0x1f0];
    v->key=1;
    v->ptoffset=0;
    v->pos=0;
    v->lastdt=0;
    v->prevdt=0;
    v->dltdt=0;
    v->bank = vreg->bank;
    v->mode = data;
    v->sample_loop = vreg->loop_msb*256 + vreg->loop_lsb;
    v->sample_start = vreg->start_msb*256 + vreg->start_lsb;
    v->sample_end = vreg->end_msb*256 + vreg->end_lsb;
   }
   else
   {
    v->key=0;
   }
  }
 }
}

canonical_original_code:
void C140_w(unsigned int offset, unsigned int data)
{
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream, 0);
    }
 offset&=0x1ff;
 REG[offset]=data;
 if( offset<0x180 )
 {
  struct VOICE *v = &voi[offset>>4];
  if( (offset&0xf)==0x5 )
  {
   if( data&0x80 )
   {
    struct voice_registers *vreg = (struct voice_registers *) &REG[offset&0x1f0];
    v->key=1;
    v->ptoffset=0;
    v->pos=0;
    v->lastdt=0;
    v->prevdt=0;
    v->dltdt=0;
    v->bank = vreg->bank;
    v->mode = data;
    v->sample_loop = vreg->loop_msb*256 + vreg->loop_lsb;
    v->sample_start = vreg->start_msb*256 + vreg->start_lsb;
    v->sample_end = vreg->end_msb*256 + vreg->end_lsb;
   }
   else
   {
    v->key=0;
   }
  }
 }
}

variable_types: struct VOICE { long ptoffset; long pos; long key; long lastdt; long prevdt; long dltdt; long rvol; long lvol; long frequency; long bank; long mode; long sample_start; long sample_end; long sample_loop; } *

variable_types: struct voice_registers { unsigned char volume_right; unsigned char volume_left; unsigned char frequency_msb; unsigned char frequency_lsb; unsigned char bank; unsigned char mode; unsigned char start_msb; unsigned char start_lsb; unsigned char end_msb; unsigned char end_lsb; unsigned char loop_msb; unsigned char loop_lsb; unsigned char reserved[4]; } *


decompiled_code:
__int64 __fastcall C140_sh_start(__int64 a1)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 v3; // rcx
int v4; // edx
int v5; // eax
__int64 v6; // rdi
__int64 v7; // rax
__int64 v8; // rcx
int v9; // eax
int v10; // edx
_QWORD *v11; // rax
_QWORD *v12; // rdx
__int64 v13; // rbx
char *v14; // rax
int v16[2]; // [rsp+8h] [rbp-20h] BYREF
__int64 v17[3]; // [rsp+10h] [rbp-18h] BYREF

v1 = *(unsigned int **)(a1 + 8);
v17[0] = (__int64)"C140 Left";
v17[1] = (__int64)"C140 Right";
v2 = *((unsigned __int8 *)v1 + 8);
v3 = *v1;
v4 = v2;
BYTE1(v2) = 2;
BYTE1(v4) = 1;
baserate = v3;
v16[0] = v4;
sample_rate = v3;
v16[1] = v2;
v5 = stream_init_multi(2LL, v17, v16, v3, 0LL, update_stereo);
v6 = v1[1];
stream = v5;
v7 = memory_region(v6);
v8 = 0LL;
pRom = v7;
v9 = 0;
do
{
pcmtbl[v8] = v9;
v10 = 16 << v8++;
v9 += v10;
}
while ( v8 != 8 );
memset(REG, 0, sizeof(REG));
v11 = &voi;
do
init_voice(v11);
while ( v12 != v11 );
v13 = sample_rate;
v14 = (char *)malloc(4LL * sample_rate);
mixer_buffer_left = v14;
if ( !v14 )
return 1LL;
mixer_buffer_right = &v14[2 * v13];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int *v1; // rbx
int v2; // eax
__int64 v3; // rcx
int v4; // edx
int v5; // eax
__int64 v6; // rdi
__int64 v7; // rax
__int64 v8; // rcx
int v9; // eax
int v10; // edx
_QWORD *v11; // rax
_QWORD *v12; // rdx
__int64 v13; // rbx
char *v14; // rax
int v16[2]; // [rsp+8h] [rbp-20h] BYREF
__int64 v17[3]; // [rsp+10h] [rbp-18h] BYREF

v1 = *(unsigned int **)(a1 + 8);
v17[0] = (__int64)"C140 Left";
v17[1] = (__int64)"C140 Right";
v2 = *((unsigned __int8 *)v1 + 8);
v3 = *v1;
v4 = v2;
BYTE1(v2) = 2;
BYTE1(v4) = 1;
baserate = v3;
v16[0] = v4;
sample_rate = v3;
v16[1] = v2;
v5 = stream_init_multi(2LL, v17, v16, v3, 0LL, update_stereo);
v6 = v1[1];
stream = v5;
v7 = memory_region(v6);
v8 = 0LL;
pRom = v7;
v9 = 0;
do
{
pcmtbl[v8] = v9;
v10 = 16 << v8++;
v9 += v10;
}
while ( v8 != 8 );
memset(REG, 0, sizeof(REG));
v11 = &voi;
do
func1(v11);
while ( v12 != v11 );
v13 = sample_rate;
v14 = (char *)malloc(4LL * sample_rate);
mixer_buffer_left = v14;
if ( !v14 )
return 1LL;
mixer_buffer_right = &v14[2 * v13];
return 0LL;
}

original_code:
int C140_sh_start( const struct MachineSound *msound )
{
 const struct C140interface *intf = (const struct C140interface *)msound->sound_interface;
 int vol[2];
 const char *stereo_names[2] = { "C140 Left", "C140 Right" };
 vol[0] = ((intf->mixing_level & 0xff) | ((1 & 0x03) << 8));
 vol[1] = ((intf->mixing_level & 0xff) | ((2 & 0x03) << 8));
 sample_rate=baserate=intf->frequency;
 stream = stream_init_multi(2,stereo_names,vol,sample_rate,0,update_stereo);
 pRom=memory_region(intf->region);
 {
  int i;
  INT32 segbase=0;
  for(i=0;i<8;i++)
  {
   pcmtbl[i]=segbase;
   segbase += 16<<i;
  }
 }
 memset(REG,0,0x200 );
 {
  int i;
  for(i=0;i<24;i++) init_voice( &voi[i] );
 }
 mixer_buffer_left = (INT16*)malloc(2 * sizeof(INT16)*sample_rate );
 if( mixer_buffer_left )
 {
  mixer_buffer_right = mixer_buffer_left + sample_rate;
  return 0;
 }
 return 1;
}

canonical_original_code:
int C140_sh_start(struct MachineSound *msound)
{
 struct C140interface *intf = (const struct C140interface *)msound->sound_interface;
 int vol[2];
 char *stereo_names[2] = { "C140 Left", "C140 Right" };
 vol[0] = ((intf->mixing_level & 0xff) | ((1 & 0x03) << 8));
 vol[1] = ((intf->mixing_level & 0xff) | ((2 & 0x03) << 8));
 sample_rate=baserate=intf->frequency;
 stream = stream_init_multi(2,stereo_names,vol,sample_rate,0,update_stereo);
 pRom=memory_region(intf->region);
 {
  int i;
  int segbase = 0;
  for(i=0;i<8;i++)
  {
   pcmtbl[i]=segbase;
   segbase += 16<<i;
  }
 }
 memset(REG,0,0x200 );
 {
  int i;
  for(i=0;i<24;i++) init_voice( &voi[i] );
 }
 mixer_buffer_left = (short *)malloc(2 * sizeof(INT16)*sample_rate );
 if( mixer_buffer_left )
 {
  mixer_buffer_right = mixer_buffer_left + sample_rate;
  return 0;
 }
 return 1;
}

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

variable_types: struct C140interface { int frequency; int region; int mixing_level; } *

variable_types:
vol
int [2]

variable_types: i int

variable_types: segbase int

return_type: int


decompiled_code:
void C140_sh_stop()
{
free(mixer_buffer_left);
}

canonical_decompiled_code:
void func7()
{
free(mixer_buffer_left);
}

original_code:
void C140_sh_stop( void )
{
 free( mixer_buffer_left );
}

canonical_original_code:
void C140_sh_stop()
{
 free( mixer_buffer_left );
}

return_type: void


original_code:
static long find_sample( long adrs, long bank)
{
 adrs=(bank<<16)+adrs;
 return ((adrs&0x200000)>>2)|(adrs&0x7ffff);
}

canonical_original_code:
static long find_sample(long adrs, long bank)
{
 adrs=(bank<<16)+adrs;
 return ((adrs&0x200000)>>2)|(adrs&0x7ffff);
}

variable_types: adrs long

variable_types: bank long

return_type: long


decompiled_code:
void arkanoid_init_machine()
{
m68705write = 0;
z80write = 0;
portA_out = 0;
portA_in = 0;
}

canonical_decompiled_code:
void func0()
{
m68705write = 0;
z80write = 0;
portA_out = 0;
portA_in = 0;
}

original_code:
void arkanoid_init_machine(void)
{
 portA_in = portA_out = z80write = m68705write = 0;
}

canonical_original_code:
void arkanoid_init_machine()
{
 portA_in = portA_out = z80write = m68705write = 0;
}


decompiled_code:
__int64 arkanoid_Z80_mcu_r()
{
m68705write = 0;
return (unsigned int)toz80;
}

canonical_decompiled_code:
__int64 func1()
{
m68705write = 0;
return (unsigned int)toz80;
}

original_code:
data_t arkanoid_Z80_mcu_r(offs_t offset)
{
 m68705write = 0;
 return toz80;
}

canonical_original_code:
unsigned int arkanoid_Z80_mcu_r(unsigned int offset)
{
 m68705write = 0;
 return toz80;
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 arkanoid_68705_portA_r()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

canonical_decompiled_code:
__int64 func2()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

original_code:
data_t arkanoid_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

canonical_original_code:
unsigned int arkanoid_68705_portA_r(unsigned int offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}


decompiled_code:
void __fastcall arkanoid_68705_portA_w(__int64 a1, char a2)
{
portA_out = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, char a2)
{
portA_out = a2;
}

original_code:
void arkanoid_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

canonical_original_code:
void arkanoid_68705_portA_w(unsigned int offset, unsigned int data)
{
 portA_out = data;
}

variable_types:
data
unsigned int


decompiled_code:
void __fastcall arkanoid_68705_ddrA_w(__int64 a1, char a2)
{
ddrA = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, char a2)
{
ddrA = a2;
}

original_code:
void arkanoid_68705_ddrA_w(offs_t offset,data_t data)
{
 ddrA = data;
}

canonical_original_code:
void arkanoid_68705_ddrA_w(unsigned int offset, unsigned int data)
{
 ddrA = data;
}


decompiled_code:
__int64 arkanoid_68705_portC_r()
{
int v0; // ecx

v0 = z80write != 0;
if ( !m68705write )
v0 |= 2u;
return (unsigned __int8)(ddrC & portC_out) | v0 & ~(unsigned __int8)ddrC;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ecx

v0 = z80write != 0;
if ( !m68705write )
v0 |= 2u;
return (unsigned __int8)(ddrC & portC_out) | v0 & ~(unsigned __int8)ddrC;
}

original_code:
data_t arkanoid_68705_portC_r(offs_t offset)
{
 int res=0;
 if (z80write) res |= 0x01;
 if (!m68705write) res |= 0x02;
 return (portC_out & ddrC) | (res & ~ddrC);
}

canonical_original_code:
unsigned int arkanoid_68705_portC_r(unsigned int offset)
{
 int res = 0;
 if (z80write) res |= 0x01;
 if (!m68705write) res |= 0x02;
 return (portC_out & ddrC) | (res & ~ddrC);
}

variable_types: res int


decompiled_code:
void __fastcall arkanoid_68705_ddrC_w(__int64 a1, char a2)
{
ddrC = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char a2)
{
ddrC = a2;
}

original_code:
void arkanoid_68705_ddrC_w(offs_t offset,data_t data)
{
 ddrC = data;
}

canonical_original_code:
void arkanoid_68705_ddrC_w(unsigned int offset, unsigned int data)
{
 ddrC = data;
}


original_code:
void arkanoid_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void arkanoid_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 __fastcall arkanoid_Z80_mcu_w(__int64 a1, int a2)
{
fromz80 = a2;
z80write = 1;
return cpu_spinuntil_trigger(700LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
fromz80 = a2;
z80write = 1;
return cpu_spinuntil_trigger(700LL);
}

original_code:
void arkanoid_Z80_mcu_w(offs_t offset,data_t data)
{
 z80write = 1;
 fromz80 = data;
 cpu_spinuntil_trigger(700);
}

canonical_original_code:
void arkanoid_Z80_mcu_w(unsigned int offset, unsigned int data)
{
 z80write = 1;
 fromz80 = data;
 cpu_spinuntil_trigger(700);
}


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

result = (unsigned __int8)ddrC;
if ( (ddrC & 4) != 0 && (a2 & 4) == 0 && (portC_out & 4) != 0 )
{
cpu_trigger(700LL);
z80write = 0;
portA_in = fromz80;
result = (unsigned __int8)ddrC;
}
if ( (result & 8) != 0 && (a2 & 8) == 0 && (portC_out & 8) != 0 )
{
result = (unsigned __int8)portA_out;
m68705write = 1;
toz80 = (unsigned __int8)portA_out;
}
portC_out = a2;
return result;
}

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

result = (unsigned __int8)ddrC;
if ( (ddrC & 4) != 0 && (a2 & 4) == 0 && (portC_out & 4) != 0 )
{
cpu_trigger(700LL);
z80write = 0;
portA_in = fromz80;
result = (unsigned __int8)ddrC;
}
if ( (result & 8) != 0 && (a2 & 8) == 0 && (portC_out & 8) != 0 )
{
result = (unsigned __int8)portA_out;
m68705write = 1;
toz80 = (unsigned __int8)portA_out;
}
portC_out = a2;
return result;
}

original_code:
void arkanoid_68705_portC_w(offs_t offset,data_t data)
{
 if ((ddrC & 0x04) && (~data & 0x04) && (portC_out & 0x04))
 {
  cpu_trigger(700);
  z80write = 0;
  portA_in = fromz80;
 }
 if ((ddrC & 0x08) && (~data & 0x08) && (portC_out & 0x08))
 {
  m68705write = 1;
  toz80 = portA_out;
 }
 portC_out = data;
}

canonical_original_code:
void arkanoid_68705_portC_w(unsigned int offset, unsigned int data)
{
 if ((ddrC & 0x04) && (~data & 0x04) && (portC_out & 0x04))
 {
  cpu_trigger(700);
  z80write = 0;
  portA_in = fromz80;
 }
 if ((ddrC & 0x08) && (~data & 0x08) && (portC_out & 0x08))
 {
  m68705write = 1;
  toz80 = portA_out;
 }
 portC_out = data;
}


decompiled_code:
char arkanoid_68705_input_0_r()
{
__int64 v0; // rax

v0 = input_port_0_r() & 0x3F;
if ( !z80write )
LOBYTE(v0) = v0 | 0x40;
if ( !m68705write )
LOBYTE(v0) = v0 | 0x80;
return v0;
}

canonical_decompiled_code:
char func10()
{
__int64 v0; // rax

v0 = input_port_0_r() & 0x3F;
if ( !z80write )
LOBYTE(v0) = v0 | 0x40;
if ( !m68705write )
LOBYTE(v0) = v0 | 0x80;
return v0;
}

original_code:
data_t arkanoid_68705_input_0_r(offs_t offset)
{
 int res = input_port_0_r(offset) & 0x3f;
 if (!z80write) res |= 0x40;
 if (!m68705write) res |= 0x80;
 return res;
}

canonical_original_code:
unsigned int arkanoid_68705_input_0_r(unsigned int offset)
{
 int res = input_port_0_r(offset) & 0x3f;
 if (!z80write) res |= 0x40;
 if (!m68705write) res |= 0x80;
 return res;
}


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

if ( arkanoid_paddle_select )
result = input_port_3_r();
else
result = input_port_2_r();
return result;
}

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

if ( arkanoid_paddle_select )
result = input_port_3_r();
else
result = input_port_2_r();
return result;
}

original_code:
data_t arkanoid_input_2_r(offs_t offset)
{
 if (arkanoid_paddle_select)
 {
  return input_port_3_r(offset);
 }
 else
 {
  return input_port_2_r(offset);
 }
}

canonical_original_code:
unsigned int arkanoid_input_2_r(unsigned int offset)
{
 if (arkanoid_paddle_select)
 {
  return input_port_3_r(offset);
 }
 else
 {
  return input_port_2_r(offset);
 }
}


decompiled_code:
__int64 __fastcall arkanoid_d008_w(__int64 a1, unsigned int a2)
{
flip_screen_x_w(a1, a2 & 1);
flip_screen_y_w((unsigned int)a1, a2 & 2);
arkanoid_paddle_select = a2 & 4;
coin_lockout_w(0LL, ((unsigned __int8)(a2 >> 3) ^ 1) & 1);
coin_lockout_w(1LL, ((unsigned __int8)(a2 >> 3) ^ 1) & 1);
set_vh_global_attribute(&gfxbank, (a2 >> 5) & 1);
return set_vh_global_attribute(&palettebank, (a2 & 0x40) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
flip_screen_x_w(a1, a2 & 1);
flip_screen_y_w((unsigned int)a1, a2 & 2);
arkanoid_paddle_select = a2 & 4;
coin_lockout_w(0LL, ((unsigned __int8)(a2 >> 3) ^ 1) & 1);
coin_lockout_w(1LL, ((unsigned __int8)(a2 >> 3) ^ 1) & 1);
set_vh_global_attribute(&gfxbank, (a2 >> 5) & 1);
return set_vh_global_attribute(&palettebank, (a2 & 0x40) != 0);
}

original_code:
void arkanoid_d008_w(offs_t offset,data_t data)
{
 flip_screen_x_w(offset, data & 0x01);
 flip_screen_y_w(offset, data & 0x02);
    arkanoid_paddle_select = data & 0x04;
 coin_lockout_w(0, !(data & 0x08));
 coin_lockout_w(1, !(data & 0x08));
 set_vh_global_attribute(&gfxbank, (data & 0x20) >> 5);
 set_vh_global_attribute(&palettebank, (data & 0x40) >> 6);
}

canonical_original_code:
void arkanoid_d008_w(unsigned int offset, unsigned int data)
{
 flip_screen_x_w(offset, data & 0x01);
 flip_screen_y_w(offset, data & 0x02);
    arkanoid_paddle_select = data & 0x04;
 coin_lockout_w(0, !(data & 0x08));
 coin_lockout_w(1, !(data & 0x08));
 set_vh_global_attribute(&gfxbank, (data & 0x20) >> 5);
 set_vh_global_attribute(&palettebank, (data & 0x40) >> 6);
}


decompiled_code:
__int64 __fastcall xmen_tile_callback(int a1, __int64 a2, __int64 a3, int *a4)
{
int v4; // eax
__int64 result; // rax

v4 = *a4;
if ( a1 )
result = layer_colorbase[a1] + ((v4 >> 2) & 0x1Fu);
else
result = layer_colorbase[0] + ((v4 >> 4) & 0xFu);
*a4 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, int *a4)
{
int v4; // eax
__int64 result; // rax

v4 = *a4;
if ( a1 )
result = layer_colorbase[a1] + ((v4 >> 2) & 0x1Fu);
else
result = layer_colorbase[0] + ((v4 >> 4) & 0xFu);
*a4 = result;
return result;
}

original_code:
static void xmen_tile_callback(int layer,int bank,int *code,int *color)
{
 if (layer == 0)
  *color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
 else
  *color = layer_colorbase[layer] + ((*color & 0x7c) >> 2);
}

canonical_original_code:
static void xmen_tile_callback(int layer, int bank, int *code, int *color)
{
 if (layer == 0)
  *color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
 else
  *color = layer_colorbase[layer] + ((*color & 0x7c) >> 2);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
__int64 __fastcall xmen_sprite_callback(__int64 a1, int *a2, _DWORD *a3)
{
int v3; // eax
__int64 result; // rax

v3 = (*a2 >> 4) & 0xE;
if ( dword_678 < v3 )
{
if ( dword_674 < v3 )
*a3 = 2 * (layerpri < v3) + 252;
else
*a3 = 240;
result = sprite_colorbase + (*a2 & 0x1Fu);
*a2 = result;
}
else
{
*a3 = 0;
result = sprite_colorbase + (*a2 & 0x1Fu);
*a2 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, _DWORD *a3)
{
int v3; // eax
__int64 result; // rax

v3 = (*a2 >> 4) & 0xE;
if ( dword_678 < v3 )
{
if ( dword_674 < v3 )
*a3 = 2 * (layerpri < v3) + 252;
else
*a3 = 240;
result = sprite_colorbase + (*a2 & 0x1Fu);
*a2 = result;
}
else
{
*a3 = 0;
result = sprite_colorbase + (*a2 & 0x1Fu);
*a2 = result;
}
return result;
}

original_code:
static void xmen_sprite_callback(int *code,int *color,int *priority_mask)
{
 int pri = (*color & 0x00e0) >> 4;
 if (pri <= layerpri[2]) *priority_mask = 0;
 else if (pri > layerpri[2] && pri <= layerpri[1]) *priority_mask = 0xf0;
 else if (pri > layerpri[1] && pri <= layerpri[0]) *priority_mask = 0xf0|0xcc;
 else *priority_mask = 0xf0|0xcc|0xaa;
 *color = sprite_colorbase + (*color & 0x001f);
}

canonical_original_code:
static void xmen_sprite_callback(int *code, int *color, int *priority_mask)
{
 int pri = (*color & 0x00e0) >> 4;
 if (pri <= layerpri[2]) *priority_mask = 0;
 else if (pri > layerpri[2] && pri <= layerpri[1]) *priority_mask = 0xf0;
 else if (pri > layerpri[1] && pri <= layerpri[0]) *priority_mask = 0xf0|0xcc;
 else *priority_mask = 0xf0|0xcc|0xaa;
 *color = sprite_colorbase + (*color & 0x001f);
}

variable_types: pri int


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

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

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

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

original_code:
int xmen_vh_start(void)
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,xmen_tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,xmen_sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int xmen_vh_start()
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,xmen_tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,xmen_sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


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

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

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


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

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

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

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


original_code:
static void init_xmen6p(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 (*(UINT16 *)(&RAM[0x21a6]) = (0x4e71));
 (*(UINT16 *)(&RAM[0x21a8]) = (0x4e71));
 (*(UINT16 *)(&RAM[0x21aa]) = (0x4e71));
 init_xmen();
}

canonical_original_code:
static void init_xmen6p()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 (*(unsigned short *)(&RAM[0x21a6]) = (0x4e71));
 (*(unsigned short *)(&RAM[0x21a8]) = (0x4e71));
 (*(unsigned short *)(&RAM[0x21aa]) = (0x4e71));
 init_xmen();
}

variable_types:
RAM
unsigned char *


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

if ( (unsigned int)cpu_getiloops() )
result = m68_level3_irq();
else
result = m68_level5_irq();
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
result = m68_level3_irq();
else
result = m68_level5_irq();
return result;
}

original_code:
static int xmen_interrupt(void)
{
 if (cpu_getiloops() == 0) return m68_level5_irq();
 else return m68_level3_irq();
}

canonical_original_code:
static int xmen_interrupt()
{
 if (cpu_getiloops() == 0) return m68_level5_irq();
 else return m68_level3_irq();
}


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

if ( !(_DWORD)a1 )
result = interrupt_enable_w(a1, a2 & 4);
return result;
}

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

if ( !(_DWORD)a1 )
result = interrupt_enable_w(a1, a2 & 4);
return result;
}

original_code:
static void xmen_18fa00_w(offs_t offset,data_t data)
{
 if (offset == 0)
 {
  interrupt_enable_w(0,data & 0x04);
 }
}

canonical_original_code:
static void xmen_18fa00_w(unsigned int offset, unsigned int data)
{
 if (offset == 0)
 {
  interrupt_enable_w(0,data & 0x04);
 }
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K053251_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K053251_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void K053251_halfword_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K053251_w(offset >> 1,data & 0xff);
}

canonical_original_code:
static void K053251_halfword_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K053251_w(offset >> 1,data & 0xff);
}


decompiled_code:
__int64 __fastcall K052109_halfword_r(unsigned int a1)
{
return K052109_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
return K052109_r(a1 >> 1);
}

original_code:
static data_t K052109_halfword_r(offs_t offset)
{
 return K052109_r(offset >> 1);
}

canonical_original_code:
static unsigned int K052109_halfword_r(unsigned int offset)
{
 return K052109_r(offset >> 1);
}


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

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

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

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

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

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

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

variable_types:
layer
int [3]


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

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

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

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

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

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

variable_types: bankaddress int


decompiled_code:
__int64 __fastcall sound_cmd_w(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( !(_DWORD)a1 )
{
soundlatch_w(a1, a2);
result = *(unsigned int *)(Machine + 836LL);
if ( !(_DWORD)result && (a2 & 0xFD) == 252 )
result = soundlatch2_w(0LL, 127LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( !(_DWORD)a1 )
{
soundlatch_w(a1, a2);
result = *(unsigned int *)(Machine + 836LL);
if ( !(_DWORD)result && (a2 & 0xFD) == 252 )
result = soundlatch2_w(0LL, 127LL);
}
return result;
}

original_code:
static void sound_cmd_w(offs_t offset,data_t data)
{
 if (offset == 0)
 {
  data &= 0xff;
  soundlatch_w(0, data);
  if(!Machine->sample_rate)
   if(data == 0xfc || data == 0xfe)
    soundlatch2_w(0, 0x7f);
 }
}

canonical_original_code:
static void sound_cmd_w(unsigned int offset, unsigned int data)
{
 if (offset == 0)
 {
  data &= 0xff;
  soundlatch_w(0, data);
  if(!Machine->sample_rate)
   if(data == 0xfc || data == 0xfe)
    soundlatch2_w(0, 0x7f);
 }
}


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

if ( (a2 & 0xFF0000) != 0 )
{
K053246_set_OBJCHA_line((a2 >> 8) & 1);
result = K052109_set_RMRD_line((a2 & 0x200) != 0);
}
else
{
coin_counter_w(0LL, a2 & 1);
EEPROM_write_bit(a2 & 4);
EEPROM_set_cs_line(((unsigned __int8)(a2 >> 4) ^ 1) & 1);
result = EEPROM_set_clock_line((a2 & 8) != 0);
}
return result;
}

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

if ( (a2 & 0xFF0000) != 0 )
{
K053246_set_OBJCHA_line((a2 >> 8) & 1);
result = K052109_set_RMRD_line((a2 & 0x200) != 0);
}
else
{
coin_counter_w(0LL, a2 & 1);
EEPROM_write_bit(a2 & 4);
EEPROM_set_cs_line(((unsigned __int8)(a2 >> 4) ^ 1) & 1);
result = EEPROM_set_clock_line((a2 & 8) != 0);
}
return result;
}

original_code:
static void eeprom_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  coin_counter_w(0,data & 0x01);
  EEPROM_write_bit(data & 0x04);
  EEPROM_set_cs_line((data & 0x10) ? 0 : 1);
  EEPROM_set_clock_line((data & 0x08) ? 1 : 0);
 }
 else
 {
  K053246_set_OBJCHA_line((data & 0x0100) ? 1 : 0);
  K052109_set_RMRD_line((data & 0x0200) ? 1 : 0);
 }
}

canonical_original_code:
static void eeprom_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  coin_counter_w(0,data & 0x01);
  EEPROM_write_bit(data & 0x04);
  EEPROM_set_cs_line((data & 0x10) ? 0 : 1);
  EEPROM_set_clock_line((data & 0x08) ? 1 : 0);
 }
 else
 {
  K053246_set_OBJCHA_line((data & 0x0100) ? 1 : 0);
  K052109_set_RMRD_line((data & 0x0200) ? 1 : 0);
 }
}


decompiled_code:
__int64 eeprom_r()
{
int v0; // ebx
__int64 result; // rax

v0 = EEPROM_read_bit();
result = (unsigned int)input_port_2_r(0LL) | (v0 << 6);
if ( init_eeprom_count )
{
result = (unsigned __int16)result & 0xBFFF;
--init_eeprom_count;
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
int v0; // ebx
__int64 result; // rax

v0 = EEPROM_read_bit();
result = (unsigned int)input_port_2_r(0LL) | (v0 << 6);
if ( init_eeprom_count )
{
result = (unsigned __int16)result & 0xBFFF;
--init_eeprom_count;
}
return result;
}

original_code:
static data_t eeprom_r(offs_t offset)
{
 int res;
 res = (EEPROM_read_bit() << 6) | input_port_2_r(0);
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xbfff;
 }
 return res;
}

canonical_original_code:
static unsigned int eeprom_r(unsigned int offset)
{
 int res;
 res = (EEPROM_read_bit() << 6) | input_port_2_r(0);
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xbfff;
 }
 return res;
}


decompiled_code:
__int64 sound_status_r()
{
return soundlatch2_r(0LL);
}

canonical_decompiled_code:
__int64 func17()
{
return soundlatch2_r(0LL);
}

original_code:
static data_t sound_status_r(offs_t offset)
{
 return soundlatch2_r(0);
}

canonical_original_code:
static unsigned int sound_status_r(unsigned int offset)
{
 return soundlatch2_r(0);
}


decompiled_code:
__int64 atari_vg_earom_r()
{
return (unsigned int)earom_data;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)earom_data;
}

original_code:
data_t atari_vg_earom_r(offs_t offset)
{
 return (earom_data);
}

canonical_original_code:
unsigned int atari_vg_earom_r(unsigned int offset)
{
 return (earom_data);
}


decompiled_code:
void __fastcall atari_vg_earom_w(int a1, int a2)
{
earom_offset = a1;
earom_data = a2;
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
earom_offset = a1;
earom_data = a2;
}

original_code:
void atari_vg_earom_w(offs_t offset,data_t data)
{
 earom_offset = offset;
 earom_data = data;
}

canonical_original_code:
void atari_vg_earom_w(unsigned int offset, unsigned int data)
{
 earom_offset = offset;
 earom_data = data;
}


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

if ( (a2 & 1) != 0 )
{
result = (unsigned int)*((char *)&earom + earom_offset);
earom_data = *((char *)&earom + earom_offset);
}
if ( (a2 & 0xC) == 12 )
{
result = earom_offset;
*((_BYTE *)&earom + earom_offset) = earom_data;
}
return result;
}

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

if ( (a2 & 1) != 0 )
{
result = (unsigned int)*((char *)&earom + earom_offset);
earom_data = *((char *)&earom + earom_offset);
}
if ( (a2 & 0xC) == 12 )
{
result = earom_offset;
*((_BYTE *)&earom + earom_offset) = earom_data;
}
return result;
}

original_code:
void atari_vg_earom_ctrl_w(offs_t offset,data_t data)
{
 if (data & 0x01)
  earom_data = earom[earom_offset];
 if ((data & 0x0c) == 0x0c)
 {
  earom[earom_offset]=earom_data;
 }
}

canonical_original_code:
void atari_vg_earom_ctrl_w(unsigned int offset, unsigned int data)
{
 if (data & 0x01)
  earom_data = earom[earom_offset];
 if ((data & 0x0c) == 0x0c)
 {
  earom[earom_offset]=earom_data;
 }
}


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

if ( a2 )
return osd_fwrite(a1, &earom, 64LL);
if ( a1 )
return osd_fread(a1, &earom, 64LL);
earom = 0LL;
xmmword_F0 = 0LL;
xmmword_100 = 0LL;
xmmword_110 = 0LL;
return result;
}

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

if ( a2 )
return osd_fwrite(a1, &earom, 64LL);
if ( a1 )
return osd_fread(a1, &earom, 64LL);
earom = 0LL;
xmmword_F0 = 0LL;
xmmword_100 = 0LL;
xmmword_110 = 0LL;
return result;
}

original_code:
void atari_vg_earom_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,earom,0x40);
 else
 {
  if (file)
   osd_fread(file,earom,0x40);
  else
   memset(earom,0,0x40);
 }
}

canonical_original_code:
void atari_vg_earom_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,earom,0x40);
 else
 {
  if (file)
   osd_fread(file,earom,0x40);
  else
   memset(earom,0,0x40);
 }
}

variable_types:
file
void *


original_code:
static void redbaron_sound_update(int param, INT16 *buffer, int length)
{
 while( length-- )
 {
  int sum = 0;
  poly_counter -= 12000;
  while( poly_counter <= 0 )
  {
   poly_counter += Machine->sample_rate;
   if( ((poly_shift & 0x0001) == 0) == ((poly_shift & 0x4000) == 0) )
    poly_shift = (poly_shift << 1) | 1;
   else
    poly_shift <<= 1;
  }
  filter_counter -= 330;
  while( filter_counter <= 0 )
  {
   filter_counter += Machine->sample_rate;
   crash_amp = (poly_shift & 1) ? latch >> 4 : 0;
  }
  sum += vol_crash[crash_amp] * 35 / 100;
  if( (latch & 0x04) == 0 )
            shot_amp = 32767;
        else
  if( (poly_shift & 0x8000) == 0 )
        {
   if( shot_amp > 0 )
   {
    shot_amp_counter -= (int)(32767 / 0.03264);;
    while( shot_amp_counter <= 0 )
    {
     shot_amp_counter += Machine->sample_rate;
     if( --shot_amp == 0 )
      break;
    }
    sum += vol_lookup[shot_amp] * 35 / 100;
            }
        }
  if( (latch & 0x02) == 0 )
   squeal_amp = 0;
  else
  {
   if( squeal_amp < 32767 )
   {
    squeal_amp_counter -= (int)(32767 / 1.01728);;
    while( squeal_amp_counter <= 0 )
    {
     squeal_amp_counter += Machine->sample_rate;
     if( ++squeal_amp == 32767 )
      break;
    }
   }
   if( squeal_out )
   {
    squeal_off_counter -= (1134 + 1134 * squeal_amp / 32767) / 3;
    while( squeal_off_counter <= 0 )
    {
     squeal_off_counter += Machine->sample_rate;
     squeal_out = 0;
    }
   }
   else
   {
    squeal_on_counter -= 1134;
    while( squeal_on_counter <= 0 )
    {
     squeal_on_counter += Machine->sample_rate;
     squeal_out = 1;
                }
            }
  }
        if( squeal_out )
   sum += 32767 * 40 / 100;
  *buffer++ = sum;
 }
}

canonical_original_code:
static void redbaron_sound_update(int param, short *buffer, int length)
{
 while( length-- )
 {
  int sum = 0;
  poly_counter -= 12000;
  while( poly_counter <= 0 )
  {
   poly_counter += Machine->sample_rate;
   if( ((poly_shift & 0x0001) == 0) == ((poly_shift & 0x4000) == 0) )
    poly_shift = (poly_shift << 1) | 1;
   else
    poly_shift <<= 1;
  }
  filter_counter -= 330;
  while( filter_counter <= 0 )
  {
   filter_counter += Machine->sample_rate;
   crash_amp = (poly_shift & 1) ? latch >> 4 : 0;
  }
  sum += vol_crash[crash_amp] * 35 / 100;
  if( (latch & 0x04) == 0 )
            shot_amp = 32767;
        else
  if( (poly_shift & 0x8000) == 0 )
        {
   if( shot_amp > 0 )
   {
    shot_amp_counter -= (int)(32767 / 0.03264);;
    while( shot_amp_counter <= 0 )
    {
     shot_amp_counter += Machine->sample_rate;
     if( --shot_amp == 0 )
      break;
    }
    sum += vol_lookup[shot_amp] * 35 / 100;
            }
        }
  if( (latch & 0x02) == 0 )
   squeal_amp = 0;
  else
  {
   if( squeal_amp < 32767 )
   {
    squeal_amp_counter -= (int)(32767 / 1.01728);;
    while( squeal_amp_counter <= 0 )
    {
     squeal_amp_counter += Machine->sample_rate;
     if( ++squeal_amp == 32767 )
      break;
    }
   }
   if( squeal_out )
   {
    squeal_off_counter -= (1134 + 1134 * squeal_amp / 32767) / 3;
    while( squeal_off_counter <= 0 )
    {
     squeal_off_counter += Machine->sample_rate;
     squeal_out = 0;
    }
   }
   else
   {
    squeal_on_counter -= 1134;
    while( squeal_on_counter <= 0 )
    {
     squeal_on_counter += Machine->sample_rate;
     squeal_out = 1;
                }
            }
  }
        if( squeal_out )
   sum += 32767 * 40 / 100;
  *buffer++ = sum;
 }
}

variable_types: param int

variable_types:
buffer
short *

variable_types: length int

variable_types: sum int


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

if ( (latch & 0x20) != 0 )
result = pokey1_w();
return result;
}

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

if ( (latch & 0x20) != 0 )
result = pokey1_w();
return result;
}

original_code:
void redbaron_pokey_w(offs_t offset,data_t data)
{
    if( latch & 0x20 )
        pokey1_w (offset, data);
}

canonical_original_code:
void redbaron_pokey_w(unsigned int offset, unsigned int data)
{
    if( latch & 0x20 )
        pokey1_w (offset, data);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

variable_types: i int


decompiled_code:
void redbaron_sh_stop()
{
if ( vol_lookup )
free(vol_lookup);
vol_lookup = 0LL;
}

canonical_decompiled_code:
void func3()
{
if ( vol_lookup )
free(vol_lookup);
vol_lookup = 0LL;
}

original_code:
void redbaron_sh_stop(void)
{
 if( vol_lookup )
  free(vol_lookup);
 vol_lookup = ((void *)0);
}

canonical_original_code:
void redbaron_sh_stop()
{
 if( vol_lookup )
  free(vol_lookup);
 vol_lookup = ((void *)0);
}


decompiled_code:
__int64 redbaron_sh_update()
{
return stream_update((unsigned int)channel, 0LL);
}

canonical_decompiled_code:
__int64 func4()
{
return stream_update((unsigned int)channel, 0LL);
}

original_code:
void redbaron_sh_update(void)
{
 stream_update(channel, 0);
}

canonical_original_code:
void redbaron_sh_update()
{
 stream_update(channel, 0);
}


decompiled_code:
void __fastcall starcrus_s1_x_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s1_x = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s1_x = a2;
}

original_code: void starcrus_s1_x_w(offs_t offset,data_t data) { s1_x = data^0xff; }

canonical_original_code: void starcrus_s1_x_w(unsigned int offset, unsigned int data) { s1_x = data^0xff; }


decompiled_code:
void __fastcall starcrus_s1_y_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s1_y = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s1_y = a2;
}

original_code: void starcrus_s1_y_w(offs_t offset,data_t data) { s1_y = data^0xff; }

canonical_original_code: void starcrus_s1_y_w(unsigned int offset, unsigned int data) { s1_y = data^0xff; }


decompiled_code:
void __fastcall starcrus_s2_x_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s2_x = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s2_x = a2;
}

original_code: void starcrus_s2_x_w(offs_t offset,data_t data) { s2_x = data^0xff; }

canonical_original_code: void starcrus_s2_x_w(unsigned int offset, unsigned int data) { s2_x = data^0xff; }


decompiled_code:
void __fastcall starcrus_s2_y_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s2_y = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
s2_y = a2;
}

original_code: void starcrus_s2_y_w(offs_t offset,data_t data) { s2_y = data^0xff; }

canonical_original_code: void starcrus_s2_y_w(unsigned int offset, unsigned int data) { s2_y = data^0xff; }


decompiled_code:
void __fastcall starcrus_p1_x_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_x = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_x = a2;
}

original_code: void starcrus_p1_x_w(offs_t offset,data_t data) { p1_x = data^0xff; }

canonical_original_code: void starcrus_p1_x_w(unsigned int offset, unsigned int data) { p1_x = data^0xff; }


decompiled_code:
void __fastcall starcrus_p1_y_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_y = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_y = a2;
}

original_code: void starcrus_p1_y_w(offs_t offset,data_t data) { p1_y = data^0xff; }

canonical_original_code: void starcrus_p1_y_w(unsigned int offset, unsigned int data) { p1_y = data^0xff; }


decompiled_code:
void __fastcall starcrus_p2_x_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_x = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_x = a2;
}

original_code: void starcrus_p2_x_w(offs_t offset,data_t data) { p2_x = data^0xff; }

canonical_original_code: void starcrus_p2_x_w(unsigned int offset, unsigned int data) { p2_x = data^0xff; }


decompiled_code:
void __fastcall starcrus_p2_y_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_y = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_y = a2;
}

original_code: void starcrus_p2_y_w(offs_t offset,data_t data) { p2_y = data^0xff; }

canonical_original_code: void starcrus_p2_y_w(unsigned int offset, unsigned int data) { p2_y = data^0xff; }


decompiled_code:
char starcrus_coll_det_r()
{
return ~(_BYTE)collision_reg;
}

canonical_decompiled_code:
char func8()
{
return ~(_BYTE)collision_reg;
}

original_code:
data_t starcrus_coll_det_r(offs_t offset)
{
    return collision_reg ^ 0xff;
}

canonical_original_code:
unsigned int starcrus_coll_det_r(unsigned int offset)
{
    return collision_reg ^ 0xff;
}


decompiled_code:
__int64 starcrus_vh_start()
{
unsigned int v0; // er12
__int64 result; // rax

v0 = 1;
ship1_vid = bitmap_alloc(16LL, 16LL);
if ( !ship1_vid )
return v0;
ship2_vid = bitmap_alloc(16LL, 16LL);
if ( ship2_vid )
{
proj1_vid = bitmap_alloc(16LL, 16LL);
if ( proj1_vid )
{
v0 = 0;
proj2_vid = bitmap_alloc(16LL, 16LL);
if ( !proj2_vid )
{
v0 = 1;
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
}
return v0;
}
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
result = 1LL;
}
else
{
bitmap_free(ship1_vid);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // er12
__int64 result; // rax

v0 = 1;
ship1_vid = bitmap_alloc(16LL, 16LL);
if ( !ship1_vid )
return v0;
ship2_vid = bitmap_alloc(16LL, 16LL);
if ( ship2_vid )
{
proj1_vid = bitmap_alloc(16LL, 16LL);
if ( proj1_vid )
{
v0 = 0;
proj2_vid = bitmap_alloc(16LL, 16LL);
if ( !proj2_vid )
{
v0 = 1;
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
}
return v0;
}
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
result = 1LL;
}
else
{
bitmap_free(ship1_vid);
result = 1LL;
}
return result;
}

original_code:
int starcrus_vh_start(void)
{
 if ((ship1_vid = bitmap_alloc(16,16)) == 0)
 {
  return 1;
 }
 if ((ship2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  return 1;
 }
 if ((proj1_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  return 1;
 }
 if ((proj2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  bitmap_free(proj1_vid);
  return 1;
 }
 return 0;
}

canonical_original_code:
int starcrus_vh_start()
{
 if ((ship1_vid = bitmap_alloc(16,16)) == 0)
 {
  return 1;
 }
 if ((ship2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  return 1;
 }
 if ((proj1_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  return 1;
 }
 if ((proj2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  bitmap_free(proj1_vid);
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 starcrus_vh_stop()
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
return bitmap_free(proj2_vid);
}

canonical_decompiled_code:
__int64 func11()
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
return bitmap_free(proj2_vid);
}

original_code:
void starcrus_vh_stop(void)
{
 bitmap_free(ship1_vid);
 bitmap_free(ship2_vid);
 bitmap_free(proj1_vid);
 bitmap_free(proj2_vid);
}

canonical_original_code:
void starcrus_vh_stop()
{
 bitmap_free(ship1_vid);
 bitmap_free(ship2_vid);
 bitmap_free(proj1_vid);
 bitmap_free(proj2_vid);
}


decompiled_code:
__int64 starcrus_collision_check_s1s2()
{
int v0; // ebp
int v1; // er13
__int64 v2; // rsi
__int64 v3; // rax
unsigned int v4; // ebp
unsigned int i; // ebx
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]
__int64 *v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+18h] [rbp-20h]
__int64 v11; // [rsp+20h] [rbp-18h]

v7 = 0xF00000000LL;
v8 = 0xF00000000LL;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), &v7);
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), &v7);
v0 = s1_x;
v1 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
&v7,
0LL,
0LL);
v2 = *(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592);
v11 = 0LL;
v10 = 0LL;
v9 = &v7;
v8 = (unsigned int)(s2_y - v1);
v3 = (unsigned int)(s2_x - v0);
v4 = 0;
((void (__fastcall *)(__int64, __int64, _QWORD, _QWORD, _QWORD, _QWORD, __int64, __int64))drawgfx)(
ship2_vid,
v2,
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
v3,
v8);
do
{
for ( i = 0; i != 16; ++i )
{
if ( (unsigned int)read_pixel(ship1_vid, i, v4) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(ship2_vid, i, v4) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
++v4;
}
while ( v4 != 16 );
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
int v1; // er13
__int64 v2; // rsi
__int64 v3; // rax
unsigned int v4; // ebp
unsigned int i; // ebx
__int64 v7; // [rsp+0h] [rbp-38h] BYREF
__int64 v8; // [rsp+8h] [rbp-30h]
__int64 *v9; // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+18h] [rbp-20h]
__int64 v11; // [rsp+20h] [rbp-18h]

v7 = 0xF00000000LL;
v8 = 0xF00000000LL;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), &v7);
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), &v7);
v0 = s1_x;
v1 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
&v7,
0LL,
0LL);
v2 = *(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592);
v11 = 0LL;
v10 = 0LL;
v9 = &v7;
v8 = (unsigned int)(s2_y - v1);
v3 = (unsigned int)(s2_x - v0);
v4 = 0;
((void (__fastcall *)(__int64, __int64, _QWORD, _QWORD, _QWORD, _QWORD, __int64, __int64))drawgfx)(
ship2_vid,
v2,
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
v3,
v8);
do
{
for ( i = 0; i != 16; ++i )
{
if ( (unsigned int)read_pixel(ship1_vid, i, v4) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(ship2_vid, i, v4) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
++v4;
}
while ( v4 != 16 );
return 0LL;
}

original_code:
int starcrus_collision_check_s1s2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_s1s2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

variable_types: sx int

variable_types: sy int

variable_types: struct rectangle { int min_x; int min_y; }


decompiled_code:
__int64 starcrus_collision_check_p1p2()
{
int v0; // ebp
int v1; // er13
unsigned int i; // ebp
unsigned int j; // ebx
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) == 0 )
return 0LL;
v5[0] = 0xF00000000LL;
v5[1] = 0xF00000000LL;
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v0 = p1_x;
v1 = p1_y;
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v0),
(unsigned int)(p2_y - v1),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // ebp
int v1; // er13
unsigned int i; // ebp
unsigned int j; // ebx
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) == 0 )
return 0LL;
v5[0] = 0xF00000000LL;
v5[1] = 0xF00000000LL;
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v0 = p1_x;
v1 = p1_y;
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v0),
(unsigned int)(p2_y - v1),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
}
return 0LL;
}

original_code:
int starcrus_collision_check_p1p2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = p1_x;
 org_y = p1_y;
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_p1p2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = p1_x;
 org_y = p1_y;
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

user_defined_types: struct rectangle { int min_x; int min_y; }


decompiled_code:
__int64 starcrus_collision_check_s1p1p2()
{
int v0; // ebp
int v1; // er13
unsigned int i; // ebp
unsigned int j; // ebx
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) == 0 )
return 0LL;
v5[0] = 0xF00000000LL;
v5[1] = 0xF00000000LL;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v0 = s1_x;
v1 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v0),
(unsigned int)(p1_y - v1),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v0),
(unsigned int)(p2_y - v1),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(ship1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& ((unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
|| (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)) )
{
return 1LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebp
int v1; // er13
unsigned int i; // ebp
unsigned int j; // ebx
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) == 0 )
return 0LL;
v5[0] = 0xF00000000LL;
v5[1] = 0xF00000000LL;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v0 = s1_x;
v1 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v0),
(unsigned int)(p1_y - v1),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v0),
(unsigned int)(p2_y - v1),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(ship1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& ((unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
|| (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)) )
{
return 1LL;
}
}
}
return 0LL;
}

original_code:
int starcrus_collision_check_s1p1p2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_s1p1p2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}


decompiled_code:
__int64 starcrus_collision_check_s2p1p2()
{
int v0; // ebp
int v1; // er13
unsigned int i; // ebp
unsigned int j; // ebx
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) == 0 )
return 0LL;
v5[0] = 0xF00000000LL;
v5[1] = 0xF00000000LL;
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v0 = s2_x;
v1 = s2_y;
drawgfx(
ship2_vid,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v0),
(unsigned int)(p1_y - v1),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v0),
(unsigned int)(p2_y - v1),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(ship2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& ((unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
|| (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)) )
{
return 1LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // ebp
int v1; // er13
unsigned int i; // ebp
unsigned int j; // ebx
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) == 0 )
return 0LL;
v5[0] = 0xF00000000LL;
v5[1] = 0xF00000000LL;
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v0 = s2_x;
v1 = s2_y;
drawgfx(
ship2_vid,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v0),
(unsigned int)(p1_y - v1),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v0),
(unsigned int)(p2_y - v1),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(ship2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& ((unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
|| (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)) )
{
return 1LL;
}
}
}
return 0LL;
}

original_code:
int starcrus_collision_check_s2p1p2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s2_x;
 org_y = s2_y;
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_s2p1p2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s2_x;
 org_y = s2_y;
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}


decompiled_code:
__int64 __fastcall starcrus_vh_screenrefresh(__int64 a1)
{
__int64 result; // rax

fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
(unsigned int)s1_x,
(unsigned int)s1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
(unsigned int)s2_x,
(unsigned int)s2_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p1_x,
(unsigned int)p1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p2_x,
(unsigned int)p2_y,
Machine + 776LL,
2LL,
0LL);
collision_reg = 0;
if ( (unsigned int)starcrus_collision_check_s1s2() )
collision_reg |= 8u;
if ( (unsigned int)starcrus_collision_check_s1p1p2() )
collision_reg |= 2u;
if ( (unsigned int)starcrus_collision_check_s2p1p2() )
collision_reg |= 1u;
result = starcrus_collision_check_p1p2();
if ( (_DWORD)result )
collision_reg |= 4u;
return result;
}

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

fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
(unsigned int)s1_x,
(unsigned int)s1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
(unsigned int)s2_x,
(unsigned int)s2_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p1_x,
(unsigned int)p1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p2_x,
(unsigned int)p2_y,
Machine + 776LL,
2LL,
0LL);
collision_reg = 0;
if ( (unsigned int)func12() )
collision_reg |= 8u;
if ( (unsigned int)func14() )
collision_reg |= 2u;
if ( (unsigned int)func15() )
collision_reg |= 1u;
result = func13();
if ( (_DWORD)result )
collision_reg |= 4u;
return result;
}

original_code:
void starcrus_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
    drawgfx(bitmap,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x,s1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    drawgfx(bitmap,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x,s2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[(p1_sprite&0x0c)>>2],
            (p1_sprite&0x03)^0x03,
            0,
            0,0,
            p1_x,p1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[4+((p2_sprite&0x0c)>>2)],
            (p2_sprite&0x03)^0x03,
            0,
            0,0,
            p2_x,p2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    collision_reg = 0x00;
    if (starcrus_collision_check_s1s2())
    {
        collision_reg |= 0x08;
    }
    if (starcrus_collision_check_s1p1p2())
    {
        collision_reg |= 0x02;
    }
    if (starcrus_collision_check_s2p1p2())
    {
        collision_reg |= 0x01;
    }
    if (starcrus_collision_check_p1p2())
    {
        collision_reg |= 0x04;
    }
}

canonical_original_code:
void starcrus_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
    drawgfx(bitmap,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x,s1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    drawgfx(bitmap,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x,s2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[(p1_sprite&0x0c)>>2],
            (p1_sprite&0x03)^0x03,
            0,
            0,0,
            p1_x,p1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[4+((p2_sprite&0x0c)>>2)],
            (p2_sprite&0x03)^0x03,
            0,
            0,0,
            p2_x,p2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    collision_reg = 0x00;
    if (starcrus_collision_check_s1s2())
    {
        collision_reg |= 0x08;
    }
    if (starcrus_collision_check_s1p1p2())
    {
        collision_reg |= 0x02;
    }
    if (starcrus_collision_check_s2p1p2())
    {
        collision_reg |= 0x01;
    }
    if (starcrus_collision_check_p1p2())
    {
        collision_reg |= 0x04;
    }
}

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


decompiled_code:
__int64 omegrace_watchdog_r()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

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

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


decompiled_code:
__int64 omegrace_spinner1_r()
{
return spinnerTable[readinputport(4LL) & 0x3F];
}

canonical_decompiled_code:
__int64 func1()
{
return spinnerTable[readinputport(4LL) & 0x3F];
}

original_code:
data_t omegrace_spinner1_r(offs_t offset)
{
 int res;
 res=readinputport(4);
 return (spinnerTable[res&0x3f]);
}

canonical_original_code:
unsigned int omegrace_spinner1_r(unsigned int offset)
{
 int res;
 res=readinputport(4);
 return (spinnerTable[res&0x3f]);
}

variable_types: res int


decompiled_code:
__int64 __fastcall omegrace_leds_w(__int64 a1, int a2)
{
unsigned int v2; // esi

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
v2 = ~a2;
osd_led_w(0LL, v2 >> 2);
return osd_led_w(1LL, v2 >> 3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // esi

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
v2 = ~a2;
osd_led_w(0LL, v2 >> 2);
return osd_led_w(1LL, v2 >> 3);
}

original_code:
void omegrace_leds_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
 osd_led_w(0,~data >> 2);
 osd_led_w(1,~data >> 3);
}

canonical_original_code:
void omegrace_leds_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
 osd_led_w(0,~data >> 2);
 osd_led_w(1,~data >> 3);
}


decompiled_code:
__int64 omegrace_soundlatch_w()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func3()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 255LL);
}

original_code:
void omegrace_soundlatch_w(offs_t offset,data_t data)
{
 soundlatch_w (offset, data);
 cpu_cause_interrupt (1, 0xff);
}

canonical_original_code:
void omegrace_soundlatch_w(unsigned int offset, unsigned int data)
{
 soundlatch_w (offset, data);
 cpu_cause_interrupt (1, 0xff);
}


decompiled_code:
__int64 omegrace_init_machine()
{
return avgdvg_reset_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func5()
{
return avgdvg_reset_w(0LL, 0LL);
}

original_code:
static void omegrace_init_machine(void)
{
 avgdvg_reset_w (0, 0);
}

canonical_original_code:
static void omegrace_init_machine()
{
 avgdvg_reset_w (0, 0);
}


decompiled_code:
__int64 omegrace_vg_status_r()
{
return (unsigned __int8)((unsigned int)avgdvg_done() == 0) << 7;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned __int8)((unsigned int)avgdvg_done() == 0) << 7;
}

original_code:
static data_t omegrace_vg_status_r(offs_t offset)
{
 if (avgdvg_done())
  return 0;
 else
  return 0x80;
}

canonical_original_code:
static unsigned int omegrace_vg_status_r(unsigned int offset)
{
 if (avgdvg_done())
  return 0;
 else
  return 0x80;
}


decompiled_code:
__int64 omegrace_vg_go_r()
{
avgdvg_go_w(0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
avgdvg_go_w(0LL, 0LL);
return 0LL;
}

original_code:
static data_t omegrace_vg_go_r(offs_t offset)
{
 avgdvg_go_w(0,0);
 return 0;
}

canonical_original_code:
static unsigned int omegrace_vg_go_r(unsigned int offset)
{
 avgdvg_go_w(0,0);
 return 0;
}


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

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

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


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

v1 = *(unsigned __int16 *)(ginganin_txtram + 2 * a1);
v2 = *(_QWORD *)(Machine + 528LL);
v3 = (unsigned int)v1 % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (v1 >> 12);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v3 * *(_DWORD *)(v2 + 52));
v5 = *(_QWORD *)(v2 + 16) + 2 * v4;
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

v1 = *(unsigned __int16 *)(ginganin_txtram + 2 * a1);
v2 = *(_QWORD *)(Machine + 528LL);
v3 = (unsigned int)v1 % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (v1 >> 12);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v3 * *(_DWORD *)(v2 + 52));
v5 = *(_QWORD *)(v2 + 16) + 2 * v4;
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_txt_tile_info(int tile_index)
{
 int code = (*(UINT16 *)(&ginganin_txtram[2*tile_index]));
 { const struct GfxElement *gfx = Machine->gfx[((2))]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (code >> 12)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_txt_tile_info(int tile_index)
{
 int code = (*(UINT16 *)(&ginganin_txtram[2*tile_index]));
 { struct GfxElement *gfx = Machine->gfx[((2))]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (code >> 12)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types: code 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 MC6840_control_port_0_w(__int64 a1, char a2)
{
if ( a2 < 0 )
{
if ( S_TEMPO != (unsigned __int8)MC6840_register0 && MC6840_register0 )
{
S_TEMPO = (unsigned __int8)MC6840_register0;
MC6809_FLAG = 1;
}
else
{
MC6809_FLAG = 1;
}
}
else
{
MC6809_FLAG = 0;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
if ( a2 < 0 )
{
if ( S_TEMPO != (unsigned __int8)MC6840_register0 && MC6840_register0 )
{
S_TEMPO = (unsigned __int8)MC6840_register0;
MC6809_FLAG = 1;
}
else
{
MC6809_FLAG = 1;
}
}
else
{
MC6809_FLAG = 0;
}
}

original_code:
static void MC6840_control_port_0_w(offs_t offset,data_t data)
{
 MC6840_index0 = data;
 if (MC6840_index0 & 0x80) {
  if ((MC6840_register0 != S_TEMPO) && (MC6840_register0 != 0)) {
   S_TEMPO = MC6840_register0;
  }
  MC6809_FLAG = 1;
 } else {
  MC6809_FLAG = 0;
 }
}

canonical_original_code:
static void MC6840_control_port_0_w(unsigned int offset, unsigned int data)
{
 MC6840_index0 = data;
 if (MC6840_index0 & 0x80) {
  if ((MC6840_register0 != S_TEMPO) && (MC6840_register0 != 0)) {
   S_TEMPO = MC6840_register0;
  }
  MC6809_FLAG = 1;
 } else {
  MC6809_FLAG = 0;
 }
}


decompiled_code:
void MC6840_control_port_1_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
static void MC6840_control_port_1_w(offs_t offset,data_t data)
{
 MC6840_index1 = data;
}

canonical_original_code:
static void MC6840_control_port_1_w(unsigned int offset, unsigned int data)
{
 MC6840_index1 = data;
}


decompiled_code:
void __fastcall MC6840_write_port_0_w(__int64 a1, char a2)
{
MC6840_register0 = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, char a2)
{
MC6840_register0 = a2;
}

original_code:
static void MC6840_write_port_0_w(offs_t offset,data_t data)
{
 MC6840_register0 = data;
}

canonical_original_code:
static void MC6840_write_port_0_w(unsigned int offset, unsigned int data)
{
 MC6840_register0 = data;
}


decompiled_code:
void MC6840_write_port_1_w()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
static void MC6840_write_port_1_w(offs_t offset,data_t data)
{
 MC6840_register1 = data;
}

canonical_original_code:
static void MC6840_write_port_1_w(unsigned int offset, unsigned int data)
{
 MC6840_register1 = data;
}


decompiled_code:
__int64 ginganin_interrupt()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 1LL;
}

original_code:
int ginganin_interrupt(void)
{
 return 1;
}

canonical_original_code:
int ginganin_interrupt()
{
 return 1;
}


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

if ( S_TEMPO_OLD != S_TEMPO )
{
S_TEMPO_OLD = S_TEMPO;
MC6809_CTR = 0;
}
result = (unsigned int)MC6809_FLAG;
if ( MC6809_FLAG )
{
if ( S_TEMPO < MC6809_CTR )
{
MC6809_CTR = 0;
result = 1LL;
}
else
{
++MC6809_CTR;
result = 0LL;
}
}
return result;
}

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

if ( S_TEMPO_OLD != S_TEMPO )
{
S_TEMPO_OLD = S_TEMPO;
MC6809_CTR = 0;
}
result = (unsigned int)MC6809_FLAG;
if ( MC6809_FLAG )
{
if ( S_TEMPO < MC6809_CTR )
{
MC6809_CTR = 0;
result = 1LL;
}
else
{
++MC6809_CTR;
result = 0LL;
}
}
return result;
}

original_code:
int ginganin_sound_interrupt(void)
{
 if (S_TEMPO_OLD != S_TEMPO) {
  S_TEMPO_OLD = S_TEMPO;
  MC6809_CTR = 0;
 }
 if (MC6809_FLAG != 0) {
  if (MC6809_CTR > S_TEMPO) {
   MC6809_CTR = 0;
   return 1;
  } else {
   MC6809_CTR++;
  }
 }
 return 0;
}

canonical_original_code:
int ginganin_sound_interrupt()
{
 if (S_TEMPO_OLD != S_TEMPO) {
  S_TEMPO_OLD = S_TEMPO;
  MC6809_CTR = 0;
 }
 if (MC6809_FLAG != 0) {
  if (MC6809_CTR > S_TEMPO) {
   MC6809_CTR = 0;
   return 1;
  } else {
   MC6809_CTR++;
  }
 }
 return 0;
}


decompiled_code:
unsigned __int16 *__fastcall ginganin_fgram_w(unsigned int a1, unsigned int a2)
{
unsigned __int16 *result; // rax
__int16 v3; // cx
int v4; // esi

result = (unsigned __int16 *)(ginganin_fgram + a1);
v3 = *result;
v4 = a2 | *result & HIWORD(a2);
*result = v4;
if ( v3 != (_WORD)v4 )
result = (unsigned __int16 *)tilemap_mark_tile_dirty(fg_tilemap, a1 >> 1);
return result;
}

canonical_decompiled_code:
unsigned __int16 *__fastcall func8(unsigned int a1, unsigned int a2)
{
unsigned __int16 *result; // rax
__int16 v3; // cx
int v4; // esi

result = (unsigned __int16 *)(ginganin_fgram + a1);
v3 = *result;
v4 = a2 | *result & HIWORD(a2);
*result = v4;
if ( v3 != (_WORD)v4 )
result = (unsigned __int16 *)tilemap_mark_tile_dirty(fg_tilemap, a1 >> 1);
return result;
}

original_code:
void ginganin_fgram_w(offs_t offset,data_t data)
{
 int old_data, new_data;
 old_data = (*(UINT16 *)(&ginganin_fgram[offset]));
 ((*(UINT16 *)((&ginganin_fgram[offset])) = (((*(UINT16 *)(&ginganin_fgram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(UINT16 *)(&ginganin_fgram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(fg_tilemap,offset/2);
}

canonical_original_code:
void ginganin_fgram_w(unsigned int offset, unsigned int data)
{
 int old_data; int new_data;
 old_data = (*(unsigned short *)(&ginganin_fgram[offset]));
 ((*(unsigned short *)((&ginganin_fgram[offset])) = (((*(unsigned short *)(&ginganin_fgram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(unsigned short *)(&ginganin_fgram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(fg_tilemap,offset/2);
}


decompiled_code:
unsigned __int16 *__fastcall ginganin_txtram_w(unsigned int a1, unsigned int a2)
{
unsigned __int16 *result; // rax
__int16 v3; // cx
int v4; // esi

result = (unsigned __int16 *)(ginganin_txtram + a1);
v3 = *result;
v4 = a2 | *result & HIWORD(a2);
*result = v4;
if ( v3 != (_WORD)v4 )
result = (unsigned __int16 *)tilemap_mark_tile_dirty(tx_tilemap, a1 >> 1);
return result;
}

canonical_decompiled_code:
unsigned __int16 *__fastcall func9(unsigned int a1, unsigned int a2)
{
unsigned __int16 *result; // rax
__int16 v3; // cx
int v4; // esi

result = (unsigned __int16 *)(ginganin_txtram + a1);
v3 = *result;
v4 = a2 | *result & HIWORD(a2);
*result = v4;
if ( v3 != (_WORD)v4 )
result = (unsigned __int16 *)tilemap_mark_tile_dirty(tx_tilemap, a1 >> 1);
return result;
}

original_code:
void ginganin_txtram_w(offs_t offset,data_t data)
{
int old_data, new_data;
 old_data = (*(UINT16 *)(&ginganin_txtram[offset]));
 ((*(UINT16 *)((&ginganin_txtram[offset])) = (((*(UINT16 *)(&ginganin_txtram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(UINT16 *)(&ginganin_txtram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(tx_tilemap,offset/2);
}

canonical_original_code:
void ginganin_txtram_w(unsigned int offset, unsigned int data)
{
int old_data; int new_data;
 old_data = (*(unsigned short *)(&ginganin_txtram[offset]));
 ((*(unsigned short *)((&ginganin_txtram[offset])) = (((*(unsigned short *)(&ginganin_txtram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(unsigned short *)(&ginganin_txtram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(tx_tilemap,offset/2);
}


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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 16LL, 16LL, 512LL, 32LL);
LODWORD(v4) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 256LL, v4);
LODWORD(v5) = 32;
fg_tilemap = v1;
v2 = tilemap_create(get_txt_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v5);
tx_tilemap = v2;
if ( !fg_tilemap || !bg_tilemap || !v2 )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 15;
*(_DWORD *)(v2 + 132) = 15;
return 0LL;
}

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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 16LL, 16LL, 512LL, 32LL);
LODWORD(v4) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 256LL, v4);
LODWORD(v5) = 32;
fg_tilemap = v1;
v2 = tilemap_create(get_txt_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v5);
tx_tilemap = v2;
if ( !fg_tilemap || !bg_tilemap || !v2 )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 15;
*(_DWORD *)(v2 + 132) = 15;
return 0LL;
}

original_code:
int ginganin_vh_start(void)
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x00,16,16,(16*32),(16*2));
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,16,16,(16*16),(16*2));
 tx_tilemap = tilemap_create(get_txt_tile_info,tilemap_scan_rows,0x01,8,8,(32),(32));
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 15;
 tx_tilemap->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int ginganin_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x00,16,16,(16*32),(16*2));
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,16,16,(16*16),(16*2));
 tx_tilemap = tilemap_create(get_txt_tile_info,tilemap_scan_rows,0x01,8,8,(32),(32));
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 15;
 tx_tilemap->transparent_pen = 15;
 return 0;
}


decompiled_code:
__int64 __fastcall ginganin_vregs_w(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
_WORD *v3; // rdx
unsigned int v4; // esi
int v5; // esi
int v6; // esi

result = a2;
v3 = (_WORD *)(a1 + ginganin_vregs);
v4 = HIWORD(a2);
LOWORD(v4) = *v3 & v4;
v5 = result | v4;
*v3 = v5;
switch ( a1 )
{
case 0u:
result = tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 2u:
result = tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 4u:
result = tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 6u:
result = tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 8u:
layers_ctrl = (unsigned __int16)v5;
break;
case 0xCu:
v6 = ~v5;
flipscreen = v6 & 1;
result = tilemap_set_flip(0LL, (v6 << 31 >> 31) & 3);
break;
case 0xEu:
soundlatch_w(0LL, (unsigned __int16)v5);
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
_WORD *v3; // rdx
unsigned int v4; // esi
int v5; // esi
int v6; // esi

result = a2;
v3 = (_WORD *)(a1 + ginganin_vregs);
v4 = HIWORD(a2);
LOWORD(v4) = *v3 & v4;
v5 = result | v4;
*v3 = v5;
switch ( a1 )
{
case 0u:
result = tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 2u:
result = tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 4u:
result = tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 6u:
result = tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int16)v5);
break;
case 8u:
layers_ctrl = (unsigned __int16)v5;
break;
case 0xCu:
v6 = ~v5;
flipscreen = v6 & 1;
result = tilemap_set_flip(0LL, (v6 << 31 >> 31) & 3);
break;
case 0xEu:
soundlatch_w(0LL, (unsigned __int16)v5);
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

original_code:
void ginganin_vregs_w(offs_t offset,data_t data)
{
 int new_data;
 ((*(UINT16 *)((&ginganin_vregs[offset])) = (((*(UINT16 *)(&ginganin_vregs[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(UINT16 *)(&ginganin_vregs[offset]));
 switch (offset)
 {
  case 0x0 : { tilemap_set_scrolly(fg_tilemap, 0, new_data); } break;
  case 0x2 : { tilemap_set_scrollx(fg_tilemap, 0, new_data); } break;
  case 0x4 : { tilemap_set_scrolly(bg_tilemap, 0, new_data); } break;
  case 0x6 : { tilemap_set_scrollx(bg_tilemap, 0, new_data); } break;
  case 0x8 : { layers_ctrl = new_data; } break;
  case 0xc : { flipscreen = !(new_data & 1); tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0); } break;
  case 0xe : { soundlatch_w(0,new_data);
      cpu_cause_interrupt(1,4);
       } break;
  default :
      break;
 }
}

canonical_original_code:
void ginganin_vregs_w(unsigned int offset, unsigned int data)
{
 int new_data;
 ((*(unsigned short *)((&ginganin_vregs[offset])) = (((*(unsigned short *)(&ginganin_vregs[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(unsigned short *)(&ginganin_vregs[offset]));
 switch (offset)
 {
  case 0x0 : { tilemap_set_scrolly(fg_tilemap, 0, new_data); } break;
  case 0x2 : { tilemap_set_scrollx(fg_tilemap, 0, new_data); } break;
  case 0x4 : { tilemap_set_scrolly(bg_tilemap, 0, new_data); } break;
  case 0x6 : { tilemap_set_scrollx(bg_tilemap, 0, new_data); } break;
  case 0x8 : { layers_ctrl = new_data; } break;
  case 0xc : { flipscreen = !(new_data & 1); tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0); } break;
  case 0xe : { soundlatch_w(0,new_data);
      cpu_cause_interrupt(1,4);
       } break;
  default :
      break;
 }
}