decompiled_code:
void *init_domino()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 1LL, 1LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

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

mcr_sound_config = 1;
install_port_write_handler(0LL, 1LL, 1LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_domino(void)
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x01, 0x01, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_domino()
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x01, 0x01, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 49152, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 49152, 2048LL);
return result;
}

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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 49152, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 49152, 2048LL);
return result;
}

original_code:
static void mcr2_nvram_handler(void *file, int read_or_write)
{
 unsigned char *ram = memory_region(REGION_CPU1);
 if (read_or_write)
  osd_fwrite(file, &ram[0xc000], 0x800);
 else if (file)
  osd_fread(file, &ram[0xc000], 0x800);
}

variable_types:
file
void *

variable_types:
ram
unsigned char *

return_type: void


decompiled_code:
void *init_kroozr()
{
void *result; // rax

mcr_sound_config = 1;
install_port_read_handler(0LL, 1LL, 1LL, kroozr_dial_r);
install_port_read_handler(0LL, 2LL, 2LL, kroozr_trakball_x_r);
install_port_read_handler(0LL, 4LL, 4LL, kroozr_trakball_y_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

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

mcr_sound_config = 1;
install_port_read_handler(0LL, 1LL, 1LL, kroozr_dial_r);
install_port_read_handler(0LL, 2LL, 2LL, kroozr_trakball_x_r);
install_port_read_handler(0LL, 4LL, 4LL, kroozr_trakball_y_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_kroozr(void)
{
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x01, 0x01, kroozr_dial_r);
 install_port_read_handler(0, 0x02, 0x02, kroozr_trakball_x_r);
 install_port_read_handler(0, 0x04, 0x04, kroozr_trakball_y_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_kroozr()
{
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x01, 0x01, kroozr_dial_r);
 install_port_read_handler(0, 0x02, 0x02, kroozr_trakball_x_r);
 install_port_read_handler(0, 0x04, 0x04, kroozr_trakball_y_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


decompiled_code:
void *init_wacko()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 4LL, 4LL, wacko_mux_select_w);
install_port_read_handler(0LL, 1LL, 2LL, wacko_trackball_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

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

mcr_sound_config = 1;
install_port_write_handler(0LL, 4LL, 4LL, wacko_mux_select_w);
install_port_read_handler(0LL, 1LL, 2LL, wacko_trackball_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_wacko(void)
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x04, 0x04, wacko_mux_select_w);
 install_port_read_handler(0, 0x01, 0x02, wacko_trackball_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_wacko()
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x04, 0x04, wacko_mux_select_w);
 install_port_read_handler(0, 0x01, 0x02, wacko_trackball_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


decompiled_code:
__int64 kroozr_trakball_y_r()
{
char v0; // al
unsigned int v1; // edx

v0 = readinputport(6LL);
v1 = 48;
if ( (v0 & 8) == 0 )
v1 = (v0 & 4) == 0 ? 100 : 152;
return v1;
}

original_code:
static data_t kroozr_trakball_y_r(offs_t offset)
{
 int val = readinputport(6);
 if (val & 0x08)
  return 0x64 - 0x34;
 if (val & 0x04)
  return 0x64 + 0x34;
 return 0x64;
}

canonical_original_code:
static unsigned int kroozr_trakball_y_r(unsigned int offset)
{
 int val = readinputport(6);
 if (val & 0x08)
  return 0x64 - 0x34;
 if (val & 0x04)
  return 0x64 + 0x34;
 return 0x64;
}

variable_types:
offset
unsigned int

variable_types: val int

return_type: unsigned int


decompiled_code:
__int64 kroozr_trakball_x_r()
{
char v0; // al
unsigned int v1; // edx

v0 = readinputport(6LL);
v1 = 48;
if ( (v0 & 2) == 0 )
v1 = (v0 & 1) == 0 ? 100 : 152;
return v1;
}

original_code:
static data_t kroozr_trakball_x_r(offs_t offset)
{
 int val = readinputport(6);
 if (val & 0x02)
  return 0x64 - 0x34;
 if (val & 0x01)
  return 0x64 + 0x34;
 return 0x64;
}

canonical_original_code:
static unsigned int kroozr_trakball_x_r(unsigned int offset)
{
 int val = readinputport(6);
 if (val & 0x02)
  return 0x64 - 0x34;
 if (val & 0x01)
  return 0x64 + 0x34;
 return 0x64;
}


decompiled_code:
__int64 kroozr_dial_r()
{
int v0; // ebx

v0 = readinputport(7LL);
return (unsigned int)readinputport(1LL) | (v0 >> 1) & 0x40 | (v0 >> 4) & 7;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx

v0 = readinputport(7LL);
return (unsigned int)readinputport(1LL) | (v0 >> 1) & 0x40 | (v0 >> 4) & 7;
}

original_code:
static data_t kroozr_dial_r(offs_t offset)
{
 int dial = readinputport(7);
 int val = readinputport(1);
 val |= (dial & 0x80) >> 1;
 val |= (dial & 0x70) >> 4;
 return val;
}

canonical_original_code:
static unsigned int kroozr_dial_r(unsigned int offset)
{
 int dial = readinputport(7);
 int val = readinputport(1);
 val |= (dial & 0x80) >> 1;
 val |= (dial & 0x70) >> 4;
 return val;
}

variable_types: dial int


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

if ( wacko_mux_select )
result = readinputport((unsigned int)(a1 + 6));
else
result = readinputport((unsigned int)(a1 + 1));
return result;
}

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

if ( wacko_mux_select )
result = readinputport((unsigned int)(a1 + 6));
else
result = readinputport((unsigned int)(a1 + 1));
return result;
}

original_code:
static data_t wacko_trackball_r(offs_t offset)
{
 if (!wacko_mux_select)
  return readinputport(1 + offset);
 else
  return readinputport(6 + offset);
}

canonical_original_code:
static unsigned int wacko_trackball_r(unsigned int offset)
{
 if (!wacko_mux_select)
  return readinputport(1 + offset);
 else
  return readinputport(6 + offset);
}


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

variable_types: i int


decompiled_code:
void *__fastcall sonson_vh_screenrefresh(__int64 a1)
{
int v1; // ebp
__int64 v2; // r12
unsigned __int8 *v3; // rsi
char *v4; // rax
void *result; // rax
int v6; // er12
__int64 v7; // rbp
int v8[5]; // [rsp+0h] [rbp-A8h] BYREF
char v9; // [rsp+14h] [rbp-94h] BYREF
char v10; // [rsp+80h] [rbp-28h] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((*(_BYTE *)(colorram + v2) & 3) << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 2,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v8[0] = 0;
v8[1] = 0;
v8[2] = 0;
v8[3] = 0;
v8[4] = 0;
v3 = (unsigned __int8 *)sonson_scrollx;
v4 = &v9;
do
{
*(_DWORD *)v4 = -*v3;
v4 += 4;
}
while ( &v10 != v4 );
copyscrollbitmap(a1, tmpbitmap, 32LL, v8, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v7 + 2)
+ ((8 * *(unsigned __int8 *)(spriteram + v7 + 1)) & 0x100u),
*(_BYTE *)(spriteram + v7 + 1) & 0x1F,
~*(_BYTE *)(spriteram + v7 + 1) & 0x40,
(unsigned __int8)~*(_BYTE *)(spriteram + v7 + 1) & 0x80,
*(unsigned __int8 *)(spriteram + v7 + 3),
*(unsigned __int8 *)(spriteram + v7),
Machine + 776LL,
2LL,
0LL);
v7 -= 4LL;
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // ebp
__int64 v2; // r12
unsigned __int8 *v3; // rsi
char *v4; // rax
void *result; // rax
int v6; // er12
__int64 v7; // rbp
int v8[5]; // [rsp+0h] [rbp-A8h] BYREF
char v9; // [rsp+14h] [rbp-94h] BYREF
char v10; // [rsp+80h] [rbp-28h] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((*(_BYTE *)(colorram + v2) & 3) << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 2,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v8[0] = 0;
v8[1] = 0;
v8[2] = 0;
v8[3] = 0;
v8[4] = 0;
v3 = (unsigned __int8 *)sonson_scrollx;
v4 = &v9;
do
{
*(_DWORD *)v4 = -*v3;
v4 += 4;
}
while ( &v10 != v4 );
copyscrollbitmap(a1, tmpbitmap, 32LL, v8, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v7 + 2)
+ ((8 * *(unsigned __int8 *)(spriteram + v7 + 1)) & 0x100u),
*(_BYTE *)(spriteram + v7 + 1) & 0x1F,
~*(_BYTE *)(spriteram + v7 + 1) & 0x40,
(unsigned __int8)~*(_BYTE *)(spriteram + v7 + 1) & 0x80,
*(unsigned __int8 *)(spriteram + v7 + 3),
*(unsigned __int8 *)(spriteram + v7),
Machine + 776LL,
2LL,
0LL);
v7 -= 4LL;
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

original_code:
void sonson_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * (colorram[offs] & 3),
     colorram[offs] >> 2,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i,scroll[32];
  for (i = 0;i < 5;i++)
   scroll[i] = 0;
  for (i = 5;i < 32;i++)
   scroll[i] = -(*sonson_scrollx);
  copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2] + ((spriteram[offs + 1] & 0x20) << 3),
    spriteram[offs + 1] & 0x1f,
    ~spriteram[offs + 1] & 0x40,~spriteram[offs + 1] & 0x80,
    spriteram[offs + 3],spriteram[offs + 0],
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void sonson_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * (colorram[offs] & 3),
     colorram[offs] >> 2,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i; int scroll[32];
  for (i = 0;i < 5;i++)
   scroll[i] = 0;
  for (i = 5;i < 32;i++)
   scroll[i] = -(*sonson_scrollx);
  copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2] + ((spriteram[offs + 1] & 0x20) << 3),
    spriteram[offs + 1] & 0x1f,
    ~spriteram[offs + 1] & 0x40,~spriteram[offs + 1] & 0x80,
    spriteram[offs + 3],spriteram[offs + 0],
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types:
scroll
int [32]


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

if ( !last_0 && a2 == 1 )
result = cpu_cause_interrupt(1LL, 2LL);
last_0 = a2;
return result;
}

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

