original_code:
void hexa_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++;
 }
}

canonical_original_code:
void hexa_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++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

result = memory_region(129LL);
*(_WORD *)(result + 292) = 0;
*(_BYTE *)(result + 294) = 0;
return result;
}

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

result = memory_region(129LL);
*(_WORD *)(result + 292) = 0;
*(_BYTE *)(result + 294) = 0;
return result;
}

original_code:
static void init_hexa(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0x0124] = 0x00;
 RAM[0x0125] = 0x00;
 RAM[0x0126] = 0x00;
}

canonical_original_code:
static void init_hexa()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0x0124] = 0x00;
 RAM[0x0125] = 0x00;
 RAM[0x0126] = 0x00;
}

variable_types:
RAM
unsigned char *

return_type: void


decompiled_code:
void *__fastcall hexa_d008_w(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(129LL);
if ( (a2 & 1) != flipx )
{
flipx = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
if ( (a2 & 2) != flipy )
{
flipy = a2 & 2;
memset(dirtybuffer, 1, videoram_size);
}
cpu_bankbase[1] = v2 + ((((a2 >> 4) & 1) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
if ( ((a2 >> 5) & 1) != charbank )
{
charbank = (a2 >> 5) & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

v2 = memory_region(129LL);
if ( (a2 & 1) != flipx )
{
flipx = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
if ( (a2 & 2) != flipy )
{
flipy = a2 & 2;
memset(dirtybuffer, 1, videoram_size);
}
cpu_bankbase[1] = v2 + ((((a2 >> 4) & 1) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
if ( ((a2 >> 5) & 1) != charbank )
{
charbank = (a2 >> 5) & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void hexa_d008_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (flipx != (data & 0x01))
 {
  flipx = data & 0x01;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipy != (data & 0x02))
 {
  flipy = data & 0x02;
  memset(dirtybuffer,1,videoram_size);
 }
 bankaddress = 0x10000 + ((data & 0x10) >> 4) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (charbank != ((data & 0x20) >> 5))
 {
  charbank = (data & 0x20) >> 5;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void hexa_d008_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (flipx != (data & 0x01))
 {
  flipx = data & 0x01;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipy != (data & 0x02))
 {
  flipy = data & 0x02;
  memset(dirtybuffer,1,videoram_size);
 }
 bankaddress = 0x10000 + ((data & 0x10) >> 4) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (charbank != ((data & 0x20) >> 5))
 {
  charbank = (data & 0x20) >> 5;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: bankaddress int


decompiled_code:
__int64 __fastcall hexa_vh_screenrefresh(__int64 a1)
{
int v1; // er14
__int64 v2; // rbx
__int64 v3; // r10

v1 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v2 = v1;
do
{
v3 = v2 + 1;
if ( *(_BYTE *)(dirtybuffer + v2) || *(_BYTE *)(dirtybuffer + v2 + 1) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((*(unsigned __int8 *)(videoram + v2) << 8) & 0x700u) + (charbank << 11),
*(_BYTE *)(videoram + v2) >> 3);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // er14
__int64 v2; // rbx
__int64 v3; // r10

v1 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v2 = v1;
do
{
v3 = v2 + 1;
if ( *(_BYTE *)(dirtybuffer + v2) || *(_BYTE *)(dirtybuffer + v2 + 1) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((*(unsigned __int8 *)(videoram + v2) << 8) & 0x700u) + (charbank << 11),
*(_BYTE *)(videoram + v2) >> 3);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void hexa_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs + 1])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs + 1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   if (flipx) sx = 31 - sx;
   if (flipy) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs + 1] + ((videoram[offs] & 0x07) << 8) + (charbank << 11),
     (videoram[offs] & 0xf8) >> 3,
     flipx,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void hexa_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs + 1])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs + 1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   if (flipx) sx = 31 - sx;
   if (flipy) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs + 1] + ((videoram[offs] & 0x07) << 8) + (charbank << 11),
     (videoram[offs] & 0xf8) >> 3,
     flipx,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 __fastcall timer_callback_2203(int a1)
{
Timer[2 * (a1 & 0x7F) + (a1 >> 7)] = 0LL;
return YM2203TimerOver(a1 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
Timer[2 * (a1 & 0x7F) + (a1 >> 7)] = 0LL;
return YM2203TimerOver(a1 & 0x7F);
}

original_code:
static void timer_callback_2203(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 YM2203TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2203(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 YM2203TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2203UpdateRequest(int a1)
{
return stream_update(stream[a1], 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return stream_update(stream[a1], 0LL);
}

original_code:
void YM2203UpdateRequest(int chip)
{
 stream_update(stream[chip],0);
}

variable_types: chip int


decompiled_code:
_BOOL8 __fastcall YM2203_sh_start(__int64 a1)
{
int v2; // er8
_BOOL8 result; // rax
unsigned int *v4; // rax
__int64 v5; // rdi
__int64 v6; // r14
const char *v7; // rax
char v8[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = AY8910_sh_start();
result = 1LL;
if ( !v2 )
{
intf = *(_QWORD *)(a1 + 8);
FMTimerInit();
v5 = *v4;
if ( (int)v5 > 0 )
{
v6 = 0LL;
do
{
v7 = (const char *)sound_name(a1);
sprintf(v8, "%s #%d FM", v7, (unsigned int)v6);
stream[v6] = stream_init(
v8,
(unsigned int)*(__int16 *)(intf + 4LL * (int)v6 + 10),
*(unsigned int *)(Machine + 836LL),
(unsigned int)v6,
&YM2203UpdateOne);
v4 = (unsigned int *)intf;
++v6;
v5 = *(unsigned int *)intf;
}
while ( (int)v5 > (int)v6 );
}
result = (unsigned int)YM2203Init(v5, v4[1], *(unsigned int *)(Machine + 836LL), TimerHandler, IRQHandler) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
int v2; // er8
_BOOL8 result; // rax
unsigned int *v4; // rax
__int64 v5; // rdi
__int64 v6; // r14
const char *v7; // rax
char v8[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = AY8910_sh_start();
result = 1LL;
if ( !v2 )
{
intf = *(_QWORD *)(a1 + 8);
func0();
v5 = *v4;
if ( (int)v5 > 0 )
{
v6 = 0LL;
do
{
v7 = (const char *)sound_name(a1);
sprintf(v8, "%s #%d FM", v7, (unsigned int)v6);
stream[v6] = stream_init(
v8,
(unsigned int)*(__int16 *)(intf + 4LL * (int)v6 + 10),
*(unsigned int *)(Machine + 836LL),
(unsigned int)v6,
&YM2203UpdateOne);
v4 = (unsigned int *)intf;
++v6;
v5 = *(unsigned int *)intf;
}
while ( (int)v5 > (int)v6 );
}
result = (unsigned int)YM2203Init(v5, v4[1], *(unsigned int *)(Machine + 836LL), TimerHandler, IRQHandler) != 0;
}
return result;
}

original_code:
int YM2203_sh_start(const struct MachineSound *msound)
{
 int i;
 if (AY8910_sh_start(msound)) return 1;
 intf = msound->sound_interface;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  int volume;
  char name[20];
  sprintf(name,"%s #%d FM",sound_name(msound),i);
  volume = intf->mixing_level[i]>>16;
  stream[i] = stream_init(name,volume,Machine->sample_rate,i,YM2203UpdateOne );
 }
 if (YM2203Init(intf->num,intf->baseclock,Machine->sample_rate,TimerHandler,IRQHandler) == 0)
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int YM2203_sh_start(struct MachineSound *msound)
{
 int i;
 if (AY8910_sh_start(msound)) return 1;
 intf = msound->sound_interface;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  int volume;
  char name[20];
  sprintf(name,"%s #%d FM",sound_name(msound),i);
  volume = intf->mixing_level[i]>>16;
  stream[i] = stream_init(name,volume,Machine->sample_rate,i,YM2203UpdateOne );
 }
 if (YM2203Init(intf->num,intf->baseclock,Machine->sample_rate,TimerHandler,IRQHandler) == 0)
 {
  return 0;
 }
 return 1;
}

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

variable_types: i int

variable_types: volume int

variable_types:
name
char [20]

return_type: int


decompiled_code:
// attributes: thunk
__int64 YM2203_sh_stop()
{
return YM2203Shutdown();
}

canonical_decompiled_code:
__int64 func5()
{
return YM2203Shutdown();
}

original_code:
void YM2203_sh_stop(void)
{
 YM2203Shutdown();
}

canonical_original_code:
void YM2203_sh_stop()
{
 YM2203Shutdown();
}


decompiled_code:
__int64 YM2203_sh_reset()
{
__int64 result; // rax
unsigned int v1; // ebx
__int64 v2; // rdi

result = *(unsigned int *)intf;
if ( (int)result > 0 )
{
v1 = 0;
do
{
v2 = v1++;
YM2203ResetChip(v2);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
unsigned int v1; // ebx
__int64 v2; // rdi

result = *(unsigned int *)intf;
if ( (int)result > 0 )
{
v1 = 0;
do
{
v2 = v1++;
YM2203ResetChip(v2);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

original_code:
void YM2203_sh_reset(void)
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2203ResetChip(i);
}

canonical_original_code:
void YM2203_sh_reset()
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2203ResetChip(i);
}


decompiled_code:
__int64 YM2203_status_port_0_r()
{
return (unsigned __int8)YM2203Read(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int8)YM2203Read(0LL, 0LL);
}

original_code: data_t YM2203_status_port_0_r(offs_t offset) { return YM2203Read(0,0); }

canonical_original_code: unsigned int YM2203_status_port_0_r(unsigned int offset) { return YM2203Read(0,0); }

return_type: unsigned int


decompiled_code:
__int64 YM2203_status_port_1_r()
{
return (unsigned __int8)YM2203Read(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int8)YM2203Read(1LL, 0LL);
}

original_code: data_t YM2203_status_port_1_r(offs_t offset) { return YM2203Read(1,0); }

canonical_original_code: unsigned int YM2203_status_port_1_r(unsigned int offset) { return YM2203Read(1,0); }


decompiled_code:
__int64 YM2203_status_port_2_r()
{
return (unsigned __int8)YM2203Read(2LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)YM2203Read(2LL, 0LL);
}

original_code: data_t YM2203_status_port_2_r(offs_t offset) { return YM2203Read(2,0); }

canonical_original_code: unsigned int YM2203_status_port_2_r(unsigned int offset) { return YM2203Read(2,0); }


decompiled_code:
__int64 YM2203_status_port_3_r()
{
return (unsigned __int8)YM2203Read(3LL, 0LL);
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned __int8)YM2203Read(3LL, 0LL);
}

original_code: data_t YM2203_status_port_3_r(offs_t offset) { return YM2203Read(3,0); }

canonical_original_code: unsigned int YM2203_status_port_3_r(unsigned int offset) { return YM2203Read(3,0); }


decompiled_code:
__int64 YM2203_status_port_4_r()
{
return (unsigned __int8)YM2203Read(4LL, 0LL);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned __int8)YM2203Read(4LL, 0LL);
}

original_code: data_t YM2203_status_port_4_r(offs_t offset) { return YM2203Read(4,0); }

canonical_original_code: unsigned int YM2203_status_port_4_r(unsigned int offset) { return YM2203Read(4,0); }


decompiled_code:
__int64 YM2203_read_port_0_r()
{
return (unsigned __int8)YM2203Read(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned __int8)YM2203Read(0LL, 1LL);
}

original_code: data_t YM2203_read_port_0_r(offs_t offset) { return YM2203Read(0,1); }

canonical_original_code: unsigned int YM2203_read_port_0_r(unsigned int offset) { return YM2203Read(0,1); }


decompiled_code:
__int64 YM2203_read_port_1_r()
{
return (unsigned __int8)YM2203Read(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned __int8)YM2203Read(1LL, 1LL);
}

original_code: data_t YM2203_read_port_1_r(offs_t offset) { return YM2203Read(1,1); }

canonical_original_code: unsigned int YM2203_read_port_1_r(unsigned int offset) { return YM2203Read(1,1); }


decompiled_code:
__int64 YM2203_read_port_2_r()
{
return (unsigned __int8)YM2203Read(2LL, 1LL);
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned __int8)YM2203Read(2LL, 1LL);
}

original_code: data_t YM2203_read_port_2_r(offs_t offset) { return YM2203Read(2,1); }

canonical_original_code: unsigned int YM2203_read_port_2_r(unsigned int offset) { return YM2203Read(2,1); }


decompiled_code:
__int64 YM2203_read_port_3_r()
{
return (unsigned __int8)YM2203Read(3LL, 1LL);
}

canonical_decompiled_code:
__int64 func15()
{
return (unsigned __int8)YM2203Read(3LL, 1LL);
}

original_code: data_t YM2203_read_port_3_r(offs_t offset) { return YM2203Read(3,1); }

canonical_original_code: unsigned int YM2203_read_port_3_r(unsigned int offset) { return YM2203Read(3,1); }


decompiled_code:
__int64 YM2203_read_port_4_r()
{
return (unsigned __int8)YM2203Read(4LL, 1LL);
}

canonical_decompiled_code:
__int64 func16()
{
return (unsigned __int8)YM2203Read(4LL, 1LL);
}

original_code: data_t YM2203_read_port_4_r(offs_t offset) { return YM2203Read(4,1); }

canonical_original_code: unsigned int YM2203_read_port_4_r(unsigned int offset) { return YM2203Read(4,1); }


decompiled_code:
__int64 __fastcall YM2203_control_port_0_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(0LL, 0LL, a2);
}

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

original_code:
void YM2203_control_port_0_w(offs_t offset,data_t data)
{
 YM2203Write(0,0,data);
}

canonical_original_code:
void YM2203_control_port_0_w(unsigned int offset, unsigned int data)
{
 YM2203Write(0,0,data);
}


decompiled_code:
__int64 __fastcall YM2203_control_port_1_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(1LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(1LL, 0LL, a2);
}

original_code:
void YM2203_control_port_1_w(offs_t offset,data_t data)
{
 YM2203Write(1,0,data);
}

canonical_original_code:
void YM2203_control_port_1_w(unsigned int offset, unsigned int data)
{
 YM2203Write(1,0,data);
}


decompiled_code:
__int64 __fastcall YM2203_control_port_2_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(2LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(2LL, 0LL, a2);
}

original_code:
void YM2203_control_port_2_w(offs_t offset,data_t data)
{
 YM2203Write(2,0,data);
}

canonical_original_code:
void YM2203_control_port_2_w(unsigned int offset, unsigned int data)
{
 YM2203Write(2,0,data);
}


decompiled_code:
__int64 __fastcall YM2203_control_port_3_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(3LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(3LL, 0LL, a2);
}

original_code:
void YM2203_control_port_3_w(offs_t offset,data_t data)
{
 YM2203Write(3,0,data);
}

canonical_original_code:
void YM2203_control_port_3_w(unsigned int offset, unsigned int data)
{
 YM2203Write(3,0,data);
}


decompiled_code:
__int64 __fastcall YM2203_control_port_4_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 0LL, a2);
}

original_code:
void YM2203_control_port_4_w(offs_t offset,data_t data)
{
 YM2203Write(4,0,data);
}

canonical_original_code:
void YM2203_control_port_4_w(unsigned int offset, unsigned int data)
{
 YM2203Write(4,0,data);
}


decompiled_code:
__int64 __fastcall YM2203_write_port_0_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(0LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(0LL, 1LL, a2);
}

original_code:
void YM2203_write_port_0_w(offs_t offset,data_t data)
{
 YM2203Write(0,1,data);
}

canonical_original_code:
void YM2203_write_port_0_w(unsigned int offset, unsigned int data)
{
 YM2203Write(0,1,data);
}


decompiled_code:
__int64 __fastcall YM2203_write_port_1_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(1LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(1LL, 1LL, a2);
}

original_code:
void YM2203_write_port_1_w(offs_t offset,data_t data)
{
 YM2203Write(1,1,data);
}

canonical_original_code:
void YM2203_write_port_1_w(unsigned int offset, unsigned int data)
{
 YM2203Write(1,1,data);
}


decompiled_code:
__int64 __fastcall YM2203_write_port_2_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(2LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(2LL, 1LL, a2);
}

original_code:
void YM2203_write_port_2_w(offs_t offset,data_t data)
{
 YM2203Write(2,1,data);
}

canonical_original_code:
void YM2203_write_port_2_w(unsigned int offset, unsigned int data)
{
 YM2203Write(2,1,data);
}


decompiled_code:
__int64 __fastcall YM2203_write_port_3_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(3LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(3LL, 1LL, a2);
}

original_code:
void YM2203_write_port_3_w(offs_t offset,data_t data)
{
 YM2203Write(3,1,data);
}

canonical_original_code:
void YM2203_write_port_3_w(unsigned int offset, unsigned int data)
{
 YM2203Write(3,1,data);
}


decompiled_code:
__int64 __fastcall YM2203_write_port_4_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 1LL, a2);
}

original_code:
void YM2203_write_port_4_w(offs_t offset,data_t data)
{
 YM2203Write(4,1,data);
}

canonical_original_code:
void YM2203_write_port_4_w(unsigned int offset, unsigned int data)
{
 YM2203Write(4,1,data);
}


FMTimerInit

decompiled_code:
void FMTimerInit()
{
qword_4E8 = 0LL;
Timer = 0LL;
qword_4F8 = 0LL;
qword_4F0 = 0LL;
qword_508 = 0LL;
qword_500 = 0LL;
qword_518 = 0LL;
qword_510 = 0LL;
}

canonical_decompiled_code:
void func0()
{
qword_4E8 = 0LL;
Timer = 0LL;
qword_4F8 = 0LL;
qword_4F0 = 0LL;
qword_508 = 0LL;
qword_500 = 0LL;
qword_518 = 0LL;
qword_510 = 0LL;
}

original_code:
static void FMTimerInit( void )
{
 int i;
 for( i = 0 ; i < 4 ; i++ )
 {
  Timer[i][0] = Timer[i][1] = 0;
 }
}

canonical_original_code:
static void FMTimerInit()
{
 int i;
 for( i = 0 ; i < 4 ; i++ )
 {
  Timer[i][0] = Timer[i][1] = 0;
 }
}


original_code:
void cheekyms_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i,j,bit;
 for (i = 0; i < 3; i++)
 {
  const unsigned char* color_prom_save = color_prom;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 0) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 1) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 2) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
  color_prom = color_prom_save;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 4) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 5) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 6) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
 }
}

canonical_original_code:
void cheekyms_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i; int j; int bit;
 for (i = 0; i < 3; i++)
 {
  unsigned char *color_prom_save = color_prom;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 0) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 1) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 2) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
  color_prom = color_prom_save;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 4) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 5) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 6) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: j int

