decompiled_code:
__int64 sound_status_r()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 3LL;
}

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

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


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbx
__int64 v3; // rbp
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 8LL * (gfxbank + 2) + 512);
v2 = spriteram + 124LL;
v3 = spriteram - 4LL;
do
{
result = drawgfx(a1, v1, *(_BYTE *)(v2 + 1) & 0x3F, *(unsigned __int8 *)(v2 + 2));
v2 -= 4LL;
}
while ( v3 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbx
__int64 v3; // rbp
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 8LL * (gfxbank + 2) + 512);
v2 = spriteram + 124LL;
v3 = spriteram - 4LL;
do
{
result = drawgfx(a1, v1, *(_BYTE *)(v2 + 1) & 0x3F, *(unsigned __int8 *)(v2 + 2));
v2 -= 4LL;
}
while ( v3 != v2 );
return result;
}

original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
    const struct GfxElement *gfx = Machine->gfx[2+gfxbank];
    struct rectangle clip = Machine->visible_area;
    const unsigned char *finish = spriteram;
 const unsigned char *source = spriteram + 0x80 - 4;
 while( source>=finish )
 {
  int color = source[2];
  int tile_number = source[1];
  int sy = source[0];
  int sx = source[3];
  int flipy = (tile_number&0x80);
  int flipx = (tile_number&0x40);
  if( flipscreen )
  {
   sx = 240-sx;
   flipx = !flipx;
   flipy = !flipy;
  }
  else
  {
   sy = 240-sy;
  }
        drawgfx( bitmap,gfx,
            tile_number&0x3f,
            color,
            flipx, flipy,
            sx,sy,
            &clip,TRANSPARENCY_PEN,0);
        source-=4;
    }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
    struct GfxElement *gfx = Machine->gfx[2+gfxbank];
    struct rectangle clip = Machine->visible_area;
    unsigned char *finish = spriteram;
 unsigned char *source = spriteram + 0x80 - 4;
 while( source>=finish )
 {
  int color = source[2];
  int tile_number = source[1];
  int sy = source[0];
  int sx = source[3];
  int flipy = (tile_number&0x80);
  int flipx = (tile_number&0x40);
  if( flipscreen )
  {
   sx = 240-sx;
   flipx = !flipx;
   flipy = !flipy;
  }
  else
  {
   sy = 240-sy;
  }
        drawgfx( bitmap,gfx,
            tile_number&0x3f,
            color,
            flipx, flipy,
            sx,sy,
            &clip,TRANSPARENCY_PEN,0);
        source-=4;
    }
}

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

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

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

variable_types:
finish
unsigned char *

variable_types:
source
unsigned char *

variable_types: color int

variable_types: sy int

variable_types: sx int

variable_types: flipy int

variable_types: flipx int

return_type: void


original_code:
void zaccaria_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i,j,k;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  if (((i % 64) / 8) == 0)
  {
   *(palette++) = 0;
   *(palette++) = 0;
   *(palette++) = 0;
  }
  else
  {
   bit0 = (color_prom[0] >> 3) & 0x01;
   bit1 = (color_prom[0] >> 2) & 0x01;
   bit2 = (color_prom[0] >> 1) & 0x01;
   *(palette++) = 0x46 * bit0 + 0x53 * bit1 + 0x66 * bit2;
   bit0 = (color_prom[0] >> 0) & 0x01;
   bit1 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
   bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
   *(palette++) = 0x46 * bit0 + 0x53 * bit1 + 0x66 * bit2;
   bit0 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
   bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
   *(palette++) = 0x53 * bit0 + 0x7b * bit1;
  }
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  for (j = 0;j < 4;j++)
  {
   for (k = 0;k < 8;k++)
   {
    (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 32 * i + 8 * j + k]) = 64 * i + 8 * k + 2*j;
   }
  }
 }
 for (i = 0;i < 8;i++)
 {
  for (j = 0;j < 4;j++)
  {
   for (k = 0;k < 8;k++)
   {
    (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 32 * i + 8 * j + k]) = 64 * i + 8 * k + 2*j+1;
   }
  }
 }
}

canonical_original_code:
void zaccaria_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i; int j; int k;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  if (((i % 64) / 8) == 0)
  {
   *(palette++) = 0;
   *(palette++) = 0;
   *(palette++) = 0;
  }
  else
  {
   bit0 = (color_prom[0] >> 3) & 0x01;
   bit1 = (color_prom[0] >> 2) & 0x01;
   bit2 = (color_prom[0] >> 1) & 0x01;
   *(palette++) = 0x46 * bit0 + 0x53 * bit1 + 0x66 * bit2;
   bit0 = (color_prom[0] >> 0) & 0x01;
   bit1 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
   bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
   *(palette++) = 0x46 * bit0 + 0x53 * bit1 + 0x66 * bit2;
   bit0 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
   bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
   *(palette++) = 0x53 * bit0 + 0x7b * bit1;
  }
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  for (j = 0;j < 4;j++)
  {
   for (k = 0;k < 8;k++)
   {
    (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 32 * i + 8 * j + k]) = 64 * i + 8 * k + 2*j;
   }
  }
 }
 for (i = 0;i < 8;i++)
 {
  for (j = 0;j < 4;j++)
  {
   for (k = 0;k < 8;k++)
   {
    (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 32 * i + 8 * j + k]) = 64 * i + 8 * k + 2*j+1;
   }
  }
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: j int

variable_types: k int


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

result = 64LL;
if ( a1 != 4 )
{
if ( a1 == 6 )
{
result = 160LL;
if ( *(_UNKNOWN **)(Machine + 816LL) == &monymony_driver )
result = 112LL;
}
else
{
result = a1 == 0 ? 0x50 : 0;
}
}
return result;
}

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

result = 64LL;
if ( a1 != 4 )
{
if ( a1 == 6 )
{
result = 160LL;
if ( *(_UNKNOWN **)(Machine + 816LL) == &monymony_driver )
result = 112LL;
}
else
{
result = a1 == 0 ? 0x50 : 0;
}
}
return result;
}

original_code:
data_t zaccaria_prot1_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return 0x50;
  case 4:
   return 0x40;
  case 6:
   if (Machine->gamedrv == &monymony_driver)
    return 0x70;
   return 0xa0;
  default:
   return 0;
 }
}

canonical_original_code:
unsigned int zaccaria_prot1_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return 0x50;
  case 4:
   return 0x40;
  case 6:
   if (Machine->gamedrv == &monymony_driver)
    return 0x70;
   return 0xa0;
  default:
   return 0;
 }
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall zaccaria_dsw_sel_w(__int64 a1, int a2)
{
switch ( a2 )
{
case 208:
dsw = 1;
break;
case 224:
dsw = 0;
break;
case 176:
dsw = 2;
break;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
switch ( a2 )
{
case 208:
dsw = 1;
break;
case 224:
dsw = 0;
break;
case 176:
dsw = 2;
break;
}
}

original_code:
void zaccaria_dsw_sel_w(offs_t offset,data_t data)
{
 switch (data)
 {
  case 0xe0:
   dsw = 0;
   break;
  case 0xd0:
   dsw = 1;
   break;
  case 0xb0:
   dsw = 2;
   break;
  default:
   break;
 }
}

canonical_original_code:
void zaccaria_dsw_sel_w(unsigned int offset, unsigned int data)
{
 switch (data)
 {
  case 0xe0:
   dsw = 0;
   break;
  case 0xd0:
   dsw = 1;
   break;
  case 0xb0:
   dsw = 2;
   break;
  default:
   break;
 }
}

variable_types:
data
unsigned int


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

if ( a1 == 4 )
return 128LL;
result = 0LL;
if ( a1 <= 4 )
{
if ( a1 )
{
if ( a1 == 2 )
result = 16LL;
}
else
{
result = input_port_6_r(0LL);
}
}
return result;
}

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

if ( a1 == 4 )
return 128LL;
result = 0LL;
if ( a1 <= 4 )
{
if ( a1 )
{
if ( a1 == 2 )
result = 16LL;
}
else
{
result = input_port_6_r(0LL);
}
}
return result;
}

original_code:
data_t zaccaria_prot2_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return input_port_6_r(0);
  case 2:
   return 0x10;
  case 4:
   return 0x80;
  case 6:
   return 0x00;
  default:
   return 0;
 }
}

canonical_original_code:
unsigned int zaccaria_prot2_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return input_port_6_r(0);
  case 2:
   return 0x10;
  case 4:
   return 0x80;
  case 6:
   return 0x00;
  default:
   return 0;
 }
}


decompiled_code:
__int64 zaccaria_dsw_r()
{
return readinputport((unsigned int)dsw);
}

canonical_decompiled_code:
__int64 func5()
{
return readinputport((unsigned int)dsw);
}

original_code:
data_t zaccaria_dsw_r(offs_t offset)
{
 return readinputport(dsw);
}

canonical_original_code:
unsigned int zaccaria_dsw_r(unsigned int offset)
{
 return readinputport(dsw);
}


decompiled_code:
__int64 zaccaria_init_machine()
{
pia_unconfig();
pia_config(0LL, 0LL, &pia_0_intf);
pia_config(1LL, 0LL, &pia_1_intf);
return pia_reset();
}

canonical_decompiled_code:
__int64 func6()
{
pia_unconfig();
pia_config(0LL, 0LL, &pia_0_intf);
pia_config(1LL, 0LL, &pia_1_intf);
return pia_reset();
}

original_code:
static void zaccaria_init_machine(void)
{
 pia_unconfig();
 pia_config(0, 0 | 0, &pia_0_intf);
 pia_config(1, 0 | 0, &pia_1_intf);
 pia_reset();
}

canonical_original_code:
static void zaccaria_init_machine()
{
 pia_unconfig();
 pia_config(0, 0 | 0, &pia_0_intf);
 pia_config(1, 0 | 0, &pia_1_intf);
 pia_reset();
}


decompiled_code:
void __fastcall redalert_backcolor_w(__int64 a1, char a2)
{
backcolor = a2 & 7;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
backcolor = a2 & 7;
}

original_code:
void redalert_backcolor_w(offs_t offset,data_t data)
{
 backcolor = data & 0x07;
}

canonical_original_code:
void redalert_backcolor_w(unsigned int offset, unsigned int data)
{
 backcolor = data & 0x07;
}


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

result = (a1 >> 3) & 0x3FF;
if ( *(unsigned __int8 *)(redalert_backram + a1) != a2 || redalert_backcolor[(int)result] != backcolor )
{
redalert_dirtyback[(int)result] = 1;
*(_BYTE *)(dirtybuffer + (int)result) = 1;
redalert_backcolor[(int)result] = backcolor;
result = redalert_backram;
*(_BYTE *)(redalert_backram + a1) = a2;
}
return result;
}

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

result = (a1 >> 3) & 0x3FF;
if ( *(unsigned __int8 *)(redalert_backram + a1) != a2 || redalert_backcolor[(int)result] != backcolor )
{
redalert_dirtyback[(int)result] = 1;
*(_BYTE *)(dirtybuffer + (int)result) = 1;
redalert_backcolor[(int)result] = backcolor;
result = redalert_backram;
*(_BYTE *)(redalert_backram + a1) = a2;
}
return result;
}

