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

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out;
if ( (ddrB & 8) != 0 && (a2 & 8) == 0 && (portB_out & 8) != 0 )
{
if ( (a2 & 0x10) != 0 )
{
if ( (a2 & 4) != 0 )
{
latch = (unsigned __int8)mexico86_protection_ram[address];
}
else
{
latch = readinputport((address & 1u) + 1);
result = (unsigned __int8)ddrB;
}
}
else
{
mexico86_protection_ram[address] = portA_out;
}
}
if ( (result & 0x20) != 0 && (a2 & 0x20) != 0 && (portB_out & 0x20) == 0 )
{
cpu_irq_line_vector_w(0LL, 0LL, (unsigned __int8)*mexico86_protection_ram);
result = cpu_set_irq_line(0LL, 0LL, 3LL);
}
portB_out = a2;
return result;
}

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

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out;
if ( (ddrB & 8) != 0 && (a2 & 8) == 0 && (portB_out & 8) != 0 )
{
if ( (a2 & 0x10) != 0 )
{
if ( (a2 & 4) != 0 )
{
latch = (unsigned __int8)mexico86_protection_ram[address];
}
else
{
latch = readinputport((address & 1u) + 1);
result = (unsigned __int8)ddrB;
}
}
else
{
mexico86_protection_ram[address] = portA_out;
}
}
if ( (result & 0x20) != 0 && (a2 & 0x20) != 0 && (portB_out & 0x20) == 0 )
{
cpu_irq_line_vector_w(0LL, 0LL, (unsigned __int8)*mexico86_protection_ram);
result = cpu_set_irq_line(0LL, 0LL, 3LL);
}
portB_out = a2;
return result;
}

original_code:
void mexico86_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = portA_out;
 }
 if ((ddrB & 0x08) && (~data & 0x08) && (portB_out & 0x08))
 {
  if (data & 0x10)
  {
   if (data & 0x04)
   {
    latch = mexico86_protection_ram[address];
   }
   else
   {
    latch = readinputport((address & 1) + 1);
   }
  }
  else
  {
    mexico86_protection_ram[address] = portA_out;
  }
 }
 if ((ddrB & 0x20) && (data & 0x20) && (~portB_out & 0x20))
 {
  cpu_irq_line_vector_w(0,0,mexico86_protection_ram[0]);
  cpu_set_irq_line(0,0,3);
 }
 portB_out = data;
}

canonical_original_code:
void mexico86_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = portA_out;
 }
 if ((ddrB & 0x08) && (~data & 0x08) && (portB_out & 0x08))
 {
  if (data & 0x10)
  {
   if (data & 0x04)
   {
    latch = mexico86_protection_ram[address];
   }
   else
   {
    latch = readinputport((address & 1) + 1);
   }
  }
  else
  {
    mexico86_protection_ram[address] = portA_out;
  }
 }
 if ((ddrB & 0x20) && (data & 0x20) && (~portB_out & 0x20))
 {
  cpu_irq_line_vector_w(0,0,mexico86_protection_ram[0]);
  cpu_set_irq_line(0,0,3);
 }
 portB_out = data;
}


decompiled_code:
void *__fastcall mexico86_bankswitch_w(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
__int64 v3; // r12
void *result; // rax
unsigned int v5; // eax

v2 = a2 & 7;
v3 = memory_region(129LL);
if ( v2 > 5 )
usrintf_showmessage("Switching to invalid bank!");
cpu_bankbase[1] = v3 + ((v2 + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
charbank = (a2 >> 5) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
__int64 v3; // r12
void *result; // rax
unsigned int v5; // eax

v2 = a2 & 7;
v3 = memory_region(129LL);
if ( v2 > 5 )
usrintf_showmessage("Switching to invalid bank!");
cpu_bankbase[1] = v3 + ((v2 + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
charbank = (a2 >> 5) & 1;
return result;
}

original_code:
void mexico86_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if ((data & 7) > 5)
  usrintf_showmessage( "Switching to invalid bank!" );
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000 + 0x4000 * (data & 0x07)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 charbank = (data & 0x20) >> 5;
}

canonical_original_code:
void mexico86_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if ((data & 7) > 5)
  usrintf_showmessage( "Switching to invalid bank!" );
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000 + 0x4000 * (data & 0x07)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 charbank = (data & 0x20) >> 5;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types:
RAM
unsigned char *

return_type: void


decompiled_code:
unsigned __int64 __fastcall mexico86_vh_screenrefresh(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
unsigned int v3; // edx
char v4; // si
int v5; // er8
int v6; // esi
int v7; // edx
int v8; // ebp
int v9; // er15
__int64 v10; // r13
int v11; // eax
int v12; // esi
__int64 v13; // r8
__int64 v14; // rcx
__int64 v15; // rdx
__int64 v16; // rax
int v17; // [rsp+Ch] [rbp-5Ch]
__int64 v18; // [rsp+10h] [rbp-58h]
int v19; // [rsp+18h] [rbp-50h]
int v20; // [rsp+20h] [rbp-48h]
int v21; // [rsp+24h] [rbp-44h]
unsigned __int64 v22; // [rsp+28h] [rbp-40h]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
v21 = 0;
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
while ( 1 )
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_3;
v3 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 1));
v4 = *(_BYTE *)(mexico86_objectram + (unsigned int)(v2 + 1));
if ( (v3 & 0x80u) == 0 )
break;
v6 = (v4 & 0x3F) << 7;
if ( (v3 & 0xC0) != 0xC0 )
{
v5 = 0;
v7 = 32;
goto LABEL_10;
}
v21 += 16;
v5 = 0;
v7 = 32;
LABEL_11:
v22 = v2;
v19 = v21;
v8 = (4 * *(_BYTE *)(mexico86_objectram + (unsigned int)(v2 + 3))) & 8;
v18 = v6;
v20 = v5 - *(unsigned __int8 *)(mexico86_objectram + v2);
v17 = v20 + 8 * v7;
do
{
v9 = v20;
v10 = v18;
do
{
v11 = *(unsigned __int8 *)(mexico86_videoram + v10 + 1);
v12 = *(unsigned __int8 *)(mexico86_videoram + v10);
v10 += 2LL;
v13 = v11 & 0x40;
v14 = v8 | (v11 >> 3) & 7u;
v15 = v12 + (((_WORD)v11 << 8) & 0x700) + ((16 * (_WORD)v11) & 0x800u) + (charbank << 12);
v16 = (unsigned __int8)v9;
v9 += 8;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v15,
v14,
v13,
0LL,
(unsigned __int8)v19,
v16,
Machine + 776LL,
2LL,
0LL);
}
while ( v17 != v9 );
v19 += 8;
v18 += 64LL;
}
while ( v21 + 16 != v19 );
v2 = v22;
LABEL_3:
v2 += 4LL;
result = mexico86_objectram_size;
if ( mexico86_objectram_size + 512LL <= v2 )
return result;
}
v5 = 240;
v6 = ((v4 & 0x1F) << 7) + ((v3 >> 1) & 0x30) + 12;
v7 = 2;
LABEL_10:
v21 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 2));
goto LABEL_11;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
unsigned int v3; // edx
char v4; // si
int v5; // er8
int v6; // esi
int v7; // edx
int v8; // ebp
int v9; // er15
__int64 v10; // r13
int v11; // eax
int v12; // esi
__int64 v13; // r8
__int64 v14; // rcx
__int64 v15; // rdx
__int64 v16; // rax
int v17; // [rsp+Ch] [rbp-5Ch]
__int64 v18; // [rsp+10h] [rbp-58h]
int v19; // [rsp+18h] [rbp-50h]
int v20; // [rsp+20h] [rbp-48h]
int v21; // [rsp+24h] [rbp-44h]
unsigned __int64 v22; // [rsp+28h] [rbp-40h]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
v21 = 0;
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
while ( 1 )
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_3;
v3 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 1));
v4 = *(_BYTE *)(mexico86_objectram + (unsigned int)(v2 + 1));
if ( (v3 & 0x80u) == 0 )
break;
v6 = (v4 & 0x3F) << 7;
if ( (v3 & 0xC0) != 0xC0 )
{
v5 = 0;
v7 = 32;
goto LABEL_10;
}
v21 += 16;
v5 = 0;
v7 = 32;
LABEL_11:
v22 = v2;
v19 = v21;
v8 = (4 * *(_BYTE *)(mexico86_objectram + (unsigned int)(v2 + 3))) & 8;
v18 = v6;
v20 = v5 - *(unsigned __int8 *)(mexico86_objectram + v2);
v17 = v20 + 8 * v7;
do
{
v9 = v20;
v10 = v18;
do
{
v11 = *(unsigned __int8 *)(mexico86_videoram + v10 + 1);
v12 = *(unsigned __int8 *)(mexico86_videoram + v10);
v10 += 2LL;
v13 = v11 & 0x40;
v14 = v8 | (v11 >> 3) & 7u;
v15 = v12 + (((_WORD)v11 << 8) & 0x700) + ((16 * (_WORD)v11) & 0x800u) + (charbank << 12);
v16 = (unsigned __int8)v9;
v9 += 8;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v15,
v14,
v13,
0LL,
(unsigned __int8)v19,
v16,
Machine + 776LL,
2LL,
0LL);
}
while ( v17 != v9 );
v19 += 8;
v18 += 64LL;
}
while ( v21 + 16 != v19 );
v2 = v22;
LABEL_3:
v2 += 4LL;
result = mexico86_objectram_size;
if ( mexico86_objectram_size + 512LL <= v2 )
return result;
}
v5 = 240;
v6 = ((v4 & 0x1F) << 7) + ((v3 >> 1) & 0x30) + 12;
v7 = 2;
LABEL_10:
v21 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 2));
goto LABEL_11;
}
return result;
}

original_code:
void mexico86_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy,xc,yc;
 int gfx_num,gfx_attr,gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(UINT32 *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs,code,color,flipx,flipy,x,y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x07) << 8)
      + ((mexico86_videoram[goffs + 1] & 0x80) << 4) + (charbank << 12);
    color = ((mexico86_videoram[goffs + 1] & 0x38) >> 3) + ((gfx_attr & 0x02) << 2);
    flipx = mexico86_videoram[goffs + 1] & 0x40;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

canonical_original_code:
void mexico86_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy; int xc; int yc;
 int gfx_num; int gfx_attr; int gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(unsigned int *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs; int code; int color; int flipx; int flipy; int x; int y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x07) << 8)
      + ((mexico86_videoram[goffs + 1] & 0x80) << 4) + (charbank << 12);
    color = ((mexico86_videoram[goffs + 1] & 0x38) >> 3) + ((gfx_attr & 0x02) << 2);
    flipx = mexico86_videoram[goffs + 1] & 0x40;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: xc int

variable_types: yc int

variable_types: height int

variable_types: goffs int

variable_types: code int

variable_types: color int

variable_types: flipx int

variable_types: flipy int

variable_types: x int

variable_types: y int


