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)
{
void *result; // rax

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

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

result = (void *)(a2 & 7);
if ( (_DWORD)result != palettebank )
{
palettebank = a2 & 7;
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);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
void *__fastcall shaolins_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int8 *v2; // rsi
char *v3; // rax
void *result; // rax
int v5; // er12
__int64 v6; // rbx
unsigned __int8 v7; // dl
int v8[4]; // [rsp+0h] [rbp-A8h] BYREF
char v9; // [rsp+10h] [rbp-98h] BYREF
char v10; // [rsp+80h] [rbp-28h] BYREF

v1 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v1) )
{
*(_BYTE *)(dirtybuffer + v1) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v1) + ((4 * *(unsigned __int8 *)(colorram + v1)) & 0x100u),
(*(_BYTE *)(colorram + v1) & 0xFu) + 16 * palettebank,
0LL,
*(_BYTE *)(colorram + v1) & 0x20,
(unsigned int)(8 * ((int)v1 % 32)),
(unsigned int)(8 * ((int)v1 / 32)),
0LL,
0LL,
0LL);
}
++v1;
}
while ( videoram_size >= v1 );
v8[0] = 0;
v8[1] = 0;
v8[2] = 0;
v8[3] = 0;
v2 = (unsigned __int8 *)shaolins_scroll;
v3 = &v9;
do
{
*(_DWORD *)v3 = ~*v2;
v3 += 4;
}
while ( v3 != &v10 );
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v8, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v5 = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v6 = v5;
do
{
result = (void *)spriteram;
if ( *(_BYTE *)(spriteram + v6) )
{
v7 = *(_BYTE *)(spriteram + v6 + 6);
if ( v7 )
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v6 + 8),
(*(_BYTE *)(spriteram + v6 + 9) & 0xFu) + 16 * palettebank,
((*(_BYTE *)(spriteram + v6 + 9) >> 6) ^ 1) & 1,
*(_BYTE *)(spriteram + v6 + 9) & 0x80,
240 - (unsigned int)v7,
248 - (unsigned int)*(unsigned __int8 *)(spriteram + v6 + 4),
Machine + 776LL,
6LL,
0LL);
}
v6 -= 32LL;
v5 -= 32;
}
while ( v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int8 *v2; // rsi
char *v3; // rax
void *result; // rax
int v5; // er12
__int64 v6; // rbx
unsigned __int8 v7; // dl
int v8[4]; // [rsp+0h] [rbp-A8h] BYREF
char v9; // [rsp+10h] [rbp-98h] BYREF
char v10; // [rsp+80h] [rbp-28h] BYREF

v1 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v1) )
{
*(_BYTE *)(dirtybuffer + v1) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v1) + ((4 * *(unsigned __int8 *)(colorram + v1)) & 0x100u),
(*(_BYTE *)(colorram + v1) & 0xFu) + 16 * palettebank,
0LL,
*(_BYTE *)(colorram + v1) & 0x20,
(unsigned int)(8 * ((int)v1 % 32)),
(unsigned int)(8 * ((int)v1 / 32)),
0LL,
0LL,
0LL);
}
++v1;
}
while ( videoram_size >= v1 );
v8[0] = 0;
v8[1] = 0;
v8[2] = 0;
v8[3] = 0;
v2 = (unsigned __int8 *)shaolins_scroll;
v3 = &v9;
do
{
*(_DWORD *)v3 = ~*v2;
v3 += 4;
}
while ( v3 != &v10 );
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v8, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v5 = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v6 = v5;
do
{
result = (void *)spriteram;
if ( *(_BYTE *)(spriteram + v6) )
{
v7 = *(_BYTE *)(spriteram + v6 + 6);
if ( v7 )
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v6 + 8),
(*(_BYTE *)(spriteram + v6 + 9) & 0xFu) + 16 * palettebank,
((*(_BYTE *)(spriteram + v6 + 9) >> 6) ^ 1) & 1,
*(_BYTE *)(spriteram + v6 + 9) & 0x80,
240 - (unsigned int)v7,
248 - (unsigned int)*(unsigned __int8 *)(spriteram + v6 + 4),
Machine + 776LL,
6LL,
0LL);
}
v6 -= 32LL;
v5 -= 32;
}
while ( v5 >= 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]

variable_types: i int


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

return_type: int


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


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

if ( a1 > 0x7FF )
v1 = magix_videobank & 1;
else
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

if ( a1 > 0x7FF )
v1 = magix_videobank & 1;
else
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

return_type: unsigned 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);
}