if ( !last_0 && a2 == 1 )
result = cpu_cause_interrupt(1LL, 2LL);
last_0 = a2;
return result;
}

original_code:
void sonson_sh_irqtrigger_w(offs_t offset,data_t data)
{
 static int last;
 if (last == 0 && data == 1)
 {
  cpu_cause_interrupt(1,2);
 }
 last = data;
}

canonical_original_code:
void sonson_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last == 0 && data == 1)
 {
  cpu_cause_interrupt(1,2);
 }
 last = data;
}

variable_types:
data
unsigned int

variable_types: last int


decompiled_code:
void __fastcall minivadr_init_palette(__int64 a1)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
}

original_code:
void minivadr_init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette, minivadr_palette, sizeof(minivadr_palette));
}

canonical_original_code:
void minivadr_init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette, minivadr_palette, sizeof(minivadr_palette));
}


decompiled_code:
__int64 __fastcall minivadr_videoram_w(unsigned int a1, unsigned int a2)
{
int v2; // ebp
__int64 result; // rax
unsigned int v4; // ebx
int i; // er13

*(_BYTE *)(videoram + a1) = a2;
v2 = 8 * (a1 & 0x1F);
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= v2 && *(_DWORD *)(Machine + 780LL) >= v2 )
{
v4 = a1 >> 5;
if ( *(_DWORD *)(Machine + 784LL) <= (signed int)(a1 >> 5) && *(_DWORD *)(Machine + 788LL) >= (signed int)v4 )
{
for ( i = 0; i != 8; ++i )
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned int)(v2 + 7 - i),
v4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1)));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
int v2; // ebp
__int64 result; // rax
unsigned int v4; // ebx
int i; // er13

*(_BYTE *)(videoram + a1) = a2;
v2 = 8 * (a1 & 0x1F);
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= v2 && *(_DWORD *)(Machine + 780LL) >= v2 )
{
v4 = a1 >> 5;
if ( *(_DWORD *)(Machine + 784LL) <= (signed int)(a1 >> 5) && *(_DWORD *)(Machine + 788LL) >= (signed int)v4 )
{
for ( i = 0; i != 8; ++i )
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned int)(v2 + 7 - i),
v4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1)));
}
}
return result;
}

original_code:
void minivadr_videoram_w(offs_t offset,data_t data)
{
 int i;
 int x, y;
 int color;
 videoram[offset] = data;
 x = (offset % 32) * 8;
 y = (offset / 32);
 if (x >= Machine->visible_area.min_x &&
   x <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y &&
   y <= Machine->visible_area.max_y)
 {
  for (i = 0; i < 8; i++)
  {
   color = Machine->pens[((data >> i) & 0x01)];
   plot_pixel(Machine->scrbitmap, x + (7 - i), y, color);
  }
 }
}

canonical_original_code:
void minivadr_videoram_w(unsigned int offset, unsigned int data)
{
 int i;
 int x; int y;
 int color;
 videoram[offset] = data;
 x = (offset % 32) * 8;
 y = (offset / 32);
 if (x >= Machine->visible_area.min_x &&
   x <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y &&
   y <= Machine->visible_area.max_y)
 {
  for (i = 0; i < 8; i++)
  {
   color = Machine->pens[((data >> i) & 0x01)];
   plot_pixel(Machine->scrbitmap, x + (7 - i), y, color);
  }
 }
}

variable_types: x int

variable_types: y int

variable_types: color int


original_code:
void YM_DELTAT_ADPCM_Write(YM_DELTAT *DELTAT,int r,int v)
{
 if(r>=0x10) return;
 DELTAT->reg[r] = v;
 switch( r ){
 case 0x00:
  if( v&0x80 ){
   DELTAT->portstate = v&0x90;
   DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
   DELTAT->now_addr = (DELTAT->start)<<1;
   DELTAT->now_step = (1<<(16))-DELTAT->step;
   DELTAT->adpcmx = 0;
   DELTAT->adpcml = 0;
   DELTAT->adpcmd = (127);
   DELTAT->next_leveling=0;
   DELTAT->flag = 1;
   if( !DELTAT->step )
   {
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }
   if(DELTAT->memory == 0){
    if( (3)>=1 ) logerror ("YM Delta-T ADPCM rom not mapped\n");
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }else{
    if( DELTAT->end >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM end out of range: $%08x\n",DELTAT->end);
     DELTAT->end = DELTAT->memory_size - 1;
    }
    if( DELTAT->start >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM start out of range: $%08x\n",DELTAT->start);
     DELTAT->flag = 0;
     DELTAT->portstate = 0x00;
    }
   }
  } else if( v&0x01 ){
   DELTAT->flag = 0;
   DELTAT->portstate = 0x00;
  }
  break;
 case 0x01:
  DELTAT->portcontrol = v&0xff;
  DELTAT->pan = &DELTAT->output_pointer[(v>>6)&0x03];
  break;
 case 0x02:
 case 0x03:
  DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << DELTAT->portshift;
  break;
 case 0x04:
 case 0x05:
  DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << DELTAT->portshift;
  DELTAT->end += (1<<DELTAT->portshift) - 1;
  break;
 case 0x06:
 case 0x07:
 case 0x08:
   break;
 case 0x09:
 case 0x0a:
  DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]);
  DELTAT->step = (UINT32)((float)(DELTAT->delta*(1<<((16)-16)))*(DELTAT->freqbase));
  DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
  break;
 case 0x0b:
  {
   INT32 oldvol = DELTAT->volume;
   DELTAT->volume = (v&0xff)*(DELTAT->output_range/256) / 32768;
   if( oldvol != 0 )
   {
    DELTAT->adpcml = (int)((float)DELTAT->adpcml / (float)oldvol * (float)DELTAT->volume);
    DELTAT->sample_step = (int)((float)DELTAT->sample_step / (float)oldvol * (float)DELTAT->volume);
   }
   DELTAT->volume_w_step = (int)((float)DELTAT->volume * (float)DELTAT->step / (float)(1<<(16)));
  }
  break;
 }
}

canonical_original_code:
void YM_DELTAT_ADPCM_Write(struct deltat_adpcm_state *DELTAT, int r, int v)
{
 if(r>=0x10) return;
 DELTAT->reg[r] = v;
 switch( r ){
 case 0x00:
  if( v&0x80 ){
   DELTAT->portstate = v&0x90;
   DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
   DELTAT->now_addr = (DELTAT->start)<<1;
   DELTAT->now_step = (1<<(16))-DELTAT->step;
   DELTAT->adpcmx = 0;
   DELTAT->adpcml = 0;
   DELTAT->adpcmd = (127);
   DELTAT->next_leveling=0;
   DELTAT->flag = 1;
   if( !DELTAT->step )
   {
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }
   if(DELTAT->memory == 0){
    if( (3)>=1 ) logerror ("YM Delta-T ADPCM rom not mapped\n");
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }else{
    if( DELTAT->end >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM end out of range: $%08x\n",DELTAT->end);
     DELTAT->end = DELTAT->memory_size - 1;
    }
    if( DELTAT->start >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM start out of range: $%08x\n",DELTAT->start);
     DELTAT->flag = 0;
     DELTAT->portstate = 0x00;
    }
   }
  } else if( v&0x01 ){
   DELTAT->flag = 0;
   DELTAT->portstate = 0x00;
  }
  break;
 case 0x01:
  DELTAT->portcontrol = v&0xff;
  DELTAT->pan = &DELTAT->output_pointer[(v>>6)&0x03];
  break;
 case 0x02:
 case 0x03:
  DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << DELTAT->portshift;
  break;
 case 0x04:
 case 0x05:
  DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << DELTAT->portshift;
  DELTAT->end += (1<<DELTAT->portshift) - 1;
  break;
 case 0x06:
 case 0x07:
 case 0x08:
   break;
 case 0x09:
 case 0x0a:
  DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]);
  DELTAT->step = (UINT32)((float)(DELTAT->delta*(1<<((16)-16)))*(DELTAT->freqbase));
  DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
  break;
 case 0x0b:
  {
   int oldvol = DELTAT->volume;
   DELTAT->volume = (v&0xff)*(DELTAT->output_range/256) / 32768;
   if( oldvol != 0 )
   {
    DELTAT->adpcml = (int)((float)DELTAT->adpcml / (float)oldvol * (float)DELTAT->volume);
    DELTAT->sample_step = (int)((float)DELTAT->sample_step / (float)oldvol * (float)DELTAT->volume);
   }
   DELTAT->volume_w_step = (int)((float)DELTAT->volume * (float)DELTAT->step / (float)(1<<(16)));
  }
  break;
 }
}