decompiled_code:
unsigned __int64 __fastcall kikikai_vh_screenrefresh(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
unsigned int v3; // eax
char v4; // si
int v5; // er9
int v6; // er8
int v7; // esi
int v8; // er12
int v9; // er13
__int64 v10; // r15
__int16 v11; // dx
int v12; // esi
__int64 v13; // rax
__int64 v14; // [rsp+0h] [rbp-58h]
int v15; // [rsp+8h] [rbp-50h]
int v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+14h] [rbp-44h]
unsigned __int64 v18; // [rsp+18h] [rbp-40h]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
v17 = 0;
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
while ( 1 )
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_3;
v3 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 1));
v4 = *(_BYTE *)(mexico86_objectram + (unsigned int)(v2 + 1));
if ( (v3 & 0x80u) == 0 )
break;
v7 = (v4 & 0x3F) << 7;
if ( (v3 & 0xC0) != 0xC0 )
{
v5 = 0;
v6 = 32;
goto LABEL_10;
}
v17 += 16;
v5 = 0;
v6 = 32;
LABEL_11:
v18 = v2;
v14 = v7;
v15 = v17;
v16 = v5 - *(unsigned __int8 *)(mexico86_objectram + v2);
v8 = v16 + 8 * v6;
do
{
v9 = v16;
v10 = v14;
do
{
v11 = *(unsigned __int8 *)(mexico86_videoram + v10 + 1);
v12 = *(unsigned __int8 *)(mexico86_videoram + v10);
v10 += 2LL;
v13 = (unsigned __int8)v9;
v9 += 8;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v12 + ((v11 << 8) & 0x1F00u),
(unsigned __int8)v11 >> 5,
0LL,
0LL,
(unsigned __int8)v15,
v13,
Machine + 776LL,
2LL,
0LL);
}
while ( v8 != v9 );
v15 += 8;
v14 += 64LL;
}
while ( v17 + 16 != v15 );
v2 = v18;
LABEL_3:
v2 += 4LL;
result = mexico86_objectram_size;
if ( mexico86_objectram_size + 512LL <= v2 )
return result;
}
v5 = 240;
v6 = 2;
v7 = ((v4 & 0x1F) << 7) + ((v3 >> 1) & 0x30) + 12;
LABEL_10:
v17 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 2));
goto LABEL_11;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func12(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // r15
unsigned int v3; // eax
char v4; // si
int v5; // er9
int v6; // er8
int v7; // esi
int v8; // er12
int v9; // er13
__int64 v10; // r15
__int16 v11; // dx
int v12; // esi
__int64 v13; // rax
__int64 v14; // [rsp+0h] [rbp-58h]
int v15; // [rsp+8h] [rbp-50h]
int v16; // [rsp+10h] [rbp-48h]
int v17; // [rsp+14h] [rbp-44h]
unsigned __int64 v18; // [rsp+18h] [rbp-40h]

fillbitmap(a1, **(unsigned __int16 **)(*(_QWORD *)(Machine + 512LL) + 16LL), Machine + 776LL);
v17 = 0;
result = mexico86_objectram_size;
if ( mexico86_objectram_size != -512LL )
{
v2 = 0LL;
while ( 1 )
{
if ( result <= v2 && result + 384 > v2 || result + 448 <= v2 || !*(_DWORD *)(mexico86_objectram + v2) )
goto LABEL_3;
v3 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 1));
v4 = *(_BYTE *)(mexico86_objectram + (unsigned int)(v2 + 1));
if ( (v3 & 0x80u) == 0 )
break;
v7 = (v4 & 0x3F) << 7;
if ( (v3 & 0xC0) != 0xC0 )
{
v5 = 0;
v6 = 32;
goto LABEL_10;
}
v17 += 16;
v5 = 0;
v6 = 32;
LABEL_11:
v18 = v2;
v14 = v7;
v15 = v17;
v16 = v5 - *(unsigned __int8 *)(mexico86_objectram + v2);
v8 = v16 + 8 * v6;
do
{
v9 = v16;
v10 = v14;
do
{
v11 = *(unsigned __int8 *)(mexico86_videoram + v10 + 1);
v12 = *(unsigned __int8 *)(mexico86_videoram + v10);
v10 += 2LL;
v13 = (unsigned __int8)v9;
v9 += 8;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v12 + ((v11 << 8) & 0x1F00u),
(unsigned __int8)v11 >> 5,
0LL,
0LL,
(unsigned __int8)v15,
v13,
Machine + 776LL,
2LL,
0LL);
}
while ( v8 != v9 );
v15 += 8;
v14 += 64LL;
}
while ( v17 + 16 != v15 );
v2 = v18;
LABEL_3:
v2 += 4LL;
result = mexico86_objectram_size;
if ( mexico86_objectram_size + 512LL <= v2 )
return result;
}
v5 = 240;
v6 = 2;
v7 = ((v4 & 0x1F) << 7) + ((v3 >> 1) & 0x30) + 12;
LABEL_10:
v17 = *(unsigned __int8 *)(mexico86_objectram + (unsigned int)(v2 + 2));
goto LABEL_11;
}
return result;
}

original_code:
void kikikai_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int sx,sy,xc,yc;
 int gfx_num,gfx_attr,gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(UINT32 *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs,code,color,flipx,flipy,x,y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x1f) << 8);
    color = (mexico86_videoram[goffs + 1] & 0xe0) >> 5;
    flipx = 0;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

canonical_original_code:
void kikikai_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int sx; int sy; int xc; int yc;
 int gfx_num; int gfx_attr; int gfx_offs;
 fillbitmap(bitmap,Machine->gfx[0]->colortable[0],&Machine->visible_area);
 sx = 0;
 for (offs = 0;offs < mexico86_objectram_size+0x200;offs += 4)
    {
  int height;
if (offs >= mexico86_objectram_size && offs < mexico86_objectram_size+0x180) continue;
if (offs >= mexico86_objectram_size+0x1c0) continue;
  if (*(unsigned int *)(&mexico86_objectram[offs]) == 0)
   continue;
  gfx_num = mexico86_objectram[offs + 1];
  gfx_attr = mexico86_objectram[offs + 3];
  if ((gfx_num & 0x80) == 0)
  {
   gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;
   height = 2;
  }
  else
  {
   gfx_offs = ((gfx_num & 0x3f) * 0x80);
   height = 32;
  }
  if ((gfx_num & 0xc0) == 0xc0)
   sx += 16;
  else
  {
   sx = mexico86_objectram[offs + 2];
  }
  sy = 256 - height*8 - (mexico86_objectram[offs + 0]);
  for (xc = 0;xc < 2;xc++)
  {
   for (yc = 0;yc < height;yc++)
   {
    int goffs; int code; int color; int flipx; int flipy; int x; int y;
    goffs = gfx_offs + xc * 0x40 + yc * 0x02;
    code = mexico86_videoram[goffs] + ((mexico86_videoram[goffs + 1] & 0x1f) << 8);
    color = (mexico86_videoram[goffs + 1] & 0xe0) >> 5;
    flipx = 0;
    flipy = 0;
    x = (sx + xc * 8) & 0xff;
    y = (sy + yc * 8) & 0xff;
    drawgfx(bitmap,Machine->gfx[0],
      code,
      color,
      flipx,flipy,
      x,y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
 }
}

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


decompiled_code:
__int64 __fastcall mexico86_f008_w(__int64 a1, unsigned int a2)
{
cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 2) ^ 1) & 1);
return cpu_set_reset_line(2LL, ((unsigned __int8)(a2 >> 1) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 2) ^ 1) & 1);
return cpu_set_reset_line(2LL, ((unsigned __int8)(a2 >> 1) ^ 1) & 1);
}

original_code:
static void mexico86_f008_w(offs_t offset,data_t data)
{
 cpu_set_reset_line(1,(data & 4) ? 0 : 1);
 cpu_set_reset_line(2,(data & 2) ? 0 : 1);
}

canonical_original_code:
static void mexico86_f008_w(unsigned int offset, unsigned int data)
{
 cpu_set_reset_line(1,(data & 4) ? 0 : 1);
 cpu_set_reset_line(2,(data & 2) ? 0 : 1);
}

variable_types:
offset
unsigned int


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

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

original_code:
static data_t shared_r(offs_t offset)
{
 return shared[offset];
}

canonical_original_code:
static unsigned int shared_r(unsigned int offset)
{
 return shared[offset];
}

return_type: unsigned int


decompiled_code:
__int64 citycon_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
__int64 v3; // rsi
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
unsigned int v7; // er8

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
schedule_full_refresh();
tmpbitmap = bitmap_alloc(
(unsigned int)(4 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL)),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap )
{
v2 = *(_QWORD *)(Machine + 824LL);
v3 = *(unsigned int *)(v2 + 668);
v4 = bitmap_alloc((unsigned int)(4 * *(_DWORD *)(v2 + 664)), v3);
v7 = 0;
tmpbitmap2 = v4;
if ( v4 )
return v7;
bitmap_free(tmpbitmap, v3, v5, v6, 0LL);
}
free(dirtybuffer);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
__int64 v3; // rsi
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rcx
unsigned int v7; // er8

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
schedule_full_refresh();
tmpbitmap = bitmap_alloc(
(unsigned int)(4 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL)),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap )
{
v2 = *(_QWORD *)(Machine + 824LL);
v3 = *(unsigned int *)(v2 + 668);
v4 = bitmap_alloc((unsigned int)(4 * *(_DWORD *)(v2 + 664)), v3);
v7 = 0;
tmpbitmap2 = v4;
if ( v4 )
return v7;
bitmap_free(tmpbitmap, v3, v5, v6, 0LL);
}
free(dirtybuffer);
return 1LL;
}

