decompiled_code:
void crash_reset_w()
{
firetruck_bit7_flags &= 0xBFu;
}

canonical_decompiled_code:
void func0()
{
firetruck_bit7_flags &= 0xBFu;
}

original_code:
static void crash_reset_w(offs_t offset,data_t data)
{
 firetruck_bit7_flags &= ~0x40;
}

canonical_original_code:
static void crash_reset_w(unsigned int offset, unsigned int data)
{
 firetruck_bit7_flags &= ~0x40;
}


decompiled_code:
__int64 firetruck_vh_init()
{
buf = osd_alloc_bitmap(
**(unsigned int **)(Machine + 768LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 4LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 8LL));
return (unsigned int)-(buf == 0);
}

canonical_decompiled_code:
__int64 func1()
{
buf = osd_alloc_bitmap(
**(unsigned int **)(Machine + 768LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 4LL),
*(unsigned int *)(*(_QWORD *)(Machine + 768LL) + 8LL));
return (unsigned int)-(buf == 0);
}

original_code:
int firetruck_vh_init( void )
{
 buf = osd_alloc_bitmap(
   Machine->scrbitmap->width,
   Machine->scrbitmap->height,
   Machine->scrbitmap->depth );
 if( buf ) return 0;
 return -1;
}

canonical_original_code:
int firetruck_vh_init()
{
 buf = osd_alloc_bitmap(
   Machine->scrbitmap->width,
   Machine->scrbitmap->height,
   Machine->scrbitmap->depth );
 if( buf ) return 0;
 return -1;
}

return_type: int


decompiled_code:
__int64 firetruck_vh_stop()
{
return osd_free_bitmap(buf);
}

canonical_decompiled_code:
__int64 func2()
{
return osd_free_bitmap(buf);
}

original_code:
void firetruck_vh_stop( void )
{
 osd_free_bitmap( buf );
}

canonical_original_code:
void firetruck_vh_stop()
{
 osd_free_bitmap( buf );
}

return_type: void


decompiled_code:
__int64 __fastcall firetruck_xtndply_w(__int64 a1, char a2)
{
return discrete_sound_w(7LL, (a2 & 1) == 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
return discrete_sound_w(7LL, (a2 & 1) == 0);
}

original_code:
static void firetruck_xtndply_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x07,!(data&0x01));
}

canonical_original_code:
static void firetruck_xtndply_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x07,!(data&0x01));
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall firetruck_out_w(__int64 a1, unsigned int a2)
{
firetruck_invert_display = a2 & 4;
discrete_sound_w(6LL, ((unsigned __int8)(a2 >> 4) ^ 1) & 1);
return discrete_sound_w(5LL, ((unsigned __int8)(a2 >> 7) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
firetruck_invert_display = a2 & 4;
discrete_sound_w(6LL, ((unsigned __int8)(a2 >> 4) ^ 1) & 1);
return discrete_sound_w(5LL, ((unsigned __int8)(a2 >> 7) ^ 1) & 1);
}

original_code:
static void firetruck_out_w(offs_t offset,data_t data)
{
 firetruck_invert_display = data&0x04;
 discrete_sound_w(0x06,!(data&0x10));
 discrete_sound_w(0x05,(data&0x80)?0x00:0x01);
}

canonical_original_code:
static void firetruck_out_w(unsigned int offset, unsigned int data)
{
 firetruck_invert_display = data&0x04;
 discrete_sound_w(0x06,!(data&0x10));
 discrete_sound_w(0x05,(data&0x80)?0x00:0x01);
}


decompiled_code:
__int64 firetruck_skidsnd_w()
{
return discrete_sound_w(4LL, 1LL);
}

canonical_decompiled_code:
__int64 func5()
{
return discrete_sound_w(4LL, 1LL);
}

original_code:
static void firetruck_skidsnd_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x04,0x01);
}

canonical_original_code:
static void firetruck_skidsnd_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x04,0x01);
}


decompiled_code:
__int64 __fastcall firetruck_crashsnd_w(__int64 a1, unsigned __int8 a2)
{
return discrete_sound_w(3LL, a2 >> 4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 a2)
{
return discrete_sound_w(3LL, a2 >> 4);
}

original_code:
static void firetruck_crashsnd_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x03,(data&0xf0)>>4);
}

canonical_original_code:
static void firetruck_crashsnd_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x03,(data&0xf0)>>4);
}


decompiled_code:
__int64 __fastcall firetruck_motorsnd_w(__int64 a1, unsigned int a2)
{
discrete_sound_w(0LL, a2 & 0xF);
return discrete_sound_w(2LL, (a2 >> 4) & 0xF);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
discrete_sound_w(0LL, a2 & 0xF);
return discrete_sound_w(2LL, (a2 >> 4) & 0xF);
}

original_code:
static void firetruck_motorsnd_w(offs_t offset,data_t data)
{
 discrete_sound_w(0x00,data&0x0f);
 discrete_sound_w(0x02,(data&0xf0)>>4);
}

canonical_original_code:
static void firetruck_motorsnd_w(unsigned int offset, unsigned int data)
{
 discrete_sound_w(0x00,data&0x0f);
 discrete_sound_w(0x02,(data&0xf0)>>4);
}


decompiled_code:
__int64 skid_reset_w()
{
firetruck_bit0_flags &= 0xBFu;
return discrete_sound_w(4LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
firetruck_bit0_flags &= 0xBFu;
return discrete_sound_w(4LL, 0LL);
}

original_code:
static void skid_reset_w(offs_t offset,data_t data)
{
 firetruck_bit0_flags &= ~0x40;
 discrete_sound_w(0x04,0x00);
}

canonical_original_code:
static void skid_reset_w(unsigned int offset, unsigned int data)
{
 firetruck_bit0_flags &= ~0x40;
 discrete_sound_w(0x04,0x00);
}


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

draw_background((__int64)a1);
draw_text((__int64)a1);
draw_sprites(a1);
v1 = input_port_6_r(0LL);
return discrete_sound_w(1LL, v1);
}

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

func9((__int64)a1);
func10((__int64)a1);
func11(a1);
v1 = input_port_6_r(0LL);
return discrete_sound_w(1LL, v1);
}

original_code:
void firetruck_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 draw_background( bitmap );
 draw_text( bitmap );
 draw_sprites( bitmap );
 discrete_sound_w(0x01,input_port_6_r(0));
}

canonical_original_code:
void firetruck_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 draw_background( bitmap );
 draw_text( bitmap );
 draw_sprites( bitmap );
 discrete_sound_w(0x01,input_port_6_r(0));
}

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

variable_types: fullrefresh int


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

firetruck_bit7_flags |= 0xCu;
firetruck_steer1 = readinputport(4LL);
result = readinputport(5LL);
firetruck_steer2 = result;
return result;
}

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

firetruck_bit7_flags |= 0xCu;
firetruck_steer1 = readinputport(4LL);
result = readinputport(5LL);
firetruck_steer2 = result;
return result;
}

original_code:
static void steer_reset_w(offs_t offset,data_t data)
{
 firetruck_bit7_flags |= 0x0c;
 firetruck_steer1 = readinputport(4);
 firetruck_steer2 = readinputport(5);
}

canonical_original_code:
static void steer_reset_w(unsigned int offset, unsigned int data)
{
 firetruck_bit7_flags |= 0x0c;
 firetruck_steer1 = readinputport(4);
 firetruck_steer2 = readinputport(5);
}


decompiled_code:
__int64 __fastcall firetruck_dsw_r(int a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = readinputport(0LL);
v2 = (4 * (_BYTE)v1) & 0xC;
switch ( a1 )
{
case 1:
return (v1 >> 4) & 3 | v2;
case 2:
return (v1 >> 2) & 3 | v2;
case 0:
v2 |= (v1 >> 6) & 3;
break;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = readinputport(0LL);
v2 = (4 * (_BYTE)v1) & 0xC;
switch ( a1 )
{
case 1:
return (v1 >> 4) & 3 | v2;
case 2:
return (v1 >> 2) & 3 | v2;
case 0:
v2 |= (v1 >> 6) & 3;
break;
}
return v2;
}

original_code:
static data_t firetruck_dsw_r(offs_t offset)
{
 int dip = readinputport(0);
 int data = (dip&0x3)<<2;
 switch (offset)
 {
 case 0x00: data |= (dip>>6)&0x03; break;
 case 0x01: data |= (dip>>4)&0x03; break;
 case 0x02: data |= (dip>>2)&0x03; break;
 }
 return data;
}

canonical_original_code:
static unsigned int firetruck_dsw_r(unsigned int offset)
{
 int dip = readinputport(0);
 int data = (dip&0x3)<<2;
 switch (offset)
 {
 case 0x00: data |= (dip>>6)&0x03; break;
 case 0x01: data |= (dip>>4)&0x03; break;
 case 0x02: data |= (dip>>2)&0x03; break;
 }
 return data;
}

variable_types: dip int

variable_types: data int

return_type: unsigned int


decompiled_code:
__int64 __fastcall firetruck_io_r(char a1)
{
char v1; // r13
char v2; // bl
unsigned __int8 v3; // r12
char v4; // r14
int v5; // ebp
char v6; // al
char v7; // r13
char v8; // al
char v9; // al
int v10; // edx
__int64 result; // rax

v1 = readinputport(1LL);
v2 = v1;
v3 = readinputport(2LL);
v4 = readinputport(3LL);
v5 = 1 << a1;
v6 = readinputport(4LL) - firetruck_steer1;
if ( (unsigned __int8)(v6 + 3) > 6u )
{
v7 = v1 | 4;
if ( v6 < -3 )
v2 = v7;
firetruck_bit7_flags &= 0xFBu;
}
v8 = readinputport(5LL) - firetruck_steer2;
if ( (unsigned __int8)(v8 + 3) > 6u )
{
if ( v8 < -3 )
v2 |= 8u;
v9 = firetruck_bit7_flags & 0xF7;
firetruck_bit7_flags &= 0xF7u;
}
else
{
v9 = firetruck_bit7_flags;
}
v10 = (unsigned __int8)(v4 | v9);
LOBYTE(result) = (unsigned __int8)(v5 & (firetruck_bit0_flags | v2)) != 0;
if ( ((unsigned __int8)v5 & v3) != 0 )
LOBYTE(result) = result | 0x40;
if ( (v5 & v10) != 0 )
LOBYTE(result) = result | 0x80;
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char a1)
{
char v1; // r13
char v2; // bl
unsigned __int8 v3; // r12
char v4; // r14
int v5; // ebp
char v6; // al
char v7; // r13
char v8; // al
char v9; // al
int v10; // edx
__int64 result; // rax

v1 = readinputport(1LL);
v2 = v1;
v3 = readinputport(2LL);
v4 = readinputport(3LL);
v5 = 1 << a1;
v6 = readinputport(4LL) - firetruck_steer1;
if ( (unsigned __int8)(v6 + 3) > 6u )
{
v7 = v1 | 4;
if ( v6 < -3 )
v2 = v7;
firetruck_bit7_flags &= 0xFBu;
}
v8 = readinputport(5LL) - firetruck_steer2;
if ( (unsigned __int8)(v8 + 3) > 6u )
{
if ( v8 < -3 )
v2 |= 8u;
v9 = firetruck_bit7_flags & 0xF7;
firetruck_bit7_flags &= 0xF7u;
}
else
{
v9 = firetruck_bit7_flags;
}
v10 = (unsigned __int8)(v4 | v9);
LOBYTE(result) = (unsigned __int8)(v5 & (firetruck_bit0_flags | v2)) != 0;
if ( ((unsigned __int8)v5 & v3) != 0 )
LOBYTE(result) = result | 0x40;
if ( (v5 & v10) != 0 )
LOBYTE(result) = result | 0x80;
return (unsigned __int8)result;
}

original_code:
static data_t firetruck_io_r(offs_t offset)
{
 data8_t data, bit0, bit6, bit7;
 int bit,steer_poll;
 bit0 = readinputport(1);
 bit6 = readinputport(2);
 bit7 = readinputport(3);
 bit = 1<<offset;
 steer_poll = ((INT8)(readinputport(4) - firetruck_steer1))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x04;
  firetruck_bit7_flags &= ~0x04;
 }
 steer_poll = ((INT8)(readinputport(5) - firetruck_steer2))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x08;
  firetruck_bit7_flags &= ~0x08;
 }
 bit0 |= firetruck_bit0_flags;
 bit7 |= firetruck_bit7_flags;
 data = 0x00;
 if( bit0 & bit ) data |= 0x01;
 if( bit6 & bit ) data |= 0x40;
 if( bit7 & bit ) data |= 0x80;
 return data;
}

