decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r14
__int64 v3; // rbp
unsigned int v4; // er13
unsigned int v5; // ebx
__int64 v6; // r15
unsigned __int8 v7; // bl
unsigned __int8 v8; // r12
unsigned int v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+Ch] [rbp-3Ch]

result = (unsigned int)(lsasquad_spriteram_size - 4);
v10 = lsasquad_spriteram_size - 4;
if ( lsasquad_spriteram_size - 4 >= 0 )
{
v2 = (int)result + 3LL;
do
{
v3 = *(unsigned __int8 *)(lsasquad_spriteram + v2);
v6 = *(unsigned __int8 *)(lsasquad_spriteram + v2 - 3);
v7 = *(_BYTE *)(lsasquad_spriteram + v2 - 2);
v9 = *(unsigned __int8 *)(lsasquad_spriteram + v2 - 1) + ((16 * v7) & 0x300);
v8 = v7 & 0xF;
v4 = v7 & 0x40;
v5 = v7 & 0x80;
if ( flip_screen_x )
{
v3 = (unsigned int)(240 - v3);
v4 = v4 == 0;
v5 = v5 == 0;
}
else
{
v6 = (unsigned int)(240 - v6);
}
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v9, v8, v4, v5, v3, v6, Machine + 776LL, 2LL, 0LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9,
v8,
v4,
v5,
(unsigned int)(v3 - 256),
v6,
Machine + 776LL,
2LL,
0LL);
v2 -= 4LL;
v10 -= 4;
}
while ( v10 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r14
__int64 v3; // rbp
unsigned int v4; // er13
unsigned int v5; // ebx
__int64 v6; // r15
unsigned __int8 v7; // bl
unsigned __int8 v8; // r12
unsigned int v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+Ch] [rbp-3Ch]

result = (unsigned int)(lsasquad_spriteram_size - 4);
v10 = lsasquad_spriteram_size - 4;
if ( lsasquad_spriteram_size - 4 >= 0 )
{
v2 = (int)result + 3LL;
do
{
v3 = *(unsigned __int8 *)(lsasquad_spriteram + v2);
v6 = *(unsigned __int8 *)(lsasquad_spriteram + v2 - 3);
v7 = *(_BYTE *)(lsasquad_spriteram + v2 - 2);
v9 = *(unsigned __int8 *)(lsasquad_spriteram + v2 - 1) + ((16 * v7) & 0x300);
v8 = v7 & 0xF;
v4 = v7 & 0x40;
v5 = v7 & 0x80;
if ( flip_screen_x )
{
v3 = (unsigned int)(240 - v3);
v4 = v4 == 0;
v5 = v5 == 0;
}
else
{
v6 = (unsigned int)(240 - v6);
}
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v9, v8, v4, v5, v3, v6, Machine + 776LL, 2LL, 0LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9,
v8,
v4,
v5,
(unsigned int)(v3 - 256),
v6,
Machine + 776LL,
2LL,
0LL);
v2 -= 4LL;
v10 -= 4;
}
while ( v10 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = lsasquad_spriteram_size-4;offs >= 0;offs -= 4)
 {
  int sx,sy,attr,code,color,flipx,flipy;
  sx = lsasquad_spriteram[offs+3];
  sy = 240 - lsasquad_spriteram[offs];
  attr = lsasquad_spriteram[offs+1];
  code = lsasquad_spriteram[offs+2] + ((attr & 0x30) << 4);
  color = attr & 0x0f;
  flipx = attr & 0x40;
  flipy = attr & 0x80;
  if (flip_screen_x)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx-256,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = lsasquad_spriteram_size-4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int attr; int code; int color; int flipx; int flipy;
  sx = lsasquad_spriteram[offs+3];
  sy = 240 - lsasquad_spriteram[offs];
  attr = lsasquad_spriteram[offs+1];
  code = lsasquad_spriteram[offs+2] + ((attr & 0x30) << 4);
  color = attr & 0x0f;
  flipx = attr & 0x40;
  flipy = attr & 0x80;
  if (flip_screen_x)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx-256,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sx int

variable_types: attr int

variable_types: code int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 __fastcall draw_layer(__int64 a1, char *a2)
{
unsigned __int8 v2; // r13
__int64 v3; // rbp
unsigned __int8 v4; // bl
int v5; // er15
unsigned int v6; // er12
__int64 result; // rax
int v8; // eax
unsigned __int8 v9; // cl
__int64 v10; // r14
__int64 v11; // [rsp+10h] [rbp-58h]
__int64 i; // [rsp+18h] [rbp-50h]
char v13; // [rsp+23h] [rbp-45h]
char v14; // [rsp+24h] [rbp-44h]

v14 = a2[3];
v13 = *a2;
for ( i = 0LL; i != 128; result = i )
{
v8 = (unsigned __int8)a2[i + 1] << 6;
v9 = v14 + 8 * ((int)i / 4);
if ( flip_screen_x )
v9 = -8 - (v14 + 8 * ((int)i / 4));
v10 = v9;
v2 = v13 - 8;
v3 = v8 + 1;
v11 = v8 + 65;
do
{
v4 = -8 - v2;
if ( flip_screen_x )
v4 = v2;
v5 = (int)*(unsigned __int8 *)(lsasquad_videoram + v3) >> 4;
v6 = ((*(unsigned __int8 *)(lsasquad_videoram + v3) << 8) & 0xF00)
+ *(unsigned __int8 *)(lsasquad_videoram + v3 - 1);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v6,
v5,
flip_screen_x,
flip_screen_x,
v10,
v4,
Machine + 776LL,
2LL,
0LL);
if ( (int)v10 > 248 )
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v6,
(unsigned int)v5,
flip_screen_x,
flip_screen_x,
(unsigned int)(v10 - 256),
v4,
Machine + 776LL,
2LL,
0LL);
v2 -= 8;
v3 += 2LL;
}
while ( v3 != v11 );
i += 4LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, char *a2)
{
unsigned __int8 v2; // r13
__int64 v3; // rbp
unsigned __int8 v4; // bl
int v5; // er15
unsigned int v6; // er12
__int64 result; // rax
int v8; // eax
unsigned __int8 v9; // cl
__int64 v10; // r14
__int64 v11; // [rsp+10h] [rbp-58h]
__int64 i; // [rsp+18h] [rbp-50h]
char v13; // [rsp+23h] [rbp-45h]
char v14; // [rsp+24h] [rbp-44h]

v14 = a2[3];
v13 = *a2;
for ( i = 0LL; i != 128; result = i )
{
v8 = (unsigned __int8)a2[i + 1] << 6;
v9 = v14 + 8 * ((int)i / 4);
if ( flip_screen_x )
v9 = -8 - (v14 + 8 * ((int)i / 4));
v10 = v9;
v2 = v13 - 8;
v3 = v8 + 1;
v11 = v8 + 65;
do
{
v4 = -8 - v2;
if ( flip_screen_x )
v4 = v2;
v5 = (int)*(unsigned __int8 *)(lsasquad_videoram + v3) >> 4;
v6 = ((*(unsigned __int8 *)(lsasquad_videoram + v3) << 8) & 0xF00)
+ *(unsigned __int8 *)(lsasquad_videoram + v3 - 1);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v6,
v5,
flip_screen_x,
flip_screen_x,
v10,
v4,
Machine + 776LL,
2LL,
0LL);
if ( (int)v10 > 248 )
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v6,
(unsigned int)v5,
flip_screen_x,
flip_screen_x,
(unsigned int)(v10 - 256),
v4,
Machine + 776LL,
2LL,
0LL);
v2 -= 8;
v3 += 2LL;
}
while ( v3 != v11 );
i += 4LL;
}
return result;
}

original_code:
static void draw_layer(struct osd_bitmap *bitmap,unsigned char *scrollram)
{
 int offs,scrollx,scrolly;
 scrollx = scrollram[3];
 scrolly = -scrollram[0];
 for (offs = 0;offs < 0x080;offs += 4)
 {
  int base,y,sx,sy,code,color;
  base = 64 * scrollram[offs+1];
  sx = 8*(offs/4) + scrollx;
  if (flip_screen_x) sx = 248 - sx;
  sx &= 0xff;
  for (y = 0;y < 32;y++)
  {
   int attr;
   sy = 8*y + scrolly;
   if (flip_screen_x) sy = 248 - sy;
   sy &= 0xff;
   attr = lsasquad_videoram[base + 2*y + 1];
   code = lsasquad_videoram[base + 2*y] + ((attr & 0x0f) << 8);
   color = attr >> 4;
   drawgfx(bitmap,Machine->gfx[0],
     code,
     color,
     flip_screen_x,flip_screen_x,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (sx > 248)
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flip_screen_x,flip_screen_x,
      sx-256,sy,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
static void draw_layer(struct osd_bitmap *bitmap, unsigned char *scrollram)
{
 int offs; int scrollx; int scrolly;
 scrollx = scrollram[3];
 scrolly = -scrollram[0];
 for (offs = 0;offs < 0x080;offs += 4)
 {
  int base; int y; int sx; int sy; int code; int color;
  base = 64 * scrollram[offs+1];
  sx = 8*(offs/4) + scrollx;
  if (flip_screen_x) sx = 248 - sx;
  sx &= 0xff;
  for (y = 0;y < 32;y++)
  {
   int attr;
   sy = 8*y + scrolly;
   if (flip_screen_x) sy = 248 - sy;
   sy &= 0xff;
   attr = lsasquad_videoram[base + 2*y + 1];
   code = lsasquad_videoram[base + 2*y] + ((attr & 0x0f) << 8);
   color = attr >> 4;
   drawgfx(bitmap,Machine->gfx[0],
     code,
     color,
     flip_screen_x,flip_screen_x,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (sx > 248)
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flip_screen_x,flip_screen_x,
      sx-256,sy,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

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

variable_types:
scrollram
unsigned char *

variable_types: scrollx int

variable_types: scrolly int

variable_types: base int

variable_types: y int

variable_types: sy int

variable_types: color int

return_type: void


decompiled_code:
__int64 __fastcall is_joy_axis_pressed(int a1, int a2, char a3)
{
__int64 result; // rax
unsigned int v4; // edx
unsigned int v5; // edx
unsigned int v6; // edx
unsigned int v7; // edx

result = rotate_controls;
if ( rotate_controls )
{
if ( a1 )
{
result = a3 & 0x40;
if ( a2 != 1 )
{
v7 = a3 & 4;
result = 0LL;
if ( a2 == 2 )
result = v7;
}
}
else
{
result = a3 & 1;
if ( a2 != 1 )
{
v6 = a3 & 0x10;
result = 0LL;
if ( a2 == 2 )
result = v6;
}
}
}
else if ( a1 )
{
if ( a2 == 1 )
{
result = a3 & 1;
}
else
{
v5 = a3 & 0x10;
if ( a2 == 2 )
result = v5;
}
}
else
{
result = a3 & 4;
if ( a2 != 1 )
{
v4 = a3 & 0x40;
result = 0LL;
if ( a2 == 2 )
result = v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, char a3)
{
__int64 result; // rax
unsigned int v4; // edx
unsigned int v5; // edx
unsigned int v6; // edx
unsigned int v7; // edx

result = rotate_controls;
if ( rotate_controls )
{
if ( a1 )
{
result = a3 & 0x40;
if ( a2 != 1 )
{
v7 = a3 & 4;
result = 0LL;
if ( a2 == 2 )
result = v7;
}
}
else
{
result = a3 & 1;
if ( a2 != 1 )
{
v6 = a3 & 0x10;
result = 0LL;
if ( a2 == 2 )
result = v6;
}
}
}
else if ( a1 )
{
if ( a2 == 1 )
{
result = a3 & 1;
}
else
{
v5 = a3 & 0x10;
if ( a2 == 2 )
result = v5;
}
}
else
{
result = a3 & 4;
if ( a2 != 1 )
{
v4 = a3 & 0x40;
result = 0LL;
if ( a2 == 2 )
result = v4;
}
}
return result;
}

original_code:
static int is_joy_axis_pressed (int axis, int dir, int ExKey)
{
 extern int rotate_controls;
 if (!rotate_controls)
 {
  if (axis==0)
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_LEFT; break;
    case 2: return ExKey & GP2X_RIGHT; break;
    default: return 0; break;
   }
  }
  else
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_UP; break;
    case 2: return ExKey & GP2X_DOWN; break;
    default: return 0; break;
   }
  }
 }
 else
 {
  if (axis==0)
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_UP; break;
    case 2: return ExKey & GP2X_DOWN; break;
    default: return 0; break;
   }
  }
  else
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_RIGHT; break;
    case 2: return ExKey & GP2X_LEFT; break;
    default: return 0; break;
   }
  }
 }
 return 0;
}

canonical_original_code:
static int is_joy_axis_pressed(int axis, int dir, int ExKey)
{
 extern int rotate_controls;
 if (!rotate_controls)
 {
  if (axis==0)
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_LEFT; break;
    case 2: return ExKey & GP2X_RIGHT; break;
    default: return 0; break;
   }
  }
  else
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_UP; break;
    case 2: return ExKey & GP2X_DOWN; break;
    default: return 0; break;
   }
  }
 }
 else
 {
  if (axis==0)
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_UP; break;
    case 2: return ExKey & GP2X_DOWN; break;
    default: return 0; break;
   }
  }
  else
  {
   switch (dir)
   {
    case 1: return ExKey & GP2X_RIGHT; break;
    case 2: return ExKey & GP2X_LEFT; break;
    default: return 0; break;
   }
  }
 }
 return 0;
}

variable_types: axis int

variable_types: dir int

variable_types: ExKey int

return_type: int


decompiled_code:
char **osd_get_key_list()
{
return &keylist;
}

