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

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

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

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

variable_types:
offset
unsigned int


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

if ( sound_cpu == 1 )
v1 = memory_region(130LL);
else
v1 = memory_region(131LL);
if ( (unsigned int)cpu_get_pc() == 297 && !*(_BYTE *)(v1 + 8220) )
cpu_spinuntil_int();
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}

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

if ( sound_cpu == 1 )
v1 = memory_region(130LL);
else
v1 = memory_region(131LL);
if ( (unsigned int)cpu_get_pc() == 297 && !*(_BYTE *)(v1 + 8220) )
cpu_spinuntil_int();
return *(unsigned __int8 *)(v1 + (unsigned int)(a1 + 8220));
}

original_code:
static data_t sound_cpu_spin_r(offs_t offset)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (cpu_get_pc()==0x129 && RAM[0x201c]==0)
  cpu_spinuntil_int();
 return RAM[0x201c+offset];
}

canonical_original_code:
static unsigned int sound_cpu_spin_r(unsigned int offset)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (cpu_get_pc()==0x129 && RAM[0x201c]==0)
  cpu_spinuntil_int();
 return RAM[0x201c+offset];
}

variable_types:
RAM
unsigned char *

return_type: unsigned int


decompiled_code:
void seibu_rst10_ack_w()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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

variable_types:
data
unsigned int

return_type: void


decompiled_code:
__int64 seibu_rst18_ack_w()
{
return timer_set(0LL, 4LL, setvector_callback);
}

canonical_decompiled_code:
__int64 func3()
{
return timer_set(0LL, 4LL, setvector_callback);
}

original_code:
void seibu_rst18_ack_w(offs_t offset,data_t data)
{
 timer_set((0),RST18_CLEAR,setvector_callback);
}

canonical_original_code:
void seibu_rst18_ack_w(unsigned int offset, unsigned int data)
{
 timer_set((0),RST18_CLEAR,setvector_callback);
}


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

if ( a1 )
result = timer_set(0LL, 1LL, setvector_callback);
else
result = timer_set(0LL, 2LL, setvector_callback);
return result;
}

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

if ( a1 )
result = timer_set(0LL, 1LL, setvector_callback);
else
result = timer_set(0LL, 2LL, setvector_callback);
return result;
}

original_code:
void seibu_ym3812_irqhandler(int linestate)
{
 if (linestate)
  timer_set((0),RST10_ASSERT,setvector_callback);
 else
  timer_set((0),RST10_CLEAR,setvector_callback);
}

variable_types: linestate int


decompiled_code:
__int64 seibu_sound_init_1()
{
sound_cpu = 1;
return setvector_callback(0);
}

canonical_decompiled_code:
__int64 func5()
{
sound_cpu = 1;
return func0(0);
}

original_code:
void seibu_sound_init_1(void)
{
 sound_cpu=1;
 setvector_callback(VECTOR_INIT);
}

canonical_original_code:
void seibu_sound_init_1()
{
 sound_cpu=1;
 setvector_callback(VECTOR_INIT);
}


decompiled_code:
__int64 seibu_sound_init_2()
{
sound_cpu = 2;
return setvector_callback(0);
}

canonical_decompiled_code:
__int64 func6()
{
sound_cpu = 2;
return func0(0);
}

original_code:
void seibu_sound_init_2(void)
{
 sound_cpu=2;
 setvector_callback(VECTOR_INIT);
}

canonical_original_code:
void seibu_sound_init_2()
{
 sound_cpu=2;
 setvector_callback(VECTOR_INIT);
}


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

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

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

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

original_code:
void seibu_bank_w(offs_t offset,data_t data)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (data&1) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x0000]); 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()); } } }; }
}

canonical_original_code:
void seibu_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM;
 if (sound_cpu==1) RAM = memory_region(REGION_CPU2);
 else RAM = memory_region(REGION_CPU3);
 if (data&1) { { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x0000]); 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()); } } }; }
}


decompiled_code:
__int64 __fastcall seibu_soundlatch_r(int a1)
{
return *(unsigned __int8 *)(seibu_shared_sound_ram + (unsigned int)(2 * a1));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return *(unsigned __int8 *)(seibu_shared_sound_ram + (unsigned int)(2 * a1));
}

original_code:
data_t seibu_soundlatch_r(offs_t offset)
{
 return seibu_shared_sound_ram[offset<<1];
}

canonical_original_code:
unsigned int seibu_soundlatch_r(unsigned int offset)
{
 return seibu_shared_sound_ram[offset<<1];
}


decompiled_code:
__int64 __fastcall install_seibu_sound_speedup(__int64 a1)
{
return install_mem_read_handler(a1, 8220LL, 8221LL, sound_cpu_spin_r);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return install_mem_read_handler(a1, 8220LL, 8221LL, sound_cpu_spin_r);
}

original_code:
void install_seibu_sound_speedup(int cpu)
{
 install_mem_read_handler(cpu, 0x201c, 0x201d, sound_cpu_spin_r);
}

variable_types: cpu int