canonical_original_code:
static unsigned int firetruck_io_r(unsigned int offset)
{
 unsigned char data; unsigned char bit0; unsigned char bit6; unsigned char bit7;
 int bit; int steer_poll;
 bit0 = readinputport(1);
 bit6 = readinputport(2);
 bit7 = readinputport(3);
 bit = 1<<offset;
 steer_poll = ((INT8)(readinputport(4) - firetruck_steer1))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x04;
  firetruck_bit7_flags &= ~0x04;
 }
 steer_poll = ((INT8)(readinputport(5) - firetruck_steer2))/4;
 if( steer_poll )
 {
  if( steer_poll<0 ) bit0 |= 0x08;
  firetruck_bit7_flags &= ~0x08;
 }
 bit0 |= firetruck_bit0_flags;
 bit7 |= firetruck_bit7_flags;
 data = 0x00;
 if( bit0 & bit ) data |= 0x01;
 if( bit6 & bit ) data |= 0x40;
 if( bit7 & bit ) data |= 0x80;
 return data;
}

variable_types:
data
unsigned char

variable_types: bit int


decompiled_code:
__int64 firetruck_interrupt()
{
if ( (unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(1LL) & 0x80u) == 0LL )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func17()
{
if ( (unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(1LL) & 0x80u) == 0LL )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
int firetruck_interrupt( void )
{
 if( cpu_getiloops()==0 )
 {
  if( readinputport(1)&0x80 )
  {
   return ignore_interrupt();
  }
  else
  {
   return nmi_interrupt();
  }
 }
 else
 {
  return interrupt();
 }
}

canonical_original_code:
int firetruck_interrupt()
{
 if( cpu_getiloops()==0 )
 {
  if( readinputport(1)&0x80 )
  {
   return ignore_interrupt();
  }
  else
  {
   return nmi_interrupt();
  }
 }
 else
 {
  return interrupt();
 }
}


decompiled_code:
_BYTE *init_firetruck()
{
__int64 v0; // rsi
_BYTE *result; // rax
_BYTE *v2; // rsi
char v3; // dl
char v4; // cl
char v5; // dl

v0 = memory_region(129LL);
result = (_BYTE *)(v0 + 12288);
v2 = (_BYTE *)(v0 + 0x4000);
do
{
v3 = result[53248];
v4 = result[57344];
++result;
v5 = v4 | (16 * v3);
*(result - 1) = v5;
result[49151] = v5;
}
while ( v2 != result );
return result;
}

canonical_decompiled_code:
_BYTE *func18()
{
__int64 v0; // rsi
_BYTE *result; // rax
_BYTE *v2; // rsi
char v3; // dl
char v4; // cl
char v5; // dl

v0 = memory_region(129LL);
result = (_BYTE *)(v0 + 12288);
v2 = (_BYTE *)(v0 + 0x4000);
do
{
v3 = result[53248];
v4 = result[57344];
++result;
v5 = v4 | (16 * v3);
*(result - 1) = v5;
result[49151] = v5;
}
while ( v2 != result );
return result;
}

original_code:
void init_firetruck( void )
{
 UINT8 *pMem = memory_region( REGION_CPU1 );
 int i;
 for( i=0; i<0x1000; i++ )
 {
  int msn = pMem[0x10000+i];
  int lsn = pMem[0x10000+i+0x1000];
  int data = (msn<<4)|lsn;
  pMem[i+0x3000] = data;
  pMem[i+0xf000] = data;
 }
}

canonical_original_code:
void init_firetruck()
{
 unsigned char *pMem = memory_region( REGION_CPU1 );
 int i;
 for( i=0; i<0x1000; i++ )
 {
  int msn = pMem[0x10000+i];
  int lsn = pMem[0x10000+i+0x1000];
  int data = (msn<<4)|lsn;
  pMem[i+0x3000] = data;
  pMem[i+0xf000] = data;
 }
}

variable_types:
pMem
unsigned char *

variable_types: i int

variable_types: msn int

variable_types: lsn int


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
int v1; // er12
__int64 v2; // rbx
unsigned __int8 *v3; // r15
int v4; // er14
int v5; // ecx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-48h]
int v9; // [rsp+8h] [rbp-40h]
char v10; // [rsp+Ch] [rbp-3Ch]

v1 = 4 * (firetruck_invert_display != 0);
v2 = videoram + 2064LL;
v9 = *(unsigned __int8 *)(videoram + 4128LL);
v8 = videoram + 2320LL;
v10 = *(_BYTE *)(videoram + 4096LL) + videoram + 16;
do
{
v3 = (unsigned __int8 *)(v2 - 16);
v4 = -v9;
do
{
v5 = *v3++;
v6 = (unsigned __int8)v4;
v4 += 16;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v5 & 0x3F,
(unsigned int)(v1 + (v5 >> 6)),
0LL,
0LL,
v6,
(unsigned __int8)(v2 - v10),
Machine + 776LL,
0LL,
0LL);
}
while ( v3 != (unsigned __int8 *)v2 );
v2 = (__int64)(v3 + 16);
}
while ( (unsigned __int8 *)v8 != v3 + 16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // er12
__int64 v2; // rbx
unsigned __int8 *v3; // r15
int v4; // er14
int v5; // ecx
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-48h]
int v9; // [rsp+8h] [rbp-40h]
char v10; // [rsp+Ch] [rbp-3Ch]

v1 = 4 * (firetruck_invert_display != 0);
v2 = videoram + 2064LL;
v9 = *(unsigned __int8 *)(videoram + 4128LL);
v8 = videoram + 2320LL;
v10 = *(_BYTE *)(videoram + 4096LL) + videoram + 16;
do
{
v3 = (unsigned __int8 *)(v2 - 16);
v4 = -v9;
do
{
v5 = *v3++;
v6 = (unsigned __int8)v4;
v4 += 16;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v5 & 0x3F,
(unsigned int)(v1 + (v5 >> 6)),
0LL,
0LL,
v6,
(unsigned __int8)(v2 - v10),
Machine + 776LL,
0LL,
0LL);
}
while ( v3 != (unsigned __int8 *)v2 );
v2 = (__int64)(v3 + 16);
}
while ( (unsigned __int8 *)v8 != v3 + 16 );
return result;
}

