decompiled_code:
__int64 bsktball_interrupt()
{
char v0; // al
__int64 result; // rax

v0 = i256V_8 + 1;
i256V_8 = (i256V_8 + 1) % 8;
if ( (v0 & 7) == 0 )
return interrupt();
result = 0LL;
if ( NMION )
result = nmi_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func4()
{
char v0; // al
__int64 result; // rax

v0 = i256V_8 + 1;
i256V_8 = (i256V_8 + 1) % 8;
if ( (v0 & 7) == 0 )
return interrupt();
result = 0LL;
if ( NMION )
result = nmi_interrupt();
return result;
}

original_code:
int bsktball_interrupt(void)
{
 static int i256V=0;
 i256V=(i256V+1) % 8;
 if (i256V==0)
  return interrupt();
 else if (NMION)
  return nmi_interrupt();
 else
  return 0;
}

canonical_original_code:
int bsktball_interrupt()
{
 static int i256V = 0;
 i256V=(i256V+1) % 8;
 if (i256V==0)
  return interrupt();
 else if (NMION)
  return nmi_interrupt();
 else
  return 0;
}


decompiled_code:
__int64 __fastcall bsktball_in0_r(unsigned int a1)
{
int v1; // ebp
int v2; // er12
int v3; // ebx
int v4; // eax
char v6; // al

v1 = input_port_0_r();
v2 = input_port_1_r(a1);
v3 = input_port_2_r(a1);
v4 = input_port_3_r(a1);
if ( last_p1_horiz_7 >= v1 )
{
if ( last_p1_horiz_7 > v1 )
DR2_6 = (last_p1_horiz_7 - v1 < 129) << 6;
}
else
{
DR2_6 = (v1 - last_p1_horiz_7 > 128) << 6;
}
if ( last_p1_vert_5 >= v2 )
{
if ( last_p1_vert_5 > v2 )
DR3_4 = (last_p1_vert_5 - v2 > 128) << 7;
}
else
{
DR3_4 = (v2 - last_p1_vert_5 < 129) << 7;
}
if ( last_p2_horiz_3 >= v3 )
{
if ( last_p2_horiz_3 > v3 )
DR0_2 = 16 * (last_p2_horiz_3 - v3 < 129);
}
else
{
DR0_2 = 16 * (v3 - last_p2_horiz_3 > 128);
}
if ( last_p2_vert_1 >= v4 )
{
if ( last_p2_vert_1 > v4 )
DR1_0 = 32 * (last_p2_vert_1 - v4 > 128);
}
else
{
DR1_0 = 32 * (v4 - last_p2_vert_1 < 129);
}
last_p1_horiz_7 = v1;
last_p1_vert_5 = v2;
last_p2_horiz_3 = v3;
last_p2_vert_1 = v4;
if ( (LD1 & LD2) != 0 )
return v1 & 0xF | (unsigned int)(unsigned __int8)(16 * v2);
if ( LD2 )
return v3 & 0xF | (unsigned int)(unsigned __int8)(16 * v4);
v6 = input_port_4_r(a1);
return ((v6 & 0xF) >> 2) & v6 & 0xF | DR3_4 | DR2_6 | DR1_0 | (unsigned int)DR0_2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v1; // ebp
int v2; // er12
int v3; // ebx
int v4; // eax
char v6; // al

v1 = input_port_0_r();
v2 = input_port_1_r(a1);
v3 = input_port_2_r(a1);
v4 = input_port_3_r(a1);
if ( last_p1_horiz_7 >= v1 )
{
if ( last_p1_horiz_7 > v1 )
DR2_6 = (last_p1_horiz_7 - v1 < 129) << 6;
}
else
{
DR2_6 = (v1 - last_p1_horiz_7 > 128) << 6;
}
if ( last_p1_vert_5 >= v2 )
{
if ( last_p1_vert_5 > v2 )
DR3_4 = (last_p1_vert_5 - v2 > 128) << 7;
}
else
{
DR3_4 = (v2 - last_p1_vert_5 < 129) << 7;
}
if ( last_p2_horiz_3 >= v3 )
{
if ( last_p2_horiz_3 > v3 )
DR0_2 = 16 * (last_p2_horiz_3 - v3 < 129);
}
else
{
DR0_2 = 16 * (v3 - last_p2_horiz_3 > 128);
}
if ( last_p2_vert_1 >= v4 )
{
if ( last_p2_vert_1 > v4 )
DR1_0 = 32 * (last_p2_vert_1 - v4 > 128);
}
else
{
DR1_0 = 32 * (v4 - last_p2_vert_1 < 129);
}
last_p1_horiz_7 = v1;
last_p1_vert_5 = v2;
last_p2_horiz_3 = v3;
last_p2_vert_1 = v4;
if ( (LD1 & LD2) != 0 )
return v1 & 0xF | (unsigned int)(unsigned __int8)(16 * v2);
if ( LD2 )
return v3 & 0xF | (unsigned int)(unsigned __int8)(16 * v4);
v6 = input_port_4_r(a1);
return ((v6 & 0xF) >> 2) & v6 & 0xF | DR3_4 | DR2_6 | DR1_0 | (unsigned int)DR0_2;
}

original_code:
data_t bsktball_in0_r(offs_t offset)
{
 static int DR0=0;
 static int DR1=0;
 static int DR2=0;
 static int DR3=0;
 static int last_p1_horiz=0;
 static int last_p1_vert=0;
 static int last_p2_horiz=0;
 static int last_p2_vert=0;
 int p1_horiz;
 int p1_vert;
 int p2_horiz;
 int p2_vert;
 int temp;
 p1_horiz = input_port_0_r(offset);
 p1_vert = input_port_1_r(offset);
 p2_horiz = input_port_2_r(offset);
 p2_vert = input_port_3_r(offset);
 if (p1_horiz > last_p1_horiz)
 {
  if ((p1_horiz-last_p1_horiz) > 128) DR2=0x40;
  else DR2=0;
 }
 else if (p1_horiz < last_p1_horiz)
 {
  if ((last_p1_horiz-p1_horiz) > 128) DR2=0;
  else DR2=0x40;
 }
 if (p1_vert > last_p1_vert)
 {
  if ((p1_vert-last_p1_vert) > 128) DR3=0;
  else DR3=0x80;
 }
 else if (p1_vert < last_p1_vert)
 {
  if ((last_p1_vert-p1_vert) > 128) DR3=0x80;
  else DR3=0;
 }
 if (p2_horiz > last_p2_horiz)
 {
  if ((p2_horiz-last_p2_horiz) > 128) DR0=0x10;
  else DR0=0;
 }
 else if (p2_horiz < last_p2_horiz)
 {
  if ((last_p2_horiz-p2_horiz) > 128) DR0=0;
  else DR0=0x10;
 }
 if (p2_vert > last_p2_vert)
 {
  if ((p2_vert-last_p2_vert) > 128) DR1=0;
  else DR1=0x20;
 }
 else if (p2_vert < last_p2_vert)
 {
  if ((last_p2_vert-p2_vert) > 128) DR1=0x20;
  else DR1=0;
 }
 last_p1_horiz = p1_horiz;
 last_p1_vert = p1_vert;
 last_p2_horiz = p2_horiz;
 last_p2_vert = p2_vert;
 if ((LD1) & (LD2))
 {
  return ((p1_horiz & 0x0F) | ((p1_vert << 4) & 0xF0));
 }
 else if (LD2)
 {
  return ((p2_horiz & 0x0F) | ((p2_vert << 4) & 0xF0));
 }
 else
 {
  temp = input_port_4_r(offset) & 0x0F;
  temp = (temp) & (temp>>2);
  return (temp | DR0 | DR1 | DR2 | DR3);
 }
}

canonical_original_code:
unsigned int bsktball_in0_r(unsigned int offset)
{
 static int DR0 = 0;
 static int DR1 = 0;
 static int DR2 = 0;
 static int DR3 = 0;
 static int last_p1_horiz = 0;
 static int last_p1_vert = 0;
 static int last_p2_horiz = 0;
 static int last_p2_vert = 0;
 int p1_horiz;
 int p1_vert;
 int p2_horiz;
 int p2_vert;
 int temp;
 p1_horiz = input_port_0_r(offset);
 p1_vert = input_port_1_r(offset);
 p2_horiz = input_port_2_r(offset);
 p2_vert = input_port_3_r(offset);
 if (p1_horiz > last_p1_horiz)
 {
  if ((p1_horiz-last_p1_horiz) > 128) DR2=0x40;
  else DR2=0;
 }
 else if (p1_horiz < last_p1_horiz)
 {
  if ((last_p1_horiz-p1_horiz) > 128) DR2=0;
  else DR2=0x40;
 }
 if (p1_vert > last_p1_vert)
 {
  if ((p1_vert-last_p1_vert) > 128) DR3=0;
  else DR3=0x80;
 }
 else if (p1_vert < last_p1_vert)
 {
  if ((last_p1_vert-p1_vert) > 128) DR3=0x80;
  else DR3=0;
 }
 if (p2_horiz > last_p2_horiz)
 {
  if ((p2_horiz-last_p2_horiz) > 128) DR0=0x10;
  else DR0=0;
 }
 else if (p2_horiz < last_p2_horiz)
 {
  if ((last_p2_horiz-p2_horiz) > 128) DR0=0;
  else DR0=0x10;
 }
 if (p2_vert > last_p2_vert)
 {
  if ((p2_vert-last_p2_vert) > 128) DR1=0;
  else DR1=0x20;
 }
 else if (p2_vert < last_p2_vert)
 {
  if ((last_p2_vert-p2_vert) > 128) DR1=0x20;
  else DR1=0;
 }
 last_p1_horiz = p1_horiz;
 last_p1_vert = p1_vert;
 last_p2_horiz = p2_horiz;
 last_p2_vert = p2_vert;
 if ((LD1) & (LD2))
 {
  return ((p1_horiz & 0x0F) | ((p1_vert << 4) & 0xF0));
 }
 else if (LD2)
 {
  return ((p2_horiz & 0x0F) | ((p2_vert << 4) & 0xF0));
 }
 else
 {
  temp = input_port_4_r(offset) & 0x0F;
  temp = (temp) & (temp>>2);
  return (temp | DR0 | DR1 | DR2 | DR3);
 }
}

variable_types:
offset
unsigned int

variable_types: temp int

return_type: unsigned int


decompiled_code:
__int64 __fastcall bsktball_led1_w(char a1)
{
return osd_led_w(0LL, a1 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return osd_led_w(0LL, a1 & 1);
}

original_code:
void bsktball_led1_w(offs_t offset,data_t data)
{
        osd_led_w(0,(offset & 0x01));
}

canonical_original_code:
void bsktball_led1_w(unsigned int offset, unsigned int data)
{
        osd_led_w(0,(offset & 0x01));
}

variable_types:
data
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall bsktball_led2_w(char a1)
{
return osd_led_w(1LL, a1 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return osd_led_w(1LL, a1 & 1);
}

original_code:
void bsktball_led2_w(offs_t offset,data_t data)
{
        osd_led_w(1,(offset & 0x01));
}

canonical_original_code:
void bsktball_led2_w(unsigned int offset, unsigned int data)
{
        osd_led_w(1,(offset & 0x01));
}


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

note_timer = a2;
note_count = 256;
if ( init_timer )
{
if ( a2 != 255 )
{
result = timer_set(22724LL, 0LL, bsktball_note_32H);
init_timer = 0;
}
}
return result;
}

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

note_timer = a2;
note_count = 256;
if ( init_timer )
{
if ( a2 != 255 )
{
result = timer_set(22724LL, 0LL, bsktball_note_32H);
init_timer = 0;
}
}
return result;
}

original_code:
static void bsktball_note_w(offs_t offset,data_t data)
{
 note_timer=data;
 note_count=256;
 if ((init_timer) && (note_timer!=255))
 {
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_note_32H);
  init_timer=0;
 }
}

