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

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));
*(_QWORD *)bank_base = *v5;
result = v5[511];
*(_QWORD *)(v4 + 4088) = result;
qmemcpy(
(void *)((v4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v5 - (v4 - ((v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v4 - (((_DWORD)v4 + 8) & 0xFFFFFFF8) + 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; // ebx
__int64 result; // rax
__int64 v4; // rcx
_QWORD *v5; // rsi

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));
*(_QWORD *)bank_base = *v5;
result = v5[511];
*(_QWORD *)(v4 + 4088) = result;
qmemcpy(
(void *)((v4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v5 - (v4 - ((v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v4 - (((_DWORD)v4 + 8) & 0xFFFFFFF8) + 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
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

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

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

variable_types:
offset
unsigned int

variable_types: result int

return_type: unsigned int


decompiled_code:
__int64 __fastcall jsa3_io_r(__int16 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

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

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)
{
char v2; // dl
__int64 result; // rax
unsigned __int64 v4; // rcx
__int64 v5; // rcx
_QWORD *v6; // rsi

v2 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, (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, (unsigned int)a2);
}
}
else if ( (_DWORD)result == 516 )
{
v5 = bank_base;
v6 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
*(_QWORD *)bank_base = *v6;
*(_QWORD *)(v5 + 4088) = v6[511];
qmemcpy(
(void *)((v5 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v6 - (v5 - ((v5 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 4096) >> 3));
last_ctl = v2;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (unsigned int)(1193181 / ((v2 & 8) == 0 ? 165 : 132)));
}
else if ( (_DWORD)result == 518 )
{
v4 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v4 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v4) >> 1)) >> 2;
oki6295_volume = 50 * ((a2 & 1) + 1);
result = update_all_volumes();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
unsigned __int64 v4; // rcx
__int64 v5; // rcx
_QWORD *v6; // rsi

v2 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, (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, (unsigned int)a2);
}
}
else if ( (_DWORD)result == 516 )
{
v5 = bank_base;
v6 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
*(_QWORD *)bank_base = *v6;
*(_QWORD *)(v5 + 4088) = v6[511];
qmemcpy(
(void *)((v5 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v6 - (v5 - ((v5 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 4096) >> 3));
last_ctl = v2;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (unsigned int)(1193181 / ((v2 & 8) == 0 ? 165 : 132)));
}
else if ( (_DWORD)result == 518 )
{
v4 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v4 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v4) >> 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;
 }
}

return_type: void


decompiled_code:
__int64 __fastcall jsa3_io_w(__int64 a1, __int64 a2, __int64 a3)
{
char v3; // bl
__int64 result; // rax
unsigned __int64 v5; // rdx
__int64 v6; // rcx
_QWORD *v7; // rsi

v3 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3);
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);
v6 = bank_base;
v7 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
*(_QWORD *)bank_base = *v7;
*(_QWORD *)(v6 + 4088) = v7[511];
qmemcpy(
(void *)((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v7 - (v6 - ((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 4096) >> 3));
last_ctl = v3;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (unsigned int)(1193181 / ((v3 & 8) == 0 ? 165 : 132)));
}
else if ( (_DWORD)result == 518 )
{
oki6295_bank_base = oki6295_bank_base & 0x40000 | ((_DWORD)a2 << 15) & 0x80000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
v5 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v5 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v5) >> 1)) >> 2;
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);
}
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)
{
char v3; // bl
__int64 result; // rax
unsigned __int64 v5; // rdx
__int64 v6; // rcx
_QWORD *v7; // rsi

v3 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3);
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);
v6 = bank_base;
v7 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
*(_QWORD *)bank_base = *v7;
*(_QWORD *)(v6 + 4088) = v7[511];
qmemcpy(
(void *)((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v7 - (v6 - ((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 4096) >> 3));
last_ctl = v3;
result = OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, (unsigned int)(1193181 / ((v3 & 8) == 0 ? 165 : 132)));
}
else if ( (_DWORD)result == 518 )
{
oki6295_bank_base = oki6295_bank_base & 0x40000 | ((_DWORD)a2 << 15) & 0x80000;
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL);
v5 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v5 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v5) >> 1)) >> 2;
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);
}
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
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

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

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)
{
char v3; // bl
__int64 result; // rax
unsigned __int64 v5; // rdx
__int64 v6; // rcx
_QWORD *v7; // rsi
__int64 v8; // rbx

v3 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3);
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);
v6 = bank_base;
v7 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
*(_QWORD *)bank_base = *v7;
*(_QWORD *)(v6 + 4088) = v7[511];
qmemcpy(
(void *)((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v7 - (v6 - ((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 4096) >> 3));
last_ctl = v3;
v8 = (unsigned int)(1193181 / ((v3 & 8) == 0 ? 165 : 132));
OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, v8);
result = OKIM6295_set_frequency(1LL, 0xFFFFFFFFLL, (unsigned int)v8);
}
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);
v5 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v5 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v5) >> 1)) >> 2;
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);
}
}
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)
{
char v3; // bl
__int64 result; // rax
unsigned __int64 v5; // rdx
__int64 v6; // rcx
_QWORD *v7; // rsi
__int64 v8; // rbx

v3 = a2;
result = a1 & 0x206;
if ( (_DWORD)result == 514 )
return atarigen_6502_sound_w(a1, a2, a3);
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);
v6 = bank_base;
v7 = (_QWORD *)(bank_source_data + (((_WORD)a2 << 6) & 0x3000));
*(_QWORD *)bank_base = *v7;
*(_QWORD *)(v6 + 4088) = v7[511];
qmemcpy(
(void *)((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v7 - (v6 - ((v6 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 4096) >> 3));
last_ctl = v3;
v8 = (unsigned int)(1193181 / ((v3 & 8) == 0 ? 165 : 132));
OKIM6295_set_frequency(0LL, 0xFFFFFFFFLL, v8);
result = OKIM6295_set_frequency(1LL, 0xFFFFFFFFLL, (unsigned int)v8);
}
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);
v5 = (613566757 * (unsigned __int64)(100 * (((unsigned int)a2 >> 1) & 7))) >> 32;
ym2151_volume = ((unsigned int)v5 + ((100 * (((unsigned int)a2 >> 1) & 7) - (unsigned int)v5) >> 1)) >> 2;
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);
}
}
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; // rcx
__int64 v1; // rsi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rcx
__int64 v1; // rsi
__int64 result; // rax