original_code:
static void draw_background( struct osd_bitmap *bitmap )
{
 int color = firetruck_invert_display?4:0;
 int pvpload = videoram[0x1000];
 int phpload = videoram[0x1020];
 int x,y,tile_number;
 const UINT8 *source = videoram+0x800;
 for( y=0; y<256; y+=16 )
 {
  for( x=0; x<256; x+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[1],
    tile_number&0x3f,
    color+(tile_number>>6),
    0,0,
    (x-phpload)&0xff,(y-pvpload)&0xff,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap)
{
 int color = firetruck_invert_display?4:0;
 int pvpload = videoram[0x1000];
 int phpload = videoram[0x1020];
 int x; int y; int tile_number;
 unsigned char *source = videoram+0x800;
 for( y=0; y<256; y+=16 )
 {
  for( x=0; x<256; x+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[1],
    tile_number&0x3f,
    color+(tile_number>>6),
    0,0,
    (x-phpload)&0xff,(y-pvpload)&0xff,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

variable_types: color int

variable_types: pvpload int

variable_types: phpload int

variable_types: x int

variable_types: y int

variable_types:
source
unsigned char *

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


decompiled_code:
__int64 __fastcall draw_text(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
unsigned __int8 *v3; // r14
__int64 v4; // r15
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // [rsp-28h] [rbp-70h]
unsigned __int8 *v8; // [rsp+8h] [rbp-40h]

v1 = 0LL;
v2 = firetruck_invert_display == 0 ? 7 : 3;
v8 = (unsigned __int8 *)videoram;
do
{
v3 = v8;
v4 = 0LL;
do
{
v5 = *v3++;
v7 = v4;
v4 = (unsigned int)(v4 + 16);
result = drawgfx(a1, *(_QWORD *)(Machine + 512LL), v5, v2, 0LL, 0LL, v1, v7, Machine + 776LL, 0LL, 0LL);
}
while ( (_DWORD)v4 != 256 );
v1 = (unsigned int)(v1 + 240);
v8 += 16;
}
while ( (_DWORD)v1 != 480 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
unsigned __int8 *v3; // r14
__int64 v4; // r15
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // [rsp-28h] [rbp-70h]
unsigned __int8 *v8; // [rsp+8h] [rbp-40h]

v1 = 0LL;
v2 = firetruck_invert_display == 0 ? 7 : 3;
v8 = (unsigned __int8 *)videoram;
do
{
v3 = v8;
v4 = 0LL;
do
{
v5 = *v3++;
v7 = v4;
v4 = (unsigned int)(v4 + 16);
result = drawgfx(a1, *(_QWORD *)(Machine + 512LL), v5, v2, 0LL, 0LL, v1, v7, Machine + 776LL, 0LL, 0LL);
}
while ( (_DWORD)v4 != 256 );
v1 = (unsigned int)(v1 + 240);
v8 += 16;
}
while ( (_DWORD)v1 != 480 );
return result;
}

original_code:
static void draw_text( struct osd_bitmap *bitmap )
{
 int color = firetruck_invert_display?3:7;
 int x,y,tile_number;
 const UINT8 *source = videoram;
 for( x=0; x<=256-16; x+=256-16 )
 {
  for( y=0; y<256; y+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[0],
    tile_number,
    color,
    0,0,
    x,y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}

canonical_original_code:
static void draw_text(struct osd_bitmap *bitmap)
{
 int color = firetruck_invert_display?3:7;
 int x; int y; int tile_number;
 unsigned char *source = videoram;
 for( x=0; x<=256-16; x+=256-16 )
 {
  for( y=0; y<256; y+=16 )
  {
   tile_number = *source++;
   drawgfx( bitmap,
    Machine->gfx[0],
    tile_number,
    color,
    0,0,
    x,y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0 );
  }
 }
}


original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
 int color = firetruck_invert_display?3:7;
 int track_color = Machine->pens[firetruck_invert_display?0:3];
 int bgcolor = firetruck_invert_display?4:0;
 int cabrot = videoram[0x1080];
 int hpos = videoram[0x1460];
 int vpos = videoram[0x1480];
 int tailrot = videoram[0x14a0];
 int pen;
 int sx, sy;
 int x,y;
 int flipx,flipy;
 int pitch;
 pitch = (bitmap->depth==8)?bitmap->width:(bitmap->width*2);
 for( sy=0; sy<bitmap->height; sy++ )
 {
  memcpy( buf->line[sy], bitmap->line[sy], pitch );
 }
 flipx = tailrot&0x08;
 flipy = tailrot&0x10;
 sx = flipx?(hpos-47):(255-hpos-47);
 sy = flipy?(sy = vpos-47):(255-vpos-47);
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  bgcolor,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  bgcolor,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 if( bitmap->depth==8 )
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = buf->line[y][x];
    if( pen != bitmap->line[y][x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 else
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = ((UINT16 *)buf->line[y])[x];
    if( pen != ((UINT16 *)bitmap->line[y])[x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  color,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  color,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int color = firetruck_invert_display?3:7;
 int track_color = Machine->pens[firetruck_invert_display?0:3];
 int bgcolor = firetruck_invert_display?4:0;
 int cabrot = videoram[0x1080];
 int hpos = videoram[0x1460];
 int vpos = videoram[0x1480];
 int tailrot = videoram[0x14a0];
 int pen;
 int sx; int sy;
 int x; int y;
 int flipx; int flipy;
 int pitch;
 pitch = (bitmap->depth==8)?bitmap->width:(bitmap->width*2);
 for( sy=0; sy<bitmap->height; sy++ )
 {
  memcpy( buf->line[sy], bitmap->line[sy], pitch );
 }
 flipx = tailrot&0x08;
 flipy = tailrot&0x10;
 sx = flipx?(hpos-47):(255-hpos-47);
 sy = flipy?(sy = vpos-47):(255-vpos-47);
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  bgcolor,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  bgcolor,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 if( bitmap->depth==8 )
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = buf->line[y][x];
    if( pen != bitmap->line[y][x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 else
 {
  for( y=0; y<bitmap->height; y++ )
  {
   for( x=0; x<bitmap->width; x++ )
   {
    pen = ((unsigned short *)buf->line[y])[x];
    if( pen != ((unsigned short *)bitmap->line[y])[x] )
    {
     if( pen == track_color )
     {
      firetruck_bit7_flags |= 0x40;
     }
     else
     {
      firetruck_bit0_flags |= 0x40;
     }
    }
   }
  }
 }
 drawgfx( bitmap,
  Machine->gfx[2],
  tailrot&0x07,
  color,
  flipx,flipy,
  sx,sy,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
 drawgfx( bitmap,
  Machine->gfx[(cabrot&0x10)?3:4],
  cabrot&0x03,
  color,
  cabrot&0x04,
  cabrot&0x08,
  124,120,
  &Machine->visible_area,
  TRANSPARENCY_PEN,0 );
}

variable_types: bgcolor int

variable_types: cabrot int

variable_types: hpos int

variable_types: vpos int

variable_types: tailrot int

variable_types: pen int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: pitch int


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

result = 0xAAAA555555000000LL;
*(_DWORD *)(a1 + 8) = -86;
*(_QWORD *)a1 = 0xAAAA555555000000LL;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_910);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 a1, __m128i *a2)
{
unsigned __int64 result; // rax

result = 0xAAAA555555000000LL;
*(_DWORD *)(a1 + 8) = -86;
*(_QWORD *)a1 = 0xAAAA555555000000LL;
*a2 = _mm_load_si128((const __m128i *)&colortable);
a2[1] = _mm_load_si128((const __m128i *)&xmmword_910);
return result;
}

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

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


bit

decompiled_code:
__int64 __fastcall bit(int a1, char a2)
{
return (a1 >> a2) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, char a2)
{
return (a1 >> a2) & 1;
}

original_code:
static int bit(int i,int n)
{
 return ((i >> n) & 1);
}

canonical_original_code:
static int bit(int i, int n)
{
 return ((i >> n) & 1);
}

variable_types: i int

variable_types: n int


decompiled_code:
__int64 scobra_init_machine()
{
return interrupt_enable_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return interrupt_enable_w(0LL, 0LL);
}

original_code:
static void scobra_init_machine(void)
{
 interrupt_enable_w(0,0);
}

canonical_original_code:
static void scobra_init_machine()
{
 interrupt_enable_w(0,0);
}


decompiled_code:
__int64 __fastcall stratgyx_coin_counter_w(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

original_code:
static void stratgyx_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(offset >> 1, data);
}

canonical_original_code:
static void stratgyx_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(offset >> 1, data);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 init_moonwar2()
{
return install_mem_read_handler(0LL, 38912LL, 38912LL, moonwar2_IN0_r);
}

canonical_decompiled_code:
__int64 func3()
{
return install_mem_read_handler(0LL, 38912LL, 38912LL, moonwar2_IN0_r);
}

original_code:
static void init_moonwar2(void)
{
 install_mem_read_handler(0, 0x9800, 0x9800, moonwar2_IN0_r);
}

canonical_original_code:
static void init_moonwar2()
{
 install_mem_read_handler(0, 0x9800, 0x9800, moonwar2_IN0_r);
}


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

v0 = readinputport(3LL);
return (v0 >> 3) & 0x10 | v0 & 0xF | (unsigned int)(readinputport(0LL) & 0xE0);
}

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

v0 = readinputport(3LL);
return (v0 >> 3) & 0x10 | v0 & 0xF | (unsigned int)(readinputport(0LL) & 0xE0);
}

original_code:
static data_t moonwar2_IN0_r(offs_t offset)
{
 int sign;
 int delta;
 delta = readinputport(3);
 sign = (delta & 0x80) >> 3;
 delta &= 0x0f;
 return ((readinputport(0) & 0xe0) | delta | sign );
}

canonical_original_code:
static unsigned int moonwar2_IN0_r(unsigned int offset)
{
 int sign;
 int delta;
 delta = readinputport(3);
 sign = (delta & 0x80) >> 3;
 delta &= 0x0f;
 return ((readinputport(0) & 0xe0) | delta | sign );
}

variable_types: sign int

variable_types: delta int


original_code:
static void init_anteater(void)
{
 int i,j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0x9bf;
  j |= ( bit(i,4) ^ bit(i,9) ^ ( bit(i,2) & bit(i,10) ) ) << 6;
  j |= ( bit(i,2) ^ bit(i,10) ) << 9;
  j |= ( bit(i,0) ^ bit(i,6) ^ 1 ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}

canonical_original_code:
static void init_anteater()
{
 int i; int j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0x9bf;
  j |= ( bit(i,4) ^ bit(i,9) ^ ( bit(i,2) & bit(i,10) ) ) << 6;
  j |= ( bit(i,2) ^ bit(i,10) ) << 9;
  j |= ( bit(i,0) ^ bit(i,6) ^ 1 ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}

variable_types: j int

variable_types:
RAM
unsigned char *


original_code:
static void init_rescue(void)
{
 int i,j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xa7f;
  j |= ( bit(i,3) ^ bit(i,10) ) << 7;
  j |= ( bit(i,1) ^ bit(i,7) ) << 8;
  j |= ( bit(i,0) ^ bit(i,8) ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}

canonical_original_code:
static void init_rescue()
{
 int i; int j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xa7f;
  j |= ( bit(i,3) ^ bit(i,10) ) << 7;
  j |= ( bit(i,1) ^ bit(i,7) ) << 8;
  j |= ( bit(i,0) ^ bit(i,8) ) << 10;
  RAM[i] = RAM[j + 0x1000];
 }
}


original_code:
static void init_minefld(void)
{
 int i,j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xd5f;
  j |= ( bit(i,3) ^ bit(i,7) ) << 5;
  j |= ( bit(i,2) ^ bit(i,9) ^ ( bit(i,0) & bit(i,5) ) ^
    ( bit(i,3) & bit(i,7) & ( bit(i,0) ^ bit(i,5) ))) << 7;
  j |= ( bit(i,0) ^ bit(i,5) ^ ( bit(i,3) & bit(i,7) ) ) << 9;
  RAM[i] = RAM[j + 0x1000];
 }
}

canonical_original_code:
static void init_minefld()
{
 int i; int j;
 unsigned char *RAM;
 RAM = memory_region(REGION_GFX1);
 for (i = 0;i < 0x1000;i++)
 {
  j = i & 0xd5f;
  j |= ( bit(i,3) ^ bit(i,7) ) << 5;
  j |= ( bit(i,2) ^ bit(i,9) ^ ( bit(i,0) & bit(i,5) ) ^
    ( bit(i,3) & bit(i,7) & ( bit(i,0) ^ bit(i,5) ))) << 7;
  j |= ( bit(i,0) ^ bit(i,5) ^ ( bit(i,3) & bit(i,7) ) ) << 9;
  RAM[i] = RAM[j + 0x1000];
 }
}


decompiled_code:
__int64 init_superbon()
{
__int64 v0; // rax
int v1; // edx
_BYTE *v2; // rcx
__int64 result; // rax

v0 = memory_region(129LL);
v1 = 0;
v2 = (_BYTE *)v0;
do
{
while ( 1 )
{
result = v1 & 0x280;
if ( (_DWORD)result != 512 )
break;
*v2 ^= 0x12u;
LABEL_4:
++v1;
++v2;
if ( v1 == 4096 )
return result;
}
if ( (v1 & 0x280u) > 0x200 )
{
if ( (_DWORD)result == 640 )
*v2 ^= 0x10u;
goto LABEL_4;
}
if ( (v1 & 0x280) != 0 )
{
if ( (_DWORD)result == 128 )
*v2 ^= 0x82u;
goto LABEL_4;
}
++v1;
*v2++ ^= 0x92u;
}
while ( v1 != 4096 );
return result;
}

original_code:
static void init_superbon(void)
{
 int i;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 for (i = 0;i < 0x1000;i++)
 {
  switch (i & 0x280)
  {
   case 0x000:
    RAM[i] ^= 0x92;
    break;
   case 0x080:
    RAM[i] ^= 0x82;
    break;
   case 0x200:
    RAM[i] ^= 0x12;
    break;
   case 0x280:
    RAM[i] ^= 0x10;
    break;
  }
 }
}

canonical_original_code:
static void init_superbon()
{
 int i;
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 for (i = 0;i < 0x1000;i++)
 {
  switch (i & 0x280)
  {
   case 0x000:
    RAM[i] ^= 0x92;
    break;
   case 0x080:
    RAM[i] ^= 0x82;
    break;
   case 0x200:
    RAM[i] ^= 0x12;
    break;
   case 0x280:
    RAM[i] ^= 0x10;
    break;
  }
 }
}


decompiled_code:
__int64 init_hustler()
{
__int64 i; // r12
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // rdx
char v4; // al
unsigned __int8 *v5; // rcx
unsigned __int8 *v6; // rdi
int v7; // edx
__int64 result; // rax
int vars0; // [rsp+0h] [rbp+0h]
int vars4; // [rsp+4h] [rbp+4h]
int vars8; // [rsp+8h] [rbp+8h]
int varsC; // [rsp+Ch] [rbp+Ch]
int vars10; // [rsp+10h] [rbp+10h]
int vars14; // [rsp+14h] [rbp+14h]
int vars18; // [rsp+18h] [rbp+18h]
int vars1C; // [rsp+1Ch] [rbp+1Ch]

for ( i = 0LL; i != 0x4000; ++i )
{
v1 = memory_region(129LL);
v2 = 0LL;
v3 = v1;
do
{
*(&vars0 + v2) = ((int)i >> v2) & 1;
++v2;
}
while ( v2 != 8 );
v4 = (vars0 == vars4) - 2;
if ( varsC != vars18 )
v4 ^= 2u;
if ( vars10 != vars14 )
v4 ^= 4u;
if ( vars0 != vars8 )
v4 ^= 8u;
if ( varsC != vars8 )
v4 ^= 0x10u;
if ( vars4 != vars14 )
v4 ^= 0x20u;
if ( vars0 != vars1C )
v4 ^= 0x40u;
if ( vars18 != vars10 )
v4 += 0x80;
*(_BYTE *)(v3 + i) ^= v4;
}
v5 = (unsigned __int8 *)memory_region(130LL);
v6 = v5 + 2048;
do
{
v7 = *v5++;
result = v7 & 0xFFFFFFFC | (v7 >> 1) & 1 | (2 * (_BYTE)v7) & 2;
*(v5 - 1) = v7 & 0xFC | (v7 >> 1) & 1 | (2 * v7) & 2;
}
while ( v6 != v5 );
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 i; // r12
__int64 v1; // rax
__int64 v2; // rcx
__int64 v3; // rdx
char v4; // al
unsigned __int8 *v5; // rcx
unsigned __int8 *v6; // rdi
int v7; // edx
__int64 result; // rax
int vars0; // [rsp+0h] [rbp+0h]
int vars4; // [rsp+4h] [rbp+4h]
int vars8; // [rsp+8h] [rbp+8h]
int varsC; // [rsp+Ch] [rbp+Ch]
int vars10; // [rsp+10h] [rbp+10h]
int vars14; // [rsp+14h] [rbp+14h]
int vars18; // [rsp+18h] [rbp+18h]
int vars1C; // [rsp+1Ch] [rbp+1Ch]

for ( i = 0LL; i != 0x4000; ++i )
{
v1 = memory_region(129LL);
v2 = 0LL;
v3 = v1;
do
{
*(&vars0 + v2) = ((int)i >> v2) & 1;
++v2;
}
while ( v2 != 8 );
v4 = (vars0 == vars4) - 2;
if ( varsC != vars18 )
v4 ^= 2u;
if ( vars10 != vars14 )
v4 ^= 4u;
if ( vars0 != vars8 )
v4 ^= 8u;
if ( varsC != vars8 )
v4 ^= 0x10u;
if ( vars4 != vars14 )
v4 ^= 0x20u;
if ( vars0 != vars1C )
v4 ^= 0x40u;
if ( vars18 != vars10 )
v4 += 0x80;
*(_BYTE *)(v3 + i) ^= v4;
}
v5 = (unsigned __int8 *)memory_region(130LL);
v6 = v5 + 2048;
do
{
v7 = *v5++;
result = v7 & 0xFFFFFFFC | (v7 >> 1) & 1 | (2 * (_BYTE)v7) & 2;
*(v5 - 1) = v7 & 0xFC | (v7 >> 1) & 1 | (2 * v7) & 2;
}
while ( v6 != v5 );
return result;
}

original_code:
static void init_hustler(void)
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0xff;
  if (bits[0] ^ bits[1]) xormask ^= 0x01;
  if (bits[3] ^ bits[6]) xormask ^= 0x02;
  if (bits[4] ^ bits[5]) xormask ^= 0x04;
  if (bits[0] ^ bits[2]) xormask ^= 0x08;
  if (bits[2] ^ bits[3]) xormask ^= 0x10;
  if (bits[1] ^ bits[5]) xormask ^= 0x20;
  if (bits[0] ^ bits[7]) xormask ^= 0x40;
  if (bits[4] ^ bits[6]) xormask ^= 0x80;
  RAM[A] ^= xormask;
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}

canonical_original_code:
static void init_hustler()
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0xff;
  if (bits[0] ^ bits[1]) xormask ^= 0x01;
  if (bits[3] ^ bits[6]) xormask ^= 0x02;
  if (bits[4] ^ bits[5]) xormask ^= 0x04;
  if (bits[0] ^ bits[2]) xormask ^= 0x08;
  if (bits[2] ^ bits[3]) xormask ^= 0x10;
  if (bits[1] ^ bits[5]) xormask ^= 0x20;
  if (bits[0] ^ bits[7]) xormask ^= 0x40;
  if (bits[4] ^ bits[6]) xormask ^= 0x80;
  RAM[A] ^= xormask;
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}

variable_types: A int

variable_types:
xormask
unsigned char

variable_types:
bits
int [8]


original_code:
static void init_billiard(void)
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0x55;
  if (bits[2] ^ ( bits[3] & bits[6])) xormask ^= 0x01;
  if (bits[4] ^ ( bits[5] & bits[7])) xormask ^= 0x02;
  if (bits[0] ^ ( bits[7] & !bits[3])) xormask ^= 0x04;
  if (bits[3] ^ (!bits[0] & bits[2])) xormask ^= 0x08;
  if (bits[5] ^ (!bits[4] & bits[1])) xormask ^= 0x10;
  if (bits[6] ^ (!bits[2] & !bits[5])) xormask ^= 0x20;
  if (bits[1] ^ (!bits[6] & !bits[4])) xormask ^= 0x40;
  if (bits[7] ^ (!bits[1] & bits[0])) xormask ^= 0x80;
  RAM[A] ^= xormask;
  for (i = 0;i < 8;i++)
   bits[i] = (RAM[A] >> i) & 1;
  RAM[A] =
   (bits[7] << 0) +
   (bits[0] << 1) +
   (bits[3] << 2) +
   (bits[4] << 3) +
   (bits[5] << 4) +
   (bits[2] << 5) +
   (bits[1] << 6) +
   (bits[6] << 7);
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}

canonical_original_code:
static void init_billiard()
{
 int A;
 for (A = 0;A < 0x4000;A++)
 {
  unsigned char xormask;
  int bits[8];
  int i;
  unsigned char *RAM = memory_region(REGION_CPU1);
  for (i = 0;i < 8;i++)
   bits[i] = (A >> i) & 1;
  xormask = 0x55;
  if (bits[2] ^ ( bits[3] & bits[6])) xormask ^= 0x01;
  if (bits[4] ^ ( bits[5] & bits[7])) xormask ^= 0x02;
  if (bits[0] ^ ( bits[7] & !bits[3])) xormask ^= 0x04;
  if (bits[3] ^ (!bits[0] & bits[2])) xormask ^= 0x08;
  if (bits[5] ^ (!bits[4] & bits[1])) xormask ^= 0x10;
  if (bits[6] ^ (!bits[2] & !bits[5])) xormask ^= 0x20;
  if (bits[1] ^ (!bits[6] & !bits[4])) xormask ^= 0x40;
  if (bits[7] ^ (!bits[1] & bits[0])) xormask ^= 0x80;
  RAM[A] ^= xormask;
  for (i = 0;i < 8;i++)
   bits[i] = (RAM[A] >> i) & 1;
  RAM[A] =
   (bits[7] << 0) +
   (bits[0] << 1) +
   (bits[3] << 2) +
   (bits[4] << 3) +
   (bits[5] << 4) +
   (bits[2] << 5) +
   (bits[1] << 6) +
   (bits[6] << 7);
 }
 {
  unsigned char *RAM = memory_region(REGION_CPU2);
  for (A = 0;A < 0x0800;A++)
   RAM[A] = (RAM[A] & 0xfc) | ((RAM[A] & 1) << 1) | ((RAM[A] & 2) >> 1);
 }
}


original_code:
void hc55516_update(int num, INT16 *buffer, int length)
{
 struct hc55516_data *chip = &hc55516[num];
 INT32 data, slope;
 int i;
 if (length == 0)
  return;
 chip->update_count += length;
 if (chip->update_count > Machine->sample_rate / 32)
 {
  chip->update_count = Machine->sample_rate;
  chip->next_value = 0;
 }
 data = chip->curr_value;
 slope = ((INT32)chip->next_value - data) / length;
 chip->curr_value = chip->next_value;
 for (i = 0; i < length; i++, data += slope)
  *buffer++ = data;
}

canonical_original_code:
void hc55516_update(int num, short *buffer, int length)
{
 struct hc55516_data *chip = &hc55516[num];
 int data; int slope;
 int i;
 if (length == 0)
  return;
 chip->update_count += length;
 if (chip->update_count > Machine->sample_rate / 32)
 {
  chip->update_count = Machine->sample_rate;
  chip->next_value = 0;
 }
 data = chip->curr_value;
 slope = ((int)chip->next_value - data) / length;
 chip->curr_value = chip->next_value;
 for (i = 0; i < length; i++, data += slope)
  *buffer++ = data;
}

variable_types: num int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct hc55516_data { char channel; unsigned char last_clock; unsigned char databit; unsigned char shiftreg; short curr_value; short next_value; unsigned int update_count; float filter; float integrator; } *

variable_types: data int

variable_types: slope int


decompiled_code:
__int64 __fastcall hc55516_sh_start(__int64 a1)
{
int *v1; // rbp
int v2; // eax
_DWORD *v3; // r15
__int64 v4; // rbx
char v5; // al
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = *(int **)(a1 + 8);
leak = 1064336736;
v2 = *v1;
charge = LC0;
decay = LC0;
if ( v2 <= 0 )
return 0LL;
v3 = &hc55516;
v4 = 0LL;
while ( 1 )
{
*(_OWORD *)v3 = 0LL;
v3[4] = 0;
sprintf(v7, "HC55516 #%d", (unsigned int)v4);
v5 = stream_init(v7, LOBYTE(v1[v4 + 1]), *(unsigned int *)(Machine + 836LL), (unsigned int)v4, hc55516_update);
*(_BYTE *)v3 = v5;
if ( v5 == -1 )
break;
++v4;
v3 += 5;
if ( *v1 <= (int)v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int *v1; // rbp
int v2; // eax
_DWORD *v3; // r15
__int64 v4; // rbx
char v5; // al
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = *(int **)(a1 + 8);
leak = 1064336736;
v2 = *v1;
charge = LC0;
decay = LC0;
if ( v2 <= 0 )
return 0LL;
v3 = &hc55516;
v4 = 0LL;
while ( 1 )
{
*(_OWORD *)v3 = 0LL;
v3[4] = 0;
sprintf(v7, "HC55516 #%d", (unsigned int)v4);
v5 = stream_init(v7, LOBYTE(v1[v4 + 1]), *(unsigned int *)(Machine + 836LL), (unsigned int)v4, hc55516_update);
*(_BYTE *)v3 = v5;
if ( v5 == -1 )
break;
++v4;
v3 += 5;
if ( *v1 <= (int)v4 )
return 0LL;
}
return 1LL;
}

original_code:
int hc55516_sh_start(const struct MachineSound *msound)
{
 const struct hc55516_interface *intf = (const struct hc55516_interface *)msound->sound_interface;
 int i;
 charge = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 decay = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 leak = pow(exp(-1), 1.0 / (0.001 * 16000.0));
 for (i = 0; i < intf->num; i++)
 {
  struct hc55516_data *chip = &hc55516[i];
  char name[40];
  memset(chip, 0, sizeof(*chip));
  sprintf(name, "HC55516 #%d", i);
  chip->channel = stream_init(name, intf->volume[i] & 0xff, Machine->sample_rate, i, hc55516_update);
  if (chip->channel == -1)
   return 1;
 }
 return 0;
}

canonical_original_code:
int hc55516_sh_start(struct MachineSound *msound)
{
 struct hc55516_interface *intf = (const struct hc55516_interface *)msound->sound_interface;
 int i;
 charge = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 decay = pow(exp(-1), 1.0 / (0.004 * 16000.0));
 leak = pow(exp(-1), 1.0 / (0.001 * 16000.0));
 for (i = 0; i < intf->num; i++)
 {
  struct hc55516_data *chip = &hc55516[i];
  char name[40];
  memset(chip, 0, sizeof(*chip));
  sprintf(name, "HC55516 #%d", i);
  chip->channel = stream_init(name, intf->volume[i] & 0xff, Machine->sample_rate, i, hc55516_update);
  if (chip->channel == -1)
   return 1;
 }
 return 0;
}

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

variable_types: struct hc55516_interface { int num; int volume[4]; } *

variable_types: i int

variable_types:
name
char [40]

user_defined_types: struct hc55516_data { char channel; unsigned char last_clock; unsigned char databit; unsigned char shiftreg; short curr_value; short next_value; unsigned int update_count; float filter; float integrator; }


original_code:
void hc55516_clock_w(int num, int state)
{
 struct hc55516_data *chip = &hc55516[num];
 int clock = state & 1, diffclock;
 diffclock = clock ^ chip->last_clock;
 chip->last_clock = clock;
 if (diffclock && clock)
 {
  float integrator = chip->integrator, temp;
  chip->update_count = 0;
  if (chip->databit)
  {
   chip->shiftreg = ((chip->shiftreg << 1) | 1) & 7;
   integrator += chip->filter;
  }
  else
  {
   chip->shiftreg = (chip->shiftreg << 1) & 7;
   integrator -= chip->filter;
  }
  integrator *= leak;
  if (chip->shiftreg == 0 || chip->shiftreg == 7)
  {
   chip->filter = 1.0954 - ((1.0954 - chip->filter) * charge);
   if (chip->filter > 1.0954)
    chip->filter = 1.0954;
  }
  else
  {
   chip->filter *= decay;
   if (chip->filter < 0.0416)
    chip->filter = 0.0416;
  }
  temp = integrator * 10000.0;
  chip->integrator = integrator;
  if (temp < 0)
   chip->next_value = (int)(temp / (-temp * (1.0 / 32768.0) + 1.0));
  else
   chip->next_value = (int)(temp / (temp * (1.0 / 32768.0) + 1.0));
        {
            extern int fast_sound;
            if (!fast_sound) stream_update(chip->channel, 0);
        }
 }
}

canonical_original_code:
void hc55516_clock_w(int num, int state)
{
 struct hc55516_data *chip = &hc55516[num];
 int clock = state & 1; int diffclock;
 diffclock = clock ^ chip->last_clock;
 chip->last_clock = clock;
 if (diffclock && clock)
 {
  float integrator = chip->integrator; float temp;
  chip->update_count = 0;
  if (chip->databit)
  {
   chip->shiftreg = ((chip->shiftreg << 1) | 1) & 7;
   integrator += chip->filter;
  }
  else
  {
   chip->shiftreg = (chip->shiftreg << 1) & 7;
   integrator -= chip->filter;
  }
  integrator *= leak;
  if (chip->shiftreg == 0 || chip->shiftreg == 7)
  {
   chip->filter = 1.0954 - ((1.0954 - chip->filter) * charge);
   if (chip->filter > 1.0954)
    chip->filter = 1.0954;
  }
  else
  {
   chip->filter *= decay;
   if (chip->filter < 0.0416)
    chip->filter = 0.0416;
  }
  temp = integrator * 10000.0;
  chip->integrator = integrator;
  if (temp < 0)
   chip->next_value = (int)(temp / (-temp * (1.0 / 32768.0) + 1.0));
  else
   chip->next_value = (int)(temp / (temp * (1.0 / 32768.0) + 1.0));
        {
            extern int fast_sound;
            if (!fast_sound) stream_update(chip->channel, 0);
        }
 }
}

variable_types: state int

variable_types: clock int

variable_types: diffclock int

variable_types: integrator float

variable_types: temp float


decompiled_code:
float *__fastcall hc55516_clock_clear_w(int a1)
{
return hc55516_clock_w(a1, 0);
}

canonical_decompiled_code:
float *__fastcall func4(int a1)
{
return func2(a1, 0);
}

original_code:
void hc55516_clock_clear_w(int num, int data)
{
 hc55516_clock_w(num, 0);
}


decompiled_code:
float *__fastcall hc55516_clock_set_w(int a1)
{
return hc55516_clock_w(a1, 1);
}

canonical_decompiled_code:
float *__fastcall func5(int a1)
{
return func2(a1, 1);
}

original_code:
void hc55516_clock_set_w(int num, int data)
{
 hc55516_clock_w(num, 1);
}


decompiled_code:
float *__fastcall hc55516_digit_clock_clear_w(int a1, char a2)
{
BYTE2(hc55516[5 * a1]) = a2 & 1;
return hc55516_clock_w(a1, 0);
}

canonical_decompiled_code:
float *__fastcall func6(int a1, char a2)
{
BYTE2(hc55516[5 * a1]) = a2 & 1;
return func2(a1, 0);
}

original_code:
void hc55516_digit_clock_clear_w(int num, int data)
{
 hc55516[num].databit = data & 1;
 hc55516_clock_w(num, 0);
}


decompiled_code:
float *__fastcall hc55516_0_clock_w(__int64 a1, char a2)
{
return hc55516_clock_w(0, a2);
}

canonical_decompiled_code:
float *__fastcall func8(__int64 a1, char a2)
{
return func2(0, a2);
}

original_code: void hc55516_0_clock_w(offs_t offset,data_t data) { hc55516_clock_w(0,data); }

canonical_original_code: void hc55516_0_clock_w(unsigned int offset, unsigned int data) { hc55516_clock_w(0,data); }

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
float *hc55516_0_clock_clear_w()
{
return hc55516_clock_clear_w(0);
}

canonical_decompiled_code:
float *func9()
{
return func4(0);
}

original_code: void hc55516_0_clock_clear_w(offs_t offset,data_t data) { hc55516_clock_clear_w(0,data); }

canonical_original_code: void hc55516_0_clock_clear_w(unsigned int offset, unsigned int data) { hc55516_clock_clear_w(0,data); }


decompiled_code:
float *hc55516_0_clock_set_w()
{
return hc55516_clock_set_w(0);
}

canonical_decompiled_code:
float *func10()
{
return func5(0);
}

original_code: void hc55516_0_clock_set_w(offs_t offset,data_t data) { hc55516_clock_set_w(0,data); }

canonical_original_code: void hc55516_0_clock_set_w(unsigned int offset, unsigned int data) { hc55516_clock_set_w(0,data); }


decompiled_code:
float *__fastcall hc55516_0_digit_clock_clear_w(__int64 a1, char a2)
{
return hc55516_digit_clock_clear_w(0, a2);
}

canonical_decompiled_code:
float *__fastcall func11(__int64 a1, char a2)
{
return func6(0, a2);
}

original_code: void hc55516_0_digit_clock_clear_w(offs_t offset,data_t data) { hc55516_digit_clock_clear_w(0,data); }

canonical_original_code: void hc55516_0_digit_clock_clear_w(unsigned int offset, unsigned int data) { hc55516_digit_clock_clear_w(0,data); }


original_code:
void naughtyb_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;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 2) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 1) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8]) = i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + j*64;
  }
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8]) = i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + 32 + j*64;
  }
 }
}

