decompiled_code:
__int64 flstory_68705_portB_r()
{
return (unsigned __int8)(ddrB & portB_out);
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)(ddrB & portB_out);
}

original_code:
data_t flstory_68705_portB_r(offs_t offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}

canonical_original_code:
unsigned int flstory_68705_portB_r(unsigned int offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}


decompiled_code:
void __fastcall flstory_68705_ddrB_w(__int64 a1, char a2)
{
ddrB = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, char a2)
{
ddrB = a2;
}

original_code:
void flstory_68705_ddrB_w(offs_t offset,data_t data)
{
 ddrB = data;
}

canonical_original_code:
void flstory_68705_ddrB_w(unsigned int offset, unsigned int data)
{
 ddrB = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
__int64 flstory_68705_portC_r()
{
portC_in = main_sent != 0;
if ( !mcu_sent )
portC_in |= 2u;
return ~(unsigned __int8)ddrC & (unsigned __int8)portC_in | (unsigned int)(unsigned __int8)(portC_out & ddrC);
}

canonical_decompiled_code:
__int64 func5()
{
portC_in = main_sent != 0;
if ( !mcu_sent )
portC_in |= 2u;
return ~(unsigned __int8)ddrC & (unsigned __int8)portC_in | (unsigned int)(unsigned __int8)(portC_out & ddrC);
}

original_code:
data_t flstory_68705_portC_r(offs_t offset)
{
 portC_in = 0;
 if (main_sent) portC_in |= 0x01;
 if (!mcu_sent) portC_in |= 0x02;
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}

canonical_original_code:
unsigned int flstory_68705_portC_r(unsigned int offset)
{
 portC_in = 0;
 if (main_sent) portC_in |= 0x01;
 if (!mcu_sent) portC_in |= 0x02;
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}

return_type: unsigned int


decompiled_code:
void __fastcall flstory_68705_ddrC_w(__int64 a1, char a2)
{
ddrC = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char a2)
{
ddrC = a2;
}

original_code:
void flstory_68705_ddrC_w(offs_t offset,data_t data)
{
 ddrC = data;
}

canonical_original_code:
void flstory_68705_ddrC_w(unsigned int offset, unsigned int data)
{
 ddrC = data;
}


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

result = main_sent == 0;
if ( mcu_sent )
result = (unsigned int)result | 2;
return result;
}

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

result = main_sent == 0;
if ( mcu_sent )
result = (unsigned int)result | 2;
return result;
}

original_code:
data_t flstory_mcu_status_r(offs_t offset)
{
 int res = 0;
 if (!main_sent) res |= 0x01;
 if (mcu_sent) res |= 0x02;
 return res;
}

canonical_original_code:
unsigned int flstory_mcu_status_r(unsigned int offset)
{
 int res = 0;
 if (!main_sent) res |= 0x01;
 if (mcu_sent) res |= 0x02;
 return res;
}

variable_types: res int


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

result = *(_QWORD *)(Machine + 824LL);
if ( *(_DWORD *)(result + 700) )
{
result = 0LL;
do
{
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
++result;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 700LL) > (unsigned int)result );
}
return result;
}

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

result = *(_QWORD *)(Machine + 824LL);
if ( *(_DWORD *)(result + 700) )
{
result = 0LL;
do
{
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
++result;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 700LL) > (unsigned int)result );
}
return result;
}

original_code:
void flstory_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->color_table_len;i++)
  colortable[i] = i ^ 0x0f;
}

canonical_original_code:
void flstory_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->color_table_len;i++)
  colortable[i] = i ^ 0x0f;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall flstory_gfxctrl_w(__int64 a1, unsigned int a2)
{
palette_bank = (a2 >> 5) & 1;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, unsigned int a2)
{
palette_bank = (a2 >> 5) & 1;
}

original_code:
void flstory_gfxctrl_w(offs_t offset,data_t data)
{
 palette_bank = (data & 0x20) >> 5;
}

canonical_original_code:
void flstory_gfxctrl_w(unsigned int offset, unsigned int data)
{
 palette_bank = (data & 0x20) >> 5;
}


decompiled_code:
__int64 flstory_d401_r()
{
return 2 * (unsigned int)(d400 != 239) + 1;
}

original_code:
static data_t flstory_d401_r(offs_t offset)
{
 if (d400 == 0xef)
  return 0x01;
 else
  return 0x03;
}

canonical_original_code:
static unsigned int flstory_d401_r(unsigned int offset)
{
 if (d400 == 0xef)
  return 0x01;
 else
  return 0x03;
}


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

if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
portA_in = from_main;
if ( main_sent )
cpu_set_irq_line(2LL, 0LL, 0LL);
main_sent = 0;
result = logerror("read command %02x from main cpu\n", (unsigned __int8)portA_in);
}
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
{
logerror("send command %02x to main cpu\n", (unsigned __int8)portA_out);
result = (unsigned __int8)portA_out;
from_mcu = portA_out;
mcu_sent = 1;
}
portB_out = a2;
return result;
}

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

if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
portA_in = from_main;
if ( main_sent )
cpu_set_irq_line(2LL, 0LL, 0LL);
main_sent = 0;
result = logerror("read command %02x from main cpu\n", (unsigned __int8)portA_in);
}
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
{
logerror("send command %02x to main cpu\n", (unsigned __int8)portA_out);
result = (unsigned __int8)portA_out;
from_mcu = portA_out;
mcu_sent = 1;
}
portB_out = a2;
return result;
}

original_code:
void flstory_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
 {
  portA_in = from_main;
  if (main_sent) cpu_set_irq_line(2,0,0);
  main_sent = 0;
logerror("read command %02x from main cpu\n",portA_in);
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
logerror("send command %02x to main cpu\n",portA_out);
  from_mcu = portA_out;
  mcu_sent = 1;
 }
 portB_out = data;
}

canonical_original_code:
void flstory_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
 {
  portA_in = from_main;
  if (main_sent) cpu_set_irq_line(2,0,0);
  main_sent = 0;
logerror("read command %02x from main cpu\n",portA_in);
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
logerror("send command %02x to main cpu\n",portA_out);
  from_mcu = portA_out;
  mcu_sent = 1;
 }
 portB_out = data;
}


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

v2 = cpu_get_pc();
result = logerror("%04x: 68705 port C write %02x\n", v2, a2);
portC_out = a2;
return result;
}

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

v2 = cpu_get_pc();
result = logerror("%04x: 68705 port C write %02x\n", v2, a2);
portC_out = a2;
return result;
}

original_code:
void flstory_68705_portC_w(offs_t offset,data_t data)
{
logerror("%04x: 68705 port C write %02x\n",cpu_get_pc(),data);
 portC_out = data;
}

canonical_original_code:
void flstory_68705_portC_w(unsigned int offset, unsigned int data)
{
logerror("%04x: 68705 port C write %02x\n",cpu_get_pc(),data);
 portC_out = data;
}


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

v2 = cpu_get_pc();
logerror("%04x: mcu_w %02x\n", v2, a2);
from_main = a2;
main_sent = 1;
return cpu_set_irq_line(2LL, 0LL, 1LL);
}

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

v2 = cpu_get_pc();
logerror("%04x: mcu_w %02x\n", v2, a2);
from_main = a2;
main_sent = 1;
return cpu_set_irq_line(2LL, 0LL, 1LL);
}

original_code:
void flstory_mcu_w(offs_t offset,data_t data)
{
logerror("%04x: mcu_w %02x\n",cpu_get_pc(),data);
 from_main = data;
 main_sent = 1;
 cpu_set_irq_line(2,0,1);
}

canonical_original_code:
void flstory_mcu_w(unsigned int offset, unsigned int data)
{
logerror("%04x: mcu_w %02x\n",cpu_get_pc(),data);
 from_main = data;
 main_sent = 1;
 cpu_set_irq_line(2,0,1);
}


decompiled_code:
__int64 flstory_mcu_r()
{
unsigned int v0; // ebx
unsigned int v1; // eax

v0 = (unsigned __int8)from_mcu;
v1 = cpu_get_pc();
logerror("%04x: mcu_r %02x\n", v1, v0);
mcu_sent = 0;
return (unsigned __int8)from_mcu;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // ebx
unsigned int v1; // eax

v0 = (unsigned __int8)from_mcu;
v1 = cpu_get_pc();
logerror("%04x: mcu_r %02x\n", v1, v0);
mcu_sent = 0;
return (unsigned __int8)from_mcu;
}

original_code:
data_t flstory_mcu_r(offs_t offset)
{
logerror("%04x: mcu_r %02x\n",cpu_get_pc(),from_mcu);
 mcu_sent = 0;
 return from_mcu;
}

canonical_original_code:
unsigned int flstory_mcu_r(unsigned int offset)
{
logerror("%04x: mcu_r %02x\n",cpu_get_pc(),from_mcu);
 mcu_sent = 0;
 return from_mcu;
}


decompiled_code:
__int64 flstory_vh_start()
{
paletteram = malloc(0x200uLL);
paletteram_2 = malloc(0x200uLL);
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func15()
{
paletteram = malloc(0x200uLL);
paletteram_2 = malloc(0x200uLL);
return generic_vh_start();
}

original_code:
int flstory_vh_start(void)
{
 paletteram = (unsigned char*)malloc(0x200);
 paletteram_2 = (unsigned char*)malloc(0x200);
 return generic_vh_start();
}

canonical_original_code:
int flstory_vh_start()
{
 paletteram = (unsigned char *)malloc(0x200);
 paletteram_2 = (unsigned char *)malloc(0x200);
 return generic_vh_start();
}

return_type: int


decompiled_code:
__int64 flstory_vh_stop()
{
free(paletteram);
paletteram = 0LL;
free(paletteram_2);
paletteram_2 = 0LL;
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func16()
{
free(paletteram);
paletteram = 0LL;
free(paletteram_2);
paletteram_2 = 0LL;
return generic_vh_stop();
}

original_code:
void flstory_vh_stop(void)
{
 free(paletteram);
 paletteram = 0;
 free(paletteram_2);
 paletteram_2 = 0;
 generic_vh_stop();
}

canonical_original_code:
void flstory_vh_stop()
{
 free(paletteram);
 paletteram = 0;
 free(paletteram_2);
 paletteram_2 = 0;
 generic_vh_stop();
}


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

if ( (a1 & 0x100) != 0 )
result = paletteram_xxxxBBBBGGGGRRRR_split2_w((palette_bank << 8) + (unsigned int)(unsigned __int8)a1);
else
result = paletteram_xxxxBBBBGGGGRRRR_split1_w((palette_bank << 8) + (unsigned int)(unsigned __int8)a1);
return result;
}

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

if ( (a1 & 0x100) != 0 )
result = paletteram_xxxxBBBBGGGGRRRR_split2_w((palette_bank << 8) + (unsigned int)(unsigned __int8)a1);
else
result = paletteram_xxxxBBBBGGGGRRRR_split1_w((palette_bank << 8) + (unsigned int)(unsigned __int8)a1);
return result;
}

original_code:
void flstory_palette_w(offs_t offset,data_t data)
{
 if (offset & 0x100)
  paletteram_xxxxBBBBGGGGRRRR_split2_w((offset & 0xff) + (palette_bank << 8),data);
 else
  paletteram_xxxxBBBBGGGGRRRR_split1_w((offset & 0xff) + (palette_bank << 8),data);
}

canonical_original_code:
void flstory_palette_w(unsigned int offset, unsigned int data)
{
 if (offset & 0x100)
  paletteram_xxxxBBBBGGGGRRRR_split2_w((offset & 0xff) + (palette_bank << 8),data);
 else
  paletteram_xxxxBBBBGGGGRRRR_split1_w((offset & 0xff) + (palette_bank << 8),data);
}


