decompiled_code:
__int64 shangha3_blitter_go_w()
{
unsigned __int64 i; // r15
unsigned __int16 v2; // si
unsigned int v3; // er8
int v4; // eax
int v5; // ecx
unsigned int v6; // er8
int v7; // er15
int v8; // edx
int v9; // eax
int v10; // ecx
unsigned int v11; // esi
__int64 v12; // rax
unsigned int v13; // esi
__int64 v14; // rcx
int v15; // ebp
int v16; // ebx
unsigned int v17; // ebx
__int64 v18; // rbp
int v19; // er14
__int64 v20; // r13
__int64 v21; // r15
int v22; // edx
int v23; // eax
__int16 *v24; // rsi
unsigned int v25; // er13
__int64 v26; // r14
__int64 v27; // r12
unsigned __int16 v28; // r8
int v29; // edx
unsigned __int16 v30; // cx
int v31; // edi
unsigned __int16 v32; // r9
unsigned __int16 v33; // r10
__int16 v34; // bp
__int16 v35; // cx
int v36; // [rsp+4h] [rbp-A4h]
unsigned __int16 v37; // [rsp+4h] [rbp-A4h]
int v38; // [rsp+8h] [rbp-A0h]
int v39; // [rsp+8h] [rbp-A0h]
int v40; // [rsp+Ch] [rbp-9Ch]
unsigned int v41; // [rsp+Ch] [rbp-9Ch]
int v42; // [rsp+10h] [rbp-98h]
unsigned __int64 v43; // [rsp+10h] [rbp-98h]
int v44; // [rsp+18h] [rbp-90h]
int v45; // [rsp+1Ch] [rbp-8Ch]
unsigned int v46; // [rsp+28h] [rbp-80h]
unsigned int v47; // [rsp+3Ch] [rbp-6Ch]
int v48; // [rsp+40h] [rbp-68h]
int v49; // [rsp+44h] [rbp-64h]
unsigned __int16 v50; // [rsp+4Ah] [rbp-5Eh]
int v51; // [rsp+4Ch] [rbp-5Ch]
unsigned int v52; // [rsp+50h] [rbp-58h]
int v53; // [rsp+54h] [rbp-54h]
unsigned __int64 v54; // [rsp+58h] [rbp-50h]
int v55[18]; // [rsp+60h] [rbp-48h] BYREF

profiler_mark(8LL);
for ( i = gfxlist_addr; shangha3_ram_size > i; i += 32LL )
{
v24 = (__int16 *)(shangha3_ram + i + 8);
v46 = *v24 & 1;
v25 = *v24 & 2;
v26 = *(_WORD *)(shangha3_ram + i + 4) >> 4;
if ( (unsigned __int16)(*(_WORD *)(shangha3_ram + i + 4) >> 4) > 0x800u )
v26 = (unsigned int)(v26 - 4096);
v27 = *(_WORD *)(shangha3_ram + i + 6) >> 4;
if ( (unsigned __int16)(*(_WORD *)(shangha3_ram + i + 6) >> 4) > 0x800u )
v27 = (unsigned int)(v27 - 4096);
v28 = *(_WORD *)(shangha3_ram + i + 12);
v29 = v28;
v30 = *(_WORD *)(shangha3_ram + i + 14);
v31 = v30;
if ( flip_screen_x )
{
v26 = 383 - (_DWORD)v26 - (unsigned int)v28;
v27 = 255 - (_DWORD)v27 - (unsigned int)v30;
v46 = !(*v24 & 1);
v25 = v25 == 0;
}
if ( v30 | v28 )
{
if ( v28 <= 0x1FFu && v30 <= 0xFFu )
{
v32 = *(_WORD *)(shangha3_ram + i + 20);
v33 = *(_WORD *)(shangha3_ram + i + 26);
if ( v32 <= 0x1EFu && v33 <= 0x1EFu )
{
LOWORD(v17) = *(_WORD *)(shangha3_ram + i + 2);
v34 = *(_WORD *)(shangha3_ram + i + 10);
v55[0] = v26;
v36 = v26 + v28;
v55[1] = v36;
v55[2] = v27;
v39 = v27 + v30;
v55[3] = v39;
v35 = *v24;
if ( (*v24 & 8) != 0 )
{
v2 = *(_WORD *)(shangha3_ram + i + 16) >> 4;
v3 = *(_WORD *)(shangha3_ram + i + 18) >> 4;
v40 = v2 & 0xF;
v50 = (*(_WORD *)(shangha3_ram + i + 18) >> 4) & 0xF;
v4 = ((v31 + 15) >> 4) + 1;
v49 = ((v29 + 15) >> 4) + 1;
v5 = v35 & 4;
if ( v5 )
{
v4 *= 2;
v49 = 2 * (((v29 + 15) >> 4) + 1);
v53 = v2 >> 3;
v6 = v3 >> 3;
}
else
{
v53 = v2 >> 4;
v6 = v3 >> 4;
}
v47 = v6;
v51 = 512 - v33;
v52 = v6 + v4;
v48 = 0;
v42 = 512 - v32;
v44 = v34 & 0x70;
v45 = v17 & 0xF000;
v54 = i;
v7 = v5;
do
{
v15 = v53;
v16 = 0;
do
{
if ( v7 )
{
v8 = *(unsigned __int16 *)(shangha3_ram + (int)(2 * ((v47 & 0x1F) + 32 * (unsigned __int8)v15)));
v9 = v16 / 32 - v40;
v10 = v48 / 32 - v50;
}
else
{
v8 = *(unsigned __int16 *)(shangha3_ram
+ (int)(2 * (((v47 & 0x10) << 8) + (v47 & 0xF) + 16 * (unsigned __int8)v15)));
v9 = v16 / 16 - v40;
v10 = v48 / 16 - v50;
}
v11 = v36 - 15 - v9;
v12 = (unsigned int)(v26 + v9);
if ( v46 )
v12 = v11;
v13 = v39 - 15 - v10;
v14 = (unsigned int)(v27 + v10);
if ( v25 )
v14 = v13;
drawgfx(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v45 | v8 & 0xFFFu,
v44 | (unsigned int)(v8 >> 12),
v46,
v25,
v12,
v14,
v55,
2LL,
15LL);
++v15;
v16 += v42;
}
while ( v15 != v53 + v49 );
++v47;
v48 += v51;
}
while ( v47 != v52 );
i = v54;
}
else
{
v37 = v34 & 0x7F;
if ( v32 > 1u || v33 > 1u )
{
v38 = (v28 + 15) >> 4;
if ( v28 )
{
v17 = (unsigned __int16)v17;
v18 = (unsigned int)v26;
v19 = 0;
v41 = v25;
v20 = (512 - (unsigned int)v33) << 8;
v43 = i;
v21 = (512 - (unsigned int)v32) << 8;
do
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v17,
v37,
v46,
v41,
v18,
v27,
v55,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
v21,
v20);
v22 = v17 & 0xF;
v23 = ((_WORD)v17++ + 256) & 0xFFF0;
if ( v22 == 15 )
v17 = v23;
++v19;
v18 = (unsigned int)(v18 + 16);
}
while ( v38 > v19 );
i = v43;
}
}
else
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned __int16)v17,
v34 & 0x7F,
v46,
v25,
v26,
v27,
v55,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
0x1000000LL,
0x1000000LL);
}
}
}
}
}
}
return profiler_mark(0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int64 i; // r15
unsigned __int16 v2; // si
unsigned int v3; // er8
int v4; // eax
int v5; // ecx
unsigned int v6; // er8
int v7; // er15
int v8; // edx
int v9; // eax
int v10; // ecx
unsigned int v11; // esi
__int64 v12; // rax
unsigned int v13; // esi
__int64 v14; // rcx
int v15; // ebp
int v16; // ebx
unsigned int v17; // ebx
__int64 v18; // rbp
int v19; // er14
__int64 v20; // r13
__int64 v21; // r15
int v22; // edx
int v23; // eax
__int16 *v24; // rsi
unsigned int v25; // er13
__int64 v26; // r14
__int64 v27; // r12
unsigned __int16 v28; // r8
int v29; // edx
unsigned __int16 v30; // cx
int v31; // edi
unsigned __int16 v32; // r9
unsigned __int16 v33; // r10
__int16 v34; // bp
__int16 v35; // cx
int v36; // [rsp+4h] [rbp-A4h]
unsigned __int16 v37; // [rsp+4h] [rbp-A4h]
int v38; // [rsp+8h] [rbp-A0h]
int v39; // [rsp+8h] [rbp-A0h]
int v40; // [rsp+Ch] [rbp-9Ch]
unsigned int v41; // [rsp+Ch] [rbp-9Ch]
int v42; // [rsp+10h] [rbp-98h]
unsigned __int64 v43; // [rsp+10h] [rbp-98h]
int v44; // [rsp+18h] [rbp-90h]
int v45; // [rsp+1Ch] [rbp-8Ch]
unsigned int v46; // [rsp+28h] [rbp-80h]
unsigned int v47; // [rsp+3Ch] [rbp-6Ch]
int v48; // [rsp+40h] [rbp-68h]
int v49; // [rsp+44h] [rbp-64h]
unsigned __int16 v50; // [rsp+4Ah] [rbp-5Eh]
int v51; // [rsp+4Ch] [rbp-5Ch]
unsigned int v52; // [rsp+50h] [rbp-58h]
int v53; // [rsp+54h] [rbp-54h]
unsigned __int64 v54; // [rsp+58h] [rbp-50h]
int v55[18]; // [rsp+60h] [rbp-48h] BYREF

profiler_mark(8LL);
for ( i = gfxlist_addr; shangha3_ram_size > i; i += 32LL )
{
v24 = (__int16 *)(shangha3_ram + i + 8);
v46 = *v24 & 1;
v25 = *v24 & 2;
v26 = *(_WORD *)(shangha3_ram + i + 4) >> 4;
if ( (unsigned __int16)(*(_WORD *)(shangha3_ram + i + 4) >> 4) > 0x800u )
v26 = (unsigned int)(v26 - 4096);
v27 = *(_WORD *)(shangha3_ram + i + 6) >> 4;
if ( (unsigned __int16)(*(_WORD *)(shangha3_ram + i + 6) >> 4) > 0x800u )
v27 = (unsigned int)(v27 - 4096);
v28 = *(_WORD *)(shangha3_ram + i + 12);
v29 = v28;
v30 = *(_WORD *)(shangha3_ram + i + 14);
v31 = v30;
if ( flip_screen_x )
{
v26 = 383 - (_DWORD)v26 - (unsigned int)v28;
v27 = 255 - (_DWORD)v27 - (unsigned int)v30;
v46 = !(*v24 & 1);
v25 = v25 == 0;
}
if ( v30 | v28 )
{
if ( v28 <= 0x1FFu && v30 <= 0xFFu )
{
v32 = *(_WORD *)(shangha3_ram + i + 20);
v33 = *(_WORD *)(shangha3_ram + i + 26);
if ( v32 <= 0x1EFu && v33 <= 0x1EFu )
{
LOWORD(v17) = *(_WORD *)(shangha3_ram + i + 2);
v34 = *(_WORD *)(shangha3_ram + i + 10);
v55[0] = v26;
v36 = v26 + v28;
v55[1] = v36;
v55[2] = v27;
v39 = v27 + v30;
v55[3] = v39;
v35 = *v24;
if ( (*v24 & 8) != 0 )
{
v2 = *(_WORD *)(shangha3_ram + i + 16) >> 4;
v3 = *(_WORD *)(shangha3_ram + i + 18) >> 4;
v40 = v2 & 0xF;
v50 = (*(_WORD *)(shangha3_ram + i + 18) >> 4) & 0xF;
v4 = ((v31 + 15) >> 4) + 1;
v49 = ((v29 + 15) >> 4) + 1;
v5 = v35 & 4;
if ( v5 )
{
v4 *= 2;
v49 = 2 * (((v29 + 15) >> 4) + 1);
v53 = v2 >> 3;
v6 = v3 >> 3;
}
else
{
v53 = v2 >> 4;
v6 = v3 >> 4;
}
v47 = v6;
v51 = 512 - v33;
v52 = v6 + v4;
v48 = 0;
v42 = 512 - v32;
v44 = v34 & 0x70;
v45 = v17 & 0xF000;
v54 = i;
v7 = v5;
do
{
v15 = v53;
v16 = 0;
do
{
if ( v7 )
{
v8 = *(unsigned __int16 *)(shangha3_ram + (int)(2 * ((v47 & 0x1F) + 32 * (unsigned __int8)v15)));
v9 = v16 / 32 - v40;
v10 = v48 / 32 - v50;
}
else
{
v8 = *(unsigned __int16 *)(shangha3_ram
+ (int)(2 * (((v47 & 0x10) << 8) + (v47 & 0xF) + 16 * (unsigned __int8)v15)));
v9 = v16 / 16 - v40;
v10 = v48 / 16 - v50;
}
v11 = v36 - 15 - v9;
v12 = (unsigned int)(v26 + v9);
if ( v46 )
v12 = v11;
v13 = v39 - 15 - v10;
v14 = (unsigned int)(v27 + v10);
if ( v25 )
v14 = v13;
drawgfx(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v45 | v8 & 0xFFFu,
v44 | (unsigned int)(v8 >> 12),
v46,
v25,
v12,
v14,
v55,
2LL,
15LL);
++v15;
v16 += v42;
}
while ( v15 != v53 + v49 );
++v47;
v48 += v51;
}
while ( v47 != v52 );
i = v54;
}
else
{
v37 = v34 & 0x7F;
if ( v32 > 1u || v33 > 1u )
{
v38 = (v28 + 15) >> 4;
if ( v28 )
{
v17 = (unsigned __int16)v17;
v18 = (unsigned int)v26;
v19 = 0;
v41 = v25;
v20 = (512 - (unsigned int)v33) << 8;
v43 = i;
v21 = (512 - (unsigned int)v32) << 8;
do
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
v17,
v37,
v46,
v41,
v18,
v27,
v55,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
v21,
v20);
v22 = v17 & 0xF;
v23 = ((_WORD)v17++ + 256) & 0xFFF0;
if ( v22 == 15 )
v17 = v23;
++v19;
v18 = (unsigned int)(v18 + 16);
}
while ( v38 > v19 );
i = v43;
}
}
else
{
drawgfxzoom(
rawbitmap,
*(_QWORD *)(Machine + 512LL),
(unsigned __int16)v17,
v34 & 0x7F,
v46,
v25,
v26,
v27,
v55,
shangha3_do_shadows[0] == 0 ? 2 : 9,
15LL,
0x1000000LL,
0x1000000LL);
}
}
}
}
}
}
return profiler_mark(0xFFFFFFFFLL);
}

