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

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

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

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


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

konami_cpu_setlines_callback = surpratk_banking;
result = memory_region(129LL) + 294912;
paletteram = result;
return result;
}

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

konami_cpu_setlines_callback = surpratk_banking;
result = memory_region(129LL) + 294912;
paletteram = result;
return result;
}

original_code:
static void surpratk_init_machine( void )
{
 konami_cpu_setlines_callback = surpratk_banking;
 paletteram = &memory_region(REGION_CPU1)[0x48000];
}

canonical_original_code:
static void surpratk_init_machine()
{
 konami_cpu_setlines_callback = surpratk_banking;
 paletteram = &memory_region(REGION_CPU1)[0x48000];
}

return_type: void


decompiled_code:
void *__fastcall surpratk_banking(char a1)
{
__int64 v1; // rax
int v2; // edi
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((a1 & 0x1F) + 8) << 13;
if ( v2 > 294911 )
v2 -= 0x40000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

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

v1 = memory_region(129LL);
v2 = ((a1 & 0x1F) + 8) << 13;
if ( v2 > 294911 )
v2 -= 0x40000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

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

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

variable_types: lines int

variable_types:
RAM
unsigned char *

variable_types: offs int


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int surpratk_interrupt(void)
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int surpratk_interrupt()
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

return_type: int


decompiled_code:
__int64 __fastcall surpratk_5fc0_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
return K052109_set_RMRD_line((a2 & 8) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
return K052109_set_RMRD_line((a2 & 8) != 0);
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


irqhandler

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

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

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

variable_types: linestate int


decompiled_code:
__int64 __fastcall timer_callback_2610(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2610TimerOver((unsigned __int8)v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2610TimerOver((unsigned __int8)v2);
}

original_code:
static void timer_callback_2610(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 YM2610TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2610(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 YM2610TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2610UpdateRequest(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

original_code:
void YM2610UpdateRequest(int chip)
{
 stream_update(stream[chip],100);
}

variable_types: chip int


decompiled_code:
_BOOL8 __fastcall YM2610_sh_start(__int64 a1, __int64 a2)
{
unsigned int v2; // er14
_BOOL4 v3; // edx
int v6; // eax
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rbx
__int64 v10; // r13
unsigned int v11; // er12
const char *v12; // rax
const char *v13; // rax
__int64 v14; // r12
int v15[2]; // [rsp+10h] [rbp-D8h] BYREF
int v16[2]; // [rsp+18h] [rbp-D0h] BYREF
__int64 v17[2]; // [rsp+20h] [rbp-C8h] BYREF
__int64 v18[3]; // [rsp+30h] [rbp-B8h] BYREF
int v19[2]; // [rsp+48h] [rbp-A0h] BYREF
__int64 v20[2]; // [rsp+50h] [rbp-98h] BYREF
char s[40]; // [rsp+60h] [rbp-88h] BYREF
char v22[96]; // [rsp+88h] [rbp-60h] BYREF

v2 = *(_DWORD *)(Machine + 836LL);
intf = *(_QWORD *)(a1 + 8);
v3 = 1;
if ( *(int *)intf <= 2 )
{
v6 = AY8910_sh_start(a1, a2, 1LL);
v3 = 1;
if ( !v6 )
{
FMTimerInit();
v7 = intf;
v8 = *(unsigned int *)intf;
if ( (int)v8 > 0 )
{
v9 = 0LL;
do
{
v10 = (int)v9 + 60LL;
v11 = *(_DWORD *)(v7 + 4 * v10 + 8);
v20[0] = (__int64)s;
v19[0] = (unsigned __int16)v11;
v12 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v12, (unsigned int)v9, 1LL);
v20[1] = (__int64)v22;
v19[1] = HIWORD(v11);
v13 = (const char *)sound_name(a1);
sprintf(v22, "%s #%d Ch%d", v13, (unsigned int)v9, 2LL);
stream[v9] = stream_init_multi(2LL, v20, v19, v2, (unsigned int)v9, &YM2610UpdateOne);
v18[v9] = memory_region(*(unsigned int *)(intf + 4 * v10));
v16[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v10));
v14 = (int)v9 + 56LL;
v17[v9] = memory_region(*(unsigned int *)(intf + 4 * v14 + 8));
v15[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v14 + 8));
v7 = intf;
v8 = *(unsigned int *)intf;
++v9;
}
while ( (int)v8 > (int)v9 );
}
v3 = YM2610Init(v8, *(unsigned int *)(v7 + 4), v2, v18, v16, v17, v15, TimerHandler, IRQHandler) != 0;
}
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2)
{
unsigned int v2; // er14
_BOOL4 v3; // edx
int v6; // eax
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rbx
__int64 v10; // r13
unsigned int v11; // er12
const char *v12; // rax
const char *v13; // rax
__int64 v14; // r12
int v15[2]; // [rsp+10h] [rbp-D8h] BYREF
int v16[2]; // [rsp+18h] [rbp-D0h] BYREF
__int64 v17[2]; // [rsp+20h] [rbp-C8h] BYREF
__int64 v18[3]; // [rsp+30h] [rbp-B8h] BYREF
int v19[2]; // [rsp+48h] [rbp-A0h] BYREF
__int64 v20[2]; // [rsp+50h] [rbp-98h] BYREF
char s[40]; // [rsp+60h] [rbp-88h] BYREF
char v22[96]; // [rsp+88h] [rbp-60h] BYREF

v2 = *(_DWORD *)(Machine + 836LL);
intf = *(_QWORD *)(a1 + 8);
v3 = 1;
if ( *(int *)intf <= 2 )
{
v6 = AY8910_sh_start(a1, a2, 1LL);
v3 = 1;
if ( !v6 )
{
func0();
v7 = intf;
v8 = *(unsigned int *)intf;
if ( (int)v8 > 0 )
{
v9 = 0LL;
do
{
v10 = (int)v9 + 60LL;
v11 = *(_DWORD *)(v7 + 4 * v10 + 8);
v20[0] = (__int64)s;
v19[0] = (unsigned __int16)v11;
v12 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v12, (unsigned int)v9, 1LL);
v20[1] = (__int64)v22;
v19[1] = HIWORD(v11);
v13 = (const char *)sound_name(a1);
sprintf(v22, "%s #%d Ch%d", v13, (unsigned int)v9, 2LL);
stream[v9] = stream_init_multi(2LL, v20, v19, v2, (unsigned int)v9, &YM2610UpdateOne);
v18[v9] = memory_region(*(unsigned int *)(intf + 4 * v10));
v16[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v10));
v14 = (int)v9 + 56LL;
v17[v9] = memory_region(*(unsigned int *)(intf + 4 * v14 + 8));
v15[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v14 + 8));
v7 = intf;
v8 = *(unsigned int *)intf;
++v9;
}
while ( (int)v8 > (int)v9 );
}
v3 = YM2610Init(v8, *(unsigned int *)(v7 + 4), v2, v18, v16, v17, v15, TimerHandler, IRQHandler) != 0;
}
}
return v3;
}

original_code:
int YM2610_sh_start(const struct MachineSound *msound)
{
 int i,j;
 int rate = Machine->sample_rate;
 char buf[2][40];
 const char *name[2];
 int mixed_vol,vol[2];
 void *pcmbufa[2],*pcmbufb[2];
 int pcmsizea[2],pcmsizeb[2];
 intf = (const struct YM2610interface *)msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2610UpdateOne);
  pcmbufa[i] = (void *)(memory_region(intf->pcmroma[i]));
  pcmsizea[i] = memory_region_length(intf->pcmroma[i]);
  pcmbufb[i] = (void *)(memory_region(intf->pcmromb[i]));
  pcmsizeb[i] = memory_region_length(intf->pcmromb[i]);
 }
 if (YM2610Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,pcmbufb,pcmsizeb,
             TimerHandler,IRQHandler) == 0)
  return 0;
 return 1;
}