canonical_decompiled_code:
char **func1()
{
return &keylist;
}

original_code:
const struct KeyboardInfo *osd_get_key_list(void)
{
 return keylist;
}

canonical_original_code:
struct KeyboardInfo *osd_get_key_list()
{
 return keylist;
}

return_type: struct KeyboardInfo { char *name; unsigned int code; unsigned int standardcode; } *


decompiled_code:
__int64 __fastcall osd_is_key_pressed(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // ecx

result = 0LL;
if ( a1 <= 127 )
{
if ( a1 == 123 )
{
v2 = key[123];
result = pressed_1 ^ (unsigned int)v2;
if ( v2 != pressed_1 )
{
v3 = counter_0;
if ( counter_0 <= 0 )
{
counter_0 = 10;
}
else
{
--counter_0;
if ( v3 == 1 )
pressed_1 = v2;
}
}
}
else
{
result = key[a1];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // ecx

result = 0LL;
if ( a1 <= 127 )
{
if ( a1 == 123 )
{
v2 = key[123];
result = pressed_1 ^ (unsigned int)v2;
if ( v2 != pressed_1 )
{
v3 = counter_0;
if ( counter_0 <= 0 )
{
counter_0 = 10;
}
else
{
--counter_0;
if ( v3 == 1 )
pressed_1 = v2;
}
}
}
else
{
result = key[a1];
}
}
return result;
}

original_code:
int osd_is_key_pressed(int keycode)
{
 if (keycode >= 128) return 0;
 if (keycode == 123)
 {
  static int pressed,counter;
  int res;
  res = key[123] ^ pressed;
  if (res)
  {
   if (counter > 0)
   {
    if (--counter == 0)
     pressed = key[123];
   }
   else counter = 10;
  }
  return res;
 }
 return key[keycode];
}

canonical_original_code:
int osd_is_key_pressed(int keycode)
{
 if (keycode >= 128) return 0;
 if (keycode == 123)
 {
  static int pressed; static int counter;
  int res;
  res = key[123] ^ pressed;
  if (res)
  {
   if (counter > 0)
   {
    if (--counter == 0)
     pressed = key[123];
   }
   else counter = 10;
  }
  return res;
 }
 return key[keycode];
}

variable_types: keycode int

variable_types: pressed int

variable_types: counter int

variable_types: res int


decompiled_code:
__int64 osd_readkey_unicode()
{
return 0LL;
}

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

original_code:
int osd_readkey_unicode(int flush)
{
 return 0;
}

variable_types: flush int


decompiled_code:
void *init_joy_list()
{
int v0; // er13
__int64 v1; // r14
int i; // edx
unsigned int v3; // ebx
char *v4; // rbp
void *result; // rax
char *v6; // rdx
char v7[312]; // [rsp+0h] [rbp-138h] BYREF

v0 = 10;
v1 = 0LL;
for ( i = 0; num_joysticks > (int)v1; v0 += 10 )
{
v3 = v0 - 10;
v4 = (char *)&joylist + 160 * v1;
do
{
sprintf(v7, "JS %d", v3);
*(_QWORD *)v4 = strdup(v7);
*((_DWORD *)v4 + 2) = v3;
*((_DWORD *)v4 + 3) = v3 + 105;
++v3;
v4 += 16;
}
while ( v3 != v0 );
i = v0;
++v1;
}
result = &joylist;
v6 = (char *)&joylist + 16 * i;
*(_QWORD *)v6 = 0LL;
*((_DWORD *)v6 + 2) = 0;
*((_DWORD *)v6 + 3) = 0;
return result;
}

canonical_decompiled_code:
void *func5()
{
int v0; // er13
__int64 v1; // r14
int i; // edx
unsigned int v3; // ebx
char *v4; // rbp
void *result; // rax
char *v6; // rdx
char v7[312]; // [rsp+0h] [rbp-138h] BYREF

v0 = 10;
v1 = 0LL;
for ( i = 0; num_joysticks > (int)v1; v0 += 10 )
{
v3 = v0 - 10;
v4 = (char *)&joylist + 160 * v1;
do
{
sprintf(v7, "JS %d", v3);
*(_QWORD *)v4 = strdup(v7);
*((_DWORD *)v4 + 2) = v3;
*((_DWORD *)v4 + 3) = v3 + 105;
++v3;
v4 += 16;
}
while ( v3 != v0 );
i = v0;
++v1;
}
result = &joylist;
v6 = (char *)&joylist + 16 * i;
*(_QWORD *)v6 = 0LL;
*((_DWORD *)v6 + 2) = 0;
*((_DWORD *)v6 + 3) = 0;
return result;
}

original_code:
void init_joy_list(void)
{
 int tot = 0,i,j;
 char buf[256];
 for (i = 0;i < num_joysticks;i++)
 {
  for (j = 0;j < 10; j++)
  {
   sprintf(buf, "JS %d", i * 10 + j);
   joylist[tot].name = strdup(buf);
   joylist[tot].code = i * 10 + j;
   joylist[tot].standardcode = JOYCODE_1_LEFT + i * 10 + j;
   tot++;
  }
 }
 joylist[tot].name = 0;
 joylist[tot].code = 0;
 joylist[tot].standardcode = 0;
}

canonical_original_code:
void init_joy_list()
{
 int tot = 0; int i; int j;
 char buf[256];
 for (i = 0;i < num_joysticks;i++)
 {
  for (j = 0;j < 10; j++)
  {
   sprintf(buf, "JS %d", i * 10 + j);
   joylist[tot].name = strdup(buf);
   joylist[tot].code = i * 10 + j;
   joylist[tot].standardcode = JOYCODE_1_LEFT + i * 10 + j;
   tot++;
  }
 }
 joylist[tot].name = 0;
 joylist[tot].code = 0;
 joylist[tot].standardcode = 0;
}

variable_types: tot int

variable_types: i int

variable_types: j int

variable_types:
buf
char [256]


decompiled_code:
void *osd_get_joy_list()
{
return &joylist;
}

canonical_decompiled_code:
void *func6()
{
return &joylist;
}

original_code:
const struct JoystickInfo *osd_get_joy_list(void)
{
 return joylist;
}

canonical_original_code:
struct JoystickInfo *osd_get_joy_list()
{
 return joylist;
}

return_type: struct JoystickInfo { char *name; unsigned int code; unsigned int standardcode; } *


decompiled_code:
__int64 __fastcall osd_is_joy_pressed(int a1)
{
return joy_pressed[a1];
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return joy_pressed[a1];
}

original_code:
int osd_is_joy_pressed(int joycode)
{
 return joy_pressed[joycode];
}

variable_types: joycode int


decompiled_code:
__int64 osd_joystick_needs_calibration()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0LL;
}

original_code:
int osd_joystick_needs_calibration (void)
{
 return 0;
}

canonical_original_code:
int osd_joystick_needs_calibration()
{
 return 0;
}


decompiled_code:
void osd_joystick_start_calibration()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void osd_joystick_start_calibration (void)
{
}

canonical_original_code:
void osd_joystick_start_calibration()
{
}


decompiled_code:
__int64 osd_joystick_calibrate_next()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
return 0LL;
}

original_code:
char *osd_joystick_calibrate_next (void)
{
 return 0;
}

canonical_original_code:
char *osd_joystick_calibrate_next()
{
 return 0;
}

return_type: char *


decompiled_code:
void osd_joystick_calibrate()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void osd_joystick_calibrate (void)
{
}

canonical_original_code:
void osd_joystick_calibrate()
{
}


decompiled_code:
void osd_joystick_end_calibration()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void osd_joystick_end_calibration (void)
{
}

canonical_original_code:
void osd_joystick_end_calibration()
{
}


decompiled_code:
void osd_customize_inputport_defaults()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void osd_customize_inputport_defaults(struct ipd *defaults)
{
}

variable_types: struct ipd { unsigned int type; char *name; unsigned int seq[16]; } *


decompiled_code:
void osd_led_w()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void osd_led_w(int led,int on) {
}

canonical_original_code:
void osd_led_w(int led, int on) {
}

variable_types: led int

variable_types: on int


decompiled_code:
_DWORD *msdos_init_input()
{
unsigned int *v0; // rax
_DWORD *result; // rax

v0 = key;
do
*v0++ = 0;
while ( v0 != &key[128] );
if ( joystick )
logerror("Installed %s %s\n", "Joystick", "GP2X");
else
logerror("Joystick not found\n");
init_joy_list();
result = &use_mouse;
use_mouse = use_mouse != 0;
return result;
}

canonical_decompiled_code:
_DWORD *func18()
{
unsigned int *v0; // rax
_DWORD *result; // rax

v0 = key;
do
*v0++ = 0;
while ( v0 != &key[128] );
if ( joystick )
logerror("Installed %s %s\n", "Joystick", "GP2X");
else
logerror("Joystick not found\n");
func5();
result = &use_mouse;
use_mouse = use_mouse != 0;
return result;
}

original_code:
void msdos_init_input (void)
{
 int i;
 for (i = 0;i < 128;i++)
 {
  key[i]=0;
 }
 if (joystick == 0)
  logerror("Joystick not found\n");
 else
  logerror("Installed %s %s\n","Joystick", "GP2X");
 init_joy_list();
 if (use_mouse)
  use_mouse = 1;
 else
  use_mouse = 0;
}

canonical_original_code:
void msdos_init_input()
{
 int i;
 for (i = 0;i < 128;i++)
 {
  key[i]=0;
 }
 if (joystick == 0)
  logerror("Joystick not found\n");
 else
  logerror("Installed %s %s\n","Joystick", "GP2X");
 init_joy_list();
 if (use_mouse)
  use_mouse = 1;
 else
  use_mouse = 0;
}


decompiled_code:
void msdos_shutdown_input()
{
;
}

canonical_decompiled_code:
void func19()
{
;
}

original_code:
void msdos_shutdown_input(void)
{
}

canonical_original_code:
void msdos_shutdown_input()
{
}


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

result = (unsigned int)(a1 - 101);
if ( (unsigned int)result <= 0x11 )
{
version = a1;
v2 = (__int64)&slapstic_table + 48 * a1 - 4848;
slapstic = v2;
state = 0;
extra_bank = -1;
next_bank = -1;
LOBYTE(v2) = a1 <= 110;
result = (unsigned int)(3 * v2);
current_bank = result;
}
return result;
}

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

result = (unsigned int)(a1 - 101);
if ( (unsigned int)result <= 0x11 )
{
version = a1;
v2 = (__int64)&slapstic_table + 48 * a1 - 4848;
slapstic = v2;
state = 0;
extra_bank = -1;
next_bank = -1;
LOBYTE(v2) = a1 <= 110;
result = (unsigned int)(3 * v2);
current_bank = result;
}
return result;
}

original_code:
void slapstic_init(int chip)
{
 if (chip < 101 || chip > 118)
  return;
 version = chip;
 slapstic = slapstic_table + (chip - 101);
 state = ENABLED;
 next_bank = extra_bank = -1;
 if (chip < 111)
  current_bank = 3;
 else
  current_bank = 0;
}

variable_types: chip int


decompiled_code:
__int64 slapstic_reset()
{
return slapstic_init((unsigned __int8)version);
}

canonical_decompiled_code:
__int64 func1()
{
return func0((unsigned __int8)version);
}

original_code:
void slapstic_reset(void)
{
 slapstic_init(version);
}

canonical_original_code:
void slapstic_reset()
{
 slapstic_init(version);
}


decompiled_code:
__int64 slapstic_bank()
{
return (unsigned int)current_bank;
}

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

original_code:
int slapstic_bank(void)
{
 return current_bank;
}

canonical_original_code:
int slapstic_bank()
{
 return current_bank;
}


