decompiled_code:
__int64 __fastcall copy_to_memory(unsigned int a1, int a2, unsigned __int8 *a3, int a4)
{
int v4; // er13
__int64 v5; // r12
unsigned __int8 *v6; // rbx
unsigned int v7; // edx
unsigned int v8; // esi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, int a2, unsigned __int8 *a3, int a4)
{
int v4; // er13
__int64 v5; // r12
unsigned __int8 *v6; // rbx
unsigned int v7; // edx
unsigned int v8; // esi
__int64 result; // rax

if ( a4 > 0 )
{
v4 = a2 - (_DWORD)a3;
v5 = (__int64)&a3[a4 - 1 + 1];
v6 = a3;
do
{
v7 = *v6;
v8 = v4 + (_DWORD)v6++;
result = func4(a1, v8, v7);
}
while ( v6 != (unsigned __int8 *)v5 );
}
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
void *v1; // rbx
__int64 i; // r13
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 = ptr;
for ( i = result; v1; v1 = (void *)*((_QWORD *)v1 + 3) )
{
v3 = *((_DWORD *)v1 + 2);
v4 = (unsigned __int8 *)malloc(v3);
v5 = v4;
if ( v4 )
{
osd_fread(i, v4, v3);
copy_to_memory(*(_DWORD *)v1, *((_DWORD *)v1 + 1), v5, *((_DWORD *)v1 + 2));
free(v5);
}
}
result = osd_fclose(i);
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
void *v1; // rbx
__int64 i; // r13
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 = ptr;
for ( i = result; v1; v1 = (void *)*((_QWORD *)v1 + 3) )
{
v3 = *((_DWORD *)v1 + 2);
v4 = (unsigned __int8 *)malloc(v3);
v5 = v4;
if ( v4 )
{
osd_fread(i, v4, v3);
func5(*(_DWORD *)v1, *((_DWORD *)v1 + 1), v5, *((_DWORD *)v1 + 2));
free(v5);
}
}
result = osd_fclose(i);
}
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: struct mem_range { unsigned int cpu; struct mem_range *next; } *

variable_types:
data
unsigned char *

return_type: void


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: cpu int

variable_types: addr int

variable_types: oldcpu int

variable_types: result int

return_type: int


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

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

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

v0 = ptr;
if ( !ptr )
return 1LL;
while ( (unsigned int)func7(*(_DWORD *)v0, *((_DWORD *)v0 + 1)) == *((_DWORD *)v0 + 3)
&& (unsigned int)func7(*(_DWORD *)v0, *((_DWORD *)v0 + 1) + *((_DWORD *)v0 + 2) - 1) == *((_DWORD *)v0 + 4) )
{
v0 = (void *)*((_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;
}

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


decompiled_code:
void __fastcall copy_from_memory(unsigned int a1, int a2, __int64 a3, int a4)
{
int v4; // er13
__int64 v5; // r12
__int64 v6; // rbx
unsigned int v7; // esi

if ( a4 > 0 )
{
v4 = a2 - a3;
v5 = a3 + (unsigned int)(a4 - 1) + 1;
v6 = a3;
do
{
v7 = v4 + v6++;
*(_BYTE *)(v6 - 1) = computer_readmem_byte(a1, v7);
}
while ( v6 != v5 );
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, int a2, __int64 a3, int a4)
{
int v4; // er13
__int64 v5; // r12
__int64 v6; // rbx
unsigned int v7; // esi

if ( a4 > 0 )
{
v4 = a2 - a3;
v5 = a3 + (unsigned int)(a4 - 1) + 1;
v6 = a3;
do
{
v7 = v4 + v6++;
*(_BYTE *)(v6 - 1) = func7(a1, v7);
}
while ( v6 != v5 );
}
}

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
unsigned int *v1; // rbx
__int64 v2; // r13
unsigned int v3; // er12
void *v4; // rax
void *v5; // rbp

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

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

result = osd_fopen(*(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL), 0LL, 4LL, 1LL);
if ( result )
{
v1 = (unsigned int *)ptr;
v2 = result;
if ( ptr )
{
do
{
v3 = v1[2];
v4 = malloc(v3);
v5 = v4;
if ( v4 )
{
func9(*v1, v1[1], (__int64)v4, v3);
osd_fwrite(v2, v5, v1[2]);
}
v1 = (unsigned int *)*((_QWORD *)v1 + 3);
}
while ( v1 );
}
result = osd_fclose(v2);
}
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(__int64 a1)
{
__int64 v1; // r14
__int64 result; // rax
__int64 v3; // rbp
_DWORD *v4; // rsi
int v5; // eax
_QWORD *i; // rax
char *v7; // [rsp+8h] [rbp-60h] BYREF
char v8[88]; // [rsp+10h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // r14
__int64 result; // rax
__int64 v3; // rbp
_DWORD *v4; // rsi
int v5; // eax
_QWORD *i; // rax
char *v7; // [rsp+8h] [rbp-60h] BYREF
char v8[88]; // [rsp+10h] [rbp-58h] BYREF

LODWORD(v1) = 0;
result = osd_fopen(0LL, db_filename, 5LL, 0LL);
ptr = 0LL;
v3 = result;
if ( result )
{
while ( osd_fgets(v8, 48LL, v3) )
{
if ( (_DWORD)v1 )
{
if ( func1(v8) )
{
v7 = v8;
v4 = malloc(0x20uLL);
if ( !v4 )
{
func3();
break;
}
*v4 = func0(&v7);
v4[1] = func0(&v7);
v4[2] = func0(&v7);
v4[3] = func0(&v7);
v5 = func0(&v7);
*((_QWORD *)v4 + 3) = 0LL;
v4[4] = v5;
for ( i = ptr; ; i = (_QWORD *)i[3] )
{
if ( !i )
{
ptr = v4;
goto LABEL_16;
}
if ( !i[3] )
break;
}
i[3] = v4;
LABEL_16:
LODWORD(v1) = 2;
}
else if ( (_DWORD)v1 == 2 )
{
break;
}
}
else
{
v1 = func2((__int64)v8, a1);
}
}
result = osd_fclose(v3);
}
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:
name
char *

variable_types:
buffer
char [48]

variable_types:
pBuf
char *


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


decompiled_code:
__int64 __fastcall RF5C68_sh_start(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
_DWORD *v3; // r13
__int64 v4; // rax
const char *v5; // rax
const char *v6; // rax
int v7; // eax
int v8; // edx
int v10[2]; // [rsp+8h] [rbp-90h] BYREF
__int64 v11[2]; // [rsp+10h] [rbp-88h] BYREF
char s[40]; // [rsp+20h] [rbp-78h] BYREF
char v13[80]; // [rsp+48h] [rbp-50h] BYREF

v1 = Machine;
LODWORD(v2) = *(_DWORD *)(Machine + 836LL);
if ( !(_DWORD)v2 )
return (unsigned int)v2;
v3 = *(_DWORD **)(a1 + 8);
if ( pcmbuf || (pcmbuf = malloc(0x10000uLL)) != 0LL )
{
v4 = *(_QWORD *)(v1 + 824);
intf = (__int64)v3;
reg_port = 0;
emulation_rate = (int)(float)((float)(int)(float)((float)(int)v2 / *(float *)(v4 + 640)) * *(float *)(v4 + 640));
LODWORD(v4) = *v3;
xmmword_644 = 0LL;
xmmword_674 = 0LL;
xmmword_684 = 0LL;
xmmword_694 = 0LL;
xmmword_6A4 = 0LL;
xmmword_714 = 0LL;
xmmword_724 = 0LL;
wreg = 0LL;
rpcm = v4;
v11[0] = (__int64)s;
v11[1] = (__int64)v13;
v5 = (const char *)sound_name(a1);
sprintf(s, "%s Left", v5);
v6 = (const char *)sound_name(a1);
sprintf(v13, "%s Right", v6);
v7 = *(unsigned __int8 *)(intf + 4);
v8 = v7;
BYTE1(v7) = 2;
BYTE1(v8) = 1;
v10[1] = v7;
v10[0] = v8;
return (unsigned int)stream_init_multi(2LL, v11, v10, (unsigned int)v2, 0LL, RF5C68Update) == -1;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
_DWORD *v3; // r13
__int64 v4; // rax
const char *v5; // rax
const char *v6; // rax
int v7; // eax
int v8; // edx
int v10[2]; // [rsp+8h] [rbp-90h] BYREF
__int64 v11[2]; // [rsp+10h] [rbp-88h] BYREF
char s[40]; // [rsp+20h] [rbp-78h] BYREF
char v13[80]; // [rsp+48h] [rbp-50h] BYREF

v1 = Machine;
LODWORD(v2) = *(_DWORD *)(Machine + 836LL);
if ( !(_DWORD)v2 )
return (unsigned int)v2;
v3 = *(_DWORD **)(a1 + 8);
if ( pcmbuf || (pcmbuf = malloc(0x10000uLL)) != 0LL )
{
v4 = *(_QWORD *)(v1 + 824);
intf = (__int64)v3;
reg_port = 0;
emulation_rate = (int)(float)((float)(int)(float)((float)(int)v2 / *(float *)(v4 + 640)) * *(float *)(v4 + 640));
LODWORD(v4) = *v3;
xmmword_644 = 0LL;
xmmword_674 = 0LL;
xmmword_684 = 0LL;
xmmword_694 = 0LL;
xmmword_6A4 = 0LL;
xmmword_714 = 0LL;
xmmword_724 = 0LL;
wreg = 0LL;
rpcm = v4;
v11[0] = (__int64)s;
v11[1] = (__int64)v13;
v5 = (const char *)sound_name(a1);
sprintf(s, "%s Left", v5);
v6 = (const char *)sound_name(a1);
sprintf(v13, "%s Right", v6);
v7 = *(unsigned __int8 *)(intf + 4);
v8 = v7;
BYTE1(v7) = 2;
BYTE1(v8) = 1;
v10[1] = v7;
v10[0] = v8;
return (unsigned int)stream_init_multi(2LL, v11, v10, (unsigned int)v2, 0LL, RF5C68Update) == -1;
}
return 1LL;
}

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 func2()
{
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 i; // rcx
int v4; // edi
unsigned int v5; // edi
__int64 v6; // rcx
__int64 v7; // rsi

*((_BYTE *)&wreg + a1) = a2;
result = BYTE7(wreg);
if ( (BYTE7(wreg) & 0x40) != 0 )
{
result = BYTE7(wreg) & 7;
reg_port = BYTE7(wreg) & 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)(28456.0
/ (float)emulation_rate
* (float)((float)WORD1(wreg) * 0.00048828125)
* ((double)rpcm[0]
/ 8000000.0)
* 32768.0);
break;
case 4u:
case 5u:
result = WORD2(wreg) << 15;
rpcm[reg_port + 29] = result;
break;
case 6u:
v6 = reg_port;
result = BYTE6(wreg) << 23;
rpcm[reg_port + 13] = result;
rpcm[v6 + 5] = result;
break;
case 7u:
result = (unsigned __int8)a2 & 0xC0;
if ( (_DWORD)result == 192 )
{
result = (unsigned __int64)rpcm;
v7 = a2 & 7;
rpcm[v7 + 53] |= 2u;
rpcm[v7 + 37] = 0;
rpcm[v7 + 45] = 0;
}
break;
case 8u:
for ( i = 0LL; i != 8; ++i )
{
v4 = *((_DWORD *)&xmmword_714 + i);
result = v4 & 0xFFFFFFFE;
v5 = v4 | 1;
if ( (a2 & (1 << i)) == 0 )
result = v5;
*((_DWORD *)&xmmword_714 + i) = result;
}
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned int a1, int a2)
{
unsigned __int64 result; // rax
__int64 i; // rcx
int v4; // edi
unsigned int v5; // edi
__int64 v6; // rcx
__int64 v7; // rsi

*((_BYTE *)&wreg + a1) = a2;
result = BYTE7(wreg);
if ( (BYTE7(wreg) & 0x40) != 0 )
{
result = BYTE7(wreg) & 7;
reg_port = BYTE7(wreg) & 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)(28456.0
/ (float)emulation_rate
* (float)((float)WORD1(wreg) * 0.00048828125)
* ((double)rpcm[0]
/ 8000000.0)
* 32768.0);
break;
case 4u:
case 5u:
result = WORD2(wreg) << 15;
rpcm[reg_port + 29] = result;
break;
case 6u:
v6 = reg_port;
result = BYTE6(wreg) << 23;
rpcm[reg_port + 13] = result;
rpcm[v6 + 5] = result;
break;
case 7u:
result = (unsigned __int8)a2 & 0xC0;
if ( (_DWORD)result == 192 )
{
result = (unsigned __int64)rpcm;
v7 = a2 & 7;
rpcm[v7 + 53] |= 2u;
rpcm[v7 + 37] = 0;
rpcm[v7 + 45] = 0;
}
break;
case 8u:
for ( i = 0LL; i != 8; ++i )
{
v4 = *((_DWORD *)&xmmword_714 + i);
result = v4 & 0xFFFFFFFE;
v5 = v4 | 1;
if ( (a2 & (1 << i)) == 0 )
result = v5;
*((_DWORD *)&xmmword_714 + i) = result;
}
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: i int

variable_types: val int


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

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return *((unsigned __int8 *)pcmbuf + a1 + (unsigned int)(unsigned __int16)(BYTE7(wreg) << 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

return_type: 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, int a3)
{
const __int32_t *v4; // rdx
__int64 v5; // rax
unsigned int v6; // er8
__int32_t v7; // ecx

if ( !a3 )
return 0LL;
v4 = *_ctype_tolower_loc();
v5 = 0LL;
do
{
v6 = v4[*(char *)(a1 + v5)];
v7 = v4[*(char *)(a2 + v5)];
if ( v7 != v6 )
{
v6 -= v7;
return v6;
}
if ( !v6 )
return v6;
++v5;
}
while ( a3 != v5 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
const __int32_t *v4; // rdx
__int64 v5; // rax
unsigned int v6; // er8
__int32_t v7; // ecx

if ( !a3 )
return 0LL;
v4 = *_ctype_tolower_loc();
v5 = 0LL;
do
{
v6 = v4[*(char *)(a1 + v5)];
v7 = v4[*(char *)(a2 + v5)];
if ( v7 != v6 )
{
v6 -= v7;
return v6;
}
if ( !v6 )
return v6;
++v5;
}
while ( a3 != v5 );
return 0LL;
}

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 *v2; // rdx
__int64 i; // rax
unsigned int v4; // er8
__int32_t v5; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const __int32_t *v2; // rdx
__int64 i; // rax
unsigned int v4; // er8
__int32_t v5; // ecx

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

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 v3; // rdi
unsigned __int8 v4; // bl
unsigned __int8 v5; // r13
__int64 v6; // rax
unsigned __int8 v7; // bl
unsigned __int8 v8; // al
__int64 v9; // rbx
unsigned __int8 v10; // al
char v11; // r13
__int64 result; // rax
__int64 v13; // r14
__int16 *v14; // rbx
unsigned __int64 v15; // rax

v3 = fp;
while ( 1 )
{
v4 = osd_fgetc(v3);
v5 = v4;
if ( (unsigned int)osd_feof(fp) )
return 0xFFFFFFFFLL;
v6 = dwFilePos;
if ( v4 == 32 || v4 == 9 )
{
v3 = fp;
goto LABEL_7;
}
*a2 = dwFilePos;
if ( v4 == 44 || v4 == 61 )
{
dwFilePos = v6 + 1;
result = v4 != 44;
bToken = v4;
return result;
}
v3 = fp;
if ( v4 > 0x20u )
break;
if ( v4 == 10 )
{
v7 = osd_fgetc(fp);
osd_ungetc(v7, fp);
if ( v7 == 10 )
{
++dwFilePos;
result = 3LL;
bToken = 10;
return result;
}
goto LABEL_13;
}
if ( v4 != 13 )
goto LABEL_7;
dwFilePos = v6 + 1;
v8 = osd_fgetc(fp);
if ( v8 == 13 )
{
osd_ungetc(13LL, fp);
result = 3LL;
bToken = 13;
return result;
}
if ( v8 != 10 )
{
--dwFilePos;
osd_ungetc(v8, fp);
LABEL_13:
v6 = dwFilePos;
v3 = fp;
goto LABEL_7;
}
v9 = ++dwFilePos;
v10 = osd_fgetc(fp);
if ( v10 == 13 )
{
v11 = osd_fgetc(fp);
osd_fseek(fp, (unsigned int)v9, 0LL);
*a2 = v9;
if ( v11 == 10 )
{
strcpy((char *)&bToken, "\r\n");
return 3LL;
}
goto LABEL_13;
}
--dwFilePos;
osd_ungetc(v10, fp);
v6 = dwFilePos;
v3 = fp;
LABEL_7:
dwFilePos = v6 + 1;
}
v13 = 0x2000100100002600LL;
v14 = &bToken;
while ( !(unsigned int)osd_feof(v3) )
{
*(_BYTE *)v14 = v5;
v14 = (__int16 *)((char *)v14 + 1);
++dwFilePos;
v15 = osd_fgetc(fp);
v5 = v15;
if ( (unsigned __int8)v15 <= 0x3Du )
{
if ( _bittest64(&v13, v15) )
break;
}
v3 = fp;
}
if ( !(unsigned int)osd_feof(fp) )
osd_ungetc(v5, fp);
*(_BYTE *)v14 = 0;
result = 2LL;
*a1 = &bToken;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 *a2)
{
__int64 v3; // rdi
unsigned __int8 v4; // bl
unsigned __int8 v5; // r13
__int64 v6; // rax
unsigned __int8 v7; // bl
unsigned __int8 v8; // al
__int64 v9; // rbx
unsigned __int8 v10; // al
char v11; // r13
__int64 result; // rax
__int64 v13; // r14
__int16 *v14; // rbx
unsigned __int64 v15; // rax

v3 = fp;
while ( 1 )
{
v4 = osd_fgetc(v3);
v5 = v4;
if ( (unsigned int)osd_feof(fp) )
return 0xFFFFFFFFLL;
v6 = dwFilePos;
if ( v4 == 32 || v4 == 9 )
{
v3 = fp;
goto LABEL_7;
}
*a2 = dwFilePos;
if ( v4 == 44 || v4 == 61 )
{
dwFilePos = v6 + 1;
result = v4 != 44;
bToken = v4;
return result;
}
v3 = fp;
if ( v4 > 0x20u )
break;
if ( v4 == 10 )
{
v7 = osd_fgetc(fp);
osd_ungetc(v7, fp);
if ( v7 == 10 )
{
++dwFilePos;
result = 3LL;
bToken = 10;
return result;
}
goto LABEL_13;
}
if ( v4 != 13 )
goto LABEL_7;
dwFilePos = v6 + 1;
v8 = osd_fgetc(fp);
if ( v8 == 13 )
{
osd_ungetc(13LL, fp);
result = 3LL;
bToken = 13;
return result;
}
if ( v8 != 10 )
{
--dwFilePos;
osd_ungetc(v8, fp);
LABEL_13:
v6 = dwFilePos;
v3 = fp;
goto LABEL_7;
}
v9 = ++dwFilePos;
v10 = osd_fgetc(fp);
if ( v10 == 13 )
{
v11 = osd_fgetc(fp);
osd_fseek(fp, (unsigned int)v9, 0LL);
*a2 = v9;
if ( v11 == 10 )
{
strcpy((char *)&bToken, "\r\n");
return 3LL;
}
goto LABEL_13;
}
--dwFilePos;
osd_ungetc(v10, fp);
v6 = dwFilePos;
v3 = fp;
LABEL_7:
dwFilePos = v6 + 1;
}
v13 = 0x2000100100002600LL;
v14 = &bToken;
while ( !(unsigned int)osd_feof(v3) )
{
*(_BYTE *)v14 = v5;
v14 = (__int16 *)((char *)v14 + 1);
++dwFilePos;
v15 = osd_fgetc(fp);
v5 = v15;
if ( (unsigned __int8)v15 <= 0x3Du )
{
if ( _bittest64(&v13, v15) )
break;
}
v3 = fp;
}
if ( !(unsigned int)osd_feof(fp) )
osd_ungetc(v5, fp);
*(_BYTE *)v14 = 0;
result = 2LL;
*a1 = &bToken;
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


ParseClose

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

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

canonical_decompiled_code:
__int64 func4()
{
__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);
}


decompiled_code:
__int64 __fastcall load_datafile_text(__int64 a1, char *a2, int a3, __int64 *a4, const char *a5)
{
char *v5; // rbx
__int64 v6; // rax
int v7; // er12
int v8; // ebp
int v9; // eax
int v10; // er15
size_t v11; // rax
int v12; // eax
char *v13; // r15
int v14; // eax
int src; // [rsp+0h] [rbp-68h]
char *srcb; // [rsp+0h] [rbp-68h]
char *srca; // [rsp+0h] [rbp-68h]
char *srcc; // [rsp+0h] [rbp-68h]
int v21; // [rsp+8h] [rbp-60h]
char *v22; // [rsp+8h] [rbp-60h]
char *s; // [rsp+20h] [rbp-48h] BYREF
__int64 v26[8]; // [rsp+28h] [rbp-40h] BYREF

v5 = a2;
*a2 = 0;
v6 = a4[1];
if ( v6 )
{
while ( a1 != v6 )
{
v6 = a4[3];
a4 += 2;
if ( !v6 )
return 1;
}
if ( !(unsigned __int8)ParseSeek_constprop_0(*a4) )
{
v7 = 0;
v8 = 0;
src = 2;
while ( 1 )
{
while ( 1 )
{
v9 = GetNextToken(&s, v26);
v10 = v9;
if ( v9 == -1 )
return (unsigned int)(v7 ^ 1);
if ( v7 )
break;
if ( v9 == 2 )
{
v12 = strlen(a5);
v13 = s;
if ( (unsigned int)ci_strncmp((__int64)a5, (__int64)s, v12) )
{
v22 = DATAFILE_TAG_KEY;
v14 = strlen(DATAFILE_TAG_KEY);
if ( !(unsigned int)ci_strncmp((__int64)v22, (__int64)v13, v14) )
return 1;
}
else
{
v7 = 1;
}
}
}
if ( v9 == 2 )
{
if ( *s == 36 && src == 3 )
return 0;
srcc = s;
*(_WORD *)&srcc[strlen(s)] = 32;
}
else if ( v9 == 3 )
{
*(_WORD *)s = 10;
}
else
{
srcb = s;
*(_WORD *)&srcb[strlen(s)] = 32;
if ( !v10 )
{
*(v5 - 1) = 0;
--v8;
--v5;
}
}
srca = s;
v11 = strlen(s);
v8 += v11;
if ( v8 >= a3 )
return 0;
v21 = v11;
memcpy(v5, srca, v11 + 1);
src = v10;
v5 += v21;
}
}
}
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2, int a3, __int64 *a4, const char *a5)
{
char *v5; // rbx
__int64 v6; // rax
int v7; // er12
int v8; // ebp
int v9; // eax
int v10; // er15
size_t v11; // rax
int v12; // eax
char *v13; // r15
int v14; // eax
int src; // [rsp+0h] [rbp-68h]
char *srcb; // [rsp+0h] [rbp-68h]
char *srca; // [rsp+0h] [rbp-68h]
char *srcc; // [rsp+0h] [rbp-68h]
int v21; // [rsp+8h] [rbp-60h]
char *v22; // [rsp+8h] [rbp-60h]
char *s; // [rsp+20h] [rbp-48h] BYREF
__int64 v26[8]; // [rsp+28h] [rbp-40h] BYREF

v5 = a2;
*a2 = 0;
v6 = a4[1];
if ( v6 )
{
while ( a1 != v6 )
{
v6 = a4[3];
a4 += 2;
if ( !v6 )
return 1;
}
if ( !(unsigned __int8)func5(*a4) )
{
v7 = 0;
v8 = 0;
src = 2;
while ( 1 )
{
while ( 1 )
{
v9 = func3(&s, v26);
v10 = v9;
if ( v9 == -1 )
return (unsigned int)(v7 ^ 1);
if ( v7 )
break;
if ( v9 == 2 )
{
v12 = strlen(a5);
v13 = s;
if ( (unsigned int)func1((__int64)a5, (__int64)s, v12) )
{
v22 = DATAFILE_TAG_KEY;
v14 = strlen(DATAFILE_TAG_KEY);
if ( !(unsigned int)func1((__int64)v22, (__int64)v13, v14) )
return 1;
}
else
{
v7 = 1;
}
}
}
if ( v9 == 2 )
{
if ( *s == 36 && src == 3 )
return 0;
srcc = s;
*(_WORD *)&srcc[strlen(s)] = 32;
}
else if ( v9 == 3 )
{
*(_WORD *)s = 10;
}
else
{
srcb = s;
*(_WORD *)&srcb[strlen(s)] = 32;
if ( !v10 )
{
*(v5 - 1) = 0;
--v8;
--v5;
}
}
srca = s;
v11 = strlen(s);
v8 += v11;
if ( v8 >= a3 )
return 0;
v21 = v11;
memcpy(v5, srca, v11 + 1);
src = v10;
v5 += v21;
}
}
}
return 1;
}

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

variable_types:
s
char *

variable_types: len int

variable_types: tell long

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


decompiled_code:
__int64 __fastcall index_datafile(_QWORD *a1)
{
int v1; // er12
char *v3; // r14
int v4; // eax
int v5; // er8
bool v6; // al
int v7; // eax
__int64 v8; // r14
__int64 v9; // r15
__int64 *v10; // r13
int v11; // eax
_QWORD *v12; // [rsp+8h] [rbp-50h]
__int64 v13; // [rsp+10h] [rbp-48h] BYREF
__int64 v14[8]; // [rsp+18h] [rbp-40h] BYREF

v1 = 0;
if ( !(unsigned __int8)ParseSeek_constprop_0(0LL) )
{
v12 = malloc(0x4FB0uLL);
*a1 = v12;
if ( v12 )
{
while ( 1 )
{
v7 = GetNextToken(v14, &v13);
if ( v7 == 2 )
{
v3 = DATAFILE_TAG_KEY;
v4 = strlen(DATAFILE_TAG_KEY);
v5 = ci_strncmp((__int64)v3, v14[0], v4);
v6 = 1;
if ( v5 )
{
LABEL_6:
if ( v1 > 1273 )
goto LABEL_11;
goto LABEL_7;
}
v7 = GetNextToken(v14, &v13);
if ( v7 == 1 )
{
while ( 1 )
{
v7 = GetNextToken(v14, &v13);
if ( v7 != 2 )
break;
v8 = v14[0];
v9 = drivers;
v10 = &drivers + 1;
if ( drivers )
{
while ( (unsigned int)ci_strcmp(v8, *(_QWORD *)(v9 + 16)) )
{
v9 = *v10++;
if ( !v9 )
goto LABEL_19;
}
++v1;
*v12 = v13;
v6 = 1;
v12[1] = v9;
v12 += 2;
goto LABEL_6;
}
LABEL_19:
v11 = GetNextToken(v14, &v13);
if ( v11 )
{
v6 = v11 != -1;
goto LABEL_7;
}
}
}
}
v6 = v7 != -1;
LABEL_7:
if ( !v6 )
{
LABEL_11:
*v12 = 0LL;
v12[1] = 0LL;
return (unsigned int)v1;
}
}
}
}
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: done int

variable_types: i int

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


decompiled_code:
__int64 __fastcall load_driver_history(__int64 a1, char *a2, int a3)
{
__int64 v3; // r13
__int64 v5; // rbx
__int64 *v6; // rcx
__int64 v7; // r15
int v8; // eax
__int64 v9; // rcx
int v10; // er15
int v11; // eax
__int64 *v12; // rcx
int v13; // er12
char *v14; // rbp
int v15; // eax
int v16; // er15
int v18; // eax
int v19; // eax
_BOOL4 v20; // eax
__int64 *v21; // [rsp+8h] [rbp-40h]

LODWORD(v3) = 0;
v5 = a1;
*a2 = 0;
if ( (unsigned __int8)ParseOpen((__int64)history_filename[0]) )
{
v6 = (__int64 *)hist_idx_1;
LODWORD(v3) = 1;
if ( hist_idx_1 || (v18 = index_datafile(&hist_idx_1), v6 = (__int64 *)hist_idx_1, v3 = v18 != 0, hist_idx_1) )
{
v7 = a1;
while ( 1 )
{
v8 = load_datafile_text(v7, a2, a3, v6, DATAFILE_TAG_BIO[0]);
v7 = *(_QWORD *)(v7 + 8);
if ( !v8 || !v7 )
break;
v6 = (__int64 *)hist_idx_1;
}
if ( v8 )
LODWORD(v3) = 0;
}
ParseClose();
}
if ( (unsigned __int8)ParseOpen((__int64)mameinfo_filename[0]) )
{
v9 = mame_idx_0;
v10 = 1;
if ( mame_idx_0 || (v19 = index_datafile(&mame_idx_0), v9 = mame_idx_0, v20 = v19 != 0, v10 = v20, mame_idx_0) )
{
v21 = (__int64 *)v9;
v11 = strlen(a2);
v12 = v21;
v13 = a3 - v11;
v14 = &a2[v11];
while ( 1 )
{
v15 = load_datafile_text(v5, v14, v13, v12, DATAFILE_TAG_MAME[0]);
v5 = *(_QWORD *)(v5 + 8);
if ( !v15 || !v5 )
break;
v12 = (__int64 *)mame_idx_0;
}
v16 = v3 | v10;
if ( !v15 )
LODWORD(v3) = v16;
}
else
{
LODWORD(v3) = v20 | v3;
}
ParseClose();
}
return (unsigned int)v3 ^ 1;
}

original_code:
int load_driver_history (const struct GameDriver *drv, char *buffer, int bufsize)
{
 static struct tDatafileIndex *hist_idx = 0;
 static struct tDatafileIndex *mame_idx = 0;
 int history = 0, mameinfo = 0;
 int err;
 *buffer = 0;
 if (ParseOpen (history_filename))
 {
  if (hist_idx)
   history = 1;
  else
   history = (index_datafile (&hist_idx) != 0);
  if (hist_idx)
  {
   const struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer, bufsize,
            hist_idx, DATAFILE_TAG_BIO);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) history = 0;
  }
  ParseClose ();
 }
 if (ParseOpen (mameinfo_filename))
 {
  if (mame_idx)
   mameinfo = 1;
  else
   mameinfo = (index_datafile (&mame_idx) != 0);
  if (mame_idx)
  {
   int len = strlen (buffer);
   const struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer+len, bufsize-len,
            mame_idx, DATAFILE_TAG_MAME);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) mameinfo = 0;
  }
  ParseClose ();
 }
 return (history == 0 && mameinfo == 0);
}

canonical_original_code:
int load_driver_history(struct GameDriver *drv, char *buffer, int bufsize)
{
 static struct tDatafileIndex *hist_idx = 0;
 static struct tDatafileIndex *mame_idx = 0;
 int history = 0; int mameinfo = 0;
 int err;
 *buffer = 0;
 if (ParseOpen (history_filename))
 {
  if (hist_idx)
   history = 1;
  else
   history = (index_datafile (&hist_idx) != 0);
  if (hist_idx)
  {
   struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer, bufsize,
            hist_idx, DATAFILE_TAG_BIO);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) history = 0;
  }
  ParseClose ();
 }
 if (ParseOpen (mameinfo_filename))
 {
  if (mame_idx)
   mameinfo = 1;
  else
   mameinfo = (index_datafile (&mame_idx) != 0);
  if (mame_idx)
  {
   int len = strlen (buffer);
   struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer+len, bufsize-len,
            mame_idx, DATAFILE_TAG_MAME);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) mameinfo = 0;
  }
  ParseClose ();
 }
 return (history == 0 && mameinfo == 0);
}

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: history int

variable_types: mameinfo int

variable_types: err int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

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

original_code:
static data_t exprraid_prot_1_r(offs_t offset)
{
 return 0x02;
}

canonical_original_code:
static unsigned int exprraid_prot_1_r(unsigned int offset)
{
 return 0x02;
}

variable_types:
offset
unsigned int


decompiled_code:
void *__fastcall exprraid_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx
int v3; // ecx
__int64 v4; // r15
unsigned int v5; // er13
unsigned int v6; // er12
void *result; // rax
int v8; // er14
__int64 v9; // r15
int v10; // edx
int v11; // esi
char v12; // al
__int64 v13; // [rsp-28h] [rbp-70h]
unsigned int v14; // [rsp+0h] [rbp-48h]
int v15; // [rsp+4h] [rbp-44h]

v1 = a1;
drawbg(a1, 0);
if ( spriteram_size )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = *(unsigned __int8 *)(spriteram + v2 + 1);
v4 = (unsigned int)(unsigned __int8)(-8 - *(_BYTE *)(spriteram + v2 + 2)) - 8;
v5 = *(unsigned __int8 *)(spriteram + v2 + 3) + ((8 * (_WORD)v3) & 0x700);
v6 = (v3 >> 1) & 4 | *(_BYTE *)(spriteram + v2 + 1) & 3;
v15 = *(unsigned __int8 *)(spriteram + v2);
v14 = *(_BYTE *)(spriteram + v2 + 1) & 4;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v5,
v6,
*(_BYTE *)(spriteram + v2 + 1) & 4,
0LL,
v4,
*(unsigned __int8 *)(spriteram + v2),
0LL,
2LL,
0LL);
if ( (*(_BYTE *)(spriteram + v2 + 1) & 0x10) != 0 )
break;
v2 += 4LL;
if ( spriteram_size <= v2 )
goto LABEL_6;
}
v2 += 4LL;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v5 + 1, v6, v14, 0LL, v4, (unsigned int)(v15 + 16), 0LL, 2LL, 0LL);
}
while ( spriteram_size > v2 );
LABEL_6:
v1 = a1;
}
drawbg(v1, 1);
result = &videoram_size;
v8 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v9 = v8;
do
{
v10 = *(unsigned __int8 *)(colorram + v9);
v11 = *(unsigned __int8 *)(videoram + v9--);
v13 = (unsigned int)(8 * (v8 >> 5));
v12 = v8--;
result = (void *)drawgfx(
v1,
*(_QWORD *)(Machine + 512LL),
v11 + (((_WORD)v10 << 8) & 0x700u),
(v10 >> 4) & 1,
0LL,
0LL,
8 * (v12 & 0x1Fu),
v13,
Machine + 776LL,
2LL,
0LL);
}
while ( v8 != -1 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx
int v3; // ecx
__int64 v4; // r15
unsigned int v5; // er13
unsigned int v6; // er12
void *result; // rax
int v8; // er14
__int64 v9; // r15
int v10; // edx
int v11; // esi
char v12; // al
__int64 v13; // [rsp-28h] [rbp-70h]
unsigned int v14; // [rsp+0h] [rbp-48h]
int v15; // [rsp+4h] [rbp-44h]

v1 = a1;
func2(a1, 0);
if ( spriteram_size )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = *(unsigned __int8 *)(spriteram + v2 + 1);
v4 = (unsigned int)(unsigned __int8)(-8 - *(_BYTE *)(spriteram + v2 + 2)) - 8;
v5 = *(unsigned __int8 *)(spriteram + v2 + 3) + ((8 * (_WORD)v3) & 0x700);
v6 = (v3 >> 1) & 4 | *(_BYTE *)(spriteram + v2 + 1) & 3;
v15 = *(unsigned __int8 *)(spriteram + v2);
v14 = *(_BYTE *)(spriteram + v2 + 1) & 4;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v5,
v6,
*(_BYTE *)(spriteram + v2 + 1) & 4,
0LL,
v4,
*(unsigned __int8 *)(spriteram + v2),
0LL,
2LL,
0LL);
if ( (*(_BYTE *)(spriteram + v2 + 1) & 0x10) != 0 )
break;
v2 += 4LL;
if ( spriteram_size <= v2 )
goto LABEL_6;
}
v2 += 4LL;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v5 + 1, v6, v14, 0LL, v4, (unsigned int)(v15 + 16), 0LL, 2LL, 0LL);
}
while ( spriteram_size > v2 );
LABEL_6:
v1 = a1;
}
func2(v1, 1);
result = &videoram_size;
v8 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v9 = v8;
do
{
v10 = *(unsigned __int8 *)(colorram + v9);
v11 = *(unsigned __int8 *)(videoram + v9--);
v13 = (unsigned int)(8 * (v8 >> 5));
v12 = v8--;
result = (void *)drawgfx(
v1,
*(_QWORD *)(Machine + 512LL),
v11 + (((_WORD)v10 << 8) & 0x700u),
(v10 >> 4) & 1,
0LL,
0LL,
8 * (v12 & 0x1Fu),
v13,
Machine + 776LL,
2LL,
0LL);
}
while ( v8 != -1 );
}
return result;
}