canonical_original_code:
int YM2610_sh_start(struct MachineSound *msound)
{
 int i; int j;
 int rate = Machine->sample_rate;
 char buf[2][40];
 char *name[2];
 int mixed_vol; int vol[2];
 void *pcmbufa[2]; void *pcmbufb[2];
 int pcmsizea[2]; int pcmsizeb[2];
 intf = (struct YM2610interface *)msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2610UpdateOne);
  pcmbufa[i] = (void *)(memory_region(intf->pcmroma[i]));
  pcmsizea[i] = memory_region_length(intf->pcmroma[i]);
  pcmbufb[i] = (void *)(memory_region(intf->pcmromb[i]));
  pcmsizeb[i] = memory_region_length(intf->pcmromb[i]);
 }
 if (YM2610Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,pcmbufb,pcmsizeb,
             TimerHandler,IRQHandler) == 0)
  return 0;
 return 1;
}

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

variable_types: i int

variable_types: j int

variable_types: rate int

variable_types:
buf
char [2][40]

variable_types:
name
char *[2]

variable_types:
vol
int [2]

variable_types:
pcmbufa
void *[2]

variable_types:
pcmbufb
void *[2]

variable_types:
pcmsizea
int [2]

variable_types:
pcmsizeb
int [2]

user_defined_types: struct YM2610interface { int num; int baseclock; int volumeSSG[5]; unsigned int (*portAread[5])(unsigned int offset); unsigned int (*portBread[5])(unsigned int offset); void (*portAwrite[5])(unsigned int offset, unsigned int data); void (*portBwrite[5])(unsigned int offset, unsigned int data); void (*handler[5])(int irq); int pcmromb[-1]; int pcmroma[-1]; int volumeFM[-1]; }


decompiled_code:
_BOOL8 __fastcall YM2610B_sh_start(__int64 a1, __int64 a2)
{
unsigned int v2; // er14
_BOOL4 v3; // edx
int v6; // eax
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rbx
__int64 v10; // r13
unsigned int v11; // er12
const char *v12; // rax
const char *v13; // rax
__int64 v14; // r12
int v15[2]; // [rsp+10h] [rbp-D8h] BYREF
int v16[2]; // [rsp+18h] [rbp-D0h] BYREF
__int64 v17[2]; // [rsp+20h] [rbp-C8h] BYREF
__int64 v18[3]; // [rsp+30h] [rbp-B8h] BYREF
int v19[2]; // [rsp+48h] [rbp-A0h] BYREF
__int64 v20[2]; // [rsp+50h] [rbp-98h] BYREF
char s[40]; // [rsp+60h] [rbp-88h] BYREF
char v22[96]; // [rsp+88h] [rbp-60h] BYREF

v2 = *(_DWORD *)(Machine + 836LL);
intf = *(_QWORD *)(a1 + 8);
v3 = 1;
if ( *(int *)intf <= 2 )
{
v6 = AY8910_sh_start(a1, a2, 1LL);
v3 = 1;
if ( !v6 )
{
FMTimerInit();
v7 = intf;
v8 = *(unsigned int *)intf;
if ( (int)v8 > 0 )
{
v9 = 0LL;
do
{
v10 = (int)v9 + 60LL;
v11 = *(_DWORD *)(v7 + 4 * v10 + 8);
v20[0] = (__int64)s;
v19[0] = (unsigned __int16)v11;
v12 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v12, (unsigned int)v9, 1LL);
v20[1] = (__int64)v22;
v19[1] = HIWORD(v11);
v13 = (const char *)sound_name(a1);
sprintf(v22, "%s #%d Ch%d", v13, (unsigned int)v9, 2LL);
stream[v9] = stream_init_multi(2LL, v20, v19, v2, (unsigned int)v9, &YM2610BUpdateOne);
v18[v9] = memory_region(*(unsigned int *)(intf + 4 * v10));
v16[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v10));
v14 = (int)v9 + 56LL;
v17[v9] = memory_region(*(unsigned int *)(intf + 4 * v14 + 8));
v15[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v14 + 8));
v7 = intf;
v8 = *(unsigned int *)intf;
++v9;
}
while ( (int)v8 > (int)v9 );
}
v3 = YM2610Init(v8, *(unsigned int *)(v7 + 4), v2, v18, v16, v17, v15, TimerHandler, IRQHandler) != 0;
}
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v2; // er14
_BOOL4 v3; // edx
int v6; // eax
__int64 v7; // rax
__int64 v8; // rdi
__int64 v9; // rbx
__int64 v10; // r13
unsigned int v11; // er12
const char *v12; // rax
const char *v13; // rax
__int64 v14; // r12
int v15[2]; // [rsp+10h] [rbp-D8h] BYREF
int v16[2]; // [rsp+18h] [rbp-D0h] BYREF
__int64 v17[2]; // [rsp+20h] [rbp-C8h] BYREF
__int64 v18[3]; // [rsp+30h] [rbp-B8h] BYREF
int v19[2]; // [rsp+48h] [rbp-A0h] BYREF
__int64 v20[2]; // [rsp+50h] [rbp-98h] BYREF
char s[40]; // [rsp+60h] [rbp-88h] BYREF
char v22[96]; // [rsp+88h] [rbp-60h] BYREF

