decompiled_code:
__int64 superqix_vh_start()
{
unsigned int v0; // ebx
void *v2; // r12
void *v3; // r13
void *v4; // r14
void *v5; // rax
void *v6; // rbp
void *v7; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = malloc(0x100uLL);
paletteram = v2;
if ( v2 )
{
v3 = malloc(0x7000uLL);
superqix_bitmapram = v3;
if ( v3 )
{
v4 = malloc(0x7000uLL);
superqix_bitmapram2 = v4;
if ( v4 )
{
v5 = malloc(0x7000uLL);
v6 = v5;
superqix_bitmapram_dirty = v5;
if ( v5 )
{
memset(v5, 1, 0x7000uLL);
v7 = malloc(0x7000uLL);
superqix_bitmapram2_dirty = v7;
if ( v7 )
{
memset(v7, 1, 0x7000uLL);
tmpbitmap2 = bitmap_alloc(256LL, 256LL);
if ( tmpbitmap2 )
{
sqix_minx = 0;
sqix_maxx = 127;
sqix_miny = 0;
sqix_maxy = 223;
sqix_last_bitmap = 0;
}
else
{
free(superqix_bitmapram2_dirty);
free(superqix_bitmapram_dirty);
free(superqix_bitmapram2);
free(superqix_bitmapram);
free(paletteram);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v6);
free(v4);
free(v3);
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v4);
free(v3);
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v3);
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
void *v2; // r12
void *v3; // r13
void *v4; // r14
void *v5; // rax
void *v6; // rbp
void *v7; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = malloc(0x100uLL);
paletteram = v2;
if ( v2 )
{
v3 = malloc(0x7000uLL);
superqix_bitmapram = v3;
if ( v3 )
{
v4 = malloc(0x7000uLL);
superqix_bitmapram2 = v4;
if ( v4 )
{
v5 = malloc(0x7000uLL);
v6 = v5;
superqix_bitmapram_dirty = v5;
if ( v5 )
{
memset(v5, 1, 0x7000uLL);
v7 = malloc(0x7000uLL);
superqix_bitmapram2_dirty = v7;
if ( v7 )
{
memset(v7, 1, 0x7000uLL);
tmpbitmap2 = bitmap_alloc(256LL, 256LL);
if ( tmpbitmap2 )
{
sqix_minx = 0;
sqix_maxx = 127;
sqix_miny = 0;
sqix_maxy = 223;
sqix_last_bitmap = 0;
}
else
{
free(superqix_bitmapram2_dirty);
free(superqix_bitmapram_dirty);
free(superqix_bitmapram2);
free(superqix_bitmapram);
free(paletteram);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v6);
free(v4);
free(v3);
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v4);
free(v3);
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v3);
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
free(v2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

original_code:
int superqix_vh_start(void)
{
 if (generic_vh_start() != 0)
  return 1;
 if ((paletteram = (unsigned char*)malloc(256 * sizeof(unsigned char))) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 if ((superqix_bitmapram = (unsigned char*)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 if ((superqix_bitmapram2 = (unsigned char*)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 if ((superqix_bitmapram_dirty = (unsigned char*)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(superqix_bitmapram2);
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 memset(superqix_bitmapram_dirty,1,0x7000);
 if ((superqix_bitmapram2_dirty = (unsigned char*)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(superqix_bitmapram_dirty);
  free(superqix_bitmapram2);
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 memset(superqix_bitmapram2_dirty,1,0x7000);
 if ((tmpbitmap2 = bitmap_alloc(256, 256)) == 0)
 {
  free(superqix_bitmapram2_dirty);
  free(superqix_bitmapram_dirty);
  free(superqix_bitmapram2);
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 sqix_minx=0;sqix_maxx=127;sqix_miny=0;sqix_maxy=223;
 sqix_last_bitmap=0;
 return 0;
}

canonical_original_code:
int superqix_vh_start()
{
 if (generic_vh_start() != 0)
  return 1;
 if ((paletteram = (unsigned char *)malloc(256 * sizeof(unsigned char))) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 if ((superqix_bitmapram = (unsigned char *)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 if ((superqix_bitmapram2 = (unsigned char *)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 if ((superqix_bitmapram_dirty = (unsigned char *)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(superqix_bitmapram2);
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 memset(superqix_bitmapram_dirty,1,0x7000);
 if ((superqix_bitmapram2_dirty = (unsigned char *)malloc(0x7000 * sizeof(unsigned char))) == 0)
 {
  free(superqix_bitmapram_dirty);
  free(superqix_bitmapram2);
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 memset(superqix_bitmapram2_dirty,1,0x7000);
 if ((tmpbitmap2 = bitmap_alloc(256, 256)) == 0)
 {
  free(superqix_bitmapram2_dirty);
  free(superqix_bitmapram_dirty);
  free(superqix_bitmapram2);
  free(superqix_bitmapram);
  free(paletteram);
  generic_vh_stop();
  return 1;
 }
 sqix_minx=0;sqix_maxx=127;sqix_miny=0;sqix_maxy=223;
 sqix_last_bitmap=0;
 return 0;
}


decompiled_code:
__int64 superqix_vh_stop()
{
free(superqix_bitmapram2);
free(superqix_bitmapram);
free(superqix_bitmapram_dirty);
free(superqix_bitmapram2_dirty);
bitmap_free(tmpbitmap2);
free(paletteram);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func5()
{
free(superqix_bitmapram2);
free(superqix_bitmapram);
free(superqix_bitmapram_dirty);
free(superqix_bitmapram2_dirty);
bitmap_free(tmpbitmap2);
free(paletteram);
return generic_vh_stop();
}

original_code:
void superqix_vh_stop(void)
{
 free(superqix_bitmapram2);
 free(superqix_bitmapram);
 free(superqix_bitmapram_dirty);
 free(superqix_bitmapram2_dirty);
 bitmap_free(tmpbitmap2);
 free(paletteram);
 generic_vh_stop();
}

canonical_original_code:
void superqix_vh_stop()
{
 free(superqix_bitmapram2);
 free(superqix_bitmapram);
 free(superqix_bitmapram_dirty);
 free(superqix_bitmapram2_dirty);
 bitmap_free(tmpbitmap2);
 free(paletteram);
 generic_vh_stop();
}

return_type: void


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

v2 = memory_region(129LL);
if ( (a2 & 3) != gfxbank )
{
gfxbank = a2 & 3;
memset(dirtybuffer, 1, videoram_size);
}
sqix_current_bitmap = a2 & 4;
if ( sqix_current_bitmap != sqix_last_bitmap )
{
sqix_last_bitmap = a2 & 4;
memset(superqix_bitmapram_dirty, 1, 0x7000uLL);
memset(superqix_bitmapram2_dirty, 1, 0x7000uLL);
sqix_minx = 0;
sqix_maxx = 127;
sqix_miny = 0;
sqix_maxy = 223;
}
interrupt_enable_w(a1, a2 & 8);
cpu_bankbase[1] = v2 + (int)((((a2 >> 4) & 3) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

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

v2 = memory_region(129LL);
if ( (a2 & 3) != gfxbank )
{
gfxbank = a2 & 3;
memset(dirtybuffer, 1, videoram_size);
}
sqix_current_bitmap = a2 & 4;
if ( sqix_current_bitmap != sqix_last_bitmap )
{
sqix_last_bitmap = a2 & 4;
memset(superqix_bitmapram_dirty, 1, 0x7000uLL);
memset(superqix_bitmapram2_dirty, 1, 0x7000uLL);
sqix_minx = 0;
sqix_maxx = 127;
sqix_miny = 0;
sqix_maxy = 223;
}
interrupt_enable_w(a1, a2 & 8);
cpu_bankbase[1] = v2 + (int)((((a2 >> 4) & 3) + 4) << 14);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
void superqix_0410_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (gfxbank != (data & 0x03))
 {
  gfxbank = data & 0x03;
  memset(dirtybuffer,1,videoram_size);
 }
 sqix_current_bitmap=data&4;
 if(sqix_current_bitmap !=sqix_last_bitmap)
 {
  sqix_last_bitmap=sqix_current_bitmap;
  memset(superqix_bitmapram_dirty,1,0x7000);
  memset(superqix_bitmapram2_dirty,1,0x7000);
  sqix_minx=0;sqix_maxx=127;sqix_miny=0;sqix_maxy=223;
 }
 interrupt_enable_w(offset,data & 0x08);
 bankaddress = 0x10000 + ((data & 0x30) >> 4) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void superqix_0410_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (gfxbank != (data & 0x03))
 {
  gfxbank = data & 0x03;
  memset(dirtybuffer,1,videoram_size);
 }
 sqix_current_bitmap=data&4;
 if(sqix_current_bitmap !=sqix_last_bitmap)
 {
  sqix_last_bitmap=sqix_current_bitmap;
  memset(superqix_bitmapram_dirty,1,0x7000);
  memset(superqix_bitmapram2_dirty,1,0x7000);
  sqix_minx=0;sqix_maxx=127;sqix_miny=0;sqix_maxy=223;
 }
 interrupt_enable_w(offset,data & 0x08);
 bankaddress = 0x10000 + ((data & 0x30) >> 4) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
int *__fastcall superqix_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // ecx
__int64 v4; // rcx
__int64 i; // rax
unsigned int v6; // er15
int v7; // ebp
__int64 v8; // rbx
unsigned __int8 v9; // r13
unsigned int v10; // er15
int v11; // ebp
__int64 v12; // rbx
unsigned __int8 v13; // r13
unsigned __int64 v14; // rbx
int v15; // ebx
__int64 v16; // rbp
unsigned __int8 v17; // al
int *result; // rax
int v19; // [rsp+4h] [rbp-54h]
int v20; // [rsp+4h] [rbp-54h]
char v21[72]; // [rsp+10h] [rbp-48h]

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(superqix_bitmapram_dirty, 1, 0x7000uLL);
memset(superqix_bitmapram2_dirty, 1, 0x7000uLL);
sqix_minx = 0;
sqix_maxx = 127;
sqix_miny = 0;
sqix_maxy = 223;
}
v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
v3 = 0;
if ( (*(_BYTE *)(colorram + v2) & 4) == 0 )
v3 = gfxbank + 1;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v3 + 512),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
*(_BYTE *)(colorram + v2) >> 4,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v4 = *(_QWORD *)(Machine + 792LL);
for ( i = 1LL; i != 16; ++i )
v21[i] = *(_WORD *)(v4 + 2 * i);
v21[0] = palette_transparent_pen;
if ( sqix_current_bitmap )
{
v20 = sqix_miny;
if ( sqix_miny <= sqix_maxy )
{
v10 = sqix_miny + 16;
do
{
v11 = sqix_minx;
if ( sqix_minx <= sqix_maxx )
{
v12 = sqix_minx + (__int64)(v20 << 7);
do
{
if ( *((_BYTE *)superqix_bitmapram2_dirty + v12) )
{
*((_BYTE *)superqix_bitmapram2_dirty + v12) = 0;
v13 = *((_BYTE *)superqix_bitmapram2 + v12);
plot_pixel(
tmpbitmap2,
(unsigned int)(2 * v11),
v10,
(unsigned __int8)v21[((unsigned __int64)v13 >> 4) & 0xF]);
plot_pixel(tmpbitmap2, (unsigned int)(2 * v11 + 1), v10, (unsigned __int8)v21[v13 & 0xF]);
}
++v11;
++v12;
}
while ( sqix_maxx >= v11 );
}
++v20;
++v10;
}
while ( sqix_maxy >= v20 );
}
}
else
{
v19 = sqix_miny;
if ( sqix_miny <= sqix_maxy )
{
v6 = sqix_miny + 16;
do
{
v7 = sqix_minx;
if ( sqix_minx <= sqix_maxx )
{
v8 = sqix_minx + (__int64)(v19 << 7);
do
{
if ( *((_BYTE *)superqix_bitmapram_dirty + v8) )
{
*((_BYTE *)superqix_bitmapram_dirty + v8) = 0;
v9 = *((_BYTE *)superqix_bitmapram + v8);
plot_pixel(
tmpbitmap2,
(unsigned int)(2 * v7),
v6,
(unsigned __int8)v21[((unsigned __int64)v9 >> 4) & 0xF]);
plot_pixel(tmpbitmap2, (unsigned int)(2 * v7 + 1), v6, (unsigned __int8)v21[v9 & 0xF]);
}
++v7;
++v8;
}
while ( sqix_maxx >= v7 );
}
++v19;
++v6;
}
while ( sqix_maxy >= v19 );
}
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
if ( spriteram_size )
{
v14 = 0LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 552LL),
*(unsigned __int8 *)(spriteram + v14) + ((unsigned __int8)(*(_BYTE *)(spriteram + v14 + 3) & 1) << 8),
*(_BYTE *)(spriteram + v14 + 3) >> 4,
*(_BYTE *)(spriteram + v14 + 3) & 4,
*(_BYTE *)(spriteram + v14 + 3) & 8,
*(unsigned __int8 *)(spriteram + v14 + 1),
*(unsigned __int8 *)(spriteram + v14 + 2),
Machine + 776LL,
2LL,
0LL);
v14 += 4LL;
}
while ( spriteram_size > v14 );
}
v15 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v16 = v15;
do
{
v17 = *(_BYTE *)(colorram + v16);
if ( (v17 & 8) != 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((v17 >> 2) ^ 1) & 1) + 512),
*(unsigned __int8 *)(videoram + v16) + ((unsigned __int8)(v17 & 3) << 8),
v17 >> 4,
0LL,
0LL,
(unsigned int)(8 * (v15 % 32)),
(unsigned int)(8 * (v15 / 32)),
Machine + 776LL,
2LL,
0LL);
--v16;
--v15;
}
while ( v15 >= 0 );
}
sqix_minx = 1000;
sqix_maxx = -1;
sqix_miny = 1000;
result = &sqix_maxy;
sqix_maxy = -1;
return result;
}

canonical_decompiled_code:
int *__fastcall func7(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // ecx
__int64 v4; // rcx
__int64 i; // rax
unsigned int v6; // er15
int v7; // ebp
__int64 v8; // rbx
unsigned __int8 v9; // r13
unsigned int v10; // er15
int v11; // ebp
__int64 v12; // rbx
unsigned __int8 v13; // r13
unsigned __int64 v14; // rbx
int v15; // ebx
__int64 v16; // rbp
unsigned __int8 v17; // al
int *result; // rax
int v19; // [rsp+4h] [rbp-54h]
int v20; // [rsp+4h] [rbp-54h]
char v21[72]; // [rsp+10h] [rbp-48h]

if ( palette_recalc() )
{
memset(dirtybuffer, 1, videoram_size);
memset(superqix_bitmapram_dirty, 1, 0x7000uLL);
memset(superqix_bitmapram2_dirty, 1, 0x7000uLL);
sqix_minx = 0;
sqix_maxx = 127;
sqix_miny = 0;
sqix_maxy = 223;
}
v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
v3 = 0;
if ( (*(_BYTE *)(colorram + v2) & 4) == 0 )
v3 = gfxbank + 1;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v3 + 512),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
*(_BYTE *)(colorram + v2) >> 4,
0LL,
0LL,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v4 = *(_QWORD *)(Machine + 792LL);
for ( i = 1LL; i != 16; ++i )
v21[i] = *(_WORD *)(v4 + 2 * i);
v21[0] = palette_transparent_pen;
if ( sqix_current_bitmap )
{
v20 = sqix_miny;
if ( sqix_miny <= sqix_maxy )
{
v10 = sqix_miny + 16;
do
{
v11 = sqix_minx;
if ( sqix_minx <= sqix_maxx )
{
v12 = sqix_minx + (__int64)(v20 << 7);
do
{
if ( *((_BYTE *)superqix_bitmapram2_dirty + v12) )
{
*((_BYTE *)superqix_bitmapram2_dirty + v12) = 0;
v13 = *((_BYTE *)superqix_bitmapram2 + v12);
plot_pixel(
tmpbitmap2,
(unsigned int)(2 * v11),
v10,
(unsigned __int8)v21[((unsigned __int64)v13 >> 4) & 0xF]);
plot_pixel(tmpbitmap2, (unsigned int)(2 * v11 + 1), v10, (unsigned __int8)v21[v13 & 0xF]);
}
++v11;
++v12;
}
while ( sqix_maxx >= v11 );
}
++v20;
++v10;
}
while ( sqix_maxy >= v20 );
}
}
else
{
v19 = sqix_miny;
if ( sqix_miny <= sqix_maxy )
{
v6 = sqix_miny + 16;
do
{
v7 = sqix_minx;
if ( sqix_minx <= sqix_maxx )
{
v8 = sqix_minx + (__int64)(v19 << 7);
do
{
if ( *((_BYTE *)superqix_bitmapram_dirty + v8) )
{
*((_BYTE *)superqix_bitmapram_dirty + v8) = 0;
v9 = *((_BYTE *)superqix_bitmapram + v8);
plot_pixel(
tmpbitmap2,
(unsigned int)(2 * v7),
v6,
(unsigned __int8)v21[((unsigned __int64)v9 >> 4) & 0xF]);
plot_pixel(tmpbitmap2, (unsigned int)(2 * v7 + 1), v6, (unsigned __int8)v21[v9 & 0xF]);
}
++v7;
++v8;
}
while ( sqix_maxx >= v7 );
}
++v19;
++v6;
}
while ( sqix_maxy >= v19 );
}
}
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 2LL, palette_transparent_pen);
if ( spriteram_size )
{
v14 = 0LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 552LL),
*(unsigned __int8 *)(spriteram + v14) + ((unsigned __int8)(*(_BYTE *)(spriteram + v14 + 3) & 1) << 8),
*(_BYTE *)(spriteram + v14 + 3) >> 4,
*(_BYTE *)(spriteram + v14 + 3) & 4,
*(_BYTE *)(spriteram + v14 + 3) & 8,
*(unsigned __int8 *)(spriteram + v14 + 1),
*(unsigned __int8 *)(spriteram + v14 + 2),
Machine + 776LL,
2LL,
0LL);
v14 += 4LL;
}
while ( spriteram_size > v14 );
}
v15 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v16 = v15;
do
{
v17 = *(_BYTE *)(colorram + v16);
if ( (v17 & 8) != 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((v17 >> 2) ^ 1) & 1) + 512),
*(unsigned __int8 *)(videoram + v16) + ((unsigned __int8)(v17 & 3) << 8),
v17 >> 4,
0LL,
0LL,
(unsigned int)(8 * (v15 % 32)),
(unsigned int)(8 * (v15 / 32)),
Machine + 776LL,
2LL,
0LL);
--v16;
--v15;
}
while ( v15 >= 0 );
}
sqix_minx = 1000;
sqix_maxx = -1;
sqix_miny = 1000;
result = &sqix_maxy;
sqix_maxy = -1;
return result;
}

original_code:
void superqix_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs,i;
 unsigned char pens[16];
 if (palette_recalc())
 {
  memset(dirtybuffer,1,videoram_size);
  memset(superqix_bitmapram_dirty,1,0x7000);
  memset(superqix_bitmapram2_dirty,1,0x7000);
  sqix_minx=0;sqix_maxx=127;sqix_miny=0;sqix_maxy=223;
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[(colorram[offs] & 0x04) ? 0 : (1 + gfxbank)],
     videoram[offs] + 256 * (colorram[offs] & 0x03),
     (colorram[offs] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for(i=1;i<16;i++)
  pens[i]=Machine->pens[i];
 pens[0]=palette_transparent_pen;
 if(sqix_current_bitmap==0)
 {
  int x,y;
  for (y = sqix_miny;y <= sqix_maxy;y++)
  {
   for (x = sqix_minx;x <= sqix_maxx;x++)
   {
    int sx,sy,d;
    if(superqix_bitmapram_dirty[y*128+x])
    {
     superqix_bitmapram_dirty[y*128+x]=0;
     d = superqix_bitmapram[y*128+x];
     sx = 2*x;
     sy = y+16;
     plot_pixel(tmpbitmap2, sx , sy, pens[d >> 4]);
     plot_pixel(tmpbitmap2, sx + 1, sy, pens[d & 0x0f]);
    }
   }
  }
 }
 else
 {
  int x,y;
  for (y = sqix_miny;y <= sqix_maxy;y++)
  {
   for (x = sqix_minx;x <= sqix_maxx;x++)
   {
    int sx,sy,d;
    if(superqix_bitmapram2_dirty[y*128+x])
    {
     superqix_bitmapram2_dirty[y*128+x]=0;
     d = superqix_bitmapram2[y*128+x];
     sx = 2*x;
     sy = y+16;
     plot_pixel(tmpbitmap2, sx , sy, pens[d >> 4]);
     plot_pixel(tmpbitmap2, sx + 1, sy, pens[d & 0x0f]);
    }
   }
  }
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  drawgfx(bitmap,Machine->gfx[5],
    spriteram[offs] + 256 * (spriteram[offs + 3] & 0x01),
    (spriteram[offs + 3] & 0xf0) >> 4,
    spriteram[offs + 3] & 0x04,spriteram[offs + 3] & 0x08,
    spriteram[offs + 1],spriteram[offs + 2],
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x08)
  {
   int sx,sy;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[(colorram[offs] & 0x04) ? 0 : 1],
     videoram[offs] + 256 * (colorram[offs] & 0x03),
     (colorram[offs] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 sqix_minx=1000;sqix_maxx=-1;sqix_miny=1000;sqix_maxy=-1;
}

canonical_original_code:
void superqix_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int i;
 unsigned char pens[16];
 if (palette_recalc())
 {
  memset(dirtybuffer,1,videoram_size);
  memset(superqix_bitmapram_dirty,1,0x7000);
  memset(superqix_bitmapram2_dirty,1,0x7000);
  sqix_minx=0;sqix_maxx=127;sqix_miny=0;sqix_maxy=223;
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[(colorram[offs] & 0x04) ? 0 : (1 + gfxbank)],
     videoram[offs] + 256 * (colorram[offs] & 0x03),
     (colorram[offs] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for(i=1;i<16;i++)
  pens[i]=Machine->pens[i];
 pens[0]=palette_transparent_pen;
 if(sqix_current_bitmap==0)
 {
  int x; int y;
  for (y = sqix_miny;y <= sqix_maxy;y++)
  {
   for (x = sqix_minx;x <= sqix_maxx;x++)
   {
    int sx; int sy; int d;
    if(superqix_bitmapram_dirty[y*128+x])
    {
     superqix_bitmapram_dirty[y*128+x]=0;
     d = superqix_bitmapram[y*128+x];
     sx = 2*x;
     sy = y+16;
     plot_pixel(tmpbitmap2, sx , sy, pens[d >> 4]);
     plot_pixel(tmpbitmap2, sx + 1, sy, pens[d & 0x0f]);
    }
   }
  }
 }
 else
 {
  int x; int y;
  for (y = sqix_miny;y <= sqix_maxy;y++)
  {
   for (x = sqix_minx;x <= sqix_maxx;x++)
   {
    int sx; int sy; int d;
    if(superqix_bitmapram2_dirty[y*128+x])
    {
     superqix_bitmapram2_dirty[y*128+x]=0;
     d = superqix_bitmapram2[y*128+x];
     sx = 2*x;
     sy = y+16;
     plot_pixel(tmpbitmap2, sx , sy, pens[d >> 4]);
     plot_pixel(tmpbitmap2, sx + 1, sy, pens[d & 0x0f]);
    }
   }
  }
 }
 copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  drawgfx(bitmap,Machine->gfx[5],
    spriteram[offs] + 256 * (spriteram[offs + 3] & 0x01),
    (spriteram[offs + 3] & 0xf0) >> 4,
    spriteram[offs + 3] & 0x04,spriteram[offs + 3] & 0x08,
    spriteram[offs + 1],spriteram[offs + 2],
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x08)
  {
   int sx; int sy;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(bitmap,Machine->gfx[(colorram[offs] & 0x04) ? 0 : 1],
     videoram[offs] + 256 * (colorram[offs] & 0x03),
     (colorram[offs] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 sqix_minx=1000;sqix_maxx=-1;sqix_miny=1000;sqix_maxy=-1;
}

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

variable_types: offs int

variable_types: i int

variable_types:
pens
unsigned char [16]

variable_types: sx int

variable_types: sy int

variable_types: x int

variable_types: y int

variable_types: d int


decompiled_code:
__int64 __fastcall sqix_interrupt(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = loop_0 + 1;
loop_0 = v2;
if ( v2 <= 2 )
return 0LL;
if ( v2 == 6 )
loop_0 = 0;
return nmi_interrupt(a1, a2, 0LL);
}

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

v2 = loop_0 + 1;
loop_0 = v2;
if ( v2 <= 2 )
return 0LL;
if ( v2 == 6 )
loop_0 = 0;
return nmi_interrupt(a1, a2, 0LL);
}

original_code:
int sqix_interrupt(void)
{
 static int loop=0;
 loop++;
 if(loop>2) {
  if(loop==6) loop=0;
  return nmi_interrupt();
 }
 else
  return 0;
}

canonical_original_code:
int sqix_interrupt()
{
 static int loop = 0;
 loop++;
 if(loop>2) {
  if(loop==6) loop=0;
  return nmi_interrupt();
 }
 else
  return 0;
}

variable_types: loop int

return_type: int


decompiled_code:
void *init_kuniokun()
{
void *result; // rax

mcu_type = 133;
result = &kuniokun_xor_table;
mcu_encrypt_table = (__int64)&kuniokun_xor_table;
mcu_encrypt_table_len = 42;
return result;
}

canonical_decompiled_code:
void *func4()
{
void *result; // rax

mcu_type = 133;
result = &kuniokun_xor_table;
mcu_encrypt_table = (__int64)&kuniokun_xor_table;
mcu_encrypt_table_len = 42;
return result;
}

original_code:
void init_kuniokun( void )
{
 mcu_type = 0x85;
 mcu_encrypt_table = kuniokun_xor_table;
 mcu_encrypt_table_len = 0x2a;
}

canonical_original_code:
void init_kuniokun()
{
 mcu_type = 0x85;
 mcu_encrypt_table = kuniokun_xor_table;
 mcu_encrypt_table_len = 0x2a;
}


decompiled_code:
void *init_renegade()
{
void *result; // rax

mcu_type = 218;
result = &renegade_xor_table;
mcu_encrypt_table = (__int64)&renegade_xor_table;
mcu_encrypt_table_len = 55;
return result;
}

canonical_decompiled_code:
void *func5()
{
void *result; // rax

mcu_type = 218;
result = &renegade_xor_table;
mcu_encrypt_table = (__int64)&renegade_xor_table;
mcu_encrypt_table_len = 55;
return result;
}

original_code:
void init_renegade( void )
{
 mcu_type = 0xda;
 mcu_encrypt_table = renegade_xor_table;
 mcu_encrypt_table_len = 0x37;
}

canonical_original_code:
void init_renegade()
{
 mcu_type = 0xda;
 mcu_encrypt_table = renegade_xor_table;
 mcu_encrypt_table_len = 0x37;
}


decompiled_code:
__int64 mcu_reset_r()
{
mcu_key = -1;
mcu_input_size = 0LL;
mcu_output_byte = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
mcu_key = -1;
mcu_input_size = 0LL;
mcu_output_byte = 0;
return 0LL;
}

original_code:
static data_t mcu_reset_r(offs_t offset){
 mcu_key = -1;
 mcu_input_size = 0;
 mcu_output_byte = 0;
 return 0;
}

canonical_original_code:
static unsigned int mcu_reset_r(unsigned int offset){
 mcu_key = -1;
 mcu_input_size = 0;
 mcu_output_byte = 0;
 return 0;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall mcu_w(__int64 a1, char a2)
{
__int64 result; // rax
char v3; // dl

mcu_output_byte = 0;
result = (unsigned int)mcu_key;
if ( mcu_key < 0 )
{
mcu_key = 0;
mcu_input_size = 1LL;
mcu_buffer[0] = a2;
}
else
{
v3 = *(_BYTE *)(mcu_encrypt_table + mcu_key++);
if ( (_DWORD)result + 1 == mcu_encrypt_table_len )
mcu_key = 0;
result = mcu_input_size;
if ( (unsigned __int64)mcu_input_size <= 5 )
{
++mcu_input_size;
mcu_buffer[result] = v3 ^ a2;
}
}
return result;
}

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

mcu_output_byte = 0;
result = (unsigned int)mcu_key;
if ( mcu_key < 0 )
{
mcu_key = 0;
mcu_input_size = 1LL;
mcu_buffer[0] = a2;
}
else
{
v3 = *(_BYTE *)(mcu_encrypt_table + mcu_key++);
if ( (_DWORD)result + 1 == mcu_encrypt_table_len )
mcu_key = 0;
result = mcu_input_size;
if ( (unsigned __int64)mcu_input_size <= 5 )
{
++mcu_input_size;
mcu_buffer[result] = v3 ^ a2;
}
}
return result;
}

original_code:
static void mcu_w(offs_t offset,data_t data){
 mcu_output_byte = 0;
 if( mcu_key<0 ){
  mcu_key = 0;
  mcu_input_size = 1;
  mcu_buffer[0] = data;
 }
 else {
  data ^= mcu_encrypt_table[mcu_key];
  if( ++mcu_key==mcu_encrypt_table_len) mcu_key = 0;
  if( mcu_input_size<6 ) mcu_buffer[mcu_input_size++] = data;
 }
}

canonical_original_code:
static void mcu_w(unsigned int offset, unsigned int data){
 mcu_output_byte = 0;
 if( mcu_key<0 ){
  mcu_key = 0;
  mcu_input_size = 1;
  mcu_buffer[0] = data;
 }
 else {
  data ^= mcu_encrypt_table[mcu_key];
  if( ++mcu_key==mcu_encrypt_table_len) mcu_key = 0;
  if( mcu_input_size<6 ) mcu_buffer[mcu_input_size++] = data;
 }
}


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

mcu_input_size = 0LL;
mcu_output_byte = 0;
result = (unsigned __int8)mcu_buffer[0];
if ( mcu_buffer[0] == 16 )
{
result = (unsigned int)mcu_type;
mcu_buffer[0] = mcu_type;
}
return result;
}

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

mcu_input_size = 0LL;
mcu_output_byte = 0;
result = (unsigned __int8)mcu_buffer[0];
if ( mcu_buffer[0] == 16 )
{
result = (unsigned int)mcu_type;
mcu_buffer[0] = mcu_type;
}
return result;
}

variable_types: difficulty int

variable_types: stage int

variable_types: result int

variable_types:
table
unsigned short [4]

variable_types: health int

variable_types: indx int


decompiled_code:
__int64 mcu_r()
{
int v0; // eax
unsigned int v1; // edx

if ( mcu_input_size )
mcu_process_command();
v0 = mcu_output_byte;
v1 = 1;
if ( mcu_output_byte <= 5 )
{
++mcu_output_byte;
v1 = (unsigned __int8)mcu_buffer[v0];
}
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
unsigned int v1; // edx

if ( mcu_input_size )
func8();
v0 = mcu_output_byte;
v1 = 1;
if ( mcu_output_byte <= 5 )
{
++mcu_output_byte;
v1 = (unsigned __int8)mcu_buffer[v0];
}
return v1;
}

original_code:
static data_t mcu_r(offs_t offset){
 int result = 1;
 if( mcu_input_size ) mcu_process_command();
 if( mcu_output_byte<6 )
  result = mcu_buffer[mcu_output_byte++];
 return result;
}

canonical_original_code:
static unsigned int mcu_r(unsigned int offset){
 int result = 1;
 if( mcu_input_size ) mcu_process_command();
 if( mcu_output_byte<6 )
  result = mcu_buffer[mcu_output_byte++];
 return result;
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall renegade_flipscreen_w(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 == 0 ? 3 : 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 == 0 ? 3 : 0);
}

original_code:
void renegade_flipscreen_w(offs_t offset,data_t data)
{
 flipscreen = !data;
 tilemap_set_flip( 0, flipscreen?(0x2|0x1):0);
}

canonical_original_code:
void renegade_flipscreen_w(unsigned int offset, unsigned int data)
{
 flipscreen = !data;
 tilemap_set_flip( 0, flipscreen?(0x2|0x1):0);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 renegade_vh_start()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 v3; // [rsp+0h] [rbp-18h]

bg_tilemap = tilemap_create(get_bg_tilemap_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 64LL, 16LL);
LODWORD(v3) = 32;
v0 = tilemap_create(get_fg_tilemap_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
fg_tilemap = v0;
v1 = bg_tilemap;
if ( !v0 || !bg_tilemap )
return 1LL;
*(_DWORD *)(v0 + 132) = 0;
tilemap_set_scrolldx(v1, 256LL, 0LL);
tilemap_set_scrolldy(fg_tilemap, 0LL, 16LL);
tilemap_set_scrolldy(bg_tilemap, 0LL, 16LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rax
__int64 v1; // rdi
__int64 v3; // [rsp+0h] [rbp-18h]

bg_tilemap = tilemap_create(get_bg_tilemap_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 64LL, 16LL);
LODWORD(v3) = 32;
v0 = tilemap_create(get_fg_tilemap_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
fg_tilemap = v0;
v1 = bg_tilemap;
if ( !v0 || !bg_tilemap )
return 1LL;
*(_DWORD *)(v0 + 132) = 0;
tilemap_set_scrolldx(v1, 256LL, 0LL);
tilemap_set_scrolldy(fg_tilemap, 0LL, 16LL);
tilemap_set_scrolldy(bg_tilemap, 0LL, 16LL);
return 0LL;
}

original_code:
int renegade_vh_start( void )
{
 bg_tilemap = tilemap_create(get_bg_tilemap_info,tilemap_scan_rows,0x00, 16,16,64,16);
 fg_tilemap = tilemap_create(get_fg_tilemap_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 tilemap_set_scrolldx( bg_tilemap, 256, 0 );
 tilemap_set_scrolldy( fg_tilemap, 0, 16 );
 tilemap_set_scrolldy( bg_tilemap, 0, 16 );
 return 0;
}

canonical_original_code:
int renegade_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tilemap_info,tilemap_scan_rows,0x00, 16,16,64,16);
 fg_tilemap = tilemap_create(get_fg_tilemap_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 tilemap_set_scrolldx( bg_tilemap, 256, 0 );
 tilemap_set_scrolldy( fg_tilemap, 0, 16 );
 tilemap_set_scrolldy( bg_tilemap, 0, 16 );
 return 0;
}


decompiled_code:
__int64 __fastcall renegade_vh_screenrefresh(__int64 a1)
{
tilemap_set_scrollx(bg_tilemap, 0LL, *(unsigned int *)&renegade_scrollx);
tilemap_set_scrolly(bg_tilemap, 0LL, 0LL);
tilemap_set_scrolly(fg_tilemap, 0LL, 0LL);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
tilemap_set_scrollx(bg_tilemap, 0LL, *(unsigned int *)&renegade_scrollx);
tilemap_set_scrolly(bg_tilemap, 0LL, 0LL);
tilemap_set_scrolly(fg_tilemap, 0LL, 0LL);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func12(a1);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void renegade_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh )
{
 tilemap_set_scrollx( bg_tilemap, 0, renegade_scrollx );
 tilemap_set_scrolly( bg_tilemap, 0, 0 );
 tilemap_set_scrolly( fg_tilemap, 0, 0 );
 tilemap_update( 0 );
 if (palette_recalc()) tilemap_mark_all_pixels_dirty( 0 );
 tilemap_render( 0 );
 tilemap_draw( bitmap,bg_tilemap,0 );
 draw_sprites( bitmap );
 tilemap_draw( bitmap,fg_tilemap,0 );
}

canonical_original_code:
void renegade_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 tilemap_set_scrollx( bg_tilemap, 0, renegade_scrollx );
 tilemap_set_scrolly( bg_tilemap, 0, 0 );
 tilemap_set_scrolly( fg_tilemap, 0, 0 );
 tilemap_update( 0 );
 if (palette_recalc()) tilemap_mark_all_pixels_dirty( 0 );
 tilemap_render( 0 );
 tilemap_draw( bitmap,bg_tilemap,0 );
 draw_sprites( bitmap );
 tilemap_draw( bitmap,fg_tilemap,0 );
}

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

variable_types: fullrefresh int


decompiled_code:
__int64 __fastcall adpcm_play_w(__int64 a1, int a2)
{
return ADPCM_play(0LL, (unsigned int)((a2 - 44) << 13), 0x4000LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2)
{
return ADPCM_play(0LL, (unsigned int)((a2 - 44) << 13), 0x4000LL);
}

original_code:
static void adpcm_play_w(offs_t offset,data_t data){
 data -= 0x2c;
 if( data >= 0 ) ADPCM_play( 0, 0x2000*data, 0x2000*2 );
}

canonical_original_code:
static void adpcm_play_w(unsigned int offset, unsigned int data){
 data -= 0x2c;
 if( data >= 0 ) ADPCM_play( 0, 0x2000*data, 0x2000*2 );
}


decompiled_code:
__int64 renegade_interrupt()
{
bool v0; // zf
__int64 result; // rax

v0 = count_2 == 0;
count_2 = count_2 == 0;
if ( v0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

canonical_decompiled_code:
__int64 func16()
{
bool v0; // zf
__int64 result; // rax

v0 = count_2 == 0;
count_2 = count_2 == 0;
if ( v0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

original_code:
static int renegade_interrupt(void){
 static int count;
 count = !count;
 if( count )
 return nmi_interrupt();
 return interrupt();
}

canonical_original_code:
static int renegade_interrupt(){
 static int count;
 count = !count;
 if( count )
 return nmi_interrupt();
 return interrupt();
}

variable_types: count int


decompiled_code:
__int64 __fastcall get_bg_tilemap_info(int a1)
{
unsigned __int8 *v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = (unsigned __int8 *)(videoram + a1);
v2 = v1[1024];
v3 = *(_QWORD *)(Machine + 8LL * (v2 & 7) + 520);
v4 = (unsigned int)*v1 % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 5);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
unsigned __int8 *v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = (unsigned __int8 *)(videoram + a1);
v2 = v1[1024];
v3 = *(_QWORD *)(Machine + 8LL * (v2 & 7) + 520);
v4 = (unsigned int)*v1 % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 5);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tilemap_info(int tile_index)
{
 const UINT8 *source = &videoram[tile_index];
 UINT8 attributes = source[0x400];
 { const struct GfxElement *gfx = Machine->gfx[(1+(attributes&0x7))]; int _code = (source[0]) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attributes>>5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_bg_tilemap_info(int tile_index)
{
 unsigned char *source = &videoram[tile_index];
 unsigned char attributes = source[0x400];
 { struct GfxElement *gfx = Machine->gfx[(1+(attributes&0x7))]; int _code = (source[0]) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attributes>>5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types:
source
unsigned char *

variable_types:
attributes
unsigned char

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


decompiled_code:
__int64 __fastcall get_fg_tilemap_info(int a1)
{
unsigned __int8 *v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned __int8 *v1; // rdi
unsigned __int8 v2; // cl
__int64 v3; // rsi
int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

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

original_code:
static void get_fg_tilemap_info(int tile_index)
{
 const UINT8 *source = &renegade_textram[tile_index];
 UINT8 attributes = source[0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((attributes&3)*256 + source[0]) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attributes>>6)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_fg_tilemap_info(int tile_index)
{
 unsigned char *source = &renegade_textram[tile_index];
 unsigned char attributes = source[0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((attributes&3)*256 + source[0]) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attributes>>6)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

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


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
unsigned __int8 *v1; // r15
__int64 result; // rax
__int64 v3; // rbx
unsigned __int8 v4; // dl
__int64 v5; // rbp
unsigned __int8 v6; // r12
int v7; // er13
unsigned int v8; // er14
unsigned int v9; // [rsp+4h] [rbp-54h]
__int64 v10; // [rsp+8h] [rbp-50h]
__int64 v11; // [rsp+10h] [rbp-48h]

v11 = Machine + 776LL;
v1 = (unsigned __int8 *)spriteram;
v10 = spriteram + 384LL;
do
{
result = *v1;
v3 = (unsigned int)(240 - result);
if ( (int)v3 > 15 )
{
v4 = v1[1];
v5 = v1[3];
v6 = v1[2];
v7 = (v4 & 0xF) + 9;
v9 = (v4 >> 4) & 3;
v8 = v4 & 0x40;
if ( v1[3] > 0xF8u )
v5 = (unsigned int)(v5 - 256);
if ( (v4 & 0x80u) != 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * v7 + 512),
(unsigned int)v6 + 1,
v9,
v4 & 0x40,
0LL,
v5,
(unsigned int)(256 - result),
v11,
2LL,
0LL);
else
v3 = (unsigned int)(256 - result);
result = drawgfx(a1, *(_QWORD *)(Machine + 8LL * v7 + 512), v6, v9, v8, 0LL, v5, v3, v11, 2LL, 0LL);
}
v1 += 4;
}
while ( (unsigned __int8 *)v10 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
unsigned __int8 *v1; // r15
__int64 result; // rax
__int64 v3; // rbx
unsigned __int8 v4; // dl
__int64 v5; // rbp
unsigned __int8 v6; // r12
int v7; // er13
unsigned int v8; // er14
unsigned int v9; // [rsp+4h] [rbp-54h]
__int64 v10; // [rsp+8h] [rbp-50h]
__int64 v11; // [rsp+10h] [rbp-48h]

v11 = Machine + 776LL;
v1 = (unsigned __int8 *)spriteram;
v10 = spriteram + 384LL;
do
{
result = *v1;
v3 = (unsigned int)(240 - result);
if ( (int)v3 > 15 )
{
v4 = v1[1];
v5 = v1[3];
v6 = v1[2];
v7 = (v4 & 0xF) + 9;
v9 = (v4 >> 4) & 3;
v8 = v4 & 0x40;
if ( v1[3] > 0xF8u )
v5 = (unsigned int)(v5 - 256);
if ( (v4 & 0x80u) != 0 )
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * v7 + 512),
(unsigned int)v6 + 1,
v9,
v4 & 0x40,
0LL,
v5,
(unsigned int)(256 - result),
v11,
2LL,
0LL);
else
v3 = (unsigned int)(256 - result);
result = drawgfx(a1, *(_QWORD *)(Machine + 8LL * v7 + 512), v6, v9, v8, 0LL, v5, v3, v11, 2LL, 0LL);
}
v1 += 4;
}
while ( (unsigned __int8 *)v10 != v1 );
return result;
}

original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
 const struct rectangle *clip = &Machine->visible_area;
 unsigned char *source = spriteram;
 unsigned char *finish = source+96*4;
 while( source<finish )
 {
  int sy = 240-source[0];
  if( sy>=16 )
  {
      int attributes = source[1];
      int sx = source[3];
      int sprite_number = source[2];
      int sprite_bank = 9 + (attributes&0xF);
      int color = (attributes>>4)&0x3;
      int xflip = attributes&0x40;
      if( sx>248 ) sx -= 256;
      if( attributes&0x80 ){
          drawgfx(bitmap,Machine->gfx[sprite_bank],
              sprite_number+1,
              color,
              xflip,0,
              sx,sy+16,
              clip,TRANSPARENCY_PEN,0);
      }
      else
   {
          sy += 16;
      }
      drawgfx(bitmap,Machine->gfx[sprite_bank],
          sprite_number,
          color,
          xflip,0,
          sx,sy,
          clip,TRANSPARENCY_PEN,0);
  }
  source+=4;
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct rectangle *clip = &Machine->visible_area;
 unsigned char *source = spriteram;
 unsigned char *finish = source+96*4;
 while( source<finish )
 {
  int sy = 240-source[0];
  if( sy>=16 )
  {
      int attributes = source[1];
      int sx = source[3];
      int sprite_number = source[2];
      int sprite_bank = 9 + (attributes&0xF);
      int color = (attributes>>4)&0x3;
      int xflip = attributes&0x40;
      if( sx>248 ) sx -= 256;
      if( attributes&0x80 ){
          drawgfx(bitmap,Machine->gfx[sprite_bank],
              sprite_number+1,
              color,
              xflip,0,
              sx,sy+16,
              clip,TRANSPARENCY_PEN,0);
      }
      else
   {
          sy += 16;
      }
      drawgfx(bitmap,Machine->gfx[sprite_bank],
          sprite_number,
          color,
          xflip,0,
          sx,sy,
          clip,TRANSPARENCY_PEN,0);
  }
  source+=4;
 }
}

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

variable_types:
finish
unsigned char *

variable_types: sy int

variable_types: attributes int

variable_types: sx int

variable_types: color int

variable_types: xflip int

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


irqhandler

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

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

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

variable_types: linestate int


decompiled_code:
__int64 __fastcall bankswitch_w(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // eax

result = a2 & 1;
if ( (_DWORD)result != bank )
{
v3 = memory_region(129LL);
bank = a2 & 1;
cpu_bankbase[1] = (-(__int64)((a2 & 1) == 0) & 0xFFFFFFFFFFFF4000LL) + v3 + 0x10000;
result = (__int64)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = cpu_setOPbase16(v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // eax

result = a2 & 1;
if ( (_DWORD)result != bank )
{
v3 = memory_region(129LL);
bank = a2 & 1;
cpu_bankbase[1] = (-(__int64)((a2 & 1) == 0) & 0xFFFFFFFFFFFF4000LL) + v3 + 0x10000;
result = (__int64)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = cpu_setOPbase16(v4);
}
}
return result;
}

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

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

variable_types:
RAM
unsigned char *


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

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

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

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

variable_types:
offset
unsigned int


decompiled_code:
void wms_wolfu_cmos_enable_w()
{
cmos_write_enable = 1;
}

canonical_decompiled_code:
void func0()
{
cmos_write_enable = 1;
}

original_code:
void wms_wolfu_cmos_enable_w(offs_t offset,data_t data)
{
 cmos_write_enable = 1;
}

canonical_original_code:
void wms_wolfu_cmos_enable_w(unsigned int offset, unsigned int data)
{
 cmos_write_enable = 1;
}

variable_types:
data
unsigned int


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

if ( cmos_write_enable )
{
v2 = (_WORD *)(wms_cmos_ram + a1);
result = (unsigned __int16)(*v2 & HIWORD(a2));
*v2 = result | a2;
cmos_write_enable = 0;
}
return result;
}

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

if ( cmos_write_enable )
{
v2 = (_WORD *)(wms_cmos_ram + a1);
result = (unsigned __int16)(*v2 & HIWORD(a2));
*v2 = result | a2;
cmos_write_enable = 0;
}
return result;
}

original_code:
void wms_wolfu_cmos_w(offs_t offset,data_t data)
{
 if (cmos_write_enable)
 {
  ((*(UINT16 *)((&wms_cmos_ram[offset])) = (((*(UINT16 *)(&wms_cmos_ram[offset])) & ((data) >> 16)) | (data))));
  cmos_write_enable = 0;
 }
}

canonical_original_code:
void wms_wolfu_cmos_w(unsigned int offset, unsigned int data)
{
 if (cmos_write_enable)
 {
  ((*(unsigned short *)((&wms_cmos_ram[offset])) = (((*(unsigned short *)(&wms_cmos_ram[offset])) & ((data) >> 16)) | (data))));
  cmos_write_enable = 0;
 }
}


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

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

original_code:
data_t wms_wolfu_cmos_r(offs_t offset)
{
 return (*(UINT16 *)(&wms_cmos_ram[offset]));
}

canonical_original_code:
unsigned int wms_wolfu_cmos_r(unsigned int offset)
{
 return (*(unsigned short *)(&wms_cmos_ram[offset]));
}


decompiled_code:
__int64 wms_wolfu_security_r()
{
security_status = 1;
return (unsigned __int8)security_buffer;
}

canonical_decompiled_code:
__int64 func3()
{
security_status = 1;
return (unsigned __int8)security_buffer;
}

original_code:
data_t wms_wolfu_security_r(offs_t offset)
{
 security_status = 1;
 return security_buffer;
}

canonical_original_code:
unsigned int wms_wolfu_security_r(unsigned int offset)
{
 security_status = 1;
 return security_buffer;
}


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

if ( (a2 & 0xFF0000) == 0 )
{
result = (a2 >> 4) & 1;
security_status = (a2 & 0x10) != 0;
if ( (a2 & 0x10) == 0 )
{
if ( (a2 & 0xF) != 0 )
{
security_buffer = a2;
}
else
{
v3 = security_index++;
result = (unsigned __int8)security_data[v3 & 0xF];
security_buffer = result;
}
}
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
result = (a2 >> 4) & 1;
security_status = (a2 & 0x10) != 0;
if ( (a2 & 0x10) == 0 )
{
if ( (a2 & 0xF) != 0 )
{
security_buffer = a2;
}
else
{
v3 = security_index++;
result = (unsigned __int8)security_data[v3 & 0xF];
security_buffer = result;
}
}
}
return result;
}

original_code:
void wms_wolfu_security_w(offs_t offset,data_t data)
{
 if (!(data & 0x00ff0000))
 {
  security_status = (data >> 4) & 1;
  if (!(data & 0x10))
  {
   if (data & 0x0f)
    security_buffer = data;
   else
    security_buffer = security_data[security_index++ % sizeof(security_data)];
  }
 }
}

canonical_original_code:
void wms_wolfu_security_w(unsigned int offset, unsigned int data)
{
 if (!(data & 0x00ff0000))
 {
  security_status = (data >> 4) & 1;
  if (!(data & 0x10))
  {
   if (data & 0x0f)
    security_buffer = data;
   else
    security_buffer = security_data[security_index++ % sizeof(security_data)];
  }
 }
}


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

v1 = a1 >> 1;
if ( a1 <= 7 )
return readinputport(v1);
if ( v1 != 4 )
return 0xFFFFLL;
v2 = (unsigned __int8)security_status << 12;
return v2 | (unsigned int)wms_wolfu_sound_state_r(0LL);
}

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

v1 = a1 >> 1;
if ( a1 <= 7 )
return readinputport(v1);
if ( v1 != 4 )
return 0xFFFFLL;
v2 = (unsigned __int8)security_status << 12;
return v2 | (unsigned int)func5(0LL);
}

original_code:
static data_t wms_wolfu_io_r(offs_t offset)
{
 switch (offset / 2)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   return readinputport(offset / 2);
  case 4:
   return (security_status << 12) | wms_wolfu_sound_state_r(0);
  default:
   break;
 }
 return 0xffff;
}

canonical_original_code:
static unsigned int wms_wolfu_io_r(unsigned int offset)
{
 switch (offset / 2)
 {
  case 0:
  case 1:
  case 2:
  case 3:
   return readinputport(offset / 2);
  case 4:
   return (security_status << 12) | wms_wolfu_sound_state_r(0);
  default:
   break;
 }
 return 0xffff;
}


decompiled_code:
__int64 init_mk3_common()
{
init_wolfu_generic(1);
generate_serial(528);
install_mem_read_handler(0LL, 3211248LL, 3211263LL, wms_wolfu_io_r);
return install_mem_write_handler(0LL, 3211248LL, 3211263LL, wms_wolfu_io_w);
}

canonical_decompiled_code:
__int64 func9()
{
func7(1);
func8(528);
install_mem_read_handler(0LL, 3211248LL, 3211263LL, wms_wolfu_io_r);
return install_mem_write_handler(0LL, 3211248LL, 3211263LL, wms_wolfu_io_w);
}

original_code:
static void init_mk3_common(void)
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x187ff80) >> 3), ((offs_t)(0x187ffff) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x187ff80) >> 3), ((offs_t)(0x187ffff) >> 3), wms_wolfu_io_w);
}

canonical_original_code:
static void init_mk3_common()
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x187ff80) >> 3), ((offs_t)(0x187ffff) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x187ff80) >> 3), ((offs_t)(0x187ffff) >> 3), wms_wolfu_io_w);
}


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

init_mk3_common();
wms_speedup_pc = -7182320;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151288LL, 2151291LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

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

func9();
wms_speedup_pc = -7182320;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151288LL, 2151291LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

original_code:
void init_mk3(void)
{
 init_mk3_common();
 wms_speedup_pc = (0xff926810); wms_speedup_offset = ((0x1069bd0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x1069bd0) & ~0x1f) >> 3), ((offs_t)((0x1069bd0) | 0x1f) >> 3), wms_generic_speedup_3);;
}

canonical_original_code:
void init_mk3()
{
 init_mk3_common();
 wms_speedup_pc = (0xff926810); wms_speedup_offset = ((0x1069bd0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x1069bd0) & ~0x1f) >> 3), ((offs_t)((0x1069bd0) | 0x1f) >> 3), wms_generic_speedup_3);;
}


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

init_mk3_common();
wms_speedup_pc = -7182448;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151288LL, 2151291LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

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

func9();
wms_speedup_pc = -7182448;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151288LL, 2151291LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

original_code:
void init_mk3r20(void)
{
 init_mk3_common();
 wms_speedup_pc = (0xff926790); wms_speedup_offset = ((0x1069bd0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x1069bd0) & ~0x1f) >> 3), ((offs_t)((0x1069bd0) | 0x1f) >> 3), wms_generic_speedup_3);;
}

canonical_original_code:
void init_mk3r20()
{
 init_mk3_common();
 wms_speedup_pc = (0xff926790); wms_speedup_offset = ((0x1069bd0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x1069bd0) & ~0x1f) >> 3), ((offs_t)((0x1069bd0) | 0x1f) >> 3), wms_generic_speedup_3);;
}


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

init_mk3_common();
wms_speedup_pc = -7193040;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 17159312;
wms_speedup_spin[1] = 17159344;
wms_speedup_spin[2] = 17159376;
result = install_mem_read_handler(0LL, 2159048LL, 2159051LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

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

func9();
wms_speedup_pc = -7193040;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 17159312;
wms_speedup_spin[1] = 17159344;
wms_speedup_spin[2] = 17159376;
result = install_mem_read_handler(0LL, 2159048LL, 2159051LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

original_code:
void init_mk3r10(void)
{
 init_mk3_common();
 wms_speedup_pc = (0xff923e30); wms_speedup_offset = ((0x1078e50) & 0x10) >> 3; wms_speedup_spin[0] = 0x105d490; wms_speedup_spin[1] = 0x105d4b0; wms_speedup_spin[2] = 0x105d4d0; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x1078e50) & ~0x1f) >> 3), ((offs_t)((0x1078e50) | 0x1f) >> 3), wms_generic_speedup_3);;
}

canonical_original_code:
void init_mk3r10()
{
 init_mk3_common();
 wms_speedup_pc = (0xff923e30); wms_speedup_offset = ((0x1078e50) & 0x10) >> 3; wms_speedup_spin[0] = 0x105d490; wms_speedup_spin[1] = 0x105d4b0; wms_speedup_spin[2] = 0x105d4d0; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x1078e50) & ~0x1f) >> 3), ((offs_t)((0x1078e50) | 0x1f) >> 3), wms_generic_speedup_3);;
}


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

