decompiled_code:
__int64 __fastcall battlnts_vh_screenrefresh(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 0LL, 16LL);
K007420_sprites_draw(a1);
return K007342_tilemap_draw(a1, 0LL, 17LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
K007342_tilemap_update();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K007342_tilemap_draw(a1, 0LL, 16LL);
K007420_sprites_draw(a1);
return K007342_tilemap_draw(a1, 0LL, 17LL);
}

original_code:
void battlnts_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh){
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 0, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 0, 1 | 0x10 );
}

canonical_original_code:
void battlnts_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh){
 K007342_tilemap_update();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 K007342_tilemap_draw( bitmap, 0, 0x10 );
 K007420_sprites_draw( bitmap );
 K007342_tilemap_draw( bitmap, 0, 1 | 0x10 );
}

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


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

if ( (unsigned int)K007342_is_INT_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K007342_is_INT_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int battlnts_interrupt( void )
{
 if (K007342_is_INT_enabled())
        return 1;
    else
        return ignore_interrupt();
}

canonical_original_code:
static int battlnts_interrupt()
{
 if (K007342_is_INT_enabled())
        return 1;
    else
        return ignore_interrupt();
}

return_type: int


decompiled_code:
__int64 __fastcall battlnts_bankswitch_w(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + (((unsigned int)(a2 >> 6) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + (((unsigned int)(a2 >> 6) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

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

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

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


decompiled_code:
void init_rackemup()
{
int v0; // ebp
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx

v0 = memory_region_length(137LL);
v1 = memory_region(137LL);
shuffle(v1, v0, v2, v3);
}

canonical_decompiled_code:
void func10()
{
int v0; // ebp
__int64 v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx

v0 = memory_region_length(137LL);
v1 = memory_region(137LL);
func9(v1, v0, v2, v3);
}

original_code:
static void init_rackemup(void)
{
 shuffle(memory_region(REGION_GFX1),memory_region_length(REGION_GFX1));
}

canonical_original_code:
static void init_rackemup()
{
 shuffle(memory_region(REGION_GFX1),memory_region_length(REGION_GFX1));
}


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

v2 = spritebank | *a1 | (4 * (unsigned __int16)*a2) & 0x300;
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 = 0;
return result;
}

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

v2 = spritebank | *a1 | (4 * (unsigned __int16)*a2) & 0x300;
*a1 = v2;
result = (*a2 >> 4) & 3 | (unsigned int)(4 * v2);
*a1 = result;
*a2 = 0;
return result;
}

original_code:
static void sprite_callback(int *code,int *color)
{
 *code |= ((*color & 0xc0) << 2) | spritebank;
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0;
}

canonical_original_code:
static void sprite_callback(int *code, int *color)
{
 *code |= ((*color & 0xc0) << 2) | spritebank;
 *code = (*code << 2) | ((*color & 0x30) >> 4);
 *color = 0;
}

variable_types:
code
int *

variable_types:
color
int *


shuffle

original_code:
static void shuffle(UINT8 *buf,int len)
{
 int i;
 UINT8 t;
 if (len == 2) return;
 if (len % 4) exit(1);
 len /= 2;
 for (i = 0;i < len/2;i++)
 {
  t = buf[len/2 + i];
  buf[len/2 + i] = buf[len + i];
  buf[len + i] = t;
 }
 shuffle(buf,len);
 shuffle(buf + len,len);
}

canonical_original_code:
static void shuffle(unsigned char *buf, int len)
{
 int i;
 unsigned char t;
 if (len == 2) return;
 if (len % 4) exit(1);
 len /= 2;
 for (i = 0;i < len/2;i++)
 {
  t = buf[len/2 + i];
  buf[len/2 + i] = buf[len + i];
  buf[len + i] = t;
 }
 shuffle(buf,len);
 shuffle(buf + len,len);
}

variable_types:
buf
unsigned char *

variable_types: len int

variable_types: i int

variable_types:
t
unsigned char


canonical_decompiled_code:
void func0()
{
serial_count = 0;
sending = 0;
}

original_code:
static void EEPROM_reset(void)
{
 serial_count = 0;
 sending = 0;
}

canonical_original_code:
static void EEPROM_reset()
{
 serial_count = 0;
 sending = 0;
}


decompiled_code:
int __fastcall EEPROM_write(int a1)
{
size_t v1; // rax
int *v2; // rbp
size_t v3; // r12
const char *v4; // r14
size_t v5; // r13
__int64 v6; // r15
const char *v7; // r13
size_t v8; // r15
__int64 v9; // r14
size_t v10; // rax
__int64 v11; // r15
const char *v12; // rsi
size_t v13; // r13
__int64 v14; // r14
const char *v15; // r13
const char *v16; // rbp
char *v17; // rbx
char *v18; // r13
int v19; // edx
char *v20; // rbx
char *v21; // r15
char *v22; // rsi
int v23; // edx
size_t v24; // r13
char *v25; // rbx
char *v26; // r13
int v27; // eax
__int64 v28; // rcx
int v29; // edx
char *s2a; // [rsp+0h] [rbp-40h]
int s2; // [rsp+0h] [rbp-40h]

v1 = serial_count;
if ( serial_count > 38 )
return v1;
v2 = (int *)intf;
++serial_count;
v3 = (int)v1 + 1;
*(&serial_buffer + v1) = 48 - ((a1 == 0) - 1);
*(&serial_buffer + v3) = 0;
v4 = (const char *)*((_QWORD *)v2 + 1);
if ( v4 )
{
v5 = strlen(*((const char **)v2 + 1));
v6 = *v2;
LODWORD(v1) = v5 + v6;
if ( v3 == v5 + v6 )
{
LODWORD(v1) = strncmp(&serial_buffer, v4, v5);
if ( !(_DWORD)v1 )
{
if ( (int)v6 > 0 )
{
v17 = &serial_buffer + v5;
v18 = (char *)&unk_781 + (unsigned int)(v6 - 1) + v5;
do
{
LODWORD(v1) = 2 * v1;
if ( *v17 == 49 )
LODWORD(v1) = v1 | 1;
++v17;
}
while ( v17 != v18 );
}
if ( v2[1] == 16 )
v19 = eeprom_data[2 * (int)v1 + 1] + (eeprom_data[2 * (int)v1] << 8);
else
v19 = eeprom_data[(int)v1];
eeprom_data_bits = v19;
eeprom_read_address = v1;
eeprom_clock_count = 0;
sending = 1;
serial_count = 0;
return v1;
}
}
}
v7 = (const char *)*((_QWORD *)v2 + 3);
if ( v7 )
{
v8 = strlen(*((const char **)v2 + 3));
v9 = *v2;
LODWORD(v1) = v8 + v9;
if ( v3 == v8 + v9 )
{
LODWORD(v1) = strncmp(&serial_buffer, v7, v8);
if ( !(_DWORD)v1 )
{
if ( (int)v9 > 0 )
{
v20 = &serial_buffer + v8;
v21 = (char *)&unk_781 + (unsigned int)(v9 - 1) + v8;
do
{
LODWORD(v1) = 2 * v1;
if ( *v20 == 49 )
LODWORD(v1) = v1 | 1;
++v20;
}
while ( v21 != v20 );
}
if ( !locked )
{
if ( v2[1] == 16 )
{
v27 = 2 * v1;
v28 = v27;
v1 = v27 + 1;
eeprom_data[v28] = 0;
eeprom_data[v1] = 0;
}
else
{
eeprom_data[(int)v1] = 0;
}
return v1;
}
LABEL_34:
serial_count = 0;
return v1;
}
}
}
if ( *((_QWORD *)v2 + 2) )
{
s2a = (char *)*((_QWORD *)v2 + 2);
v10 = strlen(s2a);
v11 = *v2;
v12 = s2a;
v13 = v10;
v14 = v2[1];
v1 = v10 + v11 + v14;
if ( v3 == v1 )
{
s2 = *v2;
LODWORD(v1) = strncmp(&serial_buffer, v12, v13);
if ( !(_DWORD)v1 )
{
if ( s2 <= 0 )
{
v23 = 0;
}
else
{
v22 = &serial_buffer + v13;
v23 = 0;
do
{
v23 *= 2;
if ( *v22 == 49 )
v23 |= 1u;
++v22;
}
while ( v22 != (char *)&unk_781 + (unsigned int)(s2 - 1) + v13 );
}
if ( (int)v14 > 0 )
{
v24 = v11 + v13;
v25 = &serial_buffer + v24;
v26 = (char *)&unk_781 + (unsigned int)(v14 - 1) + v24;
do
{
LODWORD(v1) = 2 * v1;
if ( *v25 == 49 )
LODWORD(v1) = v1 | 1;
++v25;
}
while ( v25 != v26 );
}
if ( !locked )
{
if ( (_DWORD)v14 == 16 )
{
v29 = 2 * v23;
eeprom_data[v29] = BYTE1(v1);
eeprom_data[v29 + 1] = v1;
}
else
{
eeprom_data[v23] = v1;
}
return v1;
}
goto LABEL_34;
}
}
}
v15 = (const char *)*((_QWORD *)v2 + 4);
if ( v15 )
{
v1 = strlen(*((const char **)v2 + 4));
if ( v3 == v1 )
{
LODWORD(v1) = strncmp(&serial_buffer, v15, v3);
if ( !(_DWORD)v1 )
{
locked = 1;
serial_count = 0;
return v1;
}
}
}
v16 = (const char *)*((_QWORD *)v2 + 5);
if ( v16 )
{
v1 = strlen(v16);
if ( v3 == v1 )
{
LODWORD(v1) = strncmp(&serial_buffer, v16, v3);
if ( !(_DWORD)v1 )
{
locked = 0;
goto LABEL_34;
}
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
size_t v1; // rax
int *v2; // rbp
size_t v3; // r12
const char *v4; // r14
size_t v5; // r13
__int64 v6; // r15
const char *v7; // r13
size_t v8; // r15
__int64 v9; // r14
size_t v10; // rax
__int64 v11; // r15
const char *v12; // rsi
size_t v13; // r13
__int64 v14; // r14
const char *v15; // r13
const char *v16; // rbp
char *v17; // rbx
char *v18; // r13
int v19; // edx
char *v20; // rbx
char *v21; // r15
char *v22; // rsi
int v23; // edx
size_t v24; // r13
char *v25; // rbx
char *v26; // r13
int v27; // eax
__int64 v28; // rcx
int v29; // edx
char *s2a; // [rsp+0h] [rbp-40h]
int s2; // [rsp+0h] [rbp-40h]

v1 = serial_count;
if ( serial_count > 38 )
return v1;
v2 = (int *)intf;
++serial_count;
v3 = (int)v1 + 1;
*(&serial_buffer + v1) = 48 - ((a1 == 0) - 1);
*(&serial_buffer + v3) = 0;
v4 = (const char *)*((_QWORD *)v2 + 1);
if ( v4 )
{
v5 = strlen(*((const char **)v2 + 1));
v6 = *v2;
LODWORD(v1) = v5 + v6;
if ( v3 == v5 + v6 )
{
LODWORD(v1) = strncmp(&serial_buffer, v4, v5);
if ( !(_DWORD)v1 )
{
if ( (int)v6 > 0 )
{
v17 = &serial_buffer + v5;
v18 = (char *)&unk_781 + (unsigned int)(v6 - 1) + v5;
do
{
LODWORD(v1) = 2 * v1;
if ( *v17 == 49 )
LODWORD(v1) = v1 | 1;
++v17;
}
while ( v17 != v18 );
}
if ( v2[1] == 16 )
v19 = eeprom_data[2 * (int)v1 + 1] + (eeprom_data[2 * (int)v1] << 8);
else
v19 = eeprom_data[(int)v1];
eeprom_data_bits = v19;
eeprom_read_address = v1;
eeprom_clock_count = 0;
sending = 1;
serial_count = 0;
return v1;
}
}
}
v7 = (const char *)*((_QWORD *)v2 + 3);
if ( v7 )
{
v8 = strlen(*((const char **)v2 + 3));
v9 = *v2;
LODWORD(v1) = v8 + v9;
if ( v3 == v8 + v9 )
{
LODWORD(v1) = strncmp(&serial_buffer, v7, v8);
if ( !(_DWORD)v1 )
{
if ( (int)v9 > 0 )
{
v20 = &serial_buffer + v8;
v21 = (char *)&unk_781 + (unsigned int)(v9 - 1) + v8;
do
{
LODWORD(v1) = 2 * v1;
if ( *v20 == 49 )
LODWORD(v1) = v1 | 1;
++v20;
}
while ( v21 != v20 );
}
if ( !locked )
{
if ( v2[1] == 16 )
{
v27 = 2 * v1;
v28 = v27;
v1 = v27 + 1;
eeprom_data[v28] = 0;
eeprom_data[v1] = 0;
}
else
{
eeprom_data[(int)v1] = 0;
}
return v1;
}
LABEL_34:
serial_count = 0;
return v1;
}
}
}
if ( *((_QWORD *)v2 + 2) )
{
s2a = (char *)*((_QWORD *)v2 + 2);
v10 = strlen(s2a);
v11 = *v2;
v12 = s2a;
v13 = v10;
v14 = v2[1];
v1 = v10 + v11 + v14;
if ( v3 == v1 )
{
s2 = *v2;
LODWORD(v1) = strncmp(&serial_buffer, v12, v13);
if ( !(_DWORD)v1 )
{
if ( s2 <= 0 )
{
v23 = 0;
}
else
{
v22 = &serial_buffer + v13;
v23 = 0;
do
{
v23 *= 2;
if ( *v22 == 49 )
v23 |= 1u;
++v22;
}
while ( v22 != (char *)&unk_781 + (unsigned int)(s2 - 1) + v13 );
}
if ( (int)v14 > 0 )
{
v24 = v11 + v13;
v25 = &serial_buffer + v24;
v26 = (char *)&unk_781 + (unsigned int)(v14 - 1) + v24;
do
{
LODWORD(v1) = 2 * v1;
if ( *v25 == 49 )
LODWORD(v1) = v1 | 1;
++v25;
}
while ( v25 != v26 );
}
if ( !locked )
{
if ( (_DWORD)v14 == 16 )
{
v29 = 2 * v23;
eeprom_data[v29] = BYTE1(v1);
eeprom_data[v29 + 1] = v1;
}
else
{
eeprom_data[v23] = v1;
}
return v1;
}
goto LABEL_34;
}
}
}
v15 = (const char *)*((_QWORD *)v2 + 4);
if ( v15 )
{
v1 = strlen(*((const char **)v2 + 4));
if ( v3 == v1 )
{
LODWORD(v1) = strncmp(&serial_buffer, v15, v3);
if ( !(_DWORD)v1 )
{
locked = 1;
serial_count = 0;
return v1;
}
}
}
v16 = (const char *)*((_QWORD *)v2 + 5);
if ( v16 )
{
v1 = strlen(v16);
if ( v3 == v1 )
{
LODWORD(v1) = strncmp(&serial_buffer, v16, v3);
if ( !(_DWORD)v1 )
{
locked = 0;
goto LABEL_34;
}
}
}
return v1;
}

original_code:
static void EEPROM_write(int bit)
{
 if (serial_count >= 40 -1)
 {
  return;
 }
 serial_buffer[serial_count++] = (bit ? '1' : '0');
 serial_buffer[serial_count] = 0;
 if (intf->cmd_read && serial_count == (strlen(intf->cmd_read) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_read,strlen(intf->cmd_read)))
 {
  int i,address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_read)] == '1') address |= 1;
  }
  if (intf->data_bits == 16)
   eeprom_data_bits = (eeprom_data[2*address+0] << 8) + eeprom_data[2*address+1];
  else
   eeprom_data_bits = eeprom_data[address];
  eeprom_read_address = address;
  eeprom_clock_count = 0;
  sending = 1;
  serial_count = 0;
 }
 else if (intf->cmd_erase && serial_count == (strlen(intf->cmd_erase) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_erase,strlen(intf->cmd_erase)))
 {
  int i,address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_erase)] == '1') address |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = 0x00;
    eeprom_data[2*address+1] = 0x00;
   }
   else
    eeprom_data[address] = 0x00;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_write && serial_count == (strlen(intf->cmd_write) + intf->address_bits + intf->data_bits) &&
   !strncmp(serial_buffer,intf->cmd_write,strlen(intf->cmd_write)))
 {
  int i,address,data;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write)] == '1') address |= 1;
  }
  data = 0;
  for (i = 0;i < intf->data_bits;i++)
  {
   data <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write) + intf->address_bits] == '1') data |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = data >> 8;
    eeprom_data[2*address+1] = data & 0xff;
   }
   else
    eeprom_data[address] = data;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_lock && serial_count == strlen(intf->cmd_lock) &&
   !strncmp(serial_buffer,intf->cmd_lock,strlen(intf->cmd_lock)))
 {
  locked = 1;
  serial_count = 0;
 }
 else if (intf->cmd_unlock && serial_count == strlen(intf->cmd_unlock) &&
   !strncmp(serial_buffer,intf->cmd_unlock,strlen(intf->cmd_unlock)))
 {
  locked = 0;
  serial_count = 0;
 }
}

