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

if ( K052109_selected )
result = K052109_051960_w(a1);
else
result = K051316_0_w();
return result;
}

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

if ( K052109_selected )
result = K052109_051960_w(a1);
else
result = K051316_0_w();
return result;
}

original_code:
static void bottom9_bankedram1_w(offs_t offset,data_t data)
{
 if (K052109_selected) K052109_051960_w(offset,data);
 else K051316_0_w(offset,data);
}

canonical_original_code:
static void bottom9_bankedram1_w(unsigned int offset, unsigned int data)
{
 if (K052109_selected) K052109_051960_w(offset,data);
 else K051316_0_w(offset,data);
}


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

if ( K052109_selected )
result = K052109_051960_r((unsigned int)(a1 + 0x2000));
else
result = paletteram_r();
return result;
}

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

if ( K052109_selected )
result = K052109_051960_r((unsigned int)(a1 + 0x2000));
else
result = paletteram_r();
return result;
}

original_code:
static data_t bottom9_bankedram2_r(offs_t offset)
{
 if (K052109_selected) return K052109_051960_r(offset + 0x2000);
 else return paletteram_r(offset);
}

canonical_original_code:
static unsigned int bottom9_bankedram2_r(unsigned int offset)
{
 if (K052109_selected) return K052109_051960_r(offset + 0x2000);
 else return paletteram_r(offset);
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall bottom9_bankedram1_r(__int64 a1)
{
if ( K052109_selected )
return K052109_051960_r(a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
if ( K052109_selected )
return K052109_051960_r(a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

original_code:
static data_t bottom9_bankedram1_r(offs_t offset)
{
 if (K052109_selected)
  return K052109_051960_r(offset);
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}

canonical_original_code:
static unsigned int bottom9_bankedram1_r(unsigned int offset)
{
 if (K052109_selected)
  return K052109_051960_r(offset);
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}


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

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

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x3F00;
result = *((_DWORD *)&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;
 *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;
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *

return_type: void


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

*a3 = (*a2 >> 4) & 3;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

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

*a3 = (*a2 >> 4) & 3;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

original_code:
static void sprite_callback(int *code,int *color,int *priority,int *shadow)
{
 *priority = (*color & 0x30) >> 4;
 *color = sprite_colorbase + (*color & 0x0f);
}

canonical_original_code:
static void sprite_callback(int *code, int *color, int *priority, int *shadow)
{
 *priority = (*color & 0x30) >> 4;
 *color = sprite_colorbase + (*color & 0x0f);
}

variable_types:
priority
int *

variable_types:
shadow
int *


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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = zoom_colorbase + ((*a2 >> 2) & 0xFu);
*a2 = result;
return result;
}

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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = zoom_colorbase + ((*a2 >> 2) & 0xFu);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x03) << 8);
 *color = zoom_colorbase + ((*color & 0x3c) >> 2);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x03) << 8);
 *color = zoom_colorbase + ((*color & 0x3c) >> 2);
}


decompiled_code:
void __fastcall nmi_enable_w(__int64 a1, int a2)
{
nmienable = a2;
}

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

original_code:
static void nmi_enable_w(offs_t offset,data_t data)
{
 nmienable = data;
}

canonical_original_code:
static void nmi_enable_w(unsigned int offset, unsigned int data)
{
 nmienable = data;
}

variable_types:
data
unsigned int


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

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

variable_types: v int


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

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


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

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

variable_types:
RAM
unsigned char *


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

v2 = memory_region(129LL);
if ( (a2 & 1) == 0 )
usrintf_showmessage("bankswitch RAM bank 0");
if ( (a2 & 0x10) != 0 )
v3 = (a2 & 6) + 32;
else
v3 = (a2 & 0xE) + 16;
cpu_bankbase[1] = v2 + (v3 << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

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

v2 = memory_region(129LL);
if ( (a2 & 1) == 0 )
usrintf_showmessage("bankswitch RAM bank 0");
if ( (a2 & 0x10) != 0 )
v3 = (a2 & 6) + 32;
else
v3 = (a2 & 0xE) + 16;
cpu_bankbase[1] = v2 + (v3 << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs;
if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
 if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
 else offs = 0x10000 + (data & 0x0e) * 0x1000;
 { 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 bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs;
if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
 if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
 else offs = 0x10000 + (data & 0x0e) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: offs int


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

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

original_code:
data_t bublbobl_sharedram1_r(offs_t offset)
{
 return bublbobl_sharedram1[offset];
}

canonical_original_code:
unsigned int bublbobl_sharedram1_r(unsigned int offset)
{
 return bublbobl_sharedram1[offset];
}


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

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

original_code:
data_t bublbobl_sharedram2_r(offs_t offset)
{
 return bublbobl_sharedram2[offset];
}

canonical_original_code:
unsigned int bublbobl_sharedram2_r(unsigned int offset)
{
 return bublbobl_sharedram2[offset];
}


decompiled_code:
__int64 tokio_fake_r()
{
return 191LL;
}

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

original_code:
data_t tokio_fake_r(offs_t offset)
{
  return 0xbf;
}

canonical_original_code:
unsigned int tokio_fake_r(unsigned int offset)
{
  return 0xbf;
}


decompiled_code:
void bublbobl_sh_nmi_disable_w()
{
sound_nmi_enable = 0;
}

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

original_code:
void bublbobl_sh_nmi_disable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 0;
}

canonical_original_code:
void bublbobl_sh_nmi_disable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 0;
}


decompiled_code:
__int64 bublbobl_68705_portA_r()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

canonical_decompiled_code:
__int64 func6()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

original_code:
data_t bublbobl_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

canonical_original_code:
unsigned int bublbobl_68705_portA_r(unsigned int offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}


decompiled_code:
void __fastcall bublbobl_68705_portA_w(__int64 a1, char a2)
{
portA_out = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, char a2)
{
portA_out = a2;
}

original_code:
void bublbobl_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

canonical_original_code:
void bublbobl_68705_portA_w(unsigned int offset, unsigned int data)
{
 portA_out = data;
}


decompiled_code:
void __fastcall bublbobl_68705_ddrA_w(__int64 a1, char a2)
{
ddrA = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2)
{
ddrA = a2;
}

original_code:
void bublbobl_68705_ddrA_w(offs_t offset,data_t data)
{
 ddrA = data;
}

canonical_original_code:
void bublbobl_68705_ddrA_w(unsigned int offset, unsigned int data)
{
 ddrA = data;
}


decompiled_code:
__int64 bublbobl_68705_portB_r()
{
return (unsigned __int8)(ddrB & portB_out);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)(ddrB & portB_out);
}

original_code:
data_t bublbobl_68705_portB_r(offs_t offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}

canonical_original_code:
unsigned int bublbobl_68705_portB_r(unsigned int offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}


decompiled_code:
void __fastcall bublbobl_68705_ddrB_w(__int64 a1, char a2)
{
ddrB = a2;
}

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

original_code:
void bublbobl_68705_ddrB_w(offs_t offset,data_t data)
{
 ddrB = data;
}

canonical_original_code:
void bublbobl_68705_ddrB_w(unsigned int offset, unsigned int data)
{
 ddrB = data;
}


decompiled_code:
__int64 __fastcall bublbobl_vh_convert_color_prom(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx

result = *(_QWORD *)(Machine + 824LL);
v3 = *(unsigned int *)(result + 700);
if ( (_DWORD)v3 )
{
for ( result = 0LL; result != v3; ++result )
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx

result = *(_QWORD *)(Machine + 824LL);
v3 = *(unsigned int *)(result + 700);
if ( (_DWORD)v3 )
{
for ( result = 0LL; result != v3; ++result )
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
}
return result;
}

original_code:
void bublbobl_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->color_table_len;i++)
  colortable[i] = i ^ 0x0f;
}

canonical_original_code:
void bublbobl_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->color_table_len;i++)
  colortable[i] = i ^ 0x0f;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

result = bublbobl_video_enable;
bublbobl_video_enable[0] = 1;
return result;
}

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

result = bublbobl_video_enable;
bublbobl_video_enable[0] = 1;
return result;
}

original_code:
static void init_tokio(void)
{
 extern int bublbobl_video_enable;
 bublbobl_video_enable = 1;
}

canonical_original_code:
static void init_tokio()
{
 extern int bublbobl_video_enable;
 bublbobl_video_enable = 1;
}


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

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

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

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

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

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

variable_types:
ROM
unsigned char *


decompiled_code:
__int64 __fastcall bublbobl_bankswitch_w(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + ((((a2 ^ 4) & 7u) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
bublbobl_video_enable[0] = a2 & 0x40;
return flip_screen_w(0LL, a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + ((((a2 ^ 4) & 7u) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
bublbobl_video_enable[0] = a2 & 0x40;
return flip_screen_w(0LL, a2 & 0x80);
}

original_code:
void bublbobl_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&ROM[0x10000 + 0x4000 * ((data ^ 4) & 7)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 bublbobl_video_enable = data & 0x40;
 flip_screen_w(0,data & 0x80);
}

canonical_original_code:
void bublbobl_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&ROM[0x10000 + 0x4000 * ((data ^ 4) & 7)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 bublbobl_video_enable = data & 0x40;
 flip_screen_w(0,data & 0x80);
}


decompiled_code:
__int64 __fastcall tokio_videoctrl_w(__int64 a1, unsigned __int8 a2)
{
return flip_screen_w(0LL, a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 a2)
{
return flip_screen_w(0LL, a2 & 0x80);
}

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

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


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

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

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

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


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

sound_nmi_enable = 1;
result = (unsigned int)pending_nmi;
if ( pending_nmi )
{
result = cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

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

sound_nmi_enable = 1;
result = (unsigned int)pending_nmi;
if ( pending_nmi )
{
result = cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

original_code:
void bublbobl_sh_nmi_enable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(2,-2);
  pending_nmi = 0;
 }
}

canonical_original_code:
void bublbobl_sh_nmi_enable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(2,-2);
  pending_nmi = 0;
 }
}


decompiled_code:
__int64 __fastcall bublbobl_sound_command_w(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

original_code:
void bublbobl_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}

canonical_original_code:
void bublbobl_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}


decompiled_code:
__int64 bublbobl_m68705_interrupt()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(3LL, 0LL, 0LL);
else
cpu_set_irq_line(3LL, 0LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(3LL, 0LL, 0LL);
else
cpu_set_irq_line(3LL, 0LL, 1LL);
return 0LL;
}

original_code:
int bublbobl_m68705_interrupt(void)
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(3,0,0);
 else
  cpu_set_irq_line(3,0,1);
    return 0;
}

canonical_original_code:
int bublbobl_m68705_interrupt()
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(3,0,0);
 else
  cpu_set_irq_line(3,0,1);
    return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall bublbobl_68705_portB_w(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // eax
unsigned __int8 *v4; // rcx

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out | address & 0xFF00;
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
address = (unsigned __int8)address | ((unsigned __int8)portA_out << 8) & 0xF00;
if ( (ddrB & 0x10) != 0 && (a2 & 0x10) == 0 && (portB_out & 0x10) != 0 )
{
if ( (a2 & 8) != 0 )
{
if ( (address & 0x800) != 0 )
{
if ( (address & 0xC00) == 3072 )
latch = *(unsigned __int8 *)(bublbobl_sharedram2 + (address & 0x3FF));
}
else
{
latch = readinputport((address & 3u) + 1);
result = (unsigned __int8)ddrB;
}
}
else if ( (address & 0xC00) == 3072 )
{
*(_BYTE *)(bublbobl_sharedram2 + (address & 0x3FF)) = portA_out;
}
}
if ( (result & 0x20) != 0 && (a2 & 0x20) == 0 && (portB_out & 0x20) != 0 )
{
v3 = rand();
v4 = (unsigned __int8 *)bublbobl_sharedram2;
*(_BYTE *)(bublbobl_sharedram2 + 124LL) = v3 % 6;
cpu_irq_line_vector_w(0LL, 0LL, *v4);
result = cpu_set_irq_line(0LL, 0LL, 2LL);
}
portB_out = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // eax
unsigned __int8 *v4; // rcx

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out | address & 0xFF00;
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
address = (unsigned __int8)address | ((unsigned __int8)portA_out << 8) & 0xF00;
if ( (ddrB & 0x10) != 0 && (a2 & 0x10) == 0 && (portB_out & 0x10) != 0 )
{
if ( (a2 & 8) != 0 )
{
if ( (address & 0x800) != 0 )
{
if ( (address & 0xC00) == 3072 )
latch = *(unsigned __int8 *)(bublbobl_sharedram2 + (address & 0x3FF));
}
else
{
latch = readinputport((address & 3u) + 1);
result = (unsigned __int8)ddrB;
}
}
else if ( (address & 0xC00) == 3072 )
{
*(_BYTE *)(bublbobl_sharedram2 + (address & 0x3FF)) = portA_out;
}
}
if ( (result & 0x20) != 0 && (a2 & 0x20) == 0 && (portB_out & 0x20) != 0 )
{
v3 = rand();
v4 = (unsigned __int8 *)bublbobl_sharedram2;
*(_BYTE *)(bublbobl_sharedram2 + 124LL) = v3 % 6;
cpu_irq_line_vector_w(0LL, 0LL, *v4);
result = cpu_set_irq_line(0LL, 0LL, 2LL);
}
portB_out = a2;
return result;
}

original_code:
void bublbobl_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = (address & 0xff00) | portA_out;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  address = (address & 0x00ff) | ((portA_out & 0x0f) << 8);
 }
 if ((ddrB & 0x10) && (~data & 0x10) && (portB_out & 0x10))
 {
  if (data & 0x08)
  {
   if ((address & 0x0800) == 0x0000)
   {
    latch = readinputport((address & 3) + 1);
   }
   else if ((address & 0x0c00) == 0x0c00)
   {
    latch = bublbobl_sharedram2[address & 0x03ff];
   }
  }
  else
  {
   if ((address & 0x0c00) == 0x0c00)
   {
    bublbobl_sharedram2[address & 0x03ff] = portA_out;
   }
  }
 }
 if ((ddrB & 0x20) && (~data & 0x20) && (portB_out & 0x20))
 {
  bublbobl_sharedram2[0x7c] = rand()%6;
  cpu_irq_line_vector_w(0,0,bublbobl_sharedram2[0]);
  cpu_set_irq_line(0,0,2);
 }
 portB_out = data;
}

