decompiled_code:
_BOOL8 __fastcall YM2612_sh_start(__int64 a1)
{
unsigned int v1; // er12
int *v2; // rbp
_BOOL8 result; // rax
__int64 v4; // rdi
__int64 v5; // rbx
int v6[2]; // [rsp+8h] [rbp-90h] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-88h] BYREF
char s[40]; // [rsp+20h] [rbp-78h] BYREF
char v9[80]; // [rsp+48h] [rbp-50h] BYREF

v1 = *(_DWORD *)(Machine + 836LL);
v2 = *(int **)(a1 + 8);
intf = (__int64)v2;
result = 1LL;
if ( *v2 <= 2 )
{
FMTimerInit();
v4 = (unsigned int)*v2;
if ( (int)v4 > 0 )
{
v5 = 0LL;
do
{
v6[0] = *(_DWORD *)(intf + 4LL * (int)v5 + 8);
v7[0] = (__int64)s;
sprintf(s, "YM2612(%s) #%d", "FM", (unsigned int)v5);
v6[1] = *(_DWORD *)(intf + 4LL * (int)v5 + 8);
v7[1] = (__int64)v9;
sprintf(v9, "YM2612(%s) #%d", "FM", (unsigned int)v5);
stream[v5] = stream_init_multi(2LL, v7, v6, v1, (unsigned int)v5, &YM2612UpdateOne);
v2 = (int *)intf;
v4 = *(unsigned int *)intf;
++v5;
}
while ( (int)v4 > (int)v5 );
}
result = (unsigned int)YM2612Init(v4, (unsigned int)v2[1], v1, TimerHandler, IRQHandler) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
int *v2; // rbp
_BOOL8 result; // rax
__int64 v4; // rdi
__int64 v5; // rbx
int v6[2]; // [rsp+8h] [rbp-90h] BYREF
__int64 v7[2]; // [rsp+10h] [rbp-88h] BYREF
char s[40]; // [rsp+20h] [rbp-78h] BYREF
char v9[80]; // [rsp+48h] [rbp-50h] BYREF

v1 = *(_DWORD *)(Machine + 836LL);
v2 = *(int **)(a1 + 8);
intf = (__int64)v2;
result = 1LL;
if ( *v2 <= 2 )
{
func0();
v4 = (unsigned int)*v2;
if ( (int)v4 > 0 )
{
v5 = 0LL;
do
{
v6[0] = *(_DWORD *)(intf + 4LL * (int)v5 + 8);
v7[0] = (__int64)s;
sprintf(s, "YM2612(%s) #%d", "FM", (unsigned int)v5);
v6[1] = *(_DWORD *)(intf + 4LL * (int)v5 + 8);
v7[1] = (__int64)v9;
sprintf(v9, "YM2612(%s) #%d", "FM", (unsigned int)v5);
stream[v5] = stream_init_multi(2LL, v7, v6, v1, (unsigned int)v5, &YM2612UpdateOne);
v2 = (int *)intf;
v4 = *(unsigned int *)intf;
++v5;
}
while ( (int)v4 > (int)v5 );
}
result = (unsigned int)YM2612Init(v4, (unsigned int)v2[1], v1, TimerHandler, IRQHandler) != 0;
}
return result;
}

original_code:
int YM2612_sh_start(const struct MachineSound *msound)
{
 int i,j;
 int rate = Machine->sample_rate;
 char buf[2][40];
 const char *name[2];
 intf = (const struct AY8910interface *)msound->sound_interface;
 if( intf->num > (2) ) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  int vol[2];
  for (j = 0 ; j < 2 ; j++)
  {
   vol[j] = intf->mixing_level[i];
   name[j] = buf[j];
   sprintf(buf[j],"YM2612(%s) #%d",j < 2 ? "FM" : "ADPCM",i);
  }
  stream[i] = stream_init_multi(2,
   name,vol,rate,
   i,YM2612UpdateOne);
 }
 if (YM2612Init(intf->num,intf->baseclock,rate,TimerHandler,IRQHandler) == 0)
   return 0;
 return 1;
}

canonical_original_code:
int YM2612_sh_start(struct MachineSound *msound)
{
 int i; int j;
 int rate = Machine->sample_rate;
 char buf[2][40];
 char *name[2];
 intf = (struct AY8910interface *)msound->sound_interface;
 if( intf->num > (2) ) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  int vol[2];
  for (j = 0 ; j < 2 ; j++)
  {
   vol[j] = intf->mixing_level[i];
   name[j] = buf[j];
   sprintf(buf[j],"YM2612(%s) #%d",j < 2 ? "FM" : "ADPCM",i);
  }
  stream[i] = stream_init_multi(2,
   name,vol,rate,
   i,YM2612UpdateOne);
 }
 if (YM2612Init(intf->num,intf->baseclock,rate,TimerHandler,IRQHandler) == 0)
   return 0;
 return 1;
}

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

variable_types: i int

variable_types: rate int

variable_types:
buf
char [2][40]

variable_types:
name
char *[2]

variable_types:
vol
int [2]

user_defined_types: struct AY8910interface { int num; int baseclock; int mixing_level[5]; unsigned int (*portAread[5])(unsigned int offset); unsigned int (*portBread[5])(unsigned int offset); void (*portAwrite[5])(unsigned int offset, unsigned int data); void (*portBwrite[5])(unsigned int offset, unsigned int data); void (*handler[5])(int irq); }


decompiled_code:
__int64 YM2612_sh_stop()
{
return YM2612Shutdown();
}

canonical_decompiled_code:
__int64 func4()
{
return YM2612Shutdown();
}

original_code:
void YM2612_sh_stop(void)
{
  YM2612Shutdown();
}

canonical_original_code:
void YM2612_sh_stop()
{
  YM2612Shutdown();
}

return_type: void


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

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

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

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

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

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


decompiled_code:
__int64 YM2612_status_port_0_A_r()
{
return (unsigned __int8)YM2612Read(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned __int8)YM2612Read(0LL, 0LL);
}

original_code:
data_t YM2612_status_port_0_A_r(offs_t offset)
{
  return YM2612Read(0,0);
}

canonical_original_code:
unsigned int YM2612_status_port_0_A_r(unsigned int offset)
{
  return YM2612Read(0,0);
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 YM2612_status_port_0_B_r()
{
return (unsigned __int8)YM2612Read(0LL, 2LL);
}

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

original_code:
data_t YM2612_status_port_0_B_r(offs_t offset)
{
  return YM2612Read(0,2);
}

canonical_original_code:
unsigned int YM2612_status_port_0_B_r(unsigned int offset)
{
  return YM2612Read(0,2);
}


decompiled_code:
__int64 YM2612_status_port_1_A_r()
{
return (unsigned __int8)YM2612Read(1LL, 0LL);
}

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

original_code:
data_t YM2612_status_port_1_A_r(offs_t offset) {
  return YM2612Read(1,0);
}

canonical_original_code:
unsigned int YM2612_status_port_1_A_r(unsigned int offset) {
  return YM2612Read(1,0);
}


decompiled_code:
__int64 YM2612_status_port_1_B_r()
{
return (unsigned __int8)YM2612Read(1LL, 2LL);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)YM2612Read(1LL, 2LL);
}

original_code:
data_t YM2612_status_port_1_B_r(offs_t offset) {
  return YM2612Read(1,2);
}

canonical_original_code:
unsigned int YM2612_status_port_1_B_r(unsigned int offset) {
  return YM2612Read(1,2);
}


decompiled_code:
__int64 YM2612_read_port_0_r()
{
return (unsigned __int8)YM2612Read(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned __int8)YM2612Read(0LL, 1LL);
}

original_code:
data_t YM2612_read_port_0_r(offs_t offset){
  return YM2612Read(0,1);
}

canonical_original_code:
unsigned int YM2612_read_port_0_r(unsigned int offset){
  return YM2612Read(0,1);
}


decompiled_code:
__int64 YM2612_read_port_1_r()
{
return (unsigned __int8)YM2612Read(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned __int8)YM2612Read(1LL, 1LL);
}

original_code:
data_t YM2612_read_port_1_r(offs_t offset){
  return YM2612Read(1,1);
}

canonical_original_code:
unsigned int YM2612_read_port_1_r(unsigned int offset){
  return YM2612Read(1,1);
}


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

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

original_code:
void YM2612_control_port_0_A_w(offs_t offset,data_t data)
{
  YM2612Write(0,0,data);
}

canonical_original_code:
void YM2612_control_port_0_A_w(unsigned int offset, unsigned int data)
{
  YM2612Write(0,0,data);
}

variable_types:
data
unsigned int


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

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

original_code:
void YM2612_control_port_0_B_w(offs_t offset,data_t data)
{
  YM2612Write(0,2,data);
}

canonical_original_code:
void YM2612_control_port_0_B_w(unsigned int offset, unsigned int data)
{
  YM2612Write(0,2,data);
}


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

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

original_code:
void YM2612_control_port_1_A_w(offs_t offset,data_t data){
  YM2612Write(1,0,data);
}

canonical_original_code:
void YM2612_control_port_1_A_w(unsigned int offset, unsigned int data){
  YM2612Write(1,0,data);
}


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

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

original_code:
void YM2612_control_port_1_B_w(offs_t offset,data_t data){
  YM2612Write(1,2,data);
}

canonical_original_code:
void YM2612_control_port_1_B_w(unsigned int offset, unsigned int data){
  YM2612Write(1,2,data);
}


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

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

original_code:
void YM2612_data_port_0_A_w(offs_t offset,data_t data)
{
  YM2612Write(0,1,data);
}

canonical_original_code:
void YM2612_data_port_0_A_w(unsigned int offset, unsigned int data)
{
  YM2612Write(0,1,data);
}


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

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

original_code:
void YM2612_data_port_0_B_w(offs_t offset,data_t data)
{
  YM2612Write(0,3,data);
}

canonical_original_code:
void YM2612_data_port_0_B_w(unsigned int offset, unsigned int data)
{
  YM2612Write(0,3,data);
}


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

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

