decompiled_code:
__int64 __fastcall blockout_vh_screenrefresh(__int64 a1)
{
unsigned int v1; // ebp
signed int i; // ebx
unsigned int v3; // er14
unsigned int j; // er12
int k; // ebx
__int64 result; // rax
__int16 v7; // bp

v1 = 0;
if ( palette_recalc() )
{
do
{
for ( i = 0; i != 320; i += 2 )
updatepixels(i, v1);
++v1;
}
while ( v1 != 256 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v3 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1024LL);
for ( j = 0; j != 256; ++j )
{
for ( k = 0; k != 320; k += 8 )
{
result = (int)((j << 7) + (k >> 2));
v7 = *(_WORD *)(blockout_frontvideoram + result);
if ( v7 )
{
if ( (v7 & 0x80u) != 0 )
result = plot_pixel(a1, (unsigned int)k, j, v3);
if ( (v7 & 0x40) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 1), j, v3);
if ( (v7 & 0x20) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 2), j, v3);
if ( (v7 & 0x10) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 3), j, v3);
if ( (v7 & 8) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 4), j, v3);
if ( (v7 & 4) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 5), j, v3);
if ( (v7 & 2) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 6), j, v3);
if ( (v7 & 1) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 7), j, v3);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // ebp
signed int i; // ebx
unsigned int v3; // er14
unsigned int j; // er12
int k; // ebx
__int64 result; // rax
__int16 v7; // bp

v1 = 0;
if ( palette_recalc() )
{
do
{
for ( i = 0; i != 320; i += 2 )
func0(i, v1);
++v1;
}
while ( v1 != 256 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v3 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1024LL);
for ( j = 0; j != 256; ++j )
{
for ( k = 0; k != 320; k += 8 )
{
result = (int)((j << 7) + (k >> 2));
v7 = *(_WORD *)(blockout_frontvideoram + result);
if ( v7 )
{
if ( (v7 & 0x80u) != 0 )
result = plot_pixel(a1, (unsigned int)k, j, v3);
if ( (v7 & 0x40) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 1), j, v3);
if ( (v7 & 0x20) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 2), j, v3);
if ( (v7 & 0x10) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 3), j, v3);
if ( (v7 & 8) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 4), j, v3);
if ( (v7 & 4) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 5), j, v3);
if ( (v7 & 2) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 6), j, v3);
if ( (v7 & 1) != 0 )
result = plot_pixel(a1, (unsigned int)(k + 7), j, v3);
}
}
}
return result;
}

original_code:
void blockout_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (palette_recalc())
 {
  int x,y;
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=2)
   {
    updatepixels(x,y);
   }
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 {
  int x,y,color;
  color = Machine->pens[512];
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=8)
   {
    int d;
    d = (*(UINT16 *)(&blockout_frontvideoram[(y<<7)+(x>>2)]));
    if (d)
    {
     if (d&0x80) plot_pixel(bitmap, x , y, color);
     if (d&0x40) plot_pixel(bitmap, x+1, y, color);
     if (d&0x20) plot_pixel(bitmap, x+2, y, color);
     if (d&0x10) plot_pixel(bitmap, x+3, y, color);
     if (d&0x08) plot_pixel(bitmap, x+4, y, color);
     if (d&0x04) plot_pixel(bitmap, x+5, y, color);
     if (d&0x02) plot_pixel(bitmap, x+6, y, color);
     if (d&0x01) plot_pixel(bitmap, x+7, y, color);
    }
   }
  }
 }
}

canonical_original_code:
void blockout_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (palette_recalc())
 {
  int x; int y;
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=2)
   {
    updatepixels(x,y);
   }
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 {
  int x; int y; int color;
  color = Machine->pens[512];
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=8)
   {
    int d;
    d = (*(unsigned short *)(&blockout_frontvideoram[(y<<7)+(x>>2)]));
    if (d)
    {
     if (d&0x80) plot_pixel(bitmap, x , y, color);
     if (d&0x40) plot_pixel(bitmap, x+1, y, color);
     if (d&0x20) plot_pixel(bitmap, x+2, y, color);
     if (d&0x10) plot_pixel(bitmap, x+3, y, color);
     if (d&0x08) plot_pixel(bitmap, x+4, y, color);
     if (d&0x04) plot_pixel(bitmap, x+5, y, color);
     if (d&0x02) plot_pixel(bitmap, x+6, y, color);
     if (d&0x01) plot_pixel(bitmap, x+7, y, color);
    }
   }
  }
 }
}

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

variable_types: y int

variable_types: d int


decompiled_code:
__int64 blockout_interrupt()
{
return 6 - (unsigned int)cpu_getiloops();
}

canonical_decompiled_code:
__int64 func11()
{
return 6 - (unsigned int)cpu_getiloops();
}

original_code:
int blockout_interrupt(void)
{
 return 6 - cpu_getiloops();
}

canonical_original_code:
int blockout_interrupt()
{
 return 6 - cpu_getiloops();
}

return_type: int


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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
case 3:
case 5:
case 7:
result = 0LL;
break;
case 2:
result = input_port_1_r(2LL);
break;
case 4:
result = input_port_2_r(4LL);
break;
case 6:
result = input_port_3_r(6LL);
break;
case 8:
result = input_port_4_r(8LL);
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
case 3:
case 5:
case 7:
result = 0LL;
break;
case 2:
result = input_port_1_r(2LL);
break;
case 4:
result = input_port_2_r(4LL);
break;
case 6:
result = input_port_3_r(6LL);
break;
case 8:
result = input_port_4_r(8LL);
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
data_t blockout_input_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return input_port_0_r(offset);
  case 2:
   return input_port_1_r(offset);
  case 4:
   return input_port_2_r(offset);
  case 6:
   return input_port_3_r(offset);
  case 8:
   return input_port_4_r(offset);
  default:
   return 0;
 }
}

canonical_original_code:
unsigned int blockout_input_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return input_port_0_r(offset);
  case 2:
   return input_port_1_r(offset);
  case 4:
   return input_port_2_r(offset);
  case 6:
   return input_port_3_r(offset);
  case 8:
   return input_port_4_r(offset);
  default:
   return 0;
 }
}

variable_types:
offset
unsigned int

return_type: unsigned int


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

if ( !(_DWORD)a1 )
{
soundlatch_w(a1, a2);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

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

if ( !(_DWORD)a1 )
{
soundlatch_w(a1, a2);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

original_code:
void blockout_sound_command_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0:
   soundlatch_w(offset,data & 0xff);
   cpu_cause_interrupt(1,-2);
   break;
  case 2:
   break;
 }
}

canonical_original_code:
void blockout_sound_command_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0:
   soundlatch_w(offset,data & 0xff);
   cpu_cause_interrupt(1,-2);
   break;
  case 2:
   break;
 }
}

variable_types:
data
unsigned int

return_type: void


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

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

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

variable_types: irq int


setcolor

canonical_original_code:
static void setcolor(int color, int rgb)
{
 int bit0; int bit1; int bit2; int bit3;
 int r; int g; int b;
 bit0 = (rgb >> 0) & 0x01;
 bit1 = (rgb >> 1) & 0x01;
 bit2 = (rgb >> 2) & 0x01;
 bit3 = (rgb >> 3) & 0x01;
 r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 bit0 = (rgb >> 4) & 0x01;
 bit1 = (rgb >> 5) & 0x01;
 bit2 = (rgb >> 6) & 0x01;
 bit3 = (rgb >> 7) & 0x01;
 g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 bit0 = (rgb >> 8) & 0x01;
 bit1 = (rgb >> 9) & 0x01;
 bit2 = (rgb >> 10) & 0x01;
 bit3 = (rgb >> 11) & 0x01;
 b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 palette_change_color(color,r,g,b);
}

variable_types: color int

variable_types: rgb int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
void *__fastcall llander_init_colors(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
void *result; // rax
__int64 v4; // rdx
_BYTE *v5; // rdx
int v6; // eax

avg_init_palette_white();
llander_lit_panel = 0LL;
v1 = **(_DWORD **)(Machine + 768LL);
v2 = (unsigned int)(int)((double)(int)v1 * 0.16);
result = (void *)artwork_load_size(
&llander_panel,
"llander.png",
24LL,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 24),
v1,
v2);
if ( llander_panel )
{
v4 = 24LL;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 768LL) + 8LL) == 8 )
v4 = (unsigned int)(*(_DWORD *)(llander_panel + 48) + 24);
artwork_load_size(
&llander_lit_panel,
"llander1.png",
v4,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - v4),
v1,
(unsigned int)v2);
v5 = (_BYTE *)(a1 + 24);
v6 = 0;
if ( llander_lit_panel )
{
do
{
v5[2] = v6;
v5[1] = v6;
*v5 = v6;
v6 += 17;
v5 += 3;
}
while ( (_BYTE)v6 != 16 );
memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_panel + 68)),
*(const void **)(llander_panel + 40),
3 * *(_DWORD *)(llander_panel + 48));
result = memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_lit_panel + 68)),
*(const void **)(llander_lit_panel + 40),
3 * *(_DWORD *)(llander_lit_panel + 48));
}
else
{
result = (void *)artwork_free(&llander_panel, "llander1.png", v5);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
void *result; // rax
__int64 v4; // rdx
_BYTE *v5; // rdx
int v6; // eax

avg_init_palette_white();
llander_lit_panel = 0LL;
v1 = **(_DWORD **)(Machine + 768LL);
v2 = (unsigned int)(int)((double)(int)v1 * 0.16);
result = (void *)artwork_load_size(
&llander_panel,
"llander.png",
24LL,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 24),
v1,
v2);
if ( llander_panel )
{
v4 = 24LL;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 768LL) + 8LL) == 8 )
v4 = (unsigned int)(*(_DWORD *)(llander_panel + 48) + 24);
artwork_load_size(
&llander_lit_panel,
"llander1.png",
v4,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - v4),
v1,
(unsigned int)v2);
v5 = (_BYTE *)(a1 + 24);
v6 = 0;
if ( llander_lit_panel )
{
do
{
v5[2] = v6;
v5[1] = v6;
*v5 = v6;
v6 += 17;
v5 += 3;
}
while ( (_BYTE)v6 != 16 );
memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_panel + 68)),
*(const void **)(llander_panel + 40),
3 * *(_DWORD *)(llander_panel + 48));
result = memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_lit_panel + 68)),
*(const void **)(llander_lit_panel + 40),
3 * *(_DWORD *)(llander_lit_panel + 48));
}
else
{
result = (void *)artwork_free(&llander_panel, "llander1.png", v5);
}
}
return result;
}

