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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

v0 = cpu_gettotalcycles();
return ((unsigned __int8)((3775147220LL * v0) >> 41) - (unsigned __int8)((4 * v0) >> 31)) & 0xF;
}

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

v0 = cpu_gettotalcycles();
return ((unsigned __int8)((3775147220LL * v0) >> 41) - (unsigned __int8)((4 * v0) >> 31)) & 0xF;
}

original_code:
data_t circusc_sh_timer_r(offs_t offset)
{
 int clock;
 clock = (cpu_gettotalcycles()*4) / (14318180/6144);
 return clock & 0xF;
}

canonical_original_code:
unsigned int circusc_sh_timer_r(unsigned int offset)
{
 int clock;
 clock = (cpu_gettotalcycles()*4) / (14318180/6144);
 return clock & 0xF;
}

variable_types: clock int

return_type: unsigned int


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

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

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

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


decompiled_code:
__int64 circusc_dac_w()
{
return DAC_data_w(0LL);
}

canonical_decompiled_code:
__int64 func4()
{
return DAC_data_w(0LL);
}

original_code:
void circusc_dac_w(offs_t offset,data_t data)
{
 DAC_data_w(0,data);
}

canonical_original_code:
void circusc_dac_w(unsigned int offset, unsigned int data)
{
 DAC_data_w(0,data);
}


decompiled_code:
__int64 init_circusc()
{
return konami1_decode();
}

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

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

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


decompiled_code:
void init_timeplt()
{
sprite_multiplex_hack = 1;
}

canonical_decompiled_code:
void func0()
{
sprite_multiplex_hack = 1;
}

original_code:
void init_timeplt(void)
{
 sprite_multiplex_hack = 1;
}


decompiled_code:
void init_psurge()
{
sprite_multiplex_hack = 0;
}

canonical_decompiled_code:
void func1()
{
sprite_multiplex_hack = 0;
}

original_code:
void init_psurge(void)
{
 sprite_multiplex_hack = 0;
}


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

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

variable_types: i int


decompiled_code:
__int64 psurge_protection_r()
{
return 128LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 128LL;
}

original_code:
static data_t psurge_protection_r(offs_t offset)
{
 return 0x80;
}

canonical_original_code:
static unsigned int psurge_protection_r(unsigned int offset)
{
 return 0x80;
}


decompiled_code:
__int64 __fastcall timeplt_filter_w(unsigned int a1)
{
filter_w(0, 0, (unsigned __int8)a1 >> 6);
filter_w(0, 1, BYTE1(a1) & 3);
filter_w(0, 2, (a1 >> 10) & 3);
filter_w(1, 0, a1 & 3);
filter_w(1, 1, (a1 >> 2) & 3);
return filter_w(1, 2, (a1 >> 4) & 3);
}

original_code:
static void timeplt_filter_w(offs_t offset,data_t data)
{
 filter_w(0, 0, (offset >> 6) & 3);
 filter_w(0, 1, (offset >> 8) & 3);
 filter_w(0, 2, (offset >> 10) & 3);
 filter_w(1, 0, (offset >> 0) & 3);
 filter_w(1, 1, (offset >> 2) & 3);
 filter_w(1, 2, (offset >> 4) & 3);
}

canonical_original_code:
static void timeplt_filter_w(unsigned int offset, unsigned int data)
{
 filter_w(0, 0, (offset >> 6) & 3);
 filter_w(0, 1, (offset >> 8) & 3);
 filter_w(0, 2, (offset >> 10) & 3);
 filter_w(1, 0, (offset >> 0) & 3);
 filter_w(1, 1, (offset >> 2) & 3);
 filter_w(1, 2, (offset >> 4) & 3);
}


decompiled_code:
__int64 timeplt_portB_r()
{
int v0; // ecx

v0 = cpu_gettotalcycles();
clock_1 = (clock_1 + v0 - last_totalcycles_2) % 5120;
last_totalcycles_2 = v0;
return timeplt_timer[clock_1 / 512];
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // ecx

v0 = cpu_gettotalcycles();
clock_1 = (clock_1 + v0 - last_totalcycles_2) % 5120;
last_totalcycles_2 = v0;
return timeplt_timer[clock_1 / 512];
}

original_code:
static data_t timeplt_portB_r(offs_t offset)
{
 static int last_totalcycles = 0;
 static int clock;
 int current_totalcycles;
 current_totalcycles = cpu_gettotalcycles();
 clock = (clock + (current_totalcycles-last_totalcycles)) % 5120;
 last_totalcycles = current_totalcycles;
 return timeplt_timer[clock/512];
}

canonical_original_code:
static unsigned int timeplt_portB_r(unsigned int offset)
{
 static int last_totalcycles = 0;
 static int clock;
 int current_totalcycles;
 current_totalcycles = cpu_gettotalcycles();
 clock = (clock + (current_totalcycles-last_totalcycles)) % 5120;
 last_totalcycles = current_totalcycles;
 return timeplt_timer[clock/512];
}


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

if ( !last_0 && a2 )
result = cpu_cause_interrupt(1LL, 255LL);
last_0 = a2;
return result;
}

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

if ( !last_0 && a2 )
result = cpu_cause_interrupt(1LL, 255LL);
last_0 = a2;
return result;
}

original_code:
void timeplt_sh_irqtrigger_w(offs_t offset,data_t data)
{
 static int last;
 if (last == 0 && data)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

canonical_original_code:
void timeplt_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last == 0 && data)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

variable_types: last int


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

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

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

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

return_type: int


decompiled_code:
__int64 __fastcall timeplt_flipscreen_w(__int64 a1, char a2)
{
return flip_screen_w(0LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char a2)
{
return flip_screen_w(0LL, a2 & 1);
}

original_code:
void timeplt_flipscreen_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 1);
}

canonical_original_code:
void timeplt_flipscreen_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 1);
}


decompiled_code:
__int64 timeplt_scanline_r()
{
return cpu_scalebyfcount(256LL);
}

canonical_decompiled_code:
__int64 func11()
{
return cpu_scalebyfcount(256LL);
}

original_code:
data_t timeplt_scanline_r(offs_t offset)
{
 return cpu_scalebyfcount(256);
}

canonical_original_code:
unsigned int timeplt_scanline_r(unsigned int offset)
{
 return cpu_scalebyfcount(256);
}


decompiled_code:
__int64 __fastcall timeplt_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func12(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

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

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

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


decompiled_code:
__int64 __fastcall timeplt_coin_counter_w(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1)
{
return coin_counter_w(a1 >> 1);
}

original_code:
static void timeplt_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(offset >> 1, data);
}

canonical_original_code:
static void timeplt_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(offset >> 1, data);
}


