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

result = (a1 >> 6) & 7;
switch ( (int)result )
{
case 0:
if ( a1 )
{
result = watchdog_reset_w(0LL);
}
else
{
result = (unsigned int)firq_enable;
if ( firq_enable )
result = cpu_cause_interrupt(1LL, 2LL);
}
break;
case 1:
result = cpu_cause_interrupt(2LL, 4294966296LL);
break;
case 2:
result = soundlatch_w();
break;
case 3:
result = (__int64)ajax_bankswitch_w_constprop_0(a2);
break;
case 5:
result = ajax_lamps_w_constprop_0(a2);
break;
default:
return result;
}
return result;
}

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

result = (a1 >> 6) & 7;
switch ( (int)result )
{
case 0:
if ( a1 )
{
result = watchdog_reset_w(0LL);
}
else
{
result = (unsigned int)firq_enable;
if ( firq_enable )
result = cpu_cause_interrupt(1LL, 2LL);
}
break;
case 1:
result = cpu_cause_interrupt(2LL, 4294966296LL);
break;
case 2:
result = soundlatch_w();
break;
case 3:
result = (__int64)func18(a2);
break;
case 5:
result = func17(a2);
break;
default:
return result;
}
return result;
}

original_code:
void ajax_ls138_f10_w(offs_t offset,data_t data)
{
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   if (offset)
    watchdog_reset_w(0, data);
   else{
    if (firq_enable)
     cpu_cause_interrupt(1,2);
   }
   break;
  case 0x01:
   cpu_cause_interrupt(2,-1000);
   break;
  case 0x02:
   soundlatch_w(offset,data);
   break;
  case 0x03:
   ajax_bankswitch_w(0, data);
   break;
  case 0x05:
   ajax_lamps_w(0, data);
   break;
  default:
   break;
 }
}

canonical_original_code:
void ajax_ls138_f10_w(unsigned int offset, unsigned int data)
{
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   if (offset)
    watchdog_reset_w(0, data);
   else{
    if (firq_enable)
     cpu_cause_interrupt(1,2);
   }
   break;
  case 0x01:
   cpu_cause_interrupt(2,-1000);
   break;
  case 0x02:
   soundlatch_w(offset,data);
   break;
  case 0x03:
   ajax_bankswitch_w(0, data);
   break;
  case 0x05:
   ajax_lamps_w(0, data);
   break;
  default:
   break;
 }
}


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 func3(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 *

return_type: void


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = zoom_colorbase + ((*a2 >> 3) & 1u);
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = zoom_colorbase + ((*a2 >> 3) & 1u);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x08) >> 3);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x08) >> 3);
}


decompiled_code:
__int64 __fastcall volume_callback1(int a1)
{
return K007232_set_volume(
1LL,
1LL,
(unsigned int)((17 * (a1 & 0xF)) >> 1),
(unsigned int)((int)((a1 & 0xFFFFFFF0) + (a1 >> 4)) / 2));
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return K007232_set_volume(
1LL,
1LL,
(unsigned int)((17 * (a1 & 0xF)) >> 1),
(unsigned int)((int)((a1 & 0xFFFFFFF0) + (a1 >> 4)) / 2));
}

original_code:
static void volume_callback1(int v)
{
 K007232_set_volume(1,1,(v & 0x0f) * 0x11/2,(v >> 4) * 0x11/2);
}

variable_types: v int


decompiled_code:
__int64 __fastcall volume_callback0(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}


original_code:
static void sound_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM;
 int bank_A, bank_B;
 RAM = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 1) & 0x01);
 bank_B = 0x20000 * ((data >> 0) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
 RAM = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(1,RAM + bank_A,RAM + bank_B);
}

canonical_original_code:
static void sound_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM;
 int bank_A; int bank_B;
 RAM = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 1) & 0x01);
 bank_B = 0x20000 * ((data >> 0) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
 RAM = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(1,RAM + bank_A,RAM + bank_B);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types:
RAM
unsigned char *


original_code:
void yamato_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 64;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[0] >> 4) & 0x01;
  bit1 = (color_prom[0] >> 5) & 0x01;
  bit2 = (color_prom[0] >> 6) & 0x01;
  bit3 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[64] >> 0) & 0x01;
  bit1 = (color_prom[64] >> 1) & 0x01;
  bit2 = (color_prom[64] >> 2) & 0x01;
  bit3 = (color_prom[64] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += 64;
 for (i = 0;i < 32;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
 {
  if (i % 4 == 0) (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + (i)]) = 0;
  else (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + (i)]) = i;
 }
 for (i = 0;i < (Machine->gfx[2]->total_colors * Machine->gfx[2]->color_granularity);i++)
 {
  if (i % 4 == 0) (colortable[Machine->drv->gfxdecodeinfo[2].color_codes_start + (i)]) = 0;
  else (colortable[Machine->drv->gfxdecodeinfo[2].color_codes_start + (i)]) = i + 64;
 }
}

canonical_original_code:
void yamato_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 64;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[0] >> 4) & 0x01;
  bit1 = (color_prom[0] >> 5) & 0x01;
  bit2 = (color_prom[0] >> 6) & 0x01;
  bit3 = (color_prom[0] >> 7) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[64] >> 0) & 0x01;
  bit1 = (color_prom[64] >> 1) & 0x01;
  bit2 = (color_prom[64] >> 2) & 0x01;
  bit3 = (color_prom[64] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += 64;
 for (i = 0;i < 32;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
 {
  if (i % 4 == 0) (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + (i)]) = 0;
  else (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + (i)]) = i;
 }
 for (i = 0;i < (Machine->gfx[2]->total_colors * Machine->gfx[2]->color_granularity);i++)
 {
  if (i % 4 == 0) (colortable[Machine->drv->gfxdecodeinfo[2].color_codes_start + (i)]) = 0;
  else (colortable[Machine->drv->gfxdecodeinfo[2].color_codes_start + (i)]) = i + 64;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall p0_w(__int64 a1, int a2)
{
p0 = a2;
}

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

original_code:
static void p0_w(offs_t offset,data_t data)
{
 p0 = data;
}

canonical_original_code:
static void p0_w(unsigned int offset, unsigned int data)
{
 p0 = data;
}


decompiled_code:
void __fastcall p1_w(__int64 a1, int a2)
{
p1 = a2;
}

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

original_code:
static void p1_w(offs_t offset,data_t data)
{
 p1 = data;
}

canonical_original_code:
static void p1_w(unsigned int offset, unsigned int data)
{
 p1 = data;
}


decompiled_code:
__int64 p0_r()
{
return (unsigned int)p0;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)p0;
}

original_code:
static data_t p0_r(offs_t offset)
{
 return p0;
}

canonical_original_code:
static unsigned int p0_r(unsigned int offset)
{
 return p0;
}

return_type: unsigned int


decompiled_code:
__int64 p1_r()
{
return (unsigned int)p1;
}

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

original_code:
static data_t p1_r(offs_t offset)
{
 return p1;
}

canonical_original_code:
static unsigned int p1_r(unsigned int offset)
{
 return p1;
}


decompiled_code:
// attributes: thunk
__int64 init_yamato()
{
return yamato_decode();
}

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

original_code:
static void init_yamato(void)
{
 yamato_decode();
}

canonical_original_code:
static void init_yamato()
{
 yamato_decode();
}


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

for ( result = 0LL; result != 8; ++result )
{
*(_WORD *)(a2 + 2 * result) = result;
a1 += 3LL;
*(_BYTE *)(a1 - 3) = -(result & 1);
*(_BYTE *)(a1 - 2) = -(((unsigned int)result >> 2) & 1);
v3 = result;
*(_BYTE *)(a1 - 1) = -((v3 >> 1) & 1);
}
return result;
}

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

for ( result = 0LL; result != 8; ++result )
{
*(_WORD *)(a2 + 2 * result) = result;
a1 += 3LL;
*(_BYTE *)(a1 - 3) = -(result & 1);
*(_BYTE *)(a1 - 2) = -(((unsigned int)result >> 2) & 1);
v3 = result;
*(_BYTE *)(a1 - 1) = -((v3 >> 1) & 1);
}
return result;
}

original_code:
void moleattack_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
 int i;
 for( i=0; i<8; i++ ){
  colortable[i] = i;
  *palette++ = (i&1)?0xff:0x00;
  *palette++ = (i&4)?0xff:0x00;
  *palette++ = (i&2)?0xff:0x00;
 }
}

canonical_original_code:
void moleattack_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom){
 int i;
 for( i=0; i<8; i++ ){
  colortable[i] = i;
  *palette++ = (i&1)?0xff:0x00;
  *palette++ = (i&4)?0xff:0x00;
  *palette++ = (i&2)?0xff:0x00;
 }
}


