decompiled_code:
__int64 __fastcall soundsgood_porta_w(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)soundsgood_dac_index, (unsigned __int16)dacval << 6);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)soundsgood_dac_index, (unsigned __int16)dacval << 6);
}

original_code:
static void soundsgood_porta_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(soundsgood_dac_index, dacval << 6);
}

canonical_original_code:
static void soundsgood_porta_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(soundsgood_dac_index, dacval << 6);
}


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

dacval = (a2 >> 6) | dacval & 0xFFFC;
result = DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
turbocs_status = (a2 >> 4) & 3;
return result;
}

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

dacval = (a2 >> 6) | dacval & 0xFFFC;
result = DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
turbocs_status = (a2 >> 4) & 3;
return result;
}

original_code:
static void turbocs_portb_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
 turbocs_status = (data >> 4) & 3;
}

canonical_original_code:
static void turbocs_portb_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x003) | (data >> 6);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
 turbocs_status = (data >> 4) & 3;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall turbocs_porta_w(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int16 a2)
{
dacval = (4 * a2) | dacval & 0xFC03;
return DAC_signed_data_16_w((unsigned __int8)turbocs_dac_index, (unsigned __int16)dacval << 6);
}

original_code:
static void turbocs_porta_w(offs_t offset,data_t data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
}

canonical_original_code:
static void turbocs_porta_w(unsigned int offset, unsigned int data)
{
 dacval = (dacval & ~0x3fc) | (data << 2);
 DAC_signed_data_16_w(turbocs_dac_index, dacval << 6);
}


decompiled_code:
__int64 __fastcall soundsgood_delayed_data_w(int a1)
{
pia_1_portb_w(0LL, (a1 >> 1) & 0xF);
return pia_1_ca1_w(0LL, (a1 & 1) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1)
{
pia_1_portb_w(0LL, (a1 >> 1) & 0xF);
return pia_1_ca1_w(0LL, (a1 & 1) == 0);
}

original_code:
static void soundsgood_delayed_data_w(int param)
{
 pia_1_portb_w(0, (param >> 1) & 0x0f);
 pia_1_ca1_w(0, ~param & 0x01);
}

variable_types: param int


decompiled_code:
__int64 __fastcall squawkntalk_delayed_data_w(int a1)
{
pia_0_porta_w(0LL, ~(_BYTE)a1 & 0xF);
return pia_0_cb1_w(0LL, ~a1 & 0x10);
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1)
{
pia_0_porta_w(0LL, ~(_BYTE)a1 & 0xF);
return pia_0_cb1_w(0LL, ~a1 & 0x10);
}

original_code:
static void squawkntalk_delayed_data_w(int param)
{
 pia_0_porta_w(0, ~param & 0x0f);
 pia_0_cb1_w(0, ~param & 0x10);
}


decompiled_code:
__int64 __fastcall squawkntalk_portb2_w(__int64 a1, char a2)
{
int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax

v2 = a2 & 3;
result = v2 ^ (unsigned int)(unsigned __int8)squawkntalk_tms_strobes;
if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 2) != 0 && (a2 & 2) == 0 )
{
tms5220_data_w(a1, (unsigned __int8)squawkntalk_tms_command);
pia_1_ca2_w(0LL, 1LL);
result = pia_1_ca2_w(0LL, 0LL);
}
else if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 1) != 0 && (a2 & 1) == 0 )
{
v4 = tms5220_status_r();
pia_1_porta_w(0LL, v4);
pia_1_ca2_w(0LL, 1LL);
result = pia_1_ca2_w(0LL, 0LL);
}
squawkntalk_tms_strobes = a2 & 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, char a2)
{
int v2; // ebx
__int64 result; // rax
unsigned int v4; // eax

v2 = a2 & 3;
result = v2 ^ (unsigned int)(unsigned __int8)squawkntalk_tms_strobes;
if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 2) != 0 && (a2 & 2) == 0 )
{
tms5220_data_w(a1, (unsigned __int8)squawkntalk_tms_command);
pia_1_ca2_w(0LL, 1LL);
result = pia_1_ca2_w(0LL, 0LL);
}
else if ( (((unsigned __int8)v2 ^ (unsigned __int8)squawkntalk_tms_strobes) & 1) != 0 && (a2 & 1) == 0 )
{
v4 = tms5220_status_r();
pia_1_porta_w(0LL, v4);
pia_1_ca2_w(0LL, 1LL);
result = pia_1_ca2_w(0LL, 0LL);
}
squawkntalk_tms_strobes = a2 & 3;
return result;
}

original_code:
static void squawkntalk_portb2_w(offs_t offset,data_t data)
{
 data &= 0x03;
 if (((data ^ squawkntalk_tms_strobes) & 0x02) && !(data & 0x02))
 {
  tms5220_data_w(offset, squawkntalk_tms_command);
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 else if (((data ^ squawkntalk_tms_strobes) & 0x01) && !(data & 0x01))
 {
  pia_1_porta_w(0, tms5220_status_r(offset));
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 squawkntalk_tms_strobes = data;
}

canonical_original_code:
static void squawkntalk_portb2_w(unsigned int offset, unsigned int data)
{
 data &= 0x03;
 if (((data ^ squawkntalk_tms_strobes) & 0x02) && !(data & 0x02))
 {
  tms5220_data_w(offset, squawkntalk_tms_command);
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 else if (((data ^ squawkntalk_tms_strobes) & 0x01) && !(data & 0x01))
 {
  pia_1_porta_w(0, tms5220_status_r(offset));
  pia_1_ca2_w(0, 1);
  pia_1_ca2_w(0, 0);
 }
 squawkntalk_tms_strobes = data;
}


decompiled_code:
__int64 __fastcall ssio_data_w(int a1, unsigned __int8 a2)
{
return timer_set(0LL, (a1 << 8) | (unsigned int)a2, ssio_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func25(int a1, unsigned __int8 a2)
{
return timer_set(0LL, (a1 << 8) | (unsigned int)a2, ssio_delayed_data_w);
}

original_code:
void ssio_data_w(offs_t offset,data_t data)
{
 timer_set((0), (offset << 8) | (data & 0xff), ssio_delayed_data_w);
}

canonical_original_code:
void ssio_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), (offset << 8) | (data & 0xff), ssio_delayed_data_w);
}


decompiled_code:
__int64 ssio_status_r()
{
return (unsigned __int8)ssio_status;
}

canonical_decompiled_code:
__int64 func26()
{
return (unsigned __int8)ssio_status;
}

original_code:
data_t ssio_status_r(offs_t offset)
{
 return ssio_status;
}

canonical_original_code:
unsigned int ssio_status_r(unsigned int offset)
{
 return ssio_status;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall ssio_reset_w(int a1)
{
__int64 result; // rax

if ( !a1 )
return cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 0LL);
result = cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 1LL);
ssio_data[0] = 0;
byte_818 = 0;
byte_819 = 0;
byte_81A = 0;
ssio_status = 0;
return result;
}

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

if ( !a1 )
return cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 0LL);
result = cpu_set_reset_line((unsigned __int8)ssio_sound_cpu, 1LL);
ssio_data[0] = 0;
byte_818 = 0;
byte_819 = 0;
byte_81A = 0;
ssio_status = 0;
return result;
}

original_code:
void ssio_reset_w(int state)
{
 if (state)
 {
  int i;
  cpu_set_reset_line(ssio_sound_cpu, 1);
  for (i = 0; i < 4; i++)
   ssio_data[i] = 0;
  ssio_status = 0;
 }
 else
  cpu_set_reset_line(ssio_sound_cpu, 0);
}

variable_types: state int

variable_types: i int


decompiled_code:
__int64 __fastcall csdeluxe_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, csdeluxe_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, csdeluxe_delayed_data_w);
}

original_code:
void csdeluxe_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, csdeluxe_delayed_data_w);
}

canonical_original_code:
void csdeluxe_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, csdeluxe_delayed_data_w);
}


decompiled_code:
__int64 __fastcall csdeluxe_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)csdeluxe_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func29(int a1)
{
return cpu_set_reset_line((unsigned __int8)csdeluxe_sound_cpu, a1 != 0);
}

original_code:
void csdeluxe_reset_w(int state)
{
 cpu_set_reset_line(csdeluxe_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall soundsgood_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, soundsgood_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, soundsgood_delayed_data_w);
}

original_code:
void soundsgood_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, soundsgood_delayed_data_w);
}

canonical_original_code:
void soundsgood_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, soundsgood_delayed_data_w);
}


decompiled_code:
__int64 soundsgood_status_r()
{
return (unsigned __int8)soundsgood_status;
}

canonical_decompiled_code:
__int64 func31()
{
return (unsigned __int8)soundsgood_status;
}

original_code:
data_t soundsgood_status_r(offs_t offset)
{
 return soundsgood_status;
}

canonical_original_code:
unsigned int soundsgood_status_r(unsigned int offset)
{
 return soundsgood_status;
}


decompiled_code:
__int64 __fastcall soundsgood_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)soundsgood_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func32(int a1)
{
return cpu_set_reset_line((unsigned __int8)soundsgood_sound_cpu, a1 != 0);
}

original_code:
void soundsgood_reset_w(int state)
{
 cpu_set_reset_line(soundsgood_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall turbocs_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, turbocs_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func33(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, turbocs_delayed_data_w);
}

original_code:
void turbocs_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, turbocs_delayed_data_w);
}

canonical_original_code:
void turbocs_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, turbocs_delayed_data_w);
}


decompiled_code:
__int64 turbocs_status_r()
{
return (unsigned __int8)turbocs_status;
}

canonical_decompiled_code:
__int64 func34()
{
return (unsigned __int8)turbocs_status;
}

original_code:
data_t turbocs_status_r(offs_t offset)
{
 return turbocs_status;
}

canonical_original_code:
unsigned int turbocs_status_r(unsigned int offset)
{
 return turbocs_status;
}


decompiled_code:
__int64 __fastcall turbocs_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)turbocs_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func35(int a1)
{
return cpu_set_reset_line((unsigned __int8)turbocs_sound_cpu, a1 != 0);
}

original_code:
void turbocs_reset_w(int state)
{
 cpu_set_reset_line(turbocs_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 __fastcall squawkntalk_data_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, squawkntalk_delayed_data_w);
}

canonical_decompiled_code:
__int64 __fastcall func36(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, squawkntalk_delayed_data_w);
}

original_code:
void squawkntalk_data_w(offs_t offset,data_t data)
{
 timer_set((0), data, squawkntalk_delayed_data_w);
}

canonical_original_code:
void squawkntalk_data_w(unsigned int offset, unsigned int data)
{
 timer_set((0), data, squawkntalk_delayed_data_w);
}