decompiled_code:
__int64 __fastcall magix_videoram_w(unsigned int a1, char a2)
{
int v2; // eax
__int64 v3; // rdx
int v4; // esi
unsigned int v5; // ecx
__int64 result; // rax
unsigned int v7; // eax

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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
int v2; // eax
__int64 v3; // rdx
int v4; // esi
unsigned int v5; // ecx
__int64 result; // rax
unsigned int v7; // eax

if ( a1 > 0x7FF )
{
v7 = (a1 - 4096) >> 1;
if ( a1 <= 0xFFF )
v7 = a1 - 2048;
if ( (magix_videobank & 1) != 0 )
{
*(_BYTE *)(magix_videoram_0 + a1) = a2;
result = tilemap_mark_tile_dirty(tilemap_0, v7);
}
else
{
*(_BYTE *)(magix_videoram_1 + a1) = a2;
result = tilemap_mark_tile_dirty(tilemap_1, v7);
}
}
else
{
v2 = magix_videobank & 2;
if ( (magix_videobank & 2) != 0 )
v3 = magix_videoram_0;
else
v3 = magix_videoram_1;
*(_BYTE *)(v3 + a1) = a2;
v4 = *(unsigned __int8 *)(v3 + (a1 & 0xFFFFFFFE));
v5 = v4 | (*(unsigned __int8 *)(v3 + (a1 | 1)) << 8);
result = palette_change_color(
((v2 != 0) << 10) + (a1 >> 1),
(unsigned __int8)((8 * (v4 & 0x1F)) | ((v4 & 0x1F) >> 2)),
(unsigned __int8)((8 * ((v5 >> 5) & 0x1F)) | ((int)((v5 >> 5) & 0x1F) >> 2)),
(unsigned __int8)((8 * ((v5 >> 10) & 0x1F)) | ((int)((v5 >> 10) & 0x1F) >> 2)));
}
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: g int

variable_types: b 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 v2; // [rsp+0h] [rbp-18h]

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

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

tilemap_0 = tilemap_create(get_tile_info_0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_tile_info_1, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v2);
tilemap_1 = v0;
if ( !tilemap_0 || !v0 )
return 1LL;
*(_DWORD *)(v0 + 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);
}

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


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)
{
__int64 v2; // rax
unsigned int v3; // esi
__int64 v4; // rsi
void *result; // rax
unsigned int v6; // eax

v2 = memory_region(129LL);
v3 = a2 & 7;
if ( v3 > 2 )
v4 = (int)((v3 << 14) + 0x4000);
else
v4 = (int)(v3 << 14);
cpu_bankbase[1] = v2 + 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)
{
__int64 v2; // rax
unsigned int v3; // esi
__int64 v4; // rsi
void *result; // rax
unsigned int v6; // eax

v2 = memory_region(129LL);
v3 = a2 & 7;
if ( v3 > 2 )
v4 = (int)((v3 << 14) + 0x4000);
else
v4 = (int)(v3 << 14);
cpu_bankbase[1] = v2 + 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

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

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

MSM5205_data_w(0LL, (unsigned int)(adpcm >> 4));
adpcm *= 16;
result = (unsigned int)toggle_0;
toggle_0 ^= 1u;
if ( (_DWORD)result != 1 )
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
int v2; // esi
__int64 v3; // rcx
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

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

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

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

original_code:
static void get_tile_info_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
int v2; // esi
__int64 v3; // rcx
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

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

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

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

original_code:
static void get_tile_info_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)
{
int v1; // ebx
__int64 result; // rax
unsigned int *v3; // rax

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

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

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


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

variable_types:
data
unsigned int


decompiled_code:
__int64 gotya_vh_start()
{
unsigned int v0; // edx

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

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // edx

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

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; // rbp
int i; // ebx
int v5; // eax
__int64 result; // rax

if ( flip_screen_x )
a2 = 35 - a2;
v3 = a3 + 944LL;
for ( i = 29; i != -1; --i )
{
v5 = 31 - i;
if ( flip_screen_x )
v5 = i;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(gotya_foregroundram + v3 - 16),
*(_BYTE *)(gotya_foregroundram + v3) & 0xF,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * a2),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
v3 -= 32LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
__int64 v3; // rbp
int i; // ebx
int v5; // eax
__int64 result; // rax

if ( flip_screen_x )
a2 = 35 - a2;
v3 = a3 + 944LL;
for ( i = 29; i != -1; --i )
{
v5 = 31 - i;
if ( flip_screen_x )
v5 = i;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(gotya_foregroundram + v3 - 16),
*(_BYTE *)(gotya_foregroundram + v3) & 0xF,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * a2),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
v3 -= 32LL;
}
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 v2; // ebx
__int64 v3; // r12
int v4; // eax
int v5; // esi
__int64 i; // rbx
__int64 v7; // rdx
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = v2 % 32;
v5 = (v2 & 0x3FF) >> 5;
if ( !flip_screen_x )
{
v4 = 31 - v2 % 32;
v5 = 31 - ((v2 & 0x3FF) >> 5);
}
if ( v2 < 1024 )
v4 += 32;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 0xF,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
v9[0] = (unsigned __int8)*gotya_scroll + (scroll_bit_8 << 8) + 16;
copyscrollbitmap(a1, tmpbitmap, 1LL, v9, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 3LL; i != 15; i += 2LL )
{
v7 = *(unsigned __int8 *)(spriteram + i - 1);
if ( flip_screen_x )
v7 = (unsigned int)(240 - v7);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + i) >> 2,
*(_BYTE *)(spriteram + i + 16) & 0xF,
flip_screen_x,
flip_screen_x,
256 - *(unsigned __int8 *)(spriteram + i + 15) + ((unsigned __int8)(*(_BYTE *)(spriteram + i) & 1) << 8),
v7,
Machine + 776LL,
2LL,
0LL);
}
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 v2; // ebx
__int64 v3; // r12
int v4; // eax
int v5; // esi
__int64 i; // rbx
__int64 v7; // rdx
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = v2 % 32;
v5 = (v2 & 0x3FF) >> 5;
if ( !flip_screen_x )
{
v4 = 31 - v2 % 32;
v5 = 31 - ((v2 & 0x3FF) >> 5);
}
if ( v2 < 1024 )
v4 += 32;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 0xF,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
v9[0] = (unsigned __int8)*gotya_scroll + (scroll_bit_8 << 8) + 16;
copyscrollbitmap(a1, tmpbitmap, 1LL, v9, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 3LL; i != 15; i += 2LL )
{
v7 = *(unsigned __int8 *)(spriteram + i - 1);
if ( flip_screen_x )
v7 = (unsigned int)(240 - v7);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + i) >> 2,
*(_BYTE *)(spriteram + i + 16) & 0xF,
flip_screen_x,
flip_screen_x,
256 - *(unsigned __int8 *)(spriteram + i + 15) + ((unsigned __int8)(*(_BYTE *)(spriteram + i) & 1) << 8),
v7,
Machine + 776LL,
2LL,
0LL);
}
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