variable_types: struct deltat_adpcm_state { unsigned char *memory; int memory_size; float freqbase; int *output_pointer; int output_range; unsigned char reg[16]; unsigned char portstate; int portshift; unsigned char flag; unsigned char flagMask; unsigned char now_data; unsigned int now_addr; unsigned int now_step; unsigned int step; unsigned int start; unsigned int end; unsigned int delta; int volume; int *pan; int adpcmx; int adpcml; int volume_w_step; int next_leveling; int sample_step; unsigned char arrivedFlag; } *

variable_types: r int

variable_types: v int

variable_types: oldvol int


original_code:
void YM_DELTAT_ADPCM_Reset(YM_DELTAT *DELTAT,int pan)
{
 DELTAT->now_addr = 0;
 DELTAT->now_step = 0;
 DELTAT->step = 0;
 DELTAT->start = 0;
 DELTAT->end = 0;
 DELTAT->volume = 0;
 DELTAT->pan = &DELTAT->output_pointer[pan];
 DELTAT->arrivedFlag = 0;
 DELTAT->flag = 0;
 DELTAT->adpcmx = 0;
 DELTAT->adpcmd = 127;
 DELTAT->adpcml = 0;
 DELTAT->volume_w_step = 0;
    DELTAT->next_leveling = 0;
 DELTAT->portstate = 0;
}

canonical_original_code:
void YM_DELTAT_ADPCM_Reset(struct deltat_adpcm_state *DELTAT, int pan)
{
 DELTAT->now_addr = 0;
 DELTAT->now_step = 0;
 DELTAT->step = 0;
 DELTAT->start = 0;
 DELTAT->end = 0;
 DELTAT->volume = 0;
 DELTAT->pan = &DELTAT->output_pointer[pan];
 DELTAT->arrivedFlag = 0;
 DELTAT->flag = 0;
 DELTAT->adpcmx = 0;
 DELTAT->adpcmd = 127;
 DELTAT->adpcml = 0;
 DELTAT->volume_w_step = 0;
    DELTAT->next_leveling = 0;
 DELTAT->portstate = 0;
}

variable_types: pan int

user_defined_types: struct deltat_adpcm_state { unsigned char *memory; int memory_size; float freqbase; int *output_pointer; int output_range; unsigned char reg[16]; unsigned char portstate; int portshift; unsigned char flag; unsigned char flagMask; unsigned char now_data; unsigned int now_addr; unsigned int now_step; unsigned int step; unsigned int start; unsigned int end; unsigned int delta; int volume; int *pan; int adpcmx; int adpcml; int volume_w_step; int next_leveling; int sample_step; unsigned char arrivedFlag; }


original_code:
static void K051649_update(int ch, INT16 *buffer, int length)
{
 k051649_sound_channel *voice=channel_list;
 short *mix;
 int i,v,f,j,k;
 memset(mixer_buffer, 0, length * sizeof(short));
 for (j=0; j<5; j++) {
  v=voice[j].volume;
  f=voice[j].frequency;
  k=voice[j].key;
  if (v && f && k)
  {
   const signed char *w = voice[j].waveform;
   int c=voice[j].counter;
   mix = mixer_buffer;
   for (i = 0; i < length; i++)
   {
    int offs;
    c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
    offs = (c >> 16) & 0x1f;
    *mix++ += (w[offs] * v)>>3;
   }
   voice[j].counter = c;
  }
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

canonical_original_code:
static void K051649_update(int ch, short *buffer, int length)
{
 struct k051649_sound_channel *voice = channel_list;
 short *mix;
 int i; int v; int f; int j; int k;
 memset(mixer_buffer, 0, length * sizeof(short));
 for (j=0; j<5; j++) {
  v=voice[j].volume;
  f=voice[j].frequency;
  k=voice[j].key;
  if (v && f && k)
  {
   char *w = voice[j].waveform;
   int c = voice[j].counter;
   mix = mixer_buffer;
   for (i = 0; i < length; i++)
   {
    int offs;
    c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
    offs = (c >> 16) & 0x1f;
    *mix++ += (w[offs] * v)>>3;
   }
   voice[j].counter = c;
  }
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

variable_types: ch int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct k051649_sound_channel { unsigned long counter; int frequency; int volume; int key; char waveform[32]; } *

variable_types:
mix
short *

variable_types: f int

variable_types: j int

variable_types: k int

variable_types:
w
char *

variable_types: c int


decompiled_code:
__int64 __fastcall K051649_sh_start(__int64 a1)
{
__int64 v1; // rbp
void *v2; // rax
void *v3; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K051649", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K051649_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1LL;
v3 = v2;
result = make_mixer_table(5);
if ( (_DWORD)result )
{
free(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbp
void *v2; // rax
void *v3; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K051649", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K051649_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1LL;
v3 = v2;
result = func0(5);
if ( (_DWORD)result )
{
free(v3);
result = 1LL;
}
return result;
}

original_code:
int K051649_sh_start(const struct MachineSound *msound)
{
 const char *snd_name = "K051649";
 k051649_sound_channel *voice=channel_list;
 const struct k051649_interface *intf = (const struct k051649_interface *)msound->sound_interface;
 int i;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K051649_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short int*)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(5))
 {
  free(mixer_buffer);
  return 1;
 }
 for (i=0; i>5; i++) {
  voice[i].frequency = 0;
  voice[i].volume = 0;
  voice[i].counter = 0;
 }
 return 0;
}

canonical_original_code:
int K051649_sh_start(struct MachineSound *msound)
{
 char *snd_name = "K051649";
 struct k051649_sound_channel *voice = channel_list;
 struct k051649_interface *intf = (const struct k051649_interface *)msound->sound_interface;
 int i;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K051649_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short *)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(5))
 {
  free(mixer_buffer);
  return 1;
 }
 for (i=0; i>5; i++) {
  voice[i].frequency = 0;
  voice[i].volume = 0;
  voice[i].counter = 0;
 }
 return 0;
}

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

variable_types: struct k051649_interface { int master_clock; int volume; } *

variable_types: i int

return_type: int

user_defined_types: struct k051649_sound_channel { unsigned long counter; int frequency; int volume; int key; char waveform[32]; }


decompiled_code:
void K051649_sh_stop()
{
free(mixer_table);
free(mixer_buffer);
}

canonical_decompiled_code:
void func3()
{
free(mixer_table);
free(mixer_buffer);
}

original_code:
void K051649_sh_stop(void)
{
 free(mixer_table);
 free(mixer_buffer);
}


decompiled_code:
__int64 __fastcall K051649_volume_w(char a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
v2 = a1 & 7;
result = 7 * v2;
*((_DWORD *)&channel_list + 14 * v2 + 3) = a2 & 0xF;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
v2 = a1 & 7;
result = 7 * v2;
*((_DWORD *)&channel_list + 14 * v2 + 3) = a2 & 0xF;
return result;
}

original_code:
void K051649_volume_w(offs_t offset,data_t data)
{
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset&0x7].volume=data&0xf;
}

canonical_original_code:
void K051649_volume_w(unsigned int offset, unsigned int data)
{
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset&0x7].volume=data&0xf;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

f_0[a1] = a2;
if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
result = (f_0[a1 & 0xE] + (f_0[a1 | 1] << 8)) & 0x3FF;
*((_DWORD *)&channel_list + 14 * (a1 >> 1) + 2) = result;
if ( a1 >> 1 == 3 )
{
result = ((_WORD)dword_418 + ((_WORD)dword_41C << 8)) & 0x3FF;
dword_548 = ((_WORD)dword_418 + ((_WORD)dword_41C << 8)) & 0x3FF;
}
return result;
}

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

f_0[a1] = a2;
if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
result = (f_0[a1 & 0xE] + (f_0[a1 | 1] << 8)) & 0x3FF;
*((_DWORD *)&channel_list + 14 * (a1 >> 1) + 2) = result;
if ( a1 >> 1 == 3 )
{
result = ((_WORD)dword_418 + ((_WORD)dword_41C << 8)) & 0x3FF;
dword_548 = ((_WORD)dword_418 + ((_WORD)dword_41C << 8)) & 0x3FF;
}
return result;
}