original_code:
void YM2612_data_port_1_A_w(offs_t offset,data_t data){
  YM2612Write(1,1,data);
}

canonical_original_code:
void YM2612_data_port_1_A_w(unsigned int offset, unsigned int data){
  YM2612Write(1,1,data);
}


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

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

original_code:
void YM2612_data_port_1_B_w(offs_t offset,data_t data){
  YM2612Write(1,3,data);
}

canonical_original_code:
void YM2612_data_port_1_B_w(unsigned int offset, unsigned int data){
  YM2612Write(1,3,data);
}


FMTimerInit

decompiled_code:
void FMTimerInit()
{
qword_4C8 = 0LL;
Timer = 0LL;
qword_4D8 = 0LL;
qword_4D0 = 0LL;
}

canonical_decompiled_code:
void func0()
{
qword_4C8 = 0LL;
Timer = 0LL;
qword_4D8 = 0LL;
qword_4D0 = 0LL;
}

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

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


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

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

original_code:
data_t starfire_colorram_r(offs_t offset)
{
 return starfire_colorram[offset];
}

canonical_original_code:
unsigned int starfire_colorram_r(unsigned int offset)
{
 return starfire_colorram[offset];
}


decompiled_code:
__int64 __fastcall starfire_videoram_w(__int16 a1, int a2)
{
__int64 result; // rax
char v3; // cl
int v4; // er10
int v5; // esi
int v6; // ecx
_BYTE *v7; // rbp
__int16 v8; // r9
__int16 v9; // bx
__int16 v10; // r14
__int16 v11; // r13
char v12; // r12
__int16 v13; // r9

result = (a1 + 256) & 0x1FFF;
if ( (a1 & 0xE0) != 0 || (starfire_vidctrl1 & 0x20) != 0 )
{
if ( (a1 & 0x2000) != 0 )
{
v3 = ((unsigned __int8)starfire_vidctrl >> 1) & 7;
v4 = starfire_vidctrl & 1;
}
else
{
v3 = (unsigned __int8)starfire_vidctrl >> 5;
v4 = (starfire_vidctrl & 0x10) != 0;
}
if ( v4 )
a2 = (a2 >> 7) & 1 | (a2 >> 5) & 2 | (a2 >> 3) & 4 | (a2 >> 1) & 8 | (2 * (_BYTE)a2) & 0x10 | (8 * (_BYTE)a2) & 0x20 | (32 * (_BYTE)a2) & 0x40 | (unsigned __int8)((_BYTE)a2 << 7);
v5 = a2 << 8 >> v3;
v6 = 65280 >> v3;
if ( (a1 & 0x1F00) == 7936 )
{
v13 = (unsigned __int8)v6;
LOWORD(v6) = v6 & 0xFF00;
if ( (starfire_vidctrl1 & 0x10) != 0 )
LOWORD(v6) = v13;
}
v7 = (_BYTE *)(starfire_videoram + (a1 & 0x1FFF));
result = (a1 + 256) & 0x1FFF;
v8 = *(unsigned __int8 *)(starfire_videoram + result) | ((unsigned __int8)*v7 << 8);
v9 = v8 & ~(_WORD)v6;
v10 = v8 & v6;
v11 = v5 & v6;
v12 = starfire_vidctrl1;
switch ( ~starfire_vidctrl1 & 0xF )
{
case 0:
v9 |= v6 ^ v11;
break;
case 1:
v9 |= v6 & ~(v8 | v5);
break;
case 2:
v9 |= (v6 ^ v11) & v10;
break;
case 3:
break;
case 4:
v9 |= v6 ^ v10 & v11;
break;
case 5:
v9 |= v6 ^ v10;
break;
case 6:
v9 |= v6 & (v8 ^ v5);
break;
case 7:
v9 |= (v6 ^ v10) & v11;
break;
case 8:
v9 |= v10 | v6 ^ v11;
break;
case 9:
v9 |= v6 & ~(v8 ^ v5);
break;
case 0xA:
v9 = *(unsigned __int8 *)(starfire_videoram + ((a1 + 256) & 0x1FFF)) | ((unsigned __int8)*v7 << 8);
break;
case 0xB:
v9 |= v10 & v11;
break;
case 0xC:
v9 = v6 | v8;
break;
case 0xD:
v9 |= v11 | v6 ^ v10;
break;
case 0xE:
v9 |= v6 & (v8 | v5);
break;
case 0xF:
v9 |= v11;
break;
}
*v7 = HIBYTE(v9);
*(_BYTE *)(starfire_videoram + ((a1 + 256) & 0x1FFF)) = v9;
*((_BYTE *)scanline_dirty + (unsigned __int8)a1) = 1;
if ( (a1 & 0x2000) == 0 && v12 >= 0 )
{
if ( BYTE1(v6) )
*(_BYTE *)(starfire_colorram + (a1 & 0x1FFF)) = starfire_color;
if ( (_BYTE)v6 )
*(_BYTE *)(starfire_colorram + ((a1 + 256) & 0x1FFF)) = starfire_color;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1, int a2)
{
__int64 result; // rax
char v3; // cl
int v4; // er10
int v5; // esi
int v6; // ecx
_BYTE *v7; // rbp
__int16 v8; // r9
__int16 v9; // bx
__int16 v10; // r14
__int16 v11; // r13
char v12; // r12
__int16 v13; // r9

result = (a1 + 256) & 0x1FFF;
if ( (a1 & 0xE0) != 0 || (starfire_vidctrl1 & 0x20) != 0 )
{
if ( (a1 & 0x2000) != 0 )
{
v3 = ((unsigned __int8)starfire_vidctrl >> 1) & 7;
v4 = starfire_vidctrl & 1;
}
else
{
v3 = (unsigned __int8)starfire_vidctrl >> 5;
v4 = (starfire_vidctrl & 0x10) != 0;
}
if ( v4 )
a2 = (a2 >> 7) & 1 | (a2 >> 5) & 2 | (a2 >> 3) & 4 | (a2 >> 1) & 8 | (2 * (_BYTE)a2) & 0x10 | (8 * (_BYTE)a2) & 0x20 | (32 * (_BYTE)a2) & 0x40 | (unsigned __int8)((_BYTE)a2 << 7);
v5 = a2 << 8 >> v3;
v6 = 65280 >> v3;
if ( (a1 & 0x1F00) == 7936 )
{
v13 = (unsigned __int8)v6;
LOWORD(v6) = v6 & 0xFF00;
if ( (starfire_vidctrl1 & 0x10) != 0 )
LOWORD(v6) = v13;
}
v7 = (_BYTE *)(starfire_videoram + (a1 & 0x1FFF));
result = (a1 + 256) & 0x1FFF;
v8 = *(unsigned __int8 *)(starfire_videoram + result) | ((unsigned __int8)*v7 << 8);
v9 = v8 & ~(_WORD)v6;
v10 = v8 & v6;
v11 = v5 & v6;
v12 = starfire_vidctrl1;
switch ( ~starfire_vidctrl1 & 0xF )
{
case 0:
v9 |= v6 ^ v11;
break;
case 1:
v9 |= v6 & ~(v8 | v5);
break;
case 2:
v9 |= (v6 ^ v11) & v10;
break;
case 3:
break;
case 4:
v9 |= v6 ^ v10 & v11;
break;
case 5:
v9 |= v6 ^ v10;
break;
case 6:
v9 |= v6 & (v8 ^ v5);
break;
case 7:
v9 |= (v6 ^ v10) & v11;
break;
case 8:
v9 |= v10 | v6 ^ v11;
break;
case 9:
v9 |= v6 & ~(v8 ^ v5);
break;
case 0xA:
v9 = *(unsigned __int8 *)(starfire_videoram + ((a1 + 256) & 0x1FFF)) | ((unsigned __int8)*v7 << 8);
break;
case 0xB:
v9 |= v10 & v11;
break;
case 0xC:
v9 = v6 | v8;
break;
case 0xD:
v9 |= v11 | v6 ^ v10;
break;
case 0xE:
v9 |= v6 & (v8 | v5);
break;
case 0xF:
v9 |= v11;
break;
}
*v7 = HIBYTE(v9);
*(_BYTE *)(starfire_videoram + ((a1 + 256) & 0x1FFF)) = v9;
*((_BYTE *)scanline_dirty + (unsigned __int8)a1) = 1;
if ( (a1 & 0x2000) == 0 && v12 >= 0 )
{
if ( BYTE1(v6) )
*(_BYTE *)(starfire_colorram + (a1 & 0x1FFF)) = starfire_color;
if ( (_BYTE)v6 )
*(_BYTE *)(starfire_colorram + ((a1 + 256) & 0x1FFF)) = starfire_color;
}
}
return result;
}

original_code:
void starfire_videoram_w(offs_t offset,data_t data)
{
 int sh, lr, dm, ds, mask, d0, dalu;
 int offset1 = offset & 0x1fff;
 int offset2 = (offset + 0x100) & 0x1fff;
 if (!(offset & 0xe0) && !(starfire_vidctrl1 & 0x20))
  return;
 if (offset & 0x2000)
 {
  sh = (starfire_vidctrl >> 1) & 0x07;
  lr = starfire_vidctrl & 0x01;
 }
 else
 {
  sh = (starfire_vidctrl >> 5) & 0x07;
  lr = (starfire_vidctrl >> 4) & 0x01;
 }
 dm = data;
 if (lr)
  dm = ((dm & 0x01) << 7) | ((dm & 0x02) << 5) | ((dm & 0x04) << 3) | ((dm & 0x08) << 1) |
       ((dm & 0x10) >> 1) | ((dm & 0x20) >> 3) | ((dm & 0x40) >> 5) | ((dm & 0x80) >> 7);
 ds = (dm << 8) >> sh;
 mask = 0xff00 >> sh;
 if ((offset & 0x1f00) == 0x1f00)
 {
  if (starfire_vidctrl1 & 0x10)
   mask &= 0x00ff;
  else
   mask &= 0xff00;
 }
 d0 = (starfire_videoram[offset1] << 8) | starfire_videoram[offset2];
 dalu = d0 & ~mask;
 d0 &= mask;
 ds &= mask;
 switch (~starfire_vidctrl1 & 15)
 {
  case 0: dalu |= ds ^ mask; break;
  case 1: dalu |= (ds | d0) ^ mask; break;
  case 2: dalu |= (ds ^ mask) & d0; break;
  case 3: dalu |= 0; break;
  case 4: dalu |= (ds & d0) ^ mask; break;
  case 5: dalu |= d0 ^ mask; break;
  case 6: dalu |= ds ^ d0; break;
  case 7: dalu |= ds & (d0 ^ mask); break;
  case 8: dalu |= (ds ^ mask) | d0; break;
  case 9: dalu |= (ds ^ d0) ^ mask; break;
  case 10: dalu |= d0; break;
  case 11: dalu |= ds & d0; break;
  case 12: dalu |= mask; break;
  case 13: dalu |= ds | (d0 ^ mask); break;
  case 14: dalu |= ds | d0; break;
  case 15: dalu |= ds; break;
 }
 starfire_videoram[offset1] = dalu >> 8;
 starfire_videoram[offset2] = dalu;
 scanline_dirty[offset1 & 0xff] = 1;
 if (!(offset & 0x2000) && !(starfire_vidctrl1 & 0x80))
 {
  if (mask & 0xff00)
   starfire_colorram[offset1] = starfire_color;
  if (mask & 0x00ff)
   starfire_colorram[offset2] = starfire_color;
 }
}

canonical_original_code:
void starfire_videoram_w(unsigned int offset, unsigned int data)
{
 int sh; int lr; int dm; int ds; int mask; int d0; int dalu;
 int offset1 = offset & 0x1fff;
 int offset2 = (offset + 0x100) & 0x1fff;
 if (!(offset & 0xe0) && !(starfire_vidctrl1 & 0x20))
  return;
 if (offset & 0x2000)
 {
  sh = (starfire_vidctrl >> 1) & 0x07;
  lr = starfire_vidctrl & 0x01;
 }
 else
 {
  sh = (starfire_vidctrl >> 5) & 0x07;
  lr = (starfire_vidctrl >> 4) & 0x01;
 }
 dm = data;
 if (lr)
  dm = ((dm & 0x01) << 7) | ((dm & 0x02) << 5) | ((dm & 0x04) << 3) | ((dm & 0x08) << 1) |
       ((dm & 0x10) >> 1) | ((dm & 0x20) >> 3) | ((dm & 0x40) >> 5) | ((dm & 0x80) >> 7);
 ds = (dm << 8) >> sh;
 mask = 0xff00 >> sh;
 if ((offset & 0x1f00) == 0x1f00)
 {
  if (starfire_vidctrl1 & 0x10)
   mask &= 0x00ff;
  else
   mask &= 0xff00;
 }
 d0 = (starfire_videoram[offset1] << 8) | starfire_videoram[offset2];
 dalu = d0 & ~mask;
 d0 &= mask;
 ds &= mask;
 switch (~starfire_vidctrl1 & 15)
 {
  case 0: dalu |= ds ^ mask; break;
  case 1: dalu |= (ds | d0) ^ mask; break;
  case 2: dalu |= (ds ^ mask) & d0; break;
  case 3: dalu |= 0; break;
  case 4: dalu |= (ds & d0) ^ mask; break;
  case 5: dalu |= d0 ^ mask; break;
  case 6: dalu |= ds ^ d0; break;
  case 7: dalu |= ds & (d0 ^ mask); break;
  case 8: dalu |= (ds ^ mask) | d0; break;
  case 9: dalu |= (ds ^ d0) ^ mask; break;
  case 10: dalu |= d0; break;
  case 11: dalu |= ds & d0; break;
  case 12: dalu |= mask; break;
  case 13: dalu |= ds | (d0 ^ mask); break;
  case 14: dalu |= ds | d0; break;
  case 15: dalu |= ds; break;
 }
 starfire_videoram[offset1] = dalu >> 8;
 starfire_videoram[offset2] = dalu;
 scanline_dirty[offset1 & 0xff] = 1;
 if (!(offset & 0x2000) && !(starfire_vidctrl1 & 0x80))
 {
  if (mask & 0xff00)
   starfire_colorram[offset1] = starfire_color;
  if (mask & 0x00ff)
   starfire_colorram[offset2] = starfire_color;
 }
}

variable_types: sh int

variable_types: lr int

variable_types: dm int

variable_types: ds int

variable_types: mask int

variable_types: dalu int


decompiled_code:
__int64 __fastcall starfire_videoram_r(__int16 a1)
{
char v1; // dl
int v2; // ecx
int v3; // eax

if ( (a1 & 0x2000) != 0 )
v1 = ((unsigned __int8)starfire_vidctrl >> 1) & 7;
else
v1 = (unsigned __int8)starfire_vidctrl >> 5;
v2 = 65280 >> v1;
if ( (a1 & 0x1F00) == 7936 )
{
v2 = (65280 >> v1) & 0xFF00;
if ( (starfire_vidctrl1 & 0x10) != 0 )
v2 = (unsigned __int8)(65280 >> v1);
}
v3 = (unsigned __int8)(*(_BYTE *)(starfire_videoram + ((a1 + 256) & 0x1FFF)) & v2) | (v2 >> 8) & *(unsigned __int8 *)(starfire_videoram + (a1 & 0x1FFF));
return (unsigned __int8)(((_BYTE)v3 << v1) | (v3 >> (8 - v1)));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
char v1; // dl
int v2; // ecx
int v3; // eax

if ( (a1 & 0x2000) != 0 )
v1 = ((unsigned __int8)starfire_vidctrl >> 1) & 7;
else
v1 = (unsigned __int8)starfire_vidctrl >> 5;
v2 = 65280 >> v1;
if ( (a1 & 0x1F00) == 7936 )
{
v2 = (65280 >> v1) & 0xFF00;
if ( (starfire_vidctrl1 & 0x10) != 0 )
v2 = (unsigned __int8)(65280 >> v1);
}
v3 = (unsigned __int8)(*(_BYTE *)(starfire_videoram + ((a1 + 256) & 0x1FFF)) & v2) | (v2 >> 8) & *(unsigned __int8 *)(starfire_videoram + (a1 & 0x1FFF));
return (unsigned __int8)(((_BYTE)v3 << v1) | (v3 >> (8 - v1)));
}

original_code:
data_t starfire_videoram_r(offs_t offset)
{
 int sh, mask, d0;
 int offset1 = offset & 0x1fff;
 int offset2 = (offset + 0x100) & 0x1fff;
 if (offset & 0x2000)
  sh = (starfire_vidctrl >> 1) & 0x07;
 else
  sh = (starfire_vidctrl >> 5) & 0x07;
 mask = 0xff00 >> sh;
 if ((offset & 0x1f00) == 0x1f00)
 {
  if (starfire_vidctrl1 & 0x10)
   mask &= 0x00ff;
  else
   mask &= 0xff00;
 }
 d0 = (starfire_videoram[offset1] & (mask >> 8)) | (starfire_videoram[offset2] & mask);
 d0 = (d0 << sh) | (d0 >> (8 - sh));
 return d0 & 0xff;
}

canonical_original_code:
unsigned int starfire_videoram_r(unsigned int offset)
{
 int sh; int mask; int d0;
 int offset1 = offset & 0x1fff;
 int offset2 = (offset + 0x100) & 0x1fff;
 if (offset & 0x2000)
  sh = (starfire_vidctrl >> 1) & 0x07;
 else
  sh = (starfire_vidctrl >> 5) & 0x07;
 mask = 0xff00 >> sh;
 if ((offset & 0x1f00) == 0x1f00)
 {
  if (starfire_vidctrl1 & 0x10)
   mask &= 0x00ff;
  else
   mask &= 0xff00;
 }
 d0 = (starfire_videoram[offset1] & (mask >> 8)) | (starfire_videoram[offset2] & mask);
 d0 = (d0 << sh) | (d0 >> (8 - sh));
 return d0 & 0xff;
}


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

if ( (a1 & 0x800) != 0 )
result = input_read();
else
result = *(unsigned __int8 *)(starfire_videoram + (a1 & 0x31F | (32 * a1) & 0x1C00u));
return result;
}

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

if ( (a1 & 0x800) != 0 )
result = input_read();
else
result = *(unsigned __int8 *)(starfire_videoram + (a1 & 0x31F | (32 * a1) & 0x1C00u));
return result;
}

