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

variable_types:
offset
unsigned int


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

return_type: int


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

variable_types:
data
unsigned int

return_type: void


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

return_type: unsigned int


decompiled_code:
__int64 __fastcall rainbow_c_chip_r(unsigned int a1)
{
__int64 v2; // rcx
__int64 v3; // rdx
int v4; // esi
__int64 result; // rax
unsigned int v6; // edi

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

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 v2; // rcx
__int64 v3; // rdx
int v4; // esi
__int64 result; // rax
unsigned int v6; // edi

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


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

variable_types: i int


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, _BYTE *a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdx
char v5; // cl
_BYTE *v6; // rsi

if ( !a3 )
{
LABEL_6:
if ( !*a2 )
return a3;
result = a3;
v6 = &a2[-a3];
do
++result;
while ( v6[result] );
return result;
}
result = 0LL;
v4 = a3 - 1;
if ( !v4 )
{
result = 0LL;
LABEL_5:
*a1 = 0;
a3 = result;
goto LABEL_6;
}
while ( 1 )
{
++a2;
++a1;
v5 = *(a2 - 1);
*(a1 - 1) = v5;
if ( !v5 )
return result;
++result;
if ( !--v4 )
goto LABEL_5;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _BYTE *a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // rdx
char v5; // cl
_BYTE *v6; // rsi

if ( !a3 )
{
LABEL_6:
if ( !*a2 )
return a3;
result = a3;
v6 = &a2[-a3];
do
++result;
while ( v6[result] );
return result;
}
result = 0LL;
v4 = a3 - 1;
if ( !v4 )
{
result = 0LL;
LABEL_5:
*a1 = 0;
a3 = result;
goto LABEL_6;
}
while ( 1 )
{
++a2;
++a1;
v5 = *(a2 - 1);
*(a1 - 1) = v5;
if ( !v5 )
return result;
++result;
if ( !--v4 )
goto LABEL_5;
}
}

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, _BYTE *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, _BYTE *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 ( (unsigned int)(v0 - 4) > 2 )
{
if ( v1 == 8 )
{
berzerk_irq_end_of_screen = 0;
int_count = 0;
goto LABEL_4;
}
LABEL_3:
berzerk_irq_end_of_screen = 1;
LABEL_4:
result = (unsigned int)-(irq_enabled == 0);
LOBYTE(result) = irq_enabled == 0 ? -1 : 0xFC;
return result;
}
}
else if ( v1 <= 0 )
{
goto LABEL_3;
}
berzerk_irq_end_of_screen = v1 == 7;
return (unsigned int)(nmi_enabled == 0) - 2;
}

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 ( (unsigned int)(v0 - 4) > 2 )
{
if ( v1 == 8 )
{
berzerk_irq_end_of_screen = 0;
int_count = 0;
goto LABEL_4;
}
LABEL_3:
berzerk_irq_end_of_screen = 1;
LABEL_4:
result = (unsigned int)-(irq_enabled == 0);
LOBYTE(result) = irq_enabled == 0 ? -1 : 0xFC;
return result;
}
}
else if ( v1 <= 0 )
{
goto LABEL_3;
}
berzerk_irq_end_of_screen = v1 == 7;
return (unsigned int)(nmi_enabled == 0) - 2;
}

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:
data
unsigned int

variable_types: coloroffset int


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

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

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