canonical_original_code:
static void EEPROM_write(int bit)
{
 if (serial_count >= 40 -1)
 {
  return;
 }
 serial_buffer[serial_count++] = (bit ? '1' : '0');
 serial_buffer[serial_count] = 0;
 if (intf->cmd_read && serial_count == (strlen(intf->cmd_read) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_read,strlen(intf->cmd_read)))
 {
  int i; int address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_read)] == '1') address |= 1;
  }
  if (intf->data_bits == 16)
   eeprom_data_bits = (eeprom_data[2*address+0] << 8) + eeprom_data[2*address+1];
  else
   eeprom_data_bits = eeprom_data[address];
  eeprom_read_address = address;
  eeprom_clock_count = 0;
  sending = 1;
  serial_count = 0;
 }
 else if (intf->cmd_erase && serial_count == (strlen(intf->cmd_erase) + intf->address_bits) &&
   !strncmp(serial_buffer,intf->cmd_erase,strlen(intf->cmd_erase)))
 {
  int i; int address;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_erase)] == '1') address |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = 0x00;
    eeprom_data[2*address+1] = 0x00;
   }
   else
    eeprom_data[address] = 0x00;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_write && serial_count == (strlen(intf->cmd_write) + intf->address_bits + intf->data_bits) &&
   !strncmp(serial_buffer,intf->cmd_write,strlen(intf->cmd_write)))
 {
  int i; int address; int data;
  address = 0;
  for (i = 0;i < intf->address_bits;i++)
  {
   address <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write)] == '1') address |= 1;
  }
  data = 0;
  for (i = 0;i < intf->data_bits;i++)
  {
   data <<= 1;
   if (serial_buffer[i + strlen(intf->cmd_write) + intf->address_bits] == '1') data |= 1;
  }
  if (locked == 0)
  {
   if (intf->data_bits == 16)
   {
    eeprom_data[2*address+0] = data >> 8;
    eeprom_data[2*address+1] = data & 0xff;
   }
   else
    eeprom_data[address] = data;
  }
  else
  serial_count = 0;
 }
 else if (intf->cmd_lock && serial_count == strlen(intf->cmd_lock) &&
   !strncmp(serial_buffer,intf->cmd_lock,strlen(intf->cmd_lock)))
 {
  locked = 1;
  serial_count = 0;
 }
 else if (intf->cmd_unlock && serial_count == strlen(intf->cmd_unlock) &&
   !strncmp(serial_buffer,intf->cmd_unlock,strlen(intf->cmd_unlock)))
 {
  locked = 0;
  serial_count = 0;
 }
}