original_code:
void llander_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int width, height, i, nextcol;
 avg_init_palette_white(palette,colortable,color_prom);
 llander_lit_panel = ((void *)0);
 width = Machine->scrbitmap->width;
 height = 0.16 * width;
 nextcol = 24;
 artwork_load_size(&llander_panel, "llander.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
 if (llander_panel != ((void *)0))
 {
  if (Machine->scrbitmap->depth == 8)
   nextcol += llander_panel->num_pens_used;
  artwork_load_size(&llander_lit_panel, "llander1.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
  if (llander_lit_panel == ((void *)0))
  {
   artwork_free(&llander_panel);
   return ;
  }
 }
 else
  return;
 for (i = 0; i < 16; i++)
  palette[3*(i+8)]=palette[3*(i+8)+1]=palette[3*(i+8)+2]= (255*i)/15;
 memcpy (palette+3*llander_panel->start_pen, llander_panel->orig_palette,
   3*llander_panel->num_pens_used);
 memcpy (palette+3*llander_lit_panel->start_pen, llander_lit_panel->orig_palette,
   3*llander_lit_panel->num_pens_used);
}

canonical_original_code:
void llander_init_colors(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int width; int height; int i; int nextcol;
 avg_init_palette_white(palette,colortable,color_prom);
 llander_lit_panel = ((void *)0);
 width = Machine->scrbitmap->width;
 height = 0.16 * width;
 nextcol = 24;
 artwork_load_size(&llander_panel, "llander.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
 if (llander_panel != ((void *)0))
 {
  if (Machine->scrbitmap->depth == 8)
   nextcol += llander_panel->num_pens_used;
  artwork_load_size(&llander_lit_panel, "llander1.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
  if (llander_lit_panel == ((void *)0))
  {
   artwork_free(&llander_panel);
   return ;
  }
 }
 else
  return;
 for (i = 0; i < 16; i++)
  palette[3*(i+8)]=palette[3*(i+8)+1]=palette[3*(i+8)+2]= (255*i)/15;
 memcpy (palette+3*llander_panel->start_pen, llander_panel->orig_palette,
   3*llander_panel->num_pens_used);
 memcpy (palette+3*llander_lit_panel->start_pen, llander_lit_panel->orig_palette,
   3*llander_lit_panel->num_pens_used);
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: width int

variable_types: height int

variable_types: i int

variable_types: nextcol int


decompiled_code:
__int64 llander_start()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)dvg_start() )
{
v0 = 0;
if ( llander_panel )
{
lights = 0;
lights_changed = 1;
dword_514 = 0;
dword_4F4 = 1;
dword_518 = 0;
dword_4F8 = 1;
dword_51C = 0;
dword_4FC = 1;
dword_520 = 0;
dword_500 = 1;
backdrop_refresh();
if ( llander_lit_panel )
backdrop_refresh();
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)dvg_start() )
{
v0 = 0;
if ( llander_panel )
{
lights = 0;
lights_changed = 1;
dword_514 = 0;
dword_4F4 = 1;
dword_518 = 0;
dword_4F8 = 1;
dword_51C = 0;
dword_4FC = 1;
dword_520 = 0;
dword_500 = 1;
backdrop_refresh();
if ( llander_lit_panel )
backdrop_refresh();
}
}
return v0;
}

original_code:
int llander_start(void)
{
 int i;
 if (dvg_start())
  return 1;
 if (llander_panel == ((void *)0))
  return 0;
 for (i=0;i<5;i++)
 {
  lights[i] = 0;
  lights_changed[i] = 1;
 }
 if (llander_panel) backdrop_refresh(llander_panel);
 if (llander_lit_panel) backdrop_refresh(llander_lit_panel);
 return 0;
}

canonical_original_code:
int llander_start()
{
 int i;
 if (dvg_start())
  return 1;
 if (llander_panel == ((void *)0))
  return 0;
 for (i=0;i<5;i++)
 {
  lights[i] = 0;
  lights_changed[i] = 1;
 }
 if (llander_panel) backdrop_refresh(llander_panel);
 if (llander_lit_panel) backdrop_refresh(llander_lit_panel);
 return 0;
}


decompiled_code:
__int64 __fastcall llander_stop(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = dvg_stop();
if ( llander_panel )
result = artwork_free(&llander_panel, a2, v3);
if ( llander_lit_panel )
result = artwork_free(&llander_lit_panel, a2, v3);
return result;
}

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

result = dvg_stop();
if ( llander_panel )
result = artwork_free(&llander_panel, a2, v3);
if ( llander_lit_panel )
result = artwork_free(&llander_lit_panel, a2, v3);
return result;
}

original_code:
void llander_stop(void)
{
 dvg_stop();
 if (llander_panel != ((void *)0))
  artwork_free(&llander_panel);
 if (llander_lit_panel != ((void *)0))
  artwork_free(&llander_lit_panel);
}

canonical_original_code:
void llander_stop()
{
 dvg_stop();
 if (llander_panel != ((void *)0))
  artwork_free(&llander_panel);
 if (llander_lit_panel != ((void *)0))
  artwork_free(&llander_lit_panel);
}


decompiled_code:
__int64 __fastcall llander_screenrefresh(__int64 a1, unsigned int a2)
{
int v2; // ebx
float v3; // xmm4_4
int *v4; // rbx
int *v5; // rbp
int *v6; // r13
__int64 result; // rax
float v8; // xmm2_4
int v9; // [rsp+10h] [rbp-78h]
float v10; // [rsp+14h] [rbp-74h]
unsigned int v11; // [rsp+20h] [rbp-68h]
unsigned int v12; // [rsp+24h] [rbp-64h]
unsigned int v13; // [rsp+28h] [rbp-60h]
unsigned int v14; // [rsp+28h] [rbp-60h]
unsigned int v15; // [rsp+2Ch] [rbp-5Ch]
unsigned int v16; // [rsp+2Ch] [rbp-5Ch]
int v17[4]; // [rsp+30h] [rbp-58h] BYREF
__int64 v18; // [rsp+40h] [rbp-48h]
__int64 v19; // [rsp+48h] [rbp-40h]

if ( !llander_panel )
return ((__int64 (*)(void))vector_vh_screenrefresh)();
v2 = **(_DWORD **)llander_panel;
v9 = *(_DWORD *)(*(_QWORD *)llander_panel + 4LL);
v17[0] = *(_DWORD *)a1;
v17[1] = *(_DWORD *)(a1 + 4) - v9;
v18 = *(_QWORD *)(a1 + 16);
v19 = *(_QWORD *)(a1 + 24);
vector_vh_screenrefresh(v17);
if ( a2 )
{
v13 = *(_DWORD *)(a1 + 4) - v9;
v15 = *(_DWORD *)(a1 + 4) - 1;
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
osd_mark_dirty(0LL, v13, (unsigned int)(v2 - 1), v15, 0LL);
}
v3 = (double)v2 / 800.0;
v10 = v3;
v4 = &lights_changed;
v5 = (int *)&light_areas;
v6 = &lights;
do
{
result = *v4 | a2;
if ( *v4 | a2 )
{
v11 = (int)(float)((float)*v5 * v10);
v12 = (int)(float)((float)v5[1] * v10);
v8 = (float)(*(_DWORD *)(a1 + 4) - v9);
v14 = (int)(float)((float)((float)v5[2] * v10) + v8);
v16 = (int)(float)((float)((float)v5[3] * v10) + v8);
if ( *v6 )
copybitmap(a1, *(_QWORD *)llander_lit_panel, 0LL, 0LL, 0LL);
else
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
osd_mark_dirty(v11, v14, v12, v16, 0LL);
result = (__int64)v4;
*v4 = 0;
}
++v4;
v5 += 4;
++v6;
}
while ( v4 != &lights_changed + 5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
int v2; // ebx
float v3; // xmm4_4
int *v4; // rbx
int *v5; // rbp
int *v6; // r13
__int64 result; // rax
float v8; // xmm2_4
int v9; // [rsp+10h] [rbp-78h]
float v10; // [rsp+14h] [rbp-74h]
unsigned int v11; // [rsp+20h] [rbp-68h]
unsigned int v12; // [rsp+24h] [rbp-64h]
unsigned int v13; // [rsp+28h] [rbp-60h]
unsigned int v14; // [rsp+28h] [rbp-60h]
unsigned int v15; // [rsp+2Ch] [rbp-5Ch]
unsigned int v16; // [rsp+2Ch] [rbp-5Ch]
int v17[4]; // [rsp+30h] [rbp-58h] BYREF
__int64 v18; // [rsp+40h] [rbp-48h]
__int64 v19; // [rsp+48h] [rbp-40h]

if ( !llander_panel )
return ((__int64 (*)(void))vector_vh_screenrefresh)();
v2 = **(_DWORD **)llander_panel;
v9 = *(_DWORD *)(*(_QWORD *)llander_panel + 4LL);
v17[0] = *(_DWORD *)a1;
v17[1] = *(_DWORD *)(a1 + 4) - v9;
v18 = *(_QWORD *)(a1 + 16);
v19 = *(_QWORD *)(a1 + 24);
vector_vh_screenrefresh(v17);
if ( a2 )
{
v13 = *(_DWORD *)(a1 + 4) - v9;
v15 = *(_DWORD *)(a1 + 4) - 1;
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
osd_mark_dirty(0LL, v13, (unsigned int)(v2 - 1), v15, 0LL);
}
v3 = (double)v2 / 800.0;
v10 = v3;
v4 = &lights_changed;
v5 = (int *)&light_areas;
v6 = &lights;
do
{
result = *v4 | a2;
if ( *v4 | a2 )
{
v11 = (int)(float)((float)*v5 * v10);
v12 = (int)(float)((float)v5[1] * v10);
v8 = (float)(*(_DWORD *)(a1 + 4) - v9);
v14 = (int)(float)((float)((float)v5[2] * v10) + v8);
v16 = (int)(float)((float)((float)v5[3] * v10) + v8);
if ( *v6 )
copybitmap(a1, *(_QWORD *)llander_lit_panel, 0LL, 0LL, 0LL);
else
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
osd_mark_dirty(v11, v14, v12, v16, 0LL);
result = (__int64)v4;
*v4 = 0;
}
++v4;
v5 += 4;
++v6;
}
while ( v4 != &lights_changed + 5 );
return result;
}

original_code:
void llander_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i, pwidth, pheight;
 float scale;
 struct osd_bitmap vector_bitmap;
 struct rectangle rect;
 if (llander_panel == ((void *)0))
 {
  vector_vh_screenrefresh(bitmap,full_refresh);
  return;
 }
 pwidth = llander_panel->artwork->width;
 pheight = llander_panel->artwork->height;
 vector_bitmap.width = bitmap->width;
 vector_bitmap.height = bitmap->height - pheight;
 vector_bitmap._private = bitmap->_private;
 vector_bitmap.line = bitmap->line;
 vector_vh_screenrefresh(&vector_bitmap,full_refresh);
 if (full_refresh)
 {
  rect.min_x = 0;
  rect.max_x = pwidth-1;
  rect.min_y = bitmap->height - pheight;
  rect.max_y = bitmap->height - 1;
  copybitmap(bitmap,llander_panel->artwork,0,0,
       0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
  osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
 }
 scale = pwidth/800.0;
 for (i=0;i<5;i++)
 {
  if (lights_changed[i] || full_refresh)
  {
   rect.min_x = scale * light_areas[i].min_x;
   rect.max_x = scale * light_areas[i].max_x;
   rect.min_y = bitmap->height - pheight + scale * light_areas[i].min_y;
   rect.max_y = bitmap->height - pheight + scale * light_areas[i].max_y;
   if (lights[i])
    copybitmap(bitmap,llander_lit_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   else
    copybitmap(bitmap,llander_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
   lights_changed[i] = 0;
  }
 }
}

canonical_original_code:
void llander_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i; int pwidth; int pheight;
 float scale;
 struct osd_bitmap vector_bitmap;
 struct rectangle rect;
 if (llander_panel == ((void *)0))
 {
  vector_vh_screenrefresh(bitmap,full_refresh);
  return;
 }
 pwidth = llander_panel->artwork->width;
 pheight = llander_panel->artwork->height;
 vector_bitmap.width = bitmap->width;
 vector_bitmap.height = bitmap->height - pheight;
 vector_bitmap._private = bitmap->_private;
 vector_bitmap.line = bitmap->line;
 vector_vh_screenrefresh(&vector_bitmap,full_refresh);
 if (full_refresh)
 {
  rect.min_x = 0;
  rect.max_x = pwidth-1;
  rect.min_y = bitmap->height - pheight;
  rect.max_y = bitmap->height - 1;
  copybitmap(bitmap,llander_panel->artwork,0,0,
       0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
  osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
 }
 scale = pwidth/800.0;
 for (i=0;i<5;i++)
 {
  if (lights_changed[i] || full_refresh)
  {
   rect.min_x = scale * light_areas[i].min_x;
   rect.max_x = scale * light_areas[i].max_x;
   rect.min_y = bitmap->height - pheight + scale * light_areas[i].min_y;
   rect.max_y = bitmap->height - pheight + scale * light_areas[i].max_y;
   if (lights[i])
    copybitmap(bitmap,llander_lit_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   else
    copybitmap(bitmap,llander_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
   lights_changed[i] = 0;
  }
 }
}

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

variable_types: pwidth int

variable_types: pheight int

variable_types: scale float

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


decompiled_code:
__int64 __fastcall llander_led_w(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

for ( result = 0LL; result != 5; ++result )
{
v3 = (a2 & (1 << (4 - result))) != 0;
if ( lights[result] != v3 )
{
lights[result] = v3;
lights_changed[result] = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

for ( result = 0LL; result != 5; ++result )
{
v3 = (a2 & (1 << (4 - result))) != 0;
if ( lights[result] != v3 )
{
lights[result] = v3;
lights_changed[result] = 1;
}
}
return result;
}

original_code:
void llander_led_w(offs_t offset,data_t data)
{
    int i;
    for (i=0;i<5;i++)
    {
  int new_light = (data & (1 << (4-i))) != 0;
  if (lights[i] != new_light)
  {
   lights[i] = new_light;
   lights_changed[i] = 1;
  }
    }
}

canonical_original_code:
void llander_led_w(unsigned int offset, unsigned int data)
{
    int i;
    for (i=0;i<5;i++)
    {
  int new_light = (data & (1 << (4-i))) != 0;
  if (lights[i] != new_light)
  {
   lights[i] = new_light;
   lights_changed[i] = 1;
  }
    }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall suprloco_scrollram_r(int a1)
{
return suprloco_scrollram[a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return suprloco_scrollram[a1];
}

original_code:
data_t suprloco_scrollram_r(offs_t offset)
{
 return suprloco_scrollram[offset];
}

canonical_original_code:
unsigned int suprloco_scrollram_r(unsigned int offset)
{
 return suprloco_scrollram[offset];
}


decompiled_code:
__int64 suprloco_control_r()
{
return (unsigned int)control;
}

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

original_code:
data_t suprloco_control_r(offs_t offset)
{
 return control;
}

canonical_original_code:
unsigned int suprloco_control_r(unsigned int offset)
{
 return control;
}


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

if ( flip_screen_x )
{
a2 = *a1 + ~a2;
a3 = a1[1] + ~a3;
}
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= a2
&& *(_DWORD *)(Machine + 780LL) >= a2
&& *(_DWORD *)(Machine + 784LL) <= a3
&& *(_DWORD *)(Machine + 788LL) >= a3 )
{
result = plot_pixel();
}
return result;
}

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

if ( flip_screen_x )
{
a2 = *a1 + ~a2;
a3 = a1[1] + ~a3;
}
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= a2
&& *(_DWORD *)(Machine + 780LL) >= a2
&& *(_DWORD *)(Machine + 784LL) <= a3
&& *(_DWORD *)(Machine + 788LL) >= a3 )
{
result = plot_pixel();
}
return result;
}

original_code:
static inline void draw_pixel(struct osd_bitmap *bitmap,int x,int y,int color)
{
 if (flip_screen_x)
 {
  x = bitmap->width - x - 1;
  y = bitmap->height - y - 1;
 }
 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)
  return;
 plot_pixel(bitmap, x, y, color);
}

canonical_original_code:
static inline void draw_pixel(struct osd_bitmap *bitmap, int x, int y, int color)
{
 if (flip_screen_x)
 {
  x = bitmap->width - x - 1;
  y = bitmap->height - y - 1;
 }
 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)
  return;
 plot_pixel(bitmap, x, y, color);
}

variable_types: x int

variable_types: y int

variable_types: color int

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


decompiled_code:
__int64 suprloco_vh_start()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
tilemap_set_scroll_rows(v0, 32LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
tilemap_set_scroll_rows(v0, 32LL);
result = 0LL;
}
return result;
}

original_code:
int suprloco_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}

canonical_original_code:
int suprloco_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}


