decompiled_code:
__int64 __fastcall naughtyb_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
int v3; // ebp
int v4; // er12
__int64 v5; // r12
__int64 v6; // rbp
int v7; // er12
int v9[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 % 64;
v4 = v1 / 64;
}
else
{
v3 = (v1 - 1792) % 4 + 64;
v7 = v1 - 1789;
if ( v1 - 1792 >= 0 )
v7 = v1 - 1792;
v4 = v7 >> 2;
}
v5 = (unsigned int)(8 * v4);
v6 = (unsigned int)(8 * v3);
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);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294966768LL, 0LL, &leftvisiblearea, 0LL, 0LL);
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294967056LL, 0LL, &rightvisiblearea, 0LL, 0LL);
v9[0] = 16 - (unsigned __int8)*naughtyb_scrollreg;
return copyscrollbitmap(a1, tmpbitmap, 1LL, v9, 0LL, 0LL, &scrollvisiblearea, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
int v3; // ebp
int v4; // er12
__int64 v5; // r12
__int64 v6; // rbp
int v7; // er12
int v9[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 % 64;
v4 = v1 / 64;
}
else
{
v3 = (v1 - 1792) % 4 + 64;
v7 = v1 - 1789;
if ( v1 - 1792 >= 0 )
v7 = v1 - 1792;
v4 = v7 >> 2;
}
v5 = (unsigned int)(8 * v4);
v6 = (unsigned int)(8 * v3);
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);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294966768LL, 0LL, &leftvisiblearea, 0LL, 0LL);
copybitmap(a1, tmpbitmap, 0LL, 0LL, 4294967056LL, 0LL, &rightvisiblearea, 0LL, 0LL);
v9[0] = 16 - (unsigned __int8)*naughtyb_scrollreg;
return copyscrollbitmap(a1, tmpbitmap, 1LL, v9, 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 func7()
{
__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();
}

return_type: int


decompiled_code:
__int64 __fastcall rockrage_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r9
__int64 result; // rax
__int64 v6; // rdx

v4 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL));
if ( (int)result > 1 )
{
v6 = 0LL;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 824) + 688LL) + 16LL) + (int)v6)) = *(_BYTE *)(a3 + v6) & 0xF;
*(_WORD *)(a2
+ 2LL
* ((int)v6
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL)
+ *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL)
/ 2)) = (*(_BYTE *)(a3 + v6 + 256) & 0xF) + 16;
v4 = Machine;
++v6;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL)
/ 2);
}
while ( (int)result > (int)v6 );
}
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:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

return_type: void


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

result = rockrage_vreg ^ (unsigned int)a2;
if ( (((unsigned __int8)rockrage_vreg ^ (unsigned __int8)a2) & 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 = rockrage_vreg ^ (unsigned int)a2;
if ( (((unsigned __int8)rockrage_vreg ^ (unsigned __int8)a2) & 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;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

layer_colorbase[0] = 0;
dword_85C = 16;
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; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_85C = 16;
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 );
}

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


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

return_type: unsigned int


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

v0 = K007342_is_INT_enabled();
result = 1LL;
if ( !v0 )
result = ignore_interrupt();
return result;
}

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

v0 = K007342_is_INT_enabled();
result = 1LL;
if ( !v0 )
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) + (int)((((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) + (int)((((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()
{
_BOOL4 v0; // edx

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

canonical_decompiled_code:
_BOOL8 func8()
{
_BOOL4 v0; // edx

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

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; // rbp
__int64 i; // rbx
__int64 result; // rax

v0 = memory_region(145LL);
for ( i = 0LL; i != 64; ++i )
result = palette_change_color(
(unsigned int)i,
32 * (*(_BYTE *)(v0 + i) & 7u),
(unsigned __int8)(4 * *(_BYTE *)(v0 + i)) & 0xE0,
(unsigned __int8)(*(_BYTE *)(v0 + i) >> 6) << 6);
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 result; // rax

v0 = memory_region(145LL);
for ( i = 0LL; i != 64; ++i )
result = palette_change_color(
(unsigned int)i,
32 * (*(_BYTE *)(v0 + i) & 7u),
(unsigned __int8)(4 * *(_BYTE *)(v0 + i)) & 0xE0,
(unsigned __int8)(*(_BYTE *)(v0 + i) >> 6) << 6);
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)
{
int v1; // er15
__int64 i; // rbp
unsigned __int8 v3; // bp
char *j; // r14
unsigned int v5; // er13
__int64 v6; // rsi
__int64 l; // rcx
__int64 v8; // rsi
__int64 k; // r10
__int64 result; // rax
unsigned __int8 v11; // dl
unsigned __int8 v12; // dl
int v13; // [rsp+8h] [rbp-180h]
unsigned int v14; // [rsp+8h] [rbp-180h]
int v15[12]; // [rsp+20h] [rbp-168h] BYREF
char dest[4]; // [rsp+50h] [rbp-138h] BYREF

v13 = battlane_scrolly + ((battlane_video_ctrl & 1) << 8);
v1 = battlane_scrollx + ((battlane_cpu_control & 1) << 8);
battlane_build_palette();
palette_recalc();
for ( i = 0LL; i != 1024; ++i )
drawgfx(
bkgnd_bitmap,
*(_QWORD *)(Machine + 8LL * (byte_12C0[i] & 1) + 520),
byte_12C0[i - 1024],
(byte_12C0[i] >> 1) & 7,
flipscreen == 0);
v15[0] = -v1;
*(_DWORD *)dest = -v13;
copyscrollbitmap(a1, bkgnd_bitmap, 1LL, dest, 1LL, v15, Machine + 776LL, 0LL, 0LL);
dest[0] = 0;
v3 = byte_16C1;
v14 = (unsigned __int8)byte_16C3
+ ((4 * (unsigned __int8)byte_16C1) & 0x200)
+ ((8 * (unsigned __int8)byte_16C1) & 0x100);
for ( j = (char *)&battlane_spriteram; ; j += 4 )
{
if ( (v3 & 1) != 0 )
{
v5 = v3 & 4;
if ( !flipscreen )
v5 = v5 == 0;
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v14, 0LL, v5);
if ( (v3 & 0x10) != 0 )
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v14 + 1, 0LL, v5);
}
if ( j == (char *)&unk_17BC )
break;
v3 = j[5];
v14 = ((8 * v3) & 0x100) + (unsigned __int8)j[7] + ((4 * v3) & 0x200);
if ( (int)((_DWORD)j + 4 - (unsigned int)&battlane_spriteram) > 160 )
{
sprintf((char *)v15, "%02x ", v3);
strcat(dest, (const char *)v15);
}
}
if ( flipscreen )
{
v8 = screen_bitmap;
for ( k = 2040LL; k != -8; k -= 8LL )
{
for ( result = 0LL; result != 256; ++result )
{
v11 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v8 + 24) + 2040 - k) + result);
if ( v11 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + k) + 255 - result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * v11);
}
}
}
else
{
v6 = screen_bitmap;
for ( l = 0LL; l != 2048; l += 8LL )
{
for ( result = 0LL; result != 256; ++result )
{
v12 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v6 + 24) + l) + result);
if ( v12 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + l) + result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * v12);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // er15
__int64 i; // rbp
unsigned __int8 v3; // bp
char *j; // r14
unsigned int v5; // er13
__int64 v6; // rsi
__int64 l; // rcx
__int64 v8; // rsi
__int64 k; // r10
__int64 result; // rax
unsigned __int8 v11; // dl
unsigned __int8 v12; // dl
int v13; // [rsp+8h] [rbp-180h]
unsigned int v14; // [rsp+8h] [rbp-180h]
int v15[12]; // [rsp+20h] [rbp-168h] BYREF
char dest[4]; // [rsp+50h] [rbp-138h] BYREF

v13 = battlane_scrolly + ((battlane_video_ctrl & 1) << 8);
v1 = battlane_scrollx + ((battlane_cpu_control & 1) << 8);
func13();
palette_recalc();
for ( i = 0LL; i != 1024; ++i )
drawgfx(
bkgnd_bitmap,
*(_QWORD *)(Machine + 8LL * (byte_12C0[i] & 1) + 520),
byte_12C0[i - 1024],
(byte_12C0[i] >> 1) & 7,
flipscreen == 0);
v15[0] = -v1;
*(_DWORD *)dest = -v13;
copyscrollbitmap(a1, bkgnd_bitmap, 1LL, dest, 1LL, v15, Machine + 776LL, 0LL, 0LL);
dest[0] = 0;
v3 = byte_16C1;
v14 = (unsigned __int8)byte_16C3
+ ((4 * (unsigned __int8)byte_16C1) & 0x200)
+ ((8 * (unsigned __int8)byte_16C1) & 0x100);
for ( j = (char *)&battlane_spriteram; ; j += 4 )
{
if ( (v3 & 1) != 0 )
{
v5 = v3 & 4;
if ( !flipscreen )
v5 = v5 == 0;
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v14, 0LL, v5);
if ( (v3 & 0x10) != 0 )
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v14 + 1, 0LL, v5);
}
if ( j == (char *)&unk_17BC )
break;
v3 = j[5];
v14 = ((8 * v3) & 0x100) + (unsigned __int8)j[7] + ((4 * v3) & 0x200);
if ( (int)((_DWORD)j + 4 - (unsigned int)&battlane_spriteram) > 160 )
{
sprintf((char *)v15, "%02x ", v3);
strcat(dest, (const char *)v15);
}
}
if ( flipscreen )
{
v8 = screen_bitmap;
for ( k = 2040LL; k != -8; k -= 8LL )
{
for ( result = 0LL; result != 256; ++result )
{
v11 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v8 + 24) + 2040 - k) + result);
if ( v11 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + k) + 255 - result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * v11);
}
}
}
else
{
v6 = screen_bitmap;
for ( l = 0LL; l != 2048; l += 8LL )
{
for ( result = 0LL; result != 256; ++result )
{
v12 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(v6 + 24) + l) + result);
if ( v12 )
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 24) + l) + result) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * v12);
}
}
}
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: scrollx int