decompiled_code:
void *__fastcall get_tile_info(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
int v5; // esi
void *result; // rax

v1 = *(_BYTE *)(timeplt_colorram + a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(timeplt_videoram + a1) + ((8 * v1) & 0x100u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 & 0x1F);
v4 = *(_QWORD *)(v2 + 32);
v5 = 0;
if ( v4 )
v5 = *(_DWORD *)(v4 + 4LL * v3);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v5;
*((_DWORD *)&tile_info + 5) = v1 >> 6;
*((_DWORD *)&tile_info + 6) = ((int)v1 >> 4) & 1;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
int v5; // esi
void *result; // rax

v1 = *(_BYTE *)(timeplt_colorram + a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(timeplt_videoram + a1) + ((8 * v1) & 0x100u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 & 0x1F);
v4 = *(_QWORD *)(v2 + 32);
v5 = 0;
if ( v4 )
v5 = *(_DWORD *)(v4 + 4LL * v3);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v5;
*((_DWORD *)&tile_info + 5) = v1 >> 6;
*((_DWORD *)&tile_info + 6) = ((int)v1 >> 4) & 1;
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = timeplt_colorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (timeplt_videoram[tile_index] + ((attr & 0x20) << 3)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x1f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x10) >> 4;
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = timeplt_colorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (timeplt_videoram[tile_index] + ((attr & 0x20) << 3)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x1f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x10) >> 4;
}

variable_types:
attr
unsigned char

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


original_code:
static void filter_w(int chip, int channel, int data)
{
 int C = 0;
 if (data & 1) C += 220000;
 if (data & 2) C += 47000;
 set_RC_filter(3*chip + channel,1000,5100,0,C);
}

variable_types: chip int

variable_types: channel int

variable_types: data int

variable_types: C int


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 result; // rax
int v2; // er15
__int64 v3; // r14
char v4; // al
int v5; // er12
_BOOL4 v6; // ebx
unsigned int v7; // er13
__int64 v8; // [rsp+8h] [rbp-60h]
__int64 v9; // [rsp+10h] [rbp-58h]
int v10; // [rsp+24h] [rbp-44h]
unsigned int v11; // [rsp+28h] [rbp-40h]
unsigned int v12; // [rsp+2Ch] [rbp-3Ch]

v8 = *(_QWORD *)(Machine + 520LL);
v9 = Machine + 776LL;
result = spriteram_size;
v2 = spriteram_size - 2;
if ( (int)spriteram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
v4 = *(_BYTE *)(spriteram_2 + v3 - 1);
v10 = *(unsigned __int8 *)(spriteram + v3 - 1);
v5 = *(unsigned __int8 *)(spriteram_2 + v3);
v12 = v4 & 0x40;
v6 = v4 >= 0;
v11 = v4 & 0x3F;
v7 = *(unsigned __int8 *)(spriteram + v3);
result = drawgfx(
a1,
v8,
*(unsigned __int8 *)(spriteram + v3),
v4 & 0x3F,
v4 & 0x40,
v4 >= 0,
(unsigned int)(240 - v10),
(unsigned int)(v5 - 1),
v9,
2LL,
0LL);
if ( sprite_multiplex_hack && v5 - 1 <= 239 )
{
result = (unsigned int)(v2 - 5);
if ( (unsigned int)result > 0x20 )
result = drawgfx(
a1,
v8,
v7,
v11,
v12,
v6,
(unsigned __int8)(112 - v10),
(unsigned __int8)(v5 + 127),
v9,
2LL,
0LL);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
int v2; // er15
__int64 v3; // r14
char v4; // al
int v5; // er12
_BOOL4 v6; // ebx
unsigned int v7; // er13
__int64 v8; // [rsp+8h] [rbp-60h]
__int64 v9; // [rsp+10h] [rbp-58h]
int v10; // [rsp+24h] [rbp-44h]
unsigned int v11; // [rsp+28h] [rbp-40h]
unsigned int v12; // [rsp+2Ch] [rbp-3Ch]

v8 = *(_QWORD *)(Machine + 520LL);
v9 = Machine + 776LL;
result = spriteram_size;
v2 = spriteram_size - 2;
if ( (int)spriteram_size - 2 >= 0 )
{
v3 = v2 + 1LL;
do
{
v4 = *(_BYTE *)(spriteram_2 + v3 - 1);
v10 = *(unsigned __int8 *)(spriteram + v3 - 1);
v5 = *(unsigned __int8 *)(spriteram_2 + v3);
v12 = v4 & 0x40;
v6 = v4 >= 0;
v11 = v4 & 0x3F;
v7 = *(unsigned __int8 *)(spriteram + v3);
result = drawgfx(
a1,
v8,
*(unsigned __int8 *)(spriteram + v3),
v4 & 0x3F,
v4 & 0x40,
v4 >= 0,
(unsigned int)(240 - v10),
(unsigned int)(v5 - 1),
v9,
2LL,
0LL);
if ( sprite_multiplex_hack && v5 - 1 <= 239 )
{
result = (unsigned int)(v2 - 5);
if ( (unsigned int)result > 0x20 )
result = drawgfx(
a1,
v8,
v7,
v11,
v12,
v6,
(unsigned __int8)(112 - v10),
(unsigned __int8)(v5 + 127),
v9,
2LL,
0LL);
}
v3 -= 2LL;
v2 -= 2;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 const struct GfxElement *gfx = Machine->gfx[1];
 const struct rectangle *clip = &Machine->visible_area;
 int offs;
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  int code,color,sx,sy,flipx,flipy;
  code = spriteram[offs + 1];
  color = spriteram_2[offs] & 0x3f;
  sx = 240 - spriteram[offs];
  sy = spriteram_2[offs + 1]-1;
  flipx = spriteram_2[offs] & 0x40;
  flipy = !(spriteram_2[offs] & 0x80);
  drawgfx(bitmap,gfx,
    code,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,0);
  if (sprite_multiplex_hack)
  {
   if (sy < 240)
   {
    if (offs <= 2*2 || offs >= 19*2)
    {
     drawgfx(bitmap,gfx,
       code,
       color,
       flipx,flipy,
       (sx + 128) & 0xff,(sy + 128) & 0xff,
       clip,TRANSPARENCY_PEN,0);
    }
   }
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct GfxElement *gfx = Machine->gfx[1];
 struct rectangle *clip = &Machine->visible_area;
 int offs;
 for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  int code; int color; int sx; int sy; int flipx; int flipy;
  code = spriteram[offs + 1];
  color = spriteram_2[offs] & 0x3f;
  sx = 240 - spriteram[offs];
  sy = spriteram_2[offs + 1]-1;
  flipx = spriteram_2[offs] & 0x40;
  flipy = !(spriteram_2[offs] & 0x80);
  drawgfx(bitmap,gfx,
    code,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,0);
  if (sprite_multiplex_hack)
  {
   if (sy < 240)
   {
    if (offs <= 2*2 || offs >= 19*2)
    {
     drawgfx(bitmap,gfx,
       code,
       color,
       flipx,flipy,
       (sx + 128) & 0xff,(sy + 128) & 0xff,
       clip,TRANSPARENCY_PEN,0);
    }
   }
  }
 }
}

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

variable_types: offs int

variable_types: code int

variable_types: color int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

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

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


decompiled_code:
__int64 __fastcall input_port_1_bit_r(char a1)
{
return (((int)readinputport(1LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (((int)readinputport(1LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

original_code: data_t input_port_1_bit_r(offs_t offset) { return (readinputport(1) & (1 << offset)) ? 0 : 228; }

canonical_original_code: unsigned int input_port_1_bit_r(unsigned int offset) { return (readinputport(1) & (1 << offset)) ? 0 : 228; }

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall input_port_2_bit_r(char a1)
{
return (((int)readinputport(2LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return (((int)readinputport(2LL) >> a1) & 1) == 0 ? 0xE4 : 0;
}

original_code: data_t input_port_2_bit_r(offs_t offset) { return (readinputport(2) & (1 << offset)) ? 0 : 228; }

canonical_original_code: unsigned int input_port_2_bit_r(unsigned int offset) { return (readinputport(2) & (1 << offset)) ? 0 : 228; }


decompiled_code:
__int64 __fastcall tempest_led_w(__int64 a1, unsigned int a2)
{
osd_led_w(0LL, ~(a2 >> 1));
return osd_led_w(1LL, ~a2);
}

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

original_code:
static void tempest_led_w(offs_t offset,data_t data)
{
 osd_led_w (0, ~(data >> 1));
 osd_led_w (1, ~data);
}

canonical_original_code:
static void tempest_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w (0, ~(data >> 1));
 osd_led_w (1, ~data);
}

variable_types:
data
unsigned int


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

if ( lastval_0 != a2 )
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = coin_counter_w(2LL, a2 & 4);
lastval_0 = a2;
}
return result;
}

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

if ( lastval_0 != a2 )
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = coin_counter_w(2LL, a2 & 4);
lastval_0 = a2;
}
return result;
}

original_code:
static void tempest_coin_w(offs_t offset,data_t data)
{
 static int lastval;
 if (lastval == data) return;
 coin_counter_w (0, (data & 0x01));
 coin_counter_w (1, (data & 0x02));
 coin_counter_w (2, (data & 0x04));
 lastval = data;
}

canonical_original_code:
static void tempest_coin_w(unsigned int offset, unsigned int data)
{
 static int lastval;
 if (lastval == data) return;
 coin_counter_w (0, (data & 0x01));
 coin_counter_w (1, (data & 0x02));
 coin_counter_w (2, (data & 0x04));
 lastval = data;
}

variable_types: lastval int


decompiled_code:
__int64 tempest_IN0_r()
{
unsigned int v0; // ebx
char v1; // dh
unsigned int v2; // eax

v0 = readinputport(0LL);
if ( (unsigned int)avgdvg_done() )
v0 |= 0x40u;
v1 = (unsigned __int16)cpu_gettotalcycles() >> 8;
v2 = v0;
if ( (v1 & 1) != 0 )
{
LOBYTE(v2) = v0 | 0x80;
v0 = v2;
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
char v1; // dh
unsigned int v2; // eax

v0 = readinputport(0LL);
if ( (unsigned int)avgdvg_done() )
v0 |= 0x40u;
v1 = (unsigned __int16)cpu_gettotalcycles() >> 8;
v2 = v0;
if ( (v1 & 1) != 0 )
{
LOBYTE(v2) = v0 | 0x80;
v0 = v2;
}
return v0;
}

original_code:
static data_t tempest_IN0_r(offs_t offset)
{
 int res;
 res = readinputport(0);
 if (avgdvg_done())
  res|=0x40;
 if (cpu_gettotalcycles() & 0x100)
  res |=0x80;
 return res;
}

canonical_original_code:
static unsigned int tempest_IN0_r(unsigned int offset)
{
 int res;
 res = readinputport(0);
 if (avgdvg_done())
  res|=0x40;
 if (cpu_gettotalcycles() & 0x100)
  res |=0x80;
 return res;
}

variable_types: res int


decompiled_code:
void __fastcall pcktgal_adpcm_data_w(__int64 a1, int a2)
{
msm5205next = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
msm5205next = a2;
}

original_code:
static void pcktgal_adpcm_data_w(offs_t offset,data_t data)
{
 msm5205next=data;
}

canonical_original_code:
static void pcktgal_adpcm_data_w(unsigned int offset, unsigned int data)
{
 msm5205next=data;
}


decompiled_code:
__int64 __fastcall pcktgal_flipscreen_w(__int64 a1, unsigned int a2)
{
int v2; // esi
_QWORD *v3; // rcx
__int64 result; // rax

v2 = (a2 >> 7) & 1;
flipscreen = v2;
if ( v2 != last_flip_1 )
{
v3 = dirtybuffer;
result = 0x101010101010101LL;
*dirtybuffer = 0x101010101010101LL;
v3[255] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 2048) >> 3));
}
last_flip_1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
int v2; // esi
_QWORD *v3; // rcx
__int64 result; // rax

v2 = (a2 >> 7) & 1;
flipscreen = v2;
if ( v2 != last_flip_1 )
{
v3 = dirtybuffer;
result = 0x101010101010101LL;
*dirtybuffer = 0x101010101010101LL;
v3[255] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 2048) >> 3));
}
last_flip_1 = v2;
return result;
}

original_code:
void pcktgal_flipscreen_w(offs_t offset,data_t data)
{
 static int last_flip;
 flipscreen = (data&0x80) ? 1 : 0;
 if (last_flip!=flipscreen)
  memset(dirtybuffer,1,0x800);
 last_flip=flipscreen;
}

canonical_original_code:
void pcktgal_flipscreen_w(unsigned int offset, unsigned int data)
{
 static int last_flip;
 flipscreen = (data&0x80) ? 1 : 0;
 if (last_flip!=flipscreen)
  memset(dirtybuffer,1,0x800);
 last_flip=flipscreen;
}


decompiled_code:
_BYTE *init_graphics()
{
__int64 v0; // rbx
_BYTE *result; // rax
int v2; // er8
_BYTE *v3; // rsi
int i; // edi
char v5; // dl

v0 = memory_region(137LL);
result = (_BYTE *)memory_region_length(137LL);
if ( (int)result > 0 )
{
v2 = (int)result;
v3 = (_BYTE *)(v0 + 16);
for ( i = 0; i < v2; i += 32 )
{
result = v3 - 16;
do
{
v5 = result[16];
result[16] = *result;
*result++ = v5;
}
while ( result != v3 );
v3 += 32;
}
}
return result;
}

canonical_decompiled_code:
_BYTE *func2()
{
__int64 v0; // rbx
_BYTE *result; // rax
int v2; // er8
_BYTE *v3; // rsi
int i; // edi
char v5; // dl

v0 = memory_region(137LL);
result = (_BYTE *)memory_region_length(137LL);
if ( (int)result > 0 )
{
v2 = (int)result;
v3 = (_BYTE *)(v0 + 16);
for ( i = 0; i < v2; i += 32 )
{
result = v3 - 16;
do
{
v5 = result[16];
result[16] = *result;
*result++ = v5;
}
while ( result != v3 );
v3 += 32;
}
}
return result;
}

original_code:
static void init_graphics(void)
{
 unsigned char *rom = memory_region(REGION_GFX1);
 int len = memory_region_length(REGION_GFX1);
 int i,j,temp[16];
 for (i = 0x00000;i < len;i += 32)
 {
  for (j=0; j<16; j++)
  {
   temp[j] = rom[i+j+16];
   rom[i+j+16] = rom[i+j];
   rom[i+j] = temp[j];
  }
 }
}

canonical_original_code:
static void init_graphics()
{
 unsigned char *rom = memory_region(REGION_GFX1);
 int len = memory_region_length(REGION_GFX1);
 int i; int j; int temp[16];
 for (i = 0x00000;i < len;i += 32)
 {
  for (j=0; j<16; j++)
  {
   temp[j] = rom[i+j+16];
   rom[i+j+16] = rom[i+j];
   rom[i+j] = temp[j];
  }
 }
}

variable_types:
rom
unsigned char *

variable_types: len int

variable_types: i int

variable_types: j int

variable_types:
temp
int [16]


decompiled_code:
_BYTE *init_pcktgal()
{
init_deco222();
return init_graphics();
}

canonical_decompiled_code:
_BYTE *func4()
{
func3();
return func2();
}

original_code:
static void init_pcktgal(void)
{
 init_deco222();
 init_graphics();
}

canonical_original_code:
static void init_pcktgal()
{
 init_deco222();
 init_graphics();
}


decompiled_code:
__int64 pcktgal_adpcm_int()
{
bool v0; // zf
__int64 result; // rax

MSM5205_data_w(0LL, (unsigned int)(msm5205next >> 4));
msm5205next *= 16;
v0 = toggle_0 == 1;
result = (unsigned int)(1 - toggle_0);
toggle_0 = 1 - toggle_0;
if ( !v0 )
result = cpu_cause_interrupt(1LL, 1LL);
return result;
}

canonical_decompiled_code:
__int64 func5()
{
bool v0; // zf
__int64 result; // rax

MSM5205_data_w(0LL, (unsigned int)(msm5205next >> 4));
msm5205next *= 16;
v0 = toggle_0 == 1;
result = (unsigned int)(1 - toggle_0);
toggle_0 = 1 - toggle_0;
if ( !v0 )
result = cpu_cause_interrupt(1LL, 1LL);
return result;
}

original_code:
static void pcktgal_adpcm_int(int data)
{
 static int toggle;
 MSM5205_data_w(0,msm5205next >> 4);
 msm5205next<<=4;
 toggle = 1 - toggle;
 if (toggle)
  cpu_cause_interrupt(1,1);
}

variable_types: data int

variable_types: toggle int


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

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
{
cpu_bankbase[3] = v2 + 81920;
result = &ophw;
if ( ophw != 3 )
return result;
LABEL_6:
ophw = -1;
v4 = cpu_get_pc();
return (void *)cpu_setOPbase16(v4);
}
cpu_bankbase[3] = v2 + 0x10000;
result = &ophw;
if ( ophw == 3 )
goto LABEL_6;
return result;
}

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

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
{
cpu_bankbase[3] = v2 + 81920;
result = &ophw;
if ( ophw != 3 )
return result;
LABEL_6:
ophw = -1;
v4 = cpu_get_pc();
return (void *)cpu_setOPbase16(v4);
}
cpu_bankbase[3] = v2 + 0x10000;
result = &ophw;
if ( ophw == 3 )
goto LABEL_6;
return result;
}

original_code:
static void pcktgal_sound_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 4) { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (UINT8 *)(&RAM[0x14000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (UINT8 *)(&RAM[0x10000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

canonical_original_code:
static void pcktgal_sound_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 4) { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (unsigned char *)(&RAM[0x14000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (3 >= 1 && 3 <= 16) { cpu_bankbase[3] = (unsigned char *)(&RAM[0x10000]); if (ophw == 3) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *__fastcall pcktgal_bank_w(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rbx
void *result; // rax
__int64 v5; // rdi
unsigned int v6; // eax

v2 = memory_region(129LL);
v3 = v2;
if ( (a2 & 1) != 0 )
{
cpu_bankbase[1] = v2 + 0x4000;
if ( ophw != 1 )
goto LABEL_4;
goto LABEL_3;
}
cpu_bankbase[1] = v2 + 0x10000;
if ( ophw == 1 )
{
LABEL_3:
ophw = -1;
v5 = (unsigned int)cpu_get_pc();
cpu_setOPbase16(v5);
}
LABEL_4:
if ( (a2 & 2) != 0 )
{
cpu_bankbase[2] = v3 + 24576;
result = &ophw;
if ( ophw != 2 )
return result;
LABEL_11:
ophw = -1;
v6 = cpu_get_pc();
return (void *)cpu_setOPbase16(v6);
}
cpu_bankbase[2] = v3 + 73728;
result = &ophw;
if ( ophw == 2 )
goto LABEL_11;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rbx
void *result; // rax
__int64 v5; // rdi
unsigned int v6; // eax

v2 = memory_region(129LL);
v3 = v2;
if ( (a2 & 1) != 0 )
{
cpu_bankbase[1] = v2 + 0x4000;
if ( ophw != 1 )
goto LABEL_4;
goto LABEL_3;
}
cpu_bankbase[1] = v2 + 0x10000;
if ( ophw == 1 )
{
LABEL_3:
ophw = -1;
v5 = (unsigned int)cpu_get_pc();
cpu_setOPbase16(v5);
}
LABEL_4:
if ( (a2 & 2) != 0 )
{
cpu_bankbase[2] = v3 + 24576;
result = &ophw;
if ( ophw != 2 )
return result;
LABEL_11:
ophw = -1;
v6 = cpu_get_pc();
return (void *)cpu_setOPbase16(v6);
}
cpu_bankbase[2] = v3 + 73728;
result = &ophw;
if ( ophw == 2 )
goto LABEL_11;
return result;
}

original_code:
static void pcktgal_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (data & 1) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x4000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 if (data & 2) { { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[0x6000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
 else { { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[0x12000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } }; }
}

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


decompiled_code:
__int64 pcktgal_adpcm_reset_r()
{
MSM5205_reset_w(0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
MSM5205_reset_w(0LL, 0LL);
return 0LL;
}

original_code:
static data_t pcktgal_adpcm_reset_r(offs_t offset)
{
 MSM5205_reset_w(0,0);
 return 0;
}

canonical_original_code:
static unsigned int pcktgal_adpcm_reset_r(unsigned int offset)
{
 MSM5205_reset_w(0,0);
 return 0;
}


decompiled_code:
__int64 pcktgal_sound_w()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 2LL);
}

canonical_decompiled_code:
__int64 func9()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 2LL);
}

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

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


original_code:
static void init_deco222(void)
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU2);
 int diff = memory_region_length(REGION_CPU2) / 2;
 memory_set_opcode_base(1,rom+diff);
 for (A = 0;A < diff;A++)
  rom[A + diff] = (rom[A] & 0x9f) | ((rom[A] & 0x20) << 1) | ((rom[A] & 0x40) >> 1);
}

canonical_original_code:
static void init_deco222()
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU2);
 int diff = memory_region_length(REGION_CPU2) / 2;
 memory_set_opcode_base(1,rom+diff);
 for (A = 0;A < diff;A++)
  rom[A + diff] = (rom[A] & 0x9f) | ((rom[A] & 0x20) << 1) | ((rom[A] & 0x40) >> 1);
}

variable_types: A int

variable_types: diff int


decompiled_code:
__int64 tankbatt_led_w()
{
return osd_led_w();
}

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

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

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


decompiled_code:
__int64 __fastcall tankbatt_in0_r(char a1)
{
return ((unsigned int)readinputport(0LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return ((unsigned int)readinputport(0LL) << (7 - a1)) & 0x80;
}

original_code:
data_t tankbatt_in0_r(offs_t offset)
{
 int val;
 val = readinputport(0);
 return ((val << (7-offset)) & 0x80);
}

canonical_original_code:
unsigned int tankbatt_in0_r(unsigned int offset)
{
 int val;
 val = readinputport(0);
 return ((val << (7-offset)) & 0x80);
}

variable_types: val int


decompiled_code:
__int64 __fastcall tankbatt_in1_r(char a1)
{
return ((unsigned int)readinputport(1LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
return ((unsigned int)readinputport(1LL) << (7 - a1)) & 0x80;
}

original_code:
data_t tankbatt_in1_r(offs_t offset)
{
 int val;
 val = readinputport(1);
 return ((val << (7-offset)) & 0x80);
}

canonical_original_code:
unsigned int tankbatt_in1_r(unsigned int offset)
{
 int val;
 val = readinputport(1);
 return ((val << (7-offset)) & 0x80);
}


decompiled_code:
__int64 __fastcall tankbatt_dsw_r(char a1)
{
return ((unsigned int)readinputport(2LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return ((unsigned int)readinputport(2LL) << (7 - a1)) & 0x80;
}

original_code:
data_t tankbatt_dsw_r(offs_t offset)
{
 int val;
 val = readinputport(2);
 return ((val << (7-offset)) & 0x80);
}

canonical_original_code:
unsigned int tankbatt_dsw_r(unsigned int offset)
{
 int val;
 val = readinputport(2);
 return ((val << (7-offset)) & 0x80);
}


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

tankbatt_nmi_enable = a2;
if ( a2 )
result = cpu_clear_pending_interrupts(0LL);
return result;
}

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

tankbatt_nmi_enable = a2;
if ( a2 )
result = cpu_clear_pending_interrupts(0LL);
return result;
}

original_code:
void tankbatt_demo_interrupt_enable_w(offs_t offset,data_t data)
{
 tankbatt_nmi_enable = data;
 if (data != 0) cpu_clear_pending_interrupts(0);
}

canonical_original_code:
void tankbatt_demo_interrupt_enable_w(unsigned int offset, unsigned int data)
{
 tankbatt_nmi_enable = data;
 if (data != 0) cpu_clear_pending_interrupts(0);
}


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

result = a2 == 0;
tankbatt_nmi_enable = a2 == 0;
tankbatt_sound_enable = a2 == 0;
if ( a2 )
{
cpu_clear_pending_interrupts(0LL);
result = sample_stop(2LL);
}
return result;
}

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

result = a2 == 0;
tankbatt_nmi_enable = a2 == 0;
tankbatt_sound_enable = a2 == 0;
if ( a2 )
{
cpu_clear_pending_interrupts(0LL);
result = sample_stop(2LL);
}
return result;
}

original_code:
void tankbatt_interrupt_enable_w(offs_t offset,data_t data)
{
 tankbatt_nmi_enable = !data;
 tankbatt_sound_enable = !data;
 if (data != 0) cpu_clear_pending_interrupts(0);
 if (data) sample_stop (2);
}

canonical_original_code:
void tankbatt_interrupt_enable_w(unsigned int offset, unsigned int data)
{
 tankbatt_nmi_enable = !data;
 tankbatt_sound_enable = !data;
 if (data != 0) cpu_clear_pending_interrupts(0);
 if (data) sample_stop (2);
}


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

if ( tankbatt_sound_enable )
result = sample_start(1LL, 3LL, 0LL);
return result;
}

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

if ( tankbatt_sound_enable )
result = sample_start(1LL, 3LL, 0LL);
return result;
}

original_code:
void tankbatt_sh_expl_w(offs_t offset,data_t data)
{
 if (tankbatt_sound_enable)
  sample_start (1, 3, 0);
}

canonical_original_code:
void tankbatt_sh_expl_w(unsigned int offset, unsigned int data)
{
 if (tankbatt_sound_enable)
  sample_start (1, 3, 0);
}


decompiled_code:
__int64 __fastcall tankbatt_sh_engine_w(__int64 a1, int a2)
{
if ( !tankbatt_sound_enable )
return sample_stop(2LL);
if ( a2 )
return sample_start(2LL, 2LL, 1LL);
return sample_start(2LL, 1LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
if ( !tankbatt_sound_enable )
return sample_stop(2LL);
if ( a2 )
return sample_start(2LL, 2LL, 1LL);
return sample_start(2LL, 1LL, 1LL);
}

original_code:
void tankbatt_sh_engine_w(offs_t offset,data_t data)
{
 if (tankbatt_sound_enable)
 {
  if (data)
   sample_start (2, 2, 1);
  else
   sample_start (2, 1, 1);
 }
 else sample_stop (2);
}

canonical_original_code:
void tankbatt_sh_engine_w(unsigned int offset, unsigned int data)
{
 if (tankbatt_sound_enable)
 {
  if (data)
   sample_start (2, 2, 1);
  else
   sample_start (2, 1, 1);
 }
 else sample_stop (2);
}


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

if ( tankbatt_sound_enable )
result = sample_start(0LL, 0LL, 0LL);
return result;
}

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

if ( tankbatt_sound_enable )
result = sample_start(0LL, 0LL, 0LL);
return result;
}

original_code:
void tankbatt_sh_fire_w(offs_t offset,data_t data)
{
 if (tankbatt_sound_enable)
  sample_start (0, 0, 0);
}

canonical_original_code:
void tankbatt_sh_fire_w(unsigned int offset, unsigned int data)
{
 if (tankbatt_sound_enable)
  sample_start (0, 0, 0);
}


decompiled_code:
__int64 tankbatt_interrupt()
{
if ( (readinputport(0LL) & 0x60) == 0 )
return interrupt();
if ( tankbatt_nmi_enable )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func10()
{
if ( (readinputport(0LL) & 0x60) == 0 )
return interrupt();
if ( tankbatt_nmi_enable )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
int tankbatt_interrupt (void)
{
 if ((readinputport (0) & 0x60) == 0) return interrupt ();
 if (tankbatt_nmi_enable) return nmi_interrupt ();
 else return ignore_interrupt ();
}

canonical_original_code:
int tankbatt_interrupt()
{
 if ((readinputport (0) & 0x60) == 0) return interrupt ();
 if (tankbatt_nmi_enable) return nmi_interrupt ();
 else return ignore_interrupt ();
}


decompiled_code:
unsigned __int64 __fastcall MSM5205_update(int a1, char *a2, int a3)
{
char *v4; // rdi
int v5; // eax
unsigned __int64 result; // rax
char *v7; // rdx

v4 = a2;
v5 = msm5205[12 * a1 + 9];
if ( !v5 )
return (unsigned __int64)memset(a2, 0, 2LL * a3);
result = (unsigned int)(16 * v5);
if ( a3 )
{
v7 = &a2[2 * a3];
do
{
v4 += 2;
*((_WORD *)v4 - 1) = result;
}
while ( v4 != v7 );
}
return result;
}

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

v4 = a2;
v5 = msm5205[12 * a1 + 9];
if ( !v5 )
return (unsigned __int64)memset(a2, 0, 2LL * a3);
result = (unsigned int)(16 * v5);
if ( a3 )
{
v7 = &a2[2 * a3];
do
{
v4 += 2;
*((_WORD *)v4 - 1) = result;
}
while ( v4 != v7 );
}
return result;
}

original_code:
static void MSM5205_update(int chip,INT16 *buffer,int length)
{
 struct MSM5205Voice *voice = &msm5205[chip];
 if(voice->signal)
 {
  short val = voice->signal * 16;
  while (length)
  {
   *buffer++ = val;
   length--;
  }
 }
 else
  memset (buffer,0,length*sizeof(INT16));
}

canonical_original_code:
static void MSM5205_update(int chip, short *buffer, int length)
{
 struct MSM5205Voice *voice = &msm5205[chip];
 if(voice->signal)
 {
  short val = voice->signal * 16;
  while (length)
  {
   *buffer++ = val;
   length--;
  }
 }
 else
  memset (buffer,0,length*sizeof(INT16));
}

variable_types: chip int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct MSM5205Voice { int stream; void *timer; int data; int vclk; int reset; int prescaler; int bitwidth; int signal; int step; } *

variable_types: val short


decompiled_code:
__int64 __fastcall MSM5205_set_timer(unsigned int a1, char a2)
{
int v2; // ebp
__int64 result; // rax
__int64 v4; // rcx

v2 = prescaler_table_0[a2 & 3];
result = 12LL * (int)a1;
if ( msm5205[result + 7] != v2 )
{
if ( *(_QWORD *)&msm5205[12 * a1 + 2] )
{
timer_remove();
*(_QWORD *)&msm5205[12 * a1 + 2] = 0LL;
}
result = 12LL * (int)a1;
msm5205[result + 7] = v2;
if ( v2 )
{
v4 = timer_pulse((unsigned int)(0x40000000 / (*(_DWORD *)(msm5205_intf + 4) / v2)), a1, MSM5205_vclk_callback);
result = 12LL * (int)a1;
*(_QWORD *)&msm5205[result + 2] = v4;
}
}
return result * 4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, char a2)
{
int v2; // ebp
__int64 result; // rax
__int64 v4; // rcx

v2 = prescaler_table_0[a2 & 3];
result = 12LL * (int)a1;
if ( msm5205[result + 7] != v2 )
{
if ( *(_QWORD *)&msm5205[12 * a1 + 2] )
{
timer_remove();
*(_QWORD *)&msm5205[12 * a1 + 2] = 0LL;
}
result = 12LL * (int)a1;
msm5205[result + 7] = v2;
if ( v2 )
{
v4 = timer_pulse((unsigned int)(0x40000000 / (*(_DWORD *)(msm5205_intf + 4) / v2)), a1, MSM5205_vclk_callback);
result = 12LL * (int)a1;
*(_QWORD *)&msm5205[result + 2] = v4;
}
}
return result * 4;
}

original_code:
static void MSM5205_set_timer(int num,int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 static int prescaler_table[4] = {96,48,64,0};
 int prescaler = prescaler_table[select&0x03];
 if( voice->prescaler != prescaler )
 {
  if(voice->timer)
  {
   timer_remove(voice->timer);
   voice->timer = 0;
  }
  voice->prescaler = prescaler;
  if( prescaler )
  {
   voice->timer =
    timer_pulse (((1<<30) / ((timer_tm)(msm5205_intf->baseclock / prescaler))), num, MSM5205_vclk_callback);
  }
 }
}

canonical_original_code:
static void MSM5205_set_timer(int num, int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 static int prescaler_table[4] = {96,48,64,0};
 int prescaler = prescaler_table[select&0x03];
 if( voice->prescaler != prescaler )
 {
  if(voice->timer)
  {
   timer_remove(voice->timer);
   voice->timer = 0;
  }
  voice->prescaler = prescaler;
  if( prescaler )
  {
   voice->timer =
    timer_pulse (((1<<30) / ((timer_tm)(msm5205_intf->baseclock / prescaler))), num, MSM5205_vclk_callback);
  }
 }
}

variable_types: num int

variable_types: select int

variable_types: prescaler int

user_defined_types: struct MSM5205Voice { int stream; void *timer; int data; int vclk; int reset; int prescaler; int bitwidth; int signal; int step; }


decompiled_code:
void MSM5205_sh_update()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void MSM5205_sh_update (void)
{
}

canonical_original_code:
void MSM5205_sh_update()
{
}


decompiled_code:
signed int *MSM5205_sh_reset()
{
signed int *result; // rax
_DWORD *v1; // rbx
signed int v2; // ebp
__int64 v3; // r12

result = (signed int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = (signed int *)msm5205_intf;
if ( *(int *)msm5205_intf > 0 )
{
v1 = msm5205;
v2 = 0;
do
{
v1[4] = 0;
v1[5] = 0;
v1[6] = 0;
v1[9] = 0;
v1[10] = 0;
v3 = v2 + 8LL;
MSM5205_set_timer(v2, result[v3 + 2] & 3);
result = (signed int *)msm5205_intf;
v1[8] = ((*(_BYTE *)(msm5205_intf + 4 * v3 + 8) & 4) != 0) + 3;
++v2;
v1 += 12;
}
while ( *result > v2 );
}
}
return result;
}

canonical_decompiled_code:
signed int *func6()
{
signed int *result; // rax
_DWORD *v1; // rbx
signed int v2; // ebp
__int64 v3; // r12

result = (signed int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = (signed int *)msm5205_intf;
if ( *(int *)msm5205_intf > 0 )
{
v1 = msm5205;
v2 = 0;
do
{
v1[4] = 0;
v1[5] = 0;
v1[6] = 0;
v1[9] = 0;
v1[10] = 0;
v3 = v2 + 8LL;
func2(v2, result[v3 + 2] & 3);
result = (signed int *)msm5205_intf;
v1[8] = ((*(_BYTE *)(msm5205_intf + 4 * v3 + 8) & 4) != 0) + 3;
++v2;
v1 += 12;
}
while ( *result > v2 );
}
}
return result;
}

original_code:
void MSM5205_sh_reset(void)
{
 int i;
 if (Machine->sample_rate == 0)
  return;
 for (i = 0; i < msm5205_intf->num; i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  voice->data = 0;
  voice->vclk = 0;
  voice->reset = 0;
  voice->signal = 0;
  voice->step = 0;
  MSM5205_set_timer(i,msm5205_intf->select[i] & 0x03);
  msm5205[i].bitwidth = msm5205_intf->select[i]&0x04 ? 4 : 3;
 }
}

canonical_original_code:
void MSM5205_sh_reset()
{
 int i;
 if (Machine->sample_rate == 0)
  return;
 for (i = 0; i < msm5205_intf->num; i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  voice->data = 0;
  voice->vclk = 0;
  voice->reset = 0;
  voice->signal = 0;
  voice->step = 0;
  MSM5205_set_timer(i,msm5205_intf->select[i] & 0x03);
  msm5205[i].bitwidth = msm5205_intf->select[i]&0x04 ? 4 : 3;
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall MSM5205_sh_start(__int64 a1)
{
int *v1; // rbx
_DWORD *v2; // rbp
unsigned int v3; // ebx
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

msm5205_intf = *(_QWORD *)(a1 + 8);
v1 = (int *)msm5205_intf;
ComputeTables();
memset(msm5205, 0, sizeof(msm5205));
if ( *v1 > 0 )
{
v2 = msm5205;
v3 = 0;
do
{
sprintf(v5, "MSM5205 #%d", v3);
*v2 = stream_init(
v5,
*(unsigned int *)(msm5205_intf + 4LL * (int)v3 + 56),
*(unsigned int *)(Machine + 836LL),
v3,
MSM5205_update);
++v3;
v2 += 12;
}
while ( *(_DWORD *)msm5205_intf > (signed int)v3 );
}
MSM5205_sh_reset();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int *v1; // rbx
_DWORD *v2; // rbp
unsigned int v3; // ebx
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

msm5205_intf = *(_QWORD *)(a1 + 8);
v1 = (int *)msm5205_intf;
func1();
memset(msm5205, 0, sizeof(msm5205));
if ( *v1 > 0 )
{
v2 = msm5205;
v3 = 0;
do
{
sprintf(v5, "MSM5205 #%d", v3);
*v2 = stream_init(
v5,
*(unsigned int *)(msm5205_intf + 4LL * (int)v3 + 56),
*(unsigned int *)(Machine + 836LL),
v3,
MSM5205_update);
++v3;
v2 += 12;
}
while ( *(_DWORD *)msm5205_intf > (signed int)v3 );
}
func6();
return 0LL;
}

original_code:
int MSM5205_sh_start (const struct MachineSound *msound)
{
 int i;
 msm5205_intf = (const struct MSM5205interface*)msound->sound_interface;
 ComputeTables ();
 memset (msm5205, 0, sizeof (msm5205));
 for (i = 0;i < msm5205_intf->num;i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  char name[20];
  sprintf(name,"MSM5205 #%d",i);
  voice->stream = stream_init(name,msm5205_intf->mixing_level[i],
                                Machine->sample_rate,i,
                          MSM5205_update);
 }
 MSM5205_sh_reset();
 return 0;
}

canonical_original_code:
int MSM5205_sh_start(struct MachineSound *msound)
{
 int i;
 msm5205_intf = (struct MSM5205interface *)msound->sound_interface;
 ComputeTables ();
 memset (msm5205, 0, sizeof (msm5205));
 for (i = 0;i < msm5205_intf->num;i++)
 {
  struct MSM5205Voice *voice = &msm5205[i];
  char name[20];
  sprintf(name,"MSM5205 #%d",i);
  voice->stream = stream_init(name,msm5205_intf->mixing_level[i],
                                Machine->sample_rate,i,
                          MSM5205_update);
 }
 MSM5205_sh_reset();
 return 0;
}

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

variable_types:
name
char [20]

user_defined_types: struct MSM5205interface { int num; int baseclock; void (*vclk_interrupt[4])(int); int select[4]; int mixing_level[4]; }


decompiled_code:
__int64 __fastcall MSM5205_reset_w(int a1, int a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(unsigned int *)msm5205_intf;
if ( (int)v2 <= a1 )
return logerror(
"error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n",
(unsigned int)a1,
v2);
result = 12LL * a1;
msm5205[result + 6] = a2;
return result * 4;
}

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

v2 = *(unsigned int *)msm5205_intf;
if ( (int)v2 <= a1 )
return logerror(
"error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n",
(unsigned int)a1,
v2);
result = 12LL * a1;
msm5205[result + 6] = a2;
return result * 4;
}

original_code:
void MSM5205_reset_w (int num, int reset)
{
 if (num >= msm5205_intf->num)
 {
  logerror("error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n", num, msm5205_intf->num);
  return;
 }
 msm5205[num].reset = reset;
}

canonical_original_code:
void MSM5205_reset_w(int num, int reset)
{
 if (num >= msm5205_intf->num)
 {
  logerror("error: MSM5205_reset_w() called with chip = %d, but only %d chips allocated\n", num, msm5205_intf->num);
  return;
 }
 msm5205[num].reset = reset;
}

variable_types: reset int


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

result = (2 * a2) & 0xE;
if ( msm5205[12 * a1 + 8] == 4 )
result = a2 & 0xF;
msm5205[12 * a1 + 4] = result;
return result;
}

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

result = (2 * a2) & 0xE;
if ( msm5205[12 * a1 + 8] == 4 )
result = a2 & 0xF;
msm5205[12 * a1 + 4] = result;
return result;
}

original_code:
void MSM5205_data_w (int num, int data)
{
 if( msm5205[num].bitwidth == 4)
  msm5205[num].data = data & 0x0f;
 else
  msm5205[num].data = (data & 0x07)<<1;
}

canonical_original_code:
void MSM5205_data_w(int num, int data)
{
 if( msm5205[num].bitwidth == 4)
  msm5205[num].data = data & 0x0f;
 else
  msm5205[num].data = (data & 0x07)<<1;
}

variable_types: data int


decompiled_code:
__int64 __fastcall MSM5205_selector_w(unsigned int a1, char a2)
{
stream_update((unsigned int)msm5205[12 * a1], 0LL);
return MSM5205_set_timer(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, char a2)
{
stream_update((unsigned int)msm5205[12 * a1], 0LL);
return func2(a1, a2);
}

original_code:
void MSM5205_selector_w (int num, int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 stream_update(voice->stream,0);
 MSM5205_set_timer(num,select);
}

canonical_original_code:
void MSM5205_selector_w(int num, int select)
{
 struct MSM5205Voice *voice = &msm5205[num];
 stream_update(voice->stream,0);
 MSM5205_set_timer(num,select);
}


decompiled_code:
__int64 __fastcall MSM5205_bitwidth_w(int a1, int a2)
{
int v2; // ebp
__int64 result; // rax

v2 = 3 - ((a2 == 0) - 1);
result = 48LL * a1;
if ( *(_DWORD *)((char *)&msm5205[8] + result) != v2 )
{
result = stream_update((unsigned int)msm5205[12 * a1], 0LL);
msm5205[12 * a1 + 8] = v2;
}
return result;
}

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

v2 = 3 - ((a2 == 0) - 1);
result = 48LL * a1;
if ( *(_DWORD *)((char *)&msm5205[8] + result) != v2 )
{
result = stream_update((unsigned int)msm5205[12 * a1], 0LL);
msm5205[12 * a1 + 8] = v2;
}
return result;
}

original_code:
void MSM5205_bitwidth_w (int num, int bitsel)
{
 int bitwidth = bitsel ? 4 : 3;
 if( msm5205[num].bitwidth != bitwidth )
 {
  stream_update(msm5205[num].stream,0);
  msm5205[num].bitwidth = bitwidth;
 }
}

canonical_original_code:
void MSM5205_bitwidth_w(int num, int bitsel)
{
 int bitwidth = bitsel ? 4 : 3;
 if( msm5205[num].bitwidth != bitwidth )
 {
  stream_update(msm5205[num].stream,0);
  msm5205[num].bitwidth = bitwidth;
 }
}

variable_types: bitsel int

variable_types: bitwidth int


decompiled_code:
__int64 __fastcall MSM5205_set_volume(int a1)
{
return mixer_set_volume((unsigned int)msm5205[12 * a1]);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return mixer_set_volume((unsigned int)msm5205[12 * a1]);
}

original_code:
void MSM5205_set_volume(int num,int volume)
{
 struct MSM5205Voice *voice = &msm5205[num];
 mixer_set_volume(voice->stream,volume);
}

canonical_original_code:
void MSM5205_set_volume(int num, int volume)
{
 struct MSM5205Voice *voice = &msm5205[num];
 mixer_set_volume(voice->stream,volume);
}

variable_types: volume int


original_code:
void hexa_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void hexa_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
_BYTE *init_hexa()
{
_BYTE *result; // rax

result = (_BYTE *)memory_region(129LL);
result[292] = 0;
result[293] = 0;
result[294] = 0;
return result;
}

canonical_decompiled_code:
_BYTE *func1()
{
_BYTE *result; // rax

result = (_BYTE *)memory_region(129LL);
result[292] = 0;
result[293] = 0;
result[294] = 0;
return result;
}

original_code:
static void init_hexa(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0x0124] = 0x00;
 RAM[0x0125] = 0x00;
 RAM[0x0126] = 0x00;
}

canonical_original_code:
static void init_hexa()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 RAM[0x0124] = 0x00;
 RAM[0x0125] = 0x00;
 RAM[0x0126] = 0x00;
}

variable_types:
RAM
unsigned char *


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

v2 = memory_region(129LL);
if ( (a2 & 1) != flipx )
{
flipx = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
if ( (a2 & 2) != flipy )
{
flipy = a2 & 2;
memset(dirtybuffer, 1, videoram_size);
}
cpu_bankbase[1] = v2 + (int)((((a2 >> 4) & 1) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
result = (a2 & 0x20) != 0;
if ( (_DWORD)result != charbank )
{
charbank = (a2 & 0x20) != 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

v2 = memory_region(129LL);
if ( (a2 & 1) != flipx )
{
flipx = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
if ( (a2 & 2) != flipy )
{
flipy = a2 & 2;
memset(dirtybuffer, 1, videoram_size);
}
cpu_bankbase[1] = v2 + (int)((((a2 >> 4) & 1) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
result = (a2 & 0x20) != 0;
if ( (_DWORD)result != charbank )
{
charbank = (a2 & 0x20) != 0;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void hexa_d008_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (flipx != (data & 0x01))
 {
  flipx = data & 0x01;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipy != (data & 0x02))
 {
  flipy = data & 0x02;
  memset(dirtybuffer,1,videoram_size);
 }
 bankaddress = 0x10000 + ((data & 0x10) >> 4) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (charbank != ((data & 0x20) >> 5))
 {
  charbank = (data & 0x20) >> 5;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void hexa_d008_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 if (flipx != (data & 0x01))
 {
  flipx = data & 0x01;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipy != (data & 0x02))
 {
  flipy = data & 0x02;
  memset(dirtybuffer,1,videoram_size);
 }
 bankaddress = 0x10000 + ((data & 0x10) >> 4) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (charbank != ((data & 0x20) >> 5))
 {
  charbank = (data & 0x20) >> 5;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: bankaddress int


decompiled_code:
__int64 __fastcall hexa_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
_BYTE *v3; // rax

v1 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v2 = v1 + 1LL;
do
{
v3 = (_BYTE *)(dirtybuffer + v2 - 1);
if ( *v3 || *(_BYTE *)(dirtybuffer + v2) )
{
*v3 = 0;
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2)
+ ((*(unsigned __int8 *)(videoram + v2 - 1) << 8) & 0x700u)
+ (charbank << 11),
*(_BYTE *)(videoram + v2 - 1) >> 3);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
_BYTE *v3; // rax

v1 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v2 = v1 + 1LL;
do
{
v3 = (_BYTE *)(dirtybuffer + v2 - 1);
if ( *v3 || *(_BYTE *)(dirtybuffer + v2) )
{
*v3 = 0;
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2)
+ ((*(unsigned __int8 *)(videoram + v2 - 1) << 8) & 0x700u)
+ (charbank << 11),
*(_BYTE *)(videoram + v2 - 1) >> 3);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void hexa_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 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;
   if (flipx) sx = 31 - sx;
   if (flipy) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs + 1] + ((videoram[offs] & 0x07) << 8) + (charbank << 11),
     (videoram[offs] & 0xf8) >> 3,
     flipx,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void hexa_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 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;
   if (flipx) sx = 31 - sx;
   if (flipy) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs + 1] + ((videoram[offs] & 0x07) << 8) + (charbank << 11),
     (videoram[offs] & 0xf8) >> 3,
     flipx,flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 __fastcall timer_callback_2203(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2203TimerOver((unsigned __int8)v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2203TimerOver((unsigned __int8)v2);
}

original_code:
static void timer_callback_2203(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 YM2203TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2203(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 YM2203TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2203UpdateRequest(int a1)
{
return stream_update(stream[a1], 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return stream_update(stream[a1], 0LL);
}

original_code:
void YM2203UpdateRequest(int chip)
{
 stream_update(stream[chip],0);
}

variable_types: chip int


decompiled_code:
_BOOL8 __fastcall YM2203_sh_start(__int64 a1)
{
int v2; // edx
_BOOL8 result; // rax
unsigned int *v4; // r12
__int64 v5; // rdi
__int64 v6; // rbx
const char *v7; // rax
char v8[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = AY8910_sh_start();
result = 1LL;
if ( !v2 )
{
intf = *(_QWORD *)(a1 + 8);
v4 = (unsigned int *)intf;
FMTimerInit();
v5 = *v4;
if ( (int)v5 > 0 )
{
v6 = 0LL;
do
{
v7 = (const char *)sound_name(a1);
sprintf(v8, "%s #%d FM", v7, (unsigned int)v6);
stream[v6] = stream_init(
v8,
(unsigned int)*(__int16 *)(intf + 4LL * (int)v6 + 10),
*(unsigned int *)(Machine + 836LL),
(unsigned int)v6,
&YM2203UpdateOne);
v4 = (unsigned int *)intf;
v5 = *(unsigned int *)intf;
++v6;
}
while ( (int)v5 > (int)v6 );
}
result = (unsigned int)YM2203Init(v5, v4[1], *(unsigned int *)(Machine + 836LL), TimerHandler, IRQHandler) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
int v2; // edx
_BOOL8 result; // rax
unsigned int *v4; // r12
__int64 v5; // rdi
__int64 v6; // rbx
const char *v7; // rax
char v8[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = AY8910_sh_start();
result = 1LL;
if ( !v2 )
{
intf = *(_QWORD *)(a1 + 8);
v4 = (unsigned int *)intf;
func0();
v5 = *v4;
if ( (int)v5 > 0 )
{
v6 = 0LL;
do
{
v7 = (const char *)sound_name(a1);
sprintf(v8, "%s #%d FM", v7, (unsigned int)v6);
stream[v6] = stream_init(
v8,
(unsigned int)*(__int16 *)(intf + 4LL * (int)v6 + 10),
*(unsigned int *)(Machine + 836LL),
(unsigned int)v6,
&YM2203UpdateOne);
v4 = (unsigned int *)intf;
v5 = *(unsigned int *)intf;
++v6;
}
while ( (int)v5 > (int)v6 );
}
result = (unsigned int)YM2203Init(v5, v4[1], *(unsigned int *)(Machine + 836LL), TimerHandler, IRQHandler) != 0;
}
return result;
}

original_code:
int YM2203_sh_start(const struct MachineSound *msound)
{
 int i;
 if (AY8910_sh_start(msound)) return 1;
 intf = msound->sound_interface;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  int volume;
  char name[20];
  sprintf(name,"%s #%d FM",sound_name(msound),i);
  volume = intf->mixing_level[i]>>16;
  stream[i] = stream_init(name,volume,Machine->sample_rate,i,YM2203UpdateOne );
 }
 if (YM2203Init(intf->num,intf->baseclock,Machine->sample_rate,TimerHandler,IRQHandler) == 0)
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int YM2203_sh_start(struct MachineSound *msound)
{
 int i;
 if (AY8910_sh_start(msound)) return 1;
 intf = msound->sound_interface;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  int volume;
  char name[20];
  sprintf(name,"%s #%d FM",sound_name(msound),i);
  volume = intf->mixing_level[i]>>16;
  stream[i] = stream_init(name,volume,Machine->sample_rate,i,YM2203UpdateOne );
 }
 if (YM2203Init(intf->num,intf->baseclock,Machine->sample_rate,TimerHandler,IRQHandler) == 0)
 {
  return 0;
 }
 return 1;
}

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

variable_types: i int

variable_types:
name
char [20]


decompiled_code:
__int64 YM2203_sh_stop()
{
return YM2203Shutdown();
}

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

original_code:
void YM2203_sh_stop(void)
{
 YM2203Shutdown();
}

canonical_original_code:
void YM2203_sh_stop()
{
 YM2203Shutdown();
}


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

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

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

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

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

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


decompiled_code:
__int64 YM2203_status_port_0_r()
{
return (unsigned __int8)YM2203Read(0LL, 0LL);
}

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

original_code: data_t YM2203_status_port_0_r(offs_t offset) { return YM2203Read(0,0); }

canonical_original_code: unsigned int YM2203_status_port_0_r(unsigned int offset) { return YM2203Read(0,0); }


decompiled_code:
__int64 YM2203_status_port_1_r()
{
return (unsigned __int8)YM2203Read(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int8)YM2203Read(1LL, 0LL);
}

original_code: data_t YM2203_status_port_1_r(offs_t offset) { return YM2203Read(1,0); }

canonical_original_code: unsigned int YM2203_status_port_1_r(unsigned int offset) { return YM2203Read(1,0); }


decompiled_code:
__int64 YM2203_status_port_2_r()
{
return (unsigned __int8)YM2203Read(2LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int8)YM2203Read(2LL, 0LL);
}

original_code: data_t YM2203_status_port_2_r(offs_t offset) { return YM2203Read(2,0); }

canonical_original_code: unsigned int YM2203_status_port_2_r(unsigned int offset) { return YM2203Read(2,0); }


decompiled_code:
__int64 YM2203_status_port_3_r()
{
return (unsigned __int8)YM2203Read(3LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)YM2203Read(3LL, 0LL);
}

original_code: data_t YM2203_status_port_3_r(offs_t offset) { return YM2203Read(3,0); }

canonical_original_code: unsigned int YM2203_status_port_3_r(unsigned int offset) { return YM2203Read(3,0); }


decompiled_code:
__int64 YM2203_status_port_4_r()
{
return (unsigned __int8)YM2203Read(4LL, 0LL);
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned __int8)YM2203Read(4LL, 0LL);
}

original_code: data_t YM2203_status_port_4_r(offs_t offset) { return YM2203Read(4,0); }

canonical_original_code: unsigned int YM2203_status_port_4_r(unsigned int offset) { return YM2203Read(4,0); }


decompiled_code:
__int64 YM2203_read_port_0_r()
{
return (unsigned __int8)YM2203Read(0LL, 1LL);
}

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

original_code: data_t YM2203_read_port_0_r(offs_t offset) { return YM2203Read(0,1); }

canonical_original_code: unsigned int YM2203_read_port_0_r(unsigned int offset) { return YM2203Read(0,1); }


decompiled_code:
__int64 YM2203_read_port_1_r()
{
return (unsigned __int8)YM2203Read(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned __int8)YM2203Read(1LL, 1LL);
}

original_code: data_t YM2203_read_port_1_r(offs_t offset) { return YM2203Read(1,1); }

canonical_original_code: unsigned int YM2203_read_port_1_r(unsigned int offset) { return YM2203Read(1,1); }


decompiled_code:
__int64 YM2203_read_port_2_r()
{
return (unsigned __int8)YM2203Read(2LL, 1LL);
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned __int8)YM2203Read(2LL, 1LL);
}

original_code: data_t YM2203_read_port_2_r(offs_t offset) { return YM2203Read(2,1); }

canonical_original_code: unsigned int YM2203_read_port_2_r(unsigned int offset) { return YM2203Read(2,1); }


decompiled_code:
__int64 YM2203_read_port_3_r()
{
return (unsigned __int8)YM2203Read(3LL, 1LL);
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned __int8)YM2203Read(3LL, 1LL);
}

original_code: data_t YM2203_read_port_3_r(offs_t offset) { return YM2203Read(3,1); }

canonical_original_code: unsigned int YM2203_read_port_3_r(unsigned int offset) { return YM2203Read(3,1); }


decompiled_code:
__int64 YM2203_read_port_4_r()
{
return (unsigned __int8)YM2203Read(4LL, 1LL);
}

canonical_decompiled_code:
__int64 func15()
{
return (unsigned __int8)YM2203Read(4LL, 1LL);
}

original_code: data_t YM2203_read_port_4_r(offs_t offset) { return YM2203Read(4,1); }

canonical_original_code: unsigned int YM2203_read_port_4_r(unsigned int offset) { return YM2203Read(4,1); }


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

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

original_code:
void YM2203_control_port_0_w(offs_t offset,data_t data)
{
 YM2203Write(0,0,data);
}

canonical_original_code:
void YM2203_control_port_0_w(unsigned int offset, unsigned int data)
{
 YM2203Write(0,0,data);
}


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

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

original_code:
void YM2203_control_port_1_w(offs_t offset,data_t data)
{
 YM2203Write(1,0,data);
}

canonical_original_code:
void YM2203_control_port_1_w(unsigned int offset, unsigned int data)
{
 YM2203Write(1,0,data);
}


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

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

original_code:
void YM2203_control_port_2_w(offs_t offset,data_t data)
{
 YM2203Write(2,0,data);
}

canonical_original_code:
void YM2203_control_port_2_w(unsigned int offset, unsigned int data)
{
 YM2203Write(2,0,data);
}


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

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

original_code:
void YM2203_control_port_3_w(offs_t offset,data_t data)
{
 YM2203Write(3,0,data);
}

canonical_original_code:
void YM2203_control_port_3_w(unsigned int offset, unsigned int data)
{
 YM2203Write(3,0,data);
}


decompiled_code:
__int64 __fastcall YM2203_control_port_4_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 0LL, a2);
}

original_code:
void YM2203_control_port_4_w(offs_t offset,data_t data)
{
 YM2203Write(4,0,data);
}

canonical_original_code:
void YM2203_control_port_4_w(unsigned int offset, unsigned int data)
{
 YM2203Write(4,0,data);
}


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

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

original_code:
void YM2203_write_port_0_w(offs_t offset,data_t data)
{
 YM2203Write(0,1,data);
}

canonical_original_code:
void YM2203_write_port_0_w(unsigned int offset, unsigned int data)
{
 YM2203Write(0,1,data);
}


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

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

original_code:
void YM2203_write_port_1_w(offs_t offset,data_t data)
{
 YM2203Write(1,1,data);
}

canonical_original_code:
void YM2203_write_port_1_w(unsigned int offset, unsigned int data)
{
 YM2203Write(1,1,data);
}


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

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

original_code:
void YM2203_write_port_2_w(offs_t offset,data_t data)
{
 YM2203Write(2,1,data);
}

canonical_original_code:
void YM2203_write_port_2_w(unsigned int offset, unsigned int data)
{
 YM2203Write(2,1,data);
}


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

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

original_code:
void YM2203_write_port_3_w(offs_t offset,data_t data)
{
 YM2203Write(3,1,data);
}

canonical_original_code:
void YM2203_write_port_3_w(unsigned int offset, unsigned int data)
{
 YM2203Write(3,1,data);
}


decompiled_code:
__int64 __fastcall YM2203_write_port_4_w(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, unsigned __int8 a2)
{
return YM2203Write(4LL, 1LL, a2);
}

original_code:
void YM2203_write_port_4_w(offs_t offset,data_t data)
{
 YM2203Write(4,1,data);
}

canonical_original_code:
void YM2203_write_port_4_w(unsigned int offset, unsigned int data)
{
 YM2203Write(4,1,data);
}


FMTimerInit

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

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

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

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


decompiled_code:
unsigned __int64 __fastcall cheekyms_vh_convert_color_prom(_BYTE *a1, __int64 a2, _BYTE *a3)
{
int v3; // er9
unsigned __int64 result; // rax
_BYTE *v5; // rcx
unsigned int v6; // er8
unsigned int v7; // ecx

v3 = 3;
do
{
result = *(_QWORD *)(Machine + 824LL);
v5 = a3;
v6 = 0;
if ( *(_DWORD *)(result + 696) > 5u )
{
do
{
*a1 = -(*v5 & 1);
a1[1] = -((*v5 & 2) != 0);
a1 += 3;
*(a1 - 1) = -((*v5++ & 4) != 0);
++v6;
result = *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL) / 6uLL;
}
while ( (unsigned int)result > v6 );
if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > 5u )
{
v7 = 0;
do
{
*a1 = -((*a3 & 0x10) != 0);
a1[1] = -((*a3 & 0x20) != 0);
a1 += 3;
*(a1 - 1) = -((*a3++ & 0x40) != 0);
++v7;
result = *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL) / 6uLL;
}
while ( (unsigned int)result > v7 );
}
}
--v3;
}
while ( v3 );
return result;
}

original_code:
void cheekyms_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i,j,bit;
 for (i = 0; i < 3; i++)
 {
  const unsigned char* color_prom_save = color_prom;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 0) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 1) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 2) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
  color_prom = color_prom_save;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 4) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 5) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 6) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
 }
}

canonical_original_code:
void cheekyms_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i; int j; int bit;
 for (i = 0; i < 3; i++)
 {
  unsigned char *color_prom_save = color_prom;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 0) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 1) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 2) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
  color_prom = color_prom_save;
  for (j = 0;j < Machine->drv->total_colors/6;j++)
  {
   bit = (color_prom[0] >> 4) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 5) & 0x01;
   *(palette++) = 0xff * bit;
   bit = (color_prom[0] >> 6) & 0x01;
   *(palette++) = 0xff * bit;
   color_prom++;
  }
 }
}

