decompiled_code:
__int64 __fastcall champbas_dac_w(__int64 a1, int a2)
{
return DAC_signed_data_w(0LL, (unsigned int)(4 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return DAC_signed_data_w(0LL, (unsigned int)(4 * a2));
}

original_code:
void champbas_dac_w(offs_t offset,data_t data)
{
 DAC_signed_data_w(0,data<<2);
}

canonical_original_code:
void champbas_dac_w(unsigned int offset, unsigned int data)
{
 DAC_signed_data_w(0,data<<2);
}


original_code:
void qwakprot_paletteram_w(offs_t offset,data_t data)
{
 int bit0,bit1,bit2;
 int r,g,b;
 paletteram[offset] = data;
 bit0 = (~data >> 2) & 0x01;
 bit1 = (~data >> 3) & 0x01;
 bit2 = (~data >> 4) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (~data >> 5) & 0x01;
 bit1 = (~data >> 6) & 0x01;
 bit2 = (~data >> 7) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (~data >> 0) & 0x01;
 bit2 = (~data >> 1) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset,r,g,b);
}

canonical_original_code:
void qwakprot_paletteram_w(unsigned int offset, unsigned int data)
{
 int bit0; int bit1; int bit2;
 int r; int g; int b;
 paletteram[offset] = data;
 bit0 = (~data >> 2) & 0x01;
 bit1 = (~data >> 3) & 0x01;
 bit2 = (~data >> 4) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (~data >> 5) & 0x01;
 bit1 = (~data >> 6) & 0x01;
 bit2 = (~data >> 7) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (~data >> 0) & 0x01;
 bit2 = (~data >> 1) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset,r,g,b);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int

return_type: void


decompiled_code:
__int64 __fastcall qwakprot_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v3; // rax
int v4; // ebx
__int64 v5; // r12
__int64 i; // rbx
__int64 result; // rax
unsigned int v8; // edi
unsigned __int8 v9; // r14
int v10; // er13
int v11; // er9
int v12; // er10
int v13; // ecx

v3 = palette_recalc();
if ( a2 || v3 )
memset(dirtybuffer, 1, videoram_size);
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (*(_BYTE *)(videoram + v5) >> 7) + 512),
*(_BYTE *)(videoram + v5) & 0x7F,
0LL,
0LL,
0LL,
(unsigned int)(8 * (v4 % 32)),
(unsigned int)(8 * (v4 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
for ( i = 0LL; i != 16; ++i )
{
v9 = *(_BYTE *)(spriteram + i + 32);
v10 = 240 - *(unsigned __int8 *)(spriteram + i + 16);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(_BYTE *)(spriteram + i) & 0x7F,
0LL,
0LL,
*(_BYTE *)(spriteram + i) & 0x80,
v9,
(unsigned int)v10,
&spritevisiblearea,
2LL,
0LL);
v11 = (int)v9 >> 3;
v8 = v10 >> 3;
v12 = (v10 >> 3) - (((v10 & 0xF) == 0) - 3);
v13 = v11 + ((v9 & 7) != 0) + 1;
if ( v10 >> 3 < v12 )
{
do
{
result = (int)v9 >> 3;
if ( v11 < v13 )
{
do
{
if ( (unsigned int)result <= 0x1F && v8 <= 0x1D )
*((_BYTE *)dirtybuffer + (int)(32 * v8 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v13 );
}
++v8;
}
while ( v8 != v12 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 v3; // rax
int v4; // ebx
__int64 v5; // r12
__int64 i; // rbx
__int64 result; // rax
unsigned int v8; // edi
unsigned __int8 v9; // r14
int v10; // er13
int v11; // er9
int v12; // er10
int v13; // ecx

v3 = palette_recalc();
if ( a2 || v3 )
memset(dirtybuffer, 1, videoram_size);
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (*(_BYTE *)(videoram + v5) >> 7) + 512),
*(_BYTE *)(videoram + v5) & 0x7F,
0LL,
0LL,
0LL,
(unsigned int)(8 * (v4 % 32)),
(unsigned int)(8 * (v4 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
for ( i = 0LL; i != 16; ++i )
{
v9 = *(_BYTE *)(spriteram + i + 32);
v10 = 240 - *(unsigned __int8 *)(spriteram + i + 16);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(_BYTE *)(spriteram + i) & 0x7F,
0LL,
0LL,
*(_BYTE *)(spriteram + i) & 0x80,
v9,
(unsigned int)v10,
&spritevisiblearea,
2LL,
0LL);
v11 = (int)v9 >> 3;
v8 = v10 >> 3;
v12 = (v10 >> 3) - (((v10 & 0xF) == 0) - 3);
v13 = v11 + ((v9 & 7) != 0) + 1;
if ( v10 >> 3 < v12 )
{
do
{
result = (int)v9 >> 3;
if ( v11 < v13 )
{
do
{
if ( (unsigned int)result <= 0x1F && v8 <= 0x1D )
*((_BYTE *)dirtybuffer + (int)(32 * v8 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v13 );
}
++v8;
}
while ( v8 != v12 );
}
}
return result;
}

original_code:
void qwakprot_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   int gfxset;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   gfxset = ((videoram[offs] & 0x80) >> 7);
   drawgfx(bitmap,Machine->gfx[gfxset],
     videoram[offs] & 0x7f,
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum;
  int flip;
  int x, y;
  int sx, sy;
  spritenum = spriteram[offs] & 0x7f;
  flip = (spriteram[offs] & 0x80);
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  drawgfx(bitmap,Machine->gfx[2],
    spritenum,0,
    0,flip,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2, y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

canonical_original_code:
void qwakprot_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   int gfxset;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   gfxset = ((videoram[offs] & 0x80) >> 7);
   drawgfx(bitmap,Machine->gfx[gfxset],
     videoram[offs] & 0x7f,
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum;
  int flip;
  int x; int y;
  int sx; int sy;
  spritenum = spriteram[offs] & 0x7f;
  flip = (spriteram[offs] & 0x80);
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  drawgfx(bitmap,Machine->gfx[2],
    spritenum,0,
    0,flip,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2; int y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: gfxset int

variable_types: spritenum int

variable_types: flip int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall qwakprot_led_w(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

original_code:
static void qwakprot_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset,~data >> 7);
}

canonical_original_code:
static void qwakprot_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,~data >> 7);
}


original_code:
void megazone_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 megazone_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 megazone_dip3_r()
{
return 255LL;
}

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

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

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

variable_types:
offset
unsigned int

return_type: unsigned int


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

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

original_code:
data_t megazone_sharedram_r(offs_t offset)
{
 return(megazone_sharedram[offset]);
}

canonical_original_code:
unsigned int megazone_sharedram_r(unsigned int offset)
{
 return(megazone_sharedram[offset]);
}


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

tmpbitmap = 0LL;
v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
tmpbitmap = bitmap_alloc(256LL, 256LL);
v2 = 0;
if ( !tmpbitmap )
{
free(dirtybuffer);
v2 = 1;
}
return v2;
}

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

tmpbitmap = 0LL;
v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
tmpbitmap = bitmap_alloc(256LL, 256LL);
v2 = 0;
if ( !tmpbitmap )
{
free(dirtybuffer);
v2 = 1;
}
return v2;
}

original_code:
int megazone_vh_start(void)
{
 dirtybuffer = 0;
 tmpbitmap = 0;
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc(256,256)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

canonical_original_code:
int megazone_vh_start()
{
 dirtybuffer = 0;
 tmpbitmap = 0;
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc(256,256)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

return_type: int


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall megazone_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // ebp
__int64 v4; // rbx
__int64 i; // r15
__int64 v6; // rbp
__int64 v7; // rbx
__int64 result; // rax
int v9; // [rsp+8h] [rbp-40h] BYREF
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + (*(char *)(colorram + v2) & 0x100u),
(*(_BYTE *)(colorram + v2) & 0xFu) + 16,
*(_BYTE *)(colorram + v2) & 0x40,
*(_BYTE *)(colorram + v2) & 0x20,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v9 = 32 - (unsigned __int8)*megazone_scrolly;
v10[0] = -(unsigned __int8)*megazone_scrollx;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v9, 1LL, v10, Machine + 776LL, 0LL, 0LL);
v3 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v3 + 3LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v4 - 1),
*(_BYTE *)(spriteram + v4 - 3) & 0xF,
~*(_BYTE *)(spriteram + v4 - 3) & 0x40,
*(_BYTE *)(spriteram + v4 - 3) & 0x80,
(unsigned int)*(unsigned __int8 *)(spriteram + v4) + 32,
(unsigned __int8)~(*(_BYTE *)(spriteram + v4 - 2) + 16),
Machine + 776LL,
6LL,
0LL);
v4 -= 4LL;
v3 -= 4;
}
while ( v3 >= 0 );
}
for ( i = 0LL; i != 32; ++i )
{
v6 = 32 * i;
v7 = 0LL;
do
{
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(megazone_videoram2 + v6) + (*(char *)(megazone_colorram2 + v6) & 0x100u),
(*(_BYTE *)(megazone_colorram2 + v6) & 0xFu) + 16,
*(_BYTE *)(megazone_colorram2 + v6) & 0x40,
*(_BYTE *)(megazone_colorram2 + v6) & 0x20,
v7,
(unsigned int)(8 * i),
0LL,
0LL,
0LL);
++v6;
v7 = (unsigned int)(v7 + 8);
}
while ( (_DWORD)v7 != 48 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // ebp
__int64 v4; // rbx
__int64 i; // r15
__int64 v6; // rbp
__int64 v7; // rbx
__int64 result; // rax
int v9; // [rsp+8h] [rbp-40h] BYREF
int v10[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + (*(char *)(colorram + v2) & 0x100u),
(*(_BYTE *)(colorram + v2) & 0xFu) + 16,
*(_BYTE *)(colorram + v2) & 0x40,
*(_BYTE *)(colorram + v2) & 0x20,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v9 = 32 - (unsigned __int8)*megazone_scrolly;
v10[0] = -(unsigned __int8)*megazone_scrollx;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v9, 1LL, v10, Machine + 776LL, 0LL, 0LL);
v3 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v3 + 3LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v4 - 1),
*(_BYTE *)(spriteram + v4 - 3) & 0xF,
~*(_BYTE *)(spriteram + v4 - 3) & 0x40,
*(_BYTE *)(spriteram + v4 - 3) & 0x80,
(unsigned int)*(unsigned __int8 *)(spriteram + v4) + 32,
(unsigned __int8)~(*(_BYTE *)(spriteram + v4 - 2) + 16),
Machine + 776LL,
6LL,
0LL);
v4 -= 4LL;
v3 -= 4;
}
while ( v3 >= 0 );
}
for ( i = 0LL; i != 32; ++i )
{
v6 = 32 * i;
v7 = 0LL;
do
{
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(megazone_videoram2 + v6) + (*(char *)(megazone_colorram2 + v6) & 0x100u),
(*(_BYTE *)(megazone_colorram2 + v6) & 0xFu) + 16,
*(_BYTE *)(megazone_colorram2 + v6) & 0x40,
*(_BYTE *)(megazone_colorram2 + v6) & 0x20,
v7,
(unsigned int)(8 * i),
0LL,
0LL,
0LL);
++v6;
v7 = (unsigned int)(v7 + 8);
}
while ( (_DWORD)v7 != 48 );
}
return result;
}