decompiled_code:
size_t *__fastcall flstory_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
_BYTE *v3; // rcx
unsigned __int64 v4; // rbx
int v5; // er12
__int64 v6; // rbp
unsigned int v7; // er13
unsigned int v8; // er14
size_t *result; // rax
int v10; // ebx
__int64 v11; // rbp
__int16 v12; // r8
unsigned int v13; // [rsp+Ch] [rbp-3Ch]

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1 + 1LL;
do
{
v3 = (char *)dirtybuffer + v2 - 1;
if ( *v3 || *((_BYTE *)dirtybuffer + v2) )
{
*v3 = 0;
*((_BYTE *)dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2 - 1) + ((4 * *(unsigned __int8 *)(videoram + v2)) & 0x300u) + 3072,
*(_BYTE *)(videoram + v2) & 7,
*(_BYTE *)(videoram + v2) & 8,
1LL,
8
* (((((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 27) + (unsigned __int8)(v1 / 2)) & 0x1F)
- ((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 27)),
(unsigned int)(8 * (v1 / 64)),
Machine + 776LL,
0LL,
0LL);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v4 = 0LL;
do
{
v5 = *(unsigned __int8 *)(spriteram + v4 + 3);
v6 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v4);
v7 = *(_BYTE *)(spriteram + v4 + 1) & 0x40;
v8 = *(_BYTE *)(spriteram + v4 + 1) & 0x80;
v13 = *(unsigned __int8 *)(spriteram + v4 + 2) + ((16 * *(unsigned __int8 *)(spriteram + v4 + 1)) & 0x300);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
*(_BYTE *)(spriteram + v4 + 1) & 0xF,
*(_BYTE *)(spriteram + v4 + 1) & 0x40,
*(_BYTE *)(spriteram + v4 + 1) & 0x80,
*(unsigned __int8 *)(spriteram + v4 + 3),
v6,
Machine + 776LL,
2LL,
0LL);
if ( v5 > 240 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
*(_BYTE *)(spriteram + v4 + 1) & 0xF,
v7,
v8,
(unsigned int)(v5 - 256),
v6,
Machine + 776LL,
2LL,
0LL);
v4 += 4LL;
}
while ( spriteram_size > v4 );
}
result = &videoram_size;
v10 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v11 = v10 + 1LL;
do
{
result = (size_t *)videoram;
v12 = *(unsigned __int8 *)(videoram + v11);
if ( (v12 & 0x20) != 0 )
result = (size_t *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v11 - 1) + ((4 * v12) & 0x300u) + 3072,
v12 & 7,
v12 & 8,
1LL,
8
* (((((unsigned int)((int)(v10 + ((unsigned int)v10 >> 31)) >> 31) >> 27)
+ (unsigned __int8)(v10 / 2)) & 0x1F)
- ((unsigned int)((int)(v10 + ((unsigned int)v10 >> 31)) >> 31) >> 27)),
(unsigned int)(8 * (v10 / 64)),
Machine + 776LL,
2LL,
0LL);
v11 -= 2LL;
v10 -= 2;
}
while ( v10 >= 0 );
}
return result;
}

canonical_decompiled_code:
size_t *__fastcall func18(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
_BYTE *v3; // rcx
unsigned __int64 v4; // rbx
int v5; // er12
__int64 v6; // rbp
unsigned int v7; // er13
unsigned int v8; // er14
size_t *result; // rax
int v10; // ebx
__int64 v11; // rbp
__int16 v12; // r8
unsigned int v13; // [rsp+Ch] [rbp-3Ch]

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1 + 1LL;
do
{
v3 = (char *)dirtybuffer + v2 - 1;
if ( *v3 || *((_BYTE *)dirtybuffer + v2) )
{
*v3 = 0;
*((_BYTE *)dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2 - 1) + ((4 * *(unsigned __int8 *)(videoram + v2)) & 0x300u) + 3072,
*(_BYTE *)(videoram + v2) & 7,
*(_BYTE *)(videoram + v2) & 8,
1LL,
8
* (((((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 27) + (unsigned __int8)(v1 / 2)) & 0x1F)
- ((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 27)),
(unsigned int)(8 * (v1 / 64)),
Machine + 776LL,
0LL,
0LL);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v4 = 0LL;
do
{
v5 = *(unsigned __int8 *)(spriteram + v4 + 3);
v6 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v4);
v7 = *(_BYTE *)(spriteram + v4 + 1) & 0x40;
v8 = *(_BYTE *)(spriteram + v4 + 1) & 0x80;
v13 = *(unsigned __int8 *)(spriteram + v4 + 2) + ((16 * *(unsigned __int8 *)(spriteram + v4 + 1)) & 0x300);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
*(_BYTE *)(spriteram + v4 + 1) & 0xF,
*(_BYTE *)(spriteram + v4 + 1) & 0x40,
*(_BYTE *)(spriteram + v4 + 1) & 0x80,
*(unsigned __int8 *)(spriteram + v4 + 3),
v6,
Machine + 776LL,
2LL,
0LL);
if ( v5 > 240 )
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
*(_BYTE *)(spriteram + v4 + 1) & 0xF,
v7,
v8,
(unsigned int)(v5 - 256),
v6,
Machine + 776LL,
2LL,
0LL);
v4 += 4LL;
}
while ( spriteram_size > v4 );
}
result = &videoram_size;
v10 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v11 = v10 + 1LL;
do
{
result = (size_t *)videoram;
v12 = *(unsigned __int8 *)(videoram + v11);
if ( (v12 & 0x20) != 0 )
result = (size_t *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v11 - 1) + ((4 * v12) & 0x300u) + 3072,
v12 & 7,
v12 & 8,
1LL,
8
* (((((unsigned int)((int)(v10 + ((unsigned int)v10 >> 31)) >> 31) >> 27)
+ (unsigned __int8)(v10 / 2)) & 0x1F)
- ((unsigned int)((int)(v10 + ((unsigned int)v10 >> 31)) >> 31) >> 27)),
(unsigned int)(8 * (v10 / 64)),
Machine + 776LL,
2LL,
0LL);
v11 -= 2LL;
v10 -= 2;
}
while ( v10 >= 0 );
}
return result;
}