variable_types: bit int

variable_types: address int

variable_types: data int


decompiled_code:
_BOOL8 __fastcall EEPROM_init(__int64 a1)
{
int v1; // ecx
int v2; // eax
bool v3; // zf
_BOOL8 result; // rax

v1 = *(_DWORD *)a1;
v2 = *(_DWORD *)(a1 + 4);
intf = a1;
memset(eeprom_data, 255, (v2 << v1) / 8);
v3 = *(_QWORD *)(a1 + 40) == 0LL;
serial_count = 0;
result = !v3;
latch = 0;
reset_line = 1;
clock_line = 1;
sending = 0;
locked = !v3;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
int v1; // ecx
int v2; // eax
bool v3; // zf
_BOOL8 result; // rax

v1 = *(_DWORD *)a1;
v2 = *(_DWORD *)(a1 + 4);
intf = a1;
memset(eeprom_data, 255, (v2 << v1) / 8);
v3 = *(_QWORD *)(a1 + 40) == 0LL;
serial_count = 0;
result = !v3;
latch = 0;
reset_line = 1;
clock_line = 1;
sending = 0;
locked = !v3;
return result;
}

original_code:
void EEPROM_init(struct EEPROM_interface *interface)
{
 intf = interface;
 memset(eeprom_data,0xff,(1 << intf->address_bits) * intf->data_bits / 8);
 serial_count = 0;
 latch = 0;
 reset_line = 1;
 clock_line = 1;
 sending = 0;
 if (intf->cmd_unlock) locked = 1;
 else locked = 0;
}

variable_types: struct EEPROM_interface { int address_bits; int data_bits; char *cmd_read; char *cmd_write; char *cmd_erase; char *cmd_lock; char *cmd_unlock; int enable_multi_read; } *


decompiled_code:
void __fastcall EEPROM_write_bit(int a1)
{
latch = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
latch = a1;
}

original_code:
void EEPROM_write_bit(int bit)
{
 latch = bit;
}


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

result = 1LL;
if ( sending )
result = (eeprom_data_bits >> *(_DWORD *)(intf + 4)) & 1;
return result;
}

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

result = 1LL;
if ( sending )
result = (eeprom_data_bits >> *(_DWORD *)(intf + 4)) & 1;
return result;
}