original_code:
void redalert_backram_w(offs_t offset,data_t data)
{
 int charnum;
 charnum = offset / 8 % 0x400;
 if ((redalert_backram[offset] != data) ||
  (redalert_backcolor[charnum] != backcolor))
 {
  redalert_dirtyback[charnum] = 1;
  dirtybuffer[charnum] = 1;
  redalert_backcolor[charnum] = backcolor;
  redalert_backram[offset] = data;
 }
}

canonical_original_code:
void redalert_backram_w(unsigned int offset, unsigned int data)
{
 int charnum;
 charnum = offset / 8 % 0x400;
 if ((redalert_backram[offset] != data) ||
  (redalert_backcolor[charnum] != backcolor))
 {
  redalert_dirtyback[charnum] = 1;
  dirtybuffer[charnum] = 1;
  redalert_backcolor[charnum] = backcolor;
  redalert_backram[offset] = data;
 }
}

variable_types: charnum int


decompiled_code:
__int64 redalert_AY8910_A_r()
{
return (unsigned int)AY8910_A_input_data;
}

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

original_code:
data_t redalert_AY8910_A_r(offs_t offset)
{
 return AY8910_A_input_data;
}

canonical_original_code:
unsigned int redalert_AY8910_A_r(unsigned int offset)
{
 return AY8910_A_input_data;
}


decompiled_code:
__int64 redalert_sound_register_IC1_r()
{
return (unsigned int)sound_register_IC1;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)sound_register_IC1;
}

original_code:
data_t redalert_sound_register_IC1_r(offs_t offset)
{
 return sound_register_IC1;
}

canonical_original_code:
unsigned int redalert_sound_register_IC1_r(unsigned int offset)
{
 return sound_register_IC1;
}


decompiled_code:
void __fastcall redalert_sound_register_IC2_w(__int64 a1, int a2)
{
sound_register_IC2 = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
sound_register_IC2 = a2;
}

original_code:
void redalert_sound_register_IC2_w(offs_t offset,data_t data)
{
 sound_register_IC2 = data;
}

canonical_original_code:
void redalert_sound_register_IC2_w(unsigned int offset, unsigned int data)
{
 sound_register_IC2 = data;
}


decompiled_code:
void redalert_AY8910_B_w()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

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

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


decompiled_code:
__int64 __fastcall redalert_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // r12
unsigned __int8 v4; // r15
int v5; // er12
int v6; // ebx
__int64 v7; // rbx
__int64 v8; // r12
_BYTE *v9; // rax
_BYTE *v10; // rax

LODWORD(v1) = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v1 = (int)v1;
do
{
v4 = *(_BYTE *)(videoram + v1);
if ( *(_BYTE *)(dirtybuffer + v1) || redalert_dirtycharacter[v4] )
{
if ( redalert_dirtyback[v1] == 1 )
{
decodechar(
*(_QWORD *)(Machine + 512LL),
(unsigned int)v1,
redalert_backram,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 8LL));
redalert_dirtyback[v1] = 2;
}
if ( redalert_dirtycharacter[v4] == 1 )
{
if ( v4 > 0x7Fu )
decodechar(
*(_QWORD *)(Machine + 528LL),
(unsigned int)v4 - 128,
redalert_spriteram1,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 56LL));
else
decodechar(
*(_QWORD *)(Machine + 520LL),
v4,
redalert_characterram,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 32LL));
redalert_dirtycharacter[v4] = 2;
}
*(_BYTE *)(dirtybuffer + v1) = 0;
v5 = 31 - (int)v1 / 32;
v6 = (int)v1 % 32;
if ( v4 > 0xBFu )
{
v2 = (unsigned int)(8 * v6);
v3 = (unsigned int)(8 * v5);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
(unsigned int)v4 - 128,
color_lookup[v4],
0LL,
0LL,
v3,
v2,
Machine + 776LL,
0LL,
0LL);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)v1,
redalert_backcolor[v1],
0LL,
0LL,
v3,
v2,
Machine + 776LL,
6LL,
0LL);
}
else
{
v7 = (unsigned int)(8 * v6);
v8 = (unsigned int)(8 * v5);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)v1,
redalert_backcolor[v1],
0LL,
0LL,
v8,
v7,
Machine + 776LL,
0LL,
0LL);
if ( v4 > 0x7Fu )
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
(unsigned int)v4 - 128,
color_lookup[v4],
0LL,
0LL,
v8,
v7,
Machine + 776LL,
6LL,
0LL);
else
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
v4,
color_lookup[v4],
0LL,
0LL,
v8,
v7,
Machine + 776LL,
6LL,
0LL);
}
}
--v1;
}
while ( (int)v1 >= 0 );
}
v9 = redalert_dirtycharacter;
do
{
if ( *v9 == 2 )
*v9 = 0;
++v9;
}
while ( v9 != &redalert_dirtycharacter[256] );
v10 = redalert_dirtyback;
do
{
if ( *v10 == 2 )
*v10 = 0;
++v10;
}
while ( &redalert_dirtyback[1024] != v10 );
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // r12
unsigned __int8 v4; // r15
int v5; // er12
int v6; // ebx
__int64 v7; // rbx
__int64 v8; // r12
_BYTE *v9; // rax
_BYTE *v10; // rax

LODWORD(v1) = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v1 = (int)v1;
do
{
v4 = *(_BYTE *)(videoram + v1);
if ( *(_BYTE *)(dirtybuffer + v1) || redalert_dirtycharacter[v4] )
{
if ( redalert_dirtyback[v1] == 1 )
{
decodechar(
*(_QWORD *)(Machine + 512LL),
(unsigned int)v1,
redalert_backram,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 8LL));
redalert_dirtyback[v1] = 2;
}
if ( redalert_dirtycharacter[v4] == 1 )
{
if ( v4 > 0x7Fu )
decodechar(
*(_QWORD *)(Machine + 528LL),
(unsigned int)v4 - 128,
redalert_spriteram1,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 56LL));
else
decodechar(
*(_QWORD *)(Machine + 520LL),
v4,
redalert_characterram,
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 32LL));
redalert_dirtycharacter[v4] = 2;
}
*(_BYTE *)(dirtybuffer + v1) = 0;
v5 = 31 - (int)v1 / 32;
v6 = (int)v1 % 32;
if ( v4 > 0xBFu )
{
v2 = (unsigned int)(8 * v6);
v3 = (unsigned int)(8 * v5);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
(unsigned int)v4 - 128,
color_lookup[v4],
0LL,
0LL,
v3,
v2,
Machine + 776LL,
0LL,
0LL);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)v1,
redalert_backcolor[v1],
0LL,
0LL,
v3,
v2,
Machine + 776LL,
6LL,
0LL);
}
else
{
v7 = (unsigned int)(8 * v6);
v8 = (unsigned int)(8 * v5);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)v1,
redalert_backcolor[v1],
0LL,
0LL,
v8,
v7,
Machine + 776LL,
0LL,
0LL);
if ( v4 > 0x7Fu )
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
(unsigned int)v4 - 128,
color_lookup[v4],
0LL,
0LL,
v8,
v7,
Machine + 776LL,
6LL,
0LL);
else
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
v4,
color_lookup[v4],
0LL,
0LL,
v8,
v7,
Machine + 776LL,
6LL,
0LL);
}
}
--v1;
}
while ( (int)v1 >= 0 );
}
v9 = redalert_dirtycharacter;
do
{
if ( *v9 == 2 )
*v9 = 0;
++v9;
}
while ( v9 != &redalert_dirtycharacter[256] );
v10 = redalert_dirtyback;
do
{
if ( *v10 == 2 )
*v10 = 0;
++v10;
}
while ( &redalert_dirtyback[1024] != v10 );
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void redalert_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs,i;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int charcode;
  int stat_transparent;
  charcode = videoram[offs];
  if (dirtybuffer[offs] || redalert_dirtycharacter[charcode])
  {
   int sx,sy,color;
   if (redalert_dirtyback[offs] == 1)
   {
    decodechar(Machine->gfx[0],offs,redalert_backram,
       Machine->drv->gfxdecodeinfo[0].gfxlayout);
    redalert_dirtyback[offs] = 2;
   }
   if (redalert_dirtycharacter[charcode] == 1)
   {
    if (charcode < 0x80)
     decodechar(Machine->gfx[1],charcode,redalert_characterram,
        Machine->drv->gfxdecodeinfo[1].gfxlayout);
    else
     decodechar(Machine->gfx[2],charcode-0x80,redalert_spriteram1,
        Machine->drv->gfxdecodeinfo[2].gfxlayout);
    redalert_dirtycharacter[charcode] = 2;
   }
   dirtybuffer[offs] = 0;
   sx = 31 - offs / 32;
   sy = offs % 32;
   stat_transparent = TRANSPARENCY_NONE;
   if (charcode >= 0xC0)
   {
    stat_transparent = TRANSPARENCY_COLOR;
    color = color_lookup[charcode];
    drawgfx(tmpbitmap,Machine->gfx[2],
      charcode-0x80,
      color,
      0,0,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
   }
   color = redalert_backcolor[offs];
   drawgfx(tmpbitmap,Machine->gfx[0],
     offs,
     color,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,stat_transparent,0);
   if (charcode < 0x80)
   {
    color = color_lookup[charcode];
    drawgfx(tmpbitmap,Machine->gfx[1],
      charcode,
      color,
      0,0,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_COLOR,0);
   }
   else if (charcode < 0xC0)
   {
    color = color_lookup[charcode];
    drawgfx(tmpbitmap,Machine->gfx[2],
      charcode-0x80,
      color,
      0,0,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_COLOR,0);
   }
  }
 }
 for (i = 0;i < 256;i++)
 {
  if (redalert_dirtycharacter[i] == 2)
   redalert_dirtycharacter[i] = 0;
 }
 for (i = 0;i < 0x400;i++)
 {
  if (redalert_dirtyback[i] == 2)
   redalert_dirtyback[i] = 0;
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void redalert_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int i;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int charcode;
  int stat_transparent;
  charcode = videoram[offs];
  if (dirtybuffer[offs] || redalert_dirtycharacter[charcode])
  {
   int sx; int sy; int color;
   if (redalert_dirtyback[offs] == 1)
   {
    decodechar(Machine->gfx[0],offs,redalert_backram,
       Machine->drv->gfxdecodeinfo[0].gfxlayout);
    redalert_dirtyback[offs] = 2;
   }
   if (redalert_dirtycharacter[charcode] == 1)
   {
    if (charcode < 0x80)
     decodechar(Machine->gfx[1],charcode,redalert_characterram,
        Machine->drv->gfxdecodeinfo[1].gfxlayout);
    else
     decodechar(Machine->gfx[2],charcode-0x80,redalert_spriteram1,
        Machine->drv->gfxdecodeinfo[2].gfxlayout);
    redalert_dirtycharacter[charcode] = 2;
   }
   dirtybuffer[offs] = 0;
   sx = 31 - offs / 32;
   sy = offs % 32;
   stat_transparent = TRANSPARENCY_NONE;
   if (charcode >= 0xC0)
   {
    stat_transparent = TRANSPARENCY_COLOR;
    color = color_lookup[charcode];
    drawgfx(tmpbitmap,Machine->gfx[2],
      charcode-0x80,
      color,
      0,0,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
   }
   color = redalert_backcolor[offs];
   drawgfx(tmpbitmap,Machine->gfx[0],
     offs,
     color,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,stat_transparent,0);
   if (charcode < 0x80)
   {
    color = color_lookup[charcode];
    drawgfx(tmpbitmap,Machine->gfx[1],
      charcode,
      color,
      0,0,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_COLOR,0);
   }
   else if (charcode < 0xC0)
   {
    color = color_lookup[charcode];
    drawgfx(tmpbitmap,Machine->gfx[2],
      charcode-0x80,
      color,
      0,0,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_COLOR,0);
   }
  }
 }
 for (i = 0;i < 256;i++)
 {
  if (redalert_dirtycharacter[i] == 2)
   redalert_dirtycharacter[i] = 0;
 }
 for (i = 0;i < 0x400;i++)
 {
  if (redalert_dirtyback[i] == 2)
   redalert_dirtyback[i] = 0;
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

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

variable_types: offs int

variable_types: charcode int


decompiled_code:
__int64 __fastcall redalert_c030_w(__int64 a1, char a2)
{
__int64 result; // rax

result = a2 & 0x3F;
c030_data = a2 & 0x3F;
if ( a2 < 0 )
result = cpu_cause_interrupt(2LL, 8LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char a2)
{
__int64 result; // rax

result = a2 & 0x3F;
c030_data = a2 & 0x3F;
if ( a2 < 0 )
result = cpu_cause_interrupt(2LL, 8LL);
return result;
}

original_code:
void redalert_c030_w(offs_t offset,data_t data)
{
 c030_data = data & 0x3F;
 if (data & 0x80)
  cpu_cause_interrupt(2,0x08);
}

canonical_original_code:
void redalert_c030_w(unsigned int offset, unsigned int data)
{
 c030_data = data & 0x3F;
 if (data & 0x80)
  cpu_cause_interrupt(2,0x08);
}


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

AY8910_A_input_data = a2;
if ( (a2 & 0x80u) == 0 )
result = cpu_cause_interrupt(1LL, 2LL);
return result;
}

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

AY8910_A_input_data = a2;
if ( (a2 & 0x80u) == 0 )
result = cpu_cause_interrupt(1LL, 2LL);
return result;
}

original_code:
void redalert_soundlatch_w(offs_t offset,data_t data)
{
 AY8910_A_input_data = data;
 if ((data & 0x80)!=0x80)
  cpu_cause_interrupt(1,2);
}

canonical_original_code:
void redalert_soundlatch_w(unsigned int offset, unsigned int data)
{
 AY8910_A_input_data = data;
 if ((data & 0x80)!=0x80)
  cpu_cause_interrupt(1,2);
}


decompiled_code:
void __fastcall redalert_AY8910_w(__int64 a1, int a2)
{
switch ( a2 )
{
case 2:
AY8910_write_port_0_w(a1, (unsigned int)sound_register_IC2);
break;
case 3:
AY8910_control_port_0_w(a1, (unsigned int)sound_register_IC2);
break;
case 1:
sound_register_IC1 = AY8910_read_port_0_r();
break;
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2)
{
switch ( a2 )
{
case 2:
AY8910_write_port_0_w(a1, (unsigned int)sound_register_IC2);
break;
case 3:
AY8910_control_port_0_w(a1, (unsigned int)sound_register_IC2);
break;
case 1:
sound_register_IC1 = AY8910_read_port_0_r();
break;
}
}

original_code:
void redalert_AY8910_w(offs_t offset,data_t data)
{
 switch (data)
 {
  case 0x00:
   break;
  case 0x01:
   sound_register_IC1 = AY8910_read_port_0_r(offset);
   break;
  case 0x02:
   AY8910_write_port_0_w(offset,sound_register_IC2);
   break;
  case 0x03:
   AY8910_control_port_0_w(offset,sound_register_IC2);
   break;
  default:
   break;
 }
}

canonical_original_code:
void redalert_AY8910_w(unsigned int offset, unsigned int data)
{
 switch (data)
 {
  case 0x00:
   break;
  case 0x01:
   sound_register_IC1 = AY8910_read_port_0_r(offset);
   break;
  case 0x02:
   AY8910_write_port_0_w(offset,sound_register_IC2);
   break;
  case 0x03:
   AY8910_control_port_0_w(offset,sound_register_IC2);
   break;
  default:
   break;
 }
}


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

v0 = input_port_4_r(0LL);
if ( v0 && ((v0 & 1) != 0 && (lastcoin_0 & 1) == 0 || (v0 & 2) != 0 && (lastcoin_0 & 2) == 0) )
{
lastcoin_0 = v0;
result = nmi_interrupt();
}
else
{
lastcoin_0 = v0;
result = interrupt();
}
return result;
}

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

v0 = input_port_4_r(0LL);
if ( v0 && ((v0 & 1) != 0 && (lastcoin_0 & 1) == 0 || (v0 & 2) != 0 && (lastcoin_0 & 2) == 0) )
{
lastcoin_0 = v0;
result = nmi_interrupt();
}
else
{
lastcoin_0 = v0;
result = interrupt();
}
return result;
}

