decompiled_code:
__int64 __fastcall blitscreen_dirty0_color8(__int64 a1)
{
_QWORD *v1; // rax
int v2; // ebp
__int64 v3; // r11
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // rsi
int v7; // ebx
__int64 v8; // r10
int v9; // er9

v1 = *(_QWORD **)(a1 + 24);
v2 = gfx_display_columns;
v3 = v1[1] - *v1;
v4 = v1[skiplines] + skipcolumns;
result = (int)gfx_width;
v6 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
v7 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v8 = 2LL * (int)gfx_width;
v9 = 0;
do
{
if ( v2 > 0 )
{
for ( result = 0LL; result != v2; ++result )
*(_WORD *)(v6 + 2 * result) = gp2x_palette[*(unsigned __int8 *)(v4 + result)];
}
++v9;
v4 += (int)v3;
v6 += v8;
}
while ( v9 != v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_QWORD *v1; // rax
int v2; // ebp
__int64 v3; // r11
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // rsi
int v7; // ebx
__int64 v8; // r10
int v9; // er9

v1 = *(_QWORD **)(a1 + 24);
v2 = gfx_display_columns;
v3 = v1[1] - *v1;
v4 = v1[skiplines] + skipcolumns;
result = (int)gfx_width;
v6 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
v7 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v8 = 2LL * (int)gfx_width;
v9 = 0;
do
{
if ( v2 > 0 )
{
for ( result = 0LL; result != v2; ++result )
*(_WORD *)(v6 + 2 * result) = gp2x_palette[*(unsigned __int8 *)(v4 + result)];
}
++v9;
v4 += (int)v3;
v6 += v8;
}
while ( v9 != v7 );
}
return result;
}

original_code:
void blitscreen_dirty0_color8(struct osd_bitmap *bitmap)
{
 int x,y;
 int width=(bitmap->line[1] - bitmap->line[0]);
 int columns=gfx_display_columns;
 unsigned char *lb = bitmap->line[skiplines] + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = gp2x_palette[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty0_color8(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0]);
 int columns = gfx_display_columns;
 unsigned char *lb = bitmap->line[skiplines] + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = gp2x_palette[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

variable_types: columns int


decompiled_code:
__int64 __fastcall blitscreen_dirty1_palettized16(__int64 a1)
{
_QWORD *v1; // rdx
__int64 result; // rax
int v3; // er12
__int64 v4; // r14
__int64 v5; // r13
int v6; // er10
__int64 v7; // rbx
__int64 v8; // r15
__int64 v9; // r8
int v10; // ebp
int v11; // er11
int v12; // edx
int v13; // ecx
__int64 v14; // rsi
__int64 v15; // rdi
__int64 i; // rsi
int v17; // er9
__int64 v18; // [rsp+0h] [rbp-60h]
__int64 v19; // [rsp+8h] [rbp-58h]
int v20; // [rsp+14h] [rbp-4Ch]
__int64 v21; // [rsp+18h] [rbp-48h]
__int64 v22; // [rsp+20h] [rbp-40h]
int v23; // [rsp+28h] [rbp-38h]
unsigned int v24; // [rsp+2Ch] [rbp-34h]

v1 = *(_QWORD **)(a1 + 24);
result = (__int64)(v1[1] - *v1) >> 1;
v18 = v1[skiplines] + 2LL * skipcolumns;
v19 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
v23 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v3 = 16;
v4 = 2LL * (int)result;
v5 = 2LL * (int)gfx_width;
v6 = gfx_display_columns;
v7 = dirty_new;
v8 = dirty_old;
v9 = palette_16bit_lookup;
v21 = 32LL * (_DWORD)result;
v22 = 2LL * (int)(16 * gfx_width);
v24 = ((gfx_display_lines - 1) & 0xFFFFFFF0) + 32;
do
{
result = (unsigned int)(v3 - 16);
v10 = 0;
v20 = result;
v11 = (int)result >> 4 << 8;
while ( v6 > v10 )
{
while ( 1 )
{
v12 = v10 + 16;
result = v11 + (v10 >> 4);
if ( *(_BYTE *)(v7 + result) || *(_BYTE *)(v8 + result) )
break;
v10 += 16;
if ( v6 <= v12 )
goto LABEL_20;
}
result = v18;
v13 = 16;
v14 = 2LL * v10;
v15 = v18 + v14;
for ( i = v19 + v14; v6 > v12; v13 += 16 )
{
result = v11 + (v12 >> 4);
if ( !*(_BYTE *)(v7 + result) && !*(_BYTE *)(v8 + result) )
break;
v12 += 16;
}
if ( v6 < v12 )
{
v13 = v6 - v10;
v10 = v6;
}
else
{
v10 += v13;
}
v17 = v20;
do
{
if ( v23 <= v17 )
break;
result = 0LL;
do
{
*(_WORD *)(i + 2 * result) = *(_DWORD *)(v9 + 4LL * *(unsigned __int16 *)(v15 + 2 * result));
++result;
}
while ( v13 != result );
++v17;
v15 += v4;
i += v5;
}
while ( v3 != v17 );
}
LABEL_20:
v3 += 16;
v18 += v21;
v19 += v22;
}
while ( v24 != v3 );
}
return result;
}

original_code:
void blitscreen_dirty1_palettized16(struct osd_bitmap *bitmap)
{
 int x, y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb=((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address=gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = palette_16bit_lookup[lb0[wx]];
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty1_palettized16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = palette_16bit_lookup[lb0[wx]];
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

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

variable_types: x int

variable_types: y int

variable_types: width int

variable_types:
lb
unsigned short *

variable_types:
address
unsigned short *

variable_types: w int

variable_types: h int

variable_types: wx int

return_type: void


decompiled_code:
int *__fastcall blitscreen_dirty0_palettized16(__int64 a1)
{
_QWORD *v1; // rax
int v2; // ebx
__int64 v3; // r11
__int64 v4; // rcx
__int64 v5; // rsi
int *result; // rax
int v7; // ebp
__int64 v8; // r10
int v9; // er9
__int64 v10; // r11
__int64 v11; // r8

v1 = *(_QWORD **)(a1 + 24);
v2 = gfx_display_columns;
v3 = (__int64)(v1[1] - *v1) >> 1;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
v7 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v8 = 2LL * (int)gfx_width;
v9 = 0;
v10 = 2LL * (int)v3;
v11 = palette_16bit_lookup;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
*(_WORD *)(v5 + 2LL * (_QWORD)result) = *(_DWORD *)(v11
+ 4LL * *(unsigned __int16 *)(v4 + 2LL * (_QWORD)result));
result = (int *)((char *)result + 1);
}
while ( (int *)v2 != result );
}
++v9;
v4 += v10;
v5 += v8;
}
while ( v9 != v7 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func3(__int64 a1)
{
_QWORD *v1; // rax
int v2; // ebx
__int64 v3; // r11
__int64 v4; // rcx
__int64 v5; // rsi
int *result; // rax
int v7; // ebp
__int64 v8; // r10
int v9; // er9
__int64 v10; // r11
__int64 v11; // r8

v1 = *(_QWORD **)(a1 + 24);
v2 = gfx_display_columns;
v3 = (__int64)(v1[1] - *v1) >> 1;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
v7 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v8 = 2LL * (int)gfx_width;
v9 = 0;
v10 = 2LL * (int)v3;
v11 = palette_16bit_lookup;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
*(_WORD *)(v5 + 2LL * (_QWORD)result) = *(_DWORD *)(v11
+ 4LL * *(unsigned __int16 *)(v4 + 2LL * (_QWORD)result));
result = (int *)((char *)result + 1);
}
while ( (int *)v2 != result );
}
++v9;
v4 += v10;
v5 += v8;
}
while ( v9 != v7 );
}
return result;
}