*(_BYTE *)(colorram + a1) = a2;
v2 = (a1 >> 3) & 0xFC;
v3 = (unsigned __int8)(8 * a1);
v4 = v2 + 4;
do
{
v5 = *(_BYTE *)(videoram + ((v3 >> 3) | (32 * v2)));
if ( v5 )
func7(v3, v2, v5, a2);
++v2;
}
while ( v2 != 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(unsigned int a1, int a2)
{
char v2; // dl
int v3; // eax

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

canonical_decompiled_code:
void __fastcall func12(unsigned int a1, int a2)
{
char v2; // dl
int v3; // eax

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

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


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
_QWORD *v2; // rsi
char v3; // dl
int v4; // ecx

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

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

berzerknoisemulate = 1;
v0 = *(_QWORD *)(Machine + 848LL);
if ( v0 )
{
v1 = (_QWORD *)(v0 + 8);
v2 = (_QWORD *)(v0 + 48);
v3 = 0;
v4 = 1;
do
{
if ( *v1 )
v3 = 1;
if ( *v1 )
v4 = 0;
++v1;
}
while ( v1 != v2 );
if ( v3 )
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;
irq_enabled = 0;
nmi_enabled = 0;
result = &berzerk_irq_end_of_screen;
berzerk_irq_end_of_screen = 0;
int_count = 0;
return result;
}

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

for ( i = 14336LL; i != 0x4000; ++i )
*(_BYTE *)(memory_region(129LL) + i) = -1;
irq_enabled = 0;
nmi_enabled = 0;
result = &berzerk_irq_end_of_screen;
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 func18()
{
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 func19()
{
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; // ebx
bool v3; // al
unsigned int v4; // ebp

if ( a1 <= 2 )
return;
if ( a1 != 4 )
{
if ( ((a1 - 3) & 0xFFFFFFFD) == 0 )
{
if ( lastnoise == 70 )
{
if ( a2 == 172 && a1 == 3 )
{
nextdata5 = 25;
}
else if ( a1 == 5 )
{
if ( nextdata5 == a2 )
{
deathsound = 2;
lastnoise = 64;
}
nextdata5 = -1;
}
}
else if ( lastnoise == 69 )
{
if ( a2 == 50 && a1 == 3 )
{
nextdata5 = 50;
}
else if ( a1 == 5 )
{
if ( nextdata5 == a2 )
lastnoise = 64;
nextdata5 = -1;
}
}
return;
}
v3 = a1 == 6;
if ( a2 - 61 <= 0xA && a1 == 6 )
{
v2 = berzerknoisemulate;
if ( berzerknoisemulate )
return;
v4 = a2;
if ( lastnoise != a2 )
{
switch ( a2 )
{
case 'F':
switch ( deathsound )
{
case 1:
sample_start(2LL, 33LL, 0LL);
deathsound = 0;
goto LABEL_46;
case 2:
sample_start(6LL, 34LL, 0LL);
deathsound = 3;
goto LABEL_46;
case 0:
sample_start(2LL, 31LL, 0LL);
goto LABEL_46;
}
break;
case 'G':
sample_start(3LL, 32LL, 0LL);
goto LABEL_46;
case 'E':
sample_start(1LL, 30LL, 0LL);
goto LABEL_46;
}
goto LABEL_13;
}
goto LABEL_46;
}
v2 = 0;
LABEL_11:
v4 = lastnoise;
if ( berzerknoisemulate )
return;
if ( !v3 )
{
LABEL_13:
lastnoise = v4;
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;
}
LABEL_46:
lastnoise = v4;
return;
}
if ( (a2 & 0x40) == 0 )
{
v2 = a2;
berzerkplayvoice = 0;
v3 = 0;
goto LABEL_11;
}
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;
}
}

canonical_decompiled_code:
void __fastcall func20(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
bool v3; // al
unsigned int v4; // ebp

if ( a1 <= 2 )
return;
if ( a1 != 4 )
{
if ( ((a1 - 3) & 0xFFFFFFFD) == 0 )
{
if ( lastnoise == 70 )
{
if ( a2 == 172 && a1 == 3 )
{
nextdata5 = 25;
}
else if ( a1 == 5 )
{
if ( nextdata5 == a2 )
{
deathsound = 2;
lastnoise = 64;
}
nextdata5 = -1;
}
}
else if ( lastnoise == 69 )
{
if ( a2 == 50 && a1 == 3 )
{
nextdata5 = 50;
}
else if ( a1 == 5 )
{
if ( nextdata5 == a2 )
lastnoise = 64;
nextdata5 = -1;
}
}
return;
}
v3 = a1 == 6;
if ( a2 - 61 <= 0xA && a1 == 6 )
{
v2 = berzerknoisemulate;
if ( berzerknoisemulate )
return;
v4 = a2;
if ( lastnoise != a2 )
{
switch ( a2 )
{
case 'F':
switch ( deathsound )
{
case 1:
sample_start(2LL, 33LL, 0LL);
deathsound = 0;
goto LABEL_46;
case 2:
sample_start(6LL, 34LL, 0LL);
deathsound = 3;
goto LABEL_46;
case 0:
sample_start(2LL, 31LL, 0LL);
goto LABEL_46;
}
break;
case 'G':
sample_start(3LL, 32LL, 0LL);
goto LABEL_46;
case 'E':
sample_start(1LL, 30LL, 0LL);
goto LABEL_46;
}
goto LABEL_13;
}
goto LABEL_46;
}
v2 = 0;
LABEL_11:
v4 = lastnoise;
if ( berzerknoisemulate )
return;
if ( !v3 )
{
LABEL_13:
lastnoise = v4;
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;
}
LABEL_46:
lastnoise = v4;
return;
}
if ( (a2 & 0x40) == 0 )
{
v2 = a2;
berzerkplayvoice = 0;
v3 = 0;
goto LABEL_11;
}
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;
}
}

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:
int *berzerk_sh_update()
{
int *result; // rax

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

canonical_decompiled_code:
int *func21()
{
int *result; // rax

berzerkplayvoice = sample_playing(5LL) == 0;
result = &deathsound;
if ( deathsound == 3 )
{
result = (int *)sample_playing(6LL);
if ( !(_DWORD)result )
{
result = &lastnoise;
if ( lastnoise != 70 )
{
result = &deathsound;
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 func22(__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 func23()
{
;
}

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; // ebx

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; // ebx

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

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall circus_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v2; // rax
int v3; // ebx
__int64 v4; // rbp
int v5; // er10
unsigned int v6; // edi
__int64 result; // rax
int v8; // er11
int v9; // ecx

v2 = palette_recalc();
if ( a2 || v2 )
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
0LL,
0LL,
0LL,
(unsigned int)(8 * (v3 % 32)),
(unsigned int)(8 * (v3 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v4;
--v3;
}
while ( v3 >= 0 );
}
draw_line(a1, 0, 0x12u, 0xFFu, 0x12u, 0);
draw_line(a1, 0, 0xF9u, 0xFFu, 0xF9u, 1);
draw_line(a1, 0, 0x12u, 0, 0xF8u, 0);
draw_line(a1, 0xF7u, 0x12u, 0xF7u, 0xF8u, 0);
draw_line(a1, 0, 0x89u, 0x11u, 0x89u, 0);
draw_line(a1, 0xE7u, 0x89u, 0xF8u, 0x89u, 0);
draw_line(a1, 0, 0xC1u, 0x11u, 0xC1u, 0);
draw_line(a1, 0xE7u, 0xC1u, 0xF8u, 0xC1u, 0);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)clown_z,
0LL,
0LL,
0LL,
(unsigned int)clown_y,
(unsigned int)clown_x,
Machine + 776LL,
2LL,
0LL);
v5 = clown_y >> 3;
v6 = clown_x >> 3;
result = clown_x & 0xF;
v8 = (clown_x >> 3) - (((_DWORD)result == 0) - 3);
v9 = (clown_y >> 3) + 2 - (((clown_y & 0xF) == 0) - 1);
if ( clown_x >> 3 < v8 )
{
do
{
result = (unsigned int)v5;
if ( v5 < v9 )
{
do
{
if ( (unsigned int)result <= 0x1F && v6 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(32 * v6 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v9 );
}
++v6;
}
while ( v6 != v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rax
int v3; // ebx
__int64 v4; // rbp
int v5; // er10
unsigned int v6; // edi
__int64 result; // rax
int v8; // er11
int v9; // ecx

v2 = palette_recalc();
if ( a2 || v2 )
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4),
0LL,
0LL,
0LL,
(unsigned int)(8 * (v3 % 32)),
(unsigned int)(8 * (v3 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v4;
--v3;
}
while ( v3 >= 0 );
}
func2(a1, 0, 0x12u, 0xFFu, 0x12u, 0);
func2(a1, 0, 0xF9u, 0xFFu, 0xF9u, 1);
func2(a1, 0, 0x12u, 0, 0xF8u, 0);
func2(a1, 0xF7u, 0x12u, 0xF7u, 0xF8u, 0);
func2(a1, 0, 0x89u, 0x11u, 0x89u, 0);
func2(a1, 0xE7u, 0x89u, 0xF8u, 0x89u, 0);
func2(a1, 0, 0xC1u, 0x11u, 0xC1u, 0);
func2(a1, 0xE7u, 0xC1u, 0xF8u, 0xC1u, 0);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)clown_z,
0LL,
0LL,
0LL,
(unsigned int)clown_y,
(unsigned int)clown_x,
Machine + 776LL,
2LL,
0LL);
v5 = clown_y >> 3;
v6 = clown_x >> 3;
result = clown_x & 0xF;
v8 = (clown_x >> 3) - (((_DWORD)result == 0) - 3);
v9 = (clown_y >> 3) + 2 - (((clown_y & 0xF) == 0) - 1);
if ( clown_x >> 3 < v8 )
{
do
{
result = (unsigned int)v5;
if ( v5 < v9 )
{
do
{
if ( (unsigned int)result <= 0x1F && v6 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(32 * v6 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v9 );
}
++v6;
}
while ( v6 != v8 );
}
return result;
}

original_code:
void circus_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sy = offs / 32;
   sx = offs % 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
    draw_line (bitmap,0,18,255,18,0);
    draw_line (bitmap,0,249,255,249,1);
    draw_line (bitmap,0,18,0,248,0);
    draw_line (bitmap,247,18,247,248,0);
    draw_line (bitmap,0,137,17,137,0);
    draw_line (bitmap,231,137,248,137,0);
    draw_line (bitmap,0,193,17,193,0);
    draw_line (bitmap,231,193,248,193,0);
 drawgfx(bitmap,Machine->gfx[1],
   clown_z,
   0,
   0,0,
   clown_y,clown_x,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 sx = clown_y >> 3;
 sy = clown_x >> 3;
 {
  int max_x = 2;
  int max_y = 2;
  int x2, y2;
  if (clown_y & 0x0f) max_x ++;
  if (clown_x & 0x0f) max_y ++;
  for (y2 = sy; y2 < sy + max_y; y2 ++)
  {
   for (x2 = sx; x2 < sx + max_x; x2 ++)
   {
    if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
     dirtybuffer[x2 + 32*y2] = 1;
   }
  }
 }
}

canonical_original_code:
void circus_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sy = offs / 32;
   sx = offs % 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
    draw_line (bitmap,0,18,255,18,0);
    draw_line (bitmap,0,249,255,249,1);
    draw_line (bitmap,0,18,0,248,0);
    draw_line (bitmap,247,18,247,248,0);
    draw_line (bitmap,0,137,17,137,0);
    draw_line (bitmap,231,137,248,137,0);
    draw_line (bitmap,0,193,17,193,0);
    draw_line (bitmap,231,193,248,193,0);
 drawgfx(bitmap,Machine->gfx[1],
   clown_z,
   0,
   0,0,
   clown_y,clown_x,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 sx = clown_y >> 3;
 sy = clown_x >> 3;
 {
  int max_x = 2;
  int max_y = 2;
  int x2; int y2;
  if (clown_y & 0x0f) max_x ++;
  if (clown_x & 0x0f) max_y ++;
  for (y2 = sy; y2 < sy + max_y; y2 ++)
  {
   for (x2 = sx; x2 < sx + max_x; x2 ++)
   {
    if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
     dirtybuffer[x2 + 32*y2] = 1;
   }
  }
 }
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

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


decompiled_code:
__int64 __fastcall robotbowl_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // r12
unsigned int i; // ebx
int v5; // er10
unsigned int v6; // edi
__int64 result; // rax
int v8; // er11
int v9; // ecx

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
0LL,
0LL,
0LL,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
for ( i = 15; i != 87; i += 24 )
{
draw_robot_box(a1, i, 0x1Fu);
draw_robot_box(a1, i, 0x3Fu);
draw_robot_box(a1, i, 0x5Fu);
draw_robot_box(a1, i + 152, 0x1Fu);
draw_robot_box(a1, i + 152, 0x3Fu);
draw_robot_box(a1, i + 152, 0x5Fu);
}
draw_robot_box(a1, 0x27u, 0x7Fu);
draw_line(a1, 0x27u, 0x89u, 0x2Fu, 0x89u, 0);
draw_robot_box(a1, 0xBFu, 0x7Fu);
draw_line(a1, 0xBFu, 0x89u, 0xC7u, 0x89u, 0);
draw_line(a1, 0x67u, 0x11u, 0x67u, 0xCDu, 0);
draw_line(a1, 0x6Fu, 0x11u, 0x6Fu, 0xCBu, 1);
draw_line(a1, 0x98u, 0x11u, 0x98u, 0xCDu, 0);
draw_line(a1, 0x90u, 0x11u, 0x90u, 0xCBu, 1);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)clown_z,
0LL,
0LL,
0LL,
(unsigned int)(clown_y + 8),
(unsigned int)(clown_x + 8),
Machine + 776LL,
2LL,
0LL);
v5 = clown_y >> 3;
v6 = clown_x >> 3;
result = clown_x & 0xF;
v8 = (clown_x >> 3) - (((_DWORD)result == 0) - 3);
v9 = (clown_y >> 3) + 2 - (((clown_y & 0xF) == 0) - 1);
if ( clown_x >> 3 < v8 )
{
do
{
result = (unsigned int)v5;
if ( v5 < v9 )
{
do
{
if ( (unsigned int)result <= 0x1F && v6 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(32 * v6 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v9 );
}
++v6;
}
while ( v6 != v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // r12
unsigned int i; // ebx
int v5; // er10
unsigned int v6; // edi
__int64 result; // rax
int v8; // er11
int v9; // ecx

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
0LL,
0LL,
0LL,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
for ( i = 15; i != 87; i += 24 )
{
func3(a1, i, 0x1Fu);
func3(a1, i, 0x3Fu);
func3(a1, i, 0x5Fu);
func3(a1, i + 152, 0x1Fu);
func3(a1, i + 152, 0x3Fu);
func3(a1, i + 152, 0x5Fu);
}
func3(a1, 0x27u, 0x7Fu);
func2(a1, 0x27u, 0x89u, 0x2Fu, 0x89u, 0);
func3(a1, 0xBFu, 0x7Fu);
func2(a1, 0xBFu, 0x89u, 0xC7u, 0x89u, 0);
func2(a1, 0x67u, 0x11u, 0x67u, 0xCDu, 0);
func2(a1, 0x6Fu, 0x11u, 0x6Fu, 0xCBu, 1);
func2(a1, 0x98u, 0x11u, 0x98u, 0xCDu, 0);
func2(a1, 0x90u, 0x11u, 0x90u, 0xCBu, 1);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)clown_z,
0LL,
0LL,
0LL,
(unsigned int)(clown_y + 8),
(unsigned int)(clown_x + 8),
Machine + 776LL,
2LL,
0LL);
v5 = clown_y >> 3;
v6 = clown_x >> 3;
result = clown_x & 0xF;
v8 = (clown_x >> 3) - (((_DWORD)result == 0) - 3);
v9 = (clown_y >> 3) + 2 - (((clown_y & 0xF) == 0) - 1);
if ( clown_x >> 3 < v8 )
{
do
{
result = (unsigned int)v5;
if ( v5 < v9 )
{
do
{
if ( (unsigned int)result <= 0x1F && v6 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(32 * v6 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v9 );
}
++v6;
}
while ( v6 != v8 );
}
return result;
}

original_code:
void robotbowl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
    for(offs=15;offs<=63;offs+=24)
    {
        draw_robot_box(bitmap, offs, 31);
        draw_robot_box(bitmap, offs, 63);
        draw_robot_box(bitmap, offs, 95);
        draw_robot_box(bitmap, offs+152, 31);
        draw_robot_box(bitmap, offs+152, 63);
        draw_robot_box(bitmap, offs+152, 95);
    }
    draw_robot_box(bitmap, 39, 127);
    draw_line(bitmap, 39,137,47,137,0);
    draw_robot_box(bitmap, 39+152, 127);
    draw_line(bitmap, 39+152,137,47+152,137,0);
    draw_line(bitmap, 103,17,103,205,0);
    draw_line(bitmap, 111,17,111,203,1);
    draw_line(bitmap, 152,17,152,205,0);
    draw_line(bitmap, 144,17,144,203,1);
 drawgfx(bitmap,Machine->gfx[1],
   clown_z,
   0,
   0,0,
   clown_y+8,clown_x+8,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 sx = clown_y >> 3;
 sy = clown_x >> 3;
 {
  int max_x = 2;
  int max_y = 2;
  int x2, y2;
  if (clown_y & 0x0f) max_x ++;
  if (clown_x & 0x0f) max_y ++;
  for (y2 = sy; y2 < sy + max_y; y2 ++)
  {
   for (x2 = sx; x2 < sx + max_x; x2 ++)
   {
    if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
     dirtybuffer[x2 + 32*y2] = 1;
   }
  }
 }
}

canonical_original_code:
void robotbowl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
    for(offs=15;offs<=63;offs+=24)
    {
        draw_robot_box(bitmap, offs, 31);
        draw_robot_box(bitmap, offs, 63);
        draw_robot_box(bitmap, offs, 95);
        draw_robot_box(bitmap, offs+152, 31);
        draw_robot_box(bitmap, offs+152, 63);
        draw_robot_box(bitmap, offs+152, 95);
    }
    draw_robot_box(bitmap, 39, 127);
    draw_line(bitmap, 39,137,47,137,0);
    draw_robot_box(bitmap, 39+152, 127);
    draw_line(bitmap, 39+152,137,47+152,137,0);
    draw_line(bitmap, 103,17,103,205,0);
    draw_line(bitmap, 111,17,111,203,1);
    draw_line(bitmap, 152,17,152,205,0);
    draw_line(bitmap, 144,17,144,203,1);
 drawgfx(bitmap,Machine->gfx[1],
   clown_z,
   0,
   0,0,
   clown_y+8,clown_x+8,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 sx = clown_y >> 3;
 sy = clown_x >> 3;
 {
  int max_x = 2;
  int max_y = 2;
  int x2; int y2;
  if (clown_y & 0x0f) max_x ++;
  if (clown_x & 0x0f) max_y ++;
  for (y2 = sy; y2 < sy + max_y; y2 ++)
  {
   for (x2 = sx; x2 < sx + max_x; x2 ++)
   {
    if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
     dirtybuffer[x2 + 32*y2] = 1;
   }
  }
 }
}


decompiled_code:
__int64 __fastcall crash_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // er10
unsigned int v5; // edi
__int64 result; // rax
int v7; // er11
int v8; // ecx

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
0LL,
0LL,
0LL,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)clown_z,
0LL,
0LL,
0LL,
(unsigned int)clown_y,
(unsigned int)clown_x,
Machine + 776LL,
2LL,
0LL);
v4 = clown_y >> 3;
v5 = clown_x >> 3;
result = clown_x & 0xF;
v7 = (clown_x >> 3) - (((_DWORD)result == 0) - 3);
v8 = (clown_y >> 3) + 2 - (((clown_y & 0xF) == 0) - 1);
if ( clown_x >> 3 < v7 )
{
do
{
result = (unsigned int)v4;
if ( v4 < v8 )
{
do
{
if ( (unsigned int)result <= 0x1F && v5 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(32 * v5 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v8 );
}
++v5;
}
while ( v5 != v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // er10
unsigned int v5; // edi
__int64 result; // rax
int v7; // er11
int v8; // ecx

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
0LL,
0LL,
0LL,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)clown_z,
0LL,
0LL,
0LL,
(unsigned int)clown_y,
(unsigned int)clown_x,
Machine + 776LL,
2LL,
0LL);
v4 = clown_y >> 3;
v5 = clown_x >> 3;
result = clown_x & 0xF;
v7 = (clown_x >> 3) - (((_DWORD)result == 0) - 3);
v8 = (clown_y >> 3) + 2 - (((clown_y & 0xF) == 0) - 1);
if ( clown_x >> 3 < v7 )
{
do
{
result = (unsigned int)v4;
if ( v4 < v8 )
{
do
{
if ( (unsigned int)result <= 0x1F && v5 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(32 * v5 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v8 );
}
++v5;
}
while ( v5 != v7 );
}
return result;
}

original_code:
void crash_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
    drawgfx(bitmap,Machine->gfx[1],
   clown_z,
   0,
   0,0,
   clown_y,clown_x,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 sx = clown_y >> 3;
 sy = clown_x >> 3;
 {
  int max_x = 2;
  int max_y = 2;
  int x2, y2;
  if (clown_y & 0x0f) max_x ++;
  if (clown_x & 0x0f) max_y ++;
  for (y2 = sy; y2 < sy + max_y; y2 ++)
  {
   for (x2 = sx; x2 < sx + max_x; x2 ++)
   {
    if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
     dirtybuffer[x2 + 32*y2] = 1;
   }
  }
 }
}

canonical_original_code:
void crash_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs],
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
    drawgfx(bitmap,Machine->gfx[1],
   clown_z,
   0,
   0,0,
   clown_y,clown_x,
   &Machine->visible_area,TRANSPARENCY_PEN,0);
 sx = clown_y >> 3;
 sy = clown_x >> 3;
 {
  int max_x = 2;
  int max_y = 2;
  int x2; int y2;
  if (clown_y & 0x0f) max_x ++;
  if (clown_x & 0x0f) max_y ++;
  for (y2 = sy; y2 < sy + max_y; y2 ++)
  {
   for (x2 = sx; x2 < sx + max_x; x2 ++)
   {
    if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
     dirtybuffer[x2 + 32*y2] = 1;
   }
  }
 }
}


decompiled_code:
__int64 ripcord_IN2_r()
{
++circus_interrupt;
return readinputport(2LL);
}

canonical_decompiled_code:
__int64 func10()
{
++circus_interrupt;
return readinputport(2LL);
}

original_code:
static data_t ripcord_IN2_r(offs_t offset)
{
 circus_interrupt ++;
 return readinputport (2);
}

canonical_original_code:
static unsigned int ripcord_IN2_r(unsigned int offset)
{
 circus_interrupt ++;
 return readinputport (2);
}


decompiled_code:
__int64 init_robotbwl()
{
__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 func11()
{
__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_robotbwl(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_robotbwl()
{
 int i;
 for (i = 0;i < memory_region_length(REGION_GFX2);i++)
  memory_region(REGION_GFX2)[i] ^= 0xFF;
}

variable_types: i int


decompiled_code:
__int64 ripcord_interrupt()
{
circus_interrupt = 0;
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func12()
{
circus_interrupt = 0;
return ignore_interrupt();
}

original_code:
static int ripcord_interrupt (void)
{
 circus_interrupt = 0;
 if (1)
  return ignore_interrupt();
 else
  return interrupt();
}

canonical_original_code:
static int ripcord_interrupt()
{
 circus_interrupt = 0;
 if (1)
  return ignore_interrupt();
 else
  return interrupt();
}


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

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


original_code:
void sidepckt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 4) & 0x01;
  bit1 = (color_prom[0] >> 5) & 0x01;
  bit2 = (color_prom[0] >> 6) & 0x01;
  bit3 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void sidepckt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 4) & 0x01;
  bit1 = (color_prom[0] >> 5) & 0x01;
  bit2 = (color_prom[0] >> 6) & 0x01;
  bit3 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 sidepckt_i8751_r()
{
return (unsigned int)i8751_return;
}

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

original_code:
static data_t sidepckt_i8751_r(offs_t offset)
{
 return i8751_return;
}

canonical_original_code:
static unsigned int sidepckt_i8751_r(unsigned int offset)
{
 return i8751_return;
}


decompiled_code:
__int64 sidepckt_vh_start()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 32LL, 32LL);
bg_tilemap = v0;
v1 = 1;
if ( v0 )
{
*(_DWORD *)(v0 + 136) = 255;
*(_DWORD *)(v0 + 140) = 1;
tilemap_set_flip(0LL, 1LL, 1LL);
v1 = 0;
}
return v1;
}

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

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 32LL, 32LL);
bg_tilemap = v0;
v1 = 1;
if ( v0 )
{
*(_DWORD *)(v0 + 136) = 255;
*(_DWORD *)(v0 + 140) = 1;
tilemap_set_flip(0LL, 1LL, 1LL);
v1 = 0;
}
return v1;
}

original_code:
int sidepckt_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x02,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x01;
 tilemap_set_flip(0,0x1);
 return 0;
}

canonical_original_code:
int sidepckt_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x02,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x01;
 tilemap_set_flip(0,0x1);
 return 0;
}


decompiled_code:
__int64 __fastcall sidepckt_flipscreen_w(__int64 a1, int a2, __int64 a3)
{
return tilemap_set_flip(0LL, 1 - ((unsigned int)(a2 == 0) - 1), a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3)
{
return tilemap_set_flip(0LL, 1 - ((unsigned int)(a2 == 0) - 1), a3);
}

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

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


decompiled_code:
__int64 __fastcall sidepckt_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 64LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 64LL);
}

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

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


original_code:
static void sidepckt_i8751_w(offs_t offset,data_t data)
{
 int table_1[]={5,3,2};
 int table_2[]={0x8e,0x42,0xad,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa2,0xff};
 int table_3[]={0xbd,0x73,0x80,0xbd,0x73,0xa7,0xbd,0x73,0xe0,0x7e,0x72,0x56,0xff,0xff,0xff,0xff};
 static int current_ptr=0,current_table=0,in_math=0,math_param;
 cpu_cause_interrupt(0,2);
 if (in_math==1) {
  in_math=2;
  i8751_return=math_param=data;
 }
 else if (in_math==2) {
  in_math=0;
  i8751_return=math_param/data;
 }
 else switch (data) {
  case 1:
   current_table=1; current_ptr=0; i8751_return=table_1[current_ptr++]; break;
  case 2:
   current_table=2; current_ptr=0; i8751_return=table_2[current_ptr++]; break;
  case 3:
   current_table=3; current_ptr=0; i8751_return=table_3[current_ptr++]; break;
  case 4:
   in_math=1;
   i8751_return=4;
   break;
  case 6:
   if (current_table==1) i8751_return=table_1[current_ptr++];
   if (current_table==2) i8751_return=table_2[current_ptr++];
   if (current_table==3) i8751_return=table_3[current_ptr++];
   break;
 }
}

canonical_original_code:
static void sidepckt_i8751_w(unsigned int offset, unsigned int data)
{
 int table_1[] = {5,3,2};
 int table_2[] = {0x8e,0x42,0xad,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa2,0xff};
 int table_3[] = {0xbd,0x73,0x80,0xbd,0x73,0xa7,0xbd,0x73,0xe0,0x7e,0x72,0x56,0xff,0xff,0xff,0xff};
 static int current_ptr = 0; static int current_table = 0; static int in_math = 0; static int math_param;
 cpu_cause_interrupt(0,2);
 if (in_math==1) {
  in_math=2;
  i8751_return=math_param=data;
 }
 else if (in_math==2) {
  in_math=0;
  i8751_return=math_param/data;
 }
 else switch (data) {
  case 1:
   current_table=1; current_ptr=0; i8751_return=table_1[current_ptr++]; break;
  case 2:
   current_table=2; current_ptr=0; i8751_return=table_2[current_ptr++]; break;
  case 3:
   current_table=3; current_ptr=0; i8751_return=table_3[current_ptr++]; break;
  case 4:
   in_math=1;
   i8751_return=4;
   break;
  case 6:
   if (current_table==1) i8751_return=table_1[current_ptr++];
   if (current_table==2) i8751_return=table_2[current_ptr++];
   if (current_table==3) i8751_return=table_3[current_ptr++];
   break;
 }
}


original_code:
static void sidepctj_i8751_w(offs_t offset,data_t data)
{
 int table_1[]={5,3,0};
 int table_2[]={0x8e,0x42,0xb2,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa7,0xff};
 int table_3[]={0xbd,0x71,0xc8,0xbd,0x71,0xef,0xbd,0x72,0x28,0x7e,0x70,0x9e,0xff,0xff,0xff,0xff};
 static int current_ptr=0,current_table=0,in_math,math_param;
 cpu_cause_interrupt(0,2);
 if (in_math==1) {
  in_math=2;
  i8751_return=math_param=data;
 }
 else if (in_math==2) {
  in_math=0;
  i8751_return=math_param/data;
 }
 else switch (data) {
  case 1:
   current_table=1; current_ptr=0; i8751_return=table_1[current_ptr++]; break;
  case 2:
   current_table=2; current_ptr=0; i8751_return=table_2[current_ptr++]; break;
  case 3:
   current_table=3; current_ptr=0; i8751_return=table_3[current_ptr++]; break;
  case 4:
   in_math=1;
   i8751_return=4;
   break;
  case 6:
   if (current_table==1) i8751_return=table_1[current_ptr++];
   if (current_table==2) i8751_return=table_2[current_ptr++];
   if (current_table==3) i8751_return=table_3[current_ptr++];
   break;
 }
}

canonical_original_code:
static void sidepctj_i8751_w(unsigned int offset, unsigned int data)
{
 int table_1[] = {5,3,0};
 int table_2[] = {0x8e,0x42,0xb2,0x58,0xec,0x85,0xdd,0x4c,0xad,0x9f,0x00,0x4c,0x7e,0x42,0xa7,0xff};
 int table_3[] = {0xbd,0x71,0xc8,0xbd,0x71,0xef,0xbd,0x72,0x28,0x7e,0x70,0x9e,0xff,0xff,0xff,0xff};
 static int current_ptr = 0; static int current_table = 0; static int in_math; static int math_param;
 cpu_cause_interrupt(0,2);
 if (in_math==1) {
  in_math=2;
  i8751_return=math_param=data;
 }
 else if (in_math==2) {
  in_math=0;
  i8751_return=math_param/data;
 }
 else switch (data) {
  case 1:
   current_table=1; current_ptr=0; i8751_return=table_1[current_ptr++]; break;
  case 2:
   current_table=2; current_ptr=0; i8751_return=table_2[current_ptr++]; break;
  case 3:
   current_table=3; current_ptr=0; i8751_return=table_3[current_ptr++]; break;
  case 4:
   in_math=1;
   i8751_return=4;
   break;
  case 6:
   if (current_table==1) i8751_return=table_1[current_ptr++];
   if (current_table==2) i8751_return=table_2[current_ptr++];
   if (current_table==3) i8751_return=table_3[current_ptr++];
   break;
 }
}


original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = colorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr & 0x10) >> 3) | ((attr & 0x20) >> 5))]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = 0x01 | (((attr & 0x80) >> 7)<<2);
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = colorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr & 0x10) >> 3) | ((attr & 0x20) >> 5))]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = 0x01 | (((attr & 0x80) >> 7)<<2);
}