original_code:
void shangha3_blitter_go_w(offs_t offset,data_t data)
{
 int offs;
 profiler_mark(PROFILER_VIDEO);
 for (offs = gfxlist_addr;offs < shangha3_ram_size;offs += 32)
 {
  int sx,sy,x,y,code,color,flipx,flipy,sizex,sizey,zoomx,zoomy;
  code = (*(UINT16 *)(&shangha3_ram[offs+2]));
  color = (*(UINT16 *)(&shangha3_ram[offs+10])) & 0x7f;
  flipx = (*(UINT16 *)(&shangha3_ram[offs+8])) & 0x01;
  flipy = (*(UINT16 *)(&shangha3_ram[offs+8])) & 0x02;
  sx = (*(UINT16 *)(&shangha3_ram[offs+4])) / 16;
  if (sx > 0x800) sx -= 0x1000;
  sy = (*(UINT16 *)(&shangha3_ram[offs+6])) / 16;
  if (sy > 0x800) sy -= 0x1000;
  sizex = (*(UINT16 *)(&shangha3_ram[offs+12]));
  sizey = (*(UINT16 *)(&shangha3_ram[offs+14]));
  zoomx = (*(UINT16 *)(&shangha3_ram[offs+20]));
  zoomy = (*(UINT16 *)(&shangha3_ram[offs+26]));
  if (flip_screen_x)
  {
   sx = 383 - sx - sizex;
   sy = 255 - sy - sizey;
   flipx = !flipx;
   flipy = !flipy;
  }
  if ((sizex || sizey)
&& sizex < 512 && sizey < 256 && zoomx < 0x1f0 && zoomy < 0x1f0)
  {
   struct rectangle myclip;
   myclip.min_x = sx;
   myclip.max_x = sx + sizex;
   myclip.min_y = sy;
   myclip.max_y = sy + sizey;
   if ((*(UINT16 *)(&shangha3_ram[offs+8])) & 0x08)
   {
    int srcx,srcy,dispx,dispy,w,h,condensed;
    condensed = (*(UINT16 *)(&shangha3_ram[offs+8])) & 0x04;
    srcx = (*(UINT16 *)(&shangha3_ram[offs+16]))/16;
    srcy = (*(UINT16 *)(&shangha3_ram[offs+18]))/16;
    dispx = srcx & 0x0f;
    dispy = srcy & 0x0f;
    h = (sizey+15)/16+1;
    w = (sizex+15)/16+1;
    if (condensed)
    {
     h *= 2;
     w *= 2;
     srcx /= 8;
     srcy /= 8;
    }
    else
    {
     srcx /= 16;
     srcy /= 16;
    }
    for (y = 0;y < h;y++)
    {
     for (x = 0;x < w;x++)
     {
      int dx,dy,tile;
      if (condensed)
      {
       int addr = ((y+srcy) & 0x1f) +
          0x20 * ((x+srcx) & 0xff);
       tile = (*(UINT16 *)(&shangha3_ram[2*addr]));
       dx = 8*x*(0x200-zoomx)/0x100 - dispx;
       dy = 8*y*(0x200-zoomy)/0x100 - dispy;
      }
      else
      {
       int addr = ((y+srcy) & 0x0f) +
          0x10 * ((x+srcx) & 0xff) +
          0x100 * ((y+srcy) & 0x10);
       tile = (*(UINT16 *)(&shangha3_ram[2*addr]));
       dx = 16*x*(0x200-zoomx)/0x100 - dispx;
       dy = 16*y*(0x200-zoomy)/0x100 - dispy;
      }
      if (flipx) dx = sx + sizex-15 - dx;
      else dx = sx + dx;
      if (flipy) dy = sy + sizey-15 - dy;
      else dy = sy + dy;
      drawgfx(rawbitmap,Machine->gfx[0],
        (tile & 0x0fff) | (code & 0xf000),
        (tile >> 12) | (color & 0x70),
        flipx,flipy,
        dx,dy,
        &myclip,TRANSPARENCY_PEN,15);
     }
    }
   }
   else
   {
    int w;
if (zoomx <= 1 && zoomy <= 1)
 drawgfxzoom(rawbitmap,Machine->gfx[0],
   code,
   color,
   flipx,flipy,
   sx,sy,
   &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
   0x1000000,0x1000000);
else
{
    w = (sizex+15)/16;
    for (x = 0;x < w;x++)
    {
     drawgfxzoom(rawbitmap,Machine->gfx[0],
       code,
       color,
       flipx,flipy,
       sx + 16*x,sy,
       &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
       (0x200-zoomx)*0x100,(0x200-zoomy)*0x100);
     if ((code & 0x000f) == 0x0f)
      code = (code + 0x100) & 0xfff0;
     else
      code++;
    }
}
   }
  }
 }
 profiler_mark(PROFILER_END);
}

