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

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

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

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

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

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

variable_types:
data
unsigned int


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

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

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

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

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

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

variable_types:
offset
unsigned int

return_type: unsigned int


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

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

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

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

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

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

return_type: void


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

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

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

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

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

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


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

variable_types: last int


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

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

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

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


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

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

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

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

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

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


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

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

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

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


decompiled_code:
// attributes: thunk
__int64 mario_sh_tune_r()
{
return soundlatch_r();
}

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

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

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


decompiled_code:
// attributes: thunk
__int64 mario_sh_tuneselect_w()
{
return soundlatch_w();
}

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

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

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


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

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

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

variable_types:
source
unsigned char *

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

variable_types: count int

variable_types: attributes int

variable_types: flags int

variable_types: number int


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

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

return_type: int

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


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

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

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

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

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


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

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

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

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

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


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

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

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int


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

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

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

variable_types: linestate int


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

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

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


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

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

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

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

variable_types:
offset
unsigned int


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

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

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

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

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

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

variable_types: coin int


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

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

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

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

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

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

variable_types:
data
unsigned int

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


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

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

variable_types: 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_foreground(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r13
__int64 v3; // r14
__int64 v4; // r15
__int64 result; // rax
__int64 v6; // [rsp-30h] [rbp-78h]
__int64 v7; // [rsp+0h] [rbp-48h]
__int64 v8; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r13
__int64 v3; // r14
__int64 v4; // r15
__int64 result; // rax
__int64 v6; // [rsp-30h] [rbp-78h]
__int64 v7; // [rsp+0h] [rbp-48h]
__int64 v8; // [rsp+8h] [rbp-40h]

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

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

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

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

variable_types: sx int

variable_types: sy int

variable_types:
source
unsigned char *

variable_types: color int

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


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbp
unsigned __int64 v3; // rbx

v1 = Machine;
v2 = Machine + 776LL;
if ( videoram_size )
{
v3 = 0LL;
do
{
while ( !*(_BYTE *)(dirtybuffer + v3) )
{
if ( videoram_size <= ++v3 )
goto LABEL_6;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(v1 + 528),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 7) << 8),
(int)*(unsigned __int8 *)(colorram + v3) >> 4,
0LL,
0LL,
8 * (unsigned int)(v3 & 0x1F),
(unsigned int)(8 * ((int)v3 >> 5)),
v2,
0LL,
0LL);
*(_BYTE *)(dirtybuffer + v3++) = 0;
v1 = Machine;
}
while ( videoram_size > v3 );
LABEL_6:
v2 = v1 + 776;
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, v2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rbp
unsigned __int64 v3; // rbx

v1 = Machine;
v2 = Machine + 776LL;
if ( videoram_size )
{
v3 = 0LL;
do
{
while ( !*(_BYTE *)(dirtybuffer + v3) )
{
if ( videoram_size <= ++v3 )
goto LABEL_6;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(v1 + 528),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 7) << 8),
(int)*(unsigned __int8 *)(colorram + v3) >> 4,
0LL,
0LL,
8 * (unsigned int)(v3 & 0x1F),
(unsigned int)(8 * ((int)v3 >> 5)),
v2,
0LL,
0LL);
*(_BYTE *)(dirtybuffer + v3++) = 0;
v1 = Machine;
}
while ( videoram_size > v3 );
LABEL_6:
v2 = v1 + 776;
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, v2, 0LL, 0LL);
}

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

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

variable_types: offs int

variable_types: attributes int

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


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

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

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

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


decompiled_code:
__int64 __fastcall sound_cpu_spin_r(int a1)
{
__int64 v1; // rbx

if ( sound_cpu == 1 )
{
v1 = memory_region(130LL);
if ( (unsigned int)cpu_get_pc() != 297 )
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}
else
{
v1 = memory_region(131LL);
if ( (unsigned int)cpu_get_pc() != 297 )
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}
if ( !*(_BYTE *)(v1 + 8220) )
cpu_spinuntil_int();
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rbx

if ( sound_cpu == 1 )
{
v1 = memory_region(130LL);
if ( (unsigned int)cpu_get_pc() != 297 )
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}
else
{
v1 = memory_region(131LL);
if ( (unsigned int)cpu_get_pc() != 297 )
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}
if ( !*(_BYTE *)(v1 + 8220) )
cpu_spinuntil_int();
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}

original_code:
static data_t sound_cpu_spin_r(offs_t offset)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (cpu_get_pc()==0x129 && RAM[0x201c]==0)
  cpu_spinuntil_int();
 return RAM[0x201c+offset];
}

canonical_original_code:
static unsigned int sound_cpu_spin_r(unsigned int offset)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (cpu_get_pc()==0x129 && RAM[0x201c]==0)
  cpu_spinuntil_int();
 return RAM[0x201c+offset];
}


decompiled_code:
void seibu_rst10_ack_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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


decompiled_code:
__int64 seibu_rst18_ack_w()
{
return timer_set(0LL, 4LL, setvector_callback);
}

canonical_decompiled_code:
__int64 func3()
{
return timer_set(0LL, 4LL, setvector_callback);
}