variable_types:
attr
unsigned char

variable_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *


irqhandler

decompiled_code:
__int64 __fastcall irqhandler(unsigned int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1);
}

original_code:
static void irqhandler(int linestate)
{
 cpu_set_irq_line(1,0,linestate);
}

variable_types: linestate int


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

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

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

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


decompiled_code:
_QWORD *rollerg_init_machine()
{
_QWORD *result; // rax

result = &konami_cpu_setlines_callback;
konami_cpu_setlines_callback = rollerg_banking;
readzoomroms = 0;
return result;
}

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

result = &konami_cpu_setlines_callback;
konami_cpu_setlines_callback = rollerg_banking;
readzoomroms = 0;
return result;
}

original_code:
static void rollerg_init_machine( void )
{
 konami_cpu_setlines_callback = rollerg_banking;
 readzoomroms = 0;
}

canonical_original_code:
static void rollerg_init_machine()
{
 konami_cpu_setlines_callback = rollerg_banking;
 readzoomroms = 0;
}


decompiled_code:
__int64 rollerg_vh_start()
{
unsigned int v0; // ebx

bg_colorbase = 16;
sprite_colorbase = 16;
zoom_colorbase = 0;
v0 = 1;
if ( !(unsigned int)K053245_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(138LL, 4LL, zoom_callback);
if ( v0 )
{
K053245_vh_stop();
v0 = 1;
}
else
{
K051316_set_offset(0LL, 22LL, 1LL);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx

bg_colorbase = 16;
sprite_colorbase = 16;
zoom_colorbase = 0;
v0 = 1;
if ( !(unsigned int)K053245_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(138LL, 4LL, zoom_callback);
if ( v0 )
{
K053245_vh_stop();
v0 = 1;
}
else
{
K051316_set_offset(0LL, 22LL, 1LL);
}
}
return v0;
}

original_code:
int rollerg_vh_start(void)
{
 bg_colorbase = 16;
 sprite_colorbase = 16;
 zoom_colorbase = 0;
 if (K053245_vh_start(REGION_GFX1,0,1,2,3,sprite_callback))
  return 1;
 if (K051316_vh_start_0(REGION_GFX2,4,zoom_callback))
 {
  K053245_vh_stop();
  return 1;
 }
 K051316_set_offset(0, 22, 1);
 return 0;
}

canonical_original_code:
int rollerg_vh_start()
{
 bg_colorbase = 16;
 sprite_colorbase = 16;
 zoom_colorbase = 0;
 if (K053245_vh_start(REGION_GFX1,0,1,2,3,sprite_callback))
  return 1;
 if (K051316_vh_start_0(REGION_GFX2,4,zoom_callback))
 {
  K053245_vh_stop();
  return 1;
 }
 K051316_set_offset(0, 22, 1);
 return 0;
}


decompiled_code:
__int64 rollerg_vh_stop()
{
K053245_vh_stop();
return K051316_vh_stop_0();
}

original_code:
void rollerg_vh_stop(void)
{
 K053245_vh_stop();
 K051316_vh_stop_0();
}

canonical_original_code:
void rollerg_vh_stop()
{
 K053245_vh_stop();
 K051316_vh_stop_0();
}


decompiled_code:
__int64 __fastcall rollerg_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi

K051316_tilemap_update_0();
palette_init_used_colors();
K053245_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc(a1, v2, &palette_used_colors, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K051316_zoom_draw_0(a1, 1LL);
return K053245_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi

K051316_tilemap_update_0();
palette_init_used_colors();
K053245_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc(a1, v2, &palette_used_colors, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K051316_zoom_draw_0(a1, 1LL);
return K053245_sprites_draw(a1);
}

original_code:
void rollerg_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i;
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K053245_mark_sprites_colors();
 for (i = 0;i < 16;i++)
  palette_used_colors[(zoom_colorbase + i) * 16] = (4|(1|2));
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K051316_zoom_draw_0(bitmap,1);
 K053245_sprites_draw(bitmap);
}

canonical_original_code:
void rollerg_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K053245_mark_sprites_colors();
 for (i = 0;i < 16;i++)
  palette_used_colors[(zoom_colorbase + i) * 16] = (4|(1|2));
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K051316_zoom_draw_0(bitmap,1);
 K053245_sprites_draw(bitmap);
}


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

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

original_code:
static void init_rollerg(void)
{
 konami_rom_deinterleave_2(REGION_GFX1);
}

canonical_original_code:
static void init_rollerg()
{
 konami_rom_deinterleave_2(REGION_GFX1);
}


decompiled_code:
void *__fastcall rollerg_banking(char a1)
{
__int64 v1; // rax
int v2; // edi
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((a1 & 7) + 4) << 14;
if ( v2 > 163839 )
v2 -= 0x20000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(char a1)
{
__int64 v1; // rax
int v2; // edi
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((a1 & 7) + 4) << 14;
if ( v2 > 163839 )
v2 -= 0x20000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
static void rollerg_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 offs = 0x10000 + ((lines & 0x07) * 0x4000);
 if (offs >= 0x28000) offs -= 0x20000;
 { 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 rollerg_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 offs = 0x10000 + ((lines & 0x07) * 0x4000);
 if (offs >= 0x28000) offs -= 0x20000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 sound_arm_nmi_w()
{
cpu_set_nmi_line(1LL, 0LL);
return timer_set(53687LL, 0LL, nmi_callback);
}

canonical_decompiled_code:
__int64 func10()
{
cpu_set_nmi_line(1LL, 0LL);
return timer_set(53687LL, 0LL, nmi_callback);
}

original_code:
static void sound_arm_nmi_w(offs_t offset,data_t data)
{
 cpu_set_nmi_line(1,0);
 timer_set(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)),0,nmi_callback);
}

canonical_original_code:
static void sound_arm_nmi_w(unsigned int offset, unsigned int data)
{
 cpu_set_nmi_line(1,0);
 timer_set(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)),0,nmi_callback);
}


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