original_code:
void K051649_frequency_w(offs_t offset,data_t data)
{
 static int f[10];
 f[offset]=data;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset>>1].frequency=(f[offset&0xe] + (f[offset|1]<<8))&0x3ff;
 if ((offset>>1)==3)
  channel_list[4].frequency=(f[6] + (f[7]<<8))&0x3ff;
}

canonical_original_code:
void K051649_frequency_w(unsigned int offset, unsigned int data)
{
 static int f[10];
 f[offset]=data;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset>>1].frequency=(f[offset&0xe] + (f[offset|1]<<8))&0x3ff;
 if ((offset>>1)==3)
  channel_list[4].frequency=(f[6] + (f[7]<<8))&0x3ff;
}

variable_types:
f
int [10]


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

dword_470 = a2 & 1;
dword_4A8 = a2 & 2;
dword_4E0 = a2 & 4;
result = a2 & 8;
dword_518 = a2 & 8;
dword_550 = a2 & 0x10;
return result;
}

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

dword_470 = a2 & 1;
dword_4A8 = a2 & 2;
dword_4E0 = a2 & 4;
result = a2 & 8;
dword_518 = a2 & 8;
dword_550 = a2 & 0x10;
return result;
}

original_code:
void K051649_keyonoff_w(offs_t offset,data_t data)
{
 channel_list[0].key=data&1;
 channel_list[1].key=data&2;
 channel_list[2].key=data&4;
 channel_list[3].key=data&8;
 channel_list[4].key=data&16;
}

canonical_original_code:
void K051649_keyonoff_w(unsigned int offset, unsigned int data)
{
 channel_list[0].key=data&1;
 channel_list[1].key=data&2;
 channel_list[2].key=data&4;
 channel_list[3].key=data&8;
 channel_list[4].key=data&16;
}


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

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

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

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


decompiled_code:
__int64 __fastcall galpanic_bgvideoram_w(unsigned int a1, int a2)
{
*(_WORD *)(galpanic_bgvideoram + a1) = a2 | *(_WORD *)(galpanic_bgvideoram + a1) & HIWORD(a2);
return plot_pixel(
tmpbitmap,
(unsigned __int8)(a1 >> 1),
a1 >> 9,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)*(unsigned __int16 *)(galpanic_bgvideoram + a1) >> 1) + 1024)));
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
*(_WORD *)(galpanic_bgvideoram + a1) = a2 | *(_WORD *)(galpanic_bgvideoram + a1) & HIWORD(a2);
return plot_pixel(
tmpbitmap,
(unsigned __int8)(a1 >> 1),
a1 >> 9,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)*(unsigned __int16 *)(galpanic_bgvideoram + a1) >> 1) + 1024)));
}

original_code:
void galpanic_bgvideoram_w(offs_t offset,data_t data)
{
 int sx,sy,color;
 ((*(UINT16 *)((&galpanic_bgvideoram[offset])) = (((*(UINT16 *)(&galpanic_bgvideoram[offset])) & ((data) >> 16)) | (data))));
 sy = (offset/2) / 256;
 sx = (offset/2) % 256;
 color = (*(UINT16 *)(&galpanic_bgvideoram[offset]));
 plot_pixel(tmpbitmap, sx, sy, Machine->pens[1024 + (color >> 1)]);
}

canonical_original_code:
void galpanic_bgvideoram_w(unsigned int offset, unsigned int data)
{
 int sx; int sy; int color;
 ((*(unsigned short *)((&galpanic_bgvideoram[offset])) = (((*(unsigned short *)(&galpanic_bgvideoram[offset])) & ((data) >> 16)) | (data))));
 sy = (offset/2) / 256;
 sx = (offset/2) % 256;
 color = (*(unsigned short *)(&galpanic_bgvideoram[offset]));
 plot_pixel(tmpbitmap, sx, sy, Machine->pens[1024 + (color >> 1)]);
}

variable_types: sx int

variable_types: sy int

variable_types: color int


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall galpanic_paletteram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rax
int v3; // edx

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return palette_change_color(
a1 >> 1,
(8 * ((v3 >> 6) & 0x1F)) | (unsigned int)(((v3 >> 6) & 0x1F) >> 2),
(8 * (v3 >> 11)) | (unsigned int)(v3 >> 13),
(8 * ((v3 >> 1) & 0x1F)) | (unsigned int)(((v3 >> 1) & 0x1F) >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rax
int v3; // edx

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return palette_change_color(
a1 >> 1,
(8 * ((v3 >> 6) & 0x1F)) | (unsigned int)(((v3 >> 6) & 0x1F) >> 2),
(8 * (v3 >> 11)) | (unsigned int)(v3 >> 13),
(8 * ((v3 >> 1) & 0x1F)) | (unsigned int)(((v3 >> 1) & 0x1F) >> 2));
}

original_code:
void galpanic_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = (newword >> 6) & 0x1f;
 g = (newword >> 11) & 0x1f;
 b = (newword >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void galpanic_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = (newword >> 6) & 0x1f;
 g = (newword >> 11) & 0x1f;
 b = (newword >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 galpanic_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 3 : 5;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)cpu_getiloops() == 0 ? 3 : 5;
}

original_code:
int galpanic_interrupt(void)
{
 if (cpu_getiloops() != 0) return 5;
 else return 3;
}

canonical_original_code:
int galpanic_interrupt()
{
 if (cpu_getiloops() != 0) return 5;
 else return 3;
}


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

v2 = memory_region(146LL);
bank_0 = a2 | bank_0 & HIWORD(a2);
return memcpy((void *)(v2 + 196608), (const void *)(v2 + (((BYTE1(a2) & 0xFu) + 4) << 16)), 0x10000uLL);
}

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

v2 = memory_region(146LL);
bank_0 = a2 | bank_0 & HIWORD(a2);
return memcpy((void *)(v2 + 196608), (const void *)(v2 + (((BYTE1(a2) & 0xFu) + 4) << 16)), 0x10000uLL);
}

original_code:
void galpanic_6295_bankswitch_w(offs_t offset,data_t data)
{
 static unsigned char bank[2];
 unsigned char *RAM = memory_region(REGION_SOUND1);
 ((*(UINT16 *)((bank)) = (((*(UINT16 *)(bank)) & ((data) >> 16)) | (data))));
 memcpy(&RAM[0x30000],&RAM[0x40000 + ((data >> 8) & 0x0f) * 0x10000],0x10000);
}

canonical_original_code:
void galpanic_6295_bankswitch_w(unsigned int offset, unsigned int data)
{
 static unsigned char bank[2];
 unsigned char *RAM = memory_region(REGION_SOUND1);
 ((*(unsigned short *)((bank)) = (((*(unsigned short *)(bank)) & ((data) >> 16)) | (data))));
 memcpy(&RAM[0x30000],&RAM[0x40000 + ((data >> 8) & 0x0f) * 0x10000],0x10000);
}

variable_types:
bank
unsigned char [2]

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 mexico86_68705_portA_r()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

canonical_decompiled_code:
__int64 func0()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

original_code:
data_t mexico86_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

canonical_original_code:
unsigned int mexico86_68705_portA_r(unsigned int offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}


decompiled_code:
void __fastcall mexico86_68705_portA_w(__int64 a1, char a2)
{
portA_out = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
portA_out = a2;
}

original_code:
void mexico86_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

canonical_original_code:
void mexico86_68705_portA_w(unsigned int offset, unsigned int data)
{
 portA_out = data;
}


decompiled_code:
void __fastcall mexico86_68705_ddrA_w(__int64 a1, char a2)
{
ddrA = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
ddrA = a2;
}

original_code:
void mexico86_68705_ddrA_w(offs_t offset,data_t data)
{
 ddrA = data;
}

canonical_original_code:
void mexico86_68705_ddrA_w(unsigned int offset, unsigned int data)
{
 ddrA = data;
}


decompiled_code:
__int64 mexico86_68705_portB_r()
{
return (unsigned __int8)(ddrB & portB_out);
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)(ddrB & portB_out);
}

original_code:
data_t mexico86_68705_portB_r(offs_t offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}

canonical_original_code:
unsigned int mexico86_68705_portB_r(unsigned int offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}


decompiled_code:
void __fastcall mexico86_68705_ddrB_w(__int64 a1, char a2)
{
ddrB = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, char a2)
{
ddrB = a2;
}

original_code:
void mexico86_68705_ddrB_w(offs_t offset,data_t data)
{
 ddrB = data;
}

canonical_original_code:
void mexico86_68705_ddrB_w(unsigned int offset, unsigned int data)
{
 ddrB = data;
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 mexico86_m68705_interrupt()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(2LL, 0LL, 0LL);
else
cpu_set_irq_line(2LL, 0LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(2LL, 0LL, 0LL);
else
cpu_set_irq_line(2LL, 0LL, 1LL);
return 0LL;
}

original_code:
int mexico86_m68705_interrupt(void)
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(2,0,0);
 else
  cpu_set_irq_line(2,0,1);
    return 0;
}

