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

v3 = (unsigned int *)&unk_184C;
v4 = 0LL;
LODWORD(result) = 1;
if ( a2 )
{
while ( (_DWORD)result != a2 )
{
result = *v3;
v3 += 3;
v4 = (unsigned int)(v4 + 1);
if ( (_DWORD)result == -1 )
return result;
}
result = (int)v4;
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_184C);
theme_playing_0 = 0;
}
return result;
}

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

v3 = (unsigned int *)&unk_184C;
v4 = 0LL;
LODWORD(result) = 1;
if ( a2 )
{
while ( (_DWORD)result != a2 )
{
result = *v3;
v3 += 3;
v4 = (unsigned int)(v4 + 1);
if ( (_DWORD)result == -1 )
return result;
}
result = (int)v4;
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_184C);
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;
  }
 }
}

variable_types:
data
unsigned int


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:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

return_type: void


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

variable_types:
offset
unsigned int


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

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

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

if ( nmi_enable )
result = 4LL;
else
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();
}

return_type: int


decompiled_code:
void *__fastcall yiear_vh_screenrefresh(__int64 a1)
{
int v2; // er15
__int64 v3; // r12
_BYTE *v4; // rdx
int v5; // er10
int v6; // ecx
__int16 v7; // dx
int v8; // eax
__int64 v9; // r8
__int64 v10; // r9
void *result; // rax
int v12; // er14
__int64 v13; // r15
int v14; // eax
int v15; // esi
unsigned __int8 v16; // dl
__int64 v17; // rdi
__int64 v18; // r9

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

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
int v2; // er15
__int64 v3; // r12
_BYTE *v4; // rdx
int v5; // er10
int v6; // ecx
__int16 v7; // dx
int v8; // eax
__int64 v9; // r8
__int64 v10; // r9
void *result; // rax
int v12; // er14
__int64 v13; // r15
int v14; // eax
int v15; // esi
unsigned __int8 v16; // dl
__int64 v17; // rdi
__int64 v18; // r9

v2 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v3 = v2;
do
{
v4 = (_BYTE *)(dirtybuffer + v3 + 1);
if ( *(_BYTE *)(dirtybuffer + v3) || *v4 )
{
*v4 = 0;
v5 = flipscreen;
v6 = v2 >> 6;
*(_BYTE *)(dirtybuffer + v3) = 0;
v7 = *(unsigned __int8 *)(videoram + v3);
v8 = (v2 >> 1) & 0x1F;
v9 = *(_BYTE *)(videoram + v3) & 0x80;
v10 = v7 & 0x40;
if ( v5 )
{
v8 = 31 - v8;
v6 = 31 - v6;
v9 = (_DWORD)v9 == 0;
v10 = (_DWORD)v10 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3 + 1) | (16 * v7) & 0x100u,
0LL,
v9,
v10,
(unsigned int)(8 * v8),
(unsigned int)(8 * v6),
0LL,
0LL,
0LL);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v12 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v13 = v12 + 1LL;
do
{
v14 = *(unsigned __int8 *)(spriteram + v13);
v16 = *(_BYTE *)(spriteram + v13 - 1);
v17 = *(unsigned __int8 *)(spriteram_2 + v13 - 1);
v18 = v16 & 0x80;
if ( flipscreen )
v18 = (_DWORD)v18 == 0;
else
v14 = 240 - v14;
v15 = *(unsigned __int8 *)(spriteram_2 + v13);
v13 -= 2LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v15 + ((unsigned __int8)(v16 & 1) << 8),
0LL,
~v16 & 0x40,
v18,
v17,
(unsigned int)(v12 < 38) + v14,
Machine + 776LL,
2LL,
0LL);
v12 -= 2;
}
while ( v12 >= 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: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


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:
// attributes: thunk
int yiear_speech_r(void)
{
return rand();
}

canonical_decompiled_code:
int func5(void)
{
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;
}

return_type: unsigned int


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 )
goto LABEL_18;
if ( (unsigned __int8)a1 == 160 )
{
if ( slapstic_last60xx == 176 )
goto LABEL_25;
}
else
{
if ( (unsigned __int8)a1 > 0xA0u )
{
if ( (unsigned __int8)a1 == 176 )
{
if ( slapstic_75xxcnt != 6 || slapstic_last60xx != 176 || slapstic_last75xx != 83 )
goto LABEL_17;
goto LABEL_25;
}
LABEL_26:
slapstic_primed = 0;
goto LABEL_18;
}
if ( (unsigned __int8)a1 != 128 )
{
if ( (unsigned __int8)a1 == 144 )
{
if ( slapstic_75xxcnt && (slapstic_75xxcnt != 2 || slapstic_last60xx != 144) )
goto LABEL_17;
LABEL_25:
slapstic_nextbank = 0x4000;
goto LABEL_18;
}
goto LABEL_26;
}
}
LABEL_17:
slapstic_nextbank = 0x10000;
LABEL_18:
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 )
goto LABEL_18;
if ( (unsigned __int8)a1 == 160 )
{
if ( slapstic_last60xx == 176 )
goto LABEL_25;
}
else
{
if ( (unsigned __int8)a1 > 0xA0u )
{
if ( (unsigned __int8)a1 == 176 )
{
if ( slapstic_75xxcnt != 6 || slapstic_last60xx != 176 || slapstic_last75xx != 83 )
goto LABEL_17;
goto LABEL_25;
}
LABEL_26:
slapstic_primed = 0;
goto LABEL_18;
}
if ( (unsigned __int8)a1 != 128 )
{
if ( (unsigned __int8)a1 == 144 )
{
if ( slapstic_75xxcnt && (slapstic_75xxcnt != 2 || slapstic_last60xx != 144) )
goto LABEL_17;
LABEL_25:
slapstic_nextbank = 0x4000;
goto LABEL_18;
}
goto LABEL_26;
}
}
LABEL_17:
slapstic_nextbank = 0x10000;
LABEL_18:
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)
{
size_t v1; // rbx
_BYTE *v2; // rsi
__int64 v3; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
size_t v1; // rbx
_BYTE *v2; // rsi
__int64 v3; // rdx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
if ( videoram_size )
{
v1 = 0LL;
do
{
v2 = (char *)dirtybuffer + v1 + 1;
if ( *((_BYTE *)dirtybuffer + v1) || *v2 )
{
*v2 = 0;
*((_BYTE *)dirtybuffer + v1) = 0;
v3 = 4 * (unsigned int)(v1 & 0x7F);
if ( (int)v3 <= 335 )
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(*(unsigned __int8 *)(videoram + v1 + 1) << 8) & 0x700 | (unsigned int)*(unsigned __int8 *)(videoram + v1),
*(_BYTE *)(videoram + v1 + 1) >> 4,
0LL,
0LL,
v3,
(unsigned int)(8 * ((int)v1 >> 7)),
Machine + 776LL,
0LL,
0LL);
}
v1 += 2LL;
}
while ( videoram_size > v1 );
}
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

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


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

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; // rbp

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, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, 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, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, 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)
{
char v2; // bl
__int64 result; // rax

if ( a1 == 1 )
{
if ( (a2 & 2) != 0 )
result = sample_start(0LL, 0LL, 0LL);
}
else if ( a1 == 2 )
{
v2 = ~a2;
if ( (a2 & 0x80) == 0 )
{
if ( (v2 & 8) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v2 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v2 & 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)
{
char v2; // bl
__int64 result; // rax

if ( a1 == 1 )
{
if ( (a2 & 2) != 0 )
result = sample_start(0LL, 0LL, 0LL);
}
else if ( a1 == 2 )
{
v2 = ~a2;
if ( (a2 & 0x80) == 0 )
{
if ( (v2 & 8) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v2 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v2 & 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:
void *co_active()
{
void *result; // rax

result = (void *)co_active_handle;
if ( !co_active_handle )
{
result = &co_active_buffer;
co_active_handle = (__int64)&co_active_buffer;
}
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

result = (void *)co_active_handle;
if ( !co_active_handle )
{
result = &co_active_buffer;
co_active_handle = (__int64)&co_active_buffer;
}
return result;
}

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:
// attributes: thunk
void co_delete(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func2(void *ptr)
{
free(ptr);
}

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
int v2; // eax
__int64 v4; // rdi
float v5; // xmm2_4
__int64 v6; // rdx
float v7; // xmm0_4
int v8; // eax
__int64 v9; // r12
size_t v10; // rbx
void *v11; // rax
int v12; // [rsp+0h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int *v1; // rcx
int v2; // eax
__int64 v4; // rdi
float v5; // xmm2_4
__int64 v6; // rdx
float v7; // xmm0_4
int v8; // eax
__int64 v9; // r12
size_t v10; // rbx
void *v11; // rax
int v12; // [rsp+0h] [rbp-40h]

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

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 func2()
{
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
int v3; // edi
__int64 v4; // rsi
__int64 v5; // rdi

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

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
__int64 v1; // rbx
int v2; // ebp
int v3; // edi
__int64 v4; // rsi
__int64 v5; // rdi

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = *(unsigned int *)intf;
if ( (int)result > 0 )
{
v1 = 0LL;
do
{
v2 = buffer_len;
func0(v1, buffer_len);
v3 = channel;
v4 = (__int64)*(&astrocade_buffer + v1);
sample_pos[v1] = 0;
v5 = (unsigned int)(v1++ + v3);
mixer_play_streamed_sample_16(v5, v4, (unsigned int)(2 * v2), (unsigned int)emulation_rate);
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:
data
unsigned int


decompiled_code:
void __fastcall skychut_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // rcx
__int64 v5; // rdx
char v6; // al
__int64 v7; // [rsp-28h] [rbp-50h]

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
while ( !*((_BYTE *)dirtybuffer + v3) )
{
--v2;
--v3;
if ( v2 == -1 )
return;
}
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(unsigned __int8 *)(colorram + v3);
v5 = *(unsigned __int8 *)(videoram + v3--);
v7 = (unsigned int)(8 * (v2 >> 5));
v6 = v2--;
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v5, v4, 0LL, 0LL, 8 * (v6 & 0x1Fu), v7, Machine + 776LL, 0LL, 0LL);
}
while ( v2 != -1 );
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // rcx
__int64 v5; // rdx
char v6; // al
__int64 v7; // [rsp-28h] [rbp-50h]

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
while ( !*((_BYTE *)dirtybuffer + v3) )
{
--v2;
--v3;
if ( v2 == -1 )
return;
}
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(unsigned __int8 *)(colorram + v3);
v5 = *(unsigned __int8 *)(videoram + v3--);
v7 = (unsigned int)(8 * (v2 >> 5));
v6 = v2--;
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v5, v4, 0LL, 0LL, 8 * (v6 & 0x1Fu), v7, Machine + 776LL, 0LL, 0LL);
}
while ( v2 != -1 );
}
}

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


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 func2()
{
__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)
{
__int64 v2; // rbp
int v3; // er12
__int64 v4; // r13
void *result; // rax
int v6; // er12
__int64 v7; // r15
char v8; // r10
char v9; // dl

v2 = a1;
if ( a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
else
{
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
*(_BYTE *)(amidar_attributesram + 2 * (v3 & 0x1F) + 1) & 7);
}
--v3;
--v4;
}
while ( v3 != -1 );
v2 = a1;
LABEL_8:
copybitmap(v2, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6 + 3LL;
do
{
v9 = *(_BYTE *)(spriteram + v7 - 2);
v8 = *(_BYTE *)(spriteram + v7 - 1);
v7 -= 4LL;
result = (void *)drawgfx(v2, *(_QWORD *)(Machine + 520LL), v9 & 0x3F, v8 & 7);
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rbp
int v3; // er12
__int64 v4; // r13
void *result; // rax
int v6; // er12
__int64 v7; // r15
char v8; // r10
char v9; // dl

v2 = a1;
if ( a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
else
{
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
*(_BYTE *)(amidar_attributesram + 2 * (v3 & 0x1F) + 1) & 7);
}
--v3;
--v4;
}
while ( v3 != -1 );
v2 = a1;
LABEL_8:
copybitmap(v2, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6 + 3LL;
do
{
v9 = *(_BYTE *)(spriteram + v7 - 2);
v8 = *(_BYTE *)(spriteram + v7 - 1);
v7 -= 4LL;
result = (void *)drawgfx(v2, *(_QWORD *)(Machine + 520LL), v9 & 0x3F, v8 & 7);
v6 -= 4;
}
while ( v6 >= 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);
 }
}


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

variable_types:
offset
unsigned int


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; // er8
__int64 result; // rax

layer_colorbase = 48LL;
dword_510 = 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; // er8
__int64 result; // rax

layer_colorbase = 48LL;
dword_510 = 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 * (int)layer_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * (_DWORD)layer_colorbase), 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 * (int)layer_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * (_DWORD)layer_colorbase), 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);
}

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


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


decompiled_code:
__int64 spy_interrupt()
{
if ( !(unsigned int)K052109_is_IRQ_enabled() )
return ignore_interrupt();
if ( (unsigned int)cpu_getiloops() )
return 2LL;
return interrupt();
}

canonical_decompiled_code:
__int64 func11()
{
if ( !(unsigned int)K052109_is_IRQ_enabled() )
return ignore_interrupt();
if ( (unsigned int)cpu_getiloops() )
return 2LL;
return interrupt();
}

original_code:
static int spy_interrupt(void)
{
 if (K052109_is_IRQ_enabled())
 {
  if (cpu_getiloops()) return 2;
  else return interrupt();
 }
 else return ignore_interrupt();
}

canonical_original_code:
static int spy_interrupt()
{
 if (K052109_is_IRQ_enabled())
 {
  if (cpu_getiloops()) return 2;
  else return interrupt();
 }
 else return ignore_interrupt();
}


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

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

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

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


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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = K052109_set_RMRD_line((a2 >> 2) & 1);
rambank = a2 & 0x10;
return result;
}

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = K052109_set_RMRD_line((a2 >> 2) & 1);
rambank = a2 & 0x10;
return result;
}

