decompiled_code:
void *__fastcall mrjong_vh_screenrefresh(__int64 a1)
{
int v1; // er15
__int64 v2; // r14
void *result; // rax
int v4; // ebx
__int64 v5; // r15
unsigned __int8 v6; // cl
__int64 v7; // rdx

v1 = videoram_size - 1;
if ( videoram_size - 1 > 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) | (8 * *(unsigned __int8 *)(colorram + v2)) & 0x100u,
*(_BYTE *)(colorram + v2) & 0x1F);
}
--v2;
--v1;
}
while ( v1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v5 = v4 + 1LL;
do
{
v6 = *(_BYTE *)(spriteram + v5 + 2) & 0x1F;
v7 = (2 * *(_BYTE *)(spriteram + v5 + 2)) & 0x40 | (unsigned int)(*(_BYTE *)(spriteram + v5) >> 2);
v5 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), v7, v6);
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
int v1; // er15
__int64 v2; // r14
void *result; // rax
int v4; // ebx
__int64 v5; // r15
unsigned __int8 v6; // cl
__int64 v7; // rdx

v1 = videoram_size - 1;
if ( videoram_size - 1 > 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) | (8 * *(unsigned __int8 *)(colorram + v2)) & 0x100u,
*(_BYTE *)(colorram + v2) & 0x1F);
}
--v2;
--v1;
}
while ( v1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v5 = v4 + 1LL;
do
{
v6 = *(_BYTE *)(spriteram + v5 + 2) & 0x1F;
v7 = (2 * *(_BYTE *)(spriteram + v5 + 2)) & 0x40 | (unsigned int)(*(_BYTE *)(spriteram + v5) >> 2);
v5 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), v7, v6);
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void mrjong_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = (videoram_size - 1); offs > 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int tile;
   int color;
   int sx, sy;
   int flipx, flipy;
   dirtybuffer[offs] = 0;
   tile = videoram[offs] | ((colorram[offs] & 0x20) << 3);
   flipx = (colorram[offs] & 0x40) >> 6;
   flipy = (colorram[offs] & 0x80) >> 7;
   color = colorram[offs] & 0x1f;
   sx = 31 - (offs % 32);
   sy = 31 - (offs / 32);
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap, Machine->gfx[0],
     tile,
     color,
     flipx, flipy,
     8*sx, 8*sy,
     &Machine->visible_area, TRANSPARENCY_NONE, 0);
  }
 }
 copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->visible_area, TRANSPARENCY_NONE, 0);
 for (offs = (spriteram_size - 4); offs >= 0; offs -= 4)
 {
  int sprt;
  int color;
  int sx, sy;
  int flipx, flipy;
  sprt = (((spriteram[offs + 1] >> 2) & 0x3f) | ((spriteram[offs + 3] & 0x20) << 1));
  flipx = (spriteram[offs + 1] & 0x01) >> 0;
  flipy = (spriteram[offs + 1] & 0x02) >> 1;
  color = (spriteram[offs + 3] & 0x1f);
  sx = 224 - spriteram[offs + 2];
  sy = spriteram[offs + 0];
  if (flipscreen)
  {
   sx = 208 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap, Machine->gfx[1],
    sprt,
    color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area, TRANSPARENCY_PEN, 0);
 }
}

canonical_original_code:
void mrjong_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = (videoram_size - 1); offs > 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int tile;
   int color;
   int sx; int sy;
   int flipx; int flipy;
   dirtybuffer[offs] = 0;
   tile = videoram[offs] | ((colorram[offs] & 0x20) << 3);
   flipx = (colorram[offs] & 0x40) >> 6;
   flipy = (colorram[offs] & 0x80) >> 7;
   color = colorram[offs] & 0x1f;
   sx = 31 - (offs % 32);
   sy = 31 - (offs / 32);
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap, Machine->gfx[0],
     tile,
     color,
     flipx, flipy,
     8*sx, 8*sy,
     &Machine->visible_area, TRANSPARENCY_NONE, 0);
  }
 }
 copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->visible_area, TRANSPARENCY_NONE, 0);
 for (offs = (spriteram_size - 4); offs >= 0; offs -= 4)
 {
  int sprt;
  int color;
  int sx; int sy;
  int flipx; int flipy;
  sprt = (((spriteram[offs + 1] >> 2) & 0x3f) | ((spriteram[offs + 3] & 0x20) << 1));
  flipx = (spriteram[offs + 1] & 0x01) >> 0;
  flipy = (spriteram[offs + 1] & 0x02) >> 1;
  color = (spriteram[offs + 3] & 0x1f);
  sx = 224 - spriteram[offs + 2];
  sy = spriteram[offs + 0];
  if (flipscreen)
  {
   sx = 208 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap, Machine->gfx[1],
    sprt,
    color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area, TRANSPARENCY_PEN, 0);
 }
}

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

variable_types: offs int

variable_types: tile int

variable_types: color int

variable_types: flipx int

variable_types: flipy int

variable_types: sprt int


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
void *__fastcall io_0x00_w(__int64 a1, char a2)
{
return mrjong_flipscreen_w(0LL, (a2 & 4u) > 2);
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, char a2)
{
return func3(0LL, (a2 & 4u) > 2);
}

original_code:
void io_0x00_w(offs_t offset,data_t data)
{
 mrjong_flipscreen_w(0, ((data & 0x04) > 2));
}

canonical_original_code:
void io_0x00_w(unsigned int offset, unsigned int data)
{
 mrjong_flipscreen_w(0, ((data & 0x04) > 2));
}


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
if ( ((a2 >> 3) & 7) != gfxbank )
{
gfxbank = (a2 >> 3) & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
if ( ((a2 >> 3) & 7) != gfxbank )
{
gfxbank = (a2 >> 3) & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void sichuan2_bankswitch_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (gfxbank != ((data & 0x38) >> 3))
 {
  gfxbank = (data & 0x38) >> 3;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void sichuan2_bankswitch_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (gfxbank != ((data & 0x38) >> 3))
 {
  gfxbank = (data & 0x38) >> 3;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall sichuan2_paletteram_w(unsigned __int8 a1, char a2)
{
int v2; // esi
int v3; // edx
int v4; // ecx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(_BYTE *)(paletteram + a1) & 0x1F;
v3 = *(_BYTE *)(paletteram + (unsigned int)a1 + 256) & 0x1F;
v4 = *(_BYTE *)(paletteram + (unsigned int)a1 + 512) & 0x1F;
return palette_change_color(
a1,
(8 * v2) | (unsigned int)(v2 >> 2),
(8 * v3) | (unsigned int)(v3 >> 2),
(8 * v4) | (unsigned int)(v4 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, char a2)
{
int v2; // esi
int v3; // edx
int v4; // ecx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(_BYTE *)(paletteram + a1) & 0x1F;
v3 = *(_BYTE *)(paletteram + (unsigned int)a1 + 256) & 0x1F;
v4 = *(_BYTE *)(paletteram + (unsigned int)a1 + 512) & 0x1F;
return palette_change_color(
a1,
(8 * v2) | (unsigned int)(v2 >> 2),
(8 * v3) | (unsigned int)(v3 >> 2),
(8 * v4) | (unsigned int)(v4 >> 2));
}

original_code:
void sichuan2_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 paletteram[offset] = data;
 offset &= 0xff;
 r = paletteram[offset+0x000] & 0x1f;
 g = paletteram[offset+0x100] & 0x1f;
 b = paletteram[offset+0x200] & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset,r,g,b);
}

canonical_original_code:
void sichuan2_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 paletteram[offset] = data;
 offset &= 0xff;
 r = paletteram[offset+0x000] & 0x1f;
 g = paletteram[offset+0x100] & 0x1f;
 b = paletteram[offset+0x200] & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall sichuan2_vh_screenrefresh(__int64 a1)
{
int v1; // ebp
__int64 v2; // rbx
_BYTE *v3; // rcx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1;
do
{
v3 = (char *)dirtybuffer + v2 + 1;
if ( *((_BYTE *)dirtybuffer + v2) || *v3 )
{
*v3 = 0;
*((_BYTE *)dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(gfxbank << 12)
+ *(unsigned __int8 *)(videoram + v2)
+ ((*(unsigned __int8 *)(videoram + v2 + 1) << 8) & 0xF00u),
*(_BYTE *)(videoram + v2 + 1) >> 4,
0LL,
0LL,
(4 * (_WORD)v1) & 0x1F8,
(unsigned int)(8 * (v1 >> 7)),
Machine + 776LL,
0LL,
0LL);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebp
__int64 v2; // rbx
_BYTE *v3; // rcx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1;
do
{
v3 = (char *)dirtybuffer + v2 + 1;
if ( *((_BYTE *)dirtybuffer + v2) || *v3 )
{
*v3 = 0;
*((_BYTE *)dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(gfxbank << 12)
+ *(unsigned __int8 *)(videoram + v2)
+ ((*(unsigned __int8 *)(videoram + v2 + 1) << 8) & 0xF00u),
*(_BYTE *)(videoram + v2 + 1) >> 4,
0LL,
0LL,
(4 * (_WORD)v1) & 0x1F8,
(unsigned int)(8 * (v1 >> 7)),
Machine + 776LL,
0LL,
0LL);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void sichuan2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx,sy;
   dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 64;
   sy = (offs/2) / 64;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0x0f) << 8) + (gfxbank << 12),
     (videoram[offs+1] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void sichuan2_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx; int sy;
   dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 64;
   sy = (offs/2) / 64;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0x0f) << 8) + (gfxbank << 12),
     (videoram[offs+1] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

variable_types: sx int

variable_types: sy int

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


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

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

original_code:
static void sichuan2_coin_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 4);
}

canonical_original_code:
static void sichuan2_coin_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 4);
}


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

v0 = input_port_3_r(0LL);
if ( (input_port_4_r(0LL) & 4) != 0 )
result = v0 | (16 * (unsigned int)input_port_5_r(0LL));
else
result = v0 | (unsigned int)(input_port_5_r(0LL) & 0xF0);
return result;
}

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

v0 = input_port_3_r(0LL);
if ( (input_port_4_r(0LL) & 4) != 0 )
result = v0 | (16 * (unsigned int)input_port_5_r(0LL));
else
result = v0 | (unsigned int)(input_port_5_r(0LL) & 0xF0);
return result;
}

original_code:
static data_t sichuan2_dsw1_r(offs_t offset)
{
 int ret = input_port_3_r(0);
 if (input_port_4_r(0) & 0x04)
 {
  ret |= (input_port_5_r(0) << 4);
 }
 else
 {
  ret |= (input_port_5_r(0) & 0xf0);
 }
 return ret;
}

canonical_original_code:
static unsigned int sichuan2_dsw1_r(unsigned int offset)
{
 int ret = input_port_3_r(0);
 if (input_port_4_r(0) & 0x04)
 {
  ret |= (input_port_5_r(0) << 4);
 }
 else
 {
  ret |= (input_port_5_r(0) & 0xf0);
 }
 return ret;
}

variable_types: ret int

return_type: unsigned int


original_code:
void pandoras_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0; i < Machine->drv->total_colors; i++)
 {
  int bit0, bit1, bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

canonical_original_code:
void pandoras_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0; i < Machine->drv->total_colors; i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

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

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


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

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

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

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


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

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

original_code:
static data_t pandoras_sharedram_r(offs_t offset){
 return pandoras_sharedram[offset];
}

canonical_original_code:
static unsigned int pandoras_sharedram_r(unsigned int offset){
 return pandoras_sharedram[offset];
}


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

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

original_code:
static data_t pandoras_sharedram2_r(offs_t offset){
 return pandoras_sharedram2[offset];
}

canonical_original_code:
static unsigned int pandoras_sharedram2_r(unsigned int offset){
 return pandoras_sharedram2[offset];
}


decompiled_code:
void __fastcall i8039_irqen_w(__int64 a1, char a2)
{
i8039_irqenable = a2 & 0x80;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2)
{
i8039_irqenable = a2 & 0x80;
}

original_code:
static void i8039_irqen_w(offs_t offset,data_t data)
{
 i8039_irqenable = data & 0x80;
}

canonical_original_code:
static void i8039_irqen_w(unsigned int offset, unsigned int data)
{
 i8039_irqenable = data & 0x80;
}


decompiled_code:
void pandoras_init_machine()
{
firq_old_data_b = 0;
firq_old_data_a = 0;
irq_enable_b = 0;
irq_enable_a = 0;
}

canonical_decompiled_code:
void func9()
{
firq_old_data_b = 0;
firq_old_data_a = 0;
irq_enable_b = 0;
irq_enable_a = 0;
}

original_code:
static void pandoras_init_machine( void )
{
 firq_old_data_a = firq_old_data_b = 0;
 irq_enable_a = irq_enable_b = 0;
}

canonical_original_code:
static void pandoras_init_machine()
{
 firq_old_data_a = firq_old_data_b = 0;
 irq_enable_a = irq_enable_b = 0;
}


decompiled_code:
void pandoras_portB_w()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

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

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


decompiled_code:
_BOOL8 pandoras_vh_start()
{
layer0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return layer0 == 0;
}

canonical_decompiled_code:
_BOOL8 func11()
{
layer0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return layer0 == 0;
}

original_code:
int pandoras_vh_start(void)
{
 layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,0x00,8,8,32,32);
 if (!layer0)
  return 1;
 return 0;
}

