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

result = a1 & 0x61;
if ( (_DWORD)result == 33 )
return AY8910_write_port_1_w();
if ( (unsigned int)result > 0x21 )
{
switch ( (_DWORD)result )
{
case 'A':
sound_flags |= 0x40u;
HIDWORD(sound_status) = a2;
result = cpu_cause_interrupt(0LL, 1LL);
break;
case 'a':
result = z80ctc_0_trg0_w(0LL, 0LL);
break;
case '@':
LODWORD(sound_status) = a2;
break;
}
}
else if ( (_DWORD)result == 1 )
{
result = AY8910_write_port_0_w();
}
else if ( (_DWORD)result == 32 )
{
result = AY8910_control_port_1_w();
}
else if ( (a1 & 0x61) == 0 )
{
result = AY8910_control_port_0_w();
}
return result;
}

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

result = a1 & 0x61;
if ( (_DWORD)result == 33 )
return AY8910_write_port_1_w();
if ( (unsigned int)result > 0x21 )
{
switch ( (_DWORD)result )
{
case 'A':
sound_flags |= 0x40u;
HIDWORD(sound_status) = a2;
result = cpu_cause_interrupt(0LL, 1LL);
break;
case 'a':
result = z80ctc_0_trg0_w(0LL, 0LL);
break;
case '@':
LODWORD(sound_status) = a2;
break;
}
}
else if ( (_DWORD)result == 1 )
{
result = AY8910_write_port_0_w();
}
else if ( (_DWORD)result == 32 )
{
result = AY8910_control_port_1_w();
}
else if ( (a1 & 0x61) == 0 )
{
result = AY8910_control_port_0_w();
}
return result;
}

original_code:
void cchasm_snd_io_w(offs_t offset,data_t data)
{
    switch (offset & 0x61 )
    {
    case 0x00:
        AY8910_control_port_0_w (offset, data);
        break;
    case 0x01:
        AY8910_write_port_0_w (offset, data);
        break;
    case 0x20:
        AY8910_control_port_1_w (offset, data);
        break;
    case 0x21:
        AY8910_write_port_1_w (offset, data);
        break;
    case 0x40:
        sound_status[0] = data;
        break;
    case 0x41:
        sound_flags |= 0x40;
        sound_status[1] = data;
        cpu_cause_interrupt(0,1);
        break;
    case 0x61:
        z80ctc_0_trg0_w (0, 0);
        break;
    default:
        break;
    }
}

canonical_original_code:
void cchasm_snd_io_w(unsigned int offset, unsigned int data)
{
    switch (offset & 0x61 )
    {
    case 0x00:
        AY8910_control_port_0_w (offset, data);
        break;
    case 0x01:
        AY8910_write_port_0_w (offset, data);
        break;
    case 0x20:
        AY8910_control_port_1_w (offset, data);
        break;
    case 0x21:
        AY8910_write_port_1_w (offset, data);
        break;
    case 0x40:
        sound_status[0] = data;
        break;
    case 0x41:
        sound_flags |= 0x40;
        sound_status[1] = data;
        cpu_cause_interrupt(0,1);
        break;
    case 0x61:
        z80ctc_0_trg0_w (0, 0);
        break;
    default:
        break;
    }
}


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

result = input_port_3_r(0LL) & 0x70;
if ( (_DWORD)result != 112 )
result = z80ctc_0_trg0_w(0LL, 1LL);
return result;
}

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

result = input_port_3_r(0LL) & 0x70;
if ( (_DWORD)result != 112 )
result = z80ctc_0_trg0_w(0LL, 1LL);
return result;
}

original_code:
void cchasm_sh_update(void)
{
    if ((input_port_3_r (0) & 0x70) != 0x70)
        z80ctc_0_trg0_w (0, 1);
}

canonical_original_code:
void cchasm_sh_update()
{
    if ((input_port_3_r (0) & 0x70) != 0x70)
        z80ctc_0_trg0_w (0, 1);
}

return_type: void


decompiled_code:
__int16 __fastcall cchasm_io_r(__int64 a1)
{
unsigned int v1; // eax

switch ( ((unsigned int)a1 >> 1) & 0xF )
{
case 0u:
LOWORD(v1) = (_WORD)sound_status << 8;
break;
case 1u:
sound_flags &= 0xFFFFFFBF;
LOWORD(v1) = WORD2(sound_status) << 8;
break;
case 2u:
v1 = (sound_flags | input_port_3_r(a1) & 7) << 8;
BYTE1(v1) |= 8u;
break;
case 3u:
case 4u:
case 6u:
case 7u:
LOWORD(v1) = -256;
break;
case 5u:
v1 = (unsigned int)input_port_2_r() << 8;
break;
case 8u:
v1 = (unsigned int)input_port_1_r() << 8;
break;
default:
LOWORD(v1) = -256;
break;
}
return v1;
}

canonical_decompiled_code:
__int16 __fastcall func17(__int64 a1)
{
unsigned int v1; // eax

switch ( ((unsigned int)a1 >> 1) & 0xF )
{
case 0u:
LOWORD(v1) = (_WORD)sound_status << 8;
break;
case 1u:
sound_flags &= 0xFFFFFFBF;
LOWORD(v1) = WORD2(sound_status) << 8;
break;
case 2u:
v1 = (sound_flags | input_port_3_r(a1) & 7) << 8;
BYTE1(v1) |= 8u;
break;
case 3u:
case 4u:
case 6u:
case 7u:
LOWORD(v1) = -256;
break;
case 5u:
v1 = (unsigned int)input_port_2_r() << 8;
break;
case 8u:
v1 = (unsigned int)input_port_1_r() << 8;
break;
default:
LOWORD(v1) = -256;
break;
}
return v1;
}

original_code:
data_t cchasm_io_r(offs_t offset)
{
    switch ((offset >> 1) & 0xf)
    {
    case 0x0:
        return sound_status[0] << 8;
    case 0x1:
        sound_flags &= ~0x40;
        return sound_status[1] << 8;
    case 0x2:
        return (sound_flags| (input_port_3_r (offset) & 0x07) | 0x08) << 8;
    case 0x5:
        return input_port_2_r (offset) << 8;
    case 0x8:
        return input_port_1_r (offset) << 8;
    default:
        return 0xff << 8;
    }
}

canonical_original_code:
unsigned int cchasm_io_r(unsigned int offset)
{
    switch ((offset >> 1) & 0xf)
    {
    case 0x0:
        return sound_status[0] << 8;
    case 0x1:
        sound_flags &= ~0x40;
        return sound_status[1] << 8;
    case 0x2:
        return (sound_flags| (input_port_3_r (offset) & 0x07) | 0x08) << 8;
    case 0x5:
        return input_port_2_r (offset) << 8;
    case 0x8:
        return input_port_1_r (offset) << 8;
    default:
        return 0xff << 8;
    }
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 cchasm_sh_start()
{
__int64 v0; // rdx

sound_status = 0LL;
sound_command = 0LL;
sound_flags = 0;
v0 = *(unsigned int *)(Machine + 836LL);
output = 0LL;
channel = stream_init("CTC sound 1", 50LL, v0, 0LL, tone_update);
dword_A8C = stream_init("CTC sound 2", 50LL, *(unsigned int *)(Machine + 836LL), 1LL, tone_update);
dword_1AC4 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 84LL);
z80ctc_init(&ctc_intf);
return 0LL;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 v0; // rdx

sound_status = 0LL;
sound_command = 0LL;
sound_flags = 0;
v0 = *(unsigned int *)(Machine + 836LL);
output = 0LL;
channel = stream_init("CTC sound 1", 50LL, v0, 0LL, tone_update);
dword_A8C = stream_init("CTC sound 2", 50LL, *(unsigned int *)(Machine + 836LL), 1LL, tone_update);
dword_1AC4 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 84LL);
z80ctc_init(&ctc_intf);
return 0LL;
}

original_code:
int cchasm_sh_start(const struct MachineSound *msound)
{
    sound_status[0] = 0; sound_status[1] = 0;
    sound_command[0] = 0; sound_command[1] = 0;
    sound_flags = 0;
    output[0] = 0; output[1] = 0;
    channel[0] = stream_init("CTC sound 1", 50, Machine->sample_rate, 0, tone_update);
    channel[1] = stream_init("CTC sound 2", 50, Machine->sample_rate, 1, tone_update);
 ctc_intf.baseclock[0] = Machine->drv->cpu[1].cpu_clock;
 z80ctc_init (&ctc_intf);
 return 0;
}

canonical_original_code:
int cchasm_sh_start(struct MachineSound *msound)
{
    sound_status[0] = 0; sound_status[1] = 0;
    sound_command[0] = 0; sound_command[1] = 0;
    sound_flags = 0;
    output[0] = 0; output[1] = 0;
    channel[0] = stream_init("CTC sound 1", 50, Machine->sample_rate, 0, tone_update);
    channel[1] = stream_init("CTC sound 2", 50, Machine->sample_rate, 1, tone_update);
 ctc_intf.baseclock[0] = Machine->drv->cpu[1].cpu_clock;
 z80ctc_init (&ctc_intf);
 return 0;
}

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

return_type: int


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

if ( a2 )
{
HIDWORD(output) ^= 0x7Fu;
dword_A84 = 1;
result = stream_update((unsigned int)dword_A8C, 0LL);
}
return result;
}

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

if ( a2 )
{
HIDWORD(output) ^= 0x7Fu;
dword_A84 = 1;
result = stream_update((unsigned int)dword_A8C, 0LL);
}
return result;
}

original_code:
static void ctc_timer_2_w(offs_t offset,data_t data)
{
    if (data)
    {
        output[1] ^= 0x7f;
        channel_active[1] = 1;
        stream_update(channel[1], 0);
    }
}

canonical_original_code:
static void ctc_timer_2_w(unsigned int offset, unsigned int data)
{
    if (data)
    {
        output[1] ^= 0x7f;
        channel_active[1] = 1;
        stream_update(channel[1], 0);
    }
}

variable_types:
data
unsigned int


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

if ( a2 )
{
LODWORD(output) = output ^ 0x7F;
channel_active[0] = 1;
result = stream_update((unsigned int)channel, 0LL);
}
return result;
}

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

if ( a2 )
{
LODWORD(output) = output ^ 0x7F;
channel_active[0] = 1;
result = stream_update((unsigned int)channel, 0LL);
}
return result;
}

original_code:
static void ctc_timer_1_w(offs_t offset,data_t data)
{
    if (data)
    {
        output[0] ^= 0x7f;
        channel_active[0] = 1;
        stream_update(channel[0], 0);
    }
}

canonical_original_code:
static void ctc_timer_1_w(unsigned int offset, unsigned int data)
{
    if (data)
    {
        output[0] ^= 0x7f;
        channel_active[0] = 1;
        stream_update(channel[0], 0);
    }
}


decompiled_code:
void cchasm_watchdog_w()
{
;
}

canonical_decompiled_code:
void func21()
{
;
}

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

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


decompiled_code:
__int64 __fastcall tone_update(int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rdx

result = 0LL;
if ( channel_active[a1] )
result = (unsigned int)(*((_DWORD *)&output + a1) << 8);
v5 = a2 + 2LL * a3;
if ( a3 )
{
do
{
a2 += 2LL;
*(_WORD *)(a2 - 2) = result;
}
while ( a2 != v5 );
}
channel_active[a1] = 0;
return result;
}

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