decompiled_code:
__int64 __fastcall gotya_soundlatch_w(__int64 a1, int a2)
{
char *v3; // rdx
__int64 v4; // rsi
__int64 result; // rax
unsigned int v6; // ebx
unsigned int v7; // ebp

v3 = (char *)&unk_182C;
v4 = 0LL;
LODWORD(result) = 1;
if ( a2 )
{
while ( (_DWORD)result != a2 )
{
v4 = (unsigned int)(v4 + 1);
v3 += 12;
result = *((unsigned int *)v3 - 3);
if ( (_DWORD)result == -1 )
return result;
}
result = (__int64)gotya_samples;
v6 = gotya_samples[3 * (int)v4 + 2];
if ( !v6 || !theme_playing_0 )
{
v7 = gotya_samples[3 * (int)v4 + 1];
result = sample_start(v7, v4, v6);
if ( !v7 )
theme_playing_0 = v6;
}
}
else
{
result = sample_stop(0LL, 0LL, &unk_182C);
theme_playing_0 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
char *v3; // rdx
__int64 v4; // rsi
__int64 result; // rax
unsigned int v6; // ebx
unsigned int v7; // ebp

v3 = (char *)&unk_182C;
v4 = 0LL;
LODWORD(result) = 1;
if ( a2 )
{
while ( (_DWORD)result != a2 )
{
v4 = (unsigned int)(v4 + 1);
v3 += 12;
result = *((unsigned int *)v3 - 3);
if ( (_DWORD)result == -1 )
return result;
}
result = (__int64)gotya_samples;
v6 = gotya_samples[3 * (int)v4 + 2];
if ( !v6 || !theme_playing_0 )
{
v7 = gotya_samples[3 * (int)v4 + 1];
result = sample_start(v7, v4, v6);
if ( !v7 )
theme_playing_0 = v6;
}
}
else
{
result = sample_stop(0LL, 0LL, &unk_182C);
theme_playing_0 = 0;
}
return result;
}

original_code:
void gotya_soundlatch_w(offs_t offset,data_t data)
{
 static int theme_playing;
 int sample_number;
 if (data == 0)
 {
  sample_stop(0);
  theme_playing = 0;
  return;
 }
 for (sample_number = 0;
   gotya_samples[sample_number].sound_command != -1;
   sample_number++)
 {
  if (gotya_samples[sample_number].sound_command == data)
  {
   if (gotya_samples[sample_number].looping &&
    theme_playing)
   {
    return;
   }
   sample_start(gotya_samples[sample_number].channel,
       sample_number,
       gotya_samples[sample_number].looping);
   if (gotya_samples[sample_number].channel == 0)
   {
    theme_playing = gotya_samples[sample_number].looping;
   }
   return;
  }
 }
}

canonical_original_code:
void gotya_soundlatch_w(unsigned int offset, unsigned int data)
{
 static int theme_playing;
 int sample_number;
 if (data == 0)
 {
  sample_stop(0);
  theme_playing = 0;
  return;
 }
 for (sample_number = 0;
   gotya_samples[sample_number].sound_command != -1;
   sample_number++)
 {
  if (gotya_samples[sample_number].sound_command == data)
  {
   if (gotya_samples[sample_number].looping &&
    theme_playing)
   {
    return;
   }
   sample_start(gotya_samples[sample_number].channel,
       sample_number,
       gotya_samples[sample_number].looping);
   if (gotya_samples[sample_number].channel == 0)
   {
    theme_playing = gotya_samples[sample_number].looping;
   }
   return;
  }
 }
}


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

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

variable_types: i int


decompiled_code:
__int64 __fastcall yiear_control_w(__int64 a1, unsigned int a2)
{
if ( (a2 & 1) != flipscreen )
{
flipscreen = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
nmi_enable = a2 & 2;
interrupt_enable_w(0LL, a2 & 4);
coin_counter_w(0LL, (a2 >> 3) & 1);
return coin_counter_w(1LL, (a2 & 0x10) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
if ( (a2 & 1) != flipscreen )
{
flipscreen = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
nmi_enable = a2 & 2;
interrupt_enable_w(0LL, a2 & 4);
coin_counter_w(0LL, (a2 >> 3) & 1);
return coin_counter_w(1LL, (a2 & 0x10) != 0);
}

original_code:
void yiear_control_w(offs_t offset,data_t data)
{
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 nmi_enable = data & 0x02;
 interrupt_enable_w(0, data & 0x04);
 coin_counter_w(0, (data >> 3) & 0x01);
 coin_counter_w(1, (data >> 4) & 0x01);
}

canonical_original_code:
void yiear_control_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 nmi_enable = data & 0x02;
 interrupt_enable_w(0, data & 0x04);
 coin_counter_w(0, (data >> 3) & 0x01);
 coin_counter_w(1, (data >> 4) & 0x01);
}


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

result = 4LL;
if ( !nmi_enable )
result = ignore_interrupt();
return result;
}

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

result = 4LL;
if ( !nmi_enable )
result = ignore_interrupt();
return result;
}

original_code:
int yiear_nmi_interrupt(void)
{
 return nmi_enable ? 4 : ignore_interrupt();
}

canonical_original_code:
int yiear_nmi_interrupt()
{
 return nmi_enable ? 4 : ignore_interrupt();
}


decompiled_code:
void *__fastcall yiear_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
unsigned int v4; // edi
int v5; // er10
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // rsi
void *result; // rax
int v10; // ebp
__int64 v11; // rbx
__int64 v12; // r9
int v13; // ecx

v2 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
v8 = v3 - 1;
if ( *(_BYTE *)(dirtybuffer + v3 - 1) || *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
*(_BYTE *)(dirtybuffer + v8) = 0;
v4 = ((((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27) + (unsigned __int8)(v2 / 2)) & 0x1F)
- ((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27);
v5 = v2 / 64;
v6 = *(_BYTE *)(videoram + v8) & 0x80;
v7 = *(_BYTE *)(videoram + v8) & 0x40;
if ( flipscreen )
{
v4 = 31
- (((((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27) + (unsigned __int8)(v2 / 2)) & 0x1F)
- ((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27));
v5 = 31 - v2 / 64;
v6 = (_DWORD)v6 == 0;
v7 = (_DWORD)v7 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) | (16 * *(unsigned __int8 *)(videoram + v8)) & 0x100u,
0LL,
v6,
v7,
8 * v4,
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v10 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v11 = v10 + 1LL;
do
{
v13 = *(unsigned __int8 *)(spriteram + v11);
v12 = *(_BYTE *)(spriteram + v11 - 1) & 0x80;
if ( flipscreen )
v12 = (_DWORD)v12 == 0;
else
v13 = 240 - v13;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram_2 + v11)
+ ((unsigned __int8)(*(_BYTE *)(spriteram + v11 - 1) & 1) << 8),
0LL,
~*(_BYTE *)(spriteram + v11 - 1) & 0x40,
v12,
*(unsigned __int8 *)(spriteram_2 + v11 - 1),
(unsigned int)(v10 < 38) + v13,
Machine + 776LL,
2LL,
0LL);
v11 -= 2LL;
v10 -= 2;
}
while ( v10 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
unsigned int v4; // edi
int v5; // er10
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // rsi
void *result; // rax
int v10; // ebp
__int64 v11; // rbx
__int64 v12; // r9
int v13; // ecx

v2 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
v8 = v3 - 1;
if ( *(_BYTE *)(dirtybuffer + v3 - 1) || *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
*(_BYTE *)(dirtybuffer + v8) = 0;
v4 = ((((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27) + (unsigned __int8)(v2 / 2)) & 0x1F)
- ((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27);
v5 = v2 / 64;
v6 = *(_BYTE *)(videoram + v8) & 0x80;
v7 = *(_BYTE *)(videoram + v8) & 0x40;
if ( flipscreen )
{
v4 = 31
- (((((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27) + (unsigned __int8)(v2 / 2)) & 0x1F)
- ((unsigned int)((int)(v2 + ((unsigned int)v2 >> 31)) >> 31) >> 27));
v5 = 31 - v2 / 64;
v6 = (_DWORD)v6 == 0;
v7 = (_DWORD)v7 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) | (16 * *(unsigned __int8 *)(videoram + v8)) & 0x100u,
0LL,
v6,
v7,
8 * v4,
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v10 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v11 = v10 + 1LL;
do
{
v13 = *(unsigned __int8 *)(spriteram + v11);
v12 = *(_BYTE *)(spriteram + v11 - 1) & 0x80;
if ( flipscreen )
v12 = (_DWORD)v12 == 0;
else
v13 = 240 - v13;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram_2 + v11)
+ ((unsigned __int8)(*(_BYTE *)(spriteram + v11 - 1) & 1) << 8),
0LL,
~*(_BYTE *)(spriteram + v11 - 1) & 0x40,
v12,
*(unsigned __int8 *)(spriteram_2 + v11 - 1),
(unsigned int)(v10 < 38) + v13,
Machine + 776LL,
2LL,
0LL);
v11 -= 2LL;
v10 -= 2;
}
while ( v10 >= 0 );
}
return result;
}

original_code:
void yiear_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs + 1])
  {
   int sx,sy,flipx,flipy;
   dirtybuffer[offs] = dirtybuffer[offs + 1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   flipx = videoram[offs] & 0x80;
   flipy = videoram[offs] & 0x40;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
    videoram[offs + 1] | ((videoram[offs] & 0x10) << 4),
    0,
    flipx,flipy,
    8*sx,8*sy,
    0,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  int sx,sy,flipx,flipy;
  sy = 240 - spriteram[offs + 1];
  sx = spriteram_2[offs];
  flipx = ~spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  if (flipscreen)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  if (offs < 0x26)
  {
   sy++;
  }
  drawgfx(bitmap,Machine->gfx[1],
   spriteram_2[offs + 1] + 256 * (spriteram[offs] & 1),
   0,
   flipx,flipy,
   sx,sy,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void yiear_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs + 1])
  {
   int sx; int sy; int flipx; int flipy;
   dirtybuffer[offs] = dirtybuffer[offs + 1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   flipx = videoram[offs] & 0x80;
   flipy = videoram[offs] & 0x40;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
    videoram[offs + 1] | ((videoram[offs] & 0x10) << 4),
    0,
    flipx,flipy,
    8*sx,8*sy,
    0,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  int sx; int sy; int flipx; int flipy;
  sy = 240 - spriteram[offs + 1];
  sx = spriteram_2[offs];
  flipx = ~spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  if (flipscreen)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  if (offs < 0x26)
  {
   sy++;
  }
  drawgfx(bitmap,Machine->gfx[1],
   spriteram_2[offs + 1] + 256 * (spriteram[offs] & 1),
   0,
   flipx,flipy,
   sx,sy,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 yiear_speech_st_w()
{
VLM5030_ST(1LL);
return VLM5030_ST(0LL);
}

canonical_decompiled_code:
__int64 func4()
{
VLM5030_ST(1LL);
return VLM5030_ST(0LL);
}

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

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


decompiled_code:
int yiear_speech_r()
{
return rand();
}

canonical_decompiled_code:
int func5()
{
return rand();
}

original_code:
static data_t yiear_speech_r(offs_t offset)
{
 return rand();
 if (VLM5030_BSY()) return 1;
 else return 0;
}

canonical_original_code:
static unsigned int yiear_speech_r(unsigned int offset)
{
 return rand();
 if (VLM5030_BSY()) return 1;
 else return 0;
}


decompiled_code:
__int64 __fastcall atetris_slapstic_r(unsigned int a1)
{
int v1; // eax

if ( slapstic_nextbank != -1 )
{
slapstic_bank = slapstic_nextbank;
slapstic_nextbank = -1;
}
v1 = a1 & 0xFF00;
if ( v1 == 0x2000 || v1 == 13568 )
{
if ( a1 == 0x2000 )
{
slapstic_75xxcnt = 0;
slapstic_last60xx = 0;
slapstic_primed = 1;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}
if ( a1 > 0x34FF )
{
++slapstic_75xxcnt;
slapstic_last75xx = (unsigned __int8)a1;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}
if ( slapstic_primed )
{
if ( (_BYTE)a1 == 0xA0 )
{
if ( slapstic_last60xx == 176 )
slapstic_nextbank = 0x4000;
else
slapstic_nextbank = 0x10000;
goto LABEL_23;
}
if ( (unsigned __int8)a1 > 0xA0u )
{
if ( (unsigned __int8)a1 == 176 )
{
if ( slapstic_75xxcnt == 6 && slapstic_last60xx == 176 && slapstic_last75xx == 83 )
slapstic_nextbank = 0x4000;
else
slapstic_nextbank = 0x10000;
goto LABEL_23;
}
LABEL_32:
slapstic_primed = 0;
goto LABEL_23;
}
if ( (unsigned __int8)a1 != 128 )
{
if ( (unsigned __int8)a1 == 144 )
{
if ( !slapstic_75xxcnt || slapstic_75xxcnt == 2 && slapstic_last60xx == 144 )
slapstic_nextbank = 0x4000;
else
slapstic_nextbank = 0x10000;
goto LABEL_23;
}
goto LABEL_32;
}
slapstic_nextbank = 0x10000;
}
LABEL_23:
slapstic_last60xx = (unsigned __int8)a1;
slapstic_75xxcnt = 0;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}
slapstic_primed = 0;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
int v1; // eax

if ( slapstic_nextbank != -1 )
{
slapstic_bank = slapstic_nextbank;
slapstic_nextbank = -1;
}
v1 = a1 & 0xFF00;
if ( v1 == 0x2000 || v1 == 13568 )
{
if ( a1 == 0x2000 )
{
slapstic_75xxcnt = 0;
slapstic_last60xx = 0;
slapstic_primed = 1;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}
if ( a1 > 0x34FF )
{
++slapstic_75xxcnt;
slapstic_last75xx = (unsigned __int8)a1;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}
if ( slapstic_primed )
{
if ( (_BYTE)a1 == 0xA0 )
{
if ( slapstic_last60xx == 176 )
slapstic_nextbank = 0x4000;
else
slapstic_nextbank = 0x10000;
goto LABEL_23;
}
if ( (unsigned __int8)a1 > 0xA0u )
{
if ( (unsigned __int8)a1 == 176 )
{
if ( slapstic_75xxcnt == 6 && slapstic_last60xx == 176 && slapstic_last75xx == 83 )
slapstic_nextbank = 0x4000;
else
slapstic_nextbank = 0x10000;
goto LABEL_23;
}
LABEL_32:
slapstic_primed = 0;
goto LABEL_23;
}
if ( (unsigned __int8)a1 != 128 )
{
if ( (unsigned __int8)a1 == 144 )
{
if ( !slapstic_75xxcnt || slapstic_75xxcnt == 2 && slapstic_last60xx == 144 )
slapstic_nextbank = 0x4000;
else
slapstic_nextbank = 0x10000;
goto LABEL_23;
}
goto LABEL_32;
}
slapstic_nextbank = 0x10000;
}
LABEL_23:
slapstic_last60xx = (unsigned __int8)a1;
slapstic_75xxcnt = 0;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}
slapstic_primed = 0;
return *(unsigned __int8 *)(memory_region(129LL) + slapstic_bank + a1);
}

original_code:
data_t atetris_slapstic_r(offs_t offset)
{
    if (slapstic_nextbank != -1)
    {
        slapstic_bank = slapstic_nextbank;
        slapstic_nextbank = -1;
    }
    if ((offset & 0xff00) == 0x2000 ||
        (offset & 0xff00) == 0x3500)
    {
        if (offset == 0x2000)
        {
            slapstic_75xxcnt = 0;
            slapstic_last60xx = 0;
            slapstic_primed = 1;
        }
        else if (offset >= 0x3500)
        {
            slapstic_75xxcnt++;
            slapstic_last75xx = (offset & 0xff);
        }
        else
        {
            if (slapstic_primed)
            switch (offset & 0xff)
            {
            case 0x80:
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            case 0x90:
                if ((slapstic_75xxcnt == 0) ||
                    (slapstic_75xxcnt == 2 && slapstic_last60xx == 0x90))
                {
                    slapstic_nextbank = 0x4000;
                }
                else
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            case 0xa0:
                if (slapstic_last60xx == 0xb0)
                {
                    slapstic_nextbank = 0x4000;
                }
                else
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            case 0xb0:
                if (slapstic_75xxcnt == 6 && slapstic_last60xx == 0xb0 &&
                    slapstic_last75xx == 0x53)
                {
                    slapstic_nextbank = 0x4000;
                }
                else
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            default:
                slapstic_primed = 0;
            }
            slapstic_last60xx = (offset & 0xff);
            slapstic_75xxcnt = 0;
        }
    }
    else
    {
        slapstic_primed = 0;
    }
    return memory_region(REGION_CPU1)[slapstic_bank + offset];
}

canonical_original_code:
unsigned int atetris_slapstic_r(unsigned int offset)
{
    if (slapstic_nextbank != -1)
    {
        slapstic_bank = slapstic_nextbank;
        slapstic_nextbank = -1;
    }
    if ((offset & 0xff00) == 0x2000 ||
        (offset & 0xff00) == 0x3500)
    {
        if (offset == 0x2000)
        {
            slapstic_75xxcnt = 0;
            slapstic_last60xx = 0;
            slapstic_primed = 1;
        }
        else if (offset >= 0x3500)
        {
            slapstic_75xxcnt++;
            slapstic_last75xx = (offset & 0xff);
        }
        else
        {
            if (slapstic_primed)
            switch (offset & 0xff)
            {
            case 0x80:
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            case 0x90:
                if ((slapstic_75xxcnt == 0) ||
                    (slapstic_75xxcnt == 2 && slapstic_last60xx == 0x90))
                {
                    slapstic_nextbank = 0x4000;
                }
                else
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            case 0xa0:
                if (slapstic_last60xx == 0xb0)
                {
                    slapstic_nextbank = 0x4000;
                }
                else
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            case 0xb0:
                if (slapstic_75xxcnt == 6 && slapstic_last60xx == 0xb0 &&
                    slapstic_last75xx == 0x53)
                {
                    slapstic_nextbank = 0x4000;
                }
                else
                {
                    slapstic_nextbank = 0x10000;
                }
                break;
            default:
                slapstic_primed = 0;
            }
            slapstic_last60xx = (offset & 0xff);
            slapstic_75xxcnt = 0;
        }
    }
    else
    {
        slapstic_primed = 0;
    }
    return memory_region(REGION_CPU1)[slapstic_bank + offset];
}


decompiled_code:
__int64 __fastcall atetris_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rbp
size_t v2; // rbx
__int64 v3; // rax
int v4; // ecx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
if ( videoram_size )
{
v1 = 1LL;
v2 = 0LL;
do
{
v4 = v2;
if ( *((_BYTE *)dirtybuffer + v2) || *((_BYTE *)dirtybuffer + v1) )
{
*((_BYTE *)dirtybuffer + v1) = 0;
*((_BYTE *)dirtybuffer + v2) = 0;
v3 = (unsigned int)(4 * ((int)v2 % 128));
if ( (int)v3 <= 335 )
{
if ( (v2 & 0x80000000) != 0LL )
v4 = v2 + 127;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(*(unsigned __int8 *)(videoram + v1) << 8) & 0x700 | (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(videoram + v1) >> 4,
0LL,
0LL,
v3,
(unsigned int)(8 * (v4 >> 7)),
Machine + 776LL,
0LL,
0LL);
}
}
v2 += 2LL;
v1 += 2LL;
}
while ( videoram_size > v2 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
size_t v2; // rbx
__int64 v3; // rax
int v4; // ecx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
if ( videoram_size )
{
v1 = 1LL;
v2 = 0LL;
do
{
v4 = v2;
if ( *((_BYTE *)dirtybuffer + v2) || *((_BYTE *)dirtybuffer + v1) )
{
*((_BYTE *)dirtybuffer + v1) = 0;
*((_BYTE *)dirtybuffer + v2) = 0;
v3 = (unsigned int)(4 * ((int)v2 % 128));
if ( (int)v3 <= 335 )
{
if ( (v2 & 0x80000000) != 0LL )
v4 = v2 + 127;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(*(unsigned __int8 *)(videoram + v1) << 8) & 0x700 | (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(videoram + v1) >> 4,
0LL,
0LL,
v3,
(unsigned int)(8 * (v4 >> 7)),
Machine + 776LL,
0LL,
0LL);
}
}
v2 += 2LL;
v1 += 2LL;
}
while ( videoram_size > v2 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void atetris_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc ())
  memset (dirtybuffer,1,videoram_size);
 for (offs = 0; offs < videoram_size; offs += 2)
 {
  int charcode,sx,sy,color;
  if (!dirtybuffer[offs] && !dirtybuffer[offs + 1]) continue;
  dirtybuffer[offs] = dirtybuffer[offs + 1] = 0;
  sy = 8 * (offs / 128);
  sx = 4 * (offs % 128);
  if (sx >= 42*8) continue;
  charcode = videoram[offs] | ((videoram[offs + 1] & 0x07) << 8);
  color = ((videoram[offs + 1] & 0xf0) >> 4);
  drawgfx(tmpbitmap,Machine->gfx[0],
    charcode,
    color,
    0,0,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void atetris_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc ())
  memset (dirtybuffer,1,videoram_size);
 for (offs = 0; offs < videoram_size; offs += 2)
 {
  int charcode; int sx; int sy; int color;
  if (!dirtybuffer[offs] && !dirtybuffer[offs + 1]) continue;
  dirtybuffer[offs] = dirtybuffer[offs + 1] = 0;
  sy = 8 * (offs / 128);
  sx = 4 * (offs % 128);
  if (sx >= 42*8) continue;
  charcode = videoram[offs] | ((videoram[offs + 1] & 0x07) << 8);
  color = ((videoram[offs + 1] & 0xf0) >> 4);
  drawgfx(tmpbitmap,Machine->gfx[0],
    charcode,
    color,
    0,0,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

variable_types: charcode int

variable_types: color int


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

v0 = memory_region(129LL);
memcpy((void *)(v0 + 0x10000), (const void *)v0, 0x4000uLL);
return memset((void *)v0, 0, 0x4000uLL);
}

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

v0 = memory_region(129LL);
memcpy((void *)(v0 + 0x10000), (const void *)v0, 0x4000uLL);
return memset((void *)v0, 0, 0x4000uLL);
}

original_code:
static void init_atetris(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
    memcpy(&RAM[0x10000], &RAM[0x00000], 0x4000);
    memset(&RAM[0x00000], 0, 0x4000);
}

canonical_original_code:
static void init_atetris()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
    memcpy(&RAM[0x10000], &RAM[0x00000], 0x4000);
    memset(&RAM[0x00000], 0, 0x4000);
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 255, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 255, nvram_size);
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0xff,nvram_size);
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0xff,nvram_size);
 }
}

variable_types:
file
void *


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

result = &zaxxon_vid_type;
zaxxon_vid_type = 1;
return result;
}

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

result = &zaxxon_vid_type;
zaxxon_vid_type = 1;
return result;
}

original_code:
void congo_init_machine(void)
{
 zaxxon_vid_type = 1;
}

canonical_original_code:
void congo_init_machine()
{
 zaxxon_vid_type = 1;
}


decompiled_code:
__int64 __fastcall congo_daio_w(int a1, char a2)
{
__int64 result; // rax
char v3; // bl

if ( a1 == 1 )
{
if ( (a2 & 2) != 0 )
result = sample_start(0LL, 0LL, 0LL);
}
else if ( a1 == 2 )
{
v3 = ~a2;
if ( a2 >= 0 )
{
if ( (v3 & 8) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v3 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (a2 & 1) == 0 )
result = sample_start(4LL, 4LL, 0LL);
}
}
return result;
}

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

if ( a1 == 1 )
{
if ( (a2 & 2) != 0 )
result = sample_start(0LL, 0LL, 0LL);
}
else if ( a1 == 2 )
{
v3 = ~a2;
if ( a2 >= 0 )
{
if ( (v3 & 8) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v3 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (a2 & 1) == 0 )
result = sample_start(4LL, 4LL, 0LL);
}
}
return result;
}

original_code:
void congo_daio_w(offs_t offset,data_t data)
{
 if (offset == 1)
 {
  if (data & 2) sample_start(0,0,0);
 }
 else if (offset == 2)
 {
  data ^= 0xff;
  if (data & 0x80)
  {
   if (data & 8) sample_start(1,1,0);
   if (data & 4) sample_start(2,2,0);
   if (data & 2) sample_start(3,3,0);
   if (data & 1) sample_start(4,4,0);
  }
 }
}

canonical_original_code:
void congo_daio_w(unsigned int offset, unsigned int data)
{
 if (offset == 1)
 {
  if (data & 2) sample_start(0,0,0);
 }
 else if (offset == 2)
 {
  data ^= 0xff;
  if (data & 0x80)
  {
   if (data & 8) sample_start(1,1,0);
   if (data & 4) sample_start(2,2,0);
   if (data & 2) sample_start(3,3,0);
   if (data & 1) sample_start(4,4,0);
  }
 }
}


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

if ( (readinputport(5LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

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

if ( (readinputport(5LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

original_code:
static int congo_interrupt(void)
{
 if (readinputport(5) & 1)
  return nmi_interrupt();
 else return interrupt();
}

canonical_original_code:
static int congo_interrupt()
{
 if (readinputport(5) & 1)
  return nmi_interrupt();
 else return interrupt();
}


crash

decompiled_code:
void crash()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void crash(void)
{
  ((void) (0));
}

canonical_original_code:
static void crash()
{
  ((void) (0));
}


decompiled_code:
__int64 co_active()
{
if ( !co_active_handle )
co_active_handle = (__int64)&co_active_buffer;
return co_active_handle;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !co_active_handle )
co_active_handle = (__int64)&co_active_buffer;
return co_active_handle;
}

original_code:
cothread_t co_active(void)
{
  if (!co_active_handle)
     co_active_handle = &co_active_buffer;
  return co_active_handle;
}

canonical_original_code:
void *co_active()
{
  if (!co_active_handle)
     co_active_handle = &co_active_buffer;
  return co_active_handle;
}

return_type: void *


decompiled_code:
void __fastcall co_delete(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

original_code:
void co_delete(cothread_t handle)
{
   free(handle);
}

canonical_original_code:
void co_delete(void *handle)
{
   free(handle);
}

variable_types:
handle
void *


decompiled_code:
__int64 __fastcall astrocade_sh_start(__int64 a1)
{
unsigned int *v1; // rcx
__int64 result; // rax
float v3; // xmm0_4
__int64 v4; // rdx
_DWORD *v5; // rbp
__int64 v6; // rbx
void *v7; // rax

v1 = *(unsigned int **)(a1 + 8);
intf = (__int64)v1;
result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v3 = *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL);
buffer_len = (int)(float)((float)(int)result / v3);
emulation_rate = (int)(float)(v3 * (float)buffer_len);
v4 = (unsigned int)((int)v1[1] >> 31);
LODWORD(v4) = (int)v1[1] % emulation_rate;
div_by_N_factor = (int)v1[1] / emulation_rate;
channel = mixer_allocate_channels(*v1, v1 + 2, v4);
v5 = (_DWORD *)intf;
if ( *(int *)intf <= 0 )
{
result = 0LL;
}
else
{
v6 = 0LL;
while ( 1 )
{
v7 = malloc(2LL * buffer_len);
*(&astrocade_buffer + v6) = v7;
if ( !v7 )
break;
sample_pos[v6] = 0;
current_count_A[v6] = 0;
current_count_B[v6] = 0;
current_count_C[v6] = 0;
current_count_V[v6] = 0;
current_count_N[v6] = 0;
current_state_A[v6] = 1;
current_state_B[v6] = 1;
current_state_C[v6] = 1;
current_state_V[v6++] = 1;
if ( *v5 <= (int)v6 )
return 0LL;
}
result = 1LL;
if ( (int)v6 - 1 >= 0 )
{
free(*(&astrocade_buffer + (int)v6 - 1));
if ( (int)v6 - 2 >= 0 )
free(*(&astrocade_buffer + (int)v6 - 2));
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int *v1; // rcx
__int64 result; // rax
float v3; // xmm0_4
__int64 v4; // rdx
_DWORD *v5; // rbp
__int64 v6; // rbx
void *v7; // rax

v1 = *(unsigned int **)(a1 + 8);
intf = (__int64)v1;
result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v3 = *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL);
buffer_len = (int)(float)((float)(int)result / v3);
emulation_rate = (int)(float)(v3 * (float)buffer_len);
v4 = (unsigned int)((int)v1[1] >> 31);
LODWORD(v4) = (int)v1[1] % emulation_rate;
div_by_N_factor = (int)v1[1] / emulation_rate;
channel = mixer_allocate_channels(*v1, v1 + 2, v4);
v5 = (_DWORD *)intf;
if ( *(int *)intf <= 0 )
{
result = 0LL;
}
else
{
v6 = 0LL;
while ( 1 )
{
v7 = malloc(2LL * buffer_len);
*(&astrocade_buffer + v6) = v7;
if ( !v7 )
break;
sample_pos[v6] = 0;
current_count_A[v6] = 0;
current_count_B[v6] = 0;
current_count_C[v6] = 0;
current_count_V[v6] = 0;
current_count_N[v6] = 0;
current_state_A[v6] = 1;
current_state_B[v6] = 1;
current_state_C[v6] = 1;
current_state_V[v6++] = 1;
if ( *v5 <= (int)v6 )
return 0LL;
}
result = 1LL;
if ( (int)v6 - 1 >= 0 )
{
free(*(&astrocade_buffer + (int)v6 - 1));
if ( (int)v6 - 2 >= 0 )
free(*(&astrocade_buffer + (int)v6 - 2));
result = 1LL;
}
}
}
return result;
}

original_code:
int astrocade_sh_start(const struct MachineSound *msound)
{
 int i;
 intf = (const struct astrocade_interface*)msound->sound_interface;
 if (Machine->sample_rate == 0)
 {
  return 0;
 }
 buffer_len = Machine->sample_rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 div_by_N_factor = intf->baseclock/emulation_rate;
 channel = mixer_allocate_channels(intf->num,intf->volume);
 for (i = 0;i < intf->num;i++)
 {
  if ((astrocade_buffer[i] = (INT16*)malloc(sizeof(INT16)*buffer_len)) == 0)
  {
   while (--i >= 0) free(astrocade_buffer[i]);
   return 1;
  }
  sample_pos[i] = 0;
  current_count_A[i] = 0;
  current_count_B[i] = 0;
  current_count_C[i] = 0;
  current_count_V[i] = 0;
  current_count_N[i] = 0;
  current_state_A[i] = 1;
  current_state_B[i] = 1;
  current_state_C[i] = 1;
  current_state_V[i] = 1;
 }
 return 0;
}

canonical_original_code:
int astrocade_sh_start(struct MachineSound *msound)
{
 int i;
 intf = (struct astrocade_interface *)msound->sound_interface;
 if (Machine->sample_rate == 0)
 {
  return 0;
 }
 buffer_len = Machine->sample_rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 div_by_N_factor = intf->baseclock/emulation_rate;
 channel = mixer_allocate_channels(intf->num,intf->volume);
 for (i = 0;i < intf->num;i++)
 {
  if ((astrocade_buffer[i] = (short *)malloc(sizeof(INT16)*buffer_len)) == 0)
  {
   while (--i >= 0) free(astrocade_buffer[i]);
   return 1;
  }
  sample_pos[i] = 0;
  current_count_A[i] = 0;
  current_count_B[i] = 0;
  current_count_C[i] = 0;
  current_count_V[i] = 0;
  current_count_N[i] = 0;
  current_state_A[i] = 1;
  current_state_B[i] = 1;
  current_state_C[i] = 1;
  current_state_V[i] = 1;
 }
 return 0;
}

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

user_defined_types: struct astrocade_interface { int num; int baseclock; int volume[2]; }


decompiled_code:
void astrocade_sh_stop()
{
int *v0; // rbx

v0 = (int *)intf;
if ( *(int *)intf > 0 )
{
free(astrocade_buffer);
if ( *v0 > 1 )
free(ptr);
}
}

canonical_decompiled_code:
void func1()
{
int *v0; // rbx

v0 = (int *)intf;
if ( *(int *)intf > 0 )
{
free(astrocade_buffer);
if ( *v0 > 1 )
free(ptr);
}
}

original_code:
void astrocade_sh_stop(void)
{
 int i;
 for (i = 0;i < intf->num;i++){
  free(astrocade_buffer[i]);
 }
}

canonical_original_code:
void astrocade_sh_stop()
{
 int i;
 for (i = 0;i < intf->num;i++){
  free(astrocade_buffer[i]);
 }
}


decompiled_code:
__int64 astrocade_sh_update()
{
__int64 result; // rax
__int64 v1; // rbx
int v2; // ebp

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0LL;
do
{
v2 = buffer_len;
astrocade_update(v1, buffer_len);
sample_pos[v1] = 0;
mixer_play_streamed_sample_16(
(unsigned int)(channel + v1),
*(&astrocade_buffer + v1),
(unsigned int)(2 * v2),
(unsigned int)emulation_rate);
++v1;
result = intf;
}
while ( *(_DWORD *)intf > (int)v1 );
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 v1; // rbx
int v2; // ebp

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0LL;
do
{
v2 = buffer_len;
astrocade_update(v1, buffer_len);
sample_pos[v1] = 0;
mixer_play_streamed_sample_16(
(unsigned int)(channel + v1),
*(&astrocade_buffer + v1),
(unsigned int)(2 * v2),
(unsigned int)emulation_rate);
++v1;
result = intf;
}
while ( *(_DWORD *)intf > (int)v1 );
}
}
return result;
}

original_code:
void astrocade_sh_update(void)
{
 int num;
 if (Machine->sample_rate == 0 ) return;
 for (num = 0;num < intf->num;num++)
 {
  astrocade_update(num, buffer_len);
  sample_pos[num] = 0;
  mixer_play_streamed_sample_16(channel+num,astrocade_buffer[num],2*buffer_len,emulation_rate);
 }
}

canonical_original_code:
void astrocade_sh_update()
{
 int num;
 if (Machine->sample_rate == 0 ) return;
 for (num = 0;num < intf->num;num++)
 {
  astrocade_update(num, buffer_len);
  sample_pos[num] = 0;
  mixer_play_streamed_sample_16(channel+num,astrocade_buffer[num],2*buffer_len,emulation_rate);
 }
}

variable_types: num int


decompiled_code:
void skychut_vh_flipscreen_w()
{
;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
size_t *__fastcall skychut_vh_screenrefresh(__int64 a1, int a2)
{
size_t *result; // rax
int v3; // ebx
__int64 v4; // rbp

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
result = &videoram_size;
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
result = (size_t *)((char *)dirtybuffer + v4);
if ( *((_BYTE *)dirtybuffer + v4) )
{
*(_BYTE *)result = 0;
result = (size_t *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
*(unsigned __int8 *)(colorram + v4),
0LL,
0LL,
(unsigned int)(8 * (v3 % 32)),
(unsigned int)(8 * (v3 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v4;
--v3;
}
while ( v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
size_t *__fastcall func2(__int64 a1, int a2)
{
size_t *result; // rax
int v3; // ebx
__int64 v4; // rbp

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
result = &videoram_size;
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
result = (size_t *)((char *)dirtybuffer + v4);
if ( *((_BYTE *)dirtybuffer + v4) )
{
*(_BYTE *)result = 0;
result = (size_t *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
*(unsigned __int8 *)(colorram + v4),
0LL,
0LL,
(unsigned int)(8 * (v3 % 32)),
(unsigned int)(8 * (v3 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v4;
--v3;
}
while ( v3 >= 0 );
}
return result;
}

original_code:
void skychut_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 = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
      colorram[offs],
     flipscreen,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
}

canonical_original_code:
void skychut_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 = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
      colorram[offs],
     flipscreen,flipscreen,
     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


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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

original_code:
int skychut_interrupt(void)
{
 if (readinputport(2) & 1)
            return nmi_interrupt();
        else
            return interrupt();
}

canonical_original_code:
int skychut_interrupt()
{
 if (readinputport(2) & 1)
            return nmi_interrupt();
        else
            return interrupt();
}


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

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


original_code:
void amidar_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 = (*color_prom >> 6) & 0x01;
  bit1 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
 {
  if (i & 3) (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
  else (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = 0;
 }
}

canonical_original_code:
void amidar_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 = (*color_prom >> 6) & 0x01;
  bit1 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
 {
  if (i & 3) (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
  else (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = 0;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
void *__fastcall amidar_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
void *result; // rax
int v5; // ebp
__int64 v6; // rbx

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(amidar_attributesram + 2 * (v2 % 32) + 1) & 7);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + v6 - 2) & 0x3F,
*(_BYTE *)(spriteram + v6 - 1) & 7);
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
void *result; // rax
int v5; // ebp
__int64 v6; // rbx

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(amidar_attributesram + 2 * (v2 % 32) + 1) & 7);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + v6 - 2) & 0x3F,
*(_BYTE *)(spriteram + v6 - 1) & 7);
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
return result;
}

original_code:
void amidar_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 = offs % 32;
   sy = offs / 32;
   if (flip_screen_x) sx = 31 - sx;
   if (flip_screen_y) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     amidar_attributesram[2 * (offs % 32) + 1] & 0x07,
     flip_screen_x,flip_screen_y,
     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 flipx,flipy,sx,sy;
  sx = (spriteram[offs + 3] + 1) & 0xff;
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flip_screen_x)
  {
   sx = 241 - sx;
   flipx = !flipx;
  }
  if (flip_screen_y)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  if (offs <= 2*4) sy++;
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1] & 0x3f,
    spriteram[offs + 2] & 0x07,
    flipx,flipy,
    sx,sy,
    flip_screen_x ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void amidar_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 = offs % 32;
   sy = offs / 32;
   if (flip_screen_x) sx = 31 - sx;
   if (flip_screen_y) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     amidar_attributesram[2 * (offs % 32) + 1] & 0x07,
     flip_screen_x,flip_screen_y,
     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 flipx; int flipy; int sx; int sy;
  sx = (spriteram[offs + 3] + 1) & 0xff;
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flip_screen_x)
  {
   sx = 241 - sx;
   flipx = !flipx;
  }
  if (flip_screen_y)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  if (offs <= 2*4) sy++;
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1] & 0x3f,
    spriteram[offs + 2] & 0x07,
    flipx,flipy,
    sx,sy,
    flip_screen_x ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sy int


decompiled_code:
__int64 amidar_coina_w()
{
coin_counter_w(0LL);
return coin_counter_w(0LL);
}

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

original_code:
void amidar_coina_w(offs_t offset,data_t data)
{
 coin_counter_w (0, data);
 coin_counter_w (0, 0);
}

canonical_original_code:
void amidar_coina_w(unsigned int offset, unsigned int data)
{
 coin_counter_w (0, data);
 coin_counter_w (0, 0);
}


decompiled_code:
__int64 amidar_coinb_w()
{
coin_counter_w(1LL);
return coin_counter_w(1LL);
}

canonical_decompiled_code:
__int64 func4()
{
coin_counter_w(1LL);
return coin_counter_w(1LL);
}

original_code:
void amidar_coinb_w(offs_t offset,data_t data)
{
 coin_counter_w (1, data);
 coin_counter_w (1, 0);
}

canonical_original_code:
void amidar_coinb_w(unsigned int offset, unsigned int data)
{
 coin_counter_w (1, data);
 coin_counter_w (1, 0);
}


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

layer_colorbase[0] = 48;
dword_4C4 = 0;
dword_4C8 = 16;
sprite_colorbase = 32;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

layer_colorbase[0] = 48;
dword_4C4 = 0;
dword_4C8 = 16;
sprite_colorbase = 32;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int spy_vh_start(void)
{
 layer_colorbase[0] = 48;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int spy_vh_start()
{
 layer_colorbase[0] = 48;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 spy_vh_stop()
{
K052109_vh_stop();
return K051960_vh_stop();
}

original_code:
void spy_vh_stop(void)
{
 K052109_vh_stop();
 K051960_vh_stop();
}


decompiled_code:
__int64 __fastcall spy_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * layer_colorbase[0]) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * layer_colorbase[0]), Machine + 776LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 3LL, 3LL);
K051960_sprites_draw(a1, 2LL, 2LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * layer_colorbase[0]) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * layer_colorbase[0]), Machine + 776LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 3LL, 3LL);
K051960_sprites_draw(a1, 2LL, 2LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

original_code:
void spy_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[16 * layer_colorbase[0]] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[16 * layer_colorbase[0]],&Machine->visible_area);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,1,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,2,0);
 K051960_sprites_draw(bitmap,3,3);
 K051960_sprites_draw(bitmap,2,2);
 K052109_tilemap_draw(bitmap,0,0);
}

canonical_original_code:
void spy_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[16 * layer_colorbase[0]] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[16 * layer_colorbase[0]],&Machine->visible_area);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,1,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,2,0);
 K051960_sprites_draw(bitmap,3,3);
 K051960_sprites_draw(bitmap,2,2);
 K052109_tilemap_draw(bitmap,0,0);
}


decompiled_code:
__int64 init_spy()
{
paletteram = memory_region(129LL) + 163840;
return gfx_untangle();
}

canonical_decompiled_code:
__int64 func6()
{
paletteram = memory_region(129LL) + 163840;
return func5();
}

original_code:
static void init_spy(void)
{
 paletteram = &memory_region(REGION_CPU1)[0x28000];
 gfx_untangle();
}

canonical_original_code:
static void init_spy()
{
 paletteram = &memory_region(REGION_CPU1)[0x28000];
 gfx_untangle();
}