original_code:
void megazone_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int x,y;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipx,flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & (1<<6);
   flipy = colorram[offs] & (1<<5);
   drawgfx(tmpbitmap,Machine->gfx[0],
     ((int)videoram[offs]) + ((colorram[offs] & (1<<7) ? 256 : 0) ),
     (colorram[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx = -*megazone_scrolly + 4*8;
  int scrolly = -*megazone_scrollx;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  for (offs = spriteram_size-4; offs >= 0;offs -= 4)
  {
   int sx,sy,flipx,flipy;
   sx = spriteram[offs + 3] + 4*8;
   sy = 255-((spriteram[offs + 1]+16)&0xff);
   flipx = ~spriteram[offs+0] & 0x40;
   flipy = spriteram[offs+0] & 0x80;
   drawgfx(bitmap,Machine->gfx[1],
     spriteram[offs + 2],
     spriteram[offs + 0] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
 for (y = 0; y < 32;y++)
 {
  offs = y*32;
  for (x = 0; x < 6; x++)
  {
   int sx,sy,flipx,flipy;
   sx = x;
   sy = y;
   flipx = megazone_colorram2[offs] & (1<<6);
   flipy = megazone_colorram2[offs] & (1<<5);
   drawgfx(bitmap,Machine->gfx[0],
     ((int)megazone_videoram2[offs]) + ((megazone_colorram2[offs] & (1<<7) ? 256 : 0) ),
     (megazone_colorram2[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   offs++;
  }
 }
}

canonical_original_code:
void megazone_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int x; int y;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & (1<<6);
   flipy = colorram[offs] & (1<<5);
   drawgfx(tmpbitmap,Machine->gfx[0],
     ((int)videoram[offs]) + ((colorram[offs] & (1<<7) ? 256 : 0) ),
     (colorram[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx = -*megazone_scrolly + 4*8;
  int scrolly = -*megazone_scrollx;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  for (offs = spriteram_size-4; offs >= 0;offs -= 4)
  {
   int sx; int sy; int flipx; int flipy;
   sx = spriteram[offs + 3] + 4*8;
   sy = 255-((spriteram[offs + 1]+16)&0xff);
   flipx = ~spriteram[offs+0] & 0x40;
   flipy = spriteram[offs+0] & 0x80;
   drawgfx(bitmap,Machine->gfx[1],
     spriteram[offs + 2],
     spriteram[offs + 0] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
 for (y = 0; y < 32;y++)
 {
  offs = y*32;
  for (x = 0; x < 6; x++)
  {
   int sx; int sy; int flipx; int flipy;
   sx = x;
   sy = y;
   flipx = megazone_colorram2[offs] & (1<<6);
   flipy = megazone_colorram2[offs] & (1<<5);
   drawgfx(bitmap,Machine->gfx[0],
     ((int)megazone_videoram2[offs]) + ((megazone_colorram2[offs] & (1<<7) ? 256 : 0) ),
     (megazone_colorram2[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   offs++;
  }
 }
}

variable_types: flipx int

variable_types: flipy int

variable_types: scrollx int

variable_types: scrolly int

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


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

v0 = cpu_gettotalcycles();
return i8039_status | (unsigned int)(unsigned __int8)(16 * (((5124611814397LL * v0) >> 52) - ((7159 * v0) >> 31)));
}

original_code:
data_t megazone_portA_r(offs_t offset)
{
 int clock,timer;
 clock = cpu_gettotalcycles() * 7159/12288;
 timer = (clock / (1024/2)) & 0x0f;
 return (timer << 4) | i8039_status;
}

canonical_original_code:
unsigned int megazone_portA_r(unsigned int offset)
{
 int clock; int timer;
 clock = cpu_gettotalcycles() * 7159/12288;
 timer = (clock / (1024/2)) & 0x0f;
 return (timer << 4) | i8039_status;
}

variable_types: clock int

variable_types: timer int


decompiled_code:
__int64 init_megazone()
{
return konami1_decode();
}

canonical_decompiled_code:
__int64 func11()
{
return konami1_decode();
}

original_code:
static void init_megazone(void)
{
 konami1_decode();
}

canonical_original_code:
static void init_megazone()
{
 konami1_decode();
}


decompiled_code:
__int64 __fastcall megazone_portB_w(__int64 a1, unsigned int a2)
{
unsigned int i; // ebp
__int64 v4; // r8
__int64 result; // rax

for ( i = 0; i != 3; ++i )
{
v4 = -(a2 & 1) & 0x2710;
if ( (a2 & 2) != 0 )
v4 = (unsigned int)(v4 + 220000);
a2 >>= 2;
result = set_RC_filter(i, 1000LL, 2200LL, 200LL, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
unsigned int i; // ebp
__int64 v4; // r8
__int64 result; // rax

for ( i = 0; i != 3; ++i )
{
v4 = -(a2 & 1) & 0x2710;
if ( (a2 & 2) != 0 )
v4 = (unsigned int)(v4 + 220000);
a2 >>= 2;
result = set_RC_filter(i, 1000LL, 2200LL, 200LL, v4);
}
return result;
}

original_code:
static void megazone_portB_w(offs_t offset,data_t data)
{
 int i;
 for (i = 0;i < 3;i++)
 {
  int C;
  C = 0;
  if (data & 1) C += 10000;
  if (data & 2) C += 220000;
  data >>= 2;
  set_RC_filter(i,1000,2200,200,C);
 }
}

canonical_original_code:
static void megazone_portB_w(unsigned int offset, unsigned int data)
{
 int i;
 for (i = 0;i < 3;i++)
 {
  int C;
  C = 0;
  if (data & 1) C += 10000;
  if (data & 2) C += 220000;
  data >>= 2;
  set_RC_filter(i,1000,2200,200,C);
 }
}

variable_types:
data
unsigned int

variable_types: C int


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

if ( i8039_irqenable )
result = cpu_cause_interrupt(2LL, 1LL);
return result;
}

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

if ( i8039_irqenable )
result = cpu_cause_interrupt(2LL, 1LL);
return result;
}

original_code:
static void megazone_i8039_irq_w(offs_t offset,data_t data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(2,1);
}

canonical_original_code:
static void megazone_i8039_irq_w(unsigned int offset, unsigned int data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(2,1);
}


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

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

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

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

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

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


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

result = (unsigned __int8)a2 & 0x80;
i8039_irqenable = a2 & 0x80;
i8039_status = (a2 >> 4) & 7;
return result;
}

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

result = (unsigned __int8)a2 & 0x80;
i8039_irqenable = a2 & 0x80;
i8039_status = (a2 >> 4) & 7;
return result;
}

original_code:
void i8039_irqen_and_status_w(offs_t offset,data_t data)
{
 i8039_irqenable = data & 0x80;
 i8039_status = (data & 0x70) >> 4;
}

canonical_original_code:
void i8039_irqen_and_status_w(unsigned int offset, unsigned int data)
{
 i8039_irqenable = data & 0x80;
 i8039_status = (data & 0x70) >> 4;
}


decompiled_code:
__int64 __fastcall ohmygod_videoram_r(unsigned int a1)
{
return *(unsigned __int16 *)(ohmygod_videoram + a1);
}

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

original_code:
data_t ohmygod_videoram_r(offs_t offset)
{
   return (*(UINT16 *)(&ohmygod_videoram[offset]));
}

canonical_original_code:
unsigned int ohmygod_videoram_r(unsigned int offset)
{
   return (*(unsigned short *)(&ohmygod_videoram[offset]));
}


decompiled_code:
void __fastcall ohmygod_spritebank_w(__int64 a1, __int16 a2)
{
spritebank = a2 & 0x8000;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int16 a2)
{
spritebank = a2 & 0x8000;
}

original_code:
void ohmygod_spritebank_w(offs_t offset,data_t data)
{
 spritebank = data & 0x8000;
}

canonical_original_code:
void ohmygod_spritebank_w(unsigned int offset, unsigned int data)
{
 spritebank = data & 0x8000;
}


decompiled_code:
_BOOL8 ohmygod_vh_start()
{
bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 64LL);
return bg_tilemap == 0;
}

canonical_decompiled_code:
_BOOL8 func3()
{
bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 64LL);
return bg_tilemap == 0;
}

original_code:
int ohmygod_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,64,64);
 if (!bg_tilemap)
  return 1;
 return 0;
}

canonical_original_code:
int ohmygod_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,64,64);
 if (!bg_tilemap)
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall ohmygod_videoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ohmygod_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ohmygod_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 2);
}
return result;
}

original_code:
void ohmygod_videoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&ohmygod_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(UINT16 *)(&ohmygod_videoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,offset/4);
 }
}

canonical_original_code:
void ohmygod_videoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&ohmygod_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(unsigned short *)(&ohmygod_videoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,offset/4);
 }
}