canonical_original_code:
static void bsktball_note_w(unsigned int offset, unsigned int data)
{
 note_timer=data;
 note_count=256;
 if ((init_timer) && (note_timer!=255))
 {
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_note_32H);
  init_timer=0;
 }
}


decompiled_code:
__int64 bsktball_note_32H()
{
int v0; // eax
__int64 result; // rax

v0 = note_count - 1;
if ( note_count - 1 == note_timer )
v0 = 256;
note_count = v0;
if ( note_timer + ((256 - note_timer) >> 1) >= v0 )
result = DAC_data_w(0LL, 0LL);
else
result = DAC_data_w(0LL, 255LL);
if ( note_timer != 255 )
return timer_set(22724LL, 0LL, bsktball_note_32H);
init_timer = 1;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
__int64 result; // rax

v0 = note_count - 1;
if ( note_count - 1 == note_timer )
v0 = 256;
note_count = v0;
if ( note_timer + ((256 - note_timer) >> 1) >= v0 )
result = DAC_data_w(0LL, 0LL);
else
result = DAC_data_w(0LL, 255LL);
if ( note_timer != 255 )
return timer_set(22724LL, 0LL, bsktball_note_32H);
init_timer = 1;
return result;
}

original_code:
static void bsktball_note_32H(int foo)
{
 note_count--;
 if (note_count==note_timer)
  note_count=256;
 if (note_count > ((256-note_timer)>>1)+note_timer)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if (note_timer!=255)
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_note_32H);
 else
  init_timer=1;
}

canonical_original_code:
static void bsktball_note_32H(int foo)
{
 note_count--;
 if (note_count==note_timer)
  note_count=256;
 if (note_count > ((256-note_timer)>>1)+note_timer)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if (note_timer!=255)
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_note_32H);
 else
  init_timer=1;
}

variable_types: foo int


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

noise_a10 = 0;
noise_b10 = 0;
result = DAC_data_w(2LL, 0LL);
if ( !noise_timer_set )
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

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

noise_a10 = 0;
noise_b10 = 0;
result = DAC_data_w(2LL, 0LL);
if ( !noise_timer_set )
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

original_code:
static void bsktball_noise_reset_w(offs_t offset,data_t data)
{
 noise_a10=0;
 noise_b10=0;
 DAC_data_w(2,0);
 if (!noise_timer_set)
  timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}

canonical_original_code:
static void bsktball_noise_reset_w(unsigned int offset, unsigned int data)
{
 noise_a10=0;
 noise_b10=0;
 DAC_data_w(2,0);
 if (!noise_timer_set)
  timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}


decompiled_code:
__int64 bsktball_noise_256H()
{
int v0; // eax
__int64 result; // rax

v0 = noise_b10;
noise_b10 = (unsigned __int8)((2 * noise_b10) | (noise_b10 ^ (~noise_a10 >> 6)) & 1);
noise_a10 = (unsigned __int8)((2 * noise_a10) | (v0 >> 7) & 1);
noise = noise_a10 >> 7;
if ( noise_a10 >> 7 )
DAC_data_w(2LL, (unsigned int)crowd_mask);
else
DAC_data_w(2LL, 0LL);
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // eax
__int64 result; // rax

v0 = noise_b10;
noise_b10 = (unsigned __int8)((2 * noise_b10) | (noise_b10 ^ (~noise_a10 >> 6)) & 1);
noise_a10 = (unsigned __int8)((2 * noise_a10) | (v0 >> 7) & 1);
noise = noise_a10 >> 7;
if ( noise_a10 >> 7 )
DAC_data_w(2LL, (unsigned int)crowd_mask);
else
DAC_data_w(2LL, 0LL);
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

original_code:
static void bsktball_noise_256H(int foo)
{
 int b10_input;
 int a10_input;
 b10_input = (noise_b10 & 0x01) ^ (((~noise_a10) & 0x40) >> 6);
 a10_input = (noise_b10 & 0x80) >> 7;
 noise_b10 = ((noise_b10 << 1) | b10_input) & 0xFF;
 noise_a10 = ((noise_a10 << 1) | a10_input) & 0xFF;
 noise = (noise_a10 & 0x80) >> 7;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}

canonical_original_code:
static void bsktball_noise_256H(int foo)
{
 int b10_input;
 int a10_input;
 b10_input = (noise_b10 & 0x01) ^ (((~noise_a10) & 0x40) >> 6);
 a10_input = (noise_b10 & 0x80) >> 7;
 noise_b10 = ((noise_b10 << 1) | b10_input) & 0xFF;
 noise_a10 = ((noise_a10 << 1) | a10_input) & 0xFF;
 noise = (noise_a10 & 0x80) >> 7;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}


decompiled_code:
__int64 __fastcall bsktball_bounce_w(__int64 a1, char a2)
{
__int64 v3; // rsi
__int64 result; // rax

v3 = (unsigned __int8)(16 * a2);
crowd_mask = v3;
if ( noise )
DAC_data_w(2LL, v3);
else
DAC_data_w(2LL, 0LL);
if ( (a2 & 0x10) != 0 )
result = DAC_data_w(1LL, 255LL);
else
result = DAC_data_w(1LL, 0LL);
return result;
}

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

v3 = (unsigned __int8)(16 * a2);
crowd_mask = v3;
if ( noise )
DAC_data_w(2LL, v3);
else
DAC_data_w(2LL, 0LL);
if ( (a2 & 0x10) != 0 )
result = DAC_data_w(1LL, 255LL);
else
result = DAC_data_w(1LL, 0LL);
return result;
}

original_code:
static void bsktball_bounce_w(offs_t offset,data_t data)
{
 crowd_mask = (data & 0x0F) << 4;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 if (data & 0x10)
  DAC_data_w(1,255);
 else
  DAC_data_w(1,0);
}

canonical_original_code:
static void bsktball_bounce_w(unsigned int offset, unsigned int data)
{
 crowd_mask = (data & 0x0F) << 4;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 if (data & 0x10)
  DAC_data_w(1,255);
 else
  DAC_data_w(1,0);
}


decompiled_code:
__int64 __fastcall init_palette(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

*(_QWORD *)a1 = 0x5050808080000000LL;
*(_DWORD *)(a1 + 8) = -176;
*a2 = colortable;
result = qword_8C8;
a2[65] = qword_8C8;
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&colortable - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 528) >> 3));
return result;
}

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

*(_QWORD *)a1 = 0x5050808080000000LL;
*(_DWORD *)(a1 + 8) = -176;
*a2 = colortable;
result = qword_8C8;
a2[65] = qword_8C8;
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&colortable - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 528) >> 3));
return result;
}

original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}


casencmp

