original_code:
static inline int tone23(int samplerate)
{
 static int counter2, output2, counter3, output3;
 int level = 32767 - update_pb4(samplerate);
 int sum = 0;
 if( (sound_latch_b & 0x20) == 0 )
  return sum;
 if( level < 32767 )
 {
  counter2 -= tone2_max_freq * level / 32768;
  if( counter2 <= 0 )
  {
   int n = (-counter2 / samplerate) + 1;
   counter2 += n * samplerate;
   output2 = (output2 + n) & 1;
  }
  counter3 -= tone3_max_freq*1/3 + tone3_max_freq*2/3 * level / 33768;
  if( counter3 <= 0 )
  {
   int n = (-counter2 / samplerate) + 1;
   counter3 += samplerate;
   output3 = (output3 + n) & 1;
  }
 }
 sum += (output2) ? 32767 : -32767;
 sum += (output3) ? 32767 : -32767;
 return sum / 2;
}

canonical_original_code:
static inline int tone23(int samplerate)
{
 static int counter2; static int output2; static int counter3; static int output3;
 int level = 32767 - update_pb4(samplerate);
 int sum = 0;
 if( (sound_latch_b & 0x20) == 0 )
  return sum;
 if( level < 32767 )
 {
  counter2 -= tone2_max_freq * level / 32768;
  if( counter2 <= 0 )
  {
   int n = (-counter2 / samplerate) + 1;
   counter2 += n * samplerate;
   output2 = (output2 + n) & 1;
  }
  counter3 -= tone3_max_freq*1/3 + tone3_max_freq*2/3 * level / 33768;
  if( counter3 <= 0 )
  {
   int n = (-counter2 / samplerate) + 1;
   counter3 += samplerate;
   output3 = (output3 + n) & 1;
  }
 }
 sum += (output2) ? 32767 : -32767;
 sum += (output3) ? 32767 : -32767;
 return sum / 2;
}

variable_types: sum int


decompiled_code:
__int64 __fastcall update_c_pc4(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // eax
int v6; // eax
unsigned int v7; // er8
int v8; // eax

v1 = level_9;
if ( (sound_latch_c & 0x10) != 0 )
{
if ( level_9 > 32766 )
return v1;
v2 = (int)(float)((float)(0x7FFF - level_9) / *(float *)&pc4_charge_time);
v3 = counter_8 - v2;
if ( counter_8 - v2 > 0 )
{
LABEL_4:
counter_8 = v3;
return v1;
}
v8 = (v2 - counter_8) / a1 + 1;
v7 = v8 + level_9;
counter_8 = v8 * a1 + v3;
if ( v8 + level_9 > 0x7FFF )
{
level_9 = 0x7FFF;
return 0x7FFF;
}
}
else
{
if ( level_9 <= 4587 )
return v1;
v5 = (int)(float)((float)(level_9 - 4587) / *(float *)&pc4_discharge_time);
v3 = counter_8 - v5;
if ( counter_8 - v5 > 0 )
goto LABEL_4;
v6 = (v5 - counter_8) / a1 + 1;
v7 = level_9 - v6;
counter_8 = v3 + v6 * a1;
if ( level_9 - v6 <= 4586 )
{
level_9 = 4587;
return 4587;
}
}
level_9 = v7;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // eax
int v6; // eax
unsigned int v7; // er8
int v8; // eax

v1 = level_9;
if ( (sound_latch_c & 0x10) != 0 )
{
if ( level_9 > 32766 )
return v1;
v2 = (int)(float)((float)(0x7FFF - level_9) / *(float *)&pc4_charge_time);
v3 = counter_8 - v2;
if ( counter_8 - v2 > 0 )
{
LABEL_4:
counter_8 = v3;
return v1;
}
v8 = (v2 - counter_8) / a1 + 1;
v7 = v8 + level_9;
counter_8 = v8 * a1 + v3;
if ( v8 + level_9 > 0x7FFF )
{
level_9 = 0x7FFF;
return 0x7FFF;
}
}
else
{
if ( level_9 <= 4587 )
return v1;
v5 = (int)(float)((float)(level_9 - 4587) / *(float *)&pc4_discharge_time);
v3 = counter_8 - v5;
if ( counter_8 - v5 > 0 )
goto LABEL_4;
v6 = (v5 - counter_8) / a1 + 1;
v7 = level_9 - v6;
counter_8 = v3 + v6 * a1;
if ( level_9 - v6 <= 4586 )
{
level_9 = 4587;
return 4587;
}
}
level_9 = v7;
return v7;
}

original_code:
static inline int update_c_pc4(int samplerate)
{
 static int counter, level = (int)(32767 * 7 / 50);
 if (sound_latch_c & 0x10)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pc4_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (level > (int)(32767 * 7 / 50))
  {
   counter -= (int)((level - (int)(32767 * 7 / 50)) / pc4_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level -= n) < (int)(32767 * 7 / 50) )
     level = (int)(32767 * 7 / 50);
   }
  }
 }
 return level;
}

canonical_original_code:
static inline int update_c_pc4(int samplerate)
{
 static int counter; static int level = (int)(32767 * 7 / 50);
 if (sound_latch_c & 0x10)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pc4_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (level > (int)(32767 * 7 / 50))
  {
   counter -= (int)((level - (int)(32767 * 7 / 50)) / pc4_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level -= n) < (int)(32767 * 7 / 50) )
     level = (int)(32767 * 7 / 50);
   }
  }
 }
 return level;
}

variable_types: samplerate int

variable_types: counter int

variable_types: level int

variable_types: n int

return_type: int


decompiled_code:
__int64 __fastcall update_c_pc5(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // ecx
int v6; // eax
int v7; // er8
int v8; // eax

v1 = level_7;
if ( (sound_latch_c & 0x20) != 0 )
{
if ( level_7 > 32766 )
return v1;
v2 = (int)(float)((float)(0x7FFF - level_7) / *(float *)&pc5_charge_time);
v3 = counter_6 - v2;
if ( counter_6 - v2 > 0 )
{
counter_6 -= v2;
return v1;
}
v8 = (v2 - counter_6) / a1 + 1;
v7 = v8 + level_7;
counter_6 = v8 * a1 + v3;
if ( v8 + level_7 > 0x7FFF )
{
level_7 = 0x7FFF;
return 0x7FFF;
}
}
else
{
if ( level_7 <= 0 )
return v1;
v5 = counter_6;
v6 = (int)(float)((float)level_7 / *(float *)&pc5_discharge_time);
if ( counter_6 - v6 > 0 )
{
counter_6 -= v6;
return (unsigned int)level_7;
}
counter_6 = a1 + counter_6 - v6;
v7 = level_7 - ((v6 - v5) / a1 + 1);
if ( v7 < 0 )
{
level_7 = 0;
return 0;
}
}
level_7 = v7;
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // ecx
int v6; // eax
int v7; // er8
int v8; // eax

v1 = level_7;
if ( (sound_latch_c & 0x20) != 0 )
{
if ( level_7 > 32766 )
return v1;
v2 = (int)(float)((float)(0x7FFF - level_7) / *(float *)&pc5_charge_time);
v3 = counter_6 - v2;
if ( counter_6 - v2 > 0 )
{
counter_6 -= v2;
return v1;
}
v8 = (v2 - counter_6) / a1 + 1;
v7 = v8 + level_7;
counter_6 = v8 * a1 + v3;
if ( v8 + level_7 > 0x7FFF )
{
level_7 = 0x7FFF;
return 0x7FFF;
}
}
else
{
if ( level_7 <= 0 )
return v1;
v5 = counter_6;
v6 = (int)(float)((float)level_7 / *(float *)&pc5_discharge_time);
if ( counter_6 - v6 > 0 )
{
counter_6 -= v6;
return (unsigned int)level_7;
}
counter_6 = a1 + counter_6 - v6;
v7 = level_7 - ((v6 - v5) / a1 + 1);
if ( v7 < 0 )
{
level_7 = 0;
return 0;
}
}
level_7 = v7;
return (unsigned int)v7;
}

original_code:
static inline int update_c_pc5(int samplerate)
{
 static int counter, level;
 if (sound_latch_c & 0x20)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pc5_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (level > 0)
  {
   counter -= (int)((level - 0) / pc5_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += samplerate;
    if( (level -= n) < 0 )
     level = 0;
   }
  }
 }
 return level;
}

canonical_original_code:
static inline int update_c_pc5(int samplerate)
{
 static int counter; static int level;
 if (sound_latch_c & 0x20)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pc5_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (level > 0)
  {
   counter -= (int)((level - 0) / pc5_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += samplerate;
    if( (level -= n) < 0 )
     level = 0;
   }
  }
 }
 return level;
}


decompiled_code:
__int64 __fastcall update_c_pa5(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // ecx
int v6; // eax
int v7; // er8
int v8; // eax

v1 = level_5;
if ( (sound_latch_a & 0x20) != 0 )
{
if ( level_5 > 32766 )
return v1;
v2 = (int)(float)((float)(0x7FFF - level_5) / *(float *)&pa5_charge_time);
v3 = counter_4 - v2;
if ( counter_4 - v2 > 0 )
{
counter_4 -= v2;
return v1;
}
v8 = (v2 - counter_4) / a1 + 1;
v7 = v8 + level_5;
counter_4 = v8 * a1 + v3;
if ( v8 + level_5 > 0x7FFF )
{
level_5 = 0x7FFF;
return 0x7FFF;
}
}
else
{
if ( level_5 <= 0 )
return v1;
v5 = counter_4;
v6 = (int)(float)((float)level_5 / *(float *)&pa5_discharge_time);
if ( counter_4 - v6 > 0 )
{
counter_4 -= v6;
return (unsigned int)level_5;
}
counter_4 = a1 + counter_4 - v6;
v7 = level_5 - ((v6 - v5) / a1 + 1);
if ( v7 < 0 )
{
level_5 = 0;
return 0;
}
}
level_5 = v7;
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // ecx
int v6; // eax
int v7; // er8
int v8; // eax

v1 = level_5;
if ( (sound_latch_a & 0x20) != 0 )
{
if ( level_5 > 32766 )
return v1;
v2 = (int)(float)((float)(0x7FFF - level_5) / *(float *)&pa5_charge_time);
v3 = counter_4 - v2;
if ( counter_4 - v2 > 0 )
{
counter_4 -= v2;
return v1;
}
v8 = (v2 - counter_4) / a1 + 1;
v7 = v8 + level_5;
counter_4 = v8 * a1 + v3;
if ( v8 + level_5 > 0x7FFF )
{
level_5 = 0x7FFF;
return 0x7FFF;
}
}
else
{
if ( level_5 <= 0 )
return v1;
v5 = counter_4;
v6 = (int)(float)((float)level_5 / *(float *)&pa5_discharge_time);
if ( counter_4 - v6 > 0 )
{
counter_4 -= v6;
return (unsigned int)level_5;
}
counter_4 = a1 + counter_4 - v6;
v7 = level_5 - ((v6 - v5) / a1 + 1);
if ( v7 < 0 )
{
level_5 = 0;
return 0;
}
}
level_5 = v7;
return (unsigned int)v7;
}

original_code:
static inline int update_c_pa5(int samplerate)
{
 static int counter, level;
 if (sound_latch_a & 0x20)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pa5_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (level > 0)
  {
   counter -= (int)((level - 0) / pa5_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += samplerate;
    if( (level -= n) < 0 )
     level = 0;
   }
  }
 }
 return level;
}

canonical_original_code:
static inline int update_c_pa5(int samplerate)
{
 static int counter; static int level;
 if (sound_latch_a & 0x20)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pa5_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (level > 0)
  {
   counter -= (int)((level - 0) / pa5_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += samplerate;
    if( (level -= n) < 0 )
     level = 0;
   }
  }
 }
 return level;
}


