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

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

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

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

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

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

variable_types:
RAM
unsigned char *


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

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

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

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

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

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

variable_types: code int

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

return_type: void


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

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

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

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

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

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

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 convert_point(unsigned int a1, int a2, unsigned __int8 **a3, _DWORD *a4)
{
__int64 v4; // rax
unsigned __int8 *v5; // rax
unsigned __int8 v6; // al
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, unsigned __int8 **a3, _DWORD *a4)
{
__int64 v4; // rax
unsigned __int8 *v5; // rax
unsigned __int8 v6; // al
__int64 result; // rax

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

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

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
vptr
unsigned char **

variable_types:
vpixel
int *

variable_types:
voff
unsigned int


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
vptr
unsigned char *

variable_types: vpixel int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall cloud9_bitmap_regs_w(unsigned int a1, char a2)
{
unsigned __int64 result; // rax
unsigned int v4; // er10
unsigned int v5; // er9
char v6; // r11
char v7; // al
int v8; // [rsp+4h] [rbp-14h] BYREF
char *v9; // [rsp+8h] [rbp-10h] BYREF

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

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned int a1, char a2)
{
unsigned __int64 result; // rax
unsigned int v4; // er10
unsigned int v5; // er9
char v6; // r11
char v7; // al
int v8; // [rsp+4h] [rbp-14h] BYREF
char *v9; // [rsp+8h] [rbp-10h] BYREF

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

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

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

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall cloud9_bitmap_w(unsigned int a1, unsigned __int8 a2)
{
__int64 v2; // rax
int v3; // er15
unsigned int v4; // er12
unsigned __int8 v5; // di
unsigned int v6; // er12
int v7; // ebp
__int64 v8; // rsi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned __int8 a2)
{
__int64 v2; // rax
int v3; // er15
unsigned int v4; // er12
unsigned __int8 v5; // di
unsigned int v6; // er12
int v7; // ebp
__int64 v8; // rsi
__int64 result; // rax

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

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

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

variable_types:
x
unsigned char

variable_types:
y
unsigned char


decompiled_code:
void cloud9_led_w()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

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

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


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

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

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: blue int


decompiled_code:
__int64 __fastcall cloud9_vh_screenrefresh(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // [rsp-28h] [rbp-60h]

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // r8
__int64 v3; // r9
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // [rsp-28h] [rbp-60h]

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

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

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

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

variable_types: offs int

variable_types: spritenum int

variable_types: xflip int

variable_types: yflip int

variable_types: rblank int

variable_types: lblank int

variable_types: x int

variable_types: y int


decompiled_code:
_BYTE *redraw_bitmap()
{
char v0; // dl
char v1; // r15
unsigned __int64 v2; // r14
unsigned int v3; // edi
unsigned __int8 v4; // si
_BYTE *result; // rax
char v6; // [rsp+Fh] [rbp-39h]

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

canonical_decompiled_code:
_BYTE *func4()
{
char v0; // dl
char v1; // r15
unsigned __int64 v2; // r14
unsigned int v3; // edi
unsigned __int8 v4; // si
_BYTE *result; // rax
char v6; // [rsp+Fh] [rbp-39h]

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

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

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


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

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

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

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

variable_types:
file
void *


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

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

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

variable_types:
offset
unsigned int


decompiled_code:
void *__fastcall kyugo_flipscreen_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

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

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

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

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

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

variable_types:
data
unsigned int


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

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

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

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

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

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

variable_types:
baf
char [40]


decompiled_code:
int *__fastcall kyugo_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // r15
int v4; // esi
int v5; // edi
unsigned __int8 v6; // dl
__int64 v7; // r8
__int64 v8; // r9
int *result; // rax
int v10; // ebx
__int64 v11; // r15
int v12; // eax
int v13; // edx
int v14; // er10
int v15; // [rsp+8h] [rbp-40h] BYREF
int v16[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
*(_BYTE *)(v3 + dirtybuffer) = 0;
v4 = v2 & 0x3F;
v5 = v2 >> 6;
v6 = *(_BYTE *)(colorram + v3);
v7 = v6 & 4;
v8 = v6 & 8;
if ( flipscreen )
{
v4 = 63 - v4;
v5 = 31 - v5;
v7 = (_DWORD)v7 == 0;
v8 = (_DWORD)v8 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(v6 & 3) << 8),
16 * palbank + (unsigned int)(v6 >> 4),
v7,
v8,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v15 = -32 - ((unsigned __int8)*kyugo_back_scrollY_lo + ((unsigned __int8)kyugo_back_scrollY_hi << 8));
if ( flipscreen )
v16[0] = (unsigned __int8)*kyugo_back_scrollX;
else
v16[0] = -(unsigned __int8)*kyugo_back_scrollX;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v15, 1LL, v16, Machine + 776LL, 0LL, 0LL);
draw_sprites(a1);
result = &kyugo_videoram_size;
v10 = kyugo_videoram_size - 1;
if ( kyugo_videoram_size - 1 >= 0 )
{
v11 = v10;
do
{
v12 = v10 & 0x3F;
v13 = v10 >> 6;
if ( flipscreen )
{
v12 = 35 - v12;
v13 = 31 - v13;
}
--v10;
v14 = *(unsigned __int8 *)(kyugo_videoram + v11--);
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)v14,
frontcolor + 2 * (unsigned int)*(unsigned __int8 *)(color_codes + (v14 >> 3)),
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v12),
(unsigned int)(8 * v13),
Machine + 776LL,
2LL,
0LL);
}
while ( v10 != -1 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func7(__int64 a1)
{
int v2; // ebx
__int64 v3; // r15
int v4; // esi
int v5; // edi
unsigned __int8 v6; // dl
__int64 v7; // r8
__int64 v8; // r9
int *result; // rax
int v10; // ebx
__int64 v11; // r15
int v12; // eax
int v13; // edx
int v14; // er10
int v15; // [rsp+8h] [rbp-40h] BYREF
int v16[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(v3 + dirtybuffer) )
{
*(_BYTE *)(v3 + dirtybuffer) = 0;
v4 = v2 & 0x3F;
v5 = v2 >> 6;
v6 = *(_BYTE *)(colorram + v3);
v7 = v6 & 4;
v8 = v6 & 8;
if ( flipscreen )
{
v4 = 63 - v4;
v5 = 31 - v5;
v7 = (_DWORD)v7 == 0;
v8 = (_DWORD)v8 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(v6 & 3) << 8),
16 * palbank + (unsigned int)(v6 >> 4),
v7,
v8,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v15 = -32 - ((unsigned __int8)*kyugo_back_scrollY_lo + ((unsigned __int8)kyugo_back_scrollY_hi << 8));
if ( flipscreen )
v16[0] = (unsigned __int8)*kyugo_back_scrollX;
else
v16[0] = -(unsigned __int8)*kyugo_back_scrollX;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v15, 1LL, v16, Machine + 776LL, 0LL, 0LL);
func6(a1);
result = &kyugo_videoram_size;
v10 = kyugo_videoram_size - 1;
if ( kyugo_videoram_size - 1 >= 0 )
{
v11 = v10;
do
{
v12 = v10 & 0x3F;
v13 = v10 >> 6;
if ( flipscreen )
{
v12 = 35 - v12;
v13 = 31 - v13;
}
--v10;
v14 = *(unsigned __int8 *)(kyugo_videoram + v11--);
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)v14,
frontcolor + 2 * (unsigned int)*(unsigned __int8 *)(color_codes + (v14 >> 3)),
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v12),
(unsigned int)(8 * v13),
Machine + 776LL,
2LL,
0LL);
}
while ( v10 != -1 );
}
return result;
}

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

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

variable_types: sx int

variable_types: sy int

variable_types: tile int

variable_types: flipx int

variable_types: flipy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: code int

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


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

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

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

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

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

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


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

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

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

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


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

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

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

variable_types: n int

variable_types: offs int

variable_types: color int


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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall dcon_control_w(__int64 a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rdi

dcon_enable = a2;
if ( (a2 & 4) != 0 )
{
tilemap_set_enable(foreground_layer, 0LL);
v2 = midground_layer;
if ( (dcon_enable & 2) != 0 )
goto LABEL_3;
LABEL_6:
tilemap_set_enable(v2, 1LL);
v3 = background_layer;
if ( (dcon_enable & 1) != 0 )
return tilemap_set_enable(v3, 0LL);
return tilemap_set_enable(v3, 1LL);
}
tilemap_set_enable(foreground_layer, 1LL);
v2 = midground_layer;
if ( (dcon_enable & 2) == 0 )
goto LABEL_6;
LABEL_3:
tilemap_set_enable(v2, 0LL);
v3 = background_layer;
if ( (dcon_enable & 1) != 0 )
return tilemap_set_enable(v3, 0LL);
return tilemap_set_enable(v3, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rdi

dcon_enable = a2;
if ( (a2 & 4) != 0 )
{
tilemap_set_enable(foreground_layer, 0LL);
v2 = midground_layer;
if ( (dcon_enable & 2) != 0 )
goto LABEL_3;
LABEL_6:
tilemap_set_enable(v2, 1LL);
v3 = background_layer;
if ( (dcon_enable & 1) != 0 )
return tilemap_set_enable(v3, 0LL);
return tilemap_set_enable(v3, 1LL);
}
tilemap_set_enable(foreground_layer, 1LL);
v2 = midground_layer;
if ( (dcon_enable & 2) == 0 )
goto LABEL_6;
LABEL_3:
tilemap_set_enable(v2, 0LL);
v3 = background_layer;
if ( (dcon_enable & 1) != 0 )
return tilemap_set_enable(v3, 0LL);
return tilemap_set_enable(v3, 1LL);
}

original_code:
void dcon_control_w(offs_t offset,data_t data)
{
 dcon_enable=data;
 if ((dcon_enable&4)==4)
  tilemap_set_enable(foreground_layer,0);
 else
  tilemap_set_enable(foreground_layer,1);
 if ((dcon_enable&2)==2)
  tilemap_set_enable(midground_layer,0);
 else
  tilemap_set_enable(midground_layer,1);
 if ((dcon_enable&1)==1)
  tilemap_set_enable(background_layer,0);
 else
  tilemap_set_enable(background_layer,1);
}

canonical_original_code:
void dcon_control_w(unsigned int offset, unsigned int data)
{
 dcon_enable=data;
 if ((dcon_enable&4)==4)
  tilemap_set_enable(foreground_layer,0);
 else
  tilemap_set_enable(foreground_layer,1);
 if ((dcon_enable&2)==2)
  tilemap_set_enable(midground_layer,0);
 else
  tilemap_set_enable(midground_layer,1);
 if ((dcon_enable&1)==1)
  tilemap_set_enable(background_layer,0);
 else
  tilemap_set_enable(background_layer,1);
}


decompiled_code:
__int64 __fastcall dcon_background_w(unsigned int a1, int a2)
{
*(_WORD *)(dcon_back_data + a1) = a2 | *(_WORD *)(dcon_back_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(background_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
*(_WORD *)(dcon_back_data + a1) = a2 | *(_WORD *)(dcon_back_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(background_layer, a1 >> 1);
}

original_code:
void dcon_background_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&dcon_back_data[offset])) = (((*(UINT16 *)(&dcon_back_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( background_layer,offset/2);
}

canonical_original_code:
void dcon_background_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&dcon_back_data[offset])) = (((*(unsigned short *)(&dcon_back_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( background_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dcon_foreground_w(unsigned int a1, int a2)
{
*(_WORD *)(dcon_fore_data + a1) = a2 | *(_WORD *)(dcon_fore_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(foreground_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2)
{
*(_WORD *)(dcon_fore_data + a1) = a2 | *(_WORD *)(dcon_fore_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(foreground_layer, a1 >> 1);
}

original_code:
void dcon_foreground_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&dcon_fore_data[offset])) = (((*(UINT16 *)(&dcon_fore_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( foreground_layer,offset/2);
}

canonical_original_code:
void dcon_foreground_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&dcon_fore_data[offset])) = (((*(unsigned short *)(&dcon_fore_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( foreground_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dcon_midground_w(unsigned int a1, int a2)
{
*(_WORD *)(dcon_mid_data + a1) = a2 | *(_WORD *)(dcon_mid_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(midground_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, int a2)
{
*(_WORD *)(dcon_mid_data + a1) = a2 | *(_WORD *)(dcon_mid_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(midground_layer, a1 >> 1);
}

original_code:
void dcon_midground_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&dcon_mid_data[offset])) = (((*(UINT16 *)(&dcon_mid_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( midground_layer,offset/2);
}

canonical_original_code:
void dcon_midground_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&dcon_mid_data[offset])) = (((*(unsigned short *)(&dcon_mid_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( midground_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dcon_text_w(unsigned int a1, int a2)
{
*(_WORD *)(videoram + a1) = a2 | *(_WORD *)(videoram + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(text_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, int a2)
{
*(_WORD *)(videoram + a1) = a2 | *(_WORD *)(videoram + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(text_layer, a1 >> 1);
}

original_code:
void dcon_text_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&videoram[offset])) = (((*(UINT16 *)(&videoram[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( text_layer,offset/2);
}

canonical_original_code:
void dcon_text_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&videoram[offset])) = (((*(unsigned short *)(&videoram[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( text_layer,offset/2);
}


decompiled_code:
__int64 dcon_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rdx
__int64 v6; // [rsp+0h] [rbp-18h]
__int64 v7; // [rsp+0h] [rbp-18h]
__int64 v8; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_back_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v6) = 32;
background_layer = v0;
v1 = tilemap_create(get_fore_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v6);
LODWORD(v7) = 32;
foreground_layer = v1;
v2 = tilemap_create(get_mid_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v7);
LODWORD(v8) = 32;
midground_layer = v2;
v3 = tilemap_create(get_text_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v8);
text_layer = v3;
if ( !background_layer )
return 1LL;
v4 = foreground_layer;
if ( !foreground_layer || !v3 || !midground_layer )
return 1LL;
*(_DWORD *)(midground_layer + 132) = 15;
*(_DWORD *)(v4 + 132) = 15;
*(_DWORD *)(v3 + 132) = 15;
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rdx
__int64 v6; // [rsp+0h] [rbp-18h]
__int64 v7; // [rsp+0h] [rbp-18h]
__int64 v8; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_back_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v6) = 32;
background_layer = v0;
v1 = tilemap_create(get_fore_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v6);
LODWORD(v7) = 32;
foreground_layer = v1;
v2 = tilemap_create(get_mid_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v7);
LODWORD(v8) = 32;
midground_layer = v2;
v3 = tilemap_create(get_text_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v8);
text_layer = v3;
if ( !background_layer )
return 1LL;
v4 = foreground_layer;
if ( !foreground_layer || !v3 || !midground_layer )
return 1LL;
*(_DWORD *)(midground_layer + 132) = 15;
*(_DWORD *)(v4 + 132) = 15;
*(_DWORD *)(v3 + 132) = 15;
return 0LL;
}

original_code:
int dcon_vh_start(void)
{
 background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 midground_layer = tilemap_create(get_mid_tile_info, tilemap_scan_rows,0x01,16,16,32,32);
 text_layer = tilemap_create(get_text_tile_info,tilemap_scan_rows,0x01, 8,8,64,32);
 if (!background_layer || !foreground_layer || !midground_layer || !text_layer)
  return 1;
 midground_layer->transparent_pen = 15;
 foreground_layer->transparent_pen = 15;
 text_layer->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int dcon_vh_start()
{
 background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 midground_layer = tilemap_create(get_mid_tile_info, tilemap_scan_rows,0x01,16,16,32,32);
 text_layer = tilemap_create(get_text_tile_info,tilemap_scan_rows,0x01, 8,8,64,32);
 if (!background_layer || !foreground_layer || !midground_layer || !text_layer)
  return 1;
 midground_layer->transparent_pen = 15;
 foreground_layer->transparent_pen = 15;
 text_layer->transparent_pen = 15;
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall dcon_vh_screenrefresh(__int64 a1)
{
tilemap_set_scrollx(background_layer, 0LL, (unsigned __int16)*dcon_scroll_ram);
tilemap_set_scrolly(background_layer, 0LL, (unsigned __int16)dcon_scroll_ram[1]);
tilemap_set_scrollx(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[2]);
tilemap_set_scrolly(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[3]);
tilemap_set_scrollx(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[4]);
tilemap_set_scrolly(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[5]);
tilemap_update(0LL);
palette_init_used_colors();
mark_sprite_colours();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( (dcon_enable & 1) != 0 )
fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
else
tilemap_draw(a1, background_layer, 0LL);
draw_sprites(a1, 2);
tilemap_draw(a1, midground_layer, 0LL);
draw_sprites(a1, 1);
tilemap_draw(a1, foreground_layer, 0LL);
draw_sprites(a1, 0);
draw_sprites(a1, 3);
return tilemap_draw(a1, text_layer, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
tilemap_set_scrollx(background_layer, 0LL, (unsigned __int16)*dcon_scroll_ram);
tilemap_set_scrolly(background_layer, 0LL, (unsigned __int16)dcon_scroll_ram[1]);
tilemap_set_scrollx(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[2]);
tilemap_set_scrolly(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[3]);
tilemap_set_scrollx(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[4]);
tilemap_set_scrolly(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[5]);
tilemap_update(0LL);
palette_init_used_colors();
func4();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( (dcon_enable & 1) != 0 )
fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
else
tilemap_draw(a1, background_layer, 0LL);
func14(a1, 2);
tilemap_draw(a1, midground_layer, 0LL);
func14(a1, 1);
tilemap_draw(a1, foreground_layer, 0LL);
func14(a1, 0);
func14(a1, 3);
return tilemap_draw(a1, text_layer, 0LL);
}

original_code:
void dcon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_set_scrollx( background_layer,0, (*(UINT16 *)(&dcon_scroll_ram[0])) );
 tilemap_set_scrolly( background_layer,0, (*(UINT16 *)(&dcon_scroll_ram[2])) );
 tilemap_set_scrollx( midground_layer, 0, (*(UINT16 *)(&dcon_scroll_ram[4])) );
 tilemap_set_scrolly( midground_layer, 0, (*(UINT16 *)(&dcon_scroll_ram[6])) );
 tilemap_set_scrollx( foreground_layer,0, (*(UINT16 *)(&dcon_scroll_ram[8])) );
 tilemap_set_scrolly( foreground_layer,0, (*(UINT16 *)(&dcon_scroll_ram[0xa])) );
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colours();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if ((dcon_enable&1)!=1)
  tilemap_draw(bitmap,background_layer,0);
 else
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
 draw_sprites(bitmap,2);
 tilemap_draw(bitmap,midground_layer,0);
 draw_sprites(bitmap,1);
 tilemap_draw(bitmap,foreground_layer,0);
 draw_sprites(bitmap,0);
 draw_sprites(bitmap,3);
 tilemap_draw(bitmap,text_layer,0);
}

canonical_original_code:
void dcon_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_set_scrollx( background_layer,0, (*(unsigned short *)(&dcon_scroll_ram[0])) );
 tilemap_set_scrolly( background_layer,0, (*(unsigned short *)(&dcon_scroll_ram[2])) );
 tilemap_set_scrollx( midground_layer, 0, (*(unsigned short *)(&dcon_scroll_ram[4])) );
 tilemap_set_scrolly( midground_layer, 0, (*(unsigned short *)(&dcon_scroll_ram[6])) );
 tilemap_set_scrollx( foreground_layer,0, (*(unsigned short *)(&dcon_scroll_ram[8])) );
 tilemap_set_scrolly( foreground_layer,0, (*(unsigned short *)(&dcon_scroll_ram[0xa])) );
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colours();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if ((dcon_enable&1)!=1)
  tilemap_draw(bitmap,background_layer,0);
 else
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
 draw_sprites(bitmap,2);
 tilemap_draw(bitmap,midground_layer,0);
 draw_sprites(bitmap,1);
 tilemap_draw(bitmap,foreground_layer,0);
 draw_sprites(bitmap,0);
 draw_sprites(bitmap,3);
 tilemap_draw(bitmap,text_layer,0);
}


decompiled_code:
__int64 init_dcon()
{
return install_seibu_sound_speedup(1LL);
}

canonical_decompiled_code:
__int64 func16()
{
return install_seibu_sound_speedup(1LL);
}

original_code:
static void init_dcon(void)
{
 install_seibu_sound_speedup(1);
}

canonical_original_code:
static void init_dcon()
{
 install_seibu_sound_speedup(1);
}


decompiled_code:
__int64 __fastcall dcon_sound_w(__int64 a1, unsigned __int8 a2)
{
return seibu_soundlatch_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
return seibu_soundlatch_w(a1, a2);
}

original_code:
static void dcon_sound_w(offs_t offset,data_t data)
{
 seibu_soundlatch_w(offset,data&0xff);
}

canonical_original_code:
static void dcon_sound_w(unsigned int offset, unsigned int data)
{
 seibu_soundlatch_w(offset,data&0xff);
}


decompiled_code:
__int64 __fastcall dcon_control_r(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebx

if ( a1 == 2 )
{
v3 = readinputport(0LL);
result = v3 + ((unsigned int)readinputport(1LL) << 8);
}
else if ( a1 == 4 )
{
result = readinputport(2LL);
}
else
{
result = 0xFFFFLL;
if ( !a1 )
{
v2 = readinputport(4LL);
result = v2 + ((unsigned int)readinputport(3LL) << 8);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebx

if ( a1 == 2 )
{
v3 = readinputport(0LL);
result = v3 + ((unsigned int)readinputport(1LL) << 8);
}
else if ( a1 == 4 )
{
result = readinputport(2LL);
}
else
{
result = 0xFFFFLL;
if ( !a1 )
{
v2 = readinputport(4LL);
result = v2 + ((unsigned int)readinputport(3LL) << 8);
}
}
return result;
}

original_code:
static data_t dcon_control_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return (readinputport(4) + (readinputport(3) << 8));
  case 2:
   return (readinputport(0) + (readinputport(1) << 8));
  case 4:
   return readinputport(2);
 }
 return 0xffff;
}

canonical_original_code:
static unsigned int dcon_control_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return (readinputport(4) + (readinputport(3) << 8));
  case 2:
   return (readinputport(0) + (readinputport(1) << 8));
  case 4:
   return readinputport(2);
 }
 return 0xffff;
}


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
__int64 mark_sprite_colours()
{
char *v0; // r9
int v1; // er8
__int64 v2; // rdi
unsigned __int16 *v3; // r11
__int64 v4; // rbx
int v5; // eax
__int64 v6; // r10
int v7; // edx
int v8; // ecx
__int16 v9; // si
int v10; // ecx
__int64 result; // rax
int v12[64]; // [rsp+0h] [rbp-108h] BYREF
char v13; // [rsp+100h] [rbp-8h] BYREF

v0 = (char *)v12;
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 112LL);
memset(v12, 0, sizeof(v12));
v2 = *(_QWORD *)(*(_QWORD *)(Machine + 544LL) + 32LL);
v3 = (unsigned __int16 *)(spriteram + 8LL);
v4 = spriteram + 2048LL;
do
{
v5 = v3[1] & 0x3FFF;
v6 = *v3 & 0x3F;
v7 = v12[v6];
v8 = v5 + ((((int)*v3 >> 10) & 7) + 1) * ((((int)*v3 >> 7) & 7) + 1);
do
{
v9 = v5++;
v7 |= *(_DWORD *)(v2 + 4LL * (v9 & 0x3FFF));
}
while ( v8 != v5 );
v3 += 4;
v12[v6] = v7;
}
while ( (unsigned __int16 *)v4 != v3 );
do
{
v10 = *(_DWORD *)v0;
LODWORD(result) = 0;
do
{
if ( _bittest(&v10, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v0 += 4;
v1 += 16;
}
while ( v0 != &v13 );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // r9
int v1; // er8
__int64 v2; // rdi
unsigned __int16 *v3; // r11
__int64 v4; // rbx
int v5; // eax
__int64 v6; // r10
int v7; // edx
int v8; // ecx
__int16 v9; // si
int v10; // ecx
__int64 result; // rax
int v12[64]; // [rsp+0h] [rbp-108h] BYREF
char v13; // [rsp+100h] [rbp-8h] BYREF

v0 = (char *)v12;
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 112LL);
memset(v12, 0, sizeof(v12));
v2 = *(_QWORD *)(*(_QWORD *)(Machine + 544LL) + 32LL);
v3 = (unsigned __int16 *)(spriteram + 8LL);
v4 = spriteram + 2048LL;
do
{
v5 = v3[1] & 0x3FFF;
v6 = *v3 & 0x3F;
v7 = v12[v6];
v8 = v5 + ((((int)*v3 >> 10) & 7) + 1) * ((((int)*v3 >> 7) & 7) + 1);
do
{
v9 = v5++;
v7 |= *(_DWORD *)(v2 + 4LL * (v9 & 0x3FFF));
}
while ( v8 != v5 );
v3 += 4;
v12[v6] = v7;
}
while ( (unsigned __int16 *)v4 != v3 );
do
{
v10 = *(_DWORD *)v0;
LODWORD(result) = 0;
do
{
if ( _bittest(&v10, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v0 += 4;
v1 += 16;
}
while ( v0 != &v13 );
return result;
}

original_code:
static void mark_sprite_colours(void)
{
 int colmask[64],i,pal_base,color,offs,sprite,multi;
 pal_base = Machine->drv->gfxdecodeinfo[4].color_codes_start;
 for (color = 0;color < 64;color++) colmask[color] = 0;
 for (offs = 8;offs <0x800;offs += 8)
 {
  color = (*(UINT16 *)(&spriteram[offs+0]))&0x3f;
  sprite = (*(UINT16 *)(&spriteram[offs+2]));
  sprite &= 0x3fff;
  multi=((((*(UINT16 *)(&spriteram[offs+0]))&0x0380)>>7)+1)*((((*(UINT16 *)(&spriteram[offs+0]))&0x1c00)>>10)+1);
  for (i=0; i<multi; i++)
   colmask[color] |= Machine->gfx[4]->pen_usage[(sprite+i)&0x3fff];
 }
 for (color = 0;color < 64;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

canonical_original_code:
static void mark_sprite_colours()
{
 int colmask[64]; int i; int pal_base; int color; int offs; int sprite; int multi;
 pal_base = Machine->drv->gfxdecodeinfo[4].color_codes_start;
 for (color = 0;color < 64;color++) colmask[color] = 0;
 for (offs = 8;offs <0x800;offs += 8)
 {
  color = (*(unsigned short *)(&spriteram[offs+0]))&0x3f;
  sprite = (*(unsigned short *)(&spriteram[offs+2]));
  sprite &= 0x3fff;
  multi=((((*(unsigned short *)(&spriteram[offs+0]))&0x0380)>>7)+1)*((((*(unsigned short *)(&spriteram[offs+0]))&0x1c00)>>10)+1);
  for (i=0; i<multi; i++)
   colmask[color] |= Machine->gfx[4]->pen_usage[(sprite+i)&0x3fff];
 }
 for (color = 0;color < 64;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

variable_types:
colmask
int [64]

variable_types: i int

variable_types: sprite int

variable_types: multi int


original_code:
static void draw_sprites(struct osd_bitmap *bitmap,int pri)
{
 int offs,fx,fy,x,y,color,sprite;
 int dx,dy,ax,ay;
 for (offs = 0x800-8;offs >= 0;offs -= 8)
 {
  if (((*(UINT16 *)(&spriteram[offs+0]))&0x8000)!=0x8000) continue;
  sprite = (*(UINT16 *)(&spriteram[offs+2]));
  if ((sprite>>14)!=pri) continue;
  sprite &= 0x3fff;
  y = (*(UINT16 *)(&spriteram[offs+6]));
  x = (*(UINT16 *)(&spriteram[offs+4]));
  if (x&0x8000) x=0-(0x200-(x&0x1ff));
  else x&=0x1ff;
  if (y&0x8000) y=0-(0x200-(y&0x1ff));
  else y&=0x1ff;
  color = (*(UINT16 *)(&spriteram[offs+0]))&0x3f;
  fx = 0;
  fy = 0;
  dy=(((*(UINT16 *)(&spriteram[offs+0]))&0x0380)>>7)+1;
  dx=(((*(UINT16 *)(&spriteram[offs+0]))&0x1c00)>>10)+1;
  for (ax=0; ax<dx; ax++)
   for (ay=0; ay<dy; ay++) {
    drawgfx(bitmap,Machine->gfx[4],
    sprite++,
    color,fx,fy,x+ax*16,y+ay*16,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
   }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap, int pri)
{
 int offs; int fx; int fy; int x; int y; int color; int sprite;
 int dx; int dy; int ax; int ay;
 for (offs = 0x800-8;offs >= 0;offs -= 8)
 {
  if (((*(unsigned short *)(&spriteram[offs+0]))&0x8000)!=0x8000) continue;
  sprite = (*(unsigned short *)(&spriteram[offs+2]));
  if ((sprite>>14)!=pri) continue;
  sprite &= 0x3fff;
  y = (*(unsigned short *)(&spriteram[offs+6]));
  x = (*(unsigned short *)(&spriteram[offs+4]));
  if (x&0x8000) x=0-(0x200-(x&0x1ff));
  else x&=0x1ff;
  if (y&0x8000) y=0-(0x200-(y&0x1ff));
  else y&=0x1ff;
  color = (*(unsigned short *)(&spriteram[offs+0]))&0x3f;
  fx = 0;
  fy = 0;
  dy=(((*(unsigned short *)(&spriteram[offs+0]))&0x0380)>>7)+1;
  dx=(((*(unsigned short *)(&spriteram[offs+0]))&0x1c00)>>10)+1;
  for (ax=0; ax<dx; ax++)
   for (ay=0; ay<dy; ay++) {
    drawgfx(bitmap,Machine->gfx[4],
    sprite++,
    color,fx,fy,x+ax*16,y+ay*16,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
   }
 }
}

variable_types: pri int

variable_types: fx int

variable_types: fy int

variable_types: x int

variable_types: y int

variable_types: dx int

variable_types: dy int

variable_types: ax int

variable_types: ay int


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

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

original_code: static data_t bogeyman_videoram_r(offs_t offset) { return bogeyman_videoram[offset]; }

canonical_original_code: static unsigned int bogeyman_videoram_r(unsigned int offset) { return bogeyman_videoram[offset]; }

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall bogeyman_8910_latch_w(__int64 a1, int a2)
{
psg_latch = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
psg_latch = a2;
}

original_code:
static void bogeyman_8910_latch_w(offs_t offset,data_t data)
{
 psg_latch = data;
}

canonical_original_code:
static void bogeyman_8910_latch_w(unsigned int offset, unsigned int data)
{
 psg_latch = data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 bogeyman_vh_start()
{
size_t v0; // r12

v0 = videoram_size;
dirtybuffer = malloc(videoram_size);
memset(dirtybuffer, 1, v0);
tmpbitmap = bitmap_alloc(256LL, 256LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
size_t v0; // r12

v0 = videoram_size;
dirtybuffer = malloc(videoram_size);
memset(dirtybuffer, 1, v0);
tmpbitmap = bitmap_alloc(256LL, 256LL);
return 0LL;
}

original_code:
int bogeyman_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(videoram_size);
 memset(dirtybuffer,1,videoram_size);
 tmpbitmap = bitmap_alloc(256,256);
 return 0;
}

canonical_original_code:
int bogeyman_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(videoram_size);
 memset(dirtybuffer,1,videoram_size);
 tmpbitmap = bitmap_alloc(256,256);
 return 0;
}


decompiled_code:
__int64 bogeyman_vh_stop()
{
free(dirtybuffer);
return bitmap_free(tmpbitmap);
}

canonical_decompiled_code:
__int64 func5()
{
free(dirtybuffer);
return bitmap_free(tmpbitmap);
}

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall bogeyman_vh_screenrefresh(__int64 a1)
{
__int64 i; // r12
_BYTE *v2; // rdx
__int64 v3; // r8
__int16 v4; // ax
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rsi
unsigned __int64 v8; // r12
unsigned __int8 v9; // al
__int64 v10; // r15
__int64 v11; // r10
int v12; // edx
__int64 j; // r13
_BOOL4 v14; // er10
__int64 result; // rax
int v16; // ecx
int v17; // edx
__int64 v18; // [rsp-28h] [rbp-80h]
char v19; // [rsp+Fh] [rbp-49h]
_BOOL4 v20; // [rsp+10h] [rbp-48h]
int v21; // [rsp+14h] [rbp-44h]
__int64 v22; // [rsp+18h] [rbp-40h]

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
flipscreen = 0;
for ( i = 0LL; i != 256; ++i )
{
while ( 1 )
{
v2 = (char *)dirtybuffer + i + 256;
if ( *v2 | *((_BYTE *)dirtybuffer + i) )
break;
if ( ++i == 256 )
goto LABEL_7;
}
*v2 = 0;
v3 = (unsigned int)flipscreen;
*((_BYTE *)dirtybuffer + i) = 0;
v4 = *(unsigned __int8 *)(bogeyman_videoram + i + 256);
v5 = ((unsigned __int8)v4 >> 1) & 7;
v6 = *(_BYTE *)(bogeyman_videoram + i) & 0x7F;
v7 = *(_QWORD *)(Machine + 8LL * (((*(unsigned __int8 *)(bogeyman_videoram + i) | (v4 << 8) & 0x100) >> 7) + 3) + 512);
v18 = (unsigned int)i & 0xFFFFFFF0;
LOBYTE(v4) = i;
drawgfx(tmpbitmap, v7, v6, v5, v3, (unsigned int)v3, 16 * (v4 & 0xFu), v18, 0LL, 0LL, 0LL);
}
LABEL_7:
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v8 = 0LL;
do
{
while ( 1 )
{
v9 = *(_BYTE *)(spriteram + v8);
if ( (v9 & 1) != 0 )
{
v10 = *(unsigned __int8 *)(spriteram + (unsigned int)(v8 + 3));
v11 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + (unsigned int)(v8 + 2)));
v19 = v9 & 0x10;
if ( (v9 & 0x10) != 0 )
v11 = (unsigned int)(v11 - 16);
v22 = (unsigned int)(v8 + 1);
v21 = v11;
v20 = (v9 & 4) == 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v22) + ((4 * v9) & 0x100u),
((int)v9 >> 3) & 1,
(v9 & 4) == 0,
0LL,
v10,
v11,
Machine + 776LL,
2LL,
0LL);
if ( v19 )
break;
}
v8 += 4LL;
if ( spriteram_size <= v8 )
goto LABEL_15;
}
v12 = *(unsigned __int8 *)(spriteram + v8);
v8 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v22) + ((4 * (_WORD)v12) & 0x100u) + 1,
(v12 >> 3) & 1,
v20,
0LL,
v10,
(unsigned int)(v21 + 16),
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v8 );
}
LABEL_15:
for ( j = 0LL; j != 1024; ++j )
{
result = j & 0x1F;
v16 = (int)j >> 5;
if ( flipscreen )
{
result = (unsigned int)(31 - result);
v16 = 31 - v16;
}
v17 = *(unsigned __int8 *)(videoram + j) | (*(unsigned __int8 *)(videoram + j + 1024) << 8) & 0x300;
if ( v17 )
{
if ( v17 >> 9 )
{
v14 = (unsigned int)(v17 - 528) <= 0x16E;
}
else
{
v14 = 1;
if ( (unsigned int)(v17 - 267) > 0x4F )
v14 = (unsigned int)(v17 - 2) <= 0x33;
if ( (unsigned int)(v17 - 376) <= 0x4E || (unsigned int)(v17 - 480) <= 0x12 )
v14 = 1;
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (v17 >> 9) + 512),
v17 & 0x1FF,
v14,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * result),
(unsigned int)(8 * v16),
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 i; // r12
_BYTE *v2; // rdx
__int64 v3; // r8
__int16 v4; // ax
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rsi
unsigned __int64 v8; // r12
unsigned __int8 v9; // al
__int64 v10; // r15
__int64 v11; // r10
int v12; // edx
__int64 j; // r13
_BOOL4 v14; // er10
__int64 result; // rax
int v16; // ecx
int v17; // edx
__int64 v18; // [rsp-28h] [rbp-80h]
char v19; // [rsp+Fh] [rbp-49h]
_BOOL4 v20; // [rsp+10h] [rbp-48h]
int v21; // [rsp+14h] [rbp-44h]
__int64 v22; // [rsp+18h] [rbp-40h]

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
flipscreen = 0;
for ( i = 0LL; i != 256; ++i )
{
while ( 1 )
{
v2 = (char *)dirtybuffer + i + 256;
if ( *v2 | *((_BYTE *)dirtybuffer + i) )
break;
if ( ++i == 256 )
goto LABEL_7;
}
*v2 = 0;
v3 = (unsigned int)flipscreen;
*((_BYTE *)dirtybuffer + i) = 0;
v4 = *(unsigned __int8 *)(bogeyman_videoram + i + 256);
v5 = ((unsigned __int8)v4 >> 1) & 7;
v6 = *(_BYTE *)(bogeyman_videoram + i) & 0x7F;
v7 = *(_QWORD *)(Machine + 8LL * (((*(unsigned __int8 *)(bogeyman_videoram + i) | (v4 << 8) & 0x100) >> 7) + 3) + 512);
v18 = (unsigned int)i & 0xFFFFFFF0;
LOBYTE(v4) = i;
drawgfx(tmpbitmap, v7, v6, v5, v3, (unsigned int)v3, 16 * (v4 & 0xFu), v18, 0LL, 0LL, 0LL);
}
LABEL_7:
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v8 = 0LL;
do
{
while ( 1 )
{
v9 = *(_BYTE *)(spriteram + v8);
if ( (v9 & 1) != 0 )
{
v10 = *(unsigned __int8 *)(spriteram + (unsigned int)(v8 + 3));
v11 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + (unsigned int)(v8 + 2)));
v19 = v9 & 0x10;
if ( (v9 & 0x10) != 0 )
v11 = (unsigned int)(v11 - 16);
v22 = (unsigned int)(v8 + 1);
v21 = v11;
v20 = (v9 & 4) == 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v22) + ((4 * v9) & 0x100u),
((int)v9 >> 3) & 1,
(v9 & 4) == 0,
0LL,
v10,
v11,
Machine + 776LL,
2LL,
0LL);
if ( v19 )
break;
}
v8 += 4LL;
if ( spriteram_size <= v8 )
goto LABEL_15;
}
v12 = *(unsigned __int8 *)(spriteram + v8);
v8 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v22) + ((4 * (_WORD)v12) & 0x100u) + 1,
(v12 >> 3) & 1,
v20,
0LL,
v10,
(unsigned int)(v21 + 16),
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v8 );
}
LABEL_15:
for ( j = 0LL; j != 1024; ++j )
{
result = j & 0x1F;
v16 = (int)j >> 5;
if ( flipscreen )
{
result = (unsigned int)(31 - result);
v16 = 31 - v16;
}
v17 = *(unsigned __int8 *)(videoram + j) | (*(unsigned __int8 *)(videoram + j + 1024) << 8) & 0x300;
if ( v17 )
{
if ( v17 >> 9 )
{
v14 = (unsigned int)(v17 - 528) <= 0x16E;
}
else
{
v14 = 1;
if ( (unsigned int)(v17 - 267) > 0x4F )
v14 = (unsigned int)(v17 - 2) <= 0x33;
if ( (unsigned int)(v17 - 376) <= 0x4E || (unsigned int)(v17 - 480) <= 0x12 )
v14 = 1;
}
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (v17 >> 9) + 512),
v17 & 0x1FF,
v14,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * result),
(unsigned int)(8 * v16),
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

original_code:
void bogeyman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int mx,my,offs,color,tile,bank,sx,sy,flipx,flipy,multi;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 flipscreen=0;
 for (offs = 0; offs<0x100; offs++)
 {
  if (dirtybuffer[offs] | dirtybuffer[offs+0x100])
  {
   dirtybuffer[offs] = dirtybuffer[offs+0x100] = 0;
   sx=offs%16;
   sy=offs/16;
   bank=((bogeyman_videoram[offs+0x100] & 0x01) << 8) | bogeyman_videoram[offs];
   bank=(bank/0x80)+3;
   color=bogeyman_videoram[offs+0x100]>>1;
   drawgfx(tmpbitmap,Machine->gfx[bank],
     bogeyman_videoram[offs]&0x7f,
     color&7,
     flipscreen,flipscreen,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = 0;
   multi=spriteram[offs] & 0x10;
   if (multi) sy-=16;
   if (1 )
   {
    sx = 240 - sx;
    flipx = !flipx;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (multi)
    drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1]+ 1 + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy+16,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = 0;offs < 0x400; offs ++)
 {
  mx=offs%32;
  my=offs/32;
  if (flipscreen) {mx=31-mx; my=31-my;}
  tile=videoram[offs] | ((videoram[offs+0x400]&3)<<8);
  bank=tile/0x200;
  if (!tile) continue;
  color = 0;
  if (!bank)
  {
   if ((tile >= 0x002) && (tile < 0x036)) color = 1;
   if ((tile >= 0x10b) && (tile < 0x15b)) color = 1;
   if ((tile >= 0x178) && (tile < 0x1c7)) color = 1;
   if ((tile >= 0x1e0) && (tile < 0x1f3)) color = 1;
  } else {
   if ((tile >= (0x010+0x200)) && (tile < (0x17f+0x200))) color = 1;
  }
  drawgfx(bitmap,Machine->gfx[bank],
    tile&0x1ff,
    color,
    flipscreen,flipscreen,
    8*mx,8*my,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void bogeyman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int mx; int my; int offs; int color; int tile; int bank; int sx; int sy; int flipx; int flipy; int multi;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 flipscreen=0;
 for (offs = 0; offs<0x100; offs++)
 {
  if (dirtybuffer[offs] | dirtybuffer[offs+0x100])
  {
   dirtybuffer[offs] = dirtybuffer[offs+0x100] = 0;
   sx=offs%16;
   sy=offs/16;
   bank=((bogeyman_videoram[offs+0x100] & 0x01) << 8) | bogeyman_videoram[offs];
   bank=(bank/0x80)+3;
   color=bogeyman_videoram[offs+0x100]>>1;
   drawgfx(tmpbitmap,Machine->gfx[bank],
     bogeyman_videoram[offs]&0x7f,
     color&7,
     flipscreen,flipscreen,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = 0;
   multi=spriteram[offs] & 0x10;
   if (multi) sy-=16;
   if (1 )
   {
    sx = 240 - sx;
    flipx = !flipx;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (multi)
    drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1]+ 1 + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy+16,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = 0;offs < 0x400; offs ++)
 {
  mx=offs%32;
  my=offs/32;
  if (flipscreen) {mx=31-mx; my=31-my;}
  tile=videoram[offs] | ((videoram[offs+0x400]&3)<<8);
  bank=tile/0x200;
  if (!tile) continue;
  color = 0;
  if (!bank)
  {
   if ((tile >= 0x002) && (tile < 0x036)) color = 1;
   if ((tile >= 0x10b) && (tile < 0x15b)) color = 1;
   if ((tile >= 0x178) && (tile < 0x1c7)) color = 1;
   if ((tile >= 0x1e0) && (tile < 0x1f3)) color = 1;
  } else {
   if ((tile >= (0x010+0x200)) && (tile < (0x17f+0x200))) color = 1;
  }
  drawgfx(bitmap,Machine->gfx[bank],
    tile&0x1ff,
    color,
    flipscreen,flipscreen,
    8*mx,8*my,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: mx int

variable_types: my int

variable_types: offs int

variable_types: color int

variable_types: tile int

variable_types: bank int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


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

result = (unsigned int)last_0;
if ( (last_0 & 0x20) != 0 && (a2 & 0x20) == 0 )
{
if ( (last_0 & 0x10) != 0 )
AY8910_control_port_0_w(0LL, (unsigned int)psg_latch);
else
AY8910_write_port_0_w(0LL, (unsigned int)psg_latch);
result = (unsigned int)last_0;
}
if ( (result & 0x80u) == 0LL || (a2 & 0x80u) != 0 )
goto LABEL_7;
if ( (result & 0x40) != 0 )
{
result = AY8910_control_port_1_w(0LL, (unsigned int)psg_latch);
LABEL_7:
last_0 = a2;
return result;
}
result = AY8910_write_port_1_w(0LL, (unsigned int)psg_latch);
last_0 = a2;
return result;
}

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

result = (unsigned int)last_0;
if ( (last_0 & 0x20) != 0 && (a2 & 0x20) == 0 )
{
if ( (last_0 & 0x10) != 0 )
AY8910_control_port_0_w(0LL, (unsigned int)psg_latch);
else
AY8910_write_port_0_w(0LL, (unsigned int)psg_latch);
result = (unsigned int)last_0;
}
if ( (result & 0x80u) == 0LL || (a2 & 0x80u) != 0 )
goto LABEL_7;
if ( (result & 0x40) != 0 )
{
result = AY8910_control_port_1_w(0LL, (unsigned int)psg_latch);
LABEL_7:
last_0 = a2;
return result;
}
result = AY8910_write_port_1_w(0LL, (unsigned int)psg_latch);
last_0 = a2;
return result;
}

original_code:
static void bogeyman_8910_control_w(offs_t offset,data_t data)
{
 static int last;
 if ((last & 0x20) == 0x20 && (data & 0x20) == 0x00)
 {
  if (last & 0x10)
   AY8910_control_port_0_w(0,psg_latch);
  else
   AY8910_write_port_0_w(0,psg_latch);
 }
 if ((last & 0x80) == 0x80 && (data & 0x80) == 0x00)
 {
  if (last & 0x40)
   AY8910_control_port_1_w(0,psg_latch);
  else
   AY8910_write_port_1_w(0,psg_latch);
 }
 last = data;
}

canonical_original_code:
static void bogeyman_8910_control_w(unsigned int offset, unsigned int data)
{
 static int last;
 if ((last & 0x20) == 0x20 && (data & 0x20) == 0x00)
 {
  if (last & 0x10)
   AY8910_control_port_0_w(0,psg_latch);
  else
   AY8910_write_port_0_w(0,psg_latch);
 }
 if ((last & 0x80) == 0x80 && (data & 0x80) == 0x00)
 {
  if (last & 0x40)
   AY8910_control_port_1_w(0,psg_latch);
  else
   AY8910_write_port_1_w(0,psg_latch);
 }
 last = data;
}

variable_types: last int


decompiled_code:
__int64 __fastcall osd_start_audio_stream(int a1)
{
unsigned int v1; // er12
int v2; // ebp

usestereo = a1 != 0;
v1 = *(_DWORD *)(Machine + 836LL);
v2 = (int)(float)((float)(int)v1 / *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL));
samples_per_frame = v2;
if ( !v1 )
return v1;
v1 = v2;
samples_buffer = calloc(v2, 2 * (a1 != 0) + 2);
if ( a1 )
return v1;
conversion_buffer = calloc(v2, 4uLL);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // er12
int v2; // ebp

usestereo = a1 != 0;
v1 = *(_DWORD *)(Machine + 836LL);
v2 = (int)(float)((float)(int)v1 / *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL));
samples_per_frame = v2;
if ( !v1 )
return v1;
v1 = v2;
samples_buffer = calloc(v2, 2 * (a1 != 0) + 2);
if ( a1 )
return v1;
conversion_buffer = calloc(v2, 4uLL);
return (unsigned int)v2;
}

original_code:
int osd_start_audio_stream(int stereo)
{
 usestereo = stereo ? 1 : 0;
 samples_per_frame = Machine->sample_rate / Machine->drv->frames_per_second;
 if (Machine->sample_rate == 0) return 0;
 samples_buffer = (short *) calloc(samples_per_frame, 2 + usestereo * 2);
 if (!usestereo) conversion_buffer = (short *) calloc(samples_per_frame, 4);
 return samples_per_frame;
}

variable_types: stereo int


decompiled_code:
_DWORD *osd_stop_audio_stream()
{
_DWORD *result; // rax

result = &samples_per_frame;
samples_per_frame = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func1()
{
_DWORD *result; // rax

result = &samples_per_frame;
samples_per_frame = 0;
return result;
}

original_code:
void osd_stop_audio_stream(void)
{
 samples_per_frame = 0;
}

canonical_original_code:
void osd_stop_audio_stream()
{
 samples_per_frame = 0;
}


decompiled_code:
__int64 __fastcall osd_update_audio_stream(void *src)
{
memcpy(samples_buffer, src, samples_per_frame * (usestereo == 0 ? 2 : 4));
hook_audio_done();
return (unsigned int)samples_per_frame;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src)
{
memcpy(samples_buffer, src, samples_per_frame * (usestereo == 0 ? 2 : 4));
hook_audio_done();
return (unsigned int)samples_per_frame;
}

original_code:
int osd_update_audio_stream(INT16 *buffer)
{
 memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
   hook_audio_done();
 return samples_per_frame;
}

canonical_original_code:
int osd_update_audio_stream(short *buffer)
{
 memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
   hook_audio_done();
 return samples_per_frame;
}

variable_types:
buffer
short *


decompiled_code:
__int64 osd_get_mastervolume()
{
return 100LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 100LL;
}

original_code:
int osd_get_mastervolume(void)
{
 return 100;
}

canonical_original_code:
int osd_get_mastervolume()
{
 return 100;
}


decompiled_code:
void osd_sound_enable()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void osd_sound_enable(int enable_it)
{
 (void)enable_it;
}


decompiled_code:
void osd_opl_write()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void osd_opl_write(int chip,int data)
{
 (void)chip;
 (void)data;
}

canonical_original_code:
void osd_opl_write(int chip, int data)
{
 (void)chip;
 (void)data;
}

variable_types: chip int

variable_types: data int