decompiled_code:
void __fastcall moleattack_tilesetselector_w(__int64 a1, int a2)
{
tile_bank = a2;
}

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

original_code:
void moleattack_tilesetselector_w(offs_t offset,data_t data){
 tile_bank = data;
}

canonical_original_code:
void moleattack_tilesetselector_w(unsigned int offset, unsigned int data){
 tile_bank = data;
}


decompiled_code:
__int64 moleattack_vh_start()
{
void *v0; // rax
void *v1; // rbp
_QWORD *v2; // rdx
__int64 result; // rax

v0 = malloc(0x7D0uLL);
tile_data = v0;
if ( !v0 )
return 1LL;
v1 = v0;
v2 = malloc(0x3E8uLL);
dirtybuffer = v2;
if ( v2 )
{
memset(v2, 1u, 0x3E8uLL);
result = 0LL;
}
else
{
free(v1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
void *v0; // rax
void *v1; // rbp
_QWORD *v2; // rdx
__int64 result; // rax

v0 = malloc(0x7D0uLL);
tile_data = v0;
if ( !v0 )
return 1LL;
v1 = v0;
v2 = malloc(0x3E8uLL);
dirtybuffer = v2;
if ( v2 )
{
memset(v2, 1u, 0x3E8uLL);
result = 0LL;
}
else
{
free(v1);
result = 1LL;
}
return result;
}

original_code:
int moleattack_vh_start( void ){
 tile_data = (UINT16 *)malloc( (25*40)*sizeof(UINT16) );
 if( tile_data ){
  dirtybuffer = (unsigned char*)malloc( (25*40) );
  if( dirtybuffer ){
   memset( dirtybuffer, 1, (25*40) );
   return 0;
  }
  free( tile_data );
 }
 return 1;
}

canonical_original_code:
int moleattack_vh_start(){
 tile_data = (unsigned short *)malloc( (25*40)*sizeof(UINT16) );
 if( tile_data ){
  dirtybuffer = (unsigned char *)malloc( (25*40) );
  if( dirtybuffer ){
   memset( dirtybuffer, 1, (25*40) );
   return 0;
  }
  free( tile_data );
 }
 return 1;
}

return_type: int


decompiled_code:
void moleattack_vh_stop()
{
free(dirtybuffer);
free(tile_data);
}

canonical_decompiled_code:
void func4()
{
free(dirtybuffer);
free(tile_data);
}

original_code:
void moleattack_vh_stop( void ){
 free( dirtybuffer );
 free( tile_data );
}

canonical_original_code:
void moleattack_vh_stop(){
 free( dirtybuffer );
 free( tile_data );
}


decompiled_code:
__int64 __fastcall mole_prot_r(unsigned int a1)
{
__int64 result; // rax
bool v2; // zf

if ( a1 == 134 )
return 145LL;
if ( a1 > 0x86 )
{
result = 0LL;
if ( a1 == 174 )
result = 50LL;
}
else
{
result = 176LL;
if ( a1 != 8 )
{
if ( a1 == 38 )
{
v2 = (unsigned int)cpu_get_pc() == 21463;
result = 6LL;
if ( !v2 )
result = 198LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax
bool v2; // zf

if ( a1 == 134 )
return 145LL;
if ( a1 > 0x86 )
{
result = 0LL;
if ( a1 == 174 )
result = 50LL;
}
else
{
result = 176LL;
if ( a1 != 8 )
{
if ( a1 == 38 )
{
v2 = (unsigned int)cpu_get_pc() == 21463;
result = 6LL;
if ( !v2 )
result = 198LL;
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
data_t mole_prot_r(offs_t offset){
 switch( offset ){
 case 0x08: return 0xb0;
 case 0x26:
  if( cpu_get_pc() == 0x53d7 ){
   return 0x06;
  }
  else {
   return 0xc6;
  }
 case 0x86: return 0x91;
 case 0xae: return 0x32;
 }
 return 0x00;
}

canonical_original_code:
unsigned int mole_prot_r(unsigned int offset){
 switch( offset ){
 case 0x08: return 0xb0;
 case 0x26:
  if( cpu_get_pc() == 0x53d7 ){
   return 0x06;
  }
  else {
   return 0xc6;
  }
 case 0x86: return 0x91;
 case 0xae: return 0x32;
 }
 return 0x00;
}


original_code:
static UINT32 gundealr_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
{
 return (row & 0x0f) + ((col & 0x3f) << 4) + ((row & 0x10) << 6);
}

canonical_original_code:
static unsigned int gundealr_scan(unsigned int col, unsigned int row, unsigned int num_cols, unsigned int num_rows)
{
 return (row & 0x0f) + ((col & 0x3f) << 4) + ((row & 0x10) << 6);
}

variable_types:
col
unsigned int

variable_types:
row
unsigned int


canonical_decompiled_code:
void func3()
{
input_ports_hack = 0;
}

original_code:
static void init_gundealr(void)
{
 input_ports_hack = 0;
}

canonical_original_code:
static void init_gundealr()
{
 input_ports_hack = 0;
}


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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, gundealr_scan, 1LL, 16LL, 16LL, 64LL, v3);
fg_tilemap = v1;
if ( !bg_tilemap || !v1 )
return 1LL;
*(_DWORD *)(v1 + 132) = 15;
return 0LL;
}

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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
bg_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, gundealr_scan, 1LL, 16LL, 16LL, 64LL, v3);
fg_tilemap = v1;
if ( !bg_tilemap || !v1 )
return 1LL;
*(_DWORD *)(v1 + 132) = 15;
return 0LL;
}

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

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


decompiled_code:
__int64 __fastcall gundealr_paletteram_w(unsigned int a1, char a2)
{
*(_BYTE *)(paletteram + a1) = a2;
return palette_change_color(
a1 >> 1,
((int)*(unsigned __int8 *)(paletteram + (a1 & 0xFFFFFFFE)) >> 4)
+ (*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) & 0xF0u),
17 * (*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) & 0xFu),
((int)*(unsigned __int8 *)(paletteram + (a1 | 1)) >> 4) + (*(_BYTE *)(paletteram + (a1 | 1)) & 0xF0u));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
*(_BYTE *)(paletteram + a1) = a2;
return palette_change_color(
a1 >> 1,
((int)*(unsigned __int8 *)(paletteram + (a1 & 0xFFFFFFFE)) >> 4)
+ (*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) & 0xF0u),
17 * (*(_BYTE *)(paletteram + (a1 & 0xFFFFFFFE)) & 0xFu),
((int)*(unsigned __int8 *)(paletteram + (a1 | 1)) >> 4) + (*(_BYTE *)(paletteram + (a1 | 1)) & 0xF0u));
}

original_code:
void gundealr_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b,val;
 paletteram[offset] = data;
 val = paletteram[offset & ~1];
 r = (val >> 4) & 0x0f;
 g = (val >> 0) & 0x0f;
 val = paletteram[offset | 1];
 b = (val >> 4) & 0x0f;
 r = 0x11 * r;
 g = 0x11 * g;
 b = 0x11 * b;
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void gundealr_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b; int val;
 paletteram[offset] = data;
 val = paletteram[offset & ~1];
 r = (val >> 4) & 0x0f;
 g = (val >> 0) & 0x0f;
 val = paletteram[offset | 1];
 b = (val >> 4) & 0x0f;
 r = 0x11 * r;
 g = 0x11 * g;
 b = 0x11 * b;
 palette_change_color(offset / 2,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: val int


decompiled_code:
__int64 __fastcall gundealr_fg_scroll_w(int a1, char a2)
{
scroll_1[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)byte_B45 | ((unsigned __int8)scroll_1[0] << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B47 | ((unsigned __int8)byte_B46 << 8) & 0x300u);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char a2)
{
scroll_1[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)byte_B45 | ((unsigned __int8)scroll_1[0] << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B47 | ((unsigned __int8)byte_B46 << 8) & 0x300u);
}

original_code:
void gundealr_fg_scroll_w(offs_t offset,data_t data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[1] | ((scroll[0] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[3] | ((scroll[2] & 0x03) << 8));
}

canonical_original_code:
void gundealr_fg_scroll_w(unsigned int offset, unsigned int data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[1] | ((scroll[0] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[3] | ((scroll[2] & 0x03) << 8));
}

variable_types:
scroll
unsigned char [4]


decompiled_code:
__int64 __fastcall yamyam_fg_scroll_w(int a1, char a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)scroll_0[0] | ((unsigned __int8)byte_B41 << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B42 | ((unsigned __int8)byte_B43 << 8) & 0x300u);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)scroll_0[0] | ((unsigned __int8)byte_B41 << 8) & 0x300u);
return tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)byte_B42 | ((unsigned __int8)byte_B43 << 8) & 0x300u);
}

