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

result = 0xFF000000FF000000LL;
*a1 = 0xFF000000FF000000LL;
a1[1] = 0xFFFF000000FFFF00LL;
a1[2] = -16711936LL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1)
{
unsigned __int64 result; // rax

result = 0xFF000000FF000000LL;
*a1 = 0xFF000000FF000000LL;
a1[1] = 0xFFFF000000FFFF00LL;
a1[2] = -16711936LL;
return result;
}

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

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


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

result = ~(unsigned __int8)input_mux & 0xFFFFFF80;
input_mux = ~input_mux & 0x80;
return result;
}

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

result = ~(unsigned __int8)input_mux & 0xFFFFFF80;
input_mux = ~input_mux & 0x80;
return result;
}

original_code:
static void powerdrv_port_7_w(offs_t offset,data_t data)
{
 input_mux = ~input_mux & 0x80;
}

canonical_original_code:
static void powerdrv_port_7_w(unsigned int offset, unsigned int data)
{
 input_mux = ~input_mux & 0x80;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
void __fastcall maxrpm_mux_w(__int64 a1, unsigned int a2)
{
input_mux = (a2 >> 1) & 3;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
input_mux = (a2 >> 1) & 3;
}

original_code:
static void maxrpm_mux_w(offs_t offset,data_t data)
{
 input_mux = (data >> 1) & 3;
}

canonical_original_code:
static void maxrpm_mux_w(unsigned int offset, unsigned int data)
{
 input_mux = (data >> 1) & 3;
}


decompiled_code:
void *init_tapper()
{
void *result; // rax

result = &mcr_sound_config;
mcr_sound_config = 1;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

result = &mcr_sound_config;
mcr_sound_config = 1;
return result;
}

original_code:
static void init_tapper(void)
{
 mcr_sound_config = 0x01;
}

canonical_original_code:
static void init_tapper()
{
 mcr_sound_config = 0x01;
}


decompiled_code:
void *init_crater()
{
void *result; // rax

mcr_sound_config = 1;
spyhunt_sprite_color_mask = 3;
spyhunt_scroll_offset = -96;
result = &spyhunt_draw_lamps;
spyhunt_draw_lamps = 0;
return result;
}

canonical_decompiled_code:
void *func3()
{
void *result; // rax

mcr_sound_config = 1;
spyhunt_sprite_color_mask = 3;
spyhunt_scroll_offset = -96;
result = &spyhunt_draw_lamps;
spyhunt_draw_lamps = 0;
return result;
}

original_code:
static void init_crater(void)
{
 mcr_sound_config = 0x01;
 spyhunt_sprite_color_mask = 0x03;
 spyhunt_scroll_offset = -96;
 spyhunt_draw_lamps = 0;
}

canonical_original_code:
static void init_crater()
{
 mcr_sound_config = 0x01;
 spyhunt_sprite_color_mask = 0x03;
 spyhunt_scroll_offset = -96;
 spyhunt_draw_lamps = 0;
}


decompiled_code:
_BYTE *spyhunt_decode()
{
_BYTE *result; // rax
_BYTE *v1; // rsi
_BYTE *v2; // rsi
char v3; // dl

result = (_BYTE *)memory_region(129LL);
if ( result[40960] != 12 )
{
v1 = result;
result += 40960;
v2 = v1 + 49152;
do
{
v3 = *result;
*result = result[0x2000];
result[0x2000] = v3;
++result;
}
while ( result != v2 );
}
return result;
}

canonical_decompiled_code:
_BYTE *func4()
{
_BYTE *result; // rax
_BYTE *v1; // rsi
_BYTE *v2; // rsi
char v3; // dl

result = (_BYTE *)memory_region(129LL);
if ( result[40960] != 12 )
{
v1 = result;
result += 40960;
v2 = v1 + 49152;
do
{
v3 = *result;
*result = result[0x2000];
result[0x2000] = v3;
++result;
}
while ( result != v2 );
}
return result;
}

original_code:
static void spyhunt_decode(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (RAM[0xa000] != 0x0c)
 {
  int i;
  for (i = 0; i < 0x2000; i++)
  {
   UINT8 temp = RAM[0xa000 + i];
   RAM[0xa000 + i] = RAM[0xc000 + i];
   RAM[0xc000 + i] = temp;
  }
 }
}

canonical_original_code:
static void spyhunt_decode()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (RAM[0xa000] != 0x0c)
 {
  int i;
  for (i = 0; i < 0x2000; i++)
  {
   unsigned char temp = RAM[0xa000 + i];
   RAM[0xa000 + i] = RAM[0xc000 + i];
   RAM[0xc000 + i] = temp;
  }
 }
}

variable_types:
RAM
unsigned char *

variable_types: i int

variable_types:
temp
unsigned char


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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 57344, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 57344, 2048LL);
return result;
}

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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 57344, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 57344, 2048LL);
return result;
}

original_code:
static void mcr3_nvram_handler(void *file, int read_or_write)
{
 unsigned char *ram = memory_region(REGION_CPU1);
 if (read_or_write)
  osd_fwrite(file, &ram[0xe000], 0x800);
 else if (file)
  osd_fread(file, &ram[0xe000], 0x800);
}

variable_types:
file
void *

variable_types:
ram
unsigned char *


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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 61440, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 61440, 2048LL);
return result;
}

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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 61440, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 61440, 2048LL);
return result;
}

original_code:
static void spyhunt_nvram_handler(void *file, int read_or_write)
{
 unsigned char *ram = memory_region(REGION_CPU1);
 if (read_or_write)
  osd_fwrite(file, &ram[0xf000], 0x800);
 else if (file)
  osd_fread(file, &ram[0xf000], 0x800);
}


decompiled_code:
__int64 powerdrv_port_2_r()
{
return input_port_2_r() & 0x7F | input_mux & 0x80;
}

canonical_decompiled_code:
__int64 func7()
{
return input_port_2_r() & 0x7F | input_mux & 0x80;
}

original_code:
static data_t powerdrv_port_2_r(offs_t offset)
{
 int result = input_port_2_r(offset) & 0x7f;
 return result | (input_mux & 0x80);
}

canonical_original_code:
static unsigned int powerdrv_port_2_r(unsigned int offset)
{
 int result = input_port_2_r(offset) & 0x7f;
 return result | (input_mux & 0x80);
}

variable_types: result int

return_type: unsigned int


decompiled_code:
__int64 init_timber()
{
mcr_sound_config = 1;
install_mem_read_handler(1LL, 12288LL, 0x3FFFLL, -1LL);
return install_mem_write_handler(1LL, 12288LL, 0x3FFFLL, -1LL);
}

canonical_decompiled_code:
__int64 func8()
{
mcr_sound_config = 1;
install_mem_read_handler(1LL, 12288LL, 0x3FFFLL, -1LL);
return install_mem_write_handler(1LL, 12288LL, 0x3FFFLL, -1LL);
}

original_code:
static void init_timber(void)
{
 mcr_sound_config = 0x01;
 install_mem_read_handler(1, 0x3000, 0x3fff, ((mem_read_handler)-1));
 install_mem_write_handler(1, 0x3000, 0x3fff, ((mem_write_handler)-1));
}

canonical_original_code:
static void init_timber()
{
 mcr_sound_config = 0x01;
 install_mem_read_handler(1, 0x3000, 0x3fff, ((mem_read_handler)-1));
 install_mem_write_handler(1, 0x3000, 0x3fff, ((mem_write_handler)-1));
}


decompiled_code:
__int64 init_dotron()
{
mcr_sound_config = 17;
install_port_read_handler(0LL, 2LL, 2LL, dotron_port_2_r);
return install_port_write_handler(0LL, 4LL, 4LL, dotron_port_4_w);
}

canonical_decompiled_code:
__int64 func9()
{
mcr_sound_config = 17;
install_port_read_handler(0LL, 2LL, 2LL, dotron_port_2_r);
return install_port_write_handler(0LL, 4LL, 4LL, dotron_port_4_w);
}

original_code:
static void init_dotron(void)
{
 mcr_sound_config = 0x01 | 0x10;
 install_port_read_handler(0, 0x02, 0x02, dotron_port_2_r);
 install_port_write_handler(0, 0x04, 0x04, dotron_port_4_w);
}

canonical_original_code:
static void init_dotron()
{
 mcr_sound_config = 0x01 | 0x10;
 install_port_read_handler(0, 0x02, 0x02, dotron_port_2_r);
 install_port_write_handler(0, 0x04, 0x04, dotron_port_4_w);
}


decompiled_code:
__int64 init_destderb()
{
mcr_sound_config = 8;
return install_port_write_handler(0LL, 4LL, 4LL, &turbocs_data_w);
}

canonical_decompiled_code:
__int64 func10()
{
mcr_sound_config = 8;
return install_port_write_handler(0LL, 4LL, 4LL, &turbocs_data_w);
}

original_code:
static void init_destderb(void)
{
 mcr_sound_config = 0x08;
 install_port_write_handler(0, 0x04, 0x04, turbocs_data_w);
}

canonical_original_code:
static void init_destderb()
{
 mcr_sound_config = 0x08;
 install_port_write_handler(0, 0x04, 0x04, turbocs_data_w);
}


decompiled_code:
_BYTE *init_spyhunt()
{
mcr_sound_config = 3;
install_port_read_handler(0LL, 2LL, 2LL, spyhunt_port_2_r);
install_port_write_handler(0LL, 4LL, 4LL, spyhunt_port_4_w);
spyhunt_sprite_color_mask = 0;
spyhunt_scroll_offset = -16;
spyhunt_draw_lamps = 1;
return spyhunt_decode();
}

canonical_decompiled_code:
_BYTE *func11()
{
mcr_sound_config = 3;
install_port_read_handler(0LL, 2LL, 2LL, spyhunt_port_2_r);
install_port_write_handler(0LL, 4LL, 4LL, spyhunt_port_4_w);
spyhunt_sprite_color_mask = 0;
spyhunt_scroll_offset = -16;
spyhunt_draw_lamps = 1;
return func4();
}

original_code:
static void init_spyhunt(void)
{
 mcr_sound_config = 0x01 | 0x02;
 install_port_read_handler(0, 0x02, 0x02, spyhunt_port_2_r);
 install_port_write_handler(0, 0x04, 0x04, spyhunt_port_4_w);
 spyhunt_sprite_color_mask = 0x00;
 spyhunt_scroll_offset = -16;
 spyhunt_draw_lamps = 1;
 spyhunt_decode();
}