canonical_original_code:
void bublbobl_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = (address & 0xff00) | portA_out;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  address = (address & 0x00ff) | ((portA_out & 0x0f) << 8);
 }
 if ((ddrB & 0x10) && (~data & 0x10) && (portB_out & 0x10))
 {
  if (data & 0x08)
  {
   if ((address & 0x0800) == 0x0000)
   {
    latch = readinputport((address & 3) + 1);
   }
   else if ((address & 0x0c00) == 0x0c00)
   {
    latch = bublbobl_sharedram2[address & 0x03ff];
   }
  }
  else
  {
   if ((address & 0x0c00) == 0x0c00)
   {
    bublbobl_sharedram2[address & 0x03ff] = portA_out;
   }
  }
 }
 if ((ddrB & 0x20) && (~data & 0x20) && (portB_out & 0x20))
 {
  bublbobl_sharedram2[0x7c] = rand()%6;
  cpu_irq_line_vector_w(0,0,bublbobl_sharedram2[0]);
  cpu_set_irq_line(0,0,2);
 }
 portB_out = data;
}


decompiled_code:
void *init_bublbobl()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x8000), (const void *)(v0 + 0x10000), 0x4000uLL);
}

canonical_decompiled_code:
void *func23()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x8000), (const void *)(v0 + 0x10000), 0x4000uLL);
}

original_code:
static void init_bublbobl(void)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 memcpy(ROM+0x08000,ROM+0x10000,0x4000);
}

canonical_original_code:
static void init_bublbobl()
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 memcpy(ROM+0x08000,ROM+0x10000,0x4000);
}


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

result = (unsigned int)sound_nmi_enable;
if ( sound_nmi_enable )
return cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 1;
return result;
}

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

result = (unsigned int)sound_nmi_enable;
if ( sound_nmi_enable )
return cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 1;
return result;
}

original_code:
static void nmi_callback(int param)
{
 if (sound_nmi_enable) cpu_cause_interrupt(2,-2);
 else pending_nmi = 1;
}

variable_types: param int


irqhandler

decompiled_code:
__int64 __fastcall irqhandler(int a1)
{
return cpu_set_irq_line(2LL, 0LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
return cpu_set_irq_line(2LL, 0LL, a1 != 0);
}

original_code:
static void irqhandler(int irq)
{
 cpu_set_irq_line(2,0,irq ? 1 : 0);
}

variable_types: irq int


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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0xE00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0xE00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

original_code:
static void gradius3_tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
}

canonical_original_code:
static void gradius3_tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
}


decompiled_code:
__int64 __fastcall gradius3_sprite_callback(_DWORD *a1, int *a2, _DWORD *a3)
{
__int64 v3; // rax
int v4; // eax
__int64 result; // rax

v3 = (*a2 >> 5) & 3;
if ( gradius3_priority )
v4 = primask_1[v3 + 4];
else
v4 = primask_1[v3];
*a3 = v4;
*a1 |= ((unsigned __int16)*a2 << 13) & 0x2000;
result = sprite_colorbase + ((*a2 >> 1) & 0xFu);
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int *a2, _DWORD *a3)
{
__int64 v3; // rax
int v4; // eax
__int64 result; // rax

v3 = (*a2 >> 5) & 3;
if ( gradius3_priority )
v4 = primask_1[v3 + 4];
else
v4 = primask_1[v3];
*a3 = v4;
*a1 |= ((unsigned __int16)*a2 << 13) & 0x2000;
result = sprite_colorbase + ((*a2 >> 1) & 0xFu);
*a2 = result;
return result;
}

original_code:
static void gradius3_sprite_callback(int *code,int *color,int *priority_mask,int *shadow)
{
 static int primask[2][4] =
 {
  { 0xaa|0xf0, 0xaa, 0xaa|0xf0, 0xaa|0xcc|0xf0 },
  { 0xcc|0xf0, 0xf0, 0, 0xaa|0xcc|0xf0 }
 };
 int pri = ((*color & 0x60) >> 5);
 if (gradius3_priority == 0) *priority_mask = primask[0][pri];
 else *priority_mask = primask[1][pri];
 *code |= (*color & 0x01) << 13;
 *color = sprite_colorbase + ((*color & 0x1e) >> 1);
}

canonical_original_code:
static void gradius3_sprite_callback(int *code, int *color, int *priority_mask, int *shadow)
{
 static int primask[2][4] = {
  { 0xaa|0xf0, 0xaa, 0xaa|0xf0, 0xaa|0xcc|0xf0 },
  { 0xcc|0xf0, 0xf0, 0, 0xaa|0xcc|0xf0 }
 };
 int pri = ((*color & 0x60) >> 5);
 if (gradius3_priority == 0) *priority_mask = primask[0][pri];
 else *priority_mask = primask[1][pri];
 *code |= (*color & 0x01) << 13;
 *color = sprite_colorbase + ((*color & 0x1e) >> 1);
}

variable_types:
primask
int [2][4]

variable_types: pri int


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

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

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

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

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall cpuB_irqenable_w(__int64 a1, unsigned int a2)
{
if ( (a2 & 0xFF000000) == 0 )
irqBmask = (a2 >> 8) & 7;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned int a2)
{
if ( (a2 & 0xFF000000) == 0 )
irqBmask = (a2 >> 8) & 7;
}

original_code:
static void cpuB_irqenable_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
  irqBmask = (data >> 8) & 0x07;
}

canonical_original_code:
static void cpuB_irqenable_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
  irqBmask = (data >> 8) & 0x07;
}


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

result = (unsigned int)irqAen;
if ( irqAen )
result = 2LL;
return result;
}

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

result = (unsigned int)irqAen;
if ( irqAen )
result = 2LL;
return result;
}

original_code:
static int cpuA_interrupt(void)
{
 if (irqAen) return 2;
 return 0;
}

canonical_original_code:
static int cpuA_interrupt()
{
 if (irqAen) return 2;
 return 0;
}


decompiled_code:
__int64 __fastcall gradius3_gfxrom_r(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(138LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(138LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

original_code:
data_t gradius3_gfxrom_r(offs_t offset)
{
 unsigned char *gfxdata = memory_region(REGION_GFX2);
 return (gfxdata[offset+1] << 8) | gfxdata[offset];
}

canonical_original_code:
unsigned int gradius3_gfxrom_r(unsigned int offset)
{
 unsigned char *gfxdata = memory_region(REGION_GFX2);
 return (gfxdata[offset+1] << 8) | gfxdata[offset];
}

variable_types:
gfxdata
unsigned char *


decompiled_code:
__int64 gradius3_vh_start()
{
unsigned int v1; // er13
unsigned int i; // ebx
__int64 v3; // rax
__int64 v4; // rsi

layer_colorbase = 0x2000000000LL;
dword_BE0 = 48;
sprite_colorbase = 16;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, gradius3_tile_callback) )
return 1LL;
v1 = K051960_vh_start(138LL, 3LL, 2LL, 1LL, 0LL, gradius3_sprite_callback);
if ( v1 )
{
K052109_vh_stop();
return 1LL;
}
for ( i = 0; i != 0x4000; ++i )
{
v3 = memory_region(138LL);
v4 = i;
decodechar(*(_QWORD *)(Machine + 520LL), v4, v3, &spritelayout_2);
}
dirtychar = malloc(0x1000uLL);
if ( !dirtychar )
{
K052109_vh_stop();
K051960_vh_stop();
return 1LL;
}
memset(dirtychar, 1u, 0x1000uLL);
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v1; // er13
unsigned int i; // ebx
__int64 v3; // rax
__int64 v4; // rsi

layer_colorbase = 0x2000000000LL;
dword_BE0 = 48;
sprite_colorbase = 16;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, gradius3_tile_callback) )
return 1LL;
v1 = K051960_vh_start(138LL, 3LL, 2LL, 1LL, 0LL, gradius3_sprite_callback);
if ( v1 )
{
K052109_vh_stop();
return 1LL;
}
for ( i = 0; i != 0x4000; ++i )
{
v3 = memory_region(138LL);
v4 = i;
decodechar(*(_QWORD *)(Machine + 520LL), v4, v3, &spritelayout_2);
}
dirtychar = malloc(0x1000uLL);
if ( !dirtychar )
{
K052109_vh_stop();
K051960_vh_stop();
return 1LL;
}
memset(dirtychar, 1u, 0x1000uLL);
return v1;
}

variable_types: struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; }


decompiled_code:
void gradius3_vh_stop()
{
K052109_vh_stop();
K051960_vh_stop();
free(dirtychar);
dirtychar = 0LL;
}

canonical_decompiled_code:
void func10()
{
K052109_vh_stop();
K051960_vh_stop();
free(dirtychar);
dirtychar = 0LL;
}

original_code:
void gradius3_vh_stop(void)
{
 K052109_vh_stop();
 K051960_vh_stop();
 free(dirtychar);
 dirtychar = 0;
}

canonical_original_code:
void gradius3_vh_stop()
{
 K052109_vh_stop();
 K051960_vh_stop();
 free(dirtychar);
 dirtychar = 0;
}