atarigen_sound_io_reset((unsigned __int8)cpu_num);
speech_data = 0;
last_ctl = 0;
oki6295_bank_base = 0;
overall_volume = 100;
pokey_volume = 100;
ym2151_volume = 100;
tms5220_volume = 100;
oki6295_volume = 100;
v0 = bank_base;
v1 = bank_source_data;
*(_QWORD *)bank_base = *(_QWORD *)bank_source_data;
result = *(_QWORD *)(v1 + 4088);
*(_QWORD *)(v0 + 4088) = result;
qmemcpy(
(void *)((v0 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v1 - (v0 - ((v0 + 8) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 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

variable_types: i 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_5D0 + ((*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_5D0 + ((*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()
{
unsigned int v0; // ebx

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

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

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

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

return_type: int


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

K051316_tilemap_update_0();
K051316_tilemap_update_1();
K051316_tilemap_update_2();
palette_init_used_colors();
K051960_mark_sprites_colors();
v2 = 16 * zoom_colorbase;
v3 = v2 + 1024;
v4 = 16 * (dword_5CC - (__int64)zoom_colorbase);
v5 = 16 * (dword_5D0 - (__int64)zoom_colorbase);
do
{
*(_BYTE *)(palette_used_colors + v2) = 7;
*(_BYTE *)(palette_used_colors + v2 + v4) = 7;
*(_BYTE *)(palette_used_colors + v2 + v5) = 7;
v2 += 16LL;
}
while ( v2 != v3 );
if ( palette_recalc(v4, v5, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * dword_5D0), 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; // rax
__int64 v3; // r8
__int64 v4; // rdi
__int64 v5; // rsi

K051316_tilemap_update_0();
K051316_tilemap_update_1();
K051316_tilemap_update_2();
palette_init_used_colors();
K051960_mark_sprites_colors();
v2 = 16 * zoom_colorbase;
v3 = v2 + 1024;
v4 = 16 * (dword_5CC - (__int64)zoom_colorbase);
v5 = 16 * (dword_5D0 - (__int64)zoom_colorbase);
do
{
*(_BYTE *)(palette_used_colors + v2) = 7;
*(_BYTE *)(palette_used_colors + v2 + v4) = 7;
*(_BYTE *)(palette_used_colors + v2 + v5) = 7;
v2 += 16LL;
}
while ( v2 != v3 );
if ( palette_recalc(v4, v5, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * dword_5D0), 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; } *


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 = zoom_colorbase + ((*a2 >> 3) & 0x1Fu);
*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 = zoom_colorbase + ((*a2 >> 3) & 0x1Fu);
*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 = dword_5CC + ((*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 = dword_5CC + ((*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; // ebx

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

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

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
bool v2; // zf
__int64 result; // rax

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

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

v0 = cpu_get_pc();
if ( v0 == 3307 )
return 64LL;
v1 = v0;
if ( v0 > 0xCEB )
{
result = 0LL;
if ( v1 != 7330 )
{
result = 176LL;
if ( v1 != 7550 )
{
result = 0LL;
if ( v1 == 3383 )
result = 96LL;
}
}
}
else if ( v0 == 3101 )
{
result = 240LL;
}
else if ( v0 <= 0xC1D )
{
result = 240LL;
if ( v1 != 168 )
{
result = 0LL;
if ( v1 == 190 )
result = 176LL;
}
}
else
{
v2 = v0 == 3178;
result = 0LL;
if ( v2 )
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; // edx
__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; // edx
__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; // ecx

v0 = cpu_gettotalcycles();
clock_1 = (clock_1 + v0 - last_totalcycles_2) % 5120;
last_totalcycles_2 = v0;
return scramble_timer[clock_1 / 512];
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // ecx

v0 = cpu_gettotalcycles();
clock_1 = (clock_1 + v0 - last_totalcycles_2) % 5120;
last_totalcycles_2 = v0;
return scramble_timer[clock_1 / 512];
}

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

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

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

if ( !last_0 && (a2 & 8) != 0 )
result = cpu_cause_interrupt(1LL, 4294966296LL);
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:
data
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:
offset
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);
}


decompiled_code:
__int64 init_scrambls()
{
install_mem_read_handler(0LL, 33026LL, 33026LL, scramble_input_port_2_r);
return install_mem_read_handler(0LL, 33282LL, 33282LL, scramble_protection_r);
}

canonical_decompiled_code:
__int64 func17()
{
install_mem_read_handler(0LL, 33026LL, 33026LL, scramble_input_port_2_r);
return install_mem_read_handler(0LL, 33282LL, 33282LL, scramble_protection_r);
}

original_code:
static void init_scrambls(void)
{
 install_mem_read_handler(0, 0x8102, 0x8102, scramble_input_port_2_r);
 install_mem_read_handler(0, 0x8202, 0x8202, scramble_protection_r);
}

canonical_original_code:
static void init_scrambls()
{
 install_mem_read_handler(0, 0x8102, 0x8102, scramble_input_port_2_r);
 install_mem_read_handler(0, 0x8202, 0x8202, scramble_protection_r);
}


decompiled_code:
__int64 scramble_coin_counter_2_w()
{
return coin_counter_w(1LL);
}

canonical_decompiled_code:
__int64 func18()
{
return coin_counter_w(1LL);
}

original_code:
static void scramble_coin_counter_2_w(offs_t offset,data_t data)
{
 coin_counter_w(1, data);
}

canonical_original_code:
static void scramble_coin_counter_2_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(1, data);
}


decompiled_code:
__int64 scramble_coin_counter_3_w()
{
return coin_counter_w(2LL);
}

canonical_decompiled_code:
__int64 func19()
{
return coin_counter_w(2LL);
}

original_code:
static void scramble_coin_counter_3_w(offs_t offset,data_t data)
{
 coin_counter_w(2, data);
}

canonical_original_code:
static void scramble_coin_counter_3_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(2, data);
}


decompiled_code:
__int64 init_froggers()
{
_BYTE *v0; // rcx
_BYTE *v1; // rdi
__int64 result; // rax

v0 = (_BYTE *)memory_region(130LL);
v1 = v0 + 2048;
do
{
result = *v0 & 0xFC | ((int)(unsigned __int8)*v0 >> 1) & 1 | (2 * *v0) & 2u;
*v0 = *v0 & 0xFC | ((int)(unsigned __int8)*v0 >> 1) & 1 | (2 * *v0) & 2;
++v0;
}
while ( v0 != v1 );
return result;
}

original_code:
static void init_froggers(void)
{
 int A;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU2);
 for (A = 0;A < 0x0800;A++)
  RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
}

canonical_original_code:
static void init_froggers()
{
 int A;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU2);
 for (A = 0;A < 0x0800;A++)
  RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
}

variable_types: A int

variable_types:
RAM
unsigned char *


original_code:
static void init_mars(void)
{
 int i;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 for (i = 0; i < 0x10000; i += 16)
 {
  int j;
  unsigned char swapbuffer[16];
  for (j = 0; j < 16; j++)
  {
   swapbuffer[j] = RAM[i + ((j & 1) << 2) + ((j & 2) >> 1) + ((j & 4) << 1) + ((j & 8) >> 2)];
  }
  memcpy(&RAM[i], swapbuffer, 16);
 }
}

canonical_original_code:
static void init_mars()
{
 int i;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 for (i = 0; i < 0x10000; i += 16)
 {
  int j;
  unsigned char swapbuffer[16];
  for (j = 0; j < 16; j++)
  {
   swapbuffer[j] = RAM[i + ((j & 1) << 2) + ((j & 2) >> 1) + ((j & 4) << 1) + ((j & 8) >> 2)];
  }
  memcpy(&RAM[i], swapbuffer, 16);
 }
}

variable_types: j int

variable_types:
swapbuffer
unsigned char [16]


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

result = memory_region(129LL);
*(_BYTE *)(result + 12025) = -55;
return result;
}

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

result = memory_region(129LL);
*(_BYTE *)(result + 12025) = -55;
return result;
}

original_code:
static void init_hotshock(void)
{
 memory_region(REGION_CPU1)[0x2ef9] = 0xc9;
}

canonical_original_code:
static void init_hotshock()
{
 memory_region(REGION_CPU1)[0x2ef9] = 0xc9;
}


decompiled_code:
__int64 scramblb_protection_1_r()
{
return (unsigned __int8)((unsigned int)cpu_get_pc() == 474) << 7;
}

canonical_decompiled_code:
__int64 func23()
{
return (unsigned __int8)((unsigned int)cpu_get_pc() == 474) << 7;
}

original_code:
data_t scramblb_protection_1_r(offs_t offset)
{
 switch (cpu_get_pc())
 {
 case 0x01da: return 0x80;
 case 0x01e4: return 0x00;
 default:
  return 0;
 }
}

canonical_original_code:
unsigned int scramblb_protection_1_r(unsigned int offset)
{
 switch (cpu_get_pc())
 {
 case 0x01da: return 0x80;
 case 0x01e4: return 0x00;
 default:
  return 0;
 }
}


decompiled_code:
__int64 scramblb_protection_2_r()
{
bool v0; // zf
__int64 result; // rax

v0 = (unsigned int)cpu_get_pc() == 458;
result = 144LL;
if ( !v0 )
result = 0LL;
return result;
}

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

v0 = (unsigned int)cpu_get_pc() == 458;
result = 144LL;
if ( !v0 )
result = 0LL;
return result;
}

original_code:
data_t scramblb_protection_2_r(offs_t offset)
{
 switch (cpu_get_pc())
 {
 case 0x01ca: return 0x90;
 default:
  return 0;
 }
}

canonical_original_code:
unsigned int scramblb_protection_2_r(unsigned int offset)
{
 switch (cpu_get_pc())
 {
 case 0x01ca: return 0x90;
 default:
  return 0;
 }
}


original_code:
static void filter_w(int chip, int channel, int data)
{
 int C;
 C = 0;
 if (data & 1) C += 220000;
 if (data & 2) C += 47000;
 set_RC_filter(3*chip + channel,1000,5100,0,C);
}

variable_types: chip int

variable_types: channel int

variable_types: data int

variable_types: C int


decompiled_code:
__int64 __fastcall slapfight_dpram_r(unsigned int a1)
{
return *(unsigned __int8 *)(slapfight_dpram + a1);
}

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

original_code:
data_t slapfight_dpram_r(offs_t offset)
{
    return slapfight_dpram[offset];
}

canonical_original_code:
unsigned int slapfight_dpram_r(unsigned int offset)
{
    return slapfight_dpram[offset];
}


decompiled_code:
__int64 slapfight_port_00_r()
{
unsigned int v0; // edx
int v1; // eax
int v3[3]; // [rsp+0h] [rbp-Ch]

v3[0] = 199;
v3[1] = 85;
v3[2] = 0;
v0 = v3[slapfight_status_state];
slapfight_status = v0;
v1 = slapfight_status_state + 1;
if ( slapfight_status_state + 1 > 2 )
v1 = 0;
slapfight_status_state = v1;
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // edx
int v1; // eax
int v3[3]; // [rsp+0h] [rbp-Ch]

v3[0] = 199;
v3[1] = 85;
v3[2] = 0;
v0 = v3[slapfight_status_state];
slapfight_status = v0;
v1 = slapfight_status_state + 1;
if ( slapfight_status_state + 1 > 2 )
v1 = 0;
slapfight_status_state = v1;
return v0;
}

original_code:
data_t slapfight_port_00_r(offs_t offset)
{
 int states[3]={ 0xc7, 0x55, 0x00 };
 slapfight_status = states[slapfight_status_state];
 slapfight_status_state++;
 if (slapfight_status_state > 2) slapfight_status_state = 0;
 return slapfight_status;
}

canonical_original_code:
unsigned int slapfight_port_00_r(unsigned int offset)
{
 int states[3] = { 0xc7, 0x55, 0x00 };
 slapfight_status = states[slapfight_status_state];
 slapfight_status_state++;
 if (slapfight_status_state > 2) slapfight_status_state = 0;
 return slapfight_status;
}

variable_types:
states
int [3]


decompiled_code:
__int64 getstar_e803_r()
{
__int64 v0; // rsi
__int16 v2; // [rsp+1h] [rbp-3h]
char v3; // [rsp+3h] [rbp-1h]

v2 = 256;
v3 = 83;
v0 = getstar_sequence_index;
getstar_sequence_index = (getstar_sequence_index + 1) % 3;
return *((unsigned __int8 *)&v2 + v0);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rsi
__int16 v2; // [rsp+1h] [rbp-3h]
char v3; // [rsp+3h] [rbp-1h]

v2 = 256;
v3 = 83;
v0 = getstar_sequence_index;
getstar_sequence_index = (getstar_sequence_index + 1) % 3;
return *((unsigned __int8 *)&v2 + v0);
}

original_code:
data_t getstar_e803_r(offs_t offset)
{
unsigned char seq[] = { 0, 1, (0+5)^0x56 };
unsigned char val;
 val = seq[getstar_sequence_index];
 getstar_sequence_index = (getstar_sequence_index+1)%3;
 return val;
}

canonical_original_code:
unsigned int getstar_e803_r(unsigned int offset)
{
unsigned char seq[] = { 0, 1, (0+5)^0x56 };
unsigned char val;
 val = seq[getstar_sequence_index];
 getstar_sequence_index = (getstar_sequence_index+1)%3;
 return val;
}

variable_types:
seq
unsigned char []

variable_types:
val
unsigned char


decompiled_code:
_DWORD *getstar_sh_intenable_w()
{
_DWORD *result; // rax

result = &getstar_sh_intenabled;
getstar_sh_intenabled = 1;
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *result; // rax

result = &getstar_sh_intenabled;
getstar_sh_intenabled = 1;
return result;
}

original_code:
void getstar_sh_intenable_w(offs_t offset,data_t data)
{
 getstar_sh_intenabled = 1;
}

canonical_original_code:
void getstar_sh_intenable_w(unsigned int offset, unsigned int data)
{
 getstar_sh_intenabled = 1;
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 slapfight_init_machine()
{
slapfight_status_state = 0;
slapfight_status = 199;
getstar_sequence_index = 0;
getstar_sh_intenabled = 0;
return cpu_set_reset_line(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func6()
{
slapfight_status_state = 0;
slapfight_status = 199;
getstar_sequence_index = 0;
getstar_sh_intenabled = 0;
return cpu_set_reset_line(1LL, 1LL);
}

original_code:
void slapfight_init_machine(void)
{
 slapfight_status_state=0;
 slapfight_status = 0xc7;
 getstar_sequence_index = 0;
 getstar_sh_intenabled = 0;
 cpu_set_reset_line(1,1);
}

canonical_original_code:
void slapfight_init_machine()
{
 slapfight_status_state=0;
 slapfight_status = 0xc7;
 getstar_sequence_index = 0;
 getstar_sh_intenabled = 0;
 cpu_set_reset_line(1,1);
}


decompiled_code:
_DWORD *slapfight_port_00_w()
{
_DWORD *result; // rax

cpu_set_reset_line(1LL, 1LL);
result = &getstar_sh_intenabled;
getstar_sh_intenabled = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func7()
{
_DWORD *result; // rax

cpu_set_reset_line(1LL, 1LL);
result = &getstar_sh_intenabled;
getstar_sh_intenabled = 0;
return result;
}

original_code:
void slapfight_port_00_w(offs_t offset,data_t data)
{
 cpu_set_reset_line(1,1);
 getstar_sh_intenabled = 0;
}

canonical_original_code:
void slapfight_port_00_w(unsigned int offset, unsigned int data)
{
 cpu_set_reset_line(1,1);
 getstar_sh_intenabled = 0;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 slapfight_port_01_w()
{
return cpu_set_reset_line(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
return cpu_set_reset_line(1LL, 0LL);
}

original_code:
void slapfight_port_01_w(offs_t offset,data_t data)
{
 cpu_set_reset_line(1,0);
}

canonical_original_code:
void slapfight_port_01_w(unsigned int offset, unsigned int data)
{
 cpu_set_reset_line(1,0);
}


decompiled_code:
__int64 slapfight_port_06_w()
{
return interrupt_enable_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return interrupt_enable_w(0LL, 0LL);
}

original_code:
void slapfight_port_06_w(offs_t offset,data_t data)
{
 interrupt_enable_w(0,0);
}

canonical_original_code:
void slapfight_port_06_w(unsigned int offset, unsigned int data)
{
 interrupt_enable_w(0,0);
}


decompiled_code:
__int64 slapfight_port_07_w()
{
return interrupt_enable_w(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func10()
{
return interrupt_enable_w(0LL, 1LL);
}

original_code:
void slapfight_port_07_w(offs_t offset,data_t data)
{
 interrupt_enable_w(0,1);
}

canonical_original_code:
void slapfight_port_07_w(unsigned int offset, unsigned int data)
{
 interrupt_enable_w(0,1);
}


decompiled_code:
void *slapfight_port_08_w()
{
void *result; // rax
unsigned int v1; // eax

cpu_bankbase[1] = memory_region(129LL) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v1 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v1);
}
return result;
}

canonical_decompiled_code:
void *func11()
{
void *result; // rax
unsigned int v1; // eax

cpu_bankbase[1] = memory_region(129LL) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v1 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v1);
}
return result;
}

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

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


decompiled_code:
void *slapfight_port_09_w()
{
void *result; // rax
unsigned int v1; // eax

cpu_bankbase[1] = memory_region(129LL) + 81920;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v1 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v1);
}
return result;
}

canonical_decompiled_code:
void *func12()
{
void *result; // rax
unsigned int v1; // eax

cpu_bankbase[1] = memory_region(129LL) + 81920;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v1 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v1);
}
return result;
}

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

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


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

if ( getstar_sh_intenabled )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( getstar_sh_intenabled )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
int getstar_interrupt(void)
{
 if (getstar_sh_intenabled)
  return nmi_interrupt();
 else
  return ignore_interrupt();
}

canonical_original_code:
int getstar_interrupt()
{
 if (getstar_sh_intenabled)
  return nmi_interrupt();
 else
  return ignore_interrupt();
}


decompiled_code:
int *__fastcall slapfight_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
unsigned __int64 v3; // rbx
int *result; // rax
int v5; // ebx
__int64 v6; // rbp
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
((*(unsigned __int8 *)(colorram + v2) << 8) & 0xF00) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 4,
0LL,
0LL,
(unsigned int)(8 * (v1 % 64)),
(unsigned int)(8 * (v1 / 64)),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v7 = -((unsigned __int8)*slapfight_scrollx_lo + ((unsigned __int8)*slapfight_scrollx_hi << 8));
v8[0] = 1 - (unsigned __int8)*slapfight_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v7, 1LL, v8, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v3 = 0LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v3) + ((4 * *(unsigned __int8 *)(spriteram + v3 + 2)) & 0x300u),
((int)*(unsigned __int8 *)(spriteram + v3 + 2) >> 1) & 0xF,
0LL,
0LL,
*(unsigned __int8 *)(spriteram + v3 + 1) + ((*(unsigned __int8 *)(spriteram + v3 + 2) << 8) & 0x100u) - 13,
*(unsigned __int8 *)(spriteram + v3 + 3),
Machine + 776LL,
2LL,
0LL);
v3 += 4LL;
}
while ( spriteram_size > v3 );
}
result = &slapfight_videoram_size;
v5 = slapfight_videoram_size - 1;
if ( slapfight_videoram_size - 1 >= 0 )
{
v6 = v5;
do
{
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(slapfight_colorram + v6) << 8) & 0x300)
+ (unsigned int)*(unsigned __int8 *)(slapfight_videoram + v6),
*(_BYTE *)(slapfight_colorram + v6) >> 2,
0LL,
0LL,
(unsigned int)(8 * (v5 % 64)),
(unsigned int)(8 * (v5 / 64)),
Machine + 776LL,
2LL,
0LL);
--v6;
--v5;
}
while ( v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func14(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
unsigned __int64 v3; // rbx
int *result; // rax
int v5; // ebx
__int64 v6; // rbp
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
((*(unsigned __int8 *)(colorram + v2) << 8) & 0xF00) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 4,
0LL,
0LL,
(unsigned int)(8 * (v1 % 64)),
(unsigned int)(8 * (v1 / 64)),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v7 = -((unsigned __int8)*slapfight_scrollx_lo + ((unsigned __int8)*slapfight_scrollx_hi << 8));
v8[0] = 1 - (unsigned __int8)*slapfight_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v7, 1LL, v8, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v3 = 0LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v3) + ((4 * *(unsigned __int8 *)(spriteram + v3 + 2)) & 0x300u),
((int)*(unsigned __int8 *)(spriteram + v3 + 2) >> 1) & 0xF,
0LL,
0LL,
*(unsigned __int8 *)(spriteram + v3 + 1) + ((*(unsigned __int8 *)(spriteram + v3 + 2) << 8) & 0x100u) - 13,
*(unsigned __int8 *)(spriteram + v3 + 3),
Machine + 776LL,
2LL,
0LL);
v3 += 4LL;
}
while ( spriteram_size > v3 );
}
result = &slapfight_videoram_size;
v5 = slapfight_videoram_size - 1;
if ( slapfight_videoram_size - 1 >= 0 )
{
v6 = v5;
do
{
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(slapfight_colorram + v6) << 8) & 0x300)
+ (unsigned int)*(unsigned __int8 *)(slapfight_videoram + v6),
*(_BYTE *)(slapfight_colorram + v6) >> 2,
0LL,
0LL,
(unsigned int)(8 * (v5 % 64)),
(unsigned int)(8 * (v5 / 64)),
Machine + 776LL,
2LL,
0LL);
--v6;
--v5;
}
while ( v5 >= 0 );
}
return result;
}

