original_code:
static void warpwarp_sound_update(int param, INT16 *buffer, int length)
{
    static int vcarry = 0;
    static int vcount = 0;
    static int mcarry = 0;
 static int mcount = 0;
    while (length--)
    {
  *buffer++ = (sound_signal + music_signal) / 2;
  mcarry -= (18432000/3/2/16) / (4 * (64 - music1_latch));
  while( mcarry < 0 )
  {
   mcarry += Machine->sample_rate;
   mcount++;
   music_signal = (mcount & ~music2_latch & 15) ? decay[music_volume] : 0;
   if( (music2_latch & 32) && (noise & 0x8000) )
    music_signal = decay[music_volume];
  }
  vcarry -= (18432000/3/2/384);
        while (vcarry < 0)
        {
            vcarry += Machine->sample_rate;
            vcount++;
   if ((vcount & 3) == 2)
   {
    if ((noise & 1) == ((noise >> 10) & 1))
     noise = (noise << 1) | 1;
    else
     noise = noise << 1;
   }
            switch (sound_latch & 7)
            {
            case 0:
    sound_signal = (vcount & 0x04) ? decay[sound_volume] : 0;
                break;
            case 1:
    sound_signal = (vcount & 0x08) ? decay[sound_volume] : 0;
                break;
            case 2:
    sound_signal = (vcount & 0x10) ? decay[sound_volume] : 0;
                break;
            case 3:
    sound_signal = (vcount & 0x20) ? decay[sound_volume] : 0;
                break;
            case 4:
    sound_signal = !(vcount & 0x01) && !(vcount & 0x10) ? decay[sound_volume] : 0;
                break;
            case 5:
    sound_signal = !(vcount & 0x02) && !(vcount & 0x20) ? decay[sound_volume] : 0;
                break;
            case 6:
    sound_signal = !(vcount & 0x04) && !(vcount & 0x40) ? decay[sound_volume] : 0;
                break;
   default:
    sound_signal = (noise & 0x8000) ? decay[sound_volume] : 0;
            }
        }
    }
}

canonical_original_code:
static void warpwarp_sound_update(int param, short *buffer, int length)
{
    static int vcarry = 0;
    static int vcount = 0;
    static int mcarry = 0;
 static int mcount = 0;
    while (length--)
    {
  *buffer++ = (sound_signal + music_signal) / 2;
  mcarry -= (18432000/3/2/16) / (4 * (64 - music1_latch));
  while( mcarry < 0 )
  {
   mcarry += Machine->sample_rate;
   mcount++;
   music_signal = (mcount & ~music2_latch & 15) ? decay[music_volume] : 0;
   if( (music2_latch & 32) && (noise & 0x8000) )
    music_signal = decay[music_volume];
  }
  vcarry -= (18432000/3/2/384);
        while (vcarry < 0)
        {
            vcarry += Machine->sample_rate;
            vcount++;
   if ((vcount & 3) == 2)
   {
    if ((noise & 1) == ((noise >> 10) & 1))
     noise = (noise << 1) | 1;
    else
     noise = noise << 1;
   }
            switch (sound_latch & 7)
            {
            case 0:
    sound_signal = (vcount & 0x04) ? decay[sound_volume] : 0;
                break;
            case 1:
    sound_signal = (vcount & 0x08) ? decay[sound_volume] : 0;
                break;
            case 2:
    sound_signal = (vcount & 0x10) ? decay[sound_volume] : 0;
                break;
            case 3:
    sound_signal = (vcount & 0x20) ? decay[sound_volume] : 0;
                break;
            case 4:
    sound_signal = !(vcount & 0x01) && !(vcount & 0x10) ? decay[sound_volume] : 0;
                break;
            case 5:
    sound_signal = !(vcount & 0x02) && !(vcount & 0x20) ? decay[sound_volume] : 0;
                break;
            case 6:
    sound_signal = !(vcount & 0x04) && !(vcount & 0x40) ? decay[sound_volume] : 0;
                break;
   default:
    sound_signal = (noise & 0x8000) ? decay[sound_volume] : 0;
            }
        }
    }
}

variable_types:
buffer
short *

variable_types: length int

variable_types: vcarry int

variable_types: vcount int

variable_types: mcarry int

variable_types: mcount int


decompiled_code:
__int64 __fastcall warpwarp_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // rdi
int v5; // edx
__int64 result; // rax
unsigned int v7; // er15
int v8; // esi
unsigned int v9; // er13
unsigned int v10; // er12
unsigned int v11; // ebx
int v12; // [rsp+8h] [rbp-40h]

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
v4 = 264LL;
v5 = v2 & 0x1F;
if ( v2 >> 5 )
{
v4 = 0LL;
if ( v2 >> 5 != 1 )
{
v4 = (unsigned int)(8 * v5 + 8);
v5 = v2 >> 5;
}
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
*(unsigned __int8 *)(colorram + v3),
0LL,
0LL,
v4,
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
*(_BYTE *)(dirtybuffer + v3) = 0;
}
--v2;
--v3;
}
while ( v2 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = (unsigned __int8)*warpwarp_bulletsram;
if ( (unsigned __int8)result > 1u )
{
v7 = 260 - result;
if ( *(_DWORD *)(Machine + 776LL) <= 260 - (int)result && 262 - (int)result < *(_DWORD *)(Machine + 780LL) )
{
v8 = (unsigned __int8)warpwarp_bulletsram[1];
if ( *(_DWORD *)(Machine + 784LL) <= 252 - v8 && 254 - v8 < *(_DWORD *)(Machine + 788LL) )
{
v9 = 252 - v8;
v10 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 492LL);
v12 = 264 - result;
do
{
v11 = v7;
do
result = plot_pixel(a1, v11++, v9, v10);
while ( v12 != v11 );
++v9;
}
while ( v9 != 256 - v8 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
__int64 v4; // rdi
int v5; // edx
__int64 result; // rax
unsigned int v7; // er15
int v8; // esi
unsigned int v9; // er13
unsigned int v10; // er12
unsigned int v11; // ebx
int v12; // [rsp+8h] [rbp-40h]

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
v4 = 264LL;
v5 = v2 & 0x1F;
if ( v2 >> 5 )
{
v4 = 0LL;
if ( v2 >> 5 != 1 )
{
v4 = (unsigned int)(8 * v5 + 8);
v5 = v2 >> 5;
}
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3),
*(unsigned __int8 *)(colorram + v3),
0LL,
0LL,
v4,
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
*(_BYTE *)(dirtybuffer + v3) = 0;
}
--v2;
--v3;
}
while ( v2 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = (unsigned __int8)*warpwarp_bulletsram;
if ( (unsigned __int8)result > 1u )
{
v7 = 260 - result;
if ( *(_DWORD *)(Machine + 776LL) <= 260 - (int)result && 262 - (int)result < *(_DWORD *)(Machine + 780LL) )
{
v8 = (unsigned __int8)warpwarp_bulletsram[1];
if ( *(_DWORD *)(Machine + 784LL) <= 252 - v8 && 254 - v8 < *(_DWORD *)(Machine + 788LL) )
{
v9 = 252 - v8;
v10 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 492LL);
v12 = 264 - result;
do
{
v11 = v7;
do
result = plot_pixel(a1, v11++, v9, v10);
while ( v12 != v11 );
++v9;
}
while ( v9 != 256 - v8 );
}
}
}
return result;
}

original_code:
void warpwarp_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int mx,my,sx,sy;
   mx = offs % 32;
   my = offs / 32;
   if (my == 0)
   {
    sx = 33;
    sy = mx;
   }
   else if (my == 1)
   {
    sx = 0;
    sy = mx;
   }
   else
   {
    sx = mx + 1;
    sy = my;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     colorram[offs],
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 if (warpwarp_bulletsram[0] > 1)
 {
  int x,y;
  x = 260 - warpwarp_bulletsram[0];
  y = 252 - warpwarp_bulletsram[1];
  if (x >= Machine->visible_area.min_x && x+3 <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y && y+3 <= Machine->visible_area.max_y)
  {
   int colour;
   int i,j;
   colour = Machine->pens[0xf6];
   for (i = 0;i < 4;i++)
   {
    for (j = 0;j < 4;j++)
    {
     plot_pixel(bitmap, x+j, y+i, colour);
    }
   }
  }
 }
}

canonical_original_code:
void warpwarp_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int mx; int my; int sx; int sy;
   mx = offs % 32;
   my = offs / 32;
   if (my == 0)
   {
    sx = 33;
    sy = mx;
   }
   else if (my == 1)
   {
    sx = 0;
    sy = mx;
   }
   else
   {
    sx = mx + 1;
    sy = my;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     colorram[offs],
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 if (warpwarp_bulletsram[0] > 1)
 {
  int x; int y;
  x = 260 - warpwarp_bulletsram[0];
  y = 252 - warpwarp_bulletsram[1];
  if (x >= Machine->visible_area.min_x && x+3 <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y && y+3 <= Machine->visible_area.max_y)
  {
   int colour;
   int i; int j;
   colour = Machine->pens[0xf6];
   for (i = 0;i < 4;i++)
   {
    for (j = 0;j < 4;j++)
    {
     plot_pixel(bitmap, x+j, y+i, colour);
    }
   }
  }
 }
}

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

variable_types: offs int

variable_types: mx int

variable_types: my int

variable_types: sx int

variable_types: sy int

variable_types: x int

variable_types: y int

variable_types: colour int

variable_types: i int

variable_types: j int

return_type: void


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

result = stream_update((unsigned int)channel, 0LL);
music1_latch = a2 & 0x3F;
return result;
}

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