original_code:
void flstory_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs+1] = 0;
   sx = (offs/2)%32;
   sy = (offs/2)/32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs + 1] & 0xc0) << 2) + 0xc00,
     videoram[offs + 1] & 0x07,
     videoram[offs + 1] & 0x08,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 = 0;offs < spriteram_size;offs += 4)
 {
  int code,sx,sy,flipx,flipy;
  code = spriteram[offs+2] + ((spriteram[offs+1] & 0x30) << 4);
  sx = spriteram[offs+3];
  sy = 240 - spriteram[offs+0];
  flipx = spriteram[offs+1]&0x40;
  flipy = spriteram[offs+1]&0x80;
  drawgfx(bitmap,Machine->gfx[1],
    code,
    spriteram[offs+1] & 0x0f,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  if (sx > 240)
   drawgfx(bitmap,Machine->gfx[1],
     code,
     spriteram[offs+1] & 0x0f,
     flipx,flipy,
     sx-256,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (videoram[offs + 1] & 0x20)
  {
   int sx,sy;
   sx = (offs/2)%32;
   sy = (offs/2)/32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs + 1] & 0xc0) << 2) + 0xc00,
     videoram[offs + 1] & 0x07,
     videoram[offs + 1] & 0x08,1,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
void flstory_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs+1] = 0;
   sx = (offs/2)%32;
   sy = (offs/2)/32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs + 1] & 0xc0) << 2) + 0xc00,
     videoram[offs + 1] & 0x07,
     videoram[offs + 1] & 0x08,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 = 0;offs < spriteram_size;offs += 4)
 {
  int code; int sx; int sy; int flipx; int flipy;
  code = spriteram[offs+2] + ((spriteram[offs+1] & 0x30) << 4);
  sx = spriteram[offs+3];
  sy = 240 - spriteram[offs+0];
  flipx = spriteram[offs+1]&0x40;
  flipy = spriteram[offs+1]&0x80;
  drawgfx(bitmap,Machine->gfx[1],
    code,
    spriteram[offs+1] & 0x0f,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  if (sx > 240)
   drawgfx(bitmap,Machine->gfx[1],
     code,
     spriteram[offs+1] & 0x0f,
     flipx,flipy,
     sx-256,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 2;offs >= 0;offs -= 2)
 {
  if (videoram[offs + 1] & 0x20)
  {
   int sx; int sy;
   sx = (offs/2)%32;
   sy = (offs/2)/32;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs + 1] & 0xc0) << 2) + 0xc00,
     videoram[offs + 1] & 0x07,
     videoram[offs + 1] & 0x08,1,
     8*sx,8*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: code int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 __fastcall sound_command_w(__int64 a1, unsigned int a2)
{
d400 = a2;
soundlatch_w(0LL);
cpu_cause_interrupt(1LL, 4294967294LL);
return logerror("sound command %02x\n", a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2)
{
d400 = a2;
soundlatch_w(0LL);
cpu_cause_interrupt(1LL, 4294967294LL);
return logerror("sound command %02x\n", a2);
}

original_code:
static void sound_command_w(offs_t offset,data_t data)
{
 d400 = data;
 soundlatch_w(0,data);
 cpu_cause_interrupt(1,-2);
logerror("sound command %02x\n",data);
}

canonical_original_code:
static void sound_command_w(unsigned int offset, unsigned int data)
{
 d400 = data;
 soundlatch_w(0,data);
 cpu_cause_interrupt(1,-2);
logerror("sound command %02x\n",data);
}


decompiled_code:
__int64 KDAC_A_make_fncode()
{
float *v0; // rsi
int v1; // ecx
__int64 result; // rax

v0 = (float *)&fncode;
v1 = 512;
do
{
result = (unsigned int)(28160 / v1);
*v0++ = (float)(int)result;
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
float *v0; // rsi
int v1; // ecx
__int64 result; // rax

v0 = (float *)&fncode;
v1 = 512;
do
{
result = (unsigned int)(28160 / v1);
*v0++ = (float)(int)result;
--v1;
}
while ( v1 );
return result;
}

original_code:
static void KDAC_A_make_fncode( void ){
  int i;
  for( i = 0; i < 0x200; i++ ){
    fncode[i] = (0x200 * 55) / (0x200 - i);
  }
}

canonical_original_code:
static void KDAC_A_make_fncode(){
  int i;
  for( i = 0; i < 0x200; i++ ){
    fncode[i] = (0x200 * 55) / (0x200 - i);
  }
}


original_code:
static int K007232_ReadReg( int r, int chip )
{
 if (r == 0x05)
 {
  if (kpcm[chip].start[0] < 0x20000)
  {
   kpcm[chip].play[0] = 1;
   kpcm[chip].addr[0] = 0;
  }
 }
 else if (r == 0x0b)
 {
  if (kpcm[chip].start[1] < 0x20000)
  {
   kpcm[chip].play[1] = 1;
   kpcm[chip].addr[1] = 0;
  }
 }
 return 0;
}

canonical_original_code:
static int K007232_ReadReg(int r, int chip)
{
 if (r == 0x05)
 {
  if (kpcm[chip].start[0] < 0x20000)
  {
   kpcm[chip].play[0] = 1;
   kpcm[chip].addr[0] = 0;
  }
 }
 else if (r == 0x0b)
 {
  if (kpcm[chip].start[1] < 0x20000)
  {
   kpcm[chip].play[1] = 1;
   kpcm[chip].addr[1] = 0;
  }
 }
 return 0;
}

variable_types: r int

variable_types: chip int


original_code:
static void KDAC_A_update(int chip, INT16 **buffer, int buffer_len)
{
 int i;
 memset(buffer[0],0,buffer_len * sizeof(INT16));
 memset(buffer[1],0,buffer_len * sizeof(INT16));
 for( i = 0; i < (2); i++ )
 {
  if (kpcm[chip].play[i])
  {
   int volA,volB,j,out;
   unsigned int addr, old_addr;
   addr = kpcm[chip].start[i] + ((kpcm[chip].addr[i]>>(12))&0x000fffff);
   volA = 2 * kpcm[chip].vol[i][0];
   volB = 2 * kpcm[chip].vol[i][1];
   for( j = 0; j < buffer_len; j++ )
   {
    old_addr = addr;
    addr = kpcm[chip].start[i] + ((kpcm[chip].addr[i]>>(12))&0x000fffff);
    while (old_addr <= addr)
    {
     if (kpcm[chip].pcmbuf[i][old_addr] & 0x80)
     {
      if (kpcm[chip].loop[i])
      {
       addr = kpcm[chip].start[i];
       kpcm[chip].addr[i] = 0;
      }
      else
      {
       kpcm[chip].play[i] = 0;
      }
      break;
     }
     old_addr++;
    }
    if (kpcm[chip].play[i] == 0)
     break;
    kpcm[chip].addr[i] += kpcm[chip].step[i];
    out = (kpcm[chip].pcmbuf[i][addr] & 0x7f) - 0x40;
    buffer[0][j] += out * volA;
    buffer[1][j] += out * volB;
   }
  }
 }
}

canonical_original_code:
static void KDAC_A_update(int chip, short **buffer, int buffer_len)
{
 int i;
 memset(buffer[0],0,buffer_len * sizeof(INT16));
 memset(buffer[1],0,buffer_len * sizeof(INT16));
 for( i = 0; i < (2); i++ )
 {
  if (kpcm[chip].play[i])
  {
   int volA; int volB; int j; int out;
   unsigned int addr; unsigned int old_addr;
   addr = kpcm[chip].start[i] + ((kpcm[chip].addr[i]>>(12))&0x000fffff);
   volA = 2 * kpcm[chip].vol[i][0];
   volB = 2 * kpcm[chip].vol[i][1];
   for( j = 0; j < buffer_len; j++ )
   {
    old_addr = addr;
    addr = kpcm[chip].start[i] + ((kpcm[chip].addr[i]>>(12))&0x000fffff);
    while (old_addr <= addr)
    {
     if (kpcm[chip].pcmbuf[i][old_addr] & 0x80)
     {
      if (kpcm[chip].loop[i])
      {
       addr = kpcm[chip].start[i];
       kpcm[chip].addr[i] = 0;
      }
      else
      {
       kpcm[chip].play[i] = 0;
      }
      break;
     }
     old_addr++;
    }
    if (kpcm[chip].play[i] == 0)
     break;
    kpcm[chip].addr[i] += kpcm[chip].step[i];
    out = (kpcm[chip].pcmbuf[i][addr] & 0x7f) - 0x40;
    buffer[0][j] += out * volA;
    buffer[1][j] += out * volB;
   }
  }
 }
}

variable_types:
buffer
short **

variable_types: volA int

variable_types: volB int

variable_types: j int

variable_types: out int

variable_types:
addr
unsigned int


decompiled_code:
__int64 __fastcall K007232_WriteReg(int a1, unsigned int a2, int a3)
{
__int64 result; // rax
int v4; // ebx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // r8

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
v4 = a1;
if ( !fast_sound )
stream_update(pcm_chan[a3], 0LL);
v6 = 80LL * a3;
result = (__int64)&kpcm + v6;
*((_BYTE *)&kpcm + v6 + a1 + 44) = a2;
switch ( a1 )
{
case 5:
if ( *(_DWORD *)((char *)&kpcm + v6 + 12) <= 0x1FFFFu )
{
result = 4LL * a3;
v8 = 80LL * a3;
*(_DWORD *)((char *)&kpcm + v8 + 28) = 1;
*(_DWORD *)((char *)&kpcm + v8 + 4) = 0;
}
break;
case 11:
result = 80LL * a3;
if ( *(_DWORD *)((char *)&kpcm + result + 16) <= 0x1FFFFu )
{
result = 4LL * a3;
v9 = 80LL * a3;
*(_DWORD *)((char *)&kpcm + v9 + 32) = 1;
*(_DWORD *)((char *)&kpcm + v9 + 8) = 0;
}
break;
case 13:
result = 4LL * a3;
v10 = 80LL * a3;
*(_DWORD *)((char *)&kpcm + v10 + 36) = a2 & 1;
*(_DWORD *)((char *)&kpcm + v10 + 40) = a2 & 2;
return result;
case 12:
result = *(_QWORD *)(intf + 8LL * a3 + 32);
if ( result )
result = ((__int64 (__fastcall *)(_QWORD))result)(a2);
break;
default:
if ( a1 <= 5 )
{
result = 0LL;
if ( a1 > 1 )
{
LABEL_10:
if ( (unsigned int)(v4 - 2) <= 2 )
{
v7 = (int)result + 20LL * a3;
result = *((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 46) | (*((unsigned __int8 *)&kpcm
+ 80 * a3
+ 6 * (int)result
+ 47) << 8) | (*((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 48) << 16) & 0x10000u;
*((_DWORD *)&kpcm + v7 + 3) = result;
}
return result;
}
if ( a1 < 0 )
return result;
LODWORD(result) = 0;
}
else
{
v4 = a1 - 6;
result = 1LL;
if ( a1 - 6 > 1 )
goto LABEL_10;
}
v11 = (int)result + 20LL * a3 + 4;
result = (unsigned int)(int)(fncode[*((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 44) | (*((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 45) << 8) & 0x100]
/ 220.0
* (7850.0
/ (float)*(int *)(Machine + 836LL))
* 0.8949999809265137
* 4096.0);
*((_DWORD *)&kpcm + v11 + 1) = result;
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2, int a3)
{
__int64 result; // rax
int v4; // ebx
__int64 v6; // rcx
__int64 v7; // r8
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // r8

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
v4 = a1;
if ( !fast_sound )
stream_update(pcm_chan[a3], 0LL);
v6 = 80LL * a3;
result = (__int64)&kpcm + v6;
*((_BYTE *)&kpcm + v6 + a1 + 44) = a2;
switch ( a1 )
{
case 5:
if ( *(_DWORD *)((char *)&kpcm + v6 + 12) <= 0x1FFFFu )
{
result = 4LL * a3;
v8 = 80LL * a3;
*(_DWORD *)((char *)&kpcm + v8 + 28) = 1;
*(_DWORD *)((char *)&kpcm + v8 + 4) = 0;
}
break;
case 11:
result = 80LL * a3;
if ( *(_DWORD *)((char *)&kpcm + result + 16) <= 0x1FFFFu )
{
result = 4LL * a3;
v9 = 80LL * a3;
*(_DWORD *)((char *)&kpcm + v9 + 32) = 1;
*(_DWORD *)((char *)&kpcm + v9 + 8) = 0;
}
break;
case 13:
result = 4LL * a3;
v10 = 80LL * a3;
*(_DWORD *)((char *)&kpcm + v10 + 36) = a2 & 1;
*(_DWORD *)((char *)&kpcm + v10 + 40) = a2 & 2;
return result;
case 12:
result = *(_QWORD *)(intf + 8LL * a3 + 32);
if ( result )
result = ((__int64 (__fastcall *)(_QWORD))result)(a2);
break;
default:
if ( a1 <= 5 )
{
result = 0LL;
if ( a1 > 1 )
{
LABEL_10:
if ( (unsigned int)(v4 - 2) <= 2 )
{
v7 = (int)result + 20LL * a3;
result = *((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 46) | (*((unsigned __int8 *)&kpcm
+ 80 * a3
+ 6 * (int)result
+ 47) << 8) | (*((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 48) << 16) & 0x10000u;
*((_DWORD *)&kpcm + v7 + 3) = result;
}
return result;
}
if ( a1 < 0 )
return result;
LODWORD(result) = 0;
}
else
{
v4 = a1 - 6;
result = 1LL;
if ( a1 - 6 > 1 )
goto LABEL_10;
}
v11 = (int)result + 20LL * a3 + 4;
result = (unsigned int)(int)(fncode[*((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 44) | (*((unsigned __int8 *)&kpcm + 80 * a3 + 6 * (int)result + 45) << 8) & 0x100]
/ 220.0
* (7850.0
/ (float)*(int *)(Machine + 836LL))
* 0.8949999809265137
* 4096.0);
*((_DWORD *)&kpcm + v11 + 1) = result;
return result;
}
}
return result;
}

original_code:
static void K007232_WriteReg( int r, int v, int chip )
{
 int data;
 if (Machine->sample_rate == 0) return;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(pcm_chan[chip],0);
    }
 kpcm[chip].wreg[r] = v;
 if (r == 0x05)
 {
  if (kpcm[chip].start[0] < 0x20000)
  {
   kpcm[chip].play[0] = 1;
   kpcm[chip].addr[0] = 0;
  }
 }
 else if (r == 0x0b)
 {
  if (kpcm[chip].start[1] < 0x20000)
  {
   kpcm[chip].play[1] = 1;
   kpcm[chip].addr[1] = 0;
  }
 }
 else if (r == 0x0d)
 {
  kpcm[chip].loop[0] = v & 0x01;
  kpcm[chip].loop[1] = v & 0x02;
  return;
 }
 else if (r == 0x0c)
 {
  if (intf->portwritehandler[chip]) (*intf->portwritehandler[chip])(v);
  return;
 }
 else
 {
  int reg_port;
  reg_port = 0;
  if (r >= 0x06)
  {
   reg_port = 1;
   r -= 0x06;
  }
  switch (r)
  {
   case 0x00:
   case 0x01:
    data = (((((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x01])<<8)&0x0100) | (((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x00])&0x00ff));
    kpcm[chip].step[reg_port] =
     ( (7850.0 / (float)Machine->sample_rate) ) *
     ( fncode[data] / (440.00/2) ) *
     ( (float)3580000 / (float)4000000 ) *
     (1<<(12));
    break;
   case 0x02:
   case 0x03:
   case 0x04:
    kpcm[chip].start[reg_port] =
     ((((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x04]<<16)&0x00010000) |
     (((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x03]<< 8)&0x0000ff00) |
     (((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x02] )&0x000000ff));
   break;
  }
 }
}

canonical_original_code:
static void K007232_WriteReg(int r, int v, int chip)
{
 int data;
 if (Machine->sample_rate == 0) return;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(pcm_chan[chip],0);
    }
 kpcm[chip].wreg[r] = v;
 if (r == 0x05)
 {
  if (kpcm[chip].start[0] < 0x20000)
  {
   kpcm[chip].play[0] = 1;
   kpcm[chip].addr[0] = 0;
  }
 }
 else if (r == 0x0b)
 {
  if (kpcm[chip].start[1] < 0x20000)
  {
   kpcm[chip].play[1] = 1;
   kpcm[chip].addr[1] = 0;
  }
 }
 else if (r == 0x0d)
 {
  kpcm[chip].loop[0] = v & 0x01;
  kpcm[chip].loop[1] = v & 0x02;
  return;
 }
 else if (r == 0x0c)
 {
  if (intf->portwritehandler[chip]) (*intf->portwritehandler[chip])(v);
  return;
 }
 else
 {
  int reg_port;
  reg_port = 0;
  if (r >= 0x06)
  {
   reg_port = 1;
   r -= 0x06;
  }
  switch (r)
  {
   case 0x00:
   case 0x01:
    data = (((((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x01])<<8)&0x0100) | (((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x00])&0x00ff));
    kpcm[chip].step[reg_port] =
     ( (7850.0 / (float)Machine->sample_rate) ) *
     ( fncode[data] / (440.00/2) ) *
     ( (float)3580000 / (float)4000000 ) *
     (1<<(12));
    break;
   case 0x02:
   case 0x03:
   case 0x04:
    kpcm[chip].start[reg_port] =
     ((((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x04]<<16)&0x00010000) |
     (((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x03]<< 8)&0x0000ff00) |
     (((unsigned int)kpcm[chip].wreg[reg_port*0x06 + 0x02] )&0x000000ff));
   break;
  }
 }
}

variable_types: v int

variable_types: data int


original_code:
int K007232_sh_start(const struct MachineSound *msound)
{
 int i,j;
 intf = (const struct K007232_interface*)msound->sound_interface;
 for (j=0; j<intf->num_chips; j++)
 {
  char buf[2][40];
  const char *name[2];
  int vol[2];
  kpcm[j].pcmbuf[0] = (unsigned char *)memory_region(intf->bank[j]);
  kpcm[j].pcmbuf[1] = (unsigned char *)memory_region(intf->bank[j]);
  for( i = 0; i < (2); i++ )
  {
   kpcm[j].start[i] = 0;
   kpcm[j].step[i] = 0;
   kpcm[j].play[i] = 0;
   kpcm[j].loop[i] = 0;
  }
  kpcm[j].vol[0][0] = 255;
  kpcm[j].vol[0][1] = 0;
  kpcm[j].vol[1][0] = 0;
  kpcm[j].vol[1][1] = 255;
  for( i = 0; i < 0x10; i++ ) kpcm[j].wreg[i] = 0;
  for (i = 0;i < 2;i++)
  {
   name[i] = buf[i];
   sprintf(buf[i],"007232 #%d Ch %c",j,'A'+i);
  }
  vol[0]=intf->volume[j] & 0xffff;
  vol[1]=intf->volume[j] >> 16;
  pcm_chan[j] = stream_init_multi(2,name,vol,Machine->sample_rate,
    j,KDAC_A_update);
 }
 KDAC_A_make_fncode();
 return 0;
}

canonical_original_code:
int K007232_sh_start(struct MachineSound *msound)
{
 int i; int j;
 intf = (struct K007232_interface *)msound->sound_interface;
 for (j=0; j<intf->num_chips; j++)
 {
  char buf[2][40];
  char *name[2];
  int vol[2];
  kpcm[j].pcmbuf[0] = (unsigned char *)memory_region(intf->bank[j]);
  kpcm[j].pcmbuf[1] = (unsigned char *)memory_region(intf->bank[j]);
  for( i = 0; i < (2); i++ )
  {
   kpcm[j].start[i] = 0;
   kpcm[j].step[i] = 0;
   kpcm[j].play[i] = 0;
   kpcm[j].loop[i] = 0;
  }
  kpcm[j].vol[0][0] = 255;
  kpcm[j].vol[0][1] = 0;
  kpcm[j].vol[1][0] = 0;
  kpcm[j].vol[1][1] = 255;
  for( i = 0; i < 0x10; i++ ) kpcm[j].wreg[i] = 0;
  for (i = 0;i < 2;i++)
  {
   name[i] = buf[i];
   sprintf(buf[i],"007232 #%d Ch %c",j,'A'+i);
  }
  vol[0]=intf->volume[j] & 0xffff;
  vol[1]=intf->volume[j] >> 16;
  pcm_chan[j] = stream_init_multi(2,name,vol,Machine->sample_rate,
    j,KDAC_A_update);
 }
 KDAC_A_make_fncode();
 return 0;
}

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

variable_types: i int

variable_types:
buf
char [2][40]

variable_types:
name
char *[2]

variable_types:
vol
int [2]

user_defined_types: struct K007232_interface { int num_chips; int bank[3]; int volume[3]; void (*portwritehandler[3])(int); }


decompiled_code:
__int64 __fastcall K007232_write_port_0_w(int a1, unsigned int a2)
{
return K007232_WriteReg(a1, a2, 0);
}

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

original_code:
void K007232_write_port_0_w(offs_t offset,data_t data)
{
 K007232_WriteReg(offset,data,0);
}

canonical_original_code:
void K007232_write_port_0_w(unsigned int offset, unsigned int data)
{
 K007232_WriteReg(offset,data,0);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall K007232_read_port_0_r(int a1)
{
return K007232_ReadReg(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return func1(a1, 0);
}

original_code:
data_t K007232_read_port_0_r(offs_t offset)
{
 return K007232_ReadReg(offset,0);
}

canonical_original_code:
unsigned int K007232_read_port_0_r(unsigned int offset)
{
 return K007232_ReadReg(offset,0);
}


decompiled_code:
__int64 __fastcall K007232_write_port_1_w(int a1, unsigned int a2)
{
return K007232_WriteReg(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned int a2)
{
return func3(a1, a2, 1);
}

original_code:
void K007232_write_port_1_w(offs_t offset,data_t data)
{
 K007232_WriteReg(offset,data,1);
}

canonical_original_code:
void K007232_write_port_1_w(unsigned int offset, unsigned int data)
{
 K007232_WriteReg(offset,data,1);
}


decompiled_code:
__int64 __fastcall K007232_read_port_1_r(int a1)
{
return K007232_ReadReg(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return func1(a1, 1);
}

original_code:
data_t K007232_read_port_1_r(offs_t offset)
{
 return K007232_ReadReg(offset,1);
}

canonical_original_code:
unsigned int K007232_read_port_1_r(unsigned int offset)
{
 return K007232_ReadReg(offset,1);
}


decompiled_code:
__int64 __fastcall K007232_write_port_2_w(int a1, unsigned int a2)
{
return K007232_WriteReg(a1, a2, 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, unsigned int a2)
{
return func3(a1, a2, 2);
}

original_code:
void K007232_write_port_2_w(offs_t offset,data_t data)
{
 K007232_WriteReg(offset,data,2);
}

canonical_original_code:
void K007232_write_port_2_w(unsigned int offset, unsigned int data)
{
 K007232_WriteReg(offset,data,2);
}


decompiled_code:
__int64 __fastcall K007232_read_port_2_r(int a1)
{
return K007232_ReadReg(a1, 2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return func1(a1, 2);
}

original_code:
data_t K007232_read_port_2_r(offs_t offset)
{
 return K007232_ReadReg(offset,2);
}

canonical_original_code:
unsigned int K007232_read_port_2_r(unsigned int offset)
{
 return K007232_ReadReg(offset,2);
}


decompiled_code:
__int64 __fastcall K007232_bankswitch(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v6; // rdx

result = a1;
v6 = 80LL * a1;
*(_QWORD *)((char *)&kpcm + v6 + 64) = a2;
*(_QWORD *)((char *)&kpcm + v6 + 72) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v6; // rdx

result = a1;
v6 = 80LL * a1;
*(_QWORD *)((char *)&kpcm + v6 + 64) = a2;
*(_QWORD *)((char *)&kpcm + v6 + 72) = a3;
return result;
}

original_code:
void K007232_bankswitch(int chip,unsigned char *ptr_A,unsigned char *ptr_B)
{
 kpcm[chip].pcmbuf[0] = ptr_A;
 kpcm[chip].pcmbuf[1] = ptr_B;
}

canonical_original_code:
void K007232_bankswitch(int chip, unsigned char *ptr_A, unsigned char *ptr_B)
{
 kpcm[chip].pcmbuf[0] = ptr_A;
 kpcm[chip].pcmbuf[1] = ptr_B;
}


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

switch ( a1 )
{
case 2:
result = (unsigned int)m6840_status;
break;
case 4:
result = (unsigned int)m6840_timerMSB;
break;
case 6:
result = (unsigned int)m6840_timerLSB;
break;
case 8:
result = (unsigned int)dword_9A4;
break;
case 10:
result = (unsigned int)dword_9B4;
break;
case 12:
result = (unsigned int)dword_9A8;
break;
case 14:
result = (unsigned int)dword_9B8;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 2:
result = (unsigned int)m6840_status;
break;
case 4:
result = (unsigned int)m6840_timerMSB;
break;
case 6:
result = (unsigned int)m6840_timerLSB;
break;
case 8:
result = (unsigned int)dword_9A4;
break;
case 10:
result = (unsigned int)dword_9B4;
break;
case 12:
result = (unsigned int)dword_9A8;
break;
case 14:
result = (unsigned int)dword_9B8;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
data_t cchasm_6840_r(offs_t offset)
{
 switch (offset) {
  case 0x0:
   break;
  case 0x2:
   return m6840_status;
   break;
  case 0x4:
   return m6840_timerMSB[0];
  case 0x6:
   return m6840_timerLSB[0];
  case 0x8:
   return m6840_timerMSB[1];
  case 0xa:
   return m6840_timerLSB[1];
  case 0xc:
   return m6840_timerMSB[2];
  case 0xe:
   return m6840_timerLSB[2];
 }
 return 0;
}

canonical_original_code:
unsigned int cchasm_6840_r(unsigned int offset)
{
 switch (offset) {
  case 0x0:
   break;
  case 0x2:
   return m6840_status;
   break;
  case 0x4:
   return m6840_timerMSB[0];
  case 0x6:
   return m6840_timerLSB[0];
  case 0x8:
   return m6840_timerMSB[1];
  case 0xa:
   return m6840_timerLSB[1];
  case 0xc:
   return m6840_timerMSB[2];
  case 0xe:
   return m6840_timerLSB[2];
 }
 return 0;
}


decompiled_code:
void cchasm_watchdog_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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


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

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

original_code:
static void cchasm_6840_irq (int state)
{
    cpu_set_irq_line (0, 4, state);
}

canonical_original_code:
static void cchasm_6840_irq(int state)
{
    cpu_set_irq_line (0, 4, state);
}

variable_types: state int


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

switch ( a1 )
{
case 0:
result = (unsigned int)m6840_cr_select;
m6840_cr[m6840_cr_select] = a2;
if ( !(_DWORD)result && (a2 & 1) != 0 )
{
m6840_timerLSB = 255;
m6840_timerMSB = 255;
dword_9B4 = 255;
dword_9A4 = 255;
dword_9B8 = 255;
dword_9A8 = 255;
}
break;
case 2:
dword_994 = a2;
result = 2 * (unsigned int)((a2 & 1) == 0);
m6840_cr_select = 2 * ((a2 & 1) == 0);
break;
case 4:
m6840_timerMSB = a2;
m6840_status &= 0xFFFFFFFE;
break;
case 6:
m6840_status &= 0xFFFFFFFE;
m6840_timerLSB = a2;
break;
case 8:
m6840_status &= 0xFFFFFFFD;
result = cchasm_6840_irq(0);
dword_9A4 = a2;
if ( (dword_994 & 0x38) == 0 )
result = timer_set(1342 * (dword_9B4 | (a2 << 8)), 0LL, timer_2_timeout);
break;
case 10:
m6840_status &= 0xFFFFFFFD;
result = cchasm_6840_irq(0);
dword_9B4 = a2;
break;
case 12:
m6840_status &= 0xFFFFFFFB;
dword_9A8 = a2;
break;
case 14:
m6840_status &= 0xFFFFFFFB;
dword_9B8 = a2;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = (unsigned int)m6840_cr_select;
m6840_cr[m6840_cr_select] = a2;
if ( !(_DWORD)result && (a2 & 1) != 0 )
{
m6840_timerLSB = 255;
m6840_timerMSB = 255;
dword_9B4 = 255;
dword_9A4 = 255;
dword_9B8 = 255;
dword_9A8 = 255;
}
break;
case 2:
dword_994 = a2;
result = 2 * (unsigned int)((a2 & 1) == 0);
m6840_cr_select = 2 * ((a2 & 1) == 0);
break;
case 4:
m6840_timerMSB = a2;
m6840_status &= 0xFFFFFFFE;
break;
case 6:
m6840_status &= 0xFFFFFFFE;
m6840_timerLSB = a2;
break;
case 8:
m6840_status &= 0xFFFFFFFD;
result = func4(0);
dword_9A4 = a2;
if ( (dword_994 & 0x38) == 0 )
result = timer_set(1342 * (dword_9B4 | (a2 << 8)), 0LL, timer_2_timeout);
break;
case 10:
m6840_status &= 0xFFFFFFFD;
result = func4(0);
dword_9B4 = a2;
break;
case 12:
m6840_status &= 0xFFFFFFFB;
dword_9A8 = a2;
break;
case 14:
m6840_status &= 0xFFFFFFFB;
dword_9B8 = a2;
break;
default:
return result;
}
return result;
}

original_code:
void cchasm_6840_w(offs_t offset,data_t data)
{
 data &= 0xff;
 switch (offset) {
  case 0x0:
            m6840_cr[m6840_cr_select] = data;
   if (m6840_cr_select==0)
            {
    if ((data&0x1))
                {
     int i;
                    for (i=0; i<3; i++) {
                        m6840_timerLSB[i]=255;
                        m6840_timerMSB[i]=255;
                    }
                }
   }
   break;
  case 0x2:
            m6840_cr[1] = data;
   if (data&0x1)
            {
    m6840_cr_select=0;
   }
   else {
    m6840_cr_select=2;
   }
   break;
  case 0x4:
   m6840_timerMSB[0]=data;
            m6840_status &= ~0x01;
   break;
  case 0x6:
            m6840_status &= ~0x01;
   m6840_timerLSB[0]=data;
   break;
  case 0x8:
            m6840_status &= ~0x02;
            cchasm_6840_irq(0);
   m6840_timerMSB[1]=data;
            if ((m6840_cr[1] & 0x38) == 0)
                timer_set ((((INT64)(1250)*(INT64)((1<<30)))/(INT64)1000000000) * ((m6840_timerMSB[1]<<8) | m6840_timerLSB[1]), 0, timer_2_timeout);
   break;
  case 0xa:
            m6840_status &= ~0x02;
            cchasm_6840_irq(0);
   m6840_timerLSB[1]=data;
   break;
  case 0xc:
            m6840_status &= ~0x04;
   m6840_timerMSB[2]=data;
   break;
  case 0xe:
            m6840_status &= ~0x04;
   m6840_timerLSB[2]=data;
   break;
 }
}

canonical_original_code:
void cchasm_6840_w(unsigned int offset, unsigned int data)
{
 data &= 0xff;
 switch (offset) {
  case 0x0:
            m6840_cr[m6840_cr_select] = data;
   if (m6840_cr_select==0)
            {
    if ((data&0x1))
                {
     int i;
                    for (i=0; i<3; i++) {
                        m6840_timerLSB[i]=255;
                        m6840_timerMSB[i]=255;
                    }
                }
   }
   break;
  case 0x2:
            m6840_cr[1] = data;
   if (data&0x1)
            {
    m6840_cr_select=0;
   }
   else {
    m6840_cr_select=2;
   }
   break;
  case 0x4:
   m6840_timerMSB[0]=data;
            m6840_status &= ~0x01;
   break;
  case 0x6:
            m6840_status &= ~0x01;
   m6840_timerLSB[0]=data;
   break;
  case 0x8:
            m6840_status &= ~0x02;
            cchasm_6840_irq(0);
   m6840_timerMSB[1]=data;
            if ((m6840_cr[1] & 0x38) == 0)
                timer_set ((((INT64)(1250)*(INT64)((1<<30)))/(long long)1000000000) * ((m6840_timerMSB[1]<<8) | m6840_timerLSB[1]), 0, timer_2_timeout);
   break;
  case 0xa:
            m6840_status &= ~0x02;
            cchasm_6840_irq(0);
   m6840_timerLSB[1]=data;
   break;
  case 0xc:
            m6840_status &= ~0x04;
   m6840_timerMSB[2]=data;
   break;
  case 0xe:
            m6840_status &= ~0x04;
   m6840_timerLSB[2]=data;
   break;
 }
}


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

if ( (dword_994 & 0x40) != 0 )
{
m6840_status |= 0x82u;
result = cchasm_6840_irq(1u);
}
return result;
}

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

if ( (dword_994 & 0x40) != 0 )
{
m6840_status |= 0x82u;
result = func4(1u);
}
return result;
}

original_code:
static void timer_2_timeout (int dummy)
{
    if (m6840_cr[1] & 0x40)
    {
        m6840_status |= 0x82;
        cchasm_6840_irq(1);
    }
}

canonical_original_code:
static void timer_2_timeout(int dummy)
{
    if (m6840_cr[1] & 0x40)
    {
        m6840_status |= 0x82;
        cchasm_6840_irq(1);
    }
}

variable_types: dummy int


decompiled_code:
__int64 cchasm_refresh_end()
{
return cpu_set_irq_line(0LL, 2LL, 1LL);
}

canonical_decompiled_code:
__int64 func7()
{
return cpu_set_irq_line(0LL, 2LL, 1LL);
}

original_code:
static void cchasm_refresh_end (int dummy)
{
    cpu_set_irq_line (0, 2, 1);
}

canonical_original_code:
static void cchasm_refresh_end(int dummy)
{
    cpu_set_irq_line (0, 2, 1);
}


decompiled_code:
__int64 cchasm_refresh()
{
int v0; // esi
unsigned int v1; // er13
unsigned int v2; // er15
unsigned int v3; // er14
int v4; // ebp
unsigned __int16 v5; // dx
int v6; // ebx
int v8; // [rsp+4h] [rbp-44h]
int v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+Ch] [rbp-3Ch]

vector_clear_list();
v0 = 0;
v10 = 1;
v1 = 0;
v9 = 0;
v8 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = *(_WORD *)(cchasm_ram + v4);
v6 = v5 & 0xFFF;
if ( v5 > 0x2FFFu && (v5 & 0x800) != 0 )
v6 = *(_WORD *)(cchasm_ram + v4) & 0xFFF | 0xFFFFF000;
v4 += 2;
switch ( (int)v5 >> 12 )
{
case 1:
v4 = v6 - 2816;
break;
case 2:
v1 = ((v6 ^ 0xFFF) >> 2) & 3 | ((v6 ^ 0xFFF) >> 3) & 0x1C | ((v6 ^ 0xFFF) >> 4) & 0xE0;
break;
case 3:
v9 = 32 * v6;
break;
case 4:
v2 = ycenter + (v6 << 16);
v0 = 1;
break;
case 5:
v8 = 32 * v6;
break;
case 6:
v3 = xcenter - (v6 << 16);
v0 = 1;
break;
case 7:
if ( v0 )
vector_add_point(v3, v2, 0LL, 0LL);
v3 -= v6 * v8;
v2 += v6 * v9;
v10 += abs32(v6);
v0 = 1;
if ( v1 )
{
vector_add_point(v3, v2, v1, 255LL);
v0 = 0;
}
break;
default:
return timer_set((unsigned int)(178 * v10), 0LL, cchasm_refresh_end);
}
}
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // esi
unsigned int v1; // er13
unsigned int v2; // er15
unsigned int v3; // er14
int v4; // ebp
unsigned __int16 v5; // dx
int v6; // ebx
int v8; // [rsp+4h] [rbp-44h]
int v9; // [rsp+8h] [rbp-40h]
int v10; // [rsp+Ch] [rbp-3Ch]

vector_clear_list();
v0 = 0;
v10 = 1;
v1 = 0;
v9 = 0;
v8 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = *(_WORD *)(cchasm_ram + v4);
v6 = v5 & 0xFFF;
if ( v5 > 0x2FFFu && (v5 & 0x800) != 0 )
v6 = *(_WORD *)(cchasm_ram + v4) & 0xFFF | 0xFFFFF000;
v4 += 2;
switch ( (int)v5 >> 12 )
{
case 1:
v4 = v6 - 2816;
break;
case 2:
v1 = ((v6 ^ 0xFFF) >> 2) & 3 | ((v6 ^ 0xFFF) >> 3) & 0x1C | ((v6 ^ 0xFFF) >> 4) & 0xE0;
break;
case 3:
v9 = 32 * v6;
break;
case 4:
v2 = ycenter + (v6 << 16);
v0 = 1;
break;
case 5:
v8 = 32 * v6;
break;
case 6:
v3 = xcenter - (v6 << 16);
v0 = 1;
break;
case 7:
if ( v0 )
vector_add_point(v3, v2, 0LL, 0LL);
v3 -= v6 * v8;
v2 += v6 * v9;
v10 += abs32(v6);
v0 = 1;
if ( v1 )
{
vector_add_point(v3, v2, v1, 255LL);
v0 = 0;
}
break;
default:
return timer_set((unsigned int)(178 * v10), 0LL, cchasm_refresh_end);
}
}
}

original_code:
static void cchasm_refresh (void)
{
 int pc = 0;
    int done = 0;
    int opcode, data;
    int currentx = 0, currenty = 0;
    int scalex = 0, scaley = 0;
    int color = 0;
    int total_length = 1;
    int move = 0;
 vector_clear_list();
 while (!done)
 {
        data = (*(UINT16 *)(&cchasm_ram[pc]));
     opcode = data >> 12;
        data &= 0xfff;
        if ((opcode > 2) && (data & 0x800))
          data |= 0xfffff000;
  pc += 2;
  switch (opcode)
  {
        case 0:
            done=1;
            break;
        case 1:
            pc = data - 0xb00;
            break;
        case 2:
            data = data ^ 0xfff;
            color = ((data >> 4) & 0xe0) | ((data >> 3 ) &0x1c) | ((data >> 2 ) &0x3);
            break;
        case 3:
            scaley = data << 5;
            break;
        case 4:
            move = 1;
            currenty = ycenter + (data << 16);
            break;
        case 5:
            scalex = data << 5;
            break;
        case 6:
            move = 1;
            currentx = xcenter - (data << 16);
            break;
        case 7:
            if (move)
            {
                vector_add_point (currentx, currenty, 0, 0);
                move = 0;
            }
            currentx -= data * scalex;
            currenty += data * scaley;
            total_length += abs(data);
            if (color)
                vector_add_point (currentx, currenty, color, 0xff);
            else
                move = 1;
            break;
        default:
            done = 1;
            break;
  }
 }
    timer_set ((((INT64)(166)*(INT64)((1<<30)))/(INT64)1000000000) * total_length, 0, cchasm_refresh_end);
}

canonical_original_code:
static void cchasm_refresh()
{
 int pc = 0;
    int done = 0;
    int opcode; int data;
    int currentx = 0; int currenty = 0;
    int scalex = 0; int scaley = 0;
    int color = 0;
    int total_length = 1;
    int move = 0;
 vector_clear_list();
 while (!done)
 {
        data = (*(unsigned short *)(&cchasm_ram[pc]));
     opcode = data >> 12;
        data &= 0xfff;
        if ((opcode > 2) && (data & 0x800))
          data |= 0xfffff000;
  pc += 2;
  switch (opcode)
  {
        case 0:
            done=1;
            break;
        case 1:
            pc = data - 0xb00;
            break;
        case 2:
            data = data ^ 0xfff;
            color = ((data >> 4) & 0xe0) | ((data >> 3 ) &0x1c) | ((data >> 2 ) &0x3);
            break;
        case 3:
            scaley = data << 5;
            break;
        case 4:
            move = 1;
            currenty = ycenter + (data << 16);
            break;
        case 5:
            scalex = data << 5;
            break;
        case 6:
            move = 1;
            currentx = xcenter - (data << 16);
            break;
        case 7:
            if (move)
            {
                vector_add_point (currentx, currenty, 0, 0);
                move = 0;
            }
            currentx -= data * scalex;
            currenty += data * scaley;
            total_length += abs(data);
            if (color)
                vector_add_point (currentx, currenty, color, 0xff);
            else
                move = 1;
            break;
        default:
            done = 1;
            break;
  }
 }
    timer_set ((((INT64)(166)*(INT64)((1<<30)))/(long long)1000000000) * total_length, 0, cchasm_refresh_end);
}

variable_types: pc int

variable_types: done int

variable_types: opcode int

variable_types: currentx int

variable_types: currenty int

variable_types: scalex int

variable_types: scaley int

variable_types: color int

variable_types: move int


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

if ( a2 == 14335 )
return cchasm_refresh();
if ( a2 == 63487 )
result = cpu_set_irq_line(0LL, 2LL, 0LL);
return result;
}

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

if ( a2 == 14335 )
return func8();
if ( a2 == 63487 )
result = cpu_set_irq_line(0LL, 2LL, 0LL);
return result;
}

original_code:
void cchasm_refresh_control_w(offs_t offset,data_t data)
{
    switch (data)
    {
    case 0x37ff:
        cchasm_refresh();
        break;
    case 0xf7ff:
        cpu_set_irq_line (0, 2, 0);
        break;
    }
}

canonical_original_code:
void cchasm_refresh_control_w(unsigned int offset, unsigned int data)
{
    switch (data)
    {
    case 0x37ff:
        cchasm_refresh();
        break;
    case 0xf7ff:
        cpu_set_irq_line (0, 2, 0);
        break;
    }
}


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

v0 = *(_DWORD *)(Machine + 788LL);
xcenter = ((*(_DWORD *)(Machine + 776LL) + *(_DWORD *)(Machine + 780LL)) / 2) << 16;
ycenter = ((*(_DWORD *)(Machine + 784LL) + v0) / 2) << 16;
vector_set_shift(16LL);
return vector_vh_start();
}

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

v0 = *(_DWORD *)(Machine + 788LL);
xcenter = ((*(_DWORD *)(Machine + 776LL) + *(_DWORD *)(Machine + 780LL)) / 2) << 16;
ycenter = ((*(_DWORD *)(Machine + 784LL) + v0) / 2) << 16;
vector_set_shift(16LL);
return vector_vh_start();
}

original_code:
int cchasm_vh_start (void)
{
    int xmin, xmax, ymin, ymax;
 xmin=Machine->visible_area.min_x;
 ymin=Machine->visible_area.min_y;
 xmax=Machine->visible_area.max_x;
 ymax=Machine->visible_area.max_y;
 xcenter=((xmax+xmin)/2) << 16;
 ycenter=((ymax+ymin)/2) << 16;
 vector_set_shift (16);
 return vector_vh_start();
}

canonical_original_code:
int cchasm_vh_start()
{
    int xmin; int xmax; int ymin; int ymax;
 xmin=Machine->visible_area.min_x;
 ymin=Machine->visible_area.min_y;
 xmax=Machine->visible_area.max_x;
 ymax=Machine->visible_area.max_y;
 xcenter=((xmax+xmin)/2) << 16;
 ycenter=((ymax+ymin)/2) << 16;
 vector_set_shift (16);
 return vector_vh_start();
}

variable_types: xmin int

variable_types: xmax int

variable_types: ymin int

variable_types: ymax int


decompiled_code:
__int64 cchasm_vh_stop()
{
return vector_vh_stop();
}

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

original_code:
void cchasm_vh_stop (void)
{
 vector_vh_stop();
}

canonical_original_code:
void cchasm_vh_stop()
{
 vector_vh_stop();
}


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

v1 = a1 & 0x61;
if ( v1 == 33 )
return AY8910_read_port_1_r();
if ( v1 <= 0x21 )
{
if ( (a1 & 0x61) != 0 )
{
if ( v1 == 1 )
result = AY8910_read_port_0_r();
else
result = 0LL;
}
else
{
v3 = ((unsigned int)input_port_3_r() >> 4) & 7;
if ( v3 != 7 )
v3 |= 8u;
result = sound_flags | v3;
}
}
else if ( v1 == 64 )
{
result = (unsigned __int8)sound_command;
}
else if ( v1 == 65 )
{
sound_flags &= 0xFFFFFF7F;
z80ctc_0_trg2_w(0LL, 0LL);
result = (unsigned __int8)dword_97C;
}
else
{
result = 0LL;
}
return result;
}

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

v1 = a1 & 0x61;
if ( v1 == 33 )
return AY8910_read_port_1_r();
if ( v1 <= 0x21 )
{
if ( (a1 & 0x61) != 0 )
{
if ( v1 == 1 )
result = AY8910_read_port_0_r();
else
result = 0LL;
}
else
{
v3 = ((unsigned int)input_port_3_r() >> 4) & 7;
if ( v3 != 7 )
v3 |= 8u;
result = sound_flags | v3;
}
}
else if ( v1 == 64 )
{
result = (unsigned __int8)sound_command;
}
else if ( v1 == 65 )
{
sound_flags &= 0xFFFFFF7F;
z80ctc_0_trg2_w(0LL, 0LL);
result = (unsigned __int8)dword_97C;
}
else
{
result = 0LL;
}
return result;
}

original_code:
data_t cchasm_snd_io_r(offs_t offset)
{
    int coin;
    switch (offset & 0x61 )
    {
    case 0x00:
        coin = (input_port_3_r (offset) >> 4) & 0x7;
        if (coin != 0x7) coin |= 0x8;
        return sound_flags | coin;
    case 0x01:
        return AY8910_read_port_0_r (offset);
    case 0x21:
        return AY8910_read_port_1_r (offset);
    case 0x40:
        return sound_command[0] & 0xff;
    case 0x41:
        sound_flags &= ~0x80;
        z80ctc_0_trg2_w (0, 0);
        return sound_command[1] & 0xff;
    default:
        return 0;
    }
}

canonical_original_code:
unsigned int cchasm_snd_io_r(unsigned int offset)
{
    int coin;
    switch (offset & 0x61 )
    {
    case 0x00:
        coin = (input_port_3_r (offset) >> 4) & 0x7;
        if (coin != 0x7) coin |= 0x8;
        return sound_flags | coin;
    case 0x01:
        return AY8910_read_port_0_r (offset);
    case 0x21:
        return AY8910_read_port_1_r (offset);
    case 0x40:
        return sound_command[0] & 0xff;
    case 0x41:
        sound_flags &= ~0x80;
        z80ctc_0_trg2_w (0, 0);
        return sound_command[1] & 0xff;
    default:
        return 0;
    }
}

variable_types:
offset
unsigned int

variable_types: coin int


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

v2 = (a1 >> 1) & 0xF;
if ( v2 )
{
if ( v2 == 1 )
{
sound_flags |= 0x80u;
dword_97C = a2 >> 8;
z80ctc_0_trg2_w(0LL, 1LL);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
}
else
{
sound_command = a2 >> 8;
}
return result;
}

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

v2 = (a1 >> 1) & 0xF;
if ( v2 )
{
if ( v2 == 1 )
{
sound_flags |= 0x80u;
dword_97C = a2 >> 8;
z80ctc_0_trg2_w(0LL, 1LL);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
}
else
{
sound_command = a2 >> 8;
}
return result;
}

original_code:
void cchasm_io_w(offs_t offset,data_t data)
{
    static int led;
    switch ((offset >> 1) & 0xf)
    {
    case 0:
        sound_command[0] = data >> 8;
        break;
    case 1:
        sound_flags |= 0x80;
        sound_command[1] = data >> 8;
        z80ctc_0_trg2_w (0, 1);
        cpu_cause_interrupt( 1, -2 );
        break;
    case 2:
        led = data;
        break;
    }
}

canonical_original_code:
void cchasm_io_w(unsigned int offset, unsigned int data)
{
    static int led;
    switch ((offset >> 1) & 0xf)
    {
    case 0:
        sound_command[0] = data >> 8;
        break;
    case 1:
        sound_flags |= 0x80;
        sound_command[1] = data >> 8;
        z80ctc_0_trg2_w (0, 1);
        cpu_cause_interrupt( 1, -2 );
        break;
    case 2:
        led = data;
        break;
    }
}

variable_types:
data
unsigned int

variable_types: led int


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

result = a1 & 0x61;
if ( (_DWORD)result == 33 )
return AY8910_write_port_1_w();
if ( (unsigned int)result > 0x21 )
{
switch ( (_DWORD)result )
{
case 'A':
sound_flags |= 0x40u;
dword_984 = a2;
result = cpu_cause_interrupt(0LL, 1LL);
break;
case 'a':
result = z80ctc_0_trg0_w(0LL, 0LL);
break;
case '@':
sound_status = a2;
break;
}
}
else if ( (_DWORD)result == 1 )
{
result = AY8910_write_port_0_w();
}
else if ( (_DWORD)result == 32 )
{
result = AY8910_control_port_1_w();
}
else if ( (a1 & 0x61) == 0 )
{
result = AY8910_control_port_0_w();
}
return result;
}

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

result = a1 & 0x61;
if ( (_DWORD)result == 33 )
return AY8910_write_port_1_w();
if ( (unsigned int)result > 0x21 )
{
switch ( (_DWORD)result )
{
case 'A':
sound_flags |= 0x40u;
dword_984 = a2;
result = cpu_cause_interrupt(0LL, 1LL);
break;
case 'a':
result = z80ctc_0_trg0_w(0LL, 0LL);
break;
case '@':
sound_status = a2;
break;
}
}
else if ( (_DWORD)result == 1 )
{
result = AY8910_write_port_0_w();
}
else if ( (_DWORD)result == 32 )
{
result = AY8910_control_port_1_w();
}
else if ( (a1 & 0x61) == 0 )
{
result = AY8910_control_port_0_w();
}
return result;
}

original_code:
void cchasm_snd_io_w(offs_t offset,data_t data)
{
    switch (offset & 0x61 )
    {
    case 0x00:
        AY8910_control_port_0_w (offset, data);
        break;
    case 0x01:
        AY8910_write_port_0_w (offset, data);
        break;
    case 0x20:
        AY8910_control_port_1_w (offset, data);
        break;
    case 0x21:
        AY8910_write_port_1_w (offset, data);
        break;
    case 0x40:
        sound_status[0] = data;
        break;
    case 0x41:
        sound_flags |= 0x40;
        sound_status[1] = data;
        cpu_cause_interrupt(0,1);
        break;
    case 0x61:
        z80ctc_0_trg0_w (0, 0);
        break;
    default:
        break;
    }
}

canonical_original_code:
void cchasm_snd_io_w(unsigned int offset, unsigned int data)
{
    switch (offset & 0x61 )
    {
    case 0x00:
        AY8910_control_port_0_w (offset, data);
        break;
    case 0x01:
        AY8910_write_port_0_w (offset, data);
        break;
    case 0x20:
        AY8910_control_port_1_w (offset, data);
        break;
    case 0x21:
        AY8910_write_port_1_w (offset, data);
        break;
    case 0x40:
        sound_status[0] = data;
        break;
    case 0x41:
        sound_flags |= 0x40;
        sound_status[1] = data;
        cpu_cause_interrupt(0,1);
        break;
    case 0x61:
        z80ctc_0_trg0_w (0, 0);
        break;
    default:
        break;
    }
}


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

result = input_port_3_r(0LL) & 0x70;
if ( (_DWORD)result != 112 )
result = z80ctc_0_trg0_w(0LL, 1LL);
return result;
}

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

