decompiled_code:
__int64 __fastcall vigilant_paletteram_w(unsigned int a1, char a2)
{
unsigned __int8 v2; // al
int v3; // edi

v2 = a1;
*(_BYTE *)(paletteram + a1) = a2;
v3 = a1 & 0x400;
return palette_change_color(
(unsigned int)v2 + (v3 >> 2),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + (v2 | (unsigned int)v3))),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + (v2 | (unsigned int)v3) + 256)),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + (v2 | (unsigned int)v3) + 512)));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
unsigned __int8 v2; // al
int v3; // edi

v2 = a1;
*(_BYTE *)(paletteram + a1) = a2;
v3 = a1 & 0x400;
return palette_change_color(
(unsigned int)v2 + (v3 >> 2),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + (v2 | (unsigned int)v3))),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + (v2 | (unsigned int)v3) + 256)),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + (v2 | (unsigned int)v3) + 512)));
}

original_code:
void vigilant_paletteram_w(offs_t offset,data_t data)
{
 int bank,r,g,b;
 paletteram[offset] = data;
 bank = offset & 0x400;
 offset &= 0xff;
 r = (paletteram[bank + offset + 0x000] << 3) & 0xFF;
 g = (paletteram[bank + offset + 0x100] << 3) & 0xFF;
 b = (paletteram[bank + offset + 0x200] << 3) & 0xFF;
 palette_change_color((bank >> 2) + offset,r,g,b);
}

canonical_original_code:
void vigilant_paletteram_w(unsigned int offset, unsigned int data)
{
 int bank; int r; int g; int b;
 paletteram[offset] = data;
 bank = offset & 0x400;
 offset &= 0xff;
 r = (paletteram[bank + offset + 0x000] << 3) & 0xFF;
 g = (paletteram[bank + offset + 0x100] << 3) & 0xFF;
 b = (paletteram[bank + offset + 0x200] << 3) & 0xFF;
 palette_change_color((bank >> 2) + offset,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void vigilant_bank_select_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void vigilant_bank_select_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: bankaddress int

variable_types:
RAM
unsigned char *

return_type: void


decompiled_code:
__int64 __fastcall vigilant_out2_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 2);
return coin_counter_w(1LL, a2 & 4);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 2);
return coin_counter_w(1LL, a2 & 4);
}

original_code:
void vigilant_out2_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x04);
}

canonical_original_code:
void vigilant_out2_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x04);
}


decompiled_code:
__int64 __fastcall kikcubic_coin_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

original_code:
void kikcubic_coin_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void kikcubic_coin_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 update_background()
{
unsigned int i; // er15
__int64 v1; // r12
int v2; // er13
unsigned int v3; // ebx
__int64 v4; // rbp
__int64 result; // rax

for ( i = 0; i != 1536; i += 512 )
{
v2 = 8 * i + 16;
v1 = 0LL;
do
{
v3 = v2 - 16;
v4 = i;
do
{
result = drawgfx(bg_bitmap, *(_QWORD *)(Machine + 528LL), v3++, (int)v1 > 127, 0LL, 0LL, v4, v1, 0LL, 0LL, 0LL);
v4 = (unsigned int)(v4 + 32);
}
while ( v3 != v2 );
v1 = (unsigned int)(v1 + 1);
v2 += 16;
}
while ( (_DWORD)v1 != 256 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int i; // er15
__int64 v1; // r12
int v2; // er13
unsigned int v3; // ebx
__int64 v4; // rbp
__int64 result; // rax

for ( i = 0; i != 1536; i += 512 )
{
v2 = 8 * i + 16;
v1 = 0LL;
do
{
v3 = v2 - 16;
v4 = i;
do
{
result = drawgfx(bg_bitmap, *(_QWORD *)(Machine + 528LL), v3++, (int)v1 > 127, 0LL, 0LL, v4, v1, 0LL, 0LL, 0LL);
v4 = (unsigned int)(v4 + 32);
}
while ( v3 != v2 );
v1 = (unsigned int)(v1 + 1);
v2 += 16;
}
while ( (_DWORD)v1 != 256 );
}
return result;
}

original_code:
static void update_background( void )
{
 int row,col,page;
 int charcode;
 charcode=0;
 for (page=0; page<3; page++)
 {
  for( row=0; row<256; row++ )
  {
   for( col=0; col<512; col+=32 )
   {
    drawgfx(bg_bitmap,
      Machine->gfx[2],
      charcode,
      row < 128 ? 0 : 1,
      0,0,
      512*page + col,row,
      0,TRANSPARENCY_NONE,0);
    charcode++;
   }
  }
 }
}

canonical_original_code:
static void update_background()
{
 int row; int col; int page;
 int charcode;
 charcode=0;
 for (page=0; page<3; page++)
 {
  for( row=0; row<256; row++ )
  {
   for( col=0; col<512; col+=32 )
   {
    drawgfx(bg_bitmap,
      Machine->gfx[2],
      charcode,
      row < 128 ? 0 : 1,
      0,0,
      512*page + col,row,
      0,TRANSPARENCY_NONE,0);
    charcode++;
   }
  }
 }
}

variable_types: row int

variable_types: col int

variable_types: page int

variable_types: charcode int


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 506 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
if ( rear_refresh )
{
update_background();
rear_refresh = 0;
}
return copyscrollbitmap(a1, bg_bitmap, 1LL, v2, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 506 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
if ( rear_refresh )
{
func6();
rear_refresh = 0;
}
return copyscrollbitmap(a1, bg_bitmap, 1LL, v2, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

original_code:
static void draw_background( struct osd_bitmap *bitmap )
{
 int scrollx = 0x17a + 16*8 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
 if (rear_refresh)
 {
  update_background( );
  rear_refresh=0;
 }
 copyscrollbitmap(bitmap,bg_bitmap,1,&scrollx,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap)
{
 int scrollx = 0x17a + 16*8 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
 if (rear_refresh)
 {
  update_background( );
  rear_refresh=0;
 }
 copyscrollbitmap(bitmap,bg_bitmap,1,&scrollx,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

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

variable_types: scrollx int


original_code:
static data_t aeroboto_201_r(offs_t offset)
{
 int res[4] = { 0xff,0x9f,0x1b,0x03};
 static int count;
 return res[(count++)&3];
}

canonical_original_code:
static unsigned int aeroboto_201_r(unsigned int offset)
{
 int res[4] = { 0xff,0x9f,0x1b,0x03};
 static int count;
 return res[(count++)&3];
}

variable_types:
res
int [4]

variable_types: count int

return_type: unsigned int


decompiled_code:
void *__fastcall aeroboto_vh_screenrefresh(__int64 a1)
{
int v1; // er14
__int64 v2; // r12
int v3; // ebp
int v4; // er14
__int64 v5; // r12
int v6; // ebp
void *result; // rax
int v8; // ebp
__int64 v9; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
v3 = v1 / 32;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(videoram + v2) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v1 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v3),
(unsigned int)(8 * v3),
Machine + 776LL,
0LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(videoram + v2--) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v1 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v3) + 256,
(unsigned int)(8 * v3),
Machine + 776LL,
0LL,
0LL);
--v1;
}
while ( v1 >= 0 );
v4 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
v6 = v4 / 32;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(aeroboto_videoram + v5) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v4 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v6),
(unsigned int)(8 * v6),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(aeroboto_videoram + v5--) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v4 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v6) + 256,
(unsigned int)(8 * v6),
Machine + 776LL,
2LL,
0LL);
--v4;
}
while ( v4 >= 0 );
}
}
result = &spriteram_size;
v8 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v9 = v8 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v9 - 2),
*(_BYTE *)(spriteram + v9 - 1) & 0xF,
0LL,
0LL,
*(unsigned __int8 *)(spriteram + v9),
239 - (unsigned int)*(unsigned __int8 *)(spriteram + v9 - 3),
Machine + 776LL,
2LL,
0LL);
v9 -= 4LL;
v8 -= 4;
}
while ( v8 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // er14
__int64 v2; // r12
int v3; // ebp
int v4; // er14
__int64 v5; // r12
int v6; // ebp
void *result; // rax
int v8; // ebp
__int64 v9; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
v3 = v1 / 32;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(videoram + v2) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v1 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v3),
(unsigned int)(8 * v3),
Machine + 776LL,
0LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(videoram + v2--) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v1 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v3) + 256,
(unsigned int)(8 * v3),
Machine + 776LL,
0LL,
0LL);
--v1;
}
while ( v1 >= 0 );
v4 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
v6 = v4 / 32;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(aeroboto_videoram + v5) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v4 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v6),
(unsigned int)(8 * v6),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)*(unsigned __int8 *)(aeroboto_videoram + v5--) + (aeroboto_charbank[0] << 8),
0LL,
0LL,
0LL,
8 * (v4 % 32) - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v6) + 256,
(unsigned int)(8 * v6),
Machine + 776LL,
2LL,
0LL);
--v4;
}
while ( v4 >= 0 );
}
}
result = &spriteram_size;
v8 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v9 = v8 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v9 - 2),
*(_BYTE *)(spriteram + v9 - 1) & 0xF,
0LL,
0LL,
*(unsigned __int8 *)(spriteram + v9),
239 - (unsigned int)*(unsigned __int8 *)(spriteram + v9 - 3),
Machine + 776LL,
2LL,
0LL);
v9 -= 4LL;
v8 -= 4;
}
while ( v8 >= 0 );
}
return result;
}