canonical_original_code:
void shangha3_blitter_go_w(unsigned int offset, unsigned int data)
{
 int offs;
 profiler_mark(PROFILER_VIDEO);
 for (offs = gfxlist_addr;offs < shangha3_ram_size;offs += 32)
 {
  int sx; int sy; int x; int y; int code; int color; int flipx; int flipy; int sizex; int sizey; int zoomx; int zoomy;
  code = (*(unsigned short *)(&shangha3_ram[offs+2]));
  color = (*(unsigned short *)(&shangha3_ram[offs+10])) & 0x7f;
  flipx = (*(unsigned short *)(&shangha3_ram[offs+8])) & 0x01;
  flipy = (*(unsigned short *)(&shangha3_ram[offs+8])) & 0x02;
  sx = (*(unsigned short *)(&shangha3_ram[offs+4])) / 16;
  if (sx > 0x800) sx -= 0x1000;
  sy = (*(unsigned short *)(&shangha3_ram[offs+6])) / 16;
  if (sy > 0x800) sy -= 0x1000;
  sizex = (*(unsigned short *)(&shangha3_ram[offs+12]));
  sizey = (*(unsigned short *)(&shangha3_ram[offs+14]));
  zoomx = (*(unsigned short *)(&shangha3_ram[offs+20]));
  zoomy = (*(unsigned short *)(&shangha3_ram[offs+26]));
  if (flip_screen_x)
  {
   sx = 383 - sx - sizex;
   sy = 255 - sy - sizey;
   flipx = !flipx;
   flipy = !flipy;
  }
  if ((sizex || sizey)
&& sizex < 512 && sizey < 256 && zoomx < 0x1f0 && zoomy < 0x1f0)
  {
   struct rectangle myclip;
   myclip.min_x = sx;
   myclip.max_x = sx + sizex;
   myclip.min_y = sy;
   myclip.max_y = sy + sizey;
   if ((*(unsigned short *)(&shangha3_ram[offs+8])) & 0x08)
   {
    int srcx; int srcy; int dispx; int dispy; int w; int h; int condensed;
    condensed = (*(unsigned short *)(&shangha3_ram[offs+8])) & 0x04;
    srcx = (*(unsigned short *)(&shangha3_ram[offs+16]))/16;
    srcy = (*(unsigned short *)(&shangha3_ram[offs+18]))/16;
    dispx = srcx & 0x0f;
    dispy = srcy & 0x0f;
    h = (sizey+15)/16+1;
    w = (sizex+15)/16+1;
    if (condensed)
    {
     h *= 2;
     w *= 2;
     srcx /= 8;
     srcy /= 8;
    }
    else
    {
     srcx /= 16;
     srcy /= 16;
    }
    for (y = 0;y < h;y++)
    {
     for (x = 0;x < w;x++)
     {
      int dx; int dy; int tile;
      if (condensed)
      {
       int addr = ((y+srcy) & 0x1f) +
          0x20 * ((x+srcx) & 0xff);
       tile = (*(unsigned short *)(&shangha3_ram[2*addr]));
       dx = 8*x*(0x200-zoomx)/0x100 - dispx;
       dy = 8*y*(0x200-zoomy)/0x100 - dispy;
      }
      else
      {
       int addr = ((y+srcy) & 0x0f) +
          0x10 * ((x+srcx) & 0xff) +
          0x100 * ((y+srcy) & 0x10);
       tile = (*(unsigned short *)(&shangha3_ram[2*addr]));
       dx = 16*x*(0x200-zoomx)/0x100 - dispx;
       dy = 16*y*(0x200-zoomy)/0x100 - dispy;
      }
      if (flipx) dx = sx + sizex-15 - dx;
      else dx = sx + dx;
      if (flipy) dy = sy + sizey-15 - dy;
      else dy = sy + dy;
      drawgfx(rawbitmap,Machine->gfx[0],
        (tile & 0x0fff) | (code & 0xf000),
        (tile >> 12) | (color & 0x70),
        flipx,flipy,
        dx,dy,
        &myclip,TRANSPARENCY_PEN,15);
     }
    }
   }
   else
   {
    int w;
if (zoomx <= 1 && zoomy <= 1)
 drawgfxzoom(rawbitmap,Machine->gfx[0],
   code,
   color,
   flipx,flipy,
   sx,sy,
   &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
   0x1000000,0x1000000);
else
{
    w = (sizex+15)/16;
    for (x = 0;x < w;x++)
    {
     drawgfxzoom(rawbitmap,Machine->gfx[0],
       code,
       color,
       flipx,flipy,
       sx + 16*x,sy,
       &myclip,shangha3_do_shadows ? TRANSPARENCY_PEN_TABLE : TRANSPARENCY_PEN,15,
       (0x200-zoomx)*0x100,(0x200-zoomy)*0x100);
     if ((code & 0x000f) == 0x0f)
      code = (code + 0x100) & 0xfff0;
     else
      code++;
    }
}
   }
  }
 }
 profiler_mark(PROFILER_END);
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: x int

variable_types: y int

variable_types: code int

variable_types: color int

variable_types: sizex int

variable_types: sizey int

variable_types: zoomx int

variable_types: zoomy int

variable_types: struct rectangle { int min_x; int min_y; }

variable_types: srcx int

variable_types: srcy int

variable_types: dispx int

variable_types: dispy int

variable_types: w int

variable_types: h int

variable_types: condensed int

variable_types: dx int

variable_types: dy int

variable_types: tile int

variable_types: addr int


decompiled_code:
__int64 __fastcall shangha3_vh_screenrefresh(__int64 a1)
{
palette_recalc();
return copybitmap(a1, rawbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
palette_recalc();
return copybitmap(a1, rawbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void shangha3_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 palette_recalc();
 copybitmap(bitmap,rawbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void shangha3_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 palette_recalc();
 copybitmap(bitmap,rawbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

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

return_type: void


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

if ( (a2 & 0xFF000000) == 0 )
{
coin_lockout_w(0LL, ~(_WORD)a2 & 0x400);
coin_lockout_w(1LL, ~(_WORD)a2 & 0x400);
coin_counter_w(0LL, a2 & 0x100);
result = coin_counter_w(1LL, a2 & 0x200);
}
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
{
coin_lockout_w(0LL, ~(_WORD)a2 & 0x400);
coin_lockout_w(1LL, ~(_WORD)a2 & 0x400);
coin_counter_w(0LL, a2 & 0x100);
result = coin_counter_w(1LL, a2 & 0x200);
}
return result;
}

original_code:
static void shangha3_coinctrl_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
 {
  coin_lockout_w(0,~data & 0x0400);
  coin_lockout_w(1,~data & 0x0400);
  coin_counter_w(0,data & 0x0100);
  coin_counter_w(1,data & 0x0200);
 }
}

canonical_original_code:
static void shangha3_coinctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
 {
  coin_lockout_w(0,~data & 0x0400);
  coin_lockout_w(1,~data & 0x0400);
  coin_counter_w(0,data & 0x0100);
  coin_counter_w(1,data & 0x0200);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 heberpop_sound_command_w()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func12()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 255LL);
}

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

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


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

if ( (a2 & 0xFF0000) == 0 )
{
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (a2 << 15) & 0x40000);
coin_lockout_w(0LL, ~(_BYTE)a2 & 4);
coin_lockout_w(1LL, ~(_BYTE)a2 & 4);
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (a2 << 15) & 0x40000);
coin_lockout_w(0LL, ~(_BYTE)a2 & 4);
coin_lockout_w(1LL, ~(_BYTE)a2 & 4);
coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
}
return result;
}

original_code:
static void heberpop_coinctrl_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  OKIM6295_set_bank_base(0,-1,(data & 0x08) ? 0x40000 : 0x00000);
  coin_lockout_w(0,~data & 0x04);
  coin_lockout_w(1,~data & 0x04);
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
 }
}

canonical_original_code:
static void heberpop_coinctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  OKIM6295_set_bank_base(0,-1,(data & 0x08) ? 0x40000 : 0x00000);
  coin_lockout_w(0,~data & 0x04);
  coin_lockout_w(1,~data & 0x04);
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
 }
}