v2 = *(_DWORD *)(Machine + 836LL);
intf = *(_QWORD *)(a1 + 8);
v3 = 1;
if ( *(int *)intf <= 2 )
{
v6 = AY8910_sh_start(a1, a2, 1LL);
v3 = 1;
if ( !v6 )
{
func0();
v7 = intf;
v8 = *(unsigned int *)intf;
if ( (int)v8 > 0 )
{
v9 = 0LL;
do
{
v10 = (int)v9 + 60LL;
v11 = *(_DWORD *)(v7 + 4 * v10 + 8);
v20[0] = (__int64)s;
v19[0] = (unsigned __int16)v11;
v12 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v12, (unsigned int)v9, 1LL);
v20[1] = (__int64)v22;
v19[1] = HIWORD(v11);
v13 = (const char *)sound_name(a1);
sprintf(v22, "%s #%d Ch%d", v13, (unsigned int)v9, 2LL);
stream[v9] = stream_init_multi(2LL, v20, v19, v2, (unsigned int)v9, &YM2610BUpdateOne);
v18[v9] = memory_region(*(unsigned int *)(intf + 4 * v10));
v16[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v10));
v14 = (int)v9 + 56LL;
v17[v9] = memory_region(*(unsigned int *)(intf + 4 * v14 + 8));
v15[v9] = memory_region_length(*(unsigned int *)(intf + 4 * v14 + 8));
v7 = intf;
v8 = *(unsigned int *)intf;
++v9;
}
while ( (int)v8 > (int)v9 );
}
v3 = YM2610Init(v8, *(unsigned int *)(v7 + 4), v2, v18, v16, v17, v15, TimerHandler, IRQHandler) != 0;
}
}
return v3;
}

original_code:
int YM2610B_sh_start(const struct MachineSound *msound)
{
 int i,j;
 int rate = Machine->sample_rate;
 char buf[2][40];
 const char *name[2];
 int mixed_vol,vol[2];
 void *pcmbufa[2],*pcmbufb[2];
 int pcmsizea[2],pcmsizeb[2];
 intf = (const struct YM2610interface *)msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2610BUpdateOne);
  pcmbufa[i] = (void *)(memory_region(intf->pcmroma[i]));
  pcmsizea[i] = memory_region_length(intf->pcmroma[i]);
  pcmbufb[i] = (void *)(memory_region(intf->pcmromb[i]));
  pcmsizeb[i] = memory_region_length(intf->pcmromb[i]);
 }
 if (YM2610Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,pcmbufb,pcmsizeb,
             TimerHandler,IRQHandler) == 0)
  return 0;
 return 1;
}

canonical_original_code:
int YM2610B_sh_start(struct MachineSound *msound)
{
 int i; int j;
 int rate = Machine->sample_rate;
 char buf[2][40];
 char *name[2];
 int mixed_vol; int vol[2];
 void *pcmbufa[2]; void *pcmbufb[2];
 int pcmsizea[2]; int pcmsizeb[2];
 intf = (struct YM2610interface *)msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2610BUpdateOne);
  pcmbufa[i] = (void *)(memory_region(intf->pcmroma[i]));
  pcmsizea[i] = memory_region_length(intf->pcmroma[i]);
  pcmbufb[i] = (void *)(memory_region(intf->pcmromb[i]));
  pcmsizeb[i] = memory_region_length(intf->pcmromb[i]);
 }
 if (YM2610Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,pcmbufb,pcmsizeb,
             TimerHandler,IRQHandler) == 0)
  return 0;
 return 1;
}

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


decompiled_code:
__int64 YM2610_sh_stop()
{
return YM2610Shutdown();
}

canonical_decompiled_code:
__int64 func5()
{
return YM2610Shutdown();
}

original_code:
void YM2610_sh_stop(void)
{
 YM2610Shutdown();
}

canonical_original_code:
void YM2610_sh_stop()
{
 YM2610Shutdown();
}


decompiled_code:
__int64 YM2610_sh_reset()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
YM2610ResetChip(v1++);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
YM2610ResetChip(v1++);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

original_code:
void YM2610_sh_reset(void)
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2610ResetChip(i);
}

canonical_original_code:
void YM2610_sh_reset()
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2610ResetChip(i);
}


decompiled_code:
__int64 YM2610_status_port_0_A_r()
{
return (unsigned __int8)YM2610Read(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int8)YM2610Read(0LL, 0LL);
}

original_code:
data_t YM2610_status_port_0_A_r(offs_t offset)
{
 return YM2610Read(0,0);
}

canonical_original_code:
unsigned int YM2610_status_port_0_A_r(unsigned int offset)
{
 return YM2610Read(0,0);
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 YM2610_status_port_0_B_r()
{
return (unsigned __int8)YM2610Read(0LL, 2LL);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int8)YM2610Read(0LL, 2LL);
}

original_code:
data_t YM2610_status_port_0_B_r(offs_t offset)
{
 return YM2610Read(0,2);
}

canonical_original_code:
unsigned int YM2610_status_port_0_B_r(unsigned int offset)
{
 return YM2610Read(0,2);
}


decompiled_code:
__int64 YM2610_status_port_1_A_r()
{
return (unsigned __int8)YM2610Read(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)YM2610Read(1LL, 0LL);
}

original_code:
data_t YM2610_status_port_1_A_r(offs_t offset) {
 return YM2610Read(1,0);
}

canonical_original_code:
unsigned int YM2610_status_port_1_A_r(unsigned int offset) {
 return YM2610Read(1,0);
}


decompiled_code:
__int64 YM2610_status_port_1_B_r()
{
return (unsigned __int8)YM2610Read(1LL, 2LL);
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned __int8)YM2610Read(1LL, 2LL);
}

original_code:
data_t YM2610_status_port_1_B_r(offs_t offset) {
 return YM2610Read(1,2);
}

canonical_original_code:
unsigned int YM2610_status_port_1_B_r(unsigned int offset) {
 return YM2610Read(1,2);
}


decompiled_code:
__int64 YM2610_read_port_0_r()
{
return (unsigned __int8)YM2610Read(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned __int8)YM2610Read(0LL, 1LL);
}

original_code:
data_t YM2610_read_port_0_r(offs_t offset){
 return YM2610Read(0,1);
}

canonical_original_code:
unsigned int YM2610_read_port_0_r(unsigned int offset){
 return YM2610Read(0,1);
}


decompiled_code:
__int64 YM2610_read_port_1_r()
{
return (unsigned __int8)YM2610Read(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned __int8)YM2610Read(1LL, 1LL);
}

original_code:
data_t YM2610_read_port_1_r(offs_t offset){
 return YM2610Read(1,1);
}

canonical_original_code:
unsigned int YM2610_read_port_1_r(unsigned int offset){
 return YM2610Read(1,1);
}