result = stream_update((unsigned int)channel, 0LL);
music1_latch = a2 & 0x3F;
return result;
}

original_code:
void warpwarp_music1_w(offs_t offset,data_t data)
{
    stream_update(channel,0);
 music1_latch = data & 63;
}

canonical_original_code:
void warpwarp_music1_w(unsigned int offset, unsigned int data)
{
    stream_update(channel,0);
 music1_latch = data & 63;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 warpwarp_sh_update()
{
return stream_update((unsigned int)channel, 0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return stream_update((unsigned int)channel, 0LL);
}

original_code:
void warpwarp_sh_update(void)
{
 stream_update(channel,0);
}

canonical_original_code:
void warpwarp_sh_update()
{
 stream_update(channel,0);
}


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

stream_update((unsigned int)channel, 0LL);
sound_latch = a2;
sound_volume = 0x7FFF;
noise = 0;
if ( (a2 & 8) != 0 )
{
if ( sound_volume_timer )
timer_remove(sound_volume_timer);
result = timer_pulse(31408LL, 0LL, sound_volume_decay);
sound_volume_timer = result;
}
else
{
if ( sound_volume_timer )
timer_remove(sound_volume_timer);
result = timer_pulse(62817LL, 0LL, sound_volume_decay);
sound_volume_timer = result;
}
return result;
}

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

stream_update((unsigned int)channel, 0LL);
sound_latch = a2;
sound_volume = 0x7FFF;
noise = 0;
if ( (a2 & 8) != 0 )
{
if ( sound_volume_timer )
timer_remove(sound_volume_timer);
result = timer_pulse(31408LL, 0LL, sound_volume_decay);
sound_volume_timer = result;
}
else
{
if ( sound_volume_timer )
timer_remove(sound_volume_timer);
result = timer_pulse(62817LL, 0LL, sound_volume_decay);
sound_volume_timer = result;
}
return result;
}

original_code:
void warpwarp_sound_w(offs_t offset,data_t data)
{
 stream_update(channel,0);
 sound_latch = data;
 sound_volume = 0x7fff;
 noise = 0x0000;
 if( sound_latch & 8 )
 {
  if( sound_volume_timer )
   timer_remove(sound_volume_timer);
  sound_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.9585))), 0, sound_volume_decay);
 }
 else
 {
  if( sound_volume_timer )
   timer_remove(sound_volume_timer);
  sound_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/1.917))), 0, sound_volume_decay);
    }
}

canonical_original_code:
void warpwarp_sound_w(unsigned int offset, unsigned int data)
{
 stream_update(channel,0);
 sound_latch = data;
 sound_volume = 0x7fff;
 noise = 0x0000;
 if( sound_latch & 8 )
 {
  if( sound_volume_timer )
   timer_remove(sound_volume_timer);
  sound_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.9585))), 0, sound_volume_decay);
 }
 else
 {
  if( sound_volume_timer )
   timer_remove(sound_volume_timer);
  sound_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/1.917))), 0, sound_volume_decay);
    }
}


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

stream_update((unsigned int)channel, 0LL);
music2_latch = a2;
music_volume = 0x7FFF;
if ( (a2 & 0x10) != 0 )
{
if ( music_volume_timer )
timer_remove(music_volume_timer);
result = timer_pulse(31408LL, 0LL, music_volume_decay);
music_volume_timer = result;
}
else
{
if ( music_volume_timer )
timer_remove(music_volume_timer);
result = timer_pulse(98418LL, 0LL, music_volume_decay);
music_volume_timer = result;
}
return result;
}

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

stream_update((unsigned int)channel, 0LL);
music2_latch = a2;
music_volume = 0x7FFF;
if ( (a2 & 0x10) != 0 )
{
if ( music_volume_timer )
timer_remove(music_volume_timer);
result = timer_pulse(31408LL, 0LL, music_volume_decay);
music_volume_timer = result;
}
else
{
if ( music_volume_timer )
timer_remove(music_volume_timer);
result = timer_pulse(98418LL, 0LL, music_volume_decay);
music_volume_timer = result;
}
return result;
}

original_code:
void warpwarp_music2_w(offs_t offset,data_t data)
{
    stream_update(channel,0);
 music2_latch = data;
 music_volume = 0x7fff;
 if( music2_latch & 16 )
 {
  if( music_volume_timer )
   timer_remove(music_volume_timer);
  music_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.9585))), 0, music_volume_decay);
 }
 else
 {
  if( music_volume_timer )
   timer_remove(music_volume_timer);
  music_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/3.0033))), 0, music_volume_decay);
 }
}

canonical_original_code:
void warpwarp_music2_w(unsigned int offset, unsigned int data)
{
    stream_update(channel,0);
 music2_latch = data;
 music_volume = 0x7fff;
 if( music2_latch & 16 )
 {
  if( music_volume_timer )
   timer_remove(music_volume_timer);
  music_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.9585))), 0, music_volume_decay);
 }
 else
 {
  if( music_volume_timer )
   timer_remove(music_volume_timer);
  music_volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/3.0033))), 0, music_volume_decay);
 }
}


decompiled_code:
__int64 warpwarp_sh_start()
{
char *v0; // rax
char *v1; // rbp
int i; // ebx
double v3; // xmm0_8

v0 = (char *)malloc(0x10000uLL);
decay = v0;
if ( !v0 )
return 1LL;
v1 = v0 + 65534;
for ( i = 0; i != 0x8000; ++i )
{
v1 -= 2;
v3 = (double)i * 0.000244140625;
*((_WORD *)v1 + 1) = (int)(32767.0 / exp(v3));
}
channel = stream_init("WarpWarp", 100LL, *(unsigned int *)(Machine + 836LL), 0LL, warpwarp_sound_update);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
char *v0; // rax
char *v1; // rbp
int i; // ebx
double v3; // xmm0_8

v0 = (char *)malloc(0x10000uLL);
decay = v0;
if ( !v0 )
return 1LL;
v1 = v0 + 65534;
for ( i = 0; i != 0x8000; ++i )
{
v1 -= 2;
v3 = (double)i * 0.000244140625;
*((_WORD *)v1 + 1) = (int)(32767.0 / exp(v3));
}
channel = stream_init("WarpWarp", 100LL, *(unsigned int *)(Machine + 836LL), 0LL, warpwarp_sound_update);
return 0LL;
}