original_code:
static data_t starfire_scratch_r(offs_t offset)
{
 if (offset & 0x800)
  return (*input_read)(offset);
 offset = (offset & 0x31f) | ((offset & 0xe0) << 5);
    return starfire_videoram[offset];
}

canonical_original_code:
static unsigned int starfire_scratch_r(unsigned int offset)
{
 if (offset & 0x800)
  return (*input_read)(offset);
 offset = (offset & 0x31f) | ((offset & 0xe0) << 5);
    return starfire_videoram[offset];
}


original_code:
int starfire_vh_start(void)
{
 tmpbitmap = bitmap_alloc(Machine->drv->screen_width, Machine->drv->screen_height);
 if (!tmpbitmap)
  return 1;
 scanline_dirty = (unsigned char*)malloc(256);
 if (!scanline_dirty)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 memset(starfire_videoram, 0, 0x2000);
 memset(starfire_colorram, 0, 0x2000);
 memset(scanline_dirty, 1, 256);
 return 0;
}

canonical_original_code:
int starfire_vh_start()
{
 tmpbitmap = bitmap_alloc(Machine->drv->screen_width, Machine->drv->screen_height);
 if (!tmpbitmap)
  return 1;
 scanline_dirty = (unsigned char *)malloc(256);
 if (!scanline_dirty)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 memset(starfire_videoram, 0, 0x2000);
 memset(starfire_colorram, 0, 0x2000);
 memset(scanline_dirty, 1, 256);
 return 0;
}

return_type: int


decompiled_code:
void starfire_vh_stop()
{
bitmap_free(tmpbitmap);
free(scanline_dirty);
}

