decompiled_code:
__int64 crimfght_vh_stop()
{
free(paletteram);
K052109_vh_stop();
return K051960_vh_stop();
}

canonical_decompiled_code:
__int64 func2()
{
free(paletteram);
K052109_vh_stop();
return K051960_vh_stop();
}

original_code:
void crimfght_vh_stop( void )
{
 free(paletteram);
 K052109_vh_stop();
 K051960_vh_stop();
}

canonical_original_code:
void crimfght_vh_stop()
{
 free(paletteram);
 K052109_vh_stop();
 K051960_vh_stop();
}


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

paletteram = malloc(0x400uLL);
if ( !paletteram )
return 1LL;
layer_colorbase = 0x400000000LL;
dword_4D8 = 8;
sprite_colorbase = 16;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
{
free(paletteram);
result = 1LL;
}
else
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
free(paletteram);
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

paletteram = malloc(0x400uLL);
if ( !paletteram )
return 1LL;
layer_colorbase = 0x400000000LL;
dword_4D8 = 8;
sprite_colorbase = 16;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
{
free(paletteram);
result = 1LL;
}
else
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
free(paletteram);
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int crimfght_vh_start( void )
{
 paletteram = (unsigned char*)malloc(0x400);
 if (!paletteram) return 1;
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 4;
 layer_colorbase[2] = 8;
 sprite_colorbase = 16;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  free(paletteram);
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  free(paletteram);
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int crimfght_vh_start()
{
 paletteram = (unsigned char *)malloc(0x400);
 if (!paletteram) return 1;
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 4;
 layer_colorbase[2] = 8;
 sprite_colorbase = 16;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  free(paletteram);
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  free(paletteram);
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall crimfght_vh_screenrefresh(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K052109_tilemap_draw(a1, 1LL, 16LL);
K051960_sprites_draw(a1, 2LL, 2LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 0LL, 0LL);
return K051960_sprites_draw(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
K052109_tilemap_draw(a1, 1LL, 16LL);
K051960_sprites_draw(a1, 2LL, 2LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 0LL, 0LL);
return K051960_sprites_draw(a1, 0LL, 0LL);
}

original_code:
void crimfght_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 K052109_tilemap_draw(bitmap,1,0x10);
 K051960_sprites_draw(bitmap,2,2);
 K052109_tilemap_draw(bitmap,2,0);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,0,0);
 K051960_sprites_draw(bitmap,0,0);
}

canonical_original_code:
void crimfght_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 K052109_tilemap_draw(bitmap,1,0x10);
 K051960_sprites_draw(bitmap,2,2);
 K052109_tilemap_draw(bitmap,2,0);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,0,0);
 K051960_sprites_draw(bitmap,0,0);
}

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

return_type: void


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

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

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

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


decompiled_code:
__int64 __fastcall crimfght_snd_bankswitch_w(__int64 a1, int a2)
{
__int64 v2; // rax

v2 = memory_region(146LL);
return K007232_bankswitch(0LL, v2 + ((a2 << 16) & 0x20000), v2 + ((a2 << 17) & 0x20000));
}

original_code:
static void crimfght_snd_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A = 0x20000*((data >> 1) & 0x01);
 int bank_B = 0x20000*((data) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
}

canonical_original_code:
static void crimfght_snd_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_SOUND1);
 int bank_A = 0x20000*((data >> 1) & 0x01);
 int bank_B = 0x20000*((data) & 0x01);
 K007232_bankswitch(0,RAM + bank_A,RAM + bank_B);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types:
RAM
unsigned char *


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

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

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

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

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

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