original_code:
int warpwarp_sh_start(const struct MachineSound *msound)
{
 int i;
 decay = (INT16 *) malloc(32768 * sizeof(INT16));
 if( !decay )
  return 1;
    for( i = 0; i < 0x8000; i++ )
  decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096));
 channel = stream_init("WarpWarp", 100, Machine->sample_rate, 0, warpwarp_sound_update);
    return 0;
}

canonical_original_code:
int warpwarp_sh_start(struct MachineSound *msound)
{
 int i;
 decay = (short *) malloc(32768 * sizeof(INT16));
 if( !decay )
  return 1;
    for( i = 0; i < 0x8000; i++ )
  decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096));
 channel = stream_init("WarpWarp", 100, Machine->sample_rate, 0, warpwarp_sound_update);
    return 0;
}

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

return_type: int


decompiled_code:
void warpwarp_sh_stop()
{
if ( decay )
free(decay);
decay = 0LL;
music_volume_timer = 0LL;
sound_volume_timer = 0LL;
}

canonical_decompiled_code:
void func10()
{
if ( decay )
free(decay);
decay = 0LL;
music_volume_timer = 0LL;
sound_volume_timer = 0LL;
}

original_code:
void warpwarp_sh_stop(void)
{
 if( decay )
  free(decay);
 decay = ((void *)0);
 music_volume_timer = ((void *)0);
 sound_volume_timer = ((void *)0);
}

canonical_original_code:
void warpwarp_sh_stop()
{
 if( decay )
  free(decay);
 decay = ((void *)0);
 music_volume_timer = ((void *)0);
 sound_volume_timer = ((void *)0);
}


decompiled_code:
// attributes: thunk
__int64 warpwarp_leds_w()
{
return osd_led_w();
}

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

original_code:
static void warpwarp_leds_w(offs_t offset,data_t data)
{
 osd_led_w(offset,data);
}

canonical_original_code:
static void warpwarp_leds_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,data);
}


decompiled_code:
__int64 __fastcall warpwarp_input_c020_27_r(char a1)
{
return ((int)readinputport(1LL) >> a1) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func12(char a1)
{
return ((int)readinputport(1LL) >> a1) & 1;
}

original_code:
static data_t warpwarp_input_c020_27_r(offs_t offset)
{
 return (readinputport(1) >> offset) & 1;
}

canonical_original_code:
static unsigned int warpwarp_input_c020_27_r(unsigned int offset)
{
 return (readinputport(1) >> offset) & 1;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall warpwarp_input_c000_7_r(char a1)
{
return ((int)readinputport(0LL) >> a1) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1)
{
return ((int)readinputport(0LL) >> a1) & 1;
}

original_code:
static data_t warpwarp_input_c000_7_r(offs_t offset)
{
 return (readinputport(0) >> offset) & 1;
}

canonical_original_code:
static unsigned int warpwarp_input_c000_7_r(unsigned int offset)
{
 return (readinputport(0) >> offset) & 1;
}


original_code:
static data_t warpwarp_input_controller_r(offs_t offset)
{
 int res;
 res = readinputport(2);
 if (res & 1) return 23;
 if (res & 2) return 63;
 if (res & 4) return 111;
 if (res & 8) return 167;
 return 255;
}

canonical_original_code:
static unsigned int warpwarp_input_controller_r(unsigned int offset)
{
 int res;
 res = readinputport(2);
 if (res & 1) return 23;
 if (res & 2) return 63;
 if (res & 4) return 111;
 if (res & 8) return 167;
 return 255;
}

variable_types: res int


decompiled_code:
__int64 __fastcall bitmap_common_w(unsigned __int8 a1, unsigned __int8 a2, int a3)
{
*((_BYTE *)liberatr_videoram + (a1 | (a2 << 8))) = a3 & 0xE0;
return plot_pixel(
*(_QWORD *)(Machine + 768LL),
a1,
a2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a3 >> 5) + 16)));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int8 a2, int a3)
{
*((_BYTE *)liberatr_videoram + (a1 | (a2 << 8))) = a3 & 0xE0;
return plot_pixel(
*(_QWORD *)(Machine + 768LL),
a1,
a2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a3 >> 5) + 16)));
}

original_code:
static inline void bitmap_common_w(UINT8 x, UINT8 y, int data)
{
 int pen;
 liberatr_videoram[(y<<8) | x] = data & 0xe0;
 pen = Machine->pens[(data >> 5) + 0x10];
 plot_pixel(Machine->scrbitmap, x, y, pen);
}

canonical_original_code:
static inline void bitmap_common_w(unsigned char x, unsigned char y, int data)
{
 int pen;
 liberatr_videoram[(y<<8) | x] = data & 0xe0;
 pen = Machine->pens[(data >> 5) + 0x10];
 plot_pixel(Machine->scrbitmap, x, y, pen);
}

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types: data int

variable_types: pen int