variable_types: oldword int

variable_types: newword int


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

if ( a1 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)(a2 - 33263));
else
result = tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned int)(a2 - 33260));
return result;
}

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

if ( a1 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)(a2 - 33263));
else
result = tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned int)(a2 - 33260));
return result;
}

original_code:
void ohmygod_scroll_w(offs_t offset,data_t data)
{
 if (offset == 0) tilemap_set_scrollx(bg_tilemap,0,data - 0x81ec);
 else tilemap_set_scrolly(bg_tilemap,0,data - 0x81ef);
}

canonical_original_code:
void ohmygod_scroll_w(unsigned int offset, unsigned int data)
{
 if (offset == 0) tilemap_set_scrollx(bg_tilemap,0,data - 0x81ec);
 else tilemap_set_scrolly(bg_tilemap,0,data - 0x81ef);
}


decompiled_code:
void *ohmygod_init_machine()
{
__int64 v0; // rbx

v0 = memory_region(146LL);
watchdog_reset_r(0LL);
sndbank[0] = 0;
return memcpy((void *)(v0 + 0x20000), (const void *)(v0 + 0x40000), 0x20000uLL);
}

canonical_decompiled_code:
void *func6()
{
__int64 v0; // rbx

v0 = memory_region(146LL);
watchdog_reset_r(0LL);
sndbank[0] = 0;
return memcpy((void *)(v0 + 0x20000), (const void *)(v0 + 0x40000), 0x20000uLL);
}

original_code:
static void ohmygod_init_machine(void)
{
 unsigned char *rom = memory_region(REGION_SOUND1);
 watchdog_reset_r(0);
 sndbank = 0;
 memcpy(rom + 0x20000,rom + 0x40000 + 0x20000 * sndbank,0x20000);
}

canonical_original_code:
static void ohmygod_init_machine()
{
 unsigned char *rom = memory_region(REGION_SOUND1);
 watchdog_reset_r(0);
 sndbank = 0;
 memcpy(rom + 0x20000,rom + 0x40000 + 0x20000 * sndbank,0x20000);
}

variable_types:
rom
unsigned char *


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

v1 = 4 * a1;
v2 = *(_WORD *)(ohmygod_videoram + v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (unsigned int)*(unsigned __int16 *)(ohmygod_videoram + v1 + 2) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (HIBYTE(v2) & 0xF);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

v1 = 4 * a1;
v2 = *(_WORD *)(ohmygod_videoram + v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (unsigned int)*(unsigned __int16 *)(ohmygod_videoram + v1 + 2) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (HIBYTE(v2) & 0xF);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 UINT16 code = (*(UINT16 *)(&ohmygod_videoram[4*tile_index+2]));
 UINT16 attr = (*(UINT16 *)(&ohmygod_videoram[4*tile_index]));
 { 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 & 0x0f00) >> 8)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned short code = (*(UINT16 *)(&ohmygod_videoram[4*tile_index+2]));
 unsigned short attr = (*(UINT16 *)(&ohmygod_videoram[4*tile_index]));
 { 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 & 0x0f00) >> 8)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types:
code
unsigned short

variable_types:
attr
unsigned short

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


decompiled_code:
void __fastcall battlnts_spritebank_w(__int64 a1, char a2)
{
spritebank = (a2 & 1) << 10;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
spritebank = (a2 & 1) << 10;
}

original_code:
void battlnts_spritebank_w(offs_t offset,data_t data)
{
 spritebank = 1024 * (data & 1);
}

canonical_original_code:
void battlnts_spritebank_w(unsigned int offset, unsigned int data)
{
 spritebank = 1024 * (data & 1);
}


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

layer_colorbase[0] = 0;
dword_714 = 0;
if ( (unsigned int)K007342_vh_start(0LL, tile_callback) )
{
K007342_tilemap_set_enable(1LL, 0LL);
result = 1LL;
}
else
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

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

layer_colorbase[0] = 0;
dword_714 = 0;
if ( (unsigned int)K007342_vh_start(0LL, tile_callback) )
{
K007342_tilemap_set_enable(1LL, 0LL);
result = 1LL;
}
else
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

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

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


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

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

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


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

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

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

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

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


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

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

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

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


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

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

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

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

original_code:
static int battlnts_interrupt( void )
{
 if (K007342_is_INT_enabled())
        return 1;
    else
        return ignore_interrupt();
}

canonical_original_code:
static int battlnts_interrupt()
{
 if (K007342_is_INT_enabled())
        return 1;
    else
        return ignore_interrupt();
}


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 >> 6) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 >> 6) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

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

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

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


decompiled_code:
void init_rackemup()
{
int v0; // ebx
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx

v0 = memory_region_length(137LL);
v1 = memory_region(137LL);
shuffle(v1, v0, v2, v3);
}

canonical_decompiled_code:
void func10()
{
int v0; // ebx
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx

v0 = memory_region_length(137LL);
v1 = memory_region(137LL);
func9(v1, v0, v2, v3);
}

original_code:
static void init_rackemup(void)
{
 shuffle(memory_region(REGION_GFX1),memory_region_length(REGION_GFX1));
}

canonical_original_code:
static void init_rackemup()
{
 shuffle(memory_region(REGION_GFX1),memory_region_length(REGION_GFX1));
}


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

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

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

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

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

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

variable_types:
code
int *

variable_types:
color
int *


shuffle

original_code:
static void shuffle(UINT8 *buf,int len)
{
 int i;
 UINT8 t;
 if (len == 2) return;
 if (len % 4) exit(1);
 len /= 2;
 for (i = 0;i < len/2;i++)
 {
  t = buf[len/2 + i];
  buf[len/2 + i] = buf[len + i];
  buf[len + i] = t;
 }
 shuffle(buf,len);
 shuffle(buf + len,len);
}