original_code:
void seibu_rst18_ack_w(offs_t offset,data_t data)
{
 timer_set((0),RST18_CLEAR,setvector_callback);
}

canonical_original_code:
void seibu_rst18_ack_w(unsigned int offset, unsigned int data)
{
 timer_set((0),RST18_CLEAR,setvector_callback);
}


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

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

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

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

original_code:
void seibu_ym3812_irqhandler(int linestate)
{
 if (linestate)
  timer_set((0),RST10_ASSERT,setvector_callback);
 else
  timer_set((0),RST10_CLEAR,setvector_callback);
}


decompiled_code:
__int64 seibu_sound_init_1()
{
sound_cpu = 1;
return setvector_callback(0);
}

canonical_decompiled_code:
__int64 func5()
{
sound_cpu = 1;
return func0(0);
}

original_code:
void seibu_sound_init_1(void)
{
 sound_cpu=1;
 setvector_callback(VECTOR_INIT);
}

canonical_original_code:
void seibu_sound_init_1()
{
 sound_cpu=1;
 setvector_callback(VECTOR_INIT);
}


decompiled_code:
__int64 seibu_sound_init_2()
{
sound_cpu = 2;
return setvector_callback(0);
}

canonical_decompiled_code:
__int64 func6()
{
sound_cpu = 2;
return func0(0);
}

original_code:
void seibu_sound_init_2(void)
{
 sound_cpu=2;
 setvector_callback(VECTOR_INIT);
}

canonical_original_code:
void seibu_sound_init_2()
{
 sound_cpu=2;
 setvector_callback(VECTOR_INIT);
}


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

if ( sound_cpu == 1 )
result = memory_region(130LL);
else
result = memory_region(131LL);
v3 = ophw;
if ( (a2 & 1) == 0 )
result += 0x10000LL;
cpu_bankbase[1] = result;
if ( v3 == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = cpu_setOPbase16(v4);
}
return result;
}

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

if ( sound_cpu == 1 )
result = memory_region(130LL);
else
result = memory_region(131LL);
v3 = ophw;
if ( (a2 & 1) == 0 )
result += 0x10000LL;
cpu_bankbase[1] = result;
if ( v3 == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = cpu_setOPbase16(v4);
}
return result;
}

original_code:
void seibu_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (data&1) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x0000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

canonical_original_code:
void seibu_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (data&1) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x0000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}


decompiled_code:
__int64 __fastcall seibu_soundlatch_r(int a1)
{
return *(unsigned __int8 *)(seibu_shared_sound_ram + (unsigned int)(2 * a1));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return *(unsigned __int8 *)(seibu_shared_sound_ram + (unsigned int)(2 * a1));
}

original_code:
data_t seibu_soundlatch_r(offs_t offset)
{
 return seibu_shared_sound_ram[offset<<1];
}

canonical_original_code:
unsigned int seibu_soundlatch_r(unsigned int offset)
{
 return seibu_shared_sound_ram[offset<<1];
}


decompiled_code:
__int64 __fastcall install_seibu_sound_speedup(__int64 a1)
{
return install_mem_read_handler(a1, 8220LL, 8221LL, sound_cpu_spin_r);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return install_mem_read_handler(a1, 8220LL, 8221LL, sound_cpu_spin_r);
}

original_code:
void install_seibu_sound_speedup(int cpu)
{
 install_mem_read_handler(cpu, 0x201c, 0x201d, sound_cpu_spin_r);
}

variable_types: cpu int


decompiled_code:
__int64 seibu_sound_decrypt()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax
int v3[130]; // [rsp+0h] [rbp-208h] BYREF

v0 = memory_region(131LL);
qmemcpy(v3, &unk_3E0, 0x200uLL);
v1 = v0;
for ( result = 0LL; result != 98304; ++result )
*(_BYTE *)(v1 + result) ^= v3[result & 0x7F];
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax
int v3[130]; // [rsp+0h] [rbp-208h] BYREF

v0 = memory_region(131LL);
qmemcpy(v3, &unk_3E0, 0x200uLL);
v1 = v0;
for ( result = 0LL; result != 98304; ++result )
*(_BYTE *)(v1 + result) ^= v3[result & 0x7F];
return result;
}

variable_types: i int


decompiled_code:
__int64 __fastcall setvector_callback(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

switch ( a1 )
{
case 0:
irq2_1 = 255;
v1 = 255LL;
irq1_0 = 255;
break;
case 1:
irq1_0 = 215;
v1 = (unsigned __int8)irq2_1 & 0xD7;
break;
case 2:
irq1_0 = 255;
v1 = (unsigned __int8)irq2_1;
break;
case 3:
irq2_1 = 223;
v1 = (unsigned __int8)irq1_0 & 0xDF;
break;
case 4:
irq2_1 = 255;
v1 = (unsigned __int8)irq1_0;
break;
default:
v1 = irq2_1 & (unsigned int)irq1_0;
break;
}
cpu_irq_line_vector_w((unsigned int)sound_cpu, 0LL, v1);
if ( (irq2_1 & irq1_0) == 255 )
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 0LL);
else
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