decompiled_code:
__int64 __fastcall squawkntalk_reset_w(int a1)
{
return cpu_set_reset_line((unsigned __int8)squawkntalk_sound_cpu, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func37(int a1)
{
return cpu_set_reset_line((unsigned __int8)squawkntalk_sound_cpu, a1 != 0);
}

original_code:
void squawkntalk_reset_w(int state)
{
 cpu_set_reset_line(squawkntalk_sound_cpu, state ? 1 : 0);
}


decompiled_code:
__int64 mcr_sound_init()
{
unsigned int v0; // ebx
char v1; // bp

v0 = 1;
if ( (mcr_sound_config & 1) != 0 )
{
ssio_sound_cpu = 1;
ssio_reset_w(1);
ssio_reset_w(0);
v0 = 2;
}
v1 = 0;
if ( (mcr_sound_config & 8) != 0 )
{
pia_config(0LL, 1LL, &turbocs_pia_intf);
turbocs_dac_index = 0;
turbocs_sound_cpu = v0;
turbocs_reset_w(1);
turbocs_reset_w(0);
++v0;
v1 = 1;
}
if ( (mcr_sound_config & 2) != 0 )
{
pia_config(0LL, 11LL, &csdeluxe_pia_intf);
csdeluxe_dac_index = v1;
csdeluxe_sound_cpu = v0;
csdeluxe_reset_w(1);
csdeluxe_reset_w(0);
++v1;
++v0;
}
if ( (mcr_sound_config & 4) != 0 )
{
pia_config(1LL, 7LL, &soundsgood_pia_intf);
soundsgood_dac_index = v1;
soundsgood_sound_cpu = v0;
soundsgood_reset_w(1);
soundsgood_reset_w(0);
++v0;
}
if ( (mcr_sound_config & 0x10) != 0 )
{
pia_config(0LL, 0LL, &squawkntalk_pia0_intf);
pia_config(1LL, 0LL, &squawkntalk_pia1_intf);
squawkntalk_sound_cpu = v0;
squawkntalk_reset_w(1);
squawkntalk_reset_w(0);
++v0;
}
if ( (mcr_sound_config & 0x20) != 0 )
{
williams_cvsd_init(v0, 0LL);
williams_cvsd_reset_w(1LL);
williams_cvsd_reset_w(0LL);
}
return pia_reset();
}

canonical_decompiled_code:
__int64 func38()
{
unsigned int v0; // ebx
char v1; // bp

v0 = 1;
if ( (mcr_sound_config & 1) != 0 )
{
ssio_sound_cpu = 1;
func27(1);
func27(0);
v0 = 2;
}
v1 = 0;
if ( (mcr_sound_config & 8) != 0 )
{
pia_config(0LL, 1LL, &turbocs_pia_intf);
turbocs_dac_index = 0;
turbocs_sound_cpu = v0;
func35(1);
func35(0);
++v0;
v1 = 1;
}
if ( (mcr_sound_config & 2) != 0 )
{
pia_config(0LL, 11LL, &csdeluxe_pia_intf);
csdeluxe_dac_index = v1;
csdeluxe_sound_cpu = v0;
func29(1);
func29(0);
++v1;
++v0;
}
if ( (mcr_sound_config & 4) != 0 )
{
pia_config(1LL, 7LL, &soundsgood_pia_intf);
soundsgood_dac_index = v1;
soundsgood_sound_cpu = v0;
func32(1);
func32(0);
++v0;
}
if ( (mcr_sound_config & 0x10) != 0 )
{
pia_config(0LL, 0LL, &squawkntalk_pia0_intf);
pia_config(1LL, 0LL, &squawkntalk_pia1_intf);
squawkntalk_sound_cpu = v0;
func37(1);
func37(0);
++v0;
}
if ( (mcr_sound_config & 0x20) != 0 )
{
williams_cvsd_init(v0, 0LL);
williams_cvsd_reset_w(1LL);
williams_cvsd_reset_w(0LL);
}
return pia_reset();
}

original_code:
void mcr_sound_init(void)
{
 int sound_cpu = 1;
 int dac_index = 0;
 if (mcr_sound_config & 0x01)
 {
  ssio_sound_cpu = sound_cpu++;
  ssio_reset_w(1);
  ssio_reset_w(0);
 }
 if (mcr_sound_config & 0x08)
 {
  pia_config(0, 1, &turbocs_pia_intf);
  turbocs_dac_index = dac_index++;
  turbocs_sound_cpu = sound_cpu++;
  turbocs_reset_w(1);
  turbocs_reset_w(0);
 }
 if (mcr_sound_config & 0x02)
 {
  pia_config(0, 1 | (2 | 8), &csdeluxe_pia_intf);
  csdeluxe_dac_index = dac_index++;
  csdeluxe_sound_cpu = sound_cpu++;
  csdeluxe_reset_w(1);
  csdeluxe_reset_w(0);
 }
 if (mcr_sound_config & 0x04)
 {
  pia_config(1, 1 | (2 | 4), &soundsgood_pia_intf);
  soundsgood_dac_index = dac_index++;
  soundsgood_sound_cpu = sound_cpu++;
  soundsgood_reset_w(1);
  soundsgood_reset_w(0);
 }
 if (mcr_sound_config & 0x10)
 {
  pia_config(0, 0 | 0, &squawkntalk_pia0_intf);
  pia_config(1, 0 | 0, &squawkntalk_pia1_intf);
  squawkntalk_sound_cpu = sound_cpu++;
  squawkntalk_reset_w(1);
  squawkntalk_reset_w(0);
 }
 if (mcr_sound_config & 0x20)
 {
  williams_cvsd_init(sound_cpu++, 0);
  dac_index++;
  williams_cvsd_reset_w(1);
  williams_cvsd_reset_w(0);
 }
 pia_reset();
}

canonical_original_code:
void mcr_sound_init()
{
 int sound_cpu = 1;
 int dac_index = 0;
 if (mcr_sound_config & 0x01)
 {
  ssio_sound_cpu = sound_cpu++;
  ssio_reset_w(1);
  ssio_reset_w(0);
 }
 if (mcr_sound_config & 0x08)
 {
  pia_config(0, 1, &turbocs_pia_intf);
  turbocs_dac_index = dac_index++;
  turbocs_sound_cpu = sound_cpu++;
  turbocs_reset_w(1);
  turbocs_reset_w(0);
 }
 if (mcr_sound_config & 0x02)
 {
  pia_config(0, 1 | (2 | 8), &csdeluxe_pia_intf);
  csdeluxe_dac_index = dac_index++;
  csdeluxe_sound_cpu = sound_cpu++;
  csdeluxe_reset_w(1);
  csdeluxe_reset_w(0);
 }
 if (mcr_sound_config & 0x04)
 {
  pia_config(1, 1 | (2 | 4), &soundsgood_pia_intf);
  soundsgood_dac_index = dac_index++;
  soundsgood_sound_cpu = sound_cpu++;
  soundsgood_reset_w(1);
  soundsgood_reset_w(0);
 }
 if (mcr_sound_config & 0x10)
 {
  pia_config(0, 0 | 0, &squawkntalk_pia0_intf);
  pia_config(1, 0 | 0, &squawkntalk_pia1_intf);
  squawkntalk_sound_cpu = sound_cpu++;
  squawkntalk_reset_w(1);
  squawkntalk_reset_w(0);
 }
 if (mcr_sound_config & 0x20)
 {
  williams_cvsd_init(sound_cpu++, 0);
  dac_index++;
  williams_cvsd_reset_w(1);
  williams_cvsd_reset_w(0);
 }
 pia_reset();
}


original_code:
void blueprnt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 16;i++)
 {
  (*palette++) = ((i >> 0) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 2) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 1) & 1) * ((i & 0x08) ? 0xbf : 0xff);
 }
 for (i = 0;i < 128;i++)
 {
  int base = (i & 0x40) ? 8 : 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+0]) = base + 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+1]) = base + ((i >> 0) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+2]) = base + ((i >> 3) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+3]) = base + (((i >> 0) & 7) | ((i >> 3) & 7));
 }
 for (i = 0;i < 8;i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = i;
}

canonical_original_code:
void blueprnt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 16;i++)
 {
  (*palette++) = ((i >> 0) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 2) & 1) * ((i & 0x08) ? 0xbf : 0xff);
  (*palette++) = ((i >> 1) & 1) * ((i & 0x08) ? 0xbf : 0xff);
 }
 for (i = 0;i < 128;i++)
 {
  int base = (i & 0x40) ? 8 : 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+0]) = base + 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+1]) = base + ((i >> 0) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+2]) = base + ((i >> 3) & 7);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+3]) = base + (((i >> 0) & 7) | ((i >> 3) & 7));
 }
 for (i = 0;i < 8;i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = i;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: base int


decompiled_code:
void __fastcall dipsw_w(__int64 a1, int a2)
{
dipsw = a2;
}

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

original_code:
static void dipsw_w(offs_t offset,data_t data)
{
 dipsw = data;
}

canonical_original_code:
static void dipsw_w(unsigned int offset, unsigned int data)
{
 dipsw = data;
}


decompiled_code:
__int64 blueprnt_sh_dipsw_r()
{
return (unsigned int)dipsw;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)dipsw;
}

original_code:
data_t blueprnt_sh_dipsw_r(offs_t offset)
{
 return dipsw;
}

canonical_original_code:
unsigned int blueprnt_sh_dipsw_r(unsigned int offset)
{
 return dipsw;
}


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

if ( (~a2 & 2) != flipscreen )
{
flipscreen = ~a2 & 2;
memset(dirtybuffer, 1, videoram_size);
}
result = (a2 & 4) != 0;
if ( (_DWORD)result != gfx_bank )
{
gfx_bank = (a2 & 4) != 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

if ( (~a2 & 2) != flipscreen )
{
flipscreen = ~a2 & 2;
memset(dirtybuffer, 1, videoram_size);
}
result = (a2 & 4) != 0;
if ( (_DWORD)result != gfx_bank )
{
gfx_bank = (a2 & 4) != 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void blueprnt_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != (~data & 2))
 {
  flipscreen = ~data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
 if (gfx_bank != ((data & 4) >> 2))
 {
  gfx_bank = ((data & 4) >> 2);
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void blueprnt_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != (~data & 2))
 {
  flipscreen = ~data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
 if (gfx_bank != ((data & 4) >> 2))
 {
  gfx_bank = ((data & 4) >> 2);
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
void *__fastcall blueprnt_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
int v3; // eax
int v4; // esi
__int64 v5; // rcx
__int64 i; // rax
unsigned __int64 v7; // rbx
unsigned __int8 *v8; // rcx
char *v9; // rax
int v10; // esi
__int64 v11; // r8
__int64 v12; // r9
int v13; // edx
void *result; // rax
int v15; // ebx
__int64 v16; // r12
int v17; // eax
int v18; // er9
char v19; // si
int v20[32]; // [rsp+0h] [rbp-A8h] BYREF
char v21; // [rsp+80h] [rbp-28h] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v4 = v1 % 32;
if ( flipscreen )
{
v3 = v1 / 32;
v4 = 31 - v1 % 32;
}
else
{
v3 = v1 / -32 + 31;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(gfx_bank << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v3),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
if ( flipscreen )
{
v5 = blueprnt_scrollram;
for ( i = 0LL; i != -32; --i )
v20[i + 31] = *(unsigned __int8 *)(v5 + i + 32);
}
else
{
v8 = (unsigned __int8 *)(blueprnt_scrollram + 30LL);
v9 = (char *)v20;
do
{
*(_DWORD *)v9 = -*v8--;
v9 += 4;
}
while ( v9 != &v21 );
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v20, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v7 = 0LL;
do
{
v10 = *(unsigned __int8 *)(spriteram + v7 + 3);
v13 = *(unsigned __int8 *)(spriteram + v7);
v11 = *(_BYTE *)(spriteram + v7 + 2) & 0x40;
v12 = *(_BYTE *)(spriteram + v7 - 2) & 0x80;
if ( flipscreen )
{
v10 = 248 - v10;
v11 = (_DWORD)v11 == 0;
v12 = (_DWORD)v12 == 0;
}
else
{
v13 = 240 - v13;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v7 + 1),
0LL,
v11,
v12,
(unsigned int)(v10 + 2),
(unsigned int)(v13 - 1),
Machine + 776LL,
2LL,
0LL);
v7 += 4LL;
}
while ( spriteram_size > v7 );
}
result = &videoram_size;
v15 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v16 = v15;
do
{
result = (void *)colorram;
v19 = *(_BYTE *)(colorram + v16);
if ( v19 < 0 )
{
v18 = v15 % 32;
if ( flipscreen )
{
v17 = v15 / 32;
LOBYTE(v18) = 31 - v15 % 32;
}
else
{
v17 = v15 / -32 + 31;
}
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(gfx_bank << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v16),
v19 & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v17),
(unsigned __int8)(v20[v17] + 8 * v18),
Machine + 776LL,
2LL,
0LL);
}
--v16;
--v15;
}
while ( v15 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
int v3; // eax
int v4; // esi
__int64 v5; // rcx
__int64 i; // rax
unsigned __int64 v7; // rbx
unsigned __int8 *v8; // rcx
char *v9; // rax
int v10; // esi
__int64 v11; // r8
__int64 v12; // r9
int v13; // edx
void *result; // rax
int v15; // ebx
__int64 v16; // r12
int v17; // eax
int v18; // er9
char v19; // si
int v20[32]; // [rsp+0h] [rbp-A8h] BYREF
char v21; // [rsp+80h] [rbp-28h] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v4 = v1 % 32;
if ( flipscreen )
{
v3 = v1 / 32;
v4 = 31 - v1 % 32;
}
else
{
v3 = v1 / -32 + 31;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(gfx_bank << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v3),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
if ( flipscreen )
{
v5 = blueprnt_scrollram;
for ( i = 0LL; i != -32; --i )
v20[i + 31] = *(unsigned __int8 *)(v5 + i + 32);
}
else
{
v8 = (unsigned __int8 *)(blueprnt_scrollram + 30LL);
v9 = (char *)v20;
do
{
*(_DWORD *)v9 = -*v8--;
v9 += 4;
}
while ( v9 != &v21 );
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v20, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v7 = 0LL;
do
{
v10 = *(unsigned __int8 *)(spriteram + v7 + 3);
v13 = *(unsigned __int8 *)(spriteram + v7);
v11 = *(_BYTE *)(spriteram + v7 + 2) & 0x40;
v12 = *(_BYTE *)(spriteram + v7 - 2) & 0x80;
if ( flipscreen )
{
v10 = 248 - v10;
v11 = (_DWORD)v11 == 0;
v12 = (_DWORD)v12 == 0;
}
else
{
v13 = 240 - v13;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v7 + 1),
0LL,
v11,
v12,
(unsigned int)(v10 + 2),
(unsigned int)(v13 - 1),
Machine + 776LL,
2LL,
0LL);
v7 += 4LL;
}
while ( spriteram_size > v7 );
}
result = &videoram_size;
v15 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v16 = v15;
do
{
result = (void *)colorram;
v19 = *(_BYTE *)(colorram + v16);
if ( v19 < 0 )
{
v18 = v15 % 32;
if ( flipscreen )
{
v17 = v15 / 32;
LOBYTE(v18) = 31 - v15 % 32;
}
else
{
v17 = v15 / -32 + 31;
}
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(gfx_bank << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v16),
v19 & 0x7F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v17),
(unsigned __int8)(v20[v17] + 8 * v18),
Machine + 776LL,
2LL,
0LL);
}
--v16;
--v15;
}
while ( v15 >= 0 );
}
return result;
}