decompiled_code:
__int64 seibu_sound_decrypt()
{
__int64 v0; // r8
__int64 i; // rdx
__int64 result; // rax
int v3[130]; // [rsp+0h] [rbp-208h] BYREF

v0 = memory_region(131LL);
qmemcpy(v3, &unk_360, 0x200uLL);
for ( i = 0LL; i != 98304; ++i )
{
result = (unsigned int)v3[(int)i % 128];
*(_BYTE *)(v0 + i) ^= result;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // r8
__int64 i; // rdx
__int64 result; // rax
int v3[130]; // [rsp+0h] [rbp-208h] BYREF

v0 = memory_region(131LL);
qmemcpy(v3, &unk_360, 0x200uLL);
for ( i = 0LL; i != 98304; ++i )
{
result = (unsigned int)v3[(int)i % 128];
*(_BYTE *)(v0 + i) ^= result;
}
return result;
}

variable_types: i int


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

switch ( a1 )
{
case 0:
irq2_1 = 255;
irq1_0 = 255;
break;
case 1:
irq1_0 = 215;
break;
case 2:
irq1_0 = 255;
break;
case 3:
irq2_1 = 223;
break;
case 4:
irq2_1 = 255;
break;
default:
break;
}
cpu_irq_line_vector_w((unsigned int)sound_cpu, 0LL, irq2_1 & (unsigned int)irq1_0);
if ( (irq2_1 & irq1_0) == 255 )
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 0LL);
else
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 1LL);
return result;
}

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

switch ( a1 )
{
case 0:
irq2_1 = 255;
irq1_0 = 255;
break;
case 1:
irq1_0 = 215;
break;
case 2:
irq1_0 = 255;
break;
case 3:
irq2_1 = 223;
break;
case 4:
irq2_1 = 255;
break;
default:
break;
}
cpu_irq_line_vector_w((unsigned int)sound_cpu, 0LL, irq2_1 & (unsigned int)irq1_0);
if ( (irq2_1 & irq1_0) == 255 )
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 0LL);
else
result = cpu_set_irq_line((unsigned int)sound_cpu, 0LL, 1LL);
return result;
}

original_code:
static void setvector_callback(int param)
{
 static int irq1,irq2;
 switch(param)
 {
  case VECTOR_INIT:
   irq1 = irq2 = 0xff;
   break;
  case RST10_ASSERT:
   irq1 = 0xd7;
   break;
  case RST10_CLEAR:
   irq1 = 0xff;
   break;
  case RST18_ASSERT:
   irq2 = 0xdf;
   break;
  case RST18_CLEAR:
   irq2 = 0xff;
   break;
 }
 cpu_irq_line_vector_w(sound_cpu,0,irq1 & irq2);
 if ((irq1 & irq2) == 0xff)
  cpu_set_irq_line(sound_cpu,0,0);
 else
  cpu_set_irq_line(sound_cpu,0,1);
}

canonical_original_code:
static void setvector_callback(int param)
{
 static int irq1; static int irq2;
 switch(param)
 {
  case VECTOR_INIT:
   irq1 = irq2 = 0xff;
   break;
  case RST10_ASSERT:
   irq1 = 0xd7;
   break;
  case RST10_CLEAR:
   irq1 = 0xff;
   break;
  case RST18_ASSERT:
   irq2 = 0xdf;
   break;
  case RST18_CLEAR:
   irq2 = 0xff;
   break;
 }
 cpu_irq_line_vector_w(sound_cpu,0,irq1 & irq2);
 if ((irq1 & irq2) == 0xff)
  cpu_set_irq_line(sound_cpu,0,0);
 else
  cpu_set_irq_line(sound_cpu,0,1);
}

variable_types: param int


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

layer_colorbase[0] = 64;
dword_74C = 0;
dword_750 = 16;
sprite_colorbase = 32;
zoom_colorbase = 48;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
if ( (unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
K052109_vh_stop();
result = 1LL;
}
else
{
result = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
K051960_vh_stop();
result = 1LL;
}
}
}
return result;
}

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

layer_colorbase[0] = 64;
dword_74C = 0;
dword_750 = 16;
sprite_colorbase = 32;
zoom_colorbase = 48;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
if ( (unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
K052109_vh_stop();
result = 1LL;
}
else
{
result = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
K051960_vh_stop();
result = 1LL;
}
}
}
return result;
}

original_code:
int k88games_vh_start(void)
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 zoom_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int k88games_vh_start()
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 zoom_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall k88games_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 v3; // rdx
__int64 result; // rax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
if ( palette_recalc(a1, v2, v3, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( k88games_priority )
{
K052109_tilemap_draw(a1, 0LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
result = K051316_zoom_draw_0(a1, 0LL);
}
else
{
K052109_tilemap_draw(a1, 2LL, 16LL);
K051316_zoom_draw_0(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 1LL, 1LL);
result = K052109_tilemap_draw(a1, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 v3; // rdx
__int64 result; // rax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
if ( palette_recalc(a1, v2, v3, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( k88games_priority )
{
K052109_tilemap_draw(a1, 0LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
result = K051316_zoom_draw_0(a1, 0LL);
}
else
{
K052109_tilemap_draw(a1, 2LL, 16LL);
K051316_zoom_draw_0(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 1LL, 1LL);
result = K052109_tilemap_draw(a1, 0LL, 0LL);
}
return result;
}

original_code:
void k88games_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i;
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0;i < 16;i++)
  palette_used_colors[(zoom_colorbase + i) * 16] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (k88games_priority)
 {
  K052109_tilemap_draw(bitmap,0,0x10);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,2,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,0,0);
  K051316_zoom_draw_0(bitmap,0);
 }
 else
 {
  K052109_tilemap_draw(bitmap,2,0x10);
  K051316_zoom_draw_0(bitmap,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,0,0);
 }
}

canonical_original_code:
void k88games_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0;i < 16;i++)
  palette_used_colors[(zoom_colorbase + i) * 16] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (k88games_priority)
 {
  K052109_tilemap_draw(bitmap,0,0x10);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,2,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,0,0);
  K051316_zoom_draw_0(bitmap,0);
 }
 else
 {
  K052109_tilemap_draw(bitmap,2,0x10);
  K051316_zoom_draw_0(bitmap,0);
  K051960_sprites_draw(bitmap,0,0);
  K052109_tilemap_draw(bitmap,1,0);
  K051960_sprites_draw(bitmap,1,1);
  K052109_tilemap_draw(bitmap,0,0);
 }
}

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


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

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

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

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


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

konami_cpu_setlines_callback = k88games_banking;
result = memory_region(129LL) + 0x20000;
paletteram = result;
return result;
}

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

