decompiled_code:
void __fastcall starcrus_p1_x_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_x = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_x = a2;
}

original_code: void starcrus_p1_x_w(offs_t offset,data_t data) { p1_x = data^0xff; }

canonical_original_code: void starcrus_p1_x_w(unsigned int offset, unsigned int data) { p1_x = data^0xff; }


decompiled_code:
void __fastcall starcrus_p1_y_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_y = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p1_y = a2;
}

original_code: void starcrus_p1_y_w(offs_t offset,data_t data) { p1_y = data^0xff; }

canonical_original_code: void starcrus_p1_y_w(unsigned int offset, unsigned int data) { p1_y = data^0xff; }

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
void __fastcall starcrus_p2_x_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_x = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_x = a2;
}

original_code: void starcrus_p2_x_w(offs_t offset,data_t data) { p2_x = data^0xff; }

canonical_original_code: void starcrus_p2_x_w(unsigned int offset, unsigned int data) { p2_x = data^0xff; }


decompiled_code:
void __fastcall starcrus_p2_y_w(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_y = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
LOBYTE(a2) = ~(_BYTE)a2;
p2_y = a2;
}

original_code: void starcrus_p2_y_w(offs_t offset,data_t data) { p2_y = data^0xff; }

canonical_original_code: void starcrus_p2_y_w(unsigned int offset, unsigned int data) { p2_y = data^0xff; }


decompiled_code:
char starcrus_coll_det_r()
{
return ~(_BYTE)collision_reg;
}

canonical_decompiled_code:
char func8()
{
return ~(_BYTE)collision_reg;
}

original_code:
data_t starcrus_coll_det_r(offs_t offset)
{
    return collision_reg ^ 0xff;
}

canonical_original_code:
unsigned int starcrus_coll_det_r(unsigned int offset)
{
    return collision_reg ^ 0xff;
}

return_type: unsigned int


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

ship1_vid = bitmap_alloc(16LL, 16LL);
v0 = 1;
if ( ship1_vid )
{
ship2_vid = bitmap_alloc(16LL, 16LL);
if ( ship2_vid )
{
proj1_vid = bitmap_alloc(16LL, 16LL);
if ( proj1_vid )
{
proj2_vid = bitmap_alloc(16LL, 16LL);
v0 = 0;
if ( !proj2_vid )
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
v0 = 1;
}
}
else
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
v0 = 1;
}
}
else
{
bitmap_free(ship1_vid);
v0 = 1;
}
}
return v0;
}

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

ship1_vid = bitmap_alloc(16LL, 16LL);
v0 = 1;
if ( ship1_vid )
{
ship2_vid = bitmap_alloc(16LL, 16LL);
if ( ship2_vid )
{
proj1_vid = bitmap_alloc(16LL, 16LL);
if ( proj1_vid )
{
proj2_vid = bitmap_alloc(16LL, 16LL);
v0 = 0;
if ( !proj2_vid )
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
v0 = 1;
}
}
else
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
v0 = 1;
}
}
else
{
bitmap_free(ship1_vid);
v0 = 1;
}
}
return v0;
}

original_code:
int starcrus_vh_start(void)
{
 if ((ship1_vid = bitmap_alloc(16,16)) == 0)
 {
  return 1;
 }
 if ((ship2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  return 1;
 }
 if ((proj1_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  return 1;
 }
 if ((proj2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  bitmap_free(proj1_vid);
  return 1;
 }
 return 0;
}

canonical_original_code:
int starcrus_vh_start()
{
 if ((ship1_vid = bitmap_alloc(16,16)) == 0)
 {
  return 1;
 }
 if ((ship2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  return 1;
 }
 if ((proj1_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  return 1;
 }
 if ((proj2_vid = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(ship1_vid);
  bitmap_free(ship2_vid);
  bitmap_free(proj1_vid);
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 starcrus_vh_stop()
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
return bitmap_free(proj2_vid);
}

canonical_decompiled_code:
__int64 func11()
{
bitmap_free(ship1_vid);
bitmap_free(ship2_vid);
bitmap_free(proj1_vid);
return bitmap_free(proj2_vid);
}

original_code:
void starcrus_vh_stop(void)
{
 bitmap_free(ship1_vid);
 bitmap_free(ship2_vid);
 bitmap_free(proj1_vid);
 bitmap_free(proj2_vid);
}

canonical_original_code:
void starcrus_vh_stop()
{
 bitmap_free(ship1_vid);
 bitmap_free(ship2_vid);
 bitmap_free(proj1_vid);
 bitmap_free(proj2_vid);
}


decompiled_code:
__int64 starcrus_collision_check_s1s2()
{
int v0; // ebp
int v1; // er12
__int64 v2; // rsi
unsigned int i; // ebp
unsigned int j; // ebx
int v6[4]; // [rsp+0h] [rbp-38h] BYREF
int *v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+18h] [rbp-20h]
__int64 v9; // [rsp+20h] [rbp-18h]

v6[0] = 0;
v6[1] = 15;
v6[2] = 0;
v6[3] = 15;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), v6);
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), v6);
v0 = s1_x;
v1 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
v6,
0LL,
0LL);
v2 = *(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592);
v9 = 0LL;
v8 = 0LL;
v7 = v6;
((void (__fastcall *)(__int64, __int64, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))drawgfx)(
ship2_vid,
v2,
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
(unsigned int)(s2_x - v0),
(unsigned int)(s2_y - v1));
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(ship1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(ship2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
int v1; // er12
__int64 v2; // rsi
unsigned int i; // ebp
unsigned int j; // ebx
int v6[4]; // [rsp+0h] [rbp-38h] BYREF
int *v7; // [rsp+10h] [rbp-28h]
__int64 v8; // [rsp+18h] [rbp-20h]
__int64 v9; // [rsp+20h] [rbp-18h]

v6[0] = 0;
v6[1] = 15;
v6[2] = 0;
v6[3] = 15;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), v6);
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), v6);
v0 = s1_x;
v1 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
v6,
0LL,
0LL);
v2 = *(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592);
v9 = 0LL;
v8 = 0LL;
v7 = v6;
((void (__fastcall *)(__int64, __int64, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))drawgfx)(
ship2_vid,
v2,
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
(unsigned int)(s2_x - v0),
(unsigned int)(s2_y - v1));
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(ship1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(ship2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
}
return 0LL;
}

original_code:
int starcrus_collision_check_s1s2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_s1s2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

variable_types: sx int

variable_types: sy int

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


decompiled_code:
__int64 starcrus_collision_check_p1p2()
{
__int64 result; // rax
int v1; // ebx
int v2; // ebp
unsigned int i; // ebp
unsigned int j; // ebx
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

result = ((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8;
if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) != 0 )
{
v5[0] = 0;
v5[1] = 15;
v5[2] = 0;
v5[3] = 15;
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v1 = p1_x;
v2 = p1_y;
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v1),
(unsigned int)(p2_y - v2),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // ebx
int v2; // ebp
unsigned int i; // ebp
unsigned int j; // ebx
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

result = ((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8;
if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) != 0 )
{
v5[0] = 0;
v5[1] = 15;
v5[2] = 0;
v5[3] = 15;
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v1 = p1_x;
v2 = p1_y;
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v1),
(unsigned int)(p2_y - v2),
v5,
0LL,
0LL);
for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
if ( (unsigned int)read_pixel(proj1_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL)
&& (unsigned int)read_pixel(proj2_vid, j, i) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
return 1LL;
}
}
}
result = 0LL;
}
return result;
}

original_code:
int starcrus_collision_check_p1p2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = p1_x;
 org_y = p1_y;
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_p1p2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = p1_x;
 org_y = p1_y;
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
   }
        }
    }
    return 0;
}

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


