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

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

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

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

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

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


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall xain_vh_screenrefresh(__int64 a1)
{
_QWORD *v1; // rdx
__int64 result; // rax

tilemap_update(0LL);
palette_init_used_colors();
v1 = (_QWORD *)palette_used_colors;
*(_QWORD *)(palette_used_colors + 128LL) = 0x303030303030303LL;
v1[17] = 0x303030303030303LL;
v1[18] = 0x303030303030303LL;
v1[19] = 0x303030303030303LL;
v1[20] = 0x303030303030303LL;
v1[21] = 0x303030303030303LL;
v1[22] = 0x303030303030303LL;
v1[23] = 0x303030303030303LL;
v1[24] = 0x303030303030303LL;
v1[25] = 0x303030303030303LL;
v1[26] = 0x303030303030303LL;
v1[27] = 0x303030303030303LL;
v1[28] = 0x303030303030303LL;
v1[29] = 0x303030303030303LL;
v1[30] = 0x303030303030303LL;
v1[31] = 0x303030303030303LL;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
switch ( xain_pri & 7 )
{
case 0:
tilemap_draw(a1, bgram0_tilemap, 0LL);
tilemap_draw(a1, bgram1_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
case 1:
tilemap_draw(a1, bgram1_tilemap, 0LL);
tilemap_draw(a1, bgram0_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
case 2:
tilemap_draw(a1, char_tilemap, 0LL);
tilemap_draw(a1, bgram0_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram1_tilemap, 0LL);
break;
case 3:
tilemap_draw(a1, char_tilemap, 0LL);
tilemap_draw(a1, bgram1_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram0_tilemap, 0LL);
break;
case 4:
tilemap_draw(a1, bgram0_tilemap, 0LL);
tilemap_draw(a1, char_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram1_tilemap, 0LL);
break;
case 5:
tilemap_draw(a1, bgram1_tilemap, 0LL);
tilemap_draw(a1, char_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram0_tilemap, 0LL);
break;
case 6:
tilemap_draw(a1, bgram0_tilemap, 0LL);
draw_sprites(a1);
tilemap_draw(a1, bgram1_tilemap, 0LL);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
case 7:
tilemap_draw(a1, bgram1_tilemap, 0LL);
draw_sprites(a1);
tilemap_draw(a1, bgram0_tilemap, 0LL);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
_QWORD *v1; // rdx
__int64 result; // rax

tilemap_update(0LL);
palette_init_used_colors();
v1 = (_QWORD *)palette_used_colors;
*(_QWORD *)(palette_used_colors + 128LL) = 0x303030303030303LL;
v1[17] = 0x303030303030303LL;
v1[18] = 0x303030303030303LL;
v1[19] = 0x303030303030303LL;
v1[20] = 0x303030303030303LL;
v1[21] = 0x303030303030303LL;
v1[22] = 0x303030303030303LL;
v1[23] = 0x303030303030303LL;
v1[24] = 0x303030303030303LL;
v1[25] = 0x303030303030303LL;
v1[26] = 0x303030303030303LL;
v1[27] = 0x303030303030303LL;
v1[28] = 0x303030303030303LL;
v1[29] = 0x303030303030303LL;
v1[30] = 0x303030303030303LL;
v1[31] = 0x303030303030303LL;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
switch ( xain_pri & 7 )
{
case 0:
tilemap_draw(a1, bgram0_tilemap, 0LL);
tilemap_draw(a1, bgram1_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
case 1:
tilemap_draw(a1, bgram1_tilemap, 0LL);
tilemap_draw(a1, bgram0_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
case 2:
tilemap_draw(a1, char_tilemap, 0LL);
tilemap_draw(a1, bgram0_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram1_tilemap, 0LL);
break;
case 3:
tilemap_draw(a1, char_tilemap, 0LL);
tilemap_draw(a1, bgram1_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram0_tilemap, 0LL);
break;
case 4:
tilemap_draw(a1, bgram0_tilemap, 0LL);
tilemap_draw(a1, char_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram1_tilemap, 0LL);
break;
case 5:
tilemap_draw(a1, bgram1_tilemap, 0LL);
tilemap_draw(a1, char_tilemap, 0LL);
draw_sprites(a1);
result = tilemap_draw(a1, bgram0_tilemap, 0LL);
break;
case 6:
tilemap_draw(a1, bgram0_tilemap, 0LL);
draw_sprites(a1);
tilemap_draw(a1, bgram1_tilemap, 0LL);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
case 7:
tilemap_draw(a1, bgram1_tilemap, 0LL);
draw_sprites(a1);
tilemap_draw(a1, bgram0_tilemap, 0LL);
result = tilemap_draw(a1, char_tilemap, 0LL);
break;
}
return result;
}

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

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

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


decompiled_code:
_BYTE *init_xsleena()
{
_BYTE *result; // rax

result = (_BYTE *)memory_region(129LL);
result[54408] = 18;
result[54409] = 18;
result[54410] = 18;
result[54411] = 18;
result[54412] = 18;
result[54413] = 18;
return result;
}

canonical_decompiled_code:
_BYTE *func15()
{
_BYTE *result; // rax

result = (_BYTE *)memory_region(129LL);
result[54408] = 18;
result[54409] = 18;
result[54410] = 18;
result[54411] = 18;
result[54412] = 18;
result[54413] = 18;
return result;
}

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

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

variable_types:
RAM
unsigned char *


decompiled_code:
_BYTE *init_solarwar()
{
_BYTE *result; // rax

result = (_BYTE *)memory_region(129LL);
result[54398] = 18;
result[54399] = 18;
result[54400] = 18;
result[54401] = 18;
result[54402] = 18;
result[54403] = 18;
return result;
}

canonical_decompiled_code:
_BYTE *func16()
{
_BYTE *result; // rax

result = (_BYTE *)memory_region(129LL);
result[54398] = 18;
result[54399] = 18;
result[54400] = 18;
result[54401] = 18;
result[54402] = 18;
result[54403] = 18;
return result;
}

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

return_type: int


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

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

variable_types:
col
unsigned int

variable_types:
row
unsigned int

return_type: unsigned int


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

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

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

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

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

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

variable_types: attr int

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


irqhandler

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

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

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

variable_types: irq int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: bits int


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
void *__fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
unsigned int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
unsigned int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

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

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

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

variable_types:
attr
unsigned char

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


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

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

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

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

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

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


decompiled_code:
void *__fastcall draw_sprites(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v3; // rbx
unsigned __int8 v4; // dl

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

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v3; // rbx
unsigned __int8 v4; // dl

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

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

variable_types: offs int


decompiled_code:
__int64 solomon_vh_start()
{
unsigned int v0; // ebx
__int64 v2; // rbp
size_t v3; // r12
void *v4; // rdi
__int64 i; // rax

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

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
__int64 v2; // rbp
size_t v3; // r12
void *v4; // rdi
__int64 i; // rax

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

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

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


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

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

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, char a2)
{
void *result; // rax

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

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

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


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

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

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

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


decompiled_code:
void *__fastcall solomon_vh_screenrefresh(__int64 a1)
{
size_t v1; // rbx
int v2; // ebx
__int64 v3; // rbp
void *result; // rax
int v5; // ebp
__int64 v6; // rbx

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
if ( videoram_size )
{
v1 = 0LL;
do
{
if ( *((_BYTE *)dirtybuffer2 + v1) )
{
*((_BYTE *)dirtybuffer2 + v1) = 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(solomon_bgvideoram + v1)
+ ((unsigned __int8)(*(_BYTE *)(solomon_bgcolorram + v1) & 7) << 8),
((int)*(unsigned __int8 *)(solomon_bgcolorram + v1) >> 4) & 7);
}
++v1;
}
while ( videoram_size > v1 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 7) << 8),
(*(unsigned __int8 *)(colorram + v3) >> 4) & 7);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
result = &spriteram_size;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v6 - 3) + 16 * (*(_BYTE *)(spriteram + v6 - 2) & 0x10u),
((int)*(unsigned __int8 *)(spriteram + v6 - 2) >> 1) & 7);
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1)
{
size_t v1; // rbx
int v2; // ebx
__int64 v3; // rbp
void *result; // rax
int v5; // ebp
__int64 v6; // rbx

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
if ( videoram_size )
{
v1 = 0LL;
do
{
if ( *((_BYTE *)dirtybuffer2 + v1) )
{
*((_BYTE *)dirtybuffer2 + v1) = 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(solomon_bgvideoram + v1)
+ ((unsigned __int8)(*(_BYTE *)(solomon_bgcolorram + v1) & 7) << 8),
((int)*(unsigned __int8 *)(solomon_bgcolorram + v1) >> 4) & 7);
}
++v1;
}
while ( videoram_size > v1 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 7) << 8),
(*(unsigned __int8 *)(colorram + v3) >> 4) & 7);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
result = &spriteram_size;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v6 - 3) + 16 * (*(_BYTE *)(spriteram + v6 - 2) & 0x10u),
((int)*(unsigned __int8 *)(spriteram + v6 - 2) >> 1) & 7);
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
return result;
}