original_code:
static void spy_3f90_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x04) ? 1 : 0);
 rambank = data & 0x10;
}

canonical_original_code:
static void spy_3f90_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x04) ? 1 : 0);
 rambank = data & 0x10;
}


decompiled_code:
__int64 __fastcall spy_bankedram1_r(unsigned int a1)
{
__int64 result; // rax

if ( rambank )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
__int64 result; // rax

if ( rambank )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

original_code:
static data_t spy_bankedram1_r(offs_t offset)
{
 if (!rambank) return ram[offset];
 else return paletteram_r(offset);
}

canonical_original_code:
static unsigned int spy_bankedram1_r(unsigned int offset)
{
 if (!rambank) return ram[offset];
 else return paletteram_r(offset);
}


decompiled_code:
__int64 __fastcall tile_callback(int a1, int a2, _DWORD *a3, int *a4)
{
__int64 result; // rax

tile_info[5] = (*a4 >> 5) & 1;
*a3 |= ((unsigned __int16)*a4 << 9) & 0x1800 | ((unsigned __int16)*a4 << 6) & 0x400 | ((unsigned __int16)*a4 << 8) & 0x300 | (a2 << 13);
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 tile_info.flags = (*color & 0x20) ? 0x01 : 0;
 *code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9)
   | (bank << 13);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 tile_info.flags = (*color & 0x20) ? 0x01 : 0;
 *code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9)
   | (bank << 13);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

