decompiled_code:
void *__fastcall solomon_vh_screenrefresh(__int64 a1)
{
size_t v2; // rbx
int v3; // esi
int v4; // edi
int v5; // eax
int v6; // ecx
__int64 v7; // r8
__int64 v8; // r9
int v9; // ebx
__int64 v10; // r13
__int64 v11; // r8
int v12; // esi
int v13; // edi
void *result; // rax
int v15; // ebx
__int64 v16; // r15
__int64 v17; // r10
__int64 v18; // r11
int v19; // ecx
__int64 v20; // rdi
int v21; // eax
unsigned __int8 v22; // dl
__int64 v23; // r8
__int64 v24; // r9

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
if ( videoram_size )
{
v2 = 0LL;
do
{
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
v3 = flipscreen;
*((_BYTE *)dirtybuffer2 + v2) = 0;
v4 = (int)v2 >> 5;
v5 = v2 & 0x1F;
v6 = *(unsigned __int8 *)(solomon_bgcolorram + v2);
v7 = (unsigned __int8)v6 & 0x80;
v8 = *(_BYTE *)(solomon_bgcolorram + v2) & 8;
if ( v3 )
{
v5 = 31 - v5;
v4 = 31 - v4;
v7 = (_DWORD)v7 == 0;
v8 = (_DWORD)v8 == 0;
}
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(solomon_bgvideoram + v2)
+ ((unsigned __int8)(*(_BYTE *)(solomon_bgcolorram + v2) & 7) << 8),
(v6 >> 4) & 7,
v7,
v8,
(unsigned int)(8 * v5),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
++v2;
}
while ( videoram_size > v2 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v9 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v10 = v9;
do
{
if ( *((_BYTE *)dirtybuffer + v10) )
{
v11 = (unsigned int)flipscreen;
*((_BYTE *)dirtybuffer + v10) = 0;
v12 = v9 & 0x1F;
v13 = v9 >> 5;
if ( (_DWORD)v11 )
{
v12 = 31 - v12;
v13 = 31 - v13;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v10) + ((unsigned __int8)(*(_BYTE *)(colorram + v10) & 7) << 8),
(*(unsigned __int8 *)(colorram + v10) >> 4) & 7,
v11,
(unsigned int)v11,
(unsigned int)(8 * v12),
(unsigned int)(8 * v13),
Machine + 776LL,
0LL,
0LL);
}
--v9;
--v10;
}
while ( v9 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
result = &spriteram_size;
v15 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v16 = v15 + 3LL;
do
{
v18 = v16 - 3;
v19 = *(unsigned __int8 *)(spriteram + v16 - 2);
v20 = *(unsigned __int8 *)(spriteram + v16);
v21 = *(unsigned __int8 *)(spriteram + v16 - 1);
v22 = *(_BYTE *)(spriteram + v16 - 2);
v23 = v19 & 0x40;
v24 = v22 & 0x80;
if ( (flipscreen & 1) != 0 )
{
v20 = (unsigned int)(240 - v20);
v17 = (unsigned int)(v21 - 1);
v23 = (_DWORD)v23 == 0;
v24 = (_DWORD)v24 == 0;
}
else
{
v17 = (unsigned int)(241 - v21);
}
v16 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v18) + 16 * (v22 & 0x10u),
(v19 >> 1) & 7,
v23,
v24,
v20,
v17,
Machine + 776LL,
2LL,
0LL);
v15 -= 4;
}
while ( v15 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
size_t v2; // rbx
int v3; // esi
int v4; // edi
int v5; // eax
int v6; // ecx
__int64 v7; // r8
__int64 v8; // r9
int v9; // ebx
__int64 v10; // r13
__int64 v11; // r8
int v12; // esi
int v13; // edi
void *result; // rax
int v15; // ebx
__int64 v16; // r15
__int64 v17; // r10
__int64 v18; // r11
int v19; // ecx
__int64 v20; // rdi
int v21; // eax
unsigned __int8 v22; // dl
__int64 v23; // r8
__int64 v24; // r9

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
if ( videoram_size )
{
v2 = 0LL;
do
{
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
v3 = flipscreen;
*((_BYTE *)dirtybuffer2 + v2) = 0;
v4 = (int)v2 >> 5;
v5 = v2 & 0x1F;
v6 = *(unsigned __int8 *)(solomon_bgcolorram + v2);
v7 = (unsigned __int8)v6 & 0x80;
v8 = *(_BYTE *)(solomon_bgcolorram + v2) & 8;
if ( v3 )
{
v5 = 31 - v5;
v4 = 31 - v4;
v7 = (_DWORD)v7 == 0;
v8 = (_DWORD)v8 == 0;
}
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(solomon_bgvideoram + v2)
+ ((unsigned __int8)(*(_BYTE *)(solomon_bgcolorram + v2) & 7) << 8),
(v6 >> 4) & 7,
v7,
v8,
(unsigned int)(8 * v5),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
++v2;
}
while ( videoram_size > v2 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v9 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v10 = v9;
do
{
if ( *((_BYTE *)dirtybuffer + v10) )
{
v11 = (unsigned int)flipscreen;
*((_BYTE *)dirtybuffer + v10) = 0;
v12 = v9 & 0x1F;
v13 = v9 >> 5;
if ( (_DWORD)v11 )
{
v12 = 31 - v12;
v13 = 31 - v13;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v10) + ((unsigned __int8)(*(_BYTE *)(colorram + v10) & 7) << 8),
(*(unsigned __int8 *)(colorram + v10) >> 4) & 7,
v11,
(unsigned int)v11,
(unsigned int)(8 * v12),
(unsigned int)(8 * v13),
Machine + 776LL,
0LL,
0LL);
}
--v9;
--v10;
}
while ( v9 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
result = &spriteram_size;
v15 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v16 = v15 + 3LL;
do
{
v18 = v16 - 3;
v19 = *(unsigned __int8 *)(spriteram + v16 - 2);
v20 = *(unsigned __int8 *)(spriteram + v16);
v21 = *(unsigned __int8 *)(spriteram + v16 - 1);
v22 = *(_BYTE *)(spriteram + v16 - 2);
v23 = v19 & 0x40;
v24 = v22 & 0x80;
if ( (flipscreen & 1) != 0 )
{
v20 = (unsigned int)(240 - v20);
v17 = (unsigned int)(v21 - 1);
v23 = (_DWORD)v23 == 0;
v24 = (_DWORD)v24 == 0;
}
else
{
v17 = (unsigned int)(241 - v21);
}
v16 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v18) + 16 * (v22 & 0x10u),
(v19 >> 1) & 7,
v23,
v24,
v20,
v17,
Machine + 776LL,
2LL,
0LL);
v15 -= 4;
}
while ( v15 >= 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 func4()
{
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

return_type: void


decompiled_code:
__int64 generic_vh_start()
{
size_t v0; // r12
unsigned int v1; // er8
__int64 v3; // rax

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

canonical_decompiled_code:
__int64 func0()
{
size_t v0; // r12
unsigned int v1; // er8
__int64 v3; // rax

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

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

return_type: int


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];
}

return_type: unsigned int


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 func9(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 *func11()
{
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 *func12()
{
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 func13(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 func14(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 func7(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:
__int64 __fastcall ticket_dispenser_w(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rax

result = (unsigned int)power;
if ( (a2 & 0x80) == motoron )
{
if ( !power )
{
v3 = timer_set(
(unsigned int)(int)(float)((float)((float)time_msec * 1073741800.0) / 1000.0),
0LL,
ticket_dispenser_toggle);
power = 1;
timer = v3;
result = (unsigned int)ticketnotdispensed;
status = ticketnotdispensed;
}
}
else if ( power )
{
timer_remove(timer);
result = osd_led_w(2LL, 0LL);
power = 0;
}
return result;
}

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

result = (unsigned int)power;
if ( (a2 & 0x80) == motoron )
{
if ( !power )
{
v3 = timer_set(
(unsigned int)(int)(float)((float)((float)time_msec * 1073741800.0) / 1000.0),
0LL,
ticket_dispenser_toggle);
power = 1;
timer = v3;
result = (unsigned int)ticketnotdispensed;
status = ticketnotdispensed;
}
}
else if ( power )
{
timer_remove(timer);
result = osd_led_w(2LL, 0LL);
power = 0;
}
return result;
}

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
__int64 v3; // rcx
_QWORD *v4; // rax
__int64 v5; // rdx
int v6; // er12
int v7; // edi
int v8; // edx
int v9; // edi
__int64 v10; // rdx
int v11; // er12
size_t v12; // rdx
int v13; // edi
__int64 v14; // rdx
int v15; // er12
int v16; // edi
int v17; // edx
int v18; // edi
__int64 result; // rax
__int64 v20; // [rsp+0h] [rbp-28h]
__int64 v21; // [rsp+0h] [rbp-28h]

cbasebal_textram = malloc(0x1000uLL);
cbasebal_scrollram = malloc(0x1000uLL);
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 64LL, 32LL);
LODWORD(v20) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v20);
fg_tilemap = v1;
if ( cbasebal_textram && cbasebal_scrollram && bg_tilemap && v1 )
{
*(_DWORD *)(v1 + 132) = 3;
((void (__fastcall *)(__int64 (__fastcall *)(int), void *, __int64, __int64, __int64))palette_init_used_colors)(
get_fg_tile_info,
&tilemap_scan_rows,
v2,
v3,
v21);
v4 = (_QWORD *)Machine;
v5 = *(_QWORD *)(Machine + 512LL);
if ( *(int *)(v5 + 24) > 0 )
{
v6 = 0;
do
{
v7 = *(_DWORD *)(v5 + 12);
v8 = v7 - 1;
v9 = v6 * v7;
++v6;
memset((void *)(palette_used_colors + *(_DWORD *)(*(_QWORD *)(v4[103] + 688LL) + 16LL) + v9), 3, v8);
v4 = (_QWORD *)Machine;
v5 = *(_QWORD *)(Machine + 512LL);
}
while ( *(_DWORD *)(v5 + 24) > v6 );
}
v10 = v4[65];
if ( *(int *)(v10 + 24) > 0 )
{
v11 = 0;
do
{
v12 = *(int *)(v10 + 12);
v13 = v11 * v12;
++v11;
memset((void *)(palette_used_colors + *(_DWORD *)(*(_QWORD *)(v4[103] + 688LL) + 40LL) + v13), 3, v12);
v4 = (_QWORD *)Machine;
v10 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v10 + 24) > v11 );
}
v14 = v4[66];
if ( *(int *)(v14 + 24) > 0 )
{
v15 = 0;
do
{
v16 = *(_DWORD *)(v14 + 12);
v17 = v16 - 1;
v18 = v15 * v16;
++v15;
memset((void *)(palette_used_colors + *(_DWORD *)(*(_QWORD *)(v4[103] + 688LL) + 64LL) + v18), 1, v17);
v4 = (_QWORD *)Machine;
v14 = *(_QWORD *)(Machine + 528LL);
}
while ( *(_DWORD *)(v14 + 24) > v15 );
}
result = 0LL;
}
else
{
cbasebal_vh_stop();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
_QWORD *v4; // rax
__int64 v5; // rdx
int v6; // er12
int v7; // edi
int v8; // edx
int v9; // edi
__int64 v10; // rdx
int v11; // er12
size_t v12; // rdx
int v13; // edi
__int64 v14; // rdx
int v15; // er12
int v16; // edi
int v17; // edx
int v18; // edi
__int64 result; // rax
__int64 v20; // [rsp+0h] [rbp-28h]
__int64 v21; // [rsp+0h] [rbp-28h]

cbasebal_textram = malloc(0x1000uLL);
cbasebal_scrollram = malloc(0x1000uLL);
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 64LL, 32LL);
LODWORD(v20) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v20);
fg_tilemap = v1;
if ( cbasebal_textram && cbasebal_scrollram && bg_tilemap && v1 )
{
*(_DWORD *)(v1 + 132) = 3;
((void (__fastcall *)(__int64 (__fastcall *)(int), void *, __int64, __int64, __int64))palette_init_used_colors)(
get_fg_tile_info,
&tilemap_scan_rows,
v2,
v3,
v21);
v4 = (_QWORD *)Machine;
v5 = *(_QWORD *)(Machine + 512LL);
if ( *(int *)(v5 + 24) > 0 )
{
v6 = 0;
do
{
v7 = *(_DWORD *)(v5 + 12);
v8 = v7 - 1;
v9 = v6 * v7;
++v6;
memset((void *)(palette_used_colors + *(_DWORD *)(*(_QWORD *)(v4[103] + 688LL) + 16LL) + v9), 3, v8);
v4 = (_QWORD *)Machine;
v5 = *(_QWORD *)(Machine + 512LL);
}
while ( *(_DWORD *)(v5 + 24) > v6 );
}
v10 = v4[65];
if ( *(int *)(v10 + 24) > 0 )
{
v11 = 0;
do
{
v12 = *(int *)(v10 + 12);
v13 = v11 * v12;
++v11;
memset((void *)(palette_used_colors + *(_DWORD *)(*(_QWORD *)(v4[103] + 688LL) + 40LL) + v13), 3, v12);
v4 = (_QWORD *)Machine;
v10 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v10 + 24) > v11 );
}
v14 = v4[66];
if ( *(int *)(v14 + 24) > 0 )
{
v15 = 0;
do
{
v16 = *(_DWORD *)(v14 + 12);
v17 = v16 - 1;
v18 = v15 * v16;
++v15;
memset((void *)(palette_used_colors + *(_DWORD *)(*(_QWORD *)(v4[103] + 688LL) + 64LL) + v18), 1, v17);
v4 = (_QWORD *)Machine;
v14 = *(_QWORD *)(Machine + 528LL);
}
while ( *(_DWORD *)(v14 + 24) > v15 );
}
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;
}

variable_types: i int


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

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

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

v3 = a2 & 2;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
if ( ((a2 >> 3) & 1) != tilebank )
{
tilebank = (a2 >> 3) & 1;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
v4 = a2;
v5 = ~(_BYTE)a2;
spritebank = (v4 >> 4) & 1;
text_on = v5 & 0x20;
result = v5 & 0x40;
obj_on = v5 & 0x80;
bg_on = v5 & 0x40;
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_F93 << 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_F93 << 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_F91 << 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_F91 << 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:
__int64 __fastcall cbasebal_vh_screenrefresh(__int64 a1)
{
__int64 result; // rax

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

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

tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( bg_on )
{
tilemap_draw(a1, bg_tilemap, 0LL);
if ( !obj_on )
goto LABEL_5;
}
else
{
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1536LL), Machine + 776LL);
if ( !obj_on )
{
LABEL_5:
result = (unsigned int)text_on;
if ( !text_on )
return result;
return tilemap_draw(a1, fg_tilemap, 0LL);
}
}
func7(a1);
result = (unsigned int)text_on;
if ( text_on )
return 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);
}

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


decompiled_code:
// attributes: thunk
__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 & 0x1Fu) + 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 & 0x1Fu) + 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:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rax
int v2; // edi
__int64 v3; // rsi
__int64 v4; // rcx
signed int v5; // edx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rax
int v2; // edi
__int64 v3; // rsi
__int64 v4; // rcx
signed int v5; // edx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *((unsigned __int8 *)cbasebal_scrollram + v1 + 1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_DWORD *)(v3 + 12) * ((unsigned __int8)v2 >> 4);
v5 = ((tilebank << 11) + *((unsigned __int8 *)cbasebal_scrollram + v1) + (((_WORD)v2 << 8) & 0x700u))
% *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + v5 * *(_DWORD *)(v3 + 52);
v6 = *(_QWORD *)(v3 + 16) + 2 * v4;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v2 >> 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:
attr
unsigned char

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


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

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

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