original_code:
void solomon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
 {
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
 for (offs = 0;offs < videoram_size;offs++)
 {
  if (dirtybuffer2[offs])
  {
   int sx,sy,flipx,flipy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = solomon_bgcolorram[offs] & 0x80;
   flipy = solomon_bgcolorram[offs] & 0x08;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     solomon_bgvideoram[offs] + 256 * (solomon_bgcolorram[offs] & 0x07),
     ((solomon_bgcolorram[offs] & 0x70) >> 4),
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * (colorram[offs] & 0x07),
     (colorram[offs] & 0x70) >> 4,
     flipscreen,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs+3];
  sy = 241-spriteram[offs+2];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen & 1)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[2],
    spriteram[offs] + 16*(spriteram[offs+1] & 0x10),
    (spriteram[offs + 1] & 0x0e) >> 1,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void solomon_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
 {
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
 for (offs = 0;offs < videoram_size;offs++)
 {
  if (dirtybuffer2[offs])
  {
   int sx; int sy; int flipx; int flipy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = solomon_bgcolorram[offs] & 0x80;
   flipy = solomon_bgcolorram[offs] & 0x08;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     solomon_bgvideoram[offs] + 256 * (solomon_bgcolorram[offs] & 0x07),
     ((solomon_bgcolorram[offs] & 0x70) >> 4),
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * (colorram[offs] & 0x07),
     (colorram[offs] & 0x70) >> 4,
     flipscreen,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs+3];
  sy = 241-spriteram[offs+2];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen & 1)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[2],
    spriteram[offs] + 16*(spriteram[offs+1] & 0x10),
    (spriteram[offs + 1] & 0x0e) >> 1,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 generic_vh_start()
{
size_t v0; // rbx
__int64 result; // rax
void *v2; // rdi

dirtybuffer = 0LL;
tmpbitmap = 0LL;
v0 = videoram_size;
result = 1LL;
if ( videoram_size )
{
v2 = malloc(videoram_size);
dirtybuffer = v2;
if ( v2 )
{
memset(v2, 1, v0);
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
result = 0LL;
if ( !tmpbitmap )
{
free(dirtybuffer);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
size_t v0; // rbx
__int64 result; // rax
void *v2; // rdi

dirtybuffer = 0LL;
tmpbitmap = 0LL;
v0 = videoram_size;
result = 1LL;
if ( videoram_size )
{
v2 = malloc(videoram_size);
dirtybuffer = v2;
if ( v2 )
{
memset(v2, 1, v0);
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
result = 0LL;
if ( !tmpbitmap )
{
free(dirtybuffer);
result = 1LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int generic_vh_start(void)
{
 dirtybuffer = 0;
 tmpbitmap = 0;
 if (videoram_size == 0)
 {
  return 1;
 }
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

canonical_original_code:
int generic_vh_start()
{
 dirtybuffer = 0;
 tmpbitmap = 0;
 if (videoram_size == 0)
 {
  return 1;
 }
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}


decompiled_code:
_BOOL8 generic_bitmapped_vh_start()
{
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
return tmpbitmap == 0LL;
}

canonical_decompiled_code:
_BOOL8 func1()
{
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
return tmpbitmap == 0LL;
}

original_code:
int generic_bitmapped_vh_start(void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int generic_bitmapped_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  return 1;
 }
 return 0;
}


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

free(dirtybuffer);
result = bitmap_free(tmpbitmap);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
return result;
}

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

free(dirtybuffer);
result = bitmap_free(tmpbitmap);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
return result;
}

original_code:
void generic_vh_stop(void)
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
 dirtybuffer = 0;
 tmpbitmap = 0;
}

canonical_original_code:
void generic_vh_stop()
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
 dirtybuffer = 0;
 tmpbitmap = 0;
}


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

result = bitmap_free(tmpbitmap);
tmpbitmap = 0LL;
return result;
}

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

result = bitmap_free(tmpbitmap);
tmpbitmap = 0LL;
return result;
}

original_code:
void generic_bitmapped_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 tmpbitmap = 0;
}

canonical_original_code:
void generic_bitmapped_vh_stop()
{
 bitmap_free(tmpbitmap);
 tmpbitmap = 0;
}


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

if ( a2 )
result = copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return result;
}

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

if ( a2 )
result = copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return result;
}