original_code:
void blitscreen_dirty0_palettized16(struct osd_bitmap *bitmap)
{
 int x,y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 int columns=gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = palette_16bit_lookup[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty0_palettized16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 int columns = gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = palette_16bit_lookup[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

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


original_code:
void blitscreen_dirty1_color16(struct osd_bitmap *bitmap)
{
 int x, y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb=((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address=gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = lb0[wx]&0xFFDF;
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty1_color16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = lb0[wx]&0xFFDF;
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}


decompiled_code:
int *__fastcall blitscreen_dirty0_color16(__int64 a1)
{
_QWORD *v1; // rax
int v2; // ebx
__int64 v3; // r10
__int64 v4; // rcx
__int64 v5; // rsi
int *result; // rax
int v7; // er11
__int64 v8; // r9
int v9; // er8
__int64 v10; // r10

v1 = *(_QWORD **)(a1 + 24);
v2 = gfx_display_columns;
v3 = (__int64)(v1[1] - *v1) >> 1;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
v7 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v8 = 2LL * (int)gfx_width;
v9 = 0;
v10 = 2LL * (int)v3;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
*(_WORD *)(v5 + 2LL * (_QWORD)result) = *(_WORD *)(v4 + 2LL * (_QWORD)result) & 0xFFDF;
result = (int *)((char *)result + 1);
}
while ( (int *)v2 != result );
}
++v9;
v4 += v10;
v5 += v8;
}
while ( v9 != v7 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func5(__int64 a1)
{
_QWORD *v1; // rax
int v2; // ebx
__int64 v3; // r10
__int64 v4; // rcx
__int64 v5; // rsi
int *result; // rax
int v7; // er11
__int64 v8; // r9
int v9; // er8
__int64 v10; // r10

v1 = *(_QWORD **)(a1 + 24);
v2 = gfx_display_columns;
v3 = (__int64)(v1[1] - *v1) >> 1;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
v7 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v8 = 2LL * (int)gfx_width;
v9 = 0;
v10 = 2LL * (int)v3;
do
{
result = 0LL;
if ( v2 > 0 )
{
do
{
*(_WORD *)(v5 + 2LL * (_QWORD)result) = *(_WORD *)(v4 + 2LL * (_QWORD)result) & 0xFFDF;
result = (int *)((char *)result + 1);
}
while ( (int *)v2 != result );
}
++v9;
v4 += v10;
v5 += v8;
}
while ( v9 != v7 );
}
return result;
}

original_code:
void blitscreen_dirty0_color16(struct osd_bitmap *bitmap)
{
 int x,y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 int columns=gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = lb[x]&0xFFDF;
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty0_color16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 int columns = gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = lb[x]&0xFFDF;
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}


decompiled_code:
__int64 lkage_68705_portA_r()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

canonical_decompiled_code:
__int64 func0()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

original_code:
data_t lkage_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

canonical_original_code:
unsigned int lkage_68705_portA_r(unsigned int offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall lkage_68705_portA_w(__int64 a1, char a2)
{
portA_out = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
portA_out = a2;
}

original_code:
void lkage_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

canonical_original_code:
void lkage_68705_portA_w(unsigned int offset, unsigned int data)
{
 portA_out = data;
}

variable_types:
data
unsigned int


decompiled_code:
void __fastcall lkage_68705_ddrA_w(__int64 a1, char a2)
{
ddrA = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
ddrA = a2;
}

original_code:
void lkage_68705_ddrA_w(offs_t offset,data_t data)
{
 ddrA = data;
}

canonical_original_code:
void lkage_68705_ddrA_w(unsigned int offset, unsigned int data)
{
 ddrA = data;
}


decompiled_code:
__int64 lkage_68705_portB_r()
{
return (unsigned __int8)(ddrB & portB_out);
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)(ddrB & portB_out);
}

original_code:
data_t lkage_68705_portB_r(offs_t offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}

canonical_original_code:
unsigned int lkage_68705_portB_r(unsigned int offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}


decompiled_code:
void __fastcall lkage_68705_ddrB_w(__int64 a1, char a2)
{
ddrB = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, char a2)
{
ddrB = a2;
}

original_code:
void lkage_68705_ddrB_w(offs_t offset,data_t data)
{
 ddrB = data;
}

canonical_original_code:
void lkage_68705_ddrB_w(unsigned int offset, unsigned int data)
{
 ddrB = data;
}


decompiled_code:
__int64 lkage_68705_portC_r()
{
unsigned __int8 v0; // cl

portC_in = 0;
v0 = 0;
if ( main_sent )
{
portC_in = 1;
v0 = 1;
}
if ( !mcu_sent )
{
v0 |= 2u;
portC_in = v0;
}
return (unsigned __int8)(ddrC & portC_out) | v0 & ~(unsigned __int8)ddrC;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int8 v0; // cl

portC_in = 0;
v0 = 0;
if ( main_sent )
{
portC_in = 1;
v0 = 1;
}
if ( !mcu_sent )
{
v0 |= 2u;
portC_in = v0;
}
return (unsigned __int8)(ddrC & portC_out) | v0 & ~(unsigned __int8)ddrC;
}

original_code:
data_t lkage_68705_portC_r(offs_t offset)
{
 portC_in = 0;
 if (main_sent) portC_in |= 0x01;
 if (!mcu_sent) portC_in |= 0x02;
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}

canonical_original_code:
unsigned int lkage_68705_portC_r(unsigned int offset)
{
 portC_in = 0;
 if (main_sent) portC_in |= 0x01;
 if (!mcu_sent) portC_in |= 0x02;
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}


decompiled_code:
void __fastcall lkage_68705_portC_w(__int64 a1, char a2)
{
portC_out = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char a2)
{
portC_out = a2;
}

original_code:
void lkage_68705_portC_w(offs_t offset,data_t data)
{
 portC_out = data;
}

canonical_original_code:
void lkage_68705_portC_w(unsigned int offset, unsigned int data)
{
 portC_out = data;
}


decompiled_code:
void __fastcall lkage_68705_ddrC_w(__int64 a1, char a2)
{
ddrC = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, char a2)
{
ddrC = a2;
}

original_code:
void lkage_68705_ddrC_w(offs_t offset,data_t data)
{
 ddrC = data;
}

canonical_original_code:
void lkage_68705_ddrC_w(unsigned int offset, unsigned int data)
{
 ddrC = data;
}


decompiled_code:
__int64 lkage_mcu_r()
{
mcu_sent = 0;
return (unsigned __int8)from_mcu;
}

canonical_decompiled_code:
__int64 func8()
{
mcu_sent = 0;
return (unsigned __int8)from_mcu;
}

original_code:
data_t lkage_mcu_r(offs_t offset)
{
 mcu_sent = 0;
 return from_mcu;
}

canonical_original_code:
unsigned int lkage_mcu_r(unsigned int offset)
{
 mcu_sent = 0;
 return from_mcu;
}


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

result = main_sent == 0;
if ( mcu_sent )
result = (unsigned int)result | 2;
return result;
}

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

result = main_sent == 0;
if ( mcu_sent )
result = (unsigned int)result | 2;
return result;
}

original_code:
data_t lkage_mcu_status_r(offs_t offset)
{
 int res = 0;
 if (!main_sent) res |= 0x01;
 if (mcu_sent) res |= 0x02;
 return res;
}

canonical_original_code:
unsigned int lkage_mcu_status_r(unsigned int offset)
{
 int res = 0;
 if (!main_sent) res |= 0x01;
 if (mcu_sent) res |= 0x02;
 return res;
}

variable_types: res int


decompiled_code:
void lkage_sh_nmi_disable_w()
{
sound_nmi_enable = 0;
}

canonical_decompiled_code:
void func13()
{
sound_nmi_enable = 0;
}

original_code:
void lkage_sh_nmi_disable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 0;
}

canonical_original_code:
void lkage_sh_nmi_disable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 0;
}


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

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

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

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


decompiled_code:
__int64 fake_status_r()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func15()
{
return 3LL;
}

original_code:
static data_t fake_status_r(offs_t offset)
{
 return 3;
}

canonical_original_code:
static unsigned int fake_status_r(unsigned int offset)
{
 return 3;
}


decompiled_code:
__int64 __fastcall lkage_68705_portB_w(__int64 a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)ddrB;
if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
portA_in = from_main;
if ( main_sent )
{
cpu_set_irq_line(2LL, 0LL, 0LL);
result = (unsigned __int8)ddrB;
}
main_sent = 0;
}
if ( (result & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
{
result = (unsigned __int8)portA_out;
mcu_sent = 1;
from_mcu = portA_out;
}
portB_out = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char a2)
{
__int64 result; // rax

result = (unsigned __int8)ddrB;
if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
portA_in = from_main;
if ( main_sent )
{
cpu_set_irq_line(2LL, 0LL, 0LL);
result = (unsigned __int8)ddrB;
}
main_sent = 0;
}
if ( (result & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
{
result = (unsigned __int8)portA_out;
mcu_sent = 1;
from_mcu = portA_out;
}
portB_out = a2;
return result;
}

original_code:
void lkage_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
 {
  portA_in = from_main;
  if (main_sent) cpu_set_irq_line(2,0,0);
  main_sent = 0;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  from_mcu = portA_out;
  mcu_sent = 1;
 }
 portB_out = data;
}

canonical_original_code:
void lkage_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
 {
  portA_in = from_main;
  if (main_sent) cpu_set_irq_line(2,0,0);
  main_sent = 0;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  from_mcu = portA_out;
  mcu_sent = 1;
 }
 portB_out = data;
}


decompiled_code:
__int64 __fastcall lkage_mcu_w(__int64 a1, char a2)
{
from_main = a2;
main_sent = 1;
return cpu_set_irq_line(2LL, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char a2)
{
from_main = a2;
main_sent = 1;
return cpu_set_irq_line(2LL, 0LL, 1LL);
}

original_code:
void lkage_mcu_w(offs_t offset,data_t data)
{
 from_main = data;
 main_sent = 1;
 cpu_set_irq_line(2,0,1);
}

canonical_original_code:
void lkage_mcu_w(unsigned int offset, unsigned int data)
{
 from_main = data;
 main_sent = 1;
 cpu_set_irq_line(2,0,1);
}


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

result = videoram + a1;
if ( *(unsigned __int8 *)result != a2 )
{
*(_BYTE *)result = a2;
result = a1 >> 10;
switch ( (_DWORD)result )
{
case 1:
result = tilemap_mark_tile_dirty(fg_tilemap, a1 & 0x3FF);
break;
case 2:
result = tilemap_mark_tile_dirty(bg_tilemap, a1 & 0x3FF);
break;
case 0:
result = tilemap_mark_tile_dirty(tx_tilemap, a1);
break;
}
}
return result;
}

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

result = videoram + a1;
if ( *(unsigned __int8 *)result != a2 )
{
*(_BYTE *)result = a2;
result = a1 >> 10;
switch ( (_DWORD)result )
{
case 1:
result = tilemap_mark_tile_dirty(fg_tilemap, a1 & 0x3FF);
break;
case 2:
result = tilemap_mark_tile_dirty(bg_tilemap, a1 & 0x3FF);
break;
case 0:
result = tilemap_mark_tile_dirty(tx_tilemap, a1);
break;
}
}
return result;
}

original_code:
void lkage_videoram_w(offs_t offset,data_t data)
{
 if( videoram[offset]!=data )
 {
  videoram[offset] = data;
  switch( offset/0x400 )
  {
   case 0:
   tilemap_mark_tile_dirty(tx_tilemap,offset & 0x3ff);
   break;
   case 1:
   tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
   break;
   case 2:
   tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
   break;
  }
 }
}

canonical_original_code:
void lkage_videoram_w(unsigned int offset, unsigned int data)
{
 if( videoram[offset]!=data )
 {
  videoram[offset] = data;
  switch( offset/0x400 )
  {
   case 0:
   tilemap_mark_tile_dirty(tx_tilemap,offset & 0x3ff);
   break;
   case 1:
   tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
   break;
   case 2:
   tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
   break;
  }
 }
}