decompiled_code:
__int64 __fastcall casencmp(__int64 a1, __int64 a2, __int64 a3)
{
const __int32_t *v5; // rcx
__int64 v6; // rax
__int32_t v7; // edx
__int32_t v8; // esi

if ( !a3 )
return 0LL;
v5 = *_ctype_tolower_loc();
v6 = 0LL;
while ( 1 )
{
v7 = v5[*(char *)(a1 + v6)];
v8 = v5[*(char *)(a2 + v6)];
if ( v8 != v7 )
break;
if ( ++v6 == a3 )
return 0LL;
}
return (unsigned int)(v7 - v8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
const __int32_t *v5; // rcx
__int64 v6; // rax
__int32_t v7; // edx
__int32_t v8; // esi

if ( !a3 )
return 0LL;
v5 = *_ctype_tolower_loc();
v6 = 0LL;
while ( 1 )
{
v7 = v5[*(char *)(a1 + v6)];
v8 = v5[*(char *)(a2 + v6)];
if ( v8 != v7 )
break;
if ( ++v6 == a3 )
return 0LL;
}
return (unsigned int)(v7 - v8);
}

original_code:
static int casencmp(const char *a, const char *b, size_t n)
{
   size_t i;
   for (i = 0; i < n; i++)
   {
      int a_lower = tolower(a[i]);
      int b_lower = tolower(b[i]);
      if (a_lower != b_lower)
         return a_lower - b_lower;
   }
   return 0;
}

canonical_original_code:
static int casencmp(char *a, char *b, unsigned long n)
{
   unsigned long i;
   for (i = 0; i < n; i++)
   {
      int a_lower = tolower(a[i]);
      int b_lower = tolower(b[i]);
      if (a_lower != b_lower)
         return a_lower - b_lower;
   }
   return 0;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

return_type: int


decompiled_code:
const char *__fastcall strcasestr_retro__(const char *a1, const char *a2)
{
size_t v2; // r12
size_t v3; // rax
__int64 v4; // r13
size_t v5; // r12
__int64 v6; // rbx
const char *v7; // rbp

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 < v3 )
return 0LL;
v4 = v3;
v5 = v2 - v3;
v6 = 0LL;
while ( 1 )
{
v7 = &a1[v6];
if ( !(unsigned int)casencmp((__int64)&a1[v6], (__int64)a2, v4) )
break;
if ( v5 < ++v6 )
return 0LL;
}
return v7;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1, const char *a2)
{
size_t v2; // r12
size_t v3; // rax
__int64 v4; // r13
size_t v5; // r12
__int64 v6; // rbx
const char *v7; // rbp

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 < v3 )
return 0LL;
v4 = v3;
v5 = v2 - v3;
v6 = 0LL;
while ( 1 )
{
v7 = &a1[v6];
if ( !(unsigned int)func0((__int64)&a1[v6], (__int64)a2, v4) )
break;
if ( v5 < ++v6 )
return 0LL;
}
return v7;
}

original_code:
char *strcasestr_retro__(const char *haystack, const char *needle)
{
   size_t i, search_off;
   size_t hay_len = strlen(haystack);
   size_t needle_len = strlen(needle);
   if (needle_len > hay_len)
      return ((void *)0);
   search_off = hay_len - needle_len;
   for (i = 0; i <= search_off; i++)
      if (!casencmp(haystack + i, needle, needle_len))
         return (char*)haystack + i;
   return ((void *)0);
}

canonical_original_code:
char *strcasestr_retro__(char *haystack, char *needle)
{
   unsigned long i; unsigned long search_off;
   unsigned long hay_len = strlen(haystack);
   unsigned long needle_len = strlen(needle);
   if (needle_len > hay_len)
      return ((void *)0);
   search_off = hay_len - needle_len;
   for (i = 0; i <= search_off; i++)
      if (!casencmp(haystack + i, needle, needle_len))
         return (char *)haystack + i;
   return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
needle
char *

return_type: char *


decompiled_code:
__int64 __fastcall carnival_sh_port1_w(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port1State_1 ^ (unsigned int)a2;
v3 = a2 & (port1State_1 ^ a2);
v4 = (port1State_1 ^ a2) & ~(_BYTE)a2;
port1State_1 = a2;
if ( (v4 & 1) != 0 )
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 2) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_stop(3LL);
if ( (v4 & 4) != 0 )
result = sample_start(4LL, 4LL, 1LL);
if ( (v3 & 4) != 0 )
result = sample_stop(4LL);
if ( (v4 & 8) != 0 )
result = sample_start(5LL, 5LL, 1LL);
if ( (v3 & 8) != 0 )
result = sample_stop(5LL);
if ( (v4 & 0x10) != 0 )
result = sample_start(6LL, 6LL, 1LL);
if ( (v3 & 0x10) != 0 )
result = sample_stop(6LL);
if ( (v4 & 0x20) != 0 )
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 0x40) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( v4 < 0 )
result = sample_start(2LL, 2LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port1State_1 ^ (unsigned int)a2;
v3 = a2 & (port1State_1 ^ a2);
v4 = (port1State_1 ^ a2) & ~(_BYTE)a2;
port1State_1 = a2;
if ( (v4 & 1) != 0 )
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 2) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_stop(3LL);
if ( (v4 & 4) != 0 )
result = sample_start(4LL, 4LL, 1LL);
if ( (v3 & 4) != 0 )
result = sample_stop(4LL);
if ( (v4 & 8) != 0 )
result = sample_start(5LL, 5LL, 1LL);
if ( (v3 & 8) != 0 )
result = sample_stop(5LL);
if ( (v4 & 0x10) != 0 )
result = sample_start(6LL, 6LL, 1LL);
if ( (v3 & 0x10) != 0 )
result = sample_stop(6LL);
if ( (v4 & 0x20) != 0 )
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 0x40) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( v4 < 0 )
result = sample_start(2LL, 2LL, 0LL);
return result;
}

original_code:
void carnival_sh_port1_w(offs_t offset,data_t data)
{
 static int port1State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_RIFLE_SHOT, SND_RIFLE_SHOT, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_DUCK_1, SND_DUCK_1, 1 );
 }
 if ( bitsGoneHigh & 0x04 )
 {
  sample_stop( SND_DUCK_1 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_DUCK_2, SND_DUCK_2, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_DUCK_2 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_DUCK_3, SND_DUCK_3, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_DUCK_3 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PIPE_HIT, SND_PIPE_HIT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS_1, SND_BONUS_1, 0 );
 }
 if ( bitsGoneLow & 0x80 )
 {
  sample_start( SND_BONUS_2, SND_BONUS_2, 0 );
 }
}

canonical_original_code:
void carnival_sh_port1_w(unsigned int offset, unsigned int data)
{
 static int port1State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_RIFLE_SHOT, SND_RIFLE_SHOT, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_DUCK_1, SND_DUCK_1, 1 );
 }
 if ( bitsGoneHigh & 0x04 )
 {
  sample_stop( SND_DUCK_1 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_DUCK_2, SND_DUCK_2, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_DUCK_2 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_DUCK_3, SND_DUCK_3, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_DUCK_3 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PIPE_HIT, SND_PIPE_HIT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS_1, SND_BONUS_1, 0 );
 }
 if ( bitsGoneLow & 0x80 )
 {
  sample_start( SND_BONUS_2, SND_BONUS_2, 0 );
 }
}

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int


decompiled_code:
__int64 __fastcall carnival_sh_port2_w(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port2State ^ (unsigned int)a2;
v3 = a2 & (port2State ^ a2);
v4 = (port2State ^ a2) & ~(_BYTE)a2;
port2State = a2;
if ( (v4 & 4) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v4 & 0x20) != 0 )
result = sample_start(8LL, 8LL, 0LL);
if ( (v3 & 0x10) != 0 )
result = cpu_set_reset_line(1LL, 3LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port2State ^ (unsigned int)a2;
v3 = a2 & (port2State ^ a2);
v4 = (port2State ^ a2) & ~(_BYTE)a2;
port2State = a2;
if ( (v4 & 4) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v4 & 0x20) != 0 )
result = sample_start(8LL, 8LL, 0LL);
if ( (v3 & 0x10) != 0 )
result = cpu_set_reset_line(1LL, 3LL);
return result;
}

original_code:
void carnival_sh_port2_w(offs_t offset,data_t data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BEAR, SND_BEAR, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_RANKING, SND_RANKING, 0 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  cpu_set_reset_line( 1, 3 );
 }
}

canonical_original_code:
void carnival_sh_port2_w(unsigned int offset, unsigned int data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BEAR, SND_BEAR, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_RANKING, SND_RANKING, 0 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  cpu_set_reset_line( 1, 3 );
 }
}


decompiled_code:
_BOOL8 carnival_music_port_t1_r()
{
return (port2State & 8) == 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return (port2State & 8) == 0;
}

original_code:
data_t carnival_music_port_t1_r(offs_t offset)
{
 return ( port2State & 0x08 ) ? 0 : 1;
}

canonical_original_code:
unsigned int carnival_music_port_t1_r(unsigned int offset)
{
 return ( port2State & 0x08 ) ? 0 : 1;
}


decompiled_code:
void __fastcall carnival_music_port_1_w(__int64 a1, int a2)
{
psgData = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
psgData = a2;
}

original_code:
void carnival_music_port_1_w(offs_t offset,data_t data)
{
 psgData = data;
}

canonical_original_code:
void carnival_music_port_1_w(unsigned int offset, unsigned int data)
{
 psgData = data;
}


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