original_code:
void generic_bitmapped_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (full_refresh)
  copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void generic_bitmapped_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (full_refresh)
  copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

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


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

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

original_code:
data_t videoram_r(offs_t offset)
{
 return videoram[offset];
}

canonical_original_code:
unsigned int videoram_r(unsigned int offset)
{
 return videoram[offset];
}


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

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

original_code:
data_t colorram_r(offs_t offset)
{
 return colorram[offset];
}

canonical_original_code:
unsigned int colorram_r(unsigned int offset)
{
 return colorram[offset];
}


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

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

original_code:
data_t spriteram_2_r(offs_t offset)
{
 return spriteram_2[offset];
}

canonical_original_code:
unsigned int spriteram_2_r(unsigned int offset)
{
 return spriteram_2[offset];
}


decompiled_code:
void *buffer_spriteram_w()
{
return memcpy(buffered_spriteram, spriteram, spriteram_size);
}

canonical_decompiled_code:
void *func13()
{
return memcpy(buffered_spriteram, spriteram, spriteram_size);
}

original_code:
void buffer_spriteram_w(offs_t offset,data_t data)
{
 memcpy(buffered_spriteram,spriteram,spriteram_size);
}

canonical_original_code:
void buffer_spriteram_w(unsigned int offset, unsigned int data)
{
 memcpy(buffered_spriteram,spriteram,spriteram_size);
}


decompiled_code:
void *buffer_spriteram_2_w()
{
return memcpy(buffered_spriteram_2, spriteram_2, spriteram_2_size);
}

canonical_decompiled_code:
void *func14()
{
return memcpy(buffered_spriteram_2, spriteram_2, spriteram_2_size);
}

original_code:
void buffer_spriteram_2_w(offs_t offset,data_t data)
{
 memcpy(buffered_spriteram_2,spriteram_2,spriteram_2_size);
}

canonical_original_code:
void buffer_spriteram_2_w(unsigned int offset, unsigned int data)
{
 memcpy(buffered_spriteram_2,spriteram_2,spriteram_2_size);
}


decompiled_code:
void *__fastcall buffer_spriteram(void *src, int a2)
{
return memcpy(buffered_spriteram, src, a2);
}

canonical_decompiled_code:
void *__fastcall func15(void *src, int a2)
{
return memcpy(buffered_spriteram, src, a2);
}

original_code:
void buffer_spriteram(unsigned char *ptr,int length)
{
 memcpy(buffered_spriteram,ptr,length);
}

canonical_original_code:
void buffer_spriteram(unsigned char *ptr, int length)
{
 memcpy(buffered_spriteram,ptr,length);
}

variable_types:
ptr
unsigned char *

variable_types: length int


decompiled_code:
void *__fastcall buffer_spriteram_2(void *src, int a2)
{
return memcpy(buffered_spriteram_2, src, a2);
}

canonical_decompiled_code:
void *__fastcall func16(void *src, int a2)
{
return memcpy(buffered_spriteram_2, src, a2);
}

original_code:
void buffer_spriteram_2(unsigned char *ptr,int length)
{
 memcpy(buffered_spriteram_2,ptr,length);
}

canonical_original_code:
void buffer_spriteram_2(unsigned char *ptr, int length)
{
 memcpy(buffered_spriteram_2,ptr,length);
}


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

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

original_code:
data_t spriteram_r(offs_t offset)
{
 return spriteram[offset];
}

canonical_original_code:
unsigned int spriteram_r(unsigned int offset)
{
 return spriteram[offset];
}


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

if ( power )
{
status ^= 0x80u;
timer = timer_set(
(unsigned int)(int)(float)((float)((float)time_msec * 1073741800.0) / 1000.0),
0LL,
ticket_dispenser_toggle);
}
if ( status != ticketdispensed )
return (_DWORD *)osd_led_w(2LL, 0LL);
osd_led_w(2LL, 1LL);
result = &dispensed_tickets;
++dispensed_tickets;
return result;
}

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

if ( power )
{
status ^= 0x80u;
timer = timer_set(
(unsigned int)(int)(float)((float)((float)time_msec * 1073741800.0) / 1000.0),
0LL,
ticket_dispenser_toggle);
}
if ( status != ticketdispensed )
return (_DWORD *)osd_led_w(2LL, 0LL);
osd_led_w(2LL, 1LL);
result = &dispensed_tickets;
++dispensed_tickets;
return result;
}