original_code:
void blueprnt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int scroll[32];
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i;
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = blueprnt_scrollram[32-i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -blueprnt_scrollram[30-i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs + 0];
  flipx = spriteram[offs + 2] & 0x40;
  flipy = spriteram[offs + 2 - 4] & 0x80;
  if (flipscreen)
  {
   sx = 248 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    0,
    flipx,flipy,
    2+sx,sy-1,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x80)
  {
   int sx,sy;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,(8*sy+scroll[sx]) & 0xff,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
void blueprnt_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int scroll[32];
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i;
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = blueprnt_scrollram[32-i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -blueprnt_scrollram[30-i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs + 0];
  flipx = spriteram[offs + 2] & 0x40;
  flipy = spriteram[offs + 2 - 4] & 0x80;
  if (flipscreen)
  {
   sx = 248 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    0,
    flipx,flipy,
    2+sx,sy-1,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x80)
  {
   int sx; int sy;
   sx = 31 - offs / 32;
   sy = offs % 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + 256 * gfx_bank,
     colorram[offs] & 0x7f,
     flipscreen,flipscreen,
     8*sx,(8*sy+scroll[sx]) & 0xff,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

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

variable_types: offs int

variable_types:
scroll
int [32]

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


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

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

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

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


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

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

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

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

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

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

variable_types: lastval int


decompiled_code:
void __fastcall jedi_control_w(char a1)
{
jedi_control_num = a1;
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
jedi_control_num = a1;
}

original_code:
void jedi_control_w(offs_t offset,data_t data) {
    jedi_control_num = offset;
}

canonical_original_code:
void jedi_control_w(unsigned int offset, unsigned int data) {
    jedi_control_num = offset;
}


decompiled_code:
__int64 jedi_soundlatch_r()
{
jedi_com_stat &= 0x7Fu;
return jedi_soundlatch;
}

canonical_decompiled_code:
__int64 func3()
{
jedi_com_stat &= 0x7Fu;
return jedi_soundlatch;
}

original_code:
data_t jedi_soundlatch_r(offs_t offset) {
    jedi_com_stat &= 0x7F;
    return jedi_soundlatch;
}

canonical_original_code:
unsigned int jedi_soundlatch_r(unsigned int offset) {
    jedi_com_stat &= 0x7F;
    return jedi_soundlatch;
}


decompiled_code:
__int64 jedi_soundacklatch_r()
{
jedi_com_stat &= 0xBFu;
return jedi_soundacklatch;
}

canonical_decompiled_code:
__int64 func4()
{
jedi_com_stat &= 0xBFu;
return jedi_soundacklatch;
}

original_code:
data_t jedi_soundacklatch_r(offs_t offset) {
    jedi_com_stat &= 0xBF;
    return jedi_soundacklatch;
}

canonical_original_code:
unsigned int jedi_soundacklatch_r(unsigned int offset) {
    jedi_com_stat &= 0xBF;
    return jedi_soundacklatch;
}


decompiled_code:
__int64 jedi_soundstat_r()
{
return jedi_com_stat;
}

canonical_decompiled_code:
__int64 func5()
{
return jedi_com_stat;
}

original_code:
data_t jedi_soundstat_r(offs_t offset) {
    return jedi_com_stat;
}

canonical_original_code:
unsigned int jedi_soundstat_r(unsigned int offset) {
    return jedi_com_stat;
}


decompiled_code:
void __fastcall jedi_vscroll_w(int a1, int a2)
{
jedi_vscroll = a2 | (a1 << 8);
}

canonical_decompiled_code:
void __fastcall func7(int a1, int a2)
{
jedi_vscroll = a2 | (a1 << 8);
}

original_code:
void jedi_vscroll_w(offs_t offset,data_t data)
{
    jedi_vscroll = data | (offset << 8);
}

canonical_original_code:
void jedi_vscroll_w(unsigned int offset, unsigned int data)
{
    jedi_vscroll = data | (offset << 8);
}


decompiled_code:
void __fastcall jedi_hscroll_w(int a1, int a2)
{
jedi_hscroll = a2 | (a1 << 8);
}

canonical_decompiled_code:
void __fastcall func8(int a1, int a2)
{
jedi_hscroll = a2 | (a1 << 8);
}

original_code:
void jedi_hscroll_w(offs_t offset,data_t data)
{
    jedi_hscroll = data | (offset << 8);
}

canonical_original_code:
void jedi_hscroll_w(unsigned int offset, unsigned int data)
{
    jedi_hscroll = data | (offset << 8);
}


decompiled_code:
void __fastcall jedi_video_off_w(__int64 a1, int a2)
{
video_off = a2;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2)
{
video_off = a2;
}

original_code:
void jedi_video_off_w(offs_t offset,data_t data)
{
 video_off = data;
}

canonical_original_code:
void jedi_video_off_w(unsigned int offset, unsigned int data)
{
 video_off = data;
}


decompiled_code:
void __fastcall jedi_PIXIRAM_w(__int64 a1, char a2)
{
smooth_table = a2 & 3;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, char a2)
{
smooth_table = a2 & 3;
}

original_code:
void jedi_PIXIRAM_w(offs_t offset,data_t data)
{
 smooth_table = data & 0x03;
}

canonical_original_code:
void jedi_PIXIRAM_w(unsigned int offset, unsigned int data)
{
 smooth_table = data & 0x03;
}


decompiled_code:
char *__fastcall jedi_rom_banksel_w(__int64 a1, char a2)
{
char *result; // rax
char *v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

result = (char *)memory_region(129LL);
v3 = result;
if ( (a2 & 1) != 0 )
{
cpu_bankbase[1] = result + 0x10000;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v4);
}
}
if ( (a2 & 2) != 0 )
{
cpu_bankbase[1] = v3 + 81920;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v5);
}
}
if ( (a2 & 4) != 0 )
{
cpu_bankbase[1] = v3 + 98304;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v6);
}
}
return result;
}

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

result = (char *)memory_region(129LL);
v3 = result;
if ( (a2 & 1) != 0 )
{
cpu_bankbase[1] = result + 0x10000;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v4);
}
}
if ( (a2 & 2) != 0 )
{
cpu_bankbase[1] = v3 + 81920;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v5);
}
}
if ( (a2 & 4) != 0 )
{
cpu_bankbase[1] = v3 + 98304;
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v6 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v6);
}
}
return result;
}

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

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

variable_types:
RAM
unsigned char *


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

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

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

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

original_code:
void jedi_sound_reset_w(offs_t offset,data_t data)
{
    if (data & 1)
  cpu_set_reset_line(1,0);
    else
  cpu_set_reset_line(1,1);
}

canonical_original_code:
void jedi_sound_reset_w(unsigned int offset, unsigned int data)
{
    if (data & 1)
  cpu_set_reset_line(1,0);
    else
  cpu_set_reset_line(1,1);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 jedi_control_r()
{
unsigned int v0; // edx

if ( !jedi_control_num )
return (unsigned int)readinputport(2LL);
v0 = 0;
if ( jedi_control_num == 2 )
v0 = readinputport(3LL);
return v0;
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v0; // edx

if ( !jedi_control_num )
return (unsigned int)readinputport(2LL);
v0 = 0;
if ( jedi_control_num == 2 )
v0 = readinputport(3LL);
return v0;
}

original_code:
data_t jedi_control_r(offs_t offset) {
    if (jedi_control_num == 0)
        return readinputport (2);
    else if (jedi_control_num == 2)
        return readinputport (3);
    return 0;
}

canonical_original_code:
unsigned int jedi_control_r(unsigned int offset) {
    if (jedi_control_num == 0)
        return readinputport (2);
    else if (jedi_control_num == 2)
        return readinputport (3);
    return 0;
}


decompiled_code:
__int64 jedi_mainstat_r()
{
int v0; // ebx

v0 = ((int)jedi_com_stat >> 1) & 0x60;
return (unsigned __int8)(v0 | input_port_1_r(0LL) & 0x80) | 0x1Bu;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx

v0 = ((int)jedi_com_stat >> 1) & 0x60;
return (unsigned __int8)(v0 | input_port_1_r(0LL) & 0x80) | 0x1Bu;
}

original_code:
data_t jedi_mainstat_r(offs_t offset) {
    unsigned char d;
    d = (jedi_com_stat & 0xC0) >> 1;
    d = d | (input_port_1_r(0) & 0x80);
    d = d | 0x1B;
    return d;
}

canonical_original_code:
unsigned int jedi_mainstat_r(unsigned int offset) {
    unsigned char d;
    d = (jedi_com_stat & 0xC0) >> 1;
    d = d | (input_port_1_r(0) & 0x80);
    d = d | 0x1B;
    return d;
}

variable_types:
d
unsigned char


decompiled_code:
__int64 __fastcall jedi_paletteram_w(unsigned int a1, char a2)
{
unsigned int v2; // eax
__int64 v3; // rdi

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 | 0x400)) << 8;
v3 = a1 & 0x3FF;
return palette_change_color(
v3,
5 * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v2) >> 6) & 7) * ((v2 >> 9) & 7),
5 * ((v2 >> 9) & 7) * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v2) >> 3) & 7),
5 * ((v2 >> 9) & 7) * (*(_BYTE *)(paletteram + (unsigned int)v3) & 7));
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, char a2)
{
unsigned int v2; // eax
__int64 v3; // rdi

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 | 0x400)) << 8;
v3 = a1 & 0x3FF;
return palette_change_color(
v3,
5 * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v2) >> 6) & 7) * ((v2 >> 9) & 7),
5 * ((v2 >> 9) & 7) * (((*(unsigned __int8 *)(paletteram + (unsigned int)v3) | v2) >> 3) & 7),
5 * ((v2 >> 9) & 7) * (*(_BYTE *)(paletteram + (unsigned int)v3) & 7));
}

