decompiled_code:
__int64 __fastcall draw_text(__int64 a1)
{
__int64 v2; // r12
__int64 i; // rbx
__int64 result; // rax
unsigned __int16 v5; // dx
int v6; // edi

v2 = Machine + 776LL;
for ( i = 0LL; i != 2048; i += 2LL )
{
result = colorram;
v5 = *(_WORD *)(colorram + i) & 0x3FF;
if ( v5 != 13 )
{
v6 = ((int)i >> 1) + 31;
if ( (int)i >> 1 >= 0 )
v6 = (int)i >> 1;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v5,
*(_WORD *)(colorram + i) >> 10,
0LL,
0LL,
8
* (((((unsigned int)((int)i >> 31) >> 27) + (unsigned __int8)((int)i >> 1)) & 0x1F)
- ((unsigned int)((int)i >> 31) >> 27)),
(unsigned int)(8 * (v6 >> 5)),
v2,
2LL,
3LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // r12
__int64 i; // rbx
__int64 result; // rax
unsigned __int16 v5; // dx
int v6; // edi

v2 = Machine + 776LL;
for ( i = 0LL; i != 2048; i += 2LL )
{
result = colorram;
v5 = *(_WORD *)(colorram + i) & 0x3FF;
if ( v5 != 13 )
{
v6 = ((int)i >> 1) + 31;
if ( (int)i >> 1 >= 0 )
v6 = (int)i >> 1;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v5,
*(_WORD *)(colorram + i) >> 10,
0LL,
0LL,
8
* (((((unsigned int)((int)i >> 31) >> 27) + (unsigned __int8)((int)i >> 1)) & 0x1F)
- ((unsigned int)((int)i >> 31) >> 27)),
(unsigned int)(8 * (v6 >> 5)),
v2,
2LL,
3LL);
}
}
return result;
}

original_code:
static void draw_text( struct osd_bitmap *bitmap ) {
    int offs;
    const struct rectangle *clip = &Machine->visible_area;
    for ( offs = 0; offs < 0x800; offs += 2 ) {
        unsigned short data = (*(UINT16 *)(&colorram[offs]));
        int tile_number = data&0x3ff;
        if ( tile_number != 0xd ) {
            int color = data>>10;
            int sx = 8 * ( ( offs >> 1 ) % 32 );
            int sy = 8 * ( ( offs >> 1 ) / 32 );
            drawgfx( bitmap,Machine->gfx[0],
                tile_number,
                color,
                0,0,
                sx,sy,
                clip,TRANSPARENCY_PEN,0x3);
        }
    }
}

canonical_original_code:
static void draw_text(struct osd_bitmap *bitmap) {
    int offs;
    struct rectangle *clip = &Machine->visible_area;
    for ( offs = 0; offs < 0x800; offs += 2 ) {
        unsigned short data = (*(UINT16 *)(&colorram[offs]));
        int tile_number = data&0x3ff;
        if ( tile_number != 0xd ) {
            int color = data>>10;
            int sx = 8 * ( ( offs >> 1 ) % 32 );
            int sy = 8 * ( ( offs >> 1 ) / 32 );
            drawgfx( bitmap,Machine->gfx[0],
                tile_number,
                color,
                0,0,
                sx,sy,
                clip,TRANSPARENCY_PEN,0x3);
        }
    }
}

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

variable_types:
data
unsigned short

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


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
__int64 v1; // r13
unsigned __int64 v2; // rbx
int v3; // eax
_BYTE *v4; // rdx
unsigned __int16 v5; // si
__int64 v6; // rcx
unsigned int v7; // esi
int v8; // edx

v1 = *(_QWORD *)(Machine + 520LL);
if ( videoram_size )
{
v2 = 0LL;
do
{
v3 = (int)v2 / 2;
v4 = (_BYTE *)(dirtybuffer + (int)v2 / 2);
if ( *v4 )
{
v5 = *(_WORD *)(videoram + v2);
*v4 = 0;
v6 = v5 >> 12;
v7 = v5 & 0xFFF;
v8 = v3 + 15;
if ( v3 >= 0 )
v8 = (int)v2 / 2;
drawgfx(tmpbitmap, v1, v7, v6, 0LL, 0LL, (unsigned int)(16 * (v3 % 16)), v8 & 0xFFFFFFF0, 0LL, 0LL, 0LL);
}
v2 += 2LL;
}
while ( videoram_size > v2 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r13
unsigned __int64 v2; // rbx
int v3; // eax
_BYTE *v4; // rdx
unsigned __int16 v5; // si
__int64 v6; // rcx
unsigned int v7; // esi
int v8; // edx

v1 = *(_QWORD *)(Machine + 520LL);
if ( videoram_size )
{
v2 = 0LL;
do
{
v3 = (int)v2 / 2;
v4 = (_BYTE *)(dirtybuffer + (int)v2 / 2);
if ( *v4 )
{
v5 = *(_WORD *)(videoram + v2);
*v4 = 0;
v6 = v5 >> 12;
v7 = v5 & 0xFFF;
v8 = v3 + 15;
if ( v3 >= 0 )
v8 = (int)v2 / 2;
drawgfx(tmpbitmap, v1, v7, v6, 0LL, 0LL, (unsigned int)(16 * (v3 % 16)), v8 & 0xFFFFFFF0, 0LL, 0LL, 0LL);
}
v2 += 2LL;
}
while ( videoram_size > v2 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
static void draw_background( struct osd_bitmap *bitmap ) {
    int offs;
    const struct GfxElement *gfx = Machine->gfx[1];
    for( offs = 0; offs < videoram_size; offs += 2 ){
        int offs2 = offs / 2;
        if( dirtybuffer[offs2] ) {
            int data = (*(UINT16 *)(&videoram[offs]));
            int numtile = ( data & 0xfff );
            int color = ( data & 0xf000 ) >> 12;
            int sx = ( offs2 % 16 ) * 16;
            int sy = ( offs2 / 16 ) * 16;
            dirtybuffer[offs2] = 0;
            drawgfx( tmpbitmap,gfx,
                numtile,
                color,
                0,0,
                sx,sy,
                0,TRANSPARENCY_NONE,0);
        }
    }
    copybitmap( bitmap, tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0 );
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap) {
    int offs;
    struct GfxElement *gfx = Machine->gfx[1];
    for( offs = 0; offs < videoram_size; offs += 2 ){
        int offs2 = offs / 2;
        if( dirtybuffer[offs2] ) {
            int data = (*(UINT16 *)(&videoram[offs]));
            int numtile = ( data & 0xfff );
            int color = ( data & 0xf000 ) >> 12;
            int sx = ( offs2 % 16 ) * 16;
            int sy = ( offs2 / 16 ) * 16;
            dirtybuffer[offs2] = 0;
            drawgfx( tmpbitmap,gfx,
                numtile,
                color,
                0,0,
                sx,sy,
                0,TRANSPARENCY_NONE,0);
        }
    }
    copybitmap( bitmap, tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0 );
}

variable_types: offs 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; } *

variable_types: data int

variable_types: numtile int

variable_types: color int

variable_types: sx int

variable_types: sy int

return_type: void

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


decompiled_code:
void __fastcall dominos_attract_w(__int64 a1, char a2)
{
dominos_attract = (a2 << 6) & 0x40;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
dominos_attract = (a2 << 6) & 0x40;
}

original_code:
void dominos_attract_w(offs_t offset,data_t data)
{
 dominos_attract = (data & 0x01) << 6;
}

canonical_original_code:
void dominos_attract_w(unsigned int offset, unsigned int data)
{
 dominos_attract = (data & 0x01) << 6;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void dominos_tumble_w()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void dominos_tumble_w(offs_t offset,data_t data)
{
 return;
}

canonical_original_code:
void dominos_tumble_w(unsigned int offset, unsigned int data)
{
 return;
}


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

switch ( a1 )
{
case 16:
case 20:
case 48:
case 52:
result = (unsigned __int8)((unsigned __int8)input_port_0_r(0LL) << 6);
break;
case 17:
case 21:
case 49:
case 53:
result = (unsigned __int8)(16 * input_port_0_r(0LL)) & 0xC0;
break;
case 18:
case 22:
case 50:
case 54:
result = (unsigned __int8)(4 * input_port_0_r(0LL)) & 0xC0;
break;
case 19:
case 23:
case 51:
case 55:
result = input_port_0_r(0LL) & 0xC0;
break;
case 24:
result = (unsigned __int8)((unsigned __int8)input_port_1_r(0LL) << 7);
break;
case 25:
result = (unsigned __int8)((unsigned __int8)input_port_1_r(0LL) << 6) & 0x80;
break;
case 26:
result = (unsigned __int8)(32 * input_port_1_r(0LL)) & 0x80;
break;
case 27:
result = (unsigned __int8)(16 * input_port_1_r(0LL)) & 0x80;
break;
case 28:
result = (unsigned __int8)(8 * input_port_1_r(0LL)) & 0x80;
break;
case 29:
result = (unsigned __int8)(4 * input_port_1_r(0LL)) & 0x80;
break;
case 30:
result = (unsigned __int8)(2 * input_port_1_r(0LL)) & 0x80;
break;
case 31:
result = input_port_1_r(0LL) & 0x80;
break;
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
result = 255LL;
break;
case 40:
result = (unsigned __int8)((unsigned __int8)input_port_2_r(0LL) << 7);
break;
case 41:
result = (unsigned __int8)((unsigned __int8)input_port_2_r(0LL) << 6) & 0x80;
break;
case 42:
result = (unsigned __int8)(32 * input_port_2_r(0LL)) & 0x80;
break;
case 43:
result = (unsigned __int8)(16 * input_port_2_r(0LL)) & 0x80;
break;
case 44:
result = (unsigned __int8)(8 * input_port_2_r(0LL)) & 0x80;
break;
case 45:
result = (unsigned __int8)(4 * input_port_2_r(0LL)) & 0x80;
break;
case 46:
result = (unsigned __int8)(2 * input_port_2_r(0LL)) & 0x80;
break;
case 47:
result = input_port_2_r(0LL) & 0x80;
break;
default:
result = 255LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 16:
case 20:
case 48:
case 52:
result = (unsigned __int8)((unsigned __int8)input_port_0_r(0LL) << 6);
break;
case 17:
case 21:
case 49:
case 53:
result = (unsigned __int8)(16 * input_port_0_r(0LL)) & 0xC0;
break;
case 18:
case 22:
case 50:
case 54:
result = (unsigned __int8)(4 * input_port_0_r(0LL)) & 0xC0;
break;
case 19:
case 23:
case 51:
case 55:
result = input_port_0_r(0LL) & 0xC0;
break;
case 24:
result = (unsigned __int8)((unsigned __int8)input_port_1_r(0LL) << 7);
break;
case 25:
result = (unsigned __int8)((unsigned __int8)input_port_1_r(0LL) << 6) & 0x80;
break;
case 26:
result = (unsigned __int8)(32 * input_port_1_r(0LL)) & 0x80;
break;
case 27:
result = (unsigned __int8)(16 * input_port_1_r(0LL)) & 0x80;
break;
case 28:
result = (unsigned __int8)(8 * input_port_1_r(0LL)) & 0x80;
break;
case 29:
result = (unsigned __int8)(4 * input_port_1_r(0LL)) & 0x80;
break;
case 30:
result = (unsigned __int8)(2 * input_port_1_r(0LL)) & 0x80;
break;
case 31:
result = input_port_1_r(0LL) & 0x80;
break;
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
result = 255LL;
break;
case 40:
result = (unsigned __int8)((unsigned __int8)input_port_2_r(0LL) << 7);
break;
case 41:
result = (unsigned __int8)((unsigned __int8)input_port_2_r(0LL) << 6) & 0x80;
break;
case 42:
result = (unsigned __int8)(32 * input_port_2_r(0LL)) & 0x80;
break;
case 43:
result = (unsigned __int8)(16 * input_port_2_r(0LL)) & 0x80;
break;
case 44:
result = (unsigned __int8)(8 * input_port_2_r(0LL)) & 0x80;
break;
case 45:
result = (unsigned __int8)(4 * input_port_2_r(0LL)) & 0x80;
break;
case 46:
result = (unsigned __int8)(2 * input_port_2_r(0LL)) & 0x80;
break;
case 47:
result = input_port_2_r(0LL) & 0x80;
break;
default:
result = 255LL;
break;
}
return result;
}

original_code:
data_t dominos_port_r(offs_t offset)
{
 switch (offset)
 {
  case 0x18: return ((input_port_1_r(0) & 0x01) << 7);
  case 0x19: return ((input_port_1_r(0) & 0x02) << 6);
  case 0x1A: return ((input_port_1_r(0) & 0x04) << 5);
  case 0x1B: return ((input_port_1_r(0) & 0x08) << 4);
  case 0x1C: return ((input_port_1_r(0) & 0x10) << 3);
  case 0x1D: return ((input_port_1_r(0) & 0x20) << 2);
  case 0x1E: return ((input_port_1_r(0) & 0x40) << 1);
  case 0x1F: return ((input_port_1_r(0) & 0x80) << 0);
  case 0x28: return ((input_port_2_r(0) & 0x01) << 7);
  case 0x29: return ((input_port_2_r(0) & 0x02) << 6);
  case 0x2A: return ((input_port_2_r(0) & 0x04) << 5);
  case 0x2B: return ((input_port_2_r(0) & 0x08) << 4);
  case 0x2C: return ((input_port_2_r(0) & 0x10) << 3);
  case 0x2D: return ((input_port_2_r(0) & 0x20) << 2);
  case 0x2E: return ((input_port_2_r(0) & 0x40) << 1);
  case 0x2F: return ((input_port_2_r(0) & 0x80) << 0);
  case 0x10:
  case 0x14:
  case 0x30:
  case 0x34: return ((input_port_0_r(0) & 0x03) << 6);
  case 0x11:
  case 0x15:
  case 0x31:
  case 0x35: return ((input_port_0_r(0) & 0x0C) << 4);
  case 0x12:
  case 0x16:
  case 0x32:
  case 0x36: return ((input_port_0_r(0) & 0x30) << 2);
  case 0x13:
  case 0x17:
  case 0x33:
  case 0x37: return ((input_port_0_r(0) & 0xC0) << 0);
  default: return 0xFF;
 }
}

canonical_original_code:
unsigned int dominos_port_r(unsigned int offset)
{
 switch (offset)
 {
  case 0x18: return ((input_port_1_r(0) & 0x01) << 7);
  case 0x19: return ((input_port_1_r(0) & 0x02) << 6);
  case 0x1A: return ((input_port_1_r(0) & 0x04) << 5);
  case 0x1B: return ((input_port_1_r(0) & 0x08) << 4);
  case 0x1C: return ((input_port_1_r(0) & 0x10) << 3);
  case 0x1D: return ((input_port_1_r(0) & 0x20) << 2);
  case 0x1E: return ((input_port_1_r(0) & 0x40) << 1);
  case 0x1F: return ((input_port_1_r(0) & 0x80) << 0);
  case 0x28: return ((input_port_2_r(0) & 0x01) << 7);
  case 0x29: return ((input_port_2_r(0) & 0x02) << 6);
  case 0x2A: return ((input_port_2_r(0) & 0x04) << 5);
  case 0x2B: return ((input_port_2_r(0) & 0x08) << 4);
  case 0x2C: return ((input_port_2_r(0) & 0x10) << 3);
  case 0x2D: return ((input_port_2_r(0) & 0x20) << 2);
  case 0x2E: return ((input_port_2_r(0) & 0x40) << 1);
  case 0x2F: return ((input_port_2_r(0) & 0x80) << 0);
  case 0x10:
  case 0x14:
  case 0x30:
  case 0x34: return ((input_port_0_r(0) & 0x03) << 6);
  case 0x11:
  case 0x15:
  case 0x31:
  case 0x35: return ((input_port_0_r(0) & 0x0C) << 4);
  case 0x12:
  case 0x16:
  case 0x32:
  case 0x36: return ((input_port_0_r(0) & 0x30) << 2);
  case 0x13:
  case 0x17:
  case 0x33:
  case 0x37: return ((input_port_0_r(0) & 0xC0) << 0);
  default: return 0xFF;
 }
}

return_type: unsigned int


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

ac_line_0 = (ac_line_0 + 1) % 3;
if ( ac_line_0 )
return dominos_attract | (unsigned int)(input_port_4_r(0LL) & 0x7F);
result = dominos_attract | (unsigned int)(input_port_4_r(0LL) & 0x7F);
LOBYTE(result) = result | 0x80;
return result;
}

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

ac_line_0 = (ac_line_0 + 1) % 3;
if ( ac_line_0 )
return dominos_attract | (unsigned int)(input_port_4_r(0LL) & 0x7F);
result = dominos_attract | (unsigned int)(input_port_4_r(0LL) & 0x7F);
LOBYTE(result) = result | 0x80;
return result;
}

original_code:
data_t dominos_sync_r(offs_t offset)
{
  static int ac_line=0x00;
  ac_line=(ac_line+1) % 3;
  if (ac_line==0)
    return ((input_port_4_r(0) & 0x7F) | dominos_attract | 0x80);
  else
    return ((input_port_4_r(0) & 0x7F) | dominos_attract );
}

canonical_original_code:
unsigned int dominos_sync_r(unsigned int offset)
{
  static int ac_line = 0x00;
  ac_line=(ac_line+1) % 3;
  if (ac_line==0)
    return ((input_port_4_r(0) & 0x7F) | dominos_attract | 0x80);
  else
    return ((input_port_4_r(0) & 0x7F) | dominos_attract );
}


decompiled_code:
__int64 __fastcall dominos_lamp1_w(char a1)
{
return osd_led_w(0LL, a1 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return osd_led_w(0LL, a1 & 1);
}

original_code:
void dominos_lamp1_w(offs_t offset,data_t data)
{
 osd_led_w(0,offset & 0x01);
}

canonical_original_code:
void dominos_lamp1_w(unsigned int offset, unsigned int data)
{
 osd_led_w(0,offset & 0x01);
}


decompiled_code:
__int64 __fastcall dominos_lamp2_w(char a1)
{
return osd_led_w(1LL, a1 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return osd_led_w(1LL, a1 & 1);
}

original_code:
void dominos_lamp2_w(offs_t offset,data_t data)
{
 osd_led_w(1,offset & 0x01);
}

canonical_original_code:
void dominos_lamp2_w(unsigned int offset, unsigned int data)
{
 osd_led_w(1,offset & 0x01);
}


decompiled_code:
__int64 __fastcall dominos_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v2) & 0x3F,
*(_BYTE *)(videoram + v2) >> 7,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v2) & 0x3F,
*(_BYTE *)(videoram + v2) >> 7,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void dominos_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int charcode;
   int sx,sy;
   dirtybuffer[offs]=0;
   charcode = videoram[offs] & 0x3F;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0],
     charcode, (videoram[offs] & 0x80)>>7,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void dominos_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int charcode;
   int sx; int sy;
   dirtybuffer[offs]=0;
   charcode = videoram[offs] & 0x3F;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0],
     charcode, (videoram[offs] & 0x80)>>7,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