decompiled_code:
__int64 __fastcall tone4(int a1)
{
int v1; // esi
int v2; // er9
int v3; // er9
int v4; // edi
int v5; // er9
int v6; // er10
int v7; // ecx
int v8; // eax
int v9; // er8
int v10; // ecx
int v11; // eax
int v12; // ecx
__int64 result; // rax

v1 = update_c_pc4(a1);
update_c_pc5(v2);
v4 = update_c_pa5(v3);
v7 = polybit_resistor + opamp_resistor;
if ( polybit )
v8 = v1 + opamp_resistor * (0x7FFF - v1) / v7;
else
v8 = v1 * polybit_resistor / v7;
v9 = output_10;
v10 = counter_11 - tone4_max_freq * v8 / 0x8000;
counter_11 = v10;
if ( v10 <= 0 )
{
v11 = -v10 / v5 + 1;
v9 = ((_BYTE)v11 + (_BYTE)output_10) & 1;
output_10 = v9;
counter_11 = v10 + v11 * v5;
}
v12 = v6 * pa5_resistor / (pa5_resistor + pc5_resistor);
result = (unsigned int)(v12 + v4 * pc5_resistor / (pa5_resistor + pc5_resistor));
if ( !v9 )
result = (unsigned int)-(v12 + v4 * pc5_resistor / (pa5_resistor + pc5_resistor));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // esi
int v2; // er9
int v3; // er9
int v4; // edi
int v5; // er9
int v6; // er10
int v7; // ecx
int v8; // eax
int v9; // er8
int v10; // ecx
int v11; // eax
int v12; // ecx
__int64 result; // rax

v1 = func4(a1);
func5(v2);
v4 = func6(v3);
v7 = polybit_resistor + opamp_resistor;
if ( polybit )
v8 = v1 + opamp_resistor * (0x7FFF - v1) / v7;
else
v8 = v1 * polybit_resistor / v7;
v9 = output_10;
v10 = counter_11 - tone4_max_freq * v8 / 0x8000;
counter_11 = v10;
if ( v10 <= 0 )
{
v11 = -v10 / v5 + 1;
v9 = ((_BYTE)v11 + (_BYTE)output_10) & 1;
output_10 = v9;
counter_11 = v10 + v11 * v5;
}
v12 = v6 * pa5_resistor / (pa5_resistor + pc5_resistor);
result = (unsigned int)(v12 + v4 * pc5_resistor / (pa5_resistor + pc5_resistor));
if ( !v9 )
result = (unsigned int)-(v12 + v4 * pc5_resistor / (pa5_resistor + pc5_resistor));
return result;
}

original_code:
static inline int tone4(int samplerate)
{
 static int counter, output;
 int level = update_c_pc4(samplerate);
 int vpc5 = update_c_pc5(samplerate);
 int vpa5 = update_c_pa5(samplerate);
 int sum;
 if (polybit)
  level = level + (32767 - level) * opamp_resistor / (opamp_resistor + polybit_resistor);
 else
  level = level * polybit_resistor / (opamp_resistor + polybit_resistor);
 counter -= tone4_max_freq * level / 32768;
 if( counter <= 0 )
 {
  int n = (-counter / samplerate) + 1;
  counter += n * samplerate;
  output = (output + n) & 1;
 }
 sum = vpc5 * pa5_resistor / (pa5_resistor + pc5_resistor) +
    vpa5 * pc5_resistor / (pa5_resistor + pc5_resistor);
 return (output) ? sum : -sum;
}

canonical_original_code:
static inline int tone4(int samplerate)
{
 static int counter; static int output;
 int level = update_c_pc4(samplerate);
 int vpc5 = update_c_pc5(samplerate);
 int vpa5 = update_c_pa5(samplerate);
 int sum;
 if (polybit)
  level = level + (32767 - level) * opamp_resistor / (opamp_resistor + polybit_resistor);
 else
  level = level * polybit_resistor / (opamp_resistor + polybit_resistor);
 counter -= tone4_max_freq * level / 32768;
 if( counter <= 0 )
 {
  int n = (-counter / samplerate) + 1;
  counter += n * samplerate;
  output = (output + n) & 1;
 }
 sum = vpc5 * pa5_resistor / (pa5_resistor + pc5_resistor) +
    vpa5 * pc5_resistor / (pa5_resistor + pc5_resistor);
 return (output) ? sum : -sum;
}

variable_types: output int


decompiled_code:
__int64 __fastcall update_c_pa6(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // eax
int v6; // eax
int v7; // eax

v1 = level_1;
if ( (sound_latch_a & 0x40) != 0 )
{
if ( level_1 <= 32766 )
{
v2 = (int)(float)((float)(0x7FFF - level_1) / *(float *)&pa6_charge_time);
v3 = counter_0 - v2;
if ( counter_0 - v2 > 0 )
{
LABEL_4:
counter_0 = v3;
return v1;
}
v7 = (v2 - counter_0) / a1 + 1;
v1 = v7 + level_1;
counter_0 = v7 * a1 + v3;
if ( v7 + level_1 > 0x7FFF )
{
level_1 = 0x7FFF;
return 0x7FFF;
}
LABEL_10:
level_1 = v1;
return v1;
}
}
else if ( polybit && level_1 > 0 )
{
v5 = (int)((double)level_1 / 0.1);
v3 = counter_0 - v5;
if ( counter_0 - v5 > 0 )
goto LABEL_4;
v6 = (v5 - counter_0) / a1 + 1;
counter_0 = v3 + v6 * a1;
v1 = level_1 - v6;
if ( level_1 - v6 < 0 )
{
level_1 = 0;
return 0;
}
goto LABEL_10;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // er8
int v2; // eax
int v3; // ecx
int v5; // eax
int v6; // eax
int v7; // eax

v1 = level_1;
if ( (sound_latch_a & 0x40) != 0 )
{
if ( level_1 <= 32766 )
{
v2 = (int)(float)((float)(0x7FFF - level_1) / *(float *)&pa6_charge_time);
v3 = counter_0 - v2;
if ( counter_0 - v2 > 0 )
{
LABEL_4:
counter_0 = v3;
return v1;
}
v7 = (v2 - counter_0) / a1 + 1;
v1 = v7 + level_1;
counter_0 = v7 * a1 + v3;
if ( v7 + level_1 > 0x7FFF )
{
level_1 = 0x7FFF;
return 0x7FFF;
}
LABEL_10:
level_1 = v1;
return v1;
}
}
else if ( polybit && level_1 > 0 )
{
v5 = (int)((double)level_1 / 0.1);
v3 = counter_0 - v5;
if ( counter_0 - v5 > 0 )
goto LABEL_4;
v6 = (v5 - counter_0) / a1 + 1;
counter_0 = v3 + v6 * a1;
v1 = level_1 - v6;
if ( level_1 - v6 < 0 )
{
level_1 = 0;
return 0;
}
goto LABEL_10;
}
return v1;
}

original_code:
static inline int update_c_pa6(int samplerate)
{
 static int counter, level;
 if (sound_latch_a & 0x40)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pa6_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (polybit && level > 0)
  {
   counter -= (int)((level - 0) / 0.1);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level -= n) < 0 )
     level = 0;
   }
  }
 }
 return level;
}

canonical_original_code:
static inline int update_c_pa6(int samplerate)
{
 static int counter; static int level;
 if (sound_latch_a & 0x40)
 {
  if (level < 32767)
  {
   counter -= (int)((32767 - level) / pa6_charge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level += n) > 32767 )
     level = 32767;
   }
  }
 }
 else
 {
  if (polybit && level > 0)
  {
   counter -= (int)((level - 0) / 0.1);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level -= n) < 0 )
     level = 0;
   }
  }
 }
 return level;
}


decompiled_code:
__int64 __fastcall pleiads_sound_update(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbp
int v7; // eax
int v8; // er11

result = Machine;
v4 = *(_DWORD *)(Machine + 836LL);
if ( a3 > 0 )
{
v5 = a2;
v6 = a2 + 2LL * a3;
do
{
v5 += 2LL;
tone1(v4);
tone23(v4);
tone4(v4);
v7 = noise(v4);
result = clip_short_ret(v8 + v7);
*(_WORD *)(v5 - 2) = result;
}
while ( v5 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbp
int v7; // eax
int v8; // er11

result = Machine;
v4 = *(_DWORD *)(Machine + 836LL);
if ( a3 > 0 )
{
v5 = a2;
v6 = a2 + 2LL * a3;
do
{
v5 += 2LL;
func1(v4);
func3(v4);
func7(v4);
v7 = func9(v4);
result = func0(v8 + v7);
*(_WORD *)(v5 - 2) = result;
}
while ( v5 != v6 );
}
return result;
}

original_code:
static void pleiads_sound_update(int param, INT16 *buffer, int length)
{
 int rate = Machine->sample_rate;
 while( length-- > 0 )
 {
  int sum = tone1(rate)/2 + tone23(rate)/2 + tone4(rate) + noise(rate);
        *buffer++ = _clip_short_ret(sum);
 }
}

canonical_original_code:
static void pleiads_sound_update(int param, short *buffer, int length)
{
 int rate = Machine->sample_rate;
 while( length-- > 0 )
 {
  int sum = tone1(rate)/2 + tone23(rate)/2 + tone4(rate) + noise(rate);
        *buffer++ = _clip_short_ret(sum);
 }
}

variable_types: param int

variable_types:
buffer
short *

variable_types: length int

variable_types: rate int

return_type: void


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

if ( sound_latch_a != a2 )
{
result = stream_update((unsigned int)channel, 0LL);
sound_latch_a = a2;
}
return result;
}

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

if ( sound_latch_a != a2 )
{
result = stream_update((unsigned int)channel, 0LL);
sound_latch_a = a2;
}
return result;
}

original_code:
void pleiads_sound_control_a_w(offs_t offset,data_t data)
{
 if (data == sound_latch_a)
  return;
 stream_update(channel,0);
 sound_latch_a = data;
}

canonical_original_code:
void pleiads_sound_control_a_w(unsigned int offset, unsigned int data)
{
 if (data == sound_latch_a)
  return;
 stream_update(channel,0);
 sound_latch_a = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall pleiads_sound_control_b_w(__int64 a1, int a2)
{
__int64 v3; // rdx
__int64 v4; // rsi
__int64 result; // rax

v3 = a2 & 0xF;
v4 = (unsigned __int8)a2 >> 6;
if ( sound_latch_b != a2 )
{
if ( (_DWORD)v4 == 3 )
v4 = 2LL;
tms36xx_note_w(0LL, v4, v3);
result = stream_update((unsigned int)channel, 0LL);
sound_latch_b = a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 v3; // rdx
__int64 v4; // rsi
__int64 result; // rax

v3 = a2 & 0xF;
v4 = (unsigned __int8)a2 >> 6;
if ( sound_latch_b != a2 )
{
if ( (_DWORD)v4 == 3 )
v4 = 2LL;
tms36xx_note_w(0LL, v4, v3);
result = stream_update((unsigned int)channel, 0LL);
sound_latch_b = a2;
}
return result;
}

original_code:
void pleiads_sound_control_b_w(offs_t offset,data_t data)
{
 int note = data & 15;
 int pitch = (data >> 6) & 3;
 if (data == sound_latch_b)
  return;
 if (pitch == 3)
  pitch = 2;
 tms36xx_note_w(0, pitch, note);
 stream_update(channel,0);
 sound_latch_b = data;
}

canonical_original_code:
void pleiads_sound_control_b_w(unsigned int offset, unsigned int data)
{
 int note = data & 15;
 int pitch = (data >> 6) & 3;
 if (data == sound_latch_b)
  return;
 if (pitch == 3)
  pitch = 2;
 tms36xx_note_w(0, pitch, note);
 stream_update(channel,0);
 sound_latch_b = data;
}

variable_types: note int

variable_types: pitch int


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

if ( sound_latch_c != a2 )
{
result = stream_update((unsigned int)channel, 0LL);
sound_latch_c = a2;
}
return result;
}

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

if ( sound_latch_c != a2 )
{
result = stream_update((unsigned int)channel, 0LL);
sound_latch_c = a2;
}
return result;
}

original_code:
void pleiads_sound_control_c_w(offs_t offset,data_t data)
{
 if (data == sound_latch_c)
  return;
 stream_update(channel,0);
 sound_latch_c = data;
}

canonical_original_code:
void pleiads_sound_control_c_w(unsigned int offset, unsigned int data)
{
 if (data == sound_latch_c)
  return;
 stream_update(channel,0);
 sound_latch_c = data;
}