original_code:
void slapfight_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 64;
   sy = offs / 64;
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + ((colorram[offs] & 0x0f) << 8),
     (colorram[offs] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx,scrolly;
  scrollx = -(*slapfight_scrollx_lo + 256 * *slapfight_scrollx_hi);
  scrolly = -*slapfight_scrolly+1;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  drawgfx(bitmap,Machine->gfx[2],
   spriteram[offs] + ((spriteram[offs+2] & 0xc0) << 2),
   (spriteram[offs+2] & 0x1e) >>1,
   0,0,
   (spriteram[offs+1] + ((spriteram[offs+2] & 0x01) << 8)) - 13,spriteram[offs+3],
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = slapfight_videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 64;
  sy = offs / 64;
  drawgfx(bitmap,Machine->gfx[0],
   slapfight_videoram[offs] + ((slapfight_colorram[offs] & 0x03) << 8),
   (slapfight_colorram[offs] & 0xfc) >> 2,
   0,0,
   8*sx,8*sy,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void slapfight_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 64;
   sy = offs / 64;
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + ((colorram[offs] & 0x0f) << 8),
     (colorram[offs] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx; int scrolly;
  scrollx = -(*slapfight_scrollx_lo + 256 * *slapfight_scrollx_hi);
  scrolly = -*slapfight_scrolly+1;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  drawgfx(bitmap,Machine->gfx[2],
   spriteram[offs] + ((spriteram[offs+2] & 0xc0) << 2),
   (spriteram[offs+2] & 0x1e) >>1,
   0,0,
   (spriteram[offs+1] + ((spriteram[offs+2] & 0x01) << 8)) - 13,spriteram[offs+3],
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = slapfight_videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 64;
  sy = offs / 64;
  drawgfx(bitmap,Machine->gfx[0],
   slapfight_videoram[offs] + ((slapfight_colorram[offs] & 0x03) << 8),
   (slapfight_colorram[offs] & 0xfc) >> 2,
   0,0,
   8*sx,8*sy,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: scrollx int

variable_types: scrolly int


decompiled_code:
void getstar_port_04_w()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

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

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

variable_types:
offset
unsigned int


original_code:
static void object_update(struct gfx_object *object)
{
 int min_x,min_y,max_x,max_y;
 object->dirty_flag = 0;
 if(object->gfx == 0)
  return;
 min_x = Machine->visible_area.min_x;
 max_x = Machine->visible_area.max_x;
 min_y = Machine->visible_area.min_y;
 max_y = Machine->visible_area.max_y;
 if(
  (object->width==0) ||
  (object->height==0) ||
  (object->sx > max_x) ||
  (object->sy > max_y) ||
  (object->sx+object->width <= min_x) ||
  (object->sy+object->height <= min_y) )
 {
  object->visible = 0;
  return;
 }
 object->visible = 1;
 object->draw_x = object->sx -
  ( object->flipx ?
   (object->gfx->width - (object->left + object->width)) :
   (object->left)
  );
 object->draw_y = object->sy -
  ( object->flipy ?
   (object->gfx->height - (object->top + object->height)) :
   (object->top)
  );
 object->clip.min_x = object->sx;
 object->clip.max_x = object->sx + object->width -1;
 object->clip.min_y = object->sy;
 object->clip.max_y = object->sy + object->height -1;
 if (object->clip.min_x < min_x) object->clip.min_x = min_x;
 if (object->clip.max_x > max_x) object->clip.max_x = max_x;
 if (object->clip.min_y < min_y) object->clip.min_y = min_y;
 if (object->clip.max_y > max_y) object->clip.max_y = max_y;
}

canonical_original_code:
static void object_update(struct gfx_object *object)
{
 int min_x; int min_y; int max_x; int max_y;
 object->dirty_flag = 0;
 if(object->gfx == 0)
  return;
 min_x = Machine->visible_area.min_x;
 max_x = Machine->visible_area.max_x;
 min_y = Machine->visible_area.min_y;
 max_y = Machine->visible_area.max_y;
 if(
  (object->width==0) ||
  (object->height==0) ||
  (object->sx > max_x) ||
  (object->sy > max_y) ||
  (object->sx+object->width <= min_x) ||
  (object->sy+object->height <= min_y) )
 {
  object->visible = 0;
  return;
 }
 object->visible = 1;
 object->draw_x = object->sx -
  ( object->flipx ?
   (object->gfx->width - (object->left + object->width)) :
   (object->left)
  );
 object->draw_y = object->sy -
  ( object->flipy ?
   (object->gfx->height - (object->top + object->height)) :
   (object->top)
  );
 object->clip.min_x = object->sx;
 object->clip.max_x = object->sx + object->width -1;
 object->clip.min_y = object->sy;
 object->clip.max_y = object->sy + object->height -1;
 if (object->clip.min_x < min_x) object->clip.min_x = min_x;
 if (object->clip.max_x > max_x) object->clip.max_x = max_x;
 if (object->clip.min_y < min_y) object->clip.min_y = min_y;
 if (object->clip.max_y > max_y) object->clip.max_y = max_y;
}

variable_types: struct gfx_object { int transparency; int transparet_color; struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *gfx; int code; int color; int priority; int sx; int sy; int flipx; int flipy; int top; int left; int width; int height; int palette_flag; int scalex; int scaley; struct gfx_object *next; void (*special_handler)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, struct gfx_object *object); int dirty_flag; int visible; int draw_x; int draw_y; struct rectangle { int min_x; int min_y; } clip; } *

user_defined_types: struct gfx_object { int transparency; int transparet_color; struct GfxElement *gfx; int code; int color; int priority; int sx; int sy; int flipx; int flipy; int top; int left; int width; int height; int palette_flag; int scalex; int scaley; struct gfx_object *next; void (*special_handler)(struct osd_bitmap *bitmap, struct gfx_object *object); int dirty_flag; int visible; int draw_x; int draw_y; struct rectangle clip; }


original_code:
static void gfxobj_update_one(struct gfx_object_list *object_list)
{
 struct gfx_object *object;
 struct gfx_object *start_object,*last_object;
 int dx,start_priority,end_priority;
 int priorities = object_list->max_priority;
 int priority;
 if(object_list->sort_type&0x01)
 {
  struct gfx_object *top_object[16],*end_object[16];
  if(object_list->sort_type&0x02)
  {
   start_object = object_list->objects + object_list->nums-1;
   last_object = object_list->objects-1;
   dx = -1;
  }
  else
  {
   start_object = object_list->objects;
   last_object = object_list->objects + object_list->nums;
   dx = 1;
  }
  for( priority = 0; priority < priorities; priority++ )
   end_object[priority] = 0;
  for(object=start_object ; object != last_object ; object+=dx)
  {
   if(object->dirty_flag)
    object_update(object);
   if(object->visible)
   {
    priority = object->priority;
    if(end_object[priority])
     end_object[priority]->next = object;
    else
     top_object[priority] = object;
    end_object[priority] = object;
   }
  }
  if(object_list->sort_type&0x04)
  {
   start_priority = priorities-1;
   end_priority = -1;
   dx = -1;
  }
  else
  {
   start_priority = 0;
   end_priority = priorities;
   dx = 1;
  }
  last_object = 0;
  for( priority = start_priority; priority != end_priority; priority+=dx )
  {
   if(end_object[priority])
   {
    if(last_object)
     last_object->next = top_object[priority];
    else
     object_list->first_object = top_object[priority];
    last_object = end_object[priority];
   }
  }
  if(last_object == 0 )
   object_list->first_object = 0;
  else
   last_object->next = 0;
 }
 else
 {
  for(object=object_list->first_object ; object !=0 ; object=object->next)
  {
   if(object->dirty_flag)
    object_update(object);
  }
 }
 if(object->palette_flag)
 {
 }
}

canonical_original_code:
static void gfxobj_update_one(struct gfx_object_list *object_list)
{
 struct gfx_object *object;
 struct gfx_object *start_object; struct gfx_object *last_object;
 int dx; int start_priority; int end_priority;
 int priorities = object_list->max_priority;
 int priority;
 if(object_list->sort_type&0x01)
 {
  struct gfx_object *top_object[16]; struct gfx_object *end_object[16];
  if(object_list->sort_type&0x02)
  {
   start_object = object_list->objects + object_list->nums-1;
   last_object = object_list->objects-1;
   dx = -1;
  }
  else
  {
   start_object = object_list->objects;
   last_object = object_list->objects + object_list->nums;
   dx = 1;
  }
  for( priority = 0; priority < priorities; priority++ )
   end_object[priority] = 0;
  for(object=start_object ; object != last_object ; object+=dx)
  {
   if(object->dirty_flag)
    object_update(object);
   if(object->visible)
   {
    priority = object->priority;
    if(end_object[priority])
     end_object[priority]->next = object;
    else
     top_object[priority] = object;
    end_object[priority] = object;
   }
  }
  if(object_list->sort_type&0x04)
  {
   start_priority = priorities-1;
   end_priority = -1;
   dx = -1;
  }
  else
  {
   start_priority = 0;
   end_priority = priorities;
   dx = 1;
  }
  last_object = 0;
  for( priority = start_priority; priority != end_priority; priority+=dx )
  {
   if(end_object[priority])
   {
    if(last_object)
     last_object->next = top_object[priority];
    else
     object_list->first_object = top_object[priority];
    last_object = end_object[priority];
   }
  }
  if(last_object == 0 )
   object_list->first_object = 0;
  else
   last_object->next = 0;
 }
 else
 {
  for(object=object_list->first_object ; object !=0 ; object=object->next)
  {
   if(object->dirty_flag)
    object_update(object);
  }
 }
 if(object->palette_flag)
 {
 }
}

variable_types: struct gfx_object_list { int nums; int max_priority; struct gfx_object { int transparency; int transparet_color; struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *gfx; int code; int color; int priority; int sx; int sy; int flipx; int flipy; int top; int left; int width; int height; int palette_flag; int scalex; int scaley; struct gfx_object *next; void (*special_handler)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, struct gfx_object *object); int dirty_flag; int visible; int draw_x; int draw_y; struct rectangle { int min_x; int min_y; } clip; } *objects; struct gfx_object *first_object; int sort_type; struct gfx_object_list *next; } *

variable_types: dx int

variable_types: priorities int

variable_types: priority int

variable_types: struct gfx_object { int transparency; int transparet_color; struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *gfx; int code; int color; int priority; int sx; int sy; int flipx; int flipy; int top; int left; int width; int height; int palette_flag; int scalex; int scaley; struct gfx_object *next; void (*special_handler)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, struct gfx_object *object); int dirty_flag; int visible; int draw_x; int draw_y; struct rectangle { int min_x; int min_y; } clip; } *[16]

user_defined_types: struct gfx_object_list { int nums; int max_priority; struct gfx_object *objects; struct gfx_object *first_object; int sort_type; struct gfx_object_list *next; }


original_code:
static void draw_object_one(struct osd_bitmap *bitmap,struct gfx_object *object)
{
 if(object->special_handler)
 {
  object->special_handler(bitmap,object);
 }
 else
 {
  drawgfx(bitmap,object->gfx,
    object->code,
    object->color,
    object->flipx,
    object->flipy,
    object->draw_x,
    object->draw_y,
    &object->clip,
    object->transparency,
    object->transparet_color);
 }
}

canonical_original_code:
static void draw_object_one(struct osd_bitmap *bitmap, struct gfx_object *object)
{
 if(object->special_handler)
 {
  object->special_handler(bitmap,object);
 }
 else
 {
  drawgfx(bitmap,object->gfx,
    object->code,
    object->color,
    object->flipx,
    object->flipy,
    object->draw_x,
    object->draw_y,
    &object->clip,
    object->transparency,
    object->transparet_color);
 }
}

variable_types: struct gfx_object { int transparency; int transparet_color; struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *gfx; int code; int color; int priority; int sx; int sy; int flipx; int flipy; int top; int left; int width; int height; int palette_flag; int scalex; int scaley; struct gfx_object *next; void (*special_handler)(struct osd_bitmap *bitmap, struct gfx_object *object); int dirty_flag; int visible; int draw_x; int draw_y; struct rectangle { int min_x; int min_y; } clip; } *

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


decompiled_code:
void gfxobj_init()
{
first_object_list = 0LL;
}

canonical_decompiled_code:
void func3()
{
first_object_list = 0LL;
}

original_code:
void gfxobj_init(void)
{
 first_object_list = 0;
}

canonical_original_code:
void gfxobj_init()
{
 first_object_list = 0;
}


decompiled_code:
void gfxobj_close()
{
void **v0; // rbx
void **v1; // rdi

v0 = (void **)first_object_list;
if ( first_object_list )
{
do
{
free(v0[1]);
v1 = v0;
v0 = (void **)v0[4];
free(v1);
}
while ( v0 );
}
}

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

v0 = (void **)first_object_list;
if ( first_object_list )
{
do
{
free(v0[1]);
v1 = v0;
v0 = (void **)v0[4];
free(v1);
}
while ( v0 );
}
}

original_code:
void gfxobj_close(void)
{
 struct gfx_object_list *object_list,*object_next;
 for(object_list = first_object_list ; object_list != 0 ; object_list=object_next)
 {
  free(object_list->objects);
  object_next = object_list->next;
  free(object_list);
 }
}

canonical_original_code:
void gfxobj_close()
{
 struct gfx_object_list *object_list; struct gfx_object_list *object_next;
 for(object_list = first_object_list ; object_list != 0 ; object_list=object_next)
 {
  free(object_list->objects);
  object_next = object_list->next;
  free(object_list);
 }
}

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

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


decompiled_code:
void gfxobj_mark_all_pixels_dirty()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void gfxobj_mark_all_pixels_dirty(struct gfx_object_list *object_list)
{
}


decompiled_code:
unsigned __int64 gfxobj_update()
{
int *v0; // rbx
unsigned __int64 result; // rax

v0 = (int *)first_object_list;
if ( first_object_list )
{
do
{
result = gfxobj_update_one(v0);
v0 = (int *)*((_QWORD *)v0 + 4);
}
while ( v0 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 func7()
{
int *v0; // rbx
unsigned __int64 result; // rax

v0 = (int *)first_object_list;
if ( first_object_list )
{
do
{
result = func1(v0);
v0 = (int *)*((_QWORD *)v0 + 4);
}
while ( v0 );
}
return result;
}

original_code:
void gfxobj_update(void)
{
 struct gfx_object_list *object_list;
 for(object_list=first_object_list ; object_list != 0 ; object_list=object_list->next)
  gfxobj_update_one(object_list);
}

canonical_original_code:
void gfxobj_update()
{
 struct gfx_object_list *object_list;
 for(object_list=first_object_list ; object_list != 0 ; object_list=object_list->next)
  gfxobj_update_one(object_list);
}


decompiled_code:
__int64 __fastcall gfxobj_draw(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 i; // rbx

result = Machine;
v2 = *(_QWORD *)(Machine + 768LL);
for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 72) )
{
if ( *(_DWORD *)(i + 92) )
result = draw_object_one(v2, (unsigned int *)i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 i; // rbx

result = Machine;
v2 = *(_QWORD *)(Machine + 768LL);
for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 72) )
{
if ( *(_DWORD *)(i + 92) )
result = func2(v2, (unsigned int *)i);
}
return result;
}

original_code:
void gfxobj_draw(struct gfx_object_list *object_list)
{
 struct osd_bitmap *bitmap = Machine->scrbitmap;
 struct gfx_object *object;
 for(object=object_list->first_object ; object ; object=object->next)
 {
  if(object->visible )
   draw_object_one(bitmap,object);
 }
}