decompiled_code:
__int64 __fastcall gradius3_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rsi

K052109_w(7552LL, 16LL);
K052109_w(7936LL, 50LL);
if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 4096; ++i )
{
while ( !*((_BYTE *)dirtychar + i) )
{
if ( ++i == 4096 )
goto LABEL_6;
}
*((_BYTE *)dirtychar + i) = 0;
v2 = (unsigned int)i;
decodechar(*(_QWORD *)(Machine + 512LL), v2, gradius3_gfxram, &charlayout_0);
}
LABEL_6:
tilemap_mark_all_tiles_dirty(0LL);
}
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
if ( gradius3_priority )
{
K052109_tilemap_draw(a1, 0LL, 65552LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 131088LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
K052109_tilemap_draw(a1, 0LL, 0x10000LL);
}
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rsi

K052109_w(7552LL, 16LL);
K052109_w(7936LL, 50LL);
if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 4096; ++i )
{
while ( !*((_BYTE *)dirtychar + i) )
{
if ( ++i == 4096 )
goto LABEL_6;
}
*((_BYTE *)dirtychar + i) = 0;
v2 = (unsigned int)i;
decodechar(*(_QWORD *)(Machine + 512LL), v2, gradius3_gfxram, &charlayout_0);
}
LABEL_6:
tilemap_mark_all_tiles_dirty(0LL);
}
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
if ( gradius3_priority )
{
K052109_tilemap_draw(a1, 0LL, 65552LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 131088LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
K052109_tilemap_draw(a1, 0LL, 0x10000LL);
}
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

original_code:
void gradius3_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 static struct GfxLayout charlayout =
 {
  8,8,
  0x1000,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 },
  { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
  32*8
 };
 K052109_w(0x1d80,0x10);
 K052109_w(0x1f00,0x32);
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x1000;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[0],i,gradius3_gfxram,&charlayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 if (gradius3_priority == 0)
 {
  K052109_tilemap_draw(bitmap,1,0x10|(2<<16));
  K052109_tilemap_draw(bitmap,2,4<<16);
  K052109_tilemap_draw(bitmap,0,1<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,0,0x10|(1<<16));
  K052109_tilemap_draw(bitmap,1,2<<16);
  K052109_tilemap_draw(bitmap,2,4<<16);
 }
 K051960_sprites_draw(bitmap,-1,-1);
}

canonical_original_code:
void gradius3_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 static struct GfxLayout charlayout = {
  8,8,
  0x1000,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 },
  { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
  32*8
 };
 K052109_w(0x1d80,0x10);
 K052109_w(0x1f00,0x32);
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x1000;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[0],i,gradius3_gfxram,&charlayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 if (gradius3_priority == 0)
 {
  K052109_tilemap_draw(bitmap,1,0x10|(2<<16));
  K052109_tilemap_draw(bitmap,2,4<<16);
  K052109_tilemap_draw(bitmap,0,1<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,0,0x10|(1<<16));
  K052109_tilemap_draw(bitmap,1,2<<16);
  K052109_tilemap_draw(bitmap,2,4<<16);
 }
 K051960_sprites_draw(bitmap,-1,-1);
}

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

user_defined_types: struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; }


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

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

original_code:
static void init_gradius3(void)
{
 konami_rom_deinterleave_2(REGION_GFX2);
}

canonical_original_code:
static void init_gradius3()
{
 konami_rom_deinterleave_2(REGION_GFX2);
}


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

result = cpu_set_reset_line(1LL, 1LL);
irqAen = 0;
irqBmask = 0;
return result;
}

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

result = cpu_set_reset_line(1LL, 1LL);
irqAen = 0;
irqBmask = 0;
return result;
}

original_code:
static void gradius3_init(void)
{
 cpu_set_reset_line(1,1);
 irqAen = 0;
 irqBmask = 0;
}

canonical_original_code:
static void gradius3_init()
{
 cpu_set_reset_line(1,1);
 irqAen = 0;
 irqBmask = 0;
}


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

if ( (cpu_getiloops() & 1) == 0 )
return irqBmask & 1;
result = irqBmask & 2;
if ( (irqBmask & 2) != 0 )
result = 2LL;
return result;
}

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

if ( (cpu_getiloops() & 1) == 0 )
return irqBmask & 1;
result = irqBmask & 2;
if ( (irqBmask & 2) != 0 )
result = 2LL;
return result;
}

original_code:
static int cpuB_interrupt(void)
{
 if (cpu_getiloops() & 1)
 {
  if (irqBmask & 2) return 2;
 }
 else
 {
  if (irqBmask & 1) return 1;
 }
 return 0;
}

canonical_original_code:
static int cpuB_interrupt()
{
 if (cpu_getiloops() & 1)
 {
  if (irqBmask & 2) return 2;
 }
 else
 {
  if (irqBmask & 1) return 1;
 }
 return 0;
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051960_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051960_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void K051960_halfword_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051960_w(offset >> 1,data & 0xff);
}

canonical_original_code:
static void K051960_halfword_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051960_w(offset >> 1,data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051937_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051937_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void K051937_halfword_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051937_w(offset >> 1,data & 0xff);
}

canonical_original_code:
static void K051937_halfword_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051937_w(offset >> 1,data & 0xff);
}


decompiled_code:
__int64 __fastcall K051960_halfword_r(unsigned int a1)
{
return K051960_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1)
{
return K051960_r(a1 >> 1);
}

original_code:
static data_t K051960_halfword_r(offs_t offset)
{
 return K051960_r(offset >> 1);
}

canonical_original_code:
static unsigned int K051960_halfword_r(unsigned int offset)
{
 return K051960_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall K051937_halfword_r(unsigned int a1)
{
return K051937_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1)
{
return K051937_r(a1 >> 1);
}

original_code:
static data_t K051937_halfword_r(offs_t offset)
{
 return K051937_r(offset >> 1);
}

canonical_original_code:
static unsigned int K051937_halfword_r(unsigned int offset)
{
 return K051937_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall K052109_halfword_r(unsigned int a1)
{
return K052109_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned int a1)
{
return K052109_r(a1 >> 1);
}

original_code:
static data_t K052109_halfword_r(offs_t offset)
{
 return K052109_r(offset >> 1);
}

canonical_original_code:
static unsigned int K052109_halfword_r(unsigned int offset)
{
 return K052109_r(offset >> 1);
}


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

if ( (irqBmask & 4) != 0 )
result = cpu_cause_interrupt(1LL, 4LL);
return result;
}

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

if ( (irqBmask & 4) != 0 )
result = cpu_cause_interrupt(1LL, 4LL);
return result;
}

original_code:
static void cpuB_irqtrigger_w(offs_t offset,data_t data)
{
 if (irqBmask & 4)
 {
  cpu_cause_interrupt(1,4);
 }
}

canonical_original_code:
static void cpuB_irqtrigger_w(unsigned int offset, unsigned int data)
{
 if (irqBmask & 4)
 {
  cpu_cause_interrupt(1,4);
 }
}


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

if ( (a2 & 0xFF000000) == 0 )
{
coin_counter_w(0LL, BYTE1(a2) & 1);
coin_counter_w(1LL, BYTE1(a2) & 2);
gradius3_priority = BYTE1(a2) & 4;
result = cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 11) ^ 1) & 1);
irqAen = (a2 >> 8) & 0x20;
}
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
{
coin_counter_w(0LL, BYTE1(a2) & 1);
coin_counter_w(1LL, BYTE1(a2) & 2);
gradius3_priority = BYTE1(a2) & 4;
result = cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 11) ^ 1) & 1);
irqAen = (a2 >> 8) & 0x20;
}
return result;
}

original_code:
static void cpuA_ctrl_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
 {
  data >>= 8;
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
  gradius3_priority = data & 0x04;
  cpu_set_reset_line(1,(data & 0x08) ? 0 : 1);
  irqAen = data & 0x20;
 }
}

canonical_original_code:
static void cpuA_ctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
 {
  data >>= 8;
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
  gradius3_priority = data & 0x04;
  cpu_set_reset_line(1,(data & 0x08) ? 0 : 1);
  irqAen = data & 0x20;
 }
}


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

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

original_code:
static data_t sharedram_r(offs_t offset)
{
 return (*(UINT16 *)(&sharedram[offset]));
}

canonical_original_code:
static unsigned int sharedram_r(unsigned int offset)
{
 return (*(unsigned short *)(&sharedram[offset]));
}


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

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


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

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


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

if ( (a2 & 0xFF000000) == 0 )
result = soundlatch_w(0LL, BYTE1(a2));
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
result = soundlatch_w(0LL, BYTE1(a2));
return result;
}

original_code:
static void sound_command_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
  soundlatch_w(0,(data >> 8) & 0xff);
}

canonical_original_code:
static void sound_command_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
  soundlatch_w(0,(data >> 8) & 0xff);
}


decompiled_code:
__int64 rainbow_interrupt()
{
return 4LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 4LL;
}

original_code:
int rainbow_interrupt(void)
{
 return 4;
}

canonical_original_code:
int rainbow_interrupt()
{
 return 4;
}


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

result = (unsigned int)(a1 + 1);
if ( a1 == 26 )
{
ChipOffset = 0;
}
else if ( a1 == 3072 )
{
FrameBank = (2 * a2) & 0x1FE;
}
else if ( !a1 && (_BYTE)a2 == 1 )
{
ChipOffset = 18768;
}
return result;
}

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

result = (unsigned int)(a1 + 1);
if ( a1 == 26 )
{
ChipOffset = 0;
}
else if ( a1 == 3072 )
{
FrameBank = (2 * a2) & 0x1FE;
}
else if ( !a1 && (_BYTE)a2 == 1 )
{
ChipOffset = 18768;
}
return result;
}

original_code:
void rainbow_c_chip_w(offs_t offset,data_t data)
{
  switch(offset+1)
  {
   case 0x001: if ((data & 0xff) == 1) ChipOffset = 0x4950;
          break;
    case 0x01b: ChipOffset = 0;
          break;
    case 0xc01: FrameBank = (data & 0xff) << 1;
       break;
  }
}

canonical_original_code:
void rainbow_c_chip_w(unsigned int offset, unsigned int data)
{
  switch(offset+1)
  {
   case 0x001: if ((data & 0xff) == 1) ChipOffset = 0x4950;
          break;
    case 0x01b: ChipOffset = 0;
          break;
    case 0xc01: FrameBank = (data & 0xff) << 1;
       break;
  }
}


decompiled_code:
__int64 jumping_latch_r()
{
return (unsigned int)jumping_latch;
}

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

original_code:
static data_t jumping_latch_r(offs_t offset)
{
 return jumping_latch;
}

canonical_original_code:
static unsigned int jumping_latch_r(unsigned int offset)
{
 return jumping_latch;
}