original_code:
void exprraid_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 drawbg(bitmap,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx,sy,code,color,flipx;
  code = spriteram[offs+3] + ( ( spriteram[offs+1] & 0xe0 ) << 3 );
  sx = ((248 - spriteram[offs+2]) & 0xff) - 8;
  sy = spriteram[offs];
  color = (spriteram[offs+1] & 0x03) + ((spriteram[offs+1] & 0x08) >> 1);
  flipx = ( spriteram[offs+1] & 0x04 );
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,0,
    sx,sy,
    0,TRANSPARENCY_PEN,0);
  if ( spriteram[offs+1] & 0x10 ) {
   drawgfx(bitmap,Machine->gfx[1],
     code + 1,
     color,
     flipx,0,
     sx,sy+16,
     0,TRANSPARENCY_PEN,0);
  }
 }
 drawbg(bitmap,1);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + ((colorram[offs] & 7) << 8),
    (colorram[offs] & 0x10) >> 4,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void exprraid_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 drawbg(bitmap,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx; int sy; int code; int color; int flipx;
  code = spriteram[offs+3] + ( ( spriteram[offs+1] & 0xe0 ) << 3 );
  sx = ((248 - spriteram[offs+2]) & 0xff) - 8;
  sy = spriteram[offs];
  color = (spriteram[offs+1] & 0x03) + ((spriteram[offs+1] & 0x08) >> 1);
  flipx = ( spriteram[offs+1] & 0x04 );
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,0,
    sx,sy,
    0,TRANSPARENCY_PEN,0);
  if ( spriteram[offs+1] & 0x10 ) {
   drawgfx(bitmap,Machine->gfx[1],
     code + 1,
     color,
     flipx,0,
     sx,sy+16,
     0,TRANSPARENCY_PEN,0);
  }
 }
 drawbg(bitmap,1);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + ((colorram[offs] & 7) << 8),
    (colorram[offs] & 0x10) >> 4,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,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: code int