original_code:
void yamyam_fg_scroll_w(offs_t offset,data_t data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[0] | ((scroll[1] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[2] | ((scroll[3] & 0x03) << 8));
}

canonical_original_code:
void yamyam_fg_scroll_w(unsigned int offset, unsigned int data)
{
 static unsigned char scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(fg_tilemap,0,scroll[0] | ((scroll[1] & 0x03) << 8));
 tilemap_set_scrolly(fg_tilemap,0,scroll[2] | ((scroll[3] & 0x03) << 8));
}


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

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

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

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


decompiled_code:
__int64 __fastcall gundealr_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void gundealr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void gundealr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
}

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


decompiled_code:
__int64 yamyam_interrupt()
{
unsigned int v0; // er12
__int64 result; // rax
_BYTE *v2; // rbx

if ( (unsigned int)cpu_getiloops() )
{
v0 = 207;
if ( (cpu_getiloops() & 1) != 0 )
return v0;
result = ignore_interrupt();
}
else
{
v0 = 215;
if ( !input_ports_hack )
return v0;
v2 = (_BYTE *)memory_region(129LL);
v2[57348] = readinputport(4LL);
v2[57349] = readinputport(3LL);
v2[57350] = readinputport(2LL);
result = 215LL;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // er12
__int64 result; // rax
_BYTE *v2; // rbx

if ( (unsigned int)cpu_getiloops() )
{
v0 = 207;
if ( (cpu_getiloops() & 1) != 0 )
return v0;
result = ignore_interrupt();
}
else
{
v0 = 215;
if ( !input_ports_hack )
return v0;
v2 = (_BYTE *)memory_region(129LL);
v2[57348] = readinputport(4LL);
v2[57349] = readinputport(3LL);
v2[57350] = readinputport(2LL);
result = 215LL;
}
return result;
}

original_code:
static int yamyam_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (input_ports_hack)
  {
   unsigned char *RAM = memory_region(REGION_CPU1);
   RAM[0xe004] = readinputport(4);
   RAM[0xe005] = readinputport(3);
   RAM[0xe006] = readinputport(2);
  }
  return 0xd7;
 }
 if ((cpu_getiloops() & 1) == 1) return 0xcf;
 else return ignore_interrupt();
}

canonical_original_code:
static int yamyam_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (input_ports_hack)
  {
   unsigned char *RAM = memory_region(REGION_CPU1);
   RAM[0xe004] = readinputport(4);
   RAM[0xe005] = readinputport(3);
   RAM[0xe006] = readinputport(2);
  }
  return 0xd7;
 }
 if ((cpu_getiloops() & 1) == 1) return 0xcf;
 else return ignore_interrupt();
}


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7u) + 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 func12(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

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

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

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

variable_types: bankaddress int


decompiled_code:
__int64 init_yamyam()
{
input_ports_hack = 1;
return install_mem_write_handler(0LL, 57344LL, 57344LL, yamyam_protection_w);
}

canonical_decompiled_code:
__int64 func13()
{
input_ports_hack = 1;
return install_mem_write_handler(0LL, 57344LL, 57344LL, yamyam_protection_w);
}

original_code:
static void init_yamyam(void)
{
 input_ports_hack = 1;
 install_mem_write_handler(0, 0xe000, 0xe000, yamyam_protection_w);
}

canonical_original_code:
static void init_yamyam()
{
 input_ports_hack = 1;
 install_mem_write_handler(0, 0xe000, 0xe000, yamyam_protection_w);
}


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

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

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

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

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

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

variable_types:
attr
unsigned char

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


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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall kchamp_vh_convert_color_prom(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // edx
char v6; // r10
char v7; // dl
__int64 v8; // rdx

result = *(_QWORD *)(Machine + 824LL);
v5 = *(_DWORD *)(result + 696);
if ( v5 )
{
result = 0LL;
do
{
a1 += 3LL;
v6 = *(_BYTE *)(a3 + v5 + (unsigned int)result);
v7 = *(_BYTE *)(a3 + (unsigned int)result + 2 * v5);
*(_BYTE *)(a1 - 3) = 17 * *(_BYTE *)(a3 + result);
*(_BYTE *)(a1 - 2) = 17 * v6;
*(_BYTE *)(a1 - 1) = 17 * v7;
v8 = Machine;
*(_WORD *)(a2 + 2 * result) = result;
++result;
v5 = *(_DWORD *)(*(_QWORD *)(v8 + 824) + 696LL);
}
while ( v5 > (unsigned int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // edx
char v6; // r10
char v7; // dl
__int64 v8; // rdx

result = *(_QWORD *)(Machine + 824LL);
v5 = *(_DWORD *)(result + 696);
if ( v5 )
{
result = 0LL;
do
{
a1 += 3LL;
v6 = *(_BYTE *)(a3 + v5 + (unsigned int)result);
v7 = *(_BYTE *)(a3 + (unsigned int)result + 2 * v5);
*(_BYTE *)(a1 - 3) = 17 * *(_BYTE *)(a3 + result);
*(_BYTE *)(a1 - 2) = 17 * v6;
*(_BYTE *)(a1 - 1) = 17 * v7;
v8 = Machine;
*(_WORD *)(a2 + 2 * result) = result;
++result;
v5 = *(_DWORD *)(*(_QWORD *)(v8 + 824) + 696LL);
}
while ( v5 > (unsigned int)result );
}
return result;
}

original_code:
void kchamp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
        int i, red, green, blue;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
                red = color_prom[i];
                green = color_prom[Machine->drv->total_colors+i];
                blue = color_prom[2*Machine->drv->total_colors+i];
                *(palette++) = red*0x11;
                *(palette++) = green*0x11;
                *(palette++) = blue*0x11;
                *(colortable++) = i;
 }
}

canonical_original_code:
void kchamp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
        int i; int red; int green; int blue;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
                red = color_prom[i];
                green = color_prom[Machine->drv->total_colors+i];
                blue = color_prom[2*Machine->drv->total_colors+i];
                *(palette++) = red*0x11;
                *(palette++) = green*0x11;
                *(palette++) = blue*0x11;
                *(colortable++) = i;
 }
}

variable_types: red int

variable_types: green int

variable_types: blue int


decompiled_code:
void __fastcall control_w(__int64 a1, char a2)
{
nmi_enable = a2 & 1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
nmi_enable = a2 & 1;
}

original_code:
static void control_w(offs_t offset,data_t data) {
 nmi_enable = data & 1;
}

canonical_original_code:
static void control_w(unsigned int offset, unsigned int data) {
 nmi_enable = data & 1;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void __fastcall sound_msm_w(__int64 a1, int a2)
{
msm_data = a2;
msm_play_lo_nibble = 1;
}

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

original_code:
static void sound_msm_w(offs_t offset,data_t data) {
 msm_data = data;
 msm_play_lo_nibble = 1;
}

canonical_original_code:
static void sound_msm_w(unsigned int offset, unsigned int data) {
 msm_data = data;
 msm_play_lo_nibble = 1;
}


decompiled_code:
void __fastcall kc_sound_control_w(int a1, unsigned int a2)
{
if ( !a1 )
sound_nmi_enable = (a2 >> 7) & 1;
}

canonical_decompiled_code:
void __fastcall func3(int a1, unsigned int a2)
{
if ( !a1 )
sound_nmi_enable = (a2 >> 7) & 1;
}

original_code:
static void kc_sound_control_w(offs_t offset,data_t data) {
 if ( offset == 0 )
  sound_nmi_enable = ( ( data >> 7 ) & 1 );
}

canonical_original_code:
static void kc_sound_control_w(unsigned int offset, unsigned int data) {
 if ( offset == 0 )
  sound_nmi_enable = ( ( data >> 7 ) & 1 );
}


decompiled_code:
__int64 kc_interrupt()
{
return (unsigned int)(nmi_enable == 0) - 2;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)(nmi_enable == 0) - 2;
}

original_code:
static int kc_interrupt( void ) {
 if ( nmi_enable )
  return -2;
 return -1;
}

canonical_original_code:
static int kc_interrupt() {
 if ( nmi_enable )
  return -2;
 return -1;
}


decompiled_code:
__int64 sound_int()
{
return (unsigned int)(sound_nmi_enable == 0) - 2;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)(sound_nmi_enable == 0) - 2;
}

original_code:
static int sound_int( void ) {
 if ( sound_nmi_enable )
  return -2;
 return -1;
}

canonical_original_code:
static int sound_int() {
 if ( sound_nmi_enable )
  return -2;
 return -1;
}