decompiled_code:
__int64 __fastcall slapstic_tweak(int a1)
{
char v2; // al
char v3; // al
char v4; // al
char v5; // al

if ( next_bank != -1 )
{
current_bank = next_bank;
next_bank = -1;
extra_bank = -1;
}
if ( state == 2 )
{
if ( *(_DWORD *)(slapstic + 28) == a1 )
state = 3;
else
state = 0;
}
else if ( (unsigned int)state > 2 )
{
if ( state == 3 )
{
if ( *(_DWORD *)(slapstic + 32) == a1 )
{
state = 0;
extra_bank = 0;
}
else if ( *(_DWORD *)(slapstic + 36) == a1 )
{
state = 0;
extra_bank = 1;
}
else if ( *(_DWORD *)(slapstic + 40) == a1 )
{
state = 0;
extra_bank = 2;
}
else if ( *(_DWORD *)(slapstic + 44) == a1 )
{
state = 0;
extra_bank = 3;
}
else if ( *(_DWORD *)slapstic == a1 )
{
state = 0;
next_bank = -1;
extra_bank = -1;
}
else
{
state = 0;
}
}
}
else if ( state )
{
if ( *(_DWORD *)slapstic == a1 )
{
state = 0;
next_bank = -1;
extra_bank = -1;
}
}
else if ( (a1 & 0x3FF0) == *(_DWORD *)(slapstic + 20) )
{
state = 1;
if ( extra_bank != -1 )
next_bank = extra_bank;
}
else if ( (a1 & 0x7F) == *(_DWORD *)(slapstic + 24) )
{
state = 2;
}
else if ( *(_DWORD *)(slapstic + 4) == a1 )
{
state = 1;
v2 = extra_bank;
if ( extra_bank == -1 )
v2 = 0;
next_bank = v2;
}
else if ( *(_DWORD *)(slapstic + 8) == a1 )
{
state = 1;
v3 = extra_bank;
if ( extra_bank == -1 )
v3 = 1;
next_bank = v3;
}
else if ( *(_DWORD *)(slapstic + 12) == a1 )
{
state = 1;
v4 = extra_bank;
if ( extra_bank == -1 )
v4 = 2;
next_bank = v4;
}
else if ( *(_DWORD *)(slapstic + 16) == a1 )
{
state = 1;
v5 = extra_bank;
if ( extra_bank == -1 )
v5 = 3;
next_bank = v5;
}
else if ( *(_DWORD *)slapstic == a1 )
{
next_bank = -1;
extra_bank = -1;
}
else if ( *(_DWORD *)(slapstic + 28) == a1 )
{
state = 3;
}
return (unsigned int)current_bank;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
char v2; // al
char v3; // al
char v4; // al
char v5; // al

if ( next_bank != -1 )
{
current_bank = next_bank;
next_bank = -1;
extra_bank = -1;
}
if ( state == 2 )
{
if ( *(_DWORD *)(slapstic + 28) == a1 )
state = 3;
else
state = 0;
}
else if ( (unsigned int)state > 2 )
{
if ( state == 3 )
{
if ( *(_DWORD *)(slapstic + 32) == a1 )
{
state = 0;
extra_bank = 0;
}
else if ( *(_DWORD *)(slapstic + 36) == a1 )
{
state = 0;
extra_bank = 1;
}
else if ( *(_DWORD *)(slapstic + 40) == a1 )
{
state = 0;
extra_bank = 2;
}
else if ( *(_DWORD *)(slapstic + 44) == a1 )
{
state = 0;
extra_bank = 3;
}
else if ( *(_DWORD *)slapstic == a1 )
{
state = 0;
next_bank = -1;
extra_bank = -1;
}
else
{
state = 0;
}
}
}
else if ( state )
{
if ( *(_DWORD *)slapstic == a1 )
{
state = 0;
next_bank = -1;
extra_bank = -1;
}
}
else if ( (a1 & 0x3FF0) == *(_DWORD *)(slapstic + 20) )
{
state = 1;
if ( extra_bank != -1 )
next_bank = extra_bank;
}
else if ( (a1 & 0x7F) == *(_DWORD *)(slapstic + 24) )
{
state = 2;
}
else if ( *(_DWORD *)(slapstic + 4) == a1 )
{
state = 1;
v2 = extra_bank;
if ( extra_bank == -1 )
v2 = 0;
next_bank = v2;
}
else if ( *(_DWORD *)(slapstic + 8) == a1 )
{
state = 1;
v3 = extra_bank;
if ( extra_bank == -1 )
v3 = 1;
next_bank = v3;
}
else if ( *(_DWORD *)(slapstic + 12) == a1 )
{
state = 1;
v4 = extra_bank;
if ( extra_bank == -1 )
v4 = 2;
next_bank = v4;
}
else if ( *(_DWORD *)(slapstic + 16) == a1 )
{
state = 1;
v5 = extra_bank;
if ( extra_bank == -1 )
v5 = 3;
next_bank = v5;
}
else if ( *(_DWORD *)slapstic == a1 )
{
next_bank = -1;
extra_bank = -1;
}
else if ( *(_DWORD *)(slapstic + 28) == a1 )
{
state = 3;
}
return (unsigned int)current_bank;
}

original_code:
int slapstic_tweak(offs_t offset)
{
 if (next_bank != -1)
 {
  current_bank = next_bank;
  next_bank = -1;
  extra_bank = -1;
 }
 switch (state)
 {
  case ENABLED:
   if ((offset & 0x3ff0) == slapstic->disable)
   {
    state = DISABLED;
    if (extra_bank != -1)
     next_bank = extra_bank;
   }
   else if ((offset & 0x007f) == slapstic->ignore)
   {
    state = IGNORE;
   }
   else if (offset == slapstic->bank0)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 0;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->bank1)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 1;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->bank2)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 2;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->bank3)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 3;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->reset)
   {
    next_bank = -1;
    extra_bank = -1;
   }
   else if (offset == slapstic->senable)
   {
    state = SPECIAL;
   }
   break;
  case DISABLED:
   if (offset == slapstic->reset)
   {
    state = ENABLED;
    next_bank = -1;
    extra_bank = -1;
   }
   break;
  case IGNORE:
   if (offset == slapstic->senable)
   {
    state = SPECIAL;
   }
   else
   {
    state = ENABLED;
   }
   break;
  case SPECIAL:
   if (offset == slapstic->sbank0)
   {
    state = ENABLED;
    extra_bank = 0;
   }
   else if (offset == slapstic->sbank1)
   {
    state = ENABLED;
    extra_bank = 1;
   }
   else if (offset == slapstic->sbank2)
   {
    state = ENABLED;
    extra_bank = 2;
   }
   else if (offset == slapstic->sbank3)
   {
    state = ENABLED;
    extra_bank = 3;
   }
   else if (offset == slapstic->reset)
   {
    state = ENABLED;
    next_bank = -1;
    extra_bank = -1;
   }
   else
   {
    state = ENABLED;
   }
   break;
 }
 ;
 return current_bank;
}

canonical_original_code:
int slapstic_tweak(unsigned int offset)
{
 if (next_bank != -1)
 {
  current_bank = next_bank;
  next_bank = -1;
  extra_bank = -1;
 }
 switch (state)
 {
  case ENABLED:
   if ((offset & 0x3ff0) == slapstic->disable)
   {
    state = DISABLED;
    if (extra_bank != -1)
     next_bank = extra_bank;
   }
   else if ((offset & 0x007f) == slapstic->ignore)
   {
    state = IGNORE;
   }
   else if (offset == slapstic->bank0)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 0;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->bank1)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 1;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->bank2)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 2;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->bank3)
   {
    state = DISABLED;
    if (extra_bank == -1)
     next_bank = 3;
    else
     next_bank = extra_bank;
   }
   else if (offset == slapstic->reset)
   {
    next_bank = -1;
    extra_bank = -1;
   }
   else if (offset == slapstic->senable)
   {
    state = SPECIAL;
   }
   break;
  case DISABLED:
   if (offset == slapstic->reset)
   {
    state = ENABLED;
    next_bank = -1;
    extra_bank = -1;
   }
   break;
  case IGNORE:
   if (offset == slapstic->senable)
   {
    state = SPECIAL;
   }
   else
   {
    state = ENABLED;
   }
   break;
  case SPECIAL:
   if (offset == slapstic->sbank0)
   {
    state = ENABLED;
    extra_bank = 0;
   }
   else if (offset == slapstic->sbank1)
   {
    state = ENABLED;
    extra_bank = 1;
   }
   else if (offset == slapstic->sbank2)
   {
    state = ENABLED;
    extra_bank = 2;
   }
   else if (offset == slapstic->sbank3)
   {
    state = ENABLED;
    extra_bank = 3;
   }
   else if (offset == slapstic->reset)
   {
    state = ENABLED;
    next_bank = -1;
    extra_bank = -1;
   }
   else
   {
    state = ENABLED;
   }
   break;
 }
 ;
 return current_bank;
}

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall route16_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
route16_color_prom = a3;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
route16_color_prom = a3;
}

original_code:
void route16_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 route16_color_prom = color_prom;
}

canonical_original_code:
void route16_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 route16_color_prom = color_prom;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
void init_route16b()
{
route16_hardware = 1;
}

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

original_code:
void init_route16b(void)
{
    route16_hardware = 1;
}


decompiled_code:
void init_stratvox()
{
route16_hardware = 0;
}

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

original_code:
void init_stratvox(void)
{
    route16_hardware = 0;
}


decompiled_code:
void __fastcall route16_out1_w(__int64 a1, int a2)
{
_BOOL4 v2; // eax

if ( last_write_0 != a2 )
{
v2 = 0;
if ( (a2 & 2) != 0 )
v2 = route16_hardware != 0;
video_disable_2 = v2;
video_color_select_2 = (4 * (_BYTE)a2) & 0x7C;
if ( ((a2 & 0x20) != 0) != video_flip )
video_flip = (a2 & 0x20) != 0;
video_remap_2 = 1;
last_write_0 = a2;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
_BOOL4 v2; // eax

if ( last_write_0 != a2 )
{
v2 = 0;
if ( (a2 & 2) != 0 )
v2 = route16_hardware != 0;
video_disable_2 = v2;
video_color_select_2 = (4 * (_BYTE)a2) & 0x7C;
if ( ((a2 & 0x20) != 0) != video_flip )
video_flip = (a2 & 0x20) != 0;
video_remap_2 = 1;
last_write_0 = a2;
}
}

original_code:
void route16_out1_w(offs_t offset,data_t data)
{
 static int last_write = 0;
 if (data == last_write) return;
 video_disable_2 = ((data & 0x02) << 6 ) && route16_hardware;
 video_color_select_2 = ((data & 0x1f) << 2);
 if (video_flip != ((data & 0x20) >> 5))
 {
  video_flip = (data & 0x20) >> 5;
 }
 video_remap_2 = 1;
 last_write = data;
}

canonical_original_code:
void route16_out1_w(unsigned int offset, unsigned int data)
{
 static int last_write = 0;
 if (data == last_write) return;
 video_disable_2 = ((data & 0x02) << 6 ) && route16_hardware;
 video_color_select_2 = ((data & 0x1f) << 2);
 if (video_flip != ((data & 0x20) >> 5))
 {
  video_flip = (data & 0x20) >> 5;
 }
 video_remap_2 = 1;
 last_write = data;
}

variable_types:
data
unsigned int


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

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

original_code:
data_t route16_sharedram_r(offs_t offset)
{
 return route16_sharedram[offset];
}

canonical_original_code:
unsigned int route16_sharedram_r(unsigned int offset)
{
 return route16_sharedram[offset];
}

return_type: unsigned int


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

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

original_code:
data_t route16_videoram2_r(offs_t offset)
{
 return route16_videoram1[offset];
}

canonical_original_code:
unsigned int route16_videoram2_r(unsigned int offset)
{
 return route16_videoram1[offset];
}


decompiled_code:
__int64 __fastcall route16_videoram1_w(unsigned int a1, int a2)
{
*(_BYTE *)(route16_videoram1 + a1) = a2;
return common_videoram_w(a1, a2, 0, tmpbitmap1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
*(_BYTE *)(route16_videoram1 + a1) = a2;
return func7(a1, a2, 0, tmpbitmap1);
}

original_code:
void route16_videoram1_w(offs_t offset,data_t data)
{
 route16_videoram1[offset] = data;
 common_videoram_w(offset, data, 0, tmpbitmap1);
}

canonical_original_code:
void route16_videoram1_w(unsigned int offset, unsigned int data)
{
 route16_videoram1[offset] = data;
 common_videoram_w(offset, data, 0, tmpbitmap1);
}


decompiled_code:
__int64 __fastcall route16_videoram2_w(unsigned int a1, int a2)
{
*(_BYTE *)(route16_videoram2 + a1) = a2;
return common_videoram_w(a1, a2, 4, tmpbitmap2);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
*(_BYTE *)(route16_videoram2 + a1) = a2;
return func7(a1, a2, 4, tmpbitmap2);
}

original_code:
void route16_videoram2_w(offs_t offset,data_t data)
{
 route16_videoram2[offset] = data;
 common_videoram_w(offset, data, 4, tmpbitmap2);
}

canonical_original_code:
void route16_videoram2_w(unsigned int offset, unsigned int data)
{
 route16_videoram2[offset] = data;
 common_videoram_w(offset, data, 4, tmpbitmap2);
}


original_code:
void init_route16(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0x00e9] = 0x3a;
 rom[0x0754] = 0xc3;
 rom[0x0755] = 0x63;
 rom[0x0756] = 0x07;
 init_route16b();
}

canonical_original_code:
void init_route16()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0x00e9] = 0x3a;
 rom[0x0754] = 0xc3;
 rom[0x0755] = 0x63;
 rom[0x0756] = 0x07;
 init_route16b();
}

variable_types:
rom
unsigned char *