decompiled_code:
void *__fastcall crimfght_banking(int a1)
{
__int64 v1; // rbp
void *result; // rax
unsigned int v3; // eax

v1 = memory_region(129LL);
if ( (a1 & 0x20) != 0 )
{
cpu_setbankhandler_r(1LL, &paletteram_r);
cpu_setbankhandler_w(1LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
}
else
{
cpu_setbankhandler_r(1LL, -1LL);
cpu_setbankhandler_w(1LL, -1LL);
}
K052109_set_RMRD_line((a1 >> 6) & 1);
cpu_bankbase[2] = v1 + (((a1 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(int a1)
{
__int64 v1; // rbp
void *result; // rax
unsigned int v3; // eax

v1 = memory_region(129LL);
if ( (a1 & 0x20) != 0 )
{
cpu_setbankhandler_r(1LL, &paletteram_r);
cpu_setbankhandler_w(1LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
}
else
{
cpu_setbankhandler_r(1LL, -1LL);
cpu_setbankhandler_w(1LL, -1LL);
}
K052109_set_RMRD_line((a1 >> 6) & 1);
cpu_bankbase[2] = v1 + (((a1 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
static void crimfght_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 if (lines & 0x20){
  cpu_setbankhandler_r (1, paletteram_r);
  cpu_setbankhandler_w (1, paletteram_xBBBBBGGGGGRRRRR_swap_w);
 }
 else{
  cpu_setbankhandler_r (1, ((mem_read_handler)-1));
  cpu_setbankhandler_w (1, ((mem_write_handler)-1));
 }
 K052109_set_RMRD_line((lines & 0x40) ? 1 : 0);
 offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[offs]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void crimfght_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 if (lines & 0x20){
  cpu_setbankhandler_r (1, paletteram_r);
  cpu_setbankhandler_w (1, paletteram_xBBBBBGGGGGRRRRR_swap_w);
 }
 else{
  cpu_setbankhandler_r (1, ((mem_read_handler)-1));
  cpu_setbankhandler_w (1, ((mem_write_handler)-1));
 }
 K052109_set_RMRD_line((lines & 0x40) ? 1 : 0);
 offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[offs]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int

variable_types: offs int


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

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

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

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


decompiled_code:
__int64 __fastcall crimfght_coin_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

original_code:
static void crimfght_coin_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
}

canonical_original_code:
static void crimfght_coin_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
}


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

tile_info[5] = (*a4 >> 5) & 1;
*a3 |= (a2 << 13) | ((unsigned __int16)*a4 << 8) & 0x1F00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

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

tile_info[5] = (*a4 >> 5) & 1;
*a3 |= (a2 << 13) | ((unsigned __int16)*a4 << 8) & 0x1F00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 tile_info.flags = (*color & 0x20) ? 0x01 : 0;
 *code |= ((*color & 0x1f) << 8) | (bank << 13);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 tile_info.flags = (*color & 0x20) ? 0x01 : 0;
 *code |= ((*color & 0x1f) << 8) | (bank << 13);
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


decompiled_code:
__int64 __fastcall volume_callback(int a1)
{
K007232_set_volume(0LL, 0LL, 17 * (a1 & 0xFu), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, (a1 & 0xFFFFFFF0) + (a1 >> 4));
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
K007232_set_volume(0LL, 0LL, 17 * (a1 & 0xFu), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, (a1 & 0xFFFFFFF0) + (a1 >> 4));
}

variable_types: v int


decompiled_code:
__int64 speedup_r()
{
__int64 v0; // rbx
unsigned __int16 v1; // bp

v0 = memory_region(129LL);
v1 = __ROL2__(*(_WORD *)(v0 + 1044), 8);
if ( (int)memory_region_length(129LL) <= v1
|| (*(unsigned __int8 *)(v0 + v1 + 1) | (*(unsigned __int8 *)(v0 + v1) << 8)) != 0xFFFF )
{
return *(unsigned __int8 *)(v0 + 1044);
}
cpu_spinuntil_int();
return *(unsigned __int8 *)(v0 + 1044);
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbx
unsigned __int16 v1; // bp

v0 = memory_region(129LL);
v1 = __ROL2__(*(_WORD *)(v0 + 1044), 8);
if ( (int)memory_region_length(129LL) <= v1
|| (*(unsigned __int8 *)(v0 + v1 + 1) | (*(unsigned __int8 *)(v0 + v1) << 8)) != 0xFFFF )
{
return *(unsigned __int8 *)(v0 + 1044);
}
cpu_spinuntil_int();
return *(unsigned __int8 *)(v0 + 1044);
}

original_code:
static data_t speedup_r(offs_t offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int data = ( RAM[0x0414] << 8 ) | RAM[0x0415];
 if ( data < memory_region_length(REGION_CPU1) )
 {
  data = ( RAM[data] << 8 ) | RAM[data + 1];
  if ( data == 0xffff )
   cpu_spinuntil_int();
 }
 return RAM[0x0414];
}

canonical_original_code:
static unsigned int speedup_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int data = ( RAM[0x0414] << 8 ) | RAM[0x0415];
 if ( data < memory_region_length(REGION_CPU1) )
 {
  data = ( RAM[data] << 8 ) | RAM[data + 1];
  if ( data == 0xffff )
   cpu_spinuntil_int();
 }
 return RAM[0x0414];
}

variable_types: data int

return_type: unsigned int


decompiled_code:
__int64 __fastcall read_vectorram(int a1, int *a2, _DWORD *a3, _DWORD *a4)
{
__int64 v4; // rdi
__int64 v5; // rax
__int16 v6; // cx
__int64 result; // rax

v4 = 2 * a1;
v5 = aztarac_vectorram;
*a4 = *(unsigned __int16 *)(aztarac_vectorram + v4);
v6 = *(_WORD *)(v5 + v4 + 4096);
result = *(_WORD *)(v5 + v4 + 0x2000) & 0x3FF;
*a2 = v6 & 0x3FF;
*a3 = result;
if ( (*a2 & 0x200) != 0 )
{
*a2 |= 0xFFFFFC00;
result = (unsigned int)*a3;
}
if ( (result & 0x200) != 0 )
{
result = (unsigned int)result | 0xFFFFFC00;
*a3 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int *a2, _DWORD *a3, _DWORD *a4)
{
__int64 v4; // rdi
__int64 v5; // rax
__int16 v6; // cx
__int64 result; // rax

v4 = 2 * a1;
v5 = aztarac_vectorram;
*a4 = *(unsigned __int16 *)(aztarac_vectorram + v4);
v6 = *(_WORD *)(v5 + v4 + 4096);
result = *(_WORD *)(v5 + v4 + 0x2000) & 0x3FF;
*a2 = v6 & 0x3FF;
*a3 = result;
if ( (*a2 & 0x200) != 0 )
{
*a2 |= 0xFFFFFC00;
result = (unsigned int)*a3;
}
if ( (result & 0x200) != 0 )
{
result = (unsigned int)result | 0xFFFFFC00;
*a3 = result;
}
return result;
}

original_code:
static inline void read_vectorram (int addr, int *x, int *y, int *c)
{
    addr <<= 1;
    *c = (*(UINT16 *)(&aztarac_vectorram[addr])) & 0xffff;
    *x = (*(UINT16 *)(&aztarac_vectorram[addr + 0x1000])) & 0x03ff;
    *y = (*(UINT16 *)(&aztarac_vectorram[addr + 0x2000])) & 0x03ff;
    if (*x & 0x200) *x |= 0xfffffc00;
    if (*y & 0x200) *y |= 0xfffffc00;
}

canonical_original_code:
static inline void read_vectorram(int addr, int *x, int *y, int *c)
{
    addr <<= 1;
    *c = (*(unsigned short *)(&aztarac_vectorram[addr])) & 0xffff;
    *x = (*(unsigned short *)(&aztarac_vectorram[addr + 0x1000])) & 0x03ff;
    *y = (*(unsigned short *)(&aztarac_vectorram[addr + 0x2000])) & 0x03ff;
    if (*x & 0x200) *x |= 0xfffffc00;
    if (*y & 0x200) *y |= 0xfffffc00;
}

variable_types: addr int

variable_types:
x
int *

variable_types:
y
int *

variable_types:
c
int *


decompiled_code:
__int64 aztarac_vg_interrupt()
{
return 4LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 4LL;
}

original_code:
int aztarac_vg_interrupt(void)
{
    return 4;
}

canonical_original_code:
int aztarac_vg_interrupt()
{
    return 4;
}


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

result = 1LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = sound_status & 1;
return result;
}

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

result = 1LL;
if ( *(_DWORD *)(Machine + 836LL) )
result = sound_status & 1;
return result;
}

original_code:
data_t aztarac_sound_r(offs_t offset)
{
    if (Machine->sample_rate)
        return sound_status & 0x01;
    else
        return 1;
}

canonical_original_code:
unsigned int aztarac_sound_r(unsigned int offset)
{
    if (Machine->sample_rate)
        return sound_status & 0x01;
    else
        return 1;
}


decompiled_code:
__int64 aztarac_snd_command_r()
{
sound_status = sound_status & 0xFFFFFFDF | 1;
return (unsigned int)sound_command;
}

canonical_decompiled_code:
__int64 func3()
{
sound_status = sound_status & 0xFFFFFFDF | 1;
return (unsigned int)sound_command;
}

original_code:
data_t aztarac_snd_command_r(offs_t offset)
{
    sound_status |= 0x01;
    sound_status &= ~0x20;
    return sound_command;
}

canonical_original_code:
unsigned int aztarac_snd_command_r(unsigned int offset)
{
    sound_status |= 0x01;
    sound_status &= ~0x20;
    return sound_command;
}


decompiled_code:
__int64 aztarac_snd_status_r()
{
return sound_status & 0xFFFFFFFE;
}

canonical_decompiled_code:
__int64 func4()
{
return sound_status & 0xFFFFFFFE;
}

original_code:
data_t aztarac_snd_status_r(offs_t offset)
{
    return sound_status & ~0x01;
}

canonical_original_code:
unsigned int aztarac_snd_status_r(unsigned int offset)
{
    return sound_status & ~0x01;
}


decompiled_code:
void aztarac_snd_status_w()
{
sound_status &= 0xFFFFFFEF;
}

canonical_decompiled_code:
void func5()
{
sound_status &= 0xFFFFFFEF;
}

original_code:
void aztarac_snd_status_w(offs_t offset,data_t data)
{
    sound_status &= ~0x10;
}

canonical_original_code:
void aztarac_snd_status_w(unsigned int offset, unsigned int data)
{
    sound_status &= ~0x10;
}


decompiled_code:
__int64 aztarac_snd_timed_irq()
{
sound_status ^= 0x10u;
return (sound_status & 0x10) == 0 ? -1 : 0xFFFFFC18;
}

canonical_decompiled_code:
__int64 func6()
{
sound_status ^= 0x10u;
return (sound_status & 0x10) == 0 ? -1 : 0xFFFFFC18;
}

original_code:
int aztarac_snd_timed_irq (void)
{
    sound_status ^= 0x10;
    if (sound_status & 0x10)
        return -1000;
    else
        return -1;
}

canonical_original_code:
int aztarac_snd_timed_irq()
{
    sound_status ^= 0x10;
    if (sound_status & 0x10)
        return -1000;
    else
        return -1;
}


decompiled_code:
__int64 __fastcall aztarac_vector(int a1, int a2)
{
return vector_add_point((unsigned int)(xcenter + (a1 << 16)), (unsigned int)(ycenter - (a2 << 16)));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return vector_add_point((unsigned int)(xcenter + (a1 << 16)), (unsigned int)(ycenter - (a2 << 16)));
}

original_code:
static inline void aztarac_vector (int x, int y, int color, int intensity)
{
    if (translucency) intensity *= 0.8;
    vector_add_point (xcenter + (x << 16), ycenter - (y << 16), color, intensity);
}

canonical_original_code:
static inline void aztarac_vector(int x, int y, int color, int intensity)
{
    if (translucency) intensity *= 0.8;
    vector_add_point (xcenter + (x << 16), ycenter - (y << 16), color, intensity);
}

variable_types: x int

variable_types: y int

variable_types: color int

variable_types: intensity int


decompiled_code:
void __fastcall aztarac_ubr_w(__int64 a1, char a2)
{
int v2; // ebp
int v3; // edi
int v4; // er14
int v7; // [rsp+20h] [rbp-50h] BYREF
int v8; // [rsp+24h] [rbp-4Ch] BYREF
int v9; // [rsp+28h] [rbp-48h] BYREF
int v10; // [rsp+2Ch] [rbp-44h] BYREF
int v11; // [rsp+30h] [rbp-40h] BYREF
int v12[15]; // [rsp+34h] [rbp-3Ch] BYREF

if ( (a2 & 1) != 0 )
{
v2 = 0;
vector_clear_list();
while ( 1 )
{
v3 = v2++;
read_vectorram(v3, &v10, &v11, &v9);
if ( (v9 & 0x4000) != 0 )
break;
if ( (v9 & 0x2000) == 0 )
{
v4 = (v9 >> 1) & 0x7FF;
aztarac_vector(v10, v11);
read_vectorram(v4, &v7, v12, &v9);
if ( v9 )
{
if ( v12[0] != -1 )
{
do
{
read_vectorram(++v4, &v7, &v8, &v9);
aztarac_vector(v7 + v10, v8 + v11);
}
while ( v12[0]-- );
}
}
else if ( v12[0] != -1 )
{
do
{
read_vectorram(++v4, &v7, &v8, &v9);
aztarac_vector(v7 + v10, v8 + v11);
}
while ( v12[0]-- );
}
}
}
}
}

original_code:
void aztarac_ubr_w(offs_t offset,data_t data)
{
    int x, y, c, intensity, xoffset, yoffset, color;
    int defaddr, objaddr=0, ndefs;
    if (data & 1)
    {
        vector_clear_list();
        while (1)
        {
            read_vectorram (objaddr, &xoffset, &yoffset, &c);
            objaddr++;
            if (c & 0x4000)
                break;
            if ((c & 0x2000) == 0)
            {
                defaddr = (c >> 1) & 0x7ff;
                aztarac_vector (xoffset, yoffset, 0, 0);
                read_vectorram (defaddr, &x, &ndefs, &c);
                ndefs++;
                if (c)
                {
                    intensity = c >> 8;
                    color = c & 0x3f;
                    while (ndefs--)
                    {
                        defaddr++;
                        read_vectorram (defaddr, &x, &y, &c);
                        if ((c & 0xff00) == 0)
                            aztarac_vector (x + xoffset, y + yoffset, 0, 0);
                        else
                            aztarac_vector (x + xoffset, y + yoffset, color, intensity);
                    }
                }
                else
                {
                    while (ndefs--)
                    {
                        defaddr++;
                        read_vectorram (defaddr, &x, &y, &c);
                        aztarac_vector (x + xoffset, y + yoffset, c & 0x3f, c >> 8);
                    }
                }
            }
        }
    }
}

canonical_original_code:
void aztarac_ubr_w(unsigned int offset, unsigned int data)
{
    int x; int y; int c; int intensity; int xoffset; int yoffset; int color;
    int defaddr; int objaddr = 0; int ndefs;
    if (data & 1)
    {
        vector_clear_list();
        while (1)
        {
            read_vectorram (objaddr, &xoffset, &yoffset, &c);
            objaddr++;
            if (c & 0x4000)
                break;
            if ((c & 0x2000) == 0)
            {
                defaddr = (c >> 1) & 0x7ff;
                aztarac_vector (xoffset, yoffset, 0, 0);
                read_vectorram (defaddr, &x, &ndefs, &c);
                ndefs++;
                if (c)
                {
                    intensity = c >> 8;
                    color = c & 0x3f;
                    while (ndefs--)
                    {
                        defaddr++;
                        read_vectorram (defaddr, &x, &y, &c);
                        if ((c & 0xff00) == 0)
                            aztarac_vector (x + xoffset, y + yoffset, 0, 0);
                        else
                            aztarac_vector (x + xoffset, y + yoffset, color, intensity);
                    }
                }
                else
                {
                    while (ndefs--)
                    {
                        defaddr++;
                        read_vectorram (defaddr, &x, &y, &c);
                        aztarac_vector (x + xoffset, y + yoffset, c & 0x3f, c >> 8);
                    }
                }
            }
        }
    }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: c int

variable_types: xoffset int

variable_types: yoffset int

variable_types: defaddr int

variable_types: objaddr int

variable_types: ndefs int


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

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

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

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

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

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

variable_types: xmin int

variable_types: xmax int

variable_types: ymin int

variable_types: ymax int


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

sound_command = a2;
result = sound_status ^ 0x21u;
sound_status = result;
if ( (result & 0x20) != 0 )
result = cpu_cause_interrupt(1LL, 4294966296LL);
return result;
}

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

sound_command = a2;
result = sound_status ^ 0x21u;
sound_status = result;
if ( (result & 0x20) != 0 )
result = cpu_cause_interrupt(1LL, 4294966296LL);
return result;
}

original_code:
void aztarac_sound_w(offs_t offset,data_t data)
{
    sound_command = data;
    sound_status ^= 0x21;
    if (sound_status & 0x20)
        cpu_cause_interrupt( 1, -1000 );
}

canonical_original_code:
void aztarac_sound_w(unsigned int offset, unsigned int data)
{
    sound_command = data;
    sound_status ^= 0x21;
    if (sound_status & 0x20)
        cpu_cause_interrupt( 1, -1000 );
}


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

result = memory_region(129LL);
*(_DWORD *)(result + 112) = 201457664;
return result;
}

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

result = memory_region(129LL);
*(_DWORD *)(result + 112) = 201457664;
return result;
}

original_code:
static void init_aztarac(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 (*(UINT16 *)(&rom[0x70]) = (0));
 (*(UINT16 *)(&rom[0x72]) = (0x0c02));
}

canonical_original_code:
static void init_aztarac()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 (*(unsigned short *)(&rom[0x70]) = (0));
 (*(unsigned short *)(&rom[0x72]) = (0x0c02));
}

variable_types:
rom
unsigned char *


decompiled_code:
__int64 __fastcall aztarac_joystick_r(unsigned int a1)
{
int v1; // ebx

v1 = input_port_0_r();
return (unsigned __int8)(input_port_1_r(a1) - 15) | (unsigned int)((v1 - 15) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
int v1; // ebx

v1 = input_port_0_r();
return (unsigned __int8)(input_port_1_r(a1) - 15) | (unsigned int)((v1 - 15) << 8);
}

original_code:
static data_t aztarac_joystick_r(offs_t offset)
{
    return (((input_port_0_r (offset) - 0xf) << 8) |
            ((input_port_1_r (offset) - 0xf) & 0xff));
}

canonical_original_code:
static unsigned int aztarac_joystick_r(unsigned int offset)
{
    return (((input_port_0_r (offset) - 0xf) << 8) |
            ((input_port_1_r (offset) - 0xf) & 0xff));
}


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

canonical_original_code:
void ambush_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors; i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall ambush_coin_counter_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 1);
return coin_counter_w(1LL, a2 & 2);
}

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

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


decompiled_code:
__int64 __fastcall ppi8255_r(int a1, int a2)
{
char *v2; // rdx
__int64 (*v3)(void); // rax
char *v5; // rdx
__int64 (*v6)(void); // rdx
unsigned int v7; // eax

if ( *(_DWORD *)intf < a1 || a2 > 3 )
return 0LL;
switch ( a2 )
{
case 2:
v6 = *(__int64 (**)(void))(intf + 24);
v7 = 0;
if ( v6 )
v7 = v6();
return chips[9 * a1 + 7] ^ chips[9 * a1 + 4] & (chips[9 * a1 + 7] ^ v7);
case 3:
return 255LL;
case 0:
v5 = (char *)&chips[9 * a1];
if ( !*((_DWORD *)v5 + 2) )
return *((unsigned int *)v5 + 5);
v3 = *(__int64 (**)(void))(intf + 8);
if ( v3 )
return v3();
return 0LL;
}
if ( a2 != 1 )
return 0LL;
v2 = (char *)&chips[9 * a1];
if ( *((_DWORD *)v2 + 3) )
{
v3 = *(__int64 (**)(void))(intf + 16);
if ( v3 )
return v3();
return 0LL;
}
return *((unsigned int *)v2 + 6);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
char *v2; // rdx
__int64 (*v3)(void); // rax
char *v5; // rdx
__int64 (*v6)(void); // rdx
unsigned int v7; // eax

if ( *(_DWORD *)intf < a1 || a2 > 3 )
return 0LL;
switch ( a2 )
{
case 2:
v6 = *(__int64 (**)(void))(intf + 24);
v7 = 0;
if ( v6 )
v7 = v6();
return chips[9 * a1 + 7] ^ chips[9 * a1 + 4] & (chips[9 * a1 + 7] ^ v7);
case 3:
return 255LL;
case 0:
v5 = (char *)&chips[9 * a1];
if ( !*((_DWORD *)v5 + 2) )
return *((unsigned int *)v5 + 5);
v3 = *(__int64 (**)(void))(intf + 8);
if ( v3 )
return v3();
return 0LL;
}
if ( a2 != 1 )
return 0LL;
v2 = (char *)&chips[9 * a1];
if ( *((_DWORD *)v2 + 3) )
{
v3 = *(__int64 (**)(void))(intf + 16);
if ( v3 )
return v3();
return 0LL;
}
return *((unsigned int *)v2 + 6);
}

original_code:
int ppi8255_r( int which, int offset ) {
 ppi8255 *chip;
 if ( which > intf->num ) {
  return 0;
 }
 if ( offset > 3 ) {
  return 0;
 }
 chip = &chips[which];
 switch( offset )
        {
  case 0:
   if ( chip->io[0] == 0 )
                        {
    return chip->latch[0];
                        }
                        else
                        {
    if ( intf->portA_r )
     return (*intf->portA_r)( which );
   }
  break;
                case 1:
   if ( chip->io[1] == 0 )
                        {
    return chip->latch[1];
                        }
                        else
                        {
    if ( intf->portB_r )
     return (*intf->portB_r)( which );
   }
  break;
  case 2:
                {
                        int input = 0;
                        if (intf->portC_r)
                                input = (*intf->portC_r)(which);
                        return ((chip->latch[2] & ~chip->io[2]) | (input & chip->io[2]));
                }
  case 3:
                        return 0x0ff;
  break;
 }
 return 0x00;
}

canonical_original_code:
int ppi8255_r(int which, int offset) {
 struct ppi8255 *chip;
 if ( which > intf->num ) {
  return 0;
 }
 if ( offset > 3 ) {
  return 0;
 }
 chip = &chips[which];
 switch( offset )
        {
  case 0:
   if ( chip->io[0] == 0 )
                        {
    return chip->latch[0];
                        }
                        else
                        {
    if ( intf->portA_r )
     return (*intf->portA_r)( which );
   }
  break;
                case 1:
   if ( chip->io[1] == 0 )
                        {
    return chip->latch[1];
                        }
                        else
                        {
    if ( intf->portB_r )
     return (*intf->portB_r)( which );
   }
  break;
  case 2:
                {
                        int input = 0;
                        if (intf->portC_r)
                                input = (*intf->portC_r)(which);
                        return ((chip->latch[2] & ~chip->io[2]) | (input & chip->io[2]));
                }
  case 3:
                        return 0x0ff;
  break;
 }
 return 0x00;
}

variable_types: which int

variable_types: offset int

variable_types: struct ppi8255 { int groupA_mode; int groupB_mode; int io[3]; int latch[3]; int control; } *

variable_types: input int


decompiled_code:
__int64 __fastcall ppi8255_0_r(int a1)
{
return ppi8255_r(0, a1);
}

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

original_code: data_t ppi8255_0_r(offs_t offset) { return ppi8255_r( 0, offset ); }

canonical_original_code: unsigned int ppi8255_0_r(unsigned int offset) { return ppi8255_r( 0, offset ); }

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall ppi8255_1_r(int a1)
{
return ppi8255_r(1, a1);
}

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

original_code: data_t ppi8255_1_r(offs_t offset) { return ppi8255_r( 1, offset ); }

canonical_original_code: unsigned int ppi8255_1_r(unsigned int offset) { return ppi8255_r( 1, offset ); }


decompiled_code:
__int64 __fastcall ppi8255_2_r(int a1)
{
return ppi8255_r(2, a1);
}

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

original_code: data_t ppi8255_2_r(offs_t offset) { return ppi8255_r( 2, offset ); }

canonical_original_code: unsigned int ppi8255_2_r(unsigned int offset) { return ppi8255_r( 2, offset ); }


decompiled_code:
__int64 __fastcall ppi8255_3_r(int a1)
{
return ppi8255_r(3, a1);
}

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

original_code: data_t ppi8255_3_r(offs_t offset) { return ppi8255_r( 3, offset ); }

canonical_original_code: unsigned int ppi8255_3_r(unsigned int offset) { return ppi8255_r( 3, offset ); }


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

alpha_rcvd = 1;
result = (unsigned int)gamma_data;
gamma_xmtd = 0;
return result;
}

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