canonical_decompiled_code:
void func5()
{
bitmap_free(tmpbitmap);
free(scanline_dirty);
}

original_code:
void starfire_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 free(scanline_dirty);
}


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

if ( (a1 & 0xE0) != 0 )
{
v4 = starfire_color;
if ( starfire_vidctrl1 >= 0 )
v4 = a2 & 0x1F;
*((_BYTE *)starfire_colorram + a1) = v4;
result = (__int64)scanline_dirty;
*((_BYTE *)scanline_dirty + (unsigned __int8)a1) = 1;
starfire_color = a2 & 0x1F;
}
else
{
*((_BYTE *)starfire_colorram + (a1 & 0xFFFFFEFF)) = a2;
*((_BYTE *)starfire_colorram + (a1 | 0x100)) = a2;
result = a2 & 0x1F;
starfire_color = a2 & 0x1F;
if ( (starfire_vidctrl1 & 0x40) != 0 )
{
v3 = (a1 >> 8) & 1 | (2 * (_BYTE)a2) & 6;
result = palette_change_color(
(a1 >> 4) & 0x20 | a1 & 0x1F,
(4 * v3) | (32 * v3) | (unsigned int)(v3 >> 1),
((unsigned __int8)a2 >> 5 >> 1) | (4 * ((unsigned __int8)a2 >> 5)) | (32
* (unsigned int)((unsigned __int8)a2 >> 5)),
(4 * ((a2 >> 2) & 7)) | (32 * ((a2 >> 2) & 7)) | ((int)((a2 >> 2) & 7) >> 1));
}
}
return result;
}

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

if ( (a1 & 0xE0) != 0 )
{
v4 = starfire_color;
if ( starfire_vidctrl1 >= 0 )
v4 = a2 & 0x1F;
*((_BYTE *)starfire_colorram + a1) = v4;
result = (__int64)scanline_dirty;
*((_BYTE *)scanline_dirty + (unsigned __int8)a1) = 1;
starfire_color = a2 & 0x1F;
}
else
{
*((_BYTE *)starfire_colorram + (a1 & 0xFFFFFEFF)) = a2;
*((_BYTE *)starfire_colorram + (a1 | 0x100)) = a2;
result = a2 & 0x1F;
starfire_color = a2 & 0x1F;
if ( (starfire_vidctrl1 & 0x40) != 0 )
{
v3 = (a1 >> 8) & 1 | (2 * (_BYTE)a2) & 6;
result = palette_change_color(
(a1 >> 4) & 0x20 | a1 & 0x1F,
(4 * v3) | (32 * v3) | (unsigned int)(v3 >> 1),
((unsigned __int8)a2 >> 5 >> 1) | (4 * ((unsigned __int8)a2 >> 5)) | (32
* (unsigned int)((unsigned __int8)a2 >> 5)),
(4 * ((a2 >> 2) & 7)) | (32 * ((a2 >> 2) & 7)) | ((int)((a2 >> 2) & 7) >> 1));
}
}
return result;
}

original_code:
void starfire_colorram_w(offs_t offset,data_t data)
{
 if ((offset & 0xe0) == 0)
 {
  int palette_index = (offset & 0x1f) | ((offset & 0x200) >> 4);
  int r = ((data << 1) & 0x06) | ((offset >> 8) & 0x01);
  int b = (data >> 2) & 0x07;
  int g = (data >> 5) & 0x07;
  starfire_colorram[offset & ~0x100] = data;
  starfire_colorram[offset | 0x100] = data;
  starfire_color = data & 0x1f;
  if (!(starfire_vidctrl1 & 0x40))
   return;
  r = (r << 5) | (r << 2) | (r >> 1);
  b = (b << 5) | (b << 2) | (b >> 1);
  g = (g << 5) | (g << 2) | (g >> 1);
  palette_change_color(palette_index, r, g, b);
 }
 else
 {
  starfire_colorram[offset] = (starfire_vidctrl1 & 0x80) ? starfire_color : (data & 0x1f);
  scanline_dirty[offset & 0xff] = 1;
  starfire_color = data & 0x1f;
 }
}

canonical_original_code:
void starfire_colorram_w(unsigned int offset, unsigned int data)
{
 if ((offset & 0xe0) == 0)
 {
  int palette_index = (offset & 0x1f) | ((offset & 0x200) >> 4);
  int r = ((data << 1) & 0x06) | ((offset >> 8) & 0x01);
  int b = (data >> 2) & 0x07;
  int g = (data >> 5) & 0x07;
  starfire_colorram[offset & ~0x100] = data;
  starfire_colorram[offset | 0x100] = data;
  starfire_color = data & 0x1f;
  if (!(starfire_vidctrl1 & 0x40))
   return;
  r = (r << 5) | (r << 2) | (r >> 1);
  b = (b << 5) | (b << 2) | (b >> 1);
  g = (g << 5) | (g << 2) | (g >> 1);
  palette_change_color(palette_index, r, g, b);
 }
 else
 {
  starfire_colorram[offset] = (starfire_vidctrl1 & 0x80) ? starfire_color : (data & 0x1f);
  scanline_dirty[offset & 0xff] = 1;
  starfire_color = data & 0x1f;
 }
}

variable_types: r int

variable_types: b int

variable_types: g int


decompiled_code:
__int64 __fastcall starfire_vh_screenrefresh(__int64 a1)
{
palette_recalc();
return copybitmap_remap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
palette_recalc();
return copybitmap_remap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void starfire_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 palette_recalc();
 copybitmap_remap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->visible_area, TRANSPARENCY_NONE, 0);
}

canonical_original_code:
void starfire_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 palette_recalc();
 copybitmap_remap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->visible_area, TRANSPARENCY_NONE, 0);
}

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


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

switch ( a1 & 0xF )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
result = input_port_1_r(0LL);
break;
case 2:
case 3:
case 4:
result = 255LL;
break;
case 5:
result = input_port_4_r(0LL);
break;
case 6:
result = input_port_2_r(0LL);
break;
case 7:
result = input_port_3_r(0LL);
break;
default:
result = 255LL;
break;
}
return result;
}

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

switch ( a1 & 0xF )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
result = input_port_1_r(0LL);
break;
case 2:
case 3:
case 4:
result = 255LL;
break;
case 5:
result = input_port_4_r(0LL);
break;
case 6:
result = input_port_2_r(0LL);
break;
case 7:
result = input_port_3_r(0LL);
break;
default:
result = 255LL;
break;
}
return result;
}

original_code:
static data_t starfire_input_r(offs_t offset)
{
 switch (offset & 15)
 {
  case 0: return input_port_0_r(0);
  case 1: return input_port_1_r(0);
  case 5: return input_port_4_r(0);
  case 6: return input_port_2_r(0);
  case 7: return input_port_3_r(0);
  default: return 0xff;
 }
}

canonical_original_code:
static unsigned int starfire_input_r(unsigned int offset)
{
 switch (offset & 15)
 {
  case 0: return input_port_0_r(0);
  case 1: return input_port_1_r(0);
  case 5: return input_port_4_r(0);
  case 6: return input_port_2_r(0);
  case 7: return input_port_3_r(0);
  default: return 0xff;
 }
}


decompiled_code:
__int64 __fastcall fireone_input_r(char a1)
{
__int64 v1; // rdi
__int64 result; // rax
char v3; // dl

v1 = a1 & 0xF;
if ( (_DWORD)v1 == 1 )
return input_port_1_r(0LL);
if ( (_DWORD)v1 == 2 )
{
if ( fireone_select )
v3 = input_port_2_r(0LL);
else
v3 = input_port_3_r(0LL);
result = v3 & 0xC0 | (unsigned int)fireone_paddle_map_0[v3 & 0x3F];
}
else
{
result = 255LL;
if ( !(_DWORD)v1 )
result = input_port_0_r(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
__int64 v1; // rdi
__int64 result; // rax
char v3; // dl

v1 = a1 & 0xF;
if ( (_DWORD)v1 == 1 )
return input_port_1_r(0LL);
if ( (_DWORD)v1 == 2 )
{
if ( fireone_select )
v3 = input_port_2_r(0LL);
else
v3 = input_port_3_r(0LL);
result = v3 & 0xC0 | (unsigned int)fireone_paddle_map_0[v3 & 0x3F];
}
else
{
result = 255LL;
if ( !(_DWORD)v1 )
result = input_port_0_r(v1);
}
return result;
}

canonical_original_code:
static unsigned int fireone_input_r(unsigned int offset)
{
 static unsigned char fireone_paddle_map[64] = {
  0x00,0x01,0x03,0x02,0x06,0x07,0x05,0x04,
  0x0c,0x0d,0x0f,0x0e,0x0a,0x0b,0x09,0x08,
  0x18,0x19,0x1b,0x1a,0x1e,0x1f,0x1d,0x1c,
  0x14,0x15,0x17,0x16,0x12,0x13,0x11,0x10,
  0x30,0x31,0x33,0x32,0x36,0x37,0x35,0x34,
  0x3c,0x3d,0x3f,0x3e,0x3a,0x3b,0x39,0x38,
  0x28,0x29,0x2b,0x2a,0x2e,0x2f,0x2d,0x2c,
  0x24,0x25,0x27,0x26,0x22,0x23,0x21,0x20
 };
 int temp;
 switch (offset & 15)
 {
  case 0: return input_port_0_r(0);
  case 1: return input_port_1_r(0);
  case 2:
   temp = fireone_select ? input_port_2_r(0) : input_port_3_r(0);
   temp = (temp & 0xc0) | fireone_paddle_map[temp & 0x3f];
   return temp;
  default: return 0xff;
 }
}

variable_types: temp int


decompiled_code:
void __fastcall starfire_vidctrl_w(__int64 a1, char a2)
{
starfire_vidctrl = a2;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, char a2)
{
starfire_vidctrl = a2;
}

original_code:
void starfire_vidctrl_w(offs_t offset,data_t data)
{
    starfire_vidctrl = data;
}

canonical_original_code:
void starfire_vidctrl_w(unsigned int offset, unsigned int data)
{
    starfire_vidctrl = data;
}


decompiled_code:
void __fastcall starfire_vidctrl1_w(__int64 a1, char a2)
{
starfire_vidctrl1 = a2;
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, char a2)
{
starfire_vidctrl1 = a2;
}

original_code:
void starfire_vidctrl1_w(offs_t offset,data_t data)
{
    starfire_vidctrl1 = data;
}

canonical_original_code:
void starfire_vidctrl1_w(unsigned int offset, unsigned int data)
{
    starfire_vidctrl1 = data;
}


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

starfire_video_update(a1, 8);
v1 = a1 + 8;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) <= a1 + 8 )
v1 = 32;
v2 = cpu_getscanlinetime(v1 + 7);
return timer_set(v2, v1, update_callback);
}

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