v2 = a2 & 0xC0;
if ( psgSelect_0 != v2 )
{
psgSelect_0 = v2;
if ( v2 == 64 )
{
result = AY8910_write_port_0_w(0LL, (unsigned int)psgData);
}
else if ( v2 == 192 )
{
result = AY8910_control_port_0_w(0LL, (unsigned int)psgData);
}
}
return result;
}

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

v2 = a2 & 0xC0;
if ( psgSelect_0 != v2 )
{
psgSelect_0 = v2;
if ( v2 == 64 )
{
result = AY8910_write_port_0_w(0LL, (unsigned int)psgData);
}
else if ( v2 == 192 )
{
result = AY8910_control_port_0_w(0LL, (unsigned int)psgData);
}
}
return result;
}

original_code:
void carnival_music_port_2_w(offs_t offset,data_t data)
{
 static int psgSelect = 0;
 int newSelect;
 newSelect = data & ( 0x40 | 0x80 );
 if ( psgSelect != newSelect )
 {
  psgSelect = newSelect;
  switch ( psgSelect )
  {
  case 0:
   break;
  case 0x80:
   break;
  case 0x40:
   AY8910_write_port_0_w( 0, psgData );
   break;
  case ( 0x40 | 0x80 ):
   AY8910_control_port_0_w( 0, psgData );
   break;
  }
 }
}

canonical_original_code:
void carnival_music_port_2_w(unsigned int offset, unsigned int data)
{
 static int psgSelect = 0;
 int newSelect;
 newSelect = data & ( 0x40 | 0x80 );
 if ( psgSelect != newSelect )
 {
  psgSelect = newSelect;
  switch ( psgSelect )
  {
  case 0:
   break;
  case 0x80:
   break;
  case 0x40:
   AY8910_write_port_0_w( 0, psgData );
   break;
  case ( 0x40 | 0x80 ):
   AY8910_control_port_0_w( 0, psgData );
   break;
  }
 }
}

variable_types: psgSelect int

variable_types: newSelect int


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

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

original_code:
data_t ajax_sharedram_r(offs_t offset)
{
 return ajax_sharedram[offset];
}

canonical_original_code:
unsigned int ajax_sharedram_r(unsigned int offset)
{
 return ajax_sharedram[offset];
}


decompiled_code:
void ajax_init_machine()
{
firq_enable = 1;
}

canonical_decompiled_code:
void func2()
{
firq_enable = 1;
}

original_code:
void ajax_init_machine( void )
{
 firq_enable = 1;
}


decompiled_code:
int __fastcall ajax_ls138_f10_r(unsigned int a1)
{
int v1; // eax
int result; // eax

v1 = (a1 >> 6) & 7;
if ( v1 == 6 )
{
if ( (a1 & 2) != 0 )
result = readinputport(a1 & 1);
else
result = readinputport((a1 & 1) + 3);
}
else if ( ((a1 >> 6) & 7) == 7 )
{
result = readinputport(2LL);
}
else if ( v1 )
{
if ( v1 == 4 )
result = readinputport(5LL);
else
result = 0;
}
else
{
result = rand();
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
int v1; // eax
int result; // eax

v1 = (a1 >> 6) & 7;
if ( v1 == 6 )
{
if ( (a1 & 2) != 0 )
result = readinputport(a1 & 1);
else
result = readinputport((a1 & 1) + 3);
}
else if ( ((a1 >> 6) & 7) == 7 )
{
result = readinputport(2LL);
}
else if ( v1 )
{
if ( v1 == 4 )
result = readinputport(5LL);
else
result = 0;
}
else
{
result = rand();
}
return result;
}

original_code:
data_t ajax_ls138_f10_r(offs_t offset)
{
 int data = 0;
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   data = rand();
   break;
  case 0x04:
   data = readinputport(5);
   break;
  case 0x06:
   if (offset & 0x02)
    data = readinputport(offset & 0x01);
   else
    data = readinputport(3 + (offset & 0x01));
   break;
  case 0x07:
   data = readinputport(2);
   break;
  default:
   break;
 }
 return data;
}

canonical_original_code:
unsigned int ajax_ls138_f10_r(unsigned int offset)
{
 int data = 0;
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   data = rand();
   break;
  case 0x04:
   data = readinputport(5);
   break;
  case 0x06:
   if (offset & 0x02)
    data = readinputport(offset & 0x01);
   else
    data = readinputport(3 + (offset & 0x01));
   break;
  case 0x07:
   data = readinputport(2);
   break;
  default:
   break;
 }
 return data;
}

variable_types: data int


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

result = (a1 >> 6) & 7;
switch ( (int)result )
{
case 0:
if ( a1 )
{
result = watchdog_reset_w(0LL);
}
else if ( firq_enable )
{
result = cpu_cause_interrupt(1LL, 2LL);
}
break;
case 1:
result = cpu_cause_interrupt(2LL, 4294966296LL);
break;
case 2:
result = soundlatch_w();
break;
case 3:
result = (__int64)ajax_bankswitch_w(0LL, a2);
break;
case 5:
result = ajax_lamps_w(0LL, a2);
break;
default:
return result;
}
return result;
}

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

result = (a1 >> 6) & 7;
switch ( (int)result )
{
case 0:
if ( a1 )
{
result = watchdog_reset_w(0LL);
}
else if ( firq_enable )
{
result = cpu_cause_interrupt(1LL, 2LL);
}
break;
case 1:
result = cpu_cause_interrupt(2LL, 4294966296LL);
break;
case 2:
result = soundlatch_w();
break;
case 3:
result = (__int64)func7(0LL, a2);
break;
case 5:
result = func8(0LL, a2);
break;
default:
return result;
}
return result;
}

original_code:
void ajax_ls138_f10_w(offs_t offset,data_t data)
{
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   if (offset)
    watchdog_reset_w(0, data);
   else{
    if (firq_enable)
     cpu_cause_interrupt(1,2);
   }
   break;
  case 0x01:
   cpu_cause_interrupt(2,-1000);
   break;
  case 0x02:
   soundlatch_w(offset,data);
   break;
  case 0x03:
   ajax_bankswitch_w(0, data);
   break;
  case 0x05:
   ajax_lamps_w(0, data);
   break;
  default:
   break;
 }
}

canonical_original_code:
void ajax_ls138_f10_w(unsigned int offset, unsigned int data)
{
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   if (offset)
    watchdog_reset_w(0, data);
   else{
    if (firq_enable)
     cpu_cause_interrupt(1,2);
   }
   break;
  case 0x01:
   cpu_cause_interrupt(2,-1000);
   break;
  case 0x02:
   soundlatch_w(offset,data);
   break;
  case 0x03:
   ajax_bankswitch_w(0, data);
   break;
  case 0x05:
   ajax_lamps_w(0, data);
   break;
  default:
   break;
 }
}


