decompiled_code:
__int64 __fastcall capbowl_vh_screenrefresh(__int64 a1, int a2)
{
__int64 *v3; // rax
__int64 *v4; // rdx
__int64 result; // rax
__int64 *v6; // r8
__int64 *v7; // rcx
_BYTE *v8; // rdx
int v9; // edi
int v10; // esi
_BYTE *v11; // rax
__int64 v12; // r13
__int64 v13; // r12
unsigned int v14; // ebp
unsigned __int8 v15; // bl
unsigned int v16; // er15
__int64 v17; // r8
int v18; // [rsp+4h] [rbp-54h]
__int64 v19; // [rsp+8h] [rbp-50h]
int v20; // [rsp+18h] [rbp-40h]

if ( a2 && max_row >= 0 )
{
v3 = &dirty_row;
v4 = (__int64 *)((char *)&dirty_row + (unsigned int)max_row + 1);
do
{
*(_BYTE *)v3 = 1;
v3 = (__int64 *)((char *)v3 + 1);
}
while ( v3 != v4 );
}
if ( TMS34061_display_blanked() )
return fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
result = palette_recalc();
if ( result )
{
if ( max_row < 0 )
return result;
v7 = &dirty_row;
v8 = (_BYTE *)(result + 16);
v9 = 16 * (max_row + 1);
v10 = 0;
do
{
v6 = v7;
if ( !*(_BYTE *)v7 )
{
v11 = v8 - 16;
while ( !*v11 )
{
if ( ++v11 == v8 )
goto LABEL_12;
}
*(_BYTE *)v7 = 1;
}
LABEL_12:
v7 = (__int64 *)((char *)v7 + 1);
v8 += 16;
v10 += 16;
}
while ( v10 != v9 );
}
else if ( max_row < 0 )
{
return result;
}
v12 = 0LL;
v19 = a1;
do
{
result = (__int64)&dirty_row;
if ( *((_BYTE *)&dirty_row + v12) )
{
result = ((_DWORD)v12 << 8) | 0x20u;
v18 = 16 * v12;
*((_BYTE *)&dirty_row + v12) = 0;
if ( max_col_offset > 32 )
{
v13 = (int)result;
v14 = 0;
v20 = 32 - result;
do
{
v15 = *((_BYTE *)raw_video_ram + v13);
v16 = v14 + 1;
plot_pixel(
v19,
v14,
(unsigned int)v12,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v18 | ((int)v15 >> 4))),
v6);
v14 += 2;
plot_pixel(
v19,
v16,
(unsigned int)v12,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v18 | v15 & 0xF)),
v17);
result = (unsigned int)(++v13 + v20);
}
while ( (int)result < max_col_offset );
}
}
++v12;
}
while ( max_row >= (int)v12 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1, int a2)
{
__int64 *v3; // rax
__int64 *v4; // rdx
__int64 result; // rax
__int64 *v6; // r8
__int64 *v7; // rcx
_BYTE *v8; // rdx
int v9; // edi
int v10; // esi
_BYTE *v11; // rax
__int64 v12; // r13
__int64 v13; // r12
unsigned int v14; // ebp
unsigned __int8 v15; // bl
unsigned int v16; // er15
__int64 v17; // r8
int v18; // [rsp+4h] [rbp-54h]
__int64 v19; // [rsp+8h] [rbp-50h]
int v20; // [rsp+18h] [rbp-40h]

if ( a2 && max_row >= 0 )
{
v3 = &dirty_row;
v4 = (__int64 *)((char *)&dirty_row + (unsigned int)max_row + 1);
do
{
*(_BYTE *)v3 = 1;
v3 = (__int64 *)((char *)v3 + 1);
}
while ( v3 != v4 );
}
if ( func29() )
return fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
result = palette_recalc();
if ( result )
{
if ( max_row < 0 )
return result;
v7 = &dirty_row;
v8 = (_BYTE *)(result + 16);
v9 = 16 * (max_row + 1);
v10 = 0;
do
{
v6 = v7;
if ( !*(_BYTE *)v7 )
{
v11 = v8 - 16;
while ( !*v11 )
{
if ( ++v11 == v8 )
goto LABEL_12;
}
*(_BYTE *)v7 = 1;
}
LABEL_12:
v7 = (__int64 *)((char *)v7 + 1);
v8 += 16;
v10 += 16;
}
while ( v10 != v9 );
}
else if ( max_row < 0 )
{
return result;
}
v12 = 0LL;
v19 = a1;
do
{
result = (__int64)&dirty_row;
if ( *((_BYTE *)&dirty_row + v12) )
{
result = ((_DWORD)v12 << 8) | 0x20u;
v18 = 16 * v12;
*((_BYTE *)&dirty_row + v12) = 0;
if ( max_col_offset > 32 )
{
v13 = (int)result;
v14 = 0;
v20 = 32 - result;
do
{
v15 = *((_BYTE *)raw_video_ram + v13);
v16 = v14 + 1;
plot_pixel(
v19,
v14,
(unsigned int)v12,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v18 | ((int)v15 >> 4))),
v6);
v14 += 2;
plot_pixel(
v19,
v16,
(unsigned int)v12,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v18 | v15 & 0xF)),
v17);
result = (unsigned int)(++v13 + v20);
}
while ( (int)result < max_col_offset );
}
}
++v12;
}
while ( max_row >= (int)v12 );
return result;
}

original_code:
void capbowl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int col, row;
 const unsigned char *remapped;
 if (full_refresh)
 {
  for (row = 0; row <= max_row; row++) dirty_row[row] = 1;
 }
 if (TMS34061_display_blanked())
 {
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
  return;
 }
 if ((remapped = palette_recalc()) != 0)
 {
  for (row = 0; row <= max_row; row++)
  {
   if (dirty_row[row] == 0)
   {
    int i;
    for (i = 0;i < 16;i++)
    {
     if (remapped[16 * row + i] != 0)
     {
      dirty_row[row] = 1;
      break;
     }
    }
   }
  }
 }
 for (row = 0; row <= max_row; row++)
 {
  if (dirty_row[row])
  {
   int col1 = 0;
   int row1 = (row << 8 | 0x20);
   int row2 = row << 4;
   dirty_row[row] = 0;
   for (col = 0x20; col < max_col_offset; col++)
   {
    int pixel = raw_video_ram[row1++];
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel >> 4) ]);
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel & 0x0f)]);
   }
  }
 }
}

canonical_original_code:
void capbowl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int col; int row;
 unsigned char *remapped;
 if (full_refresh)
 {
  for (row = 0; row <= max_row; row++) dirty_row[row] = 1;
 }
 if (TMS34061_display_blanked())
 {
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
  return;
 }
 if ((remapped = palette_recalc()) != 0)
 {
  for (row = 0; row <= max_row; row++)
  {
   if (dirty_row[row] == 0)
   {
    int i;
    for (i = 0;i < 16;i++)
    {
     if (remapped[16 * row + i] != 0)
     {
      dirty_row[row] = 1;
      break;
     }
    }
   }
  }
 }
 for (row = 0; row <= max_row; row++)
 {
  if (dirty_row[row])
  {
   int col1 = 0;
   int row1 = (row << 8 | 0x20);
   int row2 = row << 4;
   dirty_row[row] = 0;
   for (col = 0x20; col < max_col_offset; col++)
   {
    int pixel = raw_video_ram[row1++];
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel >> 4) ]);
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel & 0x0f)]);
   }
  }
 }
}

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

variable_types:
remapped
unsigned char *


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, 1, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func18(__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, 1, 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,0x01,nvram_size);
  }
 }
}

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

variable_types:
file
void *

return_type: void


decompiled_code:
__int64 __fastcall vert_scale(int a1)
{
return ((2 * (_BYTE)a1) & 0xE) + 10 * ((a1 >> 3) & 0x1Fu);
}

original_code:
static int vert_scale(int data)
{
 return ((data & 0x07)<<1) + ((data & 0xf8)>>3) * 10;
}

variable_types: data int

return_type: int


decompiled_code:
void lazercmd_ctrl_port_w()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

original_code:
static data_t lazercmd_ctrl_port_r(offs_t offset)
{
 int data = 0;
 return data;
}

canonical_original_code:
static unsigned int lazercmd_ctrl_port_r(unsigned int offset)
{
 int data = 0;
 return data;
}

return_type: unsigned int


decompiled_code:
void lazercmd_data_port_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


decompiled_code:
__int64 __fastcall plot_pattern(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // ebx
__int64 result; // rax
unsigned int v6; // ebp
unsigned int v7; // er12
unsigned int v8; // er13

v3 = a2;
result = input_port_2_r(0LL) & 0x40;
if ( a3 <= 0xEF )
{
v6 = a2;
v7 = a2 + ((_DWORD)result == 0 ? 2 : 4);
do
{
if ( v3 <= 0xFF )
result = plot_pixel(a1, v3, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 4LL));
++v3;
}
while ( v3 != v7 );
v8 = a3 + 1;
if ( v8 <= 0xEF )
{
do
{
if ( v6 <= 0xFF )
result = plot_pixel(a1, v6, v8, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 4LL));
++v6;
}
while ( v6 != v7 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // ebx
__int64 result; // rax
unsigned int v6; // ebp
unsigned int v7; // er12
unsigned int v8; // er13

v3 = a2;
result = input_port_2_r(0LL) & 0x40;
if ( a3 <= 0xEF )
{
v6 = a2;
v7 = a2 + ((_DWORD)result == 0 ? 2 : 4);
do
{
if ( v3 <= 0xFF )
result = plot_pixel(a1, v3, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 4LL));
++v3;
}
while ( v3 != v7 );
v8 = a3 + 1;
if ( v8 <= 0xEF )
{
do
{
if ( v6 <= 0xFF )
result = plot_pixel(a1, v6, v8, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 4LL));
++v6;
}
while ( v6 != v7 );
}
}
return result;
}

original_code:
static void plot_pattern(struct osd_bitmap *bitmap, int x, int y)
{
 int xbit, ybit, size;
    size = 2;
 if (input_port_2_r(0) & 0x40)
    {
  size = 4;
    }
 for (ybit = 0; ybit < 2; ybit++)
 {
     if (y+ybit < 0 || y+ybit >= 24 * 10)
      return;
     for (xbit = 0; xbit < size; xbit++)
  {
   if (x+xbit < 0 || x+xbit >= 32 * 8)
    continue;
   plot_pixel(bitmap, x+xbit, y+ybit, Machine->pens[2]);
  }
 }
}

canonical_original_code:
static void plot_pattern(struct osd_bitmap *bitmap, int x, int y)
{
 int xbit; int ybit; int size;
    size = 2;
 if (input_port_2_r(0) & 0x40)
    {
  size = 4;
    }
 for (ybit = 0; ybit < 2; ybit++)
 {
     if (y+ybit < 0 || y+ybit >= 24 * 10)
      return;
     for (xbit = 0; xbit < size; xbit++)
  {
   if (x+xbit < 0 || x+xbit >= 32 * 8)
    continue;
   plot_pixel(bitmap, x+xbit, y+ybit, Machine->pens[2]);
  }
 }
}

variable_types: x int

variable_types: y int

variable_types: xbit int

variable_types: ybit int

variable_types: size int

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


decompiled_code:
__int64 lazercmd_data_port_r()
{
return input_port_2_r(0LL) & 0xF;
}

canonical_decompiled_code:
__int64 func6()
{
return input_port_2_r(0LL) & 0xF;
}

original_code:
static data_t lazercmd_data_port_r(offs_t offset)
{
 int data;
 data = input_port_2_r(0) & 0x0f;
 return data;
}