decompiled_code:
__int64 __fastcall YM2610_control_port_0_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 0LL, a2);
}

original_code:
void YM2610_control_port_0_A_w(offs_t offset,data_t data)
{
 YM2610Write(0,0,data);
}

canonical_original_code:
void YM2610_control_port_0_A_w(unsigned int offset, unsigned int data)
{
 YM2610Write(0,0,data);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall YM2610_control_port_0_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 2LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 2LL, a2);
}

original_code:
void YM2610_control_port_0_B_w(offs_t offset,data_t data)
{
 YM2610Write(0,2,data);
}

canonical_original_code:
void YM2610_control_port_0_B_w(unsigned int offset, unsigned int data)
{
 YM2610Write(0,2,data);
}


decompiled_code:
__int64 __fastcall YM2610_control_port_1_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 0LL, a2);
}

original_code:
void YM2610_control_port_1_A_w(offs_t offset,data_t data){
 YM2610Write(1,0,data);
}

canonical_original_code:
void YM2610_control_port_1_A_w(unsigned int offset, unsigned int data){
 YM2610Write(1,0,data);
}


decompiled_code:
__int64 __fastcall YM2610_control_port_1_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 2LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 2LL, a2);
}

original_code:
void YM2610_control_port_1_B_w(offs_t offset,data_t data){
 YM2610Write(1,2,data);
}

canonical_original_code:
void YM2610_control_port_1_B_w(unsigned int offset, unsigned int data){
 YM2610Write(1,2,data);
}


decompiled_code:
__int64 __fastcall YM2610_data_port_0_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 1LL, a2);
}

original_code:
void YM2610_data_port_0_A_w(offs_t offset,data_t data)
{
 YM2610Write(0,1,data);
}

canonical_original_code:
void YM2610_data_port_0_A_w(unsigned int offset, unsigned int data)
{
 YM2610Write(0,1,data);
}


decompiled_code:
__int64 __fastcall YM2610_data_port_0_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(0LL, 3LL, a2);
}

original_code:
void YM2610_data_port_0_B_w(offs_t offset,data_t data)
{
 YM2610Write(0,3,data);
}

canonical_original_code:
void YM2610_data_port_0_B_w(unsigned int offset, unsigned int data)
{
 YM2610Write(0,3,data);
}


decompiled_code:
__int64 __fastcall YM2610_data_port_1_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 1LL, a2);
}

original_code:
void YM2610_data_port_1_A_w(offs_t offset,data_t data){
 YM2610Write(1,1,data);
}

canonical_original_code:
void YM2610_data_port_1_A_w(unsigned int offset, unsigned int data){
 YM2610Write(1,1,data);
}


decompiled_code:
__int64 __fastcall YM2610_data_port_1_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int8 a2)
{
return YM2610Write(1LL, 3LL, a2);
}

original_code:
void YM2610_data_port_1_B_w(offs_t offset,data_t data){
 YM2610Write(1,3,data);
}

canonical_original_code:
void YM2610_data_port_1_B_w(unsigned int offset, unsigned int data){
 YM2610Write(1,3,data);
}


FMTimerInit

decompiled_code:
void FMTimerInit()
{
qword_6C8 = 0LL;
Timer = 0LL;
qword_6D8 = 0LL;
qword_6D0 = 0LL;
}

canonical_decompiled_code:
void func0()
{
qword_6C8 = 0LL;
Timer = 0LL;
qword_6D8 = 0LL;
qword_6D0 = 0LL;
}

original_code:
static void FMTimerInit( void )
{
 int i;
 for( i = 0 ; i < (2) ; i++ )
  Timer[i][0] = Timer[i][1] = 0;
}

canonical_original_code:
static void FMTimerInit()
{
 int i;
 for( i = 0 ; i < (2) ; i++ )
  Timer[i][0] = Timer[i][1] = 0;
}


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

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

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

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


decompiled_code:
__int64 __fastcall snowbros_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // r12
__int64 result; // rax
unsigned int v5; // edx
unsigned int v6; // eax
__int16 v7; // cx

palette_recalc();
fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
v1 = 8LL;
LODWORD(v2) = 0;
LODWORD(v3) = 0;
do
{
v5 = *(unsigned __int8 *)(snowbros_spriteram + v1);
v6 = *(unsigned __int8 *)(snowbros_spriteram + v1 + 2);
v7 = *(_WORD *)(snowbros_spriteram + v1 - 2);
if ( (v7 & 1) != 0 )
v5 = *(unsigned __int8 *)(snowbros_spriteram + v1) ^ 0xFFFFFF00;
if ( (v7 & 2) != 0 )
v6 ^= 0xFFFFFF00;
if ( (v7 & 4) != 0 )
{
v3 = v5 + (unsigned int)v3;
v2 = v6 + (unsigned int)v2;
if ( (int)v3 > 511 )
v3 &= 0x1FFu;
if ( (int)v2 > 511 )
v2 &= 0x1FFu;
}
else
{
v3 = v5;
v2 = v6;
}
result = (unsigned int)(v2 - 1);
if ( (unsigned int)result <= 0xEE )
{
result = (unsigned int)(v3 + 15);
if ( (unsigned int)result <= 0x10E )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(*(_WORD *)(snowbros_spriteram + v1 + 6) << 8) & 0xF00 | (unsigned int)*(unsigned __int8 *)(snowbros_spriteram + v1 + 4),
(unsigned __int8)v7 >> 4,
*(_WORD *)(snowbros_spriteram + v1 + 6) & 0x80,
*(_WORD *)(snowbros_spriteram + v1 + 6) & 0x40,
v3,
v2,
Machine + 776LL,
2LL,
0LL);
}
v1 += 16LL;
}
while ( v1 != 7688 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // r12
__int64 result; // rax
unsigned int v5; // edx
unsigned int v6; // eax
__int16 v7; // cx

palette_recalc();
fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
v1 = 8LL;
LODWORD(v2) = 0;
LODWORD(v3) = 0;
do
{
v5 = *(unsigned __int8 *)(snowbros_spriteram + v1);
v6 = *(unsigned __int8 *)(snowbros_spriteram + v1 + 2);
v7 = *(_WORD *)(snowbros_spriteram + v1 - 2);
if ( (v7 & 1) != 0 )
v5 = *(unsigned __int8 *)(snowbros_spriteram + v1) ^ 0xFFFFFF00;
if ( (v7 & 2) != 0 )
v6 ^= 0xFFFFFF00;
if ( (v7 & 4) != 0 )
{
v3 = v5 + (unsigned int)v3;
v2 = v6 + (unsigned int)v2;
if ( (int)v3 > 511 )
v3 &= 0x1FFu;
if ( (int)v2 > 511 )
v2 &= 0x1FFu;
}
else
{
v3 = v5;
v2 = v6;
}
result = (unsigned int)(v2 - 1);
if ( (unsigned int)result <= 0xEE )
{
result = (unsigned int)(v3 + 15);
if ( (unsigned int)result <= 0x10E )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(*(_WORD *)(snowbros_spriteram + v1 + 6) << 8) & 0xF00 | (unsigned int)*(unsigned __int8 *)(snowbros_spriteram + v1 + 4),
(unsigned __int8)v7 >> 4,
*(_WORD *)(snowbros_spriteram + v1 + 6) & 0x80,
*(_WORD *)(snowbros_spriteram + v1 + 6) & 0x40,
v3,
v2,
Machine + 776LL,
2LL,
0LL);
}
v1 += 16LL;
}
while ( v1 != 7688 );
return result;
}