decompiled_code:
__int64 lkage_vh_start()
{
__int64 v0; // rdi
__int64 v2; // [rsp+0h] [rbp-28h]
__int64 v3; // [rsp+0h] [rbp-28h]

fg_tile_bank = 0;
bg_tile_bank = 0;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
LODWORD(v3) = 32;
v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
tx_tilemap = v0;
if ( !bg_tilemap || !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132LL) = 0;
*(_DWORD *)(v0 + 132) = 0;
tilemap_set_scrolldx(v0, 4294967287LL, 15LL);
tilemap_set_scrolldx(fg_tilemap, 4294967281LL, 13LL);
tilemap_set_scrolldx(bg_tilemap, 4294967283LL, 19LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
__int64 v0; // rdi
__int64 v2; // [rsp+0h] [rbp-28h]
__int64 v3; // [rsp+0h] [rbp-28h]

fg_tile_bank = 0;
bg_tile_bank = 0;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
LODWORD(v3) = 32;
v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
tx_tilemap = v0;
if ( !bg_tilemap || !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132LL) = 0;
*(_DWORD *)(v0 + 132) = 0;
tilemap_set_scrolldx(v0, 4294967287LL, 15LL);
tilemap_set_scrolldx(fg_tilemap, 4294967281LL, 13LL);
tilemap_set_scrolldx(bg_tilemap, 4294967283LL, 19LL);
return 0LL;
}

original_code:
int lkage_vh_start(void)
{
 bg_tile_bank = fg_tile_bank = 0;
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 tx_tilemap->transparent_pen = 0;
 tilemap_set_scrolldx(tx_tilemap,-9,15);
 tilemap_set_scrolldx(fg_tilemap,-15,13);
 tilemap_set_scrolldx(bg_tilemap,-13,19);
 return 0;
}

canonical_original_code:
int lkage_vh_start()
{
 bg_tile_bank = fg_tile_bank = 0;
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 tx_tilemap->transparent_pen = 0;
 tilemap_set_scrolldx(tx_tilemap,-9,15);
 tilemap_set_scrolldx(fg_tilemap,-15,13);
 tilemap_set_scrolldx(bg_tilemap,-13,19);
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall lkage_sound_command_w(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

original_code:
void lkage_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}

canonical_original_code:
void lkage_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}


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

sound_nmi_enable = 1;
result = (unsigned int)pending_nmi;
if ( pending_nmi )
{
result = cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

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

sound_nmi_enable = 1;
result = (unsigned int)pending_nmi;
if ( pending_nmi )
{
result = cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

original_code:
void lkage_sh_nmi_enable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(1,-2);
  pending_nmi = 0;
 }
}

canonical_original_code:
void lkage_sh_nmi_enable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(1,-2);
  pending_nmi = 0;
 }
}


decompiled_code:
__int64 init_lkageb()
{
install_mem_read_handler(0LL, 61538LL, 61538LL, fake_mcu_r);
return install_mem_read_handler(0LL, 61575LL, 61575LL, fake_status_r);
}

canonical_decompiled_code:
__int64 func25()
{
install_mem_read_handler(0LL, 61538LL, 61538LL, fake_mcu_r);
return install_mem_read_handler(0LL, 61575LL, 61575LL, fake_status_r);
}

original_code:
void init_lkageb(void)
{
 install_mem_read_handler(0,0xf062,0xf062,fake_mcu_r);
 install_mem_read_handler(0,0xf087,0xf087,fake_status_r);
}

canonical_original_code:
void init_lkageb()
{
 install_mem_read_handler(0,0xf062,0xf062,fake_mcu_r);
 install_mem_read_handler(0,0xf087,0xf087,fake_status_r);
}


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

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

original_code:
static data_t port_fetch_r(offs_t offset)
{
 return memory_region(REGION_USER1)[offset];
}

canonical_original_code:
static unsigned int port_fetch_r(unsigned int offset)
{
 return memory_region(REGION_USER1)[offset];
}


decompiled_code:
__int64 __fastcall lkage_vh_screenrefresh(__int64 a1)
{
_BYTE *v1; // rdx
__int64 v2; // rdx

flip_screen_x_w(0LL, (*(_BYTE *)(lkage_vreg + 2LL) & 1) == 0);
flip_screen_y_w(0LL, ~*(_BYTE *)(lkage_vreg + 2LL) & 2);
v1 = (_BYTE *)lkage_vreg;
if ( bg_tile_bank != (*(_BYTE *)(lkage_vreg + 1LL) & 8) )
{
bg_tile_bank = *(_BYTE *)(lkage_vreg + 1LL) & 8;
tilemap_mark_all_tiles_dirty(bg_tilemap);
v1 = (_BYTE *)lkage_vreg;
}
if ( fg_tile_bank != (*v1 & 4) )
{
fg_tile_bank = *v1 & 4;
tilemap_mark_all_tiles_dirty(fg_tilemap);
}
lkage_set_palette_row(0, 0, 128);
lkage_set_palette_row(8, (unsigned __int8)((*(_BYTE *)(lkage_vreg + 1LL) >> 4) + 48), 16);
lkage_set_palette_row(9, (unsigned __int8)((*(_BYTE *)(lkage_vreg + 1LL) >> 4) + 32), 16);
lkage_set_palette_row(10, 17, 16);
tilemap_set_scrollx(tx_tilemap, 0LL, (unsigned __int8)*lkage_scroll);
tilemap_set_scrolly(tx_tilemap, 0LL, (unsigned __int8)lkage_scroll[1]);
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[2]);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[3]);
tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[4]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[5]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 16LL;
if ( (*(_BYTE *)(lkage_vreg + 2LL) & 0xF0) == 0xF0 )
{
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1, 1u);
tilemap_draw(a1, fg_tilemap, 0LL);
draw_sprites(a1, 0);
v2 = 0LL;
}
return tilemap_draw(a1, tx_tilemap, v2);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1)
{
_BYTE *v1; // rdx
__int64 v2; // rdx

flip_screen_x_w(0LL, (*(_BYTE *)(lkage_vreg + 2LL) & 1) == 0);
flip_screen_y_w(0LL, ~*(_BYTE *)(lkage_vreg + 2LL) & 2);
v1 = (_BYTE *)lkage_vreg;
if ( bg_tile_bank != (*(_BYTE *)(lkage_vreg + 1LL) & 8) )
{
bg_tile_bank = *(_BYTE *)(lkage_vreg + 1LL) & 8;
tilemap_mark_all_tiles_dirty(bg_tilemap);
v1 = (_BYTE *)lkage_vreg;
}
if ( fg_tile_bank != (*v1 & 4) )
{
fg_tile_bank = *v1 & 4;
tilemap_mark_all_tiles_dirty(fg_tilemap);
}
lkage_set_palette_row(0, 0, 128);
lkage_set_palette_row(8, (unsigned __int8)((*(_BYTE *)(lkage_vreg + 1LL) >> 4) + 48), 16);
lkage_set_palette_row(9, (unsigned __int8)((*(_BYTE *)(lkage_vreg + 1LL) >> 4) + 32), 16);
lkage_set_palette_row(10, 17, 16);
tilemap_set_scrollx(tx_tilemap, 0LL, (unsigned __int8)*lkage_scroll);
tilemap_set_scrolly(tx_tilemap, 0LL, (unsigned __int8)lkage_scroll[1]);
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[2]);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[3]);
tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[4]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[5]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 16LL;
if ( (*(_BYTE *)(lkage_vreg + 2LL) & 0xF0) == 0xF0 )
{
tilemap_draw(a1, bg_tilemap, 0LL);
func21(a1, 1u);
tilemap_draw(a1, fg_tilemap, 0LL);
func21(a1, 0);
v2 = 0LL;
}
return tilemap_draw(a1, tx_tilemap, v2);
}

original_code:
void lkage_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 flip_screen_x_w(0,~lkage_vreg[2] & 0x01);
 flip_screen_y_w(0,~lkage_vreg[2] & 0x02);
 if( bg_tile_bank != (lkage_vreg[1]&0x08) )
 {
  bg_tile_bank = lkage_vreg[1]&0x08;
  tilemap_mark_all_tiles_dirty( bg_tilemap );
 }
 if( fg_tile_bank != (lkage_vreg[0]&0x04) )
 {
  fg_tile_bank = lkage_vreg[0]&0x04;
  tilemap_mark_all_tiles_dirty( fg_tilemap );
 }
 {
  lkage_set_palette_row( 0x0, 0x00, 16*8 );
  lkage_set_palette_row( 0x8, 0x30 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0x9, 0x20 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0xa, 0x11, 16 );
 }
 tilemap_set_scrollx(tx_tilemap,0,lkage_scroll[0]);
 tilemap_set_scrolly(tx_tilemap,0,lkage_scroll[1]);
 tilemap_set_scrollx(fg_tilemap,0,lkage_scroll[2]);
 tilemap_set_scrolly(fg_tilemap,0,lkage_scroll[3]);
 tilemap_set_scrollx(bg_tilemap,0,lkage_scroll[4]);
 tilemap_set_scrolly(bg_tilemap,0,lkage_scroll[5]);
 tilemap_update( 0 );
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 if ((lkage_vreg[2] & 0xf0) == 0xf0)
 {
  tilemap_draw( bitmap,bg_tilemap,0 );
  draw_sprites( bitmap, 1 );
  tilemap_draw( bitmap,fg_tilemap,0 );
  draw_sprites( bitmap, 0 );
  tilemap_draw( bitmap,tx_tilemap,0 );
 }
 else
 {
  tilemap_draw( bitmap,tx_tilemap,0x10 );
 }
}