variable_types: color int

variable_types: flipx int


decompiled_code:
__int64 exprraid_prot_0_r()
{
return *(unsigned __int8 *)(memory_region(129LL) + 681);
}

canonical_decompiled_code:
__int64 func4()
{
return *(unsigned __int8 *)(memory_region(129LL) + 681);
}

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

canonical_original_code:
static unsigned int exprraid_prot_0_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 return RAM[0x02a9];
}

variable_types:
RAM
unsigned char *


decompiled_code:
_QWORD *exprraid_gfx_expand()
{
__int64 v0; // r8
_QWORD *result; // rax
char *v2; // rdx
_QWORD *v3; // r8
unsigned __int64 v4; // rdi
_QWORD *v5; // rcx
char *v6; // rsi

v0 = memory_region(139LL);
result = (_QWORD *)(v0 + 61440);
v2 = (char *)(v0 + 28672);
v3 = (_QWORD *)(v0 - 4096);
do
{
*result = *(_QWORD *)v2;
result[511] = *((_QWORD *)v2 + 511);
qmemcpy(
(void *)((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - ((char *)result - ((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 4096) >> 3));
v4 = (unsigned __int64)(result - 511);
v5 = result - 512;
result -= 1024;
result[512] = *(_QWORD *)v2;
result[1023] = *((_QWORD *)v2 + 511);
v6 = v2;
v2 -= 4096;
qmemcpy(
(void *)(v4 & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v6 - ((char *)v5 - (v4 & 0xFFFFFFFFFFFFFFF8LL))),
8 * (((unsigned int)v5 - (v4 & 0xFFFFFFF8) + 4096) >> 3));
}
while ( result != v3 );
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
__int64 v0; // r8
_QWORD *result; // rax
char *v2; // rdx
_QWORD *v3; // r8
unsigned __int64 v4; // rdi
_QWORD *v5; // rcx
char *v6; // rsi

v0 = memory_region(139LL);
result = (_QWORD *)(v0 + 61440);
v2 = (char *)(v0 + 28672);
v3 = (_QWORD *)(v0 - 4096);
do
{
*result = *(_QWORD *)v2;
result[511] = *((_QWORD *)v2 + 511);
qmemcpy(
(void *)((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - ((char *)result - ((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 4096) >> 3));
v4 = (unsigned __int64)(result - 511);
v5 = result - 512;
result -= 1024;
result[512] = *(_QWORD *)v2;
result[1023] = *((_QWORD *)v2 + 511);
v6 = v2;
v2 -= 4096;
qmemcpy(
(void *)(v4 & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v6 - ((char *)v5 - (v4 & 0xFFFFFFFFFFFFFFF8LL))),
8 * (((unsigned int)v5 - (v4 & 0xFFFFFFF8) + 4096) >> 3));
}
while ( result != v3 );
return result;
}

original_code:
static void exprraid_gfx_expand(void)
{
 unsigned char *gfx = memory_region(REGION_GFX3);
 int offs = 0x10000-0x1000;
 int i;
 for ( i = 0x8000-0x1000; i >= 0; i-= 0x1000 )
 {
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
 }
}

canonical_original_code:
static void exprraid_gfx_expand()
{
 unsigned char *gfx = memory_region(REGION_GFX3);
 int offs = 0x10000-0x1000;
 int i;
 for ( i = 0x8000-0x1000; i >= 0; i-= 0x1000 )
 {
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
 }
}

variable_types:
gfx
unsigned char *


decompiled_code:
__int64 init_wexpress()
{
__int64 v0; // rbx
int i; // edx
__int64 result; // rax
_BYTE *v3; // rsi
_BYTE *v4; // rdi

v0 = memory_region(129LL);
exprraid_gfx_expand();
for ( i = 0; ; i = result )
{
result = (unsigned int)(i + 1);
v3 = (_BYTE *)(v0 + i);
if ( *v3 == 75 )
{
v4 = (_BYTE *)(v0 + (int)result);
if ( !*v4 && *(_BYTE *)(v0 + i + 2) == 41 && *(_BYTE *)(v0 + i + 3) == 2 )
break;
}
if ( (int)result > 0xFFFF )
return result;
LABEL_3:
;
}
result = (unsigned int)(i + 2);
*v3 = -91;
*v4 = -1;
if ( (int)result <= 0xFFFF )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
int i; // edx
__int64 result; // rax
_BYTE *v3; // rsi
_BYTE *v4; // rdi

v0 = memory_region(129LL);
func5();
for ( i = 0; ; i = result )
{
result = (unsigned int)(i + 1);
v3 = (_BYTE *)(v0 + i);
if ( *v3 == 75 )
{
v4 = (_BYTE *)(v0 + (int)result);
if ( !*v4 && *(_BYTE *)(v0 + i + 2) == 41 && *(_BYTE *)(v0 + i + 3) == 2 )
break;
}
if ( (int)result > 0xFFFF )
return result;
LABEL_3:
;
}
result = (unsigned int)(i + 2);
*v3 = -91;
*v4 = -1;
if ( (int)result <= 0xFFFF )
goto LABEL_3;
return result;
}

original_code:
static void init_wexpress(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 exprraid_gfx_expand();
 for ( i = 0; i < 0x10000; i++ )
 {
  if ( rom[i] == 0x4b && rom[i+1] == 0x00 && rom[i+2] == 0x29 && rom[i+3] == 0x02 )
  {
   rom[i] = 0xa5;
   i++;
   rom[i] = 0xff;
  }
 }
}

canonical_original_code:
static void init_wexpress()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 exprraid_gfx_expand();
 for ( i = 0; i < 0x10000; i++ )
 {
  if ( rom[i] == 0x4b && rom[i+1] == 0x00 && rom[i+2] == 0x29 && rom[i+3] == 0x02 )
  {
   rom[i] = 0xa5;
   i++;
   rom[i] = 0xff;
  }
 }
}

variable_types:
rom
unsigned char *

variable_types: i int


original_code:
static void init_exprraid(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0xfffa] = rom[0xfff7];
 rom[0xfffb] = rom[0xfff6];
 rom[0xfffc] = rom[0xfff1];
 rom[0xfffd] = rom[0xfff0];
 rom[0xfffe] = rom[0xfff3];
 rom[0xffff] = rom[0xfff2];
 init_wexpress();
}

canonical_original_code:
static void init_exprraid()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0xfffa] = rom[0xfff7];
 rom[0xfffb] = rom[0xfff6];
 rom[0xfffc] = rom[0xfff1];
 rom[0xfffd] = rom[0xfff0];
 rom[0xfffe] = rom[0xfff3];
 rom[0xffff] = rom[0xfff2];
 init_wexpress();
}


decompiled_code:
// attributes: thunk
_QWORD *init_wexpresb()
{
return exprraid_gfx_expand();
}

canonical_decompiled_code:
_QWORD *func8()
{
return func5();
}

original_code:
static void init_wexpresb(void)
{
 exprraid_gfx_expand();
}

canonical_original_code:
static void init_wexpresb()
{
 exprraid_gfx_expand();
}


decompiled_code:
__int64 exprraid_interrupt()
{
if ( (~(unsigned __int8)readinputport(3LL) & 0xC0) == 0 )
{
coin_0 = 0;
return ignore_interrupt();
}
if ( coin_0 )
return ignore_interrupt();
coin_0 = 1;
return nmi_interrupt();
}

canonical_decompiled_code:
__int64 func10()
{
if ( (~(unsigned __int8)readinputport(3LL) & 0xC0) == 0 )
{
coin_0 = 0;
return ignore_interrupt();
}
if ( coin_0 )
return ignore_interrupt();
coin_0 = 1;
return nmi_interrupt();
}

original_code:
static int exprraid_interrupt(void)
{
 static int coin = 0;
 if ( ( ~readinputport( 3 ) ) & 0xc0 ) {
  if ( coin == 0 ) {
   coin = 1;
   return nmi_interrupt();
  }
 } else
  coin = 0;
 return ignore_interrupt();
}

canonical_original_code:
static int exprraid_interrupt()
{
 static int coin = 0;
 if ( ( ~readinputport( 3 ) ) & 0xc0 ) {
  if ( coin == 0 ) {
   coin = 1;
   return nmi_interrupt();
  }
 } else
  coin = 0;
 return ignore_interrupt();
}

variable_types: coin int


decompiled_code:
__int64 vblank_r()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-Ch]

result = readinputport(0LL);
if ( (result & 2) != 0 )
{
v1 = result;
cpu_spin();
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-Ch]

result = readinputport(0LL);
if ( (result & 2) != 0 )
{
v1 = result;
cpu_spin();
result = v1;
}
return result;
}