alpha_rcvd = 1;
result = (unsigned int)gamma_data;
gamma_xmtd = 0;
return result;
}

original_code:
data_t mhavoc_gamma_r(offs_t offset)
{
 alpha_rcvd=1;
 gamma_xmtd=0;
 return gamma_data;
}

canonical_original_code:
unsigned int mhavoc_gamma_r(unsigned int offset)
{
 alpha_rcvd=1;
 gamma_xmtd=0;
 return gamma_data;
}


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

gamma_rcvd = 1;
result = (unsigned int)alpha_data;
alpha_xmtd = 0;
return result;
}

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

gamma_rcvd = 1;
result = (unsigned int)alpha_data;
alpha_xmtd = 0;
return result;
}

original_code:
data_t mhavoc_alpha_r(offs_t offset)
{
 gamma_rcvd=1;
 alpha_xmtd=0;
 return alpha_data;
}

canonical_original_code:
unsigned int mhavoc_alpha_r(unsigned int offset)
{
 gamma_rcvd=1;
 alpha_xmtd=0;
 return alpha_data;
}


decompiled_code:
void __fastcall mhavoc_alpha_w(__int64 a1, int a2)
{
alpha_rcvd = 0;
gamma_xmtd = 1;
gamma_data = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
alpha_rcvd = 0;
gamma_xmtd = 1;
gamma_data = a2;
}

original_code:
void mhavoc_alpha_w(offs_t offset,data_t data)
{
 alpha_rcvd=0;
 gamma_xmtd=1;
 gamma_data = data;
}