variable_types: charcode int


decompiled_code:
void __fastcall spacefb_video_control_w(__int64 a1, int a2)
{
video_control = a2;
}

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

original_code:
void spacefb_video_control_w(offs_t offset,data_t data)
{
 video_control = data;
}

canonical_original_code:
void spacefb_video_control_w(unsigned int offset, unsigned int data)
{
 video_control = data;
}


decompiled_code:
void spacefb_port_2_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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


decompiled_code:
__int64 spacefb_sh_p2_r()
{
return (2 * spacefb_sound_latch) & 0x30;
}

canonical_decompiled_code:
__int64 func3()
{
return (2 * spacefb_sound_latch) & 0x30;
}

original_code:
static data_t spacefb_sh_p2_r(offs_t offset)
{
    return ((spacefb_sound_latch & 0x18) << 1);
}

canonical_original_code:
static unsigned int spacefb_sh_p2_r(unsigned int offset)
{
    return ((spacefb_sound_latch & 0x18) << 1);
}


decompiled_code:
__int64 spacefb_sh_t0_r()
{
return spacefb_sound_latch & 0x20;
}

canonical_decompiled_code:
__int64 func4()
{
return spacefb_sound_latch & 0x20;
}

original_code:
static data_t spacefb_sh_t0_r(offs_t offset)
{
    return spacefb_sound_latch & 0x20;
}

canonical_original_code:
static unsigned int spacefb_sh_t0_r(unsigned int offset)
{
    return spacefb_sound_latch & 0x20;
}


decompiled_code:
__int64 spacefb_sh_t1_r()
{
return spacefb_sound_latch & 4;
}

canonical_decompiled_code:
__int64 func5()
{
return spacefb_sound_latch & 4;
}

original_code:
static data_t spacefb_sh_t1_r(offs_t offset)
{
    return spacefb_sound_latch & 0x04;
}

canonical_original_code:
static unsigned int spacefb_sh_t1_r(unsigned int offset)
{
    return spacefb_sound_latch & 0x04;
}


decompiled_code:
__int64 __fastcall spacefb_vh_screenrefresh(__int64 a1)
{
int v2; // eax
unsigned int v3; // ebp
int v4; // er14
__int64 v5; // rbx
__int64 v6; // r12
__int64 result; // rax
char v8; // dl
int v9; // er8
__int64 v10; // rsi
__int64 v11; // rdi
__int64 v12; // rcx
__int64 v13; // rdi

fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
v2 = (4 * (_BYTE)video_control) & 0x80;
v3 = video_control & 1;
v4 = (video_control >> 4) & 4;
v5 = v2 + 768;
v6 = v2 + 896;
do
{
result = videoram;
v8 = *(_BYTE *)(videoram + v5);
if ( v8 )
{
v9 = *(unsigned __int8 *)(videoram + v5 - 768);
v10 = (unsigned int)(255 - v9);
v11 = *(unsigned __int8 *)(videoram + v5 - 512);
result = *(unsigned __int8 *)(videoram + v5 - 256);
v12 = v4 | ~v8 & 3u;
if ( (v8 & 0x20) != 0 )
{
if ( v3 )
{
v10 = (unsigned int)(v9 + 5);
v11 = (unsigned int)(252 - v11);
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
result & 0x3F,
v12,
v3,
v3,
v10,
v11,
Machine + 776LL,
2LL,
0LL);
}
else if ( (v8 & 0x40) != 0 )
{
v13 = (unsigned int)(v11 - 5);
if ( v3 )
{
v10 = (unsigned int)(v9 + 1);
v13 = (unsigned int)(248 - v13);
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned __int8)~(_BYTE)result,
v12,
v3,
v3,
v10,
v13,
Machine + 776LL,
0LL,
0LL);
}
}
++v5;
}
while ( v5 != v6 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v2; // eax
unsigned int v3; // ebp
int v4; // er14
__int64 v5; // rbx
__int64 v6; // r12
__int64 result; // rax
char v8; // dl
int v9; // er8
__int64 v10; // rsi
__int64 v11; // rdi
__int64 v12; // rcx
__int64 v13; // rdi

fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
v2 = (4 * (_BYTE)video_control) & 0x80;
v3 = video_control & 1;
v4 = (video_control >> 4) & 4;
v5 = v2 + 768;
v6 = v2 + 896;
do
{
result = videoram;
v8 = *(_BYTE *)(videoram + v5);
if ( v8 )
{
v9 = *(unsigned __int8 *)(videoram + v5 - 768);
v10 = (unsigned int)(255 - v9);
v11 = *(unsigned __int8 *)(videoram + v5 - 512);
result = *(unsigned __int8 *)(videoram + v5 - 256);
v12 = v4 | ~v8 & 3u;
if ( (v8 & 0x20) != 0 )
{
if ( v3 )
{
v10 = (unsigned int)(v9 + 5);
v11 = (unsigned int)(252 - v11);
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
result & 0x3F,
v12,
v3,
v3,
v10,
v11,
Machine + 776LL,
2LL,
0LL);
}
else if ( (v8 & 0x40) != 0 )
{
v13 = (unsigned int)(v11 - 5);
if ( v3 )
{
v10 = (unsigned int)(v9 + 1);
v13 = (unsigned int)(248 - v13);
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned __int8)~(_BYTE)result,
v12,
v3,
v3,
v10,
v13,
Machine + 776LL,
0LL,
0LL);
}
}
++v5;
}
while ( v5 != v6 );
return result;
}