canonical_original_code:
static void shuffle(unsigned char *buf, int len)
{
 int i;
 unsigned char t;
 if (len == 2) return;
 if (len % 4) exit(1);
 len /= 2;
 for (i = 0;i < len/2;i++)
 {
  t = buf[len/2 + i];
  buf[len/2 + i] = buf[len + i];
  buf[len + i] = t;
 }
 shuffle(buf,len);
 shuffle(buf + len,len);
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: i int

variable_types:
t
unsigned char


canonical_decompiled_code:
void func0()
{
serial_count = 0;
sending = 0;
}

original_code:
static void EEPROM_reset(void)
{
 serial_count = 0;
 sending = 0;
}

canonical_original_code:
static void EEPROM_reset()
{
 serial_count = 0;
 sending = 0;
}


decompiled_code:
int __fastcall EEPROM_write(int a1)
{
size_t v1; // rax
int v2; // ebp
int *v3; // rbx
const char *v4; // r14
size_t v5; // r12
int v6; // er13
const char *v7; // r14
size_t v8; // r12
int v9; // er13
const char *v10; // r12
size_t v11; // rsi
int v12; // er14
int v13; // er13
const char *v14; // r12
size_t v15; // rdx
const char *v16; // rbx
char *v17; // rdx
char *v18; // r12
int v19; // edx
char *v20; // rdx
char *v21; // r12
int v22; // eax
char *v23; // rcx
int v24; // edx
char *v25; // rcx
int v26; // edx

LODWORD(v1) = serial_count;
if ( serial_count <= 38 )
{
v2 = ++serial_count;
*(&serial_buffer + (int)v1) = 48 - ((a1 == 0) - 1);
LODWORD(v1) = v2;
*(&serial_buffer + v2) = 0;
v3 = (int *)intf;
v4 = *(const char **)(intf + 8);
if ( v4
&& (v5 = strlen(*(const char **)(intf + 8)), v6 = *v3, v1 = v5 + *v3, v2 == v1)
&& (LODWORD(v1) = strncmp(&serial_buffer, v4, v5), !(_DWORD)v1) )
{
if ( v6 > 0 )
{
v17 = &serial_buffer + v5;
v18 = (char *)&unk_701 + (unsigned int)(v6 - 1) + v5;
do
{
LODWORD(v1) = 2 * v1;
if ( *v17 == 49 )
LODWORD(v1) = v1 | 1;
++v17;
}
while ( v17 != v18 );
}
if ( v3[1] == 16 )
v19 = eeprom_data[2 * (int)v1 + 1] + (eeprom_data[2 * (int)v1] << 8);
else
v19 = eeprom_data[(int)v1];
eeprom_data_bits = v19;
eeprom_read_address = v1;
eeprom_clock_count = 0;
sending = 1;
serial_count = 0;
}
else
{
v7 = (const char *)*((_QWORD *)v3 + 3);
if ( v7
&& (v8 = strlen(*((const char **)v3 + 3)), v9 = *v3, v1 = v8 + *v3, v2 == v1)
&& (LODWORD(v1) = strncmp(&serial_buffer, v7, v8), !(_DWORD)v1) )
{
if ( v9 > 0 )
{
v20 = &serial_buffer + v8;
v21 = (char *)&unk_701 + (unsigned int)(v9 - 1) + v8;
do
{
LODWORD(v1) = 2 * v1;
if ( *v20 == 49 )
LODWORD(v1) = v1 | 1;
++v20;
}
while ( v20 != v21 );
}
if ( locked )
{
serial_count = 0;
}
else if ( v3[1] == 16 )
{
v22 = 2 * v1;
eeprom_data[v22] = 0;
v1 = v22 + 1;
eeprom_data[v1] = 0;
}
else
{
eeprom_data[(int)v1] = 0;
}
}
else
{
v10 = (const char *)*((_QWORD *)v3 + 2);
if ( v10
&& (v11 = strlen(*((const char **)v3 + 2)), v12 = *v3, v13 = v3[1], v1 = v11 + *v3 + (__int64)v13, v2 == v1)
&& (LODWORD(v1) = strncmp(&serial_buffer, v10, v11), !(_DWORD)v1) )
{
if ( v12 <= 0 )
{
v24 = 0;
}
else
{
v23 = &serial_buffer + v11;
v24 = 0;
do
{
v24 *= 2;
if ( *v23 == 49 )
v24 |= 1u;
++v23;
}
while ( v23 != (char *)&unk_701 + (unsigned int)(v12 - 1) + v11 );
}
if ( v13 > 0 )
{
v25 = &serial_buffer + v11 + v12;
do
{
LODWORD(v1) = 2 * v1;
if ( *v25 == 49 )
LODWORD(v1) = v1 | 1;
++v25;
}
while ( v25 != &serial_buffer + v12 + (unsigned int)(v13 - 1) + v11 + 1 );
}
if ( locked )
{
serial_count = 0;
}
else if ( v13 == 16 )
{
v26 = 2 * v24;
eeprom_data[v26] = BYTE1(v1);
eeprom_data[v26 + 1] = v1;
}
else
{
eeprom_data[v24] = v1;
}
}
else
{
v14 = (const char *)*((_QWORD *)v3 + 4);
if ( v14
&& (v15 = strlen(*((const char **)v3 + 4)), LODWORD(v1) = v2, v2 == v15)
&& (LODWORD(v1) = strncmp(&serial_buffer, v14, v15), !(_DWORD)v1) )
{
locked = 1;
serial_count = 0;
}
else
{
v16 = (const char *)*((_QWORD *)v3 + 5);
if ( v16 )
{
v1 = strlen(v16);
if ( v2 == v1 )
{
LODWORD(v1) = strncmp(&serial_buffer, v16, v1);
if ( !(_DWORD)v1 )
{
locked = 0;
serial_count = 0;
}
}
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
size_t v1; // rax
int v2; // ebp
int *v3; // rbx
const char *v4; // r14
size_t v5; // r12
int v6; // er13
const char *v7; // r14
size_t v8; // r12
int v9; // er13
const char *v10; // r12
size_t v11; // rsi
int v12; // er14
int v13; // er13
const char *v14; // r12
size_t v15; // rdx
const char *v16; // rbx
char *v17; // rdx
char *v18; // r12
int v19; // edx
char *v20; // rdx
char *v21; // r12
int v22; // eax
char *v23; // rcx
int v24; // edx
char *v25; // rcx
int v26; // edx

LODWORD(v1) = serial_count;
if ( serial_count <= 38 )
{
v2 = ++serial_count;
*(&serial_buffer + (int)v1) = 48 - ((a1 == 0) - 1);
LODWORD(v1) = v2;
*(&serial_buffer + v2) = 0;
v3 = (int *)intf;
v4 = *(const char **)(intf + 8);
if ( v4
&& (v5 = strlen(*(const char **)(intf + 8)), v6 = *v3, v1 = v5 + *v3, v2 == v1)
&& (LODWORD(v1) = strncmp(&serial_buffer, v4, v5), !(_DWORD)v1) )
{
if ( v6 > 0 )
{
v17 = &serial_buffer + v5;
v18 = (char *)&unk_701 + (unsigned int)(v6 - 1) + v5;
do
{
LODWORD(v1) = 2 * v1;
if ( *v17 == 49 )
LODWORD(v1) = v1 | 1;
++v17;
}
while ( v17 != v18 );
}
if ( v3[1] == 16 )
v19 = eeprom_data[2 * (int)v1 + 1] + (eeprom_data[2 * (int)v1] << 8);
else
v19 = eeprom_data[(int)v1];
eeprom_data_bits = v19;
eeprom_read_address = v1;
eeprom_clock_count = 0;
sending = 1;
serial_count = 0;
}
else
{
v7 = (const char *)*((_QWORD *)v3 + 3);
if ( v7
&& (v8 = strlen(*((const char **)v3 + 3)), v9 = *v3, v1 = v8 + *v3, v2 == v1)
&& (LODWORD(v1) = strncmp(&serial_buffer, v7, v8), !(_DWORD)v1) )
{
if ( v9 > 0 )
{
v20 = &serial_buffer + v8;
v21 = (char *)&unk_701 + (unsigned int)(v9 - 1) + v8;
do
{
LODWORD(v1) = 2 * v1;
if ( *v20 == 49 )
LODWORD(v1) = v1 | 1;
++v20;
}
while ( v20 != v21 );
}
if ( locked )
{
serial_count = 0;
}
else if ( v3[1] == 16 )
{
v22 = 2 * v1;
eeprom_data[v22] = 0;
v1 = v22 + 1;
eeprom_data[v1] = 0;
}
else
{
eeprom_data[(int)v1] = 0;
}
}
else
{
v10 = (const char *)*((_QWORD *)v3 + 2);
if ( v10
&& (v11 = strlen(*((const char **)v3 + 2)), v12 = *v3, v13 = v3[1], v1 = v11 + *v3 + (__int64)v13, v2 == v1)
&& (LODWORD(v1) = strncmp(&serial_buffer, v10, v11), !(_DWORD)v1) )
{
if ( v12 <= 0 )
{
v24 = 0;
}
else
{
v23 = &serial_buffer + v11;
v24 = 0;
do
{
v24 *= 2;
if ( *v23 == 49 )
v24 |= 1u;
++v23;
}
while ( v23 != (char *)&unk_701 + (unsigned int)(v12 - 1) + v11 );
}
if ( v13 > 0 )
{
v25 = &serial_buffer + v11 + v12;
do
{
LODWORD(v1) = 2 * v1;
if ( *v25 == 49 )
LODWORD(v1) = v1 | 1;
++v25;
}
while ( v25 != &serial_buffer + v12 + (unsigned int)(v13 - 1) + v11 + 1 );
}
if ( locked )
{
serial_count = 0;
}
else if ( v13 == 16 )
{
v26 = 2 * v24;
eeprom_data[v26] = BYTE1(v1);
eeprom_data[v26 + 1] = v1;
}
else
{
eeprom_data[v24] = v1;
}
}
else
{
v14 = (const char *)*((_QWORD *)v3 + 4);
if ( v14
&& (v15 = strlen(*((const char **)v3 + 4)), LODWORD(v1) = v2, v2 == v15)
&& (LODWORD(v1) = strncmp(&serial_buffer, v14, v15), !(_DWORD)v1) )
{
locked = 1;
serial_count = 0;
}
else
{
v16 = (const char *)*((_QWORD *)v3 + 5);
if ( v16 )
{
v1 = strlen(v16);
if ( v2 == v1 )
{
LODWORD(v1) = strncmp(&serial_buffer, v16, v1);
if ( !(_DWORD)v1 )
{
locked = 0;
serial_count = 0;
}
}
}
}
}
}
}
}
return v1;
}

original_code:
static void EEPROM_write(int bit)
{
 if (serial_count >= 40 -1)
 {
  return;
 }
 serial_buffer[serial_count++] = (bit ? '1' : '0');
 serial_buffer[serial_count] = 0;
 if (intf->cmd_read && serial_count == (strlen(intf->cmd_read) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_read,strlen(intf->cmd_read)))
 {
  int i,address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_read)] == '1') address |= 1;
  }
  if (intf->data_bits == 16)
   eeprom_data_bits = (eeprom_data[2*address+0] << 8) + eeprom_data[2*address+1];
  else
   eeprom_data_bits = eeprom_data[address];
  eeprom_read_address = address;
  eeprom_clock_count = 0;
  sending = 1;
  serial_count = 0;
 }
 else if (intf->cmd_erase && serial_count == (strlen(intf->cmd_erase) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_erase,strlen(intf->cmd_erase)))
 {
  int i,address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_erase)] == '1') address |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = 0x00;
    eeprom_data[2*address+1] = 0x00;
   }
   else
    eeprom_data[address] = 0x00;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_write && serial_count == (strlen(intf->cmd_write) + intf->address_bits + intf->data_bits) &&
   !strncmp(serial_buffer,intf->cmd_write,strlen(intf->cmd_write)))
 {
  int i,address,data;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write)] == '1') address |= 1;
  }
  data = 0;
  for (i = 0;i < intf->data_bits;i++)
  {
   data <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write) + intf->address_bits] == '1') data |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = data >> 8;
    eeprom_data[2*address+1] = data & 0xff;
   }
   else
    eeprom_data[address] = data;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_lock && serial_count == strlen(intf->cmd_lock) &&
   !strncmp(serial_buffer,intf->cmd_lock,strlen(intf->cmd_lock)))
 {
  locked = 1;
  serial_count = 0;
 }
 else if (intf->cmd_unlock && serial_count == strlen(intf->cmd_unlock) &&
   !strncmp(serial_buffer,intf->cmd_unlock,strlen(intf->cmd_unlock)))
 {
  locked = 0;
  serial_count = 0;
 }
}