variable_types:
palette
unsigned char *

variable_types: j int

variable_types: bit int


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

result = a2 & 0x80;
if ( (_DWORD)result != last_dac_0 )
{
last_dac_0 = a2 & 0x80;
result = DAC_data_w(0LL, a2 & 0x80);
}
return result;
}

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

result = a2 & 0x80;
if ( (_DWORD)result != last_dac_0 )
{
last_dac_0 = a2 & 0x80;
result = DAC_data_w(0LL, a2 & 0x80);
}
return result;
}

original_code:
void cheekyms_port_40_w(offs_t offset,data_t data)
{
 static int last_dac = -1;
 if (last_dac != (data & 0x80))
 {
  last_dac = data & 0x80;
  DAC_data_w(0, last_dac ? 0x80 : 0);
 }
}

canonical_original_code:
void cheekyms_port_40_w(unsigned int offset, unsigned int data)
{
 static int last_dac = -1;
 if (last_dac != (data & 0x80))
 {
  last_dac = data & 0x80;
  DAC_data_w(0, last_dac ? 0x80 : 0);
 }
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall cheekyms_port_80_w(__int64 a1, unsigned int a2)
{
interrupt_enable_w(a1, a2 & 4);
if ( man_scroll != ((a2 >> 3) & 7) )
{
man_scroll = (a2 >> 3) & 7;
redraw_man = 1;
}
set_vh_global_attribute(&char_palette, (a2 >> 2) & 0x10);
return flip_screen_w((unsigned int)a1, (unsigned __int8)a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
interrupt_enable_w(a1, a2 & 4);
if ( man_scroll != ((a2 >> 3) & 7) )
{
man_scroll = (a2 >> 3) & 7;
redraw_man = 1;
}
set_vh_global_attribute(&char_palette, (a2 >> 2) & 0x10);
return flip_screen_w((unsigned int)a1, (unsigned __int8)a2 & 0x80);
}

original_code:
void cheekyms_port_80_w(offs_t offset,data_t data)
{
 int new_man_scroll;
 interrupt_enable_w(offset, data & 0x04);
    new_man_scroll = (data >> 3) & 0x07;
 if (man_scroll != new_man_scroll)
 {
  man_scroll = new_man_scroll;
  redraw_man = 1;
 }
 set_vh_global_attribute(&char_palette, (data >> 2) & 0x10);
 flip_screen_w(offset, data & 0x80);
}

canonical_original_code:
void cheekyms_port_80_w(unsigned int offset, unsigned int data)
{
 int new_man_scroll;
 interrupt_enable_w(offset, data & 0x04);
    new_man_scroll = (data >> 3) & 0x07;
 if (man_scroll != new_man_scroll)
 {
  man_scroll = new_man_scroll;
  redraw_man = 1;
 }
 set_vh_global_attribute(&char_palette, (data >> 2) & 0x10);
 flip_screen_w(offset, data & 0x80);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall cheekyms_vh_screenrefresh(__int64 a1, int a2)
{
int *v2; // r14
int v3; // ebp
__int64 v4; // r15
__int64 v5; // r13
unsigned int v6; // eax
char v7; // r12
int v8; // ebx
int v9; // ebx
__int64 v10; // rbp
__int64 v11; // rdi
__int64 v12; // r10
int v13; // eax
int v14; // er9
int v15; // esi
int v16; // eax
int v17; // ecx
__int64 v18; // r8
unsigned int v20; // [rsp+4h] [rbp-44h]

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
v2 = sprites;
do
{
if ( (v2[3] & 8) != 0 )
{
v3 = *v2;
v4 = (unsigned int)v2[1];
v5 = (unsigned int)(256 - v2[2]);
v6 = v2[3] & 7;
v20 = v6;
v7 = ~(unsigned __int8)*v2;
v8 = (2 * v7) & 0x1F;
if ( (*v2 & 0x80u) == 0 )
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(v8 + 32),
v6,
0LL,
0LL,
v5,
v4,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(v8 + 33),
v20,
0LL,
0LL,
(unsigned int)v5 + 8 * (v3 & 2),
(unsigned int)v4 + 8 * (v7 & 2),
Machine + 776LL,
2LL,
0LL);
}
else
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(flip_screen_x == 0) + v8,
v6,
0LL,
0LL,
v5,
v4,
Machine + 776LL,
2LL,
0LL);
}
}
v2 += 4;
}
while ( v2 != &char_palette + 136 );
v9 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v10 = v9;
do
{
v16 = v9 % 32;
v15 = v9 % 32;
v17 = v9 / 32;
v18 = flip_screen_x;
if ( flip_screen_x )
{
if ( (unsigned int)(v17 - 5) > 0x14 || (unsigned int)(v16 - 8) > 4 )
goto LABEL_26;
}
else if ( (unsigned int)(v17 - 6) > 0x14 || (unsigned int)(v16 - 8) > 4 )
{
LABEL_26:
if ( !*((_BYTE *)dirtybuffer + v10) )
goto LABEL_22;
*((_BYTE *)dirtybuffer + v10) = 0;
v18 = flip_screen_x;
if ( !flip_screen_x )
{
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * v17;
v14 = 0;
goto LABEL_21;
}
v14 = 0;
LABEL_19:
v15 = 31 - v16;
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * (31 - v17);
if ( v14 )
LABEL_20:
v14 = man_scroll;
LABEL_21:
drawgfx(
tmpbitmap,
*(_QWORD *)(v11 + 512),
*(unsigned __int8 *)(videoram + v10),
(unsigned int)char_palette,
v18,
(unsigned int)v18,
(unsigned int)(8 * v15),
(unsigned int)(v13 - v14),
v12,
0LL,
0LL);
goto LABEL_22;
}
if ( *((_BYTE *)dirtybuffer + v10) )
{
*((_BYTE *)dirtybuffer + v10) = 0;
v18 = flip_screen_x;
v14 = 1;
if ( flip_screen_x )
goto LABEL_19;
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * v17;
goto LABEL_20;
}
if ( redraw_man )
{
if ( flip_screen_x )
{
v14 = 1;
goto LABEL_19;
}
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * v17;
goto LABEL_20;
}
LABEL_22:
--v10;
--v9;
}
while ( v9 >= 0 );
}
redraw_man = 0;
return copybitmap(
a1,
tmpbitmap,
0LL,
0LL,
0LL,
0LL,
Machine + 776LL,
2LL,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned int)(4 * char_palette)));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int *v2; // r14
int v3; // ebp
__int64 v4; // r15
__int64 v5; // r13
unsigned int v6; // eax
char v7; // r12
int v8; // ebx
int v9; // ebx
__int64 v10; // rbp
__int64 v11; // rdi
__int64 v12; // r10
int v13; // eax
int v14; // er9
int v15; // esi
int v16; // eax
int v17; // ecx
__int64 v18; // r8
unsigned int v20; // [rsp+4h] [rbp-44h]