canonical_original_code:
void naughtyb_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;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 2) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  bit0 = (color_prom[0] >> 1) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8]) = i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + j*64;
  }
 }
 for (i = 0;i < 8;i++)
 {
  int j;
  for (j = 0;j < 4;j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8]) = i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 1]) = 8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 2]) = 2*8 + i + 32 + j*64;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + 4*i + j*4*8 + 3]) = 3*8 + i + 32 + j*64;
  }
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: j int


decompiled_code:
__int64 naughtyb_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
unsigned int v3; // er8

bankreg = 0;
palreg = 0;
videoreg = 0;
v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
v2 = bitmap_alloc(544LL, 224LL);
v3 = 0;
tmpbitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 func1()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
unsigned int v3; // er8

bankreg = 0;
palreg = 0;
videoreg = 0;
v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
v2 = bitmap_alloc(544LL, 224LL);
v3 = 0;
tmpbitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
v3 = 1;
}
return v3;
}

original_code:
int naughtyb_vh_start(void)
{
 videoreg = palreg = bankreg = 0;
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 if ((tmpbitmap = bitmap_alloc(68*8,28*8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

canonical_original_code:
int naughtyb_vh_start()
{
 videoreg = palreg = bankreg = 0;
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 if ((tmpbitmap = bitmap_alloc(68*8,28*8)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}


decompiled_code:
void naughtyb_vh_stop()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

canonical_decompiled_code:
void func2()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

original_code:
void naughtyb_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 free(dirtybuffer);
}


decompiled_code:
__int64 __fastcall naughtyb_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // er12
int v4; // eax
__int64 v5; // r12
__int64 v6; // r15
int v8[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
if ( v1 > 1791 )
{
v3 = (v1 - 1792) >> 2;
v4 = (v1 & 3) + 64;
}
else
{
v4 = v1 & 0x3F;
v3 = v1 >> 6;
}
v5 = (unsigned int)(8 * v3);
v6 = (unsigned int)(8 * v4);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(naughtyb_videoram2 + v2) + (bankreg << 8),
(*(_BYTE *)(naughtyb_videoram2 + v2) >> 5) + 8 * (unsigned int)(unsigned __int8)palreg,
0LL,
0LL,
v6,
v5,
0LL,
0LL,
0LL);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
(unsigned int)*(unsigned __int8 *)(videoram + v2) + (bankreg << 8),
(*(_BYTE *)(videoram + v2) >> 5) + 8 * (unsigned int)(unsigned __int8)palreg,
0LL,
0LL,
v6,
v5,
0LL,
2LL,
0LL);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294966768LL, 0LL, &leftvisiblearea, 0LL, 0LL);
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294967056LL, 0LL, &rightvisiblearea, 0LL, 0LL);
v8[0] = 16 - (unsigned __int8)*naughtyb_scrollreg;
return copyscrollbitmap(a1, tmpbitmap, 1LL, v8, 0LL, 0LL, &scrollvisiblearea, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // er12
int v4; // eax
__int64 v5; // r12
__int64 v6; // r15
int v8[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
if ( v1 > 1791 )
{
v3 = (v1 - 1792) >> 2;
v4 = (v1 & 3) + 64;
}
else
{
v4 = v1 & 0x3F;
v3 = v1 >> 6;
}
v5 = (unsigned int)(8 * v3);
v6 = (unsigned int)(8 * v4);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(naughtyb_videoram2 + v2) + (bankreg << 8),
(*(_BYTE *)(naughtyb_videoram2 + v2) >> 5) + 8 * (unsigned int)(unsigned __int8)palreg,
0LL,
0LL,
v6,
v5,
0LL,
0LL,
0LL);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
(unsigned int)*(unsigned __int8 *)(videoram + v2) + (bankreg << 8),
(*(_BYTE *)(videoram + v2) >> 5) + 8 * (unsigned int)(unsigned __int8)palreg,
0LL,
0LL,
v6,
v5,
0LL,
2LL,
0LL);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294966768LL, 0LL, &leftvisiblearea, 0LL, 0LL);
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294967056LL, 0LL, &rightvisiblearea, 0LL, 0LL);
v8[0] = 16 - (unsigned __int8)*naughtyb_scrollreg;
return copyscrollbitmap(a1, tmpbitmap, 1LL, v8, 0LL, 0LL, &scrollvisiblearea, 0LL, 0LL);
}