canonical_original_code:
int pandoras_vh_start()
{
 layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,0x00,8,8,32,32);
 if (!layer0)
  return 1;
 return 0;
}

return_type: int


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

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

original_code:
void pandoras_scrolly_w(offs_t offset,data_t data)
{
 tilemap_set_scrolly(layer0,0,data);
}

canonical_original_code:
void pandoras_scrolly_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrolly(layer0,0,data);
}


decompiled_code:
__int64 __fastcall pandoras_vh_screenrefresh(__int64 a1)
{
tilemap_update(layer0);
tilemap_render(layer0);
tilemap_draw(a1, layer0, 1LL);
draw_sprites(a1, (unsigned __int8 *)(pandoras_sharedram + 2048LL));
return tilemap_draw(a1, layer0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
tilemap_update(layer0);
tilemap_render(layer0);
tilemap_draw(a1, layer0, 1LL);
func15(a1, (unsigned __int8 *)(pandoras_sharedram + 2048LL));
return tilemap_draw(a1, layer0, 0LL);
}

original_code:
void pandoras_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update( layer0 );
 tilemap_render( layer0 );
 tilemap_draw( bitmap, layer0, 1 );
 draw_sprites( bitmap, &pandoras_sharedram[0x800] );
 tilemap_draw( bitmap, layer0, 0 );
}

canonical_original_code:
void pandoras_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update( layer0 );
 tilemap_render( layer0 );
 tilemap_draw( bitmap, layer0, 1 );
 draw_sprites( bitmap, &pandoras_sharedram[0x800] );
 tilemap_draw( bitmap, layer0, 0 );
}

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


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

result = (unsigned int)firq_old_data_a;
if ( !firq_old_data_a && a2 )
{
result = cpu_cause_interrupt(0LL, 2LL);
firq_old_data_a = a2;
}
else
{
firq_old_data_a = a2;
}
return result;
}

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

result = (unsigned int)firq_old_data_a;
if ( !firq_old_data_a && a2 )
{
result = cpu_cause_interrupt(0LL, 2LL);
firq_old_data_a = a2;
}
else
{
firq_old_data_a = a2;
}
return result;
}

original_code:
void pandoras_cpua_irqtrigger_w(offs_t offset,data_t data){
 if (!firq_old_data_a && data){
  cpu_cause_interrupt(0,2);
 }
 firq_old_data_a = data;
}

canonical_original_code:
void pandoras_cpua_irqtrigger_w(unsigned int offset, unsigned int data){
 if (!firq_old_data_a && data){
  cpu_cause_interrupt(0,2);
 }
 firq_old_data_a = data;
}


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

result = (unsigned int)firq_old_data_b;
if ( !firq_old_data_b && a2 )
{
result = cpu_cause_interrupt(1LL, 2LL);
firq_old_data_b = a2;
}
else
{
firq_old_data_b = a2;
}
return result;
}

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

result = (unsigned int)firq_old_data_b;
if ( !firq_old_data_b && a2 )
{
result = cpu_cause_interrupt(1LL, 2LL);
firq_old_data_b = a2;
}
else
{
firq_old_data_b = a2;
}
return result;
}

original_code:
void pandoras_cpub_irqtrigger_w(offs_t offset,data_t data){
 if (!firq_old_data_b && data){
  cpu_cause_interrupt(1,2);
 }
 firq_old_data_b = data;
}

canonical_original_code:
void pandoras_cpub_irqtrigger_w(unsigned int offset, unsigned int data){
 if (!firq_old_data_b && data){
  cpu_cause_interrupt(1,2);
 }
 firq_old_data_b = data;
}


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

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

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

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


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

result = (unsigned int)i8039_irqenable;
if ( i8039_irqenable )
result = cpu_cause_interrupt(3LL, 1LL);
return result;
}

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

result = (unsigned int)i8039_irqenable;
if ( i8039_irqenable )
result = cpu_cause_interrupt(3LL, 1LL);
return result;
}

original_code:
void pandoras_i8039_irqtrigger_w(offs_t offset,data_t data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(3,1);
}

canonical_original_code:
void pandoras_i8039_irqtrigger_w(unsigned int offset, unsigned int data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(3,1);
}


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

if ( irq_enable_b )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

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

if ( irq_enable_b )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int pandoras_interrupt_b( void ){
 if (irq_enable_b)
  return 1;
 return ignore_interrupt();
}

canonical_original_code:
static int pandoras_interrupt_b(){
 if (irq_enable_b)
  return 1;
 return ignore_interrupt();
}


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

if ( irq_enable_a )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

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

if ( irq_enable_a )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int pandoras_interrupt_a( void ){
 if (irq_enable_a)
  return 1;
 return ignore_interrupt();
}

canonical_original_code:
static int pandoras_interrupt_a(){
 if (irq_enable_a)
  return 1;
 return ignore_interrupt();
}


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

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

original_code:
static data_t pandoras_portB_r(offs_t offset)
{
 return (cpu_gettotalcycles() / 1024) & 0x0f;
}

canonical_original_code:
static unsigned int pandoras_portB_r(unsigned int offset)
{
 return (cpu_gettotalcycles() / 1024) & 0x0f;
}


decompiled_code:
__int64 __fastcall pandoras_flipscreen_w(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 != 0 ? 3 : 0);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 != 0 ? 3 : 0);
}

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

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


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