decompiled_code:
__int64 starcrus_collision_check_s1p1p2()
{
__int64 result; // rax
int v1; // ebp
int v2; // er12
unsigned int v3; // ebp
unsigned int i; // ebx
int v5[14]; // [rsp+30h] [rbp-38h] BYREF

result = ((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8;
if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) != 0 )
{
v5[0] = 0;
v5[1] = 15;
v5[2] = 0;
v5[3] = 15;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v1 = s1_x;
v2 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v1),
(unsigned int)(p1_y - v2),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v1),
(unsigned int)(p2_y - v2),
v5,
0LL,
0LL);
v3 = 0;
while ( 2 )
{
for ( i = 0; i != 16; ++i )
{
if ( (unsigned int)read_pixel(ship1_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
if ( (unsigned int)read_pixel(proj1_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
if ( (unsigned int)read_pixel(proj2_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
}
}
if ( ++v3 != 16 )
continue;
break;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
int v1; // ebp
int v2; // er12
unsigned int v3; // ebp
unsigned int i; // ebx
int v5[14]; // [rsp+30h] [rbp-38h] BYREF

result = ((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8;
if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) != 0 )
{
v5[0] = 0;
v5[1] = 15;
v5[2] = 0;
v5[3] = 15;
fillbitmap(ship1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v1 = s1_x;
v2 = s1_y;
drawgfx(
ship1_vid,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v1),
(unsigned int)(p1_y - v2),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v1),
(unsigned int)(p2_y - v2),
v5,
0LL,
0LL);
v3 = 0;
while ( 2 )
{
for ( i = 0; i != 16; ++i )
{
if ( (unsigned int)read_pixel(ship1_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
if ( (unsigned int)read_pixel(proj1_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
if ( (unsigned int)read_pixel(proj2_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
}
}
if ( ++v3 != 16 )
continue;
break;
}
result = 0LL;
}
return result;
}

original_code:
int starcrus_collision_check_s1p1p2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_s1p1p2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship1_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s1_x;
 org_y = s1_y;
    drawgfx(ship1_vid,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x-org_x,s1_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}


decompiled_code:
__int64 starcrus_collision_check_s2p1p2()
{
__int64 result; // rax
int v1; // ebp
int v2; // er12
unsigned int v3; // ebp
unsigned int i; // ebx
int v5[14]; // [rsp+30h] [rbp-38h] BYREF

result = ((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8;
if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) != 0 )
{
v5[0] = 0;
v5[1] = 15;
v5[2] = 0;
v5[3] = 15;
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v1 = s2_x;
v2 = s2_y;
drawgfx(
ship2_vid,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v1),
(unsigned int)(p1_y - v2),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v1),
(unsigned int)(p2_y - v2),
v5,
0LL,
0LL);
v3 = 0;
while ( 2 )
{
for ( i = 0; i != 16; ++i )
{
if ( (unsigned int)read_pixel(ship2_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
if ( (unsigned int)read_pixel(proj1_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
if ( (unsigned int)read_pixel(proj2_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
}
}
if ( ++v3 != 16 )
continue;
break;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax
int v1; // ebp
int v2; // er12
unsigned int v3; // ebp
unsigned int i; // ebx
int v5[14]; // [rsp+30h] [rbp-38h] BYREF

result = ((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8;
if ( (((unsigned __int8)p2_sprite | (unsigned __int8)p1_sprite) & 8) != 0 )
{
v5[0] = 0;
v5[1] = 15;
v5[2] = 0;
v5[3] = 15;
fillbitmap(ship2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj1_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
fillbitmap(proj2_vid, **(unsigned __int16 **)(Machine + 792LL), v5);
v1 = s2_x;
v2 = s2_y;
drawgfx(
ship2_vid,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
0LL,
0LL,
v5,
0LL,
0LL);
if ( (p1_sprite & 8) != 0 )
drawgfx(
proj1_vid,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p1_x - v1),
(unsigned int)(p1_y - v2),
v5,
0LL,
0LL);
if ( (p2_sprite & 8) != 0 )
drawgfx(
proj2_vid,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)(p2_x - v1),
(unsigned int)(p2_y - v2),
v5,
0LL,
0LL);
v3 = 0;
while ( 2 )
{
for ( i = 0; i != 16; ++i )
{
if ( (unsigned int)read_pixel(ship2_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
{
if ( (unsigned int)read_pixel(proj1_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
if ( (unsigned int)read_pixel(proj2_vid, i, v3) == *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL) )
return 1LL;
}
}
if ( ++v3 != 16 )
continue;
break;
}
result = 0LL;
}
return result;
}

original_code:
int starcrus_collision_check_s2p1p2(void)
{
 int org_x, org_y;
 int sx, sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s2_x;
 org_y = s2_y;
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int starcrus_collision_check_s2p1p2()
{
 int org_x; int org_y;
 int sx; int sy;
 struct rectangle clip;
 if ( ((p1_sprite & 0x08) == 0) &&
         ((p2_sprite & 0x08) == 0) )
 {
  return 0;
 }
    clip.min_x=0;
    clip.max_x=15;
    clip.min_y=0;
    clip.max_y=15;
    fillbitmap(ship2_vid,Machine->pens[0],&clip);
    fillbitmap(proj1_vid,Machine->pens[0],&clip);
    fillbitmap(proj2_vid,Machine->pens[0],&clip);
 org_x = s2_x;
 org_y = s2_y;
    drawgfx(ship2_vid,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x-org_x,s2_y-org_y,
            &clip,
            TRANSPARENCY_NONE,
            0);
 if (p1_sprite & 0x08)
 {
  drawgfx(proj1_vid,
    Machine->gfx[(p1_sprite&0x0c)>>2],
    (p1_sprite&0x03)^0x03,
    0,
    0,0,
    p1_x-org_x,p1_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
 if (p2_sprite & 0x08)
 {
  drawgfx(proj2_vid,
    Machine->gfx[4+((p2_sprite&0x0c)>>2)],
    (p2_sprite&0x03)^0x03,
    0,
    0,0,
    p2_x-org_x,p2_y-org_y,
    &clip,
    TRANSPARENCY_NONE,
    0);
 }
    for (sy=0;sy<16;sy++)
    {
        for (sx=0;sx<16;sx++)
        {
         if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1])
            {
    if (read_pixel(proj1_vid, sx, sy)==Machine->pens[1])
                 return 1;
          if (read_pixel(proj2_vid, sx, sy)==Machine->pens[1])
                 return 1;
            }
        }
    }
    return 0;
}


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

fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
(unsigned int)s1_x,
(unsigned int)s1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
(unsigned int)s2_x,
(unsigned int)s2_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p1_x,
(unsigned int)p1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p2_x,
(unsigned int)p2_y,
Machine + 776LL,
2LL,
0LL);
collision_reg = 0;
if ( (unsigned int)starcrus_collision_check_s1s2() )
collision_reg |= 8u;
if ( (unsigned int)starcrus_collision_check_s1p1p2() )
collision_reg |= 2u;
if ( (unsigned int)starcrus_collision_check_s2p1p2() )
collision_reg |= 1u;
result = starcrus_collision_check_p1p2();
if ( (_DWORD)result )
collision_reg |= 4u;
return result;
}

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

fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s1_sprite >> 2) & 1) + 576),
~(_BYTE)s1_sprite & 3,
0LL,
(s1_sprite >> 3) & 1,
(s1_sprite >> 4) & 1,
(unsigned int)s1_x,
(unsigned int)s1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((s2_sprite >> 2) & 1) + 592),
~(_BYTE)s2_sprite & 3,
0LL,
(s2_sprite >> 3) & 1,
(s2_sprite >> 4) & 1,
(unsigned int)s2_x,
(unsigned int)s2_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p1_sprite >> 2) & 3) + 512),
~(_BYTE)p1_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p1_x,
(unsigned int)p1_y,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * ((p2_sprite >> 2) & 3) + 544),
~(_BYTE)p2_sprite & 3,
0LL,
0LL,
0LL,
(unsigned int)p2_x,
(unsigned int)p2_y,
Machine + 776LL,
2LL,
0LL);
collision_reg = 0;
if ( (unsigned int)func12() )
collision_reg |= 8u;
if ( (unsigned int)func14() )
collision_reg |= 2u;
if ( (unsigned int)func15() )
collision_reg |= 1u;
result = func13();
if ( (_DWORD)result )
collision_reg |= 4u;
return result;
}

original_code:
void starcrus_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
    drawgfx(bitmap,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x,s1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    drawgfx(bitmap,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x,s2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[(p1_sprite&0x0c)>>2],
            (p1_sprite&0x03)^0x03,
            0,
            0,0,
            p1_x,p1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[4+((p2_sprite&0x0c)>>2)],
            (p2_sprite&0x03)^0x03,
            0,
            0,0,
            p2_x,p2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    collision_reg = 0x00;
    if (starcrus_collision_check_s1s2())
    {
        collision_reg |= 0x08;
    }
    if (starcrus_collision_check_s1p1p2())
    {
        collision_reg |= 0x02;
    }
    if (starcrus_collision_check_s2p1p2())
    {
        collision_reg |= 0x01;
    }
    if (starcrus_collision_check_p1p2())
    {
        collision_reg |= 0x04;
    }
}

canonical_original_code:
void starcrus_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
    drawgfx(bitmap,
            Machine->gfx[8+((s1_sprite&0x04)>>2)],
            (s1_sprite&0x03)^0x03,
            0,
            (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4,
            s1_x,s1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    drawgfx(bitmap,
            Machine->gfx[10+((s2_sprite&0x04)>>2)],
            (s2_sprite&0x03)^0x03,
            0,
            (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4,
            s2_x,s2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[(p1_sprite&0x0c)>>2],
            (p1_sprite&0x03)^0x03,
            0,
            0,0,
            p1_x,p1_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
 drawgfx(bitmap,
            Machine->gfx[4+((p2_sprite&0x0c)>>2)],
            (p2_sprite&0x03)^0x03,
            0,
            0,0,
            p2_x,p2_y,
            &Machine->visible_area,
            TRANSPARENCY_PEN,
            0);
    collision_reg = 0x00;
    if (starcrus_collision_check_s1s2())
    {
        collision_reg |= 0x08;
    }
    if (starcrus_collision_check_s1p1p2())
    {
        collision_reg |= 0x02;
    }
    if (starcrus_collision_check_s2p1p2())
    {
        collision_reg |= 0x01;
    }
    if (starcrus_collision_check_p1p2())
    {
        collision_reg |= 0x04;
    }
}

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


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

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

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

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


decompiled_code:
__int64 omegrace_spinner1_r()
{
return spinnerTable[readinputport(4LL) & 0x3F];
}

canonical_decompiled_code:
__int64 func1()
{
return spinnerTable[readinputport(4LL) & 0x3F];
}

original_code:
data_t omegrace_spinner1_r(offs_t offset)
{
 int res;
 res=readinputport(4);
 return (spinnerTable[res&0x3f]);
}

canonical_original_code:
unsigned int omegrace_spinner1_r(unsigned int offset)
{
 int res;
 res=readinputport(4);
 return (spinnerTable[res&0x3f]);
}

variable_types: res int


decompiled_code:
__int64 __fastcall omegrace_leds_w(__int64 a1, int a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
osd_led_w(0LL, (unsigned int)~a2 >> 2);
return osd_led_w(1LL, (unsigned int)~a2 >> 3);
}

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

original_code:
void omegrace_leds_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
 osd_led_w(0,~data >> 2);
 osd_led_w(1,~data >> 3);
}

canonical_original_code:
void omegrace_leds_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
 osd_led_w(0,~data >> 2);
 osd_led_w(1,~data >> 3);
}


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

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

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

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


decompiled_code:
__int64 omegrace_init_machine()
{
return avgdvg_reset_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func5()
{
return avgdvg_reset_w(0LL, 0LL);
}

original_code:
static void omegrace_init_machine(void)
{
 avgdvg_reset_w (0, 0);
}

canonical_original_code:
static void omegrace_init_machine()
{
 avgdvg_reset_w (0, 0);
}


decompiled_code:
__int64 omegrace_vg_status_r()
{
return (unsigned __int8)((unsigned int)avgdvg_done() == 0) << 7;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned __int8)((unsigned int)avgdvg_done() == 0) << 7;
}

original_code:
static data_t omegrace_vg_status_r(offs_t offset)
{
 if (avgdvg_done())
  return 0;
 else
  return 0x80;
}

canonical_original_code:
static unsigned int omegrace_vg_status_r(unsigned int offset)
{
 if (avgdvg_done())
  return 0;
 else
  return 0x80;
}


decompiled_code:
__int64 omegrace_vg_go_r()
{
avgdvg_go_w(0LL, 0LL);
return 0LL;
}

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

original_code:
static data_t omegrace_vg_go_r(offs_t offset)
{
 avgdvg_go_w(0,0);
 return 0;
}

canonical_original_code:
static unsigned int omegrace_vg_go_r(unsigned int offset)
{
 avgdvg_go_w(0,0);
 return 0;
}


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

variable_types:
file
void *


decompiled_code:
__int64 __fastcall get_txt_tile_info(int a1)
{
__int64 v1; // rsi
int v2; // ecx
int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 528LL);
v2 = *(unsigned __int16 *)(ginganin_txtram + 2 * a1);
v3 = (unsigned int)v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16) + 2LL * *(_DWORD *)(v1 + 12) * (v2 >> 12);
v4 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rsi
int v2; // ecx
int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 528LL);
v2 = *(unsigned __int16 *)(ginganin_txtram + 2 * a1);
v3 = (unsigned int)v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16) + 2LL * *(_DWORD *)(v1 + 12) * (v2 >> 12);
v4 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

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

variable_types: code int

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


decompiled_code:
void __fastcall MC6840_control_port_0_w(__int64 a1, char a2)
{
if ( a2 < 0 )
{
if ( S_TEMPO != (unsigned __int8)MC6840_register0 )
{
if ( MC6840_register0 )
S_TEMPO = (unsigned __int8)MC6840_register0;
}
MC6809_FLAG = 1;
}
else
{
MC6809_FLAG = 0;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
if ( a2 < 0 )
{
if ( S_TEMPO != (unsigned __int8)MC6840_register0 )
{
if ( MC6840_register0 )
S_TEMPO = (unsigned __int8)MC6840_register0;
}
MC6809_FLAG = 1;
}
else
{
MC6809_FLAG = 0;
}
}

original_code:
static void MC6840_control_port_0_w(offs_t offset,data_t data)
{
 MC6840_index0 = data;
 if (MC6840_index0 & 0x80) {
  if ((MC6840_register0 != S_TEMPO) && (MC6840_register0 != 0)) {
   S_TEMPO = MC6840_register0;
  }
  MC6809_FLAG = 1;
 } else {
  MC6809_FLAG = 0;
 }
}

canonical_original_code:
static void MC6840_control_port_0_w(unsigned int offset, unsigned int data)
{
 MC6840_index0 = data;
 if (MC6840_index0 & 0x80) {
  if ((MC6840_register0 != S_TEMPO) && (MC6840_register0 != 0)) {
   S_TEMPO = MC6840_register0;
  }
  MC6809_FLAG = 1;
 } else {
  MC6809_FLAG = 0;
 }
}


decompiled_code:
void MC6840_control_port_1_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
static void MC6840_control_port_1_w(offs_t offset,data_t data)
{
 MC6840_index1 = data;
}

canonical_original_code:
static void MC6840_control_port_1_w(unsigned int offset, unsigned int data)
{
 MC6840_index1 = data;
}


decompiled_code:
void __fastcall MC6840_write_port_0_w(__int64 a1, char a2)
{
MC6840_register0 = a2;
}

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

original_code:
static void MC6840_write_port_0_w(offs_t offset,data_t data)
{
 MC6840_register0 = data;
}

canonical_original_code:
static void MC6840_write_port_0_w(unsigned int offset, unsigned int data)
{
 MC6840_register0 = data;
}


decompiled_code:
void MC6840_write_port_1_w()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
static void MC6840_write_port_1_w(offs_t offset,data_t data)
{
 MC6840_register1 = data;
}

canonical_original_code:
static void MC6840_write_port_1_w(unsigned int offset, unsigned int data)
{
 MC6840_register1 = data;
}


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

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

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

canonical_original_code:
int ginganin_interrupt()
{
 return 1;
}


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

if ( S_TEMPO_OLD != S_TEMPO )
{
S_TEMPO_OLD = S_TEMPO;
MC6809_CTR = 0;
}
result = (unsigned int)MC6809_FLAG;
if ( MC6809_FLAG )
{
if ( S_TEMPO < MC6809_CTR )
{
MC6809_CTR = 0;
result = 1LL;
}
else
{
++MC6809_CTR;
result = 0LL;
}
}
return result;
}

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

if ( S_TEMPO_OLD != S_TEMPO )
{
S_TEMPO_OLD = S_TEMPO;
MC6809_CTR = 0;
}
result = (unsigned int)MC6809_FLAG;
if ( MC6809_FLAG )
{
if ( S_TEMPO < MC6809_CTR )
{
MC6809_CTR = 0;
result = 1LL;
}
else
{
++MC6809_CTR;
result = 0LL;
}
}
return result;
}

original_code:
int ginganin_sound_interrupt(void)
{
 if (S_TEMPO_OLD != S_TEMPO) {
  S_TEMPO_OLD = S_TEMPO;
  MC6809_CTR = 0;
 }
 if (MC6809_FLAG != 0) {
  if (MC6809_CTR > S_TEMPO) {
   MC6809_CTR = 0;
   return 1;
  } else {
   MC6809_CTR++;
  }
 }
 return 0;
}

canonical_original_code:
int ginganin_sound_interrupt()
{
 if (S_TEMPO_OLD != S_TEMPO) {
  S_TEMPO_OLD = S_TEMPO;
  MC6809_CTR = 0;
 }
 if (MC6809_FLAG != 0) {
  if (MC6809_CTR > S_TEMPO) {
   MC6809_CTR = 0;
   return 1;
  } else {
   MC6809_CTR++;
  }
 }
 return 0;
}


decompiled_code:
__int64 __fastcall ginganin_fgram_w(unsigned int a1, int a2)
{
__int16 *v2; // r9
__int16 v3; // cx
__int64 result; // rax

v2 = (__int16 *)(ginganin_fgram + a1);
v3 = *v2;
*v2 = a2 | *v2 & HIWORD(a2);
result = ginganin_fgram;
if ( v3 != *(_WORD *)(ginganin_fgram + a1) )
result = tilemap_mark_tile_dirty(fg_tilemap, a1 >> 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
__int16 *v2; // r9
__int16 v3; // cx
__int64 result; // rax

v2 = (__int16 *)(ginganin_fgram + a1);
v3 = *v2;
*v2 = a2 | *v2 & HIWORD(a2);
result = ginganin_fgram;
if ( v3 != *(_WORD *)(ginganin_fgram + a1) )
result = tilemap_mark_tile_dirty(fg_tilemap, a1 >> 1);
return result;
}

original_code:
void ginganin_fgram_w(offs_t offset,data_t data)
{
 int old_data, new_data;
 old_data = (*(UINT16 *)(&ginganin_fgram[offset]));
 ((*(UINT16 *)((&ginganin_fgram[offset])) = (((*(UINT16 *)(&ginganin_fgram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(UINT16 *)(&ginganin_fgram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(fg_tilemap,offset/2);
}

canonical_original_code:
void ginganin_fgram_w(unsigned int offset, unsigned int data)
{
 int old_data; int new_data;
 old_data = (*(unsigned short *)(&ginganin_fgram[offset]));
 ((*(unsigned short *)((&ginganin_fgram[offset])) = (((*(unsigned short *)(&ginganin_fgram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(unsigned short *)(&ginganin_fgram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(fg_tilemap,offset/2);
}


decompiled_code:
__int64 __fastcall ginganin_txtram_w(unsigned int a1, int a2)
{
__int16 *v2; // r9
__int16 v3; // cx
__int64 result; // rax

v2 = (__int16 *)(ginganin_txtram + a1);
v3 = *v2;
*v2 = a2 | *v2 & HIWORD(a2);
result = ginganin_txtram;
if ( v3 != *(_WORD *)(ginganin_txtram + a1) )
result = tilemap_mark_tile_dirty(tx_tilemap, a1 >> 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
__int16 *v2; // r9
__int16 v3; // cx
__int64 result; // rax

v2 = (__int16 *)(ginganin_txtram + a1);
v3 = *v2;
*v2 = a2 | *v2 & HIWORD(a2);
result = ginganin_txtram;
if ( v3 != *(_WORD *)(ginganin_txtram + a1) )
result = tilemap_mark_tile_dirty(tx_tilemap, a1 >> 1);
return result;
}

original_code:
void ginganin_txtram_w(offs_t offset,data_t data)
{
int old_data, new_data;
 old_data = (*(UINT16 *)(&ginganin_txtram[offset]));
 ((*(UINT16 *)((&ginganin_txtram[offset])) = (((*(UINT16 *)(&ginganin_txtram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(UINT16 *)(&ginganin_txtram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(tx_tilemap,offset/2);
}

canonical_original_code:
void ginganin_txtram_w(unsigned int offset, unsigned int data)
{
int old_data; int new_data;
 old_data = (*(unsigned short *)(&ginganin_txtram[offset]));
 ((*(unsigned short *)((&ginganin_txtram[offset])) = (((*(unsigned short *)(&ginganin_txtram[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(unsigned short *)(&ginganin_txtram[offset]));
 if (old_data != new_data)
  tilemap_mark_tile_dirty(tx_tilemap,offset/2);
}


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

bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 16LL, 16LL, 512LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 256LL, v2);
LODWORD(v3) = 32;
v0 = tilemap_create(get_txt_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
tx_tilemap = v0;
if ( !fg_tilemap )
return 1LL;
if ( !bg_tilemap || !v0 )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

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

bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 16LL, 16LL, 512LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 256LL, v2);
LODWORD(v3) = 32;
v0 = tilemap_create(get_txt_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
tx_tilemap = v0;
if ( !fg_tilemap )
return 1LL;
if ( !bg_tilemap || !v0 )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

original_code:
int ginganin_vh_start(void)
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x00,16,16,(16*32),(16*2));
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,16,16,(16*16),(16*2));
 tx_tilemap = tilemap_create(get_txt_tile_info,tilemap_scan_rows,0x01,8,8,(32),(32));
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 15;
 tx_tilemap->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int ginganin_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x00,16,16,(16*32),(16*2));
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,16,16,(16*16),(16*2));
 tx_tilemap = tilemap_create(get_txt_tile_info,tilemap_scan_rows,0x01,8,8,(32),(32));
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 15;
 tx_tilemap->transparent_pen = 15;
 return 0;
}


decompiled_code:
__int64 __fastcall ginganin_vregs_w(unsigned int a1, int a2)
{
__int64 result; // rax
unsigned __int16 v3; // si

*(_WORD *)(ginganin_vregs + a1) = a2 | *(_WORD *)(ginganin_vregs + a1) & HIWORD(a2);
result = ginganin_vregs;
v3 = *(_WORD *)(ginganin_vregs + a1);
switch ( a1 )
{
case 0u:
result = tilemap_set_scrolly(fg_tilemap, 0LL, v3);
break;
case 2u:
result = tilemap_set_scrollx(fg_tilemap, 0LL, v3);
break;
case 4u:
result = tilemap_set_scrolly(bg_tilemap, 0LL, v3);
break;
case 6u:
result = tilemap_set_scrollx(bg_tilemap, 0LL, v3);
break;
case 8u:
layers_ctrl = v3;
break;
case 0xCu:
flipscreen = (*(_WORD *)(ginganin_vregs + a1) & 1) == 0;
result = tilemap_set_flip(0LL, (v3 & 1) == 0 ? 3 : 0, a1, v3);
break;
case 0xEu:
soundlatch_w(0LL, v3, a1, v3);
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, int a2)
{
__int64 result; // rax
unsigned __int16 v3; // si

*(_WORD *)(ginganin_vregs + a1) = a2 | *(_WORD *)(ginganin_vregs + a1) & HIWORD(a2);
result = ginganin_vregs;
v3 = *(_WORD *)(ginganin_vregs + a1);
switch ( a1 )
{
case 0u:
result = tilemap_set_scrolly(fg_tilemap, 0LL, v3);
break;
case 2u:
result = tilemap_set_scrollx(fg_tilemap, 0LL, v3);
break;
case 4u:
result = tilemap_set_scrolly(bg_tilemap, 0LL, v3);
break;
case 6u:
result = tilemap_set_scrollx(bg_tilemap, 0LL, v3);
break;
case 8u:
layers_ctrl = v3;
break;
case 0xCu:
flipscreen = (*(_WORD *)(ginganin_vregs + a1) & 1) == 0;
result = tilemap_set_flip(0LL, (v3 & 1) == 0 ? 3 : 0, a1, v3);
break;
case 0xEu:
soundlatch_w(0LL, v3, a1, v3);
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

original_code:
void ginganin_vregs_w(offs_t offset,data_t data)
{
 int new_data;
 ((*(UINT16 *)((&ginganin_vregs[offset])) = (((*(UINT16 *)(&ginganin_vregs[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(UINT16 *)(&ginganin_vregs[offset]));
 switch (offset)
 {
  case 0x0 : { tilemap_set_scrolly(fg_tilemap, 0, new_data); } break;
  case 0x2 : { tilemap_set_scrollx(fg_tilemap, 0, new_data); } break;
  case 0x4 : { tilemap_set_scrolly(bg_tilemap, 0, new_data); } break;
  case 0x6 : { tilemap_set_scrollx(bg_tilemap, 0, new_data); } break;
  case 0x8 : { layers_ctrl = new_data; } break;
  case 0xc : { flipscreen = !(new_data & 1); tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0); } break;
  case 0xe : { soundlatch_w(0,new_data);
      cpu_cause_interrupt(1,4);
       } break;
  default :
      break;
 }
}

canonical_original_code:
void ginganin_vregs_w(unsigned int offset, unsigned int data)
{
 int new_data;
 ((*(unsigned short *)((&ginganin_vregs[offset])) = (((*(unsigned short *)(&ginganin_vregs[offset])) & ((data) >> 16)) | (data))));
 new_data = (*(unsigned short *)(&ginganin_vregs[offset]));
 switch (offset)
 {
  case 0x0 : { tilemap_set_scrolly(fg_tilemap, 0, new_data); } break;
  case 0x2 : { tilemap_set_scrollx(fg_tilemap, 0, new_data); } break;
  case 0x4 : { tilemap_set_scrolly(bg_tilemap, 0, new_data); } break;
  case 0x6 : { tilemap_set_scrollx(bg_tilemap, 0, new_data); } break;
  case 0x8 : { layers_ctrl = new_data; } break;
  case 0xc : { flipscreen = !(new_data & 1); tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0); } break;
  case 0xe : { soundlatch_w(0,new_data);
      cpu_cause_interrupt(1,4);
       } break;
  default :
      break;
 }
}


decompiled_code:
__int64 init_ginganin()
{
__int64 v0; // rax
_QWORD *v1; // rax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v0 = memory_region(129LL);
*(_WORD *)(v0 + 1032) = 24576;
*(_WORD *)(v0 + 1034) = 28;
v1 = (_QWORD *)memory_region(130LL);
*v1 = 0LL;
v1[255] = 0LL;
v2 = (void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)((_DWORD)v1 - (_DWORD)v2 + 2048) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
_QWORD *v1; // rax
void *v2; // rdi
unsigned int v3; // ecx
__int64 result; // rax

v0 = memory_region(129LL);
*(_WORD *)(v0 + 1032) = 24576;
*(_WORD *)(v0 + 1034) = 28;
v1 = (_QWORD *)memory_region(130LL);
*v1 = 0LL;
v1[255] = 0LL;
v2 = (void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL);
v3 = (unsigned int)((_DWORD)v1 - (_DWORD)v2 + 2048) >> 3;
result = 0LL;
memset(v2, 0, 8LL * v3);
return result;
}

original_code:
void init_ginganin(void)
{
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 (*(UINT16 *)(&RAM[0x408]) = (0x6000)); (*(UINT16 *)(&RAM[0x40a]) = (0x001c));
 RAM = memory_region(REGION_CPU2);
 memset (&RAM[0],0,0x800);
}

canonical_original_code:
void init_ginganin()
{
 unsigned char *RAM;
 RAM = memory_region(REGION_CPU1);
 (*(unsigned short *)(&RAM[0x408]) = (0x6000)); (*(unsigned short *)(&RAM[0x40a]) = (0x001c));
 RAM = memory_region(REGION_CPU2);
 memset (&RAM[0],0,0x800);
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rsi
int v2; // ecx
int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 520LL);
v2 = *(unsigned __int16 *)(ginganin_fgram + 2 * a1);
v3 = (unsigned int)v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16) + 2LL * *(_DWORD *)(v1 + 12) * (v2 >> 12);
v4 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

v1 = *(_QWORD *)(Machine + 520LL);
v2 = *(unsigned __int16 *)(ginganin_fgram + 2 * a1);
v3 = (unsigned int)v2 % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16) + 2LL * *(_DWORD *)(v1 + 12) * (v2 >> 12);
v4 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

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

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


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

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

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rbx
int v2; // ebp
int v3; // ecx
__int64 v4; // rsi
int v5; // edx
__int64 v6; // rcx
__int64 result; // rax

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

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

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


decompiled_code:
__int64 __fastcall convert_point(unsigned int a1, int a2, _QWORD *a3, _DWORD *a4)
{
unsigned int v4; // eax
__int64 result; // rax

v4 = (a1 >> 2) + (a2 << 6) - 1536;
if ( (a1 & 2) != 0 )
*a3 = cloud9_vram2 + v4;
else
*a3 = videoram + v4;
if ( (a1 & 1) != 0 )
{
result = *(_BYTE *)*a3 >> 4;
*a4 = (unsigned __int8)result;
}
else
{
result = *(_BYTE *)*a3 & 0xF;
*a4 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, _QWORD *a3, _DWORD *a4)
{
unsigned int v4; // eax
__int64 result; // rax

v4 = (a1 >> 2) + (a2 << 6) - 1536;
if ( (a1 & 2) != 0 )
*a3 = cloud9_vram2 + v4;
else
*a3 = videoram + v4;
if ( (a1 & 1) != 0 )
{
result = *(_BYTE *)*a3 >> 4;
*a4 = (unsigned __int8)result;
}
else
{
result = *(_BYTE *)*a3 & 0xF;
*a4 = result;
}
return result;
}

original_code:
static void convert_point(unsigned int x, unsigned int y, unsigned char **vptr, int *vpixel)
{
 unsigned int voff;
 voff = (y << 6) + (x >> 2) - 0x600;
 switch (x & 0x02)
 {
 case 0x00:
  *vptr = &(videoram[voff]);
  break;
 case 0x02:
  *vptr = &(cloud9_vram2[voff]);
  break;
 }
 switch (x & 0x01)
 {
 case 0x00:
  *vpixel = (**vptr & 0x0f) >> 0;
  break;
 case 0x01:
  *vpixel = (**vptr & 0xf0) >> 4;
  break;
 }
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
vptr
unsigned char **

variable_types:
vpixel
int *

variable_types:
voff
unsigned int


decompiled_code:
__int64 __fastcall cloud9_bitmap_regs_r(int a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+0h] [rbp-Ch] BYREF
__int64 v3; // [rsp+4h] [rbp-8h] BYREF

result = (unsigned __int8)cloud9_bitmap_regs[1];
if ( a1 != 1 )
{
if ( a1 == 2 )
{
if ( (unsigned int)result > 0xB )
{
convert_point((unsigned __int8)*cloud9_bitmap_regs, (unsigned __int8)cloud9_bitmap_regs[1], &v3, &v2);
result = v2;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
if ( !a1 )
result = (unsigned __int8)*cloud9_bitmap_regs;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+0h] [rbp-Ch] BYREF
__int64 v3; // [rsp+4h] [rbp-8h] BYREF

result = (unsigned __int8)cloud9_bitmap_regs[1];
if ( a1 != 1 )
{
if ( a1 == 2 )
{
if ( (unsigned int)result > 0xB )
{
func0((unsigned __int8)*cloud9_bitmap_regs, (unsigned __int8)cloud9_bitmap_regs[1], &v3, &v2);
result = v2;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
if ( !a1 )
result = (unsigned __int8)*cloud9_bitmap_regs;
}
}
return result;
}

original_code:
data_t cloud9_bitmap_regs_r(offs_t offset)
{
 unsigned char *vptr;
 int vpixel;
 unsigned int x, y;
 x = cloud9_bitmap_regs[0];
 y = cloud9_bitmap_regs[1];
 switch (offset)
 {
 case 0:
  return x;
 case 1:
  return y;
 case 2:
  if (y < 0x0c)
  {
   return 0;
  }
  convert_point(x,y,&vptr,&vpixel);
  return vpixel;
 }
 return 0;
}

canonical_original_code:
unsigned int cloud9_bitmap_regs_r(unsigned int offset)
{
 unsigned char *vptr;
 int vpixel;
 unsigned int x; unsigned int y;
 x = cloud9_bitmap_regs[0];
 y = cloud9_bitmap_regs[1];
 switch (offset)
 {
 case 0:
  return x;
 case 1:
  return y;
 case 2:
  if (y < 0x0c)
  {
   return 0;
  }
  convert_point(x,y,&vptr,&vpixel);
  return vpixel;
 }
 return 0;
}

variable_types:
vptr
unsigned char *

variable_types: vpixel int


decompiled_code:
unsigned __int64 __fastcall cloud9_bitmap_regs_w(unsigned int a1, char a2)
{
unsigned __int64 result; // rax
unsigned __int8 v3; // r12
unsigned __int8 v4; // bp
int v5; // [rsp+0h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+4h] [rbp-20h] BYREF

result = a1;
cloud9_bitmap_regs[a1] = a2;
if ( a1 == 2 )
{
v3 = *cloud9_bitmap_regs;
v4 = cloud9_bitmap_regs[1];
if ( v4 > 0xBu )
{
convert_point(v3, v4, v6, &v5);
if ( (v3 & 1) != 0 )
*(_BYTE *)v6[0] = (16 * a2) | *(_BYTE *)v6[0] & 0xF;
else
*(_BYTE *)v6[0] = a2 & 0xF | *(_BYTE *)v6[0] & 0xF0;
}
plot_pixel(
tmpbitmap,
v3,
v4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20 | a2 & 0xFu)));
if ( (char)*cloud9_auto_inc_x >= 0 )
++*cloud9_bitmap_regs;
result = (unsigned __int64)cloud9_auto_inc_y;
if ( (char)*cloud9_auto_inc_y >= 0 )
{
result = (unsigned __int64)cloud9_bitmap_regs;
++cloud9_bitmap_regs[1];
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, char a2)
{
unsigned __int64 result; // rax
unsigned __int8 v3; // r12
unsigned __int8 v4; // bp
int v5; // [rsp+0h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+4h] [rbp-20h] BYREF

result = a1;
cloud9_bitmap_regs[a1] = a2;
if ( a1 == 2 )
{
v3 = *cloud9_bitmap_regs;
v4 = cloud9_bitmap_regs[1];
if ( v4 > 0xBu )
{
func0(v3, v4, v6, &v5);
if ( (v3 & 1) != 0 )
*(_BYTE *)v6[0] = (16 * a2) | *(_BYTE *)v6[0] & 0xF;
else
*(_BYTE *)v6[0] = a2 & 0xF | *(_BYTE *)v6[0] & 0xF0;
}
plot_pixel(
tmpbitmap,
v3,
v4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20 | a2 & 0xFu)));
if ( (char)*cloud9_auto_inc_x >= 0 )
++*cloud9_bitmap_regs;
result = (unsigned __int64)cloud9_auto_inc_y;
if ( (char)*cloud9_auto_inc_y >= 0 )
{
result = (unsigned __int64)cloud9_bitmap_regs;
++cloud9_bitmap_regs[1];
}
}
return result;
}

original_code:
void cloud9_bitmap_regs_w(offs_t offset,data_t data)
{
 unsigned int x, y;
 cloud9_bitmap_regs[offset] = data;
 x = cloud9_bitmap_regs[0];
 y = cloud9_bitmap_regs[1];
 if (offset == 2)
 {
  if (y >= 0x0c)
  {
   unsigned char *vptr;
   int vpixel;
   convert_point(x,y,&vptr,&vpixel);
   switch (x & 0x01)
   {
   case 0x00:
    *vptr = (*vptr & 0xf0) | ((data & 0x0f) << 0);
    break;
   case 0x01:
    *vptr = (*vptr & 0x0f) | ((data & 0x0f) << 4);
    break;
   }
  }
  plot_pixel(tmpbitmap, x, y, Machine->pens[(data & 0x0f) + ((*cloud9_color_bank & 0x80) >> 2)]);
  if ((*cloud9_auto_inc_x) < 0x80)
   cloud9_bitmap_regs[0]++;
  if ((*cloud9_auto_inc_y) < 0x80)
   cloud9_bitmap_regs[1]++;
 }
}

canonical_original_code:
void cloud9_bitmap_regs_w(unsigned int offset, unsigned int data)
{
 unsigned int x; unsigned int y;
 cloud9_bitmap_regs[offset] = data;
 x = cloud9_bitmap_regs[0];
 y = cloud9_bitmap_regs[1];
 if (offset == 2)
 {
  if (y >= 0x0c)
  {
   unsigned char *vptr;
   int vpixel;
   convert_point(x,y,&vptr,&vpixel);
   switch (x & 0x01)
   {
   case 0x00:
    *vptr = (*vptr & 0xf0) | ((data & 0x0f) << 0);
    break;
   case 0x01:
    *vptr = (*vptr & 0x0f) | ((data & 0x0f) << 4);
    break;
   }
  }
  plot_pixel(tmpbitmap, x, y, Machine->pens[(data & 0x0f) + ((*cloud9_color_bank & 0x80) >> 2)]);
  if ((*cloud9_auto_inc_x) < 0x80)
   cloud9_bitmap_regs[0]++;
  if ((*cloud9_auto_inc_y) < 0x80)
   cloud9_bitmap_regs[1]++;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall cloud9_bitmap_w(unsigned int a1, unsigned __int8 a2)
{
unsigned int v2; // ebp
unsigned __int8 v3; // r12
__int64 result; // rax
int v5; // ebx
int v6; // [rsp+Ch] [rbp-3Ch]

v2 = (a1 + 1536) >> 6;
v3 = 4 * a1;
if ( (char)*cloud9_both_banks < 0 )
{
*(_BYTE *)(videoram + a1) = a2;
*(_BYTE *)(cloud9_vram2 + a1) = a2;
v6 = a2 & 0xF;
plot_pixel(
tmpbitmap,
v3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (v6 | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
v5 = a2 >> 4;
plot_pixel(
tmpbitmap,
(unsigned int)v3 + 1,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (v5 | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
plot_pixel(
tmpbitmap,
(unsigned int)v3 + 2,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (v6 | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
result = plot_pixel(
tmpbitmap,
(unsigned int)v3 + 3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20 | (unsigned int)v5)));
}
else if ( (char)*cloud9_vram_bank < 0 )
{
*(_BYTE *)(cloud9_vram2 + a1) = a2;
plot_pixel(
tmpbitmap,
(unsigned int)v3 + 2,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (a2 & 0xF | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
result = plot_pixel(
tmpbitmap,
(unsigned int)v3 + 3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * ((a2 >> 4) | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
}
else
{
*(_BYTE *)(videoram + a1) = a2;
plot_pixel(
tmpbitmap,
v3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (a2 & 0xF | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
result = plot_pixel(
tmpbitmap,
(unsigned int)v3 + 1,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20 | (unsigned int)(a2 >> 4))));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned __int8 a2)
{
unsigned int v2; // ebp
unsigned __int8 v3; // r12
__int64 result; // rax
int v5; // ebx
int v6; // [rsp+Ch] [rbp-3Ch]

v2 = (a1 + 1536) >> 6;
v3 = 4 * a1;
if ( (char)*cloud9_both_banks < 0 )
{
*(_BYTE *)(videoram + a1) = a2;
*(_BYTE *)(cloud9_vram2 + a1) = a2;
v6 = a2 & 0xF;
plot_pixel(
tmpbitmap,
v3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (v6 | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
v5 = a2 >> 4;
plot_pixel(
tmpbitmap,
(unsigned int)v3 + 1,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (v5 | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
plot_pixel(
tmpbitmap,
(unsigned int)v3 + 2,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (v6 | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
result = plot_pixel(
tmpbitmap,
(unsigned int)v3 + 3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20 | (unsigned int)v5)));
}
else if ( (char)*cloud9_vram_bank < 0 )
{
*(_BYTE *)(cloud9_vram2 + a1) = a2;
plot_pixel(
tmpbitmap,
(unsigned int)v3 + 2,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (a2 & 0xF | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
result = plot_pixel(
tmpbitmap,
(unsigned int)v3 + 3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * ((a2 >> 4) | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
}
else
{
*(_BYTE *)(videoram + a1) = a2;
plot_pixel(
tmpbitmap,
v3,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (a2 & 0xF | ((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20u)));
result = plot_pixel(
tmpbitmap,
(unsigned int)v3 + 1,
(unsigned __int8)v2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (((int)(unsigned __int8)*cloud9_color_bank >> 2) & 0x20 | (unsigned int)(a2 >> 4))));
}
return result;
}

original_code:
void cloud9_bitmap_w(offs_t offset,data_t data)
{
 UINT8 x, y;
 y = ((offset + 0x600) >> 6);
 x = ((offset + 0x600) & 0x3f) << 2;
 if (*cloud9_both_banks & 0x80)
 {
  videoram[offset] = data;
  cloud9_vram2[offset] = data;
  plot_pixel(tmpbitmap, x, y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+1, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+2, y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+3, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
 }
 else if (*cloud9_vram_bank & 0x80)
 {
  cloud9_vram2[offset] = data;
  plot_pixel(tmpbitmap, x+2, y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+3, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
 }
 else
 {
  videoram[offset] = data;
  plot_pixel(tmpbitmap, x , y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+1, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
 }
}

canonical_original_code:
void cloud9_bitmap_w(unsigned int offset, unsigned int data)
{
 unsigned char x; unsigned char y;
 y = ((offset + 0x600) >> 6);
 x = ((offset + 0x600) & 0x3f) << 2;
 if (*cloud9_both_banks & 0x80)
 {
  videoram[offset] = data;
  cloud9_vram2[offset] = data;
  plot_pixel(tmpbitmap, x, y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+1, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+2, y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+3, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
 }
 else if (*cloud9_vram_bank & 0x80)
 {
  cloud9_vram2[offset] = data;
  plot_pixel(tmpbitmap, x+2, y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+3, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
 }
 else
 {
  videoram[offset] = data;
  plot_pixel(tmpbitmap, x , y, Machine->pens[((data & 0x0f) >> 0) + ((*cloud9_color_bank & 0x80) >> 2)]);
  plot_pixel(tmpbitmap, x+1, y, Machine->pens[((data & 0xf0) >> 4) + ((*cloud9_color_bank & 0x80) >> 2)]);
 }
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char


decompiled_code:
void cloud9_led_w()
{
;
}

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

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


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

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

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: blue int


decompiled_code:
__int64 __fastcall cloud9_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

if ( palette_recalc() )
redraw_bitmap();
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 0LL; i != 20; ++i )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + i + 32),
(((int)(unsigned __int8)*cloud9_color_bank >> 6) & 2u) + 1,
*(_BYTE *)(spriteram + i + 64) & 0x80,
*(_BYTE *)(spriteram + i + 64) & 0x40,
*(unsigned __int8 *)(spriteram + i + 96),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + i),
Machine + 776LL,
2LL,
0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

if ( palette_recalc() )
func4();
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 0LL; i != 20; ++i )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + i + 32),
(((int)(unsigned __int8)*cloud9_color_bank >> 6) & 2u) + 1,
*(_BYTE *)(spriteram + i + 64) & 0x80,
*(_BYTE *)(spriteram + i + 64) & 0x40,
*(unsigned __int8 *)(spriteram + i + 96),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + i),
Machine + 776LL,
2LL,
0LL);
return result;
}

original_code:
void cloud9_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
 {
  redraw_bitmap();
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < 20;offs++)
 {
  int spritenum;
  int xflip,yflip,rblank,lblank;
  int x, y;
  spritenum = spriteram[offs + 0x20];
  xflip = (spriteram[offs + 0x40] & 0x80);
  yflip = (spriteram[offs + 0x40] & 0x40);
  rblank = (spriteram[offs + 0x40] & 0x20);
  lblank = (spriteram[offs + 0x40] & 0x10);
  x = spriteram[offs + 0x60];
  y = 240 - spriteram[offs];
  drawgfx(bitmap,Machine->gfx[2],
    spritenum,
    1 + ((*cloud9_color_bank & 0x80) >> 6),
    xflip,yflip,
    x,y,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void cloud9_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
 {
  redraw_bitmap();
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < 20;offs++)
 {
  int spritenum;
  int xflip; int yflip; int rblank; int lblank;
  int x; int y;
  spritenum = spriteram[offs + 0x20];
  xflip = (spriteram[offs + 0x40] & 0x80);
  yflip = (spriteram[offs + 0x40] & 0x40);
  rblank = (spriteram[offs + 0x40] & 0x20);
  lblank = (spriteram[offs + 0x40] & 0x10);
  x = spriteram[offs + 0x60];
  y = 240 - spriteram[offs];
  drawgfx(bitmap,Machine->gfx[2],
    spritenum,
    1 + ((*cloud9_color_bank & 0x80) >> 6),
    xflip,yflip,
    x,y,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: spritenum int

variable_types: xflip int

variable_types: yflip int

variable_types: rblank int

variable_types: lblank int

variable_types: x int

variable_types: y int


decompiled_code:
_BYTE *redraw_bitmap()
{
char v0; // r13
char v1; // r12
unsigned __int64 v2; // rbx
_BYTE *result; // rax

v0 = *cloud9_both_banks;
v1 = *cloud9_vram_bank;
*cloud9_both_banks = 0;
if ( videoram_size )
{
v2 = 0LL;
do
{
*cloud9_vram_bank = 0;
cloud9_bitmap_w(v2, *(_BYTE *)(videoram + v2));
*cloud9_vram_bank = 0x80;
cloud9_bitmap_w(v2, *(_BYTE *)(cloud9_vram2 + v2));
++v2;
}
while ( videoram_size > v2 );
}
*cloud9_both_banks = v0;
result = cloud9_vram_bank;
*cloud9_vram_bank = v1;
return result;
}

canonical_decompiled_code:
_BYTE *func4()
{
char v0; // r13
char v1; // r12
unsigned __int64 v2; // rbx
_BYTE *result; // rax

v0 = *cloud9_both_banks;
v1 = *cloud9_vram_bank;
*cloud9_both_banks = 0;
if ( videoram_size )
{
v2 = 0LL;
do
{
*cloud9_vram_bank = 0;
func3(v2, *(_BYTE *)(videoram + v2));
*cloud9_vram_bank = 0x80;
func3(v2, *(_BYTE *)(cloud9_vram2 + v2));
++v2;
}
while ( videoram_size > v2 );
}
*cloud9_both_banks = v0;
result = cloud9_vram_bank;
*cloud9_vram_bank = v1;
return result;
}

original_code:
static void redraw_bitmap(void)
{
 int offs;
 int cloud9_both_banks_save = *cloud9_both_banks;
 int cloud9_vram_bank_save = *cloud9_vram_bank;
 *cloud9_both_banks = 0;
 for (offs = 0; offs < videoram_size; offs++)
 {
  *cloud9_vram_bank = 0;
  cloud9_bitmap_w(offs, videoram[offs]);
  *cloud9_vram_bank = 0x80;
  cloud9_bitmap_w(offs, cloud9_vram2[offs]);
 }
 *cloud9_both_banks = cloud9_both_banks_save;
 *cloud9_vram_bank = cloud9_vram_bank_save;
}

canonical_original_code:
static void redraw_bitmap()
{
 int offs;
 int cloud9_both_banks_save = *cloud9_both_banks;
 int cloud9_vram_bank_save = *cloud9_vram_bank;
 *cloud9_both_banks = 0;
 for (offs = 0; offs < videoram_size; offs++)
 {
  *cloud9_vram_bank = 0;
  cloud9_bitmap_w(offs, videoram[offs]);
  *cloud9_vram_bank = 0x80;
  cloud9_bitmap_w(offs, cloud9_vram2[offs]);
 }
 *cloud9_both_banks = cloud9_both_banks_save;
 *cloud9_vram_bank = cloud9_vram_bank_save;
}


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

variable_types:
file
void *


original_code:
void kyugo_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;
 color_codes = color_prom;
}

canonical_original_code:
void kyugo_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;
 color_codes = color_prom;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall special_spriteram_r(unsigned int a1)
{
return *(_BYTE *)(spriteram_2 + a1) | 0xF0u;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return *(_BYTE *)(spriteram_2 + a1) | 0xF0u;
}

original_code:
static data_t special_spriteram_r(offs_t offset)
{
 return spriteram_2[offset] | 0xf0;
}

canonical_original_code:
static unsigned int special_spriteram_r(unsigned int offset)
{
 return spriteram_2[offset] | 0xf0;
}

variable_types:
offset
unsigned int


decompiled_code:
void *__fastcall kyugo_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 func4(__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 kyugo_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != (data & 0x01))
 {
  flipscreen = (data & 0x01);
  memset(dirtybuffer,1,videoram_size);
 }
}

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

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall kyugo_gfxctrl_w(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

kyugo_back_scrollY_hi = a2 & 1;
frontcolor = (a2 >> 5) & 1;
result = a2 >> 6;
if ( ((a2 & 0x40) != 0) != palbank )
{
palbank = (a2 & 0x40) != 0;
result = (__int64)memset(dirtybuffer, 1, videoram_size);
}
if ( (a2 & 0x9E) != 0 )
{
sprintf(v3, "%02x", a2);
result = usrintf_showmessage(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

kyugo_back_scrollY_hi = a2 & 1;
frontcolor = (a2 >> 5) & 1;
result = a2 >> 6;
if ( ((a2 & 0x40) != 0) != palbank )
{
palbank = (a2 & 0x40) != 0;
result = (__int64)memset(dirtybuffer, 1, videoram_size);
}
if ( (a2 & 0x9E) != 0 )
{
sprintf(v3, "%02x", a2);
result = usrintf_showmessage(v3);
}
return result;
}

original_code:
void kyugo_gfxctrl_w(offs_t offset,data_t data)
{
 kyugo_back_scrollY_hi = data & 0x01;
 frontcolor = (data & 0x20) >> 5;
 if (palbank != ((data & 0x40) >> 6))
 {
  palbank = (data & 0x40) >> 6;
  memset(dirtybuffer,1,videoram_size);
 }
if (data & 0x9e)
{
 char baf[40];
 sprintf(baf,"%02x",data);
 usrintf_showmessage(baf);
}
}

canonical_original_code:
void kyugo_gfxctrl_w(unsigned int offset, unsigned int data)
{
 kyugo_back_scrollY_hi = data & 0x01;
 frontcolor = (data & 0x20) >> 5;
 if (palbank != ((data & 0x40) >> 6))
 {
  palbank = (data & 0x40) >> 6;
  memset(dirtybuffer,1,videoram_size);
 }
if (data & 0x9e)
{
 char baf[40];
 sprintf(baf,"%02x",data);
 usrintf_showmessage(baf);
}
}

variable_types:
baf
char [40]


decompiled_code:
int *__fastcall kyugo_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int *result; // rax
int v4; // ebx
__int64 v5; // rbp
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
16 * palbank + (unsigned int)(*(_BYTE *)(colorram + v2) >> 4));
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v6 = -32 - ((unsigned __int8)*kyugo_back_scrollY_lo + ((unsigned __int8)kyugo_back_scrollY_hi << 8));
if ( flipscreen )
v7[0] = (unsigned __int8)*kyugo_back_scrollX;
else
v7[0] = -(unsigned __int8)*kyugo_back_scrollX;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v6, 1LL, v7, Machine + 776LL, 0LL, 0LL);
draw_sprites(a1);
result = &kyugo_videoram_size;
v4 = kyugo_videoram_size - 1;
if ( kyugo_videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(kyugo_videoram + v5),
frontcolor
+ 2
* (unsigned int)*(unsigned __int8 *)(color_codes
+ ((int)*(unsigned __int8 *)(kyugo_videoram + v5) >> 3)));
--v5;
--v4;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func7(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int *result; // rax
int v4; // ebx
__int64 v5; // rbp
int v6; // [rsp+8h] [rbp-30h] BYREF
int v7[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
16 * palbank + (unsigned int)(*(_BYTE *)(colorram + v2) >> 4));
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v6 = -32 - ((unsigned __int8)*kyugo_back_scrollY_lo + ((unsigned __int8)kyugo_back_scrollY_hi << 8));
if ( flipscreen )
v7[0] = (unsigned __int8)*kyugo_back_scrollX;
else
v7[0] = -(unsigned __int8)*kyugo_back_scrollX;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v6, 1LL, v7, Machine + 776LL, 0LL, 0LL);
func6(a1);
result = &kyugo_videoram_size;
v4 = kyugo_videoram_size - 1;
if ( kyugo_videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(kyugo_videoram + v5),
frontcolor
+ 2
* (unsigned int)*(unsigned __int8 *)(color_codes
+ ((int)*(unsigned __int8 *)(kyugo_videoram + v5) >> 3)));
--v5;
--v4;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void kyugo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for( offs = videoram_size - 1;offs >= 0;offs-- )
 {
  if ( dirtybuffer[offs] )
  {
   int sx,sy,tile,flipx,flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 64;
   sy = offs / 64;
   flipx = colorram[offs] & 0x04;
   flipy = colorram[offs] & 0x08;
   if (flipscreen)
   {
    sx = 63 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   tile = videoram[offs] + ( 256 * ( colorram[offs] & 3 ) );
   drawgfx( tmpbitmap, Machine->gfx[2],
     tile,
     ((colorram[offs] & 0xf0) >> 4) + (palbank << 4),
     flipx,flipy,
     8*sx, 8*sy,
     0,TRANSPARENCY_NONE, 0 );
  }
 }
 {
  int scrollx,scrolly;
  if (flipscreen)
  {
   scrollx = -32 - ( ( kyugo_back_scrollY_lo[0] ) + ( kyugo_back_scrollY_hi * 256 ) );
   scrolly = kyugo_back_scrollX[0];
  }
  else
  {
   scrollx = -32 - ( ( kyugo_back_scrollY_lo[0] ) + ( kyugo_back_scrollY_hi * 256 ) );
   scrolly = -kyugo_back_scrollX[0];
  }
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 draw_sprites(bitmap);
 for( offs = kyugo_videoram_size - 1;offs >= 0;offs-- )
 {
  int sx,sy,code;
  sx = offs % 64;
  sy = offs / 64;
  if (flipscreen)
  {
   sx = 35 - sx;
   sy = 31 - sy;
  }
  code = kyugo_videoram[offs];
  drawgfx( bitmap, Machine->gfx[0],
    code,
    2*color_codes[code/8] + frontcolor,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void kyugo_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for( offs = videoram_size - 1;offs >= 0;offs-- )
 {
  if ( dirtybuffer[offs] )
  {
   int sx; int sy; int tile; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 64;
   sy = offs / 64;
   flipx = colorram[offs] & 0x04;
   flipy = colorram[offs] & 0x08;
   if (flipscreen)
   {
    sx = 63 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   tile = videoram[offs] + ( 256 * ( colorram[offs] & 3 ) );
   drawgfx( tmpbitmap, Machine->gfx[2],
     tile,
     ((colorram[offs] & 0xf0) >> 4) + (palbank << 4),
     flipx,flipy,
     8*sx, 8*sy,
     0,TRANSPARENCY_NONE, 0 );
  }
 }
 {
  int scrollx; int scrolly;
  if (flipscreen)
  {
   scrollx = -32 - ( ( kyugo_back_scrollY_lo[0] ) + ( kyugo_back_scrollY_hi * 256 ) );
   scrolly = kyugo_back_scrollX[0];
  }
  else
  {
   scrollx = -32 - ( ( kyugo_back_scrollY_lo[0] ) + ( kyugo_back_scrollY_hi * 256 ) );
   scrolly = -kyugo_back_scrollX[0];
  }
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 draw_sprites(bitmap);
 for( offs = kyugo_videoram_size - 1;offs >= 0;offs-- )
 {
  int sx; int sy; int code;
  sx = offs % 64;
  sy = offs / 64;
  if (flipscreen)
  {
   sx = 35 - sx;
   sy = 31 - sy;
  }
  code = kyugo_videoram[offs];
  drawgfx( bitmap, Machine->gfx[0],
    code,
    2*color_codes[code/8] + frontcolor,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: sx int

variable_types: sy int

variable_types: tile int

variable_types: flipx int

variable_types: flipy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: code int

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


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

if ( (a2 & 1) != 0 )
result = cpu_set_reset_line(1LL, 0LL);
else
result = cpu_set_reset_line(1LL, 1LL);
return result;
}

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

if ( (a2 & 1) != 0 )
result = cpu_set_reset_line(1LL, 0LL);
else
result = cpu_set_reset_line(1LL, 1LL);
return result;
}

original_code:
static void sub_cpu_control_w(offs_t offset,data_t data)
{
 if (data & 1)
  cpu_set_reset_line(1,0);
 else
  cpu_set_reset_line(1,1);
}

canonical_original_code:
static void sub_cpu_control_w(unsigned int offset, unsigned int data)
{
 if (data & 1)
  cpu_set_reset_line(1,0);
 else
  cpu_set_reset_line(1,1);
}


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

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

original_code:
static data_t shared_ram_r(offs_t offset)
{
 return shared_ram[offset];
}

canonical_original_code:
static unsigned int shared_ram_r(unsigned int offset)
{
 return shared_ram[offset];
}


original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 unsigned char *spriteram_area1 = &spriteram[0x28];
 unsigned char *spriteram_area2 = &spriteram_2[0x28];
 unsigned char *spriteram_area3 = &kyugo_videoram[0x28];
 int n;
 for( n = 0; n < 12*2; n++ )
 {
  int offs,y,sy,sx,color;
  offs = 2*(n % 12) + 64*(n / 12);
  sx = spriteram_area3[offs+1] + 256 * (spriteram_area2[offs+1] & 1);
  if (sx > 320) sx -= 512;
  sy = 255 - spriteram_area1[offs];
  if (flipscreen) sy = 240 - sy;
  color = spriteram_area1[offs+1] & 0x1f;
  for (y = 0;y < 16;y++)
  {
   int attr2,code,flipx,flipy;
   attr2 = spriteram_area2[offs + 128*y];
   code = spriteram_area3[offs + 128*y];
   if (attr2 & 0x01) code += 512;
   if (attr2 & 0x02) code += 256;
   flipx = attr2 & 0x08;
   flipy = attr2 & 0x04;
   if (flipscreen)
   {
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx( bitmap, Machine->gfx[1],
      code,
      color,
      flipx,flipy,
      sx,flipscreen ? sy - 16*y : sy + 16*y,
      &Machine->visible_area,TRANSPARENCY_PEN, 0 );
   }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 unsigned char *spriteram_area1 = &spriteram[0x28];
 unsigned char *spriteram_area2 = &spriteram_2[0x28];
 unsigned char *spriteram_area3 = &kyugo_videoram[0x28];
 int n;
 for( n = 0; n < 12*2; n++ )
 {
  int offs; int y; int sy; int sx; int color;
  offs = 2*(n % 12) + 64*(n / 12);
  sx = spriteram_area3[offs+1] + 256 * (spriteram_area2[offs+1] & 1);
  if (sx > 320) sx -= 512;
  sy = 255 - spriteram_area1[offs];
  if (flipscreen) sy = 240 - sy;
  color = spriteram_area1[offs+1] & 0x1f;
  for (y = 0;y < 16;y++)
  {
   int attr2; int code; int flipx; int flipy;
   attr2 = spriteram_area2[offs + 128*y];
   code = spriteram_area3[offs + 128*y];
   if (attr2 & 0x01) code += 512;
   if (attr2 & 0x02) code += 256;
   flipx = attr2 & 0x08;
   flipy = attr2 & 0x04;
   if (flipscreen)
   {
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx( bitmap, Machine->gfx[1],
      code,
      color,
      flipx,flipy,
      sx,flipscreen ? sy - 16*y : sy + 16*y,
      &Machine->visible_area,TRANSPARENCY_PEN, 0 );
   }
 }
}

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

variable_types: n int

variable_types: offs int

variable_types: color int


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

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

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

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


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

if ( *(_BYTE *)mermaid_AY8910_enable )
AY8910_control_port_0_w();
result = mermaid_AY8910_enable;
if ( *(_BYTE *)(mermaid_AY8910_enable + 1) )
result = AY8910_control_port_1_w(a1, a2);
return result;
}

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

if ( *(_BYTE *)mermaid_AY8910_enable )
AY8910_control_port_0_w();
result = mermaid_AY8910_enable;
if ( *(_BYTE *)(mermaid_AY8910_enable + 1) )
result = AY8910_control_port_1_w(a1, a2);
return result;
}

original_code:
static void mermaid_AY8910_control_port_w(offs_t offset,data_t data)
{
 if (mermaid_AY8910_enable[0]) AY8910_control_port_0_w(offset, data);
 if (mermaid_AY8910_enable[1]) AY8910_control_port_1_w(offset, data);
}

canonical_original_code:
static void mermaid_AY8910_control_port_w(unsigned int offset, unsigned int data)
{
 if (mermaid_AY8910_enable[0]) AY8910_control_port_0_w(offset, data);
 if (mermaid_AY8910_enable[1]) AY8910_control_port_1_w(offset, data);
}


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

if ( *(_BYTE *)mermaid_AY8910_enable )
AY8910_write_port_0_w();
result = mermaid_AY8910_enable;
if ( *(_BYTE *)(mermaid_AY8910_enable + 1) )
result = AY8910_write_port_1_w(a1, a2);
return result;
}

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

if ( *(_BYTE *)mermaid_AY8910_enable )
AY8910_write_port_0_w();
result = mermaid_AY8910_enable;
if ( *(_BYTE *)(mermaid_AY8910_enable + 1) )
result = AY8910_write_port_1_w(a1, a2);
return result;
}

original_code:
static void mermaid_AY8910_write_port_w(offs_t offset,data_t data)
{
 if (mermaid_AY8910_enable[0]) AY8910_write_port_0_w(offset, data);
 if (mermaid_AY8910_enable[1]) AY8910_write_port_1_w(offset, data);
}

canonical_original_code:
static void mermaid_AY8910_write_port_w(unsigned int offset, unsigned int data)
{
 if (mermaid_AY8910_enable[0]) AY8910_write_port_0_w(offset, data);
 if (mermaid_AY8910_enable[1]) AY8910_write_port_1_w(offset, data);
}


decompiled_code:
__int64 __fastcall get_mid_tile_info(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(dcon_mid_data + 2 * a1);
v2 = *(_QWORD *)(Machine + 536LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

v1 = *(_WORD *)(dcon_mid_data + 2 * a1);
v2 = *(_QWORD *)(Machine + 536LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_mid_tile_info(int tile_index)
{
 int tile=(*(UINT16 *)(&dcon_mid_data[2*tile_index]));
 int color=(tile>>12)&0xf;
 tile&=0xfff;
 { const struct GfxElement *gfx = Machine->gfx[(3)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_mid_tile_info(int tile_index)
{
 int tile = (*(UINT16 *)(&dcon_mid_data[2*tile_index]));
 int color = (tile>>12)&0xf;
 tile&=0xfff;
 { struct GfxElement *gfx = Machine->gfx[(3)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

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