original_code:
void aeroboto_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size-4;offs >= 0;offs -= 4)
 {
  int sx,sy;
  sx = spriteram[offs + 3];
  sy = 239 - spriteram[offs];
  drawgfx(bitmap,Machine->gfx[2],
    spriteram[offs + 1],
    spriteram[offs + 2] & 0x0f,
    0,0,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void aeroboto_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size-4;offs >= 0;offs -= 4)
 {
  int sx; int sy;
  sx = spriteram[offs + 3];
  sy = 239 - spriteram[offs];
  drawgfx(bitmap,Machine->gfx[2],
    spriteram[offs + 1],
    spriteram[offs + 2] & 0x0f,
    0,0,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

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


decompiled_code:
__int64 aeroboto_in0_r()
{
return readinputport((unsigned int)player);
}

canonical_decompiled_code:
__int64 func2()
{
return readinputport((unsigned int)player);
}

original_code:
static data_t aeroboto_in0_r(offs_t offset)
{
 return readinputport(player);
}

canonical_original_code:
static unsigned int aeroboto_in0_r(unsigned int offset)
{
 return readinputport(player);
}


decompiled_code:
void __fastcall adjust_xy(int a1)
{
switch ( a1 )
{
case 0:
--x;
++y;
break;
case 1:
--y;
break;
case 2:
--x;
break;
case 4:
++x;
++y;
break;
case 5:
++y;
break;
case 6:
++x;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
switch ( a1 )
{
case 0:
--x;
++y;
break;
case 1:
--y;
break;
case 2:
--x;
break;
case 4:
++x;
++y;
break;
case 5:
++y;
break;
case 6:
++x;
break;
default:
return;
}
}

original_code:
static void adjust_xy(int offset)
{
 switch(offset)
 {
 case 0x00: x--; y++; break;
 case 0x01: y--; break;
 case 0x02: x--; break;
 case 0x04: x++; y++; break;
 case 0x05: y++; break;
 case 0x06: x++; break;
 }
}

variable_types: offset int


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

if ( bmap )
v1 = *((unsigned __int8 *)tmpvideoram2 + 256 * (unsigned __int8)y + (unsigned __int8)x);
else
v1 = *((unsigned __int8 *)tmpvideoram + 256 * (unsigned __int8)y + (unsigned __int8)x);
adjust_xy(a1);
return v1;
}

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

if ( bmap )
v1 = *((unsigned __int8 *)tmpvideoram2 + 256 * (unsigned __int8)y + (unsigned __int8)x);
else
v1 = *((unsigned __int8 *)tmpvideoram + 256 * (unsigned __int8)y + (unsigned __int8)x);
func0(a1);
return v1;
}

original_code:
data_t graph_processor_r(offs_t offset)
{
 int ret;
 if (bmap)
 {
  ret = tmpvideoram2[y*256+x];
 }
 else
 {
  ret = tmpvideoram[y*256+x];
 }
 adjust_xy(offset);
 return ret;
}

canonical_original_code:
unsigned int graph_processor_r(unsigned int offset)
{
 int ret;
 if (bmap)
 {
  ret = tmpvideoram2[y*256+x];
 }
 else
 {
  ret = tmpvideoram[y*256+x];
 }
 adjust_xy(offset);
 return ret;
}

variable_types: ret int


decompiled_code:
void __fastcall graph_processor_w(int a1, char a2)
{
int v2; // esi

if ( a1 == 3 )
{
x = a2;
}
else if ( a1 == 7 )
{
y = a2;
}
else
{
v2 = a2 & 7;
if ( bmap )
{
plot_pixel(
tmpbitmap,
(unsigned __int8)(x - 6),
(unsigned __int8)y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v2 + 16)));
*((_BYTE *)tmpvideoram + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
else
{
plot_pixel(
tmpbitmap2,
(unsigned __int8)(x - 6),
(unsigned __int8)y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v2 + 16)));
*((_BYTE *)tmpvideoram2 + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
adjust_xy(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, char a2)
{
int v2; // esi

if ( a1 == 3 )
{
x = a2;
}
else if ( a1 == 7 )
{
y = a2;
}
else
{
v2 = a2 & 7;
if ( bmap )
{
plot_pixel(
tmpbitmap,
(unsigned __int8)(x - 6),
(unsigned __int8)y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v2 + 16)));
*((_BYTE *)tmpvideoram + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
else
{
plot_pixel(
tmpbitmap2,
(unsigned __int8)(x - 6),
(unsigned __int8)y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v2 + 16)));
*((_BYTE *)tmpvideoram2 + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
func0(a1);
}
}

original_code:
void graph_processor_w(offs_t offset,data_t data)
{
 int col;
 switch (offset)
 {
 case 0x03: x=data; break;
 case 0x07: y=data; break;
 default:
  col = data & 0x07;
  if (bmap)
  {
   plot_pixel(tmpbitmap, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram[y*256+x] = col;
  }
  else
  {
   plot_pixel(tmpbitmap2, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram2[y*256+x] = col;
  }
  adjust_xy(offset);
  break;
 }
}

canonical_original_code:
void graph_processor_w(unsigned int offset, unsigned int data)
{
 int col;
 switch (offset)
 {
 case 0x03: x=data; break;
 case 0x07: y=data; break;
 default:
  col = data & 0x07;
  if (bmap)
  {
   plot_pixel(tmpbitmap, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram[y*256+x] = col;
  }
  else
  {
   plot_pixel(tmpbitmap2, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram2[y*256+x] = col;
  }
  adjust_xy(offset);
  break;
 }
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 refresh_bitmaps()
{
unsigned int i; // er14
__int64 v1; // rbp
int j; // ebx
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-40h]

v4 = 0LL;
for ( i = 0; i != 256; ++i )
{
v1 = v4;
for ( j = -6; j != 250; ++j )
{
plot_pixel(
tmpbitmap,
(unsigned __int8)j,
i,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)tmpvideoram + v1) + 32));
result = plot_pixel(
tmpbitmap2,
(unsigned __int8)j,
i,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * *((unsigned __int8 *)tmpvideoram2 + v1++)
+ 32));
}
v4 += 256LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int i; // er14
__int64 v1; // rbp
int j; // ebx
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-40h]

v4 = 0LL;
for ( i = 0; i != 256; ++i )
{
v1 = v4;
for ( j = -6; j != 250; ++j )
{
plot_pixel(
tmpbitmap,
(unsigned __int8)j,
i,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)tmpvideoram + v1) + 32));
result = plot_pixel(
tmpbitmap2,
(unsigned __int8)j,
i,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * *((unsigned __int8 *)tmpvideoram2 + v1++)
+ 32));
}
v4 += 256LL;
}
return result;
}

original_code:
static void refresh_bitmaps(void)
{
 int lx,ly;
 for (ly = 0; ly < 256; ly++)
 {
  for (lx = 0; lx < 256; lx++)
  {
   plot_pixel(tmpbitmap, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram[ly*256+lx]]);
   plot_pixel(tmpbitmap2, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram2[ly*256+lx]]);
  }
 }
}

canonical_original_code:
static void refresh_bitmaps()
{
 int lx; int ly;
 for (ly = 0; ly < 256; ly++)
 {
  for (lx = 0; lx < 256; lx++)
  {
   plot_pixel(tmpbitmap, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram[ly*256+lx]]);
   plot_pixel(tmpbitmap2, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram2[ly*256+lx]]);
  }
 }
}

variable_types: lx int

variable_types: ly int


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

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

original_code:
static data_t cloak_sharedram_r(offs_t offset)
{
 return cloak_sharedram[offset];
}

canonical_original_code:
static unsigned int cloak_sharedram_r(unsigned int offset)
{
 return cloak_sharedram[offset];
}


variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


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

result = (void *)(a2 & 1);
bmap = a2 & 1;
if ( (a2 & 2) != 0 )
{
if ( (_BYTE)result )
{
fillbitmap(tmpbitmap, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL), Machine + 776LL);
result = memset(tmpvideoram, 0, 0x10000uLL);
}
else
{
fillbitmap(tmpbitmap2, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL), Machine + 776LL);
result = memset(tmpvideoram2, 0, 0x10000uLL);
}
}
return result;
}

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

result = (void *)(a2 & 1);
bmap = a2 & 1;
if ( (a2 & 2) != 0 )
{
if ( (_BYTE)result )
{
fillbitmap(tmpbitmap, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL), Machine + 776LL);
result = memset(tmpvideoram, 0, 0x10000uLL);
}
else
{
fillbitmap(tmpbitmap2, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL), Machine + 776LL);
result = memset(tmpvideoram2, 0, 0x10000uLL);
}
}
return result;
}

original_code:
void cloak_clearbmp_w(offs_t offset,data_t data)
{
 bmap = data & 1;
 if (data & 2)
 {
  if (bmap)
  {
   fillbitmap(tmpbitmap, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram, 0, 256*256);
  }
  else
  {
   fillbitmap(tmpbitmap2, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram2, 0, 256*256);
  }
 }
}

canonical_original_code:
void cloak_clearbmp_w(unsigned int offset, unsigned int data)
{
 bmap = data & 1;
 if (data & 2)
 {
  if (bmap)
  {
   fillbitmap(tmpbitmap, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram, 0, 256*256);
  }
  else
  {
   fillbitmap(tmpbitmap2, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram2, 0, 256*256);
  }
 }
}


decompiled_code:
void cloak_vh_stop()
{
if ( charbitmap )
bitmap_free();
if ( tmpbitmap2 )
bitmap_free();
if ( tmpbitmap )
bitmap_free();
if ( dirtybuffer )
free(dirtybuffer);
if ( tmpvideoram )
free(tmpvideoram);
if ( tmpvideoram2 )
free(tmpvideoram2);
}

canonical_decompiled_code:
void func8()
{
if ( charbitmap )
bitmap_free();
if ( tmpbitmap2 )
bitmap_free();
if ( tmpbitmap )
bitmap_free();
if ( dirtybuffer )
free(dirtybuffer);
if ( tmpvideoram )
free(tmpvideoram);
if ( tmpvideoram2 )
free(tmpvideoram2);
}

original_code:
void cloak_vh_stop(void)
{
 if (charbitmap) bitmap_free(charbitmap);
 if (tmpbitmap2) bitmap_free(tmpbitmap2);
 if (tmpbitmap) bitmap_free(tmpbitmap);
 if (dirtybuffer) free(dirtybuffer);
 if (tmpvideoram) free(tmpvideoram);
 if (tmpvideoram2) free(tmpvideoram2);
}

canonical_original_code:
void cloak_vh_stop()
{
 if (charbitmap) bitmap_free(charbitmap);
 if (tmpbitmap2) bitmap_free(tmpbitmap2);
 if (tmpbitmap) bitmap_free(tmpbitmap);
 if (dirtybuffer) free(dirtybuffer);
 if (tmpvideoram) free(tmpvideoram);
 if (tmpvideoram2) free(tmpvideoram2);
}