decompiled_code:
_BOOL8 pleiads_sh_start()
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pc4_charge_time = 1032268546;
pc4_discharge_time = 1018444120;
pc5_charge_time = 995640528;
pa5_resistor = 33;
pc5_resistor = 47;
tone2_max_freq = 351;
tone3_max_freq = 582;
tone4_max_freq = 1315;
polybit_resistor = 47;
opamp_resistor = 20;
noise_freq = 1412;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc5_discharge_time = LC4;
return common_sh_start_constprop_0((__int64)"Custom (Pleiads)");
}

canonical_decompiled_code:
_BOOL8 func15()
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pc4_charge_time = 1032268546;
pc4_discharge_time = 1018444120;
pc5_charge_time = 995640528;
pa5_resistor = 33;
pc5_resistor = 47;
tone2_max_freq = 351;
tone3_max_freq = 582;
tone4_max_freq = 1315;
polybit_resistor = 47;
opamp_resistor = 20;
noise_freq = 1412;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc5_discharge_time = LC4;
return func11((__int64)"Custom (Pleiads)");
}

original_code:
int pleiads_sh_start(const struct MachineSound *msound)
{
 pa5_charge_time = 3.3;
 pa5_discharge_time = 2.2;
 pa6_charge_time = 0.000726;
 pa6_discharge_time = 0.022;
 pb4_charge_time = 0.1;
 pb4_discharge_time = 0.1;
 pc4_charge_time = 0.066;
 pc4_discharge_time = 0.022;
 pc5_charge_time = 0.0033;
 pc5_discharge_time = 0.1;
 pa5_resistor = 33;
 pc5_resistor = 47;
 tone2_max_freq = 351;
 tone3_max_freq = 582;
 tone4_max_freq = 1315;
 polybit_resistor = 47;
 opamp_resistor = 20;
 noise_freq = 1412;
 return common_sh_start(msound, "Custom (Pleiads)");
}

canonical_original_code:
int pleiads_sh_start(struct MachineSound *msound)
{
 pa5_charge_time = 3.3;
 pa5_discharge_time = 2.2;
 pa6_charge_time = 0.000726;
 pa6_discharge_time = 0.022;
 pb4_charge_time = 0.1;
 pb4_discharge_time = 0.1;
 pc4_charge_time = 0.066;
 pc4_discharge_time = 0.022;
 pc5_charge_time = 0.0033;
 pc5_discharge_time = 0.1;
 pa5_resistor = 33;
 pc5_resistor = 47;
 tone2_max_freq = 351;
 tone3_max_freq = 582;
 tone4_max_freq = 1315;
 polybit_resistor = 47;
 opamp_resistor = 20;
 noise_freq = 1412;
 return common_sh_start(msound, "Custom (Pleiads)");
}

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


decompiled_code:
_BOOL8 naughtyb_sh_start()
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pc4_charge_time = 1056964608;
pc4_discharge_time = 1045220557;
pc5_charge_time = 995640528;
pa5_resistor = 100;
pc5_resistor = 78;
tone2_max_freq = 351;
tone3_max_freq = 322;
tone4_max_freq = 1315;
polybit_resistor = 47;
opamp_resistor = 20;
noise_freq = 713;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc5_discharge_time = LC4;
return common_sh_start_constprop_0((__int64)"Custom (Naughty Boy)");
}

canonical_decompiled_code:
_BOOL8 func16()
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pc4_charge_time = 1056964608;
pc4_discharge_time = 1045220557;
pc5_charge_time = 995640528;
pa5_resistor = 100;
pc5_resistor = 78;
tone2_max_freq = 351;
tone3_max_freq = 322;
tone4_max_freq = 1315;
polybit_resistor = 47;
opamp_resistor = 20;
noise_freq = 713;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc5_discharge_time = LC4;
return func11((__int64)"Custom (Naughty Boy)");
}

original_code:
int naughtyb_sh_start(const struct MachineSound *msound)
{
 pa5_charge_time = 3.3;
 pa5_discharge_time = 2.2;
 pa6_charge_time = 0.000726;
 pa6_discharge_time = 0.022;
 pb4_charge_time = 0.1;
 pb4_discharge_time = 0.1;
 pc4_charge_time = 0.05 * 10;
 pc4_discharge_time = 0.02 * 10;
 pc5_charge_time = 0.0033;
 pc5_discharge_time = 0.1;
 pa5_resistor = 100;
 pc5_resistor = 78;
 tone2_max_freq = 351;
 tone3_max_freq = 322;
 tone4_max_freq = 1315;
 polybit_resistor = 47;
 opamp_resistor = 20;
 noise_freq = 713;
 return common_sh_start(msound, "Custom (Naughty Boy)");
}

canonical_original_code:
int naughtyb_sh_start(struct MachineSound *msound)
{
 pa5_charge_time = 3.3;
 pa5_discharge_time = 2.2;
 pa6_charge_time = 0.000726;
 pa6_discharge_time = 0.022;
 pb4_charge_time = 0.1;
 pb4_discharge_time = 0.1;
 pc4_charge_time = 0.05 * 10;
 pc4_discharge_time = 0.02 * 10;
 pc5_charge_time = 0.0033;
 pc5_discharge_time = 0.1;
 pa5_resistor = 100;
 pc5_resistor = 78;
 tone2_max_freq = 351;
 tone3_max_freq = 322;
 tone4_max_freq = 1315;
 polybit_resistor = 47;
 opamp_resistor = 20;
 noise_freq = 713;
 return common_sh_start(msound, "Custom (Naughty Boy)");
}

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


decompiled_code:
_BOOL8 popflame_sh_start()
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pc4_charge_time = 964542817;
pc4_discharge_time = 963030989;
pc5_charge_time = 1046562734;
pc5_discharge_time = 1036831949;
pa5_resistor = 33;
pc5_resistor = 47;
tone2_max_freq = 1309;
tone3_max_freq = 1108;
tone4_max_freq = 1315;
polybit_resistor = 20;
opamp_resistor = 20;
noise_freq = 713;
pb4_charge_time = LC12;
pb4_discharge_time = LC12;
return common_sh_start_constprop_0((__int64)"Custom (Pop Flamer)");
}

canonical_decompiled_code:
_BOOL8 func17()
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pc4_charge_time = 964542817;
pc4_discharge_time = 963030989;
pc5_charge_time = 1046562734;
pc5_discharge_time = 1036831949;
pa5_resistor = 33;
pc5_resistor = 47;
tone2_max_freq = 1309;
tone3_max_freq = 1108;
tone4_max_freq = 1315;
polybit_resistor = 20;
opamp_resistor = 20;
noise_freq = 713;
pb4_charge_time = LC12;
pb4_discharge_time = LC12;
return func11((__int64)"Custom (Pop Flamer)");
}

original_code:
int popflame_sh_start(const struct MachineSound *msound)
{
 pa5_charge_time = 3.3;
 pa5_discharge_time = 2.2;
 pa6_charge_time = 0.000726;
 pa6_discharge_time = 0.022;
 pb4_charge_time = 0.02;
 pb4_discharge_time = 0.02;
 pc4_charge_time = 0.000242;
 pc4_discharge_time = 0.00022;
 pc5_charge_time = 0.22;
 pc5_discharge_time = 0.1;
 pa5_resistor = 33;
 pc5_resistor = 47;
 tone2_max_freq = 1309;
 tone3_max_freq = 1108;
 tone4_max_freq = 1315;
 polybit_resistor = 20;
 opamp_resistor = 20;
 noise_freq = 713;
 return common_sh_start(msound, "Custom (Pop Flamer)");
}

canonical_original_code:
int popflame_sh_start(struct MachineSound *msound)
{
 pa5_charge_time = 3.3;
 pa5_discharge_time = 2.2;
 pa6_charge_time = 0.000726;
 pa6_discharge_time = 0.022;
 pb4_charge_time = 0.02;
 pb4_discharge_time = 0.02;
 pc4_charge_time = 0.000242;
 pc4_discharge_time = 0.00022;
 pc5_charge_time = 0.22;
 pc5_discharge_time = 0.1;
 pa5_resistor = 33;
 pc5_resistor = 47;
 tone2_max_freq = 1309;
 tone3_max_freq = 1108;
 tone4_max_freq = 1315;
 polybit_resistor = 20;
 opamp_resistor = 20;
 noise_freq = 713;
 return common_sh_start(msound, "Custom (Pop Flamer)");
}


decompiled_code:
void pleiads_sh_stop()
{
if ( poly18 )
free(poly18);
poly18 = 0LL;
}

canonical_decompiled_code:
void func18()
{
if ( poly18 )
free(poly18);
poly18 = 0LL;
}

original_code:
void pleiads_sh_stop(void)
{
 if( poly18 )
  free(poly18);
 poly18 = ((void *)0);
}

canonical_original_code:
void pleiads_sh_stop()
{
 if( poly18 )
  free(poly18);
 poly18 = ((void *)0);
}


decompiled_code:
__int64 pleiads_sh_update()
{
return stream_update((unsigned int)channel, 0LL);
}

canonical_decompiled_code:
__int64 func19()
{
return stream_update((unsigned int)channel, 0LL);
}

original_code:
void pleiads_sh_update(void)
{
 stream_update(channel, 0);
}

canonical_original_code:
void pleiads_sh_update()
{
 stream_update(channel, 0);
}


original_code:
static inline int tone1(int samplerate)
{
 static int counter, divisor, output;
 if( (sound_latch_a & 15) != 15 )
 {
  counter -= 8000;
  while( counter <= 0 )
  {
   counter += samplerate;
   if( ++divisor == 16 )
   {
    divisor = sound_latch_a & 15;
    output ^= 1;
   }
  }
 }
 return output ? 32767 : -32767;
}

canonical_original_code:
static inline int tone1(int samplerate)
{
 static int counter; static int divisor; static int output;
 if( (sound_latch_a & 15) != 15 )
 {
  counter -= 8000;
  while( counter <= 0 )
  {
   counter += samplerate;
   if( ++divisor == 16 )
   {
    divisor = sound_latch_a & 15;
    output ^= 1;
   }
  }
 }
 return output ? 32767 : -32767;
}

variable_types: divisor int


noise