konami_cpu_setlines_callback = k88games_banking;
result = memory_region(129LL) + 0x20000;
paletteram = result;
return result;
}

original_code:
static void k88games_init_machine( void )
{
 konami_cpu_setlines_callback = k88games_banking;
 paletteram = &memory_region(REGION_CPU1)[0x20000];
}

canonical_original_code:
static void k88games_init_machine()
{
 konami_cpu_setlines_callback = k88games_banking;
 paletteram = &memory_region(REGION_CPU1)[0x20000];
}


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

speech_chip = (a2 >> 2) & 1;
result = UPD7759_reset_w((a2 >> 2) & 1, (a2 >> 1) & 1);
if ( !invalid_code )
result = UPD7759_start_w((unsigned int)speech_chip, ((unsigned __int8)a2 ^ 1) & 1);
return result;
}

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

speech_chip = (a2 >> 2) & 1;
result = UPD7759_reset_w((a2 >> 2) & 1, (a2 >> 1) & 1);
if ( !invalid_code )
result = UPD7759_start_w((unsigned int)speech_chip, ((unsigned __int8)a2 ^ 1) & 1);
return result;
}

original_code:
static void speech_control_w(offs_t offset,data_t data)
{
 int reset = ( ( data >> 1 ) & 1 );
 int start = ( ~data ) & 1;
 speech_chip = ( data & 4 ) ? 1 : 0;
 UPD7759_reset_w( speech_chip, reset );
 if (!invalid_code)
  UPD7759_start_w( speech_chip, start );
}

canonical_original_code:
static void speech_control_w(unsigned int offset, unsigned int data)
{
 int reset = ( ( data >> 1 ) & 1 );
 int start = ( ~data ) & 1;
 speech_chip = ( data & 4 ) ? 1 : 0;
 UPD7759_reset_w( speech_chip, reset );
 if (!invalid_code)
  UPD7759_start_w( speech_chip, start );
}

variable_types: reset int

variable_types: start int


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

UPD7759_message_w((unsigned int)speech_chip);
result = total_samples[speech_chip] == a2;
invalid_code = total_samples[speech_chip] == a2;
return result;
}

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

UPD7759_message_w((unsigned int)speech_chip);
result = total_samples[speech_chip] == a2;
invalid_code = total_samples[speech_chip] == a2;
return result;
}

original_code:
static void speech_msg_w(offs_t offset,data_t data)
{
 UPD7759_message_w( speech_chip, data );
 invalid_code = (data == total_samples[speech_chip]);
}

canonical_original_code:
static void speech_msg_w(unsigned int offset, unsigned int data)
{
 UPD7759_message_w( speech_chip, data );
 invalid_code = (data == total_samples[speech_chip]);
}


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int k88games_interrupt(void)
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int k88games_interrupt()
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}


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

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

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

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


decompiled_code:
__int64 __fastcall k88games_5f84_w(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = a2 & 4;
zoomreadroms = a2 & 4;
if ( (a2 & 0xF8) != 0 )
{
sprintf(v3, "5f84 = %02x", a2);
result = usrintf_showmessage(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = a2 & 4;
zoomreadroms = a2 & 4;
if ( (a2 & 0xF8) != 0 )
{
sprintf(v3, "5f84 = %02x", a2);
result = usrintf_showmessage(v3);
}
return result;
}

original_code:
static void k88games_5f84_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 zoomreadroms = data & 0x04;
 if (data & 0xf8)
 {
  char buf[40];
  sprintf(buf,"5f84 = %02x",data);
  usrintf_showmessage(buf);
 }
}

canonical_original_code:
static void k88games_5f84_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 zoomreadroms = data & 0x04;
 if (data & 0xf8)
 {
  char buf[40];
  sprintf(buf,"5f84 = %02x",data);
  usrintf_showmessage(buf);
 }
}

variable_types:
buf
char [40]


decompiled_code:
__int64 cheat_r()
{
unsigned int v0; // ebx

v0 = readinputport(1LL);
if ( (readinputport(0LL) & 8) == 0 )
{
v0 = bits_0[cheat_1] & (v0 | 0x55);
cheat_1 = (cheat_1 + 1) % 4;
}
return v0;
}

canonical_decompiled_code:
__int64 func15()
{
unsigned int v0; // ebx

v0 = readinputport(1LL);
if ( (readinputport(0LL) & 8) == 0 )
{
v0 = bits_0[cheat_1] & (v0 | 0x55);
cheat_1 = (cheat_1 + 1) % 4;
}
return v0;
}

original_code:
static data_t cheat_r(offs_t offset)
{
 int res;
 static int cheat = 0;
 static int bits[] = { 0xee, 0xff, 0xbb, 0xaa };
 res = readinputport(1);
 if ((readinputport(0) & 0x08) == 0)
 {
  res |= 0x55;
  res &= bits[cheat];
  cheat = (++cheat)%4;
 }
 return res;
}