original_code:
void spacefb_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int spriteno, col_bit2, flipscreen;
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 spriteno = (video_control & 0x20) ? 0x80 : 0x00;
 flipscreen = video_control & 0x01;
 col_bit2 = (video_control & 0x40) ? 0x04 : 0x00;
 for (offs = 0; offs < 128; offs++, spriteno++)
 {
  int sx,sy,code,cnt,col;
  sx = 255 - videoram[spriteno];
  sy = videoram[spriteno+0x100];
  code = videoram[spriteno+0x200];
  cnt = videoram[spriteno+0x300];
  col = (~cnt & 0x03) | col_bit2;
  if (cnt)
  {
   if (cnt & 0x20)
   {
    if (flipscreen)
    {
     sx = 260 - sx;
     sy = 252 - sy;
    }
    drawgfx(bitmap,Machine->gfx[1],
      code & 0x3f,
      col,
      flipscreen,flipscreen,
      sx,sy,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
   else if (cnt & 0x40)
   {
    sy -= 5;
    if (flipscreen)
    {
     sx = 256 - sx;
     sy = 248 - sy;
    }
    drawgfx(bitmap,Machine->gfx[0],
      255 - code,
      col,
      flipscreen,flipscreen,
      sx,sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
   }
  }
 }
}

canonical_original_code:
void spacefb_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int spriteno; int col_bit2; int flipscreen;
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 spriteno = (video_control & 0x20) ? 0x80 : 0x00;
 flipscreen = video_control & 0x01;
 col_bit2 = (video_control & 0x40) ? 0x04 : 0x00;
 for (offs = 0; offs < 128; offs++, spriteno++)
 {
  int sx; int sy; int code; int cnt; int col;
  sx = 255 - videoram[spriteno];
  sy = videoram[spriteno+0x100];
  code = videoram[spriteno+0x200];
  cnt = videoram[spriteno+0x300];
  col = (~cnt & 0x03) | col_bit2;
  if (cnt)
  {
   if (cnt & 0x20)
   {
    if (flipscreen)
    {
     sx = 260 - sx;
     sy = 252 - sy;
    }
    drawgfx(bitmap,Machine->gfx[1],
      code & 0x3f,
      col,
      flipscreen,flipscreen,
      sx,sy,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
   else if (cnt & 0x40)
   {
    sy -= 5;
    if (flipscreen)
    {
     sx = 256 - sx;
     sy = 248 - sy;
    }
    drawgfx(bitmap,Machine->gfx[0],
      255 - code,
      col,
      flipscreen,flipscreen,
      sx,sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
   }
  }
 }
}

variable_types: spriteno int

variable_types: flipscreen int

variable_types: code int

variable_types: cnt int

variable_types: col int


decompiled_code:
__int64 spacefb_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 215 : 207;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)cpu_getiloops() == 0 ? 215 : 207;
}

original_code:
static int spacefb_interrupt(void)
{
 if (cpu_getiloops() != 0) return (0x00cf);
 else return (0x00d7);
}

canonical_original_code:
static int spacefb_interrupt()
{
 if (cpu_getiloops() != 0) return (0x00cf);
 else return (0x00d7);
}

return_type: int


decompiled_code:
void __fastcall zwackery_pia_3_w(__int64 a1, unsigned __int8 a2)
{
zwackery_sound_data = a2 >> 4;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, unsigned __int8 a2)
{
zwackery_sound_data = a2 >> 4;
}

original_code:
void zwackery_pia_3_w(offs_t offset,data_t data)
{
 zwackery_sound_data = (data >> 4) & 0x0f;
}

canonical_original_code:
void zwackery_pia_3_w(unsigned int offset, unsigned int data)
{
 zwackery_sound_data = (data >> 4) & 0x0f;
}


decompiled_code:
__int64 update_mcr68_interrupts()
{
__int64 v0; // rsi

if ( v493_irq_state )
{
v0 = (unsigned __int8)v493_irq_vector;
if ( !m6840_irq_state )
goto LABEL_4;
}
else if ( !m6840_irq_state )
{
return cpu_set_irq_line(0LL, 7LL, 0LL);
}
v0 = (unsigned __int8)m6840_irq_vector;
LABEL_4:
if ( (_DWORD)v0 )
return cpu_set_irq_line(0LL, v0, 1LL);
return cpu_set_irq_line(0LL, 7LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rsi

if ( v493_irq_state )
{
v0 = (unsigned __int8)v493_irq_vector;
if ( !m6840_irq_state )
goto LABEL_4;
}
else if ( !m6840_irq_state )
{
return cpu_set_irq_line(0LL, 7LL, 0LL);
}
v0 = (unsigned __int8)m6840_irq_vector;
LABEL_4:
if ( (_DWORD)v0 )
return cpu_set_irq_line(0LL, v0, 1LL);
return cpu_set_irq_line(0LL, 7LL, 0LL);
}

original_code:
static void update_mcr68_interrupts(void)
{
 int newstate = 0;
 if (v493_irq_state)
  newstate = v493_irq_vector;
 if (m6840_irq_state)
  newstate = m6840_irq_vector;
 if (newstate)
  cpu_set_irq_line(0, newstate, 1);
 else
  cpu_set_irq_line(0, 7, 0);
}

canonical_original_code:
static void update_mcr68_interrupts()
{
 int newstate = 0;
 if (v493_irq_state)
  newstate = v493_irq_vector;
 if (m6840_irq_state)
  newstate = m6840_irq_vector;
 if (newstate)
  cpu_set_irq_line(0, newstate, 1);
 else
  cpu_set_irq_line(0, 7, 0);
}

variable_types: newstate int


decompiled_code:
__int64 mcr68_493_callback()
{
unsigned int v0; // eax

v493_irq_state = 1;
update_mcr68_interrupts();
v0 = cpu_getscanlineperiod();
return timer_set(v0, 0LL, mcr68_493_off_callback);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // eax

v493_irq_state = 1;
func2();
v0 = cpu_getscanlineperiod();
return timer_set(v0, 0LL, mcr68_493_off_callback);
}

original_code:
static void mcr68_493_callback(int param)
{
 v493_irq_state = 1;
 update_mcr68_interrupts();
 timer_set(cpu_getscanlineperiod(), 0, mcr68_493_off_callback);
}

variable_types: param int


decompiled_code:
__int64 mcr68_493_off_callback()
{
v493_irq_state = 0;
return update_mcr68_interrupts();
}

canonical_decompiled_code:
__int64 func4()
{
v493_irq_state = 0;
return func2();
}

original_code:
static void mcr68_493_off_callback(int param)
{
 v493_irq_state = 0;
 update_mcr68_interrupts();
}


decompiled_code:
__int64 __fastcall zwackery_pia_irq(char a1)
{
v493_irq_state = a1;
return update_mcr68_interrupts();
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
v493_irq_state = a1;
return func2();
}

original_code:
void zwackery_pia_irq(int state)
{
 v493_irq_state = state;
 update_mcr68_interrupts();
}

variable_types: state int


decompiled_code:
char *__fastcall subtract_from_counter(int a1, int a2)
{
__int16 v2; // ax
int v3; // ebx
int v4; // eax
int v5; // ebx
int v6; // er14
char *v7; // r12
char *result; // rax
int v9; // ebx

if ( (m6840_state[24 * a1] & 4) != 0 )
{
v2 = *(_WORD *)&m6840_state[24 * a1 + 4];
v3 = (unsigned __int8)v2;
v4 = HIBYTE(v2);
v5 = v3 - a2;
if ( v5 < 0 )
{
v6 = 1 << a1;
v7 = &m6840_state[24 * a1];
do
{
v5 += (unsigned __int8)v7[2] + 1;
if ( --v4 < 0 )
{
m6840_status |= v6;
m6840_status_read_since_int &= ~(_BYTE)v6;
update_interrupts();
v4 = (unsigned __int8)v7[3] + 1;
}
}
while ( v5 < 0 );
}
result = (char *)(v5 | (unsigned int)(v4 << 8));
*(_WORD *)&m6840_state[24 * a1 + 4] = (_WORD)result;
}
else
{
v9 = *(unsigned __int16 *)&m6840_state[24 * a1 + 4] - a2;
while ( v9 < 0 )
{
v9 += *(unsigned __int16 *)&m6840_state[24 * a1 + 2] + 1;
m6840_status |= 1 << a1;
m6840_status_read_since_int &= ~(1 << a1);
update_interrupts();
}
result = m6840_state;
*(_WORD *)&m6840_state[24 * a1 + 4] = v9;
}
return result;
}

original_code:
static void subtract_from_counter(int counter, int count)
{
 if (m6840_state[counter].control & 0x04)
 {
  int lsb = m6840_state[counter].count & 0xff;
  int msb = m6840_state[counter].count >> 8;
  lsb -= count;
  while (lsb < 0)
  {
   lsb += (m6840_state[counter].latch & 0xff) + 1;
   msb--;
   if (msb < 0)
   {
    m6840_status |= 1 << counter;
    m6840_status_read_since_int &= ~(1 << counter);
    update_interrupts();
    msb = (m6840_state[counter].latch >> 8) + 1;
    ;
   }
  }
  m6840_state[counter].count = (msb << 8) | lsb;
 }
 else
 {
  int word = m6840_state[counter].count;
  word -= count;
  while (word < 0)
  {
   word += m6840_state[counter].latch + 1;
   m6840_status |= 1 << counter;
   m6840_status_read_since_int &= ~(1 << counter);
   update_interrupts();
   ;
  }
  m6840_state[counter].count = word;
 }
}

variable_types: counter int

variable_types: count int

variable_types: lsb int

variable_types: msb int

variable_types: word int


decompiled_code:
char *__fastcall counter_fired_callback(int a1)
{
*(_QWORD *)&m6840_state[24 * (a1 & 3) + 8] = 0LL;
return subtract_from_counter(a1 & 3, a1 >> 2);
}

original_code:
static void counter_fired_callback(int counter)
{
 int count = counter >> 2;
 counter &= 3;
 m6840_state[counter].timer = ((void *)0);
 subtract_from_counter(counter, count);
}


decompiled_code:
__int64 __fastcall mcr68_common_init(__int64 a1, __int64 a2)
{
int v2; // ecx

m6840_status = 0;
m6840_status_read_since_int = 0;
m6840_lsb_buffer = 0;
m6840_msb_buffer = 0;
m6840_state[0] = 0;
word_E02 = -1;
word_E04 = -1;
qword_E08 = 0LL;
dword_E10 = 35791394;
byte_E18 = 0;
word_E1A = -1;
word_E1C = -1;
qword_E20 = 0LL;
dword_E28 = 0x7FFFFFFF;
byte_E30 = 0;
word_E32 = -1;
word_E34 = -1;
qword_E38 = 0LL;
dword_E40 = 69905;
v2 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 4LL) / 10;
m6840_internal_counter_period = 0x40000000 / v2;
mcr_cocktail_flip = 0;
pia_unconfig(a1, a2, (unsigned int)(0x40000000 % v2));
return mcr_sound_init();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // ecx

m6840_status = 0;
m6840_status_read_since_int = 0;
m6840_lsb_buffer = 0;
m6840_msb_buffer = 0;
m6840_state[0] = 0;
word_E02 = -1;
word_E04 = -1;
qword_E08 = 0LL;
dword_E10 = 35791394;
byte_E18 = 0;
word_E1A = -1;
word_E1C = -1;
qword_E20 = 0LL;
dword_E28 = 0x7FFFFFFF;
byte_E30 = 0;
word_E32 = -1;
word_E34 = -1;
qword_E38 = 0LL;
dword_E40 = 69905;
v2 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 4LL) / 10;
m6840_internal_counter_period = 0x40000000 / v2;
mcr_cocktail_flip = 0;
pia_unconfig(a1, a2, (unsigned int)(0x40000000 % v2));
return mcr_sound_init();
}

original_code:
static void mcr68_common_init(void)
{
 int i;
 m6840_status = 0x00;
 m6840_status_read_since_int = 0x00;
 m6840_msb_buffer = m6840_lsb_buffer = 0;
 for (i = 0; i < 3; i++)
 {
  m6840_state[i].control = 0x00;
  m6840_state[i].latch = 0xffff;
  m6840_state[i].count = 0xffff;
  m6840_state[i].timer = ((void *)0);
  m6840_state[i].period = m6840_counter_periods[i];
 }
 m6840_internal_counter_period = ((1<<30) / ((timer_tm)(Machine->drv->cpu[0].cpu_clock / 10)));
 mcr_cocktail_flip = 0;
 pia_unconfig();
 mcr_sound_init();
}

canonical_original_code:
static void mcr68_common_init()
{
 int i;
 m6840_status = 0x00;
 m6840_status_read_since_int = 0x00;
 m6840_msb_buffer = m6840_lsb_buffer = 0;
 for (i = 0; i < 3; i++)
 {
  m6840_state[i].control = 0x00;
  m6840_state[i].latch = 0xffff;
  m6840_state[i].count = 0xffff;
  m6840_state[i].timer = ((void *)0);
  m6840_state[i].period = m6840_counter_periods[i];
 }
 m6840_internal_counter_period = ((1<<30) / ((timer_tm)(Machine->drv->cpu[0].cpu_clock / 10)));
 mcr_cocktail_flip = 0;
 pia_unconfig();
 mcr_sound_init();
}

variable_types: i int


decompiled_code:
__int64 __fastcall zwackery_ca2_w(__int64 a1, int a2)
{
return csdeluxe_data_w(a1, (unsigned __int8)zwackery_sound_data | (unsigned int)(16 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
return csdeluxe_data_w(a1, (unsigned __int8)zwackery_sound_data | (unsigned int)(16 * a2));
}

original_code:
void zwackery_ca2_w(offs_t offset,data_t data)
{
 csdeluxe_data_w(offset, (data << 4) | zwackery_sound_data);
}

canonical_original_code:
void zwackery_ca2_w(unsigned int offset, unsigned int data)
{
 csdeluxe_data_w(offset, (data << 4) | zwackery_sound_data);
}

variable_types:
offset
unsigned int


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

if ( a2 >= 0 )
result = watchdog_reset_w();
return result;
}

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

if ( a2 >= 0 )
result = watchdog_reset_w();
return result;
}

original_code:
void zwackery_pia_2_w(offs_t offset,data_t data)
{
 if (!(data & 0x80)) watchdog_reset_w(offset, data);
}

canonical_original_code:
void zwackery_pia_2_w(unsigned int offset, unsigned int data)
{
 if (!(data & 0x80)) watchdog_reset_w(offset, data);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 zwackery_493_callback()
{
unsigned int v0; // eax

pia_2_ca1_w(0LL, 1LL);
v0 = cpu_getscanlineperiod();
return timer_set(v0, 0LL, zwackery_493_off_callback);
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // eax

pia_2_ca1_w(0LL, 1LL);
v0 = cpu_getscanlineperiod();
return timer_set(v0, 0LL, zwackery_493_off_callback);
}

original_code:
static void zwackery_493_callback(int param)
{
 pia_2_ca1_w(0, 1);
 timer_set(cpu_getscanlineperiod(), 0, zwackery_493_off_callback);
}


decompiled_code:
__int64 zwackery_493_off_callback()
{
return pia_2_ca1_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func13()
{
return pia_2_ca1_w(0LL, 0LL);
}

original_code:
static void zwackery_493_off_callback(int param)
{
 pia_2_ca1_w(0, 0);
}


decompiled_code:
char *__fastcall mcr68_6840_w_common(unsigned int a1, unsigned __int8 a2)
{
int v2; // edi
char v3; // bl
char *v4; // rbp
char *result; // rax
unsigned int v6; // ebx

if ( a1 > 1 )
{
if ( (a1 & 1) != 0 )
{
v6 = (a1 - 2) >> 1;
*(_WORD *)&m6840_state[24 * v6 + 2] = ((unsigned __int8)m6840_msb_buffer << 8) | a2;
m6840_status &= __ROL4__(-2, v6);
result = (char *)update_interrupts();
if ( (m6840_state[24 * v6] & 0x10) == 0 )
result = reload_count(v6);
}
else
{
m6840_msb_buffer = a2;
}
return result;
}
if ( a1 == 1 )
{
v2 = 1;
}
else
{
v2 = 2;
if ( (byte_E18 & 1) != 0 )
{
v3 = m6840_state[0] ^ a2;
m6840_state[0] = a2;
v2 = 0;
if ( (v3 & 1) != 0 )
{
if ( (a2 & 1) != 0 )
{
v4 = m6840_state;
do
{
if ( *((_QWORD *)v4 + 1) )
timer_remove();
*((_QWORD *)v4 + 1) = 0LL;
v4 += 24;
}
while ( v4 != &m6840_state[72] );
}
else
{
reload_count(0);
reload_count(1);
reload_count(2);
}
m6840_status = 0;
result = (char *)update_interrupts();
v2 = 0;
}
goto LABEL_19;
}
}
result = (char *)(2LL * v2);
v3 = m6840_state[24 * v2] ^ a2;
m6840_state[24 * v2] = a2;
LABEL_19:
if ( (v3 & 2) != 0 )
result = reload_count(v2);
return result;
}

original_code:
static void mcr68_6840_w_common(offs_t offset,data_t data)
{
 int i;
 if (offset < 2)
 {
  int counter = (offset == 1) ? 1 : (m6840_state[1].control & 0x01) ? 0 : 2;
  UINT8 diffs = data ^ m6840_state[counter].control;
  m6840_state[counter].control = data;
  if (counter == 0 && (diffs & 0x01))
  {
   if (data & 0x01)
   {
    for (i = 0; i < 3; i++)
    {
     if (m6840_state[i].timer)
      timer_remove(m6840_state[i].timer);
     m6840_state[i].timer = ((void *)0);
    }
   }
   else
   {
    for (i = 0; i < 3; i++)
     reload_count(i);
   }
   m6840_status = 0;
   update_interrupts();
  }
  if (diffs & 0x02)
   reload_count(counter);
  ;
 }
 else if ((offset & 1) == 0)
 {
  ;
  m6840_msb_buffer = data;
 }
 else
 {
  int counter = (offset - 2) / 2;
  m6840_state[counter].latch = (m6840_msb_buffer << 8) | (data & 0xff);
  m6840_status &= ~(1 << counter);
  update_interrupts();
  if (!(m6840_state[counter].control & 0x10))
   reload_count(counter);
  ;
 }
}

canonical_original_code:
static void mcr68_6840_w_common(unsigned int offset, unsigned int data)
{
 int i;
 if (offset < 2)
 {
  int counter = (offset == 1) ? 1 : (m6840_state[1].control & 0x01) ? 0 : 2;
  unsigned char diffs = data ^ m6840_state[counter].control;
  m6840_state[counter].control = data;
  if (counter == 0 && (diffs & 0x01))
  {
   if (data & 0x01)
   {
    for (i = 0; i < 3; i++)
    {
     if (m6840_state[i].timer)
      timer_remove(m6840_state[i].timer);
     m6840_state[i].timer = ((void *)0);
    }
   }
   else
   {
    for (i = 0; i < 3; i++)
     reload_count(i);
   }
   m6840_status = 0;
   update_interrupts();
  }
  if (diffs & 0x02)
   reload_count(counter);
  ;
 }
 else if ((offset & 1) == 0)
 {
  ;
  m6840_msb_buffer = data;
 }
 else
 {
  int counter = (offset - 2) / 2;
  m6840_state[counter].latch = (m6840_msb_buffer << 8) | (data & 0xff);
  m6840_status &= ~(1 << counter);
  update_interrupts();
  if (!(m6840_state[counter].control & 0x10))
   reload_count(counter);
  ;
 }
}

variable_types:
diffs
unsigned char


decompiled_code:
__int64 __fastcall compute_counter(int a1)
{
int v1; // ebp
__int64 result; // rax
int v3; // ecx

if ( !*(_QWORD *)&m6840_state[24 * a1 + 8] )
return *(unsigned __int16 *)&m6840_state[24 * a1 + 4];
v1 = m6840_internal_counter_period;
if ( (m6840_state[24 * a1] & 2) == 0 )
v1 = m6840_counter_periods[a1];
result = (unsigned int)((int)timer_timeleft() / v1);
if ( (m6840_state[24 * a1] & 4) != 0 )
{
v3 = (unsigned __int8)m6840_state[24 * a1 + 4] + 1;
result = ((int)result % v3) | (unsigned int)(((int)result / v3) << 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
int v1; // ebp
__int64 result; // rax
int v3; // ecx

if ( !*(_QWORD *)&m6840_state[24 * a1 + 8] )
return *(unsigned __int16 *)&m6840_state[24 * a1 + 4];
v1 = m6840_internal_counter_period;
if ( (m6840_state[24 * a1] & 2) == 0 )
v1 = m6840_counter_periods[a1];
result = (unsigned int)((int)timer_timeleft() / v1);
if ( (m6840_state[24 * a1] & 4) != 0 )
{
v3 = (unsigned __int8)m6840_state[24 * a1 + 4] + 1;
result = ((int)result % v3) | (unsigned int)(((int)result / v3) << 8);
}
return result;
}

original_code:
static UINT16 compute_counter(int counter)
{
 timer_tm period;
 int remaining;
 if (!m6840_state[counter].timer)
  return m6840_state[counter].count;
 if (m6840_state[counter].control & 0x02)
  period = m6840_internal_counter_period;
 else
  period = m6840_counter_periods[counter];
 remaining = (int)(timer_timeleft(m6840_state[counter].timer) / period);
 if (m6840_state[counter].control & 0x04)
 {
  int divisor = (m6840_state[counter].count & 0xff) + 1;
  int msb = remaining / divisor;
  int lsb = remaining % divisor;
  remaining = (msb << 8) | lsb;
 }
 return remaining;
}

canonical_original_code:
static unsigned short compute_counter(int counter)
{
 int period;
 int remaining;
 if (!m6840_state[counter].timer)
  return m6840_state[counter].count;
 if (m6840_state[counter].control & 0x02)
  period = m6840_internal_counter_period;
 else
  period = m6840_counter_periods[counter];
 remaining = (int)(timer_timeleft(m6840_state[counter].timer) / period);
 if (m6840_state[counter].control & 0x04)
 {
  int divisor = (m6840_state[counter].count & 0xff) + 1;
  int msb = remaining / divisor;
  int lsb = remaining % divisor;
  remaining = (msb << 8) | lsb;
 }
 return remaining;
}

variable_types: period int

variable_types: remaining int

variable_types: divisor int

return_type: unsigned short


decompiled_code:
__int64 __fastcall mcr68_6840_r_common(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // ebx
unsigned __int16 v3; // ax
char v4; // r12
int v5; // ebp
int v6; // eax

result = a1;
if ( a1 )
{
if ( a1 == 1 )
{
m6840_status_read_since_int |= m6840_status & 7;
result = (unsigned __int8)m6840_status;
}
else
{
result = (unsigned __int8)m6840_lsb_buffer;
if ( (a1 & 1) == 0 )
{
v2 = (a1 - 2) >> 1;
v3 = compute_counter(v2);
v4 = v3;
v5 = v3;
v6 = (unsigned __int8)m6840_status_read_since_int;
if ( _bittest(&v6, v2) )
m6840_status &= __ROL4__(-2, v2);
update_interrupts();
m6840_lsb_buffer = v4;
result = (unsigned int)(v5 >> 8);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // ebx
unsigned __int16 v3; // ax
char v4; // r12
int v5; // ebp
int v6; // eax

result = a1;
if ( a1 )
{
if ( a1 == 1 )
{
m6840_status_read_since_int |= m6840_status & 7;
result = (unsigned __int8)m6840_status;
}
else
{
result = (unsigned __int8)m6840_lsb_buffer;
if ( (a1 & 1) == 0 )
{
v2 = (a1 - 2) >> 1;
v3 = func16(v2);
v4 = v3;
v5 = v3;
v6 = (unsigned __int8)m6840_status_read_since_int;
if ( _bittest(&v6, v2) )
m6840_status &= __ROL4__(-2, v2);
func6();
m6840_lsb_buffer = v4;
result = (unsigned int)(v5 >> 8);
}
}
}
return result;
}

original_code:
static data_t mcr68_6840_r_common(offs_t offset)
{
 if (offset == 0)
  return 0;
 else if (offset == 1)
 {
  ;
  m6840_status_read_since_int |= m6840_status & 0x07;
  return m6840_status;
 }
 else if ((offset & 1) == 0)
 {
  int counter = (offset - 2) / 2;
  int result = compute_counter(counter);
  if (m6840_status_read_since_int & (1 << counter))
   m6840_status &= ~(1 << counter);
  update_interrupts();
  m6840_lsb_buffer = result & 0xff;
  ;
  return result >> 8;
 }
 else
  return m6840_lsb_buffer;
}

canonical_original_code:
static unsigned int mcr68_6840_r_common(unsigned int offset)
{
 if (offset == 0)
  return 0;
 else if (offset == 1)
 {
  ;
  m6840_status_read_since_int |= m6840_status & 0x07;
  return m6840_status;
 }
 else if ((offset & 1) == 0)
 {
  int counter = (offset - 2) / 2;
  int result = compute_counter(counter);
  if (m6840_status_read_since_int & (1 << counter))
   m6840_status &= ~(1 << counter);
  update_interrupts();
  m6840_lsb_buffer = result & 0xff;
  ;
  return result >> 8;
 }
 else
  return m6840_lsb_buffer;
}

variable_types: result int


decompiled_code:
__int64 mcr_init_machine()
{
dword_E64 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 4LL);
z80ctc_init(&ctc_intf);
mcr_cocktail_flip = 0;
return mcr_sound_init();
}

canonical_decompiled_code:
__int64 func18()
{
dword_E64 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 4LL);
z80ctc_init(&ctc_intf);
mcr_cocktail_flip = 0;
return mcr_sound_init();
}

original_code:
void mcr_init_machine(void)
{
 ctc_intf.baseclock[0] = Machine->drv->cpu[0].cpu_clock;
 z80ctc_init(&ctc_intf);
 mcr_cocktail_flip = 0;
 mcr_sound_init();
}

canonical_original_code:
void mcr_init_machine()
{
 ctc_intf.baseclock[0] = Machine->drv->cpu[0].cpu_clock;
 z80ctc_init(&ctc_intf);
 mcr_cocktail_flip = 0;
 mcr_sound_init();
}


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

mcr68_common_init(a1, a2);
v493_callback = (__int64)zwackery_493_callback;
pia_config(2LL, 6LL, &zwackery_pia_2_intf);
pia_config(3LL, 2LL, &zwackery_pia_3_intf);
pia_config(4LL, 2LL, &zwackery_pia_4_intf);
result = pia_reset();
v493_irq_vector = 5;
m6840_irq_vector = 6;
return result;
}

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

func9(a1, a2);
v493_callback = (__int64)zwackery_493_callback;
pia_config(2LL, 6LL, &zwackery_pia_2_intf);
pia_config(3LL, 2LL, &zwackery_pia_3_intf);
pia_config(4LL, 2LL, &zwackery_pia_4_intf);
result = pia_reset();
v493_irq_vector = 5;
m6840_irq_vector = 6;
return result;
}

original_code:
void zwackery_init_machine(void)
{
 mcr68_common_init();
 v493_callback = zwackery_493_callback;
 pia_config(2, 0 | (2 | 4), &zwackery_pia_2_intf);
 pia_config(3, 0 | (2 | 0), &zwackery_pia_3_intf);
 pia_config(4, 0 | (2 | 0), &zwackery_pia_4_intf);
 pia_reset();
 v493_irq_vector = 5;
 m6840_irq_vector = 6;
}

canonical_original_code:
void zwackery_init_machine()
{
 mcr68_common_init();
 v493_callback = zwackery_493_callback;
 pia_config(2, 0 | (2 | 4), &zwackery_pia_2_intf);
 pia_config(3, 0 | (2 | 0), &zwackery_pia_3_intf);
 pia_config(4, 0 | (2 | 0), &zwackery_pia_4_intf);
 pia_reset();
 v493_irq_vector = 5;
 m6840_irq_vector = 6;
}


decompiled_code:
__int64 mcr_interrupt()
{
z80ctc_0_trg3_w(0LL, 1LL);
z80ctc_0_trg3_w(0LL, 0LL);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func20()
{
z80ctc_0_trg3_w(0LL, 1LL);
z80ctc_0_trg3_w(0LL, 0LL);
return ignore_interrupt();
}

original_code:
int mcr_interrupt(void)
{
 z80ctc_0_trg3_w(0, 1);
 z80ctc_0_trg3_w(0, 0);
 return ignore_interrupt();
}

canonical_original_code:
int mcr_interrupt()
{
 z80ctc_0_trg3_w(0, 1);
 z80ctc_0_trg3_w(0, 0);
 return ignore_interrupt();
}


decompiled_code:
__int64 mcr68_interrupt()
{
if ( !qword_E08 )
subtract_from_counter(0, 1);
timer_set((unsigned int)(35791394 - mcr68_timing_factor), 0LL, v493_callback);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func21()
{
if ( !qword_E08 )
func7(0, 1);
timer_set((unsigned int)(35791394 - mcr68_timing_factor), 0LL, v493_callback);
return ignore_interrupt();
}

original_code:
int mcr68_interrupt(void)
{
 if (!m6840_state[0].timer)
  subtract_from_counter(0, 1);
 timer_set(((1<<30) / ((timer_tm)(30))) - mcr68_timing_factor, 0, v493_callback);
 return ignore_interrupt();
}

canonical_original_code:
int mcr68_interrupt()
{
 if (!m6840_state[0].timer)
  subtract_from_counter(0, 1);
 timer_set(((1<<30) / ((timer_tm)(30))) - mcr68_timing_factor, 0, v493_callback);
 return ignore_interrupt();
}


decompiled_code:
char __fastcall mcr_scroll_value_w(int a1, __int16 a2)
{
void *v2; // rax

switch ( a1 )
{
case 1:
*((_BYTE *)&spyhunt_scrollx + 1) = a2 & 7;
v2 = &spyhunt_scrolly;
*((_BYTE *)&spyhunt_scrolly + 1) = (a2 & 0x80) != 0;
break;
case 2:
BYTE1(v2) = unk_1409;
LOBYTE(v2) = 0;
spyhunt_scrolly = (unsigned __int16)v2 | a2;
break;
case 0:
BYTE1(v2) = unk_1401;
LOBYTE(v2) = 0;
spyhunt_scrollx = (unsigned __int16)v2 | a2;
break;
}
return (char)v2;
}

canonical_decompiled_code:
char __fastcall func22(int a1, __int16 a2)
{
void *v2; // rax

switch ( a1 )
{
case 1:
*((_BYTE *)&spyhunt_scrollx + 1) = a2 & 7;
v2 = &spyhunt_scrolly;
*((_BYTE *)&spyhunt_scrolly + 1) = (a2 & 0x80) != 0;
break;
case 2:
BYTE1(v2) = unk_1409;
LOBYTE(v2) = 0;
spyhunt_scrolly = (unsigned __int16)v2 | a2;
break;
case 0:
BYTE1(v2) = unk_1401;
LOBYTE(v2) = 0;
spyhunt_scrollx = (unsigned __int16)v2 | a2;
break;
}
return (char)v2;
}

original_code:
void mcr_scroll_value_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0:
   spyhunt_scrollx = (spyhunt_scrollx & ~0xff) | data;
   break;
  case 1:
   spyhunt_scrollx = (spyhunt_scrollx & 0xff) | ((data & 0x07) << 8);
   spyhunt_scrolly = (spyhunt_scrolly & 0xff) | ((data & 0x80) << 1);
   break;
  case 2:
   spyhunt_scrolly = (spyhunt_scrolly & ~0xff) | data;
   break;
 }
}

canonical_original_code:
void mcr_scroll_value_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0:
   spyhunt_scrollx = (spyhunt_scrollx & ~0xff) | data;
   break;
  case 1:
   spyhunt_scrollx = (spyhunt_scrollx & 0xff) | ((data & 0x07) << 8);
   spyhunt_scrolly = (spyhunt_scrolly & 0xff) | ((data & 0x80) << 1);
   break;
  case 2:
   spyhunt_scrolly = (spyhunt_scrolly & ~0xff) | data;
   break;
 }
}


decompiled_code:
char *__fastcall mcr68_6840_upper_w(unsigned int a1, int a2)
{
char *result; // rax

if ( (a2 & 0xFF000000) == 0 )
result = mcr68_6840_w_common(a1 >> 1, BYTE1(a2));
return result;
}

canonical_decompiled_code:
char *__fastcall func23(unsigned int a1, int a2)
{
char *result; // rax

if ( (a2 & 0xFF000000) == 0 )
result = func15(a1 >> 1, BYTE1(a2));
return result;
}

original_code:
void mcr68_6840_upper_w(offs_t offset,data_t data)
{
 if (!(data & 0xff000000))
  mcr68_6840_w_common(offset / 2, (data >> 8) & 0xff);
}

canonical_original_code:
void mcr68_6840_upper_w(unsigned int offset, unsigned int data)
{
 if (!(data & 0xff000000))
  mcr68_6840_w_common(offset / 2, (data >> 8) & 0xff);
}


decompiled_code:
char *__fastcall mcr68_6840_lower_w(unsigned int a1, int a2)
{
char *result; // rax

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

canonical_decompiled_code:
char *__fastcall func24(unsigned int a1, int a2)
{
char *result; // rax

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

original_code:
void mcr68_6840_lower_w(offs_t offset,data_t data)
{
 if (!(data & 0x00ff0000))
  mcr68_6840_w_common(offset / 2, data & 0xff);
}

canonical_original_code:
void mcr68_6840_lower_w(unsigned int offset, unsigned int data)
{
 if (!(data & 0x00ff0000))
  mcr68_6840_w_common(offset / 2, data & 0xff);
}


decompiled_code:
char __fastcall mcr68_6840_upper_r(unsigned int a1)
{
mcr68_6840_r_common(a1 >> 1);
return -1;
}

canonical_decompiled_code:
char __fastcall func25(unsigned int a1)
{
func17(a1 >> 1);
return -1;
}

original_code:
data_t mcr68_6840_upper_r(offs_t offset)
{
 return (mcr68_6840_r_common(offset / 2) << 8) | 0x00ff;
}

canonical_original_code:
unsigned int mcr68_6840_upper_r(unsigned int offset)
{
 return (mcr68_6840_r_common(offset / 2) << 8) | 0x00ff;
}


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

result = mcr68_6840_r_common(a1 >> 1);
BYTE1(result) = -1;
return result;
}

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

result = func17(a1 >> 1);
BYTE1(result) = -1;
return result;
}

original_code:
data_t mcr68_6840_lower_r(offs_t offset)
{
 return mcr68_6840_r_common(offset / 2) | 0xff00;
}

canonical_original_code:
unsigned int mcr68_6840_lower_r(unsigned int offset)
{
 return mcr68_6840_r_common(offset / 2) | 0xff00;
}


decompiled_code:
__int64 __fastcall ctc_interrupt(unsigned int a1)
{
return cpu_cause_interrupt(0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return cpu_cause_interrupt(0LL, a1);
}

original_code:
static void ctc_interrupt(int state)
{
 cpu_cause_interrupt(0, (((0)<<8)|(state)));
}


original_code:
static inline void update_interrupts(void)
{
 m6840_status &= ~0x80;
 if ((m6840_status & 0x01) && (m6840_state[0].control & 0x40)) m6840_status |= 0x80;
 if ((m6840_status & 0x02) && (m6840_state[1].control & 0x40)) m6840_status |= 0x80;
 if ((m6840_status & 0x04) && (m6840_state[2].control & 0x40)) m6840_status |= 0x80;
 m6840_irq_state = m6840_status >> 7;
 update_mcr68_interrupts();
}

canonical_original_code:
static inline void update_interrupts()
{
 m6840_status &= ~0x80;
 if ((m6840_status & 0x01) && (m6840_state[0].control & 0x40)) m6840_status |= 0x80;
 if ((m6840_status & 0x02) && (m6840_state[1].control & 0x40)) m6840_status |= 0x80;
 if ((m6840_status & 0x04) && (m6840_state[2].control & 0x40)) m6840_status |= 0x80;
 m6840_irq_state = m6840_status >> 7;
 update_mcr68_interrupts();
}


original_code:
static void get_tile_info_A(int tile_index)
{
 int attr = k007121_ram[tile_index];
 int code = k007121_ram[tile_index+0x400];
 int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
 int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
 int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
 int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
 int bank = ((attr & 0x80) >> 7) |
   ((attr >> (bit0+2)) & 0x02) |
   ((attr >> (bit1+1)) & 0x04) |
   ((attr >> (bit2 )) & 0x08) |
   ((attr >> (bit3-1)) & 0x10) |
   ((K007121_ctrlram[0][0x03] & 0x01) << 5);
 int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
 bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
 if ((attr == 0x0d) && (!(K007121_ctrlram[0][0])) && (!(K007121_ctrlram[0][2])))
  bank = 0;
 tile_info.flags = (attr & 0x20) ? 0x02 : 0;
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code + 256*bank) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x0f) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_tile_info_A(int tile_index)
{
 int attr = k007121_ram[tile_index];
 int code = k007121_ram[tile_index+0x400];
 int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
 int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
 int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
 int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
 int bank = ((attr & 0x80) >> 7) |
   ((attr >> (bit0+2)) & 0x02) |
   ((attr >> (bit1+1)) & 0x04) |
   ((attr >> (bit2 )) & 0x08) |
   ((attr >> (bit3-1)) & 0x10) |
   ((K007121_ctrlram[0][0x03] & 0x01) << 5);
 int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
 bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
 if ((attr == 0x0d) && (!(K007121_ctrlram[0][0])) && (!(K007121_ctrlram[0][2])))
  bank = 0;
 tile_info.flags = (attr & 0x20) ? 0x02 : 0;
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code + 256*bank) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x0f) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types: attr int

variable_types: code int

variable_types: bank int

variable_types: mask 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:
__int64 __fastcall get_tile_info_B(int a1)
{
char v1; // si
__int64 v2; // rcx
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(k007121_ram + a1 + 2048LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (unsigned int)*(unsigned __int8 *)(k007121_ram + a1 + 3072LL) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * ((v1 & 0xF) + 16);
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 func1(int a1)
{
char v1; // si
__int64 v2; // rcx
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(k007121_ram + a1 + 2048LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (unsigned int)*(unsigned __int8 *)(k007121_ram + a1 + 3072LL) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * ((v1 & 0xF) + 16);
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_tile_info_B(int tile_index)
{
 int attr = k007121_ram[tile_index+0x800];
 int code = k007121_ram[tile_index+0xc00];
 { 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 * ((attr & 0x0f) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_tile_info_B(int tile_index)
{
 int attr = k007121_ram[tile_index+0x800];
 int code = k007121_ram[tile_index+0xc00];
 { 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 * ((attr & 0x0f) + 16)]; 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 flkatck_vh_start()
{
__int64 v1; // [rsp+0h] [rbp-28h]
__m128i v2; // [rsp+10h] [rbp-18h] BYREF

k007121_tilemap = tilemap_create(get_tile_info_A, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v1) = 32;
qword_8C8 = tilemap_create(get_tile_info_B, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, v1);
if ( !qword_8C8 || !k007121_tilemap )
return 1LL;
v2 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v2.m128i_i32[0] += 40;
tilemap_set_clip(k007121_tilemap, &v2);
v2.m128i_i64[0] = 0x2700000000LL;
tilemap_set_clip(qword_8C8, &v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v1; // [rsp+0h] [rbp-28h]
__m128i v2; // [rsp+10h] [rbp-18h] BYREF

k007121_tilemap = tilemap_create(get_tile_info_A, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v1) = 32;
qword_8C8 = tilemap_create(get_tile_info_B, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, v1);
if ( !qword_8C8 || !k007121_tilemap )
return 1LL;
v2 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v2.m128i_i32[0] += 40;
tilemap_set_clip(k007121_tilemap, &v2);
v2.m128i_i64[0] = 0x2700000000LL;
tilemap_set_clip(qword_8C8, &v2);
return 0LL;
}

original_code:
int flkatck_vh_start(void)
{
 k007121_tilemap[0] = tilemap_create(get_tile_info_A,tilemap_scan_rows,0x00,8,8,32,32);
 k007121_tilemap[1] = tilemap_create(get_tile_info_B,tilemap_scan_rows,0x00,8,8,32,32);
 if (!k007121_tilemap[0] || !k007121_tilemap[1])
  return 1;
 {
  struct rectangle clip = Machine->visible_area;
  clip.min_x += 40;
  tilemap_set_clip(k007121_tilemap[0],&clip);
  clip.max_x = 39;
  clip.min_x = 0;
  tilemap_set_clip(k007121_tilemap[1],&clip);
  return 0;
 }
}

canonical_original_code:
int flkatck_vh_start()
{
 k007121_tilemap[0] = tilemap_create(get_tile_info_A,tilemap_scan_rows,0x00,8,8,32,32);
 k007121_tilemap[1] = tilemap_create(get_tile_info_B,tilemap_scan_rows,0x00,8,8,32,32);
 if (!k007121_tilemap[0] || !k007121_tilemap[1])
  return 1;
 {
  struct rectangle clip = Machine->visible_area;
  clip.min_x += 40;
  tilemap_set_clip(k007121_tilemap[0],&clip);
  clip.max_x = 39;
  clip.min_x = 0;
  tilemap_set_clip(k007121_tilemap[1],&clip);
  return 0;
 }
}

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


decompiled_code:
__int64 __fastcall flkatck_k007121_regs_w(unsigned int a1, unsigned int a2)
{
__int64 v4; // rsi

if ( a1 == 4 )
{
if ( (unsigned __int8)K007121_ctrlram[4] != a2 )
tilemap_mark_all_tiles_dirty(0LL);
}
else if ( a1 == 7 )
{
v4 = a2 & 8;
if ( (_DWORD)v4 )
v4 = 3LL;
tilemap_set_flip(0LL, v4);
flkatck_irq_enabled = a2 & 2;
}
return K007121_ctrl_0_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
__int64 v4; // rsi

if ( a1 == 4 )
{
if ( (unsigned __int8)K007121_ctrlram[4] != a2 )
tilemap_mark_all_tiles_dirty(0LL);
}
else if ( a1 == 7 )
{
v4 = a2 & 8;
if ( (_DWORD)v4 )
v4 = 3LL;
tilemap_set_flip(0LL, v4);
flkatck_irq_enabled = a2 & 2;
}
return K007121_ctrl_0_w(a1, a2);
}

original_code:
void flkatck_k007121_regs_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0x04:
   if (data != K007121_ctrlram[0][0x04])
    tilemap_mark_all_tiles_dirty(0);
   break;
  case 0x07:
   k007121_flip_screen = data & 0x08;
   tilemap_set_flip(0, k007121_flip_screen ? (0x2 | 0x1) : 0);
   flkatck_irq_enabled = data & 0x02;
   break;
 }
 K007121_ctrl_0_w(offset,data);
}

canonical_original_code:
void flkatck_k007121_regs_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0x04:
   if (data != K007121_ctrlram[0][0x04])
    tilemap_mark_all_tiles_dirty(0);
   break;
  case 0x07:
   k007121_flip_screen = data & 0x08;
   tilemap_set_flip(0, k007121_flip_screen ? (0x2 | 0x1) : 0);
   flkatck_irq_enabled = data & 0x02;
   break;
 }
 K007121_ctrl_0_w(offset,data);
}


decompiled_code:
__int64 __fastcall flkatck_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
K007121_mark_sprites_colors(0LL, k007121_ram + 4096LL, 0LL, 0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_set_scrollx(k007121_tilemap, 0LL, (unsigned int)K007121_ctrlram[0] - 40);
tilemap_set_scrolly(k007121_tilemap, 0LL, (unsigned __int8)K007121_ctrlram[2]);
tilemap_draw(a1, k007121_tilemap, 0LL);
K007121_sprites_draw(0LL, a1, k007121_ram + 4096LL, 0LL, 40LL, 0LL, -1LL);
return tilemap_draw(a1, qword_8C8, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
K007121_mark_sprites_colors(0LL, k007121_ram + 4096LL, 0LL, 0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_set_scrollx(k007121_tilemap, 0LL, (unsigned int)K007121_ctrlram[0] - 40);
tilemap_set_scrolly(k007121_tilemap, 0LL, (unsigned __int8)K007121_ctrlram[2]);
tilemap_draw(a1, k007121_tilemap, 0LL);
K007121_sprites_draw(0LL, a1, k007121_ram + 4096LL, 0LL, 40LL, 0LL, -1LL);
return tilemap_draw(a1, qword_8C8, 0LL);
}

original_code:
void flkatck_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update( 0 );
 palette_init_used_colors();
 K007121_mark_sprites_colors(0,&k007121_ram[0x1000],0,0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_set_scrollx(k007121_tilemap[0],0,K007121_ctrlram[0][0x00] - 40);
 tilemap_set_scrolly(k007121_tilemap[0],0,K007121_ctrlram[0][0x02]);
 tilemap_draw(bitmap,k007121_tilemap[0],0);
 K007121_sprites_draw(0,bitmap,&k007121_ram[0x1000],0,40,0,-1);
 tilemap_draw(bitmap,k007121_tilemap[1],0);
}

canonical_original_code:
void flkatck_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update( 0 );
 palette_init_used_colors();
 K007121_mark_sprites_colors(0,&k007121_ram[0x1000],0,0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_set_scrollx(k007121_tilemap[0],0,K007121_ctrlram[0][0x00] - 40);
 tilemap_set_scrolly(k007121_tilemap[0],0,K007121_ctrlram[0][0x02]);
 tilemap_draw(bitmap,k007121_tilemap[0],0);
 K007121_sprites_draw(0,bitmap,&k007121_ram[0x1000],0,40,0,-1);
 tilemap_draw(bitmap,k007121_tilemap[1],0);
}

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


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

result = 1LL;
if ( !flkatck_irq_enabled )
result = ignore_interrupt();
return result;
}

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

result = 1LL;
if ( !flkatck_irq_enabled )
result = ignore_interrupt();
return result;
}

original_code:
static int flkatck_interrupt( void )
{
 if (flkatck_irq_enabled)
  return 1;
 else
  return ignore_interrupt();
}

canonical_original_code:
static int flkatck_interrupt()
{
 if (flkatck_irq_enabled)
  return 1;
 else
  return ignore_interrupt();
}


decompiled_code:
__int64 flkatck_init_machine()
{
__int64 v0; // rax

v0 = memory_region(146LL);
return K007232_bankswitch(0LL, v0, v0 + 0x20000);
}

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

v0 = memory_region(146LL);
return K007232_bankswitch(0LL, v0, v0 + 0x20000);
}

original_code:
static void flkatck_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A, bank_B;
 bank_A = 0x20000 * 0;
 bank_B = 0x20000 * 1;
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
}

canonical_original_code:
static void flkatck_init_machine()
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A; int bank_B;
 bank_A = 0x20000 * 0;
 bank_B = 0x20000 * 1;
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *__fastcall flkatck_ls138_w(unsigned int a1, char a2)
{
unsigned int v2; // edi
void *result; // rax

v2 = (a1 >> 2) & 7;
if ( v2 == 6 )
return (void *)cpu_cause_interrupt(1LL, 4294966296LL);
if ( v2 > 6 )
return (void *)watchdog_reset_w(0LL);
if ( v2 == 4 )
return flkatck_bankswitch_w(0LL, a2);
if ( v2 == 5 )
result = (void *)soundlatch_w(0LL);
return result;
}

canonical_decompiled_code:
void *__fastcall func9(unsigned int a1, char a2)
{
unsigned int v2; // edi
void *result; // rax

v2 = (a1 >> 2) & 7;
if ( v2 == 6 )
return (void *)cpu_cause_interrupt(1LL, 4294966296LL);
if ( v2 > 6 )
return (void *)watchdog_reset_w(0LL);
if ( v2 == 4 )
return func8(0LL, a2);
if ( v2 == 5 )
result = (void *)soundlatch_w(0LL);
return result;
}

original_code:
static void flkatck_ls138_w(offs_t offset,data_t data)
{
 switch ((offset & 0x1c) >> 2){
  case 0x04:
   flkatck_bankswitch_w(0, data);
   break;
  case 0x05:
   soundlatch_w(0, data);
   break;
  case 0x06:
   cpu_cause_interrupt(1,-1000);
   break;
  case 0x07:
   watchdog_reset_w(0, data);
   break;
 }
}

canonical_original_code:
static void flkatck_ls138_w(unsigned int offset, unsigned int data)
{
 switch ((offset & 0x1c) >> 2){
  case 0x04:
   flkatck_bankswitch_w(0, data);
   break;
  case 0x05:
   soundlatch_w(0, data);
   break;
  case 0x06:
   cpu_cause_interrupt(1,-1000);
   break;
  case 0x07:
   watchdog_reset_w(0, data);
   break;
 }
}


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

if ( ((a1 >> 2) & 7) != 0 )
{
if ( ((a1 >> 2) & 7) == 1 )
{
result = 0LL;
if ( (a1 & 2) != 0 )
result = readinputport(((unsigned __int8)a1 ^ 1) & 1);
}
else
{
result = 0LL;
}
}
else if ( (a1 & 2) != 0 )
{
result = readinputport((a1 & 1) + 2);
}
else
{
result = readinputport((a1 & 1) + 4);
}
return result;
}

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

if ( ((a1 >> 2) & 7) != 0 )
{
if ( ((a1 >> 2) & 7) == 1 )
{
result = 0LL;
if ( (a1 & 2) != 0 )
result = readinputport(((unsigned __int8)a1 ^ 1) & 1);
}
else
{
result = 0LL;
}
}
else if ( (a1 & 2) != 0 )
{
result = readinputport((a1 & 1) + 2);
}
else
{
result = readinputport((a1 & 1) + 4);
}
return result;
}

original_code:
static data_t flkatck_ls138_r(offs_t offset)
{
 int data = 0;
 switch ((offset & 0x1c) >> 2){
  case 0x00:
   if (offset & 0x02)
    data = readinputport(2 + (offset & 0x01));
   else
    data = readinputport(4 + (offset & 0x01));
   break;
  case 0x01:
   if (offset & 0x02)
    data = readinputport(1 - (offset & 0x01));
   break;
 }
 return data;
}

canonical_original_code:
static unsigned int flkatck_ls138_r(unsigned int offset)
{
 int data = 0;
 switch ((offset & 0x1c) >> 2){
  case 0x00:
   if (offset & 0x02)
    data = readinputport(2 + (offset & 0x01));
   else
    data = readinputport(4 + (offset & 0x01));
   break;
  case 0x01:
   if (offset & 0x02)
    data = readinputport(1 - (offset & 0x01));
   break;
 }
 return data;
}

variable_types: data int


decompiled_code:
__int64 __fastcall volume_callback0(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

variable_types: v int


decompiled_code:
void __fastcall ttmahjng_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
ttmahjng_color_prom = a3;
}

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

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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

if ( last_write_0 != a2 )
{
video_color_select_2 = (4 * (_BYTE)a2) & 0x7C;
result = a2 >> 5;
if ( ((a2 & 0x20) != 0) != video_flip )
video_flip = (a2 & 0x20) != 0;
video_remap_2 = 1;
last_write_0 = a2;
}
return result;
}

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

if ( last_write_0 != a2 )
{
video_color_select_2 = (4 * (_BYTE)a2) & 0x7C;
result = a2 >> 5;
if ( ((a2 & 0x20) != 0) != video_flip )
video_flip = (a2 & 0x20) != 0;
video_remap_2 = 1;
last_write_0 = a2;
}
return result;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

original_code:
data_t ttmahjng_sharedram_r(offs_t offset)
{
 return ttmahjng_sharedram[offset];
}

canonical_original_code:
unsigned int ttmahjng_sharedram_r(unsigned int offset)
{
 return ttmahjng_sharedram[offset];
}


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

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

original_code:
data_t ttmahjng_videoram2_r(offs_t offset)
{
 return ttmahjng_videoram1[offset];
}

canonical_original_code:
unsigned int ttmahjng_videoram2_r(unsigned int offset)
{
 return ttmahjng_videoram1[offset];
}


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

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

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

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


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

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
*(_BYTE *)(ttmahjng_videoram2 + a1) = a2;
return func6(a1, a2, 4, tmpbitmap2);
}

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

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


