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

if ( (unsigned int)cpu_getiloops() )
result = interrupt();
else
result = nmi_interrupt();
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
result = interrupt();
else
result = nmi_interrupt();
return result;
}

original_code:
int zodiac_master_interrupt(void)
{
 return (cpu_getiloops() == 0) ? nmi_interrupt() : interrupt();
}

canonical_original_code:
int zodiac_master_interrupt()
{
 return (cpu_getiloops() == 0) ? nmi_interrupt() : interrupt();
}


decompiled_code:
__int64 zodiac_master_soundlatch_w()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 func6()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 4294966296LL);
}

original_code:
void zodiac_master_soundlatch_w(offs_t offset,data_t data)
{
 soundlatch_w(offset, data);
 cpu_cause_interrupt(1, -1000);
}

canonical_original_code:
void zodiac_master_soundlatch_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset, data);
 cpu_cause_interrupt(1, -1000);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


zlibVersion

decompiled_code:
const char *zlibVersion()
{
return "1.2.3";
}

canonical_decompiled_code:
const char *func0()
{
return "1.2.3";
}

original_code:
const char * zlibVersion()
{
    return "1.2.3";
}

canonical_original_code:
char *zlibVersion()
{
    return "1.2.3";
}

return_type: char *


zlibCompileFlags

decompiled_code:
__int64 zlibCompileFlags()
{
return 169LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 169LL;
}

original_code:
uLong zlibCompileFlags()
{
    uLong flags;
    flags = 0;
    switch (sizeof(uInt)) {
    case 2: break;
    case 4: flags += 1; break;
    case 8: flags += 2; break;
    default: flags += 3;
    }
    switch (sizeof(uLong)) {
    case 2: break;
    case 4: flags += 1 << 2; break;
    case 8: flags += 2 << 2; break;
    default: flags += 3 << 2;
    }
    switch (sizeof(voidpf)) {
    case 2: break;
    case 4: flags += 1 << 4; break;
    case 8: flags += 2 << 4; break;
    default: flags += 3 << 4;
    }
    switch (sizeof(long)) {
    case 2: break;
    case 4: flags += 1 << 6; break;
    case 8: flags += 2 << 6; break;
    default: flags += 3 << 6;
    }
    return flags;
}

canonical_original_code:
unsigned long zlibCompileFlags()
{
    unsigned long flags;
    flags = 0;
    switch (sizeof(uInt)) {
    case 2: break;
    case 4: flags += 1; break;
    case 8: flags += 2; break;
    default: flags += 3;
    }
    switch (sizeof(uLong)) {
    case 2: break;
    case 4: flags += 1 << 2; break;
    case 8: flags += 2 << 2; break;
    default: flags += 3 << 2;
    }
    switch (sizeof(voidpf)) {
    case 2: break;
    case 4: flags += 1 << 4; break;
    case 8: flags += 2 << 4; break;
    default: flags += 3 << 4;
    }
    switch (sizeof(long)) {
    case 2: break;
    case 4: flags += 1 << 6; break;
    case 8: flags += 2 << 6; break;
    default: flags += 3 << 6;
    }
    return flags;
}

variable_types:
flags
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall astrof_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
prom = a3;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
prom = a3;
}

original_code:
void astrof_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 prom = color_prom;
}

canonical_original_code:
void astrof_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 prom = color_prom;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 __fastcall astrof_videoram_w(int a1, int a2)
{
return common_videoram_w(a1, a2, *astrof_color & 0xE);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return func1(a1, a2, *astrof_color & 0xE);
}

original_code:
void astrof_videoram_w(offs_t offset,data_t data)
{
 common_videoram_w(offset, data, *astrof_color & 0x0e);
}

canonical_original_code:
void astrof_videoram_w(unsigned int offset, unsigned int data)
{
 common_videoram_w(offset, data, *astrof_color & 0x0e);
}


decompiled_code:
__int64 __fastcall tomahawk_videoram_w(int a1, int a2)
{
return common_videoram_w(a1, a2, *astrof_color & 0xE | (16 * *astrof_color) & 0x10u);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return func1(a1, a2, *astrof_color & 0xE | (16 * *astrof_color) & 0x10u);
}

original_code:
void tomahawk_videoram_w(offs_t offset,data_t data)
{
 common_videoram_w(offset, data, (*astrof_color & 0x0e) | ((*astrof_color & 0x01) << 4));
}

canonical_original_code:
void tomahawk_videoram_w(unsigned int offset, unsigned int data)
{
 common_videoram_w(offset, data, (*astrof_color & 0x0e) | ((*astrof_color & 0x01) << 4));
}


decompiled_code:
__int64 __fastcall astrof_video_control2_w(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // esi

result = a2 & 4;
if ( (_DWORD)result != palette_bank )
{
palette_bank = a2 & 4;
do_modify_palette = 1;
}
v3 = a2 & 8;
if ( v3 != red_on )
{
red_on = v3;
do_modify_palette = 1;
}
return result;
}

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

result = a2 & 4;
if ( (_DWORD)result != palette_bank )
{
palette_bank = a2 & 4;
do_modify_palette = 1;
}
v3 = a2 & 8;
if ( v3 != red_on )
{
red_on = v3;
do_modify_palette = 1;
}
return result;
}

