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

canonical_decompiled_code:
void __fastcall func3(__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)
{
unsigned int v1; // ebx

v1 = (unsigned __int8)((__int64 (*)(void))input_port_5_r)() | 0x3F;
if ( (royalmah_input_port_select & 1) == 0 )
v1 &= input_port_5_r(a1);
if ( (royalmah_input_port_select & 2) == 0 )
v1 &= input_port_6_r(a1);
if ( (royalmah_input_port_select & 4) == 0 )
v1 &= input_port_7_r(a1);
if ( (royalmah_input_port_select & 8) == 0 )
v1 &= input_port_8_r(a1);
if ( (royalmah_input_port_select & 0x10) == 0 )
v1 &= input_port_9_r(a1);
return v1;
}

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

v1 = (unsigned __int8)((__int64 (*)(void))input_port_5_r)() | 0x3F;
if ( (royalmah_input_port_select & 1) == 0 )
v1 &= input_port_5_r(a1);
if ( (royalmah_input_port_select & 2) == 0 )
v1 &= input_port_6_r(a1);
if ( (royalmah_input_port_select & 4) == 0 )
v1 &= input_port_7_r(a1);
if ( (royalmah_input_port_select & 8) == 0 )
v1 &= input_port_8_r(a1);
if ( (royalmah_input_port_select & 0x10) == 0 )
v1 &= input_port_9_r(a1);
return v1;
}

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:
offset
unsigned int

variable_types: ret int

return_type: unsigned int


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

v1 = (unsigned __int8)((__int64 (*)(void))input_port_0_r)() | 0x3F;
if ( (royalmah_input_port_select & 1) == 0 )
v1 &= input_port_0_r(a1);
if ( (royalmah_input_port_select & 2) == 0 )
v1 &= input_port_1_r(a1);
if ( (royalmah_input_port_select & 4) == 0 )
v1 &= input_port_2_r(a1);
if ( (royalmah_input_port_select & 8) == 0 )
v1 &= input_port_3_r(a1);
if ( (royalmah_input_port_select & 0x10) == 0 )
v1 &= input_port_4_r(a1);
return v1;
}

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

v1 = (unsigned __int8)((__int64 (*)(void))input_port_0_r)() | 0x3F;
if ( (royalmah_input_port_select & 1) == 0 )
v1 &= input_port_0_r(a1);
if ( (royalmah_input_port_select & 2) == 0 )
v1 &= input_port_1_r(a1);
if ( (royalmah_input_port_select & 4) == 0 )
v1 &= input_port_2_r(a1);
if ( (royalmah_input_port_select & 8) == 0 )
v1 &= input_port_3_r(a1);
if ( (royalmah_input_port_select & 0x10) == 0 )
v1 &= input_port_4_r(a1);
return v1;
}

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 = 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 = 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

variable_types:
code
int *

variable_types:
color
int *

return_type: void


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 = 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 = 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:
data
unsigned int


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

layer_colorbase[0] = 0;
dword_63C = 8;
dword_640 = 4;
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; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_63C = 8;
dword_640 = 4;
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;
}

return_type: int


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

layer_colorbase[0] = 0;
dword_63C = 0;
dword_640 = 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; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_63C = 0;
dword_640 = 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);
}