canonical_original_code:
int mexico86_m68705_interrupt()
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(2,0,0);
 else
  cpu_set_irq_line(2,0,1);
    return 0;
}


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

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out;
if ( (ddrB & 8) != 0 && (a2 & 8) == 0 && (portB_out & 8) != 0 )
{
if ( (a2 & 0x10) != 0 )
{
if ( (a2 & 4) != 0 )
{
result = (unsigned __int8)mexico86_protection_ram[address];
latch = (unsigned __int8)mexico86_protection_ram[address];
}
else
{
result = readinputport((address & 1u) + 1);
latch = result;
}
}
else
{
result = address;
mexico86_protection_ram[address] = portA_out;
}
}
if ( (ddrB & 0x20) != 0 && (a2 & 0x20) != 0 && (portB_out & 0x20) == 0 )
{
cpu_irq_line_vector_w(0LL, 0LL, (unsigned __int8)*mexico86_protection_ram);
result = cpu_set_irq_line(0LL, 0LL, 3LL);
}
portB_out = a2;
return result;
}

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

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out;
if ( (ddrB & 8) != 0 && (a2 & 8) == 0 && (portB_out & 8) != 0 )
{
if ( (a2 & 0x10) != 0 )
{
if ( (a2 & 4) != 0 )
{
result = (unsigned __int8)mexico86_protection_ram[address];
latch = (unsigned __int8)mexico86_protection_ram[address];
}
else
{
result = readinputport((address & 1u) + 1);
latch = result;
}
}
else
{
result = address;
mexico86_protection_ram[address] = portA_out;
}
}
if ( (ddrB & 0x20) != 0 && (a2 & 0x20) != 0 && (portB_out & 0x20) == 0 )
{
cpu_irq_line_vector_w(0LL, 0LL, (unsigned __int8)*mexico86_protection_ram);
result = cpu_set_irq_line(0LL, 0LL, 3LL);
}
portB_out = a2;
return result;
}

original_code:
void mexico86_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = portA_out;
 }
 if ((ddrB & 0x08) && (~data & 0x08) && (portB_out & 0x08))
 {
  if (data & 0x10)
  {
   if (data & 0x04)
   {
    latch = mexico86_protection_ram[address];
   }
   else
   {
    latch = readinputport((address & 1) + 1);
   }
  }
  else
  {
    mexico86_protection_ram[address] = portA_out;
  }
 }
 if ((ddrB & 0x20) && (data & 0x20) && (~portB_out & 0x20))
 {
  cpu_irq_line_vector_w(0,0,mexico86_protection_ram[0]);
  cpu_set_irq_line(0,0,3);
 }
 portB_out = data;
}

canonical_original_code:
void mexico86_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = portA_out;
 }
 if ((ddrB & 0x08) && (~data & 0x08) && (portB_out & 0x08))
 {
  if (data & 0x10)
  {
   if (data & 0x04)
   {
    latch = mexico86_protection_ram[address];
   }
   else
   {
    latch = readinputport((address & 1) + 1);
   }
  }
  else
  {
    mexico86_protection_ram[address] = portA_out;
  }
 }
 if ((ddrB & 0x20) && (data & 0x20) && (~portB_out & 0x20))
 {
  cpu_irq_line_vector_w(0,0,mexico86_protection_ram[0]);
  cpu_set_irq_line(0,0,3);
 }
 portB_out = data;
}


decompiled_code:
void *__fastcall mexico86_bankswitch_w(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
unsigned int v3; // ebp
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
v3 = a2 & 7;
if ( v3 > 5 )
usrintf_showmessage("Switching to invalid bank!");
cpu_bankbase[1] = v2 + ((v3 + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
charbank = (a2 >> 5) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
unsigned int v3; // ebp
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
v3 = a2 & 7;
if ( v3 > 5 )
usrintf_showmessage("Switching to invalid bank!");
cpu_bankbase[1] = v2 + ((v3 + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
charbank = (a2 >> 5) & 1;
return result;
}

original_code:
void mexico86_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if ((data & 7) > 5)
  usrintf_showmessage( "Switching to invalid bank!" );
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000 + 0x4000 * (data & 0x07)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 charbank = (data & 0x20) >> 5;
}

canonical_original_code:
void mexico86_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if ((data & 7) > 5)
  usrintf_showmessage( "Switching to invalid bank!" );
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000 + 0x4000 * (data & 0x07)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 charbank = (data & 0x20) >> 5;
}


decompiled_code:
unsigned __int64 __fastcall mexico86_vh_screenrefresh(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
int v3; // edi
int v4; // edx
int v5; // er14
int v6; // ebp
__int64 v7; // rbx
unsigned int v8; // edx
char v9; // si
__int64 v10; // [rsp+8h] [rbp-60h]
int v11; // [rsp+10h] [rbp-58h]
int v12; // [rsp+14h] [rbp-54h]
int v13; // [rsp+1Ch] [rbp-4Ch]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
v13 = 0;
do
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_11;
v8 = *(unsigned __int8 *)(mexico86_objectram + v2 + 1);
v9 = *(_BYTE *)(mexico86_objectram + v2 + 3);
if ( (v8 & 0x80u) != 0 )
{
v3 = (v8 & 0x3F) << 7;
if ( (v8 & 0xC0) == 0xC0 )
{
v13 += 16;
v4 = 32;
goto LABEL_7;
}
v4 = 32;
}
else
{
v3 = ((v8 & 0x1F) << 7) + ((v8 >> 1) & 0x30) + 12;
v4 = 2;
}
v13 = *(unsigned __int8 *)(mexico86_objectram + v2 + 2);
LABEL_7:
v11 = v13;
v10 = v3;
v12 = 8 * (32 - v4) - *(unsigned __int8 *)(mexico86_objectram + v2);
v5 = v12 + 8 * v4;
do
{
v6 = v12;
v7 = v10;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(charbank << 12)
+ *(unsigned __int8 *)(mexico86_videoram + v7)
+ ((*(unsigned __int8 *)(mexico86_videoram + v7 + 1) << 8) & 0x700)
+ ((16 * *(unsigned __int8 *)(mexico86_videoram + v7 + 1)) & 0x800u),
(4 * v9) & 8 | ((int)*(unsigned __int8 *)(mexico86_videoram + v7 + 1) >> 3) & 7u,
*(_BYTE *)(mexico86_videoram + v7 + 1) & 0x40,
0LL,
(unsigned __int8)v11,
(unsigned __int8)v6,
Machine + 776LL,
2LL,
0LL);
v7 += 2LL;
v6 += 8;
}
while ( v5 != v6 );
v11 += 8;
v10 += 64LL;
}
while ( v11 != v13 + 16 );
LABEL_11:
result = mexico86_objectram_size;
v2 += 4LL;
}
while ( mexico86_objectram_size + 512LL > v2 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
int v3; // edi
int v4; // edx
int v5; // er14
int v6; // ebp
__int64 v7; // rbx
unsigned int v8; // edx
char v9; // si
__int64 v10; // [rsp+8h] [rbp-60h]
int v11; // [rsp+10h] [rbp-58h]
int v12; // [rsp+14h] [rbp-54h]
int v13; // [rsp+1Ch] [rbp-4Ch]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
v13 = 0;
do
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_11;
v8 = *(unsigned __int8 *)(mexico86_objectram + v2 + 1);
v9 = *(_BYTE *)(mexico86_objectram + v2 + 3);
if ( (v8 & 0x80u) != 0 )
{
v3 = (v8 & 0x3F) << 7;
if ( (v8 & 0xC0) == 0xC0 )
{
v13 += 16;
v4 = 32;
goto LABEL_7;
}
v4 = 32;
}
else
{
v3 = ((v8 & 0x1F) << 7) + ((v8 >> 1) & 0x30) + 12;
v4 = 2;
}
v13 = *(unsigned __int8 *)(mexico86_objectram + v2 + 2);
LABEL_7:
v11 = v13;
v10 = v3;
v12 = 8 * (32 - v4) - *(unsigned __int8 *)(mexico86_objectram + v2);
v5 = v12 + 8 * v4;
do
{
v6 = v12;
v7 = v10;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(charbank << 12)
+ *(unsigned __int8 *)(mexico86_videoram + v7)
+ ((*(unsigned __int8 *)(mexico86_videoram + v7 + 1) << 8) & 0x700)
+ ((16 * *(unsigned __int8 *)(mexico86_videoram + v7 + 1)) & 0x800u),
(4 * v9) & 8 | ((int)*(unsigned __int8 *)(mexico86_videoram + v7 + 1) >> 3) & 7u,
*(_BYTE *)(mexico86_videoram + v7 + 1) & 0x40,
0LL,
(unsigned __int8)v11,
(unsigned __int8)v6,
Machine + 776LL,
2LL,
0LL);
v7 += 2LL;
v6 += 8;
}
while ( v5 != v6 );
v11 += 8;
v10 += 64LL;
}
while ( v11 != v13 + 16 );
LABEL_11:
result = mexico86_objectram_size;
v2 += 4LL;
}
while ( mexico86_objectram_size + 512LL > v2 );
}
return result;
}