*a3 = (*a2 >> 4) & 3;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

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

*a3 = (*a2 >> 4) & 3;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

original_code:
static void sprite_callback(int *code,int *color,int *priority,int *shadow)
{
 *priority = (*color & 0x30) >> 4;
 *color = sprite_colorbase + (*color & 0x0f);
}

canonical_original_code:
static void sprite_callback(int *code, int *color, int *priority, int *shadow)
{
 *priority = (*color & 0x30) >> 4;
 *color = sprite_colorbase + (*color & 0x0f);
}

variable_types:
priority
int *

variable_types:
shadow
int *


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

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

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

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


decompiled_code:
__int64 __fastcall volume_callback1(int a1)
{
K007232_set_volume(1LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(1LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
K007232_set_volume(1LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(1LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

variable_types: v int


decompiled_code:
__int64 __fastcall volume_callback0(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}


irqhandler

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

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

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

variable_types: linestate int


original_code:
static void sound_bank_w(offs_t offset,data_t data)
{
 unsigned char *rom;
 int bank_A,bank_B;
 rom = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 0) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(0,rom + bank_A,rom + bank_B);
 rom = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 6) & 0x03);
 K007232_bankswitch(1,rom + bank_A,rom + bank_B);
}

canonical_original_code:
static void sound_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *rom;
 int bank_A; int bank_B;
 rom = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 0) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(0,rom + bank_A,rom + bank_B);
 rom = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 6) & 0x03);
 K007232_bankswitch(1,rom + bank_A,rom + bank_B);
}

variable_types:
rom
unsigned char *