v1 = a1;
v2 = *((unsigned __int8 *)cbasebal_textram + a1 + 2048);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*((unsigned __int8 *)cbasebal_textram + v1) + ((16 * (_WORD)v2) & 0xF00u)) % *(_DWORD *)(v3 + 8);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 7);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v2 >> 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;
}

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


decompiled_code:
__int64 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(__int64 a1, __int64 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 ( (unsigned int)a1 <= 0x7FF )
result = paletteram_xxxxBBBBRRRRGGGG_w(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 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 ( (unsigned int)a1 <= 0x7FF )
result = paletteram_xxxxBBBBRRRRGGGG_w(a1, a2);
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)
{
if ( rambank == 2 )
return cbasebal_textram_r(a1);
if ( rambank != 1 )
return cbasebal_scrollram_r(a1);
if ( a1 <= 0x7FF )
return paletteram_r();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1)
{
if ( rambank == 2 )
return func17(a1);
if ( rambank != 1 )
return func19(a1);
if ( a1 <= 0x7FF )
return paletteram_r();
return 0LL;
}

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 v0; // rdi
unsigned __int16 *v1; // rax
unsigned __int16 *v2; // rsi
unsigned __int16 v3; // cx
__int64 v4; // rdx

rawbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !rawbitmap )
return 1LL;
if ( shangha3_do_shadows[0] )
{
gfx_drawmode_table = 0x101010101010101LL;
*((_DWORD *)&gfx_drawmode_table + 2) = 16843009;
*((_WORD *)&gfx_drawmode_table + 6) = 257;
*((_BYTE *)&gfx_drawmode_table + 14) = 2;
v0 = palette_shadow_table;
v1 = *(unsigned __int16 **)(Machine + 792LL);
v2 = v1 + 128;
do
{
v3 = v1[128];
v4 = *v1++;
*(_WORD *)(v0 + 2 * v4) = v3;
}
while ( v2 != v1 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi
unsigned __int16 *v1; // rax
unsigned __int16 *v2; // rsi
unsigned __int16 v3; // cx
__int64 v4; // rdx

rawbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !rawbitmap )
return 1LL;
if ( shangha3_do_shadows[0] )
{
gfx_drawmode_table = 0x101010101010101LL;
*((_DWORD *)&gfx_drawmode_table + 2) = 16843009;
*((_WORD *)&gfx_drawmode_table + 6) = 257;
*((_BYTE *)&gfx_drawmode_table + 14) = 2;
v0 = palette_shadow_table;
v1 = *(unsigned __int16 **)(Machine + 792LL);
v2 = v1 + 128;
do
{
v3 = v1[128];
v4 = *v1++;
*(_WORD *)(v0 + 2 * v4) = v3;
}
while ( v2 != v1 );
}
return 0LL;
}

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


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