original_code:
void astrof_video_control2_w(offs_t offset,data_t data)
{
 if (palette_bank != (data & 0x04))
 {
  palette_bank = (data & 0x04);
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}

canonical_original_code:
void astrof_video_control2_w(unsigned int offset, unsigned int data)
{
 if (palette_bank != (data & 0x04))
 {
  palette_bank = (data & 0x04);
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}


decompiled_code:
void __fastcall tomahawk_video_control2_w(__int64 a1, char a2)
{
int v2; // esi

if ( palette_bank == -1 )
{
palette_bank = 0;
do_modify_palette = 1;
}
v2 = a2 & 8;
if ( v2 != red_on )
{
red_on = v2;
do_modify_palette = 1;
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char a2)
{
int v2; // esi

if ( palette_bank == -1 )
{
palette_bank = 0;
do_modify_palette = 1;
}
v2 = a2 & 8;
if ( v2 != red_on )
{
red_on = v2;
do_modify_palette = 1;
}
}

original_code:
void tomahawk_video_control2_w(offs_t offset,data_t data)
{
 if (palette_bank == -1)
 {
  palette_bank = 0;
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}

canonical_original_code:
void tomahawk_video_control2_w(unsigned int offset, unsigned int data)
{
 if (palette_bank == -1)
 {
  palette_bank = 0;
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}


decompiled_code:
__int64 tomahawk_protection_r()
{
int v0; // edx

v0 = (unsigned __int8)*tomahawk_protection;
return (v0 >> 5) & 2 | (v0 >> 3) & 4 | (v0 >> 1) & 8 | (2 * (_BYTE)v0) & 0x10 | (8 * (_BYTE)v0) & 0x20 | (*tomahawk_protection >> 7) | (32 * *tomahawk_protection) & 0x40 | (unsigned int)(unsigned __int8)((_BYTE)v0 << 7);
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edx

v0 = (unsigned __int8)*tomahawk_protection;
return (v0 >> 5) & 2 | (v0 >> 3) & 4 | (v0 >> 1) & 8 | (2 * (_BYTE)v0) & 0x10 | (8 * (_BYTE)v0) & 0x20 | (*tomahawk_protection >> 7) | (32 * *tomahawk_protection) & 0x40 | (unsigned int)(unsigned __int8)((_BYTE)v0 << 7);
}

original_code:
data_t tomahawk_protection_r(offs_t offset)
{
 int res = ((*tomahawk_protection & 0x01) << 7) |
     ((*tomahawk_protection & 0x02) << 5) |
     ((*tomahawk_protection & 0x04) << 3) |
     ((*tomahawk_protection & 0x08) << 1) |
     ((*tomahawk_protection & 0x10) >> 1) |
     ((*tomahawk_protection & 0x20) >> 3) |
     ((*tomahawk_protection & 0x40) >> 5) |
     ((*tomahawk_protection & 0x80) >> 7);
 return res;
}

canonical_original_code:
unsigned int tomahawk_protection_r(unsigned int offset)
{
 int res = ((*tomahawk_protection & 0x01) << 7) |
     ((*tomahawk_protection & 0x02) << 5) |
     ((*tomahawk_protection & 0x04) << 3) |
     ((*tomahawk_protection & 0x08) << 1) |
     ((*tomahawk_protection & 0x10) >> 1) |
     ((*tomahawk_protection & 0x20) >> 3) |
     ((*tomahawk_protection & 0x40) >> 5) |
     ((*tomahawk_protection & 0x80) >> 7);
 return res;
}

variable_types: res int

return_type: unsigned int


decompiled_code:
__int64 astrof_vh_start()
{
colorram = malloc(videoram_size);
if ( colorram )
return 0LL;
generic_bitmapped_vh_stop();
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
colorram = malloc(videoram_size);
if ( colorram )
return 0LL;
generic_bitmapped_vh_stop();
return 1LL;
}

original_code:
int astrof_vh_start(void)
{
 if ((colorram = (unsigned char*)malloc(videoram_size)) == 0)
 {
  generic_bitmapped_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int astrof_vh_start()
{
 if ((colorram = (unsigned char *)malloc(videoram_size)) == 0)
 {
  generic_bitmapped_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
void astrof_vh_stop()
{
if ( colorram )
free(colorram);
}

canonical_decompiled_code:
void func8()
{
if ( colorram )
free(colorram);
}

original_code:
void astrof_vh_stop(void)
{
 if (colorram) free(colorram);
}

canonical_original_code:
void astrof_vh_stop()
{
 if (colorram) free(colorram);
}


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

result = input_port_2_r(0LL);
if ( (result & 2) != 0 )
result = flip_screen_w(a1, a2 & 1);
return result;
}

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

result = input_port_2_r(0LL);
if ( (result & 2) != 0 )
result = flip_screen_w(a1, a2 & 1);
return result;
}

original_code:
void astrof_video_control1_w(offs_t offset,data_t data)
{
 if (input_port_2_r(0) & 0x02)
 {
  flip_screen_w(offset, data & 0x01);
 }
}

canonical_original_code:
void astrof_video_control1_w(unsigned int offset, unsigned int data)
{
 if (input_port_2_r(0) & 0x02)
 {
  flip_screen_w(offset, data & 0x01);
 }
}


decompiled_code:
__int64 modify_palette()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rbp
unsigned int v3; // er9
unsigned int v4; // er8
int v5; // eax
int v6; // ecx
__int64 v7; // rdi

v0 = palette_bank;
if ( palette_bank )
v0 = 16LL;
result = *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL);
if ( (_DWORD)result )
{
v2 = 0LL;
do
{
v3 = 63 * ((*(_BYTE *)(v2 + prom + v0) & 0x20) != 0) + 192 * ((*(_BYTE *)(v2 + prom + v0) & 0x10) != 0);
v4 = 192 * ((*(_BYTE *)(v2 + prom + v0) & 4) != 0) + 63 * ((*(_BYTE *)(v2 + prom + v0) & 8) != 0);
v5 = (red_on >> 3) | *(_BYTE *)(v2 + prom + v0) & 1;
v6 = (red_on >> 3) | ((*(_BYTE *)(v2 + prom + v0) & 2) != 0);
v7 = (unsigned int)v2++;
palette_change_color(v7, (unsigned __int8)(63 * v6 - ((_BYTE)v5 << 6)), v4, v3);
result = *(_QWORD *)(Machine + 824LL);
}
while ( *(_DWORD *)(result + 696) > (unsigned int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rbp
unsigned int v3; // er9
unsigned int v4; // er8
int v5; // eax
int v6; // ecx
__int64 v7; // rdi

v0 = palette_bank;
if ( palette_bank )
v0 = 16LL;
result = *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL);
if ( (_DWORD)result )
{
v2 = 0LL;
do
{
v3 = 63 * ((*(_BYTE *)(v2 + prom + v0) & 0x20) != 0) + 192 * ((*(_BYTE *)(v2 + prom + v0) & 0x10) != 0);
v4 = 192 * ((*(_BYTE *)(v2 + prom + v0) & 4) != 0) + 63 * ((*(_BYTE *)(v2 + prom + v0) & 8) != 0);
v5 = (red_on >> 3) | *(_BYTE *)(v2 + prom + v0) & 1;
v6 = (red_on >> 3) | ((*(_BYTE *)(v2 + prom + v0) & 2) != 0);
v7 = (unsigned int)v2++;
palette_change_color(v7, (unsigned __int8)(63 * v6 - ((_BYTE)v5 << 6)), v4, v3);
result = *(_QWORD *)(Machine + 824LL);
}
while ( *(_DWORD *)(result + 696) > (unsigned int)v2 );
}
return result;
}

original_code:
static void modify_palette(void)
{
 int i, col_index;
 col_index = (palette_bank ? 16 : 0);
 for (i = 0;i < Machine->drv->total_colors; i++)
 {
  int bit0,bit1,r,g,b;
  bit0 = ((prom[col_index] >> 0) & 0x01) | (red_on >> 3);
  bit1 = ((prom[col_index] >> 1) & 0x01) | (red_on >> 3);
  r = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 2) & 0x01;
  bit1 = ( prom[col_index] >> 3) & 0x01;
  g = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 4) & 0x01;
  bit1 = ( prom[col_index] >> 5) & 0x01;
  b = 0xc0 * bit0 + 0x3f * bit1;
  col_index++;
  palette_change_color(i,r,g,b);
 }
}

canonical_original_code:
static void modify_palette()
{
 int i; int col_index;
 col_index = (palette_bank ? 16 : 0);
 for (i = 0;i < Machine->drv->total_colors; i++)
 {
  int bit0; int bit1; int r; int g; int b;
  bit0 = ((prom[col_index] >> 0) & 0x01) | (red_on >> 3);
  bit1 = ((prom[col_index] >> 1) & 0x01) | (red_on >> 3);
  r = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 2) & 0x01;
  bit1 = ( prom[col_index] >> 3) & 0x01;
  g = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 4) & 0x01;
  bit1 = ( prom[col_index] >> 5) & 0x01;
  b = 0xc0 * bit0 + 0x3f * bit1;
  col_index++;
  palette_change_color(i,r,g,b);
 }
}

variable_types: i int

variable_types: r int

variable_types: g int

variable_types: b int


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

if ( start_explosion )
{
if ( (a2 & 4) != 0 )
{
if ( !bosskill_playing )
{
result = sample_start(1LL, 10LL, 0LL);
bosskill_playing = 1;
}
}
else if ( (a2 & 2) != 0 )
{
result = sample_start(1LL, 9LL, 0LL);
}
else if ( (a2 & 1) != 0 )
{
result = sample_start(1LL, 1LL, 0LL);
}
else
{
result = (unsigned int)death_playing;
if ( !death_playing )
{
result = sample_start(1LL, 8LL, 0LL);
death_playing = 1;
}
}
start_explosion = 0;
}
if ( (a2 & 8) != 0 && (last_0 & 8) == 0 )
{
result = sample_start(3LL, 7LL, 0LL);
last_0 = a2;
}
else
{
last_0 = a2;
}
return result;
}

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

if ( start_explosion )
{
if ( (a2 & 4) != 0 )
{
if ( !bosskill_playing )
{
result = sample_start(1LL, 10LL, 0LL);
bosskill_playing = 1;
}
}
else if ( (a2 & 2) != 0 )
{
result = sample_start(1LL, 9LL, 0LL);
}
else if ( (a2 & 1) != 0 )
{
result = sample_start(1LL, 1LL, 0LL);
}
else
{
result = (unsigned int)death_playing;
if ( !death_playing )
{
result = sample_start(1LL, 8LL, 0LL);
death_playing = 1;
}
}
start_explosion = 0;
}
if ( (a2 & 8) != 0 && (last_0 & 8) == 0 )
{
result = sample_start(3LL, 7LL, 0LL);
last_0 = a2;
}
else
{
last_0 = a2;
}
return result;
}

original_code:
void astrof_sample2_w(offs_t offset,data_t data)
{
 static int last = 0;
 if (start_explosion)
 {
  if (data & 0x04)
  {
   if (!bosskill_playing)
   {
    sample_start(1,10,0);
    bosskill_playing = 1;
   }
  }
  else if (data & 0x02)
  {
   sample_start(1,9,0);
  }
  else if (data & 0x01)
  {
   sample_start(1,1,0);
  }
  else
  {
   if (!death_playing)
   {
    sample_start(1,8,0);
    death_playing = 1;
   }
  }
  start_explosion = 0;
 }
 if ((data & 0x08) && !(last & 0x08))
 {
  sample_start(3,7,0);
 }
 last = data;
}

canonical_original_code:
void astrof_sample2_w(unsigned int offset, unsigned int data)
{
 static int last = 0;
 if (start_explosion)
 {
  if (data & 0x04)
  {
   if (!bosskill_playing)
   {
    sample_start(1,10,0);
    bosskill_playing = 1;
   }
  }
  else if (data & 0x02)
  {
   sample_start(1,9,0);
  }
  else if (data & 0x01)
  {
   sample_start(1,1,0);
  }
  else
  {
   if (!death_playing)
   {
    sample_start(1,8,0);
    death_playing = 1;
   }
  }
  start_explosion = 0;
 }
 if ((data & 0x08) && !(last & 0x08))
 {
  sample_start(3,7,0);
 }
 last = data;
}

variable_types: last int


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

if ( death_playing )
death_playing = sample_playing(1LL);
if ( bosskill_playing )
bosskill_playing = sample_playing(1LL);
if ( (a2 & 4) != 0 && (last_1 & 4) == 0 )
start_explosion = 1;
result = a2 ^ (unsigned int)last_1;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)last_1) & 8) != 0 )
{
if ( (a2 & 8) != 0 )
result = sample_start(2LL, (a2 & 3u) + 2, 1LL);
else
result = sample_stop(2LL);
}
if ( (a2 & 0x10) != 0 )
{
result = bosskill_playing | last_1 & 0x10u;
if ( !(bosskill_playing | last_1 & 0x10) )
result = sample_start(2LL, 6LL, 0LL);
}
if ( (a2 & 0x20) != 0 )
{
result = bosskill_playing | last_1 & 0x20u;
if ( !(bosskill_playing | last_1 & 0x20) )
result = sample_start(0LL, 0LL, 0LL);
}
last_1 = a2;
return result;
}

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

if ( death_playing )
death_playing = sample_playing(1LL);
if ( bosskill_playing )
bosskill_playing = sample_playing(1LL);
if ( (a2 & 4) != 0 && (last_1 & 4) == 0 )
start_explosion = 1;
result = a2 ^ (unsigned int)last_1;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)last_1) & 8) != 0 )
{
if ( (a2 & 8) != 0 )
result = sample_start(2LL, (a2 & 3u) + 2, 1LL);
else
result = sample_stop(2LL);
}
if ( (a2 & 0x10) != 0 )
{
result = bosskill_playing | last_1 & 0x10u;
if ( !(bosskill_playing | last_1 & 0x10) )
result = sample_start(2LL, 6LL, 0LL);
}
if ( (a2 & 0x20) != 0 )
{
result = bosskill_playing | last_1 & 0x20u;
if ( !(bosskill_playing | last_1 & 0x20) )
result = sample_start(0LL, 0LL, 0LL);
}
last_1 = a2;
return result;
}

original_code:
void astrof_sample1_w(offs_t offset,data_t data)
{
 static int last = 0;
 if (death_playing)
 {
  death_playing = sample_playing(1);
 }
 if (bosskill_playing)
 {
  bosskill_playing = sample_playing(1);
 }
 if ((data & 0x04) && !(last & 0x04))
 {
  start_explosion = 1;
 }
 if ((data & 0x08) != (last & 0x08))
 {
  if (data & 0x08)
  {
   int sample = 2 + (data & 3);
   sample_start(2,sample,1);
  }
  else
  {
   sample_stop(2);
  }
 }
 if ((data & 0x10) && !(last & 0x10))
 {
  if (!bosskill_playing)
  {
   sample_start(2,6,0);
  }
 }
 if ((data & 0x20) && !(last & 0x20))
 {
  if (!bosskill_playing)
  {
   sample_start(0,0,0);
  }
 }
 last = data;
}

canonical_original_code:
void astrof_sample1_w(unsigned int offset, unsigned int data)
{
 static int last = 0;
 if (death_playing)
 {
  death_playing = sample_playing(1);
 }
 if (bosskill_playing)
 {
  bosskill_playing = sample_playing(1);
 }
 if ((data & 0x04) && !(last & 0x04))
 {
  start_explosion = 1;
 }
 if ((data & 0x08) != (last & 0x08))
 {
  if (data & 0x08)
  {
   int sample = 2 + (data & 3);
   sample_start(2,sample,1);
  }
  else
  {
   sample_stop(2);
  }
 }
 if ((data & 0x10) && !(last & 0x10))
 {
  if (!bosskill_playing)
  {
   sample_start(2,6,0);
  }
 }
 if ((data & 0x20) && !(last & 0x20))
 {
  if (!bosskill_playing)
  {
   sample_start(0,0,0);
  }
 }
 last = data;
}