original_code:
static void ticket_dispenser_toggle(int parm)
{
 if (power)
 {
  status ^= active_bit;
  timer = timer_set (((timer_tm)(((float)(time_msec)*(float)((1<<30)))/(float)1000)), 0, ticket_dispenser_toggle);
 }
 if (status == ticketdispensed)
 {
  osd_led_w(2,1);
  dispensed_tickets++;
 }
 else
 {
  osd_led_w(2,0);
 }
}

variable_types: parm int


decompiled_code:
__int64 ticket_dispenser_r()
{
return (unsigned int)status;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)status;
}

original_code:
data_t ticket_dispenser_r(offs_t offset)
{
 return status;
}

canonical_original_code:
unsigned int ticket_dispenser_r(unsigned int offset)
{
 return status;
}


decompiled_code:
void __fastcall ticket_dispenser_w(__int64 a1, char a2)
{
if ( (a2 & 0x80) == motoron )
{
if ( !power )
{
timer = timer_set(
(unsigned int)(int)(float)((float)((float)time_msec * 1073741800.0) / 1000.0),
0LL,
ticket_dispenser_toggle);
power = 1;
status = ticketnotdispensed;
}
}
else if ( power )
{
timer_remove(timer);
osd_led_w(2LL, 0LL);
power = 0;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
if ( (a2 & 0x80) == motoron )
{
if ( !power )
{
timer = timer_set(
(unsigned int)(int)(float)((float)((float)time_msec * 1073741800.0) / 1000.0),
0LL,
ticket_dispenser_toggle);
power = 1;
status = ticketnotdispensed;
}
}
else if ( power )
{
timer_remove(timer);
osd_led_w(2LL, 0LL);
power = 0;
}
}

original_code:
void ticket_dispenser_w(offs_t offset,data_t data)
{
 if ((data & active_bit) == motoron)
 {
  if (!power)
  {
   timer = timer_set (((timer_tm)(((float)(time_msec)*(float)((1<<30)))/(float)1000)), 0, ticket_dispenser_toggle);
   power = 1;
   status = ticketnotdispensed;
  }
 }
 else
 {
  if (power)
  {
   timer_remove(timer);
   osd_led_w(2,0);
   power = 0;
  }
 }
}

canonical_original_code:
void ticket_dispenser_w(unsigned int offset, unsigned int data)
{
 if ((data & active_bit) == motoron)
 {
  if (!power)
  {
   timer = timer_set (((timer_tm)(((float)(time_msec)*(float)((1<<30)))/(float)1000)), 0, ticket_dispenser_toggle);
   power = 1;
   status = ticketnotdispensed;
  }
 }
 else
 {
  if (power)
  {
   timer_remove(timer);
   osd_led_w(2,0);
   power = 0;
  }
 }
}


decompiled_code:
void cbasebal_vh_stop()
{
free(cbasebal_textram);
cbasebal_textram = 0LL;
free(cbasebal_scrollram);
cbasebal_scrollram = 0LL;
}

canonical_decompiled_code:
void func2()
{
free(cbasebal_textram);
cbasebal_textram = 0LL;
free(cbasebal_scrollram);
cbasebal_scrollram = 0LL;
}

original_code:
void cbasebal_vh_stop(void)
{
 free(cbasebal_textram);
 cbasebal_textram = 0;
 free(cbasebal_scrollram);
 cbasebal_scrollram = 0;
}

canonical_original_code:
void cbasebal_vh_stop()
{
 free(cbasebal_textram);
 cbasebal_textram = 0;
 free(cbasebal_scrollram);
 cbasebal_scrollram = 0;
}


decompiled_code:
__int64 cbasebal_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rdx
int v3; // ebx
__int64 v4; // rax
__int64 v5; // rdx
int v6; // ebx
__int64 v7; // rax
__int64 v8; // rdx
int v9; // ebx
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-28h]

cbasebal_textram = malloc(0x1000uLL);
cbasebal_scrollram = malloc(0x1000uLL);
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 64LL, 32LL);
LODWORD(v11) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v11);
fg_tilemap = v0;
if ( cbasebal_textram && cbasebal_scrollram && bg_tilemap && v0 )
{
*(_DWORD *)(v0 + 132) = 3;
palette_init_used_colors();
v1 = Machine;
v2 = *(_QWORD *)(Machine + 512LL);
if ( *(int *)(v2 + 24) > 0 )
{
v3 = 0;
do
{
memset(
(void *)(palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v1 + 824) + 688LL) + 16LL)
+ v3 * *(_DWORD *)(v2 + 12)),
3,
*(_DWORD *)(v2 + 12) - 1);
++v3;
v1 = Machine;
v2 = *(_QWORD *)(Machine + 512LL);
}
while ( *(_DWORD *)(v2 + 24) > v3 );
}
v4 = Machine;
v5 = *(_QWORD *)(Machine + 520LL);
if ( *(int *)(v5 + 24) > 0 )
{
v6 = 0;
do
{
memset(
(void *)(palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 824) + 688LL) + 40LL)
+ v6 * *(_DWORD *)(v5 + 12)),
3,
*(int *)(v5 + 12));
++v6;
v4 = Machine;
v5 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v5 + 24) > v6 );
}
v7 = Machine;
v8 = *(_QWORD *)(Machine + 528LL);
if ( *(int *)(v8 + 24) <= 0 )
{
result = 0LL;
}
else
{
v9 = 0;
do
{
memset(
(void *)(palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v7 + 824) + 688LL) + 64LL)
+ v9 * *(_DWORD *)(v8 + 12)),
1,
*(_DWORD *)(v8 + 12) - 1);
++v9;
v7 = Machine;
v8 = *(_QWORD *)(Machine + 528LL);
}
while ( *(_DWORD *)(v8 + 24) > v9 );
result = 0LL;
}
}
else
{
cbasebal_vh_stop();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rdx
int v3; // ebx
__int64 v4; // rax
__int64 v5; // rdx
int v6; // ebx
__int64 v7; // rax
__int64 v8; // rdx
int v9; // ebx
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-28h]