original_code:
int citycon_vh_start(void)
{
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 schedule_full_refresh();
 if ((tmpbitmap = bitmap_alloc(4 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(4 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

canonical_original_code:
int citycon_vh_start()
{
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 schedule_full_refresh();
 if ((tmpbitmap = bitmap_alloc(4 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(4 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall citycon_vh_stop(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8

free(dirtybuffer);
bitmap_free(tmpbitmap, a2, v2, v3, v4);
return bitmap_free(tmpbitmap2, a2, v5, v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // r8

free(dirtybuffer);
bitmap_free(tmpbitmap, a2, v2, v3, v4);
return bitmap_free(tmpbitmap2, a2, v5, v6, v7);
}

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

canonical_original_code:
void citycon_vh_stop()
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
 bitmap_free(tmpbitmap2);
}


decompiled_code:
__int64 __fastcall citycon_background_w(unsigned int a1, unsigned int a2)
{
set_vh_global_attribute(&bg_image, a2 >> 4);
return flip_screen_w(a1, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
set_vh_global_attribute(&bg_image, a2 >> 4);
return flip_screen_w(a1, a2 & 1);
}

original_code:
void citycon_background_w(offs_t offset,data_t data)
{
 set_vh_global_attribute(&bg_image, data >> 4);
 flip_screen_w(offset, data & 0x01);
}

canonical_original_code:
void citycon_background_w(unsigned int offset, unsigned int data)
{
 set_vh_global_attribute(&bg_image, data >> 4);
 flip_screen_w(offset, data & 0x01);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 citycon_in_r()
{
return readinputport(flip_screen_x != 0);
}

canonical_decompiled_code:
__int64 func3()
{
return readinputport(flip_screen_x != 0);
}

original_code:
data_t citycon_in_r(offs_t offset)
{
 return readinputport(flip_screen_x ? 1 : 0);
}

canonical_original_code:
unsigned int citycon_in_r(unsigned int offset)
{
 return readinputport(flip_screen_x ? 1 : 0);
}


decompiled_code:
__int64 copsnrob_vh_start()
{
overlay_create(&copsnrob_overlay, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
overlay_create(&copsnrob_overlay, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
return 0LL;
}

original_code:
int copsnrob_vh_start(void)
{
 overlay_create(copsnrob_overlay, 2, Machine->drv->total_colors - 2);
    return 0;
}

canonical_original_code:
int copsnrob_vh_start()
{
 overlay_create(copsnrob_overlay, 2, Machine->drv->total_colors - 2);
    return 0;
}


decompiled_code:
__int64 __fastcall copsnrob_vh_screenrefresh(__int64 a1)
{
int v1; // ebp
__int64 v2; // r13
char v3; // dl
char v4; // al
_BYTE *v5; // rax
int v6; // edx
int v7; // edx
int v8; // edx
int v9; // eax
int i; // ebx
__int64 j; // rbp
__int64 result; // rax
unsigned __int8 v13; // r12
char v14; // r15
char v15; // r13
__int64 v16; // rbx
__int64 v17; // [rsp-28h] [rbp-70h]
__int64 v18; // [rsp-28h] [rbp-70h]
int v19; // [rsp+0h] [rbp-48h]

palette_recalc();
if ( videoram_size >= 0 )
{
v1 = videoram_size;
v2 = videoram_size;
do
{
v3 = *(_BYTE *)(videoram + v2--);
v17 = (unsigned int)(8 * (v1 >> 5));
v4 = v1--;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v3 & 0x3F,
0LL,
0LL,
0LL,
8 * (~v4 & 0x1Fu),
v17,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
v5 = copsnrob_cary;
v6 = (unsigned __int8)*copsnrob_cary;
if ( (_BYTE)v6 )
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)*copsnrob_carimage,
0LL,
1LL,
0LL,
228LL,
(unsigned int)(256 - v6),
Machine + 776LL,
2LL,
0LL);
v5 = copsnrob_cary;
v7 = (unsigned __int8)copsnrob_cary[1];
if ( !(_BYTE)v7 )
{
LABEL_6:
v8 = (unsigned __int8)v5[2];
if ( !(_BYTE)v8 )
goto LABEL_7;
LABEL_30:
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[2],
0LL,
0LL,
0LL,
36LL,
(unsigned int)(256 - v8),
Machine + 776LL,
2LL,
0LL);
v9 = (unsigned __int8)copsnrob_cary[3];
if ( !(_BYTE)v9 )
goto LABEL_8;
LABEL_31:
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[3],
0LL,
0LL,
0LL,
4LL,
(unsigned int)(256 - v9),
Machine + 776LL,
2LL,
0LL);
goto LABEL_8;
}
}
else
{
v7 = (unsigned __int8)copsnrob_cary[1];
if ( !(_BYTE)v7 )
goto LABEL_6;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[1],
0LL,
1LL,
0LL,
196LL,
(unsigned int)(256 - v7),
Machine + 776LL,
2LL,
0LL);
v5 = copsnrob_cary;
v8 = (unsigned __int8)copsnrob_cary[2];
if ( (_BYTE)v8 )
goto LABEL_30;
LABEL_7:
v9 = (unsigned __int8)v5[3];
if ( (_BYTE)v9 )
goto LABEL_31;
LABEL_8:
for ( i = 0; i <= 255; i += 32 )
{
while ( !*(_BYTE *)(copsnrob_truckram + 255 - i) )
{
LABEL_11:
if ( ++i > 255 )
goto LABEL_15;
}
if ( (((unsigned __int8)(i + 31) ^ *copsnrob_trucky) & 0x1F) != 0 )
{
if ( (((unsigned __int8)i ^ *copsnrob_trucky) & 0x1F) == 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
128LL,
(unsigned int)(256 - i),
Machine + 776LL,
2LL,
0LL);
goto LABEL_11;
}
v18 = (unsigned int)(225 - i);
drawgfx(a1, *(_QWORD *)(Machine + 528LL), 0LL, 0LL, 0LL, 0LL, 128LL, v18, Machine + 776LL, 2LL, 0LL);
}
LABEL_15:
for ( j = 0LL; j != 256; ++j )
{
result = copsnrob_bulletsram;
v13 = *(_BYTE *)(copsnrob_bulletsram + j);
if ( (v13 & 0xF) != 0 )
{
result = v13;
v19 = 4;
v14 = 16;
v15 = 1;
if ( (*(_BYTE *)(copsnrob_bulletsram + j) & 1) != 0 )
{
LABEL_21:
result = Machine;
if ( *(int *)(Machine + 788LL) >= 0 )
{
v16 = 0LL;
do
{
if ( ((unsigned __int8)v14 & *(_BYTE *)(copsnrob_bulletsram + v16)) != 0 )
plot_pixel(
a1,
(unsigned int)(256 - j),
(unsigned int)v16,
*(unsigned __int16 *)(*(_QWORD *)(result + 792) + 2LL));
result = Machine;
++v16;
}
while ( *(_DWORD *)(Machine + 788LL) >= (int)v16 );
}
}
while ( 1 )
{
v15 *= 2;
v14 *= 2;
if ( !--v19 )
break;
if ( ((unsigned __int8)v15 & v13) != 0 )
goto LABEL_21;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebp
__int64 v2; // r13
char v3; // dl
char v4; // al
_BYTE *v5; // rax
int v6; // edx
int v7; // edx
int v8; // edx
int v9; // eax
int i; // ebx
__int64 j; // rbp
__int64 result; // rax
unsigned __int8 v13; // r12
char v14; // r15
char v15; // r13
__int64 v16; // rbx
__int64 v17; // [rsp-28h] [rbp-70h]
__int64 v18; // [rsp-28h] [rbp-70h]
int v19; // [rsp+0h] [rbp-48h]

palette_recalc();
if ( videoram_size >= 0 )
{
v1 = videoram_size;
v2 = videoram_size;
do
{
v3 = *(_BYTE *)(videoram + v2--);
v17 = (unsigned int)(8 * (v1 >> 5));
v4 = v1--;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v3 & 0x3F,
0LL,
0LL,
0LL,
8 * (~v4 & 0x1Fu),
v17,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
v5 = copsnrob_cary;
v6 = (unsigned __int8)*copsnrob_cary;
if ( (_BYTE)v6 )
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)*copsnrob_carimage,
0LL,
1LL,
0LL,
228LL,
(unsigned int)(256 - v6),
Machine + 776LL,
2LL,
0LL);
v5 = copsnrob_cary;
v7 = (unsigned __int8)copsnrob_cary[1];
if ( !(_BYTE)v7 )
{
LABEL_6:
v8 = (unsigned __int8)v5[2];
if ( !(_BYTE)v8 )
goto LABEL_7;
LABEL_30:
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[2],
0LL,
0LL,
0LL,
36LL,
(unsigned int)(256 - v8),
Machine + 776LL,
2LL,
0LL);
v9 = (unsigned __int8)copsnrob_cary[3];
if ( !(_BYTE)v9 )
goto LABEL_8;
LABEL_31:
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[3],
0LL,
0LL,
0LL,
4LL,
(unsigned int)(256 - v9),
Machine + 776LL,
2LL,
0LL);
goto LABEL_8;
}
}
else
{
v7 = (unsigned __int8)copsnrob_cary[1];
if ( !(_BYTE)v7 )
goto LABEL_6;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned __int8)copsnrob_carimage[1],
0LL,
1LL,
0LL,
196LL,
(unsigned int)(256 - v7),
Machine + 776LL,
2LL,
0LL);
v5 = copsnrob_cary;
v8 = (unsigned __int8)copsnrob_cary[2];
if ( (_BYTE)v8 )
goto LABEL_30;
LABEL_7:
v9 = (unsigned __int8)v5[3];
if ( (_BYTE)v9 )
goto LABEL_31;
LABEL_8:
for ( i = 0; i <= 255; i += 32 )
{
while ( !*(_BYTE *)(copsnrob_truckram + 255 - i) )
{
LABEL_11:
if ( ++i > 255 )
goto LABEL_15;
}
if ( (((unsigned __int8)(i + 31) ^ *copsnrob_trucky) & 0x1F) != 0 )
{
if ( (((unsigned __int8)i ^ *copsnrob_trucky) & 0x1F) == 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
128LL,
(unsigned int)(256 - i),
Machine + 776LL,
2LL,
0LL);
goto LABEL_11;
}
v18 = (unsigned int)(225 - i);
drawgfx(a1, *(_QWORD *)(Machine + 528LL), 0LL, 0LL, 0LL, 0LL, 128LL, v18, Machine + 776LL, 2LL, 0LL);
}
LABEL_15:
for ( j = 0LL; j != 256; ++j )
{
result = copsnrob_bulletsram;
v13 = *(_BYTE *)(copsnrob_bulletsram + j);
if ( (v13 & 0xF) != 0 )
{
result = v13;
v19 = 4;
v14 = 16;
v15 = 1;
if ( (*(_BYTE *)(copsnrob_bulletsram + j) & 1) != 0 )
{
LABEL_21:
result = Machine;
if ( *(int *)(Machine + 788LL) >= 0 )
{
v16 = 0LL;
do
{
if ( ((unsigned __int8)v14 & *(_BYTE *)(copsnrob_bulletsram + v16)) != 0 )
plot_pixel(
a1,
(unsigned int)(256 - j),
(unsigned int)v16,
*(unsigned __int16 *)(*(_QWORD *)(result + 792) + 2LL));
result = Machine;
++v16;
}
while ( *(_DWORD *)(Machine + 788LL) >= (int)v16 );
}
}
while ( 1 )
{
v15 *= 2;
v14 *= 2;
if ( !--v19 )
break;
if ( ((unsigned __int8)v15 & v13) != 0 )
goto LABEL_21;
}
}
}
return result;
}

original_code:
void copsnrob_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs, x, y;
 palette_recalc();
    for (offs = videoram_size;offs >= 0;offs--)
    {
  int sx,sy;
  sx = 31 - (offs % 32);
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] & 0x3f,0,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
    }
    if (copsnrob_cary[0])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[0],0,
                1,0,
                0xe4,256-copsnrob_cary[0],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[1])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[1],0,
                1,0,
                0xc4,256-copsnrob_cary[1],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[2])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[2],0,
                0,0,
                0x24,256-copsnrob_cary[2],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[3])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[3],0,
                0,0,
                0x04,256-copsnrob_cary[3],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
     for (y = 0; y < 256; y++)
     {
  if (copsnrob_truckram[255-y])
  {
   if ((copsnrob_trucky[0] & 0x1f) == ((y+31) & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-(y+31),
      &Machine->visible_area,TRANSPARENCY_PEN,0);
    y += 31;
   }
   else if ((copsnrob_trucky[0] & 0x1f) == (y & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
    }
    for (x = 0; x < 256; x++)
    {
     int bullet, mask1, mask2, val;
        val = copsnrob_bulletsram[x];
        if (!(val & 0x0f)) continue;
        mask1 = 0x01;
        mask2 = 0x10;
        for (bullet = 0; bullet < 4; bullet++)
        {
            if (val & mask1)
            {
                for (y = 0; y <= Machine->visible_area.max_y; y++)
                {
                    if (copsnrob_bulletsram[y] & mask2)
                    {
                        plot_pixel(bitmap, 256-x, y, Machine->pens[1]);
                    }
                }
            }
            mask1 <<= 1;
            mask2 <<= 1;
        }
    }
}

canonical_original_code:
void copsnrob_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int x; int y;
 palette_recalc();
    for (offs = videoram_size;offs >= 0;offs--)
    {
  int sx; int sy;
  sx = 31 - (offs % 32);
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] & 0x3f,0,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
    }
    if (copsnrob_cary[0])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[0],0,
                1,0,
                0xe4,256-copsnrob_cary[0],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[1])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[1],0,
                1,0,
                0xc4,256-copsnrob_cary[1],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[2])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[2],0,
                0,0,
                0x24,256-copsnrob_cary[2],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
    if (copsnrob_cary[3])
    {
        drawgfx(bitmap,Machine->gfx[1],
                copsnrob_carimage[3],0,
                0,0,
                0x04,256-copsnrob_cary[3],
                &Machine->visible_area,TRANSPARENCY_PEN,0);
    }
     for (y = 0; y < 256; y++)
     {
  if (copsnrob_truckram[255-y])
  {
   if ((copsnrob_trucky[0] & 0x1f) == ((y+31) & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-(y+31),
      &Machine->visible_area,TRANSPARENCY_PEN,0);
    y += 31;
   }
   else if ((copsnrob_trucky[0] & 0x1f) == (y & 0x1f))
   {
    drawgfx(bitmap,Machine->gfx[2],
      0,0,
      0,0,
      0x80,256-y,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
  }
    }
    for (x = 0; x < 256; x++)
    {
     int bullet; int mask1; int mask2; int val;
        val = copsnrob_bulletsram[x];
        if (!(val & 0x0f)) continue;
        mask1 = 0x01;
        mask2 = 0x10;
        for (bullet = 0; bullet < 4; bullet++)
        {
            if (val & mask1)
            {
                for (y = 0; y <= Machine->visible_area.max_y; y++)
                {
                    if (copsnrob_bulletsram[y] & mask2)
                    {
                        plot_pixel(bitmap, 256-x, y, Machine->pens[1]);
                    }
                }
            }
            mask1 <<= 1;
            mask2 <<= 1;
        }
    }
}

variable_types: bullet int

variable_types: val int


decompiled_code:
__int64 __fastcall copsnrob_gun_position_r(int a1)
{
int v1; // ebx
char v2; // al
int v3; // edx

switch ( a1 )
{
case 8:
v1 = (unsigned __int8)copsnrob_carimage[2];
v2 = input_port_6_r(0LL);
break;
case 12:
v1 = (unsigned __int8)copsnrob_carimage[3];
v2 = input_port_7_r(0LL);
break;
case 4:
v1 = (unsigned __int8)copsnrob_carimage[1];
v2 = input_port_5_r(0LL);
break;
default:
v1 = (unsigned __int8)*copsnrob_carimage;
v2 = input_port_4_r(0LL);
break;
}
if ( v1 <= 6 )
{
v3 = 6 - v1;
if ( (v2 & 1) != 0 )
goto LABEL_7;
goto LABEL_11;
}
if ( v1 <= 13 )
{
v3 = 13 - v1;
if ( (v2 & 1) != 0 )
{
LABEL_7:
v3 += v3 != 6;
if ( (v2 & 2) != 0 )
return gun_mask[v3 - 1] | v2 & 0x80u;
return gun_mask[v3] | v2 & 0x80u;
}
LABEL_11:
if ( (v2 & 2) != 0 )
{
if ( v3 )
return gun_mask[v3 - 1] | v2 & 0x80u;
return v2 & 0x80 | 0x7Eu;
}
return gun_mask[v3] | v2 & 0x80u;
}
if ( (v2 & 1) == 0 )
return v2 & 0x80 | 0x7Eu;
v3 = v2 & 1;
if ( (v2 & 2) != 0 )
return gun_mask[v3 - 1] | v2 & 0x80u;
return gun_mask[v3] | v2 & 0x80u;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebx
char v2; // al
int v3; // edx

switch ( a1 )
{
case 8:
v1 = (unsigned __int8)copsnrob_carimage[2];
v2 = input_port_6_r(0LL);
break;
case 12:
v1 = (unsigned __int8)copsnrob_carimage[3];
v2 = input_port_7_r(0LL);
break;
case 4:
v1 = (unsigned __int8)copsnrob_carimage[1];
v2 = input_port_5_r(0LL);
break;
default:
v1 = (unsigned __int8)*copsnrob_carimage;
v2 = input_port_4_r(0LL);
break;
}
if ( v1 <= 6 )
{
v3 = 6 - v1;
if ( (v2 & 1) != 0 )
goto LABEL_7;
goto LABEL_11;
}
if ( v1 <= 13 )
{
v3 = 13 - v1;
if ( (v2 & 1) != 0 )
{
LABEL_7:
v3 += v3 != 6;
if ( (v2 & 2) != 0 )
return gun_mask[v3 - 1] | v2 & 0x80u;
return gun_mask[v3] | v2 & 0x80u;
}
LABEL_11:
if ( (v2 & 2) != 0 )
{
if ( v3 )
return gun_mask[v3 - 1] | v2 & 0x80u;
return v2 & 0x80 | 0x7Eu;
}
return gun_mask[v3] | v2 & 0x80u;
}
if ( (v2 & 1) == 0 )
return v2 & 0x80 | 0x7Eu;
v3 = v2 & 1;
if ( (v2 & 2) != 0 )
return gun_mask[v3 - 1] | v2 & 0x80u;
return gun_mask[v3] | v2 & 0x80u;
}

original_code:
data_t copsnrob_gun_position_r(offs_t offset)
{
    int keys, current_car_image, current_gun_pos = 0;
    switch (offset)
    {
    default:
    case 0x00:
        current_car_image = copsnrob_carimage[0];
        keys = input_port_4_r(0);
        break;
    case 0x04:
        current_car_image = copsnrob_carimage[1];
        keys = input_port_5_r(0);
        break;
    case 0x08:
        current_car_image = copsnrob_carimage[2];
        keys = input_port_6_r(0);
        break;
    case 0x0c:
        current_car_image = copsnrob_carimage[3];
        keys = input_port_7_r(0);
    }
    if (current_car_image < 7)
    {
        current_gun_pos = 6 - current_car_image;
    }
    else if (current_car_image < 14)
    {
        current_gun_pos = 13 - current_car_image;
    }
    if ((keys & 0x01) && (current_gun_pos != 6)) current_gun_pos++;
    if ((keys & 0x02) && (current_gun_pos != 0)) current_gun_pos--;
    return (keys & 0x80) | gun_mask[current_gun_pos];
}

canonical_original_code:
unsigned int copsnrob_gun_position_r(unsigned int offset)
{
    int keys; int current_car_image; int current_gun_pos = 0;
    switch (offset)
    {
    default:
    case 0x00:
        current_car_image = copsnrob_carimage[0];
        keys = input_port_4_r(0);
        break;
    case 0x04:
        current_car_image = copsnrob_carimage[1];
        keys = input_port_5_r(0);
        break;
    case 0x08:
        current_car_image = copsnrob_carimage[2];
        keys = input_port_6_r(0);
        break;
    case 0x0c:
        current_car_image = copsnrob_carimage[3];
        keys = input_port_7_r(0);
    }
    if (current_car_image < 7)
    {
        current_gun_pos = 6 - current_car_image;
    }
    else if (current_car_image < 14)
    {
        current_gun_pos = 13 - current_car_image;
    }
    if ((keys & 0x01) && (current_gun_pos != 6)) current_gun_pos++;
    if ((keys & 0x02) && (current_gun_pos != 0)) current_gun_pos--;
    return (keys & 0x80) | gun_mask[current_gun_pos];
}

variable_types: keys int


decodebyte

decompiled_code:
__int64 __fastcall decodebyte(int a1, char a2)
{
int v2; // edx
int v3; // eax
int v4; // edx

v2 = (a2 & 2) == 0 ? -224 : -128;
v3 = v2 | 2;
v4 = v2 | 8;
if ( (a2 & 8) != 0 )
v3 = v4;
return a1 ^ (unsigned int)v3;
}

original_code:
unsigned char decodebyte( unsigned char opcode, unsigned short address )
{
 unsigned char xormask;
 xormask = 0;
 if (address & 0x02) xormask |= 0x80;
 else xormask |= 0x20;
 if (address & 0x08) xormask |= 0x08;
 else xormask |= 0x02;
 return opcode ^ xormask;
}

canonical_original_code:
unsigned char decodebyte(unsigned char opcode, unsigned short address)
{
 unsigned char xormask;
 xormask = 0;
 if (address & 0x02) xormask |= 0x80;
 else xormask |= 0x20;
 if (address & 0x08) xormask |= 0x08;
 else xormask |= 0x02;
 return opcode ^ xormask;
}

variable_types:
opcode
unsigned char

variable_types:
address
unsigned short

variable_types:
xormask
unsigned char

return_type: unsigned char


decompiled_code:
__int64 konami1_decode()
{
return decode(0);
}

canonical_decompiled_code:
__int64 func2()
{
return func1(0);
}

original_code:
void konami1_decode(void)
{
 decode(0);
}

canonical_original_code:
void konami1_decode()
{
 decode(0);
}


decompiled_code:
__int64 konami1_decode_cpu4()
{
return decode(3u);
}

canonical_decompiled_code:
__int64 func3()
{
return func1(3u);
}

original_code:
void konami1_decode_cpu4(void)
{
 decode(3);
}

canonical_original_code:
void konami1_decode_cpu4()
{
 decode(3);
}


decode

decompiled_code:
__int64 __fastcall decode(unsigned int a1)
{
unsigned __int8 *v1; // rbx
int v2; // ebp
int v3; // er12
__int64 result; // rax
int v5; // ebp
int v6; // edi
char v7; // si

v1 = (unsigned __int8 *)memory_region(a1 + 129);
v2 = memory_region_length(a1 + 129);
v3 = v2 / 2;
result = memory_set_opcode_base(a1, &v1[v2 / 2]);
if ( v2 > 1 )
{
v5 = 0;
do
{
v6 = *v1;
v7 = v5++;
++v1;
result = decodebyte(v6, v7);
v1[v3 - 1] = result;
}
while ( v3 > v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned __int8 *v1; // rbx
int v2; // ebp
int v3; // er12
__int64 result; // rax
int v5; // ebp
int v6; // edi
char v7; // si

v1 = (unsigned __int8 *)memory_region(a1 + 129);
v2 = memory_region_length(a1 + 129);
v3 = v2 / 2;
result = memory_set_opcode_base(a1, &v1[v2 / 2]);
if ( v2 > 1 )
{
v5 = 0;
do
{
v6 = *v1;
v7 = v5++;
++v1;
result = func0(v6, v7);
v1[v3 - 1] = result;
}
while ( v3 > v5 );
}
return result;
}

original_code:
static void decode(int cpu)
{
 unsigned char *rom = memory_region(REGION_CPU1+cpu);
 int diff = memory_region_length(REGION_CPU1+cpu) / 2;
 int A;
 memory_set_opcode_base(cpu,rom+diff);
 for (A = 0;A < diff;A++)
 {
  rom[A+diff] = decodebyte(rom[A],A);
 }
}

variable_types: cpu int

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int


original_code:
void mb_go_w(offs_t offset,data_t data)
{
  s32 mb_temp;
  s16 mb_q;
  int msb;
  switch (offset)
    {
    case 0x00: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0xff00) | data; break;
    case 0x01: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0x00ff) | (data << 8); break;
    case 0x02: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0xff00) | data; break;
    case 0x03: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0x00ff) | (data << 8); break;
    case 0x04: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0xff00) | data; break;
    case 0x05: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0x00ff) | (data << 8); break;
    case 0x06: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0xff00) | data; break;
    case 0x07: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8); break;
    case 0x08: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0xff00) | data; break;
    case 0x09: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0x00ff) | (data << 8); break;
    case 0x0a: mb_result = mb_reg [0x05] = (mb_reg [0x05] & 0xff00) | data; break;
    case 0x0c: mb_result = mb_reg [0x06] = data; break;
    case 0x15: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0xff00) | data; break;
    case 0x16: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0x00ff) | (data << 8); break;
    case 0x1a: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0xff00) | data; break;
    case 0x1b: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0x00ff) | (data << 8); break;
    case 0x0d: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0xff00) | data; break;
    case 0x0e: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0x00ff) | (data << 8); break;
    case 0x0f: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0xff00) | data; break;
    case 0x10: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0x00ff) | (data << 8); break;
    case 0x17: mb_result = mb_reg [0x07]; break;
    case 0x19: mb_result = mb_reg [0x08]; break;
    case 0x18: mb_result = mb_reg [0x09]; break;
    case 0x0b:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = (s16)0xffff;
      mb_reg [0x04] -= mb_reg [0x02];
      mb_reg [0x05] -= mb_reg [0x03];
    step_048:
      mb_temp = ((s32) mb_reg [0x00]) * ((s32) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x0e] = mb_temp & 0xffff;
      mb_temp = ((s32) -mb_reg [0x01]) * ((s32) mb_reg [0x05]);
      mb_reg [0x07] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x07] += mb_reg [0x0c];
      mb_reg [0x0e] = (mb_reg [0x0e] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_q = mb_reg [0x0c] + mb_reg [0x0e];
      if (mb_q < 0)
 mb_reg [0x07]++;
      mb_result = mb_reg [0x07];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x07] += mb_reg [0x02];
    case 0x12:
      mb_temp = ((s32) mb_reg [0x01]) * ((s32) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x09] = mb_temp & 0xffff;
      mb_temp = ((s32) mb_reg [0x00]) * ((s32) mb_reg [0x05]);
      mb_reg [0x08] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x08] += mb_reg [0x0c];
      mb_reg [0x09] = (mb_reg [0x09] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_reg [0x09] += mb_reg [0x0c];
      if (mb_reg [0x09] < 0)
 mb_reg [0x08]++;
      mb_reg [0x09] <<= 1;
      mb_result = mb_reg [0x08];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x08] += mb_reg [0x03];
      mb_reg [0x09] &= 0xff00;
    case 0x13:
      mb_reg [0x0c] = mb_reg [0x09];
      mb_q = mb_reg [0x08];
      goto step_0bf;
    case 0x14:
      mb_reg [0x0c] = mb_reg [0x0a];
      mb_q = mb_reg [0x0b];
    step_0bf:
      mb_reg [0x0e] = mb_reg [0x07] ^ mb_q;
      mb_reg [0x0d] = mb_q;
      if (mb_q >= 0)
 mb_q = mb_reg [0x0c];
      else
 {
   mb_reg [0x0d] = - mb_q - 1;
   mb_q = - mb_reg [0x0c] - 1;
   if ((mb_q < 0) && ((mb_q + 1) < 0))
     mb_reg [0x0d]++;
   mb_q++;
 }
      if (mb_reg [0x07] >= 0)
 mb_reg [0x0c] = mb_reg [0x07];
      else
        mb_reg [0x0c] = -mb_reg [0x07];
      mb_reg [0x0f] = mb_reg [0x06];
      do
 {
   mb_reg [0x0d] -= mb_reg [0x0c];
   msb = ((mb_q & 0x8000) != 0);
   mb_q <<= 1;
   if (mb_reg [0x0d] >= 0)
     mb_q++;
   else
     mb_reg [0x0d] += mb_reg [0x0c];
   mb_reg [0x0d] <<= 1;
   mb_reg [0x0d] += msb;
 }
      while (--mb_reg [0x0f] >= 0);
      if (mb_reg [0x0e] >= 0)
 mb_result = mb_q;
      else
 mb_result = - mb_q;
      break;
    case 0x11:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = 0x0000;
      goto step_048;
      break;
    case 0x1c:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      do
 {
   mb_reg [0x0e] = (mb_reg [0x04] + mb_reg [0x07]) >> 1;
   mb_reg [0x0f] = (mb_reg [0x05] + mb_reg [0x08]) >> 1;
   if ((mb_reg [0x0b] < mb_reg [0x0e]) && (mb_reg [0x0f] < mb_reg [0x0e]) && ((mb_reg [0x0e] + mb_reg [0x0f]) >= 0))
     { mb_reg [0x07] = mb_reg [0x0e]; mb_reg [0x08] = mb_reg [0x0f]; }
   else
     { mb_reg [0x04] = mb_reg [0x0e]; mb_reg [0x05] = mb_reg [0x0f]; }
 }
      while (--mb_reg [0x06] >= 0);
      mb_result = mb_reg [0x08];
      break;
    case 0x1d:
      mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8);
      mb_reg [0x02] -= mb_reg [0x00];
      if (mb_reg [0x02] < 0)
 mb_reg [0x02] = -mb_reg [0x02];
      mb_reg [0x03] -= mb_reg [0x01];
      if (mb_reg [0x03] < 0)
 mb_reg [0x03] = -mb_reg [0x03];
    case 0x1e:
      if (mb_reg [0x03] >= mb_reg [0x02])
        { mb_reg [0x0c] = mb_reg [0x02]; mb_reg [0x0d] = mb_reg [0x03]; }
      else
 { mb_reg [0x0d] = mb_reg [0x02]; mb_reg [0x0c] = mb_reg [0x03]; }
      mb_reg [0x0c] >>= 2;
      mb_reg [0x0d] += mb_reg [0x0c];
      mb_reg [0x0c] >>= 1;
      mb_result = mb_reg [0x0d] = (mb_reg [0x0c] + mb_reg [0x0d]);
      break;
    case 0x1f:
      break;
    }
}