decompiled_code:
void __fastcall input_port_matrix_w(__int64 a1, int a2)
{
psel = a2;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2)
{
psel = a2;
}

original_code:
void input_port_matrix_w(offs_t offset,data_t data)
{
 psel = data;
}

canonical_original_code:
void input_port_matrix_w(unsigned int offset, unsigned int data)
{
 psel = data;
}


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

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

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

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

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

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


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

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

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

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


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

if ( last_write_1 != a2 )
{
video_color_select_1 = (4 * (_BYTE)a2) & 0x7C;
result = coin_counter_w(0LL, a2 & 0x20);
video_remap_1 = 1;
last_write_1 = a2;
}
return result;
}

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

if ( last_write_1 != a2 )
{
video_color_select_1 = (4 * (_BYTE)a2) & 0x7C;
result = coin_counter_w(0LL, a2 & 0x20);
video_remap_1 = 1;
last_write_1 = a2;
}
return result;
}

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

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


decompiled_code:
__int64 __fastcall ttmahjng_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( video_remap_1 )
{
modify_pen(0LL, video_color_select_1);
modify_pen(1LL, video_color_select_1 + 1);
modify_pen(2LL, video_color_select_1 + 2);
modify_pen(3LL, video_color_select_1 + 3);
}
if ( video_remap_2 )
{
modify_pen(4LL, video_color_select_2);
modify_pen(5LL, video_color_select_2 + 1);
modify_pen(6LL, video_color_select_2 + 2);
modify_pen(7LL, video_color_select_2 + 3);
}
if ( palette_recalc() || __PAIR64__(video_remap_1, video_remap_2) )
{
if ( ttmahjng_videoram_size )
{
v1 = 0LL;
do
{
ttmahjng_videoram1_w(v1, *(unsigned __int8 *)(ttmahjng_videoram1 + v1));
ttmahjng_videoram2_w(v1, *(unsigned __int8 *)(ttmahjng_videoram2 + v1));
++v1;
}
while ( ttmahjng_videoram_size > v1 );
}
}
video_remap_1 = 0;
video_remap_2 = 0;
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}

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