original_code:
void mexico86_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy,xc,yc;
 int gfx_num,gfx_attr,gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(UINT32 *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs,code,color,flipx,flipy,x,y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x07) << 8)
      + ((mexico86_videoram[goffs + 1] & 0x80) << 4) + (charbank << 12);
    color = ((mexico86_videoram[goffs + 1] & 0x38) >> 3) + ((gfx_attr & 0x02) << 2);
    flipx = mexico86_videoram[goffs + 1] & 0x40;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

canonical_original_code:
void mexico86_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy; int xc; int yc;
 int gfx_num; int gfx_attr; int gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(unsigned int *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs; int code; int color; int flipx; int flipy; int x; int y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x07) << 8)
      + ((mexico86_videoram[goffs + 1] & 0x80) << 4) + (charbank << 12);
    color = ((mexico86_videoram[goffs + 1] & 0x38) >> 3) + ((gfx_attr & 0x02) << 2);
    flipx = mexico86_videoram[goffs + 1] & 0x40;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

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

variable_types: offs int

variable_types: xc int

variable_types: yc int

variable_types: height int

variable_types: goffs int

variable_types: code int

variable_types: flipx int

variable_types: flipy int

variable_types: x int

variable_types: y int


decompiled_code:
unsigned __int64 __fastcall kikikai_vh_screenrefresh(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
int v3; // edi
int v4; // esi
int v5; // ebp
__int64 v6; // rbx
unsigned int v7; // eax
__int64 v8; // [rsp+8h] [rbp-60h]
int v9; // [rsp+10h] [rbp-58h]
int v10; // [rsp+14h] [rbp-54h]
int v11; // [rsp+1Ch] [rbp-4Ch]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
v11 = 0;
do
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_11;
v7 = *(unsigned __int8 *)(mexico86_objectram + v2 + 1);
if ( (v7 & 0x80u) != 0 )
{
v3 = (v7 & 0x3F) << 7;
if ( (v7 & 0xC0) == 0xC0 )
{
v11 += 16;
v4 = 32;
goto LABEL_7;
}
v4 = 32;
}
else
{
v3 = ((v7 & 0x1F) << 7) + ((v7 >> 1) & 0x30) + 12;
v4 = 2;
}
v11 = *(unsigned __int8 *)(mexico86_objectram + v2 + 2);
LABEL_7:
v9 = v11;
v8 = v3;
v10 = 8 * (32 - v4) - *(unsigned __int8 *)(mexico86_objectram + v2);
do
{
v5 = v10;
v6 = v8;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(mexico86_videoram + v6)
+ ((*(unsigned __int8 *)(mexico86_videoram + v6 + 1) << 8) & 0x1F00u),
*(_BYTE *)(mexico86_videoram + v6 + 1) >> 5,
0LL,
0LL,
(unsigned __int8)v9,
(unsigned __int8)v5,
Machine + 776LL,
2LL,
0LL);
v6 += 2LL;
v5 += 8;
}
while ( v10 + 8 * v4 != v5 );
v9 += 8;
v8 += 64LL;
}
while ( v9 != v11 + 16 );
LABEL_11:
result = mexico86_objectram_size;
v2 += 4LL;
}
while ( mexico86_objectram_size + 512LL > v2 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
int v3; // edi
int v4; // esi
int v5; // ebp
__int64 v6; // rbx
unsigned int v7; // eax
__int64 v8; // [rsp+8h] [rbp-60h]
int v9; // [rsp+10h] [rbp-58h]
int v10; // [rsp+14h] [rbp-54h]
int v11; // [rsp+1Ch] [rbp-4Ch]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
v11 = 0;
do
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_11;
v7 = *(unsigned __int8 *)(mexico86_objectram + v2 + 1);
if ( (v7 & 0x80u) != 0 )
{
v3 = (v7 & 0x3F) << 7;
if ( (v7 & 0xC0) == 0xC0 )
{
v11 += 16;
v4 = 32;
goto LABEL_7;
}
v4 = 32;
}
else
{
v3 = ((v7 & 0x1F) << 7) + ((v7 >> 1) & 0x30) + 12;
v4 = 2;
}
v11 = *(unsigned __int8 *)(mexico86_objectram + v2 + 2);
LABEL_7:
v9 = v11;
v8 = v3;
v10 = 8 * (32 - v4) - *(unsigned __int8 *)(mexico86_objectram + v2);
do
{
v5 = v10;
v6 = v8;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(mexico86_videoram + v6)
+ ((*(unsigned __int8 *)(mexico86_videoram + v6 + 1) << 8) & 0x1F00u),
*(_BYTE *)(mexico86_videoram + v6 + 1) >> 5,
0LL,
0LL,
(unsigned __int8)v9,
(unsigned __int8)v5,
Machine + 776LL,
2LL,
0LL);
v6 += 2LL;
v5 += 8;
}
while ( v10 + 8 * v4 != v5 );
v9 += 8;
v8 += 64LL;
}
while ( v9 != v11 + 16 );
LABEL_11:
result = mexico86_objectram_size;
v2 += 4LL;
}
while ( mexico86_objectram_size + 512LL > v2 );
}
return result;
}

original_code:
void kikikai_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy,xc,yc;
 int gfx_num,gfx_attr,gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(UINT32 *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs,code,color,flipx,flipy,x,y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x1f) << 8);
    color = (mexico86_videoram[goffs + 1] & 0xe0) >> 5;
    flipx = 0;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

canonical_original_code:
void kikikai_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy; int xc; int yc;
 int gfx_num; int gfx_attr; int gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(unsigned int *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs; int code; int color; int flipx; int flipy; int x; int y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x1f) << 8);
    color = (mexico86_videoram[goffs + 1] & 0xe0) >> 5;
    flipx = 0;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: color int

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


decompiled_code:
__int64 __fastcall mexico86_f008_w(__int64 a1, unsigned int a2)
{
cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 2) ^ 1) & 1);
return cpu_set_reset_line(2LL, ((unsigned __int8)(a2 >> 1) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 2) ^ 1) & 1);
return cpu_set_reset_line(2LL, ((unsigned __int8)(a2 >> 1) ^ 1) & 1);
}

original_code:
static void mexico86_f008_w(offs_t offset,data_t data)
{
 cpu_set_reset_line(1,(data & 4) ? 0 : 1);
 cpu_set_reset_line(2,(data & 2) ? 0 : 1);
}