variable_types: bit int


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

v2 = a2 & 0x80;
if ( v2 != last_dac_0 )
{
last_dac_0 = v2;
result = DAC_data_w(0LL);
}
return result;
}

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

v2 = a2 & 0x80;
if ( v2 != last_dac_0 )
{
last_dac_0 = v2;
result = DAC_data_w(0LL);
}
return result;
}

original_code:
void cheekyms_port_40_w(offs_t offset,data_t data)
{
 static int last_dac = -1;
 if (last_dac != (data & 0x80))
 {
  last_dac = data & 0x80;
  DAC_data_w(0, last_dac ? 0x80 : 0);
 }
}

canonical_original_code:
void cheekyms_port_40_w(unsigned int offset, unsigned int data)
{
 static int last_dac = -1;
 if (last_dac != (data & 0x80))
 {
  last_dac = data & 0x80;
  DAC_data_w(0, last_dac ? 0x80 : 0);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall cheekyms_port_80_w(__int64 a1, unsigned int a2)
{
interrupt_enable_w(a1, a2 & 4);
if ( man_scroll != ((a2 >> 3) & 7) )
{
man_scroll = (a2 >> 3) & 7;
redraw_man = 1;
}
set_vh_global_attribute(&char_palette, (a2 >> 2) & 0x10);
return flip_screen_w((unsigned int)a1, (unsigned __int8)a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
interrupt_enable_w(a1, a2 & 4);
if ( man_scroll != ((a2 >> 3) & 7) )
{
man_scroll = (a2 >> 3) & 7;
redraw_man = 1;
}
set_vh_global_attribute(&char_palette, (a2 >> 2) & 0x10);
return flip_screen_w((unsigned int)a1, (unsigned __int8)a2 & 0x80);
}

original_code:
void cheekyms_port_80_w(offs_t offset,data_t data)
{
 int new_man_scroll;
 interrupt_enable_w(offset, data & 0x04);
    new_man_scroll = (data >> 3) & 0x07;
 if (man_scroll != new_man_scroll)
 {
  man_scroll = new_man_scroll;
  redraw_man = 1;
 }
 set_vh_global_attribute(&char_palette, (data >> 2) & 0x10);
 flip_screen_w(offset, data & 0x80);
}

canonical_original_code:
void cheekyms_port_80_w(unsigned int offset, unsigned int data)
{
 int new_man_scroll;
 interrupt_enable_w(offset, data & 0x04);
    new_man_scroll = (data >> 3) & 0x07;
 if (man_scroll != new_man_scroll)
 {
  man_scroll = new_man_scroll;
  redraw_man = 1;
 }
 set_vh_global_attribute(&char_palette, (data >> 2) & 0x10);
 flip_screen_w(offset, data & 0x80);
}


decompiled_code:
__int64 __fastcall cheekyms_vh_screenrefresh(__int64 a1, int a2)
{
int *v3; // rbx
int *v4; // r15
int v5; // ecx
int v6; // ebp
__int64 v7; // rcx
__int64 v8; // r11
__int64 v9; // r10
__int64 v10; // rsi
__int64 v11; // rdi
int v12; // er12
int v13; // ebx
__int64 v14; // r15
_BOOL4 v15; // esi
int v16; // edx
int v17; // eax
__int64 v18; // rcx
__int64 v19; // rax
__int64 v20; // rdi
__int64 v21; // r8
unsigned int v23; // [rsp+0h] [rbp-58h]
int v24; // [rsp+8h] [rbp-50h]
int v25; // [rsp+10h] [rbp-48h]
int v26; // [rsp+14h] [rbp-44h]

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v3 = sprites;
v4 = &sprites[128];
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
do
{
while ( 1 )
{
v5 = v3[3];
if ( (v5 & 8) == 0 )
goto LABEL_5;
v6 = *v3;
v7 = v5 & 7;
v8 = (unsigned int)v3[1];
v9 = (unsigned int)(256 - v3[2]);
v10 = *(_QWORD *)(Machine + 520LL);
v11 = Machine + 776LL;
v12 = (2 * ~*(_BYTE *)v3) & 0x1F;
if ( (*v3 & 0x80u) == 0 )
break;
drawgfx(a1, v10, (unsigned int)(flip_screen_x == 0) + v12, v7, 0LL, 0LL, v9, v8, v11, 2LL, 0LL);
LABEL_5:
v3 += 4;
if ( v4 == v3 )
goto LABEL_9;
}
v26 = ~*v3;
v3 += 4;
v25 = v8;
v24 = v9;
v23 = v7;
drawgfx(a1, v10, (unsigned int)(v12 + 32), v7, 0LL, 0LL, v9, v8, v11, 2LL, 0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(v12 + 33),
v23,
0LL,
0LL,
v24 + 8 * (v6 & 2u),
v25 + 8 * (v26 & 2u),
Machine + 776LL,
2LL,
0LL);
}
while ( v4 != v3 );
LABEL_9:
v13 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v14 = v13;
while ( 1 )
{
v21 = flip_screen_x;
v16 = v13 & 0x1F;
v17 = v13 >> 5;
if ( flip_screen_x )
{
if ( (unsigned int)(v17 - 5) > 0x14 )
goto LABEL_24;
}
else if ( (unsigned int)(v17 - 6) > 0x14 )
{
LABEL_24:
if ( !*((_BYTE *)dirtybuffer + v14) )
goto LABEL_21;
*((_BYTE *)dirtybuffer + v14) = 0;
v21 = flip_screen_x;
v18 = Machine;
if ( flip_screen_x )
{
v16 = 31 - v16;
v19 = (unsigned int)(8 * (31 - v17));
}
else
{
v19 = (unsigned int)(8 * v17);
}
v20 = Machine + 776LL;
goto LABEL_20;
}
v15 = (unsigned int)(v16 - 8) <= 4;
if ( !*((_BYTE *)dirtybuffer + v14) )
break;
*((_BYTE *)dirtybuffer + v14) = 0;
v21 = flip_screen_x;
if ( flip_screen_x )
goto LABEL_17;
LABEL_18:
v18 = Machine;
v19 = (unsigned int)(8 * v17);
v20 = Machine + 776LL;
if ( v15 )
goto LABEL_19;
LABEL_20:
drawgfx(
tmpbitmap,
*(_QWORD *)(v18 + 512),
*(unsigned __int8 *)(videoram + v14),
(unsigned int)char_palette,
v21,
(unsigned int)v21,
(unsigned int)(8 * v16),
v19,
v20,
0LL,
0LL);
LABEL_21:
--v13;
--v14;
if ( v13 == -1 )
goto LABEL_31;
}
if ( !redraw_man || (unsigned int)(v16 - 8) > 4 )
goto LABEL_21;
if ( !flip_screen_x )
{
v18 = Machine;
LODWORD(v19) = 8 * v17;
v20 = Machine + 776LL;
LABEL_19:
v19 = (unsigned int)(v19 - man_scroll);
goto LABEL_20;
}
v15 = 1;
LABEL_17:
v16 = 31 - v16;
v17 = 31 - v17;
goto LABEL_18;
}
LABEL_31:
redraw_man = 0;
return copybitmap(
a1,
tmpbitmap,
0LL,
0LL,
0LL,
0LL,
Machine + 776LL,
2LL,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned int)(4 * char_palette)));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int *v3; // rbx
int *v4; // r15
int v5; // ecx
int v6; // ebp
__int64 v7; // rcx
__int64 v8; // r11
__int64 v9; // r10
__int64 v10; // rsi
__int64 v11; // rdi
int v12; // er12
int v13; // ebx
__int64 v14; // r15
_BOOL4 v15; // esi
int v16; // edx
int v17; // eax
__int64 v18; // rcx
__int64 v19; // rax
__int64 v20; // rdi
__int64 v21; // r8
unsigned int v23; // [rsp+0h] [rbp-58h]
int v24; // [rsp+8h] [rbp-50h]
int v25; // [rsp+10h] [rbp-48h]
int v26; // [rsp+14h] [rbp-44h]

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v3 = sprites;
v4 = &sprites[128];
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
do
{
while ( 1 )
{
v5 = v3[3];
if ( (v5 & 8) == 0 )
goto LABEL_5;
v6 = *v3;
v7 = v5 & 7;
v8 = (unsigned int)v3[1];
v9 = (unsigned int)(256 - v3[2]);
v10 = *(_QWORD *)(Machine + 520LL);
v11 = Machine + 776LL;
v12 = (2 * ~*(_BYTE *)v3) & 0x1F;
if ( (*v3 & 0x80u) == 0 )
break;
drawgfx(a1, v10, (unsigned int)(flip_screen_x == 0) + v12, v7, 0LL, 0LL, v9, v8, v11, 2LL, 0LL);
LABEL_5:
v3 += 4;
if ( v4 == v3 )
goto LABEL_9;
}
v26 = ~*v3;
v3 += 4;
v25 = v8;
v24 = v9;
v23 = v7;
drawgfx(a1, v10, (unsigned int)(v12 + 32), v7, 0LL, 0LL, v9, v8, v11, 2LL, 0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(v12 + 33),
v23,
0LL,
0LL,
v24 + 8 * (v6 & 2u),
v25 + 8 * (v26 & 2u),
Machine + 776LL,
2LL,
0LL);
}
while ( v4 != v3 );
LABEL_9:
v13 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v14 = v13;
while ( 1 )
{
v21 = flip_screen_x;
v16 = v13 & 0x1F;
v17 = v13 >> 5;
if ( flip_screen_x )
{
if ( (unsigned int)(v17 - 5) > 0x14 )
goto LABEL_24;
}
else if ( (unsigned int)(v17 - 6) > 0x14 )
{
LABEL_24:
if ( !*((_BYTE *)dirtybuffer + v14) )
goto LABEL_21;
*((_BYTE *)dirtybuffer + v14) = 0;
v21 = flip_screen_x;
v18 = Machine;
if ( flip_screen_x )
{
v16 = 31 - v16;
v19 = (unsigned int)(8 * (31 - v17));
}
else
{
v19 = (unsigned int)(8 * v17);
}
v20 = Machine + 776LL;
goto LABEL_20;
}
v15 = (unsigned int)(v16 - 8) <= 4;
if ( !*((_BYTE *)dirtybuffer + v14) )
break;
*((_BYTE *)dirtybuffer + v14) = 0;
v21 = flip_screen_x;
if ( flip_screen_x )
goto LABEL_17;
LABEL_18:
v18 = Machine;
v19 = (unsigned int)(8 * v17);
v20 = Machine + 776LL;
if ( v15 )
goto LABEL_19;
LABEL_20:
drawgfx(
tmpbitmap,
*(_QWORD *)(v18 + 512),
*(unsigned __int8 *)(videoram + v14),
(unsigned int)char_palette,
v21,
(unsigned int)v21,
(unsigned int)(8 * v16),
v19,
v20,
0LL,
0LL);
LABEL_21:
--v13;
--v14;
if ( v13 == -1 )
goto LABEL_31;
}
if ( !redraw_man || (unsigned int)(v16 - 8) > 4 )
goto LABEL_21;
if ( !flip_screen_x )
{
v18 = Machine;
LODWORD(v19) = 8 * v17;
v20 = Machine + 776LL;
LABEL_19:
v19 = (unsigned int)(v19 - man_scroll);
goto LABEL_20;
}
v15 = 1;
LABEL_17:
v16 = 31 - v16;
v17 = 31 - v17;
goto LABEL_18;
}
LABEL_31:
redraw_man = 0;
return copybitmap(
a1,
tmpbitmap,
0LL,
0LL,
0LL,
0LL,
Machine + 776LL,
2LL,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned int)(4 * char_palette)));
}

