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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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()
{
unsigned __int8 *v0; // rcx
unsigned __int8 *v1; // rdi
int v2; // edx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func20()
{
unsigned __int8 *v0; // rcx
unsigned __int8 *v1; // rdi
int v2; // edx
__int64 result; // rax

v0 = (unsigned __int8 *)memory_region(130LL);
v1 = v0 + 2048;
do
{
v2 = *v0++;
result = v2 & 0xFFFFFFFC | (v2 >> 1) & 1 | (2 * (_BYTE)v2) & 2;
*(v0 - 1) = v2 & 0xFC | (v2 >> 1) & 1 | (2 * v2) & 2;
}
while ( v1 != v0 );
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: i int

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

return_type: unsigned int


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; // er8
int v1; // eax
__int64 v3; // [rsp+0h] [rbp-Ch]
int v4; // [rsp+8h] [rbp-4h]

v4 = 0;
v3 = 0x55000000C7LL;
v0 = *((_DWORD *)&v3 + slapfight_status_state);
v1 = slapfight_status_state + 1;
slapfight_status = v0;
if ( slapfight_status_state + 1 > 2 )
v1 = 0;
slapfight_status_state = v1;
return v0;
}

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

v4 = 0;
v3 = 0x55000000C7LL;
v0 = *((_DWORD *)&v3 + slapfight_status_state);
v1 = slapfight_status_state + 1;
slapfight_status = v0;
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 result; // rax
__int16 v1; // [rsp+1h] [rbp-3h]
char v2; // [rsp+3h] [rbp-1h]

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

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
__int16 v1; // [rsp+1h] [rbp-3h]
char v2; // [rsp+3h] [rbp-1h]

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

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 *


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


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

return_type: int


decompiled_code:
int *__fastcall slapfight_vh_screenrefresh(__int64 a1)
{
int v1; // er12
__int64 v2; // r13
int v3; // edx
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rdx
unsigned __int64 v7; // r14
__int16 v8; // ax
unsigned int v9; // er10
int v10; // edx
__int64 v11; // rcx
int *result; // rax
int v13; // er14
__int64 v14; // r15
__int16 v15; // dx
int v16; // esi
char v17; // al
__int64 v18; // [rsp-28h] [rbp-70h]
__int64 v19; // [rsp-28h] [rbp-70h]
__int64 v20; // [rsp-28h] [rbp-70h]
int v21; // [rsp+8h] [rbp-40h] BYREF
int v22[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = (*(unsigned __int8 *)(colorram + v2) << 8) & 0xF00;
v4 = *(unsigned __int8 *)(videoram + v2);
v5 = *(_BYTE *)(colorram + v2--) >> 4;
v6 = (unsigned int)(v4 + v3);
v18 = (unsigned int)(8 * (v1 >> 6));
LOBYTE(v4) = v1--;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 520LL), v6, v5, 0LL, 0LL, 8 * (v4 & 0x3Fu), v18, 0LL, 0LL, 0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v21 = -((unsigned __int8)*slapfight_scrollx_lo + ((unsigned __int8)*slapfight_scrollx_hi << 8));
v22[0] = 1 - (unsigned __int8)*slapfight_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v21, 1LL, v22, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(spriteram + v7 + 2);
v9 = *(unsigned __int8 *)(spriteram + v7) + ((4 * v8) & 0x300);
v19 = *(unsigned __int8 *)(spriteram + v7 + 3);
v10 = *(unsigned __int8 *)(spriteram + v7 + 1);
v11 = ((int)*(unsigned __int8 *)(spriteram + v7 + 2) >> 1) & 0xF;
v7 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v9,
v11,
0LL,
0LL,
v10 + ((v8 << 8) & 0x100u) - 13,
v19,
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v7 );
}
result = &slapfight_videoram_size;
v13 = slapfight_videoram_size - 1;
if ( slapfight_videoram_size - 1 >= 0 )
{
v14 = v13;
do
{
v15 = *(unsigned __int8 *)(slapfight_colorram + v14);
v16 = *(unsigned __int8 *)(slapfight_videoram + v14--);
v20 = (unsigned int)(8 * (v13 >> 6));
v17 = v13--;
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v16 + ((v15 << 8) & 0x300u),
(unsigned __int8)v15 >> 2,
0LL,
0LL,
8 * (v17 & 0x3Fu),
v20,
Machine + 776LL,
2LL,
0LL);
}
while ( v13 != -1 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func14(__int64 a1)
{
int v1; // er12
__int64 v2; // r13
int v3; // edx
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rdx
unsigned __int64 v7; // r14
__int16 v8; // ax
unsigned int v9; // er10
int v10; // edx
__int64 v11; // rcx
int *result; // rax
int v13; // er14
__int64 v14; // r15
__int16 v15; // dx
int v16; // esi
char v17; // al
__int64 v18; // [rsp-28h] [rbp-70h]
__int64 v19; // [rsp-28h] [rbp-70h]
__int64 v20; // [rsp-28h] [rbp-70h]
int v21; // [rsp+8h] [rbp-40h] BYREF
int v22[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = (*(unsigned __int8 *)(colorram + v2) << 8) & 0xF00;
v4 = *(unsigned __int8 *)(videoram + v2);
v5 = *(_BYTE *)(colorram + v2--) >> 4;
v6 = (unsigned int)(v4 + v3);
v18 = (unsigned int)(8 * (v1 >> 6));
LOBYTE(v4) = v1--;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 520LL), v6, v5, 0LL, 0LL, 8 * (v4 & 0x3Fu), v18, 0LL, 0LL, 0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v21 = -((unsigned __int8)*slapfight_scrollx_lo + ((unsigned __int8)*slapfight_scrollx_hi << 8));
v22[0] = 1 - (unsigned __int8)*slapfight_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v21, 1LL, v22, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v7 = 0LL;
do
{
v8 = *(unsigned __int8 *)(spriteram + v7 + 2);
v9 = *(unsigned __int8 *)(spriteram + v7) + ((4 * v8) & 0x300);
v19 = *(unsigned __int8 *)(spriteram + v7 + 3);
v10 = *(unsigned __int8 *)(spriteram + v7 + 1);
v11 = ((int)*(unsigned __int8 *)(spriteram + v7 + 2) >> 1) & 0xF;
v7 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v9,
v11,
0LL,
0LL,
v10 + ((v8 << 8) & 0x100u) - 13,
v19,
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v7 );
}
result = &slapfight_videoram_size;
v13 = slapfight_videoram_size - 1;
if ( slapfight_videoram_size - 1 >= 0 )
{
v14 = v13;
do
{
v15 = *(unsigned __int8 *)(slapfight_colorram + v14);
v16 = *(unsigned __int8 *)(slapfight_videoram + v14--);
v20 = (unsigned int)(8 * (v13 >> 6));
v17 = v13--;
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v16 + ((v15 << 8) & 0x300u),
(unsigned __int8)v15 >> 2,
0LL,
0LL,
8 * (v17 & 0x3Fu),
v20,
Machine + 776LL,
2LL,
0LL);
}
while ( v13 != -1 );
}
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

