decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
__int64 result; // rax

v2 = a2;
do
{
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v2[2],
v2[3] & 0xF,
((v2[3] >> 6) ^ 1) & 1,
(v2[3] & 0x80u) == 0,
v2[1],
240 - (unsigned int)*v2,
Machine + 776LL,
6LL,
0LL);
v2 += 4;
}
while ( v2 != a2 + 256 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
__int64 result; // rax

v2 = a2;
do
{
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v2[2],
v2[3] & 0xF,
((v2[3] >> 6) ^ 1) & 1,
(v2[3] & 0x80u) == 0,
v2[1],
240 - (unsigned int)*v2,
Machine + 776LL,
6LL,
0LL);
v2 += 4;
}
while ( v2 != a2 + 256 );
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap, unsigned char* sr)
{
 int offs;
 for (offs = 0; offs < 0x100; offs += 4)
 {
  int sx = sr[offs + 1];
  int sy = 240 - sr[offs];
  int nflipx = sr[offs + 3] & 0x40;
  int nflipy = sr[offs + 3] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
   sr[offs + 2],
   sr[offs + 3] & 0x0f,
   !nflipx,!nflipy,
   sx,sy,
   &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap, unsigned char *sr)
{
 int offs;
 for (offs = 0; offs < 0x100; offs += 4)
 {
  int sx = sr[offs + 1];
  int sy = 240 - sr[offs];
  int nflipx = sr[offs + 3] & 0x40;
  int nflipy = sr[offs + 3] & 0x80;
  drawgfx(bitmap,Machine->gfx[1],
   sr[offs + 2],
   sr[offs + 3] & 0x0f,
   !nflipx,!nflipy,
   sx,sy,
   &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

variable_types:
sr
unsigned char *

variable_types: offs int

variable_types: nflipx int

variable_types: nflipy int


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

result = a2 == 0;
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 == 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = a2 == 0;
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 == 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

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

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

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


decompiled_code:
void *__fastcall zodiack_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v2; // rbx
int v3; // edi
int v4; // er10
unsigned __int64 v5; // rbx
int v6; // edi
int v7; // esi
unsigned __int8 *v8; // rdx
char *v9; // rax
int *v10; // rcx
unsigned __int64 v11; // rbx
__int64 v12; // rcx
__int64 i; // rax
__int64 v14; // rcx
void *result; // rax
int v16; // er12
__int64 v17; // rbx
__int64 v18; // r9
__int64 v19; // rsi
int v20[31]; // [rsp+0h] [rbp-A8h] BYREF
char v21; // [rsp+7Ch] [rbp-2Ch] BYREF

if ( videoram_size )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v3 = (int)v2 / 32;
v4 = (int)v2 % 32;
if ( flipscreen )
{
v4 = 31 - (int)v2 % 32;
v3 = 31 - (int)v2 / 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 536LL),
*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(galaxian_attributesram + 2 * ((int)v2 % 32) + 1) & 7,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v4),
(unsigned int)(8 * v3),
0LL,
0LL,
0LL);
}
++v2;
}
while ( videoram_size > v2 );
if ( videoram_size )
{
v5 = 0LL;
do
{
v6 = (int)v5 / 32;
v7 = (int)v5 % 32;
if ( flipscreen )
{
v6 = 31 - (int)v5 / 32;
v7 = 31 - (int)v5 % 32;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(zodiack_videoram2 + v5),
(*(_BYTE *)(galaxian_attributesram + 2 * ((int)v5 % 32) + 1) >> 4) & 7,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v7),
(unsigned int)(8 * v6),
Machine + 776LL,
0LL,
0LL);
++v5;
}
while ( videoram_size > v5 );
}
}
if ( flipscreen )
{
v8 = (unsigned __int8 *)galaxian_attributesram;
v9 = &v21;
do
{
*(_DWORD *)v9 = *v8;
v8 += 2;
v10 = (int *)v9;
v9 -= 4;
}
while ( v10 != v20 );
}
else
{
v12 = galaxian_attributesram;
for ( i = 0LL; i != 32; ++i )
v20[i] = -*(unsigned __int8 *)(v12 + 2 * i);
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v20, Machine + 776LL, 6LL, 0LL);
if ( galaxian_bulletsram_size )
{
v11 = 0LL;
do
{
v14 = *(unsigned __int8 *)(galaxian_bulletsram + v11 + 1);
if ( !percuss_hardware )
v14 = (unsigned int)(255 - v14);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
*(unsigned __int8 *)(galaxian_bulletsram + v11 + 3)
+ (unsigned int)**(unsigned __int16 **)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 56LL),
v14,
Machine + 776LL,
2LL,
0LL);
v11 += 4LL;
}
while ( galaxian_bulletsram_size > v11 );
}
result = &spriteram_size;
v16 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v17 = v16 + 3LL;
do
{
v19 = *(unsigned __int8 *)(spriteram + v17 - 3);
v18 = *(_BYTE *)(spriteram + v17 - 2) & 0x80;
if ( percuss_hardware )
v18 = (_DWORD)v18 == 0;
else
v19 = (unsigned int)(240 - v19);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + v17 - 2) & 0x3F,
*(_BYTE *)(spriteram + v17 - 1) & 7,
((*(_BYTE *)(spriteram + v17 - 2) >> 6) ^ 1) & 1,
v18,
240 - (unsigned int)*(unsigned __int8 *)(spriteram + v17),
v19,
Machine + 776LL,
2LL,
0LL);
v17 -= 4LL;
v16 -= 4;
}
while ( v16 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
unsigned __int64 v2; // rbx
int v3; // edi
int v4; // er10
unsigned __int64 v5; // rbx
int v6; // edi
int v7; // esi
unsigned __int8 *v8; // rdx
char *v9; // rax
int *v10; // rcx
unsigned __int64 v11; // rbx
__int64 v12; // rcx
__int64 i; // rax
__int64 v14; // rcx
void *result; // rax
int v16; // er12
__int64 v17; // rbx
__int64 v18; // r9
__int64 v19; // rsi
int v20[31]; // [rsp+0h] [rbp-A8h] BYREF
char v21; // [rsp+7Ch] [rbp-2Ch] BYREF

if ( videoram_size )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v3 = (int)v2 / 32;
v4 = (int)v2 % 32;
if ( flipscreen )
{
v4 = 31 - (int)v2 % 32;
v3 = 31 - (int)v2 / 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 536LL),
*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(galaxian_attributesram + 2 * ((int)v2 % 32) + 1) & 7,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v4),
(unsigned int)(8 * v3),
0LL,
0LL,
0LL);
}
++v2;
}
while ( videoram_size > v2 );
if ( videoram_size )
{
v5 = 0LL;
do
{
v6 = (int)v5 / 32;
v7 = (int)v5 % 32;
if ( flipscreen )
{
v6 = 31 - (int)v5 / 32;
v7 = 31 - (int)v5 % 32;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(zodiack_videoram2 + v5),
(*(_BYTE *)(galaxian_attributesram + 2 * ((int)v5 % 32) + 1) >> 4) & 7,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v7),
(unsigned int)(8 * v6),
Machine + 776LL,
0LL,
0LL);
++v5;
}
while ( videoram_size > v5 );
}
}
if ( flipscreen )
{
v8 = (unsigned __int8 *)galaxian_attributesram;
v9 = &v21;
do
{
*(_DWORD *)v9 = *v8;
v8 += 2;
v10 = (int *)v9;
v9 -= 4;
}
while ( v10 != v20 );
}
else
{
v12 = galaxian_attributesram;
for ( i = 0LL; i != 32; ++i )
v20[i] = -*(unsigned __int8 *)(v12 + 2 * i);
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 32LL, v20, Machine + 776LL, 6LL, 0LL);
if ( galaxian_bulletsram_size )
{
v11 = 0LL;
do
{
v14 = *(unsigned __int8 *)(galaxian_bulletsram + v11 + 1);
if ( !percuss_hardware )
v14 = (unsigned int)(255 - v14);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
0LL,
0LL,
0LL,
*(unsigned __int8 *)(galaxian_bulletsram + v11 + 3)
+ (unsigned int)**(unsigned __int16 **)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 56LL),
v14,
Machine + 776LL,
2LL,
0LL);
v11 += 4LL;
}
while ( galaxian_bulletsram_size > v11 );
}
result = &spriteram_size;
v16 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v17 = v16 + 3LL;
do
{
v19 = *(unsigned __int8 *)(spriteram + v17 - 3);
v18 = *(_BYTE *)(spriteram + v17 - 2) & 0x80;
if ( percuss_hardware )
v18 = (_DWORD)v18 == 0;
else
v19 = (unsigned int)(240 - v19);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + v17 - 2) & 0x3F,
*(_BYTE *)(spriteram + v17 - 1) & 7,
((*(_BYTE *)(spriteram + v17 - 2) >> 6) ^ 1) & 1,
v18,
240 - (unsigned int)*(unsigned __int8 *)(spriteram + v17),
v19,
Machine + 776LL,
2LL,
0LL);
v17 -= 4LL;
v16 -= 4;
}
while ( v16 >= 0 );
}
return result;
}