canonical_original_code:
static void EEPROM_write(int bit)
{
 if (serial_count >= 40 -1)
 {
  return;
 }
 serial_buffer[serial_count++] = (bit ? '1' : '0');
 serial_buffer[serial_count] = 0;
 if (intf->cmd_read && serial_count == (strlen(intf->cmd_read) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_read,strlen(intf->cmd_read)))
 {
  int i; int address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_read)] == '1') address |= 1;
  }
  if (intf->data_bits == 16)
   eeprom_data_bits = (eeprom_data[2*address+0] << 8) + eeprom_data[2*address+1];
  else
   eeprom_data_bits = eeprom_data[address];
  eeprom_read_address = address;
  eeprom_clock_count = 0;
  sending = 1;
  serial_count = 0;
 }
 else if (intf->cmd_erase && serial_count == (strlen(intf->cmd_erase) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_erase,strlen(intf->cmd_erase)))
 {
  int i; int address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_erase)] == '1') address |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = 0x00;
    eeprom_data[2*address+1] = 0x00;
   }
   else
    eeprom_data[address] = 0x00;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_write && serial_count == (strlen(intf->cmd_write) + intf->address_bits + intf->data_bits) &&
   !strncmp(serial_buffer,intf->cmd_write,strlen(intf->cmd_write)))
 {
  int i; int address; int data;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write)] == '1') address |= 1;
  }
  data = 0;
  for (i = 0;i < intf->data_bits;i++)
  {
   data <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write) + intf->address_bits] == '1') data |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = data >> 8;
    eeprom_data[2*address+1] = data & 0xff;
   }
   else
    eeprom_data[address] = data;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_lock && serial_count == strlen(intf->cmd_lock) &&
   !strncmp(serial_buffer,intf->cmd_lock,strlen(intf->cmd_lock)))
 {
  locked = 1;
  serial_count = 0;
 }
 else if (intf->cmd_unlock && serial_count == strlen(intf->cmd_unlock) &&
   !strncmp(serial_buffer,intf->cmd_unlock,strlen(intf->cmd_unlock)))
 {
  locked = 0;
  serial_count = 0;
 }
}

variable_types: bit int

variable_types: address int

variable_types: data int


decompiled_code:
_BOOL8 __fastcall EEPROM_init(__int64 a1)
{
_BOOL8 result; // rax

intf = a1;
memset(eeprom_data, 255, (*(_DWORD *)(a1 + 4) << *(_DWORD *)a1) / 8);
serial_count = 0;
latch = 0;
reset_line = 1;
clock_line = 1;
sending = 0;
result = *(_QWORD *)(a1 + 40) != 0LL;
locked = *(_QWORD *)(a1 + 40) != 0LL;
return result;
}

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

intf = a1;
memset(eeprom_data, 255, (*(_DWORD *)(a1 + 4) << *(_DWORD *)a1) / 8);
serial_count = 0;
latch = 0;
reset_line = 1;
clock_line = 1;
sending = 0;
result = *(_QWORD *)(a1 + 40) != 0LL;
locked = *(_QWORD *)(a1 + 40) != 0LL;
return result;
}

original_code:
void EEPROM_init(struct EEPROM_interface *interface)
{
 intf = interface;
 memset(eeprom_data,0xff,(1 << intf->address_bits) * intf->data_bits / 8);
 serial_count = 0;
 latch = 0;
 reset_line = 1;
 clock_line = 1;
 sending = 0;
 if (intf->cmd_unlock) locked = 1;
 else locked = 0;
}

variable_types: struct EEPROM_interface { int address_bits; int data_bits; char *cmd_read; char *cmd_write; char *cmd_erase; char *cmd_lock; char *cmd_unlock; int enable_multi_read; } *


decompiled_code:
void __fastcall EEPROM_write_bit(int a1)
{
latch = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
latch = a1;
}

original_code:
void EEPROM_write_bit(int bit)
{
 latch = bit;
}


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

result = 1LL;
if ( sending )
result = (eeprom_data_bits >> *(_DWORD *)(intf + 4)) & 1;
return result;
}

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

result = 1LL;
if ( sending )
result = (eeprom_data_bits >> *(_DWORD *)(intf + 4)) & 1;
return result;
}

original_code:
int EEPROM_read_bit(void)
{
 int res;
 if (sending)
  res = (eeprom_data_bits >> intf->data_bits) & 1;
 else res = 1;
 return res;
}

canonical_original_code:
int EEPROM_read_bit()
{
 int res;
 if (sending)
  res = (eeprom_data_bits >> intf->data_bits) & 1;
 else res = 1;
 return res;
}

variable_types: res int


decompiled_code:
void __fastcall EEPROM_set_cs_line(int a1)
{
reset_line = a1;
if ( a1 )
EEPROM_reset();
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
reset_line = a1;
if ( a1 )
func0();
}

original_code:
void EEPROM_set_cs_line(int state)
{
 reset_line = state;
 if (reset_line != 0)
  EEPROM_reset();
}

variable_types: state int


decompiled_code:
void __fastcall EEPROM_set_clock_line(int a1)
{
int v1; // edx
int v2; // eax
int v3; // eax

if ( (a1 == 3 || !clock_line && a1) && !reset_line )
{
if ( sending )
{
v1 = *(_DWORD *)(intf + 4);
if ( v1 == eeprom_clock_count && *(_DWORD *)(intf + 48) )
{
v2 = (eeprom_read_address + 1) & ((1 << *(_DWORD *)intf) - 1);
eeprom_read_address = v2;
if ( v1 == 16 )
v3 = (eeprom_data[2 * v2] << 8) + eeprom_data[2 * v2 + 1];
else
v3 = eeprom_data[v2];
eeprom_data_bits = v3;
eeprom_clock_count = 0;
}
eeprom_data_bits = 2 * eeprom_data_bits + 1;
++eeprom_clock_count;
}
else
{
EEPROM_write(latch);
}
}
clock_line = a1;
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
int v1; // edx
int v2; // eax
int v3; // eax

if ( (a1 == 3 || !clock_line && a1) && !reset_line )
{
if ( sending )
{
v1 = *(_DWORD *)(intf + 4);
if ( v1 == eeprom_clock_count && *(_DWORD *)(intf + 48) )
{
v2 = (eeprom_read_address + 1) & ((1 << *(_DWORD *)intf) - 1);
eeprom_read_address = v2;
if ( v1 == 16 )
v3 = (eeprom_data[2 * v2] << 8) + eeprom_data[2 * v2 + 1];
else
v3 = eeprom_data[v2];
eeprom_data_bits = v3;
eeprom_clock_count = 0;
}
eeprom_data_bits = 2 * eeprom_data_bits + 1;
++eeprom_clock_count;
}
else
{
func1(latch);
}
}
clock_line = a1;
}