original_code:
static int redalert_interrupt(void)
{
 static int lastcoin = 0;
 int newcoin;
 newcoin = input_port_4_r(0);
 if (newcoin)
 {
  if ((newcoin & 0x01) && !(lastcoin & 0x01))
  {
   lastcoin = newcoin;
   return nmi_interrupt();
  }
  if ((newcoin & 0x02) && !(lastcoin & 0x02))
  {
   lastcoin = newcoin;
   return nmi_interrupt();
  }
 }
 lastcoin = newcoin;
 return interrupt();
}

canonical_original_code:
static int redalert_interrupt()
{
 static int lastcoin = 0;
 int newcoin;
 newcoin = input_port_4_r(0);
 if (newcoin)
 {
  if ((newcoin & 0x01) && !(lastcoin & 0x01))
  {
   lastcoin = newcoin;
   return nmi_interrupt();
  }
  if ((newcoin & 0x02) && !(lastcoin & 0x02))
  {
   lastcoin = newcoin;
   return nmi_interrupt();
  }
 }
 lastcoin = newcoin;
 return interrupt();
}

variable_types: lastcoin int

variable_types: newcoin int

return_type: int


decompiled_code:
__int64 redalert_voicecommand_r()
{
return (unsigned int)c030_data;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned int)c030_data;
}

original_code:
data_t redalert_voicecommand_r(offs_t offset)
{
 return c030_data;
}

canonical_original_code:
unsigned int redalert_voicecommand_r(unsigned int offset)
{
 return c030_data;
}


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

*(_QWORD *)a1 = 0xFFFF0000FF8040LL;
*(_QWORD *)(a1 + 8) = 0xFF0000FFFFFF00FFLL;
result = 0xFFFFFF00FFFF0080LL;
*(_QWORD *)(a1 + 16) = 0xFFFFFF00FFFF0080LL;
*(_WORD *)(a1 + 24) = 0;
*(_BYTE *)(a1 + 26) = 0;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_650);
a2[2] = _mm_load_si128((const __m128i *)&xmmword_660);
a2[3] = _mm_load_si128((const __m128i *)&xmmword_670);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1, __m128i *a2)
{
unsigned __int64 result; // rax

*(_QWORD *)a1 = 0xFFFF0000FF8040LL;
*(_QWORD *)(a1 + 8) = 0xFF0000FFFFFF00FFLL;
result = 0xFFFFFF00FFFF0080LL;
*(_QWORD *)(a1 + 16) = 0xFFFFFF00FFFF0080LL;
*(_WORD *)(a1 + 24) = 0;
*(_BYTE *)(a1 + 26) = 0;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_650);
a2[2] = _mm_load_si128((const __m128i *)&xmmword_660);
a2[3] = _mm_load_si128((const __m128i *)&xmmword_670);
return result;
}

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

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


decompiled_code:
__int64 ninjakd2_interrupt()
{
return 215LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 215LL;
}

original_code:
int ninjakd2_interrupt(void)
{
 return 0x00d7;
}

canonical_original_code:
int ninjakd2_interrupt()
{
 return 0x00d7;
}


decompiled_code:
__int64 ninjakd2_bankselect_r()
{
return (unsigned int)ninjakd2_bank_latch;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)ninjakd2_bank_latch;
}

original_code:
data_t ninjakd2_bankselect_r(offs_t offset)
{
 return ninjakd2_bank_latch;
}

canonical_original_code:
unsigned int ninjakd2_bankselect_r(unsigned int offset)
{
 return ninjakd2_bank_latch;
}


decompiled_code:
__int64 ninjakd2_vh_start()
{
_QWORD *v0; // rdx
__int64 v1; // rax
__int64 v2; // rcx
int v3; // edx
__int64 result; // rax

bg_dirtybuffer = malloc(0x400uLL);
if ( !bg_dirtybuffer )
return 1LL;
bitmap_bg = (void *)bitmap_alloc(
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL)),
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)));
if ( bitmap_bg )
{
bitmap_sp = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_sp )
{
v0 = bg_dirtybuffer;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1024) >> 3));
memset(palette_used_colors, 3, *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL));
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
if ( *(int *)(v2 + 24) <= 0 )
{
result = 0LL;
}
else
{
v3 = 0;
do
{
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v1 + 824) + 688LL) + 40LL)
+ *(_DWORD *)(v2 + 12) * v3
+ 15) = 7;
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 64LL)
+ *(_DWORD *)(*(_QWORD *)(Machine + 528LL) + 12LL) * v3++
+ 15) = 7;
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v2 + 24) > v3 );
result = 0LL;
}
}
else
{
free(bg_dirtybuffer);
free(bitmap_bg);
result = 1LL;
}
}
else
{
free(bg_dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
_QWORD *v0; // rdx
__int64 v1; // rax
__int64 v2; // rcx
int v3; // edx
__int64 result; // rax

bg_dirtybuffer = malloc(0x400uLL);
if ( !bg_dirtybuffer )
return 1LL;
bitmap_bg = (void *)bitmap_alloc(
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL)),
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)));
if ( bitmap_bg )
{
bitmap_sp = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_sp )
{
v0 = bg_dirtybuffer;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1024) >> 3));
memset(palette_used_colors, 3, *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL));
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
if ( *(int *)(v2 + 24) <= 0 )
{
result = 0LL;
}
else
{
v3 = 0;
do
{
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v1 + 824) + 688LL) + 40LL)
+ *(_DWORD *)(v2 + 12) * v3
+ 15) = 7;
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 64LL)
+ *(_DWORD *)(*(_QWORD *)(Machine + 528LL) + 12LL) * v3++
+ 15) = 7;
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v2 + 24) > v3 );
result = 0LL;
}
}
else
{
free(bg_dirtybuffer);
free(bitmap_bg);
result = 1LL;
}
}
else
{
free(bg_dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
int ninjakd2_vh_start(void)
{
 int i;
 if ((bg_dirtybuffer = (unsigned char*)malloc(1024)) == 0)
 {
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc(Machine->drv->screen_width*2,Machine->drv->screen_height*2)) == 0)
 {
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_sp = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(bg_dirtybuffer);
  free(bitmap_bg);
  return 1;
 }
 memset(bg_dirtybuffer,1,1024);
 memset(palette_used_colors,(1|2),Machine->drv->total_colors * sizeof(unsigned char));
 for (i = 0;i < Machine->gfx[1]->total_colors;i++)
 {
  palette_used_colors[Machine->drv->gfxdecodeinfo[1].color_codes_start + i * Machine->gfx[1]->color_granularity+15] = (4|(1|2));
  palette_used_colors[Machine->drv->gfxdecodeinfo[2].color_codes_start + i * Machine->gfx[2]->color_granularity+15] = (4|(1|2));
 }
 return 0;
}

canonical_original_code:
int ninjakd2_vh_start()
{
 int i;
 if ((bg_dirtybuffer = (unsigned char *)malloc(1024)) == 0)
 {
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc(Machine->drv->screen_width*2,Machine->drv->screen_height*2)) == 0)
 {
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_sp = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(bg_dirtybuffer);
  free(bitmap_bg);
  return 1;
 }
 memset(bg_dirtybuffer,1,1024);
 memset(palette_used_colors,(1|2),Machine->drv->total_colors * sizeof(unsigned char));
 for (i = 0;i < Machine->gfx[1]->total_colors;i++)
 {
  palette_used_colors[Machine->drv->gfxdecodeinfo[1].color_codes_start + i * Machine->gfx[1]->color_granularity+15] = (4|(1|2));
  palette_used_colors[Machine->drv->gfxdecodeinfo[2].color_codes_start + i * Machine->gfx[2]->color_granularity+15] = (4|(1|2));
 }
 return 0;
}