decompiled_code:
__int64 cloak_vh_start()
{
unsigned int v0; // edx
size_t v1; // rbx
void *v2; // rdi

tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v0 = 1;
if ( tmpbitmap )
{
charbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( charbitmap
&& (tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL))) != 0
&& (v1 = videoram_size, v2 = malloc(videoram_size), (dirtybuffer = v2) != 0LL)
&& (memset(v2, 1, v1), (tmpvideoram = malloc(0x10000uLL)) != 0LL)
&& (tmpvideoram2 = malloc(0x10000uLL)) != 0LL )
{
v0 = 0;
}
else
{
cloak_vh_stop();
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // edx
size_t v1; // rbx
void *v2; // rdi

tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v0 = 1;
if ( tmpbitmap )
{
charbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( charbitmap
&& (tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL))) != 0
&& (v1 = videoram_size, v2 = malloc(videoram_size), (dirtybuffer = v2) != 0LL)
&& (memset(v2, 1, v1), (tmpvideoram = malloc(0x10000uLL)) != 0LL)
&& (tmpvideoram2 = malloc(0x10000uLL)) != 0LL )
{
v0 = 0;
}
else
{
func8();
v0 = 1;
}
}
return v0;
}

original_code:
int cloak_vh_start(void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((charbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpvideoram = (unsigned char*)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpvideoram2 = (unsigned char*)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int cloak_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((charbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpvideoram = (unsigned char *)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpvideoram2 = (unsigned char *)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


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

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

original_code:
void cloak_led_w(offs_t offset,data_t data)
{
 osd_led_w(1 - offset,~data >> 7);
}

canonical_original_code:
void cloak_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(1 - offset,~data >> 7);
}


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

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

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

variable_types:
file
void *


decompiled_code:
void init_jack()
{
timer_rate = 128;
}

canonical_decompiled_code:
void func0()
{
timer_rate = 128;
}

original_code:
static void init_jack(void)
{
 timer_rate = 128;
}

canonical_original_code:
static void init_jack()
{
 timer_rate = 128;
}


canonical_decompiled_code:
void func1()
{
timer_rate = 16;
}

original_code:
static void init_zzyzzyxx(void)
{
 timer_rate = 16;
}

canonical_original_code:
static void init_zzyzzyxx()
{
 timer_rate = 16;
}


decompiled_code:
__int64 __fastcall jack_paletteram_w(__int64 a1, int a2)
{
return paletteram_BBGGGRRR_w(a1, (unsigned int)~a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return paletteram_BBGGGRRR_w(a1, (unsigned int)~a2);
}

original_code:
void jack_paletteram_w(offs_t offset,data_t data)
{
 paletteram_BBGGGRRR_w(offset,~data);
}

canonical_original_code:
void jack_paletteram_w(unsigned int offset, unsigned int data)
{
 paletteram_BBGGGRRR_w(offset,~data);
}


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

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

original_code:
data_t jack_flipscreen_r(offs_t offset)
{
 flip_screen_w(0, offset);
 return 0;
}

canonical_original_code:
unsigned int jack_flipscreen_r(unsigned int offset)
{
 flip_screen_w(0, offset);
 return 0;
}


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

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

original_code:
void jack_flipscreen_w(offs_t offset,data_t data)
{
 flip_screen_w(0, offset);
}

canonical_original_code:
void jack_flipscreen_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0, offset);
}


decompiled_code:
void *__fastcall jack_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v3; // rax
int v4; // ebx
__int64 v5; // rbp
int v6; // ecx
int v7; // esi
void *result; // rax
int v9; // ebp
__int64 v10; // rbx
__int64 v11; // rdi
__int64 v12; // r10
__int64 v13; // r8
__int64 v14; // r9

v3 = palette_recalc();
if ( a2 || v3 )
memset(dirtybuffer, 1, videoram_size);
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
v6 = v4 / 32;
v7 = v4 % 32;
if ( flip_screen_x )
v6 = 31 - v4 / 32;
else
v7 = 31 - v4 % 32;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v5) + ((32 * *(unsigned __int8 *)(colorram + v5)) & 0x300u),
*(_BYTE *)(colorram + v5) & 7,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v6),
(unsigned int)(8 * v7),
Machine + 776LL,
0LL,
0LL);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v9 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v10 = v9 + 1LL;
do
{
v11 = *(unsigned __int8 *)(spriteram + v10);
v12 = *(unsigned __int8 *)(spriteram + v10 - 1);
v13 = *(_BYTE *)(spriteram + v10 + 2) & 0x80;
v14 = *(_BYTE *)(spriteram + v10 + 2) & 0x40;
if ( flip_screen_x )
{
v11 = (unsigned int)(248 - v11);
v12 = (unsigned int)(248 - v12);
v13 = (_DWORD)v13 == 0;
v14 = (_DWORD)v14 == 0;
}
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(spriteram + v10 + 1)
+ ((32 * *(unsigned __int8 *)(spriteram + v10 + 2)) & 0x100u),
*(_BYTE *)(spriteram + v10 + 2) & 7,
v13,
v14,
v11,
v12,
Machine + 776LL,
2LL,
0LL);
v10 -= 4LL;
v9 -= 4;
}
while ( v9 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, int a2)
{
__int64 v3; // rax
int v4; // ebx
__int64 v5; // rbp
int v6; // ecx
int v7; // esi
void *result; // rax
int v9; // ebp
__int64 v10; // rbx
__int64 v11; // rdi
__int64 v12; // r10
__int64 v13; // r8
__int64 v14; // r9

v3 = palette_recalc();
if ( a2 || v3 )
memset(dirtybuffer, 1, videoram_size);
v4 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v5 = v4;
do
{
if ( *((_BYTE *)dirtybuffer + v5) )
{
*((_BYTE *)dirtybuffer + v5) = 0;
v6 = v4 / 32;
v7 = v4 % 32;
if ( flip_screen_x )
v6 = 31 - v4 / 32;
else
v7 = 31 - v4 % 32;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v5) + ((32 * *(unsigned __int8 *)(colorram + v5)) & 0x300u),
*(_BYTE *)(colorram + v5) & 7,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v6),
(unsigned int)(8 * v7),
Machine + 776LL,
0LL,
0LL);
}
--v5;
--v4;
}
while ( v4 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v9 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v10 = v9 + 1LL;
do
{
v11 = *(unsigned __int8 *)(spriteram + v10);
v12 = *(unsigned __int8 *)(spriteram + v10 - 1);
v13 = *(_BYTE *)(spriteram + v10 + 2) & 0x80;
v14 = *(_BYTE *)(spriteram + v10 + 2) & 0x40;
if ( flip_screen_x )
{
v11 = (unsigned int)(248 - v11);
v12 = (unsigned int)(248 - v12);
v13 = (_DWORD)v13 == 0;
v14 = (_DWORD)v14 == 0;
}
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(spriteram + v10 + 1)
+ ((32 * *(unsigned __int8 *)(spriteram + v10 + 2)) & 0x100u),
*(_BYTE *)(spriteram + v10 + 2) & 7,
v13,
v14,
v11,
v12,
Machine + 776LL,
2LL,
0LL);
v10 -= 4LL;
v9 -= 4;
}
while ( v9 >= 0 );
}
return result;
}

original_code:
void jack_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs / 32;
   sy = 31 - offs % 32;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x18) << 5),
     colorram[offs] & 0x07,
     flip_screen_x,flip_screen_x,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,num, color,flipx,flipy;
  sx = spriteram[offs + 1];
  sy = spriteram[offs];
  num = spriteram[offs + 2] + ((spriteram[offs + 3] & 0x08) << 5);
  color = spriteram[offs + 3] & 0x07;
  flipx = (spriteram[offs + 3] & 0x80);
  flipy = (spriteram[offs + 3] & 0x40);
  if (flip_screen_x)
  {
   sx = 248 - sx;
   sy = 248 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    num,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void jack_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs / 32;
   sy = 31 - offs % 32;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x18) << 5),
     colorram[offs] & 0x07,
     flip_screen_x,flip_screen_x,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int num; int color; int flipx; int flipy;
  sx = spriteram[offs + 1];
  sy = spriteram[offs];
  num = spriteram[offs + 2] + ((spriteram[offs + 3] & 0x08) << 5);
  color = spriteram[offs + 3] & 0x07;
  flipx = (spriteram[offs + 3] & 0x80);
  flipy = (spriteram[offs + 3] & 0x40);
  if (flip_screen_x)
  {
   sx = 248 - sx;
   sy = 248 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    num,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: num int

variable_types: color int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 jack_sh_command_w()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 func7()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 4294966296LL);
}

original_code:
static void jack_sh_command_w(offs_t offset,data_t data)
{
 soundlatch_w(0,data);
 cpu_cause_interrupt(1, -1000);
}

canonical_original_code:
static void jack_sh_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(0,data);
 cpu_cause_interrupt(1, -1000);
}


decompiled_code:
__int64 treahunt_decode()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // esi
__int64 i; // rcx
__int64 result; // rax
int v5; // er8

v0 = memory_region(129LL);
v1 = (int)memory_region_length(129LL) / 2;
memory_set_opcode_base(0LL, v0 + v1);
v2 = v1;
for ( i = 0LL; i != 0x4000; ++i )
{
v5 = *(unsigned __int8 *)(v0 + i);
if ( (i & 0x1000) != 0 )
{
result = ((int)(unsigned __int8)v5 >> 3) & 2 | (16 * (_BYTE)v5) & 0x40 | (8 * (_BYTE)v5) & 0x10 | v5 & 0x28 | ((int)(unsigned __int8)v5 >> 7) | ((unsigned __int8)v5 << 7) | ((int)(unsigned __int8)v5 >> 4) & 4u;
if ( (i & 4) == 0 )
result = (unsigned int)result ^ 0xFFFFFF81;
*(_BYTE *)(v0 + v2) = result;
}
else
{
result = ((int)(unsigned __int8)v5 >> 3) & 2 | (16 * (_BYTE)v5) & 0x40 | (8 * (_BYTE)v5) & 0x10 | v5 & 0xFFFFFFA9 ^ 0xFFFFFF81 | ((int)(unsigned __int8)v5 >> 4) & 4;
*(_BYTE *)(v0 + v2) = ((int)(unsigned __int8)v5 >> 3) & 2 | (16 * v5) & 0x40 | (8 * v5) & 0x10 | v5 & 0xA9 ^ 0x81 | ((int)(unsigned __int8)v5 >> 4) & 4;
}
++v2;
}
return result;
}