canonical_original_code:
void mb_go_w(unsigned int offset, unsigned int data)
{
  int mb_temp;
  short mb_q;
  int msb;
  switch (offset)
    {
    case 0x00: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0xff00) | data; break;
    case 0x01: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0x00ff) | (data << 8); break;
    case 0x02: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0xff00) | data; break;
    case 0x03: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0x00ff) | (data << 8); break;
    case 0x04: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0xff00) | data; break;
    case 0x05: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0x00ff) | (data << 8); break;
    case 0x06: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0xff00) | data; break;
    case 0x07: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8); break;
    case 0x08: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0xff00) | data; break;
    case 0x09: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0x00ff) | (data << 8); break;
    case 0x0a: mb_result = mb_reg [0x05] = (mb_reg [0x05] & 0xff00) | data; break;
    case 0x0c: mb_result = mb_reg [0x06] = data; break;
    case 0x15: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0xff00) | data; break;
    case 0x16: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0x00ff) | (data << 8); break;
    case 0x1a: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0xff00) | data; break;
    case 0x1b: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0x00ff) | (data << 8); break;
    case 0x0d: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0xff00) | data; break;
    case 0x0e: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0x00ff) | (data << 8); break;
    case 0x0f: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0xff00) | data; break;
    case 0x10: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0x00ff) | (data << 8); break;
    case 0x17: mb_result = mb_reg [0x07]; break;
    case 0x19: mb_result = mb_reg [0x08]; break;
    case 0x18: mb_result = mb_reg [0x09]; break;
    case 0x0b:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = (short)0xffff;
      mb_reg [0x04] -= mb_reg [0x02];
      mb_reg [0x05] -= mb_reg [0x03];
    step_048:
      mb_temp = ((int) mb_reg [0x00]) * ((int) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x0e] = mb_temp & 0xffff;
      mb_temp = ((s32) -mb_reg [0x01]) * ((int) mb_reg [0x05]);
      mb_reg [0x07] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x07] += mb_reg [0x0c];
      mb_reg [0x0e] = (mb_reg [0x0e] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_q = mb_reg [0x0c] + mb_reg [0x0e];
      if (mb_q < 0)
 mb_reg [0x07]++;
      mb_result = mb_reg [0x07];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x07] += mb_reg [0x02];
    case 0x12:
      mb_temp = ((int) mb_reg [0x01]) * ((int) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x09] = mb_temp & 0xffff;
      mb_temp = ((int) mb_reg [0x00]) * ((int) mb_reg [0x05]);
      mb_reg [0x08] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x08] += mb_reg [0x0c];
      mb_reg [0x09] = (mb_reg [0x09] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_reg [0x09] += mb_reg [0x0c];
      if (mb_reg [0x09] < 0)
 mb_reg [0x08]++;
      mb_reg [0x09] <<= 1;
      mb_result = mb_reg [0x08];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x08] += mb_reg [0x03];
      mb_reg [0x09] &= 0xff00;
    case 0x13:
      mb_reg [0x0c] = mb_reg [0x09];
      mb_q = mb_reg [0x08];
      goto step_0bf;
    case 0x14:
      mb_reg [0x0c] = mb_reg [0x0a];
      mb_q = mb_reg [0x0b];
    step_0bf:
      mb_reg [0x0e] = mb_reg [0x07] ^ mb_q;
      mb_reg [0x0d] = mb_q;
      if (mb_q >= 0)
 mb_q = mb_reg [0x0c];
      else
 {
   mb_reg [0x0d] = - mb_q - 1;
   mb_q = - mb_reg [0x0c] - 1;
   if ((mb_q < 0) && ((mb_q + 1) < 0))
     mb_reg [0x0d]++;
   mb_q++;
 }
      if (mb_reg [0x07] >= 0)
 mb_reg [0x0c] = mb_reg [0x07];
      else
        mb_reg [0x0c] = -mb_reg [0x07];
      mb_reg [0x0f] = mb_reg [0x06];
      do
 {
   mb_reg [0x0d] -= mb_reg [0x0c];
   msb = ((mb_q & 0x8000) != 0);
   mb_q <<= 1;
   if (mb_reg [0x0d] >= 0)
     mb_q++;
   else
     mb_reg [0x0d] += mb_reg [0x0c];
   mb_reg [0x0d] <<= 1;
   mb_reg [0x0d] += msb;
 }
      while (--mb_reg [0x0f] >= 0);
      if (mb_reg [0x0e] >= 0)
 mb_result = mb_q;
      else
 mb_result = - mb_q;
      break;
    case 0x11:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = 0x0000;
      goto step_048;
      break;
    case 0x1c:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      do
 {
   mb_reg [0x0e] = (mb_reg [0x04] + mb_reg [0x07]) >> 1;
   mb_reg [0x0f] = (mb_reg [0x05] + mb_reg [0x08]) >> 1;
   if ((mb_reg [0x0b] < mb_reg [0x0e]) && (mb_reg [0x0f] < mb_reg [0x0e]) && ((mb_reg [0x0e] + mb_reg [0x0f]) >= 0))
     { mb_reg [0x07] = mb_reg [0x0e]; mb_reg [0x08] = mb_reg [0x0f]; }
   else
     { mb_reg [0x04] = mb_reg [0x0e]; mb_reg [0x05] = mb_reg [0x0f]; }
 }
      while (--mb_reg [0x06] >= 0);
      mb_result = mb_reg [0x08];
      break;
    case 0x1d:
      mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8);
      mb_reg [0x02] -= mb_reg [0x00];
      if (mb_reg [0x02] < 0)
 mb_reg [0x02] = -mb_reg [0x02];
      mb_reg [0x03] -= mb_reg [0x01];
      if (mb_reg [0x03] < 0)
 mb_reg [0x03] = -mb_reg [0x03];
    case 0x1e:
      if (mb_reg [0x03] >= mb_reg [0x02])
        { mb_reg [0x0c] = mb_reg [0x02]; mb_reg [0x0d] = mb_reg [0x03]; }
      else
 { mb_reg [0x0d] = mb_reg [0x02]; mb_reg [0x0c] = mb_reg [0x03]; }
      mb_reg [0x0c] >>= 2;
      mb_reg [0x0d] += mb_reg [0x0c];
      mb_reg [0x0c] >>= 1;
      mb_result = mb_reg [0x0d] = (mb_reg [0x0c] + mb_reg [0x0d]);
      break;
    case 0x1f:
      break;
    }
}