decompiled_code:
void ninjakd2_vh_stop()
{
bitmap_free(bitmap_bg);
bitmap_free(bitmap_sp);
free(bg_dirtybuffer);
}

canonical_decompiled_code:
void func5()
{
bitmap_free(bitmap_bg);
bitmap_free(bitmap_sp);
free(bg_dirtybuffer);
}

original_code:
void ninjakd2_vh_stop(void)
{
 bitmap_free(bitmap_bg);
 bitmap_free(bitmap_sp);
 free(bg_dirtybuffer);
}


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

if ( bg_enable != a2 )
{
*(_BYTE *)(ninjakd2_bgenable_ram + a1) = a2;
bg_enable = a2;
if ( a2 )
result = memset(bg_dirtybuffer, 1, ninjakd2_backgroundram_size >> 1);
else
result = (void *)fillbitmap(bitmap_bg, palette_transparent_pen, 0LL);
}
return result;
}

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

if ( bg_enable != a2 )
{
*(_BYTE *)(ninjakd2_bgenable_ram + a1) = a2;
bg_enable = a2;
if ( a2 )
result = memset(bg_dirtybuffer, 1, ninjakd2_backgroundram_size >> 1);
else
result = (void *)fillbitmap(bitmap_bg, palette_transparent_pen, 0LL);
}
return result;
}

original_code:
void ninjakd2_background_enable_w(offs_t offset,data_t data)
{
 if (bg_enable!=data)
 {
  ninjakd2_bgenable_ram[offset] = data;
  bg_enable = data;
  if (bg_enable)
   memset(bg_dirtybuffer, 1, ninjakd2_backgroundram_size / 2);
  else
   fillbitmap(bitmap_bg, palette_transparent_pen,0);
 }
}

canonical_original_code:
void ninjakd2_background_enable_w(unsigned int offset, unsigned int data)
{
 if (bg_enable!=data)
 {
  ninjakd2_bgenable_ram[offset] = data;
  bg_enable = data;
  if (bg_enable)
   memset(bg_dirtybuffer, 1, ninjakd2_backgroundram_size / 2);
  else
   fillbitmap(bitmap_bg, palette_transparent_pen,0);
 }
}


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

if ( sp_overdraw != a2 )
{
*(_BYTE *)(ninjakd2_spoverdraw_ram + a1) = a2;
result = fillbitmap(bitmap_sp, 15LL, Machine + 776LL);
sp_overdraw = a2;
}
return result;
}

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

if ( sp_overdraw != a2 )
{
*(_BYTE *)(ninjakd2_spoverdraw_ram + a1) = a2;
result = fillbitmap(bitmap_sp, 15LL, Machine + 776LL);
sp_overdraw = a2;
}
return result;
}

original_code:
void ninjakd2_sprite_overdraw_w(offs_t offset,data_t data)
{
 if (sp_overdraw!=data)
 {
  ninjakd2_spoverdraw_ram[offset] = data;
  fillbitmap(bitmap_sp,15,&Machine->visible_area);
  sp_overdraw = data;
 }
}

canonical_original_code:
void ninjakd2_sprite_overdraw_w(unsigned int offset, unsigned int data)
{
 if (sp_overdraw!=data)
 {
  ninjakd2_spoverdraw_ram[offset] = data;
  fillbitmap(bitmap_sp,15,&Machine->visible_area);
  sp_overdraw = data;
 }
}


original_code:
int ninjakd2_init_samples(const struct MachineSound *msound)
{
 int i,n;
 unsigned char *source = memory_region(REGION_SOUND1);
 struct GameSamples *samples;
 int sample_info [9][2] = { {0x0000,0x0A00},{0x0A00,0x1D00},{0x2700,0x1700},
 {0x3E00,0x1500},{0x5300,0x0B00},{0x5E00,0x0A00},{0x6800,0x0E00},{0x7600,0x1E00},{0xF000,0x0400} };
 if ((Machine->samples = (struct GameSamples*)malloc(sizeof(struct GameSamples) + 9 * sizeof(struct GameSample *))) == ((void *)0))
  return 1;
 samples = Machine->samples;
 samples->total = 8;
 for (i=0;i<8;i++)
 {
  if ((samples->sample[i] = (struct GameSample*)malloc(sizeof(struct GameSample) + (sample_info[i][1]))) == ((void *)0))
   return 1;
  samples->sample[i]->length = sample_info[i][1];
  samples->sample[i]->smpfreq = 16000;
  samples->sample[i]->resolution = 8;
  for (n=0; n<sample_info[i][1]; n++)
   samples->sample[i]->data[n] = source[sample_info[i][0]+n] ^ 0x80;
 }
 return 0;
}

canonical_original_code:
int ninjakd2_init_samples(struct MachineSound *msound)
{
 int i; int n;
 unsigned char *source = memory_region(REGION_SOUND1);
 struct GameSamples *samples;
 int sample_info[9][2] = { {0x0000,0x0A00},{0x0A00,0x1D00},{0x2700,0x1700},
 {0x3E00,0x1500},{0x5300,0x0B00},{0x5E00,0x0A00},{0x6800,0x0E00},{0x7600,0x1E00},{0xF000,0x0400} };
 if ((Machine->samples = (struct GameSamples *)malloc(sizeof(struct GameSamples) + 9 * sizeof(struct GameSample *))) == ((void *)0))
  return 1;
 samples = Machine->samples;
 samples->total = 8;
 for (i=0;i<8;i++)
 {
  if ((samples->sample[i] = (struct GameSample *)malloc(sizeof(struct GameSample) + (sample_info[i][1]))) == ((void *)0))
   return 1;
  samples->sample[i]->length = sample_info[i][1];
  samples->sample[i]->smpfreq = 16000;
  samples->sample[i]->resolution = 8;
  for (n=0; n<sample_info[i][1]; n++)
   samples->sample[i]->data[n] = source[sample_info[i][0]+n] ^ 0x80;
 }
 return 0;
}

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

variable_types: n int

variable_types:
source
unsigned char *

variable_types: struct GameSamples { int total; struct GameSample { int length; int smpfreq; int resolution; char data[1]; } *sample[1]; } *

user_defined_types: struct GameSamples { int total; struct GameSample *sample[1]; }


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

result = (char *)memory_region(129LL);
if ( ninjakd2_bank_latch != a2 )
{
ninjakd2_bank_latch = a2;
cpu_bankbase[1] = &result[0x4000 * (a2 & 7) + 0x10000];
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v3);
}
}
return result;
}

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

result = (char *)memory_region(129LL);
if ( ninjakd2_bank_latch != a2 )
{
ninjakd2_bank_latch = a2;
cpu_bankbase[1] = &result[0x4000 * (a2 & 7) + 0x10000];
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v3);
}
}
return result;
}