original_code:
void EEPROM_set_clock_line(int state)
{
 if (state == 3 || (clock_line == 0 && state != 0))
 {
  if (reset_line == 0)
  {
   if (sending)
   {
    if (eeprom_clock_count == intf->data_bits && intf->enable_multi_read)
    {
     eeprom_read_address = (eeprom_read_address + 1) & ((1 << intf->address_bits) - 1);
     if (intf->data_bits == 16)
      eeprom_data_bits = (eeprom_data[2*eeprom_read_address+0] << 8) + eeprom_data[2*eeprom_read_address+1];
     else
      eeprom_data_bits = eeprom_data[eeprom_read_address];
     eeprom_clock_count = 0;
    }
    eeprom_data_bits = (eeprom_data_bits << 1) | 1;
    eeprom_clock_count++;
   }
   else
    EEPROM_write(latch);
  }
 }
 clock_line = state;
}


decompiled_code:
__int64 __fastcall EEPROM_load(__int64 a1)
{
return osd_fread(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return osd_fread(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

original_code:
void EEPROM_load(void *f)
{
 osd_fread(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8);
}

variable_types:
f
void *


decompiled_code:
__int64 __fastcall EEPROM_save(__int64 a1)
{
return osd_fwrite(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return osd_fwrite(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

original_code:
void EEPROM_save(void *f)
{
 osd_fwrite(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8);
}


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

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

original_code:
void EEPROM_set_data(UINT8 *data, int length)
{
 memcpy(eeprom_data, data, length);
}

canonical_original_code:
void EEPROM_set_data(unsigned char *data, int length)
{
 memcpy(eeprom_data, data, length);
}

variable_types:
data
unsigned char *

variable_types: length int


original_code:
static void sega_decode(const unsigned char xortable[32][4])
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0x0000;A < 0x8000;A++)
 {
  int row,col;
  unsigned char src;
  src = rom[A];
  row = (A & 1) + (((A >> 4) & 1) << 1) + (((A >> 8) & 1) << 2) + (((A >> 12) & 1) << 3);
  col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
  if (src & 0x80) col = 3 - col;
  rom[A + diff] = src ^ xortable[2*row][col];
  rom[A] = src ^ xortable[2*row+1][col];
  if (xortable[2*row][col] == 0xff)
   rom[A + diff] = 0x00;
  if (xortable[2*row+1][col] == 0xff)
   rom[A] = 0xee;
 }
 for (A = 0x8000;A < diff;A++)
  rom[A + diff] = rom[A];
}

canonical_original_code:
static void sega_decode(unsigned char xortable[32][4])
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0x0000;A < 0x8000;A++)
 {
  int row; int col;
  unsigned char src;
  src = rom[A];
  row = (A & 1) + (((A >> 4) & 1) << 1) + (((A >> 8) & 1) << 2) + (((A >> 12) & 1) << 3);
  col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
  if (src & 0x80) col = 3 - col;
  rom[A + diff] = src ^ xortable[2*row][col];
  rom[A] = src ^ xortable[2*row+1][col];
  if (xortable[2*row][col] == 0xff)
   rom[A + diff] = 0x00;
  if (xortable[2*row+1][col] == 0xff)
   rom[A] = 0xee;
 }
 for (A = 0x8000;A < diff;A++)
  rom[A + diff] = rom[A];
}

variable_types:
xortable
unsigned char [32][4]

variable_types: A int

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: row int

variable_types: col int

variable_types:
src
unsigned char


decompiled_code:
__int64 pengo_decode()
{
return sega_decode((__int64)&xortable_20);
}

canonical_decompiled_code:
__int64 func1()
{
return func0((__int64)&xortable_20);
}


decompiled_code:
__int64 szaxxon_decode()
{
return sega_decode((__int64)&xortable_19);
}

canonical_decompiled_code:
__int64 func2()
{
return func0((__int64)&xortable_19);
}


decompiled_code:
__int64 suprloco_decode()
{
return sega_decode((__int64)&xortable_18);
}

canonical_decompiled_code:
__int64 func3()
{
return func0((__int64)&xortable_18);
}


decompiled_code:
__int64 yamato_decode()
{
return sega_decode((__int64)&xortable_17);
}

canonical_decompiled_code:
__int64 func4()
{
return func0((__int64)&xortable_17);
}


decompiled_code:
__int64 sindbadm_decode()
{
return sega_decode((__int64)&xortable_16);
}

canonical_decompiled_code:
__int64 func5()
{
return func0((__int64)&xortable_16);
}


decompiled_code:
__int64 regulus_decode()
{
return sega_decode((__int64)&xortable_15);
}

canonical_decompiled_code:
__int64 func6()
{
return func0((__int64)&xortable_15);
}


decompiled_code:
__int64 mrviking_decode()
{
return sega_decode((__int64)&xortable_14);
}

canonical_decompiled_code:
__int64 func7()
{
return func0((__int64)&xortable_14);
}


decompiled_code:
__int64 swat_decode()
{
return sega_decode((__int64)&xortable_13);
}

canonical_decompiled_code:
__int64 func8()
{
return func0((__int64)&xortable_13);
}


decompiled_code:
__int64 flicky_decode()
{
return sega_decode((__int64)&xortable_12);
}

canonical_decompiled_code:
__int64 func9()
{
return func0((__int64)&xortable_12);
}


decompiled_code:
__int64 futspy_decode()
{
return sega_decode((__int64)&xortable_11);
}

canonical_decompiled_code:
__int64 func10()
{
return func0((__int64)&xortable_11);
}


decompiled_code:
__int64 bullfgtj_decode()
{
return sega_decode((__int64)&xortable_10);
}

canonical_decompiled_code:
__int64 func11()
{
return func0((__int64)&xortable_10);
}


decompiled_code:
__int64 pitfall2_decode()
{
return sega_decode((__int64)&xortable_9);
}

canonical_decompiled_code:
__int64 func12()
{
return func0((__int64)&xortable_9);
}


decompiled_code:
__int64 nprinces_decode()
{
return sega_decode((__int64)&xortable_8);
}

canonical_decompiled_code:
__int64 func13()
{
return func0((__int64)&xortable_8);
}


decompiled_code:
__int64 seganinj_decode()
{
return sega_decode((__int64)&xortable_7);
}

canonical_decompiled_code:
__int64 func14()
{
return func0((__int64)&xortable_7);
}


decompiled_code:
__int64 imsorry_decode()
{
return sega_decode((__int64)&xortable_6);
}

canonical_decompiled_code:
__int64 func15()
{
return func0((__int64)&xortable_6);
}


decompiled_code:
__int64 teddybb_decode()
{
return sega_decode((__int64)&xortable_5);
}

canonical_decompiled_code:
__int64 func16()
{
return func0((__int64)&xortable_5);
}


decompiled_code:
__int64 hvymetal_decode()
{
return sega_decode((__int64)&xortable_4);
}

canonical_decompiled_code:
__int64 func17()
{
return func0((__int64)&xortable_4);
}


decompiled_code:
__int64 myheroj_decode()
{
return sega_decode((__int64)&xortable_3);
}

canonical_decompiled_code:
__int64 func18()
{
return func0((__int64)&xortable_3);
}


variable_types:
xortable
unsigned char [-1][8]


decompiled_code:
char *wboy4_decode()
{
__int64 v0; // rbx
int v1; // er13
__int64 v2; // rbp
__int64 i; // rsi
unsigned __int8 v4; // di
int v5; // edx
__int64 v6; // rax
char *result; // rax

v0 = memory_region(129LL);
v1 = memory_region_length(129LL);
v2 = v0 + v1 / 2;
memory_set_opcode_base(0LL, v2);
for ( i = 0LL; i != 0x8000; ++i )
{
v4 = *(_BYTE *)(v0 + i);
v5 = ((2 * (v4 >> 2)) & 2 | v4 & 1) + ((4 * (v4 >> 4)) & 4);
if ( (v4 & 0x40) != 0 )
v5 = 7 - v5;
v6 = 8LL
* (int)((((unsigned int)i >> 2) & 2 | i & 1)
+ (((unsigned int)i >> 4) & 4)
+ (((unsigned int)i >> 6) & 8)
+ (((unsigned int)i >> 8) & 0x10)
+ (((unsigned int)i >> 9) & 0x20));
*(_BYTE *)(v2 + i) = opcode_xortable_1[v6 + v5] ^ v4;
result = (char *)&data_xortable_0 + v6;
*(_BYTE *)(v0 + i) = result[v5] ^ v4;
}
if ( v1 > 65537 )
{
do
{
result = (char *)*(unsigned __int8 *)(v0 + i);
*(_BYTE *)(v2 + i++) = (_BYTE)result;
}
while ( v1 / 2 > (int)i );
}
return result;
}

canonical_decompiled_code:
char *func21()
{
__int64 v0; // rbx
int v1; // er13
__int64 v2; // rbp
__int64 i; // rsi
unsigned __int8 v4; // di
int v5; // edx
__int64 v6; // rax
char *result; // rax

v0 = memory_region(129LL);
v1 = memory_region_length(129LL);
v2 = v0 + v1 / 2;
memory_set_opcode_base(0LL, v2);
for ( i = 0LL; i != 0x8000; ++i )
{
v4 = *(_BYTE *)(v0 + i);
v5 = ((2 * (v4 >> 2)) & 2 | v4 & 1) + ((4 * (v4 >> 4)) & 4);
if ( (v4 & 0x40) != 0 )
v5 = 7 - v5;
v6 = 8LL
* (int)((((unsigned int)i >> 2) & 2 | i & 1)
+ (((unsigned int)i >> 4) & 4)
+ (((unsigned int)i >> 6) & 8)
+ (((unsigned int)i >> 8) & 0x10)
+ (((unsigned int)i >> 9) & 0x20));
*(_BYTE *)(v2 + i) = opcode_xortable_1[v6 + v5] ^ v4;
result = (char *)&data_xortable_0 + v6;
*(_BYTE *)(v0 + i) = result[v5] ^ v4;
}
if ( v1 > 65537 )
{
do
{
result = (char *)*(unsigned __int8 *)(v0 + i);
*(_BYTE *)(v2 + i++) = (_BYTE)result;
}
while ( v1 / 2 > (int)i );
}
return result;
}


decompiled_code:
void gardia_decode()
{
;
}

canonical_decompiled_code:
void func22()
{
;
}

original_code:
void gardia_decode(void)
{
}

canonical_original_code:
void gardia_decode()
{
}


decompiled_code:
__int64 meteor_interrupt()
{
return 8LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 8LL;
}

original_code:
static int meteor_interrupt(void)
{
 return 0x08;
}

canonical_original_code:
static int meteor_interrupt()
{
 return 0x08;
}


decompiled_code:
void __fastcall meteor_SN76496_latch_w(__int64 a1, int a2)
{
meteor_SN76496_latch = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
meteor_SN76496_latch = a2;
}

original_code:
static void meteor_SN76496_latch_w(offs_t offset,data_t data)
{
 meteor_SN76496_latch = data;
}

canonical_original_code:
static void meteor_SN76496_latch_w(unsigned int offset, unsigned int data)
{
 meteor_SN76496_latch = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 meteor_SN76496_select_r()
{
return (unsigned int)meteor_SN76496_select;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)meteor_SN76496_select;
}

original_code:
static data_t meteor_SN76496_select_r(offs_t offset)
{
 return meteor_SN76496_select;
}

canonical_original_code:
static unsigned int meteor_SN76496_select_r(unsigned int offset)
{
 return meteor_SN76496_select;
}


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

meteor_SN76496_select = a2;
if ( (a2 & 0x40) == 0 )
result = SN76496_0_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x20) == 0 )
result = SN76496_1_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x10) == 0 )
result = SN76496_2_w(0LL, (unsigned int)meteor_SN76496_latch);
return result;
}

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