original_code:
static data_t vblank_r(offs_t offset) {
 int val = readinputport( 0 );
 if ( ( val & 0x02 ) )
  cpu_spin();
 return val;
}

canonical_original_code:
static unsigned int vblank_r(unsigned int offset) {
 int val = readinputport( 0 );
 if ( ( val & 0x02 ) )
  cpu_spin();
 return val;
}

variable_types: val int


irqhandler

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

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

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

variable_types: linestate int


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

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

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

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

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall canyon_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // r13
_BYTE *v4; // rdx

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
v4 = (_BYTE *)(v3 + dirtybuffer);
if ( a2 || *v4 )
{
*v4 = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v3) & 0x3F,
*(_BYTE *)(videoram + v3) >> 7,
0LL,
0LL,
8 * (v2 & 0x1Fu),
(unsigned int)(8 * (v2 >> 5)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
((unsigned int)*(char *)(spriteram + 9LL) >> 3) & 3,
0LL,
*(char *)(spriteram + 9LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 1LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 8LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
((unsigned int)*(char *)(spriteram + 11LL) >> 3) & 3,
1LL,
*(char *)(spriteram + 11LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 3LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 10LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
2LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 5LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 12LL),
Machine + 776LL,
2LL,
0LL);
return drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
3LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 7LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 14LL),
Machine + 776LL,
2LL,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // r13
_BYTE *v4; // rdx

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
v4 = (_BYTE *)(v3 + dirtybuffer);
if ( a2 || *v4 )
{
*v4 = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v3) & 0x3F,
*(_BYTE *)(videoram + v3) >> 7,
0LL,
0LL,
8 * (v2 & 0x1Fu),
(unsigned int)(8 * (v2 >> 5)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
((unsigned int)*(char *)(spriteram + 9LL) >> 3) & 3,
0LL,
*(char *)(spriteram + 9LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 1LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 8LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
((unsigned int)*(char *)(spriteram + 11LL) >> 3) & 3,
1LL,
*(char *)(spriteram + 11LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 3LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 10LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
2LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 5LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 12LL),
Machine + 776LL,
2LL,
0LL);
return drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
3LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 7LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 14LL),
Machine + 776LL,
2LL,
0LL);
}