switch ( a1 )
{
case 0:
if ( !a2 )
result = cpu_set_irq_line(0LL, 0LL, 0LL);
irq_enable_a = a2;
break;
case 2:
result = coin_counter_w(0LL, a2 & 1);
break;
case 3:
result = coin_counter_w(1LL, a2 & 1);
break;
case 5:
result = pandoras_flipscreen_w(0LL, a2);
break;
case 6:
if ( !a2 )
result = cpu_set_irq_line(1LL, 0LL, 0LL);
irq_enable_b = a2;
break;
case 7:
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
if ( !a2 )
result = cpu_set_irq_line(0LL, 0LL, 0LL);
irq_enable_a = a2;
break;
case 2:
result = coin_counter_w(0LL, a2 & 1);
break;
case 3:
result = coin_counter_w(1LL, a2 & 1);
break;
case 5:
result = func24(0LL, a2);
break;
case 6:
if ( !a2 )
result = cpu_set_irq_line(1LL, 0LL, 0LL);
irq_enable_b = a2;
break;
case 7:
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

original_code:
static void pandoras_int_control_w(offs_t offset,data_t data){
 switch (offset){
  case 0x00: if (!data) cpu_set_irq_line(0, 0, 0);
     irq_enable_a = data;
     break;
  case 0x02: coin_counter_w(0,data & 0x01);
     break;
  case 0x03: coin_counter_w(1,data & 0x01);
     break;
  case 0x05: pandoras_flipscreen_w(0, data);
     break;
  case 0x06: if (!data) cpu_set_irq_line(1, 0, 0);
     irq_enable_b = data;
     break;
  case 0x07: cpu_cause_interrupt(1,4);
     break;
  default:
   break;
 }
}

canonical_original_code:
static void pandoras_int_control_w(unsigned int offset, unsigned int data){
 switch (offset){
  case 0x00: if (!data) cpu_set_irq_line(0, 0, 0);
     irq_enable_a = data;
     break;
  case 0x02: coin_counter_w(0,data & 0x01);
     break;
  case 0x03: coin_counter_w(1,data & 0x01);
     break;
  case 0x05: pandoras_flipscreen_w(0, data);
     break;
  case 0x06: if (!data) cpu_set_irq_line(1, 0, 0);
     irq_enable_b = data;
     break;
  case 0x07: cpu_cause_interrupt(1,4);
     break;
  default:
   break;
 }
}


decompiled_code:
void *__fastcall get_tile_info0(int a1)
{
__int64 v1; // rax
int v2; // edi
__int64 v3; // rsi
__int64 v4; // r9
unsigned int v5; // edx
void *result; // rax
__int64 v7; // r8
int v8; // esi

v1 = a1;
v2 = *(unsigned __int8 *)(colorram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (*(unsigned __int8 *)(videoram + v1) + ((16 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
result = &tile_info;
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
*((_QWORD *)&tile_info + 1) = v4 + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v7 = *(_QWORD *)(v3 + 32);
v8 = 0;
if ( v7 )
v8 = *(_DWORD *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v8;
*((_DWORD *)&tile_info + 5) = (unsigned __int8)v2 >> 6;
*((_DWORD *)&tile_info + 6) = (v2 >> 5) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__int64 v1; // rax
int v2; // edi
__int64 v3; // rsi
__int64 v4; // r9
unsigned int v5; // edx
void *result; // rax
__int64 v7; // r8
int v8; // esi

v1 = a1;
v2 = *(unsigned __int8 *)(colorram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (*(unsigned __int8 *)(videoram + v1) + ((16 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
result = &tile_info;
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
*((_QWORD *)&tile_info + 1) = v4 + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v7 = *(_QWORD *)(v3 + 32);
v8 = 0;
if ( v7 )
v8 = *(_DWORD *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v8;
*((_DWORD *)&tile_info + 5) = (unsigned __int8)v2 >> 6;
*((_DWORD *)&tile_info + 6) = (v2 >> 5) & 1;
return result;
}

original_code:
static void get_tile_info0(int tile_index)
{
 unsigned char attr = colorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index] + ((attr & 0x10) << 4)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x20) >> 5;
}

canonical_original_code:
static void get_tile_info0(int tile_index)
{
 unsigned char attr = colorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index] + ((attr & 0x10) << 4)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x20) >> 5;
}

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


original_code:
static void draw_sprites(struct osd_bitmap *bitmap, unsigned char* sr)
{
 int offs;
 for (offs = 0; offs < 0x100; offs += 4)
 {
  int sx = sr[offs + 1];
  int sy = 240 - sr[offs];
  int nflipx = sr[offs + 3] & 0x40;
  int nflipy = sr[offs + 3] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
   sr[offs + 2],
   sr[offs + 3] & 0x0f,
   !nflipx,!nflipy,
   sx,sy,
   &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap, unsigned char *sr)
{
 int offs;
 for (offs = 0; offs < 0x100; offs += 4)
 {
  int sx = sr[offs + 1];
  int sy = 240 - sr[offs];
  int nflipx = sr[offs + 3] & 0x40;
  int nflipy = sr[offs + 3] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
   sr[offs + 2],
   sr[offs + 3] & 0x0f,
   !nflipx,!nflipy,
   sx,sy,
   &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

variable_types:
sr
unsigned char *

variable_types: offs int

variable_types: nflipx int

variable_types: nflipy int


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

result = a2 == 0;
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 == 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = a2 == 0;
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 == 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall zodiac_control_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 2);
return coin_counter_w(1LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 2);
return coin_counter_w(1LL, a2 & 1);
}

original_code:
void zodiac_control_w(offs_t offset,data_t data)
{
 coin_counter_w(0, data & 0x02);
 coin_counter_w(1, data & 0x01);
}

canonical_original_code:
void zodiac_control_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0, data & 0x02);
 coin_counter_w(1, data & 0x01);
}


decompiled_code:
void *__fastcall zodiack_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v2; // r15
int v3; // edx
int v4; // edi
unsigned __int8 v5; // cl
unsigned __int64 v6; // r14
int v7; // edx
int v8; // edi
unsigned __int8 v9; // cl
unsigned int v10; // er11
__int64 v11; // rdx
__int64 i; // rax
__int64 j; // r14
unsigned int v14; // esi
void *result; // rax
int v16; // ebp
__int64 v17; // r15
__int64 v18; // rdi
char v19; // r10
__int64 v20; // r11
unsigned __int8 v21; // dl
__int64 v22; // r9
__int64 v23; // r8
unsigned __int8 *v24; // rax
char *v25; // rdx
int v26; // ecx
char *v27; // rcx
_DWORD v28[31]; // [rsp+10h] [rbp-B8h] BYREF
char v29; // [rsp+8Ch] [rbp-3Ch] BYREF

if ( videoram_size )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = v2 & 0x1F;
v4 = (int)v2 >> 5;
v5 = *(_BYTE *)(galaxian_attributesram + 2 * v3 + 1) & 7;
if ( flipscreen )
{
v3 = 31 - v3;
v4 = 31 - v4;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 536LL),
*(unsigned __int8 *)(videoram + v2),
v5,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v3),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
++v2;
}
while ( videoram_size > v2 );
if ( videoram_size )
{
v6 = 0LL;
do
{
v7 = v6 & 0x1F;
v8 = (int)v6 >> 5;
v9 = (*(_BYTE *)(galaxian_attributesram + 2 * v7 + 1) >> 4) & 7;
if ( flipscreen )
{
v8 = 31 - v8;
v7 = 31 - v7;
}
v10 = *(unsigned __int8 *)(zodiack_videoram2 + v6++);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v10,
v9,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v7),
(unsigned int)(8 * v8),
Machine + 776LL,
0LL,
0LL);
}
while ( videoram_size > v6 );
}
}
v11 = galaxian_attributesram;
if ( flipscreen )
{
v24 = (unsigned __int8 *)galaxian_attributesram;
v25 = &v29;
do
{
v26 = *v24;
v24 += 2;
*(_DWORD *)v25 = v26;
v27 = v25;
v25 -= 4;
}
while ( v28 != (_DWORD *)v27 );
}
else
{
for ( i = 0LL; i != 32; ++i )
v28[i] = -*(unsigned __int8 *)(v11 + 2 * i);
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v28, Machine + 776LL, 6LL, 0LL);
if ( galaxian_bulletsram_size )
{
for ( j = 3LL; ; j += 4LL )
{
v14 = *(unsigned __int8 *)(galaxian_bulletsram + j - 2);
if ( !percuss_hardware )
v14 = 255 - *(unsigned __int8 *)(galaxian_bulletsram + j - 2);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
*(unsigned __int8 *)(galaxian_bulletsram + j)
+ (unsigned int)**(unsigned __int16 **)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 56LL),
v14,
Machine + 776LL,
2LL,
0LL);
if ( galaxian_bulletsram_size <= (unsigned __int64)(j + 1) )
break;
}
}
result = &spriteram_size;
v16 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v17 = v16 + 3LL;
do
{
v18 = *(unsigned __int8 *)(spriteram + v17 - 3);
v20 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v17);
v21 = *(_BYTE *)(spriteram + v17 - 2) & 0x3F;
v22 = *(_BYTE *)(spriteram + v17 - 2) & 0x80;
v23 = ((*(_BYTE *)(spriteram + v17 - 2) >> 6) ^ 1) & 1;
if ( percuss_hardware )
v22 = (_DWORD)v22 == 0;
else
v18 = (unsigned int)(240 - v18);
v19 = *(_BYTE *)(spriteram + v17 - 1);
v17 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v21,
v19 & 7,
v23,
v22,
v20,
v18,
Machine + 776LL,
2LL,
0LL);
v16 -= 4;
}
while ( v16 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
unsigned __int64 v2; // r15
int v3; // edx
int v4; // edi
unsigned __int8 v5; // cl
unsigned __int64 v6; // r14
int v7; // edx
int v8; // edi
unsigned __int8 v9; // cl
unsigned int v10; // er11
__int64 v11; // rdx
__int64 i; // rax
__int64 j; // r14
unsigned int v14; // esi
void *result; // rax
int v16; // ebp
__int64 v17; // r15
__int64 v18; // rdi
char v19; // r10
__int64 v20; // r11
unsigned __int8 v21; // dl
__int64 v22; // r9
__int64 v23; // r8
unsigned __int8 *v24; // rax
char *v25; // rdx
int v26; // ecx
char *v27; // rcx
_DWORD v28[31]; // [rsp+10h] [rbp-B8h] BYREF
char v29; // [rsp+8Ch] [rbp-3Ch] BYREF

if ( videoram_size )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = v2 & 0x1F;
v4 = (int)v2 >> 5;
v5 = *(_BYTE *)(galaxian_attributesram + 2 * v3 + 1) & 7;
if ( flipscreen )
{
v3 = 31 - v3;
v4 = 31 - v4;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 536LL),
*(unsigned __int8 *)(videoram + v2),
v5,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v3),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
++v2;
}
while ( videoram_size > v2 );
if ( videoram_size )
{
v6 = 0LL;
do
{
v7 = v6 & 0x1F;
v8 = (int)v6 >> 5;
v9 = (*(_BYTE *)(galaxian_attributesram + 2 * v7 + 1) >> 4) & 7;
if ( flipscreen )
{
v8 = 31 - v8;
v7 = 31 - v7;
}
v10 = *(unsigned __int8 *)(zodiack_videoram2 + v6++);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v10,
v9,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v7),
(unsigned int)(8 * v8),
Machine + 776LL,
0LL,
0LL);
}
while ( videoram_size > v6 );
}
}
v11 = galaxian_attributesram;
if ( flipscreen )
{
v24 = (unsigned __int8 *)galaxian_attributesram;
v25 = &v29;
do
{
v26 = *v24;
v24 += 2;
*(_DWORD *)v25 = v26;
v27 = v25;
v25 -= 4;
}
while ( v28 != (_DWORD *)v27 );
}
else
{
for ( i = 0LL; i != 32; ++i )
v28[i] = -*(unsigned __int8 *)(v11 + 2 * i);
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v28, Machine + 776LL, 6LL, 0LL);
if ( galaxian_bulletsram_size )
{
for ( j = 3LL; ; j += 4LL )
{
v14 = *(unsigned __int8 *)(galaxian_bulletsram + j - 2);
if ( !percuss_hardware )
v14 = 255 - *(unsigned __int8 *)(galaxian_bulletsram + j - 2);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
*(unsigned __int8 *)(galaxian_bulletsram + j)
+ (unsigned int)**(unsigned __int16 **)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 56LL),
v14,
Machine + 776LL,
2LL,
0LL);
if ( galaxian_bulletsram_size <= (unsigned __int64)(j + 1) )
break;
}
}
result = &spriteram_size;
v16 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v17 = v16 + 3LL;
do
{
v18 = *(unsigned __int8 *)(spriteram + v17 - 3);
v20 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v17);
v21 = *(_BYTE *)(spriteram + v17 - 2) & 0x3F;
v22 = *(_BYTE *)(spriteram + v17 - 2) & 0x80;
v23 = ((*(_BYTE *)(spriteram + v17 - 2) >> 6) ^ 1) & 1;
if ( percuss_hardware )
v22 = (_DWORD)v22 == 0;
else
v18 = (unsigned int)(240 - v18);
v19 = *(_BYTE *)(spriteram + v17 - 1);
v17 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v21,
v19 & 7,
v23,
v22,
v20,
v18,
Machine + 776LL,
2LL,
0LL);
v16 -= 4;
}
while ( v16 >= 0 );
}
return result;
}