original_code:
void snowbros_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int x=0,y=0,offs;
 palette_recalc ();
   fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 for (offs = 0;offs < 0x1e00; offs += 16)
 {
  int sx = (*(UINT16 *)(&snowbros_spriteram[8+offs])) & 0xff;
  int sy = (*(UINT16 *)(&snowbros_spriteram[0x0a+offs])) & 0xff;
  int tilecolour = (*(UINT16 *)(&snowbros_spriteram[6+offs]));
  if (tilecolour & 1) sx = -1 - (sx ^ 0xff);
  if (tilecolour & 2) sy = -1 - (sy ^ 0xff);
  if (tilecolour & 4)
  {
   x += sx;
   y += sy;
  }
  else
  {
   x = sx;
   y = sy;
  }
  if (x > 511) x &= 0x1ff;
  if (y > 511) y &= 0x1ff;
  if ((x>-16) && (y>0) && (x<256) && (y<240))
  {
   int attr = (*(UINT16 *)(&snowbros_spriteram[0x0e + offs]));
   int tile = ((attr & 0x0f) << 8) + ((*(UINT16 *)(&snowbros_spriteram[0x0c+offs])) & 0xff);
   drawgfx(bitmap,Machine->gfx[0],
     tile,
     (tilecolour & 0xf0) >> 4,
     attr & 0x80, attr & 0x40,
     x,y,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
void snowbros_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int x = 0; int y = 0; int offs;
 palette_recalc ();
   fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 for (offs = 0;offs < 0x1e00; offs += 16)
 {
  int sx = (*(UINT16 *)(&snowbros_spriteram[8+offs])) & 0xff;
  int sy = (*(UINT16 *)(&snowbros_spriteram[0x0a+offs])) & 0xff;
  int tilecolour = (*(UINT16 *)(&snowbros_spriteram[6+offs]));
  if (tilecolour & 1) sx = -1 - (sx ^ 0xff);
  if (tilecolour & 2) sy = -1 - (sy ^ 0xff);
  if (tilecolour & 4)
  {
   x += sx;
   y += sy;
  }
  else
  {
   x = sx;
   y = sy;
  }
  if (x > 511) x &= 0x1ff;
  if (y > 511) y &= 0x1ff;
  if ((x>-16) && (y>0) && (x<256) && (y<240))
  {
   int attr = (*(UINT16 *)(&snowbros_spriteram[0x0e + offs]));
   int tile = ((attr & 0x0f) << 8) + ((*(UINT16 *)(&snowbros_spriteram[0x0c+offs])) & 0xff);
   drawgfx(bitmap,Machine->gfx[0],
     tile,
     (tilecolour & 0xf0) >> 4,
     attr & 0x80, attr & 0x40,
     x,y,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

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

variable_types: x int

variable_types: y int

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: tilecolour int

variable_types: attr int

variable_types: tile int


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

result = 3LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = soundlatch_r();
return result;
}

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

result = 3LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = soundlatch_r();
return result;
}

original_code:
data_t snowbros_68000_sound_r(offs_t offset)
{
 int ret;
 if (Machine->sample_rate != 0)
 {
  ret = soundlatch_r(offset);
 }
 else
 {
  ret = 3;
 }
 return ret;
}

canonical_original_code:
unsigned int snowbros_68000_sound_r(unsigned int offset)
{
 int ret;
 if (Machine->sample_rate != 0)
 {
  ret = soundlatch_r(offset);
 }
 else
 {
  ret = 3;
 }
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 snowbros_interrupt()
{
return (unsigned int)cpu_getiloops() + 2;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)cpu_getiloops() + 2;
}

original_code:
static int snowbros_interrupt(void)
{
 return cpu_getiloops() + 2;
}

canonical_original_code:
static int snowbros_interrupt()
{
 return cpu_getiloops() + 2;
}


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

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

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

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


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

if ( a1 == 2 )
{
v3 = input_port_1_r(2LL);
result = (v3 << 8) + (unsigned int)input_port_4_r(2LL);
}
else if ( a1 == 4 )
{
result = (unsigned int)input_port_2_r(4LL) << 8;
}
else
{
result = 255LL;
if ( !a1 )
{
v2 = input_port_0_r();
result = (v2 << 8) + (unsigned int)input_port_3_r(0LL);
}
}
return result;
}

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

if ( a1 == 2 )
{
v3 = input_port_1_r(2LL);
result = (v3 << 8) + (unsigned int)input_port_4_r(2LL);
}
else if ( a1 == 4 )
{
result = (unsigned int)input_port_2_r(4LL) << 8;
}
else
{
result = 255LL;
if ( !a1 )
{
v2 = input_port_0_r();
result = (v2 << 8) + (unsigned int)input_port_3_r(0LL);
}
}
return result;
}

original_code:
static data_t snowbros_input_r(offs_t offset)
{
 int ans = 0xff;
 switch (offset)
 {
  case 0:
   ans = (input_port_0_r (offset) << 8) + (input_port_3_r (offset));
            break;
  case 2:
   ans = (input_port_1_r (offset) << 8) + (input_port_4_r (offset));
            break;
  case 4:
   ans = input_port_2_r (offset) << 8;
            break;
 }
    return ans;
}

canonical_original_code:
static unsigned int snowbros_input_r(unsigned int offset)
{
 int ans = 0xff;
 switch (offset)
 {
  case 0:
   ans = (input_port_0_r (offset) << 8) + (input_port_3_r (offset));
            break;
  case 2:
   ans = (input_port_1_r (offset) << 8) + (input_port_4_r (offset));
            break;
  case 4:
   ans = input_port_2_r (offset) << 8;
            break;
 }
    return ans;
}

variable_types: ans int


irqhandler

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1);
}

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

variable_types: linestate int


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