variable_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);
}

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


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 3) + 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 & 3) + 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)
{
if ( (a2 & 2) != 0 )
{
if ( (a2 & 1) != 0 )
UPD7759_start_w(0LL, 0LL);
}
else
{
UPD7759_reset_w(0LL, (a2 >> 1) & 1);
}
return interrupt_enable_w(0LL, a2 & 4);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
if ( (a2 & 2) != 0 )
{
if ( (a2 & 1) != 0 )
UPD7759_start_w(0LL, 0LL);
}
else
{
UPD7759_reset_w(0LL, (a2 >> 1) & 1);
}
return interrupt_enable_w(0LL, a2 & 4);
}

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()
{
int v0; // edx
__int64 result; // rax

v0 = K052109_is_IRQ_enabled();
result = 1LL;
if ( !v0 )
result = ignore_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func19()
{
int v0; // edx
__int64 result; // rax

v0 = K052109_is_IRQ_enabled();
result = 1LL;
if ( !v0 )
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

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

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

result = 4LL;
if ( !nmi_enable )
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:
__int64 __fastcall bagman_pal16r6_w(char a1, unsigned __int8 a2)
{
__int64 v2; // rcx
__int64 result; // rax

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

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

v2 = (unsigned __int8)(4 * a1);
result = (a2 ^ 1) & 1;
columnvalue[v2] = result;
columnvalue[v2 + 1] = a2 & 1;
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 v2; // ecx
int *result; // rax

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

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

v2 = a2 & 1;
result = flipscreen;
if ( v2 != flipscreen[a1] )
{
flipscreen[a1] = v2;
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);
 }
}

variable_types:
offset
unsigned int


decompiled_code:
void *__fastcall bagman_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ecx
int v5; // ebp
__int64 v6; // rbx

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 *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v4 = 0;
if ( *(_QWORD *)(Machine + 528LL) )
v4 = 2 * ((*(_BYTE *)(colorram + v2) & 0x10) != 0);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v4 + 512),
*(unsigned __int8 *)(videoram + v2) + 8 * (*(_BYTE *)(colorram + v2) & 0x20u),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5 + 3LL;
do
{
result = (void *)spriteram;
if ( *(_BYTE *)(spriteram + v6) )
{
if ( *(_BYTE *)(spriteram + v6 - 1) )
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(_BYTE *)(spriteram + v6 - 3) & 0x3F) + 2 * (*(_BYTE *)(spriteram + v6 - 2) & 0x20u),
*(_BYTE *)(spriteram + v6 - 2) & 0x1F);
}
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ecx
int v5; // ebp
__int64 v6; // rbx

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 *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v4 = 0;
if ( *(_QWORD *)(Machine + 528LL) )
v4 = 2 * ((*(_BYTE *)(colorram + v2) & 0x10) != 0);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v4 + 512),
*(unsigned __int8 *)(videoram + v2) + 8 * (*(_BYTE *)(colorram + v2) & 0x20u),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5 + 3LL;
do
{
result = (void *)spriteram;
if ( *(_BYTE *)(spriteram + v6) )
{
if ( *(_BYTE *)(spriteram + v6 - 1) )
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(_BYTE *)(spriteram + v6 - 3) & 0x3F) + 2 * (*(_BYTE *)(spriteram + v6 - 2) & 0x20u),
*(_BYTE *)(spriteram + v6 - 2) & 0x1F);
}
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 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: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
unsigned __int64 update_pal()
{
char *v0; // rdx
char *v1; // r8
int i; // edi
__int64 v3; // rax
char v4; // cl
char *v5; // rax
char v6; // dl
char *v7; // rax
char v8; // dl
char *v9; // rax
char v10; // dl
char *v11; // rax
char v12; // dl
char *v13; // rax
char v14; // dl
char *v15; // rax
char v16; // dl
char *v17; // rax
char v18; // dl
char *v19; // rax
int v20; // edx
unsigned __int64 result; // rax

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

canonical_decompiled_code:
unsigned __int64 func4()
{
char *v0; // rdx
char *v1; // r8
int i; // edi
__int64 v3; // rax
char v4; // cl
char *v5; // rax
char v6; // dl
char *v7; // rax
char v8; // dl
char *v9; // rax
char v10; // dl
char *v11; // rax
char v12; // dl
char *v13; // rax
char v14; // dl
char *v15; // rax
char v16; // dl
char *v17; // rax
char v18; // dl
char *v19; // rax
int v20; // edx
unsigned __int64 result; // rax

v0 = (char *)&fusemap;
v1 = andmap;
for ( i = 0; i != 2048; i += 32 )
{
v3 = 0LL;
v4 = 1;
do
{
if ( !v0[v3] )
v4 &= columnvalue[v3];
++v3;
}
while ( v3 != 32 );
*v1++ = v4;
v0 += 32;
}
v5 = &andmap[1];
v6 = 0;
do
v6 |= *v5++;
while ( v5 != &andmap[8] );
if ( andmap[0] == 1 )
{
columnvalue[2] = 1 - v6;
columnvalue[3] = v6;
outvalue[0] = 1 - v6;
}
else
{
columnvalue[2] = 0;
columnvalue[3] = 1;
}
v7 = &andmap[8];
v8 = 0;
do
v8 |= *v7++;
while ( v7 != &andmap[16] );
columnvalue[6] = 1 - v8;
columnvalue[7] = v8;
outvalue[1] = 1 - v8;
v9 = &andmap[16];
v10 = 0;
do
v10 |= *v9++;
while ( v9 != &andmap[24] );
columnvalue[10] = 1 - v10;
columnvalue[11] = v10;
outvalue[2] = 1 - v10;
v11 = &andmap[24];
v12 = 0;
do
v12 |= *v11++;
while ( v11 != &andmap[32] );
columnvalue[14] = 1 - v12;
columnvalue[15] = v12;
outvalue[3] = 1 - v12;
v13 = &andmap[32];
v14 = 0;
do
v14 |= *v13++;
while ( v13 != &andmap[40] );
columnvalue[18] = 1 - v14;
columnvalue[19] = v14;
outvalue[4] = 1 - v14;
v15 = &andmap[40];
v16 = 0;
do
v16 |= *v15++;
while ( &andmap[48] != v15 );
columnvalue[22] = 1 - v16;
columnvalue[23] = v16;
outvalue[5] = 1 - v16;
v17 = &andmap[48];
v18 = 0;
do
v18 |= *v17++;
while ( &andmap[56] != v17 );
columnvalue[26] = 1 - v18;
columnvalue[27] = v18;
outvalue[6] = 1 - v18;
v19 = &andmap[57];
v20 = 0;
do
LOBYTE(v20) = *v19++ | v20;
while ( &andmap[64] != v19 );
if ( andmap[56] == 1 )
{
result = (unsigned int)(1 - v20);
columnvalue[30] = 1 - v20;
columnvalue[31] = v20;
outvalue[7] = 1 - v20;
}
else
{
result = (unsigned __int64)columnvalue;
columnvalue[30] = 0;
columnvalue[31] = 1;
}
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:
unsigned __int64 bagman_machine_init()
{
bagman_pal16r6_w(0, 1u);
bagman_pal16r6_w(1, 1u);
bagman_pal16r6_w(2, 1u);
bagman_pal16r6_w(3, 1u);
bagman_pal16r6_w(4, 1u);
bagman_pal16r6_w(5, 1u);
bagman_pal16r6_w(6, 1u);
bagman_pal16r6_w(7, 1u);
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);
}


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 func1()
{
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

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

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

if ( a1 )
v2 = a2 | cmd_0 & 0xFF00;
else
v2 = (unsigned __int8)cmd_0 | (a2 << 8);
cmd_0 = v2;
if ( (v2 & 0x8000) != 0 )
{
LODWORD(result) = 15;
}
else
{
LODWORD(result) = 14;
while ( !_bittest(&v2, result) )
{
result = (unsigned int)(result - 1);
if ( (_DWORD)result == -1 )
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


decompiled_code:
void crash_reset_w()
{
firetruck_bit7_flags &= 0xBFu;
}

canonical_decompiled_code:
void func0()
{
firetruck_bit7_flags &= 0xBFu;
}

original_code:
static void crash_reset_w(offs_t offset,data_t data)
{
 firetruck_bit7_flags &= ~0x40;
}

canonical_original_code:
static void crash_reset_w(unsigned int offset, unsigned int data)
{
 firetruck_bit7_flags &= ~0x40;
}


decompiled_code:
__int64 firetruck_vh_init()
{
buf = osd_alloc_bitmap(
**(unsigned int **)(Machine + 768LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 4LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 8LL));
return (unsigned int)-(buf == 0);
}

canonical_decompiled_code:
__int64 func1()
{
buf = osd_alloc_bitmap(
**(unsigned int **)(Machine + 768LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 4LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 8LL));
return (unsigned int)-(buf == 0);
}

original_code:
int firetruck_vh_init( void )
{
 buf = osd_alloc_bitmap(
   Machine->scrbitmap->width,
   Machine->scrbitmap->height,
   Machine->scrbitmap->depth );
 if( buf ) return 0;
 return -1;
}

canonical_original_code:
int firetruck_vh_init()
{
 buf = osd_alloc_bitmap(
   Machine->scrbitmap->width,
   Machine->scrbitmap->height,
   Machine->scrbitmap->depth );
 if( buf ) return 0;
 return -1;
}


decompiled_code:
__int64 firetruck_vh_stop()
{
return osd_free_bitmap(buf);
}

canonical_decompiled_code:
__int64 func2()
{
return osd_free_bitmap(buf);
}

original_code:
void firetruck_vh_stop( void )
{
 osd_free_bitmap( buf );
}

canonical_original_code:
void firetruck_vh_stop()
{
 osd_free_bitmap( buf );
}


decompiled_code:
__int64 __fastcall firetruck_xtndply_w(__int64 a1, unsigned __int8 a2)
{
return discrete_sound_w(7LL, (a2 ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 a2)
{
return discrete_sound_w(7LL, (a2 ^ 1) & 1);
}

original_code:
static void firetruck_xtndply_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x07,!(data&0x01));
}

canonical_original_code:
static void firetruck_xtndply_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x07,!(data&0x01));
}


decompiled_code:
__int64 __fastcall firetruck_out_w(__int64 a1, unsigned int a2)
{
firetruck_invert_display = a2 & 4;
discrete_sound_w(6LL, ((unsigned __int8)(a2 >> 4) ^ 1) & 1);
return discrete_sound_w(5LL, ((unsigned __int8)(a2 >> 7) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
firetruck_invert_display = a2 & 4;
discrete_sound_w(6LL, ((unsigned __int8)(a2 >> 4) ^ 1) & 1);
return discrete_sound_w(5LL, ((unsigned __int8)(a2 >> 7) ^ 1) & 1);
}

original_code:
static void firetruck_out_w(offs_t offset,data_t data)
{
 firetruck_invert_display = data&0x04;
 discrete_sound_w(0x06,!(data&0x10));
 discrete_sound_w(0x05,(data&0x80)?0x00:0x01);
}

canonical_original_code:
static void firetruck_out_w(unsigned int offset, unsigned int data)
{
 firetruck_invert_display = data&0x04;
 discrete_sound_w(0x06,!(data&0x10));
 discrete_sound_w(0x05,(data&0x80)?0x00:0x01);
}


decompiled_code:
__int64 firetruck_skidsnd_w()
{
return discrete_sound_w(4LL, 1LL);
}

canonical_decompiled_code:
__int64 func5()
{
return discrete_sound_w(4LL, 1LL);
}

original_code:
static void firetruck_skidsnd_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x04,0x01);
}

canonical_original_code:
static void firetruck_skidsnd_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x04,0x01);
}


decompiled_code:
__int64 __fastcall firetruck_crashsnd_w(__int64 a1, unsigned __int8 a2)
{
return discrete_sound_w(3LL, a2 >> 4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 a2)
{
return discrete_sound_w(3LL, a2 >> 4);
}

original_code:
static void firetruck_crashsnd_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x03,(data&0xf0)>>4);
}