original_code:
void zodiack_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code,sx,sy,col;
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  sy = offs / 32;
  sx = offs % 32;
  col = galaxian_attributesram[2 * sx + 1] & 0x07;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  code = videoram[offs];
  drawgfx(tmpbitmap,Machine->gfx[3],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    0,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code,sx,sy,col;
  sy = offs / 32;
  sx = offs % 32;
  col = (galaxian_attributesram[2 * sx + 1] >> 4) & 0x07;
  if (flipscreen)
  {
   sy = 31 - sy;
   sx = 31 - sx;
  }
  code = zodiack_videoram2[offs];
  drawgfx(bitmap,Machine->gfx[0],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  int i, scroll[32];
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = galaxian_attributesram[2 * i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -galaxian_attributesram[2 * i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 for (offs = 0;offs < galaxian_bulletsram_size;offs += 4)
 {
  int x,y;
  x = galaxian_bulletsram[offs + 3] + Machine->drv->gfxdecodeinfo[2].gfxlayout->width;
  y = galaxian_bulletsram[offs + 1];
  if (!percuss_hardware)
  {
   y = 255 - y;
  }
  drawgfx(bitmap,Machine->gfx[2],
    0,
    0,
    0,0,
    x,y,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int flipx,flipy,sx,sy,spritecode;
  sx = 240 - spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = !(spriteram[offs + 1] & 0x40);
  flipy = spriteram[offs + 1] & 0x80;
  spritecode = spriteram[offs + 1] & 0x3f;
  if (percuss_hardware)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spritecode,
    spriteram[offs + 2] & 0x07,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void zodiack_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code; int sx; int sy; int col;
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  sy = offs / 32;
  sx = offs % 32;
  col = galaxian_attributesram[2 * sx + 1] & 0x07;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  code = videoram[offs];
  drawgfx(tmpbitmap,Machine->gfx[3],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    0,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code; int sx; int sy; int col;
  sy = offs / 32;
  sx = offs % 32;
  col = (galaxian_attributesram[2 * sx + 1] >> 4) & 0x07;
  if (flipscreen)
  {
   sy = 31 - sy;
   sx = 31 - sx;
  }
  code = zodiack_videoram2[offs];
  drawgfx(bitmap,Machine->gfx[0],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  int i; int scroll[32];
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = galaxian_attributesram[2 * i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -galaxian_attributesram[2 * i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 for (offs = 0;offs < galaxian_bulletsram_size;offs += 4)
 {
  int x; int y;
  x = galaxian_bulletsram[offs + 3] + Machine->drv->gfxdecodeinfo[2].gfxlayout->width;
  y = galaxian_bulletsram[offs + 1];
  if (!percuss_hardware)
  {
   y = 255 - y;
  }
  drawgfx(bitmap,Machine->gfx[2],
    0,
    0,
    0,0,
    x,y,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int flipx; int flipy; int sx; int sy; int spritecode;
  sx = 240 - spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = !(spriteram[offs + 1] & 0x40);
  flipy = spriteram[offs + 1] & 0x80;
  spritecode = spriteram[offs + 1] & 0x3f;
  if (percuss_hardware)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spritecode,
    spriteram[offs + 2] & 0x07,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: code int

variable_types: col int

variable_types:
scroll
int [32]

variable_types: x int

variable_types: y int

variable_types: flipx int

variable_types: flipy int

variable_types: spritecode int


decompiled_code:
__int64 zodiack_init_machine()
{
percuss_hardware = 0;
return espial_init_machine();
}

canonical_decompiled_code:
__int64 func4()
{
percuss_hardware = 0;
return espial_init_machine();
}

original_code:
static void zodiack_init_machine(void)
{
 percuss_hardware = 0;
 espial_init_machine();
}

canonical_original_code:
static void zodiack_init_machine()
{
 percuss_hardware = 0;
 espial_init_machine();
}


decompiled_code:
__int64 percuss_init_machine()
{
percuss_hardware = 1;
return espial_init_machine();
}

canonical_decompiled_code:
__int64 func5()
{
percuss_hardware = 1;
return espial_init_machine();
}

original_code:
static void percuss_init_machine(void)
{
 percuss_hardware = 1;
 espial_init_machine();
}

canonical_original_code:
static void percuss_init_machine()
{
 percuss_hardware = 1;
 espial_init_machine();
}


decompiled_code:
__int64 __fastcall timer_callback_2151(int a1)
{
Timer[2 * (a1 & 0x7F) + (a1 >> 7)] = 0LL;
return YM2151TimerOver(a1 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
Timer[2 * (a1 & 0x7F) + (a1 >> 7)] = 0LL;
return YM2151TimerOver(a1 & 0x7F);
}

original_code:
static void timer_callback_2151(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 YM2151TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2151(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 YM2151TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2151UpdateRequest(int a1)
{
return stream_update((unsigned int)stream[a1], 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return stream_update((unsigned int)stream[a1], 0LL);
}

original_code:
void YM2151UpdateRequest(int chip)
{
 stream_update(stream[chip],0);
}

variable_types: chip int


decompiled_code:
// attributes: thunk
__int64 __fastcall YM2151_sh_start(__int64 a1)
{
return my_YM2151_sh_start_constprop_0(a1);
}

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

original_code:
int YM2151_sh_start(const struct MachineSound *msound)
{
 return my_YM2151_sh_start(msound,0);
}

canonical_original_code:
int YM2151_sh_start(struct MachineSound *msound)
{
 return my_YM2151_sh_start(msound,0);
}

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


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

if ( FMMode == 4 )
result = OPMShutdown();
return result;
}

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

if ( FMMode == 4 )
result = OPMShutdown();
return result;
}

original_code:
void YM2151_sh_stop(void)
{
 switch(FMMode)
 {
 case 4:
  OPMShutdown();
  break;
 }
}

canonical_original_code:
void YM2151_sh_stop()
{
 switch(FMMode)
 {
 case 4:
  OPMShutdown();
  break;
 }
}


decompiled_code:
_DWORD *YM2151_sh_reset()
{
_DWORD *result; // rax
unsigned int v1; // ebx
__int64 v2; // rdi

result = (_DWORD *)intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
while ( FMMode != 4 )
{
if ( *result <= (signed int)++v1 )
return result;
}
v2 = v1++;
OPMResetChip(v2);
result = (_DWORD *)intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

canonical_decompiled_code:
_DWORD *func6()
{
_DWORD *result; // rax
unsigned int v1; // ebx
__int64 v2; // rdi

result = (_DWORD *)intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
while ( FMMode != 4 )
{
if ( *result <= (signed int)++v1 )
return result;
}
v2 = v1++;
OPMResetChip(v2);
result = (_DWORD *)intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

original_code:
void YM2151_sh_reset(void)
{
 int i;
 for (i = 0;i < intf->num;i++)
 switch(FMMode)
 {
 case 4:
  OPMResetChip(i);
  break;
 }
}

canonical_original_code:
void YM2151_sh_reset()
{
 int i;
 for (i = 0;i < intf->num;i++)
 switch(FMMode)
 {
 case 4:
  OPMResetChip(i);
  break;
 }
}

variable_types: i int


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

if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(0LL, 1LL);
else
result = 0LL;
return result;
}

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

if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(0LL, 1LL);
else
result = 0LL;
return result;
}

original_code:
data_t YM2151_status_port_0_r(offs_t offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(0,1);
 }
 return 0;
}

canonical_original_code:
unsigned int YM2151_status_port_0_r(unsigned int offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(0,1);
 }
 return 0;
}


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

if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(1LL, 1LL);
else
result = 0LL;
return result;
}

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

if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(1LL, 1LL);
else
result = 0LL;
return result;
}

original_code:
data_t YM2151_status_port_1_r(offs_t offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(1,1);
 }
 return 0;
}

canonical_original_code:
unsigned int YM2151_status_port_1_r(unsigned int offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(1,1);
 }
 return 0;
}


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

if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(2LL, 1LL);
else
result = 0LL;
return result;
}

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

if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(2LL, 1LL);
else
result = 0LL;
return result;
}

original_code:
data_t YM2151_status_port_2_r(offs_t offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(2,1);
 }
 return 0;
}

canonical_original_code:
unsigned int YM2151_status_port_2_r(unsigned int offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(2,1);
 }
 return 0;
}


decompiled_code:
void __fastcall YM2151_register_port_0_w(__int64 a1, int a2)
{
lastreg0 = a2;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2)
{
lastreg0 = a2;
}

original_code:
void YM2151_register_port_0_w(offs_t offset,data_t data)
{
 lastreg0 = data;
}

canonical_original_code:
void YM2151_register_port_0_w(unsigned int offset, unsigned int data)
{
 lastreg0 = data;
}


decompiled_code:
void __fastcall YM2151_register_port_1_w(__int64 a1, int a2)
{
lastreg1 = a2;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2)
{
lastreg1 = a2;
}

original_code:
void YM2151_register_port_1_w(offs_t offset,data_t data)
{
 lastreg1 = data;
}

canonical_original_code:
void YM2151_register_port_1_w(unsigned int offset, unsigned int data)
{
 lastreg1 = data;
}


decompiled_code:
void __fastcall YM2151_register_port_2_w(__int64 a1, int a2)
{
lastreg2 = a2;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, int a2)
{
lastreg2 = a2;
}

original_code:
void YM2151_register_port_2_w(offs_t offset,data_t data)
{
 lastreg2 = data;
}

canonical_original_code:
void YM2151_register_port_2_w(unsigned int offset, unsigned int data)
{
 lastreg2 = data;
}


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

if ( FMMode == 4 )
{
YM2151Write(0LL, 0LL, (unsigned __int8)lastreg0);
result = YM2151Write(0LL, 1LL, a2);
}
return result;
}

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

if ( FMMode == 4 )
{
YM2151Write(0LL, 0LL, (unsigned __int8)lastreg0);
result = YM2151Write(0LL, 1LL, a2);
}
return result;
}

original_code:
void YM2151_data_port_0_w(offs_t offset,data_t data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(0,0,lastreg0);
  YM2151Write(0,1,data);
  break;
 }
}

canonical_original_code:
void YM2151_data_port_0_w(unsigned int offset, unsigned int data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(0,0,lastreg0);
  YM2151Write(0,1,data);
  break;
 }
}


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