canonical_original_code:
void mhavoc_alpha_w(unsigned int offset, unsigned int data)
{
 alpha_rcvd=0;
 gamma_xmtd=1;
 gamma_data = data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall mhavoc_gammaram_r(__int16 a1)
{
return *(unsigned __int8 *)(gammaram + (a1 & 0x7FF));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
return *(unsigned __int8 *)(gammaram + (a1 & 0x7FF));
}

original_code:
static data_t mhavoc_gammaram_r(offs_t offset)
{
 return gammaram[offset & 0x7ff];
}

canonical_original_code:
static unsigned int mhavoc_gammaram_r(unsigned int offset)
{
 return gammaram[offset & 0x7ff];
}


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

cpu_bankbase[1] = *((int *)&bank_1 + (a2 & 1)) + memory_region(129LL);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[1] = *((int *)&bank_1 + (a2 & 1)) + memory_region(129LL);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void mhavoc_ram_banksel_w(offs_t offset,data_t data)
{
 static int bank[2] = { 0x20200, 0x20800 };
 unsigned char *RAM = memory_region(REGION_CPU1);
 data&=0x01;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bank[data]]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void mhavoc_ram_banksel_w(unsigned int offset, unsigned int data)
{
 static int bank[2] = { 0x20200, 0x20800 };
 unsigned char *RAM = memory_region(REGION_CPU1);
 data&=0x01;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bank[data]]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
bank
int [2]

variable_types:
RAM
unsigned char *


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

cpu_bankbase[2] = bank_0[a2 & 3] + memory_region(129LL);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[2] = bank_0[a2 & 3] + memory_region(129LL);
result = &ophw;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void mhavoc_rom_banksel_w(offs_t offset,data_t data)
{
 static int bank[4] = { 0x10000, 0x12000, 0x14000, 0x16000 };
 unsigned char *RAM = memory_region(REGION_CPU1);
 data &= 0x03;
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[bank[data]]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void mhavoc_rom_banksel_w(unsigned int offset, unsigned int data)
{
 static int bank[4] = { 0x10000, 0x12000, 0x14000, 0x16000 };
 unsigned char *RAM = memory_region(REGION_CPU1);
 data &= 0x03;
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[bank[data]]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
bank
int [4]


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

mhavoc_ram_banksel_w(0LL, 0);
mhavoc_rom_banksel_w(0LL, 0);
alpha_data = 0;
gamma_data = 0;
alpha_rcvd = 0;
alpha_xmtd = 0;
gamma_rcvd = 0;
gamma_xmtd = 0;
player_1 = 0;
if ( gamma_timer )
timer_remove();
result = timer_pulse(1717986LL, 0LL, mhavoc_gamma_irq);
gamma_timer = result;
return result;
}

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

func5(0LL, 0);
func6(0LL, 0);
alpha_data = 0;
gamma_data = 0;
alpha_rcvd = 0;
alpha_xmtd = 0;
gamma_rcvd = 0;
gamma_xmtd = 0;
player_1 = 0;
if ( gamma_timer )
timer_remove();
result = timer_pulse(1717986LL, 0LL, mhavoc_gamma_irq);
gamma_timer = result;
return result;
}

original_code:
void mhavoc_init_machine (void)
{
 mhavoc_ram_banksel_w (0,0);
 mhavoc_rom_banksel_w (0,0);
 bank_select = -1;
 alpha_data=0;
 gamma_data=0;
 alpha_rcvd=0;
 alpha_xmtd=0;
 gamma_rcvd=0;
 gamma_xmtd=0;
 player_1 = 0;
 if (gamma_timer)
   timer_remove(gamma_timer);
 gamma_timer = timer_pulse(((1<<30) / ((timer_tm)(2*5000/16))), 0, mhavoc_gamma_irq);
}

canonical_original_code:
void mhavoc_init_machine()
{
 mhavoc_ram_banksel_w (0,0);
 mhavoc_rom_banksel_w (0,0);
 bank_select = -1;
 alpha_data=0;
 gamma_data=0;
 alpha_rcvd=0;
 alpha_xmtd=0;
 gamma_rcvd=0;
 gamma_xmtd=0;
 player_1 = 0;
 if (gamma_timer)
   timer_remove(gamma_timer);
 gamma_timer = timer_pulse(((1<<30) / ((timer_tm)(2*5000/16))), 0, mhavoc_gamma_irq);
}


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

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

original_code:
static void mhavoc_gamma_irq(int param)
{
 cpu_set_irq_line(1,0,2);
}

variable_types: param int


decompiled_code:
__int64 __fastcall mhavoc_gamma_w(__int64 a1, int a2)
{
alpha_data = a2;
gamma_rcvd = 0;
alpha_xmtd = 1;
cpu_cause_interrupt(1LL, 2LL);
return timer_set(268435LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
alpha_data = a2;
gamma_rcvd = 0;
alpha_xmtd = 1;
cpu_cause_interrupt(1LL, 2LL);
return timer_set(268435LL, 0LL, 0LL);
}

original_code:
void mhavoc_gamma_w(offs_t offset,data_t data)
{
 gamma_rcvd=0;
 alpha_xmtd=1;
 alpha_data = data;
 cpu_cause_interrupt (1, 2);
 timer_set (((timer_tm)(((float)(250)*(float)((1<<30)))/(float)1000000)), 0, 0);
}

canonical_original_code:
void mhavoc_gamma_w(unsigned int offset, unsigned int data)
{
 gamma_rcvd=0;
 alpha_xmtd=1;
 alpha_data = data;
 cpu_cause_interrupt (1, 2);
 timer_set (((timer_tm)(((float)(250)*(float)((1<<30)))/(float)1000000)), 0, 0);
}


decompiled_code:
__int64 mhavoc_port_1_r()
{
char v0; // al
char v1; // dl
__int64 result; // rax

v0 = readinputport(1LL);
v1 = v0 & 0xFD;
if ( alpha_rcvd == 1 )
v1 = v0 | 2;
LOBYTE(result) = v1 & 0xFE;
if ( alpha_xmtd == 1 )
LOBYTE(result) = v1 | 1;
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 func10()
{
char v0; // al
char v1; // dl
__int64 result; // rax

v0 = readinputport(1LL);
v1 = v0 & 0xFD;
if ( alpha_rcvd == 1 )
v1 = v0 | 2;
LOBYTE(result) = v1 & 0xFE;
if ( alpha_xmtd == 1 )
LOBYTE(result) = v1 | 1;
return (unsigned __int8)result;
}

original_code:
data_t mhavoc_port_1_r(offs_t offset)
{
 int res;
 res=readinputport(1);
 if (alpha_rcvd==1)
  res |=0x02;
 else
  res &=~0x02;
 if (alpha_xmtd==1)
  res |=0x01;
 else
  res &=~0x01;
 return (res & 0xff);
}

canonical_original_code:
unsigned int mhavoc_port_1_r(unsigned int offset)
{
 int res;
 res=readinputport(1);
 if (alpha_rcvd==1)
  res |=0x02;
 else
  res &=~0x02;
 if (alpha_xmtd==1)
  res |=0x01;
 else
  res &=~0x01;
 return (res & 0xff);
}

variable_types: res int


decompiled_code:
__int64 mhavoc_port_0_r()
{
char v0; // bl
__int16 v1; // r8
char v2; // al
char v3; // bl
char v4; // al
int v5; // er8
char v6; // al
char v7; // bl
char v8; // al
char v9; // dl
__int64 result; // rax

v0 = readinputport(0LL);
if ( player_1 )
v0 = readinputport(5LL) & 0xC0 | v0 & 0x3F;
v1 = cpu_gettotalcycles();
v2 = v0;
v3 = v0 | 2;
v4 = v2 & 0xFD;
if ( (v1 & 0x400) != 0 )
v3 = v4;
v5 = avgdvg_done();
v6 = v3;
v7 = v3 & 0xFE;
v8 = v6 | 1;
if ( v5 )
v7 = v8;
v9 = v7 & 0xF7;
if ( gamma_rcvd == 1 )
v9 = v7 | 8;
LOBYTE(result) = v9 & 0xFB;
if ( gamma_xmtd == 1 )
LOBYTE(result) = v9 | 4;
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 func11()
{
char v0; // bl
__int16 v1; // r8
char v2; // al
char v3; // bl
char v4; // al
int v5; // er8
char v6; // al
char v7; // bl
char v8; // al
char v9; // dl
__int64 result; // rax

v0 = readinputport(0LL);
if ( player_1 )
v0 = readinputport(5LL) & 0xC0 | v0 & 0x3F;
v1 = cpu_gettotalcycles();
v2 = v0;
v3 = v0 | 2;
v4 = v2 & 0xFD;
if ( (v1 & 0x400) != 0 )
v3 = v4;
v5 = avgdvg_done();
v6 = v3;
v7 = v3 & 0xFE;
v8 = v6 | 1;
if ( v5 )
v7 = v8;
v9 = v7 & 0xF7;
if ( gamma_rcvd == 1 )
v9 = v7 | 8;
LOBYTE(result) = v9 & 0xFB;
if ( gamma_xmtd == 1 )
LOBYTE(result) = v9 | 4;
return (unsigned __int8)result;
}

original_code:
data_t mhavoc_port_0_r(offs_t offset)
{
 int res;
 res = readinputport(0);
 if (player_1)
  res = (res & 0x3f) | (readinputport (5) & 0xc0);
 if (cpu_gettotalcycles() & 0x400)
  res &=~0x02;
 else
  res|=0x02;
 if (avgdvg_done())
  res |=0x01;
 else
  res &=~0x01;
 if (gamma_rcvd==1)
  res |=0x08;
 else
  res &=~0x08;
 if (gamma_xmtd==1)
  res |=0x04;
 else
  res &=~0x04;
 return (res & 0xff);
}

canonical_original_code:
unsigned int mhavoc_port_0_r(unsigned int offset)
{
 int res;
 res = readinputport(0);
 if (player_1)
  res = (res & 0x3f) | (readinputport (5) & 0xc0);
 if (cpu_gettotalcycles() & 0x400)
  res &=~0x02;
 else
  res|=0x02;
 if (avgdvg_done())
  res |=0x01;
 else
  res &=~0x01;
 if (gamma_rcvd==1)
  res |=0x08;
 else
  res &=~0x08;
 if (gamma_xmtd==1)
  res |=0x04;
 else
  res &=~0x04;
 return (res & 0xff);
}


decompiled_code:
__int64 __fastcall mhavoc_out_0_w(__int64 a1, char a2)
{
if ( (a2 & 8) == 0 )
{
cpu_set_reset_line(1LL, 3LL);
alpha_rcvd = 0;
alpha_xmtd = 0;
gamma_rcvd = 0;
gamma_xmtd = 0;
}
player_1 = a2 & 0x20;
return osd_led_w(2LL, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char a2)
{
if ( (a2 & 8) == 0 )
{
cpu_set_reset_line(1LL, 3LL);
alpha_rcvd = 0;
alpha_xmtd = 0;
gamma_rcvd = 0;
gamma_xmtd = 0;
}
player_1 = a2 & 0x20;
return osd_led_w(2LL, a2 & 1);
}

original_code:
void mhavoc_out_0_w(offs_t offset,data_t data)
{
 if (!(data & 0x08))
 {
  cpu_set_reset_line(1,3);
  alpha_rcvd=0;
  alpha_xmtd=0;
  gamma_rcvd=0;
  gamma_xmtd=0;
 }
 player_1 = data & 0x20;
 osd_led_w (2, data & 0x01);
}

canonical_original_code:
void mhavoc_out_0_w(unsigned int offset, unsigned int data)
{
 if (!(data & 0x08))
 {
  cpu_set_reset_line(1,3);
  alpha_rcvd=0;
  alpha_xmtd=0;
  gamma_rcvd=0;
  gamma_xmtd=0;
 }
 player_1 = data & 0x20;
 osd_led_w (2, data & 0x01);
}


decompiled_code:
__int64 __fastcall mhavoc_out_1_w(__int64 a1, char a2)
{
osd_led_w(1LL, a2 & 1);
return osd_led_w(0LL, (a2 & 2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char a2)
{
osd_led_w(1LL, a2 & 1);
return osd_led_w(0LL, (a2 & 2) != 0);
}

original_code:
void mhavoc_out_1_w(offs_t offset,data_t data)
{
 osd_led_w (1, data & 0x01);
 osd_led_w (0, (data & 0x02)>>1);
}

canonical_original_code:
void mhavoc_out_1_w(unsigned int offset, unsigned int data)
{
 osd_led_w (1, data & 0x01);
 osd_led_w (0, (data & 0x02)>>1);
}


decompiled_code:
__int64 mhavoc_irqack_w()
{
timer_reset(gamma_timer, 1717986LL);
return cpu_set_irq_line(1LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func14()
{
timer_reset(gamma_timer, 1717986LL);
return cpu_set_irq_line(1LL, 0LL, 0LL);
}

original_code:
void mhavoc_irqack_w(offs_t offset,data_t data)
{
 timer_reset( gamma_timer, ((1<<30) / ((timer_tm)(2*5000/16))));
 cpu_set_irq_line(1,0,0);
}

canonical_original_code:
void mhavoc_irqack_w(unsigned int offset, unsigned int data)
{
 timer_reset( gamma_timer, ((1<<30) / ((timer_tm)(2*5000/16))));
 cpu_set_irq_line(1,0,0);
}


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

canonical_decompiled_code:
void *__fastcall func15(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, nvram_size);
return memset(nvram, 255, 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,0xff,nvram_size);
 }
}

variable_types:
file
void *


decompiled_code:
void profiler_stop()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void profiler_stop(void) { }

canonical_original_code: void profiler_stop() { }


decompiled_code:
void profiler_mark()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void profiler_mark(int type) { }

canonical_original_code: void profiler_mark(int type) { }

variable_types: type int


decompiled_code:
void profiler_show()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code: void profiler_show(struct osd_bitmap *bitmap) { }

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


decompiled_code:
void __fastcall wacko_mux_select_w(__int64 a1, char a2)
{
wacko_mux_select = a2 & 1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
wacko_mux_select = a2 & 1;
}

original_code:
static void wacko_mux_select_w(offs_t offset,data_t data)
{
 wacko_mux_select = data & 1;
}

canonical_original_code:
static void wacko_mux_select_w(unsigned int offset, unsigned int data)
{
 wacko_mux_select = data & 1;
}


decompiled_code:
void *init_mcr2()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 0LL, 0LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

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

mcr_sound_config = 1;
install_port_write_handler(0LL, 0LL, 0LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_mcr2(void)
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x00, 0x00, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_mcr2()
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x00, 0x00, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


decompiled_code:
void *init_domino()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 1LL, 1LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 1LL, 1LL, &mcr_control_port_w);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_domino(void)
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x01, 0x01, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_domino()
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x01, 0x01, mcr_control_port_w);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 49152, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 49152, 2048LL);
return result;
}

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

result = memory_region(129LL);
if ( a2 )
return osd_fwrite(a1, result + 49152, 2048LL);
if ( a1 )
result = osd_fread(a1, result + 49152, 2048LL);
return result;
}

original_code:
static void mcr2_nvram_handler(void *file, int read_or_write)
{
 unsigned char *ram = memory_region(REGION_CPU1);
 if (read_or_write)
  osd_fwrite(file, &ram[0xc000], 0x800);
 else if (file)
  osd_fread(file, &ram[0xc000], 0x800);
}

variable_types:
ram
unsigned char *


decompiled_code:
void *init_kroozr()
{
void *result; // rax

mcr_sound_config = 1;
install_port_read_handler(0LL, 1LL, 1LL, kroozr_dial_r);
install_port_read_handler(0LL, 2LL, 2LL, kroozr_trakball_x_r);
install_port_read_handler(0LL, 4LL, 4LL, kroozr_trakball_y_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

canonical_decompiled_code:
void *func4()
{
void *result; // rax

mcr_sound_config = 1;
install_port_read_handler(0LL, 1LL, 1LL, kroozr_dial_r);
install_port_read_handler(0LL, 2LL, 2LL, kroozr_trakball_x_r);
install_port_read_handler(0LL, 4LL, 4LL, kroozr_trakball_y_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_kroozr(void)
{
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x01, 0x01, kroozr_dial_r);
 install_port_read_handler(0, 0x02, 0x02, kroozr_trakball_x_r);
 install_port_read_handler(0, 0x04, 0x04, kroozr_trakball_y_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_kroozr()
{
 mcr_sound_config = 0x01;
 install_port_read_handler(0, 0x01, 0x01, kroozr_dial_r);
 install_port_read_handler(0, 0x02, 0x02, kroozr_trakball_x_r);
 install_port_read_handler(0, 0x04, 0x04, kroozr_trakball_y_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


decompiled_code:
void *init_wacko()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 4LL, 4LL, wacko_mux_select_w);
install_port_read_handler(0LL, 1LL, 2LL, wacko_trackball_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

canonical_decompiled_code:
void *func5()
{
void *result; // rax

mcr_sound_config = 1;
install_port_write_handler(0LL, 4LL, 4LL, wacko_mux_select_w);
install_port_read_handler(0LL, 1LL, 2LL, wacko_trackball_r);
mcr12_sprite_xoffs = 0;
result = &mcr12_sprite_xoffs_flip;
mcr12_sprite_xoffs_flip = 0;
return result;
}

original_code:
static void init_wacko(void)
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x04, 0x04, wacko_mux_select_w);
 install_port_read_handler(0, 0x01, 0x02, wacko_trackball_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}

canonical_original_code:
static void init_wacko()
{
 mcr_sound_config = 0x01;
 install_port_write_handler(0, 0x04, 0x04, wacko_mux_select_w);
 install_port_read_handler(0, 0x01, 0x02, wacko_trackball_r);
 mcr12_sprite_xoffs = 0;
 mcr12_sprite_xoffs_flip = 0;
}


decompiled_code:
__int64 kroozr_trakball_y_r()
{
char v0; // al
unsigned int v1; // er8

v0 = readinputport(6LL);
v1 = 48;
if ( (v0 & 8) == 0 )
v1 = (v0 & 4) == 0 ? 100 : 152;
return v1;
}

original_code:
static data_t kroozr_trakball_y_r(offs_t offset)
{
 int val = readinputport(6);
 if (val & 0x08)
  return 0x64 - 0x34;
 if (val & 0x04)
  return 0x64 + 0x34;
 return 0x64;
}

canonical_original_code:
static unsigned int kroozr_trakball_y_r(unsigned int offset)
{
 int val = readinputport(6);
 if (val & 0x08)
  return 0x64 - 0x34;
 if (val & 0x04)
  return 0x64 + 0x34;
 return 0x64;
}

variable_types: val int


decompiled_code:
__int64 kroozr_trakball_x_r()
{
char v0; // al
unsigned int v1; // er8

v0 = readinputport(6LL);
v1 = 48;
if ( (v0 & 2) == 0 )
v1 = (v0 & 1) == 0 ? 100 : 152;
return v1;
}

original_code:
static data_t kroozr_trakball_x_r(offs_t offset)
{
 int val = readinputport(6);
 if (val & 0x02)
  return 0x64 - 0x34;
 if (val & 0x01)
  return 0x64 + 0x34;
 return 0x64;
}

canonical_original_code:
static unsigned int kroozr_trakball_x_r(unsigned int offset)
{
 int val = readinputport(6);
 if (val & 0x02)
  return 0x64 - 0x34;
 if (val & 0x01)
  return 0x64 + 0x34;
 return 0x64;
}


decompiled_code:
__int64 kroozr_dial_r()
{
int v0; // ebx

v0 = readinputport(7LL);
return (unsigned int)readinputport(1LL) | (v0 >> 1) & 0x40 | (v0 >> 4) & 7;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx

v0 = readinputport(7LL);
return (unsigned int)readinputport(1LL) | (v0 >> 1) & 0x40 | (v0 >> 4) & 7;
}

original_code:
static data_t kroozr_dial_r(offs_t offset)
{
 int dial = readinputport(7);
 int val = readinputport(1);
 val |= (dial & 0x80) >> 1;
 val |= (dial & 0x70) >> 4;
 return val;
}

canonical_original_code:
static unsigned int kroozr_dial_r(unsigned int offset)
{
 int dial = readinputport(7);
 int val = readinputport(1);
 val |= (dial & 0x80) >> 1;
 val |= (dial & 0x70) >> 4;
 return val;
}

variable_types: dial int


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

if ( wacko_mux_select )
result = readinputport((unsigned int)(a1 + 6));
else
result = readinputport((unsigned int)(a1 + 1));
return result;
}

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

if ( wacko_mux_select )
result = readinputport((unsigned int)(a1 + 6));
else
result = readinputport((unsigned int)(a1 + 1));
return result;
}

original_code:
static data_t wacko_trackball_r(offs_t offset)
{
 if (!wacko_mux_select)
  return readinputport(1 + offset);
 else
  return readinputport(6 + offset);
}

canonical_original_code:
static unsigned int wacko_trackball_r(unsigned int offset)
{
 if (!wacko_mux_select)
  return readinputport(1 + offset);
 else
  return readinputport(6 + offset);
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void *__fastcall sonson_vh_screenrefresh(__int64 a1)
{
int v1; // er13
__int64 v2; // r14
int v3; // edx
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rdx
unsigned __int8 *v7; // rsi
char *v8; // rax
void *result; // rax
int v10; // er12
__int64 v11; // r14
__int16 v12; // dx
char v13; // cl
char v14; // r8
unsigned __int8 v15; // r9
__int64 v16; // rdx
__int64 v17; // rax
__int64 v18; // [rsp-28h] [rbp-E0h]
__int64 v19; // [rsp-28h] [rbp-E0h]
__int64 v20[2]; // [rsp+0h] [rbp-B8h] BYREF
int v21; // [rsp+10h] [rbp-A8h]
char v22; // [rsp+14h] [rbp-A4h] BYREF
char v23; // [rsp+80h] [rbp-38h] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = (*(_BYTE *)(colorram + v2) & 3) << 8;
v4 = *(unsigned __int8 *)(videoram + v2);
v5 = *(_BYTE *)(colorram + v2--) >> 2;
v6 = (unsigned int)(v4 + v3);
v18 = (unsigned int)(8 * (v1 >> 5));
LOBYTE(v4) = v1--;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 512LL), v6, v5, 0LL, 0LL, 8 * (v4 & 0x1Fu), v18, 0LL, 0LL, 0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v20[0] = 0LL;
v20[1] = 0LL;
v21 = 0;
v7 = (unsigned __int8 *)sonson_scrollx;
v8 = &v22;
do
{
v8 += 4;
*((_DWORD *)v8 - 1) = -*v7;
}
while ( &v23 != v8 );
copyscrollbitmap(a1, tmpbitmap, 32LL, v20, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v10 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v10;
do
{
v12 = *(unsigned __int8 *)(spriteram + v11 + 1);
v13 = v12;
v14 = ~(_BYTE)v12;
v15 = ~(_BYTE)v12;
v16 = *(unsigned __int8 *)(spriteram + v11 + 2) + ((8 * v12) & 0x100u);
v19 = *(unsigned __int8 *)(spriteram + v11);
v17 = *(unsigned __int8 *)(spriteram + v11 + 3);
v11 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v16,
v13 & 0x1F,
v14 & 0x40,
v15 & 0x80,
v17,
v19,
Machine + 776LL,
2LL,
0LL);
v10 -= 4;
}
while ( v10 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // er13
__int64 v2; // r14
int v3; // edx
int v4; // eax
__int64 v5; // rcx
__int64 v6; // rdx
unsigned __int8 *v7; // rsi
char *v8; // rax
void *result; // rax
int v10; // er12
__int64 v11; // r14
__int16 v12; // dx
char v13; // cl
char v14; // r8
unsigned __int8 v15; // r9
__int64 v16; // rdx
__int64 v17; // rax
__int64 v18; // [rsp-28h] [rbp-E0h]
__int64 v19; // [rsp-28h] [rbp-E0h]
__int64 v20[2]; // [rsp+0h] [rbp-B8h] BYREF
int v21; // [rsp+10h] [rbp-A8h]
char v22; // [rsp+14h] [rbp-A4h] BYREF
char v23; // [rsp+80h] [rbp-38h] BYREF

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = (*(_BYTE *)(colorram + v2) & 3) << 8;
v4 = *(unsigned __int8 *)(videoram + v2);
v5 = *(_BYTE *)(colorram + v2--) >> 2;
v6 = (unsigned int)(v4 + v3);
v18 = (unsigned int)(8 * (v1 >> 5));
LOBYTE(v4) = v1--;
drawgfx(tmpbitmap, *(_QWORD *)(Machine + 512LL), v6, v5, 0LL, 0LL, 8 * (v4 & 0x1Fu), v18, 0LL, 0LL, 0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v20[0] = 0LL;
v20[1] = 0LL;
v21 = 0;
v7 = (unsigned __int8 *)sonson_scrollx;
v8 = &v22;
do
{
v8 += 4;
*((_DWORD *)v8 - 1) = -*v7;
}
while ( &v23 != v8 );
copyscrollbitmap(a1, tmpbitmap, 32LL, v20, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v10 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v10;
do
{
v12 = *(unsigned __int8 *)(spriteram + v11 + 1);
v13 = v12;
v14 = ~(_BYTE)v12;
v15 = ~(_BYTE)v12;
v16 = *(unsigned __int8 *)(spriteram + v11 + 2) + ((8 * v12) & 0x100u);
v19 = *(unsigned __int8 *)(spriteram + v11);
v17 = *(unsigned __int8 *)(spriteram + v11 + 3);
v11 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v16,
v13 & 0x1F,
v14 & 0x40,
v15 & 0x80,
v17,
v19,
Machine + 776LL,
2LL,
0LL);
v10 -= 4;
}
while ( v10 >= 0 );
}
return result;
}

original_code:
void sonson_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * (colorram[offs] & 3),
     colorram[offs] >> 2,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i,scroll[32];
  for (i = 0;i < 5;i++)
   scroll[i] = 0;
  for (i = 5;i < 32;i++)
   scroll[i] = -(*sonson_scrollx);
  copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2] + ((spriteram[offs + 1] & 0x20) << 3),
    spriteram[offs + 1] & 0x1f,
    ~spriteram[offs + 1] & 0x40,~spriteram[offs + 1] & 0x80,
    spriteram[offs + 3],spriteram[offs + 0],
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void sonson_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * (colorram[offs] & 3),
     colorram[offs] >> 2,
     0,0,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int i; int scroll[32];
  for (i = 0;i < 5;i++)
   scroll[i] = 0;
  for (i = 5;i < 32;i++)
   scroll[i] = -(*sonson_scrollx);
  copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 2] + ((spriteram[offs + 1] & 0x20) << 3),
    spriteram[offs + 1] & 0x1f,
    ~spriteram[offs + 1] & 0x40,~spriteram[offs + 1] & 0x80,
    spriteram[offs + 3],spriteram[offs + 0],
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types:
scroll
int [32]

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


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

result = (unsigned int)last_0;
if ( !last_0 && a2 == 1 )
{
result = cpu_cause_interrupt(1LL, 2LL);
last_0 = 1;
}
else
{
last_0 = a2;
}
return result;
}

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

result = (unsigned int)last_0;
if ( !last_0 && a2 == 1 )
{
result = cpu_cause_interrupt(1LL, 2LL);
last_0 = 1;
}
else
{
last_0 = a2;
}
return result;
}

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: last int


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

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

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

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

original_code:
void minivadr_init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette, minivadr_palette, sizeof(minivadr_palette));
}

canonical_original_code:
void minivadr_init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette, minivadr_palette, sizeof(minivadr_palette));
}