decompiled_code:
void *__fastcall bankswitch_w(__int64 a1, char a2)
{
__int64 v2; // rbp
int v3; // ebx
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
if ( (a2 & 1) == 0 )
usrintf_showmessage("bankswitch RAM bank 0");
if ( (a2 & 0x10) != 0 )
v3 = (a2 & 6) + 32;
else
v3 = (a2 & 0xE) + 16;
cpu_bankbase[1] = v2 + (v3 << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func14(__int64 a1, char a2)
{
__int64 v2; // rbp
int v3; // ebx
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
if ( (a2 & 1) == 0 )
usrintf_showmessage("bankswitch RAM bank 0");
if ( (a2 & 0x10) != 0 )
v3 = (a2 & 6) + 32;
else
v3 = (a2 & 0xE) + 16;
cpu_bankbase[1] = v2 + (v3 << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int offs;
if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
 if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
 else offs = 0x10000 + (data & 0x0e) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&rom[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int offs;
if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
 if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
 else offs = 0x10000 + (data & 0x0e) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&rom[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: offs int


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

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

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

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


decompiled_code:
void zerozone_vh_stop()
{
free(video_dirty);
}

canonical_decompiled_code:
void func1()
{
free(video_dirty);
}

original_code:
void zerozone_vh_stop(void)
{
 free(video_dirty);
}


decompiled_code:
__int64 zerozone_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 result; // rax

v0 = videoram_size >> 1;
v1 = malloc(videoram_size >> 1);
video_dirty = v1;
if ( v1 )
{
memset(v1, 1, v0);
result = 0LL;
}
else
{
zerozone_vh_stop();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
size_t v0; // r12
void *v1; // rax
__int64 result; // rax

v0 = videoram_size >> 1;
v1 = malloc(videoram_size >> 1);
video_dirty = v1;
if ( v1 )
{
memset(v1, 1, v0);
result = 0LL;
}
else
{
func1();
result = 1LL;
}
return result;
}

original_code:
int zerozone_vh_start(void)
{
 video_dirty = (unsigned char*)malloc(videoram_size/2);
 if (!video_dirty)
 {
  zerozone_vh_stop();
  return 1;
 }
 memset(video_dirty,1,videoram_size/2);
 return 0;
}

canonical_original_code:
int zerozone_vh_start()
{
 video_dirty = (unsigned char *)malloc(videoram_size/2);
 if (!video_dirty)
 {
  zerozone_vh_stop();
  return 1;
 }
 memset(video_dirty,1,videoram_size/2);
 return 0;
}


decompiled_code:
__int64 __fastcall zerozone_sound_w(__int64 a1, __int16 a2)
{
soundlatch_w(a1, HIBYTE(a2));
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int16 a2)
{
soundlatch_w(a1, HIBYTE(a2));
return cpu_cause_interrupt(1LL, 255LL);
}

original_code:
void zerozone_sound_w(offs_t offset,data_t data)
{
 soundlatch_w (offset, (data >> 8) & 0xff);
 cpu_cause_interrupt (1, 0xff);
}

canonical_original_code:
void zerozone_sound_w(unsigned int offset, unsigned int data)
{
 soundlatch_w (offset, (data >> 8) & 0xff);
 cpu_cause_interrupt (1, 0xff);
}


decompiled_code:
__int64 __fastcall zerozone_input_r(unsigned int a1)
{
int v1; // ebx

if ( a1 == 8 )
return (unsigned int)readinputport(4LL) << 8;
if ( a1 > 8 )
{
if ( a1 == 10 )
return readinputport(3LL);
return 0LL;
}
if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
return v1 | ((unsigned int)readinputport(2LL) << 8);
}
return 0LL;
}
return readinputport(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
int v1; // ebx

if ( a1 == 8 )
return (unsigned int)readinputport(4LL) << 8;
if ( a1 > 8 )
{
if ( a1 == 10 )
return readinputport(3LL);
return 0LL;
}
if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
return v1 | ((unsigned int)readinputport(2LL) << 8);
}
return 0LL;
}
return readinputport(0LL);
}

original_code:
static data_t zerozone_input_r(offs_t offset)
{
 switch (offset)
 {
  case 0x00:
   return readinputport(0);
  case 0x02:
   return (readinputport(1) | (readinputport(2) << 8));
  case 0x08:
   return (readinputport(4) << 8);
  case 0x0a:
   return readinputport(3);
 }
 return 0x00;
}

canonical_original_code:
static unsigned int zerozone_input_r(unsigned int offset)
{
 switch (offset)
 {
  case 0x00:
   return readinputport(0);
  case 0x02:
   return (readinputport(1) | (readinputport(2) << 8));
  case 0x08:
   return (readinputport(4) << 8);
  case 0x0a:
   return readinputport(3);
 }
 return 0x00;
}


decompiled_code:
void *__fastcall zerozone_update_palette(__int64 a1, _BYTE *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdi
_WORD *v5; // rax
__int16 v6; // ax
char *v7; // rdi
__int64 v8; // r9
_OWORD *v9; // rdx
int v10; // eax
void *result; // rax
__int128 v12[2]; // [rsp+0h] [rbp-28h] BYREF
char v13; // [rsp+20h] [rbp-8h] BYREF

v12[0] = 0LL;
v12[1] = 0LL;
if ( videoram_size )
{
v4 = *(_QWORD *)(*(_QWORD *)(Machine + 512LL) + 32LL);
v5 = (_WORD *)zerozone_videoram;
a4 = zerozone_videoram + 2LL;
a2 = (_BYTE *)(((videoram_size - 1LL) & 0xFFFFFFFFFFFFFFFELL) + zerozone_videoram + 2LL);
while ( 1 )
{
*((_WORD *)v12 + ((*v5 >> 12) & 0xF)) |= *(_DWORD *)(v4 + 4LL * (*v5 & 0xFFF));
v5 = (_WORD *)a4;
if ( a2 == (_BYTE *)a4 )
break;
a4 += 2LL;
}
v6 = v12[0];
}
else
{
v6 = 0;
}
v7 = (char *)v12;
v8 = 0LL;
while ( 1 )
{
v9 = (_OWORD *)(v8 + palette_used_colors);
if ( v6 )
break;
v7 += 2;
v8 += 16LL;
*v9 = 0LL;
if ( &v13 == v7 )
goto LABEL_13;
LABEL_8:
v6 = *(_WORD *)v7;
}
*(_BYTE *)v9 = 7;
LODWORD(a4) = 1;
v9 = (_OWORD *)(v8 + 1);
do
{
v10 = (int)*(unsigned __int16 *)v7 >> a4;
a2 = (char *)v9 + palette_used_colors;
a4 = (unsigned int)(a4 + 1);
v9 = (_OWORD *)((char *)v9 + 1);
*a2 = -(v10 & 1) & 3;
}
while ( (_DWORD)a4 != 16 );
v7 += 2;
v8 += 16LL;
if ( &v13 != v7 )
goto LABEL_8;
LABEL_13:
result = (void *)palette_recalc(v7, a2, v9, a4, &palette_used_colors, v8);
if ( result )
result = memset(video_dirty, 1, videoram_size >> 1);
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, _BYTE *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdi
_WORD *v5; // rax
__int16 v6; // ax
char *v7; // rdi
__int64 v8; // r9
_OWORD *v9; // rdx
int v10; // eax
void *result; // rax
__int128 v12[2]; // [rsp+0h] [rbp-28h] BYREF
char v13; // [rsp+20h] [rbp-8h] BYREF

v12[0] = 0LL;
v12[1] = 0LL;
if ( videoram_size )
{
v4 = *(_QWORD *)(*(_QWORD *)(Machine + 512LL) + 32LL);
v5 = (_WORD *)zerozone_videoram;
a4 = zerozone_videoram + 2LL;
a2 = (_BYTE *)(((videoram_size - 1LL) & 0xFFFFFFFFFFFFFFFELL) + zerozone_videoram + 2LL);
while ( 1 )
{
*((_WORD *)v12 + ((*v5 >> 12) & 0xF)) |= *(_DWORD *)(v4 + 4LL * (*v5 & 0xFFF));
v5 = (_WORD *)a4;
if ( a2 == (_BYTE *)a4 )
break;
a4 += 2LL;
}
v6 = v12[0];
}
else
{
v6 = 0;
}
v7 = (char *)v12;
v8 = 0LL;
while ( 1 )
{
v9 = (_OWORD *)(v8 + palette_used_colors);
if ( v6 )
break;
v7 += 2;
v8 += 16LL;
*v9 = 0LL;
if ( &v13 == v7 )
goto LABEL_13;
LABEL_8:
v6 = *(_WORD *)v7;
}
*(_BYTE *)v9 = 7;
LODWORD(a4) = 1;
v9 = (_OWORD *)(v8 + 1);
do
{
v10 = (int)*(unsigned __int16 *)v7 >> a4;
a2 = (char *)v9 + palette_used_colors;
a4 = (unsigned int)(a4 + 1);
v9 = (_OWORD *)((char *)v9 + 1);
*a2 = -(v10 & 1) & 3;
}
while ( (_DWORD)a4 != 16 );
v7 += 2;
v8 += 16LL;
if ( &v13 != v7 )
goto LABEL_8;
LABEL_13:
result = (void *)palette_recalc(v7, a2, v9, a4, &palette_used_colors, v8);
if ( result )
result = memset(video_dirty, 1, videoram_size >> 1);
return result;
}

original_code:
void zerozone_update_palette (void)
{
 unsigned short palette_map[16];
 int i;
 memset (palette_map, 0, sizeof (palette_map));
 for (i = 0; i < videoram_size; i += 2)
 {
  int tile, color;
  tile = (*(UINT16 *)(&zerozone_videoram[i])) & 0xfff;
  color = ((*(UINT16 *)(&zerozone_videoram[i])) & 0xf000) >> 12;
  palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
 }
 for (i = 0;i < 16;i++)
 {
  int usage = palette_map[i];
  int j;
  if (usage)
  {
   palette_used_colors[i * 16 + 0] = (4|(1|2));
   for (j = 1; j < 16; j++)
    if (palette_map[i] & (1 << j))
     palette_used_colors[i * 16 + j] = (1|2);
    else
     palette_used_colors[i * 16 + j] = 0;
  }
  else
   memset(&palette_used_colors[i * 16],0,16);
 }
 if (palette_recalc ())
  memset(video_dirty,1,videoram_size/2);
}

canonical_original_code:
void zerozone_update_palette()
{
 unsigned short palette_map[16];
 int i;
 memset (palette_map, 0, sizeof (palette_map));
 for (i = 0; i < videoram_size; i += 2)
 {
  int tile; int color;
  tile = (*(unsigned short *)(&zerozone_videoram[i])) & 0xfff;
  color = ((*(unsigned short *)(&zerozone_videoram[i])) & 0xf000) >> 12;
  palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
 }
 for (i = 0;i < 16;i++)
 {
  int usage = palette_map[i];
  int j;
  if (usage)
  {
   palette_used_colors[i * 16 + 0] = (4|(1|2));
   for (j = 1; j < 16; j++)
    if (palette_map[i] & (1 << j))
     palette_used_colors[i * 16 + j] = (1|2);
    else
     palette_used_colors[i * 16 + j] = 0;
  }
  else
   memset(&palette_used_colors[i * 16],0,16);
 }
 if (palette_recalc ())
  memset(video_dirty,1,videoram_size/2);
}

variable_types: i int

variable_types: tile int

variable_types: color int

variable_types: usage int

variable_types: j int


decompiled_code:
void __fastcall nova2001_scroll_x_w(__int64 a1, int a2)
{
nova2001_xscroll = a2;
}

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

original_code:
void nova2001_scroll_x_w(offs_t offset,data_t data)
{
 nova2001_xscroll = data;
}

canonical_original_code:
void nova2001_scroll_x_w(unsigned int offset, unsigned int data)
{
 nova2001_xscroll = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void __fastcall nova2001_scroll_y_w(__int64 a1, int a2)
{
nova2001_yscroll = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
nova2001_yscroll = a2;
}

original_code:
void nova2001_scroll_y_w(offs_t offset,data_t data)
{
 nova2001_yscroll = data;
}

canonical_original_code:
void nova2001_scroll_y_w(unsigned int offset, unsigned int data)
{
 nova2001_yscroll = data;
}


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

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

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

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

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

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


decompiled_code:
int *__fastcall nova2001_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // r15
__int64 v4; // r8
int v5; // edx
int v6; // ecx
int v7; // edx
int v8; // eax
unsigned __int64 v9; // rbx
unsigned __int8 v10; // al
__int64 v11; // rdi
__int64 v12; // r11
char v13; // cl
__int64 v14; // r8
__int64 v15; // r9
int *result; // rax
int v17; // ebx
__int64 v18; // r13
int v19; // eax
int v20; // edx
unsigned int v21; // er11
char v22; // cl
int v23; // [rsp+8h] [rbp-40h] BYREF
int v24[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
v4 = (unsigned int)flipscreen;
*(_BYTE *)(v3 + dirtybuffer) = 0;
v5 = v2 & 0x1F;
v6 = v2 >> 5;
if ( (_DWORD)v4 )
{
v5 = 31 - v5;
v6 = 31 - v6;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 0xF,
v4,
(unsigned int)v4,
(unsigned int)(8 * v5),
(unsigned int)(8 * v6),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v7 = nova2001_xscroll;
v8 = nova2001_yscroll;
if ( !flipscreen )
{
v7 = -nova2001_xscroll;
v8 = -nova2001_yscroll;
}
v23 = v7;
v24[0] = v8;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v23, 1LL, v24, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v9 = 0LL;
do
{
v10 = *(_BYTE *)(spriteram + v9);
if ( (v10 & 0x40) != 0 )
{
v11 = *(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 1));
v12 = *(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 2));
v13 = *(_BYTE *)(spriteram + (unsigned int)(v9 + 3));
v14 = v13 & 0x10;
v15 = v13 & 0x20;
if ( flipscreen )
{
v11 = (unsigned int)(240 - v11);
v12 = (unsigned int)(240 - v12);
v14 = (_DWORD)v14 == 0;
v15 = (_DWORD)v15 == 0;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((v10 >> 7) + 2) & 7) + 512),
v10 & 0x3F,
*(_BYTE *)(spriteram + (unsigned int)(v9 + 3)) & 0xF,
v14,
v15,
v11,
v12,
Machine + 776LL,
2LL,
0LL);
}
v9 += 32LL;
}
while ( spriteram_size > v9 );
}
result = &nova2001_videoram_size;
v17 = nova2001_videoram_size - 1;
if ( nova2001_videoram_size - 1 >= 0 )
{
v18 = v17;
do
{
v19 = v17 & 0x1F;
v20 = v17 >> 5;
if ( flipscreen )
{
v19 = 31 - v19;
v20 = 31 - v20;
}
--v17;
v21 = *(unsigned __int8 *)(nova2001_videoram + v18);
v22 = *(_BYTE *)(nova2001_colorram + v18--);
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v21,
v22 & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v19),
(unsigned int)(8 * v20),
Machine + 776LL,
2LL,
0LL);
}
while ( v17 != -1 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func4(__int64 a1)
{
int v2; // ebx
__int64 v3; // r15
__int64 v4; // r8
int v5; // edx
int v6; // ecx
int v7; // edx
int v8; // eax
unsigned __int64 v9; // rbx
unsigned __int8 v10; // al
__int64 v11; // rdi
__int64 v12; // r11
char v13; // cl
__int64 v14; // r8
__int64 v15; // r9
int *result; // rax
int v17; // ebx
__int64 v18; // r13
int v19; // eax
int v20; // edx
unsigned int v21; // er11
char v22; // cl
int v23; // [rsp+8h] [rbp-40h] BYREF
int v24[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
v4 = (unsigned int)flipscreen;
*(_BYTE *)(v3 + dirtybuffer) = 0;
v5 = v2 & 0x1F;
v6 = v2 >> 5;
if ( (_DWORD)v4 )
{
v5 = 31 - v5;
v6 = 31 - v6;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 0xF,
v4,
(unsigned int)v4,
(unsigned int)(8 * v5),
(unsigned int)(8 * v6),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v7 = nova2001_xscroll;
v8 = nova2001_yscroll;
if ( !flipscreen )
{
v7 = -nova2001_xscroll;
v8 = -nova2001_yscroll;
}
v23 = v7;
v24[0] = v8;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v23, 1LL, v24, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v9 = 0LL;
do
{
v10 = *(_BYTE *)(spriteram + v9);
if ( (v10 & 0x40) != 0 )
{
v11 = *(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 1));
v12 = *(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 2));
v13 = *(_BYTE *)(spriteram + (unsigned int)(v9 + 3));
v14 = v13 & 0x10;
v15 = v13 & 0x20;
if ( flipscreen )
{
v11 = (unsigned int)(240 - v11);
v12 = (unsigned int)(240 - v12);
v14 = (_DWORD)v14 == 0;
v15 = (_DWORD)v15 == 0;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((v10 >> 7) + 2) & 7) + 512),
v10 & 0x3F,
*(_BYTE *)(spriteram + (unsigned int)(v9 + 3)) & 0xF,
v14,
v15,
v11,
v12,
Machine + 776LL,
2LL,
0LL);
}
v9 += 32LL;
}
while ( spriteram_size > v9 );
}
result = &nova2001_videoram_size;
v17 = nova2001_videoram_size - 1;
if ( nova2001_videoram_size - 1 >= 0 )
{
v18 = v17;
do
{
v19 = v17 & 0x1F;
v20 = v17 >> 5;
if ( flipscreen )
{
v19 = 31 - v19;
v20 = 31 - v20;
}
--v17;
v21 = *(unsigned __int8 *)(nova2001_videoram + v18);
v22 = *(_BYTE *)(nova2001_colorram + v18--);
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v21,
v22 & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v19),
(unsigned int)(8 * v20),
Machine + 776LL,
2LL,
0LL);
}
while ( v17 != -1 );
}
return result;
}