original_code:
static void treahunt_decode(void)
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int data;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0; A < 0x4000; A++)
 {
  data = rom[A];
  if (A & 0x1000)
  {
   rom[A+diff] =
     ((data & 0x01) << 7) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4) |
     ((data & 0x80) >> 7);
   if ((A & 0x04) == 0)
    rom[A+diff] ^= 0x81;
  }
  else
  {
   rom[A+diff] =
     (~data & 0x81) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4);
  }
 }
}

canonical_original_code:
static void treahunt_decode()
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int data;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0; A < 0x4000; A++)
 {
  data = rom[A];
  if (A & 0x1000)
  {
   rom[A+diff] =
     ((data & 0x01) << 7) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4) |
     ((data & 0x80) >> 7);
   if ((A & 0x04) == 0)
    rom[A+diff] ^= 0x81;
  }
  else
  {
   rom[A+diff] =
     (~data & 0x81) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4);
  }
 }
}

variable_types: A int

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: data int


decompiled_code:
__int64 init_treahunt()
{
timer_rate = 128;
return treahunt_decode();
}

canonical_decompiled_code:
__int64 func9()
{
timer_rate = 128;
return func8();
}

original_code:
static void init_treahunt(void)
{
 timer_rate = 128;
 treahunt_decode();
}

canonical_original_code:
static void init_treahunt()
{
 timer_rate = 128;
 treahunt_decode();
}


decompiled_code:
__int64 timer_r()
{
return (unsigned int)((int)cpu_gettotalcycles() / timer_rate);
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)((int)cpu_gettotalcycles() / timer_rate);
}

original_code:
static data_t timer_r(offs_t offset)
{
 return cpu_gettotalcycles() / timer_rate;
}

canonical_original_code:
static unsigned int timer_r(unsigned int offset)
{
 return cpu_gettotalcycles() / timer_rate;
}

variable_types:
offset
unsigned int