if ( FMMode == 4 )
{
YM2151Write(1LL, 0LL, (unsigned __int8)lastreg1);
result = YM2151Write(1LL, 1LL, a2);
}
return result;
}

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

if ( FMMode == 4 )
{
YM2151Write(1LL, 0LL, (unsigned __int8)lastreg1);
result = YM2151Write(1LL, 1LL, a2);
}
return result;
}

original_code:
void YM2151_data_port_1_w(offs_t offset,data_t data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(1,0,lastreg1);
  YM2151Write(1,1,data);
  break;
 }
}

canonical_original_code:
void YM2151_data_port_1_w(unsigned int offset, unsigned int data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(1,0,lastreg1);
  YM2151Write(1,1,data);
  break;
 }
}


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

if ( FMMode == 4 )
{
YM2151Write(2LL, 0LL, (unsigned __int8)lastreg2);
result = YM2151Write(2LL, 1LL, a2);
}
return result;
}

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

if ( FMMode == 4 )
{
YM2151Write(2LL, 0LL, (unsigned __int8)lastreg2);
result = YM2151Write(2LL, 1LL, a2);
}
return result;
}

original_code:
void YM2151_data_port_2_w(offs_t offset,data_t data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(2,0,lastreg2);
  YM2151Write(2,1,data);
  break;
 }
}

canonical_original_code:
void YM2151_data_port_2_w(unsigned int offset, unsigned int data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(2,0,lastreg2);
  YM2151Write(2,1,data);
  break;
 }
}


original_code:
static void K053157_get_char01_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000+2));
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x300) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

canonical_original_code:
static void K053157_get_char01_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000+2));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x300) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

variable_types: attr int

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


original_code:
static void K053157_get_char11_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000+2));
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x700) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

canonical_original_code:
static void K053157_get_char11_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000+2));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x700) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

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


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

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

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

variable_types:
offset
unsigned int


decompiled_code:
__int64 control2_r()
{
return (unsigned int)cur_control2;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)cur_control2;
}

original_code:
static data_t control2_r(offs_t offset)
{
 return cur_control2;
}

canonical_original_code:
static unsigned int control2_r(unsigned int offset)
{
 return cur_control2;
}


decompiled_code:
__int64 back_ctrla_r()
{
return (unsigned int)cur_back_ctrla;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)cur_back_ctrla;
}

original_code:
static data_t back_ctrla_r(offs_t offset)
{
 return cur_back_ctrla;
}

canonical_original_code:
static unsigned int back_ctrla_r(unsigned int offset)
{
 return cur_back_ctrla;
}


decompiled_code:
void __fastcall back_ctrla_w(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_ctrla != a2 )
cur_back_ctrla = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_ctrla != a2 )
cur_back_ctrla = a2;
}

original_code:
static void back_ctrla_w(offs_t offset,data_t data)
{
 data &= 0xff;
 if(data != cur_back_ctrla) {
  cur_back_ctrla = data;
 }
}

canonical_original_code:
static void back_ctrla_w(unsigned int offset, unsigned int data)
{
 data &= 0xff;
 if(data != cur_back_ctrla) {
  cur_back_ctrla = data;
 }
}

variable_types:
data
unsigned int


decompiled_code:
__int64 back_select_r()
{
return (unsigned int)cur_back_select;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)cur_back_select;
}

original_code:
static data_t back_select_r(offs_t offset)
{
 return cur_back_select;
}

canonical_original_code:
static unsigned int back_select_r(unsigned int offset)
{
 return cur_back_select;
}


decompiled_code:
void __fastcall back_select_w(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_select != a2 )
cur_back_select = a2;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_select != a2 )
cur_back_select = a2;
}

original_code:
static void back_select_w(offs_t offset,data_t data)
{
 data &= 0xff;
 if(data != cur_back_select) {
  cur_back_select = data;
 }
}

canonical_original_code:
static void back_select_w(unsigned int offset, unsigned int data)
{
 data &= 0xff;
 if(data != cur_back_select) {
  cur_back_select = data;
 }
}