original_code:
void canyon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (full_refresh || dirtybuffer[offs])
  {
   int charcode;
   int sx,sy;
   dirtybuffer[offs]=0;
   charcode = videoram[offs] & 0x3F;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0],
     charcode, (videoram[offs] & 0x80)>>7,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs=0; offs<2; offs++)
 {
  int sx, sy;
  int pic;
  int flipx;
  sx = 224 - spriteram[offs*2+1];
  sy = 240 - spriteram[offs*2+8];
  pic = spriteram[offs*2+9];
  if (pic & 0x80)
   flipx=0;
  else
   flipx=1;
        drawgfx(bitmap,Machine->gfx[1],
                (pic & 0x18) >> 3, offs,
  flipx,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs=2; offs<4; offs++)
 {
  int sx, sy;
  sx = 254 - spriteram[offs*2+1];
  sy = 246 - spriteram[offs*2+8];
        drawgfx(bitmap,Machine->gfx[2],
                0, offs,
  0,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void canyon_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (full_refresh || dirtybuffer[offs])
  {
   int charcode;
   int sx; int sy;
   dirtybuffer[offs]=0;
   charcode = videoram[offs] & 0x3F;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0],
     charcode, (videoram[offs] & 0x80)>>7,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs=0; offs<2; offs++)
 {
  int sx; int sy;
  int pic;
  int flipx;
  sx = 224 - spriteram[offs*2+1];
  sy = 240 - spriteram[offs*2+8];
  pic = spriteram[offs*2+9];
  if (pic & 0x80)
   flipx=0;
  else
   flipx=1;
        drawgfx(bitmap,Machine->gfx[1],
                (pic & 0x18) >> 3, offs,
  flipx,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs=2; offs<4; offs++)
 {
  int sx; int sy;
  sx = 254 - spriteram[offs*2+1];
  sy = 246 - spriteram[offs*2+8];
        drawgfx(bitmap,Machine->gfx[2],
                0, offs,
  0,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: charcode int

variable_types: pic int

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


decompiled_code:
__int64 __fastcall canyon_motor_w(char a1, char a2)
{
return discrete_sound_w(a1 & 1, a2 & 0xF);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, char a2)
{
return discrete_sound_w(a1 & 1, a2 & 0xF);
}

original_code:
void canyon_motor_w(offs_t offset,data_t data)
{
        discrete_sound_w(offset & 0x01, data & 0x0f);
}

canonical_original_code:
void canyon_motor_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(offset & 0x01, data & 0x0f);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall canyon_explode_w(__int64 a1, unsigned int a2)
{
return discrete_sound_w(6LL, a2 >> 4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
return discrete_sound_w(6LL, a2 >> 4);
}

original_code:
void canyon_explode_w(offs_t offset,data_t data)
{
        discrete_sound_w(6, data / 16);
}

canonical_original_code:
void canyon_explode_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(6, data / 16);
}


decompiled_code:
__int64 __fastcall canyon_attract_w(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 4, ((unsigned __int8)(a1 >> 1) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 4, ((unsigned __int8)(a1 >> 1) ^ 1) & 1);
}

original_code:
void canyon_attract_w(offs_t offset,data_t data)
{
        discrete_sound_w(4 + (offset & 0x01), !(offset & 0x02));
}

canonical_original_code:
void canyon_attract_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(4 + (offset & 0x01), !(offset & 0x02));
}


decompiled_code:
__int64 __fastcall canyon_whistle_w(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 2, (a1 >> 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 2, (a1 >> 1) & 1);
}

original_code:
void canyon_whistle_w(offs_t offset,data_t data)
{
        discrete_sound_w(2 + (offset & 0x01), (offset & 0x02) >> 1);
}

canonical_original_code:
void canyon_whistle_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(2 + (offset & 0x01), (offset & 0x02) >> 1);
}


decompiled_code:
__int64 __fastcall canyon_options_r(char a1)
{
int v1; // edi

v1 = a1 & 3;
switch ( v1 )
{
case 2:
return ((unsigned int)input_port_0_r(0LL) >> 2) & 3;
case 3:
return input_port_0_r(0LL) & 3;
case 1:
return ((unsigned int)input_port_0_r(0LL) >> 4) & 3;
}
return (unsigned __int8)input_port_0_r(0LL) >> 6;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
int v1; // edi

v1 = a1 & 3;
switch ( v1 )
{
case 2:
return ((unsigned int)input_port_0_r(0LL) >> 2) & 3;
case 3:
return input_port_0_r(0LL) & 3;
case 1:
return ((unsigned int)input_port_0_r(0LL) >> 4) & 3;
}
return (unsigned __int8)input_port_0_r(0LL) >> 6;
}

original_code:
static data_t canyon_options_r(offs_t offset)
{
 switch (offset & 0x03)
 {
  case 0x00:
   return ((input_port_0_r(0) >> 6) & 0x03);
  case 0x01:
   return ((input_port_0_r(0) >> 4) & 0x03);
  case 0x02:
   return ((input_port_0_r(0) >> 2) & 0x03);
  case 0x03:
   return ((input_port_0_r(0) >> 0) & 0x03);
 }
 return 0xFF;
}

canonical_original_code:
static unsigned int canyon_options_r(unsigned int offset)
{
 switch (offset & 0x03)
 {
  case 0x00:
   return ((input_port_0_r(0) >> 6) & 0x03);
  case 0x01:
   return ((input_port_0_r(0) >> 4) & 0x03);
  case 0x02:
   return ((input_port_0_r(0) >> 2) & 0x03);
  case 0x03:
   return ((input_port_0_r(0) >> 0) & 0x03);
 }
 return 0xFF;
}


decompiled_code:
__int64 canyon_switches_r()
{
return (unsigned __int8)((unsigned __int8)input_port_3_r(0LL) << 7);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int8)((unsigned __int8)input_port_3_r(0LL) << 7);
}

original_code:
static data_t canyon_switches_r(offs_t offset)
{
 switch (offset & 0x07)
 {
  case 0x00:
   return ((input_port_3_r(0) << 7) & 0x80);
  case 0x01:
   return ((input_port_3_r(0) << 6) & 0x80);
  case 0x02:
   return ((input_port_3_r(0) << 5) & 0x80) | input_port_1_r(0);
  case 0x03:
   return ((input_port_3_r(0) << 4) & 0x80) | input_port_2_r(0);
  case 0x04:
   return ((input_port_3_r(0) << 3) & 0x80);
  case 0x05:
   return ((input_port_3_r(0) << 2) & 0x80);
  case 0x06:
   return ((input_port_3_r(0) << 1) & 0x80) | input_port_1_r(0);
  case 0x07:
   return ((input_port_3_r(0) << 0) & 0x80) | input_port_2_r(0);
 }
 return 0xFF;
}

canonical_original_code:
static unsigned int canyon_switches_r(unsigned int offset)
{
 switch (offset & 0x07)
 {
  case 0x00:
   return ((input_port_3_r(0) << 7) & 0x80);
  case 0x01:
   return ((input_port_3_r(0) << 6) & 0x80);
  case 0x02:
   return ((input_port_3_r(0) << 5) & 0x80) | input_port_1_r(0);
  case 0x03:
   return ((input_port_3_r(0) << 4) & 0x80) | input_port_2_r(0);
  case 0x04:
   return ((input_port_3_r(0) << 3) & 0x80);
  case 0x05:
   return ((input_port_3_r(0) << 2) & 0x80);
  case 0x06:
   return ((input_port_3_r(0) << 1) & 0x80) | input_port_1_r(0);
  case 0x07:
   return ((input_port_3_r(0) << 0) & 0x80) | input_port_2_r(0);
 }
 return 0xFF;
}


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

switch ( a1 )
{
case 0:
ddragon3_fg_scrollx = a2;
break;
case 2:
ddragon3_fg_scrolly = a2;
break;
case 4:
ddragon3_bg_scrollx = a2;
break;
case 6:
ddragon3_bg_scrolly = a2;
break;
case 12:
result = (unsigned __int16)(ddragon3_bg_tilebase & HIWORD(a2));
ddragon3_bg_tilebase = (result | a2) & 0x1FF;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
ddragon3_fg_scrollx = a2;
break;
case 2:
ddragon3_fg_scrolly = a2;
break;
case 4:
ddragon3_bg_scrollx = a2;
break;
case 6:
ddragon3_bg_scrolly = a2;
break;
case 12:
result = (unsigned __int16)(ddragon3_bg_tilebase & HIWORD(a2));
ddragon3_bg_tilebase = (result | a2) & 0x1FF;
break;
default:
return result;
}
return result;
}

original_code:
void ddragon3_scroll_w(offs_t offset,data_t data){
 switch (offset) {
  case 0x0:
  ddragon3_fg_scrollx = data;
  return;
  case 0x2:
  ddragon3_fg_scrolly = data;
  return;
  case 0x4:
  ddragon3_bg_scrollx = data;
  return;
  case 0x6:
  ddragon3_bg_scrolly = data;
  return;
  case 0xc:
  ddragon3_bg_tilebase = (((ddragon3_bg_tilebase) & ((data) >> 16)) | ((data) & 0xffff))&0x1ff;
  return;
  default:
  break;
 }
}

canonical_original_code:
void ddragon3_scroll_w(unsigned int offset, unsigned int data){
 switch (offset) {
  case 0x0:
  ddragon3_fg_scrollx = data;
  return;
  case 0x2:
  ddragon3_fg_scrolly = data;
  return;
  case 0x4:
  ddragon3_bg_scrollx = data;
  return;
  case 0x6:
  ddragon3_bg_scrolly = data;
  return;
  case 0xc:
  ddragon3_bg_tilebase = (((ddragon3_bg_tilebase) & ((data) >> 16)) | ((data) & 0xffff))&0x1ff;
  return;
  default:
  break;
 }
}


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

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall ddragon3_bg_videoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ddragon3_bg_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(background, a1 >> 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ddragon3_bg_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(background, a1 >> 1);
}
return result;
}