decompiled_code:
__int64 __fastcall suprloco_scrollram_w(unsigned int a1, unsigned int a2)
{
int v2; // eax

v2 = flip_screen_x == 0 ? 8 : -8;
suprloco_scrollram[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, a1, a2 - v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
int v2; // eax

v2 = flip_screen_x == 0 ? 8 : -8;
suprloco_scrollram[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, a1, a2 - v2);
}

original_code:
void suprloco_scrollram_w(offs_t offset,data_t data)
{
 int adj = flip_screen_x ? -8 : 8;
 suprloco_scrollram[offset] = data;
 tilemap_set_scrollx(bg_tilemap,offset, data - adj);
}

canonical_original_code:
void suprloco_scrollram_w(unsigned int offset, unsigned int data)
{
 int adj = flip_screen_x ? -8 : 8;
 suprloco_scrollram[offset] = data;
 tilemap_set_scrollx(bg_tilemap,offset, data - adj);
}

variable_types: adj int


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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
flip_screen_w(0LL, a2 & 0x80);
result = tilemap_set_scrolly(bg_tilemap, 0LL, flip_screen_x != 0 ? 0xFFFFFFE0 : 0);
control = a2;
return result;
}

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
flip_screen_w(0LL, a2 & 0x80);
result = tilemap_set_scrolly(bg_tilemap, 0LL, flip_screen_x != 0 ? 0xFFFFFFE0 : 0);
control = a2;
return result;
}

original_code:
void suprloco_control_w(offs_t offset,data_t data)
{
 if ((control & 0x10) != (data & 0x10))
 {
 }
 coin_counter_w(0, data & 0x01);
 coin_counter_w(1, data & 0x02);
 flip_screen_w(0,data & 0x80);
 tilemap_set_scrolly(bg_tilemap,0,flip_screen_x ? -32 : 0);
 control = data;
}

canonical_original_code:
void suprloco_control_w(unsigned int offset, unsigned int data)
{
 if ((control & 0x10) != (data & 0x10))
 {
 }
 coin_counter_w(0, data & 0x01);
 coin_counter_w(1, data & 0x02);
 flip_screen_w(0,data & 0x80);
 tilemap_set_scrolly(bg_tilemap,0,flip_screen_x ? -32 : 0);
 control = data;
}


original_code:
static void render_sprite(struct osd_bitmap *bitmap,int spr_number)
{
 int sx,sy,col,row,height,src,adjy,dy;
 unsigned char *spr_reg;
 unsigned short *spr_palette;
 short skip;
 spr_reg = spriteram + 0x10 * spr_number;
 src = spr_reg[6] + (spr_reg[7] << 8);
 skip = spr_reg[4] + (spr_reg[5] << 8);
 height = spr_reg[1] - spr_reg[0];
 spr_palette = Machine->remapped_colortable + 0x100 + 0x10 * spr_reg[3] + ((control & 0x20)?0x100:0);
 sx = spr_reg[2];
 sy = spr_reg[0] + 1;
 if (!flip_screen_x)
 {
  adjy = sy;
  dy = 1;
 }
 else
 {
  adjy = sy + height + 30;
  dy = -1;
 }
 for (row = 0;row < height;row++,adjy+=dy)
 {
  int color1,color2,flipx;
  UINT8 data;
  UINT8 *gfx;
  src += skip;
  col = 0;
  gfx = &(memory_region(REGION_GFX2)[src & 0x7fff]);
  flipx = src & 0x8000;
  while (1)
  {
   if (flipx)
   {
    data = *gfx--;
    color1 = data & 0x0f;
    color2 = data >> 4;
   }
   else
   {
    data = *gfx++;
    color1 = data >> 4;
    color2 = data & 0x0f;
   }
   if (color1 == 15) break;
   if (color1)
    draw_pixel(bitmap,sx+col, adjy,spr_palette[color1]);
   if (color2 == 15) break;
   if (color2)
    draw_pixel(bitmap,sx+col+1,adjy,spr_palette[color2]);
   col += 2;
  }
 }
}

canonical_original_code:
static void render_sprite(struct osd_bitmap *bitmap, int spr_number)
{
 int sx; int sy; int col; int row; int height; int src; int adjy; int dy;
 unsigned char *spr_reg;
 unsigned short *spr_palette;
 short skip;
 spr_reg = spriteram + 0x10 * spr_number;
 src = spr_reg[6] + (spr_reg[7] << 8);
 skip = spr_reg[4] + (spr_reg[5] << 8);
 height = spr_reg[1] - spr_reg[0];
 spr_palette = Machine->remapped_colortable + 0x100 + 0x10 * spr_reg[3] + ((control & 0x20)?0x100:0);
 sx = spr_reg[2];
 sy = spr_reg[0] + 1;
 if (!flip_screen_x)
 {
  adjy = sy;
  dy = 1;
 }
 else
 {
  adjy = sy + height + 30;
  dy = -1;
 }
 for (row = 0;row < height;row++,adjy+=dy)
 {
  int color1; int color2; int flipx;
  unsigned char data;
  unsigned char *gfx;
  src += skip;
  col = 0;
  gfx = &(memory_region(REGION_GFX2)[src & 0x7fff]);
  flipx = src & 0x8000;
  while (1)
  {
   if (flipx)
   {
    data = *gfx--;
    color1 = data & 0x0f;
    color2 = data >> 4;
   }
   else
   {
    data = *gfx++;
    color1 = data >> 4;
    color2 = data & 0x0f;
   }
   if (color1 == 15) break;
   if (color1)
    draw_pixel(bitmap,sx+col, adjy,spr_palette[color1]);
   if (color2 == 15) break;
   if (color2)
    draw_pixel(bitmap,sx+col+1,adjy,spr_palette[color2]);
   col += 2;
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: col int

variable_types: row int

variable_types: src int

variable_types: adjy int

variable_types: dy int

variable_types: skip short

variable_types: flipx int

variable_types:
data
unsigned char

variable_types:
gfx
unsigned char *


decompiled_code:
__int64 __fastcall suprloco_vh_screenrefresh(_DWORD *a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func9(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

original_code:
void suprloco_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,1);
}

canonical_original_code:
void suprloco_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,1);
}

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


original_code:
void init_suprloco(void)
{
 int i, j, k, color_source, color_dest;
 unsigned char *source, *dest, *lookup;
 source = memory_region(REGION_GFX1);
 dest = source + 0x6000;
 lookup = memory_region(REGION_PROMS) + 0x0200;
 for (i = 0; i < 0x80; i++, lookup += 8)
 {
  for (j = 0; j < 0x40; j++, source++, dest++)
  {
   dest[0] = dest[0x2000] = dest[0x4000] = dest[0x6000] = 0;
   for (k = 0; k < 8; k++)
   {
    color_source = (((source[0x0000] >> k) & 0x01) << 2) |
          (((source[0x2000] >> k) & 0x01) << 1) |
          (((source[0x4000] >> k) & 0x01) << 0);
    color_dest = lookup[color_source];
    dest[0x0000] |= (((color_dest >> 3) & 0x01) << k);
    dest[0x2000] |= (((color_dest >> 2) & 0x01) << k);
    dest[0x4000] |= (((color_dest >> 1) & 0x01) << k);
    dest[0x6000] |= (((color_dest >> 0) & 0x01) << k);
   }
  }
 }
 suprloco_decode();
}

canonical_original_code:
void init_suprloco()
{
 int i; int j; int k; int color_source; int color_dest;
 unsigned char *source; unsigned char *dest; unsigned char *lookup;
 source = memory_region(REGION_GFX1);
 dest = source + 0x6000;
 lookup = memory_region(REGION_PROMS) + 0x0200;
 for (i = 0; i < 0x80; i++, lookup += 8)
 {
  for (j = 0; j < 0x40; j++, source++, dest++)
  {
   dest[0] = dest[0x2000] = dest[0x4000] = dest[0x6000] = 0;
   for (k = 0; k < 8; k++)
   {
    color_source = (((source[0x0000] >> k) & 0x01) << 2) |
          (((source[0x2000] >> k) & 0x01) << 1) |
          (((source[0x4000] >> k) & 0x01) << 0);
    color_dest = lookup[color_source];
    dest[0x0000] |= (((color_dest >> 3) & 0x01) << k);
    dest[0x2000] |= (((color_dest >> 2) & 0x01) << k);
    dest[0x4000] |= (((color_dest >> 1) & 0x01) << k);
    dest[0x6000] |= (((color_dest >> 0) & 0x01) << k);
   }
  }
 }
 suprloco_decode();
}

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
source
unsigned char *

variable_types:
dest
unsigned char *

variable_types:
lookup
unsigned char *


decompiled_code:
__int64 suprloco_soundport_w()
{
soundlatch_w(0LL);
cpu_cause_interrupt(1LL, 4294967294LL);
return cpu_spinuntil_time(53687LL);
}

canonical_decompiled_code:
__int64 func12()
{
soundlatch_w(0LL);
cpu_cause_interrupt(1LL, 4294967294LL);
return cpu_spinuntil_time(53687LL);
}

original_code:
static void suprloco_soundport_w(offs_t offset,data_t data)
{
 soundlatch_w(0,data);
 cpu_cause_interrupt(1,-2);
 cpu_spinuntil_time(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)));
}