decompiled_code:
void *__fastcall ajax_bankswitch_2_w(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(130LL);
K052109_set_RMRD_line((a2 >> 6) & 1);
K051316_wraparound_enable(0LL, a2 & 0x20);
firq_enable = a2 & 0x10;
cpu_bankbase[1] = v2 + (int)(((a2 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

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

v2 = memory_region(130LL);
K052109_set_RMRD_line((a2 >> 6) & 1);
K051316_wraparound_enable(0LL, a2 & 0x20);
firq_enable = a2 & 0x10;
cpu_bankbase[1] = v2 + (int)(((a2 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
void ajax_bankswitch_2_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int bankaddress;
 K052109_set_RMRD_line((data & 0x40) ? 1 : 0);
 K051316_wraparound_enable(0, data & 0x20);
 firq_enable = data & 0x10;
 bankaddress = 0x10000 + (data & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void ajax_bankswitch_2_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int bankaddress;
 K052109_set_RMRD_line((data & 0x40) ? 1 : 0);
 K051316_wraparound_enable(0, data & 0x20);
 firq_enable = data & 0x10;
 bankaddress = 0x10000 + (data & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


decompiled_code:
__int64 ajax_interrupt()
{
int v0; // edx
__int64 result; // rax

v0 = K051960_is_IRQ_enabled();
result = 1LL;
if ( !v0 )
result = ignore_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // edx
__int64 result; // rax

v0 = K051960_is_IRQ_enabled();
result = 1LL;
if ( !v0 )
result = ignore_interrupt();
return result;
}

original_code:
int ajax_interrupt( void )
{
 if (K051960_is_IRQ_enabled())
  return 1;
 else
  return ignore_interrupt();
}

canonical_original_code:
int ajax_interrupt()
{
 if (K051960_is_IRQ_enabled())
  return 1;
 else
  return ignore_interrupt();
}


decompiled_code:
__int64 ajax_vh_start()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 64;
dword_6E4 = 0;
dword_6E8 = 32;
sprite_colorbase = 16;
zoom_colorbase = 6;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
if ( (unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
K052109_vh_stop();
result = 1LL;
}
else
{
result = K051316_vh_start_0(139LL, 7LL, zoom_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
K051960_vh_stop();
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 64;
dword_6E4 = 0;
dword_6E8 = 32;
sprite_colorbase = 16;
zoom_colorbase = 6;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
if ( (unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
K052109_vh_stop();
result = 1LL;
}
else
{
result = K051316_vh_start_0(139LL, 7LL, zoom_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
K051960_vh_stop();
result = 1LL;
}
}
}
return result;
}

original_code:
int ajax_vh_start( void )
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 32;
 sprite_colorbase = 16;
 zoom_colorbase = 6;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,7,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int ajax_vh_start()
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 32;
 sprite_colorbase = 16;
 zoom_colorbase = 6;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,7,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall ajax_vh_screenrefresh(__int64 a1)
{
int v1; // eax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = zoom_colorbase << 7;
*(_BYTE *)(palette_used_colors + (zoom_colorbase << 7)) = 7;
*(_BYTE *)(palette_used_colors + v1 + 128) = 7;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K052109_tilemap_draw(a1, 2LL, 0x10000LL);
if ( ajax_priority )
{
K051316_zoom_draw_0(a1, 4LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K051316_zoom_draw_0(a1, 4LL);
}
K052109_tilemap_draw(a1, 0LL, 0x80000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // eax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = zoom_colorbase << 7;
*(_BYTE *)(palette_used_colors + (zoom_colorbase << 7)) = 7;
*(_BYTE *)(palette_used_colors + v1 + 128) = 7;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K052109_tilemap_draw(a1, 2LL, 0x10000LL);
if ( ajax_priority )
{
K051316_zoom_draw_0(a1, 4LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K051316_zoom_draw_0(a1, 4LL);
}
K052109_tilemap_draw(a1, 0LL, 0x80000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

original_code:
void ajax_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[(zoom_colorbase + 0) * 128] = (4|(1|2));
 palette_used_colors[(zoom_colorbase + 1) * 128] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,2,1<<16);
 if (ajax_priority)
 {
  K051316_zoom_draw_0(bitmap,4);
  K052109_tilemap_draw(bitmap,1,2<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,1,2<<16);
  K051316_zoom_draw_0(bitmap,4);
 }
 K052109_tilemap_draw(bitmap,0,8<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

canonical_original_code:
void ajax_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[(zoom_colorbase + 0) * 128] = (4|(1|2));
 palette_used_colors[(zoom_colorbase + 1) * 128] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,2,1<<16);
 if (ajax_priority)
 {
  K051316_zoom_draw_0(bitmap,4);
  K052109_tilemap_draw(bitmap,1,2<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,1,2<<16);
  K051316_zoom_draw_0(bitmap,4);
 }
 K052109_tilemap_draw(bitmap,0,8<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

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

variable_types: fullrefresh int


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

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

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

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


original_code:
static void k007232_extvol_w(offs_t offset,data_t data)
{
 K007232_set_volume(1,0,(data & 0x0f) * 0x11/2,(data & 0x0f) * 0x11/2);
}

canonical_original_code:
static void k007232_extvol_w(unsigned int offset, unsigned int data)
{
 K007232_set_volume(1,0,(data & 0x0f) * 0x11/2,(data & 0x0f) * 0x11/2);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

*a3 |= (a2 << 12) | ((unsigned __int16)*a4 << 8) & 0xF00;
result = layer_colorbase[a1] + ((*a4 >> 4) & 0xFu);
*a4 = result;
return result;
}

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

*a3 |= (a2 << 12) | ((unsigned __int16)*a4 << 8) & 0xF00;
result = layer_colorbase[a1] + ((*a4 >> 4) & 0xFu);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x0f) << 8) | (bank << 12);
 *color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x0f) << 8) | (bank << 12);
 *color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = zoom_colorbase + ((*a2 >> 3) & 1u);
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = zoom_colorbase + ((*a2 >> 3) & 1u);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x08) >> 3);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x08) >> 3);
}


decompiled_code:
__int64 __fastcall volume_callback1(int a1)
{
return K007232_set_volume(
1LL,
1LL,
(unsigned int)((17 * (a1 & 0xF)) >> 1),
(unsigned int)((int)((a1 & 0xFFFFFFF0) + (a1 >> 4)) / 2));
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
return K007232_set_volume(
1LL,
1LL,
(unsigned int)((17 * (a1 & 0xF)) >> 1),
(unsigned int)((int)((a1 & 0xFFFFFFF0) + (a1 >> 4)) / 2));
}

original_code:
static void volume_callback1(int v)
{
 K007232_set_volume(1,1,(v & 0x0f) * 0x11/2,(v >> 4) * 0x11/2);
}

variable_types: v int


decompiled_code:
__int64 __fastcall volume_callback0(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}


original_code:
static void sound_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM;
 int bank_A, bank_B;
 RAM = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 1) & 0x01);
 bank_B = 0x20000 * ((data >> 0) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
 RAM = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(1,RAM + bank_A,RAM + bank_B);
}

canonical_original_code:
static void sound_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM;
 int bank_A; int bank_B;
 RAM = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 1) & 0x01);
 bank_B = 0x20000 * ((data >> 0) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
 RAM = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(1,RAM + bank_A,RAM + bank_B);
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall p0_w(__int64 a1, int a2)
{
p0 = a2;
}

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

original_code:
static void p0_w(offs_t offset,data_t data)
{
 p0 = data;
}

canonical_original_code:
static void p0_w(unsigned int offset, unsigned int data)
{
 p0 = data;
}


decompiled_code:
void __fastcall p1_w(__int64 a1, int a2)
{
p1 = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
p1 = a2;
}

original_code:
static void p1_w(offs_t offset,data_t data)
{
 p1 = data;
}

canonical_original_code:
static void p1_w(unsigned int offset, unsigned int data)
{
 p1 = data;
}


decompiled_code:
__int64 p0_r()
{
return (unsigned int)p0;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)p0;
}

original_code:
static data_t p0_r(offs_t offset)
{
 return p0;
}

canonical_original_code:
static unsigned int p0_r(unsigned int offset)
{
 return p0;
}


decompiled_code:
__int64 p1_r()
{
return (unsigned int)p1;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)p1;
}

original_code:
static data_t p1_r(offs_t offset)
{
 return p1;
}

canonical_original_code:
static unsigned int p1_r(unsigned int offset)
{
 return p1;
}


decompiled_code:
__int64 init_yamato()
{
return yamato_decode();
}

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

original_code:
static void init_yamato(void)
{
 yamato_decode();
}

canonical_original_code:
static void init_yamato()
{
 yamato_decode();
}


decompiled_code:
__int64 __fastcall moleattack_vh_convert_color_prom(_BYTE *a1, __int64 a2)
{
__int64 result; // rax

for ( result = 0LL; result != 8; ++result )
{
*(_WORD *)(a2 + 2 * result) = result;
*a1 = -(result & 1);
a1[1] = -(((unsigned int)result >> 2) & 1);
a1 += 3;
*(a1 - 1) = -(((unsigned int)result >> 1) & 1);
}
return result;
}

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

for ( result = 0LL; result != 8; ++result )
{
*(_WORD *)(a2 + 2 * result) = result;
*a1 = -(result & 1);
a1[1] = -(((unsigned int)result >> 2) & 1);
a1 += 3;
*(a1 - 1) = -(((unsigned int)result >> 1) & 1);
}
return result;
}

original_code:
void moleattack_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
 int i;
 for( i=0; i<8; i++ ){
  colortable[i] = i;
  *palette++ = (i&1)?0xff:0x00;
  *palette++ = (i&4)?0xff:0x00;
  *palette++ = (i&2)?0xff:0x00;
 }
}

canonical_original_code:
void moleattack_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom){
 int i;
 for( i=0; i<8; i++ ){
  colortable[i] = i;
  *palette++ = (i&1)?0xff:0x00;
  *palette++ = (i&4)?0xff:0x00;
  *palette++ = (i&2)?0xff:0x00;
 }
}


decompiled_code:
void __fastcall moleattack_tilesetselector_w(__int64 a1, int a2)
{
tile_bank = a2;
}

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

original_code:
void moleattack_tilesetselector_w(offs_t offset,data_t data){
 tile_bank = data;
}

canonical_original_code:
void moleattack_tilesetselector_w(unsigned int offset, unsigned int data){
 tile_bank = data;
}