original_code:
void ddragon3_bg_videoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&ddragon3_bg_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if( oldword != newword )
 {
  (*(UINT16 *)(&ddragon3_bg_videoram[offset]) = (newword));
  offset = offset/2;
  tilemap_mark_tile_dirty(background,offset);
 }
}

canonical_original_code:
void ddragon3_bg_videoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&ddragon3_bg_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if( oldword != newword )
 {
  (*(unsigned short *)(&ddragon3_bg_videoram[offset]) = (newword));
  offset = offset/2;
  tilemap_mark_tile_dirty(background,offset);
 }
}

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 __fastcall ddragon3_fg_videoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ddragon3_fg_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(foreground, a1 >> 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ddragon3_fg_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(foreground, a1 >> 2);
}
return result;
}

original_code:
void ddragon3_fg_videoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&ddragon3_fg_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if( oldword != newword )
 {
  (*(UINT16 *)(&ddragon3_fg_videoram[offset]) = (newword));
  offset = offset/4;
  tilemap_mark_tile_dirty(foreground,offset);
 }
}

canonical_original_code:
void ddragon3_fg_videoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&ddragon3_fg_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if( oldword != newword )
 {
  (*(unsigned short *)(&ddragon3_fg_videoram[offset]) = (newword));
  offset = offset/4;
  tilemap_mark_tile_dirty(foreground,offset);
 }
}