variable_types: sample int


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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int astrof_interrupt(void)
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int astrof_interrupt()
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall common_videoram_w(int a1, int a2, int a3)
{
__int64 v3; // rcx
int v4; // er13
int v5; // er12
__int64 v7; // rdx
__int64 v8; // rdi
unsigned int v9; // er14
int v10; // esi
unsigned int v11; // ebp
unsigned int v12; // er15
int v13; // ebx
__int64 v14; // rcx
__int64 v15; // rsi
__int64 result; // rax
unsigned __int16 v17; // [rsp+Eh] [rbp-3Ah]

v3 = a3;
v4 = a2;
v5 = 1;
*(_BYTE *)(videoram + a1) = a2;
*(_BYTE *)(colorram + a1) = a3;
v7 = Machine;
v8 = *(_QWORD *)(Machine + 792LL);
v9 = *(unsigned __int16 *)(v8 + 2 * v3);
v10 = a1 >> 8;
v11 = (unsigned __int8)~(_BYTE)a1;
v17 = *(_WORD *)(v8 + 2LL * (int)(v3 | 1));
v12 = 8 * v10;
if ( flip_screen_x )
{
v5 = -1;
v11 = 255 - v11;
v12 = 255 - v12;
}
v13 = 8;
while ( 1 )
{
v14 = v17;
v15 = v12;
if ( (v4 & 1) == 0 )
v14 = v9;
v12 += v5;
v4 >>= 1;
result = plot_pixel(*(_QWORD *)(v7 + 768), v15, v11, v14);
if ( !--v13 )
break;
v7 = Machine;
}
return result;
}

original_code:
static void common_videoram_w(int offset, int data, int color)
{
 int i,x,y,fore,back;
 int dx = 1;
 videoram[offset] = data;
 colorram[offset] = color;
 fore = Machine->pens[color | 1];
 back = Machine->pens[color ];
 x = (offset >> 8) << 3;
 y = 255 - (offset & 0xff);
 if (flip_screen_x)
 {
  x = 255 - x;
  y = 255 - y;
  dx = -1;
 }
 for (i = 0; i < 8; i++)
 {
  plot_pixel(Machine->scrbitmap, x, y, (data & 1) ? fore : back);
  x += dx;
  data >>= 1;
 }
}

canonical_original_code:
static void common_videoram_w(int offset, int data, int color)
{
 int i; int x; int y; int fore; int back;
 int dx = 1;
 videoram[offset] = data;
 colorram[offset] = color;
 fore = Machine->pens[color | 1];
 back = Machine->pens[color ];
 x = (offset >> 8) << 3;
 y = 255 - (offset & 0xff);
 if (flip_screen_x)
 {
  x = 255 - x;
  y = 255 - y;
  dx = -1;
 }
 for (i = 0; i < 8; i++)
 {
  plot_pixel(Machine->scrbitmap, x, y, (data & 1) ? fore : back);
  x += dx;
  data >>= 1;
 }
}

variable_types: offset int

variable_types: data int

variable_types: color int

variable_types: x int

variable_types: y int

variable_types: fore int

variable_types: back int

variable_types: dx int


original_code:
void vicdual_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 static unsigned char bw_color_prom[] =
 {
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
 };
 if (color_prom == 0) color_prom = bw_color_prom;
 for (i = 0;i < Machine->drv->total_colors / 2;i++)
 {
  int bit;
  bit = (*color_prom >> 3) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 1) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 2) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 7) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 5) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 6) & 0x01;
  *(palette++) = 0xff * bit;
  color_prom++;
 }
 palette_bank = 0;
 {
  extern struct GameDriver driver_heiankyo;
  extern struct GameDriver driver_invinco;
  extern struct GameDriver driver_digger;
  extern struct GameDriver driver_tranqgun;
  if (Machine->gamedrv == &driver_heiankyo)
   palette_bank = 3;
  if (Machine->gamedrv == &driver_invinco ||
    Machine->gamedrv == &driver_digger ||
    Machine->gamedrv == &driver_tranqgun)
   palette_bank = 1;
 }
}

canonical_original_code:
void vicdual_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 static unsigned char bw_color_prom[] = {
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
 };
 if (color_prom == 0) color_prom = bw_color_prom;
 for (i = 0;i < Machine->drv->total_colors / 2;i++)
 {
  int bit;
  bit = (*color_prom >> 3) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 1) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 2) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 7) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 5) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 6) & 0x01;
  *(palette++) = 0xff * bit;
  color_prom++;
 }
 palette_bank = 0;
 {
  extern struct GameDriver driver_heiankyo;
  extern struct GameDriver driver_invinco;
  extern struct GameDriver driver_digger;
  extern struct GameDriver driver_tranqgun;
  if (Machine->gamedrv == &driver_heiankyo)
   palette_bank = 3;
  if (Machine->gamedrv == &driver_invinco ||
    Machine->gamedrv == &driver_digger ||
    Machine->gamedrv == &driver_tranqgun)
   palette_bank = 1;
 }
}

variable_types:
palette
unsigned char *

variable_types: bit int

variable_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver { struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); } *memory_read; struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; } *memory_write; struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); } *port_read; struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); } *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; } cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle { int min_x; int min_y; } default_visible_area; struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; } *gfxlayout; int color_codes_start; int total_color_codes; } *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound { int sound_type; void *sound_interface; } sound[5]; void (*nvram_handler)(void *file, int read_or_write); } *drv; struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; } *input_ports; void (*driver_init)(); struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *rom; unsigned int flags; }

user_defined_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver *drv; struct InputPortTiny *input_ports; void (*driver_init)(); struct RomModule *rom; unsigned int flags; }

user_defined_types: struct MachineDriver { struct MachineCPU cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle default_visible_area; struct GfxDecodeInfo *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound sound[5]; void (*nvram_handler)(void *file, int read_or_write); }

user_defined_types: struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress *memory_read; struct MemoryWriteAddress *memory_write; struct IOReadPort *port_read; struct IOWritePort *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; }

user_defined_types: struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout *gfxlayout; int color_codes_start; int total_color_codes; }


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

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

original_code:
data_t vicdual_characterram_r(offs_t offset)
{
 return vicdual_characterram[offset];
}

canonical_original_code:
unsigned int vicdual_characterram_r(unsigned int offset)
{
 return vicdual_characterram[offset];
}

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall samurai_protection_w(__int64 a1, int a2)
{
protection_data = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
protection_data = a2;
}

original_code:
static void samurai_protection_w(offs_t offset,data_t data)
{
 protection_data = data;
}

canonical_original_code:
static void samurai_protection_w(unsigned int offset, unsigned int data)
{
 protection_data = data;
}

variable_types:
data
unsigned int


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

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

original_code:
static data_t vicdual_ram_r(offs_t offset)
{
 return vicdual_ram[offset];
}

canonical_original_code:
static unsigned int vicdual_ram_r(unsigned int offset)
{
 return vicdual_ram[offset];
}


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

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

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

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

original_code:
void vicdual_palette_bank_w(offs_t offset,data_t data)
{
 if (palette_bank != (data & 3))
 {
  palette_bank = data & 3;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void vicdual_palette_bank_w(unsigned int offset, unsigned int data)
{
 if (palette_bank != (data & 3))
 {
  palette_bank = data & 3;
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
__int64 depthch_input_port_1_r()
{
char v0; // bl

v0 = input_port_1_r(0LL);
return v0 & 0xFE | ((int)cpu_getscanline() >> 6) & 1u;
}

canonical_decompiled_code:
__int64 func6()
{
char v0; // bl

v0 = input_port_1_r(0LL);
return v0 & 0xFE | ((int)cpu_getscanline() >> 6) & 1u;
}

original_code:
static data_t depthch_input_port_1_r(offs_t offset)
{
 return (input_port_1_r(0) & 0xfe) | ((cpu_getscanline() >> 6) & 0x01);
}

canonical_original_code:
static unsigned int depthch_input_port_1_r(unsigned int offset)
{
 return (input_port_1_r(0) & 0xfe) | ((cpu_getscanline() >> 6) & 0x01);
}


decompiled_code:
void *vicdual_decode()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x4000), (const void *)v0, 0x4000uLL);
}

canonical_decompiled_code:
void *func7()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x4000), (const void *)v0, 0x4000uLL);
}

original_code:
static void vicdual_decode(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memcpy(&RAM[0x4000],&RAM[0x0000],0x4000);
}