original_code:
int EEPROM_read_bit(void)
{
 int res;
 if (sending)
  res = (eeprom_data_bits >> intf->data_bits) & 1;
 else res = 1;
 return res;
}

canonical_original_code:
int EEPROM_read_bit()
{
 int res;
 if (sending)
  res = (eeprom_data_bits >> intf->data_bits) & 1;
 else res = 1;
 return res;
}

variable_types: res int


decompiled_code:
void __fastcall EEPROM_set_cs_line(int a1)
{
reset_line = a1;
if ( a1 )
EEPROM_reset();
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
reset_line = a1;
if ( a1 )
func0();
}

original_code:
void EEPROM_set_cs_line(int state)
{
 reset_line = state;
 if (reset_line != 0)
  EEPROM_reset();
}

variable_types: state int


decompiled_code:
void __fastcall EEPROM_set_clock_line(int a1)
{
int v1; // esi
int v2; // edx
int v3; // eax
int v4; // eax

if ( a1 != 3 && (clock_line || !a1) || reset_line )
goto LABEL_4;
if ( !sending )
{
EEPROM_write(latch);
LABEL_4:
clock_line = a1;
return;
}
v1 = *(_DWORD *)(intf + 4);
if ( v1 == eeprom_clock_count )
{
if ( *(_DWORD *)(intf + 48) )
{
v4 = (eeprom_read_address + 1) & ((1 << *(_DWORD *)intf) - 1);
eeprom_read_address = v4;
if ( v1 == 16 )
v2 = eeprom_data[2 * v4 + 1] + (eeprom_data[2 * v4] << 8);
else
v2 = eeprom_data[v4];
v3 = 1;
}
else
{
v2 = eeprom_data_bits;
v3 = v1 + 1;
}
}
else
{
v2 = eeprom_data_bits;
v3 = eeprom_clock_count + 1;
}
clock_line = a1;
eeprom_data_bits = 2 * v2 + 1;
eeprom_clock_count = v3;
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
int v1; // esi
int v2; // edx
int v3; // eax
int v4; // eax

if ( a1 != 3 && (clock_line || !a1) || reset_line )
goto LABEL_4;
if ( !sending )
{
func1(latch);
LABEL_4:
clock_line = a1;
return;
}
v1 = *(_DWORD *)(intf + 4);
if ( v1 == eeprom_clock_count )
{
if ( *(_DWORD *)(intf + 48) )
{
v4 = (eeprom_read_address + 1) & ((1 << *(_DWORD *)intf) - 1);
eeprom_read_address = v4;
if ( v1 == 16 )
v2 = eeprom_data[2 * v4 + 1] + (eeprom_data[2 * v4] << 8);
else
v2 = eeprom_data[v4];
v3 = 1;
}
else
{
v2 = eeprom_data_bits;
v3 = v1 + 1;
}
}
else
{
v2 = eeprom_data_bits;
v3 = eeprom_clock_count + 1;
}
clock_line = a1;
eeprom_data_bits = 2 * v2 + 1;
eeprom_clock_count = v3;
}

original_code:
void EEPROM_set_clock_line(int state)
{
 if (state == 3 || (clock_line == 0 && state != 0))
 {
  if (reset_line == 0)
  {
   if (sending)
   {
    if (eeprom_clock_count == intf->data_bits && intf->enable_multi_read)
    {
     eeprom_read_address = (eeprom_read_address + 1) & ((1 << intf->address_bits) - 1);
     if (intf->data_bits == 16)
      eeprom_data_bits = (eeprom_data[2*eeprom_read_address+0] << 8) + eeprom_data[2*eeprom_read_address+1];
     else
      eeprom_data_bits = eeprom_data[eeprom_read_address];
     eeprom_clock_count = 0;
    }
    eeprom_data_bits = (eeprom_data_bits << 1) | 1;
    eeprom_clock_count++;
   }
   else
    EEPROM_write(latch);
  }
 }
 clock_line = state;
}


decompiled_code:
__int64 __fastcall EEPROM_load(__int64 a1)
{
return osd_fread(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return osd_fread(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

original_code:
void EEPROM_load(void *f)
{
 osd_fread(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8);
}

variable_types:
f
void *


decompiled_code:
__int64 __fastcall EEPROM_save(__int64 a1)
{
return osd_fwrite(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return osd_fwrite(a1, eeprom_data, (unsigned int)((*(_DWORD *)(intf + 4) << *(_DWORD *)intf) / 8));
}

original_code:
void EEPROM_save(void *f)
{
 osd_fwrite(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8);
}


decompiled_code:
void *__fastcall EEPROM_set_data(void *src, int a2)
{
return memcpy(eeprom_data, src, a2);
}

canonical_decompiled_code:
void *__fastcall func9(void *src, int a2)
{
return memcpy(eeprom_data, src, a2);
}

original_code:
void EEPROM_set_data(UINT8 *data, int length)
{
 memcpy(eeprom_data, data, length);
}

canonical_original_code:
void EEPROM_set_data(unsigned char *data, int length)
{
 memcpy(eeprom_data, data, length);
}

variable_types:
data
unsigned char *

variable_types: length int


original_code:
static void sega_decode(const unsigned char xortable[32][4])
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0x0000;A < 0x8000;A++)
 {
  int row,col;
  unsigned char src;
  src = rom[A];
  row = (A & 1) + (((A >> 4) & 1) << 1) + (((A >> 8) & 1) << 2) + (((A >> 12) & 1) << 3);
  col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
  if (src & 0x80) col = 3 - col;
  rom[A + diff] = src ^ xortable[2*row][col];
  rom[A] = src ^ xortable[2*row+1][col];
  if (xortable[2*row][col] == 0xff)
   rom[A + diff] = 0x00;
  if (xortable[2*row+1][col] == 0xff)
   rom[A] = 0xee;
 }
 for (A = 0x8000;A < diff;A++)
  rom[A + diff] = rom[A];
}

canonical_original_code:
static void sega_decode(unsigned char xortable[32][4])
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0x0000;A < 0x8000;A++)
 {
  int row; int col;
  unsigned char src;
  src = rom[A];
  row = (A & 1) + (((A >> 4) & 1) << 1) + (((A >> 8) & 1) << 2) + (((A >> 12) & 1) << 3);
  col = ((src >> 3) & 1) + (((src >> 5) & 1) << 1);
  if (src & 0x80) col = 3 - col;
  rom[A + diff] = src ^ xortable[2*row][col];
  rom[A] = src ^ xortable[2*row+1][col];
  if (xortable[2*row][col] == 0xff)
   rom[A + diff] = 0x00;
  if (xortable[2*row+1][col] == 0xff)
   rom[A] = 0xee;
 }
 for (A = 0x8000;A < diff;A++)
  rom[A + diff] = rom[A];
}

variable_types:
xortable
unsigned char [32][4]

variable_types: A int

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: row int

variable_types: col int

variable_types:
src
unsigned char


decompiled_code:
__int64 pengo_decode()
{
return sega_decode((__int64)&xortable_20);
}

canonical_decompiled_code:
__int64 func1()
{
return func0((__int64)&xortable_20);
}


decompiled_code:
__int64 szaxxon_decode()
{
return sega_decode((__int64)&xortable_19);
}

canonical_decompiled_code:
__int64 func2()
{
return func0((__int64)&xortable_19);
}