original_code:
void ninjakd2_bankselect_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int bankaddress;
 if (data != ninjakd2_bank_latch)
 {
  ninjakd2_bank_latch = data;
  bankaddress = 0x10000 + ((data & 0x7) * 0x4000);
  { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

canonical_original_code:
void ninjakd2_bankselect_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int bankaddress;
 if (data != ninjakd2_bank_latch)
 {
  ninjakd2_bank_latch = data;
  bankaddress = 0x10000 + ((data & 0x7) * 0x4000);
  { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


original_code:
void ninjakd2_pcm_play_w(offs_t offset,data_t data)
{
 int i;
 int sample_no[9] = { 0x00,0x0A,0x27,0x3E,0x53,0x5E,0x68,0x76,0xF0 };
 for(i=0;i<9;i++)
  if (sample_no[i]==data) break;
 if (i==8)
  sample_stop(0);
 else
  sample_start(0,i,0);
}

canonical_original_code:
void ninjakd2_pcm_play_w(unsigned int offset, unsigned int data)
{
 int i;
 int sample_no[9] = { 0x00,0x0A,0x27,0x3E,0x53,0x5E,0x68,0x76,0xF0 };
 for(i=0;i<9;i++)
  if (sample_no[i]==data) break;
 if (i==8)
  sample_stop(0);
 else
  sample_start(0,i,0);
}

variable_types: i int


decompiled_code:
__int64 init_ninjak2a()
{
__int64 v0; // rbx
int v1; // eax

v0 = memory_region(130LL);
v1 = memory_region_length(130LL);
return memory_set_opcode_base(1LL, v0 + v1 / 2);
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rbx
int v1; // eax

v0 = memory_region(130LL);
v1 = memory_region_length(130LL);
return memory_set_opcode_base(1LL, v0 + v1 / 2);
}

original_code:
void init_ninjak2a(void)
{
 unsigned char *rom = memory_region(REGION_CPU2);
 int diff = memory_region_length(REGION_CPU2) / 2;
 memory_set_opcode_base(1,rom+diff);
}

canonical_original_code:
void init_ninjak2a()
{
 unsigned char *rom = memory_region(REGION_CPU2);
 int diff = memory_region_length(REGION_CPU2) / 2;
 memory_set_opcode_base(1,rom+diff);
}

variable_types:
rom
unsigned char *

variable_types: diff int


irqhandler

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

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

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

variable_types: irq int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
void appoooh_scroll_w()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 appoooh_vh_start()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi

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

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi

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

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

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


decompiled_code:
__int64 appoooh_vh_stop()
{
free(dirtybuffer2);
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func5()
{
free(dirtybuffer2);
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

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

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


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

if ( (a2 & 1) != 0 )
interrupt_enable_w(0LL, 1LL);
else
interrupt_enable_w(0LL, 0LL);
if ( (a2 & 2) != flipscreen )
{
flipscreen = a2 & 2;
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
priority = (a2 >> 4) & 3;
cpu_bankbase[1] = (-(__int64)((a2 & 0x40) == 0) & 0xFFFFFFFFFFFFA000LL) + memory_region(129LL) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

if ( (a2 & 1) != 0 )
interrupt_enable_w(0LL, 1LL);
else
interrupt_enable_w(0LL, 0LL);
if ( (a2 & 2) != flipscreen )
{
flipscreen = a2 & 2;
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
priority = (a2 >> 4) & 3;
cpu_bankbase[1] = (-(__int64)((a2 & 0x40) == 0) & 0xFFFFFFFFFFFFA000LL) + memory_region(129LL) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void appoooh_out_w(offs_t offset,data_t data)
{
 if (data & 0x01) interrupt_enable_w(0,1);
 else interrupt_enable_w(0,0);
 if ((data & 0x02) != flipscreen)
 {
  flipscreen = data & 0x02;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
 priority = (data & 0x30) >> 4;
 {
  unsigned char *RAM = memory_region(REGION_CPU1);
  { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[data&0x40 ? 0x10000 : 0x0a000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

canonical_original_code:
void appoooh_out_w(unsigned int offset, unsigned int data)
{
 if (data & 0x01) interrupt_enable_w(0,1);
 else interrupt_enable_w(0,0);
 if ((data & 0x02) != flipscreen)
 {
  flipscreen = data & 0x02;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
 priority = (data & 0x30) >> 4;
 {
  unsigned char *RAM = memory_region(REGION_CPU1);
  { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[data&0x40 ? 0x10000 : 0x0a000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}


decompiled_code:
void *__fastcall appoooh_draw_sprites(__int64 a1, __int64 a2, __int64 a3)
{
void *result; // rax
__int64 v4; // rbx

result = &spriteram_size;
LODWORD(v4) = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = (int)v4;
do
{
result = (void *)drawgfx(
a1,
a2,
(*(_BYTE *)(a3 + v4 + 1) >> 2) + ((unsigned __int8)(*(_BYTE *)(a3 + v4 + 2) >> 5) << 6),
*(_BYTE *)(a3 + v4 + 2) & 0xF);
v4 -= 4LL;
}
while ( (int)v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
void *result; // rax
__int64 v4; // rbx

result = &spriteram_size;
LODWORD(v4) = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = (int)v4;
do
{
result = (void *)drawgfx(
a1,
a2,
(*(_BYTE *)(a3 + v4 + 1) >> 2) + ((unsigned __int8)(*(_BYTE *)(a3 + v4 + 2) >> 5) << 6),
*(_BYTE *)(a3 + v4 + 2) & 0xF);
v4 -= 4LL;
}
while ( (int)v4 >= 0 );
}
return result;
}

original_code:
static void appoooh_draw_sprites(struct osd_bitmap *dest_bmp,
        const struct GfxElement *gfx,
        unsigned char *sprite)
{
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sy = 256-16-sprite[offs+0];
  int code = (sprite[offs+1]>>2) + ((sprite[offs+2]>>5) & 0x07)*0x40;
  int color = sprite[offs+2]&0x0f;
  int sx = sprite[offs+3];
  int flipx = sprite[offs+1]&0x01;
  if(sx>=248) sx -= 256;
  if (flipscreen)
  {
   sx = 239- sx;
   sy = 255- sy;
   flipx = !flipx;
  }
  drawgfx( dest_bmp, gfx,
    code,
    color,
    flipx,flipscreen,
    sx, sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN , 0);
  }
}

canonical_original_code:
static void appoooh_draw_sprites(struct osd_bitmap *dest_bmp, struct GfxElement *gfx, unsigned char *sprite)
{
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sy = 256-16-sprite[offs+0];
  int code = (sprite[offs+1]>>2) + ((sprite[offs+2]>>5) & 0x07)*0x40;
  int color = sprite[offs+2]&0x0f;
  int sx = sprite[offs+3];
  int flipx = sprite[offs+1]&0x01;
  if(sx>=248) sx -= 256;
  if (flipscreen)
  {
   sx = 239- sx;
   sy = 255- sy;
   flipx = !flipx;
  }
  drawgfx( dest_bmp, gfx,
    code,
    color,
    flipx,flipscreen,
    sx, sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN , 0);
  }
}

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

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

variable_types:
sprite
unsigned char *

variable_types: offs int

variable_types: sy int

variable_types: code int

variable_types: color int

variable_types: sx int

variable_types: flipx int


decompiled_code:
void *__fastcall appoooh_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) >> 5) << 8),
*(_BYTE *)(colorram + v2) & 0xF);
}
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
*((_BYTE *)dirtybuffer2 + v2) = 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(appoooh_videoram2 + v2)
+ ((unsigned __int8)(*(_BYTE *)(appoooh_colorram2 + v2) >> 5) << 8),
*(_BYTE *)(appoooh_colorram2 + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v4[0] = 0;
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( !priority )
copyscrollbitmap(a1, tmpbitmap, 1LL, v4, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
if ( priority == 1 )
{
appoooh_draw_sprites(a1, *(_QWORD *)(Machine + 528LL), spriteram);
result = appoooh_draw_sprites(a1, *(_QWORD *)(Machine + 536LL), appoooh_spriteram2);
}
else
{
appoooh_draw_sprites(a1, *(_QWORD *)(Machine + 536LL), appoooh_spriteram2);
result = appoooh_draw_sprites(a1, *(_QWORD *)(Machine + 528LL), spriteram);
}
if ( priority )
result = (void *)copyscrollbitmap(a1, tmpbitmap, 1LL, v4, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) >> 5) << 8),
*(_BYTE *)(colorram + v2) & 0xF);
}
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
*((_BYTE *)dirtybuffer2 + v2) = 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(appoooh_videoram2 + v2)
+ ((unsigned __int8)(*(_BYTE *)(appoooh_colorram2 + v2) >> 5) << 8),
*(_BYTE *)(appoooh_colorram2 + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v4[0] = 0;
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( !priority )
copyscrollbitmap(a1, tmpbitmap, 1LL, v4, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
if ( priority == 1 )
{
func7(a1, *(_QWORD *)(Machine + 528LL), spriteram);
result = func7(a1, *(_QWORD *)(Machine + 536LL), appoooh_spriteram2);
}
else
{
func7(a1, *(_QWORD *)(Machine + 536LL), appoooh_spriteram2);
result = func7(a1, *(_QWORD *)(Machine + 528LL), spriteram);
}
if ( priority )
result = (void *)copyscrollbitmap(a1, tmpbitmap, 1LL, v4, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
return result;
}

original_code:
void appoooh_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int scroll;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,code,flipx;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   code = videoram[offs] + 256 * ((colorram[offs]>>5) & 7);
   flipx = colorram[offs] & 0x10;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     code,
     colorram[offs]&0x0f,
     flipx,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx,sy,code,flipx;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   code = appoooh_videoram2[offs] + 256 * ((appoooh_colorram2[offs]>>5) & 0x07);
   flipx = appoooh_colorram2[offs] & 0x10;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     code,
     appoooh_colorram2[offs]&0x0f,
     flipx,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 scroll = -scroll_x;
 scroll = 0;
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 if (priority == 0)
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0x00);
 if (priority == 1)
 {
  appoooh_draw_sprites( bitmap, Machine->gfx[2],spriteram);
  appoooh_draw_sprites( bitmap, Machine->gfx[3],appoooh_spriteram2);
 }
 else
 {
  appoooh_draw_sprites( bitmap, Machine->gfx[3],appoooh_spriteram2);
  appoooh_draw_sprites( bitmap, Machine->gfx[2],spriteram);
 }
 if (priority != 0)
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0x00);
}

canonical_original_code:
void appoooh_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int scroll;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int code; int flipx;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   code = videoram[offs] + 256 * ((colorram[offs]>>5) & 7);
   flipx = colorram[offs] & 0x10;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     code,
     colorram[offs]&0x0f,
     flipx,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx; int sy; int code; int flipx;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   code = appoooh_videoram2[offs] + 256 * ((appoooh_colorram2[offs]>>5) & 0x07);
   flipx = appoooh_colorram2[offs] & 0x10;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     code,
     appoooh_colorram2[offs]&0x0f,
     flipx,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 scroll = -scroll_x;
 scroll = 0;
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 if (priority == 0)
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0x00);
 if (priority == 1)
 {
  appoooh_draw_sprites( bitmap, Machine->gfx[2],spriteram);
  appoooh_draw_sprites( bitmap, Machine->gfx[3],appoooh_spriteram2);
 }
 else
 {
  appoooh_draw_sprites( bitmap, Machine->gfx[3],appoooh_spriteram2);
  appoooh_draw_sprites( bitmap, Machine->gfx[2],spriteram);
 }
 if (priority != 0)
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0x00);
}

variable_types: scroll int

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


decompiled_code:
unsigned __int8 *appoooh_adpcm_int()
{
unsigned __int8 *result; // rax

result = (unsigned __int8 *)adpcmptr;
if ( adpcmptr )
{
if ( appoooh_adpcm_data == -1 )
{
++adpcmptr;
appoooh_adpcm_data = *result;
result = (unsigned __int8 *)MSM5205_data_w(0LL, appoooh_adpcm_data >> 4);
if ( appoooh_adpcm_data == 112 )
{
adpcmptr = 0LL;
result = (unsigned __int8 *)MSM5205_reset_w(0LL, 1LL);
}
}
else
{
result = (unsigned __int8 *)MSM5205_data_w(0LL, appoooh_adpcm_data & 0xF);
appoooh_adpcm_data = -1;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *func9()
{
unsigned __int8 *result; // rax

result = (unsigned __int8 *)adpcmptr;
if ( adpcmptr )
{
if ( appoooh_adpcm_data == -1 )
{
++adpcmptr;
appoooh_adpcm_data = *result;
result = (unsigned __int8 *)MSM5205_data_w(0LL, appoooh_adpcm_data >> 4);
if ( appoooh_adpcm_data == 112 )
{
adpcmptr = 0LL;
result = (unsigned __int8 *)MSM5205_reset_w(0LL, 1LL);
}
}
else
{
result = (unsigned __int8 *)MSM5205_data_w(0LL, appoooh_adpcm_data & 0xF);
appoooh_adpcm_data = -1;
}
}
return result;
}

original_code:
static void appoooh_adpcm_int (int num)
{
 if( adpcmptr )
 {
  if( appoooh_adpcm_data==-1)
  {
   appoooh_adpcm_data = *adpcmptr++;
   MSM5205_data_w(0,appoooh_adpcm_data >> 4);
   if(appoooh_adpcm_data==0x70)
   {
    adpcmptr = 0;
    MSM5205_reset_w(0,1);
   }
  }else{
   MSM5205_data_w(0,appoooh_adpcm_data & 0x0f );
   appoooh_adpcm_data =-1;
  }
 }
}

canonical_original_code:
static void appoooh_adpcm_int(int num)
{
 if( adpcmptr )
 {
  if( appoooh_adpcm_data==-1)
  {
   appoooh_adpcm_data = *adpcmptr++;
   MSM5205_data_w(0,appoooh_adpcm_data >> 4);
   if(appoooh_adpcm_data==0x70)
   {
    adpcmptr = 0;
    MSM5205_reset_w(0,1);
   }
  }else{
   MSM5205_data_w(0,appoooh_adpcm_data & 0x0f );
   appoooh_adpcm_data =-1;
  }
 }
}

variable_types: num int


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

adpcmptr = memory_region(146LL) + (unsigned int)(a2 << 8);
result = MSM5205_reset_w(0LL, 0LL);
appoooh_adpcm_data = -1;
return result;
}

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

adpcmptr = memory_region(146LL) + (unsigned int)(a2 << 8);
result = MSM5205_reset_w(0LL, 0LL);
appoooh_adpcm_data = -1;
return result;
}

original_code:
static void appoooh_adpcm_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 adpcmptr = &RAM[data*256];
 MSM5205_reset_w(0,0);
 appoooh_adpcm_data=-1;
}

canonical_original_code:
static void appoooh_adpcm_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 adpcmptr = &RAM[data*256];
 MSM5205_reset_w(0,0);
 appoooh_adpcm_data=-1;
}

variable_types:
RAM
unsigned char *


decompiled_code:
void gbusters_unknown_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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


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

layer_colorbase[0] = 48;
dword_464 = 0;
dword_468 = 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 func3()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 48;
dword_464 = 0;
dword_468 = 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 gbusters_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 gbusters_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 gbusters_vh_stop()
{
K052109_vh_stop();
return K051960_vh_stop();
}

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

canonical_original_code:
void gbusters_vh_stop()
{
 K052109_vh_stop();
 K051960_vh_stop();
}


decompiled_code:
__int64 __fastcall gbusters_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( gbusters_priority )
{
K052109_tilemap_draw(a1, 2LL, 16LL);
K051960_sprites_draw(a1, 2LL, 2LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 16LL);
K051960_sprites_draw(a1, 2LL, 2LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
}
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( gbusters_priority )
{
K052109_tilemap_draw(a1, 2LL, 16LL);
K051960_sprites_draw(a1, 2LL, 2LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 16LL);
K051960_sprites_draw(a1, 2LL, 2LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
}
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

original_code:
void gbusters_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (gbusters_priority)
 {
  K052109_tilemap_draw(bitmap,2,0x10);
  K051960_sprites_draw(bitmap,2,2);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,0,0);
 }
 else
 {
  K052109_tilemap_draw(bitmap,1,0x10);
  K051960_sprites_draw(bitmap,2,2);
  K052109_tilemap_draw(bitmap,2,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,0,0);
 }
}

canonical_original_code:
void gbusters_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (gbusters_priority)
 {
  K052109_tilemap_draw(bitmap,2,0x10);
  K051960_sprites_draw(bitmap,2,2);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,0,0);
 }
 else
 {
  K052109_tilemap_draw(bitmap,1,0x10);
  K051960_sprites_draw(bitmap,2,2);
  K052109_tilemap_draw(bitmap,2,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,0,0);
 }
}


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

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

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

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


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

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

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

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


decompiled_code:
_QWORD *gbusters_init_machine()
{
__int64 v0; // rbx
_QWORD *result; // rax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = gbusters_banking;
memcpy((void *)(v0 + 98304), (const void *)(v0 + 0x10000), 0x8000uLL);
result = &paletteram;
paletteram = v0 + 196608;
return result;
}

canonical_decompiled_code:
_QWORD *func9()
{
__int64 v0; // rbx
_QWORD *result; // rax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = gbusters_banking;
memcpy((void *)(v0 + 98304), (const void *)(v0 + 0x10000), 0x8000uLL);
result = &paletteram;
paletteram = v0 + 196608;
return result;
}

original_code:
static void gbusters_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = gbusters_banking;
 memcpy(&RAM[0x18000], &RAM[0x10000], 0x08000 );
 paletteram = &RAM[0x30000];
}