original_code:
void nova2001_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs],
     colorram[offs] & 0x0f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx,scrolly;
  if (flipscreen)
  {
   scrollx = nova2001_xscroll;
   scrolly = nova2001_yscroll;
  }
  else
  {
   scrollx = -nova2001_xscroll;
   scrolly = -nova2001_yscroll;
  }
     copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 32)
 {
  if (spriteram[offs+0] & 0x40)
  {
   int sx,sy,flipx,flipy;
   sx = spriteram[offs+1];
   sy = spriteram[offs+2];
   flipx = spriteram[offs+3] & 0x10;
   flipy = spriteram[offs+3] & 0x20;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2 + ((spriteram[offs+0] & 0x80) >> 7)],
     spriteram[offs+0] & 0x3f,
     spriteram[offs+3] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = nova2001_videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    nova2001_videoram[offs],
    nova2001_colorram[offs] & 0x0f,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void nova2001_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs],
     colorram[offs] & 0x0f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx; int scrolly;
  if (flipscreen)
  {
   scrollx = nova2001_xscroll;
   scrolly = nova2001_yscroll;
  }
  else
  {
   scrollx = -nova2001_xscroll;
   scrolly = -nova2001_yscroll;
  }
     copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 32)
 {
  if (spriteram[offs+0] & 0x40)
  {
   int sx; int sy; int flipx; int flipy;
   sx = spriteram[offs+1];
   sy = spriteram[offs+2];
   flipx = spriteram[offs+3] & 0x10;
   flipy = spriteram[offs+3] & 0x20;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2 + ((spriteram[offs+0] & 0x80) >> 7)],
     spriteram[offs+0] & 0x3f,
     spriteram[offs+3] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = nova2001_videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    nova2001_videoram[offs],
    nova2001_colorram[offs] & 0x0f,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: sx int

variable_types: sy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: flipx int

variable_types: flipy int


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

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

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

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

original_code:
void funkybee_gfx_bank_w(offs_t offset,data_t data)
{
 if (data != (gfx_bank & 0x01))
 {
  gfx_bank = data & 0x01;
  memset(dirtybuffer, 1, videoram_size);
 }
}

canonical_original_code:
void funkybee_gfx_bank_w(unsigned int offset, unsigned int data)
{
 if (data != (gfx_bank & 0x01))
 {
  gfx_bank = data & 0x01;
  memset(dirtybuffer, 1, videoram_size);
 }
}


decompiled_code:
__int64 __fastcall funkybee_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r9
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // rax
__int64 i; // rbx
__int64 v7; // r15
__int64 v8; // rdx
__int64 result; // rax
__int64 v10; // [rsp-28h] [rbp-60h]

v1 = 7695LL;
draw_chars(tmpbitmap, a1);
do
{
v2 = *(_BYTE *)(videoram + v1) & 1;
v3 = ((int)*(unsigned __int8 *)(videoram + v1) >> 2) | (32 * *(_BYTE *)(videoram + v1)) & 0x40u;
v4 = *(unsigned __int8 *)(colorram + v1 + 16);
v10 = 224 - (unsigned int)*(unsigned __int8 *)(colorram + v1);
v5 = *(unsigned __int8 *)(videoram + v1-- + 16);
drawgfx(a1, *(_QWORD *)(Machine + 8LL * (gfx_bank + 2) + 512), v3, v4, 0LL, v2, v5, v10, Machine + 776LL, 2LL, 0LL);
}
while ( v1 != 7679 );
for ( i = 7199LL; i != 7167; --i )
{
v7 = (unsigned int)(8 * i - 57344);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + i),
*(_BYTE *)(colorram + 7952LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7952LL),
v7,
0LL,
2LL,
0LL);
v8 = *(unsigned __int8 *)(videoram + i + 256);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
v8,
*(_BYTE *)(colorram + 7953LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7953LL),
v7,
0LL,
2LL,
0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r9
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // rax
__int64 i; // rbx
__int64 v7; // r15
__int64 v8; // rdx
__int64 result; // rax
__int64 v10; // [rsp-28h] [rbp-60h]