canonical_original_code:
void lkage_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 flip_screen_x_w(0,~lkage_vreg[2] & 0x01);
 flip_screen_y_w(0,~lkage_vreg[2] & 0x02);
 if( bg_tile_bank != (lkage_vreg[1]&0x08) )
 {
  bg_tile_bank = lkage_vreg[1]&0x08;
  tilemap_mark_all_tiles_dirty( bg_tilemap );
 }
 if( fg_tile_bank != (lkage_vreg[0]&0x04) )
 {
  fg_tile_bank = lkage_vreg[0]&0x04;
  tilemap_mark_all_tiles_dirty( fg_tilemap );
 }
 {
  lkage_set_palette_row( 0x0, 0x00, 16*8 );
  lkage_set_palette_row( 0x8, 0x30 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0x9, 0x20 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0xa, 0x11, 16 );
 }
 tilemap_set_scrollx(tx_tilemap,0,lkage_scroll[0]);
 tilemap_set_scrolly(tx_tilemap,0,lkage_scroll[1]);
 tilemap_set_scrollx(fg_tilemap,0,lkage_scroll[2]);
 tilemap_set_scrolly(fg_tilemap,0,lkage_scroll[3]);
 tilemap_set_scrollx(bg_tilemap,0,lkage_scroll[4]);
 tilemap_set_scrolly(bg_tilemap,0,lkage_scroll[5]);
 tilemap_update( 0 );
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 if ((lkage_vreg[2] & 0xf0) == 0xf0)
 {
  tilemap_draw( bitmap,bg_tilemap,0 );
  draw_sprites( bitmap, 1 );
  tilemap_draw( bitmap,fg_tilemap,0 );
  draw_sprites( bitmap, 0 );
  tilemap_draw( bitmap,tx_tilemap,0 );
 }
 else
 {
  tilemap_draw( bitmap,tx_tilemap,0x10 );
 }
}


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rcx
unsigned int v2; // edx
__int64 v3; // rax
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = (*(unsigned __int8 *)(videoram + a1 + 2048LL) + (bg_tile_bank == 0 ? 0xFFFFFC00 : 0) + 1280)
% *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + (int)(v2 * *(_DWORD *)(v1 + 52));
v3 = *(_QWORD *)(v1 + 16);
v4 = *(_QWORD *)(v1 + 32);
*((_QWORD *)&tile_info + 1) = v3;
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v2);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int64 v1; // rcx
unsigned int v2; // edx
__int64 v3; // rax
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = (*(unsigned __int8 *)(videoram + a1 + 2048LL) + (bg_tile_bank == 0 ? 0xFFFFFC00 : 0) + 1280)
% *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + (int)(v2 * *(_DWORD *)(v1 + 52));
v3 = *(_QWORD *)(v1 + 16);
v4 = *(_QWORD *)(v1 + 32);
*((_QWORD *)&tile_info + 1) = v3;
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v2);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x800] + 256 * (bg_tile_bank?5:1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x800] + 256 * (bg_tile_bank?5:1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rcx
unsigned int v2; // eax
__int64 v3; // rdi
unsigned int v4; // edx
__int64 v5; // rax
__int64 v6; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = *(unsigned __int8 *)(videoram + a1 + 1024LL);
if ( fg_tile_bank )
v2 += 256;
v3 = *(int *)(v1 + 12);
v4 = v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + (int)(v4 * *(_DWORD *)(v1 + 52));
v5 = *(_QWORD *)(v1 + 16);
v6 = *(_QWORD *)(v1 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2 * v3;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rcx
unsigned int v2; // eax
__int64 v3; // rdi
unsigned int v4; // edx
__int64 v5; // rax
__int64 v6; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = *(unsigned __int8 *)(videoram + a1 + 1024LL);
if ( fg_tile_bank )
v2 += 256;
v3 = *(int *)(v1 + 12);
v4 = v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + (int)(v4 * *(_DWORD *)(v1 + 52));
v5 = *(_QWORD *)(v1 + 16);
v6 = *(_QWORD *)(v1 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2 * v3;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x400] + 256 * (fg_tile_bank?1:0)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (1)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x400] + 256 * (fg_tile_bank?1:0)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (1)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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


decompiled_code:
__int64 __fastcall get_tx_tile_info(int a1)
{
__int64 v1; // rcx
unsigned int v2; // eax
__int64 v3; // rdi
unsigned int v4; // edx
int v5; // eax
__int64 v6; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = *(unsigned __int8 *)(videoram + a1);
v3 = *(_QWORD *)(v1 + 16);
v4 = v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + (int)(v4 * *(_DWORD *)(v1 + 52));
v5 = *(_DWORD *)(v1 + 12);
v6 = *(_QWORD *)(v1 + 32);
*((_QWORD *)&tile_info + 1) = v3 + 4LL * v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 v1; // rcx
unsigned int v2; // eax
__int64 v3; // rdi
unsigned int v4; // edx
int v5; // eax
__int64 v6; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = *(unsigned __int8 *)(videoram + a1);
v3 = *(_QWORD *)(v1 + 16);
v4 = v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + (int)(v4 * *(_DWORD *)(v1 + 52));
v5 = *(_DWORD *)(v1 + 12);
v6 = *(_QWORD *)(v1 + 32);
*((_QWORD *)&tile_info + 1) = v3 + 4LL * v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tx_tile_info(int tile_index)
{
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index]) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tx_tile_info(int tile_index)
{
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index]) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}


irqhandler

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

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

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

variable_types: irq int


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

result = (unsigned int)sound_nmi_enable;
if ( sound_nmi_enable )
return cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 1;
return result;
}

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

result = (unsigned int)sound_nmi_enable;
if ( sound_nmi_enable )
return cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 1;
return result;
}

original_code:
static void nmi_callback(int param)
{
 if (sound_nmi_enable) cpu_cause_interrupt(1,-2);
 else pending_nmi = 1;
}

variable_types: param int


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

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

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

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


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

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

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

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


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

v2 = (_WORD *)(zoomdata + a1);
v3 = (unsigned __int16)*v2;
result = (void *)(v3 & HIWORD(a2));
v5 = (unsigned int)result | (unsigned __int16)a2;
if ( v3 != v5 )
{
result = dirtychar;
dirtygfx = 1;
*((_BYTE *)dirtychar + (a1 >> 7)) = 1;
*v2 = v5;
}
return result;
}

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

v2 = (_WORD *)(zoomdata + a1);
v3 = (unsigned __int16)*v2;
result = (void *)(v3 & HIWORD(a2));
v5 = (unsigned int)result | (unsigned __int16)a2;
if ( v3 != v5 )
{
result = dirtychar;
dirtygfx = 1;
*((_BYTE *)dirtychar + (a1 >> 7)) = 1;
*v2 = v5;
}
return result;
}

original_code:
void tail2nos_zoomdata_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&zoomdata[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  dirtygfx = 1;
  dirtychar[offset / 128] = 1;
  (*(UINT16 *)(&zoomdata[offset]) = (newword));
 }
}

canonical_original_code:
void tail2nos_zoomdata_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&zoomdata[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  dirtygfx = 1;
  dirtychar[offset / 128] = 1;
  (*(unsigned short *)(&zoomdata[offset]) = (newword));
 }
}

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 tail2nos_vh_start()
{
unsigned int v0; // er12

bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
if ( !bg_tilemap )
return 1LL;
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
return 1LL;
dirtychar = malloc(0x400uLL);
if ( !dirtychar )
{
K051316_vh_stop_0();
return 1LL;
}
memset(dirtychar, 1u, 0x400uLL);
*(_DWORD *)(bg_tilemap + 132) = 15;
K051316_wraparound_enable(0LL, 1LL);
K051316_set_offset(0LL, 4294967207LL, 4294967282LL);
zoomdata = memory_region(139LL);
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // er12

bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
if ( !bg_tilemap )
return 1LL;
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
return 1LL;
dirtychar = malloc(0x400uLL);
if ( !dirtychar )
{
K051316_vh_stop_0();
return 1LL;
}
memset(dirtychar, 1u, 0x400uLL);
*(_DWORD *)(bg_tilemap + 132) = 15;
K051316_wraparound_enable(0LL, 1LL);
K051316_set_offset(0LL, 4294967207LL, 4294967282LL);
zoomdata = memory_region(139LL);
return v0;
}

original_code:
int tail2nos_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x01,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
  return 1;
 if (!(dirtychar = (unsigned char*)malloc(0x400)))
 {
  K051316_vh_stop_0();
  return 1;
 }
 memset(dirtychar,1,0x400);
 bg_tilemap->transparent_pen = 15;
 K051316_wraparound_enable(0,1);
 K051316_set_offset(0,-89,-14);
 zoomdata = memory_region(REGION_GFX3);
 return 0;
}

canonical_original_code:
int tail2nos_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x01,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
  return 1;
 if (!(dirtychar = (unsigned char *)malloc(0x400)))
 {
  K051316_vh_stop_0();
  return 1;
 }
 memset(dirtychar,1,0x400);
 bg_tilemap->transparent_pen = 15;
 K051316_wraparound_enable(0,1);
 K051316_set_offset(0,-89,-14);
 zoomdata = memory_region(REGION_GFX3);
 return 0;
}


decompiled_code:
void tail2nos_vh_stop()
{
K051316_vh_stop_0();
free(dirtychar);
dirtychar = 0LL;
}

canonical_decompiled_code:
void func6()
{
K051316_vh_stop_0();
free(dirtychar);
dirtychar = 0LL;
}

original_code:
void tail2nos_vh_stop(void)
{
 K051316_vh_stop_0();
 free(dirtychar);
 dirtychar = 0;
}

canonical_original_code:
void tail2nos_vh_stop()
{
 K051316_vh_stop_0();
 free(dirtychar);
 dirtychar = 0;
}


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

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

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

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

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

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


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