result = 0LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = K053260_r((unsigned int)(a1 + 2));
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = K053260_r((unsigned int)(a1 + 2));
return result;
}

original_code:
static data_t rollerg_sound_r(offs_t offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else return 0x00;
}

canonical_original_code:
static unsigned int rollerg_sound_r(unsigned int offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else return 0x00;
}


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

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

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

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


decompiled_code:
__int64 __fastcall rollerg_0010_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
readzoomroms = a2 & 4;
return K051316_wraparound_enable(0LL, a2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
readzoomroms = a2 & 4;
return K051316_wraparound_enable(0LL, a2 & 0x20);
}

original_code:
static void rollerg_0010_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 readzoomroms = data & 0x04;
 K051316_wraparound_enable(0, data & 0x20);
}

canonical_original_code:
static void rollerg_0010_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 readzoomroms = data & 0x04;
 K051316_wraparound_enable(0, data & 0x20);
}


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

if ( readzoomroms )
result = K051316_rom_0_r();
else
result = K051316_0_r();
return result;
}

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

if ( readzoomroms )
result = K051316_rom_0_r();
else
result = K051316_0_r();
return result;
}

original_code:
static data_t rollerg_K051316_r(offs_t offset)
{
 if (readzoomroms) return K051316_rom_0_r(offset);
 else return K051316_0_r(offset);
}