canonical_original_code:
static void suprloco_soundport_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(0,data);
 cpu_cause_interrupt(1,-2);
 cpu_spinuntil_time(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)));
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall get_tile_info(int a1)
{
__int64 v1; // rdi
__int64 v2; // rsi
int v3; // ecx
int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
__int64 v1; // rdi
__int64 v2; // rsi
int v3; // ecx
int v4; // edx
__int64 v5; // rax
int v6; // esi
void *result; // rax

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

original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = suprloco_videoram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (suprloco_videoram[2*tile_index] | ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x1c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.priority = (attr & 0x20) >> 5;
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = suprloco_videoram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (suprloco_videoram[2*tile_index] | ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x1c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.priority = (attr & 0x20) >> 5;
}

variable_types:
attr
unsigned char

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


decompiled_code:
__int64 __fastcall draw_sprites(_DWORD *a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx

result = spriteram_size >> 4;
if ( spriteram_size >> 4 )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(spriteram + 16 * v2 + 2) != 0xFF )
render_sprite(a1, v2);
++v2;
result = spriteram_size >> 4;
}
while ( spriteram_size >> 4 > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx

result = spriteram_size >> 4;
if ( spriteram_size >> 4 )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(spriteram + 16 * v2 + 2) != 0xFF )
func8(a1, v2);
++v2;
result = spriteram_size >> 4;
}
while ( spriteram_size >> 4 > v2 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int spr_number;
 unsigned char *spr_reg;
 for (spr_number = 0;spr_number < (spriteram_size >> 4);spr_number++)
 {
  spr_reg = spriteram + 0x10 * spr_number;
  if (spr_reg[2] != 0xff)
   render_sprite(bitmap,spr_number);
 }
}


decompiled_code:
void __fastcall mpatrol_bg1xpos_w(__int64 a1, char a2)
{
bg1xpos = a2;
}

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

original_code:
void mpatrol_bg1xpos_w(offs_t offset,data_t data)
{
 bg1xpos = data;
}

canonical_original_code:
void mpatrol_bg1xpos_w(unsigned int offset, unsigned int data)
{
 bg1xpos = data;
}


decompiled_code:
void __fastcall mpatrol_bg1ypos_w(__int64 a1, char a2)
{
bg1ypos = a2;
}

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

original_code:
void mpatrol_bg1ypos_w(offs_t offset,data_t data)
{
 bg1ypos = data;
}

canonical_original_code:
void mpatrol_bg1ypos_w(unsigned int offset, unsigned int data)
{
 bg1ypos = data;
}


decompiled_code:
void __fastcall mpatrol_bg2xpos_w(__int64 a1, char a2)
{
bg2xpos = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, char a2)
{
bg2xpos = a2;
}

original_code:
void mpatrol_bg2xpos_w(offs_t offset,data_t data)
{
 bg2xpos = data;
}

canonical_original_code:
void mpatrol_bg2xpos_w(unsigned int offset, unsigned int data)
{
 bg2xpos = data;
}


decompiled_code:
void __fastcall mpatrol_bg2ypos_w(__int64 a1, char a2)
{
bg2ypos = a2;
}

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

original_code:
void mpatrol_bg2ypos_w(offs_t offset,data_t data)
{
 bg2ypos = data;
}

canonical_original_code:
void mpatrol_bg2ypos_w(unsigned int offset, unsigned int data)
{
 bg2ypos = data;
}


decompiled_code:
void __fastcall mpatrol_bgcontrol_w(__int64 a1, char a2)
{
bgcontrol = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char a2)
{
bgcontrol = a2;
}

original_code:
void mpatrol_bgcontrol_w(offs_t offset,data_t data)
{
 bgcontrol = data;
}

canonical_original_code:
void mpatrol_bgcontrol_w(unsigned int offset, unsigned int data)
{
 bgcontrol = data;
}


decompiled_code:
__int64 mpatrol_vh_start()
{
__int64 v0; // rax
unsigned int i; // ebx
int v3; // [rsp+0h] [rbp-48h]
unsigned int v4; // [rsp+4h] [rbp-44h]
__int64 *v5; // [rsp+8h] [rbp-40h]

v4 = generic_vh_start();
if ( v4 )
return 1;
v5 = &bgbitmap;
v3 = 3;
while ( 1 )
{
v0 = bitmap_alloc(256LL, 64LL);
*v5 = v0;
if ( !v0 )
break;
for ( i = 0; i != 8; ++i )
{
drawgfx(*v5, *(_QWORD *)(Machine + 8 * (v3 - 1 + 64LL)), i, 0LL, 0LL, 0LL, 32 * i, 0LL, 0LL, 0LL, 0LL);
drawgfx(*v5, *(_QWORD *)(Machine + 8 * (v3 + 64LL)), i, 0LL, 0LL, 0LL, 32 * i, 32LL, 0LL, 0LL, 0LL);
}
++v5;
v3 += 2;
if ( v3 == 9 )
return v4;
}
generic_vh_stop();
return 1;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
unsigned int i; // ebx
int v3; // [rsp+0h] [rbp-48h]
unsigned int v4; // [rsp+4h] [rbp-44h]
__int64 *v5; // [rsp+8h] [rbp-40h]

v4 = generic_vh_start();
if ( v4 )
return 1;
v5 = &bgbitmap;
v3 = 3;
while ( 1 )
{
v0 = bitmap_alloc(256LL, 64LL);
*v5 = v0;
if ( !v0 )
break;
for ( i = 0; i != 8; ++i )
{
drawgfx(*v5, *(_QWORD *)(Machine + 8 * (v3 - 1 + 64LL)), i, 0LL, 0LL, 0LL, 32 * i, 0LL, 0LL, 0LL, 0LL);
drawgfx(*v5, *(_QWORD *)(Machine + 8 * (v3 + 64LL)), i, 0LL, 0LL, 0LL, 32 * i, 32LL, 0LL, 0LL, 0LL);
}
++v5;
v3 += 2;
if ( v3 == 9 )
return v4;
}
generic_vh_stop();
return 1;
}

original_code:
int mpatrol_vh_start(void)
{
 int i,j;
 if (generic_vh_start() != 0)
  return 1;
 for (i = 0;i < 3;i++)
 {
  if ((bgbitmap[i] = bitmap_alloc(256,(64))) == 0)
  {
   generic_vh_stop();
   return 1;
  }
  for (j = 0;j < 8;j++)
  {
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i],
     j,0,
     0,0,
     32 * j,0,
     0,TRANSPARENCY_NONE,0);
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i + 1],
     j,0,
     0,0,
     32 * j,((64) / 2),
     0,TRANSPARENCY_NONE,0);
  }
 }
 return 0;
}

canonical_original_code:
int mpatrol_vh_start()
{
 int i; int j;
 if (generic_vh_start() != 0)
  return 1;
 for (i = 0;i < 3;i++)
 {
  if ((bgbitmap[i] = bitmap_alloc(256,(64))) == 0)
  {
   generic_vh_stop();
   return 1;
  }
  for (j = 0;j < 8;j++)
  {
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i],
     j,0,
     0,0,
     32 * j,0,
     0,TRANSPARENCY_NONE,0);
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i + 1],
     j,0,
     0,0,
     32 * j,((64) / 2),
     0,TRANSPARENCY_NONE,0);
  }
 }
 return 0;
}


decompiled_code:
__int64 mpatrol_vh_stop()
{
bitmap_free(bgbitmap);
bitmap_free(qword_1548);
bitmap_free(qword_1550);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func8()
{
bitmap_free(bgbitmap);
bitmap_free(qword_1548);
bitmap_free(qword_1550);
return generic_vh_stop();
}

original_code:
void mpatrol_vh_stop(void)
{
 bitmap_free(bgbitmap[0]);
 bitmap_free(bgbitmap[1]);
 bitmap_free(bgbitmap[2]);
 generic_vh_stop();
}

canonical_original_code:
void mpatrol_vh_stop()
{
 bitmap_free(bgbitmap[0]);
 bitmap_free(bgbitmap[1]);
 bitmap_free(bgbitmap[2]);
 generic_vh_stop();
}


decompiled_code:
__int64 __fastcall mpatrol_flipscreen_w(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
if ( (v2 & 1) != flipscreen )
{
flipscreen = v2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
if ( (v2 & 1) != flipscreen )
{
flipscreen = v2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

original_code:
void mpatrol_flipscreen_w(offs_t offset,data_t data)
{
 data ^= ~readinputport(4) & 1;
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void mpatrol_flipscreen_w(unsigned int offset, unsigned int data)
{
 data ^= ~readinputport(4) & 1;
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 mpatrol_input_port_3_r()
{
int v0; // ebx
__int64 result; // rax

v0 = input_port_3_r(0LL);
if ( (input_port_4_r(0LL) & 4) != 0 )
result = v0 | (16 * (unsigned int)input_port_5_r(0LL));
else
result = v0 | (unsigned int)(input_port_5_r(0LL) & 0xF0);
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
__int64 result; // rax

v0 = input_port_3_r(0LL);
if ( (input_port_4_r(0LL) & 4) != 0 )
result = v0 | (16 * (unsigned int)input_port_5_r(0LL));
else
result = v0 | (unsigned int)(input_port_5_r(0LL) & 0xF0);
return result;
}

original_code:
data_t mpatrol_input_port_3_r(offs_t offset)
{
 int ret = input_port_3_r(0);
 if (input_port_4_r(0) & 0x04)
 {
  ret |= (input_port_5_r(0) << 4);
 }
 else
 {
  ret |= (input_port_5_r(0) & 0xf0);
 }
 return ret;
}

canonical_original_code:
unsigned int mpatrol_input_port_3_r(unsigned int offset)
{
 int ret = input_port_3_r(0);
 if (input_port_4_r(0) & 0x04)
 {
  ret |= (input_port_5_r(0) << 4);
 }
 else
 {
  ret |= (input_port_5_r(0) & 0xf0);
 }
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 mpatrol_protection_r()
{
return (unsigned __int8)cpu_get_reg(5LL);
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned __int8)cpu_get_reg(5LL);
}

original_code:
data_t mpatrol_protection_r(offs_t offset)
{
 return cpu_get_reg(Z80_DE) & 0xff;
}

canonical_original_code:
unsigned int mpatrol_protection_r(unsigned int offset)
{
 return cpu_get_reg(Z80_DE) & 0xff;
}


decompiled_code:
__int64 __fastcall draw_background(__int64 a1, unsigned int a2, int a3, int a4, int a5, unsigned int a6)
{
unsigned int v6; // ebp
unsigned int v7; // ebx
__int64 v9; // r12
_DWORD v12[4]; // [rsp+10h] [rbp-58h] BYREF
_DWORD v13[18]; // [rsp+20h] [rbp-48h] BYREF

v6 = a2;
v7 = a3;
v9 = a6;
get_clip(v13, a3, a3 + 63);
get_clip(v12, v7 + 64, a4);
if ( flipscreen )
{
v6 = 256 - a2;
v7 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) - 64 - v7;
}
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v6, v7, v13, v9, 128LL);
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v6 - 256, v7, v13, v9, 128LL);
return fillbitmap(
a1,
*(unsigned __int16 *)(*(_QWORD *)(*(_QWORD *)(Machine + 8LL * (2 * a5 + 2) + 512) + 16LL) + 6LL),
v12);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2, int a3, int a4, int a5, unsigned int a6)
{
unsigned int v6; // ebp
unsigned int v7; // ebx
__int64 v9; // r12
_DWORD v12[4]; // [rsp+10h] [rbp-58h] BYREF
_DWORD v13[18]; // [rsp+20h] [rbp-48h] BYREF

v6 = a2;
v7 = a3;
v9 = a6;
func6(v13, a3, a3 + 63);
func6(v12, v7 + 64, a4);
if ( flipscreen )
{
v6 = 256 - a2;
v7 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) - 64 - v7;
}
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v6, v7, v13, v9, 128LL);
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v6 - 256, v7, v13, v9, 128LL);
return fillbitmap(
a1,
*(unsigned __int16 *)(*(_QWORD *)(*(_QWORD *)(Machine + 8LL * (2 * a5 + 2) + 512) + 16LL) + 6LL),
v12);
}

original_code:
static void draw_background(struct osd_bitmap *bitmap,
                            int xpos, int ypos, int ypos_end, int image,
       int transparency)
{
 struct rectangle clip1, clip2;
 get_clip(&clip1, ypos, ypos + (64) - 1);
 get_clip(&clip2, ypos + (64), ypos_end);
 if (flipscreen)
 {
  xpos = 256 - xpos;
  ypos = Machine->drv->screen_height - (64) - ypos;
 }
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos, ypos,&clip1,transparency,128);
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos - 256,ypos,&clip1,transparency,128);
 fillbitmap(bitmap,Machine->gfx[image*2+2]->colortable[3],&clip2);
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap, int xpos, int ypos, int ypos_end, int image, int transparency)
{
 struct rectangle clip1; struct rectangle clip2;
 get_clip(&clip1, ypos, ypos + (64) - 1);
 get_clip(&clip2, ypos + (64), ypos_end);
 if (flipscreen)
 {
  xpos = 256 - xpos;
  ypos = Machine->drv->screen_height - (64) - ypos;
 }
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos, ypos,&clip1,transparency,128);
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos - 256,ypos,&clip1,transparency,128);
 fillbitmap(bitmap,Machine->gfx[image*2+2]->colortable[3],&clip2);
}