if ( (a2 & 0xFF0000) == 0 )
{
v2 = a2 & 1;
if ( (a2 & 4) != 0 )
v2 = 2;
if ( charbank != v2 )
{
charbank = v2;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
if ( charpalette != ((a2 & 0x20) == 0 ? 3 : 7) )
{
charpalette = (a2 & 0x20) == 0 ? 3 : 7;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
video_enable = a2 & 0x10;
}
}

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

if ( (a2 & 0xFF0000) == 0 )
{
v2 = a2 & 1;
if ( (a2 & 4) != 0 )
v2 = 2;
if ( charbank != v2 )
{
charbank = v2;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
if ( charpalette != ((a2 & 0x20) == 0 ? 3 : 7) )
{
charpalette = (a2 & 0x20) == 0 ? 3 : 7;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
video_enable = a2 & 0x10;
}
}

original_code:
void tail2nos_gfxbank_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  int bank;
  if (data & 0x04) bank = 2;
  else if (data & 0x01) bank = 1;
  else bank = 0;
  if (charbank != bank)
  {
   charbank = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  if (data & 0x20) bank = 7;
  else bank = 3;
  if (charpalette != bank)
  {
   charpalette = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  video_enable = data & 0x10;
 }
}

canonical_original_code:
void tail2nos_gfxbank_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  int bank;
  if (data & 0x04) bank = 2;
  else if (data & 0x01) bank = 1;
  else bank = 0;
  if (charbank != bank)
  {
   charbank = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  if (data & 0x20) bank = 7;
  else bank = 3;
  if (charpalette != bank)
  {
   charpalette = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  video_enable = data & 0x10;
 }
}

variable_types: bank int


decompiled_code:
__int64 __fastcall tail2nos_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rsi

if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 1024; ++i )
{
while ( !*((_BYTE *)dirtychar + i) )
{
if ( ++i == 1024 )
goto LABEL_6;
}
*((_BYTE *)dirtychar + i) = 0;
v2 = (unsigned int)i;
decodechar(*(_QWORD *)(Machine + 528LL), v2, zoomdata, &tilelayout_0);
}
LABEL_6:
tilemap_mark_all_tiles_dirty(0LL);
}
K051316_tilemap_update_0();
tilemap_update(bg_tilemap);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( !video_enable )
return fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K051316_zoom_draw_0(a1, 0LL);
drawsprites(a1);
return tilemap_draw(a1, bg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rsi

if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 1024; ++i )
{
while ( !*((_BYTE *)dirtychar + i) )
{
if ( ++i == 1024 )
goto LABEL_6;
}
*((_BYTE *)dirtychar + i) = 0;
v2 = (unsigned int)i;
decodechar(*(_QWORD *)(Machine + 528LL), v2, zoomdata, &tilelayout_0);
}
LABEL_6:
tilemap_mark_all_tiles_dirty(0LL);
}
K051316_tilemap_update_0();
tilemap_update(bg_tilemap);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( !video_enable )
return fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K051316_zoom_draw_0(a1, 0LL);
func9(a1);
return tilemap_draw(a1, bg_tilemap, 0LL);
}

original_code:
void tail2nos_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 static struct GfxLayout tilelayout =
 {
  16,16,
  0x400,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4,
    10*4, 11*4, 8*4, 9*4, 14*4, 15*4, 12*4, 13*4 },
  { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
    8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
  128*8
 };
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x400;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[2],i,zoomdata,&tilelayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K051316_tilemap_update_0();
 tilemap_update(bg_tilemap);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (video_enable)
 {
  K051316_zoom_draw_0(bitmap,0);
  drawsprites(bitmap);
  tilemap_draw(bitmap,bg_tilemap,0);
 }
 else
  fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
}

canonical_original_code:
void tail2nos_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 static struct GfxLayout tilelayout = {
  16,16,
  0x400,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4,
    10*4, 11*4, 8*4, 9*4, 14*4, 15*4, 12*4, 13*4 },
  { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
    8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
  128*8
 };
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x400;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[2],i,zoomdata,&tilelayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K051316_tilemap_update_0();
 tilemap_update(bg_tilemap);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (video_enable)
 {
  K051316_zoom_draw_0(bitmap,0);
  drawsprites(bitmap);
  tilemap_draw(bitmap,bg_tilemap,0);
 }
 else
  fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
}

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

variable_types: struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; }

variable_types: i int