variable_types: msb int


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

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

original_code:
data_t mb_status_r(offs_t offset)
{
 return 0x00;
}

canonical_original_code:
unsigned int mb_status_r(unsigned int offset)
{
 return 0x00;
}


decompiled_code:
__int64 mb_lo_r()
{
return mb_result;
}

canonical_decompiled_code:
__int64 func2()
{
return mb_result;
}

original_code:
data_t mb_lo_r(offs_t offset)
{
 return mb_result & 0xff;
}

canonical_original_code:
unsigned int mb_lo_r(unsigned int offset)
{
 return mb_result & 0xff;
}


decompiled_code:
__int64 mb_hi_r()
{
return unk_7A1;
}

canonical_decompiled_code:
__int64 func3()
{
return unk_7A1;
}

original_code:
data_t mb_hi_r(offs_t offset)
{
 return (mb_result >> 8) & 0xff;
}

canonical_original_code:
unsigned int mb_hi_r(unsigned int offset)
{
 return (mb_result >> 8) & 0xff;
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall sauro_scroll1_w(__int64 a1, int a2)
{
scroll1 = a2;
}

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

original_code:
void sauro_scroll1_w(offs_t offset,data_t data)
{
 scroll1 = data;
}

canonical_original_code:
void sauro_scroll1_w(unsigned int offset, unsigned int data)
{
 scroll1 = data;
}


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

if ( flipscreen != a2 )
{
flipscreen = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

if ( flipscreen != a2 )
{
flipscreen = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void sauro_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != data)
 {
  flipscreen = data;
  memset(dirtybuffer, 1, videoram_size);
 }
}

canonical_original_code:
void sauro_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != data)
 {
  flipscreen = data;
  memset(dirtybuffer, 1, videoram_size);
 }
}