init_mk3_common();
wms_speedup_pc = -6908256;
wms_speedup_offset = 0;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151452LL, 2151455LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

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

func9();
wms_speedup_pc = -6908256;
wms_speedup_offset = 0;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151452LL, 2151455LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

original_code:
void init_umk3(void)
{
 init_mk3_common();
 wms_speedup_pc = (0xff9696a0); wms_speedup_offset = ((0x106a0e0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x106a0e0) & ~0x1f) >> 3), ((offs_t)((0x106a0e0) | 0x1f) >> 3), wms_generic_speedup_3);;
}

canonical_original_code:
void init_umk3()
{
 init_mk3_common();
 wms_speedup_pc = (0xff9696a0); wms_speedup_offset = ((0x106a0e0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x106a0e0) & ~0x1f) >> 3), ((offs_t)((0x106a0e0) | 0x1f) >> 3), wms_generic_speedup_3);;
}


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

init_mk3_common();
wms_speedup_pc = -6908288;
wms_speedup_offset = 0;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151452LL, 2151455LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

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

func9();
wms_speedup_pc = -6908288;
wms_speedup_offset = 0;
wms_speedup_spin[0] = 17161232;
wms_speedup_spin[1] = 17161264;
wms_speedup_spin[2] = 17161296;
result = install_mem_read_handler(0LL, 2151452LL, 2151455LL, &wms_generic_speedup_3);
wms_speedup_base = result;
return result;
}