v1 = 7695LL;
func2(tmpbitmap, a1);
do
{
v2 = *(_BYTE *)(videoram + v1) & 1;
v3 = ((int)*(unsigned __int8 *)(videoram + v1) >> 2) | (32 * *(_BYTE *)(videoram + v1)) & 0x40u;
v4 = *(unsigned __int8 *)(colorram + v1 + 16);
v10 = 224 - (unsigned int)*(unsigned __int8 *)(colorram + v1);
v5 = *(unsigned __int8 *)(videoram + v1-- + 16);
drawgfx(a1, *(_QWORD *)(Machine + 8LL * (gfx_bank + 2) + 512), v3, v4, 0LL, v2, v5, v10, Machine + 776LL, 2LL, 0LL);
}
while ( v1 != 7679 );
for ( i = 7199LL; i != 7167; --i )
{
v7 = (unsigned int)(8 * i - 57344);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + i),
*(_BYTE *)(colorram + 7952LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7952LL),
v7,
0LL,
2LL,
0LL);
v8 = *(unsigned __int8 *)(videoram + i + 256);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
v8,
*(_BYTE *)(colorram + 7953LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7953LL),
v7,
0LL,
2LL,
0LL);
}
return result;
}

original_code:
void funkybee_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 draw_chars(tmpbitmap, bitmap);
 for (offs = 0x0f; offs >= 0; offs--)
 {
  int sx,sy,code,col,flipy,offs2;
  offs2 = 0x1e00 + offs;
  code = videoram[offs2];
  sx = videoram[offs2 + 0x10];
  sy = 224 - colorram[offs2];
  col = colorram[offs2 + 0x10];
  flipy = code & 0x01;
  drawgfx(bitmap,Machine->gfx[2+gfx_bank],
    (code >> 2) | ((code & 2) << 5),
    col,
    0,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = 0x1f;offs >= 0;offs--)
 {
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1c00],
    colorram[0x1f10] & 0x03,
    0,0,
    videoram[0x1f10],8*offs,
    0,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1d00],
    colorram[0x1f11] & 0x03,
    0,0,
    videoram[0x1f11],8*offs,
    0,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void funkybee_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 draw_chars(tmpbitmap, bitmap);
 for (offs = 0x0f; offs >= 0; offs--)
 {
  int sx; int sy; int code; int col; int flipy; int offs2;
  offs2 = 0x1e00 + offs;
  code = videoram[offs2];
  sx = videoram[offs2 + 0x10];
  sy = 224 - colorram[offs2];
  col = colorram[offs2 + 0x10];
  flipy = code & 0x01;
  drawgfx(bitmap,Machine->gfx[2+gfx_bank],
    (code >> 2) | ((code & 2) << 5),
    col,
    0,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = 0x1f;offs >= 0;offs--)
 {
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1c00],
    colorram[0x1f10] & 0x03,
    0,0,
    videoram[0x1f10],8*offs,
    0,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1d00],
    colorram[0x1f11] & 0x03,
    0,0,
    videoram[0x1f11],8*offs,
    0,TRANSPARENCY_PEN,0);
 }
}