decompiled_code:
__int64 shangha3_blitter_go_w()
{
unsigned __int64 i; // r13
unsigned int v1; // er15
int v2; // esi
int v3; // er10
__int16 v4; // ax
unsigned __int16 v5; // ax
unsigned int v6; // ebx
__int64 v7; // rdx
__int16 v8; // cx
int v9; // er11
unsigned __int16 v10; // si
__int64 v11; // rbp
__int64 v12; // r9
unsigned __int16 v13; // si
__int64 v14; // r12
int v15; // edi
unsigned __int16 v17; // r8
int v18; // er14
int v19; // ebx
int v20; // er11
int v21; // edi
unsigned int v22; // er13
unsigned int v23; // er14
int v24; // ebx
unsigned int v25; // ebp
unsigned int v26; // er13
int v27; // er14
int v28; // esi
int v29; // edx
int v30; // ecx
__int64 v31; // rdi
unsigned int v32; // ecx
__int64 v33; // r11
unsigned int v34; // esi
int v35; // edi
__int64 v36; // r14
unsigned int v37; // er13
int v38; // eax
unsigned int v39; // ebp
int v40; // edx
unsigned __int16 v41; // [rsp+8h] [rbp-B0h]
int v42; // [rsp+14h] [rbp-A4h]
unsigned int v43; // [rsp+14h] [rbp-A4h]
int v44; // [rsp+18h] [rbp-A0h]
int v45; // [rsp+1Ch] [rbp-9Ch]
int v46; // [rsp+1Ch] [rbp-9Ch]
__int16 v47; // [rsp+20h] [rbp-98h]
int v48; // [rsp+28h] [rbp-90h]
unsigned __int64 v49; // [rsp+28h] [rbp-90h]
int v50; // [rsp+30h] [rbp-88h]
int v51; // [rsp+38h] [rbp-80h]
int v52; // [rsp+3Ch] [rbp-7Ch]
int v53; // [rsp+40h] [rbp-78h]
int v54; // [rsp+54h] [rbp-64h]
int v55; // [rsp+58h] [rbp-60h]
int v56; // [rsp+5Ch] [rbp-5Ch]
int v57; // [rsp+60h] [rbp-58h]
int v58; // [rsp+64h] [rbp-54h]
unsigned __int64 v59; // [rsp+68h] [rbp-50h]
int v60[18]; // [rsp+70h] [rbp-48h] BYREF

profiler_mark(8LL);
for ( i = gfxlist_addr; shangha3_ram_size > i; i += 32LL )
{
v7 = shangha3_ram;
v8 = *(_WORD *)(shangha3_ram + i + 8);
v9 = *(unsigned __int16 *)(shangha3_ram + i + 14);
v10 = *(_WORD *)(shangha3_ram + i + 4) >> 4;
v11 = v10;
v12 = v8 & 2;
if ( v10 > 0x800u )
v11 = v10 | 0xFFFFF000;
v13 = *(_WORD *)(shangha3_ram + i + 6) >> 4;
v14 = v13;
if ( v13 > 0x800u )
v14 = v13 | 0xFFFFF000;
v15 = *(unsigned __int16 *)(shangha3_ram + i + 12);
if ( flip_screen_x )
{
v11 = (unsigned int)(383 - v11 - v15);
v14 = (unsigned int)(255 - v14 - v9);
v1 = (v8 & 1) == 0;
v12 = (_DWORD)v12 == 0;
}
else
{
v1 = v8 & 1;
}
if ( *(_DWORD *)(shangha3_ram + i + 12) )
{
if ( *(unsigned __int16 *)(shangha3_ram + i + 12) <= 0x1FFu
&& *(unsigned __int16 *)(shangha3_ram + i + 14) <= 0xFFu )
{
v2 = *(unsigned __int16 *)(shangha3_ram + i + 20);
v3 = *(unsigned __int16 *)(shangha3_ram + i + 26);
if ( (unsigned int)v2 <= 0x1EF && *(unsigned __int16 *)(shangha3_ram + i + 26) <= 0x1EFu )
{
v42 = v11 + v15;
v41 = *(_WORD *)(shangha3_ram + i + 2);
v4 = *(_WORD *)(shangha3_ram + i + 10);
v60[1] = v11 + v15;
v60[0] = v11;
v60[2] = v14;
v44 = v14 + v9;
v60[3] = v14 + v9;
if ( (v8 & 8) != 0 )
{
v17 = *(_WORD *)(shangha3_ram + i + 16) >> 4;
v45 = v17 & 0xF;
v18 = *(_WORD *)(shangha3_ram + i + 18) >> 4;
v47 = v8 & 4;
v19 = ((v9 + 15) >> 4) + 1;
v20 = ((v15 + 15) >> 4) + 1;
if ( (v8 & 4) != 0 )
{
v19 *= 2;
v20 *= 2;
v55 = (int)v17 >> 3;
v21 = v18 >> 3;
}
else
{
v55 = (int)v17 >> 4;
v21 = v18 >> 4;
}
v53 = v21;
v48 = v4 & 0x70;
v56 = v21 + v19;
v57 = 512 - v3;
v58 = (*(_WORD *)(shangha3_ram + i + 18) >> 4) & 0xF;
v54 = 0;
v50 = 512 - v2;
v51 = v20 + v55;
v52 = v11;
v59 = i;
v22 = v1;
v23 = v12;
while ( 1 )
{
v24 = v55;
v25 = v22;
v26 = v23;
v27 = 0;
while ( 1 )
{
if ( v47 )
{
v28 = (v54 >> 5) - v58;
v29 = *(unsigned __int16 *)(v7 + 2 * ((v53 & 0x1F) + 32 * (unsigned __int8)v24));
v30 = (v27 >> 5) - v45;
}
else
{
v28 = (v54 >> 4) - v58;
v29 = *(unsigned __int16 *)(v7 + 2 * (((v53 & 0x10) << 8) + (v53 & 0xF) + 16 * (unsigned __int8)v24));
v30 = (v27 >> 4) - v45;
}
v31 = (unsigned int)(v42 - 15 - v30);
v32 = v52 + v30;
if ( !v25 )
v31 = v32;
v33 = (unsigned int)(v44 - 15 - v28);
v34 = v14 + v28;
if ( !v26 )
v33 = v34;
++v24;
drawgfx(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v41 & 0xF000 | v29 & 0xFFFu,
v48 | (unsigned int)(v29 >> 12),
v25,
v26,
v31,
v33,
v60,
2LL,
15LL);
v27 += v50;
if ( v51 == v24 )
break;
v7 = shangha3_ram;
}
++v53;
v23 = v26;
v22 = v25;
v54 += v57;
if ( v56 == v53 )
break;
v7 = shangha3_ram;
}
i = v59;
}
else
{
v5 = v4 & 0x7F;
v6 = v5;
if ( v2 > 1 || v3 > 1 )
{
v35 = (v15 + 15) >> 4;
if ( v35 )
{
v49 = i;
v36 = (unsigned int)v11;
v37 = v12;
v43 = (512 - v3) << 8;
v38 = 16 * v35 + v11;
v39 = v41;
v46 = v38;
do
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v39,
v6,
v1,
v37,
v36,
(unsigned int)v14,
v60,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
(unsigned int)((512 - v2) << 8),
v43);
v40 = ((_WORD)v39 + 256) & 0xFFF0;
if ( (v39 & 0xF) != 15 )
v40 = v39 + 1;
v36 = (unsigned int)(v36 + 16);
v39 = v40;
}
while ( v46 != (_DWORD)v36 );
i = v49;
}
}
else
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v41,
v5,
v1,
v12,
v11,
v14,
v60,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
0x1000000LL,
0x1000000LL);
}
}
}
}
}
}
return profiler_mark(0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int64 i; // r13
unsigned int v1; // er15
int v2; // esi
int v3; // er10
__int16 v4; // ax
unsigned __int16 v5; // ax
unsigned int v6; // ebx
__int64 v7; // rdx
__int16 v8; // cx
int v9; // er11
unsigned __int16 v10; // si
__int64 v11; // rbp
__int64 v12; // r9
unsigned __int16 v13; // si
__int64 v14; // r12
int v15; // edi
unsigned __int16 v17; // r8
int v18; // er14
int v19; // ebx
int v20; // er11
int v21; // edi
unsigned int v22; // er13
unsigned int v23; // er14
int v24; // ebx
unsigned int v25; // ebp
unsigned int v26; // er13
int v27; // er14
int v28; // esi
int v29; // edx
int v30; // ecx
__int64 v31; // rdi
unsigned int v32; // ecx
__int64 v33; // r11
unsigned int v34; // esi
int v35; // edi
__int64 v36; // r14
unsigned int v37; // er13
int v38; // eax
unsigned int v39; // ebp
int v40; // edx
unsigned __int16 v41; // [rsp+8h] [rbp-B0h]
int v42; // [rsp+14h] [rbp-A4h]
unsigned int v43; // [rsp+14h] [rbp-A4h]
int v44; // [rsp+18h] [rbp-A0h]
int v45; // [rsp+1Ch] [rbp-9Ch]
int v46; // [rsp+1Ch] [rbp-9Ch]
__int16 v47; // [rsp+20h] [rbp-98h]
int v48; // [rsp+28h] [rbp-90h]
unsigned __int64 v49; // [rsp+28h] [rbp-90h]
int v50; // [rsp+30h] [rbp-88h]
int v51; // [rsp+38h] [rbp-80h]
int v52; // [rsp+3Ch] [rbp-7Ch]
int v53; // [rsp+40h] [rbp-78h]
int v54; // [rsp+54h] [rbp-64h]
int v55; // [rsp+58h] [rbp-60h]
int v56; // [rsp+5Ch] [rbp-5Ch]
int v57; // [rsp+60h] [rbp-58h]
int v58; // [rsp+64h] [rbp-54h]
unsigned __int64 v59; // [rsp+68h] [rbp-50h]
int v60[18]; // [rsp+70h] [rbp-48h] BYREF

profiler_mark(8LL);
for ( i = gfxlist_addr; shangha3_ram_size > i; i += 32LL )
{
v7 = shangha3_ram;
v8 = *(_WORD *)(shangha3_ram + i + 8);
v9 = *(unsigned __int16 *)(shangha3_ram + i + 14);
v10 = *(_WORD *)(shangha3_ram + i + 4) >> 4;
v11 = v10;
v12 = v8 & 2;
if ( v10 > 0x800u )
v11 = v10 | 0xFFFFF000;
v13 = *(_WORD *)(shangha3_ram + i + 6) >> 4;
v14 = v13;
if ( v13 > 0x800u )
v14 = v13 | 0xFFFFF000;
v15 = *(unsigned __int16 *)(shangha3_ram + i + 12);
if ( flip_screen_x )
{
v11 = (unsigned int)(383 - v11 - v15);
v14 = (unsigned int)(255 - v14 - v9);
v1 = (v8 & 1) == 0;
v12 = (_DWORD)v12 == 0;
}
else
{
v1 = v8 & 1;
}
if ( *(_DWORD *)(shangha3_ram + i + 12) )
{
if ( *(unsigned __int16 *)(shangha3_ram + i + 12) <= 0x1FFu
&& *(unsigned __int16 *)(shangha3_ram + i + 14) <= 0xFFu )
{
v2 = *(unsigned __int16 *)(shangha3_ram + i + 20);
v3 = *(unsigned __int16 *)(shangha3_ram + i + 26);
if ( (unsigned int)v2 <= 0x1EF && *(unsigned __int16 *)(shangha3_ram + i + 26) <= 0x1EFu )
{
v42 = v11 + v15;
v41 = *(_WORD *)(shangha3_ram + i + 2);
v4 = *(_WORD *)(shangha3_ram + i + 10);
v60[1] = v11 + v15;
v60[0] = v11;
v60[2] = v14;
v44 = v14 + v9;
v60[3] = v14 + v9;
if ( (v8 & 8) != 0 )
{
v17 = *(_WORD *)(shangha3_ram + i + 16) >> 4;
v45 = v17 & 0xF;
v18 = *(_WORD *)(shangha3_ram + i + 18) >> 4;
v47 = v8 & 4;
v19 = ((v9 + 15) >> 4) + 1;
v20 = ((v15 + 15) >> 4) + 1;
if ( (v8 & 4) != 0 )
{
v19 *= 2;
v20 *= 2;
v55 = (int)v17 >> 3;
v21 = v18 >> 3;
}
else
{
v55 = (int)v17 >> 4;
v21 = v18 >> 4;
}
v53 = v21;
v48 = v4 & 0x70;
v56 = v21 + v19;
v57 = 512 - v3;
v58 = (*(_WORD *)(shangha3_ram + i + 18) >> 4) & 0xF;
v54 = 0;
v50 = 512 - v2;
v51 = v20 + v55;
v52 = v11;
v59 = i;
v22 = v1;
v23 = v12;
while ( 1 )
{
v24 = v55;
v25 = v22;
v26 = v23;
v27 = 0;
while ( 1 )
{
if ( v47 )
{
v28 = (v54 >> 5) - v58;
v29 = *(unsigned __int16 *)(v7 + 2 * ((v53 & 0x1F) + 32 * (unsigned __int8)v24));
v30 = (v27 >> 5) - v45;
}
else
{
v28 = (v54 >> 4) - v58;
v29 = *(unsigned __int16 *)(v7 + 2 * (((v53 & 0x10) << 8) + (v53 & 0xF) + 16 * (unsigned __int8)v24));
v30 = (v27 >> 4) - v45;
}
v31 = (unsigned int)(v42 - 15 - v30);
v32 = v52 + v30;
if ( !v25 )
v31 = v32;
v33 = (unsigned int)(v44 - 15 - v28);
v34 = v14 + v28;
if ( !v26 )
v33 = v34;
++v24;
drawgfx(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v41 & 0xF000 | v29 & 0xFFFu,
v48 | (unsigned int)(v29 >> 12),
v25,
v26,
v31,
v33,
v60,
2LL,
15LL);
v27 += v50;
if ( v51 == v24 )
break;
v7 = shangha3_ram;
}
++v53;
v23 = v26;
v22 = v25;
v54 += v57;
if ( v56 == v53 )
break;
v7 = shangha3_ram;
}
i = v59;
}
else
{
v5 = v4 & 0x7F;
v6 = v5;
if ( v2 > 1 || v3 > 1 )
{
v35 = (v15 + 15) >> 4;
if ( v35 )
{
v49 = i;
v36 = (unsigned int)v11;
v37 = v12;
v43 = (512 - v3) << 8;
v38 = 16 * v35 + v11;
v39 = v41;
v46 = v38;
do
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v39,
v6,
v1,
v37,
v36,
(unsigned int)v14,
v60,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
(unsigned int)((512 - v2) << 8),
v43);
v40 = ((_WORD)v39 + 256) & 0xFFF0;
if ( (v39 & 0xF) != 15 )
v40 = v39 + 1;
v36 = (unsigned int)(v36 + 16);
v39 = v40;
}
while ( v46 != (_DWORD)v36 );
i = v49;
}
}
else
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v41,
v5,
v1,
v12,
v11,
v14,
v60,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
0x1000000LL,
0x1000000LL);
}
}
}
}
}
}
return profiler_mark(0xFFFFFFFFLL);
}