canonical_original_code:
static unsigned int cheat_r(unsigned int offset)
{
 int res;
 static int cheat = 0;
 static int bits[] = { 0xee, 0xff, 0xbb, 0xaa };
 res = readinputport(1);
 if ((readinputport(0) & 0x08) == 0)
 {
  res |= 0x55;
  res &= bits[cheat];
  cheat = (++cheat)%4;
 }
 return res;
}

variable_types: res int

variable_types: cheat int

variable_types:
bits
int []


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

*a3 |= (a2 << 12) | ((unsigned __int16)*a4 << 8) & 0xF00;
result = layer_colorbase[a1] + ((*a4 >> 4) & 0xFu);
*a4 = result;
return result;
}

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

*a3 |= (a2 << 12) | ((unsigned __int16)*a4 << 8) & 0xF00;
result = layer_colorbase[a1] + ((*a4 >> 4) & 0xFu);
*a4 = result;
return result;
}

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

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

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

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

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

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

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

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

variable_types:
priority
int *

variable_types:
shadow
int *


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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = ((*a2 >> 4) & 8) + zoom_colorbase + ((*a2 >> 3) & 7u);
*a2 = result;
return result;
}

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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x700;
result = ((*a2 >> 4) & 8) + zoom_colorbase + ((*a2 >> 3) & 7u);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x38) >> 3) + ((*color & 0x80) >> 4);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x07) << 8);
 *color = zoom_colorbase + ((*color & 0x38) >> 3) + ((*color & 0x80) >> 4);
}


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, (unsigned int)nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, (unsigned int)nvram_size);
return memset(nvram, 0, nvram_size);
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
   memset(nvram,0,nvram_size);
 }
}

variable_types:
file
void *