canonical_original_code:
static void vicdual_decode()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memcpy(&RAM[0x4000],&RAM[0x0000],0x4000);
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *init_depthch()
{
install_port_read_handler(0LL, 8LL, 8LL, depthch_input_port_1_r);
install_port_write_handler(0LL, 4LL, 4LL, &depthch_sh_port1_w);
qword_6F8 = (__int64)&depthch_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func8()
{
install_port_read_handler(0LL, 8LL, 8LL, depthch_input_port_1_r);
install_port_write_handler(0LL, 4LL, 4LL, &depthch_sh_port1_w);
qword_6F8 = (__int64)&depthch_sample_names;
return func7();
}

original_code:
static void init_depthch(void)
{
 install_port_read_handler(0, 0x08, 0x08, depthch_input_port_1_r);
 install_port_write_handler(0, 0x04, 0x04, depthch_sh_port1_w);
 samples_interface.samplenames = depthch_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_depthch()
{
 install_port_read_handler(0, 0x08, 0x08, depthch_input_port_1_r);
 install_port_write_handler(0, 0x04, 0x04, depthch_sh_port1_w);
 samples_interface.samplenames = depthch_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_nosamples()
{
qword_6F8 = 0LL;
return vicdual_decode();
}

canonical_decompiled_code:
void *func9()
{
qword_6F8 = 0LL;
return func7();
}

original_code:
static void init_nosamples(void)
{
 samples_interface.samplenames = 0;
 vicdual_decode();
}

canonical_original_code:
static void init_nosamples()
{
 samples_interface.samplenames = 0;
 vicdual_decode();
}


decompiled_code:
void *init_invinco()
{
install_port_write_handler(0LL, 2LL, 2LL, &invinco_sh_port2_w);
qword_6F8 = (__int64)&invinco_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func10()
{
install_port_write_handler(0LL, 2LL, 2LL, &invinco_sh_port2_w);
qword_6F8 = (__int64)&invinco_sample_names;
return func7();
}

original_code:
static void init_invinco(void)
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_invinco()
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}


decompiled_code:
// attributes: thunk
void *init_invho2()
{
return init_invinco();
}

canonical_decompiled_code:
void *func11()
{
return func10();
}

original_code:
static void init_invho2(void)
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_invho2()
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_invds()
{
install_port_write_handler(0LL, 1LL, 1LL, &invinco_sh_port2_w);
qword_6F8 = (__int64)&invinco_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func12()
{
install_port_write_handler(0LL, 1LL, 1LL, &invinco_sh_port2_w);
qword_6F8 = (__int64)&invinco_sample_names;
return func7();
}

original_code:
static void init_invds(void)
{
 install_port_write_handler(0, 0x01, 0x01, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_invds()
{
 install_port_write_handler(0, 0x01, 0x01, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_carnival()
{
install_port_write_handler(0LL, 1LL, 1LL, &carnival_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &carnival_sh_port2_w);
qword_6F8 = (__int64)&carnival_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func13()
{
install_port_write_handler(0LL, 1LL, 1LL, &carnival_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &carnival_sh_port2_w);
qword_6F8 = (__int64)&carnival_sample_names;
return func7();
}

original_code:
static void init_carnival(void)
{
 install_port_write_handler(0, 0x01, 0x01, carnival_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, carnival_sh_port2_w);
 samples_interface.samplenames = carnival_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_carnival()
{
 install_port_write_handler(0, 0x01, 0x01, carnival_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, carnival_sh_port2_w);
 samples_interface.samplenames = carnival_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_pulsar()
{
install_port_write_handler(0LL, 1LL, 1LL, &pulsar_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &pulsar_sh_port2_w);
qword_6F8 = (__int64)&pulsar_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func14()
{
install_port_write_handler(0LL, 1LL, 1LL, &pulsar_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &pulsar_sh_port2_w);
qword_6F8 = (__int64)&pulsar_sample_names;
return func7();
}

original_code:
static void init_pulsar(void)
{
 install_port_write_handler(0, 0x01, 0x01, pulsar_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, pulsar_sh_port2_w);
 samples_interface.samplenames = pulsar_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_pulsar()
{
 install_port_write_handler(0, 0x01, 0x01, pulsar_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, pulsar_sh_port2_w);
 samples_interface.samplenames = pulsar_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_samurai()
{
install_mem_write_handler(0LL, 32512LL, 32512LL, samurai_protection_w);
install_port_read_handler(0LL, 1LL, 3LL, samurai_input_r);
qword_6F8 = 0LL;
return vicdual_decode();
}

canonical_decompiled_code:
void *func15()
{
install_mem_write_handler(0LL, 32512LL, 32512LL, samurai_protection_w);
install_port_read_handler(0LL, 1LL, 3LL, samurai_input_r);
qword_6F8 = 0LL;
return func7();
}

original_code:
static void init_samurai(void)
{
 install_mem_write_handler(0, 0x7f00, 0x7f00, samurai_protection_w);
 install_port_read_handler(0, 0x01, 0x03, samurai_input_r);
 samples_interface.samplenames = 0;
 vicdual_decode();
}

canonical_original_code:
static void init_samurai()
{
 install_mem_write_handler(0, 0x7f00, 0x7f00, samurai_protection_w);
 install_port_read_handler(0, 0x01, 0x03, samurai_input_r);
 samples_interface.samplenames = 0;
 vicdual_decode();
}


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

if ( protection_data == 171 )
{
v1 = (2 >> a1) & 2;
}
else
{
v1 = 0;
if ( protection_data == 29 )
v1 = (12 >> a1) & 2;
}
return v1 | (unsigned int)(readinputport((unsigned int)(a1 + 1)) & 0xFD);
}

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

if ( protection_data == 171 )
{
v1 = (2 >> a1) & 2;
}
else
{
v1 = 0;
if ( protection_data == 29 )
v1 = (12 >> a1) & 2;
}
return v1 | (unsigned int)(readinputport((unsigned int)(a1 + 1)) & 0xFD);
}

original_code:
static data_t samurai_input_r(offs_t offset)
{
 int answer = 0;
 if (protection_data == 0xab) answer = 0x02;
 else if (protection_data == 0x1d) answer = 0x0c;
 return (readinputport(1 + offset) & 0xfd) | ((answer >> offset) & 0x02);
}

canonical_original_code:
static unsigned int samurai_input_r(unsigned int offset)
{
 int answer = 0;
 if (protection_data == 0xab) answer = 0x02;
 else if (protection_data == 0x1d) answer = 0x0c;
 return (readinputport(1 + offset) & 0xfd) | ((answer >> offset) & 0x02);
}

variable_types: answer int


decompiled_code:
__int64 __fastcall bladestl_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5; // ecx
__int64 v6; // rdi
__int64 i; // rdx

result = a2;
v5 = *(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 24LL);
if ( v5 > 0 )
{
v6 = result + 2LL * *(int *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 40LL);
for ( i = 0LL; i != v5; ++i )
{
result = (*(_BYTE *)(a3 + i) & 0xFu) + 32;
*(_WORD *)(v6 + 2 * i) = (*(_BYTE *)(a3 + i) & 0xF) + 32;
}
}
return result;
}

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

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

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void bladestl_port_A_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


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

layer_colorbase = 0x100000000LL;
v0 = K007342_vh_start(0LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

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

layer_colorbase = 0x100000000LL;
v0 = K007342_vh_start(0LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int bladestl_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 1;
 if (K007342_vh_start(0,tile_callback))
 {
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int bladestl_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 1;
 if (K007342_vh_start(0,tile_callback))
 {
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 bladestl_vh_stop()
{
K007342_vh_stop();
return K007420_vh_stop();
}

original_code:
void bladestl_vh_stop(void)
{
 K007342_vh_stop();
 K007420_vh_stop();
}

canonical_original_code:
void bladestl_vh_stop()
{
 K007342_vh_stop();
 K007420_vh_stop();
}


decompiled_code:
__int64 __fastcall bladestl_vh_screenrefresh(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 1LL, 16LL);
K007420_sprites_draw(a1);
K007342_tilemap_draw(a1, 1LL, 17LL);
K007342_tilemap_draw(a1, 0LL, 0LL);
return K007342_tilemap_draw(a1, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 1LL, 16LL);
K007420_sprites_draw(a1);
K007342_tilemap_draw(a1, 1LL, 17LL);
K007342_tilemap_draw(a1, 0LL, 0LL);
return K007342_tilemap_draw(a1, 0LL, 1LL);
}

original_code:
void bladestl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 1, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 1, 1 | 0x10 );
 K007342_tilemap_draw( bitmap, 0, 0 );
 K007342_tilemap_draw( bitmap, 0, 1 );
}

canonical_original_code:
void bladestl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 1, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 1, 1 | 0x10 );
 K007342_tilemap_draw( bitmap, 0, 0 );
 K007342_tilemap_draw( bitmap, 0, 1 );
}

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


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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( !(unsigned int)K007342_is_INT_enabled() )
return ignore_interrupt();
result = 2LL;
}
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( !(unsigned int)K007342_is_INT_enabled() )
return ignore_interrupt();
result = 2LL;
}
return result;
}

original_code:
static int bladestl_interrupt( void )
{
 if (cpu_getiloops() == 0){
  if (K007342_is_INT_enabled())
   return 2;
 }
 else if (cpu_getiloops() % 2){
  return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int bladestl_interrupt()
{
 if (cpu_getiloops() == 0){
  if (K007342_is_INT_enabled())
   return 2;
 }
 else if (cpu_getiloops() % 2){
  return nmi_interrupt();
 }
 return ignore_interrupt();
}


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

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

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

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


decompiled_code:
void bladestl_speech_ctrl_w()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

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

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


decompiled_code:
void bladestl_port_B_w()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

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

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


decompiled_code:
__int64 __fastcall sprite_callback(int *a1, int *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *a1 | (bladestl_spritebank + ((4 * (unsigned __int16)*a2) & 0x300));
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 &= 0xFu;
return result;
}

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

v2 = *a1 | (bladestl_spritebank + ((4 * (unsigned __int16)*a2) & 0x300));
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 &= 0xFu;
return result;
}

original_code:
static void sprite_callback(int *code,int *color)
{
 *code |= ((*color & 0xc0) << 2) + bladestl_spritebank;
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0 + (*color & 0x0f);
}

canonical_original_code:
static void sprite_callback(int *code, int *color)
{
 *code |= ((*color & 0xc0) << 2) + bladestl_spritebank;
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0 + (*color & 0x0f);
}

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
__int64 __fastcall trackball_r(int a1)
{
int v1; // eax
int v2; // edx

v1 = readinputport((unsigned int)(a1 + 5));
v2 = v1 - last_0[a1];
last_0[a1] = v1;
return v2 & 0x80 | (unsigned int)(v1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // eax
int v2; // edx

v1 = readinputport((unsigned int)(a1 + 5));
v2 = v1 - last_0[a1];
last_0[a1] = v1;
return v2 & 0x80 | (unsigned int)(v1 >> 1);
}

original_code:
static data_t trackball_r(offs_t offset)
{
 static int last[4];
 int curr,delta;
 curr = readinputport(5 + offset);
 delta = (curr - last[offset]) & 0xff;
 last[offset] = curr;
 return (delta & 0x80) | (curr >> 1);
}

canonical_original_code:
static unsigned int trackball_r(unsigned int offset)
{
 static int last[4];
 int curr; int delta;
 curr = readinputport(5 + offset);
 delta = (curr - last[offset]) & 0xff;
 last[offset] = curr;
 return (delta & 0x80) | (curr >> 1);
}

variable_types:
last
int [4]

variable_types: curr int

variable_types: delta int


original_code:
void royalmah_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void royalmah_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}


decompiled_code:
__int64 __fastcall royalmah_videoram_w(unsigned int a1, char a2)
{
unsigned int v2; // ebx
unsigned int v3; // er14
unsigned int v4; // ebp
unsigned __int8 v5; // r15
unsigned int v6; // er13
__int64 v7; // rsi
int v8; // edi
int v9; // edx
int v10; // eax
__int64 result; // rax

v2 = (unsigned __int8)(a1 >> 6);
*(_BYTE *)(videoram + a1) = a2;
v3 = *(unsigned __int8 *)(videoram + (a1 & 0x3FFF));
v4 = (unsigned __int8)(4 * a1);
v5 = *(_BYTE *)(videoram + (a1 | 0x4000));
v6 = v4 + 4;
do
{
v7 = v4++;
v8 = (4 * v5) & 4;
v9 = ((int)v5 >> 1) & 8;
v5 >>= 1;
v10 = v8 | (v3 >> 3) & 2;
LOBYTE(v8) = v3;
LOBYTE(v3) = (unsigned __int8)v3 >> 1;
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
v7,
v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v9 | v8 & 1 | v10)));
}
while ( v6 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
unsigned int v2; // ebx
unsigned int v3; // er14
unsigned int v4; // ebp
unsigned __int8 v5; // r15
unsigned int v6; // er13
__int64 v7; // rsi
int v8; // edi
int v9; // edx
int v10; // eax
__int64 result; // rax

v2 = (unsigned __int8)(a1 >> 6);
*(_BYTE *)(videoram + a1) = a2;
v3 = *(unsigned __int8 *)(videoram + (a1 & 0x3FFF));
v4 = (unsigned __int8)(4 * a1);
v5 = *(_BYTE *)(videoram + (a1 | 0x4000));
v6 = v4 + 4;
do
{
v7 = v4++;
v8 = (4 * v5) & 4;
v9 = ((int)v5 >> 1) & 8;
v5 >>= 1;
v10 = v8 | (v3 >> 3) & 2;
LOBYTE(v8) = v3;
LOBYTE(v3) = (unsigned __int8)v3 >> 1;
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
v7,
v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v9 | v8 & 1 | v10)));
}
while ( v6 != v4 );
return result;
}

original_code:
void royalmah_videoram_w(offs_t offset,data_t data)
{
 int i;
 UINT8 x, y;
 UINT8 col1, col2;
 videoram[offset] = data;
 col1 = videoram[offset & 0x3fff];
 col2 = videoram[offset | 0x4000];
 y = (offset >> 6);
 x = (offset & 0x3f) << 2;
 for (i = 0; i < 4; i++)
 {
  int col = ((col1 & 0x01) >> 0) | ((col1 & 0x10) >> 3) | ((col2 & 0x01) << 2) | ((col2 & 0x10) >> 1);
  plot_pixel(Machine->scrbitmap, x+i, y, Machine->pens[col]);
  col1 >>= 1;
  col2 >>= 1;
 }
}

canonical_original_code:
void royalmah_videoram_w(unsigned int offset, unsigned int data)
{
 int i;
 unsigned char x; unsigned char y;
 unsigned char col1; unsigned char col2;
 videoram[offset] = data;
 col1 = videoram[offset & 0x3fff];
 col2 = videoram[offset | 0x4000];
 y = (offset >> 6);
 x = (offset & 0x3f) << 2;
 for (i = 0; i < 4; i++)
 {
  int col = ((col1 & 0x01) >> 0) | ((col1 & 0x10) >> 3) | ((col2 & 0x01) << 2) | ((col2 & 0x10) >> 1);
  plot_pixel(Machine->scrbitmap, x+i, y, Machine->pens[col]);
  col1 >>= 1;
  col2 >>= 1;
 }
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types: col int


decompiled_code:
void royalmah_rom_w()
{
;
}

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

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


decompiled_code:
void __fastcall royalmah_input_port_select_w(__int64 a1, int a2)
{
royalmah_input_port_select = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
royalmah_input_port_select = a2;
}

original_code:
static void royalmah_input_port_select_w(offs_t offset,data_t data)
{
 royalmah_input_port_select = data;
}

canonical_original_code:
static void royalmah_input_port_select_w(unsigned int offset, unsigned int data)
{
 royalmah_input_port_select = data;
}


decompiled_code:
__int64 __fastcall royalmah_player_2_port_r(unsigned int a1)
{
int v1; // er12
char v2; // al
unsigned int v3; // er12

v1 = (unsigned __int8)((__int64 (*)(void))input_port_5_r)();
v2 = royalmah_input_port_select;
v3 = v1 | 0x3F;
if ( (royalmah_input_port_select & 1) != 0 )
{
if ( (royalmah_input_port_select & 2) != 0 )
goto LABEL_3;
}
else
{
v3 &= input_port_5_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 2) != 0 )
{
LABEL_3:
if ( (v2 & 4) != 0 )
goto LABEL_4;
goto LABEL_9;
}
}
v3 &= input_port_6_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 4) != 0 )
{
LABEL_4:
if ( (v2 & 8) != 0 )
goto LABEL_5;
LABEL_10:
v3 &= input_port_8_r(a1);
if ( (royalmah_input_port_select & 0x10) != 0 )
return v3;
return (unsigned int)input_port_9_r(a1) & v3;
}
LABEL_9:
v3 &= input_port_7_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 8) == 0 )
goto LABEL_10;
LABEL_5:
if ( (v2 & 0x10) != 0 )
return v3;
return (unsigned int)input_port_9_r(a1) & v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v1; // er12
char v2; // al
unsigned int v3; // er12