result = input_port_3_r(0LL) & 0x70;
if ( (_DWORD)result != 112 )
result = z80ctc_0_trg0_w(0LL, 1LL);
return result;
}

original_code:
void cchasm_sh_update(void)
{
    if ((input_port_3_r (0) & 0x70) != 0x70)
        z80ctc_0_trg0_w (0, 1);
}

canonical_original_code:
void cchasm_sh_update()
{
    if ((input_port_3_r (0) & 0x70) != 0x70)
        z80ctc_0_trg0_w (0, 1);
}


decompiled_code:
__int16 __fastcall cchasm_io_r(__int64 a1)
{
unsigned int v1; // eax

switch ( ((unsigned int)a1 >> 1) & 0xF )
{
case 0u:
LOWORD(v1) = (_WORD)sound_status << 8;
break;
case 1u:
sound_flags &= 0xFFFFFFBF;
LOWORD(v1) = (_WORD)dword_984 << 8;
break;
case 2u:
v1 = (sound_flags | input_port_3_r(a1) & 7) << 8;
BYTE1(v1) |= 8u;
break;
case 3u:
case 4u:
case 6u:
case 7u:
LOWORD(v1) = -256;
break;
case 5u:
v1 = (unsigned int)input_port_2_r() << 8;
break;
case 8u:
v1 = (unsigned int)input_port_1_r() << 8;
break;
default:
LOWORD(v1) = -256;
break;
}
return v1;
}