switch ( a1 )
{
case 0:
irq2_1 = 255;
v1 = 255LL;
irq1_0 = 255;
break;
case 1:
irq1_0 = 215;
v1 = (unsigned __int8)irq2_1 & 0xD7;
break;
case 2:
irq1_0 = 255;
v1 = (unsigned __int8)irq2_1;
break;
case 3:
irq2_1 = 223;
v1 = (unsigned __int8)irq1_0 & 0xDF;
break;
case 4:
irq2_1 = 255;
v1 = (unsigned __int8)irq1_0;
break;
default:
v1 = irq2_1 & (unsigned int)irq1_0;
break;
}
cpu_irq_line_vector_w((unsigned int)sound_cpu, 0LL, v1);
if ( (irq2_1 & irq1_0) == 255 )
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 0LL);
else
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 1LL);
return result;
}

original_code:
static void setvector_callback(int param)
{
 static int irq1,irq2;
 switch(param)
 {
  case VECTOR_INIT:
   irq1 = irq2 = 0xff;
   break;
  case RST10_ASSERT:
   irq1 = 0xd7;
   break;
  case RST10_CLEAR:
   irq1 = 0xff;
   break;
  case RST18_ASSERT:
   irq2 = 0xdf;
   break;
  case RST18_CLEAR:
   irq2 = 0xff;
   break;
 }
 cpu_irq_line_vector_w(sound_cpu,0,irq1 & irq2);
 if ((irq1 & irq2) == 0xff)
  cpu_set_irq_line(sound_cpu,0,0);
 else
  cpu_set_irq_line(sound_cpu,0,1);
}

canonical_original_code:
static void setvector_callback(int param)
{
 static int irq1; static int irq2;
 switch(param)
 {
  case VECTOR_INIT:
   irq1 = irq2 = 0xff;
   break;
  case RST10_ASSERT:
   irq1 = 0xd7;
   break;
  case RST10_CLEAR:
   irq1 = 0xff;
   break;
  case RST18_ASSERT:
   irq2 = 0xdf;
   break;
  case RST18_CLEAR:
   irq2 = 0xff;
   break;
 }
 cpu_irq_line_vector_w(sound_cpu,0,irq1 & irq2);
 if ((irq1 & irq2) == 0xff)
  cpu_set_irq_line(sound_cpu,0,0);
 else
  cpu_set_irq_line(sound_cpu,0,1);
}

variable_types: param int


decompiled_code:
__int64 k88games_vh_start()
{
unsigned int v0; // er12

layer_colorbase = 64LL;
dword_770 = 16;
v0 = 1;
sprite_colorbase = 32;
zoom_colorbase = 48;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
return v0;
if ( !(unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
K051960_vh_stop();
}
return v0;
}
K052109_vh_stop();
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // er12

layer_colorbase = 64LL;
dword_770 = 16;
v0 = 1;
sprite_colorbase = 32;
zoom_colorbase = 48;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
return v0;
if ( !(unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
K051960_vh_stop();
}
return v0;
}
K052109_vh_stop();
return 1LL;
}

original_code:
int k88games_vh_start(void)
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 zoom_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int k88games_vh_start()
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 zoom_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall k88games_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 v3; // rdx
__int64 result; // rax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
if ( palette_recalc(a1, v2, v3, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( k88games_priority )
{
K052109_tilemap_draw(a1, 0LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
result = K051316_zoom_draw_0(a1, 0LL);
}
else
{
K052109_tilemap_draw(a1, 2LL, 16LL);
K051316_zoom_draw_0(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 1LL, 1LL);
result = K052109_tilemap_draw(a1, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 v3; // rdx
__int64 result; // rax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
if ( palette_recalc(a1, v2, v3, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( k88games_priority )
{
K052109_tilemap_draw(a1, 0LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
result = K051316_zoom_draw_0(a1, 0LL);
}
else
{
K052109_tilemap_draw(a1, 2LL, 16LL);
K051316_zoom_draw_0(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 1LL, 1LL);
result = K052109_tilemap_draw(a1, 0LL, 0LL);
}
return result;
}

original_code:
void k88games_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i;
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0;i < 16;i++)
  palette_used_colors[(zoom_colorbase + i) * 16] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (k88games_priority)
 {
  K052109_tilemap_draw(bitmap,0,0x10);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,2,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,0,0);
  K051316_zoom_draw_0(bitmap,0);
 }
 else
 {
  K052109_tilemap_draw(bitmap,2,0x10);
  K051316_zoom_draw_0(bitmap,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,0,0);
 }
}

canonical_original_code:
void k88games_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0;i < 16;i++)
  palette_used_colors[(zoom_colorbase + i) * 16] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (k88games_priority)
 {
  K052109_tilemap_draw(bitmap,0,0x10);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,2,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,0,0);
  K051316_zoom_draw_0(bitmap,0);
 }
 else
 {
  K052109_tilemap_draw(bitmap,2,0x10);
  K051316_zoom_draw_0(bitmap,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,0,0);
 }
}

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


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

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

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

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


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

konami_cpu_setlines_callback = k88games_banking;
result = memory_region(129LL) + 0x20000;
paletteram = result;
return result;
}

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

konami_cpu_setlines_callback = k88games_banking;
result = memory_region(129LL) + 0x20000;
paletteram = result;
return result;
}