decompiled_code:
__int64 __fastcall liberatr_bitmap_xy_w(__int64 a1, int a2)
{
return bitmap_common_w(*liberatr_x, *liberatr_y, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return func0(*liberatr_x, *liberatr_y, a2);
}

original_code:
void liberatr_bitmap_xy_w(offs_t offset,data_t data)
{
 bitmap_common_w(*liberatr_x, *liberatr_y, data);
}

canonical_original_code:
void liberatr_bitmap_xy_w(unsigned int offset, unsigned int data)
{
 bitmap_common_w(*liberatr_x, *liberatr_y, data);
}


decompiled_code:
__int64 __fastcall liberatr_bitmap_w(unsigned int a1, int a2)
{
unsigned __int8 v2; // bp

v2 = a1 >> 6;
*(_BYTE *)(liberatr_bitmapram + a1) = a2;
bitmap_common_w(4 * a1, v2, a2);
bitmap_common_w(4 * a1 + 1, v2, a2);
bitmap_common_w(4 * a1 + 2, v2, a2);
return bitmap_common_w(4 * (unsigned __int8)a1 + 3, v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
unsigned __int8 v2; // bp

v2 = a1 >> 6;
*(_BYTE *)(liberatr_bitmapram + a1) = a2;
func0(4 * a1, v2, a2);
func0(4 * a1 + 1, v2, a2);
func0(4 * a1 + 2, v2, a2);
return func0(4 * (unsigned __int8)a1 + 3, v2, a2);
}

original_code:
void liberatr_bitmap_w(offs_t offset,data_t data)
{
 UINT8 x = (offset & 0x3f) << 2;
 UINT8 y = (offset >> 6);
 liberatr_bitmapram[offset] = data;
    bitmap_common_w(x , y, data);
    bitmap_common_w(x+1, y, data);
    bitmap_common_w(x+2, y, data);
    bitmap_common_w(x+3, y, data);
}

canonical_original_code:
void liberatr_bitmap_w(unsigned int offset, unsigned int data)
{
 unsigned char x = (offset & 0x3f) << 2;
 unsigned char y = (offset >> 6);
 liberatr_bitmapram[offset] = data;
    bitmap_common_w(x , y, data);
    bitmap_common_w(x+1, y, data);
    bitmap_common_w(x+2, y, data);
    bitmap_common_w(x+3, y, data);
}


decompiled_code:
__int64 liberatr_bitmap_xy_r()
{
return *((unsigned __int8 *)liberatr_videoram + ((unsigned __int8)*liberatr_x | ((unsigned __int8)*liberatr_y << 8)));
}

canonical_decompiled_code:
__int64 func3()
{
return *((unsigned __int8 *)liberatr_videoram + ((unsigned __int8)*liberatr_x | ((unsigned __int8)*liberatr_y << 8)));
}

original_code:
data_t liberatr_bitmap_xy_r(offs_t offset)
{
 return liberatr_videoram[((*liberatr_y)<<8) | (*liberatr_x)];
}

canonical_original_code:
unsigned int liberatr_bitmap_xy_r(unsigned int offset)
{
 return liberatr_videoram[((*liberatr_y)<<8) | (*liberatr_x)];
}


decompiled_code:
__int64 liberatr_draw_planet()
{
unsigned int v0; // er15
unsigned __int8 *v1; // rdx
unsigned __int8 v2; // r13
__int64 result; // rax
__int64 v4; // rdx
unsigned __int8 v5; // bl
unsigned int v6; // er12
char v7; // bl
unsigned __int8 *v8; // [rsp+0h] [rbp-58h]
__int64 v9; // [rsp+8h] [rbp-50h]
unsigned __int8 *v10; // [rsp+10h] [rbp-48h]
unsigned __int8 v11; // [rsp+1Eh] [rbp-3Ah]
unsigned __int8 v12; // [rsp+1Fh] [rbp-39h]

v0 = 64;
v1 = (unsigned __int8 *)*((_QWORD *)*(&liberatr_planet_segs + ((*liberatr_planet_select & 0x10) != 0))
+ (unsigned __int8)*liberatr_planet_frame);
do
{
v2 = v1[1];
v10 = v1 + 2;
result = *v1;
v12 = result;
v11 = *(_BYTE *)(liberatr_base_ram + ((unsigned __int8)(v0 - 64) >> 3)) ^ 0xF;
if ( (_BYTE)result )
{
v8 = v1 + 2;
v9 = (__int64)&v1[2 * (unsigned __int8)(result - 1) + 4];
do
{
v4 = *v8;
if ( (*v8 & 0xC) == 12 )
v4 = v11;
v5 = v8[1];
v8 += 2;
v6 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2 * v4);
if ( v5 )
{
v7 = v2 + v5;
do
{
if ( !*((_BYTE *)liberatr_videoram + (int)(v2 | (v0 << 8))) )
plot_pixel(*(_QWORD *)(Machine + 768LL), v2, v0, v6);
++v2;
}
while ( v2 != v7 );
}
}
while ( v8 != (unsigned __int8 *)v9 );
result = v12;
v1 = &v10[2 * v12];
}
else
{
v1 += 2;
}
++v0;
}
while ( v0 != 192 );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er15
unsigned __int8 *v1; // rdx
unsigned __int8 v2; // r13
__int64 result; // rax
__int64 v4; // rdx
unsigned __int8 v5; // bl
unsigned int v6; // er12
char v7; // bl
unsigned __int8 *v8; // [rsp+0h] [rbp-58h]
__int64 v9; // [rsp+8h] [rbp-50h]
unsigned __int8 *v10; // [rsp+10h] [rbp-48h]
unsigned __int8 v11; // [rsp+1Eh] [rbp-3Ah]
unsigned __int8 v12; // [rsp+1Fh] [rbp-39h]

v0 = 64;
v1 = (unsigned __int8 *)*((_QWORD *)*(&liberatr_planet_segs + ((*liberatr_planet_select & 0x10) != 0))
+ (unsigned __int8)*liberatr_planet_frame);
do
{
v2 = v1[1];
v10 = v1 + 2;
result = *v1;
v12 = result;
v11 = *(_BYTE *)(liberatr_base_ram + ((unsigned __int8)(v0 - 64) >> 3)) ^ 0xF;
if ( (_BYTE)result )
{
v8 = v1 + 2;
v9 = (__int64)&v1[2 * (unsigned __int8)(result - 1) + 4];
do
{
v4 = *v8;
if ( (*v8 & 0xC) == 12 )
v4 = v11;
v5 = v8[1];
v8 += 2;
v6 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2 * v4);
if ( v5 )
{
v7 = v2 + v5;
do
{
if ( !*((_BYTE *)liberatr_videoram + (int)(v2 | (v0 << 8))) )
plot_pixel(*(_QWORD *)(Machine + 768LL), v2, v0, v6);
++v2;
}
while ( v2 != v7 );
}
}
while ( v8 != (unsigned __int8 *)v9 );
result = v12;
v1 = &v10[2 * v12];
}
else
{
v1 += 2;
}
++v0;
}
while ( v0 != 192 );
return result;
}

original_code:
static void liberatr_draw_planet(void)
{
 UINT8 latitude;
 UINT8 *buffer;
 buffer = liberatr_planet_segs[ (*liberatr_planet_select >> 4) & 0x01 ]->frame[ *liberatr_planet_frame ];
 for (latitude = 0; latitude < 0x80; latitude++)
 {
  UINT8 base_color, segment, segment_count, x, y;
  base_color = liberatr_base_ram[latitude>>3] ^ 0x0f;
  segment_count = *buffer++;
  x = *buffer++;
  y = 64 + latitude;
  for (segment = 0; segment < segment_count; segment++)
  {
   UINT8 color, segment_length, i;
   UINT16 pen;
   color = *buffer++;
   if ((color & 0x0c) == 0x0c)
    color = base_color;
   pen = Machine->pens[color];
   segment_length = *buffer++;
   for (i = 0; i < segment_length; i++, x++)
   {
    if (!liberatr_videoram[(y<<8) | x])
     plot_pixel(Machine->scrbitmap, x, y, pen);
   }
  }
 }
}

canonical_original_code:
static void liberatr_draw_planet()
{
 unsigned char latitude;
 unsigned char *buffer;
 buffer = liberatr_planet_segs[ (*liberatr_planet_select >> 4) & 0x01 ]->frame[ *liberatr_planet_frame ];
 for (latitude = 0; latitude < 0x80; latitude++)
 {
  unsigned char base_color; unsigned char segment; unsigned char segment_count; unsigned char x; unsigned char y;
  base_color = liberatr_base_ram[latitude>>3] ^ 0x0f;
  segment_count = *buffer++;
  x = *buffer++;
  y = 64 + latitude;
  for (segment = 0; segment < segment_count; segment++)
  {
   unsigned char color; unsigned char segment_length; unsigned char i;
   unsigned short pen;
   color = *buffer++;
   if ((color & 0x0c) == 0x0c)
    color = base_color;
   pen = Machine->pens[color];
   segment_length = *buffer++;
   for (i = 0; i < segment_length; i++, x++)
   {
    if (!liberatr_videoram[(y<<8) | x])
     plot_pixel(Machine->scrbitmap, x, y, pen);
   }
  }
 }
}

variable_types:
latitude
unsigned char

variable_types:
buffer
unsigned char *

variable_types:
segment
unsigned char

variable_types:
color
unsigned char

variable_types:
i
unsigned char

variable_types:
pen
unsigned short