original_code:
void cheekyms_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 for (offs = 0; offs < sizeof(sprites); offs += 4)
 {
  int v1, sx, sy, col, code;
  v1 = sprites[offs + 0];
  sy = sprites[offs + 1];
  sx = 256 - sprites[offs + 2];
  col = (sprites[offs + 3] & 0x07);
  if (!(sprites[offs + 3] & 0x08)) continue;
  code = (~v1 << 1) & 0x1f;
  if (v1 & 0x80)
  {
   if (!flip_screen_x)
   {
    code++;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
  else
  {
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x20,
     col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x21,
     col,
     0,0,
     sx + 8*(v1 & 2),sy + 8*(~v1 & 2),
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy,man_area;
  sx = offs % 32;
  sy = offs / 32;
  if (flip_screen_x)
  {
   man_area = ((sy >= 5) && (sy <= 25) && (sx >= 8) && (sx <= 12));
  }
  else
  {
   man_area = ((sy >= 6) && (sy <= 26) && (sx >= 8) && (sx <= 12));
  }
  if (dirtybuffer[offs] ||
   (redraw_man && man_area))
  {
   dirtybuffer[offs] = 0;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     0 + char_palette,
     flip_screen_x,flip_screen_x,
     8*sx, 8*sy - (man_area ? man_scroll : 0),
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 redraw_man = 0;
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,Machine->pens[4*char_palette]);
}

canonical_original_code:
void cheekyms_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 for (offs = 0; offs < sizeof(sprites); offs += 4)
 {
  int v1; int sx; int sy; int col; int code;
  v1 = sprites[offs + 0];
  sy = sprites[offs + 1];
  sx = 256 - sprites[offs + 2];
  col = (sprites[offs + 3] & 0x07);
  if (!(sprites[offs + 3] & 0x08)) continue;
  code = (~v1 << 1) & 0x1f;
  if (v1 & 0x80)
  {
   if (!flip_screen_x)
   {
    code++;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
  else
  {
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x20,
     col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x21,
     col,
     0,0,
     sx + 8*(v1 & 2),sy + 8*(~v1 & 2),
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy; int man_area;
  sx = offs % 32;
  sy = offs / 32;
  if (flip_screen_x)
  {
   man_area = ((sy >= 5) && (sy <= 25) && (sx >= 8) && (sx <= 12));
  }
  else
  {
   man_area = ((sy >= 6) && (sy <= 26) && (sx >= 8) && (sx <= 12));
  }
  if (dirtybuffer[offs] ||
   (redraw_man && man_area))
  {
   dirtybuffer[offs] = 0;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     0 + char_palette,
     flip_screen_x,flip_screen_x,
     8*sx, 8*sy - (man_area ? man_scroll : 0),
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 redraw_man = 0;
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,Machine->pens[4*char_palette]);
}

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

variable_types: offs int

variable_types: col int

variable_types: code int


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

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

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

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

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

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


decompiled_code:
void __fastcall avalnche_noise_amplitude_w(__int64 a1, char a2)
{
volume = a2 & 0x3F;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
volume = a2 & 0x3F;
}

original_code:
void avalnche_noise_amplitude_w(offs_t offset,data_t data)
{
 volume = data & 0x3F;
}

canonical_original_code:
void avalnche_noise_amplitude_w(unsigned int offset, unsigned int data)
{
 volume = data & 0x3F;
}


decompiled_code:
__int64 __fastcall avalnche_videoram_w(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int i; // ebx
unsigned int v5; // eax
__int64 v6; // rsi

result = a1;
*(_BYTE *)(videoram + a1) = a2;
if ( a1 > 0x1FF )
{
for ( i = 0; i != 8; ++i )
{
v5 = a2 >> i;
v6 = 8 * (a1 & 0x1F) + 7 - i;
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
v6,
a1 >> 5,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v5 & 1)));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int i; // ebx
unsigned int v5; // eax
__int64 v6; // rsi

result = a1;
*(_BYTE *)(videoram + a1) = a2;
if ( a1 > 0x1FF )
{
for ( i = 0; i != 8; ++i )
{
v5 = a2 >> i;
v6 = 8 * (a1 & 0x1F) + 7 - i;
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
v6,
a1 >> 5,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v5 & 1)));
}
}
return result;
}

original_code:
void avalnche_videoram_w(offs_t offset,data_t data)
{
 videoram[offset] = data;
 if (offset >= 0x200)
 {
  int x,y,i;
  x = 8 * (offset % 32);
  y = offset / 32;
  for (i = 0;i < 8;i++)
   plot_pixel(Machine->scrbitmap,x+7-i,y,Machine->pens[(data >> i) & 1]);
 }
}

canonical_original_code:
void avalnche_videoram_w(unsigned int offset, unsigned int data)
{
 videoram[offset] = data;
 if (offset >= 0x200)
 {
  int x; int y; int i;
  x = 8 * (offset % 32);
  y = offset / 32;
  for (i = 0;i < 8;i++)
   plot_pixel(Machine->scrbitmap,x+7-i,y,Machine->pens[(data >> i) & 1]);
 }
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall avalnche_input_r(char a1)
{
int v1; // eax

v1 = a1 & 3;
if ( v1 == 1 )
return input_port_1_r();
if ( v1 == 2 )
return input_port_2_r();
if ( (a1 & 3) != 0 )
return 0LL;
return input_port_0_r();
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
int v1; // eax

v1 = a1 & 3;
if ( v1 == 1 )
return input_port_1_r();
if ( v1 == 2 )
return input_port_2_r();
if ( (a1 & 3) != 0 )
return 0LL;
return input_port_0_r();
}

original_code:
data_t avalnche_input_r(offs_t offset)
{
 switch (offset & 0x03)
 {
  case 0x00: return input_port_0_r(offset);
  case 0x01: return input_port_1_r(offset);
  case 0x02: return input_port_2_r(offset);
  case 0x03: return 0;
 }
 return 0;
}

canonical_original_code:
unsigned int avalnche_input_r(unsigned int offset)
{
 switch (offset & 0x03)
 {
  case 0x00: return input_port_0_r(offset);
  case 0x01: return input_port_1_r(offset);
  case 0x02: return input_port_2_r(offset);
  case 0x03: return 0;
 }
 return 0;
}


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

switch ( a1 & 7 )
{
case 0:
result = osd_led_w(0LL, a2 & 1);
break;
case 1:
attract = a2 & 1;
break;
case 2:
if ( (a2 & 1) != 0 )
{
palette_change_color(0LL, 0LL, 0LL, 0LL);
result = palette_change_color(1LL, 255LL, 255LL, 255LL);
}
else
{
palette_change_color(0LL, 255LL, 255LL, 255LL);
result = palette_change_color(1LL, 0LL, 0LL, 0LL);
}
break;
case 3:
result = osd_led_w(1LL, a2 & 1);
break;
case 4:
aud0 = a2 & 1;
break;
case 5:
aud1 = a2 & 1;
break;
case 6:
aud2 = a2 & 1;
break;
case 7:
result = osd_led_w(2LL, a2 & 1);
break;
}
return result;
}

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

switch ( a1 & 7 )
{
case 0:
result = osd_led_w(0LL, a2 & 1);
break;
case 1:
attract = a2 & 1;
break;
case 2:
if ( (a2 & 1) != 0 )
{
palette_change_color(0LL, 0LL, 0LL, 0LL);
result = palette_change_color(1LL, 255LL, 255LL, 255LL);
}
else
{
palette_change_color(0LL, 255LL, 255LL, 255LL);
result = palette_change_color(1LL, 0LL, 0LL, 0LL);
}
break;
case 3:
result = osd_led_w(1LL, a2 & 1);
break;
case 4:
aud0 = a2 & 1;
break;
case 5:
aud1 = a2 & 1;
break;
case 6:
aud2 = a2 & 1;
break;
case 7:
result = osd_led_w(2LL, a2 & 1);
break;
}
return result;
}

original_code:
void avalnche_output_w(offs_t offset,data_t data)
{
 switch (offset & 0x07)
 {
  case 0x00:
         osd_led_w(0,(data & 0x01));
   break;
  case 0x01:
   attract = data & 0x01;
   break;
  case 0x02:
   if (data & 0x01)
   {
    palette_change_color(0,0,0,0);
    palette_change_color(1,255,255,255);
   }
   else
   {
    palette_change_color(0,255,255,255);
    palette_change_color(1,0,0,0);
   }
   break;
  case 0x03:
         osd_led_w(1,(data & 0x01));
   break;
  case 0x04:
   aud0 = data & 0x01;
   break;
  case 0x05:
   aud1 = data & 0x01;
   break;
  case 0x06:
   aud2 = data & 0x01;
   break;
  case 0x07:
         osd_led_w(2,(data & 0x01));
   break;
 }
}

canonical_original_code:
void avalnche_output_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x07)
 {
  case 0x00:
         osd_led_w(0,(data & 0x01));
   break;
  case 0x01:
   attract = data & 0x01;
   break;
  case 0x02:
   if (data & 0x01)
   {
    palette_change_color(0,0,0,0);
    palette_change_color(1,255,255,255);
   }
   else
   {
    palette_change_color(0,255,255,255);
    palette_change_color(1,0,0,0);
   }
   break;
  case 0x03:
         osd_led_w(1,(data & 0x01));
   break;
  case 0x04:
   aud0 = data & 0x01;
   break;
  case 0x05:
   aud1 = data & 0x01;
   break;
  case 0x06:
   aud2 = data & 0x01;
   break;
  case 0x07:
         osd_led_w(2,(data & 0x01));
   break;
 }
}