if ( video_remap_1 )
{
func13(0LL, video_color_select_1);
func13(1LL, video_color_select_1 + 1);
func13(2LL, video_color_select_1 + 2);
func13(3LL, video_color_select_1 + 3);
}
if ( video_remap_2 )
{
func13(4LL, video_color_select_2);
func13(5LL, video_color_select_2 + 1);
func13(6LL, video_color_select_2 + 2);
func13(7LL, video_color_select_2 + 3);
}
if ( palette_recalc() || __PAIR64__(video_remap_1, video_remap_2) )
{
if ( ttmahjng_videoram_size )
{
v1 = 0LL;
do
{
func7(v1, *(unsigned __int8 *)(ttmahjng_videoram1 + v1));
func8(v1, *(unsigned __int8 *)(ttmahjng_videoram2 + v1));
++v1;
}
while ( ttmahjng_videoram_size > v1 );
}
}
video_remap_1 = 0;
video_remap_2 = 0;
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return copybitmap(a1, tmpbitmap1, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}

original_code:
void ttmahjng_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (video_remap_1)
 {
  modify_pen(0, video_color_select_1 + 0);
  modify_pen(1, video_color_select_1 + 1);
  modify_pen(2, video_color_select_1 + 2);
  modify_pen(3, video_color_select_1 + 3);
 }
 if (video_remap_2)
 {
  modify_pen(4, video_color_select_2 + 0);
  modify_pen(5, video_color_select_2 + 1);
  modify_pen(6, video_color_select_2 + 2);
  modify_pen(7, video_color_select_2 + 3);
 }
 if (palette_recalc() || video_remap_1 || video_remap_2)
 {
  int offs;
  for (offs = 0; offs < ttmahjng_videoram_size; offs++)
  {
   ttmahjng_videoram1_w(offs, ttmahjng_videoram1[offs]);
   ttmahjng_videoram2_w(offs, ttmahjng_videoram2[offs]);
  }
 }
 video_remap_1 = 0;
 video_remap_2 = 0;
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 copybitmap(bitmap,tmpbitmap1,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
}