variable_types: code int

variable_types: col int


decompiled_code:
__int64 __fastcall funkybee_input_port_0_r(unsigned int a1)
{
watchdog_reset_r(0LL);
return input_port_0_r(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
watchdog_reset_r(0LL);
return input_port_0_r(a1);
}

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

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


decompiled_code:
__int64 __fastcall draw_chars(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rcx
__int64 v6; // rdx
unsigned __int8 *v7; // rsi
__int64 *v8; // rax
__int64 v10; // [rsp-30h] [rbp-F8h]
char v12[112]; // [rsp+10h] [rbp-B8h] BYREF
__int64 v13[9]; // [rsp+80h] [rbp-48h] BYREF

v2 = 248LL;
do
{
v3 = 248LL;
v4 = (int)((32 * v2) | 0x1F);
do
{
while ( !*(_BYTE *)(v4 + dirtybuffer) )
{
v3 = (unsigned int)(v3 - 8);
--v4;
if ( (_DWORD)v3 == -8 )
goto LABEL_6;
}
*(_BYTE *)(v4 + dirtybuffer) = 0;
v5 = *(_BYTE *)(colorram + v4) & 3;
v6 = *(unsigned __int8 *)(videoram + v4--);
v10 = v3;
v3 = (unsigned int)(v3 - 8);
drawgfx(a1, *(_QWORD *)(Machine + 8LL * gfx_bank + 512), v6, v5, 0LL, 0LL, v10, v2, 0LL, 0LL, 0LL);
}
while ( (_DWORD)v3 != -8 );
LABEL_6:
v2 = (unsigned int)(v2 - 8);
}
while ( (_DWORD)v2 != -8 );
v7 = (unsigned __int8 *)funkyb_row_scroll;
v8 = (__int64 *)v12;
do
{
v8 = (__int64 *)((char *)v8 + 4);
*((_DWORD *)v8 - 1) = -*v7;
}
while ( v13 != v8 );
v13[0] = 0LL;
v13[1] = 0LL;
return copyscrollbitmap(a2, a1, 32LL, v12, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // rcx
__int64 v6; // rdx
unsigned __int8 *v7; // rsi
__int64 *v8; // rax
__int64 v10; // [rsp-30h] [rbp-F8h]
char v12[112]; // [rsp+10h] [rbp-B8h] BYREF
__int64 v13[9]; // [rsp+80h] [rbp-48h] BYREF

v2 = 248LL;
do
{
v3 = 248LL;
v4 = (int)((32 * v2) | 0x1F);
do
{
while ( !*(_BYTE *)(v4 + dirtybuffer) )
{
v3 = (unsigned int)(v3 - 8);
--v4;
if ( (_DWORD)v3 == -8 )
goto LABEL_6;
}
*(_BYTE *)(v4 + dirtybuffer) = 0;
v5 = *(_BYTE *)(colorram + v4) & 3;
v6 = *(unsigned __int8 *)(videoram + v4--);
v10 = v3;
v3 = (unsigned int)(v3 - 8);
drawgfx(a1, *(_QWORD *)(Machine + 8LL * gfx_bank + 512), v6, v5, 0LL, 0LL, v10, v2, 0LL, 0LL, 0LL);
}
while ( (_DWORD)v3 != -8 );
LABEL_6:
v2 = (unsigned int)(v2 - 8);
}
while ( (_DWORD)v2 != -8 );
v7 = (unsigned __int8 *)funkyb_row_scroll;
v8 = (__int64 *)v12;
do
{
v8 = (__int64 *)((char *)v8 + 4);
*((_DWORD *)v8 - 1) = -*v7;
}
while ( v13 != v8 );
v13[0] = 0LL;
v13[1] = 0LL;
return copyscrollbitmap(a2, a1, 32LL, v12, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
static void draw_chars(struct osd_bitmap *_tmpbitmap, struct osd_bitmap *bitmap)
{
 int sx,sy;
 for (sy = 0x1f;sy >= 0;sy--)
 {
  int offs;
  offs = (sy << 8) | 0x1f;
  for (sx = 0x1f;sx >= 0;sx--,offs--)
  {
   if (dirtybuffer[offs])
   {
    dirtybuffer[offs] = 0;
    drawgfx(_tmpbitmap,Machine->gfx[gfx_bank],
      videoram[offs],
      colorram[offs] & 0x03,
      0,0,
      8*sx,8*sy,
      0,TRANSPARENCY_NONE,0);
   }
  }
 }
 {
  int offs,scroll[32];
  for (offs = 0;offs < 28;offs++)
   scroll[offs] = -*funkyb_row_scroll;
  for (;offs < 32;offs++)
   scroll[offs] = 0;
  copyscrollbitmap(bitmap,_tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
static void draw_chars(struct osd_bitmap *_tmpbitmap, struct osd_bitmap *bitmap)
{
 int sx; int sy;
 for (sy = 0x1f;sy >= 0;sy--)
 {
  int offs;
  offs = (sy << 8) | 0x1f;
  for (sx = 0x1f;sx >= 0;sx--,offs--)
  {
   if (dirtybuffer[offs])
   {
    dirtybuffer[offs] = 0;
    drawgfx(_tmpbitmap,Machine->gfx[gfx_bank],
      videoram[offs],
      colorram[offs] & 0x03,
      0,0,
      8*sx,8*sy,
      0,TRANSPARENCY_NONE,0);
   }
  }
 }
 {
  int offs; int scroll[32];
  for (offs = 0;offs < 28;offs++)
   scroll[offs] = -*funkyb_row_scroll;
  for (;offs < 32;offs++)
   scroll[offs] = 0;
  copyscrollbitmap(bitmap,_tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

variable_types:
bitmap
struct osd_bitmap *

variable_types: offs int

variable_types:
scroll
int [32]


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

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

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

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

original_code:
void astinvad_sh_port_4_w(offs_t offset,data_t data)
{
 static int port4State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port4State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port4State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_UFO, SND_UFO, 1 );
 if ( bitsGoneLow & 0x01 ) sample_stop( SND_UFO );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_SHOT, SND_SHOT, 0 );
 if ( bitsGoneLow & 0x02 ) sample_stop( SND_SHOT );
 if ( bitsGoneHigh & 0x04 )
 {
  sample_start( SND_BASEHIT, SND_BASEHIT, 0 );
     invaders_screen_red_w(1);
    }
 if ( bitsGoneLow & 0x04 )
 {
  sample_stop( SND_BASEHIT );
     invaders_screen_red_w(0);
    }
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_INVADERHIT, SND_INVADERHIT, 0 );
 if ( bitsGoneLow & 0x08 ) sample_stop( SND_INVADERHIT );
}

canonical_original_code:
void astinvad_sh_port_4_w(unsigned int offset, unsigned int data)
{
 static int port4State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port4State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port4State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_UFO, SND_UFO, 1 );
 if ( bitsGoneLow & 0x01 ) sample_stop( SND_UFO );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_SHOT, SND_SHOT, 0 );
 if ( bitsGoneLow & 0x02 ) sample_stop( SND_SHOT );
 if ( bitsGoneHigh & 0x04 )
 {
  sample_start( SND_BASEHIT, SND_BASEHIT, 0 );
     invaders_screen_red_w(1);
    }
 if ( bitsGoneLow & 0x04 )
 {
  sample_stop( SND_BASEHIT );
     invaders_screen_red_w(0);
    }
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_INVADERHIT, SND_INVADERHIT, 0 );
 if ( bitsGoneLow & 0x08 ) sample_stop( SND_INVADERHIT );
}

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int


decompiled_code:
__int64 __fastcall astinvad_sh_port_5_w(__int64 a1, int a2)
{
char v2; // r12
unsigned __int8 v3; // r12
char v4; // bp
__int64 result; // rax

v2 = port5State_0;
port5State_0 = a2;
v3 = a2 ^ v2;
v4 = a2 & v3;
if ( ((unsigned __int8)a2 & v3 & 1) != 0 )
{
result = sample_start(4LL, 4LL, 0LL);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v4 & 4) == 0 )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(5LL, 5LL, 0LL);
if ( (v4 & 4) == 0 )
{
LABEL_4:
if ( (v4 & 8) == 0 )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
result = sample_start(6LL, 6LL, 0LL);
if ( (v4 & 8) == 0 )
{
LABEL_5:
if ( ((unsigned __int8)a2 & v3 & 0x10) == 0 )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
result = sample_start(7LL, 7LL, 0LL);
if ( ((unsigned __int8)a2 & v3 & 0x10) == 0 )
{
LABEL_6:
if ( (v3 & (unsigned __int8)~(_BYTE)a2 & 0x10) == 0 )
goto LABEL_7;
goto LABEL_14;
}
LABEL_13:
result = sample_start(8LL, 8LL, 0LL);
if ( (v3 & (unsigned __int8)~(_BYTE)a2 & 0x10) == 0 )
{
LABEL_7:
if ( (v3 & 0x20) == 0 )
return result;
return invaders_flip_screen_w(a2 & 0x20);
}
LABEL_14:
result = sample_stop(8LL);
if ( (v3 & 0x20) != 0 )
return invaders_flip_screen_w(a2 & 0x20);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
char v2; // r12
unsigned __int8 v3; // r12
char v4; // bp
__int64 result; // rax

v2 = port5State_0;
port5State_0 = a2;
v3 = a2 ^ v2;
v4 = a2 & v3;
if ( ((unsigned __int8)a2 & v3 & 1) != 0 )
{
result = sample_start(4LL, 4LL, 0LL);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v4 & 4) == 0 )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(5LL, 5LL, 0LL);
if ( (v4 & 4) == 0 )
{
LABEL_4:
if ( (v4 & 8) == 0 )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
result = sample_start(6LL, 6LL, 0LL);
if ( (v4 & 8) == 0 )
{
LABEL_5:
if ( ((unsigned __int8)a2 & v3 & 0x10) == 0 )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
result = sample_start(7LL, 7LL, 0LL);
if ( ((unsigned __int8)a2 & v3 & 0x10) == 0 )
{
LABEL_6:
if ( (v3 & (unsigned __int8)~(_BYTE)a2 & 0x10) == 0 )
goto LABEL_7;
goto LABEL_14;
}
LABEL_13:
result = sample_start(8LL, 8LL, 0LL);
if ( (v3 & (unsigned __int8)~(_BYTE)a2 & 0x10) == 0 )
{
LABEL_7:
if ( (v3 & 0x20) == 0 )
return result;
return invaders_flip_screen_w(a2 & 0x20);
}
LABEL_14:
result = sample_stop(8LL);
if ( (v3 & 0x20) != 0 )
return invaders_flip_screen_w(a2 & 0x20);
return result;
}

original_code:
void astinvad_sh_port_5_w(offs_t offset,data_t data)
{
 static int port5State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port5State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port5State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_FLEET1, SND_FLEET1, 0 );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_FLEET2, SND_FLEET2, 0 );
 if ( bitsGoneHigh & 0x04 ) sample_start( SND_FLEET3, SND_FLEET3, 0 );
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_FLEET4, SND_FLEET4, 0 );
 if ( bitsGoneHigh & 0x10 ) sample_start( SND_UFO2, SND_UFO2, 0 );
 if ( bitsGoneLow & 0x10 ) sample_stop( SND_UFO2 );
 if ( bitsChanged & 0x20 ) invaders_flip_screen_w(data & 0x20);
}

canonical_original_code:
void astinvad_sh_port_5_w(unsigned int offset, unsigned int data)
{
 static int port5State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port5State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port5State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_FLEET1, SND_FLEET1, 0 );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_FLEET2, SND_FLEET2, 0 );
 if ( bitsGoneHigh & 0x04 ) sample_start( SND_FLEET3, SND_FLEET3, 0 );
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_FLEET4, SND_FLEET4, 0 );
 if ( bitsGoneHigh & 0x10 ) sample_start( SND_UFO2, SND_UFO2, 0 );
 if ( bitsGoneLow & 0x10 ) sample_stop( SND_UFO2 );
 if ( bitsChanged & 0x20 ) invaders_flip_screen_w(data & 0x20);
}

variable_types:
offset
unsigned int