original_code:
void jedi_paletteram_w(offs_t offset,data_t data)
{
    int r,g,b;
 int bits,intensity;
    unsigned int color;
 paletteram[offset] = data;
 color = paletteram[offset & 0x3FF] | (paletteram[offset | 0x400] << 8);
 intensity = (color >> 9) & 0x07;
 bits = (color >> 6) & 0x07;
 r = 5 * bits * intensity;
 bits = (color >> 3) & 0x07;
 g = 5 * bits * intensity;
 bits = (color >> 0) & 0x07;
 b = 5 * bits * intensity;
 palette_change_color (offset & 0x3ff,r,g,b);
}

canonical_original_code:
void jedi_paletteram_w(unsigned int offset, unsigned int data)
{
    int r; int g; int b;
 int bits; int intensity;
    unsigned int color;
 paletteram[offset] = data;
 color = paletteram[offset & 0x3FF] | (paletteram[offset | 0x400] << 8);
 intensity = (color >> 9) & 0x07;
 bits = (color >> 6) & 0x07;
 r = 5 * bits * intensity;
 bits = (color >> 3) & 0x07;
 g = 5 * bits * intensity;
 bits = (color >> 0) & 0x07;
 b = 5 * bits * intensity;
 palette_change_color (offset & 0x3ff,r,g,b);
}

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: bits int

variable_types: intensity int

variable_types:
color
unsigned int


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

v2 = 2 * (a2 & 0x80);
if ( v2 != jedi_alpha_bank )
{
jedi_alpha_bank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

v2 = 2 * (a2 & 0x80);
if ( v2 != jedi_alpha_bank )
{
jedi_alpha_bank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void jedi_alpha_banksel_w(offs_t offset,data_t data)
{
 if (jedi_alpha_bank != 2*(data & 0x80))
 {
  jedi_alpha_bank = 2*(data & 0x80);
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void jedi_alpha_banksel_w(unsigned int offset, unsigned int data)
{
 if (jedi_alpha_bank != 2*(data & 0x80))
 {
  jedi_alpha_bank = 2*(data & 0x80);
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
__int64 jedi_vh_start()
{
size_t v0; // rbx
void *v1; // rdi
__int64 v2; // rbx
size_t v3; // rbp
void *v4; // rdi
__int64 result; // rax

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
v2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
tmpbitmap = v2;
if ( v2 )
{
v3 = jedi_backgroundram_size;
v4 = malloc(jedi_backgroundram_size);
dirtybuffer2 = v4;
if ( v4 )
{
memset(v4, 1, v3);
tmpbitmap2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
if ( tmpbitmap2 )
{
tmpbitmap3 = bitmap_alloc_depth(256LL, 256LL, 8LL);
if ( tmpbitmap3 )
{
palette_change_color(1024LL, 0LL, 0LL, 0LL);
result = 0LL;
}
else
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
free(dirtybuffer);
free(dirtybuffer2);
result = 1LL;
}
}
else
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
result = 1LL;
}
}
else
{
bitmap_free(v2);
free(dirtybuffer);
result = 1LL;
}
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
size_t v0; // rbx
void *v1; // rdi
__int64 v2; // rbx
size_t v3; // rbp
void *v4; // rdi
__int64 result; // rax

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
v2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
tmpbitmap = v2;
if ( v2 )
{
v3 = jedi_backgroundram_size;
v4 = malloc(jedi_backgroundram_size);
dirtybuffer2 = v4;
if ( v4 )
{
memset(v4, 1, v3);
tmpbitmap2 = bitmap_alloc_depth(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL),
8LL);
if ( tmpbitmap2 )
{
tmpbitmap3 = bitmap_alloc_depth(256LL, 256LL, 8LL);
if ( tmpbitmap3 )
{
palette_change_color(1024LL, 0LL, 0LL, 0LL);
result = 0LL;
}
else
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
free(dirtybuffer);
free(dirtybuffer2);
result = 1LL;
}
}
else
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
free(dirtybuffer2);
result = 1LL;
}
}
else
{
bitmap_free(v2);
free(dirtybuffer);
result = 1LL;
}
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
int jedi_vh_start(void)
{
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
 {
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 if ((dirtybuffer2 = (unsigned char*)malloc(jedi_backgroundram_size)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  return 1;
 }
 memset(dirtybuffer2,1,jedi_backgroundram_size);
 if ((tmpbitmap2 = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 if ((tmpbitmap3 = bitmap_alloc_depth(256,256,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  bitmap_free(tmpbitmap2);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 palette_change_color(1024,0,0,0);
 return 0;
}

canonical_original_code:
int jedi_vh_start()
{
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
 {
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 if ((dirtybuffer2 = (unsigned char *)malloc(jedi_backgroundram_size)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  return 1;
 }
 memset(dirtybuffer2,1,jedi_backgroundram_size);
 if ((tmpbitmap2 = bitmap_alloc_depth(Machine->drv->screen_width,Machine->drv->screen_height,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 if ((tmpbitmap3 = bitmap_alloc_depth(256,256,8)) == 0)
 {
  bitmap_free(tmpbitmap);
  bitmap_free(tmpbitmap2);
  free(dirtybuffer);
  free(dirtybuffer2);
  return 1;
 }
 palette_change_color(1024,0,0,0);
 return 0;
}

return_type: int


decompiled_code:
void jedi_vh_stop()
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
bitmap_free(tmpbitmap3);
free(dirtybuffer);
free(dirtybuffer2);
}

canonical_decompiled_code:
void func18()
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
bitmap_free(tmpbitmap3);
free(dirtybuffer);
free(dirtybuffer2);
}

original_code:
void jedi_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 bitmap_free(tmpbitmap2);
 bitmap_free(tmpbitmap3);
 free(dirtybuffer);
 free(dirtybuffer2);
}


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

if ( a1 > 0xFE )
{
if ( a1 <= 0x1FE )
result = tms5220_data_w(0LL, (unsigned __int8)speech_write_buffer_0);
}
else
{
speech_write_buffer_0 = a2;
}
return result;
}

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

if ( a1 > 0xFE )
{
if ( a1 <= 0x1FE )
result = tms5220_data_w(0LL, (unsigned __int8)speech_write_buffer_0);
}
else
{
speech_write_buffer_0 = a2;
}
return result;
}

original_code:
void jedi_speech_w(offs_t offset,data_t data)
{
    static unsigned char speech_write_buffer;
    if(offset<0xff)
    {
        speech_write_buffer = data;
    }
    else if (offset<0x1ff)
    {
        tms5220_data_w(0,speech_write_buffer);
    }
}

canonical_original_code:
void jedi_speech_w(unsigned int offset, unsigned int data)
{
    static unsigned char speech_write_buffer;
    if(offset<0xff)
    {
        speech_write_buffer = data;
    }
    else if (offset<0x1ff)
    {
        tms5220_data_w(0,speech_write_buffer);
    }
}


decompiled_code:
__int64 jedi_speech_ready_r()
{
return (unsigned __int8)((unsigned int)tms5220_ready_r() == 0) << 7;
}

canonical_decompiled_code:
__int64 func21()
{
return (unsigned __int8)((unsigned int)tms5220_ready_r() == 0) << 7;
}

original_code:
data_t jedi_speech_ready_r(offs_t offset)
{
    return (!tms5220_ready_r())<<7;
}

canonical_original_code:
unsigned int jedi_speech_ready_r(unsigned int offset)
{
    return (!tms5220_ready_r())<<7;
}


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func22(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

variable_types:
file
void *


decompiled_code:
char *__fastcall get_resource_path(const char *a1)
{
sprintf(resource_path_1, "%s/%s", IMAMEBASEPATH, a1);
return resource_path_1;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
sprintf(resource_path_1, "%s/%s", IMAMEBASEPATH, a1);
return resource_path_1;
}

original_code:
const char* get_resource_path(char* file)
{
  static char resource_path[1024];
  sprintf(resource_path, "%s/%s", IMAMEBASEPATH, file);
  return resource_path;
}

canonical_original_code:
char *get_resource_path(char *file)
{
  static char resource_path[1024];
  sprintf(resource_path, "%s/%s", IMAMEBASEPATH, file);
  return resource_path;
}

variable_types:
file
char *

return_type: char *


decompiled_code:
char *__fastcall get_documents_path(const char *a1)
{
sprintf(documents_path_0, "%s/%s", IMAMEBASEPATH, a1);
return documents_path_0;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
sprintf(documents_path_0, "%s/%s", IMAMEBASEPATH, a1);
return documents_path_0;
}

original_code:
const char* get_documents_path(char* file)
{
    static char documents_path[1024];
    sprintf(documents_path, "%s/%s", IMAMEBASEPATH, file);
    return documents_path;
}

canonical_original_code:
char *get_documents_path(char *file)
{
    static char documents_path[1024];
    sprintf(documents_path, "%s/%s", IMAMEBASEPATH, file);
    return documents_path;
}


original_code:
void warlord_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i, j;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int r,g,b;
  r = ((*color_prom >> 2) & 0x01) * 0xff;
  g = ((*color_prom >> 1) & 0x01) * 0xff;
  b = ((*color_prom >> 0) & 0x01) * 0xff;
  if (i >= Machine->drv->total_colors / 2)
  {
   int grey;
   grey = ((r != 0) * 0x4d) + ((g != 0) * 0x96) + ((b != 0) * 0x1c);
   r = g = b = grey;
  }
  *(palette++) = r;
  *(palette++) = g;
  *(palette++) = b;
  color_prom++;
 }
 for (i = 0; i < 8; i++)
 {
  for (j = 0; j < 4; j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i*4+j]) = i*16+j;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i*4+j]) = i*16+j*4;
  }
 }
}

canonical_original_code:
void warlord_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i; int j;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int r; int g; int b;
  r = ((*color_prom >> 2) & 0x01) * 0xff;
  g = ((*color_prom >> 1) & 0x01) * 0xff;
  b = ((*color_prom >> 0) & 0x01) * 0xff;
  if (i >= Machine->drv->total_colors / 2)
  {
   int grey;
   grey = ((r != 0) * 0x4d) + ((g != 0) * 0x96) + ((b != 0) * 0x1c);
   r = g = b = grey;
  }
  *(palette++) = r;
  *(palette++) = g;
  *(palette++) = b;
  color_prom++;
 }
 for (i = 0; i < 8; i++)
 {
  for (j = 0; j < 4; j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i*4+j]) = i*16+j;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i*4+j]) = i*16+j*4;
  }
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: j int

variable_types: grey int


decompiled_code:
__int64 __fastcall warlord_vh_screenrefresh(__int64 a1)
{
int v2; // ebp
int v3; // er12
int v4; // ebx
__int64 v5; // r14
int v6; // esi
_BOOL8 v7; // r8
char v8; // cl
__int64 i; // rbx
int v10; // edi
_BOOL8 v11; // r8
__int64 result; // rax
char v13; // cl

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = input_port_0_r(0LL) & 0x80;
v3 = 4;
if ( !v2 )
v3 = 0;
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
v6 = v4 % 32;
v8 = *(_BYTE *)(videoram + v5) & 0x40;
if ( v2 )
{
v6 = 31 - v4 % 32;
v7 = v8 != 0;
}
else
{
v7 = v8 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v5) & 0x3F,
(v6 >> 4) & 1 | v3 | ((v4 / 32) >> 3) & 2u,
v7);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 0LL; i != 16; ++i )
{
v10 = *(unsigned __int8 *)(spriteram + i + 32);
v13 = *(_BYTE *)(spriteram + i) & 0x40;
if ( v2 )
{
v10 = 248 - v10;
v11 = v13 != 0;
}
else
{
v11 = v13 == 0;
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + i) & 0x3F,
(v10 >> 7) & 1 | v3 | ((248 - *(unsigned __int8 *)(spriteram + i + 16)) >> 6) & 2u,
v11);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2; // ebp
int v3; // er12
int v4; // ebx
__int64 v5; // r14
int v6; // esi
_BOOL8 v7; // r8
char v8; // cl
__int64 i; // rbx
int v10; // edi
_BOOL8 v11; // r8
__int64 result; // rax
char v13; // cl

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = input_port_0_r(0LL) & 0x80;
v3 = 4;
if ( !v2 )
v3 = 0;
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
v6 = v4 % 32;
v8 = *(_BYTE *)(videoram + v5) & 0x40;
if ( v2 )
{
v6 = 31 - v4 % 32;
v7 = v8 != 0;
}
else
{
v7 = v8 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v5) & 0x3F,
(v6 >> 4) & 1 | v3 | ((v4 / 32) >> 3) & 2u,
v7);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 0LL; i != 16; ++i )
{
v10 = *(unsigned __int8 *)(spriteram + i + 32);
v13 = *(_BYTE *)(spriteram + i) & 0x40;
if ( v2 )
{
v10 = 248 - v10;
v11 = v13 != 0;
}
else
{
v11 = v13 == 0;
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + i) & 0x3F,
(v10 >> 7) & 1 | v3 | ((248 - *(unsigned __int8 *)(spriteram + i + 16)) >> 6) & 2u,
v11);
}
return result;
}