cbasebal_textram = malloc(0x1000uLL);
cbasebal_scrollram = malloc(0x1000uLL);
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 64LL, 32LL);
LODWORD(v11) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v11);
fg_tilemap = v0;
if ( cbasebal_textram && cbasebal_scrollram && bg_tilemap && v0 )
{
*(_DWORD *)(v0 + 132) = 3;
palette_init_used_colors();
v1 = Machine;
v2 = *(_QWORD *)(Machine + 512LL);
if ( *(int *)(v2 + 24) > 0 )
{
v3 = 0;
do
{
memset(
(void *)(palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v1 + 824) + 688LL) + 16LL)
+ v3 * *(_DWORD *)(v2 + 12)),
3,
*(_DWORD *)(v2 + 12) - 1);
++v3;
v1 = Machine;
v2 = *(_QWORD *)(Machine + 512LL);
}
while ( *(_DWORD *)(v2 + 24) > v3 );
}
v4 = Machine;
v5 = *(_QWORD *)(Machine + 520LL);
if ( *(int *)(v5 + 24) > 0 )
{
v6 = 0;
do
{
memset(
(void *)(palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 824) + 688LL) + 40LL)
+ v6 * *(_DWORD *)(v5 + 12)),
3,
*(int *)(v5 + 12));
++v6;
v4 = Machine;
v5 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v5 + 24) > v6 );
}
v7 = Machine;
v8 = *(_QWORD *)(Machine + 528LL);
if ( *(int *)(v8 + 24) <= 0 )
{
result = 0LL;
}
else
{
v9 = 0;
do
{
memset(
(void *)(palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v7 + 824) + 688LL) + 64LL)
+ v9 * *(_DWORD *)(v8 + 12)),
1,
*(_DWORD *)(v8 + 12) - 1);
++v9;
v7 = Machine;
v8 = *(_QWORD *)(Machine + 528LL);
}
while ( *(_DWORD *)(v8 + 24) > v9 );
result = 0LL;
}
}
else
{
func2();
result = 1LL;
}
return result;
}

original_code:
int cbasebal_vh_start(void)
{
 int i;
 cbasebal_textram = (unsigned char*)malloc(0x1000);
 cbasebal_scrollram = (unsigned char*)malloc(0x1000);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,64,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,64,32);
 if (!cbasebal_textram || !cbasebal_scrollram || !bg_tilemap || !fg_tilemap)
 {
  cbasebal_vh_stop();
  return 1;
 }
 fg_tilemap->transparent_pen = 3;
 palette_init_used_colors();
 for (i = 0;i < Machine->gfx[0]->total_colors;i++)
 {
  memset(&palette_used_colors[Machine->drv->gfxdecodeinfo[0].color_codes_start + i * Machine->gfx[0]->color_granularity],
    (1|2),
    Machine->gfx[0]->color_granularity-1);
 }
 for (i = 0;i < Machine->gfx[1]->total_colors;i++)
 {
  memset(&palette_used_colors[Machine->drv->gfxdecodeinfo[1].color_codes_start + i * Machine->gfx[1]->color_granularity],
    (1|2),
    Machine->gfx[1]->color_granularity);
 }
 for (i = 0;i < Machine->gfx[2]->total_colors;i++)
 {
  memset(&palette_used_colors[Machine->drv->gfxdecodeinfo[2].color_codes_start + i * Machine->gfx[2]->color_granularity],
    1,
    Machine->gfx[2]->color_granularity-1);
 }
 return 0;
}