decompiled_code:
__int64 __fastcall minivadr_videoram_w(unsigned int a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 result; // rax
unsigned int v4; // ebx
int v6; // er15
int v7; // er14
unsigned int v8; // eax
__int64 v9; // rsi

*(_BYTE *)(videoram + a1) = a2;
v2 = Machine;
result = 8 * (a1 & 0x1F);
if ( *(_DWORD *)(Machine + 776LL) <= (int)result && *(_DWORD *)(Machine + 780LL) >= (int)result )
{
v4 = a1 >> 5;
if ( *(_DWORD *)(Machine + 784LL) <= (signed int)(a1 >> 5) && *(_DWORD *)(Machine + 788LL) >= (signed int)v4 )
{
v6 = 0;
v7 = result + 7;
while ( 1 )
{
v8 = a2 >> v6;
v9 = (unsigned int)(v7 - v6++);
result = plot_pixel(
*(_QWORD *)(v2 + 768),
v9,
v4,
*(unsigned __int16 *)(*(_QWORD *)(v2 + 792) + 2LL * (v8 & 1)));
if ( v6 == 8 )
break;
v2 = Machine;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 v2; // rdx
__int64 result; // rax
unsigned int v4; // ebx
int v6; // er15
int v7; // er14
unsigned int v8; // eax
__int64 v9; // rsi

*(_BYTE *)(videoram + a1) = a2;
v2 = Machine;
result = 8 * (a1 & 0x1F);
if ( *(_DWORD *)(Machine + 776LL) <= (int)result && *(_DWORD *)(Machine + 780LL) >= (int)result )
{
v4 = a1 >> 5;
if ( *(_DWORD *)(Machine + 784LL) <= (signed int)(a1 >> 5) && *(_DWORD *)(Machine + 788LL) >= (signed int)v4 )
{
v6 = 0;
v7 = result + 7;
while ( 1 )
{
v8 = a2 >> v6;
v9 = (unsigned int)(v7 - v6++);
result = plot_pixel(
*(_QWORD *)(v2 + 768),
v9,
v4,
*(unsigned __int16 *)(*(_QWORD *)(v2 + 792) + 2LL * (v8 & 1)));
if ( v6 == 8 )
break;
v2 = Machine;
}
}
}
return result;
}

original_code:
void minivadr_videoram_w(offs_t offset,data_t data)
{
 int i;
 int x, y;
 int color;
 videoram[offset] = data;
 x = (offset % 32) * 8;
 y = (offset / 32);
 if (x >= Machine->visible_area.min_x &&
   x <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y &&
   y <= Machine->visible_area.max_y)
 {
  for (i = 0; i < 8; i++)
  {
   color = Machine->pens[((data >> i) & 0x01)];
   plot_pixel(Machine->scrbitmap, x + (7 - i), y, color);
  }
 }
}

canonical_original_code:
void minivadr_videoram_w(unsigned int offset, unsigned int data)
{
 int i;
 int x; int y;
 int color;
 videoram[offset] = data;
 x = (offset % 32) * 8;
 y = (offset / 32);
 if (x >= Machine->visible_area.min_x &&
   x <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y &&
   y <= Machine->visible_area.max_y)
 {
  for (i = 0; i < 8; i++)
  {
   color = Machine->pens[((data >> i) & 0x01)];
   plot_pixel(Machine->scrbitmap, x + (7 - i), y, color);
  }
 }
}

variable_types: x int

variable_types: y int

variable_types: color int


original_code:
void YM_DELTAT_ADPCM_Write(YM_DELTAT *DELTAT,int r,int v)
{
 if(r>=0x10) return;
 DELTAT->reg[r] = v;
 switch( r ){
 case 0x00:
  if( v&0x80 ){
   DELTAT->portstate = v&0x90;
   DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
   DELTAT->now_addr = (DELTAT->start)<<1;
   DELTAT->now_step = (1<<(16))-DELTAT->step;
   DELTAT->adpcmx = 0;
   DELTAT->adpcml = 0;
   DELTAT->adpcmd = (127);
   DELTAT->next_leveling=0;
   DELTAT->flag = 1;
   if( !DELTAT->step )
   {
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }
   if(DELTAT->memory == 0){
    if( (3)>=1 ) logerror ("YM Delta-T ADPCM rom not mapped\n");
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }else{
    if( DELTAT->end >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM end out of range: $%08x\n",DELTAT->end);
     DELTAT->end = DELTAT->memory_size - 1;
    }
    if( DELTAT->start >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM start out of range: $%08x\n",DELTAT->start);
     DELTAT->flag = 0;
     DELTAT->portstate = 0x00;
    }
   }
  } else if( v&0x01 ){
   DELTAT->flag = 0;
   DELTAT->portstate = 0x00;
  }
  break;
 case 0x01:
  DELTAT->portcontrol = v&0xff;
  DELTAT->pan = &DELTAT->output_pointer[(v>>6)&0x03];
  break;
 case 0x02:
 case 0x03:
  DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << DELTAT->portshift;
  break;
 case 0x04:
 case 0x05:
  DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << DELTAT->portshift;
  DELTAT->end += (1<<DELTAT->portshift) - 1;
  break;
 case 0x06:
 case 0x07:
 case 0x08:
   break;
 case 0x09:
 case 0x0a:
  DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]);
  DELTAT->step = (UINT32)((float)(DELTAT->delta*(1<<((16)-16)))*(DELTAT->freqbase));
  DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
  break;
 case 0x0b:
  {
   INT32 oldvol = DELTAT->volume;
   DELTAT->volume = (v&0xff)*(DELTAT->output_range/256) / 32768;
   if( oldvol != 0 )
   {
    DELTAT->adpcml = (int)((float)DELTAT->adpcml / (float)oldvol * (float)DELTAT->volume);
    DELTAT->sample_step = (int)((float)DELTAT->sample_step / (float)oldvol * (float)DELTAT->volume);
   }
   DELTAT->volume_w_step = (int)((float)DELTAT->volume * (float)DELTAT->step / (float)(1<<(16)));
  }
  break;
 }
}

canonical_original_code:
void YM_DELTAT_ADPCM_Write(struct deltat_adpcm_state *DELTAT, int r, int v)
{
 if(r>=0x10) return;
 DELTAT->reg[r] = v;
 switch( r ){
 case 0x00:
  if( v&0x80 ){
   DELTAT->portstate = v&0x90;
   DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
   DELTAT->now_addr = (DELTAT->start)<<1;
   DELTAT->now_step = (1<<(16))-DELTAT->step;
   DELTAT->adpcmx = 0;
   DELTAT->adpcml = 0;
   DELTAT->adpcmd = (127);
   DELTAT->next_leveling=0;
   DELTAT->flag = 1;
   if( !DELTAT->step )
   {
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }
   if(DELTAT->memory == 0){
    if( (3)>=1 ) logerror ("YM Delta-T ADPCM rom not mapped\n");
    DELTAT->flag = 0;
    DELTAT->portstate = 0x00;
   }else{
    if( DELTAT->end >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM end out of range: $%08x\n",DELTAT->end);
     DELTAT->end = DELTAT->memory_size - 1;
    }
    if( DELTAT->start >= DELTAT->memory_size )
    {
     if( (3)>=1 ) logerror ("YM Delta-T ADPCM start out of range: $%08x\n",DELTAT->start);
     DELTAT->flag = 0;
     DELTAT->portstate = 0x00;
    }
   }
  } else if( v&0x01 ){
   DELTAT->flag = 0;
   DELTAT->portstate = 0x00;
  }
  break;
 case 0x01:
  DELTAT->portcontrol = v&0xff;
  DELTAT->pan = &DELTAT->output_pointer[(v>>6)&0x03];
  break;
 case 0x02:
 case 0x03:
  DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << DELTAT->portshift;
  break;
 case 0x04:
 case 0x05:
  DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << DELTAT->portshift;
  DELTAT->end += (1<<DELTAT->portshift) - 1;
  break;
 case 0x06:
 case 0x07:
 case 0x08:
   break;
 case 0x09:
 case 0x0a:
  DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]);
  DELTAT->step = (UINT32)((float)(DELTAT->delta*(1<<((16)-16)))*(DELTAT->freqbase));
  DELTAT->volume_w_step = (float)DELTAT->volume * DELTAT->step / (1<<(16));
  break;
 case 0x0b:
  {
   int oldvol = DELTAT->volume;
   DELTAT->volume = (v&0xff)*(DELTAT->output_range/256) / 32768;
   if( oldvol != 0 )
   {
    DELTAT->adpcml = (int)((float)DELTAT->adpcml / (float)oldvol * (float)DELTAT->volume);
    DELTAT->sample_step = (int)((float)DELTAT->sample_step / (float)oldvol * (float)DELTAT->volume);
   }
   DELTAT->volume_w_step = (int)((float)DELTAT->volume * (float)DELTAT->step / (float)(1<<(16)));
  }
  break;
 }
}