result = 0LL;
if ( channel_active[a1] )
result = (unsigned int)(*((_DWORD *)&output + a1) << 8);
v5 = a2 + 2LL * a3;
if ( a3 )
{
do
{
a2 += 2LL;
*(_WORD *)(a2 - 2) = result;
}
while ( a2 != v5 );
}
channel_active[a1] = 0;
return result;
}

original_code:
static void tone_update(int num,INT16 *buffer,int length)
{
 INT16 out = 0;
 if (channel_active[num])
  out = output[num] << 8;
 while (length--) *(buffer++) = out;
 channel_active[num] = 0;
}

canonical_original_code:
static void tone_update(int num, short *buffer, int length)
{
 short out = 0;
 if (channel_active[num])
  out = output[num] << 8;
 while (length--) *(buffer++) = out;
 channel_active[num] = 0;
}

variable_types: num int

variable_types:
buffer
short *

variable_types: length int

variable_types: out short


decompiled_code:
__int64 __fastcall ctc_interrupt(unsigned int a1)
{
return cpu_cause_interrupt(1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
return cpu_cause_interrupt(1LL, a1);
}

original_code:
static void ctc_interrupt (int state)
{
 cpu_cause_interrupt (1, (((0)<<8)|(state)) );
}

canonical_original_code:
static void ctc_interrupt(int state)
{
 cpu_cause_interrupt (1, (((0)<<8)|(state)) );
}

variable_types: state int


original_code:
void yard_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 256;i++)
 {
  int bit0,bit1,bit2;
  bit0 = 0;
  bit1 = (color_prom[256] >> 2) & 0x01;
  bit2 = (color_prom[256] >> 3) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[256] >> 0) & 0x01;
  bit2 = (color_prom[256] >> 1) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 color_prom += 256;
 for (i = 0;i < 16;i++)
 {
  int bit0,bit1,bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 color_prom += 16;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = 256 + (*(color_prom++) & 0x0f);
 for (i = 0;i < 256;i++)
 {
  int bit0,bit1,bit2;
  bit0 = 0;
  bit1 = (color_prom[256] >> 2) & 0x01;
  bit2 = (color_prom[256] >> 3) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[256] >> 0) & 0x01;
  bit2 = (color_prom[256] >> 1) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void yard_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 256;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = 0;
  bit1 = (color_prom[256] >> 2) & 0x01;
  bit2 = (color_prom[256] >> 3) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[256] >> 0) & 0x01;
  bit2 = (color_prom[256] >> 1) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 color_prom += 256;
 for (i = 0;i < 16;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 color_prom += 16;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = 256 + (*(color_prom++) & 0x0f);
 for (i = 0;i < 256;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = 0;
  bit1 = (color_prom[256] >> 2) & 0x01;
  bit2 = (color_prom[256] >> 3) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[256] >> 0) & 0x01;
  bit2 = (color_prom[256] >> 1) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall yard_scroll_panel_w(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
int v4; // ebx
int i; // er15
char v6; // cl
__int64 v7; // rsi
__int64 result; // rax

v2 = (a1 & 0xF) - 1;
if ( v2 <= 0xD )
{
v4 = 4 * v2;
for ( i = 0; i != 4; ++i )
{
v6 = i;
v7 = (unsigned int)(i + v4);
result = plot_pixel(
scroll_panel_bitmap,
v7,
a1 >> 4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (int)(((a1 >> 4) & 0xFC)
+ 272
+ (((a2 >> v6) & 0x11 | ((int)((a2 >> v6) & 0x11) >> 3)) & 3))));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
int v4; // ebx
int i; // er15
char v6; // cl
__int64 v7; // rsi
__int64 result; // rax

v2 = (a1 & 0xF) - 1;
if ( v2 <= 0xD )
{
v4 = 4 * v2;
for ( i = 0; i != 4; ++i )
{
v6 = i;
v7 = (unsigned int)(i + v4);
result = plot_pixel(
scroll_panel_bitmap,
v7,
a1 >> 4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (int)(((a1 >> 4) & 0xFC)
+ 272
+ (((a2 >> v6) & 0x11 | ((int)((a2 >> v6) & 0x11) >> 3)) & 3))));
}
}
return result;
}

original_code:
void yard_scroll_panel_w(offs_t offset,data_t data)
{
 int sx,sy,i;
 sx = ( offset % 16 );
 sy = ( offset / 16 );
 if (sx < 1 || sx > 14) return;
 sx = 4 * (sx - 1);
 for (i = 0;i < 4;i++)
 {
  int col;
  col = (data >> i) & 0x11;
  col = ((col >> 3) | col) & 3;
  plot_pixel(scroll_panel_bitmap, sx + i, sy, Machine->pens[(256+16) + (sy & 0xfc) + col]);
 }
}

canonical_original_code:
void yard_scroll_panel_w(unsigned int offset, unsigned int data)
{
 int sx; int sy; int i;
 sx = ( offset % 16 );
 sy = ( offset / 16 );
 if (sx < 1 || sx > 14) return;
 sx = 4 * (sx - 1);
 for (i = 0;i < 4;i++)
 {
  int col;
  col = (data >> i) & 0x11;
  col = ((col >> 3) | col) & 3;
  plot_pixel(scroll_panel_bitmap, sx + i, sy, Machine->pens[(256+16) + (sy & 0xfc) + col]);
 }
}

variable_types: sx int

variable_types: sy int

variable_types: col int


decompiled_code:
__int64 yard_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
unsigned int v3; // er8

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));
if ( tmpbitmap )
{
v2 = bitmap_alloc(56LL, *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v3 = 0;
scroll_panel_bitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
bitmap_free(tmpbitmap);
v3 = 1;
}
return v3;
}
free(dirtybuffer);
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
unsigned int v3; // er8

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));
if ( tmpbitmap )
{
v2 = bitmap_alloc(56LL, *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v3 = 0;
scroll_panel_bitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
bitmap_free(tmpbitmap);
v3 = 1;
}
return v3;
}
free(dirtybuffer);
return 1LL;
}