decompiled_code:
__int64 suprloco_decode()
{
return sega_decode((__int64)&xortable_18);
}

canonical_decompiled_code:
__int64 func3()
{
return func0((__int64)&xortable_18);
}


decompiled_code:
__int64 yamato_decode()
{
return sega_decode((__int64)&xortable_17);
}

canonical_decompiled_code:
__int64 func4()
{
return func0((__int64)&xortable_17);
}


decompiled_code:
__int64 sindbadm_decode()
{
return sega_decode((__int64)&xortable_16);
}

canonical_decompiled_code:
__int64 func5()
{
return func0((__int64)&xortable_16);
}


decompiled_code:
__int64 regulus_decode()
{
return sega_decode((__int64)&xortable_15);
}

canonical_decompiled_code:
__int64 func6()
{
return func0((__int64)&xortable_15);
}


decompiled_code:
__int64 mrviking_decode()
{
return sega_decode((__int64)&xortable_14);
}

canonical_decompiled_code:
__int64 func7()
{
return func0((__int64)&xortable_14);
}


decompiled_code:
__int64 swat_decode()
{
return sega_decode((__int64)&xortable_13);
}

canonical_decompiled_code:
__int64 func8()
{
return func0((__int64)&xortable_13);
}


decompiled_code:
__int64 flicky_decode()
{
return sega_decode((__int64)&xortable_12);
}

canonical_decompiled_code:
__int64 func9()
{
return func0((__int64)&xortable_12);
}


decompiled_code:
__int64 futspy_decode()
{
return sega_decode((__int64)&xortable_11);
}

canonical_decompiled_code:
__int64 func10()
{
return func0((__int64)&xortable_11);
}


decompiled_code:
__int64 bullfgtj_decode()
{
return sega_decode((__int64)&xortable_10);
}

canonical_decompiled_code:
__int64 func11()
{
return func0((__int64)&xortable_10);
}


decompiled_code:
__int64 pitfall2_decode()
{
return sega_decode((__int64)&xortable_9);
}

canonical_decompiled_code:
__int64 func12()
{
return func0((__int64)&xortable_9);
}


decompiled_code:
__int64 nprinces_decode()
{
return sega_decode((__int64)&xortable_8);
}

canonical_decompiled_code:
__int64 func13()
{
return func0((__int64)&xortable_8);
}


decompiled_code:
__int64 seganinj_decode()
{
return sega_decode((__int64)&xortable_7);
}

canonical_decompiled_code:
__int64 func14()
{
return func0((__int64)&xortable_7);
}


decompiled_code:
__int64 imsorry_decode()
{
return sega_decode((__int64)&xortable_6);
}

canonical_decompiled_code:
__int64 func15()
{
return func0((__int64)&xortable_6);
}


decompiled_code:
__int64 teddybb_decode()
{
return sega_decode((__int64)&xortable_5);
}

canonical_decompiled_code:
__int64 func16()
{
return func0((__int64)&xortable_5);
}


decompiled_code:
__int64 hvymetal_decode()
{
return sega_decode((__int64)&xortable_4);
}

canonical_decompiled_code:
__int64 func17()
{
return func0((__int64)&xortable_4);
}


decompiled_code:
__int64 myheroj_decode()
{
return sega_decode((__int64)&xortable_3);
}

canonical_decompiled_code:
__int64 func18()
{
return func0((__int64)&xortable_3);
}


variable_types:
xortable
unsigned char [-1][8]


decompiled_code:
void gardia_decode()
{
;
}

canonical_decompiled_code:
void func22()
{
;
}

original_code:
void gardia_decode(void)
{
}

canonical_original_code:
void gardia_decode()
{
}


decompiled_code:
__int64 meteor_interrupt()
{
return 8LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 8LL;
}

original_code:
static int meteor_interrupt(void)
{
 return 0x08;
}

canonical_original_code:
static int meteor_interrupt()
{
 return 0x08;
}


decompiled_code:
void __fastcall meteor_SN76496_latch_w(__int64 a1, int a2)
{
meteor_SN76496_latch = a2;
}

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

original_code:
static void meteor_SN76496_latch_w(offs_t offset,data_t data)
{
 meteor_SN76496_latch = data;
}

canonical_original_code:
static void meteor_SN76496_latch_w(unsigned int offset, unsigned int data)
{
 meteor_SN76496_latch = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 meteor_SN76496_select_r()
{
return (unsigned int)meteor_SN76496_select;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)meteor_SN76496_select;
}

original_code:
static data_t meteor_SN76496_select_r(offs_t offset)
{
 return meteor_SN76496_select;
}

canonical_original_code:
static unsigned int meteor_SN76496_select_r(unsigned int offset)
{
 return meteor_SN76496_select;
}

return_type: unsigned int


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

meteor_SN76496_select = a2;
if ( (a2 & 0x40) != 0 )
{
if ( (a2 & 0x20) != 0 )
goto LABEL_3;
}
else
{
result = SN76496_0_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x20) != 0 )
{
LABEL_3:
if ( (a2 & 0x10) != 0 )
return result;
return SN76496_2_w(0LL, (unsigned int)meteor_SN76496_latch);
}
}
result = SN76496_1_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x10) == 0 )
return SN76496_2_w(0LL, (unsigned int)meteor_SN76496_latch);
return result;
}

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

meteor_SN76496_select = a2;
if ( (a2 & 0x40) != 0 )
{
if ( (a2 & 0x20) != 0 )
goto LABEL_3;
}
else
{
result = SN76496_0_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x20) != 0 )
{
LABEL_3:
if ( (a2 & 0x10) != 0 )
return result;
return SN76496_2_w(0LL, (unsigned int)meteor_SN76496_latch);
}
}
result = SN76496_1_w(0LL, (unsigned int)meteor_SN76496_latch);
if ( (a2 & 0x10) == 0 )
return SN76496_2_w(0LL, (unsigned int)meteor_SN76496_latch);
return result;
}

original_code:
static void meteor_SN76496_select_w(offs_t offset,data_t data)
{
    meteor_SN76496_select = data;
 if (~data & 0x40) SN76496_0_w(0, meteor_SN76496_latch);
 if (~data & 0x20) SN76496_1_w(0, meteor_SN76496_latch);
 if (~data & 0x10) SN76496_2_w(0, meteor_SN76496_latch);
}

canonical_original_code:
static void meteor_SN76496_select_w(unsigned int offset, unsigned int data)
{
    meteor_SN76496_select = data;
 if (~data & 0x40) SN76496_0_w(0, meteor_SN76496_latch);
 if (~data & 0x20) SN76496_1_w(0, meteor_SN76496_latch);
 if (~data & 0x10) SN76496_2_w(0, meteor_SN76496_latch);
}


decompiled_code:
__int64 meteor_t0_r()
{
return rand() & 1;
}

canonical_decompiled_code:
__int64 func5()
{
return rand() & 1;
}

original_code:
static data_t meteor_t0_r(offs_t offset)
{
 return rand() & 1;
}

canonical_original_code:
static unsigned int meteor_t0_r(unsigned int offset)
{
 return rand() & 1;
}


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

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

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

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

original_code:
static void meteor_soundtrigger_w(offs_t offset,data_t data)
{
 if ((meteor_soundtrigger & 0x08) && (~data & 0x08))
 {
  cpu_cause_interrupt(1, 1);
 }
 meteor_soundtrigger = data;
}