original_code:
void init_umk3r11(void)
{
 init_mk3_common();
 wms_speedup_pc = (0xff969680); wms_speedup_offset = ((0x106a0e0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x106a0e0) & ~0x1f) >> 3), ((offs_t)((0x106a0e0) | 0x1f) >> 3), wms_generic_speedup_3);;
}

canonical_original_code:
void init_umk3r11()
{
 init_mk3_common();
 wms_speedup_pc = (0xff969680); wms_speedup_offset = ((0x106a0e0) & 0x10) >> 3; wms_speedup_spin[0] = 0x105dc10; wms_speedup_spin[1] = 0x105dc30; wms_speedup_spin[2] = 0x105dc50; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x106a0e0) & ~0x1f) >> 3), ((offs_t)((0x106a0e0) | 0x1f) >> 3), wms_generic_speedup_3);;
}


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

init_wolfu_generic(1);
generate_serial(528);
install_mem_read_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_r);
install_mem_write_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_w);
wms_speedup_pc = -7711472;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 16785472;
wms_speedup_spin[1] = 208;
wms_speedup_spin[2] = 176;
result = install_mem_read_handler(0LL, 2156092LL, 2156095LL, &wms_generic_speedup_1_16bit);
wms_speedup_base = result;
return result;
}

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

func7(1);
func8(528);
install_mem_read_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_r);
install_mem_write_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_w);
wms_speedup_pc = -7711472;
wms_speedup_offset = 2;
wms_speedup_spin[0] = 16785472;
wms_speedup_spin[1] = 208;
wms_speedup_spin[2] = 176;
result = install_mem_read_handler(0LL, 2156092LL, 2156095LL, &wms_generic_speedup_1_16bit);
wms_speedup_base = result;
return result;
}