canonical_original_code:
static unsigned int lazercmd_data_port_r(unsigned int offset)
{
 int data;
 data = input_port_2_r(0) & 0x0f;
 return data;
}


decompiled_code:
__int64 lazercmd_vh_start()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
if ( (input_port_2_r(0LL) & 0x80u) != 0LL )
overlay_create(&overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
if ( (input_port_2_r(0LL) & 0x80u) != 0LL )
overlay_create(&overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
}
return v0;
}

original_code:
int lazercmd_vh_start(void)
{
 if( generic_vh_start() )
  return 1;
 if (input_port_2_r(0) & 0x80)
 {
  overlay_create(overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}

canonical_original_code:
int lazercmd_vh_start()
{
 if( generic_vh_start() )
  return 1;
 if (input_port_2_r(0) & 0x80)
 {
  overlay_create(overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall lazercmd_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 i; // rbx
int v4; // eax

if ( (input_port_2_r(0LL) & 0x20) != video_inverted )
{
LOBYTE(video_inverted) = input_port_2_r(0LL) & 0x20;
video_inverted = (unsigned __int8)video_inverted;
memset(dirtybuffer, 1, videoram_size);
}
v2 = palette_recalc();
if ( a2 || v2 )
memset(dirtybuffer, 1, videoram_size);
for ( i = 0LL; i != 736; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
*((_BYTE *)dirtybuffer + i) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + i),
video_inverted != 0,
0LL,
0LL,
(unsigned int)(8 * ((int)i % 32)),
(unsigned int)(10 * ((int)i / 32)),
Machine + 776LL,
0LL,
0LL);
}
}
v4 = vert_scale(marker_y);
return plot_pattern(a1, marker_x - 1, v4 - 10);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 i; // rbx
int v4; // eax

if ( (input_port_2_r(0LL) & 0x20) != video_inverted )
{
LOBYTE(video_inverted) = input_port_2_r(0LL) & 0x20;
video_inverted = (unsigned __int8)video_inverted;
memset(dirtybuffer, 1, videoram_size);
}
v2 = palette_recalc();
if ( a2 || v2 )
memset(dirtybuffer, 1, videoram_size);
for ( i = 0LL; i != 736; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
*((_BYTE *)dirtybuffer + i) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + i),
video_inverted != 0,
0LL,
0LL,
(unsigned int)(8 * ((int)i % 32)),
(unsigned int)(10 * ((int)i / 32)),
Machine + 776LL,
0LL,
0LL);
}
}
v4 = func0(marker_y);
return func5(a1, marker_x - 1, v4 - 10);
}

original_code:
void lazercmd_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i,x,y;
 if (video_inverted != (input_port_2_r(0) & 0x20))
 {
  video_inverted = input_port_2_r(0) & 0x20;
  memset(dirtybuffer, 1, videoram_size);
 }
 if (palette_recalc() || full_refresh)
        memset(dirtybuffer, 1, videoram_size);
 for (i = 0; i < (24 - 1) * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int sx,sy;
   dirtybuffer[i] = 0;
   sx = i % 32;
   sy = i / 32;
   sx *= 8;
   sy *= 10;
   drawgfx(bitmap, Machine->gfx[0],
     videoram[i], video_inverted ? 1 : 0,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 x = marker_x - 1;
 y = vert_scale(marker_y) - 10;
 plot_pattern(bitmap,x,y);
}

canonical_original_code:
void lazercmd_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i; int x; int y;
 if (video_inverted != (input_port_2_r(0) & 0x20))
 {
  video_inverted = input_port_2_r(0) & 0x20;
  memset(dirtybuffer, 1, videoram_size);
 }
 if (palette_recalc() || full_refresh)
        memset(dirtybuffer, 1, videoram_size);
 for (i = 0; i < (24 - 1) * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int sx; int sy;
   dirtybuffer[i] = 0;
   sx = i % 32;
   sy = i / 32;
   sx *= 8;
   sy *= 10;
   drawgfx(bitmap, Machine->gfx[0],
     videoram[i], video_inverted ? 1 : 0,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 x = marker_x - 1;
 y = vert_scale(marker_y) - 10;
 plot_pattern(bitmap,x,y);
}

variable_types: i int

variable_types: sx int

variable_types: sy int


variable_types:
d
unsigned char *

variable_types:
s
unsigned char *


decompiled_code:
__int64 lazercmd_timer()
{
int v1; // eax

if ( timer_count + 1 > 0x1FFF )
{
timer_count = 0;
v1 = sense_state_2;
sense_state_2 ^= 1u;
cpu_set_irq_line(0LL, 1LL, v1 != 1);
}
else
{
++timer_count;
}
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func11()
{
int v1; // eax

if ( timer_count + 1 > 0x1FFF )
{
timer_count = 0;
v1 = sense_state_2;
sense_state_2 ^= 1u;
cpu_set_irq_line(0LL, 1LL, v1 != 1);
}
else
{
++timer_count;
}
return ignore_interrupt();
}

original_code:
static int lazercmd_timer(void)
{
 static int sense_state = 0;
 if( ++timer_count >= 64*128 ) {
  timer_count = 0;
  sense_state ^= 1;
  cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0 );
 }
    return ignore_interrupt();
}

canonical_original_code:
static int lazercmd_timer()
{
 static int sense_state = 0;
 if( ++timer_count >= 64*128 ) {
  timer_count = 0;
  sense_state ^= 1;
  cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0 );
 }
    return ignore_interrupt();
}


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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
result = input_port_1_r(0LL);
break;
case 2:
result = input_port_4_r(0LL);
break;
case 3:
result = input_port_3_r(0LL);
break;
case 4:
result = (timer_count >> 7) & 1 | (timer_count >> 5) & 2 | (timer_count >> 3) & 4 | (timer_count >> 1) & 8u;
break;
case 5:
result = timer_count & 0xF;
break;
case 6:
result = marker_x;
break;
case 7:
result = marker_y;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
result = input_port_1_r(0LL);
break;
case 2:
result = input_port_4_r(0LL);
break;
case 3:
result = input_port_3_r(0LL);
break;
case 4:
result = (timer_count >> 7) & 1 | (timer_count >> 5) & 2 | (timer_count >> 3) & 4 | (timer_count >> 1) & 8u;
break;
case 5:
result = timer_count & 0xF;
break;
case 6:
result = marker_x;
break;
case 7:
result = marker_y;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static data_t lazercmd_hardware_r(offs_t offset)
{
 int data = 0;
 switch (offset)
 {
  case 0:
   data = input_port_0_r(0);
   break;
  case 1:
   data = input_port_1_r(0);
   break;
  case 2:
   data = input_port_4_r(0);
   break;
  case 3:
   data = input_port_3_r(0);
   break;
  case 4:
   data = ((timer_count&0x10)>>1)|((timer_count&0x20)>>3)|((timer_count&0x40)>>5)|((timer_count&0x80)>>7);
   break;
  case 5:
   data = timer_count & 0x0f;
   break;
  case 6:
   data = marker_x;
   break;
  case 7:
   data = marker_y;
   break;
 }
    return data;
}

canonical_original_code:
static unsigned int lazercmd_hardware_r(unsigned int offset)
{
 int data = 0;
 switch (offset)
 {
  case 0:
   data = input_port_0_r(0);
   break;
  case 1:
   data = input_port_1_r(0);
   break;
  case 2:
   data = input_port_4_r(0);
   break;
  case 3:
   data = input_port_3_r(0);
   break;
  case 4:
   data = ((timer_count&0x10)>>1)|((timer_count&0x20)>>3)|((timer_count&0x40)>>5)|((timer_count&0x80)>>7);
   break;
  case 5:
   data = timer_count & 0x0f;
   break;
  case 6:
   data = marker_x;
   break;
  case 7:
   data = marker_y;
   break;
 }
    return data;
}


decompiled_code:
__int64 lazercmd_marker_dirty()
{
__int64 result; // rax
int v1; // ebx
int v2; // ebp
int v3; // edx
int v4; // ecx
int v5; // eax
int v6; // ecx
int v7; // ebx
int v8; // ebx

result = (__int64)&marker_x;
v1 = marker_x;
v2 = marker_x - 1;
if ( (unsigned int)(marker_x - 1) <= 0xFF )
{
result = vert_scale(marker_y);
if ( (unsigned int)(result - 10) <= 0xE5 )
{
v3 = 32 * (((int)result - 10) / 10);
v4 = v2 / 8;
*((_BYTE *)dirtybuffer + v3 + v4) = 1;
v5 = 32 * (((int)result - 7) / 10);
*((_BYTE *)dirtybuffer + v5 + v4) = 1;
v6 = v1 + 9;
v7 = v1 + 2;
if ( v7 < 0 )
v7 = v6;
v8 = v7 >> 3;
*((_BYTE *)dirtybuffer + v8 + v3) = 1;
result = v8 + v5;
*((_BYTE *)dirtybuffer + result) = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // ebx
int v2; // ebp
int v3; // edx
int v4; // ecx
int v5; // eax
int v6; // ecx
int v7; // ebx
int v8; // ebx

result = (__int64)&marker_x;
v1 = marker_x;
v2 = marker_x - 1;
if ( (unsigned int)(marker_x - 1) <= 0xFF )
{
result = func0(marker_y);
if ( (unsigned int)(result - 10) <= 0xE5 )
{
v3 = 32 * (((int)result - 10) / 10);
v4 = v2 / 8;
*((_BYTE *)dirtybuffer + v3 + v4) = 1;
v5 = 32 * (((int)result - 7) / 10);
*((_BYTE *)dirtybuffer + v5 + v4) = 1;
v6 = v1 + 9;
v7 = v1 + 2;
if ( v7 < 0 )
v7 = v6;
v8 = v7 >> 3;
*((_BYTE *)dirtybuffer + v8 + v3) = 1;
result = v8 + v5;
*((_BYTE *)dirtybuffer + result) = 1;
}
}
return result;
}

variable_types: marker int


decompiled_code:
__int64 sbrkout_select1_r()
{
return (unsigned __int8)(sbrkout_game_switch == 2) << 7;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned __int8)(sbrkout_game_switch == 2) << 7;
}

original_code:
data_t sbrkout_select1_r(offs_t offset)
{
    if (sbrkout_game_switch==0x02)
        return 0x80;
    else return 0x00;
}

canonical_original_code:
unsigned int sbrkout_select1_r(unsigned int offset)
{
    if (sbrkout_game_switch==0x02)
        return 0x80;
    else return 0x00;
}


decompiled_code:
__int64 sbrkout_select2_r()
{
return (unsigned __int8)(sbrkout_game_switch == 1) << 7;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int8)(sbrkout_game_switch == 1) << 7;
}

original_code:
data_t sbrkout_select2_r(offs_t offset)
{
    if (sbrkout_game_switch==0x01)
        return 0x80;
    else return 0x00;
}

canonical_original_code:
unsigned int sbrkout_select2_r(unsigned int offset)
{
    if (sbrkout_game_switch==0x01)
        return 0x80;
    else return 0x00;
}


decompiled_code:
__int64 sbrkout_interrupt()
{
char v0; // al

v0 = input_port_7_r(0LL);
if ( (v0 & 1) != 0 )
{
sbrkout_game_switch = 0;
}
else if ( (v0 & 2) != 0 )
{
sbrkout_game_switch = 1;
}
else if ( (v0 & 4) != 0 )
{
sbrkout_game_switch = 2;
}
return interrupt();
}

canonical_decompiled_code:
__int64 func2()
{
char v0; // al

v0 = input_port_7_r(0LL);
if ( (v0 & 1) != 0 )
{
sbrkout_game_switch = 0;
}
else if ( (v0 & 2) != 0 )
{
sbrkout_game_switch = 1;
}
else if ( (v0 & 4) != 0 )
{
sbrkout_game_switch = 2;
}
return interrupt();
}

original_code:
int sbrkout_interrupt(void)
{
    int game_switch;
    game_switch=input_port_7_r(0);
    if (game_switch & 0x01)
        sbrkout_game_switch=0x00;
    else if (game_switch & 0x02)
        sbrkout_game_switch=0x01;
    else if (game_switch & 0x04)
        sbrkout_game_switch=0x02;
    return interrupt();
}

canonical_original_code:
int sbrkout_interrupt()
{
    int game_switch;
    game_switch=input_port_7_r(0);
    if (game_switch & 0x01)
        sbrkout_game_switch=0x00;
    else if (game_switch & 0x02)
        sbrkout_game_switch=0x01;
    else if (game_switch & 0x04)
        sbrkout_game_switch=0x02;
    return interrupt();
}


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

if ( a1 == 2 )
return input_port_0_r(0LL) & 0xC0;
if ( a1 > 2 )
{
result = 255LL;
if ( a1 == 3 )
result = (unsigned __int8)(4 * input_port_0_r(0LL)) & 0xC0;
}
else if ( a1 )
{
result = (unsigned __int8)(16 * input_port_0_r(0LL)) & 0xC0;
}
else
{
result = (unsigned __int8)((unsigned __int8)input_port_0_r(0LL) << 6);
}
return result;
}

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