canonical_decompiled_code:
__int16 __fastcall func17(__int64 a1)
{
unsigned int v1; // eax

switch ( ((unsigned int)a1 >> 1) & 0xF )
{
case 0u:
LOWORD(v1) = (_WORD)sound_status << 8;
break;
case 1u:
sound_flags &= 0xFFFFFFBF;
LOWORD(v1) = (_WORD)dword_984 << 8;
break;
case 2u:
v1 = (sound_flags | input_port_3_r(a1) & 7) << 8;
BYTE1(v1) |= 8u;
break;
case 3u:
case 4u:
case 6u:
case 7u:
LOWORD(v1) = -256;
break;
case 5u:
v1 = (unsigned int)input_port_2_r() << 8;
break;
case 8u:
v1 = (unsigned int)input_port_1_r() << 8;
break;
default:
LOWORD(v1) = -256;
break;
}
return v1;
}

original_code:
data_t cchasm_io_r(offs_t offset)
{
    switch ((offset >> 1) & 0xf)
    {
    case 0x0:
        return sound_status[0] << 8;
    case 0x1:
        sound_flags &= ~0x40;
        return sound_status[1] << 8;
    case 0x2:
        return (sound_flags| (input_port_3_r (offset) & 0x07) | 0x08) << 8;
    case 0x5:
        return input_port_2_r (offset) << 8;
    case 0x8:
        return input_port_1_r (offset) << 8;
    default:
        return 0xff << 8;
    }
}