canonical_original_code:
static void init_spyhunt()
{
 mcr_sound_config = 0x01 | 0x02;
 install_port_read_handler(0, 0x02, 0x02, spyhunt_port_2_r);
 install_port_write_handler(0, 0x04, 0x04, spyhunt_port_4_w);
 spyhunt_sprite_color_mask = 0x00;
 spyhunt_scroll_offset = -16;
 spyhunt_draw_lamps = 1;
 spyhunt_decode();
}


decompiled_code:
__int64 init_turbotag()
{
mcr_sound_config = 2;
install_port_read_handler(0LL, 2LL, 2LL, spyhunt_port_2_r);
install_port_write_handler(0LL, 4LL, 4LL, spyhunt_port_4_w);
spyhunt_sprite_color_mask = 0;
spyhunt_scroll_offset = -88;
spyhunt_draw_lamps = 0;
return install_mem_read_handler(0LL, 2899LL, 2899LL, turbotag_kludge_r);
}

canonical_decompiled_code:
__int64 func12()
{
mcr_sound_config = 2;
install_port_read_handler(0LL, 2LL, 2LL, spyhunt_port_2_r);
install_port_write_handler(0LL, 4LL, 4LL, spyhunt_port_4_w);
spyhunt_sprite_color_mask = 0;
spyhunt_scroll_offset = -88;
spyhunt_draw_lamps = 0;
return install_mem_read_handler(0LL, 2899LL, 2899LL, turbotag_kludge_r);
}

original_code:
static void init_turbotag(void)
{
 mcr_sound_config = 0x02;
 install_port_read_handler(0, 0x02, 0x02, spyhunt_port_2_r);
 install_port_write_handler(0, 0x04, 0x04, spyhunt_port_4_w);
 spyhunt_sprite_color_mask = 0x00;
 spyhunt_scroll_offset = -88;
 spyhunt_draw_lamps = 0;
 install_mem_read_handler(0, 0x0b53, 0x0b53, turbotag_kludge_r);
}

canonical_original_code:
static void init_turbotag()
{
 mcr_sound_config = 0x02;
 install_port_read_handler(0, 0x02, 0x02, spyhunt_port_2_r);
 install_port_write_handler(0, 0x04, 0x04, spyhunt_port_4_w);
 spyhunt_sprite_color_mask = 0x00;
 spyhunt_scroll_offset = -88;
 spyhunt_draw_lamps = 0;
 install_mem_read_handler(0, 0x0b53, 0x0b53, turbotag_kludge_r);
}


decompiled_code:
__int64 __fastcall dotron_port_4_w(unsigned int a1, unsigned int a2)
{
dotron_change_light(a2 >> 6);
return squawkntalk_data_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, unsigned int a2)
{
dotron_change_light(a2 >> 6);
return squawkntalk_data_w(a1, a2);
}

original_code:
static void dotron_port_4_w(offs_t offset,data_t data)
{
 dotron_change_light(data >> 6);
 squawkntalk_data_w(offset, data);
}

canonical_original_code:
static void dotron_port_4_w(unsigned int offset, unsigned int data)
{
 dotron_change_light(data >> 6);
 squawkntalk_data_w(offset, data);
}


decompiled_code:
__int64 __fastcall dotron_port_2_r(unsigned int a1)
{
unsigned int v1; // ebx
char v2; // dl
int v3; // eax

v1 = input_port_2_r();
v2 = input_port_6_r(a1);
v3 = delta_4 + v2 - lastfake_5;
delta_4 = v3;
lastfake_5 = v2;
if ( v3 > 5 )
{
mask_3 = 239;
count_2 = 5;
delta_4 = 0;
LABEL_3:
--count_2;
return mask_3 & v1;
}
if ( v3 < -5 )
{
mask_3 = 223;
count_2 = 5;
delta_4 = 0;
goto LABEL_3;
}
if ( count_2 > 0 )
{
--count_2;
}
else
{
count_2 = 0;
mask_3 = 255;
}
return mask_3 & v1;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
unsigned int v1; // ebx
char v2; // dl
int v3; // eax

v1 = input_port_2_r();
v2 = input_port_6_r(a1);
v3 = delta_4 + v2 - lastfake_5;
delta_4 = v3;
lastfake_5 = v2;
if ( v3 > 5 )
{
mask_3 = 239;
count_2 = 5;
delta_4 = 0;
LABEL_3:
--count_2;
return mask_3 & v1;
}
if ( v3 < -5 )
{
mask_3 = 223;
count_2 = 5;
delta_4 = 0;
goto LABEL_3;
}
if ( count_2 > 0 )
{
--count_2;
}
else
{
count_2 = 0;
mask_3 = 255;
}
return mask_3 & v1;
}

original_code:
static data_t dotron_port_2_r(offs_t offset)
{
 static char lastfake = 0;
 static int mask = 0x00FF;
 static int count = 0;
 static int delta = 0;
 int data;
 char fake;
 data = input_port_2_r(offset);
 fake = input_port_6_r(offset);
 delta += (fake - lastfake);
 lastfake = fake;
 if (delta > 5)
 {
  mask = 0x00EF;
  count = 5;
  delta = 0;
 }
 else if (delta < -5)
 {
  mask = 0x00DF;
  count = 5;
  delta = 0;
 }
 if ((count--) <= 0)
 {
  count = 0;
  mask = 0x00FF;
 }
 data &= mask;
 return data;
}

canonical_original_code:
static unsigned int dotron_port_2_r(unsigned int offset)
{
 static char lastfake = 0;
 static int mask = 0x00FF;
 static int count = 0;
 static int delta = 0;
 int data;
 char fake;
 data = input_port_2_r(offset);
 fake = input_port_6_r(offset);
 delta += (fake - lastfake);
 lastfake = fake;
 if (delta > 5)
 {
  mask = 0x00EF;
  count = 5;
  delta = 0;
 }
 else if (delta < -5)
 {
  mask = 0x00DF;
  count = 5;
  delta = 0;
 }
 if ((count--) <= 0)
 {
  count = 0;
  mask = 0x00FF;
 }
 data &= mask;
 return data;
}

variable_types: lastfake char

variable_types: mask int

variable_types: count int

variable_types: delta int

variable_types: data int

variable_types: fake char


decompiled_code:
__int64 dotron_interrupt()
{
z80ctc_0_trg2_w(0LL, 1LL);
z80ctc_0_trg2_w(0LL, 0LL);
return mcr_interrupt();
}

canonical_decompiled_code:
__int64 func15()
{
z80ctc_0_trg2_w(0LL, 1LL);
z80ctc_0_trg2_w(0LL, 0LL);
return mcr_interrupt();
}

original_code:
static int dotron_interrupt(void)
{
 z80ctc_0_trg2_w(0, 1);
 z80ctc_0_trg2_w(0, 0);
 return mcr_interrupt();
}

canonical_original_code:
static int dotron_interrupt()
{
 z80ctc_0_trg2_w(0, 1);
 z80ctc_0_trg2_w(0, 0);
 return mcr_interrupt();
}

return_type: int