original_code:
int yard_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;
 }
 if ((scroll_panel_bitmap = bitmap_alloc((14*4),Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  bitmap_free(tmpbitmap);
  return 1;
 }
 return 0;
}

canonical_original_code:
int yard_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;
 }
 if ((scroll_panel_bitmap = bitmap_alloc((14*4),Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  bitmap_free(tmpbitmap);
  return 1;
 }
 return 0;
}


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

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

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

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


decompiled_code:
__int64 __fastcall yard_flipscreen_w(unsigned int a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
flip_screen_w(a1, v2 & 1);
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
flip_screen_w(a1, v2 & 1);
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

original_code:
void yard_flipscreen_w(offs_t offset,data_t data)
{
 data ^= ~readinputport(4) & 1;
 flip_screen_w(offset, data & 1);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void yard_flipscreen_w(unsigned int offset, unsigned int data)
{
 data ^= ~readinputport(4) & 1;
 flip_screen_w(offset, data & 1);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 __fastcall yard_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v2; // r13
int v3; // ebx
__int64 v4; // r15
int v5; // er14
__int64 v6; // rcx
__int16 v7; // r11
char v8; // cl
__int64 v9; // r8
int v10; // eax
__int64 v11; // r15
__int64 v12; // r8
int v13; // ebx
char v14; // cl
unsigned int v15; // ecx
int v16; // er10
int v17; // esi
__int64 result; // rax
void *v19; // rax
__int64 v20; // r8
unsigned int v21; // [rsp+0h] [rbp-68h]
int v22; // [rsp+18h] [rbp-50h]
int v23; // [rsp+1Ch] [rbp-4Ch]
int v24; // [rsp+28h] [rbp-40h] BYREF
int v25[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v2 = a1;
if ( a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 2;
if ( (int)videoram_size - 2 < 0 )
goto LABEL_11;
}
else
{
v3 = videoram_size - 2;
if ( (int)videoram_size - 2 < 0 )
goto LABEL_11;
}
v4 = v3;
v5 = v3;
do
{
v6 = v4 + 1;
if ( *((_BYTE *)dirtybuffer + v4) || *((_BYTE *)dirtybuffer + v4 + 1) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
*((_BYTE *)dirtybuffer + v6) = 0;
v7 = *(unsigned __int8 *)(videoram + v6);
v8 = *(_BYTE *)(videoram + v6);
v9 = v8 & 0x20;
if ( flip_screen_x )
v9 = (_DWORD)v9 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + ((4 * v7) & 0x300u),
v8 & 0x1F,
v9);
}
v4 -= 2LL;
v5 -= 2;
}
while ( v5 >= 0 );
v2 = a1;
LABEL_11:
v10 = (unsigned __int8)*yard_scroll_x_low + ((unsigned __int8)*yard_scroll_x_high << 8);
if ( flip_screen_x )
{
v24 = v10 + 256;
v25[0] = (unsigned __int8)*yard_scroll_y_low;
}
else
{
v24 = -v10;
v25[0] = -(unsigned __int8)*yard_scroll_y_low;
}
copyscrollbitmap(v2, tmpbitmap, 1LL, &v24, 1LL, v25, Machine + 776LL, 0LL, 0LL);
v23 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v23 + 1LL;
do
{
v15 = *(unsigned __int8 *)(spriteram + v11);
v12 = *(_BYTE *)(spriteram + v11) & 0x40;
v16 = *(_BYTE *)(spriteram + v11 + 1) & 0xBF;
v17 = *(_BYTE *)(spriteram + v11 + 1) | 0x40;
if ( (v15 & 0x80u) == 0 )
{
v17 = *(_BYTE *)(spriteram + v11 + 1) & 0xBF;
v16 = *(_BYTE *)(spriteram + v11 + 1) | 0x40;
}
if ( flip_screen_x )
v12 = (_DWORD)v12 == 0;
v13 = ((v15 >> 5) & 1) << 8;
v22 = v16;
v21 = v12;
drawgfx(v2, *(_QWORD *)(Machine + 520LL), (unsigned int)(v13 + v17), v15 & 0x1F, v12);
v14 = *(_BYTE *)(spriteram + v11);
v11 -= 4LL;
drawgfx(v2, *(_QWORD *)(Machine + 520LL), (unsigned int)(v13 + v22), v14 & 0x1F, v21);
v23 -= 4;
}
while ( v23 >= 0 );
}
result = (__int64)yard_score_panel_disabled;
if ( !*yard_score_panel_disabled )
{
if ( flip_screen_x )
{
v19 = &panelvisibleareaflip;
v20 = (unsigned int)(*(_DWORD *)(Machine + 776LL) - 8);
}
else
{
v19 = &panelvisiblearea;
v20 = (unsigned int)(*(_DWORD *)(Machine + 780LL) - 55);
}
result = copybitmap(v2, scroll_panel_bitmap, flip_screen_x, flip_screen_x, v20, 0LL, v19, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v2; // r13
int v3; // ebx
__int64 v4; // r15
int v5; // er14
__int64 v6; // rcx
__int16 v7; // r11
char v8; // cl
__int64 v9; // r8
int v10; // eax
__int64 v11; // r15
__int64 v12; // r8
int v13; // ebx
char v14; // cl
unsigned int v15; // ecx
int v16; // er10
int v17; // esi
__int64 result; // rax
void *v19; // rax
__int64 v20; // r8
unsigned int v21; // [rsp+0h] [rbp-68h]
int v22; // [rsp+18h] [rbp-50h]
int v23; // [rsp+1Ch] [rbp-4Ch]
int v24; // [rsp+28h] [rbp-40h] BYREF
int v25[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v2 = a1;
if ( a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 2;
if ( (int)videoram_size - 2 < 0 )
goto LABEL_11;
}
else
{
v3 = videoram_size - 2;
if ( (int)videoram_size - 2 < 0 )
goto LABEL_11;
}
v4 = v3;
v5 = v3;
do
{
v6 = v4 + 1;
if ( *((_BYTE *)dirtybuffer + v4) || *((_BYTE *)dirtybuffer + v4 + 1) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
*((_BYTE *)dirtybuffer + v6) = 0;
v7 = *(unsigned __int8 *)(videoram + v6);
v8 = *(_BYTE *)(videoram + v6);
v9 = v8 & 0x20;
if ( flip_screen_x )
v9 = (_DWORD)v9 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + ((4 * v7) & 0x300u),
v8 & 0x1F,
v9);
}
v4 -= 2LL;
v5 -= 2;
}
while ( v5 >= 0 );
v2 = a1;
LABEL_11:
v10 = (unsigned __int8)*yard_scroll_x_low + ((unsigned __int8)*yard_scroll_x_high << 8);
if ( flip_screen_x )
{
v24 = v10 + 256;
v25[0] = (unsigned __int8)*yard_scroll_y_low;
}
else
{
v24 = -v10;
v25[0] = -(unsigned __int8)*yard_scroll_y_low;
}
copyscrollbitmap(v2, tmpbitmap, 1LL, &v24, 1LL, v25, Machine + 776LL, 0LL, 0LL);
v23 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v23 + 1LL;
do
{
v15 = *(unsigned __int8 *)(spriteram + v11);
v12 = *(_BYTE *)(spriteram + v11) & 0x40;
v16 = *(_BYTE *)(spriteram + v11 + 1) & 0xBF;
v17 = *(_BYTE *)(spriteram + v11 + 1) | 0x40;
if ( (v15 & 0x80u) == 0 )
{
v17 = *(_BYTE *)(spriteram + v11 + 1) & 0xBF;
v16 = *(_BYTE *)(spriteram + v11 + 1) | 0x40;
}
if ( flip_screen_x )
v12 = (_DWORD)v12 == 0;
v13 = ((v15 >> 5) & 1) << 8;
v22 = v16;
v21 = v12;
drawgfx(v2, *(_QWORD *)(Machine + 520LL), (unsigned int)(v13 + v17), v15 & 0x1F, v12);
v14 = *(_BYTE *)(spriteram + v11);
v11 -= 4LL;
drawgfx(v2, *(_QWORD *)(Machine + 520LL), (unsigned int)(v13 + v22), v14 & 0x1F, v21);
v23 -= 4;
}
while ( v23 >= 0 );
}
result = (__int64)yard_score_panel_disabled;
if ( !*yard_score_panel_disabled )
{
if ( flip_screen_x )
{
v19 = &panelvisibleareaflip;
v20 = (unsigned int)(*(_DWORD *)(Machine + 776LL) - 8);
}
else
{
v19 = &panelvisiblearea;
v20 = (unsigned int)(*(_DWORD *)(Machine + 780LL) - 55);
}
result = copybitmap(v2, scroll_panel_bitmap, flip_screen_x, flip_screen_x, v20, 0LL, v19, 0LL, 0LL);
}
return result;
}

original_code:
void yard_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx,sy,flipx;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   flipx = videoram[offs+1] & 0x20;
   if (sy >= 32)
   {
    sy -= 32;
    sx += 32;
   }
   if (flip_screen_x)
   {
    sx = 63 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0xc0) << 2),
     videoram[offs+1] & 0x1f,
     flipx,flip_screen_x,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll_x,scroll_y;
  scroll_x = (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low;
  if (flip_screen_x)
  {
   scroll_x += 256;
   scroll_y = *yard_scroll_y_low ;
  }
  else
  {
   scroll_x = -scroll_x;
   scroll_y = -*yard_scroll_y_low ;
  }
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll_x,1,&scroll_y,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int code1,code2,bank,sx,sy1,sy2,flipx,flipy;
  bank = (spriteram[offs + 1] & 0x20) >> 5;
  code1 = spriteram[offs + 2] & 0xbf;
  sx = spriteram[offs + 3];
  sy1 = 241 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flipy)
  {
   code2 = code1;
   code1 += 0x40;
  }
  else
  {
   code2 = code1 + 0x40;
  }
  if (flip_screen_x)
  {
   flipx = !flipx;
   flipy = !flipy;
   sx = 240 - sx;
   sy2 = 224 - sy1;
   sy1 = sy2 + 0x10;
  }
  else
  {
   sy2 = sy1 + 0x10;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code1 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy1,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
  drawgfx(bitmap,Machine->gfx[1],
    code2 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy2,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
 }
 if (! *yard_score_panel_disabled)
 {
  int xpos;
  xpos = flip_screen_x ? Machine->visible_area.min_x - 8 :
                       Machine->visible_area.max_x + 1 - (14*4);
  copybitmap(bitmap,scroll_panel_bitmap,flip_screen_x,flip_screen_x,
             xpos,0,
       flip_screen_x ? &panelvisibleareaflip : &panelvisiblearea,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
void yard_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx; int sy; int flipx;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   flipx = videoram[offs+1] & 0x20;
   if (sy >= 32)
   {
    sy -= 32;
    sx += 32;
   }
   if (flip_screen_x)
   {
    sx = 63 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0xc0) << 2),
     videoram[offs+1] & 0x1f,
     flipx,flip_screen_x,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll_x; int scroll_y;
  scroll_x = (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low;
  if (flip_screen_x)
  {
   scroll_x += 256;
   scroll_y = *yard_scroll_y_low ;
  }
  else
  {
   scroll_x = -scroll_x;
   scroll_y = -*yard_scroll_y_low ;
  }
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll_x,1,&scroll_y,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int code1; int code2; int bank; int sx; int sy1; int sy2; int flipx; int flipy;
  bank = (spriteram[offs + 1] & 0x20) >> 5;
  code1 = spriteram[offs + 2] & 0xbf;
  sx = spriteram[offs + 3];
  sy1 = 241 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flipy)
  {
   code2 = code1;
   code1 += 0x40;
  }
  else
  {
   code2 = code1 + 0x40;
  }
  if (flip_screen_x)
  {
   flipx = !flipx;
   flipy = !flipy;
   sx = 240 - sx;
   sy2 = 224 - sy1;
   sy1 = sy2 + 0x10;
  }
  else
  {
   sy2 = sy1 + 0x10;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code1 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy1,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
  drawgfx(bitmap,Machine->gfx[1],
    code2 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy2,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
 }
 if (! *yard_score_panel_disabled)
 {
  int xpos;
  xpos = flip_screen_x ? Machine->visible_area.min_x - 8 :
                       Machine->visible_area.max_x + 1 - (14*4);
  copybitmap(bitmap,scroll_panel_bitmap,flip_screen_x,flip_screen_x,
             xpos,0,
       flip_screen_x ? &panelvisibleareaflip : &panelvisiblearea,TRANSPARENCY_NONE,0);
 }
}

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

variable_types: offs int

variable_types: flipx int

variable_types: bank int

variable_types: flipy int

variable_types: xpos int


decompiled_code:
__int64 __fastcall jsa1_io_r(__int16 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // eax
__int64 v5; // rdi
unsigned int v6; // ebx
unsigned __int16 v7; // r8
unsigned int v8; // eax

v2 = a1 & 0x206;
if ( v2 == 4 )
{
v4 = readinputport((unsigned __int8)input_port);
v5 = (unsigned __int8)test_port;
v6 = v4;
v7 = readinputport((unsigned __int8)test_port);
v8 = v6;
if ( (v7 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v8) = v6 ^ 0x80;
v6 = v8;
}
if ( atarigen_cpu_to_sound_ready )
v6 ^= 0x40u;
if ( atarigen_sound_to_cpu_ready )
v6 ^= 0x20u;
if ( !has_tms5220 || (unsigned int)tms5220_ready_r(v5, a2, &atarigen_sound_to_cpu_ready) )
result = v6 ^ 0x10;
else
result = v6;
}
else if ( v2 == 6 )
{
atarigen_6502_irq_ack_r(0LL);
result = 255LL;
}
else
{
result = 255LL;
if ( v2 == 2 )
result = atarigen_6502_sound_r();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax
unsigned int v4; // eax
__int64 v5; // rdi
unsigned int v6; // ebx
unsigned __int16 v7; // r8
unsigned int v8; // eax

v2 = a1 & 0x206;
if ( v2 == 4 )
{
v4 = readinputport((unsigned __int8)input_port);
v5 = (unsigned __int8)test_port;
v6 = v4;
v7 = readinputport((unsigned __int8)test_port);
v8 = v6;
if ( (v7 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v8) = v6 ^ 0x80;
v6 = v8;
}
if ( atarigen_cpu_to_sound_ready )
v6 ^= 0x40u;
if ( atarigen_sound_to_cpu_ready )
v6 ^= 0x20u;
if ( !has_tms5220 || (unsigned int)tms5220_ready_r(v5, a2, &atarigen_sound_to_cpu_ready) )
result = v6 ^ 0x10;
else
result = v6;
}
else if ( v2 == 6 )
{
atarigen_6502_irq_ack_r(0LL);
result = 255LL;
}
else
{
result = 255LL;
if ( v2 == 2 )
result = atarigen_6502_sound_r();
}
return result;
}

original_code:
static data_t jsa1_io_r(offs_t offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x80;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   if (!has_tms5220 || tms5220_ready_r()) result ^= 0x10;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

canonical_original_code:
static unsigned int jsa1_io_r(unsigned int offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x80;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   if (!has_tms5220 || tms5220_ready_r()) result ^= 0x10;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

variable_types:
offset
unsigned int

variable_types: result int


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

if ( has_pokey )
{
result = atarigen_set_pokey_vol((unsigned __int8)pokey_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
if ( !has_ym2151 )
{
LABEL_3:
if ( !has_tms5220 )
goto LABEL_4;
goto LABEL_8;
}
}
else if ( !has_ym2151 )
{
goto LABEL_3;
}
result = atarigen_set_ym2151_vol((unsigned __int8)ym2151_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
if ( !has_tms5220 )
{
LABEL_4:
if ( !has_oki6295 )
return result;
return atarigen_set_oki6295_vol((unsigned __int8)oki6295_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
}
LABEL_8:
result = atarigen_set_tms5220_vol((unsigned __int8)tms5220_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
if ( has_oki6295 )
return atarigen_set_oki6295_vol((unsigned __int8)oki6295_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
return result;
}

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

if ( has_pokey )
{
result = atarigen_set_pokey_vol((unsigned __int8)pokey_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
if ( !has_ym2151 )
{
LABEL_3:
if ( !has_tms5220 )
goto LABEL_4;
goto LABEL_8;
}
}
else if ( !has_ym2151 )
{
goto LABEL_3;
}
result = atarigen_set_ym2151_vol((unsigned __int8)ym2151_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
if ( !has_tms5220 )
{
LABEL_4:
if ( !has_oki6295 )
return result;
return atarigen_set_oki6295_vol((unsigned __int8)oki6295_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
}
LABEL_8:
result = atarigen_set_tms5220_vol((unsigned __int8)tms5220_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
if ( has_oki6295 )
return atarigen_set_oki6295_vol((unsigned __int8)oki6295_volume * (unsigned int)(unsigned __int8)overall_volume / 0x64uLL);
return result;
}

original_code:
static void update_all_volumes(void)
{
 if (has_pokey) atarigen_set_pokey_vol(overall_volume * pokey_volume / 100);
 if (has_ym2151) atarigen_set_ym2151_vol(overall_volume * ym2151_volume / 100);
 if (has_tms5220) atarigen_set_tms5220_vol(overall_volume * tms5220_volume / 100);
 if (has_oki6295) atarigen_set_oki6295_vol(overall_volume * oki6295_volume / 100);
}

canonical_original_code:
static void update_all_volumes()
{
 if (has_pokey) atarigen_set_pokey_vol(overall_volume * pokey_volume / 100);
 if (has_ym2151) atarigen_set_ym2151_vol(overall_volume * ym2151_volume / 100);
 if (has_tms5220) atarigen_set_tms5220_vol(overall_volume * tms5220_volume / 100);
 if (has_oki6295) atarigen_set_oki6295_vol(overall_volume * oki6295_volume / 100);
}


decompiled_code:
__int64 __fastcall jsa1_io_w(__int16 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 result; // rax
__int64 v4; // rcx
_QWORD *v5; // rsi
char *v6; // rdi

v2 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w();
if ( (unsigned int)result <= 0x202 )
{
if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 )
{
speech_data = a2;
}
}
else if ( (_DWORD)result == 516 )
{
if ( has_tms5220 )
{
if ( (((unsigned __int8)a2 ^ (unsigned __int8)last_ctl) & 2) != 0 && (a2 & 2) != 0 )
{
a2 = (unsigned __int8)speech_data;
tms5220_data_w(0LL, (unsigned __int8)speech_data);
}
tms5220_set_frequency(
(unsigned int)(7159090 / (int)(16 - ((v2 >> 2) & 2 | 5))),
a2,
(unsigned int)(7159090 % (int)(16 - ((v2 >> 2) & 2 | 5))));
}
v4 = bank_base;
v5 = (_QWORD *)(bank_source_data + (((_WORD)v2 << 6) & 0x3000));
v6 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v5;
result = v5[511];
*(_QWORD *)(v4 + 4088) = result;
qmemcpy(v6, (char *)v5 - (v4 - (_QWORD)v6), 8LL * ((unsigned int)(v4 - (_DWORD)v6 + 4096) >> 3));
last_ctl = v2;
}
else if ( (_DWORD)result == 518 )
{
tms5220_volume = 100 * (unsigned int)((unsigned __int8)a2 >> 6) / 3;
pokey_volume = 100 * (((unsigned int)a2 >> 4) & 3) / 3;
ym2151_volume = 100 * (((unsigned int)a2 >> 1) & 7) / 7;
result = update_all_volumes();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __int64 a2)
{
unsigned int v2; // ebp
__int64 result; // rax
__int64 v4; // rcx
_QWORD *v5; // rsi
char *v6; // rdi

v2 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w();
if ( (unsigned int)result <= 0x202 )
{
if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 )
{
speech_data = a2;
}
}
else if ( (_DWORD)result == 516 )
{
if ( has_tms5220 )
{
if ( (((unsigned __int8)a2 ^ (unsigned __int8)last_ctl) & 2) != 0 && (a2 & 2) != 0 )
{
a2 = (unsigned __int8)speech_data;
tms5220_data_w(0LL, (unsigned __int8)speech_data);
}
tms5220_set_frequency(
(unsigned int)(7159090 / (int)(16 - ((v2 >> 2) & 2 | 5))),
a2,
(unsigned int)(7159090 % (int)(16 - ((v2 >> 2) & 2 | 5))));
}
v4 = bank_base;
v5 = (_QWORD *)(bank_source_data + (((_WORD)v2 << 6) & 0x3000));
v6 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v5;
result = v5[511];
*(_QWORD *)(v4 + 4088) = result;
qmemcpy(v6, (char *)v5 - (v4 - (_QWORD)v6), 8LL * ((unsigned int)(v4 - (_DWORD)v6 + 4096) >> 3));
last_ctl = v2;
}
else if ( (_DWORD)result == 518 )
{
tms5220_volume = 100 * (unsigned int)((unsigned __int8)a2 >> 6) / 3;
pokey_volume = 100 * (((unsigned int)a2 >> 4) & 3) / 3;
ym2151_volume = 100 * (((unsigned int)a2 >> 1) & 7) / 7;
result = func1();
}
return result;
}

original_code:
static void jsa1_io_w(offs_t offset,data_t data)
{
 switch (offset & 0x206)
 {
  case 0x000:
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   speech_data = data;
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   if (has_tms5220)
   {
    int count;
    if (((data ^ last_ctl) & 0x02) && (data & 0x02))
     tms5220_data_w(0, speech_data);
    count = 5 | ((data >> 2) & 2);
    tms5220_set_frequency(14318180/2 / (16 - count));
   }
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   break;
  case 0x206:
   tms5220_volume = ((data >> 6) & 3) * 100 / 3;
   pokey_volume = ((data >> 4) & 3) * 100 / 3;
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   update_all_volumes();
   break;
 }
}

canonical_original_code:
static void jsa1_io_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x206)
 {
  case 0x000:
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   speech_data = data;
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   if (has_tms5220)
   {
    int count;
    if (((data ^ last_ctl) & 0x02) && (data & 0x02))
     tms5220_data_w(0, speech_data);
    count = 5 | ((data >> 2) & 2);
    tms5220_set_frequency(14318180/2 / (16 - count));
   }
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   break;
  case 0x206:
   tms5220_volume = ((data >> 6) & 3) * 100 / 3;
   pokey_volume = ((data >> 4) & 3) * 100 / 3;
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   update_all_volumes();
   break;
 }
}

variable_types:
data
unsigned int

variable_types: count int


decompiled_code:
__int64 __fastcall jsa2_io_r(__int16 a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // ebx
unsigned __int16 v4; // r8
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v3 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v3;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v3 ^ 0x80;
v3 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v3 ^= 0x40u;
result = v3 ^ 0x20;
if ( !atarigen_sound_to_cpu_ready )
result = v3;
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
atarigen_6502_irq_ack_r(0LL);
return 255LL;
}
if ( (a1 & 0x206) != 0 )
{
if ( v1 == 2 )
return atarigen_6502_sound_r();
return 255LL;
}
result = 255LL;
if ( has_oki6295 )
result = OKIM6295_status_0_r();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // ebx
unsigned __int16 v4; // r8
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v3 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v3;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v3 ^ 0x80;
v3 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v3 ^= 0x40u;
result = v3 ^ 0x20;
if ( !atarigen_sound_to_cpu_ready )
result = v3;
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
atarigen_6502_irq_ack_r(0LL);
return 255LL;
}
if ( (a1 & 0x206) != 0 )
{
if ( v1 == 2 )
return atarigen_6502_sound_r();
return 255LL;
}
result = 255LL;
if ( has_oki6295 )
result = OKIM6295_status_0_r();
}
return result;
}

original_code:
static data_t jsa2_io_r(offs_t offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   if (has_oki6295)
    result = OKIM6295_status_0_r(offset);
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x80;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

canonical_original_code:
static unsigned int jsa2_io_r(unsigned int offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   if (has_oki6295)
    result = OKIM6295_status_0_r(offset);
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x80;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}


decompiled_code:
__int64 __fastcall jsa3_io_r(__int16 a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // ebx
unsigned __int16 v4; // r8
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v3 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v3;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v3 ^ 0x90;
v3 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v3 ^= 0x40u;
result = v3 ^ 0x20;
if ( !atarigen_sound_to_cpu_ready )
result = v3;
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
atarigen_6502_irq_ack_r(0LL);
return 255LL;
}
if ( (a1 & 0x206) != 0 )
{
if ( v1 == 2 )
return atarigen_6502_sound_r();
return 255LL;
}
result = 255LL;
if ( has_oki6295 )
result = OKIM6295_status_0_r();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // ebx
unsigned __int16 v4; // r8
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v3 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v3;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v3 ^ 0x90;
v3 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v3 ^= 0x40u;
result = v3 ^ 0x20;
if ( !atarigen_sound_to_cpu_ready )
result = v3;
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
atarigen_6502_irq_ack_r(0LL);
return 255LL;
}
if ( (a1 & 0x206) != 0 )
{
if ( v1 == 2 )
return atarigen_6502_sound_r();
return 255LL;
}
result = 255LL;
if ( has_oki6295 )
result = OKIM6295_status_0_r();
}
return result;
}

original_code:
static data_t jsa3_io_r(offs_t offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   if (has_oki6295)
    result = OKIM6295_status_0_r(offset);
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x90;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

canonical_original_code:
static unsigned int jsa3_io_r(unsigned int offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   if (has_oki6295)
    result = OKIM6295_status_0_r(offset);
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x90;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}


decompiled_code:
__int64 __fastcall jsa2_io_w(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
char v4; // r8
__int64 result; // rax
unsigned __int64 v6; // rdx
__int64 v7; // rcx
_QWORD *v8; // rsi
char *v9; // rdi

v4 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3, a4, (unsigned int)a2);
if ( (unsigned int)result <= 0x202 )
{
if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 && has_oki6295 )
{
result = OKIM6295_data_0_w(a1, a2, a3, a4, (unsigned int)a2);
}
}
else if ( (_DWORD)result == 516 )
{
v7 = bank_base;
v8 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
v9 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v8;
*(_QWORD *)(v7 + 4088) = v8[511];
qmemcpy(v9, (char *)v8 - (v7 - (_QWORD)v9), 8LL * ((unsigned int)(v7 - (_DWORD)v9 + 4096) >> 3));
last_ctl = v4;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (v4 & 8) == 0 ? 7231 : 9039);
}
else if ( (_DWORD)result == 518 )
{
v6 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v6 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v6) >> 1)) >> 2;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = update_all_volumes();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
char v4; // r8
__int64 result; // rax
unsigned __int64 v6; // rdx
__int64 v7; // rcx
_QWORD *v8; // rsi
char *v9; // rdi

v4 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3, a4, (unsigned int)a2);
if ( (unsigned int)result <= 0x202 )
{
if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 && has_oki6295 )
{
result = OKIM6295_data_0_w(a1, a2, a3, a4, (unsigned int)a2);
}
}
else if ( (_DWORD)result == 516 )
{
v7 = bank_base;
v8 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
v9 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v8;
*(_QWORD *)(v7 + 4088) = v8[511];
qmemcpy(v9, (char *)v8 - (v7 - (_QWORD)v9), 8LL * ((unsigned int)(v7 - (_DWORD)v9 + 4096) >> 3));
last_ctl = v4;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (v4 & 8) == 0 ? 7231 : 9039);
}
else if ( (_DWORD)result == 518 )
{
v6 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v6 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v6) >> 1)) >> 2;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = func1();
}
return result;
}