decompiled_code:
__int64 avalnche_interrupt()
{
int v0; // edx
int v1; // eax
unsigned __int8 v2; // dl

v0 = ((_BYTE)time_8V_2 + 1) & 1;
time_8V_2 = v0;
time_16V_1 = ((_BYTE)time_16V_1 + 1) & 3;
v1 = ((_BYTE)time_32V_0 + 1) & 7;
time_32V_0 = v1;
if ( attract || (aud2 != 1 || v0) && (aud1 != 1 || v1) )
DAC_data_w(0LL, 0LL);
else
DAC_data_w(0LL, 255LL);
if ( !(time_16V_1 | attract) )
{
v2 = (2 * noise_l4) | ((((unsigned __int8)noise_l4 ^ (unsigned __int8)(noise_k4 >> 6)) & 1) == 0);
noise_k4 = (unsigned __int8)((2 * noise_k4) | (noise_l4 >> 7) & 1);
noise_l4 = v2;
noise = noise_k4 >> 7;
}
if ( !aud0 && noise )
{
DAC_data_w(1LL, (unsigned int)volume);
if ( time_16V_1 )
return 0LL;
}
else
{
DAC_data_w(1LL, 0LL);
if ( time_16V_1 )
return 0LL;
}
return nmi_interrupt();
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edx
int v1; // eax
unsigned __int8 v2; // dl

v0 = ((_BYTE)time_8V_2 + 1) & 1;
time_8V_2 = v0;
time_16V_1 = ((_BYTE)time_16V_1 + 1) & 3;
v1 = ((_BYTE)time_32V_0 + 1) & 7;
time_32V_0 = v1;
if ( attract || (aud2 != 1 || v0) && (aud1 != 1 || v1) )
DAC_data_w(0LL, 0LL);
else
DAC_data_w(0LL, 255LL);
if ( !(time_16V_1 | attract) )
{
v2 = (2 * noise_l4) | ((((unsigned __int8)noise_l4 ^ (unsigned __int8)(noise_k4 >> 6)) & 1) == 0);
noise_k4 = (unsigned __int8)((2 * noise_k4) | (noise_l4 >> 7) & 1);
noise_l4 = v2;
noise = noise_k4 >> 7;
}
if ( !aud0 && noise )
{
DAC_data_w(1LL, (unsigned int)volume);
if ( time_16V_1 )
return 0LL;
}
else
{
DAC_data_w(1LL, 0LL);
if ( time_16V_1 )
return 0LL;
}
return nmi_interrupt();
}

original_code:
int avalnche_interrupt(void)
{
 static int time_8V = 0;
 static int time_16V = 0;
 static int time_32V = 0;
 int k4_input;
 int l4_input;
 time_8V = (time_8V + 1) & 0x01;
 time_16V = (time_16V + 1) & 0x03;
 time_32V = (time_32V + 1) & 0x07;
 if ((attract==0) && (aud2==1) && (time_8V==0))
  DAC_data_w(0,255);
 else if ((attract==0) && (aud1==1) && (time_32V==0))
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if ((attract==0) && (time_16V==0))
 {
  l4_input = 0x01 ^ ((noise_l4 & 0x01) ^ (((noise_k4) & 0x40) >> 6));
  k4_input = (noise_l4 & 0x80) >> 7;
  noise_l4 = ((noise_l4 << 1) | l4_input) & 0xFF;
  noise_k4 = ((noise_k4 << 1) | k4_input) & 0xFF;
  noise = (noise_k4 & 0x80) >> 7;
 }
 if ((aud0==0) && (noise))
  DAC_data_w(1,volume);
 else
  DAC_data_w(1,0);
 if (time_16V==0)
  return nmi_interrupt();
 else
  return 0;
}

canonical_original_code:
int avalnche_interrupt()
{
 static int time_8V = 0;
 static int time_16V = 0;
 static int time_32V = 0;
 int k4_input;
 int l4_input;
 time_8V = (time_8V + 1) & 0x01;
 time_16V = (time_16V + 1) & 0x03;
 time_32V = (time_32V + 1) & 0x07;
 if ((attract==0) && (aud2==1) && (time_8V==0))
  DAC_data_w(0,255);
 else if ((attract==0) && (aud1==1) && (time_32V==0))
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if ((attract==0) && (time_16V==0))
 {
  l4_input = 0x01 ^ ((noise_l4 & 0x01) ^ (((noise_k4) & 0x40) >> 6));
  k4_input = (noise_l4 & 0x80) >> 7;
  noise_l4 = ((noise_l4 << 1) | l4_input) & 0xFF;
  noise_k4 = ((noise_k4 << 1) | k4_input) & 0xFF;
  noise = (noise_k4 & 0x80) >> 7;
 }
 if ((aud0==0) && (noise))
  DAC_data_w(1,volume);
 else
  DAC_data_w(1,0);
 if (time_16V==0)
  return nmi_interrupt();
 else
  return 0;
}


decompiled_code:
__int64 init_avalnche()
{
__int64 v0; // rcx
__int64 result; // rax
__int64 v2; // rcx
char v3; // dl
char v4; // dl

v0 = memory_region(129LL);
result = v0 + 24576;
v2 = v0 + 0x8000;
do
{
v3 = *(_BYTE *)(result + 0x2000);
v4 = *(_BYTE *)(++result + 0x3FFF) + 16 * v3;
*(_BYTE *)(result - 1) = v4;
*(_BYTE *)(result + 0x7FFF) = v4;
}
while ( v2 != result );
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rcx
__int64 result; // rax
__int64 v2; // rcx
char v3; // dl
char v4; // dl

v0 = memory_region(129LL);
result = v0 + 24576;
v2 = v0 + 0x8000;
do
{
v3 = *(_BYTE *)(result + 0x2000);
v4 = *(_BYTE *)(++result + 0x3FFF) + 16 * v3;
*(_BYTE *)(result - 1) = v4;
*(_BYTE *)(result + 0x7FFF) = v4;
}
while ( v2 != result );
return result;
}

original_code:
static void init_avalnche(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for(i=0;i<0x2000;i++)
 {
  rom[0x6000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
  rom[0xE000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
 }
}

canonical_original_code:
static void init_avalnche()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for(i=0;i<0x2000;i++)
 {
  rom[0x6000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
  rom[0xE000+i] = (rom[0x8000+i]<<4)+rom[0xA000+i];
 }
}

variable_types:
rom
unsigned char *


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

result = 0xFFFFFFFFLL;
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return result;
}

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

result = 0xFFFFFFFFLL;
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return result;
}

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

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