canonical_original_code:
void ttmahjng_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (video_remap_1)
 {
  modify_pen(0, video_color_select_1 + 0);
  modify_pen(1, video_color_select_1 + 1);
  modify_pen(2, video_color_select_1 + 2);
  modify_pen(3, video_color_select_1 + 3);
 }
 if (video_remap_2)
 {
  modify_pen(4, video_color_select_2 + 0);
  modify_pen(5, video_color_select_2 + 1);
  modify_pen(6, video_color_select_2 + 2);
  modify_pen(7, video_color_select_2 + 3);
 }
 if (palette_recalc() || video_remap_1 || video_remap_2)
 {
  int offs;
  for (offs = 0; offs < ttmahjng_videoram_size; offs++)
  {
   ttmahjng_videoram1_w(offs, ttmahjng_videoram1[offs]);
   ttmahjng_videoram2_w(offs, ttmahjng_videoram2[offs]);
  }
 }
 video_remap_1 = 0;
 video_remap_2 = 0;
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 copybitmap(bitmap,tmpbitmap1,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
}

variable_types: offs int


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

if ( psel == 4 )
return readinputport(4LL);
if ( psel > 4 )
{
if ( psel == 8 )
result = readinputport(5LL);
else
result = 0LL;
}
else if ( psel == 1 )
{
result = readinputport(2LL);
}
else if ( psel == 2 )
{
result = readinputport(3LL);
}
else
{
result = 0LL;
}
return result;
}

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