decompiled_code:
__int64 __fastcall rainbow_c_chip_r(unsigned int a1)
{
__int64 v1; // rdx
__int64 v2; // rax
int v3; // ecx
unsigned int v4; // eax
__int64 v5; // rsi
unsigned int v6; // eax
unsigned int v7; // er8
__int64 result; // rax

v1 = memory_region(154LL);
v2 = FrameBank + ChipOffset + ((16 * *(_WORD *)(cpu_bankbase[1] + 4168LL)) & 0xFF0);
v3 = *(unsigned __int8 *)(v1 + v2 + 1) + (*(unsigned __int8 *)(v1 + v2) << 8);
v4 = (*(unsigned __int8 *)(v1 + v2 + 2) << 8) + *(unsigned __int8 *)(v1 + v2 + 3) - v3;
v5 = v4;
if ( v4 )
{
if ( a1 >> 1 < v4 )
v5 = *(unsigned __int8 *)(v1 + v3 + (a1 >> 1));
else
v5 = 0LL;
}
v6 = a1 + 1;
if ( a1 + 1 > 0x2AB )
{
v7 = 1;
if ( a1 != 2050 )
return (unsigned int)v5;
return v7;
}
if ( v6 > 0x294 )
{
switch ( a1 )
{
case 0x294u:
case 0x296u:
return 0;
case 0x298u:
case 0x29Au:
result = 16LL;
break;
case 0x29Cu:
case 0x29Eu:
return 32;
case 0x2A0u:
return 48;
case 0x2A2u:
return 56;
case 0x2A4u:
return 64;
case 0x2A6u:
case 0x2A8u:
return 80;
case 0x2AAu:
return 96;
default:
return (unsigned int)v5;
}
return result;
}
if ( v6 > 0xD )
{
v7 = 255;
if ( a1 != 512 )
return (unsigned int)v5;
return v7;
}
if ( a1 == -1 )
return (unsigned int)v5;
switch ( a1 )
{
case 0u:
result = 255LL;
break;
case 6u:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_2_r(6LL, v5);
break;
case 8u:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_3_r(8LL, v5);
break;
case 0xAu:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_4_r(10LL, v5);
break;
case 0xCu:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_5_r(12LL, v5);
break;
default:
return (unsigned int)v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v1; // rdx
__int64 v2; // rax
int v3; // ecx
unsigned int v4; // eax
__int64 v5; // rsi
unsigned int v6; // eax
unsigned int v7; // er8
__int64 result; // rax

v1 = memory_region(154LL);
v2 = FrameBank + ChipOffset + ((16 * *(_WORD *)(cpu_bankbase[1] + 4168LL)) & 0xFF0);
v3 = *(unsigned __int8 *)(v1 + v2 + 1) + (*(unsigned __int8 *)(v1 + v2) << 8);
v4 = (*(unsigned __int8 *)(v1 + v2 + 2) << 8) + *(unsigned __int8 *)(v1 + v2 + 3) - v3;
v5 = v4;
if ( v4 )
{
if ( a1 >> 1 < v4 )
v5 = *(unsigned __int8 *)(v1 + v3 + (a1 >> 1));
else
v5 = 0LL;
}
v6 = a1 + 1;
if ( a1 + 1 > 0x2AB )
{
v7 = 1;
if ( a1 != 2050 )
return (unsigned int)v5;
return v7;
}
if ( v6 > 0x294 )
{
switch ( a1 )
{
case 0x294u:
case 0x296u:
return 0;
case 0x298u:
case 0x29Au:
result = 16LL;
break;
case 0x29Cu:
case 0x29Eu:
return 32;
case 0x2A0u:
return 48;
case 0x2A2u:
return 56;
case 0x2A4u:
return 64;
case 0x2A6u:
case 0x2A8u:
return 80;
case 0x2AAu:
return 96;
default:
return (unsigned int)v5;
}
return result;
}
if ( v6 > 0xD )
{
v7 = 255;
if ( a1 != 512 )
return (unsigned int)v5;
return v7;
}
if ( a1 == -1 )
return (unsigned int)v5;
switch ( a1 )
{
case 0u:
result = 255LL;
break;
case 6u:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_2_r(6LL, v5);
break;
case 8u:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_3_r(8LL, v5);
break;
case 0xAu:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_4_r(10LL, v5);
break;
case 0xCu:
if ( FrameBank )
return (unsigned int)v5;
result = input_port_5_r(12LL, v5);
break;
default:
return (unsigned int)v5;
}
return result;
}

original_code:
data_t rainbow_c_chip_r(offs_t offset)
{
  unsigned char *CROM = memory_region(REGION_USER1);
  int Address;
  int Data1,Data2;
  int ans;
  Address = ChipOffset
          + FrameBank
          + (((*(UINT16 *)(cpu_bankbase[1] + 0x1048)) & 0xFF) << 4);
  Data2 = (CROM[Address] << 8) + CROM[Address+1];
  Data1 = ((CROM[Address+2] << 8) + CROM[Address+3]) - Data2;
  if (Data1 == 0)
  {
   ans = 0;
  }
  else
  {
   if (Data1 <= (offset >> 1))
    {
     ans = 0;
    }
    else
    {
      ans = CROM[(offset >> 1) + Data2];
    }
  }
  switch(offset+1)
  {
   case 0x007: if (FrameBank==0) ans=input_port_2_r(offset);
                break;
    case 0x009: if (FrameBank==0) ans=input_port_3_r(offset);
                break;
    case 0x00b: if (FrameBank==0) ans=input_port_4_r(offset);
                break;
    case 0x00d: if (FrameBank==0) ans=input_port_5_r(offset);
                break;
    case 0x001: ans=0xff;
                break;
   case 0x201: ans=0xff;
                break;
    case 0x803: ans=0x01;
                break;
    case 0x295: ans=0;
       break;
    case 0x297: ans=0;
       break;
    case 0x299: ans=0x10;
       break;
    case 0x29b: ans=0x10;
       break;
    case 0x29d: ans=0x20;
       break;
    case 0x29f: ans=0x20;
       break;
    case 0x2a1: ans=0x30;
       break;
    case 0x2a3: ans=0x38;
       break;
    case 0x2a5: ans=0x40;
       break;
    case 0x2a7: ans=0x50;
       break;
    case 0x2a9: ans=0x50;
       break;
    case 0x2ab: ans=0x60;
       break;
  }
  return ans;
}

canonical_original_code:
unsigned int rainbow_c_chip_r(unsigned int offset)
{
  unsigned char *CROM = memory_region(REGION_USER1);
  int Address;
  int Data1; int Data2;
  int ans;
  Address = ChipOffset
          + FrameBank
          + (((*(unsigned short *)(cpu_bankbase[1] + 0x1048)) & 0xFF) << 4);
  Data2 = (CROM[Address] << 8) + CROM[Address+1];
  Data1 = ((CROM[Address+2] << 8) + CROM[Address+3]) - Data2;
  if (Data1 == 0)
  {
   ans = 0;
  }
  else
  {
   if (Data1 <= (offset >> 1))
    {
     ans = 0;
    }
    else
    {
      ans = CROM[(offset >> 1) + Data2];
    }
  }
  switch(offset+1)
  {
   case 0x007: if (FrameBank==0) ans=input_port_2_r(offset);
                break;
    case 0x009: if (FrameBank==0) ans=input_port_3_r(offset);
                break;
    case 0x00b: if (FrameBank==0) ans=input_port_4_r(offset);
                break;
    case 0x00d: if (FrameBank==0) ans=input_port_5_r(offset);
                break;
    case 0x001: ans=0xff;
                break;
   case 0x201: ans=0xff;
                break;
    case 0x803: ans=0x01;
                break;
    case 0x295: ans=0;
       break;
    case 0x297: ans=0;
       break;
    case 0x299: ans=0x10;
       break;
    case 0x29b: ans=0x10;
       break;
    case 0x29d: ans=0x20;
       break;
    case 0x29f: ans=0x20;
       break;
    case 0x2a1: ans=0x30;
       break;
    case 0x2a3: ans=0x38;
       break;
    case 0x2a5: ans=0x40;
       break;
    case 0x2a7: ans=0x50;
       break;
    case 0x2a9: ans=0x50;
       break;
    case 0x2ab: ans=0x60;
       break;
  }
  return ans;
}

variable_types:
CROM
unsigned char *

variable_types: Address int

variable_types: ans int


decompiled_code:
__int64 __fastcall rainbow_sound_w(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( !(_DWORD)a1 )
return rastan_sound_port_w(a1, a2);
if ( (_DWORD)a1 == 2 )
result = rastan_sound_comm_w(0LL, a2);
return result;
}

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

if ( !(_DWORD)a1 )
return rastan_sound_port_w(a1, a2);
if ( (_DWORD)a1 == 2 )
result = rastan_sound_comm_w(0LL, a2);
return result;
}

original_code:
static void rainbow_sound_w(offs_t offset,data_t data)
{
 if (offset == 0)
 {
  rastan_sound_port_w(0,data & 0xff);
 }
 else if (offset == 2)
 {
  rastan_sound_comm_w(0,data & 0xff);
 }
}

canonical_original_code:
static void rainbow_sound_w(unsigned int offset, unsigned int data)
{
 if (offset == 0)
 {
  rastan_sound_port_w(0,data & 0xff);
 }
 else if (offset == 2)
 {
  rastan_sound_comm_w(0,data & 0xff);
 }
}

variable_types:
data
unsigned int


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

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

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

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

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

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


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

if ( !a1 )
{
jumping_latch = a2;
result = cpu_cause_interrupt(1LL, 4294966296LL);
}
return result;
}

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

if ( !a1 )
{
jumping_latch = a2;
result = cpu_cause_interrupt(1LL, 4294966296LL);
}
return result;
}

original_code:
static void jumping_sound_w(offs_t offset,data_t data)
{
 if (offset == 0)
 {
  jumping_latch = data & 0xff;
  cpu_cause_interrupt(1,-1000);
 }
}

canonical_original_code:
static void jumping_sound_w(unsigned int offset, unsigned int data)
{
 if (offset == 0)
 {
  jumping_latch = data & 0xff;
  cpu_cause_interrupt(1,-1000);
 }
}


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

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

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

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