meteor_SN76496_select = a2;
if ( (a2 & 0x40) == 0 )
result = SN76496_0_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x20) == 0 )
result = SN76496_1_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x10) == 0 )
result = SN76496_2_w(0LL, (unsigned int)meteor_SN76496_latch);
return result;
}

original_code:
static void meteor_SN76496_select_w(offs_t offset,data_t data)
{
    meteor_SN76496_select = data;
 if (~data & 0x40) SN76496_0_w(0, meteor_SN76496_latch);
 if (~data & 0x20) SN76496_1_w(0, meteor_SN76496_latch);
 if (~data & 0x10) SN76496_2_w(0, meteor_SN76496_latch);
}

canonical_original_code:
static void meteor_SN76496_select_w(unsigned int offset, unsigned int data)
{
    meteor_SN76496_select = data;
 if (~data & 0x40) SN76496_0_w(0, meteor_SN76496_latch);
 if (~data & 0x20) SN76496_1_w(0, meteor_SN76496_latch);
 if (~data & 0x10) SN76496_2_w(0, meteor_SN76496_latch);
}


decompiled_code:
__int64 meteor_t0_r()
{
return rand() & 1;
}

canonical_decompiled_code:
__int64 func5()
{
return rand() & 1;
}

original_code:
static data_t meteor_t0_r(offs_t offset)
{
 return rand() & 1;
}

canonical_original_code:
static unsigned int meteor_t0_r(unsigned int offset)
{
 return rand() & 1;
}


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

if ( (meteor_soundtrigger & 8) != 0 && (a2 & 8) == 0 )
result = cpu_cause_interrupt(1LL, 1LL);
meteor_soundtrigger = a2;
return result;
}

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

if ( (meteor_soundtrigger & 8) != 0 && (a2 & 8) == 0 )
result = cpu_cause_interrupt(1LL, 1LL);
meteor_soundtrigger = a2;
return result;
}

original_code:
static void meteor_soundtrigger_w(offs_t offset,data_t data)
{
 if ((meteor_soundtrigger & 0x08) && (~data & 0x08))
 {
  cpu_cause_interrupt(1, 1);
 }
 meteor_soundtrigger = data;
}

canonical_original_code:
static void meteor_soundtrigger_w(unsigned int offset, unsigned int data)
{
 if ((meteor_soundtrigger & 0x08) && (~data & 0x08))
 {
  cpu_cause_interrupt(1, 1);
 }
 meteor_soundtrigger = data;
}


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

result = 0xFF000000FF000000LL;
*a1 = 0xFF000000FF000000LL;
a1[1] = 0xFFFF000000FFFF00LL;
a1[2] = -16711936LL;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_290);
a2[2] = _mm_load_si128((const __m128i *)&xmmword_2A0);
a2[3] = _mm_load_si128((const __m128i *)&xmmword_2B0);
a2[4] = _mm_load_si128((const __m128i *)&xmmword_2C0);
a2[5] = _mm_load_si128((const __m128i *)&xmmword_2D0);
a2[6] = _mm_load_si128((const __m128i *)&xmmword_2E0);
a2[7] = _mm_load_si128((const __m128i *)&xmmword_2F0);
return result;
}

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

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


original_code:
void pinbo_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void pinbo_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((32 * *(unsigned __int8 *)(colorram + v2)) & 0xE00) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
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 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(8 * *(unsigned __int8 *)(spriteram + v5 - 1)) & 0x180 | *(_BYTE *)(spriteram + v5 - 2) & 0x3F | 0x40u,
*(_BYTE *)(spriteram + v5 - 1) & 0xF);
v5 -= 4LL;
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

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

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((32 * *(unsigned __int8 *)(colorram + v2)) & 0xE00) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
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 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(8 * *(unsigned __int8 *)(spriteram + v5 - 1)) & 0x180 | *(_BYTE *)(spriteram + v5 - 2) & 0x3F | 0x40u,
*(_BYTE *)(spriteram + v5 - 1) & 0xF);
v5 -= 4LL;
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void pinbo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x70) << 5),
     colorram[offs] & 0x0f,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  int code,color;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen[0])
  {
   sx = 240 - sx;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  code = (spriteram[offs+1] & 0x3f) | 0x40 | ((spriteram[offs+2] & 0x30) << 3);
  color = (spriteram[offs+2] & 0x0f);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void pinbo_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x70) << 5),
     colorram[offs] & 0x0f,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  int code; int color;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen[0])
  {
   sx = 240 - sx;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  code = (spriteram[offs+1] & 0x3f) | 0x40 | ((spriteram[offs+2] & 0x30) << 3);
  color = (spriteram[offs+2] & 0x0f);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    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: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: code int

variable_types: color int


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

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

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

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


decompiled_code:
__int64 pinbo_interrupt()
{
if ( !(unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(3LL) & 0x30) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func3()
{
if ( !(unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(3LL) & 0x30) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
static int pinbo_interrupt(void)
{
 if (cpu_getiloops() != 0)
 {
  if (readinputport(3) & 0x30)
   return nmi_interrupt();
  else return ignore_interrupt();
 }
 else return interrupt();
}

canonical_original_code:
static int pinbo_interrupt()
{
 if (cpu_getiloops() != 0)
 {
  if (readinputport(3) & 0x30)
   return nmi_interrupt();
  else return ignore_interrupt();
 }
 else return interrupt();
}


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

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

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

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

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

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


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

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


decompiled_code:
__int64 travrusa_vh_start()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 64LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
*(_DWORD *)(v0 + 136) = 255;
*(_DWORD *)(v0 + 140) = 63;
tilemap_set_scroll_rows(v0, 32LL);
result = 0LL;
}
return result;
}

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

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 64LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
*(_DWORD *)(v0 + 136) = 255;
*(_DWORD *)(v0 + 140) = 63;
tilemap_set_scroll_rows(v0, 32LL);
result = 0LL;
}
return result;
}

original_code:
int travrusa_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x02,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x3f;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}

canonical_original_code:
int travrusa_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x02,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x3f;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}