decompiled_code:
__int64 kchampvs_vh_start()
{
kchamp_drawsprites = (__int64)kchamp_vs_drawsprites;
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func6()
{
kchamp_drawsprites = (__int64)kchamp_vs_drawsprites;
return generic_vh_start();
}

original_code:
int kchampvs_vh_start(void) {
 kchamp_drawsprites = kchamp_vs_drawsprites;
 return generic_vh_start();
}

canonical_original_code:
int kchampvs_vh_start() {
 kchamp_drawsprites = kchamp_vs_drawsprites;
 return generic_vh_start();
}


decompiled_code:
__int64 kchamp1p_vh_start()
{
kchamp_drawsprites = (__int64)kchamp_1p_drawsprites;
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func7()
{
kchamp_drawsprites = (__int64)kchamp_1p_drawsprites;
return generic_vh_start();
}

original_code:
int kchamp1p_vh_start(void) {
 kchamp_drawsprites = kchamp_1p_drawsprites;
 return generic_vh_start();
}

canonical_original_code:
int kchamp1p_vh_start() {
 kchamp_drawsprites = kchamp_1p_drawsprites;
 return generic_vh_start();
}


decompiled_code:
__int64 __fastcall kchamp_vs_drawsprites(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // r9
__int64 v3; // rsi
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // [rsp-28h] [rbp-50h]

for ( i = 1LL; i != 257; i += 4LL )
{
v2 = *(_BYTE *)(spriteram + i + 1) & 0x80;
v3 = *(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520);
v4 = *(_BYTE *)(spriteram + i + 1) & 0xF;
v8 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1);
v5 = *(unsigned __int8 *)(spriteram + i + 2);
v6 = *(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u);
result = drawgfx(a1, v3, v6, v4, 0LL, v2, v5, v8, Machine + 776LL, 2LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // r9
__int64 v3; // rsi
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // [rsp-28h] [rbp-50h]

for ( i = 1LL; i != 257; i += 4LL )
{
v2 = *(_BYTE *)(spriteram + i + 1) & 0x80;
v3 = *(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520);
v4 = *(_BYTE *)(spriteram + i + 1) & 0xF;
v8 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1);
v5 = *(unsigned __int8 *)(spriteram + i + 2);
v6 = *(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u);
result = drawgfx(a1, v3, v6, v4, 0LL, v2, v5, v8, Machine + 776LL, 2LL, 0LL);
}
return result;
}

original_code:
void kchamp_vs_drawsprites( struct osd_bitmap *bitmap ) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx, sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3];
                sy = 240 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void kchamp_vs_drawsprites(struct osd_bitmap *bitmap) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx; int sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3];
                sy = 240 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: numtile int

variable_types: flipx int

variable_types: sx int

variable_types: sy int

variable_types: gfx int

variable_types: color int

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