original_code:
void shangha3_blitter_go_w(offs_t offset,data_t data)
{
 int offs;
 profiler_mark(PROFILER_VIDEO);
 for (offs = gfxlist_addr;offs < shangha3_ram_size;offs += 32)
 {
  int sx,sy,x,y,code,color,flipx,flipy,sizex,sizey,zoomx,zoomy;
  code = (*(UINT16 *)(&shangha3_ram[offs+2]));
  color = (*(UINT16 *)(&shangha3_ram[offs+10])) & 0x7f;
  flipx = (*(UINT16 *)(&shangha3_ram[offs+8])) & 0x01;
  flipy = (*(UINT16 *)(&shangha3_ram[offs+8])) & 0x02;
  sx = (*(UINT16 *)(&shangha3_ram[offs+4])) / 16;
  if (sx > 0x800) sx -= 0x1000;
  sy = (*(UINT16 *)(&shangha3_ram[offs+6])) / 16;
  if (sy > 0x800) sy -= 0x1000;
  sizex = (*(UINT16 *)(&shangha3_ram[offs+12]));
  sizey = (*(UINT16 *)(&shangha3_ram[offs+14]));
  zoomx = (*(UINT16 *)(&shangha3_ram[offs+20]));
  zoomy = (*(UINT16 *)(&shangha3_ram[offs+26]));
  if (flip_screen_x)
  {
   sx = 383 - sx - sizex;
   sy = 255 - sy - sizey;
   flipx = !flipx;
   flipy = !flipy;
  }
  if ((sizex || sizey)
&& sizex < 512 && sizey < 256 && zoomx < 0x1f0 && zoomy < 0x1f0)
  {
   struct rectangle myclip;
   myclip.min_x = sx;
   myclip.max_x = sx + sizex;
   myclip.min_y = sy;
   myclip.max_y = sy + sizey;
   if ((*(UINT16 *)(&shangha3_ram[offs+8])) & 0x08)
   {
    int srcx,srcy,dispx,dispy,w,h,condensed;
    condensed = (*(UINT16 *)(&shangha3_ram[offs+8])) & 0x04;
    srcx = (*(UINT16 *)(&shangha3_ram[offs+16]))/16;
    srcy = (*(UINT16 *)(&shangha3_ram[offs+18]))/16;
    dispx = srcx & 0x0f;
    dispy = srcy & 0x0f;
    h = (sizey+15)/16+1;
    w = (sizex+15)/16+1;
    if (condensed)
    {
     h *= 2;
     w *= 2;
     srcx /= 8;
     srcy /= 8;
    }
    else
    {
     srcx /= 16;
     srcy /= 16;
    }
    for (y = 0;y < h;y++)
    {
     for (x = 0;x < w;x++)
     {
      int dx,dy,tile;
      if (condensed)
      {
       int addr = ((y+srcy) & 0x1f) +
          0x20 * ((x+srcx) & 0xff);
       tile = (*(UINT16 *)(&shangha3_ram[2*addr]));
       dx = 8*x*(0x200-zoomx)/0x100 - dispx;
       dy = 8*y*(0x200-zoomy)/0x100 - dispy;
      }
      else
      {
       int addr = ((y+srcy) & 0x0f) +
          0x10 * ((x+srcx) & 0xff) +
          0x100 * ((y+srcy) & 0x10);
       tile = (*(UINT16 *)(&shangha3_ram[2*addr]));
       dx = 16*x*(0x200-zoomx)/0x100 - dispx;
       dy = 16*y*(0x200-zoomy)/0x100 - dispy;
      }
      if (flipx) dx = sx + sizex-15 - dx;
      else dx = sx + dx;
      if (flipy) dy = sy + sizey-15 - dy;
      else dy = sy + dy;
      drawgfx(rawbitmap,Machine->gfx[0],
        (tile & 0x0fff) | (code & 0xf000),
        (tile >> 12) | (color & 0x70),
        flipx,flipy,
        dx,dy,
        &myclip,TRANSPARENCY_PEN,15);
     }
    }
   }
   else
   {
    int w;
if (zoomx <= 1 && zoomy <= 1)
 drawgfxzoom(rawbitmap,Machine->gfx[0],
   code,
   color,
   flipx,flipy,
   sx,sy,
   &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
   0x1000000,0x1000000);
else
{
    w = (sizex+15)/16;
    for (x = 0;x < w;x++)
    {
     drawgfxzoom(rawbitmap,Machine->gfx[0],
       code,
       color,
       flipx,flipy,
       sx + 16*x,sy,
       &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
       (0x200-zoomx)*0x100,(0x200-zoomy)*0x100);
     if ((code & 0x000f) == 0x0f)
      code = (code + 0x100) & 0xfff0;
     else
      code++;
    }
}
   }
  }
 }
 profiler_mark(PROFILER_END);
}