decompiled_code:
__int64 __fastcall OPL_WRITE(unsigned int a1, unsigned int a2)
{
YM3812_control_port_0_w(0LL, a1);
return YM3812_write_port_0_w(0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
YM3812_control_port_0_w(0LL, a1);
return YM3812_write_port_0_w(0LL, a2);
}

original_code:
static inline void OPL_WRITE(int reg, int data)
{
 YM3812_control_port_0_w(0, reg);
 YM3812_write_port_0_w(0, data);
}

variable_types: reg int

variable_types: data int


decompiled_code:
__int64 __fastcall OPL_WRITE_DATA2(int a1, int a2, unsigned int a3)
{
return OPL_WRITE(order_1[a2] + a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, unsigned int a3)
{
return func0(order_1[a2] + a1, a3);
}

original_code:
static inline void OPL_WRITE_DATA2(int offset, int channel, int data)
{
 static const int order[9]={0x03,0x04,0x05,0x0b,0x0c,0x0d,0x13,0x14,0x15};
 OPL_WRITE(offset+order[channel], data);
}

canonical_original_code:
static inline void OPL_WRITE_DATA2(int offset, int channel, int data)
{
 static int order[9] = {0x03,0x04,0x05,0x0b,0x0c,0x0d,0x13,0x14,0x15};
 OPL_WRITE(offset+order[channel], data);
}

variable_types: offset int

variable_types: channel int

variable_types:
order
int [9]


decompiled_code:
__int64 __fastcall OPL_WRITE_DATA1(int a1, int a2, unsigned int a3)
{
return OPL_WRITE(order_0[a2] + a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, unsigned int a3)
{
return func0(order_0[a2] + a1, a3);
}

original_code:
static inline void OPL_WRITE_DATA1(int offset, int channel, int data)
{
 static const int order[9]={0x00,0x01,0x02,0x08,0x09,0x0a,0x10,0x11,0x12};
 OPL_WRITE(offset+order[channel], data);
}

canonical_original_code:
static inline void OPL_WRITE_DATA1(int offset, int channel, int data)
{
 static int order[9] = {0x00,0x01,0x02,0x08,0x09,0x0a,0x10,0x11,0x12};
 OPL_WRITE(offset+order[channel], data);
}


decompiled_code:
__int64 __fastcall ym2413_setinstrument(int a1, int a2, int a3)
{
int *v3; // rbp
__int64 v4; // rbx
int i; // edi
__int64 result; // rax
unsigned int v7; // edx

if ( a3 )
v3 = (int *)((char *)&ym2413_instruments + 48 * a3);
else
v3 = &ym2413_state[24 * a1 + 3];
v4 = 0LL;
for ( i = 32; ; i = reg_2[v4] )
{
v7 = v3[v4];
if ( (v4 & 1) == 0 )
break;
result = OPL_WRITE_DATA2(i, a2, v7);
if ( ++v4 == 10 )
return result;
LABEL_5:
;
}
result = OPL_WRITE_DATA1(i, a2, v7);
if ( ++v4 != 10 )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3)
{
int *v3; // rbp
__int64 v4; // rbx
int i; // edi
__int64 result; // rax
unsigned int v7; // edx

if ( a3 )
v3 = (int *)((char *)&ym2413_instruments + 48 * a3);
else
v3 = &ym2413_state[24 * a1 + 3];
v4 = 0LL;
for ( i = 32; ; i = reg_2[v4] )
{
v7 = v3[v4];
if ( (v4 & 1) == 0 )
break;
result = func1(i, a2, v7);
if ( ++v4 == 10 )
return result;
LABEL_5:
;
}
result = func2(i, a2, v7);
if ( ++v4 != 10 )
goto LABEL_5;
return result;
}

original_code:
void ym2413_setinstrument(int chip, int channel, int inst)
{
 static const int reg[10]=
 {
  0x20,0x20,0x40,0x40,0x60,0x60,0x80,0x80,0xe0,0xe0
 };
 int *pn;
 int i;
 if (!inst)
 {
  pn=&ym2413_state[chip].user_instrument[0];
 }
 else
 {
  pn=&(ym2413_instruments[inst][0]);
 }
 for (i=0; i<10; i++)
 {
  if (i & 0x01)
  {
   OPL_WRITE_DATA2(reg[i], channel, *pn);
  }
  else
  {
   OPL_WRITE_DATA1(reg[i], channel, *pn);
  }
  pn++;
 }
}

canonical_original_code:
void ym2413_setinstrument(int chip, int channel, int inst)
{
 static int reg[10] = {
  0x20,0x20,0x40,0x40,0x60,0x60,0x80,0x80,0xe0,0xe0
 };
 int *pn;
 int i;
 if (!inst)
 {
  pn=&ym2413_state[chip].user_instrument[0];
 }
 else
 {
  pn=&(ym2413_instruments[inst][0]);
 }
 for (i=0; i<10; i++)
 {
  if (i & 0x01)
  {
   OPL_WRITE_DATA2(reg[i], channel, *pn);
  }
  else
  {
   OPL_WRITE_DATA1(reg[i], channel, *pn);
  }
  pn++;
 }
}

variable_types: chip int

variable_types: inst int

variable_types:
reg
int [10]

variable_types:
pn
int *

variable_types: i int


decompiled_code:
__int64 __fastcall YM2413_sh_start(__int64 a1, __int64 a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm1
__m128i v4; // xmm0

memset(ym2413_state, 0, 0x60uLL);
ym2413_state[0] = 50000;
v2 = _mm_load_si128(ym2413_instruments);
v3 = _mm_load_si128(&ym2413_instruments[1]);
v4 = _mm_load_si128(&ym2413_instruments[2]);
xmmword_78C = (__int128)v2;
xmmword_79C = (__int128)v3;
xmmword_7AC = (__int128)v4;
memset(&ym2413_state[24], 0, 0x60uLL);
dword_7E0 = 50000;
xmmword_7EC = (__int128)v2;
xmmword_7FC = (__int128)v3;
xmmword_80C = (__int128)v4;
return YM3812_sh_start(a1, a2, ym2413_instruments);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__m128i v2; // xmm2
__m128i v3; // xmm1
__m128i v4; // xmm0

memset(ym2413_state, 0, 0x60uLL);
ym2413_state[0] = 50000;
v2 = _mm_load_si128(ym2413_instruments);
v3 = _mm_load_si128(&ym2413_instruments[1]);
v4 = _mm_load_si128(&ym2413_instruments[2]);
xmmword_78C = (__int128)v2;
xmmword_79C = (__int128)v3;
xmmword_7AC = (__int128)v4;
memset(&ym2413_state[24], 0, 0x60uLL);
dword_7E0 = 50000;
xmmword_7EC = (__int128)v2;
xmmword_7FC = (__int128)v3;
xmmword_80C = (__int128)v4;
return YM3812_sh_start(a1, a2, ym2413_instruments);
}

original_code:
int YM2413_sh_start(const struct MachineSound *msound)
{
 int i, j;
 for (i=0; i<2; i++)
 {
  memset(&ym2413_state[i], 0, sizeof(ym2413_state[0]));
  for (j=0; j<12; j++)
  {
   ym2413_state[i].user_instrument[j]=ym2413_instruments[0][j];
  }
        ym2413_state[i].fsam = ym2413_clock / 72;
 }
 return YM3812_sh_start(msound);
}

canonical_original_code:
int YM2413_sh_start(struct MachineSound *msound)
{
 int i; int j;
 for (i=0; i<2; i++)
 {
  memset(&ym2413_state[i], 0, sizeof(ym2413_state[0]));
  for (j=0; j<12; j++)
  {
   ym2413_state[i].user_instrument[j]=ym2413_instruments[0][j];
  }
        ym2413_state[i].fsam = ym2413_clock / 72;
 }
 return YM3812_sh_start(msound);
}

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

variable_types: j int


decompiled_code:
__int64 YM2413_sh_stop()
{
unsigned int i; // ebx
unsigned int v1; // edi

for ( i = 0; i != 245; ++i )
{
v1 = i;
OPL_WRITE(v1, 0);
}
return YM3812_sh_stop();
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int i; // ebx
unsigned int v1; // edi

for ( i = 0; i != 245; ++i )
{
v1 = i;
func0(v1, 0);
}
return YM3812_sh_stop();
}

original_code:
void YM2413_sh_stop(void)
{
 int i;
 for (i=0; i<0xf5; i++)
 {
  OPL_WRITE(i, 0);
 }
 YM3812_sh_stop();
}

canonical_original_code:
void YM2413_sh_stop()
{
 int i;
 for (i=0; i<0xf5; i++)
 {
  OPL_WRITE(i, 0);
 }
 YM3812_sh_stop();
}


decompiled_code:
// attributes: thunk
__int64 YM2413_status_port_0_r()
{
return YM3812_status_port_0_r();
}

canonical_decompiled_code:
__int64 func6()
{
return YM3812_status_port_0_r();
}

original_code:
data_t YM2413_status_port_0_r(offs_t offset)
{
 return YM3812_status_port_0_r(offset);
}

canonical_original_code:
unsigned int YM2413_status_port_0_r(unsigned int offset)
{
 return YM3812_status_port_0_r(offset);
}

variable_types:
offset
unsigned int


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

result = 24LL * a1;
ym2413_state[result + 2] = a2;
return result * 4;
}

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

result = 24LL * a1;
ym2413_state[result + 2] = a2;
return result * 4;
}

original_code:
void YM2413_register_port_0_w(offs_t offset,data_t data)
{
 int chip = offset;
 ym2413_state[chip].pending_register=data;
}

canonical_original_code:
void YM2413_register_port_0_w(unsigned int offset, unsigned int data)
{
 int chip = offset;
 ym2413_state[chip].pending_register=data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall YM2413_data_port_0_w(int a1, unsigned int a2)
{
int v2; // ebp
unsigned __int8 v3; // bl
__int64 result; // rax
int v5; // eax
int v6; // kr00_4
int v7; // ebx
int v8; // esi

v2 = ym2413_state[24 * a1 + 2];
v3 = a2;
switch ( v2 )
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
result = v2 + 24LL * a1;
ym2413_state[result + 3] = a2;
break;
case 14:
ym2413_state[24 * a1 + 1] = a2 & 0x20;
if ( (a2 & 0x20) != 0 )
{
OPL_WRITE(0xB6u, 0);
OPL_WRITE(0xB7u, 0);
OPL_WRITE(0xB8u, 0);
ym2413_setinstrument(a1, 6, 16);
ym2413_setinstrument(a1, 7, 17);
ym2413_setinstrument(a1, 8, 18);
}
result = OPL_WRITE(0xBDu, a2 & 0x3F);
break;
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
result = v2 - 16 + 24LL * a1 + 12;
ym2413_state[result + 3] = a2;
break;
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
v6 = ym2413_state[24 * a1]
* (2 << (((a2 >> 1) & 7) - 1))
* (ym2413_state[24 * a1 - 17 + v2] | ((_WORD)a2 << 8) & 0x100);
v5 = v6 + (v6 < 0 ? 0x7FFFF : 0);
v7 = (4 * ((v5 >> 29) & 0xF) + 12) | (2 * (_BYTE)a2) & 0x20 | (v5 >> 27) & 3;
OPL_WRITE(v2 + 128, (unsigned __int8)(v6 / 0x80000));
result = OPL_WRITE(v2 + 144, v7);
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
v8 = v2 - 48;
result = (unsigned int)ym2413_state[24 * a1 + 1];
if ( !(_DWORD)result || v8 <= 5 )
result = ym2413_setinstrument(a1, v8, v3 >> 4);
break;
default:
result = logerror("YM2413: Write to register %02x\n", (unsigned int)v2);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2)
{
int v2; // ebp
unsigned __int8 v3; // bl
__int64 result; // rax
int v5; // eax
int v6; // kr00_4
int v7; // ebx
int v8; // esi

v2 = ym2413_state[24 * a1 + 2];
v3 = a2;
switch ( v2 )
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
result = v2 + 24LL * a1;
ym2413_state[result + 3] = a2;
break;
case 14:
ym2413_state[24 * a1 + 1] = a2 & 0x20;
if ( (a2 & 0x20) != 0 )
{
func0(0xB6u, 0);
func0(0xB7u, 0);
func0(0xB8u, 0);
func3(a1, 6, 16);
func3(a1, 7, 17);
func3(a1, 8, 18);
}
result = func0(0xBDu, a2 & 0x3F);
break;
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
result = v2 - 16 + 24LL * a1 + 12;
ym2413_state[result + 3] = a2;
break;
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
v6 = ym2413_state[24 * a1]
* (2 << (((a2 >> 1) & 7) - 1))
* (ym2413_state[24 * a1 - 17 + v2] | ((_WORD)a2 << 8) & 0x100);
v5 = v6 + (v6 < 0 ? 0x7FFFF : 0);
v7 = (4 * ((v5 >> 29) & 0xF) + 12) | (2 * (_BYTE)a2) & 0x20 | (v5 >> 27) & 3;
func0(v2 + 128, (unsigned __int8)(v6 / 0x80000));
result = func0(v2 + 144, v7);
break;
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
v8 = v2 - 48;
result = (unsigned int)ym2413_state[24 * a1 + 1];
if ( !(_DWORD)result || v8 <= 5 )
result = func3(a1, v8, v3 >> 4);
break;
default:
result = logerror("YM2413: Write to register %02x\n", (unsigned int)v2);
break;
}
return result;
}

original_code:
void YM2413_data_port_0_w(offs_t offset,data_t data)
{
 int chip = offset;
    int value, channel, instrument, i, block, volume, frq, fnumber, octave;
 int pending=ym2413_state[chip].pending_register;
 switch(pending)
 {
  case 0x00:
  case 0x01:
  case 0x02:
  case 0x03:
  case 0x04:
  case 0x05:
  case 0x06:
  case 0x07:
    ym2413_state[chip].user_instrument[pending] = data;
    break;
  case 0x0e:
    ym2413_state[chip].rhythm_mode=data&0x20;
    if (data & 0x20 )
    {
     for (i=6; i<9; i++)
     {
      OPL_WRITE(0xb0+i, 0);
     }
     ym2413_setinstrument(chip, 6, 16);
     ym2413_setinstrument(chip, 7, 17);
     ym2413_setinstrument(chip, 8, 18);
    }
    OPL_WRITE(0xbd, data & 0x3f);
    break;
  case 0x10:
  case 0x11:
  case 0x12:
  case 0x13:
  case 0x14:
  case 0x15:
  case 0x16:
  case 0x17:
  case 0x18:
    channel=pending-0x10;
                ym2413_state[chip].fnumberlow[channel]=data;
    break;
  case 0x20:
  case 0x21:
  case 0x22:
  case 0x23:
  case 0x24:
  case 0x25:
  case 0x26:
  case 0x27:
  case 0x28:
    channel=pending-0x20;
                fnumber=ym2413_state[chip].fnumberlow[channel]|(data&0x01)<<8;
                block = (data >> 1) & 0x07;
                frq=fnumber * ( 2 << (block-1) ) *
                              ym2413_state[chip].fsam / (2<<18);
                octave = ((frq >> 10) & 0x0f) + 3;
                frq &= 0x3ff;
                value = ( data & 0x10) << 1;
                value |= (frq >> 8) & 0x03;
                value |= octave << 2;
                OPL_WRITE(0xa0+channel, frq & 0xff);
                OPL_WRITE(0xb0+channel, value);
    break;
  case 0x30:
  case 0x31:
  case 0x32:
  case 0x33:
  case 0x34:
  case 0x35:
  case 0x36:
  case 0x37:
  case 0x38:
    channel=pending-0x30;
    if (ym2413_state[chip].rhythm_mode && channel >= 6)
    {
    }
    else
    {
     instrument=(data >> 4) & 0x0f;
     ym2413_setinstrument(chip, channel, instrument);
     volume=data & 0x0f;
    }
    break;
  default:
    logerror("YM2413: Write to register %02x\n", pending);
    break;
 }
}

canonical_original_code:
void YM2413_data_port_0_w(unsigned int offset, unsigned int data)
{
 int chip = offset;
    int value; int channel; int instrument; int i; int block; int volume; int frq; int fnumber; int octave;
 int pending = ym2413_state[chip].pending_register;
 switch(pending)
 {
  case 0x00:
  case 0x01:
  case 0x02:
  case 0x03:
  case 0x04:
  case 0x05:
  case 0x06:
  case 0x07:
    ym2413_state[chip].user_instrument[pending] = data;
    break;
  case 0x0e:
    ym2413_state[chip].rhythm_mode=data&0x20;
    if (data & 0x20 )
    {
     for (i=6; i<9; i++)
     {
      OPL_WRITE(0xb0+i, 0);
     }
     ym2413_setinstrument(chip, 6, 16);
     ym2413_setinstrument(chip, 7, 17);
     ym2413_setinstrument(chip, 8, 18);
    }
    OPL_WRITE(0xbd, data & 0x3f);
    break;
  case 0x10:
  case 0x11:
  case 0x12:
  case 0x13:
  case 0x14:
  case 0x15:
  case 0x16:
  case 0x17:
  case 0x18:
    channel=pending-0x10;
                ym2413_state[chip].fnumberlow[channel]=data;
    break;
  case 0x20:
  case 0x21:
  case 0x22:
  case 0x23:
  case 0x24:
  case 0x25:
  case 0x26:
  case 0x27:
  case 0x28:
    channel=pending-0x20;
                fnumber=ym2413_state[chip].fnumberlow[channel]|(data&0x01)<<8;
                block = (data >> 1) & 0x07;
                frq=fnumber * ( 2 << (block-1) ) *
                              ym2413_state[chip].fsam / (2<<18);
                octave = ((frq >> 10) & 0x0f) + 3;
                frq &= 0x3ff;
                value = ( data & 0x10) << 1;
                value |= (frq >> 8) & 0x03;
                value |= octave << 2;
                OPL_WRITE(0xa0+channel, frq & 0xff);
                OPL_WRITE(0xb0+channel, value);
    break;
  case 0x30:
  case 0x31:
  case 0x32:
  case 0x33:
  case 0x34:
  case 0x35:
  case 0x36:
  case 0x37:
  case 0x38:
    channel=pending-0x30;
    if (ym2413_state[chip].rhythm_mode && channel >= 6)
    {
    }
    else
    {
     instrument=(data >> 4) & 0x0f;
     ym2413_setinstrument(chip, channel, instrument);
     volume=data & 0x0f;
    }
    break;
  default:
    logerror("YM2413: Write to register %02x\n", pending);
    break;
 }
}

variable_types: value int

variable_types: instrument int

variable_types: block int

variable_types: volume int

variable_types: frq int

variable_types: fnumber int

variable_types: octave int

variable_types: pending int


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

result = addr_1 ^ 2u;
addr_1 ^= 2u;
return result;
}

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