original_code:
static void jsa2_io_w(offs_t offset,data_t data)
{
 switch (offset & 0x206)
 {
  case 0x000:
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   if (has_oki6295)
    OKIM6295_data_0_w(offset, data);
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   OKIM6295_set_frequency(0, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   break;
  case 0x206:
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   oki6295_volume = 50 + (data & 1) * 50;
   update_all_volumes();
   break;
 }
}

canonical_original_code:
static void jsa2_io_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x206)
 {
  case 0x000:
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   if (has_oki6295)
    OKIM6295_data_0_w(offset, data);
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   OKIM6295_set_frequency(0, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   break;
  case 0x206:
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   oki6295_volume = 50 + (data & 1) * 50;
   update_all_volumes();
   break;
 }
}


decompiled_code:
__int64 __fastcall jsa3_io_w(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
char v5; // bp
__int64 result; // rax
__int64 v7; // rcx
_QWORD *v8; // rsi
char *v9; // rdi

v5 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3, a4, a5);
if ( (unsigned int)result > 0x202 )
{
if ( (_DWORD)result == 516 )
{
oki6295_bank_base = oki6295_bank_base & 0x80000 | ((_DWORD)a2 << 17) & 0x40000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
v7 = bank_base;
v8 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
v9 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v8;
*(_QWORD *)(v7 + 4088) = v8[511];
qmemcpy(v9, (char *)v8 - (v7 - (_QWORD)v9), 8LL * ((unsigned int)(v7 - (_DWORD)v9 + 4096) >> 3));
last_ctl = v5;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (v5 & 8) == 0 ? 7231 : 9039);
}
else if ( (_DWORD)result == 518 )
{
oki6295_bank_base = oki6295_bank_base & 0x40000 | ((_DWORD)a2 << 15) & 0x80000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
ym2151_volume = 100 * (((unsigned int)a2 >> 1) & 7) / 7;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = update_all_volumes();
}
}
else if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 )
{
if ( has_oki6295 )
result = OKIM6295_data_0_w(a1, a2, a3, a4, a5);
}
else if ( (a1 & 0x206) == 0 )
{
overall_volume = 100 * (int)a2 / 0x7Fu;
result = update_all_volumes();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
char v5; // bp
__int64 result; // rax
__int64 v7; // rcx
_QWORD *v8; // rsi
char *v9; // rdi

v5 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3, a4, a5);
if ( (unsigned int)result > 0x202 )
{
if ( (_DWORD)result == 516 )
{
oki6295_bank_base = oki6295_bank_base & 0x80000 | ((_DWORD)a2 << 17) & 0x40000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
v7 = bank_base;
v8 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
v9 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v8;
*(_QWORD *)(v7 + 4088) = v8[511];
qmemcpy(v9, (char *)v8 - (v7 - (_QWORD)v9), 8LL * ((unsigned int)(v7 - (_DWORD)v9 + 4096) >> 3));
last_ctl = v5;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (v5 & 8) == 0 ? 7231 : 9039);
}
else if ( (_DWORD)result == 518 )
{
oki6295_bank_base = oki6295_bank_base & 0x40000 | ((_DWORD)a2 << 15) & 0x80000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
ym2151_volume = 100 * (((unsigned int)a2 >> 1) & 7) / 7;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = func1();
}
}
else if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 )
{
if ( has_oki6295 )
result = OKIM6295_data_0_w(a1, a2, a3, a4, a5);
}
else if ( (a1 & 0x206) == 0 )
{
overall_volume = 100 * (int)a2 / 0x7Fu;
result = func1();
}
return result;
}