if ( a2 )
memset(dirtybuffer, 1, videoram_size);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
v2 = sprites;
do
{
if ( (v2[3] & 8) != 0 )
{
v3 = *v2;
v4 = (unsigned int)v2[1];
v5 = (unsigned int)(256 - v2[2]);
v6 = v2[3] & 7;
v20 = v6;
v7 = ~(unsigned __int8)*v2;
v8 = (2 * v7) & 0x1F;
if ( (*v2 & 0x80u) == 0 )
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(v8 + 32),
v6,
0LL,
0LL,
v5,
v4,
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(v8 + 33),
v20,
0LL,
0LL,
(unsigned int)v5 + 8 * (v3 & 2),
(unsigned int)v4 + 8 * (v7 & 2),
Machine + 776LL,
2LL,
0LL);
}
else
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(unsigned int)(flip_screen_x == 0) + v8,
v6,
0LL,
0LL,
v5,
v4,
Machine + 776LL,
2LL,
0LL);
}
}
v2 += 4;
}
while ( v2 != &char_palette + 136 );
v9 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v10 = v9;
do
{
v16 = v9 % 32;
v15 = v9 % 32;
v17 = v9 / 32;
v18 = flip_screen_x;
if ( flip_screen_x )
{
if ( (unsigned int)(v17 - 5) > 0x14 || (unsigned int)(v16 - 8) > 4 )
goto LABEL_26;
}
else if ( (unsigned int)(v17 - 6) > 0x14 || (unsigned int)(v16 - 8) > 4 )
{
LABEL_26:
if ( !*((_BYTE *)dirtybuffer + v10) )
goto LABEL_22;
*((_BYTE *)dirtybuffer + v10) = 0;
v18 = flip_screen_x;
if ( !flip_screen_x )
{
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * v17;
v14 = 0;
goto LABEL_21;
}
v14 = 0;
LABEL_19:
v15 = 31 - v16;
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * (31 - v17);
if ( v14 )
LABEL_20:
v14 = man_scroll;
LABEL_21:
drawgfx(
tmpbitmap,
*(_QWORD *)(v11 + 512),
*(unsigned __int8 *)(videoram + v10),
(unsigned int)char_palette,
v18,
(unsigned int)v18,
(unsigned int)(8 * v15),
(unsigned int)(v13 - v14),
v12,
0LL,
0LL);
goto LABEL_22;
}
if ( *((_BYTE *)dirtybuffer + v10) )
{
*((_BYTE *)dirtybuffer + v10) = 0;
v18 = flip_screen_x;
v14 = 1;
if ( flip_screen_x )
goto LABEL_19;
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * v17;
goto LABEL_20;
}
if ( redraw_man )
{
if ( flip_screen_x )
{
v14 = 1;
goto LABEL_19;
}
v11 = Machine;
v12 = Machine + 776LL;
v13 = 8 * v17;
goto LABEL_20;
}
LABEL_22:
--v10;
--v9;
}
while ( v9 >= 0 );
}
redraw_man = 0;
return copybitmap(
a1,
tmpbitmap,
0LL,
0LL,
0LL,
0LL,
Machine + 776LL,
2LL,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned int)(4 * char_palette)));
}