decompiled_code:
__int64 route16_vh_start()
{
unsigned int v0; // edx

tmpbitmap1 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v0 = 1;
if ( tmpbitmap1 )
{
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
{
video_flip = 0;
video_color_select_1 = 0;
video_color_select_2 = 0;
video_disable_1 = 0;
video_disable_2 = 0;
video_remap_1 = 1;
video_remap_2 = 1;
v0 = 0;
}
else
{
bitmap_free(tmpbitmap1);
tmpbitmap1 = 0LL;
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // edx

tmpbitmap1 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v0 = 1;
if ( tmpbitmap1 )
{
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
{
video_flip = 0;
video_color_select_1 = 0;
video_color_select_2 = 0;
video_disable_1 = 0;
video_disable_2 = 0;
video_remap_1 = 1;
video_remap_2 = 1;
v0 = 0;
}
else
{
bitmap_free(tmpbitmap1);
tmpbitmap1 = 0LL;
v0 = 1;
}
}
return v0;
}

original_code:
int route16_vh_start(void)
{
 if ((tmpbitmap1 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap1);
  tmpbitmap1 = 0;
  return 1;
 }
 video_flip = 0;
 video_color_select_1 = 0;
 video_color_select_2 = 0;
 video_disable_1 = 0;
 video_disable_2 = 0;
 video_remap_1 = 1;
 video_remap_2 = 1;
 return 0;
}

canonical_original_code:
int route16_vh_start()
{
 if ((tmpbitmap1 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap1);
  tmpbitmap1 = 0;
  return 1;
 }
 video_flip = 0;
 video_color_select_1 = 0;
 video_color_select_2 = 0;
 video_disable_1 = 0;
 video_disable_2 = 0;
 video_remap_1 = 1;
 video_remap_2 = 1;
 return 0;
}


decompiled_code:
__int64 route16_vh_stop()
{
bitmap_free(tmpbitmap1);
return bitmap_free(tmpbitmap2);
}

canonical_decompiled_code:
__int64 func12()
{
bitmap_free(tmpbitmap1);
return bitmap_free(tmpbitmap2);
}

original_code:
void route16_vh_stop(void)
{
 bitmap_free(tmpbitmap1);
 bitmap_free(tmpbitmap2);
}

canonical_original_code:
void route16_vh_stop()
{
 bitmap_free(tmpbitmap1);
 bitmap_free(tmpbitmap2);
}


decompiled_code:
void __fastcall route16_out0_w(__int64 a1, int a2)
{
_BOOL4 v2; // eax

if ( last_write_1 != a2 )
{
v2 = 0;
if ( (a2 & 2) != 0 )
v2 = route16_hardware != 0;
video_disable_1 = v2;
video_color_select_1 = (4 * (_BYTE)a2) & 0x7C;
coin_counter_w(0LL, a2 & 0x20);
video_remap_1 = 1;
last_write_1 = a2;
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, int a2)
{
_BOOL4 v2; // eax

if ( last_write_1 != a2 )
{
v2 = 0;
if ( (a2 & 2) != 0 )
v2 = route16_hardware != 0;
video_disable_1 = v2;
video_color_select_1 = (4 * (_BYTE)a2) & 0x7C;
coin_counter_w(0LL, a2 & 0x20);
video_remap_1 = 1;
last_write_1 = a2;
}
}

original_code:
void route16_out0_w(offs_t offset,data_t data)
{
 static int last_write = 0;
 if (data == last_write) return;
 video_disable_1 = ((data & 0x02) << 6) && route16_hardware;
 video_color_select_1 = ((data & 0x1f) << 2);
 coin_counter_w(0, data & 0x20);
 video_remap_1 = 1;
 last_write = data;
}

canonical_original_code:
void route16_out0_w(unsigned int offset, unsigned int data)
{
 static int last_write = 0;
 if (data == last_write) return;
 video_disable_1 = ((data & 0x02) << 6) && route16_hardware;
 video_color_select_1 = ((data & 0x1f) << 2);
 coin_counter_w(0, data & 0x20);
 video_remap_1 = 1;
 last_write = data;
}


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

if ( !route16_hardware )
{
SN76477_mixer_w(0LL, (a2 >> 4) & 7);
SN76477_envelope_w(0LL, (a2 >> 2) & 3);
SN76477_vco_w(0LL, (a2 >> 1) & 1);
result = SN76477_enable_w(0LL, a2 & 1);
}
return result;
}

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

if ( !route16_hardware )
{
SN76477_mixer_w(0LL, (a2 >> 4) & 7);
SN76477_envelope_w(0LL, (a2 >> 2) & 3);
SN76477_vco_w(0LL, (a2 >> 1) & 1);
result = SN76477_enable_w(0LL, a2 & 1);
}
return result;
}

original_code:
void stratvox_sn76477_w(offs_t offset,data_t data)
{
 if (route16_hardware) return;
    SN76477_mixer_w(0,(data >> 4) & 7);
 SN76477_envelope_w(0,(data >> 2) & 3);
    SN76477_vco_w(0,(data >> 1) & 1);
    SN76477_enable_w(0,data & 1);
}

canonical_original_code:
void stratvox_sn76477_w(unsigned int offset, unsigned int data)
{
 if (route16_hardware) return;
    SN76477_mixer_w(0,(data >> 4) & 7);
 SN76477_envelope_w(0,(data >> 2) & 3);
    SN76477_vco_w(0,(data >> 1) & 1);
    SN76477_enable_w(0,data & 1);
}


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

result = a1;
*(_BYTE *)(route16_sharedram + a1) = a2;
if ( a1 - 787 <= 6 && a2 == 255 )
{
if ( route16_hardware )
result = cpu_yield();
}
return result;
}

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

result = a1;
*(_BYTE *)(route16_sharedram + a1) = a2;
if ( a1 - 787 <= 6 && a2 == 255 )
{
if ( route16_hardware )
result = cpu_yield();
}
return result;
}

original_code:
void route16_sharedram_w(offs_t offset,data_t data)
{
 route16_sharedram[offset] = data;
 if (offset >= 0x0313 && offset <= 0x0319 && data == 0xff && route16_hardware)
 {
  cpu_yield();
 }
}

canonical_original_code:
void route16_sharedram_w(unsigned int offset, unsigned int data)
{
 route16_sharedram[offset] = data;
 if (offset >= 0x0313 && offset <= 0x0319 && data == 0xff && route16_hardware)
 {
  cpu_yield();
 }
}


decompiled_code:
__int64 __fastcall route16_vh_screenrefresh(__int64 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx

if ( video_remap_1 )
{
modify_pen(0LL, video_color_select_1);
modify_pen(1LL, video_color_select_1 + 1);
modify_pen(2LL, video_color_select_1 + 2);
modify_pen(3LL, video_color_select_1 + 3);
}
if ( video_remap_2 )
{
modify_pen(4LL, video_color_select_2);
modify_pen(5LL, video_color_select_2 + 1);
modify_pen(6LL, video_color_select_2 + 2);
modify_pen(7LL, video_color_select_2 + 3);
}
if ( palette_recalc()
|| (result = video_remap_2 | (unsigned int)video_remap_1, __PAIR64__(video_remap_1, video_remap_2)) )
{
result = (__int64)&route16_videoram_size;
if ( route16_videoram_size )
{
v2 = 0LL;
do
{
route16_videoram1_w(v2, *(unsigned __int8 *)(route16_videoram1 + v2));
route16_videoram2_w(v2, *(unsigned __int8 *)(route16_videoram2 + v2));
++v2;
result = (__int64)&route16_videoram_size;
}
while ( route16_videoram_size > v2 );
}
}
video_remap_1 = 0;
video_remap_2 = 0;
if ( video_disable_2 )
{
if ( video_disable_1 )
return result;
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( !video_disable_1 )
{
if ( !video_disable_2 )
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
return result;
}

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

if ( video_remap_1 )
{
func16(0LL, video_color_select_1);
func16(1LL, video_color_select_1 + 1);
func16(2LL, video_color_select_1 + 2);
func16(3LL, video_color_select_1 + 3);
}
if ( video_remap_2 )
{
func16(4LL, video_color_select_2);
func16(5LL, video_color_select_2 + 1);
func16(6LL, video_color_select_2 + 2);
func16(7LL, video_color_select_2 + 3);
}
if ( palette_recalc()
|| (result = video_remap_2 | (unsigned int)video_remap_1, __PAIR64__(video_remap_1, video_remap_2)) )
{
result = (__int64)&route16_videoram_size;
if ( route16_videoram_size )
{
v2 = 0LL;
do
{
func8(v2, *(unsigned __int8 *)(route16_videoram1 + v2));
func9(v2, *(unsigned __int8 *)(route16_videoram2 + v2));
++v2;
result = (__int64)&route16_videoram_size;
}
while ( route16_videoram_size > v2 );
}
}
video_remap_1 = 0;
video_remap_2 = 0;
if ( video_disable_2 )
{
if ( video_disable_1 )
return result;
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( !video_disable_1 )
{
if ( !video_disable_2 )
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
return result;
}

original_code:
void route16_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    if (video_remap_1)
 {
  modify_pen(0, video_color_select_1 + 0);
  modify_pen(1, video_color_select_1 + 1);
  modify_pen(2, video_color_select_1 + 2);
  modify_pen(3, video_color_select_1 + 3);
 }
 if (video_remap_2)
 {
  modify_pen(4, video_color_select_2 + 0);
  modify_pen(5, video_color_select_2 + 1);
  modify_pen(6, video_color_select_2 + 2);
  modify_pen(7, video_color_select_2 + 3);
 }
 if (palette_recalc() || video_remap_1 || video_remap_2)
 {
  int offs;
  for (offs = 0; offs < route16_videoram_size; offs++)
  {
   route16_videoram1_w(offs, route16_videoram1[offs]);
   route16_videoram2_w(offs, route16_videoram2[offs]);
  }
 }
 video_remap_1 = 0;
 video_remap_2 = 0;
 if (!video_disable_2)
 {
  copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 if (!video_disable_1)
 {
  if (video_disable_2)
   copybitmap(bitmap,tmpbitmap1,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
  else
   copybitmap(bitmap,tmpbitmap1,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
void route16_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    if (video_remap_1)
 {
  modify_pen(0, video_color_select_1 + 0);
  modify_pen(1, video_color_select_1 + 1);
  modify_pen(2, video_color_select_1 + 2);
  modify_pen(3, video_color_select_1 + 3);
 }
 if (video_remap_2)
 {
  modify_pen(4, video_color_select_2 + 0);
  modify_pen(5, video_color_select_2 + 1);
  modify_pen(6, video_color_select_2 + 2);
  modify_pen(7, video_color_select_2 + 3);
 }
 if (palette_recalc() || video_remap_1 || video_remap_2)
 {
  int offs;
  for (offs = 0; offs < route16_videoram_size; offs++)
  {
   route16_videoram1_w(offs, route16_videoram1[offs]);
   route16_videoram2_w(offs, route16_videoram2[offs]);
  }
 }
 video_remap_1 = 0;
 video_remap_2 = 0;
 if (!video_disable_2)
 {
  copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 if (!video_disable_1)
 {
  if (video_disable_2)
   copybitmap(bitmap,tmpbitmap1,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
  else
   copybitmap(bitmap,tmpbitmap1,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

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

variable_types: offs int


decompiled_code:
__int64 __fastcall common_videoram_w(int a1, int a2, int a3, __int64 a4)
{
unsigned int v5; // ebp
unsigned int v6; // ebx
int v7; // er12
int v8; // esi
__int64 result; // rax
int v11; // [rsp+8h] [rbp-40h]
int v12; // [rsp+Ch] [rbp-3Ch]

v5 = (unsigned __int8)(4 * a1);
v6 = (a1 >> 6) & 0x3FF;
if ( video_flip )
{
v5 = 255 - v5;
v6 = 255 - v6;
}
v11 = (a2 >> 3) & 1 | (a2 >> 6) & 2;
v12 = (a2 >> 2) & 1 | (a2 >> 5) & 2;
v7 = (a2 >> 1) & 1 | (a2 >> 4) & 2;
v8 = (a2 >> 3) & 2 | a2 & 1;
if ( video_flip )
{
plot_pixel(a4, v5, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v8)));
plot_pixel(a4, v5 - 1, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v7)));
plot_pixel(a4, v5 - 2, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v12)));
result = plot_pixel(a4, v5 - 3, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v11)));
}
else
{
plot_pixel(a4, v5, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v8)));
plot_pixel(a4, v5 + 1, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v7)));
plot_pixel(a4, v5 + 2, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v12)));
result = plot_pixel(a4, v5 + 3, v6, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a3 | v11)));
}
return result;
}

original_code:
static void common_videoram_w(int offset,int data,
                              int coloroffset, struct osd_bitmap *bitmap)
{
 int x, y, color1, color2, color3, color4;
 x = ((offset & 0x3f) << 2);
 y = (offset & 0xffc0) >> 6;
 if (video_flip)
 {
  x = 255 - x;
  y = 255 - y;
 }
 color4 = ((data & 0x80) >> 6) | ((data & 0x08) >> 3);
 color3 = ((data & 0x40) >> 5) | ((data & 0x04) >> 2);
 color2 = ((data & 0x20) >> 4) | ((data & 0x02) >> 1);
 color1 = ((data & 0x10) >> 3) | ((data & 0x01) );
 if (video_flip)
 {
  plot_pixel(bitmap, x , y, Machine->pens[color1 | coloroffset]);
  plot_pixel(bitmap, x-1, y, Machine->pens[color2 | coloroffset]);
  plot_pixel(bitmap, x-2, y, Machine->pens[color3 | coloroffset]);
  plot_pixel(bitmap, x-3, y, Machine->pens[color4 | coloroffset]);
 }
 else
 {
  plot_pixel(bitmap, x , y, Machine->pens[color1 | coloroffset]);
  plot_pixel(bitmap, x+1, y, Machine->pens[color2 | coloroffset]);
  plot_pixel(bitmap, x+2, y, Machine->pens[color3 | coloroffset]);
  plot_pixel(bitmap, x+3, y, Machine->pens[color4 | coloroffset]);
 }
}

canonical_original_code:
static void common_videoram_w(int offset, int data, int coloroffset, struct osd_bitmap *bitmap)
{
 int x; int y; int color1; int color2; int color3; int color4;
 x = ((offset & 0x3f) << 2);
 y = (offset & 0xffc0) >> 6;
 if (video_flip)
 {
  x = 255 - x;
  y = 255 - y;
 }
 color4 = ((data & 0x80) >> 6) | ((data & 0x08) >> 3);
 color3 = ((data & 0x40) >> 5) | ((data & 0x04) >> 2);
 color2 = ((data & 0x20) >> 4) | ((data & 0x02) >> 1);
 color1 = ((data & 0x10) >> 3) | ((data & 0x01) );
 if (video_flip)
 {
  plot_pixel(bitmap, x , y, Machine->pens[color1 | coloroffset]);
  plot_pixel(bitmap, x-1, y, Machine->pens[color2 | coloroffset]);
  plot_pixel(bitmap, x-2, y, Machine->pens[color3 | coloroffset]);
  plot_pixel(bitmap, x-3, y, Machine->pens[color4 | coloroffset]);
 }
 else
 {
  plot_pixel(bitmap, x , y, Machine->pens[color1 | coloroffset]);
  plot_pixel(bitmap, x+1, y, Machine->pens[color2 | coloroffset]);
  plot_pixel(bitmap, x+2, y, Machine->pens[color3 | coloroffset]);
  plot_pixel(bitmap, x+3, y, Machine->pens[color4 | coloroffset]);
 }
}