original_code:
void zodiack_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code,sx,sy,col;
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  sy = offs / 32;
  sx = offs % 32;
  col = galaxian_attributesram[2 * sx + 1] & 0x07;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  code = videoram[offs];
  drawgfx(tmpbitmap,Machine->gfx[3],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    0,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code,sx,sy,col;
  sy = offs / 32;
  sx = offs % 32;
  col = (galaxian_attributesram[2 * sx + 1] >> 4) & 0x07;
  if (flipscreen)
  {
   sy = 31 - sy;
   sx = 31 - sx;
  }
  code = zodiack_videoram2[offs];
  drawgfx(bitmap,Machine->gfx[0],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  int i, scroll[32];
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = galaxian_attributesram[2 * i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -galaxian_attributesram[2 * i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 for (offs = 0;offs < galaxian_bulletsram_size;offs += 4)
 {
  int x,y;
  x = galaxian_bulletsram[offs + 3] + Machine->drv->gfxdecodeinfo[2].gfxlayout->width;
  y = galaxian_bulletsram[offs + 1];
  if (!percuss_hardware)
  {
   y = 255 - y;
  }
  drawgfx(bitmap,Machine->gfx[2],
    0,
    0,
    0,0,
    x,y,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int flipx,flipy,sx,sy,spritecode;
  sx = 240 - spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = !(spriteram[offs + 1] & 0x40);
  flipy = spriteram[offs + 1] & 0x80;
  spritecode = spriteram[offs + 1] & 0x3f;
  if (percuss_hardware)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spritecode,
    spriteram[offs + 2] & 0x07,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void zodiack_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code; int sx; int sy; int col;
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  sy = offs / 32;
  sx = offs % 32;
  col = galaxian_attributesram[2 * sx + 1] & 0x07;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  code = videoram[offs];
  drawgfx(tmpbitmap,Machine->gfx[3],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    0,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  int code; int sx; int sy; int col;
  sy = offs / 32;
  sx = offs % 32;
  col = (galaxian_attributesram[2 * sx + 1] >> 4) & 0x07;
  if (flipscreen)
  {
   sy = 31 - sy;
   sx = 31 - sx;
  }
  code = zodiack_videoram2[offs];
  drawgfx(bitmap,Machine->gfx[0],
    code,
    col,
    flipscreen, flipscreen,
    8*sx, 8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  int i; int scroll[32];
  if (flipscreen)
  {
   for (i = 0;i < 32;i++)
   {
    scroll[31-i] = galaxian_attributesram[2 * i];
   }
  }
  else
  {
   for (i = 0;i < 32;i++)
   {
    scroll[i] = -galaxian_attributesram[2 * i];
   }
  }
  copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
 for (offs = 0;offs < galaxian_bulletsram_size;offs += 4)
 {
  int x; int y;
  x = galaxian_bulletsram[offs + 3] + Machine->drv->gfxdecodeinfo[2].gfxlayout->width;
  y = galaxian_bulletsram[offs + 1];
  if (!percuss_hardware)
  {
   y = 255 - y;
  }
  drawgfx(bitmap,Machine->gfx[2],
    0,
    0,
    0,0,
    x,y,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int flipx; int flipy; int sx; int sy; int spritecode;
  sx = 240 - spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = !(spriteram[offs + 1] & 0x40);
  flipy = spriteram[offs + 1] & 0x80;
  spritecode = spriteram[offs + 1] & 0x3f;
  if (percuss_hardware)
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spritecode,
    spriteram[offs + 2] & 0x07,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: code int

variable_types: sx int

variable_types: sy int

variable_types: col int

variable_types: i int

variable_types:
scroll
int [32]

variable_types: x int

variable_types: y int

variable_types: flipx int

variable_types: flipy int

variable_types: spritecode int


decompiled_code:
__int64 zodiack_init_machine()
{
percuss_hardware = 0;
return espial_init_machine();
}

canonical_decompiled_code:
__int64 func4()
{
percuss_hardware = 0;
return espial_init_machine();
}

original_code:
static void zodiack_init_machine(void)
{
 percuss_hardware = 0;
 espial_init_machine();
}

canonical_original_code:
static void zodiack_init_machine()
{
 percuss_hardware = 0;
 espial_init_machine();
}


decompiled_code:
__int64 percuss_init_machine()
{
percuss_hardware = 1;
return espial_init_machine();
}

canonical_decompiled_code:
__int64 func5()
{
percuss_hardware = 1;
return espial_init_machine();
}

original_code:
static void percuss_init_machine(void)
{
 percuss_hardware = 1;
 espial_init_machine();
}

canonical_original_code:
static void percuss_init_machine()
{
 percuss_hardware = 1;
 espial_init_machine();
}


decompiled_code:
__int64 __fastcall timer_callback_2151(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2151TimerOver((unsigned __int8)v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2151TimerOver((unsigned __int8)v2);
}

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

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

variable_types: param int

variable_types: n int

variable_types: c int


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

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

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

variable_types: chip int


decompiled_code:
__int64 __fastcall YM2151_sh_start(__int64 a1)
{
return my_YM2151_sh_start(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func0(a1, 0);
}

original_code:
int YM2151_sh_start(const struct MachineSound *msound)
{
 return my_YM2151_sh_start(msound,0);
}

canonical_original_code:
int YM2151_sh_start(struct MachineSound *msound)
{
 return my_YM2151_sh_start(msound,0);
}

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

return_type: int


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

if ( FMMode == 4 )
result = OPMShutdown();
return result;
}

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

if ( FMMode == 4 )
result = OPMShutdown();
return result;
}

original_code:
void YM2151_sh_stop(void)
{
 switch(FMMode)
 {
 case 4:
  OPMShutdown();
  break;
 }
}

canonical_original_code:
void YM2151_sh_stop()
{
 switch(FMMode)
 {
 case 4:
  OPMShutdown();
  break;
 }
}


decompiled_code:
__int64 YM2151_sh_reset()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
if ( FMMode == 4 )
OPMResetChip(v1);
++v1;
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
if ( FMMode == 4 )
OPMResetChip(v1);
++v1;
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

original_code:
void YM2151_sh_reset(void)
{
 int i;
 for (i = 0;i < intf->num;i++)
 switch(FMMode)
 {
 case 4:
  OPMResetChip(i);
  break;
 }
}

canonical_original_code:
void YM2151_sh_reset()
{
 int i;
 for (i = 0;i < intf->num;i++)
 switch(FMMode)
 {
 case 4:
  OPMResetChip(i);
  break;
 }
}


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

result = 0LL;
if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(0LL, 1LL);
return result;
}

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

result = 0LL;
if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(0LL, 1LL);
return result;
}

original_code:
data_t YM2151_status_port_0_r(offs_t offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(0,1);
 }
 return 0;
}

canonical_original_code:
unsigned int YM2151_status_port_0_r(unsigned int offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(0,1);
 }
 return 0;
}

variable_types:
offset
unsigned int

return_type: unsigned int


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

result = 0LL;
if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(1LL, 1LL);
return result;
}

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

result = 0LL;
if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(1LL, 1LL);
return result;
}

original_code:
data_t YM2151_status_port_1_r(offs_t offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(1,1);
 }
 return 0;
}

canonical_original_code:
unsigned int YM2151_status_port_1_r(unsigned int offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(1,1);
 }
 return 0;
}


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

result = 0LL;
if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(2LL, 1LL);
return result;
}

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

result = 0LL;
if ( FMMode == 4 )
result = (unsigned __int8)YM2151Read(2LL, 1LL);
return result;
}

original_code:
data_t YM2151_status_port_2_r(offs_t offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(2,1);
 }
 return 0;
}

canonical_original_code:
unsigned int YM2151_status_port_2_r(unsigned int offset)
{
 switch(FMMode)
 {
 case 4:
  return YM2151Read(2,1);
 }
 return 0;
}


decompiled_code:
void __fastcall YM2151_register_port_0_w(__int64 a1, int a2)
{
lastreg0 = a2;
}

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

original_code:
void YM2151_register_port_0_w(offs_t offset,data_t data)
{
 lastreg0 = data;
}

canonical_original_code:
void YM2151_register_port_0_w(unsigned int offset, unsigned int data)
{
 lastreg0 = data;
}

variable_types:
data
unsigned int


decompiled_code:
void __fastcall YM2151_register_port_1_w(__int64 a1, int a2)
{
lastreg1 = a2;
}

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

original_code:
void YM2151_register_port_1_w(offs_t offset,data_t data)
{
 lastreg1 = data;
}

canonical_original_code:
void YM2151_register_port_1_w(unsigned int offset, unsigned int data)
{
 lastreg1 = data;
}


decompiled_code:
void __fastcall YM2151_register_port_2_w(__int64 a1, int a2)
{
lastreg2 = a2;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2)
{
lastreg2 = a2;
}

original_code:
void YM2151_register_port_2_w(offs_t offset,data_t data)
{
 lastreg2 = data;
}

canonical_original_code:
void YM2151_register_port_2_w(unsigned int offset, unsigned int data)
{
 lastreg2 = data;
}


decompiled_code:
__int64 __fastcall YM2151_data_port_0_w(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( FMMode == 4 )
{
YM2151Write(0LL, 0LL, (unsigned __int8)lastreg0);
result = YM2151Write(0LL, 1LL, a2);
}
return result;
}

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

if ( FMMode == 4 )
{
YM2151Write(0LL, 0LL, (unsigned __int8)lastreg0);
result = YM2151Write(0LL, 1LL, a2);
}
return result;
}

original_code:
void YM2151_data_port_0_w(offs_t offset,data_t data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(0,0,lastreg0);
  YM2151Write(0,1,data);
  break;
 }
}

canonical_original_code:
void YM2151_data_port_0_w(unsigned int offset, unsigned int data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(0,0,lastreg0);
  YM2151Write(0,1,data);
  break;
 }
}


decompiled_code:
__int64 __fastcall YM2151_data_port_1_w(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( FMMode == 4 )
{
YM2151Write(1LL, 0LL, (unsigned __int8)lastreg1);
result = YM2151Write(1LL, 1LL, a2);
}
return result;
}

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

if ( FMMode == 4 )
{
YM2151Write(1LL, 0LL, (unsigned __int8)lastreg1);
result = YM2151Write(1LL, 1LL, a2);
}
return result;
}

original_code:
void YM2151_data_port_1_w(offs_t offset,data_t data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(1,0,lastreg1);
  YM2151Write(1,1,data);
  break;
 }
}

canonical_original_code:
void YM2151_data_port_1_w(unsigned int offset, unsigned int data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(1,0,lastreg1);
  YM2151Write(1,1,data);
  break;
 }
}


decompiled_code:
__int64 __fastcall YM2151_data_port_2_w(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( FMMode == 4 )
{
YM2151Write(2LL, 0LL, (unsigned __int8)lastreg2);
result = YM2151Write(2LL, 1LL, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 a2)
{
__int64 result; // rax

if ( FMMode == 4 )
{
YM2151Write(2LL, 0LL, (unsigned __int8)lastreg2);
result = YM2151Write(2LL, 1LL, a2);
}
return result;
}

original_code:
void YM2151_data_port_2_w(offs_t offset,data_t data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(2,0,lastreg2);
  YM2151Write(2,1,data);
  break;
 }
}

canonical_original_code:
void YM2151_data_port_2_w(unsigned int offset, unsigned int data)
{
 switch(FMMode)
 {
 case 4:
  YM2151Write(2,0,lastreg2);
  YM2151Write(2,1,data);
  break;
 }
}


original_code:
static void K053157_get_char01_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000+2));
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x300) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

canonical_original_code:
static void K053157_get_char01_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0x2000+2));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x300) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

variable_types: attr int

variable_types: code int

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


original_code:
static void K053157_get_char11_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000+2));
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x700) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

canonical_original_code:
static void K053157_get_char11_tile_info(int tile_index)
{
 int attr = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000));
 int code = (*(UINT16 *)(K053157_rambase+4*tile_index+0xa000+2));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((attr + 0x700) & 0x7f0)>>4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 3);
}

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; }


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

original_code:
data_t K053157_r(offs_t offset)
{
 return 0;
}

canonical_original_code:
unsigned int K053157_r(unsigned int offset)
{
 return 0;
}


decompiled_code:
__int64 control2_r()
{
return (unsigned int)cur_control2;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)cur_control2;
}

original_code:
static data_t control2_r(offs_t offset)
{
 return cur_control2;
}

canonical_original_code:
static unsigned int control2_r(unsigned int offset)
{
 return cur_control2;
}


decompiled_code:
__int64 back_ctrla_r()
{
return (unsigned int)cur_back_ctrla;
}

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

original_code:
static data_t back_ctrla_r(offs_t offset)
{
 return cur_back_ctrla;
}

canonical_original_code:
static unsigned int back_ctrla_r(unsigned int offset)
{
 return cur_back_ctrla;
}


decompiled_code:
void __fastcall back_ctrla_w(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_ctrla != a2 )
cur_back_ctrla = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_ctrla != a2 )
cur_back_ctrla = a2;
}

original_code:
static void back_ctrla_w(offs_t offset,data_t data)
{
 data &= 0xff;
 if(data != cur_back_ctrla) {
  cur_back_ctrla = data;
 }
}