canonical_original_code:
static void meteor_soundtrigger_w(unsigned int offset, unsigned int data)
{
 if ((meteor_soundtrigger & 0x08) && (~data & 0x08))
 {
  cpu_cause_interrupt(1, 1);
 }
 meteor_soundtrigger = data;
}


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

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}


original_code:
void pinbo_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++;
 }
}

canonical_original_code:
void pinbo_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++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void *__fastcall pinbo_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r15
void *result; // rax
int v4; // ebx
__int64 v5; // r14
__int16 v6; // si
char v7; // dl

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((32 * *(unsigned __int8 *)(colorram + v2)) & 0xE00) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v5 = v4 + 3LL;
do
{
v7 = *(_BYTE *)(spriteram + v5 - 2);
v6 = *(unsigned __int8 *)(spriteram + v5 - 1);
v5 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), (8 * v6) & 0x180 | v7 & 0x3F | 0x40u, v6 & 0xF);
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // r15
void *result; // rax
int v4; // ebx
__int64 v5; // r14
__int16 v6; // si
char v7; // dl

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(v2 + dirtybuffer) )
{
*(_BYTE *)(v2 + dirtybuffer) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((32 * *(unsigned __int8 *)(colorram + v2)) & 0xE00) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v1;
--v2;
}
while ( v1 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v5 = v4 + 3LL;
do
{
v7 = *(_BYTE *)(spriteram + v5 - 2);
v6 = *(unsigned __int8 *)(spriteram + v5 - 1);
v5 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), (8 * v6) & 0x180 | v7 & 0x3F | 0x40u, v6 & 0xF);
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void pinbo_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 = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x70) << 5),
     colorram[offs] & 0x0f,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  int code,color;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen[0])
  {
   sx = 240 - sx;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  code = (spriteram[offs+1] & 0x3f) | 0x40 | ((spriteram[offs+2] & 0x30) << 3);
  color = (spriteram[offs+2] & 0x0f);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void pinbo_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 = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x70) << 5),
     colorram[offs] & 0x0f,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  int code; int color;
  sx = spriteram[offs + 3];
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen[0])
  {
   sx = 240 - sx;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  code = (spriteram[offs+1] & 0x3f) | 0x40 | ((spriteram[offs+2] & 0x30) << 3);
  color = (spriteram[offs+2] & 0x0f);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: code int

variable_types: color int


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

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

original_code:
void pinbo_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 cpu_cause_interrupt(1,-1000);
}

canonical_original_code:
void pinbo_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 cpu_cause_interrupt(1,-1000);
}


decompiled_code:
__int64 pinbo_interrupt()
{
if ( !(unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(3LL) & 0x30) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func3()
{
if ( !(unsigned int)cpu_getiloops() )
return interrupt();
if ( (readinputport(3LL) & 0x30) != 0 )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
static int pinbo_interrupt(void)
{
 if (cpu_getiloops() != 0)
 {
  if (readinputport(3) & 0x30)
   return nmi_interrupt();
  else return ignore_interrupt();
 }
 else return interrupt();
}

canonical_original_code:
static int pinbo_interrupt()
{
 if (cpu_getiloops() != 0)
 {
  if (readinputport(3) & 0x30)
   return nmi_interrupt();
  else return ignore_interrupt();
 }
 else return interrupt();
}


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

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

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

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

original_code:
void pinbo_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen[0] != (data & 1))
 {
  flipscreen[0] = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipscreen[1] != (data & 2))
 {
  flipscreen[1] = data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void pinbo_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen[0] != (data & 1))
 {
  flipscreen[0] = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipscreen[1] != (data & 2))
 {
  flipscreen[1] = data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
}


original_code:
void travrusa_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 128;i++)
 {
  int bit0,bit1,bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 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 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 color_prom += 128;
 for (i = 0;i < 32;i++)
 {
  int bit0,bit1,bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 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 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 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]) = i;
 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++) + 128;
}

canonical_original_code:
void travrusa_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < 128;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 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 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 color_prom += 128;
 for (i = 0;i < 32;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 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 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 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]) = i;
 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++) + 128;
}


decompiled_code:
__int64 travrusa_vh_start()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 64LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
*(_QWORD *)(v0 + 136) = 0x3F000000FFLL;
((void (__fastcall *)(__int64, __int64))tilemap_set_scroll_rows)(v0, 32LL);
result = 0LL;
}
return result;
}

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

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 2LL, 8LL, 8LL, 64LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
*(_QWORD *)(v0 + 136) = 0x3F000000FFLL;
((void (__fastcall *)(__int64, __int64))tilemap_set_scroll_rows)(v0, 32LL);
result = 0LL;
}
return result;
}

original_code:
int travrusa_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x02,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x3f;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}

canonical_original_code:
int travrusa_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x02,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 bg_tilemap->transmask[0] = 0xff;
 bg_tilemap->transmask[1] = 0x3f;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}


decompiled_code:
__int64 set_scroll()
{
unsigned int i; // ebx
__int64 v1; // rsi
__int64 v2; // rsi
__int64 result; // rax

for ( i = 0; i != 24; ++i )
{
v1 = i;
tilemap_set_scrollx(bg_tilemap, v1, (unsigned int)(scrollx + (dword_B5C << 8)));
}
do
{
v2 = i++;
result = tilemap_set_scrollx(bg_tilemap, v2, 0LL);
}
while ( i != 32 );
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int i; // ebx
__int64 v1; // rsi
__int64 v2; // rsi
__int64 result; // rax

for ( i = 0; i != 24; ++i )
{
v1 = i;
tilemap_set_scrollx(bg_tilemap, v1, (unsigned int)(scrollx + (dword_B5C << 8)));
}
do
{
v2 = i++;
result = tilemap_set_scrollx(bg_tilemap, v2, 0LL);
}
while ( i != 32 );
return result;
}

original_code:
static void set_scroll(void)
{
 int i;
 for (i = 0;i < 24;i++)
  tilemap_set_scrollx(bg_tilemap,i,scrollx[0] + 256 * scrollx[1]);
 for (i = 24;i < 32;i++)
  tilemap_set_scrollx(bg_tilemap,i,0);
}

canonical_original_code:
static void set_scroll()
{
 int i;
 for (i = 0;i < 24;i++)
  tilemap_set_scrollx(bg_tilemap,i,scrollx[0] + 256 * scrollx[1]);
 for (i = 24;i < 32;i++)
  tilemap_set_scrollx(bg_tilemap,i,0);
}


decompiled_code:
__int64 __fastcall travrusa_scroll_x_low_w(__int64 a1, int a2)
{
scrollx = a2;
return set_scroll();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
scrollx = a2;
return func3();
}

original_code:
void travrusa_scroll_x_low_w(offs_t offset,data_t data)
{
 scrollx[0] = data;
 set_scroll();
}

canonical_original_code:
void travrusa_scroll_x_low_w(unsigned int offset, unsigned int data)
{
 scrollx[0] = data;
 set_scroll();
}


decompiled_code:
__int64 __fastcall travrusa_scroll_x_high_w(__int64 a1, int a2)
{
dword_B5C = a2;
return set_scroll();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
dword_B5C = a2;
return func3();
}

original_code:
void travrusa_scroll_x_high_w(offs_t offset,data_t data)
{
 scrollx[1] = data;
 set_scroll();
}