canonical_original_code:
static void gbusters_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = gbusters_banking;
 memcpy(&RAM[0x18000], &RAM[0x10000], 0x08000 );
 paletteram = &RAM[0x30000];
}


decompiled_code:
void *__fastcall gbusters_banking(char a1)
{
void *result; // rax
unsigned int v2; // eax

cpu_bankbase[1] = memory_region(129LL) + ((a1 & 0xF) << 13) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(char a1)
{
void *result; // rax
unsigned int v2; // eax

cpu_bankbase[1] = memory_region(129LL) + ((a1 & 0xF) << 13) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v2);
}
return result;
}

original_code:
static void gbusters_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0x10000;
 offs += (lines & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void gbusters_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0x10000;
 offs += (lines & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int


decompiled_code:
__int64 __fastcall gbusters_snd_bankswitch_w(__int64 a1, int a2)
{
__int64 v2; // rax

v2 = memory_region(146LL);
return K007232_bankswitch(0LL, v2 + ((a2 << 17) & 0x20000), v2 + ((a2 << 15) & 0x20000));
}

original_code:
static void gbusters_snd_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_B = 0x20000*((data >> 2) & 0x01);
 int bank_A = 0x20000*((data) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
}

canonical_original_code:
static void gbusters_snd_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_B = 0x20000*((data >> 2) & 0x01);
 int bank_A = 0x20000*((data) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
}


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

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

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

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

original_code:
static int gbusters_interrupt( void )
{
 if (K052109_is_IRQ_enabled())
  return 1;
 else
  return ignore_interrupt();
}

canonical_original_code:
static int gbusters_interrupt()
{
 if (K052109_is_IRQ_enabled())
  return 1;
 else
  return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall gbusters_1f98_w(__int64 a1, char a2)
{
return K052109_set_RMRD_line(a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, char a2)
{
return K052109_set_RMRD_line(a2 & 1);
}

original_code:
static void gbusters_1f98_w(offs_t offset,data_t data)
{
 K052109_set_RMRD_line((data & 0x01) ? 1 : 0);
}

canonical_original_code:
static void gbusters_1f98_w(unsigned int offset, unsigned int data)
{
 K052109_set_RMRD_line((data & 0x01) ? 1 : 0);
}


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

*a3 |= (32 * (unsigned __int16)*a4) & 0x200 | ((unsigned __int16)*a4 << 8) & 0xD00 | (a2 << 12);
result = layer_colorbase[a1] + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

*a3 |= (32 * (unsigned __int16)*a4) & 0x200 | ((unsigned __int16)*a4 << 8) & 0xD00 | (a2 << 12);
result = layer_colorbase[a1] + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x0d) << 8) | ((*color & 0x10) << 5) | (bank << 12);
 *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x0d) << 8) | ((*color & 0x10) << 5) | (bank << 12);
 *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
}

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

variable_types: v int


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

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

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

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

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}

variable_types:
offset
unsigned int


original_code:
void ssozumo_paletteram_w(offs_t offset,data_t data)
{
 int bit0, bit1, bit2, bit3, val;
 int r, g, b;
 int offs2;
 paletteram[offset] = data;
 offs2 = offset & 0x0f;
 val = paletteram[offs2];
 bit0 = (val >> 0) & 0x01;
 bit1 = (val >> 1) & 0x01;
 bit2 = (val >> 2) & 0x01;
 bit3 = (val >> 3) & 0x01;
 r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 val = paletteram[offs2 | 0x10];
 bit0 = (val >> 0) & 0x01;
 bit1 = (val >> 1) & 0x01;
 bit2 = (val >> 2) & 0x01;
 bit3 = (val >> 3) & 0x01;
 g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 val = paletteram[offs2 | 0x20];
 bit0 = (val >> 0) & 0x01;
 bit1 = (val >> 1) & 0x01;
 bit2 = (val >> 2) & 0x01;
 bit3 = (val >> 3) & 0x01;
 b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 palette_change_color(offs2 + 64, r, g, b);
}

canonical_original_code:
void ssozumo_paletteram_w(unsigned int offset, unsigned int data)
{
 int bit0; int bit1; int bit2; int bit3; int val;
 int r; int g; int b;
 int offs2;
 paletteram[offset] = data;
 offs2 = offset & 0x0f;
 val = paletteram[offs2];
 bit0 = (val >> 0) & 0x01;
 bit1 = (val >> 1) & 0x01;
 bit2 = (val >> 2) & 0x01;
 bit3 = (val >> 3) & 0x01;
 r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 val = paletteram[offs2 | 0x10];
 bit0 = (val >> 0) & 0x01;
 bit1 = (val >> 1) & 0x01;
 bit2 = (val >> 2) & 0x01;
 bit3 = (val >> 3) & 0x01;
 g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 val = paletteram[offs2 | 0x20];
 bit0 = (val >> 0) & 0x01;
 bit1 = (val >> 1) & 0x01;
 bit2 = (val >> 2) & 0x01;
 bit3 = (val >> 3) & 0x01;
 b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 palette_change_color(offs2 + 64, r, g, b);
}

variable_types:
data
unsigned int

variable_types: val int

variable_types: r int

variable_types: g int

variable_types: b int


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

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

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

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

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

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


decompiled_code:
__int64 ssozumo_vh_stop()
{
free(dirtybuffer);
return bitmap_free(tmpbitmap);
}

canonical_decompiled_code:
__int64 func3()
{
free(dirtybuffer);
return bitmap_free(tmpbitmap);
}

original_code:
void ssozumo_vh_stop(void)
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
}

canonical_original_code:
void ssozumo_vh_stop()
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
}


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

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

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

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


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

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

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

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

variable_types: coin int


decompiled_code:
void spiders_irq3b()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void spiders_irq3b(int state) { }

canonical_original_code: void spiders_irq3b(int state) { }

variable_types: state int


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

vrom_ctrl_mode = (a2 >> 7) & 1;
result = (a2 >> 4) & 3;
vrom_ctrl_latch = (a2 >> 4) & 3;
vrom_ctrl_data = ~(_BYTE)a2 & 0xF;
return result;
}

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

vrom_ctrl_mode = (a2 >> 7) & 1;
result = (a2 >> 4) & 3;
vrom_ctrl_latch = (a2 >> 4) & 3;
vrom_ctrl_data = ~(_BYTE)a2 & 0xF;
return result;
}

original_code:
void spiders_vrif_w(offs_t offset,data_t data)
{
 vrom_ctrl_mode=(data&0x80)>>7;
 vrom_ctrl_latch=(data&0x30)>>4;
 vrom_ctrl_data=15-(data&0x0f);
}

canonical_original_code:
void spiders_vrif_w(unsigned int offset, unsigned int data)
{
 vrom_ctrl_mode=(data&0x80)>>7;
 vrom_ctrl_latch=(data&0x30)>>4;
 vrom_ctrl_data=15-(data&0x0f);
}


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