canonical_original_code:
unsigned int cchasm_io_r(unsigned int offset)
{
    switch ((offset >> 1) & 0xf)
    {
    case 0x0:
        return sound_status[0] << 8;
    case 0x1:
        sound_flags &= ~0x40;
        return sound_status[1] << 8;
    case 0x2:
        return (sound_flags| (input_port_3_r (offset) & 0x07) | 0x08) << 8;
    case 0x5:
        return input_port_2_r (offset) << 8;
    case 0x8:
        return input_port_1_r (offset) << 8;
    default:
        return 0xff << 8;
    }
}


decompiled_code:
__int64 cchasm_sh_start()
{
sound_status = 0;
dword_984 = 0;
sound_command = 0;
dword_97C = 0;
sound_flags = 0;
output[0] = 0;
dword_95C = 0;
channel = stream_init("CTC sound 1", 50LL, *(unsigned int *)(Machine + 836LL), 0LL, tone_update);
dword_96C = stream_init("CTC sound 2", 50LL, *(unsigned int *)(Machine + 836LL), 1LL, tone_update);
dword_19A4 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 84LL);
z80ctc_init(&ctc_intf);
return 0LL;
}

canonical_decompiled_code:
__int64 func18()
{
sound_status = 0;
dword_984 = 0;
sound_command = 0;
dword_97C = 0;
sound_flags = 0;
output[0] = 0;
dword_95C = 0;
channel = stream_init("CTC sound 1", 50LL, *(unsigned int *)(Machine + 836LL), 0LL, tone_update);
dword_96C = stream_init("CTC sound 2", 50LL, *(unsigned int *)(Machine + 836LL), 1LL, tone_update);
dword_19A4 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 84LL);
z80ctc_init(&ctc_intf);
return 0LL;
}