decompiled_code:
__int64 tail2nos_init_machine()
{
__int64 v0; // rax
bool v1; // zf
__int64 v2; // rax
__int64 result; // rax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

v0 = memory_region(154LL);
v1 = ophw == 1;
cpu_bankbase[1] = v0;
if ( v1 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
v2 = memory_region(155LL);
v1 = ophw == 2;
cpu_bankbase[2] = v2;
if ( v1 )
{
ophw = -1;
v6 = cpu_get_pc();
cpu_setOPbase16(v6);
}
result = memory_region(130LL) + 0x10000;
v1 = ophw == 9;
cpu_bankbase[9] = result;
if ( v1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
bool v1; // zf
__int64 v2; // rax
__int64 result; // rax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

v0 = memory_region(154LL);
v1 = ophw == 1;
cpu_bankbase[1] = v0;
if ( v1 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
v2 = memory_region(155LL);
v1 = ophw == 2;
cpu_bankbase[2] = v2;
if ( v1 )
{
ophw = -1;
v6 = cpu_get_pc();
cpu_setOPbase16(v6);
}
result = memory_region(130LL) + 0x10000;
v1 = ophw == 9;
cpu_bankbase[9] = result;
if ( v1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void tail2nos_init_machine(void)
{
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(memory_region(REGION_USER1)); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(memory_region(REGION_USER2)); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (UINT8 *)(memory_region(REGION_CPU2) + 0x10000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void tail2nos_init_machine()
{
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(memory_region(REGION_USER1)); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(memory_region(REGION_USER2)); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (unsigned char *)(memory_region(REGION_CPU2) + 0x10000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_ctrl_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void tail2nos_K051316_ctrl_0_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_0_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void tail2nos_K051316_ctrl_0_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_ctrl_0_w(offset >> 1, data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051316_0_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void tail2nos_K051316_0_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_0_w(offset >> 1, data & 0xff);
}

canonical_original_code:
static void tail2nos_K051316_0_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051316_0_w(offset >> 1, data & 0xff);
}


decompiled_code:
__int64 __fastcall tail2nos_K051316_0_r(unsigned int a1)
{
return K051316_0_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
return K051316_0_r(a1 >> 1);
}

original_code:
static data_t tail2nos_K051316_0_r(offs_t offset)
{
 return K051316_0_r(offset >> 1);
}

canonical_original_code:
static unsigned int tail2nos_K051316_0_r(unsigned int offset)
{
 return K051316_0_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall get_tile_info(int a1)
{
unsigned __int16 v1; // si
__int64 v2; // rcx
signed int v3; // edx
int v4; // eax
__int64 v5; // rsi
__int64 v6; // rcx
__int64 result; // rax

v1 = *(_WORD *)(tail2nos_bgvideoram + 2 * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = ((v1 & 0x1FFFu) + (charbank << 13)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v4 = *(_DWORD *)(v2 + 12) * ((v1 >> 13) + 16 * charpalette);
v5 = *(_QWORD *)(v2 + 16);
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2LL * v4;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int16 v1; // si
__int64 v2; // rcx
signed int v3; // edx
int v4; // eax
__int64 v5; // rsi
__int64 v6; // rcx
__int64 result; // rax

v1 = *(_WORD *)(tail2nos_bgvideoram + 2 * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = ((v1 & 0x1FFFu) + (charbank << 13)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v4 = *(_DWORD *)(v2 + 12) * ((v1 >> 13) + 16 * charpalette);
v5 = *(_QWORD *)(v2 + 16);
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2LL * v4;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 UINT16 code = (*(UINT16 *)(&tail2nos_bgvideoram[2*tile_index]));
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((code & 0x1fff) + (charbank << 13)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((code & 0xe000) >> 13) + charpalette * 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned short code = (*(UINT16 *)(&tail2nos_bgvideoram[2*tile_index]));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((code & 0x1fff) + (charbank << 13)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((code & 0xe000) >> 13) + charpalette * 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types:
code
unsigned short


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = ((*a2 >> 3) & 7u) + 32;
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = ((*a2 >> 3) & 7u) + 32;
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 *code |= ((*color & 0x03) << 8);
 *color = 32 + ((*color & 0x38) >> 3);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 *code |= ((*color & 0x03) << 8);
 *color = 32 + ((*color & 0x38) >> 3);
}

variable_types:
code
int *

variable_types:
color
int *


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

canonical_original_code:
static void irqhandler(int irq)
{
 cpu_set_irq_line(1,0,irq ? 1 : 0);
}


decompiled_code:
void *__fastcall sound_bankswitch_w(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[9] = memory_region(130LL) + ((unsigned __int8)(a2 & 1) << 15) + 0x10000;
result = &ophw;
if ( ophw == 9 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[9] = memory_region(130LL) + ((unsigned __int8)(a2 & 1) << 15) + 0x10000;
result = &ophw;
if ( ophw == 9 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
static void sound_bankswitch_w(offs_t offset,data_t data)
{
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (UINT8 *)(memory_region(REGION_CPU2) + 0x10000 + (data & 0x01) * 0x8000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void sound_bankswitch_w(unsigned int offset, unsigned int data)
{
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (unsigned char *)(memory_region(REGION_CPU2) + 0x10000 + (data & 0x01) * 0x8000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


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

if ( (a2 & 0xFF0000) == 0 )
{
soundlatch_w(a1, (unsigned __int8)a2);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
soundlatch_w(a1, (unsigned __int8)a2);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

original_code:
static void sound_command_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  soundlatch_w(offset,data & 0xff);
  cpu_cause_interrupt(1,-2);
 }
}

canonical_original_code:
static void sound_command_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  soundlatch_w(offset,data & 0xff);
  cpu_cause_interrupt(1,-2);
 }
}


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

v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v3) = 64;
fg_tilemap = v0;
v1 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 64LL, v3);
bg_tilemap = v1;
if ( !v1 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 3;
*(_QWORD *)(v1 + 136) = 0x7FF0000FFFFLL;
return 0LL;
}

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

v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v3) = 64;
fg_tilemap = v0;
v1 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 64LL, v3);
bg_tilemap = v1;
if ( !v1 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 3;
*(_QWORD *)(v1 + 136) = 0x7FF0000FFFFLL;
return 0LL;
}

original_code:
int srumbler_vh_start(void)
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,64,64);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 3;
 bg_tilemap->transmask[0] = 0xffff;
 bg_tilemap->transmask[1] = 0x07ff;
 return 0;
}

canonical_original_code:
int srumbler_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,64,64);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 3;
 bg_tilemap->transmask[0] = 0xffff;
 bg_tilemap->transmask[1] = 0x07ff;
 return 0;
}


decompiled_code:
__int64 __fastcall srumbler_4009_w(__int64 a1, unsigned __int8 a2)
{
flip_screen_w(0LL, a2 & 1);
coin_counter_w(0LL, a2 & 0x40);
return coin_counter_w(1LL, a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 a2)
{
flip_screen_w(0LL, a2 & 1);
coin_counter_w(0LL, a2 & 0x40);
return coin_counter_w(1LL, a2 & 0x80);
}

original_code:
void srumbler_4009_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x40);
 coin_counter_w(1,data & 0x80);
}

canonical_original_code:
void srumbler_4009_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x40);
 coin_counter_w(1,data & 0x80);
}


decompiled_code:
__int64 __fastcall srumbler_scroll_w(int a1, int a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(bg_tilemap, 0LL, scroll_0[0] | (unsigned int)(dword_D04 << 8));
return tilemap_set_scrolly(bg_tilemap, 0LL, dword_D08 | (unsigned int)(dword_D0C << 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(bg_tilemap, 0LL, scroll_0[0] | (unsigned int)(dword_D04 << 8));
return tilemap_set_scrolly(bg_tilemap, 0LL, dword_D08 | (unsigned int)(dword_D0C << 8));
}

original_code:
void srumbler_scroll_w(offs_t offset,data_t data)
{
 static int scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
 tilemap_set_scrolly(bg_tilemap,0,scroll[2] | (scroll[3] << 8));
}

canonical_original_code:
void srumbler_scroll_w(unsigned int offset, unsigned int data)
{
 static int scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
 tilemap_set_scrolly(bg_tilemap,0,scroll[2] | (scroll[3] << 8));
}

variable_types:
scroll
int [4]


decompiled_code:
__int64 __fastcall srumbler_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
tilemap_draw(a1, bg_tilemap, 64LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
func5(a1);
tilemap_draw(a1, bg_tilemap, 64LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void srumbler_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void srumbler_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0);
}


decompiled_code:
__int64 __fastcall srumbler_bankswitch_w(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // r12
__int64 v3; // r14
__int64 v4; // rbx
__int64 v5; // r13
__int64 result; // rax
unsigned int v7; // eax

v2 = memory_region(154LL);
v3 = memory_region(145LL) + (a2 & 0xF0);
v4 = 6LL;
v5 = (unsigned __int8)(16 * a2) + memory_region(145LL) + 256;
do
{
while ( 1 )
{
cpu_bankbase[v4] = v2 + ((*(_BYTE *)(v5 + v4 - 1) & 0xF | (16 * *(_BYTE *)(v3 + v4 - 1)) & 0x30u) << 12);
result = ophw;
if ( ophw == (_DWORD)v4 )
break;
if ( ++v4 == 17 )
return result;
}
ophw = -1;
++v4;
v7 = cpu_get_pc();
result = cpu_setOPbase16(v7);
}
while ( v4 != 17 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // r12
__int64 v3; // r14
__int64 v4; // rbx
__int64 v5; // r13
__int64 result; // rax
unsigned int v7; // eax

v2 = memory_region(154LL);
v3 = memory_region(145LL) + (a2 & 0xF0);
v4 = 6LL;
v5 = (unsigned __int8)(16 * a2) + memory_region(145LL) + 256;
do
{
while ( 1 )
{
cpu_bankbase[v4] = v2 + ((*(_BYTE *)(v5 + v4 - 1) & 0xF | (16 * *(_BYTE *)(v3 + v4 - 1)) & 0x30u) << 12);
result = ophw;
if ( ophw == (_DWORD)v4 )
break;
if ( ++v4 == 17 )
return result;
}
ophw = -1;
++v4;
v7 = cpu_get_pc();
result = cpu_setOPbase16(v7);
}
while ( v4 != 17 );
return result;
}

original_code:
static void srumbler_bankswitch_w(offs_t offset,data_t data)
{
 int i;
 unsigned char *ROM = memory_region(REGION_USER1);
 unsigned char *prom1 = memory_region(REGION_PROMS) + (data & 0xf0);
 unsigned char *prom2 = memory_region(REGION_PROMS) + 0x100 + ((data & 0x0f) << 4);
 for (i = 0x05;i < 0x10;i++)
 {
  int bank = ((prom1[i] & 0x03) << 4) | (prom2[i] & 0x0f);
  { if (i+1 >= 1 && i+1 <= 16) { cpu_bankbase[i+1] = (UINT8 *)(&ROM[bank*0x1000]); if (ophw == i+1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

canonical_original_code:
static void srumbler_bankswitch_w(unsigned int offset, unsigned int data)
{
 int i;
 unsigned char *ROM = memory_region(REGION_USER1);
 unsigned char *prom1 = memory_region(REGION_PROMS) + (data & 0xf0);
 unsigned char *prom2 = memory_region(REGION_PROMS) + 0x100 + ((data & 0x0f) << 4);
 for (i = 0x05;i < 0x10;i++)
 {
  int bank = ((prom1[i] & 0x03) << 4) | (prom2[i] & 0x0f);
  { if (i+1 >= 1 && i+1 <= 16) { cpu_bankbase[i+1] = (unsigned char *)(&ROM[bank*0x1000]); if (ophw == i+1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

variable_types:
ROM
unsigned char *


decompiled_code:
__int64 srumbler_init_machine()
{
return srumbler_bankswitch_w(0LL, 0);
}

canonical_decompiled_code:
__int64 func8()
{
return func7(0LL, 0);
}

original_code:
static void srumbler_init_machine(void)
{
 srumbler_bankswitch_w(0,0);
}

canonical_original_code:
static void srumbler_init_machine()
{
 srumbler_bankswitch_w(0,0);
}


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

if ( (unsigned int)cpu_getiloops() )
result = 2LL;
else
result = interrupt();
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
result = 2LL;
else
result = interrupt();
return result;
}

original_code:
static int srumbler_interrupt(void)
{
 if (cpu_getiloops()==0)
 {
  return interrupt();
 }
 else
 {
  return 2;
 }
}

canonical_original_code:
static int srumbler_interrupt()
{
 if (cpu_getiloops()==0)
 {
  return interrupt();
 }
 else
 {
  return 2;
 }
}


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rdi
__int64 v2; // rsi
int v3; // ecx
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rsi
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (int)*(unsigned __int8 *)(srumbler_foregroundram + v1) >> 2;
v4 = *(_QWORD *)(v2 + 16);
v5 = (*(unsigned __int8 *)(srumbler_foregroundram + v1 + 1)
+ ((*(unsigned __int8 *)(srumbler_foregroundram + v1) << 8) & 0x300u))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v5 * *(_DWORD *)(v2 + 52));
v6 = *(_DWORD *)(v2 + 12) * (v3 & 0xF);
v7 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = v3 & 0x10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rdi
__int64 v2; // rsi
int v3; // ecx
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rsi
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (int)*(unsigned __int8 *)(srumbler_foregroundram + v1) >> 2;
v4 = *(_QWORD *)(v2 + 16);
v5 = (*(unsigned __int8 *)(srumbler_foregroundram + v1 + 1)
+ ((*(unsigned __int8 *)(srumbler_foregroundram + v1) << 8) & 0x300u))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v5 * *(_DWORD *)(v2 + 52));
v6 = *(_DWORD *)(v2 + 12) * (v3 & 0xF);
v7 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = v3 & 0x10;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_foregroundram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (srumbler_foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x3c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x40) ? 0x10 : 0;
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_foregroundram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (srumbler_foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x3c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x40) ? 0x10 : 0;
}

variable_types:
attr
unsigned char


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned int v2; // ecx
__int64 v3; // rsi
__int64 v4; // r9
char v5; // r8
unsigned int v6; // edx
int v7; // eax
__int64 v8; // rsi
int v9; // eax
int v10; // ecx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(unsigned __int8 *)(srumbler_backgroundram + v1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = *(_BYTE *)(srumbler_backgroundram + v1);
v6 = (*(unsigned __int8 *)(srumbler_backgroundram + v1 + 1) + (((_WORD)v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v6 * *(_DWORD *)(v3 + 52));
v7 = *(_DWORD *)(v3 + 12) * ((unsigned __int8)v2 >> 5);
v8 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v7;
v9 = 0;
if ( v8 )
v9 = *(_DWORD *)(v8 + 4LL * v6);
*((_DWORD *)&tile_info + 4) = v9;
v10 = (v2 >> 2) & 4;
result = v10 | 2u;
if ( (v5 & 8) != 0 )
v10 |= 2u;
*((_DWORD *)&tile_info + 5) = v10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdi
unsigned int v2; // ecx
__int64 v3; // rsi
__int64 v4; // r9
char v5; // r8
unsigned int v6; // edx
int v7; // eax
__int64 v8; // rsi
int v9; // eax
int v10; // ecx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(unsigned __int8 *)(srumbler_backgroundram + v1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = *(_BYTE *)(srumbler_backgroundram + v1);
v6 = (*(unsigned __int8 *)(srumbler_backgroundram + v1 + 1) + (((_WORD)v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v6 * *(_DWORD *)(v3 + 52));
v7 = *(_DWORD *)(v3 + 12) * ((unsigned __int8)v2 >> 5);
v8 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v7;
v9 = 0;
if ( v8 )
v9 = *(_DWORD *)(v8 + 4LL * v6);
*((_DWORD *)&tile_info + 4) = v9;
v10 = (v2 >> 2) & 4;
result = v10 | 2u;
if ( (v5 & 8) != 0 )
v10 |= 2u;
*((_DWORD *)&tile_info + 5) = v10;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_backgroundram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (srumbler_backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xe0) >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x10) >> 4)<<2);
 if (attr & 0x08) tile_info.flags |= 0x02;
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_backgroundram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (srumbler_backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xe0) >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x10) >> 4)<<2);
 if (attr & 0x08) tile_info.flags |= 0x02;
}


decompiled_code:
void *__fastcall draw_sprites(__int64 a1)
{
void *result; // rax
int v2; // ebx
__int64 v4; // r15
int v5; // ecx
__int64 v6; // r11
__int16 v7; // dx
__int64 v8; // rcx
__int64 v9; // rdx
__int64 v10; // r9
__int64 v11; // rdi

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v2 + 1LL;
do
{
v5 = *(unsigned __int8 *)(spriteram + v4);
v6 = *(unsigned __int8 *)(spriteram + v4 + 1);
v7 = 8 * v5;
v8 = (v5 >> 2) & 7;
v9 = *(unsigned __int8 *)(spriteram + v4 - 1) + (v7 & 0x700u);
v10 = *(_BYTE *)(spriteram + v4) & 2;
v11 = *(unsigned __int8 *)(spriteram + v4 + 2) + ((unsigned __int8)(*(_BYTE *)(spriteram + v4) & 1) << 8);
if ( flip_screen_x )
{
v11 = (unsigned int)(496 - v11);
v6 = (unsigned int)(240 - v6);
v10 = (_DWORD)v10 == 0;
}
v4 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v9,
v8,
flip_screen_x,
v10,
v11,
v6,
Machine + 776LL,
2LL,
15LL);
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1)
{
void *result; // rax
int v2; // ebx
__int64 v4; // r15
int v5; // ecx
__int64 v6; // r11
__int16 v7; // dx
__int64 v8; // rcx
__int64 v9; // rdx
__int64 v10; // r9
__int64 v11; // rdi

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v4 = v2 + 1LL;
do
{
v5 = *(unsigned __int8 *)(spriteram + v4);
v6 = *(unsigned __int8 *)(spriteram + v4 + 1);
v7 = 8 * v5;
v8 = (v5 >> 2) & 7;
v9 = *(unsigned __int8 *)(spriteram + v4 - 1) + (v7 & 0x700u);
v10 = *(_BYTE *)(spriteram + v4) & 2;
v11 = *(unsigned __int8 *)(spriteram + v4 + 2) + ((unsigned __int8)(*(_BYTE *)(spriteram + v4) & 1) << 8);
if ( flip_screen_x )
{
v11 = (unsigned int)(496 - v11);
v6 = (unsigned int)(240 - v6);
v10 = (_DWORD)v10 == 0;
}
v4 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v9,
v8,
flip_screen_x,
v10,
v11,
v6,
Machine + 776LL,
2LL,
15LL);
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = spriteram_size-4; offs>=0;offs -= 4)
 {
  int code,colour,sx,sy,flipy;
  int attr=spriteram[offs+1];
  code = spriteram[offs];
  code += ( (attr&0xe0) << 3 );
  colour = (attr & 0x1c)>>2;
  sy = spriteram[offs + 2];
  sx = spriteram[offs + 3] + 0x100 * ( attr & 0x01);
  flipy = attr & 0x02;
  if (flip_screen_x)
  {
   sx = 496 - sx;
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[2],
    code,
    colour,
    flip_screen_x,flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = spriteram_size-4; offs>=0;offs -= 4)
 {
  int code; int colour; int sx; int sy; int flipy;
  int attr = spriteram[offs+1];
  code = spriteram[offs];
  code += ( (attr&0xe0) << 3 );
  colour = (attr & 0x1c)>>2;
  sy = spriteram[offs + 2];
  sx = spriteram[offs + 3] + 0x100 * ( attr & 0x01);
  flipy = attr & 0x02;
  if (flip_screen_x)
  {
   sx = 496 - sx;
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[2],
    code,
    colour,
    flip_screen_x,flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
 }
}

variable_types: offs int

variable_types: code int

variable_types: colour int

variable_types: sx int

variable_types: sy int

variable_types: flipy int

variable_types: attr int


decompiled_code:
__int64 __fastcall foodf_nvram_r(unsigned int a1)
{
return ((int)*((unsigned __int8 *)&nvram + ((a1 >> 2) ^ 3)) >> (2 * (a1 & 3))) & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return ((int)*((unsigned __int8 *)&nvram + ((a1 >> 2) ^ 3)) >> (2 * (a1 & 3))) & 0xF;
}

original_code:
data_t foodf_nvram_r(offs_t offset)
{
 return ((nvram[(offset / 4) ^ 0x03] >> 2*(offset % 4))) & 0x0f;
}

canonical_original_code:
unsigned int foodf_nvram_r(unsigned int offset)
{
 return ((nvram[(offset / 4) ^ 0x03] >> 2*(offset % 4))) & 0x0f;
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall foodf_nvram_w(unsigned int a1, char a2)
{
char v2; // cl
__int64 v3; // rdx
int v4; // eax
__int64 result; // rax

v2 = 2 * (a1 & 3);
v3 = (a1 >> 2) ^ 3;
v4 = ~(15 << v2);
LOBYTE(v4) = *((_BYTE *)&nvram + v3) & v4;
result = ((a2 & 0xF) << v2) | (unsigned int)v4;
*((_BYTE *)&nvram + v3) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
char v2; // cl
__int64 v3; // rdx
int v4; // eax
__int64 result; // rax

v2 = 2 * (a1 & 3);
v3 = (a1 >> 2) ^ 3;
v4 = ~(15 << v2);
LOBYTE(v4) = *((_BYTE *)&nvram + v3) & v4;
result = ((a2 & 0xF) << v2) | (unsigned int)v4;
*((_BYTE *)&nvram + v3) = result;
return result;
}

original_code:
void foodf_nvram_w(offs_t offset,data_t data)
{
 nvram[(offset / 4) ^ 0x03] &= ~(0x0f << 2*(offset % 4));
 nvram[(offset / 4) ^ 0x03] |= (data & 0x0f) << 2*(offset % 4);
}

canonical_original_code:
void foodf_nvram_w(unsigned int offset, unsigned int data)
{
 nvram[(offset / 4) ^ 0x03] &= ~(0x0f << 2*(offset % 4));
 nvram[(offset / 4) ^ 0x03] |= (data & 0x0f) << 2*(offset % 4);
}

variable_types:
data
unsigned int


decompiled_code:
void __fastcall foodf_analog_w(unsigned int a1)
{
whichport = ~(unsigned __int8)(a1 >> 1) & 3;
}

canonical_decompiled_code:
void __fastcall func2(unsigned int a1)
{
whichport = ~(unsigned __int8)(a1 >> 1) & 3;
}

original_code:
void foodf_analog_w(offs_t offset,data_t data)
{
 whichport = 3 - ((offset/2) & 3);
}

canonical_original_code:
void foodf_analog_w(unsigned int offset, unsigned int data)
{
 whichport = 3 - ((offset/2) & 3);
}


decompiled_code:
void foodf_digital_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void foodf_digital_w(offs_t offset,data_t data)
{
}

canonical_original_code:
void foodf_digital_w(unsigned int offset, unsigned int data)
{
}


original_code:
void foodf_vh_convert_color_prom (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  *(palette++) = ((i & 1) >> 0) * 0xff;
  *(palette++) = ((i & 2) >> 1) * 0xff;
  *(palette++) = ((i & 4) >> 2) * 0xff;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
}

canonical_original_code:
void foodf_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  *(palette++) = ((i & 1) >> 0) * 0xff;
  *(palette++) = ((i & 2) >> 1) * 0xff;
  *(palette++) = ((i & 4) >> 2) * 0xff;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

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

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

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


decompiled_code:
__int64 foodf_delayed_interrupt()
{
return cpu_cause_interrupt(0LL, 2LL);
}

canonical_decompiled_code:
__int64 func6()
{
return cpu_cause_interrupt(0LL, 2LL);
}

original_code:
void foodf_delayed_interrupt (int param)
{
 cpu_cause_interrupt (0, 2);
}

canonical_original_code:
void foodf_delayed_interrupt(int param)
{
 cpu_cause_interrupt (0, 2);
}

variable_types: param int


decompiled_code:
__int64 foodf_interrupt()
{
if ( !(unsigned int)cpu_getiloops() )
timer_set(107374LL, 0LL, foodf_delayed_interrupt);
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
if ( !(unsigned int)cpu_getiloops() )
timer_set(107374LL, 0LL, foodf_delayed_interrupt);
return 1LL;
}

original_code:
int foodf_interrupt (void)
{
 if (cpu_getiloops () == 0)
  timer_set (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)), 0, foodf_delayed_interrupt);
 return 1;
}

canonical_original_code:
int foodf_interrupt()
{
 if (cpu_getiloops () == 0)
  timer_set (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)), 0, foodf_delayed_interrupt);
 return 1;
}


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

if ( a2 )
return osd_fwrite(a1, &nvram, 128LL);
if ( a1 )
return osd_fread(a1, &nvram, 128LL);
nvram = -1LL;
xmmword_D30 = -1LL;
xmmword_D40 = -1LL;
xmmword_D50 = -1LL;
xmmword_D60 = -1LL;
xmmword_D70 = -1LL;
xmmword_D80 = -1LL;
xmmword_D90 = -1LL;
return result;
}

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

if ( a2 )
return osd_fwrite(a1, &nvram, 128LL);
if ( a1 )
return osd_fread(a1, &nvram, 128LL);
nvram = -1LL;
xmmword_D30 = -1LL;
xmmword_D40 = -1LL;
xmmword_D50 = -1LL;
xmmword_D60 = -1LL;
xmmword_D70 = -1LL;
xmmword_D80 = -1LL;
xmmword_D90 = -1LL;
return result;
}

original_code:
void foodf_nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,128);
 else
 {
  if (file)
   osd_fread(file,nvram,128);
  else
   memset(nvram,0xff,128);
 }
}

canonical_original_code:
void foodf_nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,128);
 else
 {
  if (file)
   osd_fread(file,nvram,128);
  else
   memset(nvram,0xff,128);
 }
}

variable_types:
file
void *


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

if ( a1 <= 6 && ((1LL << a1) & 0x55) != 0 )
result = readinputport((unsigned int)whichport);
else
result = 0LL;
return result;
}

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

if ( a1 <= 6 && ((1LL << a1) & 0x55) != 0 )
result = readinputport((unsigned int)whichport);
else
result = 0LL;
return result;
}

original_code:
data_t foodf_analog_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
  case 2:
  case 4:
  case 6:
   return readinputport (whichport);
 }
 return 0;
}

canonical_original_code:
unsigned int foodf_analog_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
  case 2:
  case 4:
  case 6:
   return readinputport (whichport);
 }
 return 0;
}


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