decompiled_code:
__int64 ddragon3_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-18h]

old_ddragon3_bg_tilebase = -1;
ddragon3_bg_tilebase = 0;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v3) = 32;
background = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v3);
foreground = v1;
if ( !background || !v1 )
return 1LL;
*(_DWORD *)(v1 + 132) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v3; // [rsp+0h] [rbp-18h]

old_ddragon3_bg_tilebase = -1;
ddragon3_bg_tilebase = 0;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v3) = 32;
background = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v3);
foreground = v1;
if ( !background || !v1 )
return 1LL;
*(_DWORD *)(v1 + 132) = 0;
return 0LL;
}

original_code:
int ddragon3_vh_start(void){
 ddragon3_bg_tilebase = 0;
 old_ddragon3_bg_tilebase = -1;
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 if (!background || !foreground)
  return 1;
 foreground->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int ddragon3_vh_start(){
 ddragon3_bg_tilebase = 0;
 old_ddragon3_bg_tilebase = -1;
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 if (!background || !foreground)
  return 1;
 foreground->transparent_pen = 0;
 return 0;
}


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

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

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

variable_types: irq int


decompiled_code:
__int64 __fastcall oki_bankswitch_w(__int64 a1, char a2)
{
return OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (unsigned __int8)(a2 & 1) << 18);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char a2)
{
return OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (unsigned __int8)(a2 & 1) << 18);
}

original_code:
static void oki_bankswitch_w(offs_t offset,data_t data)
{
 OKIM6295_set_bank_base(0, -1, (data & 1) * 0x40000);
}

canonical_original_code:
static void oki_bankswitch_w(unsigned int offset, unsigned int data)
{
 OKIM6295_set_bank_base(0, -1, (data & 1) * 0x40000);
}


decompiled_code:
__int64 ddragon3_cpu_interrupt()
{
return (unsigned int)((unsigned int)cpu_getiloops() == 0) + 5;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)((unsigned int)cpu_getiloops() == 0) + 5;
}

original_code:
static int ddragon3_cpu_interrupt(void) {
 if( cpu_getiloops() == 0 ){
  return 6;
 }
 else {
  return 5;
 }
 return 0;
}

canonical_original_code:
static int ddragon3_cpu_interrupt() {
 if( cpu_getiloops() == 0 ){
  return 6;
 }
 else {
  return 5;
 }
 return 0;
}