decompiled_code:
__int64 moleattack_vh_start()
{
void *v0; // rax
void *v1; // rbx
_QWORD *v2; // rdx
__int64 result; // rax

v0 = malloc(0x7D0uLL);
tile_data = v0;
if ( !v0 )
return 1LL;
v1 = v0;
v2 = malloc(0x3E8uLL);
dirtybuffer = v2;
if ( v2 )
{
memset(v2, 1u, 0x3E8uLL);
result = 0LL;
}
else
{
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
void *v0; // rax
void *v1; // rbx
_QWORD *v2; // rdx
__int64 result; // rax

v0 = malloc(0x7D0uLL);
tile_data = v0;
if ( !v0 )
return 1LL;
v1 = v0;
v2 = malloc(0x3E8uLL);
dirtybuffer = v2;
if ( v2 )
{
memset(v2, 1u, 0x3E8uLL);
result = 0LL;
}
else
{
free(v1);
result = 1LL;
}
return result;
}

original_code:
int moleattack_vh_start( void ){
 tile_data = (UINT16 *)malloc( (25*40)*sizeof(UINT16) );
 if( tile_data ){
  dirtybuffer = (unsigned char*)malloc( (25*40) );
  if( dirtybuffer ){
   memset( dirtybuffer, 1, (25*40) );
   return 0;
  }
  free( tile_data );
 }
 return 1;
}

canonical_original_code:
int moleattack_vh_start(){
 tile_data = (unsigned short *)malloc( (25*40)*sizeof(UINT16) );
 if( tile_data ){
  dirtybuffer = (unsigned char *)malloc( (25*40) );
  if( dirtybuffer ){
   memset( dirtybuffer, 1, (25*40) );
   return 0;
  }
  free( tile_data );
 }
 return 1;
}


decompiled_code:
void moleattack_vh_stop()
{
free(dirtybuffer);
free(tile_data);
}

canonical_decompiled_code:
void func4()
{
free(dirtybuffer);
free(tile_data);
}

original_code:
void moleattack_vh_stop( void ){
 free( dirtybuffer );
 free( tile_data );
}

canonical_original_code:
void moleattack_vh_stop(){
 free( dirtybuffer );
 free( tile_data );
}


decompiled_code:
__int64 __fastcall mole_prot_r(unsigned int a1)
{
__int64 result; // rax
bool v2; // zf

if ( a1 == 134 )
return 145LL;
if ( a1 > 0x86 )
{
result = 0LL;
if ( a1 == 174 )
result = 50LL;
}
else
{
result = 176LL;
if ( a1 != 8 )
{
if ( a1 == 38 )
{
v2 = (unsigned int)cpu_get_pc() == 21463;
result = 6LL;
if ( !v2 )
result = 198LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax
bool v2; // zf

if ( a1 == 134 )
return 145LL;
if ( a1 > 0x86 )
{
result = 0LL;
if ( a1 == 174 )
result = 50LL;
}
else
{
result = 176LL;
if ( a1 != 8 )
{
if ( a1 == 38 )
{
v2 = (unsigned int)cpu_get_pc() == 21463;
result = 6LL;
if ( !v2 )
result = 198LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
data_t mole_prot_r(offs_t offset){
 switch( offset ){
 case 0x08: return 0xb0;
 case 0x26:
  if( cpu_get_pc() == 0x53d7 ){
   return 0x06;
  }
  else {
   return 0xc6;
  }
 case 0x86: return 0x91;
 case 0xae: return 0x32;
 }
 return 0x00;
}

canonical_original_code:
unsigned int mole_prot_r(unsigned int offset){
 switch( offset ){
 case 0x08: return 0xb0;
 case 0x26:
  if( cpu_get_pc() == 0x53d7 ){
   return 0x06;
  }
  else {
   return 0xc6;
  }
 case 0x86: return 0x91;
 case 0xae: return 0x32;
 }
 return 0x00;
}


original_code:
static UINT32 gundealr_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (row & 0x0f) + ((col & 0x3f) << 4) + ((row & 0x10) << 6);
}

canonical_original_code:
static unsigned int gundealr_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (row & 0x0f) + ((col & 0x3f) << 4) + ((row & 0x10) << 6);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


canonical_decompiled_code:
void func3()
{
input_ports_hack = 0;
}

original_code:
static void init_gundealr(void)
{
 input_ports_hack = 0;
}

canonical_original_code:
static void init_gundealr()
{
 input_ports_hack = 0;
}


decompiled_code:
__int64 gundealr_vh_start()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, gundealr_scan, 1LL, 16LL, 16LL, 64LL, v2);
fg_tilemap = v0;
if ( !bg_tilemap || !v0 )
return 1LL;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, gundealr_scan, 1LL, 16LL, 16LL, 64LL, v2);
fg_tilemap = v0;
if ( !bg_tilemap || !v0 )
return 1LL;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

original_code:
int gundealr_vh_start(void)
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x00, 8, 8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,gundealr_scan, 0x01,16,16,64,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int gundealr_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x00, 8, 8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,gundealr_scan, 0x01,16,16,64,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 15;
 return 0;
}


decompiled_code:
__int64 __fastcall gundealr_paletteram_w(unsigned int a1, char a2)
{
*(_BYTE *)(paletteram + a1) = a2;
return palette_change_color(
a1 >> 1,
17 * (unsigned int)(*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) >> 4),
17 * (*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) & 0xFu),
17 * (unsigned int)(*(_BYTE *)(paletteram + (a1 | 1)) >> 4));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
*(_BYTE *)(paletteram + a1) = a2;
return palette_change_color(
a1 >> 1,
17 * (unsigned int)(*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) >> 4),
17 * (*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) & 0xFu),
17 * (unsigned int)(*(_BYTE *)(paletteram + (a1 | 1)) >> 4));
}

