decompiled_code:
__int64 __fastcall pulsar_sh_port2_w(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
char v4; // bl
char v5; // bp

v2 = port2State_0;
port2State_0 = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( (v4 & 1) != 0 )
{
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v5 & 2) == 0 )
goto LABEL_4;
goto LABEL_12;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(0LL, 8LL, 0LL);
if ( (v5 & 2) == 0 )
{
LABEL_4:
if ( (v4 & 4) == 0 )
goto LABEL_5;
goto LABEL_13;
}
LABEL_12:
result = sample_stop(0LL);
if ( (v4 & 4) == 0 )
{
LABEL_5:
if ( (v4 & 8) == 0 )
goto LABEL_6;
goto LABEL_14;
}
LABEL_13:
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 8) == 0 )
{
LABEL_6:
if ( (v5 & 8) == 0 )
goto LABEL_7;
goto LABEL_15;
}
LABEL_14:
result = sample_start(10LL, 10LL, 1LL);
if ( (v5 & 8) == 0 )
{
LABEL_7:
if ( (v4 & 0x10) == 0 )
goto LABEL_8;
goto LABEL_16;
}
LABEL_15:
result = sample_stop(10LL);
if ( (v4 & 0x10) == 0 )
{
LABEL_8:
if ( (v5 & 0x10) == 0 )
return result;
return sample_stop(11LL);
}
LABEL_16:
result = sample_start(11LL, 11LL, 1LL);
if ( (v5 & 0x10) != 0 )
return sample_stop(11LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
char v4; // bl
char v5; // bp

v2 = port2State_0;
port2State_0 = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( (v4 & 1) != 0 )
{
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v5 & 2) == 0 )
goto LABEL_4;
goto LABEL_12;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(0LL, 8LL, 0LL);
if ( (v5 & 2) == 0 )
{
LABEL_4:
if ( (v4 & 4) == 0 )
goto LABEL_5;
goto LABEL_13;
}
LABEL_12:
result = sample_stop(0LL);
if ( (v4 & 4) == 0 )
{
LABEL_5:
if ( (v4 & 8) == 0 )
goto LABEL_6;
goto LABEL_14;
}
LABEL_13:
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 8) == 0 )
{
LABEL_6:
if ( (v5 & 8) == 0 )
goto LABEL_7;
goto LABEL_15;
}
LABEL_14:
result = sample_start(10LL, 10LL, 1LL);
if ( (v5 & 8) == 0 )
{
LABEL_7:
if ( (v4 & 0x10) == 0 )
goto LABEL_8;
goto LABEL_16;
}
LABEL_15:
result = sample_stop(10LL);
if ( (v4 & 0x10) == 0 )
{
LABEL_8:
if ( (v5 & 0x10) == 0 )
return result;
return sample_stop(11LL);
}
LABEL_16:
result = sample_start(11LL, 11LL, 1LL);
if ( (v5 & 0x10) != 0 )
return sample_stop(11LL);
return result;
}

original_code:
void pulsar_sh_port2_w(offs_t offset,data_t data)
{
 static int port2State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_SIZZLE, SND_SIZZLE, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_GATE, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BIRTH, SND_BIRTH, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_HBEAT, SND_HBEAT, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_HBEAT );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_MOVMAZE, SND_MOVMAZE, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_MOVMAZE );
 }
}

canonical_original_code:
void pulsar_sh_port2_w(unsigned int offset, unsigned int data)
{
 static int port2State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_SIZZLE, SND_SIZZLE, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_GATE, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BIRTH, SND_BIRTH, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_HBEAT, SND_HBEAT, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_HBEAT );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_MOVMAZE, SND_MOVMAZE, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_MOVMAZE );
 }
}


original_code:
void pingpong_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++)
 {
  int code;
  int bit0,bit1,bit2,bit3;
  code = *(color_prom++) & 0x0f;
  bit0 = (code >> 0) & 1;
  bit1 = (code >> 1) & 1;
  bit2 = (code >> 2) & 1;
  bit3 = (code >> 3) & 1;
  code = (bit0 << 3) | (bit1 << 2) | (bit2 << 1) | (bit3 << 0);
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = code;
 }
 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 pingpong_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++)
 {
  int code;
  int bit0; int bit1; int bit2; int bit3;
  code = *(color_prom++) & 0x0f;
  bit0 = (code >> 0) & 1;
  bit1 = (code >> 1) & 1;
  bit2 = (code >> 2) & 1;
  bit3 = (code >> 3) & 1;
  code = (bit0 << 3) | (bit1 << 2) | (bit2 << 1) | (bit3 << 0);
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = code;
 }
 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

variable_types: code int

return_type: void


decompiled_code:
void *__fastcall pingpong_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
__int16 v3; // r8
int v4; // esi
char v5; // al
void *result; // rax
int v7; // ebx
__int64 v8; // r15
unsigned int v9; // er10
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdx
__int64 v13; // r9
__int64 v14; // [rsp-28h] [rbp-60h]
__int64 v15; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(colorram + v2);
v4 = *(unsigned __int8 *)(videoram + v2--);
v14 = (unsigned int)(8 * (v1 >> 5));
v5 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
v4 + ((8 * v3) & 0x100u),
v3 & 0x1F,
v3 & 0x40,
v3 & 0x80,
8 * (v5 & 0x1Fu),
v14,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v7 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v8 = v7 + 3LL;
do
{
v9 = *(_BYTE *)(spriteram + v8 - 1) & 0x7F;
v10 = *(_BYTE *)(spriteram + v8 - 3) & 0x1F;
v11 = *(_BYTE *)(spriteram + v8 - 3) & 0x40;
v15 = 241 - (unsigned int)*(unsigned __int8 *)(spriteram + v8 - 2);
v12 = *(unsigned __int8 *)(spriteram + v8);
v13 = *(_BYTE *)(spriteram + v8 - 3) & 0x80;
v8 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9,
v10,
v11,
v13,
v12,
v15,
&spritevisiblearea,
6LL,
0LL);
v7 -= 4;
}
while ( v7 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
__int16 v3; // r8
int v4; // esi
char v5; // al
void *result; // rax
int v7; // ebx
__int64 v8; // r15
unsigned int v9; // er10
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // rdx
__int64 v13; // r9
__int64 v14; // [rsp-28h] [rbp-60h]
__int64 v15; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(colorram + v2);
v4 = *(unsigned __int8 *)(videoram + v2--);
v14 = (unsigned int)(8 * (v1 >> 5));
v5 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
v4 + ((8 * v3) & 0x100u),
v3 & 0x1F,
v3 & 0x40,
v3 & 0x80,
8 * (v5 & 0x1Fu),
v14,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v7 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v8 = v7 + 3LL;
do
{
v9 = *(_BYTE *)(spriteram + v8 - 1) & 0x7F;
v10 = *(_BYTE *)(spriteram + v8 - 3) & 0x1F;
v11 = *(_BYTE *)(spriteram + v8 - 3) & 0x40;
v15 = 241 - (unsigned int)*(unsigned __int8 *)(spriteram + v8 - 2);
v12 = *(unsigned __int8 *)(spriteram + v8);
v13 = *(_BYTE *)(spriteram + v8 - 3) & 0x80;
v8 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9,
v10,
v11,
v13,
v12,
v15,
&spritevisiblearea,
6LL,
0LL);
v7 -= 4;
}
while ( v7 >= 0 );
}
return result;
}

original_code:
void pingpong_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,flipx,flipy,tchar,color;
   sx = offs % 32;
   sy = offs / 32;
   dirtybuffer[offs] = 0;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x80;
   color = colorram[offs] & 0x1F;
   tchar = (videoram[offs] + ((colorram[offs] & 0x20)<<3));
   drawgfx(tmpbitmap,Machine->gfx[0],
     tchar,
     color,
     flipx,flipy,
     8 * sx,8 * sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy,color,schar;
  sx = spriteram[offs + 3];
  sy = 241 - spriteram[offs + 1];
  flipx = spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  color = spriteram[offs] & 0x1F;
  schar = spriteram[offs + 2] & 0x7F;
  drawgfx(bitmap,Machine->gfx[1],
    schar,
    color,
    flipx,flipy,
    sx,sy,
    &spritevisiblearea,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
void pingpong_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; int flipx; int flipy; int tchar; int color;
   sx = offs % 32;
   sy = offs / 32;
   dirtybuffer[offs] = 0;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x80;
   color = colorram[offs] & 0x1F;
   tchar = (videoram[offs] + ((colorram[offs] & 0x20)<<3));
   drawgfx(tmpbitmap,Machine->gfx[0],
     tchar,
     color,
     flipx,flipy,
     8 * sx,8 * sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy; int color; int schar;
  sx = spriteram[offs + 3];
  sy = 241 - spriteram[offs + 1];
  flipx = spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  color = spriteram[offs] & 0x1F;
  schar = spriteram[offs + 2] & 0x7F;
  drawgfx(bitmap,Machine->gfx[1],
    schar,
    color,
    flipx,flipy,
    sx,sy,
    &spritevisiblearea,TRANSPARENCY_COLOR,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: tchar int

variable_types: color int

variable_types: schar int


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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (*(_BYTE *)intenable & 8) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (*(_BYTE *)intenable & 4) == 0 )
return ignore_interrupt();
result = interrupt();
}
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (*(_BYTE *)intenable & 8) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (*(_BYTE *)intenable & 4) == 0 )
return ignore_interrupt();
result = interrupt();
}
return result;
}

original_code:
static int pingpong_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (*intenable & 0x04) return interrupt();
 }
 else if (cpu_getiloops() % 2)
 {
  if (*intenable & 0x08) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int pingpong_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (*intenable & 0x04) return interrupt();
 }
 else if (cpu_getiloops() % 2)
 {
  if (*intenable & 0x08) return nmi_interrupt();
 }
 return ignore_interrupt();
}

return_type: int


original_code:
void bankp_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[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = *(color_prom++) & 0x0f;
 color_prom += 128;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
}

canonical_original_code:
void bankp_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[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = *(color_prom++) & 0x0f;
 color_prom += 128;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
}


decompiled_code:
void __fastcall bankp_scroll_w(__int64 a1, int a2)
{
scroll_x = a2;
}

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

original_code:
void bankp_scroll_w(offs_t offset,data_t data)
{
 scroll_x = data;
}