original_code:
static void k88games_init_machine( void )
{
 konami_cpu_setlines_callback = k88games_banking;
 paletteram = &memory_region(REGION_CPU1)[0x20000];
}

canonical_original_code:
static void k88games_init_machine()
{
 konami_cpu_setlines_callback = k88games_banking;
 paletteram = &memory_region(REGION_CPU1)[0x20000];
}


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

speech_chip = (a2 >> 2) & 1;
UPD7759_reset_w((a2 >> 2) & 1, (a2 >> 1) & 1);
result = (unsigned int)invalid_code;
if ( !invalid_code )
result = UPD7759_start_w((unsigned int)speech_chip, (a2 & 1) == 0);
return result;
}

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

speech_chip = (a2 >> 2) & 1;
UPD7759_reset_w((a2 >> 2) & 1, (a2 >> 1) & 1);
result = (unsigned int)invalid_code;
if ( !invalid_code )
result = UPD7759_start_w((unsigned int)speech_chip, (a2 & 1) == 0);
return result;
}

original_code:
static void speech_control_w(offs_t offset,data_t data)
{
 int reset = ( ( data >> 1 ) & 1 );
 int start = ( ~data ) & 1;
 speech_chip = ( data & 4 ) ? 1 : 0;
 UPD7759_reset_w( speech_chip, reset );
 if (!invalid_code)
  UPD7759_start_w( speech_chip, start );
}

canonical_original_code:
static void speech_control_w(unsigned int offset, unsigned int data)
{
 int reset = ( ( data >> 1 ) & 1 );
 int start = ( ~data ) & 1;
 speech_chip = ( data & 4 ) ? 1 : 0;
 UPD7759_reset_w( speech_chip, reset );
 if (!invalid_code)
  UPD7759_start_w( speech_chip, start );
}

variable_types:
offset
unsigned int

variable_types: reset int

variable_types: start int


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

UPD7759_message_w((unsigned int)speech_chip);
result = total_samples[speech_chip] == a2;
invalid_code = total_samples[speech_chip] == a2;
return result;
}

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

UPD7759_message_w((unsigned int)speech_chip);
result = total_samples[speech_chip] == a2;
invalid_code = total_samples[speech_chip] == a2;
return result;
}

original_code:
static void speech_msg_w(offs_t offset,data_t data)
{
 UPD7759_message_w( speech_chip, data );
 invalid_code = (data == total_samples[speech_chip]);
}

canonical_original_code:
static void speech_msg_w(unsigned int offset, unsigned int data)
{
 UPD7759_message_w( speech_chip, data );
 invalid_code = (data == total_samples[speech_chip]);
}

variable_types:
data
unsigned int


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int k88games_interrupt(void)
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int k88games_interrupt()
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}


decompiled_code:
__int64 k88games_sh_irqtrigger_w()
{
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func12()
{
return cpu_cause_interrupt(1LL, 255LL);
}

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

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


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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = a2 & 4;
zoomreadroms = a2 & 4;
if ( (a2 & 0xF8) != 0 )
{
sprintf(v3, "5f84 = %02x", a2);
result = usrintf_showmessage(v3);
}
return result;
}

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = a2 & 4;
zoomreadroms = a2 & 4;
if ( (a2 & 0xF8) != 0 )
{
sprintf(v3, "5f84 = %02x", a2);
result = usrintf_showmessage(v3);
}
return result;
}

original_code:
static void k88games_5f84_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 zoomreadroms = data & 0x04;
 if (data & 0xf8)
 {
  char buf[40];
  sprintf(buf,"5f84 = %02x",data);
  usrintf_showmessage(buf);
 }
}

canonical_original_code:
static void k88games_5f84_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 zoomreadroms = data & 0x04;
 if (data & 0xf8)
 {
  char buf[40];
  sprintf(buf,"5f84 = %02x",data);
  usrintf_showmessage(buf);
 }
}

variable_types:
buf
char [40]


decompiled_code:
__int64 cheat_r()
{
unsigned int v0; // er12

v0 = readinputport(1LL);
if ( (readinputport(0LL) & 8) == 0 )
{
v0 = bits_0[cheat_1] & (v0 | 0x55);
cheat_1 = (cheat_1 + 1) % 4;
}
return v0;
}

canonical_decompiled_code:
__int64 func15()
{
unsigned int v0; // er12

v0 = readinputport(1LL);
if ( (readinputport(0LL) & 8) == 0 )
{
v0 = bits_0[cheat_1] & (v0 | 0x55);
cheat_1 = (cheat_1 + 1) % 4;
}
return v0;
}

original_code:
static data_t cheat_r(offs_t offset)
{
 int res;
 static int cheat = 0;
 static int bits[] = { 0xee, 0xff, 0xbb, 0xaa };
 res = readinputport(1);
 if ((readinputport(0) & 0x08) == 0)
 {
  res |= 0x55;
  res &= bits[cheat];
  cheat = (++cheat)%4;
 }
 return res;
}

canonical_original_code:
static unsigned int cheat_r(unsigned int offset)
{
 int res;
 static int cheat = 0;
 static int bits[] = { 0xee, 0xff, 0xbb, 0xaa };
 res = readinputport(1);
 if ((readinputport(0) & 0x08) == 0)
 {
  res |= 0x55;
  res &= bits[cheat];
  cheat = (++cheat)%4;
 }
 return res;
}