variable_types: offset int

variable_types: data int

variable_types: coloroffset int

variable_types: x int

variable_types: y int

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


decompiled_code:
__int64 __fastcall modify_pen(__int64 a1, int a2)
{
return palette_change_color(
a1,
(unsigned __int8)(*(unsigned __int8 *)(route16_color_prom + a2) << 31 >> 31),
(unsigned __int8)-((*(_BYTE *)(route16_color_prom + a2) & 2) != 0),
(unsigned __int8)-((*(_BYTE *)(route16_color_prom + a2) & 4) != 0));
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
return palette_change_color(
a1,
(unsigned __int8)(*(unsigned __int8 *)(route16_color_prom + a2) << 31 >> 31),
(unsigned __int8)-((*(_BYTE *)(route16_color_prom + a2) & 2) != 0),
(unsigned __int8)-((*(_BYTE *)(route16_color_prom + a2) & 4) != 0));
}

original_code:
static void modify_pen(int pen, int colorindex)
{
 int r,g,b,color;
 color = route16_color_prom[colorindex];
 r = ((color & 1) ? 0xff : 0x00);
 g = ((color & 2) ? 0xff : 0x00);
 b = ((color & 4) ? 0xff : 0x00);
 palette_change_color(pen,r,g,b);
}

canonical_original_code:
static void modify_pen(int pen, int colorindex)
{
 int r; int g; int b; int color;
 color = route16_color_prom[colorindex];
 r = ((color & 1) ? 0xff : 0x00);
 g = ((color & 2) ? 0xff : 0x00);
 b = ((color & 4) ? 0xff : 0x00);
 palette_change_color(pen,r,g,b);
}

variable_types: pen int

variable_types: colorindex int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: color int


decompiled_code:
void centiped_init_machine()
{
powerup_counter = 10;
}

canonical_decompiled_code:
void func0()
{
powerup_counter = 10;
}

original_code:
void centiped_init_machine(void)
{
 powerup_counter = 10;
}


decompiled_code:
__int64 centiped_interrupt()
{
int v0; // er12
__int64 i; // rbx

v0 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL) + 4 * (3 - cpu_getiloops());
for ( i = 4LL; i != 8; ++i )
setcolor((unsigned int)(v0 + i - 4), *(unsigned __int8 *)(paletteram + i));
if ( !powerup_counter )
return interrupt();
--powerup_counter;
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // er12
__int64 i; // rbx

v0 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL) + 4 * (3 - cpu_getiloops());
for ( i = 4LL; i != 8; ++i )
func1((unsigned int)(v0 + i - 4), *(unsigned __int8 *)(paletteram + i));
if ( !powerup_counter )
return interrupt();
--powerup_counter;
return ignore_interrupt();
}

original_code:
int centiped_interrupt(void)
{
 int offset;
 int slice = 3 - cpu_getiloops();
 int start = Machine->drv->gfxdecodeinfo[0].color_codes_start;
 for (offset = 4;offset < 8;offset++)
  setcolor(4 * slice + start + (offset - 4),paletteram[offset]);
 if (powerup_counter == 0)
  return interrupt();
 else
 {
  powerup_counter--;
  return ignore_interrupt();
 }
}

canonical_original_code:
int centiped_interrupt()
{
 int offset;
 int slice = 3 - cpu_getiloops();
 int start = Machine->drv->gfxdecodeinfo[0].color_codes_start;
 for (offset = 4;offset < 8;offset++)
  setcolor(4 * slice + start + (offset - 4),paletteram[offset]);
 if (powerup_counter == 0)
  return interrupt();
 else
 {
  powerup_counter--;
  return ignore_interrupt();
 }
}

variable_types: slice int

variable_types: start int


decompiled_code:
__int64 __fastcall centiped_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v3; // rax
int v4; // ebx
__int64 v5; // r12
int v6; // ecx
__int64 i; // rbx
__int64 result; // rax
unsigned int v9; // edi
unsigned int v10; // esi
__int64 v11; // r9
unsigned __int8 v12; // r14
__int64 v13; // r13
unsigned __int8 v14; // dl
int v15; // er10
int v16; // ecx

v3 = palette_recalc();
if ( a2 || v3 )
memset(dirtybuffer, 1, videoram_size);
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
v6 = v4 / 32 + 8;
if ( v4 / 32 + 1 >= 0 )
v6 = v4 / 32 + 1;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned __int8)((*(_BYTE *)(videoram + v5) & 0x3F) + 64),
(unsigned int)(v6 >> 3),
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * (v4 % 32)),
(unsigned int)(8 * (v4 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
for ( i = 0LL; i != 16; ++i )
{
v10 = (unsigned __int8)(*(_BYTE *)(spriteram + i) & 0x3F) >> 1;
if ( (*(_BYTE *)(spriteram + i) & 1) != 0 )
v10 += 64;
v11 = *(_BYTE *)(spriteram + i) & 0x80;
v12 = *(_BYTE *)(spriteram + i + 32);
v13 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + i + 16);
if ( flip_screen_x )
v11 = (_DWORD)v11 == 0;
v14 = *(_BYTE *)(spriteram + i + 48);
*(_WORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 520LL) + 16LL) + 6LL) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL)
+ 40LL)
+ (((int)v14 >> 4) & 3)));
*(_WORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 520LL) + 16LL) + 4LL) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL)
+ 40LL)
+ (((int)v14 >> 2) & 3)));
*(_WORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 520LL) + 16LL) + 2LL) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL)
+ 40LL)
+ (v14 & 3)));
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v10,
0LL,
flip_screen_x,
v11,
v12,
v13,
&spritevisiblearea,
2LL,
0LL);
v9 = (int)v13 >> 3;
v15 = ((int)v13 >> 3) - (((v13 & 0xF) == 0) - 3);
v16 = ((int)v12 >> 3) + ((v12 & 7) != 0) + 1;
if ( (int)v13 >> 3 < v15 )
{
do
{
result = (int)v12 >> 3;
if ( (int)v12 >> 3 < v16 )
{
do
{
if ( (unsigned int)result <= 0x1F && v9 <= 0x1D )
*((_BYTE *)dirtybuffer + (int)(32 * v9 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v16 );
}
++v9;
}
while ( v9 != v15 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 v3; // rax
int v4; // ebx
__int64 v5; // r12
int v6; // ecx
__int64 i; // rbx
__int64 result; // rax
unsigned int v9; // edi
unsigned int v10; // esi
__int64 v11; // r9
unsigned __int8 v12; // r14
__int64 v13; // r13
unsigned __int8 v14; // dl
int v15; // er10
int v16; // ecx

v3 = palette_recalc();
if ( a2 || v3 )
memset(dirtybuffer, 1, videoram_size);
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
v6 = v4 / 32 + 8;
if ( v4 / 32 + 1 >= 0 )
v6 = v4 / 32 + 1;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned __int8)((*(_BYTE *)(videoram + v5) & 0x3F) + 64),
(unsigned int)(v6 >> 3),
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * (v4 % 32)),
(unsigned int)(8 * (v4 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
for ( i = 0LL; i != 16; ++i )
{
v10 = (unsigned __int8)(*(_BYTE *)(spriteram + i) & 0x3F) >> 1;
if ( (*(_BYTE *)(spriteram + i) & 1) != 0 )
v10 += 64;
v11 = *(_BYTE *)(spriteram + i) & 0x80;
v12 = *(_BYTE *)(spriteram + i + 32);
v13 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + i + 16);
if ( flip_screen_x )
v11 = (_DWORD)v11 == 0;
v14 = *(_BYTE *)(spriteram + i + 48);
*(_WORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 520LL) + 16LL) + 6LL) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL)
+ 40LL)
+ (((int)v14 >> 4) & 3)));
*(_WORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 520LL) + 16LL) + 4LL) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL)
+ 40LL)
+ (((int)v14 >> 2) & 3)));
*(_WORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 520LL) + 16LL) + 2LL) = *(_WORD *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL)
+ 40LL)
+ (v14 & 3)));
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v10,
0LL,
flip_screen_x,
v11,
v12,
v13,
&spritevisiblearea,
2LL,
0LL);
v9 = (int)v13 >> 3;
v15 = ((int)v13 >> 3) - (((v13 & 0xF) == 0) - 3);
v16 = ((int)v12 >> 3) + ((v12 & 7) != 0) + 1;
if ( (int)v13 >> 3 < v15 )
{
do
{
result = (int)v12 >> 3;
if ( (int)v12 >> 3 < v16 )
{
do
{
if ( (unsigned int)result <= 0x1F && v9 <= 0x1D )
*((_BYTE *)dirtybuffer + (int)(32 * v9 + result)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v16 );
}
++v9;
}
while ( v9 != v15 );
}
}
return result;
}

original_code:
void centiped_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     (videoram[offs] & 0x3f) + 0x40,
     (sy + 1) / 8,
     flip_screen_x,flip_screen_x,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum,color;
  int flipx;
  int x, y;
  int sx, sy;
  spritenum = spriteram[offs] & 0x3f;
  if (spritenum & 1) spritenum = spritenum / 2 + 64;
  else spritenum = spritenum / 2;
  flipx = (spriteram[offs] & 0x80);
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  if (flip_screen_x)
  {
   flipx = !flipx;
  }
  color = spriteram[offs+0x30];
  Machine->gfx[1]->colortable[3] =
    Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 4) & 3)];
  Machine->gfx[1]->colortable[2] =
    Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 2) & 3)];
  Machine->gfx[1]->colortable[1] =
    Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 0) & 3)];
  drawgfx(bitmap,Machine->gfx[1],
    spritenum,0,
    flip_screen_x,flipx,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2, y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

canonical_original_code:
void centiped_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[0],
     (videoram[offs] & 0x3f) + 0x40,
     (sy + 1) / 8,
     flip_screen_x,flip_screen_x,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum; int color;
  int flipx;
  int x; int y;
  int sx; int sy;
  spritenum = spriteram[offs] & 0x3f;
  if (spritenum & 1) spritenum = spritenum / 2 + 64;
  else spritenum = spritenum / 2;
  flipx = (spriteram[offs] & 0x80);
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  if (flip_screen_x)
  {
   flipx = !flipx;
  }
  color = spriteram[offs+0x30];
  Machine->gfx[1]->colortable[3] =
    Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 4) & 3)];
  Machine->gfx[1]->colortable[2] =
    Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 2) & 3)];
  Machine->gfx[1]->colortable[1] =
    Machine->pens[Machine->drv->gfxdecodeinfo[1].color_codes_start + ((color >> 0) & 3)];
  drawgfx(bitmap,Machine->gfx[1],
    spritenum,0,
    flip_screen_x,flipx,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2; int y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: spritenum int

variable_types: flipx int


decompiled_code:
__int64 __fastcall centiped_led_w(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

original_code:
static void centiped_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset,~data >> 7);
}

canonical_original_code:
static void centiped_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,~data >> 7);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

v0 = readinputport(2LL);
if ( oldpos_3 != v0 )
{
sign_2 = ((_BYTE)v0 - (_BYTE)oldpos_3) & 0x80;
oldpos_3 = v0;
}
return sign_2 | oldpos_3 & 0xFu;
}

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

v0 = readinputport(2LL);
if ( oldpos_3 != v0 )
{
sign_2 = ((_BYTE)v0 - (_BYTE)oldpos_3) & 0x80;
oldpos_3 = v0;
}
return sign_2 | oldpos_3 & 0xFu;
}

original_code:
static data_t centiped_IN2_r(offs_t offset)
{
 static int oldpos,sign;
 int newpos;
 newpos = readinputport(2);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((oldpos & 0x0f) | sign );
}

canonical_original_code:
static unsigned int centiped_IN2_r(unsigned int offset)
{
 static int oldpos; static int sign;
 int newpos;
 newpos = readinputport(2);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((oldpos & 0x0f) | sign );
}

variable_types: oldpos int

variable_types: sign int

variable_types: newpos int


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

v0 = readinputport(6LL);
if ( oldpos_1 != v0 )
{
sign_0 = ((_BYTE)v0 - (_BYTE)oldpos_1) & 0x80;
oldpos_1 = v0;
}
return readinputport(0LL) & 0x70 | sign_0 | oldpos_1 & 0xFu;
}

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

v0 = readinputport(6LL);
if ( oldpos_1 != v0 )
{
sign_0 = ((_BYTE)v0 - (_BYTE)oldpos_1) & 0x80;
oldpos_1 = v0;
}
return readinputport(0LL) & 0x70 | sign_0 | oldpos_1 & 0xFu;
}

original_code:
static data_t centiped_IN0_r(offs_t offset)
{
 static int oldpos,sign;
 int newpos;
 newpos = readinputport(6);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((readinputport(0) & 0x70) | (oldpos & 0x0f) | sign );
}

canonical_original_code:
static unsigned int centiped_IN0_r(unsigned int offset)
{
 static int oldpos; static int sign;
 int newpos;
 newpos = readinputport(6);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((readinputport(0) & 0x70) | (oldpos & 0x0f) | sign );
}


decompiled_code:
__int64 __fastcall centipdb_AY8910_w(unsigned int a1, unsigned int a2)
{
AY8910_control_port_0_w(0LL, a1);
return AY8910_write_port_0_w(0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
AY8910_control_port_0_w(0LL, a1);
return AY8910_write_port_0_w(0LL, a2);
}

original_code:
static void centipdb_AY8910_w(offs_t offset,data_t data)
{
 AY8910_control_port_0_w(0, offset);
 AY8910_write_port_0_w(0, data);
}

canonical_original_code:
static void centipdb_AY8910_w(unsigned int offset, unsigned int data)
{
 AY8910_control_port_0_w(0, offset);
 AY8910_write_port_0_w(0, data);
}


decompiled_code:
__int64 centipdb_rand_r()
{
return (unsigned int)(rand() % 255);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)(rand() % 255);
}