v1 = (unsigned __int8)((__int64 (*)(void))input_port_5_r)();
v2 = royalmah_input_port_select;
v3 = v1 | 0x3F;
if ( (royalmah_input_port_select & 1) != 0 )
{
if ( (royalmah_input_port_select & 2) != 0 )
goto LABEL_3;
}
else
{
v3 &= input_port_5_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 2) != 0 )
{
LABEL_3:
if ( (v2 & 4) != 0 )
goto LABEL_4;
goto LABEL_9;
}
}
v3 &= input_port_6_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 4) != 0 )
{
LABEL_4:
if ( (v2 & 8) != 0 )
goto LABEL_5;
LABEL_10:
v3 &= input_port_8_r(a1);
if ( (royalmah_input_port_select & 0x10) != 0 )
return v3;
return (unsigned int)input_port_9_r(a1) & v3;
}
LABEL_9:
v3 &= input_port_7_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 8) == 0 )
goto LABEL_10;
LABEL_5:
if ( (v2 & 0x10) != 0 )
return v3;
return (unsigned int)input_port_9_r(a1) & v3;
}

original_code:
static data_t royalmah_player_2_port_r(offs_t offset)
{
 int ret = (input_port_5_r(offset) & 0xc0) | 0x3f;
 if ((royalmah_input_port_select & 0x01) == 0) ret &= input_port_5_r(offset);
 if ((royalmah_input_port_select & 0x02) == 0) ret &= input_port_6_r(offset);
 if ((royalmah_input_port_select & 0x04) == 0) ret &= input_port_7_r(offset);
 if ((royalmah_input_port_select & 0x08) == 0) ret &= input_port_8_r(offset);
 if ((royalmah_input_port_select & 0x10) == 0) ret &= input_port_9_r(offset);
 return ret;
}

canonical_original_code:
static unsigned int royalmah_player_2_port_r(unsigned int offset)
{
 int ret = (input_port_5_r(offset) & 0xc0) | 0x3f;
 if ((royalmah_input_port_select & 0x01) == 0) ret &= input_port_5_r(offset);
 if ((royalmah_input_port_select & 0x02) == 0) ret &= input_port_6_r(offset);
 if ((royalmah_input_port_select & 0x04) == 0) ret &= input_port_7_r(offset);
 if ((royalmah_input_port_select & 0x08) == 0) ret &= input_port_8_r(offset);
 if ((royalmah_input_port_select & 0x10) == 0) ret &= input_port_9_r(offset);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall royalmah_player_1_port_r(unsigned int a1)
{
int v1; // er12
char v2; // al
unsigned int v3; // er12

v1 = (unsigned __int8)((__int64 (*)(void))input_port_0_r)();
v2 = royalmah_input_port_select;
v3 = v1 | 0x3F;
if ( (royalmah_input_port_select & 1) != 0 )
{
if ( (royalmah_input_port_select & 2) != 0 )
goto LABEL_3;
}
else
{
v3 &= input_port_0_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 2) != 0 )
{
LABEL_3:
if ( (v2 & 4) != 0 )
goto LABEL_4;
goto LABEL_9;
}
}
v3 &= input_port_1_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 4) != 0 )
{
LABEL_4:
if ( (v2 & 8) != 0 )
goto LABEL_5;
LABEL_10:
v3 &= input_port_3_r(a1);
if ( (royalmah_input_port_select & 0x10) != 0 )
return v3;
return (unsigned int)input_port_4_r(a1) & v3;
}
LABEL_9:
v3 &= input_port_2_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 8) == 0 )
goto LABEL_10;
LABEL_5:
if ( (v2 & 0x10) != 0 )
return v3;
return (unsigned int)input_port_4_r(a1) & v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
int v1; // er12
char v2; // al
unsigned int v3; // er12

v1 = (unsigned __int8)((__int64 (*)(void))input_port_0_r)();
v2 = royalmah_input_port_select;
v3 = v1 | 0x3F;
if ( (royalmah_input_port_select & 1) != 0 )
{
if ( (royalmah_input_port_select & 2) != 0 )
goto LABEL_3;
}
else
{
v3 &= input_port_0_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 2) != 0 )
{
LABEL_3:
if ( (v2 & 4) != 0 )
goto LABEL_4;
goto LABEL_9;
}
}
v3 &= input_port_1_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 4) != 0 )
{
LABEL_4:
if ( (v2 & 8) != 0 )
goto LABEL_5;
LABEL_10:
v3 &= input_port_3_r(a1);
if ( (royalmah_input_port_select & 0x10) != 0 )
return v3;
return (unsigned int)input_port_4_r(a1) & v3;
}
LABEL_9:
v3 &= input_port_2_r(a1);
v2 = royalmah_input_port_select;
if ( (royalmah_input_port_select & 8) == 0 )
goto LABEL_10;
LABEL_5:
if ( (v2 & 0x10) != 0 )
return v3;
return (unsigned int)input_port_4_r(a1) & v3;
}

original_code:
static data_t royalmah_player_1_port_r(offs_t offset)
{
 int ret = (input_port_0_r(offset) & 0xc0) | 0x3f;
 if ((royalmah_input_port_select & 0x01) == 0) ret &= input_port_0_r(offset);
 if ((royalmah_input_port_select & 0x02) == 0) ret &= input_port_1_r(offset);
 if ((royalmah_input_port_select & 0x04) == 0) ret &= input_port_2_r(offset);
 if ((royalmah_input_port_select & 0x08) == 0) ret &= input_port_3_r(offset);
 if ((royalmah_input_port_select & 0x10) == 0) ret &= input_port_4_r(offset);
 return ret;
}

canonical_original_code:
static unsigned int royalmah_player_1_port_r(unsigned int offset)
{
 int ret = (input_port_0_r(offset) & 0xc0) | 0x3f;
 if ((royalmah_input_port_select & 0x01) == 0) ret &= input_port_0_r(offset);
 if ((royalmah_input_port_select & 0x02) == 0) ret &= input_port_1_r(offset);
 if ((royalmah_input_port_select & 0x04) == 0) ret &= input_port_2_r(offset);
 if ((royalmah_input_port_select & 0x08) == 0) ret &= input_port_3_r(offset);
 if ((royalmah_input_port_select & 0x10) == 0) ret &= input_port_4_r(offset);
 return ret;
}


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

tile_info[5] = (*a4 >> 1) & 1;
v4 = 0;
if ( a1 == 2 )
v4 = (*a4 >> 5) & 1;
tile_info[6] = v4;
*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0xE00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

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