decompiled_code:
__int64 __fastcall heberpop_gfxrom_r(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(137LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(137LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

original_code:
static data_t heberpop_gfxrom_r(offs_t offset)
{
 UINT8 *ROM = memory_region(REGION_GFX1);
 return ROM[offset] | (ROM[offset+1] << 8);
}

canonical_original_code:
static unsigned int heberpop_gfxrom_r(unsigned int offset)
{
 unsigned char *ROM = memory_region(REGION_GFX1);
 return ROM[offset] | (ROM[offset+1] << 8);
}

variable_types:
ROM
unsigned char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall shangha3_paletteram_w(unsigned int a1, unsigned int a2)
{
unsigned int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx

*(_WORD *)(paletteram + a1) = a2 | *(_WORD *)(paletteram + a1) & HIWORD(a2);
v2 = (8 * ((unsigned __int16)a2 >> 11)) | ((unsigned __int16)a2 >> 11 >> 2);
v3 = (8 * ((a2 >> 6) & 0x1F)) | ((int)((a2 >> 6) & 0x1F) >> 2);
v4 = ((int)((a2 >> 1) & 0x1F) >> 2) | (8 * ((a2 >> 1) & 0x1F));
if ( a1 > 0xFF )
{
v2 ^= 4u;
v3 = (unsigned int)v3 ^ 4;
v4 = (unsigned int)v4 ^ 4;
}
return palette_change_color(a1 >> 1, v2, v3, v4);
}

original_code:
void shangha3_paletteram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int r,g,b;
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = (data >> 11) & 0x1f;
 g = (data >> 6) & 0x1f;
 b = (data >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 if (offset/2 >= 128)
 {
  r ^= 0x04;
  g ^= 0x04;
  b ^= 0x04;
 }
 palette_change_color(offset/2,r,g,b);
}

canonical_original_code:
void shangha3_paletteram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int r; int g; int b;
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = (data >> 11) & 0x1f;
 g = (data >> 6) & 0x1f;
 b = (data >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 if (offset/2 >= 128)
 {
  r ^= 0x04;
  g ^= 0x04;
  b ^= 0x04;
 }
 palette_change_color(offset/2,r,g,b);
}

variable_types: oldword int

variable_types: newword int

variable_types: r int

variable_types: g int

variable_types: b int


irqhandler

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

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return cpu_set_nmi_line(1LL, a1);
}

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

variable_types: linestate int


original_code:
void tp84_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 + 0x42 * bit2 + 0x90 * 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 + 0x42 * bit2 + 0x90 * 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 + 0x42 * bit2 + 0x90 * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i+256*j]) = *color_prom + 128 + 16*j;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
  {
   if (*color_prom) (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = *color_prom + 16*j;
   else (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = 0;
  }
  color_prom++;
 }
}

canonical_original_code:
void tp84_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 + 0x42 * bit2 + 0x90 * 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 + 0x42 * bit2 + 0x90 * 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 + 0x42 * bit2 + 0x90 * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i+256*j]) = *color_prom + 128 + 16*j;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
  {
   if (*color_prom) (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = *color_prom + 16*j;
   else (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i+256*j]) = 0;
  }
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 tp84_beam_r()
{
return 255LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 255LL;
}

original_code:
static data_t tp84_beam_r(offs_t offset)
{
 return 255;
}

canonical_original_code:
static unsigned int tp84_beam_r(unsigned int offset)
{
 return 255;
}


decompiled_code:
__int64 tp84_vh_start()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer2 = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap2 )
{
free(dirtybuffer2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer2 = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap2 )
{
free(dirtybuffer2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

original_code:
int tp84_vh_start(void)
{
 if (generic_vh_start() != 0)
  return 1;
 if ((dirtybuffer2 = (unsigned char*)malloc(videoram_size)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer2);
  generic_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int tp84_vh_start()
{
 if (generic_vh_start() != 0)
  return 1;
 if ((dirtybuffer2 = (unsigned char *)malloc(videoram_size)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer2);
  generic_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 tp84_vh_stop()
{
free(dirtybuffer2);
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func7()
{
free(dirtybuffer2);
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

original_code:
void tp84_vh_stop(void)
{
 free(dirtybuffer2);
 bitmap_free(tmpbitmap2);
 generic_vh_stop();
}

canonical_original_code:
void tp84_vh_stop()
{
 free(dirtybuffer2);
 bitmap_free(tmpbitmap2);
 generic_vh_stop();
}


decompiled_code:
__int64 __fastcall tp84_vh_screenrefresh(__int64 a1)
{
int v1; // er13
int v2; // ebx
__int64 v3; // rbp
int v4; // er13
int v5; // ebp
__int64 v6; // rbx
int v8; // [rsp+8h] [rbp-30h] BYREF
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = (LOWORD(col0[0]) << 6) & 0x1C0 | (2 * LOBYTE(col0[0])) & 0x30;
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((16 * *(unsigned __int8 *)(colorram + v3)) & 0x300u),
v1 + (*(_BYTE *)(colorram + v3) & 0xFu),
*(_BYTE *)(colorram + v3) & 0x40,
*(_BYTE *)(colorram + v3) & 0x80,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
0LL,
0LL,
0LL);
}
if ( *((_BYTE *)dirtybuffer2 + v3) )
{
*((_BYTE *)dirtybuffer2 + v3) = 0;
if ( (unsigned int)(v2 % 32 - 2) > 0x1B )
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(tp84_videoram2 + v3) + ((16 * *(unsigned __int8 *)(tp84_colorram2 + v3)) & 0x300u),
v1 + (*(_BYTE *)(tp84_colorram2 + v3) & 0xFu),
*(_BYTE *)(tp84_colorram2 + v3) & 0x40,
*(_BYTE *)(tp84_colorram2 + v3) & 0x80,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
v8 = -(unsigned __int8)*tp84_scrollx;
v9[0] = -(unsigned __int8)*tp84_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v8, 1LL, v9, Machine + 776LL, 0LL, 0LL);
v4 = (16 * LOBYTE(col0[0])) & 0x70;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v6 + 1),
v4 + (*(_BYTE *)(spriteram + v6 + 2) & 0xFu),
((*(_BYTE *)(spriteram + v6 + 2) >> 6) ^ 1) & 1,
*(_BYTE *)(spriteram + v6 + 2) & 0x80,
*(unsigned __int8 *)(spriteram + v6),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + v6 + 3),
Machine + 776LL,
6LL,
0LL);
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &topvisiblearea, 0LL, 0LL);
return copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // er13
int v2; // ebx
__int64 v3; // rbp
int v4; // er13
int v5; // ebp
__int64 v6; // rbx
int v8; // [rsp+8h] [rbp-30h] BYREF
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = (LOWORD(col0[0]) << 6) & 0x1C0 | (2 * LOBYTE(col0[0])) & 0x30;
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((16 * *(unsigned __int8 *)(colorram + v3)) & 0x300u),
v1 + (*(_BYTE *)(colorram + v3) & 0xFu),
*(_BYTE *)(colorram + v3) & 0x40,
*(_BYTE *)(colorram + v3) & 0x80,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
0LL,
0LL,
0LL);
}
if ( *((_BYTE *)dirtybuffer2 + v3) )
{
*((_BYTE *)dirtybuffer2 + v3) = 0;
if ( (unsigned int)(v2 % 32 - 2) > 0x1B )
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(tp84_videoram2 + v3) + ((16 * *(unsigned __int8 *)(tp84_colorram2 + v3)) & 0x300u),
v1 + (*(_BYTE *)(tp84_colorram2 + v3) & 0xFu),
*(_BYTE *)(tp84_colorram2 + v3) & 0x40,
*(_BYTE *)(tp84_colorram2 + v3) & 0x80,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
v8 = -(unsigned __int8)*tp84_scrollx;
v9[0] = -(unsigned __int8)*tp84_scrolly;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v8, 1LL, v9, Machine + 776LL, 0LL, 0LL);
v4 = (16 * LOBYTE(col0[0])) & 0x70;
v5 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v6 = v5;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v6 + 1),
v4 + (*(_BYTE *)(spriteram + v6 + 2) & 0xFu),
((*(_BYTE *)(spriteram + v6 + 2) >> 6) ^ 1) & 1,
*(_BYTE *)(spriteram + v6 + 2) & 0x80,
*(unsigned __int8 *)(spriteram + v6),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + v6 + 3),
Machine + 776LL,
6LL,
0LL);
v6 -= 4LL;
v5 -= 4;
}
while ( v5 >= 0 );
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &topvisiblearea, 0LL, 0LL);
return copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