canonical_original_code:
static unsigned int rollerg_K051316_r(unsigned int offset)
{
 if (readzoomroms) return K051316_rom_0_r(offset);
 else return K051316_0_r(offset);
}


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

tile_info[5] = (*a2 >> 6) & 3;
*a1 |= ((unsigned __int16)*a2 << 8) & 0xF00;
result = zoom_colorbase + ((*a2 >> 4) & 3u);
*a2 = result;
return result;
}

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

tile_info[5] = (*a2 >> 6) & 3;
*a1 |= ((unsigned __int16)*a2 << 8) & 0xF00;
result = zoom_colorbase + ((*a2 >> 4) & 3u);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 tile_info.flags = ((*color & 0xc0) >> 6);
 *code |= ((*color & 0x0f) << 8);
 *color = zoom_colorbase + ((*color & 0x30) >> 4);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 tile_info.flags = ((*color & 0xc0) >> 6);
 *code |= ((*color & 0x0f) << 8);
 *color = zoom_colorbase + ((*color & 0x30) >> 4);
}

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
__int64 pip_r()
{
return 127LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 127LL;
}

original_code:
static data_t pip_r(offs_t offset)
{
 return 0x7f;
}

canonical_original_code:
static unsigned int pip_r(unsigned int offset)
{
 return 0x7f;
}


original_code:
void seicross_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void seicross_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}