variable_types: struct deltat_adpcm_state { unsigned char *memory; int memory_size; float freqbase; int *output_pointer; int output_range; unsigned char reg[16]; unsigned char portstate; int portshift; unsigned char flag; unsigned char flagMask; unsigned char now_data; unsigned int now_addr; unsigned int now_step; unsigned int step; unsigned int start; unsigned int end; unsigned int delta; int volume; int *pan; int adpcmx; int adpcml; int volume_w_step; int next_leveling; int sample_step; unsigned char arrivedFlag; } *

variable_types: r int

variable_types: v int

variable_types: oldvol int


original_code:
void YM_DELTAT_ADPCM_Reset(YM_DELTAT *DELTAT,int pan)
{
 DELTAT->now_addr = 0;
 DELTAT->now_step = 0;
 DELTAT->step = 0;
 DELTAT->start = 0;
 DELTAT->end = 0;
 DELTAT->volume = 0;
 DELTAT->pan = &DELTAT->output_pointer[pan];
 DELTAT->arrivedFlag = 0;
 DELTAT->flag = 0;
 DELTAT->adpcmx = 0;
 DELTAT->adpcmd = 127;
 DELTAT->adpcml = 0;
 DELTAT->volume_w_step = 0;
    DELTAT->next_leveling = 0;
 DELTAT->portstate = 0;
}