func13(a1, 8);
v1 = a1 + 8;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) <= a1 + 8 )
v1 = 32;
v2 = cpu_getscanlinetime(v1 + 7);
return timer_set(v2, v1, update_callback);
}

original_code:
static void update_callback(int scanline)
{
 starfire_video_update(scanline, 8);
 scanline += 8;
 if (scanline >= Machine->drv->screen_height)
  scanline = 32;
 timer_set(cpu_getscanlinetime(scanline + 8 - 1), scanline, update_callback);
}

variable_types: scanline int


decompiled_code:
__int64 init_machine()
{
unsigned int v0; // eax

v0 = cpu_getscanlinetime(39LL);
return timer_set(v0, 32LL, update_callback);
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // eax

v0 = cpu_getscanlinetime(39LL);
return timer_set(v0, 32LL, update_callback);
}

original_code:
static void init_machine(void)
{
 timer_set(cpu_getscanlinetime(32 + 8 - 1), 32, update_callback);
}

canonical_original_code:
static void init_machine()
{
 timer_set(cpu_getscanlinetime(32 + 8 - 1), 32, update_callback);
}


decompiled_code:
void __fastcall blockade_coin_latch_w(__int64 a1, char a2)
{
if ( a2 < 0 )
{
if ( just_been_reset )
{
just_been_reset = 0;
coin_latch = 0;
}
else
{
coin_latch = 1;
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
if ( a2 < 0 )
{
if ( just_been_reset )
{
just_been_reset = 0;
coin_latch = 0;
}
else
{
coin_latch = 1;
}
}
}

original_code:
void blockade_coin_latch_w(offs_t offset,data_t data)
{
    if (data & 0x80)
    {
        if (just_been_reset)
        {
            just_been_reset = 0;
            coin_latch = 0;
        }
        else
            coin_latch = 1;
    }
    if (data & 0x20)
    {
    }
    else
    {
    }
    return;
}

canonical_original_code:
void blockade_coin_latch_w(unsigned int offset, unsigned int data)
{
    if (data & 0x80)
    {
        if (just_been_reset)
        {
            just_been_reset = 0;
            coin_latch = 0;
        }
        else
            coin_latch = 1;
    }
    if (data & 0x20)
    {
    }
    else
    {
    }
    return;
}


decompiled_code:
void blockade_env_off_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void blockade_env_off_w(offs_t offset,data_t data)
{
    return;
}

canonical_original_code:
void blockade_env_off_w(unsigned int offset, unsigned int data)
{
    return;
}


decompiled_code:
void __fastcall init_palette_gr(__int64 a1)
{
*(_DWORD *)a1 = 0;
*(_WORD *)(a1 + 4) = 255;
}

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

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


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

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


decompiled_code:
_BYTE *init_blockade()
{
_BYTE *result; // rax
_BYTE *v1; // rcx

result = (_BYTE *)memory_region(129LL);
v1 = result + 1024;
do
{
*result = result[5120] + 16 * result[4096];
++result;
}
while ( result != v1 );
coin_latch = 1;
just_been_reset = 0;
return result;
}

canonical_decompiled_code:
_BYTE *func5()
{
_BYTE *result; // rax
_BYTE *v1; // rcx

result = (_BYTE *)memory_region(129LL);
v1 = result + 1024;
do
{
*result = result[5120] + 16 * result[4096];
++result;
}
while ( result != v1 );
coin_latch = 1;
just_been_reset = 0;
return result;
}

original_code:
void init_blockade(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for (i = 0;i < 0x0400;i++)
 {
  rom[0x0000+i] = (rom[0x1000+i]<<4)+rom[0x1400+i];
 }
 coin_latch = 1;
 just_been_reset = 0;
}

canonical_original_code:
void init_blockade()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for (i = 0;i < 0x0400;i++)
 {
  rom[0x0000+i] = (rom[0x1000+i]<<4)+rom[0x1400+i];
 }
 coin_latch = 1;
 just_been_reset = 0;
}

variable_types:
rom
unsigned char *

variable_types: i int


decompiled_code:
__int64 init_comotion()
{
unsigned __int8 *v0; // rax
unsigned __int8 *v1; // rcx
unsigned __int8 *v2; // rsi
unsigned __int8 *v3; // rdx
__int64 result; // rax

v0 = (unsigned __int8 *)memory_region(129LL);
v1 = v0;
v2 = v0 + 1024;
do
{
*v0 = v0[5120] + 16 * v0[4096];
v0[1024] = v0[7168] + 16 * v0[6144];
++v0;
}
while ( v0 != v2 );
v3 = v1 + 2048;
do
{
result = *v1;
v1[0x4000] = result;
++v1;
}
while ( v1 != v3 );
coin_latch = 1;
just_been_reset = 0;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned __int8 *v0; // rax
unsigned __int8 *v1; // rcx
unsigned __int8 *v2; // rsi
unsigned __int8 *v3; // rdx
__int64 result; // rax

v0 = (unsigned __int8 *)memory_region(129LL);
v1 = v0;
v2 = v0 + 1024;
do
{
*v0 = v0[5120] + 16 * v0[4096];
v0[1024] = v0[7168] + 16 * v0[6144];
++v0;
}
while ( v0 != v2 );
v3 = v1 + 2048;
do
{
result = *v1;
v1[0x4000] = result;
++v1;
}
while ( v1 != v3 );
coin_latch = 1;
just_been_reset = 0;
return result;
}

original_code:
void init_comotion(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for(i = 0;i < 0x0400;i++)
 {
  rom[0x0000+i] = (rom[0x1000+i]<<4)+rom[0x1400+i];
  rom[0x0400+i] = (rom[0x1800+i]<<4)+rom[0x1c00+i];
 }
 for(i = 0;i < 2048;i++)
 {
  rom[0x4000+i] = rom[0x0000+i];
 }
 coin_latch = 1;
 just_been_reset = 0;
}


decompiled_code:
__int64 blockade_input_port_0_r()
{
return input_port_0_r(0LL) & 0x7F | (unsigned int)(coin_latch << 7);
}

canonical_decompiled_code:
__int64 func7()
{
return input_port_0_r(0LL) & 0x7F | (unsigned int)(coin_latch << 7);
}

original_code:
data_t blockade_input_port_0_r(offs_t offset)
{
    int temp = (input_port_0_r(0)&0x7f);
    return (coin_latch<<7) | (temp);
}

canonical_original_code:
unsigned int blockade_input_port_0_r(unsigned int offset)
{
    int temp = (input_port_0_r(0)&0x7f);
    return (coin_latch<<7) | (temp);
}


decompiled_code:
__int64 blockade_interrupt()
{
timer_suspendcpu(0LL, 0LL, 0xFFFFFFFFLL);
if ( (input_port_0_r(0LL) & 0x80u) == 0LL )
{
just_been_reset = 1;
cpu_set_reset_line(0LL, 3LL);
}
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func8()
{
timer_suspendcpu(0LL, 0LL, 0xFFFFFFFFLL);
if ( (input_port_0_r(0LL) & 0x80u) == 0LL )
{
just_been_reset = 1;
cpu_set_reset_line(0LL, 3LL);
}
return ignore_interrupt();
}

original_code:
int blockade_interrupt(void)
{
 timer_suspendcpu(0, 0, ((UINT32)-1));
 if ((input_port_0_r(0) & 0x80) == 0)
 {
  just_been_reset = 1;
  cpu_set_reset_line(0,3);
 }
 return ignore_interrupt();
}

canonical_original_code:
int blockade_interrupt()
{
 timer_suspendcpu(0, 0, ((UINT32)-1));
 if ((input_port_0_r(0) & 0x80) == 0)
 {
  just_been_reset = 1;
  cpu_set_reset_line(0,3);
 }
 return ignore_interrupt();
}


decompiled_code:
__int64 blockade_env_on_w()
{
return sample_start(0LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return sample_start(0LL, 0LL, 0LL);
}

original_code:
void blockade_env_on_w(offs_t offset,data_t data)
{
    sample_start(0,0,0);
    return;
}

canonical_original_code:
void blockade_env_on_w(unsigned int offset, unsigned int data)
{
    sample_start(0,0,0);
    return;
}


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

videoram_w();
result = input_port_3_r(0LL);
if ( (result & 0x80u) != 0LL )
result = cpu_spinuntil_int();
return result;
}

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

videoram_w();
result = input_port_3_r(0LL);
if ( (result & 0x80u) != 0LL )
result = cpu_spinuntil_int();
return result;
}

original_code:
static void blockade_videoram_w(offs_t offset,data_t data)
{
 videoram_w(offset, data);
 if (input_port_3_r(0) & 0x80)
 {
  cpu_spinuntil_int();
 }
}

canonical_original_code:
static void blockade_videoram_w(unsigned int offset, unsigned int data)
{
 videoram_w(offset, data);
 if (input_port_3_r(0) & 0x80)
 {
  cpu_spinuntil_int();
 }
}


original_code:
void ironhors_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}

canonical_original_code:
void ironhors_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: j int


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

result = (void *)(a2 & 1);
if ( (_DWORD)result != charbank )
{
charbank = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
spriterambank = a2 & 8;
return result;
}

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

result = (void *)(a2 & 1);
if ( (_DWORD)result != charbank )
{
charbank = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
spriterambank = a2 & 8;
return result;
}