decompiled_code:
__int64 __fastcall noise(int a1)
{
int v1; // esi
int v2; // er9
int v3; // eax
int v4; // edx
int v5; // er8
int v6; // ecx
int v7; // er9
int v8; // ecx
__int64 result; // rax
int v10; // ecx

v1 = update_c_pa6(a1);
v3 = noise_freq;
if ( (sound_latch_a & 0x10) != 0 )
v3 = 2 * noise_freq;
v4 = polybit;
v5 = v3 / -3 + counter_3;
counter_3 = v5;
if ( v5 <= 0 )
{
v6 = -v5 / v2 + 1;
v7 = v6 * v2;
v8 = polyoffs_2 + v6;
counter_3 = v7 + v5;
polyoffs_2 = v8 & 0x3FFFF;
v4 = (*((_DWORD *)poly18 + ((v8 & 0x3FFFF) >> 5)) >> v8) & 1;
polybit = v4;
}
if ( v4 )
{
if ( (sound_latch_a & 0x80) != 0 )
v1 += 0x7FFF;
result = (unsigned int)(v1 / 2);
}
else
{
v10 = -v1;
if ( (sound_latch_a & 0x80) != 0 )
v10 = -32767 - v1;
result = (unsigned int)(v10 / 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // esi
int v2; // er9
int v3; // eax
int v4; // edx
int v5; // er8
int v6; // ecx
int v7; // er9
int v8; // ecx
__int64 result; // rax
int v10; // ecx

v1 = func8(a1);
v3 = noise_freq;
if ( (sound_latch_a & 0x10) != 0 )
v3 = 2 * noise_freq;
v4 = polybit;
v5 = v3 / -3 + counter_3;
counter_3 = v5;
if ( v5 <= 0 )
{
v6 = -v5 / v2 + 1;
v7 = v6 * v2;
v8 = polyoffs_2 + v6;
counter_3 = v7 + v5;
polyoffs_2 = v8 & 0x3FFFF;
v4 = (*((_DWORD *)poly18 + ((v8 & 0x3FFFF) >> 5)) >> v8) & 1;
polybit = v4;
}
if ( v4 )
{
if ( (sound_latch_a & 0x80) != 0 )
v1 += 0x7FFF;
result = (unsigned int)(v1 / 2);
}
else
{
v10 = -v1;
if ( (sound_latch_a & 0x80) != 0 )
v10 = -32767 - v1;
result = (unsigned int)(v10 / 2);
}
return result;
}

original_code:
static inline int noise(int samplerate)
{
 static int counter, polyoffs;
 int c_pa6_level = update_c_pa6(samplerate);
 int sum = 0;
 if ( sound_latch_a & 0x10 )
  counter -= noise_freq * 2 / 3;
 else
  counter -= noise_freq * 1 / 3;
 if( counter <= 0 )
 {
  int n = (-counter / samplerate) + 1;
  counter += n * samplerate;
  polyoffs = (polyoffs + n) & 0x3ffff;
  polybit = (poly18[polyoffs>>5] >> (polyoffs & 31)) & 1;
 }
 if (polybit)
 {
  sum += c_pa6_level;
  if (sound_latch_a & 0x80)
   sum += 32767;
 }
 else
 {
  sum -= c_pa6_level;
  if (sound_latch_a & 0x80)
   sum -= 32767;
 }
 return sum / 2;
}

canonical_original_code:
static inline int noise(int samplerate)
{
 static int counter; static int polyoffs;
 int c_pa6_level = update_c_pa6(samplerate);
 int sum = 0;
 if ( sound_latch_a & 0x10 )
  counter -= noise_freq * 2 / 3;
 else
  counter -= noise_freq * 1 / 3;
 if( counter <= 0 )
 {
  int n = (-counter / samplerate) + 1;
  counter += n * samplerate;
  polyoffs = (polyoffs + n) & 0x3ffff;
  polybit = (poly18[polyoffs>>5] >> (polyoffs & 31)) & 1;
 }
 if (polybit)
 {
  sum += c_pa6_level;
  if (sound_latch_a & 0x80)
   sum += 32767;
 }
 else
 {
  sum -= c_pa6_level;
  if (sound_latch_a & 0x80)
   sum -= 32767;
 }
 return sum / 2;
}

variable_types: polyoffs int


decompiled_code:
__int64 __fastcall popeye_videoram_w(unsigned int a1, int a2)
{
unsigned int v2; // eax
__int64 result; // rax
_BYTE *v4; // rdi
_BYTE *v5; // rdi

v2 = *(unsigned __int8 *)(popeye_videoram + a1);
if ( (a2 & 0x80u) == 0 )
{
result = a2 ^ v2;
if ( (result & 0xF) != 0 )
{
*((_BYTE *)dirtybuffer2 + a1) = 1;
v5 = (_BYTE *)(popeye_videoram + a1);
result = *v5 & 0xF0;
*v5 = *v5 & 0xF0 | a2 & 0xF;
}
}
else
{
result = (unsigned __int8)v2 & 0xF0;
if ( (_DWORD)result != (unsigned __int8)(16 * a2) )
{
*((_BYTE *)dirtybuffer2 + a1) = 1;
v4 = (_BYTE *)(popeye_videoram + a1);
result = *v4 & 0xF;
*v4 = result | (16 * a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2)
{
unsigned int v2; // eax
__int64 result; // rax
_BYTE *v4; // rdi
_BYTE *v5; // rdi

v2 = *(unsigned __int8 *)(popeye_videoram + a1);
if ( (a2 & 0x80u) == 0 )
{
result = a2 ^ v2;
if ( (result & 0xF) != 0 )
{
*((_BYTE *)dirtybuffer2 + a1) = 1;
v5 = (_BYTE *)(popeye_videoram + a1);
result = *v5 & 0xF0;
*v5 = *v5 & 0xF0 | a2 & 0xF;
}
}
else
{
result = (unsigned __int8)v2 & 0xF0;
if ( (_DWORD)result != (unsigned __int8)(16 * a2) )
{
*((_BYTE *)dirtybuffer2 + a1) = 1;
v4 = (_BYTE *)(popeye_videoram + a1);
result = *v4 & 0xF;
*v4 = result | (16 * a2);
}
}
return result;
}

original_code:
void popeye_videoram_w(offs_t offset,data_t data)
{
 if (data & 0x80)
 {
  if ((popeye_videoram[offset] & 0xf0) != ((data << 4) & 0xf0))
  {
   dirtybuffer2[offset] = 1;
   popeye_videoram[offset] = (popeye_videoram[offset] & 0x0f) | ((data << 4) & 0xf0);
  }
 }
 else
 {
  if ((popeye_videoram[offset] & 0x0f) != (data & 0x0f))
  {
   dirtybuffer2[offset] = 1;
   popeye_videoram[offset] = (popeye_videoram[offset] & 0xf0) | (data & 0x0f);
  }
 }
}

canonical_original_code:
void popeye_videoram_w(unsigned int offset, unsigned int data)
{
 if (data & 0x80)
 {
  if ((popeye_videoram[offset] & 0xf0) != ((data << 4) & 0xf0))
  {
   dirtybuffer2[offset] = 1;
   popeye_videoram[offset] = (popeye_videoram[offset] & 0x0f) | ((data << 4) & 0xf0);
  }
 }
 else
 {
  if ((popeye_videoram[offset] & 0x0f) != (data & 0x0f))
  {
   dirtybuffer2[offset] = 1;
   popeye_videoram[offset] = (popeye_videoram[offset] & 0xf0) | (data & 0x0f);
  }
 }
}


decompiled_code:
void __fastcall popeye_portB_w(__int64 a1, unsigned int a2)
{
dswbit = (a2 >> 1) & 7;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
dswbit = (a2 >> 1) & 7;
}

original_code:
static void popeye_portB_w(offs_t offset,data_t data)
{
 dswbit = (data & 0x0e) >> 1;
}

canonical_original_code:
static void popeye_portB_w(unsigned int offset, unsigned int data)
{
 dswbit = (data & 0x0e) >> 1;
}


decompiled_code:
__int64 popeye_vh_start()
{
unsigned int v0; // er12
size_t v2; // r13
void *v3; // rdi

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

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12
size_t v2; // r13
void *v3; // rdi

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

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

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


decompiled_code:
__int64 popeye_vh_stop()
{
void *v0; // rdi

bitmap_free(tmpbitmap2);
v0 = dirtybuffer2;
free(dirtybuffer2);
return generic_vh_stop(v0);
}

canonical_decompiled_code:
__int64 func4()
{
void *v0; // rdi

bitmap_free(tmpbitmap2);
v0 = dirtybuffer2;
free(dirtybuffer2);
return generic_vh_stop(v0);
}

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

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


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

v1 = input_port_3_r();
return v1 | ((unsigned int)input_port_4_r(a1) << (7 - dswbit)) & 0x80;
}

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

v1 = input_port_3_r();
return v1 | ((unsigned int)input_port_4_r(a1) << (7 - dswbit)) & 0x80;
}

original_code:
static data_t popeye_portA_r(offs_t offset)
{
 int res;
 res = input_port_3_r(offset);
 res |= (input_port_4_r(offset) << (7-dswbit)) & 0x80;
 return res;
}

canonical_original_code:
static unsigned int popeye_portA_r(unsigned int offset)
{
 int res;
 res = input_port_3_r(offset);
 res |= (input_port_4_r(offset) << (7-dswbit)) & 0x80;
 return res;
}

variable_types: res int

return_type: unsigned int


decompiled_code:
void __fastcall ssio_status_w(__int64 a1, char a2)
{
ssio_status = a2;
}

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

original_code:
static void ssio_status_w(offs_t offset,data_t data)
{
 ssio_status = data;
}

canonical_original_code:
static void ssio_status_w(unsigned int offset, unsigned int data)
{
 ssio_status = data;
}


decompiled_code:
__int64 __fastcall ssio_data_r(unsigned int a1)
{
return *((unsigned __int8 *)&ssio_data + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return *((unsigned __int8 *)&ssio_data + a1);
}

original_code:
static data_t ssio_data_r(offs_t offset)
{
 return ssio_data[offset];
}

canonical_original_code:
static unsigned int ssio_data_r(unsigned int offset)
{
 return ssio_data[offset];
}


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

result = a1 >> 8;
*((_BYTE *)&ssio_data + result) = a1;
return result;
}

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

result = a1 >> 8;
*((_BYTE *)&ssio_data + result) = a1;
return result;
}

original_code:
static void ssio_delayed_data_w(int param)
{
 ssio_data[param >> 8] = param & 0xff;
}


decompiled_code:
void squawkntalk_porta1_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


decompiled_code:
void __fastcall squawkntalk_porta2_w(__int64 a1, char a2)
{
squawkntalk_tms_command = a2;
}

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

original_code:
static void squawkntalk_porta2_w(offs_t offset,data_t data)
{
 squawkntalk_tms_command = data;
}

canonical_original_code:
static void squawkntalk_porta2_w(unsigned int offset, unsigned int data)
{
 squawkntalk_tms_command = data;
}


decompiled_code:
__int64 ssio_update_volumes()
{
__int64 i; // rbp
char v1; // dl
__int64 v2; // rsi
__int64 j; // rbp
char v4; // dl
__int64 v5; // rsi
__int64 result; // rax

for ( i = 0LL; i != 3; ++i )
{
v1 = ssio_duty_cycle[i];
v2 = (unsigned int)i;
AY8910_set_volume(0LL, v2, 100 * ((unsigned __int8)v1 ^ 0xFu) / 0xFuLL);
}
for ( j = 0LL; j != 3; ++j )
{
v4 = byte_7D3[j];
v5 = (unsigned int)j;
result = AY8910_set_volume(1LL, v5, 100 * ((unsigned __int8)v4 ^ 0xFu) / 0xFuLL);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 i; // rbp
char v1; // dl
__int64 v2; // rsi
__int64 j; // rbp
char v4; // dl
__int64 v5; // rsi
__int64 result; // rax

for ( i = 0LL; i != 3; ++i )
{
v1 = ssio_duty_cycle[i];
v2 = (unsigned int)i;
AY8910_set_volume(0LL, v2, 100 * ((unsigned __int8)v1 ^ 0xFu) / 0xFuLL);
}
for ( j = 0LL; j != 3; ++j )
{
v4 = byte_7D3[j];
v5 = (unsigned int)j;
result = AY8910_set_volume(1LL, v5, 100 * ((unsigned __int8)v4 ^ 0xFu) / 0xFuLL);
}
return result;
}

original_code:
static void ssio_update_volumes(void)
{
 int chip, chan;
 for (chip = 0; chip < 2; chip++)
  for (chan = 0; chan < 3; chan++)
   AY8910_set_volume(chip, chan, (ssio_duty_cycle[chip][chan] ^ 15) * 100 / 15);
}

canonical_original_code:
static void ssio_update_volumes()
{
 int chip; int chan;
 for (chip = 0; chip < 2; chip++)
  for (chan = 0; chan < 3; chan++)
   AY8910_set_volume(chip, chan, (ssio_duty_cycle[chip][chan] ^ 15) * 100 / 15);
}

variable_types: chip int

variable_types: chan int


decompiled_code:
__int64 __fastcall ssio_portb1_w(__int64 a1, unsigned int a2)
{
byte_7D5 = a2 & 0xF;
mixer_sound_enable_global_w(((unsigned __int8)(a2 >> 7) ^ 1) & 1);
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
byte_7D5 = a2 & 0xF;
mixer_sound_enable_global_w(((unsigned __int8)(a2 >> 7) ^ 1) & 1);
return func5();
}

original_code:
static void ssio_portb1_w(offs_t offset,data_t data)
{
 ssio_duty_cycle[1][2] = data & 15;
 mixer_sound_enable_global_w(!(data & 0x80));
 ssio_update_volumes();
}

canonical_original_code:
static void ssio_portb1_w(unsigned int offset, unsigned int data)
{
 ssio_duty_cycle[1][2] = data & 15;
 mixer_sound_enable_global_w(!(data & 0x80));
 ssio_update_volumes();
}


decompiled_code:
__int64 __fastcall ssio_portb0_w(__int64 a1, char a2)
{
byte_7D2 = a2 & 0xF;
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char a2)
{
byte_7D2 = a2 & 0xF;
return func5();
}

original_code:
static void ssio_portb0_w(offs_t offset,data_t data)
{
 ssio_duty_cycle[0][2] = data & 15;
 ssio_update_volumes();
}

canonical_original_code:
static void ssio_portb0_w(unsigned int offset, unsigned int data)
{
 ssio_duty_cycle[0][2] = data & 15;
 ssio_update_volumes();
}


decompiled_code:
__int64 __fastcall ssio_porta1_w(__int64 a1, unsigned int a2)
{
byte_7D4 = a2 >> 4;
byte_7D3[0] = a2 & 0xF;
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
byte_7D4 = a2 >> 4;
byte_7D3[0] = a2 & 0xF;
return func5();
}

original_code:
static void ssio_porta1_w(offs_t offset,data_t data)
{
 ssio_duty_cycle[1][0] = data & 15;
 ssio_duty_cycle[1][1] = data >> 4;
 ssio_update_volumes();
}

canonical_original_code:
static void ssio_porta1_w(unsigned int offset, unsigned int data)
{
 ssio_duty_cycle[1][0] = data & 15;
 ssio_duty_cycle[1][1] = data >> 4;
 ssio_update_volumes();
}


decompiled_code:
__int64 __fastcall ssio_porta0_w(__int64 a1, unsigned int a2)
{
byte_7D1 = a2 >> 4;
ssio_duty_cycle[0] = a2 & 0xF;
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
byte_7D1 = a2 >> 4;
ssio_duty_cycle[0] = a2 & 0xF;
return func5();
}

original_code:
static void ssio_porta0_w(offs_t offset,data_t data)
{
 ssio_duty_cycle[0][0] = data & 15;
 ssio_duty_cycle[0][1] = data >> 4;
 ssio_update_volumes();
}

canonical_original_code:
static void ssio_porta0_w(unsigned int offset, unsigned int data)
{
 ssio_duty_cycle[0][0] = data & 15;
 ssio_duty_cycle[0][1] = data >> 4;
 ssio_update_volumes();
}


decompiled_code:
__int64 __fastcall csdeluxe_delayed_data_w(char a1)
{
pia_0_portb_w(0LL, a1 & 0xF);
return pia_0_ca1_w(0LL, ~a1 & 0x10);
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
pia_0_portb_w(0LL, a1 & 0xF);
return pia_0_ca1_w(0LL, ~a1 & 0x10);
}

original_code:
static void csdeluxe_delayed_data_w(int param)
{
 pia_0_portb_w(0, param & 0x0f);
 pia_0_ca1_w(0, ~param & 0x10);
}


decompiled_code:
__int64 __fastcall turbocs_delayed_data_w(int a1)
{
pia_0_portb_w(0LL, (a1 >> 1) & 0xF);
return pia_0_ca1_w(0LL, (a1 & 1) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
pia_0_portb_w(0LL, (a1 >> 1) & 0xF);
return pia_0_ca1_w(0LL, (a1 & 1) == 0);
}

original_code:
static void turbocs_delayed_data_w(int param)
{
 pia_0_portb_w(0, (param >> 1) & 0x0f);
 pia_0_ca1_w(0, ~param & 0x01);
}


decompiled_code:
__int64 __fastcall csdeluxe_irq(int a1)
{
return cpu_set_irq_line((unsigned __int8)csdeluxe_sound_cpu, 4LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return cpu_set_irq_line((unsigned __int8)csdeluxe_sound_cpu, 4LL, a1 != 0);
}

original_code:
static void csdeluxe_irq(int state)
{
   cpu_set_irq_line(csdeluxe_sound_cpu, 4, state ? 1 : 0);
}

variable_types: state int


decompiled_code:
__int64 __fastcall soundsgood_irq(int a1)
{
return cpu_set_irq_line((unsigned __int8)soundsgood_sound_cpu, 4LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return cpu_set_irq_line((unsigned __int8)soundsgood_sound_cpu, 4LL, a1 != 0);
}

original_code:
static void soundsgood_irq(int state)
{
   cpu_set_irq_line(soundsgood_sound_cpu, 4, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall turbocs_irq(int a1)
{
return cpu_set_irq_line((unsigned __int8)turbocs_sound_cpu, 0LL, a1 != 0);
}

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

original_code:
static void turbocs_irq(int state)
{
 cpu_set_irq_line(turbocs_sound_cpu, 0, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall squawkntalk_irq(int a1)
{
return cpu_set_irq_line((unsigned __int8)squawkntalk_sound_cpu, 0LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return cpu_set_irq_line((unsigned __int8)squawkntalk_sound_cpu, 0LL, a1 != 0);
}

original_code:
static void squawkntalk_irq(int state)
{
 cpu_set_irq_line(squawkntalk_sound_cpu, 0, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall csdeluxe_portb_w(__int64 a1, unsigned int a2)
{
dacval = (a2 >> 6) | dacval & 0xFFFC;
return DAC_signed_data_16_w((unsigned __int8)csdeluxe_dac_index, (unsigned __int16)dacval << 6);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned int a2)
{
dacval = (a2 >> 6) | dacval & 0xFFFC;
return DAC_signed_data_16_w((unsigned __int8)csdeluxe_dac_index, (unsigned __int16)dacval << 6);
}

original_code:
static void csdeluxe_portb_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(csdeluxe_dac_index, dacval << 6);
}

canonical_original_code:
static void csdeluxe_portb_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(csdeluxe_dac_index, dacval << 6);
}


decompiled_code:
__int64 __fastcall csdeluxe_porta_w(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)csdeluxe_dac_index, (unsigned __int16)dacval << 6);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)csdeluxe_dac_index, (unsigned __int16)dacval << 6);
}

original_code:
static void csdeluxe_porta_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(csdeluxe_dac_index, dacval << 6);
}

canonical_original_code:
static void csdeluxe_porta_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(csdeluxe_dac_index, dacval << 6);
}


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

dacval = (a2 >> 6) | dacval & 0xFFFC;
result = DAC_signed_data_16_w((unsigned __int8)soundsgood_dac_index, (unsigned __int16)dacval << 6);
soundsgood_status = (a2 >> 4) & 3;
return result;
}

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

dacval = (a2 >> 6) | dacval & 0xFFFC;
result = DAC_signed_data_16_w((unsigned __int8)soundsgood_dac_index, (unsigned __int16)dacval << 6);
soundsgood_status = (a2 >> 4) & 3;
return result;
}

original_code:
static void soundsgood_portb_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(soundsgood_dac_index, dacval << 6);
 soundsgood_status = (data >> 4) & 3;
}

canonical_original_code:
static void soundsgood_portb_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(soundsgood_dac_index, dacval << 6);
 soundsgood_status = (data >> 4) & 3;
}


decompiled_code:
__int64 __fastcall soundsgood_porta_w(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)soundsgood_dac_index, (unsigned __int16)dacval << 6);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)soundsgood_dac_index, (unsigned __int16)dacval << 6);
}