original_code:
void espial_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void espial_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (color_prom[0] >> 3) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
unsigned __int64 __fastcall espial_attributeram_w(unsigned int a1, int a2)
{
_BYTE *v2; // rdi
unsigned __int64 result; // rax

v2 = (_BYTE *)(espial_attributeram + a1);
result = (unsigned __int8)*v2;
if ( (_DWORD)result != a2 )
{
*v2 = a2;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

v2 = (_BYTE *)(espial_attributeram + a1);
result = (unsigned __int8)*v2;
if ( (_DWORD)result != a2 )
{
*v2 = a2;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void espial_attributeram_w(offs_t offset,data_t data)
{
 if (espial_attributeram[offset] != data)
 {
  espial_attributeram[offset] = data;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void espial_attributeram_w(unsigned int offset, unsigned int data)
{
 if (espial_attributeram[offset] != data)
 {
  espial_attributeram[offset] = data;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
data
unsigned int


decompiled_code:
__int64 espial_init_machine()
{
return interrupt_enable_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
return interrupt_enable_w(0LL, 0LL);
}

original_code:
void espial_init_machine(void)
{
 interrupt_enable_w(0, 0);
}

canonical_original_code:
void espial_init_machine()
{
 interrupt_enable_w(0, 0);
}


decompiled_code:
__int64 __fastcall zodiac_master_interrupt_enable_w(__int64 a1, int a2)
{
return interrupt_enable_w(a1, a2 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return interrupt_enable_w(a1, a2 ^ 1u);
}

original_code:
void zodiac_master_interrupt_enable_w(offs_t offset,data_t data)
{
 interrupt_enable_w(offset, data ^ 1);
}

canonical_original_code:
void zodiac_master_interrupt_enable_w(unsigned int offset, unsigned int data)
{
 interrupt_enable_w(offset, data ^ 1);
}


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

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

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

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

original_code:
int zodiac_master_interrupt(void)
{
 return (cpu_getiloops() == 0) ? nmi_interrupt() : interrupt();
}

canonical_original_code:
int zodiac_master_interrupt()
{
 return (cpu_getiloops() == 0) ? nmi_interrupt() : interrupt();
}


decompiled_code:
__int64 zodiac_master_soundlatch_w()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 func5()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 4294966296LL);
}

original_code:
void zodiac_master_soundlatch_w(offs_t offset,data_t data)
{
 soundlatch_w(offset, data);
 cpu_cause_interrupt(1, -1000);
}

canonical_original_code:
void zodiac_master_soundlatch_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset, data);
 cpu_cause_interrupt(1, -1000);
}


zlibVersion

decompiled_code:
const char *zlibVersion()
{
return "1.2.3";
}

canonical_decompiled_code:
const char *func0()
{
return "1.2.3";
}

original_code:
const char * zlibVersion()
{
    return "1.2.3";
}

canonical_original_code:
char *zlibVersion()
{
    return "1.2.3";
}

return_type: char *


zlibCompileFlags

decompiled_code:
__int64 zlibCompileFlags()
{
return 169LL;
}

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

original_code:
uLong zlibCompileFlags()
{
    uLong flags;
    flags = 0;
    switch (sizeof(uInt)) {
    case 2: break;
    case 4: flags += 1; break;
    case 8: flags += 2; break;
    default: flags += 3;
    }
    switch (sizeof(uLong)) {
    case 2: break;
    case 4: flags += 1 << 2; break;
    case 8: flags += 2 << 2; break;
    default: flags += 3 << 2;
    }
    switch (sizeof(voidpf)) {
    case 2: break;
    case 4: flags += 1 << 4; break;
    case 8: flags += 2 << 4; break;
    default: flags += 3 << 4;
    }
    switch (sizeof(long)) {
    case 2: break;
    case 4: flags += 1 << 6; break;
    case 8: flags += 2 << 6; break;
    default: flags += 3 << 6;
    }
    return flags;
}

canonical_original_code:
unsigned long zlibCompileFlags()
{
    unsigned long flags;
    flags = 0;
    switch (sizeof(uInt)) {
    case 2: break;
    case 4: flags += 1; break;
    case 8: flags += 2; break;
    default: flags += 3;
    }
    switch (sizeof(uLong)) {
    case 2: break;
    case 4: flags += 1 << 2; break;
    case 8: flags += 2 << 2; break;
    default: flags += 3 << 2;
    }
    switch (sizeof(voidpf)) {
    case 2: break;
    case 4: flags += 1 << 4; break;
    case 8: flags += 2 << 4; break;
    default: flags += 3 << 4;
    }
    switch (sizeof(long)) {
    case 2: break;
    case 4: flags += 1 << 6; break;
    case 8: flags += 2 << 6; break;
    default: flags += 3 << 6;
    }
    return flags;
}

variable_types:
flags
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall astrof_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
prom = a3;
}

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

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

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


decompiled_code:
__int64 __fastcall astrof_videoram_w(int a1, int a2)
{
return common_videoram_w(a1, a2, *astrof_color & 0xE);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return func1(a1, a2, *astrof_color & 0xE);
}

original_code:
void astrof_videoram_w(offs_t offset,data_t data)
{
 common_videoram_w(offset, data, *astrof_color & 0x0e);
}

canonical_original_code:
void astrof_videoram_w(unsigned int offset, unsigned int data)
{
 common_videoram_w(offset, data, *astrof_color & 0x0e);
}


decompiled_code:
__int64 __fastcall tomahawk_videoram_w(int a1, int a2)
{
return common_videoram_w(a1, a2, *astrof_color & 0xE | (16 * *astrof_color) & 0x10u);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return func1(a1, a2, *astrof_color & 0xE | (16 * *astrof_color) & 0x10u);
}

original_code:
void tomahawk_videoram_w(offs_t offset,data_t data)
{
 common_videoram_w(offset, data, (*astrof_color & 0x0e) | ((*astrof_color & 0x01) << 4));
}

canonical_original_code:
void tomahawk_videoram_w(unsigned int offset, unsigned int data)
{
 common_videoram_w(offset, data, (*astrof_color & 0x0e) | ((*astrof_color & 0x01) << 4));
}


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

if ( (a2 & 4) != palette_bank )
{
palette_bank = a2 & 4;
do_modify_palette = 1;
}
result = a2 & 8;
if ( (_DWORD)result != red_on )
{
red_on = a2 & 8;
do_modify_palette = 1;
}
return result;
}

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

if ( (a2 & 4) != palette_bank )
{
palette_bank = a2 & 4;
do_modify_palette = 1;
}
result = a2 & 8;
if ( (_DWORD)result != red_on )
{
red_on = a2 & 8;
do_modify_palette = 1;
}
return result;
}

original_code:
void astrof_video_control2_w(offs_t offset,data_t data)
{
 if (palette_bank != (data & 0x04))
 {
  palette_bank = (data & 0x04);
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}

canonical_original_code:
void astrof_video_control2_w(unsigned int offset, unsigned int data)
{
 if (palette_bank != (data & 0x04))
 {
  palette_bank = (data & 0x04);
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}


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

if ( palette_bank == -1 )
{
palette_bank = 0;
do_modify_palette = 1;
}
result = a2 & 8;
if ( (_DWORD)result != red_on )
{
red_on = a2 & 8;
do_modify_palette = 1;
}
return result;
}

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

if ( palette_bank == -1 )
{
palette_bank = 0;
do_modify_palette = 1;
}
result = a2 & 8;
if ( (_DWORD)result != red_on )
{
red_on = a2 & 8;
do_modify_palette = 1;
}
return result;
}

original_code:
void tomahawk_video_control2_w(offs_t offset,data_t data)
{
 if (palette_bank == -1)
 {
  palette_bank = 0;
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}

canonical_original_code:
void tomahawk_video_control2_w(unsigned int offset, unsigned int data)
{
 if (palette_bank == -1)
 {
  palette_bank = 0;
  do_modify_palette = 1;
 }
 if (red_on != (data & 0x08))
 {
  red_on = data & 0x08;
  do_modify_palette = 1;
 }
}


decompiled_code:
__int64 tomahawk_protection_r()
{
return ((int)(unsigned __int8)*tomahawk_protection >> 5) & 2 | ((int)(unsigned __int8)*tomahawk_protection >> 3) & 4 | ((int)(unsigned __int8)*tomahawk_protection >> 1) & 8 | (2 * *tomahawk_protection) & 0x10 | (8 * *tomahawk_protection) & 0x20 | (*tomahawk_protection >> 7) | (32 * *tomahawk_protection) & 0x40 | (unsigned int)(unsigned __int8)(*tomahawk_protection << 7);
}

canonical_decompiled_code:
__int64 func6()
{
return ((int)(unsigned __int8)*tomahawk_protection >> 5) & 2 | ((int)(unsigned __int8)*tomahawk_protection >> 3) & 4 | ((int)(unsigned __int8)*tomahawk_protection >> 1) & 8 | (2 * *tomahawk_protection) & 0x10 | (8 * *tomahawk_protection) & 0x20 | (*tomahawk_protection >> 7) | (32 * *tomahawk_protection) & 0x40 | (unsigned int)(unsigned __int8)(*tomahawk_protection << 7);
}

original_code:
data_t tomahawk_protection_r(offs_t offset)
{
 int res = ((*tomahawk_protection & 0x01) << 7) |
     ((*tomahawk_protection & 0x02) << 5) |
     ((*tomahawk_protection & 0x04) << 3) |
     ((*tomahawk_protection & 0x08) << 1) |
     ((*tomahawk_protection & 0x10) >> 1) |
     ((*tomahawk_protection & 0x20) >> 3) |
     ((*tomahawk_protection & 0x40) >> 5) |
     ((*tomahawk_protection & 0x80) >> 7);
 return res;
}

canonical_original_code:
unsigned int tomahawk_protection_r(unsigned int offset)
{
 int res = ((*tomahawk_protection & 0x01) << 7) |
     ((*tomahawk_protection & 0x02) << 5) |
     ((*tomahawk_protection & 0x04) << 3) |
     ((*tomahawk_protection & 0x08) << 1) |
     ((*tomahawk_protection & 0x10) >> 1) |
     ((*tomahawk_protection & 0x20) >> 3) |
     ((*tomahawk_protection & 0x40) >> 5) |
     ((*tomahawk_protection & 0x80) >> 7);
 return res;
}

variable_types: res int


decompiled_code:
__int64 astrof_vh_start()
{
colorram = malloc(videoram_size);
if ( colorram )
return 0LL;
generic_bitmapped_vh_stop();
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
colorram = malloc(videoram_size);
if ( colorram )
return 0LL;
generic_bitmapped_vh_stop();
return 1LL;
}

original_code:
int astrof_vh_start(void)
{
 if ((colorram = (unsigned char*)malloc(videoram_size)) == 0)
 {
  generic_bitmapped_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int astrof_vh_start()
{
 if ((colorram = (unsigned char *)malloc(videoram_size)) == 0)
 {
  generic_bitmapped_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
void astrof_vh_stop()
{
if ( colorram )
free(colorram);
}

canonical_decompiled_code:
void func8()
{
if ( colorram )
free(colorram);
}

original_code:
void astrof_vh_stop(void)
{
 if (colorram) free(colorram);
}

canonical_original_code:
void astrof_vh_stop()
{
 if (colorram) free(colorram);
}


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

result = input_port_2_r(0LL);
if ( (result & 2) != 0 )
result = flip_screen_w(a1, a2 & 1);
return result;
}

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

result = input_port_2_r(0LL);
if ( (result & 2) != 0 )
result = flip_screen_w(a1, a2 & 1);
return result;
}

original_code:
void astrof_video_control1_w(offs_t offset,data_t data)
{
 if (input_port_2_r(0) & 0x02)
 {
  flip_screen_w(offset, data & 0x01);
 }
}

canonical_original_code:
void astrof_video_control1_w(unsigned int offset, unsigned int data)
{
 if (input_port_2_r(0) & 0x02)
 {
  flip_screen_w(offset, data & 0x01);
 }
}


decompiled_code:
__int64 modify_palette()
{
int v0; // ebp
__int64 result; // rax
__int64 v2; // rbx

v0 = palette_bank;
if ( palette_bank )
v0 = 16;
result = *(_QWORD *)(Machine + 824LL);
if ( *(_DWORD *)(result + 696) )
{
v2 = 0LL;
do
{
palette_change_color(
(unsigned int)v2,
(unsigned __int8)(63 * ((red_on >> 3) | ((*(_BYTE *)(prom + v2 + v0) & 2) != 0))
- (((unsigned __int8)(red_on >> 3) | *(_BYTE *)(prom + v2 + v0) & 1) << 6)),
192 * ((*(_BYTE *)(prom + v2 + v0) & 4) != 0) + 63 * (unsigned int)((*(_BYTE *)(prom + v2 + v0) & 8) != 0),
63 * ((*(_BYTE *)(prom + v2 + v0) & 0x20) != 0) + 192 * (unsigned int)((*(_BYTE *)(prom + v2 + v0) & 0x10) != 0));
++v2;
result = *(_QWORD *)(Machine + 824LL);
}
while ( *(_DWORD *)(result + 696) > (unsigned int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebp
__int64 result; // rax
__int64 v2; // rbx

v0 = palette_bank;
if ( palette_bank )
v0 = 16;
result = *(_QWORD *)(Machine + 824LL);
if ( *(_DWORD *)(result + 696) )
{
v2 = 0LL;
do
{
palette_change_color(
(unsigned int)v2,
(unsigned __int8)(63 * ((red_on >> 3) | ((*(_BYTE *)(prom + v2 + v0) & 2) != 0))
- (((unsigned __int8)(red_on >> 3) | *(_BYTE *)(prom + v2 + v0) & 1) << 6)),
192 * ((*(_BYTE *)(prom + v2 + v0) & 4) != 0) + 63 * (unsigned int)((*(_BYTE *)(prom + v2 + v0) & 8) != 0),
63 * ((*(_BYTE *)(prom + v2 + v0) & 0x20) != 0) + 192 * (unsigned int)((*(_BYTE *)(prom + v2 + v0) & 0x10) != 0));
++v2;
result = *(_QWORD *)(Machine + 824LL);
}
while ( *(_DWORD *)(result + 696) > (unsigned int)v2 );
}
return result;
}

original_code:
static void modify_palette(void)
{
 int i, col_index;
 col_index = (palette_bank ? 16 : 0);
 for (i = 0;i < Machine->drv->total_colors; i++)
 {
  int bit0,bit1,r,g,b;
  bit0 = ((prom[col_index] >> 0) & 0x01) | (red_on >> 3);
  bit1 = ((prom[col_index] >> 1) & 0x01) | (red_on >> 3);
  r = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 2) & 0x01;
  bit1 = ( prom[col_index] >> 3) & 0x01;
  g = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 4) & 0x01;
  bit1 = ( prom[col_index] >> 5) & 0x01;
  b = 0xc0 * bit0 + 0x3f * bit1;
  col_index++;
  palette_change_color(i,r,g,b);
 }
}

canonical_original_code:
static void modify_palette()
{
 int i; int col_index;
 col_index = (palette_bank ? 16 : 0);
 for (i = 0;i < Machine->drv->total_colors; i++)
 {
  int bit0; int bit1; int r; int g; int b;
  bit0 = ((prom[col_index] >> 0) & 0x01) | (red_on >> 3);
  bit1 = ((prom[col_index] >> 1) & 0x01) | (red_on >> 3);
  r = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 2) & 0x01;
  bit1 = ( prom[col_index] >> 3) & 0x01;
  g = 0xc0 * bit0 + 0x3f * bit1;
  bit0 = ( prom[col_index] >> 4) & 0x01;
  bit1 = ( prom[col_index] >> 5) & 0x01;
  b = 0xc0 * bit0 + 0x3f * bit1;
  col_index++;
  palette_change_color(i,r,g,b);
 }
}

variable_types: r int

variable_types: g int

variable_types: b int


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

if ( start_explosion )
{
if ( (a2 & 4) != 0 )
{
if ( !bosskill_playing )
{
result = sample_start(1LL, 10LL, 0LL);
bosskill_playing = 1;
}
}
else if ( (a2 & 2) != 0 )
{
result = sample_start(1LL, 9LL, 0LL);
}
else if ( (a2 & 1) != 0 )
{
result = sample_start(1LL, 1LL, 0LL);
}
else if ( !death_playing )
{
result = sample_start(1LL, 8LL, 0LL);
death_playing = 1;
}
start_explosion = 0;
}
if ( (a2 & 8) != 0 && (last_0 & 8) == 0 )
result = sample_start(3LL, 7LL, 0LL);
last_0 = a2;
return result;
}

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

if ( start_explosion )
{
if ( (a2 & 4) != 0 )
{
if ( !bosskill_playing )
{
result = sample_start(1LL, 10LL, 0LL);
bosskill_playing = 1;
}
}
else if ( (a2 & 2) != 0 )
{
result = sample_start(1LL, 9LL, 0LL);
}
else if ( (a2 & 1) != 0 )
{
result = sample_start(1LL, 1LL, 0LL);
}
else if ( !death_playing )
{
result = sample_start(1LL, 8LL, 0LL);
death_playing = 1;
}
start_explosion = 0;
}
if ( (a2 & 8) != 0 && (last_0 & 8) == 0 )
result = sample_start(3LL, 7LL, 0LL);
last_0 = a2;
return result;
}

original_code:
void astrof_sample2_w(offs_t offset,data_t data)
{
 static int last = 0;
 if (start_explosion)
 {
  if (data & 0x04)
  {
   if (!bosskill_playing)
   {
    sample_start(1,10,0);
    bosskill_playing = 1;
   }
  }
  else if (data & 0x02)
  {
   sample_start(1,9,0);
  }
  else if (data & 0x01)
  {
   sample_start(1,1,0);
  }
  else
  {
   if (!death_playing)
   {
    sample_start(1,8,0);
    death_playing = 1;
   }
  }
  start_explosion = 0;
 }
 if ((data & 0x08) && !(last & 0x08))
 {
  sample_start(3,7,0);
 }
 last = data;
}

canonical_original_code:
void astrof_sample2_w(unsigned int offset, unsigned int data)
{
 static int last = 0;
 if (start_explosion)
 {
  if (data & 0x04)
  {
   if (!bosskill_playing)
   {
    sample_start(1,10,0);
    bosskill_playing = 1;
   }
  }
  else if (data & 0x02)
  {
   sample_start(1,9,0);
  }
  else if (data & 0x01)
  {
   sample_start(1,1,0);
  }
  else
  {
   if (!death_playing)
   {
    sample_start(1,8,0);
    death_playing = 1;
   }
  }
  start_explosion = 0;
 }
 if ((data & 0x08) && !(last & 0x08))
 {
  sample_start(3,7,0);
 }
 last = data;
}

variable_types: last int


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

if ( death_playing )
death_playing = sample_playing(1LL);
if ( bosskill_playing )
bosskill_playing = sample_playing(1LL);
if ( (a2 & 4) != 0 && (last_1 & 4) == 0 )
start_explosion = 1;
result = last_1 ^ (unsigned int)a2;
if ( (((unsigned __int8)last_1 ^ (unsigned __int8)a2) & 8) != 0 )
{
if ( (a2 & 8) != 0 )
result = sample_start(2LL, (a2 & 3u) + 2, 1LL);
else
result = sample_stop(2LL);
}
if ( (a2 & 0x10) != 0 )
{
result = bosskill_playing | last_1 & 0x10u;
if ( !(bosskill_playing | last_1 & 0x10) )
result = sample_start(2LL, 6LL, 0LL);
}
if ( (a2 & 0x20) != 0 )
{
result = bosskill_playing | last_1 & 0x20u;
if ( !(bosskill_playing | last_1 & 0x20) )
result = sample_start(0LL, 0LL, 0LL);
}
last_1 = a2;
return result;
}

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

if ( death_playing )
death_playing = sample_playing(1LL);
if ( bosskill_playing )
bosskill_playing = sample_playing(1LL);
if ( (a2 & 4) != 0 && (last_1 & 4) == 0 )
start_explosion = 1;
result = last_1 ^ (unsigned int)a2;
if ( (((unsigned __int8)last_1 ^ (unsigned __int8)a2) & 8) != 0 )
{
if ( (a2 & 8) != 0 )
result = sample_start(2LL, (a2 & 3u) + 2, 1LL);
else
result = sample_stop(2LL);
}
if ( (a2 & 0x10) != 0 )
{
result = bosskill_playing | last_1 & 0x10u;
if ( !(bosskill_playing | last_1 & 0x10) )
result = sample_start(2LL, 6LL, 0LL);
}
if ( (a2 & 0x20) != 0 )
{
result = bosskill_playing | last_1 & 0x20u;
if ( !(bosskill_playing | last_1 & 0x20) )
result = sample_start(0LL, 0LL, 0LL);
}
last_1 = a2;
return result;
}