original_code:
void cheekyms_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 for (offs = 0; offs < sizeof(sprites); offs += 4)
 {
  int v1, sx, sy, col, code;
  v1 = sprites[offs + 0];
  sy = sprites[offs + 1];
  sx = 256 - sprites[offs + 2];
  col = (sprites[offs + 3] & 0x07);
  if (!(sprites[offs + 3] & 0x08)) continue;
  code = (~v1 << 1) & 0x1f;
  if (v1 & 0x80)
  {
   if (!flip_screen_x)
   {
    code++;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
  else
  {
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x20,
     col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x21,
     col,
     0,0,
     sx + 8*(v1 & 2),sy + 8*(~v1 & 2),
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy,man_area;
  sx = offs % 32;
  sy = offs / 32;
  if (flip_screen_x)
  {
   man_area = ((sy >= 5) && (sy <= 25) && (sx >= 8) && (sx <= 12));
  }
  else
  {
   man_area = ((sy >= 6) && (sy <= 26) && (sx >= 8) && (sx <= 12));
  }
  if (dirtybuffer[offs] ||
   (redraw_man && man_area))
  {
   dirtybuffer[offs] = 0;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     0 + char_palette,
     flip_screen_x,flip_screen_x,
     8*sx, 8*sy - (man_area ? man_scroll : 0),
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 redraw_man = 0;
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,Machine->pens[4*char_palette]);
}

canonical_original_code:
void cheekyms_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (full_refresh)
 {
  memset(dirtybuffer, 1, videoram_size);
 }
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 for (offs = 0; offs < sizeof(sprites); offs += 4)
 {
  int v1; int sx; int sy; int col; int code;
  v1 = sprites[offs + 0];
  sy = sprites[offs + 1];
  sx = 256 - sprites[offs + 2];
  col = (sprites[offs + 3] & 0x07);
  if (!(sprites[offs + 3] & 0x08)) continue;
  code = (~v1 << 1) & 0x1f;
  if (v1 & 0x80)
  {
   if (!flip_screen_x)
   {
    code++;
   }
   drawgfx(bitmap,Machine->gfx[1],
     code,col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
  else
  {
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x20,
     col,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[1],
     code + 0x21,
     col,
     0,0,
     sx + 8*(v1 & 2),sy + 8*(~v1 & 2),
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy; int man_area;
  sx = offs % 32;
  sy = offs / 32;
  if (flip_screen_x)
  {
   man_area = ((sy >= 5) && (sy <= 25) && (sx >= 8) && (sx <= 12));
  }
  else
  {
   man_area = ((sy >= 6) && (sy <= 26) && (sx >= 8) && (sx <= 12));
  }
  if (dirtybuffer[offs] ||
   (redraw_man && man_area))
  {
   dirtybuffer[offs] = 0;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs],
     0 + char_palette,
     flip_screen_x,flip_screen_x,
     8*sx, 8*sy - (man_area ? man_scroll : 0),
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 redraw_man = 0;
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_PEN,Machine->pens[4*char_palette]);
}

variable_types: col int

variable_types: code int


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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

original_code:
static int cheekyms_interrupt(void)
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return interrupt();
}

canonical_original_code:
static int cheekyms_interrupt()
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return interrupt();
}


decompiled_code:
void __fastcall avalnche_noise_amplitude_w(__int64 a1, char a2)
{
volume = a2 & 0x3F;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
volume = a2 & 0x3F;
}

original_code:
void avalnche_noise_amplitude_w(offs_t offset,data_t data)
{
 volume = data & 0x3F;
}

canonical_original_code:
void avalnche_noise_amplitude_w(unsigned int offset, unsigned int data)
{
 volume = data & 0x3F;
}


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

result = a1;
*(_BYTE *)(videoram + a1) = a2;
if ( a1 > 0x1FF )
{
for ( i = 0; i != 8; ++i )
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
8 * (a1 & 0x1F) + 7 - i,
a1 >> 5,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1)));
}
return result;
}

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