original_code:
static void soundsgood_porta_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(soundsgood_dac_index, dacval << 6);
}

canonical_original_code:
static void soundsgood_porta_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(soundsgood_dac_index, dacval << 6);
}


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

dacval = (a2 >> 6) | dacval & 0xFFFC;
result = DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
turbocs_status = (a2 >> 4) & 3;
return result;
}

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

dacval = (a2 >> 6) | dacval & 0xFFFC;
result = DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
turbocs_status = (a2 >> 4) & 3;
return result;
}

original_code:
static void turbocs_portb_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
 turbocs_status = (data >> 4) & 3;
}

canonical_original_code:
static void turbocs_portb_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
 turbocs_status = (data >> 4) & 3;
}


decompiled_code:
__int64 __fastcall turbocs_porta_w(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
}

original_code:
static void turbocs_porta_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
}

canonical_original_code:
static void turbocs_porta_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
}


decompiled_code:
__int64 __fastcall soundsgood_delayed_data_w(int a1)
{
pia_1_portb_w(0LL, (a1 >> 1) & 0xF);
return pia_1_ca1_w(0LL, (a1 & 1) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1)
{
pia_1_portb_w(0LL, (a1 >> 1) & 0xF);
return pia_1_ca1_w(0LL, (a1 & 1) == 0);
}

original_code:
static void soundsgood_delayed_data_w(int param)
{
 pia_1_portb_w(0, (param >> 1) & 0x0f);
 pia_1_ca1_w(0, ~param & 0x01);
}


decompiled_code:
__int64 __fastcall squawkntalk_delayed_data_w(char a1)
{
pia_0_porta_w(0LL, ~a1 & 0xF);
return pia_0_cb1_w(0LL, ~a1 & 0x10);
}

canonical_decompiled_code:
__int64 __fastcall func23(char a1)
{
pia_0_porta_w(0LL, ~a1 & 0xF);
return pia_0_cb1_w(0LL, ~a1 & 0x10);
}

original_code:
static void squawkntalk_delayed_data_w(int param)
{
 pia_0_porta_w(0, ~param & 0x0f);
 pia_0_cb1_w(0, ~param & 0x10);
}


decompiled_code:
__int64 __fastcall squawkntalk_portb2_w(__int64 a1, char a2)
{
int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax

v2 = a2 & 3;
result = v2 ^ (unsigned int)(unsigned __int8)squawkntalk_tms_strobes;
if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 2) != 0 && (a2 & 2) == 0 )
{
tms5220_data_w(a1, (unsigned __int8)squawkntalk_tms_command);
}
else
{
if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 1) == 0 || (a2 & 1) != 0 )
{
squawkntalk_tms_strobes = a2 & 3;
return result;
}
v4 = tms5220_status_r();
pia_1_porta_w(0LL, v4);
}
pia_1_ca2_w(0LL, 1LL);
result = pia_1_ca2_w(0LL, 0LL);
squawkntalk_tms_strobes = a2 & 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, char a2)
{
int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax

v2 = a2 & 3;
result = v2 ^ (unsigned int)(unsigned __int8)squawkntalk_tms_strobes;
if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 2) != 0 && (a2 & 2) == 0 )
{
tms5220_data_w(a1, (unsigned __int8)squawkntalk_tms_command);
}
else
{
if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 1) == 0 || (a2 & 1) != 0 )
{
squawkntalk_tms_strobes = a2 & 3;
return result;
}
v4 = tms5220_status_r();
pia_1_porta_w(0LL, v4);
}
pia_1_ca2_w(0LL, 1LL);
result = pia_1_ca2_w(0LL, 0LL);
squawkntalk_tms_strobes = a2 & 3;
return result;
}

original_code:
static void squawkntalk_portb2_w(offs_t offset,data_t data)
{
 data &= 0x03;
 if (((data ^ squawkntalk_tms_strobes) & 0x02) && !(data & 0x02))
 {
  tms5220_data_w(offset, squawkntalk_tms_command);
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 else if (((data ^ squawkntalk_tms_strobes) & 0x01) && !(data & 0x01))
 {
  pia_1_porta_w(0, tms5220_status_r(offset));
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 squawkntalk_tms_strobes = data;
}

canonical_original_code:
static void squawkntalk_portb2_w(unsigned int offset, unsigned int data)
{
 data &= 0x03;
 if (((data ^ squawkntalk_tms_strobes) & 0x02) && !(data & 0x02))
 {
  tms5220_data_w(offset, squawkntalk_tms_command);
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 else if (((data ^ squawkntalk_tms_strobes) & 0x01) && !(data & 0x01))
 {
  pia_1_porta_w(0, tms5220_status_r(offset));
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 squawkntalk_tms_strobes = data;
}


decompiled_code:
__int64 __fastcall ssio_data_w(int a1, unsigned __int8 a2)
{
return timer_set(0LL, (a1 << 8) | (unsigned int)a2, ssio_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func25(int a1, unsigned __int8 a2)
{
return timer_set(0LL, (a1 << 8) | (unsigned int)a2, ssio_delayed_data_w);
}

original_code:
void ssio_data_w(offs_t offset,data_t data)
{
 timer_set((0), (offset << 8) | (data & 0xff), ssio_delayed_data_w);
}

canonical_original_code:
void ssio_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), (offset << 8) | (data & 0xff), ssio_delayed_data_w);
}


decompiled_code:
__int64 ssio_status_r()
{
return (unsigned __int8)ssio_status;
}

canonical_decompiled_code:
__int64 func26()
{
return (unsigned __int8)ssio_status;
}

original_code:
data_t ssio_status_r(offs_t offset)
{
 return ssio_status;
}

canonical_original_code:
unsigned int ssio_status_r(unsigned int offset)
{
 return ssio_status;
}


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

if ( !a1 )
return cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 0LL);
result = cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 1LL);
ssio_status = 0;
ssio_data = 0;
return result;
}

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