canonical_original_code:
static void firetruck_crashsnd_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x03,(data&0xf0)>>4);
}


decompiled_code:
__int64 __fastcall firetruck_motorsnd_w(__int64 a1, unsigned int a2)
{
discrete_sound_w(0LL, a2 & 0xF);
return discrete_sound_w(2LL, (a2 >> 4) & 0xF);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
discrete_sound_w(0LL, a2 & 0xF);
return discrete_sound_w(2LL, (a2 >> 4) & 0xF);
}

original_code:
static void firetruck_motorsnd_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x00,data&0x0f);
 discrete_sound_w(0x02,(data&0xf0)>>4);
}

canonical_original_code:
static void firetruck_motorsnd_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x00,data&0x0f);
 discrete_sound_w(0x02,(data&0xf0)>>4);
}


decompiled_code:
__int64 skid_reset_w()
{
firetruck_bit0_flags &= 0xBFu;
return discrete_sound_w(4LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
firetruck_bit0_flags &= 0xBFu;
return discrete_sound_w(4LL, 0LL);
}

original_code:
static void skid_reset_w(offs_t offset,data_t data)
{
 firetruck_bit0_flags &= ~0x40;
 discrete_sound_w(0x04,0x00);
}

canonical_original_code:
static void skid_reset_w(unsigned int offset, unsigned int data)
{
 firetruck_bit0_flags &= ~0x40;
 discrete_sound_w(0x04,0x00);
}


decompiled_code:
__int64 __fastcall firetruck_vh_screenrefresh(__int64 a1)
{
unsigned int v1; // eax

draw_background(a1);
draw_text(a1);
draw_sprites(a1);
v1 = input_port_6_r(0LL);
return discrete_sound_w(1LL, v1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned int v1; // eax

func9(a1);
func10(a1);
func11(a1);
v1 = input_port_6_r(0LL);
return discrete_sound_w(1LL, v1);
}

original_code:
void firetruck_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 draw_background( bitmap );
 draw_text( bitmap );
 draw_sprites( bitmap );
 discrete_sound_w(0x01,input_port_6_r(0));
}

canonical_original_code:
void firetruck_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 draw_background( bitmap );
 draw_text( bitmap );
 draw_sprites( bitmap );
 discrete_sound_w(0x01,input_port_6_r(0));
}

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

variable_types: fullrefresh int


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

firetruck_bit7_flags |= 0xCu;
firetruck_steer1 = readinputport(4LL);
result = readinputport(5LL);
firetruck_steer2 = result;
return result;
}

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

firetruck_bit7_flags |= 0xCu;
firetruck_steer1 = readinputport(4LL);
result = readinputport(5LL);
firetruck_steer2 = result;
return result;
}

original_code:
static void steer_reset_w(offs_t offset,data_t data)
{
 firetruck_bit7_flags |= 0x0c;
 firetruck_steer1 = readinputport(4);
 firetruck_steer2 = readinputport(5);
}

canonical_original_code:
static void steer_reset_w(unsigned int offset, unsigned int data)
{
 firetruck_bit7_flags |= 0x0c;
 firetruck_steer1 = readinputport(4);
 firetruck_steer2 = readinputport(5);
}


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

v1 = readinputport(0LL);
v2 = (4 * (_BYTE)v1) & 0xC;
switch ( a1 )
{
case 1:
v2 |= (v1 >> 4) & 3;
break;
case 2:
v2 |= (v1 >> 2) & 3;
break;
case 0:
v2 |= (v1 >> 6) & 3;
break;
}
return v2;
}

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

v1 = readinputport(0LL);
v2 = (4 * (_BYTE)v1) & 0xC;
switch ( a1 )
{
case 1:
v2 |= (v1 >> 4) & 3;
break;
case 2:
v2 |= (v1 >> 2) & 3;
break;
case 0:
v2 |= (v1 >> 6) & 3;
break;
}
return v2;
}

original_code:
static data_t firetruck_dsw_r(offs_t offset)
{
 int dip = readinputport(0);
 int data = (dip&0x3)<<2;
 switch (offset)
 {
 case 0x00: data |= (dip>>6)&0x03; break;
 case 0x01: data |= (dip>>4)&0x03; break;
 case 0x02: data |= (dip>>2)&0x03; break;
 }
 return data;
}

canonical_original_code:
static unsigned int firetruck_dsw_r(unsigned int offset)
{
 int dip = readinputport(0);
 int data = (dip&0x3)<<2;
 switch (offset)
 {
 case 0x00: data |= (dip>>6)&0x03; break;
 case 0x01: data |= (dip>>4)&0x03; break;
 case 0x02: data |= (dip>>2)&0x03; break;
 }
 return data;
}

variable_types: dip int

variable_types: data int


decompiled_code:
__int64 __fastcall firetruck_io_r(char a1)
{
char v1; // r14
char v2; // bl
unsigned __int8 v3; // r12
char v4; // r13
int v5; // ebp
char v6; // dl
char v7; // r14
char v8; // dl
unsigned __int8 v9; // r13
__int64 result; // rax

v1 = readinputport(1LL);
v2 = v1;
v3 = readinputport(2LL);
v4 = readinputport(3LL);
v5 = 1 << a1;
v6 = readinputport(4LL) - firetruck_steer1;
if ( v6 / 4 )
{
v7 = v1 | 4;
if ( v6 / 4 < 0 )
v2 = v7;
firetruck_bit7_flags &= 0xFBu;
}
v8 = readinputport(5LL) - firetruck_steer2;
if ( v8 / 4 )
{
if ( v8 / 4 < 0 )
v2 |= 8u;
firetruck_bit7_flags &= 0xF7u;
}
v9 = firetruck_bit7_flags | v4;
LOBYTE(result) = (unsigned __int8)(v5 & (firetruck_bit0_flags | v2)) != 0;
if ( ((unsigned __int8)v5 & v3) != 0 )
LOBYTE(result) = result | 0x40;
if ( ((unsigned __int8)v5 & v9) != 0 )
LOBYTE(result) = result | 0x80;
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char a1)
{
char v1; // r14
char v2; // bl
unsigned __int8 v3; // r12
char v4; // r13
int v5; // ebp
char v6; // dl
char v7; // r14
char v8; // dl
unsigned __int8 v9; // r13
__int64 result; // rax

v1 = readinputport(1LL);
v2 = v1;
v3 = readinputport(2LL);
v4 = readinputport(3LL);
v5 = 1 << a1;
v6 = readinputport(4LL) - firetruck_steer1;
if ( v6 / 4 )
{
v7 = v1 | 4;
if ( v6 / 4 < 0 )
v2 = v7;
firetruck_bit7_flags &= 0xFBu;
}
v8 = readinputport(5LL) - firetruck_steer2;
if ( v8 / 4 )
{
if ( v8 / 4 < 0 )
v2 |= 8u;
firetruck_bit7_flags &= 0xF7u;
}
v9 = firetruck_bit7_flags | v4;
LOBYTE(result) = (unsigned __int8)(v5 & (firetruck_bit0_flags | v2)) != 0;
if ( ((unsigned __int8)v5 & v3) != 0 )
LOBYTE(result) = result | 0x40;
if ( ((unsigned __int8)v5 & v9) != 0 )
LOBYTE(result) = result | 0x80;
return (unsigned __int8)result;
}