decompiled_code:
__int64 __fastcall kchamp_1p_drawsprites(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // r9
__int64 v3; // rsi
__int64 v4; // rcx
int v5; // eax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // [rsp-28h] [rbp-50h]

for ( i = 1LL; i != 257; i += 4LL )
{
v2 = *(_BYTE *)(spriteram + i + 1) & 0x80;
v3 = *(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520);
v4 = *(_BYTE *)(spriteram + i + 1) & 0xF;
v8 = 247 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1);
v5 = *(unsigned __int8 *)(spriteram + i + 2);
v6 = *(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u);
result = drawgfx(a1, v3, v6, v4, 0LL, v2, (unsigned int)(v5 - 8), v8, Machine + 776LL, 2LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // r9
__int64 v3; // rsi
__int64 v4; // rcx
int v5; // eax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // [rsp-28h] [rbp-50h]

for ( i = 1LL; i != 257; i += 4LL )
{
v2 = *(_BYTE *)(spriteram + i + 1) & 0x80;
v3 = *(_QWORD *)(Machine + 8LL * (((int)*(unsigned __int8 *)(spriteram + i + 1) >> 5) & 3) + 520);
v4 = *(_BYTE *)(spriteram + i + 1) & 0xF;
v8 = 247 - (unsigned int)*(unsigned __int8 *)(spriteram + i - 1);
v5 = *(unsigned __int8 *)(spriteram + i + 2);
v6 = *(unsigned __int8 *)(spriteram + i) + ((16 * *(unsigned __int8 *)(spriteram + i + 1)) & 0x100u);
result = drawgfx(a1, v3, v6, v4, 0LL, v2, (unsigned int)(v5 - 8), v8, Machine + 776LL, 2LL, 0LL);
}
return result;
}

original_code:
void kchamp_1p_drawsprites( struct osd_bitmap *bitmap ) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx, sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3] - 8;
                sy = 247 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void kchamp_1p_drawsprites(struct osd_bitmap *bitmap) {
 int offs;
        for (offs = 0 ;offs < 0x100;offs+=4)
 {
                int numtile = spriteram[offs+1] + ( ( spriteram[offs+2] & 0x10 ) << 4 );
                int flipx = ( spriteram[offs+2] & 0x80 );
                int sx; int sy;
                int gfx = 1 + ( ( spriteram[offs+2] & 0x60 ) >> 5 );
                int color = ( spriteram[offs+2] & 0x0f );
                sx = spriteram[offs+3] - 8;
                sy = 247 - spriteram[offs];
                drawgfx(bitmap,Machine->gfx[gfx],
                                numtile,
                                color,
                                0, flipx,
                                sx,sy,
                                &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}


decompiled_code:
__int64 __fastcall kchamp_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int16 v3; // dx
int v4; // esi
char v5; // al
__int64 v7; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(colorram + v2);
v4 = *(unsigned __int8 *)(videoram + v2--);
v7 = (unsigned int)(8 * (v1 >> 5));
v5 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
v4 + ((v3 << 8) & 0x700u),
(unsigned __int8)v3 >> 3,
0LL,
0LL,
8 * (v5 & 0x1Fu),
v7,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return kchamp_drawsprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int16 v3; // dx
int v4; // esi
char v5; // al
__int64 v7; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(colorram + v2);
v4 = *(unsigned __int8 *)(videoram + v2--);
v7 = (unsigned int)(8 * (v1 >> 5));
v5 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
v4 + ((v3 << 8) & 0x700u),
(unsigned __int8)v3 >> 3,
0LL,
0LL,
8 * (v5 & 0x1Fu),
v7,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return kchamp_drawsprites(a1);
}

original_code:
void kchamp_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
        int offs;
        for ( offs = videoram_size - 1; offs >= 0; offs-- ) {
                if ( dirtybuffer[offs] ) {
   int sx,sy,code;
   dirtybuffer[offs] = 0;
                        sx = (offs % 32);
   sy = (offs / 32);
                        code = videoram[offs] + ( ( colorram[offs] & 7 ) << 8 );
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                        code,
                                        ( colorram[offs] >> 3 ) & 0x1f,
                                        0,
                                        0,
     sx*8,sy*8,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 (*kchamp_drawsprites)( bitmap);
}

canonical_original_code:
void kchamp_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
        int offs;
        for ( offs = videoram_size - 1; offs >= 0; offs-- ) {
                if ( dirtybuffer[offs] ) {
   int sx; int sy; int code;
   dirtybuffer[offs] = 0;
                        sx = (offs % 32);
   sy = (offs / 32);
                        code = videoram[offs] + ( ( colorram[offs] & 7 ) << 8 );
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                        code,
                                        ( colorram[offs] >> 3 ) & 0x1f,
                                        0,
                                        0,
     sx*8,sy*8,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 (*kchamp_drawsprites)( bitmap);
}

variable_types: code int


decompiled_code:
__int64 sound_reset_r()
{
cpu_set_reset_line(1LL, 3LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
cpu_set_reset_line(1LL, 3LL);
return 0LL;
}

original_code:
static data_t sound_reset_r(offs_t offset) {
 cpu_set_reset_line(1,3);
 return 0;
}

canonical_original_code:
static unsigned int sound_reset_r(unsigned int offset) {
 cpu_set_reset_line(1,3);
 return 0;
}


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

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

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

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

original_code:
static void sound_reset_w(offs_t offset,data_t data) {
 if ( !( data & 1 ) )
  cpu_set_reset_line(1,3);
}

canonical_original_code:
static void sound_reset_w(unsigned int offset, unsigned int data) {
 if ( !( data & 1 ) )
  cpu_set_reset_line(1,3);
}


decompiled_code:
__int64 init_kchampvs()
{
unsigned __int8 *v0; // rbp
int v1; // er12
unsigned __int8 *v2; // rcx
int v3; // edx
int v4; // eax
unsigned __int8 *v5; // rcx
unsigned __int8 v6; // dl
int v7; // eax
int v8; // edx
__int64 result; // rax

v0 = (unsigned __int8 *)memory_region(129LL);
v1 = (int)memory_region_length(129LL) / 2;
memory_set_opcode_base(0LL, &v0[v1]);
v2 = v0;
do
{
v3 = *v2++;
v2[v1 - 1] = v3 & 0x55 | (4 * v3) & 0x88 | (v3 >> 2) & 0x22;
}
while ( v0 + 0x10000 != v2 );
v0[v1] = *v0;
v4 = v0[1] + (v0[2] << 8);
v0[v1 + v4] = v0[v4];
v5 = &v0[v4 + 1];
v6 = *v5 ^ 0xEE;
*v5 = v6;
v7 = (v0[v4 + 2] << 8) + v6;
LOBYTE(v5) = v0[v7];
v8 = v1 + v7;
v7 += 2;
v0[v8] = (unsigned __int8)v5;
LOBYTE(v8) = v0[v7];
result = v1 + v7;
v0[result] = v8;
return result;
}

original_code:
static void init_kchampvs( 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 < 0x10000;A++)
  rom[A+diff] = (rom[A] & 0x55) | ((rom[A] & 0x88) >> 2) | ((rom[A] & 0x22) << 2);
 rom[0+diff] = rom[0];
 A = rom[1] + 256 * rom[2];
 rom[A+diff] = rom[A];
 rom[A+1] ^= 0xee;
 A = rom[A+1] + 256 * rom[A+2];
 rom[A+diff] = rom[A];
 A += 2;
 rom[A+diff] = rom[A];
}

canonical_original_code:
static void init_kchampvs()
{
 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 < 0x10000;A++)
  rom[A+diff] = (rom[A] & 0x55) | ((rom[A] & 0x88) >> 2) | ((rom[A] & 0x22) << 2);
 rom[0+diff] = rom[0];
 A = rom[1] + 256 * rom[2];
 rom[A+diff] = rom[A];
 rom[A+1] ^= 0xee;
 A = rom[A+1] + 256 * rom[A+2];
 rom[A+diff] = rom[A];
 A += 2;
 rom[A+diff] = rom[A];
}

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: A int


msmint

decompiled_code:
__int64 msmint()
{
int v0; // esi
__int64 result; // rax

LOBYTE(v0) = msm_data;
if ( !msm_play_lo_nibble )
v0 = msm_data >> 4;
result = MSM5205_data_w(0LL, v0 & 0xF);
msm_play_lo_nibble ^= 1u;
counter_0 ^= 1u;
if ( !counter_0 )
{
result = (unsigned int)sound_nmi_enable;
if ( sound_nmi_enable )
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // esi
__int64 result; // rax

LOBYTE(v0) = msm_data;
if ( !msm_play_lo_nibble )
v0 = msm_data >> 4;
result = MSM5205_data_w(0LL, v0 & 0xF);
msm_play_lo_nibble ^= 1u;
counter_0 ^= 1u;
if ( !counter_0 )
{
result = (unsigned int)sound_nmi_enable;
if ( sound_nmi_enable )
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

original_code:
static void msmint( int data ) {
 static int counter = 0;
 if ( msm_play_lo_nibble )
  MSM5205_data_w( 0, msm_data & 0x0f );
 else
  MSM5205_data_w( 0, ( msm_data >> 4 ) & 0x0f );
 msm_play_lo_nibble ^= 1;
 if ( !( counter ^= 1 ) ) {
  if ( sound_nmi_enable ) {
   cpu_cause_interrupt( 1, -2 );
  }
 }
}

canonical_original_code:
static void msmint(int data) {
 static int counter = 0;
 if ( msm_play_lo_nibble )
  MSM5205_data_w( 0, msm_data & 0x0f );
 else
  MSM5205_data_w( 0, ( msm_data >> 4 ) & 0x0f );
 msm_play_lo_nibble ^= 1;
 if ( !( counter ^= 1 ) ) {
  if ( sound_nmi_enable ) {
   cpu_cause_interrupt( 1, -2 );
  }
 }
}

variable_types: data int

variable_types: counter int


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

result = MSM5205_reset_w(0LL, (a2 & 1) == 0);
sound_nmi_enable = (a2 >> 1) & 1;
return result;
}

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

result = MSM5205_reset_w(0LL, (a2 & 1) == 0);
sound_nmi_enable = (a2 >> 1) & 1;
return result;
}

original_code:
static void sound_control_w(offs_t offset,data_t data) {
 MSM5205_reset_w( 0, !( data & 1 ) );
 sound_nmi_enable = ( ( data >> 1 ) & 1 );
}

canonical_original_code:
static void sound_control_w(unsigned int offset, unsigned int data) {
 MSM5205_reset_w( 0, !( data & 1 ) );
 sound_nmi_enable = ( ( data >> 1 ) & 1 );
}


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

canonical_decompiled_code:
__int64 func11()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 255LL);
}

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

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


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall champbas_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
__int64 v3; // rcx
__int64 v4; // rdx
char v5; // al
void *result; // rax
int v7; // ebx
__int64 v8; // r15
__int64 v9; // rcx
unsigned int v10; // er10
int v11; // edx
__int64 v12; // r9
__int64 v13; // r8
__int64 v14; // [rsp-28h] [rbp-60h]
__int64 v15; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = (*(_BYTE *)(colorram + v2) & 0x1Fu) + 32;
v4 = *(unsigned __int8 *)(videoram + v2--);
v14 = (unsigned int)(8 * (v1 >> 5));
v5 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfxbank + 512),
v4,
v3,
0LL,
0LL,
8 * (v5 & 0x1Fu),
v14,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v7 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v8 = v7;
do
{
v9 = *(unsigned __int8 *)(spriteram + v8 + 1);
v10 = *(_BYTE *)(spriteram + v8) >> 2;
v15 = (unsigned int)*(unsigned __int8 *)(spriteram_2 + v8) - 16;
v11 = (unsigned __int8)(16 - *(_BYTE *)(spriteram_2 + v8 + 1));
v12 = *(_BYTE *)(spriteram + v8) & 2;
v13 = *(_BYTE *)(spriteram + v8) & 1;
v8 -= 2LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (gfxbank + 2) + 512),
v10,
v9,
v13,
v12,
(unsigned int)(v11 - 16),
v15,
Machine + 776LL,
6LL,
0LL);
v7 -= 2;
}
while ( v7 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
__int64 v3; // rcx
__int64 v4; // rdx
char v5; // al
void *result; // rax
int v7; // ebx
__int64 v8; // r15
__int64 v9; // rcx
unsigned int v10; // er10
int v11; // edx
__int64 v12; // r9
__int64 v13; // r8
__int64 v14; // [rsp-28h] [rbp-60h]
__int64 v15; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = (*(_BYTE *)(colorram + v2) & 0x1Fu) + 32;
v4 = *(unsigned __int8 *)(videoram + v2--);
v14 = (unsigned int)(8 * (v1 >> 5));
v5 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfxbank + 512),
v4,
v3,
0LL,
0LL,
8 * (v5 & 0x1Fu),
v14,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v7 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v8 = v7;
do
{
v9 = *(unsigned __int8 *)(spriteram + v8 + 1);
v10 = *(_BYTE *)(spriteram + v8) >> 2;
v15 = (unsigned int)*(unsigned __int8 *)(spriteram_2 + v8) - 16;
v11 = (unsigned __int8)(16 - *(_BYTE *)(spriteram_2 + v8 + 1));
v12 = *(_BYTE *)(spriteram + v8) & 2;
v13 = *(_BYTE *)(spriteram + v8) & 1;
v8 -= 2LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (gfxbank + 2) + 512),
v10,
v9,
v13,
v12,
(unsigned int)(v11 - 16),
v15,
Machine + 776LL,
6LL,
0LL);
v7 -= 2;
}
while ( v7 >= 0 );
}
return result;
}