original_code:
void ironhors_charbank_w(offs_t offset,data_t data)
{
 if (charbank != (data & 1))
 {
  charbank = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 spriterambank = data & 8;
}

canonical_original_code:
void ironhors_charbank_w(unsigned int offset, unsigned int data)
{
 if (charbank != (data & 1))
 {
  charbank = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 spriterambank = data & 8;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

result = (void *)(a2 & 7);
if ( (_DWORD)result != palettebank )
{
palettebank = a2 & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = (void *)(a2 & 7);
if ( (_DWORD)result != palettebank )
{
palettebank = a2 & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

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


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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) != 0 && (*(_BYTE *)ironhors_interrupt_enable & 1) != 0 )
return nmi_interrupt();
}
else
{
result = 2LL;
if ( (*(_BYTE *)ironhors_interrupt_enable & 4) != 0 )
return result;
}
return ignore_interrupt();
}

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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) != 0 && (*(_BYTE *)ironhors_interrupt_enable & 1) != 0 )
return nmi_interrupt();
}
else
{
result = 2LL;
if ( (*(_BYTE *)ironhors_interrupt_enable & 4) != 0 )
return result;
}
return ignore_interrupt();
}

original_code:
static int ironhors_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (*ironhors_interrupt_enable & 4) return 2;
 }
 else if (cpu_getiloops() % 2)
 {
  if (*ironhors_interrupt_enable & 1) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int ironhors_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (*ironhors_interrupt_enable & 4) return 2;
 }
 else if (cpu_getiloops() % 2)
 {
  if (*ironhors_interrupt_enable & 1) return nmi_interrupt();
 }
 return ignore_interrupt();
}


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

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

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

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


decompiled_code:
__int64 blockhl_vh_start()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_344 = 16;
dword_348 = 32;
sprite_colorbase = 48;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx
__int64 result; // rax

layer_colorbase[0] = 0;
dword_344 = 16;
dword_348 = 32;
sprite_colorbase = 48;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int blockhl_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 16;
 layer_colorbase[2] = 32;
 sprite_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int blockhl_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 16;
 layer_colorbase[2] = 32;
 sprite_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 blockhl_vh_stop()
{
K052109_vh_stop();
return K051960_vh_stop();
}

original_code:
void blockhl_vh_stop(void)
{
 K052109_vh_stop();
 K051960_vh_stop();
}

canonical_original_code:
void blockhl_vh_stop()
{
 K052109_vh_stop();
 K051960_vh_stop();
}


decompiled_code:
__int64 __fastcall blockhl_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K052109_tilemap_draw(a1, 2LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K052109_tilemap_draw(a1, 2LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

original_code:
void blockhl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 K052109_tilemap_draw(bitmap,2,0x10);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,1,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,0,0);
}

canonical_original_code:
void blockhl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 K052109_tilemap_draw(bitmap,2,0x10);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,1,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,0,0);
}

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 blockhl_init_machine()
{
__int64 v0; // rax
__int64 result; // rax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = blockhl_banking;
result = v0 + 98304;
paletteram = result;
return result;
}

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

v0 = memory_region(129LL);
konami_cpu_setlines_callback = blockhl_banking;
result = v0 + 98304;
paletteram = result;
return result;
}

original_code:
static void blockhl_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = blockhl_banking;
 paletteram = &RAM[0x18000];
}

canonical_original_code:
static void blockhl_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = blockhl_banking;
 paletteram = &RAM[0x18000];
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall blockhl_banking(int a1)
{
__int64 v1; // rax
unsigned int v3; // eax

v1 = memory_region(129LL);
rombank = a1 & 3;
cpu_bankbase[1] = v1 + ((rombank + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a1 & 8);
coin_counter_w(1LL, a1 & 0x10);
palette_selected = ~(_BYTE)a1 & 0x20;
return K052109_set_RMRD_line((a1 >> 6) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rax
unsigned int v3; // eax

v1 = memory_region(129LL);
rombank = a1 & 3;
cpu_bankbase[1] = v1 + ((rombank + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a1 & 8);
coin_counter_w(1LL, a1 & 0x10);
palette_selected = ~(_BYTE)a1 & 0x20;
return K052109_set_RMRD_line((a1 >> 6) & 1);
}

original_code:
static void blockhl_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs;
 rombank = lines & 0x03;
 offs = 0x10000 + (lines & 0x03) * 0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 coin_counter_w(0,lines & 0x08);
 coin_counter_w(1,lines & 0x10);
 palette_selected = ~lines & 0x20;
 K052109_set_RMRD_line( ( lines & 0x40 ) ? 1 : 0 );
}

canonical_original_code:
static void blockhl_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs;
 rombank = lines & 0x03;
 offs = 0x10000 + (lines & 0x03) * 0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 coin_counter_w(0,lines & 0x08);
 coin_counter_w(1,lines & 0x10);
 palette_selected = ~lines & 0x20;
 K052109_set_RMRD_line( ( lines & 0x40 ) ? 1 : 0 );
}

variable_types: lines int

variable_types: offs int


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

if ( !(unsigned int)K052109_is_IRQ_enabled() || (result = 1LL, rombank) )
result = ignore_interrupt();
return result;
}

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

if ( !(unsigned int)K052109_is_IRQ_enabled() || (result = 1LL, rombank) )
result = ignore_interrupt();
return result;
}

original_code:
static int blockhl_interrupt( void )
{
 if (K052109_is_IRQ_enabled() && rombank == 0)
  return 1;
 else
  return ignore_interrupt();
}

canonical_original_code:
static int blockhl_interrupt()
{
 if (K052109_is_IRQ_enabled() && rombank == 0)
  return 1;
 else
  return ignore_interrupt();
}


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

*a3 |= ((unsigned __int16)*a4 << 8) & 0xF00;
result = layer_colorbase[a1] + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0xF00;
result = layer_colorbase[a1] + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

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

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

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

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

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

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

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

variable_types:
priority
int *

variable_types:
shadow
int *


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

if ( palette_selected )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

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

if ( palette_selected )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}


decompiled_code:
int *__fastcall sample_start(int a1, __int64 a2, unsigned int a3)
{
int *result; // rax
unsigned int *v5; // rdi
int v6; // eax

result = (int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = *(int **)(Machine + 848LL);
if ( result )
{
v5 = *(unsigned int **)&result[2 * (int)a2 + 2];
if ( v5 )
{
if ( numchannels <= a1 )
{
result = (int *)logerror(
"error: sample_start() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
}
else
{
v6 = *result;
if ( v6 <= (int)a2 )
{
result = (int *)logerror(
"error: sample_start() called with samplenum = %d, but only %d samples available\n",
a2,
(unsigned int)v6);
}
else if ( v5[2] == 8 )
{
result = (int *)mixer_play_sample((unsigned int)(firstchannel + a1), v5 + 3, *v5, v5[1], a3);
}
else
{
result = (int *)mixer_play_sample_16((unsigned int)(firstchannel + a1), v5 + 3, *v5, v5[1], a3);
}
}
}
}
}
return result;
}

canonical_decompiled_code:
int *__fastcall func0(int a1, __int64 a2, unsigned int a3)
{
int *result; // rax
unsigned int *v5; // rdi
int v6; // eax

result = (int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = *(int **)(Machine + 848LL);
if ( result )
{
v5 = *(unsigned int **)&result[2 * (int)a2 + 2];
if ( v5 )
{
if ( numchannels <= a1 )
{
result = (int *)logerror(
"error: sample_start() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
}
else
{
v6 = *result;
if ( v6 <= (int)a2 )
{
result = (int *)logerror(
"error: sample_start() called with samplenum = %d, but only %d samples available\n",
a2,
(unsigned int)v6);
}
else if ( v5[2] == 8 )
{
result = (int *)mixer_play_sample((unsigned int)(firstchannel + a1), v5 + 3, *v5, v5[1], a3);
}
else
{
result = (int *)mixer_play_sample_16((unsigned int)(firstchannel + a1), v5 + 3, *v5, v5[1], a3);
}
}
}
}
}
return result;
}

original_code:
void sample_start(int channel,int samplenum,int loop)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (Machine->samples->sample[samplenum] == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_start() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 if (samplenum >= Machine->samples->total)
 {
  logerror("error: sample_start() called with samplenum = %d, but only %d samples available\n",samplenum,Machine->samples->total);
  return;
 }
 if ( Machine->samples->sample[samplenum]->resolution == 8 )
 {
  mixer_play_sample(firstchannel + channel,
    Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
 else
 {
  mixer_play_sample_16(firstchannel + channel,
    (short *) Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
}

canonical_original_code:
void sample_start(int channel, int samplenum, int loop)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (Machine->samples->sample[samplenum] == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_start() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 if (samplenum >= Machine->samples->total)
 {
  logerror("error: sample_start() called with samplenum = %d, but only %d samples available\n",samplenum,Machine->samples->total);
  return;
 }
 if ( Machine->samples->sample[samplenum]->resolution == 8 )
 {
  mixer_play_sample(firstchannel + channel,
    Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
 else
 {
  mixer_play_sample_16(firstchannel + channel,
    (short *) Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
}

variable_types: channel int

variable_types: samplenum int

variable_types: loop int


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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_sample_frequency((unsigned int)(firstchannel + a1));
}
return result;
}

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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_sample_frequency((unsigned int)(firstchannel + a1));
}
return result;
}

original_code:
void sample_set_freq(int channel,int freq)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_sample_frequency(channel + firstchannel,freq);
}

canonical_original_code:
void sample_set_freq(int channel, int freq)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_sample_frequency(channel + firstchannel,freq);
}

variable_types: freq int


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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_volume((unsigned int)(firstchannel + a1), (unsigned int)(100 * a2 / 255));
}
return result;
}

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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_volume((unsigned int)(firstchannel + a1), (unsigned int)(100 * a2 / 255));
}
return result;
}

original_code:
void sample_set_volume(int channel,int volume)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_volume(channel + firstchannel,volume * 100 / 255);
}

canonical_original_code:
void sample_set_volume(int channel, int volume)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_volume(channel + firstchannel,volume * 100 / 255);
}