original_code:
void naughtyb_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   if (offs < 0x700)
   {
    sx = offs % 64;
    sy = offs / 64;
   }
   else
   {
    sx = 64 + (offs - 0x700) % 4;
    sy = (offs - 0x700) / 4;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     naughtyb_videoram2[offs] + 256 * bankreg,
     (naughtyb_videoram2[offs] >> 5) + 8 * palreg,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + 256*bankreg,
     (videoram[offs] >> 5) + 8 * palreg,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_PEN,0);
  }
 }
 {
  int scrollx;
  copybitmap(bitmap,tmpbitmap,0,0,-66*8,0,&leftvisiblearea,TRANSPARENCY_NONE,0);
  copybitmap(bitmap,tmpbitmap,0,0,-30*8,0,&rightvisiblearea,TRANSPARENCY_NONE,0);
  scrollx = -*naughtyb_scrollreg + 16;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,0,0,&scrollvisiblearea,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
void naughtyb_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   if (offs < 0x700)
   {
    sx = offs % 64;
    sy = offs / 64;
   }
   else
   {
    sx = 64 + (offs - 0x700) % 4;
    sy = (offs - 0x700) / 4;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     naughtyb_videoram2[offs] + 256 * bankreg,
     (naughtyb_videoram2[offs] >> 5) + 8 * palreg,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + 256*bankreg,
     (videoram[offs] >> 5) + 8 * palreg,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_PEN,0);
  }
 }
 {
  int scrollx;
  copybitmap(bitmap,tmpbitmap,0,0,-66*8,0,&leftvisiblearea,TRANSPARENCY_NONE,0);
  copybitmap(bitmap,tmpbitmap,0,0,-30*8,0,&rightvisiblearea,TRANSPARENCY_NONE,0);
  scrollx = -*naughtyb_scrollreg + 16;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,0,0,&scrollvisiblearea,TRANSPARENCY_NONE,0);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: scrollx int


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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
int naughtyb_interrupt(void)
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
int naughtyb_interrupt()
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall rockrage_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rdx
__int64 result; // rax
int v7; // esi
__int64 v8; // r8
__int64 v9; // rdi

v5 = *(_QWORD *)(Machine + 512LL);
result = (unsigned int)(*(_DWORD *)(v5 + 12) * *(_DWORD *)(v5 + 24));
v7 = *(_DWORD *)(v5 + 12) * *(_DWORD *)(v5 + 24) / 2;
if ( (int)result > 1 )
{
v8 = a2 + 2LL * *(int *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL);
v9 = a2 + 2LL * (v7 + *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL));
result = 0LL;
do
{
*(_WORD *)(v8 + 2 * result) = *(_BYTE *)(a3 + result) & 0xF;
*(_WORD *)(v9 + 2 * result) = (*(_BYTE *)(a3 + result + 256) & 0xF) + 16;
++result;
}
while ( v7 > (int)result );
}
return result;
}

original_code:
void rockrage_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/2; i++){
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = 0x00 + (color_prom[i] & 0x0f);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + ((Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/2)+i]) = 0x10 + (color_prom[0x100+i] & 0x0f);
 }
}

canonical_original_code:
void rockrage_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/2; i++){
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = 0x00 + (color_prom[i] & 0x0f);
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + ((Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/2)+i]) = 0x10 + (color_prom[0x100+i] & 0x0f);
 }
}

variable_types: i int


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

result = a2 ^ (unsigned int)rockrage_vreg;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)rockrage_vreg) & 0xC) != 0 )
result = tilemap_mark_all_tiles_dirty(0LL);
rockrage_vreg = a2;
return result;
}

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

result = a2 ^ (unsigned int)rockrage_vreg;
if ( (((unsigned __int8)a2 ^ (unsigned __int8)rockrage_vreg) & 0xC) != 0 )
result = tilemap_mark_all_tiles_dirty(0LL);
rockrage_vreg = a2;
return result;
}

original_code:
void rockrage_vreg_w(offs_t offset,data_t data){
 if ((data & 0x0c) != (rockrage_vreg & 0x0c))
  tilemap_mark_all_tiles_dirty(0);
 rockrage_vreg = data;
}

canonical_original_code:
void rockrage_vreg_w(unsigned int offset, unsigned int data){
 if ((data & 0x0c) != (rockrage_vreg & 0x0c))
  tilemap_mark_all_tiles_dirty(0);
 rockrage_vreg = data;
}