original_code:
void tp84_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int coloffset;
 coloffset = ((col0&0x18) << 1) + ((col0&0x07) << 6);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x30) << 4),
     (colorram[offs] & 0x0f) + coloffset,
     colorram[offs] & 0x40,colorram[offs] & 0x80,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx,sy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (sx < 2 || sx >= 30)
    drawgfx(tmpbitmap2,Machine->gfx[0],
      tp84_videoram2[offs] + ((tp84_colorram2[offs] & 0x30) << 4),
      (tp84_colorram2[offs] & 0x0f) + coloffset,
      tp84_colorram2[offs] & 0x40,tp84_colorram2[offs] & 0x80,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx,scrolly;
  scrollx = -*tp84_scrollx;
  scrolly = -*tp84_scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 coloffset = ((col0&0x07) << 4);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs + 0];
  sy = 240-spriteram[offs + 3];
  flipx = !(spriteram[offs + 2] & 0x40);
  flipy = spriteram[offs + 2] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    (spriteram[offs + 2] & 0x0f) + coloffset,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&topvisiblearea,TRANSPARENCY_NONE,0);
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void tp84_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int coloffset;
 coloffset = ((col0&0x18) << 1) + ((col0&0x07) << 6);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x30) << 4),
     (colorram[offs] & 0x0f) + coloffset,
     colorram[offs] & 0x40,colorram[offs] & 0x80,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx; int sy;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (sx < 2 || sx >= 30)
    drawgfx(tmpbitmap2,Machine->gfx[0],
      tp84_videoram2[offs] + ((tp84_colorram2[offs] & 0x30) << 4),
      (tp84_colorram2[offs] & 0x0f) + coloffset,
      tp84_colorram2[offs] & 0x40,tp84_colorram2[offs] & 0x80,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx; int scrolly;
  scrollx = -*tp84_scrollx;
  scrolly = -*tp84_scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 coloffset = ((col0&0x07) << 4);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs + 0];
  sy = 240-spriteram[offs + 3];
  flipx = !(spriteram[offs + 2] & 0x40);
  flipy = spriteram[offs + 2] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    (spriteram[offs + 2] & 0x0f) + coloffset,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&topvisiblearea,TRANSPARENCY_NONE,0);
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

variable_types: offs int

variable_types: coloffset int

variable_types: sx int

variable_types: sy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: flipx int

variable_types: flipy int

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


variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: C int


decompiled_code:
__int64 tp84_sh_timer_r()
{
return ((int)cpu_gettotalcycles() / 1024) & 0xF;
}

canonical_decompiled_code:
__int64 func10()
{
return ((int)cpu_gettotalcycles() / 1024) & 0xF;
}

original_code:
static data_t tp84_sh_timer_r(offs_t offset)
{
 return (cpu_gettotalcycles() / (2048/2)) & 0x0f;
}

canonical_original_code:
static unsigned int tp84_sh_timer_r(unsigned int offset)
{
 return (cpu_gettotalcycles() / (2048/2)) & 0x0f;
}


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

result = cpu_get_pc();
if ( (_DWORD)result == 57586 )
result = cpu_spinuntil_int();
return result;
}

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

result = cpu_get_pc();
if ( (_DWORD)result == 57586 )
result = cpu_spinuntil_int();
return result;
}

original_code:
static void tp84_catchloop_w(offs_t offset,data_t data)
{
 if( cpu_get_pc()==0xe0f2 ) cpu_spinuntil_int();
}

canonical_original_code:
static void tp84_catchloop_w(unsigned int offset, unsigned int data)
{
 if( cpu_get_pc()==0xe0f2 ) cpu_spinuntil_int();
}


decompiled_code:
__int64 tp84_sh_irqtrigger_w()
{
return cpu_cause_interrupt(2LL, 255LL);
}

canonical_decompiled_code:
__int64 func12()
{
return cpu_cause_interrupt(2LL, 255LL);
}

original_code:
static void tp84_sh_irqtrigger_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(2,0xff);
}

canonical_original_code:
static void tp84_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(2,0xff);
}


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

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

original_code:
static data_t sharedram_r(offs_t offset)
{
 return sharedram[offset];
}

canonical_original_code:
static unsigned int sharedram_r(unsigned int offset)
{
 return sharedram[offset];
}


original_code:
void mikie_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++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}

canonical_original_code:
void mikie_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++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}


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

result = (void *)(a2 & 7);
if ( (_DWORD)result != palettebank )
{
palettebank = a2 & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = (void *)(a2 & 7);
if ( (_DWORD)result != palettebank )
{
palettebank = a2 & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void mikie_palettebank_w(offs_t offset,data_t data)
{
 if (palettebank != (data & 7))
 {
  palettebank = data & 7;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void mikie_palettebank_w(unsigned int offset, unsigned int data)
{
 if (palettebank != (data & 7))
 {
  palettebank = data & 7;
  memset(dirtybuffer,1,videoram_size);
 }
}


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

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

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

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

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

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


decompiled_code:
__int64 mikie_sh_timer_r()
{
return (unsigned int)((int)cpu_gettotalcycles() / 512);
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)((int)cpu_gettotalcycles() / 512);
}

original_code:
data_t mikie_sh_timer_r(offs_t offset)
{
 int clock;
 clock = cpu_gettotalcycles() / 512;
 return clock;
}

canonical_original_code:
unsigned int mikie_sh_timer_r(unsigned int offset)
{
 int clock;
 clock = cpu_gettotalcycles() / 512;
 return clock;
}

variable_types: clock int


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

if ( !last_0 && a2 == 1 )
result = cpu_cause_interrupt(1LL, 255LL);
last_0 = a2;
return result;
}

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

if ( !last_0 && a2 == 1 )
result = cpu_cause_interrupt(1LL, 255LL);
last_0 = a2;
return result;
}

original_code:
void mikie_sh_irqtrigger_w(offs_t offset,data_t data)
{
 static int last;
 if (last == 0 && data == 1)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

canonical_original_code:
void mikie_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last == 0 && data == 1)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

variable_types: last int


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall hacked_controls_r(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&bionicc_inp + a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&bionicc_inp + a1);
}

original_code:
static data_t hacked_controls_r(offs_t offset)
{
 return (*(UINT16 *)(&bionicc_inp[offset]));
}

canonical_original_code:
static unsigned int hacked_controls_r(unsigned int offset)
{
 return (*(unsigned short *)(&bionicc_inp[offset]));
}


decompiled_code:
__int64 __fastcall hacked_soundcommand_r(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&soundcommand + a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&soundcommand + a1);
}

original_code:
static data_t hacked_soundcommand_r(offs_t offset)
{
 return (*(UINT16 *)(&soundcommand[offset]));
}

canonical_original_code:
static unsigned int hacked_soundcommand_r(unsigned int offset)
{
 return (*(unsigned short *)(&soundcommand[offset]));
}


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

tx_tilemap = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 64;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 64LL, v3);
LODWORD(v4) = 64;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v4);
bg_tilemap = v0;
v1 = fg_tilemap;
if ( !v0 || !fg_tilemap )
return 1LL;
if ( !tx_tilemap )
return 1LL;
*(_DWORD *)(tx_tilemap + 132) = 3;
*(_DWORD *)(v1 + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

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

tx_tilemap = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 64;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 64LL, v3);
LODWORD(v4) = 64;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v4);
bg_tilemap = v0;
v1 = fg_tilemap;
if ( !v0 || !fg_tilemap )
return 1LL;
if ( !tx_tilemap )
return 1LL;
*(_DWORD *)(tx_tilemap + 132) = 3;
*(_DWORD *)(v1 + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

original_code:
int bionicc_vh_start(void)
{
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,64,64);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x01, 8,8,64,64);
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 tx_tilemap->transparent_pen = 3;
 fg_tilemap->transparent_pen = 15;
 bg_tilemap->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int bionicc_vh_start()
{
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,64,64);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x01, 8,8,64,64);
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 tx_tilemap->transparent_pen = 3;
 fg_tilemap->transparent_pen = 15;
 bg_tilemap->transparent_pen = 15;
 return 0;
}


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

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

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

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

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

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

variable_types: oldword int

variable_types: newword int


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

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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall bionicc_paletteram_w(__int64 a1, __int16 a2)
{
return paletteram_RRRRGGGGBBBBIIII_word_w(a1, (2 * (_BYTE)a2) & 0xE | a2 & 0xFFF1u);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int16 a2)
{
return paletteram_RRRRGGGGBBBBIIII_word_w(a1, (2 * (_BYTE)a2) & 0xE | a2 & 0xFFF1u);
}

original_code:
void bionicc_paletteram_w(offs_t offset,data_t data)
{
 paletteram_RRRRGGGGBBBBIIII_word_w(offset,(data & 0xfff1) | ((data & 0x0007) << 1));
}

canonical_original_code:
void bionicc_paletteram_w(unsigned int offset, unsigned int data)
{
 paletteram_RRRRGGGGBBBBIIII_word_w(offset,(data & 0xfff1) | ((data & 0x0007) << 1));
}


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

if ( a1 == 4 )
return tilemap_set_scrollx(bg_tilemap, 0LL, a2);
if ( a1 > 4 )
{
if ( a1 == 6 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, a2);
}
else if ( a1 )
{
if ( a1 == 2 )
result = tilemap_set_scrolly(fg_tilemap, 0LL, a2);
}
else
{
result = tilemap_set_scrollx(fg_tilemap, 0LL, a2);
}
return result;
}

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

if ( a1 == 4 )
return tilemap_set_scrollx(bg_tilemap, 0LL, a2);
if ( a1 > 4 )
{
if ( a1 == 6 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, a2);
}
else if ( a1 )
{
if ( a1 == 2 )
result = tilemap_set_scrolly(fg_tilemap, 0LL, a2);
}
else
{
result = tilemap_set_scrollx(fg_tilemap, 0LL, a2);
}
return result;
}