if ( a1 == 2 )
return input_port_0_r(0LL) & 0xC0;
if ( a1 > 2 )
{
result = 255LL;
if ( a1 == 3 )
result = (unsigned __int8)(4 * input_port_0_r(0LL)) & 0xC0;
}
else if ( a1 )
{
result = (unsigned __int8)(16 * input_port_0_r(0LL)) & 0xC0;
}
else
{
result = (unsigned __int8)((unsigned __int8)input_port_0_r(0LL) << 6);
}
return result;
}

original_code:
data_t sbrkout_read_DIPs_r(offs_t offset)
{
        switch (offset)
        {
                case 0x00: return ((input_port_0_r(0) & 0x03) << 6);
                case 0x01: return ((input_port_0_r(0) & 0x0C) << 4);
                case 0x02: return ((input_port_0_r(0) & 0xC0) << 0);
                case 0x03: return ((input_port_0_r(0) & 0x30) << 2);
                default: return 0xFF;
        }
}

canonical_original_code:
unsigned int sbrkout_read_DIPs_r(unsigned int offset)
{
        switch (offset)
        {
                case 0x00: return ((input_port_0_r(0) & 0x03) << 6);
                case 0x01: return ((input_port_0_r(0) & 0x0C) << 4);
                case 0x02: return ((input_port_0_r(0) & 0xC0) << 0);
                case 0x03: return ((input_port_0_r(0) & 0x30) << 2);
                default: return 0xFF;
        }
}


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

if ( (_DWORD)a1 )
result = osd_led_w(0LL, 1LL);
else
result = osd_led_w(a1, 0LL);
return result;
}

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

if ( (_DWORD)a1 )
result = osd_led_w(0LL, 1LL);
else
result = osd_led_w(a1, 0LL);
return result;
}

original_code:
void sbrkout_start_1_led_w(offs_t offset,data_t data)
{
    if (offset==0)
        osd_led_w(0,0);
    else
        osd_led_w(0,1);
}

canonical_original_code:
void sbrkout_start_1_led_w(unsigned int offset, unsigned int data)
{
    if (offset==0)
        osd_led_w(0,0);
    else
        osd_led_w(0,1);
}


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

if ( a1 )
result = osd_led_w(1LL, 1LL);
else
result = osd_led_w(1LL, 0LL);
return result;
}

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

if ( a1 )
result = osd_led_w(1LL, 1LL);
else
result = osd_led_w(1LL, 0LL);
return result;
}

original_code:
void sbrkout_start_2_led_w(offs_t offset,data_t data)
{
    if (offset==0)
        osd_led_w(1,0);
    else
        osd_led_w(1,1);
}

canonical_original_code:
void sbrkout_start_2_led_w(unsigned int offset, unsigned int data)
{
    if (offset==0)
        osd_led_w(1,0);
    else
        osd_led_w(1,1);
}


decompiled_code:
__int64 sbrkout_vh_start()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&sbrkout_ol, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&sbrkout_ol, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int sbrkout_vh_start(void)
{
 int start_pen = 2;
 if (generic_vh_start()!=0)
  return 1;
 overlay_create(sbrkout_ol, start_pen, Machine->drv->total_colors-start_pen);
 return 0;
}

canonical_original_code:
int sbrkout_vh_start()
{
 int start_pen = 2;
 if (generic_vh_start()!=0)
  return 1;
 overlay_create(sbrkout_ol, start_pen, Machine->drv->total_colors-start_pen);
 return 0;
}


decompiled_code:
__int64 __fastcall sbrkout_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v2; // rax
int v3; // ebx
__int64 v4; // rbp
__int64 i; // rbx
__int64 result; // rax

v2 = palette_recalc();
if ( a2 || v2 )
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v4) & 0x3F,
*(_BYTE *)(videoram + v4) >> 7,
0LL,
0LL,
(unsigned int)(8 * (v3 % 32)),
(unsigned int)(8 * (v3 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v4;
--v3;
}
while ( v3 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 4LL; i != -2; i -= 2LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(sbrkout_vert_ram + i + 1) >> 7,
1LL,
0LL,
0LL,
248 - (unsigned int)*(unsigned __int8 *)(sbrkout_horiz_ram + i),
240 - (unsigned int)*(unsigned __int8 *)(sbrkout_vert_ram + i),
Machine + 776LL,
2LL,
0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rax
int v3; // ebx
__int64 v4; // rbp
__int64 i; // rbx
__int64 result; // rax

v2 = palette_recalc();
if ( a2 || v2 )
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v4) & 0x3F,
*(_BYTE *)(videoram + v4) >> 7,
0LL,
0LL,
(unsigned int)(8 * (v3 % 32)),
(unsigned int)(8 * (v3 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v4;
--v3;
}
while ( v3 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( i = 4LL; i != -2; i -= 2LL )
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(sbrkout_vert_ram + i + 1) >> 7,
1LL,
0LL,
0LL,
248 - (unsigned int)*(unsigned __int8 *)(sbrkout_horiz_ram + i),
240 - (unsigned int)*(unsigned __int8 *)(sbrkout_vert_ram + i),
Machine + 776LL,
2LL,
0LL);
return result;
}

original_code:
void sbrkout_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int ball;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int code,sx,sy,color;
   dirtybuffer[offs]=0;
   code = videoram[offs] & 0x3f;
   sx = 8*(offs % 32);
   sy = 8*(offs / 32);
   color = ((videoram[offs] & 0x80)>>7);
   drawgfx(tmpbitmap,Machine->gfx[0],
     code, color,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (ball=2;ball>=0;ball--)
 {
  int sx,sy,code;
  sx = 31*8-sbrkout_horiz_ram[ball*2];
  sy = 30*8-sbrkout_vert_ram[ball*2];
  code = ((sbrkout_vert_ram[ball*2+1] & 0x80) >> 7);
  drawgfx(bitmap,Machine->gfx[1],
    code,1,
    0,0,sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void sbrkout_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int ball;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int code; int sx; int sy; int color;
   dirtybuffer[offs]=0;
   code = videoram[offs] & 0x3f;
   sx = 8*(offs % 32);
   sy = 8*(offs / 32);
   color = ((videoram[offs] & 0x80)>>7);
   drawgfx(tmpbitmap,Machine->gfx[0],
     code, color,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (ball=2;ball>=0;ball--)
 {
  int sx; int sy; int code;
  sx = 31*8-sbrkout_horiz_ram[ball*2];
  sy = 30*8-sbrkout_vert_ram[ball*2];
  code = ((sbrkout_vert_ram[ball*2+1] & 0x80) >> 7);
  drawgfx(bitmap,Machine->gfx[1],
    code,1,
    0,0,sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: ball int

variable_types: code int

variable_types: color int


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

result = sbrkout_sound;
*(_BYTE *)(sbrkout_sound + a1) = a2;
if ( init_timer )
{
result = timer_set(1093874LL, 0LL, sbrkout_tones_4V);
init_timer = 0;
}
return result;
}

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

result = sbrkout_sound;
*(_BYTE *)(sbrkout_sound + a1) = a2;
if ( init_timer )
{
result = timer_set(1093874LL, 0LL, sbrkout_tones_4V);
init_timer = 0;
}
return result;
}

original_code:
static void sbrkout_dac_w(offs_t offset,data_t data)
{
 sbrkout_sound[offset]=data;
 if (init_timer)
 {
  timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
  init_timer=0;
 }
}

canonical_original_code:
static void sbrkout_dac_w(unsigned int offset, unsigned int data)
{
 sbrkout_sound[offset]=data;
 if (init_timer)
 {
  timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
  init_timer=0;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 sbrkout_tones_4V()
{
if ( ((unsigned __int8)vlines_0 & *sbrkout_sound) != 0 )
DAC_data_w(0LL, 255LL);
else
DAC_data_w(0LL, 0LL);
vlines_0 = (vlines_0 + 1) % 16;
return timer_set(1093874LL, 0LL, sbrkout_tones_4V);
}

canonical_decompiled_code:
__int64 func10()
{
if ( ((unsigned __int8)vlines_0 & *sbrkout_sound) != 0 )
DAC_data_w(0LL, 255LL);
else
DAC_data_w(0LL, 0LL);
vlines_0 = (vlines_0 + 1) % 16;
return timer_set(1093874LL, 0LL, sbrkout_tones_4V);
}

original_code:
static void sbrkout_tones_4V(int foo)
{
 static int vlines=0;
 if ((*sbrkout_sound) & vlines)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 vlines = (vlines+1) % 16;
 timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
}

canonical_original_code:
static void sbrkout_tones_4V(int foo)
{
 static int vlines = 0;
 if ((*sbrkout_sound) & vlines)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 vlines = (vlines+1) % 16;
 timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
}

variable_types: foo int

variable_types: vlines int


decompiled_code:
__int64 sbrkout_irq_w()
{
return cpu_cause_interrupt(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func11()
{
return cpu_cause_interrupt(0LL, 1LL);
}

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

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


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

if ( a1 )
result = osd_led_w(2LL, 0LL);
else
result = osd_led_w(2LL, 1LL);
return result;
}

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

if ( a1 )
result = osd_led_w(2LL, 0LL);
else
result = osd_led_w(2LL, 1LL);
return result;
}

original_code:
void sbrkout_serve_led_w(offs_t offset,data_t data)
{
    if (offset==0)
        osd_led_w(2,1);
    else
        osd_led_w(2,0);
}

canonical_original_code:
void sbrkout_serve_led_w(unsigned int offset, unsigned int data)
{
    if (offset==0)
        osd_led_w(2,1);
    else
        osd_led_w(2,0);
}


decompiled_code:
void *__fastcall init_palette(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}


original_code:
void geebee_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, const unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, geebee_colortable, sizeof (geebee_colortable));
}

canonical_original_code:
void geebee_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, geebee_colortable, sizeof (geebee_colortable));
}


original_code:
void navalone_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, const unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, navalone_colortable, sizeof (navalone_colortable));
}

canonical_original_code:
void navalone_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, navalone_colortable, sizeof (navalone_colortable));
}


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