original_code:
static data_t firetruck_io_r(offs_t offset)
{
 data8_t data, bit0, bit6, bit7;
 int bit,steer_poll;
 bit0 = readinputport(1);
 bit6 = readinputport(2);
 bit7 = readinputport(3);
 bit = 1<<offset;
 steer_poll = ((INT8)(readinputport(4) - firetruck_steer1))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x04;
  firetruck_bit7_flags &= ~0x04;
 }
 steer_poll = ((INT8)(readinputport(5) - firetruck_steer2))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x08;
  firetruck_bit7_flags &= ~0x08;
 }
 bit0 |= firetruck_bit0_flags;
 bit7 |= firetruck_bit7_flags;
 data = 0x00;
 if( bit0 & bit ) data |= 0x01;
 if( bit6 & bit ) data |= 0x40;
 if( bit7 & bit ) data |= 0x80;
 return data;
}

canonical_original_code:
static unsigned int firetruck_io_r(unsigned int offset)
{
 unsigned char data; unsigned char bit0; unsigned char bit6; unsigned char bit7;
 int bit; int steer_poll;
 bit0 = readinputport(1);
 bit6 = readinputport(2);
 bit7 = readinputport(3);
 bit = 1<<offset;
 steer_poll = ((INT8)(readinputport(4) - firetruck_steer1))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x04;
  firetruck_bit7_flags &= ~0x04;
 }
 steer_poll = ((INT8)(readinputport(5) - firetruck_steer2))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x08;
  firetruck_bit7_flags &= ~0x08;
 }
 bit0 |= firetruck_bit0_flags;
 bit7 |= firetruck_bit7_flags;
 data = 0x00;
 if( bit0 & bit ) data |= 0x01;
 if( bit6 & bit ) data |= 0x40;
 if( bit7 & bit ) data |= 0x80;
 return data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned char

variable_types: bit int


decompiled_code:
__int64 firetruck_interrupt()
{
if ( (unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(1LL) & 0x80u) == 0LL )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func17()
{
if ( (unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(1LL) & 0x80u) == 0LL )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
int firetruck_interrupt( void )
{
 if( cpu_getiloops()==0 )
 {
  if( readinputport(1)&0x80 )
  {
   return ignore_interrupt();
  }
  else
  {
   return nmi_interrupt();
  }
 }
 else
 {
  return interrupt();
 }
}

canonical_original_code:
int firetruck_interrupt()
{
 if( cpu_getiloops()==0 )
 {
  if( readinputport(1)&0x80 )
  {
   return ignore_interrupt();
  }
  else
  {
   return nmi_interrupt();
  }
 }
 else
 {
  return interrupt();
 }
}


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

v0 = memory_region(129LL);
result = (_BYTE *)(v0 + 12288);
v2 = (_BYTE *)(v0 + 0x4000);
do
{
v3 = result[57344] | (16 * result[53248]);
*result = v3;
result[49152] = v3;
++result;
}
while ( result != v2 );
return result;
}

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

v0 = memory_region(129LL);
result = (_BYTE *)(v0 + 12288);
v2 = (_BYTE *)(v0 + 0x4000);
do
{
v3 = result[57344] | (16 * result[53248]);
*result = v3;
result[49152] = v3;
++result;
}
while ( result != v2 );
return result;
}

original_code:
void init_firetruck( void )
{
 UINT8 *pMem = memory_region( REGION_CPU1 );
 int i;
 for( i=0; i<0x1000; i++ )
 {
  int msn = pMem[0x10000+i];
  int lsn = pMem[0x10000+i+0x1000];
  int data = (msn<<4)|lsn;
  pMem[i+0x3000] = data;
  pMem[i+0xf000] = data;
 }
}

canonical_original_code:
void init_firetruck()
{
 unsigned char *pMem = memory_region( REGION_CPU1 );
 int i;
 for( i=0; i<0x1000; i++ )
 {
  int msn = pMem[0x10000+i];
  int lsn = pMem[0x10000+i+0x1000];
  int data = (msn<<4)|lsn;
  pMem[i+0x3000] = data;
  pMem[i+0xf000] = data;
 }
}

variable_types:
pMem
unsigned char *

variable_types: i int

variable_types: msn int

variable_types: lsn int


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
__int64 v1; // r12
int v2; // er13
__int64 v3; // rbx
int v4; // ebp
__int64 result; // rax
int v6; // [rsp+8h] [rbp-48h]
int v7; // [rsp+Ch] [rbp-44h]
__int64 v8; // [rsp+10h] [rbp-40h]

v6 = 4 * (firetruck_invert_display != 0);
v7 = *(unsigned __int8 *)(videoram + 4128LL);
v1 = videoram + 2064LL;
v2 = -*(unsigned __int8 *)(videoram + 4096LL);
v8 = videoram + 2320LL;
do
{
v3 = v1 - 16;
v4 = -v7;
do
{
++v3;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(v3 - 1) & 0x3F,
(unsigned int)(v6 + ((int)*(unsigned __int8 *)(v3 - 1) >> 6)),
0LL,
0LL,
(unsigned __int8)v4,
(unsigned __int8)v2,
Machine + 776LL,
0LL,
0LL);
v4 += 16;
}
while ( v3 != v1 );
v1 += 16LL;
LOBYTE(v2) = v2 + 16;
}
while ( v1 != v8 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // r12
int v2; // er13
__int64 v3; // rbx
int v4; // ebp
__int64 result; // rax
int v6; // [rsp+8h] [rbp-48h]
int v7; // [rsp+Ch] [rbp-44h]
__int64 v8; // [rsp+10h] [rbp-40h]

v6 = 4 * (firetruck_invert_display != 0);
v7 = *(unsigned __int8 *)(videoram + 4128LL);
v1 = videoram + 2064LL;
v2 = -*(unsigned __int8 *)(videoram + 4096LL);
v8 = videoram + 2320LL;
do
{
v3 = v1 - 16;
v4 = -v7;
do
{
++v3;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(v3 - 1) & 0x3F,
(unsigned int)(v6 + ((int)*(unsigned __int8 *)(v3 - 1) >> 6)),
0LL,
0LL,
(unsigned __int8)v4,
(unsigned __int8)v2,
Machine + 776LL,
0LL,
0LL);
v4 += 16;
}
while ( v3 != v1 );
v1 += 16LL;
LOBYTE(v2) = v2 + 16;
}
while ( v1 != v8 );
return result;
}