original_code:
void bionicc_scroll_w(offs_t offset,data_t data)
{
 switch( offset )
 {
  case 0:
   tilemap_set_scrollx(fg_tilemap,0,data);
   break;
  case 2:
   tilemap_set_scrolly(fg_tilemap,0,data);
   break;
  case 4:
   tilemap_set_scrollx(bg_tilemap,0,data);
   break;
  case 6:
   tilemap_set_scrolly(bg_tilemap,0,data);
   break;
 }
}

canonical_original_code:
void bionicc_scroll_w(unsigned int offset, unsigned int data)
{
 switch( offset )
 {
  case 0:
   tilemap_set_scrollx(fg_tilemap,0,data);
   break;
  case 2:
   tilemap_set_scrolly(fg_tilemap,0,data);
   break;
  case 4:
   tilemap_set_scrollx(bg_tilemap,0,data);
   break;
  case 6:
   tilemap_set_scrolly(bg_tilemap,0,data);
   break;
 }
}


decompiled_code:
__int64 __fastcall bionicc_gfxctrl_w(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx
__int64 v3; // rsi

v2 = a2 >> 8;
v3 = BYTE1(a2) & 1;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
tilemap_set_enable(bg_tilemap, v2 & 0x20);
tilemap_set_enable(fg_tilemap, v2 & 0x10);
coin_counter_w(0LL, v2 & 0x80);
return coin_counter_w(1LL, v2 & 0x40);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx
__int64 v3; // rsi

v2 = a2 >> 8;
v3 = BYTE1(a2) & 1;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
tilemap_set_enable(bg_tilemap, v2 & 0x20);
tilemap_set_enable(fg_tilemap, v2 & 0x10);
coin_counter_w(0LL, v2 & 0x80);
return coin_counter_w(1LL, v2 & 0x40);
}

original_code:
void bionicc_gfxctrl_w(offs_t offset,data_t data)
{
 data >>= 8;
 flipscreen = data & 1;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 tilemap_set_enable(bg_tilemap,data & 0x20);
 tilemap_set_enable(fg_tilemap,data & 0x10);
 coin_counter_w(0,data & 0x80);
 coin_counter_w(1,data & 0x40);
}

canonical_original_code:
void bionicc_gfxctrl_w(unsigned int offset, unsigned int data)
{
 data >>= 8;
 flipscreen = data & 1;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 tilemap_set_enable(bg_tilemap,data & 0x20);
 tilemap_set_enable(fg_tilemap,data & 0x10);
 coin_counter_w(0,data & 0x80);
 coin_counter_w(1,data & 0x40);
}


decompiled_code:
void *__fastcall bionicc_draw_sprites(__int64 a1)
{
__int64 v1; // r15
void *result; // rax
int v3; // ebp
__int64 v4; // rbx
unsigned __int16 v5; // dx

v1 = *(_QWORD *)(Machine + 536LL);
result = &spriteram_size;
v3 = spriteram_size - 8;
if ( spriteram_size - 8 >= 0 )
{
v4 = v3;
do
{
result = (void *)buffered_spriteram;
v5 = *(_WORD *)(buffered_spriteram + v4) & 0x7FF;
if ( v5 != 2047 )
result = (void *)drawgfx(a1, v1, v5);
v4 -= 8LL;
v3 -= 8;
}
while ( v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func16(__int64 a1)
{
__int64 v1; // r15
void *result; // rax
int v3; // ebp
__int64 v4; // rbx
unsigned __int16 v5; // dx

v1 = *(_QWORD *)(Machine + 536LL);
result = &spriteram_size;
v3 = spriteram_size - 8;
if ( spriteram_size - 8 >= 0 )
{
v4 = v3;
do
{
result = (void *)buffered_spriteram;
v5 = *(_WORD *)(buffered_spriteram + v4) & 0x7FF;
if ( v5 != 2047 )
result = (void *)drawgfx(a1, v1, v5);
v4 -= 8LL;
v3 -= 8;
}
while ( v3 >= 0 );
}
return result;
}

original_code:
static void bionicc_draw_sprites( struct osd_bitmap *bitmap )
{
 int offs;
 const struct GfxElement *gfx = Machine->gfx[3];
 const struct rectangle *clip = &Machine->visible_area;
 for (offs = spriteram_size-8;offs >= 0;offs -= 8)
 {
  int tile_number = (*(UINT16 *)(&buffered_spriteram[offs]))&0x7ff;
  if( tile_number!=0x7FF ){
   int attr = (*(UINT16 *)(&buffered_spriteram[offs+2]));
   int color = (attr&0x3C)>>2;
   int flipx = attr&0x02;
   int flipy = 0;
   int sx= (signed short)(*(UINT16 *)(&buffered_spriteram[offs+6]));
   int sy= (signed short)(*(UINT16 *)(&buffered_spriteram[offs+4]));
   if(sy>512-16) sy-=512;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx( bitmap, gfx,
    tile_number,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,15);
  }
 }
}

canonical_original_code:
static void bionicc_draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 struct GfxElement *gfx = Machine->gfx[3];
 struct rectangle *clip = &Machine->visible_area;
 for (offs = spriteram_size-8;offs >= 0;offs -= 8)
 {
  int tile_number = (*(UINT16 *)(&buffered_spriteram[offs]))&0x7ff;
  if( tile_number!=0x7FF ){
   int attr = (*(UINT16 *)(&buffered_spriteram[offs+2]));
   int color = (attr&0x3C)>>2;
   int flipx = attr&0x02;
   int flipy = 0;
   int sx = (signed short)(*(UINT16 *)(&buffered_spriteram[offs+6]));
   int sy = (signed short)(*(UINT16 *)(&buffered_spriteram[offs+4]));
   if(sy>512-16) sy-=512;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx( bitmap, gfx,
    tile_number,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,15);
  }
 }
}

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

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

variable_types: struct rectangle { int min_x; int min_y; } *

variable_types: attr int

variable_types: color int


decompiled_code:
__int64 bionicc_eof_callback()
{
return buffer_spriteram_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func17()
{
return buffer_spriteram_w(0LL, 0LL);
}

original_code:
void bionicc_eof_callback(void)
{
 buffer_spriteram_w(0,0);
}

canonical_original_code:
void bionicc_eof_callback()
{
 buffer_spriteram_w(0,0);
}


decompiled_code:
__int64 __fastcall bionicc_inputs_r(int a1)
{
int v1; // ebx

v1 = ((__int64 (*)(void))readinputport)();
return (v1 << 8) + (unsigned int)readinputport((unsigned int)(a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
int v1; // ebx

v1 = ((__int64 (*)(void))readinputport)();
return (v1 << 8) + (unsigned int)readinputport((unsigned int)(a1 + 1));
}

original_code:
data_t bionicc_inputs_r(offs_t offset)
{
 return (readinputport(offset)<<8) + readinputport(offset+1);
}

canonical_original_code:
unsigned int bionicc_inputs_r(unsigned int offset)
{
 return (readinputport(offset)<<8) + readinputport(offset+1);
}


decompiled_code:
char bionicc_mpu_trigger_w()
{
__int16 v0; // ax
__int16 v1; // ax

bionicc_inp = ((int)readinputport(0LL) >> 4) ^ 0xF;
v0 = readinputport(5LL);
LOBYTE(v0) = ~(_BYTE)v0;
word_11CC = v0;
v1 = readinputport(4LL);
LOBYTE(v1) = ~(_BYTE)v1;
word_11CE = v1;
return v1;
}

canonical_decompiled_code:
char func19()
{
__int16 v0; // ax
__int16 v1; // ax

bionicc_inp = ((int)readinputport(0LL) >> 4) ^ 0xF;
v0 = readinputport(5LL);
LOBYTE(v0) = ~(_BYTE)v0;
word_11CC = v0;
v1 = readinputport(4LL);
LOBYTE(v1) = ~(_BYTE)v1;
word_11CE = v1;
return v1;
}

original_code:
static void bionicc_mpu_trigger_w(offs_t offset,data_t data)
{
 data = readinputport(0) >> 4;
 (*(UINT16 *)(&bionicc_inp[0x00]) = (data ^ 0x0f));
 data = readinputport(5);
 (*(UINT16 *)(&bionicc_inp[0x02]) = (data ^ 0xff));
 data = readinputport(4);
 (*(UINT16 *)(&bionicc_inp[0x04]) = (data ^ 0xff));
}

canonical_original_code:
static void bionicc_mpu_trigger_w(unsigned int offset, unsigned int data)
{
 data = readinputport(0) >> 4;
 (*(unsigned short *)(&bionicc_inp[0x00]) = (data ^ 0x0f));
 data = readinputport(5);
 (*(unsigned short *)(&bionicc_inp[0x02]) = (data ^ 0xff));
 data = readinputport(4);
 (*(unsigned short *)(&bionicc_inp[0x04]) = (data ^ 0xff));
}


decompiled_code:
__int64 __fastcall hacked_soundcommand_w(unsigned int a1, int a2)
{
*(_WORD *)((char *)&soundcommand + a1) = a2 | *(_WORD *)((_BYTE *)&soundcommand + a1) & HIWORD(a2);
return soundlatch_w(0LL, (unsigned __int8)a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1, int a2)
{
*(_WORD *)((char *)&soundcommand + a1) = a2 | *(_WORD *)((_BYTE *)&soundcommand + a1) & HIWORD(a2);
return soundlatch_w(0LL, (unsigned __int8)a2);
}

original_code:
void hacked_soundcommand_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&soundcommand[offset])) = (((*(UINT16 *)(&soundcommand[offset])) & ((data) >> 16)) | (data))));
 soundlatch_w(0,data & 0xff);
}

canonical_original_code:
void hacked_soundcommand_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&soundcommand[offset])) = (((*(unsigned short *)(&soundcommand[offset])) & ((data) >> 16)) | (data))));
 soundlatch_w(0,data & 0xff);
}