result = addr_1 ^ 2u;
addr_1 ^= 2u;
return result;
}

original_code:
int airbustr_interrupt(void)
{
static int addr = 0xff;
 addr ^= 0x02;
 return addr;
}

canonical_original_code:
int airbustr_interrupt()
{
static int addr = 0xff;
 addr ^= 0x02;
 return addr;
}

variable_types: addr int


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

result = addr_0 ^ 2u;
addr_0 ^= 2u;
return result;
}

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

result = addr_0 ^ 2u;
addr_0 ^= 2u;
return result;
}

original_code:
int airbustr_interrupt2(void)
{
static int addr = 0xfd;
 addr ^= 0x02;
 return addr;
}

canonical_original_code:
int airbustr_interrupt2()
{
static int addr = 0xfd;
 addr ^= 0x02;
 return addr;
}


decompiled_code:
__int64 soundcommand_status_r()
{
return (unsigned int)(1 - soundlatch2_status + 2 * soundlatch_status + 4);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)(1 - soundlatch2_status + 2 * soundlatch_status + 4);
}

original_code:
static data_t soundcommand_status_r(offs_t offset)
{
 return 4 + soundlatch_status * 2 + (1-soundlatch2_status);
}

canonical_original_code:
static unsigned int soundcommand_status_r(unsigned int offset)
{
 return 4 + soundlatch_status * 2 + (1-soundlatch2_status);
}


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

v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = v0;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, v2);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

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

v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = v0;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, v2);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

original_code:
int airbustr_vh_start(void)
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int airbustr_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall airbustr_scrollregs_w(int a1, int a2)
{
int v2; // ebx
int v3; // ebp
int v4; // edx

v2 = (unsigned __int8)-(flipscreen == 0) - 511;
v3 = flipscreen == 0 ? -148 : -106;
switch ( a1 )
{
case 0:
fg_scrolly_6 = a2;
goto LABEL_3;
case 2:
fg_scrollx_5 = a2;
v4 = bg_scrollx_3;
LOWORD(a2) = highbits_2;
break;
case 4:
bg_scrolly_4 = a2;
v4 = bg_scrollx_3;
LOWORD(a2) = highbits_2;
break;
case 6:
bg_scrollx_3 = a2;
v4 = a2;
LOWORD(a2) = highbits_2;
break;
case 8:
a2 = ~a2;
v4 = bg_scrollx_3;
highbits_2 = a2;
break;
default:
LABEL_3:
LOWORD(a2) = highbits_2;
v4 = bg_scrollx_3;
break;
}
tilemap_set_scrollx(bg_tilemap, 0LL, v3 + (((_WORD)a2 << 6) & 0x100u) + v4);
tilemap_set_scrolly(bg_tilemap, 0LL, v2 + bg_scrolly_4 + ((32 * (_WORD)highbits_2) & 0x100u));
tilemap_set_scrollx(fg_tilemap, 0LL, v3 + fg_scrollx_5 + (((_WORD)highbits_2 << 8) & 0x100u));
return tilemap_set_scrolly(fg_tilemap, 0LL, v2 + fg_scrolly_6 + (((_WORD)highbits_2 << 7) & 0x100u));
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
int v2; // ebx
int v3; // ebp
int v4; // edx

v2 = (unsigned __int8)-(flipscreen == 0) - 511;
v3 = flipscreen == 0 ? -148 : -106;
switch ( a1 )
{
case 0:
fg_scrolly_6 = a2;
goto LABEL_3;
case 2:
fg_scrollx_5 = a2;
v4 = bg_scrollx_3;
LOWORD(a2) = highbits_2;
break;
case 4:
bg_scrolly_4 = a2;
v4 = bg_scrollx_3;
LOWORD(a2) = highbits_2;
break;
case 6:
bg_scrollx_3 = a2;
v4 = a2;
LOWORD(a2) = highbits_2;
break;
case 8:
a2 = ~a2;
v4 = bg_scrollx_3;
highbits_2 = a2;
break;
default:
LABEL_3:
LOWORD(a2) = highbits_2;
v4 = bg_scrollx_3;
break;
}
tilemap_set_scrollx(bg_tilemap, 0LL, v3 + (((_WORD)a2 << 6) & 0x100u) + v4);
tilemap_set_scrolly(bg_tilemap, 0LL, v2 + bg_scrolly_4 + ((32 * (_WORD)highbits_2) & 0x100u));
tilemap_set_scrollx(fg_tilemap, 0LL, v3 + fg_scrollx_5 + (((_WORD)highbits_2 << 8) & 0x100u));
return tilemap_set_scrolly(fg_tilemap, 0LL, v2 + fg_scrolly_6 + (((_WORD)highbits_2 << 7) & 0x100u));
}

original_code:
void airbustr_scrollregs_w(offs_t offset,data_t data)
{
static int bg_scrollx, bg_scrolly, fg_scrollx, fg_scrolly, highbits;
int xoffs, yoffs;
 if (flipscreen) { xoffs = -0x06a; yoffs = -0x1ff;}
 else { xoffs = -0x094; yoffs = -0x100;}
 switch (offset)
 {
  case 0x00: fg_scrolly = data; break;
  case 0x02: fg_scrollx = data; break;
  case 0x04: bg_scrolly = data; break;
  case 0x06: bg_scrollx = data; break;
  case 0x08: highbits = ~data; break;
  default:
      break;
 }
 tilemap_set_scrollx(bg_tilemap, 0, ((highbits << 6) & 0x100) + bg_scrollx + xoffs );
 tilemap_set_scrolly(bg_tilemap, 0, ((highbits << 5) & 0x100) + bg_scrolly + yoffs );
 tilemap_set_scrollx(fg_tilemap, 0, ((highbits << 8) & 0x100) + fg_scrollx + xoffs );
 tilemap_set_scrolly(fg_tilemap, 0, ((highbits << 7) & 0x100) + fg_scrolly + yoffs );
}

canonical_original_code:
void airbustr_scrollregs_w(unsigned int offset, unsigned int data)
{
static int bg_scrollx; static int bg_scrolly; static int fg_scrollx; static int fg_scrolly; static int highbits;
int xoffs; int yoffs;
 if (flipscreen) { xoffs = -0x06a; yoffs = -0x1ff;}
 else { xoffs = -0x094; yoffs = -0x100;}
 switch (offset)
 {
  case 0x00: fg_scrolly = data; break;
  case 0x02: fg_scrollx = data; break;
  case 0x04: bg_scrolly = data; break;
  case 0x06: bg_scrollx = data; break;
  case 0x08: highbits = ~data; break;
  default:
      break;
 }
 tilemap_set_scrollx(bg_tilemap, 0, ((highbits << 6) & 0x100) + bg_scrollx + xoffs );
 tilemap_set_scrolly(bg_tilemap, 0, ((highbits << 5) & 0x100) + bg_scrolly + yoffs );
 tilemap_set_scrollx(fg_tilemap, 0, ((highbits << 8) & 0x100) + fg_scrollx + xoffs );
 tilemap_set_scrolly(fg_tilemap, 0, ((highbits << 7) & 0x100) + fg_scrolly + yoffs );
}