original_code:
static data_t centipdb_rand_r(offs_t offset)
{
 return rand() % 0xff;
}

canonical_original_code:
static unsigned int centipdb_rand_r(unsigned int offset)
{
 return rand() % 0xff;
}


decompiled_code:
__int64 __fastcall centipdb_AY8910_r(unsigned int a1)
{
AY8910_control_port_0_w(0LL, a1);
return AY8910_read_port_0_r(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
AY8910_control_port_0_w(0LL, a1);
return AY8910_read_port_0_r(0LL);
}

original_code:
static data_t centipdb_AY8910_r(offs_t offset)
{
 AY8910_control_port_0_w(0, offset);
 return AY8910_read_port_0_r(0);
}

canonical_original_code:
static unsigned int centipdb_AY8910_r(unsigned int offset)
{
 AY8910_control_port_0_w(0, offset);
 return AY8910_read_port_0_r(0);
}


setcolor

original_code:
static void setcolor(int pen,int data)
{
 int r,g,b;
 r = 0xff * ((~data >> 0) & 1);
 g = 0xff * ((~data >> 1) & 1);
 b = 0xff * ((~data >> 2) & 1);
 if (~data & 0x08)
 {
  if (b) b = 0xc0;
  else if (g) g = 0xc0;
 }
 palette_change_color(pen,r,g,b);
}

canonical_original_code:
static void setcolor(int pen, int data)
{
 int r; int g; int b;
 r = 0xff * ((~data >> 0) & 1);
 g = 0xff * ((~data >> 1) & 1);
 b = 0xff * ((~data >> 2) & 1);
 if (~data & 0x08)
 {
  if (b) b = 0xc0;
  else if (g) g = 0xc0;
 }
 palette_change_color(pen,r,g,b);
}

variable_types: pen int

variable_types: data int


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

result = 0LL;
if ( !a1 )
result = (unsigned int)finished_sound;
return result;
}

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

result = 0LL;
if ( !a1 )
result = (unsigned int)finished_sound;
return result;
}

original_code:
data_t gameplan_sound_r(offs_t offset)
{
 if (offset == 0)
 {
  return finished_sound;
 }
 else
  return 0;
}

canonical_original_code:
unsigned int gameplan_sound_r(unsigned int offset)
{
 if (offset == 0)
 {
  return finished_sound;
 }
 else
  return 0;
}


decompiled_code:
__int64 __fastcall gameplan_sound_w(int a1, int a2)
{
int v2; // esi
__int64 result; // rax

if ( a1 == 1 )
{
if ( cb2 )
{
port_b = a2;
finished_sound = 0;
new_request = 1;
}
}
else if ( a1 == 12 && (a2 & 0x80u) != 0 )
{
v2 = a2 & 0x60;
if ( v2 == 96 )
{
cb2 = 1;
}
else
{
result = (unsigned int)(v2 == 64) - 1;
cb2 = (v2 == 64) - 1;
}
}
return result;
}

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

if ( a1 == 1 )
{
if ( cb2 )
{
port_b = a2;
finished_sound = 0;
new_request = 1;
}
}
else if ( a1 == 12 && (a2 & 0x80u) != 0 )
{
v2 = a2 & 0x60;
if ( v2 == 96 )
{
cb2 = 1;
}
else
{
result = (unsigned int)(v2 == 64) - 1;
cb2 = (v2 == 64) - 1;
}
}
return result;
}

original_code:
void gameplan_sound_w(offs_t offset,data_t data)
{
 if (offset == 1)
 {
  if (cb2 == 0)
  {
   return;
  }
  port_b = data;
  finished_sound = 0;
  new_request = 1;
 }
 else if (offset == 0x0c)
 {
  if (data & 0x80)
  {
   if ((data & 0x60) == 0x60)
    cb2 = 1;
   else if ((data & 0x60) == 0x40)
    cb2 = 0;
   else cb2 = -1;
  }
 }
}

canonical_original_code:
void gameplan_sound_w(unsigned int offset, unsigned int data)
{
 if (offset == 1)
 {
  if (cb2 == 0)
  {
   return;
  }
  port_b = data;
  finished_sound = 0;
  new_request = 1;
 }
 else if (offset == 0x0c)
 {
  if (data & 0x80)
  {
   if ((data & 0x60) == 0x60)
    cb2 = 1;
   else if ((data & 0x60) == 0x40)
    cb2 = 0;
   else cb2 = -1;
  }
 }
}


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

if ( a1 )
{
result = 1LL;
if ( a1 == 5 )
result = (unsigned __int8)(new_request == 1) << 6;
}
else
{
new_request = 0;
result = (unsigned int)port_b;
}
return result;
}

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

if ( a1 )
{
result = 1LL;
if ( a1 == 5 )
result = (unsigned __int8)(new_request == 1) << 6;
}
else
{
new_request = 0;
result = (unsigned int)port_b;
}
return result;
}

original_code:
data_t gameplan_via5_r(offs_t offset)
{
 if (offset == 0)
 {
  new_request = 0;
  return port_b;
 }
 if (offset == 5)
 {
  if (new_request == 1)
  {
   return 0x40;
  }
  else
  {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
unsigned int gameplan_via5_r(unsigned int offset)
{
 if (offset == 0)
 {
  new_request = 0;
  return port_b;
 }
 if (offset == 5)
 {
  if (new_request == 1)
  {
   return 0x40;
  }
  else
  {
   return 0;
  }
 }
 return 1;
}


decompiled_code:
void __fastcall gameplan_via5_w(int a1, int a2)
{
if ( a1 == 2 )
finished_sound = a2;
}

canonical_decompiled_code:
void __fastcall func3(int a1, int a2)
{
if ( a1 == 2 )
finished_sound = a2;
}

original_code:
void gameplan_via5_w(offs_t offset,data_t data)
{
 if (offset == 2)
 {
  finished_sound = data;
 }
}

canonical_original_code:
void gameplan_via5_w(unsigned int offset, unsigned int data)
{
 if (offset == 2)
 {
  finished_sound = data;
 }
}


decompiled_code:
__int64 gameplan_video_r()
{
return (unsigned int)++x_4;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)++x_4;
}

original_code:
data_t gameplan_video_r(offs_t offset)
{
 static int x;
 x++;
 return x;
}

canonical_original_code:
unsigned int gameplan_video_r(unsigned int offset)
{
 static int x;
 x++;
 return x;
}

variable_types: x int


decompiled_code:
void __fastcall gameplan_port_select_w(int a1, unsigned int a2)
{
if ( !a1 )
{
if ( a2 == 8 )
{
gameplan_current_port = 3;
}
else if ( a2 > 8 )
{
if ( a2 == 64 )
{
gameplan_current_port = 5;
}
else if ( a2 == 128 )
{
gameplan_current_port = 4;
}
}
else
{
switch ( a2 )
{
case 2u:
gameplan_current_port = 1;
break;
case 4u:
gameplan_current_port = 2;
break;
case 1u:
gameplan_current_port = 0;
break;
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, unsigned int a2)
{
if ( !a1 )
{
if ( a2 == 8 )
{
gameplan_current_port = 3;
}
else if ( a2 > 8 )
{
if ( a2 == 64 )
{
gameplan_current_port = 5;
}
else if ( a2 == 128 )
{
gameplan_current_port = 4;
}
}
else
{
switch ( a2 )
{
case 2u:
gameplan_current_port = 1;
break;
case 4u:
gameplan_current_port = 2;
break;
case 1u:
gameplan_current_port = 0;
break;
}
}
}
}

original_code:
static void gameplan_port_select_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0x00:
   switch(data)
   {
    case 0x01: gameplan_current_port = 0; break;
    case 0x02: gameplan_current_port = 1; break;
    case 0x04: gameplan_current_port = 2; break;
    case 0x08: gameplan_current_port = 3; break;
    case 0x80: gameplan_current_port = 4; break;
    case 0x40: gameplan_current_port = 5; break;
    default:
     return;
   }
   break;
  default:
   break;
 }
}

canonical_original_code:
static void gameplan_port_select_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0x00:
   switch(data)
   {
    case 0x01: gameplan_current_port = 0; break;
    case 0x02: gameplan_current_port = 1; break;
    case 0x04: gameplan_current_port = 2; break;
    case 0x08: gameplan_current_port = 3; break;
    case 0x80: gameplan_current_port = 4; break;
    case 0x40: gameplan_current_port = 5; break;
    default:
     return;
   }
   break;
  default:
   break;
 }
}


decompiled_code:
__int64 gameplan_interrupt()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 1LL;
}

original_code:
int gameplan_interrupt(void)
{
 return 1;
}

canonical_original_code:
int gameplan_interrupt()
{
 return 1;
}


decompiled_code:
__int64 gameplan_vh_start()
{
const char *v0; // rax
bool v1; // cf
bool v2; // zf
__int64 v3; // rcx
const char *v4; // rdi
const char *v5; // rsi

v0 = *(const char **)(*(_QWORD *)(Machine + 816LL) + 16LL);
v1 = 0;
v2 = strcmp(v0, "kaos") == 0;
gameplan_this_is_kaos = v2;
v3 = 9LL;
v4 = "megatack";
v5 = v0;
do
{
if ( !v3 )
break;
v1 = *v5 < (unsigned int)*v4;
v2 = *v5++ == *v4++;
--v3;
}
while ( v2 );
gameplan_this_is_megatack = (!v1 && !v2) == v1;
return generic_bitmapped_vh_start(v4, v5);
}

canonical_decompiled_code:
__int64 func8()
{
const char *v0; // rax
bool v1; // cf
bool v2; // zf
__int64 v3; // rcx
const char *v4; // rdi
const char *v5; // rsi

v0 = *(const char **)(*(_QWORD *)(Machine + 816LL) + 16LL);
v1 = 0;
v2 = strcmp(v0, "kaos") == 0;
gameplan_this_is_kaos = v2;
v3 = 9LL;
v4 = "megatack";
v5 = v0;
do
{
if ( !v3 )
break;
v1 = *v5 < (unsigned int)*v4;
v2 = *v5++ == *v4++;
--v3;
}
while ( v2 );
gameplan_this_is_megatack = (!v1 && !v2) == v1;
return generic_bitmapped_vh_start(v4, v5);
}

original_code:
int gameplan_vh_start(void)
{
 if (strcmp(Machine->gamedrv->name, "kaos") == 0)
  gameplan_this_is_kaos = 1;
 else
  gameplan_this_is_kaos = 0;
 if (strcmp(Machine->gamedrv->name, "megatack") == 0)
  gameplan_this_is_megatack = 1;
 else
  gameplan_this_is_megatack = 0;
 return generic_bitmapped_vh_start();
}

canonical_original_code:
int gameplan_vh_start()
{
 if (strcmp(Machine->gamedrv->name, "kaos") == 0)
  gameplan_this_is_kaos = 1;
 else
  gameplan_this_is_kaos = 0;
 if (strcmp(Machine->gamedrv->name, "megatack") == 0)
  gameplan_this_is_megatack = 1;
 else
  gameplan_this_is_megatack = 0;
 return generic_bitmapped_vh_start();
}


decompiled_code:
__int64 gameplan_port_r()
{
return readinputport((unsigned int)gameplan_current_port);
}

canonical_decompiled_code:
__int64 func9()
{
return readinputport((unsigned int)gameplan_current_port);
}

original_code:
static data_t gameplan_port_r(offs_t offset)
{
 return readinputport(gameplan_current_port);
}

canonical_original_code:
static unsigned int gameplan_port_r(unsigned int offset)
{
 return readinputport(gameplan_current_port);
}


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

logerror(" clearing the screen to colour %d (%s)\n", (unsigned int)clear_to_colour, colour_names[clear_to_colour]);
fillbitmap(tmpbitmap, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * clear_to_colour), 0LL);
result = fillbitmap(
*(_QWORD *)(Machine + 768LL),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * clear_to_colour),
0LL);
fix_clear_to_colour = -1;
return result;
}

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

logerror(" clearing the screen to colour %d (%s)\n", (unsigned int)clear_to_colour, colour_names[clear_to_colour]);
fillbitmap(tmpbitmap, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * clear_to_colour), 0LL);
result = fillbitmap(
*(_QWORD *)(Machine + 768LL),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * clear_to_colour),
0LL);
fix_clear_to_colour = -1;
return result;
}

original_code:
void gameplan_clear_screen(void)
{
 logerror("  clearing the screen to colour %d (%s)\n", clear_to_colour, colour_names[clear_to_colour]);
 fillbitmap(tmpbitmap, Machine->pens[clear_to_colour], 0);
 fillbitmap(Machine->scrbitmap, Machine->pens[clear_to_colour], 0);
 fix_clear_to_colour = -1;
}

canonical_original_code:
void gameplan_clear_screen()
{
 logerror("  clearing the screen to colour %d (%s)\n", clear_to_colour, colour_names[clear_to_colour]);
 fillbitmap(tmpbitmap, Machine->pens[clear_to_colour], 0);
 fillbitmap(Machine->scrbitmap, Machine->pens[clear_to_colour], 0);
 fix_clear_to_colour = -1;
}