original_code:
static void rastan_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int banknum = ( data - 1 ) & 3;
 { if (5 >= 1 && 5 <= 16) { cpu_bankbase[5] = (UINT8 *)(&RAM[ 0x10000 + ( banknum * 0x4000 ) ]); if (ophw == 5) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void rastan_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int banknum = ( data - 1 ) & 3;
 { if (5 >= 1 && 5 <= 16) { cpu_bankbase[5] = (unsigned char *)(&RAM[ 0x10000 + ( banknum * 0x4000 ) ]); if (ophw == 5) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *

variable_types: banknum int


decompiled_code:
__int64 __fastcall strlcpy_retro__(_BYTE *a1, char *a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rcx
char v6; // dl

v3 = a3;
if ( !a3 )
{
LABEL_4:
result = v3;
if ( *a2 )
{
do
++result;
while ( a2[result - v3] );
}
return result;
}
result = 0LL;
v5 = a3 - 1;
if ( a3 == 1 )
{
LABEL_3:
*a1 = 0;
v3 = result;
goto LABEL_4;
}
while ( 1 )
{
v6 = *a2++;
*a1++ = v6;
if ( !v6 )
return result;
if ( ++result == v5 )
goto LABEL_3;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char *a2, __int64 a3)
{
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rcx
char v6; // dl

v3 = a3;
if ( !a3 )
{
LABEL_4:
result = v3;
if ( *a2 )
{
do
++result;
while ( a2[result - v3] );
}
return result;
}
result = 0LL;
v5 = a3 - 1;
if ( a3 == 1 )
{
LABEL_3:
*a1 = 0;
v3 = result;
goto LABEL_4;
}
while ( 1 )
{
v6 = *a2++;
*a1++ = v6;
if ( !v6 )
return result;
if ( ++result == v5 )
goto LABEL_3;
}
}

original_code:
size_t strlcpy_retro__(char *dest, const char *source, size_t size)
{
   size_t src_size = 0;
   size_t n = size;
   if (n)
      while (--n && (*dest++ = *source++)) src_size++;
   if (!n)
   {
      if (size) *dest = '\0';
      while (*source++) src_size++;
   }
   return src_size;
}

canonical_original_code:
unsigned long strlcpy_retro__(char *dest, char *source, unsigned long size)
{
   unsigned long src_size = 0;
   unsigned long n = size;
   if (n)
      while (--n && (*dest++ = *source++)) src_size++;
   if (!n)
   {
      if (size) *dest = '\0';
      while (*source++) src_size++;
   }
   return src_size;
}

variable_types:
dest
char *

variable_types:
source
char *

variable_types:
size
unsigned long

variable_types:
n
unsigned long

return_type: unsigned long


decompiled_code:
size_t __fastcall strlcat_retro__(const char *a1, char *a2, size_t a3)
{
size_t v4; // rbx
char *v5; // rdi
__int64 v6; // rdx

v4 = strlen(a1);
v5 = (char *)&a1[v4];
v6 = a3 - v4;
if ( v4 > a3 )
v6 = 0LL;
return v4 + strlcpy_retro__(v5, a2, v6);
}

canonical_decompiled_code:
size_t __fastcall func1(const char *a1, char *a2, size_t a3)
{
size_t v4; // rbx
char *v5; // rdi
__int64 v6; // rdx

v4 = strlen(a1);
v5 = (char *)&a1[v4];
v6 = a3 - v4;
if ( v4 > a3 )
v6 = 0LL;
return v4 + func0(v5, a2, v6);
}

original_code:
size_t strlcat_retro__(char *dest, const char *source, size_t size)
{
   size_t len = strlen(dest);
   dest += len;
   if (len > size)
      size = 0;
   else
      size -= len;
   return len + strlcpy_retro__(dest, source, size);
}

canonical_original_code:
unsigned long strlcat_retro__(char *dest, char *source, unsigned long size)
{
   unsigned long len = strlen(dest);
   dest += len;
   if (len > size)
      size = 0;
   else
      size -= len;
   return len + strlcpy_retro__(dest, source, size);
}

variable_types:
len
unsigned long


decompiled_code:
void __fastcall berzerk_irq_enable_w(__int64 a1, int a2)
{
irq_enabled = a2;
}

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

original_code:
void berzerk_irq_enable_w(offs_t offset,data_t data)
{
 irq_enabled = data;
}

canonical_original_code:
void berzerk_irq_enable_w(unsigned int offset, unsigned int data)
{
 irq_enabled = data;
}


decompiled_code:
void berzerk_nmi_enable_w()
{
nmi_enabled = 1;
}

canonical_decompiled_code:
void func1()
{
nmi_enabled = 1;
}

original_code:
void berzerk_nmi_enable_w(offs_t offset,data_t data)
{
 nmi_enabled = 1;
}

canonical_original_code:
void berzerk_nmi_enable_w(unsigned int offset, unsigned int data)
{
 nmi_enabled = 1;
}


decompiled_code:
void berzerk_nmi_disable_w()
{
nmi_enabled = 0;
}

canonical_decompiled_code:
void func2()
{
nmi_enabled = 0;
}

original_code:
void berzerk_nmi_disable_w(offs_t offset,data_t data)
{
 nmi_enabled = 0;
}

canonical_original_code:
void berzerk_nmi_disable_w(unsigned int offset, unsigned int data)
{
 nmi_enabled = 0;
}


decompiled_code:
__int64 berzerk_nmi_enable_r()
{
nmi_enabled = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
nmi_enabled = 1;
return 0LL;
}

original_code:
data_t berzerk_nmi_enable_r(offs_t offset)
{
 nmi_enabled = 1;
 return 0;
}

canonical_original_code:
unsigned int berzerk_nmi_enable_r(unsigned int offset)
{
 nmi_enabled = 1;
 return 0;
}


decompiled_code:
__int64 berzerk_nmi_disable_r()
{
nmi_enabled = 0;
return 0LL;
}

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

original_code:
data_t berzerk_nmi_disable_r(offs_t offset)
{
 nmi_enabled = 0;
 return 0;
}

canonical_original_code:
unsigned int berzerk_nmi_disable_r(unsigned int offset)
{
 nmi_enabled = 0;
 return 0;
}


decompiled_code:
__int64 berzerk_voiceboard_r()
{
return (unsigned __int8)(berzerkplayvoice != 0) << 6;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned __int8)(berzerkplayvoice != 0) << 6;
}

original_code:
data_t berzerk_voiceboard_r(offs_t offset)
{
   if (!berzerkplayvoice)
      return 0;
   else
      return 0x40;
}

canonical_original_code:
unsigned int berzerk_voiceboard_r(unsigned int offset)
{
   if (!berzerkplayvoice)
      return 0;
   else
      return 0x40;
}


decompiled_code:
__int64 berzerk_interrupt()
{
int v0; // eax
int v1; // edx
__int64 result; // rax

v0 = int_count;
v1 = int_count + 1;
int_count = v1;
if ( v1 <= 3 )
{
if ( v1 <= 0 )
goto LABEL_3;
LABEL_9:
berzerk_irq_end_of_screen = v1 == 7;
if ( nmi_enabled )
return 4294967294LL;
return 0xFFFFFFFFLL;
}
if ( (unsigned int)(v0 - 4) <= 2 )
goto LABEL_9;
if ( v1 != 8 )
{
LABEL_3:
berzerk_irq_end_of_screen = 1;
result = 252LL;
if ( irq_enabled )
return result;
return 0xFFFFFFFFLL;
}
int_count = 0;
berzerk_irq_end_of_screen = 0;
result = 252LL;
if ( !irq_enabled )
return 0xFFFFFFFFLL;
return result;
}

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

v0 = int_count;
v1 = int_count + 1;
int_count = v1;
if ( v1 <= 3 )
{
if ( v1 <= 0 )
goto LABEL_3;
LABEL_9:
berzerk_irq_end_of_screen = v1 == 7;
if ( nmi_enabled )
return 4294967294LL;
return 0xFFFFFFFFLL;
}
if ( (unsigned int)(v0 - 4) <= 2 )
goto LABEL_9;
if ( v1 != 8 )
{
LABEL_3:
berzerk_irq_end_of_screen = 1;
result = 252LL;
if ( irq_enabled )
return result;
return 0xFFFFFFFFLL;
}
int_count = 0;
berzerk_irq_end_of_screen = 0;
result = 252LL;
if ( !irq_enabled )
return 0xFFFFFFFFLL;
return result;
}

original_code:
int berzerk_interrupt(void)
{
 int_count++;
 switch (int_count)
 {
 default:
 case 4:
 case 8:
  if (int_count == 8)
  {
   berzerk_irq_end_of_screen = 0;
   int_count = 0;
  }
  else
  {
   berzerk_irq_end_of_screen = 1;
  }
  return irq_enabled ? 0xfc : -1;
 case 1:
 case 2:
 case 3:
 case 5:
 case 6:
 case 7:
  if (int_count == 7)
  {
   berzerk_irq_end_of_screen = 1;
  }
  else
  {
   berzerk_irq_end_of_screen = 0;
  }
  return nmi_enabled ? -2 : -1;
 }
}

canonical_original_code:
int berzerk_interrupt()
{
 int_count++;
 switch (int_count)
 {
 default:
 case 4:
 case 8:
  if (int_count == 8)
  {
   berzerk_irq_end_of_screen = 0;
   int_count = 0;
  }
  else
  {
   berzerk_irq_end_of_screen = 1;
  }
  return irq_enabled ? 0xfc : -1;
 case 1:
 case 2:
 case 3:
 case 5:
 case 6:
 case 7:
  if (int_count == 7)
  {
   berzerk_irq_end_of_screen = 1;
  }
  else
  {
   berzerk_irq_end_of_screen = 0;
  }
  return nmi_enabled ? -2 : -1;
 }
}


original_code:
static inline void copy_byte(int x, int y, int data, int col)
{
 UINT16 fore, back;
 if (y < 32) return;
 fore = Machine->pens[(col >> 4) & 0x0f];
 back = Machine->pens[0];
 plot_pixel(Machine->scrbitmap, x , y, (data & 0x80) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+1, y, (data & 0x40) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+2, y, (data & 0x20) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+3, y, (data & 0x10) ? fore : back);
 fore = Machine->pens[col & 0x0f];
 plot_pixel(Machine->scrbitmap, x+4, y, (data & 0x08) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+5, y, (data & 0x04) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+6, y, (data & 0x02) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+7, y, (data & 0x01) ? fore : back);
}

canonical_original_code:
static inline void copy_byte(int x, int y, int data, int col)
{
 unsigned short fore; unsigned short back;
 if (y < 32) return;
 fore = Machine->pens[(col >> 4) & 0x0f];
 back = Machine->pens[0];
 plot_pixel(Machine->scrbitmap, x , y, (data & 0x80) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+1, y, (data & 0x40) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+2, y, (data & 0x20) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+3, y, (data & 0x10) ? fore : back);
 fore = Machine->pens[col & 0x0f];
 plot_pixel(Machine->scrbitmap, x+4, y, (data & 0x08) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+5, y, (data & 0x04) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+6, y, (data & 0x02) ? fore : back);
 plot_pixel(Machine->scrbitmap, x+7, y, (data & 0x01) ? fore : back);
}

variable_types: x int

variable_types: y int

variable_types: data int

variable_types: col int

variable_types:
fore
unsigned short

variable_types:
back
unsigned short


decompiled_code:
void __fastcall berzerk_videoram_w(unsigned int a1, char a2)
{
*(_BYTE *)(videoram + a1) = a2;
copy_byte((unsigned __int8)(8 * a1), a1 >> 5, a2, *(unsigned __int8 *)(colorram + (a1 & 0x1F | (a1 >> 2) & 0x3FE0)));
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1, char a2)
{
*(_BYTE *)(videoram + a1) = a2;
func7((unsigned __int8)(8 * a1), a1 >> 5, a2, *(unsigned __int8 *)(colorram + (a1 & 0x1F | (a1 >> 2) & 0x3FE0)));
}

original_code:
void berzerk_videoram_w(offs_t offset,data_t data)
{
 int coloroffset, x, y;
 videoram[offset] = data;
 coloroffset = ((offset & 0xff80) >> 2) | (offset & 0x1f);
 y = (offset >> 5);
 x = (offset & 0x1f) << 3;
    copy_byte(x, y, data, colorram[coloroffset]);
}

canonical_original_code:
void berzerk_videoram_w(unsigned int offset, unsigned int data)
{
 int coloroffset; int x; int y;
 videoram[offset] = data;
 coloroffset = ((offset & 0xff80) >> 2) | (offset & 0x1f);
 y = (offset >> 5);
 x = (offset & 0x1f) << 3;
    copy_byte(x, y, data, colorram[coloroffset]);
}

variable_types:
offset
unsigned int

variable_types: coloroffset int


decompiled_code:
void __fastcall berzerk_colorram_w(unsigned int a1, char a2)
{
signed int v2; // ebp
int v3; // ebx
int v4; // er14
char v5; // dl

v2 = (unsigned __int8)(8 * a1);
v3 = (a1 >> 3) & 0xFC;
v4 = v3 + 4;
*(_BYTE *)(colorram + a1) = a2;
do
{
v5 = *(_BYTE *)(videoram + ((v2 >> 3) | (32 * v3)));
if ( v5 )
copy_byte(v2, v3, v5, a2);
++v3;
}
while ( v3 != v4 );
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, char a2)
{
signed int v2; // ebp
int v3; // ebx
int v4; // er14
char v5; // dl

v2 = (unsigned __int8)(8 * a1);
v3 = (a1 >> 3) & 0xFC;
v4 = v3 + 4;
*(_BYTE *)(colorram + a1) = a2;
do
{
v5 = *(_BYTE *)(videoram + ((v2 >> 3) | (32 * v3)));
if ( v5 )
func7(v2, v3, v5, a2);
++v3;
}
while ( v3 != v4 );
}

original_code:
void berzerk_colorram_w(offs_t offset,data_t data)
{
 int x, y, i;
 colorram[offset] = data;
 y = ((offset >> 3) & 0xfc);
 x = (offset & 0x1f) << 3;
 for (i = 0; i < 4; i++, y++)
 {
  int byte = videoram[(y << 5) | (x >> 3)];
  if (byte)
  {
   copy_byte(x, y, byte, data);
  }
 }
}

canonical_original_code:
void berzerk_colorram_w(unsigned int offset, unsigned int data)
{
 int x; int y; int i;
 colorram[offset] = data;
 y = ((offset >> 3) & 0xfc);
 x = (offset & 0x1f) << 3;
 for (i = 0; i < 4; i++, y++)
 {
  int byte = videoram[(y << 5) | (x >> 3)];
  if (byte)
  {
   copy_byte(x, y, byte, data);
  }
 }
}

variable_types: i int

variable_types: byte int


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

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return ((int)(unsigned __int8)a1 >> 5) & 2 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 1) & 8 | (2 * (_BYTE)a1) & 0x10 | (8 * (_BYTE)a1) & 0x20 | (32 * (_BYTE)a1) & 0x40 | ((unsigned __int8)a1 << 7) | v1;
}

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

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return ((int)(unsigned __int8)a1 >> 5) & 2 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 1) & 8 | (2 * (_BYTE)a1) & 0x10 | (8 * (_BYTE)a1) & 0x20 | (32 * (_BYTE)a1) & 0x40 | ((unsigned __int8)a1 << 7) | v1;
}