original_code:
void warlord_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs, upright_mode, palette;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 upright_mode = input_port_0_r(0) & 0x80;
 palette = ( upright_mode ? 4 : 0);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,color,flipx,flipy;
   dirtybuffer[offs] = 0;
   sy = (offs / 32);
   sx = (offs % 32);
   flipx = !(videoram [offs] & 0x40);
   flipy = videoram [offs] & 0x80;
   if (upright_mode)
   {
    sx = 31 - sx;
    flipx = !flipx;
   }
   color = ((sy & 0x10) >> 3) | ((sx & 0x10) >> 4) | palette;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram [offs] & 0x3f,
     color,
     flipx, flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < 0x10;offs++)
 {
  int sx, sy, flipx, flipy, spritenum, color;
  sx = spriteram [offs + 0x20];
        sy = 248 - spriteram[offs + 0x10];
  flipx = !(spriteram [offs] & 0x40);
  flipy = spriteram [offs] & 0x80;
  if (upright_mode)
  {
   sx = 248 - sx;
   flipx = !flipx;
  }
  spritenum = (spriteram[offs] & 0x3f);
  color = ((sy & 0x80) >> 6) | ((sx & 0x80) >> 7) | palette;
  drawgfx(bitmap,Machine->gfx[1],
    spritenum, color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void warlord_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int upright_mode; int palette;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 upright_mode = input_port_0_r(0) & 0x80;
 palette = ( upright_mode ? 4 : 0);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int color; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sy = (offs / 32);
   sx = (offs % 32);
   flipx = !(videoram [offs] & 0x40);
   flipy = videoram [offs] & 0x80;
   if (upright_mode)
   {
    sx = 31 - sx;
    flipx = !flipx;
   }
   color = ((sy & 0x10) >> 3) | ((sx & 0x10) >> 4) | palette;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram [offs] & 0x3f,
     color,
     flipx, flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < 0x10;offs++)
 {
  int sx; int sy; int flipx; int flipy; int spritenum; int color;
  sx = spriteram [offs + 0x20];
        sy = 248 - spriteram[offs + 0x10];
  flipx = !(spriteram [offs] & 0x40);
  flipy = spriteram [offs] & 0x80;
  if (upright_mode)
  {
   sx = 248 - sx;
   flipx = !flipx;
  }
  spritenum = (spriteram[offs] & 0x3f);
  color = ((sy & 0x80) >> 6) | ((sx & 0x80) >> 7) | palette;
  drawgfx(bitmap,Machine->gfx[1],
    spritenum, color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: palette int

variable_types: sx int

variable_types: sy int

variable_types: color int

variable_types: flipx int

variable_types: flipy int

variable_types: spritenum int


decompiled_code:
__int64 __fastcall warlord_led_w(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

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

original_code:
static void warlord_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset,~data >> 7);
}

canonical_original_code:
static void warlord_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,~data >> 7);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 llander_sh_start()
{
__int64 result; // rax
float v1; // xmm0_4
_WORD *v2; // r8
__int64 i; // rdx
size_t v4; // rbx
void *v5; // rdi

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
volume = 0;
tone_3khz = 0;
tone_6khz = 0;
llander_explosion = 0;
v1 = *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL);
buffer_len = (int)(float)((float)(int)result / v1);
emulation_rate = (int)(float)(v1 * (float)buffer_len);
sample_pos = 0;
multiplier = 0xBB8000000LL * (768000LL / emulation_rate) / emulation_rate + ((768000LL / emulation_rate) << 16);
lfsr_index = 0;
v2 = malloc(0x20000uLL);
lfsr_buffer = (__int64)v2;
if ( v2 )
{
for ( i = 0LL; i != 0x10000; ++i )
v2[i] = (2 * i) | ((unsigned __int8)((int)i >> 14) & ((int)i >> 6) & 1 | (unsigned __int8)(((int)i >> 6) | ((int)i >> 14)) ^ 1) & 1;
channel = mixer_allocate_channel(25LL);
v4 = 2LL * buffer_len;
v5 = malloc(v4);
sample_buffer = (__int64)v5;
if ( v5 )
{
memset(v5, 0, v4);
result = 0LL;
}
else
{
result = 1LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
float v1; // xmm0_4
_WORD *v2; // r8
__int64 i; // rdx
size_t v4; // rbx
void *v5; // rdi

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
volume = 0;
tone_3khz = 0;
tone_6khz = 0;
llander_explosion = 0;
v1 = *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL);
buffer_len = (int)(float)((float)(int)result / v1);
emulation_rate = (int)(float)(v1 * (float)buffer_len);
sample_pos = 0;
multiplier = 0xBB8000000LL * (768000LL / emulation_rate) / emulation_rate + ((768000LL / emulation_rate) << 16);
lfsr_index = 0;
v2 = malloc(0x20000uLL);
lfsr_buffer = (__int64)v2;
if ( v2 )
{
for ( i = 0LL; i != 0x10000; ++i )
v2[i] = (2 * i) | ((unsigned __int8)((int)i >> 14) & ((int)i >> 6) & 1 | (unsigned __int8)(((int)i >> 6) | ((int)i >> 14)) ^ 1) & 1;
channel = mixer_allocate_channel(25LL);
v4 = 2LL * buffer_len;
v5 = malloc(v4);
sample_buffer = (__int64)v5;
if ( v5 )
{
memset(v5, 0, v4);
result = 0LL;
}
else
{
result = 1LL;
}
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int llander_sh_start(const struct MachineSound *msound)
{
 int loop,lfsrtmp,nor1,nor2,bit14,bit6;
 long fraction,remainder;
        if (Machine->sample_rate == 0) return 0;
 volume=0;
 tone_3khz=0;
 tone_6khz=0;
 llander_explosion=0;
 buffer_len = Machine->sample_rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 sample_pos = 0;
 multiplier=768000/(long)emulation_rate;
 remainder=multiplier*768000;
 fraction=remainder<<16;
 fraction/=emulation_rate;
 multiplier=(multiplier<<16)+fraction;
 lfsr_index=0;
 if ((lfsr_buffer = (unsigned short*)malloc(65536*2)) == 0) return 1;
 for(loop=0;loop<65536;loop++)
 {
  lfsrtmp=(short)loop<<1;
  bit14=(loop&0x04000)?1:0;
  bit6=(loop&0x0040)?1:0;
  nor1=(!( bit14 && bit6 ) )?0:1;
  nor2=(!(!bit14 && !bit6 ) )?0:1;
  lfsrtmp|=nor1|nor2;
  lfsr_buffer[loop]=lfsrtmp;
 }
 channel = mixer_allocate_channel(25);
 if ((sample_buffer = (INT16*)malloc(sizeof(INT16)*buffer_len)) == 0) return 1;
 memset(sample_buffer,0,sizeof(INT16)*buffer_len);
 return 0;
}

canonical_original_code:
int llander_sh_start(struct MachineSound *msound)
{
 int loop; int lfsrtmp; int nor1; int nor2; int bit14; int bit6;
 long fraction; long remainder;
        if (Machine->sample_rate == 0) return 0;
 volume=0;
 tone_3khz=0;
 tone_6khz=0;
 llander_explosion=0;
 buffer_len = Machine->sample_rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 sample_pos = 0;
 multiplier=768000/(long)emulation_rate;
 remainder=multiplier*768000;
 fraction=remainder<<16;
 fraction/=emulation_rate;
 multiplier=(multiplier<<16)+fraction;
 lfsr_index=0;
 if ((lfsr_buffer = (unsigned short *)malloc(65536*2)) == 0) return 1;
 for(loop=0;loop<65536;loop++)
 {
  lfsrtmp=(short)loop<<1;
  bit14=(loop&0x04000)?1:0;
  bit6=(loop&0x0040)?1:0;
  nor1=(!( bit14 && bit6 ) )?0:1;
  nor2=(!(!bit14 && !bit6 ) )?0:1;
  lfsrtmp|=nor1|nor2;
  lfsr_buffer[loop]=lfsrtmp;
 }
 channel = mixer_allocate_channel(25);
 if ((sample_buffer = (short *)malloc(sizeof(INT16)*buffer_len)) == 0) return 1;
 memset(sample_buffer,0,sizeof(INT16)*buffer_len);
 return 0;
}

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

variable_types: loop int

variable_types: lfsrtmp int

variable_types: fraction long

variable_types: remainder long


decompiled_code:
void llander_sh_stop()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void llander_sh_stop(void)
{
}

canonical_original_code:
void llander_sh_stop()
{
}


original_code:
void llander_process(INT16 *buffer,int start, int n)
{
 static int sampnum=0;
 static long noisetarg=0,noisecurrent=0;
 static long lastoversampnum=0;
 int loop,sample;
 long oversampnum,loop2;
 for(loop=0;loop<n;loop++)
 {
  oversampnum=(long)(sampnum*multiplier)>>16;
  if(lastoversampnum>>6!=oversampnum>>6)
  {
   lfsr_index=lfsr_buffer[lfsr_index];
   noisetarg=(lfsr_buffer[lfsr_index]&0x4000)?llander_volume[volume]:0x00;
   noisetarg<<=16;
  }
  for(loop2=lastoversampnum;loop2<oversampnum;loop2++)
  {
   noisecurrent+=(noisetarg-noisecurrent)>>7;
  }
  sample=(int)(noisecurrent>>16);
  sample<<=1;
  if(tone_3khz)
  {
   sample+=sinetable[(oversampnum>>2)&0x3f];
  }
  if(tone_6khz)
  {
   sample+=sinetable[(oversampnum>>1)&0x3f];
  }
  if(llander_explosion)
  {
   sample+=(int)(noisecurrent>>(16-2));
  }
  buffer[start+loop] = ((sample<<5)-0x8000);
  sampnum++;
  lastoversampnum=oversampnum;
 }
}

canonical_original_code:
void llander_process(short *buffer, int start, int n)
{
 static int sampnum = 0;
 static long noisetarg = 0; static long noisecurrent = 0;
 static long lastoversampnum = 0;
 int loop; int sample;
 long oversampnum; long loop2;
 for(loop=0;loop<n;loop++)
 {
  oversampnum=(long)(sampnum*multiplier)>>16;
  if(lastoversampnum>>6!=oversampnum>>6)
  {
   lfsr_index=lfsr_buffer[lfsr_index];
   noisetarg=(lfsr_buffer[lfsr_index]&0x4000)?llander_volume[volume]:0x00;
   noisetarg<<=16;
  }
  for(loop2=lastoversampnum;loop2<oversampnum;loop2++)
  {
   noisecurrent+=(noisetarg-noisecurrent)>>7;
  }
  sample=(int)(noisecurrent>>16);
  sample<<=1;
  if(tone_3khz)
  {
   sample+=sinetable[(oversampnum>>2)&0x3f];
  }
  if(tone_6khz)
  {
   sample+=sinetable[(oversampnum>>1)&0x3f];
  }
  if(llander_explosion)
  {
   sample+=(int)(noisecurrent>>(16-2));
  }
  buffer[start+loop] = ((sample<<5)-0x8000);
  sampnum++;
  lastoversampnum=oversampnum;
 }
}

variable_types:
buffer
short *

variable_types: start int

variable_types: n int

variable_types: sampnum int

variable_types: noisetarg long

variable_types: noisecurrent long

variable_types: lastoversampnum long

variable_types: sample int

variable_types: oversampnum long


decompiled_code:
void llander_sh_update_partial()
{
int v0; // ebx

if ( *(_DWORD *)(Machine + 836LL) )
{
v0 = sound_scalebufferpos((unsigned int)buffer_len);
if ( v0 - sample_pos > 9 )
{
llander_process(sample_buffer, sample_pos, v0 - sample_pos);
sample_pos = v0;
}
}
}

canonical_decompiled_code:
void func3()
{
int v0; // ebx

if ( *(_DWORD *)(Machine + 836LL) )
{
v0 = sound_scalebufferpos((unsigned int)buffer_len);
if ( v0 - sample_pos > 9 )
{
func2(sample_buffer, sample_pos, v0 - sample_pos);
sample_pos = v0;
}
}
}

original_code:
void llander_sh_update_partial(void)
{
 int newpos;
 if (Machine->sample_rate == 0) return;
 newpos = sound_scalebufferpos(buffer_len);
 if(newpos-sample_pos<10) return;
 llander_process (sample_buffer, sample_pos, newpos - sample_pos);
 sample_pos = newpos;
}

canonical_original_code:
void llander_sh_update_partial()
{
 int newpos;
 if (Machine->sample_rate == 0) return;
 newpos = sound_scalebufferpos(buffer_len);
 if(newpos-sample_pos<10) return;
 llander_process (sample_buffer, sample_pos, newpos - sample_pos);
 sample_pos = newpos;
}

variable_types: newpos int


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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
if ( sample_pos < buffer_len )
llander_process(sample_buffer, sample_pos, buffer_len - sample_pos);
sample_pos = 0;
result = mixer_play_streamed_sample_16(
(unsigned int)channel,
sample_buffer,
(unsigned int)(2 * buffer_len),
(unsigned int)emulation_rate);
}
return result;
}

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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
if ( sample_pos < buffer_len )
func2(sample_buffer, sample_pos, buffer_len - sample_pos);
sample_pos = 0;
result = mixer_play_streamed_sample_16(
(unsigned int)channel,
sample_buffer,
(unsigned int)(2 * buffer_len),
(unsigned int)emulation_rate);
}
return result;
}