switch ( crtc6845_address_latch )
{
case 0:
result = crtc6845_horiz_total;
break;
case 1:
result = crtc6845_horiz_disp;
break;
case 2:
result = crtc6845_horiz_sync_pos;
break;
case 3:
result = crtc6845_sync_width;
break;
case 4:
result = crtc6845_vert_total;
break;
case 5:
result = crtc6845_vert_total_adj;
break;
case 6:
result = crtc6845_vert_disp;
break;
case 7:
result = crtc6845_vert_sync_pos;
break;
case 8:
result = crtc6845_intl_skew;
break;
case 9:
result = crtc6845_max_ras_addr;
break;
case 0xA:
result = crtc6845_cursor_start_ras;
break;
case 0xB:
result = crtc6845_cursor_end_ras;
break;
case 0xD:
result = crtc6845_start_addr;
break;
case 0xF:
result = crtc6845_cursor;
break;
case 0x11:
result = crtc6845_light_pen;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( crtc6845_address_latch )
{
case 0:
result = crtc6845_horiz_total;
break;
case 1:
result = crtc6845_horiz_disp;
break;
case 2:
result = crtc6845_horiz_sync_pos;
break;
case 3:
result = crtc6845_sync_width;
break;
case 4:
result = crtc6845_vert_total;
break;
case 5:
result = crtc6845_vert_total_adj;
break;
case 6:
result = crtc6845_vert_disp;
break;
case 7:
result = crtc6845_vert_sync_pos;
break;
case 8:
result = crtc6845_intl_skew;
break;
case 9:
result = crtc6845_max_ras_addr;
break;
case 0xA:
result = crtc6845_cursor_start_ras;
break;
case 0xB:
result = crtc6845_cursor_end_ras;
break;
case 0xD:
result = crtc6845_start_addr;
break;
case 0xF:
result = crtc6845_cursor;
break;
case 0x11:
result = crtc6845_light_pen;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
data_t crtc6845_register_r(offs_t offset)
{
 int retval=0;
 switch(crtc6845_address_latch)
 {
  case 0:
   retval=crtc6845_horiz_total;
   break;
  case 1:
   retval=crtc6845_horiz_disp;
   break;
  case 2:
   retval=crtc6845_horiz_sync_pos;
   break;
  case 3:
   retval=crtc6845_sync_width;
   break;
  case 4:
   retval=crtc6845_vert_total;
   break;
  case 5:
   retval=crtc6845_vert_total_adj;
   break;
  case 6:
   retval=crtc6845_vert_disp;
   break;
  case 7:
   retval=crtc6845_vert_sync_pos;
   break;
  case 8:
   retval=crtc6845_intl_skew;
   break;
  case 9:
   retval=crtc6845_max_ras_addr;
   break;
  case 10:
   retval=crtc6845_cursor_start_ras;
   break;
  case 11:
   retval=crtc6845_cursor_end_ras;
   break;
  case 12:
   retval=(crtc6845_start_addr&0x3f)>>8;
   break;
  case 13:
   retval=crtc6845_start_addr&0xff;
   break;
  case 14:
   retval=(crtc6845_cursor&0x3f)>>8;
   break;
  case 15:
   retval=crtc6845_cursor&0xff;
   break;
  case 16:
   retval=(crtc6845_light_pen&0x3f)>>8;
   break;
  case 17:
   retval=crtc6845_light_pen&0xff;
   break;
  default:
   break;
 }
        return retval;
}

canonical_original_code:
unsigned int crtc6845_register_r(unsigned int offset)
{
 int retval = 0;
 switch(crtc6845_address_latch)
 {
  case 0:
   retval=crtc6845_horiz_total;
   break;
  case 1:
   retval=crtc6845_horiz_disp;
   break;
  case 2:
   retval=crtc6845_horiz_sync_pos;
   break;
  case 3:
   retval=crtc6845_sync_width;
   break;
  case 4:
   retval=crtc6845_vert_total;
   break;
  case 5:
   retval=crtc6845_vert_total_adj;
   break;
  case 6:
   retval=crtc6845_vert_disp;
   break;
  case 7:
   retval=crtc6845_vert_sync_pos;
   break;
  case 8:
   retval=crtc6845_intl_skew;
   break;
  case 9:
   retval=crtc6845_max_ras_addr;
   break;
  case 10:
   retval=crtc6845_cursor_start_ras;
   break;
  case 11:
   retval=crtc6845_cursor_end_ras;
   break;
  case 12:
   retval=(crtc6845_start_addr&0x3f)>>8;
   break;
  case 13:
   retval=crtc6845_start_addr&0xff;
   break;
  case 14:
   retval=(crtc6845_cursor&0x3f)>>8;
   break;
  case 15:
   retval=crtc6845_cursor&0xff;
   break;
  case 16:
   retval=(crtc6845_light_pen&0x3f)>>8;
   break;
  case 17:
   retval=crtc6845_light_pen&0xff;
   break;
  default:
   break;
 }
        return retval;
}

variable_types: retval int


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

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

original_code: void spiders_irq0b(int state) { cpu_set_irq_line(0,0,state ? 1 : 0); }


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

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

original_code: void spiders_irq1a(int state) { cpu_set_irq_line(0,0,state ? 1 : 0); }


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

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

original_code: void spiders_irq1b(int state) { cpu_set_irq_line(0,0,state ? 1 : 0); }


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

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

original_code: void spiders_irq2a(int state) { cpu_set_irq_line(0,0,state ? 1 : 0); }


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

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

original_code: void spiders_irq2b(int state) { cpu_set_irq_line(0,0,state ? 1 : 0); }


decompiled_code:
__int64 spiders_init_machine()
{
pia_unconfig();
pia_config(0LL, 0LL, &pia_0_intf);
pia_config(1LL, 1LL, pia_1_intf);
pia_config(2LL, 0LL, &pia_2_intf);
pia_config(3LL, 0LL, &pia_3_intf);
return pia_reset();
}

canonical_decompiled_code:
__int64 func12()
{
pia_unconfig();
pia_config(0LL, 0LL, &pia_0_intf);
pia_config(1LL, 1LL, pia_1_intf);
pia_config(2LL, 0LL, &pia_2_intf);
pia_config(3LL, 0LL, &pia_3_intf);
return pia_reset();
}

original_code:
void spiders_init_machine(void)
{
 pia_unconfig();
 pia_config(0, 0 | 0, &pia_0_intf);
 pia_config(1, 1 | 0, &pia_1_intf);
 pia_config(2, 0 | 0, &pia_2_intf);
 pia_config(3, 0 | 0, &pia_3_intf);
 pia_reset();
}

canonical_original_code:
void spiders_init_machine()
{
 pia_unconfig();
 pia_config(0, 0 | 0, &pia_0_intf);
 pia_config(1, 1 | 0, &pia_1_intf);
 pia_config(2, 0 | 0, &pia_2_intf);
 pia_config(3, 0 | 0, &pia_3_intf);
 pia_reset();
}


decompiled_code:
__int64 spiders_timed_irq()
{
char v0; // al
char v1; // al
unsigned int v2; // eax

v0 = input_port_0_r(0LL);
pia_0_ca1_w(0LL, v0 & 1);
v1 = input_port_0_r(0LL);
pia_0_ca2_w(0LL, v1 & 2);
v2 = input_port_6_r(0LL);
pia_0_cb1_w(0LL, v2);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func13()
{
char v0; // al
char v1; // al
unsigned int v2; // eax

v0 = input_port_0_r(0LL);
pia_0_ca1_w(0LL, v0 & 1);
v1 = input_port_0_r(0LL);
pia_0_ca2_w(0LL, v1 & 2);
v2 = input_port_6_r(0LL);
pia_0_cb1_w(0LL, v2);
return ignore_interrupt();
}

original_code:
int spiders_timed_irq(void)
{
 pia_0_ca1_w(0 , input_port_0_r(0)&0x01);
 pia_0_ca2_w(0 , input_port_0_r(0)&0x02);
 pia_0_cb1_w(0 , input_port_6_r(0));
 return ignore_interrupt();
}

canonical_original_code:
int spiders_timed_irq()
{
 pia_0_ca1_w(0 , input_port_0_r(0)&0x01);
 pia_0_ca2_w(0 , input_port_0_r(0)&0x02);
 pia_0_cb1_w(0 , input_port_6_r(0));
 return ignore_interrupt();
}


decompiled_code:
__int64 spiders_vrom_r()
{
__int64 v0; // rdx
__int64 result; // rax

v0 = memory_region(137LL);
result = (unsigned int)vrom_ctrl_mode;
if ( vrom_ctrl_mode )
return *(unsigned __int8 *)(v0 + vrom_address++);
if ( vrom_ctrl_latch == 2 )
{
vrom_address = (vrom_ctrl_data << 8) | vrom_address & 0xF0FF;
}
else if ( vrom_ctrl_latch > 2 )
{
if ( vrom_ctrl_latch == 3 )
vrom_address = (vrom_ctrl_data << 12) | vrom_address & 0xFFF;
}
else if ( vrom_ctrl_latch )
{
if ( vrom_ctrl_latch == 1 )
vrom_address = (16 * vrom_ctrl_data) | vrom_address & 0xFF0F;
}
else
{
vrom_address = vrom_ctrl_data | vrom_address & 0xFFF0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rdx
__int64 result; // rax

v0 = memory_region(137LL);
result = (unsigned int)vrom_ctrl_mode;
if ( vrom_ctrl_mode )
return *(unsigned __int8 *)(v0 + vrom_address++);
if ( vrom_ctrl_latch == 2 )
{
vrom_address = (vrom_ctrl_data << 8) | vrom_address & 0xF0FF;
}
else if ( vrom_ctrl_latch > 2 )
{
if ( vrom_ctrl_latch == 3 )
vrom_address = (vrom_ctrl_data << 12) | vrom_address & 0xFFF;
}
else if ( vrom_ctrl_latch )
{
if ( vrom_ctrl_latch == 1 )
vrom_address = (16 * vrom_ctrl_data) | vrom_address & 0xFF0F;
}
else
{
vrom_address = vrom_ctrl_data | vrom_address & 0xFFF0;
result = 0LL;
}
return result;
}

original_code:
data_t spiders_vrom_r(offs_t offset)
{
 int retval;
 unsigned char *RAM = memory_region(REGION_GFX1);
 if(vrom_ctrl_mode)
 {
  retval=RAM[vrom_address];
  vrom_address++;
 }
 else
 {
  switch(vrom_ctrl_latch)
  {
   case 0:
    vrom_address&=0xfff0;
    vrom_address|=vrom_ctrl_data;
    break;
   case 1:
    vrom_address&=0xff0f;
    vrom_address|=vrom_ctrl_data<<4;
    break;
   case 2:
    vrom_address&=0xf0ff;
    vrom_address|=vrom_ctrl_data<<8;
    break;
   case 3:
    vrom_address&=0x0fff;
    vrom_address|=vrom_ctrl_data<<12;
    break;
   default:
    break;
  }
  retval=0;
 }
 return retval;
}

canonical_original_code:
unsigned int spiders_vrom_r(unsigned int offset)
{
 int retval;
 unsigned char *RAM = memory_region(REGION_GFX1);
 if(vrom_ctrl_mode)
 {
  retval=RAM[vrom_address];
  vrom_address++;
 }
 else
 {
  switch(vrom_ctrl_latch)
  {
   case 0:
    vrom_address&=0xfff0;
    vrom_address|=vrom_ctrl_data;
    break;
   case 1:
    vrom_address&=0xff0f;
    vrom_address|=vrom_ctrl_data<<4;
    break;
   case 2:
    vrom_address&=0xf0ff;
    vrom_address|=vrom_ctrl_data<<8;
    break;
   case 3:
    vrom_address&=0x0fff;
    vrom_address|=vrom_ctrl_data<<12;
    break;
   default:
    break;
  }
  retval=0;
 }
 return retval;
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 spiders_vh_start()
{
__int64 i; // rdx
void *v1; // rdi

tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap )
return 1LL;
for ( i = 0LL; i != 256; ++i )
bitflip[i] = ((int)i >> 7) & 1 | ((int)i >> 5) & 2 | ((int)i >> 3) & 4 | ((int)i >> 1) & 8 | (2 * (_BYTE)i) & 0x10 | (8 * (_BYTE)i) & 0x20 | (32 * (_BYTE)i) & 0x40 | (unsigned __int8)((_BYTE)i << 7);
v1 = malloc(0x8000uLL);
screenbuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, 0x8000uLL);
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 i; // rdx
void *v1; // rdi

tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap )
return 1LL;
for ( i = 0LL; i != 256; ++i )
bitflip[i] = ((int)i >> 7) & 1 | ((int)i >> 5) & 2 | ((int)i >> 3) & 4 | ((int)i >> 1) & 8 | (2 * (_BYTE)i) & 0x10 | (8 * (_BYTE)i) & 0x20 | (32 * (_BYTE)i) & 0x40 | (unsigned __int8)((_BYTE)i << 7);
v1 = malloc(0x8000uLL);
screenbuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, 0x8000uLL);
return 0LL;
}

original_code:
int spiders_vh_start(void)
{
 int loop;
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0) return 1;
 for(loop=0;loop<256;loop++)
 {
  bitflip[loop]=(loop&0x01)?0x80:0x00;
  bitflip[loop]|=(loop&0x02)?0x40:0x00;
  bitflip[loop]|=(loop&0x04)?0x20:0x00;
  bitflip[loop]|=(loop&0x08)?0x10:0x00;
  bitflip[loop]|=(loop&0x10)?0x08:0x00;
  bitflip[loop]|=(loop&0x20)?0x04:0x00;
  bitflip[loop]|=(loop&0x40)?0x02:0x00;
  bitflip[loop]|=(loop&0x80)?0x01:0x00;
 }
 if ((screenbuffer = (int*)malloc(0x2000*sizeof(int))) == 0) return 1;
 memset(screenbuffer,1,0x2000*sizeof(int));
 return 0;
}