canonical_original_code:
int cbasebal_vh_start()
{
 int i;
 cbasebal_textram = (unsigned char *)malloc(0x1000);
 cbasebal_scrollram = (unsigned char *)malloc(0x1000);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,64,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,64,32);
 if (!cbasebal_textram || !cbasebal_scrollram || !bg_tilemap || !fg_tilemap)
 {
  cbasebal_vh_stop();
  return 1;
 }
 fg_tilemap->transparent_pen = 3;
 palette_init_used_colors();
 for (i = 0;i < Machine->gfx[0]->total_colors;i++)
 {
  memset(&palette_used_colors[Machine->drv->gfxdecodeinfo[0].color_codes_start + i * Machine->gfx[0]->color_granularity],
    (1|2),
    Machine->gfx[0]->color_granularity-1);
 }
 for (i = 0;i < Machine->gfx[1]->total_colors;i++)
 {
  memset(&palette_used_colors[Machine->drv->gfxdecodeinfo[1].color_codes_start + i * Machine->gfx[1]->color_granularity],
    (1|2),
    Machine->gfx[1]->color_granularity);
 }
 for (i = 0;i < Machine->gfx[2]->total_colors;i++)
 {
  memset(&palette_used_colors[Machine->drv->gfxdecodeinfo[2].color_codes_start + i * Machine->gfx[2]->color_granularity],
    1,
    Machine->gfx[2]->color_granularity-1);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall cbasebal_gfxctrl_w(__int64 a1, unsigned int a2)
{
__int64 v3; // rsi
char v4; // bl
__int64 result; // rax

v3 = a2 & 2;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
if ( ((a2 & 8) != 0) != tilebank )
{
tilebank = (a2 & 8) != 0;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
spritebank = (a2 >> 4) & 1;
v4 = ~(_BYTE)a2;
text_on = v4 & 0x20;
result = v4 & 0x40;
bg_on = v4 & 0x40;
obj_on = v4 & 0x80;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
__int64 v3; // rsi
char v4; // bl
__int64 result; // rax

v3 = a2 & 2;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
if ( ((a2 & 8) != 0) != tilebank )
{
tilebank = (a2 & 8) != 0;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
spritebank = (a2 >> 4) & 1;
v4 = ~(_BYTE)a2;
text_on = v4 & 0x20;
result = v4 & 0x40;
bg_on = v4 & 0x40;
obj_on = v4 & 0x80;
return result;
}

original_code:
void cbasebal_gfxctrl_w(offs_t offset,data_t data)
{
 flipscreen = data & 0x02;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 if (tilebank != ((data & 0x08) >> 3))
 {
  tilebank = (data & 0x08) >> 3;
  tilemap_mark_all_tiles_dirty(bg_tilemap);
 }
 spritebank = (data & 0x10) >> 4;
 text_on = ~data & 0x20;
 bg_on = ~data & 0x40;
 obj_on = ~data & 0x80;
}

canonical_original_code:
void cbasebal_gfxctrl_w(unsigned int offset, unsigned int data)
{
 flipscreen = data & 0x02;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 if (tilebank != ((data & 0x08) >> 3))
 {
  tilebank = (data & 0x08) >> 3;
  tilemap_mark_all_tiles_dirty(bg_tilemap);
 }
 spritebank = (data & 0x10) >> 4;
 text_on = ~data & 0x20;
 bg_on = ~data & 0x40;
 obj_on = ~data & 0x80;
}


decompiled_code:
__int64 __fastcall cbasebal_scrollx_w(int a1, char a2)
{
scroll_1[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)scroll_1[0] + ((unsigned __int8)byte_F53 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, char a2)
{
scroll_1[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)scroll_1[0] + ((unsigned __int8)byte_F53 << 8));
}

original_code:
void cbasebal_scrollx_w(offs_t offset,data_t data)
{
 static unsigned char scroll[2];
 scroll[offset] = data;
 tilemap_set_scrollx(bg_tilemap,0,scroll[0] + 256 * scroll[1]);
}

canonical_original_code:
void cbasebal_scrollx_w(unsigned int offset, unsigned int data)
{
 static unsigned char scroll[2];
 scroll[offset] = data;
 tilemap_set_scrollx(bg_tilemap,0,scroll[0] + 256 * scroll[1]);
}

variable_types:
scroll
unsigned char [2]


decompiled_code:
__int64 __fastcall cbasebal_scrolly_w(int a1, char a2)
{
scroll_0[a1] = a2;
return tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)scroll_0[0] + ((unsigned __int8)byte_F51 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char a2)
{
scroll_0[a1] = a2;
return tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)scroll_0[0] + ((unsigned __int8)byte_F51 << 8));
}

original_code:
void cbasebal_scrolly_w(offs_t offset,data_t data)
{
 static unsigned char scroll[2];
 scroll[offset] = data;
 tilemap_set_scrolly(bg_tilemap,0,scroll[0] + 256 * scroll[1]);
}

canonical_original_code:
void cbasebal_scrolly_w(unsigned int offset, unsigned int data)
{
 static unsigned char scroll[2];
 scroll[offset] = data;
 tilemap_set_scrolly(bg_tilemap,0,scroll[0] + 256 * scroll[1]);
}


decompiled_code:
void *__fastcall cbasebal_vh_screenrefresh(__int64 a1)
{
void *result; // rax

tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( bg_on )
result = (void *)tilemap_draw(a1, bg_tilemap, 0LL);
else
result = (void *)fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1536LL), Machine + 776LL);
if ( obj_on )
result = draw_sprites(a1);
if ( text_on )
result = (void *)tilemap_draw(a1, fg_tilemap, 0LL);
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
void *result; // rax

tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( bg_on )
result = (void *)tilemap_draw(a1, bg_tilemap, 0LL);
else
result = (void *)fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1536LL), Machine + 776LL);
if ( obj_on )
result = func7(a1);
if ( text_on )
result = (void *)tilemap_draw(a1, fg_tilemap, 0LL);
return result;
}

original_code:
void cbasebal_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (bg_on)
  tilemap_draw(bitmap,bg_tilemap,0);
 else
  fillbitmap(bitmap,Machine->pens[768],&Machine->visible_area);
 if (obj_on)
  draw_sprites(bitmap);
 if (text_on)
  tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void cbasebal_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (bg_on)
  tilemap_draw(bitmap,bg_tilemap,0);
 else
  fillbitmap(bitmap,Machine->pens[768],&Machine->visible_area);
 if (obj_on)
  draw_sprites(bitmap);
 if (text_on)
  tilemap_draw(bitmap,fg_tilemap,0);
}


decompiled_code:
__int64 init_cbasebal()
{
return pang_decode();
}

canonical_decompiled_code:
__int64 func9()
{
return pang_decode();
}

original_code:
void init_cbasebal(void)
{
 pang_decode();
}

canonical_original_code:
void init_cbasebal()
{
 pang_decode();
}