if ( psel == 4 )
return readinputport(4LL);
if ( psel > 4 )
{
if ( psel == 8 )
result = readinputport(5LL);
else
result = 0LL;
}
else if ( psel == 1 )
{
result = readinputport(2LL);
}
else if ( psel == 2 )
{
result = readinputport(3LL);
}
else
{
result = 0LL;
}
return result;
}

original_code:
data_t input_port_matrix_r(offs_t offset)
{
 int cdata;
 cdata = 0;
 switch (psel)
 {
  case 1:
   cdata = readinputport(2);
   break;
  case 2:
   cdata = readinputport(3);
   break;
  case 4:
   cdata = readinputport(4);
   break;
  case 8:
   cdata = readinputport(5);
   break;
  default:
   break;
 }
 return cdata;
}

canonical_original_code:
unsigned int input_port_matrix_r(unsigned int offset)
{
 int cdata;
 cdata = 0;
 switch (psel)
 {
  case 1:
   cdata = readinputport(2);
   break;
  case 2:
   cdata = readinputport(3);
   break;
  case 4:
   cdata = readinputport(4);
   break;
  case 8:
   cdata = readinputport(5);
   break;
  default:
   break;
 }
 return cdata;
}

variable_types: cdata int


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

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

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

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

variable_types: offset int