canonical_original_code:
void bankp_scroll_w(unsigned int offset, unsigned int data)
{
 scroll_x = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

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

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

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

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


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

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

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

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

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

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


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

priority = a2 & 3;
if ( (a2 & 0x10) != 0 )
{
v2 = a2 & 0x20;
result = (void *)interrupt_enable_w(0LL, 1LL);
if ( v2 == flipscreen )
return result;
LABEL_5:
flipscreen = v2;
memset(dirtybuffer, 1, videoram_size);
return memset(dirtybuffer2, 1, videoram_size);
}
v2 = a2 & 0x20;
result = (void *)interrupt_enable_w(0LL, 0LL);
if ( v2 != flipscreen )
goto LABEL_5;
return result;
}

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

priority = a2 & 3;
if ( (a2 & 0x10) != 0 )
{
v2 = a2 & 0x20;
result = (void *)interrupt_enable_w(0LL, 1LL);
if ( v2 == flipscreen )
return result;
LABEL_5:
flipscreen = v2;
memset(dirtybuffer, 1, videoram_size);
return memset(dirtybuffer2, 1, videoram_size);
}
v2 = a2 & 0x20;
result = (void *)interrupt_enable_w(0LL, 0LL);
if ( v2 != flipscreen )
goto LABEL_5;
return result;
}

original_code:
void bankp_out_w(offs_t offset,data_t data)
{
 priority = data & 0x03;
 if (data & 0x10) interrupt_enable_w(0,1);
 else interrupt_enable_w(0,0);
 if ((data & 0x20) != flipscreen)
 {
  flipscreen = data & 0x20;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
}

canonical_original_code:
void bankp_out_w(unsigned int offset, unsigned int data)
{
 priority = data & 0x03;
 if (data & 0x10) interrupt_enable_w(0,1);
 else interrupt_enable_w(0,0);
 if ((data & 0x20) != flipscreen)
 {
  flipscreen = data & 0x20;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
}


decompiled_code:
__int64 __fastcall bankp_vh_screenrefresh(__int64 a1)
{
int v1; // er15
__int64 v2; // rbx
__int64 v3; // r8
__int64 v4; // r8
__int64 result; // rax
int v6[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(_BYTE *)(colorram + v2) & 4;
if ( flipscreen )
v3 = (_DWORD)v3 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
*(_BYTE *)(colorram + v2) >> 3,
v3);
}
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
*((_BYTE *)dirtybuffer2 + v2) = 0;
v4 = *(_BYTE *)(bankp_colorram2 + v2) & 8;
if ( flipscreen )
v4 = (_DWORD)v4 == 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
((*(_BYTE *)(bankp_colorram2 + v2) & 7) << 8) + (unsigned int)*(unsigned __int8 *)(bankp_videoram2 + v2),
*(_BYTE *)(bankp_colorram2 + v2) >> 4,
v4);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
v6[0] = -scroll_x;
if ( priority == 2 )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
else
{
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // er15
__int64 v2; // rbx
__int64 v3; // r8
__int64 v4; // r8
__int64 result; // rax
int v6[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(_BYTE *)(colorram + v2) & 4;
if ( flipscreen )
v3 = (_DWORD)v3 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
*(_BYTE *)(colorram + v2) >> 3,
v3);
}
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
*((_BYTE *)dirtybuffer2 + v2) = 0;
v4 = *(_BYTE *)(bankp_colorram2 + v2) & 8;
if ( flipscreen )
v4 = (_DWORD)v4 == 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
((*(_BYTE *)(bankp_colorram2 + v2) & 7) << 8) + (unsigned int)*(unsigned __int8 *)(bankp_videoram2 + v2),
*(_BYTE *)(bankp_colorram2 + v2) >> 4,
v4);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
v6[0] = -scroll_x;
if ( priority == 2 )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
else
{
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
return result;
}

original_code:
void bankp_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,flipx;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x04;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * ((colorram[offs] & 3) >> 0),
     colorram[offs] >> 3,
     flipx,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx,sy,flipx;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = bankp_colorram2[offs] & 0x08;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     bankp_videoram2[offs] + 256 * (bankp_colorram2[offs] & 0x07),
     bankp_colorram2[offs] >> 4,
     flipx,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll;
  scroll = -scroll_x;
  if (priority == 2)
  {
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
  else
  {
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
}

canonical_original_code:
void bankp_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; int flipx;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x04;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * ((colorram[offs] & 3) >> 0),
     colorram[offs] >> 3,
     flipx,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx; int sy; int flipx;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = bankp_colorram2[offs] & 0x08;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     bankp_videoram2[offs] + 256 * (bankp_colorram2[offs] & 0x07),
     bankp_colorram2[offs] >> 4,
     flipx,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll;
  scroll = -scroll_x;
  if (priority == 2)
  {
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
  else
  {
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
}

variable_types: scroll int

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


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

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

original_code:
int tigeroad_interrupt(void)
{
 return 2;
}

canonical_original_code:
int tigeroad_interrupt()
{
 return 2;
}


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

if ( (a2 & 0xFF000000) == 0 )
{
flipscreen = BYTE1(a2) & 2;
bgcharbank = (BYTE1(a2) >> 2) & 1;
coin_counter_w(0LL, BYTE1(a2) & 0x40);
result = coin_counter_w(1LL, (a2 >> 8) & 0x80);
}
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
{
flipscreen = BYTE1(a2) & 2;
bgcharbank = (BYTE1(a2) >> 2) & 1;
coin_counter_w(0LL, BYTE1(a2) & 0x40);
result = coin_counter_w(1LL, (a2 >> 8) & 0x80);
}
return result;
}

original_code:
void tigeroad_videoctrl_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
 {
  data = (data >> 8) & 0xff;
  flipscreen = data & 0x02;
  bgcharbank = (data & 0x04) >> 2;
  coin_counter_w(0,data & 0x40);
  coin_counter_w(1,data & 0x80);
 }
}

canonical_original_code:
void tigeroad_videoctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
 {
  data = (data >> 8) & 0xff;
  flipscreen = data & 0x02;
  bgcharbank = (data & 0x04) >> 2;
  coin_counter_w(0,data & 0x40);
  coin_counter_w(1,data & 0x80);
 }
}


decompiled_code:
__int64 init_tigeroad()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, tigeroad_soundcmd_w);
}

canonical_decompiled_code:
__int64 func7()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, tigeroad_soundcmd_w);
}

original_code:
void init_tigeroad(void)
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, tigeroad_soundcmd_w);
}

canonical_original_code:
void init_tigeroad()
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, tigeroad_soundcmd_w);
}


decompiled_code:
__int64 init_f1dream()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, f1dream_control_w);
}

canonical_decompiled_code:
__int64 func8()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, f1dream_control_w);
}

original_code:
void init_f1dream(void)
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, f1dream_control_w);
}

canonical_original_code:
void init_f1dream()
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, f1dream_control_w);
}


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

if ( (a2 & 0xFF000000) == 0 )
result = soundlatch_w(a1, BYTE1(a2));
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
result = soundlatch_w(a1, BYTE1(a2));
return result;
}

original_code:
static void tigeroad_soundcmd_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
  soundlatch_w(offset,(data >> 8) & 0xff);
}

canonical_original_code:
static void tigeroad_soundcmd_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
  soundlatch_w(offset,(data >> 8) & 0xff);
}


decompiled_code:
__int64 f1dream_protection_w()
{
__int64 result; // rax
__int16 v1; // cx
int v2; // esi
_WORD *v3; // rdx
_DWORD *v4; // rcx
__int64 v5; // rsi
int v6; // eax
int v7; // esi
unsigned __int16 v8; // cx
int v9; // esi

result = cpu_get_reg(0xFFFFFFFFLL);
if ( (_DWORD)result == 9292 )
{
v3 = (_WORD *)ram;
v4 = &f1dream_2450_lookup;
v5 = *(unsigned __int16 *)(ram + 16368);
v6 = *(unsigned __int16 *)(ram + 16368);
goto LABEL_15;
}
if ( (_DWORD)result != 24890 )
{
if ( (_DWORD)result != 97136 )
{
if ( (_DWORD)result == 10232 || (_DWORD)result == 20762 || (_DWORD)result == 20802 || (_DWORD)result == 20842 )
result = soundlatch_w(2LL, *(unsigned __int16 *)(ram + 16380));
return result;
}
v3 = (_WORD *)ram;
v8 = *(_WORD *)(ram + 16368);
if ( v8 > 3u )
goto LABEL_22;
v9 = 96;
if ( v8 != 3 )
{
v9 = 64;
if ( v8 != 2 )
v9 = 32 * (v8 == 1);
}
v6 = v9 + *(unsigned __int16 *)(ram + 16366);
if ( v6 > 127 )
{
LABEL_22:
result = 0xFF00FF00FF00FFLL;
*(_QWORD *)(ram + 16358) = 0xFF00FF00FF00FFLL;
return result;
}
v4 = &f1dream_17b74_lookup;
v5 = v6;
LABEL_15:
v3[8179] = v4[v5];
v3[8180] = v4[v6 + 1];
v7 = v4[v6 + 2];
result = (unsigned int)v4[v6 + 3];
v3[8181] = v7;
v3[8182] = result;
return result;
}
v1 = 255;
result = *(unsigned __int16 *)(ram + 16374);
if ( (unsigned __int16)result <= 0xEu )
{
v2 = (unsigned __int16)result;
result = f1dream_613ea_lookup[result] - (unsigned int)*(unsigned __int16 *)(ram + 16372);
if ( (int)result > 255 )
{
result = v2 + 16 * (int)result;
v1 = f1dream_613eb_lookup[2 * result];
}
}
*(_WORD *)(ram + 16370) = v1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
__int16 v1; // cx
int v2; // esi
_WORD *v3; // rdx
_DWORD *v4; // rcx
__int64 v5; // rsi
int v6; // eax
int v7; // esi
unsigned __int16 v8; // cx
int v9; // esi

result = cpu_get_reg(0xFFFFFFFFLL);
if ( (_DWORD)result == 9292 )
{
v3 = (_WORD *)ram;
v4 = &f1dream_2450_lookup;
v5 = *(unsigned __int16 *)(ram + 16368);
v6 = *(unsigned __int16 *)(ram + 16368);
goto LABEL_15;
}
if ( (_DWORD)result != 24890 )
{
if ( (_DWORD)result != 97136 )
{
if ( (_DWORD)result == 10232 || (_DWORD)result == 20762 || (_DWORD)result == 20802 || (_DWORD)result == 20842 )
result = soundlatch_w(2LL, *(unsigned __int16 *)(ram + 16380));
return result;
}
v3 = (_WORD *)ram;
v8 = *(_WORD *)(ram + 16368);
if ( v8 > 3u )
goto LABEL_22;
v9 = 96;
if ( v8 != 3 )
{
v9 = 64;
if ( v8 != 2 )
v9 = 32 * (v8 == 1);
}
v6 = v9 + *(unsigned __int16 *)(ram + 16366);
if ( v6 > 127 )
{
LABEL_22:
result = 0xFF00FF00FF00FFLL;
*(_QWORD *)(ram + 16358) = 0xFF00FF00FF00FFLL;
return result;
}
v4 = &f1dream_17b74_lookup;
v5 = v6;
LABEL_15:
v3[8179] = v4[v5];
v3[8180] = v4[v6 + 1];
v7 = v4[v6 + 2];
result = (unsigned int)v4[v6 + 3];
v3[8181] = v7;
v3[8182] = result;
return result;
}
v1 = 255;
result = *(unsigned __int16 *)(ram + 16374);
if ( (unsigned __int16)result <= 0xEu )
{
v2 = (unsigned __int16)result;
result = f1dream_613ea_lookup[result] - (unsigned int)*(unsigned __int16 *)(ram + 16372);
if ( (int)result > 255 )
{
result = v2 + 16 * (int)result;
v1 = f1dream_613eb_lookup[2 * result];
}
}
*(_WORD *)(ram + 16370) = v1;
return result;
}