result = a1;
*(_BYTE *)(videoram + a1) = a2;
if ( a1 > 0x1FF )
{
for ( i = 0; i != 8; ++i )
result = plot_pixel(
*(_QWORD *)(Machine + 768LL),
8 * (a1 & 0x1F) + 7 - i,
a1 >> 5,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1)));
}
return result;
}

original_code:
void avalnche_videoram_w(offs_t offset,data_t data)
{
 videoram[offset] = data;
 if (offset >= 0x200)
 {
  int x,y,i;
  x = 8 * (offset % 32);
  y = offset / 32;
  for (i = 0;i < 8;i++)
   plot_pixel(Machine->scrbitmap,x+7-i,y,Machine->pens[(data >> i) & 1]);
 }
}

canonical_original_code:
void avalnche_videoram_w(unsigned int offset, unsigned int data)
{
 videoram[offset] = data;
 if (offset >= 0x200)
 {
  int x; int y; int i;
  x = 8 * (offset % 32);
  y = offset / 32;
  for (i = 0;i < 8;i++)
   plot_pixel(Machine->scrbitmap,x+7-i,y,Machine->pens[(data >> i) & 1]);
 }
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall avalnche_input_r(char a1)
{
int v1; // edx
__int64 result; // rax

v1 = a1 & 3;
if ( v1 == 1 )
return input_port_1_r();
if ( v1 == 2 )
return input_port_2_r();
result = 0LL;
if ( (a1 & 3) == 0 )
result = input_port_0_r();
return result;
}

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

v1 = a1 & 3;
if ( v1 == 1 )
return input_port_1_r();
if ( v1 == 2 )
return input_port_2_r();
result = 0LL;
if ( (a1 & 3) == 0 )
result = input_port_0_r();
return result;
}

original_code:
data_t avalnche_input_r(offs_t offset)
{
 switch (offset & 0x03)
 {
  case 0x00: return input_port_0_r(offset);
  case 0x01: return input_port_1_r(offset);
  case 0x02: return input_port_2_r(offset);
  case 0x03: return 0;
 }
 return 0;
}

canonical_original_code:
unsigned int avalnche_input_r(unsigned int offset)
{
 switch (offset & 0x03)
 {
  case 0x00: return input_port_0_r(offset);
  case 0x01: return input_port_1_r(offset);
  case 0x02: return input_port_2_r(offset);
  case 0x03: return 0;
 }
 return 0;
}