canonical_original_code:
void shangha3_blitter_go_w(unsigned int offset, unsigned int data)
{
 int offs;
 profiler_mark(PROFILER_VIDEO);
 for (offs = gfxlist_addr;offs < shangha3_ram_size;offs += 32)
 {
  int sx; int sy; int x; int y; int code; int color; int flipx; int flipy; int sizex; int sizey; int zoomx; int zoomy;
  code = (*(unsigned short *)(&shangha3_ram[offs+2]));
  color = (*(unsigned short *)(&shangha3_ram[offs+10])) & 0x7f;
  flipx = (*(unsigned short *)(&shangha3_ram[offs+8])) & 0x01;
  flipy = (*(unsigned short *)(&shangha3_ram[offs+8])) & 0x02;
  sx = (*(unsigned short *)(&shangha3_ram[offs+4])) / 16;
  if (sx > 0x800) sx -= 0x1000;
  sy = (*(unsigned short *)(&shangha3_ram[offs+6])) / 16;
  if (sy > 0x800) sy -= 0x1000;
  sizex = (*(unsigned short *)(&shangha3_ram[offs+12]));
  sizey = (*(unsigned short *)(&shangha3_ram[offs+14]));
  zoomx = (*(unsigned short *)(&shangha3_ram[offs+20]));
  zoomy = (*(unsigned short *)(&shangha3_ram[offs+26]));
  if (flip_screen_x)
  {
   sx = 383 - sx - sizex;
   sy = 255 - sy - sizey;
   flipx = !flipx;
   flipy = !flipy;
  }
  if ((sizex || sizey)
&& sizex < 512 && sizey < 256 && zoomx < 0x1f0 && zoomy < 0x1f0)
  {
   struct rectangle myclip;
   myclip.min_x = sx;
   myclip.max_x = sx + sizex;
   myclip.min_y = sy;
   myclip.max_y = sy + sizey;
   if ((*(unsigned short *)(&shangha3_ram[offs+8])) & 0x08)
   {
    int srcx; int srcy; int dispx; int dispy; int w; int h; int condensed;
    condensed = (*(unsigned short *)(&shangha3_ram[offs+8])) & 0x04;
    srcx = (*(unsigned short *)(&shangha3_ram[offs+16]))/16;
    srcy = (*(unsigned short *)(&shangha3_ram[offs+18]))/16;
    dispx = srcx & 0x0f;
    dispy = srcy & 0x0f;
    h = (sizey+15)/16+1;
    w = (sizex+15)/16+1;
    if (condensed)
    {
     h *= 2;
     w *= 2;
     srcx /= 8;
     srcy /= 8;
    }
    else
    {
     srcx /= 16;
     srcy /= 16;
    }
    for (y = 0;y < h;y++)
    {
     for (x = 0;x < w;x++)
     {
      int dx; int dy; int tile;
      if (condensed)
      {
       int addr = ((y+srcy) & 0x1f) +
          0x20 * ((x+srcx) & 0xff);
       tile = (*(unsigned short *)(&shangha3_ram[2*addr]));
       dx = 8*x*(0x200-zoomx)/0x100 - dispx;
       dy = 8*y*(0x200-zoomy)/0x100 - dispy;
      }
      else
      {
       int addr = ((y+srcy) & 0x0f) +
          0x10 * ((x+srcx) & 0xff) +
          0x100 * ((y+srcy) & 0x10);
       tile = (*(unsigned short *)(&shangha3_ram[2*addr]));
       dx = 16*x*(0x200-zoomx)/0x100 - dispx;
       dy = 16*y*(0x200-zoomy)/0x100 - dispy;
      }
      if (flipx) dx = sx + sizex-15 - dx;
      else dx = sx + dx;
      if (flipy) dy = sy + sizey-15 - dy;
      else dy = sy + dy;
      drawgfx(rawbitmap,Machine->gfx[0],
        (tile & 0x0fff) | (code & 0xf000),
        (tile >> 12) | (color & 0x70),
        flipx,flipy,
        dx,dy,
        &myclip,TRANSPARENCY_PEN,15);
     }
    }
   }
   else
   {
    int w;
if (zoomx <= 1 && zoomy <= 1)
 drawgfxzoom(rawbitmap,Machine->gfx[0],
   code,
   color,
   flipx,flipy,
   sx,sy,
   &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
   0x1000000,0x1000000);
else
{
    w = (sizex+15)/16;
    for (x = 0;x < w;x++)
    {
     drawgfxzoom(rawbitmap,Machine->gfx[0],
       code,
       color,
       flipx,flipy,
       sx + 16*x,sy,
       &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
       (0x200-zoomx)*0x100,(0x200-zoomy)*0x100);
     if ((code & 0x000f) == 0x0f)
      code = (code + 0x100) & 0xfff0;
     else
      code++;
    }
}
   }
  }
 }
 profiler_mark(PROFILER_END);
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: x int

variable_types: y int

variable_types: code int

variable_types: color int

variable_types: flipx int

variable_types: sizex int

variable_types: sizey int

variable_types: zoomx int

variable_types: zoomy int

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

variable_types: srcx int

variable_types: srcy int

variable_types: dispx int

variable_types: dispy int

variable_types: w int

variable_types: h int

variable_types: condensed int

variable_types: dx int

variable_types: dy int

variable_types: tile int

variable_types: addr int


decompiled_code:
__int64 __fastcall shangha3_vh_screenrefresh(__int64 a1)
{
palette_recalc();
return copybitmap(a1, rawbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
palette_recalc();
return copybitmap(a1, rawbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void shangha3_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 palette_recalc();
 copybitmap(bitmap,rawbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void shangha3_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 palette_recalc();
 copybitmap(bitmap,rawbitmap,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 shangha3_coinctrl_w(__int64 a1, int a2)
{
__int64 result; // rax

if ( (a2 & 0xFF000000) == 0 )
{
coin_lockout_w(0LL, ~(_WORD)a2 & 0x400);
coin_lockout_w(1LL, ~(_WORD)a2 & 0x400);
coin_counter_w(0LL, a2 & 0x100);
result = coin_counter_w(1LL, a2 & 0x200);
}
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
{
coin_lockout_w(0LL, ~(_WORD)a2 & 0x400);
coin_lockout_w(1LL, ~(_WORD)a2 & 0x400);
coin_counter_w(0LL, a2 & 0x100);
result = coin_counter_w(1LL, a2 & 0x200);
}
return result;
}

original_code:
static void shangha3_coinctrl_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
 {
  coin_lockout_w(0,~data & 0x0400);
  coin_lockout_w(1,~data & 0x0400);
  coin_counter_w(0,data & 0x0100);
  coin_counter_w(1,data & 0x0200);
 }
}

canonical_original_code:
static void shangha3_coinctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
 {
  coin_lockout_w(0,~data & 0x0400);
  coin_lockout_w(1,~data & 0x0400);
  coin_counter_w(0,data & 0x0100);
  coin_counter_w(1,data & 0x0200);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

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

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


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

if ( (a2 & 0xFF0000) == 0 )
{
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (a2 << 15) & 0x40000);
coin_lockout_w(0LL, ~(_BYTE)a2 & 4);
coin_lockout_w(1LL, ~(_BYTE)a2 & 4);
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (a2 << 15) & 0x40000);
coin_lockout_w(0LL, ~(_BYTE)a2 & 4);
coin_lockout_w(1LL, ~(_BYTE)a2 & 4);
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
}
return result;
}

original_code:
static void heberpop_coinctrl_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  OKIM6295_set_bank_base(0,-1,(data & 0x08) ? 0x40000 : 0x00000);
  coin_lockout_w(0,~data & 0x04);
  coin_lockout_w(1,~data & 0x04);
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
 }
}

canonical_original_code:
static void heberpop_coinctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  OKIM6295_set_bank_base(0,-1,(data & 0x08) ? 0x40000 : 0x00000);
  coin_lockout_w(0,~data & 0x04);
  coin_lockout_w(1,~data & 0x04);
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
 }
}