variable_types: res int

variable_types: cheat int

variable_types:
bits
int []


decompiled_code:
__int64 __fastcall tile_callback(int a1, int a2, _DWORD *a3, int *a4)
{
__int64 result; // rax

*a3 |= (a2 << 12) | ((unsigned __int16)*a4 << 8) & 0xF00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 4) & 0xFu);
*a4 = result;
return result;
}

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

*a3 |= (a2 << 12) | ((unsigned __int16)*a4 << 8) & 0xF00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 4) & 0xFu);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x0f) << 8) | (bank << 12);
 *color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x0f) << 8) | (bank << 12);
 *color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
__int64 __fastcall sprite_callback(__int64 a1, int *a2, int *a3)
{
__int64 result; // rax

*a3 = (*a2 >> 5) & 1;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

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

*a3 = (*a2 >> 5) & 1;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

original_code:
static void sprite_callback(int *code,int *color,int *priority,int *shadow)
{
 *priority = (*color & 0x20) >> 5;
 *color = sprite_colorbase + (*color & 0x0f);
}

canonical_original_code:
static void sprite_callback(int *code, int *color, int *priority, int *shadow)
{
 *priority = (*color & 0x20) >> 5;
 *color = sprite_colorbase + (*color & 0x0f);
}

variable_types:
priority
int *

variable_types:
shadow
int *


decompiled_code:
__int64 __fastcall zoom_callback(_DWORD *a1, int *a2)
{
__int64 result; // rax

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = ((*a2 >> 4) & 8) + zoom_colorbase + ((*a2 >> 3) & 7u);
*a2 = result;
return result;
}

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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = ((*a2 >> 4) & 8) + zoom_colorbase + ((*a2 >> 3) & 7u);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x38) >> 3) + ((*color & 0x80) >> 4);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x38) >> 3) + ((*color & 0x80) >> 4);
}


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

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

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

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

variable_types:
file
void *


decompiled_code:
__int64 __fastcall bankedram_r(unsigned int a1)
{
if ( videobank )
return *(unsigned __int8 *)(ram + a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
if ( videobank )
return *(unsigned __int8 *)(ram + a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (videobank) return ram[offset];
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (videobank) return ram[offset];
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}


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

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

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

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


decompiled_code:
__int64 mystston_vh_start()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
unsigned int v3; // er8

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
v2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)));
v3 = 0;
tmpbitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 func2()
{
size_t v0; // r12
void *v1; // rax
__int64 v2; // rax
unsigned int v3; // er8

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
v2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)));
v3 = 0;
tmpbitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
v3 = 1;
}
return v3;
}

original_code:
int mystston_vh_start(void)
{
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,2*Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}

canonical_original_code:
int mystston_vh_start()
{
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
  return 1;
 memset(dirtybuffer,1,videoram_size);
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,2*Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer);
  return 1;
 }
 return 0;
}


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

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

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

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


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