decompiled_code:
__int64 __fastcall cbasebal_coinctrl_w(__int64 a1, char a2)
{
coin_lockout_w(0LL, ~a2 & 4);
coin_lockout_w(1LL, ~a2 & 8);
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char a2)
{
coin_lockout_w(0LL, ~a2 & 4);
coin_lockout_w(1LL, ~a2 & 8);
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

original_code:
static void cbasebal_coinctrl_w(offs_t offset,data_t data)
{
 coin_lockout_w(0,~data & 0x04);
 coin_lockout_w(1,~data & 0x08);
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
}

canonical_original_code:
static void cbasebal_coinctrl_w(unsigned int offset, unsigned int data)
{
 coin_lockout_w(0,~data & 0x04);
 coin_lockout_w(1,~data & 0x08);
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
}


decompiled_code:
__int64 __fastcall eeprom_serial_w(__int64 a1, unsigned int a2)
{
return EEPROM_write_bit(a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
return EEPROM_write_bit(a2);
}

original_code:
static void eeprom_serial_w(offs_t offset,data_t data)
{
 EEPROM_write_bit(data);
}

canonical_original_code:
static void eeprom_serial_w(unsigned int offset, unsigned int data)
{
 EEPROM_write_bit(data);
}


decompiled_code:
__int64 __fastcall eeprom_clock_w(__int64 a1, int a2)
{
return EEPROM_set_clock_line(a2 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
return EEPROM_set_clock_line(a2 == 0);
}

original_code:
static void eeprom_clock_w(offs_t offset,data_t data)
{
 EEPROM_set_clock_line(data ? 0 : 1);
}

canonical_original_code:
static void eeprom_clock_w(unsigned int offset, unsigned int data)
{
 EEPROM_set_clock_line(data ? 0 : 1);
}


decompiled_code:
__int64 __fastcall eeprom_cs_w(__int64 a1, int a2)
{
return EEPROM_set_cs_line(a2 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
return EEPROM_set_cs_line(a2 == 0);
}

original_code:
static void eeprom_cs_w(offs_t offset,data_t data)
{
 EEPROM_set_cs_line(data ? 0 : 1);
}

canonical_original_code:
static void eeprom_cs_w(unsigned int offset, unsigned int data)
{
 EEPROM_set_cs_line(data ? 0 : 1);
}


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0x1F) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
rambank = a2 >> 6;
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0x1F) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
rambank = a2 >> 6;
return result;
}

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

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

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


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

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

original_code:
data_t cbasebal_textram_r(offs_t offset)
{
 return cbasebal_textram[offset];
}

canonical_original_code:
unsigned int cbasebal_textram_r(unsigned int offset)
{
 return cbasebal_textram[offset];
}


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

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

original_code:
data_t cbasebal_scrollram_r(offs_t offset)
{
 return cbasebal_scrollram[offset];
}

canonical_original_code:
unsigned int cbasebal_scrollram_r(unsigned int offset)
{
 return cbasebal_scrollram[offset];
}


decompiled_code:
void *__fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

v1 = 2 * a1;
v2 = *((_BYTE *)cbasebal_scrollram + v1 + 1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = v2;
v5 = ((tilebank << 11) + *((unsigned __int8 *)cbasebal_scrollram + v1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 4);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v7;
*((_DWORD *)&tile_info + 5) = (v4 >> 3) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

v1 = 2 * a1;
v2 = *((_BYTE *)cbasebal_scrollram + v1 + 1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = v2;
v5 = ((tilebank << 11) + *((unsigned __int8 *)cbasebal_scrollram + v1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 4);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v7;
*((_DWORD *)&tile_info + 5) = (v4 >> 3) & 1;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = cbasebal_scrollram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (cbasebal_scrollram[2*tile_index] + ((attr & 0x07) << 8) + 0x800 * tilebank) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x08) ? 0x01 : 0;
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = cbasebal_scrollram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (cbasebal_scrollram[2*tile_index] + ((attr & 0x07) << 8) + 0x800 * tilebank) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x08) ? 0x01 : 0;
}

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


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

v1 = a1;
v2 = *((_BYTE *)cbasebal_textram + a1 + 2048);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = v2;
v5 = (*((unsigned __int8 *)cbasebal_textram + v1) + ((16 * v2) & 0xF00u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 7);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v7;
*((_DWORD *)&tile_info + 5) = (v4 >> 3) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edi
signed int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

v1 = a1;
v2 = *((_BYTE *)cbasebal_textram + a1 + 2048);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = v2;
v5 = (*((unsigned __int8 *)cbasebal_textram + v1) + ((16 * v2) & 0xF00u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v5;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 7);
v6 = *(_QWORD *)(v3 + 32);
v7 = 0;
if ( v6 )
v7 = *(_DWORD *)(v6 + 4LL * v5);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v7;
*((_DWORD *)&tile_info + 5) = (v4 >> 3) & 1;
return result;
}

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

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = cbasebal_textram[tile_index+0x800];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (cbasebal_textram[tile_index] + ((attr & 0xf0) << 4)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x08) ? 0x01 : 0;
}


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

v0 = EEPROM_read_bit();
return (v0 << 7) | (unsigned int)(input_port_2_r(0LL) & 0x7F);
}

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

v0 = EEPROM_read_bit();
return (v0 << 7) | (unsigned int)(input_port_2_r(0LL) & 0x7F);
}

original_code:
static data_t eeprom_r(offs_t offset)
{
 int bit;
 bit = EEPROM_read_bit() << 7;
 return (input_port_2_r(0) & 0x7f) | bit;
}

canonical_original_code:
static unsigned int eeprom_r(unsigned int offset)
{
 int bit;
 bit = EEPROM_read_bit() << 7;
 return (input_port_2_r(0) & 0x7f) | bit;
}

variable_types: bit int


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

result = (unsigned int)rambank;
if ( rambank == 2 )
return (__int64)cbasebal_textram_w(a1, a2);
if ( rambank != 1 )
return (__int64)cbasebal_scrollram_w(a1, a2);
if ( a1 <= 0x7FF )
result = paletteram_xxxxBBBBRRRRGGGG_w();
return result;
}

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

result = (unsigned int)rambank;
if ( rambank == 2 )
return (__int64)cbasebal_textram_w(a1, a2);
if ( rambank != 1 )
return (__int64)cbasebal_scrollram_w(a1, a2);
if ( a1 <= 0x7FF )
result = paletteram_xxxxBBBBRRRRGGGG_w();
return result;
}

original_code:
static void bankedram_w(offs_t offset,data_t data)
{
 if (rambank == 2)
  cbasebal_textram_w(offset,data);
 else if (rambank == 1)
 {
  if (offset < 0x800)
   paletteram_xxxxBBBBRRRRGGGG_w(offset,data);
 }
 else
  cbasebal_scrollram_w(offset,data);
}

canonical_original_code:
static void bankedram_w(unsigned int offset, unsigned int data)
{
 if (rambank == 2)
  cbasebal_textram_w(offset,data);
 else if (rambank == 1)
 {
  if (offset < 0x800)
   paletteram_xxxxBBBBRRRRGGGG_w(offset,data);
 }
 else
  cbasebal_scrollram_w(offset,data);
}


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

if ( rambank == 2 )
return cbasebal_textram_r(a1);
if ( rambank != 1 )
return cbasebal_scrollram_r(a1);
result = 0LL;
if ( a1 <= 0x7FF )
result = paletteram_r();
return result;
}

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