decompiled_code:
__int64 mcrmono_decode()
{
__int64 i; // rbx
__int64 v1; // rax
__int64 result; // rax

for ( i = 0LL; ; ++i )
{
result = memory_region_length(137LL);
if ( (int)result <= (int)i )
break;
v1 = memory_region(137LL);
*(_BYTE *)(v1 + i) = ~*(_BYTE *)(v1 + i);
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 i; // rbx
__int64 v1; // rax
__int64 result; // rax

for ( i = 0LL; ; ++i )
{
result = memory_region_length(137LL);
if ( (int)result <= (int)i )
break;
v1 = memory_region(137LL);
*(_BYTE *)(v1 + i) = ~*(_BYTE *)(v1 + i);
}
return result;
}

original_code:
static void mcrmono_decode(void)
{
 int i;
 for (i = 0; i < memory_region_length(REGION_GFX1); i++)
  memory_region(REGION_GFX1)[i] ^= 0xff;
}

canonical_original_code:
static void mcrmono_decode()
{
 int i;
 for (i = 0; i < memory_region_length(REGION_GFX1); i++)
  memory_region(REGION_GFX1)[i] ^= 0xff;
}


decompiled_code:
__int64 init_destderm()
{
mcr_sound_config = 8;
install_port_write_handler(0LL, 6LL, 6LL, &turbocs_data_w);
return mcrmono_decode();
}

canonical_decompiled_code:
__int64 func17()
{
mcr_sound_config = 8;
install_port_write_handler(0LL, 6LL, 6LL, &turbocs_data_w);
return func16();
}

original_code:
static void init_destderm(void)
{
 mcr_sound_config = 0x08;
 install_port_write_handler(0, 0x06, 0x06, turbocs_data_w);
 mcrmono_decode();
}

canonical_original_code:
static void init_destderm()
{
 mcr_sound_config = 0x08;
 install_port_write_handler(0, 0x06, 0x06, turbocs_data_w);
 mcrmono_decode();
}


decompiled_code:
__int64 init_sarge()
{
mcr_sound_config = 8;
install_port_read_handler(0LL, 1LL, 1LL, sarge_port_1_r);
install_port_read_handler(0LL, 2LL, 2LL, sarge_port_2_r);
install_port_write_handler(0LL, 6LL, 6LL, &turbocs_data_w);
return mcrmono_decode();
}

canonical_decompiled_code:
__int64 func18()
{
mcr_sound_config = 8;
install_port_read_handler(0LL, 1LL, 1LL, sarge_port_1_r);
install_port_read_handler(0LL, 2LL, 2LL, sarge_port_2_r);
install_port_write_handler(0LL, 6LL, 6LL, &turbocs_data_w);
return func16();
}

original_code:
static void init_sarge(void)
{
 mcr_sound_config = 0x08;
 install_port_read_handler(0, 0x01, 0x01, sarge_port_1_r);
 install_port_read_handler(0, 0x02, 0x02, sarge_port_2_r);
 install_port_write_handler(0, 0x06, 0x06, turbocs_data_w);
 mcrmono_decode();
}

canonical_original_code:
static void init_sarge()
{
 mcr_sound_config = 0x08;
 install_port_read_handler(0, 0x01, 0x01, sarge_port_1_r);
 install_port_read_handler(0, 0x02, 0x02, sarge_port_2_r);
 install_port_write_handler(0, 0x06, 0x06, turbocs_data_w);
 mcrmono_decode();
}


decompiled_code:
__int64 init_rampage()
{
mcr_sound_config = 4;
install_port_write_handler(0LL, 6LL, 6LL, &soundsgood_data_w);
return mcrmono_decode();
}

canonical_decompiled_code:
__int64 func19()
{
mcr_sound_config = 4;
install_port_write_handler(0LL, 6LL, 6LL, &soundsgood_data_w);
return func16();
}

original_code:
static void init_rampage(void)
{
 mcr_sound_config = 0x04;
 install_port_write_handler(0, 0x06, 0x06, soundsgood_data_w);
 mcrmono_decode();
}

canonical_original_code:
static void init_rampage()
{
 mcr_sound_config = 0x04;
 install_port_write_handler(0, 0x06, 0x06, soundsgood_data_w);
 mcrmono_decode();
}


decompiled_code:
__int64 init_powerdrv()
{
mcr_sound_config = 4;
install_port_read_handler(0LL, 2LL, 2LL, powerdrv_port_2_r);
install_port_write_handler(0LL, 6LL, 6LL, &soundsgood_data_w);
install_port_write_handler(0LL, 7LL, 7LL, powerdrv_port_7_w);
return mcrmono_decode();
}

canonical_decompiled_code:
__int64 func20()
{
mcr_sound_config = 4;
install_port_read_handler(0LL, 2LL, 2LL, powerdrv_port_2_r);
install_port_write_handler(0LL, 6LL, 6LL, &soundsgood_data_w);
install_port_write_handler(0LL, 7LL, 7LL, powerdrv_port_7_w);
return func16();
}

original_code:
static void init_powerdrv(void)
{
 mcr_sound_config = 0x04;
 install_port_read_handler(0, 0x02, 0x02, powerdrv_port_2_r);
 install_port_write_handler(0, 0x06, 0x06, soundsgood_data_w);
 install_port_write_handler(0, 0x07, 0x07, powerdrv_port_7_w);
 mcrmono_decode();
}

canonical_original_code:
static void init_powerdrv()
{
 mcr_sound_config = 0x04;
 install_port_read_handler(0, 0x02, 0x02, powerdrv_port_2_r);
 install_port_write_handler(0, 0x06, 0x06, soundsgood_data_w);
 install_port_write_handler(0, 0x07, 0x07, powerdrv_port_7_w);
 mcrmono_decode();
}


decompiled_code:
__int64 init_maxrpm()
{
mcr_sound_config = 8;
install_port_read_handler(0LL, 1LL, 1LL, maxrpm_port_1_r);
install_port_read_handler(0LL, 2LL, 2LL, maxrpm_port_2_r);
install_port_write_handler(0LL, 5LL, 5LL, maxrpm_mux_w);
install_port_write_handler(0LL, 6LL, 6LL, &turbocs_data_w);
return mcrmono_decode();
}

canonical_decompiled_code:
__int64 func21()
{
mcr_sound_config = 8;
install_port_read_handler(0LL, 1LL, 1LL, maxrpm_port_1_r);
install_port_read_handler(0LL, 2LL, 2LL, maxrpm_port_2_r);
install_port_write_handler(0LL, 5LL, 5LL, maxrpm_mux_w);
install_port_write_handler(0LL, 6LL, 6LL, &turbocs_data_w);
return func16();
}

original_code:
static void init_maxrpm(void)
{
 mcr_sound_config = 0x08;
 install_port_read_handler(0, 0x01, 0x01, maxrpm_port_1_r);
 install_port_read_handler(0, 0x02, 0x02, maxrpm_port_2_r);
 install_port_write_handler(0, 0x05, 0x05, maxrpm_mux_w);
 install_port_write_handler(0, 0x06, 0x06, turbocs_data_w);
 mcrmono_decode();
}

canonical_original_code:
static void init_maxrpm()
{
 mcr_sound_config = 0x08;
 install_port_read_handler(0, 0x01, 0x01, maxrpm_port_1_r);
 install_port_read_handler(0, 0x02, 0x02, maxrpm_port_2_r);
 install_port_write_handler(0, 0x05, 0x05, maxrpm_mux_w);
 install_port_write_handler(0, 0x06, 0x06, turbocs_data_w);
 mcrmono_decode();
}


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

v0 = readinputport(2LL);
return v0 & ~one_joy_trans[((int)readinputport(6LL) >> 4) & 0xF];
}

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

v0 = readinputport(2LL);
return v0 & ~one_joy_trans[((int)readinputport(6LL) >> 4) & 0xF];
}

original_code:
static data_t sarge_port_2_r(offs_t offset)
{
 return readinputport(2) & ~one_joy_trans[(readinputport(6) >> 4) & 0x0f];
}

canonical_original_code:
static unsigned int sarge_port_2_r(unsigned int offset)
{
 return readinputport(2) & ~one_joy_trans[(readinputport(6) >> 4) & 0x0f];
}


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

v0 = readinputport(1LL);
return v0 & ~one_joy_trans[readinputport(6LL) & 0xF];
}

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

v0 = readinputport(1LL);
return v0 & ~one_joy_trans[readinputport(6LL) & 0xF];
}

original_code:
static data_t sarge_port_1_r(offs_t offset)
{
 return readinputport(1) & ~one_joy_trans[readinputport(6) & 0x0f];
}

canonical_original_code:
static unsigned int sarge_port_1_r(unsigned int offset)
{
 return readinputport(1) & ~one_joy_trans[readinputport(6) & 0x0f];
}


decompiled_code:
__int64 maxrpm_port_2_r()
{
char v0; // bl
char v1; // al
char v2; // dl
char v3; // dl
char v4; // dl
char v5; // dl

v0 = readinputport(0LL);
v1 = readinputport(10LL);
if ( (v0 & 8) == 0 )
maxrpm_p1_shift = 0;
if ( (v0 & 4) == 0 )
maxrpm_p2_shift = 0;
if ( (v1 & 1) == 0 && (maxrpm_last_shift & 1) != 0 )
{
v2 = maxrpm_p1_shift + 1;
if ( (char)(maxrpm_p1_shift + 1) > 4 )
v2 = 4;
maxrpm_p1_shift = v2;
}
if ( (v1 & 2) == 0 && (maxrpm_last_shift & 2) != 0 )
{
v3 = maxrpm_p1_shift - 1;
if ( (char)(maxrpm_p1_shift - 1) < 0 )
v3 = 0;
maxrpm_p1_shift = v3;
}
if ( (v1 & 4) == 0 && (maxrpm_last_shift & 4) != 0 )
{
v4 = maxrpm_p2_shift + 1;
if ( (char)(maxrpm_p2_shift + 1) > 4 )
v4 = 4;
maxrpm_p2_shift = v4;
}
if ( (v1 & 8) == 0 && (maxrpm_last_shift & 8) != 0 )
{
v5 = maxrpm_p2_shift - 1;
if ( (char)(maxrpm_p2_shift - 1) < 0 )
v5 = 0;
maxrpm_p2_shift = v5;
}
maxrpm_last_shift = v1;
return ~(shift_bits_1[maxrpm_p2_shift] + 16 * (unsigned int)shift_bits_1[maxrpm_p1_shift]);
}

canonical_decompiled_code:
__int64 func24()
{
char v0; // bl
char v1; // al
char v2; // dl
char v3; // dl
char v4; // dl
char v5; // dl

v0 = readinputport(0LL);
v1 = readinputport(10LL);
if ( (v0 & 8) == 0 )
maxrpm_p1_shift = 0;
if ( (v0 & 4) == 0 )
maxrpm_p2_shift = 0;
if ( (v1 & 1) == 0 && (maxrpm_last_shift & 1) != 0 )
{
v2 = maxrpm_p1_shift + 1;
if ( (char)(maxrpm_p1_shift + 1) > 4 )
v2 = 4;
maxrpm_p1_shift = v2;
}
if ( (v1 & 2) == 0 && (maxrpm_last_shift & 2) != 0 )
{
v3 = maxrpm_p1_shift - 1;
if ( (char)(maxrpm_p1_shift - 1) < 0 )
v3 = 0;
maxrpm_p1_shift = v3;
}
if ( (v1 & 4) == 0 && (maxrpm_last_shift & 4) != 0 )
{
v4 = maxrpm_p2_shift + 1;
if ( (char)(maxrpm_p2_shift + 1) > 4 )
v4 = 4;
maxrpm_p2_shift = v4;
}
if ( (v1 & 8) == 0 && (maxrpm_last_shift & 8) != 0 )
{
v5 = maxrpm_p2_shift - 1;
if ( (char)(maxrpm_p2_shift - 1) < 0 )
v5 = 0;
maxrpm_p2_shift = v5;
}
maxrpm_last_shift = v1;
return ~(shift_bits_1[maxrpm_p2_shift] + 16 * (unsigned int)shift_bits_1[maxrpm_p1_shift]);
}

original_code:
static data_t maxrpm_port_2_r(offs_t offset)
{
 static const UINT8 shift_bits[5] = { 0x00, 0x05, 0x06, 0x01, 0x02 };
 UINT8 start = readinputport(0);
 UINT8 shift = readinputport(10);
 if (!(start & 0x08))
  maxrpm_p1_shift = 0;
 if (!(start & 0x04))
  maxrpm_p2_shift = 0;
 if (!(shift & 0x01) && (maxrpm_last_shift & 0x01))
 {
  maxrpm_p1_shift++;
  if (maxrpm_p1_shift > 4)
   maxrpm_p1_shift = 4;
 }
 if (!(shift & 0x02) && (maxrpm_last_shift & 0x02))
 {
  maxrpm_p1_shift--;
  if (maxrpm_p1_shift < 0)
   maxrpm_p1_shift = 0;
 }
 if (!(shift & 0x04) && (maxrpm_last_shift & 0x04))
 {
  maxrpm_p2_shift++;
  if (maxrpm_p2_shift > 4)
   maxrpm_p2_shift = 4;
 }
 if (!(shift & 0x08) && (maxrpm_last_shift & 0x08))
 {
  maxrpm_p2_shift--;
  if (maxrpm_p2_shift < 0)
   maxrpm_p2_shift = 0;
 }
 maxrpm_last_shift = shift;
 return ~((shift_bits[maxrpm_p1_shift] << 4) + shift_bits[maxrpm_p2_shift]);
}