canonical_original_code:
static void f1dream_protection_w()
{
 int indx;
 int value = 255;
 int prevpc = cpu_get_reg(-1);
 if (prevpc == 0x244c)
 {
  indx = (*(unsigned short *)(&ram[0x3ff0]));
  (*(unsigned short *)(&ram[0x3fe6]) = (f1dream_2450_lookup[indx]));
  (*(unsigned short *)(&ram[0x3fe8]) = (f1dream_2450_lookup[++indx]));
  (*(unsigned short *)(&ram[0x3fea]) = (f1dream_2450_lookup[++indx]));
  (*(unsigned short *)(&ram[0x3fec]) = (f1dream_2450_lookup[++indx]));
 }
 else if (prevpc == 0x613a)
 {
  if (((*(unsigned short *)(&ram[0x3ff6]))) < 15)
  {
   indx = f1dream_613ea_lookup[(*(unsigned short *)(&ram[0x3ff6]))] - ((*(unsigned short *)(&ram[0x3ff4])));
   if (indx > 255)
   {
    indx <<= 4;
    indx += (*(unsigned short *)(&ram[0x3ff6])) & 0x00ff;
    value = f1dream_613eb_lookup[indx];
   }
  }
  (*(unsigned short *)(&ram[0x3ff2]) = (value));
 }
 else if (prevpc == 0x17b70)
 {
  if (((*(unsigned short *)(&ram[0x3ff0]))) >= 0x04) indx = 128;
  else if (((*(unsigned short *)(&ram[0x3ff0]))) > 0x02) indx = 96;
  else if (((*(unsigned short *)(&ram[0x3ff0]))) == 0x02) indx = 64;
  else if (((*(unsigned short *)(&ram[0x3ff0]))) == 0x01) indx = 32;
  else indx = 0;
  indx += (*(unsigned short *)(&ram[0x3fee]));
  if (indx < 128)
  {
   (*(unsigned short *)(&ram[0x3fe6]) = (f1dream_17b74_lookup[indx]));
   (*(unsigned short *)(&ram[0x3fe8]) = (f1dream_17b74_lookup[++indx]));
   (*(unsigned short *)(&ram[0x3fea]) = (f1dream_17b74_lookup[++indx]));
   (*(unsigned short *)(&ram[0x3fec]) = (f1dream_17b74_lookup[++indx]));
  }
  else
  {
   (*(unsigned short *)(&ram[0x3fe6]) = (0x00ff));
   (*(unsigned short *)(&ram[0x3fe8]) = (0x00ff));
   (*(unsigned short *)(&ram[0x3fea]) = (0x00ff));
   (*(unsigned short *)(&ram[0x3fec]) = (0x00ff));
  }
 }
 else if ((prevpc == 0x27f8) || (prevpc == 0x511a) || (prevpc == 0x5142) || (prevpc == 0x516a))
 {
  soundlatch_w(2,(*(unsigned short *)(&ram[0x3ffc])));
 }
}

variable_types: indx int

variable_types: value int

variable_types: prevpc int


decompiled_code:
// attributes: thunk
__int64 __fastcall f1dream_control_w()
{
return f1dream_protection_w();
}

canonical_decompiled_code:
__int64 __fastcall func11()
{
return func10();
}

original_code:
static void f1dream_control_w(offs_t offset,data_t data)
{
 f1dream_protection_w();
}

canonical_original_code:
static void f1dream_control_w(unsigned int offset, unsigned int data)
{
 f1dream_protection_w();
}


decompiled_code:
__int64 __fastcall msm5205_w(__int64 a1, unsigned int a2)
{
MSM5205_reset_w(a1, (a2 >> 7) & 1);
MSM5205_data_w((unsigned int)a1, a2);
MSM5205_vclk_w((unsigned int)a1, 1LL);
return MSM5205_vclk_w((unsigned int)a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
MSM5205_reset_w(a1, (a2 >> 7) & 1);
MSM5205_data_w((unsigned int)a1, a2);
MSM5205_vclk_w((unsigned int)a1, 1LL);
return MSM5205_vclk_w((unsigned int)a1, 0LL);
}

original_code:
static void msm5205_w(offs_t offset,data_t data)
{
 MSM5205_reset_w(offset,(data>>7)&1);
 MSM5205_data_w(offset,data);
 MSM5205_vclk_w(offset,1);
 MSM5205_vclk_w(offset,0);
}

canonical_original_code:
static void msm5205_w(unsigned int offset, unsigned int data)
{
 MSM5205_reset_w(offset,(data>>7)&1);
 MSM5205_data_w(offset,data);
 MSM5205_vclk_w(offset,1);
 MSM5205_vclk_w(offset,0);
}


decompiled_code:
__int64 __fastcall render_sprites(__int64 a1)
{
unsigned __int64 v1; // rbp
__int64 result; // rax
unsigned __int16 *v3; // rbx
__int64 v4; // rdx

v1 = spriteram;
result = spriteram_size;
v3 = (unsigned __int16 *)(spriteram + spriteram_size - 8LL);
if ( spriteram <= (unsigned __int64)v3 )
{
do
{
v4 = *v3;
if ( (_WORD)v4 != 4095 )
result = drawgfx(a1, *(_QWORD *)(Machine + 528LL), v4, (v3[1] >> 2) & 0xF);
v3 -= 4;
}
while ( v1 <= (unsigned __int64)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rbp
__int64 result; // rax
unsigned __int16 *v3; // rbx
__int64 v4; // rdx

v1 = spriteram;
result = spriteram_size;
v3 = (unsigned __int16 *)(spriteram + spriteram_size - 8LL);
if ( spriteram <= (unsigned __int64)v3 )
{
do
{
v4 = *v3;
if ( (_WORD)v4 != 4095 )
result = drawgfx(a1, *(_QWORD *)(Machine + 528LL), v4, (v3[1] >> 2) & 0xF);
v3 -= 4;
}
while ( v1 <= (unsigned __int64)v3 );
}
return result;
}

original_code:
static void render_sprites( struct osd_bitmap *bitmap )
{
 unsigned char *source = &spriteram[spriteram_size] - 8;
 unsigned char *finish = spriteram;
 while( source>=finish )
 {
  int tile_number = (*(UINT16 *)(source));
  if( tile_number!=0xFFF ){
   int attributes = (*(UINT16 *)(source+2));
   int sy = (*(UINT16 *)(source+4)) & 0x1ff;
   int sx = (*(UINT16 *)(source+6)) & 0x1ff;
   int flipx = attributes&2;
   int flipy = attributes&1;
   int color = (attributes>>2)&0xf;
   if( sx>0x100 ) sx -= 0x200;
   if( sy>0x100 ) sy -= 0x200;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
    tile_number,
    color,
    flipx,flipy,
    sx,240-sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,15);
  }
  source-=8;
 }
}

canonical_original_code:
static void render_sprites(struct osd_bitmap *bitmap)
{
 unsigned char *source = &spriteram[spriteram_size] - 8;
 unsigned char *finish = spriteram;
 while( source>=finish )
 {
  int tile_number = (*(UINT16 *)(source));
  if( tile_number!=0xFFF ){
   int attributes = (*(UINT16 *)(source+2));
   int sy = (*(UINT16 *)(source+4)) & 0x1ff;
   int sx = (*(UINT16 *)(source+6)) & 0x1ff;
   int flipx = attributes&2;
   int flipy = attributes&1;
   int color = (attributes>>2)&0xf;
   if( sx>0x100 ) sx -= 0x200;
   if( sy>0x100 ) sy -= 0x200;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
    tile_number,
    color,
    flipx,flipy,
    sx,240-sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,15);
  }
  source-=8;
 }
}

variable_types:
source
unsigned char *

variable_types:
finish
unsigned char *

variable_types: attributes int


original_code:
static void render_background( struct osd_bitmap *bitmap, int priority )
{
 int scrollx = (*(UINT16 *)(&tigeroad_scrollram[0])) & 0xfff;
 int scrolly = (*(UINT16 *)(&tigeroad_scrollram[2])) & 0xfff;
 unsigned char *p = memory_region(REGION_GFX4);
 int alignx = scrollx%32;
 int aligny = scrolly%32;
 int row = scrolly/32;
 int sy = 224+aligny;
 int transp0,transp1;
 if( priority ){
  transp0 = 0xFFFF;
  transp1 = 0x01FF;
 }
 else {
  transp0 = 0;
  transp1 = 0xFE00;
 }
 while( sy>-32 ){
  int col = scrollx/32;
  int sx = -alignx;
  while( sx<256 ){
   int offset = 2*(col%8) + 16*(row%8) + 128*(col/8) + 2048*(row/8);
   int code = p[offset];
   int attr = p[offset+1];
   int flipx = attr & 0x20;
   int flipy = 0;
   int color = attr & 0x0f;
   if (flipscreen)
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      !flipx,!flipy,
      224-sx,224-sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   else
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      flipx,flipy,
      sx,sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   sx+=32;
   col++;
   if( col>=128 ) col-=128;
  }
  sy-=32;
  row++;
  if( row>=128 ) row-=128;
 }
}

canonical_original_code:
static void render_background(struct osd_bitmap *bitmap, int priority)
{
 int scrollx = (*(UINT16 *)(&tigeroad_scrollram[0])) & 0xfff;
 int scrolly = (*(UINT16 *)(&tigeroad_scrollram[2])) & 0xfff;
 unsigned char *p = memory_region(REGION_GFX4);
 int alignx = scrollx%32;
 int aligny = scrolly%32;
 int row = scrolly/32;
 int sy = 224+aligny;
 int transp0; int transp1;
 if( priority ){
  transp0 = 0xFFFF;
  transp1 = 0x01FF;
 }
 else {
  transp0 = 0;
  transp1 = 0xFE00;
 }
 while( sy>-32 ){
  int col = scrollx/32;
  int sx = -alignx;
  while( sx<256 ){
   int offset = 2*(col%8) + 16*(row%8) + 128*(col/8) + 2048*(row/8);
   int code = p[offset];
   int attr = p[offset+1];
   int flipx = attr & 0x20;
   int flipy = 0;
   int color = attr & 0x0f;
   if (flipscreen)
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      !flipx,!flipy,
      224-sx,224-sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   else
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      flipx,flipy,
      sx,sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   sx+=32;
   col++;
   if( col>=128 ) col-=128;
  }
  sy-=32;
  row++;
  if( row>=128 ) row-=128;
 }
}

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

variable_types: priority int

variable_types: scrollx int

variable_types: scrolly int

variable_types:
p
unsigned char *

variable_types: alignx int

variable_types: aligny int

variable_types: row int

variable_types: col int

variable_types: offset int

variable_types: code int

variable_types: attr int


irqhandler

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

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

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

variable_types: irq int


decompiled_code:
void sharkatt_vtcsel_w()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void __fastcall sharkatt_color_plane_w(__int64 a1, char a2)
{
color_plane = a2 & 0x3F;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
color_plane = a2 & 0x3F;
}

original_code:
void sharkatt_color_plane_w(offs_t offset,data_t data)
{
 color_plane = (data & 0x3F);
}

canonical_original_code:
void sharkatt_color_plane_w(unsigned int offset, unsigned int data)
{
 color_plane = (data & 0x3F);
}


decompiled_code:
void __fastcall sharkatt_8255_w(char a1, int a2)
{
if ( (a1 & 3) == 0 )
PA_8255 = a2;
}

canonical_decompiled_code:
void __fastcall func2(char a1, int a2)
{
if ( (a1 & 3) == 0 )
PA_8255 = a2;
}

original_code:
static void sharkatt_8255_w(offs_t offset,data_t data)
{
 switch (offset & 0x03)
 {
  case 0: PA_8255 = data; break;
  case 1: PB_8255 = data; break;
  case 2: PC_8255 = data; break;
  case 3: break;
 }
}

canonical_original_code:
static void sharkatt_8255_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x03)
 {
  case 0: PA_8255 = data; break;
  case 1: PB_8255 = data; break;
  case 2: PC_8255 = data; break;
  case 3: break;
 }
}