decompiled_code:
__int64 __fastcall sauro_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // r15
__int64 v2; // r8
__int64 v3; // rax
unsigned __int64 v4; // r14
__int64 v5; // rdx
__int64 v6; // r8
__int64 result; // rax
unsigned __int64 v8; // rbp
__int64 v9; // r8
__int16 v10; // r8
unsigned __int8 v11; // cl
unsigned int v12; // er10
int v13[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( videoram_size )
{
v1 = 0LL;
do
{
if ( *(_BYTE *)(v1 + dirtybuffer) )
{
*(_BYTE *)(v1 + dirtybuffer) = 0;
v2 = *(_BYTE *)(colorram + v1) & 8;
if ( flipscreen )
v2 = (_DWORD)v2 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v1) + ((*(unsigned __int8 *)(colorram + v1) << 8) & 0x700u),
*(_BYTE *)(colorram + v1) >> 4,
v2);
}
++v1;
}
while ( videoram_size > v1 );
}
v3 = Machine + 776LL;
if ( flipscreen )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll1, 0LL, 0LL, v3, 0LL, 0LL);
}
else
{
v13[0] = -scroll1;
copyscrollbitmap(a1, tmpbitmap, 1LL, v13, 0LL, 0LL, v3, 0LL, 0LL);
}
if ( videoram_size )
{
v4 = 0LL;
do
{
v5 = *(unsigned __int8 *)(sauro_videoram2 + v4) + ((*(unsigned __int8 *)(sauro_colorram2 + v4) << 8) & 0x700u);
if ( (_DWORD)v5 != 25 )
{
v6 = *(_BYTE *)(sauro_colorram2 + v4) & 8;
if ( flipscreen )
v6 = (_DWORD)v6 == 0;
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v5, *(_BYTE *)(sauro_colorram2 + v4) >> 4, v6);
}
++v4;
}
while ( videoram_size > v4 );
}
result = spriteram_size - 1LL;
if ( (unsigned __int64)(spriteram_size - 1LL) > 3 )
{
v8 = 3LL;
while ( 1 )
{
if ( *(unsigned __int8 *)(spriteram + v8) == 248 )
goto LABEL_21;
v10 = *(unsigned __int8 *)(spriteram + v8 + 3);
v11 = (unsigned __int8)v10 >> 4;
v12 = *(unsigned __int8 *)(spriteram + v8 + 1) + ((v10 << 8) & 0x300);
if ( (v10 & 8) == 0 )
break;
v9 = v10 & 4;
if ( flipscreen )
goto LABEL_26;
LABEL_20:
drawgfx(a1, *(_QWORD *)(Machine + 528LL), v12, v11, v9);
LABEL_21:
v8 += 4LL;
result = spriteram_size - 1LL;
if ( spriteram_size - 1LL <= v8 )
return result;
}
if ( *(unsigned __int8 *)(spriteram + v8 + 2) <= 0x3Fu )
goto LABEL_21;
v9 = v10 & 4;
if ( !flipscreen )
goto LABEL_20;
LABEL_26:
v9 = (_DWORD)v9 == 0;
goto LABEL_20;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // r15
__int64 v2; // r8
__int64 v3; // rax
unsigned __int64 v4; // r14
__int64 v5; // rdx
__int64 v6; // r8
__int64 result; // rax
unsigned __int64 v8; // rbp
__int64 v9; // r8
__int16 v10; // r8
unsigned __int8 v11; // cl
unsigned int v12; // er10
int v13[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( videoram_size )
{
v1 = 0LL;
do
{
if ( *(_BYTE *)(v1 + dirtybuffer) )
{
*(_BYTE *)(v1 + dirtybuffer) = 0;
v2 = *(_BYTE *)(colorram + v1) & 8;
if ( flipscreen )
v2 = (_DWORD)v2 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v1) + ((*(unsigned __int8 *)(colorram + v1) << 8) & 0x700u),
*(_BYTE *)(colorram + v1) >> 4,
v2);
}
++v1;
}
while ( videoram_size > v1 );
}
v3 = Machine + 776LL;
if ( flipscreen )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll1, 0LL, 0LL, v3, 0LL, 0LL);
}
else
{
v13[0] = -scroll1;
copyscrollbitmap(a1, tmpbitmap, 1LL, v13, 0LL, 0LL, v3, 0LL, 0LL);
}
if ( videoram_size )
{
v4 = 0LL;
do
{
v5 = *(unsigned __int8 *)(sauro_videoram2 + v4) + ((*(unsigned __int8 *)(sauro_colorram2 + v4) << 8) & 0x700u);
if ( (_DWORD)v5 != 25 )
{
v6 = *(_BYTE *)(sauro_colorram2 + v4) & 8;
if ( flipscreen )
v6 = (_DWORD)v6 == 0;
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v5, *(_BYTE *)(sauro_colorram2 + v4) >> 4, v6);
}
++v4;
}
while ( videoram_size > v4 );
}
result = spriteram_size - 1LL;
if ( (unsigned __int64)(spriteram_size - 1LL) > 3 )
{
v8 = 3LL;
while ( 1 )
{
if ( *(unsigned __int8 *)(spriteram + v8) == 248 )
goto LABEL_21;
v10 = *(unsigned __int8 *)(spriteram + v8 + 3);
v11 = (unsigned __int8)v10 >> 4;
v12 = *(unsigned __int8 *)(spriteram + v8 + 1) + ((v10 << 8) & 0x300);
if ( (v10 & 8) == 0 )
break;
v9 = v10 & 4;
if ( flipscreen )
goto LABEL_26;
LABEL_20:
drawgfx(a1, *(_QWORD *)(Machine + 528LL), v12, v11, v9);
LABEL_21:
v8 += 4LL;
result = spriteram_size - 1LL;
if ( spriteram_size - 1LL <= v8 )
return result;
}
if ( *(unsigned __int8 *)(spriteram + v8 + 2) <= 0x3Fu )
goto LABEL_21;
v9 = v10 & 4;
if ( !flipscreen )
goto LABEL_20;
LABEL_26:
v9 = (_DWORD)v9 == 0;
goto LABEL_20;
}
return result;
}