variable_types:
data
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 func5()
{
;
}

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 func6()
{
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 v1; // rbx
__int64 result; // rax
__int64 i; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
__int64 i; // rbp

v1 = *(_QWORD *)(a1 + 16);
result = Machine;
for ( i = *(_QWORD *)(Machine + 768LL); v1; v1 = *(_QWORD *)(v1 + 72) )
{
while ( 1 )
{
result = *(unsigned int *)(v1 + 92);
if ( (_DWORD)result )
break;
v1 = *(_QWORD *)(v1 + 72);
if ( !v1 )
return result;
}
result = func2(i, (unsigned int *)v1);
}
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);
 }
}


original_code:
void circusc_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

canonical_original_code:
void circusc_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;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

variable_types:
palette
unsigned char *

variable_types: i int


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

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

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

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

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

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


decompiled_code:
__int64 circusc_sh_timer_r()
{
int v0; // eax

v0 = cpu_gettotalcycles();
return ((unsigned __int8)((3775147220LL * v0) >> 41) - (unsigned __int8)((4 * v0) >> 31)) & 0xF;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax

v0 = cpu_gettotalcycles();
return ((unsigned __int8)((3775147220LL * v0) >> 41) - (unsigned __int8)((4 * v0) >> 31)) & 0xF;
}

original_code:
data_t circusc_sh_timer_r(offs_t offset)
{
 int clock;
 clock = (cpu_gettotalcycles()*4) / (14318180/6144);
 return clock & 0xF;
}

canonical_original_code:
unsigned int circusc_sh_timer_r(unsigned int offset)
{
 int clock;
 clock = (cpu_gettotalcycles()*4) / (14318180/6144);
 return clock & 0xF;
}

variable_types: clock int


decompiled_code:
__int64 circusc_sh_irqtrigger_w()
{
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func3()
{
return cpu_cause_interrupt(1LL, 255LL);
}

original_code:
void circusc_sh_irqtrigger_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(1,0xff);
}

canonical_original_code:
void circusc_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(1,0xff);
}


decompiled_code:
__int64 circusc_dac_w()
{
return DAC_data_w(0LL);
}

canonical_decompiled_code:
__int64 func4()
{
return DAC_data_w(0LL);
}

original_code:
void circusc_dac_w(offs_t offset,data_t data)
{
 DAC_data_w(0,data);
}

canonical_original_code:
void circusc_dac_w(unsigned int offset, unsigned int data)
{
 DAC_data_w(0,data);
}


decompiled_code:
// attributes: thunk
__int64 init_circusc()
{
return konami1_decode();
}

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

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

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


decompiled_code:
void init_timeplt()
{
sprite_multiplex_hack = 1;
}

canonical_decompiled_code:
void func0()
{
sprite_multiplex_hack = 1;
}

original_code:
void init_timeplt(void)
{
 sprite_multiplex_hack = 1;
}


decompiled_code:
void init_psurge()
{
sprite_multiplex_hack = 0;
}

canonical_decompiled_code:
void func1()
{
sprite_multiplex_hack = 0;
}

original_code:
void init_psurge(void)
{
 sprite_multiplex_hack = 0;
}


original_code:
void timeplt_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,bit4;
  bit0 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 4) & 0x01;
  bit4 = (color_prom[Machine->drv->total_colors] >> 5) & 0x01;
  *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  bit0 = (color_prom[Machine->drv->total_colors] >> 6) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 7) & 0x01;
  bit2 = (color_prom[0] >> 0) & 0x01;
  bit3 = (color_prom[0] >> 1) & 0x01;
  bit4 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[0] >> 4) & 0x01;
  bit2 = (color_prom[0] >> 5) & 0x01;
  bit3 = (color_prom[0] >> 6) & 0x01;
  bit4 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  color_prom++;
 }
 color_prom += Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

canonical_original_code:
void timeplt_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; int bit4;
  bit0 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 4) & 0x01;
  bit4 = (color_prom[Machine->drv->total_colors] >> 5) & 0x01;
  *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  bit0 = (color_prom[Machine->drv->total_colors] >> 6) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 7) & 0x01;
  bit2 = (color_prom[0] >> 0) & 0x01;
  bit3 = (color_prom[0] >> 1) & 0x01;
  bit4 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[0] >> 4) & 0x01;
  bit2 = (color_prom[0] >> 5) & 0x01;
  bit3 = (color_prom[0] >> 6) & 0x01;
  bit4 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  color_prom++;
 }
 color_prom += Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 psurge_protection_r()
{
return 128LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 128LL;
}

original_code:
static data_t psurge_protection_r(offs_t offset)
{
 return 0x80;
}

canonical_original_code:
static unsigned int psurge_protection_r(unsigned int offset)
{
 return 0x80;
}


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

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


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

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

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

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

original_code:
static data_t timeplt_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 timeplt_timer[clock/512];
}

canonical_original_code:
static unsigned int timeplt_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 timeplt_timer[clock/512];
}


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

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

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

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

original_code:
void timeplt_sh_irqtrigger_w(offs_t offset,data_t data)
{
 static int last;
 if (last == 0 && data)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

canonical_original_code:
void timeplt_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last == 0 && data)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

variable_types: last int


decompiled_code:
_BOOL8 timeplt_vh_start()
{
bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return bg_tilemap == 0;
}

canonical_decompiled_code:
_BOOL8 func9()
{
bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return bg_tilemap == 0;
}

original_code:
int timeplt_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 return 0;
}

canonical_original_code:
int timeplt_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall timeplt_flipscreen_w(__int64 a1, char a2)
{
return flip_screen_w(0LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char a2)
{
return flip_screen_w(0LL, a2 & 1);
}

original_code:
void timeplt_flipscreen_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 1);
}

canonical_original_code:
void timeplt_flipscreen_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 1);
}


decompiled_code:
__int64 timeplt_scanline_r()
{
return cpu_scalebyfcount(256LL);
}

canonical_decompiled_code:
__int64 func11()
{
return cpu_scalebyfcount(256LL);
}

original_code:
data_t timeplt_scanline_r(offs_t offset)
{
 return cpu_scalebyfcount(256);
}

canonical_original_code:
unsigned int timeplt_scanline_r(unsigned int offset)
{
 return cpu_scalebyfcount(256);
}


decompiled_code:
__int64 __fastcall timeplt_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func12(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

original_code:
void timeplt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,1);
}

canonical_original_code:
void timeplt_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,1);
}

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