decompiled_code:
__int64 bionicc_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 2 : 4;
}

canonical_decompiled_code:
__int64 func21()
{
return (unsigned int)cpu_getiloops() == 0 ? 2 : 4;
}

original_code:
int bionicc_interrupt(void)
{
 if (cpu_getiloops() == 0) return 2;
 else return 4;
}

canonical_original_code:
int bionicc_interrupt()
{
 if (cpu_getiloops() == 0) return 2;
 else return 4;
}


decompiled_code:
__int64 __fastcall bionicc_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
mark_sprite_colors();
*palette_used_colors |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
tilemap_draw(a1, fg_tilemap, 2LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
bionicc_draw_sprites(a1);
tilemap_draw(a1, fg_tilemap, 1LL);
return tilemap_draw(a1, tx_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
func22();
*palette_used_colors |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
tilemap_draw(a1, fg_tilemap, 2LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
func16(a1);
tilemap_draw(a1, fg_tilemap, 1LL);
return tilemap_draw(a1, tx_tilemap, 0LL);
}

original_code:
void bionicc_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colors();
 palette_used_colors[0] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 tilemap_draw(bitmap,fg_tilemap,2);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 bionicc_draw_sprites(bitmap);
 tilemap_draw(bitmap,fg_tilemap,1);
 tilemap_draw(bitmap,tx_tilemap,0);
}

canonical_original_code:
void bionicc_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colors();
 palette_used_colors[0] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 tilemap_draw(bitmap,fg_tilemap,2);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 bionicc_draw_sprites(bitmap);
 tilemap_draw(bitmap,fg_tilemap,1);
 tilemap_draw(bitmap,tx_tilemap,0);
}


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