variable_types: coloroffset int

variable_types: x int

variable_types: y int


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

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

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

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

variable_types: pen int

variable_types: colorindex int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: color int


decompiled_code:
__int64 __fastcall draw_lasso(__int64 a1)
{
unsigned int v1; // er15
int k; // ebx
int v3; // ebx
int j; // er12
unsigned __int8 *v5; // r13
int v6; // ebp
__int64 result; // rax
unsigned int i; // [rsp+0h] [rbp-48h]
unsigned __int8 *v9; // [rsp+8h] [rbp-40h]

v9 = (unsigned __int8 *)lasso_vram;
v1 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 126LL);
for ( i = 255; i != -1; result = i )
{
v5 = v9;
for ( j = 0; j != 256; j += 8 )
{
v6 = *v5++;
if ( *(v5 - 1) )
{
v3 = flipscreen;
if ( flipscreen )
{
for ( k = 0; k != 8; ++k )
{
if ( ((v6 << k) & 0x80u) != 0 )
plot_pixel(a1, (unsigned int)(255 - j - k), i, v1);
}
}
else
{
do
{
if ( ((v6 << v3) & 0x80u) != 0 )
plot_pixel(a1, (unsigned int)(v3 + j), 255 - i, v1);
++v3;
}
while ( v3 != 8 );
}
}
}
v9 += 32;
--i;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // er15
int k; // ebx
int v3; // ebx
int j; // er12
unsigned __int8 *v5; // r13
int v6; // ebp
__int64 result; // rax
unsigned int i; // [rsp+0h] [rbp-48h]
unsigned __int8 *v9; // [rsp+8h] [rbp-40h]

v9 = (unsigned __int8 *)lasso_vram;
v1 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 126LL);
for ( i = 255; i != -1; result = i )
{
v5 = v9;
for ( j = 0; j != 256; j += 8 )
{
v6 = *v5++;
if ( *(v5 - 1) )
{
v3 = flipscreen;
if ( flipscreen )
{
for ( k = 0; k != 8; ++k )
{
if ( ((v6 << k) & 0x80u) != 0 )
plot_pixel(a1, (unsigned int)(255 - j - k), i, v1);
}
}
else
{
do
{
if ( ((v6 << v3) & 0x80u) != 0 )
plot_pixel(a1, (unsigned int)(v3 + j), 255 - i, v1);
++v3;
}
while ( v3 != 8 );
}
}
}
v9 += 32;
--i;
}
return result;
}

original_code:
static void draw_lasso( struct osd_bitmap *bitmap )
{
 const unsigned char *source = lasso_vram;
 int x,y;
 int pen = Machine->pens[0x3f];
 for( y=0; y<256; y++ )
 {
  for( x=0; x<256; x+=8 )
  {
   int data = *source++;
   if( data )
   {
    int bit;
    if( flipscreen )
    {
     for( bit=0; bit<8; bit++ )
     {
      if( (data<<bit)&0x80 )
       plot_pixel( bitmap, 255-(x+bit), 255-y, pen );
     }
    }
    else
    {
     for( bit=0; bit<8; bit++ )
     {
      if( (data<<bit)&0x80 )
       plot_pixel( bitmap, x+bit, y, pen );
     }
    }
   }
  }
 }
}

canonical_original_code:
static void draw_lasso(struct osd_bitmap *bitmap)
{
 unsigned char *source = lasso_vram;
 int x; int y;
 int pen = Machine->pens[0x3f];
 for( y=0; y<256; y++ )
 {
  for( x=0; x<256; x+=8 )
  {
   int data = *source++;
   if( data )
   {
    int bit;
    if( flipscreen )
    {
     for( bit=0; bit<8; bit++ )
     {
      if( (data<<bit)&0x80 )
       plot_pixel( bitmap, 255-(x+bit), 255-y, pen );
     }
    }
    else
    {
     for( bit=0; bit<8; bit++ )
     {
      if( (data<<bit)&0x80 )
       plot_pixel( bitmap, x+bit, y, pen );
     }
    }
   }
  }
 }
}

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

variable_types:
source
unsigned char *

variable_types: data int

variable_types: bit int


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

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

original_code:
static data_t shareram_r(offs_t offset)
{
 return shareram[offset];
}

canonical_original_code:
static unsigned int shareram_r(unsigned int offset)
{
 return shareram[offset];
}

variable_types:
offset
unsigned int


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

result = (unsigned __int8)((_BYTE)a2 << 7);
lasso_chip_data = result | (32 * (_BYTE)a2) & 0x40 | (8 * (_BYTE)a2) & 0x20 | (2 * (_BYTE)a2) & 0x10 | (a2 >> 1) & 8 | (a2 >> 3) & 4 | (a2 >> 5) & 2 | (a2 >> 7) & 1;
return result;
}

variable_types:
data
unsigned int


decompiled_code:
_BOOL8 lasso_vh_start()
{
background = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return background == 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
background = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return background == 0;
}

original_code:
int lasso_vh_start( void )
{
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!background)
  return 1;
 return 0;
}

canonical_original_code:
int lasso_vh_start()
{
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!background)
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall lasso_cocktail_w(__int64 a1, unsigned int a2)
{
__int64 v3; // rsi
unsigned int v4; // ebx
__int64 result; // rax

v3 = a2 & 1;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
v4 = a2 >> 2;
result = v4 & 1;
if ( (_DWORD)result != gfxbank )
{
gfxbank = v4 & 1;
result = tilemap_mark_all_tiles_dirty(0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 v3; // rsi
unsigned int v4; // ebx
__int64 result; // rax

v3 = a2 & 1;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
v4 = a2 >> 2;
result = v4 & 1;
if ( (_DWORD)result != gfxbank )
{
gfxbank = v4 & 1;
result = tilemap_mark_all_tiles_dirty(0LL);
}
return result;
}

original_code:
void lasso_cocktail_w(offs_t offset,data_t data)
{
 flipscreen = data & 0x01;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 if (gfxbank != ((data & 0x04) >> 2))
 {
  gfxbank = (data & 0x04) >> 2;
  tilemap_mark_all_tiles_dirty(0);
 }
}

canonical_original_code:
void lasso_cocktail_w(unsigned int offset, unsigned int data)
{
 flipscreen = data & 0x01;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 if (gfxbank != ((data & 0x04) >> 2))
 {
  gfxbank = (data & 0x04) >> 2;
  tilemap_mark_all_tiles_dirty(0);
 }
}


original_code:
void lasso_backcolor_w(offs_t offset,data_t data)
{
 int i,bit0,bit1,bit2,r,g,b;
 bit0 = (data >> 0) & 0x01;
 bit1 = (data >> 1) & 0x01;
 bit2 = (data >> 2) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (data >> 3) & 0x01;
 bit1 = (data >> 4) & 0x01;
 bit2 = (data >> 5) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (data >> 6) & 0x01;
 bit1 = (data >> 7) & 0x01;
 b = 0x4f * bit0 + 0xa8 * bit1;
 for( i=0; i<0x40; i+=4 )
  palette_change_color( i,r,g,b );
}

canonical_original_code:
void lasso_backcolor_w(unsigned int offset, unsigned int data)
{
 int i; int bit0; int bit1; int bit2; int r; int g; int b;
 bit0 = (data >> 0) & 0x01;
 bit1 = (data >> 1) & 0x01;
 bit2 = (data >> 2) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (data >> 3) & 0x01;
 bit1 = (data >> 4) & 0x01;
 bit2 = (data >> 5) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (data >> 6) & 0x01;
 bit1 = (data >> 7) & 0x01;
 b = 0x4f * bit0 + 0xa8 * bit1;
 for( i=0; i<0x40; i+=4 )
  palette_change_color( i,r,g,b );
}

variable_types: i int


decompiled_code:
__int64 __fastcall lasso_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, background, 0LL);
draw_lasso(a1);
return draw_sprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, background, 0LL);
func2(a1);
return func10(a1);
}

original_code:
void lasso_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,background,0);
 draw_lasso(bitmap);
 draw_sprites(bitmap);
}

canonical_original_code:
void lasso_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,background,0);
 draw_lasso(bitmap);
 draw_sprites(bitmap);
}

variable_types: fullrefresh int


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

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

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

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

original_code:
int lasso_interrupt( void )
{
 if (cpu_getiloops() == 0)
  return interrupt();
 else
  return nmi_interrupt();
}

canonical_original_code:
int lasso_interrupt()
{
 if (cpu_getiloops() == 0)
  return interrupt();
 else
  return nmi_interrupt();
}


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

if ( (a2 & 1) == 0 )
result = SN76496_0_w(0LL, (unsigned int)lasso_chip_data);
if ( (a2 & 2) == 0 )
result = SN76496_1_w(0LL, (unsigned int)lasso_chip_data);
return result;
}

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

if ( (a2 & 1) == 0 )
result = SN76496_0_w(0LL, (unsigned int)lasso_chip_data);
if ( (a2 & 2) == 0 )
result = SN76496_1_w(0LL, (unsigned int)lasso_chip_data);
return result;
}

original_code:
static void sound_select_w(offs_t offset,data_t data)
{
 if (~data & 0x01)
  SN76496_0_w(0,lasso_chip_data);
 if (~data & 0x02)
  SN76496_1_w(0,lasso_chip_data);
}

canonical_original_code:
static void sound_select_w(unsigned int offset, unsigned int data)
{
 if (~data & 0x01)
  SN76496_0_w(0,lasso_chip_data);
 if (~data & 0x02)
  SN76496_1_w(0,lasso_chip_data);
}


decompiled_code:
__int64 lasso_sound_command_w()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 func14()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, 4294966296LL);
}

original_code:
static void lasso_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 cpu_cause_interrupt( 2, -1000 );
}

canonical_original_code:
static void lasso_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 cpu_cause_interrupt( 2, -1000 );
}


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

v1 = *(_BYTE *)(videoram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 8LL * gfxbank + 512);
v3 = (unsigned int)*(unsigned __int8 *)(videoram + a1) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 & 0xF);
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 func1(int a1)
{
char v1; // si
__int64 v2; // rcx
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_BYTE *)(videoram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 8LL * gfxbank + 512);
v3 = (unsigned int)*(unsigned __int8 *)(videoram + a1) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 & 0xF);
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_bg_tile_info(int tile_index)
{
 int tile_number = videoram[tile_index];
 int attributes = videoram[tile_index+0x400];
 { const struct GfxElement *gfx = Machine->gfx[(gfxbank)]; int _code = (tile_number) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attributes&0xf)]; 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 tile_number = videoram[tile_index];
 int attributes = videoram[tile_index+0x400];
 { struct GfxElement *gfx = Machine->gfx[(gfxbank)]; int _code = (tile_number) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attributes&0xf)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types: attributes 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; } *