decompiled_code:
__int64 __fastcall timeplt_coin_counter_w(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

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

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


decompiled_code:
void *__fastcall get_tile_info(int a1)
{
__int64 v1; // rax
int v2; // edi
__int64 v3; // rsi
__int64 v4; // r9
unsigned int v5; // edx
void *result; // rax
__int64 v7; // r8
int v8; // esi

v1 = a1;
v2 = *(unsigned __int8 *)(timeplt_colorram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (*(unsigned __int8 *)(timeplt_videoram + v1) + ((8 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
result = &tile_info;
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
*((_QWORD *)&tile_info + 1) = v4 + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0x1F);
v7 = *(_QWORD *)(v3 + 32);
v8 = 0;
if ( v7 )
v8 = *(_DWORD *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v8;
*((_DWORD *)&tile_info + 5) = (unsigned __int8)v2 >> 6;
*((_DWORD *)&tile_info + 6) = (v2 >> 4) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(int a1)
{
__int64 v1; // rax
int v2; // edi
__int64 v3; // rsi
__int64 v4; // r9
unsigned int v5; // edx
void *result; // rax
__int64 v7; // r8
int v8; // esi

v1 = a1;
v2 = *(unsigned __int8 *)(timeplt_colorram + a1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (*(unsigned __int8 *)(timeplt_videoram + v1) + ((8 * (_WORD)v2) & 0x100u)) % *(_DWORD *)(v3 + 8);
result = &tile_info;
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
*((_QWORD *)&tile_info + 1) = v4 + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0x1F);
v7 = *(_QWORD *)(v3 + 32);
v8 = 0;
if ( v7 )
v8 = *(_DWORD *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v8;
*((_DWORD *)&tile_info + 5) = (unsigned __int8)v2 >> 6;
*((_DWORD *)&tile_info + 6) = (v2 >> 4) & 1;
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = timeplt_colorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (timeplt_videoram[tile_index] + ((attr & 0x20) << 3)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x1f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x10) >> 4;
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = timeplt_colorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (timeplt_videoram[tile_index] + ((attr & 0x20) << 3)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x1f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x10) >> 4;
}

variable_types:
attr
unsigned char

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


original_code:
static void filter_w(int chip, int channel, int data)
{
 int 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 draw_sprites(__int64 a1)
{
__int64 result; // rax
int v2; // er13
__int64 v3; // rbx
unsigned int v4; // er15
int v5; // er14
unsigned int v6; // er12
_BOOL4 v7; // ebp
unsigned int v8; // [rsp+Ch] [rbp-5Ch]
int v9; // [rsp+10h] [rbp-58h]
unsigned int v10; // [rsp+14h] [rbp-54h]
__int64 v11; // [rsp+18h] [rbp-50h]
__int64 v12; // [rsp+20h] [rbp-48h]

v12 = Machine + 776LL;
result = (__int64)&spriteram_size;
v11 = *(_QWORD *)(Machine + 520LL);
v2 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
while ( 1 )
{
v4 = *(unsigned __int8 *)(spriteram + v3);
v5 = *(unsigned __int8 *)(spriteram_2 + v3) - 1;
v10 = *(unsigned __int8 *)(spriteram_2 + v3);
v6 = *(_BYTE *)(spriteram_2 + v3 - 1) & 0x3F;
v7 = *(char *)(spriteram_2 + v3 - 1) >= 0;
v9 = *(unsigned __int8 *)(spriteram + v3 - 1);
v8 = *(_BYTE *)(spriteram_2 + v3 - 1) & 0x40;
drawgfx(
a1,
v11,
*(unsigned __int8 *)(spriteram + v3),
*(_BYTE *)(spriteram_2 + v3 - 1) & 0x3F,
*(_BYTE *)(spriteram_2 + v3 - 1) & 0x40,
*(char *)(spriteram_2 + v3 - 1) >= 0,
(unsigned int)(240 - v9),
(unsigned int)v5,
v12,
2LL,
0LL);
result = (unsigned int)sprite_multiplex_hack;
if ( sprite_multiplex_hack )
{
if ( v5 <= 239 )
{
result = v10;
if ( (unsigned int)(v2 - 5) > 0x20 )
break;
}
}
v3 -= 2LL;
v2 -= 2;
if ( v2 < 0 )
return result;
}
v3 -= 2LL;
result = drawgfx(
a1,
v11,
v4,
v6,
v8,
v7,
(unsigned __int8)(112 - v9),
(unsigned __int8)(v10 + 127),
v12,
2LL,
0LL);
v2 -= 2;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
int v2; // er13
__int64 v3; // rbx
unsigned int v4; // er15
int v5; // er14
unsigned int v6; // er12
_BOOL4 v7; // ebp
unsigned int v8; // [rsp+Ch] [rbp-5Ch]
int v9; // [rsp+10h] [rbp-58h]
unsigned int v10; // [rsp+14h] [rbp-54h]
__int64 v11; // [rsp+18h] [rbp-50h]
__int64 v12; // [rsp+20h] [rbp-48h]

v12 = Machine + 776LL;
result = (__int64)&spriteram_size;
v11 = *(_QWORD *)(Machine + 520LL);
v2 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
while ( 1 )
{
v4 = *(unsigned __int8 *)(spriteram + v3);
v5 = *(unsigned __int8 *)(spriteram_2 + v3) - 1;
v10 = *(unsigned __int8 *)(spriteram_2 + v3);
v6 = *(_BYTE *)(spriteram_2 + v3 - 1) & 0x3F;
v7 = *(char *)(spriteram_2 + v3 - 1) >= 0;
v9 = *(unsigned __int8 *)(spriteram + v3 - 1);
v8 = *(_BYTE *)(spriteram_2 + v3 - 1) & 0x40;
drawgfx(
a1,
v11,
*(unsigned __int8 *)(spriteram + v3),
*(_BYTE *)(spriteram_2 + v3 - 1) & 0x3F,
*(_BYTE *)(spriteram_2 + v3 - 1) & 0x40,
*(char *)(spriteram_2 + v3 - 1) >= 0,
(unsigned int)(240 - v9),
(unsigned int)v5,
v12,
2LL,
0LL);
result = (unsigned int)sprite_multiplex_hack;
if ( sprite_multiplex_hack )
{
if ( v5 <= 239 )
{
result = v10;
if ( (unsigned int)(v2 - 5) > 0x20 )
break;
}
}
v3 -= 2LL;
v2 -= 2;
if ( v2 < 0 )
return result;
}
v3 -= 2LL;
result = drawgfx(
a1,
v11,
v4,
v6,
v8,
v7,
(unsigned __int8)(112 - v9),
(unsigned __int8)(v10 + 127),
v12,
2LL,
0LL);
v2 -= 2;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 const struct GfxElement *gfx = Machine->gfx[1];
 const struct rectangle *clip = &Machine->visible_area;
 int offs;
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  int code,color,sx,sy,flipx,flipy;
  code = spriteram[offs + 1];
  color = spriteram_2[offs] & 0x3f;
  sx = 240 - spriteram[offs];
  sy = spriteram_2[offs + 1]-1;
  flipx = spriteram_2[offs] & 0x40;
  flipy = !(spriteram_2[offs] & 0x80);
  drawgfx(bitmap,gfx,
    code,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,0);
  if (sprite_multiplex_hack)
  {
   if (sy < 240)
   {
    if (offs <= 2*2 || offs >= 19*2)
    {
     drawgfx(bitmap,gfx,
       code,
       color,
       flipx,flipy,
       (sx + 128) & 0xff,(sy + 128) & 0xff,
       clip,TRANSPARENCY_PEN,0);
    }
   }
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct GfxElement *gfx = Machine->gfx[1];
 struct rectangle *clip = &Machine->visible_area;
 int offs;
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  int code; int color; int sx; int sy; int flipx; int flipy;
  code = spriteram[offs + 1];
  color = spriteram_2[offs] & 0x3f;
  sx = 240 - spriteram[offs];
  sy = spriteram_2[offs + 1]-1;
  flipx = spriteram_2[offs] & 0x40;
  flipy = !(spriteram_2[offs] & 0x80);
  drawgfx(bitmap,gfx,
    code,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,0);
  if (sprite_multiplex_hack)
  {
   if (sy < 240)
   {
    if (offs <= 2*2 || offs >= 19*2)
    {
     drawgfx(bitmap,gfx,
       code,
       color,
       flipx,flipy,
       (sx + 128) & 0xff,(sy + 128) & 0xff,
       clip,TRANSPARENCY_PEN,0);
    }
   }
  }
 }
}

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

variable_types: offs int

variable_types: code int

variable_types: color int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 __fastcall input_port_1_bit_r(char a1)
{
return (((int)readinputport(1LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (((int)readinputport(1LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

original_code: data_t input_port_1_bit_r(offs_t offset) { return (readinputport(1) & (1 << offset)) ? 0 : 228; }

canonical_original_code: unsigned int input_port_1_bit_r(unsigned int offset) { return (readinputport(1) & (1 << offset)) ? 0 : 228; }

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall input_port_2_bit_r(char a1)
{
return (((int)readinputport(2LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return (((int)readinputport(2LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

original_code: data_t input_port_2_bit_r(offs_t offset) { return (readinputport(2) & (1 << offset)) ? 0 : 228; }

canonical_original_code: unsigned int input_port_2_bit_r(unsigned int offset) { return (readinputport(2) & (1 << offset)) ? 0 : 228; }


decompiled_code:
__int64 __fastcall tempest_led_w(__int64 a1, unsigned int a2)
{
osd_led_w(0LL, ~(a2 >> 1));
return osd_led_w(1LL, ~a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
osd_led_w(0LL, ~(a2 >> 1));
return osd_led_w(1LL, ~a2);
}

original_code:
static void tempest_led_w(offs_t offset,data_t data)
{
 osd_led_w (0, ~(data >> 1));
 osd_led_w (1, ~data);
}

canonical_original_code:
static void tempest_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w (0, ~(data >> 1));
 osd_led_w (1, ~data);
}

variable_types:
data
unsigned int


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

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

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

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

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

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

variable_types: lastval int


decompiled_code:
__int64 tempest_IN0_r()
{
unsigned int v0; // er12
__int16 v1; // r8
unsigned int v2; // eax

v0 = readinputport(0LL);
if ( (unsigned int)avgdvg_done() )
v0 |= 0x40u;
v1 = cpu_gettotalcycles();
v2 = v0;
if ( (v1 & 0x100) != 0 )
{
LOBYTE(v2) = v0 | 0x80;
v0 = v2;
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
__int16 v1; // r8
unsigned int v2; // eax

v0 = readinputport(0LL);
if ( (unsigned int)avgdvg_done() )
v0 |= 0x40u;
v1 = cpu_gettotalcycles();
v2 = v0;
if ( (v1 & 0x100) != 0 )
{
LOBYTE(v2) = v0 | 0x80;
v0 = v2;
}
return v0;
}

original_code:
static data_t tempest_IN0_r(offs_t offset)
{
 int res;
 res = readinputport(0);
 if (avgdvg_done())
  res|=0x40;
 if (cpu_gettotalcycles() & 0x100)
  res |=0x80;
 return res;
}

canonical_original_code:
static unsigned int tempest_IN0_r(unsigned int offset)
{
 int res;
 res = readinputport(0);
 if (avgdvg_done())
  res|=0x40;
 if (cpu_gettotalcycles() & 0x100)
  res |=0x80;
 return res;
}

variable_types: res int


decompiled_code:
void __fastcall pcktgal_adpcm_data_w(__int64 a1, int a2)
{
msm5205next = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
msm5205next = a2;
}

original_code:
static void pcktgal_adpcm_data_w(offs_t offset,data_t data)
{
 msm5205next=data;
}

canonical_original_code:
static void pcktgal_adpcm_data_w(unsigned int offset, unsigned int data)
{
 msm5205next=data;
}


decompiled_code:
__int64 __fastcall pcktgal_flipscreen_w(__int64 a1, unsigned int a2)
{
int v2; // esi
_QWORD *v3; // rcx
__int64 result; // rax
__int64 v5; // rdi

v2 = (a2 >> 7) & 1;
flipscreen = v2;
if ( v2 != last_flip_1 )
{
v3 = dirtybuffer;
result = 0x101010101010101LL;
v5 = (__int64)(dirtybuffer + 1);
*dirtybuffer = 0x101010101010101LL;
v3[255] = 0x101010101010101LL;
memset(
(void *)(v5 & 0xFFFFFFFFFFFFFFF8LL),
1u,
8 * ((unsigned __int64)((unsigned int)v3 - (v5 & 0xFFFFFFF8) + 2048) >> 3));
}
last_flip_1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
int v2; // esi
_QWORD *v3; // rcx
__int64 result; // rax
__int64 v5; // rdi

v2 = (a2 >> 7) & 1;
flipscreen = v2;
if ( v2 != last_flip_1 )
{
v3 = dirtybuffer;
result = 0x101010101010101LL;
v5 = (__int64)(dirtybuffer + 1);
*dirtybuffer = 0x101010101010101LL;
v3[255] = 0x101010101010101LL;
memset(
(void *)(v5 & 0xFFFFFFFFFFFFFFF8LL),
1u,
8 * ((unsigned __int64)((unsigned int)v3 - (v5 & 0xFFFFFFF8) + 2048) >> 3));
}
last_flip_1 = v2;
return result;
}

original_code:
void pcktgal_flipscreen_w(offs_t offset,data_t data)
{
 static int last_flip;
 flipscreen = (data&0x80) ? 1 : 0;
 if (last_flip!=flipscreen)
  memset(dirtybuffer,1,0x800);
 last_flip=flipscreen;
}

canonical_original_code:
void pcktgal_flipscreen_w(unsigned int offset, unsigned int data)
{
 static int last_flip;
 flipscreen = (data&0x80) ? 1 : 0;
 if (last_flip!=flipscreen)
  memset(dirtybuffer,1,0x800);
 last_flip=flipscreen;
}


decompiled_code:
char *init_graphics()
{
__int64 v0; // rbx
char *result; // rax
int v2; // er8
char *v3; // rsi
int i; // edi
char v5; // dl
char v6; // cl

v0 = memory_region(137LL);
result = (char *)memory_region_length(137LL);
if ( (int)result > 0 )
{
v2 = (int)result;
v3 = (char *)(v0 + 16);
for ( i = 0; i < v2; i += 32 )
{
result = v3 - 16;
do
{
v5 = result[16];
v6 = *result++;
result[15] = v6;
*(result - 1) = v5;
}
while ( v3 != result );
v3 += 32;
}
}
return result;
}

canonical_decompiled_code:
char *func3()
{
__int64 v0; // rbx
char *result; // rax
int v2; // er8
char *v3; // rsi
int i; // edi
char v5; // dl
char v6; // cl

v0 = memory_region(137LL);
result = (char *)memory_region_length(137LL);
if ( (int)result > 0 )
{
v2 = (int)result;
v3 = (char *)(v0 + 16);
for ( i = 0; i < v2; i += 32 )
{
result = v3 - 16;
do
{
v5 = result[16];
v6 = *result++;
result[15] = v6;
*(result - 1) = v5;
}
while ( v3 != result );
v3 += 32;
}
}
return result;
}

original_code:
static void init_graphics(void)
{
 unsigned char *rom = memory_region(REGION_GFX1);
 int len = memory_region_length(REGION_GFX1);
 int i,j,temp[16];
 for (i = 0x00000;i < len;i += 32)
 {
  for (j=0; j<16; j++)
  {
   temp[j] = rom[i+j+16];
   rom[i+j+16] = rom[i+j];
   rom[i+j] = temp[j];
  }
 }
}

canonical_original_code:
static void init_graphics()
{
 unsigned char *rom = memory_region(REGION_GFX1);
 int len = memory_region_length(REGION_GFX1);
 int i; int j; int temp[16];
 for (i = 0x00000;i < len;i += 32)
 {
  for (j=0; j<16; j++)
  {
   temp[j] = rom[i+j+16];
   rom[i+j+16] = rom[i+j];
   rom[i+j] = temp[j];
  }
 }
}

variable_types:
rom
unsigned char *

variable_types: len int

variable_types: i int

variable_types: j int

variable_types:
temp
int [16]


decompiled_code:
char *init_pcktgal()
{
init_deco222();
return init_graphics();
}

canonical_decompiled_code:
char *func5()
{
func4();
return func3();
}

original_code:
static void init_pcktgal(void)
{
 init_deco222();
 init_graphics();
}

canonical_original_code:
static void init_pcktgal()
{
 init_deco222();
 init_graphics();
}


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

MSM5205_data_w(0LL, (unsigned int)(msm5205next >> 4));
msm5205next *= 16;
v0 = toggle_0 == 1;
result = (unsigned int)(1 - toggle_0);
toggle_0 = 1 - toggle_0;
if ( !v0 )
result = cpu_cause_interrupt(1LL, 1LL);
return result;
}

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

MSM5205_data_w(0LL, (unsigned int)(msm5205next >> 4));
msm5205next *= 16;
v0 = toggle_0 == 1;
result = (unsigned int)(1 - toggle_0);
toggle_0 = 1 - toggle_0;
if ( !v0 )
result = cpu_cause_interrupt(1LL, 1LL);
return result;
}

original_code:
static void pcktgal_adpcm_int(int data)
{
 static int toggle;
 MSM5205_data_w(0,msm5205next >> 4);
 msm5205next<<=4;
 toggle = 1 - toggle;
 if (toggle)
  cpu_cause_interrupt(1,1);
}

variable_types: data int

variable_types: toggle int


decompiled_code:
void *__fastcall pcktgal_sound_bank_w(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
v3 = v2 + 81920;
else
v3 = v2 + 0x10000;
cpu_bankbase[3] = v3;
result = &ophw;
if ( ophw == 3 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
v3 = v2 + 81920;
else
v3 = v2 + 0x10000;
cpu_bankbase[3] = v3;
result = &ophw;
if ( ophw == 3 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void pcktgal_sound_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 4) { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (UINT8 *)(&RAM[0x14000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (UINT8 *)(&RAM[0x10000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

canonical_original_code:
static void pcktgal_sound_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 4) { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (unsigned char *)(&RAM[0x14000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (unsigned char *)(&RAM[0x10000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall pcktgal_bank_w(__int64 a1, char a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 result; // rax
unsigned int v5; // eax
__int64 v6; // rdi

v2 = memory_region(129LL);
v3 = v2 + 0x4000;
if ( (a2 & 1) == 0 )
v3 = v2 + 0x10000;
cpu_bankbase[1] = v3;
result = ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = (unsigned int)cpu_get_pc();
cpu_setOPbase16(v6);
result = ophw;
}
if ( (a2 & 2) != 0 )
{
cpu_bankbase[2] = v2 + 24576;
if ( (_BYTE)result != 2 )
return result;
LABEL_9:
ophw = -1;
v5 = cpu_get_pc();
return cpu_setOPbase16(v5);
}
cpu_bankbase[2] = v2 + 73728;
if ( (_BYTE)result == 2 )
goto LABEL_9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 result; // rax
unsigned int v5; // eax
__int64 v6; // rdi

v2 = memory_region(129LL);
v3 = v2 + 0x4000;
if ( (a2 & 1) == 0 )
v3 = v2 + 0x10000;
cpu_bankbase[1] = v3;
result = ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = (unsigned int)cpu_get_pc();
cpu_setOPbase16(v6);
result = ophw;
}
if ( (a2 & 2) != 0 )
{
cpu_bankbase[2] = v2 + 24576;
if ( (_BYTE)result != 2 )
return result;
LABEL_9:
ophw = -1;
v5 = cpu_get_pc();
return cpu_setOPbase16(v5);
}
cpu_bankbase[2] = v2 + 73728;
if ( (_BYTE)result == 2 )
goto LABEL_9;
return result;
}

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

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


decompiled_code:
__int64 pcktgal_adpcm_reset_r()
{
MSM5205_reset_w(0LL, 0LL);
return 0LL;
}

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

original_code:
static data_t pcktgal_adpcm_reset_r(offs_t offset)
{
 MSM5205_reset_w(0,0);
 return 0;
}

canonical_original_code:
static unsigned int pcktgal_adpcm_reset_r(unsigned int offset)
{
 MSM5205_reset_w(0,0);
 return 0;
}


decompiled_code:
__int64 pcktgal_sound_w()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 2LL);
}

canonical_decompiled_code:
__int64 func10()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 2LL);
}

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

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


original_code:
static void init_deco222(void)
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU2);
 int diff = memory_region_length(REGION_CPU2) / 2;
 memory_set_opcode_base(1,rom+diff);
 for (A = 0;A < diff;A++)
  rom[A + diff] = (rom[A] & 0x9f) | ((rom[A] & 0x20) << 1) | ((rom[A] & 0x40) >> 1);
}

canonical_original_code:
static void init_deco222()
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU2);
 int diff = memory_region_length(REGION_CPU2) / 2;
 memory_set_opcode_base(1,rom+diff);
 for (A = 0;A < diff;A++)
  rom[A + diff] = (rom[A] & 0x9f) | ((rom[A] & 0x20) << 1) | ((rom[A] & 0x40) >> 1);
}

variable_types: A int

variable_types: diff int


decompiled_code:
// attributes: thunk
__int64 tankbatt_led_w()
{
return osd_led_w();
}

canonical_decompiled_code:
__int64 func2()
{
return osd_led_w();
}

original_code:
void tankbatt_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset, data);
}

canonical_original_code:
void tankbatt_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset, data);
}


decompiled_code:
__int64 __fastcall tankbatt_in0_r(char a1)
{
return ((unsigned int)readinputport(0LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
return ((unsigned int)readinputport(0LL) << (7 - a1)) & 0x80;
}

original_code:
data_t tankbatt_in0_r(offs_t offset)
{
 int val;
 val = readinputport(0);
 return ((val << (7-offset)) & 0x80);
}

canonical_original_code:
unsigned int tankbatt_in0_r(unsigned int offset)
{
 int val;
 val = readinputport(0);
 return ((val << (7-offset)) & 0x80);
}

variable_types: val int


decompiled_code:
__int64 __fastcall tankbatt_in1_r(char a1)
{
return ((unsigned int)readinputport(1LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return ((unsigned int)readinputport(1LL) << (7 - a1)) & 0x80;
}

original_code:
data_t tankbatt_in1_r(offs_t offset)
{
 int val;
 val = readinputport(1);
 return ((val << (7-offset)) & 0x80);
}

canonical_original_code:
unsigned int tankbatt_in1_r(unsigned int offset)
{
 int val;
 val = readinputport(1);
 return ((val << (7-offset)) & 0x80);
}


decompiled_code:
__int64 __fastcall tankbatt_dsw_r(char a1)
{
return ((unsigned int)readinputport(2LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return ((unsigned int)readinputport(2LL) << (7 - a1)) & 0x80;
}

original_code:
data_t tankbatt_dsw_r(offs_t offset)
{
 int val;
 val = readinputport(2);
 return ((val << (7-offset)) & 0x80);
}

canonical_original_code:
unsigned int tankbatt_dsw_r(unsigned int offset)
{
 int val;
 val = readinputport(2);
 return ((val << (7-offset)) & 0x80);
}


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

tankbatt_nmi_enable = a2;
if ( a2 )
result = cpu_clear_pending_interrupts(0LL);
return result;
}

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

tankbatt_nmi_enable = a2;
if ( a2 )
result = cpu_clear_pending_interrupts(0LL);
return result;
}

original_code:
void tankbatt_demo_interrupt_enable_w(offs_t offset,data_t data)
{
 tankbatt_nmi_enable = data;
 if (data != 0) cpu_clear_pending_interrupts(0);
}

canonical_original_code:
void tankbatt_demo_interrupt_enable_w(unsigned int offset, unsigned int data)
{
 tankbatt_nmi_enable = data;
 if (data != 0) cpu_clear_pending_interrupts(0);
}


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

result = a2 == 0;
tankbatt_nmi_enable = a2 == 0;
tankbatt_sound_enable = a2 == 0;
if ( a2 )
{
cpu_clear_pending_interrupts(0LL);
result = sample_stop(2LL);
}
return result;
}

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

result = a2 == 0;
tankbatt_nmi_enable = a2 == 0;
tankbatt_sound_enable = a2 == 0;
if ( a2 )
{
cpu_clear_pending_interrupts(0LL);
result = sample_stop(2LL);
}
return result;
}

original_code:
void tankbatt_interrupt_enable_w(offs_t offset,data_t data)
{
 tankbatt_nmi_enable = !data;
 tankbatt_sound_enable = !data;
 if (data != 0) cpu_clear_pending_interrupts(0);
 if (data) sample_stop (2);
}

canonical_original_code:
void tankbatt_interrupt_enable_w(unsigned int offset, unsigned int data)
{
 tankbatt_nmi_enable = !data;
 tankbatt_sound_enable = !data;
 if (data != 0) cpu_clear_pending_interrupts(0);
 if (data) sample_stop (2);
}


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

result = (unsigned int)tankbatt_sound_enable;
if ( tankbatt_sound_enable )
result = sample_start(1LL, 3LL, 0LL);
return result;
}

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

result = (unsigned int)tankbatt_sound_enable;
if ( tankbatt_sound_enable )
result = sample_start(1LL, 3LL, 0LL);
return result;
}

original_code:
void tankbatt_sh_expl_w(offs_t offset,data_t data)
{
 if (tankbatt_sound_enable)
  sample_start (1, 3, 0);
}

canonical_original_code:
void tankbatt_sh_expl_w(unsigned int offset, unsigned int data)
{
 if (tankbatt_sound_enable)
  sample_start (1, 3, 0);
}


decompiled_code:
__int64 __fastcall tankbatt_sh_engine_w(__int64 a1, int a2)
{
if ( !tankbatt_sound_enable )
return sample_stop(2LL);
if ( a2 )
return sample_start(2LL, 2LL, 1LL);
return sample_start(2LL, 1LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
if ( !tankbatt_sound_enable )
return sample_stop(2LL);
if ( a2 )
return sample_start(2LL, 2LL, 1LL);
return sample_start(2LL, 1LL, 1LL);
}

original_code:
void tankbatt_sh_engine_w(offs_t offset,data_t data)
{
 if (tankbatt_sound_enable)
 {
  if (data)
   sample_start (2, 2, 1);
  else
   sample_start (2, 1, 1);
 }
 else sample_stop (2);
}

canonical_original_code:
void tankbatt_sh_engine_w(unsigned int offset, unsigned int data)
{
 if (tankbatt_sound_enable)
 {
  if (data)
   sample_start (2, 2, 1);
  else
   sample_start (2, 1, 1);
 }
 else sample_stop (2);
}


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

result = (unsigned int)tankbatt_sound_enable;
if ( tankbatt_sound_enable )
result = sample_start(0LL, 0LL, 0LL);
return result;
}

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

result = (unsigned int)tankbatt_sound_enable;
if ( tankbatt_sound_enable )
result = sample_start(0LL, 0LL, 0LL);
return result;
}

original_code:
void tankbatt_sh_fire_w(offs_t offset,data_t data)
{
 if (tankbatt_sound_enable)
  sample_start (0, 0, 0);
}

canonical_original_code:
void tankbatt_sh_fire_w(unsigned int offset, unsigned int data)
{
 if (tankbatt_sound_enable)
  sample_start (0, 0, 0);
}


decompiled_code:
__int64 tankbatt_interrupt()
{
if ( (readinputport(0LL) & 0x60) == 0 )
return interrupt();
if ( tankbatt_nmi_enable )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func11()
{
if ( (readinputport(0LL) & 0x60) == 0 )
return interrupt();
if ( tankbatt_nmi_enable )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
int tankbatt_interrupt (void)
{
 if ((readinputport (0) & 0x60) == 0) return interrupt ();
 if (tankbatt_nmi_enable) return nmi_interrupt ();
 else return ignore_interrupt ();
}

canonical_original_code:
int tankbatt_interrupt()
{
 if ((readinputport (0) & 0x60) == 0) return interrupt ();
 if (tankbatt_nmi_enable) return nmi_interrupt ();
 else return ignore_interrupt ();
}


decompiled_code:
unsigned __int64 __fastcall MSM5205_update(int a1, char *a2, int a3)
{
__int64 v3; // rax
char *v5; // rdi
int v6; // eax
unsigned __int64 result; // rax
char *v8; // rdx

v3 = a1;
v5 = a2;
v6 = msm5205[12 * v3 + 9];
if ( !v6 )
return (unsigned __int64)memset(a2, 0, 2LL * a3);
result = (unsigned int)(16 * v6);
v8 = &a2[2 * a3];
if ( a3 )
{
do
{
v5 += 2;
*((_WORD *)v5 - 1) = result;
}
while ( v5 != v8 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1, char *a2, int a3)
{
__int64 v3; // rax
char *v5; // rdi
int v6; // eax
unsigned __int64 result; // rax
char *v8; // rdx

v3 = a1;
v5 = a2;
v6 = msm5205[12 * v3 + 9];
if ( !v6 )
return (unsigned __int64)memset(a2, 0, 2LL * a3);
result = (unsigned int)(16 * v6);
v8 = &a2[2 * a3];
if ( a3 )
{
do
{
v5 += 2;
*((_WORD *)v5 - 1) = result;
}
while ( v5 != v8 );
}
return result;
}

original_code:
static void MSM5205_update(int chip,INT16 *buffer,int length)
{
 struct MSM5205Voice *voice = &msm5205[chip];
 if(voice->signal)
 {
  short val = voice->signal * 16;
  while (length)
  {
   *buffer++ = val;
   length--;
  }
 }
 else
  memset (buffer,0,length*sizeof(INT16));
}

canonical_original_code:
static void MSM5205_update(int chip, short *buffer, int length)
{
 struct MSM5205Voice *voice = &msm5205[chip];
 if(voice->signal)
 {
  short val = voice->signal * 16;
  while (length)
  {
   *buffer++ = val;
   length--;
  }
 }
 else
  memset (buffer,0,length*sizeof(INT16));
}

variable_types: chip int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct MSM5205Voice { int stream; void *timer; int data; int vclk; int reset; int prescaler; int bitwidth; int signal; int step; } *

variable_types: val short


decompiled_code:
__int64 __fastcall MSM5205_set_timer(unsigned int a1, char a2)
{
__int64 result; // rax
int v3; // er14
_DWORD *v4; // rbx
char *v5; // r13

result = (__int64)prescaler_table_0;
v3 = prescaler_table_0[a2 & 3];
v4 = &msm5205[12 * a1];
if ( v4[7] != v3 )
{
if ( *((_QWORD *)v4 + 1) )
{
timer_remove();
*((_QWORD *)v4 + 1) = 0LL;
}
result = 48LL * (int)a1;
v5 = (char *)msm5205 + result;
*(_DWORD *)((char *)&msm5205[7] + result) = v3;
if ( v3 )
{
result = timer_pulse((unsigned int)(0x40000000 / (*(_DWORD *)(msm5205_intf + 4) / v3)), a1, MSM5205_vclk_callback);
*((_QWORD *)v5 + 1) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, char a2)
{
__int64 result; // rax
int v3; // er14
_DWORD *v4; // rbx
char *v5; // r13

result = (__int64)prescaler_table_0;
v3 = prescaler_table_0[a2 & 3];
v4 = &msm5205[12 * a1];
if ( v4[7] != v3 )
{
if ( *((_QWORD *)v4 + 1) )
{
timer_remove();
*((_QWORD *)v4 + 1) = 0LL;
}
result = 48LL * (int)a1;
v5 = (char *)msm5205 + result;
*(_DWORD *)((char *)&msm5205[7] + result) = v3;
if ( v3 )
{
result = timer_pulse((unsigned int)(0x40000000 / (*(_DWORD *)(msm5205_intf + 4) / v3)), a1, MSM5205_vclk_callback);
*((_QWORD *)v5 + 1) = result;
}
}
return result;
}

original_code:
static void MSM5205_set_timer(int num,int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 static int prescaler_table[4] = {96,48,64,0};
 int prescaler = prescaler_table[select&0x03];
 if( voice->prescaler != prescaler )
 {
  if(voice->timer)
  {
   timer_remove(voice->timer);
   voice->timer = 0;
  }
  voice->prescaler = prescaler;
  if( prescaler )
  {
   voice->timer =
    timer_pulse (((1<<30) / ((timer_tm)(msm5205_intf->baseclock / prescaler))), num, MSM5205_vclk_callback);
  }
 }
}

canonical_original_code:
static void MSM5205_set_timer(int num, int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 static int prescaler_table[4] = {96,48,64,0};
 int prescaler = prescaler_table[select&0x03];
 if( voice->prescaler != prescaler )
 {
  if(voice->timer)
  {
   timer_remove(voice->timer);
   voice->timer = 0;
  }
  voice->prescaler = prescaler;
  if( prescaler )
  {
   voice->timer =
    timer_pulse (((1<<30) / ((timer_tm)(msm5205_intf->baseclock / prescaler))), num, MSM5205_vclk_callback);
  }
 }
}

variable_types: num int

variable_types: select int

variable_types: prescaler int

user_defined_types: struct MSM5205Voice { int stream; void *timer; int data; int vclk; int reset; int prescaler; int bitwidth; int signal; int step; }


decompiled_code:
void MSM5205_sh_update()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void MSM5205_sh_update (void)
{
}

canonical_original_code:
void MSM5205_sh_update()
{
}


decompiled_code:
signed int *MSM5205_sh_reset()
{
signed int *result; // rax
signed int v1; // ebp
_DWORD *v2; // rbx
__int64 v3; // r12
signed int v4; // esi

result = (signed int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = (signed int *)msm5205_intf;
if ( *(int *)msm5205_intf > 0 )
{
v1 = 0;
v2 = msm5205;
do
{
v2[4] = 0;
v3 = v1 + 8LL;
v2[5] = 0;
v4 = result[v3 + 2];
v2[6] = 0;
v2[9] = 0;
v2[10] = 0;
MSM5205_set_timer(v1, v4 & 3);
result = (signed int *)msm5205_intf;
++v1;
v2 += 12;
*(v2 - 4) = ((*(_BYTE *)(msm5205_intf + 4 * v3 + 8) & 4) != 0) + 3;
}
while ( *result > v1 );
}
}
return result;
}

canonical_decompiled_code:
signed int *func5()
{
signed int *result; // rax
signed int v1; // ebp
_DWORD *v2; // rbx
__int64 v3; // r12
signed int v4; // esi

result = (signed int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = (signed int *)msm5205_intf;
if ( *(int *)msm5205_intf > 0 )
{
v1 = 0;
v2 = msm5205;
do
{
v2[4] = 0;
v3 = v1 + 8LL;
v2[5] = 0;
v4 = result[v3 + 2];
v2[6] = 0;
v2[9] = 0;
v2[10] = 0;
func2(v1, v4 & 3);
result = (signed int *)msm5205_intf;
++v1;
v2 += 12;
*(v2 - 4) = ((*(_BYTE *)(msm5205_intf + 4 * v3 + 8) & 4) != 0) + 3;
}
while ( *result > v1 );
}
}
return result;
}

original_code:
void MSM5205_sh_reset(void)
{
 int i;
 if (Machine->sample_rate == 0)
  return;
 for (i = 0; i < msm5205_intf->num; i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  voice->data = 0;
  voice->vclk = 0;
  voice->reset = 0;
  voice->signal = 0;
  voice->step = 0;
  MSM5205_set_timer(i,msm5205_intf->select[i] & 0x03);
  msm5205[i].bitwidth = msm5205_intf->select[i]&0x04 ? 4 : 3;
 }
}

canonical_original_code:
void MSM5205_sh_reset()
{
 int i;
 if (Machine->sample_rate == 0)
  return;
 for (i = 0; i < msm5205_intf->num; i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  voice->data = 0;
  voice->vclk = 0;
  voice->reset = 0;
  voice->signal = 0;
  voice->step = 0;
  MSM5205_set_timer(i,msm5205_intf->select[i] & 0x03);
  msm5205[i].bitwidth = msm5205_intf->select[i]&0x04 ? 4 : 3;
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall MSM5205_sh_start(__int64 a1)
{
_DWORD *v1; // rbp
int *v2; // rbx
unsigned int v3; // ebx
__int64 v4; // rsi
__int64 v5; // rcx
char v7[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = msm5205;
msm5205_intf = *(_QWORD *)(a1 + 8);
v2 = (int *)msm5205_intf;
ComputeTables();
memset(msm5205, 0, sizeof(msm5205));
if ( *v2 > 0 )
{
v3 = 0;
do
{
sprintf(v7, "MSM5205 #%d", v3);
v1 += 12;
v4 = *(unsigned int *)(msm5205_intf + 4LL * (int)v3 + 56);
v5 = v3++;
*(v1 - 12) = stream_init(v7, v4, *(unsigned int *)(Machine + 836LL), v5, MSM5205_update);
}
while ( *(_DWORD *)msm5205_intf > (signed int)v3 );
}
MSM5205_sh_reset();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_DWORD *v1; // rbp
int *v2; // rbx
unsigned int v3; // ebx
__int64 v4; // rsi
__int64 v5; // rcx
char v7[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = msm5205;
msm5205_intf = *(_QWORD *)(a1 + 8);
v2 = (int *)msm5205_intf;
func1();
memset(msm5205, 0, sizeof(msm5205));
if ( *v2 > 0 )
{
v3 = 0;
do
{
sprintf(v7, "MSM5205 #%d", v3);
v1 += 12;
v4 = *(unsigned int *)(msm5205_intf + 4LL * (int)v3 + 56);
v5 = v3++;
*(v1 - 12) = stream_init(v7, v4, *(unsigned int *)(Machine + 836LL), v5, MSM5205_update);
}
while ( *(_DWORD *)msm5205_intf > (signed int)v3 );
}
func5();
return 0LL;
}

original_code:
int MSM5205_sh_start (const struct MachineSound *msound)
{
 int i;
 msm5205_intf = (const struct MSM5205interface*)msound->sound_interface;
 ComputeTables ();
 memset (msm5205, 0, sizeof (msm5205));
 for (i = 0;i < msm5205_intf->num;i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  char name[20];
  sprintf(name,"MSM5205 #%d",i);
  voice->stream = stream_init(name,msm5205_intf->mixing_level[i],
                                Machine->sample_rate,i,
                          MSM5205_update);
 }
 MSM5205_sh_reset();
 return 0;
}

canonical_original_code:
int MSM5205_sh_start(struct MachineSound *msound)
{
 int i;
 msm5205_intf = (struct MSM5205interface *)msound->sound_interface;
 ComputeTables ();
 memset (msm5205, 0, sizeof (msm5205));
 for (i = 0;i < msm5205_intf->num;i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  char name[20];
  sprintf(name,"MSM5205 #%d",i);
  voice->stream = stream_init(name,msm5205_intf->mixing_level[i],
                                Machine->sample_rate,i,
                          MSM5205_update);
 }
 MSM5205_sh_reset();
 return 0;
}

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

variable_types:
name
char [20]

user_defined_types: struct MSM5205interface { int num; int baseclock; void (*vclk_interrupt[4])(int); int select[4]; int mixing_level[4]; }


decompiled_code:
__int64 __fastcall MSM5205_reset_w(int a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(unsigned int *)msm5205_intf;
if ( (int)v2 <= a1 )
return logerror(
"error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n",
(unsigned int)a1,
v2);
result = 12LL * a1;
msm5205[result + 6] = a2;
return result * 4;
}

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

v2 = *(unsigned int *)msm5205_intf;
if ( (int)v2 <= a1 )
return logerror(
"error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n",
(unsigned int)a1,
v2);
result = 12LL * a1;
msm5205[result + 6] = a2;
return result * 4;
}

original_code:
void MSM5205_reset_w (int num, int reset)
{
 if (num >= msm5205_intf->num)
 {
  logerror("error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n", num, msm5205_intf->num);
  return;
 }
 msm5205[num].reset = reset;
}

canonical_original_code:
void MSM5205_reset_w(int num, int reset)
{
 if (num >= msm5205_intf->num)
 {
  logerror("error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n", num, msm5205_intf->num);
  return;
 }
 msm5205[num].reset = reset;
}

variable_types: reset int


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

result = (2 * a2) & 0xE;
if ( msm5205[12 * a1 + 8] == 4 )
result = a2 & 0xF;
msm5205[12 * a1 + 4] = result;
return result;
}

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

result = (2 * a2) & 0xE;
if ( msm5205[12 * a1 + 8] == 4 )
result = a2 & 0xF;
msm5205[12 * a1 + 4] = result;
return result;
}

original_code:
void MSM5205_data_w (int num, int data)
{
 if( msm5205[num].bitwidth == 4)
  msm5205[num].data = data & 0x0f;
 else
  msm5205[num].data = (data & 0x07)<<1;
}

canonical_original_code:
void MSM5205_data_w(int num, int data)
{
 if( msm5205[num].bitwidth == 4)
  msm5205[num].data = data & 0x0f;
 else
  msm5205[num].data = (data & 0x07)<<1;
}

variable_types: data int


decompiled_code:
__int64 __fastcall MSM5205_selector_w(unsigned int a1, char a2)
{
stream_update((unsigned int)msm5205[12 * a1], 0LL);
return MSM5205_set_timer(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, char a2)
{
stream_update((unsigned int)msm5205[12 * a1], 0LL);
return func2(a1, a2);
}

original_code:
void MSM5205_selector_w (int num, int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 stream_update(voice->stream,0);
 MSM5205_set_timer(num,select);
}

canonical_original_code:
void MSM5205_selector_w(int num, int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 stream_update(voice->stream,0);
 MSM5205_set_timer(num,select);
}


decompiled_code:
__int64 __fastcall MSM5205_bitwidth_w(int a1, int a2)
{
int v2; // ebp
__int64 result; // rax
unsigned int *v4; // rbx

v2 = 3 - ((a2 == 0) - 1);
result = 48LL * a1;
v4 = (_DWORD *)((char *)msm5205 + result);
if ( *(_DWORD *)((char *)&msm5205[8] + result) != v2 )
{
result = stream_update(*v4, 0LL);
v4[8] = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v2; // ebp
__int64 result; // rax
unsigned int *v4; // rbx

v2 = 3 - ((a2 == 0) - 1);
result = 48LL * a1;
v4 = (_DWORD *)((char *)msm5205 + result);
if ( *(_DWORD *)((char *)&msm5205[8] + result) != v2 )
{
result = stream_update(*v4, 0LL);
v4[8] = v2;
}
return result;
}

original_code:
void MSM5205_bitwidth_w (int num, int bitsel)
{
 int bitwidth = bitsel ? 4 : 3;
 if( msm5205[num].bitwidth != bitwidth )
 {
  stream_update(msm5205[num].stream,0);
  msm5205[num].bitwidth = bitwidth;
 }
}

canonical_original_code:
void MSM5205_bitwidth_w(int num, int bitsel)
{
 int bitwidth = bitsel ? 4 : 3;
 if( msm5205[num].bitwidth != bitwidth )
 {
  stream_update(msm5205[num].stream,0);
  msm5205[num].bitwidth = bitwidth;
 }
}

variable_types: bitsel int

variable_types: bitwidth int


decompiled_code:
__int64 __fastcall MSM5205_set_volume(int a1)
{
return mixer_set_volume((unsigned int)msm5205[12 * a1]);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return mixer_set_volume((unsigned int)msm5205[12 * a1]);
}

original_code:
void MSM5205_set_volume(int num,int volume)
{
 struct MSM5205Voice *voice = &msm5205[num];
 mixer_set_volume(voice->stream,volume);
}

canonical_original_code:
void MSM5205_set_volume(int num, int volume)
{
 struct MSM5205Voice *voice = &msm5205[num];
 mixer_set_volume(voice->stream,volume);
}

variable_types: volume int