canonical_original_code:
void jailbrek_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom) {
 int i;
 for ( i = 0; i < Machine->drv->total_colors; i++ ) {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[0] >> 4) & 0x01;
  bit1 = (color_prom[0] >> 5) & 0x01;
  bit2 = (color_prom[0] >> 6) & 0x01;
  bit3 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += Machine->drv->total_colors;
 for ( i = 0; i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity); i++ )
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = ( *color_prom++ ) + 0x10;
 for ( i = 0; i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity); i++ )
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *color_prom++;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

result = interrupt_control;
*(_BYTE *)interrupt_control = 0;
return result;
}

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

result = interrupt_control;
*(_BYTE *)interrupt_control = 0;
return result;
}

original_code:
static void jailbrek_machine_init( void )
{
 interrupt_control[0] = 0;
}

canonical_original_code:
static void jailbrek_machine_init()
{
 interrupt_control[0] = 0;
}


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

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

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

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

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

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


decompiled_code:
__int64 init_jailbrek()
{
return konami1_decode();
}

canonical_decompiled_code:
__int64 func3()
{
return konami1_decode();
}

original_code:
static void init_jailbrek(void)
{
 konami1_decode();
}

canonical_original_code:
static void init_jailbrek()
{
 konami1_decode();
}


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