original_code:
int cchasm_sh_start(const struct MachineSound *msound)
{
    sound_status[0] = 0; sound_status[1] = 0;
    sound_command[0] = 0; sound_command[1] = 0;
    sound_flags = 0;
    output[0] = 0; output[1] = 0;
    channel[0] = stream_init("CTC sound 1", 50, Machine->sample_rate, 0, tone_update);
    channel[1] = stream_init("CTC sound 2", 50, Machine->sample_rate, 1, tone_update);
 ctc_intf.baseclock[0] = Machine->drv->cpu[1].cpu_clock;
 z80ctc_init (&ctc_intf);
 return 0;
}

canonical_original_code:
int cchasm_sh_start(struct MachineSound *msound)
{
    sound_status[0] = 0; sound_status[1] = 0;
    sound_command[0] = 0; sound_command[1] = 0;
    sound_flags = 0;
    output[0] = 0; output[1] = 0;
    channel[0] = stream_init("CTC sound 1", 50, Machine->sample_rate, 0, tone_update);
    channel[1] = stream_init("CTC sound 2", 50, Machine->sample_rate, 1, tone_update);
 ctc_intf.baseclock[0] = Machine->drv->cpu[1].cpu_clock;
 z80ctc_init (&ctc_intf);
 return 0;
}

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


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

if ( a2 )
{
dword_95C ^= 0x7Fu;
dword_964 = 1;
result = stream_update((unsigned int)dword_96C, 0LL);
}
return result;
}

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

if ( a2 )
{
dword_95C ^= 0x7Fu;
dword_964 = 1;
result = stream_update((unsigned int)dword_96C, 0LL);
}
return result;
}

original_code:
static void ctc_timer_2_w(offs_t offset,data_t data)
{
    if (data)
    {
        output[1] ^= 0x7f;
        channel_active[1] = 1;
        stream_update(channel[1], 0);
    }
}

canonical_original_code:
static void ctc_timer_2_w(unsigned int offset, unsigned int data)
{
    if (data)
    {
        output[1] ^= 0x7f;
        channel_active[1] = 1;
        stream_update(channel[1], 0);
    }
}


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

if ( a2 )
{
output[0] ^= 0x7Fu;
channel_active[0] = 1;
result = stream_update((unsigned int)channel, 0LL);
}
return result;
}

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

if ( a2 )
{
output[0] ^= 0x7Fu;
channel_active[0] = 1;
result = stream_update((unsigned int)channel, 0LL);
}
return result;
}

original_code:
static void ctc_timer_1_w(offs_t offset,data_t data)
{
    if (data)
    {
        output[0] ^= 0x7f;
        channel_active[0] = 1;
        stream_update(channel[0], 0);
    }
}

canonical_original_code:
static void ctc_timer_1_w(unsigned int offset, unsigned int data)
{
    if (data)
    {
        output[0] ^= 0x7f;
        channel_active[0] = 1;
        stream_update(channel[0], 0);
    }
}


decompiled_code:
int *__fastcall tone_update(int a1, __int64 a2, unsigned int a3)
{
__int16 v4; // ax
__int64 v5; // rdx
int *result; // rax

v4 = 0;
if ( channel_active[a1] )
v4 = (unsigned __int16)output[a1] << 8;
v5 = a2 + 2LL * a3;
if ( a3 )
{
do
{
a2 += 2LL;
*(_WORD *)(a2 - 2) = v4;
}
while ( a2 != v5 );
}
result = channel_active;
channel_active[a1] = 0;
return result;
}

canonical_decompiled_code:
int *__fastcall func3(int a1, __int64 a2, unsigned int a3)
{
__int16 v4; // ax
__int64 v5; // rdx
int *result; // rax

v4 = 0;
if ( channel_active[a1] )
v4 = (unsigned __int16)output[a1] << 8;
v5 = a2 + 2LL * a3;
if ( a3 )
{
do
{
a2 += 2LL;
*(_WORD *)(a2 - 2) = v4;
}
while ( a2 != v5 );
}
result = channel_active;
channel_active[a1] = 0;
return result;
}

original_code:
static void tone_update(int num,INT16 *buffer,int length)
{
 INT16 out = 0;
 if (channel_active[num])
  out = output[num] << 8;
 while (length--) *(buffer++) = out;
 channel_active[num] = 0;
}

canonical_original_code:
static void tone_update(int num, short *buffer, int length)
{
 short out = 0;
 if (channel_active[num])
  out = output[num] << 8;
 while (length--) *(buffer++) = out;
 channel_active[num] = 0;
}

variable_types: num int

variable_types:
buffer
short *

variable_types: length int

variable_types: out short


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

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

original_code:
static void ctc_interrupt (int state)
{
 cpu_cause_interrupt (1, (((0)<<8)|(state)) );
}

canonical_original_code:
static void ctc_interrupt(int state)
{
 cpu_cause_interrupt (1, (((0)<<8)|(state)) );
}

variable_types: state int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall yard_scroll_panel_w(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // er14
int i; // ebx

result = a1 & 0xF;
if ( (unsigned int)(result - 1) <= 0xD )
{
v3 = 4 * result - 4;
for ( i = 0; i != 4; ++i )
result = plot_pixel(
scroll_panel_bitmap,
(unsigned int)(i + v3),
a1 >> 4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (int)(((a1 >> 4) & 0xFC)
+ 272
+ (((a2 >> i) & 0x11 | ((int)((a2 >> i) & 0x11) >> 3)) & 3))));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // er14
int i; // ebx

result = a1 & 0xF;
if ( (unsigned int)(result - 1) <= 0xD )
{
v3 = 4 * result - 4;
for ( i = 0; i != 4; ++i )
result = plot_pixel(
scroll_panel_bitmap,
(unsigned int)(i + v3),
a1 >> 4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL)
+ 2LL
* (int)(((a1 >> 4) & 0xFC)
+ 272
+ (((a2 >> i) & 0x11 | ((int)((a2 >> i) & 0x11) >> 3)) & 3))));
}
return result;
}

original_code:
void yard_scroll_panel_w(offs_t offset,data_t data)
{
 int sx,sy,i;
 sx = ( offset % 16 );
 sy = ( offset / 16 );
 if (sx < 1 || sx > 14) return;
 sx = 4 * (sx - 1);
 for (i = 0;i < 4;i++)
 {
  int col;
  col = (data >> i) & 0x11;
  col = ((col >> 3) | col) & 3;
  plot_pixel(scroll_panel_bitmap, sx + i, sy, Machine->pens[(256+16) + (sy & 0xfc) + col]);
 }
}

canonical_original_code:
void yard_scroll_panel_w(unsigned int offset, unsigned int data)
{
 int sx; int sy; int i;
 sx = ( offset % 16 );
 sy = ( offset / 16 );
 if (sx < 1 || sx > 14) return;
 sx = 4 * (sx - 1);
 for (i = 0;i < 4;i++)
 {
  int col;
  col = (data >> i) & 0x11;
  col = ((col >> 3) | col) & 3;
  plot_pixel(scroll_panel_bitmap, sx + i, sy, Machine->pens[(256+16) + (sy & 0xfc) + col]);
 }
}

variable_types: sx int

variable_types: sy int

variable_types: col int


decompiled_code:
__int64 yard_vh_start()
{
size_t v0; // rbx
void *v1; // rdi
unsigned int v2; // edx

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

canonical_decompiled_code:
__int64 func2()
{
size_t v0; // rbx
void *v1; // rdi
unsigned int v2; // edx

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall yard_flipscreen_w(unsigned int a1, char a2)
{
char v2; // bl

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, char a2)
{
char v2; // bl

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

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

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


decompiled_code:
__int64 __fastcall yard_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // r8
_BYTE *v5; // rax
int v6; // eax
__int64 v7; // r15
int v8; // edx
int v9; // ebx
int v10; // esi
unsigned __int8 v11; // di
unsigned int v12; // ebp
__int64 result; // rax
__int64 v14; // r8
void *v15; // rax
int v17; // [rsp+Ch] [rbp-4Ch]
int v18; // [rsp+18h] [rbp-40h] BYREF
int v19[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
v5 = (char *)dirtybuffer + v3 - 1;
if ( *v5 || *((_BYTE *)dirtybuffer + v3) )
{
*v5 = 0;
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(_BYTE *)(videoram + v3) & 0x20;
if ( flip_screen_x )
v4 = (_DWORD)v4 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3 - 1) + ((4 * *(unsigned __int8 *)(videoram + v3)) & 0x300u),
*(_BYTE *)(videoram + v3) & 0x1F,
v4);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
v6 = (unsigned __int8)*yard_scroll_x_low + ((unsigned __int8)*yard_scroll_x_high << 8);
if ( flip_screen_x )
{
v18 = v6 + 256;
v19[0] = (unsigned __int8)*yard_scroll_y_low;
}
else
{
v18 = -v6;
v19[0] = -(unsigned __int8)*yard_scroll_y_low;
}
copyscrollbitmap(a1, tmpbitmap, 1LL, &v18, 1LL, v19, Machine + 776LL, 0LL, 0LL);
v17 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = spriteram_size - 4 + 1LL;
do
{
v10 = (*(unsigned __int8 *)(spriteram + v7) >> 5) & 1;
v11 = *(_BYTE *)(spriteram + v7 + 1) & 0xBF;
v9 = v11;
v12 = *(_BYTE *)(spriteram + v7) & 0x40;
if ( (*(_BYTE *)(spriteram + v7) & 0x80) != 0 )
{
v8 = (unsigned __int8)(v11 + 64);
}
else
{
v8 = *(_BYTE *)(spriteram + v7 + 1) & 0xBF;
v9 = (unsigned __int8)(v11 + 64);
}
if ( flip_screen_x )
v12 = v12 == 0;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), (unsigned int)((v10 << 8) + v8), *(_BYTE *)(spriteram + v7) & 0x1F, v12);
drawgfx(a1, *(_QWORD *)(Machine + 520LL), (unsigned int)((v10 << 8) + v9), *(_BYTE *)(spriteram + v7) & 0x1F, v12);
v7 -= 4LL;
v17 -= 4;
}
while ( v17 >= 0 );
}
result = (__int64)yard_score_panel_disabled;
if ( !*yard_score_panel_disabled )
{
if ( flip_screen_x )
{
v14 = (unsigned int)(*(_DWORD *)(Machine + 776LL) - 8);
v15 = &panelvisibleareaflip;
}
else
{
v14 = (unsigned int)(*(_DWORD *)(Machine + 780LL) - 55);
v15 = &panelvisiblearea;
}
result = copybitmap(a1, scroll_panel_bitmap, flip_screen_x, flip_screen_x, v14, 0LL, v15, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // r8
_BYTE *v5; // rax
int v6; // eax
__int64 v7; // r15
int v8; // edx
int v9; // ebx
int v10; // esi
unsigned __int8 v11; // di
unsigned int v12; // ebp
__int64 result; // rax
__int64 v14; // r8
void *v15; // rax
int v17; // [rsp+Ch] [rbp-4Ch]
int v18; // [rsp+18h] [rbp-40h] BYREF
int v19[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
v5 = (char *)dirtybuffer + v3 - 1;
if ( *v5 || *((_BYTE *)dirtybuffer + v3) )
{
*v5 = 0;
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(_BYTE *)(videoram + v3) & 0x20;
if ( flip_screen_x )
v4 = (_DWORD)v4 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3 - 1) + ((4 * *(unsigned __int8 *)(videoram + v3)) & 0x300u),
*(_BYTE *)(videoram + v3) & 0x1F,
v4);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
v6 = (unsigned __int8)*yard_scroll_x_low + ((unsigned __int8)*yard_scroll_x_high << 8);
if ( flip_screen_x )
{
v18 = v6 + 256;
v19[0] = (unsigned __int8)*yard_scroll_y_low;
}
else
{
v18 = -v6;
v19[0] = -(unsigned __int8)*yard_scroll_y_low;
}
copyscrollbitmap(a1, tmpbitmap, 1LL, &v18, 1LL, v19, Machine + 776LL, 0LL, 0LL);
v17 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = spriteram_size - 4 + 1LL;
do
{
v10 = (*(unsigned __int8 *)(spriteram + v7) >> 5) & 1;
v11 = *(_BYTE *)(spriteram + v7 + 1) & 0xBF;
v9 = v11;
v12 = *(_BYTE *)(spriteram + v7) & 0x40;
if ( (*(_BYTE *)(spriteram + v7) & 0x80) != 0 )
{
v8 = (unsigned __int8)(v11 + 64);
}
else
{
v8 = *(_BYTE *)(spriteram + v7 + 1) & 0xBF;
v9 = (unsigned __int8)(v11 + 64);
}
if ( flip_screen_x )
v12 = v12 == 0;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), (unsigned int)((v10 << 8) + v8), *(_BYTE *)(spriteram + v7) & 0x1F, v12);
drawgfx(a1, *(_QWORD *)(Machine + 520LL), (unsigned int)((v10 << 8) + v9), *(_BYTE *)(spriteram + v7) & 0x1F, v12);
v7 -= 4LL;
v17 -= 4;
}
while ( v17 >= 0 );
}
result = (__int64)yard_score_panel_disabled;
if ( !*yard_score_panel_disabled )
{
if ( flip_screen_x )
{
v14 = (unsigned int)(*(_DWORD *)(Machine + 776LL) - 8);
v15 = &panelvisibleareaflip;
}
else
{
v14 = (unsigned int)(*(_DWORD *)(Machine + 780LL) - 55);
v15 = &panelvisiblearea;
}
result = copybitmap(a1, scroll_panel_bitmap, flip_screen_x, flip_screen_x, v14, 0LL, v15, 0LL, 0LL);
}
return result;
}