if ( !a1 )
return cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 0LL);
result = cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 1LL);
ssio_status = 0;
ssio_data = 0;
return result;
}

original_code:
void ssio_reset_w(int state)
{
 if (state)
 {
  int i;
  cpu_set_reset_line(ssio_sound_cpu, 1);
  for (i = 0; i < 4; i++)
   ssio_data[i] = 0;
  ssio_status = 0;
 }
 else
  cpu_set_reset_line(ssio_sound_cpu, 0);
}

variable_types: i int


decompiled_code:
__int64 __fastcall csdeluxe_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, csdeluxe_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, csdeluxe_delayed_data_w);
}

original_code:
void csdeluxe_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, csdeluxe_delayed_data_w);
}

canonical_original_code:
void csdeluxe_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, csdeluxe_delayed_data_w);
}


decompiled_code:
__int64 __fastcall csdeluxe_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)csdeluxe_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func29(int a1)
{
return cpu_set_reset_line((unsigned __int8)csdeluxe_sound_cpu, a1 != 0);
}

original_code:
void csdeluxe_reset_w(int state)
{
 cpu_set_reset_line(csdeluxe_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall soundsgood_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, soundsgood_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, soundsgood_delayed_data_w);
}

original_code:
void soundsgood_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, soundsgood_delayed_data_w);
}

canonical_original_code:
void soundsgood_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, soundsgood_delayed_data_w);
}


decompiled_code:
__int64 soundsgood_status_r()
{
return (unsigned __int8)soundsgood_status;
}

canonical_decompiled_code:
__int64 func31()
{
return (unsigned __int8)soundsgood_status;
}

original_code:
data_t soundsgood_status_r(offs_t offset)
{
 return soundsgood_status;
}

canonical_original_code:
unsigned int soundsgood_status_r(unsigned int offset)
{
 return soundsgood_status;
}


decompiled_code:
__int64 __fastcall soundsgood_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)soundsgood_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func32(int a1)
{
return cpu_set_reset_line((unsigned __int8)soundsgood_sound_cpu, a1 != 0);
}

original_code:
void soundsgood_reset_w(int state)
{
 cpu_set_reset_line(soundsgood_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall turbocs_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, turbocs_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func33(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, turbocs_delayed_data_w);
}

original_code:
void turbocs_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, turbocs_delayed_data_w);
}

canonical_original_code:
void turbocs_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, turbocs_delayed_data_w);
}


decompiled_code:
__int64 turbocs_status_r()
{
return (unsigned __int8)turbocs_status;
}

canonical_decompiled_code:
__int64 func34()
{
return (unsigned __int8)turbocs_status;
}

original_code:
data_t turbocs_status_r(offs_t offset)
{
 return turbocs_status;
}

canonical_original_code:
unsigned int turbocs_status_r(unsigned int offset)
{
 return turbocs_status;
}


decompiled_code:
__int64 __fastcall turbocs_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)turbocs_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func35(int a1)
{
return cpu_set_reset_line((unsigned __int8)turbocs_sound_cpu, a1 != 0);
}

original_code:
void turbocs_reset_w(int state)
{
 cpu_set_reset_line(turbocs_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall squawkntalk_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, squawkntalk_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func36(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, squawkntalk_delayed_data_w);
}

original_code:
void squawkntalk_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, squawkntalk_delayed_data_w);
}

canonical_original_code:
void squawkntalk_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, squawkntalk_delayed_data_w);
}


decompiled_code:
__int64 __fastcall squawkntalk_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)squawkntalk_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func37(int a1)
{
return cpu_set_reset_line((unsigned __int8)squawkntalk_sound_cpu, a1 != 0);
}

original_code:
void squawkntalk_reset_w(int state)
{
 cpu_set_reset_line(squawkntalk_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 mcr_sound_init()
{
unsigned int v0; // ebp
char v1; // al
char v2; // r12

v0 = 1;
v1 = mcr_sound_config;
if ( (mcr_sound_config & 1) != 0 )
{
ssio_sound_cpu = 1;
v0 = 2;
v2 = 0;
ssio_reset_w(1);
ssio_reset_w(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 8) == 0 )
{
LABEL_3:
if ( (v1 & 2) == 0 )
goto LABEL_4;
goto LABEL_10;
}
}
else
{
v2 = 0;
if ( (mcr_sound_config & 8) == 0 )
goto LABEL_3;
}
pia_config(0LL, 1LL, &turbocs_pia_intf);
turbocs_sound_cpu = v0++;
turbocs_dac_index = 0;
v2 = 1;
turbocs_reset_w(1);
turbocs_reset_w(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 2) == 0 )
{
LABEL_4:
if ( (v1 & 4) == 0 )
goto LABEL_5;
goto LABEL_11;
}
LABEL_10:
pia_config(0LL, 11LL, &csdeluxe_pia_intf);
csdeluxe_dac_index = v2++;
csdeluxe_sound_cpu = v0++;
csdeluxe_reset_w(1);
csdeluxe_reset_w(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 4) == 0 )
{
LABEL_5:
if ( (v1 & 0x10) == 0 )
goto LABEL_6;
LABEL_12:
pia_config(0LL, 0LL, &squawkntalk_pia0_intf);
pia_config(1LL, 0LL, &squawkntalk_pia1_intf);
squawkntalk_sound_cpu = v0++;
squawkntalk_reset_w(1);
squawkntalk_reset_w(0);
if ( (mcr_sound_config & 0x20) == 0 )
return pia_reset();
LABEL_13:
williams_cvsd_init(v0, 0LL);
williams_cvsd_reset_w(1LL);
williams_cvsd_reset_w(0LL);
return pia_reset();
}
LABEL_11:
pia_config(1LL, 7LL, &soundsgood_pia_intf);
soundsgood_dac_index = v2;
soundsgood_sound_cpu = v0++;
soundsgood_reset_w(1);
soundsgood_reset_w(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 0x10) != 0 )
goto LABEL_12;
LABEL_6:
if ( (v1 & 0x20) != 0 )
goto LABEL_13;
return pia_reset();
}

canonical_decompiled_code:
__int64 func38()
{
unsigned int v0; // ebp
char v1; // al
char v2; // r12

v0 = 1;
v1 = mcr_sound_config;
if ( (mcr_sound_config & 1) != 0 )
{
ssio_sound_cpu = 1;
v0 = 2;
v2 = 0;
func27(1);
func27(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 8) == 0 )
{
LABEL_3:
if ( (v1 & 2) == 0 )
goto LABEL_4;
goto LABEL_10;
}
}
else
{
v2 = 0;
if ( (mcr_sound_config & 8) == 0 )
goto LABEL_3;
}
pia_config(0LL, 1LL, &turbocs_pia_intf);
turbocs_sound_cpu = v0++;
turbocs_dac_index = 0;
v2 = 1;
func35(1);
func35(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 2) == 0 )
{
LABEL_4:
if ( (v1 & 4) == 0 )
goto LABEL_5;
goto LABEL_11;
}
LABEL_10:
pia_config(0LL, 11LL, &csdeluxe_pia_intf);
csdeluxe_dac_index = v2++;
csdeluxe_sound_cpu = v0++;
func29(1);
func29(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 4) == 0 )
{
LABEL_5:
if ( (v1 & 0x10) == 0 )
goto LABEL_6;
LABEL_12:
pia_config(0LL, 0LL, &squawkntalk_pia0_intf);
pia_config(1LL, 0LL, &squawkntalk_pia1_intf);
squawkntalk_sound_cpu = v0++;
func37(1);
func37(0);
if ( (mcr_sound_config & 0x20) == 0 )
return pia_reset();
LABEL_13:
williams_cvsd_init(v0, 0LL);
williams_cvsd_reset_w(1LL);
williams_cvsd_reset_w(0LL);
return pia_reset();
}
LABEL_11:
pia_config(1LL, 7LL, &soundsgood_pia_intf);
soundsgood_dac_index = v2;
soundsgood_sound_cpu = v0++;
func32(1);
func32(0);
v1 = mcr_sound_config;
if ( (mcr_sound_config & 0x10) != 0 )
goto LABEL_12;
LABEL_6:
if ( (v1 & 0x20) != 0 )
goto LABEL_13;
return pia_reset();
}

original_code:
void mcr_sound_init(void)
{
 int sound_cpu = 1;
 int dac_index = 0;
 if (mcr_sound_config & 0x01)
 {
  ssio_sound_cpu = sound_cpu++;
  ssio_reset_w(1);
  ssio_reset_w(0);
 }
 if (mcr_sound_config & 0x08)
 {
  pia_config(0, 1, &turbocs_pia_intf);
  turbocs_dac_index = dac_index++;
  turbocs_sound_cpu = sound_cpu++;
  turbocs_reset_w(1);
  turbocs_reset_w(0);
 }
 if (mcr_sound_config & 0x02)
 {
  pia_config(0, 1 | (2 | 8), &csdeluxe_pia_intf);
  csdeluxe_dac_index = dac_index++;
  csdeluxe_sound_cpu = sound_cpu++;
  csdeluxe_reset_w(1);
  csdeluxe_reset_w(0);
 }
 if (mcr_sound_config & 0x04)
 {
  pia_config(1, 1 | (2 | 4), &soundsgood_pia_intf);
  soundsgood_dac_index = dac_index++;
  soundsgood_sound_cpu = sound_cpu++;
  soundsgood_reset_w(1);
  soundsgood_reset_w(0);
 }
 if (mcr_sound_config & 0x10)
 {
  pia_config(0, 0 | 0, &squawkntalk_pia0_intf);
  pia_config(1, 0 | 0, &squawkntalk_pia1_intf);
  squawkntalk_sound_cpu = sound_cpu++;
  squawkntalk_reset_w(1);
  squawkntalk_reset_w(0);
 }
 if (mcr_sound_config & 0x20)
 {
  williams_cvsd_init(sound_cpu++, 0);
  dac_index++;
  williams_cvsd_reset_w(1);
  williams_cvsd_reset_w(0);
 }
 pia_reset();
}

canonical_original_code:
void mcr_sound_init()
{
 int sound_cpu = 1;
 int dac_index = 0;
 if (mcr_sound_config & 0x01)
 {
  ssio_sound_cpu = sound_cpu++;
  ssio_reset_w(1);
  ssio_reset_w(0);
 }
 if (mcr_sound_config & 0x08)
 {
  pia_config(0, 1, &turbocs_pia_intf);
  turbocs_dac_index = dac_index++;
  turbocs_sound_cpu = sound_cpu++;
  turbocs_reset_w(1);
  turbocs_reset_w(0);
 }
 if (mcr_sound_config & 0x02)
 {
  pia_config(0, 1 | (2 | 8), &csdeluxe_pia_intf);
  csdeluxe_dac_index = dac_index++;
  csdeluxe_sound_cpu = sound_cpu++;
  csdeluxe_reset_w(1);
  csdeluxe_reset_w(0);
 }
 if (mcr_sound_config & 0x04)
 {
  pia_config(1, 1 | (2 | 4), &soundsgood_pia_intf);
  soundsgood_dac_index = dac_index++;
  soundsgood_sound_cpu = sound_cpu++;
  soundsgood_reset_w(1);
  soundsgood_reset_w(0);
 }
 if (mcr_sound_config & 0x10)
 {
  pia_config(0, 0 | 0, &squawkntalk_pia0_intf);
  pia_config(1, 0 | 0, &squawkntalk_pia1_intf);
  squawkntalk_sound_cpu = sound_cpu++;
  squawkntalk_reset_w(1);
  squawkntalk_reset_w(0);
 }
 if (mcr_sound_config & 0x20)
 {
  williams_cvsd_init(sound_cpu++, 0);
  dac_index++;
  williams_cvsd_reset_w(1);
  williams_cvsd_reset_w(0);
 }
 pia_reset();
}