textcolor = (a2 >> 1) & 1 | (2 * (_BYTE)a2) & 2;
coin_counter_w(0LL, a2 & 0x10);
result = (void *)coin_counter_w(1LL, a2 & 0x20);
if ( (a2 & 0x80) != flipscreen )
{
flipscreen = a2 & 0x80;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

textcolor = (a2 >> 1) & 1 | (2 * (_BYTE)a2) & 2;
coin_counter_w(0LL, a2 & 0x10);
result = (void *)coin_counter_w(1LL, a2 & 0x20);
if ( (a2 & 0x80) != flipscreen )
{
flipscreen = a2 & 0x80;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void mystston_2000_w(offs_t offset,data_t data)
{
 textcolor = ((data & 0x01) << 1) | ((data & 0x02) >> 1);
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void mystston_2000_w(unsigned int offset, unsigned int data)
{
 textcolor = ((data & 0x01) << 1) | ((data & 0x02) >> 1);
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
int *__fastcall mystston_vh_screenrefresh(__int64 a1)
{
int v2; // er12
__int64 v3; // r15
int v4; // eax
_BOOL8 v5; // r9
int v6; // ecx
int v7; // edx
int v8; // eax
unsigned __int64 v9; // r12
__int64 v10; // rdi
int v11; // edx
__int64 v12; // r8
__int64 v13; // r9
__int64 v14; // rcx
int *result; // rax
int v16; // er15
__int64 v17; // r14
int v18; // eax
char v19; // dl
int v20; // esi
int v21; // ecx
int v22[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v6 = v2 & 0x1F;
v7 = v2 & 0x10;
if ( flipscreen )
{
v4 = v2 / 32;
v6 = 31 - v6;
v5 = v7 == 0;
}
else
{
v4 = v2 / -32 + 15;
v5 = v7 != 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 1) << 8),
0LL,
(unsigned int)flipscreen,
v5,
(unsigned int)(16 * v4),
(unsigned int)(16 * v6),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v8 = (unsigned __int8)*mystston_scroll;
v22[0] = -v8;
if ( flipscreen )
v22[0] = v8 + 256;
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 1LL, v22, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v9 = 0LL;
do
{
v11 = *(unsigned __int8 *)(spriteram + v9);
if ( (v11 & 1) != 0 )
{
v10 = *(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 3));
v12 = v11 & 4;
v13 = v11 & 2;
v14 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + (unsigned int)(v9 + 2)));
if ( flipscreen )
{
v14 = (unsigned int)(240 - v14);
v12 = (_DWORD)v12 == 0;
v13 = (_DWORD)v13 == 0;
}
else
{
v10 = (unsigned int)(240 - v10);
}
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 1)) + ((16 * (_WORD)v11) & 0x100u),
(v11 >> 3) & 1,
v12,
v13,
v10,
v14,
Machine + 776LL,
2LL,
0LL);
}
v9 += 4LL;
}
while ( spriteram_size > v9 );
}
result = &mystston_videoram2_size;
v16 = mystston_videoram2_size - 1;
if ( mystston_videoram2_size - 1 >= 0 )
{
v17 = v16;
do
{
v21 = v16 & 0x1F;
if ( flipscreen )
{
v18 = v16 / 32;
v21 = 31 - v21;
}
else
{
v18 = v16 / -32 + 31;
}
--v16;
v19 = *(_BYTE *)(mystston_colorram2 + v17);
v20 = *(unsigned __int8 *)(mystston_videoram2 + v17--);
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v20 + ((unsigned __int8)(v19 & 7) << 8),
(unsigned int)textcolor,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v18),
(unsigned int)(8 * v21),
Machine + 776LL,
2LL,
0LL);
}
while ( v16 != -1 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func5(__int64 a1)
{
int v2; // er12
__int64 v3; // r15
int v4; // eax
_BOOL8 v5; // r9
int v6; // ecx
int v7; // edx
int v8; // eax
unsigned __int64 v9; // r12
__int64 v10; // rdi
int v11; // edx
__int64 v12; // r8
__int64 v13; // r9
__int64 v14; // rcx
int *result; // rax
int v16; // er15
__int64 v17; // r14
int v18; // eax
char v19; // dl
int v20; // esi
int v21; // ecx
int v22[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v6 = v2 & 0x1F;
v7 = v2 & 0x10;
if ( flipscreen )
{
v4 = v2 / 32;
v6 = 31 - v6;
v5 = v7 == 0;
}
else
{
v4 = v2 / -32 + 15;
v5 = v7 != 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 1) << 8),
0LL,
(unsigned int)flipscreen,
v5,
(unsigned int)(16 * v4),
(unsigned int)(16 * v6),
0LL,
0LL,
0LL);
}
--v2;
--v3;
}
while ( v2 != -1 );
}
v8 = (unsigned __int8)*mystston_scroll;
v22[0] = -v8;
if ( flipscreen )
v22[0] = v8 + 256;
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 1LL, v22, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v9 = 0LL;
do
{
v11 = *(unsigned __int8 *)(spriteram + v9);
if ( (v11 & 1) != 0 )
{
v10 = *(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 3));
v12 = v11 & 4;
v13 = v11 & 2;
v14 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + (unsigned int)(v9 + 2)));
if ( flipscreen )
{
v14 = (unsigned int)(240 - v14);
v12 = (_DWORD)v12 == 0;
v13 = (_DWORD)v13 == 0;
}
else
{
v10 = (unsigned int)(240 - v10);
}
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + (unsigned int)(v9 + 1)) + ((16 * (_WORD)v11) & 0x100u),
(v11 >> 3) & 1,
v12,
v13,
v10,
v14,
Machine + 776LL,
2LL,
0LL);
}
v9 += 4LL;
}
while ( spriteram_size > v9 );
}
result = &mystston_videoram2_size;
v16 = mystston_videoram2_size - 1;
if ( mystston_videoram2_size - 1 >= 0 )
{
v17 = v16;
do
{
v21 = v16 & 0x1F;
if ( flipscreen )
{
v18 = v16 / 32;
v21 = 31 - v21;
}
else
{
v18 = v16 / -32 + 31;
}
--v16;
v19 = *(_BYTE *)(mystston_colorram2 + v17);
v20 = *(unsigned __int8 *)(mystston_videoram2 + v17--);
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v20 + ((unsigned __int8)(v19 & 7) << 8),
(unsigned int)textcolor,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v18),
(unsigned int)(8 * v21),
Machine + 776LL,
2LL,
0LL);
}
while ( v16 != -1 );
}
return result;
}