original_code:
void init_nbamaxht(void)
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_w);
 wms_speedup_pc = (0xff8a5510); wms_speedup_offset = ((0x10731f0) & 0x10) >> 3; wms_speedup_spin[0] = 0x1002040; wms_speedup_spin[1] = 0xd0; wms_speedup_spin[2] = 0xb0; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x10731f0) & ~0x1f) >> 3), ((offs_t)((0x10731f0) | 0x1f) >> 3), wms_generic_speedup_1_16bit);;
}

canonical_original_code:
void init_nbamaxht()
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_w);
 wms_speedup_pc = (0xff8a5510); wms_speedup_offset = ((0x10731f0) & 0x10) >> 3; wms_speedup_spin[0] = 0x1002040; wms_speedup_spin[1] = 0xd0; wms_speedup_spin[2] = 0xb0; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x10731f0) & ~0x1f) >> 3), ((offs_t)((0x10731f0) | 0x1f) >> 3), wms_generic_speedup_1_16bit);;
}


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

init_wolfu_generic(1);
generate_serial(528);
install_mem_read_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_r);
install_mem_write_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_w);
wms_speedup_pc = -8287792;
wms_speedup_offset = 2;
result = install_mem_read_handler(0LL, 2144328LL, 2144331LL, wms_generic_speedup_1_address);
wms_speedup_base = result;
return result;
}

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