decompiled_code:
void __fastcall gameplan_video_w(int a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rsi

if ( !a1 )
{
r0_3 = a2;
return;
}
if ( a1 != 1 )
{
if ( a1 != 2 )
{
if ( a1 == 3 )
{
if ( r0_3 )
{
if ( (a2 & 0xF8) == 248 && a2 != 255 )
{
fix_clear_to_colour = a2 & 7;
clear_to_colour = a2 & 7;
}
}
else
{
colour_2 = a2 & 7;
}
}
return;
}
if ( a2 != 7 )
return;
if ( gameplan_this_is_megatack )
{
v2 = (unsigned int)fix_clear_to_colour;
if ( fix_clear_to_colour != -1 )
{
LABEL_31:
logerror(" clear req colour %d hidden by fixed colour %d\n", (unsigned __int8)colour_2, v2);
return;
}
v3 = (unsigned __int8)colour_2;
clear_to_colour = (unsigned __int8)colour_2;
}
else
{
v3 = (unsigned __int8)colour_2;
clear_to_colour = (unsigned __int8)colour_2;
v2 = (unsigned int)fix_clear_to_colour;
if ( fix_clear_to_colour != -1 )
goto LABEL_31;
}
logerror(" clear screen colour = %d (%s)\n", v3, colour_names[(int)v3]);
return;
}
if ( r0_3 )
{
if ( r0_3 == 1 )
{
xpos_0 = a2;
logerror("\n");
}
else if ( r0_3 == 2 )
{
ypos_1 = a2;
}
else if ( !a2 && r0_3 == 3 )
{
logerror(" clear screen\n");
gameplan_clear_screen();
}
}
else
{
if ( gameplan_this_is_kaos )
colour_2 = ~(_BYTE)a2 & 7;
logerror("%c", (unsigned int)*colour_names[(unsigned __int8)colour_2]);
if ( (a2 & 0x20) != 0 )
{
if ( (a2 & 0x80u) == 0 )
++ypos_1;
else
--ypos_1;
}
if ( (a2 & 0x10) != 0 )
{
if ( (a2 & 0x40) != 0 )
--xpos_0;
else
++xpos_0;
}
plot_pixel2(
*(_QWORD *)(Machine + 768LL),
tmpbitmap,
(unsigned __int8)xpos_0,
(unsigned __int8)ypos_1,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned __int8)colour_2));
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rsi

if ( !a1 )
{
r0_3 = a2;
return;
}
if ( a1 != 1 )
{
if ( a1 != 2 )
{
if ( a1 == 3 )
{
if ( r0_3 )
{
if ( (a2 & 0xF8) == 248 && a2 != 255 )
{
fix_clear_to_colour = a2 & 7;
clear_to_colour = a2 & 7;
}
}
else
{
colour_2 = a2 & 7;
}
}
return;
}
if ( a2 != 7 )
return;
if ( gameplan_this_is_megatack )
{
v2 = (unsigned int)fix_clear_to_colour;
if ( fix_clear_to_colour != -1 )
{
LABEL_31:
logerror(" clear req colour %d hidden by fixed colour %d\n", (unsigned __int8)colour_2, v2);
return;
}
v3 = (unsigned __int8)colour_2;
clear_to_colour = (unsigned __int8)colour_2;
}
else
{
v3 = (unsigned __int8)colour_2;
clear_to_colour = (unsigned __int8)colour_2;
v2 = (unsigned int)fix_clear_to_colour;
if ( fix_clear_to_colour != -1 )
goto LABEL_31;
}
logerror(" clear screen colour = %d (%s)\n", v3, colour_names[(int)v3]);
return;
}
if ( r0_3 )
{
if ( r0_3 == 1 )
{
xpos_0 = a2;
logerror("\n");
}
else if ( r0_3 == 2 )
{
ypos_1 = a2;
}
else if ( !a2 && r0_3 == 3 )
{
logerror(" clear screen\n");
func10();
}
}
else
{
if ( gameplan_this_is_kaos )
colour_2 = ~(_BYTE)a2 & 7;
logerror("%c", (unsigned int)*colour_names[(unsigned __int8)colour_2]);
if ( (a2 & 0x20) != 0 )
{
if ( (a2 & 0x80u) == 0 )
++ypos_1;
else
--ypos_1;
}
if ( (a2 & 0x10) != 0 )
{
if ( (a2 & 0x40) != 0 )
--xpos_0;
else
++xpos_0;
}
plot_pixel2(
*(_QWORD *)(Machine + 768LL),
tmpbitmap,
(unsigned __int8)xpos_0,
(unsigned __int8)ypos_1,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned __int8)colour_2));
}
}

original_code:
void gameplan_video_w(offs_t offset,data_t data)
{
 static int r0 = -1;
 static unsigned char xpos, ypos, colour = 7;
 if (offset == 0)
 {
  r0 = data;
 }
 else if (offset == 1)
 {
  if (r0 == 0)
  {
   if (gameplan_this_is_kaos)
    colour = ~data & 0x07;
   else if (data & 0x0f)
   {
   }
   logerror("%c", colour_names[colour][0]);
   if (data & 0x20)
   {
    if (data & 0x80)
     ypos--;
    else
     ypos++;
   }
   if (data & 0x10)
   {
    if (data & 0x40)
     xpos--;
    else
     xpos++;
   }
   plot_pixel2(Machine->scrbitmap, tmpbitmap, xpos, ypos, Machine->pens[colour]);
  }
  else if (r0 == 1)
  {
   xpos = data;
   logerror("\n");
  }
  else if (r0 == 2)
  {
   ypos = data;
  }
  else if (r0 == 3)
  {
   if (offset == 1 && data == 0)
   {
    logerror("  clear screen\n");
    gameplan_clear_screen();
   }
  }
 }
 else if (offset == 2)
 {
  if (data == 7)
  {
   if (!gameplan_this_is_megatack || fix_clear_to_colour == -1)
    clear_to_colour = colour;
   if (fix_clear_to_colour == -1)
    logerror("  clear screen colour = %d (%s)\n", colour, colour_names[colour]);
   else
    logerror("  clear req colour %d hidden by fixed colour %d\n", colour, fix_clear_to_colour);
  }
 }
 else if (offset == 3)
 {
  if (r0 == 0)
  {
   colour = data & 7;
  }
  else if ((data & 0xf8) == 0xf8 && data != 0xff)
  {
   clear_to_colour = fix_clear_to_colour = data & 0x07;
  }
 }
}

canonical_original_code:
void gameplan_video_w(unsigned int offset, unsigned int data)
{
 static int r0 = -1;
 static unsigned char xpos; static unsigned char ypos; static unsigned char colour = 7;
 if (offset == 0)
 {
  r0 = data;
 }
 else if (offset == 1)
 {
  if (r0 == 0)
  {
   if (gameplan_this_is_kaos)
    colour = ~data & 0x07;
   else if (data & 0x0f)
   {
   }
   logerror("%c", colour_names[colour][0]);
   if (data & 0x20)
   {
    if (data & 0x80)
     ypos--;
    else
     ypos++;
   }
   if (data & 0x10)
   {
    if (data & 0x40)
     xpos--;
    else
     xpos++;
   }
   plot_pixel2(Machine->scrbitmap, tmpbitmap, xpos, ypos, Machine->pens[colour]);
  }
  else if (r0 == 1)
  {
   xpos = data;
   logerror("\n");
  }
  else if (r0 == 2)
  {
   ypos = data;
  }
  else if (r0 == 3)
  {
   if (offset == 1 && data == 0)
   {
    logerror("  clear screen\n");
    gameplan_clear_screen();
   }
  }
 }
 else if (offset == 2)
 {
  if (data == 7)
  {
   if (!gameplan_this_is_megatack || fix_clear_to_colour == -1)
    clear_to_colour = colour;
   if (fix_clear_to_colour == -1)
    logerror("  clear screen colour = %d (%s)\n", colour, colour_names[colour]);
   else
    logerror("  clear req colour %d hidden by fixed colour %d\n", colour, fix_clear_to_colour);
  }
 }
 else if (offset == 3)
 {
  if (r0 == 0)
  {
   colour = data & 7;
  }
  else if ((data & 0xf8) == 0xf8 && data != 0xff)
  {
   clear_to_colour = fix_clear_to_colour = data & 0x07;
  }
 }
}

variable_types:
xpos
unsigned char

variable_types:
ypos
unsigned char

variable_types:
colour
unsigned char


decompiled_code:
__int64 __fastcall init_palette(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0x20FFFFFF20FFFFFFLL;
a1[1] = 0x2020FFFFFF2020FFLL;
result = 0x2020FF20FFLL;
a1[2] = 0x2020FF20FFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0x20FFFFFF20FFFFFFLL;
a1[1] = 0x2020FFFFFF2020FFLL;
result = 0x2020FF20FFLL;
a1[2] = 0x2020FF20FFLL;
return result;
}

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

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


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

result = (unsigned int)a1;
if ( _bittest(&a3, a2 & 7) )
result = a1 & 0xFC | (2 * (_BYTE)a1) & 2 | (a1 >> 1) & 1u;
if ( _bittest(&a3, (a2 >> 4) & 7) )
result = result & 0xF3 | (2 * (_BYTE)result) & 8 | ((int)result >> 1) & 4u;
if ( _bittest(&a3, (a2 >> 8) & 7) )
result = result & 0xCF | (2 * (_BYTE)result) & 0x20 | ((int)result >> 1) & 0x10u;
if ( _bittest(&a3, (a2 >> 12) & 7) )
result = result & 0x3F | (2 * (_BYTE)result) & 0x80 | ((int)result >> 1) & 0x40u;
return result;
}

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

result = (unsigned int)a1;
if ( _bittest(&a3, a2 & 7) )
result = a1 & 0xFC | (2 * (_BYTE)a1) & 2 | (a1 >> 1) & 1u;
if ( _bittest(&a3, (a2 >> 4) & 7) )
result = result & 0xF3 | (2 * (_BYTE)result) & 8 | ((int)result >> 1) & 4u;
if ( _bittest(&a3, (a2 >> 8) & 7) )
result = result & 0xCF | (2 * (_BYTE)result) & 0x20 | ((int)result >> 1) & 0x10u;
if ( _bittest(&a3, (a2 >> 12) & 7) )
result = result & 0x3F | (2 * (_BYTE)result) & 0x80 | ((int)result >> 1) & 0x40u;
return result;
}

variable_types: src int

variable_types: key int

variable_types: select int


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

result = (unsigned int)a1;
if ( _bittest(&a3, (a2 >> 12) & 7) )
result = a1 & 0xFC | (2 * (_BYTE)a1) & 2 | (a1 >> 1) & 1u;
if ( _bittest(&a3, (a2 >> 8) & 7) )
result = result & 0xF3 | (2 * (_BYTE)result) & 8 | ((int)result >> 1) & 4u;
if ( _bittest(&a3, (a2 >> 4) & 7) )
result = result & 0xCF | (2 * (_BYTE)result) & 0x20 | ((int)result >> 1) & 0x10u;
if ( _bittest(&a3, a2 & 7) )
result = result & 0x3F | (2 * (_BYTE)result) & 0x80 | ((int)result >> 1) & 0x40u;
return result;
}

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

result = (unsigned int)a1;
if ( _bittest(&a3, (a2 >> 12) & 7) )
result = a1 & 0xFC | (2 * (_BYTE)a1) & 2 | (a1 >> 1) & 1u;
if ( _bittest(&a3, (a2 >> 8) & 7) )
result = result & 0xF3 | (2 * (_BYTE)result) & 8 | ((int)result >> 1) & 4u;
if ( _bittest(&a3, (a2 >> 4) & 7) )
result = result & 0xCF | (2 * (_BYTE)result) & 0x20 | ((int)result >> 1) & 0x10u;
if ( _bittest(&a3, a2 & 7) )
result = result & 0x3F | (2 * (_BYTE)result) & 0x80 | ((int)result >> 1) & 0x40u;
return result;
}


bytedecode

decompiled_code:
__int64 __fastcall bytedecode(int a1, int a2, int a3, int a4, int a5)
{
int v7; // ebp
int v8; // er14
int v9; // eax
int v10; // eax
int v11; // eax

v7 = a5;
v8 = (unsigned __int8)a5;
v9 = bitswap1(a1, (unsigned __int16)a2, (unsigned __int8)a5);
v10 = bitswap2((v9 >> 7) & 1 | (unsigned int)(unsigned __int8)(2 * v9), a2 >> 16, v8);
v7 >>= 8;
v11 = bitswap2(((a4 ^ v10) >> 7) & 1 | (unsigned int)(unsigned __int8)(2 * (a4 ^ v10)), (unsigned __int16)a3, v7);
return bitswap1((v11 >> 7) & 1 | (unsigned int)(unsigned __int8)(2 * v11), a3 >> 16, v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4, int a5)
{
int v7; // ebp
int v8; // er14
int v9; // eax
int v10; // eax
int v11; // eax

v7 = a5;
v8 = (unsigned __int8)a5;
v9 = func0(a1, (unsigned __int16)a2, (unsigned __int8)a5);
v10 = func1((v9 >> 7) & 1 | (unsigned int)(unsigned __int8)(2 * v9), a2 >> 16, v8);
v7 >>= 8;
v11 = func1(((a4 ^ v10) >> 7) & 1 | (unsigned int)(unsigned __int8)(2 * (a4 ^ v10)), (unsigned __int16)a3, v7);
return func0((v11 >> 7) & 1 | (unsigned int)(unsigned __int8)(2 * v11), a3 >> 16, v7);
}

original_code:
static int bytedecode(int src,int swap_key1,int swap_key2,int xor_key,int select)
{
 src = bitswap1(src,swap_key1 & 0xffff,select & 0xff);
 src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);
 src = bitswap2(src,swap_key1 >> 16,select & 0xff);
 src ^= xor_key;
 src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);
 src = bitswap2(src,swap_key2 & 0xffff,select >> 8);
 src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);
 src = bitswap1(src,swap_key2 >> 16,select >> 8);
 return src;
}