original_code:
void mystston_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipy;
   dirtybuffer[offs] = 0;
   sx = 15 - offs / 32;
   sy = offs % 32;
   flipy = (sy >= 16) ? 1 : 0;
   if (flipscreen)
   {
    sx = 15 - sx;
    sy = 31 - sy;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + 256 * (colorram[offs] & 0x01),
     0,
     flipscreen,flipy,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrolly;
  scrolly = -*mystston_scroll;
  if (flipscreen) scrolly = 256 - scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   int sx,sy,flipx,flipy;
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = spriteram[offs] & 0x02;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x10) << 4),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = mystston_videoram2_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = 31 - offs / 32;
  sy = offs % 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    mystston_videoram2[offs] + 256 * (mystston_colorram2[offs] & 0x07),
    textcolor,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void mystston_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipy;
   dirtybuffer[offs] = 0;
   sx = 15 - offs / 32;
   sy = offs % 32;
   flipy = (sy >= 16) ? 1 : 0;
   if (flipscreen)
   {
    sx = 15 - sx;
    sy = 31 - sy;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + 256 * (colorram[offs] & 0x01),
     0,
     flipscreen,flipy,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrolly;
  scrolly = -*mystston_scroll;
  if (flipscreen) scrolly = 256 - scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   int sx; int sy; int flipx; int flipy;
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = spriteram[offs] & 0x02;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x10) << 4),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = mystston_videoram2_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = 31 - offs / 32;
  sy = offs % 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    mystston_videoram2[offs] + 256 * (mystston_colorram2[offs] & 0x07),
    textcolor,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipy int

variable_types: scrolly int

variable_types: flipx int


decompiled_code:
__int64 mystston_interrupt()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_1 = 0;
return interrupt();
}
if ( coin_1 )
return interrupt();
coin_1 = 1;
return nmi_interrupt();
}

canonical_decompiled_code:
__int64 func6()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_1 = 0;
return interrupt();
}
if ( coin_1 )
return interrupt();
coin_1 = 1;
return nmi_interrupt();
}

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

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

variable_types: coin int


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: last int


decompiled_code:
void __fastcall parodius_videobank_w(__int64 a1, int a2)
{
videobank = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
videobank = a2;
}

original_code:
static void parodius_videobank_w(offs_t offset,data_t data)
{
 videobank = data;
}

canonical_original_code:
static void parodius_videobank_w(unsigned int offset, unsigned int data)
{
 videobank = data;
}


decompiled_code:
__int64 parodius_vh_start()
{
int v0; // er8
__int64 result; // rax

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053245_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // er8
__int64 result; // rax

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053245_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int parodius_vh_start( void )
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K053245_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int parodius_vh_start()
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K053245_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 parodius_vh_stop()
{
K052109_vh_stop();
return K053245_vh_stop();
}

original_code:
void parodius_vh_stop( void )
{
 K052109_vh_stop();
 K053245_vh_stop();
}

canonical_original_code:
void parodius_vh_stop()
{
 K052109_vh_stop();
 K053245_vh_stop();
}


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

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

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

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


decompiled_code:
void *parodius_init_machine()
{
__int64 v0; // rbx
__int64 v1; // rax
void *result; // rax
unsigned int v3; // eax

v0 = memory_region(129LL) + 0x10000;
konami_cpu_setlines_callback = parodius_banking;
v1 = memory_region(129LL);
videobank = 0;
paletteram = v1 + 294912;
cpu_bankbase[1] = v0;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *func6()
{
__int64 v0; // rbx
__int64 v1; // rax
void *result; // rax
unsigned int v3; // eax

v0 = memory_region(129LL) + 0x10000;
konami_cpu_setlines_callback = parodius_banking;
v1 = memory_region(129LL);
videobank = 0;
paletteram = v1 + 294912;
cpu_bankbase[1] = v0;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
static void parodius_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = parodius_banking;
 paletteram = &memory_region(REGION_CPU1)[0x48000];
 videobank = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void parodius_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = parodius_banking;
 paletteram = &memory_region(REGION_CPU1)[0x48000];
 videobank = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *__fastcall parodius_banking(char a1)
{
__int64 v1; // r8
int v2; // eax
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((~a1 & 0xF) + 4) << 14;
if ( v2 > 294911 )
v2 -= 0x40000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(char a1)
{
__int64 v1; // r8
int v2; // eax
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((~a1 & 0xF) + 4) << 14;
if ( v2 > 294911 )
v2 -= 0x40000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
static void parodius_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 offs = 0x10000 + (((lines & 0x0f)^0x0f) * 0x4000);
 if (offs >= 0x48000) offs -= 0x40000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void parodius_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 offs = 0x10000 + (((lines & 0x0f)^0x0f) * 0x4000);
 if (offs >= 0x48000) offs -= 0x40000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int


decompiled_code:
__int64 sound_arm_nmi_w()
{
cpu_set_nmi_line(1LL, 0LL);
return timer_set(53687LL, 0LL, nmi_callback);
}

canonical_decompiled_code:
__int64 func9()
{
cpu_set_nmi_line(1LL, 0LL);
return timer_set(53687LL, 0LL, nmi_callback);
}

original_code:
static void sound_arm_nmi_w(offs_t offset,data_t data)
{
 cpu_set_nmi_line(1,0);
 timer_set(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)),0,nmi_callback);
}

canonical_original_code:
static void sound_arm_nmi_w(unsigned int offset, unsigned int data)
{
 cpu_set_nmi_line(1,0);
 timer_set(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)),0,nmi_callback);
}


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

if ( *(_DWORD *)(Machine + 836LL) )
result = K053260_r((unsigned int)(a1 + 2));
else
result = (unsigned __int8)(a1 == 0) << 7;
return result;
}

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

if ( *(_DWORD *)(Machine + 836LL) )
result = K053260_r((unsigned int)(a1 + 2));
else
result = (unsigned __int8)(a1 == 0) << 7;
return result;
}