decompiled_code:
void fake_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


original_code:
void sharkatt_color_map_w(offs_t offset,data_t data)
{
    int vals[4] = {0x00,0x55,0xAA,0xFF};
    int r,g,b;
    r = vals[(data & 0x03) >> 0];
    g = vals[(data & 0x0C) >> 2];
    b = vals[(data & 0x30) >> 4];
 palette_change_color (offset,r,g,b);
}

canonical_original_code:
void sharkatt_color_map_w(unsigned int offset, unsigned int data)
{
    int vals[4] = {0x00,0x55,0xAA,0xFF};
    int r; int g; int b;
    r = vals[(data & 0x03) >> 0];
    g = vals[(data & 0x0C) >> 2];
    b = vals[(data & 0x30) >> 4];
 palette_change_color (offset,r,g,b);
}

variable_types:
vals
int [4]

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall sharkatt_videoram_w(unsigned int a1, int a2)
{
unsigned int v2; // er15
int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er14
__int64 v6; // rcx
__int64 result; // rax
unsigned __int16 *v8; // rdx
__int64 v9; // rsi
__int64 v10; // rcx

v2 = a1 >> 5;
v3 = a2;
v4 = 8 * (a1 & 0x1F);
v5 = v4 + 8;
*(_BYTE *)(videoram + a1) = a2;
do
{
while ( 1 )
{
v8 = *(unsigned __int16 **)(Machine + 792LL);
v9 = *(_QWORD *)(Machine + 768LL);
if ( (v3 & 0x80u) == 0 )
break;
v6 = v4++;
v3 *= 2;
result = plot_pixel2(tmpbitmap, v9, v2, v6, v8[color_plane & 0xF]);
if ( v4 == v5 )
return result;
}
v10 = v4++;
v3 *= 2;
result = plot_pixel2(tmpbitmap, v9, v2, v10, *v8);
}
while ( v4 != v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, int a2)
{
unsigned int v2; // er15
int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er14
__int64 v6; // rcx
__int64 result; // rax
unsigned __int16 *v8; // rdx
__int64 v9; // rsi
__int64 v10; // rcx

v2 = a1 >> 5;
v3 = a2;
v4 = 8 * (a1 & 0x1F);
v5 = v4 + 8;
*(_BYTE *)(videoram + a1) = a2;
do
{
while ( 1 )
{
v8 = *(unsigned __int16 **)(Machine + 792LL);
v9 = *(_QWORD *)(Machine + 768LL);
if ( (v3 & 0x80u) == 0 )
break;
v6 = v4++;
v3 *= 2;
result = plot_pixel2(tmpbitmap, v9, v2, v6, v8[color_plane & 0xF]);
if ( v4 == v5 )
return result;
}
v10 = v4++;
v3 *= 2;
result = plot_pixel2(tmpbitmap, v9, v2, v10, *v8);
}
while ( v4 != v5 );
return result;
}

original_code:
void sharkatt_videoram_w(offs_t offset,data_t data)
{
 int i,x,y;
 videoram[offset] = data;
 x = offset / 32;
 y = 8 * (offset % 32);
 for (i = 0;i < 8;i++)
 {
  int col;
  col = Machine->pens[color_plane & 0x0F];
  if (data & 0x80)
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, col);
  }
  else
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, Machine->pens[0]);
  }
  y++;
  data <<= 1;
 }
}

canonical_original_code:
void sharkatt_videoram_w(unsigned int offset, unsigned int data)
{
 int i; int x; int y;
 videoram[offset] = data;
 x = offset / 32;
 y = 8 * (offset % 32);
 for (i = 0;i < 8;i++)
 {
  int col;
  col = Machine->pens[color_plane & 0x0F];
  if (data & 0x80)
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, col);
  }
  else
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, Machine->pens[0]);
  }
  y++;
  data <<= 1;
 }
}

variable_types: i int

variable_types: x int

variable_types: y int


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

if ( (input_port_3_r(0LL) & 0x10) != 0 )
result = interrupt();
else
result = nmi_interrupt();
return result;
}

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

if ( (input_port_3_r(0LL) & 0x10) != 0 )
result = interrupt();
else
result = nmi_interrupt();
return result;
}

original_code:
static int sharkatt_interrupt(void)
{
 if ((input_port_3_r(0) & 0x10) == 0)
  return nmi_interrupt();
 return interrupt();
}

canonical_original_code:
static int sharkatt_interrupt()
{
 if ((input_port_3_r(0) & 0x10) == 0)
  return nmi_interrupt();
 return interrupt();
}