original_code:
void yard_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx,sy,flipx;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   flipx = videoram[offs+1] & 0x20;
   if (sy >= 32)
   {
    sy -= 32;
    sx += 32;
   }
   if (flip_screen_x)
   {
    sx = 63 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0xc0) << 2),
     videoram[offs+1] & 0x1f,
     flipx,flip_screen_x,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll_x,scroll_y;
  scroll_x = (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low;
  if (flip_screen_x)
  {
   scroll_x += 256;
   scroll_y = *yard_scroll_y_low ;
  }
  else
  {
   scroll_x = -scroll_x;
   scroll_y = -*yard_scroll_y_low ;
  }
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll_x,1,&scroll_y,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int code1,code2,bank,sx,sy1,sy2,flipx,flipy;
  bank = (spriteram[offs + 1] & 0x20) >> 5;
  code1 = spriteram[offs + 2] & 0xbf;
  sx = spriteram[offs + 3];
  sy1 = 241 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flipy)
  {
   code2 = code1;
   code1 += 0x40;
  }
  else
  {
   code2 = code1 + 0x40;
  }
  if (flip_screen_x)
  {
   flipx = !flipx;
   flipy = !flipy;
   sx = 240 - sx;
   sy2 = 224 - sy1;
   sy1 = sy2 + 0x10;
  }
  else
  {
   sy2 = sy1 + 0x10;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code1 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy1,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
  drawgfx(bitmap,Machine->gfx[1],
    code2 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy2,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
 }
 if (! *yard_score_panel_disabled)
 {
  int xpos;
  xpos = flip_screen_x ? Machine->visible_area.min_x - 8 :
                       Machine->visible_area.max_x + 1 - (14*4);
  copybitmap(bitmap,scroll_panel_bitmap,flip_screen_x,flip_screen_x,
             xpos,0,
       flip_screen_x ? &panelvisibleareaflip : &panelvisiblearea,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
void yard_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx; int sy; int flipx;
   dirtybuffer[offs] = 0;
   dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 32;
   sy = (offs/2) / 32;
   flipx = videoram[offs+1] & 0x20;
   if (sy >= 32)
   {
    sy -= 32;
    sx += 32;
   }
   if (flip_screen_x)
   {
    sx = 63 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0xc0) << 2),
     videoram[offs+1] & 0x1f,
     flipx,flip_screen_x,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll_x; int scroll_y;
  scroll_x = (*yard_scroll_x_high * 0x100) + *yard_scroll_x_low;
  if (flip_screen_x)
  {
   scroll_x += 256;
   scroll_y = *yard_scroll_y_low ;
  }
  else
  {
   scroll_x = -scroll_x;
   scroll_y = -*yard_scroll_y_low ;
  }
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll_x,1,&scroll_y,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int code1; int code2; int bank; int sx; int sy1; int sy2; int flipx; int flipy;
  bank = (spriteram[offs + 1] & 0x20) >> 5;
  code1 = spriteram[offs + 2] & 0xbf;
  sx = spriteram[offs + 3];
  sy1 = 241 - spriteram[offs];
  flipx = spriteram[offs + 1] & 0x40;
  flipy = spriteram[offs + 1] & 0x80;
  if (flipy)
  {
   code2 = code1;
   code1 += 0x40;
  }
  else
  {
   code2 = code1 + 0x40;
  }
  if (flip_screen_x)
  {
   flipx = !flipx;
   flipy = !flipy;
   sx = 240 - sx;
   sy2 = 224 - sy1;
   sy1 = sy2 + 0x10;
  }
  else
  {
   sy2 = sy1 + 0x10;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code1 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy1,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
  drawgfx(bitmap,Machine->gfx[1],
    code2 + 256 * bank,
    spriteram[offs + 1] & 0x1f,
    flipx,flipy,
    sx, sy2,
    &Machine->visible_area,TRANSPARENCY_COLOR,256);
 }
 if (! *yard_score_panel_disabled)
 {
  int xpos;
  xpos = flip_screen_x ? Machine->visible_area.min_x - 8 :
                       Machine->visible_area.max_x + 1 - (14*4);
  copybitmap(bitmap,scroll_panel_bitmap,flip_screen_x,flip_screen_x,
             xpos,0,
       flip_screen_x ? &panelvisibleareaflip : &panelvisiblearea,TRANSPARENCY_NONE,0);
 }
}

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

variable_types: offs int

variable_types: flipx int

variable_types: bank int

variable_types: flipy int

variable_types: xpos int


decompiled_code:
__int64 __fastcall jsa1_io_r(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v2 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v2;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v2 ^ 0x80;
v2 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v2 ^= 0x40u;
if ( atarigen_sound_to_cpu_ready )
v2 ^= 0x20u;
if ( !has_tms5220 || (unsigned int)tms5220_ready_r() )
v2 ^= 0x10u;
}
else if ( v1 == 6 )
{
atarigen_6502_irq_ack_r(0LL);
v2 = 255;
}
else
{
v2 = 255;
if ( v1 == 2 )
v2 = atarigen_6502_sound_r();
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned __int16 v4; // dx
unsigned int v5; // eax

v1 = a1 & 0x206;
if ( v1 == 4 )
{
v2 = readinputport((unsigned __int8)input_port);
v4 = readinputport((unsigned __int8)test_port);
v5 = v2;
if ( (v4 & (unsigned __int16)test_mask) == 0 )
{
LOBYTE(v5) = v2 ^ 0x80;
v2 = v5;
}
if ( atarigen_cpu_to_sound_ready )
v2 ^= 0x40u;
if ( atarigen_sound_to_cpu_ready )
v2 ^= 0x20u;
if ( !has_tms5220 || (unsigned int)tms5220_ready_r() )
v2 ^= 0x10u;
}
else if ( v1 == 6 )
{
atarigen_6502_irq_ack_r(0LL);
v2 = 255;
}
else
{
v2 = 255;
if ( v1 == 2 )
v2 = atarigen_6502_sound_r();
}
return v2;
}

original_code:
static data_t jsa1_io_r(offs_t offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x80;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   if (!has_tms5220 || tms5220_ready_r()) result ^= 0x10;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

canonical_original_code:
static unsigned int jsa1_io_r(unsigned int offset)
{
 int result = 0xff;
 switch (offset & 0x206)
 {
  case 0x000:
   break;
  case 0x002:
   result = atarigen_6502_sound_r(offset);
   break;
  case 0x004:
   result = readinputport(input_port);
   if (!(readinputport(test_port) & test_mask)) result ^= 0x80;
   if (atarigen_cpu_to_sound_ready) result ^= 0x40;
   if (atarigen_sound_to_cpu_ready) result ^= 0x20;
   if (!has_tms5220 || tms5220_ready_r()) result ^= 0x10;
   break;
  case 0x006:
   atarigen_6502_irq_ack_r(0);
   break;
  case 0x200:
  case 0x202:
  case 0x204:
  case 0x206:
   break;
 }
 return result;
}

variable_types:
offset
unsigned int

variable_types: result int


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

if ( has_pokey )
result = atarigen_set_pokey_vol((1374389535LL * (unsigned __int8)pokey_volume * (unsigned __int8)overall_volume) >> 37);
if ( has_ym2151 )
result = atarigen_set_ym2151_vol((1374389535LL * (unsigned __int8)ym2151_volume * (unsigned __int8)overall_volume) >> 37);
if ( has_tms5220 )
result = atarigen_set_tms5220_vol((1374389535LL * (unsigned __int8)tms5220_volume * (unsigned __int8)overall_volume) >> 37);
if ( has_oki6295 )
result = atarigen_set_oki6295_vol((1374389535LL * (unsigned __int8)oki6295_volume * (unsigned __int8)overall_volume) >> 37);
return result;
}

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

if ( has_pokey )
result = atarigen_set_pokey_vol((1374389535LL * (unsigned __int8)pokey_volume * (unsigned __int8)overall_volume) >> 37);
if ( has_ym2151 )
result = atarigen_set_ym2151_vol((1374389535LL * (unsigned __int8)ym2151_volume * (unsigned __int8)overall_volume) >> 37);
if ( has_tms5220 )
result = atarigen_set_tms5220_vol((1374389535LL * (unsigned __int8)tms5220_volume * (unsigned __int8)overall_volume) >> 37);
if ( has_oki6295 )
result = atarigen_set_oki6295_vol((1374389535LL * (unsigned __int8)oki6295_volume * (unsigned __int8)overall_volume) >> 37);
return result;
}

original_code:
static void update_all_volumes(void)
{
 if (has_pokey) atarigen_set_pokey_vol(overall_volume * pokey_volume / 100);
 if (has_ym2151) atarigen_set_ym2151_vol(overall_volume * ym2151_volume / 100);
 if (has_tms5220) atarigen_set_tms5220_vol(overall_volume * tms5220_volume / 100);
 if (has_oki6295) atarigen_set_oki6295_vol(overall_volume * oki6295_volume / 100);
}

canonical_original_code:
static void update_all_volumes()
{
 if (has_pokey) atarigen_set_pokey_vol(overall_volume * pokey_volume / 100);
 if (has_ym2151) atarigen_set_ym2151_vol(overall_volume * ym2151_volume / 100);
 if (has_tms5220) atarigen_set_tms5220_vol(overall_volume * tms5220_volume / 100);
 if (has_oki6295) atarigen_set_oki6295_vol(overall_volume * oki6295_volume / 100);
}