tile_info[5] = (*a4 >> 1) & 1;
v4 = 0;
if ( a1 == 2 )
v4 = (*a4 >> 5) & 1;
tile_info[6] = v4;
*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0xE00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

original_code:
static void mainevt_tile_callback(int layer,int bank,int *code,int *color)
{
 tile_info.flags = (*color & 0x02) ? 0x01 : 0;
 if (layer == 2) tile_info.priority = (*color & 0x20) >> 5;
 else tile_info.priority = 0;
 *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

canonical_original_code:
static void mainevt_tile_callback(int layer, int bank, int *code, int *color)
{
 tile_info.flags = (*color & 0x02) ? 0x01 : 0;
 if (layer == 2) tile_info.priority = (*color & 0x20) >> 5;
 else tile_info.priority = 0;
 *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

variable_types: layer int

variable_types: bank int


decompiled_code:
__int64 __fastcall dv_tile_callback(int a1, __int64 a2, _DWORD *a3, int *a4)
{
__int64 result; // rax

*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0x1E00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0x1E00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

original_code:
static void dv_tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x01) << 8) | ((*color & 0x3c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

canonical_original_code:
static void dv_tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x01) << 8) | ((*color & 0x3c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}


decompiled_code:
void __fastcall dv_nmienable_w(__int64 a1, int a2)
{
nmi_enable = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
nmi_enable = a2;
}

original_code:
static void dv_nmienable_w(offs_t offset,data_t data)
{
 nmi_enable = data;
}

canonical_original_code:
static void dv_nmienable_w(unsigned int offset, unsigned int data)
{
 nmi_enable = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

dword_6C0 = 4;
layer_colorbase = 0x800000000LL;
sprite_colorbase = 12;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, mainevt_tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, mainevt_sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

dword_6C0 = 4;
layer_colorbase = 0x800000000LL;
sprite_colorbase = 12;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, mainevt_tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, mainevt_sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int mainevt_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 8;
 layer_colorbase[2] = 4;
 sprite_colorbase = 12;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,mainevt_tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,mainevt_sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int mainevt_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 8;
 layer_colorbase[2] = 4;
 sprite_colorbase = 12;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,mainevt_tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,mainevt_sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


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

layer_colorbase = 0LL;
dword_6C0 = 4;
sprite_colorbase = 8;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, dv_tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, dv_sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

layer_colorbase = 0LL;
dword_6C0 = 4;
sprite_colorbase = 8;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, dv_tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, dv_sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int dv_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 4;
 sprite_colorbase = 8;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,dv_tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,dv_sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int dv_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 4;
 sprite_colorbase = 8;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,dv_tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,dv_sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 mainevt_vh_stop()
{
K052109_vh_stop();
return K051960_vh_stop();
}

original_code:
void mainevt_vh_stop(void)
{
 K052109_vh_stop();
 K051960_vh_stop();
}

canonical_original_code:
void mainevt_vh_stop()
{
 K052109_vh_stop();
 K051960_vh_stop();
}


decompiled_code:
__int64 __fastcall mainevt_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 65552LL);
K052109_tilemap_draw(a1, 2LL, 131073LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
K052109_tilemap_draw(a1, 0LL, 0x80000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
K052109_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 65552LL);
K052109_tilemap_draw(a1, 2LL, 131073LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
K052109_tilemap_draw(a1, 0LL, 0x80000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

original_code:
void mainevt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 K052109_tilemap_draw(bitmap,1,0x10|(1<<16));
 K052109_tilemap_draw(bitmap,2,1|(2<<16));
 K052109_tilemap_draw(bitmap,2,0|(4<<16));
 K052109_tilemap_draw(bitmap,0,8<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

canonical_original_code:
void mainevt_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 K052109_tilemap_draw(bitmap,1,0x10|(1<<16));
 K052109_tilemap_draw(bitmap,2,1|(2<<16));
 K052109_tilemap_draw(bitmap,2,0|(4<<16));
 K052109_tilemap_draw(bitmap,0,8<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

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


decompiled_code:
__int64 __fastcall dv_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K052109_tilemap_draw(a1, 1LL, 16LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
K052109_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K052109_tilemap_draw(a1, 1LL, 16LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

original_code:
void dv_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 K052109_tilemap_draw(bitmap,1,0x10);
 K052109_tilemap_draw(bitmap,2,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,0,0);
}

canonical_original_code:
void dv_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 K052109_tilemap_draw(bitmap,1,0x10);
 K052109_tilemap_draw(bitmap,2,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,0,0);
}


decompiled_code:
__int64 __fastcall mainevt_bankswitch_w(__int64 a1, char a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 3u) + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
return K052109_set_RMRD_line((a2 & 0x40) != 0);
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 3u) + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
return K052109_set_RMRD_line((a2 & 0x40) != 0);
}

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

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

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


decompiled_code:
__int64 __fastcall mainevt_coin_w(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 0x10);
coin_counter_w(1LL, a2 & 0x20);
osd_led_w(0LL, a2);
osd_led_w(1LL, a2 >> 1);
osd_led_w(2LL, a2 >> 2);
return osd_led_w(3LL, a2 >> 3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 0x10);
coin_counter_w(1LL, a2 & 0x20);
osd_led_w(0LL, a2);
osd_led_w(1LL, a2 >> 1);
osd_led_w(2LL, a2 >> 2);
return osd_led_w(3LL, a2 >> 3);
}

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

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


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

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

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

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


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

if ( (a2 & 2) != 0 )
{
if ( (a2 & 1) != 0 )
UPD7759_start_w(0LL, 0LL);
result = interrupt_enable_w(0LL, a2 & 4);
}
else
{
UPD7759_reset_w(0LL, (a2 >> 1) & 1);
result = interrupt_enable_w(0LL, a2 & 4);
}
return result;
}

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

if ( (a2 & 2) != 0 )
{
if ( (a2 & 1) != 0 )
UPD7759_start_w(0LL, 0LL);
result = interrupt_enable_w(0LL, a2 & 4);
}
else
{
UPD7759_reset_w(0LL, (a2 >> 1) & 1);
result = interrupt_enable_w(0LL, a2 & 4);
}
return result;
}

original_code:
void mainevt_sh_irqcontrol_w(offs_t offset,data_t data)
{
  if ((data & 0x02) == 0)
  {
   UPD7759_reset_w(0,(data & 0x02) >> 1);
  }
 else if ((data & 0x01))
  {
  UPD7759_start_w(0,0);
  }
 interrupt_enable_w(0,data & 4);
}

canonical_original_code:
void mainevt_sh_irqcontrol_w(unsigned int offset, unsigned int data)
{
  if ((data & 0x02) == 0)
  {
   UPD7759_reset_w(0,(data & 0x02) >> 1);
  }
 else if ((data & 0x01))
  {
  UPD7759_start_w(0,0);
  }
 interrupt_enable_w(0,data & 4);
}


decompiled_code:
__int64 __fastcall devstor_sh_irqcontrol_w(__int64 a1, char a2)
{
return interrupt_enable_w(0LL, a2 & 4);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, char a2)
{
return interrupt_enable_w(0LL, a2 & 4);
}

original_code:
void devstor_sh_irqcontrol_w(offs_t offset,data_t data)
{
interrupt_enable_w(0,data & 4);
}

canonical_original_code:
void devstor_sh_irqcontrol_w(unsigned int offset, unsigned int data)
{
interrupt_enable_w(0,data & 4);
}


original_code:
void dv_sh_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A,bank_B;
 bank_A=0x20000 * (data&0x3);
 bank_B=0x20000 * ((data>>2)&0x3);
 K007232_bankswitch(0,RAM+bank_A,RAM+bank_B);
}

canonical_original_code:
void dv_sh_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A; int bank_B;
 bank_A=0x20000 * (data&0x3);
 bank_B=0x20000 * ((data>>2)&0x3);
 K007232_bankswitch(0,RAM+bank_A,RAM+bank_B);
}


decompiled_code:
void *__fastcall mainevt_sh_bankswitch_w(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbp
void *v4; // rax

v2 = memory_region(146LL);
K007232_bankswitch(0LL, v2 + ((a2 << 17) & 0x60000), v2 + ((a2 << 15) & 0x60000));
v3 = memory_region(147LL);
v4 = (void *)memory_region(147LL);
return memcpy(v4, (const void *)(v3 + ((((a2 >> 4) & 3) + 1) << 17)), 0x20000uLL);
}

original_code:
void mainevt_sh_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *src,*dest;
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A,bank_B;
 bank_A=0x20000 * (data&0x3);
 bank_B=0x20000 * ((data>>2)&0x3);
 K007232_bankswitch(0,RAM+bank_A,RAM+bank_B);
 src = &memory_region(REGION_SOUND2)[0x20000];
 dest = memory_region(REGION_SOUND2);
 memcpy(dest,&src[((data >> 4) & 0x03) * 0x20000],0x20000);
}

canonical_original_code:
void mainevt_sh_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *src; unsigned char *dest;
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A; int bank_B;
 bank_A=0x20000 * (data&0x3);
 bank_B=0x20000 * ((data>>2)&0x3);
 K007232_bankswitch(0,RAM+bank_A,RAM+bank_B);
 src = &memory_region(REGION_SOUND2)[0x20000];
 dest = memory_region(REGION_SOUND2);
 memcpy(dest,&src[((data >> 4) & 0x03) * 0x20000],0x20000);
}

variable_types:
src
unsigned char *

variable_types:
dest
unsigned char *


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

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

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

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


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int mainevt_interrupt(void)
{
 if (K052109_is_IRQ_enabled()) return 1;
 else return ignore_interrupt();
}

canonical_original_code:
static int mainevt_interrupt()
{
 if (K052109_is_IRQ_enabled()) return 1;
 else return ignore_interrupt();
}


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

if ( nmi_enable )
result = 4LL;
else
result = ignore_interrupt();
return result;
}

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

if ( nmi_enable )
result = 4LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int dv_interrupt(void)
{
 if (nmi_enable) return 4;
 else return ignore_interrupt();
}