original_code:
static data_t parodius_sound_r(offs_t offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else return offset ? 0x00 : 0x80;
}

canonical_original_code:
static unsigned int parodius_sound_r(unsigned int offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else return offset ? 0x00 : 0x80;
}


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int parodius_interrupt(void)
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int parodius_interrupt()
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}


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

if ( (videobank & 2) != 0 )
result = K053245_w();
else
result = K052109_w();
return result;
}

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

if ( (videobank & 2) != 0 )
result = K053245_w();
else
result = K052109_w();
return result;
}

original_code:
static void parodius_052109_053245_w(offs_t offset,data_t data)
{
 if (videobank & 0x02)
  K053245_w(offset,data);
 else
  K052109_w(offset,data);
}

canonical_original_code:
static void parodius_052109_053245_w(unsigned int offset, unsigned int data)
{
 if (videobank & 0x02)
  K053245_w(offset,data);
 else
  K052109_w(offset,data);
}


decompiled_code:
__int64 parodius_sh_irqtrigger_w()
{
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 func13()
{
return cpu_cause_interrupt(1LL, 255LL);
}

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

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


decompiled_code:
__int64 __fastcall parodius_3fc0_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
return K052109_set_RMRD_line((a2 & 8) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
return K052109_set_RMRD_line((a2 & 8) != 0);
}

original_code:
static void parodius_3fc0_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line( ( data & 0x08 ) ? 1 : 0 );
}

canonical_original_code:
static void parodius_3fc0_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line( ( data & 0x08 ) ? 1 : 0 );
}


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

if ( (videobank & 2) != 0 )
result = K053245_r();
else
result = K052109_r();
return result;
}

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

if ( (videobank & 2) != 0 )
result = K053245_r();
else
result = K052109_r();
return result;
}

original_code:
static data_t parodius_052109_053245_r(offs_t offset)
{
 if (videobank & 0x02)
  return K053245_r(offset);
 else
  return K052109_r(offset);
}

canonical_original_code:
static unsigned int parodius_052109_053245_r(unsigned int offset)
{
 if (videobank & 0x02)
  return K053245_r(offset);
 else
  return K052109_r(offset);
}


decompiled_code:
__int64 __fastcall parodius_vh_screenrefresh(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_6F4 = K053251_get_palette_index(4LL);
dword_6F8 = K053251_get_palette_index(3LL);
K052109_tilemap_update();
palette_init_used_colors();
K053245_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
v3 = 1;
layerpri = K053251_get_priority(2LL);
v4 = 2;
dword_6DC = K053251_get_priority(4LL);
dword_6E0 = K053251_get_priority(3LL);
sortlayers_constprop_0((int *)&v2);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053245_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_6F4 = K053251_get_palette_index(4LL);
dword_6F8 = K053251_get_palette_index(3LL);
K052109_tilemap_update();
palette_init_used_colors();
K053245_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
v3 = 1;
layerpri = K053251_get_priority(2LL);
v4 = 2;
dword_6DC = K053251_get_priority(4LL);
dword_6E0 = K053251_get_priority(3LL);
func19((int *)&v2);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053245_sprites_draw(a1);
}

original_code:
void parodius_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI4);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI3);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053245_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI4);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI3);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053245_sprites_draw(bitmap);
}

canonical_original_code:
void parodius_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI4);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI3);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053245_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI4);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI3);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053245_sprites_draw(bitmap);
}

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

variable_types:
layer
int [3]


original_code:
void warpwarp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (i >> 0) & 0x01;
  bit1 = (i >> 1) & 0x01;
  bit2 = (i >> 2) & 0x01;
  *(palette++) = 0x1f * bit0 + 0x3c * bit1 + 0xa4 * bit2;
  bit0 = (i >> 3) & 0x01;
  bit1 = (i >> 4) & 0x01;
  bit2 = (i >> 5) & 0x01;
  *(palette++) = 0x1f * bit0 + 0x3c * bit1 + 0xa4 * bit2;
  bit0 = 0;
  bit1 = (i >> 6) & 0x01;
  bit2 = (i >> 7) & 0x01;
  *(palette++) = 0x1f * bit0 + 0x3c * bit1 + 0xa4 * bit2;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i += 2)
 {
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + 1]) = i / 2;
 }
}

canonical_original_code:
void warpwarp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (i >> 0) & 0x01;
  bit1 = (i >> 1) & 0x01;
  bit2 = (i >> 2) & 0x01;
  *(palette++) = 0x1f * bit0 + 0x3c * bit1 + 0xa4 * bit2;
  bit0 = (i >> 3) & 0x01;
  bit1 = (i >> 4) & 0x01;
  bit2 = (i >> 5) & 0x01;
  *(palette++) = 0x1f * bit0 + 0x3c * bit1 + 0xa4 * bit2;
  bit0 = 0;
  bit1 = (i >> 6) & 0x01;
  bit2 = (i >> 7) & 0x01;
  *(palette++) = 0x1f * bit0 + 0x3c * bit1 + 0xa4 * bit2;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i += 2)
 {
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = 0;
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + 1]) = i / 2;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

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

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

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

variable_types: param int


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

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

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

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

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