original_code:
void llander_sh_update(void)
{
 if (Machine->sample_rate == 0) return;
 if (sample_pos < buffer_len)
  llander_process (sample_buffer, sample_pos, buffer_len - sample_pos);
 sample_pos = 0;
 mixer_play_streamed_sample_16(channel,sample_buffer,2*buffer_len,emulation_rate);
}

canonical_original_code:
void llander_sh_update()
{
 if (Machine->sample_rate == 0) return;
 if (sample_pos < buffer_len)
  llander_process (sample_buffer, sample_pos, buffer_len - sample_pos);
 sample_pos = 0;
 mixer_play_streamed_sample_16(channel,sample_buffer,2*buffer_len,emulation_rate);
}


decompiled_code:
void llander_snd_reset_w()
{
lfsr_index = 0;
}

canonical_decompiled_code:
void func5()
{
lfsr_index = 0;
}

original_code:
void llander_snd_reset_w(offs_t offset,data_t data)
{
        lfsr_index=0;
}

canonical_original_code:
void llander_snd_reset_w(unsigned int offset, unsigned int data)
{
        lfsr_index=0;
}

variable_types:
offset
unsigned int


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

llander_sh_update_partial();
volume = a2 & 7;
tone_3khz = a2 & 0x10;
result = a2 & 0x20;
tone_6khz = a2 & 0x20;
llander_explosion = a2 & 8;
return result;
}

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

func3();
volume = a2 & 7;
tone_3khz = a2 & 0x10;
result = a2 & 0x20;
tone_6khz = a2 & 0x20;
llander_explosion = a2 & 8;
return result;
}

original_code:
void llander_sounds_w(offs_t offset,data_t data)
{
 llander_sh_update_partial();
 volume = data & 0x07;
 tone_3khz = data & 0x10;
 tone_6khz = data & 0x20;
 llander_explosion = data & 0x08;
}

canonical_original_code:
void llander_sounds_w(unsigned int offset, unsigned int data)
{
 llander_sh_update_partial();
 volume = data & 0x07;
 tone_3khz = data & 0x10;
 tone_6khz = data & 0x20;
 llander_explosion = data & 0x08;
}

variable_types:
data
unsigned int


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

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

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

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


decompiled_code:
__int64 __fastcall decode_byte(unsigned __int8 a1, _BYTE *a2)
{
char v3; // di
_BYTE *v4; // r9
_BYTE *v5; // rdx
unsigned int v6; // esi
char v7; // di

v3 = (char)a2;
v4 = a2 + 8;
v5 = a2;
v6 = 0;
v7 = v3 + 7;
do
{
v6 |= (((int)a1 >> *v5) & 1) << (v7 - (_BYTE)v5);
++v5;
}
while ( v5 != v4 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, _BYTE *a2)
{
char v3; // di
_BYTE *v4; // r9
_BYTE *v5; // rdx
unsigned int v6; // esi
char v7; // di

v3 = (char)a2;
v4 = a2 + 8;
v5 = a2;
v6 = 0;
v7 = v3 + 7;
do
{
v6 |= (((int)a1 >> *v5) & 1) << (v7 - (_BYTE)v5);
++v5;
}
while ( v5 != v4 );
return v6;
}

original_code:
static unsigned char decode_byte(unsigned char src, unsigned char *bitp)
{
 unsigned char ret, i;
 ret = 0;
 for (i=0; i<8; i++)
  ret |= (((src >> bitp[i]) & 1) << (7-i));
 return ret;
}

canonical_original_code:
static unsigned char decode_byte(unsigned char src, unsigned char *bitp)
{
 unsigned char ret; unsigned char i;
 ret = 0;
 for (i=0; i<8; i++)
  ret |= (((src >> bitp[i]) & 1) << (7-i));
 return ret;
}

variable_types:
src
unsigned char

variable_types:
bitp
unsigned char *

variable_types:
ret
unsigned char

variable_types:
i
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall decode_word(unsigned __int16 a1, _BYTE *a2)
{
char v3; // di
_BYTE *v4; // r9
_BYTE *v5; // rdx
unsigned int v6; // esi
char v7; // di

v3 = (char)a2;
v4 = a2 + 16;
v5 = a2;
v6 = 0;
v7 = v3 + 15;
do
{
v6 |= (((int)a1 >> *v5) & 1) << (v7 - (_BYTE)v5);
++v5;
}
while ( v5 != v4 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, _BYTE *a2)
{
char v3; // di
_BYTE *v4; // r9
_BYTE *v5; // rdx
unsigned int v6; // esi
char v7; // di

v3 = (char)a2;
v4 = a2 + 16;
v5 = a2;
v6 = 0;
v7 = v3 + 15;
do
{
v6 |= (((int)a1 >> *v5) & 1) << (v7 - (_BYTE)v5);
++v5;
}
while ( v5 != v4 );
return v6;
}

original_code:
static unsigned short decode_word(unsigned short src, unsigned char *bitp)
{
 unsigned short ret, i;
 ret=0;
 for (i=0; i<16; i++)
  ret |= (((src >> bitp[i]) & 1) << (15-i));
 return ret;
}

canonical_original_code:
static unsigned short decode_word(unsigned short src, unsigned char *bitp)
{
 unsigned short ret; unsigned short i;
 ret=0;
 for (i=0; i<16; i++)
  ret |= (((src >> bitp[i]) & 1) << (15-i));
 return ret;
}

variable_types:
src
unsigned short

variable_types:
ret
unsigned short

variable_types:
i
unsigned short

return_type: unsigned short


decompiled_code:
__int64 bjtwin_vh_start()
{
__int64 v0; // rax
__int64 result; // rax

dirtybuffer = malloc(bjtwin_txvideoram_size >> 1);
v0 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
tmpbitmap = v0;
if ( dirtybuffer && v0 )
{
bjtwin_spriteram = bjtwin_workram + 0x8000LL;
result = 0LL;
}
else
{
if ( v0 )
bitmap_free(v0);
result = 1LL;
if ( dirtybuffer )
{
free(dirtybuffer);
result = 1LL;
}
}
return result;
}

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

dirtybuffer = malloc(bjtwin_txvideoram_size >> 1);
v0 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
tmpbitmap = v0;
if ( dirtybuffer && v0 )
{
bjtwin_spriteram = bjtwin_workram + 0x8000LL;
result = 0LL;
}
else
{
if ( v0 )
bitmap_free(v0);
result = 1LL;
if ( dirtybuffer )
{
free(dirtybuffer);
result = 1LL;
}
}
return result;
}

original_code:
int bjtwin_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(bjtwin_txvideoram_size/2);
 tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height);
 if (!dirtybuffer || !tmpbitmap)
 {
  if (tmpbitmap) bitmap_free(tmpbitmap);
  if (dirtybuffer) free(dirtybuffer);
  return 1;
 }
 bjtwin_spriteram = bjtwin_workram + 0x8000;
 return 0;
}

canonical_original_code:
int bjtwin_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(bjtwin_txvideoram_size/2);
 tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height);
 if (!dirtybuffer || !tmpbitmap)
 {
  if (tmpbitmap) bitmap_free(tmpbitmap);
  if (dirtybuffer) free(dirtybuffer);
  return 1;
 }
 bjtwin_spriteram = bjtwin_workram + 0x8000;
 return 0;
}


decompiled_code:
void bjtwin_vh_stop()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
}

canonical_decompiled_code:
void func5()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
}

original_code:
void bjtwin_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 free(dirtybuffer);
 dirtybuffer = 0;
 tmpbitmap = 0;
}

canonical_original_code:
void bjtwin_vh_stop()
{
 bitmap_free(tmpbitmap);
 free(dirtybuffer);
 dirtybuffer = 0;
 tmpbitmap = 0;
}


decompiled_code:
__int64 __fastcall bjtwin_paletteram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // esi
int v4; // eax
int v5; // esi

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
v4 = (v3 >> 3) & 1 | (v3 >> 11) & 0x1E;
LODWORD(v2) = (v3 >> 2) & 1 | (v3 >> 7) & 0x1E;
v5 = (v3 >> 3) & 0x1E | (v3 >> 1) & 1;
return palette_change_color(
a1 >> 1,
(8 * v4) | (unsigned int)(v4 >> 2),
(8 * (_DWORD)v2) | (unsigned int)((int)v2 >> 2),
(v5 >> 2) | (unsigned int)(8 * v5));
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // esi
int v4; // eax
int v5; // esi

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
v4 = (v3 >> 3) & 1 | (v3 >> 11) & 0x1E;
LODWORD(v2) = (v3 >> 2) & 1 | (v3 >> 7) & 0x1E;
v5 = (v3 >> 3) & 0x1E | (v3 >> 1) & 1;
return palette_change_color(
a1 >> 1,
(8 * v4) | (unsigned int)(v4 >> 2),
(8 * (_DWORD)v2) | (unsigned int)((int)v2 >> 2),
(v5 >> 2) | (unsigned int)(8 * v5));
}

original_code:
void bjtwin_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = ((newword >> 11) & 0x1e) | ((newword >> 3) & 0x01);
 g = ((newword >> 7) & 0x1e) | ((newword >> 2) & 0x01);
 b = ((newword >> 3) & 0x1e) | ((newword >> 1) & 0x01);
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void bjtwin_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = ((newword >> 11) & 0x1e) | ((newword >> 3) & 0x01);
 g = ((newword >> 7) & 0x1e) | ((newword >> 2) & 0x01);
 b = ((newword >> 3) & 0x1e) | ((newword >> 1) & 0x01);
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: oldword int

variable_types: newword int


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

result = (void *)(a2 & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 1;
result = memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
}
return result;
}

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

result = (void *)(a2 & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 1;
result = memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
}
return result;
}