result = Machine;
if ( (int)a2 <= *(_DWORD *)(Machine + 780LL)
&& (int)a3 <= *(_DWORD *)(Machine + 788LL)
&& (int)a3 >= *(_DWORD *)(Machine + 784LL)
&& *(_DWORD *)(Machine + 776LL) <= (int)a2 )
{
result = plot_pixel(a1, a2, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL));
}
return result;
}

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

result = Machine;
if ( (int)a2 <= *(_DWORD *)(Machine + 780LL)
&& (int)a3 <= *(_DWORD *)(Machine + 788LL)
&& (int)a3 >= *(_DWORD *)(Machine + 784LL)
&& *(_DWORD *)(Machine + 776LL) <= (int)a2 )
{
result = plot_pixel(a1, a2, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL));
}
return result;
}

original_code:
static inline void geebee_plot(struct osd_bitmap *bitmap, int x, int y)
{
 struct rectangle r = Machine->visible_area;
 if (x >= r.min_x && x <= r.max_x && y >= r.min_y && y <= r.max_y)
  plot_pixel(bitmap,x,y,Machine->pens[1]);
}

variable_types: x int

variable_types: y int

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


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

result = (unsigned int)(volume - 1);
if ( volume - 1 < 0 )
result = 0LL;
volume = result;
return result;
}

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

result = (unsigned int)(volume - 1);
if ( volume - 1 < 0 )
result = 0LL;
volume = result;
return result;
}

original_code:
static void volume_decay(int param)
{
 if( --volume < 0 )
  volume = 0;
}

variable_types: param int


original_code:
static void geebee_sound_update(int param, INT16 *buffer, int length)
{
    static int vcarry = 0;
    static int vcount = 0;
    while (length--)
    {
  *buffer++ = sound_signal;
  vcarry -= 18432000 / 3 / 2 / 384;
        while (vcarry < 0)
        {
            vcarry += Machine->sample_rate;
            vcount++;
   if ((vcount & 3) == 2)
   {
    if ((noise & 1) == ((noise >> 10) & 1))
     noise = ((noise << 1) & 0xfffe) | 1;
    else
     noise = (noise << 1) & 0xfffe;
   }
            switch (sound_latch & 7)
            {
            case 0:
    sound_signal = (vcount & 0x04) ? decay[volume] : 0;
                break;
            case 1:
    sound_signal = (vcount & 0x08) ? decay[volume] : 0;
                break;
            case 2:
    sound_signal = (vcount & 0x10) ? decay[volume] : 0;
                break;
            case 3:
    sound_signal = (vcount & 0x20) ? decay[volume] : 0;
                break;
            case 4:
    sound_signal = !(vcount & 0x01) && !(vcount & 0x10) ? decay[volume] : 0;
                break;
            case 5:
    sound_signal = !(vcount & 0x02) && !(vcount & 0x20) ? decay[volume] : 0;
                break;
            case 6:
    sound_signal = !(vcount & 0x04) && !(vcount & 0x40) ? decay[volume] : 0;
                break;
   default:
                sound_signal = (noise & 0x8000) ? decay[volume] : 0;
            }
        }
    }
}

canonical_original_code:
static void geebee_sound_update(int param, short *buffer, int length)
{
    static int vcarry = 0;
    static int vcount = 0;
    while (length--)
    {
  *buffer++ = sound_signal;
  vcarry -= 18432000 / 3 / 2 / 384;
        while (vcarry < 0)
        {
            vcarry += Machine->sample_rate;
            vcount++;
   if ((vcount & 3) == 2)
   {
    if ((noise & 1) == ((noise >> 10) & 1))
     noise = ((noise << 1) & 0xfffe) | 1;
    else
     noise = (noise << 1) & 0xfffe;
   }
            switch (sound_latch & 7)
            {
            case 0:
    sound_signal = (vcount & 0x04) ? decay[volume] : 0;
                break;
            case 1:
    sound_signal = (vcount & 0x08) ? decay[volume] : 0;
                break;
            case 2:
    sound_signal = (vcount & 0x10) ? decay[volume] : 0;
                break;
            case 3:
    sound_signal = (vcount & 0x20) ? decay[volume] : 0;
                break;
            case 4:
    sound_signal = !(vcount & 0x01) && !(vcount & 0x10) ? decay[volume] : 0;
                break;
            case 5:
    sound_signal = !(vcount & 0x02) && !(vcount & 0x20) ? decay[volume] : 0;
                break;
            case 6:
    sound_signal = !(vcount & 0x04) && !(vcount & 0x40) ? decay[volume] : 0;
                break;
   default:
                sound_signal = (noise & 0x8000) ? decay[volume] : 0;
            }
        }
    }
}

variable_types:
buffer
short *

variable_types: length int

variable_types: vcarry int

variable_types: vcount int


decompiled_code:
__int64 geebee_interrupt()
{
cpu_set_irq_line(0LL, 0LL, 3LL);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func6()
{
cpu_set_irq_line(0LL, 0LL, 3LL);
return ignore_interrupt();
}

original_code:
int geebee_interrupt(void)
{
 cpu_set_irq_line(0, 0, 3);
    return ignore_interrupt();
}

canonical_original_code:
int geebee_interrupt()
{
 cpu_set_irq_line(0, 0, 3);
    return ignore_interrupt();
}


decompiled_code:
__int64 kaitei_interrupt()
{
cpu_set_irq_line(0LL, 0LL, 2LL);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func7()
{
cpu_set_irq_line(0LL, 0LL, 2LL);
return ignore_interrupt();
}

original_code:
int kaitei_interrupt(void)
{
 cpu_set_irq_line(0, 0, 2);
    return ignore_interrupt();
}

canonical_original_code:
int kaitei_interrupt()
{
 cpu_set_irq_line(0, 0, 2);
    return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall geebee_in_r(char a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx

v1 = ((__int64 (*)(void))readinputport)();
v2 = v1;
if ( (a1 & 3) == 2 )
{
if ( (v1 & 2) != 0 )
v2 = readinputport(5LL) | v1;
else
v2 = readinputport(4LL) | v1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx

v1 = ((__int64 (*)(void))readinputport)();
v2 = v1;
if ( (a1 & 3) == 2 )
{
if ( (v1 & 2) != 0 )
v2 = readinputport(5LL) | v1;
else
v2 = readinputport(4LL) | v1;
}
return v2;
}

original_code:
data_t geebee_in_r(offs_t offset)
{
 int data = readinputport(offset & 3);
 if ((offset & 3) == 2)
 {
  if (data & 0x02)
   data |= readinputport(5);
  else
   data |= readinputport(4);
 }
 return data;
}

canonical_original_code:
unsigned int geebee_in_r(unsigned int offset)
{
 int data = readinputport(offset & 3);
 if ((offset & 3) == 2)
 {
  if (data & 0x02)
   data |= readinputport(5);
  else
   data |= readinputport(4);
 }
 return data;
}

variable_types: data int


decompiled_code:
__int64 __fastcall navalone_in_r(char a1)
{
unsigned int v1; // ebp
char v3; // al

v1 = readinputport(a1 & 3);
if ( (a1 & 3) == 3 )
{
v3 = readinputport(4LL);
if ( (v3 & 1) != 0 )
v1 = 160;
if ( (v3 & 2) != 0 )
v1 = 16;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
unsigned int v1; // ebp
char v3; // al

v1 = readinputport(a1 & 3);
if ( (a1 & 3) == 3 )
{
v3 = readinputport(4LL);
if ( (v3 & 1) != 0 )
v1 = 160;
if ( (v3 & 2) != 0 )
v1 = 16;
}
return v1;
}

original_code:
data_t navalone_in_r(offs_t offset)
{
    int data = readinputport(offset & 3);
 if ((offset & 3) == 3)
 {
  int joy = readinputport(4);
  if( joy & 1 ) data = 0xa0;
  if( joy & 2 ) data = 0x10;
 }
    return data;
}

canonical_original_code:
unsigned int navalone_in_r(unsigned int offset)
{
    int data = readinputport(offset & 3);
 if ((offset & 3) == 3)
 {
  int joy = readinputport(4);
  if( joy & 1 ) data = 0xa0;
  if( joy & 2 ) data = 0x10;
 }
    return data;
}

variable_types: joy int


decompiled_code:
_BOOL8 sos_vh_start()
{
return (unsigned int)generic_vh_start() != 0;
}

canonical_decompiled_code:
_BOOL8 func11()
{
return (unsigned int)generic_vh_start() != 0;
}

original_code:
int sos_vh_start(void)
{
 if( generic_vh_start() )
  return 1;
 return 0;
}

canonical_original_code:
int sos_vh_start()
{
 if( generic_vh_start() )
  return 1;
 return 0;
}


decompiled_code:
_BOOL8 kaitei_vh_start()
{
return (unsigned int)generic_vh_start() != 0;
}

canonical_decompiled_code:
_BOOL8 func12()
{
return (unsigned int)generic_vh_start() != 0;
}

original_code:
int kaitei_vh_start(void)
{
 if( generic_vh_start() )
 return 1;
 return 0;
}

canonical_original_code:
int kaitei_vh_start()
{
 if( generic_vh_start() )
 return 1;
 return 0;
}


decompiled_code:
__int64 geebee_vh_start()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
if ( (readinputport(2LL) & 1) == 0 )
{
overlay_create(&geebee_overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
v0 = 0;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v0; // ebx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
if ( (readinputport(2LL) & 1) == 0 )
{
overlay_create(&geebee_overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
v0 = 0;
}
}
return v0;
}

original_code:
int geebee_vh_start(void)
{
 if( generic_vh_start() )
  return 1;
 if( (readinputport(2) & 0x01) == 0 )
 {
  overlay_create(geebee_overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}

canonical_original_code:
int geebee_vh_start()
{
 if( generic_vh_start() )
  return 1;
 if( (readinputport(2) & 0x01) == 0 )
 {
  overlay_create(geebee_overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}


decompiled_code:
__int64 geebee_sh_update()
{
return stream_update((unsigned int)channel, 0LL);
}

canonical_decompiled_code:
__int64 func14()
{
return stream_update((unsigned int)channel, 0LL);
}

original_code:
void geebee_sh_update(void)
{
 stream_update(channel,0);
}

canonical_original_code:
void geebee_sh_update()
{
 stream_update(channel,0);
}


decompiled_code:
__int64 geebee_sh_start()
{
_WORD *v0; // rax
_WORD *v1; // rbp
int i; // ebx

v0 = malloc(0x10000uLL);
decay = v0;
if ( !v0 )
return 1LL;
v1 = v0 + 0x7FFF;
for ( i = 0; i != 0x8000; ++i )
*v1-- = (int)(32767.0 / exp((double)i * 0.000244140625));
channel = stream_init("GeeBee", 100LL, *(unsigned int *)(Machine + 836LL), 0LL, geebee_sound_update);
return 0LL;
}

canonical_decompiled_code:
__int64 func15()
{
_WORD *v0; // rax
_WORD *v1; // rbp
int i; // ebx

v0 = malloc(0x10000uLL);
decay = v0;
if ( !v0 )
return 1LL;
v1 = v0 + 0x7FFF;
for ( i = 0; i != 0x8000; ++i )
*v1-- = (int)(32767.0 / exp((double)i * 0.000244140625));
channel = stream_init("GeeBee", 100LL, *(unsigned int *)(Machine + 836LL), 0LL, geebee_sound_update);
return 0LL;
}

original_code:
int geebee_sh_start(const struct MachineSound *msound)
{
 int i;
 decay = (UINT16 *)malloc(32768 * sizeof(INT16));
 if( !decay )
  return 1;
    for( i = 0; i < 0x8000; i++ )
  decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096));
 channel = stream_init("GeeBee", 100, Machine->sample_rate, 0, geebee_sound_update);
    return 0;
}

canonical_original_code:
int geebee_sh_start(struct MachineSound *msound)
{
 int i;
 decay = (unsigned short *)malloc(32768 * sizeof(INT16));
 if( !decay )
  return 1;
    for( i = 0; i < 0x8000; i++ )
  decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096));
 channel = stream_init("GeeBee", 100, Machine->sample_rate, 0, geebee_sound_update);
    return 0;
}

variable_types: struct MachineSound { int sound_type; void *sound_interface; } *

variable_types: i int


decompiled_code:
void geebee_sh_stop()
{
if ( volume_timer )
timer_remove();
volume_timer = 0LL;
if ( decay )
free(decay);
decay = 0LL;
}

canonical_decompiled_code:
void func16()
{
if ( volume_timer )
timer_remove();
volume_timer = 0LL;
if ( decay )
free(decay);
decay = 0LL;
}

original_code:
void geebee_sh_stop(void)
{
 if( volume_timer )
  timer_remove(volume_timer);
 volume_timer = ((void *)0);
    if( decay )
  free(decay);
 decay = ((void *)0);
}

canonical_original_code:
void geebee_sh_stop()
{
 if( volume_timer )
  timer_remove(volume_timer);
 volume_timer = ((void *)0);
    if( decay )
  free(decay);
 decay = ((void *)0);
}


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

stream_update((unsigned int)channel, 0LL);
sound_latch = a2;
volume = 0x7FFF;
noise = 0;
if ( (a2 & 8) != 0 )
{
if ( volume_timer )
timer_remove();
result = timer_pulse(4606LL, 0LL, volume_decay);
volume_timer = result;
}
else
{
if ( volume_timer )
timer_remove();
result = timer_pulse(9522LL, 0LL, volume_decay);
volume_timer = result;
}
return result;
}

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

stream_update((unsigned int)channel, 0LL);
sound_latch = a2;
volume = 0x7FFF;
noise = 0;
if ( (a2 & 8) != 0 )
{
if ( volume_timer )
timer_remove();
result = timer_pulse(4606LL, 0LL, volume_decay);
volume_timer = result;
}
else
{
if ( volume_timer )
timer_remove();
result = timer_pulse(9522LL, 0LL, volume_decay);
volume_timer = result;
}
return result;
}

original_code:
void geebee_sound_w(offs_t offset,data_t data)
{
 stream_update(channel,0);
 sound_latch = data;
 volume = 0x7fff;
 noise = 0x0000;
 if( sound_latch & 8 )
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.14058))), 0, volume_decay);
 }
 else
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.2906))), 0, volume_decay);
    }
}