variable_types: xpos int

variable_types: ypos int

variable_types: image int

variable_types: transparency int

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


decompiled_code:
__int64 DAC_build_voltable()
{
__int64 v0; // rcx
__int64 result; // rax

v0 = 0LL;
LODWORD(result) = 0;
do
{
*(_DWORD *)((char *)&UnsignedVolTable + v0) = (int)result / 2;
*(_DWORD *)((char *)&SignedVolTable + v0) = result - 0x8000;
result = (unsigned int)(result + 257);
v0 += 4LL;
}
while ( (_DWORD)result != 65792 );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rcx
__int64 result; // rax

v0 = 0LL;
LODWORD(result) = 0;
do
{
*(_DWORD *)((char *)&UnsignedVolTable + v0) = (int)result / 2;
*(_DWORD *)((char *)&SignedVolTable + v0) = result - 0x8000;
result = (unsigned int)(result + 257);
v0 += 4LL;
}
while ( (_DWORD)result != 65792 );
return result;
}

original_code:
static void DAC_build_voltable(void)
{
 int i;
 for (i = 0;i < 256;i++)
 {
  UnsignedVolTable[i] = i * 0x101 / 2;
  SignedVolTable[i] = i * 0x101 - 0x8000;
 }
}

canonical_original_code:
static void DAC_build_voltable()
{
 int i;
 for (i = 0;i < 256;i++)
 {
  UnsignedVolTable[i] = i * 0x101 / 2;
  SignedVolTable[i] = i * 0x101 - 0x8000;
 }
}


decompiled_code:
unsigned int *__fastcall DAC_data_16_w(int a1, int a2)
{
int v2; // esi
unsigned int *result; // rax

v2 = a2 >> 1;
result = output;
if ( output[a1] != v2 )
{
stream_update(channel[a1], 0LL);
result = output;
output[a1] = v2;
}
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func4(int a1, int a2)
{
int v2; // esi
unsigned int *result; // rax

v2 = a2 >> 1;
result = output;
if ( output[a1] != v2 )
{
stream_update(channel[a1], 0LL);
result = output;
output[a1] = v2;
}
return result;
}

original_code:
void DAC_data_16_w(int num,int data)
{
 int out = data >> 1;
 if (output[num] != out)
 {
  stream_update(channel[num],0);
  output[num] = out;
 }
}

canonical_original_code:
void DAC_data_16_w(int num, int data)
{
 int out = data >> 1;
 if (output[num] != out)
 {
  stream_update(channel[num],0);
  output[num] = out;
 }
}

variable_types: num int

variable_types: data int

variable_types: out int


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

result = output;
if ( output[a1] != a2 - 0x8000 )
{
stream_update(channel[a1], 0LL);
result = output;
output[a1] = a2 - 0x8000;
}
return result;
}

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

result = output;
if ( output[a1] != a2 - 0x8000 )
{
stream_update(channel[a1], 0LL);
result = output;
output[a1] = a2 - 0x8000;
}
return result;
}

original_code:
void DAC_signed_data_16_w(int num,int data)
{
 int out = data - 0x8000;
 if (output[num] != out)
 {
  stream_update(channel[num],0);
  output[num] = out;
 }
}

canonical_original_code:
void DAC_signed_data_16_w(int num, int data)
{
 int out = data - 0x8000;
 if (output[num] != out)
 {
  stream_update(channel[num],0);
  output[num] = out;
 }
}


decompiled_code:
__int64 __fastcall DAC_sh_start(__int64 a1)
{
int *v1; // rbp
__int64 v2; // rbx
unsigned int v3; // eax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(int **)(a1 + 8);
DAC_build_voltable();
if ( *v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( 1 )
{
sprintf(v5, "DAC #%d", (unsigned int)v2);
v3 = stream_init(v5, (unsigned int)v1[v2 + 1], *(unsigned int *)(Machine + 836LL), (unsigned int)v2, DAC_update);
channel[v2] = v3;
if ( v3 == -1 )
break;
output[v2++] = 0;
if ( *v1 <= (int)v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int *v1; // rbp
__int64 v2; // rbx
unsigned int v3; // eax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = *(int **)(a1 + 8);
func1();
if ( *v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( 1 )
{
sprintf(v5, "DAC #%d", (unsigned int)v2);
v3 = stream_init(v5, (unsigned int)v1[v2 + 1], *(unsigned int *)(Machine + 836LL), (unsigned int)v2, DAC_update);
channel[v2] = v3;
if ( v3 == -1 )
break;
output[v2++] = 0;
if ( *v1 <= (int)v2 )
return 0LL;
}
return 1LL;
}

original_code:
int DAC_sh_start(const struct MachineSound *msound)
{
 int i;
 const struct DACinterface *intf = (const struct DACinterface *)msound->sound_interface;
 DAC_build_voltable();
 for (i = 0;i < intf->num;i++)
 {
  char name[40];
  sprintf(name,"DAC #%d",i);
  channel[i] = stream_init(name,intf->mixing_level[i],Machine->sample_rate,
    i,DAC_update);
  if (channel[i] == -1)
   return 1;
  output[i] = 0;
 }
 return 0;
}

canonical_original_code:
int DAC_sh_start(struct MachineSound *msound)
{
 int i;
 struct DACinterface *intf = (const struct DACinterface *)msound->sound_interface;
 DAC_build_voltable();
 for (i = 0;i < intf->num;i++)
 {
  char name[40];
  sprintf(name,"DAC #%d",i);
  channel[i] = stream_init(name,intf->mixing_level[i],Machine->sample_rate,
    i,DAC_update);
  if (channel[i] == -1)
   return 1;
  output[i] = 0;
 }
 return 0;
}

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

variable_types: i int

variable_types: struct DACinterface { int num; int mixing_level[4]; } *

variable_types:
name
char [40]


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

result = port1State_0 ^ (unsigned int)a2;
v3 = a2 & (port1State_0 ^ a2);
v4 = (port1State_0 ^ a2) & ~(_BYTE)a2;
port1State_0 = a2;
if ( (v3 & 1) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v3 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v3 & 8) != 0 )
result = sample_start(3LL, 3LL, 1LL);
if ( (v4 & 8) != 0 )
result = sample_stop(3LL);
return result;
}

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

result = port1State_0 ^ (unsigned int)a2;
v3 = a2 & (port1State_0 ^ a2);
v4 = (port1State_0 ^ a2) & ~(_BYTE)a2;
port1State_0 = a2;
if ( (v3 & 1) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v3 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v3 & 8) != 0 )
result = sample_start(3LL, 3LL, 1LL);
if ( (v4 & 8) != 0 )
result = sample_stop(3LL);
return result;
}

original_code:
void depthch_sh_port1_w(offs_t offset,data_t data)
{
 static int port1State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneHigh & 0x01 )
 {
  sample_start( SND_LONGEXPL, SND_LONGEXPL, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_start( SND_SHRTEXPL, SND_SHRTEXPL, 0 );
 }
 if ( bitsGoneHigh & 0x04 )
 {
  sample_start( SND_SPRAY, SND_SPRAY, 0 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_start( SND_SONAR, SND_SONAR, 1 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_stop( SND_SONAR );
 }
}

canonical_original_code:
void depthch_sh_port1_w(unsigned int offset, unsigned int data)
{
 static int port1State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneHigh & 0x01 )
 {
  sample_start( SND_LONGEXPL, SND_LONGEXPL, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_start( SND_SHRTEXPL, SND_SHRTEXPL, 0 );
 }
 if ( bitsGoneHigh & 0x04 )
 {
  sample_start( SND_SPRAY, SND_SPRAY, 0 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_start( SND_SONAR, SND_SONAR, 1 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_stop( SND_SONAR );
 }
}

variable_types:
offset
unsigned int

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int


decompiled_code:
__int64 superman_vh_start()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int superman_vh_start (void)
{
 return 0;
}

canonical_original_code:
int superman_vh_start()
{
 return 0;
}


decompiled_code:
void superman_vh_stop()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void superman_vh_stop (void)
{
}

canonical_original_code:
void superman_vh_stop()
{
}


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

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

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

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


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

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

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

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


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

if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
result = 255LL;
if ( a1 == 6 )
result = readinputport(3LL);
}
else if ( a1 )
{
if ( a1 == 2 )
result = readinputport(1LL);
else
result = 255LL;
}
else
{
result = readinputport(0LL);
}
return result;
}

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

if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
result = 255LL;
if ( a1 == 6 )
result = readinputport(3LL);
}
else if ( a1 )
{
if ( a1 == 2 )
result = readinputport(1LL);
else
result = 255LL;
}
else
{
result = readinputport(0LL);
}
return result;
}

original_code:
data_t superman_input_r(offs_t offset)
{
 switch (offset)
 {
  case 0x00:
   return readinputport (0);
  case 0x02:
   return readinputport (1);
  case 0x04:
   return readinputport (2);
  case 0x06:
   return readinputport (3);
  default:
   return 0xff;
 }
}

canonical_original_code:
unsigned int superman_input_r(unsigned int offset)
{
 switch (offset)
 {
  case 0x00:
   return readinputport (0);
  case 0x02:
   return readinputport (1);
  case 0x04:
   return readinputport (2);
  case 0x06:
   return readinputport (3);
  default:
   return 0xff;
 }
}


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

cpu_bankbase[2] = memory_region(130LL) + ((((a2 - 1) & 3) + 4) << 14);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[2] = memory_region(130LL) + ((((a2 - 1) & 3) + 4) << 14);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

canonical_original_code:
static void taito68k_sound_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int banknum = ( data - 1 ) & 3;
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[ 0x10000 + ( banknum * 0x4000 ) ]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
data
unsigned int

variable_types:
RAM
unsigned char *

variable_types: banknum int


original_code:
void superman_update_palette (void)
{
 unsigned short palette_map[32];
 int i;
 memset (palette_map, 0, sizeof (palette_map));
 for (i = 0; i < 0x400; i += 0x40)
 {
  int i2;
  for (i2 = i; i2 < (i + 0x40); i2 += 2)
  {
   int tile;
   int color;
   color = 0;
   tile = (*(UINT16 *)(&supes_videoram[0x800 + i2])) & 0x3fff;
   if (tile)
    color = (*(UINT16 *)(&supes_videoram[0xc00 + i2])) >> 11;
   palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
  }
 }
 for (i = 0x3fe; i >= 0; i -= 2)
 {
  int tile;
  int color;
  color = 0;
  tile = (*(UINT16 *)(&supes_videoram[i])) & 0x3fff;
  if (tile)
   color = (*(UINT16 *)(&supes_videoram[0x400 + i])) >> 11;
  palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
 }
 for (i = 0;i < 32;i++)
 {
  int usage = palette_map[i];
  int j;
  if (usage)
  {
   palette_used_colors[i * 16 + 0] = (4|(1|2));
   for (j = 1; j < 16; j++)
    if (palette_map[i] & (1 << j))
     palette_used_colors[i * 16 + j] = (1|2);
    else
     palette_used_colors[i * 16 + j] = 0;
  }
  else
   memset(&palette_used_colors[i * 16],0,16);
 }
 palette_recalc ();
}

canonical_original_code:
void superman_update_palette()
{
 unsigned short palette_map[32];
 int i;
 memset (palette_map, 0, sizeof (palette_map));
 for (i = 0; i < 0x400; i += 0x40)
 {
  int i2;
  for (i2 = i; i2 < (i + 0x40); i2 += 2)
  {
   int tile;
   int color;
   color = 0;
   tile = (*(unsigned short *)(&supes_videoram[0x800 + i2])) & 0x3fff;
   if (tile)
    color = (*(unsigned short *)(&supes_videoram[0xc00 + i2])) >> 11;
   palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
  }
 }
 for (i = 0x3fe; i >= 0; i -= 2)
 {
  int tile;
  int color;
  color = 0;
  tile = (*(unsigned short *)(&supes_videoram[i])) & 0x3fff;
  if (tile)
   color = (*(unsigned short *)(&supes_videoram[0x400 + i])) >> 11;
  palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
 }
 for (i = 0;i < 32;i++)
 {
  int usage = palette_map[i];
  int j;
  if (usage)
  {
   palette_used_colors[i * 16 + 0] = (4|(1|2));
   for (j = 1; j < 16; j++)
    if (palette_map[i] & (1 << j))
     palette_used_colors[i * 16 + j] = (1|2);
    else
     palette_used_colors[i * 16 + j] = 0;
  }
  else
   memset(&palette_used_colors[i * 16],0,16);
 }
 palette_recalc ();
}