canonical_original_code:
static int dv_interrupt()
{
 if (nmi_enable) return 4;
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall volume_callback(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

variable_types: v int


decompiled_code:
_BOOL8 __fastcall bagman_pal16r6_w(char a1, char a2)
{
__int64 v2; // rcx
_BOOL8 result; // rax

v2 = (unsigned __int8)(4 * a1);
result = (a2 & 1) == 0;
columnvalue[v2 + 1] = a2 & 1;
columnvalue[v2] = result;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1, char a2)
{
__int64 v2; // rcx
_BOOL8 result; // rax

v2 = (unsigned __int8)(4 * a1);
result = (a2 & 1) == 0;
columnvalue[v2 + 1] = a2 & 1;
columnvalue[v2] = result;
return result;
}

original_code:
void bagman_pal16r6_w(offs_t offset,data_t data)
{
unsigned char line;
 line = offset<<2;
 columnvalue[line] = 1-(data&1);
 columnvalue[line+1] = data&1;
}

canonical_original_code:
void bagman_pal16r6_w(unsigned int offset, unsigned int data)
{
unsigned char line;
 line = offset<<2;
 columnvalue[line] = 1-(data&1);
 columnvalue[line+1] = data&1;
}

variable_types:
line
unsigned char


original_code:
void bagman_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void bagman_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

result = flipscreen;
v3 = a2 & 1;
if ( v3 != flipscreen[a1] )
{
flipscreen[a1] = v3;
result = (int *)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = flipscreen;
v3 = a2 & 1;
if ( v3 != flipscreen[a1] )
{
flipscreen[a1] = v3;
result = (int *)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

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


decompiled_code:
void *__fastcall bagman_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rsi
char v4; // di
void *result; // rax
int v6; // ebp
__int64 v7; // rbx
char v8; // si
char v9; // al

if ( !*bagman_video_enable )
return (void *)fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(_QWORD *)(Machine + 528LL);
v4 = *(_BYTE *)(colorram + v2);
if ( !v3 || (v4 & 0x10) == 0 )
v3 = *(_QWORD *)(Machine + 512LL);
drawgfx(tmpbitmap, v3, *(unsigned __int8 *)(videoram + v2) + 8 * (v4 & 0x20u), v4 & 0xF);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6 + 3LL;
do
{
while ( 1 )
{
result = (void *)spriteram;
v8 = *(_BYTE *)(spriteram + v7 - 3);
if ( *(_BYTE *)(spriteram + v7 - 1) && *(_BYTE *)(spriteram + v7) )
break;
v7 -= 4LL;
v6 -= 4;
if ( v6 < 0 )
return result;
}
v9 = *(_BYTE *)(spriteram + v7 - 2);
v7 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), (v8 & 0x3F) + 2 * (v9 & 0x20u), v9 & 0x1F);
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rsi
char v4; // di
void *result; // rax
int v6; // ebp
__int64 v7; // rbx
char v8; // si
char v9; // al

if ( !*bagman_video_enable )
return (void *)fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(_QWORD *)(Machine + 528LL);
v4 = *(_BYTE *)(colorram + v2);
if ( !v3 || (v4 & 0x10) == 0 )
v3 = *(_QWORD *)(Machine + 512LL);
drawgfx(tmpbitmap, v3, *(unsigned __int8 *)(videoram + v2) + 8 * (v4 & 0x20u), v4 & 0xF);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6 + 3LL;
do
{
while ( 1 )
{
result = (void *)spriteram;
v8 = *(_BYTE *)(spriteram + v7 - 3);
if ( *(_BYTE *)(spriteram + v7 - 1) && *(_BYTE *)(spriteram + v7) )
break;
v7 -= 4LL;
v6 -= 4;
if ( v6 < 0 )
return result;
}
v9 = *(_BYTE *)(spriteram + v7 - 2);
v7 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), (v8 & 0x3F) + 2 * (v9 & 0x20u), v9 & 0x1F);
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

original_code:
void bagman_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (*bagman_video_enable == 0)
 {
  fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
  return;
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   int bank;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   if (flipscreen[0]) sx = 31 - sx;
   sy = offs / 32;
   if (flipscreen[1]) sy = 31 - sy;
   bank = 0;
   if (Machine->gfx[2] && (colorram[offs] & 0x10)) bank = 2;
   drawgfx(tmpbitmap,Machine->gfx[bank],
     videoram[offs] + 8 * (colorram[offs] & 0x20),
     colorram[offs] & 0x0f,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs + 2];
  flipx = spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  if (flipscreen[0])
  {
   sx = 240 - sx +1;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  if (spriteram[offs + 2] && spriteram[offs + 3])
   drawgfx(bitmap,Machine->gfx[1],
     (spriteram[offs] & 0x3f) + 2 * (spriteram[offs + 1] & 0x20),
     spriteram[offs + 1] & 0x1f,
     flipx,flipy,
     sx,sy+1,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void bagman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (*bagman_video_enable == 0)
 {
  fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
  return;
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   int bank;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   if (flipscreen[0]) sx = 31 - sx;
   sy = offs / 32;
   if (flipscreen[1]) sy = 31 - sy;
   bank = 0;
   if (Machine->gfx[2] && (colorram[offs] & 0x10)) bank = 2;
   drawgfx(tmpbitmap,Machine->gfx[bank],
     videoram[offs] + 8 * (colorram[offs] & 0x20),
     colorram[offs] & 0x0f,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs + 2];
  flipx = spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  if (flipscreen[0])
  {
   sx = 240 - sx +1;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  if (spriteram[offs + 2] && spriteram[offs + 3])
   drawgfx(bitmap,Machine->gfx[1],
     (spriteram[offs] & 0x3f) + 2 * (spriteram[offs + 1] & 0x20),
     spriteram[offs + 1] & 0x1f,
     flipx,flipy,
     sx,sy+1,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 update_pal()
{
char *v0; // rdx
char *v1; // r8
char *v2; // rdi
__int64 v3; // rax
char v4; // cl
char *v5; // rax
char v6; // dl
char *v7; // rax
char v8; // cl
char v9; // al
char v10; // cl
char *v11; // rax
char v12; // al
char v13; // cl
char *v14; // rax
char v15; // al
char v16; // cl
char *v17; // rax
char v18; // al
char v19; // cl
char *v20; // rax
char v21; // al
char v22; // cl
char *v23; // rax
char v24; // al
int v25; // ecx
char *v26; // rax
__int64 result; // rax

v0 = (char *)&fusemap;
v1 = &andmap[64];
v2 = andmap;
do
{
v3 = 0LL;
v4 = 1;
do
{
if ( !v0[v3] )
v4 &= columnvalue[v3];
++v3;
}
while ( v3 != 32 );
*v2++ = v4;
v0 += 32;
}
while ( v2 != v1 );
v5 = &andmap[1];
v6 = 0;
do
v6 |= *v5++;
while ( v5 != &andmap[8] );
if ( andmap[0] == 1 )
{
columnvalue[3] = v6;
columnvalue[2] = 1 - v6;
outvalue[0] = 1 - v6;
}
else
{
*(_WORD *)&columnvalue[2] = 256;
}
v7 = &andmap[8];
v8 = 0;
do
v8 |= *v7++;
while ( v7 != &andmap[16] );
columnvalue[7] = v8;
v9 = 1 - v8;
v10 = 0;
columnvalue[6] = v9;
outvalue[1] = v9;
v11 = &andmap[16];
do
v10 |= *v11++;
while ( v11 != &andmap[24] );
columnvalue[11] = v10;
v12 = 1 - v10;
v13 = 0;
columnvalue[10] = v12;
outvalue[2] = v12;
v14 = &andmap[24];
do
v13 |= *v14++;
while ( v14 != &andmap[32] );
columnvalue[15] = v13;
v15 = 1 - v13;
v16 = 0;
columnvalue[14] = v15;
outvalue[3] = v15;
v17 = &andmap[32];
do
v16 |= *v17++;
while ( &andmap[40] != v17 );
columnvalue[19] = v16;
v18 = 1 - v16;
v19 = 0;
columnvalue[18] = v18;
outvalue[4] = v18;
v20 = &andmap[40];
do
v19 |= *v20++;
while ( &andmap[48] != v20 );
columnvalue[23] = v19;
v21 = 1 - v19;
v22 = 0;
columnvalue[22] = v21;
outvalue[5] = v21;
v23 = &andmap[48];
do
v22 |= *v23++;
while ( &andmap[56] != v23 );
columnvalue[27] = v22;
v24 = 1 - v22;
v25 = 0;
columnvalue[26] = v24;
outvalue[6] = v24;
v26 = &andmap[57];
do
LOBYTE(v25) = *v26++ | v25;
while ( v26 != v1 );
if ( andmap[56] == 1 )
{
columnvalue[31] = v25;
result = (unsigned int)(1 - v25);
columnvalue[30] = 1 - v25;
outvalue[7] = 1 - v25;
}
else
{
result = 256LL;
*(_WORD *)&columnvalue[30] = 256;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rdx
char *v1; // r8
char *v2; // rdi
__int64 v3; // rax
char v4; // cl
char *v5; // rax
char v6; // dl
char *v7; // rax
char v8; // cl
char v9; // al
char v10; // cl
char *v11; // rax
char v12; // al
char v13; // cl
char *v14; // rax
char v15; // al
char v16; // cl
char *v17; // rax
char v18; // al
char v19; // cl
char *v20; // rax
char v21; // al
char v22; // cl
char *v23; // rax
char v24; // al
int v25; // ecx
char *v26; // rax
__int64 result; // rax

v0 = (char *)&fusemap;
v1 = &andmap[64];
v2 = andmap;
do
{
v3 = 0LL;
v4 = 1;
do
{
if ( !v0[v3] )
v4 &= columnvalue[v3];
++v3;
}
while ( v3 != 32 );
*v2++ = v4;
v0 += 32;
}
while ( v2 != v1 );
v5 = &andmap[1];
v6 = 0;
do
v6 |= *v5++;
while ( v5 != &andmap[8] );
if ( andmap[0] == 1 )
{
columnvalue[3] = v6;
columnvalue[2] = 1 - v6;
outvalue[0] = 1 - v6;
}
else
{
*(_WORD *)&columnvalue[2] = 256;
}
v7 = &andmap[8];
v8 = 0;
do
v8 |= *v7++;
while ( v7 != &andmap[16] );
columnvalue[7] = v8;
v9 = 1 - v8;
v10 = 0;
columnvalue[6] = v9;
outvalue[1] = v9;
v11 = &andmap[16];
do
v10 |= *v11++;
while ( v11 != &andmap[24] );
columnvalue[11] = v10;
v12 = 1 - v10;
v13 = 0;
columnvalue[10] = v12;
outvalue[2] = v12;
v14 = &andmap[24];
do
v13 |= *v14++;
while ( v14 != &andmap[32] );
columnvalue[15] = v13;
v15 = 1 - v13;
v16 = 0;
columnvalue[14] = v15;
outvalue[3] = v15;
v17 = &andmap[32];
do
v16 |= *v17++;
while ( &andmap[40] != v17 );
columnvalue[19] = v16;
v18 = 1 - v16;
v19 = 0;
columnvalue[18] = v18;
outvalue[4] = v18;
v20 = &andmap[40];
do
v19 |= *v20++;
while ( &andmap[48] != v20 );
columnvalue[23] = v19;
v21 = 1 - v19;
v22 = 0;
columnvalue[22] = v21;
outvalue[5] = v21;
v23 = &andmap[48];
do
v22 |= *v23++;
while ( &andmap[56] != v23 );
columnvalue[27] = v22;
v24 = 1 - v22;
v25 = 0;
columnvalue[26] = v24;
outvalue[6] = v24;
v26 = &andmap[57];
do
LOBYTE(v25) = *v26++ | v25;
while ( v26 != v1 );
if ( andmap[56] == 1 )
{
columnvalue[31] = v25;
result = (unsigned int)(1 - v25);
columnvalue[30] = 1 - v25;
outvalue[7] = 1 - v25;
}
else
{
result = 256LL;
*(_WORD *)&columnvalue[30] = 256;
}
return result;
}

original_code:
void update_pal(void)
{
unsigned short rowoffs;
unsigned char row, column, val;
 for (row=0; row<64; row++)
 {
  rowoffs = row<<5;
  val = 1;
  for (column=0; column<32; column++)
  {
   if ( fusemap[ rowoffs + column ] == 0 )
    val &= columnvalue[column];
  }
  andmap[row] = val;
 }
 val=0;
 for (row=1; row<8; row++)
  val |= andmap[row];
 if (andmap[0]==1)
 {
  columnvalue[2]=1-val;
  columnvalue[3]=val;
  outvalue[0]=1-val;
 }
 else
 {
  columnvalue[2]=0;
  columnvalue[3]=1;
 }
 val=0;
 for (row=8; row<16; row++)
  val |= andmap[row];
 columnvalue[6]=1-val;
 columnvalue[7]=val;
 outvalue[1]=1-val;
 val=0;
 for (row=16; row<24; row++)
  val |= andmap[row];
 columnvalue[10]=1-val;
 columnvalue[11]=val;
 outvalue[2]=1-val;
 val=0;
 for (row=24; row<32; row++)
  val |= andmap[row];
 columnvalue[14]=1-val;
 columnvalue[15]=val;
 outvalue[3]=1-val;
 val=0;
 for (row=32; row<40; row++)
  val |= andmap[row];
 columnvalue[18]=1-val;
 columnvalue[19]=val;
 outvalue[4]=1-val;
 val=0;
 for (row=40; row<48; row++)
  val |= andmap[row];
 columnvalue[22]=1-val;
 columnvalue[23]=val;
 outvalue[5]=1-val;
 val=0;
 for (row=48; row<56; row++)
  val |= andmap[row];
 columnvalue[26]=1-val;
 columnvalue[27]=val;
 outvalue[6]=1-val;
 val=0;
 for (row=57; row<64; row++)
  val |= andmap[row];
 if (andmap[56]==1)
 {
  columnvalue[30]=1-val;
  columnvalue[31]=val;
  outvalue[7]=1-val;
 }
 else
 {
  columnvalue[30]=0;
  columnvalue[31]=1;
 }
}

canonical_original_code:
void update_pal()
{
unsigned short rowoffs;
unsigned char row; unsigned char column; unsigned char val;
 for (row=0; row<64; row++)
 {
  rowoffs = row<<5;
  val = 1;
  for (column=0; column<32; column++)
  {
   if ( fusemap[ rowoffs + column ] == 0 )
    val &= columnvalue[column];
  }
  andmap[row] = val;
 }
 val=0;
 for (row=1; row<8; row++)
  val |= andmap[row];
 if (andmap[0]==1)
 {
  columnvalue[2]=1-val;
  columnvalue[3]=val;
  outvalue[0]=1-val;
 }
 else
 {
  columnvalue[2]=0;
  columnvalue[3]=1;
 }
 val=0;
 for (row=8; row<16; row++)
  val |= andmap[row];
 columnvalue[6]=1-val;
 columnvalue[7]=val;
 outvalue[1]=1-val;
 val=0;
 for (row=16; row<24; row++)
  val |= andmap[row];
 columnvalue[10]=1-val;
 columnvalue[11]=val;
 outvalue[2]=1-val;
 val=0;
 for (row=24; row<32; row++)
  val |= andmap[row];
 columnvalue[14]=1-val;
 columnvalue[15]=val;
 outvalue[3]=1-val;
 val=0;
 for (row=32; row<40; row++)
  val |= andmap[row];
 columnvalue[18]=1-val;
 columnvalue[19]=val;
 outvalue[4]=1-val;
 val=0;
 for (row=40; row<48; row++)
  val |= andmap[row];
 columnvalue[22]=1-val;
 columnvalue[23]=val;
 outvalue[5]=1-val;
 val=0;
 for (row=48; row<56; row++)
  val |= andmap[row];
 columnvalue[26]=1-val;
 columnvalue[27]=val;
 outvalue[6]=1-val;
 val=0;
 for (row=57; row<64; row++)
  val |= andmap[row];
 if (andmap[56]==1)
 {
  columnvalue[30]=1-val;
  columnvalue[31]=val;
  outvalue[7]=1-val;
 }
 else
 {
  columnvalue[30]=0;
  columnvalue[31]=1;
 }
}

variable_types:
rowoffs
unsigned short

variable_types:
row
unsigned char

variable_types:
column
unsigned char

variable_types:
val
unsigned char


decompiled_code:
__int64 bagman_machine_init()
{
bagman_pal16r6_w(0, 1);
bagman_pal16r6_w(1, 1);
bagman_pal16r6_w(2, 1);
bagman_pal16r6_w(3, 1);
bagman_pal16r6_w(4, 1);
bagman_pal16r6_w(5, 1);
bagman_pal16r6_w(6, 1);
bagman_pal16r6_w(7, 1);
return update_pal();
}

original_code:
void bagman_machine_init(void)
{
 bagman_pal16r6_w(0,1);
 bagman_pal16r6_w(1,1);
 bagman_pal16r6_w(2,1);
 bagman_pal16r6_w(3,1);
 bagman_pal16r6_w(4,1);
 bagman_pal16r6_w(5,1);
 bagman_pal16r6_w(6,1);
 bagman_pal16r6_w(7,1);
 update_pal();
}

canonical_original_code:
void bagman_machine_init()
{
 bagman_pal16r6_w(0,1);
 bagman_pal16r6_w(1,1);
 bagman_pal16r6_w(2,1);
 bagman_pal16r6_w(3,1);
 bagman_pal16r6_w(4,1);
 bagman_pal16r6_w(5,1);
 bagman_pal16r6_w(6,1);
 bagman_pal16r6_w(7,1);
 update_pal();
}


decompiled_code:
__int64 bagman_pal16r6_r()
{
update_pal();
return (unsigned __int8)outvalue[6]
+ 2 * (unsigned __int8)outvalue[5]
+ 4 * (unsigned __int8)outvalue[4]
+ 8 * (unsigned __int8)outvalue[3]
+ 16 * (unsigned __int8)outvalue[2]
+ 32 * (unsigned int)(unsigned __int8)outvalue[1];
}

canonical_decompiled_code:
__int64 func6()
{
func4();
return (unsigned __int8)outvalue[6]
+ 2 * (unsigned __int8)outvalue[5]
+ 4 * (unsigned __int8)outvalue[4]
+ 8 * (unsigned __int8)outvalue[3]
+ 16 * (unsigned __int8)outvalue[2]
+ 32 * (unsigned int)(unsigned __int8)outvalue[1];
}

original_code:
data_t bagman_pal16r6_r(offs_t offset)
{
 update_pal();
 return (outvalue[6]) + (outvalue[5]<<1) + (outvalue[4]<<2) +
  (outvalue[3]<<3) + (outvalue[2]<<4) + (outvalue[1]<<5);
}

canonical_original_code:
unsigned int bagman_pal16r6_r(unsigned int offset)
{
 update_pal();
 return (outvalue[6]) + (outvalue[5]<<1) + (outvalue[4]<<2) +
  (outvalue[3]<<3) + (outvalue[2]<<4) + (outvalue[1]<<5);
}

variable_types:
offset
unsigned int


original_code:
void olibochu_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 6) & 0x01;
  bit1 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = (*(color_prom++) & 0x0f);
}

canonical_original_code:
void olibochu_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 6) & 0x01;
  bit1 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = (*(color_prom++) & 0x0f);
}


decompiled_code:
__int64 olibochu_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 207 : 215;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)cpu_getiloops() == 0 ? 207 : 215;
}

original_code:
static int olibochu_interrupt(void)
{
 if (cpu_getiloops() == 0)
  return 0xcf;
 else
  return 0xd7;
}

canonical_original_code:
static int olibochu_interrupt()
{
 if (cpu_getiloops() == 0)
  return 0xcf;
 else
  return 0xd7;
}


decompiled_code:
__int64 __fastcall sound_command_w(int a1, int a2)
{
int v2; // esi
__int64 result; // rax
bool v4; // cf

if ( a1 )
v2 = cmd_0 & 0xFF00 | a2;
else
v2 = (unsigned __int8)cmd_0 | (a2 << 8);
cmd_0 = v2;
LODWORD(result) = 15;
while ( !_bittest(&v2, result) )
{
v4 = (_DWORD)result == 0;
result = (unsigned int)(result - 1);
if ( v4 )
return result;
}
return soundlatch_w(0LL, (unsigned int)(15 - result));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
int v2; // esi
__int64 result; // rax
bool v4; // cf

if ( a1 )
v2 = cmd_0 & 0xFF00 | a2;
else
v2 = (unsigned __int8)cmd_0 | (a2 << 8);
cmd_0 = v2;
LODWORD(result) = 15;
while ( !_bittest(&v2, result) )
{
v4 = (_DWORD)result == 0;
result = (unsigned int)(result - 1);
if ( v4 )
return result;
}
return soundlatch_w(0LL, (unsigned int)(15 - result));
}

original_code:
static void sound_command_w(offs_t offset,data_t data)
{
 static int cmd;
 int c;
 if (offset == 0) cmd = (cmd & 0x00ff) | (data << 8);
 else cmd = (cmd & 0xff00) | data;
 for (c = 15;c >= 0;c--)
  if (cmd & (1 << c)) break;
 if (c >= 0) soundlatch_w(0,15-c);
}

canonical_original_code:
static void sound_command_w(unsigned int offset, unsigned int data)
{
 static int cmd;
 int c;
 if (offset == 0) cmd = (cmd & 0x00ff) | (data << 8);
 else cmd = (cmd & 0xff00) | data;
 for (c = 15;c >= 0;c--)
  if (cmd & (1 << c)) break;
 if (c >= 0) soundlatch_w(0,15-c);
}

variable_types:
data
unsigned int

variable_types: cmd int

variable_types: c int