if ( rambank == 2 )
return func17(a1);
if ( rambank != 1 )
return func19(a1);
result = 0LL;
if ( a1 <= 0x7FF )
result = paletteram_r();
return result;
}

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (rambank == 2)
  return cbasebal_textram_r(offset);
 else if (rambank == 1)
 {
  if (offset < 0x800)
   return paletteram_r(offset);
  else return 0;
 }
 else
 {
  return cbasebal_scrollram_r(offset);
 }
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (rambank == 2)
  return cbasebal_textram_r(offset);
 else if (rambank == 1)
 {
  if (offset < 0x800)
   return paletteram_r(offset);
  else return 0;
 }
 else
 {
  return cbasebal_scrollram_r(offset);
 }
}


decompiled_code:
void __fastcall shangha3_gfxlist_addr_w(__int64 a1, int a2)
{
gfxlist_addr = 16 * a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
gfxlist_addr = 16 * a2;
}

original_code:
void shangha3_gfxlist_addr_w(offs_t offset,data_t data)
{
 gfxlist_addr = data * 0x10;
}

canonical_original_code:
void shangha3_gfxlist_addr_w(unsigned int offset, unsigned int data)
{
 gfxlist_addr = data * 0x10;
}


decompiled_code:
__int64 shangha3_prot_r()
{
int v0; // eax

v0 = count_1++;
return result_0[v0 % 9];
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax

v0 = count_1++;
return result_0[v0 % 9];
}

original_code:
static data_t shangha3_prot_r(offs_t offset)
{
 static int count;
 static int result[] = { 0x0,0x1,0x3,0x7,0xf,0xe,0xc,0x8,0x0};
 return result[count++ % 9];
}

canonical_original_code:
static unsigned int shangha3_prot_r(unsigned int offset)
{
 static int count;
 static int result[] = { 0x0,0x1,0x3,0x7,0xf,0xe,0xc,0x8,0x0};
 return result[count++ % 9];
}

variable_types: count int

variable_types:
result
int []


decompiled_code:
void shangha3_prot_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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


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

result = shangha3_do_shadows;
shangha3_do_shadows[0] = 1;
return result;
}

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

result = shangha3_do_shadows;
shangha3_do_shadows[0] = 1;
return result;
}

original_code:
static void init_shangha3(void)
{
 shangha3_do_shadows = 1;
}

canonical_original_code:
static void init_shangha3()
{
 shangha3_do_shadows = 1;
}


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

result = shangha3_do_shadows;
shangha3_do_shadows[0] = 0;
return result;
}

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

result = shangha3_do_shadows;
shangha3_do_shadows[0] = 0;
return result;
}

original_code:
static void init_heberpop(void)
{
 shangha3_do_shadows = 0;
}

canonical_original_code:
static void init_heberpop()
{
 shangha3_do_shadows = 0;
}


decompiled_code:
__int64 shangha3_vh_start()
{
__int64 result; // rax
_BYTE *v1; // rax
__int64 i; // rax

rawbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !rawbitmap )
return 1LL;
result = shangha3_do_shadows[0];
if ( shangha3_do_shadows[0] )
{
v1 = gfx_drawmode_table;
do
*v1++ = 1;
while ( v1 != &gfx_drawmode_table[14] );
gfx_drawmode_table[14] = 2;
for ( i = 256LL; i != 512; i += 2LL )
*(_WORD *)(palette_shadow_table + 2LL * *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + i - 256)) = *(_WORD *)(*(_QWORD *)(Machine + 792LL) + i);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
_BYTE *v1; // rax
__int64 i; // rax

rawbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !rawbitmap )
return 1LL;
result = shangha3_do_shadows[0];
if ( shangha3_do_shadows[0] )
{
v1 = gfx_drawmode_table;
do
*v1++ = 1;
while ( v1 != &gfx_drawmode_table[14] );
gfx_drawmode_table[14] = 2;
for ( i = 256LL; i != 512; i += 2LL )
*(_WORD *)(palette_shadow_table + 2LL * *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + i - 256)) = *(_WORD *)(*(_QWORD *)(Machine + 792LL) + i);
result = 0LL;
}
return result;
}

original_code:
int shangha3_vh_start(void)
{
 if ((rawbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if (shangha3_do_shadows)
 {
  int i;
  for (i = 0;i < 14;i++)
   gfx_drawmode_table[i] = DRAWMODE_SOURCE;
  gfx_drawmode_table[14] = DRAWMODE_SHADOW;
  for (i = 0;i < 128;i++)
   palette_shadow_table[Machine->pens[i]] = Machine->pens[i+128];
 }
 return 0;
}

canonical_original_code:
int shangha3_vh_start()
{
 if ((rawbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if (shangha3_do_shadows)
 {
  int i;
  for (i = 0;i < 14;i++)
   gfx_drawmode_table[i] = DRAWMODE_SOURCE;
  gfx_drawmode_table[14] = DRAWMODE_SHADOW;
  for (i = 0;i < 128;i++)
   palette_shadow_table[Machine->pens[i]] = Machine->pens[i+128];
 }
 return 0;
}

variable_types: i int


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

result = bitmap_free(rawbitmap);
rawbitmap = 0LL;
return result;
}

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

result = bitmap_free(rawbitmap);
rawbitmap = 0LL;
return result;
}

original_code:
void shangha3_vh_stop(void)
{
 bitmap_free(rawbitmap);
 rawbitmap = 0;
}

canonical_original_code:
void shangha3_vh_stop()
{
 bitmap_free(rawbitmap);
 rawbitmap = 0;
}


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

flip_screen_w(0LL, a2 & 0x80);
result = a2 & 0x7F;
if ( (_DWORD)result != 126 )
result = usrintf_showmessage("flipscreen_w %02x", a2);
return result;
}

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

flip_screen_w(0LL, a2 & 0x80);
result = a2 & 0x7F;
if ( (_DWORD)result != 126 )
result = usrintf_showmessage("flipscreen_w %02x", a2);
return result;
}

original_code:
void shangha3_flipscreen_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 0x80);
 if ((data & 0x7f) != 0x7e) usrintf_showmessage("flipscreen_w %02x",data);
}

canonical_original_code:
void shangha3_flipscreen_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 0x80);
 if ((data & 0x7f) != 0x7e) usrintf_showmessage("flipscreen_w %02x",data);
}