canonical_original_code:
void YM_DELTAT_ADPCM_Reset(struct deltat_adpcm_state *DELTAT, int pan)
{
 DELTAT->now_addr = 0;
 DELTAT->now_step = 0;
 DELTAT->step = 0;
 DELTAT->start = 0;
 DELTAT->end = 0;
 DELTAT->volume = 0;
 DELTAT->pan = &DELTAT->output_pointer[pan];
 DELTAT->arrivedFlag = 0;
 DELTAT->flag = 0;
 DELTAT->adpcmx = 0;
 DELTAT->adpcmd = 127;
 DELTAT->adpcml = 0;
 DELTAT->volume_w_step = 0;
    DELTAT->next_leveling = 0;
 DELTAT->portstate = 0;
}

variable_types: pan int

user_defined_types: struct deltat_adpcm_state { unsigned char *memory; int memory_size; float freqbase; int *output_pointer; int output_range; unsigned char reg[16]; unsigned char portstate; int portshift; unsigned char flag; unsigned char flagMask; unsigned char now_data; unsigned int now_addr; unsigned int now_step; unsigned int step; unsigned int start; unsigned int end; unsigned int delta; int volume; int *pan; int adpcmx; int adpcml; int volume_w_step; int next_leveling; int sample_step; unsigned char arrivedFlag; }


original_code:
static void K051649_update(int ch, INT16 *buffer, int length)
{
 k051649_sound_channel *voice=channel_list;
 short *mix;
 int i,v,f,j,k;
 memset(mixer_buffer, 0, length * sizeof(short));
 for (j=0; j<5; j++) {
  v=voice[j].volume;
  f=voice[j].frequency;
  k=voice[j].key;
  if (v && f && k)
  {
   const signed char *w = voice[j].waveform;
   int c=voice[j].counter;
   mix = mixer_buffer;
   for (i = 0; i < length; i++)
   {
    int offs;
    c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
    offs = (c >> 16) & 0x1f;
    *mix++ += (w[offs] * v)>>3;
   }
   voice[j].counter = c;
  }
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

canonical_original_code:
static void K051649_update(int ch, short *buffer, int length)
{
 struct k051649_sound_channel *voice = channel_list;
 short *mix;
 int i; int v; int f; int j; int k;
 memset(mixer_buffer, 0, length * sizeof(short));
 for (j=0; j<5; j++) {
  v=voice[j].volume;
  f=voice[j].frequency;
  k=voice[j].key;
  if (v && f && k)
  {
   char *w = voice[j].waveform;
   int c = voice[j].counter;
   mix = mixer_buffer;
   for (i = 0; i < length; i++)
   {
    int offs;
    c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
    offs = (c >> 16) & 0x1f;
    *mix++ += (w[offs] * v)>>3;
   }
   voice[j].counter = c;
  }
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

variable_types: ch int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct k051649_sound_channel { unsigned long counter; int frequency; int volume; int key; char waveform[32]; } *

variable_types:
mix
short *

variable_types: f int

variable_types: j int

variable_types: k int

variable_types:
w
char *

variable_types: c int


decompiled_code:
__int64 __fastcall K051649_sh_start(__int64 a1)
{
__int64 v1; // rbx
void *v2; // rax
void *v3; // rbp
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K051649", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K051649_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1LL;
v3 = v2;
result = make_mixer_table_constprop_0();
if ( (_DWORD)result )
{
free(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
void *v2; // rax
void *v3; // rbp
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K051649", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K051649_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1LL;
v3 = v2;
result = func1();
if ( (_DWORD)result )
{
free(v3);
result = 1LL;
}
return result;
}

original_code:
int K051649_sh_start(const struct MachineSound *msound)
{
 const char *snd_name = "K051649";
 k051649_sound_channel *voice=channel_list;
 const struct k051649_interface *intf = (const struct k051649_interface *)msound->sound_interface;
 int i;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K051649_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short int*)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(5))
 {
  free(mixer_buffer);
  return 1;
 }
 for (i=0; i>5; i++) {
  voice[i].frequency = 0;
  voice[i].volume = 0;
  voice[i].counter = 0;
 }
 return 0;
}

canonical_original_code:
int K051649_sh_start(struct MachineSound *msound)
{
 char *snd_name = "K051649";
 struct k051649_sound_channel *voice = channel_list;
 struct k051649_interface *intf = (const struct k051649_interface *)msound->sound_interface;
 int i;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K051649_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short *)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(5))
 {
  free(mixer_buffer);
  return 1;
 }
 for (i=0; i>5; i++) {
  voice[i].frequency = 0;
  voice[i].volume = 0;
  voice[i].counter = 0;
 }
 return 0;
}

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

variable_types: struct k051649_interface { int master_clock; int volume; } *

variable_types: i int

user_defined_types: struct k051649_sound_channel { unsigned long counter; int frequency; int volume; int key; char waveform[32]; }


decompiled_code:
void K051649_sh_stop()
{
free(mixer_table);
free(mixer_buffer);
}

canonical_decompiled_code:
void func3()
{
free(mixer_table);
free(mixer_buffer);
}

original_code:
void K051649_sh_stop(void)
{
 free(mixer_table);
 free(mixer_buffer);
}


decompiled_code:
__int64 __fastcall K051649_volume_w(char a1, char a2)
{
__int64 v2; // rdi
__int64 result; // rax

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
v2 = a1 & 7;
result = 7 * v2;
*((_DWORD *)&channel_list + 14 * v2 + 3) = a2 & 0xF;
return result;
}

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

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
v2 = a1 & 7;
result = 7 * v2;
*((_DWORD *)&channel_list + 14 * v2 + 3) = a2 & 0xF;
return result;
}

original_code:
void K051649_volume_w(offs_t offset,data_t data)
{
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset&0x7].volume=data&0xf;
}

canonical_original_code:
void K051649_volume_w(unsigned int offset, unsigned int data)
{
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset&0x7].volume=data&0xf;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

f_0[a1] = a2;
if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
result = (f_0[a1 & 0xE] + (f_0[a1 | 1] << 8)) & 0x3FF;
*((_DWORD *)&channel_list + 14 * (a1 >> 1) + 2) = result;
if ( a1 >> 1 == 3 )
{
result = ((_WORD)dword_438 + ((_WORD)dword_43C << 8)) & 0x3FF;
dword_568 = ((_WORD)dword_438 + ((_WORD)dword_43C << 8)) & 0x3FF;
}
return result;
}

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