decompiled_code:
__int64 __fastcall bankedram_r(unsigned int a1)
{
if ( videobank )
return *(unsigned __int8 *)(ram + a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
if ( videobank )
return *(unsigned __int8 *)(ram + a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (videobank) return ram[offset];
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (videobank) return ram[offset];
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall mystston_8910_latch_w(__int64 a1, int a2)
{
psg_latch = a2;
}

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

original_code:
void mystston_8910_latch_w(offs_t offset,data_t data)
{
 psg_latch = data;
}

canonical_original_code:
void mystston_8910_latch_w(unsigned int offset, unsigned int data)
{
 psg_latch = data;
}

variable_types:
data
unsigned int


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

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

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

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

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

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


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

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

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

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


decompiled_code:
void *__fastcall mystston_2000_w(__int64 a1, unsigned int a2)
{
void *result; // rax

textcolor = (a2 >> 1) & 1 | (2 * (_BYTE)a2) & 2;
coin_counter_w(0LL, a2 & 0x10);
coin_counter_w(1LL, a2 & 0x20);
result = (void *)((unsigned __int8)a2 & 0x80);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 0x80;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

textcolor = (a2 >> 1) & 1 | (2 * (_BYTE)a2) & 2;
coin_counter_w(0LL, a2 & 0x10);
coin_counter_w(1LL, a2 & 0x20);
result = (void *)((unsigned __int8)a2 & 0x80);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 0x80;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void mystston_2000_w(offs_t offset,data_t data)
{
 textcolor = ((data & 0x01) << 1) | ((data & 0x02) >> 1);
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void mystston_2000_w(unsigned int offset, unsigned int data)
{
 textcolor = ((data & 0x01) << 1) | ((data & 0x02) >> 1);
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
int *__fastcall mystston_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // eax
int v5; // ecx
_BOOL8 v6; // r9
int v7; // edx
int v8; // eax
unsigned __int64 v9; // rbx
__int64 v10; // rsi
__int64 v11; // r8
__int64 v12; // r9
unsigned __int8 v13; // al
__int64 v14; // r10
int *result; // rax
int v16; // ebx
__int64 v17; // rbp
int v18; // eax
int v19; // edi
int v20[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v7 = v2 % 32;
if ( flipscreen )
{
v4 = v2 / 32;
v5 = 31 - v7;
v6 = v7 <= 15;
}
else
{
v4 = v2 / -32 + 15;
v6 = v7 > 15;
v5 = v2 % 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 1) << 8),
0LL,
(unsigned int)flipscreen,
v6,
(unsigned int)(16 * v4),
(unsigned int)(16 * v5),
0LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
v8 = (unsigned __int8)*mystston_scroll;
v20[0] = -v8;
if ( flipscreen )
v20[0] = v8 + 256;
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 1LL, v20, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v9 = 0LL;
do
{
v13 = *(_BYTE *)(spriteram + v9);
if ( (v13 & 1) != 0 )
{
v14 = *(unsigned __int8 *)(spriteram + v9 + 3);
v10 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + v9 + 2));
v11 = v13 & 4;
v12 = v13 & 2;
if ( flipscreen )
{
v10 = (unsigned int)(240 - v10);
v11 = (_DWORD)v11 == 0;
v12 = (_DWORD)v12 == 0;
}
else
{
v14 = (unsigned int)(240 - v14);
}
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
((16 * v13) & 0x100) + (unsigned int)*(unsigned __int8 *)(spriteram + v9 + 1),
((int)v13 >> 3) & 1,
v11,
v12,
v14,
v10,
Machine + 776LL,
2LL,
0LL);
}
v9 += 4LL;
}
while ( spriteram_size > v9 );
}
result = &mystston_videoram2_size;
v16 = mystston_videoram2_size - 1;
if ( mystston_videoram2_size - 1 >= 0 )
{
v17 = v16;
do
{
v19 = v16 % 32;
if ( flipscreen )
{
v18 = v16 / 32;
v19 = 31 - v16 % 32;
}
else
{
v18 = v16 / -32 + 31;
}
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(mystston_videoram2 + v17)
+ ((unsigned __int8)(*(_BYTE *)(mystston_colorram2 + v17) & 7) << 8),
(unsigned int)textcolor,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v18),
(unsigned int)(8 * v19),
Machine + 776LL,
2LL,
0LL);
--v17;
--v16;
}
while ( v16 >= 0 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func5(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // eax
int v5; // ecx
_BOOL8 v6; // r9
int v7; // edx
int v8; // eax
unsigned __int64 v9; // rbx
__int64 v10; // rsi
__int64 v11; // r8
__int64 v12; // r9
unsigned __int8 v13; // al
__int64 v14; // r10
int *result; // rax
int v16; // ebx
__int64 v17; // rbp
int v18; // eax
int v19; // edi
int v20[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *((_BYTE *)dirtybuffer + v3) )
{
*((_BYTE *)dirtybuffer + v3) = 0;
v7 = v2 % 32;
if ( flipscreen )
{
v4 = v2 / 32;
v5 = 31 - v7;
v6 = v7 <= 15;
}
else
{
v4 = v2 / -32 + 15;
v6 = v7 > 15;
v5 = v2 % 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3) + ((unsigned __int8)(*(_BYTE *)(colorram + v3) & 1) << 8),
0LL,
(unsigned int)flipscreen,
v6,
(unsigned int)(16 * v4),
(unsigned int)(16 * v5),
0LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
v8 = (unsigned __int8)*mystston_scroll;
v20[0] = -v8;
if ( flipscreen )
v20[0] = v8 + 256;
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 1LL, v20, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v9 = 0LL;
do
{
v13 = *(_BYTE *)(spriteram + v9);
if ( (v13 & 1) != 0 )
{
v14 = *(unsigned __int8 *)(spriteram + v9 + 3);
v10 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + v9 + 2));
v11 = v13 & 4;
v12 = v13 & 2;
if ( flipscreen )
{
v10 = (unsigned int)(240 - v10);
v11 = (_DWORD)v11 == 0;
v12 = (_DWORD)v12 == 0;
}
else
{
v14 = (unsigned int)(240 - v14);
}
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
((16 * v13) & 0x100) + (unsigned int)*(unsigned __int8 *)(spriteram + v9 + 1),
((int)v13 >> 3) & 1,
v11,
v12,
v14,
v10,
Machine + 776LL,
2LL,
0LL);
}
v9 += 4LL;
}
while ( spriteram_size > v9 );
}
result = &mystston_videoram2_size;
v16 = mystston_videoram2_size - 1;
if ( mystston_videoram2_size - 1 >= 0 )
{
v17 = v16;
do
{
v19 = v16 % 32;
if ( flipscreen )
{
v18 = v16 / 32;
v19 = 31 - v16 % 32;
}
else
{
v18 = v16 / -32 + 31;
}
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(mystston_videoram2 + v17)
+ ((unsigned __int8)(*(_BYTE *)(mystston_colorram2 + v17) & 7) << 8),
(unsigned int)textcolor,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v18),
(unsigned int)(8 * v19),
Machine + 776LL,
2LL,
0LL);
--v17;
--v16;
}
while ( v16 >= 0 );
}
return result;
}

original_code:
void mystston_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipy;
   dirtybuffer[offs] = 0;
   sx = 15 - offs / 32;
   sy = offs % 32;
   flipy = (sy >= 16) ? 1 : 0;
   if (flipscreen)
   {
    sx = 15 - sx;
    sy = 31 - sy;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + 256 * (colorram[offs] & 0x01),
     0,
     flipscreen,flipy,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrolly;
  scrolly = -*mystston_scroll;
  if (flipscreen) scrolly = 256 - scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   int sx,sy,flipx,flipy;
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = spriteram[offs] & 0x02;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x10) << 4),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = mystston_videoram2_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = 31 - offs / 32;
  sy = offs % 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    mystston_videoram2[offs] + 256 * (mystston_colorram2[offs] & 0x07),
    textcolor,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void mystston_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipy;
   dirtybuffer[offs] = 0;
   sx = 15 - offs / 32;
   sy = offs % 32;
   flipy = (sy >= 16) ? 1 : 0;
   if (flipscreen)
   {
    sx = 15 - sx;
    sy = 31 - sy;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs] + 256 * (colorram[offs] & 0x01),
     0,
     flipscreen,flipy,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrolly;
  scrolly = -*mystston_scroll;
  if (flipscreen) scrolly = 256 - scrolly;
  copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   int sx; int sy; int flipx; int flipy;
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = spriteram[offs] & 0x02;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x10) << 4),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = mystston_videoram2_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = 31 - offs / 32;
  sy = offs % 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    mystston_videoram2[offs] + 256 * (mystston_colorram2[offs] & 0x07),
    textcolor,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipy int

variable_types: scrolly int

variable_types: flipx int

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


decompiled_code:
__int64 mystston_interrupt()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_1 = 0;
return interrupt();
}
if ( coin_1 )
return interrupt();
coin_1 = 1;
return nmi_interrupt();
}