func7(1);
func8(528);
install_mem_read_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_r);
install_mem_write_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_w);
wms_speedup_pc = -8287792;
wms_speedup_offset = 2;
result = install_mem_read_handler(0LL, 2144328LL, 2144331LL, wms_generic_speedup_1_address);
wms_speedup_base = result;
return result;
}

original_code:
void init_wwfmania(void)
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_w);
 wms_speedup_pc = (0xff8189d0); wms_speedup_offset = ((0x105c250) & 0x10) >> 3; wms_speedup_base = (UINT8*)install_mem_read_handler(0, ((offs_t)((0x105c250) & ~0x1f) >> 3), ((offs_t)((0x105c250) | 0x1f) >> 3), wms_generic_speedup_1_address);;
}

canonical_original_code:
void init_wwfmania()
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_w);
 wms_speedup_pc = (0xff8189d0); wms_speedup_offset = ((0x105c250) & 0x10) >> 3; wms_speedup_base = (unsigned char *)install_mem_read_handler(0, ((offs_t)((0x105c250) & ~0x1f) >> 3), ((offs_t)((0x105c250) | 0x1f) >> 3), wms_generic_speedup_1_address);;
}


decompiled_code:
__int64 init_rmpgwt()
{
init_wolfu_generic(1);
generate_serial(528);
install_mem_read_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_r);
return install_mem_write_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_w);
}