original_code:
void champbas_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0 + gfxbank],
     videoram[offs],
     (colorram[offs] & 0x1f) + 32,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  drawgfx(bitmap,Machine->gfx[2 + gfxbank],
    spriteram[offs] >> 2,
    spriteram[offs + 1],
    spriteram[offs] & 1,spriteram[offs] & 2,
    ((256+16 - spriteram_2[offs + 1]) & 0xff) - 16,spriteram_2[offs] - 16,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
void champbas_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0 + gfxbank],
     videoram[offs],
     (colorram[offs] & 0x1f) + 32,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  drawgfx(bitmap,Machine->gfx[2 + gfxbank],
    spriteram[offs] >> 2,
    spriteram[offs + 1],
    spriteram[offs] & 1,spriteram[offs] & 2,
    ((256+16 - spriteram_2[offs + 1]) & 0xff) - 16,spriteram_2[offs] - 16,
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

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

variable_types: offs int


decompiled_code:
__int64 __fastcall champbas_dac_w(__int64 a1, int a2)
{
return DAC_signed_data_w(0LL, (unsigned int)(4 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return DAC_signed_data_w(0LL, (unsigned int)(4 * a2));
}

original_code:
void champbas_dac_w(offs_t offset,data_t data)
{
 DAC_signed_data_w(0,data<<2);
}

canonical_original_code:
void champbas_dac_w(unsigned int offset, unsigned int data)
{
 DAC_signed_data_w(0,data<<2);
}


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

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

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall qwakprot_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebp
__int64 v3; // r12
unsigned __int8 v4; // al
__int64 v5; // rsi
__int64 v6; // rdx
char v7; // al
__int64 i; // r14
int v9; // er13
int v10; // ebp
unsigned __int8 v11; // r12
unsigned int v12; // er8
int v13; // er9
__int64 result; // rax
int v15; // er11
int v16; // ecx
__int64 v17; // [rsp-28h] [rbp-60h]

if ( palette_recalc() || a2 )
{
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
else
{
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
v3 = v2;
do
{
while ( !*((_BYTE *)dirtybuffer + v3) )
{
--v2;
--v3;
if ( v2 == -1 )
goto LABEL_8;
}
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(_BYTE *)(videoram + v3--);
v5 = *(_QWORD *)(Machine + 8LL * (v4 >> 7) + 512);
v6 = v4 & 0x7F;
v17 = (unsigned int)(8 * (v2 >> 5));
v7 = v2--;
drawgfx(a1, v5, v6, 0LL, 0LL, 0LL, 8 * (v7 & 0x1Fu), v17, Machine + 776LL, 0LL, 0LL);
}
while ( v2 != -1 );
LABEL_8:
for ( i = 0LL; i != 16; ++i )
{
v9 = *(unsigned __int8 *)(spriteram + i + 32);
v10 = 240 - *(unsigned __int8 *)(spriteram + i + 16);
v11 = *(_BYTE *)(spriteram + i + 32);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(_BYTE *)(spriteram + i) & 0x7F,
0LL,
0LL,
*(_BYTE *)(spriteram + i) & 0x80,
v11,
(unsigned int)v10,
&spritevisiblearea,
2LL,
0LL);
v12 = v10 >> 3;
v13 = v9 >> 3;
result = v10 & 0xF;
v15 = (v10 >> 3) - (((_DWORD)result == 0) - 3);
if ( v10 >> 3 < v15 )
{
v16 = v13 + ((v11 & 7) != 0) + 1;
do
{
if ( v13 < v16 )
{
LODWORD(result) = v9 >> 3;
do
{
if ( (int)result <= 31 && v12 <= 0x1D )
*((_BYTE *)dirtybuffer + (int)(result + 32 * v12)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v16 );
}
++v12;
}
while ( v12 != v15 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // ebp
__int64 v3; // r12
unsigned __int8 v4; // al
__int64 v5; // rsi
__int64 v6; // rdx
char v7; // al
__int64 i; // r14
int v9; // er13
int v10; // ebp
unsigned __int8 v11; // r12
unsigned int v12; // er8
int v13; // er9
__int64 result; // rax
int v15; // er11
int v16; // ecx
__int64 v17; // [rsp-28h] [rbp-60h]

if ( palette_recalc() || a2 )
{
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
else
{
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
v3 = v2;
do
{
while ( !*((_BYTE *)dirtybuffer + v3) )
{
--v2;
--v3;
if ( v2 == -1 )
goto LABEL_8;
}
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(_BYTE *)(videoram + v3--);
v5 = *(_QWORD *)(Machine + 8LL * (v4 >> 7) + 512);
v6 = v4 & 0x7F;
v17 = (unsigned int)(8 * (v2 >> 5));
v7 = v2--;
drawgfx(a1, v5, v6, 0LL, 0LL, 0LL, 8 * (v7 & 0x1Fu), v17, Machine + 776LL, 0LL, 0LL);
}
while ( v2 != -1 );
LABEL_8:
for ( i = 0LL; i != 16; ++i )
{
v9 = *(unsigned __int8 *)(spriteram + i + 32);
v10 = 240 - *(unsigned __int8 *)(spriteram + i + 16);
v11 = *(_BYTE *)(spriteram + i + 32);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(_BYTE *)(spriteram + i) & 0x7F,
0LL,
0LL,
*(_BYTE *)(spriteram + i) & 0x80,
v11,
(unsigned int)v10,
&spritevisiblearea,
2LL,
0LL);
v12 = v10 >> 3;
v13 = v9 >> 3;
result = v10 & 0xF;
v15 = (v10 >> 3) - (((_DWORD)result == 0) - 3);
if ( v10 >> 3 < v15 )
{
v16 = v13 + ((v11 & 7) != 0) + 1;
do
{
if ( v13 < v16 )
{
LODWORD(result) = v9 >> 3;
do
{
if ( (int)result <= 31 && v12 <= 0x1D )
*((_BYTE *)dirtybuffer + (int)(result + 32 * v12)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v16 );
}
++v12;
}
while ( v12 != v15 );
}
}
return result;
}

original_code:
void qwakprot_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   int gfxset;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   gfxset = ((videoram[offs] & 0x80) >> 7);
   drawgfx(bitmap,Machine->gfx[gfxset],
     videoram[offs] & 0x7f,
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum;
  int flip;
  int x, y;
  int sx, sy;
  spritenum = spriteram[offs] & 0x7f;
  flip = (spriteram[offs] & 0x80);
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  drawgfx(bitmap,Machine->gfx[2],
    spritenum,0,
    0,flip,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2, y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

canonical_original_code:
void qwakprot_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   int gfxset;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   gfxset = ((videoram[offs] & 0x80) >> 7);
   drawgfx(bitmap,Machine->gfx[gfxset],
     videoram[offs] & 0x7f,
     0,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum;
  int flip;
  int x; int y;
  int sx; int sy;
  spritenum = spriteram[offs] & 0x7f;
  flip = (spriteram[offs] & 0x80);
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  drawgfx(bitmap,Machine->gfx[2],
    spritenum,0,
    0,flip,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2; int y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 30) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: gfxset int

variable_types: spritenum int

variable_types: flip int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall qwakprot_led_w(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

original_code:
static void qwakprot_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset,~data >> 7);
}

canonical_original_code:
static void qwakprot_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,~data >> 7);
}


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

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

variable_types:
palette
unsigned char *


decompiled_code:
__int64 megazone_dip3_r()
{
return 255LL;
}

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

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

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


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

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

original_code:
data_t megazone_sharedram_r(offs_t offset)
{
 return(megazone_sharedram[offset]);
}

canonical_original_code:
unsigned int megazone_sharedram_r(unsigned int offset)
{
 return(megazone_sharedram[offset]);
}


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

v0 = videoram_size;
tmpbitmap = 0LL;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
v2 = bitmap_alloc(256LL, 256LL);
v3 = 0;
tmpbitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
v3 = 1;
}
return v3;
}

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

v0 = videoram_size;
tmpbitmap = 0LL;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1;
memset(v1, 1, v0);
v2 = bitmap_alloc(256LL, 256LL);
v3 = 0;
tmpbitmap = v2;
if ( !v2 )
{
free(dirtybuffer);
v3 = 1;
}
return v3;
}

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

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


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

free(dirtybuffer);
result = bitmap_free(tmpbitmap);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
return result;
}

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

free(dirtybuffer);
result = bitmap_free(tmpbitmap);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
return result;
}

original_code:
void megazone_vh_stop(void)
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
 dirtybuffer = 0;
 tmpbitmap = 0;
}

canonical_original_code:
void megazone_vh_stop()
{
 free(dirtybuffer);
 bitmap_free(tmpbitmap);
 dirtybuffer = 0;
 tmpbitmap = 0;
}


decompiled_code:
__int64 __fastcall megazone_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
__int64 v3; // r8
__int64 v4; // rcx
__int64 v5; // r9
int v6; // esi
__int16 v7; // ax
__int64 v8; // rdx
int v9; // ebx
__int64 v10; // r14
__int64 v11; // r9
__int64 v12; // rcx
__int64 v13; // r8
int v14; // eax
__int64 v15; // rdx
__int64 v16; // r15
__int64 v17; // rbx
char v18; // r8
int v19; // esi
__int64 result; // rax
__int64 v21; // [rsp-30h] [rbp-88h]
__int64 v22; // [rsp-28h] [rbp-80h]
__int64 v23; // [rsp-28h] [rbp-80h]
__int64 i; // [rsp+8h] [rbp-50h]
int v25; // [rsp+18h] [rbp-40h] BYREF
int v26[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*((_BYTE *)dirtybuffer + v2) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*((_BYTE *)dirtybuffer + v2) = 0;
v3 = *(_BYTE *)(colorram + v2) & 0x40;
v4 = (*(_BYTE *)(colorram + v2) & 0xFu) + 16;
v5 = *(_BYTE *)(colorram + v2) & 0x20;
v6 = *(unsigned __int8 *)(videoram + v2);
v7 = *(char *)(colorram + v2--);
v8 = v6 + (v7 & 0x100u);
v22 = (unsigned int)(8 * (v1 >> 5));
LOBYTE(v7) = v1--;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 512LL), v8, v4, v3, v5, 8 * (v7 & 0x1Fu), v22, 0LL, 0LL, 0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v25 = 32 - (unsigned __int8)*megazone_scrolly;
v26[0] = -(unsigned __int8)*megazone_scrollx;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v25, 1LL, v26, Machine + 776LL, 0LL, 0LL);
v9 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v10 = v9 + 3LL;
do
{
v11 = *(_BYTE *)(spriteram + v10 - 3) & 0x80;
v12 = *(_BYTE *)(spriteram + v10 - 3) & 0xF;
v13 = ~*(_BYTE *)(spriteram + v10 - 3) & 0x40;
v23 = (unsigned __int8)~(*(_BYTE *)(spriteram + v10 - 2) + 16);
v14 = *(unsigned __int8 *)(spriteram + v10);
v15 = *(unsigned __int8 *)(spriteram + v10 - 1);
v10 -= 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v15,
v12,
v13,
v11,
(unsigned int)(v14 + 32),
v23,
Machine + 776LL,
6LL,
0LL);
v9 -= 4;
}
while ( v9 >= 0 );
}
for ( i = 0LL; i != 32; result = i )
{
v16 = 0LL;
v17 = 32 * i;
do
{
v18 = *(_BYTE *)(megazone_colorram2 + v17);
v19 = *(unsigned __int8 *)(megazone_videoram2 + v17++);
v21 = v16;
v16 = (unsigned int)(v16 + 8);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v19 + (v18 & 0x100u),
(v18 & 0xFu) + 16,
v18 & 0x40,
v18 & 0x20,
v21,
(unsigned int)(8 * i),
0LL,
0LL,
0LL);
}
while ( (_DWORD)v16 != 48 );
++i;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
__int64 v3; // r8
__int64 v4; // rcx
__int64 v5; // r9
int v6; // esi
__int16 v7; // ax
__int64 v8; // rdx
int v9; // ebx
__int64 v10; // r14
__int64 v11; // r9
__int64 v12; // rcx
__int64 v13; // r8
int v14; // eax
__int64 v15; // rdx
__int64 v16; // r15
__int64 v17; // rbx
char v18; // r8
int v19; // esi
__int64 result; // rax
__int64 v21; // [rsp-30h] [rbp-88h]
__int64 v22; // [rsp-28h] [rbp-80h]
__int64 v23; // [rsp-28h] [rbp-80h]
__int64 i; // [rsp+8h] [rbp-50h]
int v25; // [rsp+18h] [rbp-40h] BYREF
int v26[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*((_BYTE *)dirtybuffer + v2) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*((_BYTE *)dirtybuffer + v2) = 0;
v3 = *(_BYTE *)(colorram + v2) & 0x40;
v4 = (*(_BYTE *)(colorram + v2) & 0xFu) + 16;
v5 = *(_BYTE *)(colorram + v2) & 0x20;
v6 = *(unsigned __int8 *)(videoram + v2);
v7 = *(char *)(colorram + v2--);
v8 = v6 + (v7 & 0x100u);
v22 = (unsigned int)(8 * (v1 >> 5));
LOBYTE(v7) = v1--;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 512LL), v8, v4, v3, v5, 8 * (v7 & 0x1Fu), v22, 0LL, 0LL, 0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v25 = 32 - (unsigned __int8)*megazone_scrolly;
v26[0] = -(unsigned __int8)*megazone_scrollx;
copyscrollbitmap(a1, tmpbitmap, 1LL, &v25, 1LL, v26, Machine + 776LL, 0LL, 0LL);
v9 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v10 = v9 + 3LL;
do
{
v11 = *(_BYTE *)(spriteram + v10 - 3) & 0x80;
v12 = *(_BYTE *)(spriteram + v10 - 3) & 0xF;
v13 = ~*(_BYTE *)(spriteram + v10 - 3) & 0x40;
v23 = (unsigned __int8)~(*(_BYTE *)(spriteram + v10 - 2) + 16);
v14 = *(unsigned __int8 *)(spriteram + v10);
v15 = *(unsigned __int8 *)(spriteram + v10 - 1);
v10 -= 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v15,
v12,
v13,
v11,
(unsigned int)(v14 + 32),
v23,
Machine + 776LL,
6LL,
0LL);
v9 -= 4;
}
while ( v9 >= 0 );
}
for ( i = 0LL; i != 32; result = i )
{
v16 = 0LL;
v17 = 32 * i;
do
{
v18 = *(_BYTE *)(megazone_colorram2 + v17);
v19 = *(unsigned __int8 *)(megazone_videoram2 + v17++);
v21 = v16;
v16 = (unsigned int)(v16 + 8);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v19 + (v18 & 0x100u),
(v18 & 0xFu) + 16,
v18 & 0x40,
v18 & 0x20,
v21,
(unsigned int)(8 * i),
0LL,
0LL,
0LL);
}
while ( (_DWORD)v16 != 48 );
++i;
}
return result;
}