original_code:
void blueprnt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 16;i++)
 {
  (*palette++) = ((i >> 0) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 2) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 1) & 1) * ((i & 0x08) ? 0xbf : 0xff);
 }
 for (i = 0;i < 128;i++)
 {
  int base = (i & 0x40) ? 8 : 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+0]) = base + 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+1]) = base + ((i >> 0) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+2]) = base + ((i >> 3) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+3]) = base + (((i >> 0) & 7) | ((i >> 3) & 7));
 }
 for (i = 0;i < 8;i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = i;
}

canonical_original_code:
void blueprnt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 16;i++)
 {
  (*palette++) = ((i >> 0) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 2) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 1) & 1) * ((i & 0x08) ? 0xbf : 0xff);
 }
 for (i = 0;i < 128;i++)
 {
  int base = (i & 0x40) ? 8 : 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+0]) = base + 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+1]) = base + ((i >> 0) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+2]) = base + ((i >> 3) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+3]) = base + (((i >> 0) & 7) | ((i >> 3) & 7));
 }
 for (i = 0;i < 8;i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = i;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: base int


decompiled_code:
void __fastcall dipsw_w(__int64 a1, int a2)
{
dipsw = a2;
}

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

original_code:
static void dipsw_w(offs_t offset,data_t data)
{
 dipsw = data;
}

canonical_original_code:
static void dipsw_w(unsigned int offset, unsigned int data)
{
 dipsw = data;
}


decompiled_code:
__int64 blueprnt_sh_dipsw_r()
{
return (unsigned int)dipsw;
}

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

original_code:
data_t blueprnt_sh_dipsw_r(offs_t offset)
{
 return dipsw;
}

canonical_original_code:
unsigned int blueprnt_sh_dipsw_r(unsigned int offset)
{
 return dipsw;
}


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

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

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

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

original_code:
void blueprnt_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != (~data & 2))
 {
  flipscreen = ~data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
 if (gfx_bank != ((data & 4) >> 2))
 {
  gfx_bank = ((data & 4) >> 2);
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void blueprnt_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != (~data & 2))
 {
  flipscreen = ~data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
 if (gfx_bank != ((data & 4) >> 2))
 {
  gfx_bank = ((data & 4) >> 2);
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
void *__fastcall blueprnt_vh_screenrefresh(__int64 a1)
{
int v2; // er12
__int64 v3; // r13
int v4; // edx
int v5; // er9
__int64 v6; // rdx
__int64 i; // rax
unsigned __int64 v8; // r13
int v9; // edi
__int64 v10; // rdx
int v11; // ecx
__int64 v12; // r8
__int64 v13; // r9
void *result; // rax
int v15; // er13
__int64 v16; // r14
char v17; // cl
char v18; // di
int v19; // edx
int v20; // er10
unsigned __int8 *v21; // rax
char *v22; // rdx
int v23; // ecx
int v24[32]; // [rsp+10h] [rbp-B8h] BYREF
char v25; // [rsp+90h] [rbp-38h] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
*(_BYTE *)(v3 + dirtybuffer) = 0;
v4 = v2 & 0x1F;
v5 = v2 / -32 + 31;
if ( flipscreen )
{
v5 = v2 / 32;
v4 = 31 - v4;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(videoram + v3) + (gfx_bank << 8),
*(_BYTE *)(colorram + v3) & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v5),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v6 = blueprnt_scrollram;
if ( flipscreen )
{
for ( i = 0LL; i != -32; --i )
v24[i + 31] = *(unsigned __int8 *)(v6 + i + 32);
}
else
{
v21 = (unsigned __int8 *)(blueprnt_scrollram + 30LL);
v22 = (char *)v24;
do
{
v23 = *v21;
v22 += 4;
--v21;
*((_DWORD *)v22 - 1) = -v23;
}
while ( &v25 != v22 );
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v24, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v8 = 0LL;
do
{
v11 = *(unsigned __int8 *)(spriteram + v8 + 3);
v9 = *(unsigned __int8 *)(spriteram + v8);
v12 = *(_BYTE *)(spriteram + v8 + 2) & 0x40;
v13 = *(_BYTE *)(spriteram + v8 - 2) & 0x80;
if ( flipscreen )
{
v11 = 248 - v11;
v12 = (_DWORD)v12 == 0;
v13 = (_DWORD)v13 == 0;
}
else
{
v9 = 240 - v9;
}
v10 = *(unsigned __int8 *)(spriteram + v8 + 1);
v8 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v10,
0LL,
v12,
v13,
(unsigned int)(v11 + 2),
(unsigned int)(v9 - 1),
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v8 );
}
result = &videoram_size;
v15 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v16 = v15;
do
{
while ( 1 )
{
v17 = *(_BYTE *)(colorram + v16);
if ( v17 < 0 )
break;
--v15;
--v16;
if ( v15 == -1 )
return result;
}
v18 = v15 & 0x1F;
if ( flipscreen )
{
v19 = v15 / 32;
v18 = 31 - v18;
}
else
{
v19 = v15 / -32 + 31;
}
--v15;
v20 = *(unsigned __int8 *)(videoram + v16--);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)((gfx_bank << 8) + v20),
v17 & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v19),
(unsigned __int8)(v24[v19] + 8 * v18),
Machine + 776LL,
2LL,
0LL);
}
while ( v15 != -1 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
int v2; // er12
__int64 v3; // r13
int v4; // edx
int v5; // er9
__int64 v6; // rdx
__int64 i; // rax
unsigned __int64 v8; // r13
int v9; // edi
__int64 v10; // rdx
int v11; // ecx
__int64 v12; // r8
__int64 v13; // r9
void *result; // rax
int v15; // er13
__int64 v16; // r14
char v17; // cl
char v18; // di
int v19; // edx
int v20; // er10
unsigned __int8 *v21; // rax
char *v22; // rdx
int v23; // ecx
int v24[32]; // [rsp+10h] [rbp-B8h] BYREF
char v25; // [rsp+90h] [rbp-38h] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
*(_BYTE *)(v3 + dirtybuffer) = 0;
v4 = v2 & 0x1F;
v5 = v2 / -32 + 31;
if ( flipscreen )
{
v5 = v2 / 32;
v4 = 31 - v4;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(videoram + v3) + (gfx_bank << 8),
*(_BYTE *)(colorram + v3) & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v5),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v6 = blueprnt_scrollram;
if ( flipscreen )
{
for ( i = 0LL; i != -32; --i )
v24[i + 31] = *(unsigned __int8 *)(v6 + i + 32);
}
else
{
v21 = (unsigned __int8 *)(blueprnt_scrollram + 30LL);
v22 = (char *)v24;
do
{
v23 = *v21;
v22 += 4;
--v21;
*((_DWORD *)v22 - 1) = -v23;
}
while ( &v25 != v22 );
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v24, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v8 = 0LL;
do
{
v11 = *(unsigned __int8 *)(spriteram + v8 + 3);
v9 = *(unsigned __int8 *)(spriteram + v8);
v12 = *(_BYTE *)(spriteram + v8 + 2) & 0x40;
v13 = *(_BYTE *)(spriteram + v8 - 2) & 0x80;
if ( flipscreen )
{
v11 = 248 - v11;
v12 = (_DWORD)v12 == 0;
v13 = (_DWORD)v13 == 0;
}
else
{
v9 = 240 - v9;
}
v10 = *(unsigned __int8 *)(spriteram + v8 + 1);
v8 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v10,
0LL,
v12,
v13,
(unsigned int)(v11 + 2),
(unsigned int)(v9 - 1),
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v8 );
}
result = &videoram_size;
v15 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v16 = v15;
do
{
while ( 1 )
{
v17 = *(_BYTE *)(colorram + v16);
if ( v17 < 0 )
break;
--v15;
--v16;
if ( v15 == -1 )
return result;
}
v18 = v15 & 0x1F;
if ( flipscreen )
{
v19 = v15 / 32;
v18 = 31 - v18;
}
else
{
v19 = v15 / -32 + 31;
}
--v15;
v20 = *(unsigned __int8 *)(videoram + v16--);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)((gfx_bank << 8) + v20),
v17 & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v19),
(unsigned __int8)(v24[v19] + 8 * v18),
Machine + 776LL,
2LL,
0LL);
}
while ( v15 != -1 );
}
return result;
}

original_code:
void blueprnt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int scroll[32];
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i;
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = blueprnt_scrollram[32-i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -blueprnt_scrollram[30-i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs + 0];
  flipx = spriteram[offs + 2] & 0x40;
  flipy = spriteram[offs + 2 - 4] & 0x80;
  if (flipscreen)
  {
   sx = 248 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    0,
    flipx,flipy,
    2+sx,sy-1,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x80)
  {
   int sx,sy;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,(8*sy+scroll[sx]) & 0xff,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
void blueprnt_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int scroll[32];
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i;
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = blueprnt_scrollram[32-i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -blueprnt_scrollram[30-i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs + 0];
  flipx = spriteram[offs + 2] & 0x40;
  flipy = spriteram[offs + 2 - 4] & 0x80;
  if (flipscreen)
  {
   sx = 248 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    0,
    flipx,flipy,
    2+sx,sy-1,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x80)
  {
   int sx; int sy;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,(8*sy+scroll[sx]) & 0xff,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

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

variable_types: offs int

variable_types:
scroll
int [32]

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

if ( lastval_0 != a2 )
{
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
lastval_0 = a2;
}
return result;
}

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

if ( lastval_0 != a2 )
{
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
lastval_0 = a2;
}
return result;
}

original_code:
static void blueprnt_coin_w(offs_t offset,data_t data)
{
 static int lastval;
 if (lastval == data) return;
 coin_counter_w (0, data & 0x01);
 coin_counter_w (1, data & 0x02);
 lastval = data;
}

canonical_original_code:
static void blueprnt_coin_w(unsigned int offset, unsigned int data)
{
 static int lastval;
 if (lastval == data) return;
 coin_counter_w (0, data & 0x01);
 coin_counter_w (1, data & 0x02);
 lastval = data;
}

variable_types: lastval int


decompiled_code:
void __fastcall jedi_control_w(char a1)
{
jedi_control_num = a1;
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
jedi_control_num = a1;
}

original_code:
void jedi_control_w(offs_t offset,data_t data) {
    jedi_control_num = offset;
}

canonical_original_code:
void jedi_control_w(unsigned int offset, unsigned int data) {
    jedi_control_num = offset;
}


decompiled_code:
__int64 jedi_soundlatch_r()
{
jedi_com_stat &= 0x7Fu;
return jedi_soundlatch;
}

canonical_decompiled_code:
__int64 func3()
{
jedi_com_stat &= 0x7Fu;
return jedi_soundlatch;
}

original_code:
data_t jedi_soundlatch_r(offs_t offset) {
    jedi_com_stat &= 0x7F;
    return jedi_soundlatch;
}

canonical_original_code:
unsigned int jedi_soundlatch_r(unsigned int offset) {
    jedi_com_stat &= 0x7F;
    return jedi_soundlatch;
}


decompiled_code:
__int64 jedi_soundacklatch_r()
{
jedi_com_stat &= 0xBFu;
return jedi_soundacklatch;
}

canonical_decompiled_code:
__int64 func4()
{
jedi_com_stat &= 0xBFu;
return jedi_soundacklatch;
}

original_code:
data_t jedi_soundacklatch_r(offs_t offset) {
    jedi_com_stat &= 0xBF;
    return jedi_soundacklatch;
}

canonical_original_code:
unsigned int jedi_soundacklatch_r(unsigned int offset) {
    jedi_com_stat &= 0xBF;
    return jedi_soundacklatch;
}


decompiled_code:
__int64 jedi_soundstat_r()
{
return jedi_com_stat;
}

canonical_decompiled_code:
__int64 func5()
{
return jedi_com_stat;
}

original_code:
data_t jedi_soundstat_r(offs_t offset) {
    return jedi_com_stat;
}

canonical_original_code:
unsigned int jedi_soundstat_r(unsigned int offset) {
    return jedi_com_stat;
}


decompiled_code:
void __fastcall jedi_vscroll_w(int a1, int a2)
{
jedi_vscroll = a2 | (a1 << 8);
}

canonical_decompiled_code:
void __fastcall func6(int a1, int a2)
{
jedi_vscroll = a2 | (a1 << 8);
}

original_code:
void jedi_vscroll_w(offs_t offset,data_t data)
{
    jedi_vscroll = data | (offset << 8);
}

canonical_original_code:
void jedi_vscroll_w(unsigned int offset, unsigned int data)
{
    jedi_vscroll = data | (offset << 8);
}


decompiled_code:
void __fastcall jedi_hscroll_w(int a1, int a2)
{
jedi_hscroll = a2 | (a1 << 8);
}

canonical_decompiled_code:
void __fastcall func7(int a1, int a2)
{
jedi_hscroll = a2 | (a1 << 8);
}

original_code:
void jedi_hscroll_w(offs_t offset,data_t data)
{
    jedi_hscroll = data | (offset << 8);
}

canonical_original_code:
void jedi_hscroll_w(unsigned int offset, unsigned int data)
{
    jedi_hscroll = data | (offset << 8);
}


decompiled_code:
void __fastcall jedi_video_off_w(__int64 a1, int a2)
{
video_off = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
video_off = a2;
}

original_code:
void jedi_video_off_w(offs_t offset,data_t data)
{
 video_off = data;
}

canonical_original_code:
void jedi_video_off_w(unsigned int offset, unsigned int data)
{
 video_off = data;
}


decompiled_code:
void __fastcall jedi_PIXIRAM_w(__int64 a1, char a2)
{
smooth_table = a2 & 3;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char a2)
{
smooth_table = a2 & 3;
}

original_code:
void jedi_PIXIRAM_w(offs_t offset,data_t data)
{
 smooth_table = data & 0x03;
}

canonical_original_code:
void jedi_PIXIRAM_w(unsigned int offset, unsigned int data)
{
 smooth_table = data & 0x03;
}


decompiled_code:
char *__fastcall jedi_rom_banksel_w(__int64 a1, char a2)
{
char *result; // rax
char *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

result = (char *)memory_region(129LL);
v3 = result;
if ( (a2 & 1) != 0 )
{
cpu_bankbase[1] = result + 0x10000;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v5);
}
}
if ( (a2 & 2) != 0 )
{
cpu_bankbase[1] = v3 + 81920;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v6);
}
}
if ( (a2 & 4) != 0 )
{
cpu_bankbase[1] = v3 + 98304;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v4);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(__int64 a1, char a2)
{
char *result; // rax
char *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

result = (char *)memory_region(129LL);
v3 = result;
if ( (a2 & 1) != 0 )
{
cpu_bankbase[1] = result + 0x10000;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v5);
}
}
if ( (a2 & 2) != 0 )
{
cpu_bankbase[1] = v3 + 81920;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v6);
}
}
if ( (a2 & 4) != 0 )
{
cpu_bankbase[1] = v3 + 98304;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v4);
}
}
return result;
}