canonical_original_code:
void geebee_sound_w(unsigned int offset, unsigned int data)
{
 stream_update(channel,0);
 sound_latch = data;
 volume = 0x7fff;
 noise = 0x0000;
 if( sound_latch & 8 )
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.14058))), 0, volume_decay);
 }
 else
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.2906))), 0, volume_decay);
    }
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

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

original_code: static data_t shared_auxram_r(offs_t offset){ return shared_auxram[offset]; }

canonical_original_code: static unsigned int shared_auxram_r(unsigned int offset){ return shared_auxram[offset]; }

variable_types:
offset
unsigned int


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

result = (unsigned int)snk_soundcommand;
snk_soundcommand = 0;
return result;
}

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

result = (unsigned int)snk_soundcommand;
snk_soundcommand = 0;
return result;
}

original_code:
static data_t snk_soundcommand_r(offs_t offset)
{
 int val = snk_soundcommand;
 snk_soundcommand = 0;
 return val;
}

canonical_original_code:
static unsigned int snk_soundcommand_r(unsigned int offset)
{
 int val = snk_soundcommand;
 snk_soundcommand = 0;
 return val;
}

variable_types: val int


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

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

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

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


decompiled_code:
__int64 aso_vh_start()
{
scrollx_base = -16;
return common_vh_start();
}

canonical_decompiled_code:
__int64 func9()
{
scrollx_base = -16;
return func8();
}

original_code:
int aso_vh_start( void ){
 scrollx_base = -16;
 return common_vh_start();
}

canonical_original_code:
int aso_vh_start(){
 scrollx_base = -16;
 return common_vh_start();
}


decompiled_code:
__int64 hal21_vh_start()
{
scrollx_base = 240;
return common_vh_start();
}

canonical_decompiled_code:
__int64 func10()
{
scrollx_base = 240;
return func8();
}

original_code:
int hal21_vh_start( void ){
 scrollx_base = 240;
 return common_vh_start();
}

canonical_original_code:
int hal21_vh_start(){
 scrollx_base = 240;
 return common_vh_start();
}


decompiled_code:
void aso_vh_stop()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

canonical_decompiled_code:
void func11()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

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

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


decompiled_code:
__int64 __fastcall aso_draw_background(__int64 a1, int a2, int a3, int a4, unsigned int a5, __int64 a6)
{
__int64 v8; // r15
_QWORD *v9; // rdx
int v10; // er12
__int64 i; // rbx
int v13; // [rsp+8h] [rbp-40h] BYREF
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v14[0] = a2;
v13 = a3;
v8 = Machine + 776LL;
if ( old_color_1 != a5 || old_bank_0 != a4 )
{
v9 = dirtybuffer;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v9[511] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v9 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v9 - (((_DWORD)v9 + 8) & 0xFFFFFFF8) + 4096) >> 3));
old_bank_0 = a4;
old_color_1 = a5;
}
v10 = a4 << 8;
for ( i = 0LL; i != 4096; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
drawgfx(
tmpbitmap,
a6,
v10 + (unsigned int)*(unsigned __int8 *)(videoram + i),
a5,
0LL,
0LL,
(unsigned int)(8 * ((int)i / 64)),
(unsigned int)(8 * ((int)i % 64)),
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + i) = 0;
}
}
return copyscrollbitmap(a1, tmpbitmap, 1LL, v14, 1LL, &v13, v8, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3, int a4, unsigned int a5, __int64 a6)
{
__int64 v8; // r15
_QWORD *v9; // rdx
int v10; // er12
__int64 i; // rbx
int v13; // [rsp+8h] [rbp-40h] BYREF
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v14[0] = a2;
v13 = a3;
v8 = Machine + 776LL;
if ( old_color_1 != a5 || old_bank_0 != a4 )
{
v9 = dirtybuffer;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v9[511] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v9 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v9 - (((_DWORD)v9 + 8) & 0xFFFFFFF8) + 4096) >> 3));
old_bank_0 = a4;
old_color_1 = a5;
}
v10 = a4 << 8;
for ( i = 0LL; i != 4096; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
drawgfx(
tmpbitmap,
a6,
v10 + (unsigned int)*(unsigned __int8 *)(videoram + i),
a5,
0LL,
0LL,
(unsigned int)(8 * ((int)i / 64)),
(unsigned int)(8 * ((int)i % 64)),
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + i) = 0;
}
}
return copyscrollbitmap(a1, tmpbitmap, 1LL, v14, 1LL, &v13, v8, 0LL, 0LL);
}