original_code:
void astrof_sample1_w(offs_t offset,data_t data)
{
 static int last = 0;
 if (death_playing)
 {
  death_playing = sample_playing(1);
 }
 if (bosskill_playing)
 {
  bosskill_playing = sample_playing(1);
 }
 if ((data & 0x04) && !(last & 0x04))
 {
  start_explosion = 1;
 }
 if ((data & 0x08) != (last & 0x08))
 {
  if (data & 0x08)
  {
   int sample = 2 + (data & 3);
   sample_start(2,sample,1);
  }
  else
  {
   sample_stop(2);
  }
 }
 if ((data & 0x10) && !(last & 0x10))
 {
  if (!bosskill_playing)
  {
   sample_start(2,6,0);
  }
 }
 if ((data & 0x20) && !(last & 0x20))
 {
  if (!bosskill_playing)
  {
   sample_start(0,0,0);
  }
 }
 last = data;
}

canonical_original_code:
void astrof_sample1_w(unsigned int offset, unsigned int data)
{
 static int last = 0;
 if (death_playing)
 {
  death_playing = sample_playing(1);
 }
 if (bosskill_playing)
 {
  bosskill_playing = sample_playing(1);
 }
 if ((data & 0x04) && !(last & 0x04))
 {
  start_explosion = 1;
 }
 if ((data & 0x08) != (last & 0x08))
 {
  if (data & 0x08)
  {
   int sample = 2 + (data & 3);
   sample_start(2,sample,1);
  }
  else
  {
   sample_stop(2);
  }
 }
 if ((data & 0x10) && !(last & 0x10))
 {
  if (!bosskill_playing)
  {
   sample_start(2,6,0);
  }
 }
 if ((data & 0x20) && !(last & 0x20))
 {
  if (!bosskill_playing)
  {
   sample_start(0,0,0);
  }
 }
 last = data;
}

variable_types: sample int


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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int astrof_interrupt(void)
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int astrof_interrupt()
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall common_videoram_w(int a1, int a2, int a3)
{
int v3; // ebx
__int64 v4; // rcx
unsigned __int16 v5; // r14
unsigned __int16 v6; // r15
unsigned int v7; // ebp
int v8; // er12
unsigned __int16 v9; // cx
__int64 result; // rax
unsigned int v11; // [rsp+8h] [rbp-40h]
int v12; // [rsp+Ch] [rbp-3Ch]

v3 = a2;
*(_BYTE *)(videoram + a1) = a2;
*(_BYTE *)(colorram + a1) = a3;
v4 = *(_QWORD *)(Machine + 792LL);
v5 = *(_WORD *)(v4 + 2LL * (a3 | 1));
v6 = *(_WORD *)(v4 + 2LL * a3);
v7 = 8 * (a1 >> 8);
v11 = (unsigned __int8)~(_BYTE)a1;
v12 = 1;
if ( flip_screen_x )
{
v7 = 255 - v7;
v11 = 255 - (unsigned __int8)~(_BYTE)a1;
v12 = -1;
}
v8 = 8;
do
{
v9 = v6;
if ( (v3 & 1) != 0 )
v9 = v5;
result = plot_pixel(*(_QWORD *)(Machine + 768LL), v7, v11, v9);
v7 += v12;
v3 >>= 1;
--v8;
}
while ( v8 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3)
{
int v3; // ebx
__int64 v4; // rcx
unsigned __int16 v5; // r14
unsigned __int16 v6; // r15
unsigned int v7; // ebp
int v8; // er12
unsigned __int16 v9; // cx
__int64 result; // rax
unsigned int v11; // [rsp+8h] [rbp-40h]
int v12; // [rsp+Ch] [rbp-3Ch]

v3 = a2;
*(_BYTE *)(videoram + a1) = a2;
*(_BYTE *)(colorram + a1) = a3;
v4 = *(_QWORD *)(Machine + 792LL);
v5 = *(_WORD *)(v4 + 2LL * (a3 | 1));
v6 = *(_WORD *)(v4 + 2LL * a3);
v7 = 8 * (a1 >> 8);
v11 = (unsigned __int8)~(_BYTE)a1;
v12 = 1;
if ( flip_screen_x )
{
v7 = 255 - v7;
v11 = 255 - (unsigned __int8)~(_BYTE)a1;
v12 = -1;
}
v8 = 8;
do
{
v9 = v6;
if ( (v3 & 1) != 0 )
v9 = v5;
result = plot_pixel(*(_QWORD *)(Machine + 768LL), v7, v11, v9);
v7 += v12;
v3 >>= 1;
--v8;
}
while ( v8 );
return result;
}

original_code:
static void common_videoram_w(int offset, int data, int color)
{
 int i,x,y,fore,back;
 int dx = 1;
 videoram[offset] = data;
 colorram[offset] = color;
 fore = Machine->pens[color | 1];
 back = Machine->pens[color ];
 x = (offset >> 8) << 3;
 y = 255 - (offset & 0xff);
 if (flip_screen_x)
 {
  x = 255 - x;
  y = 255 - y;
  dx = -1;
 }
 for (i = 0; i < 8; i++)
 {
  plot_pixel(Machine->scrbitmap, x, y, (data & 1) ? fore : back);
  x += dx;
  data >>= 1;
 }
}

canonical_original_code:
static void common_videoram_w(int offset, int data, int color)
{
 int i; int x; int y; int fore; int back;
 int dx = 1;
 videoram[offset] = data;
 colorram[offset] = color;
 fore = Machine->pens[color | 1];
 back = Machine->pens[color ];
 x = (offset >> 8) << 3;
 y = 255 - (offset & 0xff);
 if (flip_screen_x)
 {
  x = 255 - x;
  y = 255 - y;
  dx = -1;
 }
 for (i = 0; i < 8; i++)
 {
  plot_pixel(Machine->scrbitmap, x, y, (data & 1) ? fore : back);
  x += dx;
  data >>= 1;
 }
}

variable_types: offset int

variable_types: color int

variable_types: x int

variable_types: y int

variable_types: fore int

variable_types: back int

variable_types: dx int


decompiled_code:
bool __fastcall vicdual_vh_convert_color_prom(_BYTE *a1, __int64 a2, char *a3)
{
__int64 v3; // r8
unsigned int v4; // ecx
char **v5; // rdx
bool result; // al

if ( !a3 )
a3 = (char *)&bw_color_prom_0;
v3 = Machine;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > 1u )
{
v4 = 0;
do
{
*a1 = -((*a3 & 8) != 0);
a1[1] = -((*a3 & 2) != 0);
a1[2] = -((*a3 & 4) != 0);
a1[3] = *a3 >> 7;
a1[4] = -((*a3 & 0x20) != 0);
a1 += 6;
*(a1 - 1) = -((*a3++ & 0x40) != 0);
++v4;
v3 = Machine;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) >> 1 > v4 );
}
v5 = *(char ***)(v3 + 816);
palette_bank = 3 * (v5 == &driver_heiankyo);
result = v5 == &driver_invinco;
if ( v5 == &driver_invinco || v5 == &driver_digger || v5 == &driver_tranqgun )
palette_bank = 1;
return result;
}

original_code:
void vicdual_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 static unsigned char bw_color_prom[] =
 {
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
 };
 if (color_prom == 0) color_prom = bw_color_prom;
 for (i = 0;i < Machine->drv->total_colors / 2;i++)
 {
  int bit;
  bit = (*color_prom >> 3) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 1) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 2) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 7) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 5) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 6) & 0x01;
  *(palette++) = 0xff * bit;
  color_prom++;
 }
 palette_bank = 0;
 {
  extern struct GameDriver driver_heiankyo;
  extern struct GameDriver driver_invinco;
  extern struct GameDriver driver_digger;
  extern struct GameDriver driver_tranqgun;
  if (Machine->gamedrv == &driver_heiankyo)
   palette_bank = 3;
  if (Machine->gamedrv == &driver_invinco ||
    Machine->gamedrv == &driver_digger ||
    Machine->gamedrv == &driver_tranqgun)
   palette_bank = 1;
 }
}