decompiled_code:
__int64 rockrage_vh_start()
{
int v0; // er8
__int64 result; // rax

layer_colorbase = 0x1000000000LL;
v0 = K007342_vh_start(0LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

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

layer_colorbase = 0x1000000000LL;
v0 = K007342_vh_start(0LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int rockrage_vh_start(void)
{
 layer_colorbase[0] = 0x00;
 layer_colorbase[1] = 0x10;
 if (K007342_vh_start(0,tile_callback))
 {
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int rockrage_vh_start()
{
 layer_colorbase[0] = 0x00;
 layer_colorbase[1] = 0x10;
 if (K007342_vh_start(0,tile_callback))
 {
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 rockrage_vh_stop()
{
K007342_vh_stop();
return K007420_vh_stop();
}

original_code:
void rockrage_vh_stop(void)
{
 K007342_vh_stop();
 K007420_vh_stop();
}

canonical_original_code:
void rockrage_vh_stop()
{
 K007342_vh_stop();
 K007420_vh_stop();
}


decompiled_code:
__int64 __fastcall rockrage_vh_screenrefresh(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 0LL, 16LL);
K007420_sprites_draw(a1);
K007342_tilemap_draw(a1, 0LL, 17LL);
K007342_tilemap_draw(a1, 1LL, 0LL);
return K007342_tilemap_draw(a1, 1LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 0LL, 16LL);
K007420_sprites_draw(a1);
K007342_tilemap_draw(a1, 0LL, 17LL);
K007342_tilemap_draw(a1, 1LL, 0LL);
return K007342_tilemap_draw(a1, 1LL, 1LL);
}

original_code:
void rockrage_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 0, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 0, 1 | 0x10 );
 K007342_tilemap_draw( bitmap, 1, 0 );
 K007342_tilemap_draw( bitmap, 1, 1 );
}

canonical_original_code:
void rockrage_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 0, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 0, 1 | 0x10 );
 K007342_tilemap_draw( bitmap, 1, 0 );
 K007342_tilemap_draw( bitmap, 1, 1 );
}


decompiled_code:
__int64 __fastcall rockrage_speech_w(__int64 a1, unsigned int a2)
{
VLM5030_RST((a2 >> 2) & 1);
VLM5030_ST(a2 & 1);
return VLM5030_VCU((a2 & 2) != 0);
}

original_code:
static void rockrage_speech_w(offs_t offset,data_t data) {
 VLM5030_RST( ( data >> 2 ) & 0x01 );
 VLM5030_ST( ( data >> 0 ) & 0x01 );
 VLM5030_VCU( ( data >> 1 ) & 0x01 );
}

canonical_original_code:
static void rockrage_speech_w(unsigned int offset, unsigned int data) {
 VLM5030_RST( ( data >> 2 ) & 0x01 );
 VLM5030_ST( ( data >> 0 ) & 0x01 );
 VLM5030_VCU( ( data >> 1 ) & 0x01 );
}


decompiled_code:
_BOOL8 rockrage_VLM5030_busy_r()
{
return (unsigned int)VLM5030_BSY() != 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return (unsigned int)VLM5030_BSY() != 0;
}

original_code:
static data_t rockrage_VLM5030_busy_r(offs_t offset) {
 return ( VLM5030_BSY() ? 1 : 0 );
}

canonical_original_code:
static unsigned int rockrage_VLM5030_busy_r(unsigned int offset) {
 return ( VLM5030_BSY() ? 1 : 0 );
}


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

if ( (unsigned int)K007342_is_INT_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K007342_is_INT_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int rockrage_interrupt( void )
{
 if (K007342_is_INT_enabled())
        return 1;
    else
  return ignore_interrupt();
}

canonical_original_code:
static int rockrage_interrupt()
{
 if (K007342_is_INT_enabled())
        return 1;
    else
  return ignore_interrupt();
}


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

cpu_bankbase[1] = memory_region(129LL) + ((((a2 >> 4) & 7) + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

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

cpu_bankbase[1] = memory_region(129LL) + ((((a2 >> 4) & 7) + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

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

canonical_original_code:
static void rockrage_bankswitch_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + ((data & 0x70) >> 4) * 0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
}

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


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

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

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

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


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

v2 = *a1 | (4 * (unsigned __int16)*a2) & 0x100 | (2 * rockrage_vreg * ((2 * (unsigned __int16)*a2) & 0x100));
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 = 0;
return result;
}

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

v2 = *a1 | (4 * (unsigned __int16)*a2) & 0x100 | (2 * rockrage_vreg * ((2 * (unsigned __int16)*a2) & 0x100));
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 = 0;
return result;
}

original_code:
static void sprite_callback(int *code,int *color)
{
 *code |= ((*color & 0x40) << 2) | ((*color & 0x80) << 1)*(rockrage_vreg << 1);
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0;
}

canonical_original_code:
static void sprite_callback(int *code, int *color)
{
 *code |= ((*color & 0x40) << 2) | ((*color & 0x80) << 1)*(rockrage_vreg << 1);
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0;
}

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
void __fastcall battlane_video_ctrl_w(__int64 a1, int a2)
{
battlane_video_ctrl = a2;
}

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

original_code:
void battlane_video_ctrl_w(offs_t offset,data_t data)
{
 battlane_video_ctrl=data;
}

canonical_original_code:
void battlane_video_ctrl_w(unsigned int offset, unsigned int data)
{
 battlane_video_ctrl=data;
}


decompiled_code:
void __fastcall battlane_scrollx_w(__int64 a1, int a2)
{
battlane_scrollx = a2;
}

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

original_code:
void battlane_scrollx_w(offs_t offset,data_t data)
{
    battlane_scrollx=data;
}

canonical_original_code:
void battlane_scrollx_w(unsigned int offset, unsigned int data)
{
    battlane_scrollx=data;
}


decompiled_code:
void __fastcall battlane_scrolly_w(__int64 a1, int a2)
{
battlane_scrolly = a2;
}

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

original_code:
void battlane_scrolly_w(offs_t offset,data_t data)
{
    battlane_scrolly=data;
}

canonical_original_code:
void battlane_scrolly_w(unsigned int offset, unsigned int data)
{
    battlane_scrolly=data;
}


decompiled_code:
__int64 __fastcall battlane_tileram_r(int a1)
{
return (unsigned __int8)battlane_tileram[a1];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned __int8)battlane_tileram[a1];
}

original_code:
data_t battlane_tileram_r(offs_t offset)
{
    return battlane_tileram[offset];
}

canonical_original_code:
unsigned int battlane_tileram_r(unsigned int offset)
{
    return battlane_tileram[offset];
}


decompiled_code:
void *__fastcall battlane_spriteram_w(unsigned int a1, char a2)
{
void *result; // rax

result = &battlane_spriteram;
*((_BYTE *)&battlane_spriteram + a1) = a2;
return result;
}

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

result = &battlane_spriteram;
*((_BYTE *)&battlane_spriteram + a1) = a2;
return result;
}

original_code:
void battlane_spriteram_w(offs_t offset,data_t data)
{
    battlane_spriteram[offset]=data;
}

canonical_original_code:
void battlane_spriteram_w(unsigned int offset, unsigned int data)
{
    battlane_spriteram[offset]=data;
}


decompiled_code:
__int64 __fastcall battlane_spriteram_r(unsigned int a1)
{
return *((unsigned __int8 *)&battlane_spriteram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return *((unsigned __int8 *)&battlane_spriteram + a1);
}

original_code:
data_t battlane_spriteram_r(offs_t offset)
{
    return battlane_spriteram[offset];
}

canonical_original_code:
unsigned int battlane_spriteram_r(unsigned int offset)
{
    return battlane_spriteram[offset];
}


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

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

original_code:
data_t battlane_bitmap_r(offs_t offset)
{
 return battlane_bitmap[offset];
}

canonical_original_code:
unsigned int battlane_bitmap_r(unsigned int offset)
{
 return battlane_bitmap[offset];
}


decompiled_code:
_BOOL8 battlane_vh_start()
{
screen_bitmap = bitmap_alloc(256LL, 256LL);
if ( !screen_bitmap )
return 1LL;
battlane_bitmap = malloc(battlane_bitmap_size);
if ( !battlane_bitmap )
return 1LL;
memset(&battlane_spriteram, 0, 0x100uLL);
memset(battlane_tileram, 0xFFu, 0x800uLL);
bkgnd_bitmap = (void *)bitmap_alloc(512LL, 512LL);
return bkgnd_bitmap == 0LL;
}

canonical_decompiled_code:
_BOOL8 func8()
{
screen_bitmap = bitmap_alloc(256LL, 256LL);
if ( !screen_bitmap )
return 1LL;
battlane_bitmap = malloc(battlane_bitmap_size);
if ( !battlane_bitmap )
return 1LL;
memset(&battlane_spriteram, 0, 0x100uLL);
memset(battlane_tileram, 0xFFu, 0x800uLL);
bkgnd_bitmap = (void *)bitmap_alloc(512LL, 512LL);
return bkgnd_bitmap == 0LL;
}

original_code:
int battlane_vh_start(void)
{
 screen_bitmap = bitmap_alloc(0x20*8, 0x20*8);
 if (!screen_bitmap)
 {
  return 1;
 }
 battlane_bitmap=(unsigned char*)malloc(battlane_bitmap_size);
 if (!battlane_bitmap)
 {
  return 1;
 }
 memset(battlane_spriteram, 0, battlane_spriteram_size);
    memset(battlane_tileram,255, battlane_tileram_size);
    bkgnd_bitmap = bitmap_alloc(0x0200, 0x0200);
    if (!bkgnd_bitmap)
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int battlane_vh_start()
{
 screen_bitmap = bitmap_alloc(0x20*8, 0x20*8);
 if (!screen_bitmap)
 {
  return 1;
 }
 battlane_bitmap=(unsigned char *)malloc(battlane_bitmap_size);
 if (!battlane_bitmap)
 {
  return 1;
 }
 memset(battlane_spriteram, 0, battlane_spriteram_size);
    memset(battlane_tileram,255, battlane_tileram_size);
    bkgnd_bitmap = bitmap_alloc(0x0200, 0x0200);
    if (!bkgnd_bitmap)
 {
  return 1;
 }
 return 0;
}


decompiled_code:
void battlane_vh_stop()
{
if ( screen_bitmap )
bitmap_free();
if ( battlane_bitmap )
free(battlane_bitmap);
if ( bkgnd_bitmap )
free(bkgnd_bitmap);
}

canonical_decompiled_code:
void func9()
{
if ( screen_bitmap )
bitmap_free();
if ( battlane_bitmap )
free(battlane_bitmap);
if ( bkgnd_bitmap )
free(bkgnd_bitmap);
}

original_code:
void battlane_vh_stop(void)
{
 if (screen_bitmap)
 {
  bitmap_free(screen_bitmap);
 }
 if (battlane_bitmap)
 {
  free(battlane_bitmap);
 }
    if (bkgnd_bitmap)
    {
        free(bkgnd_bitmap);
    }
}

canonical_original_code:
void battlane_vh_stop()
{
 if (screen_bitmap)
 {
  bitmap_free(screen_bitmap);
 }
 if (battlane_bitmap)
 {
  free(battlane_bitmap);
 }
    if (bkgnd_bitmap)
    {
        free(bkgnd_bitmap);
    }
}


decompiled_code:
__int64 __fastcall battlane_shared_ram_r(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(129LL) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(129LL) + a1);
}

original_code:
data_t battlane_shared_ram_r(offs_t offset)
{
 unsigned char *RAM =
  memory_region(REGION_CPU1);
 return RAM[offset];
}

canonical_original_code:
unsigned int battlane_shared_ram_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 return RAM[offset];
}


decompiled_code:
__int64 init_battlane()
{
__int64 v0; // rbx
__int64 v1; // rcx
__int64 result; // rax

v0 = memory_region(130LL);
v1 = memory_region(129LL);
for ( result = 0LL; result != 0x4000; ++result )
*(_BYTE *)(v1 + result + 0x4000) = *(_BYTE *)(v0 + result);
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbx
__int64 v1; // rcx
__int64 result; // rax

v0 = memory_region(130LL);
v1 = memory_region(129LL);
for ( result = 0LL; result != 0x4000; ++result )
*(_BYTE *)(v1 + result + 0x4000) = *(_BYTE *)(v0 + result);
return result;
}

original_code:
static void init_battlane(void)
{
 unsigned char *src,*dest;
 int A;
 src = memory_region(REGION_CPU2);
 dest = memory_region(REGION_CPU1);
 for(A = 0;A < 0x4000;A++)
  dest[A + 0x4000] = src[A];
}

canonical_original_code:
static void init_battlane()
{
 unsigned char *src; unsigned char *dest;
 int A;
 src = memory_region(REGION_CPU2);
 dest = memory_region(REGION_CPU1);
 for(A = 0;A < 0x4000;A++)
  dest[A + 0x4000] = src[A];
}

variable_types:
src
unsigned char *

variable_types:
dest
unsigned char *

variable_types: A int


decompiled_code:
__int64 battlane_build_palette()
{
__int64 v0; // rbx
__int64 v1; // rbp
unsigned __int8 v2; // si
__int64 v3; // rdi
__int64 result; // rax

v0 = 0LL;
v1 = memory_region(145LL);
do
{
v2 = *(_BYTE *)(v1 + v0);
v3 = (unsigned int)v0++;
result = palette_change_color(v3, 32 * (v2 & 7u), (unsigned __int8)(4 * v2) & 0xE0, v2 & 0xC0);
}
while ( v0 != 64 );
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rbx
__int64 v1; // rbp
unsigned __int8 v2; // si
__int64 v3; // rdi
__int64 result; // rax

v0 = 0LL;
v1 = memory_region(145LL);
do
{
v2 = *(_BYTE *)(v1 + v0);
v3 = (unsigned int)v0++;
result = palette_change_color(v3, 32 * (v2 & 7u), (unsigned __int8)(4 * v2) & 0xE0, v2 & 0xC0);
}
while ( v0 != 64 );
return result;
}

original_code:
static inline void battlane_build_palette(void)
{
 int offset;
    unsigned char *PALETTE =
        memory_region(REGION_PROMS);
    for (offset = 0; offset < 0x40; offset++)
 {
          int palette = PALETTE[offset];
          int red, green, blue;
          blue = ((palette>>6)&0x03) * 16*4;
          green = ((palette>>3)&0x07) * 16*2;
          red = ((palette>>0)&0x07) * 16*2;
          palette_change_color (offset, red, green, blue);
 }
}

canonical_original_code:
static inline void battlane_build_palette()
{
 int offset;
    unsigned char *PALETTE = memory_region(REGION_PROMS);
    for (offset = 0; offset < 0x40; offset++)
 {
          int palette = PALETTE[offset];
          int red; int green; int blue;
          blue = ((palette>>6)&0x03) * 16*4;
          green = ((palette>>3)&0x07) * 16*2;
          red = ((palette>>0)&0x07) * 16*2;
          palette_change_color (offset, red, green, blue);
 }
}

variable_types: offset int

variable_types:
PALETTE
unsigned char *

variable_types: palette int

variable_types: red int

variable_types: green int

variable_types: blue int


decompiled_code:
__int64 __fastcall battlane_vh_screenrefresh(__int64 a1)
{
__int64 v1; // r14
int v2; // er15
__int64 v3; // rdx
unsigned int v4; // ecx
unsigned __int8 *v5; // r12
char v6; // cl
unsigned int v7; // er13
__int64 v8; // rdx
__int64 v9; // r8
__int64 v10; // rsi
__int64 v11; // rcx
__int64 v12; // rsi
__int64 i; // r9
__int64 result; // rax
__int64 v15; // rdx
__int64 v16; // rdx
int v17; // [rsp+4h] [rbp-184h]
unsigned int v18; // [rsp+8h] [rbp-180h]
char v19; // [rsp+8h] [rbp-180h]
char s[4]; // [rsp+20h] [rbp-168h] BYREF
int v21[78]; // [rsp+50h] [rbp-138h] BYREF

v17 = battlane_scrolly + ((battlane_video_ctrl & 1) << 8);
v1 = 0LL;
v2 = battlane_scrollx + ((battlane_cpu_control & 1) << 8);
battlane_build_palette();
palette_recalc();
do
{
v3 = byte_1300[v1 - 1024];
v4 = byte_1300[v1++];
drawgfx(bkgnd_bitmap, *(_QWORD *)(Machine + 8LL * (v4 & 1) + 520), v3, (v4 >> 1) & 7, flipscreen == 0);
}
while ( v1 != 1024 );
*(_DWORD *)s = -v2;
v21[0] = -v17;
v5 = (unsigned __int8 *)&battlane_spriteram;
copyscrollbitmap(a1, bkgnd_bitmap, 1LL, v21, 1LL, s, Machine + 776LL, 0LL, 0LL);
LOBYTE(v21[0]) = 0;
v6 = byte_1701;
v7 = (unsigned __int8)byte_1703
+ ((4 * (unsigned __int8)byte_1701) & 0x200)
+ ((8 * (unsigned __int8)byte_1701) & 0x100);
while ( (v6 & 1) == 0 )
{
LABEL_5:
if ( &unk_17FC == (_UNKNOWN *)v5 )
goto LABEL_14;
LABEL_6:
v8 = v5[5];
v6 = v5[5];
v7 = v5[7] + ((4 * (_WORD)v8) & 0x200) + ((8 * (_WORD)v8) & 0x100);
if ( (int)((_DWORD)v5 + 4 - (unsigned int)&battlane_spriteram) > 160 )
{
v19 = v5[5];
sprintf(s, "%02x ", v8);
strcat((char *)v21, s);
v6 = v19;
}
v5 += 4;
}
v9 = v6 & 4;
if ( !flipscreen )
v9 = (_DWORD)v9 == 0;
v10 = *(_QWORD *)(Machine + 512LL);
if ( (v6 & 0x10) != 0 )
{
v18 = v9;
drawgfx(a1, v10, v7, 0LL, v9);
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v7 + 1, 0LL, v18);
goto LABEL_5;
}
drawgfx(a1, v10, v7, 0LL, v9);
if ( &unk_17FC != (_UNKNOWN *)v5 )
goto LABEL_6;
LABEL_14:
v11 = screen_bitmap;
v12 = 0LL;
if ( flipscreen )
{
for ( i = 2040LL; i != -8; i -= 8LL )
{
for ( result = 0LL; result != 256; ++result )
{
v15 = *(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(v11 + 24) + 2040 - i) + result);
if ( (_BYTE)v15 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + i) + 255 - result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2 * v15);
}
}
}
else
{
do
{
for ( result = 0LL; result != 256; ++result )
{
v16 = *(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(v11 + 24) + v12) + result);
if ( (_BYTE)v16 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v12) + result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2 * v16);
}
v12 += 8LL;
}
while ( v12 != 2048 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v1; // r14
int v2; // er15
__int64 v3; // rdx
unsigned int v4; // ecx
unsigned __int8 *v5; // r12
char v6; // cl
unsigned int v7; // er13
__int64 v8; // rdx
__int64 v9; // r8
__int64 v10; // rsi
__int64 v11; // rcx
__int64 v12; // rsi
__int64 i; // r9
__int64 result; // rax
__int64 v15; // rdx
__int64 v16; // rdx
int v17; // [rsp+4h] [rbp-184h]
unsigned int v18; // [rsp+8h] [rbp-180h]
char v19; // [rsp+8h] [rbp-180h]
char s[4]; // [rsp+20h] [rbp-168h] BYREF
int v21[78]; // [rsp+50h] [rbp-138h] BYREF

v17 = battlane_scrolly + ((battlane_video_ctrl & 1) << 8);
v1 = 0LL;
v2 = battlane_scrollx + ((battlane_cpu_control & 1) << 8);
func13();
palette_recalc();
do
{
v3 = byte_1300[v1 - 1024];
v4 = byte_1300[v1++];
drawgfx(bkgnd_bitmap, *(_QWORD *)(Machine + 8LL * (v4 & 1) + 520), v3, (v4 >> 1) & 7, flipscreen == 0);
}
while ( v1 != 1024 );
*(_DWORD *)s = -v2;
v21[0] = -v17;
v5 = (unsigned __int8 *)&battlane_spriteram;
copyscrollbitmap(a1, bkgnd_bitmap, 1LL, v21, 1LL, s, Machine + 776LL, 0LL, 0LL);
LOBYTE(v21[0]) = 0;
v6 = byte_1701;
v7 = (unsigned __int8)byte_1703
+ ((4 * (unsigned __int8)byte_1701) & 0x200)
+ ((8 * (unsigned __int8)byte_1701) & 0x100);
while ( (v6 & 1) == 0 )
{
LABEL_5:
if ( &unk_17FC == (_UNKNOWN *)v5 )
goto LABEL_14;
LABEL_6:
v8 = v5[5];
v6 = v5[5];
v7 = v5[7] + ((4 * (_WORD)v8) & 0x200) + ((8 * (_WORD)v8) & 0x100);
if ( (int)((_DWORD)v5 + 4 - (unsigned int)&battlane_spriteram) > 160 )
{
v19 = v5[5];
sprintf(s, "%02x ", v8);
strcat((char *)v21, s);
v6 = v19;
}
v5 += 4;
}
v9 = v6 & 4;
if ( !flipscreen )
v9 = (_DWORD)v9 == 0;
v10 = *(_QWORD *)(Machine + 512LL);
if ( (v6 & 0x10) != 0 )
{
v18 = v9;
drawgfx(a1, v10, v7, 0LL, v9);
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v7 + 1, 0LL, v18);
goto LABEL_5;
}
drawgfx(a1, v10, v7, 0LL, v9);
if ( &unk_17FC != (_UNKNOWN *)v5 )
goto LABEL_6;
LABEL_14:
v11 = screen_bitmap;
v12 = 0LL;
if ( flipscreen )
{
for ( i = 2040LL; i != -8; i -= 8LL )
{
for ( result = 0LL; result != 256; ++result )
{
v15 = *(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(v11 + 24) + 2040 - i) + result);
if ( (_BYTE)v15 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + i) + 255 - result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2 * v15);
}
}
}
else
{
do
{
for ( result = 0LL; result != 256; ++result )
{
v16 = *(unsigned __int8 *)(*(_QWORD *)(*(_QWORD *)(v11 + 24) + v12) + result);
if ( (_BYTE)v16 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v12) + result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2 * v16);
}
v12 += 8LL;
}
while ( v12 != 2048 );
}
return result;
}