decompiled_code:
__int64 __fastcall sharkatt_8255_r(__int64 a1)
{
if ( (a1 & 3) != 1 )
return 0LL;
if ( (PA_8255 & 1) != 0 )
return input_port_0_r();
if ( (PA_8255 & 2) != 0 )
return input_port_1_r();
if ( (PA_8255 & 4) != 0 )
return input_port_2_r();
if ( (PA_8255 & 8) == 0 )
return 0LL;
return input_port_3_r(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( (a1 & 3) != 1 )
return 0LL;
if ( (PA_8255 & 1) != 0 )
return input_port_0_r();
if ( (PA_8255 & 2) != 0 )
return input_port_1_r();
if ( (PA_8255 & 4) != 0 )
return input_port_2_r();
if ( (PA_8255 & 8) == 0 )
return 0LL;
return input_port_3_r(a1);
}

original_code:
static data_t sharkatt_8255_r(offs_t offset)
{
 switch (offset & 0x03)
 {
  case 1:
   if (PA_8255 & 0x01)
    return input_port_0_r(offset);
   if (PA_8255 & 0x02)
    return input_port_1_r(offset);
   if (PA_8255 & 0x04)
    return input_port_2_r(offset);
   if (PA_8255 & 0x08)
    return input_port_3_r(offset);
   break;
  default:
   break;
 }
 return 0;
}

canonical_original_code:
static unsigned int sharkatt_8255_r(unsigned int offset)
{
 switch (offset & 0x03)
 {
  case 1:
   if (PA_8255 & 0x01)
    return input_port_0_r(offset);
   if (PA_8255 & 0x02)
    return input_port_1_r(offset);
   if (PA_8255 & 0x04)
    return input_port_2_r(offset);
   if (PA_8255 & 0x08)
    return input_port_3_r(offset);
   break;
  default:
   break;
 }
 return 0;
}

return_type: unsigned int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: j int


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

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

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

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

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

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


decompiled_code:
void *__fastcall shaolins_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // r13
__int16 v3; // r9
__int64 v4; // rcx
__int64 v5; // rdx
char v6; // al
unsigned __int8 *v7; // rsi
char *v8; // rax
void *result; // rax
int v10; // er13
__int64 v11; // r12
int v12; // edx
unsigned int v13; // er10
__int64 v14; // r9
__int64 v15; // rcx
__int64 v16; // r8
int v17; // edi
__int64 v18; // [rsp-28h] [rbp-E0h]
__int64 v19[2]; // [rsp+0h] [rbp-B8h] BYREF
char v20; // [rsp+10h] [rbp-A8h] BYREF
char v21; // [rsp+80h] [rbp-38h] BYREF

v1 = 0LL;
do
{
while ( !*(_BYTE *)(v1 + dirtybuffer) )
{
if ( videoram_size < ++v1 )
goto LABEL_5;
}
*(_BYTE *)(v1 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(colorram + v1);
v4 = (*(_BYTE *)(colorram + v1) & 0xFu) + 16 * palettebank;
v5 = *(unsigned __int8 *)(videoram + v1) + ((4 * v3) & 0x100u);
v18 = (unsigned int)(8 * ((int)v1 >> 5));
v6 = v1++;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 512LL), v5, v4, 0LL, v3 & 0x20, 8 * (v6 & 0x1Fu), v18, 0LL, 0LL, 0LL);
}
while ( videoram_size >= v1 );
LABEL_5:
v19[0] = 0LL;
v19[1] = 0LL;
v7 = (unsigned __int8 *)shaolins_scroll;
v8 = &v20;
do
{
v8 += 4;
*((_DWORD *)v8 - 1) = ~*v7;
}
while ( &v21 != v8 );
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v19, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v10 = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v11 = v10;
do
{
while ( 1 )
{
result = (void *)spriteram;
if ( *(_BYTE *)(spriteram + v11) )
{
v12 = *(unsigned __int8 *)(spriteram + v11 + 6);
if ( (_BYTE)v12 )
break;
}
v11 -= 32LL;
v10 -= 32;
if ( v10 < 0 )
return result;
}
v13 = *(unsigned __int8 *)(spriteram + v11 + 8);
v14 = *(_BYTE *)(spriteram + v11 + 9) & 0x80;
v15 = (*(_BYTE *)(spriteram + v11 + 9) & 0xFu) + 16 * palettebank;
v16 = ((*(_BYTE *)(spriteram + v11 + 9) >> 6) ^ 1) & 1;
v17 = *(unsigned __int8 *)(spriteram + v11 + 4);
v11 -= 32LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
v15,
v16,
v14,
(unsigned int)(240 - v12),
(unsigned int)(248 - v17),
Machine + 776LL,
6LL,
0LL);
v10 -= 32;
}
while ( v10 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
unsigned __int64 v1; // r13
__int16 v3; // r9
__int64 v4; // rcx
__int64 v5; // rdx
char v6; // al
unsigned __int8 *v7; // rsi
char *v8; // rax
void *result; // rax
int v10; // er13
__int64 v11; // r12
int v12; // edx
unsigned int v13; // er10
__int64 v14; // r9
__int64 v15; // rcx
__int64 v16; // r8
int v17; // edi
__int64 v18; // [rsp-28h] [rbp-E0h]
__int64 v19[2]; // [rsp+0h] [rbp-B8h] BYREF
char v20; // [rsp+10h] [rbp-A8h] BYREF
char v21; // [rsp+80h] [rbp-38h] BYREF

v1 = 0LL;
do
{
while ( !*(_BYTE *)(v1 + dirtybuffer) )
{
if ( videoram_size < ++v1 )
goto LABEL_5;
}
*(_BYTE *)(v1 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(colorram + v1);
v4 = (*(_BYTE *)(colorram + v1) & 0xFu) + 16 * palettebank;
v5 = *(unsigned __int8 *)(videoram + v1) + ((4 * v3) & 0x100u);
v18 = (unsigned int)(8 * ((int)v1 >> 5));
v6 = v1++;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 512LL), v5, v4, 0LL, v3 & 0x20, 8 * (v6 & 0x1Fu), v18, 0LL, 0LL, 0LL);
}
while ( videoram_size >= v1 );
LABEL_5:
v19[0] = 0LL;
v19[1] = 0LL;
v7 = (unsigned __int8 *)shaolins_scroll;
v8 = &v20;
do
{
v8 += 4;
*((_DWORD *)v8 - 1) = ~*v7;
}
while ( &v21 != v8 );
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v19, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v10 = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v11 = v10;
do
{
while ( 1 )
{
result = (void *)spriteram;
if ( *(_BYTE *)(spriteram + v11) )
{
v12 = *(unsigned __int8 *)(spriteram + v11 + 6);
if ( (_BYTE)v12 )
break;
}
v11 -= 32LL;
v10 -= 32;
if ( v10 < 0 )
return result;
}
v13 = *(unsigned __int8 *)(spriteram + v11 + 8);
v14 = *(_BYTE *)(spriteram + v11 + 9) & 0x80;
v15 = (*(_BYTE *)(spriteram + v11 + 9) & 0xFu) + 16 * palettebank;
v16 = ((*(_BYTE *)(spriteram + v11 + 9) >> 6) ^ 1) & 1;
v17 = *(unsigned __int8 *)(spriteram + v11 + 4);
v11 -= 32LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
v15,
v16,
v14,
(unsigned int)(240 - v12),
(unsigned int)(248 - v17),
Machine + 776LL,
6LL,
0LL);
v10 -= 32;
}
while ( v10 >= 0 );
}
return result;
}