decompiled_code:
__int64 __fastcall liberatr_colorram_w(int a1, int a2)
{
unsigned int v2; // esi
int v3; // er8
unsigned int v4; // er9

v2 = ~a2;
v3 = 36 * ((v2 >> 3) & 7) + 3;
if ( !(36 * ((v2 >> 3) & 7)) )
LOBYTE(v3) = 0;
v4 = a1 ^ 0xF;
if ( (a1 & 0x10) != 0 )
v4 = penmap_0[a1 & 7];
return palette_change_color(v4, (unsigned __int8)v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
unsigned int v2; // esi
int v3; // er8
unsigned int v4; // er9

v2 = ~a2;
v3 = 36 * ((v2 >> 3) & 7) + 3;
if ( !(36 * ((v2 >> 3) & 7)) )
LOBYTE(v3) = 0;
v4 = a1 ^ 0xF;
if ( (a1 & 0x10) != 0 )
v4 = penmap_0[a1 & 7];
return palette_change_color(v4, (unsigned __int8)v3);
}

original_code:
void liberatr_colorram_w(offs_t offset,data_t data)
{
 UINT8 r,g,b;
 static UINT8 penmap[] = {0x10,0x12,0x14,0x16,0x11,0x13,0x15,0x17};
 r = ((~data >> 3) & 0x07) * 0x24 + 3; if (r == 3) r = 0;
 g = ((~data ) & 0x07) * 0x24 + 3; if (g == 3) g = 0;
 b = ((~data >> 5) & 0x06) * 0x24 + 3; if (b == 3) b = 0;
 if (offset & 0x10)
 {
  offset = penmap[offset & 0x07];
  }
 else
 {
  offset ^= 0x0f;
 }
 palette_change_color(offset,r,g,b);
}

canonical_original_code:
void liberatr_colorram_w(unsigned int offset, unsigned int data)
{
 unsigned char r; unsigned char g; unsigned char b;
 static unsigned char penmap[] = {0x10,0x12,0x14,0x16,0x11,0x13,0x15,0x17};
 r = ((~data >> 3) & 0x07) * 0x24 + 3; if (r == 3) r = 0;
 g = ((~data ) & 0x07) * 0x24 + 3; if (g == 3) g = 0;
 b = ((~data >> 5) & 0x06) * 0x24 + 3; if (b == 3) b = 0;
 if (offset & 0x10)
 {
  offset = penmap[offset & 0x07];
  }
 else
 {
  offset ^= 0x0f;
 }
 palette_change_color(offset,r,g,b);
}

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types:
penmap
unsigned char []


decompiled_code:
void liberatr_vh_stop()
{
_QWORD *v0; // r8
int i; // ebx
void *v2; // rdi
_QWORD *v3; // r8
int j; // ebx
void *v5; // rdi

if ( liberatr_videoram )
{
free(liberatr_videoram);
liberatr_videoram = 0LL;
}
v0 = liberatr_planet_segs;
if ( liberatr_planet_segs )
{
for ( i = 0; i != 256; ++i )
{
v2 = (void *)v0[i];
if ( v2 )
{
free(v2);
v0 = liberatr_planet_segs;
}
}
free(v0);
liberatr_planet_segs = 0LL;
}
v3 = ptr;
if ( ptr )
{
for ( j = 0; j != 256; ++j )
{
v5 = (void *)v3[j];
if ( v5 )
{
free(v5);
v3 = ptr;
}
}
free(v3);
ptr = 0LL;
}
}

canonical_decompiled_code:
void func7()
{
_QWORD *v0; // r8
int i; // ebx
void *v2; // rdi
_QWORD *v3; // r8
int j; // ebx
void *v5; // rdi

if ( liberatr_videoram )
{
free(liberatr_videoram);
liberatr_videoram = 0LL;
}
v0 = liberatr_planet_segs;
if ( liberatr_planet_segs )
{
for ( i = 0; i != 256; ++i )
{
v2 = (void *)v0[i];
if ( v2 )
{
free(v2);
v0 = liberatr_planet_segs;
}
}
free(v0);
liberatr_planet_segs = 0LL;
}
v3 = ptr;
if ( ptr )
{
for ( j = 0; j != 256; ++j )
{
v5 = (void *)v3[j];
if ( v5 )
{
free(v5);
v3 = ptr;
}
}
free(v3);
ptr = 0LL;
}
}

original_code:
void liberatr_vh_stop(void)
{
 int i;
 if (liberatr_videoram)
 {
  free(liberatr_videoram);
  liberatr_videoram = 0;
 }
 if (liberatr_planet_segs[0])
 {
  for (i = 0; i < 256; i++)
   if (liberatr_planet_segs[0]->frame[i])
    free(liberatr_planet_segs[0]->frame[i]);
  free(liberatr_planet_segs[0]);
  liberatr_planet_segs[0] = 0;
 }
 if (liberatr_planet_segs[1])
 {
  for (i = 0; i < 256; i++)
   if (liberatr_planet_segs[1]->frame[i])
    free(liberatr_planet_segs[1]->frame[i]);
  free(liberatr_planet_segs[1]);
  liberatr_planet_segs[1] = 0;
 }
}

canonical_original_code:
void liberatr_vh_stop()
{
 int i;
 if (liberatr_videoram)
 {
  free(liberatr_videoram);
  liberatr_videoram = 0;
 }
 if (liberatr_planet_segs[0])
 {
  for (i = 0; i < 256; i++)
   if (liberatr_planet_segs[0]->frame[i])
    free(liberatr_planet_segs[0]->frame[i]);
  free(liberatr_planet_segs[0]);
  liberatr_planet_segs[0] = 0;
 }
 if (liberatr_planet_segs[1])
 {
  for (i = 0; i < 256; i++)
   if (liberatr_planet_segs[1]->frame[i])
    free(liberatr_planet_segs[1]->frame[i]);
  free(liberatr_planet_segs[1]);
  liberatr_planet_segs[1] = 0;
 }
}

variable_types: i int


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

liberatr_planet_segs = 0LL;
ptr = 0LL;
liberatr_videoram = malloc(
*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL));
if ( !liberatr_videoram
|| (liberatr_planet_segs = calloc(0x800uLL, 1uLL)) == 0LL
|| (ptr = calloc(0x800uLL, 1uLL)) == 0LL
|| (unsigned int)liberatr_init_planet(0)
|| (result = liberatr_init_planet(1), (_DWORD)result) )
{
liberatr_vh_stop();
result = 1LL;
}
return result;
}

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

liberatr_planet_segs = 0LL;
ptr = 0LL;
liberatr_videoram = malloc(
*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL));
if ( !liberatr_videoram
|| (liberatr_planet_segs = calloc(0x800uLL, 1uLL)) == 0LL
|| (ptr = calloc(0x800uLL, 1uLL)) == 0LL
|| (unsigned int)func6(0)
|| (result = func6(1), (_DWORD)result) )
{
func7();
result = 1LL;
}
return result;
}