canonical_decompiled_code:
__int64 func6()
{
if ( (readinputport(0LL) & 0xC0) == 192 )
{
coin_1 = 0;
return interrupt();
}
if ( coin_1 )
return interrupt();
coin_1 = 1;
return nmi_interrupt();
}

original_code:
int mystston_interrupt(void)
{
 static int coin;
 if ((readinputport(0) & 0xc0) != 0xc0)
 {
  if (coin == 0)
  {
   coin = 1;
   return nmi_interrupt();
  }
 }
 else coin = 0;
 return interrupt();
}

canonical_original_code:
int mystston_interrupt()
{
 static int coin;
 if ((readinputport(0) & 0xc0) != 0xc0)
 {
  if (coin == 0)
  {
   coin = 1;
   return nmi_interrupt();
  }
 }
 else coin = 0;
 return interrupt();
}

variable_types: coin int


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

if ( (last_0 & 0x20) != 0 && (a2 & 0x20) == 0 )
{
if ( (last_0 & 0x10) != 0 )
AY8910_control_port_0_w(0LL, (unsigned int)psg_latch);
else
AY8910_write_port_0_w(0LL, (unsigned int)psg_latch);
}
result = (unsigned int)last_0;
if ( (last_0 & 0x80u) != 0 && (a2 & 0x80u) == 0 )
{
if ( (last_0 & 0x40) != 0 )
result = AY8910_control_port_1_w(0LL, (unsigned int)psg_latch);
else
result = AY8910_write_port_1_w(0LL, (unsigned int)psg_latch);
}
last_0 = a2;
return result;
}

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

if ( (last_0 & 0x20) != 0 && (a2 & 0x20) == 0 )
{
if ( (last_0 & 0x10) != 0 )
AY8910_control_port_0_w(0LL, (unsigned int)psg_latch);
else
AY8910_write_port_0_w(0LL, (unsigned int)psg_latch);
}
result = (unsigned int)last_0;
if ( (last_0 & 0x80u) != 0 && (a2 & 0x80u) == 0 )
{
if ( (last_0 & 0x40) != 0 )
result = AY8910_control_port_1_w(0LL, (unsigned int)psg_latch);
else
result = AY8910_write_port_1_w(0LL, (unsigned int)psg_latch);
}
last_0 = a2;
return result;
}

original_code:
void mystston_8910_control_w(offs_t offset,data_t data)
{
 static int last;
 if ((last & 0x20) == 0x20 && (data & 0x20) == 0x00)
 {
  if (last & 0x10)
   AY8910_control_port_0_w(0,psg_latch);
  else
   AY8910_write_port_0_w(0,psg_latch);
 }
 if ((last & 0x80) == 0x80 && (data & 0x80) == 0x00)
 {
  if (last & 0x40)
   AY8910_control_port_1_w(0,psg_latch);
  else
   AY8910_write_port_1_w(0,psg_latch);
 }
 last = data;
}

canonical_original_code:
void mystston_8910_control_w(unsigned int offset, unsigned int data)
{
 static int last;
 if ((last & 0x20) == 0x20 && (data & 0x20) == 0x00)
 {
  if (last & 0x10)
   AY8910_control_port_0_w(0,psg_latch);
  else
   AY8910_write_port_0_w(0,psg_latch);
 }
 if ((last & 0x80) == 0x80 && (data & 0x80) == 0x00)
 {
  if (last & 0x40)
   AY8910_control_port_1_w(0,psg_latch);
  else
   AY8910_write_port_1_w(0,psg_latch);
 }
 last = data;
}

variable_types: last int


decompiled_code:
void __fastcall parodius_videobank_w(__int64 a1, int a2)
{
videobank = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
videobank = a2;
}

original_code:
static void parodius_videobank_w(offs_t offset,data_t data)
{
 videobank = data;
}

canonical_original_code:
static void parodius_videobank_w(unsigned int offset, unsigned int data)
{
 videobank = data;
}


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

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053245_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053245_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int parodius_vh_start( void )
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K053245_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int parodius_vh_start()
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K053245_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 parodius_vh_stop()
{
K052109_vh_stop();
return K053245_vh_stop();
}

original_code:
void parodius_vh_stop( void )
{
 K052109_vh_stop();
 K053245_vh_stop();
}

canonical_original_code:
void parodius_vh_stop()
{
 K052109_vh_stop();
 K053245_vh_stop();
}


decompiled_code:
__int64 __fastcall parodius_vh_screenrefresh(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_634 = K053251_get_palette_index(4LL);
dword_638 = K053251_get_palette_index(3LL);
K052109_tilemap_update();
palette_init_used_colors();
K053245_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_61C = K053251_get_priority(4LL);
v4 = 2;
dword_620 = K053251_get_priority(3LL);
sortlayers((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053245_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_634 = K053251_get_palette_index(4LL);
dword_638 = K053251_get_palette_index(3LL);
K052109_tilemap_update();
palette_init_used_colors();
K053245_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_61C = K053251_get_priority(4LL);
v4 = 2;
dword_620 = K053251_get_priority(3LL);
func2((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053245_sprites_draw(a1);
}

original_code:
void parodius_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI4);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI3);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053245_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI4);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI3);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053245_sprites_draw(bitmap);
}

canonical_original_code:
void parodius_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI4);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI3);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053245_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI4);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI3);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053245_sprites_draw(bitmap);
}

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