original_code:
static void jsa3_io_w(offs_t offset,data_t data)
{
 switch (offset & 0x206)
 {
  case 0x000:
   overall_volume = data * 100 / 127;
   update_all_volumes();
   break;
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   if (has_oki6295)
    OKIM6295_data_0_w(offset, data);
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   oki6295_bank_base = (0x40000 * ((data >> 1) & 1)) | (oki6295_bank_base & 0x80000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   OKIM6295_set_frequency(0, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   break;
  case 0x206:
   oki6295_bank_base = (0x80000 * ((data >> 4) & 1)) | (oki6295_bank_base & 0x40000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   oki6295_volume = 50 + (data & 1) * 50;
   update_all_volumes();
   break;
 }
}

canonical_original_code:
static void jsa3_io_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x206)
 {
  case 0x000:
   overall_volume = data * 100 / 127;
   update_all_volumes();
   break;
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   if (has_oki6295)
    OKIM6295_data_0_w(offset, data);
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   oki6295_bank_base = (0x40000 * ((data >> 1) & 1)) | (oki6295_bank_base & 0x80000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   OKIM6295_set_frequency(0, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   break;
  case 0x206:
   oki6295_bank_base = (0x80000 * ((data >> 4) & 1)) | (oki6295_bank_base & 0x40000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   oki6295_volume = 50 + (data & 1) * 50;
   update_all_volumes();
   break;
 }
}


decompiled_code:
__int64 __fastcall jsa3s_io_r(__int16 a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // ebx
unsigned __int16 v4; // r8
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v3 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v3;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v3 ^ 0x90;
v3 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v3 ^= 0x40u;
result = v3 ^ 0x20;
if ( !atarigen_sound_to_cpu_ready )
result = v3;
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
{
atarigen_6502_irq_ack_r(0LL);
return 255LL;
}
return 255LL;
}
if ( (a1 & 0x206) != 0 )
{
if ( v1 == 2 )
return atarigen_6502_sound_r();
return 255LL;
}
if ( !has_oki6295 )
return 255LL;
if ( (a1 & 1) != 0 )
result = OKIM6295_status_1_r();
else
result = OKIM6295_status_0_r();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // ebx
unsigned __int16 v4; // r8
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v3 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v3;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v3 ^ 0x90;
v3 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v3 ^= 0x40u;
result = v3 ^ 0x20;
if ( !atarigen_sound_to_cpu_ready )
result = v3;
}
else
{
if ( v1 > 4 )
{
if ( v1 == 6 )
{
atarigen_6502_irq_ack_r(0LL);
return 255LL;
}
return 255LL;
}
if ( (a1 & 0x206) != 0 )
{
if ( v1 == 2 )
return atarigen_6502_sound_r();
return 255LL;
}
if ( !has_oki6295 )
return 255LL;
if ( (a1 & 1) != 0 )
result = OKIM6295_status_1_r();
else
result = OKIM6295_status_0_r();
}
return result;
}

original_code:
static data_t jsa3s_io_r(offs_t offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   if (has_oki6295)
   {
    if (offset & 1)
     result = OKIM6295_status_1_r(offset);
    else
     result = OKIM6295_status_0_r(offset);
   }
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x90;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

canonical_original_code:
static unsigned int jsa3s_io_r(unsigned int offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   if (has_oki6295)
   {
    if (offset & 1)
     result = OKIM6295_status_1_r(offset);
    else
     result = OKIM6295_status_0_r(offset);
   }
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x90;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}


decompiled_code:
__int64 __fastcall jsa3s_io_w(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 result; // rax
char v6; // bp
__int64 v7; // rcx
_QWORD *v8; // rsi
char *v9; // rdi
unsigned int v10; // er12

result = a1 & 0x206;
v6 = a2;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3, a4, a5);
if ( (unsigned int)result > 0x202 )
{
if ( (_DWORD)result == 516 )
{
oki6295_bank_base = oki6295_bank_base & 0x80000 | ((_DWORD)a2 << 17) & 0x40000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
v7 = bank_base;
v8 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
v9 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v8;
*(_QWORD *)(v7 + 4088) = v8[511];
qmemcpy(v9, (char *)v8 - (v7 - (_QWORD)v9), 8LL * ((unsigned int)(v7 - (_DWORD)v9 + 4096) >> 3));
last_ctl = v6;
v10 = (v6 & 8) == 0 ? 7231 : 9039;
OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, v10);
result = OKIM6295_set_frequency(1LL, 0xFFFFFFFFLL, v10);
}
else if ( (_DWORD)result == 518 )
{
oki6295_bank_base = oki6295_bank_base & 0x40000 | ((_DWORD)a2 << 15) & 0x80000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
OKIM6295_set_bank_base(1LL, 0xFFFFFFFFLL);
ym2151_volume = 100 * (((unsigned int)a2 >> 1) & 7) / 7;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = update_all_volumes();
}
}
else if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 )
{
if ( has_oki6295 )
{
if ( (a1 & 1) != 0 )
result = OKIM6295_data_1_w();
else
result = OKIM6295_data_0_w(a1, a2, a3, a4, a5);
}
}
else if ( (a1 & 0x206) == 0 )
{
overall_volume = 100 * (int)a2 / 0x7Fu;
result = update_all_volumes();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 result; // rax
char v6; // bp
__int64 v7; // rcx
_QWORD *v8; // rsi
char *v9; // rdi
unsigned int v10; // er12

result = a1 & 0x206;
v6 = a2;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3, a4, a5);
if ( (unsigned int)result > 0x202 )
{
if ( (_DWORD)result == 516 )
{
oki6295_bank_base = oki6295_bank_base & 0x80000 | ((_DWORD)a2 << 17) & 0x40000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
v7 = bank_base;
v8 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
v9 = (char *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
*(_QWORD *)bank_base = *v8;
*(_QWORD *)(v7 + 4088) = v8[511];
qmemcpy(v9, (char *)v8 - (v7 - (_QWORD)v9), 8LL * ((unsigned int)(v7 - (_DWORD)v9 + 4096) >> 3));
last_ctl = v6;
v10 = (v6 & 8) == 0 ? 7231 : 9039;
OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, v10);
result = OKIM6295_set_frequency(1LL, 0xFFFFFFFFLL, v10);
}
else if ( (_DWORD)result == 518 )
{
oki6295_bank_base = oki6295_bank_base & 0x40000 | ((_DWORD)a2 << 15) & 0x80000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
OKIM6295_set_bank_base(1LL, 0xFFFFFFFFLL);
ym2151_volume = 100 * (((unsigned int)a2 >> 1) & 7) / 7;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = func1();
}
}
else if ( (_DWORD)result == 6 )
{
result = atarigen_6502_irq_ack_r(0LL);
}
else if ( (_DWORD)result == 512 )
{
if ( has_oki6295 )
{
if ( (a1 & 1) != 0 )
result = OKIM6295_data_1_w();
else
result = OKIM6295_data_0_w(a1, a2, a3, a4, a5);
}
}
else if ( (a1 & 0x206) == 0 )
{
overall_volume = 100 * (int)a2 / 0x7Fu;
result = func1();
}
return result;
}