f_0[a1] = a2;
if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
result = (f_0[a1 & 0xE] + (f_0[a1 | 1] << 8)) & 0x3FF;
*((_DWORD *)&channel_list + 14 * (a1 >> 1) + 2) = result;
if ( a1 >> 1 == 3 )
{
result = ((_WORD)dword_438 + ((_WORD)dword_43C << 8)) & 0x3FF;
dword_568 = ((_WORD)dword_438 + ((_WORD)dword_43C << 8)) & 0x3FF;
}
return result;
}

original_code:
void K051649_frequency_w(offs_t offset,data_t data)
{
 static int f[10];
 f[offset]=data;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset>>1].frequency=(f[offset&0xe] + (f[offset|1]<<8))&0x3ff;
 if ((offset>>1)==3)
  channel_list[4].frequency=(f[6] + (f[7]<<8))&0x3ff;
}

canonical_original_code:
void K051649_frequency_w(unsigned int offset, unsigned int data)
{
 static int f[10];
 f[offset]=data;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 channel_list[offset>>1].frequency=(f[offset&0xe] + (f[offset|1]<<8))&0x3ff;
 if ((offset>>1)==3)
  channel_list[4].frequency=(f[6] + (f[7]<<8))&0x3ff;
}

variable_types:
f
int [10]


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

dword_490 = a2 & 1;
dword_4C8 = a2 & 2;
dword_500 = a2 & 4;
result = a2 & 8;
dword_570 = a2 & 0x10;
dword_538 = a2 & 8;
return result;
}

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

dword_490 = a2 & 1;
dword_4C8 = a2 & 2;
dword_500 = a2 & 4;
result = a2 & 8;
dword_570 = a2 & 0x10;
dword_538 = a2 & 8;
return result;
}

original_code:
void K051649_keyonoff_w(offs_t offset,data_t data)
{
 channel_list[0].key=data&1;
 channel_list[1].key=data&2;
 channel_list[2].key=data&4;
 channel_list[3].key=data&8;
 channel_list[4].key=data&16;
}

canonical_original_code:
void K051649_keyonoff_w(unsigned int offset, unsigned int data)
{
 channel_list[0].key=data&1;
 channel_list[1].key=data&2;
 channel_list[2].key=data&4;
 channel_list[3].key=data&8;
 channel_list[4].key=data&16;
}


decompiled_code:
__int64 __fastcall galpanic_bgvideoram_r(unsigned int a1)
{
return *(unsigned __int16 *)(galpanic_bgvideoram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return *(unsigned __int16 *)(galpanic_bgvideoram + a1);
}

original_code:
data_t galpanic_bgvideoram_r(offs_t offset)
{
 return (*(UINT16 *)(&galpanic_bgvideoram[offset]));
}

canonical_original_code:
unsigned int galpanic_bgvideoram_r(unsigned int offset)
{
 return (*(unsigned short *)(&galpanic_bgvideoram[offset]));
}


decompiled_code:
__int64 __fastcall galpanic_bgvideoram_w(unsigned int a1, int a2)
{
unsigned __int16 *v2; // rax
unsigned __int16 v3; // si

v2 = (unsigned __int16 *)(galpanic_bgvideoram + a1);
v3 = a2 | *v2 & HIWORD(a2);
*v2 = v3;
return plot_pixel(
tmpbitmap,
(unsigned __int8)(a1 >> 1),
a1 >> 9,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (((int)v3 >> 1) + 1024)));
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
unsigned __int16 *v2; // rax
unsigned __int16 v3; // si

v2 = (unsigned __int16 *)(galpanic_bgvideoram + a1);
v3 = a2 | *v2 & HIWORD(a2);
*v2 = v3;
return plot_pixel(
tmpbitmap,
(unsigned __int8)(a1 >> 1),
a1 >> 9,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (((int)v3 >> 1) + 1024)));
}

original_code:
void galpanic_bgvideoram_w(offs_t offset,data_t data)
{
 int sx,sy,color;
 ((*(UINT16 *)((&galpanic_bgvideoram[offset])) = (((*(UINT16 *)(&galpanic_bgvideoram[offset])) & ((data) >> 16)) | (data))));
 sy = (offset/2) / 256;
 sx = (offset/2) % 256;
 color = (*(UINT16 *)(&galpanic_bgvideoram[offset]));
 plot_pixel(tmpbitmap, sx, sy, Machine->pens[1024 + (color >> 1)]);
}

canonical_original_code:
void galpanic_bgvideoram_w(unsigned int offset, unsigned int data)
{
 int sx; int sy; int color;
 ((*(unsigned short *)((&galpanic_bgvideoram[offset])) = (((*(unsigned short *)(&galpanic_bgvideoram[offset])) & ((data) >> 16)) | (data))));
 sy = (offset/2) / 256;
 sx = (offset/2) % 256;
 color = (*(unsigned short *)(&galpanic_bgvideoram[offset]));
 plot_pixel(tmpbitmap, sx, sy, Machine->pens[1024 + (color >> 1)]);
}

variable_types: sx int

variable_types: sy int

variable_types: color int


decompiled_code:
__int64 __fastcall galpanic_fgvideoram_r(unsigned int a1)
{
return *(unsigned __int16 *)(galpanic_fgvideoram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return *(unsigned __int16 *)(galpanic_fgvideoram + a1);
}

original_code:
data_t galpanic_fgvideoram_r(offs_t offset)
{
 return (*(UINT16 *)(&galpanic_fgvideoram[offset]));
}

canonical_original_code:
unsigned int galpanic_fgvideoram_r(unsigned int offset)
{
 return (*(unsigned short *)(&galpanic_fgvideoram[offset]));
}


decompiled_code:
__int64 __fastcall galpanic_paletteram_r(unsigned int a1)
{
return *(unsigned __int16 *)(paletteram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return *(unsigned __int16 *)(paletteram + a1);
}

original_code:
data_t galpanic_paletteram_r(offs_t offset)
{
 return (*(UINT16 *)(&paletteram[offset]));
}

canonical_original_code:
unsigned int galpanic_paletteram_r(unsigned int offset)
{
 return (*(unsigned short *)(&paletteram[offset]));
}


decompiled_code:
__int64 __fastcall galpanic_spriteram_r(unsigned int a1)
{
return *(unsigned __int16 *)(spriteram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return *(unsigned __int16 *)(spriteram + a1);
}

original_code:
data_t galpanic_spriteram_r(offs_t offset)
{
 return (*(UINT16 *)(&spriteram[offset]));
}

canonical_original_code:
unsigned int galpanic_spriteram_r(unsigned int offset)
{
 return (*(unsigned short *)(&spriteram[offset]));
}


decompiled_code:
__int64 __fastcall galpanic_paletteram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rax
int v3; // edx

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return palette_change_color(
a1 >> 1,
(8 * ((v3 >> 6) & 0x1F)) | (unsigned int)(((v3 >> 6) & 0x1F) >> 2),
(8 * (v3 >> 11)) | (unsigned int)(v3 >> 13),
(8 * ((v3 >> 1) & 0x1F)) | (unsigned int)(((v3 >> 1) & 0x1F) >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rax
int v3; // edx

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return palette_change_color(
a1 >> 1,
(8 * ((v3 >> 6) & 0x1F)) | (unsigned int)(((v3 >> 6) & 0x1F) >> 2),
(8 * (v3 >> 11)) | (unsigned int)(v3 >> 13),
(8 * ((v3 >> 1) & 0x1F)) | (unsigned int)(((v3 >> 1) & 0x1F) >> 2));
}

original_code:
void galpanic_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = (newword >> 6) & 0x1f;
 g = (newword >> 11) & 0x1f;
 b = (newword >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void galpanic_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = (newword >> 6) & 0x1f;
 g = (newword >> 11) & 0x1f;
 b = (newword >> 1) & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 galpanic_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 3 : 5;
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)cpu_getiloops() == 0 ? 3 : 5;
}

original_code:
int galpanic_interrupt(void)
{
 if (cpu_getiloops() != 0) return 5;
 else return 3;
}

canonical_original_code:
int galpanic_interrupt()
{
 if (cpu_getiloops() != 0) return 5;
 else return 3;
}


decompiled_code:
void *__fastcall galpanic_6295_bankswitch_w(__int64 a1, int a2)
{
__int64 v2; // rax

v2 = memory_region(146LL);
bank_0 = a2 | bank_0 & HIWORD(a2);
return memcpy((void *)(v2 + 196608), (const void *)(v2 + (((BYTE1(a2) & 0xFu) + 4) << 16)), 0x10000uLL);
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1, int a2)
{
__int64 v2; // rax

v2 = memory_region(146LL);
bank_0 = a2 | bank_0 & HIWORD(a2);
return memcpy((void *)(v2 + 196608), (const void *)(v2 + (((BYTE1(a2) & 0xFu) + 4) << 16)), 0x10000uLL);
}

original_code:
void galpanic_6295_bankswitch_w(offs_t offset,data_t data)
{
 static unsigned char bank[2];
 unsigned char *RAM = memory_region(REGION_SOUND1);
 ((*(UINT16 *)((bank)) = (((*(UINT16 *)(bank)) & ((data) >> 16)) | (data))));
 memcpy(&RAM[0x30000],&RAM[0x40000 + ((data >> 8) & 0x0f) * 0x10000],0x10000);
}

canonical_original_code:
void galpanic_6295_bankswitch_w(unsigned int offset, unsigned int data)
{
 static unsigned char bank[2];
 unsigned char *RAM = memory_region(REGION_SOUND1);
 ((*(unsigned short *)((bank)) = (((*(unsigned short *)(bank)) & ((data) >> 16)) | (data))));
 memcpy(&RAM[0x30000],&RAM[0x40000 + ((data >> 8) & 0x0f) * 0x10000],0x10000);
}

variable_types:
bank
unsigned char [2]

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 mexico86_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 mexico86_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

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


decompiled_code:
void __fastcall mexico86_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 mexico86_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 mexico86_m68705_interrupt()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(2LL, 0LL, 0LL);
else
cpu_set_irq_line(2LL, 0LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(2LL, 0LL, 0LL);
else
cpu_set_irq_line(2LL, 0LL, 1LL);
return 0LL;
}

original_code:
int mexico86_m68705_interrupt(void)
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(2,0,0);
 else
  cpu_set_irq_line(2,0,1);
    return 0;
}

canonical_original_code:
int mexico86_m68705_interrupt()
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(2,0,0);
 else
  cpu_set_irq_line(2,0,1);
    return 0;
}