canonical_original_code:
void travrusa_scroll_x_high_w(unsigned int offset, unsigned int data)
{
 scrollx[1] = data;
 set_scroll();
}


decompiled_code:
__int64 __fastcall travrusa_flipscreen_w(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
flip_screen_w(0LL, v2 & 1);
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
flip_screen_w(0LL, v2 & 1);
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

original_code:
void travrusa_flipscreen_w(offs_t offset,data_t data)
{
 data ^= ~readinputport(4) & 1;
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void travrusa_flipscreen_w(unsigned int offset, unsigned int data)
{
 data ^= ~readinputport(4) & 1;
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 __fastcall travrusa_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 64LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
func7(a1);
return tilemap_draw(a1, bg_tilemap, 64LL);
}

original_code:
void travrusa_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
}

canonical_original_code:
void travrusa_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
}

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


variable_types: A int

variable_types: j int

variable_types:
RAM
unsigned char *

variable_types:
bit
int [13]


original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = travrusa_videoram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (travrusa_videoram[2*tile_index] + ((attr & 0xc0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = 0;
 if (attr & 0x20) tile_info.flags |= 0x01;
 if (attr & 0x10) tile_info.flags |= 0x02;
 if ((attr & 0x0f) == 0x0f) tile_info.flags |= ((1)<<2);
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = travrusa_videoram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (travrusa_videoram[2*tile_index] + ((attr & 0xc0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = 0;
 if (attr & 0x20) tile_info.flags |= 0x01;
 if (attr & 0x10) tile_info.flags |= 0x02;
 if ((attr & 0x0f) == 0x0f) tile_info.flags |= ((1)<<2);
}

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:
void *__fastcall draw_sprites(__int64 a1)
{
void *result; // rax
int v2; // ebx
__int64 v3; // r14
__int64 v4; // rdx
char v5; // cl

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v3 = v2 + 3LL;
do
{
v5 = *(_BYTE *)(spriteram + v3 - 2);
v4 = *(unsigned __int8 *)(spriteram + v3 - 1);
v3 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), v4, v5 & 0xF);
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *result; // rax
int v2; // ebx
__int64 v3; // r14
__int64 v4; // rdx
char v5; // cl

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v3 = v2 + 3LL;
do
{
v5 = *(_BYTE *)(spriteram + v3 - 2);
v4 = *(unsigned __int8 *)(spriteram + v3 - 1);
v3 -= 4LL;
result = (void *)drawgfx(a1, *(_QWORD *)(Machine + 520LL), v4, v5 & 0xF);
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 static struct rectangle spritevisiblearea =
 {
  1*8, 31*8-1,
  0*8, 24*8-1
 };
 static struct rectangle spritevisibleareaflip =
 {
  1*8, 31*8-1,
  8*8, 32*8-1
 };
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = ((spriteram[offs + 3] + 8) & 0xff) - 8;
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flip_screen_x)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2],
    spriteram[offs + 1] & 0x0f,
    flipx,flipy,
    sx,sy,
    flip_screen_x ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 static struct rectangle spritevisiblearea = {
  1*8, 31*8-1,
  0*8, 24*8-1
 };
 static struct rectangle spritevisibleareaflip = {
  1*8, 31*8-1,
  8*8, 32*8-1
 };
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = ((spriteram[offs + 3] + 8) & 0xff) - 8;
  sy = 240 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flip_screen_x)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2],
    spriteram[offs + 1] & 0x0f,
    flipx,flipy,
    sx,sy,
    flip_screen_x ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,0);
 }
}

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


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

v1 = (a1 >> 7) + 2LL * (a1 & 0x7F);
Timer[v1] = 0LL;
lastfired[v1] = timer_get_time();
return YM2612TimerOver(a1 & 0x7F, (unsigned int)(a1 >> 7));
}

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

v1 = (a1 >> 7) + 2LL * (a1 & 0x7F);
Timer[v1] = 0LL;
lastfired[v1] = timer_get_time();
return YM2612TimerOver(a1 & 0x7F, (unsigned int)(a1 >> 7));
}