original_code:
static void jsa3s_io_w(offs_t offset,data_t data)
{
 switch (offset & 0x206)
 {
  case 0x000:
   overall_volume = data * 100 / 127;
   update_all_volumes();
   break;
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   if (has_oki6295)
   {
    if (offset & 1)
     OKIM6295_data_1_w(offset, data);
    else
     OKIM6295_data_0_w(offset, data);
   }
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   oki6295_bank_base = (0x40000 * ((data >> 1) & 1)) | (oki6295_bank_base & 0x80000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   OKIM6295_set_frequency(0, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   OKIM6295_set_frequency(1, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   break;
  case 0x206:
   oki6295_bank_base = (0x80000 * ((data >> 4) & 1)) | (oki6295_bank_base & 0x40000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   OKIM6295_set_bank_base(1, -1, 0x40000 * (data >> 6));
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   oki6295_volume = 50 + (data & 1) * 50;
   update_all_volumes();
   break;
 }
}

canonical_original_code:
static void jsa3s_io_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x206)
 {
  case 0x000:
   overall_volume = data * 100 / 127;
   update_all_volumes();
   break;
  case 0x002:
  case 0x004:
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
   if (has_oki6295)
   {
    if (offset & 1)
     OKIM6295_data_1_w(offset, data);
    else
     OKIM6295_data_0_w(offset, data);
   }
   break;
  case 0x202:
   atarigen_6502_sound_w(offset, data);
   break;
  case 0x204:
   oki6295_bank_base = (0x40000 * ((data >> 1) & 1)) | (oki6295_bank_base & 0x80000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
   last_ctl = data;
   OKIM6295_set_frequency(0, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   OKIM6295_set_frequency(1, -1, 14318180/4/3 / ((data & 8) ? 132 : 165));
   break;
  case 0x206:
   oki6295_bank_base = (0x80000 * ((data >> 4) & 1)) | (oki6295_bank_base & 0x40000);
   OKIM6295_set_bank_base(0, -1, oki6295_bank_base);
   OKIM6295_set_bank_base(1, -1, 0x40000 * (data >> 6));
   ym2151_volume = ((data >> 1) & 7) * 100 / 7;
   oki6295_volume = 50 + (data & 1) * 50;
   update_all_volumes();
   break;
 }
}


decompiled_code:
__int64 atarijsa_reset()
{
__int64 v0; // rsi
__int64 v1; // rcx
void *v2; // rdi
__int64 result; // rax

atarigen_sound_io_reset((unsigned __int8)cpu_num);
v0 = bank_source_data;
speech_data = 0;
last_ctl = 0;
v1 = bank_base;
oki6295_bank_base = 0;
overall_volume = 100;
pokey_volume = 100;
v2 = (void *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
ym2151_volume = 100;
tms5220_volume = 100;
oki6295_volume = 100;
*(_QWORD *)bank_base = *(_QWORD *)bank_source_data;
result = *(_QWORD *)(v0 + 4088);
*(_QWORD *)(v1 + 4088) = result;
qmemcpy(v2, (const void *)(v0 - (v1 - (_QWORD)v2)), 8LL * ((unsigned int)(v1 - (_DWORD)v2 + 4096) >> 3));
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rsi
__int64 v1; // rcx
void *v2; // rdi
__int64 result; // rax

atarigen_sound_io_reset((unsigned __int8)cpu_num);
v0 = bank_source_data;
speech_data = 0;
last_ctl = 0;
v1 = bank_base;
oki6295_bank_base = 0;
overall_volume = 100;
pokey_volume = 100;
v2 = (void *)((bank_base + 8) & 0xFFFFFFFFFFFFFFF8LL);
ym2151_volume = 100;
tms5220_volume = 100;
oki6295_volume = 100;
*(_QWORD *)bank_base = *(_QWORD *)bank_source_data;
result = *(_QWORD *)(v0 + 4088);
*(_QWORD *)(v1 + 4088) = result;
qmemcpy(v2, (const void *)(v0 - (v1 - (_QWORD)v2)), 8LL * ((unsigned int)(v1 - (_DWORD)v2 + 4096) >> 3));
return result;
}

original_code:
void atarijsa_reset(void)
{
 atarigen_sound_io_reset(cpu_num);
 speech_data = 0;
 last_ctl = 0;
 oki6295_bank_base = 0x00000;
 overall_volume = 100;
 pokey_volume = 100;
 ym2151_volume = 100;
 tms5220_volume = 100;
 oki6295_volume = 100;
 memcpy(bank_base, &bank_source_data[0x0000], 0x1000);
}

canonical_original_code:
void atarijsa_reset()
{
 atarigen_sound_io_reset(cpu_num);
 speech_data = 0;
 last_ctl = 0;
 oki6295_bank_base = 0x00000;
 overall_volume = 100;
 pokey_volume = 100;
 ym2151_volume = 100;
 tms5220_volume = 100;
 oki6295_volume = 100;
 memcpy(bank_base, &bank_source_data[0x0000], 0x1000);
}


original_code:
void atarijsa_init(int cpunum, int inputport, int testport, int testmask)
{
 int i;
 cpu_num = cpunum;
 input_port = inputport;
 test_port = testport;
 test_mask = testmask;
 bank_base = &memory_region(REGION_CPU1+cpunum)[0x03000];
 bank_source_data = &memory_region(REGION_CPU1+cpunum)[0x10000];
 has_tms5220 = has_oki6295 = has_pokey = has_ym2151 = 0;
 for (i = 0; i < 5; i++)
 {
  switch (Machine->drv->sound[i].sound_type)
  {
   case SOUND_TMS5220:
    has_tms5220 = 1;
    break;
   case SOUND_OKIM6295:
    has_oki6295 = 1;
    break;
   case SOUND_POKEY:
    has_pokey = 1;
    break;
   case SOUND_YM2151:
    has_ym2151 = 1;
    break;
  }
 }
 if (has_pokey)
 {
  install_mem_read_handler(cpunum, 0x2c00, 0x2c0f, pokey1_r);
  install_mem_write_handler(cpunum, 0x2c00, 0x2c0f, pokey1_w);
 }
 atarijsa_reset();
}

variable_types: cpunum int

variable_types: inputport int

variable_types: testport int

variable_types: testmask int


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700 | (*(_WORD *)(ultraman_regs + 24LL) << 6) & 0x800;
result = dword_630 + ((*a2 >> 3) & 0x1Fu);
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700 | (*(_WORD *)(ultraman_regs + 24LL) << 6) & 0x800;
result = dword_630 + ((*a2 >> 3) & 0x1Fu);
*a2 = result;
return result;
}

original_code:
static void zoom_callback_2(int *code,int *color)
{
 unsigned short data = (*(UINT16 *)(&ultraman_regs[0x18]));
 *code |= ((*color & 0x07) << 8) | (data & 0x20) << 6;
 *color = zoom_colorbase[2] + ((*color & 0xf8) >> 3);
}

canonical_original_code:
static void zoom_callback_2(int *code, int *color)
{
 unsigned short data = (*(UINT16 *)(&ultraman_regs[0x18]));
 *code |= ((*color & 0x07) << 8) | (data & 0x20) << 6;
 *color = zoom_colorbase[2] + ((*color & 0xf8) >> 3);
}

variable_types:
code
int *

variable_types:
color
int *

variable_types:
data
unsigned short


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

sprite_colorbase = 192;
zoom_colorbase = 0x4000000000LL;
dword_630 = 128;
if ( (unsigned int)K051960_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
return 1LL;
if ( (unsigned int)K051316_vh_start_0(138LL, 4LL, zoom_callback_0) )
{
K051960_vh_stop();
result = 1LL;
}
else if ( (unsigned int)K051316_vh_start_1(139LL, 4LL, zoom_callback_1) )
{
K051960_vh_stop();
K051316_vh_stop_0();
result = 1LL;
}
else
{
if ( (unsigned int)K051316_vh_start_2(140LL, 4LL, zoom_callback_2) )
{
K051960_vh_stop();
K051316_vh_stop_0();
K051316_vh_stop_1();
return 1LL;
}
K051316_set_offset(0LL, 8LL, 0LL);
K051316_set_offset(1LL, 8LL, 0LL);
K051316_set_offset(2LL, 8LL, 0LL);
result = 0LL;
}
return result;
}

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

sprite_colorbase = 192;
zoom_colorbase = 0x4000000000LL;
dword_630 = 128;
if ( (unsigned int)K051960_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
return 1LL;
if ( (unsigned int)K051316_vh_start_0(138LL, 4LL, zoom_callback_0) )
{
K051960_vh_stop();
result = 1LL;
}
else if ( (unsigned int)K051316_vh_start_1(139LL, 4LL, zoom_callback_1) )
{
K051960_vh_stop();
K051316_vh_stop_0();
result = 1LL;
}
else
{
if ( (unsigned int)K051316_vh_start_2(140LL, 4LL, zoom_callback_2) )
{
K051960_vh_stop();
K051316_vh_stop_0();
K051316_vh_stop_1();
return 1LL;
}
K051316_set_offset(0LL, 8LL, 0LL);
K051316_set_offset(1LL, 8LL, 0LL);
K051316_set_offset(2LL, 8LL, 0LL);
result = 0LL;
}
return result;
}

original_code:
int ultraman_vh_start(void)
{
 sprite_colorbase = 192;
 zoom_colorbase[0] = 0;
 zoom_colorbase[1] = 64;
 zoom_colorbase[2] = 128;
 if (K051960_vh_start(REGION_GFX1,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX2,4,zoom_callback_0))
 {
  K051960_vh_stop();
  return 1;
 }
 if (K051316_vh_start_1(REGION_GFX3,4,zoom_callback_1))
 {
  K051960_vh_stop();
  K051316_vh_stop_0();
  return 1;
 }
 if (K051316_vh_start_2(REGION_GFX4,4,zoom_callback_2))
 {
  K051960_vh_stop();
  K051316_vh_stop_0();
  K051316_vh_stop_1();
  return 1;
 }
 K051316_set_offset(0, 8, 0);
 K051316_set_offset(1, 8, 0);
 K051316_set_offset(2, 8, 0);
 return 0;
}

canonical_original_code:
int ultraman_vh_start()
{
 sprite_colorbase = 192;
 zoom_colorbase[0] = 0;
 zoom_colorbase[1] = 64;
 zoom_colorbase[2] = 128;
 if (K051960_vh_start(REGION_GFX1,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX2,4,zoom_callback_0))
 {
  K051960_vh_stop();
  return 1;
 }
 if (K051316_vh_start_1(REGION_GFX3,4,zoom_callback_1))
 {
  K051960_vh_stop();
  K051316_vh_stop_0();
  return 1;
 }
 if (K051316_vh_start_2(REGION_GFX4,4,zoom_callback_2))
 {
  K051960_vh_stop();
  K051316_vh_stop_0();
  K051316_vh_stop_1();
  return 1;
 }
 K051316_set_offset(0, 8, 0);
 K051316_set_offset(1, 8, 0);
 K051316_set_offset(2, 8, 0);
 return 0;
}


decompiled_code:
__int64 __fastcall ultraman_vh_screenrefresh(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // r8
__int64 v6; // rcx

K051316_tilemap_update_0();
K051316_tilemap_update_1();
K051316_tilemap_update_2();
palette_init_used_colors();
K051960_mark_sprites_colors();
v2 = 16 * (SHIDWORD(zoom_colorbase) - (__int64)(int)zoom_colorbase);
v3 = 16 * (int)zoom_colorbase;
v4 = 16 * (dword_630 - (__int64)(int)zoom_colorbase);
v5 = v3 + 1024;
do
{
*(_BYTE *)(palette_used_colors + v3) = 7;
*(_BYTE *)(v2 + palette_used_colors + v3) = 7;
v6 = v3 + palette_used_colors;
v3 += 16LL;
*(_BYTE *)(v6 + v4) = 7;
}
while ( v3 != v5 );
if ( palette_recalc(v2, v4, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * dword_630), Machine + 776LL);
K051316_zoom_draw_2(a1, 0LL);
K051316_zoom_draw_1(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K051316_zoom_draw_0(a1, 0LL);
return K051960_sprites_draw(a1, 1LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rsi
__int64 v5; // r8
__int64 v6; // rcx

K051316_tilemap_update_0();
K051316_tilemap_update_1();
K051316_tilemap_update_2();
palette_init_used_colors();
K051960_mark_sprites_colors();
v2 = 16 * (SHIDWORD(zoom_colorbase) - (__int64)(int)zoom_colorbase);
v3 = 16 * (int)zoom_colorbase;
v4 = 16 * (dword_630 - (__int64)(int)zoom_colorbase);
v5 = v3 + 1024;
do
{
*(_BYTE *)(palette_used_colors + v3) = 7;
*(_BYTE *)(v2 + palette_used_colors + v3) = 7;
v6 = v3 + palette_used_colors;
v3 += 16LL;
*(_BYTE *)(v6 + v4) = 7;
}
while ( v3 != v5 );
if ( palette_recalc(v2, v4, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * dword_630), Machine + 776LL);
K051316_zoom_draw_2(a1, 0LL);
K051316_zoom_draw_1(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K051316_zoom_draw_0(a1, 0LL);
return K051960_sprites_draw(a1, 1LL, 1LL);
}

original_code:
void ultraman_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i;
 K051316_tilemap_update_0();
 K051316_tilemap_update_1();
 K051316_tilemap_update_2();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0;i < 64;i++)
 {
  palette_used_colors[(zoom_colorbase[0] + i) * 16] = (4|(1|2));
  palette_used_colors[(zoom_colorbase[1] + i) * 16] = (4|(1|2));
  palette_used_colors[(zoom_colorbase[2] + i) * 16] = (4|(1|2));
 }
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[zoom_colorbase[2] * 16],&Machine->visible_area);
 K051316_zoom_draw_2(bitmap,0);
 K051316_zoom_draw_1(bitmap,0);
 K051960_sprites_draw(bitmap,0,0);
 K051316_zoom_draw_0(bitmap,0);
 K051960_sprites_draw(bitmap,1,1);
}

canonical_original_code:
void ultraman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 K051316_tilemap_update_0();
 K051316_tilemap_update_1();
 K051316_tilemap_update_2();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0;i < 64;i++)
 {
  palette_used_colors[(zoom_colorbase[0] + i) * 16] = (4|(1|2));
  palette_used_colors[(zoom_colorbase[1] + i) * 16] = (4|(1|2));
  palette_used_colors[(zoom_colorbase[2] + i) * 16] = (4|(1|2));
 }
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[zoom_colorbase[2] * 16],&Machine->visible_area);
 K051316_zoom_draw_2(bitmap,0);
 K051316_zoom_draw_1(bitmap,0);
 K051960_sprites_draw(bitmap,0,0);
 K051316_zoom_draw_0(bitmap,0);
 K051960_sprites_draw(bitmap,1,1);
}

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

variable_types: i int


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

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

original_code:
static void init_ultraman(void)
{
 konami_rom_deinterleave_2(REGION_GFX1);
}

canonical_original_code:
static void init_ultraman()
{
 konami_rom_deinterleave_2(REGION_GFX1);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051960_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051960_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051960_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051960_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051960_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051960_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051937_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051937_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051937_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051937_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051937_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051937_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_2_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_2_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051316_ctrl_2_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_2_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051316_ctrl_2_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_2_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_1_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_1_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051316_ctrl_1_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_1_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051316_ctrl_1_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_1_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051316_ctrl_0_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_0_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051316_ctrl_0_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_0_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_2_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_2_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051316_2_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_2_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051316_2_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_2_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_1_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_1_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051316_1_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_1_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051316_1_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_1_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void ultraman_K051316_0_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_0_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void ultraman_K051316_0_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_0_w(offset >> 1, data & 0xff);
}


decompiled_code:
__int64 __fastcall ultraman_K051960_r(unsigned int a1)
{
return K051960_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
return K051960_r(a1 >> 1);
}

original_code:
static data_t ultraman_K051960_r(offs_t offset)
{
 return K051960_r(offset >> 1);
}

canonical_original_code:
static unsigned int ultraman_K051960_r(unsigned int offset)
{
 return K051960_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall ultraman_K051937_r(unsigned int a1)
{
return K051937_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
return K051937_r(a1 >> 1);
}

original_code:
static data_t ultraman_K051937_r(offs_t offset)
{
 return K051937_r(offset >> 1);
}

canonical_original_code:
static unsigned int ultraman_K051937_r(unsigned int offset)
{
 return K051937_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall ultraman_K051316_2_r(unsigned int a1)
{
return K051316_2_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1)
{
return K051316_2_r(a1 >> 1);
}

original_code:
static data_t ultraman_K051316_2_r(offs_t offset)
{
 return K051316_2_r(offset >> 1);
}

canonical_original_code:
static unsigned int ultraman_K051316_2_r(unsigned int offset)
{
 return K051316_2_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall ultraman_K051316_1_r(unsigned int a1)
{
return K051316_1_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1)
{
return K051316_1_r(a1 >> 1);
}

original_code:
static data_t ultraman_K051316_1_r(offs_t offset)
{
 return K051316_1_r(offset >> 1);
}

canonical_original_code:
static unsigned int ultraman_K051316_1_r(unsigned int offset)
{
 return K051316_1_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall ultraman_K051316_0_r(unsigned int a1)
{
return K051316_0_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1)
{
return K051316_0_r(a1 >> 1);
}

original_code:
static data_t ultraman_K051316_0_r(offs_t offset)
{
 return K051316_0_r(offset >> 1);
}

canonical_original_code:
static unsigned int ultraman_K051316_0_r(unsigned int offset)
{
 return K051316_0_r(offset >> 1);
}


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

*a3 = (*a2 >> 7) & 1;
result = sprite_colorbase + ((*a2 >> 1) & 0x3Fu);
*a2 = result;
return result;
}

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

*a3 = (*a2 >> 7) & 1;
result = sprite_colorbase + ((*a2 >> 1) & 0x3Fu);
*a2 = result;
return result;
}

original_code:
static void sprite_callback(int *code,int *color,int *priority,int *shadow)
{
 *priority = (*color & 0x80) >> 7;
 *color = sprite_colorbase + ((*color & 0x7e) >> 1);
}

canonical_original_code:
static void sprite_callback(int *code, int *color, int *priority, int *shadow)
{
 *priority = (*color & 0x80) >> 7;
 *color = sprite_colorbase + ((*color & 0x7e) >> 1);
}

variable_types:
priority
int *

variable_types:
shadow
int *


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700 | (*(_WORD *)(ultraman_regs + 24LL) << 10) & 0x800;
result = (unsigned int)zoom_colorbase + ((*a2 >> 3) & 0x1F);
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700 | (*(_WORD *)(ultraman_regs + 24LL) << 10) & 0x800;
result = (unsigned int)zoom_colorbase + ((*a2 >> 3) & 0x1F);
*a2 = result;
return result;
}

original_code:
static void zoom_callback_0(int *code,int *color)
{
 unsigned short data = (*(UINT16 *)(&ultraman_regs[0x18]));
 *code |= ((*color & 0x07) << 8) | (data & 0x02) << 10;
 *color = zoom_colorbase[0] + ((*color & 0xf8) >> 3);
}

canonical_original_code:
static void zoom_callback_0(int *code, int *color)
{
 unsigned short data = (*(UINT16 *)(&ultraman_regs[0x18]));
 *code |= ((*color & 0x07) << 8) | (data & 0x02) << 10;
 *color = zoom_colorbase[0] + ((*color & 0xf8) >> 3);
}


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700 | (*(_WORD *)(ultraman_regs + 24LL) << 8) & 0x800;
result = HIDWORD(zoom_colorbase) + ((*a2 >> 3) & 0x1Fu);
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700 | (*(_WORD *)(ultraman_regs + 24LL) << 8) & 0x800;
result = HIDWORD(zoom_colorbase) + ((*a2 >> 3) & 0x1Fu);
*a2 = result;
return result;
}

original_code:
static void zoom_callback_1(int *code,int *color)
{
 unsigned short data = (*(UINT16 *)(&ultraman_regs[0x18]));
 *code |= ((*color & 0x07) << 8) | (data & 0x08) << 8;
 *color = zoom_colorbase[1] + ((*color & 0xf8) >> 3);
}

canonical_original_code:
static void zoom_callback_1(int *code, int *color)
{
 unsigned short data = (*(UINT16 *)(&ultraman_regs[0x18]));
 *code |= ((*color & 0x07) << 8) | (data & 0x08) << 8;
 *color = zoom_colorbase[1] + ((*color & 0xf8) >> 3);
}


decompiled_code:
__int64 scramble_protection_r()
{
return 111LL;
}

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

original_code:
data_t scramble_protection_r(offs_t offset)
{
 return 0x6f;
}

canonical_original_code:
unsigned int scramble_protection_r(unsigned int offset)
{
 return 0x6f;
}


decompiled_code:
__int64 mariner_protection_1_r()
{
return 7LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 7LL;
}

original_code:
data_t mariner_protection_1_r(offs_t offset)
{
 return 7;
}

canonical_original_code:
unsigned int mariner_protection_1_r(unsigned int offset)
{
 return 7;
}


decompiled_code:
__int64 mariner_protection_2_r()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 3LL;
}