original_code:
static void draw_background( struct osd_bitmap *bitmap )
{
 int color = firetruck_invert_display?4:0;
 int pvpload = videoram[0x1000];
 int phpload = videoram[0x1020];
 int x,y,tile_number;
 const UINT8 *source = videoram+0x800;
 for( y=0; y<256; y+=16 )
 {
  for( x=0; x<256; x+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[1],
    tile_number&0x3f,
    color+(tile_number>>6),
    0,0,
    (x-phpload)&0xff,(y-pvpload)&0xff,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap)
{
 int color = firetruck_invert_display?4:0;
 int pvpload = videoram[0x1000];
 int phpload = videoram[0x1020];
 int x; int y; int tile_number;
 unsigned char *source = videoram+0x800;
 for( y=0; y<256; y+=16 )
 {
  for( x=0; x<256; x+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[1],
    tile_number&0x3f,
    color+(tile_number>>6),
    0,0,
    (x-phpload)&0xff,(y-pvpload)&0xff,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

variable_types: color int

variable_types: pvpload int

variable_types: phpload int

variable_types: x int

variable_types: y int

variable_types:
source
unsigned char *


decompiled_code:
__int64 __fastcall draw_text(__int64 a1)
{
unsigned int v1; // er13
__int64 v2; // r12
unsigned __int8 *v3; // rbp
__int64 v4; // rbx
__int64 result; // rax
unsigned __int8 *v6; // [rsp+8h] [rbp-40h]

v1 = firetruck_invert_display == 0 ? 7 : 3;
v6 = (unsigned __int8 *)videoram;
v2 = 0LL;
do
{
v3 = v6;
v4 = 0LL;
do
{
result = drawgfx(a1, *(_QWORD *)(Machine + 512LL), *v3++, v1, 0LL, 0LL, v2, v4, Machine + 776LL, 0LL, 0LL);
v4 = (unsigned int)(v4 + 16);
}
while ( (_DWORD)v4 != 256 );
v6 += 16;
v2 = (unsigned int)(v2 + 240);
}
while ( (_DWORD)v2 != 480 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // er13
__int64 v2; // r12
unsigned __int8 *v3; // rbp
__int64 v4; // rbx
__int64 result; // rax
unsigned __int8 *v6; // [rsp+8h] [rbp-40h]

v1 = firetruck_invert_display == 0 ? 7 : 3;
v6 = (unsigned __int8 *)videoram;
v2 = 0LL;
do
{
v3 = v6;
v4 = 0LL;
do
{
result = drawgfx(a1, *(_QWORD *)(Machine + 512LL), *v3++, v1, 0LL, 0LL, v2, v4, Machine + 776LL, 0LL, 0LL);
v4 = (unsigned int)(v4 + 16);
}
while ( (_DWORD)v4 != 256 );
v6 += 16;
v2 = (unsigned int)(v2 + 240);
}
while ( (_DWORD)v2 != 480 );
return result;
}

original_code:
static void draw_text( struct osd_bitmap *bitmap )
{
 int color = firetruck_invert_display?3:7;
 int x,y,tile_number;
 const UINT8 *source = videoram;
 for( x=0; x<=256-16; x+=256-16 )
 {
  for( y=0; y<256; y+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[0],
    tile_number,
    color,
    0,0,
    x,y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

canonical_original_code:
static void draw_text(struct osd_bitmap *bitmap)
{
 int color = firetruck_invert_display?3:7;
 int x; int y; int tile_number;
 unsigned char *source = videoram;
 for( x=0; x<=256-16; x+=256-16 )
 {
  for( y=0; y<256; y+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[0],
    tile_number,
    color,
    0,0,
    x,y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

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


original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
 int color = firetruck_invert_display?3:7;
 int track_color = Machine->pens[firetruck_invert_display?0:3];
 int bgcolor = firetruck_invert_display?4:0;
 int cabrot = videoram[0x1080];
 int hpos = videoram[0x1460];
 int vpos = videoram[0x1480];
 int tailrot = videoram[0x14a0];
 int pen;
 int sx, sy;
 int x,y;
 int flipx,flipy;
 int pitch;
 pitch = (bitmap->depth==8)?bitmap->width:(bitmap->width*2);
 for( sy=0; sy<bitmap->height; sy++ )
 {
  memcpy( buf->line[sy], bitmap->line[sy], pitch );
 }
 flipx = tailrot&0x08;
 flipy = tailrot&0x10;
 sx = flipx?(hpos-47):(255-hpos-47);
 sy = flipy?(sy = vpos-47):(255-vpos-47);
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  bgcolor,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  bgcolor,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 if( bitmap->depth==8 )
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = buf->line[y][x];
    if( pen != bitmap->line[y][x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 else
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = ((UINT16 *)buf->line[y])[x];
    if( pen != ((UINT16 *)bitmap->line[y])[x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  color,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  color,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int color = firetruck_invert_display?3:7;
 int track_color = Machine->pens[firetruck_invert_display?0:3];
 int bgcolor = firetruck_invert_display?4:0;
 int cabrot = videoram[0x1080];
 int hpos = videoram[0x1460];
 int vpos = videoram[0x1480];
 int tailrot = videoram[0x14a0];
 int pen;
 int sx; int sy;
 int x; int y;
 int flipx; int flipy;
 int pitch;
 pitch = (bitmap->depth==8)?bitmap->width:(bitmap->width*2);
 for( sy=0; sy<bitmap->height; sy++ )
 {
  memcpy( buf->line[sy], bitmap->line[sy], pitch );
 }
 flipx = tailrot&0x08;
 flipy = tailrot&0x10;
 sx = flipx?(hpos-47):(255-hpos-47);
 sy = flipy?(sy = vpos-47):(255-vpos-47);
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  bgcolor,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  bgcolor,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 if( bitmap->depth==8 )
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = buf->line[y][x];
    if( pen != bitmap->line[y][x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 else
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = ((unsigned short *)buf->line[y])[x];
    if( pen != ((unsigned short *)bitmap->line[y])[x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  color,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  color,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
}

variable_types: bgcolor int

variable_types: cabrot int

variable_types: hpos int

variable_types: vpos int

variable_types: tailrot int

variable_types: pen int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: pitch int


decompiled_code:
unsigned __int64 __fastcall init_palette(__int64 a1, __m128i *a2)
{
unsigned __int64 result; // rax

result = 0xAAAA555555000000LL;
*(_QWORD *)a1 = 0xAAAA555555000000LL;
*(_DWORD *)(a1 + 8) = -86;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_8F0);
return result;
}

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

result = 0xAAAA555555000000LL;
*(_QWORD *)a1 = 0xAAAA555555000000LL;
*(_DWORD *)(a1 + 8) = -86;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_8F0);
return result;
}

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

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


bit

decompiled_code:
__int64 __fastcall bit(int a1, char a2)
{
return (a1 >> a2) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char a2)
{
return (a1 >> a2) & 1;
}

original_code:
static int bit(int i,int n)
{
 return ((i >> n) & 1);
}

canonical_original_code:
static int bit(int i, int n)
{
 return ((i >> n) & 1);
}

variable_types: i int

variable_types: n int


decompiled_code:
__int64 scobra_init_machine()
{
return interrupt_enable_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return interrupt_enable_w(0LL, 0LL);
}

original_code:
static void scobra_init_machine(void)
{
 interrupt_enable_w(0,0);
}

canonical_original_code:
static void scobra_init_machine()
{
 interrupt_enable_w(0,0);
}


decompiled_code:
__int64 __fastcall stratgyx_coin_counter_w(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

original_code:
static void stratgyx_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(offset >> 1, data);
}

canonical_original_code:
static void stratgyx_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(offset >> 1, data);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 init_moonwar2()
{
return install_mem_read_handler(0LL, 38912LL, 38912LL, moonwar2_IN0_r);
}

canonical_decompiled_code:
__int64 func3()
{
return install_mem_read_handler(0LL, 38912LL, 38912LL, moonwar2_IN0_r);
}

original_code:
static void init_moonwar2(void)
{
 install_mem_read_handler(0, 0x9800, 0x9800, moonwar2_IN0_r);
}

canonical_original_code:
static void init_moonwar2()
{
 install_mem_read_handler(0, 0x9800, 0x9800, moonwar2_IN0_r);
}


decompiled_code:
__int64 moonwar2_IN0_r()
{
int v0; // ebx

v0 = readinputport(3LL);
return (v0 >> 3) & 0x10 | v0 & 0xF | (unsigned int)(readinputport(0LL) & 0xE0);
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx

v0 = readinputport(3LL);
return (v0 >> 3) & 0x10 | v0 & 0xF | (unsigned int)(readinputport(0LL) & 0xE0);
}

original_code:
static data_t moonwar2_IN0_r(offs_t offset)
{
 int sign;
 int delta;
 delta = readinputport(3);
 sign = (delta & 0x80) >> 3;
 delta &= 0x0f;
 return ((readinputport(0) & 0xe0) | delta | sign );
}

canonical_original_code:
static unsigned int moonwar2_IN0_r(unsigned int offset)
{
 int sign;
 int delta;
 delta = readinputport(3);
 sign = (delta & 0x80) >> 3;
 delta &= 0x0f;
 return ((readinputport(0) & 0xe0) | delta | sign );
}

variable_types: sign int

variable_types: delta int


decompiled_code:
__int64 init_anteater()
{
__int64 v0; // r12
__int64 i; // rbp
int v2; // er14
int v3; // er14
int v4; // ebx
int v5; // eax
int v6; // er13
int v7; // ebx
unsigned int v8; // eax
__int64 result; // rax

v0 = memory_region(137LL);
for ( i = 0LL; i != 4096; ++i )
{
v2 = bit(i, 4);
v3 = bit(i, 9) ^ v2;
v4 = bit(i, 2);
v5 = bit(i, 10);
v6 = ((v3 ^ v5 & v4) << 6) | i & 0x9BF | ((v4 ^ v5) << 9);
v7 = bit(i, 0);
v8 = (v7 ^ (unsigned int)bit(i, 6)) << 10;
BYTE1(v8) ^= 4u;
result = *(unsigned __int8 *)(v0 + (int)(v6 | v8) + 4096);
*(_BYTE *)(v0 + i) = result;
}
return result;
}

original_code:
static void init_anteater(void)
{
 int i,j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0x9bf;
  j |= ( bit(i,4) ^ bit(i,9) ^ ( bit(i,2) & bit(i,10) ) ) << 6;
  j |= ( bit(i,2) ^ bit(i,10) ) << 9;
  j |= ( bit(i,0) ^ bit(i,6) ^ 1 ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}

canonical_original_code:
static void init_anteater()
{
 int i; int j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0x9bf;
  j |= ( bit(i,4) ^ bit(i,9) ^ ( bit(i,2) & bit(i,10) ) ) << 6;
  j |= ( bit(i,2) ^ bit(i,10) ) << 9;
  j |= ( bit(i,0) ^ bit(i,6) ^ 1 ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}

variable_types: j int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 init_rescue()
{
__int64 v0; // r12
__int64 i; // rbp
int v2; // er15
int v3; // er14
int v4; // ebx
unsigned int v5; // er14
int v6; // ebx
__int64 result; // rax

v0 = memory_region(137LL);
for ( i = 0LL; i != 4096; ++i )
{
v2 = bit(i, 3);
v3 = bit(i, 10);
v4 = bit(i, 1);
v5 = (((unsigned int)bit(i, 7) ^ v4) << 8) | ((v3 ^ v2) << 7);
v6 = bit(i, 0);
result = *(unsigned __int8 *)(v0 + (int)(i & 0xA7F | v5 | ((v6 ^ (unsigned int)bit(i, 8)) << 10)) + 4096);
*(_BYTE *)(v0 + i) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // r12
__int64 i; // rbp
int v2; // er15
int v3; // er14
int v4; // ebx
unsigned int v5; // er14
int v6; // ebx
__int64 result; // rax

v0 = memory_region(137LL);
for ( i = 0LL; i != 4096; ++i )
{
v2 = func0(i, 3);
v3 = func0(i, 10);
v4 = func0(i, 1);
v5 = (((unsigned int)func0(i, 7) ^ v4) << 8) | ((v3 ^ v2) << 7);
v6 = func0(i, 0);
result = *(unsigned __int8 *)(v0 + (int)(i & 0xA7F | v5 | ((v6 ^ (unsigned int)func0(i, 8)) << 10)) + 4096);
*(_BYTE *)(v0 + i) = result;
}
return result;
}

original_code:
static void init_rescue(void)
{
 int i,j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xa7f;
  j |= ( bit(i,3) ^ bit(i,10) ) << 7;
  j |= ( bit(i,1) ^ bit(i,7) ) << 8;
  j |= ( bit(i,0) ^ bit(i,8) ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}

canonical_original_code:
static void init_rescue()
{
 int i; int j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xa7f;
  j |= ( bit(i,3) ^ bit(i,10) ) << 7;
  j |= ( bit(i,1) ^ bit(i,7) ) << 8;
  j |= ( bit(i,0) ^ bit(i,8) ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}


original_code:
static void init_minefld(void)
{
 int i,j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xd5f;
  j |= ( bit(i,3) ^ bit(i,7) ) << 5;
  j |= ( bit(i,2) ^ bit(i,9) ^ ( bit(i,0) & bit(i,5) ) ^
    ( bit(i,3) & bit(i,7) & ( bit(i,0) ^ bit(i,5) ))) << 7;
  j |= ( bit(i,0) ^ bit(i,5) ^ ( bit(i,3) & bit(i,7) ) ) << 9;
  RAM[i] = RAM[j + 0x1000];
 }
}

canonical_original_code:
static void init_minefld()
{
 int i; int j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xd5f;
  j |= ( bit(i,3) ^ bit(i,7) ) << 5;
  j |= ( bit(i,2) ^ bit(i,9) ^ ( bit(i,0) & bit(i,5) ) ^
    ( bit(i,3) & bit(i,7) & ( bit(i,0) ^ bit(i,5) ))) << 7;
  j |= ( bit(i,0) ^ bit(i,5) ^ ( bit(i,3) & bit(i,7) ) ) << 9;
  RAM[i] = RAM[j + 0x1000];
 }
}


original_code:
static void init_superbon(void)
{
 int i;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 for (i = 0;i < 0x1000;i++)
 {
  switch (i & 0x280)
  {
   case 0x000:
    RAM[i] ^= 0x92;
    break;
   case 0x080:
    RAM[i] ^= 0x82;
    break;
   case 0x200:
    RAM[i] ^= 0x12;
    break;
   case 0x280:
    RAM[i] ^= 0x10;
    break;
  }
 }
}

canonical_original_code:
static void init_superbon()
{
 int i;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 for (i = 0;i < 0x1000;i++)
 {
  switch (i & 0x280)
  {
   case 0x000:
    RAM[i] ^= 0x92;
    break;
   case 0x080:
    RAM[i] ^= 0x82;
    break;
   case 0x200:
    RAM[i] ^= 0x12;
    break;
   case 0x280:
    RAM[i] ^= 0x10;
    break;
  }
 }
}


original_code:
static void init_hustler(void)
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0xff;
  if (bits[0] ^ bits[1]) xormask ^= 0x01;
  if (bits[3] ^ bits[6]) xormask ^= 0x02;
  if (bits[4] ^ bits[5]) xormask ^= 0x04;
  if (bits[0] ^ bits[2]) xormask ^= 0x08;
  if (bits[2] ^ bits[3]) xormask ^= 0x10;
  if (bits[1] ^ bits[5]) xormask ^= 0x20;
  if (bits[0] ^ bits[7]) xormask ^= 0x40;
  if (bits[4] ^ bits[6]) xormask ^= 0x80;
  RAM[A] ^= xormask;
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}

canonical_original_code:
static void init_hustler()
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0xff;
  if (bits[0] ^ bits[1]) xormask ^= 0x01;
  if (bits[3] ^ bits[6]) xormask ^= 0x02;
  if (bits[4] ^ bits[5]) xormask ^= 0x04;
  if (bits[0] ^ bits[2]) xormask ^= 0x08;
  if (bits[2] ^ bits[3]) xormask ^= 0x10;
  if (bits[1] ^ bits[5]) xormask ^= 0x20;
  if (bits[0] ^ bits[7]) xormask ^= 0x40;
  if (bits[4] ^ bits[6]) xormask ^= 0x80;
  RAM[A] ^= xormask;
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}

variable_types: A int

variable_types:
xormask
unsigned char

variable_types:
bits
int [8]


original_code:
static void init_billiard(void)
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0x55;
  if (bits[2] ^ ( bits[3] & bits[6])) xormask ^= 0x01;
  if (bits[4] ^ ( bits[5] & bits[7])) xormask ^= 0x02;
  if (bits[0] ^ ( bits[7] & !bits[3])) xormask ^= 0x04;
  if (bits[3] ^ (!bits[0] & bits[2])) xormask ^= 0x08;
  if (bits[5] ^ (!bits[4] & bits[1])) xormask ^= 0x10;
  if (bits[6] ^ (!bits[2] & !bits[5])) xormask ^= 0x20;
  if (bits[1] ^ (!bits[6] & !bits[4])) xormask ^= 0x40;
  if (bits[7] ^ (!bits[1] & bits[0])) xormask ^= 0x80;
  RAM[A] ^= xormask;
  for (i = 0;i < 8;i++)
   bits[i] = (RAM[A] >> i) & 1;
  RAM[A] =
   (bits[7] << 0) +
   (bits[0] << 1) +
   (bits[3] << 2) +
   (bits[4] << 3) +
   (bits[5] << 4) +
   (bits[2] << 5) +
   (bits[1] << 6) +
   (bits[6] << 7);
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}

canonical_original_code:
static void init_billiard()
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0x55;
  if (bits[2] ^ ( bits[3] & bits[6])) xormask ^= 0x01;
  if (bits[4] ^ ( bits[5] & bits[7])) xormask ^= 0x02;
  if (bits[0] ^ ( bits[7] & !bits[3])) xormask ^= 0x04;
  if (bits[3] ^ (!bits[0] & bits[2])) xormask ^= 0x08;
  if (bits[5] ^ (!bits[4] & bits[1])) xormask ^= 0x10;
  if (bits[6] ^ (!bits[2] & !bits[5])) xormask ^= 0x20;
  if (bits[1] ^ (!bits[6] & !bits[4])) xormask ^= 0x40;
  if (bits[7] ^ (!bits[1] & bits[0])) xormask ^= 0x80;
  RAM[A] ^= xormask;
  for (i = 0;i < 8;i++)
   bits[i] = (RAM[A] >> i) & 1;
  RAM[A] =
   (bits[7] << 0) +
   (bits[0] << 1) +
   (bits[3] << 2) +
   (bits[4] << 3) +
   (bits[5] << 4) +
   (bits[2] << 5) +
   (bits[1] << 6) +
   (bits[6] << 7);
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}


original_code:
void hc55516_update(int num, INT16 *buffer, int length)
{
 struct hc55516_data *chip = &hc55516[num];
 INT32 data, slope;
 int i;
 if (length == 0)
  return;
 chip->update_count += length;
 if (chip->update_count > Machine->sample_rate / 32)
 {
  chip->update_count = Machine->sample_rate;
  chip->next_value = 0;
 }
 data = chip->curr_value;
 slope = ((INT32)chip->next_value - data) / length;
 chip->curr_value = chip->next_value;
 for (i = 0; i < length; i++, data += slope)
  *buffer++ = data;
}

canonical_original_code:
void hc55516_update(int num, short *buffer, int length)
{
 struct hc55516_data *chip = &hc55516[num];
 int data; int slope;
 int i;
 if (length == 0)
  return;
 chip->update_count += length;
 if (chip->update_count > Machine->sample_rate / 32)
 {
  chip->update_count = Machine->sample_rate;
  chip->next_value = 0;
 }
 data = chip->curr_value;
 slope = ((int)chip->next_value - data) / length;
 chip->curr_value = chip->next_value;
 for (i = 0; i < length; i++, data += slope)
  *buffer++ = data;
}

variable_types: num int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct hc55516_data { char channel; unsigned char last_clock; unsigned char databit; unsigned char shiftreg; short curr_value; short next_value; unsigned int update_count; float filter; float integrator; } *

variable_types: data int

variable_types: slope int


decompiled_code:
__int64 __fastcall hc55516_sh_start(__int64 a1)
{
int *v1; // r12
_QWORD *v2; // rbp
__int64 v3; // rbx
char v4; // al
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(int **)(a1 + 8);
charge = LC0;
decay = LC0;
leak = 1064336736;
if ( *v1 <= 0 )
return 0LL;
v2 = &hc55516;
v3 = 0LL;
while ( 1 )
{
*v2 = 0LL;
v2[1] = 0LL;
*((_DWORD *)v2 + 4) = 0;
sprintf(v6, "HC55516 #%d", (unsigned int)v3);
v4 = stream_init(v6, LOBYTE(v1[v3 + 1]), *(unsigned int *)(Machine + 836LL), (unsigned int)v3, hc55516_update);
*(_BYTE *)v2 = v4;
if ( v4 == -1 )
break;
++v3;
v2 = (_QWORD *)((char *)v2 + 20);
if ( *v1 <= (int)v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int *v1; // r12
_QWORD *v2; // rbp
__int64 v3; // rbx
char v4; // al
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(int **)(a1 + 8);
charge = LC0;
decay = LC0;
leak = 1064336736;
if ( *v1 <= 0 )
return 0LL;
v2 = &hc55516;
v3 = 0LL;
while ( 1 )
{
*v2 = 0LL;
v2[1] = 0LL;
*((_DWORD *)v2 + 4) = 0;
sprintf(v6, "HC55516 #%d", (unsigned int)v3);
v4 = stream_init(v6, LOBYTE(v1[v3 + 1]), *(unsigned int *)(Machine + 836LL), (unsigned int)v3, hc55516_update);
*(_BYTE *)v2 = v4;
if ( v4 == -1 )
break;
++v3;
v2 = (_QWORD *)((char *)v2 + 20);
if ( *v1 <= (int)v3 )
return 0LL;
}
return 1LL;
}

original_code:
int hc55516_sh_start(const struct MachineSound *msound)
{
 const struct hc55516_interface *intf = (const struct hc55516_interface *)msound->sound_interface;
 int i;
 charge = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 decay = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 leak = pow(exp(-1), 1.0 / (0.001 * 16000.0));
 for (i = 0; i < intf->num; i++)
 {
  struct hc55516_data *chip = &hc55516[i];
  char name[40];
  memset(chip, 0, sizeof(*chip));
  sprintf(name, "HC55516 #%d", i);
  chip->channel = stream_init(name, intf->volume[i] & 0xff, Machine->sample_rate, i, hc55516_update);
  if (chip->channel == -1)
   return 1;
 }
 return 0;
}

canonical_original_code:
int hc55516_sh_start(struct MachineSound *msound)
{
 struct hc55516_interface *intf = (const struct hc55516_interface *)msound->sound_interface;
 int i;
 charge = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 decay = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 leak = pow(exp(-1), 1.0 / (0.001 * 16000.0));
 for (i = 0; i < intf->num; i++)
 {
  struct hc55516_data *chip = &hc55516[i];
  char name[40];
  memset(chip, 0, sizeof(*chip));
  sprintf(name, "HC55516 #%d", i);
  chip->channel = stream_init(name, intf->volume[i] & 0xff, Machine->sample_rate, i, hc55516_update);
  if (chip->channel == -1)
   return 1;
 }
 return 0;
}

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

variable_types: struct hc55516_interface { int num; int volume[4]; } *

variable_types: i int

variable_types:
name
char [40]

user_defined_types: struct hc55516_data { char channel; unsigned char last_clock; unsigned char databit; unsigned char shiftreg; short curr_value; short next_value; unsigned int update_count; float filter; float integrator; }


original_code:
void hc55516_clock_w(int num, int state)
{
 struct hc55516_data *chip = &hc55516[num];
 int clock = state & 1, diffclock;
 diffclock = clock ^ chip->last_clock;
 chip->last_clock = clock;
 if (diffclock && clock)
 {
  float integrator = chip->integrator, temp;
  chip->update_count = 0;
  if (chip->databit)
  {
   chip->shiftreg = ((chip->shiftreg << 1) | 1) & 7;
   integrator += chip->filter;
  }
  else
  {
   chip->shiftreg = (chip->shiftreg << 1) & 7;
   integrator -= chip->filter;
  }
  integrator *= leak;
  if (chip->shiftreg == 0 || chip->shiftreg == 7)
  {
   chip->filter = 1.0954 - ((1.0954 - chip->filter) * charge);
   if (chip->filter > 1.0954)
    chip->filter = 1.0954;
  }
  else
  {
   chip->filter *= decay;
   if (chip->filter < 0.0416)
    chip->filter = 0.0416;
  }
  temp = integrator * 10000.0;
  chip->integrator = integrator;
  if (temp < 0)
   chip->next_value = (int)(temp / (-temp * (1.0 / 32768.0) + 1.0));
  else
   chip->next_value = (int)(temp / (temp * (1.0 / 32768.0) + 1.0));
        {
            extern int fast_sound;
            if (!fast_sound) stream_update(chip->channel, 0);
        }
 }
}

canonical_original_code:
void hc55516_clock_w(int num, int state)
{
 struct hc55516_data *chip = &hc55516[num];
 int clock = state & 1; int diffclock;
 diffclock = clock ^ chip->last_clock;
 chip->last_clock = clock;
 if (diffclock && clock)
 {
  float integrator = chip->integrator; float temp;
  chip->update_count = 0;
  if (chip->databit)
  {
   chip->shiftreg = ((chip->shiftreg << 1) | 1) & 7;
   integrator += chip->filter;
  }
  else
  {
   chip->shiftreg = (chip->shiftreg << 1) & 7;
   integrator -= chip->filter;
  }
  integrator *= leak;
  if (chip->shiftreg == 0 || chip->shiftreg == 7)
  {
   chip->filter = 1.0954 - ((1.0954 - chip->filter) * charge);
   if (chip->filter > 1.0954)
    chip->filter = 1.0954;
  }
  else
  {
   chip->filter *= decay;
   if (chip->filter < 0.0416)
    chip->filter = 0.0416;
  }
  temp = integrator * 10000.0;
  chip->integrator = integrator;
  if (temp < 0)
   chip->next_value = (int)(temp / (-temp * (1.0 / 32768.0) + 1.0));
  else
   chip->next_value = (int)(temp / (temp * (1.0 / 32768.0) + 1.0));
        {
            extern int fast_sound;
            if (!fast_sound) stream_update(chip->channel, 0);
        }
 }
}

variable_types: state int

variable_types: clock int

variable_types: diffclock int

variable_types: integrator float

variable_types: temp float


decompiled_code:
__int64 __fastcall hc55516_clock_clear_w(int a1)
{
return hc55516_clock_w(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return func2(a1, 0);
}

original_code:
void hc55516_clock_clear_w(int num, int data)
{
 hc55516_clock_w(num, 0);
}


decompiled_code:
__int64 __fastcall hc55516_clock_set_w(int a1)
{
return hc55516_clock_w(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return func2(a1, 1);
}

original_code:
void hc55516_clock_set_w(int num, int data)
{
 hc55516_clock_w(num, 1);
}


decompiled_code:
__int64 __fastcall hc55516_digit_clock_clear_w(int a1, char a2)
{
hc55516[20 * a1 + 2] = a2 & 1;
return hc55516_clock_w(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, char a2)
{
hc55516[20 * a1 + 2] = a2 & 1;
return func2(a1, 0);
}

original_code:
void hc55516_digit_clock_clear_w(int num, int data)
{
 hc55516[num].databit = data & 1;
 hc55516_clock_w(num, 0);
}


decompiled_code:
__int64 __fastcall hc55516_0_clock_w(__int64 a1, char a2)
{
return hc55516_clock_w(0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
return func2(0, a2);
}

original_code: void hc55516_0_clock_w(offs_t offset,data_t data) { hc55516_clock_w(0,data); }

canonical_original_code: void hc55516_0_clock_w(unsigned int offset, unsigned int data) { hc55516_clock_w(0,data); }

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 hc55516_0_clock_clear_w()
{
return hc55516_clock_clear_w(0);
}

canonical_decompiled_code:
__int64 func7()
{
return func3(0);
}

original_code: void hc55516_0_clock_clear_w(offs_t offset,data_t data) { hc55516_clock_clear_w(0,data); }

canonical_original_code: void hc55516_0_clock_clear_w(unsigned int offset, unsigned int data) { hc55516_clock_clear_w(0,data); }


decompiled_code:
__int64 hc55516_0_clock_set_w()
{
return hc55516_clock_set_w(0);
}

canonical_decompiled_code:
__int64 func8()
{
return func4(0);
}

original_code: void hc55516_0_clock_set_w(offs_t offset,data_t data) { hc55516_clock_set_w(0,data); }

canonical_original_code: void hc55516_0_clock_set_w(unsigned int offset, unsigned int data) { hc55516_clock_set_w(0,data); }


decompiled_code:
__int64 __fastcall hc55516_0_digit_clock_clear_w(__int64 a1, char a2)
{
return hc55516_digit_clock_clear_w(0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
return func5(0, a2);
}

original_code: void hc55516_0_digit_clock_clear_w(offs_t offset,data_t data) { hc55516_digit_clock_clear_w(0,data); }

canonical_original_code: void hc55516_0_digit_clock_clear_w(unsigned int offset, unsigned int data) { hc55516_digit_clock_clear_w(0,data); }


original_code:
void naughtyb_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;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 2) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 1) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8]) = i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + j*64;
  }
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8]) = i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + 32 + j*64;
  }
 }
}

canonical_original_code:
void naughtyb_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;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 2) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 1) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8]) = i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + j*64;
  }
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8]) = i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + 32 + j*64;
  }
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: j int


decompiled_code:
__int64 naughtyb_vh_start()
{
size_t v0; // rbx
void *v1; // rdi
unsigned int v2; // edx

bankreg = 0;
palreg = 0;
videoreg = 0;
v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
tmpbitmap = bitmap_alloc(544LL, 224LL);
v2 = 0;
if ( !tmpbitmap )
{
free(dirtybuffer);
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 func2()
{
size_t v0; // rbx
void *v1; // rdi
unsigned int v2; // edx

bankreg = 0;
palreg = 0;
videoreg = 0;
v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
tmpbitmap = bitmap_alloc(544LL, 224LL);
v2 = 0;
if ( !tmpbitmap )
{
free(dirtybuffer);
v2 = 1;
}
return v2;
}

original_code:
int naughtyb_vh_start(void)
{
 videoreg = palreg = bankreg = 0;
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 if ((tmpbitmap = bitmap_alloc(68*8,28*8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

canonical_original_code:
int naughtyb_vh_start()
{
 videoreg = palreg = bankreg = 0;
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 if ((tmpbitmap = bitmap_alloc(68*8,28*8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}


decompiled_code:
void naughtyb_vh_stop()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

canonical_decompiled_code:
void func3()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

original_code:
void naughtyb_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 free(dirtybuffer);
}