variable_types: highbits int

variable_types: xoffs int

variable_types: yoffs int


decompiled_code:
__int64 __fastcall airbustr_vh_screenrefresh(__int64 a1)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rdi
unsigned __int8 v4; // al
__int64 v5; // rax
unsigned __int8 *v6; // rdx
__int64 v7; // rdi
unsigned __int8 v8; // al
__int64 v9; // rax

tilemap_update(0LL);
palette_init_used_colors();
v2 = (unsigned __int8 *)(spriteram + 768LL);
v3 = spriteram + 1024LL;
do
{
v4 = *v2++;
v5 = palette_used_colors + (v4 & 0xF0) + 513LL;
*(_QWORD *)v5 = 0x303030303030303LL;
*(_DWORD *)(v5 + 8) = 50529027;
*(_WORD *)(v5 + 12) = 771;
*(_BYTE *)(v5 + 14) = 3;
}
while ( (unsigned __int8 *)v3 != v2 );
v6 = (unsigned __int8 *)(spriteram + 2816LL);
v7 = spriteram + 3072LL;
do
{
v8 = *v6++;
v9 = palette_used_colors + (v8 & 0xF0) + 513LL;
*(_QWORD *)v9 = 0x303030303030303LL;
*(_DWORD *)(v9 + 8) = 50529027;
*(_WORD *)(v9 + 12) = 771;
*(_BYTE *)(v9 + 14) = 3;
}
while ( (unsigned __int8 *)v7 != v6 );
if ( palette_recalc(v7, 771LL, v6, &palette_used_colors, 0x303030303030303LL) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
return draw_sprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned __int8 *v2; // rdx
__int64 v3; // rdi
unsigned __int8 v4; // al
__int64 v5; // rax
unsigned __int8 *v6; // rdx
__int64 v7; // rdi
unsigned __int8 v8; // al
__int64 v9; // rax

tilemap_update(0LL);
palette_init_used_colors();
v2 = (unsigned __int8 *)(spriteram + 768LL);
v3 = spriteram + 1024LL;
do
{
v4 = *v2++;
v5 = palette_used_colors + (v4 & 0xF0) + 513LL;
*(_QWORD *)v5 = 0x303030303030303LL;
*(_DWORD *)(v5 + 8) = 50529027;
*(_WORD *)(v5 + 12) = 771;
*(_BYTE *)(v5 + 14) = 3;
}
while ( (unsigned __int8 *)v3 != v2 );
v6 = (unsigned __int8 *)(spriteram + 2816LL);
v7 = spriteram + 3072LL;
do
{
v8 = *v6++;
v9 = palette_used_colors + (v8 & 0xF0) + 513LL;
*(_QWORD *)v9 = 0x303030303030303LL;
*(_DWORD *)(v9 + 8) = 50529027;
*(_WORD *)(v9 + 12) = 771;
*(_BYTE *)(v9 + 14) = 3;
}
while ( (unsigned __int8 *)v7 != v6 );
if ( palette_recalc(v7, 771LL, v6, &palette_used_colors, 0x303030303030303LL) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
return func10(a1);
}

original_code:
void airbustr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
unsigned char *ram;
int i, offs;
 tilemap_update(0);
 palette_init_used_colors();
 for (i = 0 ; i < 2 ; i++)
 {
  ram = &spriteram[i * 0x800 + 0x300];
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int color = 256 * 2 + (ram[offs] & 0xf0);
   memset(&palette_used_colors[color+1],(1|2),16-1);
  }
 }
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 draw_sprites(bitmap);
}

canonical_original_code:
void airbustr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
unsigned char *ram;
int i; int offs;
 tilemap_update(0);
 palette_init_used_colors();
 for (i = 0 ; i < 2 ; i++)
 {
  ram = &spriteram[i * 0x800 + 0x300];
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int color = 256 * 2 + (ram[offs] & 0xf0);
   memset(&palette_used_colors[color+1],(1|2),16-1);
  }
 }
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 draw_sprites(bitmap);
}

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

variable_types:
ram
unsigned char *

variable_types: i int

variable_types: offs int

variable_types: color int


decompiled_code:
int __fastcall devram_r(unsigned int a1)
{
int result; // eax
__int16 v2; // cx

if ( a1 > 0xFF3 )
{
if ( a1 == 4084 )
return rand();
return *(unsigned __int8 *)(devram + a1);
}
if ( a1 <= 0xFF1 )
{
result = 0;
if ( a1 == 4064 )
return result;
return *(unsigned __int8 *)(devram + a1);
}
v2 = *(unsigned __int8 *)(devram + 4082LL);
result = (unsigned __int8)((unsigned __int16)((v2 + (*(unsigned __int8 *)(devram + 4083LL) << 8))
* (*(unsigned __int8 *)(devram + 4080LL)
+ (*(unsigned __int8 *)(devram + 4081LL) << 8))) >> 8);
if ( a1 == 4082 )
result = (unsigned __int8)(v2 * *(_BYTE *)(devram + 4080LL));
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1)
{
int result; // eax
__int16 v2; // cx

if ( a1 > 0xFF3 )
{
if ( a1 == 4084 )
return rand();
return *(unsigned __int8 *)(devram + a1);
}
if ( a1 <= 0xFF1 )
{
result = 0;
if ( a1 == 4064 )
return result;
return *(unsigned __int8 *)(devram + a1);
}
v2 = *(unsigned __int8 *)(devram + 4082LL);
result = (unsigned __int8)((unsigned __int16)((v2 + (*(unsigned __int8 *)(devram + 4083LL) << 8))
* (*(unsigned __int8 *)(devram + 4080LL)
+ (*(unsigned __int8 *)(devram + 4081LL) << 8))) >> 8);
if ( a1 == 4082 )
result = (unsigned __int8)(v2 * *(_BYTE *)(devram + 4080LL));
return result;
}

original_code:
data_t devram_r(offs_t offset)
{
 switch (offset)
 {
  case 0xfe0:
   return 0 ;
   break;
  case 0xff2:
  case 0xff3:
  {
   int x = (devram[0xff0] + devram[0xff1] * 256) *
     (devram[0xff2] + devram[0xff3] * 256);
   if (offset == 0xff2) return (x & 0x00FF) >> 0;
   else return (x & 0xFF00) >> 8;
  } break;
  case 0xff4:
  {
   return rand();
  } break;
  default: { return devram[offset]; break;}
 }
}

canonical_original_code:
unsigned int devram_r(unsigned int offset)
{
 switch (offset)
 {
  case 0xfe0:
   return 0 ;
   break;
  case 0xff2:
  case 0xff3:
  {
   int x = (devram[0xff0] + devram[0xff1] * 256) *
     (devram[0xff2] + devram[0xff3] * 256);
   if (offset == 0xff2) return (x & 0x00FF) >> 0;
   else return (x & 0xFF00) >> 8;
  } break;
  case 0xff4:
  {
   return rand();
  } break;
  default: { return devram[offset]; break;}
 }
}

variable_types:
offset
unsigned int

variable_types: x int


decompiled_code:
__int64 __fastcall airbustr_paletteram_w(unsigned int a1, char a2)
{
int v2; // edx
unsigned int v3; // esi
unsigned int v4; // eax
unsigned int v5; // esi
unsigned int v6; // ecx
unsigned int v7; // edx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFFFFFFE));
v3 = *(unsigned __int8 *)(paletteram + (a1 | 1)) << 8;
v4 = v3 >> 10;
v5 = v2 | v3;
v6 = 255 * (v2 & 0x1F);
v7 = 255 * (v4 & 0x1F);
return palette_change_color(a1 >> 1, 255 * ((v5 >> 5) & 0x1F) / 0x1F, v7 / 0x1F, v6 / 0x1F);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, char a2)
{
int v2; // edx
unsigned int v3; // esi
unsigned int v4; // eax
unsigned int v5; // esi
unsigned int v6; // ecx
unsigned int v7; // edx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFFFFFFE));
v3 = *(unsigned __int8 *)(paletteram + (a1 | 1)) << 8;
v4 = v3 >> 10;
v5 = v2 | v3;
v6 = 255 * (v2 & 0x1F);
v7 = 255 * (v4 & 0x1F);
return palette_change_color(a1 >> 1, 255 * ((v5 >> 5) & 0x1F) / 0x1F, v7 / 0x1F, v6 / 0x1F);
}

original_code:
void airbustr_paletteram_w(offs_t offset,data_t data)
{
int r,g,b;
 paletteram[offset] = data;
 data = (paletteram[offset | 1] << 8) | paletteram[offset & ~1];
 g = (data >> 10) & 0x1f;
 r = (data >> 5) & 0x1f;
 b = (data >> 0) & 0x1f;
 palette_change_color(offset/2, (r * 0xff) / 0x1f,
         (g * 0xff) / 0x1f,
         (b * 0xff) / 0x1f );
}

canonical_original_code:
void airbustr_paletteram_w(unsigned int offset, unsigned int data)
{
int r; int g; int b;
 paletteram[offset] = data;
 data = (paletteram[offset | 1] << 8) | paletteram[offset & ~1];
 g = (data >> 10) & 0x1f;
 r = (data >> 5) & 0x1f;
 b = (data >> 0) & 0x1f;
 palette_change_color(offset/2, (r * 0xff) / 0x1f,
         (g * 0xff) / 0x1f,
         (b * 0xff) / 0x1f );
}

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 soundcommand_r()
{
soundlatch_status = 0;
return soundlatch_r(0LL);
}

canonical_decompiled_code:
__int64 func14()
{
soundlatch_status = 0;
return soundlatch_r(0LL);
}

original_code:
data_t soundcommand_r(offs_t offset)
{
 soundlatch_status = 0;
 return soundlatch_r(0);
}

canonical_original_code:
unsigned int soundcommand_r(unsigned int offset)
{
 soundlatch_status = 0;
 return soundlatch_r(0);
}


decompiled_code:
__int64 soundcommand2_w()
{
soundlatch2_status = 1;
return soundlatch2_w(0LL);
}

canonical_decompiled_code:
__int64 func15()
{
soundlatch2_status = 1;
return soundlatch2_w(0LL);
}

original_code:
void soundcommand2_w(offs_t offset,data_t data)
{
 soundlatch2_status = 1;
 soundlatch2_w(0,data);
}

canonical_original_code:
void soundcommand2_w(unsigned int offset, unsigned int data)
{
 soundlatch2_status = 1;
 soundlatch2_w(0,data);
}


decompiled_code:
__int64 init_airbustr()
{
_BYTE *v0; // rax
_BYTE *v1; // rdx
__int64 result; // rax

v0 = (_BYTE *)memory_region(137LL);
v1 = v0 + 0x80000;
do
{
*v0 = __ROL1__(*v0, 4);
++v0;
}
while ( v1 != v0 );
*(_WORD *)(memory_region(129LL) + 14324) = 0;
result = memory_region(130LL);
*(_BYTE *)(result + 600) = 83;
return result;
}

canonical_decompiled_code:
__int64 func16()
{
_BYTE *v0; // rax
_BYTE *v1; // rdx
__int64 result; // rax

v0 = (_BYTE *)memory_region(137LL);
v1 = v0 + 0x80000;
do
{
*v0 = __ROL1__(*v0, 4);
++v0;
}
while ( v1 != v0 );
*(_WORD *)(memory_region(129LL) + 14324) = 0;
result = memory_region(130LL);
*(_BYTE *)(result + 600) = 83;
return result;
}

original_code:
void init_airbustr(void)
{
int i;
unsigned char *RAM;
 RAM = memory_region(REGION_GFX1) + 0x000000;
 for (i = 0; i < 0x80000; i ++)
 {
  RAM[i] = ((RAM[i] & 0xF0)>>4) + ((RAM[i] & 0x0F)<<4);
 }
 RAM = memory_region(REGION_CPU1);
 RAM[0x37f4] = 0x00; RAM[0x37f5] = 0x00;
 RAM = memory_region(REGION_CPU2);
 RAM[0x0258] = 0x53;
}