original_code:
void jedi_rom_banksel_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
    if (data & 0x01) { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
    if (data & 0x02) { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x14000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
    if (data & 0x04) { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x18000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void jedi_rom_banksel_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
    if (data & 0x01) { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
    if (data & 0x02) { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x14000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
    if (data & 0x04) { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x18000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *


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

if ( (a2 & 1) != 0 )
result = cpu_set_reset_line(1LL, 0LL);
else
result = cpu_set_reset_line(1LL, 1LL);
return result;
}

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

if ( (a2 & 1) != 0 )
result = cpu_set_reset_line(1LL, 0LL);
else
result = cpu_set_reset_line(1LL, 1LL);
return result;
}

original_code:
void jedi_sound_reset_w(offs_t offset,data_t data)
{
    if (data & 1)
  cpu_set_reset_line(1,0);
    else
  cpu_set_reset_line(1,1);
}

canonical_original_code:
void jedi_sound_reset_w(unsigned int offset, unsigned int data)
{
    if (data & 1)
  cpu_set_reset_line(1,0);
    else
  cpu_set_reset_line(1,1);
}


decompiled_code:
__int64 jedi_control_r()
{
if ( !jedi_control_num )
return readinputport(2LL);
if ( jedi_control_num == 2 )
return readinputport(3LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
if ( !jedi_control_num )
return readinputport(2LL);
if ( jedi_control_num == 2 )
return readinputport(3LL);
return 0LL;
}

original_code:
data_t jedi_control_r(offs_t offset) {
    if (jedi_control_num == 0)
        return readinputport (2);
    else if (jedi_control_num == 2)
        return readinputport (3);
    return 0;
}

canonical_original_code:
unsigned int jedi_control_r(unsigned int offset) {
    if (jedi_control_num == 0)
        return readinputport (2);
    else if (jedi_control_num == 2)
        return readinputport (3);
    return 0;
}


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

v0 = (int)jedi_com_stat >> 1;
return v0 & 0x60 | input_port_1_r(0LL) & 0x80 | 0x1B;
}

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

v0 = (int)jedi_com_stat >> 1;
return v0 & 0x60 | input_port_1_r(0LL) & 0x80 | 0x1B;
}

original_code:
data_t jedi_mainstat_r(offs_t offset) {
    unsigned char d;
    d = (jedi_com_stat & 0xC0) >> 1;
    d = d | (input_port_1_r(0) & 0x80);
    d = d | 0x1B;
    return d;
}

canonical_original_code:
unsigned int jedi_mainstat_r(unsigned int offset) {
    unsigned char d;
    d = (jedi_com_stat & 0xC0) >> 1;
    d = d | (input_port_1_r(0) & 0x80);
    d = d | 0x1B;
    return d;
}

variable_types:
d
unsigned char


decompiled_code:
__int64 __fastcall jedi_paletteram_w(unsigned int a1, char a2)
{
__int64 v3; // rdi
unsigned int v4; // edx

*(_BYTE *)(paletteram + a1) = a2;
v3 = a1 & 0x3FF;
v4 = *(unsigned __int8 *)(paletteram + (a1 | 0x400)) << 8;
return palette_change_color(
v3,
5 * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v4) >> 6) & 7) * ((v4 >> 9) & 7),
5 * ((v4 >> 9) & 7) * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v4) >> 3) & 7),
5 * ((v4 >> 9) & 7) * (*(_BYTE *)(paletteram + (unsigned int)v3) & 7));
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, char a2)
{
__int64 v3; // rdi
unsigned int v4; // edx

*(_BYTE *)(paletteram + a1) = a2;
v3 = a1 & 0x3FF;
v4 = *(unsigned __int8 *)(paletteram + (a1 | 0x400)) << 8;
return palette_change_color(
v3,
5 * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v4) >> 6) & 7) * ((v4 >> 9) & 7),
5 * ((v4 >> 9) & 7) * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v4) >> 3) & 7),
5 * ((v4 >> 9) & 7) * (*(_BYTE *)(paletteram + (unsigned int)v3) & 7));
}

original_code:
void jedi_paletteram_w(offs_t offset,data_t data)
{
    int r,g,b;
 int bits,intensity;
    unsigned int color;
 paletteram[offset] = data;
 color = paletteram[offset & 0x3FF] | (paletteram[offset | 0x400] << 8);
 intensity = (color >> 9) & 0x07;
 bits = (color >> 6) & 0x07;
 r = 5 * bits * intensity;
 bits = (color >> 3) & 0x07;
 g = 5 * bits * intensity;
 bits = (color >> 0) & 0x07;
 b = 5 * bits * intensity;
 palette_change_color (offset & 0x3ff,r,g,b);
}

canonical_original_code:
void jedi_paletteram_w(unsigned int offset, unsigned int data)
{
    int r; int g; int b;
 int bits; int intensity;
    unsigned int color;
 paletteram[offset] = data;
 color = paletteram[offset & 0x3FF] | (paletteram[offset | 0x400] << 8);
 intensity = (color >> 9) & 0x07;
 bits = (color >> 6) & 0x07;
 r = 5 * bits * intensity;
 bits = (color >> 3) & 0x07;
 g = 5 * bits * intensity;
 bits = (color >> 0) & 0x07;
 b = 5 * bits * intensity;
 palette_change_color (offset & 0x3ff,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: bits int

variable_types: intensity int

variable_types:
color
unsigned int


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

v2 = 2 * (a2 & 0x80);
if ( v2 != jedi_alpha_bank )
{
jedi_alpha_bank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

v2 = 2 * (a2 & 0x80);
if ( v2 != jedi_alpha_bank )
{
jedi_alpha_bank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void jedi_alpha_banksel_w(offs_t offset,data_t data)
{
 if (jedi_alpha_bank != 2*(data & 0x80))
 {
  jedi_alpha_bank = 2*(data & 0x80);
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void jedi_alpha_banksel_w(unsigned int offset, unsigned int data)
{
 if (jedi_alpha_bank != 2*(data & 0x80))
 {
  jedi_alpha_bank = 2*(data & 0x80);
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
__int64 jedi_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rbp
size_t v3; // r14
__int64 v5; // rdi

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
v2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
tmpbitmap = v2;
if ( !v2 )
{
LABEL_8:
free(dirtybuffer);
return 1LL;
}
v3 = jedi_backgroundram_size;
dirtybuffer2 = malloc(jedi_backgroundram_size);
if ( !dirtybuffer2 )
{
bitmap_free(v2);
goto LABEL_8;
}
memset(dirtybuffer2, 1, v3);
tmpbitmap2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
if ( tmpbitmap2 )
{
tmpbitmap3 = bitmap_alloc_depth(256LL, 256LL, 8LL);
if ( tmpbitmap3 )
{
palette_change_color(1024LL, 0LL, 0LL, 0LL);
return 0LL;
}
bitmap_free(tmpbitmap);
v5 = tmpbitmap2;
}
else
{
v5 = tmpbitmap;
}
bitmap_free(v5);
free(dirtybuffer);
free(dirtybuffer2);
return 1LL;
}

canonical_decompiled_code:
__int64 func16()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rbp
size_t v3; // r14
__int64 v5; // rdi

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
v2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
tmpbitmap = v2;
if ( !v2 )
{
LABEL_8:
free(dirtybuffer);
return 1LL;
}
v3 = jedi_backgroundram_size;
dirtybuffer2 = malloc(jedi_backgroundram_size);
if ( !dirtybuffer2 )
{
bitmap_free(v2);
goto LABEL_8;
}
memset(dirtybuffer2, 1, v3);
tmpbitmap2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
if ( tmpbitmap2 )
{
tmpbitmap3 = bitmap_alloc_depth(256LL, 256LL, 8LL);
if ( tmpbitmap3 )
{
palette_change_color(1024LL, 0LL, 0LL, 0LL);
return 0LL;
}
bitmap_free(tmpbitmap);
v5 = tmpbitmap2;
}
else
{
v5 = tmpbitmap;
}
bitmap_free(v5);
free(dirtybuffer);
free(dirtybuffer2);
return 1LL;
}

original_code:
int jedi_vh_start(void)
{
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
 {
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 if ((dirtybuffer2 = (unsigned char*)malloc(jedi_backgroundram_size)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  return 1;
 }
 memset(dirtybuffer2,1,jedi_backgroundram_size);
 if ((tmpbitmap2 = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 if ((tmpbitmap3 = bitmap_alloc_depth(256,256,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  bitmap_free(tmpbitmap2);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 palette_change_color(1024,0,0,0);
 return 0;
}

canonical_original_code:
int jedi_vh_start()
{
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
 {
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 if ((dirtybuffer2 = (unsigned char *)malloc(jedi_backgroundram_size)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  return 1;
 }
 memset(dirtybuffer2,1,jedi_backgroundram_size);
 if ((tmpbitmap2 = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 if ((tmpbitmap3 = bitmap_alloc_depth(256,256,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  bitmap_free(tmpbitmap2);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 palette_change_color(1024,0,0,0);
 return 0;
}


decompiled_code:
void jedi_vh_stop()
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
bitmap_free(tmpbitmap3);
free(dirtybuffer);
free(dirtybuffer2);
}

canonical_decompiled_code:
void func17()
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
bitmap_free(tmpbitmap3);
free(dirtybuffer);
free(dirtybuffer2);
}

original_code:
void jedi_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 bitmap_free(tmpbitmap2);
 bitmap_free(tmpbitmap3);
 free(dirtybuffer);
 free(dirtybuffer2);
}