original_code:
void sauro_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs,code,sx,sy,color,flipx;
 for (offs = 0; offs < videoram_size; offs ++)
 {
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  code = videoram[offs] + ((colorram[offs] & 0x07) << 8);
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (colorram[offs] >> 4) & 0x0f;
  flipx = colorram[offs] & 0x08;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(tmpbitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
 }
 if (!flipscreen)
 {
  int scroll = -scroll1;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll ,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 else
 {
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll1,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  code = sauro_videoram2[offs] + ((sauro_colorram2[offs] & 0x07) << 8);
  if (code == 0x19) continue;
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (sauro_colorram2[offs] >> 4) & 0x0f;
  flipx = sauro_colorram2[offs] & 0x08;
  sx = (sx - scroll2) & 0xff;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 };
 for (offs = 3;offs < spriteram_size - 1;offs += 4)
 {
  sy = spriteram[offs];
  if (sy == 0xf8) continue;
  code = spriteram[offs+1] + ((spriteram[offs+3] & 0x03) << 8);
  sx = spriteram[offs+2];
  sy = 236 - sy;
  color = (spriteram[offs+3] >> 4) & 0x0f;
  if (spriteram[offs+3] & 0x08)
  {
   if (sx > 0xc0)
   {
    sx = (signed int)(signed char)sx;
   }
  }
  else
  {
   if (sx < 0x40) continue;
  }
  flipx = spriteram[offs+3] & 0x04;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = (235 - sx) & 0xff;
   sy = 240 - sy;
  }
  drawgfx(bitmap, Machine->gfx[2],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void sauro_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int code; int sx; int sy; int color; int flipx;
 for (offs = 0; offs < videoram_size; offs ++)
 {
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  code = videoram[offs] + ((colorram[offs] & 0x07) << 8);
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (colorram[offs] >> 4) & 0x0f;
  flipx = colorram[offs] & 0x08;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(tmpbitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
 }
 if (!flipscreen)
 {
  int scroll = -scroll1;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll ,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 else
 {
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll1,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  code = sauro_videoram2[offs] + ((sauro_colorram2[offs] & 0x07) << 8);
  if (code == 0x19) continue;
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (sauro_colorram2[offs] >> 4) & 0x0f;
  flipx = sauro_colorram2[offs] & 0x08;
  sx = (sx - scroll2) & 0xff;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 };
 for (offs = 3;offs < spriteram_size - 1;offs += 4)
 {
  sy = spriteram[offs];
  if (sy == 0xf8) continue;
  code = spriteram[offs+1] + ((spriteram[offs+3] & 0x03) << 8);
  sx = spriteram[offs+2];
  sy = 236 - sy;
  color = (spriteram[offs+3] >> 4) & 0x0f;
  if (spriteram[offs+3] & 0x08)
  {
   if (sx > 0xc0)
   {
    sx = (int)(char)sx;
   }
  }
  else
  {
   if (sx < 0x40) continue;
  }
  flipx = spriteram[offs+3] & 0x04;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = (235 - sx) & 0xff;
   sy = 240 - sy;
  }
  drawgfx(bitmap, Machine->gfx[2],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: code int

variable_types: sx int

variable_types: sy int

variable_types: color int

variable_types: flipx int

variable_types: scroll int


original_code:
static void init_sauro(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memset(&RAM[0xe000], 0, 0x100);
 RAM[0xe000] = 1;
}

canonical_original_code:
static void init_sauro()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memset(&RAM[0xe000], 0, 0x100);
 RAM[0xe000] = 1;
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 sauron_interrupt()
{
cpu_cause_interrupt(1LL, 4294967294LL);
return 4294966296LL;
}

original_code:
static int sauron_interrupt(void)
{
 cpu_cause_interrupt(1,-2);
 return -1000;
}

canonical_original_code:
static int sauron_interrupt()
{
 cpu_cause_interrupt(1,-2);
 return -1000;
}


decompiled_code:
__int64 __fastcall sauro_sound_command_r(unsigned int a1)
{
unsigned int v1; // er12

v1 = soundlatch_r();
soundlatch_clear_w(a1, 0LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // er12

v1 = soundlatch_r();
soundlatch_clear_w(a1, 0LL);
return v1;
}

original_code:
static data_t sauro_sound_command_r(offs_t offset)
{
 int ret = soundlatch_r(offset);
 soundlatch_clear_w(offset,0);
 return ret;
}

canonical_original_code:
static unsigned int sauro_sound_command_r(unsigned int offset)
{
 int ret = soundlatch_r(offset);
 soundlatch_clear_w(offset,0);
 return ret;
}

variable_types:
offset
unsigned int

variable_types: ret int


decompiled_code:
__int64 __fastcall sauro_sound_command_w(__int64 a1, __int64 a2)
{
LOBYTE(a2) = a2 | 0x80;
return soundlatch_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
LOBYTE(a2) = a2 | 0x80;
return soundlatch_w(a1, a2);
}

original_code:
static void sauro_sound_command_w(offs_t offset,data_t data)
{
 data |= 0x80;
 soundlatch_w(offset,data);
}

canonical_original_code:
static void sauro_sound_command_w(unsigned int offset, unsigned int data)
{
 data |= 0x80;
 soundlatch_w(offset,data);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall dotron_change_palette(int a1)
{
char *v1; // rbx
__int64 result; // rax
int v3; // ebp
int v4; // er12
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rdi

v1 = (char *)&dotron_palettes + 768 * a1;
result = *(unsigned int *)(artwork_backdrop + 48LL);
if ( (int)result > 0 )
{
v3 = 0;
v4 = *(_DWORD *)(artwork_backdrop + 68LL) + 95;
do
{
v5 = (unsigned __int8)v1[2];
v6 = (unsigned __int8)v1[1];
v7 = (unsigned int)(v4 + v3);
v1 += 3;
++v3;
palette_change_color(v7, (unsigned __int8)*(v1 - 3), v6, v5);
result = artwork_backdrop;
}
while ( *(_DWORD *)(artwork_backdrop + 48LL) > v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
char *v1; // rbx
__int64 result; // rax
int v3; // ebp
int v4; // er12
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rdi

v1 = (char *)&dotron_palettes + 768 * a1;
result = *(unsigned int *)(artwork_backdrop + 48LL);
if ( (int)result > 0 )
{
v3 = 0;
v4 = *(_DWORD *)(artwork_backdrop + 68LL) + 95;
do
{
v5 = (unsigned __int8)v1[2];
v6 = (unsigned __int8)v1[1];
v7 = (unsigned int)(v4 + v3);
v1 += 3;
++v3;
palette_change_color(v7, (unsigned __int8)*(v1 - 3), v6, v5);
result = artwork_backdrop;
}
while ( *(_DWORD *)(artwork_backdrop + 48LL) > v3 );
}
return result;
}

original_code:
static void dotron_change_palette(int which)
{
 UINT8 *new_palette;
 int i, offset;
 offset = artwork_backdrop->start_pen + 95;
 new_palette = dotron_palettes[which];
 for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  palette_change_color(i + offset, new_palette[i * 3], new_palette[i * 3 + 1], new_palette[i * 3 + 2]);
}

canonical_original_code:
static void dotron_change_palette(int which)
{
 unsigned char *new_palette;
 int i; int offset;
 offset = artwork_backdrop->start_pen + 95;
 new_palette = dotron_palettes[which];
 for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  palette_change_color(i + offset, new_palette[i * 3], new_palette[i * 3 + 1], new_palette[i * 3 + 2]);
}

variable_types: which int

variable_types: offset int


decompiled_code:
void *__fastcall mcr3_update_background(__int64 a1, unsigned __int8 a2)
{
void *result; // rax
int v3; // ebp
__int64 v4; // rbx
int v5; // er12
int v6; // esi
int v7; // eax
__int64 v8; // rdx
__int64 v9; // r10
__int64 v10; // rcx
unsigned __int8 v11; // r9
unsigned __int8 v12; // r8

result = &videoram_size;
v3 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v4 = v3;
v5 = a2;
do
{
result = (void *)dirtybuffer;
if ( *(_BYTE *)(dirtybuffer + v4) )
{
v6 = v3 >> 6;
v7 = (v3 >> 1) & 0x1F;
v8 = *(unsigned __int8 *)(videoram + v4) + ((unsigned __int8)(*(_BYTE *)(videoram + v4 + 1) & 3) << 8);
v9 = *(_QWORD *)(Machine + 512LL);
v10 = v5 ^ (*(unsigned __int8 *)(videoram + v4 + 1) >> 4) & 3u;
v11 = *(_BYTE *)(videoram + v4 + 1) & 8;
v12 = *(_BYTE *)(videoram + v4 + 1) & 4;
if ( mcr_cocktail_flip )
drawgfx(
a1,
v9,
v8,
v10,
v12 == 0,
v11 == 0,
(unsigned int)(16 * (31 - v7)),
(unsigned int)(16 * (29 - v6)),
Machine + 776LL,
0LL,
0LL);
else
drawgfx(
a1,
v9,
v8,
v10,
v12,
v11,
(unsigned int)(16 * v7),
(unsigned int)(16 * v6),
Machine + 776LL,
0LL,
0LL);
result = (void *)dirtybuffer;
*(_BYTE *)(dirtybuffer + v4) = 0;
}
v4 -= 2LL;
v3 -= 2;
}
while ( v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, unsigned __int8 a2)
{
void *result; // rax
int v3; // ebp
__int64 v4; // rbx
int v5; // er12
int v6; // esi
int v7; // eax
__int64 v8; // rdx
__int64 v9; // r10
__int64 v10; // rcx
unsigned __int8 v11; // r9
unsigned __int8 v12; // r8

result = &videoram_size;
v3 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v4 = v3;
v5 = a2;
do
{
result = (void *)dirtybuffer;
if ( *(_BYTE *)(dirtybuffer + v4) )
{
v6 = v3 >> 6;
v7 = (v3 >> 1) & 0x1F;
v8 = *(unsigned __int8 *)(videoram + v4) + ((unsigned __int8)(*(_BYTE *)(videoram + v4 + 1) & 3) << 8);
v9 = *(_QWORD *)(Machine + 512LL);
v10 = v5 ^ (*(unsigned __int8 *)(videoram + v4 + 1) >> 4) & 3u;
v11 = *(_BYTE *)(videoram + v4 + 1) & 8;
v12 = *(_BYTE *)(videoram + v4 + 1) & 4;
if ( mcr_cocktail_flip )
drawgfx(
a1,
v9,
v8,
v10,
v12 == 0,
v11 == 0,
(unsigned int)(16 * (31 - v7)),
(unsigned int)(16 * (29 - v6)),
Machine + 776LL,
0LL,
0LL);
else
drawgfx(
a1,
v9,
v8,
v10,
v12,
v11,
(unsigned int)(16 * v7),
(unsigned int)(16 * v6),
Machine + 776LL,
0LL,
0LL);
result = (void *)dirtybuffer;
*(_BYTE *)(dirtybuffer + v4) = 0;
}
v4 -= 2LL;
v3 -= 2;
}
while ( v3 >= 0 );
}
return result;
}

original_code:
static void mcr3_update_background(struct osd_bitmap *bitmap, UINT8 color_xor)
{
 int offs;
 for (offs = videoram_size - 2; offs >= 0; offs -= 2)
 {
  if (dirtybuffer[offs])
  {
   int mx = (offs / 2) % 32;
   int my = (offs / 2) / 32;
   int attr = videoram[offs + 1];
   int color = ((attr & 0x30) >> 4) ^ color_xor;
   int code = videoram[offs] + 256 * (attr & 0x03);
   if (!mcr_cocktail_flip)
    drawgfx(bitmap, Machine->gfx[0], code, color, attr & 0x04, attr & 0x08,
      16 * mx, 16 * my, &Machine->visible_area, TRANSPARENCY_NONE, 0);
   else
    drawgfx(bitmap, Machine->gfx[0], code, color, !(attr & 0x04), !(attr & 0x08),
      16 * (31 - mx), 16 * (29 - my), &Machine->visible_area, TRANSPARENCY_NONE, 0);
   dirtybuffer[offs] = 0;
  }
 }
}

canonical_original_code:
static void mcr3_update_background(struct osd_bitmap *bitmap, unsigned char color_xor)
{
 int offs;
 for (offs = videoram_size - 2; offs >= 0; offs -= 2)
 {
  if (dirtybuffer[offs])
  {
   int mx = (offs / 2) % 32;
   int my = (offs / 2) / 32;
   int attr = videoram[offs + 1];
   int color = ((attr & 0x30) >> 4) ^ color_xor;
   int code = videoram[offs] + 256 * (attr & 0x03);
   if (!mcr_cocktail_flip)
    drawgfx(bitmap, Machine->gfx[0], code, color, attr & 0x04, attr & 0x08,
      16 * mx, 16 * my, &Machine->visible_area, TRANSPARENCY_NONE, 0);
   else
    drawgfx(bitmap, Machine->gfx[0], code, color, !(attr & 0x04), !(attr & 0x08),
      16 * (31 - mx), 16 * (29 - my), &Machine->visible_area, TRANSPARENCY_NONE, 0);
   dirtybuffer[offs] = 0;
  }
 }
}

variable_types: mx int

variable_types: my int

variable_types: attr int


original_code:
void mcr3_paletteram_w(offs_t offset,data_t data)
{
 int r, g, b;
 paletteram[offset] = data;
 offset &= 0x7f;
 r = ((offset & 1) << 2) + (data >> 6);
 g = (data >> 0) & 7;
 b = (data >> 3) & 7;
 r = (r << 5) | (r << 2) | (r >> 1);
 g = (g << 5) | (g << 2) | (g >> 1);
 b = (b << 5) | (b << 2) | (b >> 1);
 palette_change_color(offset / 2, r, g, b);
}

canonical_original_code:
void mcr3_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 paletteram[offset] = data;
 offset &= 0x7f;
 r = ((offset & 1) << 2) + (data >> 6);
 g = (data >> 0) & 7;
 b = (data >> 3) & 7;
 r = (r << 5) | (r << 2) | (r >> 1);
 g = (g << 5) | (g << 2) | (g >> 1);
 b = (b << 5) | (b << 2) | (b >> 1);
 palette_change_color(offset / 2, r, g, b);
}

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 spyhunt_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 result; // rax

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
spyhunt_backbitmap = bitmap_alloc(4096LL, 1024LL);
if ( spyhunt_backbitmap )
{
spyhunt_scrolly = 0;
spyhunt_scrollx = 0;
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
size_t v0; // r12
void *v1; // rax
__int64 result; // rax

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
spyhunt_backbitmap = bitmap_alloc(4096LL, 1024LL);
if ( spyhunt_backbitmap )
{
spyhunt_scrolly = 0;
spyhunt_scrollx = 0;
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
int spyhunt_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(videoram_size);
 if (!dirtybuffer)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 spyhunt_backbitmap = bitmap_alloc(64*64, 32*32);
 if (!spyhunt_backbitmap)
 {
  free(dirtybuffer);
  return 1;
 }
 spyhunt_scrollx = spyhunt_scrolly = 0;
 return 0;
}

canonical_original_code:
int spyhunt_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(videoram_size);
 if (!dirtybuffer)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 spyhunt_backbitmap = bitmap_alloc(64*64, 32*32);
 if (!spyhunt_backbitmap)
 {
  free(dirtybuffer);
  return 1;
 }
 spyhunt_scrollx = spyhunt_scrolly = 0;
 return 0;
}


decompiled_code:
void spyhunt_vh_stop()
{
bitmap_free(spyhunt_backbitmap);
free(dirtybuffer);
}

canonical_decompiled_code:
void func6()
{
bitmap_free(spyhunt_backbitmap);
free(dirtybuffer);
}

original_code:
void spyhunt_vh_stop(void)
{
 bitmap_free(spyhunt_backbitmap);
 free(dirtybuffer);
}


decompiled_code:
__int64 dotron_vh_start()
{
unsigned int v0; // er15
unsigned int v2; // ebp
int **v3; // rdi
unsigned int v4; // ebx
int v5; // eax
__int64 v6; // rsi
_QWORD *v7; // rbx
_BYTE *v8; // rdx
int v9; // edi
__int64 v10; // rax
int v11; // ecx
int v12; // ecx
int v13; // ecx
int v14; // ecx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = 0;
backdrop_load("dotron.png", 64LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 64));
v3 = (int **)artwork_backdrop;
if ( artwork_backdrop )
{
do
{
if ( **v3 > 0 )
{
v4 = 0;
do
{
v5 = read_pixel(v3[3], v4, v2);
v6 = v4++;
plot_pixel(artwork_backdrop[3], v6, v2, (unsigned int)(v5 + 95));
v3 = (int **)artwork_backdrop;
}
while ( *(_DWORD *)*artwork_backdrop > (signed int)v4 );
}
++v2;
}
while ( v2 != 138 );
backdrop_refresh();
v7 = artwork_backdrop;
memcpy(&dotron_palettes, (const void *)artwork_backdrop[5], 3 * *((_DWORD *)artwork_backdrop + 12));
if ( *((int *)v7 + 12) > 0 )
{
v8 = &unk_1220;
v9 = 0;
v10 = 0LL;
do
{
v11 = 2 * *(unsigned __int8 *)(v7[5] + v10);
if ( v11 > 255 )
LOBYTE(v11) = -1;
*v8 = v11;
v8[1] = *(_BYTE *)(v7[5] + v10 + 1);
v12 = 2 * *(unsigned __int8 *)(v7[5] + v10 + 2);
if ( v12 > 255 )
LOBYTE(v12) = -1;
v8[2] = v12;
v13 = 3 * *(unsigned __int8 *)(v7[5] + v10);
if ( v13 > 255 )
LOBYTE(v13) = -1;
v8[768] = v13;
v8[769] = *(_BYTE *)(v7[5] + v10 + 1);
v14 = 3 * *(unsigned __int8 *)(v7[5] + v10 + 2);
if ( v14 > 255 )
LOBYTE(v14) = -1;
++v9;
v10 += 3LL;
v8 += 3;
v8[767] = v14;
}
while ( *((_DWORD *)v7 + 12) > v9 );
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er15
unsigned int v2; // ebp
int **v3; // rdi
unsigned int v4; // ebx
int v5; // eax
__int64 v6; // rsi
_QWORD *v7; // rbx
_BYTE *v8; // rdx
int v9; // edi
__int64 v10; // rax
int v11; // ecx
int v12; // ecx
int v13; // ecx
int v14; // ecx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = 0;
backdrop_load("dotron.png", 64LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 64));
v3 = (int **)artwork_backdrop;
if ( artwork_backdrop )
{
do
{
if ( **v3 > 0 )
{
v4 = 0;
do
{
v5 = read_pixel(v3[3], v4, v2);
v6 = v4++;
plot_pixel(artwork_backdrop[3], v6, v2, (unsigned int)(v5 + 95));
v3 = (int **)artwork_backdrop;
}
while ( *(_DWORD *)*artwork_backdrop > (signed int)v4 );
}
++v2;
}
while ( v2 != 138 );
backdrop_refresh();
v7 = artwork_backdrop;
memcpy(&dotron_palettes, (const void *)artwork_backdrop[5], 3 * *((_DWORD *)artwork_backdrop + 12));
if ( *((int *)v7 + 12) > 0 )
{
v8 = &unk_1220;
v9 = 0;
v10 = 0LL;
do
{
v11 = 2 * *(unsigned __int8 *)(v7[5] + v10);
if ( v11 > 255 )
LOBYTE(v11) = -1;
*v8 = v11;
v8[1] = *(_BYTE *)(v7[5] + v10 + 1);
v12 = 2 * *(unsigned __int8 *)(v7[5] + v10 + 2);
if ( v12 > 255 )
LOBYTE(v12) = -1;
v8[2] = v12;
v13 = 3 * *(unsigned __int8 *)(v7[5] + v10);
if ( v13 > 255 )
LOBYTE(v13) = -1;
v8[768] = v13;
v8[769] = *(_BYTE *)(v7[5] + v10 + 1);
v14 = 3 * *(unsigned __int8 *)(v7[5] + v10 + 2);
if ( v14 > 255 )
LOBYTE(v14) = -1;
++v9;
v10 += 3LL;
v8 += 3;
v8[767] = v14;
}
while ( *((_DWORD *)v7 + 12) > v9 );
}
}
}
return v0;
}

original_code:
int dotron_vh_start(void)
{
 int i, x, y;
 if (generic_vh_start())
  return 1;
 backdrop_load("dotron.png", 64, Machine->drv->total_colors-64);
 if (artwork_backdrop)
 {
  for (y = 0; y < 138; y++)
   for (x = 0; x < artwork_backdrop->artwork->width; x++)
   {
    int newpixel = read_pixel(artwork_backdrop->orig_artwork, x, y) + 95;
    plot_pixel(artwork_backdrop->orig_artwork, x, y, newpixel);
   }
  backdrop_refresh(artwork_backdrop);
  memcpy(dotron_palettes[0], artwork_backdrop->orig_palette, 3 * artwork_backdrop->num_pens_used);
  for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  {
   dotron_palettes[1][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3] * 2):(255));
   dotron_palettes[1][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[1][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 2):(255));
   dotron_palettes[2][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3] * 3):(255));
   dotron_palettes[2][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[2][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 3):(255));
  }
 }
 return 0;
}

canonical_original_code:
int dotron_vh_start()
{
 int i; int x; int y;
 if (generic_vh_start())
  return 1;
 backdrop_load("dotron.png", 64, Machine->drv->total_colors-64);
 if (artwork_backdrop)
 {
  for (y = 0; y < 138; y++)
   for (x = 0; x < artwork_backdrop->artwork->width; x++)
   {
    int newpixel = read_pixel(artwork_backdrop->orig_artwork, x, y) + 95;
    plot_pixel(artwork_backdrop->orig_artwork, x, y, newpixel);
   }
  backdrop_refresh(artwork_backdrop);
  memcpy(dotron_palettes[0], artwork_backdrop->orig_palette, 3 * artwork_backdrop->num_pens_used);
  for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  {
   dotron_palettes[1][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3] * 2):(255));
   dotron_palettes[1][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[1][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 2):(255));
   dotron_palettes[2][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3] * 3):(255));
   dotron_palettes[2][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[2][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 3):(255));
  }
 }
 return 0;
}