original_code:
static void aso_draw_background(
  struct osd_bitmap *bitmap,
  int scrollx, int scrolly,
  int bank, int color,
  const struct GfxElement *gfx )
{
 const struct rectangle *clip = &Machine->visible_area;
 int offs;
 static int old_bank, old_color;
 if( color!=old_color || bank!=old_bank ){
  memset( dirtybuffer, 1, 64*64 );
  old_bank = bank;
  old_color = color;
 }
 for( offs=0; offs<64*64; offs++ ){
  if( dirtybuffer[offs] ){
   int tile_number = videoram[offs]+bank*256;
   int sy = (offs%64)*8;
   int sx = (offs/64)*8;
   drawgfx( tmpbitmap,gfx,
    tile_number,
    color,
    0,0,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,
  1,&scrollx,1,&scrolly,
  clip,
  TRANSPARENCY_NONE,0);
}

canonical_original_code:
static void aso_draw_background(struct osd_bitmap *bitmap, int scrollx, int scrolly, int bank, int color, struct GfxElement *gfx)
{
 struct rectangle *clip = &Machine->visible_area;
 int offs;
 static int old_bank; static int old_color;
 if( color!=old_color || bank!=old_bank ){
  memset( dirtybuffer, 1, 64*64 );
  old_bank = bank;
  old_color = color;
 }
 for( offs=0; offs<64*64; offs++ ){
  if( dirtybuffer[offs] ){
   int tile_number = videoram[offs]+bank*256;
   int sy = (offs%64)*8;
   int sx = (offs/64)*8;
   drawgfx( tmpbitmap,gfx,
    tile_number,
    color,
    0,0,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,
  1,&scrollx,1,&scrolly,
  clip,
  TRANSPARENCY_NONE,0);
}

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

variable_types: scrollx int

variable_types: scrolly int

variable_types: bank int

variable_types: color int

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

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

variable_types: offs int

variable_types: sy int

variable_types: sx int


decompiled_code:
__int64 __fastcall snk_soundcommand_w(__int64 a1, int a2)
{
snk_soundcommand = a2;
return cpu_cause_interrupt(2LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
snk_soundcommand = a2;
return cpu_cause_interrupt(2LL, 4294966296LL);
}

original_code:
static void snk_soundcommand_w(offs_t offset,data_t data){
 snk_soundcommand = data;
 cpu_cause_interrupt( 2, -1000 );
}

canonical_original_code:
static void snk_soundcommand_w(unsigned int offset, unsigned int data){
 snk_soundcommand = data;
 cpu_cause_interrupt( 2, -1000 );
}

variable_types:
data
unsigned int


original_code:
void aso_draw_sprites(
  struct osd_bitmap *bitmap,
  int xscroll, int yscroll,
  const struct GfxElement *gfx
){
 const unsigned char *source = spriteram;
 const unsigned char *finish = source+60*4;
 struct rectangle clip = Machine->visible_area;
 while( source<finish ){
  int attributes = source[3];
  int tile_number = source[1];
  int sy = source[0] + ((attributes&0x10)?256:0) - yscroll;
  int sx = source[2] + ((attributes&0x80)?256:0) - xscroll;
  int color = attributes&0xf;
  if( !(attributes&0x20) ) tile_number += 512;
  if( attributes&0x40 ) tile_number += 256;
  drawgfx(bitmap,gfx,
   tile_number,
   color,
   0,0,
   (256-sx)&0x1ff,sy&0x1ff,
   &clip,TRANSPARENCY_PEN,7);
  source+=4;
 }
}

canonical_original_code:
void aso_draw_sprites(struct osd_bitmap *bitmap, int xscroll, int yscroll, struct GfxElement *gfx){
 unsigned char *source = spriteram;
 unsigned char *finish = source+60*4;
 struct rectangle clip = Machine->visible_area;
 while( source<finish ){
  int attributes = source[3];
  int tile_number = source[1];
  int sy = source[0] + ((attributes&0x10)?256:0) - yscroll;
  int sx = source[2] + ((attributes&0x80)?256:0) - xscroll;
  int color = attributes&0xf;
  if( !(attributes&0x20) ) tile_number += 512;
  if( attributes&0x40 ) tile_number += 256;
  drawgfx(bitmap,gfx,
   tile_number,
   color,
   0,0,
   (256-sx)&0x1ff,sy&0x1ff,
   &clip,TRANSPARENCY_PEN,7);
  source+=4;
 }
}

variable_types: xscroll int

variable_types: yscroll int

variable_types:
source
unsigned char *

variable_types:
finish
unsigned char *

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

variable_types: attributes int

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


decompiled_code:
__int64 __fastcall aso_vh_screenrefresh(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
unsigned int v3; // ebx

v1 = memory_region(129LL);
v2 = hal21_vreg[1];
aso_draw_background(
a1,
-((((v2 & 2) == 0) << 8) + hal21_vreg[5] + scrollx_base),
8 - (hal21_vreg[4] + ((16 * (_WORD)v2) & 0x100)),
LOBYTE(hal21_vreg[0]) >> 4,
hal21_vreg[0] & 0xF,
*(_QWORD *)(Machine + 520LL));
aso_draw_sprites(
a1,
LOWORD(hal21_vreg[3]) + (((_WORD)v2 << 8) & 0x100) + 30,
LOWORD(hal21_vreg[2]) + ((32 * v2) & 0x100) + 9,
*(_QWORD *)(Machine + 528LL));
v3 = (v2 >> 6) & 1;
tnk3_draw_text(a1, v3, v1 + 63488);
return tnk3_draw_status(a1, v3, v1 + 64512);
}

original_code:
void aso_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ){
 unsigned char *ram = memory_region(REGION_CPU1);
 int attributes = hal21_vreg[1];
 {
  unsigned char bg_attrs = hal21_vreg[0];
  int scrolly = -8+hal21_vreg[4]+((attributes&0x10)?256:0);
  int scrollx = scrollx_base + hal21_vreg[5]+((attributes&0x02)?0:256);
  aso_draw_background( bitmap, -scrollx, -scrolly,
   bg_attrs>>4,
   bg_attrs&0xf,
   Machine->gfx[1]
  );
 }
 {
  int scrollx = 0x1e + hal21_vreg[3] + ((attributes&0x01)?256:0);
  int scrolly = -8+0x11+hal21_vreg[2] + ((attributes&0x08)?256:0);
  aso_draw_sprites( bitmap, scrollx, scrolly, Machine->gfx[2] );
 }
 {
  int bank = (attributes&0x40)?1:0;
  tnk3_draw_text( bitmap, bank, &ram[0xf800] );
  tnk3_draw_status( bitmap, bank, &ram[0xfc00] );
 }
}

canonical_original_code:
void aso_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh){
 unsigned char *ram = memory_region(REGION_CPU1);
 int attributes = hal21_vreg[1];
 {
  unsigned char bg_attrs = hal21_vreg[0];
  int scrolly = -8+hal21_vreg[4]+((attributes&0x10)?256:0);
  int scrollx = scrollx_base + hal21_vreg[5]+((attributes&0x02)?0:256);
  aso_draw_background( bitmap, -scrollx, -scrolly,
   bg_attrs>>4,
   bg_attrs&0xf,
   Machine->gfx[1]
  );
 }
 {
  int scrollx = 0x1e + hal21_vreg[3] + ((attributes&0x01)?256:0);
  int scrolly = -8+0x11+hal21_vreg[2] + ((attributes&0x08)?256:0);
  aso_draw_sprites( bitmap, scrollx, scrolly, Machine->gfx[2] );
 }
 {
  int bank = (attributes&0x40)?1:0;
  tnk3_draw_text( bitmap, bank, &ram[0xf800] );
  tnk3_draw_status( bitmap, bank, &ram[0xfc00] );
 }
}

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

variable_types:
ram
unsigned char *


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

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

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

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

variable_types:
offset
unsigned int


decompiled_code:
__int64 common_vh_start()
{
_QWORD *v0; // rcx
__int64 result; // rax

dirtybuffer = malloc(0x1000uLL);
if ( !dirtybuffer )
return 1LL;
tmpbitmap = bitmap_alloc(512LL, 512LL);
if ( tmpbitmap )
{
v0 = dirtybuffer;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v0[511] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 4096) >> 3));
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
_QWORD *v0; // rcx
__int64 result; // rax

dirtybuffer = malloc(0x1000uLL);
if ( !dirtybuffer )
return 1LL;
tmpbitmap = bitmap_alloc(512LL, 512LL);
if ( tmpbitmap )
{
v0 = dirtybuffer;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v0[511] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 4096) >> 3));
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
static int common_vh_start( void ){
 dirtybuffer = (unsigned char*)malloc( 64*64 );
 if( dirtybuffer ){
  tmpbitmap = bitmap_alloc( 512, 512 );
  if( tmpbitmap ){
   memset( dirtybuffer, 1, 64*64 );
   return 0;
  }
  free( dirtybuffer );
 }
 return 1;
}

canonical_original_code:
static int common_vh_start(){
 dirtybuffer = (unsigned char *)malloc( 64*64 );
 if( dirtybuffer ){
  tmpbitmap = bitmap_alloc( 512, 512 );
  if( tmpbitmap ){
   memset( dirtybuffer, 1, 64*64 );
   return 0;
  }
  free( dirtybuffer );
 }
 return 1;
}


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

if ( (CPUB_latch & 2) != 0 )
{
result = cpu_cause_interrupt(1LL, 4294967294LL);
CPUB_latch = 0;
}
else
{
result = CPUB_latch | 1u;
CPUB_latch |= 1u;
}
return result;
}

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

if ( (CPUB_latch & 2) != 0 )
{
result = cpu_cause_interrupt(1LL, 4294967294LL);
CPUB_latch = 0;
}
else
{
result = CPUB_latch | 1u;
CPUB_latch |= 1u;
}
return result;
}

original_code:
static void CPUB_int_enable_w(offs_t offset,data_t data){
 if( CPUB_latch & 2 ){
  cpu_cause_interrupt( 1, -2 );
  CPUB_latch = 0;
 }
 else {
  CPUB_latch |= 1;
 }
}

canonical_original_code:
static void CPUB_int_enable_w(unsigned int offset, unsigned int data){
 if( CPUB_latch & 2 ){
  cpu_cause_interrupt( 1, -2 );
  CPUB_latch = 0;
 }
 else {
  CPUB_latch |= 1;
 }
}


decompiled_code:
__int64 CPUA_int_trigger_r()
{
if ( (CPUA_latch & 1) != 0 )
{
cpu_cause_interrupt(0LL, 4294967294LL);
CPUA_latch = 0;
}
else
{
CPUA_latch |= 2u;
}
return 255LL;
}

canonical_decompiled_code:
__int64 func14()
{
if ( (CPUA_latch & 1) != 0 )
{
cpu_cause_interrupt(0LL, 4294967294LL);
CPUA_latch = 0;
}
else
{
CPUA_latch |= 2u;
}
return 255LL;
}

original_code:
static data_t CPUA_int_trigger_r(offs_t offset){
 if( CPUA_latch&1 ){
  cpu_cause_interrupt( 0, -2 );
  CPUA_latch = 0;
 }
 else {
  CPUA_latch |= 2;
 }
 return 0xff;
}

canonical_original_code:
static unsigned int CPUA_int_trigger_r(unsigned int offset){
 if( CPUA_latch&1 ){
  cpu_cause_interrupt( 0, -2 );
  CPUA_latch = 0;
 }
 else {
  CPUA_latch |= 2;
 }
 return 0xff;
}


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

if ( (CPUA_latch & 2) != 0 )
{
result = cpu_cause_interrupt(0LL, 4294967294LL);
CPUA_latch = 0;
}
else
{
result = CPUA_latch | 1u;
CPUA_latch |= 1u;
}
return result;
}

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

if ( (CPUA_latch & 2) != 0 )
{
result = cpu_cause_interrupt(0LL, 4294967294LL);
CPUA_latch = 0;
}
else
{
result = CPUA_latch | 1u;
CPUA_latch |= 1u;
}
return result;
}

original_code:
static void CPUA_int_enable_w(offs_t offset,data_t data){
 if( CPUA_latch & 2 ){
  cpu_cause_interrupt( 0, -2 );
  CPUA_latch = 0;
 }
 else {
  CPUA_latch |= 1;
 }
}

canonical_original_code:
static void CPUA_int_enable_w(unsigned int offset, unsigned int data){
 if( CPUA_latch & 2 ){
  cpu_cause_interrupt( 0, -2 );
  CPUA_latch = 0;
 }
 else {
  CPUA_latch |= 1;
 }
}


decompiled_code:
__int64 CPUB_int_trigger_r()
{
if ( (CPUB_latch & 1) != 0 )
{
cpu_cause_interrupt(1LL, 4294967294LL);
CPUB_latch = 0;
}
else
{
CPUB_latch |= 2u;
}
return 255LL;
}

canonical_decompiled_code:
__int64 func17()
{
if ( (CPUB_latch & 1) != 0 )
{
cpu_cause_interrupt(1LL, 4294967294LL);
CPUB_latch = 0;
}
else
{
CPUB_latch |= 2u;
}
return 255LL;
}

original_code:
static data_t CPUB_int_trigger_r(offs_t offset){
 if( CPUB_latch&1 ){
  cpu_cause_interrupt( 1, -2 );
  CPUB_latch = 0;
 }
 else {
  CPUB_latch |= 2;
 }
 return 0xff;
}

canonical_original_code:
static unsigned int CPUB_int_trigger_r(unsigned int offset){
 if( CPUB_latch&1 ){
  cpu_cause_interrupt( 1, -2 );
  CPUB_latch = 0;
 }
 else {
  CPUB_latch |= 2;
 }
 return 0xff;
}


original_code:
void mario_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 >> 5) & 1;
  bit1 = (*color_prom >> 6) & 1;
  bit2 = (*color_prom >> 7) & 1;
  *(palette++) = 255 - (0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
  bit0 = (*color_prom >> 2) & 1;
  bit1 = (*color_prom >> 3) & 1;
  bit2 = (*color_prom >> 4) & 1;
  *(palette++) = 255 - (0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
  bit0 = (*color_prom >> 0) & 1;
  bit1 = (*color_prom >> 1) & 1;
  *(palette++) = 255 - (0x55 * bit0 + 0xaa * bit1);
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i]) = 8*i + 64;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+1]) = 8*i+1 + 64;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+2]) = 8*i+2 + 64;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+3]) = 8*i+3 + 64;
 }
 for (i = 0;i < 8;i++)
 {
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4]) = 8*i + 192;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4+1]) = 8*i+1 + 192;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4+2]) = 8*i+2 + 192;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4+3]) = 8*i+3 + 192;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = i;
}

canonical_original_code:
void mario_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 >> 5) & 1;
  bit1 = (*color_prom >> 6) & 1;
  bit2 = (*color_prom >> 7) & 1;
  *(palette++) = 255 - (0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
  bit0 = (*color_prom >> 2) & 1;
  bit1 = (*color_prom >> 3) & 1;
  bit2 = (*color_prom >> 4) & 1;
  *(palette++) = 255 - (0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
  bit0 = (*color_prom >> 0) & 1;
  bit1 = (*color_prom >> 1) & 1;
  *(palette++) = 255 - (0x55 * bit0 + 0xaa * bit1);
  color_prom++;
 }
 for (i = 0;i < 8;i++)
 {
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i]) = 8*i + 64;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+1]) = 8*i+1 + 64;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+2]) = 8*i+2 + 64;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+3]) = 8*i+3 + 64;
 }
 for (i = 0;i < 8;i++)
 {
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4]) = 8*i + 192;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4+1]) = 8*i+1 + 192;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4+2]) = 8*i+2 + 192;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + 4*i+8*4+3]) = 8*i+3 + 192;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = i;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall mario_sh_getcoin_w(__int64 a1, int a2)
{
t = a2;
}

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

original_code: void mario_sh_getcoin_w(offs_t offset,data_t data) { t[0] = data; }