canonical_original_code:
void vicdual_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 static unsigned char bw_color_prom[] = {
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
  0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
 };
 if (color_prom == 0) color_prom = bw_color_prom;
 for (i = 0;i < Machine->drv->total_colors / 2;i++)
 {
  int bit;
  bit = (*color_prom >> 3) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 1) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 2) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 7) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 5) & 0x01;
  *(palette++) = 0xff * bit;
  bit = (*color_prom >> 6) & 0x01;
  *(palette++) = 0xff * bit;
  color_prom++;
 }
 palette_bank = 0;
 {
  extern struct GameDriver driver_heiankyo;
  extern struct GameDriver driver_invinco;
  extern struct GameDriver driver_digger;
  extern struct GameDriver driver_tranqgun;
  if (Machine->gamedrv == &driver_heiankyo)
   palette_bank = 3;
  if (Machine->gamedrv == &driver_invinco ||
    Machine->gamedrv == &driver_digger ||
    Machine->gamedrv == &driver_tranqgun)
   palette_bank = 1;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: bit int

variable_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver { struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); } *memory_read; struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; } *memory_write; struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); } *port_read; struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); } *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; } cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle { int min_x; int min_y; } default_visible_area; struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; } *gfxlayout; int color_codes_start; int total_color_codes; } *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound { int sound_type; void *sound_interface; } sound[5]; void (*nvram_handler)(void *file, int read_or_write); } *drv; struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; } *input_ports; void (*driver_init)(); struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *rom; unsigned int flags; }

user_defined_types: struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver *drv; struct InputPortTiny *input_ports; void (*driver_init)(); struct RomModule *rom; unsigned int flags; }

user_defined_types: struct MachineDriver { struct MachineCPU cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle default_visible_area; struct GfxDecodeInfo *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound sound[5]; void (*nvram_handler)(void *file, int read_or_write); }

user_defined_types: struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress *memory_read; struct MemoryWriteAddress *memory_write; struct IOReadPort *port_read; struct IOWritePort *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; }

user_defined_types: struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout *gfxlayout; int color_codes_start; int total_color_codes; }


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

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

original_code:
data_t vicdual_characterram_r(offs_t offset)
{
 return vicdual_characterram[offset];
}

canonical_original_code:
unsigned int vicdual_characterram_r(unsigned int offset)
{
 return vicdual_characterram[offset];
}

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall samurai_protection_w(__int64 a1, int a2)
{
protection_data = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
protection_data = a2;
}

original_code:
static void samurai_protection_w(offs_t offset,data_t data)
{
 protection_data = data;
}

canonical_original_code:
static void samurai_protection_w(unsigned int offset, unsigned int data)
{
 protection_data = data;
}

variable_types:
data
unsigned int


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

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

original_code:
static data_t vicdual_ram_r(offs_t offset)
{
 return vicdual_ram[offset];
}

canonical_original_code:
static unsigned int vicdual_ram_r(unsigned int offset)
{
 return vicdual_ram[offset];
}


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

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

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

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

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

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


decompiled_code:
__int64 depthch_input_port_1_r()
{
char v0; // bl

v0 = input_port_1_r(0LL);
return v0 & 0xFE | ((int)cpu_getscanline() >> 6) & 1u;
}

canonical_decompiled_code:
__int64 func6()
{
char v0; // bl

v0 = input_port_1_r(0LL);
return v0 & 0xFE | ((int)cpu_getscanline() >> 6) & 1u;
}

original_code:
static data_t depthch_input_port_1_r(offs_t offset)
{
 return (input_port_1_r(0) & 0xfe) | ((cpu_getscanline() >> 6) & 0x01);
}

canonical_original_code:
static unsigned int depthch_input_port_1_r(unsigned int offset)
{
 return (input_port_1_r(0) & 0xfe) | ((cpu_getscanline() >> 6) & 0x01);
}


decompiled_code:
void *vicdual_decode()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x4000), (const void *)v0, 0x4000uLL);
}

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

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x4000), (const void *)v0, 0x4000uLL);
}

original_code:
static void vicdual_decode(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memcpy(&RAM[0x4000],&RAM[0x0000],0x4000);
}

canonical_original_code:
static void vicdual_decode()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memcpy(&RAM[0x4000],&RAM[0x0000],0x4000);
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *init_depthch()
{
install_port_read_handler(0LL, 8LL, 8LL, depthch_input_port_1_r);
install_port_write_handler(0LL, 4LL, 4LL, &depthch_sh_port1_w);
qword_6D8 = (__int64)&depthch_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func8()
{
install_port_read_handler(0LL, 8LL, 8LL, depthch_input_port_1_r);
install_port_write_handler(0LL, 4LL, 4LL, &depthch_sh_port1_w);
qword_6D8 = (__int64)&depthch_sample_names;
return func7();
}

original_code:
static void init_depthch(void)
{
 install_port_read_handler(0, 0x08, 0x08, depthch_input_port_1_r);
 install_port_write_handler(0, 0x04, 0x04, depthch_sh_port1_w);
 samples_interface.samplenames = depthch_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_depthch()
{
 install_port_read_handler(0, 0x08, 0x08, depthch_input_port_1_r);
 install_port_write_handler(0, 0x04, 0x04, depthch_sh_port1_w);
 samples_interface.samplenames = depthch_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_nosamples()
{
qword_6D8 = 0LL;
return vicdual_decode();
}

canonical_decompiled_code:
void *func9()
{
qword_6D8 = 0LL;
return func7();
}

original_code:
static void init_nosamples(void)
{
 samples_interface.samplenames = 0;
 vicdual_decode();
}

canonical_original_code:
static void init_nosamples()
{
 samples_interface.samplenames = 0;
 vicdual_decode();
}


decompiled_code:
void *init_invho2()
{
install_port_write_handler(0LL, 2LL, 2LL, &invinco_sh_port2_w);
qword_6D8 = (__int64)&invinco_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func10()
{
install_port_write_handler(0LL, 2LL, 2LL, &invinco_sh_port2_w);
qword_6D8 = (__int64)&invinco_sample_names;
return func7();
}

original_code:
static void init_invho2(void)
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_invho2()
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_invinco()
{
install_port_write_handler(0LL, 2LL, 2LL, &invinco_sh_port2_w);
qword_6D8 = (__int64)&invinco_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func11()
{
install_port_write_handler(0LL, 2LL, 2LL, &invinco_sh_port2_w);
qword_6D8 = (__int64)&invinco_sample_names;
return func7();
}

original_code:
static void init_invinco(void)
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_invinco()
{
 install_port_write_handler(0, 0x02, 0x02, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_invds()
{
install_port_write_handler(0LL, 1LL, 1LL, &invinco_sh_port2_w);
qword_6D8 = (__int64)&invinco_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func12()
{
install_port_write_handler(0LL, 1LL, 1LL, &invinco_sh_port2_w);
qword_6D8 = (__int64)&invinco_sample_names;
return func7();
}

original_code:
static void init_invds(void)
{
 install_port_write_handler(0, 0x01, 0x01, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_invds()
{
 install_port_write_handler(0, 0x01, 0x01, invinco_sh_port2_w);
 samples_interface.samplenames = invinco_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_carnival()
{
install_port_write_handler(0LL, 1LL, 1LL, &carnival_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &carnival_sh_port2_w);
qword_6D8 = (__int64)&carnival_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func13()
{
install_port_write_handler(0LL, 1LL, 1LL, &carnival_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &carnival_sh_port2_w);
qword_6D8 = (__int64)&carnival_sample_names;
return func7();
}

original_code:
static void init_carnival(void)
{
 install_port_write_handler(0, 0x01, 0x01, carnival_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, carnival_sh_port2_w);
 samples_interface.samplenames = carnival_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_carnival()
{
 install_port_write_handler(0, 0x01, 0x01, carnival_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, carnival_sh_port2_w);
 samples_interface.samplenames = carnival_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_pulsar()
{
install_port_write_handler(0LL, 1LL, 1LL, &pulsar_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &pulsar_sh_port2_w);
qword_6D8 = (__int64)&pulsar_sample_names;
return vicdual_decode();
}

canonical_decompiled_code:
void *func14()
{
install_port_write_handler(0LL, 1LL, 1LL, &pulsar_sh_port1_w);
install_port_write_handler(0LL, 2LL, 2LL, &pulsar_sh_port2_w);
qword_6D8 = (__int64)&pulsar_sample_names;
return func7();
}

original_code:
static void init_pulsar(void)
{
 install_port_write_handler(0, 0x01, 0x01, pulsar_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, pulsar_sh_port2_w);
 samples_interface.samplenames = pulsar_sample_names;
 vicdual_decode();
}

canonical_original_code:
static void init_pulsar()
{
 install_port_write_handler(0, 0x01, 0x01, pulsar_sh_port1_w);
 install_port_write_handler(0, 0x02, 0x02, pulsar_sh_port2_w);
 samples_interface.samplenames = pulsar_sample_names;
 vicdual_decode();
}


decompiled_code:
void *init_samurai()
{
install_mem_write_handler(0LL, 32512LL, 32512LL, samurai_protection_w);
install_port_read_handler(0LL, 1LL, 3LL, samurai_input_r);
qword_6D8 = 0LL;
return vicdual_decode();
}

canonical_decompiled_code:
void *func15()
{
install_mem_write_handler(0LL, 32512LL, 32512LL, samurai_protection_w);
install_port_read_handler(0LL, 1LL, 3LL, samurai_input_r);
qword_6D8 = 0LL;
return func7();
}

original_code:
static void init_samurai(void)
{
 install_mem_write_handler(0, 0x7f00, 0x7f00, samurai_protection_w);
 install_port_read_handler(0, 0x01, 0x03, samurai_input_r);
 samples_interface.samplenames = 0;
 vicdual_decode();
}

canonical_original_code:
static void init_samurai()
{
 install_mem_write_handler(0, 0x7f00, 0x7f00, samurai_protection_w);
 install_port_read_handler(0, 0x01, 0x03, samurai_input_r);
 samples_interface.samplenames = 0;
 vicdual_decode();
}


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

v1 = 2;
if ( protection_data != 171 )
{
v1 = 0;
if ( protection_data == 29 )
v1 = 12;
}
return (v1 >> a1) & 2 | (unsigned int)(readinputport((unsigned int)(a1 + 1)) & 0xFD);
}

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

v1 = 2;
if ( protection_data != 171 )
{
v1 = 0;
if ( protection_data == 29 )
v1 = 12;
}
return (v1 >> a1) & 2 | (unsigned int)(readinputport((unsigned int)(a1 + 1)) & 0xFD);
}

original_code:
static data_t samurai_input_r(offs_t offset)
{
 int answer = 0;
 if (protection_data == 0xab) answer = 0x02;
 else if (protection_data == 0x1d) answer = 0x0c;
 return (readinputport(1 + offset) & 0xfd) | ((answer >> offset) & 0x02);
}

canonical_original_code:
static unsigned int samurai_input_r(unsigned int offset)
{
 int answer = 0;
 if (protection_data == 0xab) answer = 0x02;
 else if (protection_data == 0x1d) answer = 0x0c;
 return (readinputport(1 + offset) & 0xfd) | ((answer >> offset) & 0x02);
}

variable_types: answer int


decompiled_code:
__int64 __fastcall bladestl_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // rdx

v4 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 24LL));
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 824) + 688LL) + 40LL) + (int)v6)) = (*(_BYTE *)(a3 + v6) & 0xF) + 32;
v4 = Machine;
++v6;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 24LL));
}
while ( (int)result > (int)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // rdx

v4 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 24LL));
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v4 + 824) + 688LL) + 40LL) + (int)v6)) = (*(_BYTE *)(a3 + v6) & 0xF) + 32;
v4 = Machine;
++v6;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 520LL) + 24LL));
}
while ( (int)result > (int)v6 );
}
return result;
}

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

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