original_code:
void megazone_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int x,y;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipx,flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & (1<<6);
   flipy = colorram[offs] & (1<<5);
   drawgfx(tmpbitmap,Machine->gfx[0],
     ((int)videoram[offs]) + ((colorram[offs] & (1<<7) ? 256 : 0) ),
     (colorram[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx = -*megazone_scrolly + 4*8;
  int scrolly = -*megazone_scrollx;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  for (offs = spriteram_size-4; offs >= 0;offs -= 4)
  {
   int sx,sy,flipx,flipy;
   sx = spriteram[offs + 3] + 4*8;
   sy = 255-((spriteram[offs + 1]+16)&0xff);
   flipx = ~spriteram[offs+0] & 0x40;
   flipy = spriteram[offs+0] & 0x80;
   drawgfx(bitmap,Machine->gfx[1],
     spriteram[offs + 2],
     spriteram[offs + 0] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
 for (y = 0; y < 32;y++)
 {
  offs = y*32;
  for (x = 0; x < 6; x++)
  {
   int sx,sy,flipx,flipy;
   sx = x;
   sy = y;
   flipx = megazone_colorram2[offs] & (1<<6);
   flipy = megazone_colorram2[offs] & (1<<5);
   drawgfx(bitmap,Machine->gfx[0],
     ((int)megazone_videoram2[offs]) + ((megazone_colorram2[offs] & (1<<7) ? 256 : 0) ),
     (megazone_colorram2[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   offs++;
  }
 }
}

canonical_original_code:
void megazone_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int x; int y;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & (1<<6);
   flipy = colorram[offs] & (1<<5);
   drawgfx(tmpbitmap,Machine->gfx[0],
     ((int)videoram[offs]) + ((colorram[offs] & (1<<7) ? 256 : 0) ),
     (colorram[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx = -*megazone_scrolly + 4*8;
  int scrolly = -*megazone_scrollx;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 {
  for (offs = spriteram_size-4; offs >= 0;offs -= 4)
  {
   int sx; int sy; int flipx; int flipy;
   sx = spriteram[offs + 3] + 4*8;
   sy = 255-((spriteram[offs + 1]+16)&0xff);
   flipx = ~spriteram[offs+0] & 0x40;
   flipy = spriteram[offs+0] & 0x80;
   drawgfx(bitmap,Machine->gfx[1],
     spriteram[offs + 2],
     spriteram[offs + 0] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
 for (y = 0; y < 32;y++)
 {
  offs = y*32;
  for (x = 0; x < 6; x++)
  {
   int sx; int sy; int flipx; int flipy;
   sx = x;
   sy = y;
   flipx = megazone_colorram2[offs] & (1<<6);
   flipy = megazone_colorram2[offs] & (1<<5);
   drawgfx(bitmap,Machine->gfx[0],
     ((int)megazone_videoram2[offs]) + ((megazone_colorram2[offs] & (1<<7) ? 256 : 0) ),
     (megazone_colorram2[offs] & 0x0f) + 0x10,
     flipx,flipy,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   offs++;
  }
 }
}

variable_types: flipx int

variable_types: flipy int

variable_types: scrollx int

variable_types: scrolly int


decompiled_code:
__int64 megazone_portA_r()
{
int v0; // eax

v0 = cpu_gettotalcycles();
return i8039_status | (unsigned int)(unsigned __int8)(16 * (((5124611814397LL * v0) >> 52) - ((7159 * v0) >> 31)));
}

original_code:
data_t megazone_portA_r(offs_t offset)
{
 int clock,timer;
 clock = cpu_gettotalcycles() * 7159/12288;
 timer = (clock / (1024/2)) & 0x0f;
 return (timer << 4) | i8039_status;
}

canonical_original_code:
unsigned int megazone_portA_r(unsigned int offset)
{
 int clock; int timer;
 clock = cpu_gettotalcycles() * 7159/12288;
 timer = (clock / (1024/2)) & 0x0f;
 return (timer << 4) | i8039_status;
}

variable_types:
offset
unsigned int

variable_types: clock int

variable_types: timer int


decompiled_code:
// attributes: thunk
__int64 init_megazone()
{
return konami1_decode();
}

canonical_decompiled_code:
__int64 func11()
{
return konami1_decode();
}

original_code:
static void init_megazone(void)
{
 konami1_decode();
}

canonical_original_code:
static void init_megazone()
{
 konami1_decode();
}


decompiled_code:
__int64 __fastcall megazone_portB_w(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
__int64 v4; // rdi
__int64 v5; // r8
__int64 result; // rax

v2 = 0;
do
{
v4 = v2;
v5 = -(a2 & 1) & 0x2710;
if ( (a2 & 2) != 0 )
v5 = (unsigned int)(v5 + 220000);
++v2;
a2 >>= 2;
result = set_RC_filter(v4, 1000LL, 2200LL, 200LL, v5);
}
while ( v2 != 3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebp
__int64 v4; // rdi
__int64 v5; // r8
__int64 result; // rax

v2 = 0;
do
{
v4 = v2;
v5 = -(a2 & 1) & 0x2710;
if ( (a2 & 2) != 0 )
v5 = (unsigned int)(v5 + 220000);
++v2;
a2 >>= 2;
result = set_RC_filter(v4, 1000LL, 2200LL, 200LL, v5);
}
while ( v2 != 3 );
return result;
}

original_code:
static void megazone_portB_w(offs_t offset,data_t data)
{
 int i;
 for (i = 0;i < 3;i++)
 {
  int C;
  C = 0;
  if (data & 1) C += 10000;
  if (data & 2) C += 220000;
  data >>= 2;
  set_RC_filter(i,1000,2200,200,C);
 }
}

canonical_original_code:
static void megazone_portB_w(unsigned int offset, unsigned int data)
{
 int i;
 for (i = 0;i < 3;i++)
 {
  int C;
  C = 0;
  if (data & 1) C += 10000;
  if (data & 2) C += 220000;
  data >>= 2;
  set_RC_filter(i,1000,2200,200,C);
 }
}

variable_types:
data
unsigned int

variable_types: i int

variable_types: C int


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

result = (unsigned int)i8039_irqenable;
if ( i8039_irqenable )
result = cpu_cause_interrupt(2LL, 1LL);
return result;
}

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

result = (unsigned int)i8039_irqenable;
if ( i8039_irqenable )
result = cpu_cause_interrupt(2LL, 1LL);
return result;
}

original_code:
static void megazone_i8039_irq_w(offs_t offset,data_t data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(2,1);
}

canonical_original_code:
static void megazone_i8039_irq_w(unsigned int offset, unsigned int data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(2,1);
}


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

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

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

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

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

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


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

result = (unsigned __int8)a2 & 0x80;
i8039_irqenable = a2 & 0x80;
i8039_status = (a2 >> 4) & 7;
return result;
}

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

result = (unsigned __int8)a2 & 0x80;
i8039_irqenable = a2 & 0x80;
i8039_status = (a2 >> 4) & 7;
return result;
}

original_code:
void i8039_irqen_and_status_w(offs_t offset,data_t data)
{
 i8039_irqenable = data & 0x80;
 i8039_status = (data & 0x70) >> 4;
}

canonical_original_code:
void i8039_irqen_and_status_w(unsigned int offset, unsigned int data)
{
 i8039_irqenable = data & 0x80;
 i8039_status = (data & 0x70) >> 4;
}


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

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

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

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


decompiled_code:
void __fastcall ohmygod_spritebank_w(__int64 a1, __int16 a2)
{
spritebank = a2 & 0x8000;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int16 a2)
{
spritebank = a2 & 0x8000;
}

original_code:
void ohmygod_spritebank_w(offs_t offset,data_t data)
{
 spritebank = data & 0x8000;
}

canonical_original_code:
void ohmygod_spritebank_w(unsigned int offset, unsigned int data)
{
 spritebank = data & 0x8000;
}


decompiled_code:
_BOOL8 ohmygod_vh_start()
{
bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 64LL);
return bg_tilemap == 0;
}

canonical_decompiled_code:
_BOOL8 func3()
{
bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 64LL);
return bg_tilemap == 0;
}

original_code:
int ohmygod_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,64,64);
 if (!bg_tilemap)
  return 1;
 return 0;
}

canonical_original_code:
int ohmygod_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,64,64);
 if (!bg_tilemap)
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall ohmygod_videoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ohmygod_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(ohmygod_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 2);
}
return result;
}

original_code:
void ohmygod_videoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&ohmygod_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(UINT16 *)(&ohmygod_videoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,offset/4);
 }
}

canonical_original_code:
void ohmygod_videoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&ohmygod_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(unsigned short *)(&ohmygod_videoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,offset/4);
 }
}