variable_types: i int

variable_types: x int

variable_types: y int

variable_types: newpixel int


decompiled_code:
void __fastcall dotron_change_light(char a1)
{
light_status = a1;
}

canonical_decompiled_code:
void __fastcall func8(char a1)
{
light_status = a1;
}

original_code:
void dotron_change_light(int light)
{
 light_status = light;
}

variable_types: light int


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

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

original_code:
static data_t wardner_sprite_r(offs_t offset)
{
 return spriteram[offset];
}

canonical_original_code:
static unsigned int wardner_sprite_r(unsigned int offset)
{
 return spriteram[offset];
}


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

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

original_code:
static data_t wardner_sharedram_r(offs_t offset)
{
 return wardner_sharedram[offset];
}

canonical_original_code:
static unsigned int wardner_sharedram_r(unsigned int offset)
{
 return wardner_sharedram[offset];
}


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

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

original_code:
static data_t wardner_spare_pal_ram_r(offs_t offset)
{
 return wardner_spare_pal_ram[offset];
}

canonical_original_code:
static unsigned int wardner_spare_pal_ram_r(unsigned int offset)
{
 return wardner_spare_pal_ram[offset];
}


decompiled_code:
void __fastcall wardner_ramrom_banks_w(__int64 a1, int a2)
{
wardner_membank = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
wardner_membank = a2;
}

original_code:
static void wardner_ramrom_banks_w(offs_t offset,data_t data)
{
 wardner_membank = data;
}

canonical_original_code:
static void wardner_ramrom_banks_w(unsigned int offset, unsigned int data)
{
 wardner_membank = data;
}


decompiled_code:
__int64 init_wardner()
{
__int64 v0; // rdx
__int64 result; // rax
char v2; // cl

v0 = memory_region(131LL);
for ( result = 0LL; result != 1536; ++result )
{
v2 = *(_BYTE *)(v0 + result + 6144);
*(_BYTE *)(v0 + 2 * result) = *(_BYTE *)(v0 + result + 4096);
*(_BYTE *)(v0 + 2 * result + 1) = v2;
*(_BYTE *)(v0 + result + 4096) = 0;
*(_BYTE *)(v0 + result + 6144) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rdx
__int64 result; // rax
char v2; // cl

v0 = memory_region(131LL);
for ( result = 0LL; result != 1536; ++result )
{
v2 = *(_BYTE *)(v0 + result + 6144);
*(_BYTE *)(v0 + 2 * result) = *(_BYTE *)(v0 + result + 4096);
*(_BYTE *)(v0 + 2 * result + 1) = v2;
*(_BYTE *)(v0 + result + 4096) = 0;
*(_BYTE *)(v0 + result + 6144) = 0;
}
return result;
}

original_code:
static void init_wardner(void)
{
 int A;
 unsigned char datamsb;
 unsigned char datalsb;
 unsigned char *DSP_ROMS = memory_region(REGION_CPU3);
 for (A = 0;A < 0x0600;A++)
 {
  datamsb = DSP_ROMS[0x1000 + A];
  datalsb = DSP_ROMS[0x1800 + A];
  DSP_ROMS[(A*2)] = datamsb;
  DSP_ROMS[(A*2)+1] = datalsb;
  DSP_ROMS[0x1000 + A] = 00;
  DSP_ROMS[0x1800 + A] = 00;
 }
}

canonical_original_code:
static void init_wardner()
{
 int A;
 unsigned char datamsb;
 unsigned char datalsb;
 unsigned char *DSP_ROMS = memory_region(REGION_CPU3);
 for (A = 0;A < 0x0600;A++)
 {
  datamsb = DSP_ROMS[0x1000 + A];
  datalsb = DSP_ROMS[0x1800 + A];
  DSP_ROMS[(A*2)] = datamsb;
  DSP_ROMS[(A*2)+1] = datalsb;
  DSP_ROMS[0x1000 + A] = 00;
  DSP_ROMS[0x1800 + A] = 00;
 }
}

variable_types: A int

variable_types:
datamsb
unsigned char

variable_types:
datalsb
unsigned char


decompiled_code:
__int64 wardner_interrupt()
{
if ( !twincobr_intenable )
return ignore_interrupt();
twincobr_intenable = 0;
return interrupt();
}

canonical_decompiled_code:
__int64 func9()
{
if ( !twincobr_intenable )
return ignore_interrupt();
twincobr_intenable = 0;
return interrupt();
}

original_code:
static int wardner_interrupt(void)
{
 if (twincobr_intenable) {
  twincobr_intenable = 0;
  return interrupt();
 }
 else return ignore_interrupt();
}

canonical_original_code:
static int wardner_interrupt()
{
 if (twincobr_intenable) {
  twincobr_intenable = 0;
  return interrupt();
 }
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall wardner_ram_rom_r(int a1)
{
__int16 v1; // bx
unsigned int v2; // edi
int v3; // eax
__int64 result; // rax

v1 = a1;
if ( wardner_membank )
return *(unsigned __int8 *)(memory_region(129LL) + (unsigned int)(a1 + ((wardner_membank + 1) << 15)));
v2 = a1 & 0xFFF;
v3 = (v1 + 0x8000) & 0xE000;
switch ( v3 )
{
case 40960:
if ( v2 <= 0xDFF )
result = paletteram_r();
else
result = wardner_spare_pal_ram_r(v1 & 0x1FF);
break;
case 49152:
if ( (v1 & 0x800) != 0 )
return 0LL;
result = wardner_sharedram_r(v1 & 0x7FF);
break;
case 32768:
result = wardner_sprite_r(v2);
break;
default:
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int16 v1; // bx
unsigned int v2; // edi
int v3; // eax
__int64 result; // rax

v1 = a1;
if ( wardner_membank )
return *(unsigned __int8 *)(memory_region(129LL) + (unsigned int)(a1 + ((wardner_membank + 1) << 15)));
v2 = a1 & 0xFFF;
v3 = (v1 + 0x8000) & 0xE000;
switch ( v3 )
{
case 40960:
if ( v2 <= 0xDFF )
result = paletteram_r();
else
result = func4(v1 & 0x1FF);
break;
case 49152:
if ( (v1 & 0x800) != 0 )
return 0LL;
result = func2(v1 & 0x7FF);
break;
case 32768:
result = func0(v2);
break;
default:
return 0LL;
}
return result;
}

original_code:
static data_t wardner_ram_rom_r(offs_t offset)
{
 int wardner_data = 0;
 if (wardner_membank == 0)
 {
  int wardner_bank = offset + 0x8000;
  offset &= 0xfff;
  switch (wardner_bank & 0xe000)
  {
   case 0x8000: wardner_data = wardner_sprite_r(offset); break;
   case 0xa000: if (offset < 0xe00) { wardner_data = paletteram_r(offset); }
       else { wardner_data = wardner_spare_pal_ram_r(offset & 0x1ff); } break;
   case 0xc000: if (offset < 0x800) wardner_data = wardner_sharedram_r(offset & 0x7ff); break;
   default: break;
  }
 }
 else
 {
  unsigned char *wardner_rom = memory_region(REGION_CPU1);
  int wardner_rombank = 0x8000 * (wardner_membank + 1);
  wardner_data = wardner_rom[wardner_rombank + offset];
 }
 return wardner_data;
}

canonical_original_code:
static unsigned int wardner_ram_rom_r(unsigned int offset)
{
 int wardner_data = 0;
 if (wardner_membank == 0)
 {
  int wardner_bank = offset + 0x8000;
  offset &= 0xfff;
  switch (wardner_bank & 0xe000)
  {
   case 0x8000: wardner_data = wardner_sprite_r(offset); break;
   case 0xa000: if (offset < 0xe00) { wardner_data = paletteram_r(offset); }
       else { wardner_data = wardner_spare_pal_ram_r(offset & 0x1ff); } break;
   case 0xc000: if (offset < 0x800) wardner_data = wardner_sharedram_r(offset & 0x7ff); break;
   default: break;
  }
 }
 else
 {
  unsigned char *wardner_rom = memory_region(REGION_CPU1);
  int wardner_rombank = 0x8000 * (wardner_membank + 1);
  wardner_data = wardner_rom[wardner_rombank + offset];
 }
 return wardner_data;
}

variable_types:
offset
unsigned int


irqhandler

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

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

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

variable_types: linestate int


decompiled_code:
__int64 __fastcall pulsar_sh_port1_w(__int64 a1, int a2)
{
char v2; // bl
char v3; // bl
__int64 result; // rax

v2 = port1State;
port1State = a2;
v3 = a2 ^ (a2 | v2);
if ( (v3 & 1) != 0 )
{
result = sample_start(0LL, 0LL, 0LL);
if ( (v3 & 2) == 0 )
{
LABEL_3:
if ( (v3 & 4) == 0 )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( (v3 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(1LL, 1LL, 0LL);
if ( (v3 & 4) == 0 )
{
LABEL_4:
if ( (v3 & 8) == 0 )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
result = sample_start(2LL, 2LL, 0LL);
if ( (v3 & 8) == 0 )
{
LABEL_5:
if ( (v3 & 0x10) == 0 )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
result = sample_start(3LL, 3LL, 0LL);
if ( (v3 & 0x10) == 0 )
{
LABEL_6:
if ( (v3 & 0x20) == 0 )
goto LABEL_7;
goto LABEL_14;
}
LABEL_13:
result = sample_start(4LL, 4LL, 0LL);
if ( (v3 & 0x20) == 0 )
{
LABEL_7:
if ( (v3 & 0x40) == 0 )
return result;
return sample_start(6LL, 6LL, 0LL);
}
LABEL_14:
result = sample_start(5LL, 5LL, 0LL);
if ( (v3 & 0x40) != 0 )
return sample_start(6LL, 6LL, 0LL);
return result;
}

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

v2 = port1State;
port1State = a2;
v3 = a2 ^ (a2 | v2);
if ( (v3 & 1) != 0 )
{
result = sample_start(0LL, 0LL, 0LL);
if ( (v3 & 2) == 0 )
{
LABEL_3:
if ( (v3 & 4) == 0 )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( (v3 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(1LL, 1LL, 0LL);
if ( (v3 & 4) == 0 )
{
LABEL_4:
if ( (v3 & 8) == 0 )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
result = sample_start(2LL, 2LL, 0LL);
if ( (v3 & 8) == 0 )
{
LABEL_5:
if ( (v3 & 0x10) == 0 )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
result = sample_start(3LL, 3LL, 0LL);
if ( (v3 & 0x10) == 0 )
{
LABEL_6:
if ( (v3 & 0x20) == 0 )
goto LABEL_7;
goto LABEL_14;
}
LABEL_13:
result = sample_start(4LL, 4LL, 0LL);
if ( (v3 & 0x20) == 0 )
{
LABEL_7:
if ( (v3 & 0x40) == 0 )
return result;
return sample_start(6LL, 6LL, 0LL);
}
LABEL_14:
result = sample_start(5LL, 5LL, 0LL);
if ( (v3 & 0x40) != 0 )
return sample_start(6LL, 6LL, 0LL);
return result;
}

original_code:
void pulsar_sh_port1_w(offs_t offset,data_t data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_KEY, SND_KEY, 0 );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_ALIENHIT, SND_ALIENHIT, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_PHIT, SND_PHIT, 0 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_ASHOOT, SND_ASHOOT, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PSHOOT, SND_PSHOOT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS, SND_BONUS, 0 );
 }
}

canonical_original_code:
void pulsar_sh_port1_w(unsigned int offset, unsigned int data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_KEY, SND_KEY, 0 );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_ALIENHIT, SND_ALIENHIT, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_PHIT, SND_PHIT, 0 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_ASHOOT, SND_ASHOOT, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PSHOOT, SND_PSHOOT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS, SND_BONUS, 0 );
 }
}

variable_types:
data
unsigned int

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int