decompiled_code:
void __fastcall K053157_w(int a1, unsigned int a2)
{
int v2; // ecx
__int64 v3; // rsi
__int64 (*v4)(void); // rdx
__int64 v5; // rax
int v6; // edx
__int64 v7; // rax
unsigned int v8; // eax

if ( a1 != 50 )
{
if ( a1 != 52 )
return;
v2 = K053157_rombank;
if ( (unsigned int)(K053157_rombank - 1) > 0xF )
return;
cpu_bankbase[K053157_rombank] = K053157_rombase + (int)((a2 % K053157_romnbbanks) << 13);
if ( v2 != ophw )
return;
LABEL_10:
ophw = -1;
v8 = cpu_get_pc();
cpu_setOPbase16(v8);
return;
}
v3 = (unsigned int)(unsigned __int8)a2 - 1;
if ( (unsigned int)v3 > 0x18 )
{
v4 = 0LL;
v5 = 0LL;
}
else
{
v4 = (__int64 (*)(void))K053157_modify_notifiers[CSWTCH_92[v3]];
v5 = CSWTCH_92[v3] << 13;
}
K053157_cur_notifier = v4;
v6 = K053157_rambank;
v7 = K053157_rambase + v5;
K053157_cur_rambase = v7;
if ( (unsigned int)(K053157_rambank - 1) <= 0xF )
{
cpu_bankbase[K053157_rambank] = v7;
if ( v6 == ophw )
goto LABEL_10;
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, unsigned int a2)
{
int v2; // ecx
__int64 v3; // rsi
__int64 (*v4)(void); // rdx
__int64 v5; // rax
int v6; // edx
__int64 v7; // rax
unsigned int v8; // eax

if ( a1 != 50 )
{
if ( a1 != 52 )
return;
v2 = K053157_rombank;
if ( (unsigned int)(K053157_rombank - 1) > 0xF )
return;
cpu_bankbase[K053157_rombank] = K053157_rombase + (int)((a2 % K053157_romnbbanks) << 13);
if ( v2 != ophw )
return;
LABEL_10:
ophw = -1;
v8 = cpu_get_pc();
cpu_setOPbase16(v8);
return;
}
v3 = (unsigned int)(unsigned __int8)a2 - 1;
if ( (unsigned int)v3 > 0x18 )
{
v4 = 0LL;
v5 = 0LL;
}
else
{
v4 = (__int64 (*)(void))K053157_modify_notifiers[CSWTCH_92[v3]];
v5 = CSWTCH_92[v3] << 13;
}
K053157_cur_notifier = v4;
v6 = K053157_rambank;
v7 = K053157_rambase + v5;
K053157_cur_rambase = v7;
if ( (unsigned int)(K053157_rambank - 1) <= 0xF )
{
cpu_bankbase[K053157_rambank] = v7;
if ( v6 == ophw )
goto LABEL_10;
}
}

original_code:
void K053157_w(offs_t offset,data_t data)
{
 switch(offset) {
 case 0x32: {
  int nb;
  data &= 0xff;
  switch(data) {
  case 0:
   nb = 0;
   break;
  case 1:
   nb = 1;
   break;
  case 8:
   nb = 2;
   break;
  case 9:
   nb = 3;
   break;
  case 0x10:
   nb = 4;
   break;
  case 0x11:
   nb = 5;
   break;
  case 0x18:
   nb = 6;
   break;
  case 0x19:
   nb = 7;
   break;
  default:
   nb = 0;
   break;
  }
  K053157_cur_rambank = data;
  K053157_cur_rambase = K053157_rambase + nb*0x2000;
  K053157_cur_notifier = K053157_modify_notifiers[nb];
  { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (UINT8 *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 case 0x34: {
  K053157_cur_rombank = data % K053157_romnbbanks;
  { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (UINT8 *)(K053157_rombase + 0x2000*K053157_cur_rombank); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 default:
  break;
 }
}

canonical_original_code:
void K053157_w(unsigned int offset, unsigned int data)
{
 switch(offset) {
 case 0x32: {
  int nb;
  data &= 0xff;
  switch(data) {
  case 0:
   nb = 0;
   break;
  case 1:
   nb = 1;
   break;
  case 8:
   nb = 2;
   break;
  case 9:
   nb = 3;
   break;
  case 0x10:
   nb = 4;
   break;
  case 0x11:
   nb = 5;
   break;
  case 0x18:
   nb = 6;
   break;
  case 0x19:
   nb = 7;
   break;
  default:
   nb = 0;
   break;
  }
  K053157_cur_rambank = data;
  K053157_cur_rambase = K053157_rambase + nb*0x2000;
  K053157_cur_notifier = K053157_modify_notifiers[nb];
  { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (unsigned char *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 case 0x34: {
  K053157_cur_rombank = data % K053157_romnbbanks;
  { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (unsigned char *)(K053157_rombase + 0x2000*K053157_cur_rombank); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 default:
  break;
 }
}

variable_types: nb int


decompiled_code:
__int64 __fastcall backrom_r(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(139LL) + (cur_back_select << 11) + (a1 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(139LL) + (cur_back_select << 11) + (a1 >> 2));
}

original_code:
static data_t backrom_r(offs_t offset)
{
 return *(memory_region(REGION_GFX3) + 2048*cur_back_select + (offset>>2));
}

canonical_original_code:
static unsigned int backrom_r(unsigned int offset)
{
 return *(memory_region(REGION_GFX3) + 2048*cur_back_select + (offset>>2));
}


decompiled_code:
__int64 __fastcall K053157_char11_m(int a1)
{
return tilemap_mark_tile_dirty(K053157_char11_tilemap, (unsigned int)(a1 / 4));
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return tilemap_mark_tile_dirty(K053157_char11_tilemap, (unsigned int)(a1 / 4));
}

original_code:
static void K053157_char11_m(int offset)
{
 tilemap_mark_tile_dirty(K053157_char11_tilemap,offset/4);
}

variable_types: offset int


decompiled_code:
__int64 __fastcall K053157_char01_m(int a1)
{
return tilemap_mark_tile_dirty(K053157_char01_tilemap, (unsigned int)(a1 / 4));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return tilemap_mark_tile_dirty(K053157_char01_tilemap, (unsigned int)(a1 / 4));
}

original_code:
static void K053157_char01_m(int offset)
{
 tilemap_mark_tile_dirty(K053157_char01_tilemap,offset/4);
}


decompiled_code:
// attributes: thunk
__int64 xexex_vh_stop()
{
return K053247_vh_stop();
}

original_code:
void xexex_vh_stop(void)
{
 K053247_vh_stop();
}

canonical_original_code:
void xexex_vh_stop()
{
 K053247_vh_stop();
}


decompiled_code:
__int64 __fastcall xexex_palette_w(unsigned int a1, int a2)
{
__int64 v2; // rcx

v2 = xexex_palette_ram;
*(_WORD *)(xexex_palette_ram + a1) = a2 | *(_WORD *)(xexex_palette_ram + a1) & HIWORD(a2);
return palette_change_color(
(a1 & 0xFFFFFFFC) >> 2,
*(unsigned __int8 *)(v2 + (a1 & 0xFFFFFFFC)),
(unsigned __int8)HIBYTE(*(_WORD *)(v2 + (a1 & 0xFFFFFFFC) + 2)),
(unsigned __int8)*(_WORD *)(v2 + (a1 & 0xFFFFFFFC) + 2));
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, int a2)
{
__int64 v2; // rcx

v2 = xexex_palette_ram;
*(_WORD *)(xexex_palette_ram + a1) = a2 | *(_WORD *)(xexex_palette_ram + a1) & HIWORD(a2);
return palette_change_color(
(a1 & 0xFFFFFFFC) >> 2,
*(unsigned __int8 *)(v2 + (a1 & 0xFFFFFFFC)),
(unsigned __int8)HIBYTE(*(_WORD *)(v2 + (a1 & 0xFFFFFFFC) + 2)),
(unsigned __int8)*(_WORD *)(v2 + (a1 & 0xFFFFFFFC) + 2));
}

original_code:
void xexex_palette_w(offs_t offset,data_t data)
{
 int r, g, b;
 int data0, data1;
 ((*(UINT16 *)((xexex_palette_ram+offset)) = (((*(UINT16 *)(xexex_palette_ram+offset)) & ((data) >> 16)) | (data))));
 offset &= ~3;
 data0 = (*(UINT16 *)(xexex_palette_ram + offset));
 data1 = (*(UINT16 *)(xexex_palette_ram + offset + 2));
 r = data0 & 0xff;
 g = data1 >> 8;
 b = data1 & 0xff;
 palette_change_color(offset>>2, r, g, b);
}

canonical_original_code:
void xexex_palette_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int data0; int data1;
 ((*(unsigned short *)((xexex_palette_ram+offset)) = (((*(unsigned short *)(xexex_palette_ram+offset)) & ((data) >> 16)) | (data))));
 offset &= ~3;
 data0 = (*(unsigned short *)(xexex_palette_ram + offset));
 data1 = (*(unsigned short *)(xexex_palette_ram + offset + 2));
 r = data0 & 0xff;
 g = data1 >> 8;
 b = data1 & 0xff;
 palette_change_color(offset>>2, r, g, b);
}

variable_types: r int

variable_types: g int

variable_types: b int


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

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

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

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


decompiled_code:
// attributes: thunk
__int64 init_xexex()
{
return gfx_init();
}

canonical_decompiled_code:
__int64 func18()
{
return func17();
}

original_code:
static void init_xexex(void)
{
 cur_rombank = 0;
 gfx_init();
}

canonical_original_code:
static void init_xexex()
{
 cur_rombank = 0;
 gfx_init();
}


decompiled_code:
__int64 xexex_interrupt()
{
int v0; // eax
__int64 result; // rax

v0 = cpu_getiloops();
if ( v0 )
{
if ( v0 != 1 || !(unsigned int)K053247_is_IRQ_enabled() )
return ignore_interrupt();
result = 5LL;
}
else
{
if ( !(unsigned int)K053247_is_IRQ_enabled() )
return ignore_interrupt();
result = 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // eax
__int64 result; // rax

v0 = cpu_getiloops();
if ( v0 )
{
if ( v0 != 1 || !(unsigned int)K053247_is_IRQ_enabled() )
return ignore_interrupt();
result = 5LL;
}
else
{
if ( !(unsigned int)K053247_is_IRQ_enabled() )
return ignore_interrupt();
result = 4LL;
}
return result;
}

original_code:
static int xexex_interrupt(void)
{
 switch (cpu_getiloops())
 {
  case 0:
   if (K053247_is_IRQ_enabled()) return 4;
   break;
  case 1:
   if (K053247_is_IRQ_enabled()) return 5;
   break;
  case 2:
   break;
 }
 return ignore_interrupt();
}

canonical_original_code:
static int xexex_interrupt()
{
 switch (cpu_getiloops())
 {
  case 0:
   if (K053247_is_IRQ_enabled()) return 4;
   break;
  case 1:
   if (K053247_is_IRQ_enabled()) return 5;
   break;
  case 2:
   break;
 }
 return ignore_interrupt();
}


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

v0 = EEPROM_read_bit();
result = v0 | (unsigned int)input_port_1_r(0LL);
if ( init_eeprom_count )
{
result = (unsigned __int8)result & 0xF7;
--init_eeprom_count;
}
return result;
}

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

v0 = EEPROM_read_bit();
result = v0 | (unsigned int)input_port_1_r(0LL);
if ( init_eeprom_count )
{
result = (unsigned __int8)result & 0xF7;
--init_eeprom_count;
}
return result;
}

original_code:
static data_t control1_r(offs_t offset)
{
 int res;
 res = EEPROM_read_bit() | input_port_1_r(0);
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xf7;
 }
 return res;
}

canonical_original_code:
static unsigned int control1_r(unsigned int offset)
{
 int res;
 res = EEPROM_read_bit() | input_port_1_r(0);
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xf7;
 }
 return res;
}

variable_types: res int


decompiled_code:
__int64 control0_r()
{
return input_port_0_r(0LL);
}

canonical_decompiled_code:
__int64 func23()
{
return input_port_0_r(0LL);
}

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

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


decompiled_code:
__int64 __fastcall K053157_vh_start(int a1, int a2, unsigned int a3)
{
__int64 v4; // rax
__int64 v5; // rax
void *v6; // rax
int v7; // eax
unsigned int v9; // eax
unsigned int v10; // eax
__int64 v11; // [rsp+0h] [rbp-38h]

v4 = tilemap_create(K053157_get_char01_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v11) = 32;
K053157_char01_tilemap = v4;
v5 = tilemap_create(K053157_get_char11_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v11);
K053157_char11_tilemap = v5;
if ( !K053157_char01_tilemap || !v5 )
return 1LL;
*(_DWORD *)(v5 + 132) = 0;
K053157_rambank = a1;
v6 = malloc(0x10000uLL);
K053157_cur_notifier = 0LL;
K053157_rambase = (__int64)v6;
K053157_cur_rambase = (__int64)v6;
if ( (unsigned int)(a1 - 1) <= 0xF )
{
cpu_bankbase[a1] = v6;
if ( ophw == a1 )
{
ophw = -1;
v10 = cpu_get_pc();
cpu_setOPbase16(v10);
}
}
K053157_rombank = a2;
K053157_rombase = memory_region(a3);
K053157_romnbbanks = (int)memory_region_length(a3) / 0x2000;
v7 = K053157_rombank;
if ( (unsigned int)(K053157_rombank - 1) <= 0xF )
{
cpu_bankbase[K053157_rombank] = K053157_rombase;
if ( v7 == ophw )
{
ophw = -1;
v9 = cpu_get_pc();
cpu_setOPbase16(v9);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func24(int a1, int a2, unsigned int a3)
{
__int64 v4; // rax
__int64 v5; // rax
void *v6; // rax
int v7; // eax
unsigned int v9; // eax
unsigned int v10; // eax
__int64 v11; // [rsp+0h] [rbp-38h]

v4 = tilemap_create(K053157_get_char01_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v11) = 32;
K053157_char01_tilemap = v4;
v5 = tilemap_create(K053157_get_char11_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v11);
K053157_char11_tilemap = v5;
if ( !K053157_char01_tilemap || !v5 )
return 1LL;
*(_DWORD *)(v5 + 132) = 0;
K053157_rambank = a1;
v6 = malloc(0x10000uLL);
K053157_cur_notifier = 0LL;
K053157_rambase = (__int64)v6;
K053157_cur_rambase = (__int64)v6;
if ( (unsigned int)(a1 - 1) <= 0xF )
{
cpu_bankbase[a1] = v6;
if ( ophw == a1 )
{
ophw = -1;
v10 = cpu_get_pc();
cpu_setOPbase16(v10);
}
}
K053157_rombank = a2;
K053157_rombase = memory_region(a3);
K053157_romnbbanks = (int)memory_region_length(a3) / 0x2000;
v7 = K053157_rombank;
if ( (unsigned int)(K053157_rombank - 1) <= 0xF )
{
cpu_bankbase[K053157_rombank] = K053157_rombase;
if ( v7 == ophw )
{
ophw = -1;
v9 = cpu_get_pc();
cpu_setOPbase16(v9);
}
}
return 0LL;
}

original_code:
int K053157_vh_start(int rambank, int rombank, int roms_memory_region)
{
 K053157_char01_tilemap = tilemap_create(K053157_get_char01_tile_info,tilemap_scan_rows,
           0x00,8,8,64,32);
 K053157_char11_tilemap = tilemap_create(K053157_get_char11_tile_info,tilemap_scan_rows,
           0x01,8,8,64,32);
 if(!K053157_char01_tilemap || !K053157_char11_tilemap)
  return 1;
 K053157_char11_tilemap->transparent_pen = 0;
 K053157_rambank = rambank;
 K053157_cur_rambank = 0;
 K053157_rambase = (unsigned char*)malloc(0x2000*8);
 K053157_cur_rambase = K053157_rambase;
 K053157_cur_notifier = K053157_modify_notifiers[0];
 { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (UINT8 *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 K053157_rombank = rombank;
 K053157_cur_rombank = 0;
 K053157_rombase = memory_region(roms_memory_region);
 K053157_romnbbanks = memory_region_length(roms_memory_region)/0x2000;
 { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (UINT8 *)(K053157_rombase); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 return 0;
}

canonical_original_code:
int K053157_vh_start(int rambank, int rombank, int roms_memory_region)
{
 K053157_char01_tilemap = tilemap_create(K053157_get_char01_tile_info,tilemap_scan_rows,
           0x00,8,8,64,32);
 K053157_char11_tilemap = tilemap_create(K053157_get_char11_tile_info,tilemap_scan_rows,
           0x01,8,8,64,32);
 if(!K053157_char01_tilemap || !K053157_char11_tilemap)
  return 1;
 K053157_char11_tilemap->transparent_pen = 0;
 K053157_rambank = rambank;
 K053157_cur_rambank = 0;
 K053157_rambase = (unsigned char *)malloc(0x2000*8);
 K053157_cur_rambase = K053157_rambase;
 K053157_cur_notifier = K053157_modify_notifiers[0];
 { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (unsigned char *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 K053157_rombank = rombank;
 K053157_cur_rombank = 0;
 K053157_rombase = memory_region(roms_memory_region);
 K053157_romnbbanks = memory_region_length(roms_memory_region)/0x2000;
 { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (unsigned char *)(K053157_rombase); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 return 0;
}

variable_types: rambank int

variable_types: rombank int


decompiled_code:
_BOOL8 xexex_vh_start()
{
K053157_vh_start(2, 6, 0x89u);
return (unsigned int)K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) != 0;
}

canonical_decompiled_code:
_BOOL8 func25()
{
func24(2, 6, 0x89u);
return (unsigned int)K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) != 0;
}

original_code:
int xexex_vh_start(void)
{
 K053157_vh_start(2, 6, REGION_GFX1);
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int xexex_vh_start()
{
 K053157_vh_start(2, 6, REGION_GFX1);
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 K053157_update()
{
tilemap_update(K053157_char01_tilemap);
return tilemap_update(K053157_char11_tilemap);
}

canonical_decompiled_code:
__int64 func26()
{
tilemap_update(K053157_char01_tilemap);
return tilemap_update(K053157_char11_tilemap);
}

original_code:
void K053157_update(void)
{
 tilemap_update(K053157_char01_tilemap);
 tilemap_update(K053157_char11_tilemap);
}

canonical_original_code:
void K053157_update()
{
 tilemap_update(K053157_char01_tilemap);
 tilemap_update(K053157_char11_tilemap);
}


decompiled_code:
__int64 K053157_render()
{
tilemap_render(K053157_char01_tilemap);
return tilemap_render(K053157_char11_tilemap);
}

canonical_decompiled_code:
__int64 func27()
{
tilemap_render(K053157_char01_tilemap);
return tilemap_render(K053157_char11_tilemap);
}

original_code:
void K053157_render(void)
{
 tilemap_render(K053157_char01_tilemap);
 tilemap_render(K053157_char11_tilemap);
}

canonical_original_code:
void K053157_render()
{
 tilemap_render(K053157_char01_tilemap);
 tilemap_render(K053157_char11_tilemap);
}


decompiled_code:
__int64 __fastcall K053157_draw(__int64 a1)
{
tilemap_draw(a1, K053157_char01_tilemap, 0LL);
return tilemap_draw(a1, K053157_char11_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1)
{
tilemap_draw(a1, K053157_char01_tilemap, 0LL);
return tilemap_draw(a1, K053157_char11_tilemap, 0LL);
}

original_code:
void K053157_draw(struct osd_bitmap *bitmap)
{
 tilemap_draw(bitmap, K053157_char01_tilemap, 0);
 tilemap_draw(bitmap, K053157_char11_tilemap, 0);
}

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


decompiled_code:
__int64 __fastcall xexex_vh_screenrefresh(__int64 a1)
{
K053157_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
K053157_render();
K053157_draw(a1);
return K053247_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
func26();
palette_init_used_colors();
K053247_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
func27();
func28(a1);
return K053247_sprites_draw(a1);
}

original_code:
void xexex_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K053157_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 K053157_render();
 K053157_draw(bitmap);
 K053247_sprites_draw(bitmap);
}


decompiled_code:
void __fastcall sound_cmd_w(__int64 a1, char a2)
{
if ( a2 == -2 )
sound_status = 127;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char a2)
{
if ( a2 == -2 )
sound_status = 127;
}

original_code:
static void sound_cmd_w(offs_t offset,data_t data)
{
 sound_cmd = data & 0xff;
 if(sound_cmd == 0xfe)
   sound_status = 0x7f;
}

canonical_original_code:
static void sound_cmd_w(unsigned int offset, unsigned int data)
{
 sound_cmd = data & 0xff;
 if(sound_cmd == 0xfe)
   sound_status = 0x7f;
}


decompiled_code:
__int64 sound_status_r()
{
return (unsigned int)sound_status;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)sound_status;
}

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

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


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

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

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

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

variable_types:
file
void *


decompiled_code:
__int64 __fastcall control2_w(__int64 a1, unsigned int a2)
{
EEPROM_write_bit(a2 & 1);
EEPROM_set_cs_line(((unsigned __int8)(a2 >> 1) ^ 1) & 1);
EEPROM_set_clock_line((a2 >> 2) & 1);
cur_control2 = a2;
return K053246_set_OBJCHA_line(BYTE1(a2) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned int a2)
{
EEPROM_write_bit(a2 & 1);
EEPROM_set_cs_line(((unsigned __int8)(a2 >> 1) ^ 1) & 1);
EEPROM_set_clock_line((a2 >> 2) & 1);
cur_control2 = a2;
return K053246_set_OBJCHA_line(BYTE1(a2) & 1);
}

original_code:
static void control2_w(offs_t offset,data_t data)
{
 EEPROM_write_bit(data & 0x01);
 EEPROM_set_cs_line((data & 0x02) ? 0 : 1);
 EEPROM_set_clock_line((data & 0x04) ? 1 : 0);
 cur_control2 = data;
 K053246_set_OBJCHA_line((data & 0x0100) ? 1 : 0);
}

canonical_original_code:
static void control2_w(unsigned int offset, unsigned int data)
{
 EEPROM_write_bit(data & 0x01);
 EEPROM_set_cs_line((data & 0x02) ? 0 : 1);
 EEPROM_set_clock_line((data & 0x04) ? 1 : 0);
 cur_control2 = data;
 K053246_set_OBJCHA_line((data & 0x0100) ? 1 : 0);
}


original_code:
void tagteam_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void tagteam_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
void __fastcall tagteam_control_w(__int64 a1, unsigned int a2)
{
palettebank = (a2 >> 7) & 1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
palettebank = (a2 >> 7) & 1;
}

original_code:
void tagteam_control_w(offs_t offset,data_t data)
{
 palettebank = (data & 0x80) >> 7;
}

canonical_original_code:
void tagteam_control_w(unsigned int offset, unsigned int data)
{
 palettebank = (data & 0x80) >> 7;
}


decompiled_code:
__int64 __fastcall tagteam_mirrorvideoram_r(unsigned int a1)
{
return videoram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return videoram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
data_t tagteam_mirrorvideoram_r(offs_t offset)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return videoram_r(offset);
}

canonical_original_code:
unsigned int tagteam_mirrorvideoram_r(unsigned int offset)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return videoram_r(offset);
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall tagteam_mirrorcolorram_r(unsigned int a1)
{
return colorram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return colorram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
data_t tagteam_mirrorcolorram_r(offs_t offset)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return colorram_r(offset);
}

canonical_original_code:
unsigned int tagteam_mirrorcolorram_r(unsigned int offset)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return colorram_r(offset);
}


decompiled_code:
__int64 __fastcall tagteam_mirrorvideoram_w(unsigned int a1)
{
return videoram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return videoram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
void tagteam_mirrorvideoram_w(offs_t offset,data_t data)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 videoram_w(offset,data);
}

canonical_original_code:
void tagteam_mirrorvideoram_w(unsigned int offset, unsigned int data)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 videoram_w(offset,data);
}


decompiled_code:
__int64 __fastcall tagteam_mirrorcolorram_w(unsigned int a1)
{
return colorram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return colorram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
void tagteam_mirrorcolorram_w(offs_t offset,data_t data)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 colorram_w(offset,data);
}

canonical_original_code:
void tagteam_mirrorcolorram_w(unsigned int offset, unsigned int data)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 colorram_w(offset,data);
}


decompiled_code:
__int64 __fastcall tagteam_vh_screenrefresh(__int64 a1)
{
drawchars(a1, palettebank);
return drawsprites(a1, palettebank);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
func7(a1, palettebank);
return func6(a1, palettebank);
}

original_code:
void tagteam_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 drawchars(bitmap,palettebank);
 drawsprites(bitmap,palettebank);
}

canonical_original_code:
void tagteam_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 drawchars(bitmap,palettebank);
 drawsprites(bitmap,palettebank);
}


decompiled_code:
__int64 tagteam_interrupt()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_0 = 0;
return ignore_interrupt();
}
if ( coin_0 )
return ignore_interrupt();
coin_0 = 1;
return nmi_interrupt();
}

canonical_decompiled_code:
__int64 func9()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_0 = 0;
return ignore_interrupt();
}
if ( coin_0 )
return ignore_interrupt();
coin_0 = 1;
return nmi_interrupt();
}

original_code:
static int tagteam_interrupt(void)
{
 static int coin;
 int port;
 port = readinputport(0) & 0xc0;
 if (port != 0xc0)
 {
  if (coin == 0)
  {
   coin = 1;
   return nmi_interrupt();
  }
 }
 else coin = 0;
        return ignore_interrupt();
}

canonical_original_code:
static int tagteam_interrupt()
{
 static int coin;
 int port;
 port = readinputport(0) & 0xc0;
 if (port != 0xc0)
 {
  if (coin == 0)
  {
   coin = 1;
   return nmi_interrupt();
  }
 }
 else coin = 0;
        return ignore_interrupt();
}

variable_types: coin int

variable_types: port int


drawsprites

decompiled_code:
__int64 __fastcall drawsprites(__int64 a1, unsigned int a2)
{
__int64 result; // rax
__int64 i; // rbp
int v4; // ebx
int v5; // ebx

result = 2 * a2 + 1;
for ( i = 0LL; i != 32; i += 4LL )
{
v4 = *(unsigned __int8 *)(videoram + i);
if ( (v4 & 1) != 0 )
{
v5 = (v4 << 12) & 0x30000;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v5 + (unsigned int)*(unsigned __int8 *)(videoram + i + 1), 2 * a2 + 1);
result = drawgfx(a1, *(_QWORD *)(Machine + 520LL), v5 + (unsigned int)*(unsigned __int8 *)(videoram + i + 32), a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 result; // rax
__int64 i; // rbp
int v4; // ebx
int v5; // ebx

result = 2 * a2 + 1;
for ( i = 0LL; i != 32; i += 4LL )
{
v4 = *(unsigned __int8 *)(videoram + i);
if ( (v4 & 1) != 0 )
{
v5 = (v4 << 12) & 0x30000;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v5 + (unsigned int)*(unsigned __int8 *)(videoram + i + 1), 2 * a2 + 1);
result = drawgfx(a1, *(_QWORD *)(Machine + 520LL), v5 + (unsigned int)*(unsigned __int8 *)(videoram + i + 32), a2);
}
}
return result;
}

original_code:
static void drawsprites(struct osd_bitmap *bitmap,int color)
{
 int offs;
 for (offs = 0;offs < 0x20;offs += 4)
 {
  int sx,sy,flipx,flipy;
  int spritebank;
  if (!(videoram[offs + 0] & 0x01)) continue;
  sx = 240 - videoram[offs + 3];
  sy = 240 - videoram[offs + 2];
  flipx = videoram[offs + 0] & 0x04;
  flipy = videoram[offs + 0] & 0x02;
  spritebank = (videoram[offs] & 0x30) << 4;
  if (flipscreen)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 1] + 256 * spritebank,
    1+2*color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  sy += (flipscreen ? -256 : 256);
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 0x20] + 256 * spritebank,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void drawsprites(struct osd_bitmap *bitmap, int color)
{
 int offs;
 for (offs = 0;offs < 0x20;offs += 4)
 {
  int sx; int sy; int flipx; int flipy;
  int spritebank;
  if (!(videoram[offs + 0] & 0x01)) continue;
  sx = 240 - videoram[offs + 3];
  sy = 240 - videoram[offs + 2];
  flipx = videoram[offs + 0] & 0x04;
  flipy = videoram[offs + 0] & 0x02;
  spritebank = (videoram[offs] & 0x30) << 4;
  if (flipscreen)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 1] + 256 * spritebank,
    1+2*color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  sy += (flipscreen ? -256 : 256);
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 0x20] + 256 * spritebank,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: color int

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: spritebank int


drawchars

decompiled_code:
__int64 __fastcall drawchars(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // r15

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
*(_BYTE *)(v3 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + (*(unsigned __int8 *)(colorram + v3) << 8),
(unsigned int)(2 * a2));
}
--v2;
--v3;
}
while ( v2 != -1 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // r15

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
*(_BYTE *)(v3 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + (*(unsigned __int8 *)(colorram + v3) << 8),
(unsigned int)(2 * a2));
}
--v2;
--v3;
}
while ( v2 != -1 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
static void drawchars(struct osd_bitmap *bitmap,int color)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = 31 - offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * colorram[offs],
     2*color,
     flipscreen,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
static void drawchars(struct osd_bitmap *bitmap, int color)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = 31 - offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * colorram[offs],
     2*color,
     flipscreen,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

if ( a1 == 23 )
{
GRMidByte = a2;
v2 = a2;
result = (unsigned int)GRLowByte;
a2 = GRHighByte;
}
else if ( a1 == 24 )
{
GRLowByte = a2;
result = a2;
v2 = GRMidByte;
a2 = GRHighByte;
}
else
{
if ( a1 == 8 )
GRHighByte = a2;
else
a2 = GRHighByte;
v2 = GRMidByte;
result = (unsigned int)GRLowByte;
}
currentaddress = result | (v2 << 8) | (a2 << 16);
return result;
}

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

if ( a1 == 23 )
{
GRMidByte = a2;
v2 = a2;
result = (unsigned int)GRLowByte;
a2 = GRHighByte;
}
else if ( a1 == 24 )
{
GRLowByte = a2;
result = a2;
v2 = GRMidByte;
a2 = GRHighByte;
}
else
{
if ( a1 == 8 )
GRHighByte = a2;
else
a2 = GRHighByte;
v2 = GRMidByte;
result = (unsigned int)GRLowByte;
}
currentaddress = result | (v2 << 8) | (a2 << 16);
return result;
}

original_code:
void bowlrama_turbo_w(offs_t offset,data_t data)
{
 switch( offset )
 {
  case 0x08:
   GRHighByte = data;
   break;
  case 0x17:
   GRMidByte = data;
   break;
  case 0x18:
   GRLowByte = data;
   break;
  default:
   break;
 }
 currentaddress = ((GRHighByte << 16) | (GRMidByte << 8) | GRLowByte);
}

canonical_original_code:
void bowlrama_turbo_w(unsigned int offset, unsigned int data)
{
 switch( offset )
 {
  case 0x08:
   GRHighByte = data;
   break;
  case 0x17:
   GRMidByte = data;
   break;
  case 0x18:
   GRLowByte = data;
   break;
  default:
   break;
 }
 currentaddress = ((GRHighByte << 16) | (GRMidByte << 8) | GRLowByte);
}


decompiled_code:
__int64 capbowl_vertical_interrupt()
{
return 2LL;
}

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

original_code:
static int capbowl_vertical_interrupt(void)
{
 return 2;
}

canonical_original_code:
static int capbowl_vertical_interrupt()
{
 return 2;
}


decompiled_code:
__int64 __fastcall capbowl_tms34061_getfunction(int a1)
{
return (a1 >> 8) & 3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (a1 >> 8) & 3;
}

original_code:
static int capbowl_tms34061_getfunction(int offset)
{
 return (offset >> 8) & 0x03;
}

variable_types: offset int


decompiled_code:
__int64 capbowl_tms34061_getrowaddress()
{
return (unsigned __int8)*capbowl_rowaddress;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)*capbowl_rowaddress;
}

original_code:
static int capbowl_tms34061_getrowaddress(int offset)
{
 return *capbowl_rowaddress;
}


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

result = (unsigned __int8)a1;
if ( (a1 & 0x300) == 0 )
result = (unsigned __int8)a1 ^ 2u;
return result;
}

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

result = (unsigned __int8)a1;
if ( (a1 & 0x300) == 0 )
result = (unsigned __int8)a1 ^ 2u;
return result;
}

original_code:
static int capbowl_tms34061_getcoladdress(int offset)
{
 int col = (offset & 0xff);
 if (!(offset & 0x300))
 {
  col ^= 0x02;
 }
 return col;
}

variable_types: col int


decompiled_code:
__int64 __fastcall capbowl_tms34061_getpixel(int a1, int a2)
{
return *((unsigned __int8 *)raw_video_ram + (a1 | (a2 << 8)));
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
return *((unsigned __int8 *)raw_video_ram + (a1 | (a2 << 8)));
}

original_code:
static int capbowl_tms34061_getpixel(int col, int row)
{
 return raw_video_ram[row << 8 | col];
}

variable_types: row int