variable_types:
data
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall shifter_flopper(unsigned __int8 a1)
{
__int64 result; // rax

result = ((((int)a1 >> (magicram_control & 6)) | (unsigned __int16)(magicram_latch << (8 - (magicram_control & 6)))) & 0x1FF) >> (magicram_control & 1);
if ( (magicram_control & 8) != 0 )
result = (unsigned __int8)reverse_byte((unsigned __int8)result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
__int64 result; // rax

result = ((((int)a1 >> (magicram_control & 6)) | (unsigned __int16)(magicram_latch << (8 - (magicram_control & 6)))) & 0x1FF) >> (magicram_control & 1);
if ( (magicram_control & 8) != 0 )
result = (unsigned __int8)func10((unsigned __int8)result);
return result;
}

original_code:
static inline int shifter_flopper(unsigned char data)
{
 int shift_amount, outval;
 shift_amount = magicram_control & 0x06;
 outval = ((data >> shift_amount) | (magicram_latch << (8 - shift_amount))) & 0x1ff;
 outval >>= (magicram_control & 0x01);
 if (magicram_control & 0x08)
 {
  outval = reverse_byte(outval);
 }
 return outval;
}

canonical_original_code:
static inline int shifter_flopper(unsigned char data)
{
 int shift_amount; int outval;
 shift_amount = magicram_control & 0x06;
 outval = ((data >> shift_amount) | (magicram_latch << (8 - shift_amount))) & 0x1ff;
 outval >>= (magicram_control & 0x01);
 if (magicram_control & 0x08)
 {
  outval = reverse_byte(outval);
 }
 return outval;
}

variable_types: outval int


decompiled_code:
void __fastcall berzerk_magicram_w(__int64 a1, unsigned __int8 a2)
{
char v2; // al
unsigned int v3; // er9
int v4; // er8
char v5; // dl
int v6; // eax
_BYTE *v7; // rdi

v2 = shifter_flopper(a2);
magicram_latch = v4;
v5 = v2;
if ( !collision )
collision = (unsigned __int8)(v2 & *(_BYTE *)(videoram + v3));
v6 = magicram_control & 0xF0;
v7 = (_BYTE *)(v3 + berzerk_magicram);
if ( v6 == 128 )
{
*v7 = ~*(_BYTE *)(videoram + v3) & v5;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) <= 0x80 )
{
if ( v6 == 64 )
{
*v7 = *(_BYTE *)(videoram + v3) & v5;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) > 0x40 )
{
switch ( v6 )
{
case '`':
*v7 = ~(*(_BYTE *)(videoram + v3) ^ v5);
break;
case 'p':
*v7 = *(_BYTE *)(videoram + v3) | ~v5;
break;
case 'P':
*v7 = *(_BYTE *)(videoram + v3);
break;
}
goto LABEL_10;
}
if ( v6 == 32 )
{
*v7 = ~*(_BYTE *)(videoram + v3) | v5;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) > 0x20 )
{
if ( v6 == 48 )
*v7 = -1;
goto LABEL_10;
}
if ( (magicram_control & 0xF0) != 0 )
{
if ( v6 == 16 )
*v7 = *(_BYTE *)(videoram + v3) | v5;
goto LABEL_10;
}
LABEL_22:
*v7 = v5;
goto LABEL_10;
}
if ( v6 == 192 )
{
*v7 = 0;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) <= 0xC0 )
{
switch ( v6 )
{
case 160:
*v7 = ~*(_BYTE *)(videoram + v3);
break;
case 176:
*v7 = ~(*(_BYTE *)(videoram + v3) & v5);
break;
case 144:
*v7 = *(_BYTE *)(videoram + v3) ^ v5;
break;
}
}
else
{
switch ( v6 )
{
case 224:
*v7 = ~(*(_BYTE *)(videoram + v3) | v5);
break;
case 240:
v5 = ~v5;
goto LABEL_22;
case 208:
*v7 = *(_BYTE *)(videoram + v3) & ~v5;
break;
}
}
LABEL_10:
berzerk_videoram_w(v3, *(_BYTE *)(berzerk_magicram + v3));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, unsigned __int8 a2)
{
char v2; // al
unsigned int v3; // er9
int v4; // er8
char v5; // dl
int v6; // eax
_BYTE *v7; // rdi

v2 = func11(a2);
magicram_latch = v4;
v5 = v2;
if ( !collision )
collision = (unsigned __int8)(v2 & *(_BYTE *)(videoram + v3));
v6 = magicram_control & 0xF0;
v7 = (_BYTE *)(v3 + berzerk_magicram);
if ( v6 == 128 )
{
*v7 = ~*(_BYTE *)(videoram + v3) & v5;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) <= 0x80 )
{
if ( v6 == 64 )
{
*v7 = *(_BYTE *)(videoram + v3) & v5;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) > 0x40 )
{
switch ( v6 )
{
case '`':
*v7 = ~(*(_BYTE *)(videoram + v3) ^ v5);
break;
case 'p':
*v7 = *(_BYTE *)(videoram + v3) | ~v5;
break;
case 'P':
*v7 = *(_BYTE *)(videoram + v3);
break;
}
goto LABEL_10;
}
if ( v6 == 32 )
{
*v7 = ~*(_BYTE *)(videoram + v3) | v5;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) > 0x20 )
{
if ( v6 == 48 )
*v7 = -1;
goto LABEL_10;
}
if ( (magicram_control & 0xF0) != 0 )
{
if ( v6 == 16 )
*v7 = *(_BYTE *)(videoram + v3) | v5;
goto LABEL_10;
}
LABEL_22:
*v7 = v5;
goto LABEL_10;
}
if ( v6 == 192 )
{
*v7 = 0;
goto LABEL_10;
}
if ( (magicram_control & 0xF0u) <= 0xC0 )
{
switch ( v6 )
{
case 160:
*v7 = ~*(_BYTE *)(videoram + v3);
break;
case 176:
*v7 = ~(*(_BYTE *)(videoram + v3) & v5);
break;
case 144:
*v7 = *(_BYTE *)(videoram + v3) ^ v5;
break;
}
}
else
{
switch ( v6 )
{
case 224:
*v7 = ~(*(_BYTE *)(videoram + v3) | v5);
break;
case 240:
v5 = ~v5;
goto LABEL_22;
case 208:
*v7 = *(_BYTE *)(videoram + v3) & ~v5;
break;
}
}
LABEL_10:
func8(v3, *(_BYTE *)(berzerk_magicram + v3));
}

original_code:
void berzerk_magicram_w(offs_t offset,data_t data)
{
 int data2;
 data2 = shifter_flopper(data);
 magicram_latch = data;
 if (!collision)
 {
  collision = (data2 & videoram[offset]);
 }
 switch (magicram_control & 0xf0)
 {
 case 0x00: berzerk_magicram[offset] = data2; break;
 case 0x10: berzerk_magicram[offset] = data2 | videoram[offset]; break;
 case 0x20: berzerk_magicram[offset] = data2 | ~videoram[offset]; break;
 case 0x30: berzerk_magicram[offset] = 0xff; break;
 case 0x40: berzerk_magicram[offset] = data2 & videoram[offset]; break;
 case 0x50: berzerk_magicram[offset] = videoram[offset]; break;
 case 0x60: berzerk_magicram[offset] = ~(data2 ^ videoram[offset]); break;
 case 0x70: berzerk_magicram[offset] = ~data2 | videoram[offset]; break;
 case 0x80: berzerk_magicram[offset] = data2 & ~videoram[offset]; break;
 case 0x90: berzerk_magicram[offset] = data2 ^ videoram[offset]; break;
 case 0xa0: berzerk_magicram[offset] = ~videoram[offset]; break;
 case 0xb0: berzerk_magicram[offset] = ~(data2 & videoram[offset]); break;
 case 0xc0: berzerk_magicram[offset] = 0x00; break;
 case 0xd0: berzerk_magicram[offset] = ~data2 & videoram[offset]; break;
 case 0xe0: berzerk_magicram[offset] = ~(data2 | videoram[offset]); break;
 case 0xf0: berzerk_magicram[offset] = ~data2; break;
 }
 berzerk_videoram_w(offset, berzerk_magicram[offset]);
}

canonical_original_code:
void berzerk_magicram_w(unsigned int offset, unsigned int data)
{
 int data2;
 data2 = shifter_flopper(data);
 magicram_latch = data;
 if (!collision)
 {
  collision = (data2 & videoram[offset]);
 }
 switch (magicram_control & 0xf0)
 {
 case 0x00: berzerk_magicram[offset] = data2; break;
 case 0x10: berzerk_magicram[offset] = data2 | videoram[offset]; break;
 case 0x20: berzerk_magicram[offset] = data2 | ~videoram[offset]; break;
 case 0x30: berzerk_magicram[offset] = 0xff; break;
 case 0x40: berzerk_magicram[offset] = data2 & videoram[offset]; break;
 case 0x50: berzerk_magicram[offset] = videoram[offset]; break;
 case 0x60: berzerk_magicram[offset] = ~(data2 ^ videoram[offset]); break;
 case 0x70: berzerk_magicram[offset] = ~data2 | videoram[offset]; break;
 case 0x80: berzerk_magicram[offset] = data2 & ~videoram[offset]; break;
 case 0x90: berzerk_magicram[offset] = data2 ^ videoram[offset]; break;
 case 0xa0: berzerk_magicram[offset] = ~videoram[offset]; break;
 case 0xb0: berzerk_magicram[offset] = ~(data2 & videoram[offset]); break;
 case 0xc0: berzerk_magicram[offset] = 0x00; break;
 case 0xd0: berzerk_magicram[offset] = ~data2 & videoram[offset]; break;
 case 0xe0: berzerk_magicram[offset] = ~(data2 | videoram[offset]); break;
 case 0xf0: berzerk_magicram[offset] = ~data2; break;
 }
 berzerk_videoram_w(offset, berzerk_magicram[offset]);
}

variable_types:
data
unsigned int


decompiled_code:
void __fastcall berzerk_magicram_control_w(__int64 a1, int a2)
{
magicram_control = a2;
magicram_latch = 0;
collision = 0;
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, int a2)
{
magicram_control = a2;
magicram_latch = 0;
collision = 0;
}

original_code:
void berzerk_magicram_control_w(offs_t offset,data_t data)
{
 magicram_control = data;
 magicram_latch = 0;
 collision = 0;
}