original_code:
void shaolins_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy;
 for (offs = 0;offs <= videoram_size;offs++)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x40) << 2),
     (colorram[offs] & 0x0f) + 16 * palettebank,
     0,colorram[offs] & 0x20,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll[32], i;
  for (i = 0;i < 4;i++)
   scroll[i] = 0;
  for (i = 4;i < 32;i++)
   scroll[i] = -*shaolins_scroll-1;
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size-32; offs >= 0; offs-=32 )
 {
  if (spriteram[offs] && spriteram[offs+6])
  {
   drawgfx(bitmap,Machine->gfx[1],
     spriteram[offs+8],
     (spriteram[offs+9] & 0x0f) + 16 * palettebank,
     !(spriteram[offs+9] & 0x40),(spriteram[offs+9] & 0x80),
     240-spriteram[offs+6],248-spriteram[offs+4],
     &Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
}

canonical_original_code:
void shaolins_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy;
 for (offs = 0;offs <= videoram_size;offs++)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x40) << 2),
     (colorram[offs] & 0x0f) + 16 * palettebank,
     0,colorram[offs] & 0x20,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll[32]; int i;
  for (i = 0;i < 4;i++)
   scroll[i] = 0;
  for (i = 4;i < 32;i++)
   scroll[i] = -*shaolins_scroll-1;
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size-32; offs >= 0; offs-=32 )
 {
  if (spriteram[offs] && spriteram[offs+6])
  {
   drawgfx(bitmap,Machine->gfx[1],
     spriteram[offs+8],
     (spriteram[offs+9] & 0x0f) + 16 * palettebank,
     !(spriteram[offs+9] & 0x40),(spriteram[offs+9] & 0x80),
     240-spriteram[offs+6],248-spriteram[offs+4],
     &Machine->visible_area,TRANSPARENCY_COLOR,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:
scroll
int [32]


decompiled_code:
__int64 shaolins_interrupt()
{
if ( !(unsigned int)cpu_getiloops() )
return interrupt();
if ( (cpu_getiloops() & 1) != 0 && (*shaolins_nmi_enable & 2) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func3()
{
if ( !(unsigned int)cpu_getiloops() )
return interrupt();
if ( (cpu_getiloops() & 1) != 0 && (*shaolins_nmi_enable & 2) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
int shaolins_interrupt(void)
{
 if (cpu_getiloops() == 0) return interrupt();
 else if (cpu_getiloops() % 2)
 {
  if (*shaolins_nmi_enable & 0x02) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
int shaolins_interrupt()
{
 if (cpu_getiloops() == 0) return interrupt();
 else if (cpu_getiloops() % 2)
 {
  if (*shaolins_nmi_enable & 0x02) return nmi_interrupt();
 }
 return ignore_interrupt();
}


decompiled_code:
void __fastcall magix_videobank_w(__int64 a1, int a2)
{
magix_videobank = a2;
}

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

original_code:
void magix_videobank_w(offs_t offset,data_t data)
{
 magix_videobank = data;
}

canonical_original_code:
void magix_videobank_w(unsigned int offset, unsigned int data)
{
 magix_videobank = data;
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall magix_videoram_r(unsigned int a1)
{
int v1; // eax
__int64 result; // rax

v1 = magix_videobank & 1;
if ( a1 <= 0x7FF )
v1 = magix_videobank & 2;
if ( v1 )
result = *(unsigned __int8 *)(magix_videoram_0 + a1);
else
result = *(unsigned __int8 *)(magix_videoram_1 + a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
int v1; // eax
__int64 result; // rax

v1 = magix_videobank & 1;
if ( a1 <= 0x7FF )
v1 = magix_videobank & 2;
if ( v1 )
result = *(unsigned __int8 *)(magix_videoram_0 + a1);
else
result = *(unsigned __int8 *)(magix_videoram_1 + a1);
return result;
}

original_code:
data_t magix_videoram_r(offs_t offset)
{
 int bank;
 if (offset < 0x0800) bank = magix_videobank & 2;
 else bank = magix_videobank & 1;
 if (bank) return magix_videoram_0[offset];
 else return magix_videoram_1[offset];
}

canonical_original_code:
unsigned int magix_videoram_r(unsigned int offset)
{
 int bank;
 if (offset < 0x0800) bank = magix_videobank & 2;
 else bank = magix_videobank & 1;
 if (bank) return magix_videoram_0[offset];
 else return magix_videoram_1[offset];
}

variable_types: bank int


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

result = (unsigned __int8)(16 * a2);
adpcm = result | (a2 >> 4);
return result;
}

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

result = (unsigned __int8)(16 * a2);
adpcm = result | (a2 >> 4);
return result;
}

original_code:
void magix_adpcm_w(offs_t offset,data_t data)
{
 adpcm = ((data&0xf)<<4) | ((data >>4)&0xf);
}

canonical_original_code:
void magix_adpcm_w(unsigned int offset, unsigned int data)
{
 adpcm = ((data&0xf)<<4) | ((data >>4)&0xf);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall magix_videoram_w(unsigned int a1, char a2)
{
int v2; // eax
__int64 v3; // rdx
unsigned int v4; // ecx
__int64 v6; // rdi
int v7; // esi
unsigned int v8; // edx
__int64 v9; // rcx
int v10; // esi
__int64 v11; // rdx
__int64 result; // rax
unsigned int v13; // er8

if ( a1 > 0x7FF )
{
v13 = (a1 - 4096) >> 1;
if ( a1 <= 0xFFF )
v13 = a1 - 2048;
if ( (magix_videobank & 1) != 0 )
{
*(_BYTE *)(magix_videoram_0 + a1) = a2;
result = tilemap_mark_tile_dirty(tilemap_0, v13);
}
else
{
*(_BYTE *)(magix_videoram_1 + a1) = a2;
result = tilemap_mark_tile_dirty(tilemap_1, v13);
}
}
else
{
v2 = magix_videobank & 2;
if ( (magix_videobank & 2) != 0 )
v3 = magix_videoram_0;
else
v3 = magix_videoram_1;
*(_BYTE *)(v3 + a1) = a2;
v4 = a1;
v6 = a1 >> 1;
v7 = *(unsigned __int8 *)(v3 + (a1 & 0xFFFFFFFE));
v8 = v7 | (*(unsigned __int8 *)(v3 + (v4 | 1)) << 8);
v9 = (unsigned __int8)((8 * ((v8 >> 10) & 0x1F)) | ((int)((v8 >> 10) & 0x1F) >> 2));
v10 = (8 * (v7 & 0x1F)) | ((v7 & 0x1F) >> 2);
v11 = (unsigned __int8)((8 * ((v8 >> 5) & 0x1F)) | ((int)((v8 >> 5) & 0x1F) >> 2));
if ( v2 )
v6 = (unsigned int)(v6 + 1024);
result = palette_change_color(v6, (unsigned __int8)v10, v11, v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
int v2; // eax
__int64 v3; // rdx
unsigned int v4; // ecx
__int64 v6; // rdi
int v7; // esi
unsigned int v8; // edx
__int64 v9; // rcx
int v10; // esi
__int64 v11; // rdx
__int64 result; // rax
unsigned int v13; // er8

if ( a1 > 0x7FF )
{
v13 = (a1 - 4096) >> 1;
if ( a1 <= 0xFFF )
v13 = a1 - 2048;
if ( (magix_videobank & 1) != 0 )
{
*(_BYTE *)(magix_videoram_0 + a1) = a2;
result = tilemap_mark_tile_dirty(tilemap_0, v13);
}
else
{
*(_BYTE *)(magix_videoram_1 + a1) = a2;
result = tilemap_mark_tile_dirty(tilemap_1, v13);
}
}
else
{
v2 = magix_videobank & 2;
if ( (magix_videobank & 2) != 0 )
v3 = magix_videoram_0;
else
v3 = magix_videoram_1;
*(_BYTE *)(v3 + a1) = a2;
v4 = a1;
v6 = a1 >> 1;
v7 = *(unsigned __int8 *)(v3 + (a1 & 0xFFFFFFFE));
v8 = v7 | (*(unsigned __int8 *)(v3 + (v4 | 1)) << 8);
v9 = (unsigned __int8)((8 * ((v8 >> 10) & 0x1F)) | ((int)((v8 >> 10) & 0x1F) >> 2));
v10 = (8 * (v7 & 0x1F)) | ((v7 & 0x1F) >> 2);
v11 = (unsigned __int8)((8 * ((v8 >> 5) & 0x1F)) | ((int)((v8 >> 5) & 0x1F) >> 2));
if ( v2 )
v6 = (unsigned int)(v6 + 1024);
result = palette_change_color(v6, (unsigned __int8)v10, v11, v9);
}
return result;
}

original_code:
void magix_videoram_w(offs_t offset,data_t data)
{
 if (offset < 0x0800)
 {
  int bank = magix_videobank & 2;
  unsigned char *RAM;
  int r,g,b;
  if (bank) RAM = magix_videoram_0;
  else RAM = magix_videoram_1;
  RAM[offset] = data;
  data = RAM[offset & ~1] | (RAM[offset | 1] << 8);
  r = (data >> 0) & 0x1f;
  g = (data >> 5) & 0x1f;
  b = (data >> 10) & 0x1f;
  palette_change_color(offset/2 + (bank ? 0x400:0), (r << 3)|(r >> 2), (g << 3)|(g >> 2), (b << 3)|(b >> 2));
 }
 else
 {
  int tile;
  int bank = magix_videobank & 1;
  if (offset < 0x1000) tile = (offset-0x0800);
  else tile = (offset-0x1000)/2;
  if (bank) { magix_videoram_0[offset] = data;
      tilemap_mark_tile_dirty(tilemap_0, tile); }
  else { magix_videoram_1[offset] = data;
      tilemap_mark_tile_dirty(tilemap_1, tile); }
 }
}

canonical_original_code:
void magix_videoram_w(unsigned int offset, unsigned int data)
{
 if (offset < 0x0800)
 {
  int bank = magix_videobank & 2;
  unsigned char *RAM;
  int r; int g; int b;
  if (bank) RAM = magix_videoram_0;
  else RAM = magix_videoram_1;
  RAM[offset] = data;
  data = RAM[offset & ~1] | (RAM[offset | 1] << 8);
  r = (data >> 0) & 0x1f;
  g = (data >> 5) & 0x1f;
  b = (data >> 10) & 0x1f;
  palette_change_color(offset/2 + (bank ? 0x400:0), (r << 3)|(r >> 2), (g << 3)|(g >> 2), (b << 3)|(b >> 2));
 }
 else
 {
  int tile;
  int bank = magix_videobank & 1;
  if (offset < 0x1000) tile = (offset-0x0800);
  else tile = (offset-0x1000)/2;
  if (bank) { magix_videoram_0[offset] = data;
      tilemap_mark_tile_dirty(tilemap_0, tile); }
  else { magix_videoram_1[offset] = data;
      tilemap_mark_tile_dirty(tilemap_1, tile); }
 }
}

variable_types:
RAM
unsigned char *

variable_types: r int

variable_types: tile int


decompiled_code:
__int64 __fastcall magix_flipscreen_w(__int64 a1, char a2)
{
return tilemap_set_flip(0LL, -(a2 & 1) & 3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
return tilemap_set_flip(0LL, -(a2 & 1) & 3);
}

original_code:
void magix_flipscreen_w(offs_t offset,data_t data)
{
 tilemap_set_flip(0, (data & 1) ? (0x1|0x2) : 0);
}

canonical_original_code:
void magix_flipscreen_w(unsigned int offset, unsigned int data)
{
 tilemap_set_flip(0, (data & 1) ? (0x1|0x2) : 0);
}


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

v0 = tilemap_create(get_tile_info_0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v3) = 32;
tilemap_0 = v0;
v1 = tilemap_create(get_tile_info_1, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v3);
tilemap_1 = v1;
if ( !tilemap_0 || !v1 )
return 1LL;
*(_DWORD *)(v1 + 132) = 0;
return 0LL;
}

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

v0 = tilemap_create(get_tile_info_0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v3) = 32;
tilemap_0 = v0;
v1 = tilemap_create(get_tile_info_1, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v3);
tilemap_1 = v1;
if ( !tilemap_0 || !v1 )
return 1LL;
*(_DWORD *)(v1 + 132) = 0;
return 0LL;
}

original_code:
int magix_vh_start(void)
{
 tilemap_0 = tilemap_create( get_tile_info_0,
        tilemap_scan_rows,
        0x00,
        8,8,
        (0x40), (0x20) );
 tilemap_1 = tilemap_create( get_tile_info_1,
        tilemap_scan_rows,
        0x01,
        8,8,
        (0x40), (0x20) );
 if (tilemap_0 && tilemap_1)
 {
  tilemap_1->transparent_pen = 0;
  return 0;
 }
 else return 1;
}

canonical_original_code:
int magix_vh_start()
{
 tilemap_0 = tilemap_create( get_tile_info_0,
        tilemap_scan_rows,
        0x00,
        8,8,
        (0x40), (0x20) );
 tilemap_1 = tilemap_create( get_tile_info_1,
        tilemap_scan_rows,
        0x01,
        8,8,
        (0x40), (0x20) );
 if (tilemap_0 && tilemap_1)
 {
  tilemap_1->transparent_pen = 0;
  return 0;
 }
 else return 1;
}


decompiled_code:
__int64 __fastcall magix_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, tilemap_0, 0LL);
return tilemap_draw(a1, tilemap_1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, tilemap_0, 0LL);
return tilemap_draw(a1, tilemap_1, 0LL);
}

original_code:
void magix_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int layers_ctrl = -1;
 tilemap_update(0);
 palette_init_used_colors();
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (layers_ctrl&1) tilemap_draw(bitmap, tilemap_0, 0);
 else osd_clearbitmap(bitmap);
 if (layers_ctrl&2) tilemap_draw(bitmap, tilemap_1, 0);
}

canonical_original_code:
void magix_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int layers_ctrl = -1;
 tilemap_update(0);
 palette_init_used_colors();
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (layers_ctrl&1) tilemap_draw(bitmap, tilemap_0, 0);
 else osd_clearbitmap(bitmap);
 if (layers_ctrl&2) tilemap_draw(bitmap, tilemap_1, 0);
}


decompiled_code:
void magix_init_machine()
{
__int64 v0; // rax

v0 = memory_region(129LL);
magix_videoram_0 = v0 + 147456;
magix_videoram_1 = v0 + 155648;
magix_videobank_w(0LL, 0);
}

canonical_decompiled_code:
void func9()
{
__int64 v0; // rax

v0 = memory_region(129LL);
magix_videoram_0 = v0 + 147456;
magix_videoram_1 = v0 + 155648;
func0(0LL, 0);
}

original_code:
void magix_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1) + 0x24000;
 magix_videoram_0 = RAM + 0x0000;
 magix_videoram_1 = RAM + 0x2000;
 magix_videobank_w(0,0);
}

canonical_original_code:
void magix_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1) + 0x24000;
 magix_videoram_0 = RAM + 0x0000;
 magix_videoram_1 = RAM + 0x2000;
 magix_videobank_w(0,0);
}


decompiled_code:
void *__fastcall magix_bankswitch_w(__int64 a1, char a2)
{
int v2; // ebx
__int64 v3; // rax
int v4; // esi
void *result; // rax
unsigned int v6; // eax

v2 = a2 & 7;
v3 = memory_region(129LL);
v4 = v2 << 14;
if ( v2 > 2 )
v4 += 0x4000;
cpu_bankbase[1] = v3 + v4;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v6);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, char a2)
{
int v2; // ebx
__int64 v3; // rax
int v4; // esi
void *result; // rax
unsigned int v6; // eax

v2 = a2 & 7;
v3 = memory_region(129LL);
v4 = v2 << 14;
if ( v2 > 2 )
v4 += 0x4000;
cpu_bankbase[1] = v3 + v4;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v6);
}
return result;
}