variable_types: tile int

variable_types: color int

variable_types: usage int

variable_types: j int


decompiled_code:
__int64 __fastcall superman_vh_screenrefresh(__int64 a1)
{
int i; // er12
int v2; // ebx
__int64 v3; // rbp
unsigned __int16 v4; // dx
int v5; // eax
__int16 v6; // r15
__int64 j; // rbx
__int64 result; // rax
unsigned __int16 v9; // dx
__int16 v10; // [rsp+4h] [rbp-44h]
__int64 v11; // [rsp+8h] [rbp-40h]

superman_update_palette();
osd_clearbitmap(a1);
v11 = 2048LL;
for ( i = 63; i != 1087; i += 64 )
{
v2 = i - 63;
v5 = (i - 63) >> 1;
v6 = *(_WORD *)(supes_attribram + v5 + 1032);
v10 = *(_WORD *)(supes_attribram + v5 + 1024);
v3 = v11;
do
{
v4 = *(_WORD *)(supes_videoram + v3) & 0x3FFF;
if ( v4 )
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v4,
*(_WORD *)(supes_videoram + v2 + 3072) >> 11,
*(_WORD *)(supes_videoram + v3) & 0x4000,
*(_WORD *)(supes_videoram + v3) & 0x8000,
(v6 + ((8 * (_BYTE)v2) & 0x18)) & 0x1FF,
(unsigned __int8)(((4 * v2) & 0xF0) - v10 + 9),
Machine + 776LL,
2LL,
0LL);
v2 += 2;
v3 += 2LL;
}
while ( v2 <= i );
v11 += 64LL;
}
for ( j = 1022LL; j != -2; j -= 2LL )
{
result = supes_videoram;
v9 = *(_WORD *)(supes_videoram + j) & 0x3FFF;
if ( v9 )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v9,
*(_WORD *)(supes_videoram + j + 1024) >> 11,
*(_WORD *)(supes_videoram + j) & 0x8000,
*(_WORD *)(supes_videoram + j) & 0x4000,
*(_WORD *)(supes_videoram + j + 1024) & 0x1FF,
(unsigned __int8)(-6 - *(_BYTE *)(supes_attribram + j)),
Machine + 776LL,
2LL,
0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int i; // er12
int v2; // ebx
__int64 v3; // rbp
unsigned __int16 v4; // dx
int v5; // eax
__int16 v6; // r15
__int64 j; // rbx
__int64 result; // rax
unsigned __int16 v9; // dx
__int16 v10; // [rsp+4h] [rbp-44h]
__int64 v11; // [rsp+8h] [rbp-40h]

func9();
osd_clearbitmap(a1);
v11 = 2048LL;
for ( i = 63; i != 1087; i += 64 )
{
v2 = i - 63;
v5 = (i - 63) >> 1;
v6 = *(_WORD *)(supes_attribram + v5 + 1032);
v10 = *(_WORD *)(supes_attribram + v5 + 1024);
v3 = v11;
do
{
v4 = *(_WORD *)(supes_videoram + v3) & 0x3FFF;
if ( v4 )
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v4,
*(_WORD *)(supes_videoram + v2 + 3072) >> 11,
*(_WORD *)(supes_videoram + v3) & 0x4000,
*(_WORD *)(supes_videoram + v3) & 0x8000,
(v6 + ((8 * (_BYTE)v2) & 0x18)) & 0x1FF,
(unsigned __int8)(((4 * v2) & 0xF0) - v10 + 9),
Machine + 776LL,
2LL,
0LL);
v2 += 2;
v3 += 2LL;
}
while ( v2 <= i );
v11 += 64LL;
}
for ( j = 1022LL; j != -2; j -= 2LL )
{
result = supes_videoram;
v9 = *(_WORD *)(supes_videoram + j) & 0x3FFF;
if ( v9 )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v9,
*(_WORD *)(supes_videoram + j + 1024) >> 11,
*(_WORD *)(supes_videoram + j) & 0x8000,
*(_WORD *)(supes_videoram + j) & 0x4000,
*(_WORD *)(supes_videoram + j + 1024) & 0x1FF,
(unsigned __int8)(-6 - *(_BYTE *)(supes_attribram + j)),
Machine + 776LL,
2LL,
0LL);
}
return result;
}

original_code:
void superman_vh_screenrefresh (struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 superman_update_palette ();
 osd_clearbitmap(bitmap);
 for (i = 0; i < 0x400; i += 0x40)
 {
  int x1, y1;
  int i2;
  x1 = (*(UINT16 *)(&supes_attribram[0x408 + (i >> 1)]));
  y1 = (*(UINT16 *)(&supes_attribram[0x400 + (i >> 1)]));
  for (i2 = i; i2 < (i + 0x40); i2 += 2)
  {
   int tile;
   tile = (*(UINT16 *)(&supes_videoram[0x800 + i2])) & 0x3fff;
   if (tile)
   {
    int x, y;
    x = ( x1 + ((i2 & 0x03) << 3)) & 0x1ff;
    y = ((265 - (y1 - ((i2 & 0x3c) << 2))) & 0xff);
    {
     int flipx = (*(UINT16 *)(&supes_videoram[0x800 + i2])) & 0x4000;
     int flipy = (*(UINT16 *)(&supes_videoram[0x800 + i2])) & 0x8000;
     int color = (*(UINT16 *)(&supes_videoram[0xc00 + i2])) >> 11;
     drawgfx(bitmap,Machine->gfx[0],
      tile,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,
      TRANSPARENCY_PEN,0);
    }
   }
  }
 }
 for (i = 0x3fe; i >= 0; i -= 2)
 {
  int sprite;
  sprite = (*(UINT16 *)(&supes_videoram[i])) & 0x3fff;
  if (sprite)
  {
   int x, y;
   x = ( (*(UINT16 *)(&supes_videoram [0x400 + i]))) & 0x1ff;
   y = (250 - (*(UINT16 *)(&supes_attribram[i ]))) & 0xff;
   {
    int flipy = (*(UINT16 *)(&supes_videoram[i])) & 0x4000;
    int flipx = (*(UINT16 *)(&supes_videoram[i])) & 0x8000;
    int color = (*(UINT16 *)(&supes_videoram[0x400 + i])) >> 11;
    drawgfx(bitmap,Machine->gfx[0],
     sprite,
     color,
     flipx,flipy,
     x,y,
     &Machine->visible_area,
     TRANSPARENCY_PEN,0);
   }
  }
 }
}