decompiled_code:
__int64 __fastcall heberpop_gfxrom_r(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(137LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(137LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

original_code:
static data_t heberpop_gfxrom_r(offs_t offset)
{
 UINT8 *ROM = memory_region(REGION_GFX1);
 return ROM[offset] | (ROM[offset+1] << 8);
}

canonical_original_code:
static unsigned int heberpop_gfxrom_r(unsigned int offset)
{
 unsigned char *ROM = memory_region(REGION_GFX1);
 return ROM[offset] | (ROM[offset+1] << 8);
}

variable_types:
ROM
unsigned char *


decompiled_code:
__int64 __fastcall shangha3_paletteram_w(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx

*(_WORD *)(paletteram + a1) = a2 | *(_WORD *)(paletteram + a1) & HIWORD(a2);
v2 = (8 * ((unsigned __int16)a2 >> 11)) | ((unsigned __int16)a2 >> 11 >> 2);
v3 = (8 * ((a2 >> 6) & 0x1F)) | ((int)((a2 >> 6) & 0x1F) >> 2);
v4 = ((int)((a2 >> 1) & 0x1F) >> 2) | (8 * ((a2 >> 1) & 0x1F));
if ( a1 > 0xFF )
{
v2 ^= 4u;
v3 = (unsigned int)v3 ^ 4;
v4 = (unsigned int)v4 ^ 4;
}
return palette_change_color(a1 >> 1, v2, v3, v4);
}

original_code:
void shangha3_paletteram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int r,g,b;
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = (data >> 11) & 0x1f;
 g = (data >> 6) & 0x1f;
 b = (data >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 if (offset/2 >= 128)
 {
  r ^= 0x04;
  g ^= 0x04;
  b ^= 0x04;
 }
 palette_change_color(offset/2,r,g,b);
}

canonical_original_code:
void shangha3_paletteram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int r; int g; int b;
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = (data >> 11) & 0x1f;
 g = (data >> 6) & 0x1f;
 b = (data >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 if (offset/2 >= 128)
 {
  r ^= 0x04;
  g ^= 0x04;
  b ^= 0x04;
 }
 palette_change_color(offset/2,r,g,b);
}

variable_types: oldword int

variable_types: newword int

variable_types: r int

variable_types: g int

variable_types: b int


irqhandler

decompiled_code:
__int64 __fastcall irqhandler(unsigned int a1)
{
return cpu_set_nmi_line(1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return cpu_set_nmi_line(1LL, a1);
}

original_code:
static void irqhandler(int linestate)
{
 cpu_set_nmi_line(1,linestate);
}

variable_types: linestate int


original_code:
void tp84_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i+256*j]) = *color_prom + 128 + 16*j;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
  {
   if (*color_prom) (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = *color_prom + 16*j;
   else (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = 0;
  }
  color_prom++;
 }
}

canonical_original_code:
void tp84_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i+256*j]) = *color_prom + 128 + 16*j;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
  {
   if (*color_prom) (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = *color_prom + 16*j;
   else (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = 0;
  }
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 tp84_beam_r()
{
return 255LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 255LL;
}

original_code:
static data_t tp84_beam_r(offs_t offset)
{
 return 255;
}

canonical_original_code:
static unsigned int tp84_beam_r(unsigned int offset)
{
 return 255;
}


decompiled_code:
__int64 tp84_vh_start()
{
unsigned int v0; // er12
size_t v2; // r13
void *v3; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
dirtybuffer2 = malloc(videoram_size);
v3 = dirtybuffer2;
if ( dirtybuffer2 )
{
memset(dirtybuffer2, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
return v0;
v3 = dirtybuffer2;
free(dirtybuffer2);
}
generic_vh_stop(v3);
v0 = 1;
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
size_t v2; // r13
void *v3; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
dirtybuffer2 = malloc(videoram_size);
v3 = dirtybuffer2;
if ( dirtybuffer2 )
{
memset(dirtybuffer2, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
return v0;
v3 = dirtybuffer2;
free(dirtybuffer2);
}
generic_vh_stop(v3);
v0 = 1;
}
return v0;
}

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

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


decompiled_code:
__int64 tp84_vh_stop()
{
__int64 v0; // rdi

free(dirtybuffer2);
v0 = tmpbitmap2;
bitmap_free(tmpbitmap2);
return generic_vh_stop(v0);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi

free(dirtybuffer2);
v0 = tmpbitmap2;
bitmap_free(tmpbitmap2);
return generic_vh_stop(v0);
}

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

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


decompiled_code:
__int64 __fastcall tp84_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
int v3; // er14
__int64 v4; // r15
int v5; // edx
__int16 v6; // r8
int v7; // esi
int v8; // edi
int v9; // er13
int v10; // ebx
__int64 v11; // r15
unsigned int v12; // er10
unsigned __int8 v13; // r11
__int64 v14; // rdx
__int64 v16; // [rsp-28h] [rbp-80h]
int v17; // [rsp+18h] [rbp-40h] BYREF
int v18[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v2 = (LOWORD(col0[0]) << 6) & 0x1C0 | (2 * LOBYTE(col0[0])) & 0x30;
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
while ( 1 )
{
if ( *(_BYTE *)(v4 + dirtybuffer) )
{
*(_BYTE *)(v4 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + ((16 * *(unsigned __int8 *)(colorram + v4)) & 0x300u),
v2 + (*(_BYTE *)(colorram + v4) & 0xFu),
*(_BYTE *)(colorram + v4) & 0x40,
*(_BYTE *)(colorram + v4) & 0x80,
8 * (v3 & 0x1Fu),
(unsigned int)(8 * (v3 >> 5)),
0LL,
0LL,
0LL);
}
if ( *((_BYTE *)dirtybuffer2 + v4) )
{
*((_BYTE *)dirtybuffer2 + v4) = 0;
v5 = v3 & 0x1F;
if ( (unsigned int)(v5 - 2) > 0x1B )
break;
}
--v3;
--v4;
if ( v3 == -1 )
goto LABEL_9;
}
v6 = *(unsigned __int8 *)(tp84_colorram2 + v4);
v7 = *(unsigned __int8 *)(tp84_videoram2 + v4--);
v8 = v3--;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 512LL),
v7 + ((16 * v6) & 0x300u),
v2 + (v6 & 0xFu),
v6 & 0x40,
v6 & 0x80,
(unsigned int)(8 * v5),
(unsigned int)(8 * (v8 >> 5)),
Machine + 776LL,
0LL,
0LL);
}
while ( v3 != -1 );
}
LABEL_9:
v17 = -(unsigned __int8)*tp84_scrollx;
v18[0] = -(unsigned __int8)*tp84_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v17, 1LL, v18, Machine + 776LL, 0LL, 0LL);
v9 = (16 * LOBYTE(col0[0])) & 0x70;
v10 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v10;
do
{
v12 = *(unsigned __int8 *)(spriteram + v11 + 1);
v13 = *(_BYTE *)(spriteram + v11 + 2);
v16 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v11 + 3);
v14 = *(unsigned __int8 *)(spriteram + v11);
v11 -= 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v12,
v9 + (v13 & 0xFu),
((v13 >> 6) ^ 1) & 1,
v13 & 0x80,
v14,
v16,
Machine + 776LL,
6LL,
0LL);
v10 -= 4;
}
while ( v10 >= 0 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &topvisiblearea, 0LL, 0LL);
return copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v2; // ebx
int v3; // er14
__int64 v4; // r15
int v5; // edx
__int16 v6; // r8
int v7; // esi
int v8; // edi
int v9; // er13
int v10; // ebx
__int64 v11; // r15
unsigned int v12; // er10
unsigned __int8 v13; // r11
__int64 v14; // rdx
__int64 v16; // [rsp-28h] [rbp-80h]
int v17; // [rsp+18h] [rbp-40h] BYREF
int v18[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v2 = (LOWORD(col0[0]) << 6) & 0x1C0 | (2 * LOBYTE(col0[0])) & 0x30;
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
while ( 1 )
{
if ( *(_BYTE *)(v4 + dirtybuffer) )
{
*(_BYTE *)(v4 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + ((16 * *(unsigned __int8 *)(colorram + v4)) & 0x300u),
v2 + (*(_BYTE *)(colorram + v4) & 0xFu),
*(_BYTE *)(colorram + v4) & 0x40,
*(_BYTE *)(colorram + v4) & 0x80,
8 * (v3 & 0x1Fu),
(unsigned int)(8 * (v3 >> 5)),
0LL,
0LL,
0LL);
}
if ( *((_BYTE *)dirtybuffer2 + v4) )
{
*((_BYTE *)dirtybuffer2 + v4) = 0;
v5 = v3 & 0x1F;
if ( (unsigned int)(v5 - 2) > 0x1B )
break;
}
--v3;
--v4;
if ( v3 == -1 )
goto LABEL_9;
}
v6 = *(unsigned __int8 *)(tp84_colorram2 + v4);
v7 = *(unsigned __int8 *)(tp84_videoram2 + v4--);
v8 = v3--;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 512LL),
v7 + ((16 * v6) & 0x300u),
v2 + (v6 & 0xFu),
v6 & 0x40,
v6 & 0x80,
(unsigned int)(8 * v5),
(unsigned int)(8 * (v8 >> 5)),
Machine + 776LL,
0LL,
0LL);
}
while ( v3 != -1 );
}
LABEL_9:
v17 = -(unsigned __int8)*tp84_scrollx;
v18[0] = -(unsigned __int8)*tp84_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v17, 1LL, v18, Machine + 776LL, 0LL, 0LL);
v9 = (16 * LOBYTE(col0[0])) & 0x70;
v10 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v10;
do
{
v12 = *(unsigned __int8 *)(spriteram + v11 + 1);
v13 = *(_BYTE *)(spriteram + v11 + 2);
v16 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v11 + 3);
v14 = *(unsigned __int8 *)(spriteram + v11);
v11 -= 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v12,
v9 + (v13 & 0xFu),
((v13 >> 6) ^ 1) & 1,
v13 & 0x80,
v14,
v16,
Machine + 776LL,
6LL,
0LL);
v10 -= 4;
}
while ( v10 >= 0 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &topvisiblearea, 0LL, 0LL);
return copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