canonical_original_code:
static void mexico86_f008_w(unsigned int offset, unsigned int data)
{
 cpu_set_reset_line(1,(data & 4) ? 0 : 1);
 cpu_set_reset_line(2,(data & 2) ? 0 : 1);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

original_code:
static data_t shared_r(offs_t offset)
{
 return shared[offset];
}

canonical_original_code:
static unsigned int shared_r(unsigned int offset)
{
 return shared[offset];
}


decompiled_code:
__int64 citycon_vh_start()
{
size_t v0; // rbx
void *v1; // rdi
__int64 v2; // rax
__int64 v3; // rsi
unsigned int v4; // edx

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

canonical_decompiled_code:
__int64 func0()
{
size_t v0; // rbx
void *v1; // rdi
__int64 v2; // rax
__int64 v3; // rsi
unsigned int v4; // edx

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

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

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


decompiled_code:
__int64 __fastcall citycon_vh_stop(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx

free(dirtybuffer);
bitmap_free(tmpbitmap, a2, v2);
return bitmap_free(tmpbitmap2, a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rdx

free(dirtybuffer);
bitmap_free(tmpbitmap, a2, v2);
return bitmap_free(tmpbitmap2, a2, v3);
}

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

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


decompiled_code:
__int64 __fastcall citycon_background_w(unsigned int a1, unsigned int a2)
{
set_vh_global_attribute(&bg_image, a2 >> 4);
return flip_screen_w(a1, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
set_vh_global_attribute(&bg_image, a2 >> 4);
return flip_screen_w(a1, a2 & 1);
}

original_code:
void citycon_background_w(offs_t offset,data_t data)
{
 set_vh_global_attribute(&bg_image, data >> 4);
 flip_screen_w(offset, data & 0x01);
}

canonical_original_code:
void citycon_background_w(unsigned int offset, unsigned int data)
{
 set_vh_global_attribute(&bg_image, data >> 4);
 flip_screen_w(offset, data & 0x01);
}


decompiled_code:
__int64 citycon_in_r()
{
return readinputport(flip_screen_x != 0);
}

canonical_decompiled_code:
__int64 func3()
{
return readinputport(flip_screen_x != 0);
}

original_code:
data_t citycon_in_r(offs_t offset)
{
 return readinputport(flip_screen_x ? 1 : 0);
}

canonical_original_code:
unsigned int citycon_in_r(unsigned int offset)
{
 return readinputport(flip_screen_x ? 1 : 0);
}


decompiled_code:
__int64 copsnrob_vh_start()
{
overlay_create(&copsnrob_overlay, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
overlay_create(&copsnrob_overlay, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
return 0LL;
}

original_code:
int copsnrob_vh_start(void)
{
 overlay_create(copsnrob_overlay, 2, Machine->drv->total_colors - 2);
    return 0;
}

canonical_original_code:
int copsnrob_vh_start()
{
 overlay_create(copsnrob_overlay, 2, Machine->drv->total_colors - 2);
    return 0;
}


decompiled_code:
__int64 __fastcall copsnrob_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
int i; // ebx
__int64 j; // r13
__int64 result; // rax
__int64 v9; // rbx
int v10; // er12
char v11; // bp
int v12; // er14
int v13; // edi

palette_recalc();
if ( videoram_size >= 0 )
{
v1 = videoram_size;
v2 = videoram_size;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v2) & 0x3F,
0LL,
0LL,
0LL,
8 * (((unsigned int)(v1 >> 31) >> 27) - (((_BYTE)v1 + ((unsigned int)(v1 >> 31) >> 27)) & 0x1F)) + 248,
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
--v1;
--v2;
}
while ( v1 != -1 );
}
if ( *copsnrob_cary )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)*copsnrob_carimage,
0LL,
1LL,
0LL,
228LL,
256 - (unsigned int)(unsigned __int8)*copsnrob_cary,
Machine + 776LL,
2LL,
0LL);
v3 = copsnrob_cary[1];
if ( v3 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[1],
0LL,
1LL,
0LL,
196LL,
256 - (unsigned int)v3,
Machine + 776LL,
2LL,
0LL);
v4 = copsnrob_cary[2];
if ( v4 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[2],
0LL,
0LL,
0LL,
36LL,
256 - (unsigned int)v4,
Machine + 776LL,
2LL,
0LL);
v5 = copsnrob_cary[3];
if ( v5 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[3],
0LL,
0LL,
0LL,
4LL,
256 - (unsigned int)v5,
Machine + 776LL,
2LL,
0LL);
for ( i = 0; i <= 255; ++i )
{
if ( *(_BYTE *)(copsnrob_truckram + 255 - i) )
{
if ( (((unsigned __int8)(i + 31) ^ *copsnrob_trucky) & 0x1F) != 0 )
{
if ( (((unsigned __int8)i ^ *copsnrob_trucky) & 0x1F) == 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
128LL,
(unsigned int)(256 - i),
Machine + 776LL,
2LL,
0LL);
}
else
{
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
128LL,
(unsigned int)(225 - i),
Machine + 776LL,
2LL,
0LL);
i += 31;
}
}
}
for ( j = 0LL; j != 256; ++j )
{
result = *(unsigned __int8 *)(copsnrob_bulletsram + j);
if ( (result & 0xF) != 0 )
{
v13 = (unsigned __int8)result;
v12 = 4;
v11 = 16;
v10 = 1;
result = (unsigned int)(256 - j);
do
{
if ( (v10 & v13) != 0 )
{
result = Machine;
if ( *(int *)(Machine + 788LL) >= 0 )
{
v9 = 0LL;
do
{
if ( ((unsigned __int8)v11 & *(_BYTE *)(copsnrob_bulletsram + v9)) != 0 )
plot_pixel(
a1,
(unsigned int)(256 - j),
(unsigned int)v9,
*(unsigned __int16 *)(*(_QWORD *)(result + 792) + 2LL));
result = Machine;
++v9;
}
while ( *(_DWORD *)(Machine + 788LL) >= (int)v9 );
}
}
v10 *= 2;
v11 *= 2;
--v12;
}
while ( v12 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
unsigned __int8 v3; // al
unsigned __int8 v4; // al
unsigned __int8 v5; // al
int i; // ebx
__int64 j; // r13
__int64 result; // rax
__int64 v9; // rbx
int v10; // er12
char v11; // bp
int v12; // er14
int v13; // edi

palette_recalc();
if ( videoram_size >= 0 )
{
v1 = videoram_size;
v2 = videoram_size;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v2) & 0x3F,
0LL,
0LL,
0LL,
8 * (((unsigned int)(v1 >> 31) >> 27) - (((_BYTE)v1 + ((unsigned int)(v1 >> 31) >> 27)) & 0x1F)) + 248,
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
--v1;
--v2;
}
while ( v1 != -1 );
}
if ( *copsnrob_cary )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)*copsnrob_carimage,
0LL,
1LL,
0LL,
228LL,
256 - (unsigned int)(unsigned __int8)*copsnrob_cary,
Machine + 776LL,
2LL,
0LL);
v3 = copsnrob_cary[1];
if ( v3 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[1],
0LL,
1LL,
0LL,
196LL,
256 - (unsigned int)v3,
Machine + 776LL,
2LL,
0LL);
v4 = copsnrob_cary[2];
if ( v4 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[2],
0LL,
0LL,
0LL,
36LL,
256 - (unsigned int)v4,
Machine + 776LL,
2LL,
0LL);
v5 = copsnrob_cary[3];
if ( v5 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[3],
0LL,
0LL,
0LL,
4LL,
256 - (unsigned int)v5,
Machine + 776LL,
2LL,
0LL);
for ( i = 0; i <= 255; ++i )
{
if ( *(_BYTE *)(copsnrob_truckram + 255 - i) )
{
if ( (((unsigned __int8)(i + 31) ^ *copsnrob_trucky) & 0x1F) != 0 )
{
if ( (((unsigned __int8)i ^ *copsnrob_trucky) & 0x1F) == 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
128LL,
(unsigned int)(256 - i),
Machine + 776LL,
2LL,
0LL);
}
else
{
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
128LL,
(unsigned int)(225 - i),
Machine + 776LL,
2LL,
0LL);
i += 31;
}
}
}
for ( j = 0LL; j != 256; ++j )
{
result = *(unsigned __int8 *)(copsnrob_bulletsram + j);
if ( (result & 0xF) != 0 )
{
v13 = (unsigned __int8)result;
v12 = 4;
v11 = 16;
v10 = 1;
result = (unsigned int)(256 - j);
do
{
if ( (v10 & v13) != 0 )
{
result = Machine;
if ( *(int *)(Machine + 788LL) >= 0 )
{
v9 = 0LL;
do
{
if ( ((unsigned __int8)v11 & *(_BYTE *)(copsnrob_bulletsram + v9)) != 0 )
plot_pixel(
a1,
(unsigned int)(256 - j),
(unsigned int)v9,
*(unsigned __int16 *)(*(_QWORD *)(result + 792) + 2LL));
result = Machine;
++v9;
}
while ( *(_DWORD *)(Machine + 788LL) >= (int)v9 );
}
}
v10 *= 2;
v11 *= 2;
--v12;
}
while ( v12 );
}
}
return result;
}