original_code:
int liberatr_vh_start(void)
{
    liberatr_videoram = 0;
    liberatr_planet_segs[0] = 0;
    liberatr_planet_segs[1] = 0;
 if ((liberatr_videoram = (UINT8*)malloc(Machine->drv->screen_width * Machine->drv->screen_height)) == 0)
 {
  liberatr_vh_stop();
  return 1;
 }
 if (((liberatr_planet_segs[0] = (Liberator_Planet*)malloc(sizeof(Liberator_Planet))) == 0) ||
     ((liberatr_planet_segs[1] = (Liberator_Planet*)malloc(sizeof(Liberator_Planet))) == 0))
 {
  liberatr_vh_stop();
  return 1;
 }
 memset(liberatr_planet_segs[0], 0, sizeof(Liberator_Planet));
 memset(liberatr_planet_segs[1], 0, sizeof(Liberator_Planet));
 if (liberatr_init_planet(0) ||
  liberatr_init_planet(1))
 {
  liberatr_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int liberatr_vh_start()
{
    liberatr_videoram = 0;
    liberatr_planet_segs[0] = 0;
    liberatr_planet_segs[1] = 0;
 if ((liberatr_videoram = (unsigned char *)malloc(Machine->drv->screen_width * Machine->drv->screen_height)) == 0)
 {
  liberatr_vh_stop();
  return 1;
 }
 if (((liberatr_planet_segs[0] = (struct Liberator_Planet *)malloc(sizeof(Liberator_Planet))) == 0) ||
     ((liberatr_planet_segs[1] = (struct Liberator_Planet *)malloc(sizeof(Liberator_Planet))) == 0))
 {
  liberatr_vh_stop();
  return 1;
 }
 memset(liberatr_planet_segs[0], 0, sizeof(Liberator_Planet));
 memset(liberatr_planet_segs[1], 0, sizeof(Liberator_Planet));
 if (liberatr_init_planet(0) ||
  liberatr_init_planet(1))
 {
  liberatr_vh_stop();
  return 1;
 }
 return 0;
}

user_defined_types: struct Liberator_Planet { unsigned char *frame[256]; }


decompiled_code:
__int64 __fastcall liberatr_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v2; // rax
char v3; // bp
char v4; // r12
int v5; // eax

v2 = palette_recalc();
if ( a2 || v2 )
{
v3 = *liberatr_x;
v4 = *liberatr_y;
for ( *liberatr_y = *(_DWORD *)(Machine + 784LL);
(unsigned __int8)*liberatr_y < *(int *)(Machine + 788LL);
++*liberatr_y )
{
for ( *liberatr_x = *(_DWORD *)(Machine + 776LL);
(unsigned __int8)*liberatr_x < *(int *)(Machine + 780LL);
++*liberatr_x )
{
v5 = liberatr_bitmap_xy_r(0LL);
liberatr_bitmap_xy_w(0LL, v5);
}
}
*liberatr_y = v4;
*liberatr_x = v3;
}
return liberatr_draw_planet();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 v2; // rax
char v3; // bp
char v4; // r12
int v5; // eax

v2 = palette_recalc();
if ( a2 || v2 )
{
v3 = *liberatr_x;
v4 = *liberatr_y;
for ( *liberatr_y = *(_DWORD *)(Machine + 784LL);
(unsigned __int8)*liberatr_y < *(int *)(Machine + 788LL);
++*liberatr_y )
{
for ( *liberatr_x = *(_DWORD *)(Machine + 776LL);
(unsigned __int8)*liberatr_x < *(int *)(Machine + 780LL);
++*liberatr_x )
{
v5 = func3(0LL);
func1(0LL, v5);
}
}
*liberatr_y = v4;
*liberatr_x = v3;
}
return func4();
}

original_code:
void liberatr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (palette_recalc() || full_refresh)
 {
  UINT8 liberatr_y_save = *liberatr_y;
  UINT8 liberatr_x_save = *liberatr_x;
  for (*liberatr_y = Machine->visible_area.min_y; *liberatr_y < Machine->visible_area.max_y; (*liberatr_y)++)
  {
   for (*liberatr_x = Machine->visible_area.min_x; *liberatr_x < Machine->visible_area.max_x; (*liberatr_x)++)
   {
    liberatr_bitmap_xy_w(0, liberatr_bitmap_xy_r(0));
   }
  }
  *liberatr_y = liberatr_y_save;
  *liberatr_x = liberatr_x_save;
 }
 liberatr_draw_planet();
}

canonical_original_code:
void liberatr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (palette_recalc() || full_refresh)
 {
  unsigned char liberatr_y_save = *liberatr_y;
  unsigned char liberatr_x_save = *liberatr_x;
  for (*liberatr_y = Machine->visible_area.min_y; *liberatr_y < Machine->visible_area.max_y; (*liberatr_y)++)
  {
   for (*liberatr_x = Machine->visible_area.min_x; *liberatr_x < Machine->visible_area.max_x; (*liberatr_x)++)
   {
    liberatr_bitmap_xy_w(0, liberatr_bitmap_xy_r(0));
   }
  }
  *liberatr_y = liberatr_y_save;
  *liberatr_x = liberatr_x_save;
 }
 liberatr_draw_planet();
}

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


decompiled_code:
__int64 __fastcall liberatr_coin_counter_w(int a1)
{
return coin_counter_w(a1 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return coin_counter_w(a1 ^ 1u);
}

original_code:
static void liberatr_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(offset ^ 0x01, data);
}

canonical_original_code:
static void liberatr_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(offset ^ 0x01, data);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall liberatr_led_w(__int64 a1, unsigned int a2)
{
return osd_led_w(a1, (a2 >> 4) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
return osd_led_w(a1, (a2 >> 4) & 1);
}

original_code:
static void liberatr_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset, (data >> 4) & 0x01);
}

canonical_original_code:
static void liberatr_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset, (data >> 4) & 0x01);
}


decompiled_code:
__int64 liberatr_input_port_0_r()
{
char v1; // bl

if ( !*(_BYTE *)liberatr_ctrld )
return input_port_0_r();
v1 = input_port_4_r(0LL);
return v1 & 0xF | (unsigned int)(unsigned __int8)(16 * input_port_5_r(0LL));
}

canonical_decompiled_code:
__int64 func12()
{
char v1; // bl

if ( !*(_BYTE *)liberatr_ctrld )
return input_port_0_r();
v1 = input_port_4_r(0LL);
return v1 & 0xF | (unsigned int)(unsigned __int8)(16 * input_port_5_r(0LL));
}

original_code:
static data_t liberatr_input_port_0_r(offs_t offset)
{
 int res ;
 int xdelta, ydelta;
 if(*liberatr_ctrld)
 {
  xdelta = input_port_4_r(0);
  ydelta = input_port_5_r(0);
  res = ( ((ydelta << 4) & 0xf0) | (xdelta & 0x0f) );
 }
 else
 {
  res = input_port_0_r(offset);
 }
 return res;
}

canonical_original_code:
static unsigned int liberatr_input_port_0_r(unsigned int offset)
{
 int res;
 int xdelta; int ydelta;
 if(*liberatr_ctrld)
 {
  xdelta = input_port_4_r(0);
  ydelta = input_port_5_r(0);
  res = ( ((ydelta << 4) & 0xf0) | (xdelta & 0x0f) );
 }
 else
 {
  res = input_port_0_r(offset);
 }
 return res;
}

variable_types: res int

variable_types: xdelta int

variable_types: ydelta int


decompiled_code:
__int64 flstory_68705_portA_r()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

canonical_decompiled_code:
__int64 func0()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

original_code:
data_t flstory_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

canonical_original_code:
unsigned int flstory_68705_portA_r(unsigned int offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}


decompiled_code:
void __fastcall flstory_68705_portA_w(__int64 a1, char a2)
{
portA_out = a2;
}

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

original_code:
void flstory_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

canonical_original_code:
void flstory_68705_portA_w(unsigned int offset, unsigned int data)
{
 portA_out = data;
}


decompiled_code:
void __fastcall flstory_68705_ddrA_w(__int64 a1, char a2)
{
ddrA = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
ddrA = a2;
}

original_code:
void flstory_68705_ddrA_w(offs_t offset,data_t data)
{
 ddrA = data;
}

canonical_original_code:
void flstory_68705_ddrA_w(unsigned int offset, unsigned int data)
{
 ddrA = data;
}


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


decompiled_code:
__int64 flstory_68705_portC_r()
{
unsigned __int8 v0; // cl

portC_in = 0;
v0 = 0;
if ( main_sent )
{
portC_in = 1;
v0 = 1;
}
if ( !mcu_sent )
{
v0 |= 2u;
portC_in = v0;
}
return (unsigned __int8)(ddrC & portC_out) | v0 & ~(unsigned __int8)ddrC;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int8 v0; // cl

portC_in = 0;
v0 = 0;
if ( main_sent )
{
portC_in = 1;
v0 = 1;
}
if ( !mcu_sent )
{
v0 |= 2u;
portC_in = v0;
}
return (unsigned __int8)(ddrC & portC_out) | v0 & ~(unsigned __int8)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);
}


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


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

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

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

result = *(_QWORD *)(Machine + 824LL);
v3 = *(unsigned int *)(result + 700);
if ( (_DWORD)v3 )
{
for ( result = 0LL; result != v3; ++result )
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
}
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 *


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
__int64 v4; // rsi