canonical_decompiled_code:
__int64 func18()
{
func7(1);
func8(528);
install_mem_read_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_r);
return install_mem_write_handler(0LL, 3194880LL, 3194895LL, wms_wolfu_io_w);
}

original_code:
void init_rmpgwt(void)
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_w);
}

canonical_original_code:
void init_rmpgwt()
{
 init_wolfu_generic(1);
 generate_serial(528);
 install_mem_read_handler (0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_r);
 install_mem_write_handler(0, ((offs_t)(0x1860000) >> 3), ((offs_t)(0x186007f) >> 3), wms_wolfu_io_w);
}


decompiled_code:
__int64 __fastcall wms_generic_speedup_1_address(unsigned int a1)
{
unsigned __int16 v1; // bx

v1 = *(_WORD *)(wms_speedup_base + a1);
if ( wms_speedup_offset != a1 )
return v1;
if ( wms_speedup_pc == (unsigned int)cpu_get_pc() && !v1 )
cpu_spinuntil_int();
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1)
{
unsigned __int16 v1; // bx

v1 = *(_WORD *)(wms_speedup_base + a1);
if ( wms_speedup_offset != a1 )
return v1;
if ( wms_speedup_pc == (unsigned int)cpu_get_pc() && !v1 )
cpu_spinuntil_int();
return v1;
}

original_code:
static data_t wms_generic_speedup_1_address(offs_t offset)
{
 UINT16 value = (*(UINT16 *)(&wms_speedup_base[offset]));
 if (offset != wms_speedup_offset)
  return value;
 if (cpu_get_pc() == wms_speedup_pc && !value)
  cpu_spinuntil_int();
 return value;
}

canonical_original_code:
static unsigned int wms_generic_speedup_1_address(unsigned int offset)
{
 unsigned short value = (*(UINT16 *)(&wms_speedup_base[offset]));
 if (offset != wms_speedup_offset)
  return value;
 if (cpu_get_pc() == wms_speedup_pc && !value)
  cpu_spinuntil_int();
 return value;
}

variable_types:
value
unsigned short


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

if ( sound_type == 1 )
result = williams_dcs_init(1LL);
return result;
}

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

if ( sound_type == 1 )
result = williams_dcs_init(1LL);
return result;
}

original_code:
void wms_wolfu_init_machine(void)
{
 switch (sound_type)
 {
  case 1:
   williams_dcs_init(1);
   break;
 }
}

canonical_original_code:
void wms_wolfu_init_machine()
{
 switch (sound_type)
 {
  case 1:
   williams_dcs_init(1);
   break;
 }
}


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

result = 0LL;
if ( sound_type == 1 )
{
result = 0LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = williams_dcs_data_r(0LL);
}
return result;
}

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

result = 0LL;
if ( sound_type == 1 )
{
result = 0LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = williams_dcs_data_r(0LL);
}
return result;
}

original_code:
data_t wms_wolfu_sound_r(offs_t offset)
{
 if ( sound_type == 1 && Machine->sample_rate )
  return williams_dcs_data_r(0);
 return 0x0000;
}

canonical_original_code:
unsigned int wms_wolfu_sound_r(unsigned int offset)
{
 if ( sound_type == 1 && Machine->sample_rate )
  return williams_dcs_data_r(0);
 return 0x0000;
}


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

if ( !(_DWORD)a1 && sound_type == 1 )
result = williams_dcs_data_w(a1, a2);
return result;
}

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

if ( !(_DWORD)a1 && sound_type == 1 )
result = williams_dcs_data_w(a1, a2);
return result;
}

original_code:
void wms_wolfu_sound_w(offs_t offset,data_t data)
{
 if (offset)
 {
  return;
 }
 switch (sound_type)
 {
  case 1:
   williams_dcs_data_w(0, data & 0xff);
   break;
 }
}

canonical_original_code:
void wms_wolfu_sound_w(unsigned int offset, unsigned int data)
{
 if (offset)
 {
  return;
 }
 switch (sound_type)
 {
  case 1:
   williams_dcs_data_w(0, data & 0xff);
   break;
 }
}


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, wms_cmos_ram, 49152LL);
if ( a1 )
return (void *)osd_fread(a1, wms_cmos_ram, 49152LL);
return memset(wms_cmos_ram, 0, 0xC000uLL);
}

canonical_decompiled_code:
void *__fastcall func23(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, wms_cmos_ram, 49152LL);
if ( a1 )
return (void *)osd_fread(a1, wms_cmos_ram, 49152LL);
return memset(wms_cmos_ram, 0, 0xC000uLL);
}

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

variable_types:
file
void *


decompiled_code:
char *__fastcall polyplay_init_palette(_BYTE *a1)
{
char *result; // rax
unsigned int v2; // edx

result = *(char **)(Machine + 824LL);
if ( *((_DWORD *)result + 174) )
{
result = (char *)&polyplay_palette_0;
v2 = 0;
do
{
*a1 = *result;
a1[1] = result[1];
a1 += 3;
*(a1 - 1) = result[2];
++v2;
result += 3;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > v2 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(_BYTE *a1)
{
char *result; // rax
unsigned int v2; // edx

result = *(char **)(Machine + 824LL);
if ( *((_DWORD *)result + 174) )
{
result = (char *)&polyplay_palette_0;
v2 = 0;
do
{
*a1 = *result;
a1[1] = result[1];
a1 += 3;
*(a1 - 1) = result[2];
++v2;
result += 3;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > v2 );
}
return result;
}

original_code:
void polyplay_init_palette(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 static unsigned char polyplay_palette[] =
 {
  0x00,0x00,0x00,
  0xff,0xff,0xff,
  0x00,0x00,0x00,
  0xff,0x00,0x00,
  0x00,0xff,0x00,
  0xff,0xff,0x00,
  0x00,0x00,0xff,
  0xff,0x00,0xff,
  0x00,0xff,0xff,
  0xff,0xff,0xff,
 };
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  *(palette++) = polyplay_palette[3*i];
  *(palette++) = polyplay_palette[3*i+1];
  *(palette++) = polyplay_palette[3*i+2];
 }
 palette_bank = 0;
}

canonical_original_code:
void polyplay_init_palette(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 static unsigned char polyplay_palette[] = {
  0x00,0x00,0x00,
  0xff,0xff,0xff,
  0x00,0x00,0x00,
  0xff,0x00,0x00,
  0x00,0xff,0x00,
  0xff,0xff,0x00,
  0x00,0x00,0xff,
  0xff,0x00,0xff,
  0x00,0xff,0xff,
  0xff,0xff,0xff,
 };
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  *(palette++) = polyplay_palette[3*i];
  *(palette++) = polyplay_palette[3*i+1];
  *(palette++) = polyplay_palette[3*i+2];
 }
 palette_bank = 0;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

original_code:
data_t polyplay_characterram_r(offs_t offset)
{
 return polyplay_characterram[offset];
}

canonical_original_code:
unsigned int polyplay_characterram_r(unsigned int offset)
{
 return polyplay_characterram[offset];
}


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

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

original_code:
data_t polyplay_ram_r(offs_t offset)
{
 return polyplay_ram[offset];
}

canonical_original_code:
unsigned int polyplay_ram_r(unsigned int offset)
{
 return polyplay_ram[offset];
}


decompiled_code:
__int64 polyplay_sh_start()
{
char *v0; // rax
char *v1; // rax

v0 = (char *)&unk_C80 - 32;
do
{
*(_WORD *)v0 = 0x4000;
v0 += 2;
}
while ( v0 != (char *)&unk_C80 );
v1 = (char *)&unk_C80;
do
{
*(_WORD *)v1 = -16384;
v1 += 2;
}
while ( v1 != (char *)&unk_C80 + 32 );
freq2 = 110;
freq1 = 110;
channellfo = mixer_allocate_channels(2LL, &lfovol);
mixer_set_name((unsigned int)channellfo, "Polyplay #0");
mixer_set_name((unsigned int)(channellfo + 1), "Polyplay #1");
mixer_set_volume((unsigned int)channellfo, 0LL);
mixer_set_volume((unsigned int)(channellfo + 1), 0LL);
channel_playing1 = 0;
channel_playing2 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
char *v0; // rax
char *v1; // rax

v0 = (char *)&unk_C80 - 32;
do
{
*(_WORD *)v0 = 0x4000;
v0 += 2;
}
while ( v0 != (char *)&unk_C80 );
v1 = (char *)&unk_C80;
do
{
*(_WORD *)v1 = -16384;
v1 += 2;
}
while ( v1 != (char *)&unk_C80 + 32 );
freq2 = 110;
freq1 = 110;
channellfo = mixer_allocate_channels(2LL, &lfovol);
mixer_set_name((unsigned int)channellfo, "Polyplay #0");
mixer_set_name((unsigned int)(channellfo + 1), "Polyplay #1");
mixer_set_volume((unsigned int)channellfo, 0LL);
mixer_set_volume((unsigned int)(channellfo + 1), 0LL);
channel_playing1 = 0;
channel_playing2 = 0;
return 0LL;
}

original_code:
int polyplay_sh_start(const struct MachineSound *msound)
{
 int i;
 for (i = 0; i < 32 / 2; i++) {
  backgroundwave[i] = + 0x4000;
 }
 for (i = 32 / 2; i < 32; i++) {
  backgroundwave[i] = - 0x4000;
 }
 freq1 = freq2 = 110;
 channellfo = mixer_allocate_channels(2,lfovol);
 mixer_set_name(channellfo+0,"Polyplay #0");
 mixer_set_name(channellfo+1,"Polyplay #1");
 mixer_set_volume(channellfo+0,0);
 mixer_set_volume(channellfo+1,0);
 channel_playing1 = 0;
 channel_playing2 = 0;
 return 0;
}

canonical_original_code:
int polyplay_sh_start(struct MachineSound *msound)
{
 int i;
 for (i = 0; i < 32 / 2; i++) {
  backgroundwave[i] = + 0x4000;
 }
 for (i = 32 / 2; i < 32; i++) {
  backgroundwave[i] = - 0x4000;
 }
 freq1 = freq2 = 110;
 channellfo = mixer_allocate_channels(2,lfovol);
 mixer_set_name(channellfo+0,"Polyplay #0");
 mixer_set_name(channellfo+1,"Polyplay #1");
 mixer_set_volume(channellfo+0,0);
 mixer_set_volume(channellfo+1,0);
 channel_playing1 = 0;
 channel_playing2 = 0;
 return 0;
}

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


decompiled_code:
__int64 polyplay_sh_stop()
{
mixer_stop_sample((unsigned int)channellfo);
return mixer_stop_sample((unsigned int)(channellfo + 1));
}

canonical_decompiled_code:
__int64 func5()
{
mixer_stop_sample((unsigned int)channellfo);
return mixer_stop_sample((unsigned int)(channellfo + 1));
}

original_code:
void polyplay_sh_stop(void)
{
 mixer_stop_sample(channellfo+0);
 mixer_stop_sample(channellfo+1);
}

canonical_original_code:
void polyplay_sh_stop()
{
 mixer_stop_sample(channellfo+0);
 mixer_stop_sample(channellfo+1);
}


decompiled_code:
__int64 polyplay_sh_update()
{
mixer_set_sample_frequency((unsigned int)channellfo, (unsigned int)(freq1 << 6));
return mixer_set_sample_frequency((unsigned int)(channellfo + 1), (unsigned int)(freq2 << 6));
}

canonical_decompiled_code:
__int64 func6()
{
mixer_set_sample_frequency((unsigned int)channellfo, (unsigned int)(freq1 << 6));
return mixer_set_sample_frequency((unsigned int)(channellfo + 1), (unsigned int)(freq2 << 6));
}

original_code:
void polyplay_sh_update(void)
{
 mixer_set_sample_frequency(channellfo+0, sizeof(backgroundwave)*freq1 );
 mixer_set_sample_frequency(channellfo+1, sizeof(backgroundwave)*freq2 );
}

canonical_original_code:
void polyplay_sh_update()
{
 mixer_set_sample_frequency(channellfo+0, sizeof(backgroundwave)*freq1 );
 mixer_set_sample_frequency(channellfo+1, sizeof(backgroundwave)*freq2 );
}


decompiled_code:
__int64 polyplay_random_read()
{
return (unsigned int)(rand() % 255);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)(rand() % 255);
}

original_code:
data_t polyplay_random_read(offs_t offset)
{
 return rand() % 0xff;
}

canonical_original_code:
unsigned int polyplay_random_read(unsigned int offset)
{
 return rand() % 0xff;
}


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

v0 = input_port_0_r();
if ( (v0 & 0x80u) == 0 )
{
cpu_cause_interrupt(0LL, 80LL);
coin_counter_w(0LL, 1LL);
timer_set(0x40000000LL, 2LL, polyplay_timer);
}
return v0;
}

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