original_code:
void copsnrob_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs, x, y;
 palette_recalc();
    for (offs = videoram_size;offs >= 0;offs--)
    {
  int sx,sy;
  sx = 31 - (offs % 32);
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] & 0x3f,0,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
    }
    if (copsnrob_cary[0])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[0],0,
                1,0,
                0xe4,256-copsnrob_cary[0],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[1])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[1],0,
                1,0,
                0xc4,256-copsnrob_cary[1],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[2])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[2],0,
                0,0,
                0x24,256-copsnrob_cary[2],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[3])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[3],0,
                0,0,
                0x04,256-copsnrob_cary[3],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
     for (y = 0; y < 256; y++)
     {
  if (copsnrob_truckram[255-y])
  {
   if ((copsnrob_trucky[0] & 0x1f) == ((y+31) & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-(y+31),
      &Machine->visible_area,TRANSPARENCY_PEN,0);
    y += 31;
   }
   else if ((copsnrob_trucky[0] & 0x1f) == (y & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
    }
    for (x = 0; x < 256; x++)
    {
     int bullet, mask1, mask2, val;
        val = copsnrob_bulletsram[x];
        if (!(val & 0x0f)) continue;
        mask1 = 0x01;
        mask2 = 0x10;
        for (bullet = 0; bullet < 4; bullet++)
        {
            if (val & mask1)
            {
                for (y = 0; y <= Machine->visible_area.max_y; y++)
                {
                    if (copsnrob_bulletsram[y] & mask2)
                    {
                        plot_pixel(bitmap, 256-x, y, Machine->pens[1]);
                    }
                }
            }
            mask1 <<= 1;
            mask2 <<= 1;
        }
    }
}

canonical_original_code:
void copsnrob_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int x; int y;
 palette_recalc();
    for (offs = videoram_size;offs >= 0;offs--)
    {
  int sx; int sy;
  sx = 31 - (offs % 32);
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] & 0x3f,0,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
    }
    if (copsnrob_cary[0])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[0],0,
                1,0,
                0xe4,256-copsnrob_cary[0],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[1])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[1],0,
                1,0,
                0xc4,256-copsnrob_cary[1],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[2])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[2],0,
                0,0,
                0x24,256-copsnrob_cary[2],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[3])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[3],0,
                0,0,
                0x04,256-copsnrob_cary[3],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
     for (y = 0; y < 256; y++)
     {
  if (copsnrob_truckram[255-y])
  {
   if ((copsnrob_trucky[0] & 0x1f) == ((y+31) & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-(y+31),
      &Machine->visible_area,TRANSPARENCY_PEN,0);
    y += 31;
   }
   else if ((copsnrob_trucky[0] & 0x1f) == (y & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
    }
    for (x = 0; x < 256; x++)
    {
     int bullet; int mask1; int mask2; int val;
        val = copsnrob_bulletsram[x];
        if (!(val & 0x0f)) continue;
        mask1 = 0x01;
        mask2 = 0x10;
        for (bullet = 0; bullet < 4; bullet++)
        {
            if (val & mask1)
            {
                for (y = 0; y <= Machine->visible_area.max_y; y++)
                {
                    if (copsnrob_bulletsram[y] & mask2)
                    {
                        plot_pixel(bitmap, 256-x, y, Machine->pens[1]);
                    }
                }
            }
            mask1 <<= 1;
            mask2 <<= 1;
        }
    }
}

variable_types: bullet int

variable_types: val int


decompiled_code:
__int64 __fastcall copsnrob_gun_position_r(int a1)
{
int v1; // ebx
char v2; // al
int v3; // edx

switch ( a1 )
{
case 8:
v1 = (unsigned __int8)copsnrob_carimage[2];
v2 = input_port_6_r(0LL);
break;
case 12:
v1 = (unsigned __int8)copsnrob_carimage[3];
v2 = input_port_7_r(0LL);
break;
case 4:
v1 = (unsigned __int8)copsnrob_carimage[1];
v2 = input_port_5_r(0LL);
break;
default:
v1 = (unsigned __int8)*copsnrob_carimage;
v2 = input_port_4_r(0LL);
break;
}
if ( v1 > 6 )
{
if ( v1 > 13 )
{
v3 = v2 & 1;
if ( (v2 & 1) == 0 )
return gun_mask[v3] | v2 & 0x80u;
v3 = 0;
goto LABEL_9;
}
v3 = 13 - v1;
}
else
{
v3 = 6 - v1;
}
if ( (v2 & 1) != 0 && v3 != 6 )
LABEL_9:
++v3;
if ( (v2 & 2) != 0 )
v3 = (v3 == 0) + v3 - 1;
return gun_mask[v3] | v2 & 0x80u;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebx
char v2; // al
int v3; // edx

switch ( a1 )
{
case 8:
v1 = (unsigned __int8)copsnrob_carimage[2];
v2 = input_port_6_r(0LL);
break;
case 12:
v1 = (unsigned __int8)copsnrob_carimage[3];
v2 = input_port_7_r(0LL);
break;
case 4:
v1 = (unsigned __int8)copsnrob_carimage[1];
v2 = input_port_5_r(0LL);
break;
default:
v1 = (unsigned __int8)*copsnrob_carimage;
v2 = input_port_4_r(0LL);
break;
}
if ( v1 > 6 )
{
if ( v1 > 13 )
{
v3 = v2 & 1;
if ( (v2 & 1) == 0 )
return gun_mask[v3] | v2 & 0x80u;
v3 = 0;
goto LABEL_9;
}
v3 = 13 - v1;
}
else
{
v3 = 6 - v1;
}
if ( (v2 & 1) != 0 && v3 != 6 )
LABEL_9:
++v3;
if ( (v2 & 2) != 0 )
v3 = (v3 == 0) + v3 - 1;
return gun_mask[v3] | v2 & 0x80u;
}

original_code:
data_t copsnrob_gun_position_r(offs_t offset)
{
    int keys, current_car_image, current_gun_pos = 0;
    switch (offset)
    {
    default:
    case 0x00:
        current_car_image = copsnrob_carimage[0];
        keys = input_port_4_r(0);
        break;
    case 0x04:
        current_car_image = copsnrob_carimage[1];
        keys = input_port_5_r(0);
        break;
    case 0x08:
        current_car_image = copsnrob_carimage[2];
        keys = input_port_6_r(0);
        break;
    case 0x0c:
        current_car_image = copsnrob_carimage[3];
        keys = input_port_7_r(0);
    }
    if (current_car_image < 7)
    {
        current_gun_pos = 6 - current_car_image;
    }
    else if (current_car_image < 14)
    {
        current_gun_pos = 13 - current_car_image;
    }
    if ((keys & 0x01) && (current_gun_pos != 6)) current_gun_pos++;
    if ((keys & 0x02) && (current_gun_pos != 0)) current_gun_pos--;
    return (keys & 0x80) | gun_mask[current_gun_pos];
}

canonical_original_code:
unsigned int copsnrob_gun_position_r(unsigned int offset)
{
    int keys; int current_car_image; int current_gun_pos = 0;
    switch (offset)
    {
    default:
    case 0x00:
        current_car_image = copsnrob_carimage[0];
        keys = input_port_4_r(0);
        break;
    case 0x04:
        current_car_image = copsnrob_carimage[1];
        keys = input_port_5_r(0);
        break;
    case 0x08:
        current_car_image = copsnrob_carimage[2];
        keys = input_port_6_r(0);
        break;
    case 0x0c:
        current_car_image = copsnrob_carimage[3];
        keys = input_port_7_r(0);
    }
    if (current_car_image < 7)
    {
        current_gun_pos = 6 - current_car_image;
    }
    else if (current_car_image < 14)
    {
        current_gun_pos = 13 - current_car_image;
    }
    if ((keys & 0x01) && (current_gun_pos != 6)) current_gun_pos++;
    if ((keys & 0x02) && (current_gun_pos != 0)) current_gun_pos--;
    return (keys & 0x80) | gun_mask[current_gun_pos];
}

variable_types: keys int


decodebyte

original_code:
unsigned char decodebyte( unsigned char opcode, unsigned short address )
{
 unsigned char xormask;
 xormask = 0;
 if (address & 0x02) xormask |= 0x80;
 else xormask |= 0x20;
 if (address & 0x08) xormask |= 0x08;
 else xormask |= 0x02;
 return opcode ^ xormask;
}

canonical_original_code:
unsigned char decodebyte(unsigned char opcode, unsigned short address)
{
 unsigned char xormask;
 xormask = 0;
 if (address & 0x02) xormask |= 0x80;
 else xormask |= 0x20;
 if (address & 0x08) xormask |= 0x08;
 else xormask |= 0x02;
 return opcode ^ xormask;
}

variable_types:
opcode
unsigned char

variable_types:
address
unsigned short

variable_types:
xormask
unsigned char

return_type: unsigned char


decompiled_code:
__int64 konami1_decode()
{
return decode(0);
}

canonical_decompiled_code:
__int64 func2()
{
return func1(0);
}

original_code:
void konami1_decode(void)
{
 decode(0);
}

canonical_original_code:
void konami1_decode()
{
 decode(0);
}


decompiled_code:
__int64 konami1_decode_cpu4()
{
return decode(3u);
}

canonical_decompiled_code:
__int64 func3()
{
return func1(3u);
}

original_code:
void konami1_decode_cpu4(void)
{
 decode(3);
}

canonical_original_code:
void konami1_decode_cpu4()
{
 decode(3);
}


decode

decompiled_code:
__int64 __fastcall decode(unsigned int a1)
{
unsigned __int8 *v1; // rbx
int v2; // ebp
int v3; // er12
__int64 result; // rax
int v5; // ebp

v1 = (unsigned __int8 *)memory_region(a1 + 129);
v2 = memory_region_length(a1 + 129);
v3 = v2 / 2;
result = memory_set_opcode_base(a1, &v1[v2 / 2]);
if ( v2 > 1 )
{
v5 = 0;
do
{
result = decodebyte(*v1, v5);
v1[v3] = result;
++v5;
++v1;
}
while ( v3 > v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned __int8 *v1; // rbx
int v2; // ebp
int v3; // er12
__int64 result; // rax
int v5; // ebp

v1 = (unsigned __int8 *)memory_region(a1 + 129);
v2 = memory_region_length(a1 + 129);
v3 = v2 / 2;
result = memory_set_opcode_base(a1, &v1[v2 / 2]);
if ( v2 > 1 )
{
v5 = 0;
do
{
result = func0(*v1, v5);
v1[v3] = result;
++v5;
++v1;
}
while ( v3 > v5 );
}
return result;
}

original_code:
static void decode(int cpu)
{
 unsigned char *rom = memory_region(REGION_CPU1+cpu);
 int diff = memory_region_length(REGION_CPU1+cpu) / 2;
 int A;
 memory_set_opcode_base(cpu,rom+diff);
 for (A = 0;A < diff;A++)
 {
  rom[A+diff] = decodebyte(rom[A],A);
 }
}

variable_types: cpu int

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int