result = (unsigned __int8)ddrB;
if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
v4 = (unsigned __int8)from_main;
portA_in = from_main;
if ( main_sent )
{
cpu_set_irq_line(2LL, 0LL, 0LL);
v4 = (unsigned __int8)portA_in;
}
main_sent = 0;
logerror("read command %02x from main cpu\n", v4);
result = (unsigned __int8)ddrB;
}
if ( (result & 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;
mcu_sent = 1;
from_mcu = portA_out;
}
portB_out = a2;
return result;
}

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

result = (unsigned __int8)ddrB;
if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
v4 = (unsigned __int8)from_main;
portA_in = from_main;
if ( main_sent )
{
cpu_set_irq_line(2LL, 0LL, 0LL);
v4 = (unsigned __int8)portA_in;
}
main_sent = 0;
logerror("read command %02x from main cpu\n", v4);
result = (unsigned __int8)ddrB;
}
if ( (result & 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;
mcu_sent = 1;
from_mcu = portA_out;
}
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; // er12
unsigned int v1; // eax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // er12
unsigned int v1; // eax
__int64 result; // rax

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

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


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)
{
char v1; // ah
__int64 v2; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func17(__int16 a1)
{
char v1; // ah
__int64 v2; // rdi
__int64 result; // rax

v1 = HIBYTE(a1);
v2 = (unsigned int)(unsigned __int8)a1 + (palette_bank << 8);
if ( (v1 & 1) != 0 )
result = paletteram_xxxxBBBBGGGGRRRR_split2_w(v2);
else
result = paletteram_xxxxBBBBGGGGRRRR_split1_w(v2);
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; // er13
__int64 v2; // r12
__int64 v3; // rcx
unsigned __int64 v4; // r15
__int16 v5; // cx
int v6; // er14
__int64 v7; // rbx
unsigned int v8; // er13
char v9; // cl
size_t *result; // rax
int v11; // er12
__int64 v12; // r13
__int16 v13; // r8
int v14; // esi
unsigned int v15; // [rsp+0h] [rbp-58h]
unsigned int v16; // [rsp+Ch] [rbp-4Ch]

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1;
do
{
v3 = v2 + 1;
if ( *((_BYTE *)dirtybuffer + v2) || *((_BYTE *)dirtybuffer + v2 + 1) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((4 * *(unsigned __int8 *)(videoram + v3)) & 0x300u) + 3072,
*(_BYTE *)(videoram + v3) & 7,
*(_BYTE *)(videoram + v3) & 8,
1LL,
(4 * (_BYTE)v1) & 0xF8,
(unsigned int)(8 * (v1 >> 6)),
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
{
while ( 1 )
{
v5 = *(unsigned __int8 *)(spriteram + v4 + 1);
v6 = *(unsigned __int8 *)(spriteram + v4 + 3);
v7 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v4);
v8 = *(unsigned __int8 *)(spriteram + v4 + 2) + ((16 * v5) & 0x300);
v16 = *(_BYTE *)(spriteram + v4 + 1) & 0x80;
v15 = *(_BYTE *)(spriteram + v4 + 1) & 0x40;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v8,
v5 & 0xF,
*(_BYTE *)(spriteram + v4 + 1) & 0x40,
*(_BYTE *)(spriteram + v4 + 1) & 0x80,
*(unsigned __int8 *)(spriteram + v4 + 3),
v7,
Machine + 776LL,
2LL,
0LL);
if ( v6 > 240 )
break;
v4 += 4LL;
if ( spriteram_size <= v4 )
goto LABEL_14;
}
v9 = *(_BYTE *)(spriteram + v4 + 1);
v4 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v8,
v9 & 0xF,
v15,
v16,
(unsigned int)(v6 - 256),
v7,
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v4 );
}
LABEL_14:
result = &videoram_size;
v11 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v12 = v11 + 1LL;
do
{
while ( 1 )
{
result = (size_t *)videoram;
v13 = *(unsigned __int8 *)(videoram + v12);
if ( (v13 & 0x20) != 0 )
break;
v12 -= 2LL;
v11 -= 2;
if ( v11 < 0 )
return result;
}
v14 = *(unsigned __int8 *)(videoram + v12 - 1);
v12 -= 2LL;
result = (size_t *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v14 + ((4 * v13) & 0x300u) + 3072,
v13 & 7,
v13 & 8,
1LL,
(unsigned __int8)(4 * v11) & 0xF8,
(unsigned int)(8 * (v11 >> 6)),
Machine + 776LL,
2LL,
0LL);
v11 -= 2;
}
while ( v11 >= 0 );
}
return result;
}