canonical_original_code:
static void back_ctrla_w(unsigned int offset, unsigned int data)
{
 data &= 0xff;
 if(data != cur_back_ctrla) {
  cur_back_ctrla = data;
 }
}


decompiled_code:
__int64 back_select_r()
{
return (unsigned int)cur_back_select;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)cur_back_select;
}

original_code:
static data_t back_select_r(offs_t offset)
{
 return cur_back_select;
}

canonical_original_code:
static unsigned int back_select_r(unsigned int offset)
{
 return cur_back_select;
}


decompiled_code:
void __fastcall back_select_w(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_select != a2 )
cur_back_select = a2;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, unsigned __int8 a2)
{
if ( cur_back_select != a2 )
cur_back_select = a2;
}

original_code:
static void back_select_w(offs_t offset,data_t data)
{
 data &= 0xff;
 if(data != cur_back_select) {
  cur_back_select = data;
 }
}

canonical_original_code:
static void back_select_w(unsigned int offset, unsigned int data)
{
 data &= 0xff;
 if(data != cur_back_select) {
  cur_back_select = data;
 }
}


decompiled_code:
void __fastcall K053157_w(int a1, unsigned int a2)
{
int v2; // edx
__int64 v3; // rax
int v4; // edx
int v5; // ecx
unsigned int v6; // eax

if ( a1 == 50 )
{
switch ( (char)a2 )
{
case 1:
v2 = 1;
break;
case 8:
v2 = 2;
break;
case 9:
v2 = 3;
break;
case 16:
v2 = 4;
break;
case 17:
v2 = 5;
break;
case 24:
v2 = 6;
break;
case 25:
v2 = 7;
break;
default:
v2 = 0;
break;
}
v3 = K053157_rambase + (v2 << 13);
K053157_cur_rambase = v3;
K053157_cur_notifier = (__int64 (*)(void))K053157_modify_notifiers[v2];
v4 = K053157_rambank;
if ( (unsigned int)(K053157_rambank - 1) <= 0xF )
{
cpu_bankbase[K053157_rambank] = v3;
if ( v4 == ophw )
goto LABEL_18;
}
}
else if ( a1 == 52 )
{
v5 = K053157_rombank;
if ( (unsigned int)(K053157_rombank - 1) <= 0xF )
{
cpu_bankbase[K053157_rombank] = K053157_rombase + (int)((a2 % K053157_romnbbanks) << 13);
if ( v5 == ophw )
{
LABEL_18:
ophw = -1;
v6 = cpu_get_pc();
cpu_setOPbase16(v6);
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, unsigned int a2)
{
int v2; // edx
__int64 v3; // rax
int v4; // edx
int v5; // ecx
unsigned int v6; // eax

if ( a1 == 50 )
{
switch ( (char)a2 )
{
case 1:
v2 = 1;
break;
case 8:
v2 = 2;
break;
case 9:
v2 = 3;
break;
case 16:
v2 = 4;
break;
case 17:
v2 = 5;
break;
case 24:
v2 = 6;
break;
case 25:
v2 = 7;
break;
default:
v2 = 0;
break;
}
v3 = K053157_rambase + (v2 << 13);
K053157_cur_rambase = v3;
K053157_cur_notifier = (__int64 (*)(void))K053157_modify_notifiers[v2];
v4 = K053157_rambank;
if ( (unsigned int)(K053157_rambank - 1) <= 0xF )
{
cpu_bankbase[K053157_rambank] = v3;
if ( v4 == ophw )
goto LABEL_18;
}
}
else if ( a1 == 52 )
{
v5 = K053157_rombank;
if ( (unsigned int)(K053157_rombank - 1) <= 0xF )
{
cpu_bankbase[K053157_rombank] = K053157_rombase + (int)((a2 % K053157_romnbbanks) << 13);
if ( v5 == ophw )
{
LABEL_18:
ophw = -1;
v6 = cpu_get_pc();
cpu_setOPbase16(v6);
return;
}
}
}
}

original_code:
void K053157_w(offs_t offset,data_t data)
{
 switch(offset) {
 case 0x32: {
  int nb;
  data &= 0xff;
  switch(data) {
  case 0:
   nb = 0;
   break;
  case 1:
   nb = 1;
   break;
  case 8:
   nb = 2;
   break;
  case 9:
   nb = 3;
   break;
  case 0x10:
   nb = 4;
   break;
  case 0x11:
   nb = 5;
   break;
  case 0x18:
   nb = 6;
   break;
  case 0x19:
   nb = 7;
   break;
  default:
   nb = 0;
   break;
  }
  K053157_cur_rambank = data;
  K053157_cur_rambase = K053157_rambase + nb*0x2000;
  K053157_cur_notifier = K053157_modify_notifiers[nb];
  { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (UINT8 *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 case 0x34: {
  K053157_cur_rombank = data % K053157_romnbbanks;
  { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (UINT8 *)(K053157_rombase + 0x2000*K053157_cur_rombank); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 default:
  break;
 }
}

canonical_original_code:
void K053157_w(unsigned int offset, unsigned int data)
{
 switch(offset) {
 case 0x32: {
  int nb;
  data &= 0xff;
  switch(data) {
  case 0:
   nb = 0;
   break;
  case 1:
   nb = 1;
   break;
  case 8:
   nb = 2;
   break;
  case 9:
   nb = 3;
   break;
  case 0x10:
   nb = 4;
   break;
  case 0x11:
   nb = 5;
   break;
  case 0x18:
   nb = 6;
   break;
  case 0x19:
   nb = 7;
   break;
  default:
   nb = 0;
   break;
  }
  K053157_cur_rambank = data;
  K053157_cur_rambase = K053157_rambase + nb*0x2000;
  K053157_cur_notifier = K053157_modify_notifiers[nb];
  { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (unsigned char *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 case 0x34: {
  K053157_cur_rombank = data % K053157_romnbbanks;
  { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (unsigned char *)(K053157_rombase + 0x2000*K053157_cur_rombank); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
  break;
 }
 default:
  break;
 }
}

variable_types: nb int


decompiled_code:
__int64 __fastcall backrom_r(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(139LL) + (cur_back_select << 11) + (a1 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(139LL) + (cur_back_select << 11) + (a1 >> 2));
}

original_code:
static data_t backrom_r(offs_t offset)
{
 return *(memory_region(REGION_GFX3) + 2048*cur_back_select + (offset>>2));
}

canonical_original_code:
static unsigned int backrom_r(unsigned int offset)
{
 return *(memory_region(REGION_GFX3) + 2048*cur_back_select + (offset>>2));
}


decompiled_code:
__int64 __fastcall K053157_char11_m(int a1)
{
return tilemap_mark_tile_dirty(K053157_char11_tilemap, (unsigned int)(a1 / 4));
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return tilemap_mark_tile_dirty(K053157_char11_tilemap, (unsigned int)(a1 / 4));
}

original_code:
static void K053157_char11_m(int offset)
{
 tilemap_mark_tile_dirty(K053157_char11_tilemap,offset/4);
}

variable_types: offset int


decompiled_code:
__int64 __fastcall K053157_char01_m(int a1)
{
return tilemap_mark_tile_dirty(K053157_char01_tilemap, (unsigned int)(a1 / 4));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return tilemap_mark_tile_dirty(K053157_char01_tilemap, (unsigned int)(a1 / 4));
}

original_code:
static void K053157_char01_m(int offset)
{
 tilemap_mark_tile_dirty(K053157_char01_tilemap,offset/4);
}


decompiled_code:
__int64 xexex_vh_stop()
{
return K053247_vh_stop();
}

original_code:
void xexex_vh_stop(void)
{
 K053247_vh_stop();
}

canonical_original_code:
void xexex_vh_stop()
{
 K053247_vh_stop();
}


decompiled_code:
__int64 __fastcall xexex_palette_w(unsigned int a1, int a2)
{
*(_WORD *)(xexex_palette_ram + a1) = a2 | *(_WORD *)(xexex_palette_ram + a1) & HIWORD(a2);
return palette_change_color(
(a1 & 0xFFFFFFFC) >> 2,
*(unsigned __int8 *)(xexex_palette_ram + (a1 & 0xFFFFFFFC)),
(unsigned __int8)HIBYTE(*(_WORD *)(xexex_palette_ram + (a1 & 0xFFFFFFFC) + 2)),
(unsigned __int8)*(_WORD *)(xexex_palette_ram + (a1 & 0xFFFFFFFC) + 2));
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, int a2)
{
*(_WORD *)(xexex_palette_ram + a1) = a2 | *(_WORD *)(xexex_palette_ram + a1) & HIWORD(a2);
return palette_change_color(
(a1 & 0xFFFFFFFC) >> 2,
*(unsigned __int8 *)(xexex_palette_ram + (a1 & 0xFFFFFFFC)),
(unsigned __int8)HIBYTE(*(_WORD *)(xexex_palette_ram + (a1 & 0xFFFFFFFC) + 2)),
(unsigned __int8)*(_WORD *)(xexex_palette_ram + (a1 & 0xFFFFFFFC) + 2));
}

original_code:
void xexex_palette_w(offs_t offset,data_t data)
{
 int r, g, b;
 int data0, data1;
 ((*(UINT16 *)((xexex_palette_ram+offset)) = (((*(UINT16 *)(xexex_palette_ram+offset)) & ((data) >> 16)) | (data))));
 offset &= ~3;
 data0 = (*(UINT16 *)(xexex_palette_ram + offset));
 data1 = (*(UINT16 *)(xexex_palette_ram + offset + 2));
 r = data0 & 0xff;
 g = data1 >> 8;
 b = data1 & 0xff;
 palette_change_color(offset>>2, r, g, b);
}

canonical_original_code:
void xexex_palette_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int data0; int data1;
 ((*(unsigned short *)((xexex_palette_ram+offset)) = (((*(unsigned short *)(xexex_palette_ram+offset)) & ((data) >> 16)) | (data))));
 offset &= ~3;
 data0 = (*(unsigned short *)(xexex_palette_ram + offset));
 data1 = (*(unsigned short *)(xexex_palette_ram + offset + 2));
 r = data0 & 0xff;
 g = data1 >> 8;
 b = data1 & 0xff;
 palette_change_color(offset>>2, r, g, b);
}

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 gfx_init()
{
konami_rom_deinterleave_2(137LL);
return konami_rom_deinterleave_4(138LL);
}

canonical_decompiled_code:
__int64 func17()
{
konami_rom_deinterleave_2(137LL);
return konami_rom_deinterleave_4(138LL);
}

original_code:
static void gfx_init(void)
{
 konami_rom_deinterleave_2(REGION_GFX1);
 konami_rom_deinterleave_4(REGION_GFX2);
}

canonical_original_code:
static void gfx_init()
{
 konami_rom_deinterleave_2(REGION_GFX1);
 konami_rom_deinterleave_4(REGION_GFX2);
}


decompiled_code:
__int64 init_xexex()
{
return gfx_init();
}

canonical_decompiled_code:
__int64 func18()
{
return func17();
}

original_code:
static void init_xexex(void)
{
 cur_rombank = 0;
 gfx_init();
}

canonical_original_code:
static void init_xexex()
{
 cur_rombank = 0;
 gfx_init();
}


decompiled_code:
__int64 xexex_interrupt()
{
int v0; // eax
__int64 result; // rax
int v2; // edx
int v3; // edx

v0 = cpu_getiloops();
if ( !v0 )
{
v2 = K053247_is_IRQ_enabled();
result = 4LL;
if ( v2 )
return result;
return ignore_interrupt();
}
if ( v0 != 1 )
return ignore_interrupt();
v3 = K053247_is_IRQ_enabled();
result = 5LL;
if ( !v3 )
return ignore_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // eax
__int64 result; // rax
int v2; // edx
int v3; // edx

v0 = cpu_getiloops();
if ( !v0 )
{
v2 = K053247_is_IRQ_enabled();
result = 4LL;
if ( v2 )
return result;
return ignore_interrupt();
}
if ( v0 != 1 )
return ignore_interrupt();
v3 = K053247_is_IRQ_enabled();
result = 5LL;
if ( !v3 )
return ignore_interrupt();
return result;
}

original_code:
static int xexex_interrupt(void)
{
 switch (cpu_getiloops())
 {
  case 0:
   if (K053247_is_IRQ_enabled()) return 4;
   break;
  case 1:
   if (K053247_is_IRQ_enabled()) return 5;
   break;
  case 2:
   break;
 }
 return ignore_interrupt();
}

canonical_original_code:
static int xexex_interrupt()
{
 switch (cpu_getiloops())
 {
  case 0:
   if (K053247_is_IRQ_enabled()) return 4;
   break;
  case 1:
   if (K053247_is_IRQ_enabled()) return 5;
   break;
  case 2:
   break;
 }
 return ignore_interrupt();
}


decompiled_code:
__int64 control1_r()
{
int v0; // ebx
__int64 result; // rax

v0 = EEPROM_read_bit();
result = v0 | (unsigned int)input_port_1_r(0LL);
if ( init_eeprom_count )
{
--init_eeprom_count;
result = (unsigned __int8)result & 0xF7;
}
return result;
}

canonical_decompiled_code:
__int64 func22()
{
int v0; // ebx
__int64 result; // rax

v0 = EEPROM_read_bit();
result = v0 | (unsigned int)input_port_1_r(0LL);
if ( init_eeprom_count )
{
--init_eeprom_count;
result = (unsigned __int8)result & 0xF7;
}
return result;
}

original_code:
static data_t control1_r(offs_t offset)
{
 int res;
 res = EEPROM_read_bit() | input_port_1_r(0);
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xf7;
 }
 return res;
}

canonical_original_code:
static unsigned int control1_r(unsigned int offset)
{
 int res;
 res = EEPROM_read_bit() | input_port_1_r(0);
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xf7;
 }
 return res;
}

variable_types: res int


decompiled_code:
__int64 control0_r()
{
return input_port_0_r(0LL);
}

canonical_decompiled_code:
__int64 func23()
{
return input_port_0_r(0LL);
}

original_code:
static data_t control0_r(offs_t offset)
{
 return input_port_0_r(0);
}

canonical_original_code:
static unsigned int control0_r(unsigned int offset)
{
 return input_port_0_r(0);
}


decompiled_code:
__int64 __fastcall K053157_vh_start(int a1, int a2, unsigned int a3)
{
__int64 v4; // rax
void *v5; // rax
int v6; // edx
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // eax
__int64 v10; // [rsp+0h] [rbp-38h]

K053157_char01_tilemap = tilemap_create(K053157_get_char01_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v10) = 32;
v4 = tilemap_create(K053157_get_char11_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v10);
K053157_char11_tilemap = v4;
if ( !K053157_char01_tilemap || !v4 )
return 1LL;
*(_DWORD *)(v4 + 132) = 0;
K053157_rambank = a1;
v5 = malloc(0x10000uLL);
K053157_rambase = (__int64)v5;
K053157_cur_rambase = (__int64)v5;
K053157_cur_notifier = 0LL;
if ( (unsigned int)(a1 - 1) <= 0xF )
{
cpu_bankbase[a1] = v5;
if ( ophw == a1 )
{
ophw = -1;
v9 = cpu_get_pc();
cpu_setOPbase16(v9);
}
}
K053157_rombank = a2;
K053157_rombase = memory_region(a3);
K053157_romnbbanks = (int)memory_region_length(a3) / 0x2000;
v6 = K053157_rombank;
result = 0LL;
if ( (unsigned int)(K053157_rombank - 1) <= 0xF )
{
cpu_bankbase[K053157_rombank] = K053157_rombase;
result = 0LL;
if ( v6 == ophw )
{
ophw = -1;
v8 = cpu_get_pc();
cpu_setOPbase16(v8);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(int a1, int a2, unsigned int a3)
{
__int64 v4; // rax
void *v5; // rax
int v6; // edx
__int64 result; // rax
unsigned int v8; // eax
unsigned int v9; // eax
__int64 v10; // [rsp+0h] [rbp-38h]

K053157_char01_tilemap = tilemap_create(K053157_get_char01_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v10) = 32;
v4 = tilemap_create(K053157_get_char11_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v10);
K053157_char11_tilemap = v4;
if ( !K053157_char01_tilemap || !v4 )
return 1LL;
*(_DWORD *)(v4 + 132) = 0;
K053157_rambank = a1;
v5 = malloc(0x10000uLL);
K053157_rambase = (__int64)v5;
K053157_cur_rambase = (__int64)v5;
K053157_cur_notifier = 0LL;
if ( (unsigned int)(a1 - 1) <= 0xF )
{
cpu_bankbase[a1] = v5;
if ( ophw == a1 )
{
ophw = -1;
v9 = cpu_get_pc();
cpu_setOPbase16(v9);
}
}
K053157_rombank = a2;
K053157_rombase = memory_region(a3);
K053157_romnbbanks = (int)memory_region_length(a3) / 0x2000;
v6 = K053157_rombank;
result = 0LL;
if ( (unsigned int)(K053157_rombank - 1) <= 0xF )
{
cpu_bankbase[K053157_rombank] = K053157_rombase;
result = 0LL;
if ( v6 == ophw )
{
ophw = -1;
v8 = cpu_get_pc();
cpu_setOPbase16(v8);
result = 0LL;
}
}
return result;
}

original_code:
int K053157_vh_start(int rambank, int rombank, int roms_memory_region)
{
 K053157_char01_tilemap = tilemap_create(K053157_get_char01_tile_info,tilemap_scan_rows,
           0x00,8,8,64,32);
 K053157_char11_tilemap = tilemap_create(K053157_get_char11_tile_info,tilemap_scan_rows,
           0x01,8,8,64,32);
 if(!K053157_char01_tilemap || !K053157_char11_tilemap)
  return 1;
 K053157_char11_tilemap->transparent_pen = 0;
 K053157_rambank = rambank;
 K053157_cur_rambank = 0;
 K053157_rambase = (unsigned char*)malloc(0x2000*8);
 K053157_cur_rambase = K053157_rambase;
 K053157_cur_notifier = K053157_modify_notifiers[0];
 { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (UINT8 *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 K053157_rombank = rombank;
 K053157_cur_rombank = 0;
 K053157_rombase = memory_region(roms_memory_region);
 K053157_romnbbanks = memory_region_length(roms_memory_region)/0x2000;
 { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (UINT8 *)(K053157_rombase); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 return 0;
}

canonical_original_code:
int K053157_vh_start(int rambank, int rombank, int roms_memory_region)
{
 K053157_char01_tilemap = tilemap_create(K053157_get_char01_tile_info,tilemap_scan_rows,
           0x00,8,8,64,32);
 K053157_char11_tilemap = tilemap_create(K053157_get_char11_tile_info,tilemap_scan_rows,
           0x01,8,8,64,32);
 if(!K053157_char01_tilemap || !K053157_char11_tilemap)
  return 1;
 K053157_char11_tilemap->transparent_pen = 0;
 K053157_rambank = rambank;
 K053157_cur_rambank = 0;
 K053157_rambase = (unsigned char *)malloc(0x2000*8);
 K053157_cur_rambase = K053157_rambase;
 K053157_cur_notifier = K053157_modify_notifiers[0];
 { if (K053157_rambank >= 1 && K053157_rambank <= 16) { cpu_bankbase[K053157_rambank] = (unsigned char *)(K053157_cur_rambase); if (ophw == K053157_rambank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 K053157_rombank = rombank;
 K053157_cur_rombank = 0;
 K053157_rombase = memory_region(roms_memory_region);
 K053157_romnbbanks = memory_region_length(roms_memory_region)/0x2000;
 { if (K053157_rombank >= 1 && K053157_rombank <= 16) { cpu_bankbase[K053157_rombank] = (unsigned char *)(K053157_rombase); if (ophw == K053157_rombank) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 return 0;
}

variable_types: rambank int

variable_types: rombank int


decompiled_code:
_BOOL8 xexex_vh_start()
{
K053157_vh_start(2, 6, 0x89u);
return (unsigned int)K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) != 0;
}

canonical_decompiled_code:
_BOOL8 func25()
{
func24(2, 6, 0x89u);
return (unsigned int)K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) != 0;
}

original_code:
int xexex_vh_start(void)
{
 K053157_vh_start(2, 6, REGION_GFX1);
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 return 0;
}

canonical_original_code:
int xexex_vh_start()
{
 K053157_vh_start(2, 6, REGION_GFX1);
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 K053157_update()
{
tilemap_update(K053157_char01_tilemap);
return tilemap_update(K053157_char11_tilemap);
}

canonical_decompiled_code:
__int64 func26()
{
tilemap_update(K053157_char01_tilemap);
return tilemap_update(K053157_char11_tilemap);
}

original_code:
void K053157_update(void)
{
 tilemap_update(K053157_char01_tilemap);
 tilemap_update(K053157_char11_tilemap);
}

canonical_original_code:
void K053157_update()
{
 tilemap_update(K053157_char01_tilemap);
 tilemap_update(K053157_char11_tilemap);
}


decompiled_code:
__int64 K053157_render()
{
tilemap_render(K053157_char01_tilemap);
return tilemap_render(K053157_char11_tilemap);
}

canonical_decompiled_code:
__int64 func27()
{
tilemap_render(K053157_char01_tilemap);
return tilemap_render(K053157_char11_tilemap);
}

original_code:
void K053157_render(void)
{
 tilemap_render(K053157_char01_tilemap);
 tilemap_render(K053157_char11_tilemap);
}

canonical_original_code:
void K053157_render()
{
 tilemap_render(K053157_char01_tilemap);
 tilemap_render(K053157_char11_tilemap);
}


decompiled_code:
__int64 __fastcall K053157_draw(__int64 a1)
{
tilemap_draw(a1, K053157_char01_tilemap, 0LL);
return tilemap_draw(a1, K053157_char11_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1)
{
tilemap_draw(a1, K053157_char01_tilemap, 0LL);
return tilemap_draw(a1, K053157_char11_tilemap, 0LL);
}

original_code:
void K053157_draw(struct osd_bitmap *bitmap)
{
 tilemap_draw(bitmap, K053157_char01_tilemap, 0);
 tilemap_draw(bitmap, K053157_char11_tilemap, 0);
}

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


decompiled_code:
__int64 __fastcall xexex_vh_screenrefresh(__int64 a1)
{
K053157_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
K053157_render();
K053157_draw(a1);
return K053247_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
func26();
palette_init_used_colors();
K053247_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
func27();
func28(a1);
return K053247_sprites_draw(a1);
}

original_code:
void xexex_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K053157_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 K053157_render();
 K053157_draw(bitmap);
 K053247_sprites_draw(bitmap);
}

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


decompiled_code:
void __fastcall sound_cmd_w(__int64 a1, char a2)
{
if ( a2 == -2 )
sound_status = 127;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char a2)
{
if ( a2 == -2 )
sound_status = 127;
}

original_code:
static void sound_cmd_w(offs_t offset,data_t data)
{
 sound_cmd = data & 0xff;
 if(sound_cmd == 0xfe)
   sound_status = 0x7f;
}

canonical_original_code:
static void sound_cmd_w(unsigned int offset, unsigned int data)
{
 sound_cmd = data & 0xff;
 if(sound_cmd == 0xfe)
   sound_status = 0x7f;
}


decompiled_code:
__int64 sound_status_r()
{
return (unsigned int)sound_status;
}

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

original_code:
static data_t sound_status_r(offs_t offset)
{
 return sound_status;
}

canonical_original_code:
static unsigned int sound_status_r(unsigned int offset)
{
 return sound_status;
}


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

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

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

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

variable_types:
file
void *


decompiled_code:
__int64 __fastcall control2_w(__int64 a1, unsigned int a2)
{
EEPROM_write_bit(a2 & 1);
EEPROM_set_cs_line(((unsigned __int8)(a2 >> 1) ^ 1) & 1);
EEPROM_set_clock_line((a2 >> 2) & 1);
cur_control2 = a2;
return K053246_set_OBJCHA_line(BYTE1(a2) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned int a2)
{
EEPROM_write_bit(a2 & 1);
EEPROM_set_cs_line(((unsigned __int8)(a2 >> 1) ^ 1) & 1);
EEPROM_set_clock_line((a2 >> 2) & 1);
cur_control2 = a2;
return K053246_set_OBJCHA_line(BYTE1(a2) & 1);
}

original_code:
static void control2_w(offs_t offset,data_t data)
{
 EEPROM_write_bit(data & 0x01);
 EEPROM_set_cs_line((data & 0x02) ? 0 : 1);
 EEPROM_set_clock_line((data & 0x04) ? 1 : 0);
 cur_control2 = data;
 K053246_set_OBJCHA_line((data & 0x0100) ? 1 : 0);
}

canonical_original_code:
static void control2_w(unsigned int offset, unsigned int data)
{
 EEPROM_write_bit(data & 0x01);
 EEPROM_set_cs_line((data & 0x02) ? 0 : 1);
 EEPROM_set_clock_line((data & 0x04) ? 1 : 0);
 cur_control2 = data;
 K053246_set_OBJCHA_line((data & 0x0100) ? 1 : 0);
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall tagteam_control_w(__int64 a1, unsigned int a2)
{
palettebank = (a2 >> 7) & 1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
palettebank = (a2 >> 7) & 1;
}

original_code:
void tagteam_control_w(offs_t offset,data_t data)
{
 palettebank = (data & 0x80) >> 7;
}

canonical_original_code:
void tagteam_control_w(unsigned int offset, unsigned int data)
{
 palettebank = (data & 0x80) >> 7;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall tagteam_mirrorvideoram_r(unsigned int a1)
{
return videoram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return videoram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
data_t tagteam_mirrorvideoram_r(offs_t offset)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return videoram_r(offset);
}

canonical_original_code:
unsigned int tagteam_mirrorvideoram_r(unsigned int offset)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return videoram_r(offset);
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall tagteam_mirrorcolorram_r(unsigned int a1)
{
return colorram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return colorram_r(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
data_t tagteam_mirrorcolorram_r(offs_t offset)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return colorram_r(offset);
}

canonical_original_code:
unsigned int tagteam_mirrorcolorram_r(unsigned int offset)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 return colorram_r(offset);
}


decompiled_code:
__int64 __fastcall tagteam_mirrorvideoram_w(unsigned int a1)
{
return videoram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return videoram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
void tagteam_mirrorvideoram_w(offs_t offset,data_t data)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 videoram_w(offset,data);
}

canonical_original_code:
void tagteam_mirrorvideoram_w(unsigned int offset, unsigned int data)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 videoram_w(offset,data);
}


decompiled_code:
__int64 __fastcall tagteam_mirrorcolorram_w(unsigned int a1)
{
return colorram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return colorram_w(32 * (a1 & 0x1F) + (a1 >> 5));
}

original_code:
void tagteam_mirrorcolorram_w(offs_t offset,data_t data)
{
 int x,y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 colorram_w(offset,data);
}

canonical_original_code:
void tagteam_mirrorcolorram_w(unsigned int offset, unsigned int data)
{
 int x; int y;
 x = offset / 32;
 y = offset % 32;
 offset = 32 * y + x;
 colorram_w(offset,data);
}


decompiled_code:
__int64 __fastcall tagteam_vh_screenrefresh(__int64 a1)
{
drawchars(a1, palettebank);
return drawsprites(a1, palettebank);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
func7(a1, palettebank);
return func6(a1, palettebank);
}

original_code:
void tagteam_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 drawchars(bitmap,palettebank);
 drawsprites(bitmap,palettebank);
}

canonical_original_code:
void tagteam_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 drawchars(bitmap,palettebank);
 drawsprites(bitmap,palettebank);
}


decompiled_code:
__int64 tagteam_interrupt()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_0 = 0;
return ignore_interrupt();
}
if ( coin_0 )
return ignore_interrupt();
coin_0 = 1;
return nmi_interrupt();
}

canonical_decompiled_code:
__int64 func9()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_0 = 0;
return ignore_interrupt();
}
if ( coin_0 )
return ignore_interrupt();
coin_0 = 1;
return nmi_interrupt();
}

original_code:
static int tagteam_interrupt(void)
{
 static int coin;
 int port;
 port = readinputport(0) & 0xc0;
 if (port != 0xc0)
 {
  if (coin == 0)
  {
   coin = 1;
   return nmi_interrupt();
  }
 }
 else coin = 0;
        return ignore_interrupt();
}

canonical_original_code:
static int tagteam_interrupt()
{
 static int coin;
 int port;
 port = readinputport(0) & 0xc0;
 if (port != 0xc0)
 {
  if (coin == 0)
  {
   coin = 1;
   return nmi_interrupt();
  }
 }
 else coin = 0;
        return ignore_interrupt();
}

variable_types: coin int

variable_types: port int


drawsprites

decompiled_code:
__int64 __fastcall drawsprites(__int64 a1, unsigned int a2)
{
__int64 i; // rbp
__int64 v3; // r13
int v4; // er14
unsigned int v5; // ebx
unsigned int v6; // er12
__int64 result; // rax
int v8; // edx
int v9; // [rsp+4h] [rbp-44h]

for ( i = 0LL; i != 32; i += 4LL )
{
result = videoram;
v8 = *(unsigned __int8 *)(videoram + i);
if ( (v8 & 1) != 0 )
{
v3 = 240 - (unsigned int)*(unsigned __int8 *)(videoram + i + 3);
v4 = *(unsigned __int8 *)(videoram + i + 2);
v5 = v8 & 4;
v6 = v8 & 2;
v9 = (v8 << 12) & 0x30000;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9 + (unsigned int)*(unsigned __int8 *)(videoram + i + 1),
2 * a2 + 1,
v8 & 4,
v8 & 2,
v3,
(unsigned int)(240 - v4),
Machine + 776LL,
2LL,
0LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9 + (unsigned int)*(unsigned __int8 *)(videoram + i + 32),
a2,
v5,
v6,
v3,
(unsigned int)(496 - v4),
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 i; // rbp
__int64 v3; // r13
int v4; // er14
unsigned int v5; // ebx
unsigned int v6; // er12
__int64 result; // rax
int v8; // edx
int v9; // [rsp+4h] [rbp-44h]

for ( i = 0LL; i != 32; i += 4LL )
{
result = videoram;
v8 = *(unsigned __int8 *)(videoram + i);
if ( (v8 & 1) != 0 )
{
v3 = 240 - (unsigned int)*(unsigned __int8 *)(videoram + i + 3);
v4 = *(unsigned __int8 *)(videoram + i + 2);
v5 = v8 & 4;
v6 = v8 & 2;
v9 = (v8 << 12) & 0x30000;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9 + (unsigned int)*(unsigned __int8 *)(videoram + i + 1),
2 * a2 + 1,
v8 & 4,
v8 & 2,
v3,
(unsigned int)(240 - v4),
Machine + 776LL,
2LL,
0LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v9 + (unsigned int)*(unsigned __int8 *)(videoram + i + 32),
a2,
v5,
v6,
v3,
(unsigned int)(496 - v4),
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

original_code:
static void drawsprites(struct osd_bitmap *bitmap,int color)
{
 int offs;
 for (offs = 0;offs < 0x20;offs += 4)
 {
  int sx,sy,flipx,flipy;
  int spritebank;
  if (!(videoram[offs + 0] & 0x01)) continue;
  sx = 240 - videoram[offs + 3];
  sy = 240 - videoram[offs + 2];
  flipx = videoram[offs + 0] & 0x04;
  flipy = videoram[offs + 0] & 0x02;
  spritebank = (videoram[offs] & 0x30) << 4;
  if (flipscreen)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 1] + 256 * spritebank,
    1+2*color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  sy += (flipscreen ? -256 : 256);
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 0x20] + 256 * spritebank,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void drawsprites(struct osd_bitmap *bitmap, int color)
{
 int offs;
 for (offs = 0;offs < 0x20;offs += 4)
 {
  int sx; int sy; int flipx; int flipy;
  int spritebank;
  if (!(videoram[offs + 0] & 0x01)) continue;
  sx = 240 - videoram[offs + 3];
  sy = 240 - videoram[offs + 2];
  flipx = videoram[offs + 0] & 0x04;
  flipy = videoram[offs + 0] & 0x02;
  spritebank = (videoram[offs] & 0x30) << 4;
  if (flipscreen)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 1] + 256 * spritebank,
    1+2*color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  sy += (flipscreen ? -256 : 256);
  drawgfx(bitmap,Machine->gfx[1],
    videoram[offs + 0x20] + 256 * spritebank,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: color int

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: spritebank int


drawchars

decompiled_code:
__int64 __fastcall drawchars(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + (*(unsigned __int8 *)(colorram + v3) << 8),
(unsigned int)(2 * a2),
0LL,
0LL,
8 * (((unsigned int)(v2 >> 31) >> 27) - (((_BYTE)v2 + ((unsigned int)(v2 >> 31) >> 27)) & 0x1F)) + 248,
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + (*(unsigned __int8 *)(colorram + v3) << 8),
(unsigned int)(2 * a2),
0LL,
0LL,
8 * (((unsigned int)(v2 >> 31) >> 27) - (((_BYTE)v2 + ((unsigned int)(v2 >> 31) >> 27)) & 0x1F)) + 248,
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
static void drawchars(struct osd_bitmap *bitmap,int color)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = 31 - offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * colorram[offs],
     2*color,
     flipscreen,flipscreen,
     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:
static void drawchars(struct osd_bitmap *bitmap, int color)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  if (dirtybuffer[offs])
  {
   dirtybuffer[offs] = 0;
   sx = 31 - offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * colorram[offs],
     2*color,
     flipscreen,flipscreen,
     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; } *


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

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

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

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


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

switch ( a1 )
{
case 23:
GRMidByte = a2;
break;
case 24:
GRLowByte = a2;
break;
case 8:
GRHighByte = a2;
break;
}
result = GRLowByte | (GRMidByte << 8) | (unsigned int)(GRHighByte << 16);
currentaddress = GRLowByte | (GRMidByte << 8) | (GRHighByte << 16);
return result;
}

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

switch ( a1 )
{
case 23:
GRMidByte = a2;
break;
case 24:
GRLowByte = a2;
break;
case 8:
GRHighByte = a2;
break;
}
result = GRLowByte | (GRMidByte << 8) | (unsigned int)(GRHighByte << 16);
currentaddress = GRLowByte | (GRMidByte << 8) | (GRHighByte << 16);
return result;
}

original_code:
void bowlrama_turbo_w(offs_t offset,data_t data)
{
 switch( offset )
 {
  case 0x08:
   GRHighByte = data;
   break;
  case 0x17:
   GRMidByte = data;
   break;
  case 0x18:
   GRLowByte = data;
   break;
  default:
   break;
 }
 currentaddress = ((GRHighByte << 16) | (GRMidByte << 8) | GRLowByte);
}

canonical_original_code:
void bowlrama_turbo_w(unsigned int offset, unsigned int data)
{
 switch( offset )
 {
  case 0x08:
   GRHighByte = data;
   break;
  case 0x17:
   GRMidByte = data;
   break;
  case 0x18:
   GRLowByte = data;
   break;
  default:
   break;
 }
 currentaddress = ((GRHighByte << 16) | (GRMidByte << 8) | GRLowByte);
}


decompiled_code:
__int64 capbowl_vertical_interrupt()
{
return 2LL;
}

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

original_code:
static int capbowl_vertical_interrupt(void)
{
 return 2;
}

canonical_original_code:
static int capbowl_vertical_interrupt()
{
 return 2;
}


decompiled_code:
__int64 __fastcall capbowl_tms34061_getfunction(int a1)
{
return (a1 >> 8) & 3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (a1 >> 8) & 3;
}

original_code:
static int capbowl_tms34061_getfunction(int offset)
{
 return (offset >> 8) & 0x03;
}

variable_types: offset int


decompiled_code:
__int64 capbowl_tms34061_getrowaddress()
{
return (unsigned __int8)*capbowl_rowaddress;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)*capbowl_rowaddress;
}

original_code:
static int capbowl_tms34061_getrowaddress(int offset)
{
 return *capbowl_rowaddress;
}


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

result = (unsigned __int8)a1;
if ( (a1 & 0x300) == 0 )
result = (unsigned __int8)a1 ^ 2u;
return result;
}

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

result = (unsigned __int8)a1;
if ( (a1 & 0x300) == 0 )
result = (unsigned __int8)a1 ^ 2u;
return result;
}

original_code:
static int capbowl_tms34061_getcoladdress(int offset)
{
 int col = (offset & 0xff);
 if (!(offset & 0x300))
 {
  col ^= 0x02;
 }
 return col;
}

variable_types: col int


decompiled_code:
__int64 __fastcall capbowl_tms34061_getpixel(int a1, int a2)
{
return *((unsigned __int8 *)raw_video_ram + (a1 | (a2 << 8)));
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
return *((unsigned __int8 *)raw_video_ram + (a1 | (a2 << 8)));
}

original_code:
static int capbowl_tms34061_getpixel(int col, int row)
{
 return raw_video_ram[row << 8 | col];
}

variable_types: row int


decompiled_code:
__int64 __fastcall TMS34061_register_r(unsigned int a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = a1 >> 2;
if ( (a1 & 2) != 0 )
result = (unsigned int)(regs[v1] >> 8);
else
result = LOBYTE(regs[v1]);
if ( v1 == 13 )
dword_C94 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = a1 >> 2;
if ( (a1 & 2) != 0 )
result = (unsigned int)(regs[v1] >> 8);
else
result = LOBYTE(regs[v1]);
if ( v1 == 13 )
dword_C94 = 0;
return result;
}

original_code:
static inline data_t TMS34061_register_r(offs_t offset)
{
 int ret;
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  ret = (regs[reg] >> 8);
 }
 else
 {
  ret = (regs[reg] & 0xff);
 }
 switch (reg)
 {
 case 13:
  regs[reg] = 0;
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
 return ret;
}

canonical_original_code:
static inline unsigned int TMS34061_register_r(unsigned int offset)
{
 int ret;
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  ret = (regs[reg] >> 8);
 }
 else
 {
  ret = (regs[reg] & 0xff);
 }
 switch (reg)
 {
 case 13:
  regs[reg] = 0;
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
 return ret;
}

variable_types:
offset
unsigned int

variable_types: ret int

variable_types: status int

variable_types: reg int


decompiled_code:
__int64 __fastcall adjust_xyaddress(char a1, char a2, __int16 a3)
{
__int64 result; // rax
unsigned __int8 v4; // si
int v5; // edi
__int16 v6; // dx

result = a1 & 6;
if ( (_DWORD)result == 4 )
{
v4 = a2 - 1;
}
else if ( (_DWORD)result == 6 )
{
v4 = 0;
}
else
{
result = (_DWORD)result == 2;
v4 = result + a2;
}
v5 = a1 & 0x18;
if ( v5 == 16 )
{
v6 = a3 - 1;
}
else if ( v5 == 24 )
{
v6 = 0;
}
else
{
result = v5 == 8;
v6 = result + a3;
}
dword_C9C = v4 | (unsigned __int16)(v6 << 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char a2, __int16 a3)
{
__int64 result; // rax
unsigned __int8 v4; // si
int v5; // edi
__int16 v6; // dx

result = a1 & 6;
if ( (_DWORD)result == 4 )
{
v4 = a2 - 1;
}
else if ( (_DWORD)result == 6 )
{
v4 = 0;
}
else
{
result = (_DWORD)result == 2;
v4 = result + a2;
}
v5 = a1 & 0x18;
if ( v5 == 16 )
{
v6 = a3 - 1;
}
else if ( v5 == 24 )
{
v6 = 0;
}
else
{
result = v5 == 8;
v6 = result + a3;
}
dword_C9C = v4 | (unsigned __int16)(v6 << 8);
return result;
}

original_code:
static inline void adjust_xyaddress(int offset, int x, int y)
{
 switch (offset & 0x06)
 {
 case 0x00: break;
 case 0x02: x++; break;
 case 0x04: x--; break;
 case 0x06: x=0; break;
 }
 switch (offset & 0x18)
 {
 case 0x00: break;
 case 0x08: y++; break;
 case 0x10: y--; break;
 case 0x18: y=0; break;
 }
 regs[15] = ((y & 0xff) << 8) | (x & 0xff);
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall TMS34061_xypixel_w(int a1, unsigned int a2)
{
char v2; // r12
int v3; // ebx
__int64 result; // rax

v2 = dword_C9C;
v3 = dword_C9C >> 8;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(
(unsigned __int8)dword_C9C,
(unsigned int)(dword_C9C >> 8),
a2);
if ( a1 )
result = adjust_xyaddress(a1, v2, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2)
{
char v2; // r12
int v3; // ebx
__int64 result; // rax

v2 = dword_C9C;
v3 = dword_C9C >> 8;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(
(unsigned __int8)dword_C9C,
(unsigned int)(dword_C9C >> 8),
a2);
if ( a1 )
result = func7(a1, v2, v3);
return result;
}

original_code:
static inline void TMS34061_xypixel_w(offs_t offset,data_t data)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    intf->setpixel(x, y, data);
 if (offset) adjust_xyaddress(offset, x, y);
}

canonical_original_code:
static inline void TMS34061_xypixel_w(unsigned int offset, unsigned int data)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    intf->setpixel(x, y, data);
 if (offset) adjust_xyaddress(offset, x, y);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall TMS34061_xypixel_r(int a1)
{
char v1; // r13
int v2; // ebx
unsigned int v3; // er12

v1 = dword_C9C;
v2 = dword_C9C >> 8;
v3 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(
(unsigned __int8)dword_C9C,
(unsigned int)(dword_C9C >> 8));
if ( a1 )
adjust_xyaddress(a1, v1, v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
char v1; // r13
int v2; // ebx
unsigned int v3; // er12

v1 = dword_C9C;
v2 = dword_C9C >> 8;
v3 = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(
(unsigned __int8)dword_C9C,
(unsigned int)(dword_C9C >> 8));
if ( a1 )
func7(a1, v1, v2);
return v3;
}

original_code:
static inline data_t TMS34061_xypixel_r(offs_t offset)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    int ret = intf->getpixel(x, y);
 if (offset) adjust_xyaddress(offset, x, y);
 return ret;
}

canonical_original_code:
static inline unsigned int TMS34061_xypixel_r(unsigned int offset)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    int ret = intf->getpixel(x, y);
 if (offset) adjust_xyaddress(offset, x, y);
 return ret;
}


decompiled_code:
__int64 __fastcall TMS34061_r(unsigned int a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
int v3; // eax
__int64 result; // rax

v1 = (*(__int64 (**)(void))(intf + 16))();
v2 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
v3 = (*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( v3 == 2 )
return TMS34061_register_r(v1);
if ( v3 <= 2 )
{
if ( v3 )
{
if ( v3 == 1 )
result = TMS34061_xypixel_r(v1);
else
result = 0LL;
return result;
}
return TMS34061_register_r(v1);
}
if ( v3 == 3 )
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(v1, v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
int v3; // eax
__int64 result; // rax

v1 = (*(__int64 (**)(void))(intf + 16))();
v2 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
v3 = (*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( v3 == 2 )
return func6(v1);
if ( v3 <= 2 )
{
if ( v3 )
{
if ( v3 == 1 )
result = func9(v1);
else
result = 0LL;
return result;
}
return func6(v1);
}
if ( v3 == 3 )
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(v1, v2);
else
result = 0LL;
return result;
}

original_code:
data_t TMS34061_r(offs_t offset)
{
 int ret = 0;
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  ret = TMS34061_register_r(col);
  break;
 case 1:
  ret = TMS34061_xypixel_r(col);
  break;
 case 3:
  ret = intf->getpixel(col, row);
  break;
 default:
  break;
 }
 return ret;
}

canonical_original_code:
unsigned int TMS34061_r(unsigned int offset)
{
 int ret = 0;
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  ret = TMS34061_register_r(col);
  break;
 case 1:
  ret = TMS34061_xypixel_r(col);
  break;
 case 3:
  ret = intf->getpixel(col, row);
  break;
 default:
  break;
 }
 return ret;
}

variable_types: func int


decompiled_code:
__int64 capbowl_init_machine()
{
return ticket_dispenser_init(100LL, 1LL, 0LL);
}

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

original_code:
void capbowl_init_machine(void)
{
 ticket_dispenser_init(100, 1, 0);
}

canonical_original_code:
void capbowl_init_machine()
{
 ticket_dispenser_init(100, 1, 0);
}


decompiled_code:
__int64 __fastcall bowlrama_turbo_r(int a1)
{
unsigned __int8 v1; // cl
unsigned int v2; // edx
int v3; // eax

v1 = *(_BYTE *)(memory_region(137LL) + currentaddress);
if ( a1 )
{
v2 = 0;
if ( a1 == 4 )
{
v2 = v1;
v3 = currentaddress + 1;
currentaddress = v3 & 0x3FFFF;
GRHighByte = (v3 & 0x3FFFF) >> 16;
GRMidByte = BYTE1(v3);
GRLowByte = (unsigned __int8)v3;
}
}
else
{
v2 = (v1 & 0xF0) == 0 ? 0xF0 : 0;
if ( (v1 & 0xF) == 0 )
v2 = ((v1 & 0xF0) == 0 ? 0xF0 : 0) | 0xF;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
unsigned __int8 v1; // cl
unsigned int v2; // edx
int v3; // eax

v1 = *(_BYTE *)(memory_region(137LL) + currentaddress);
if ( a1 )
{
v2 = 0;
if ( a1 == 4 )
{
v2 = v1;
v3 = currentaddress + 1;
currentaddress = v3 & 0x3FFFF;
GRHighByte = (v3 & 0x3FFFF) >> 16;
GRMidByte = BYTE1(v3);
GRLowByte = (unsigned __int8)v3;
}
}
else
{
v2 = (v1 & 0xF0) == 0 ? 0xF0 : 0;
if ( (v1 & 0xF) == 0 )
v2 = ((v1 & 0xF0) == 0 ? 0xF0 : 0) | 0xF;
}
return v2;
}

original_code:
data_t bowlrama_turbo_r(offs_t offset)
{
 int ret = 0;
 int data = memory_region(REGION_GFX1)[currentaddress];
 switch (offset)
 {
 case 0:
  if(!(data & 0xf0))
  {
   ret = 0xf0;
  }
  if(!(data & 0x0f))
  {
   ret |= 0x0f;
  }
  break;
 case 4:
  ret = data;
  currentaddress = (currentaddress + 1) & 0x3ffff;
  GRHighByte = (currentaddress >> 16);
  GRMidByte = (currentaddress >> 8) & 0xff;
  GRLowByte = (currentaddress & 0xff);
  break;
 default:
  break;
 }
 return ret;
}

canonical_original_code:
unsigned int bowlrama_turbo_r(unsigned int offset)
{
 int ret = 0;
 int data = memory_region(REGION_GFX1)[currentaddress];
 switch (offset)
 {
 case 0:
  if(!(data & 0xf0))
  {
   ret = 0xf0;
  }
  if(!(data & 0x0f))
  {
   ret |= 0x0f;
  }
  break;
 case 4:
  ret = data;
  currentaddress = (currentaddress + 1) & 0x3ffff;
  GRHighByte = (currentaddress >> 16);
  GRMidByte = (currentaddress >> 8) & 0xff;
  GRLowByte = (currentaddress & 0xff);
  break;
 default:
  break;
 }
 return ret;
}

variable_types: data int


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

cpu_bankbase[1] = memory_region(129LL) + (((_WORD)a2 << 14) & 0x4000 | (a2 << 13) & 0x18000) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((_WORD)a2 << 14) & 0x4000 | (a2 << 13) & 0x18000) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

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

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall capbowl_tms34061_setpixel(int a1, int a2, int a3)
{
int v3; // ecx
_BYTE *v4; // r8
__int64 result; // rax
unsigned __int8 v6; // r9
int v7; // er10
int v8; // er9
int v9; // ecx
int v10; // edx
int v11; // edi
int v12; // eax

v3 = a1 | (a2 << 8);
v4 = raw_video_ram;
result = (__int64)raw_video_ram + v3;
v6 = *(_BYTE *)result;
*(_BYTE *)result = a3;
if ( max_row >= a2 && max_col_offset > a1 )
{
v7 = 16 * a2;
if ( a1 <= 31 )
{
result = palette_change_color(
v7 | (unsigned int)(a1 >> 1),
17 * (v4[v3 & 0xFFFFFFFE] & 0xFu),
17 * (unsigned int)(v4[v3 | 1] >> 4),
17 * (v4[v3 | 1] & 0xFu));
}
else
{
result = v7 | (unsigned int)((int)v6 >> 4);
v8 = v7 | v6 & 0xF;
v9 = v7 | (a3 >> 4);
v10 = v7 | a3 & 0xF;
if ( (_DWORD)result != v9 )
{
*((_BYTE *)&dirty_row + a2) = 1;
v11 = color_count[(int)result] - 1;
color_count[(int)result] = v11;
if ( !v11 )
*(_BYTE *)(palette_used_colors + (int)result) = 0;
++color_count[v9];
result = palette_used_colors;
*(_BYTE *)(palette_used_colors + v9) = 3;
}
if ( v8 != v10 )
{
*((_BYTE *)&dirty_row + a2) = 1;
v12 = color_count[v8] - 1;
color_count[v8] = v12;
if ( !v12 )
*(_BYTE *)(palette_used_colors + v8) = 0;
++color_count[v10];
result = palette_used_colors;
*(_BYTE *)(palette_used_colors + v10) = 3;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, int a3)
{
int v3; // ecx
_BYTE *v4; // r8
__int64 result; // rax
unsigned __int8 v6; // r9
int v7; // er10
int v8; // er9
int v9; // ecx
int v10; // edx
int v11; // edi
int v12; // eax

v3 = a1 | (a2 << 8);
v4 = raw_video_ram;
result = (__int64)raw_video_ram + v3;
v6 = *(_BYTE *)result;
*(_BYTE *)result = a3;
if ( max_row >= a2 && max_col_offset > a1 )
{
v7 = 16 * a2;
if ( a1 <= 31 )
{
result = palette_change_color(
v7 | (unsigned int)(a1 >> 1),
17 * (v4[v3 & 0xFFFFFFFE] & 0xFu),
17 * (unsigned int)(v4[v3 | 1] >> 4),
17 * (v4[v3 | 1] & 0xFu));
}
else
{
result = v7 | (unsigned int)((int)v6 >> 4);
v8 = v7 | v6 & 0xF;
v9 = v7 | (a3 >> 4);
v10 = v7 | a3 & 0xF;
if ( (_DWORD)result != v9 )
{
*((_BYTE *)&dirty_row + a2) = 1;
v11 = color_count[(int)result] - 1;
color_count[(int)result] = v11;
if ( !v11 )
*(_BYTE *)(palette_used_colors + (int)result) = 0;
++color_count[v9];
result = palette_used_colors;
*(_BYTE *)(palette_used_colors + v9) = 3;
}
if ( v8 != v10 )
{
*((_BYTE *)&dirty_row + a2) = 1;
v12 = color_count[v8] - 1;
color_count[v8] = v12;
if ( !v12 )
*(_BYTE *)(palette_used_colors + v8) = 0;
++color_count[v10];
result = palette_used_colors;
*(_BYTE *)(palette_used_colors + v10) = 3;
}
}
}
return result;
}

original_code:
static void capbowl_tms34061_setpixel(int col, int row, int pixel)
{
 int off = ((row << 8) | col);
 int penstart = row << 4;
 int oldpixel = raw_video_ram[off];
 raw_video_ram[off] = pixel;
 if (row > max_row || col >= max_col_offset) return;
 if (col >= 0x20)
 {
  int oldpen1 = penstart | (oldpixel >> 4);
  int oldpen2 = penstart | (oldpixel & 0x0f);
  int newpen1 = penstart | (pixel >> 4);
  int newpen2 = penstart | (pixel & 0x0f);
  if (oldpen1 != newpen1)
  {
   dirty_row[row] = 1;
   color_count[oldpen1]--;
   if (!color_count[oldpen1]) palette_used_colors[oldpen1] = 0;
   color_count[newpen1]++;
   palette_used_colors[newpen1] = (1|2);
  }
  if (oldpen2 != newpen2)
  {
   dirty_row[row] = 1;
   color_count[oldpen2]--;
   if (!color_count[oldpen2]) palette_used_colors[oldpen2] = 0;
   color_count[newpen2]++;
   palette_used_colors[newpen2] = (1|2);
  }
 }
 else
 {
  int r = (raw_video_ram[off & ~1] & 0x0f);
  int g = (raw_video_ram[off | 1] >> 4);
  int b = (raw_video_ram[off | 1] & 0x0f);
  r = (r << 4) + r;
  g = (g << 4) + g;
  b = (b << 4) + b;
  palette_change_color(penstart | (col >> 1),r,g,b);
 }
}

variable_types: pixel int

variable_types: off int

variable_types: penstart int

variable_types: oldpixel int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
void __fastcall TMS34061_intcallback(unsigned int a1)
{
unsigned int v1; // eax

if ( (byte_C8D & 4) != 0 )
{
dword_C94 |= 1u;
v1 = (*(__int64 (**)(void))(intf + 48))();
cpu_cause_interrupt(a1, v1);
}
}

canonical_decompiled_code:
void __fastcall func15(unsigned int a1)
{
unsigned int v1; // eax

if ( (byte_C8D & 4) != 0 )
{
dword_C94 |= 1u;
v1 = (*(__int64 (**)(void))(intf + 48))();
cpu_cause_interrupt(a1, v1);
}
}

original_code:
static void TMS34061_intcallback(int param)
{
    if (!(regs[11] & 0x400)) return;
 regs[13] |= 0x0001;
 cpu_cause_interrupt (param, intf->vertical_interrupt());
}

variable_types: param int


decompiled_code:
int *__fastcall TMS34061_register_w(unsigned int a1, int a2)
{
unsigned int v2; // ecx
int v3; // esi
int *result; // rax
unsigned int v5; // eax

v2 = a1 >> 2;
if ( (a1 & 2) != 0 )
v3 = LOBYTE(regs[v2]) | (a2 << 8);
else
v3 = a2 | regs[v2] & 0xFF00;
result = regs;
regs[v2] = v3;
if ( v2 == 10 )
{
v5 = cpu_getscanlinetime((unsigned int)dword_C88);
result = (int *)timer_reset(timer, v5);
}
return result;
}

canonical_decompiled_code:
int *__fastcall func16(unsigned int a1, int a2)
{
unsigned int v2; // ecx
int v3; // esi
int *result; // rax
unsigned int v5; // eax

v2 = a1 >> 2;
if ( (a1 & 2) != 0 )
v3 = LOBYTE(regs[v2]) | (a2 << 8);
else
v3 = a2 | regs[v2] & 0xFF00;
result = regs;
regs[v2] = v3;
if ( v2 == 10 )
{
v5 = cpu_getscanlinetime((unsigned int)dword_C88);
result = (int *)timer_reset(timer, v5);
}
return result;
}

original_code:
static inline void TMS34061_register_w(offs_t offset,data_t data)
{
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  regs[reg] = ((regs[reg] & 0xff) | (data << 8));
 }
 else
 {
  regs[reg] = ((regs[reg] & 0xff00) | data);
 }
 switch (reg)
 {
 case 10:
  timer_reset(timer, cpu_getscanlinetime(regs[reg]));
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
}

canonical_original_code:
static inline void TMS34061_register_w(unsigned int offset, unsigned int data)
{
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  regs[reg] = ((regs[reg] & 0xff) | (data << 8));
 }
 else
 {
  regs[reg] = ((regs[reg] & 0xff00) | data);
 }
 switch (reg)
 {
 case 10:
  timer_reset(timer, cpu_getscanlinetime(regs[reg]));
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
}

variable_types:
offset
unsigned int

variable_types: status int


decompiled_code:
int *__fastcall TMS34061_w(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebp
unsigned int v3; // er13
int *result; // rax

v2 = (*(__int64 (**)(void))(intf + 16))();
v3 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
result = (int *)(*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( (_DWORD)result == 2 )
return TMS34061_register_w(v2, a2);
if ( (int)result <= 2 )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = (int *)TMS34061_xypixel_w(v2, a2);
return result;
}
return TMS34061_register_w(v2, a2);
}
if ( (_DWORD)result == 3 )
result = (int *)(*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(v2, v3, a2);
return result;
}

canonical_decompiled_code:
int *__fastcall func17(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebp
unsigned int v3; // er13
int *result; // rax

v2 = (*(__int64 (**)(void))(intf + 16))();
v3 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
result = (int *)(*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( (_DWORD)result == 2 )
return func16(v2, a2);
if ( (int)result <= 2 )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = (int *)func8(v2, a2);
return result;
}
return func16(v2, a2);
}
if ( (_DWORD)result == 3 )
result = (int *)(*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(v2, v3, a2);
return result;
}

original_code:
void TMS34061_w(offs_t offset,data_t data)
{
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  TMS34061_register_w(col, data);
  break;
 case 1:
  TMS34061_xypixel_w(col, data);
  break;
 case 3:
  intf->setpixel(col, row, data);
  break;
 default:
     break;
 }
}

canonical_original_code:
void TMS34061_w(unsigned int offset, unsigned int data)
{
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  TMS34061_register_w(col, data);
  break;
 case 1:
  TMS34061_xypixel_w(col, data);
  break;
 case 3:
  intf->setpixel(col, row, data);
  break;
 default:
     break;
 }
}

variable_types: col int

variable_types: row int


firqhandler

decompiled_code:
__int64 __fastcall firqhandler(int a1)
{
return cpu_set_irq_line(1LL, 1LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func19(int a1)
{
return cpu_set_irq_line(1LL, 1LL, a1 != 0);
}

original_code:
static void firqhandler(int irq)
{
 cpu_set_irq_line(1,1,irq ? 1 : 0);
}

variable_types: irq int


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

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

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

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

original_code:
static int capbowl_interrupt(void)
{
 if (readinputport(4) & 1)
  return nmi_interrupt();
 return ignore_interrupt();
}

canonical_original_code:
static int capbowl_interrupt()
{
 if (readinputport(4) & 1)
  return nmi_interrupt();
 return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall track_reset_w(unsigned int a1, unsigned int a2)
{
track = input_port_2_r();
dword_C2C = input_port_3_r(a1);
return watchdog_reset_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1, unsigned int a2)
{
track = input_port_2_r();
dword_C2C = input_port_3_r(a1);
return watchdog_reset_w(a1, a2);
}

original_code:
static void track_reset_w(offs_t offset,data_t data)
{
 track[0] = input_port_2_r(offset);
 track[1] = input_port_3_r(offset);
 watchdog_reset_w(offset,data);
}

canonical_original_code:
static void track_reset_w(unsigned int offset, unsigned int data)
{
 track[0] = input_port_2_r(offset);
 track[1] = input_port_3_r(offset);
 watchdog_reset_w(offset,data);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall capbowl_sndcmd_w(unsigned int a1, unsigned int a2)
{
cpu_cause_interrupt(1LL, 1LL);
return soundlatch_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned int a1, unsigned int a2)
{
cpu_cause_interrupt(1LL, 1LL);
return soundlatch_w(a1, a2);
}

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

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


decompiled_code:
__int64 __fastcall track_1_r(unsigned int a1)
{
char v1; // bl

v1 = input_port_1_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_3_r(a1) - (_BYTE)dword_C2C) & 0xFu;
}

canonical_decompiled_code:
__int64 __fastcall func23(unsigned int a1)
{
char v1; // bl

v1 = input_port_1_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_3_r(a1) - (_BYTE)dword_C2C) & 0xFu;
}

original_code:
static data_t track_1_r(offs_t offset)
{
 return (input_port_1_r(offset) & 0xf0) | ((input_port_3_r(offset) - track[1]) & 0x0f);
}

canonical_original_code:
static unsigned int track_1_r(unsigned int offset)
{
 return (input_port_1_r(offset) & 0xf0) | ((input_port_3_r(offset) - track[1]) & 0x0f);
}


decompiled_code:
__int64 __fastcall track_0_r(unsigned int a1)
{
char v1; // bl

v1 = input_port_0_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_2_r(a1) - (_BYTE)track) & 0xFu;
}

canonical_decompiled_code:
__int64 __fastcall func24(unsigned int a1)
{
char v1; // bl

v1 = input_port_0_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_2_r(a1) - (_BYTE)track) & 0xFu;
}

original_code:
static data_t track_0_r(offs_t offset)
{
 return (input_port_0_r(offset) & 0xf0) | ((input_port_2_r(offset) - track[0]) & 0x0f);
}

canonical_original_code:
static unsigned int track_0_r(unsigned int offset)
{
 return (input_port_0_r(offset) & 0xf0) | ((input_port_2_r(offset) - track[0]) & 0x0f);
}


decompiled_code:
_BOOL8 __fastcall TMS34061_start(__int64 a1)
{
intf = a1;
regs[0] = 16;
dword_C64 = 32;
dword_C68 = 496;
dword_C6C = 512;
dword_C70 = 4;
dword_C74 = 16;
dword_C78 = 240;
dword_C7C = 256;
dword_C80 = 0;
dword_C84 = 0;
dword_C88 = 0;
unk_C8C = 28672;
dword_C90 = 1536;
dword_C94 = 0;
dword_C98 = 16;
dword_C9C = 0;
dword_CA0 = 0;
dword_CA4 = 0;
timer = timer_pulse(
(unsigned int)(0x40000000 / (int)*(float *)(*(_QWORD *)(Machine + 824LL) + 640LL)),
*(unsigned int *)(a1 + 40),
TMS34061_intcallback);
return timer == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func25(__int64 a1)
{
intf = a1;
regs[0] = 16;
dword_C64 = 32;
dword_C68 = 496;
dword_C6C = 512;
dword_C70 = 4;
dword_C74 = 16;
dword_C78 = 240;
dword_C7C = 256;
dword_C80 = 0;
dword_C84 = 0;
dword_C88 = 0;
unk_C8C = 28672;
dword_C90 = 1536;
dword_C94 = 0;
dword_C98 = 16;
dword_C9C = 0;
dword_CA0 = 0;
dword_CA4 = 0;
timer = timer_pulse(
(unsigned int)(0x40000000 / (int)*(float *)(*(_QWORD *)(Machine + 824LL) + 640LL)),
*(unsigned int *)(a1 + 40),
TMS34061_intcallback);
return timer == 0;
}

original_code:
int TMS34061_start(struct TMS34061interface *interface)
{
 intf = interface;
 regs[0] = 0x10;
 regs[1] = 0x20;
 regs[2] = 0x1f0;
 regs[3] = 0x200;
 regs[4] = 0x04;
 regs[5] = 0x10;
 regs[6] = 0xf0;
 regs[7] = 0x100;
 regs[8] = 0x00;
 regs[9] = 0x00;
 regs[10] = 0x00;
 regs[11] = 0x7000;
 regs[12] = 0x600;
 regs[13] = 0x00;
 regs[14] = 0x10;
 regs[15] = 0x00;
 regs[16] = 0x00;
 regs[17] = 0x00;
 timer = timer_pulse(((1<<30) / ((timer_tm)(Machine->drv->frames_per_second))),
                     intf->cpu, TMS34061_intcallback);
 return !timer;
}

variable_types: struct TMS34061interface { int (*getfunction)(int offset); int (*getrowaddress)(int offset); int (*getcoladdress)(int offset); int (*getpixel)(int col, int row); void (*setpixel)(int col, int row, int pixel); int cpu; int (*vertical_interrupt)(); } *


original_code:
int capbowl_vh_start(void)
{
 int i;
 if ((raw_video_ram = (unsigned char*)malloc(256 * 256)) == 0)
 {
  return 1;
 }
    if (TMS34061_start(&tms34061_interface))
 {
  free(raw_video_ram);
  return 1;
 }
 max_row = Machine->visible_area.max_y;
 max_col = Machine->visible_area.max_x;
 max_col_offset = (max_col + 1) / 2 + 0x20;
 memset(raw_video_ram, 0, 256*256);
 palette_init_used_colors();
 memset(color_count, 0, sizeof(color_count));
 memset(dirty_row, 1, sizeof(dirty_row));
 for (i = 0; i < max_row * 16; i+=16)
 {
  palette_used_colors[i] = (1|2);
  color_count[i] = max_col + 1;
 }
 return 0;
}

canonical_original_code:
int capbowl_vh_start()
{
 int i;
 if ((raw_video_ram = (unsigned char *)malloc(256 * 256)) == 0)
 {
  return 1;
 }
    if (TMS34061_start(&tms34061_interface))
 {
  free(raw_video_ram);
  return 1;
 }
 max_row = Machine->visible_area.max_y;
 max_col = Machine->visible_area.max_x;
 max_col_offset = (max_col + 1) / 2 + 0x20;
 memset(raw_video_ram, 0, 256*256);
 palette_init_used_colors();
 memset(color_count, 0, sizeof(color_count));
 memset(dirty_row, 1, sizeof(dirty_row));
 for (i = 0; i < max_row * 16; i+=16)
 {
  palette_used_colors[i] = (1|2);
  color_count[i] = max_col + 1;
 }
 return 0;
}

variable_types: i int


decompiled_code:
__int64 TMS34061_stop()
{
return timer_remove(timer);
}

canonical_decompiled_code:
__int64 func27()
{
return timer_remove(timer);
}

original_code:
void TMS34061_stop(void)
{
 timer_remove(timer);
}

canonical_original_code:
void TMS34061_stop()
{
 timer_remove(timer);
}


decompiled_code:
__int64 capbowl_vh_stop()
{
free(raw_video_ram);
return TMS34061_stop();
}

canonical_decompiled_code:
__int64 func28()
{
free(raw_video_ram);
return func27();
}

original_code:
void capbowl_vh_stop(void)
{
 free(raw_video_ram);
 TMS34061_stop();
}

canonical_original_code:
void capbowl_vh_stop()
{
 free(raw_video_ram);
 TMS34061_stop();
}


decompiled_code:
_BOOL8 TMS34061_display_blanked()
{
return (dword_C90 & 0x2000) == 0;
}

original_code:
int TMS34061_display_blanked(void)
{
 return (!(regs[12] & 0x2000));
}

canonical_original_code:
int TMS34061_display_blanked()
{
 return (!(regs[12] & 0x2000));
}