original_code:
static void timer_callback_2612(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 lastfired[n][c] = timer_get_time();
 YM2612TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2612(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 lastfired[n][c] = timer_get_time();
 YM2612TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2612UpdateRequest(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

original_code:
void YM2612UpdateRequest(int chip)
{
 stream_update(stream[chip],100);
}

variable_types: chip int


decompiled_code:
_BOOL8 __fastcall YM2612_sh_start(__int64 a1)
{
_BOOL4 v1; // er8
unsigned int v2; // er12
bool v3; // cc
unsigned int *v5; // rax
__int64 v6; // rdi
__int64 v7; // r14
int v8; // eax
int v9; // eax
int v10[2]; // [rsp+18h] [rbp-A0h] BYREF
__int64 v11[2]; // [rsp+20h] [rbp-98h] BYREF
char s[40]; // [rsp+30h] [rbp-88h] BYREF
char v13[96]; // [rsp+58h] [rbp-60h] BYREF

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

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
_BOOL4 v1; // er8
unsigned int v2; // er12
bool v3; // cc
unsigned int *v5; // rax
__int64 v6; // rdi
__int64 v7; // r14
int v8; // eax
int v9; // eax
int v10[2]; // [rsp+18h] [rbp-A0h] BYREF
__int64 v11[2]; // [rsp+20h] [rbp-98h] BYREF
char s[40]; // [rsp+30h] [rbp-88h] BYREF
char v13[96]; // [rsp+58h] [rbp-60h] BYREF

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

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:
// attributes: thunk
__int64 YM2612_sh_stop()
{
return YM2612Shutdown();
}

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

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

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


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

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

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
unsigned int v1; // ebx
__int64 v2; // rdi

result = *(unsigned int *)intf;
if ( (int)result > 0 )
{
v1 = 0;
do
{
v2 = v1++;
YM2612ResetChip(v2);
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 func7()
{
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


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

canonical_decompiled_code:
__int64 func8()
{
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 func9()
{
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 func10()
{
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 func11()
{
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 func12()
{
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 func13(__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 func14(__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 func15(__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 func16(__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 func17(__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 func18(__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 func19(__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 func20(__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:
void __fastcall starfire_videoram_w(__int16 a1, int a2)
{
char v2; // r8
char v3; // cl
int v4; // eax
int v5; // esi
int v6; // eax
__int16 v7; // cx
__int64 v8; // rbx
__int16 v9; // r13
_BYTE *v10; // r12
__int16 v11; // dx
__int16 v12; // r14
__int16 v13; // cx

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

canonical_decompiled_code:
void __fastcall func1(__int16 a1, int a2)
{
char v2; // r8
char v3; // cl
int v4; // eax
int v5; // esi
int v6; // eax
__int16 v7; // cx
__int64 v8; // rbx
__int16 v9; // r13
_BYTE *v10; // r12
__int16 v11; // dx
__int16 v12; // r14
__int16 v13; // cx

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

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


decompiled_code:
__int64 starfire_vh_start()
{
unsigned int v0; // er12
__int64 v1; // rbp
__m128i *v2; // rdx
__m128i v3; // xmm0
_QWORD *v4; // rcx
__int64 v5; // rdi
_QWORD *v6; // rcx
__int64 v7; // rdi

v0 = 1;
v1 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
tmpbitmap = v1;
if ( v1 )
{
scanline_dirty = malloc(0x100uLL);
v2 = (__m128i *)scanline_dirty;
if ( scanline_dirty )
{
v3 = _mm_load_si128((const __m128i *)&LC0);
v0 = 0;
v4 = starfire_videoram;
v5 = (__int64)(starfire_videoram + 1);
*starfire_videoram = 0LL;
v4[1023] = 0LL;
memset(
(void *)(v5 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)v4 - (v5 & 0xFFFFFFF8) + 0x2000) >> 3));
v6 = starfire_colorram;
v7 = (__int64)(starfire_colorram + 1);
*starfire_colorram = 0LL;
v6[1023] = 0LL;
memset(
(void *)(v7 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)v6 - (v7 & 0xFFFFFFF8) + 0x2000) >> 3));
*v2 = v3;
v2[1] = v3;
v2[2] = v3;
v2[3] = v3;
v2[4] = v3;
v2[5] = v3;
v2[6] = v3;
v2[7] = v3;
v2[8] = v3;
v2[9] = v3;
v2[10] = v3;
v2[11] = v3;
v2[12] = v3;
v2[13] = v3;
v2[14] = v3;
v2[15] = v3;
}
else
{
bitmap_free(v1);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
__int64 v1; // rbp
__m128i *v2; // rdx
__m128i v3; // xmm0
_QWORD *v4; // rcx
__int64 v5; // rdi
_QWORD *v6; // rcx
__int64 v7; // rdi

v0 = 1;
v1 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
tmpbitmap = v1;
if ( v1 )
{
scanline_dirty = malloc(0x100uLL);
v2 = (__m128i *)scanline_dirty;
if ( scanline_dirty )
{
v3 = _mm_load_si128((const __m128i *)&LC0);
v0 = 0;
v4 = starfire_videoram;
v5 = (__int64)(starfire_videoram + 1);
*starfire_videoram = 0LL;
v4[1023] = 0LL;
memset(
(void *)(v5 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)v4 - (v5 & 0xFFFFFFF8) + 0x2000) >> 3));
v6 = starfire_colorram;
v7 = (__int64)(starfire_colorram + 1);
*starfire_colorram = 0LL;
v6[1023] = 0LL;
memset(
(void *)(v7 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)v6 - (v7 & 0xFFFFFFF8) + 0x2000) >> 3));
*v2 = v3;
v2[1] = v3;
v2[2] = v3;
v2[3] = v3;
v2[4] = v3;
v2[5] = v3;
v2[6] = v3;
v2[7] = v3;
v2[8] = v3;
v2[9] = v3;
v2[10] = v3;
v2[11] = v3;
v2[12] = v3;
v2[13] = v3;
v2[14] = v3;
v2[15] = v3;
}
else
{
bitmap_free(v1);
}
}
return v0;
}

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


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(__int64 a1, unsigned int a2)
{
char v2; // r8
__int64 result; // rax
char v4; // dl
__int64 v5; // rsi
signed int v6; // eax

v2 = starfire_vidctrl1;
result = a2 & 0x1F;
if ( (a1 & 0xE0) != 0 )
{
v4 = starfire_color;
v5 = (unsigned int)a1;
a1 = (unsigned __int8)a1;
starfire_color = result;
if ( starfire_vidctrl1 >= 0 )
v4 = result;
*((_BYTE *)starfire_colorram + v5) = v4;
*((_BYTE *)scanline_dirty + a1) = 1;
}
else
{
starfire_color = a2 & 0x1F;
*((_BYTE *)starfire_colorram + ((unsigned int)a1 & 0xFFFFFEFF)) = a2;
*((_BYTE *)starfire_colorram + ((unsigned int)a1 | 0x100)) = a2;
if ( (v2 & 0x40) != 0 )
{
v6 = ((unsigned int)a1 >> 8) & 1 | (2 * (_BYTE)a2) & 6;
result = palette_change_color(
((unsigned int)a1 >> 4) & 0x20 | a1 & 0x1F,
(v6 >> 1) | (4 * v6) | (unsigned int)(32 * v6),
((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(__int64 a1, unsigned int a2)
{
char v2; // r8
__int64 result; // rax
char v4; // dl
__int64 v5; // rsi
signed int v6; // eax

v2 = starfire_vidctrl1;
result = a2 & 0x1F;
if ( (a1 & 0xE0) != 0 )
{
v4 = starfire_color;
v5 = (unsigned int)a1;
a1 = (unsigned __int8)a1;
starfire_color = result;
if ( starfire_vidctrl1 >= 0 )
v4 = result;
*((_BYTE *)starfire_colorram + v5) = v4;
*((_BYTE *)scanline_dirty + a1) = 1;
}
else
{
starfire_color = a2 & 0x1F;
*((_BYTE *)starfire_colorram + ((unsigned int)a1 & 0xFFFFFEFF)) = a2;
*((_BYTE *)starfire_colorram + ((unsigned int)a1 | 0x100)) = a2;
if ( (v2 & 0x40) != 0 )
{
v6 = ((unsigned int)a1 >> 8) & 1 | (2 * (_BYTE)a2) & 6;
result = palette_change_color(
((unsigned int)a1 >> 4) & 0x20 | a1 & 0x1F,
(v6 >> 1) | (4 * v6) | (unsigned int)(32 * v6),
((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 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 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)
{
int v1; // ebp
__int64 v2; // rdi
unsigned int v3; // eax

v1 = a1 + 8;
starfire_video_update(a1, 8);
v2 = (unsigned int)(a1 + 15);
if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) <= v1 )
{
v2 = 39LL;
v1 = 32;
}
v3 = cpu_getscanlinetime(v2);
return timer_set(v3, (unsigned int)v1, update_callback);
}

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

v1 = a1 + 8;
func13(a1, 8);
v2 = (unsigned int)(a1 + 15);
if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) <= v1 )
{
v2 = 39LL;
v1 = 32;
}
v3 = cpu_getscanlinetime(v2);
return timer_set(v3, (unsigned int)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:
__int64 __fastcall blockade_coin_latch_w(__int64 a1, char a2)
{
__int64 result; // rax

if ( (a2 & 0x80) != 0 )
{
result = (unsigned int)just_been_reset;
if ( just_been_reset )
{
just_been_reset = 0;
coin_latch = 0;
}
else
{
coin_latch = 1;
}
}
return result;
}

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

if ( (a2 & 0x80) != 0 )
{
result = (unsigned int)just_been_reset;
if ( just_been_reset )
{
just_been_reset = 0;
coin_latch = 0;
}
else
{
coin_latch = 1;
}
}
return result;
}

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:
__int64 __fastcall init_palette_gr(__int64 a1)
{
__int64 result; // rax

result = 255LL;
*(_DWORD *)a1 = 0;
*(_WORD *)(a1 + 4) = 255;
return result;
}

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

result = 255LL;
*(_DWORD *)a1 = 0;
*(_WORD *)(a1 + 4) = 255;
return result;
}

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


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

result = 0xFFFFFFFFLL;
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return result;
}

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

result = 0xFFFFFFFFLL;
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return result;
}

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:
__int64 init_blockade()
{
__int64 result; // rax
__int64 v1; // rcx
char v2; // dl

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

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 v1; // rcx
char v2; // dl

result = memory_region(129LL);
v1 = result + 1024;
do
{
v2 = *(_BYTE *)(result + 4096);
++result;
*(_BYTE *)(result - 1) = *(_BYTE *)(result + 5119) + 16 * v2;
}
while ( v1 != result );
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