original_code:
void battlane_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    int scrollx,scrolly;
 int x,y, offs;
    scrolly=256*(battlane_video_ctrl&0x01)+battlane_scrolly;
    scrollx=256*(battlane_cpu_control&0x01)+battlane_scrollx;
    battlane_build_palette();
 if (palette_recalc ())
    {
    }
    for (offs=0; offs <0x400; offs++)
    {
        int sx,sy;
        int code=battlane_tileram[offs];
        int attr=battlane_tileram[0x400+offs];
        sx=(offs&0x0f)+(offs&0x100)/16;
        sy=((offs&0x200)/2+(offs&0x0f0))/16;
        drawgfx(bkgnd_bitmap,Machine->gfx[1+(attr&0x01)],
               code,
               (attr>>1)&0x07,
               !flipscreen,flipscreen,
               sx*16,sy*16,
               ((void *)0),
               TRANSPARENCY_NONE, 0);
    }
    {
  int scrlx, scrly;
        scrlx=-scrollx;
        scrly=-scrolly;
        copyscrollbitmap(bitmap,bkgnd_bitmap,1,&scrly,1,&scrlx,&Machine->visible_area,TRANSPARENCY_NONE,0);
    }
    {
    char baf[256];
    char baf2[40];
    baf[0]=0;
    for (offs=0; offs<0x0100; offs+=4)
 {
          int attr=battlane_spriteram[offs+1];
          int code=battlane_spriteram[offs+3];
          code += 256*((attr>>6) & 0x02);
          code += 256*((attr>>5) & 0x01);
          if (offs > 0x00a0)
          {
               sprintf(baf2, "%02x ", attr);
               strcat(baf,baf2);
          }
          if (attr & 0x01)
       {
               int sx=battlane_spriteram[offs+2];
               int sy=battlane_spriteram[offs];
               int flipx=attr&0x04;
               int flipy=attr&0x02;
               if (!flipscreen)
               {
                    sx=240-sx;
                    sy=240-sy;
                    flipy=!flipy;
                    flipx=!flipx;
               }
               if ( attr & 0x10)
               {
                   int dy=16;
                   if (flipy)
                   {
                        dy=-16;
                   }
                   drawgfx(bitmap,Machine->gfx[0],
                     code,
                     0,
                     flipx,flipy,
                     sx, sy,
      &Machine->visible_area,
                     TRANSPARENCY_PEN, 0);
                    drawgfx(bitmap,Machine->gfx[0],
                     code+1,
                     0,
                     flipx,flipy,
                     sx, sy-dy,
      &Machine->visible_area,
                     TRANSPARENCY_PEN, 0);
                }
                else
                {
                   drawgfx(bitmap,Machine->gfx[0],
      code,
                     0,
                     flipx,flipy,
                     sx, sy,
      &Machine->visible_area,
                     TRANSPARENCY_PEN, 0);
                }
          }
 }
    }
    if (flipscreen)
    {
        for (y=0; y<0x20*8; y++)
        {
            for (x=0; x<0x20*8; x++)
            {
                int data=screen_bitmap->line[y][x];
                if (data)
                {
                    bitmap->line[255-y][255-x]=Machine->pens[data];
                }
            }
        }
    }
    else
    {
        for (y=0; y<0x20*8; y++)
        {
            for (x=0; x<0x20*8; x++)
            {
                int data=screen_bitmap->line[y][x];
                if (data)
                {
                    bitmap->line[y][x]=Machine->pens[data];
                }
            }
        }
    }
}

canonical_original_code:
void battlane_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    int scrollx; int scrolly;
 int x; int y; int offs;
    scrolly=256*(battlane_video_ctrl&0x01)+battlane_scrolly;
    scrollx=256*(battlane_cpu_control&0x01)+battlane_scrollx;
    battlane_build_palette();
 if (palette_recalc ())
    {
    }
    for (offs=0; offs <0x400; offs++)
    {
        int sx; int sy;
        int code = battlane_tileram[offs];
        int attr = battlane_tileram[0x400+offs];
        sx=(offs&0x0f)+(offs&0x100)/16;
        sy=((offs&0x200)/2+(offs&0x0f0))/16;
        drawgfx(bkgnd_bitmap,Machine->gfx[1+(attr&0x01)],
               code,
               (attr>>1)&0x07,
               !flipscreen,flipscreen,
               sx*16,sy*16,
               ((void *)0),
               TRANSPARENCY_NONE, 0);
    }
    {
  int scrlx; int scrly;
        scrlx=-scrollx;
        scrly=-scrolly;
        copyscrollbitmap(bitmap,bkgnd_bitmap,1,&scrly,1,&scrlx,&Machine->visible_area,TRANSPARENCY_NONE,0);
    }
    {
    char baf[256];
    char baf2[40];
    baf[0]=0;
    for (offs=0; offs<0x0100; offs+=4)
 {
          int attr = battlane_spriteram[offs+1];
          int code = battlane_spriteram[offs+3];
          code += 256*((attr>>6) & 0x02);
          code += 256*((attr>>5) & 0x01);
          if (offs > 0x00a0)
          {
               sprintf(baf2, "%02x ", attr);
               strcat(baf,baf2);
          }
          if (attr & 0x01)
       {
               int sx = battlane_spriteram[offs+2];
               int sy = battlane_spriteram[offs];
               int flipx = attr&0x04;
               int flipy = attr&0x02;
               if (!flipscreen)
               {
                    sx=240-sx;
                    sy=240-sy;
                    flipy=!flipy;
                    flipx=!flipx;
               }
               if ( attr & 0x10)
               {
                   int dy = 16;
                   if (flipy)
                   {
                        dy=-16;
                   }
                   drawgfx(bitmap,Machine->gfx[0],
                     code,
                     0,
                     flipx,flipy,
                     sx, sy,
      &Machine->visible_area,
                     TRANSPARENCY_PEN, 0);
                    drawgfx(bitmap,Machine->gfx[0],
                     code+1,
                     0,
                     flipx,flipy,
                     sx, sy-dy,
      &Machine->visible_area,
                     TRANSPARENCY_PEN, 0);
                }
                else
                {
                   drawgfx(bitmap,Machine->gfx[0],
      code,
                     0,
                     flipx,flipy,
                     sx, sy,
      &Machine->visible_area,
                     TRANSPARENCY_PEN, 0);
                }
          }
 }
    }
    if (flipscreen)
    {
        for (y=0; y<0x20*8; y++)
        {
            for (x=0; x<0x20*8; x++)
            {
                int data = screen_bitmap->line[y][x];
                if (data)
                {
                    bitmap->line[255-y][255-x]=Machine->pens[data];
                }
            }
        }
    }
    else
    {
        for (y=0; y<0x20*8; y++)
        {
            for (x=0; x<0x20*8; x++)
            {
                int data = screen_bitmap->line[y][x];
                if (data)
                {
                    bitmap->line[y][x]=Machine->pens[data];
                }
            }
        }
    }
}

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