if ( (*(_BYTE *)interrupt_control & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (*(_BYTE *)interrupt_control & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int jb_interrupt_nmi( void ) {
 if ( interrupt_control[0] & 1 )
  return nmi_interrupt();
 return ignore_interrupt();
}

canonical_original_code:
static int jb_interrupt_nmi() {
 if ( interrupt_control[0] & 1 )
  return nmi_interrupt();
 return ignore_interrupt();
}


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

if ( (*(_BYTE *)interrupt_control & 2) != 0 )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (*(_BYTE *)interrupt_control & 2) != 0 )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int jb_interrupt( void ) {
 if ( interrupt_control[0] & 2 )
  return interrupt();
 return ignore_interrupt();
}

canonical_original_code:
static int jb_interrupt() {
 if ( interrupt_control[0] & 2 )
  return interrupt();
 return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall jailbrek_speech_w(__int64 a1, unsigned int a2)
{
VLM5030_VCU(a2 & 1);
VLM5030_ST((a2 >> 1) & 1);
return VLM5030_RST((a2 & 4) != 0);
}

original_code:
static void jailbrek_speech_w(offs_t offset,data_t data) {
 VLM5030_VCU( data & 1 );
 VLM5030_ST( ( data >> 1 ) & 1 );
 VLM5030_RST( ( data >> 2 ) & 1 );
}

canonical_original_code:
static void jailbrek_speech_w(unsigned int offset, unsigned int data) {
 VLM5030_VCU( data & 1 );
 VLM5030_ST( ( data >> 1 ) & 1 );
 VLM5030_RST( ( data >> 2 ) & 1 );
}

variable_types:
offset
unsigned int


decompiled_code:
_BOOL8 jailbrek_speech_r()
{
return (unsigned int)VLM5030_BSY() != 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
return (unsigned int)VLM5030_BSY() != 0;
}

original_code:
static data_t jailbrek_speech_r(offs_t offset) {
 return ( VLM5030_BSY() ? 1 : 0 );
}

canonical_original_code:
static unsigned int jailbrek_speech_r(unsigned int offset) {
 return ( VLM5030_BSY() ? 1 : 0 );
}


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

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

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

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


decompiled_code:
__int64 __fastcall update_pb4(int a1)
{
int v1; // eax
int v2; // esi
int v3; // eax
int v4; // ecx
int v5; // eax
int v6; // esi
int v8; // eax
int v9; // ecx

if ( (sound_latch_b & 0x10) != 0 )
{
if ( level_13 <= 32766 )
{
v1 = (int)(float)((float)(0x7FFF - level_13) / *(float *)&pb4_charge_time);
v2 = counter_12 - v1;
if ( counter_12 - v1 <= 0 )
{
v3 = (v1 - counter_12) / a1 + 1;
counter_12 = v3 * a1 + v2;
v4 = v3 + level_13;
if ( v3 + level_13 > 0x7FFF )
v4 = 0x7FFF;
level_13 = v4;
}
else
{
counter_12 -= v1;
}
}
}
else if ( level_13 > 0 )
{
v5 = (int)(float)((float)level_13 / *(float *)&pb4_discharge_time);
v6 = counter_12 - v5;
if ( counter_12 - v5 <= 0 )
{
v8 = (v5 - counter_12) / a1 + 1;
counter_12 = v6 + v8 * a1;
v9 = level_13 - v8;
if ( level_13 - v8 < 0 )
v9 = 0;
level_13 = v9;
}
else
{
counter_12 -= v5;
}
}
return (unsigned int)level_13;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax
int v2; // esi
int v3; // eax
int v4; // ecx
int v5; // eax
int v6; // esi
int v8; // eax
int v9; // ecx

if ( (sound_latch_b & 0x10) != 0 )
{
if ( level_13 <= 32766 )
{
v1 = (int)(float)((float)(0x7FFF - level_13) / *(float *)&pb4_charge_time);
v2 = counter_12 - v1;
if ( counter_12 - v1 <= 0 )
{
v3 = (v1 - counter_12) / a1 + 1;
counter_12 = v3 * a1 + v2;
v4 = v3 + level_13;
if ( v3 + level_13 > 0x7FFF )
v4 = 0x7FFF;
level_13 = v4;
}
else
{
counter_12 -= v1;
}
}
}
else if ( level_13 > 0 )
{
v5 = (int)(float)((float)level_13 / *(float *)&pb4_discharge_time);
v6 = counter_12 - v5;
if ( counter_12 - v5 <= 0 )
{
v8 = (v5 - counter_12) / a1 + 1;
counter_12 = v6 + v8 * a1;
v9 = level_13 - v8;
if ( level_13 - v8 < 0 )
v9 = 0;
level_13 = v9;
}
else
{
counter_12 -= v5;
}
}
return (unsigned int)level_13;
}

original_code:
static inline int update_pb4(int samplerate)
{
 static int counter, level;
 if( sound_latch_b & 0x10 )
 {
  if( level < 32767 )
  {
   counter -= (int)((32767 - level) / pb4_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) / pb4_discharge_time);
   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_pb4(int samplerate)
{
 static int counter; static int level;
 if( sound_latch_b & 0x10 )
 {
  if( level < 32767 )
  {
   counter -= (int)((32767 - level) / pb4_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) / pb4_discharge_time);
   if( counter <= 0 )
   {
    int n = (-counter / samplerate) + 1;
    counter += n * samplerate;
    if( (level -= n) < 0)
     level = 0;
   }
  }
 }
 return level;
}

variable_types: samplerate int

variable_types: counter int

variable_types: level int

variable_types: n int


decompiled_code:
__int64 __fastcall tone23(int a1)
{
int v1; // edx
__int64 result; // rax
int v3; // eax
int v4; // ecx
int v5; // edx
int v6; // eax
int v7; // esi
int v8; // ecx
int v9; // eax

v1 = update_pb4(a1);
result = sound_latch_b & 0x20;
if ( (sound_latch_b & 0x20) != 0 )
{
v3 = 0x7FFF - v1;
v4 = 0x7FFF - v1;
if ( 0x7FFF - v1 <= 32766 )
{
v5 = tone2_max_freq * v3;
v6 = tone2_max_freq * v3 + 0x7FFF;
if ( v5 >= 0 )
v6 = v5;
v7 = counter2_17 - (v6 >> 15);
if ( v7 <= 0 )
{
v9 = ((v6 >> 15) - counter2_17) / a1 + 1;
counter2_17 = v9 * a1 + v7;
output2_16 = ((_BYTE)output2_16 + (_BYTE)v9) & 1;
}
else
{
counter2_17 -= v6 >> 15;
}
v8 = counter3_15 - (v4 * (2 * tone3_max_freq / 3) / 33768 + tone3_max_freq / 3);
counter3_15 = v8;
if ( v8 <= 0 )
{
counter3_15 = a1 + v8;
output3_14 = ((unsigned __int8)(-counter2_17 / a1) + (_BYTE)output3_14 + 1) & 1;
}
}
result = (unsigned int)((int)((output2_16 == 0 ? 0xFFFF0002 : 0) + (output3_14 == 0 ? 0xFFFF0002 : 0) + 65534) / 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // edx
__int64 result; // rax
int v3; // eax
int v4; // ecx
int v5; // edx
int v6; // eax
int v7; // esi
int v8; // ecx
int v9; // eax

v1 = func2(a1);
result = sound_latch_b & 0x20;
if ( (sound_latch_b & 0x20) != 0 )
{
v3 = 0x7FFF - v1;
v4 = 0x7FFF - v1;
if ( 0x7FFF - v1 <= 32766 )
{
v5 = tone2_max_freq * v3;
v6 = tone2_max_freq * v3 + 0x7FFF;
if ( v5 >= 0 )
v6 = v5;
v7 = counter2_17 - (v6 >> 15);
if ( v7 <= 0 )
{
v9 = ((v6 >> 15) - counter2_17) / a1 + 1;
counter2_17 = v9 * a1 + v7;
output2_16 = ((_BYTE)output2_16 + (_BYTE)v9) & 1;
}
else
{
counter2_17 -= v6 >> 15;
}
v8 = counter3_15 - (v4 * (2 * tone3_max_freq / 3) / 33768 + tone3_max_freq / 3);
counter3_15 = v8;
if ( v8 <= 0 )
{
counter3_15 = a1 + v8;
output3_14 = ((unsigned __int8)(-counter2_17 / a1) + (_BYTE)output3_14 + 1) & 1;
}
}
result = (unsigned int)((int)((output2_16 == 0 ? 0xFFFF0002 : 0) + (output3_14 == 0 ? 0xFFFF0002 : 0) + 65534) / 2);
}
return result;
}

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)
{
int v1; // eax
int v2; // esi
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // esi
int v8; // eax
int v9; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // eax
int v2; // esi
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // esi
int v8; // eax
int v9; // ecx

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

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


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

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

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

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

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)
{
int v1; // eax
int v2; // esi
int v3; // eax
int v4; // ecx
int v5; // esi
int v6; // eax
int v8; // ecx

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

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

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

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 v2; // ebx
int v3; // ebp
int v4; // edi
int v5; // eax
int v6; // eax
int v7; // kr00_4
int v8; // ecx
__int64 result; // rax
int v10; // eax

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

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v2; // ebx
int v3; // ebp
int v4; // edi
int v5; // eax
int v6; // eax
int v7; // kr00_4
int v8; // ecx
__int64 result; // rax
int v10; // eax

v2 = func4(a1);
v3 = func5(a1);
v4 = func6(a1);
if ( polybit )
v5 = v2 + opamp_resistor * (0x7FFF - v2) / (polybit_resistor + opamp_resistor);
else
v5 = polybit_resistor * v2 / (opamp_resistor + polybit_resistor);
v7 = tone4_max_freq * v5;
v6 = tone4_max_freq * v5 + (tone4_max_freq * v5 < 0 ? 0x7FFF : 0);
v8 = counter_11 - v7 / 0x8000;
if ( v8 <= 0 )
{
v10 = ((v6 >> 15) - counter_11) / a1 + 1;
counter_11 = v8 + v10 * a1;
output_10 = ((_BYTE)output_10 + (_BYTE)v10) & 1;
}
else
{
counter_11 -= v6 >> 15;
}
result = (unsigned int)(v3 * pa5_resistor / (pa5_resistor + pc5_resistor)
+ v4 * pc5_resistor / (pa5_resistor + pc5_resistor));
if ( !output_10 )
result = (unsigned int)-(int)result;
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)
{
int v1; // eax
int v2; // esi
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // esi
int v8; // eax
int v9; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // eax
int v2; // esi
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // esi
int v8; // eax
int v9; // ecx

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

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; // er12
__int64 v5; // rbp
__int64 v6; // r13
int v7; // ebx
int v8; // ebx
int v9; // ebx
int v10; // eax

result = Machine;
v4 = *(_DWORD *)(Machine + 836LL);
if ( a3 > 0 )
{
v5 = a2;
v6 = a2 + 2LL * (unsigned int)a3;
do
{
v7 = tone1(v4);
v8 = v7 / 2 + (int)tone23(v4) / 2;
v9 = tone4(v4) + v8;
v10 = noise(v4);
result = clip_short_ret(v9 + v10);
v5 += 2LL;
*(_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; // er12
__int64 v5; // rbp
__int64 v6; // r13
int v7; // ebx
int v8; // ebx
int v9; // ebx
int v10; // eax

result = Machine;
v4 = *(_DWORD *)(Machine + 836LL);
if ( a3 > 0 )
{
v5 = a2;
v6 = a2 + 2LL * (unsigned int)a3;
do
{
v7 = func1(v4);
v8 = v7 / 2 + (int)func3(v4) / 2;
v9 = func7(v4) + v8;
v10 = func9(v4);
result = func0(v9 + v10);
v5 += 2LL;
*(_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


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:
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 __fastcall pleiads_sh_start(__int64 a1)
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc4_charge_time = 1032268546;
pc4_discharge_time = 1018444120;
pc5_charge_time = 995640528;
pc5_discharge_time = LC4;
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(a1, (__int64)"Custom (Pleiads)");
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1)
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc4_charge_time = 1032268546;
pc4_discharge_time = 1018444120;
pc5_charge_time = 995640528;
pc5_discharge_time = LC4;
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 func11(a1, (__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 __fastcall naughtyb_sh_start(__int64 a1)
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc4_charge_time = 1056964608;
pc4_discharge_time = 1045220557;
pc5_charge_time = 995640528;
pc5_discharge_time = LC4;
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(a1, (__int64)"Custom (Naughty Boy)");
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1)
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pb4_charge_time = LC4;
pb4_discharge_time = LC4;
pc4_charge_time = 1056964608;
pc4_discharge_time = 1045220557;
pc5_charge_time = 995640528;
pc5_discharge_time = LC4;
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 func11(a1, (__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)");
}


decompiled_code:
_BOOL8 __fastcall popflame_sh_start(__int64 a1)
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pb4_charge_time = LC12;
pb4_discharge_time = LC12;
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;
return common_sh_start(a1, (__int64)"Custom (Pop Flamer)");
}

canonical_decompiled_code:
_BOOL8 __fastcall func17(__int64 a1)
{
pa5_charge_time = 1079194419;
pa5_discharge_time = 1074580685;
pa6_charge_time = 977162505;
pb4_charge_time = LC12;
pb4_discharge_time = LC12;
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;
return func11(a1, (__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);
}


decompiled_code:
__int64 __fastcall tone1(int a1)
{
int v1; // edx
int v2; // eax
int v3; // er11
char v4; // r10
char v5; // cl

if ( (sound_latch_a & 0xF) != 15 )
{
v1 = counter_20 - 8000;
counter_20 -= 8000;
v2 = divisor_19;
v3 = output_18;
v4 = 0;
LABEL_3:
v5 = v4;
while ( v1 <= 0 )
{
v1 += a1;
++v2;
v5 = 1;
if ( v2 == 16 )
{
v3 ^= 1u;
v2 = sound_latch_a & 0xF;
v4 = 1;
goto LABEL_3;
}
}
if ( v5 )
{
counter_20 = v1;
divisor_19 = v2;
}
if ( v4 )
output_18 = v3;
}
return output_18 == 0 ? -32767 : 0x7FFF;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // edx
int v2; // eax
int v3; // er11
char v4; // r10
char v5; // cl

if ( (sound_latch_a & 0xF) != 15 )
{
v1 = counter_20 - 8000;
counter_20 -= 8000;
v2 = divisor_19;
v3 = output_18;
v4 = 0;
LABEL_3:
v5 = v4;
while ( v1 <= 0 )
{
v1 += a1;
++v2;
v5 = 1;
if ( v2 == 16 )
{
v3 ^= 1u;
v2 = sound_latch_a & 0xF;
v4 = 1;
goto LABEL_3;
}
}
if ( v5 )
{
counter_20 = v1;
divisor_19 = v2;
}
if ( v4 )
output_18 = v3;
}
return output_18 == 0 ? -32767 : 0x7FFF;
}

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; // er8
int v2; // esi
int v4; // ecx
int v5; // ecx
int v6; // edx

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

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // er8
int v2; // esi
int v4; // ecx
int v5; // ecx
int v6; // edx

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

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)
{
__int64 result; // rax
_BYTE *v3; // rdi
_BYTE *v4; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
__int64 result; // rax
_BYTE *v3; // rdi
_BYTE *v4; // rdi

if ( (a2 & 0x80u) == 0 )
{
result = a2 ^ (unsigned int)*(unsigned __int8 *)(popeye_videoram + a1);
if ( (((unsigned __int8)a2 ^ *(_BYTE *)(popeye_videoram + a1)) & 0xF) != 0 )
{
*((_BYTE *)dirtybuffer2 + a1) = 1;
v4 = (_BYTE *)(popeye_videoram + a1);
result = *v4 & 0xF0;
*v4 = *v4 & 0xF0 | a2 & 0xF;
}
}
else
{
result = (unsigned __int8)(16 * a2);
if ( (*(_BYTE *)(popeye_videoram + a1) & 0xF0) != (_DWORD)result )
{
*((_BYTE *)dirtybuffer2 + a1) = 1;
v3 = (_BYTE *)(popeye_videoram + a1);
result = *v3 & 0xF;
*v3 = 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);
  }
 }
}

variable_types:
offset
unsigned int


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

canonical_decompiled_code:
void __fastcall func2(__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; // ebx
size_t v2; // rbp
void *v3; // rdi

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

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

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

original_code:
int 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()
{
bitmap_free(tmpbitmap2);
free(dirtybuffer2);
return generic_vh_stop();
}

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

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; // ebp

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; // ebp

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


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(int a1)
{
return (unsigned __int8)ssio_data[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(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;
ssio_data[result] = a1;
return result;
}

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

result = a1 >> 8;
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; // rbx
__int64 j; // rbx
__int64 result; // rax

for ( i = 0LL; i != 3; ++i )
AY8910_set_volume(
0LL,
(unsigned int)i,
(unsigned int)((int)((unsigned __int64)(229064922500LL * ((unsigned __int8)ssio_duty_cycle[i] ^ 0xF)) >> 32) >> 3));
for ( j = 0LL; j != 3; ++j )
result = AY8910_set_volume(
1LL,
(unsigned int)j,
(unsigned int)((int)((unsigned __int64)(229064922500LL * ((unsigned __int8)byte_813[j] ^ 0xF)) >> 32) >> 3));
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax

for ( i = 0LL; i != 3; ++i )
AY8910_set_volume(
0LL,
(unsigned int)i,
(unsigned int)((int)((unsigned __int64)(229064922500LL * ((unsigned __int8)ssio_duty_cycle[i] ^ 0xF)) >> 32) >> 3));
for ( j = 0LL; j != 3; ++j )
result = AY8910_set_volume(
1LL,
(unsigned int)j,
(unsigned int)((int)((unsigned __int64)(229064922500LL * ((unsigned __int8)byte_813[j] ^ 0xF)) >> 32) >> 3));
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_815 = 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_815 = 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_812 = a2 & 0xF;
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char a2)
{
byte_812 = 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_813[0] = a2 & 0xF;
byte_814 = a2 >> 4;
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
byte_813[0] = a2 & 0xF;
byte_814 = a2 >> 4;
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)
{
ssio_duty_cycle[0] = a2 & 0xF;
byte_811 = a2 >> 4;
return ssio_update_volumes();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
ssio_duty_cycle[0] = a2 & 0xF;
byte_811 = a2 >> 4;
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;
}