canonical_original_code:
static unsigned int maxrpm_port_2_r(unsigned int offset)
{
 static unsigned char shift_bits[5] = { 0x00, 0x05, 0x06, 0x01, 0x02 };
 unsigned char start = readinputport(0);
 unsigned char shift = readinputport(10);
 if (!(start & 0x08))
  maxrpm_p1_shift = 0;
 if (!(start & 0x04))
  maxrpm_p2_shift = 0;
 if (!(shift & 0x01) && (maxrpm_last_shift & 0x01))
 {
  maxrpm_p1_shift++;
  if (maxrpm_p1_shift > 4)
   maxrpm_p1_shift = 4;
 }
 if (!(shift & 0x02) && (maxrpm_last_shift & 0x02))
 {
  maxrpm_p1_shift--;
  if (maxrpm_p1_shift < 0)
   maxrpm_p1_shift = 0;
 }
 if (!(shift & 0x04) && (maxrpm_last_shift & 0x04))
 {
  maxrpm_p2_shift++;
  if (maxrpm_p2_shift > 4)
   maxrpm_p2_shift = 4;
 }
 if (!(shift & 0x08) && (maxrpm_last_shift & 0x08))
 {
  maxrpm_p2_shift--;
  if (maxrpm_p2_shift < 0)
   maxrpm_p2_shift = 0;
 }
 maxrpm_last_shift = shift;
 return ~((shift_bits[maxrpm_p1_shift] << 4) + shift_bits[maxrpm_p2_shift]);
}

variable_types:
start
unsigned char

variable_types:
shift
unsigned char


decompiled_code:
__int64 maxrpm_port_1_r()
{
return readinputport((unsigned int)(unsigned __int8)input_mux + 6);
}

canonical_decompiled_code:
__int64 func25()
{
return readinputport((unsigned int)(unsigned __int8)input_mux + 6);
}

original_code:
static data_t maxrpm_port_1_r(offs_t offset)
{
 return readinputport(6 + input_mux);
}

canonical_original_code:
static unsigned int maxrpm_port_1_r(unsigned int offset)
{
 return readinputport(6 + input_mux);
}


decompiled_code:
__int64 spyhunt_port_2_r()
{
return readinputport((unsigned int)(unsigned __int8)input_mux + 6);
}

canonical_decompiled_code:
__int64 func26()
{
return readinputport((unsigned int)(unsigned __int8)input_mux + 6);
}

original_code:
static data_t spyhunt_port_2_r(offs_t offset)
{
 return readinputport(6 + input_mux);
}

canonical_original_code:
static unsigned int spyhunt_port_2_r(unsigned int offset)
{
 return readinputport(6 + input_mux);
}


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

z80ctc_0_trg2_w(0LL, 1LL);
z80ctc_0_trg2_w(0LL, 0LL);
if ( (unsigned int)cpu_getiloops() )
result = ignore_interrupt();
else
result = mcr_interrupt();
return result;
}

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

z80ctc_0_trg2_w(0LL, 1LL);
z80ctc_0_trg2_w(0LL, 0LL);
if ( (unsigned int)cpu_getiloops() )
result = ignore_interrupt();
else
result = mcr_interrupt();
return result;
}

original_code:
static int powerdrv_interrupt(void)
{
 z80ctc_0_trg2_w(0, 1);
 z80ctc_0_trg2_w(0, 0);
 if (cpu_getiloops() == 0)
  return mcr_interrupt();
 else
  return ignore_interrupt();
}

canonical_original_code:
static int powerdrv_interrupt()
{
 z80ctc_0_trg2_w(0, 1);
 z80ctc_0_trg2_w(0, 0);
 if (cpu_getiloops() == 0)
  return mcr_interrupt();
 else
  return ignore_interrupt();
}


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

input_mux = (unsigned __int8)a2 >> 7;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)lastport4_0) & 0x20) != 0 && (a2 & 0x20) == 0 )
*((_BYTE *)&spyhunt_lamp + (a2 & 7)) = (a2 & 8) != 0;
result = csdeluxe_data_w(a1, a2);
lastport4_0 = a2;
return result;
}

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

input_mux = (unsigned __int8)a2 >> 7;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)lastport4_0) & 0x20) != 0 && (a2 & 0x20) == 0 )
*((_BYTE *)&spyhunt_lamp + (a2 & 7)) = (a2 & 8) != 0;
result = csdeluxe_data_w(a1, a2);
lastport4_0 = a2;
return result;
}

original_code:
static void spyhunt_port_4_w(offs_t offset,data_t data)
{
 static UINT8 lastport4;
 input_mux = (data >> 7) & 1;
 if (((lastport4 ^ data) & 0x20) && !(data & 0x20))
  spyhunt_lamp[data & 7] = (data >> 3) & 1;
 csdeluxe_data_w(offset, data);
 lastport4 = data;
}

canonical_original_code:
static void spyhunt_port_4_w(unsigned int offset, unsigned int data)
{
 static unsigned char lastport4;
 input_mux = (data >> 7) & 1;
 if (((lastport4 ^ data) & 0x20) && !(data & 0x20))
  spyhunt_lamp[data & 7] = (data >> 3) & 1;
 csdeluxe_data_w(offset, data);
 lastport4 = data;
}


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

v0 = (unsigned int)cpu_get_reg(0xFFFFFFFFLL) == 2857;
result = 130LL;
if ( !v0 )
result = 146LL;
return result;
}

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

v0 = (unsigned int)cpu_get_reg(0xFFFFFFFFLL) == 2857;
result = 130LL;
if ( !v0 )
result = 146LL;
return result;
}

original_code:
static data_t turbotag_kludge_r(offs_t offset)
{
 if (cpu_get_reg(-1) == 0xb29)
  return 0x82;
 else
  return 0x92;
}

canonical_original_code:
static unsigned int turbotag_kludge_r(unsigned int offset)
{
 if (cpu_get_reg(-1) == 0xb29)
  return 0x82;
 else
  return 0x92;
}


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

paletteram = malloc(0x400uLL);
if ( !paletteram )
return 1LL;
layer_colorbase[0] = 0;
dword_49C = 4;
dword_4A0 = 8;
sprite_colorbase = 16;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
{
free(paletteram);
result = 1LL;
}
else
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
free(paletteram);
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