variable_types: scrolly int

variable_types: x int

variable_types: y int

variable_types: offs int

variable_types: sx int

variable_types: sy 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()
{
int v0; // edx
__int64 result; // rax

v0 = cpu_getiloops();
result = 2LL;
if ( !v0 )
{
if ( (battlane_cpu_control & 8) != 0 )
{
result = ignore_interrupt();
}
else
{
cpu_set_nmi_line(1LL, 3LL);
result = 4LL;
}
}
return result;
}

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

v0 = cpu_getiloops();
result = 2LL;
if ( !v0 )
{
if ( (battlane_cpu_control & 8) != 0 )
{
result = ignore_interrupt();
}
else
{
cpu_set_nmi_line(1LL, 3LL);
result = 4LL;
}
}
return result;
}

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:
__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; // edx
int v3; // eax
char v4; // al

v1 = *a1;
v2 = 0;
if ( !*a1 )
return v2;
while ( 1 )
{
v4 = *v1++;
if ( (unsigned __int8)(v4 - 48) <= 9u )
{
v3 = v4 - 48;
goto LABEL_4;
}
if ( (unsigned __int8)(v4 - 97) <= 5u )
{
v3 = v4 - 87;
goto LABEL_4;
}
if ( (unsigned __int8)(v4 - 65) > 5u )
break;
v3 = v4 - 55;
LABEL_4:
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; // edx
int v3; // eax
char v4; // al

v1 = *a1;
v2 = 0;
if ( !*a1 )
return v2;
while ( 1 )
{
v4 = *v1++;
if ( (unsigned __int8)(v4 - 48) <= 9u )
{
v3 = v4 - 48;
goto LABEL_4;
}
if ( (unsigned __int8)(v4 - 97) <= 5u )
{
v3 = v4 - 87;
goto LABEL_4;
}
if ( (unsigned __int8)(v4 - 65) > 5u )
break;
v3 = v4 - 55;
LABEL_4:
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(_BYTE *a1, char *a2)
{
char v2; // al

while ( 1 )
{
v2 = *a2;
if ( !*a2 )
break;
++a2;
if ( *a1++ != v2 )
return 0LL;
}
return *a1 == 58;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_BYTE *a1, char *a2)
{
char v2; // al

while ( 1 )
{
v2 = *a2;
if ( !*a2 )
break;
++a2;
if ( *a1++ != v2 )
return 0LL;
}
return *a1 == 58;
}

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


decompiled_code:
__int64 __fastcall copy_to_memory(unsigned int a1, int a2, unsigned __int8 *a3, int a4)
{
__int64 v4; // r13
unsigned __int8 *v5; // rbx
int v6; // ebp
__int64 result; // rax

if ( a4 > 0 )
{
v4 = (__int64)&a3[a4 - 1 + 1];
v5 = a3;
v6 = a2 - (_DWORD)a3;
do
{
result = computer_writemem_byte(a1, v6 + (int)v5, *v5);
++v5;
}
while ( v5 != (unsigned __int8 *)v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, int a2, unsigned __int8 *a3, int a4)
{
__int64 v4; // r13
unsigned __int8 *v5; // rbx
int v6; // ebp
__int64 result; // rax

if ( a4 > 0 )
{
v4 = (__int64)&a3[a4 - 1 + 1];
v5 = a3;
v6 = a2 - (_DWORD)a3;
do
{
result = func4(a1, v6 + (int)v5, *v5);
++v5;
}
while ( v5 != (unsigned __int8 *)v4 );
}
return result;
}

original_code:
static void copy_to_memory (int cpu, int addr, const UINT8 *source, int num_bytes)
{
 int i;
 for (i=0; i<num_bytes; i++)
 {
  computer_writemem_byte (cpu, addr+i, source[i]);
 }
}

canonical_original_code:
static void copy_to_memory(int cpu, int addr, unsigned char *source, int num_bytes)
{
 int i;
 for (i=0; i<num_bytes; i++)
 {
  computer_writemem_byte (cpu, addr+i, source[i]);
 }
}

variable_types:
source
unsigned char *

variable_types: i int


decompiled_code:
__int64 hs_load()
{
__int64 result; // rax
__int64 v1; // r13
void *i; // rbx
unsigned int v3; // er12
unsigned __int8 *v4; // rax
unsigned __int8 *v5; // rbp

result = osd_fopen(*(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL), 0LL, 4LL, 0LL);
state = 1;
if ( result )
{
v1 = result;
for ( i = ptr; i; i = (void *)*((_QWORD *)i + 3) )
{
v3 = *((_DWORD *)i + 2);
v4 = (unsigned __int8 *)malloc(v3);
v5 = v4;
if ( v4 )
{
osd_fread(v1, v4, v3);
copy_to_memory(*(_DWORD *)i, *((_DWORD *)i + 1), v5, *((_DWORD *)i + 2));
free(v5);
}
}
result = osd_fclose(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // r13
void *i; // rbx
unsigned int v3; // er12
unsigned __int8 *v4; // rax
unsigned __int8 *v5; // rbp

result = osd_fopen(*(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL), 0LL, 4LL, 0LL);
state = 1;
if ( result )
{
v1 = result;
for ( i = ptr; i; i = (void *)*((_QWORD *)i + 3) )
{
v3 = *((_DWORD *)i + 2);
v4 = (unsigned __int8 *)malloc(v3);
v5 = v4;
if ( v4 )
{
osd_fread(v1, v4, v3);
func5(*(_DWORD *)i, *((_DWORD *)i + 1), v5, *((_DWORD *)i + 2));
free(v5);
}
}
result = osd_fclose(v1);
}
return result;
}

original_code:
static void hs_load (void)
{
 void *f = osd_fopen (Machine->gamedrv->name, 0, OSD_FILETYPE_HIGHSCORE, 0);
 state.hiscores_have_been_loaded = 1;
 ;
 if (f)
 {
  struct mem_range *mem_range = state.mem_range;
  ;
  while (mem_range)
  {
   UINT8 *data = (UINT8*)malloc(mem_range->num_bytes);
   if (data)
   {
    osd_fread (f, data, mem_range->num_bytes);
    copy_to_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
    free(data);
   }
   mem_range = mem_range->next;
  }
  osd_fclose (f);
 }
}

canonical_original_code:
static void hs_load()
{
 void *f = osd_fopen (Machine->gamedrv->name, 0, OSD_FILETYPE_HIGHSCORE, 0);
 state.hiscores_have_been_loaded = 1;
 ;
 if (f)
 {
  struct mem_range *mem_range = state.mem_range;
  ;
  while (mem_range)
  {
   unsigned char *data = (UINT8*)malloc(mem_range->num_bytes);
   if (data)
   {
    osd_fread (f, data, mem_range->num_bytes);
    copy_to_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
    free(data);
   }
   mem_range = mem_range->next;
  }
  osd_fclose (f);
 }
}

variable_types:
f
void *

variable_types:
data
unsigned char *

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


decompiled_code:
__int64 __fastcall computer_readmem_byte(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebp
int v3; // eax
unsigned int v4; // er12

v2 = cpu_getactivecpu();
memorycontextswap(a1);
v3 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 80LL * (int)a1);
BYTE1(v3) = 0;
v4 = ((__int64 (__fastcall *)(_QWORD))cpuintf[36 * v3 + 27])(a2);
if ( v2 != a1 )
memorycontextswap(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebp
int v3; // eax
unsigned int v4; // er12

v2 = cpu_getactivecpu();
memorycontextswap(a1);
v3 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 80LL * (int)a1);
BYTE1(v3) = 0;
v4 = ((__int64 (__fastcall *)(_QWORD))cpuintf[36 * v3 + 27])(a2);
if ( v2 != a1 )
memorycontextswap(v2);
return v4;
}

original_code:
int computer_readmem_byte(int cpu, int addr)
{
    int oldcpu = cpu_getactivecpu(), result;
    memorycontextswap(cpu);
    result = ((*cpuintf[Machine->drv->cpu[cpu].cpu_type & ~0xff00]. memory_read)(addr));
    if (oldcpu != cpu)
     memorycontextswap(oldcpu);
    return result;
}

canonical_original_code:
int computer_readmem_byte(int cpu, int addr)
{
    int oldcpu = cpu_getactivecpu(); int result;
    memorycontextswap(cpu);
    result = ((*cpuintf[Machine->drv->cpu[cpu].cpu_type & ~0xff00]. memory_read)(addr));
    if (oldcpu != cpu)
     memorycontextswap(oldcpu);
    return result;
}

variable_types: result int


decompiled_code:
__int64 safe_to_load()
{
unsigned int *v0; // rbx

v0 = (unsigned int *)ptr;
if ( !ptr )
return 1LL;
while ( 1 )
{
if ( (unsigned int)computer_readmem_byte(*v0, v0[1]) != v0[3] )
return 0LL;
if ( (unsigned int)computer_readmem_byte(*v0, v0[1] + v0[2] - 1) != v0[4] )
break;
v0 = (unsigned int *)*((_QWORD *)v0 + 3);
if ( !v0 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int *v0; // rbx

v0 = (unsigned int *)ptr;
if ( !ptr )
return 1LL;
while ( 1 )
{
if ( (unsigned int)func7(*v0, v0[1]) != v0[3] )
return 0LL;
if ( (unsigned int)func7(*v0, v0[1] + v0[2] - 1) != v0[4] )
break;
v0 = (unsigned int *)*((_QWORD *)v0 + 3);
if ( !v0 )
return 1LL;
}
return 0LL;
}

original_code:
static int safe_to_load (void)
{
 struct mem_range *mem_range = (struct mem_range *)state.mem_range;
 while (mem_range)
 {
  if (computer_readmem_byte (mem_range->cpu, mem_range->addr) !=
   mem_range->start_value)
  {
   return 0;
  }
  if (computer_readmem_byte (mem_range->cpu, mem_range->addr + mem_range->num_bytes - 1) !=
   mem_range->end_value)
  {
   return 0;
  }
  mem_range = mem_range->next;
 }
 return 1;
}

canonical_original_code:
static int safe_to_load()
{
 struct mem_range *mem_range = (struct mem_range *)state.mem_range;
 while (mem_range)
 {
  if (computer_readmem_byte (mem_range->cpu, mem_range->addr) !=
   mem_range->start_value)
  {
   return 0;
  }
  if (computer_readmem_byte (mem_range->cpu, mem_range->addr + mem_range->num_bytes - 1) !=
   mem_range->end_value)
  {
   return 0;
  }
  mem_range = mem_range->next;
 }
 return 1;
}


decompiled_code:
void __fastcall copy_from_memory(unsigned int a1, int a2, _BYTE *a3, int a4)
{
__int64 v4; // r13
_BYTE *v5; // rbx
int v6; // ebp

if ( a4 > 0 )
{
v4 = (__int64)&a3[a4 - 1 + 1];
v5 = a3;
v6 = a2 - (_DWORD)a3;
do
{
*v5 = computer_readmem_byte(a1, v6 + (int)v5);
++v5;
}
while ( v5 != (_BYTE *)v4 );
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, int a2, _BYTE *a3, int a4)
{
__int64 v4; // r13
_BYTE *v5; // rbx
int v6; // ebp

if ( a4 > 0 )
{
v4 = (__int64)&a3[a4 - 1 + 1];
v5 = a3;
v6 = a2 - (_DWORD)a3;
do
{
*v5 = func7(a1, v6 + (int)v5);
++v5;
}
while ( v5 != (_BYTE *)v4 );
}
}

original_code:
static void copy_from_memory (int cpu, int addr, UINT8 *dest, int num_bytes)
{
 int i;
 for (i=0; i<num_bytes; i++)
 {
  dest[i] = computer_readmem_byte (cpu, addr+i);
 }
}

canonical_original_code:
static void copy_from_memory(int cpu, int addr, unsigned char *dest, int num_bytes)
{
 int i;
 for (i=0; i<num_bytes; i++)
 {
  dest[i] = computer_readmem_byte (cpu, addr+i);
 }
}

variable_types:
dest
unsigned char *


decompiled_code:
__int64 hs_save()
{
__int64 result; // rax
__int64 v1; // r13
unsigned int *v2; // rbx
unsigned int v3; // er12
_BYTE *v4; // rax
_BYTE *v5; // rbp

result = osd_fopen(*(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL), 0LL, 4LL, 1LL);
if ( result )
{
v1 = result;
v2 = (unsigned int *)ptr;
if ( ptr )
{
do
{
v3 = v2[2];
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
copy_from_memory(*v2, v2[1], v4, v3);
osd_fwrite(v1, v5, v2[2]);
}
v2 = (unsigned int *)*((_QWORD *)v2 + 3);
}
while ( v2 );
}
result = osd_fclose(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
__int64 v1; // r13
unsigned int *v2; // rbx
unsigned int v3; // er12
_BYTE *v4; // rax
_BYTE *v5; // rbp

result = osd_fopen(*(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL), 0LL, 4LL, 1LL);
if ( result )
{
v1 = result;
v2 = (unsigned int *)ptr;
if ( ptr )
{
do
{
v3 = v2[2];
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
func9(*v2, v2[1], v4, v3);
osd_fwrite(v1, v5, v2[2]);
}
v2 = (unsigned int *)*((_QWORD *)v2 + 3);
}
while ( v2 );
}
result = osd_fclose(v1);
}
return result;
}

original_code:
static void hs_save (void)
{
 void *f = osd_fopen (Machine->gamedrv->name, 0, OSD_FILETYPE_HIGHSCORE, 1);
 ;
 if (f)
 {
  struct mem_range *mem_range = state.mem_range;
  ;
  while (mem_range)
  {
   UINT8 *data = (UINT8*)malloc(mem_range->num_bytes);
   if (data)
   {
    copy_from_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
    osd_fwrite(f, data, mem_range->num_bytes);
   }
   mem_range = mem_range->next;
  }
  osd_fclose(f);
 }
}

canonical_original_code:
static void hs_save()
{
 void *f = osd_fopen (Machine->gamedrv->name, 0, OSD_FILETYPE_HIGHSCORE, 1);
 ;
 if (f)
 {
  struct mem_range *mem_range = state.mem_range;
  ;
  while (mem_range)
  {
   unsigned char *data = (UINT8*)malloc(mem_range->num_bytes);
   if (data)
   {
    copy_from_memory (mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
    osd_fwrite(f, data, mem_range->num_bytes);
   }
   mem_range = mem_range->next;
  }
  osd_fclose(f);
 }
}


decompiled_code:
__int64 __fastcall hs_open(char *a1)
{
__int64 result; // rax
__int64 v2; // r12
int v3; // ebp
_DWORD *v4; // rbp
_QWORD *i; // rax
char *v6; // [rsp+8h] [rbp-60h] BYREF
char v7[88]; // [rsp+10h] [rbp-58h] BYREF

result = osd_fopen(0LL, db_filename, 5LL, 0LL);
v2 = result;
ptr = 0LL;
v3 = 0;
if ( result )
{
while ( osd_fgets(v7, 48LL, v2) )
{
if ( v3 )
{
if ( is_mem_range(v7) )
{
v6 = v7;
v4 = malloc(0x20uLL);
if ( !v4 )
{
hs_free();
break;
}
*v4 = hexstr2num(&v6);
v4[1] = hexstr2num(&v6);
v4[2] = hexstr2num(&v6);
v4[3] = hexstr2num(&v6);
v4[4] = hexstr2num(&v6);
*((_QWORD *)v4 + 3) = 0LL;
for ( i = ptr; i; i = (_QWORD *)i[3] )
{
if ( !i[3] )
{
i[3] = v4;
goto LABEL_14;
}
}
ptr = v4;
LABEL_14:
v3 = 2;
}
else if ( v3 == 2 )
{
break;
}
}
else
{
v3 = matching_game_name(v7, a1);
}
}
result = osd_fclose(v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
__int64 result; // rax
__int64 v2; // r12
int v3; // ebp
_DWORD *v4; // rbp
_QWORD *i; // rax
char *v6; // [rsp+8h] [rbp-60h] BYREF
char v7[88]; // [rsp+10h] [rbp-58h] BYREF

result = osd_fopen(0LL, db_filename, 5LL, 0LL);
v2 = result;
ptr = 0LL;
v3 = 0;
if ( result )
{
while ( osd_fgets(v7, 48LL, v2) )
{
if ( v3 )
{
if ( func1(v7) )
{
v6 = v7;
v4 = malloc(0x20uLL);
if ( !v4 )
{
func3();
break;
}
*v4 = func0(&v6);
v4[1] = func0(&v6);
v4[2] = func0(&v6);
v4[3] = func0(&v6);
v4[4] = func0(&v6);
*((_QWORD *)v4 + 3) = 0LL;
for ( i = ptr; i; i = (_QWORD *)i[3] )
{
if ( !i[3] )
{
i[3] = v4;
goto LABEL_14;
}
}
ptr = v4;
LABEL_14:
v3 = 2;
}
else if ( v3 == 2 )
{
break;
}
}
else
{
v3 = func2(v7, a1);
}
}
result = osd_fclose(v2);
}
return result;
}

original_code:
void hs_open (const char *name)
{
 void *f = osd_fopen (((void *)0), db_filename, OSD_FILETYPE_HIGHSCORE_DB, 0);
 state.mem_range = ((void *)0);
 ;
 if (f)
 {
  char buffer[48];
  enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode;
  mode = FIND_NAME;
  while (osd_fgets (buffer, 48, f))
  {
   if (mode==FIND_NAME)
   {
    if (matching_game_name (buffer, name))
    {
     mode = FIND_DATA;
     ;
    }
   }
   else if (is_mem_range (buffer))
   {
    const char *pBuf = buffer;
    struct mem_range *mem_range = (struct mem_range*)malloc(sizeof(struct mem_range));
    if (mem_range)
    {
     mem_range->cpu = hexstr2num (&pBuf);
     mem_range->addr = hexstr2num (&pBuf);
     mem_range->num_bytes = hexstr2num (&pBuf);
     mem_range->start_value = hexstr2num (&pBuf);
     mem_range->end_value = hexstr2num (&pBuf);
     mem_range->next = ((void *)0);
     {
      struct mem_range *last = state.mem_range;
      while (last && last->next) last = last->next;
      if (last == ((void *)0))
      {
       state.mem_range = mem_range;
      }
      else
      {
       last->next = mem_range;
      }
     }
     mode = FETCH_DATA;
    }
    else
    {
     hs_free();
     break;
    }
   }
   else
   {
    if (mode == FETCH_DATA) break;
   }
  }
  osd_fclose (f);
 }
}

canonical_original_code:
void hs_open(char *name)
{
 void *f = osd_fopen (((void *)0), db_filename, OSD_FILETYPE_HIGHSCORE_DB, 0);
 state.mem_range = ((void *)0);
 ;
 if (f)
 {
  char buffer[48];
  enum { FIND_NAME=0, FIND_DATA=1, FETCH_DATA=2 } mode;
  mode = FIND_NAME;
  while (osd_fgets (buffer, 48, f))
  {
   if (mode==FIND_NAME)
   {
    if (matching_game_name (buffer, name))
    {
     mode = FIND_DATA;
     ;
    }
   }
   else if (is_mem_range (buffer))
   {
    char *pBuf = buffer;
    struct mem_range *mem_range = (struct mem_range*)malloc(sizeof(struct mem_range));
    if (mem_range)
    {
     mem_range->cpu = hexstr2num (&pBuf);
     mem_range->addr = hexstr2num (&pBuf);
     mem_range->num_bytes = hexstr2num (&pBuf);
     mem_range->start_value = hexstr2num (&pBuf);
     mem_range->end_value = hexstr2num (&pBuf);
     mem_range->next = ((void *)0);
     {
      struct mem_range *last = state.mem_range;
      while (last && last->next) last = last->next;
      if (last == ((void *)0))
      {
       state.mem_range = mem_range;
      }
      else
      {
       last->next = mem_range;
      }
     }
     mode = FETCH_DATA;
    }
    else
    {
     hs_free();
     break;
    }
   }
   else
   {
    if (mode == FETCH_DATA) break;
   }
  }
  osd_fclose (f);
 }
}

variable_types:
buffer
char [48]


decompiled_code:
__int64 hs_init()
{
void *v0; // rbx
__int64 result; // rax

v0 = ptr;
for ( state = 0; v0; v0 = (void *)*((_QWORD *)v0 + 3) )
{
computer_writemem_byte(*(_DWORD *)v0, *((_DWORD *)v0 + 1), ~*((_DWORD *)v0 + 3));
result = computer_writemem_byte(*(_DWORD *)v0, *((_DWORD *)v0 + 1) + *((_DWORD *)v0 + 2) - 1, ~*((_DWORD *)v0 + 4));
}
return result;
}

original_code:
void hs_init (void)
{
 struct mem_range *mem_range = state.mem_range;
 state.hiscores_have_been_loaded = 0;
 while (mem_range)
 {
  computer_writemem_byte(
   mem_range->cpu,
   mem_range->addr,
   ~mem_range->start_value
  );
  computer_writemem_byte(
   mem_range->cpu,
   mem_range->addr + mem_range->num_bytes-1,
   ~mem_range->end_value
  );
  mem_range = mem_range->next;
 }
}

canonical_original_code:
void hs_init()
{
 struct mem_range *mem_range = state.mem_range;
 state.hiscores_have_been_loaded = 0;
 while (mem_range)
 {
  computer_writemem_byte(
   mem_range->cpu,
   mem_range->addr,
   ~mem_range->start_value
  );
  computer_writemem_byte(
   mem_range->cpu,
   mem_range->addr + mem_range->num_bytes-1,
   ~mem_range->end_value
  );
  mem_range = mem_range->next;
 }
}


decompiled_code:
void hs_update()
{
if ( ptr && !state )
{
if ( (unsigned int)safe_to_load() )
hs_load();
}
}

canonical_decompiled_code:
void func13()
{
if ( ptr && !state )
{
if ( (unsigned int)func8() )
func6();
}
}

original_code:
void hs_update (void)
{
 if (state.mem_range)
 {
  if (!state.hiscores_have_been_loaded)
  {
   if (safe_to_load()) hs_load();
  }
 }
}

canonical_original_code:
void hs_update()
{
 if (state.mem_range)
 {
  if (!state.hiscores_have_been_loaded)
  {
   if (safe_to_load()) hs_load();
  }
 }
}


decompiled_code:
void hs_close()
{
if ( state )
hs_save();
hs_free();
}

canonical_decompiled_code:
void func14()
{
if ( state )
func10();
func3();
}

original_code:
void hs_close (void)
{
 if (state.hiscores_have_been_loaded) hs_save();
 hs_free();
}

canonical_original_code:
void hs_close()
{
 if (state.hiscores_have_been_loaded) hs_save();
 hs_free();
}


original_code:
int RF5C68_sh_start( const struct MachineSound *msound )
{
 int i;
 int rate = Machine->sample_rate;
 struct RF5C68interface *inintf = (struct RF5C68interface *)msound->sound_interface;
 if (Machine->sample_rate == 0) return 0;
 if(pcmbuf==((void *)0)) pcmbuf=(unsigned char *)malloc(0x10000);
 if(pcmbuf==((void *)0)) return 1;
 intf = inintf;
 buffer_len = rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 rpcm.clock = intf->clock;
 for( i = 0; i < (8); i++ )
 {
  rpcm.env[i] = 0;
  rpcm.pan[i] = 0;
  rpcm.start[i] = 0;
  rpcm.step[i] = 0;
  rpcm.flag[i] = 0;
 }
 for( i = 0; i < 0x10; i++ ) wreg[i] = 0;
 reg_port = 0;
 {
  char buf[LR_PAN][40];
  const char *name[LR_PAN];
  int vol[2];
  name[0] = buf[0];
  name[1] = buf[1];
  sprintf( buf[0], "%s Left", sound_name(msound) );
  sprintf( buf[1], "%s Right", sound_name(msound) );
  vol[0] = (1<<8) | (intf->volume&0xff);
  vol[1] = (2<<8) | (intf->volume&0xff);
  stream = stream_init_multi( RF_LR_PAN, name, vol, rate, 0, RF5C68Update );
  if(stream == -1) return 1;
 }
 return 0;
}

canonical_original_code:
int RF5C68_sh_start(struct MachineSound *msound)
{
 int i;
 int rate = Machine->sample_rate;
 struct RF5C68interface *inintf = (struct RF5C68interface *)msound->sound_interface;
 if (Machine->sample_rate == 0) return 0;
 if(pcmbuf==((void *)0)) pcmbuf=(unsigned char *)malloc(0x10000);
 if(pcmbuf==((void *)0)) return 1;
 intf = inintf;
 buffer_len = rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 rpcm.clock = intf->clock;
 for( i = 0; i < (8); i++ )
 {
  rpcm.env[i] = 0;
  rpcm.pan[i] = 0;
  rpcm.start[i] = 0;
  rpcm.step[i] = 0;
  rpcm.flag[i] = 0;
 }
 for( i = 0; i < 0x10; i++ ) wreg[i] = 0;
 reg_port = 0;
 {
  char buf[-1][40];
  char *name[-1];
  int vol[2];
  name[0] = buf[0];
  name[1] = buf[1];
  sprintf( buf[0], "%s Left", sound_name(msound) );
  sprintf( buf[1], "%s Right", sound_name(msound) );
  vol[0] = (1<<8) | (intf->volume&0xff);
  vol[1] = (2<<8) | (intf->volume&0xff);
  stream = stream_init_multi( RF_LR_PAN, name, vol, rate, 0, RF5C68Update );
  if(stream == -1) return 1;
 }
 return 0;
}

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

variable_types: rate int

variable_types: struct RF5C68interface { int clock; int volume; } *

variable_types:
name
char *[-1]

variable_types:
vol
int [2]


decompiled_code:
void RF5C68_sh_stop()
{
if ( pcmbuf )
free(pcmbuf);
pcmbuf = 0LL;
}

canonical_decompiled_code:
void func3()
{
if ( pcmbuf )
free(pcmbuf);
pcmbuf = 0LL;
}

original_code:
void RF5C68_sh_stop( void )
{
 if(pcmbuf!=((void *)0)) free(pcmbuf);
 pcmbuf=((void *)0);
}

canonical_original_code:
void RF5C68_sh_stop()
{
 if(pcmbuf!=((void *)0)) free(pcmbuf);
 pcmbuf=((void *)0);
}


decompiled_code:
unsigned __int64 __fastcall RF5C68_reg_w(unsigned int a1, int a2)
{
unsigned __int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rsi
int i; // ecx
unsigned int v6; // edx

wreg[a1] = a2;
result = (unsigned __int8)byte_5C7;
if ( (byte_5C7 & 0x40) != 0 )
{
result = byte_5C7 & 7;
reg_port = byte_5C7 & 7;
}
switch ( a1 )
{
case 0u:
result = reg_port;
*((_BYTE *)&rpcm[1] + reg_port) = a2;
break;
case 1u:
result = reg_port;
*((_BYTE *)&rpcm[3] + reg_port) = a2;
break;
case 2u:
case 3u:
result = (unsigned __int64)rpcm;
rpcm[reg_port + 21] = (int)((double)rpcm[0]
/ 8000000.0
* ((float)((float)(unsigned __int16)word_5C2 * 0.00048828125)
* (28456.0
/ (float)emulation_rate))
* 32768.0);
break;
case 4u:
case 5u:
result = (unsigned __int16)word_5C4 << 15;
rpcm[reg_port + 29] = result;
break;
case 6u:
result = (unsigned __int8)byte_5C6 << 23;
v3 = reg_port;
rpcm[reg_port + 13] = result;
rpcm[v3 + 5] = result;
break;
case 7u:
result = (unsigned __int8)a2 & 0xC0;
if ( (_DWORD)result == 192 )
{
result = (unsigned __int64)rpcm;
v4 = a2 & 7;
rpcm[v4 + 37] = 0;
rpcm[v4 + 45] = 0;
rpcm[v4 + 53] |= 2u;
}
break;
case 8u:
result = (unsigned __int64)&unk_6D4;
for ( i = 0; i != 8; ++i )
{
if ( (a2 & (1 << i)) != 0 )
v6 = *(_DWORD *)result & 0xFFFFFFFE;
else
v6 = *(_DWORD *)result | 1;
*(_DWORD *)result = v6;
result += 4LL;
}
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned int a1, int a2)
{
unsigned __int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rsi
int i; // ecx
unsigned int v6; // edx

wreg[a1] = a2;
result = (unsigned __int8)byte_5C7;
if ( (byte_5C7 & 0x40) != 0 )
{
result = byte_5C7 & 7;
reg_port = byte_5C7 & 7;
}
switch ( a1 )
{
case 0u:
result = reg_port;
*((_BYTE *)&rpcm[1] + reg_port) = a2;
break;
case 1u:
result = reg_port;
*((_BYTE *)&rpcm[3] + reg_port) = a2;
break;
case 2u:
case 3u:
result = (unsigned __int64)rpcm;
rpcm[reg_port + 21] = (int)((double)rpcm[0]
/ 8000000.0
* ((float)((float)(unsigned __int16)word_5C2 * 0.00048828125)
* (28456.0
/ (float)emulation_rate))
* 32768.0);
break;
case 4u:
case 5u:
result = (unsigned __int16)word_5C4 << 15;
rpcm[reg_port + 29] = result;
break;
case 6u:
result = (unsigned __int8)byte_5C6 << 23;
v3 = reg_port;
rpcm[reg_port + 13] = result;
rpcm[v3 + 5] = result;
break;
case 7u:
result = (unsigned __int8)a2 & 0xC0;
if ( (_DWORD)result == 192 )
{
result = (unsigned __int64)rpcm;
v4 = a2 & 7;
rpcm[v4 + 37] = 0;
rpcm[v4 + 45] = 0;
rpcm[v4 + 53] |= 2u;
}
break;
case 8u:
result = (unsigned __int64)&unk_6D4;
for ( i = 0; i != 8; ++i )
{
if ( (a2 & (1 << i)) != 0 )
v6 = *(_DWORD *)result & 0xFFFFFFFE;
else
v6 = *(_DWORD *)result | 1;
*(_DWORD *)result = v6;
result += 4LL;
}
break;
default:
return result;
}
return result;
}

original_code:
void RF5C68_reg_w(offs_t offset,data_t data)
{
 int i;
 int val;
 wreg[offset] = data;
 if( (wreg[0x07]&0x40) ) reg_port = wreg[0x07]&0x07;
 switch( offset )
 {
  case 0x00:
   rpcm.env[reg_port] = data;
   break;
  case 0x01:
   rpcm.pan[reg_port] = data;
   break;
  case 0x02:
  case 0x03:
   val = (((((int)wreg[0x03])<<8)&0xff00) | (((int)wreg[0x02])&0x00ff));
   rpcm.step[reg_port] = (int)(
   (
   ( 28456.0 / (float)emulation_rate ) *
   ( val / (float)(0x0800) ) *
   (rpcm.clock / 8000000.0) *
   (1<<(11+4))
   )
   );
   break;
  case 0x04:
  case 0x05:
   rpcm.loop[reg_port] = (((((unsigned int)wreg[0x05])<<8)&0xff00)|(((unsigned int)wreg[0x04])&0x00ff))<<((11+4));
   break;
  case 0x06:
   rpcm.start[reg_port] = (((unsigned int)wreg[0x06])&0x00ff)<<((11+4) + 8);
   rpcm.addr[reg_port] = rpcm.start[reg_port];
   break;
  case 0x07:
   if( (data&0xc0) == 0xc0 )
   {
    i = data&0x07;
    rpcm.pcmx[0][i] = 0;
    rpcm.pcmx[1][i] = 0;
    rpcm.flag[i] |= (1<<1);
   }
   break;
  case 0x08:
   for( i = 0; i < (8); i++ )
   {
    if( !(data&(1<<i)) )
    {
     rpcm.flag[i] |= (1<<0);
    }
    else
    {
     rpcm.flag[i] &= ~((1<<0));
    }
   }
   break;
 }
}

canonical_original_code:
void RF5C68_reg_w(unsigned int offset, unsigned int data)
{
 int i;
 int val;
 wreg[offset] = data;
 if( (wreg[0x07]&0x40) ) reg_port = wreg[0x07]&0x07;
 switch( offset )
 {
  case 0x00:
   rpcm.env[reg_port] = data;
   break;
  case 0x01:
   rpcm.pan[reg_port] = data;
   break;
  case 0x02:
  case 0x03:
   val = (((((int)wreg[0x03])<<8)&0xff00) | (((int)wreg[0x02])&0x00ff));
   rpcm.step[reg_port] = (int)(
   (
   ( 28456.0 / (float)emulation_rate ) *
   ( val / (float)(0x0800) ) *
   (rpcm.clock / 8000000.0) *
   (1<<(11+4))
   )
   );
   break;
  case 0x04:
  case 0x05:
   rpcm.loop[reg_port] = (((((unsigned int)wreg[0x05])<<8)&0xff00)|(((unsigned int)wreg[0x04])&0x00ff))<<((11+4));
   break;
  case 0x06:
   rpcm.start[reg_port] = (((unsigned int)wreg[0x06])&0x00ff)<<((11+4) + 8);
   rpcm.addr[reg_port] = rpcm.start[reg_port];
   break;
  case 0x07:
   if( (data&0xc0) == 0xc0 )
   {
    i = data&0x07;
    rpcm.pcmx[0][i] = 0;
    rpcm.pcmx[1][i] = 0;
    rpcm.flag[i] |= (1<<1);
   }
   break;
  case 0x08:
   for( i = 0; i < (8); i++ )
   {
    if( !(data&(1<<i)) )
    {
     rpcm.flag[i] |= (1<<0);
    }
    else
    {
     rpcm.flag[i] &= ~((1<<0));
    }
   }
   break;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: val int


decompiled_code:
__int64 __fastcall RF5C68_r(int a1)
{
return *((unsigned __int8 *)pcmbuf + a1 + (unsigned int)(unsigned __int16)((unsigned __int8)byte_5C7 << 12));
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
return *((unsigned __int8 *)pcmbuf + a1 + (unsigned int)(unsigned __int16)((unsigned __int8)byte_5C7 << 12));
}

original_code:
data_t RF5C68_r(offs_t offset)
{
 unsigned int bank;
 bank = ((unsigned int)(wreg[0x07]&0x0f))<<(8+4);
 return pcmbuf[bank + offset];
}

canonical_original_code:
unsigned int RF5C68_r(unsigned int offset)
{
 unsigned int bank;
 bank = ((unsigned int)(wreg[0x07]&0x0f))<<(8+4);
 return pcmbuf[bank + offset];
}

variable_types:
bank
unsigned int


ParseOpen

decompiled_code:
__int64 __fastcall ParseOpen(__int64 a1)
{
fp = osd_fopen(0LL, a1, 12LL, 0LL);
if ( !fp )
return 0LL;
dwFilePos = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
fp = osd_fopen(0LL, a1, 12LL, 0LL);
if ( !fp )
return 0LL;
dwFilePos = 0LL;
return 1LL;
}

original_code:
static UINT8 ParseOpen(const char *pszFilename)
{
 fp = osd_fopen (((void *)0), pszFilename, OSD_FILETYPE_HISTORY, 0);
 if (((void *)0) == fp)
 {
  return(0);
 }
 dwFilePos = 0;
 return(1);
}

canonical_original_code:
static unsigned char ParseOpen(char *pszFilename)
{
 fp = osd_fopen (((void *)0), pszFilename, OSD_FILETYPE_HISTORY, 0);
 if (((void *)0) == fp)
 {
  return(0);
 }
 dwFilePos = 0;
 return(1);
}

variable_types:
pszFilename
char *

return_type: unsigned char


decompiled_code:
__int64 __fastcall ci_strncmp(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // er12
const __int32_t *v6; // rcx
__int64 v7; // rdi
__int64 v8; // rax
__int32_t v9; // esi

v3 = a3;
if ( a3 )
{
v6 = *_ctype_tolower_loc();
v7 = v3;
v8 = 0LL;
while ( 1 )
{
v3 = v6[*(char *)(a1 + v8)];
v9 = v6[*(char *)(a2 + v8)];
if ( v9 != v3 )
break;
if ( !v3 )
return v3;
if ( ++v8 == v7 )
return 0;
}
v3 -= v9;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // er12
const __int32_t *v6; // rcx
__int64 v7; // rdi
__int64 v8; // rax
__int32_t v9; // esi

v3 = a3;
if ( a3 )
{
v6 = *_ctype_tolower_loc();
v7 = v3;
v8 = 0LL;
while ( 1 )
{
v3 = v6[*(char *)(a1 + v8)];
v9 = v6[*(char *)(a2 + v8)];
if ( v9 != v3 )
break;
if ( !v3 )
return v3;
if ( ++v8 == v7 )
return 0;
}
v3 -= v9;
}
return v3;
}

original_code:
static int ci_strncmp (const char *s1, const char *s2, int n)
{
 int c1, c2;
 while (n)
 {
  if ((c1 = tolower (*s1++)) != (c2 = tolower (*s2++)))
   return (c1 - c2);
  else if (!c1)
   break;
  --n;
 }
 return 0;
}

canonical_original_code:
static int ci_strncmp(char *s1, char *s2, int n)
{
 int c1; int c2;
 while (n)
 {
  if ((c1 = tolower (*s1++)) != (c2 = tolower (*s2++)))
   return (c1 - c2);
  else if (!c1)
   break;
  --n;
 }
 return 0;
}

variable_types: n int


decompiled_code:
__int64 __fastcall ci_strcmp(__int64 a1, __int64 a2)
{
const __int32_t *v3; // rcx
__int64 i; // rax
unsigned int v5; // edx
__int32_t v6; // esi

v3 = *_ctype_tolower_loc();
for ( i = 0LL; ; ++i )
{
v5 = v3[*(char *)(a1 + i)];
v6 = v3[*(char *)(a2 + i)];
if ( v6 != v5 )
break;
if ( !v5 )
return v5;
}
v5 -= v6;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
const __int32_t *v3; // rcx
__int64 i; // rax
unsigned int v5; // edx
__int32_t v6; // esi

v3 = *_ctype_tolower_loc();
for ( i = 0LL; ; ++i )
{
v5 = v3[*(char *)(a1 + i)];
v6 = v3[*(char *)(a2 + i)];
if ( v6 != v5 )
break;
if ( !v5 )
return v5;
}
v5 -= v6;
return v5;
}

original_code:
static int ci_strcmp (const char *s1, const char *s2)
{
 int c1, c2;
 while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
  if (!c1)
   return 0;
 return (c1 - c2);
}

canonical_original_code:
static int ci_strcmp(char *s1, char *s2)
{
 int c1; int c2;
 while ((c1 = tolower(*s1++)) == (c2 = tolower(*s2++)))
  if (!c1)
   return 0;
 return (c1 - c2);
}


GetNextToken

decompiled_code:
__int64 __fastcall GetNextToken(_QWORD *a1, __int64 *a2)
{
__int64 result; // rax
char *v3; // rbx
__int64 v4; // r13
unsigned __int64 v5; // rax
unsigned __int8 v6; // bp
unsigned __int8 v7; // bl
char v8; // bl
unsigned __int8 v9; // al
__int64 v10; // rbx
char v11; // bp

while ( 1 )
{
v8 = osd_fgetc(fp);
v6 = v8;
if ( (unsigned int)osd_feof(fp) )
return 0xFFFFFFFFLL;
if ( v8 != 32 && v8 != 9 )
break;
LABEL_12:
++dwFilePos;
}
if ( a2 )
*a2 = dwFilePos;
if ( v8 == 44 || v8 == 61 )
{
bToken = v8;
byte_8A1 = 0;
++dwFilePos;
return v8 != 44;
}
if ( (unsigned __int8)v8 <= 0x20u )
{
if ( v8 == 10 )
{
v7 = osd_fgetc(fp);
osd_ungetc(v7, fp);
if ( v7 == 10 )
{
++dwFilePos;
bToken = 10;
byte_8A1 = 0;
return 3LL;
}
}
else if ( v8 == 13 )
{
++dwFilePos;
v9 = osd_fgetc(fp);
if ( v9 == 13 )
{
osd_ungetc(13LL, fp);
bToken = 13;
byte_8A1 = 0;
return 3LL;
}
if ( v9 == 10 && (v10 = dwFilePos + 1, ++dwFilePos, v9 = osd_fgetc(fp), v9 == 13) )
{
v11 = osd_fgetc(fp);
osd_fseek(fp, (unsigned int)v10, 0LL);
if ( a2 )
*a2 = v10;
if ( v11 == 10 )
{
bToken = 13;
byte_8A1 = 10;
byte_8A2 = 0;
return 3LL;
}
}
else
{
--dwFilePos;
osd_ungetc(v9, fp);
}
}
goto LABEL_12;
}
v3 = &bToken;
v4 = 0x2000100100002600LL;
while ( !(unsigned int)osd_feof(fp) )
{
++dwFilePos;
*v3++ = v6;
v5 = osd_fgetc(fp);
v6 = v5;
if ( (unsigned __int8)v5 <= 0x3Du )
{
if ( _bittest64(&v4, v5) )
break;
}
}
if ( !(unsigned int)osd_feof(fp) )
osd_ungetc(v6, fp);
*v3 = 0;
result = 2LL;
if ( a1 )
{
*a1 = &bToken;
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 *a2)
{
__int64 result; // rax
char *v3; // rbx
__int64 v4; // r13
unsigned __int64 v5; // rax
unsigned __int8 v6; // bp
unsigned __int8 v7; // bl
char v8; // bl
unsigned __int8 v9; // al
__int64 v10; // rbx
char v11; // bp

while ( 1 )
{
v8 = osd_fgetc(fp);
v6 = v8;
if ( (unsigned int)osd_feof(fp) )
return 0xFFFFFFFFLL;
if ( v8 != 32 && v8 != 9 )
break;
LABEL_12:
++dwFilePos;
}
if ( a2 )
*a2 = dwFilePos;
if ( v8 == 44 || v8 == 61 )
{
bToken = v8;
byte_8A1 = 0;
++dwFilePos;
return v8 != 44;
}
if ( (unsigned __int8)v8 <= 0x20u )
{
if ( v8 == 10 )
{
v7 = osd_fgetc(fp);
osd_ungetc(v7, fp);
if ( v7 == 10 )
{
++dwFilePos;
bToken = 10;
byte_8A1 = 0;
return 3LL;
}
}
else if ( v8 == 13 )
{
++dwFilePos;
v9 = osd_fgetc(fp);
if ( v9 == 13 )
{
osd_ungetc(13LL, fp);
bToken = 13;
byte_8A1 = 0;
return 3LL;
}
if ( v9 == 10 && (v10 = dwFilePos + 1, ++dwFilePos, v9 = osd_fgetc(fp), v9 == 13) )
{
v11 = osd_fgetc(fp);
osd_fseek(fp, (unsigned int)v10, 0LL);
if ( a2 )
*a2 = v10;
if ( v11 == 10 )
{
bToken = 13;
byte_8A1 = 10;
byte_8A2 = 0;
return 3LL;
}
}
else
{
--dwFilePos;
osd_ungetc(v9, fp);
}
}
goto LABEL_12;
}
v3 = &bToken;
v4 = 0x2000100100002600LL;
while ( !(unsigned int)osd_feof(fp) )
{
++dwFilePos;
*v3++ = v6;
v5 = osd_fgetc(fp);
v6 = v5;
if ( (unsigned __int8)v5 <= 0x3Du )
{
if ( _bittest64(&v4, v5) )
break;
}
}
if ( !(unsigned int)osd_feof(fp) )
osd_ungetc(v6, fp);
*v3 = 0;
result = 2LL;
if ( a1 )
{
*a1 = &bToken;
result = 2LL;
}
return result;
}

original_code:
static UINT32 GetNextToken(UINT8 **ppszTokenText, long *pdwPosition)
{
 UINT32 dwLength;
 long dwPos;
 UINT8 *pbTokenPtr = bToken;
 UINT8 bData;
 while (1)
 {
  bData = osd_fgetc(fp);
  if (osd_feof(fp))
   return(TOKEN_INVALID);
  if (' ' != bData && '\t' != bData)
  {
   if (pdwPosition)
    *pdwPosition = dwFilePos;
   if (',' == bData || '=' == bData)
   {
    *pbTokenPtr++ = bData;
    *pbTokenPtr = '\0';
    ++dwFilePos;
    if (',' == bData)
     return(TOKEN_COMMA);
    else
     return(TOKEN_EQUALS);
   }
   if (bData > ' ')
   {
    dwLength = 0;
    while (bData != ',' &&
       bData != '=' &&
       bData != ' ' &&
       bData != '\t' &&
       bData != '\n' &&
       bData != '\r' &&
       osd_feof(fp) == 0)
    {
     ++dwFilePos;
     *pbTokenPtr++ = bData;
     ++dwLength;
     ((void) (0));
     bData = osd_fgetc(fp);
    }
    if (0 == osd_feof(fp))
    {
     osd_ungetc(bData, fp);
    }
    *pbTokenPtr = '\0';
    if (ppszTokenText)
     *ppszTokenText = bToken;
    return(TOKEN_SYMBOL);
   }
   if (0x0a == bData)
   {
    bData = osd_fgetc(fp);
    osd_ungetc(bData, fp);
    if (0x0a == bData)
    {
     ++dwFilePos;
     *pbTokenPtr++ = bData;
     *pbTokenPtr = '\0';
     return(TOKEN_LINEBREAK);
    }
   }
   else
   if (0x0d == bData)
   {
    ++dwFilePos;
    bData = osd_fgetc(fp);
    if (0x0d == bData)
    {
     osd_ungetc(bData, fp);
     *pbTokenPtr++ = bData;
     *pbTokenPtr = '\0';
     return(TOKEN_LINEBREAK);
    }
    else
    if (0x0a == bData)
    {
     ++dwFilePos;
     dwPos = dwFilePos;
     bData = osd_fgetc(fp);
     if (0x0d == bData)
     {
      bData = osd_fgetc(fp);
      osd_fseek(fp, dwPos, 0);
      if (pdwPosition)
       *pdwPosition = dwPos;
      if (0x0a == bData)
      {
       *pbTokenPtr++ = '\r';
       *pbTokenPtr++ = '\n';
       *pbTokenPtr = '\0';
       return(TOKEN_LINEBREAK);
      }
     }
     else
     {
      --dwFilePos;
      osd_ungetc(bData, fp);
     }
    }
    else
    {
     --dwFilePos;
     osd_ungetc(bData, fp);
    }
   }
  }
  ++dwFilePos;
 }
}

canonical_original_code:
static unsigned int GetNextToken(unsigned char **ppszTokenText, long *pdwPosition)
{
 unsigned int dwLength;
 long dwPos;
 unsigned char *pbTokenPtr = bToken;
 unsigned char bData;
 while (1)
 {
  bData = osd_fgetc(fp);
  if (osd_feof(fp))
   return(TOKEN_INVALID);
  if (' ' != bData && '\t' != bData)
  {
   if (pdwPosition)
    *pdwPosition = dwFilePos;
   if (',' == bData || '=' == bData)
   {
    *pbTokenPtr++ = bData;
    *pbTokenPtr = '\0';
    ++dwFilePos;
    if (',' == bData)
     return(TOKEN_COMMA);
    else
     return(TOKEN_EQUALS);
   }
   if (bData > ' ')
   {
    dwLength = 0;
    while (bData != ',' &&
       bData != '=' &&
       bData != ' ' &&
       bData != '\t' &&
       bData != '\n' &&
       bData != '\r' &&
       osd_feof(fp) == 0)
    {
     ++dwFilePos;
     *pbTokenPtr++ = bData;
     ++dwLength;
     ((void) (0));
     bData = osd_fgetc(fp);
    }
    if (0 == osd_feof(fp))
    {
     osd_ungetc(bData, fp);
    }
    *pbTokenPtr = '\0';
    if (ppszTokenText)
     *ppszTokenText = bToken;
    return(TOKEN_SYMBOL);
   }
   if (0x0a == bData)
   {
    bData = osd_fgetc(fp);
    osd_ungetc(bData, fp);
    if (0x0a == bData)
    {
     ++dwFilePos;
     *pbTokenPtr++ = bData;
     *pbTokenPtr = '\0';
     return(TOKEN_LINEBREAK);
    }
   }
   else
   if (0x0d == bData)
   {
    ++dwFilePos;
    bData = osd_fgetc(fp);
    if (0x0d == bData)
    {
     osd_ungetc(bData, fp);
     *pbTokenPtr++ = bData;
     *pbTokenPtr = '\0';
     return(TOKEN_LINEBREAK);
    }
    else
    if (0x0a == bData)
    {
     ++dwFilePos;
     dwPos = dwFilePos;
     bData = osd_fgetc(fp);
     if (0x0d == bData)
     {
      bData = osd_fgetc(fp);
      osd_fseek(fp, dwPos, 0);
      if (pdwPosition)
       *pdwPosition = dwPos;
      if (0x0a == bData)
      {
       *pbTokenPtr++ = '\r';
       *pbTokenPtr++ = '\n';
       *pbTokenPtr = '\0';
       return(TOKEN_LINEBREAK);
      }
     }
     else
     {
      --dwFilePos;
      osd_ungetc(bData, fp);
     }
    }
    else
    {
     --dwFilePos;
     osd_ungetc(bData, fp);
    }
   }
  }
  ++dwFilePos;
 }
}

variable_types:
ppszTokenText
unsigned char **

variable_types:
pdwPosition
long *

variable_types:
dwLength
unsigned int

variable_types: dwPos long

variable_types:
pbTokenPtr
unsigned char *

variable_types:
bData
unsigned char


decompiled_code:
__int64 __fastcall index_datafile(_QWORD *a1)
{
int v1; // er12
_QWORD *v3; // r15
int v4; // ebx
char *v5; // rbp
unsigned int v6; // eax
__int64 v7; // rbx
__int64 v8; // r14
char *v9; // rbp
int v10; // [rsp+Ch] [rbp-4Ch]
__int64 v11; // [rsp+10h] [rbp-48h] BYREF
__int64 v12[8]; // [rsp+18h] [rbp-40h] BYREF

v1 = 0;
if ( !(unsigned __int8)ParseSeek(0, 0) )
{
v3 = malloc(0x4FB0uLL);
*a1 = v3;
if ( v3 )
{
do
{
v4 = GetNextToken(v12, &v11);
if ( v4 == 2 )
{
v5 = DATAFILE_TAG_KEY;
v6 = strlen(DATAFILE_TAG_KEY);
if ( !(unsigned int)ci_strncmp((__int64)v5, v12[0], v6) )
{
v4 = GetNextToken(v12, &v11);
if ( v4 == 1 )
{
v10 = GetNextToken(v12, &v11);
v4 = v10;
if ( v10 == 2 )
{
while ( 1 )
{
v7 = drivers;
if ( drivers )
break;
LABEL_18:
v4 = GetNextToken(v12, &v11);
if ( !v4 )
{
v4 = GetNextToken(v12, &v11);
if ( v4 == 2 )
continue;
}
goto LABEL_6;
}
v8 = v12[0];
v9 = (char *)(&drivers + 1);
while ( (unsigned int)ci_strcmp(v8, *(_QWORD *)(v7 + 16)) )
{
v9 += 8;
v7 = *((_QWORD *)v9 - 1);
if ( !v7 )
goto LABEL_18;
}
v3[1] = v7;
*v3 = v11;
v3 += 2;
++v1;
v4 = v10;
}
}
}
}
LABEL_6:
;
}
while ( v1 <= 1273 && v4 != -1 );
*v3 = 0LL;
v3[1] = 0LL;
}
else
{
v1 = 0;
}
}
return (unsigned int)v1;
}

original_code:
static int index_datafile (struct tDatafileIndex **_index)
{
 struct tDatafileIndex *idx;
 int count = 0;
 UINT32 token = TOKEN_SYMBOL;
 if (ParseSeek (0L, 0)) return 0;
 idx = *_index = (struct tDatafileIndex*)malloc(1275 * sizeof (struct tDatafileIndex));
 if (((void *)0) == idx) return 0;
 while ((count < (1275 - 1)) && TOKEN_INVALID != token)
 {
  long tell;
  char *s;
  token = GetNextToken ((UINT8 **)&s, &tell);
  if (TOKEN_SYMBOL != token) continue;
  if (!ci_strncmp (DATAFILE_TAG_KEY, s, strlen (DATAFILE_TAG_KEY)))
  {
   token = GetNextToken ((UINT8 **)&s, &tell);
   if (TOKEN_EQUALS == token)
   {
    int done = 0;
    int i;
    token = GetNextToken ((UINT8 **)&s, &tell);
    while (!done && TOKEN_SYMBOL == token)
    {
     for (i = 0; drivers[i]; i++)
     {
      if (!ci_strcmp (s, drivers[i]->name))
      {
       idx->driver = drivers[i];
       idx->offset = tell;
       idx++;
       count++;
       done = 1;
       break;
      }
     }
     if (!done)
     {
      token = GetNextToken ((UINT8 **)&s, &tell);
      if (TOKEN_COMMA == token)
       token = GetNextToken ((UINT8 **)&s, &tell);
      else
       done = 1;
     }
    }
   }
  }
 }
 idx->offset = 0L;
 idx->driver = 0;
 return count;
}

canonical_original_code:
static int index_datafile(struct tDatafileIndex **_index)
{
 struct tDatafileIndex *idx;
 int count = 0;
 unsigned int token = TOKEN_SYMBOL;
 if (ParseSeek (0L, 0)) return 0;
 idx = *_index = (struct tDatafileIndex *)malloc(1275 * sizeof (struct tDatafileIndex));
 if (((void *)0) == idx) return 0;
 while ((count < (1275 - 1)) && TOKEN_INVALID != token)
 {
  long tell;
  char *s;
  token = GetNextToken ((unsigned char **)&s, &tell);
  if (TOKEN_SYMBOL != token) continue;
  if (!ci_strncmp (DATAFILE_TAG_KEY, s, strlen (DATAFILE_TAG_KEY)))
  {
   token = GetNextToken ((unsigned char **)&s, &tell);
   if (TOKEN_EQUALS == token)
   {
    int done = 0;
    int i;
    token = GetNextToken ((unsigned char **)&s, &tell);
    while (!done && TOKEN_SYMBOL == token)
    {
     for (i = 0; drivers[i]; i++)
     {
      if (!ci_strcmp (s, drivers[i]->name))
      {
       idx->driver = drivers[i];
       idx->offset = tell;
       idx++;
       count++;
       done = 1;
       break;
      }
     }
     if (!done)
     {
      token = GetNextToken ((unsigned char **)&s, &tell);
      if (TOKEN_COMMA == token)
       token = GetNextToken ((unsigned char **)&s, &tell);
      else
       done = 1;
     }
    }
   }
  }
 }
 idx->offset = 0L;
 idx->driver = 0;
 return count;
}

variable_types: struct tDatafileIndex { long offset; struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver { struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); } *memory_read; struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; } *memory_write; struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); } *port_read; struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); } *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; } cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle { int min_x; int min_y; } default_visible_area; struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; } *gfxlayout; int color_codes_start; int total_color_codes; } *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound { int sound_type; void *sound_interface; } sound[5]; void (*nvram_handler)(void *file, int read_or_write); } *drv; struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; } *input_ports; void (*driver_init)(); struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *rom; unsigned int flags; } *driver; } **

variable_types: count int

variable_types:
token
unsigned int

variable_types: tell long

variable_types:
s
char *

variable_types: done int

variable_types: i int

user_defined_types: struct tDatafileIndex { long offset; struct GameDriver *driver; }

user_defined_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver *drv; struct InputPortTiny *input_ports; void (*driver_init)(); struct RomModule *rom; unsigned int flags; }

user_defined_types: struct MachineDriver { struct MachineCPU cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle default_visible_area; struct GfxDecodeInfo *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound sound[5]; void (*nvram_handler)(void *file, int read_or_write); }

user_defined_types: struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress *memory_read; struct MemoryWriteAddress *memory_write; struct IOReadPort *port_read; struct IOWritePort *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; }

user_defined_types: struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout *gfxlayout; int color_codes_start; int total_color_codes; }


original_code:
static int load_datafile_text (const struct GameDriver *drv, char *buffer, int bufsize,
 struct tDatafileIndex *idx, const char *tag)
{
 int offset = 0;
 int found = 0;
 UINT32 token = TOKEN_SYMBOL;
 UINT32 prev_token = TOKEN_SYMBOL;
 *buffer = '\0';
 while (idx->driver)
 {
  if (idx->driver == drv) break;
  idx++;
 }
 if (idx->driver == 0) return 1;
 if (ParseSeek (idx->offset, 0)) return 1;
 while (TOKEN_INVALID != token)
 {
  char *s;
  int len;
  long tell;
  token = GetNextToken ((UINT8 **)&s, &tell);
  if (TOKEN_INVALID == token) continue;
  if (found)
  {
   if (TOKEN_SYMBOL == token && '$' == s[0] && TOKEN_LINEBREAK == prev_token) break;
   prev_token = token;
   if (TOKEN_LINEBREAK == token)
    strcpy (s, "\n");
   if (TOKEN_LINEBREAK != token)
    strcat (s, " ");
   if (TOKEN_COMMA == token)
   {
    --buffer;
    --offset;
    *buffer = '\0';
   }
   len = strlen (s);
   if ((len + offset) >= bufsize) break;
   strcpy (buffer, s);
   buffer += len;
   offset += len;
  }
  else
  {
   if (TOKEN_SYMBOL == token)
   {
    if (!ci_strncmp (tag, s, strlen (tag)))
     found = 1;
    else if (!ci_strncmp (DATAFILE_TAG_KEY, s, strlen (DATAFILE_TAG_KEY)))
     break;
   }
  }
 }
 return (!found);
}

canonical_original_code:
static int load_datafile_text(struct GameDriver *drv, char *buffer, int bufsize, struct tDatafileIndex *idx, char *tag)
{
 int offset = 0;
 int found = 0;
 unsigned int token = TOKEN_SYMBOL;
 unsigned int prev_token = TOKEN_SYMBOL;
 *buffer = '\0';
 while (idx->driver)
 {
  if (idx->driver == drv) break;
  idx++;
 }
 if (idx->driver == 0) return 1;
 if (ParseSeek (idx->offset, 0)) return 1;
 while (TOKEN_INVALID != token)
 {
  char *s;
  int len;
  long tell;
  token = GetNextToken ((unsigned char **)&s, &tell);
  if (TOKEN_INVALID == token) continue;
  if (found)
  {
   if (TOKEN_SYMBOL == token && '$' == s[0] && TOKEN_LINEBREAK == prev_token) break;
   prev_token = token;
   if (TOKEN_LINEBREAK == token)
    strcpy (s, "\n");
   if (TOKEN_LINEBREAK != token)
    strcat (s, " ");
   if (TOKEN_COMMA == token)
   {
    --buffer;
    --offset;
    *buffer = '\0';
   }
   len = strlen (s);
   if ((len + offset) >= bufsize) break;
   strcpy (buffer, s);
   buffer += len;
   offset += len;
  }
  else
  {
   if (TOKEN_SYMBOL == token)
   {
    if (!ci_strncmp (tag, s, strlen (tag)))
     found = 1;
    else if (!ci_strncmp (DATAFILE_TAG_KEY, s, strlen (DATAFILE_TAG_KEY)))
     break;
   }
  }
 }
 return (!found);
}

variable_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver { struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); } *memory_read; struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; } *memory_write; struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); } *port_read; struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); } *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; } cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle { int min_x; int min_y; } default_visible_area; struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; } *gfxlayout; int color_codes_start; int total_color_codes; } *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound { int sound_type; void *sound_interface; } sound[5]; void (*nvram_handler)(void *file, int read_or_write); } *drv; struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; } *input_ports; void (*driver_init)(); struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *rom; unsigned int flags; } *

variable_types:
buffer
char *

variable_types: bufsize int

variable_types: struct tDatafileIndex { long offset; struct GameDriver *driver; } *

variable_types:
tag
char *

variable_types: offset int

variable_types: found int

variable_types: len int


ParseClose

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

if ( fp )
result = osd_fclose();
fp = 0LL;
return result;
}

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

if ( fp )
result = osd_fclose();
fp = 0LL;
return result;
}

original_code:
static void ParseClose(void)
{
 if (fp)
 {
  osd_fclose(fp);
 }
 fp = ((void *)0);
}

canonical_original_code:
static void ParseClose()
{
 if (fp)
 {
  osd_fclose(fp);
 }
 fp = ((void *)0);
}