canonical_original_code:
void berzerk_magicram_control_w(unsigned int offset, unsigned int data)
{
 magicram_control = data;
 magicram_latch = 0;
 collision = 0;
}


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

v0 = collision;
if ( collision )
v0 = 128;
return berzerk_irq_end_of_screen | (unsigned int)v0;
}

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

v0 = collision;
if ( collision )
v0 = 128;
return berzerk_irq_end_of_screen | (unsigned int)v0;
}

original_code:
data_t berzerk_collision_r(offs_t offset)
{
 int ret = (collision ? 0x80 : 0x00);
 return ret | berzerk_irq_end_of_screen;
}

canonical_original_code:
unsigned int berzerk_collision_r(unsigned int offset)
{
 int ret = (collision ? 0x80 : 0x00);
 return ret | berzerk_irq_end_of_screen;
}

variable_types: ret int


decompiled_code:
__int64 berzerk_sh_start()
{
__int64 v0; // rsi
_QWORD *v1; // rax
char v2; // dl
_QWORD *v3; // rsi
int v4; // ecx

berzerknoisemulate = 1;
v0 = *(_QWORD *)(Machine + 848LL);
if ( v0 )
{
v1 = (_QWORD *)(v0 + 8);
v2 = 0;
v3 = (_QWORD *)(v0 + 48);
v4 = 1;
do
{
if ( *v1 )
v2 = 1;
if ( *v1 )
v4 = 0;
++v1;
}
while ( v1 != v3 );
if ( v2 )
berzerknoisemulate = v4;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 v0; // rsi
_QWORD *v1; // rax
char v2; // dl
_QWORD *v3; // rsi
int v4; // ecx

berzerknoisemulate = 1;
v0 = *(_QWORD *)(Machine + 848LL);
if ( v0 )
{
v1 = (_QWORD *)(v0 + 8);
v2 = 0;
v3 = (_QWORD *)(v0 + 48);
v4 = 1;
do
{
if ( *v1 )
v2 = 1;
if ( *v1 )
v4 = 0;
++v1;
}
while ( v1 != v3 );
if ( v2 )
berzerknoisemulate = v4;
}
return 0LL;
}

original_code:
int berzerk_sh_start(const struct MachineSound *msound)
{
 int i;
 berzerknoisemulate = 1;
 if (Machine->samples)
 {
  for (i = 0;i < 5;i++)
  {
   if (Machine->samples->sample[i])
    berzerknoisemulate = 0;
  }
 }
 return 0;
}

canonical_original_code:
int berzerk_sh_start(struct MachineSound *msound)
{
 int i;
 berzerknoisemulate = 1;
 if (Machine->samples)
 {
  for (i = 0;i < 5;i++)
  {
   if (Machine->samples->sample[i])
    berzerknoisemulate = 0;
  }
 }
 return 0;
}

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


decompiled_code:
_DWORD *berzerk_init_machine()
{
__int64 i; // rbx
_DWORD *result; // rax

for ( i = 14336LL; i != 0x4000; ++i )
*(_BYTE *)(memory_region(129LL) + i) = -1;
result = &berzerk_irq_end_of_screen;
irq_enabled = 0;
nmi_enabled = 0;
berzerk_irq_end_of_screen = 0;
int_count = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func18()
{
__int64 i; // rbx
_DWORD *result; // rax

for ( i = 14336LL; i != 0x4000; ++i )
*(_BYTE *)(memory_region(129LL) + i) = -1;
result = &berzerk_irq_end_of_screen;
irq_enabled = 0;
nmi_enabled = 0;
berzerk_irq_end_of_screen = 0;
int_count = 0;
return result;
}

original_code:
void berzerk_init_machine(void)
{
 int i;
 for (i = 0x3800; i < 0x4000; i++)
  memory_region(REGION_CPU1)[i] = 0xff;
 irq_enabled = 0;
 nmi_enabled = 0;
 berzerk_irq_end_of_screen = 0;
 int_count = 0;
}

canonical_original_code:
void berzerk_init_machine()
{
 int i;
 for (i = 0x3800; i < 0x4000; i++)
  memory_region(REGION_CPU1)[i] = 0xff;
 irq_enabled = 0;
 nmi_enabled = 0;
 berzerk_irq_end_of_screen = 0;
 int_count = 0;
}


decompiled_code:
__int64 berzerk_led_on_r()
{
osd_led_w(0LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func19()
{
osd_led_w(0LL, 1LL);
return 0LL;
}

original_code:
data_t berzerk_led_on_r(offs_t offset)
{
 osd_led_w(0,1);
 return 0;
}

canonical_original_code:
unsigned int berzerk_led_on_r(unsigned int offset)
{
 osd_led_w(0,1);
 return 0;
}


decompiled_code:
__int64 berzerk_led_off_r()
{
osd_led_w(0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
osd_led_w(0LL, 0LL);
return 0LL;
}

original_code:
data_t berzerk_led_off_r(offs_t offset)
{
 osd_led_w(0,0);
 return 0;
}

canonical_original_code:
unsigned int berzerk_led_off_r(unsigned int offset)
{
 osd_led_w(0,0);
 return 0;
}


decompiled_code:
void __fastcall berzerk_sound_control_a_w(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned int v3; // ebx

if ( a1 <= 2 )
return;
if ( a1 == 4 )
{
v2 = a2;
if ( (a2 & 0x40) != 0 )
{
if ( (a2 & 0x38) != 0 )
voicevolume = 255;
else
voicevolume = 0;
switch ( a2 & 7 )
{
case 0u:
samplefrequency = 17640LL;
break;
case 1u:
samplefrequency = 19404LL;
break;
case 2u:
samplefrequency = 20947LL;
break;
case 3u:
samplefrequency = 22050LL;
break;
case 4u:
samplefrequency = 26019LL;
break;
case 5u:
samplefrequency = 27783LL;
break;
case 6u:
samplefrequency = 31250LL;
break;
case 7u:
samplefrequency = 34700LL;
break;
}
return;
}
berzerkplayvoice = 0;
if ( berzerknoisemulate )
return;
v3 = lastnoise;
goto LABEL_12;
}
if ( ((a1 - 3) & 0xFFFFFFFD) != 0 )
{
v2 = berzerknoisemulate;
if ( a2 - 61 <= 0xA && a1 == 6 )
{
if ( berzerknoisemulate )
return;
v3 = a2;
if ( lastnoise != a2 )
{
switch ( a2 )
{
case 'F':
switch ( deathsound )
{
case 1:
sample_start(2LL, 33LL, 0LL);
deathsound = 0;
goto LABEL_29;
case 2:
sample_start(6LL, 34LL, 0LL);
deathsound = 3;
goto LABEL_29;
case 0:
sample_start(2LL, 31LL, 0LL);
goto LABEL_29;
}
break;
case 'G':
sample_start(3LL, 32LL, 0LL);
goto LABEL_29;
case 'E':
sample_start(1LL, 30LL, 0LL);
goto LABEL_29;
}
LABEL_12:
lastnoise = v3;
if ( a1 == 4 && deathsound <= 1 )
{
if ( lastvoice == 24 && v2 == 27 )
{
lastvoice = 27;
}
else
{
sample_start(5LL, v2, 0LL);
sample_set_freq(5LL, samplefrequency);
lastvoice = v2;
}
}
return;
}
}
else
{
if ( berzerknoisemulate )
return;
v3 = lastnoise;
if ( a1 != 6 )
goto LABEL_12;
}
LABEL_29:
lastnoise = v3;
return;
}
if ( lastnoise == 70 )
{
if ( a2 == 172 && a1 == 3 )
{
nextdata5 = 25;
return;
}
if ( a1 == 5 )
{
if ( nextdata5 == a2 )
{
deathsound = 2;
goto LABEL_43;
}
LABEL_40:
nextdata5 = -1;
return;
}
}
else if ( lastnoise == 69 )
{
if ( a2 == 50 && a1 == 3 )
{
nextdata5 = 50;
return;
}
if ( a1 == 5 )
{
if ( nextdata5 == a2 )
{
LABEL_43:
lastnoise = 64;
goto LABEL_40;
}
goto LABEL_40;
}
}
}

canonical_decompiled_code:
void __fastcall func21(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned int v3; // ebx

if ( a1 <= 2 )
return;
if ( a1 == 4 )
{
v2 = a2;
if ( (a2 & 0x40) != 0 )
{
if ( (a2 & 0x38) != 0 )
voicevolume = 255;
else
voicevolume = 0;
switch ( a2 & 7 )
{
case 0u:
samplefrequency = 17640LL;
break;
case 1u:
samplefrequency = 19404LL;
break;
case 2u:
samplefrequency = 20947LL;
break;
case 3u:
samplefrequency = 22050LL;
break;
case 4u:
samplefrequency = 26019LL;
break;
case 5u:
samplefrequency = 27783LL;
break;
case 6u:
samplefrequency = 31250LL;
break;
case 7u:
samplefrequency = 34700LL;
break;
}
return;
}
berzerkplayvoice = 0;
if ( berzerknoisemulate )
return;
v3 = lastnoise;
goto LABEL_12;
}
if ( ((a1 - 3) & 0xFFFFFFFD) != 0 )
{
v2 = berzerknoisemulate;
if ( a2 - 61 <= 0xA && a1 == 6 )
{
if ( berzerknoisemulate )
return;
v3 = a2;
if ( lastnoise != a2 )
{
switch ( a2 )
{
case 'F':
switch ( deathsound )
{
case 1:
sample_start(2LL, 33LL, 0LL);
deathsound = 0;
goto LABEL_29;
case 2:
sample_start(6LL, 34LL, 0LL);
deathsound = 3;
goto LABEL_29;
case 0:
sample_start(2LL, 31LL, 0LL);
goto LABEL_29;
}
break;
case 'G':
sample_start(3LL, 32LL, 0LL);
goto LABEL_29;
case 'E':
sample_start(1LL, 30LL, 0LL);
goto LABEL_29;
}
LABEL_12:
lastnoise = v3;
if ( a1 == 4 && deathsound <= 1 )
{
if ( lastvoice == 24 && v2 == 27 )
{
lastvoice = 27;
}
else
{
sample_start(5LL, v2, 0LL);
sample_set_freq(5LL, samplefrequency);
lastvoice = v2;
}
}
return;
}
}
else
{
if ( berzerknoisemulate )
return;
v3 = lastnoise;
if ( a1 != 6 )
goto LABEL_12;
}
LABEL_29:
lastnoise = v3;
return;
}
if ( lastnoise == 70 )
{
if ( a2 == 172 && a1 == 3 )
{
nextdata5 = 25;
return;
}
if ( a1 == 5 )
{
if ( nextdata5 == a2 )
{
deathsound = 2;
goto LABEL_43;
}
LABEL_40:
nextdata5 = -1;
return;
}
}
else if ( lastnoise == 69 )
{
if ( a2 == 50 && a1 == 3 )
{
nextdata5 = 50;
return;
}
if ( a1 == 5 )
{
if ( nextdata5 == a2 )
{
LABEL_43:
lastnoise = 64;
goto LABEL_40;
}
goto LABEL_40;
}
}
}

original_code:
void berzerk_sound_control_a_w(offs_t offset,data_t data)
{
 int noise = 0;
 int voice = 0;
 int voicefrequency = 0;
 if (offset < 3) return;
 if (offset==4)
 {
  if ((data & 0x40) == 0)
  {
   voice = data;
   berzerkplayvoice = 0;
  }
  else
  {
   voicevolume = ((data & 0x38) >> 3);
   if (voicevolume > 0) voicevolume=255;
   voicefrequency = (data & 0x07);
   switch(voicefrequency)
   {
   case 0 : samplefrequency = 17640; break;
   case 1 : samplefrequency = 19404; break;
   case 2 : samplefrequency = 20947; break;
   case 3 : samplefrequency = 22050; break;
   case 4 : samplefrequency = 26019; break;
   case 5 : samplefrequency = 27783; break;
   case 6 : samplefrequency = 31250; break;
   case 7 : samplefrequency = 34700; break;
   default: samplefrequency = 22050; break;
   }
   return;
  }
 }
 if ((offset==3) || (offset==5))
 {
  if (lastnoise==70)
  {
   if ((offset==3) && (data==172))
   {
    nextdata5 = 25;
    return;
   }
   if (offset==5)
   {
    if (data==nextdata5)
    {
     deathsound = 2;
     lastnoise = 64;
    }
    nextdata5 = -1;
   }
   return;
  }
  if (lastnoise==69)
  {
   if ((offset==3) && (data==50))
   {
    nextdata5 = 50;
    return;
   }
   if (offset==5)
   {
    if (data==nextdata5)
    {
     lastnoise = 64;
    }
    nextdata5 = -1;
   }
  }
  return;
 }
 if ((data > 60) && (data < 72) && (offset==6))
  noise = data;
 else
  noise = lastnoise;
 if (berzerknoisemulate)
 {
  return;
  if (voicefrequency != 1750*(4-noise))
  {
   voicefrequency = 1750*(4-noise);
   voicevolume = 85*noise;
  }
  if (noise)
  {
   sample_set_freq(2,voicefrequency);
   sample_set_volume(2,voicevolume);
  }
  else
  {
   sample_set_volume(2,0);
   voicevolume = 0;
  }
 }
 else
 {
  if ((offset==6) && (lastnoise != noise))
  {
   switch (noise)
   {
   case 69 :
    sample_start(1,30,0);
    break;
   case 70 :
    switch(deathsound)
    {
    case 1 :
     sample_start(2,33,0);
     deathsound=0;
     break;
    case 2 :
     sample_start(6,34,0);
     deathsound=3;
     break;
    case 0 :
     sample_start(2,31,0);
     break;
    }
    break;
   case 71 :
    sample_start(3,32,0);
    break;
   default :
    break;
   }
  }
  lastnoise = noise;
  if (offset==4)
  {
   if (deathsound<2)
   {
    if (lastvoice==24 && voice==27)
    {
     lastvoice=voice;
     return;
    }
    sample_start(5,voice,0);
    sample_set_freq(5,samplefrequency);
    lastvoice=voice;
   }
  }
 }
}

canonical_original_code:
void berzerk_sound_control_a_w(unsigned int offset, unsigned int data)
{
 int noise = 0;
 int voice = 0;
 int voicefrequency = 0;
 if (offset < 3) return;
 if (offset==4)
 {
  if ((data & 0x40) == 0)
  {
   voice = data;
   berzerkplayvoice = 0;
  }
  else
  {
   voicevolume = ((data & 0x38) >> 3);
   if (voicevolume > 0) voicevolume=255;
   voicefrequency = (data & 0x07);
   switch(voicefrequency)
   {
   case 0 : samplefrequency = 17640; break;
   case 1 : samplefrequency = 19404; break;
   case 2 : samplefrequency = 20947; break;
   case 3 : samplefrequency = 22050; break;
   case 4 : samplefrequency = 26019; break;
   case 5 : samplefrequency = 27783; break;
   case 6 : samplefrequency = 31250; break;
   case 7 : samplefrequency = 34700; break;
   default: samplefrequency = 22050; break;
   }
   return;
  }
 }
 if ((offset==3) || (offset==5))
 {
  if (lastnoise==70)
  {
   if ((offset==3) && (data==172))
   {
    nextdata5 = 25;
    return;
   }
   if (offset==5)
   {
    if (data==nextdata5)
    {
     deathsound = 2;
     lastnoise = 64;
    }
    nextdata5 = -1;
   }
   return;
  }
  if (lastnoise==69)
  {
   if ((offset==3) && (data==50))
   {
    nextdata5 = 50;
    return;
   }
   if (offset==5)
   {
    if (data==nextdata5)
    {
     lastnoise = 64;
    }
    nextdata5 = -1;
   }
  }
  return;
 }
 if ((data > 60) && (data < 72) && (offset==6))
  noise = data;
 else
  noise = lastnoise;
 if (berzerknoisemulate)
 {
  return;
  if (voicefrequency != 1750*(4-noise))
  {
   voicefrequency = 1750*(4-noise);
   voicevolume = 85*noise;
  }
  if (noise)
  {
   sample_set_freq(2,voicefrequency);
   sample_set_volume(2,voicevolume);
  }
  else
  {
   sample_set_volume(2,0);
   voicevolume = 0;
  }
 }
 else
 {
  if ((offset==6) && (lastnoise != noise))
  {
   switch (noise)
   {
   case 69 :
    sample_start(1,30,0);
    break;
   case 70 :
    switch(deathsound)
    {
    case 1 :
     sample_start(2,33,0);
     deathsound=0;
     break;
    case 2 :
     sample_start(6,34,0);
     deathsound=3;
     break;
    case 0 :
     sample_start(2,31,0);
     break;
    }
    break;
   case 71 :
    sample_start(3,32,0);
    break;
   default :
    break;
   }
  }
  lastnoise = noise;
  if (offset==4)
  {
   if (deathsound<2)
   {
    if (lastvoice==24 && voice==27)
    {
     lastvoice=voice;
     return;
    }
    sample_start(5,voice,0);
    sample_set_freq(5,samplefrequency);
    lastvoice=voice;
   }
  }
 }
}

variable_types: noise int

variable_types: voice int

variable_types: voicefrequency int


decompiled_code:
_DWORD *berzerk_sh_update()
{
bool v0; // zf
_DWORD *result; // rax

v0 = (unsigned int)sample_playing(5LL) == 0;
result = &berzerkplayvoice;
berzerkplayvoice = v0;
if ( deathsound == 3 )
{
result = (_DWORD *)sample_playing(6LL);
if ( !(_DWORD)result )
{
result = &lastnoise;
if ( lastnoise != 70 )
deathsound = 0;
}
}
return result;
}

canonical_decompiled_code:
_DWORD *func22()
{
bool v0; // zf
_DWORD *result; // rax

v0 = (unsigned int)sample_playing(5LL) == 0;
result = &berzerkplayvoice;
berzerkplayvoice = v0;
if ( deathsound == 3 )
{
result = (_DWORD *)sample_playing(6LL);
if ( !(_DWORD)result )
{
result = &lastnoise;
if ( lastnoise != 70 )
deathsound = 0;
}
}
return result;
}

original_code:
void berzerk_sh_update(void)
{
 berzerkplayvoice = !sample_playing(5);
 if (deathsound==3 && sample_playing(6) == 0 && lastnoise != 70)
  deathsound=0;
}

canonical_original_code:
void berzerk_sh_update()
{
 berzerkplayvoice = !sample_playing(5);
 if (deathsound==3 && sample_playing(6) == 0 && lastnoise != 70)
  deathsound=0;
}


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

if ( a2 )
return osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
result = osd_fread(a1, nvram, (unsigned int)nvram_size);
return result;
}

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

if ( a2 )
return osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
result = osd_fread(a1, nvram, (unsigned int)nvram_size);
return result;
}

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

canonical_original_code:
static void berzerk_nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
 }
}

variable_types:
file
void *


decompiled_code:
void berzerk_sound_control_b_w()
{
;
}

canonical_decompiled_code:
void func24()
{
;
}

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

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


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

result = (unsigned int)(240 - a2);
clown_x = 240 - a2;
return result;
}

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