paletteram = malloc(0x400uLL);
if ( !paletteram )
return 1LL;
layer_colorbase[0] = 0;
dword_49C = 4;
dword_4A0 = 8;
sprite_colorbase = 16;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
{
free(paletteram);
result = 1LL;
}
else
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
free(paletteram);
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int aliens_vh_start( void )
{
 paletteram = (unsigned char*)malloc(0x400);
 if (!paletteram) return 1;
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 4;
 layer_colorbase[2] = 8;
 sprite_colorbase = 16;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  free(paletteram);
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  free(paletteram);
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int aliens_vh_start()
{
 paletteram = (unsigned char *)malloc(0x400);
 if (!paletteram) return 1;
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 4;
 layer_colorbase[2] = 8;
 sprite_colorbase = 16;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  free(paletteram);
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  free(paletteram);
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 aliens_vh_stop()
{
free(paletteram);
K052109_vh_stop();
return K051960_vh_stop();
}

canonical_decompiled_code:
__int64 func3()
{
free(paletteram);
K052109_vh_stop();
return K051960_vh_stop();
}

original_code:
void aliens_vh_stop( void )
{
 free(paletteram);
 K052109_vh_stop();
 K051960_vh_stop();
}

canonical_original_code:
void aliens_vh_stop()
{
 free(paletteram);
 K052109_vh_stop();
 K051960_vh_stop();
}


decompiled_code:
__int64 __fastcall aliens_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * dword_49C) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * dword_49C), Machine + 776LL);
K052109_tilemap_draw(a1, 1LL, 0x10000LL);
K052109_tilemap_draw(a1, 2LL, 0x20000LL);
K052109_tilemap_draw(a1, 0LL, 0x40000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * dword_49C) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * dword_49C), Machine + 776LL);
K052109_tilemap_draw(a1, 1LL, 0x10000LL);
K052109_tilemap_draw(a1, 2LL, 0x20000LL);
K052109_tilemap_draw(a1, 0LL, 0x40000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

original_code:
void aliens_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[layer_colorbase[1] * 16] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[layer_colorbase[1] * 16],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,1,1<<16);
 K052109_tilemap_draw(bitmap,2,2<<16);
 K052109_tilemap_draw(bitmap,0,4<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

canonical_original_code:
void aliens_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[layer_colorbase[1] * 16] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[layer_colorbase[1] * 16],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,1,1<<16);
 K052109_tilemap_draw(bitmap,2,2<<16);
 K052109_tilemap_draw(bitmap,0,4<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

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


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

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

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

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

variable_types:
offset
unsigned int


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

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

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

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


decompiled_code:
__int64 __fastcall aliens_snd_bankswitch_w(__int64 a1, int a2)
{
__int64 v2; // rax

v2 = memory_region(146LL);
return K007232_bankswitch(0LL, v2 + ((a2 << 16) & 0x20000), v2 + ((a2 << 17) & 0x20000));
}

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

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

variable_types:
data
unsigned int


decompiled_code:
void *aliens_init_machine()
{
__int64 v0; // rax
void *result; // rax
unsigned int v2; // eax

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

canonical_decompiled_code:
void *func9()
{
__int64 v0; // rax
void *result; // rax
unsigned int v2; // eax

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

original_code:
static void aliens_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = aliens_banking;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void aliens_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = aliens_banking;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *__fastcall aliens_banking(char a1)
{
void *result; // rax
unsigned int v2; // eax

cpu_bankbase[1] = ((a1 & 0x10) == 0 ? 0x8000 : 0) + ((a1 & 0xF) << 13) + 0x10000 + memory_region(129LL);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(char a1)
{
void *result; // rax
unsigned int v2; // eax

cpu_bankbase[1] = ((a1 & 0x10) == 0 ? 0x8000 : 0) + ((a1 & 0xF) << 13) + 0x10000 + memory_region(129LL);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v2);
}
return result;
}

original_code:
static void aliens_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0x18000;
 if (lines & 0x10) offs -= 0x8000;
 offs += (lines & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void aliens_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0x18000;
 if (lines & 0x10) offs -= 0x8000;
 offs += (lines & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int

variable_types: offs int


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

if ( (unsigned int)K051960_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K051960_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int aliens_interrupt( void )
{
 if (K051960_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int aliens_interrupt()
{
 if (K051960_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall aliens_coin_counter_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
palette_selected = a2 & 0x20;
return K052109_set_RMRD_line((a2 & 0x40) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
palette_selected = a2 & 0x20;
return K052109_set_RMRD_line((a2 & 0x40) != 0);
}

original_code:
static void aliens_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 palette_selected = data & 0x20;
 K052109_set_RMRD_line((data & 0x40) ? 1 : 0);
}

canonical_original_code:
static void aliens_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 palette_selected = data & 0x20;
 K052109_set_RMRD_line((data & 0x40) ? 1 : 0);
}


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

*a3 |= (a2 << 14) | ((unsigned __int16)*a4 << 8) & 0x3F00;
result = layer_colorbase[a1] + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

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

*a3 |= (a2 << 14) | ((unsigned __int16)*a4 << 8) & 0x3F00;
result = layer_colorbase[a1] + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x3f) << 8) | (bank << 14);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x3f) << 8) | (bank << 14);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

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

variable_types: v int


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

if ( palette_selected )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

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

if ( palette_selected )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}


decompiled_code:
void __fastcall irem_port1_w(__int64 a1, int a2)
{
port1 = a2;
}

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

original_code:
static void irem_port1_w(offs_t offset,data_t data)
{
 port1 = data;
}

canonical_original_code:
static void irem_port1_w(unsigned int offset, unsigned int data)
{
 port1 = data;
}


decompiled_code:
__int64 __fastcall irem_adpcm_reset_w(__int64 a1, char a2)
{
MSM5205_reset_w(0LL, a2 & 1);
return MSM5205_reset_w(1LL, a2 & 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
MSM5205_reset_w(0LL, a2 & 1);
return MSM5205_reset_w(1LL, a2 & 2);
}

original_code:
static void irem_adpcm_reset_w(offs_t offset,data_t data)
{
 MSM5205_reset_w(0,data & 1);
 MSM5205_reset_w(1,data & 2);
}

canonical_original_code:
static void irem_adpcm_reset_w(unsigned int offset, unsigned int data)
{
 MSM5205_reset_w(0,data & 1);
 MSM5205_reset_w(1,data & 2);
}


decompiled_code:
__int64 irem_adpcm_int()
{
return cpu_set_nmi_line(1LL, 3LL);
}

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

original_code:
static void irem_adpcm_int(int data)
{
 cpu_set_nmi_line(1,3);
}


decompiled_code:
__int64 irem_adpcm_w()
{
return MSM5205_data_w();
}

canonical_decompiled_code:
__int64 func3()
{
return MSM5205_data_w();
}

original_code:
static void irem_adpcm_w(offs_t offset,data_t data)
{
 MSM5205_data_w(offset,data);
}

canonical_original_code:
static void irem_adpcm_w(unsigned int offset, unsigned int data)
{
 MSM5205_data_w(offset,data);
}


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

if ( (port2 & 0x10) != 0 )
return AY8910_read_port_1_r(0LL);
result = 255LL;
if ( (port2 & 8) != 0 )
result = AY8910_read_port_0_r(0LL);
return result;
}

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

if ( (port2 & 0x10) != 0 )
return AY8910_read_port_1_r(0LL);
result = 255LL;
if ( (port2 & 8) != 0 )
result = AY8910_read_port_0_r(0LL);
return result;
}

original_code:
static data_t irem_port1_r(offs_t offset)
{
 if (port2 & 0x10)
  return AY8910_read_port_1_r(0);
 else if (port2 & 0x08)
  return AY8910_read_port_0_r(0);
 else return 0xff;
}

canonical_original_code:
static unsigned int irem_port1_r(unsigned int offset)
{
 if (port2 & 0x10)
  return AY8910_read_port_1_r(0);
 else if (port2 & 0x08)
  return AY8910_read_port_0_r(0);
 else return 0xff;
}


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

result = (unsigned int)port2;
if ( (port2 & 1) != 0 && (a2 & 1) == 0 )
{
if ( (port2 & 4) != 0 )
{
if ( (port2 & 0x10) != 0 )
{
result = AY8910_control_port_1_w(0LL, (unsigned int)port1);
}
else if ( (port2 & 8) != 0 )
{
result = AY8910_control_port_0_w(0LL, (unsigned int)port1);
}
}
else if ( (port2 & 0x10) != 0 )
{
result = AY8910_write_port_1_w(0LL, (unsigned int)port1);
}
else if ( (port2 & 8) != 0 )
{
result = AY8910_write_port_0_w(0LL, (unsigned int)port1);
}
}
port2 = a2;
return result;
}

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

result = (unsigned int)port2;
if ( (port2 & 1) != 0 && (a2 & 1) == 0 )
{
if ( (port2 & 4) != 0 )
{
if ( (port2 & 0x10) != 0 )
{
result = AY8910_control_port_1_w(0LL, (unsigned int)port1);
}
else if ( (port2 & 8) != 0 )
{
result = AY8910_control_port_0_w(0LL, (unsigned int)port1);
}
}
else if ( (port2 & 0x10) != 0 )
{
result = AY8910_write_port_1_w(0LL, (unsigned int)port1);
}
else if ( (port2 & 8) != 0 )
{
result = AY8910_write_port_0_w(0LL, (unsigned int)port1);
}
}
port2 = a2;
return result;
}

original_code:
static void irem_port2_w(offs_t offset,data_t data)
{
 if ((port2 & 0x01) && !(data & 0x01))
 {
  if (port2 & 0x04)
  {
   if (port2 & 0x10)
    AY8910_control_port_1_w(0,port1);
   else if (port2 & 0x08)
    AY8910_control_port_0_w(0,port1);
  }
  else
  {
   if (port2 & 0x10)
    AY8910_write_port_1_w(0,port1);
   else if (port2 & 0x08)
    AY8910_write_port_0_w(0,port1);
  }
 }
 port2 = data;
}

canonical_original_code:
static void irem_port2_w(unsigned int offset, unsigned int data)
{
 if ((port2 & 0x01) && !(data & 0x01))
 {
  if (port2 & 0x04)
  {
   if (port2 & 0x10)
    AY8910_control_port_1_w(0,port1);
   else if (port2 & 0x08)
    AY8910_control_port_0_w(0,port1);
  }
  else
  {
   if (port2 & 0x10)
    AY8910_write_port_1_w(0,port1);
   else if (port2 & 0x08)
    AY8910_write_port_0_w(0,port1);
  }
 }
 port2 = data;
}


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

if ( a2 < 0 )
result = cpu_set_irq_line(1LL, 0LL, 2LL);
else
result = soundlatch_w(0LL, a2 & 0x7F);
return result;
}

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

if ( a2 < 0 )
result = cpu_set_irq_line(1LL, 0LL, 2LL);
else
result = soundlatch_w(0LL, a2 & 0x7F);
return result;
}

original_code:
void irem_sound_cmd_w(offs_t offset,data_t data)
{
 if ((data & 0x80) == 0)
  soundlatch_w(0,data & 0x7f);
 else
  cpu_set_irq_line(1,0,2);
}

canonical_original_code:
void irem_sound_cmd_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x80) == 0)
  soundlatch_w(0,data & 0x7f);
 else
  cpu_set_irq_line(1,0,2);
}


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

result = (unsigned int)(3 - a2);
scroll = 3 - a2;
return result;
}

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

result = (unsigned int)(3 - a2);
scroll = 3 - a2;
return result;
}

original_code:
void pbaction_scroll_w(offs_t offset,data_t data)
{
 scroll = -(data-3);
}

canonical_original_code:
void pbaction_scroll_w(unsigned int offset, unsigned int data)
{
 scroll = -(data-3);
}


decompiled_code:
__int64 pbaction_interrupt()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 2LL;
}

original_code:
int pbaction_interrupt(void)
{
 return 0x02;
}

canonical_original_code:
int pbaction_interrupt()
{
 return 0x02;
}


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

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

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

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

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

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