variable_types: i int


decompiled_code:
void bladestl_port_A_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


decompiled_code:
void bladestl_port_B_w()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

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

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


decompiled_code:
void bladestl_speech_ctrl_w()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

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

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


decompiled_code:
__int64 bladestl_vh_start()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_7B4 = 1;
v0 = K007342_vh_start(0LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_7B4 = 1;
v0 = K007342_vh_start(0LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int bladestl_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 1;
 if (K007342_vh_start(0,tile_callback))
 {
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int bladestl_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 1;
 if (K007342_vh_start(0,tile_callback))
 {
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 bladestl_vh_stop()
{
K007342_vh_stop();
return K007420_vh_stop();
}

original_code:
void bladestl_vh_stop(void)
{
 K007342_vh_stop();
 K007420_vh_stop();
}

canonical_original_code:
void bladestl_vh_stop()
{
 K007342_vh_stop();
 K007420_vh_stop();
}


decompiled_code:
__int64 __fastcall bladestl_vh_screenrefresh(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 1LL, 16LL);
K007420_sprites_draw(a1);
K007342_tilemap_draw(a1, 1LL, 17LL);
K007342_tilemap_draw(a1, 0LL, 0LL);
return K007342_tilemap_draw(a1, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 1LL, 16LL);
K007420_sprites_draw(a1);
K007342_tilemap_draw(a1, 1LL, 17LL);
K007342_tilemap_draw(a1, 0LL, 0LL);
return K007342_tilemap_draw(a1, 0LL, 1LL);
}

original_code:
void bladestl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 1, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 1, 1 | 0x10 );
 K007342_tilemap_draw( bitmap, 0, 0 );
 K007342_tilemap_draw( bitmap, 0, 1 );
}

canonical_original_code:
void bladestl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 1, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 1, 1 | 0x10 );
 K007342_tilemap_draw( bitmap, 0, 0 );
 K007342_tilemap_draw( bitmap, 0, 1 );
}

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


decompiled_code:
__int64 bladestl_interrupt()
{
int v0; // edx
__int64 result; // rax

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}
v0 = K007342_is_INT_enabled();
result = 2LL;
if ( !v0 )
return ignore_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // edx
__int64 result; // rax

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}
v0 = K007342_is_INT_enabled();
result = 2LL;
if ( !v0 )
return ignore_interrupt();
return result;
}

original_code:
static int bladestl_interrupt( void )
{
 if (cpu_getiloops() == 0){
  if (K007342_is_INT_enabled())
   return 2;
 }
 else if (cpu_getiloops() % 2){
  return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int bladestl_interrupt()
{
 if (cpu_getiloops() == 0){
  if (K007342_is_INT_enabled())
   return 2;
 }
 else if (cpu_getiloops() % 2){
  return nmi_interrupt();
 }
 return ignore_interrupt();
}


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

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

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

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


decompiled_code:
__int64 __fastcall sprite_callback(int *a1, int *a2)
{
int v2; // eax
__int64 result; // rax

v2 = *a1 | (bladestl_spritebank + ((4 * (unsigned __int16)*a2) & 0x300));
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 &= 0xFu;
return result;
}

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

v2 = *a1 | (bladestl_spritebank + ((4 * (unsigned __int16)*a2) & 0x300));
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 &= 0xFu;
return result;
}

original_code:
static void sprite_callback(int *code,int *color)
{
 *code |= ((*color & 0xc0) << 2) + bladestl_spritebank;
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0 + (*color & 0x0f);
}

canonical_original_code:
static void sprite_callback(int *code, int *color)
{
 *code |= ((*color & 0xc0) << 2) + bladestl_spritebank;
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0 + (*color & 0x0f);
}

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
__int64 __fastcall trackball_r(int a1)
{
int v1; // eax
int v2; // edx

v1 = readinputport((unsigned int)(a1 + 5));
v2 = v1 - last_0[a1];
last_0[a1] = v1;
return v2 & 0x80 | (unsigned int)(v1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
int v1; // eax
int v2; // edx

v1 = readinputport((unsigned int)(a1 + 5));
v2 = v1 - last_0[a1];
last_0[a1] = v1;
return v2 & 0x80 | (unsigned int)(v1 >> 1);
}

original_code:
static data_t trackball_r(offs_t offset)
{
 static int last[4];
 int curr,delta;
 curr = readinputport(5 + offset);
 delta = (curr - last[offset]) & 0xff;
 last[offset] = curr;
 return (delta & 0x80) | (curr >> 1);
}

canonical_original_code:
static unsigned int trackball_r(unsigned int offset)
{
 static int last[4];
 int curr; int delta;
 curr = readinputport(5 + offset);
 delta = (curr - last[offset]) & 0xff;
 last[offset] = curr;
 return (delta & 0x80) | (curr >> 1);
}

variable_types:
last
int [4]

variable_types: curr int

variable_types: delta int


original_code:
void royalmah_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

canonical_original_code:
void royalmah_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}


decompiled_code:
__int64 __fastcall royalmah_videoram_w(unsigned int a1, char a2)
{
unsigned int v2; // ebp
unsigned __int8 v3; // r12
unsigned int v4; // ebx
unsigned int v5; // er14
__int64 result; // rax

*(_BYTE *)(videoram + a1) = a2;
v2 = *(unsigned __int8 *)(videoram + (a1 & 0x3FFF));
v3 = *(_BYTE *)(videoram + (a1 | 0x4000));
v4 = (unsigned __int8)(4 * a1);
v5 = v4 + 4;
do
{
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
v4,
(unsigned __int8)(a1 >> 6),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)v3 >> 1) & 8 | v2 & 1 | (4 * v3) & 4 | (v2 >> 3) & 2)));
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
v3 >>= 1;
++v4;
}
while ( v4 != v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
unsigned int v2; // ebp
unsigned __int8 v3; // r12
unsigned int v4; // ebx
unsigned int v5; // er14
__int64 result; // rax

*(_BYTE *)(videoram + a1) = a2;
v2 = *(unsigned __int8 *)(videoram + (a1 & 0x3FFF));
v3 = *(_BYTE *)(videoram + (a1 | 0x4000));
v4 = (unsigned __int8)(4 * a1);
v5 = v4 + 4;
do
{
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
v4,
(unsigned __int8)(a1 >> 6),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL * (((int)v3 >> 1) & 8 | v2 & 1 | (4 * v3) & 4 | (v2 >> 3) & 2)));
LOBYTE(v2) = (unsigned __int8)v2 >> 1;
v3 >>= 1;
++v4;
}
while ( v4 != v5 );
return result;
}

original_code:
void royalmah_videoram_w(offs_t offset,data_t data)
{
 int i;
 UINT8 x, y;
 UINT8 col1, col2;
 videoram[offset] = data;
 col1 = videoram[offset & 0x3fff];
 col2 = videoram[offset | 0x4000];
 y = (offset >> 6);
 x = (offset & 0x3f) << 2;
 for (i = 0; i < 4; i++)
 {
  int col = ((col1 & 0x01) >> 0) | ((col1 & 0x10) >> 3) | ((col2 & 0x01) << 2) | ((col2 & 0x10) >> 1);
  plot_pixel(Machine->scrbitmap, x+i, y, Machine->pens[col]);
  col1 >>= 1;
  col2 >>= 1;
 }
}

canonical_original_code:
void royalmah_videoram_w(unsigned int offset, unsigned int data)
{
 int i;
 unsigned char x; unsigned char y;
 unsigned char col1; unsigned char col2;
 videoram[offset] = data;
 col1 = videoram[offset & 0x3fff];
 col2 = videoram[offset | 0x4000];
 y = (offset >> 6);
 x = (offset & 0x3f) << 2;
 for (i = 0; i < 4; i++)
 {
  int col = ((col1 & 0x01) >> 0) | ((col1 & 0x10) >> 3) | ((col2 & 0x01) << 2) | ((col2 & 0x10) >> 1);
  plot_pixel(Machine->scrbitmap, x+i, y, Machine->pens[col]);
  col1 >>= 1;
  col2 >>= 1;
 }
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types: col int


decompiled_code:
void royalmah_rom_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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