if ( a1 )
result = 0LL;
else
result = input_port_4_r();
return result;
}

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

if ( a1 )
result = 0LL;
else
result = input_port_4_r();
return result;
}

original_code:
data_t foodf_digital_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return input_port_4_r (offset);
 }
 return 0;
}

canonical_original_code:
unsigned int foodf_digital_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return input_port_4_r (offset);
 }
 return 0;
}


decompiled_code:
void foodf_vh_stop()
{
if ( playfieldbitmap )
bitmap_free();
playfieldbitmap = 0LL;
if ( playfielddirty )
free(playfielddirty);
playfielddirty = 0LL;
}

canonical_decompiled_code:
void func11()
{
if ( playfieldbitmap )
bitmap_free();
playfieldbitmap = 0LL;
if ( playfielddirty )
free(playfielddirty);
playfielddirty = 0LL;
}

original_code:
void foodf_vh_stop(void)
{
 if (playfieldbitmap) bitmap_free(playfieldbitmap); playfieldbitmap = 0;
 if (playfielddirty) free(playfielddirty); playfielddirty = 0;
}

canonical_original_code:
void foodf_vh_stop()
{
 if (playfieldbitmap) bitmap_free(playfieldbitmap); playfieldbitmap = 0;
 if (playfielddirty) free(playfielddirty); playfielddirty = 0;
}