v1 = 2 * a1;
v2 = *(unsigned __int16 *)(bionicc_bgvideoram + 2 * v1 + 2);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = ((*(_WORD *)(bionicc_bgvideoram + 2 * v1 + 2) << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(bionicc_bgvideoram + 2 * v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * ((v2 >> 3) & 3);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = v6;
result = ((unsigned int)v2 >> 5) & 2;
*((_DWORD *)&tile_info + 5) = result | (v2 >> 7) & 1;
return result;
}

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

v1 = 2 * a1;
v2 = *(unsigned __int16 *)(bionicc_bgvideoram + 2 * v1 + 2);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = ((*(_WORD *)(bionicc_bgvideoram + 2 * v1 + 2) << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(bionicc_bgvideoram + 2 * v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * ((v2 >> 3) & 3);
v5 = *(_QWORD *)(v3 + 32);
v6 = 0;
if ( v5 )
v6 = *(_DWORD *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = v6;
result = ((unsigned int)v2 >> 5) & 2;
*((_DWORD *)&tile_info + 5) = result | (v2 >> 7) & 1;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 UINT16 *videoram1 = (UINT16 *)bionicc_bgvideoram;
 int attr = videoram1[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned short *videoram1 = (UINT16 *)bionicc_bgvideoram;
 int attr = videoram1[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
}

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


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

v1 = 2 * a1;
v2 = *(_WORD *)(bionicc_fgvideoram + 2 * v1 + 2);
v3 = *(_QWORD *)(Machine + 528LL);
v4 = ((v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(bionicc_fgvideoram + 2 * v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (((int)v2 >> 3) & 3);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
if ( (v2 & 0xC0) == 192 )
{
*((_DWORD *)&tile_info + 6) = 2;
*((_DWORD *)&tile_info + 5) = 0;
}
else
{
*((_DWORD *)&tile_info + 6) = ((int)v2 >> 5) & 1;
result = (v2 >> 5) & 2;
*((_DWORD *)&tile_info + 5) = result | ((int)v2 >> 7) & 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdi
unsigned __int16 v2; // r8
__int64 v3; // rcx
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_WORD *)(bionicc_fgvideoram + 2 * v1 + 2);
v3 = *(_QWORD *)(Machine + 528LL);
v4 = ((v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(bionicc_fgvideoram + 2 * v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (((int)v2 >> 3) & 3);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
if ( (v2 & 0xC0) == 192 )
{
*((_DWORD *)&tile_info + 6) = 2;
*((_DWORD *)&tile_info + 5) = 0;
}
else
{
*((_DWORD *)&tile_info + 6) = ((int)v2 >> 5) & 1;
result = (v2 >> 5) & 2;
*((_DWORD *)&tile_info + 5) = result | ((int)v2 >> 7) & 1;
}
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 UINT16 *videoram1 = (UINT16 *)bionicc_fgvideoram;
 int attr = videoram1[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 if ((attr & 0xc0) == 0xc0)
 {
  tile_info.priority = 2;
  tile_info.flags = 0;
 }
 else
 {
  tile_info.priority = (attr & 0x20) >> 5;
  tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
 }
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned short *videoram1 = (UINT16 *)bionicc_fgvideoram;
 int attr = videoram1[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 if ((attr & 0xc0) == 0xc0)
 {
  tile_info.priority = 2;
  tile_info.flags = 0;
 }
 else
 {
  tile_info.priority = (attr & 0x20) >> 5;
  tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
 }
}


decompiled_code:
__int64 __fastcall get_tx_tile_info(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = a1 + 1024LL;
v2 = *(_WORD *)(bionicc_txvideoram + 2 * v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = ((4 * v2) & 0x300 | (unsigned __int64)*(unsigned __int8 *)(bionicc_txvideoram + 2 * v1 - 2048))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0x3F);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = a1 + 1024LL;
v2 = *(_WORD *)(bionicc_txvideoram + 2 * v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = ((4 * v2) & 0x300 | (unsigned __int64)*(unsigned __int8 *)(bionicc_txvideoram + 2 * v1 - 2048))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0x3F);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

canonical_original_code:
static void get_tx_tile_info(int tile_index)
{
 unsigned short *videoram1 = (UINT16 *)bionicc_txvideoram;
 int attr = videoram1[tile_index + 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((videoram1[tile_index] & 0xff) + ((attr & 0x00c0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}


decompiled_code:
__int64 mark_sprite_colors()
{
__int64 v0; // r11
int v1; // edi
void **v2; // r8
void **v3; // rax
_WORD *v4; // rdx
__int64 v5; // r10
unsigned __int16 v6; // ax
__int64 v7; // rcx
__int64 result; // rax
int v9; // ecx
int v10[16]; // [rsp+0h] [rbp-40h] BYREF
void *retaddr; // [rsp+40h] [rbp+0h] BYREF

v0 = Machine;
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
v2 = (void **)v10;
v3 = (void **)v10;
do
{
*(_DWORD *)v3 = 0;
v3 = (void **)((char *)v3 + 4);
}
while ( v3 != &retaddr );
v4 = (_WORD *)buffered_spriteram;
v5 = buffered_spriteram + 1280LL;
do
{
v6 = *v4 & 0x7FF;
if ( v6 != 2047 )
{
v7 = ((int)(unsigned __int16)v4[1] >> 2) & 0xF;
v10[v7] |= *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v0 + 536) + 32LL) + 4LL * v6);
}
v4 += 4;
}
while ( v4 != (_WORD *)v5 );
do
{
v9 = *(_DWORD *)v2;
LODWORD(result) = 0;
do
{
if ( _bittest(&v9, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v2 = (void **)((char *)v2 + 4);
v1 += 16;
}
while ( v2 != &retaddr );
return result;
}

canonical_decompiled_code:
__int64 func22()
{
__int64 v0; // r11
int v1; // edi
void **v2; // r8
void **v3; // rax
_WORD *v4; // rdx
__int64 v5; // r10
unsigned __int16 v6; // ax
__int64 v7; // rcx
__int64 result; // rax
int v9; // ecx
int v10[16]; // [rsp+0h] [rbp-40h] BYREF
void *retaddr; // [rsp+40h] [rbp+0h] BYREF

v0 = Machine;
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
v2 = (void **)v10;
v3 = (void **)v10;
do
{
*(_DWORD *)v3 = 0;
v3 = (void **)((char *)v3 + 4);
}
while ( v3 != &retaddr );
v4 = (_WORD *)buffered_spriteram;
v5 = buffered_spriteram + 1280LL;
do
{
v6 = *v4 & 0x7FF;
if ( v6 != 2047 )
{
v7 = ((int)(unsigned __int16)v4[1] >> 2) & 0xF;
v10[v7] |= *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v0 + 536) + 32LL) + 4LL * v6);
}
v4 += 4;
}
while ( v4 != (_WORD *)v5 );
do
{
v9 = *(_DWORD *)v2;
LODWORD(result) = 0;
do
{
if ( _bittest(&v9, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v2 = (void **)((char *)v2 + 4);
v1 += 16;
}
while ( v2 != &retaddr );
return result;
}

original_code:
void mark_sprite_colors( void )
{
 int offs, code, color, i, pal_base;
 int colmask[16];
 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
 for(i=0;i<16;i++) colmask[i] = 0;
 for (offs = 0; offs < 0x500;offs += 8)
 {
  code = (*(UINT16 *)(&buffered_spriteram[offs])) & 0x7ff;
  if( code != 0x7FF ) {
   color = ((*(UINT16 *)(&buffered_spriteram[offs+2])) & 0x3c) >> 2;
   colmask[color] |= Machine->gfx[3]->pen_usage[code];
  }
 }
 for (color = 0;color < 16;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

canonical_original_code:
void mark_sprite_colors()
{
 int offs; int code; int color; int i; int pal_base;
 int colmask[16];
 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
 for(i=0;i<16;i++) colmask[i] = 0;
 for (offs = 0; offs < 0x500;offs += 8)
 {
  code = (*(unsigned short *)(&buffered_spriteram[offs])) & 0x7ff;
  if( code != 0x7FF ) {
   color = ((*(unsigned short *)(&buffered_spriteram[offs+2])) & 0x3c) >> 2;
   colmask[color] |= Machine->gfx[3]->pen_usage[code];
  }
 }
 for (color = 0;color < 16;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

variable_types: offs int

variable_types: code int

variable_types: i int

variable_types:
colmask
int [16]


decompiled_code:
void __fastcall milliped_input_select_w(__int64 a1, int a2)
{
dsw_select = a2 == 0;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
dsw_select = a2 == 0;
}

original_code:
static void milliped_input_select_w(offs_t offset,data_t data)
{
 dsw_select = (data == 0);
}

canonical_original_code:
static void milliped_input_select_w(unsigned int offset, unsigned int data)
{
 dsw_select = (data == 0);
}


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

canonical_original_code:
void milliped_paletteram_w(unsigned int offset, unsigned int data)
{
 int bit0; int bit1; int bit2;
 int r; int g; int b;
 paletteram[offset] = data;
 bit0 = (~data >> 5) & 0x01;
 bit1 = (~data >> 6) & 0x01;
 bit2 = (~data >> 7) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (~data >> 3) & 0x01;
 bit2 = (~data >> 4) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (~data >> 0) & 0x01;
 bit1 = (~data >> 1) & 0x01;
 bit2 = (~data >> 2) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int


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

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

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

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

variable_types: sx int

variable_types: sy int

variable_types: bank int

variable_types: spritenum int

variable_types: x int

variable_types: y int


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

if ( dsw_select )
return sign_3 | (unsigned int)readinputport(1LL);
v0 = readinputport(7LL);
if ( oldpos_2 != v0 )
{
sign_3 = ((_BYTE)v0 - (_BYTE)oldpos_2) & 0x80;
oldpos_2 = v0;
}
return readinputport(1LL) & 0x70 | sign_3 | oldpos_2 & 0xFu;
}

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

if ( dsw_select )
return sign_3 | (unsigned int)readinputport(1LL);
v0 = readinputport(7LL);
if ( oldpos_2 != v0 )
{
sign_3 = ((_BYTE)v0 - (_BYTE)oldpos_2) & 0x80;
oldpos_2 = v0;
}
return readinputport(1LL) & 0x70 | sign_3 | oldpos_2 & 0xFu;
}

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

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

variable_types: oldpos int

variable_types: sign int

variable_types: newpos int


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

if ( dsw_select )
return sign_1 | (unsigned int)readinputport(0LL);
v0 = readinputport(6LL);
if ( oldpos_0 != v0 )
{
sign_1 = ((_BYTE)v0 - (_BYTE)oldpos_0) & 0x80;
oldpos_0 = v0;
}
return readinputport(0LL) & 0x70 | sign_1 | oldpos_0 & 0xFu;
}

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

if ( dsw_select )
return sign_1 | (unsigned int)readinputport(0LL);
v0 = readinputport(6LL);
if ( oldpos_0 != v0 )
{
sign_1 = ((_BYTE)v0 - (_BYTE)oldpos_0) & 0x80;
oldpos_0 = v0;
}
return readinputport(0LL) & 0x70 | sign_1 | oldpos_0 & 0xFu;
}

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

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


decompiled_code:
void __fastcall bsktball_nmion_w(char a1)
{
NMION = a1 & 1;
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
NMION = a1 & 1;
}

original_code:
void bsktball_nmion_w(offs_t offset,data_t data)
{
 NMION = offset & 0x01;
}

canonical_original_code:
void bsktball_nmion_w(unsigned int offset, unsigned int data)
{
 NMION = offset & 0x01;
}


decompiled_code:
void __fastcall bsktball_ld1_w(char a1)
{
LD1 = a1 & 1;
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
LD1 = a1 & 1;
}

original_code:
void bsktball_ld1_w(offs_t offset,data_t data)
{
 LD1 = (offset & 0x01);
}

canonical_original_code:
void bsktball_ld1_w(unsigned int offset, unsigned int data)
{
 LD1 = (offset & 0x01);
}


decompiled_code:
void __fastcall bsktball_ld2_w(char a1)
{
LD2 = a1 & 1;
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
LD2 = a1 & 1;
}

original_code:
void bsktball_ld2_w(offs_t offset,data_t data)
{
 LD2 = (offset & 0x01);
}

canonical_original_code:
void bsktball_ld2_w(unsigned int offset, unsigned int data)
{
 LD2 = (offset & 0x01);
}


decompiled_code:
__int64 __fastcall bsktball_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 i; // rbx
__int64 result; // rax

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(4 * *(_BYTE *)(videoram + v2)) & 0x3C | ((int)*(unsigned __int8 *)(videoram + v2) >> 4) & 3u,
((int)*(unsigned __int8 *)(videoram + v2) >> 6) & 1,
*(_BYTE *)(videoram + v2) >> 7,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 0LL; i != 64; i += 4LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(bsktball_motion + i) & 0x3F,
*(_BYTE *)(bsktball_motion + i + 3) & 0x3F,
*(_BYTE *)(bsktball_motion + i) >> 7,
0LL,
*(unsigned __int8 *)(bsktball_motion + i + 2),
224 - (unsigned int)*(unsigned __int8 *)(bsktball_motion + i + 1),
Machine + 776LL,
2LL,
0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 i; // rbx
__int64 result; // rax

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(4 * *(_BYTE *)(videoram + v2)) & 0x3C | ((int)*(unsigned __int8 *)(videoram + v2) >> 4) & 3u,
((int)*(unsigned __int8 *)(videoram + v2) >> 6) & 1,
*(_BYTE *)(videoram + v2) >> 7,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 0LL; i != 64; i += 4LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(bsktball_motion + i) & 0x3F,
*(_BYTE *)(bsktball_motion + i + 3) & 0x3F,
*(_BYTE *)(bsktball_motion + i) >> 7,
0LL,
*(unsigned __int8 *)(bsktball_motion + i + 2),
224 - (unsigned int)*(unsigned __int8 *)(bsktball_motion + i + 1),
Machine + 776LL,
2LL,
0LL);
return result;
}

original_code:
void bsktball_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    int offs,motion;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
                if (dirtybuffer[offs])
                {
                        int charcode;
                        int sx,sy;
      int flipx;
                        int color;
                        dirtybuffer[offs]=0;
                        charcode = videoram[offs];
                        color = (charcode & 0x40) >> 6;
      flipx = (charcode & 0x80) >> 7;
                        charcode = ((charcode & 0x0F) << 2) | ((charcode & 0x30) >> 4);
                        sx = 8 * (offs % 32);
                        sy = 8 * (offs / 32);
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                charcode, color,
        flipx,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
                }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (motion=0;motion<16;motion++)
 {
  int pic,sx,sy,color,flipx;
  pic = bsktball_motion[motion*4];
  sy = 28*8 - bsktball_motion[motion*4 + 1];
  sx = bsktball_motion[motion*4 + 2];
  color = bsktball_motion[motion*4 + 3];
  flipx = (pic & 0x80) >> 7;
  pic = (pic & 0x3F);
        color = (color & 0x3F);
        drawgfx(bitmap,Machine->gfx[1],
                pic, color,
    flipx,0,sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void bsktball_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    int offs; int motion;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
                if (dirtybuffer[offs])
                {
                        int charcode;
                        int sx; int sy;
      int flipx;
                        int color;
                        dirtybuffer[offs]=0;
                        charcode = videoram[offs];
                        color = (charcode & 0x40) >> 6;
      flipx = (charcode & 0x80) >> 7;
                        charcode = ((charcode & 0x0F) << 2) | ((charcode & 0x30) >> 4);
                        sx = 8 * (offs % 32);
                        sy = 8 * (offs / 32);
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                charcode, color,
        flipx,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
                }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (motion=0;motion<16;motion++)
 {
  int pic; int sx; int sy; int color; int flipx;
  pic = bsktball_motion[motion*4];
  sy = 28*8 - bsktball_motion[motion*4 + 1];
  sx = bsktball_motion[motion*4 + 2];
  color = bsktball_motion[motion*4 + 3];
  flipx = (pic & 0x80) >> 7;
  pic = (pic & 0x3F);
        color = (color & 0x3F);
        drawgfx(bitmap,Machine->gfx[1],
                pic, color,
    flipx,0,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: motion int

variable_types: charcode int

variable_types: flipx int

variable_types: color int

variable_types: pic int