decompiled_code:
__int64 DAC_build_voltable()
{
__int64 v0; // rdx
__int64 result; // rax
int v2; // ecx

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

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdx
__int64 result; // rax
int v2; // ecx

v0 = 0LL;
LODWORD(result) = 0;
do
{
*(_DWORD *)((char *)&UnsignedVolTable + v0) = (int)result >> 1;
v2 = result - 0x8000;
result = (unsigned int)(result + 257);
*(_DWORD *)((char *)&SignedVolTable + v0) = v2;
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:
__int64 __fastcall DAC_data_16_w(int a1, int a2)
{
int v2; // esi
__int64 result; // rax

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

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

v2 = a2 >> 1;
if ( output[a1] != v2 )
{
result = stream_update(channel[a1], 0LL);
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

return_type: void


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

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

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

if ( output[a1] != a2 - 0x8000 )
{
result = stream_update(channel[a1], 0LL);
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[104]; // [rsp+0h] [rbp-68h] 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 func4(__int64 a1)
{
int *v1; // rbp
__int64 v2; // rbx
unsigned int v3; // eax
char v5[104]; // [rsp+0h] [rbp-68h] 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]

return_type: int


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

v2 = port1State_0;
port1State_0 = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( ((unsigned __int8)a2 & (unsigned __int8)result & 1) != 0 )
{
result = sample_start(0LL, 0LL, 0LL);
if ( (v5 & 2) == 0 )
{
LABEL_3:
if ( (v5 & 4) == 0 )
goto LABEL_4;
goto LABEL_9;
}
}
else if ( (v5 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(1LL, 1LL, 0LL);
if ( (v5 & 4) == 0 )
{
LABEL_4:
if ( (v5 & 8) == 0 )
goto LABEL_5;
goto LABEL_10;
}
LABEL_9:
result = sample_start(2LL, 2LL, 0LL);
if ( (v5 & 8) == 0 )
{
LABEL_5:
if ( (v4 & 8) == 0 )
return result;
return sample_stop(3LL);
}
LABEL_10:
result = sample_start(3LL, 3LL, 1LL);
if ( (v4 & 8) != 0 )
return sample_stop(3LL);
return result;
}

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

v2 = port1State_0;
port1State_0 = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( ((unsigned __int8)a2 & (unsigned __int8)result & 1) != 0 )
{
result = sample_start(0LL, 0LL, 0LL);
if ( (v5 & 2) == 0 )
{
LABEL_3:
if ( (v5 & 4) == 0 )
goto LABEL_4;
goto LABEL_9;
}
}
else if ( (v5 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(1LL, 1LL, 0LL);
if ( (v5 & 4) == 0 )
{
LABEL_4:
if ( (v5 & 8) == 0 )
goto LABEL_5;
goto LABEL_10;
}
LABEL_9:
result = sample_start(2LL, 2LL, 0LL);
if ( (v5 & 8) == 0 )
{
LABEL_5:
if ( (v4 & 8) == 0 )
return result;
return sample_stop(3LL);
}
LABEL_10:
result = sample_start(3LL, 3LL, 1LL);
if ( (v4 & 8) != 0 )
return 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:
data
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]));
}

return_type: unsigned int


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)
{
if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
if ( a1 == 6 )
return readinputport(3LL);
return 255LL;
}
if ( a1 )
{
if ( a1 == 2 )
return readinputport(1LL);
return 255LL;
}
return readinputport(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
if ( a1 == 6 )
return readinputport(3LL);
return 255LL;
}
if ( a1 )
{
if ( a1 == 2 )
return readinputport(1LL);
return 255LL;
}
return readinputport(0LL);
}

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:
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


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 v1; // rax
__int64 v3; // [rsp+0h] [rbp-18h]

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

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

v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 64LL);
LODWORD(v3) = 32;
pf1_tilemap = v0;
v1 = tilemap_create(get_bg_tile_info, supbtime_scan, 1LL, 16LL, 16LL, 64LL, v3);
pf2_tilemap = v1;
if ( !v1 || !pf1_tilemap )
return 1LL;
*(_DWORD *)(pf1_tilemap + 132) = 0;
*(_DWORD *)(v1 + 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; // rdx
__int64 v1; // rax
__int64 v2; // rbx
int v3; // er9
unsigned __int16 *v4; // rdi
__int64 v5; // r10
unsigned __int16 v6; // si
__int64 v7; // r8
int v8; // edx
int v9; // ecx
__int64 v10; // rax
unsigned int v11; // esi
char *v12; // rdi
int v13; // ecx
__int64 result; // rax
__int128 v15[4]; // [rsp+0h] [rbp-48h] BYREF
char v16; // [rsp+40h] [rbp-8h] BYREF

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

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rdx
__int64 v1; // rax
__int64 v2; // rbx
int v3; // er9
unsigned __int16 *v4; // rdi
__int64 v5; // r10
unsigned __int16 v6; // si
__int64 v7; // r8
int v8; // edx
int v9; // ecx
__int64 v10; // rax
unsigned int v11; // esi
char *v12; // rdi
int v13; // ecx
__int64 result; // rax
__int128 v15[4]; // [rsp+0h] [rbp-48h] BYREF
char v16; // [rsp+40h] [rbp-8h] BYREF

palette_init_used_colors();
v15[0] = 0LL;
v15[1] = 0LL;
v15[2] = 0LL;
v0 = *(_QWORD *)(Machine + 528LL);
v1 = *(_QWORD *)(Machine + 824LL);
v15[3] = 0LL;
v2 = *(_QWORD *)(v0 + 32);
v3 = *(_DWORD *)(*(_QWORD *)(v1 + 688) + 64LL);
v4 = (unsigned __int16 *)spriteram;
v5 = spriteram + 2048LL;
do
{
while ( 1 )
{
v6 = v4[1] & 0x3FFF;
if ( v6 )
break;
v4 += 4;
if ( (unsigned __int16 *)v5 == v4 )
goto LABEL_7;
}
v7 = ((int)v4[2] >> 9) & 0xF;
v8 = *((_DWORD *)v15 + v7);
v9 = 1 << (((int)*v4 >> 9) & 3);
v10 = v9 - 1;
v11 = (unsigned __int16)-(__int16)v9 & v6 & 0x3FFF;
do
v8 |= *(_DWORD *)(v2 + 4LL * v11 + 4 * v10--);
while ( (_DWORD)v10 != -1 );
v4 += 4;
*((_DWORD *)v15 + v7) = v8;
}
while ( (unsigned __int16 *)v5 != v4 );
LABEL_7:
v12 = (char *)v15;
do
{
v13 = *(_DWORD *)v12;
LODWORD(result) = 1;
do
{
if ( _bittest(&v13, result) )
*(_BYTE *)(palette_used_colors + (int)result + v3) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 16 );
v12 += 4;
v3 += 16;
}
while ( v12 != &v16 );
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 v1; // r15
int v2; // er13
__int64 result; // rax
int v4; // esi
unsigned __int16 v5; // r14
unsigned int v6; // ebp
unsigned int v7; // er12
__int16 v8; // dx
int v9; // edi
int v10; // edx
int v11; // ebx
int v12; // edx
unsigned int v13; // er9
unsigned __int16 v14; // bp
unsigned int v15; // er8
int v16; // ebp
unsigned int v17; // er12
unsigned int v18; // er15
int v19; // edx
int v20; // ecx
unsigned int v21; // ebx
__int64 v22; // r13
unsigned int v23; // er14
int v24; // [rsp+4h] [rbp-54h]
int v25; // [rsp+8h] [rbp-50h]
unsigned int v26; // [rsp+Ch] [rbp-4Ch]
__int64 v28; // [rsp+18h] [rbp-40h]

v1 = 2LL;
do
{
while ( 1 )
{
result = spriteram;
v5 = *(_WORD *)(spriteram + v1) & 0x3FFF;
if ( !v5 )
goto LABEL_5;
v6 = *(unsigned __int16 *)(spriteram + v1 - 2);
if ( (v6 & 0x1000) != 0 )
{
result = cpu_getcurrentframe();
if ( (result & 1) != 0 )
goto LABEL_5;
result = spriteram;
}
v7 = *(unsigned __int16 *)(result + v1 + 2);
result = v6 & 0x1FF;
v8 = v6 & 0x100;
v2 = v7 & 0x1FF;
if ( (v7 & 0x1FF) > 0x13F )
{
v2 -= 512;
if ( !v8 )
goto LABEL_4;
}
else if ( !v8 )
{
v4 = 304 - v2;
v9 = 240 - result;
goto LABEL_11;
}
result = (unsigned int)(result - 512);
LABEL_4:
v4 = 304 - v2;
if ( 304 - v2 <= 320 )
break;
LABEL_5:
v1 += 8LL;
if ( v1 == 2050 )
return result;
}
v9 = 240 - result;
LABEL_11:
v24 = -1;
v10 = 1 << ((v6 >> 9) & 3);
v11 = v10 - 1;
v12 = v5 & -v10;
LOWORD(v13) = v6 & 0x4000;
if ( (v6 & 0x4000) == 0 )
{
v24 = 1;
v12 += v11;
}
v14 = v6 & 0x2000;
if ( flipscreen )
{
v25 = 16;
v15 = v14 == 0;
v13 = (_WORD)v13 == 0;
}
else
{
v15 = v14;
v13 = (unsigned __int16)v13;
LODWORD(result) = v9;
v2 = v4;
v25 = -16;
}
v26 = v2;
v16 = v11;
v28 = v1;
v17 = (v7 >> 9) & 0x1F;
v18 = v15;
v19 = v12 - v11 * v24;
v20 = v11 * v25;
v21 = v13;
v22 = (unsigned int)(v20 + result);
v23 = v19;
do
{
--v16;
result = drawgfx(a1, *(_QWORD *)(Machine + 528LL), v23, v17, v18, v21, v26, v22, Machine + 776LL, 2LL, 0LL);
v23 += v24;
v22 = (unsigned int)(v22 - v25);
}
while ( v16 != -1 );
v1 = v28 + 8;
}
while ( v28 != 2042 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // r15
int v2; // er13
__int64 result; // rax
int v4; // esi
unsigned __int16 v5; // r14
unsigned int v6; // ebp
unsigned int v7; // er12
__int16 v8; // dx
int v9; // edi
int v10; // edx
int v11; // ebx
int v12; // edx
unsigned int v13; // er9
unsigned __int16 v14; // bp
unsigned int v15; // er8
int v16; // ebp
unsigned int v17; // er12
unsigned int v18; // er15
int v19; // edx
int v20; // ecx
unsigned int v21; // ebx
__int64 v22; // r13
unsigned int v23; // er14
int v24; // [rsp+4h] [rbp-54h]
int v25; // [rsp+8h] [rbp-50h]
unsigned int v26; // [rsp+Ch] [rbp-4Ch]
__int64 v28; // [rsp+18h] [rbp-40h]

v1 = 2LL;
do
{
while ( 1 )
{
result = spriteram;
v5 = *(_WORD *)(spriteram + v1) & 0x3FFF;
if ( !v5 )
goto LABEL_5;
v6 = *(unsigned __int16 *)(spriteram + v1 - 2);
if ( (v6 & 0x1000) != 0 )
{
result = cpu_getcurrentframe();
if ( (result & 1) != 0 )
goto LABEL_5;
result = spriteram;
}
v7 = *(unsigned __int16 *)(result + v1 + 2);
result = v6 & 0x1FF;
v8 = v6 & 0x100;
v2 = v7 & 0x1FF;
if ( (v7 & 0x1FF) > 0x13F )
{
v2 -= 512;
if ( !v8 )
goto LABEL_4;
}
else if ( !v8 )
{
v4 = 304 - v2;
v9 = 240 - result;
goto LABEL_11;
}
result = (unsigned int)(result - 512);
LABEL_4:
v4 = 304 - v2;
if ( 304 - v2 <= 320 )
break;
LABEL_5:
v1 += 8LL;
if ( v1 == 2050 )
return result;
}
v9 = 240 - result;
LABEL_11:
v24 = -1;
v10 = 1 << ((v6 >> 9) & 3);
v11 = v10 - 1;
v12 = v5 & -v10;
LOWORD(v13) = v6 & 0x4000;
if ( (v6 & 0x4000) == 0 )
{
v24 = 1;
v12 += v11;
}
v14 = v6 & 0x2000;
if ( flipscreen )
{
v25 = 16;
v15 = v14 == 0;
v13 = (_WORD)v13 == 0;
}
else
{
v15 = v14;
v13 = (unsigned __int16)v13;
LODWORD(result) = v9;
v2 = v4;
v25 = -16;
}
v26 = v2;
v16 = v11;
v28 = v1;
v17 = (v7 >> 9) & 0x1F;
v18 = v15;
v19 = v12 - v11 * v24;
v20 = v11 * v25;
v21 = v13;
v22 = (unsigned int)(v20 + result);
v23 = v19;
do
{
--v16;
result = drawgfx(a1, *(_QWORD *)(Machine + 528LL), v23, v17, v18, v21, v26, v22, Machine + 776LL, 2LL, 0LL);
v23 += v24;
v22 = (unsigned int)(v22 - v25);
}
while ( v16 != -1 );
v1 = v28 + 8;
}
while ( v28 != 2042 );
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

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


decompiled_code:
__int64 __fastcall supbtime_vh_screenrefresh(__int64 a1)
{
flipscreen = supbtime_control_0 & 0x80;
tilemap_set_flip(0LL, ((unsigned __int16)supbtime_control_0 << 24 >> 31) & 3);
tilemap_set_scrollx(pf1_tilemap, 0LL, (unsigned __int16)word_FB2);
tilemap_set_scrolly(pf1_tilemap, 0LL, (unsigned __int16)word_FB4);
tilemap_set_scrollx(pf2_tilemap, 0LL, (unsigned __int16)word_FB6);
tilemap_set_scrolly(pf2_tilemap, 0LL, (unsigned __int16)word_FB8);
if ( word_FBC == 192 )
tilemap_set_scrollx(
pf1_tilemap,
0LL,
(unsigned __int16)word_FB2 + (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)
{
flipscreen = supbtime_control_0 & 0x80;
tilemap_set_flip(0LL, ((unsigned __int16)supbtime_control_0 << 24 >> 31) & 3);
tilemap_set_scrollx(pf1_tilemap, 0LL, (unsigned __int16)word_FB2);
tilemap_set_scrolly(pf1_tilemap, 0LL, (unsigned __int16)word_FB4);
tilemap_set_scrollx(pf2_tilemap, 0LL, (unsigned __int16)word_FB6);
tilemap_set_scrolly(pf2_tilemap, 0LL, (unsigned __int16)word_FB8);
if ( word_FBC == 192 )
tilemap_set_scrollx(
pf1_tilemap,
0LL,
(unsigned __int16)word_FB2 + (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()
{
bool v0; // zf
__int64 result; // rax

v0 = (unsigned int)cpu_get_pc() == 2018;
result = *(unsigned __int16 *)supbtime_ram;
if ( v0 && !(_WORD)result )
{
cpu_spinuntil_int();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
bool v0; // zf
__int64 result; // rax

v0 = (unsigned int)cpu_get_pc() == 2018;
result = *(unsigned __int16 *)supbtime_ram;
if ( v0 && !(_WORD)result )
{
cpu_spinuntil_int();
result = 1LL;
}
return result;
}

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:
v3 = readinputport(0LL);
result = v3 + ((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:
v2 = readinputport(3LL);
result = v2 + ((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:
v3 = readinputport(0LL);
result = v3 + ((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:
v2 = readinputport(3LL);
result = v2 + ((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 v3; // rax
int v4; // ecx

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

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

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

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


AuditRomSet

original_code:
int AuditRomSet (int game, tAuditRecord **audit)
{
 const struct RomModule *romp;
 const char *name;
 const struct GameDriver *gamedrv;
 int count = 0;
 tAuditRecord *aud;
 int err;
 if (!gAudits)
  gAudits = (tAuditRecord *)malloc(100 * sizeof (tAuditRecord));
 if (gAudits)
  *audit = aud = gAudits;
 else
  return 0;
 gamedrv = drivers[game];
 romp = gamedrv->rom;
 if (!romp) return -1;
 if (!osd_faccess (gamedrv->name, OSD_FILETYPE_ROM))
 {
  if (gamedrv->clone_of == 0 || (gamedrv->clone_of->flags & 0x4000) ||
    !osd_faccess(gamedrv->clone_of->name,OSD_FILETYPE_ROM))
   return 0;
 }
 while (romp->name || romp->offset || romp->length)
 {
  if (romp->name || romp->length) return 0;
  romp++;
  while (romp->length)
  {
   const struct GameDriver *drv;
   if (romp->name == 0)
    return 0;
   else if (romp->name == (char *)-1)
    return 0;
   name = romp->name;
   strcpy (aud->rom, name);
   aud->explength = 0;
   aud->length = 0;
   aud->expchecksum = romp->crc;
   aud->checksum = romp->crc;
   count++;
   drv = gamedrv;
   do
   {
    err = osd_fchecksum (drv->name, name, &aud->length, &aud->checksum);
    drv = drv->clone_of;
   } while (err && drv);
   do
   {
    if (romp->name != (char *)-1)
     aud->explength += romp->length & ~0xfc000000;
    romp++;
   }
   while (romp->length && (romp->name == 0 || romp->name == (char *)-1));
   if (err)
   {
    if (!aud->expchecksum)
     aud->status = 0x00000008;
    else
     aud->status = 0x00000004;
   }
   else if (aud->explength != aud->length)
    aud->status = 0x00000040;
   else if (aud->checksum != aud->expchecksum)
   {
    if (!aud->expchecksum)
     aud->status = 0x00000080;
    else if (aud->checksum == (~(aud->expchecksum)))
     aud->status = 0x00000002;
    else
     aud->status = 0x00000010;
   }
   else
    aud->status = 0x00000001;
   aud++;
  }
 }
 return count;
}

canonical_original_code:
int AuditRomSet(int game, struct tAuditRecord **audit)
{
 struct RomModule *romp;
 char *name;
 struct GameDriver *gamedrv;
 int count = 0;
 struct tAuditRecord *aud;
 int err;
 if (!gAudits)
  gAudits = (struct tAuditRecord *)malloc(100 * sizeof (tAuditRecord));
 if (gAudits)
  *audit = aud = gAudits;
 else
  return 0;
 gamedrv = drivers[game];
 romp = gamedrv->rom;
 if (!romp) return -1;
 if (!osd_faccess (gamedrv->name, OSD_FILETYPE_ROM))
 {
  if (gamedrv->clone_of == 0 || (gamedrv->clone_of->flags & 0x4000) ||
    !osd_faccess(gamedrv->clone_of->name,OSD_FILETYPE_ROM))
   return 0;
 }
 while (romp->name || romp->offset || romp->length)
 {
  if (romp->name || romp->length) return 0;
  romp++;
  while (romp->length)
  {
   struct GameDriver *drv;
   if (romp->name == 0)
    return 0;
   else if (romp->name == (char *)-1)
    return 0;
   name = romp->name;
   strcpy (aud->rom, name);
   aud->explength = 0;
   aud->length = 0;
   aud->expchecksum = romp->crc;
   aud->checksum = romp->crc;
   count++;
   drv = gamedrv;
   do
   {
    err = osd_fchecksum (drv->name, name, &aud->length, &aud->checksum);
    drv = drv->clone_of;
   } while (err && drv);
   do
   {
    if (romp->name != (char *)-1)
     aud->explength += romp->length & ~0xfc000000;
    romp++;
   }
   while (romp->length && (romp->name == 0 || romp->name == (char *)-1));
   if (err)
   {
    if (!aud->expchecksum)
     aud->status = 0x00000008;
    else
     aud->status = 0x00000004;
   }
   else if (aud->explength != aud->length)
    aud->status = 0x00000040;
   else if (aud->checksum != aud->expchecksum)
   {
    if (!aud->expchecksum)
     aud->status = 0x00000080;
    else if (aud->checksum == (~(aud->expchecksum)))
     aud->status = 0x00000002;
    else
     aud->status = 0x00000010;
   }
   else
    aud->status = 0x00000001;
   aud++;
  }
 }
 return count;
}

variable_types: game int

variable_types: struct tAuditRecord { char rom[20]; unsigned int explength; unsigned int length; unsigned int expchecksum; unsigned int checksum; int status; } **

variable_types: struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *

variable_types:
name
char *

variable_types: count int

variable_types: err int

user_defined_types: struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; }

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

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

user_defined_types: struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); }

user_defined_types: struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; }

user_defined_types: struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); }

user_defined_types: struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); }

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


RomsetMissing

original_code:
int RomsetMissing (int game)
{
 const struct GameDriver *gamedrv = drivers[game];
 if (gamedrv->clone_of)
 {
  tAuditRecord *aud;
  int count;
  int i;
  int cloneRomsFound = 0;
  if ((count = AuditRomSet (game, &aud)) == 0)
   return 1;
  if (count == -1) return 0;
  for (i = 0; i < count; i++)
   if (aud[i].status != 0x00000004)
    if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
     cloneRomsFound++;
  return !cloneRomsFound;
 }
 else
  return !osd_faccess (gamedrv->name, OSD_FILETYPE_ROM);
}

canonical_original_code:
int RomsetMissing(int game)
{
 struct GameDriver *gamedrv = drivers[game];
 if (gamedrv->clone_of)
 {
  struct tAuditRecord *aud;
  int count;
  int i;
  int cloneRomsFound = 0;
  if ((count = AuditRomSet (game, &aud)) == 0)
   return 1;
  if (count == -1) return 0;
  for (i = 0; i < count; i++)
   if (aud[i].status != 0x00000004)
    if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
     cloneRomsFound++;
  return !cloneRomsFound;
 }
 else
  return !osd_faccess (gamedrv->name, OSD_FILETYPE_ROM);
}

variable_types: struct tAuditRecord { char rom[20]; unsigned int explength; unsigned int length; unsigned int expchecksum; unsigned int checksum; int status; } *

variable_types: i int

variable_types: cloneRomsFound int

user_defined_types: struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; }


VerifyRomSet

decompiled_code:
__int64 __fastcall VerifyRomSet(int a1, void (*a2)(const char *, ...))
{
__int64 v2; // r14
int v3; // ecx
__int64 result; // rax
__int64 v5; // r13
int v6; // er15
int v7; // eax
char *v8; // rdx
int v9; // er14
char v10; // r15
int v11; // eax
__int64 v12; // [rsp+0h] [rbp-58h]
int v13; // [rsp+Ch] [rbp-4Ch]
char *v14; // [rsp+18h] [rbp-40h] BYREF

v2 = drivers[a1];
v3 = AuditRomSet(a1, &v14);
result = 1LL;
if ( !v3 )
return result;
if ( v3 == -1 )
goto LABEL_20;
if ( *(_QWORD *)(v2 + 8) )
{
if ( v3 <= 0 )
return 3LL;
v5 = 0LL;
v6 = 0;
v12 = 40LL * v3;
do
{
if ( *(_DWORD *)&v14[v5 + 36] != 4 )
{
v13 = v3;
v7 = RomInSet(*(_QWORD *)(v2 + 8), *(_DWORD *)&v14[v5 + 28]);
v3 = v13;
v6 += v7 == 0;
}
v5 += 40LL;
}
while ( v12 != v5 );
if ( !v6 )
return 3LL;
}
v8 = v14;
v9 = v3;
v10 = 0;
while ( 1 )
{
LABEL_11:
while ( 1 )
{
v11 = *((_DWORD *)v8 + 9);
v10 |= v11;
if ( v11 <= 32 )
break;
if ( v11 != 64 )
{
if ( v11 == 128 )
{
a2(
"%-8s: %-12s %7d bytes NO GOOD DUMP KNOWN\n",
*(const char **)(drivers[a1] + 16LL),
v8,
*((unsigned int *)v8 + 5));
v8 = v14;
}
goto LABEL_17;
}
a2(
"%-8s: %-12s %7d bytes %08x INCORRECT LENGTH: %8d\n",
*(const char **)(drivers[a1] + 16LL),
v8,
*((unsigned int *)v8 + 5),
*((unsigned int *)v8 + 7),
*((unsigned int *)v8 + 6));
v8 = v14 + 40;
v14 += 40;
if ( !--v9 )
goto LABEL_18;
}
if ( v11 > 1 )
break;
LABEL_17:
v8 += 40;
v14 = v8;
if ( !--v9 )
goto LABEL_18;
}
switch ( v11 )
{
case 2:
a2(
"%-8s: %-12s %7d bytes ROM NEEDS REDUMP\n",
*(const char **)(drivers[a1] + 16LL),
v8,
*((unsigned int *)v8 + 5));
v8 = v14 + 40;
v14 += 40;
if ( --v9 )
goto LABEL_11;
break;
case 4:
a2(
"%-8s: %-12s %7d bytes %08x NOT FOUND\n",
*(const char **)(drivers[a1] + 16LL),
v8,
*((unsigned int *)v8 + 5),
*((unsigned int *)v8 + 7));
v8 = v14 + 40;
v14 += 40;
if ( --v9 )
goto LABEL_11;
break;
case 8:
a2(
"%-8s: %-12s %7d bytes NOT FOUND - NO GOOD DUMP KNOWN\n",
*(const char **)(drivers[a1] + 16LL),
v8,
*((unsigned int *)v8 + 5));
v8 = v14 + 40;
v14 += 40;
if ( --v9 )
goto LABEL_11;
break;
case 16:
a2(
"%-8s: %-12s %7d bytes %08x INCORRECT CHECKSUM: %08x\n",
*(const char **)(drivers[a1] + 16LL),
v8,
*((unsigned int *)v8 + 5),
*((unsigned int *)v8 + 7),
*((unsigned int *)v8 + 8));
v8 = v14 + 40;
v14 += 40;
if ( --v9 )
goto LABEL_11;
break;
case 32:
a2("Out of memory reading ROM %s\n", v8);
v8 = v14 + 40;
v14 += 40;
if ( --v9 )
goto LABEL_11;
break;
default:
goto LABEL_17;
}
LABEL_18:
result = 2LL;
if ( (v10 & 0x74) == 0 )
{
result = 4LL;
if ( (v10 & 0x8A) == 0 )
LABEL_20:
result = 0LL;
}
return result;
}

original_code:
int VerifyRomSet (int game, verify_printf_proc verify_printf)
{
 tAuditRecord *aud;
 int count;
 int archive_status = 0;
 const struct GameDriver *gamedrv = drivers[game];
 if ((count = AuditRomSet (game, &aud)) == 0)
  return 1;
 if (count == -1) return 0;
        if (gamedrv->clone_of)
 {
  int i;
  int cloneRomsFound = 0;
  for (i = 0; i < count; i++)
   if (aud[i].status != 0x00000004)
    if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
     cloneRomsFound++;
  if (cloneRomsFound == 0)
   return 3;
 }
 while (count--)
 {
  archive_status |= aud->status;
  switch (aud->status)
  {
   case 0x00000004:
    verify_printf ("%-8s: %-12s %7d bytes %08x NOT FOUND\n",
     drivers[game]->name, aud->rom, aud->explength, aud->expchecksum);
    break;
   case 0x00000008:
    verify_printf ("%-8s: %-12s %7d bytes NOT FOUND - NO GOOD DUMP KNOWN\n",
     drivers[game]->name, aud->rom, aud->explength);
    break;
   case 0x00000080:
    verify_printf ("%-8s: %-12s %7d bytes NO GOOD DUMP KNOWN\n",
     drivers[game]->name, aud->rom, aud->explength);
    break;
   case 0x00000010:
    verify_printf ("%-8s: %-12s %7d bytes %08x INCORRECT CHECKSUM: %08x\n",
     drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->checksum);
    break;
   case 0x00000002:
    verify_printf ("%-8s: %-12s %7d bytes ROM NEEDS REDUMP\n",
     drivers[game]->name, aud->rom, aud->explength);
    break;
   case 0x00000020:
    verify_printf ("Out of memory reading ROM %s\n", aud->rom);
    break;
   case 0x00000040:
    verify_printf ("%-8s: %-12s %7d bytes %08x INCORRECT LENGTH: %8d\n",
     drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->length);
    break;
   case 0x00000001:
    break;
  }
  aud++;
 }
 if (archive_status & (0x00000004|0x00000010|0x00000020|0x00000040))
  return 2;
 if (archive_status & (0x00000080|0x00000002|0x00000008))
  return 4;
 return 0;
}

canonical_original_code:
int VerifyRomSet(int game, void (*verify_printf)(char *fmt, ...))
{
 struct tAuditRecord *aud;
 int count;
 int archive_status = 0;
 struct GameDriver *gamedrv = drivers[game];
 if ((count = AuditRomSet (game, &aud)) == 0)
  return 1;
 if (count == -1) return 0;
        if (gamedrv->clone_of)
 {
  int i;
  int cloneRomsFound = 0;
  for (i = 0; i < count; i++)
   if (aud[i].status != 0x00000004)
    if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
     cloneRomsFound++;
  if (cloneRomsFound == 0)
   return 3;
 }
 while (count--)
 {
  archive_status |= aud->status;
  switch (aud->status)
  {
   case 0x00000004:
    verify_printf ("%-8s: %-12s %7d bytes %08x NOT FOUND\n",
     drivers[game]->name, aud->rom, aud->explength, aud->expchecksum);
    break;
   case 0x00000008:
    verify_printf ("%-8s: %-12s %7d bytes NOT FOUND - NO GOOD DUMP KNOWN\n",
     drivers[game]->name, aud->rom, aud->explength);
    break;
   case 0x00000080:
    verify_printf ("%-8s: %-12s %7d bytes NO GOOD DUMP KNOWN\n",
     drivers[game]->name, aud->rom, aud->explength);
    break;
   case 0x00000010:
    verify_printf ("%-8s: %-12s %7d bytes %08x INCORRECT CHECKSUM: %08x\n",
     drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->checksum);
    break;
   case 0x00000002:
    verify_printf ("%-8s: %-12s %7d bytes ROM NEEDS REDUMP\n",
     drivers[game]->name, aud->rom, aud->explength);
    break;
   case 0x00000020:
    verify_printf ("Out of memory reading ROM %s\n", aud->rom);
    break;
   case 0x00000040:
    verify_printf ("%-8s: %-12s %7d bytes %08x INCORRECT LENGTH: %8d\n",
     drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->length);
    break;
   case 0x00000001:
    break;
  }
  aud++;
 }
 if (archive_status & (0x00000004|0x00000010|0x00000020|0x00000040))
  return 2;
 if (archive_status & (0x00000080|0x00000002|0x00000008))
  return 4;
 return 0;
}

user_defined_types: struct tAuditRecord { char rom[20]; unsigned int explength; unsigned int length; unsigned int expchecksum; unsigned int checksum; int status; }


AuditSampleSet

original_code:
int AuditSampleSet (int game, tMissingSample **audit)
{
 int skipfirst;
 void *f;
 const char **samplenames, *sharedname;
 int exist;
 static const struct GameDriver *gamedrv;
 int j;
 int count = 0;
 tMissingSample *aud;
 gamedrv = drivers[game];
 samplenames = ((void *)0);
 for( j = 0; gamedrv->drv->sound[j].sound_type && j < 5; j++ )
 {
  if( gamedrv->drv->sound[j].sound_type == SOUND_SAMPLES )
   samplenames = ((struct Samplesinterface *)gamedrv->drv->sound[j].sound_interface)->samplenames;
 }
 if (samplenames == 0 || samplenames[0] == 0)
  return 0;
 if (samplenames[0][0] == '*')
 {
  sharedname=samplenames[0]+1;
  skipfirst = 1;
 }
 else
 {
  sharedname = ((void *)0);
  skipfirst = 0;
 }
 exist = osd_faccess (gamedrv->name, OSD_FILETYPE_SAMPLE);
 if (!exist && skipfirst)
  exist = osd_faccess (sharedname, OSD_FILETYPE_SAMPLE);
 if (!exist)
  return -1;
 if (!gMissingSamples)
  gMissingSamples = (tMissingSample *)malloc(200 * sizeof (tMissingSample));
 if (gMissingSamples)
  *audit = aud = gMissingSamples;
 else
  return 0;
 for (j = skipfirst; samplenames[j] != 0; j++)
 {
  if (strlen (samplenames[j]) == 0)
   continue;
  f = osd_fopen (gamedrv->name, samplenames[j], OSD_FILETYPE_SAMPLE, 0);
  if (f == ((void *)0) && skipfirst)
   f = osd_fopen (sharedname, samplenames[j], OSD_FILETYPE_SAMPLE, 0);
  if (f)
   osd_fclose(f);
  else
  {
   strcpy (aud->name, samplenames[j]);
   count++;
   aud++;
  }
 }
 return count;
}

canonical_original_code:
int AuditSampleSet(int game, struct tMissingSample **audit)
{
 int skipfirst;
 void *f;
 char **samplenames; char *sharedname;
 int exist;
 static struct GameDriver *gamedrv;
 int j;
 int count = 0;
 struct tMissingSample *aud;
 gamedrv = drivers[game];
 samplenames = ((void *)0);
 for( j = 0; gamedrv->drv->sound[j].sound_type && j < 5; j++ )
 {
  if( gamedrv->drv->sound[j].sound_type == SOUND_SAMPLES )
   samplenames = ((struct Samplesinterface *)gamedrv->drv->sound[j].sound_interface)->samplenames;
 }
 if (samplenames == 0 || samplenames[0] == 0)
  return 0;
 if (samplenames[0][0] == '*')
 {
  sharedname=samplenames[0]+1;
  skipfirst = 1;
 }
 else
 {
  sharedname = ((void *)0);
  skipfirst = 0;
 }
 exist = osd_faccess (gamedrv->name, OSD_FILETYPE_SAMPLE);
 if (!exist && skipfirst)
  exist = osd_faccess (sharedname, OSD_FILETYPE_SAMPLE);
 if (!exist)
  return -1;
 if (!gMissingSamples)
  gMissingSamples = (struct tMissingSample *)malloc(200 * sizeof (tMissingSample));
 if (gMissingSamples)
  *audit = aud = gMissingSamples;
 else
  return 0;
 for (j = skipfirst; samplenames[j] != 0; j++)
 {
  if (strlen (samplenames[j]) == 0)
   continue;
  f = osd_fopen (gamedrv->name, samplenames[j], OSD_FILETYPE_SAMPLE, 0);
  if (f == ((void *)0) && skipfirst)
   f = osd_fopen (sharedname, samplenames[j], OSD_FILETYPE_SAMPLE, 0);
  if (f)
   osd_fclose(f);
  else
  {
   strcpy (aud->name, samplenames[j]);
   count++;
   aud++;
  }
 }
 return count;
}

variable_types: struct tMissingSample { char name[20]; } **

variable_types: skipfirst int

variable_types:
f
void *

variable_types:
samplenames
char **

variable_types:
sharedname
char *

variable_types: exist int

variable_types: j int

user_defined_types: struct Samplesinterface { int channels; int volume; char **samplenames; }


VerifySampleSet

decompiled_code:
__int64 __fastcall VerifySampleSet(int a1, void (*a2)(const char *, ...))
{
__int64 result; // rax
const char *v3; // rdx
int v4; // ebx
char *v5; // [rsp+8h] [rbp-30h] BYREF

result = AuditSampleSet(a1, &v5);
if ( (_DWORD)result == -1 )
return 1LL;
if ( (_DWORD)result )
{
v3 = v5;
v4 = result;
do
{
a2("%-8s: %s NOT FOUND\n", *(const char **)(drivers[a1] + 16LL), v3);
v3 = v5 + 20;
v5 += 20;
--v4;
}
while ( v4 );
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, void (*a2)(const char *, ...))
{
__int64 result; // rax
const char *v3; // rdx
int v4; // ebx
char *v5; // [rsp+8h] [rbp-30h] BYREF

result = func4(a1, &v5);
if ( (_DWORD)result == -1 )
return 1LL;
if ( (_DWORD)result )
{
v3 = v5;
v4 = result;
do
{
a2("%-8s: %s NOT FOUND\n", *(const char **)(drivers[a1] + 16LL), v3);
v3 = v5 + 20;
v5 += 20;
--v4;
}
while ( v4 );
result = 2LL;
}
return result;
}

original_code:
int VerifySampleSet (int game, verify_printf_proc verify_printf)
{
 tMissingSample *aud;
 int count;
 count = AuditSampleSet (game, &aud);
 if (count==-1)
  return 1;
 else if (count==0)
  return 0;
 while (count--)
 {
  verify_printf ("%-8s: %s NOT FOUND\n", drivers[game]->name, aud->name);
  aud++;
 }
 return 2;
}

canonical_original_code:
int VerifySampleSet(int game, void (*verify_printf)(char *fmt, ...))
{
 struct tMissingSample *aud;
 int count;
 count = AuditSampleSet (game, &aud);
 if (count==-1)
  return 1;
 else if (count==0)
  return 0;
 while (count--)
 {
  verify_printf ("%-8s: %s NOT FOUND\n", drivers[game]->name, aud->name);
  aud++;
 }
 return 2;
}

variable_types: struct tMissingSample { char name[20]; } *


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
char *__fastcall wiz_palettebank_w(int a1, char a2)
{
char *result; // rax
int v3; // esi

result = palbank;
v3 = a2 & 1;
if ( (unsigned __int8)palbank[a1] != v3 )
{
palbank[a1] = v3;
palette_bank = (unsigned __int8)palbank[0] + 2 * (unsigned __int8)byte_FDD;
result = (char *)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1, char a2)
{
char *result; // rax
int v3; // esi

result = palbank;
v3 = a2 & 1;
if ( (unsigned __int8)palbank[a1] != v3 )
{
palbank[a1] = v3;
palette_bank = (unsigned __int8)palbank[0] + 2 * (unsigned __int8)byte_FDD;
result = (char *)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void wiz_palettebank_w(offs_t offset,data_t data)
{
 if (palbank[offset] != (data & 1))
 {
  palbank[offset] = data & 1;
  palette_bank = palbank[0] + 2 * palbank[1];
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void wiz_palettebank_w(unsigned int offset, unsigned int data)
{
 if (palbank[offset] != (data & 1))
 {
  palbank[offset] = data & 1;
  palette_bank = palbank[0] + 2 * palbank[1];
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
char *__fastcall wiz_char_bank_select_w(int a1, char a2)
{
char *result; // rax
int v3; // esi

result = char_bank;
v3 = a2 & 1;
if ( (unsigned __int8)char_bank[a1] != v3 )
{
char_bank[a1] = v3;
result = (char *)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = char_bank;
v3 = a2 & 1;
if ( (unsigned __int8)char_bank[a1] != v3 )
{
char_bank[a1] = v3;
result = (char *)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void wiz_char_bank_select_w(offs_t offset,data_t data)
{
 if (char_bank[offset] != (data & 1))
 {
  char_bank[offset] = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void wiz_char_bank_select_w(unsigned int offset, unsigned int data)
{
 if (char_bank[offset] != (data & 1))
 {
  char_bank[offset] = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
}


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

if ( flipx != a2 )
{
flipx = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

if ( flipx != a2 )
{
flipx = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void wiz_flipx_w(offs_t offset,data_t data)
{
    if (flipx != data)
    {
  flipx = data;
  memset(dirtybuffer, 1, videoram_size);
    }
}

canonical_original_code:
void wiz_flipx_w(unsigned int offset, unsigned int data)
{
    if (flipx != data)
    {
  flipx = data;
  memset(dirtybuffer, 1, videoram_size);
    }
}


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

if ( flipy != a2 )
{
flipy = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

if ( flipy != a2 )
{
flipy = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void wiz_flipy_w(offs_t offset,data_t data)
{
    if (flipy != data)
    {
  flipy = data;
  memset(dirtybuffer, 1, videoram_size);
    }
}

canonical_original_code:
void wiz_flipy_w(unsigned int offset, unsigned int data)
{
    if (flipy != data)
    {
  flipy = data;
  memset(dirtybuffer, 1, videoram_size);
    }
}


decompiled_code:
__int64 init_stinger()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 result; // rax
char v3; // cl
int v4; // edx

v0 = memory_region(129LL);
v1 = v0 + (int)memory_region_length(129LL) / 2;
memory_set_opcode_base(0LL, v1);
for ( result = 0LL; result != 0x10000; ++result )
{
v3 = *(_BYTE *)(v0 + result);
if ( (result & 0x2040) == 0 )
{
v4 = ((v3 & 8) != 0) | (2 * ((unsigned __int8)v3 >> 5)) & 2;
if ( v3 < 0 )
v4 = 3 - v4;
v3 ^= xortable_0[4 * (((int)result >> 3) & 1 | ((unsigned int)result >> 4) & 2) + v4];
}
*(_BYTE *)(v1 + result) = v3;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 result; // rax
char v3; // cl
int v4; // edx

v0 = memory_region(129LL);
v1 = v0 + (int)memory_region_length(129LL) / 2;
memory_set_opcode_base(0LL, v1);
for ( result = 0LL; result != 0x10000; ++result )
{
v3 = *(_BYTE *)(v0 + result);
if ( (result & 0x2040) == 0 )
{
v4 = ((v3 & 8) != 0) | (2 * ((unsigned __int8)v3 >> 5)) & 2;
if ( v3 < 0 )
v4 = 3 - v4;
v3 ^= xortable_0[4 * (((int)result >> 3) & 1 | ((unsigned int)result >> 4) & 2) + v4];
}
*(_BYTE *)(v1 + result) = v3;
}
return result;
}

original_code:
static void init_stinger(void)
{
 static const unsigned char xortable[4][4] =
 {
  { 0xa0,0x88,0x88,0xa0 },
  { 0x88,0x00,0xa0,0x28 },
  { 0x80,0xa8,0x20,0x08 },
  { 0x28,0x28,0x88,0x88 }
 };
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int A;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0x0000;A < 0x10000;A++)
 {
  int row,col;
  unsigned char src;
  if (A & 0x2040)
  {
   rom[A+diff] = rom[A];
  }
  else
  {
   src = rom[A];
   row = ((A >> 3) & 1) + (((A >> 5) & 1) << 1);
   col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
   if (src & 0x80) col = 3 - col;
   rom[A+diff] = src ^ xortable[row][col];
  }
 }
}

canonical_original_code:
static void init_stinger()
{
 static unsigned char xortable[4][4] = {
  { 0xa0,0x88,0x88,0xa0 },
  { 0x88,0x00,0xa0,0x28 },
  { 0x80,0xa8,0x20,0x08 },
  { 0x28,0x28,0x88,0x88 }
 };
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int A;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0x0000;A < 0x10000;A++)
 {
  int row; int col;
  unsigned char src;
  if (A & 0x2040)
  {
   rom[A+diff] = rom[A];
  }
  else
  {
   src = rom[A];
   row = ((A >> 3) & 1) + (((A >> 5) & 1) << 1);
   col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
   if (src & 0x80) col = 3 - col;
   rom[A+diff] = src ^ xortable[row][col];
  }
 }
}

variable_types:
xortable
unsigned char [4][4]

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int

variable_types: row int

variable_types: col int

variable_types:
src
unsigned char


decompiled_code:
__int64 __fastcall stinger_vh_screenrefresh(__int64 a1)
{
draw_background_constprop_0(a1, (unsigned __int8)char_bank[0] + 2);
draw_foreground(a1, 1);
draw_sprites(a1, spriteram_2, 4);
return draw_sprites(a1, spriteram, 5);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
func10(a1, (unsigned __int8)char_bank[0] + 2);
func6(a1, 1);
func7(a1, spriteram_2, 4);
return func7(a1, spriteram, 5);
}

original_code:
void stinger_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 draw_background(bitmap, 2 + char_bank[0], 1);
 draw_foreground(bitmap, 1);
 draw_sprites(bitmap, spriteram_2, 4, &Machine->visible_area);
 draw_sprites(bitmap, spriteram , 5, &Machine->visible_area);
}

canonical_original_code:
void stinger_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 draw_background(bitmap, 2 + char_bank[0], 1);
 draw_foreground(bitmap, 1);
 draw_sprites(bitmap, spriteram_2, 4, &Machine->visible_area);
 draw_sprites(bitmap, spriteram , 5, &Machine->visible_area);
}

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


decompiled_code:
__int64 __fastcall wiz_vh_screenrefresh(__int64 a1)
{
int v1; // er13

draw_background_constprop_0(a1, ((unsigned __int8)byte_FDF | (2 * (unsigned __int8)char_bank[0])) + 2);
draw_foreground(a1, 0);
if ( *(char *)(spriteram + 1) < 0 || !*(_BYTE *)(spriteram + 3) || (v1 = 8, !*(_BYTE *)spriteram) )
v1 = (unsigned __int8)*wiz_sprite_bank + 7;
draw_sprites(a1, spriteram_2, 6);
return draw_sprites(a1, spriteram, v1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // er13

func10(a1, ((unsigned __int8)byte_FDF | (2 * (unsigned __int8)char_bank[0])) + 2);
func6(a1, 0);
if ( *(char *)(spriteram + 1) < 0 || !*(_BYTE *)(spriteram + 3) || (v1 = 8, !*(_BYTE *)spriteram) )
v1 = (unsigned __int8)*wiz_sprite_bank + 7;
func7(a1, spriteram_2, 6);
return func7(a1, spriteram, v1);
}

original_code:
void wiz_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int bank;
 const struct rectangle* visible_area;
 draw_background(bitmap, 2 + ((char_bank[0] << 1) | char_bank[1]), 0);
 draw_foreground(bitmap, 0);
 visible_area = flipx ? &spritevisibleareaflipx : &spritevisiblearea;
 if ((spriteram[1] & 0x80) || !spriteram[3] || !spriteram[0])
 {
     bank = 7 + *wiz_sprite_bank;
 }
 else
 {
  bank = 8;
 }
 draw_sprites(bitmap, spriteram_2, 6, visible_area);
 draw_sprites(bitmap, spriteram , bank, visible_area);
}

canonical_original_code:
void wiz_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int bank;
 struct rectangle *visible_area;
 draw_background(bitmap, 2 + ((char_bank[0] << 1) | char_bank[1]), 0);
 draw_foreground(bitmap, 0);
 visible_area = flipx ? &spritevisibleareaflipx : &spritevisiblearea;
 if ((spriteram[1] & 0x80) || !spriteram[3] || !spriteram[0])
 {
     bank = 7 + *wiz_sprite_bank;
 }
 else
 {
  bank = 8;
 }
 draw_sprites(bitmap, spriteram_2, 6, visible_area);
 draw_sprites(bitmap, spriteram , bank, visible_area);
}

variable_types: bank int

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


decompiled_code:
void *__fastcall draw_foreground(__int64 a1, int a2)
{
void *result; // rax
int v3; // er15
__int64 v5; // r14
int v6; // esi
unsigned int v7; // er10

result = &videoram_size;
v3 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v5 = v3;
do
{
if ( a2 )
v6 = *(_BYTE *)(wiz_attributesram2 + 2 * (v3 & 0x1F) + 1) & 7;
else
v6 = *(_BYTE *)(wiz_colorram2 + v5) & 7;
--v3;
v7 = *(unsigned __int8 *)(wiz_videoram2 + v5--);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (unsigned __int8)byte_FDF + 512),
v7,
(unsigned int)(v6 + 8 * palette_bank));
}
while ( v3 != -1 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, int a2)
{
void *result; // rax
int v3; // er15
__int64 v5; // r14
int v6; // esi
unsigned int v7; // er10

result = &videoram_size;
v3 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v5 = v3;
do
{
if ( a2 )
v6 = *(_BYTE *)(wiz_attributesram2 + 2 * (v3 & 0x1F) + 1) & 7;
else
v6 = *(_BYTE *)(wiz_colorram2 + v5) & 7;
--v3;
v7 = *(unsigned __int8 *)(wiz_videoram2 + v5--);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (unsigned __int8)byte_FDF + 512),
v7,
(unsigned int)(v6 + 8 * palette_bank));
}
while ( v3 != -1 );
}
return result;
}

original_code:
static void draw_foreground(struct osd_bitmap *bitmap, int colortype)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int scroll,sx,sy,col;
  sx = offs % 32;
  sy = offs / 32;
  if (colortype)
  {
   col = (wiz_attributesram2[2 * sx + 1] & 0x07);
  }
  else
  {
   col = (wiz_colorram2[offs] & 0x07);
  }
  scroll = (8*sy + 256 - wiz_attributesram2[2 * sx]) % 256;
  if (flipy)
  {
     scroll = (248 - scroll) % 256;
  }
  if (flipx) sx = 31 - sx;
  drawgfx(bitmap,Machine->gfx[char_bank[1]],
   wiz_videoram2[offs],
   col + 8 * palette_bank,
   flipx,flipy,
   8*sx,scroll,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_foreground(struct osd_bitmap *bitmap, int colortype)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int scroll; int sx; int sy; int col;
  sx = offs % 32;
  sy = offs / 32;
  if (colortype)
  {
   col = (wiz_attributesram2[2 * sx + 1] & 0x07);
  }
  else
  {
   col = (wiz_colorram2[offs] & 0x07);
  }
  scroll = (8*sy + 256 - wiz_attributesram2[2 * sx]) % 256;
  if (flipy)
  {
     scroll = (248 - scroll) % 256;
  }
  if (flipx) sx = 31 - sx;
  drawgfx(bitmap,Machine->gfx[char_bank[1]],
   wiz_videoram2[offs],
   col + 8 * palette_bank,
   flipx,flipy,
   8*sx,scroll,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: colortype int

variable_types: offs int

variable_types: scroll int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp

result = (__int64)&spriteram_size;
LODWORD(v4) = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = (int)v4;
v5 = a3 + 64LL;
do
{
result = *(unsigned __int8 *)(a2 + v4 + 3);
if ( *(_BYTE *)(a2 + v4 + 3) )
{
if ( *(_BYTE *)(a2 + v4) )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8 * v5),
*(unsigned __int8 *)(a2 + v4 + 1),
(*(_BYTE *)(a2 + v4 + 2) & 7u) + 8 * palette_bank);
}
v4 -= 4LL;
}
while ( (int)v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp

result = (__int64)&spriteram_size;
LODWORD(v4) = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = (int)v4;
v5 = a3 + 64LL;
do
{
result = *(unsigned __int8 *)(a2 + v4 + 3);
if ( *(_BYTE *)(a2 + v4 + 3) )
{
if ( *(_BYTE *)(a2 + v4) )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8 * v5),
*(unsigned __int8 *)(a2 + v4 + 1),
(*(_BYTE *)(a2 + v4 + 2) & 7u) + 8 * palette_bank);
}
v4 -= 4LL;
}
while ( (int)v4 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap, unsigned char* sprite_ram,
                         int bank, const struct rectangle* visible_area)
{
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy;
  sx = sprite_ram[offs + 3];
  sy = sprite_ram[offs];
  if (!sx || !sy) continue;
  if ( flipx) sx = 240 - sx;
  if (!flipy) sy = 240 - sy;
  drawgfx(bitmap,Machine->gfx[bank],
    sprite_ram[offs + 1],
    (sprite_ram[offs + 2] & 0x07) + 8 * palette_bank,
    flipx,flipy,
    sx,sy,
    visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap, unsigned char *sprite_ram, int bank, struct rectangle *visible_area)
{
 int offs;
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy;
  sx = sprite_ram[offs + 3];
  sy = sprite_ram[offs];
  if (!sx || !sy) continue;
  if ( flipx) sx = 240 - sx;
  if (!flipy) sy = 240 - sy;
  drawgfx(bitmap,Machine->gfx[bank],
    sprite_ram[offs + 1],
    (sprite_ram[offs + 2] & 0x07) + 8 * palette_bank,
    flipx,flipy,
    sx,sy,
    visible_area,TRANSPARENCY_PEN,0);
 }
}


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

if ( a2 != 144 )
result = soundlatch_w(0LL);
return result;
}

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

if ( a2 != 144 )
result = soundlatch_w(0LL);
return result;
}

original_code:
static void sound_command_w(offs_t offset,data_t data)
{
 if (data == 0x90)
 {
 }
 else
  soundlatch_w(0,data);
}

canonical_original_code:
static void sound_command_w(unsigned int offset, unsigned int data)
{
 if (data == 0x90)
 {
 }
 else
  soundlatch_w(0,data);
}

variable_types:
offset
unsigned int


original_code:
static void SN76496Update(int chip,INT16 *buffer,int length)
{
 int i;
 struct SN76496 *R = &sn[chip];
 for (i = 0;i < 4;i++)
 {
  if (R->Volume[i] == 0)
  {
   if (R->Count[i] <= length*0x10000) R->Count[i] += length*0x10000;
  }
 }
 while (length > 0)
 {
  int vol[4];
  unsigned int out;
  int left;
  vol[0] = vol[1] = vol[2] = vol[3] = 0;
  for (i = 0;i < 3;i++)
  {
   if (R->Output[i]) vol[i] += R->Count[i];
   R->Count[i] -= 0x10000;
   while (R->Count[i] <= 0)
   {
    R->Count[i] += R->Period[i];
    if (R->Count[i] > 0)
    {
     R->Output[i] ^= 1;
     if (R->Output[i]) vol[i] += R->Period[i];
     break;
    }
    R->Count[i] += R->Period[i];
    vol[i] += R->Period[i];
   }
   if (R->Output[i]) vol[i] -= R->Count[i];
  }
  left = 0x10000;
  do
  {
   int nextevent;
   if (R->Count[3] < left) nextevent = R->Count[3];
   else nextevent = left;
   if (R->Output[3]) vol[3] += R->Count[3];
   R->Count[3] -= nextevent;
   if (R->Count[3] <= 0)
   {
    if (R->RNG & 1) R->RNG ^= R->NoiseFB;
    R->RNG >>= 1;
    R->Output[3] = R->RNG & 1;
    R->Count[3] += R->Period[3];
    if (R->Output[3]) vol[3] += R->Period[3];
   }
   if (R->Output[3]) vol[3] -= R->Count[3];
   left -= nextevent;
  } while (left > 0);
  out = vol[0] * R->Volume[0] + vol[1] * R->Volume[1] +
    vol[2] * R->Volume[2] + vol[3] * R->Volume[3];
  if (out > 0x7fff * 0x10000) out = 0x7fff * 0x10000;
  *(buffer++) = out / 0x10000;
  length--;
 }
}

canonical_original_code:
static void SN76496Update(int chip, short *buffer, int length)
{
 int i;
 struct SN76496 *R = &sn[chip];
 for (i = 0;i < 4;i++)
 {
  if (R->Volume[i] == 0)
  {
   if (R->Count[i] <= length*0x10000) R->Count[i] += length*0x10000;
  }
 }
 while (length > 0)
 {
  int vol[4];
  unsigned int out;
  int left;
  vol[0] = vol[1] = vol[2] = vol[3] = 0;
  for (i = 0;i < 3;i++)
  {
   if (R->Output[i]) vol[i] += R->Count[i];
   R->Count[i] -= 0x10000;
   while (R->Count[i] <= 0)
   {
    R->Count[i] += R->Period[i];
    if (R->Count[i] > 0)
    {
     R->Output[i] ^= 1;
     if (R->Output[i]) vol[i] += R->Period[i];
     break;
    }
    R->Count[i] += R->Period[i];
    vol[i] += R->Period[i];
   }
   if (R->Output[i]) vol[i] -= R->Count[i];
  }
  left = 0x10000;
  do
  {
   int nextevent;
   if (R->Count[3] < left) nextevent = R->Count[3];
   else nextevent = left;
   if (R->Output[3]) vol[3] += R->Count[3];
   R->Count[3] -= nextevent;
   if (R->Count[3] <= 0)
   {
    if (R->RNG & 1) R->RNG ^= R->NoiseFB;
    R->RNG >>= 1;
    R->Output[3] = R->RNG & 1;
    R->Count[3] += R->Period[3];
    if (R->Output[3]) vol[3] += R->Period[3];
   }
   if (R->Output[3]) vol[3] -= R->Count[3];
   left -= nextevent;
  } while (left > 0);
  out = vol[0] * R->Volume[0] + vol[1] * R->Volume[1] +
    vol[2] * R->Volume[2] + vol[3] * R->Volume[3];
  if (out > 0x7fff * 0x10000) out = 0x7fff * 0x10000;
  *(buffer++) = out / 0x10000;
  length--;
 }
}

variable_types: chip int

variable_types:
buffer
short *

variable_types: length int

variable_types: i int

variable_types: struct SN76496 { int Channel; int SampleRate; unsigned int UpdateStep; int VolTable[16]; int Register[8]; int LastRegister; int Volume[4]; unsigned int RNG; int NoiseFB; int Period[4]; int Count[4]; int Output[4]; } *

variable_types:
vol
int [4]

variable_types:
out
unsigned int

variable_types: left int

variable_types: nextevent int


decompiled_code:
__int64 __fastcall SN76496_set_clock(int a1, int a2)
{
int *v2; // rdi
__int64 result; // rax

v2 = (int *)((char *)&sn + 184 * a1);
result = (unsigned int)(int)(float)((float)((float)((float)v2[1] * 65536.0) * 16.0) / (float)a2);
v2[2] = result;
return result;
}

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

v2 = (int *)((char *)&sn + 184 * a1);
result = (unsigned int)(int)(float)((float)((float)((float)v2[1] * 65536.0) * 16.0) / (float)a2);
v2[2] = result;
return result;
}

original_code:
static void SN76496_set_clock(int chip,int clock)
{
 struct SN76496 *R = &sn[chip];
 R->UpdateStep = ((float)0x10000 * R->SampleRate * 16) / clock;
}

canonical_original_code:
static void SN76496_set_clock(int chip, int clock)
{
 struct SN76496 *R = &sn[chip];
 R->UpdateStep = ((float)0x10000 * R->SampleRate * 16) / clock;
}

variable_types: clock int

user_defined_types: struct SN76496 { int Channel; int SampleRate; unsigned int UpdateStep; int VolTable[16]; int Register[8]; int LastRegister; int Volume[4]; unsigned int RNG; int NoiseFB; int Period[4]; int Count[4]; int Output[4]; }


original_code:
static void SN76496_set_gain(int chip,int gain)
{
 struct SN76496 *R = &sn[chip];
 int i;
 float out;
 gain &= 0xff;
 out = 0x7fff / 3;
 while (gain-- > 0)
  out *= 1.023292992;
 for (i = 0;i < 15;i++)
 {
  if (out > 0x7fff / 3) R->VolTable[i] = 0x7fff / 3;
  else R->VolTable[i] = out;
  out /= 1.258925412;
 }
 R->VolTable[15] = 0;
}

canonical_original_code:
static void SN76496_set_gain(int chip, int gain)
{
 struct SN76496 *R = &sn[chip];
 int i;
 float out;
 gain &= 0xff;
 out = 0x7fff / 3;
 while (gain-- > 0)
  out *= 1.023292992;
 for (i = 0;i < 15;i++)
 {
  if (out > 0x7fff / 3) R->VolTable[i] = 0x7fff / 3;
  else R->VolTable[i] = out;
  out /= 1.258925412;
 }
 R->VolTable[15] = 0;
}

variable_types: gain int

variable_types: out float


original_code:
static void SN76496Write(int chip,int data)
{
 struct SN76496 *R = &sn[chip];
 stream_update(R->Channel,0);
 if (data & 0x80)
 {
  int r = (data & 0x70) >> 4;
  int c = r/2;
  R->LastRegister = r;
  R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f);
  switch (r)
  {
   case 0:
   case 2:
   case 4:
    R->Period[c] = R->UpdateStep * R->Register[r];
    if (R->Period[c] == 0) R->Period[c] = R->UpdateStep;
    if (r == 4)
    {
     if ((R->Register[6] & 0x03) == 0x03)
      R->Period[3] = 2 * R->Period[2];
    }
    break;
   case 1:
   case 3:
   case 5:
   case 7:
    R->Volume[c] = R->VolTable[data & 0x0f];
    break;
   case 6:
    {
     int n = R->Register[6];
     R->NoiseFB = (n & 4) ? 0x12000 : 0x08000;
     n &= 3;
     R->Period[3] = (n == 3) ? 2 * R->Period[2] : (R->UpdateStep << (5+n));
     R->RNG = 0x0f35;
     R->Output[3] = R->RNG & 1;
    }
    break;
  }
 }
 else
 {
  int r = R->LastRegister;
  int c = r/2;
  switch (r)
  {
   case 0:
   case 2:
   case 4:
    R->Register[r] = (R->Register[r] & 0x0f) | ((data & 0x3f) << 4);
    R->Period[c] = R->UpdateStep * R->Register[r];
    if (R->Period[c] == 0) R->Period[c] = R->UpdateStep;
    if (r == 4)
    {
     if ((R->Register[6] & 0x03) == 0x03)
      R->Period[3] = 2 * R->Period[2];
    }
    break;
  }
 }
}

canonical_original_code:
static void SN76496Write(int chip, int data)
{
 struct SN76496 *R = &sn[chip];
 stream_update(R->Channel,0);
 if (data & 0x80)
 {
  int r = (data & 0x70) >> 4;
  int c = r/2;
  R->LastRegister = r;
  R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f);
  switch (r)
  {
   case 0:
   case 2:
   case 4:
    R->Period[c] = R->UpdateStep * R->Register[r];
    if (R->Period[c] == 0) R->Period[c] = R->UpdateStep;
    if (r == 4)
    {
     if ((R->Register[6] & 0x03) == 0x03)
      R->Period[3] = 2 * R->Period[2];
    }
    break;
   case 1:
   case 3:
   case 5:
   case 7:
    R->Volume[c] = R->VolTable[data & 0x0f];
    break;
   case 6:
    {
     int n = R->Register[6];
     R->NoiseFB = (n & 4) ? 0x12000 : 0x08000;
     n &= 3;
     R->Period[3] = (n == 3) ? 2 * R->Period[2] : (R->UpdateStep << (5+n));
     R->RNG = 0x0f35;
     R->Output[3] = R->RNG & 1;
    }
    break;
  }
 }
 else
 {
  int r = R->LastRegister;
  int c = r/2;
  switch (r)
  {
   case 0:
   case 2:
   case 4:
    R->Register[r] = (R->Register[r] & 0x0f) | ((data & 0x3f) << 4);
    R->Period[c] = R->UpdateStep * R->Register[r];
    if (R->Period[c] == 0) R->Period[c] = R->UpdateStep;
    if (r == 4)
    {
     if ((R->Register[6] & 0x03) == 0x03)
      R->Period[3] = 2 * R->Period[2];
    }
    break;
  }
 }
}

variable_types: data int

variable_types: r int

variable_types: c int

variable_types: n int


decompiled_code:
__int64 __fastcall SN76496_0_w(__int64 a1, int a2)
{
return SN76496Write(0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
return func3(0, a2);
}

original_code: void SN76496_0_w(offs_t offset,data_t data) { SN76496Write(0,data); }

canonical_original_code: void SN76496_0_w(unsigned int offset, unsigned int data) { SN76496Write(0,data); }

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall SN76496_1_w(__int64 a1, int a2)
{
return SN76496Write(1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
return func3(1, a2);
}

original_code: void SN76496_1_w(offs_t offset,data_t data) { SN76496Write(1,data); }

canonical_original_code: void SN76496_1_w(unsigned int offset, unsigned int data) { SN76496Write(1,data); }


decompiled_code:
__int64 __fastcall SN76496_2_w(__int64 a1, int a2)
{
return SN76496Write(2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
return func3(2, a2);
}

original_code: void SN76496_2_w(offs_t offset,data_t data) { SN76496Write(2,data); }

canonical_original_code: void SN76496_2_w(unsigned int offset, unsigned int data) { SN76496Write(2,data); }


decompiled_code:
__int64 __fastcall SN76496_3_w(__int64 a1, int a2)
{
return SN76496Write(3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
return func3(3, a2);
}

original_code: void SN76496_3_w(offs_t offset,data_t data) { SN76496Write(3,data); }

canonical_original_code: void SN76496_3_w(unsigned int offset, unsigned int data) { SN76496Write(3,data); }


decompiled_code:
__int64 __fastcall SN76496_sh_start(__int64 a1)
{
int *v1; // rbp
__int64 v2; // rbx
int v3; // esi
int v4; // edi

v1 = *(int **)(a1 + 8);
if ( *v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( !(unsigned int)SN76496_init_constprop_0(v2, v1[v2 + 1], LOBYTE(v1[v2 + 5]), *(_DWORD *)(Machine + 836LL)) )
{
v3 = BYTE1(v1[v2 + 5]);
v4 = v2++;
SN76496_set_gain(v4, v3);
if ( *v1 <= (int)v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int *v1; // rbp
__int64 v2; // rbx
int v3; // esi
int v4; // edi

v1 = *(int **)(a1 + 8);
if ( *v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( !(unsigned int)func4(v2, v1[v2 + 1], LOBYTE(v1[v2 + 5]), *(_DWORD *)(Machine + 836LL)) )
{
v3 = BYTE1(v1[v2 + 5]);
v4 = v2++;
func2(v4, v3);
if ( *v1 <= (int)v2 )
return 0LL;
}
return 1LL;
}

original_code:
int SN76496_sh_start(const struct MachineSound *msound)
{
 int chip;
 const struct SN76496interface *intf = (const struct SN76496interface *)msound->sound_interface;
 for (chip = 0;chip < intf->num;chip++)
 {
  if (SN76496_init(msound,chip,intf->baseclock[chip],intf->volume[chip] & 0xff,Machine->sample_rate) != 0)
   return 1;
  SN76496_set_gain(chip,(intf->volume[chip] >> 8) & 0xff);
 }
 return 0;
}

canonical_original_code:
int SN76496_sh_start(struct MachineSound *msound)
{
 int chip;
 struct SN76496interface *intf = (const struct SN76496interface *)msound->sound_interface;
 for (chip = 0;chip < intf->num;chip++)
 {
  if (SN76496_init(msound,chip,intf->baseclock[chip],intf->volume[chip] & 0xff,Machine->sample_rate) != 0)
   return 1;
  SN76496_set_gain(chip,(intf->volume[chip] >> 8) & 0xff);
 }
 return 0;
}

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

variable_types: chip int

variable_types: struct SN76496interface { int num; int baseclock[4]; int volume[4]; } *


decompiled_code:
__int64 __fastcall C140_r(__int16 a1)
{
return REG[a1 & 0x1FF];
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1)
{
return REG[a1 & 0x1FF];
}

original_code:
data_t C140_r(offs_t offset)
{
 offset&=0x1ff;
 return REG[offset];
}

canonical_original_code:
unsigned int C140_r(unsigned int offset)
{
 offset&=0x1ff;
 return REG[offset];
}