v0 = input_port_0_r();
if ( (v0 & 0x80u) == 0 )
{
cpu_cause_interrupt(0LL, 80LL);
coin_counter_w(0LL, 1LL);
timer_set(0x40000000LL, 2LL, polyplay_timer);
}
return v0;
}

original_code:
data_t polyplay_input_read(offs_t offset)
{
 int inp = input_port_0_r(offset);
 if ((inp & 0x80) == 0) {
  cpu_cause_interrupt(0, 0x50);
  coin_counter_w(0, 1);
  timer_set(((timer_tm)((1) * ((1<<30)))), 2, polyplay_timer);
 }
 return inp;
}

canonical_original_code:
unsigned int polyplay_input_read(unsigned int offset)
{
 int inp = input_port_0_r(offset);
 if ((inp & 0x80) == 0) {
  cpu_cause_interrupt(0, 0x50);
  coin_counter_w(0, 1);
  timer_set(((timer_tm)((1) * ((1<<30)))), 2, polyplay_timer);
 }
 return inp;
}

variable_types: inp int


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

timer_init();
timer_pulse(14316557LL, 0LL, polyplay_timer);
result = &timer2_active;
timer2_active = 0;
return result;
}

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

timer_init();
timer_pulse(14316557LL, 0LL, polyplay_timer);
result = &timer2_active;
timer2_active = 0;
return result;
}

original_code:
static void init_polyplay_sound(void)
{
 timer_init();
 timer_pulse(((1<<30) / ((timer_tm)(75))), 0, polyplay_timer);
 timer2_active = 0;
}

canonical_original_code:
static void init_polyplay_sound()
{
 timer_init();
 timer_pulse(((1<<30) / ((timer_tm)(75))), 0, polyplay_timer);
 timer2_active = 0;
}


decompiled_code:
void __fastcall set_channel1(int a1)
{
channel_playing1 = a1;
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
channel_playing1 = a1;
}

original_code:
void set_channel1(int active)
{
 channel_playing1 = active;
}

variable_types: active int


decompiled_code:
void __fastcall set_channel2(int a1)
{
channel_playing2 = a1;
}

canonical_decompiled_code:
void __fastcall func11(int a1)
{
channel_playing2 = a1;
}

original_code:
void set_channel2(int active)
{
 channel_playing2 = active;
}


decompiled_code:
__int64 __fastcall play_channel1(int a1)
{
if ( !a1 )
return polyplay_sh_stop();
freq1 = 153600 / a1 / 8;
mixer_set_volume((unsigned int)channellfo, (unsigned int)(100 * channel_playing1));
return mixer_play_sample_16((unsigned int)channellfo, &backgroundwave, 64LL, (unsigned int)(freq1 << 6), 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
if ( !a1 )
return func5();
freq1 = 153600 / a1 / 8;
mixer_set_volume((unsigned int)channellfo, (unsigned int)(100 * channel_playing1));
return mixer_play_sample_16((unsigned int)channellfo, &backgroundwave, 64LL, (unsigned int)(freq1 << 6), 1LL);
}

original_code:
void play_channel1(int data)
{
 if (data) {
  freq1 = 2457600 / 16 / data / 8;
  mixer_set_volume(channellfo+0, channel_playing1 * 100);
  mixer_play_sample_16(channellfo+0, backgroundwave, sizeof(backgroundwave), sizeof(backgroundwave)*freq1,1);
 }
 else {
  polyplay_sh_stop();
 }
}

variable_types: data int


decompiled_code:
__int64 __fastcall play_channel2(int a1)
{
if ( !a1 )
return polyplay_sh_stop();
freq2 = 153600 / a1 / 8;
mixer_set_volume((unsigned int)(channellfo + 1), (unsigned int)(100 * channel_playing2));
return mixer_play_sample_16((unsigned int)(channellfo + 1), &backgroundwave, 64LL, (unsigned int)(freq2 << 6), 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
if ( !a1 )
return func5();
freq2 = 153600 / a1 / 8;
mixer_set_volume((unsigned int)(channellfo + 1), (unsigned int)(100 * channel_playing2));
return mixer_play_sample_16((unsigned int)(channellfo + 1), &backgroundwave, 64LL, (unsigned int)(freq2 << 6), 1LL);
}

original_code:
void play_channel2(int data)
{
 if (data) {
  freq2 = 2457600 / 16 / data / 8;
  mixer_set_volume(channellfo+1, channel_playing2 * 100);
  mixer_play_sample_16(channellfo+1, backgroundwave, sizeof(backgroundwave), sizeof(backgroundwave)*freq2,1);
 }
 else {
  polyplay_sh_stop();
 }
}


decompiled_code:
__int64 polyplay_reset()
{
channel1_const = 0;
channel2_const = 0;
set_channel1(0);
play_channel1(0);
set_channel2(0);
return play_channel2(0);
}

canonical_decompiled_code:
__int64 func14()
{
channel1_const = 0;
channel2_const = 0;
func10(0);
func12(0);
func11(0);
return func13(0);
}

original_code:
void polyplay_reset(void)
{
 channel1_active = 0;
 channel1_const = 0;
 channel2_active = 0;
 channel2_const = 0;
 set_channel1(0);
 play_channel1(0);
 set_channel2(0);
 play_channel2(0);
}

canonical_original_code:
void polyplay_reset()
{
 channel1_active = 0;
 channel1_const = 0;
 channel2_active = 0;
 channel2_const = 0;
 set_channel1(0);
 play_channel1(0);
 set_channel2(0);
 play_channel2(0);
}


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

if ( a1 )
{
if ( a1 == 1 )
{
if ( channel2_const )
{
if ( a2 <= 1 )
set_channel2(0);
channel2_const = 0;
result = play_channel2(prescale2 * a2);
}
else
{
prescale2 = (a2 & 0x20) == 0 ? 1 : 16;
if ( (a2 & 4) != 0 )
{
set_channel2(1);
channel2_const = 1;
}
result = a2 & 0xFFFFFFFB;
if ( (_DWORD)result == 65 || a2 == 101 )
{
set_channel2(0);
result = play_channel2(0);
}
}
}
}
else if ( channel1_const )
{
if ( a2 <= 1 )
set_channel1(0);
channel1_const = 0;
result = play_channel1(prescale1 * a2);
}
else
{
prescale1 = (a2 & 0x20) == 0 ? 1 : 16;
if ( (a2 & 4) != 0 )
{
set_channel1(1);
channel1_const = 1;
}
result = a2 & 0xFFFFFFFB;
if ( (_DWORD)result == 65 || a2 == 101 )
{
set_channel1(0);
result = play_channel1(0);
}
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
if ( channel2_const )
{
if ( a2 <= 1 )
func11(0);
channel2_const = 0;
result = func13(prescale2 * a2);
}
else
{
prescale2 = (a2 & 0x20) == 0 ? 1 : 16;
if ( (a2 & 4) != 0 )
{
func11(1);
channel2_const = 1;
}
result = a2 & 0xFFFFFFFB;
if ( (_DWORD)result == 65 || a2 == 101 )
{
func11(0);
result = func13(0);
}
}
}
}
else if ( channel1_const )
{
if ( a2 <= 1 )
func10(0);
channel1_const = 0;
result = func12(prescale1 * a2);
}
else
{
prescale1 = (a2 & 0x20) == 0 ? 1 : 16;
if ( (a2 & 4) != 0 )
{
func10(1);
channel1_const = 1;
}
result = a2 & 0xFFFFFFFB;
if ( (_DWORD)result == 65 || a2 == 101 )
{
func10(0);
result = func12(0);
}
}
return result;
}

original_code:
void polyplay_sound_channel(offs_t offset,data_t data)
{
 switch(offset) {
 case 0x00:
  if (channel1_const) {
   if (data <= 1) {
    set_channel1(0);
   }
   channel1_const = 0;
   play_channel1(data*prescale1);
  }
  else {
   prescale1 = (data & 0x20) ? 16 : 1;
   if (data & 0x04) {
    set_channel1(1);
    channel1_const = 1;
   }
   if ((data == 0x41) || (data == 0x65) || (data == 0x45)) {
    set_channel1(0);
    play_channel1(0);
   }
  }
  break;
 case 0x01:
  if (channel2_const) {
   if (data <= 1) {
    set_channel2(0);
   }
   channel2_const = 0;
   play_channel2(data*prescale2);
  }
  else {
   prescale2 = (data & 0x20) ? 16 : 1;
   if (data & 0x04) {
    set_channel2(1);
    channel2_const = 1;
   }
   if ((data == 0x41) || (data == 0x65) || (data == 0x45)) {
    set_channel2(0);
    play_channel2(0);
   }
  }
  break;
 }
}

canonical_original_code:
void polyplay_sound_channel(unsigned int offset, unsigned int data)
{
 switch(offset) {
 case 0x00:
  if (channel1_const) {
   if (data <= 1) {
    set_channel1(0);
   }
   channel1_const = 0;
   play_channel1(data*prescale1);
  }
  else {
   prescale1 = (data & 0x20) ? 16 : 1;
   if (data & 0x04) {
    set_channel1(1);
    channel1_const = 1;
   }
   if ((data == 0x41) || (data == 0x65) || (data == 0x45)) {
    set_channel1(0);
    play_channel1(0);
   }
  }
  break;
 case 0x01:
  if (channel2_const) {
   if (data <= 1) {
    set_channel2(0);
   }
   channel2_const = 0;
   play_channel2(data*prescale2);
  }
  else {
   prescale2 = (data & 0x20) ? 16 : 1;
   if (data & 0x04) {
    set_channel2(1);
    channel2_const = 1;
   }
   if ((data == 0x41) || (data == 0x65) || (data == 0x45)) {
    set_channel2(0);
    play_channel2(0);
   }
  }
  break;
 }
}