variable_types: scrolly int

variable_types: x int

variable_types: y int

variable_types: offs int

variable_types: sx int

variable_types: code int

variable_types: attr int

variable_types: scrlx int

variable_types: scrly int

variable_types:
baf
char [256]

variable_types: flipx int

variable_types: flipy int

variable_types: dy int

variable_types: data int


decompiled_code:
__int64 battlane_cpu1_interrupt()
{
if ( (unsigned int)cpu_getiloops() )
return 2LL;
if ( (battlane_cpu_control & 8) != 0 )
return ignore_interrupt();
cpu_set_nmi_line(1LL, 3LL);
return 4LL;
}

canonical_decompiled_code:
__int64 func15()
{
if ( (unsigned int)cpu_getiloops() )
return 2LL;
if ( (battlane_cpu_control & 8) != 0 )
return ignore_interrupt();
cpu_set_nmi_line(1LL, 3LL);
return 4LL;
}

original_code:
int battlane_cpu1_interrupt(void)
{
    if (cpu_getiloops()==0)
 {
        if (~battlane_cpu_control & 0x08)
        {
            cpu_set_nmi_line(1, 3);
            return 4;
        }
        else
            return ignore_interrupt();
 }
    else
 {
  return 2;
 }
}

canonical_original_code:
int battlane_cpu1_interrupt()
{
    if (cpu_getiloops()==0)
 {
        if (~battlane_cpu_control & 0x08)
        {
            cpu_set_nmi_line(1, 3);
            return 4;
        }
        else
            return ignore_interrupt();
 }
    else
 {
  return 2;
 }
}


decompiled_code:
// attributes: thunk
__int64 battlane_cpu2_interrupt()
{
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func16()
{
return ignore_interrupt();
}

original_code:
int battlane_cpu2_interrupt(void)
{
 return ignore_interrupt();
}

canonical_original_code:
int battlane_cpu2_interrupt()
{
 return ignore_interrupt();
}


decompiled_code:
__int64 battlane_video_ctrl_r()
{
return (unsigned int)battlane_video_ctrl;
}

canonical_decompiled_code:
__int64 func17()
{
return (unsigned int)battlane_video_ctrl;
}

original_code:
data_t battlane_video_ctrl_r(offs_t offset)
{
 return battlane_video_ctrl;
}

canonical_original_code:
unsigned int battlane_video_ctrl_r(unsigned int offset)
{
 return battlane_video_ctrl;
}

variable_types:
offset
unsigned int


decompiled_code:
void battlane_set_video_flip()
{
flipscreen = 0;
}

canonical_decompiled_code:
void func18()
{
flipscreen = 0;
}

original_code:
void battlane_set_video_flip(int flip)
{
    if (flip != flipscreen)
    {
    }
    flipscreen=flip;
    flipscreen=0;
}

variable_types: flip int


decompiled_code:
__int64 __fastcall battlane_cpu_command_w(__int64 a1, int a2)
{
battlane_cpu_control = a2;
battlane_set_video_flip();
cpu_set_irq_line(0LL, 0LL, 2 * (unsigned int)((a2 & 4) == 0));
return cpu_set_irq_line(1LL, 0LL, ~(_BYTE)a2 & 2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2)
{
battlane_cpu_control = a2;
func18();
cpu_set_irq_line(0LL, 0LL, 2 * (unsigned int)((a2 & 4) == 0));
return cpu_set_irq_line(1LL, 0LL, ~(_BYTE)a2 & 2);
}

original_code:
void battlane_cpu_command_w(offs_t offset,data_t data)
{
 battlane_cpu_control=data;
    battlane_set_video_flip(data & 0x80);
    cpu_set_irq_line(0, 0, data & 0x04 ? 0 : 2);
 cpu_set_irq_line(1, 0, data & 0x02 ? 0 : 2);
}

canonical_original_code:
void battlane_cpu_command_w(unsigned int offset, unsigned int data)
{
 battlane_cpu_control=data;
    battlane_set_video_flip(data & 0x80);
    cpu_set_irq_line(0, 0, data & 0x04 ? 0 : 2);
 cpu_set_irq_line(1, 0, data & 0x02 ? 0 : 2);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall hexstr2num(char **a1)
{
char *v1; // rcx
unsigned int v2; // er8
int v3; // eax
char v4; // dl

v1 = *a1;
v2 = 0;
if ( !*a1 )
return v2;
while ( 1 )
{
v4 = *v1++;
LOBYTE(v3) = v4 - 48;
if ( (unsigned __int8)(v4 - 48) <= 9u )
goto LABEL_4;
if ( (unsigned __int8)(v4 - 97) <= 5u )
{
LOBYTE(v3) = v4 - 87;
LABEL_4:
v3 = (char)v3;
goto LABEL_5;
}
if ( (unsigned __int8)(v4 - 65) > 5u )
break;
v3 = (char)(v4 - 55);
LABEL_5:
v2 = v3 + 16 * v2;
}
if ( !v4 )
v1 = 0LL;
*a1 = v1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1)
{
char *v1; // rcx
unsigned int v2; // er8
int v3; // eax
char v4; // dl

v1 = *a1;
v2 = 0;
if ( !*a1 )
return v2;
while ( 1 )
{
v4 = *v1++;
LOBYTE(v3) = v4 - 48;
if ( (unsigned __int8)(v4 - 48) <= 9u )
goto LABEL_4;
if ( (unsigned __int8)(v4 - 97) <= 5u )
{
LOBYTE(v3) = v4 - 87;
LABEL_4:
v3 = (char)v3;
goto LABEL_5;
}
if ( (unsigned __int8)(v4 - 65) > 5u )
break;
v3 = (char)(v4 - 55);
LABEL_5:
v2 = v3 + 16 * v2;
}
if ( !v4 )
v1 = 0LL;
*a1 = v1;
return v2;
}

original_code:
static UINT32 hexstr2num (const char **pString)
{
 const char *string = *pString;
 UINT32 result = 0;
 if (string)
 {
  for(;;)
  {
   char c = *string++;
   int digit;
   if (c>='0' && c<='9')
   {
    digit = c-'0';
   }
   else if (c>='a' && c<='f')
   {
    digit = 10+c-'a';
   }
   else if (c>='A' && c<='F')
   {
    digit = 10+c-'A';
   }
   else
   {
    if (!c) string = ((void *)0);
    break;
   }
   result = result*16 + digit;
  }
  *pString = string;
 }
 return result;
}

canonical_original_code:
static unsigned int hexstr2num(char **pString)
{
 char *string = *pString;
 unsigned int result = 0;
 if (string)
 {
  for(;;)
  {
   char c = *string++;
   int digit;
   if (c>='0' && c<='9')
   {
    digit = c-'0';
   }
   else if (c>='a' && c<='f')
   {
    digit = 10+c-'a';
   }
   else if (c>='A' && c<='F')
   {
    digit = 10+c-'A';
   }
   else
   {
    if (!c) string = ((void *)0);
    break;
   }
   result = result*16 + digit;
  }
  *pString = string;
 }
 return result;
}

variable_types:
pString
char **

variable_types:
string
char *

variable_types:
result
unsigned int

variable_types: c char

variable_types: digit int


decompiled_code:
_BOOL8 __fastcall is_mem_range(char *a1)
{
char v1; // al
_BOOL8 result; // rax

do
{
v1 = *a1++;
if ( !v1 )
return 0LL;
}
while ( v1 != 58 );
result = 1LL;
if ( (unsigned __int8)(*a1 - 48) > 9u )
result = (unsigned __int8)((*a1 & 0xDF) - 65) <= 5u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *a1)
{
char v1; // al
_BOOL8 result; // rax

do
{
v1 = *a1++;
if ( !v1 )
return 0LL;
}
while ( v1 != 58 );
result = 1LL;
if ( (unsigned __int8)(*a1 - 48) > 9u )
result = (unsigned __int8)((*a1 & 0xDF) - 65) <= 5u;
return result;
}

original_code:
static int is_mem_range (const char *pBuf)
{
 char c;
 for(;;)
 {
  c = *pBuf++;
  if (c == 0) return 0;
  if (c == ':') break;
 }
 c = *pBuf;
 return (c>='0' && c<='9') ||
   (c>='a' && c<='f') ||
   (c>='A' && c<='F');
}

variable_types:
pBuf
char *


decompiled_code:
_BOOL8 __fastcall matching_game_name(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
do
{
v3 = *(_BYTE *)(a2 + v2);
v4 = *(_BYTE *)(a1 + v2);
if ( !v3 )
return v4 == 58;
++v2;
}
while ( v3 == v4 );
return 0LL;
}

original_code:
static int matching_game_name (const char *pBuf, const char *name)
{
 while (*name)
 {
  if (*name++ != *pBuf++) return 0;
 }
 return (*pBuf == ':');
}

canonical_original_code:
static int matching_game_name(char *pBuf, char *name)
{
 while (*name)
 {
  if (*name++ != *pBuf++) return 0;
 }
 return (*pBuf == ':');
}

variable_types:
name
char *


decompiled_code:
void hs_free()
{
void *v0; // rbx
void *v1; // rdi

v0 = ptr;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 3);
free(v1);
}
ptr = 0LL;
}

canonical_decompiled_code:
void func3()
{
void *v0; // rbx
void *v1; // rdi

v0 = ptr;
while ( v0 )
{
v1 = v0;
v0 = (void *)*((_QWORD *)v0 + 3);
free(v1);
}
ptr = 0LL;
}

original_code:
static void hs_free (void)
{
 struct mem_range *mem_range = state.mem_range;
 while (mem_range)
 {
  struct mem_range *next = mem_range->next;
  free(mem_range);
  mem_range = next;
 }
 state.mem_range = ((void *)0);
}

canonical_original_code:
static void hs_free()
{
 struct mem_range *mem_range = state.mem_range;
 while (mem_range)
 {
  struct mem_range *next = mem_range->next;
  free(mem_range);
  mem_range = next;
 }
 state.mem_range = ((void *)0);
}

variable_types: struct mem_range { unsigned int cpu; struct mem_range *next; } *


decompiled_code:
__int64 __fastcall computer_writemem_byte(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // er12
int v5; // eax
__int64 result; // rax

v4 = cpu_getactivecpu();
memorycontextswap(a1);
v5 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 80LL * (int)a1);
BYTE1(v5) = 0;
result = cpuintf[36 * v5 + 28](a2, a3);
if ( v4 != a1 )
result = memorycontextswap(v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // er12
int v5; // eax
__int64 result; // rax

v4 = cpu_getactivecpu();
memorycontextswap(a1);
v5 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 80LL * (int)a1);
BYTE1(v5) = 0;
result = cpuintf[36 * v5 + 28](a2, a3);
if ( v4 != a1 )
result = memorycontextswap(v4);
return result;
}

original_code:
void computer_writemem_byte(int cpu, int addr, int value)
{
    int oldcpu = cpu_getactivecpu();
    memorycontextswap(cpu);
    ((*cpuintf[Machine->drv->cpu[cpu].cpu_type & ~0xff00]. memory_write)(addr,value));
    if (oldcpu != cpu)
  memorycontextswap(oldcpu);
}

variable_types: cpu int

variable_types: addr int

variable_types: value int

variable_types: oldcpu int