canonical_original_code:
int spiders_vh_start()
{
 int loop;
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0) return 1;
 for(loop=0;loop<256;loop++)
 {
  bitflip[loop]=(loop&0x01)?0x80:0x00;
  bitflip[loop]|=(loop&0x02)?0x40:0x00;
  bitflip[loop]|=(loop&0x04)?0x20:0x00;
  bitflip[loop]|=(loop&0x08)?0x10:0x00;
  bitflip[loop]|=(loop&0x10)?0x08:0x00;
  bitflip[loop]|=(loop&0x20)?0x04:0x00;
  bitflip[loop]|=(loop&0x40)?0x02:0x00;
  bitflip[loop]|=(loop&0x80)?0x01:0x00;
 }
 if ((screenbuffer = (int *)malloc(0x2000*sizeof(int))) == 0) return 1;
 memset(screenbuffer,1,0x2000*sizeof(int));
 return 0;
}

variable_types: loop int


decompiled_code:
void spiders_vh_stop()
{
bitmap_free(tmpbitmap);
free(screenbuffer);
}

canonical_decompiled_code:
void func16()
{
bitmap_free(tmpbitmap);
free(screenbuffer);
}

original_code:
void spiders_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 free(screenbuffer);
}


decompiled_code:
__int64 __fastcall spiders_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // eax
__int16 v3; // ax
__int16 v4; // dx
int v5; // er15
__int64 result; // rax
int v7; // ebp
int v8; // er12
int v9; // er13
unsigned int v10; // ebx
unsigned int v11; // er15
__int64 i; // [rsp+0h] [rbp-78h]
__int64 v13; // [rsp+18h] [rbp-60h]
__int64 v14; // [rsp+20h] [rbp-58h]
int v15; // [rsp+28h] [rbp-50h]
__int16 v16; // [rsp+2Ch] [rbp-4Ch]
__int64 v17; // [rsp+30h] [rbp-48h]
__int16 v18; // [rsp+38h] [rbp-40h]

v17 = memory_region(129LL);
v2 = 8 * crtc6845_vert_disp * crtc6845_horiz_disp;
v14 = v2;
if ( spiders_video_flip )
{
v3 = crtc6845_start_addr + v2;
v4 = v3 - 1;
v16 = -1;
if ( (_BYTE)v3 == 0x81 )
v4 = v3 - 129;
}
else
{
v4 = crtc6845_start_addr;
v16 = 1;
}
v5 = v4 & 0xFBFF;
result = (unsigned int)(v5 + 0x2000);
if ( crtc6845_page_flip )
v5 = (v4 & 0xFBFF) + 0x2000;
if ( v14 )
{
for ( i = 0LL; i != v14; result = i )
{
if ( spiders_video_flip )
{
v7 = bitflip[*(unsigned __int8 *)(v17 + v5)];
v8 = bitflip[*(unsigned __int8 *)(v17 + v5 + 0x4000)];
v9 = bitflip[*(unsigned __int8 *)(v17 + v5 + 0x8000)];
}
else
{
v7 = *(unsigned __int8 *)(v17 + v5);
v8 = *(unsigned __int8 *)(v17 + v5 + 0x4000);
v9 = *(unsigned __int8 *)(v17 + v5 + 0x8000);
}
v15 = v7 | (v9 << 16) | (v8 << 8);
v13 = v5 & 0x1FFF;
if ( *((_DWORD *)screenbuffer + v13) != v15 )
{
v10 = 8 * ((int)i % 32);
v18 = v5;
v11 = v10 + 8;
do
{
plot_pixel2(
a1,
tmpbitmap,
v10,
(unsigned int)((int)i / 32),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * ((v7 & 1) + ((2 * (unsigned __int8)v8) & 2 | (4 * (unsigned __int8)v9) & 4))));
v7 >>= 1;
v8 >>= 1;
v9 >>= 1;
++v10;
}
while ( v10 != v11 );
LOWORD(v5) = v18;
*((_DWORD *)screenbuffer + v13) = v15;
}
v5 = (v16 + (_WORD)v5) & 0x3FFF;
++i;
}
}
if ( a2 )
result = copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return result;
}

original_code:
void spiders_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int loop,data0,data1,data2,col;
 size_t crtc6845_mem_size;
 int video_addr,increment;
 unsigned char *RAM = memory_region(REGION_CPU1);
 crtc6845_mem_size=crtc6845_horiz_disp*crtc6845_vert_disp*8;
 if(spiders_video_flip)
 {
  video_addr=crtc6845_start_addr+(crtc6845_mem_size-1);
  if((video_addr&0xff)==0x80) video_addr-=0x80;
  increment=-1;
 }
 else
 {
  video_addr=crtc6845_start_addr;
  increment=1;
 }
 video_addr&=0xfbff;
 if(crtc6845_page_flip) video_addr+=0x2000;
 for(loop=0;loop<crtc6845_mem_size;loop++)
 {
  int i,x,y,combo;
  if(spiders_video_flip)
  {
   data0=bitflip[RAM[0x0000+video_addr]];
   data1=bitflip[RAM[0x4000+video_addr]];
   data2=bitflip[RAM[0x8000+video_addr]];
  }
  else
  {
   data0=RAM[0x0000+video_addr];
   data1=RAM[0x4000+video_addr];
   data2=RAM[0x8000+video_addr];
  }
  combo=data0|(data1<<8)|(data2<<16);
  if(screenbuffer[video_addr&0x1fff]!=combo)
  {
   y=loop/0x20;
   for(i=0;i<8;i++)
   {
    x=((loop%0x20)<<3)+i;
    col=((data2&0x01)<<2)+((data1&0x01)<<1)+(data0&0x01);
    plot_pixel2(bitmap, tmpbitmap, x, y, Machine->pens[col]);
    data0 >>= 1;
    data1 >>= 1;
    data2 >>= 1;
   }
   screenbuffer[video_addr&0x1fff]=combo;
  }
  video_addr+=increment;
  video_addr&=0x3fff;
 }
 if (full_refresh)
 {
  copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
void spiders_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int loop; int data0; int data1; int data2; int col;
 unsigned long crtc6845_mem_size;
 int video_addr; int increment;
 unsigned char *RAM = memory_region(REGION_CPU1);
 crtc6845_mem_size=crtc6845_horiz_disp*crtc6845_vert_disp*8;
 if(spiders_video_flip)
 {
  video_addr=crtc6845_start_addr+(crtc6845_mem_size-1);
  if((video_addr&0xff)==0x80) video_addr-=0x80;
  increment=-1;
 }
 else
 {
  video_addr=crtc6845_start_addr;
  increment=1;
 }
 video_addr&=0xfbff;
 if(crtc6845_page_flip) video_addr+=0x2000;
 for(loop=0;loop<crtc6845_mem_size;loop++)
 {
  int i; int x; int y; int combo;
  if(spiders_video_flip)
  {
   data0=bitflip[RAM[0x0000+video_addr]];
   data1=bitflip[RAM[0x4000+video_addr]];
   data2=bitflip[RAM[0x8000+video_addr]];
  }
  else
  {
   data0=RAM[0x0000+video_addr];
   data1=RAM[0x4000+video_addr];
   data2=RAM[0x8000+video_addr];
  }
  combo=data0|(data1<<8)|(data2<<16);
  if(screenbuffer[video_addr&0x1fff]!=combo)
  {
   y=loop/0x20;
   for(i=0;i<8;i++)
   {
    x=((loop%0x20)<<3)+i;
    col=((data2&0x01)<<2)+((data1&0x01)<<1)+(data0&0x01);
    plot_pixel2(bitmap, tmpbitmap, x, y, Machine->pens[col]);
    data0 >>= 1;
    data1 >>= 1;
    data2 >>= 1;
   }
   screenbuffer[video_addr&0x1fff]=combo;
  }
  video_addr+=increment;
  video_addr&=0x3fff;
 }
 if (full_refresh)
 {
  copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

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

variable_types: col int

variable_types: increment int

variable_types: i int

variable_types: x int

variable_types: y int

variable_types: combo int