result = (unsigned int)(240 - a2);
clown_x = 240 - a2;
return result;
}

original_code:
void circus_clown_x_w(offs_t offset,data_t data)
{
 clown_x = 240-data;
}

canonical_original_code:
void circus_clown_x_w(unsigned int offset, unsigned int data)
{
 clown_x = 240-data;
}


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

result = (unsigned int)(240 - a2);
clown_y = 240 - a2;
return result;
}

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

result = (unsigned int)(240 - a2);
clown_y = 240 - a2;
return result;
}

original_code:
void circus_clown_y_w(offs_t offset,data_t data)
{
 clown_y = 240-data;
}

canonical_original_code:
void circus_clown_y_w(unsigned int offset, unsigned int data)
{
 clown_y = 240-data;
}


original_code:
static void draw_robot_box (struct osd_bitmap *bitmap, int x, int y)
{
 int ex = x + 24;
 int ey = y + 26;
 draw_line(bitmap,x,y,ex,y,0);
 draw_line(bitmap,x,ey,ex,ey,0);
 draw_line(bitmap,x,y,x,ey,0);
 draw_line(bitmap,ex,y,ex,ey,0);
 ey = y + 10;
 draw_line(bitmap,x+8,ey,ex,ey,0);
 draw_line(bitmap,x+8,y,x+8,ey,0);
 draw_line(bitmap,x+16,y,x+16,ey,0);
}

canonical_original_code:
static void draw_robot_box(struct osd_bitmap *bitmap, int x, int y)
{
 int ex = x + 24;
 int ey = y + 26;
 draw_line(bitmap,x,y,ex,y,0);
 draw_line(bitmap,x,ey,ex,ey,0);
 draw_line(bitmap,x,y,x,ey,0);
 draw_line(bitmap,ex,y,ex,ey,0);
 ey = y + 10;
 draw_line(bitmap,x+8,ey,ex,ey,0);
 draw_line(bitmap,x+8,y,x+8,ey,0);
 draw_line(bitmap,x+16,y,x+16,ey,0);
}

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

variable_types: x int

variable_types: y int

variable_types: ex int

variable_types: ey int


decompiled_code:
__int64 circus_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&circus_ol, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

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

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&circus_ol, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int circus_vh_start(void)
{
 int start_pen = 2;
 if (generic_vh_start()!=0)
  return 1;
 overlay_create(circus_ol, start_pen, Machine->drv->total_colors-start_pen);
 return 0;
}

canonical_original_code:
int circus_vh_start()
{
 int start_pen = 2;
 if (generic_vh_start()!=0)
  return 1;
 overlay_create(circus_ol, start_pen, Machine->drv->total_colors-start_pen);
 return 0;
}


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

result = a2 & 0xF;
clown_z = a2 & 0xF;
v3 = (a2 >> 4) & 7;
if ( !v3 )
return DAC_data_w(0LL, 0LL);
if ( v3 == 1 )
result = DAC_data_w(0LL, 127LL);
return result;
}

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

result = a2 & 0xF;
clown_z = a2 & 0xF;
v3 = (a2 >> 4) & 7;
if ( !v3 )
return DAC_data_w(0LL, 0LL);
if ( v3 == 1 )
result = DAC_data_w(0LL, 127LL);
return result;
}

original_code:
void circus_clown_z_w(offs_t offset,data_t data)
{
 clown_z = (data & 0x0f);
 switch ((data & 0x70) >> 4)
 {
  case 0 :
   DAC_data_w (0,0);
   break;
  case 1 :
   DAC_data_w (0,0x7f);
   break;
  case 2 :
   break;
  case 3 :
   break;
  case 4 :
   break;
  case 5 :
   break;
  case 6 :
   break;
  case 7 :
   break;
 };
}

canonical_original_code:
void circus_clown_z_w(unsigned int offset, unsigned int data)
{
 clown_z = (data & 0x0f);
 switch ((data & 0x70) >> 4)
 {
  case 0 :
   DAC_data_w (0,0);
   break;
  case 1 :
   DAC_data_w (0,0x7f);
   break;
  case 2 :
   break;
  case 3 :
   break;
  case 4 :
   break;
  case 5 :
   break;
  case 6 :
   break;
  case 7 :
   break;
 };
}

variable_types:
offset
unsigned int