variable_types: volume int


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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_stop() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_stop_sample((unsigned int)(firstchannel + a1));
}
return result;
}

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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_stop() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_stop_sample((unsigned int)(firstchannel + a1));
}
return result;
}

original_code:
void sample_stop(int channel)
{
 if (Machine->sample_rate == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_stop() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_stop_sample(channel + firstchannel);
}


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

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
if ( numchannels <= a1 )
{
logerror(
"error: sample_playing() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
result = 0LL;
}
else
{
result = mixer_is_sample_playing((unsigned int)(firstchannel + a1));
}
}
return result;
}

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

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
if ( numchannels <= a1 )
{
logerror(
"error: sample_playing() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
result = 0LL;
}
else
{
result = mixer_is_sample_playing((unsigned int)(firstchannel + a1));
}
}
return result;
}

original_code:
int sample_playing(int channel)
{
 if (Machine->sample_rate == 0) return 0;
 if (channel >= numchannels)
 {
  logerror("error: sample_playing() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return 0;
 }
 return mixer_is_sample_playing(channel + firstchannel);
}


decompiled_code:
__int64 __fastcall samples_sh_start(__int64 a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rdi
char *v4; // rax
int v5; // ebx
char v7[48]; // [rsp+0h] [rbp-88h] BYREF
char v8[88]; // [rsp+30h] [rbp-58h] BYREF

v1 = *(unsigned int **)(a1 + 8);
v2 = Machine;
*(_QWORD *)(v2 + 848) = readsamples(*((_QWORD *)v1 + 1), *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
v3 = *v1;
numchannels = v3;
if ( (int)v3 > 0 )
{
v4 = v8;
do
{
*(_DWORD *)v4 = v1[1];
v4 += 4;
}
while ( v4 != &v8[4 * (unsigned int)(v3 - 1) + 4] );
}
firstchannel = mixer_allocate_channels(v3, v8);
if ( numchannels > 0 )
{
v5 = 0;
do
{
sprintf(v7, "Sample #%d", (unsigned int)v5);
mixer_set_name((unsigned int)(firstchannel + v5++), v7);
}
while ( numchannels > v5 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rdi
char *v4; // rax
int v5; // ebx
char v7[48]; // [rsp+0h] [rbp-88h] BYREF
char v8[88]; // [rsp+30h] [rbp-58h] BYREF

v1 = *(unsigned int **)(a1 + 8);
v2 = Machine;
*(_QWORD *)(v2 + 848) = readsamples(*((_QWORD *)v1 + 1), *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
v3 = *v1;
numchannels = v3;
if ( (int)v3 > 0 )
{
v4 = v8;
do
{
*(_DWORD *)v4 = v1[1];
v4 += 4;
}
while ( v4 != &v8[4 * (unsigned int)(v3 - 1) + 4] );
}
firstchannel = mixer_allocate_channels(v3, v8);
if ( numchannels > 0 )
{
v5 = 0;
do
{
sprintf(v7, "Sample #%d", (unsigned int)v5);
mixer_set_name((unsigned int)(firstchannel + v5++), v7);
}
while ( numchannels > v5 );
}
return 0LL;
}

original_code:
int samples_sh_start(const struct MachineSound *msound)
{
 int i;
 int vol[16];
 const struct Samplesinterface *intf = (const struct Samplesinterface *)msound->sound_interface;
 Machine->samples = readsamples(intf->samplenames,Machine->gamedrv->name);
 numchannels = intf->channels;
 for (i = 0;i < numchannels;i++)
  vol[i] = intf->volume;
 firstchannel = mixer_allocate_channels(numchannels,vol);
 for (i = 0;i < numchannels;i++)
 {
  char buf[40];
  sprintf(buf,"Sample #%d",i);
  mixer_set_name(firstchannel + i,buf);
 }
 return 0;
}

canonical_original_code:
int samples_sh_start(struct MachineSound *msound)
{
 int i;
 int vol[16];
 struct Samplesinterface *intf = (const struct Samplesinterface *)msound->sound_interface;
 Machine->samples = readsamples(intf->samplenames,Machine->gamedrv->name);
 numchannels = intf->channels;
 for (i = 0;i < numchannels;i++)
  vol[i] = intf->volume;
 firstchannel = mixer_allocate_channels(numchannels,vol);
 for (i = 0;i < numchannels;i++)
 {
  char buf[40];
  sprintf(buf,"Sample #%d",i);
  mixer_set_name(firstchannel + i,buf);
 }
 return 0;
}

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

variable_types: i int

variable_types:
vol
int [16]

variable_types: struct Samplesinterface { int channels; int volume; char **samplenames; } *

variable_types:
buf
char [40]


docpy

original_code:
static void docpy(int opcode,int src,int *dst,INT16 _ax,INT16 _ay)
{
 int dstep1,dstep2;
 int ax = _ax;
 int ay = _ay;
 switch (opcode & 0x0700)
 {
  default:
  case 0x0000: dstep1 = 1; dstep2 = -384; break;
  case 0x0100: dstep1 = 1; dstep2 = 384; break;
  case 0x0200: dstep1 = -1; dstep2 = -384; break;
  case 0x0300: dstep1 = -1; dstep2 = 384; break;
  case 0x0400: dstep1 = -384; dstep2 = 1; break;
  case 0x0500: dstep1 = 384; dstep2 = 1; break;
  case 0x0600: dstep1 = -384; dstep2 = -1; break;
  case 0x0700: dstep1 = 384; dstep2 = -1; break;
 }
 dstep2 -= ax * dstep1;
 for (;;)
 {
  for (;;)
  {
   switch (opcode & 0x0007)
   {
    case 0:
     HD63484_ram[*dst] = HD63484_ram[src]; break;
    case 1:
     HD63484_ram[*dst] |= HD63484_ram[src]; break;
    case 2:
     HD63484_ram[*dst] &= HD63484_ram[src]; break;
    case 3:
     HD63484_ram[*dst] ^= HD63484_ram[src]; break;
    case 4:
     if (HD63484_ram[*dst] == (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 5:
     if (HD63484_ram[*dst] != (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 6:
     if (HD63484_ram[*dst] < HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 7:
     if (HD63484_ram[*dst] > HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
   }
   if (opcode & 0x0800)
   {
    if (ay == 0) break;
    else if (ay > 0)
    {
     src = (src - 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay--;
    }
    else
    {
     src = (src + 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay++;
    }
   }
   else
   {
    if (ax == 0) break;
    else if (ax > 0)
    {
     src = (src + 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax--;
    }
    else
    {
     src = (src - 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax++;
    }
   }
  }
  if (opcode & 0x0800)
  {
   ay = _ay;
   if (_ax < 0)
   {
    src = (src - 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax++;
   }
   else
   {
    src = (src + 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax--;
   }
  }
  else
  {
   ax = _ax;
   if (_ay < 0)
   {
    src = (src + 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay++;
   }
   else
   {
    src = (src - 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay--;
   }
  }
 }
}

canonical_original_code:
static void docpy(int opcode, int src, int *dst, short _ax, short _ay)
{
 int dstep1; int dstep2;
 int ax = _ax;
 int ay = _ay;
 switch (opcode & 0x0700)
 {
  default:
  case 0x0000: dstep1 = 1; dstep2 = -384; break;
  case 0x0100: dstep1 = 1; dstep2 = 384; break;
  case 0x0200: dstep1 = -1; dstep2 = -384; break;
  case 0x0300: dstep1 = -1; dstep2 = 384; break;
  case 0x0400: dstep1 = -384; dstep2 = 1; break;
  case 0x0500: dstep1 = 384; dstep2 = 1; break;
  case 0x0600: dstep1 = -384; dstep2 = -1; break;
  case 0x0700: dstep1 = 384; dstep2 = -1; break;
 }
 dstep2 -= ax * dstep1;
 for (;;)
 {
  for (;;)
  {
   switch (opcode & 0x0007)
   {
    case 0:
     HD63484_ram[*dst] = HD63484_ram[src]; break;
    case 1:
     HD63484_ram[*dst] |= HD63484_ram[src]; break;
    case 2:
     HD63484_ram[*dst] &= HD63484_ram[src]; break;
    case 3:
     HD63484_ram[*dst] ^= HD63484_ram[src]; break;
    case 4:
     if (HD63484_ram[*dst] == (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 5:
     if (HD63484_ram[*dst] != (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 6:
     if (HD63484_ram[*dst] < HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 7:
     if (HD63484_ram[*dst] > HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
   }
   if (opcode & 0x0800)
   {
    if (ay == 0) break;
    else if (ay > 0)
    {
     src = (src - 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay--;
    }
    else
    {
     src = (src + 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay++;
    }
   }
   else
   {
    if (ax == 0) break;
    else if (ax > 0)
    {
     src = (src + 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax--;
    }
    else
    {
     src = (src - 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax++;
    }
   }
  }
  if (opcode & 0x0800)
  {
   ay = _ay;
   if (_ax < 0)
   {
    src = (src - 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax++;
   }
   else
   {
    src = (src + 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax--;
   }
  }
  else
  {
   ax = _ax;
   if (_ay < 0)
   {
    src = (src + 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay++;
   }
   else
   {
    src = (src - 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay--;
   }
  }
 }
}

variable_types: opcode int

variable_types: src int

variable_types:
dst
int *

variable_types: ax int

variable_types: ay int


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

result = 34LL;
if ( a1 == 1 )
result = 255LL;
return result;
}

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

result = 34LL;
if ( a1 == 1 )
result = 255LL;
return result;
}

original_code:
static data_t HD63484_status_r(offs_t offset)
{
 if (offset == 1) return 0xff;
 return 0x22;
}

canonical_original_code:
static unsigned int HD63484_status_r(unsigned int offset)
{
 if (offset == 1) return 0xff;
 return 0x22;
}

variable_types:
offset
unsigned int


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

reg_0[a1] = a2;
result = (unsigned __int8)reg_0[0];
regno = (unsigned __int8)reg_0[0];
return result;
}

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

reg_0[a1] = a2;
result = (unsigned __int8)reg_0[0];
regno = (unsigned __int8)reg_0[0];
return result;
}

original_code:
static void HD63484_address_w(offs_t offset,data_t data)
{
 static unsigned char reg[2];
 reg[offset] = data;
 regno = reg[0];
}

canonical_original_code:
static void HD63484_address_w(unsigned int offset, unsigned int data)
{
 static unsigned char reg[2];
 reg[offset] = data;
 regno = reg[0];
}

variable_types:
data
unsigned int

variable_types:
reg
unsigned char [2]


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int16 __fastcall shanghai_vh_screenrefresh(__int64 a1)
{
int v1; // eax
unsigned int i; // er13
unsigned int j; // ebx
int v4; // ebp
int v5; // eax
unsigned int k; // er13
unsigned int l; // ebx
int v8; // ebp
unsigned __int8 v9; // al

if ( (unsigned int)code_pressed_memory(25LL) )
base_3 -= 53760;
if ( (unsigned int)code_pressed_memory(23LL) )
base_3 += 53760;
if ( (unsigned int)code_pressed_memory(2LL) )
--bose_2;
if ( (unsigned int)code_pressed_memory(21LL) )
++bose_2;
v1 = 2 * ((unsigned __int16)word_F2E + base_3 + (((unsigned __int16)word_F2C << 16) & 0x1F0000));
for ( i = 0; i != 280; ++i )
{
for ( j = 0; j != 384; ++j )
{
v4 = v1 & 0x1FFFFF;
plot_pixel(
a1,
j,
i,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)HD63484_ram + (v1 & 0x1FFFFF))));
v1 = v4 + 1;
}
}
LOWORD(v5) = word_E66 & 0x300;
if ( (word_E66 & 0x300) == 768 )
{
v5 = 2 * ((unsigned __int16)word_F3E + base_3 + (((unsigned __int16)word_F3C << 16) & 0x1F0000));
for ( k = 0; k != 280; ++k )
{
for ( l = 0; l != 384; ++l )
{
v8 = v5 & 0x1FFFFF;
v9 = *((_BYTE *)HD63484_ram + (v5 & 0x1FFFFF));
if ( v9 )
plot_pixel(a1, l, k, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v9));
v5 = v8 + 1;
}
}
}
return v5;
}

canonical_decompiled_code:
__int16 __fastcall func5(__int64 a1)
{
int v1; // eax
unsigned int i; // er13
unsigned int j; // ebx
int v4; // ebp
int v5; // eax
unsigned int k; // er13
unsigned int l; // ebx
int v8; // ebp
unsigned __int8 v9; // al

if ( (unsigned int)code_pressed_memory(25LL) )
base_3 -= 53760;
if ( (unsigned int)code_pressed_memory(23LL) )
base_3 += 53760;
if ( (unsigned int)code_pressed_memory(2LL) )
--bose_2;
if ( (unsigned int)code_pressed_memory(21LL) )
++bose_2;
v1 = 2 * ((unsigned __int16)word_F2E + base_3 + (((unsigned __int16)word_F2C << 16) & 0x1F0000));
for ( i = 0; i != 280; ++i )
{
for ( j = 0; j != 384; ++j )
{
v4 = v1 & 0x1FFFFF;
plot_pixel(
a1,
j,
i,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)HD63484_ram + (v1 & 0x1FFFFF))));
v1 = v4 + 1;
}
}
LOWORD(v5) = word_E66 & 0x300;
if ( (word_E66 & 0x300) == 768 )
{
v5 = 2 * ((unsigned __int16)word_F3E + base_3 + (((unsigned __int16)word_F3C << 16) & 0x1F0000));
for ( k = 0; k != 280; ++k )
{
for ( l = 0; l != 384; ++l )
{
v8 = v5 & 0x1FFFFF;
v9 = *((_BYTE *)HD63484_ram + (v5 & 0x1FFFFF));
if ( v9 )
plot_pixel(a1, l, k, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v9));
v5 = v8 + 1;
}
}
}
return v5;
}

original_code:
void shanghai_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int x,y,b;
 static int base,bose=256;
if (code_pressed_memory(KEYCODE_Z)) base -= 384/2*280;
if (code_pressed_memory(KEYCODE_X)) base += 384/2*280;
if (code_pressed_memory(KEYCODE_C)) bose--;
if (code_pressed_memory(KEYCODE_V)) bose++;
 b = 2 * (base + ((HD63484_reg[0xcc/2] & 0x001f) << 16) + HD63484_reg[0xce/2]);
 for (y = 0;y < 280;y++)
 {
  for (x = 0;x < 384;x++)
  {
   b &= 0x1fffff;
   plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
   b++;
  }
 }
 if ((HD63484_reg[0x06/2] & 0x0300) == 0x0300)
 {
  b = 2 * (base + ((HD63484_reg[0xdc/2] & 0x001f) << 16) + HD63484_reg[0xde/2]);
  for (y = 0;y < 280;y++)
  {
   for (x = 0;x < 384;x++)
   {
    b &= 0x1fffff;
    if (HD63484_ram[b])
     plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
    b++;
   }
  }
 }
}

canonical_original_code:
void shanghai_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int x; int y; int b;
 static int base; static int bose = 256;
if (code_pressed_memory(KEYCODE_Z)) base -= 384/2*280;
if (code_pressed_memory(KEYCODE_X)) base += 384/2*280;
if (code_pressed_memory(KEYCODE_C)) bose--;
if (code_pressed_memory(KEYCODE_V)) bose++;
 b = 2 * (base + ((HD63484_reg[0xcc/2] & 0x001f) << 16) + HD63484_reg[0xce/2]);
 for (y = 0;y < 280;y++)
 {
  for (x = 0;x < 384;x++)
  {
   b &= 0x1fffff;
   plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
   b++;
  }
 }
 if ((HD63484_reg[0x06/2] & 0x0300) == 0x0300)
 {
  b = 2 * (base + ((HD63484_reg[0xdc/2] & 0x001f) << 16) + HD63484_reg[0xde/2]);
  for (y = 0;y < 280;y++)
  {
   for (x = 0;x < 384;x++)
   {
    b &= 0x1fffff;
    if (HD63484_ram[b])
     plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
    b++;
   }
  }
 }
}

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

variable_types: x int

variable_types: y int

variable_types: b int

variable_types: base int

variable_types: bose int


decompiled_code:
__int64 shanghai_interrupt()
{
interrupt_vector_w(0LL, 128LL);
return interrupt();
}

canonical_decompiled_code:
__int64 func6()
{
interrupt_vector_w(0LL, 128LL);
return interrupt();
}

original_code:
static int shanghai_interrupt(void)
{
 interrupt_vector_w(0,0x80);
 return interrupt();
}

canonical_original_code:
static int shanghai_interrupt()
{
 interrupt_vector_w(0,0x80);
 return interrupt();
}


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

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

original_code:
static void shanghai_coin_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
}

canonical_original_code:
static void shanghai_coin_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
}


decompiled_code:
__int64 __fastcall HD63484_data_r(int a1)
{
__int16 v1; // ax
unsigned int v2; // edx
__int64 result; // rax

v1 = 0;
if ( regno == 128 )
v1 = cpu_getscanline();
v2 = (unsigned __int8)v1;
result = HIBYTE(v1);
if ( !a1 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int16 v1; // ax
unsigned int v2; // edx
__int64 result; // rax

v1 = 0;
if ( regno == 128 )
v1 = cpu_getscanline();
v2 = (unsigned __int8)v1;
result = HIBYTE(v1);
if ( !a1 )
result = v2;
return result;
}

original_code:
static data_t HD63484_data_r(offs_t offset)
{
 int res;
 if (regno == 0x80)
 {
  res = cpu_getscanline();
 }
 else
 {
  res = 0;
 }
 if (offset == 0)
  return res & 0xff;
 else
  return (res >> 8) & 0xff;
}

canonical_original_code:
static unsigned int HD63484_data_r(unsigned int offset)
{
 int res;
 if (regno == 0x80)
 {
  res = cpu_getscanline();
 }
 else
 {
  res = 0;
 }
 if (offset == 0)
  return res & 0xff;
 else
  return (res >> 8) & 0xff;
}

variable_types: res int


decompiled_code:
__int64 HD63484_start()
{
void *v0; // rax

fifo_counter = 0;
v0 = malloc(0x200000uLL);
HD63484_ram = v0;
if ( !v0 )
return 1LL;
memset(v0, 0, 0x200000uLL);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
void *v0; // rax

fifo_counter = 0;
v0 = malloc(0x200000uLL);
HD63484_ram = v0;
if ( !v0 )
return 1LL;
memset(v0, 0, 0x200000uLL);
return 0LL;
}

original_code:
int HD63484_start(void)
{
 fifo_counter = 0;
 HD63484_ram = (UINT8*)malloc(0x200000);
 if (!HD63484_ram) return 1;
 memset(HD63484_ram,0,0x200000);
 return 0;
}

canonical_original_code:
int HD63484_start()
{
 fifo_counter = 0;
 HD63484_ram = (unsigned char *)malloc(0x200000);
 if (!HD63484_ram) return 1;
 memset(HD63484_ram,0,0x200000);
 return 0;
}


decompiled_code:
__int64 shanghai_vh_start()
{
return HD63484_start();
}

canonical_decompiled_code:
__int64 func10()
{
return func9();
}

original_code:
int shanghai_vh_start(void)
{
 return HD63484_start();
}

canonical_original_code:
int shanghai_vh_start()
{
 return HD63484_start();
}


canonical_decompiled_code:
void func11()
{
free(HD63484_ram);
HD63484_ram = 0LL;
}

original_code:
void HD63484_stop(void)
{
 free(HD63484_ram);
 HD63484_ram = 0;
}


decompiled_code:
void shanghai_vh_stop()
{
HD63484_stop();
}

canonical_decompiled_code:
void func12()
{
func11();
}

original_code:
void shanghai_vh_stop(void)
{
 HD63484_stop();
}