variable_types:
layer
int [3]


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

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

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

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


decompiled_code:
void *parodius_init_machine()
{
__int64 v0; // rbx
void *result; // rax
unsigned int v2; // eax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = parodius_banking;
paletteram = memory_region(129LL) + 294912;
videobank = 0;
cpu_bankbase[1] = v0 + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v2);
}
return result;
}

canonical_decompiled_code:
void *func8()
{
__int64 v0; // rbx
void *result; // rax
unsigned int v2; // eax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = parodius_banking;
paletteram = memory_region(129LL) + 294912;
videobank = 0;
cpu_bankbase[1] = v0 + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v2);
}
return result;
}

original_code:
static void parodius_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = parodius_banking;
 paletteram = &memory_region(REGION_CPU1)[0x48000];
 videobank = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void parodius_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = parodius_banking;
 paletteram = &memory_region(REGION_CPU1)[0x48000];
 videobank = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *


decompiled_code:
void *__fastcall parodius_banking(char a1)
{
__int64 v1; // rdx
int v2; // eax
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((~a1 & 0xF) + 4) << 14;
if ( v2 > 294911 )
v2 -= 0x40000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(char a1)
{
__int64 v1; // rdx
int v2; // eax
void *result; // rax
unsigned int v4; // eax

v1 = memory_region(129LL);
v2 = ((~a1 & 0xF) + 4) << 14;
if ( v2 > 294911 )
v2 -= 0x40000;
cpu_bankbase[1] = v1 + v2;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
static void parodius_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 offs = 0x10000 + (((lines & 0x0f)^0x0f) * 0x4000);
 if (offs >= 0x48000) offs -= 0x40000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void parodius_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 offs = 0x10000 + (((lines & 0x0f)^0x0f) * 0x4000);
 if (offs >= 0x48000) offs -= 0x40000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int


decompiled_code:
__int64 sound_arm_nmi_w()
{
cpu_set_nmi_line(1LL, 0LL);
return timer_set(53687LL, 0LL, nmi_callback);
}

canonical_decompiled_code:
__int64 func11()
{
cpu_set_nmi_line(1LL, 0LL);
return timer_set(53687LL, 0LL, nmi_callback);
}

original_code:
static void sound_arm_nmi_w(offs_t offset,data_t data)
{
 cpu_set_nmi_line(1,0);
 timer_set(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)),0,nmi_callback);
}

canonical_original_code:
static void sound_arm_nmi_w(unsigned int offset, unsigned int data)
{
 cpu_set_nmi_line(1,0);
 timer_set(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)),0,nmi_callback);
}


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

if ( *(_DWORD *)(Machine + 836LL) )
result = K053260_r((unsigned int)(a1 + 2));
else
result = (unsigned __int8)(a1 == 0) << 7;
return result;
}

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

if ( *(_DWORD *)(Machine + 836LL) )
result = K053260_r((unsigned int)(a1 + 2));
else
result = (unsigned __int8)(a1 == 0) << 7;
return result;
}

original_code:
static data_t parodius_sound_r(offs_t offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else return offset ? 0x00 : 0x80;
}

canonical_original_code:
static unsigned int parodius_sound_r(unsigned int offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else return offset ? 0x00 : 0x80;
}


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int parodius_interrupt(void)
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int parodius_interrupt()
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}


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

if ( (videobank & 2) != 0 )
result = K053245_w();
else
result = K052109_w();
return result;
}

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

if ( (videobank & 2) != 0 )
result = K053245_w();
else
result = K052109_w();
return result;
}

original_code:
static void parodius_052109_053245_w(offs_t offset,data_t data)
{
 if (videobank & 0x02)
  K053245_w(offset,data);
 else
  K052109_w(offset,data);
}

canonical_original_code:
static void parodius_052109_053245_w(unsigned int offset, unsigned int data)
{
 if (videobank & 0x02)
  K053245_w(offset,data);
 else
  K052109_w(offset,data);
}


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

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

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

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


decompiled_code:
__int64 __fastcall parodius_3fc0_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
return K052109_set_RMRD_line((a2 & 8) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
return K052109_set_RMRD_line((a2 & 8) != 0);
}

original_code:
static void parodius_3fc0_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line( ( data & 0x08 ) ? 1 : 0 );
}

canonical_original_code:
static void parodius_3fc0_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line( ( data & 0x08 ) ? 1 : 0 );
}


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

if ( (videobank & 2) != 0 )
result = K053245_r();
else
result = K052109_r();
return result;
}

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

if ( (videobank & 2) != 0 )
result = K053245_r();
else
result = K052109_r();
return result;
}

original_code:
static data_t parodius_052109_053245_r(offs_t offset)
{
 if (videobank & 0x02)
  return K053245_r(offset);
 else
  return K052109_r(offset);
}

canonical_original_code:
static unsigned int parodius_052109_053245_r(unsigned int offset)
{
 if (videobank & 0x02)
  return K053245_r(offset);
 else
  return K052109_r(offset);
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

result = (unsigned int)(sound_volume - 1);
if ( sound_volume - 1 < 0 )
result = 0LL;
sound_volume = result;
return result;
}

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

result = (unsigned int)(sound_volume - 1);
if ( sound_volume - 1 < 0 )
result = 0LL;
sound_volume = result;
return result;
}

original_code:
static void sound_volume_decay(int param)
{
 if( --sound_volume < 0 )
  sound_volume = 0;
}

variable_types: param int


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