original_code:
void tp84_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int coloffset;
 coloffset = ((col0&0x18) << 1) + ((col0&0x07) << 6);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x30) << 4),
     (colorram[offs] & 0x0f) + coloffset,
     colorram[offs] & 0x40,colorram[offs] & 0x80,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx,sy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (sx < 2 || sx >= 30)
    drawgfx(tmpbitmap2,Machine->gfx[0],
      tp84_videoram2[offs] + ((tp84_colorram2[offs] & 0x30) << 4),
      (tp84_colorram2[offs] & 0x0f) + coloffset,
      tp84_colorram2[offs] & 0x40,tp84_colorram2[offs] & 0x80,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx,scrolly;
  scrollx = -*tp84_scrollx;
  scrolly = -*tp84_scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 coloffset = ((col0&0x07) << 4);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs + 0];
  sy = 240-spriteram[offs + 3];
  flipx = !(spriteram[offs + 2] & 0x40);
  flipy = spriteram[offs + 2] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    (spriteram[offs + 2] & 0x0f) + coloffset,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&topvisiblearea,TRANSPARENCY_NONE,0);
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void tp84_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int coloffset;
 coloffset = ((col0&0x18) << 1) + ((col0&0x07) << 6);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x30) << 4),
     (colorram[offs] & 0x0f) + coloffset,
     colorram[offs] & 0x40,colorram[offs] & 0x80,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx; int sy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (sx < 2 || sx >= 30)
    drawgfx(tmpbitmap2,Machine->gfx[0],
      tp84_videoram2[offs] + ((tp84_colorram2[offs] & 0x30) << 4),
      (tp84_colorram2[offs] & 0x0f) + coloffset,
      tp84_colorram2[offs] & 0x40,tp84_colorram2[offs] & 0x80,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx; int scrolly;
  scrollx = -*tp84_scrollx;
  scrolly = -*tp84_scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 coloffset = ((col0&0x07) << 4);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs + 0];
  sy = 240-spriteram[offs + 3];
  flipx = !(spriteram[offs + 2] & 0x40);
  flipy = spriteram[offs + 2] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    (spriteram[offs + 2] & 0x0f) + coloffset,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&topvisiblearea,TRANSPARENCY_NONE,0);
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