decompiled_code:
__int64 foodf_vh_start()
{
void *v0; // rdi
size_t v1; // rdx
void *v3; // rax
size_t v4; // [rsp+8h] [rbp-10h]

v0 = playfielddirty;
v1 = foodf_playfieldram_size >> 1;
if ( playfielddirty
|| (v4 = foodf_playfieldram_size >> 1,
v3 = malloc(foodf_playfieldram_size >> 1),
v1 = v4,
playfielddirty = v3,
(v0 = v3) != 0LL) )
{
memset(v0, 1, v1);
if ( playfieldbitmap )
return 0LL;
playfieldbitmap = bitmap_alloc(256LL, 256LL);
if ( playfieldbitmap )
return 0LL;
}
foodf_vh_stop();
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
void *v0; // rdi
size_t v1; // rdx
void *v3; // rax
size_t v4; // [rsp+8h] [rbp-10h]

v0 = playfielddirty;
v1 = foodf_playfieldram_size >> 1;
if ( playfielddirty
|| (v4 = foodf_playfieldram_size >> 1,
v3 = malloc(foodf_playfieldram_size >> 1),
v1 = v4,
playfielddirty = v3,
(v0 = v3) != 0LL) )
{
memset(v0, 1, v1);
if ( playfieldbitmap )
return 0LL;
playfieldbitmap = bitmap_alloc(256LL, 256LL);
if ( playfieldbitmap )
return 0LL;
}
func11();
return 1LL;
}

original_code:
int foodf_vh_start(void)
{
 if (!playfielddirty) playfielddirty = (unsigned char*)malloc(foodf_playfieldram_size / 2);
 if (!playfielddirty)
 {
  foodf_vh_stop ();
  return 1;
 }
 memset (playfielddirty, 1, foodf_playfieldram_size / 2);
 if (!playfieldbitmap) playfieldbitmap = bitmap_alloc (32*8, 32*8);
 if (!playfieldbitmap)
 {
  foodf_vh_stop ();
  return 1;
 }
 return 0;
}

canonical_original_code:
int foodf_vh_start()
{
 if (!playfielddirty) playfielddirty = (unsigned char *)malloc(foodf_playfieldram_size / 2);
 if (!playfielddirty)
 {
  foodf_vh_stop ();
  return 1;
 }
 memset (playfielddirty, 1, foodf_playfieldram_size / 2);
 if (!playfieldbitmap) playfieldbitmap = bitmap_alloc (32*8, 32*8);
 if (!playfieldbitmap)
 {
  foodf_vh_stop ();
  return 1;
 }
 return 0;
}


original_code:
void foodf_paletteram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int bit0,bit1,bit2;
 int r,g,b;
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 bit0 = (newword >> 0) & 0x01;
 bit1 = (newword >> 1) & 0x01;
 bit2 = (newword >> 2) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (newword >> 3) & 0x01;
 bit1 = (newword >> 4) & 0x01;
 bit2 = (newword >> 5) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (newword >> 6) & 0x01;
 bit2 = (newword >> 7) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void foodf_paletteram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int bit0; int bit1; int bit2;
 int r; int g; int b;
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 bit0 = (newword >> 0) & 0x01;
 bit1 = (newword >> 1) & 0x01;
 bit2 = (newword >> 2) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (newword >> 3) & 0x01;
 bit1 = (newword >> 4) & 0x01;
 bit2 = (newword >> 5) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (newword >> 6) & 0x01;
 bit2 = (newword >> 7) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset / 2,r,g,b);
}

variable_types: oldword int

variable_types: newword int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall foodf_pokey1_r(unsigned int a1)
{
return pokey1_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
return pokey1_r(a1 >> 1);
}

original_code: data_t foodf_pokey1_r(offs_t offset) { return pokey1_r (offset/2); }

canonical_original_code: unsigned int foodf_pokey1_r(unsigned int offset) { return pokey1_r (offset/2); }


decompiled_code:
__int64 __fastcall foodf_pokey2_r(unsigned int a1)
{
return pokey2_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
return pokey2_r(a1 >> 1);
}

original_code: data_t foodf_pokey2_r(offs_t offset) { return pokey2_r (offset/2); }

canonical_original_code: unsigned int foodf_pokey2_r(unsigned int offset) { return pokey2_r (offset/2); }


decompiled_code:
__int64 __fastcall foodf_pokey3_r(unsigned int a1)
{
return pokey3_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
return pokey3_r(a1 >> 1);
}

original_code: data_t foodf_pokey3_r(offs_t offset) { return pokey3_r (offset/2); }

canonical_original_code: unsigned int foodf_pokey3_r(unsigned int offset) { return pokey3_r (offset/2); }


decompiled_code:
__int64 __fastcall foodf_pokey1_w(unsigned int a1, unsigned __int8 a2)
{
return pokey1_w(a1 >> 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1, unsigned __int8 a2)
{
return pokey1_w(a1 >> 1, a2);
}

original_code: void foodf_pokey1_w(offs_t offset,data_t data) { pokey1_w (offset/2, data & 0xff); }

canonical_original_code: void foodf_pokey1_w(unsigned int offset, unsigned int data) { pokey1_w (offset/2, data & 0xff); }


decompiled_code:
__int64 __fastcall foodf_pokey2_w(unsigned int a1, unsigned __int8 a2)
{
return pokey2_w(a1 >> 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1, unsigned __int8 a2)
{
return pokey2_w(a1 >> 1, a2);
}

original_code: void foodf_pokey2_w(offs_t offset,data_t data) { pokey2_w (offset/2, data & 0xff); }

canonical_original_code: void foodf_pokey2_w(unsigned int offset, unsigned int data) { pokey2_w (offset/2, data & 0xff); }


decompiled_code:
__int64 __fastcall foodf_pokey3_w(unsigned int a1, unsigned __int8 a2)
{
return pokey3_w(a1 >> 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1, unsigned __int8 a2)
{
return pokey3_w(a1 >> 1, a2);
}

original_code: void foodf_pokey3_w(offs_t offset,data_t data) { pokey3_w (offset/2, data & 0xff); }

canonical_original_code: void foodf_pokey3_w(unsigned int offset, unsigned int data) { pokey3_w (offset/2, data & 0xff); }


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

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

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

canonical_original_code:
int quantum_interrupt()
{
 return 1;
}


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

v0 = input_port_0_r(0LL);
return v0 | (unsigned int)((unsigned int)avgdvg_done() != 0);
}

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

v0 = input_port_0_r(0LL);
return v0 | (unsigned int)((unsigned int)avgdvg_done() != 0);
}

original_code:
data_t quantum_switches_r(offs_t offset)
{
 return (input_port_0_r(0) |
  (avgdvg_done() ? 1 : 0));
}

canonical_original_code:
unsigned int quantum_switches_r(unsigned int offset)
{
 return (input_port_0_r(0) |
  (avgdvg_done() ? 1 : 0));
}


decompiled_code:
__int64 __fastcall quantum_led_w(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 1);
osd_led_w(0LL, (a2 >> 4) & 1);
return osd_led_w(1LL, (a2 & 0x20) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 1);
osd_led_w(0LL, (a2 >> 4) & 1);
return osd_led_w(1LL, (a2 & 0x20) != 0);
}

original_code:
void quantum_led_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 1);
 osd_led_w(0,(data & 0x10) >> 4);
 osd_led_w(1,(data & 0x20) >> 5);
}

canonical_original_code:
void quantum_led_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 1);
 osd_led_w(0,(data & 0x10) >> 4);
 osd_led_w(1,(data & 0x20) >> 5);
}