original_code:
void bjtwin_flipscreen_w(offs_t offset,data_t data)
{
 if ((data & 1) != flipscreen)
 {
  flipscreen = data & 1;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
}

canonical_original_code:
void bjtwin_flipscreen_w(unsigned int offset, unsigned int data)
{
 if ((data & 1) != flipscreen)
 {
  flipscreen = data & 1;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
}


decompiled_code:
__int64 __fastcall bjtwin_vh_screenrefresh(__int64 a1, _QWORD *a2)
{
int v2; // ebx
int v3; // edx
__int64 v4; // rcx
_QWORD *v5; // rax
__int64 i; // rax
_QWORD *v7; // rdx
int v8; // ebp
__int64 v9; // r12
__int64 v10; // r10
__int64 v11; // rdi
unsigned int v12; // esi
int v13; // ecx
int v14; // edx
int v15; // edi
int v16; // er10
unsigned __int16 v17; // cx
int v18; // eax
__int64 j; // r15
__int16 k; // r12
__int64 result; // rax
int v22; // ebp
int v23; // ebx
__int16 v24; // r13
unsigned __int16 v25; // ax
__int64 v26; // [rsp+8h] [rbp-50h]
__int16 v27; // [rsp+10h] [rbp-48h]
__int16 v28; // [rsp+14h] [rbp-44h]
int v29; // [rsp+18h] [rbp-40h]
int v30; // [rsp+1Ch] [rbp-3Ch]

v26 = a1;
v2 = (*bjtwin_videocontrol & 0xF) << 11;
palette_init_used_colors();
v3 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v3 >= 0 )
{
v4 = 2 * v3;
a1 = (__int64)&palette_used_colors;
a2 = &bjtwin_txvideoram;
do
{
v5 = (_QWORD *)(palette_used_colors + (unsigned __int8)(16 * (*(_WORD *)(bjtwin_txvideoram + v4) >> 12)));
*v5 = 0x303030303030303LL;
v5[1] = 0x303030303030303LL;
v4 -= 2LL;
--v3;
}
while ( v3 >= 0 );
}
for ( i = 0LL; i != 4096; i += 16LL )
{
v7 = (_QWORD *)bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + i) )
{
a2 = &palette_used_colors;
v7 = (_QWORD *)(palette_used_colors + 16 * (*(unsigned __int16 *)(bjtwin_spriteram + i + 14) + 16));
a1 = 0x303030303030303LL;
*v7 = 0x303030303030303LL;
v7[1] = 0x303030303030303LL;
}
}
if ( palette_recalc(a1, a2, v7, &bjtwin_spriteram) || oldbgstart_2 != v2 )
{
oldbgstart_2 = v2;
memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
}
v8 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v8 >= 0 )
{
v9 = v8;
do
{
if ( *((_BYTE *)dirtybuffer + v9) )
{
v15 = v8 / 32;
v16 = v8 % 32;
v17 = *(_WORD *)(bjtwin_txvideoram + 2 * v8);
v18 = ((int)v17 >> 11) & 1;
if ( flipscreen )
{
v15 = 47 - v8 / 32;
v16 = 31 - v8 % 32;
}
v10 = (unsigned int)(8 * v16);
v11 = (unsigned int)(8 * v15);
v12 = (int)v17 >> 12;
v13 = v17 & 0x7FF;
v14 = v2;
if ( !v18 )
v14 = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v18 + 512),
(unsigned int)(v13 + v14),
v12,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v11,
v10,
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + v9) = 0;
}
--v9;
--v8;
}
while ( v8 >= 0 );
}
copybitmap(v26, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( j = 14LL; j != 4110; j += 16LL )
{
result = bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + j - 14) )
{
v28 = (*(_WORD *)(bjtwin_spriteram + j - 6) & 0x1FF) + 64;
v24 = *(_WORD *)(bjtwin_spriteram + j - 2) & 0x1FF;
v22 = *(unsigned __int16 *)(bjtwin_spriteram + j - 8);
v25 = *(_WORD *)(bjtwin_spriteram + j - 12);
v30 = (v25 & 0xF) + 1;
v29 = (unsigned __int16)((v25 >> 4) + 1);
v27 = 16;
if ( flipscreen )
{
v28 = 367 - ((*(_WORD *)(bjtwin_spriteram + j - 6) & 0x1FF) + 64);
v24 = 239 - v24;
v27 = -16;
}
v23 = (v25 & 0xF) + 1;
for ( k = v28; ; k = v28 )
{
while ( 1 )
{
result = drawgfx(
v26,
*(_QWORD *)(Machine + 528LL),
v22++ & 0x1FFF,
*(unsigned __int16 *)(bjtwin_spriteram + j),
(unsigned int)flipscreen,
(unsigned int)flipscreen,
k & 0x1FF,
v24 & 0x1FF,
Machine + 776LL,
2LL,
15LL);
if ( !--v23 )
break;
k += v27;
}
v24 += v27;
if ( !--v29 )
break;
v23 = v30;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2)
{
int v2; // ebx
int v3; // edx
__int64 v4; // rcx
_QWORD *v5; // rax
__int64 i; // rax
_QWORD *v7; // rdx
int v8; // ebp
__int64 v9; // r12
__int64 v10; // r10
__int64 v11; // rdi
unsigned int v12; // esi
int v13; // ecx
int v14; // edx
int v15; // edi
int v16; // er10
unsigned __int16 v17; // cx
int v18; // eax
__int64 j; // r15
__int16 k; // r12
__int64 result; // rax
int v22; // ebp
int v23; // ebx
__int16 v24; // r13
unsigned __int16 v25; // ax
__int64 v26; // [rsp+8h] [rbp-50h]
__int16 v27; // [rsp+10h] [rbp-48h]
__int16 v28; // [rsp+14h] [rbp-44h]
int v29; // [rsp+18h] [rbp-40h]
int v30; // [rsp+1Ch] [rbp-3Ch]

v26 = a1;
v2 = (*bjtwin_videocontrol & 0xF) << 11;
palette_init_used_colors();
v3 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v3 >= 0 )
{
v4 = 2 * v3;
a1 = (__int64)&palette_used_colors;
a2 = &bjtwin_txvideoram;
do
{
v5 = (_QWORD *)(palette_used_colors + (unsigned __int8)(16 * (*(_WORD *)(bjtwin_txvideoram + v4) >> 12)));
*v5 = 0x303030303030303LL;
v5[1] = 0x303030303030303LL;
v4 -= 2LL;
--v3;
}
while ( v3 >= 0 );
}
for ( i = 0LL; i != 4096; i += 16LL )
{
v7 = (_QWORD *)bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + i) )
{
a2 = &palette_used_colors;
v7 = (_QWORD *)(palette_used_colors + 16 * (*(unsigned __int16 *)(bjtwin_spriteram + i + 14) + 16));
a1 = 0x303030303030303LL;
*v7 = 0x303030303030303LL;
v7[1] = 0x303030303030303LL;
}
}
if ( palette_recalc(a1, a2, v7, &bjtwin_spriteram) || oldbgstart_2 != v2 )
{
oldbgstart_2 = v2;
memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
}
v8 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v8 >= 0 )
{
v9 = v8;
do
{
if ( *((_BYTE *)dirtybuffer + v9) )
{
v15 = v8 / 32;
v16 = v8 % 32;
v17 = *(_WORD *)(bjtwin_txvideoram + 2 * v8);
v18 = ((int)v17 >> 11) & 1;
if ( flipscreen )
{
v15 = 47 - v8 / 32;
v16 = 31 - v8 % 32;
}
v10 = (unsigned int)(8 * v16);
v11 = (unsigned int)(8 * v15);
v12 = (int)v17 >> 12;
v13 = v17 & 0x7FF;
v14 = v2;
if ( !v18 )
v14 = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v18 + 512),
(unsigned int)(v13 + v14),
v12,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v11,
v10,
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + v9) = 0;
}
--v9;
--v8;
}
while ( v8 >= 0 );
}
copybitmap(v26, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( j = 14LL; j != 4110; j += 16LL )
{
result = bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + j - 14) )
{
v28 = (*(_WORD *)(bjtwin_spriteram + j - 6) & 0x1FF) + 64;
v24 = *(_WORD *)(bjtwin_spriteram + j - 2) & 0x1FF;
v22 = *(unsigned __int16 *)(bjtwin_spriteram + j - 8);
v25 = *(_WORD *)(bjtwin_spriteram + j - 12);
v30 = (v25 & 0xF) + 1;
v29 = (unsigned __int16)((v25 >> 4) + 1);
v27 = 16;
if ( flipscreen )
{
v28 = 367 - ((*(_WORD *)(bjtwin_spriteram + j - 6) & 0x1FF) + 64);
v24 = 239 - v24;
v27 = -16;
}
v23 = (v25 & 0xF) + 1;
for ( k = v28; ; k = v28 )
{
while ( 1 )
{
result = drawgfx(
v26,
*(_QWORD *)(Machine + 528LL),
v22++ & 0x1FFF,
*(unsigned __int16 *)(bjtwin_spriteram + j),
(unsigned int)flipscreen,
(unsigned int)flipscreen,
k & 0x1FF,
v24 & 0x1FF,
Machine + 776LL,
2LL,
15LL);
if ( !--v23 )
break;
k += v27;
}
v24 += v27;
if ( !--v29 )
break;
v23 = v30;
}
}
}
return result;
}

original_code:
void bjtwin_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 static int oldbgstart = -1;
 int offs, bgstart;
 bgstart = 2048 * ((*(UINT16 *)(&bjtwin_videocontrol[0])) & 0x0f);
 palette_init_used_colors();
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  int color = ((*(UINT16 *)(&bjtwin_txvideoram[offs*2])) >> 12);
  memset(&palette_used_colors[16 * color],(1|2),16);
 }
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(UINT16 *)(&bjtwin_spriteram[offs])) != 0)
   memset(&palette_used_colors[256 + 16*(*(UINT16 *)(&bjtwin_spriteram[offs+14]))],(1|2),16);
 }
 if (palette_recalc() || (oldbgstart != bgstart))
 {
  oldbgstart = bgstart;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx = offs / 32;
   int sy = offs % 32;
   int tilecode = (*(UINT16 *)(&bjtwin_txvideoram[offs*2]));
   int bank = (tilecode & 0x800) ? 1 : 0;
   if (flipscreen)
   {
    sx = 47-sx;
    sy = 31-sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[bank],
     (tilecode & 0x7ff) + ((bank) ? bgstart : 0),
     tilecode >> 12,
     flipscreen, flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(UINT16 *)(&bjtwin_spriteram[offs])) != 0)
  {
   int sx = ((*(UINT16 *)(&bjtwin_spriteram[offs+8])) & 0x1ff) + 64;
   int sy = ((*(UINT16 *)(&bjtwin_spriteram[offs+12])) & 0x1ff);
   int tilecode = (*(UINT16 *)(&bjtwin_spriteram[offs+6]));
   int xx = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) & 0x0f) + 1;
   int yy = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) >> 4) + 1;
   int width = xx;
   int delta = 16;
   int startx = sx;
   if (flipscreen)
   {
    sx = 367 - sx;
    sy = 239 - sy;
    delta = -16;
    startx = sx;
   }
   do
   {
    do
    {
     drawgfx(bitmap,Machine->gfx[2],
       tilecode & 0x1fff,
       (*(UINT16 *)(&bjtwin_spriteram[offs+14])),
       flipscreen, flipscreen,
       sx & 0x1ff,sy & 0x1ff,
       &Machine->visible_area,TRANSPARENCY_PEN,15);
     tilecode++;
     sx += delta;
    } while (--xx);
    sy += delta;
    sx = startx;
    xx = width;
   } while (--yy);
  }
 }
}