result = (unsigned int)(music_volume - 1);
if ( music_volume - 1 < 0 )
result = 0LL;
music_volume = result;
return result;
}

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

result = (unsigned int)(music_volume - 1);
if ( music_volume - 1 < 0 )
result = 0LL;
music_volume = result;
return result;
}

original_code:
static void music_volume_decay(int param)
{
 if( --music_volume < 0 )
        music_volume = 0;
}


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

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

variable_types:
buffer
short *

variable_types: length int

variable_types: vcarry int

variable_types: vcount int

variable_types: mcarry int

variable_types: mcount int


decompiled_code:
__int64 __fastcall warpwarp_vh_screenrefresh(__int64 a1)
{
int v1; // ebp
__int64 v2; // r12
int v3; // esi
int v4; // ecx
__int64 result; // rax
int v6; // ebp
int v7; // esi
unsigned int v8; // er13
int v9; // er14
unsigned int v10; // er12
unsigned int v11; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // ebp
__int64 v2; // r12
int v3; // esi
int v4; // ecx
__int64 result; // rax
int v6; // ebp
int v7; // esi
unsigned int v8; // er13
int v9; // er14
unsigned int v10; // er12
unsigned int v11; // [rsp+8h] [rbp-40h]

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

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

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

variable_types: offs int

variable_types: mx int

variable_types: my int

variable_types: sx int

variable_types: sy int

variable_types: x int

variable_types: y int

variable_types: colour int

variable_types: j int


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


decompiled_code:
__int64 warpwarp_sh_start()
{
_WORD *v0; // rax
_WORD *v1; // rbp
int i; // ebx

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

canonical_decompiled_code:
__int64 func9()
{
_WORD *v0; // rax
_WORD *v1; // rbp
int i; // ebx

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

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

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

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

variable_types: i int


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

variable_types: res int


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

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

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

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

variable_types:
x
unsigned char

variable_types:
y
unsigned char

variable_types: data int

variable_types: pen int


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

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

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

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


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

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

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

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

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

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


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

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

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

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


decompiled_code:
__int64 liberatr_draw_planet()
{
unsigned __int8 *v0; // rdx
int v1; // ebx
unsigned __int8 v2; // al
unsigned __int16 v3; // r12
unsigned __int8 *v4; // r13
int v5; // ebp
int v6; // ebp
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-50h]
_BYTE *v9; // [rsp+10h] [rbp-48h]
unsigned int i; // [rsp+18h] [rbp-40h]
unsigned __int8 v11; // [rsp+1Eh] [rbp-3Ah]
unsigned __int8 v12; // [rsp+1Fh] [rbp-39h]

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

canonical_decompiled_code:
__int64 func4()
{
unsigned __int8 *v0; // rdx
int v1; // ebx
unsigned __int8 v2; // al
unsigned __int16 v3; // r12
unsigned __int8 *v4; // r13
int v5; // ebp
int v6; // ebp
__int64 result; // rax
__int64 v8; // [rsp+8h] [rbp-50h]
_BYTE *v9; // [rsp+10h] [rbp-48h]
unsigned int i; // [rsp+18h] [rbp-40h]
unsigned __int8 v11; // [rsp+1Eh] [rbp-3Ah]
unsigned __int8 v12; // [rsp+1Fh] [rbp-39h]

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

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

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

variable_types:
latitude
unsigned char

variable_types:
buffer
unsigned char *

variable_types:
segment
unsigned char

variable_types:
color
unsigned char

variable_types:
i
unsigned char

variable_types:
pen
unsigned short


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

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

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types:
penmap
unsigned char []


decompiled_code:
void liberatr_vh_stop()
{
int i; // ebx
void *v1; // rdi
int j; // ebx
void *v3; // rdi

if ( liberatr_videoram )
{
free(liberatr_videoram);
liberatr_videoram = 0LL;
}
if ( liberatr_planet_segs )
{
for ( i = 0; i != 256; ++i )
{
v1 = (void *)*((_QWORD *)liberatr_planet_segs + i);
if ( v1 )
free(v1);
}
free(liberatr_planet_segs);
liberatr_planet_segs = 0LL;
}
if ( ptr )
{
for ( j = 0; j != 256; ++j )
{
v3 = (void *)*((_QWORD *)ptr + j);
if ( v3 )
free(v3);
}
free(ptr);
ptr = 0LL;
}
}

canonical_decompiled_code:
void func7()
{
int i; // ebx
void *v1; // rdi
int j; // ebx
void *v3; // rdi

if ( liberatr_videoram )
{
free(liberatr_videoram);
liberatr_videoram = 0LL;
}
if ( liberatr_planet_segs )
{
for ( i = 0; i != 256; ++i )
{
v1 = (void *)*((_QWORD *)liberatr_planet_segs + i);
if ( v1 )
free(v1);
}
free(liberatr_planet_segs);
liberatr_planet_segs = 0LL;
}
if ( ptr )
{
for ( j = 0; j != 256; ++j )
{
v3 = (void *)*((_QWORD *)ptr + j);
if ( v3 )
free(v3);
}
free(ptr);
ptr = 0LL;
}
}

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

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


decompiled_code:
__int64 liberatr_vh_start()
{
void *v0; // rbx
void *v1; // rdx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func8()
{
void *v0; // rbx
void *v1; // rdx
__int64 result; // rax

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

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

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


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

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

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

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

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

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

variable_types: res int

variable_types: xdelta int

variable_types: ydelta int


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

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

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

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


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

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

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

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


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

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

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

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