original_code:
data_t mariner_protection_2_r(offs_t offset)
{
 return 3;
}

canonical_original_code:
unsigned int mariner_protection_2_r(unsigned int offset)
{
 return 3;
}


decompiled_code:
__int64 ckongs_input_port_2_r()
{
char v0; // bl

v0 = readinputport(2LL);
return v0 & 0xF9 | (2 * (unsigned __int8)readinputport(1LL)) & 6u;
}

canonical_decompiled_code:
__int64 func3()
{
char v0; // bl

v0 = readinputport(2LL);
return v0 & 0xF9 | (2 * (unsigned __int8)readinputport(1LL)) & 6u;
}

original_code:
static data_t ckongs_input_port_2_r(offs_t offset)
{
 return (readinputport(2) & 0xf9) | ((readinputport(1) & 0x03) << 1);
}

canonical_original_code:
static unsigned int ckongs_input_port_2_r(unsigned int offset)
{
 return (readinputport(2) & 0xf9) | ((readinputport(1) & 0x03) << 1);
}


decompiled_code:
__int64 ckongs_input_port_1_r()
{
char v0; // bl

v0 = readinputport(1LL);
return v0 & 0xFC | ((int)readinputport(2LL) >> 1) & 3u;
}

canonical_decompiled_code:
__int64 func4()
{
char v0; // bl

v0 = readinputport(1LL);
return v0 & 0xFC | ((int)readinputport(2LL) >> 1) & 3u;
}