canonical_original_code:
void bjtwin_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 static int oldbgstart = -1;
 int offs; int bgstart;
 bgstart = 2048 * ((*(unsigned short *)(&bjtwin_videocontrol[0])) & 0x0f);
 palette_init_used_colors();
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  int color = ((*(UINT16 *)(&bjtwin_txvideoram[offs*2])) >> 12);
  memset(&palette_used_colors[16 * color],(1|2),16);
 }
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(unsigned short *)(&bjtwin_spriteram[offs])) != 0)
   memset(&palette_used_colors[256 + 16*(*(unsigned short *)(&bjtwin_spriteram[offs+14]))],(1|2),16);
 }
 if (palette_recalc() || (oldbgstart != bgstart))
 {
  oldbgstart = bgstart;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx = offs / 32;
   int sy = offs % 32;
   int tilecode = (*(UINT16 *)(&bjtwin_txvideoram[offs*2]));
   int bank = (tilecode & 0x800) ? 1 : 0;
   if (flipscreen)
   {
    sx = 47-sx;
    sy = 31-sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[bank],
     (tilecode & 0x7ff) + ((bank) ? bgstart : 0),
     tilecode >> 12,
     flipscreen, flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(unsigned short *)(&bjtwin_spriteram[offs])) != 0)
  {
   int sx = ((*(UINT16 *)(&bjtwin_spriteram[offs+8])) & 0x1ff) + 64;
   int sy = ((*(UINT16 *)(&bjtwin_spriteram[offs+12])) & 0x1ff);
   int tilecode = (*(UINT16 *)(&bjtwin_spriteram[offs+6]));
   int xx = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) & 0x0f) + 1;
   int yy = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) >> 4) + 1;
   int width = xx;
   int delta = 16;
   int startx = sx;
   if (flipscreen)
   {
    sx = 367 - sx;
    sy = 239 - sy;
    delta = -16;
    startx = sx;
   }
   do
   {
    do
    {
     drawgfx(bitmap,Machine->gfx[2],
       tilecode & 0x1fff,
       (*(unsigned short *)(&bjtwin_spriteram[offs+14])),
       flipscreen, flipscreen,
       sx & 0x1ff,sy & 0x1ff,
       &Machine->visible_area,TRANSPARENCY_PEN,15);
     tilecode++;
     sx += delta;
    } while (--xx);
    sy += delta;
    sx = startx;
    xx = width;
   } while (--yy);
  }
 }
}

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

variable_types: oldbgstart int

variable_types: offs int

variable_types: bgstart int

variable_types: color int

variable_types: sx int

variable_types: sy int

variable_types: tilecode int

variable_types: bank int

variable_types: xx int

variable_types: yy int

variable_types: width int

variable_types: delta int

variable_types: startx int


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

if ( (a2 & 0xFF0000) == 0 )
{
switch ( a1 )
{
case 0:
result = OKIM6295_set_bank_base(0LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 2:
result = OKIM6295_set_bank_base(0LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 4:
result = OKIM6295_set_bank_base(0LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 6:
result = OKIM6295_set_bank_base(0LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 8:
result = OKIM6295_set_bank_base(1LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 10:
result = OKIM6295_set_bank_base(1LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 12:
result = OKIM6295_set_bank_base(1LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 14:
result = OKIM6295_set_bank_base(1LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
default:
return result;
}
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
switch ( a1 )
{
case 0:
result = OKIM6295_set_bank_base(0LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 2:
result = OKIM6295_set_bank_base(0LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 4:
result = OKIM6295_set_bank_base(0LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 6:
result = OKIM6295_set_bank_base(0LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 8:
result = OKIM6295_set_bank_base(1LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 10:
result = OKIM6295_set_bank_base(1LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 12:
result = OKIM6295_set_bank_base(1LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 14:
result = OKIM6295_set_bank_base(1LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
default:
return result;
}
}
return result;
}

original_code:
void bjtwin_oki6295_bankswitch_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  switch (offset)
  {
   case 0x00: OKIM6295_set_bank_base(0, 0, (data & 0x0f) * 0x10000); break;
   case 0x02: OKIM6295_set_bank_base(0, 1, (data & 0x0f) * 0x10000); break;
   case 0x04: OKIM6295_set_bank_base(0, 2, (data & 0x0f) * 0x10000); break;
   case 0x06: OKIM6295_set_bank_base(0, 3, (data & 0x0f) * 0x10000); break;
   case 0x08: OKIM6295_set_bank_base(1, 0, (data & 0x0f) * 0x10000); break;
   case 0x0a: OKIM6295_set_bank_base(1, 1, (data & 0x0f) * 0x10000); break;
   case 0x0c: OKIM6295_set_bank_base(1, 2, (data & 0x0f) * 0x10000); break;
   case 0x0e: OKIM6295_set_bank_base(1, 3, (data & 0x0f) * 0x10000); break;
  }
 }
}

canonical_original_code:
void bjtwin_oki6295_bankswitch_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  switch (offset)
  {
   case 0x00: OKIM6295_set_bank_base(0, 0, (data & 0x0f) * 0x10000); break;
   case 0x02: OKIM6295_set_bank_base(0, 1, (data & 0x0f) * 0x10000); break;
   case 0x04: OKIM6295_set_bank_base(0, 2, (data & 0x0f) * 0x10000); break;
   case 0x06: OKIM6295_set_bank_base(0, 3, (data & 0x0f) * 0x10000); break;
   case 0x08: OKIM6295_set_bank_base(1, 0, (data & 0x0f) * 0x10000); break;
   case 0x0a: OKIM6295_set_bank_base(1, 1, (data & 0x0f) * 0x10000); break;
   case 0x0c: OKIM6295_set_bank_base(1, 2, (data & 0x0f) * 0x10000); break;
   case 0x0e: OKIM6295_set_bank_base(1, 3, (data & 0x0f) * 0x10000); break;
  }
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall bjtwin_address_map_bg0(unsigned __int64 a1)
{
return (a1 >> 16) & 4 | (a1 >> 10) & 2 | (a1 >> 2) & 1;
}

original_code:
unsigned long bjtwin_address_map_bg0(unsigned long addr)
{
   return ((addr&0x00004)>> 2) | ((addr&0x00800)>> 10) | ((addr&0x40000)>>16);
}

variable_types:
addr
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall bjtwin_address_map_sprites(unsigned __int64 a1)
{
return (a1 >> 16) & 2 | (a1 >> 4) & 1;
}

original_code:
unsigned long bjtwin_address_map_sprites(unsigned long addr)
{
   return ((addr&0x00010)>> 4) | ((addr&0x20000)>>16);
}


decompiled_code:
_BYTE *init_bjtwin()
{
__int64 v0; // rbp
unsigned __int64 i; // rbx
__int64 v2; // rax
__int64 v3; // rbp
unsigned __int64 j; // rbx
__int64 v5; // rax
__int16 v6; // ax
__int64 v7; // rax
_BYTE *v8; // rdx
__int64 v9; // rcx
_BYTE *v10; // rax
__int64 v11; // rax
_BYTE *v12; // rdx
__int64 v13; // rcx
_BYTE *result; // rax

v0 = memory_region(138LL);
for ( i = 0LL; (int)memory_region_length(138LL) > (int)i; ++i )
{
v2 = bjtwin_address_map_bg0(i);
*(_BYTE *)(v0 + i) = decode_byte(*(_BYTE *)(v0 + i), &decode_data_bg_1[8 * v2]);
}
v3 = memory_region(139LL);
for ( j = 0LL; (int)memory_region_length(139LL) > (int)j; j += 2LL )
{
v5 = bjtwin_address_map_sprites(j);
v6 = decode_word(
*(unsigned __int8 *)(v3 + j + 1) + (*(unsigned __int8 *)(v3 + j) << 8),
&decode_data_sprite_0[16 * v5]);
*(_BYTE *)(v3 + j) = HIBYTE(v6);
*(_BYTE *)(v3 + j + 1) = v6;
}
v7 = memory_region(146LL);
v8 = (_BYTE *)(v7 + 1024);
v9 = v7 + 1049600;
do
{
v10 = v8 - 1024;
do
{
*v10 = 0;
v10[3] = 0;
v10 += 8;
}
while ( v10 != v8 );
v8 += 0x10000;
}
while ( v8 != (_BYTE *)v9 );
v11 = memory_region(147LL);
v12 = (_BYTE *)(v11 + 1024);
v13 = v11 + 1049600;
do
{
result = v12 - 1024;
do
{
*result = 0;
result[3] = 0;
result += 8;
}
while ( result != v12 );
v12 += 0x10000;
}
while ( v12 != (_BYTE *)v13 );
return result;
}

variable_types:
rom
unsigned char *

variable_types: A int

variable_types: i int

variable_types:
tmp
unsigned short


decompiled_code:
void __fastcall vigilant_horiz_scroll_w(int a1, int a2)
{
if ( a1 )
horiz_scroll_high = (a2 & 1) << 8;
else
horiz_scroll_low = a2;
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
if ( a1 )
horiz_scroll_high = (a2 & 1) << 8;
else
horiz_scroll_low = a2;
}

original_code:
void vigilant_horiz_scroll_w(offs_t offset,data_t data)
{
 if (offset==0)
  horiz_scroll_low = data;
 else
  horiz_scroll_high = (data & 0x01) * 256;
}

canonical_original_code:
void vigilant_horiz_scroll_w(unsigned int offset, unsigned int data)
{
 if (offset==0)
  horiz_scroll_low = data;
 else
  horiz_scroll_high = (data & 0x01) * 256;
}


decompiled_code:
void __fastcall vigilant_rear_horiz_scroll_w(int a1, int a2)
{
if ( a1 )
rear_horiz_scroll_high = (a2 & 7) << 8;
else
rear_horiz_scroll_low = a2;
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
if ( a1 )
rear_horiz_scroll_high = (a2 & 7) << 8;
else
rear_horiz_scroll_low = a2;
}

original_code:
void vigilant_rear_horiz_scroll_w(offs_t offset,data_t data)
{
 if (offset==0)
  rear_horiz_scroll_low = data;
 else
  rear_horiz_scroll_high = (data & 0x07) * 256;
}

canonical_original_code:
void vigilant_rear_horiz_scroll_w(unsigned int offset, unsigned int data)
{
 if (offset==0)
  rear_horiz_scroll_low = data;
 else
  rear_horiz_scroll_high = (data & 0x07) * 256;
}


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

result = a2 & 0x40;
rear_disable = a2 & 0x40;
rear_color = a2 & 0xD;
return result;
}

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

result = a2 & 0x40;
rear_disable = a2 & 0x40;
rear_color = a2 & 0xD;
return result;
}

original_code:
void vigilant_rear_color_w(offs_t offset,data_t data)
{
 rear_disable = data & 0x40;
 rear_color = (data & 0x0d);
}

canonical_original_code:
void vigilant_rear_color_w(unsigned int offset, unsigned int data)
{
 rear_disable = data & 0x40;
 rear_color = (data & 0x0d);
}


decompiled_code:
__int64 vigilant_vh_start()
{
unsigned int v0; // edx

generic_vh_start();
bg_bitmap = bitmap_alloc(1536LL, 256LL);
v0 = 0;
if ( !bg_bitmap )
{
generic_vh_stop(1536LL, 256LL, 0LL);
v0 = 1;
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // edx

generic_vh_start();
bg_bitmap = bitmap_alloc(1536LL, 256LL);
v0 = 0;
if ( !bg_bitmap )
{
generic_vh_stop(1536LL, 256LL, 0LL);
v0 = 1;
}
return v0;
}

original_code:
int vigilant_vh_start(void)
{
 generic_vh_start();
 if ((bg_bitmap = bitmap_alloc(512*3,256)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int vigilant_vh_start()
{
 generic_vh_start();
 if ((bg_bitmap = bitmap_alloc(512*3,256)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall vigilant_vh_stop(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rdx

v2 = bg_bitmap;
bitmap_free(bg_bitmap);
return generic_vh_stop(v2, a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rdx

v2 = bg_bitmap;
bitmap_free(bg_bitmap);
return generic_vh_stop(v2, a2, v3);
}

original_code:
void vigilant_vh_stop(void)
{
 bitmap_free(bg_bitmap);
 generic_vh_stop();
}

canonical_original_code:
void vigilant_vh_stop()
{
 bitmap_free(bg_bitmap);
 generic_vh_stop();
}