canonical_original_code: void mario_sh_getcoin_w(unsigned int offset, unsigned int data) { t[0] = data; }


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

result = a2 | dword_C44 & 0xFFFFFFFE;
dword_C44 = a2 | dword_C44 & 0xFFFFFFFE;
return result;
}

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

result = a2 | dword_C44 & 0xFFFFFFFE;
dword_C44 = a2 | dword_C44 & 0xFFFFFFFE;
return result;
}

original_code: void mario_sh_crab_w(offs_t offset,data_t data) { p[1] = ((p[1] & (~(1 << 0))) | (data << 0)); }

canonical_original_code: void mario_sh_crab_w(unsigned int offset, unsigned int data) { p[1] = ((p[1] & (~(1 << 0))) | (data << 0)); }


decompiled_code:
__int64 __fastcall mario_sh_turtle_w(__int64 a1, int a2)
{
int v2; // esi
__int64 result; // rax

v2 = 2 * a2;
result = v2 | dword_C44 & 0xFFFFFFFD;
dword_C44 = v2 | dword_C44 & 0xFFFFFFFD;
return result;
}

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

v2 = 2 * a2;
result = v2 | dword_C44 & 0xFFFFFFFD;
dword_C44 = v2 | dword_C44 & 0xFFFFFFFD;
return result;
}

original_code: void mario_sh_turtle_w(offs_t offset,data_t data) { p[1] = ((p[1] & (~(1 << 1))) | (data << 1)); }

canonical_original_code: void mario_sh_turtle_w(unsigned int offset, unsigned int data) { p[1] = ((p[1] & (~(1 << 1))) | (data << 1)); }


decompiled_code:
__int64 __fastcall mario_sh_fly_w(__int64 a1, int a2)
{
int v2; // esi
__int64 result; // rax

v2 = 4 * a2;
result = v2 | dword_C44 & 0xFFFFFFFB;
dword_C44 = v2 | dword_C44 & 0xFFFFFFFB;
return result;
}

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

v2 = 4 * a2;
result = v2 | dword_C44 & 0xFFFFFFFB;
dword_C44 = v2 | dword_C44 & 0xFFFFFFFB;
return result;
}

original_code: void mario_sh_fly_w(offs_t offset,data_t data) { p[1] = ((p[1] & (~(1 << 2))) | (data << 2)); }

canonical_original_code: void mario_sh_fly_w(unsigned int offset, unsigned int data) { p[1] = ((p[1] & (~(1 << 2))) | (data << 2)); }


decompiled_code:
__int64 mario_sh_p1_r()
{
return (unsigned int)dword_C44;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)dword_C44;
}

original_code: static data_t mario_sh_p1_r(offs_t offset) { return p[1]; }

canonical_original_code: static unsigned int mario_sh_p1_r(unsigned int offset) { return p[1]; }


decompiled_code:
__int64 mario_sh_p2_r()
{
return (unsigned int)dword_C48;
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)dword_C48;
}

original_code: static data_t mario_sh_p2_r(offs_t offset) { return p[2]; }

canonical_original_code: static unsigned int mario_sh_p2_r(unsigned int offset) { return p[2]; }


decompiled_code:
__int64 mario_sh_t0_r()
{
return (unsigned int)t;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)t;
}

original_code: static data_t mario_sh_t0_r(offs_t offset) { return t[0]; }

canonical_original_code: static unsigned int mario_sh_t0_r(unsigned int offset) { return t[0]; }


decompiled_code:
__int64 mario_sh_t1_r()
{
return (unsigned int)dword_CAC;
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)dword_CAC;
}

original_code: static data_t mario_sh_t1_r(offs_t offset) { return t[1]; }

canonical_original_code: static unsigned int mario_sh_t1_r(unsigned int offset) { return t[1]; }


decompiled_code:
void __fastcall mario_sh_p1_w(__int64 a1, int a2)
{
dword_C44 = a2;
}

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

original_code:
static void mario_sh_p1_w(offs_t offset,data_t data)
{
 p[1] = data;
}

canonical_original_code:
static void mario_sh_p1_w(unsigned int offset, unsigned int data)
{
 p[1] = data;
}


decompiled_code:
void __fastcall mario_sh_p2_w(__int64 a1, int a2)
{
dword_C48 = a2;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2)
{
dword_C48 = a2;
}

original_code:
static void mario_sh_p2_w(offs_t offset,data_t data)
{
 p[2] = data;
}

canonical_original_code:
static void mario_sh_p2_w(unsigned int offset, unsigned int data)
{
 p[2] = data;
}


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

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

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

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

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

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


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

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

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

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

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

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


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

if ( a2 )
result = cpu_set_irq_line(1LL, 0LL, 1LL);
else
result = cpu_set_irq_line(1LL, 0LL, 0LL);
return result;
}

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

if ( a2 )
result = cpu_set_irq_line(1LL, 0LL, 1LL);
else
result = cpu_set_irq_line(1LL, 0LL, 0LL);
return result;
}

original_code:
void mario_sh_w(offs_t offset,data_t data)
{
 if (data)
  cpu_set_irq_line(1,0,1);
 else
  cpu_set_irq_line(1,0,0);
}

canonical_original_code:
void mario_sh_w(unsigned int offset, unsigned int data)
{
 if (data)
  cpu_set_irq_line(1,0,1);
 else
  cpu_set_irq_line(1,0,0);
}


decompiled_code:
void __fastcall mario_sh1_w(__int64 a1, int a2)
{
if ( last_3 != a2 )
{
last_3 = a2;
if ( a2 )
{
if ( !(unsigned int)sample_playing(0LL) )
sample_start(0LL, 3LL, 0LL);
}
}
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, int a2)
{
if ( last_3 != a2 )
{
last_3 = a2;
if ( a2 )
{
if ( !(unsigned int)sample_playing(0LL) )
sample_start(0LL, 3LL, 0LL);
}
}
}

original_code:
void mario_sh1_w(offs_t offset,data_t data)
{
 static int last;
 if (last!= data)
 {
  last = data;
                if (data && sample_playing(0) == 0) sample_start (0, 3, 0);
 }
}

canonical_original_code:
void mario_sh1_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last!= data)
 {
  last = data;
                if (data && sample_playing(0) == 0) sample_start (0, 3, 0);
 }
}

variable_types: last int


decompiled_code:
void __fastcall mario_sh2_w(__int64 a1, int a2)
{
if ( last_2 != a2 )
{
last_2 = a2;
if ( a2 )
{
if ( !(unsigned int)sample_playing(1LL) )
sample_start(1LL, 4LL, 0LL);
}
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, int a2)
{
if ( last_2 != a2 )
{
last_2 = a2;
if ( a2 )
{
if ( !(unsigned int)sample_playing(1LL) )
sample_start(1LL, 4LL, 0LL);
}
}
}

original_code:
void mario_sh2_w(offs_t offset,data_t data)
{
 static int last;
 if (last!= data)
 {
  last = data;
                if (data && sample_playing(1) == 0) sample_start (1, 4, 0);
 }
}

canonical_original_code:
void mario_sh2_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last!= data)
 {
  last = data;
                if (data && sample_playing(1) == 0) sample_start (1, 4, 0);
 }
}


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

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

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

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

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

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


decompiled_code:
__int64 mario_sh_sound_w()
{
return DAC_data_w(0LL);
}

canonical_decompiled_code:
__int64 func18()
{
return DAC_data_w(0LL);
}

original_code:
static void mario_sh_sound_w(offs_t offset,data_t data)
{
 DAC_data_w(0,data);
}

canonical_original_code:
static void mario_sh_sound_w(unsigned int offset, unsigned int data)
{
 DAC_data_w(0,data);
}


decompiled_code:
__int64 mario_sh_tune_r()
{
return soundlatch_r();
}

canonical_decompiled_code:
__int64 func19()
{
return soundlatch_r();
}

original_code: static data_t mario_sh_tune_r(offs_t offset) { return soundlatch_r(offset); }

canonical_original_code: static unsigned int mario_sh_tune_r(unsigned int offset) { return soundlatch_r(offset); }


decompiled_code:
__int64 mario_sh_tuneselect_w()
{
return soundlatch_w();
}

canonical_decompiled_code:
__int64 func20()
{
return soundlatch_w();
}

original_code: static void mario_sh_tuneselect_w(offs_t offset,data_t data) { soundlatch_w(offset,data); }

canonical_original_code: static void mario_sh_tuneselect_w(unsigned int offset, unsigned int data) { soundlatch_w(offset,data); }


original_code:
static void get_sprite_info2( void ){
 const struct GfxElement *gfx = Machine->gfx[1];
 const UINT8 *source = spriteram;
 struct sprite *sprite = sprite_list->sprite;
 int count = 128;
 int attributes, flags, number;
 while( count-- ){
  flags = 0;
  attributes = source[1];
  if ( attributes & 0x01 ){
   flags |= 0x08;
   sprite->priority = (attributes&0x08)?1:0;
   sprite->x = (240 - source[2])&0xff;
   sprite->y = (240 - source[0])&0xff;
   number = source[3] + ((attributes&0xc0)<<2);
   if( attributes & 0x04 ) flags |= 0x01;
   if( attributes & 0x02 ) flags |= 0x04;
   if( attributes & 0x10 ){
    number = number&(~1);
    sprite->y -= 16;
    sprite->total_height = 32;
   }
   else {
    sprite->total_height = 16;
   }
   sprite->pen_data = gfx->gfxdata + number * gfx->char_modulo;
  }
  sprite->flags = flags;
  sprite++;
  source += 4;
 }
}

canonical_original_code:
static void get_sprite_info2(){
 struct GfxElement *gfx = Machine->gfx[1];
 unsigned char *source = spriteram;
 struct sprite *sprite = sprite_list->sprite;
 int count = 128;
 int attributes; int flags; int number;
 while( count-- ){
  flags = 0;
  attributes = source[1];
  if ( attributes & 0x01 ){
   flags |= 0x08;
   sprite->priority = (attributes&0x08)?1:0;
   sprite->x = (240 - source[2])&0xff;
   sprite->y = (240 - source[0])&0xff;
   number = source[3] + ((attributes&0xc0)<<2);
   if( attributes & 0x04 ) flags |= 0x01;
   if( attributes & 0x02 ) flags |= 0x04;
   if( attributes & 0x10 ){
    number = number&(~1);
    sprite->y -= 16;
    sprite->total_height = 32;
   }
   else {
    sprite->total_height = 16;
   }
   sprite->pen_data = gfx->gfxdata + number * gfx->char_modulo;
  }
  sprite->flags = flags;
  sprite++;
  source += 4;
 }
}

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

variable_types: struct sprite { int priority; unsigned char *pen_data; int line_offset; unsigned short *pal_data; unsigned int pen_usage; int x_offset; int tile_width; int total_width; int x; int shadow_pen; struct sprite *next; long mask_offset; } *

variable_types: count int

variable_types: flags int

variable_types: number int


original_code:
int shootout_vh_start( void ){
 if( generic_vh_start()==0 ){
  sprite_list = sprite_list_create( 128, 0x0 );
  if( sprite_list ){
   int i;
   sprite_list->sprite_type = 0;
   for( i=0; i<128; i++ ){
    struct sprite *sprite = &sprite_list->sprite[i];
    sprite->pal_data = Machine->gfx[1]->colortable;
    sprite->tile_width = 16;
    sprite->tile_height = 16;
    sprite->total_width = 16;
    sprite->line_offset = 16;
   }
   sprite_list->max_priority = 1;
   return 0;
  }
  generic_vh_stop();
 }
 return 1;
}