original_code:
static data_t ckongs_input_port_1_r(offs_t offset)
{
 return (readinputport(1) & 0xfc) | ((readinputport(2) & 0x06) >> 1);
}

canonical_original_code:
static unsigned int ckongs_input_port_1_r(unsigned int offset)
{
 return (readinputport(1) & 0xfc) | ((readinputport(2) & 0x06) >> 1);
}


decompiled_code:
__int64 scramble_input_port_2_r()
{
unsigned int v0; // er12

v0 = readinputport(2LL);
if ( (unsigned int)cpu_get_pc() == 228 )
v0 &= 0x7Fu;
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // er12

v0 = readinputport(2LL);
if ( (unsigned int)cpu_get_pc() == 228 )
v0 &= 0x7Fu;
return v0;
}

original_code:
data_t scramble_input_port_2_r(offs_t offset)
{
 int res;
 res = readinputport(2);
 if (cpu_get_pc() == 0x00e4) res &= 0x7f;
 return res;
}

canonical_original_code:
unsigned int scramble_input_port_2_r(unsigned int offset)
{
 int res;
 res = readinputport(2);
 if (cpu_get_pc() == 0x00e4) res &= 0x7f;
 return res;
}

variable_types: res int


decompiled_code:
__int64 scramblk_protection_r()
{
unsigned int v0; // eax
unsigned int v1; // edx
__int64 result; // rax
bool v3; // zf

v0 = cpu_get_pc();
if ( v0 == 3307 )
return 64LL;
v1 = v0;
if ( v0 > 0xCEB )
{
result = 96LL;
if ( v1 != 3383 )
{
result = 0LL;
if ( v1 == 7550 )
result = 176LL;
}
}
else if ( v0 == 3101 )
{
result = 240LL;
}
else if ( v0 > 0xC1D )
{
v3 = v0 == 3178;
result = 0LL;
if ( v3 )
result = 176LL;
}
else
{
result = 240LL;
if ( v1 != 168 )
{
result = 0LL;
if ( v1 == 190 )
result = 176LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
unsigned int v1; // edx
__int64 result; // rax
bool v3; // zf

v0 = cpu_get_pc();
if ( v0 == 3307 )
return 64LL;
v1 = v0;
if ( v0 > 0xCEB )
{
result = 96LL;
if ( v1 != 3383 )
{
result = 0LL;
if ( v1 == 7550 )
result = 176LL;
}
}
else if ( v0 == 3101 )
{
result = 240LL;
}
else if ( v0 > 0xC1D )
{
v3 = v0 == 3178;
result = 0LL;
if ( v3 )
result = 176LL;
}
else
{
result = 240LL;
if ( v1 != 168 )
{
result = 0LL;
if ( v1 == 190 )
result = 176LL;
}
}
return result;
}

original_code:
data_t scramblk_protection_r(offs_t offset)
{
 switch (cpu_get_pc())
 {
 case 0x00a8: return 0xf0;
 case 0x00be: return 0xb0;
 case 0x0c1d: return 0xf0;
 case 0x0c6a: return 0xb0;
 case 0x0ceb: return 0x40;
 case 0x0d37: return 0x60;
 case 0x1ca2: return 0x00;
 case 0x1d7e: return 0xb0;
 default:
  return 0;
 }
}

canonical_original_code:
unsigned int scramblk_protection_r(unsigned int offset)
{
 switch (cpu_get_pc())
 {
 case 0x00a8: return 0xf0;
 case 0x00be: return 0xb0;
 case 0x0c1d: return 0xf0;
 case 0x0c6a: return 0xb0;
 case 0x0ceb: return 0x40;
 case 0x0d37: return 0x60;
 case 0x1ca2: return 0x00;
 case 0x1d7e: return 0xb0;
 default:
  return 0;
 }
}


decompiled_code:
__int64 mariner_pip_r()
{
int v0; // er8
__int64 result; // rax

v0 = cpu_get_pc();
result = 255LL;
if ( v0 != 346 )
result = 5 * (unsigned int)((unsigned int)cpu_get_pc() == 2182);
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // er8
__int64 result; // rax

v0 = cpu_get_pc();
result = 255LL;
if ( v0 != 346 )
result = 5 * (unsigned int)((unsigned int)cpu_get_pc() == 2182);
return result;
}

original_code:
data_t mariner_pip_r(offs_t offset)
{
 if (cpu_get_pc() == 0x015a) return 0xff;
 else if (cpu_get_pc() == 0x0886) return 0x05;
 else return 0;
}

canonical_original_code:
unsigned int mariner_pip_r(unsigned int offset)
{
 if (cpu_get_pc() == 0x015a) return 0xff;
 else if (cpu_get_pc() == 0x0886) return 0x05;
 else return 0;
}


decompiled_code:
__int64 mariner_pap_r()
{
return 4 * (unsigned int)((unsigned int)cpu_get_pc() == 349);
}

canonical_decompiled_code:
__int64 func8()
{
return 4 * (unsigned int)((unsigned int)cpu_get_pc() == 349);
}

original_code:
data_t mariner_pap_r(offs_t offset)
{
 if (cpu_get_pc() == 0x015d) return 0x04;
 else return 0;
}

canonical_original_code:
unsigned int mariner_pap_r(unsigned int offset)
{
 if (cpu_get_pc() == 0x015d) return 0x04;
 else return 0;
}


decompiled_code:
__int64 scramble_portB_r()
{
int v0; // eax
int v1; // edx
bool v2; // sf
int v3; // eax
int v4; // edx

v0 = cpu_gettotalcycles();
v1 = clock_1 + v0 - last_totalcycles_2;
last_totalcycles_2 = v0;
v2 = v1 % 5120 < 0;
v3 = v1 % 5120;
v4 = v1 % 5120 + 511;
clock_1 = v3;
if ( v2 )
v3 = v4;
return scramble_timer[v3 >> 9];
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
int v1; // edx
bool v2; // sf
int v3; // eax
int v4; // edx

v0 = cpu_gettotalcycles();
v1 = clock_1 + v0 - last_totalcycles_2;
last_totalcycles_2 = v0;
v2 = v1 % 5120 < 0;
v3 = v1 % 5120;
v4 = v1 % 5120 + 511;
clock_1 = v3;
if ( v2 )
v3 = v4;
return scramble_timer[v3 >> 9];
}

original_code:
data_t scramble_portB_r(offs_t offset)
{
 static int last_totalcycles = 0;
 static int clock;
 int current_totalcycles;
 current_totalcycles = cpu_gettotalcycles();
 clock = (clock + (current_totalcycles-last_totalcycles)) % 5120;
 last_totalcycles = current_totalcycles;
 return scramble_timer[clock/512];
}

canonical_original_code:
unsigned int scramble_portB_r(unsigned int offset)
{
 static int last_totalcycles = 0;
 static int clock;
 int current_totalcycles;
 current_totalcycles = cpu_gettotalcycles();
 clock = (clock + (current_totalcycles-last_totalcycles)) % 5120;
 last_totalcycles = current_totalcycles;
 return scramble_timer[clock/512];
}

variable_types: clock int


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

result = (unsigned int)last_0;
if ( !last_0 && (a2 & 8) != 0 )
{
result = cpu_cause_interrupt(1LL, 4294966296LL);
last_0 = a2 & 8;
}
else
{
last_0 = a2 & 8;
}
return result;
}

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

result = (unsigned int)last_0;
if ( !last_0 && (a2 & 8) != 0 )
{
result = cpu_cause_interrupt(1LL, 4294966296LL);
last_0 = a2 & 8;
}
else
{
last_0 = a2 & 8;
}
return result;
}

original_code:
void scramble_sh_irqtrigger_w(offs_t offset,data_t data)
{
 static int last;
 if (last == 0 && (data & 0x08) != 0)
 {
  cpu_cause_interrupt(1, -1000);
 }
 last = data & 0x08;
}

canonical_original_code:
void scramble_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last == 0 && (data & 0x08) != 0)
 {
  cpu_cause_interrupt(1, -1000);
 }
 last = data & 0x08;
}

variable_types:
offset
unsigned int

variable_types: last int


decompiled_code:
__int64 hotshock_sh_irqtrigger_w()
{
return cpu_cause_interrupt(1LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 func11()
{
return cpu_cause_interrupt(1LL, 4294966296LL);
}

original_code:
void hotshock_sh_irqtrigger_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(1, -1000);
}

canonical_original_code:
void hotshock_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(1, -1000);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall scramble_filter_w(unsigned int a1)
{
filter_w(1, 0, a1 & 3);
filter_w(1, 1, (a1 >> 2) & 3);
filter_w(1, 2, (a1 >> 4) & 3);
filter_w(0, 0, (unsigned __int8)a1 >> 6);
filter_w(0, 1, BYTE1(a1) & 3);
return filter_w(0, 2, (a1 >> 10) & 3);
}

original_code:
void scramble_filter_w(offs_t offset,data_t data)
{
 filter_w(1, 0, (offset >> 0) & 3);
 filter_w(1, 1, (offset >> 2) & 3);
 filter_w(1, 2, (offset >> 4) & 3);
 filter_w(0, 0, (offset >> 6) & 3);
 filter_w(0, 1, (offset >> 8) & 3);
 filter_w(0, 2, (offset >> 10) & 3);
}

canonical_original_code:
void scramble_filter_w(unsigned int offset, unsigned int data)
{
 filter_w(1, 0, (offset >> 0) & 3);
 filter_w(1, 1, (offset >> 2) & 3);
 filter_w(1, 2, (offset >> 4) & 3);
 filter_w(0, 0, (offset >> 6) & 3);
 filter_w(0, 1, (offset >> 8) & 3);
 filter_w(0, 2, (offset >> 10) & 3);
}


decompiled_code:
__int64 __fastcall hunchbks_mirror_r(int a1)
{
return cpu_readmem16((unsigned int)(a1 + 4096));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return cpu_readmem16((unsigned int)(a1 + 4096));
}

original_code:
data_t hunchbks_mirror_r(offs_t offset)
{
 return cpu_readmem16(0x1000+offset);
}

canonical_original_code:
unsigned int hunchbks_mirror_r(unsigned int offset)
{
 return cpu_readmem16(0x1000+offset);
}


decompiled_code:
__int64 __fastcall hunchbks_mirror_w(int a1)
{
return cpu_writemem16((unsigned int)(a1 + 4096));
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return cpu_writemem16((unsigned int)(a1 + 4096));
}

original_code:
void hunchbks_mirror_w(offs_t offset,data_t data)
{
 cpu_writemem16(0x1000+offset,data);
}

canonical_original_code:
void hunchbks_mirror_w(unsigned int offset, unsigned int data)
{
 cpu_writemem16(0x1000+offset,data);
}


decompiled_code:
__int64 init_scramble()
{
return install_mem_read_handler(0LL, 33282LL, 33282LL, scramblk_protection_r);
}

canonical_decompiled_code:
__int64 func16()
{
return install_mem_read_handler(0LL, 33282LL, 33282LL, scramblk_protection_r);
}

original_code:
static void init_scramble(void)
{
 install_mem_read_handler(0, 0x8202, 0x8202, scramblk_protection_r);
}

canonical_original_code:
static void init_scramble()
{
 install_mem_read_handler(0, 0x8202, 0x8202, scramblk_protection_r);
}