canonical_original_code:
void superman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 superman_update_palette ();
 osd_clearbitmap(bitmap);
 for (i = 0; i < 0x400; i += 0x40)
 {
  int x1; int y1;
  int i2;
  x1 = (*(unsigned short *)(&supes_attribram[0x408 + (i >> 1)]));
  y1 = (*(unsigned short *)(&supes_attribram[0x400 + (i >> 1)]));
  for (i2 = i; i2 < (i + 0x40); i2 += 2)
  {
   int tile;
   tile = (*(unsigned short *)(&supes_videoram[0x800 + i2])) & 0x3fff;
   if (tile)
   {
    int x; int y;
    x = ( x1 + ((i2 & 0x03) << 3)) & 0x1ff;
    y = ((265 - (y1 - ((i2 & 0x3c) << 2))) & 0xff);
    {
     int flipx = (*(UINT16 *)(&supes_videoram[0x800 + i2])) & 0x4000;
     int flipy = (*(UINT16 *)(&supes_videoram[0x800 + i2])) & 0x8000;
     int color = (*(UINT16 *)(&supes_videoram[0xc00 + i2])) >> 11;
     drawgfx(bitmap,Machine->gfx[0],
      tile,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,
      TRANSPARENCY_PEN,0);
    }
   }
  }
 }
 for (i = 0x3fe; i >= 0; i -= 2)
 {
  int sprite;
  sprite = (*(unsigned short *)(&supes_videoram[i])) & 0x3fff;
  if (sprite)
  {
   int x; int y;
   x = ( (*(unsigned short *)(&supes_videoram [0x400 + i]))) & 0x1ff;
   y = (250 - (*(unsigned short *)(&supes_attribram[i ]))) & 0xff;
   {
    int flipy = (*(UINT16 *)(&supes_videoram[i])) & 0x4000;
    int flipx = (*(UINT16 *)(&supes_videoram[i])) & 0x8000;
    int color = (*(UINT16 *)(&supes_videoram[0x400 + i])) >> 11;
    drawgfx(bitmap,Machine->gfx[0],
     sprite,
     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: x int

variable_types: y int

variable_types: flipx int

variable_types: flipy int

variable_types: sprite int


irqhandler

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

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

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

variable_types: irq int


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

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

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

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

variable_types:
offset
unsigned int


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

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

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

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


original_code:
static UINT32 supbtime_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 5);
}

canonical_original_code:
static unsigned int supbtime_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 5);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


decompiled_code:
__int64 __fastcall supbtime_pf2_data_w(unsigned int a1, int a2)
{
*(_WORD *)(supbtime_pf2_data + a1) = a2 | *(_WORD *)(supbtime_pf2_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(pf2_tilemap, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, int a2)
{
*(_WORD *)(supbtime_pf2_data + a1) = a2 | *(_WORD *)(supbtime_pf2_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(pf2_tilemap, a1 >> 1);
}

original_code:
void supbtime_pf2_data_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&supbtime_pf2_data[offset])) = (((*(UINT16 *)(&supbtime_pf2_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty(pf2_tilemap,offset/2);
}

canonical_original_code:
void supbtime_pf2_data_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&supbtime_pf2_data[offset])) = (((*(unsigned short *)(&supbtime_pf2_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty(pf2_tilemap,offset/2);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall supbtime_pf1_data_w(unsigned int a1, int a2)
{
*(_WORD *)(supbtime_pf1_data + a1) = a2 | *(_WORD *)(supbtime_pf1_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(pf1_tilemap, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, int a2)
{
*(_WORD *)(supbtime_pf1_data + a1) = a2 | *(_WORD *)(supbtime_pf1_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(pf1_tilemap, a1 >> 1);
}

original_code:
void supbtime_pf1_data_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&supbtime_pf1_data[offset])) = (((*(UINT16 *)(&supbtime_pf1_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty(pf1_tilemap,offset/2);
}

canonical_original_code:
void supbtime_pf1_data_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&supbtime_pf1_data[offset])) = (((*(unsigned short *)(&supbtime_pf1_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty(pf1_tilemap,offset/2);
}


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

pf1_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 64LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_bg_tile_info, supbtime_scan, 1LL, 16LL, 16LL, 64LL, v2);
pf2_tilemap = v0;
if ( !v0 || !pf1_tilemap )
return 1LL;
*(_DWORD *)(pf1_tilemap + 132) = 0;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

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

pf1_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 64LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_bg_tile_info, supbtime_scan, 1LL, 16LL, 16LL, 64LL, v2);
pf2_tilemap = v0;
if ( !v0 || !pf1_tilemap )
return 1LL;
*(_DWORD *)(pf1_tilemap + 132) = 0;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

original_code:
int supbtime_vh_start(void)
{
 pf1_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01, 8, 8,64,64);
 pf2_tilemap = tilemap_create(get_bg_tile_info,supbtime_scan, 0x01,16,16,64,32);
 if (!pf1_tilemap || !pf2_tilemap)
  return 1;
 pf1_tilemap->transparent_pen = 0;
 pf2_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int supbtime_vh_start()
{
 pf1_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01, 8, 8,64,64);
 pf2_tilemap = tilemap_create(get_bg_tile_info,supbtime_scan, 0x01,16,16,64,32);
 if (!pf1_tilemap || !pf2_tilemap)
  return 1;
 pf1_tilemap->transparent_pen = 0;
 pf2_tilemap->transparent_pen = 0;
 return 0;
}


decompiled_code:
__int64 supbtime_mark_sprite_colours()
{
__int64 v0; // r12
int v1; // er9
char *v2; // r10
char *v3; // rax
unsigned __int16 *v4; // rsi
__int64 v5; // rbx
int v6; // ecx
int v7; // edx
__int64 v8; // rax
__int64 result; // rax
int v10; // ecx
int v11[16]; // [rsp+0h] [rbp-58h] BYREF
char v12[24]; // [rsp+40h] [rbp-18h] BYREF

palette_init_used_colors();
v0 = *(_QWORD *)(*(_QWORD *)(Machine + 528LL) + 32LL);
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 64LL);
v2 = (char *)v11;
v3 = (char *)v11;
do
{
*(_DWORD *)v3 = 0;
v3 += 4;
}
while ( v3 != v12 );
v4 = (unsigned __int16 *)spriteram;
v5 = spriteram + 2048LL;
do
{
if ( (v4[1] & 0x3FFF) != 0 )
{
v6 = 1 << (((int)*v4 >> 9) & 3);
v7 = v11[((int)v4[2] >> 9) & 0xF];
v8 = v6 - 1;
do
v7 |= *(_DWORD *)(v0 + 4LL * (-v6 & v4[1] & 0x3FFFu) + 4 * v8--);
while ( (int)v8 >= 0 );
v11[((int)v4[2] >> 9) & 0xF] = v7;
}
v4 += 4;
}
while ( v4 != (unsigned __int16 *)v5 );
do
{
v10 = *(_DWORD *)v2;
LODWORD(result) = 1;
do
{
if ( _bittest(&v10, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 16 );
v2 += 4;
v1 += 16;
}
while ( v2 != v12 );
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // r12
int v1; // er9
char *v2; // r10
char *v3; // rax
unsigned __int16 *v4; // rsi
__int64 v5; // rbx
int v6; // ecx
int v7; // edx
__int64 v8; // rax
__int64 result; // rax
int v10; // ecx
int v11[16]; // [rsp+0h] [rbp-58h] BYREF
char v12[24]; // [rsp+40h] [rbp-18h] BYREF

palette_init_used_colors();
v0 = *(_QWORD *)(*(_QWORD *)(Machine + 528LL) + 32LL);
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 64LL);
v2 = (char *)v11;
v3 = (char *)v11;
do
{
*(_DWORD *)v3 = 0;
v3 += 4;
}
while ( v3 != v12 );
v4 = (unsigned __int16 *)spriteram;
v5 = spriteram + 2048LL;
do
{
if ( (v4[1] & 0x3FFF) != 0 )
{
v6 = 1 << (((int)*v4 >> 9) & 3);
v7 = v11[((int)v4[2] >> 9) & 0xF];
v8 = v6 - 1;
do
v7 |= *(_DWORD *)(v0 + 4LL * (-v6 & v4[1] & 0x3FFFu) + 4 * v8--);
while ( (int)v8 >= 0 );
v11[((int)v4[2] >> 9) & 0xF] = v7;
}
v4 += 4;
}
while ( v4 != (unsigned __int16 *)v5 );
do
{
v10 = *(_DWORD *)v2;
LODWORD(result) = 1;
do
{
if ( _bittest(&v10, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 16 );
v2 += 4;
v1 += 16;
}
while ( v2 != v12 );
return result;
}

original_code:
static void supbtime_mark_sprite_colours(void)
{
 int offs,color,i,pal_base;
 int colmask[16];
    unsigned int *pen_usage;
 palette_init_used_colors();
 pen_usage=Machine->gfx[2]->pen_usage;
 pal_base = Machine->drv->gfxdecodeinfo[2].color_codes_start;
 for (color = 0;color < 16;color++) colmask[color] = 0;
 for (offs = 0;offs < 0x800;offs += 8)
 {
  int x,y,sprite,multi;
  sprite = (*(UINT16 *)(&spriteram[offs+2])) & 0x3fff;
  if (!sprite) continue;
  y = (*(UINT16 *)(&spriteram[offs]));
  x = (*(UINT16 *)(&spriteram[offs+4]));
  color = (x >>9) &0xf;
  multi = (1 << ((y & 0x0600) >> 9)) - 1;
  sprite &= ~multi;
  while (multi >= 0)
  {
   colmask[color] |= pen_usage[sprite + multi];
   multi--;
  }
 }
 for (color = 0;color < 16;color++)
 {
  for (i = 1;i < 16;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

canonical_original_code:
static void supbtime_mark_sprite_colours()
{
 int offs; int color; int i; int pal_base;
 int colmask[16];
    unsigned int *pen_usage;
 palette_init_used_colors();
 pen_usage=Machine->gfx[2]->pen_usage;
 pal_base = Machine->drv->gfxdecodeinfo[2].color_codes_start;
 for (color = 0;color < 16;color++) colmask[color] = 0;
 for (offs = 0;offs < 0x800;offs += 8)
 {
  int x; int y; int sprite; int multi;
  sprite = (*(unsigned short *)(&spriteram[offs+2])) & 0x3fff;
  if (!sprite) continue;
  y = (*(unsigned short *)(&spriteram[offs]));
  x = (*(unsigned short *)(&spriteram[offs+4]));
  color = (x >>9) &0xf;
  multi = (1 << ((y & 0x0600) >> 9)) - 1;
  sprite &= ~multi;
  while (multi >= 0)
  {
   colmask[color] |= pen_usage[sprite + multi];
   multi--;
  }
 }
 for (color = 0;color < 16;color++)
 {
  for (i = 1;i < 16;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

variable_types: offs int

variable_types: i int

variable_types:
colmask
int [16]

variable_types: multi int


decompiled_code:
__int64 __fastcall supbtime_drawsprites(__int64 a1)
{
__int64 i; // r14
__int64 result; // rax
int v3; // esi
__int64 v4; // r13
int v5; // ebx
unsigned int v6; // er12
unsigned int v7; // edi
unsigned int v8; // edx
int v9; // er8
int v10; // eax
int v11; // ebp
int v12; // ebx
int v13; // eax
unsigned int v14; // er15
unsigned int v15; // ebx
__int64 v16; // r12
int v17; // [rsp+4h] [rbp-54h]
unsigned int v18; // [rsp+8h] [rbp-50h]
int v19; // [rsp+Ch] [rbp-4Ch]

for ( i = 2LL; i != 2050; i += 8LL )
{
result = spriteram;
v5 = *(_WORD *)(spriteram + i) & 0x3FFF;
if ( (*(_WORD *)(spriteram + i) & 0x3FFF) == 0 )
continue;
v6 = *(unsigned __int16 *)(spriteram + i - 2);
if ( (v6 & 0x1000) != 0 )
{
result = cpu_getcurrentframe();
if ( (result & 1) != 0 )
continue;
}
result = spriteram;
v7 = *(unsigned __int16 *)(spriteram + i + 2);
v8 = *(_WORD *)(spriteram + i + 2) & 0x1FF;
v3 = v6 & 0x1FF;
if ( v8 > 0x13F )
{
v8 -= 512;
if ( (v6 & 0x1FF) > 0xFF )
LABEL_4:
v3 -= 512;
v4 = 304 - v8;
if ( (int)v4 > 320 )
continue;
v9 = 240 - v3;
goto LABEL_15;
}
if ( (v6 & 0x1FF) > 0xFF )
goto LABEL_4;
v9 = 240 - v3;
v4 = 304 - v8;
LABEL_15:
v10 = 1 << ((v6 >> 9) & 3);
v11 = v10 - 1;
v12 = -v10 & v5;
v13 = -1;
v14 = v6 & 0x4000;
if ( (v6 & 0x4000) == 0 )
{
v12 += v11;
v13 = 1;
}
v18 = v6 & 0x2000;
v17 = -16;
if ( flipscreen )
{
v18 = (v6 & 0x2000) == 0;
v14 = v14 == 0;
v9 = v3;
v4 = v8;
v17 = 16;
}
v19 = v13;
v15 = v12 - v11 * v13;
v16 = (unsigned int)(v9 + v11 * v17);
do
{
result = drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v15,
(v7 >> 9) & 0x1F,
v18,
v14,
v4,
v16,
Machine + 776LL,
2LL,
0LL);
--v11;
v15 += v19;
v16 = (unsigned int)(v16 - v17);
}
while ( v11 != -1 );
}
return result;
}

original_code:
static void supbtime_drawsprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = 0;offs < 0x800;offs += 8)
 {
  int x,y,sprite,colour,multi,fx,fy,inc,flash,mult;
  sprite = (*(UINT16 *)(&spriteram[offs+2])) & 0x3fff;
  if (!sprite) continue;
  y = (*(UINT16 *)(&spriteram[offs]));
  flash=y&0x1000;
  if (flash && (cpu_getcurrentframe() & 1)) continue;
  x = (*(UINT16 *)(&spriteram[offs+4]));
  colour = (x >>9) & 0x1f;
  fx = y & 0x2000;
  fy = y & 0x4000;
  multi = (1 << ((y & 0x0600) >> 9)) - 1;
  x = x & 0x01ff;
  y = y & 0x01ff;
  if (x >= 320) x -= 512;
  if (y >= 256) y -= 512;
  y = 240 - y;
        x = 304 - x;
  if (x>320) continue;
  sprite &= ~multi;
  if (fy)
   inc = -1;
  else
  {
   sprite += multi;
   inc = 1;
  }
  if (flipscreen)
  {
   y=240-y;
   x=304-x;
   if (fx) fx=0; else fx=1;
   if (fy) fy=0; else fy=1;
   mult=16;
  }
  else mult=-16;
  while (multi >= 0)
  {
   drawgfx(bitmap,Machine->gfx[2],
     sprite - multi * inc,
     colour,
     fx,fy,
     x,y + mult * multi,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   multi--;
  }
 }
}

canonical_original_code:
static void supbtime_drawsprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = 0;offs < 0x800;offs += 8)
 {
  int x; int y; int sprite; int colour; int multi; int fx; int fy; int inc; int flash; int mult;
  sprite = (*(unsigned short *)(&spriteram[offs+2])) & 0x3fff;
  if (!sprite) continue;
  y = (*(unsigned short *)(&spriteram[offs]));
  flash=y&0x1000;
  if (flash && (cpu_getcurrentframe() & 1)) continue;
  x = (*(unsigned short *)(&spriteram[offs+4]));
  colour = (x >>9) & 0x1f;
  fx = y & 0x2000;
  fy = y & 0x4000;
  multi = (1 << ((y & 0x0600) >> 9)) - 1;
  x = x & 0x01ff;
  y = y & 0x01ff;
  if (x >= 320) x -= 512;
  if (y >= 256) y -= 512;
  y = 240 - y;
        x = 304 - x;
  if (x>320) continue;
  sprite &= ~multi;
  if (fy)
   inc = -1;
  else
  {
   sprite += multi;
   inc = 1;
  }
  if (flipscreen)
  {
   y=240-y;
   x=304-x;
   if (fx) fx=0; else fx=1;
   if (fy) fy=0; else fy=1;
   mult=16;
  }
  else mult=-16;
  while (multi >= 0)
  {
   drawgfx(bitmap,Machine->gfx[2],
     sprite - multi * inc,
     colour,
     fx,fy,
     x,y + mult * multi,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   multi--;
  }
 }
}

variable_types: colour int

variable_types: fx int

variable_types: fy int

variable_types: inc int

variable_types: flash int

variable_types: mult int


decompiled_code:
__int64 __fastcall supbtime_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rsi

v1 = (unsigned __int8)supbtime_control_0 & 0x80;
flipscreen = supbtime_control_0 & 0x80;
if ( (supbtime_control_0 & 0x80) != 0 )
v1 = 3LL;
tilemap_set_flip(0LL, v1);
tilemap_set_scrollx(pf1_tilemap, 0LL, (unsigned __int16)word_F12);
tilemap_set_scrolly(pf1_tilemap, 0LL, (unsigned __int16)word_F14);
tilemap_set_scrollx(pf2_tilemap, 0LL, (unsigned __int16)word_F16);
tilemap_set_scrolly(pf2_tilemap, 0LL, (unsigned __int16)word_F18);
if ( word_F1C == 192 )
tilemap_set_scrollx(
pf1_tilemap,
0LL,
(unsigned __int16)word_F12 + (unsigned int)*(unsigned __int16 *)(supbtime_pf1_row + 8LL));
tilemap_update(pf2_tilemap);
tilemap_update(pf1_tilemap);
supbtime_mark_sprite_colours();
*(_BYTE *)(palette_used_colors + 768LL) = 3;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1536LL), Machine + 776LL);
tilemap_draw(a1, pf2_tilemap, 0LL);
supbtime_drawsprites(a1);
return tilemap_draw(a1, pf1_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rsi

v1 = (unsigned __int8)supbtime_control_0 & 0x80;
flipscreen = supbtime_control_0 & 0x80;
if ( (supbtime_control_0 & 0x80) != 0 )
v1 = 3LL;
tilemap_set_flip(0LL, v1);
tilemap_set_scrollx(pf1_tilemap, 0LL, (unsigned __int16)word_F12);
tilemap_set_scrolly(pf1_tilemap, 0LL, (unsigned __int16)word_F14);
tilemap_set_scrollx(pf2_tilemap, 0LL, (unsigned __int16)word_F16);
tilemap_set_scrolly(pf2_tilemap, 0LL, (unsigned __int16)word_F18);
if ( word_F1C == 192 )
tilemap_set_scrollx(
pf1_tilemap,
0LL,
(unsigned __int16)word_F12 + (unsigned int)*(unsigned __int16 *)(supbtime_pf1_row + 8LL));
tilemap_update(pf2_tilemap);
tilemap_update(pf1_tilemap);
func9();
*(_BYTE *)(palette_used_colors + 768LL) = 3;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1536LL), Machine + 776LL);
tilemap_draw(a1, pf2_tilemap, 0LL);
func10(a1);
return tilemap_draw(a1, pf1_tilemap, 0LL);
}

original_code:
void supbtime_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 flipscreen=((*(UINT16 *)(&supbtime_control_0[0]))&0x80);
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 tilemap_set_scrollx( pf1_tilemap,0, (*(UINT16 *)(&supbtime_control_0[2])) );
 tilemap_set_scrolly( pf1_tilemap,0, (*(UINT16 *)(&supbtime_control_0[4])) );
 tilemap_set_scrollx( pf2_tilemap,0, (*(UINT16 *)(&supbtime_control_0[6])) );
 tilemap_set_scrolly( pf2_tilemap,0, (*(UINT16 *)(&supbtime_control_0[8])) );
 if ((*(UINT16 *)(&supbtime_control_0[0xc]))==0xc0)
  tilemap_set_scrollx( pf1_tilemap,0, (*(UINT16 *)(&supbtime_control_0[2])) + (*(UINT16 *)(&supbtime_pf1_row[8])) );
 tilemap_update(pf2_tilemap);
 tilemap_update(pf1_tilemap);
 supbtime_mark_sprite_colours();
 palette_used_colors[768] = (1|2);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[768],&Machine->visible_area);
 tilemap_draw(bitmap,pf2_tilemap,0);
 supbtime_drawsprites(bitmap);
 tilemap_draw(bitmap,pf1_tilemap,0);
}

canonical_original_code:
void supbtime_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 flipscreen=((*(unsigned short *)(&supbtime_control_0[0]))&0x80);
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 tilemap_set_scrollx( pf1_tilemap,0, (*(unsigned short *)(&supbtime_control_0[2])) );
 tilemap_set_scrolly( pf1_tilemap,0, (*(unsigned short *)(&supbtime_control_0[4])) );
 tilemap_set_scrollx( pf2_tilemap,0, (*(unsigned short *)(&supbtime_control_0[6])) );
 tilemap_set_scrolly( pf2_tilemap,0, (*(unsigned short *)(&supbtime_control_0[8])) );
 if ((*(unsigned short *)(&supbtime_control_0[0xc]))==0xc0)
  tilemap_set_scrollx( pf1_tilemap,0, (*(unsigned short *)(&supbtime_control_0[2])) + (*(unsigned short *)(&supbtime_pf1_row[8])) );
 tilemap_update(pf2_tilemap);
 tilemap_update(pf1_tilemap);
 supbtime_mark_sprite_colours();
 palette_used_colors[768] = (1|2);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[768],&Machine->visible_area);
 tilemap_draw(bitmap,pf2_tilemap,0);
 supbtime_drawsprites(bitmap);
 tilemap_draw(bitmap,pf1_tilemap,0);
}

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


decompiled_code:
__int64 init_supbtime()
{
return install_mem_read_handler(0LL, 0x100000LL, 1048577LL, supbtime_cycle_r);
}

canonical_decompiled_code:
__int64 func12()
{
return install_mem_read_handler(0LL, 0x100000LL, 1048577LL, supbtime_cycle_r);
}

original_code:
static void init_supbtime(void)
{
 install_mem_read_handler(0, 0x100000, 0x100001, supbtime_cycle_r);
}

canonical_original_code:
static void init_supbtime()
{
 install_mem_read_handler(0, 0x100000, 0x100001, supbtime_cycle_r);
}


decompiled_code:
__int64 supbtime_cycle_r()
{
if ( (unsigned int)cpu_get_pc() != 2018 || *(_WORD *)supbtime_ram )
return *(unsigned __int16 *)supbtime_ram;
cpu_spinuntil_int();
return 1LL;
}

canonical_decompiled_code:
__int64 func13()
{
if ( (unsigned int)cpu_get_pc() != 2018 || *(_WORD *)supbtime_ram )
return *(unsigned __int16 *)supbtime_ram;
cpu_spinuntil_int();
return 1LL;
}

original_code:
static data_t supbtime_cycle_r(offs_t offset)
{
 if (cpu_get_pc()==0x7e2 && (*(UINT16 *)(&supbtime_ram[0]))==0) {cpu_spinuntil_int(); return 1;}
 return (*(UINT16 *)(&supbtime_ram[0]));
}

canonical_original_code:
static unsigned int supbtime_cycle_r(unsigned int offset)
{
 if (cpu_get_pc()==0x7e2 && (*(unsigned short *)(&supbtime_ram[0]))==0) {cpu_spinuntil_int(); return 1;}
 return (*(unsigned short *)(&supbtime_ram[0]));
}


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

if ( !a1 )
return YM2151_register_port_0_w(0LL);
if ( a1 == 1 )
result = YM2151_data_port_0_w(0LL);
return result;
}

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

if ( !a1 )
return YM2151_register_port_0_w(0LL);
if ( a1 == 1 )
result = YM2151_data_port_0_w(0LL);
return result;
}

original_code:
static void YM2151_w(offs_t offset,data_t data)
{
 switch (offset) {
 case 0:
  YM2151_register_port_0_w(0,data);
  break;
 case 1:
  YM2151_data_port_0_w(0,data);
  break;
 }
}

canonical_original_code:
static void YM2151_w(unsigned int offset, unsigned int data)
{
 switch (offset) {
 case 0:
  YM2151_register_port_0_w(0,data);
  break;
 case 1:
  YM2151_data_port_0_w(0,data);
  break;
 }
}


decompiled_code:
__int64 __fastcall supbtime_controls_r(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebx

switch ( a1 )
{
case 0:
v2 = readinputport(0LL);
result = v2 + ((unsigned int)readinputport(1LL) << 8);
break;
case 1:
case 3:
case 4:
case 5:
case 6:
case 7:
case 9:
case 11:
result = 0xFFFFLL;
break;
case 2:
v3 = readinputport(3LL);
result = v3 + ((unsigned int)readinputport(4LL) << 8);
break;
case 8:
result = readinputport(2LL);
break;
case 10:
case 12:
result = 0LL;
break;
default:
result = 0xFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebx

switch ( a1 )
{
case 0:
v2 = readinputport(0LL);
result = v2 + ((unsigned int)readinputport(1LL) << 8);
break;
case 1:
case 3:
case 4:
case 5:
case 6:
case 7:
case 9:
case 11:
result = 0xFFFFLL;
break;
case 2:
v3 = readinputport(3LL);
result = v3 + ((unsigned int)readinputport(4LL) << 8);
break;
case 8:
result = readinputport(2LL);
break;
case 10:
case 12:
result = 0LL;
break;
default:
result = 0xFFFFLL;
break;
}
return result;
}

original_code:
static data_t supbtime_controls_r(offs_t offset)
{
  switch (offset)
 {
  case 0:
   return (readinputport(0) + (readinputport(1) << 8));
  case 2:
   return (readinputport(3) + (readinputport(4) << 8));
  case 8:
   return readinputport(2);
  case 10:
  case 12:
   return 0;
 }
 return 0xffff;
}

canonical_original_code:
static unsigned int supbtime_controls_r(unsigned int offset)
{
  switch (offset)
 {
  case 0:
   return (readinputport(0) + (readinputport(1) << 8));
  case 2:
   return (readinputport(3) + (readinputport(4) << 8));
  case 8:
   return readinputport(2);
  case 10:
  case 12:
   return 0;
 }
 return 0xffff;
}


decompiled_code:
__int64 __fastcall sound_w(__int64 a1, unsigned __int8 a2)
{
soundlatch_w(0LL, a2);
return cpu_cause_interrupt(1LL, 3LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned __int8 a2)
{
soundlatch_w(0LL, a2);
return cpu_cause_interrupt(1LL, 3LL);
}

original_code:
static void sound_w(offs_t offset,data_t data)
{
 soundlatch_w(0,data & 0xff);
 cpu_cause_interrupt(1,3);
}

canonical_original_code:
static void sound_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(0,data & 0xff);
 cpu_cause_interrupt(1,3);
}


RomInSet

decompiled_code:
__int64 __fastcall RomInSet(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v4; // rax

v2 = *(_QWORD *)(a1 + 72);
if ( !v2 )
return 0LL;
while ( 1 )
{
if ( !*(_QWORD *)v2 && !*(_QWORD *)(v2 + 8) )
return 0LL;
v4 = v2 + 24;
if ( *(_DWORD *)(v2 + 36) )
break;
LABEL_3:
v2 = v4;
}
LABEL_6:
if ( *(_DWORD *)(v4 + 16) != a2 )
{
while ( 1 )
{
v4 += 24LL;
if ( !*(_DWORD *)(v4 + 12) )
goto LABEL_3;
if ( (unsigned __int64)(*(_QWORD *)v4 - 1LL) <= 0xFFFFFFFFFFFFFFFDLL )
goto LABEL_6;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v4; // rax

v2 = *(_QWORD *)(a1 + 72);
if ( !v2 )
return 0LL;
while ( 1 )
{
if ( !*(_QWORD *)v2 && !*(_QWORD *)(v2 + 8) )
return 0LL;
v4 = v2 + 24;
if ( *(_DWORD *)(v2 + 36) )
break;
LABEL_3:
v2 = v4;
}
LABEL_6:
if ( *(_DWORD *)(v4 + 16) != a2 )
{
while ( 1 )
{
v4 += 24LL;
if ( !*(_DWORD *)(v4 + 12) )
goto LABEL_3;
if ( (unsigned __int64)(*(_QWORD *)v4 - 1LL) <= 0xFFFFFFFFFFFFFFFDLL )
goto LABEL_6;
}
}
return 1LL;
}

original_code:
int RomInSet (const struct GameDriver *gamedrv, unsigned int crc)
{
 const struct RomModule *romp = gamedrv->rom;
 if (!romp) return 0;
 while (romp->name || romp->offset || romp->length)
 {
  romp++;
  while (romp->length)
  {
   if (romp->crc == crc) return 1;
   do
   {
    romp++;
   }
   while (romp->length && (romp->name == 0 || romp->name == (char *)-1));
  }
 }
 return 0;
}

canonical_original_code:
int RomInSet(struct GameDriver *gamedrv, unsigned int crc)
{
 struct RomModule *romp = gamedrv->rom;
 if (!romp) return 0;
 while (romp->name || romp->offset || romp->length)
 {
  romp++;
  while (romp->length)
  {
   if (romp->crc == crc) return 1;
   do
   {
    romp++;
   }
   while (romp->length && (romp->name == 0 || romp->name == (char *)-1));
  }
 }
 return 0;
}

variable_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver { struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); } *memory_read; struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; } *memory_write; struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); } *port_read; struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); } *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; } cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle { int min_x; int min_y; } default_visible_area; struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; } *gfxlayout; int color_codes_start; int total_color_codes; } *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound { int sound_type; void *sound_interface; } sound[5]; void (*nvram_handler)(void *file, int read_or_write); } *drv; struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; } *input_ports; void (*driver_init)(); struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *rom; unsigned int flags; } *

variable_types:
crc
unsigned int

user_defined_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver *drv; struct InputPortTiny *input_ports; void (*driver_init)(); struct RomModule *rom; unsigned int flags; }

user_defined_types: struct MachineDriver { struct MachineCPU cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle default_visible_area; struct GfxDecodeInfo *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound sound[5]; void (*nvram_handler)(void *file, int read_or_write); }

user_defined_types: struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress *memory_read; struct MemoryWriteAddress *memory_write; struct IOReadPort *port_read; struct IOWritePort *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; }

user_defined_types: struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout *gfxlayout; int color_codes_start; int total_color_codes; }