decompiled_code:
__int64 pbaction_vh_start()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi
__int64 v4; // rax

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer2 = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v4 = 0LL;
if ( tmpbitmap2 )
{
do
{
*(_BYTE *)(palette_used_colors + v4) = 7;
v4 += 8LL;
}
while ( v4 != 128 );
}
else
{
free(dirtybuffer2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi
__int64 v4; // rax

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer2 = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v4 = 0LL;
if ( tmpbitmap2 )
{
do
{
*(_BYTE *)(palette_used_colors + v4) = 7;
v4 += 8LL;
}
while ( v4 != 128 );
}
else
{
free(dirtybuffer2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

original_code:
int pbaction_vh_start(void)
{
 int i;
 if (generic_vh_start() != 0)
  return 1;
 if ((dirtybuffer2 = (unsigned char*)malloc(videoram_size)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer2);
  generic_vh_stop();
  return 1;
 }
 for (i = 0;i < 16;i++) palette_used_colors[8 * i] = (4|(1|2));
 return 0;
}

canonical_original_code:
int pbaction_vh_start()
{
 int i;
 if (generic_vh_start() != 0)
  return 1;
 if ((dirtybuffer2 = (unsigned char *)malloc(videoram_size)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer2);
  generic_vh_stop();
  return 1;
 }
 for (i = 0;i < 16;i++) palette_used_colors[8 * i] = (4|(1|2));
 return 0;
}

variable_types: i int


decompiled_code:
__int64 pbaction_vh_stop()
{
bitmap_free(tmpbitmap2);
free(dirtybuffer2);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func6()
{
bitmap_free(tmpbitmap2);
free(dirtybuffer2);
return generic_vh_stop();
}

original_code:
void pbaction_vh_stop(void)
{
 bitmap_free(tmpbitmap2);
 free(dirtybuffer2);
 generic_vh_stop();
}

canonical_original_code:
void pbaction_vh_stop()
{
 bitmap_free(tmpbitmap2);
 free(dirtybuffer2);
 generic_vh_stop();
}


decompiled_code:
__int64 __fastcall pbaction_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // edi
int v5; // esi
__int64 v6; // r8
__int64 v7; // r9
int v8; // edi
int v9; // esi
__int64 v10; // r9
int v11; // ebp
__int64 i; // rbx
__int64 v13; // rdi
unsigned __int8 v14; // cl
__int64 v15; // r8
__int64 v16; // r9
__int64 v17; // r11
__int64 v18; // r10
__int64 v19; // rdx
__int64 v20; // rcx
unsigned int v21; // esi
signed int v22; // eax
int v23; // edx
int v24; // esi
unsigned __int8 v25; // al

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = v2 % 32;
v5 = v2 / 32;
v6 = *(_BYTE *)(colorram + v3) & 0x40;
v7 = *(_BYTE *)(colorram + v3) & 0x80;
if ( flipscreen )
{
v4 = 31 - v2 % 32;
v5 = 31 - v2 / 32;
v6 = (_DWORD)v6 == 0;
v7 = (_DWORD)v7 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + 16 * (*(_BYTE *)(colorram + v3) & 0x30u),
*(_BYTE *)(colorram + v3) & 0xF,
v6,
v7,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
}
if ( *((_BYTE *)dirtybuffer2 + v3) )
{
*((_BYTE *)dirtybuffer2 + v3) = 0;
v8 = v2 % 32;
v9 = v2 / 32;
v10 = *(_BYTE *)(pbaction_colorram2 + v3) & 0x80;
if ( flipscreen )
{
v8 = 31 - v2 % 32;
v9 = 31 - v2 / 32;
v10 = (_DWORD)v10 == 0;
}
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(pbaction_videoram2 + v3) + 16 * (*(_BYTE *)(pbaction_colorram2 + v3) & 0x70u),
*(_BYTE *)(pbaction_colorram2 + v3) & 0xF,
(unsigned int)flipscreen,
v10,
(unsigned int)(8 * v8),
(unsigned int)(8 * v9),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copyscrollbitmap(a1, tmpbitmap2, 1LL, &scroll, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v11 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
for ( i = v11 + 2LL; ; i -= 4LL )
{
if ( v11 > 0 && *(char *)(spriteram + i - 6) < 0 )
goto LABEL_22;
v24 = *(unsigned __int8 *)(spriteram + i + 1);
v25 = *(_BYTE *)(spriteram + i - 2);
if ( (v25 & 0x80u) == 0 )
break;
v13 = *(unsigned __int8 *)(spriteram + i);
v14 = *(_BYTE *)(spriteram + i - 1);
v15 = v14 & 0x40;
v16 = v14 & 0x80;
if ( flipscreen )
{
v23 = 224 - v24;
LABEL_20:
v15 = (_DWORD)v15 == 0;
v16 = (_DWORD)v16 == 0;
v17 = Machine;
v18 = Machine + 776LL;
v19 = (unsigned int)(scroll + v23);
v20 = v14 & 0xF;
v21 = v25;
v22 = ((unsigned int)(char)v25 >> 31) + 2;
goto LABEL_21;
}
v13 = (unsigned int)(225 - v13);
v17 = Machine;
v18 = Machine + 776LL;
v19 = (unsigned int)(scroll + v24);
v20 = *(_BYTE *)(spriteram + i - 1) & 0xF;
v21 = v25;
v22 = 3;
LABEL_21:
drawgfx(a1, *(_QWORD *)(v17 + 8LL * v22 + 512), v21, v20, v15, v16, v19, v13, v18, 2LL, 0LL);
LABEL_22:
v11 -= 4;
if ( v11 < 0 )
return copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
}
v13 = *(unsigned __int8 *)(spriteram + i);
v14 = *(_BYTE *)(spriteram + i - 1);
v15 = v14 & 0x40;
v16 = v14 & 0x80;
if ( !flipscreen )
{
v13 = (unsigned int)(241 - v13);
v17 = Machine;
v18 = Machine + 776LL;
v19 = (unsigned int)(scroll + v24);
v20 = *(_BYTE *)(spriteram + i - 1) & 0xF;
v21 = v25;
v22 = 2;
goto LABEL_21;
}
v23 = 240 - v24;
goto LABEL_20;
}
return copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // edi
int v5; // esi
__int64 v6; // r8
__int64 v7; // r9
int v8; // edi
int v9; // esi
__int64 v10; // r9
int v11; // ebp
__int64 i; // rbx
__int64 v13; // rdi
unsigned __int8 v14; // cl
__int64 v15; // r8
__int64 v16; // r9
__int64 v17; // r11
__int64 v18; // r10
__int64 v19; // rdx
__int64 v20; // rcx
unsigned int v21; // esi
signed int v22; // eax
int v23; // edx
int v24; // esi
unsigned __int8 v25; // al

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(dirtybuffer2, 1, videoram_size);
}
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = v2 % 32;
v5 = v2 / 32;
v6 = *(_BYTE *)(colorram + v3) & 0x40;
v7 = *(_BYTE *)(colorram + v3) & 0x80;
if ( flipscreen )
{
v4 = 31 - v2 % 32;
v5 = 31 - v2 / 32;
v6 = (_DWORD)v6 == 0;
v7 = (_DWORD)v7 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + 16 * (*(_BYTE *)(colorram + v3) & 0x30u),
*(_BYTE *)(colorram + v3) & 0xF,
v6,
v7,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
}
if ( *((_BYTE *)dirtybuffer2 + v3) )
{
*((_BYTE *)dirtybuffer2 + v3) = 0;
v8 = v2 % 32;
v9 = v2 / 32;
v10 = *(_BYTE *)(pbaction_colorram2 + v3) & 0x80;
if ( flipscreen )
{
v8 = 31 - v2 % 32;
v9 = 31 - v2 / 32;
v10 = (_DWORD)v10 == 0;
}
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(pbaction_videoram2 + v3) + 16 * (*(_BYTE *)(pbaction_colorram2 + v3) & 0x70u),
*(_BYTE *)(pbaction_colorram2 + v3) & 0xF,
(unsigned int)flipscreen,
v10,
(unsigned int)(8 * v8),
(unsigned int)(8 * v9),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copyscrollbitmap(a1, tmpbitmap2, 1LL, &scroll, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v11 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
for ( i = v11 + 2LL; ; i -= 4LL )
{
if ( v11 > 0 && *(char *)(spriteram + i - 6) < 0 )
goto LABEL_22;
v24 = *(unsigned __int8 *)(spriteram + i + 1);
v25 = *(_BYTE *)(spriteram + i - 2);
if ( (v25 & 0x80u) == 0 )
break;
v13 = *(unsigned __int8 *)(spriteram + i);
v14 = *(_BYTE *)(spriteram + i - 1);
v15 = v14 & 0x40;
v16 = v14 & 0x80;
if ( flipscreen )
{
v23 = 224 - v24;
LABEL_20:
v15 = (_DWORD)v15 == 0;
v16 = (_DWORD)v16 == 0;
v17 = Machine;
v18 = Machine + 776LL;
v19 = (unsigned int)(scroll + v23);
v20 = v14 & 0xF;
v21 = v25;
v22 = ((unsigned int)(char)v25 >> 31) + 2;
goto LABEL_21;
}
v13 = (unsigned int)(225 - v13);
v17 = Machine;
v18 = Machine + 776LL;
v19 = (unsigned int)(scroll + v24);
v20 = *(_BYTE *)(spriteram + i - 1) & 0xF;
v21 = v25;
v22 = 3;
LABEL_21:
drawgfx(a1, *(_QWORD *)(v17 + 8LL * v22 + 512), v21, v20, v15, v16, v19, v13, v18, 2LL, 0LL);
LABEL_22:
v11 -= 4;
if ( v11 < 0 )
return copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
}
v13 = *(unsigned __int8 *)(spriteram + i);
v14 = *(_BYTE *)(spriteram + i - 1);
v15 = v14 & 0x40;
v16 = v14 & 0x80;
if ( !flipscreen )
{
v13 = (unsigned int)(241 - v13);
v17 = Machine;
v18 = Machine + 776LL;
v19 = (unsigned int)(scroll + v24);
v20 = *(_BYTE *)(spriteram + i - 1) & 0xF;
v21 = v25;
v22 = 2;
goto LABEL_21;
}
v23 = 240 - v24;
goto LABEL_20;
}
return copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
}

original_code:
void pbaction_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
 {
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipx,flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x80;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 0x10 * (colorram[offs] & 0x30),
     colorram[offs] & 0x0f,
     flipx,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx,sy,flipy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipy = pbaction_colorram2[offs] & 0x80;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     pbaction_videoram2[offs] + 0x10 * (pbaction_colorram2[offs] & 0x70),
     pbaction_colorram2[offs] & 0x0f,
     flipscreen,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap2,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  if (offs > 0 && spriteram[offs - 4] & 0x80) continue;
  sx = spriteram[offs+3];
  if (spriteram[offs] & 0x80)
   sy = 225-spriteram[offs+2];
  else
   sy = 241-spriteram[offs+2];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen)
  {
   if (spriteram[offs] & 0x80)
   {
    sx = 224 - sx;
    sy = 225 - sy;
   }
   else
   {
    sx = 240 - sx;
    sy = 241 - sy;
   }
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[(spriteram[offs] & 0x80) ? 3 : 2],
    spriteram[offs],
    spriteram[offs + 1] & 0x0f,
    flipx,flipy,
    sx+scroll,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
}

canonical_original_code:
void pbaction_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
 {
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x80;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 0x10 * (colorram[offs] & 0x30),
     colorram[offs] & 0x0f,
     flipx,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx; int sy; int flipy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipy = pbaction_colorram2[offs] & 0x80;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     pbaction_videoram2[offs] + 0x10 * (pbaction_colorram2[offs] & 0x70),
     pbaction_colorram2[offs] & 0x0f,
     flipscreen,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap2,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  if (offs > 0 && spriteram[offs - 4] & 0x80) continue;
  sx = spriteram[offs+3];
  if (spriteram[offs] & 0x80)
   sy = 225-spriteram[offs+2];
  else
   sy = 241-spriteram[offs+2];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen)
  {
   if (spriteram[offs] & 0x80)
   {
    sx = 224 - sx;
    sy = 225 - sy;
   }
   else
   {
    sx = 240 - sx;
    sy = 241 - sy;
   }
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[(spriteram[offs] & 0x80) ? 3 : 2],
    spriteram[offs],
    spriteram[offs + 1] & 0x0f,
    flipx,flipy,
    sx+scroll,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
}

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 macross_protection_r()
{
int v0; // eax
unsigned int v1; // edx

v0 = respcount + 1;
v1 = resp[respcount];
if ( respcount + 1 >= 15 )
v0 = 0;
respcount = v0;
return v1;
}

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

v0 = respcount + 1;
v1 = resp[respcount];
if ( respcount + 1 >= 15 )
v0 = 0;
respcount = v0;
return v1;
}

original_code:
data_t macross_protection_r(offs_t offset)
{
 int res = resp[ respcount++ ];
 if (respcount >= 15) respcount = 0;
 return res;
}

canonical_original_code:
unsigned int macross_protection_r(unsigned int offset)
{
 int res = resp[ respcount++ ];
 if (respcount >= 15) respcount = 0;
 return res;
}

variable_types: res int


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 func3(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 func4(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 macross_vh_start()
{
__int64 v0; // rax
__int64 result; // rax

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

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

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

original_code:
int macross_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(macross_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;
 }
 macross_spriteram = macross_workram + 0x8000;
 return 0;
}

canonical_original_code:
int macross_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(macross_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;
 }
 macross_spriteram = macross_workram + 0x8000;
 return 0;
}


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

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

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

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


decompiled_code:
__int64 __fastcall macross_vh_screenrefresh(__int64 a1, _QWORD *a2)
{
int v2; // edx
__int64 v3; // rcx
_QWORD *v4; // rax
__int64 i; // rax
_QWORD *v6; // rdx
int v7; // ebx
__int64 v8; // rbp
__int64 j; // r15
__int16 v10; // r12
__int64 result; // rax
int v12; // ebp
int v13; // ebx
__int16 v14; // r13
unsigned __int16 v15; // ax
__int64 v16; // [rsp+8h] [rbp-50h]
int v17; // [rsp+14h] [rbp-44h]
__int16 v18; // [rsp+18h] [rbp-40h]
int v19; // [rsp+1Ch] [rbp-3Ch]

v16 = a1;
palette_init_used_colors();
v2 = (macross_txvideoram_size >> 1) - 1;
if ( v2 >= 0 )
{
v3 = 2 * v2;
a1 = (__int64)&palette_used_colors;
a2 = &macross_txvideoram;
do
{
v4 = (_QWORD *)(palette_used_colors + ((16 * ((*(_WORD *)(macross_txvideoram + v3) >> 12) + 32)) & 0x7F0));
*v4 = 0x303030303030303LL;
v4[1] = 0x303030303030303LL;
v3 -= 2LL;
--v2;
}
while ( v2 >= 0 );
}
for ( i = 0LL; i != 4096; i += 16LL )
{
v6 = (_QWORD *)macross_spriteram;
if ( *(_WORD *)(macross_spriteram + i) )
{
a2 = &palette_used_colors;
v6 = (_QWORD *)(palette_used_colors + 16 * (*(unsigned __int16 *)(macross_spriteram + i + 14) + 16));
a1 = 0x303030303030303LL;
*v6 = 0x303030303030303LL;
v6[1] = 0x303030303030303LL;
}
}
if ( palette_recalc(a1, a2, v6, &macross_spriteram) )
memset(dirtybuffer, 1, macross_txvideoram_size >> 1);
v7 = (macross_txvideoram_size >> 1) - 1;
if ( v7 >= 0 )
{
v8 = v7;
do
{
if ( *((_BYTE *)dirtybuffer + v8) )
{
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_WORD *)(macross_txvideoram + 2 * v7) & 0xFFF,
(int)*(unsigned __int16 *)(macross_txvideoram + 2 * v7) >> 12,
0LL,
0LL,
(unsigned int)(8 * (v7 / 32)),
(unsigned int)(8 * (v7 % 32)),
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + v8) = 0;
}
--v8;
--v7;
}
while ( v7 >= 0 );
}
copybitmap(v16, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( j = 14LL; j != 4110; j += 16LL )
{
result = macross_spriteram;
if ( *(_WORD *)(macross_spriteram + j - 14) )
{
v10 = *(_WORD *)(macross_spriteram + j - 6) & 0x1FF;
v18 = v10;
v14 = *(_WORD *)(macross_spriteram + j - 2) & 0x1FF;
v12 = *(unsigned __int16 *)(macross_spriteram + j - 8);
v15 = *(_WORD *)(macross_spriteram + j - 12);
v13 = (v15 & 0xF) + 1;
v19 = v13;
v17 = (unsigned __int16)((v15 >> 4) + 1);
while ( 1 )
{
while ( 1 )
{
result = drawgfx(
v16,
*(_QWORD *)(Machine + 528LL),
v12++ & 0x3FFF,
*(unsigned __int16 *)(macross_spriteram + j),
0LL,
0LL,
v10 & 0x1FF,
v14 & 0x1FF,
Machine + 776LL,
2LL,
15LL);
if ( !--v13 )
break;
v10 += 16;
}
v14 += 16;
if ( !--v17 )
break;
v13 = v19;
v10 = v18;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2)
{
int v2; // edx
__int64 v3; // rcx
_QWORD *v4; // rax
__int64 i; // rax
_QWORD *v6; // rdx
int v7; // ebx
__int64 v8; // rbp
__int64 j; // r15
__int16 v10; // r12
__int64 result; // rax
int v12; // ebp
int v13; // ebx
__int16 v14; // r13
unsigned __int16 v15; // ax
__int64 v16; // [rsp+8h] [rbp-50h]
int v17; // [rsp+14h] [rbp-44h]
__int16 v18; // [rsp+18h] [rbp-40h]
int v19; // [rsp+1Ch] [rbp-3Ch]

v16 = a1;
palette_init_used_colors();
v2 = (macross_txvideoram_size >> 1) - 1;
if ( v2 >= 0 )
{
v3 = 2 * v2;
a1 = (__int64)&palette_used_colors;
a2 = &macross_txvideoram;
do
{
v4 = (_QWORD *)(palette_used_colors + ((16 * ((*(_WORD *)(macross_txvideoram + v3) >> 12) + 32)) & 0x7F0));
*v4 = 0x303030303030303LL;
v4[1] = 0x303030303030303LL;
v3 -= 2LL;
--v2;
}
while ( v2 >= 0 );
}
for ( i = 0LL; i != 4096; i += 16LL )
{
v6 = (_QWORD *)macross_spriteram;
if ( *(_WORD *)(macross_spriteram + i) )
{
a2 = &palette_used_colors;
v6 = (_QWORD *)(palette_used_colors + 16 * (*(unsigned __int16 *)(macross_spriteram + i + 14) + 16));
a1 = 0x303030303030303LL;
*v6 = 0x303030303030303LL;
v6[1] = 0x303030303030303LL;
}
}
if ( palette_recalc(a1, a2, v6, &macross_spriteram) )
memset(dirtybuffer, 1, macross_txvideoram_size >> 1);
v7 = (macross_txvideoram_size >> 1) - 1;
if ( v7 >= 0 )
{
v8 = v7;
do
{
if ( *((_BYTE *)dirtybuffer + v8) )
{
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_WORD *)(macross_txvideoram + 2 * v7) & 0xFFF,
(int)*(unsigned __int16 *)(macross_txvideoram + 2 * v7) >> 12,
0LL,
0LL,
(unsigned int)(8 * (v7 / 32)),
(unsigned int)(8 * (v7 % 32)),
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + v8) = 0;
}
--v8;
--v7;
}
while ( v7 >= 0 );
}
copybitmap(v16, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( j = 14LL; j != 4110; j += 16LL )
{
result = macross_spriteram;
if ( *(_WORD *)(macross_spriteram + j - 14) )
{
v10 = *(_WORD *)(macross_spriteram + j - 6) & 0x1FF;
v18 = v10;
v14 = *(_WORD *)(macross_spriteram + j - 2) & 0x1FF;
v12 = *(unsigned __int16 *)(macross_spriteram + j - 8);
v15 = *(_WORD *)(macross_spriteram + j - 12);
v13 = (v15 & 0xF) + 1;
v19 = v13;
v17 = (unsigned __int16)((v15 >> 4) + 1);
while ( 1 )
{
while ( 1 )
{
result = drawgfx(
v16,
*(_QWORD *)(Machine + 528LL),
v12++ & 0x3FFF,
*(unsigned __int16 *)(macross_spriteram + j),
0LL,
0LL,
v10 & 0x1FF,
v14 & 0x1FF,
Machine + 776LL,
2LL,
15LL);
if ( !--v13 )
break;
v10 += 16;
}
v14 += 16;
if ( !--v17 )
break;
v13 = v19;
v10 = v18;
}
}
}
return result;
}

original_code:
void macross_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 palette_init_used_colors();
 for (offs = (macross_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  int color = ((*(UINT16 *)(&macross_txvideoram[offs*2])) >> 12);
  memset(&palette_used_colors[512 + 16 * color],(1|2),16);
 }
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(UINT16 *)(&macross_spriteram[offs])) != 0)
   memset(&palette_used_colors[256 + 16*(*(UINT16 *)(&macross_spriteram[offs+14]))],(1|2),16);
 }
 if (palette_recalc())
 {
  memset(dirtybuffer, 1, macross_txvideoram_size/2);
 }
 for (offs = (macross_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx = offs / 32;
   int sy = offs % 32;
   int tilecode = (*(UINT16 *)(&macross_txvideoram[offs*2]));
   if (flipscreen)
   {
    sx = 47-sx;
    sy = 31-sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     tilecode & 0xfff,
     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 *)(&macross_spriteram[offs])) != 0)
  {
   int sx = ((*(UINT16 *)(&macross_spriteram[offs+8])) & 0x1ff);
   int sy = ((*(UINT16 *)(&macross_spriteram[offs+12])) & 0x1ff);
   int tilecode = (*(UINT16 *)(&macross_spriteram[offs+6]));
   int xx = ((*(UINT16 *)(&macross_spriteram[offs+2])) & 0x0f) + 1;
   int yy = ((*(UINT16 *)(&macross_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 & 0x3fff,
       (*(UINT16 *)(&macross_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 macross_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 palette_init_used_colors();
 for (offs = (macross_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  int color = ((*(UINT16 *)(&macross_txvideoram[offs*2])) >> 12);
  memset(&palette_used_colors[512 + 16 * color],(1|2),16);
 }
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(unsigned short *)(&macross_spriteram[offs])) != 0)
   memset(&palette_used_colors[256 + 16*(*(unsigned short *)(&macross_spriteram[offs+14]))],(1|2),16);
 }
 if (palette_recalc())
 {
  memset(dirtybuffer, 1, macross_txvideoram_size/2);
 }
 for (offs = (macross_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx = offs / 32;
   int sy = offs % 32;
   int tilecode = (*(UINT16 *)(&macross_txvideoram[offs*2]));
   if (flipscreen)
   {
    sx = 47-sx;
    sy = 31-sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     tilecode & 0xfff,
     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 *)(&macross_spriteram[offs])) != 0)
  {
   int sx = ((*(UINT16 *)(&macross_spriteram[offs+8])) & 0x1ff);
   int sy = ((*(UINT16 *)(&macross_spriteram[offs+12])) & 0x1ff);
   int tilecode = (*(UINT16 *)(&macross_spriteram[offs+6]));
   int xx = ((*(UINT16 *)(&macross_spriteram[offs+2])) & 0x0f) + 1;
   int yy = ((*(UINT16 *)(&macross_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 & 0x3fff,
       (*(unsigned short *)(&macross_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: offs int

variable_types: color int

variable_types: tilecode 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 macross_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 func8(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 macross_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 macross_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:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 __fastcall macross_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 macross_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 macross_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;
  }
 }
}


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

original_code:
unsigned long macross_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 macross_address_map_sprites(unsigned __int64 a1)
{
return (a1 >> 18) & 4 | (a1 >> 16) & 2 | (a1 >> 4) & 1;
}

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


decompiled_code:
__int64 init_macross()
{
__int64 v0; // rbp
unsigned __int64 i; // rbx
__int64 v2; // rax
__int64 v3; // rbp
unsigned __int64 j; // rbx
__int64 v5; // rax
__int16 v6; // ax
__int64 result; // rax

v0 = memory_region(138LL);
for ( i = 0LL; (int)memory_region_length(138LL) > (int)i; ++i )
{
v2 = macross_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; ; j += 2LL )
{
result = memory_region_length(139LL);
if ( (int)result <= (int)j )
break;
v5 = macross_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;
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbp
unsigned __int64 i; // rbx
__int64 v2; // rax
__int64 v3; // rbp
unsigned __int64 j; // rbx
__int64 v5; // rax
__int16 v6; // ax
__int64 result; // rax

v0 = memory_region(138LL);
for ( i = 0LL; (int)memory_region_length(138LL) > (int)i; ++i )
{
v2 = func10(i);
*(_BYTE *)(v0 + i) = func3(*(_BYTE *)(v0 + i), &decode_data_bg_1[8 * v2]);
}
v3 = memory_region(139LL);
for ( j = 0LL; ; j += 2LL )
{
result = memory_region_length(139LL);
if ( (int)result <= (int)j )
break;
v5 = func11(j);
v6 = func4(
*(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;
}
return result;
}

variable_types:
rom
unsigned char *

variable_types: A int

variable_types:
tmp
unsigned short


decompiled_code:
void *init_solarfox()
{
void *result; // rax

nvram_init = (__int64)&hiscore_init_0;
mcr_sound_config = 1;
install_port_read_handler(0LL, 0LL, 0LL, solarfox_input_0_r);
install_port_read_handler(0LL, 1LL, 1LL, solarfox_input_1_r);
install_port_write_handler(0LL, 1LL, 1LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 16;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

nvram_init = (__int64)&hiscore_init_0;
mcr_sound_config = 1;
install_port_read_handler(0LL, 0LL, 0LL, solarfox_input_0_r);
install_port_read_handler(0LL, 1LL, 1LL, solarfox_input_1_r);
install_port_write_handler(0LL, 1LL, 1LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 16;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_solarfox(void)
{
 static const UINT8 hiscore_init[] = { 0,0,1,1,1,1,1,3,3,3,7 };
 nvram_init = hiscore_init;
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x00, 0x00, solarfox_input_0_r);
 install_port_read_handler(0, 0x01, 0x01, solarfox_input_1_r);
 install_port_write_handler(0, 0x01, 0x01, mcr_control_port_w);
 mcr12_sprite_xoffs = 16;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_solarfox()
{
 static unsigned char hiscore_init[] = { 0,0,1,1,1,1,1,3,3,3,7 };
 nvram_init = hiscore_init;
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x00, 0x00, solarfox_input_0_r);
 install_port_read_handler(0, 0x01, 0x01, solarfox_input_1_r);
 install_port_write_handler(0, 0x01, 0x01, mcr_control_port_w);
 mcr12_sprite_xoffs = 16;
 mcr12_sprite_xoffs_flip = 0;
}


decompiled_code:
void *init_kick()
{
void *result; // rax

nvram_init = 0LL;
mcr_sound_config = 1;
install_port_read_handler(0LL, 1LL, 1LL, kick_dial_r);
install_port_write_handler(0LL, 3LL, 3LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 16;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

nvram_init = 0LL;
mcr_sound_config = 1;
install_port_read_handler(0LL, 1LL, 1LL, kick_dial_r);
install_port_write_handler(0LL, 3LL, 3LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 16;
return result;
}

original_code:
static void init_kick(void)
{
 nvram_init = ((void *)0);
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x01, 0x01, kick_dial_r);
 install_port_write_handler(0, 0x03, 0x03, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 16;
}

canonical_original_code:
static void init_kick()
{
 nvram_init = ((void *)0);
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x01, 0x01, kick_dial_r);
 install_port_write_handler(0, 0x03, 0x03, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 16;
}


decompiled_code:
char solarfox_input_1_r()
{
char result; // al

if ( mcr_cocktail_flip )
result = readinputport(1LL) | 0xF0;
else
result = ((int)readinputport(1LL) >> 4) | 0xF0;
return result;
}

canonical_decompiled_code:
char func2()
{
char result; // al

if ( mcr_cocktail_flip )
result = readinputport(1LL) | 0xF0;
else
result = ((int)readinputport(1LL) >> 4) | 0xF0;
return result;
}

original_code:
static data_t solarfox_input_1_r(offs_t offset)
{
 if (mcr_cocktail_flip)
  return readinputport(1) | 0xf0;
 else
  return (readinputport(1) >> 4) | 0xf0;
}

canonical_original_code:
static unsigned int solarfox_input_1_r(unsigned int offset)
{
 if (mcr_cocktail_flip)
  return readinputport(1) | 0xf0;
 else
  return (readinputport(1) >> 4) | 0xf0;
}


decompiled_code:
__int64 solarfox_input_0_r()
{
int v1; // ebp
int v2; // ebx

if ( mcr_cocktail_flip )
return (unsigned int)readinputport(0LL) | 8;
v1 = readinputport(0LL);
v2 = readinputport(0LL);
return v1 & 0xFFFFFFE3 | (v2 >> 1) & 4 | (16 * (unsigned __int8)readinputport(2LL)) & 0x10 | 8;
}

canonical_decompiled_code:
__int64 func3()
{
int v1; // ebp
int v2; // ebx

if ( mcr_cocktail_flip )
return (unsigned int)readinputport(0LL) | 8;
v1 = readinputport(0LL);
v2 = readinputport(0LL);
return v1 & 0xFFFFFFE3 | (v2 >> 1) & 4 | (16 * (unsigned __int8)readinputport(2LL)) & 0x10 | 8;
}

original_code:
static data_t solarfox_input_0_r(offs_t offset)
{
 if (mcr_cocktail_flip)
  return readinputport(0) | 0x08;
 else
  return ((readinputport(0) & ~0x14) | 0x08) | ((readinputport(0) & 0x08) >> 1) | ((readinputport(2) & 0x01) << 4);
}

canonical_original_code:
static unsigned int solarfox_input_0_r(unsigned int offset)
{
 if (mcr_cocktail_flip)
  return readinputport(0) | 0x08;
 else
  return ((readinputport(0) & ~0x14) | 0x08) | ((readinputport(0) & 0x08) >> 1) | ((readinputport(2) & 0x01) << 4);
}


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

v0 = readinputport(1LL);
return v0 & 0xF | (unsigned int)(unsigned __int8)(16 * readinputport(6LL));
}

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

v0 = readinputport(1LL);
return v0 & 0xF | (unsigned int)(unsigned __int8)(16 * readinputport(6LL));
}

original_code:
static data_t kick_dial_r(offs_t offset)
{
 return (readinputport(1) & 0x0f) | ((readinputport(6) << 4) & 0xf0);
}

canonical_original_code:
static unsigned int kick_dial_r(unsigned int offset)
{
 return (readinputport(1) & 0x0f) | ((readinputport(6) << 4) & 0xf0);
}


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

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int vendetta_vh_start(void)
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int vendetta_vh_start()
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 vendetta_vh_stop()
{
K052109_vh_stop();
return K053247_vh_stop();
}

original_code:
void vendetta_vh_stop(void)
{
 K052109_vh_stop();
 K053247_vh_stop();
}

canonical_original_code:
void vendetta_vh_stop()
{
 K052109_vh_stop();
 K053247_vh_stop();
}


decompiled_code:
__int64 __fastcall vendetta_vh_screenrefresh(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_70C = K053251_get_palette_index(3LL);
dword_710 = K053251_get_palette_index(4LL);
K052109_tilemap_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_6FC = K053251_get_priority(3LL);
v4 = 2;
dword_700 = K053251_get_priority(4LL);
sortlayers((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
K052109_tilemap_draw(a1, v2, 65552LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053247_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_70C = K053251_get_palette_index(3LL);
dword_710 = K053251_get_palette_index(4LL);
K052109_tilemap_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_6FC = K053251_get_priority(3LL);
v4 = 2;
dword_700 = K053251_get_priority(4LL);
func2((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
K052109_tilemap_draw(a1, v2, 65552LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053247_sprites_draw(a1);
}

original_code:
void vendetta_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI3);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI4);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 K052109_tilemap_draw(bitmap,layer[0],0x10|(1<<16));
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053247_sprites_draw(bitmap);
}

canonical_original_code:
void vendetta_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI3);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI4);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 K052109_tilemap_draw(bitmap,layer[0],0x10|(1<<16));
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053247_sprites_draw(bitmap);
}

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

variable_types:
layer
int [3]


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

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

original_code:
data_t vendetta_sound_interrupt_r(offs_t offset)
{
 cpu_cause_interrupt( 1, 0xff );
 return 0x00;
}

canonical_original_code:
unsigned int vendetta_sound_interrupt_r(unsigned int offset)
{
 cpu_cause_interrupt( 1, 0xff );
 return 0x00;
}