original_code:
void magix_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int bank = data & 7;
 if (bank < 3) RAM = &RAM[0x4000 * bank];
 else RAM = &RAM[0x4000 * (bank-3) + 0x10000];
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(RAM); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void magix_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int bank = data & 7;
 if (bank < 3) RAM = &RAM[0x4000 * bank];
 else RAM = &RAM[0x4000 * (bank-3) + 0x10000];
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(RAM); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


decompiled_code:
__int64 __fastcall magix_sound_bankswitch_w(__int64 a1, char a2)
{
__int64 v2; // rax
unsigned int v3; // edx
__int64 v4; // rdx
unsigned int v6; // eax

v2 = memory_region(130LL);
v3 = a2 & 7;
if ( v3 > 2 )
v4 = (int)((v3 << 14) + 0x4000);
else
v4 = (int)(v3 << 14);
cpu_bankbase[3] = v4 + v2;
if ( ophw == 3 )
{
ophw = -1;
v6 = cpu_get_pc();
cpu_setOPbase16(v6);
}
return MSM5205_reset_w(0LL, a2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char a2)
{
__int64 v2; // rax
unsigned int v3; // edx
__int64 v4; // rdx
unsigned int v6; // eax

v2 = memory_region(130LL);
v3 = a2 & 7;
if ( v3 > 2 )
v4 = (int)((v3 << 14) + 0x4000);
else
v4 = (int)(v3 << 14);
cpu_bankbase[3] = v4 + v2;
if ( ophw == 3 )
{
ophw = -1;
v6 = cpu_get_pc();
cpu_setOPbase16(v6);
}
return MSM5205_reset_w(0LL, a2 & 0x20);
}

original_code:
void magix_sound_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int bank = data & 7;
 if (bank < 3) RAM = &RAM[0x4000 * bank];
 else RAM = &RAM[0x4000 * (bank-3) + 0x10000];
 { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (UINT8 *)(RAM); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 MSM5205_reset_w(0,data & 0x20);
}

canonical_original_code:
void magix_sound_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int bank = data & 7;
 if (bank < 3) RAM = &RAM[0x4000 * bank];
 else RAM = &RAM[0x4000 * (bank-3) + 0x10000];
 { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (unsigned char *)(RAM); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 MSM5205_reset_w(0,data & 0x20);
}


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

result = MSM5205_data_w(0LL, (unsigned int)(adpcm >> 4));
adpcm *= 16;
toggle_0 ^= 1u;
if ( toggle_0 )
result = cpu_set_nmi_line(1LL, 3LL);
return result;
}

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

result = MSM5205_data_w(0LL, (unsigned int)(adpcm >> 4));
adpcm *= 16;
toggle_0 ^= 1u;
if ( toggle_0 )
result = cpu_set_nmi_line(1LL, 3LL);
return result;
}

original_code:
static void magix_adpcm_int(int irq)
{
 static int toggle=0;
 MSM5205_data_w (0,adpcm>>4);
 adpcm<<=4;
 toggle ^= 1;
 if (toggle)
  cpu_set_nmi_line(1,3);
}

canonical_original_code:
static void magix_adpcm_int(int irq)
{
 static int toggle = 0;
 MSM5205_data_w (0,adpcm>>4);
 adpcm<<=4;
 toggle ^= 1;
 if (toggle)
  cpu_set_nmi_line(1,3);
}

variable_types: irq int

variable_types: toggle int


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

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

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

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