decompiled_code:
__int64 set_scroll()
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 24; ++i )
tilemap_set_scrollx(bg_tilemap, i, (unsigned int)(scrollx + (dword_B7C << 8)));
do
result = tilemap_set_scrollx(bg_tilemap, i++, 0LL);
while ( i != 32 );
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 24; ++i )
tilemap_set_scrollx(bg_tilemap, i, (unsigned int)(scrollx + (dword_B7C << 8)));
do
result = tilemap_set_scrollx(bg_tilemap, i++, 0LL);
while ( i != 32 );
return result;
}

original_code:
static void set_scroll(void)
{
 int i;
 for (i = 0;i < 24;i++)
  tilemap_set_scrollx(bg_tilemap,i,scrollx[0] + 256 * scrollx[1]);
 for (i = 24;i < 32;i++)
  tilemap_set_scrollx(bg_tilemap,i,0);
}

canonical_original_code:
static void set_scroll()
{
 int i;
 for (i = 0;i < 24;i++)
  tilemap_set_scrollx(bg_tilemap,i,scrollx[0] + 256 * scrollx[1]);
 for (i = 24;i < 32;i++)
  tilemap_set_scrollx(bg_tilemap,i,0);
}


decompiled_code:
__int64 __fastcall travrusa_scroll_x_low_w(__int64 a1, int a2)
{
scrollx = a2;
return set_scroll();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
scrollx = a2;
return func3();
}

original_code:
void travrusa_scroll_x_low_w(offs_t offset,data_t data)
{
 scrollx[0] = data;
 set_scroll();
}

canonical_original_code:
void travrusa_scroll_x_low_w(unsigned int offset, unsigned int data)
{
 scrollx[0] = data;
 set_scroll();
}


decompiled_code:
__int64 __fastcall travrusa_scroll_x_high_w(__int64 a1, int a2)
{
dword_B7C = a2;
return set_scroll();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
dword_B7C = a2;
return func3();
}

original_code:
void travrusa_scroll_x_high_w(offs_t offset,data_t data)
{
 scrollx[1] = data;
 set_scroll();
}

canonical_original_code:
void travrusa_scroll_x_high_w(unsigned int offset, unsigned int data)
{
 scrollx[1] = data;
 set_scroll();
}


decompiled_code:
__int64 __fastcall travrusa_flipscreen_w(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
flip_screen_w(0LL, v2 & 1);
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

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

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
flip_screen_w(0LL, v2 & 1);
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

original_code:
void travrusa_flipscreen_w(offs_t offset,data_t data)
{
 data ^= ~readinputport(4) & 1;
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void travrusa_flipscreen_w(unsigned int offset, unsigned int data)
{
 data ^= ~readinputport(4) & 1;
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 __fastcall travrusa_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 64LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
func7(a1);
return tilemap_draw(a1, bg_tilemap, 64LL);
}

original_code:
void travrusa_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
}

canonical_original_code:
void travrusa_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
}


variable_types: A int

variable_types: j int

variable_types:
RAM
unsigned char *

variable_types:
bit
int [13]


decompiled_code:
void *__fastcall get_tile_info(int a1)
{
__int64 v1; // rdi
__int16 v2; // si
__int64 v3; // rcx
signed int v4; // edx
__int64 v5; // rcx
void *result; // rax

v1 = 2 * a1;
v2 = *(unsigned __int8 *)(travrusa_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(travrusa_videoram + v1) + ((4 * v2) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = (void *)*(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = (_DWORD)result;
if ( (v2 & 0x20) != 0 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) = 1;
}
else
{
*((_DWORD *)&tile_info + 5) = 0;
}
if ( (v2 & 0x10) != 0 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) |= 2u;
}
if ( (v2 & 0xF) == 15 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) |= 4u;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__int64 v1; // rdi
__int16 v2; // si
__int64 v3; // rcx
signed int v4; // edx
__int64 v5; // rcx
void *result; // rax

v1 = 2 * a1;
v2 = *(unsigned __int8 *)(travrusa_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(travrusa_videoram + v1) + ((4 * v2) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = (void *)*(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = (_DWORD)result;
if ( (v2 & 0x20) != 0 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) = 1;
}
else
{
*((_DWORD *)&tile_info + 5) = 0;
}
if ( (v2 & 0x10) != 0 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) |= 2u;
}
if ( (v2 & 0xF) == 15 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) |= 4u;
}
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = travrusa_videoram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (travrusa_videoram[2*tile_index] + ((attr & 0xc0) << 2)) % 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 = 0;
 if (attr & 0x20) tile_info.flags |= 0x01;
 if (attr & 0x10) tile_info.flags |= 0x02;
 if ((attr & 0x0f) == 0x0f) tile_info.flags |= ((1)<<2);
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = travrusa_videoram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (travrusa_videoram[2*tile_index] + ((attr & 0xc0) << 2)) % 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 = 0;
 if (attr & 0x20) tile_info.flags |= 0x01;
 if (attr & 0x10) tile_info.flags |= 0x02;
 if ((attr & 0x0f) == 0x0f) tile_info.flags |= ((1)<<2);
}

variable_types:
attr
unsigned char

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


decompiled_code:
void *__fastcall draw_sprites(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // r8
__int64 v7; // r9
void *v8; // r10
__int64 v9; // rdi

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v2 + 3LL;
do
{
v5 = (unsigned int)(unsigned __int8)(*(_BYTE *)(spriteram + v4) + 8) - 8;
v9 = *(unsigned __int8 *)(spriteram + v4 - 3);
v6 = *(_BYTE *)(spriteram + v4 - 2) & 0x40;
v7 = *(_BYTE *)(spriteram + v4 - 2) & 0x80;
if ( flip_screen_x )
{
v5 = (unsigned int)(240 - v5);
v6 = (_DWORD)v6 == 0;
v7 = (_DWORD)v7 == 0;
v8 = &spritevisibleareaflip_1;
}
else
{
v9 = (unsigned int)(240 - v9);
v8 = &spritevisiblearea_0;
}
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v4 - 1),
*(_BYTE *)(spriteram + v4 - 2) & 0xF,
v6,
v7,
v5,
v9,
v8,
2LL,
0LL);
v4 -= 4LL;
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v4; // rbx
__int64 v5; // rax
__int64 v6; // r8
__int64 v7; // r9
void *v8; // r10
__int64 v9; // rdi

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v2 + 3LL;
do
{
v5 = (unsigned int)(unsigned __int8)(*(_BYTE *)(spriteram + v4) + 8) - 8;
v9 = *(unsigned __int8 *)(spriteram + v4 - 3);
v6 = *(_BYTE *)(spriteram + v4 - 2) & 0x40;
v7 = *(_BYTE *)(spriteram + v4 - 2) & 0x80;
if ( flip_screen_x )
{
v5 = (unsigned int)(240 - v5);
v6 = (_DWORD)v6 == 0;
v7 = (_DWORD)v7 == 0;
v8 = &spritevisibleareaflip_1;
}
else
{
v9 = (unsigned int)(240 - v9);
v8 = &spritevisiblearea_0;
}
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v4 - 1),
*(_BYTE *)(spriteram + v4 - 2) & 0xF,
v6,
v7,
v5,
v9,
v8,
2LL,
0LL);
v4 -= 4LL;
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 static struct rectangle spritevisiblearea =
 {
  1*8, 31*8-1,
  0*8, 24*8-1
 };
 static struct rectangle spritevisibleareaflip =
 {
  1*8, 31*8-1,
  8*8, 32*8-1
 };
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = ((spriteram[offs + 3] + 8) & 0xff) - 8;
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flip_screen_x)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2],
    spriteram[offs + 1] & 0x0f,
    flipx,flipy,
    sx,sy,
    flip_screen_x ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 static struct rectangle spritevisiblearea = {
  1*8, 31*8-1,
  0*8, 24*8-1
 };
 static struct rectangle spritevisibleareaflip = {
  1*8, 31*8-1,
  8*8, 32*8-1
 };
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = ((spriteram[offs + 3] + 8) & 0xff) - 8;
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flip_screen_x)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2],
    spriteram[offs + 1] & 0x0f,
    flipx,flipy,
    sx,sy,
    flip_screen_x ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,0);
 }
}

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


decompiled_code:
__int64 __fastcall timer_callback_2612(int a1)
{
__int64 v1; // rbp

v1 = (a1 >> 7) + 2LL * (a1 & 0x7F);
Timer[v1] = 0LL;
lastfired[v1] = timer_get_time();
return YM2612TimerOver(a1 & 0x7F, (unsigned int)(a1 >> 7));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rbp

v1 = (a1 >> 7) + 2LL * (a1 & 0x7F);
Timer[v1] = 0LL;
lastfired[v1] = timer_get_time();
return YM2612TimerOver(a1 & 0x7F, (unsigned int)(a1 >> 7));
}

original_code:
static void timer_callback_2612(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 lastfired[n][c] = timer_get_time();
 YM2612TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2612(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 lastfired[n][c] = timer_get_time();
 YM2612TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2612UpdateRequest(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

original_code:
void YM2612UpdateRequest(int chip)
{
 stream_update(stream[chip],100);
}

variable_types: chip int