canonical_original_code:
static int bytedecode(int src, int swap_key1, int swap_key2, int xor_key, int select)
{
 src = bitswap1(src,swap_key1 & 0xffff,select & 0xff);
 src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);
 src = bitswap2(src,swap_key1 >> 16,select & 0xff);
 src ^= xor_key;
 src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);
 src = bitswap2(src,swap_key2 & 0xffff,select >> 8);
 src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);
 src = bitswap1(src,swap_key2 >> 16,select >> 8);
 return src;
}


decompiled_code:
void __fastcall kabuki_decode(unsigned __int8 *a1, _BYTE *a2, _BYTE *a3, int a4, int a5, int a6, int a7, int a8, int a9)
{
int v13; // ebx
int v14; // [rsp+4h] [rbp-34h]

if ( a5 > 0 )
{
v13 = a4;
v14 = a5 + a4;
do
{
*a2 = bytedecode(*a1, a6, a7, a9, a8 + v13);
*a3 = bytedecode(*a1++, a6, a7, a9, a8 + (v13 ^ 0x1FC0u) + 1);
++a2;
++v13;
++a3;
}
while ( v13 != v14 );
}
}

original_code:
void kabuki_decode(unsigned char *src,unsigned char *dest_op,unsigned char *dest_data,
  int base_addr,int length,int swap_key1,int swap_key2,int addr_key,int xor_key)
{
 int A;
 int select;
 for (A = 0;A < length;A++)
 {
  select = (A + base_addr) + addr_key;
  dest_op[A] = bytedecode(src[A],swap_key1,swap_key2,xor_key,select);
  select = ((A + base_addr) ^ 0x1fc0) + addr_key + 1;
  dest_data[A] = bytedecode(src[A],swap_key1,swap_key2,xor_key,select);
 }
}

canonical_original_code:
void kabuki_decode(unsigned char *src, unsigned char *dest_op, unsigned char *dest_data, int base_addr, int length, int swap_key1, int swap_key2, int addr_key, int xor_key)
{
 int A;
 int select;
 for (A = 0;A < length;A++)
 {
  select = (A + base_addr) + addr_key;
  dest_op[A] = bytedecode(src[A],swap_key1,swap_key2,xor_key,select);
  select = ((A + base_addr) ^ 0x1fc0) + addr_key + 1;
  dest_data[A] = bytedecode(src[A],swap_key1,swap_key2,xor_key,select);
 }
}

variable_types:
src
unsigned char *

variable_types: length int

variable_types: A int


decompiled_code:
void __fastcall mitchell_decode(int a1, int a2, int a3, int a4)
{
unsigned __int8 *v6; // rbx
int v7; // ebp
unsigned __int8 *v8; // rbx
int v9; // [rsp+14h] [rbp-44h]
int v10; // [rsp+14h] [rbp-44h]

v6 = (unsigned __int8 *)memory_region(129LL);
v9 = memory_region_length(129LL);
v7 = v9 / 2;
memory_set_opcode_base(0LL, &v6[v9 / 2]);
kabuki_decode(v6, &v6[v9 / 2], v6, 0, 0x8000, a1, a2, a3, a4);
if ( v9 > 131073 )
{
v8 = v6 + 0x10000;
v10 = 0x10000 - (_DWORD)v8;
do
{
kabuki_decode(v8, &v8[v7], v8, 0x8000, 0x4000, a1, a2, a3, a4);
v8 += 0x4000;
}
while ( v7 > (int)v8 + v10 );
}
}

original_code:
static void mitchell_decode(int swap_key1,int swap_key2,int addr_key,int xor_key)
{
 int i;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 memory_set_opcode_base(0,rom+diff);
 kabuki_decode(rom,rom+diff,rom,0x0000,0x8000, swap_key1,swap_key2,addr_key,xor_key);
 for (i = 0x10000;i < diff;i += 0x4000)
  kabuki_decode(rom+i,rom+i+diff,rom+i,0x8000,0x4000, swap_key1,swap_key2,addr_key,xor_key);
}

canonical_original_code:
static void mitchell_decode(int swap_key1, int swap_key2, int addr_key, int xor_key)
{
 int i;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 memory_set_opcode_base(0,rom+diff);
 kabuki_decode(rom,rom+diff,rom,0x0000,0x8000, swap_key1,swap_key2,addr_key,xor_key);
 for (i = 0x10000;i < diff;i += 0x4000)
  kabuki_decode(rom+i,rom+i+diff,rom+i,0x8000,0x4000, swap_key1,swap_key2,addr_key,xor_key);
}

variable_types: i int

variable_types:
rom
unsigned char *

variable_types: diff int


decompiled_code:
void __fastcall cps1_decode(int a1, int a2, int a3, int a4)
{
char *v6; // rbp
void *v7; // r12
int v8; // ebx
char *v9; // rbx

v6 = (char *)memory_region(130LL);
v7 = (void *)memory_region(154LL);
v8 = (int)memory_region_length(130LL) / 2;
if ( v7 )
memcpy(v7, v6, 0x8000uLL);
v9 = &v6[v8];
memory_set_opcode_base(1LL, v9);
kabuki_decode((unsigned __int8 *)v6, v9, v6, 0, 0x8000, a1, a2, a3, a4);
}

canonical_decompiled_code:
void __fastcall func5(int a1, int a2, int a3, int a4)
{
char *v6; // rbp
void *v7; // r12
int v8; // ebx
char *v9; // rbx

v6 = (char *)memory_region(130LL);
v7 = (void *)memory_region(154LL);
v8 = (int)memory_region_length(130LL) / 2;
if ( v7 )
memcpy(v7, v6, 0x8000uLL);
v9 = &v6[v8];
memory_set_opcode_base(1LL, v9);
func3((unsigned __int8 *)v6, v9, v6, 0, 0x8000, a1, a2, a3, a4);
}

original_code:
static void cps1_decode(int swap_key1,int swap_key2,int addr_key,int xor_key)
{
 unsigned char *rom = memory_region(REGION_CPU2);
 unsigned char *backup = memory_region(REGION_USER1);
 int diff = memory_region_length(REGION_CPU2) / 2;
 if (backup) memcpy(backup,rom,0x8000);
 memory_set_opcode_base(1,rom+diff);
 kabuki_decode(rom,rom+diff,rom,0x0000,0x8000, swap_key1,swap_key2,addr_key,xor_key);
}

canonical_original_code:
static void cps1_decode(int swap_key1, int swap_key2, int addr_key, int xor_key)
{
 unsigned char *rom = memory_region(REGION_CPU2);
 unsigned char *backup = memory_region(REGION_USER1);
 int diff = memory_region_length(REGION_CPU2) / 2;
 if (backup) memcpy(backup,rom,0x8000);
 memory_set_opcode_base(1,rom+diff);
 kabuki_decode(rom,rom+diff,rom,0x0000,0x8000, swap_key1,swap_key2,addr_key,xor_key);
}

variable_types:
backup
unsigned char *


original_code: void mgakuen2_decode(void) { mitchell_decode(0x76543210,0x01234567,0xaa55,0xa5); }

canonical_original_code: void mgakuen2_decode() { mitchell_decode(0x76543210,0x01234567,0xaa55,0xa5); }


original_code: void cworld_decode(void) { mitchell_decode(0x04152637,0x40516273,0x5751,0x43); }


original_code: void hatena_decode(void) { mitchell_decode(0x45670123,0x45670123,0x5751,0x43); }


original_code: void sbbros_decode(void) { mitchell_decode(0x45670123,0x45670123,0x2130,0x12); }


original_code: void marukin_decode(void) { mitchell_decode(0x54321076,0x54321076,0x4854,0x4f); }


original_code: void qsangoku_decode(void) { mitchell_decode(0x23456701,0x23456701,0x1828,0x18); }


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

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

original_code:
data_t superqix_bitmapram_r(offs_t offset)
{
 return superqix_bitmapram[offset];
}

canonical_original_code:
unsigned int superqix_bitmapram_r(unsigned int offset)
{
 return superqix_bitmapram[offset];
}

variable_types:
offset
unsigned int


decompiled_code:
unsigned __int64 __fastcall superqix_bitmapram_w(unsigned int a1, int a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // rdx
int v4; // eax
int v5; // edi

result = a1;
v3 = (char *)superqix_bitmapram + a1;
if ( (unsigned __int8)*v3 != a2 )
{
*v3 = a2;
*((_BYTE *)superqix_bitmapram_dirty + a1) = 1;
v4 = a1 & 0x7F;
v5 = a1 >> 7;
if ( sqix_minx > v4 )
sqix_minx = v4;
if ( sqix_maxx < v4 )
sqix_maxx = v4;
if ( sqix_miny > v5 )
sqix_miny = v5;
result = (unsigned __int64)&sqix_maxy;
if ( sqix_maxy < v5 )
sqix_maxy = v5;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned int a1, int a2)
{
unsigned __int64 result; // rax
_BYTE *v3; // rdx
int v4; // eax
int v5; // edi

result = a1;
v3 = (char *)superqix_bitmapram + a1;
if ( (unsigned __int8)*v3 != a2 )
{
*v3 = a2;
*((_BYTE *)superqix_bitmapram_dirty + a1) = 1;
v4 = a1 & 0x7F;
v5 = a1 >> 7;
if ( sqix_minx > v4 )
sqix_minx = v4;
if ( sqix_maxx < v4 )
sqix_maxx = v4;
if ( sqix_miny > v5 )
sqix_miny = v5;
result = (unsigned __int64)&sqix_maxy;
if ( sqix_maxy < v5 )
sqix_maxy = v5;
}
return result;
}

original_code:
void superqix_bitmapram_w(offs_t offset,data_t data)
{
 if(data != superqix_bitmapram[offset])
 {
  int x,y;
  superqix_bitmapram[offset] = data;
  superqix_bitmapram_dirty[offset] = 1;
  x=offset%128;
  y=offset/128;
  if(x<sqix_minx) sqix_minx=x;
  if(x>sqix_maxx) sqix_maxx=x;
  if(y<sqix_miny) sqix_miny=y;
  if(y>sqix_maxy) sqix_maxy=y;
 }
}

canonical_original_code:
void superqix_bitmapram_w(unsigned int offset, unsigned int data)
{
 if(data != superqix_bitmapram[offset])
 {
  int x; int y;
  superqix_bitmapram[offset] = data;
  superqix_bitmapram_dirty[offset] = 1;
  x=offset%128;
  y=offset/128;
  if(x<sqix_minx) sqix_minx=x;
  if(x>sqix_maxx) sqix_maxx=x;
  if(y<sqix_miny) sqix_miny=y;
  if(y>sqix_maxy) sqix_maxy=y;
 }
}

variable_types:
data
unsigned int

variable_types: y int


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

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

original_code:
data_t superqix_bitmapram2_r(offs_t offset)
{
 return superqix_bitmapram2[offset];
}

canonical_original_code:
unsigned int superqix_bitmapram2_r(unsigned int offset)
{
 return superqix_bitmapram2[offset];
}


decompiled_code:
int *__fastcall superqix_bitmapram2_w(unsigned int a1, int a2)
{
int *result; // rax
_BYTE *v3; // rdx
int v4; // eax
int v5; // edi

result = (int *)a1;
v3 = (char *)superqix_bitmapram2 + a1;
if ( (unsigned __int8)*v3 != a2 )
{
*v3 = a2;
*((_BYTE *)superqix_bitmapram2_dirty + a1) = 1;
v4 = a1 & 0x7F;
v5 = a1 >> 7;
if ( sqix_minx > v4 )
sqix_minx = v4;
if ( sqix_maxx < v4 )
sqix_maxx = v4;
if ( sqix_miny > v5 )
sqix_miny = v5;
result = &sqix_maxy;
if ( sqix_maxy < v5 )
sqix_maxy = v5;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func3(unsigned int a1, int a2)
{
int *result; // rax
_BYTE *v3; // rdx
int v4; // eax
int v5; // edi

result = (int *)a1;
v3 = (char *)superqix_bitmapram2 + a1;
if ( (unsigned __int8)*v3 != a2 )
{
*v3 = a2;
*((_BYTE *)superqix_bitmapram2_dirty + a1) = 1;
v4 = a1 & 0x7F;
v5 = a1 >> 7;
if ( sqix_minx > v4 )
sqix_minx = v4;
if ( sqix_maxx < v4 )
sqix_maxx = v4;
if ( sqix_miny > v5 )
sqix_miny = v5;
result = &sqix_maxy;
if ( sqix_maxy < v5 )
sqix_maxy = v5;
}
return result;
}

original_code:
void superqix_bitmapram2_w(offs_t offset,data_t data)
{
 if(data != superqix_bitmapram2[offset])
 {
  int x,y;
  superqix_bitmapram2[offset] = data;
  superqix_bitmapram2_dirty[offset] = 1;
  x=offset%128;
  y=offset/128;
  if(x<sqix_minx) sqix_minx=x;
  if(x>sqix_maxx) sqix_maxx=x;
  if(y<sqix_miny) sqix_miny=y;
  if(y>sqix_maxy) sqix_maxy=y;
 }
}

canonical_original_code:
void superqix_bitmapram2_w(unsigned int offset, unsigned int data)
{
 if(data != superqix_bitmapram2[offset])
 {
  int x; int y;
  superqix_bitmapram2[offset] = data;
  superqix_bitmapram2_dirty[offset] = 1;
  x=offset%128;
  y=offset/128;
  if(x<sqix_minx) sqix_minx=x;
  if(x>sqix_maxx) sqix_maxx=x;
  if(y<sqix_miny) sqix_miny=y;
  if(y>sqix_maxy) sqix_maxy=y;
 }
}

variable_types: x int