canonical_original_code:
int shootout_vh_start(){
 if( generic_vh_start()==0 ){
  sprite_list = sprite_list_create( 128, 0x0 );
  if( sprite_list ){
   int i;
   sprite_list->sprite_type = 0;
   for( i=0; i<128; i++ ){
    struct sprite *sprite = &sprite_list->sprite[i];
    sprite->pal_data = Machine->gfx[1]->colortable;
    sprite->tile_width = 16;
    sprite->tile_height = 16;
    sprite->total_width = 16;
    sprite->line_offset = 16;
   }
   sprite_list->max_priority = 1;
   return 0;
  }
  generic_vh_stop();
 }
 return 1;
}

user_defined_types: struct sprite { int priority; unsigned char *pen_data; int line_offset; unsigned short *pal_data; unsigned int pen_usage; int x_offset; int tile_width; int total_width; int x; int shadow_pen; struct sprite *next; long mask_offset; }


decompiled_code:
__int64 __fastcall shootout_vh_screenrefresh(__int64 a1)
{
get_sprite_info();
sprite_update();
draw_background(a1);
sprite_draw(sprite_list, 1LL);
draw_foreground(a1);
return sprite_draw(sprite_list, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
func0();
sprite_update();
func4(a1);
sprite_draw(sprite_list, 1LL);
func3(a1);
return sprite_draw(sprite_list, 0LL);
}

original_code:
void shootout_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh){
 get_sprite_info();
 sprite_update();
 draw_background( bitmap );
 sprite_draw( sprite_list, 1);
 draw_foreground( bitmap );
 sprite_draw( sprite_list, 0);
}

canonical_original_code:
void shootout_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh){
 get_sprite_info();
 sprite_update();
 draw_background( bitmap );
 sprite_draw( sprite_list, 1);
 draw_foreground( bitmap );
 sprite_draw( sprite_list, 0);
}


decompiled_code:
__int64 __fastcall shootouj_vh_screenrefresh(__int64 a1)
{
get_sprite_info2();
sprite_update();
draw_background(a1);
sprite_draw(sprite_list, 1LL);
draw_foreground(a1);
return sprite_draw(sprite_list, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
func1();
sprite_update();
func4(a1);
sprite_draw(sprite_list, 1LL);
func3(a1);
return sprite_draw(sprite_list, 0LL);
}

original_code:
void shootouj_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh){
 get_sprite_info2();
 sprite_update();
 draw_background( bitmap );
 sprite_draw( sprite_list, 1);
 draw_foreground( bitmap );
 sprite_draw( sprite_list, 0);
}

canonical_original_code:
void shootouj_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh){
 get_sprite_info2();
 sprite_update();
 draw_background( bitmap );
 sprite_draw( sprite_list, 1);
 draw_foreground( bitmap );
 sprite_draw( sprite_list, 0);
}


original_code:
static void init_shootout(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int A;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0;A < diff;A++)
  rom[A+diff] = (rom[A] & 0x9f) | ((rom[A] & 0x40) >> 1) | ((rom[A] & 0x20) << 1);
}

canonical_original_code:
static void init_shootout()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int A;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0;A < diff;A++)
  rom[A+diff] = (rom[A] & 0x9f) | ((rom[A] & 0x40) >> 1) | ((rom[A] & 0x20) << 1);
}

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int


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

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

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

variable_types: linestate int


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

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

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


decompiled_code:
__int64 low_input_r()
{
return (unsigned int)~readinputport();
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)~readinputport();
}

original_code:
static data_t low_input_r(offs_t offset)
{
 return ~readinputport( offset );
}

canonical_original_code:
static unsigned int low_input_r(unsigned int offset)
{
 return ~readinputport( offset );
}


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

result = readinputport(2LL) & 0xC0;
if ( (_DWORD)result )
{
result = 0LL;
if ( !coin_0 )
{
coin_0 = 1;
result = nmi_interrupt();
}
}
else
{
coin_0 = 0;
}
return result;
}

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

result = readinputport(2LL) & 0xC0;
if ( (_DWORD)result )
{
result = 0LL;
if ( !coin_0 )
{
coin_0 = 1;
result = nmi_interrupt();
}
}
else
{
coin_0 = 0;
}
return result;
}

original_code:
static int shootout_interrupt(void)
{
 static int coin = 0;
 if ( readinputport( 2 ) & 0xc0 ) {
  if ( coin == 0 ) {
   coin = 1;
   return nmi_interrupt();
  }
 } else
  coin = 0;
 return 0;
}

canonical_original_code:
static int shootout_interrupt()
{
 static int coin = 0;
 if ( readinputport( 2 ) & 0xc0 ) {
  if ( coin == 0 ) {
   coin = 1;
   return nmi_interrupt();
  }
 } else
  coin = 0;
 return 0;
}

variable_types: coin int


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0xF) + 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 func13(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

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

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

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

variable_types:
data
unsigned int

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


original_code:
static void get_sprite_info( void ){
 const struct GfxElement *gfx = Machine->gfx[1];
 const UINT8 *source = spriteram;
 struct sprite *sprite = sprite_list->sprite;
 int count = 128;
 int attributes, flags, number;
 while( count-- ){
  flags = 0;
  attributes = source[1];
  if ( attributes & 0x01 ){
   flags |= 0x08;
   sprite->priority = (attributes&0x08)?1:0;
   sprite->x = (240 - source[2])&0xff;
   sprite->y = (240 - source[0])&0xff;
   number = source[3] + ((attributes&0xe0)<<3);
   if( attributes & 0x04 ) flags |= 0x01;
   if( attributes & 0x02 ) flags |= 0x04;
   if( attributes & 0x10 ){
    number = number&(~1);
    sprite->y -= 16;
    sprite->total_height = 32;
   }
   else {
    sprite->total_height = 16;
   }
   sprite->pen_data = gfx->gfxdata + number * gfx->char_modulo;
  }
  sprite->flags = flags;
  sprite++;
  source += 4;
 }
}

canonical_original_code:
static void get_sprite_info(){
 struct GfxElement *gfx = Machine->gfx[1];
 unsigned char *source = spriteram;
 struct sprite *sprite = sprite_list->sprite;
 int count = 128;
 int attributes; int flags; int number;
 while( count-- ){
  flags = 0;
  attributes = source[1];
  if ( attributes & 0x01 ){
   flags |= 0x08;
   sprite->priority = (attributes&0x08)?1:0;
   sprite->x = (240 - source[2])&0xff;
   sprite->y = (240 - source[0])&0xff;
   number = source[3] + ((attributes&0xe0)<<3);
   if( attributes & 0x04 ) flags |= 0x01;
   if( attributes & 0x02 ) flags |= 0x04;
   if( attributes & 0x10 ){
    number = number&(~1);
    sprite->y -= 16;
    sprite->total_height = 32;
   }
   else {
    sprite->total_height = 16;
   }
   sprite->pen_data = gfx->gfxdata + number * gfx->char_modulo;
  }
  sprite->flags = flags;
  sprite++;
  source += 4;
 }
}

variable_types:
source
unsigned char *

variable_types: attributes int


decompiled_code:
__int64 __fastcall draw_foreground(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // r14
__int64 v3; // r12
unsigned __int8 *v4; // rbp
__int64 v5; // rbx
unsigned __int8 v6; // dl
__int64 result; // rax
unsigned __int8 *v8; // [rsp+8h] [rbp-40h]

v1 = Machine + 776LL;
v2 = *(_QWORD *)(Machine + 512LL);
v8 = (unsigned __int8 *)shootout_textram;
v3 = 0LL;
do
{
v4 = v8;
v5 = 0LL;
do
{
v6 = v4[videoram_size];
result = drawgfx(a1, v2, *v4++ + ((unsigned __int8)(v6 & 3) << 8), (int)v6 >> 4, 0LL, 0LL, v5, v3, v1, 2LL, 0LL);
v5 = (unsigned int)(v5 + 8);
}
while ( (_DWORD)v5 != 256 );
v8 += 32;
v3 = (unsigned int)(v3 + 8);
}
while ( (_DWORD)v3 != 256 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // r14
__int64 v3; // r12
unsigned __int8 *v4; // rbp
__int64 v5; // rbx
unsigned __int8 v6; // dl
__int64 result; // rax
unsigned __int8 *v8; // [rsp+8h] [rbp-40h]

v1 = Machine + 776LL;
v2 = *(_QWORD *)(Machine + 512LL);
v8 = (unsigned __int8 *)shootout_textram;
v3 = 0LL;
do
{
v4 = v8;
v5 = 0LL;
do
{
v6 = v4[videoram_size];
result = drawgfx(a1, v2, *v4++ + ((unsigned __int8)(v6 & 3) << 8), (int)v6 >> 4, 0LL, 0LL, v5, v3, v1, 2LL, 0LL);
v5 = (unsigned int)(v5 + 8);
}
while ( (_DWORD)v5 != 256 );
v8 += 32;
v3 = (unsigned int)(v3 + 8);
}
while ( (_DWORD)v3 != 256 );
return result;
}

original_code:
static void draw_foreground( struct osd_bitmap *bitmap ){
 const struct rectangle *clip = &Machine->visible_area;
 const struct GfxElement *gfx = Machine->gfx[0];
 int sx,sy;
 unsigned char *source = shootout_textram;
 for( sy=0; sy<256; sy+=8 ){
  for( sx=0; sx<256; sx+=8 ){
   int attributes = *(source+videoram_size);
   int tile_number = 256*(attributes&0x3) + *source++;
   int color = attributes>>4;
   drawgfx(bitmap,gfx,
    tile_number,
    color,
    0,0,
    sx,sy,
    clip,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
static void draw_foreground(struct osd_bitmap *bitmap){
 struct rectangle *clip = &Machine->visible_area;
 struct GfxElement *gfx = Machine->gfx[0];
 int sx; int sy;
 unsigned char *source = shootout_textram;
 for( sy=0; sy<256; sy+=8 ){
  for( sx=0; sx<256; sx+=8 ){
   int attributes = *(source+videoram_size);
   int tile_number = 256*(attributes&0x3) + *source++;
   int color = attributes>>4;
   drawgfx(bitmap,gfx,
    tile_number,
    color,
    0,0,
    sx,sy,
    clip,TRANSPARENCY_PEN,0);
  }
 }
}

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

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

variable_types: sx int

variable_types: sy int

variable_types: color int


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
__int64 v1; // r12
unsigned __int64 v2; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // r12
unsigned __int64 v2; // rbx

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

original_code:
static void draw_background( struct osd_bitmap *bitmap ){
 const struct rectangle *clip = &Machine->visible_area;
 int offs;
 for( offs=0; offs<videoram_size; offs++ ){
  if( dirtybuffer[offs] ){
   int sx = (offs%32)*8;
   int sy = (offs/32)*8;
   int attributes = colorram[offs];
   int tile_number = videoram[offs] + 256*(attributes&7);
   int color = attributes>>4;
   drawgfx(tmpbitmap,Machine->gfx[2],
     tile_number&0x7ff,
     color,
     0,0,
     sx,sy,
     clip,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap){
 struct rectangle *clip = &Machine->visible_area;
 int offs;
 for( offs=0; offs<videoram_size; offs++ ){
  if( dirtybuffer[offs] ){
   int sx = (offs%32)*8;
   int sy = (offs/32)*8;
   int attributes = colorram[offs];
   int tile_number = videoram[offs] + 256*(attributes&7);
   int color = attributes>>4;
   drawgfx(tmpbitmap,Machine->gfx[2],
     tile_number&0x7ff,
     color,
     0,0,
     sx,sy,
     clip,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

variable_types: offs int

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