variable_types: oldword int

variable_types: newword int


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

if ( a1 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)(a2 - 33263));
else
result = tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned int)(a2 - 33260));
return result;
}

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

if ( a1 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)(a2 - 33263));
else
result = tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned int)(a2 - 33260));
return result;
}

original_code:
void ohmygod_scroll_w(offs_t offset,data_t data)
{
 if (offset == 0) tilemap_set_scrollx(bg_tilemap,0,data - 0x81ec);
 else tilemap_set_scrolly(bg_tilemap,0,data - 0x81ef);
}

canonical_original_code:
void ohmygod_scroll_w(unsigned int offset, unsigned int data)
{
 if (offset == 0) tilemap_set_scrollx(bg_tilemap,0,data - 0x81ec);
 else tilemap_set_scrolly(bg_tilemap,0,data - 0x81ef);
}


decompiled_code:
void *ohmygod_init_machine()
{
__int64 v0; // rbx

v0 = memory_region(146LL);
watchdog_reset_r(0LL);
sndbank[0] = 0;
return memcpy((void *)(v0 + 0x20000), (const void *)(v0 + 0x40000), 0x20000uLL);
}

canonical_decompiled_code:
void *func8()
{
__int64 v0; // rbx

v0 = memory_region(146LL);
watchdog_reset_r(0LL);
sndbank[0] = 0;
return memcpy((void *)(v0 + 0x20000), (const void *)(v0 + 0x40000), 0x20000uLL);
}

original_code:
static void ohmygod_init_machine(void)
{
 unsigned char *rom = memory_region(REGION_SOUND1);
 watchdog_reset_r(0);
 sndbank = 0;
 memcpy(rom + 0x20000,rom + 0x40000 + 0x20000 * sndbank,0x20000);
}

canonical_original_code:
static void ohmygod_init_machine()
{
 unsigned char *rom = memory_region(REGION_SOUND1);
 watchdog_reset_r(0);
 sndbank = 0;
 memcpy(rom + 0x20000,rom + 0x40000 + 0x20000 * sndbank,0x20000);
}

variable_types:
rom
unsigned char *


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

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

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

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

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

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned short code = (*(UINT16 *)(&ohmygod_videoram[4*tile_index+2]));
 unsigned short attr = (*(UINT16 *)(&ohmygod_videoram[4*tile_index]));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x0f00) >> 8)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types:
code
unsigned short

variable_types:
attr
unsigned short

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:
void __fastcall battlnts_spritebank_w(__int64 a1, char a2)
{
spritebank = (a2 & 1) << 10;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
spritebank = (a2 & 1) << 10;
}

original_code:
void battlnts_spritebank_w(offs_t offset,data_t data)
{
 spritebank = 1024 * (data & 1);
}

canonical_original_code:
void battlnts_spritebank_w(unsigned int offset, unsigned int data)
{
 spritebank = 1024 * (data & 1);
}


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

layer_colorbase = 0LL;
if ( (unsigned int)K007342_vh_start(0LL, tile_callback) )
{
K007342_tilemap_set_enable(1LL, 0LL);
result = 1LL;
}
else
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

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

layer_colorbase = 0LL;
if ( (unsigned int)K007342_vh_start(0LL, tile_callback) )
{
K007342_tilemap_set_enable(1LL, 0LL);
result = 1LL;
}
else
{
result = K007420_vh_start(1LL, sprite_callback);
if ( (_DWORD)result )
{
K007420_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int battlnts_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 0;
 if (K007342_vh_start(0,tile_callback))
 {
  K007342_tilemap_set_enable(1, 0);
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int battlnts_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 0;
 if (K007342_vh_start(0,tile_callback))
 {
  K007342_tilemap_set_enable(1, 0);
  return 1;
 }
 if (K007420_vh_start(1,sprite_callback))
 {
  K007420_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 battlnts_vh_stop()
{
K007342_vh_stop();
return K007420_vh_stop();
}

original_code:
void battlnts_vh_stop(void)
{
 K007342_vh_stop();
 K007420_vh_stop();
}

canonical_original_code:
void battlnts_vh_stop()
{
 K007342_vh_stop();
 K007420_vh_stop();
}