original_code:
static void get_tile_info_0( int tile_index )
{
 int code = magix_videoram_0[0x1000+tile_index * 2 + 0] + magix_videoram_0[0x1000+tile_index * 2 + 1] * 256;
 int color = magix_videoram_0[0x0800+ tile_index] & 0x07;
 { 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 * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info_0(int tile_index)
{
 int code = magix_videoram_0[0x1000+tile_index * 2 + 0] + magix_videoram_0[0x1000+tile_index * 2 + 1] * 256;
 int color = magix_videoram_0[0x0800+ tile_index] & 0x07;
 { 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 * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types: code int

variable_types: color int

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


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

v1 = a1 + 2048;
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (*(unsigned __int8 *)(magix_videoram_1 + 2 * v1) + (*(unsigned __int8 *)(magix_videoram_1 + 2 * v1 + 1LL) << 8))
% *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (*(_BYTE *)(magix_videoram_1 + v1) & 0x3F);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v3 * *(_DWORD *)(v2 + 52));
v5 = *(_QWORD *)(v2 + 16);
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2 * v4;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

v1 = a1 + 2048;
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (*(unsigned __int8 *)(magix_videoram_1 + 2 * v1) + (*(unsigned __int8 *)(magix_videoram_1 + 2 * v1 + 1LL) << 8))
% *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (*(_BYTE *)(magix_videoram_1 + v1) & 0x3F);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v3 * *(_DWORD *)(v2 + 52));
v5 = *(_QWORD *)(v2 + 16);
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2 * v4;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info_1( int tile_index )
{
 int code = magix_videoram_1[0x1000+ tile_index * 2 + 0] + magix_videoram_1[0x1000+tile_index * 2 + 1] * 256;
 int color = magix_videoram_1[0x0800+ tile_index] & 0x3f;
 { const struct GfxElement *gfx = Machine->gfx[(1)]; 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 * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info_1(int tile_index)
{
 int code = magix_videoram_1[0x1000+ tile_index * 2 + 0] + magix_videoram_1[0x1000+tile_index * 2 + 1] * 256;
 int color = magix_videoram_1[0x0800+ tile_index] & 0x3f;
 { struct GfxElement *gfx = Machine->gfx[(1)]; 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 * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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


decompiled_code:
__int64 sh_votrax_stop()
{
return freesamples(VotraxSamples);
}

canonical_decompiled_code:
__int64 func0()
{
return freesamples(VotraxSamples);
}

original_code:
void sh_votrax_stop(void)
{
 freesamples(VotraxSamples);
}

canonical_original_code:
void sh_votrax_stop()
{
 freesamples(VotraxSamples);
}


decompiled_code:
__int64 __fastcall votrax_w(int a1)
{
__int64 v1; // rbp
int v2; // ebx
__int64 result; // rax

v1 = a1 & 0x3F;
v2 = a1 >> 6;
logerror("Speech : %s at intonation %d\n", VotraxTable[v1], (unsigned int)(a1 >> 6));
if ( (a1 & 0x3F) == 63 )
mixer_stop_sample((unsigned int)VotraxChannel);
result = VotraxSamples;
if ( *(_QWORD *)(VotraxSamples + 8 * v1 + 8) )
{
mixer_set_volume((unsigned int)VotraxChannel, (unsigned int)(VotraxBaseVolume + 800 * v2 / 255));
result = mixer_play_sample(
(unsigned int)VotraxChannel,
*(_QWORD *)(VotraxSamples + 8 * v1 + 8) + 12LL,
**(unsigned int **)(VotraxSamples + 8 * v1 + 8),
(unsigned int)(VotraxBaseFrequency + (v2 << 8)),
0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rbp
int v2; // ebx
__int64 result; // rax

v1 = a1 & 0x3F;
v2 = a1 >> 6;
logerror("Speech : %s at intonation %d\n", VotraxTable[v1], (unsigned int)(a1 >> 6));
if ( (a1 & 0x3F) == 63 )
mixer_stop_sample((unsigned int)VotraxChannel);
result = VotraxSamples;
if ( *(_QWORD *)(VotraxSamples + 8 * v1 + 8) )
{
mixer_set_volume((unsigned int)VotraxChannel, (unsigned int)(VotraxBaseVolume + 800 * v2 / 255));
result = mixer_play_sample(
(unsigned int)VotraxChannel,
*(_QWORD *)(VotraxSamples + 8 * v1 + 8) + 12LL,
**(unsigned int **)(VotraxSamples + 8 * v1 + 8),
(unsigned int)(VotraxBaseFrequency + (v2 << 8)),
0LL);
}
return result;
}

original_code:
void votrax_w(int data)
{
 int Phoneme,Intonation;
    Phoneme = data & 0x3F;
    Intonation = data >> 6;
   logerror("Speech : %s at intonation %d\n",VotraxTable[Phoneme],Intonation);
    if(Phoneme==63)
     mixer_stop_sample(VotraxChannel);
    if(VotraxSamples->sample[Phoneme])
 {
  mixer_set_volume(VotraxChannel,VotraxBaseVolume+(8*Intonation)*100/255);
  mixer_play_sample(VotraxChannel,VotraxSamples->sample[Phoneme]->data,
      VotraxSamples->sample[Phoneme]->length,
      VotraxBaseFrequency+(256*Intonation),
      0);
 }
}

canonical_original_code:
void votrax_w(int data)
{
 int Phoneme; int Intonation;
    Phoneme = data & 0x3F;
    Intonation = data >> 6;
   logerror("Speech : %s at intonation %d\n",VotraxTable[Phoneme],Intonation);
    if(Phoneme==63)
     mixer_stop_sample(VotraxChannel);
    if(VotraxSamples->sample[Phoneme])
 {
  mixer_set_volume(VotraxChannel,VotraxBaseVolume+(8*Intonation)*100/255);
  mixer_play_sample(VotraxChannel,VotraxSamples->sample[Phoneme]->data,
      VotraxSamples->sample[Phoneme]->length,
      VotraxBaseFrequency+(256*Intonation),
      0);
 }
}

variable_types: data int

variable_types: Phoneme int

variable_types: Intonation int


decompiled_code:
__int64 votrax_status_r()
{
return mixer_is_sample_playing((unsigned int)VotraxChannel);
}

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

original_code:
int votrax_status_r(void)
{
    return mixer_is_sample_playing(VotraxChannel);
}

canonical_original_code:
int votrax_status_r()
{
    return mixer_is_sample_playing(VotraxChannel);
}


original_code:
void gotya_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++;
 }
 color_prom += 0x18;
 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++) & 0x07;
}

canonical_original_code:
void gotya_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++;
 }
 color_prom += 0x18;
 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++) & 0x07;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall gotya_video_control_w(__int64 a1, char a2)
{
scroll_bit_8 = a2 & 1;
return flip_screen_w(a1, a2 & 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
scroll_bit_8 = a2 & 1;
return flip_screen_w(a1, a2 & 2);
}

original_code:
void gotya_video_control_w(offs_t offset,data_t data)
{
 scroll_bit_8 = data & 0x01;
 flip_screen_w(offset, data & 0x02);
}

canonical_original_code:
void gotya_video_control_w(unsigned int offset, unsigned int data)
{
 scroll_bit_8 = data & 0x01;
 flip_screen_w(offset, data & 0x02);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 gotya_vh_start()
{
__int64 v0; // rax
unsigned int v1; // er8

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

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
unsigned int v1; // er8

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

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

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


decompiled_code:
__int64 __fastcall draw_status_row(__int64 a1, int a2, int a3)
{
__int64 v3; // r14
int v4; // er12
__int64 v6; // r8
int v7; // edi
char v8; // cl
unsigned int v9; // er11
__int64 result; // rax

v3 = a3 + 944;
v4 = 29;
v6 = flip_screen_x;
if ( flip_screen_x )
a2 = 35 - a2;
while ( 1 )
{
v7 = 31 - v4;
v8 = *(_BYTE *)(gotya_foregroundram + v3);
if ( (_DWORD)v6 )
v7 = v4;
v9 = *(unsigned __int8 *)(gotya_foregroundram + v3 - 16);
--v4;
v3 -= 32LL;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v9,
v8 & 0xF,
v6,
(unsigned int)v6,
(unsigned int)(8 * a2),
(unsigned int)(8 * v7),
Machine + 776LL,
0LL,
0LL);
if ( v4 == -1 )
break;
v6 = flip_screen_x;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
__int64 v3; // r14
int v4; // er12
__int64 v6; // r8
int v7; // edi
char v8; // cl
unsigned int v9; // er11
__int64 result; // rax

v3 = a3 + 944;
v4 = 29;
v6 = flip_screen_x;
if ( flip_screen_x )
a2 = 35 - a2;
while ( 1 )
{
v7 = 31 - v4;
v8 = *(_BYTE *)(gotya_foregroundram + v3);
if ( (_DWORD)v6 )
v7 = v4;
v9 = *(unsigned __int8 *)(gotya_foregroundram + v3 - 16);
--v4;
v3 -= 32LL;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v9,
v8 & 0xF,
v6,
(unsigned int)v6,
(unsigned int)(8 * a2),
(unsigned int)(8 * v7),
Machine + 776LL,
0LL,
0LL);
if ( v4 == -1 )
break;
v6 = flip_screen_x;
}
return result;
}

original_code:
static void draw_status_row(struct osd_bitmap *bitmap, int sx, int col)
{
 int row;
 if (flip_screen_x)
 {
  sx = 35 - sx;
 }
 for (row = 29;row >= 0;row--)
 {
  int sy;
  if (flip_screen_x)
  {
   sy = row;
  }
  else
  {
   sy = 31 - row;
  }
  drawgfx(bitmap,Machine->gfx[0],
    gotya_foregroundram[row * 32 + col],
    gotya_foregroundram[row * 32 + col + 0x10] & 0x0f,
    flip_screen_x, flip_screen_x,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

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

variable_types: sx int

variable_types: col int

variable_types: row int

variable_types: sy int


decompiled_code:
__int64 __fastcall gotya_vh_screenrefresh(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // r14
int v5; // edx
int v6; // edi
__int64 v7; // rbx
char v8; // r11
__int64 v9; // rdx
__int64 v10; // rax
unsigned int v11; // er10
int v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_11;
}
else
{
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_11;
}
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v5 = v3 & 0x1F;
v6 = (v3 & 0x3FF) >> 5;
if ( !flip_screen_x )
{
v6 = 31 - ((v3 & 0x3FF) >> 5);
v5 = 31 - v5;
}
if ( v3 < 1024 )
v5 += 32;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
*(_BYTE *)(colorram + v4) & 0xF,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v5),
(unsigned int)(8 * v6),
0LL,
0LL,
0LL);
}
--v3;
--v4;
}
while ( v3 != -1 );
LABEL_11:
v7 = 3LL;
v13[0] = (unsigned __int8)*gotya_scroll + (scroll_bit_8 << 8) + 16;
copyscrollbitmap(a1, tmpbitmap, 1LL, v13, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v8 = *(_BYTE *)(spriteram + v7 + 16);
v9 = *(unsigned __int8 *)(spriteram + v7 - 1);
v10 = 256 - *(unsigned __int8 *)(spriteram + v7 + 15) + ((unsigned __int8)(*(_BYTE *)(spriteram + v7) & 1) << 8);
v11 = *(_BYTE *)(spriteram + v7) >> 2;
if ( flip_screen_x )
v9 = (unsigned int)(240 - v9);
v7 += 2LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v11,
v8 & 0xF,
flip_screen_x,
flip_screen_x,
v10,
v9,
Machine + 776LL,
2LL,
0LL);
}
while ( v7 != 15 );
draw_status_row(a1, 0, 1);
draw_status_row(a1, 1, 0);
draw_status_row(a1, 2, 2);
draw_status_row(a1, 33, 13);
draw_status_row(a1, 35, 14);
return draw_status_row(a1, 34, 15);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // r14
int v5; // edx
int v6; // edi
__int64 v7; // rbx
char v8; // r11
__int64 v9; // rdx
__int64 v10; // rax
unsigned int v11; // er10
int v13[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_11;
}
else
{
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_11;
}
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v5 = v3 & 0x1F;
v6 = (v3 & 0x3FF) >> 5;
if ( !flip_screen_x )
{
v6 = 31 - ((v3 & 0x3FF) >> 5);
v5 = 31 - v5;
}
if ( v3 < 1024 )
v5 += 32;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
*(_BYTE *)(colorram + v4) & 0xF,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v5),
(unsigned int)(8 * v6),
0LL,
0LL,
0LL);
}
--v3;
--v4;
}
while ( v3 != -1 );
LABEL_11:
v7 = 3LL;
v13[0] = (unsigned __int8)*gotya_scroll + (scroll_bit_8 << 8) + 16;
copyscrollbitmap(a1, tmpbitmap, 1LL, v13, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v8 = *(_BYTE *)(spriteram + v7 + 16);
v9 = *(unsigned __int8 *)(spriteram + v7 - 1);
v10 = 256 - *(unsigned __int8 *)(spriteram + v7 + 15) + ((unsigned __int8)(*(_BYTE *)(spriteram + v7) & 1) << 8);
v11 = *(_BYTE *)(spriteram + v7) >> 2;
if ( flip_screen_x )
v9 = (unsigned int)(240 - v9);
v7 += 2LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v11,
v8 & 0xF,
flip_screen_x,
flip_screen_x,
v10,
v9,
Machine + 776LL,
2LL,
0LL);
}
while ( v7 != 15 );
func3(a1, 0, 1);
func3(a1, 1, 0);
func3(a1, 2, 2);
func3(a1, 33, 13);
func3(a1, 35, 14);
return func3(a1, 34, 15);
}

original_code:
void gotya_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
    for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
         int sx,sy;
   dirtybuffer[offs] = 0;
   sx = 31 - (offs % 32);
   sy = 31 - ((offs & 0x03ff) / 32);
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   if (offs < 0x0400)
   {
    sx = sx + 32;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     colorram[offs] & 0x0f,
     flip_screen_x,flip_screen_x,
     8*sx, 8*sy,
     0,TRANSPARENCY_NONE,0);
  }
    }
 {
  int scroll;
  scroll = *gotya_scroll + (scroll_bit_8 * 256) + 16;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 2; offs < 0x0e; offs += 2)
 {
  int code,col,sx,sy;
  code = spriteram[offs + 0x01] >> 2;
  col = spriteram[offs + 0x11] & 0x0f;
  sx = 256 - spriteram[offs + 0x10] + (spriteram[offs + 0x01] & 0x01) * 256;
  sy = spriteram[offs + 0x00];
  if (flip_screen_x)
  {
   sy = 240 - sy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code,col,
    flip_screen_x,flip_screen_x,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 draw_status_row(bitmap, 0, 1);
 draw_status_row(bitmap, 1, 0);
 draw_status_row(bitmap, 2, 2);
 draw_status_row(bitmap, 33, 13);
 draw_status_row(bitmap, 35, 14);
 draw_status_row(bitmap, 34, 15);
}

canonical_original_code:
void gotya_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
    for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
         int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = 31 - (offs % 32);
   sy = 31 - ((offs & 0x03ff) / 32);
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   if (offs < 0x0400)
   {
    sx = sx + 32;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     colorram[offs] & 0x0f,
     flip_screen_x,flip_screen_x,
     8*sx, 8*sy,
     0,TRANSPARENCY_NONE,0);
  }
    }
 {
  int scroll;
  scroll = *gotya_scroll + (scroll_bit_8 * 256) + 16;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 2; offs < 0x0e; offs += 2)
 {
  int code; int col; int sx; int sy;
  code = spriteram[offs + 0x01] >> 2;
  col = spriteram[offs + 0x11] & 0x0f;
  sx = 256 - spriteram[offs + 0x10] + (spriteram[offs + 0x01] & 0x01) * 256;
  sy = spriteram[offs + 0x00];
  if (flip_screen_x)
  {
   sy = 240 - sy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code,col,
    flip_screen_x,flip_screen_x,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 draw_status_row(bitmap, 0, 1);
 draw_status_row(bitmap, 1, 0);
 draw_status_row(bitmap, 2, 2);
 draw_status_row(bitmap, 33, 13);
 draw_status_row(bitmap, 35, 14);
 draw_status_row(bitmap, 34, 15);
}

variable_types: offs int

variable_types: scroll int