variable_types: offs int

variable_types: coloffset int

variable_types: sx int

variable_types: sy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: flipx int

variable_types: flipy int


variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: C int


decompiled_code:
__int64 tp84_sh_timer_r()
{
return ((int)cpu_gettotalcycles() / 1024) & 0xF;
}

canonical_decompiled_code:
__int64 func8()
{
return ((int)cpu_gettotalcycles() / 1024) & 0xF;
}

original_code:
static data_t tp84_sh_timer_r(offs_t offset)
{
 return (cpu_gettotalcycles() / (2048/2)) & 0x0f;
}

canonical_original_code:
static unsigned int tp84_sh_timer_r(unsigned int offset)
{
 return (cpu_gettotalcycles() / (2048/2)) & 0x0f;
}


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

result = cpu_get_pc();
if ( (_DWORD)result == 57586 )
result = cpu_spinuntil_int();
return result;
}

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

result = cpu_get_pc();
if ( (_DWORD)result == 57586 )
result = cpu_spinuntil_int();
return result;
}

original_code:
static void tp84_catchloop_w(offs_t offset,data_t data)
{
 if( cpu_get_pc()==0xe0f2 ) cpu_spinuntil_int();
}

canonical_original_code:
static void tp84_catchloop_w(unsigned int offset, unsigned int data)
{
 if( cpu_get_pc()==0xe0f2 ) cpu_spinuntil_int();
}


decompiled_code:
__int64 tp84_sh_irqtrigger_w()
{
return cpu_cause_interrupt(2LL, 255LL);
}

canonical_decompiled_code:
__int64 func10()
{
return cpu_cause_interrupt(2LL, 255LL);
}

original_code:
static void tp84_sh_irqtrigger_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(2,0xff);
}

canonical_original_code:
static void tp84_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(2,0xff);
}


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

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

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

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


original_code:
void mikie_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}

canonical_original_code:
void mikie_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}