canonical_decompiled_code:
size_t *__fastcall func18(__int64 a1)
{
int v1; // er13
__int64 v2; // r12
__int64 v3; // rcx
unsigned __int64 v4; // r15
__int16 v5; // cx
int v6; // er14
__int64 v7; // rbx
unsigned int v8; // er13
char v9; // cl
size_t *result; // rax
int v11; // er12
__int64 v12; // r13
__int16 v13; // r8
int v14; // esi
unsigned int v15; // [rsp+0h] [rbp-58h]
unsigned int v16; // [rsp+Ch] [rbp-4Ch]

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1;
do
{
v3 = v2 + 1;
if ( *((_BYTE *)dirtybuffer + v2) || *((_BYTE *)dirtybuffer + v2 + 1) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((4 * *(unsigned __int8 *)(videoram + v3)) & 0x300u) + 3072,
*(_BYTE *)(videoram + v3) & 7,
*(_BYTE *)(videoram + v3) & 8,
1LL,
(4 * (_BYTE)v1) & 0xF8,
(unsigned int)(8 * (v1 >> 6)),
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
{
while ( 1 )
{
v5 = *(unsigned __int8 *)(spriteram + v4 + 1);
v6 = *(unsigned __int8 *)(spriteram + v4 + 3);
v7 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + v4);
v8 = *(unsigned __int8 *)(spriteram + v4 + 2) + ((16 * v5) & 0x300);
v16 = *(_BYTE *)(spriteram + v4 + 1) & 0x80;
v15 = *(_BYTE *)(spriteram + v4 + 1) & 0x40;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v8,
v5 & 0xF,
*(_BYTE *)(spriteram + v4 + 1) & 0x40,
*(_BYTE *)(spriteram + v4 + 1) & 0x80,
*(unsigned __int8 *)(spriteram + v4 + 3),
v7,
Machine + 776LL,
2LL,
0LL);
if ( v6 > 240 )
break;
v4 += 4LL;
if ( spriteram_size <= v4 )
goto LABEL_14;
}
v9 = *(_BYTE *)(spriteram + v4 + 1);
v4 += 4LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v8,
v9 & 0xF,
v15,
v16,
(unsigned int)(v6 - 256),
v7,
Machine + 776LL,
2LL,
0LL);
}
while ( spriteram_size > v4 );
}
LABEL_14:
result = &videoram_size;
v11 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v12 = v11 + 1LL;
do
{
while ( 1 )
{
result = (size_t *)videoram;
v13 = *(unsigned __int8 *)(videoram + v12);
if ( (v13 & 0x20) != 0 )
break;
v12 -= 2LL;
v11 -= 2;
if ( v11 < 0 )
return result;
}
v14 = *(unsigned __int8 *)(videoram + v12 - 1);
v12 -= 2LL;
result = (size_t *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v14 + ((4 * v13) & 0x300u) + 3072,
v13 & 7,
v13 & 8,
1LL,
(unsigned __int8)(4 * v11) & 0xF8,
(unsigned int)(8 * (v11 >> 6)),
Machine + 776LL,
2LL,
0LL);
v11 -= 2;
}
while ( v11 >= 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: offs int

variable_types: sx int

variable_types: sy int

variable_types: code int

variable_types: flipx int

variable_types: flipy int

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


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
{
++v0;
result = (unsigned int)(28160 / v1);
*(v0 - 1) = (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
{
++v0;
result = (unsigned int)(28160 / v1);
*(v0 - 1) = (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: i int

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 v5; // rbp
int v6; // edx
__int64 v7; // rsi

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

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

result = (char *)&kpcm + 80 * a1;
*((_QWORD *)result + 8) = a2;
*((_QWORD *)result + 9) = a3;
return result;
}

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

result = (char *)&kpcm + 80 * a1;
*((_QWORD *)result + 8) = a2;
*((_QWORD *)result + 9) = 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 = HIDWORD(m6840_timerMSB);
break;
case 10:
result = HIDWORD(m6840_timerLSB);
break;
case 12:
result = (unsigned int)dword_AC8;
break;
case 14:
result = (unsigned int)dword_AD8;
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 = HIDWORD(m6840_timerMSB);
break;
case 10:
result = HIDWORD(m6840_timerLSB);
break;
case 12:
result = (unsigned int)dword_AC8;
break;
case 14:
result = (unsigned int)dword_AD8;
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:
__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)
{
int v2; // ecx
__int64 result; // rax

switch ( a1 )
{
case 0:
v2 = m6840_cr_select;
m6840_cr[m6840_cr_select] = a2;
if ( !v2 && (a2 & 1) != 0 )
{
result = 0xFF000000FFLL;
dword_AD8 = 255;
m6840_timerLSB = 0xFF000000FFLL;
m6840_timerMSB = 0xFF000000FFLL;
dword_AC8 = 255;
}
break;
case 2:
dword_AB4 = a2;
result = 2 * (unsigned int)((a2 & 1) == 0);
m6840_cr_select = 2 * ((a2 & 1) == 0);
break;
case 4:
LODWORD(m6840_timerMSB) = a2;
m6840_status &= 0xFFFFFFFE;
break;
case 6:
LODWORD(m6840_timerLSB) = a2;
m6840_status &= 0xFFFFFFFE;
break;
case 8:
m6840_status &= 0xFFFFFFFD;
result = cchasm_6840_irq(0);
HIDWORD(m6840_timerMSB) = a2;
if ( (dword_AB4 & 0x38) == 0 )
result = timer_set(1342 * (HIDWORD(m6840_timerLSB) | (a2 << 8)), 0LL, timer_2_timeout);
break;
case 10:
m6840_status &= 0xFFFFFFFD;
result = cchasm_6840_irq(0);
HIDWORD(m6840_timerLSB) = a2;
break;
case 12:
dword_AC8 = a2;
m6840_status &= 0xFFFFFFFB;
break;
case 14:
m6840_status &= 0xFFFFFFFB;
dword_AD8 = a2;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
v2 = m6840_cr_select;
m6840_cr[m6840_cr_select] = a2;
if ( !v2 && (a2 & 1) != 0 )
{
result = 0xFF000000FFLL;
dword_AD8 = 255;
m6840_timerLSB = 0xFF000000FFLL;
m6840_timerMSB = 0xFF000000FFLL;
dword_AC8 = 255;
}
break;
case 2:
dword_AB4 = a2;
result = 2 * (unsigned int)((a2 & 1) == 0);
m6840_cr_select = 2 * ((a2 & 1) == 0);
break;
case 4:
LODWORD(m6840_timerMSB) = a2;
m6840_status &= 0xFFFFFFFE;
break;
case 6:
LODWORD(m6840_timerLSB) = a2;
m6840_status &= 0xFFFFFFFE;
break;
case 8:
m6840_status &= 0xFFFFFFFD;
result = func4(0);
HIDWORD(m6840_timerMSB) = a2;
if ( (dword_AB4 & 0x38) == 0 )
result = timer_set(1342 * (HIDWORD(m6840_timerLSB) | (a2 << 8)), 0LL, timer_2_timeout);
break;
case 10:
m6840_status &= 0xFFFFFFFD;
result = func4(0);
HIDWORD(m6840_timerLSB) = a2;
break;
case 12:
dword_AC8 = a2;
m6840_status &= 0xFFFFFFFB;
break;
case 14:
m6840_status &= 0xFFFFFFFB;
dword_AD8 = 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_AB4 & 0x40) != 0 )
{
m6840_status |= 0x82u;
result = cchasm_6840_irq(1u);
}
return result;
}

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

if ( (dword_AB4 & 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()
{
unsigned int v0; // er15
unsigned int v1; // er14
int v2; // er13
int v3; // ebp
int v4; // ecx
__int64 v5; // rsi
int v6; // er10
int v7; // er9
__int64 v8; // rdx
int v9; // eax
int v10; // ebx
int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]
int v15; // [rsp+Ch] [rbp-3Ch]

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

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er15
unsigned int v1; // er14
int v2; // er13
int v3; // ebp
int v4; // ecx
__int64 v5; // rsi
int v6; // er10
int v7; // er9
__int64 v8; // rdx
int v9; // eax
int v10; // ebx
int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]
int v15; // [rsp+Ch] [rbp-3Ch]

v0 = 0;
v1 = 0;
v2 = 1;
v3 = 0;
vector_clear_list();
v4 = 0;
v5 = 0LL;
v6 = 0;
v7 = 0;
v8 = cchasm_ram;
while ( 1 )
{
v9 = (int)*(unsigned __int16 *)(v8 + v3) >> 12;
v10 = *(_WORD *)(v8 + v3) & 0xFFF;
if ( *(unsigned __int16 *)(v8 + v3) > 0x2FFFu && (*(_WORD *)(v8 + v3) & 0x800) != 0 )
v10 |= 0xFFFFF000;
v3 += 2;
switch ( v9 )
{
case 1:
v3 = v10 - 2816;
break;
case 2:
v1 = ((v10 ^ 0xFFF) >> 2) & 3 | ((v10 ^ 0xFFF) >> 3) & 0x1C | ((v10 ^ 0xFFF) >> 4) & 0xE0;
break;
case 3:
v6 = 32 * v10;
break;
case 4:
v4 = 1;
v5 = (unsigned int)(ycenter + (v10 << 16));
break;
case 5:
v7 = 32 * v10;
break;
case 6:
v4 = 1;
v0 = xcenter - (v10 << 16);
break;
case 7:
if ( v4 )
{
v14 = v7;
v12 = v6;
vector_add_point(v0, v5, 0LL, 0LL);
v7 = v14;
v6 = v12;
}
v0 -= v7 * v10;
v5 = (unsigned int)(v6 * v10 + v5);
v2 += abs32(v10);
if ( v1 )
{
v15 = v7;
v13 = v6;
vector_add_point(v0, v5, v1, 255LL);
v5 = (unsigned int)v5;
v6 = v13;
v4 = 0;
v7 = v15;
}
else
{
v4 = 1;
}
v8 = cchasm_ram;
break;
default:
return timer_set((unsigned int)(178 * v2), 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 + 784LL) + *(_DWORD *)(Machine + 788LL);
xcenter = ((*(_DWORD *)(Machine + 780LL) + *(_DWORD *)(Machine + 776LL)) / 2) << 16;
ycenter = (v0 / 2) << 16;
vector_set_shift(16LL);
return vector_vh_start();
}

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

v0 = *(_DWORD *)(Machine + 784LL) + *(_DWORD *)(Machine + 788LL);
xcenter = ((*(_DWORD *)(Machine + 780LL) + *(_DWORD *)(Machine + 776LL)) / 2) << 16;
ycenter = (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:
// attributes: thunk
__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
unsigned int v3; // eax

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

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

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

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;
HIDWORD(sound_command) = a2 >> 8;
z80ctc_0_trg2_w(0LL, 1LL);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
}
else
{
LODWORD(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;
HIDWORD(sound_command) = a2 >> 8;
z80ctc_0_trg2_w(0LL, 1LL);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
}
else
{
LODWORD(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