decompiled_code:
void cabal_init_machine()
{
cabal_sound_command2 = 255;
cabal_sound_command1 = 255;
}

canonical_decompiled_code:
void func0()
{
cabal_sound_command2 = 255;
cabal_sound_command1 = 255;
}

original_code:
static void cabal_init_machine( void ) {
 cabal_sound_command1 = cabal_sound_command2 = 0xff;
}

canonical_original_code:
static void cabal_init_machine() {
 cabal_sound_command1 = cabal_sound_command2 = 0xff;
}


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

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

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

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


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

result = (unsigned int)cabal_sound_command2;
if ( a1 != 8 )
{
result = 255LL;
if ( a1 == 10 )
result = (unsigned int)cabal_sound_command1;
}
return result;
}

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

result = (unsigned int)cabal_sound_command2;
if ( a1 != 8 )
{
result = 255LL;
if ( a1 == 10 )
result = (unsigned int)cabal_sound_command1;
}
return result;
}

original_code:
static data_t cabal_snd_r(offs_t offset)
{
 switch(offset){
  case 0x08: return cabal_sound_command2;
  case 0x0a: return cabal_sound_command1;
  default: return(0xff);
 }
}

canonical_original_code:
static unsigned int cabal_snd_r(unsigned int offset)
{
 switch(offset){
  case 0x08: return cabal_sound_command2;
  case 0x0a: return cabal_sound_command1;
  default: return(0xff);
 }
}


decompiled_code:
__int64 __fastcall cabal_vh_screenrefresh(__int64 a1)
{
if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size >> 1);
draw_background(a1);
draw_sprites(a1);
return draw_text(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size >> 1);
func6(a1);
func4(a1);
return func5(a1);
}

original_code:
void cabal_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
    if (palette_recalc())
        memset(dirtybuffer, 1, videoram_size/2);
    draw_background( bitmap );
    draw_sprites( bitmap );
    draw_text( bitmap );
}

canonical_original_code:
void cabal_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
    if (palette_recalc())
        memset(dirtybuffer, 1, videoram_size/2);
    draw_background( bitmap );
    draw_sprites( bitmap );
    draw_text( bitmap );
}

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

variable_types: fullrefresh int


original_code:
static void cabal_play_adpcm( int channel, int which ){
 if( which!=0xff ){
  unsigned char *RAM = memory_region(REGION_SOUND1);
  int offset = channel*0x10000;
  int start, len;
  which = which&0x7f;
  if( which ){
   which = which*2+0x100;
   start = RAM[offset+which] + 256*RAM[offset+which+1];
   len = (RAM[offset+start]*256 + RAM[offset+start+1])*2;
   start+=2;
   ADPCM_play( channel,offset+start,len );
  }
 }
}

canonical_original_code:
static void cabal_play_adpcm(int channel, int which){
 if( which!=0xff ){
  unsigned char *RAM = memory_region(REGION_SOUND1);
  int offset = channel*0x10000;
  int start; int len;
  which = which&0x7f;
  if( which ){
   which = which*2+0x100;
   start = RAM[offset+which] + 256*RAM[offset+which+1];
   len = (RAM[offset+start]*256 + RAM[offset+start+1])*2;
   start+=2;
   ADPCM_play( channel,offset+start,len );
  }
 }
}

variable_types: channel int

variable_types: which int

variable_types: offset int

variable_types: start int

variable_types: len int


decompiled_code:
void __fastcall cabal_snd_w(int a1, int a2)
{
if ( a1 )
{
if ( a1 == 2 )
cabal_play_adpcm(1u, a2);
}
else
{
cabal_play_adpcm(0, a2);
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, int a2)
{
if ( a1 )
{
if ( a1 == 2 )
func8(1u, a2);
}
else
{
func8(0, a2);
}
}

original_code:
static void cabal_snd_w(offs_t offset,data_t data)
{
 switch( offset ){
  case 0x00: cabal_play_adpcm( 0, data ); break;
  case 0x02: cabal_play_adpcm( 1, data ); break;
     }
}

canonical_original_code:
static void cabal_snd_w(unsigned int offset, unsigned int data)
{
 switch( offset ){
  case 0x00: cabal_play_adpcm( 0, data ); break;
  case 0x02: cabal_play_adpcm( 1, data ); break;
     }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

if ( a1 )
{
if ( a1 == 2 )
cabal_sound_command2 = (unsigned __int8)a2;
}
else
{
cabal_sound_command1 = a2;
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

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

if ( a1 )
{
if ( a1 == 2 )
cabal_sound_command2 = (unsigned __int8)a2;
}
else
{
cabal_sound_command1 = a2;
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

original_code:
static void cabal_sndcmd_w(offs_t offset,data_t data) {
 switch (offset) {
  case 0x0:
   cabal_sound_command1 = data;
   cpu_cause_interrupt( 1, -2 );
  break;
  case 0x2:
   cabal_sound_command2 = data & 0xff;
  break;
  case 0x8:
  break;
 }
}

canonical_original_code:
static void cabal_sndcmd_w(unsigned int offset, unsigned int data) {
 switch (offset) {
  case 0x0:
   cabal_sound_command1 = data;
   cpu_cause_interrupt( 1, -2 );
  break;
  case 0x2:
   cabal_sound_command2 = data & 0xff;
  break;
  case 0x8:
  break;
 }
}


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

result = readinputport(3LL);
if ( (result & 4) != 0 )
{
coin_0 = 0;
}
else if ( !coin_0 )
{
coin_0 = 1;
return result;
}
return (unsigned int)result | 4;
}

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

result = readinputport(3LL);
if ( (result & 4) != 0 )
{
coin_0 = 0;
}
else if ( !coin_0 )
{
coin_0 = 1;
return result;
}
return (unsigned int)result | 4;
}

original_code:
static data_t cabal_coin_r(offs_t offset) {
 static int coin = 0;
 int val = readinputport( 3 );
 if ( !( val & 0x04 ) ){
  if ( coin == 0 ){
   coin = 1;
   return val;
  }
 } else {
  coin = 0;
 }
  return val | 0x04;
}

canonical_original_code:
static unsigned int cabal_coin_r(unsigned int offset) {
 static int coin = 0;
 int val = readinputport( 3 );
 if ( !( val & 0x04 ) ){
  if ( coin == 0 ){
   coin = 1;
   return val;
  }
 } else {
  coin = 0;
 }
  return val | 0x04;
}

variable_types: coin int

variable_types: val int


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

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

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

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

original_code:
static data_t cabal_io_r(offs_t offset) {
 switch (offset){
  case 0x0: return readinputport(4) + (readinputport(5)<<8);
  case 0x8: return 0xff + (readinputport(0)<<8);
  case 0x10: return readinputport(1) + (readinputport(2)<<8);
  default: return (0xffff);
 }
}

canonical_original_code:
static unsigned int cabal_io_r(unsigned int offset) {
 switch (offset){
  case 0x0: return readinputport(4) + (readinputport(5)<<8);
  case 0x8: return 0xff + (readinputport(0)<<8);
  case 0x10: return readinputport(1) + (readinputport(2)<<8);
  default: return (0xffff);
 }
}


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r14
__int64 v2; // r15
__int64 result; // rax
int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rdx

v1 = Machine + 776LL;
v2 = *(_QWORD *)(Machine + 528LL);
result = (__int64)&spriteram_size;
v4 = spriteram_size - 8;
if ( spriteram_size - 8 >= 0 )
{
v5 = v4;
do
{
result = *(unsigned __int16 *)(spriteram + v5);
if ( (result & 0x100) != 0 )
{
result = (unsigned __int8)result;
v6 = *(_WORD *)(spriteram + v5 + 4) & 0x1FF;
if ( (*(_WORD *)(spriteram + v5 + 4) & 0x1FFu) > 0x100 )
v6 = *(unsigned __int16 *)(spriteram + v5 + 4) | 0xFFFFFE00;
result = drawgfx(
a1,
v2,
*(_WORD *)(spriteram + v5 + 2) & 0xFFF,
(*(unsigned __int16 *)(spriteram + v5 + 4) >> 11) & 0xF,
*(_WORD *)(spriteram + v5 + 4) & 0x400,
0LL,
v6,
result,
v1,
2LL,
15LL);
}
v5 -= 8LL;
v4 -= 8;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // r14
__int64 v2; // r15
__int64 result; // rax
int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rdx

v1 = Machine + 776LL;
v2 = *(_QWORD *)(Machine + 528LL);
result = (__int64)&spriteram_size;
v4 = spriteram_size - 8;
if ( spriteram_size - 8 >= 0 )
{
v5 = v4;
do
{
result = *(unsigned __int16 *)(spriteram + v5);
if ( (result & 0x100) != 0 )
{
result = (unsigned __int8)result;
v6 = *(_WORD *)(spriteram + v5 + 4) & 0x1FF;
if ( (*(_WORD *)(spriteram + v5 + 4) & 0x1FFu) > 0x100 )
v6 = *(unsigned __int16 *)(spriteram + v5 + 4) | 0xFFFFFE00;
result = drawgfx(
a1,
v2,
*(_WORD *)(spriteram + v5 + 2) & 0xFFF,
(*(unsigned __int16 *)(spriteram + v5 + 4) >> 11) & 0xF,
*(_WORD *)(spriteram + v5 + 4) & 0x400,
0LL,
v6,
result,
v1,
2LL,
15LL);
}
v5 -= 8LL;
v4 -= 8;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
static void draw_sprites( struct osd_bitmap *bitmap ){
    const struct rectangle *clip = &Machine->visible_area;
    const struct GfxElement *gfx = Machine->gfx[2];
    int offs;
    for( offs = spriteram_size - 8; offs >= 0; offs -= 8 ) {
        int data0 = (*(UINT16 *)(&spriteram[offs]));
        int data1 = (*(UINT16 *)(&spriteram[offs+2]));
        int data2 = (*(UINT16 *)(&spriteram[offs+4]));
        if( data0 & 0x100 ) {
            int tile_number = data1 & 0xfff;
            int color = ( data2 & 0x7800 ) >> 11;
            int sy = ( data0 & 0xff );
            int sx = ( data2 & 0x1ff );
            int hflip = ( data2 & 0x0400 );
            if ( sx > 256 )
                sx -= 512;
            drawgfx( bitmap,gfx,
                tile_number,
                color,
                hflip,0,
                sx,sy,
                clip,TRANSPARENCY_PEN,0xf );
        }
    }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap){
    struct rectangle *clip = &Machine->visible_area;
    struct GfxElement *gfx = Machine->gfx[2];
    int offs;
    for( offs = spriteram_size - 8; offs >= 0; offs -= 8 ) {
        int data0 = (*(UINT16 *)(&spriteram[offs]));
        int data1 = (*(UINT16 *)(&spriteram[offs+2]));
        int data2 = (*(UINT16 *)(&spriteram[offs+4]));
        if( data0 & 0x100 ) {
            int tile_number = data1 & 0xfff;
            int color = ( data2 & 0x7800 ) >> 11;
            int sy = ( data0 & 0xff );
            int sx = ( data2 & 0x1ff );
            int hflip = ( data2 & 0x0400 );
            if ( sx > 256 )
                sx -= 512;
            drawgfx( bitmap,gfx,
                tile_number,
                color,
                hflip,0,
                sx,sy,
                clip,TRANSPARENCY_PEN,0xf );
        }
    }
}

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

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

variable_types: offs int

variable_types: color int

variable_types: sy int

variable_types: sx int

variable_types: hflip int