canonical_original_code:
void init_airbustr()
{
int i;
unsigned char *RAM;
 RAM = memory_region(REGION_GFX1) + 0x000000;
 for (i = 0; i < 0x80000; i ++)
 {
  RAM[i] = ((RAM[i] & 0xF0)>>4) + ((RAM[i] & 0x0F)<<4);
 }
 RAM = memory_region(REGION_CPU1);
 RAM[0x37f4] = 0x00; RAM[0x37f5] = 0x00;
 RAM = memory_region(REGION_CPU2);
 RAM[0x0258] = 0x53;
}

variable_types:
RAM
unsigned char *


decompiled_code:
_DWORD *airbustr_init_machine()
{
soundlatch2_status = 0;
soundlatch_status = 0;
bankswitch_w(0LL, 2);
bankswitch2_w(0LL, 2);
return sound_bankswitch_w(0LL, 2);
}

canonical_decompiled_code:
_DWORD *func17()
{
soundlatch2_status = 0;
soundlatch_status = 0;
bankswitch_w(0LL, 2);
bankswitch2_w(0LL, 2);
return sound_bankswitch_w(0LL, 2);
}

original_code:
static void airbustr_init_machine (void)
{
 soundlatch_status = soundlatch2_status = 0;
 bankswitch_w(0,2);
 bankswitch2_w(0,2);
 sound_bankswitch_w(0,2);
}

canonical_original_code:
static void airbustr_init_machine()
{
 soundlatch_status = soundlatch2_status = 0;
 bankswitch_w(0,2);
 bankswitch2_w(0,2);
 sound_bankswitch_w(0,2);
}


decompiled_code:
__int64 cause_nmi_w()
{
return cpu_cause_interrupt(1LL, 4294967294LL);
}

canonical_decompiled_code:
__int64 func19()
{
return cpu_cause_interrupt(1LL, 4294967294LL);
}

original_code:
static void cause_nmi_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(1,-2);
}

canonical_original_code:
static void cause_nmi_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(1,-2);
}


decompiled_code:
__int64 soundcommand2_r()
{
soundlatch2_status = 0;
return soundlatch2_r(0LL);
}

canonical_decompiled_code:
__int64 func20()
{
soundlatch2_status = 0;
return soundlatch2_r(0LL);
}

original_code:
static data_t soundcommand2_r(offs_t offset)
{
 soundlatch2_status = 0;
 return soundlatch2_r(0);
}

canonical_original_code:
static unsigned int soundcommand2_r(unsigned int offset)
{
 soundlatch2_status = 0;
 return soundlatch2_r(0);
}


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

v1 = *(unsigned __int8 *)(airbustr_fgram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(airbustr_fgram + a1) + ((v1 << 8) & 0xF00u)) % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * ((unsigned __int8)v1 >> 4);
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)
{
__int16 v1; // cx
__int64 v2; // rsi
unsigned int v3; // edx
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(airbustr_fgram + a1 + 1024LL);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(airbustr_fgram + a1) + ((v1 << 8) & 0xF00u)) % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * ((unsigned __int8)v1 >> 4);
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)
{
 unsigned char attr = airbustr_fgram[tile_index + 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_fgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_fgram[tile_index + 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_fgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types:
attr
unsigned char

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


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

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

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

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

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_bgram[tile_index + 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_bgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = airbustr_bgram[tile_index + 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (airbustr_bgram[tile_index] + ((attr & 0x0f) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 4) + 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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


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

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

original_code: static data_t sharedram_r(offs_t offset) { return sharedram[offset]; }

canonical_original_code: static unsigned int sharedram_r(unsigned int offset) { return sharedram[offset]; }


original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
int i, offs;
 for (i = 0 ; i < 2 ; i++)
 {
  unsigned char *ram = &spriteram[i * 0x800];
  int sx = 0;
  int sy = 0;
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int attr = ram[offs + 0x300];
   int x = ram[offs + 0x400] - ((attr << 8) & 0x100);
   int y = ram[offs + 0x500] - ((attr << 7) & 0x100);
   int gfx = ram[offs + 0x700];
   int code = ram[offs + 0x600] + ((gfx & 0x1f) << 8);
   int flipx = gfx & 0x80;
   int flipy = gfx & 0x40;
   if (attr & 0x04) { sx += x; sy += y;}
   else { sx = x; sy = y;}
   if (flipscreen)
   {
    sx = 240 - sx; sy = 240 - sy;
    flipx = !flipx; flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,
     attr >> 4,
     flipx, flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (flipscreen) {sx = 240 - sx; sy = 240 - sy;}
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
int i; int offs;
 for (i = 0 ; i < 2 ; i++)
 {
  unsigned char *ram = &spriteram[i * 0x800];
  int sx = 0;
  int sy = 0;
  for ( offs = 0 ; offs < 0x100 ; offs++)
  {
   int attr = ram[offs + 0x300];
   int x = ram[offs + 0x400] - ((attr << 8) & 0x100);
   int y = ram[offs + 0x500] - ((attr << 7) & 0x100);
   int gfx = ram[offs + 0x700];
   int code = ram[offs + 0x600] + ((gfx & 0x1f) << 8);
   int flipx = gfx & 0x80;
   int flipy = gfx & 0x40;
   if (attr & 0x04) { sx += x; sy += y;}
   else { sx = x; sy = y;}
   if (flipscreen)
   {
    sx = 240 - sx; sy = 240 - sy;
    flipx = !flipx; flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,
     attr >> 4,
     flipx, flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (flipscreen) {sx = 240 - sx; sy = 240 - sy;}
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: attr int

variable_types: y int

variable_types: gfx int

variable_types: code int

variable_types: flipx int

variable_types: flipy int

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


decompiled_code:
__int64 soundcommand_w()
{
soundlatch_w(0LL);
soundlatch_status = 1;
return cpu_cause_interrupt(2LL, 4294967294LL);
}

canonical_decompiled_code:
__int64 func18()
{
soundlatch_w(0LL);
soundlatch_status = 1;
return cpu_cause_interrupt(2LL, 4294967294LL);
}

original_code:
static void soundcommand_w(offs_t offset,data_t data)
{
 soundlatch_w(0,data);
 soundlatch_status = 1;
 cpu_cause_interrupt(2,-2);
}

canonical_original_code:
static void soundcommand_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(0,data);
 soundlatch_status = 1;
 cpu_cause_interrupt(2,-2);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall ddrible_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v4; // ecx
__int64 v5; // rdi

result = a2;
v4 = *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 24LL);
if ( v4 > 0 )
{
v5 = a2 + 2LL * *(int *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
for ( result = 0LL; result != v4; ++result )
*(_WORD *)(v5 + 2 * result) = *(_BYTE *)(a3 + result) & 0xF;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v4; // ecx
__int64 v5; // rdi

result = a2;
v4 = *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 536LL) + 24LL);
if ( v4 > 0 )
{
v5 = a2 + 2LL * *(int *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
for ( result = 0LL; result != v4; ++result )
*(_WORD *)(v5 + 2 * result) = *(_BYTE *)(a3 + result) & 0xF;
}
return result;
}

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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


original_code:
static UINT32 tilemap_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 6);
}

canonical_original_code:
static unsigned int tilemap_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 6);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


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

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

original_code:
static data_t ddrible_sharedram_r(offs_t offset)
{
 return ddrible_sharedram[offset];
}

canonical_original_code:
static unsigned int ddrible_sharedram_r(unsigned int offset)
{
 return ddrible_sharedram[offset];
}


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

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

original_code:
static data_t ddrible_snd_sharedram_r(offs_t offset)
{
 return ddrible_snd_sharedram[offset];
}

canonical_original_code:
static unsigned int ddrible_snd_sharedram_r(unsigned int offset)
{
 return ddrible_snd_sharedram[offset];
}


decompiled_code:
int *__fastcall K005885_0_w(int a1, int a2)
{
int *result; // rax
int v3; // esi

if ( a1 == 3 )
{
v3 = a2 & 2;
if ( v3 != dword_13AC )
{
dword_13AC = v3;
result = (int *)tilemap_mark_all_tiles_dirty(fg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_0;
dword_13B0 = a2;
ddrible_int_enable_0 = a2 & 2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1] = a2;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func8(int a1, int a2)
{
int *result; // rax
int v3; // esi

if ( a1 == 3 )
{
v3 = a2 & 2;
if ( v3 != dword_13AC )
{
dword_13AC = v3;
result = (int *)tilemap_mark_all_tiles_dirty(fg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_0;
dword_13B0 = a2;
ddrible_int_enable_0 = a2 & 2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1] = a2;
}
return result;
}

original_code:
void K005885_0_w(offs_t offset,data_t data)
{
 switch (offset){
  case 0x03:
   if ((data & 0x02) != ddribble_vregs[0][3]){
    ddribble_vregs[0][3] = (data & 0x02);
    tilemap_mark_all_tiles_dirty( fg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_0 = data & 0x02;
   ddribble_vregs[0][4] = data;
   break;
  default:
   ddribble_vregs[0][offset] = data;
 }
}

canonical_original_code:
void K005885_0_w(unsigned int offset, unsigned int data)
{
 switch (offset){
  case 0x03:
   if ((data & 0x02) != ddribble_vregs[0][3]){
    ddribble_vregs[0][3] = (data & 0x02);
    tilemap_mark_all_tiles_dirty( fg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_0 = data & 0x02;
   ddribble_vregs[0][4] = data;
   break;
  default:
   ddribble_vregs[0][offset] = data;
 }
}

variable_types:
data
unsigned int


decompiled_code:
int *__fastcall K005885_1_w(int a1, int a2)
{
int *result; // rax
int v3; // esi

if ( a1 == 3 )
{
v3 = (2 * (_BYTE)a2) & 6;
if ( v3 != dword_13C0 )
{
dword_13C0 = v3;
result = (int *)tilemap_mark_all_tiles_dirty(bg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_1;
dword_13C4 = a2;
ddrible_int_enable_1 = a2 & 2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1 + 5] = a2;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func9(int a1, int a2)
{
int *result; // rax
int v3; // esi

if ( a1 == 3 )
{
v3 = (2 * (_BYTE)a2) & 6;
if ( v3 != dword_13C0 )
{
dword_13C0 = v3;
result = (int *)tilemap_mark_all_tiles_dirty(bg_tilemap);
}
}
else if ( a1 == 4 )
{
result = &ddrible_int_enable_1;
dword_13C4 = a2;
ddrible_int_enable_1 = a2 & 2;
}
else
{
result = ddribble_vregs;
ddribble_vregs[a1 + 5] = a2;
}
return result;
}

original_code:
void K005885_1_w(offs_t offset,data_t data)
{
 switch (offset){
  case 0x03:
   if (((data & 0x03) << 1) != ddribble_vregs[1][3]){
    ddribble_vregs[1][3] = (data & 0x03) << 1;
    tilemap_mark_all_tiles_dirty( bg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_1 = data & 0x02;
   ddribble_vregs[1][4] = data;
   break;
  default:
   ddribble_vregs[1][offset] = data;
 }
}

canonical_original_code:
void K005885_1_w(unsigned int offset, unsigned int data)
{
 switch (offset){
  case 0x03:
   if (((data & 0x03) << 1) != ddribble_vregs[1][3]){
    ddribble_vregs[1][3] = (data & 0x03) << 1;
    tilemap_mark_all_tiles_dirty( bg_tilemap );
   }
   break;
  case 0x04:
   ddrible_int_enable_1 = data & 0x02;
   ddribble_vregs[1][4] = data;
   break;
  default:
   ddribble_vregs[1][offset] = data;
 }
}


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

v0 = tilemap_create(get_fg_tile_info, tilemap_scan, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = v0;
bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan, 0LL, 8LL, 8LL, 64LL, v2);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

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

v0 = tilemap_create(get_fg_tile_info, tilemap_scan, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = v0;
bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan, 0LL, 8LL, 8LL, 64LL, v2);
if ( !bg_tilemap || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 0;
return 0LL;
}

original_code:
int ddrible_vh_start ( void )
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan,0x00, 8,8,64,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int ddrible_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan,0x00, 8,8,64,32);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 return 0;
}