original_code:
void gundealr_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b,val;
 paletteram[offset] = data;
 val = paletteram[offset & ~1];
 r = (val >> 4) & 0x0f;
 g = (val >> 0) & 0x0f;
 val = paletteram[offset | 1];
 b = (val >> 4) & 0x0f;
 r = 0x11 * r;
 g = 0x11 * g;
 b = 0x11 * b;
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void gundealr_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b; int val;
 paletteram[offset] = data;
 val = paletteram[offset & ~1];
 r = (val >> 4) & 0x0f;
 g = (val >> 0) & 0x0f;
 val = paletteram[offset | 1];
 b = (val >> 4) & 0x0f;
 r = 0x11 * r;
 g = 0x11 * g;
 b = 0x11 * b;
 palette_change_color(offset / 2,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: val int


decompiled_code:
__int64 __fastcall gundealr_fg_scroll_w(int a1, char a2)
{
scroll_1[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)byte_B65 | ((unsigned __int8)scroll_1[0] << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B67 | ((unsigned __int8)byte_B66 << 8) & 0x300u);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char a2)
{
scroll_1[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)byte_B65 | ((unsigned __int8)scroll_1[0] << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B67 | ((unsigned __int8)byte_B66 << 8) & 0x300u);
}

original_code:
void gundealr_fg_scroll_w(offs_t offset,data_t data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[1] | ((scroll[0] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[3] | ((scroll[2] & 0x03) << 8));
}

canonical_original_code:
void gundealr_fg_scroll_w(unsigned int offset, unsigned int data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[1] | ((scroll[0] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[3] | ((scroll[2] & 0x03) << 8));
}

variable_types:
scroll
unsigned char [4]


decompiled_code:
__int64 __fastcall yamyam_fg_scroll_w(int a1, char a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)scroll_0[0] | ((unsigned __int8)byte_B61 << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B62 | ((unsigned __int8)byte_B63 << 8) & 0x300u);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)scroll_0[0] | ((unsigned __int8)byte_B61 << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B62 | ((unsigned __int8)byte_B63 << 8) & 0x300u);
}

original_code:
void yamyam_fg_scroll_w(offs_t offset,data_t data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[0] | ((scroll[1] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[2] | ((scroll[3] & 0x03) << 8));
}

canonical_original_code:
void yamyam_fg_scroll_w(unsigned int offset, unsigned int data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[0] | ((scroll[1] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[2] | ((scroll[3] & 0x03) << 8));
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall gundealr_flipscreen_w(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 != 0 ? 3 : 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 != 0 ? 3 : 0);
}

original_code:
void gundealr_flipscreen_w(offs_t offset,data_t data)
{
 flipscreen = data;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
}

canonical_original_code:
void gundealr_flipscreen_w(unsigned int offset, unsigned int data)
{
 flipscreen = data;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall gundealr_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void gundealr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void gundealr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
}

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


decompiled_code:
__int64 yamyam_interrupt()
{
char v0; // dl
__int64 result; // rax
_BYTE *v2; // rbx

if ( (unsigned int)cpu_getiloops() )
{
v0 = cpu_getiloops();
result = 207LL;
if ( (v0 & 1) == 0 )
result = ignore_interrupt();
}
else
{
result = 215LL;
if ( input_ports_hack )
{
v2 = (_BYTE *)memory_region(129LL);
v2[57348] = readinputport(4LL);
v2[57349] = readinputport(3LL);
v2[57350] = readinputport(2LL);
result = 215LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
char v0; // dl
__int64 result; // rax
_BYTE *v2; // rbx

if ( (unsigned int)cpu_getiloops() )
{
v0 = cpu_getiloops();
result = 207LL;
if ( (v0 & 1) == 0 )
result = ignore_interrupt();
}
else
{
result = 215LL;
if ( input_ports_hack )
{
v2 = (_BYTE *)memory_region(129LL);
v2[57348] = readinputport(4LL);
v2[57349] = readinputport(3LL);
v2[57350] = readinputport(2LL);
result = 215LL;
}
}
return result;
}

original_code:
static int yamyam_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (input_ports_hack)
  {
   unsigned char *RAM = memory_region(REGION_CPU1);
   RAM[0xe004] = readinputport(4);
   RAM[0xe005] = readinputport(3);
   RAM[0xe006] = readinputport(2);
  }
  return 0xd7;
 }
 if ((cpu_getiloops() & 1) == 1) return 0xcf;
 else return ignore_interrupt();
}

canonical_original_code:
static int yamyam_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (input_ports_hack)
  {
   unsigned char *RAM = memory_region(REGION_CPU1);
   RAM[0xe004] = readinputport(4);
   RAM[0xe005] = readinputport(3);
   RAM[0xe006] = readinputport(2);
  }
  return 0xd7;
 }
 if ((cpu_getiloops() & 1) == 1) return 0xcf;
 else return ignore_interrupt();
}

variable_types:
RAM
unsigned char *


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

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

variable_types: bankaddress int


decompiled_code:
__int64 init_yamyam()
{
input_ports_hack = 1;
return install_mem_write_handler(0LL, 57344LL, 57344LL, yamyam_protection_w);
}

canonical_decompiled_code:
__int64 func12()
{
input_ports_hack = 1;
return install_mem_write_handler(0LL, 57344LL, 57344LL, yamyam_protection_w);
}

original_code:
static void init_yamyam(void)
{
 input_ports_hack = 1;
 install_mem_write_handler(0, 0xe000, 0xe000, yamyam_protection_w);
}

canonical_original_code:
static void init_yamyam()
{
 input_ports_hack = 1;
 install_mem_write_handler(0, 0xe000, 0xe000, yamyam_protection_w);
}


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(gundealr_bg_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(gundealr_bg_videoram + v1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 4);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(gundealr_bg_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(gundealr_bg_videoram + v1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 4);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = gundealr_bg_videoram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (gundealr_bg_videoram[2*tile_index] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = gundealr_bg_videoram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (gundealr_bg_videoram[2*tile_index] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

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


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(gundealr_fg_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(gundealr_fg_videoram + v1) + ((v2 << 8) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 4);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(gundealr_fg_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(gundealr_fg_videoram + v1) + ((v2 << 8) & 0x300u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 4);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = gundealr_fg_videoram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (gundealr_fg_videoram[2*tile_index] + ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = gundealr_fg_videoram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (gundealr_fg_videoram[2*tile_index] + ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

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:
__int64 __fastcall kchamp_vh_convert_color_prom(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // edx
char v6; // r10
char v7; // r9

result = *(_QWORD *)(Machine + 824LL);
v5 = *(_DWORD *)(result + 696);
if ( v5 )
{
result = 0LL;
do
{
v6 = *(_BYTE *)(a3 + v5 + (unsigned int)result);
v7 = *(_BYTE *)(a3 + (unsigned int)result + 2 * v5);
*a1 = 17 * *(_BYTE *)(a3 + result);
a1[1] = 17 * v6;
a1 += 3;
*(a1 - 1) = 17 * v7;
*(_WORD *)(a2 + 2 * result) = result;
v5 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL);
++result;
}
while ( v5 > (unsigned int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // edx
char v6; // r10
char v7; // r9

result = *(_QWORD *)(Machine + 824LL);
v5 = *(_DWORD *)(result + 696);
if ( v5 )
{
result = 0LL;
do
{
v6 = *(_BYTE *)(a3 + v5 + (unsigned int)result);
v7 = *(_BYTE *)(a3 + (unsigned int)result + 2 * v5);
*a1 = 17 * *(_BYTE *)(a3 + result);
a1[1] = 17 * v6;
a1 += 3;
*(a1 - 1) = 17 * v7;
*(_WORD *)(a2 + 2 * result) = result;
v5 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL);
++result;
}
while ( v5 > (unsigned int)result );
}
return result;
}

original_code:
void kchamp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
        int i, red, green, blue;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
                red = color_prom[i];
                green = color_prom[Machine->drv->total_colors+i];
                blue = color_prom[2*Machine->drv->total_colors+i];
                *(palette++) = red*0x11;
                *(palette++) = green*0x11;
                *(palette++) = blue*0x11;
                *(colortable++) = i;
 }
}

canonical_original_code:
void kchamp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
        int i; int red; int green; int blue;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
                red = color_prom[i];
                green = color_prom[Machine->drv->total_colors+i];
                blue = color_prom[2*Machine->drv->total_colors+i];
                *(palette++) = red*0x11;
                *(palette++) = green*0x11;
                *(palette++) = blue*0x11;
                *(colortable++) = i;
 }
}

variable_types:
palette
unsigned char *

variable_types: red int

variable_types: green int

variable_types: blue int


decompiled_code:
void __fastcall control_w(__int64 a1, char a2)
{
nmi_enable = a2 & 1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
nmi_enable = a2 & 1;
}

original_code:
static void control_w(offs_t offset,data_t data) {
 nmi_enable = data & 1;
}

canonical_original_code:
static void control_w(unsigned int offset, unsigned int data) {
 nmi_enable = data & 1;
}


decompiled_code:
void __fastcall sound_msm_w(__int64 a1, int a2)
{
msm_data = a2;
msm_play_lo_nibble = 1;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
msm_data = a2;
msm_play_lo_nibble = 1;
}

original_code:
static void sound_msm_w(offs_t offset,data_t data) {
 msm_data = data;
 msm_play_lo_nibble = 1;
}

canonical_original_code:
static void sound_msm_w(unsigned int offset, unsigned int data) {
 msm_data = data;
 msm_play_lo_nibble = 1;
}


decompiled_code:
void __fastcall kc_sound_control_w(int a1, unsigned int a2)
{
if ( !a1 )
sound_nmi_enable = (a2 >> 7) & 1;
}

canonical_decompiled_code:
void __fastcall func3(int a1, unsigned int a2)
{
if ( !a1 )
sound_nmi_enable = (a2 >> 7) & 1;
}

original_code:
static void kc_sound_control_w(offs_t offset,data_t data) {
 if ( offset == 0 )
  sound_nmi_enable = ( ( data >> 7 ) & 1 );
}

canonical_original_code:
static void kc_sound_control_w(unsigned int offset, unsigned int data) {
 if ( offset == 0 )
  sound_nmi_enable = ( ( data >> 7 ) & 1 );
}


decompiled_code:
__int64 kc_interrupt()
{
return (unsigned int)(nmi_enable == 0) - 2;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)(nmi_enable == 0) - 2;
}

original_code:
static int kc_interrupt( void ) {
 if ( nmi_enable )
  return -2;
 return -1;
}

canonical_original_code:
static int kc_interrupt() {
 if ( nmi_enable )
  return -2;
 return -1;
}


decompiled_code:
__int64 sound_int()
{
return (unsigned int)(sound_nmi_enable == 0) - 2;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)(sound_nmi_enable == 0) - 2;
}

original_code:
static int sound_int( void ) {
 if ( sound_nmi_enable )
  return -2;
 return -1;
}

canonical_original_code:
static int sound_int() {
 if ( sound_nmi_enable )
  return -2;
 return -1;
}


decompiled_code:
__int64 kchampvs_vh_start()
{
kchamp_drawsprites = (__int64)kchamp_vs_drawsprites;
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func6()
{
kchamp_drawsprites = (__int64)kchamp_vs_drawsprites;
return generic_vh_start();
}

original_code:
int kchampvs_vh_start(void) {
 kchamp_drawsprites = kchamp_vs_drawsprites;
 return generic_vh_start();
}

canonical_original_code:
int kchampvs_vh_start() {
 kchamp_drawsprites = kchamp_vs_drawsprites;
 return generic_vh_start();
}


decompiled_code:
__int64 kchamp1p_vh_start()
{
kchamp_drawsprites = (__int64)kchamp_1p_drawsprites;
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func7()
{
kchamp_drawsprites = (__int64)kchamp_1p_drawsprites;
return generic_vh_start();
}

original_code:
int kchamp1p_vh_start(void) {
 kchamp_drawsprites = kchamp_1p_drawsprites;
 return generic_vh_start();
}

canonical_original_code:
int kchamp1p_vh_start() {
 kchamp_drawsprites = kchamp_1p_drawsprites;
 return generic_vh_start();
}


decompiled_code:
__int64 __fastcall kchamp_vs_drawsprites(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 1LL; i != 257; i += 4LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520),
*(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u),
*(_BYTE *)(spriteram + i + 1) & 0xF,
0LL,
*(_BYTE *)(spriteram + i + 1) & 0x80,
*(unsigned __int8 *)(spriteram + i + 2),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1),
Machine + 776LL,
2LL,
0LL);
return result;
}

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

for ( i = 1LL; i != 257; i += 4LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520),
*(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u),
*(_BYTE *)(spriteram + i + 1) & 0xF,
0LL,
*(_BYTE *)(spriteram + i + 1) & 0x80,
*(unsigned __int8 *)(spriteram + i + 2),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1),
Machine + 776LL,
2LL,
0LL);
return result;
}

original_code:
void kchamp_vs_drawsprites( struct osd_bitmap *bitmap ) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx, sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3];
                sy = 240 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void kchamp_vs_drawsprites(struct osd_bitmap *bitmap) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx; int sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3];
                sy = 240 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: numtile int

variable_types: flipx int

variable_types: sx int

variable_types: sy int

variable_types: gfx int

variable_types: color int

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


decompiled_code:
__int64 __fastcall kchamp_1p_drawsprites(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 1LL; i != 257; i += 4LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520),
*(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u),
*(_BYTE *)(spriteram + i + 1) & 0xF,
0LL,
*(_BYTE *)(spriteram + i + 1) & 0x80,
(unsigned int)*(unsigned __int8 *)(spriteram + i + 2) - 8,
247 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1),
Machine + 776LL,
2LL,
0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 1LL; i != 257; i += 4LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520),
*(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u),
*(_BYTE *)(spriteram + i + 1) & 0xF,
0LL,
*(_BYTE *)(spriteram + i + 1) & 0x80,
(unsigned int)*(unsigned __int8 *)(spriteram + i + 2) - 8,
247 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1),
Machine + 776LL,
2LL,
0LL);
return result;
}

original_code:
void kchamp_1p_drawsprites( struct osd_bitmap *bitmap ) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx, sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3] - 8;
                sy = 247 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void kchamp_1p_drawsprites(struct osd_bitmap *bitmap) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx; int sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3] - 8;
                sy = 247 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}


decompiled_code:
__int64 __fastcall kchamp_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(colorram + v2) << 8) & 0x700) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 3,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return kchamp_drawsprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(colorram + v2) << 8) & 0x700) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 3,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return kchamp_drawsprites(a1);
}

original_code:
void kchamp_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,code;
   dirtybuffer[offs] = 0;
                        sx = (offs % 32);
   sy = (offs / 32);
                        code = videoram[offs] + ( ( colorram[offs] & 7 ) << 8 );
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                        code,
                                        ( colorram[offs] >> 3 ) & 0x1f,
                                        0,
                                        0,
     sx*8,sy*8,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 (*kchamp_drawsprites)( bitmap);
}

canonical_original_code:
void kchamp_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; int code;
   dirtybuffer[offs] = 0;
                        sx = (offs % 32);
   sy = (offs / 32);
                        code = videoram[offs] + ( ( colorram[offs] & 7 ) << 8 );
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                        code,
                                        ( colorram[offs] >> 3 ) & 0x1f,
                                        0,
                                        0,
     sx*8,sy*8,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 (*kchamp_drawsprites)( bitmap);
}

variable_types: code int


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

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

original_code:
static data_t sound_reset_r(offs_t offset) {
 cpu_set_reset_line(1,3);
 return 0;
}

canonical_original_code:
static unsigned int sound_reset_r(unsigned int offset) {
 cpu_set_reset_line(1,3);
 return 0;
}

variable_types:
offset
unsigned int


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

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

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

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

original_code:
static void sound_reset_w(offs_t offset,data_t data) {
 if ( !( data & 1 ) )
  cpu_set_reset_line(1,3);
}

canonical_original_code:
static void sound_reset_w(unsigned int offset, unsigned int data) {
 if ( !( data & 1 ) )
  cpu_set_reset_line(1,3);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 init_kchampvs()
{
_BYTE *v0; // rbp
int v1; // er12
_BYTE *v2; // rcx
int v3; // eax
unsigned __int8 *v4; // rcx
unsigned __int8 v5; // dl
int v6; // eax
char v7; // dl
__int64 result; // rax

v0 = (_BYTE *)memory_region(129LL);
v1 = (int)memory_region_length(129LL) / 2;
memory_set_opcode_base(0LL, &v0[v1]);
v2 = v0;
do
{
v2[v1] = *v2 & 0x55 | (4 * *v2) & 0x88 | ((int)(unsigned __int8)*v2 >> 2) & 0x22;
++v2;
}
while ( v2 != v0 + 0x10000 );
v0[v1] = *v0;
v3 = (unsigned __int8)v0[1] + ((unsigned __int8)v0[2] << 8);
v0[v1 + v3] = v0[v3];
v4 = &v0[v3 + 1];
v5 = *v4 ^ 0xEE;
*v4 = v5;
v6 = ((unsigned __int8)v0[v3 + 2] << 8) + v5;
v0[v1 + v6] = v0[v6];
v6 += 2;
v7 = v0[v6];
result = v1 + v6;
v0[result] = v7;
return result;
}

original_code:
static void init_kchampvs( void )
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int A;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0;A < 0x10000;A++)
  rom[A+diff] = (rom[A] & 0x55) | ((rom[A] & 0x88) >> 2) | ((rom[A] & 0x22) << 2);
 rom[0+diff] = rom[0];
 A = rom[1] + 256 * rom[2];
 rom[A+diff] = rom[A];
 rom[A+1] ^= 0xee;
 A = rom[A+1] + 256 * rom[A+2];
 rom[A+diff] = rom[A];
 A += 2;
 rom[A+diff] = rom[A];
}

canonical_original_code:
static void init_kchampvs()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int A;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0;A < 0x10000;A++)
  rom[A+diff] = (rom[A] & 0x55) | ((rom[A] & 0x88) >> 2) | ((rom[A] & 0x22) << 2);
 rom[0+diff] = rom[0];
 A = rom[1] + 256 * rom[2];
 rom[A+diff] = rom[A];
 rom[A+1] ^= 0xee;
 A = rom[A+1] + 256 * rom[A+2];
 rom[A+diff] = rom[A];
 A += 2;
 rom[A+diff] = rom[A];
}

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int


msmint

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

if ( msm_play_lo_nibble )
MSM5205_data_w(0LL, msm_data & 0xF);
else
MSM5205_data_w(0LL, (msm_data >> 4) & 0xF);
msm_play_lo_nibble ^= 1u;
result = (unsigned int)counter_0;
counter_0 ^= 1u;
if ( (_DWORD)result == 1 )
{
if ( sound_nmi_enable )
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

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

if ( msm_play_lo_nibble )
MSM5205_data_w(0LL, msm_data & 0xF);
else
MSM5205_data_w(0LL, (msm_data >> 4) & 0xF);
msm_play_lo_nibble ^= 1u;
result = (unsigned int)counter_0;
counter_0 ^= 1u;
if ( (_DWORD)result == 1 )
{
if ( sound_nmi_enable )
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

original_code:
static void msmint( int data ) {
 static int counter = 0;
 if ( msm_play_lo_nibble )
  MSM5205_data_w( 0, msm_data & 0x0f );
 else
  MSM5205_data_w( 0, ( msm_data >> 4 ) & 0x0f );
 msm_play_lo_nibble ^= 1;
 if ( !( counter ^= 1 ) ) {
  if ( sound_nmi_enable ) {
   cpu_cause_interrupt( 1, -2 );
  }
 }
}

canonical_original_code:
static void msmint(int data) {
 static int counter = 0;
 if ( msm_play_lo_nibble )
  MSM5205_data_w( 0, msm_data & 0x0f );
 else
  MSM5205_data_w( 0, ( msm_data >> 4 ) & 0x0f );
 msm_play_lo_nibble ^= 1;
 if ( !( counter ^= 1 ) ) {
  if ( sound_nmi_enable ) {
   cpu_cause_interrupt( 1, -2 );
  }
 }
}

variable_types: data int

variable_types: counter int


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

result = MSM5205_reset_w(0LL, ((unsigned __int8)a2 ^ 1) & 1);
sound_nmi_enable = (a2 >> 1) & 1;
return result;
}

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

result = MSM5205_reset_w(0LL, ((unsigned __int8)a2 ^ 1) & 1);
sound_nmi_enable = (a2 >> 1) & 1;
return result;
}

original_code:
static void sound_control_w(offs_t offset,data_t data) {
 MSM5205_reset_w( 0, !( data & 1 ) );
 sound_nmi_enable = ( ( data >> 1 ) & 1 );
}

canonical_original_code:
static void sound_control_w(unsigned int offset, unsigned int data) {
 MSM5205_reset_w( 0, !( data & 1 ) );
 sound_nmi_enable = ( ( data >> 1 ) & 1 );
}


decompiled_code:
__int64 sound_command_w()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func11()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 255LL);
}

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

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


original_code:
void champbas_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[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f);
}

canonical_original_code:
void champbas_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[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f);
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void *__fastcall champbas_gfxbank_w(__int64 a1, char a2)
{
void *result; // rax

result = (void *)(a2 & 1);
if ( (_DWORD)result != gfxbank )
{
gfxbank = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = (void *)(a2 & 1);
if ( (_DWORD)result != gfxbank )
{
gfxbank = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

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


decompiled_code:
void *__fastcall champbas_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ebp
__int64 v5; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfxbank + 512),
*(unsigned __int8 *)(videoram + v2),
(*(_BYTE *)(colorram + v2) & 0x1Fu) + 32,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v5 = v4;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (gfxbank + 2) + 512),
*(_BYTE *)(spriteram + v5) >> 2,
*(unsigned __int8 *)(spriteram + v5 + 1),
*(_BYTE *)(spriteram + v5) & 1,
*(_BYTE *)(spriteram + v5) & 2,
(unsigned int)(unsigned __int8)(16 - *(_BYTE *)(spriteram_2 + v5 + 1)) - 16,
(unsigned int)*(unsigned __int8 *)(spriteram_2 + v5) - 16,
Machine + 776LL,
6LL,
0LL);
v5 -= 2LL;
v4 -= 2;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ebp
__int64 v5; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfxbank + 512),
*(unsigned __int8 *)(videoram + v2),
(*(_BYTE *)(colorram + v2) & 0x1Fu) + 32,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v5 = v4;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (gfxbank + 2) + 512),
*(_BYTE *)(spriteram + v5) >> 2,
*(unsigned __int8 *)(spriteram + v5 + 1),
*(_BYTE *)(spriteram + v5) & 1,
*(_BYTE *)(spriteram + v5) & 2,
(unsigned int)(unsigned __int8)(16 - *(_BYTE *)(spriteram_2 + v5 + 1)) - 16,
(unsigned int)*(unsigned __int8 *)(spriteram_2 + v5) - 16,
Machine + 776LL,
6LL,
0LL);
v5 -= 2LL;
v4 -= 2;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void champbas_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 = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0 + gfxbank],
     videoram[offs],
     (colorram[offs] & 0x1f) + 32,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  drawgfx(bitmap,Machine->gfx[2 + gfxbank],
    spriteram[offs] >> 2,
    spriteram[offs + 1],
    spriteram[offs] & 1,spriteram[offs] & 2,
    ((256+16 - spriteram_2[offs + 1]) & 0xff) - 16,spriteram_2[offs] - 16,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
void champbas_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 = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0 + gfxbank],
     videoram[offs],
     (colorram[offs] & 0x1f) + 32,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  drawgfx(bitmap,Machine->gfx[2 + gfxbank],
    spriteram[offs] >> 2,
    spriteram[offs + 1],
    spriteram[offs] & 1,spriteram[offs] & 2,
    ((256+16 - spriteram_2[offs + 1]) & 0xff) - 16,spriteram_2[offs] - 16,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

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

variable_types: offs int