original_code:
void init_comotion(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 for(i = 0;i < 0x0400;i++)
 {
  rom[0x0000+i] = (rom[0x1000+i]<<4)+rom[0x1400+i];
  rom[0x0400+i] = (rom[0x1800+i]<<4)+rom[0x1c00+i];
 }
 for(i = 0;i < 2048;i++)
 {
  rom[0x4000+i] = rom[0x0000+i];
 }
 coin_latch = 1;
 just_been_reset = 0;
}


decompiled_code:
__int64 blockade_input_port_0_r()
{
return input_port_0_r(0LL) & 0x7F | (unsigned int)(coin_latch << 7);
}

canonical_decompiled_code:
__int64 func7()
{
return input_port_0_r(0LL) & 0x7F | (unsigned int)(coin_latch << 7);
}

original_code:
data_t blockade_input_port_0_r(offs_t offset)
{
    int temp = (input_port_0_r(0)&0x7f);
    return (coin_latch<<7) | (temp);
}

canonical_original_code:
unsigned int blockade_input_port_0_r(unsigned int offset)
{
    int temp = (input_port_0_r(0)&0x7f);
    return (coin_latch<<7) | (temp);
}

variable_types:
offset
unsigned int

variable_types: temp int

return_type: unsigned int


decompiled_code:
__int64 blockade_interrupt()
{
timer_suspendcpu(0LL, 0LL, 0xFFFFFFFFLL);
if ( (input_port_0_r(0LL) & 0x80u) == 0LL )
{
just_been_reset = 1;
cpu_set_reset_line(0LL, 3LL);
}
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func8()
{
timer_suspendcpu(0LL, 0LL, 0xFFFFFFFFLL);
if ( (input_port_0_r(0LL) & 0x80u) == 0LL )
{
just_been_reset = 1;
cpu_set_reset_line(0LL, 3LL);
}
return ignore_interrupt();
}

original_code:
int blockade_interrupt(void)
{
 timer_suspendcpu(0, 0, ((UINT32)-1));
 if ((input_port_0_r(0) & 0x80) == 0)
 {
  just_been_reset = 1;
  cpu_set_reset_line(0,3);
 }
 return ignore_interrupt();
}

canonical_original_code:
int blockade_interrupt()
{
 timer_suspendcpu(0, 0, ((UINT32)-1));
 if ((input_port_0_r(0) & 0x80) == 0)
 {
  just_been_reset = 1;
  cpu_set_reset_line(0,3);
 }
 return ignore_interrupt();
}

return_type: int


decompiled_code:
__int64 blockade_env_on_w()
{
return sample_start(0LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func9()
{
return sample_start(0LL, 0LL, 0LL);
}

original_code:
void blockade_env_on_w(offs_t offset,data_t data)
{
    sample_start(0,0,0);
    return;
}

canonical_original_code:
void blockade_env_on_w(unsigned int offset, unsigned int data)
{
    sample_start(0,0,0);
    return;
}

variable_types:
data
unsigned int

return_type: void


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

videoram_w();
result = input_port_3_r(0LL);
if ( (result & 0x80u) != 0LL )
result = cpu_spinuntil_int();
return result;
}

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

videoram_w();
result = input_port_3_r(0LL);
if ( (result & 0x80u) != 0LL )
result = cpu_spinuntil_int();
return result;
}

original_code:
static void blockade_videoram_w(offs_t offset,data_t data)
{
 videoram_w(offset, data);
 if (input_port_3_r(0) & 0x80)
 {
  cpu_spinuntil_int();
 }
}

canonical_original_code:
static void blockade_videoram_w(unsigned int offset, unsigned int data)
{
 videoram_w(offset, data);
 if (input_port_3_r(0) & 0x80)
 {
  cpu_spinuntil_int();
 }
}


decompiled_code:
void blockade_env_off_w()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void blockade_env_off_w(offs_t offset,data_t data)
{
    return;
}

canonical_original_code:
void blockade_env_off_w(unsigned int offset, unsigned int data)
{
    return;
}


original_code:
void ironhors_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++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}

canonical_original_code:
void ironhors_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++;
 }
 color_prom += 2*Machine->drv->total_colors;
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i + j * (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j + 16;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8;i++)
 {
  int j;
  for (j = 0;j < 8;j++)
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i + j * (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity)/8]) = (*color_prom & 0x0f) + 32 * j;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: j int


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

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

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

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

original_code:
void ironhors_charbank_w(offs_t offset,data_t data)
{
 if (charbank != (data & 1))
 {
  charbank = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 spriterambank = data & 8;
}

canonical_original_code:
void ironhors_charbank_w(unsigned int offset, unsigned int data)
{
 if (charbank != (data & 1))
 {
  charbank = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 spriterambank = data & 8;
}


decompiled_code:
void *__fastcall ironhors_palettebank_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 7;
if ( v2 != palettebank )
{
palettebank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 7;
if ( v2 != palettebank )
{
palettebank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

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


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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (*(_BYTE *)ironhors_interrupt_enable & 1) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (*(_BYTE *)ironhors_interrupt_enable & 4) == 0 )
return ignore_interrupt();
result = 2LL;
}
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (*(_BYTE *)ironhors_interrupt_enable & 1) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (*(_BYTE *)ironhors_interrupt_enable & 4) == 0 )
return ignore_interrupt();
result = 2LL;
}
return result;
}

original_code:
static int ironhors_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (*ironhors_interrupt_enable & 4) return 2;
 }
 else if (cpu_getiloops() % 2)
 {
  if (*ironhors_interrupt_enable & 1) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int ironhors_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (*ironhors_interrupt_enable & 4) return 2;
 }
 else if (cpu_getiloops() % 2)
 {
  if (*ironhors_interrupt_enable & 1) return nmi_interrupt();
 }
 return ignore_interrupt();
}


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

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

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

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


decompiled_code:
__int64 blockhl_vh_start()
{
int v0; // er8
__int64 result; // rax

dword_3A8 = 32;
layer_colorbase = 0x1000000000LL;
sprite_colorbase = 48;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er8
__int64 result; // rax

dword_3A8 = 32;
layer_colorbase = 0x1000000000LL;
sprite_colorbase = 48;
v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int blockhl_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 16;
 layer_colorbase[2] = 32;
 sprite_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int blockhl_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 16;
 layer_colorbase[2] = 32;
 sprite_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 blockhl_vh_stop()
{
K052109_vh_stop();
return K051960_vh_stop();
}

original_code:
void blockhl_vh_stop(void)
{
 K052109_vh_stop();
 K051960_vh_stop();
}

canonical_original_code:
void blockhl_vh_stop()
{
 K052109_vh_stop();
 K051960_vh_stop();
}


decompiled_code:
__int64 __fastcall blockhl_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, 2LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_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, 2LL, 16LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K052109_tilemap_draw(a1, 1LL, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
return K052109_tilemap_draw(a1, 0LL, 0LL);
}

original_code:
void blockhl_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,2,0x10);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,1,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,0,0);
}

canonical_original_code:
void blockhl_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,2,0x10);
 K051960_sprites_draw(bitmap,1,1);
 K052109_tilemap_draw(bitmap,1,0);
 K051960_sprites_draw(bitmap,0,0);
 K052109_tilemap_draw(bitmap,0,0);
}

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


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

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

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

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


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

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

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

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


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

result = memory_region(129LL) + 98304;
konami_cpu_setlines_callback = blockhl_banking;
paletteram = result;
return result;
}

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

result = memory_region(129LL) + 98304;
konami_cpu_setlines_callback = blockhl_banking;
paletteram = result;
return result;
}

original_code:
static void blockhl_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = blockhl_banking;
 paletteram = &RAM[0x18000];
}

canonical_original_code:
static void blockhl_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = blockhl_banking;
 paletteram = &RAM[0x18000];
}

variable_types:
RAM
unsigned char *


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

v1 = memory_region(129LL);
rombank = a1 & 3;
cpu_bankbase[1] = v1 + ((rombank + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a1 & 8);
coin_counter_w(1LL, a1 & 0x10);
palette_selected = ~(_BYTE)a1 & 0x20;
return K052109_set_RMRD_line((a1 >> 6) & 1);
}

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

v1 = memory_region(129LL);
rombank = a1 & 3;
cpu_bankbase[1] = v1 + ((rombank + 8) << 13);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
coin_counter_w(0LL, a1 & 8);
coin_counter_w(1LL, a1 & 0x10);
palette_selected = ~(_BYTE)a1 & 0x20;
return K052109_set_RMRD_line((a1 >> 6) & 1);
}

original_code:
static void blockhl_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs;
 rombank = lines & 0x03;
 offs = 0x10000 + (lines & 0x03) * 0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 coin_counter_w(0,lines & 0x08);
 coin_counter_w(1,lines & 0x10);
 palette_selected = ~lines & 0x20;
 K052109_set_RMRD_line( ( lines & 0x40 ) ? 1 : 0 );
}

canonical_original_code:
static void blockhl_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs;
 rombank = lines & 0x03;
 offs = 0x10000 + (lines & 0x03) * 0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 coin_counter_w(0,lines & 0x08);
 coin_counter_w(1,lines & 0x10);
 palette_selected = ~lines & 0x20;
 K052109_set_RMRD_line( ( lines & 0x40 ) ? 1 : 0 );
}

variable_types: lines int

variable_types: offs int


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

if ( !(unsigned int)K052109_is_IRQ_enabled() || rombank )
result = ignore_interrupt();
else
result = 1LL;
return result;
}

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

if ( !(unsigned int)K052109_is_IRQ_enabled() || rombank )
result = ignore_interrupt();
else
result = 1LL;
return result;
}

original_code:
static int blockhl_interrupt( void )
{
 if (K052109_is_IRQ_enabled() && rombank == 0)
  return 1;
 else
  return ignore_interrupt();
}

canonical_original_code:
static int blockhl_interrupt()
{
 if (K052109_is_IRQ_enabled() && rombank == 0)
  return 1;
 else
  return ignore_interrupt();
}


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

*a3 |= ((unsigned __int16)*a4 << 8) & 0xF00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0xF00;
result = *((_DWORD *)&layer_colorbase + a1) + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

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

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

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

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

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

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

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

variable_types:
priority
int *

variable_types:
shadow
int *


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

if ( palette_selected )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

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

if ( palette_selected )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

original_code:
static data_t bankedram_r(offs_t offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}

canonical_original_code:
static unsigned int bankedram_r(unsigned int offset)
{
 if (palette_selected)
  return paletteram_r(offset);
 else
  return ram[offset];
}

variable_types:
offset
unsigned int


decompiled_code:
unsigned int *__fastcall sample_start(int a1, __int64 a2, unsigned int a3)
{
unsigned int *result; // rax
unsigned int *v4; // rcx
unsigned int *v5; // rsi
__int64 v6; // r8
__int64 v7; // rdi
bool v8; // zf
__int64 v9; // rdx
__int64 v10; // rcx

result = (unsigned int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = *(unsigned int **)(Machine + 848LL);
if ( result )
{
v4 = *(unsigned int **)&result[2 * (int)a2 + 2];
if ( v4 )
{
if ( numchannels <= a1 )
{
result = (unsigned int *)logerror(
"error: sample_start() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
}
else if ( (int)*result <= (int)a2 )
{
result = (unsigned int *)logerror(
"error: sample_start() called with samplenum = %d, but only %d samples available\n",
a2,
*result);
}
else
{
v5 = v4 + 3;
v6 = a3;
v7 = (unsigned int)(firstchannel + a1);
v8 = v4[2] == 8;
v9 = *v4;
v10 = v4[1];
if ( v8 )
result = (unsigned int *)mixer_play_sample(v7, v5, v9, v10, v6);
else
result = (unsigned int *)mixer_play_sample_16(v7, v5, v9, v10, v6);
}
}
}
}
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(int a1, __int64 a2, unsigned int a3)
{
unsigned int *result; // rax
unsigned int *v4; // rcx
unsigned int *v5; // rsi
__int64 v6; // r8
__int64 v7; // rdi
bool v8; // zf
__int64 v9; // rdx
__int64 v10; // rcx

result = (unsigned int *)Machine;
if ( *(_DWORD *)(Machine + 836LL) )
{
result = *(unsigned int **)(Machine + 848LL);
if ( result )
{
v4 = *(unsigned int **)&result[2 * (int)a2 + 2];
if ( v4 )
{
if ( numchannels <= a1 )
{
result = (unsigned int *)logerror(
"error: sample_start() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
}
else if ( (int)*result <= (int)a2 )
{
result = (unsigned int *)logerror(
"error: sample_start() called with samplenum = %d, but only %d samples available\n",
a2,
*result);
}
else
{
v5 = v4 + 3;
v6 = a3;
v7 = (unsigned int)(firstchannel + a1);
v8 = v4[2] == 8;
v9 = *v4;
v10 = v4[1];
if ( v8 )
result = (unsigned int *)mixer_play_sample(v7, v5, v9, v10, v6);
else
result = (unsigned int *)mixer_play_sample_16(v7, v5, v9, v10, v6);
}
}
}
}
return result;
}

original_code:
void sample_start(int channel,int samplenum,int loop)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (Machine->samples->sample[samplenum] == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_start() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 if (samplenum >= Machine->samples->total)
 {
  logerror("error: sample_start() called with samplenum = %d, but only %d samples available\n",samplenum,Machine->samples->total);
  return;
 }
 if ( Machine->samples->sample[samplenum]->resolution == 8 )
 {
  mixer_play_sample(firstchannel + channel,
    Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
 else
 {
  mixer_play_sample_16(firstchannel + channel,
    (short *) Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
}

canonical_original_code:
void sample_start(int channel, int samplenum, int loop)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (Machine->samples->sample[samplenum] == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_start() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 if (samplenum >= Machine->samples->total)
 {
  logerror("error: sample_start() called with samplenum = %d, but only %d samples available\n",samplenum,Machine->samples->total);
  return;
 }
 if ( Machine->samples->sample[samplenum]->resolution == 8 )
 {
  mixer_play_sample(firstchannel + channel,
    Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
 else
 {
  mixer_play_sample_16(firstchannel + channel,
    (short *) Machine->samples->sample[samplenum]->data,
    Machine->samples->sample[samplenum]->length,
    Machine->samples->sample[samplenum]->smpfreq,
    loop);
 }
}

variable_types: channel int

variable_types: samplenum int

variable_types: loop int


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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_sample_frequency((unsigned int)(firstchannel + a1));
}
return result;
}

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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_sample_frequency((unsigned int)(firstchannel + a1));
}
return result;
}

original_code:
void sample_set_freq(int channel,int freq)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_sample_frequency(channel + firstchannel,freq);
}

canonical_original_code:
void sample_set_freq(int channel, int freq)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_sample_frequency(channel + firstchannel,freq);
}

variable_types: freq int


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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_volume((unsigned int)(firstchannel + a1), (unsigned int)(100 * a2 / 255));
}
return result;
}

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

result = Machine;
if ( *(_DWORD *)(Machine + 836LL) && *(_QWORD *)(Machine + 848LL) )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_adjust() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_set_volume((unsigned int)(firstchannel + a1), (unsigned int)(100 * a2 / 255));
}
return result;
}

original_code:
void sample_set_volume(int channel,int volume)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_volume(channel + firstchannel,volume * 100 / 255);
}

canonical_original_code:
void sample_set_volume(int channel, int volume)
{
 if (Machine->sample_rate == 0) return;
 if (Machine->samples == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_adjust() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_set_volume(channel + firstchannel,volume * 100 / 255);
}

variable_types: volume int


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

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_stop() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_stop_sample((unsigned int)(firstchannel + a1));
}
return result;
}

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

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
if ( numchannels <= a1 )
result = logerror(
"error: sample_stop() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
else
result = mixer_stop_sample((unsigned int)(firstchannel + a1));
}
return result;
}

original_code:
void sample_stop(int channel)
{
 if (Machine->sample_rate == 0) return;
 if (channel >= numchannels)
 {
  logerror("error: sample_stop() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return;
 }
 mixer_stop_sample(channel + firstchannel);
}


decompiled_code:
__int64 __fastcall sample_playing(int a1)
{
if ( !*(_DWORD *)(Machine + 836LL) )
return 0LL;
if ( numchannels > a1 )
return mixer_is_sample_playing((unsigned int)(firstchannel + a1));
logerror(
"error: sample_playing() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
if ( !*(_DWORD *)(Machine + 836LL) )
return 0LL;
if ( numchannels > a1 )
return mixer_is_sample_playing((unsigned int)(firstchannel + a1));
logerror(
"error: sample_playing() called with channel = %d, but only %d channels allocated\n",
(unsigned int)a1,
(unsigned int)numchannels);
return 0LL;
}

original_code:
int sample_playing(int channel)
{
 if (Machine->sample_rate == 0) return 0;
 if (channel >= numchannels)
 {
  logerror("error: sample_playing() called with channel = %d, but only %d channels allocated\n",channel,numchannels);
  return 0;
 }
 return mixer_is_sample_playing(channel + firstchannel);
}


decompiled_code:
__int64 __fastcall samples_sh_start(__int64 a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rdi
char *v5; // rax
int v6; // ebx
__int64 v7; // rdi
char v9[48]; // [rsp+0h] [rbp-88h] BYREF
char v10[88]; // [rsp+30h] [rbp-58h] BYREF

v1 = *(unsigned int **)(a1 + 8);
v2 = Machine;
v3 = readsamples(*((_QWORD *)v1 + 1), *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
v4 = *v1;
*(_QWORD *)(v2 + 848) = v3;
numchannels = v4;
if ( (int)v4 > 0 )
{
v5 = v10;
do
{
v5 += 4;
*((_DWORD *)v5 - 1) = v1[1];
}
while ( v5 != &v10[4 * (unsigned int)(v4 - 1) + 4] );
}
firstchannel = mixer_allocate_channels(v4, v10);
if ( numchannels > 0 )
{
v6 = 0;
do
{
sprintf(v9, "Sample #%d", (unsigned int)v6);
v7 = (unsigned int)(v6 + firstchannel);
++v6;
mixer_set_name(v7, v9);
}
while ( numchannels > v6 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rdi
char *v5; // rax
int v6; // ebx
__int64 v7; // rdi
char v9[48]; // [rsp+0h] [rbp-88h] BYREF
char v10[88]; // [rsp+30h] [rbp-58h] BYREF

v1 = *(unsigned int **)(a1 + 8);
v2 = Machine;
v3 = readsamples(*((_QWORD *)v1 + 1), *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
v4 = *v1;
*(_QWORD *)(v2 + 848) = v3;
numchannels = v4;
if ( (int)v4 > 0 )
{
v5 = v10;
do
{
v5 += 4;
*((_DWORD *)v5 - 1) = v1[1];
}
while ( v5 != &v10[4 * (unsigned int)(v4 - 1) + 4] );
}
firstchannel = mixer_allocate_channels(v4, v10);
if ( numchannels > 0 )
{
v6 = 0;
do
{
sprintf(v9, "Sample #%d", (unsigned int)v6);
v7 = (unsigned int)(v6 + firstchannel);
++v6;
mixer_set_name(v7, v9);
}
while ( numchannels > v6 );
}
return 0LL;
}

original_code:
int samples_sh_start(const struct MachineSound *msound)
{
 int i;
 int vol[16];
 const struct Samplesinterface *intf = (const struct Samplesinterface *)msound->sound_interface;
 Machine->samples = readsamples(intf->samplenames,Machine->gamedrv->name);
 numchannels = intf->channels;
 for (i = 0;i < numchannels;i++)
  vol[i] = intf->volume;
 firstchannel = mixer_allocate_channels(numchannels,vol);
 for (i = 0;i < numchannels;i++)
 {
  char buf[40];
  sprintf(buf,"Sample #%d",i);
  mixer_set_name(firstchannel + i,buf);
 }
 return 0;
}

canonical_original_code:
int samples_sh_start(struct MachineSound *msound)
{
 int i;
 int vol[16];
 struct Samplesinterface *intf = (const struct Samplesinterface *)msound->sound_interface;
 Machine->samples = readsamples(intf->samplenames,Machine->gamedrv->name);
 numchannels = intf->channels;
 for (i = 0;i < numchannels;i++)
  vol[i] = intf->volume;
 firstchannel = mixer_allocate_channels(numchannels,vol);
 for (i = 0;i < numchannels;i++)
 {
  char buf[40];
  sprintf(buf,"Sample #%d",i);
  mixer_set_name(firstchannel + i,buf);
 }
 return 0;
}

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

variable_types: i int

variable_types:
vol
int [16]

variable_types: struct Samplesinterface { int channels; int volume; char **samplenames; } *

variable_types:
buf
char [40]


docpy

original_code:
static void docpy(int opcode,int src,int *dst,INT16 _ax,INT16 _ay)
{
 int dstep1,dstep2;
 int ax = _ax;
 int ay = _ay;
 switch (opcode & 0x0700)
 {
  default:
  case 0x0000: dstep1 = 1; dstep2 = -384; break;
  case 0x0100: dstep1 = 1; dstep2 = 384; break;
  case 0x0200: dstep1 = -1; dstep2 = -384; break;
  case 0x0300: dstep1 = -1; dstep2 = 384; break;
  case 0x0400: dstep1 = -384; dstep2 = 1; break;
  case 0x0500: dstep1 = 384; dstep2 = 1; break;
  case 0x0600: dstep1 = -384; dstep2 = -1; break;
  case 0x0700: dstep1 = 384; dstep2 = -1; break;
 }
 dstep2 -= ax * dstep1;
 for (;;)
 {
  for (;;)
  {
   switch (opcode & 0x0007)
   {
    case 0:
     HD63484_ram[*dst] = HD63484_ram[src]; break;
    case 1:
     HD63484_ram[*dst] |= HD63484_ram[src]; break;
    case 2:
     HD63484_ram[*dst] &= HD63484_ram[src]; break;
    case 3:
     HD63484_ram[*dst] ^= HD63484_ram[src]; break;
    case 4:
     if (HD63484_ram[*dst] == (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 5:
     if (HD63484_ram[*dst] != (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 6:
     if (HD63484_ram[*dst] < HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 7:
     if (HD63484_ram[*dst] > HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
   }
   if (opcode & 0x0800)
   {
    if (ay == 0) break;
    else if (ay > 0)
    {
     src = (src - 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay--;
    }
    else
    {
     src = (src + 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay++;
    }
   }
   else
   {
    if (ax == 0) break;
    else if (ax > 0)
    {
     src = (src + 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax--;
    }
    else
    {
     src = (src - 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax++;
    }
   }
  }
  if (opcode & 0x0800)
  {
   ay = _ay;
   if (_ax < 0)
   {
    src = (src - 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax++;
   }
   else
   {
    src = (src + 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax--;
   }
  }
  else
  {
   ax = _ax;
   if (_ay < 0)
   {
    src = (src + 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay++;
   }
   else
   {
    src = (src - 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay--;
   }
  }
 }
}

canonical_original_code:
static void docpy(int opcode, int src, int *dst, short _ax, short _ay)
{
 int dstep1; int dstep2;
 int ax = _ax;
 int ay = _ay;
 switch (opcode & 0x0700)
 {
  default:
  case 0x0000: dstep1 = 1; dstep2 = -384; break;
  case 0x0100: dstep1 = 1; dstep2 = 384; break;
  case 0x0200: dstep1 = -1; dstep2 = -384; break;
  case 0x0300: dstep1 = -1; dstep2 = 384; break;
  case 0x0400: dstep1 = -384; dstep2 = 1; break;
  case 0x0500: dstep1 = 384; dstep2 = 1; break;
  case 0x0600: dstep1 = -384; dstep2 = -1; break;
  case 0x0700: dstep1 = 384; dstep2 = -1; break;
 }
 dstep2 -= ax * dstep1;
 for (;;)
 {
  for (;;)
  {
   switch (opcode & 0x0007)
   {
    case 0:
     HD63484_ram[*dst] = HD63484_ram[src]; break;
    case 1:
     HD63484_ram[*dst] |= HD63484_ram[src]; break;
    case 2:
     HD63484_ram[*dst] &= HD63484_ram[src]; break;
    case 3:
     HD63484_ram[*dst] ^= HD63484_ram[src]; break;
    case 4:
     if (HD63484_ram[*dst] == (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 5:
     if (HD63484_ram[*dst] != (ccmp & 0xff))
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 6:
     if (HD63484_ram[*dst] < HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
    case 7:
     if (HD63484_ram[*dst] > HD63484_ram[src])
      HD63484_ram[*dst] = HD63484_ram[src];
     break;
   }
   if (opcode & 0x0800)
   {
    if (ay == 0) break;
    else if (ay > 0)
    {
     src = (src - 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay--;
    }
    else
    {
     src = (src + 384) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ay++;
    }
   }
   else
   {
    if (ax == 0) break;
    else if (ax > 0)
    {
     src = (src + 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax--;
    }
    else
    {
     src = (src - 1) & 0x1fffff;
     *dst = (*dst + dstep1) & 0x1fffff;
     ax++;
    }
   }
  }
  if (opcode & 0x0800)
  {
   ay = _ay;
   if (_ax < 0)
   {
    src = (src - 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax++;
   }
   else
   {
    src = (src + 1 - ay) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ax == 0) break;
    ax--;
   }
  }
  else
  {
   ax = _ax;
   if (_ay < 0)
   {
    src = (src + 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay++;
   }
   else
   {
    src = (src - 384 - ax) & 0x1fffff;
    *dst = (*dst + dstep2) & 0x1fffff;
    if (ay == 0) break;
    ay--;
   }
  }
 }
}

variable_types: opcode int

variable_types: src int

variable_types:
dst
int *

variable_types: ax int

variable_types: ay int


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

result = 34LL;
if ( a1 == 1 )
result = 255LL;
return result;
}

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

result = 34LL;
if ( a1 == 1 )
result = 255LL;
return result;
}

original_code:
static data_t HD63484_status_r(offs_t offset)
{
 if (offset == 1) return 0xff;
 return 0x22;
}

canonical_original_code:
static unsigned int HD63484_status_r(unsigned int offset)
{
 if (offset == 1) return 0xff;
 return 0x22;
}


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

reg_0[a1] = a2;
result = (unsigned __int8)reg_0[0];
regno = (unsigned __int8)reg_0[0];
return result;
}

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

reg_0[a1] = a2;
result = (unsigned __int8)reg_0[0];
regno = (unsigned __int8)reg_0[0];
return result;
}

original_code:
static void HD63484_address_w(offs_t offset,data_t data)
{
 static unsigned char reg[2];
 reg[offset] = data;
 regno = reg[0];
}

canonical_original_code:
static void HD63484_address_w(unsigned int offset, unsigned int data)
{
 static unsigned char reg[2];
 reg[offset] = data;
 regno = reg[0];
}

variable_types:
data
unsigned int

variable_types:
reg
unsigned char [2]


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int16 __fastcall shanghai_vh_screenrefresh(__int64 a1)
{
unsigned int v1; // er14
int v2; // eax
unsigned int i; // er15
__int64 v4; // rsi
int v5; // ebx
int v6; // eax
unsigned int v7; // ebx
unsigned int j; // er14
int v9; // er15
__int64 v10; // rax

if ( (unsigned int)code_pressed_memory(25LL) )
base_3 -= 53760;
if ( (unsigned int)code_pressed_memory(23LL) )
base_3 += 53760;
if ( (unsigned int)code_pressed_memory(2LL) )
--bose_2;
if ( (unsigned int)code_pressed_memory(21LL) )
++bose_2;
v1 = 0;
v2 = 2 * ((unsigned __int16)word_FCE + base_3 + (((unsigned __int16)word_FCC << 16) & 0x1F0000));
do
{
for ( i = 0; i != 384; ++i )
{
v4 = i;
v5 = v2 & 0x1FFFFF;
plot_pixel(
a1,
v4,
v1,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)HD63484_ram + (v2 & 0x1FFFFF))));
v2 = v5 + 1;
}
++v1;
}
while ( v1 != 280 );
LOWORD(v6) = word_F06 & 0x300;
if ( (word_F06 & 0x300) == 768 )
{
v7 = 0;
v6 = 2 * ((unsigned __int16)word_FDE + base_3 + (((unsigned __int16)word_FDC << 16) & 0x1F0000));
do
{
for ( j = 0; j != 384; ++j )
{
v9 = v6 & 0x1FFFFF;
v10 = *((unsigned __int8 *)HD63484_ram + (v6 & 0x1FFFFF));
if ( (_BYTE)v10 )
plot_pixel(a1, j, v7, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2 * v10));
v6 = v9 + 1;
}
++v7;
}
while ( v7 != 280 );
}
return v6;
}

canonical_decompiled_code:
__int16 __fastcall func4(__int64 a1)
{
unsigned int v1; // er14
int v2; // eax
unsigned int i; // er15
__int64 v4; // rsi
int v5; // ebx
int v6; // eax
unsigned int v7; // ebx
unsigned int j; // er14
int v9; // er15
__int64 v10; // rax

if ( (unsigned int)code_pressed_memory(25LL) )
base_3 -= 53760;
if ( (unsigned int)code_pressed_memory(23LL) )
base_3 += 53760;
if ( (unsigned int)code_pressed_memory(2LL) )
--bose_2;
if ( (unsigned int)code_pressed_memory(21LL) )
++bose_2;
v1 = 0;
v2 = 2 * ((unsigned __int16)word_FCE + base_3 + (((unsigned __int16)word_FCC << 16) & 0x1F0000));
do
{
for ( i = 0; i != 384; ++i )
{
v4 = i;
v5 = v2 & 0x1FFFFF;
plot_pixel(
a1,
v4,
v1,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)HD63484_ram + (v2 & 0x1FFFFF))));
v2 = v5 + 1;
}
++v1;
}
while ( v1 != 280 );
LOWORD(v6) = word_F06 & 0x300;
if ( (word_F06 & 0x300) == 768 )
{
v7 = 0;
v6 = 2 * ((unsigned __int16)word_FDE + base_3 + (((unsigned __int16)word_FDC << 16) & 0x1F0000));
do
{
for ( j = 0; j != 384; ++j )
{
v9 = v6 & 0x1FFFFF;
v10 = *((unsigned __int8 *)HD63484_ram + (v6 & 0x1FFFFF));
if ( (_BYTE)v10 )
plot_pixel(a1, j, v7, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2 * v10));
v6 = v9 + 1;
}
++v7;
}
while ( v7 != 280 );
}
return v6;
}

original_code:
void shanghai_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int x,y,b;
 static int base,bose=256;
if (code_pressed_memory(KEYCODE_Z)) base -= 384/2*280;
if (code_pressed_memory(KEYCODE_X)) base += 384/2*280;
if (code_pressed_memory(KEYCODE_C)) bose--;
if (code_pressed_memory(KEYCODE_V)) bose++;
 b = 2 * (base + ((HD63484_reg[0xcc/2] & 0x001f) << 16) + HD63484_reg[0xce/2]);
 for (y = 0;y < 280;y++)
 {
  for (x = 0;x < 384;x++)
  {
   b &= 0x1fffff;
   plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
   b++;
  }
 }
 if ((HD63484_reg[0x06/2] & 0x0300) == 0x0300)
 {
  b = 2 * (base + ((HD63484_reg[0xdc/2] & 0x001f) << 16) + HD63484_reg[0xde/2]);
  for (y = 0;y < 280;y++)
  {
   for (x = 0;x < 384;x++)
   {
    b &= 0x1fffff;
    if (HD63484_ram[b])
     plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
    b++;
   }
  }
 }
}

canonical_original_code:
void shanghai_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int x; int y; int b;
 static int base; static int bose = 256;
if (code_pressed_memory(KEYCODE_Z)) base -= 384/2*280;
if (code_pressed_memory(KEYCODE_X)) base += 384/2*280;
if (code_pressed_memory(KEYCODE_C)) bose--;
if (code_pressed_memory(KEYCODE_V)) bose++;
 b = 2 * (base + ((HD63484_reg[0xcc/2] & 0x001f) << 16) + HD63484_reg[0xce/2]);
 for (y = 0;y < 280;y++)
 {
  for (x = 0;x < 384;x++)
  {
   b &= 0x1fffff;
   plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
   b++;
  }
 }
 if ((HD63484_reg[0x06/2] & 0x0300) == 0x0300)
 {
  b = 2 * (base + ((HD63484_reg[0xdc/2] & 0x001f) << 16) + HD63484_reg[0xde/2]);
  for (y = 0;y < 280;y++)
  {
   for (x = 0;x < 384;x++)
   {
    b &= 0x1fffff;
    if (HD63484_ram[b])
     plot_pixel(bitmap,x,y,Machine->pens[HD63484_ram[b]]);
    b++;
   }
  }
 }
}

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

variable_types: x int

variable_types: y int

variable_types: b int

variable_types: base int

variable_types: bose int


decompiled_code:
__int64 shanghai_interrupt()
{
interrupt_vector_w(0LL, 128LL);
return interrupt();
}

canonical_decompiled_code:
__int64 func5()
{
interrupt_vector_w(0LL, 128LL);
return interrupt();
}

original_code:
static int shanghai_interrupt(void)
{
 interrupt_vector_w(0,0x80);
 return interrupt();
}

canonical_original_code:
static int shanghai_interrupt()
{
 interrupt_vector_w(0,0x80);
 return interrupt();
}


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

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

original_code:
static void shanghai_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 shanghai_coin_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 1);
 coin_counter_w(1,data & 2);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall HD63484_data_r(int a1)
{
__int64 result; // rax
__int16 v2; // ax
unsigned int v3; // edx

if ( regno == 128 )
{
v2 = cpu_getscanline();
v3 = (unsigned __int8)v2;
result = HIBYTE(v2);
if ( !a1 )
result = v3;
}
else
{
result = 0LL;
if ( !a1 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax
__int16 v2; // ax
unsigned int v3; // edx

if ( regno == 128 )
{
v2 = cpu_getscanline();
v3 = (unsigned __int8)v2;
result = HIBYTE(v2);
if ( !a1 )
result = v3;
}
else
{
result = 0LL;
if ( !a1 )
result = 0LL;
}
return result;
}

original_code:
static data_t HD63484_data_r(offs_t offset)
{
 int res;
 if (regno == 0x80)
 {
  res = cpu_getscanline();
 }
 else
 {
  res = 0;
 }
 if (offset == 0)
  return res & 0xff;
 else
  return (res >> 8) & 0xff;
}

canonical_original_code:
static unsigned int HD63484_data_r(unsigned int offset)
{
 int res;
 if (regno == 0x80)
 {
  res = cpu_getscanline();
 }
 else
 {
  res = 0;
 }
 if (offset == 0)
  return res & 0xff;
 else
  return (res >> 8) & 0xff;
}

variable_types: res int


decompiled_code:
_BOOL8 HD63484_start()
{
fifo_counter = 0;
HD63484_ram = calloc(0x200000uLL, 1uLL);
return HD63484_ram == 0LL;
}

canonical_decompiled_code:
_BOOL8 func9()
{
fifo_counter = 0;
HD63484_ram = calloc(0x200000uLL, 1uLL);
return HD63484_ram == 0LL;
}

original_code:
int HD63484_start(void)
{
 fifo_counter = 0;
 HD63484_ram = (UINT8*)malloc(0x200000);
 if (!HD63484_ram) return 1;
 memset(HD63484_ram,0,0x200000);
 return 0;
}

canonical_original_code:
int HD63484_start()
{
 fifo_counter = 0;
 HD63484_ram = (unsigned char *)malloc(0x200000);
 if (!HD63484_ram) return 1;
 memset(HD63484_ram,0,0x200000);
 return 0;
}


decompiled_code:
// attributes: thunk
_BOOL8 shanghai_vh_start()
{
return HD63484_start();
}

canonical_decompiled_code:
_BOOL8 func10()
{
return func9();
}

original_code:
int shanghai_vh_start(void)
{
 return HD63484_start();
}

canonical_original_code:
int shanghai_vh_start()
{
 return HD63484_start();
}


canonical_decompiled_code:
void func11()
{
free(HD63484_ram);
HD63484_ram = 0LL;
}

original_code:
void HD63484_stop(void)
{
 free(HD63484_ram);
 HD63484_ram = 0;
}


decompiled_code:
// attributes: thunk
void shanghai_vh_stop()
{
HD63484_stop();
}

canonical_decompiled_code:
void func12()
{
func11();
}

original_code:
void shanghai_vh_stop(void)
{
 HD63484_stop();
}


decompiled_code:
__int64 __fastcall HD63484_command_w(__int16 a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax
__int16 v4; // ax
int v5; // edx
int v6; // edx
int v7; // edx
char v8; // dh
_BYTE *v9; // rcx
__int16 v10; // bp
__int64 v11; // rcx
__int16 v12; // r12
char v13; // r11
int v14; // ebx
char *v15; // r10
int v16; // er15
int v17; // edi
int v18; // er14
int v19; // er9
int v20; // er13
char *v21; // rdx
int v22; // ebx
int v23[13]; // [rsp+0h] [rbp-34h] BYREF

v1 = fifo_counter;
fifo[fifo_counter] = a1;
v2 = v1 + 1;
fifo_counter = v1 + 1;
result = instruction_length[((unsigned __int16)fifo[0] >> 10) & 0x3F];
if ( (_DWORD)result == -1 )
{
if ( v2 <= 1 )
return result;
result = (unsigned int)(unsigned __int16)word_1022 + 2;
if ( v2 < (int)result )
return result;
}
else if ( (_DWORD)result == -2 )
{
if ( v2 <= 1 )
return result;
result = 2 * (unsigned int)(unsigned __int16)word_1022 + 2;
if ( v2 < (int)result )
return result;
}
else if ( v2 < (int)result )
{
return result;
}
if ( fifo[0] == 1024 )
{
fifo_counter = 0;
v5 = (unsigned __int16)word_1024 >> 4;
result = v5 | ((unsigned __int16)word_1022 << 12) & 0xFF000u;
org = v5 | ((unsigned __int16)word_1022 << 12) & 0xFF000;
}
else
{
if ( fifo[0] == 2048 )
{
result = (unsigned __int16)word_1022;
cl0 = word_1022;
}
else if ( fifo[0] != 2049 )
{
if ( fifo[0] == 2050 )
{
result = (unsigned __int16)word_1022;
ccmp = word_1022;
}
else if ( fifo[0] == 2060 )
{
v7 = rwp & 0xFFF;
result = v7 | ((unsigned __int16)word_1022 << 12) & 0xFF000u;
rwp = v7 | ((unsigned __int16)word_1022 << 12) & 0xFF000;
}
else if ( fifo[0] == 2061 )
{
v6 = (unsigned __int16)word_1022 >> 4;
result = v6 | rwp & 0xFF000u;
rwp = v6 | rwp & 0xFF000;
}
else
{
if ( fifo[0] != 18432 )
{
if ( fifo[0] == 22528 )
{
rwp *= 2;
doclr_constprop_0(0, word_1022, (__int16)(2 * word_1024 + 1), word_1026);
}
else if ( (fifo[0] & 0xFFFC) == 23552 )
{
rwp *= 2;
doclr_constprop_0(fifo[0], word_1022, (__int16)(2 * word_1024 + 1), word_1026);
}
else
{
LOBYTE(v4) = fifo[0];
HIBYTE(v4) = HIBYTE(fifo[0]) & 0xF0;
if ( v4 != 24576 && (fifo[0] & 0xF0FC) != 28672 )
{
if ( fifo[0] == (__int16)0x8000 )
{
cpx = word_1022;
result = (unsigned __int16)word_1024;
cpy = word_1024;
}
else
{
result = fifo[0] & 0xFFF8;
if ( (fifo[0] & 0xFFF8) == 0xC000 )
{
v10 = cpy;
v11 = fifo[0] & 7;
v12 = word_1024;
v13 = cl0;
v14 = (unsigned __int16)word_1022 - cpx;
v15 = (char *)HD63484_ram;
v16 = (unsigned __int8)cl0;
v17 = v14;
v18 = (unsigned __int8)ccmp;
v19 = (unsigned __int16)word_1024 - (unsigned __int16)cpy;
v20 = (__int16)(word_1022 - cpx);
LODWORD(result) = (cpx + 2 * org - 384 * cpy) & 0x1FFFFF;
while ( 1 )
{
v21 = &v15[(int)result];
switch ( v11 )
{
case 0LL:
goto LABEL_42;
case 1LL:
*v21 |= v13;
goto LABEL_43;
case 2LL:
*v21 &= v13;
goto LABEL_43;
case 3LL:
*v21 ^= v13;
goto LABEL_43;
case 4LL:
if ( (unsigned __int8)*v21 == v18 )
goto LABEL_42;
goto LABEL_43;
case 5LL:
if ( (unsigned __int8)*v21 == v18 )
goto LABEL_43;
goto LABEL_42;
case 6LL:
if ( (unsigned __int8)*v21 < v16 )
goto LABEL_42;
goto LABEL_43;
case 7LL:
if ( v16 < (unsigned __int8)*v21 )
LABEL_42:
*v21 = v13;
LABEL_43:
if ( (_WORD)v17 )
{
if ( (__int16)v17 <= 0 )
{
++v17;
LODWORD(result) = (result - 1) & 0x1FFFFF;
}
else
{
--v17;
LODWORD(result) = (result + 1) & 0x1FFFFF;
}
}
else if ( v10 <= v12 )
{
result = ((_DWORD)result - 384 - v20) & 0x1FFFFF;
if ( !(_WORD)v19 )
goto LABEL_19;
--v19;
v17 = v14;
}
else
{
result = ((_DWORD)result + 384 - v20) & 0x1FFFFF;
if ( !(_WORD)v19 )
goto LABEL_19;
++v19;
v17 = v14;
}
break;
}
}
}
if ( (fifo[0] & 0xF0F8) == 0xE000 )
{
v22 = 2 * org;
v23[0] = (-384 * cpy + 2 * org + cpx) & 0x1FFFFF;
docpy(fifo[0], (-384 * word_1024 + 2 * org + word_1022) & 0x1FFFFF, v23, word_1026, word_1028);
result = (unsigned int)((v23[0] - v22) / 384);
cpx = (v23[0] - v22) % 384;
cpy = (v23[0] - v22) / 384;
}
}
goto LABEL_19;
}
rwp *= 2;
docpy(
fifo[0],
2 * (((unsigned __int16)word_1024 >> 4) | ((unsigned __int16)word_1022 << 12) & 0xFF000),
&rwp,
2 * word_1026 + 1,
word_1028);
}
result = (unsigned int)(rwp / 2);
rwp /= 2;
LABEL_19:
fifo_counter = 0;
return result;
}
v8 = HIBYTE(word_1022);
v9 = HD63484_ram;
*((_BYTE *)HD63484_ram + 2 * rwp) = word_1022;
v9[2 * rwp + 1] = v8;
result = (rwp + 1) & 0xFFFFF;
rwp = (rwp + 1) & 0xFFFFF;
}
}
fifo_counter = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int16 a1)
{
int v1; // eax
int v2; // edx
__int64 result; // rax
__int16 v4; // ax
int v5; // edx
int v6; // edx
int v7; // edx
char v8; // dh
_BYTE *v9; // rcx
__int16 v10; // bp
__int64 v11; // rcx
__int16 v12; // r12
char v13; // r11
int v14; // ebx
char *v15; // r10
int v16; // er15
int v17; // edi
int v18; // er14
int v19; // er9
int v20; // er13
char *v21; // rdx
int v22; // ebx
int v23[13]; // [rsp+0h] [rbp-34h] BYREF

v1 = fifo_counter;
fifo[fifo_counter] = a1;
v2 = v1 + 1;
fifo_counter = v1 + 1;
result = instruction_length[((unsigned __int16)fifo[0] >> 10) & 0x3F];
if ( (_DWORD)result == -1 )
{
if ( v2 <= 1 )
return result;
result = (unsigned int)(unsigned __int16)word_1022 + 2;
if ( v2 < (int)result )
return result;
}
else if ( (_DWORD)result == -2 )
{
if ( v2 <= 1 )
return result;
result = 2 * (unsigned int)(unsigned __int16)word_1022 + 2;
if ( v2 < (int)result )
return result;
}
else if ( v2 < (int)result )
{
return result;
}
if ( fifo[0] == 1024 )
{
fifo_counter = 0;
v5 = (unsigned __int16)word_1024 >> 4;
result = v5 | ((unsigned __int16)word_1022 << 12) & 0xFF000u;
org = v5 | ((unsigned __int16)word_1022 << 12) & 0xFF000;
}
else
{
if ( fifo[0] == 2048 )
{
result = (unsigned __int16)word_1022;
cl0 = word_1022;
}
else if ( fifo[0] != 2049 )
{
if ( fifo[0] == 2050 )
{
result = (unsigned __int16)word_1022;
ccmp = word_1022;
}
else if ( fifo[0] == 2060 )
{
v7 = rwp & 0xFFF;
result = v7 | ((unsigned __int16)word_1022 << 12) & 0xFF000u;
rwp = v7 | ((unsigned __int16)word_1022 << 12) & 0xFF000;
}
else if ( fifo[0] == 2061 )
{
v6 = (unsigned __int16)word_1022 >> 4;
result = v6 | rwp & 0xFF000u;
rwp = v6 | rwp & 0xFF000;
}
else
{
if ( fifo[0] != 18432 )
{
if ( fifo[0] == 22528 )
{
rwp *= 2;
func8(0, word_1022, (__int16)(2 * word_1024 + 1), word_1026);
}
else if ( (fifo[0] & 0xFFFC) == 23552 )
{
rwp *= 2;
func8(fifo[0], word_1022, (__int16)(2 * word_1024 + 1), word_1026);
}
else
{
LOBYTE(v4) = fifo[0];
HIBYTE(v4) = HIBYTE(fifo[0]) & 0xF0;
if ( v4 != 24576 && (fifo[0] & 0xF0FC) != 28672 )
{
if ( fifo[0] == (__int16)0x8000 )
{
cpx = word_1022;
result = (unsigned __int16)word_1024;
cpy = word_1024;
}
else
{
result = fifo[0] & 0xFFF8;
if ( (fifo[0] & 0xFFF8) == 0xC000 )
{
v10 = cpy;
v11 = fifo[0] & 7;
v12 = word_1024;
v13 = cl0;
v14 = (unsigned __int16)word_1022 - cpx;
v15 = (char *)HD63484_ram;
v16 = (unsigned __int8)cl0;
v17 = v14;
v18 = (unsigned __int8)ccmp;
v19 = (unsigned __int16)word_1024 - (unsigned __int16)cpy;
v20 = (__int16)(word_1022 - cpx);
LODWORD(result) = (cpx + 2 * org - 384 * cpy) & 0x1FFFFF;
while ( 1 )
{
v21 = &v15[(int)result];
switch ( v11 )
{
case 0LL:
goto LABEL_42;
case 1LL:
*v21 |= v13;
goto LABEL_43;
case 2LL:
*v21 &= v13;
goto LABEL_43;
case 3LL:
*v21 ^= v13;
goto LABEL_43;
case 4LL:
if ( (unsigned __int8)*v21 == v18 )
goto LABEL_42;
goto LABEL_43;
case 5LL:
if ( (unsigned __int8)*v21 == v18 )
goto LABEL_43;
goto LABEL_42;
case 6LL:
if ( (unsigned __int8)*v21 < v16 )
goto LABEL_42;
goto LABEL_43;
case 7LL:
if ( v16 < (unsigned __int8)*v21 )
LABEL_42:
*v21 = v13;
LABEL_43:
if ( (_WORD)v17 )
{
if ( (__int16)v17 <= 0 )
{
++v17;
LODWORD(result) = (result - 1) & 0x1FFFFF;
}
else
{
--v17;
LODWORD(result) = (result + 1) & 0x1FFFFF;
}
}
else if ( v10 <= v12 )
{
result = ((_DWORD)result - 384 - v20) & 0x1FFFFF;
if ( !(_WORD)v19 )
goto LABEL_19;
--v19;
v17 = v14;
}
else
{
result = ((_DWORD)result + 384 - v20) & 0x1FFFFF;
if ( !(_WORD)v19 )
goto LABEL_19;
++v19;
v17 = v14;
}
break;
}
}
}
if ( (fifo[0] & 0xF0F8) == 0xE000 )
{
v22 = 2 * org;
v23[0] = (-384 * cpy + 2 * org + cpx) & 0x1FFFFF;
func0(fifo[0], (-384 * word_1024 + 2 * org + word_1022) & 0x1FFFFF, v23, word_1026, word_1028);
result = (unsigned int)((v23[0] - v22) / 384);
cpx = (v23[0] - v22) % 384;
cpy = (v23[0] - v22) / 384;
}
}
goto LABEL_19;
}
rwp *= 2;
func0(
fifo[0],
2 * (((unsigned __int16)word_1024 >> 4) | ((unsigned __int16)word_1022 << 12) & 0xFF000),
&rwp,
2 * word_1026 + 1,
word_1028);
}
result = (unsigned int)(rwp / 2);
rwp /= 2;
LABEL_19:
fifo_counter = 0;
return result;
}
v8 = HIBYTE(word_1022);
v9 = HD63484_ram;
*((_BYTE *)HD63484_ram + 2 * rwp) = word_1022;
v9[2 * rwp + 1] = v8;
result = (rwp + 1) & 0xFFFFF;
rwp = (rwp + 1) & 0xFFFFF;
}
}
fifo_counter = 0;
}
return result;
}

original_code:
void HD63484_command_w(UINT16 cmd)
{
 int len;
 fifo[fifo_counter++] = cmd;
 len = instruction_length[fifo[0]>>10];
 if (len == -1)
 {
  if (fifo_counter < 2) return;
  else len = fifo[1]+2;
 }
 else if (len == -2)
 {
  if (fifo_counter < 2) return;
  else len = 2*fifo[1]+2;
 }
 if (fifo_counter >= len)
 {
  if (fifo[0] == 0x0400)
   org = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
  else if (fifo[0] == 0x0800)
   cl0 = fifo[1];
  else if (fifo[0] == 0x0801)
   cl1 = fifo[1];
  else if (fifo[0] == 0x0802)
   ccmp = fifo[1];
  else if (fifo[0] == 0x080c)
   rwp = (rwp & 0x00fff) | ((fifo[1] & 0x00ff) << 12);
  else if (fifo[0] == 0x080d)
   rwp = (rwp & 0xff000) | ((fifo[1] & 0xfff0) >> 4);
  else if (fifo[0] == 0x4800)
  {
   HD63484_ram[2*rwp] = fifo[1] & 0x00ff ;
   HD63484_ram[2*rwp+1] = (fifo[1] & 0xff00) >> 8;
   rwp = (rwp + 1) & 0xfffff;
  }
  else if (fifo[0] == 0x5800)
  {
rwp *= 2;
   doclr(fifo[0],fifo[1],&rwp,2*fifo[2]+1,fifo[3]);
rwp /= 2;
  }
  else if ((fifo[0] & 0xfffc) == 0x5c00)
  {
rwp *= 2;
   doclr(fifo[0],fifo[1],&rwp,2*fifo[2]+1,fifo[3]);
rwp /= 2;
  }
  else if ((fifo[0] & 0xf0ff) == 0x6000)
  {
   int src;
   src = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
rwp *= 2;
   docpy(fifo[0],2*src,&rwp,2*fifo[3]+1,fifo[4]);
rwp /= 2;
  }
  else if ((fifo[0] & 0xf0fc) == 0x7000)
  {
   int src;
   src = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
rwp *= 2;
   docpy(fifo[0],2*src,&rwp,2*fifo[3]+1,fifo[4]);
rwp /= 2;
  }
  else if (fifo[0] == 0x8000)
  {
   cpx = fifo[1];
   cpy = fifo[2];
  }
  else if ((fifo[0] & 0xfff8) == 0xc000)
  {
   INT16 pcx,pcy;
   INT16 ax,ay;
   int dst;
   pcx = fifo[1];
   pcy = fifo[2];
   ax = pcx - cpx;
   ay = pcy - cpy;
   dst = (2*org + cpx - cpy * 384) & 0x1fffff;
   for (;;)
   {
    for (;;)
    {
     switch (fifo[0] & 0x0007)
     {
      case 0:
       HD63484_ram[dst] = cl0; break;
      case 1:
       HD63484_ram[dst] |= cl0; break;
      case 2:
       HD63484_ram[dst] &= cl0; break;
      case 3:
       HD63484_ram[dst] ^= cl0; break;
      case 4:
       if (HD63484_ram[dst] == (ccmp & 0xff))
        HD63484_ram[dst] = cl0;
       break;
      case 5:
       if (HD63484_ram[dst] != (ccmp & 0xff))
        HD63484_ram[dst] = cl0;
       break;
      case 6:
       if (HD63484_ram[dst] < (cl0 & 0xff))
        HD63484_ram[dst] = cl0;
       break;
      case 7:
       if (HD63484_ram[dst] > (cl0 & 0xff))
        HD63484_ram[dst] = cl0;
       break;
     }
     if (ax == 0) break;
     else if (ax > 0)
     {
      dst = (dst + 1) & 0x1fffff;
      ax--;
     }
     else
     {
      dst = (dst - 1) & 0x1fffff;
      ax++;
     }
    }
    ax = pcx - cpx;
    if (pcy < cpy)
    {
     dst = (dst + 384 - ax) & 0x1fffff;
     if (ay == 0) break;
     ay++;
    }
    else
    {
     dst = (dst - 384 - ax) & 0x1fffff;
     if (ay == 0) break;
     ay--;
    }
   }
  }
  else if ((fifo[0] & 0xf0f8) == 0xe000)
  {
   INT16 pcx,pcy;
   int src,dst;
   pcx = fifo[1];
   pcy = fifo[2];
   src = (2*org + pcx - pcy * 384) & 0x1fffff;
   dst = (2*org + cpx - cpy * 384) & 0x1fffff;
   docpy(fifo[0],src,&dst,fifo[3],fifo[4]);
   cpx = (dst - 2*org) % 384;
   cpy = (dst - 2*org) / 384;
  }
  fifo_counter = 0;
 }
}

canonical_original_code:
void HD63484_command_w(unsigned short cmd)
{
 int len;
 fifo[fifo_counter++] = cmd;
 len = instruction_length[fifo[0]>>10];
 if (len == -1)
 {
  if (fifo_counter < 2) return;
  else len = fifo[1]+2;
 }
 else if (len == -2)
 {
  if (fifo_counter < 2) return;
  else len = 2*fifo[1]+2;
 }
 if (fifo_counter >= len)
 {
  if (fifo[0] == 0x0400)
   org = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
  else if (fifo[0] == 0x0800)
   cl0 = fifo[1];
  else if (fifo[0] == 0x0801)
   cl1 = fifo[1];
  else if (fifo[0] == 0x0802)
   ccmp = fifo[1];
  else if (fifo[0] == 0x080c)
   rwp = (rwp & 0x00fff) | ((fifo[1] & 0x00ff) << 12);
  else if (fifo[0] == 0x080d)
   rwp = (rwp & 0xff000) | ((fifo[1] & 0xfff0) >> 4);
  else if (fifo[0] == 0x4800)
  {
   HD63484_ram[2*rwp] = fifo[1] & 0x00ff ;
   HD63484_ram[2*rwp+1] = (fifo[1] & 0xff00) >> 8;
   rwp = (rwp + 1) & 0xfffff;
  }
  else if (fifo[0] == 0x5800)
  {
rwp *= 2;
   doclr(fifo[0],fifo[1],&rwp,2*fifo[2]+1,fifo[3]);
rwp /= 2;
  }
  else if ((fifo[0] & 0xfffc) == 0x5c00)
  {
rwp *= 2;
   doclr(fifo[0],fifo[1],&rwp,2*fifo[2]+1,fifo[3]);
rwp /= 2;
  }
  else if ((fifo[0] & 0xf0ff) == 0x6000)
  {
   int src;
   src = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
rwp *= 2;
   docpy(fifo[0],2*src,&rwp,2*fifo[3]+1,fifo[4]);
rwp /= 2;
  }
  else if ((fifo[0] & 0xf0fc) == 0x7000)
  {
   int src;
   src = ((fifo[1] & 0x00ff) << 12) | ((fifo[2] & 0xfff0) >> 4);
rwp *= 2;
   docpy(fifo[0],2*src,&rwp,2*fifo[3]+1,fifo[4]);
rwp /= 2;
  }
  else if (fifo[0] == 0x8000)
  {
   cpx = fifo[1];
   cpy = fifo[2];
  }
  else if ((fifo[0] & 0xfff8) == 0xc000)
  {
   short pcx; short pcy;
   short ax; short ay;
   int dst;
   pcx = fifo[1];
   pcy = fifo[2];
   ax = pcx - cpx;
   ay = pcy - cpy;
   dst = (2*org + cpx - cpy * 384) & 0x1fffff;
   for (;;)
   {
    for (;;)
    {
     switch (fifo[0] & 0x0007)
     {
      case 0:
       HD63484_ram[dst] = cl0; break;
      case 1:
       HD63484_ram[dst] |= cl0; break;
      case 2:
       HD63484_ram[dst] &= cl0; break;
      case 3:
       HD63484_ram[dst] ^= cl0; break;
      case 4:
       if (HD63484_ram[dst] == (ccmp & 0xff))
        HD63484_ram[dst] = cl0;
       break;
      case 5:
       if (HD63484_ram[dst] != (ccmp & 0xff))
        HD63484_ram[dst] = cl0;
       break;
      case 6:
       if (HD63484_ram[dst] < (cl0 & 0xff))
        HD63484_ram[dst] = cl0;
       break;
      case 7:
       if (HD63484_ram[dst] > (cl0 & 0xff))
        HD63484_ram[dst] = cl0;
       break;
     }
     if (ax == 0) break;
     else if (ax > 0)
     {
      dst = (dst + 1) & 0x1fffff;
      ax--;
     }
     else
     {
      dst = (dst - 1) & 0x1fffff;
      ax++;
     }
    }
    ax = pcx - cpx;
    if (pcy < cpy)
    {
     dst = (dst + 384 - ax) & 0x1fffff;
     if (ay == 0) break;
     ay++;
    }
    else
    {
     dst = (dst - 384 - ax) & 0x1fffff;
     if (ay == 0) break;
     ay--;
    }
   }
  }
  else if ((fifo[0] & 0xf0f8) == 0xe000)
  {
   short pcx; short pcy;
   int src; int dst;
   pcx = fifo[1];
   pcy = fifo[2];
   src = (2*org + pcx - pcy * 384) & 0x1fffff;
   dst = (2*org + cpx - cpy * 384) & 0x1fffff;
   docpy(fifo[0],src,&dst,fifo[3],fifo[4]);
   cpx = (dst - 2*org) % 384;
   cpy = (dst - 2*org) / 384;
  }
  fifo_counter = 0;
 }
}

variable_types:
cmd
unsigned short

variable_types: len int

variable_types: pcx short

variable_types: pcy short

variable_types: ax short

variable_types: ay short

variable_types: dst int


decompiled_code:
__int64 __fastcall HD63484_data_w(unsigned int a1, char a2)
{
__int64 result; // rax
int v3; // edx
__int16 v4; // di

result = a1;
dat_1[a1] = a2;
if ( a1 == 1 )
{
v3 = regno;
v4 = (unsigned __int8)dat_1[0] + ((unsigned __int8)byte_EE3 << 8);
if ( regno )
{
result = regno / 2;
HD63484_reg[result] = v4;
if ( (v3 & 0x80u) != 0 )
regno = v3 + 2;
}
else
{
result = HD63484_command_w(v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, char a2)
{
__int64 result; // rax
int v3; // edx
__int16 v4; // di

result = a1;
dat_1[a1] = a2;
if ( a1 == 1 )
{
v3 = regno;
v4 = (unsigned __int8)dat_1[0] + ((unsigned __int8)byte_EE3 << 8);
if ( regno )
{
result = regno / 2;
HD63484_reg[result] = v4;
if ( (v3 & 0x80u) != 0 )
regno = v3 + 2;
}
else
{
result = func13(v4);
}
}
return result;
}

original_code:
static void HD63484_data_w(offs_t offset,data_t data)
{
 static unsigned char dat[2];
 dat[offset] = data;
 if (offset == 1)
 {
  int val = dat[0] + 256 * dat[1];
  if (regno == 0)
   HD63484_command_w(val);
  else
  {
   HD63484_reg[regno/2] = val;
   if (regno & 0x80) regno += 2;
  }
 }
}

canonical_original_code:
static void HD63484_data_w(unsigned int offset, unsigned int data)
{
 static unsigned char dat[2];
 dat[offset] = data;
 if (offset == 1)
 {
  int val = dat[0] + 256 * dat[1];
  if (regno == 0)
   HD63484_command_w(val);
  else
  {
   HD63484_reg[regno/2] = val;
   if (regno & 0x80) regno += 2;
  }
 }
}

variable_types:
data
unsigned int

variable_types:
dat
unsigned char [2]

variable_types: val int


original_code:
void qsound_update( int num, INT16 **buffer, int length )
{
 int i,j;
 int rvol, lvol, count;
 struct QSOUND_CHANNEL *pC=&qsound_channel[0];
 QSOUND_SRC_SAMPLE * pST;
 QSOUND_SAMPLE *datap[2];
 if (Machine->sample_rate == 0) return;
 datap[0] = buffer[0];
 datap[1] = buffer[1];
 memset( datap[0], 0x00, length * sizeof(QSOUND_SAMPLE) );
 memset( datap[1], 0x00, length * sizeof(QSOUND_SAMPLE) );
 for (i=0; i<16; i++)
 {
  if (pC->key)
  {
   QSOUND_SAMPLE *pOutL=datap[0];
   QSOUND_SAMPLE *pOutR=datap[1];
   pST=qsound_sample_rom+pC->bank;
   rvol=(pC->rvol*pC->vol)>>(8*1);
   lvol=(pC->lvol*pC->vol)>>(8*1);
   for (j=length-1; j>=0; j--)
   {
    count=(pC->offset)>>16;
    pC->offset &= 0xffff;
    if (count)
    {
     pC->address += count;
     if (pC->address >= pC->end)
     {
      if (!pC->loop)
      {
       pC->key=0;
       break;
      }
      pC->address = (pC->end - pC->loop) & 0xffff;
     }
     pC->lastdt=pST[pC->address];
    }
    (*pOutL) += ((pC->lastdt * lvol) >> 6);
    (*pOutR) += ((pC->lastdt * rvol) >> 6);
    pOutL++;
    pOutR++;
    pC->offset += pC->pitch;
   }
  }
  pC++;
 }
}

canonical_original_code:
void qsound_update(int num, short **buffer, int length)
{
 int i; int j;
 int rvol; int lvol; int count;
 struct QSOUND_CHANNEL *pC = &qsound_channel[0];
 char *pST;
 short *datap[2];
 if (Machine->sample_rate == 0) return;
 datap[0] = buffer[0];
 datap[1] = buffer[1];
 memset( datap[0], 0x00, length * sizeof(QSOUND_SAMPLE) );
 memset( datap[1], 0x00, length * sizeof(QSOUND_SAMPLE) );
 for (i=0; i<16; i++)
 {
  if (pC->key)
  {
   short *pOutL = datap[0];
   short *pOutR = datap[1];
   pST=qsound_sample_rom+pC->bank;
   rvol=(pC->rvol*pC->vol)>>(8*1);
   lvol=(pC->lvol*pC->vol)>>(8*1);
   for (j=length-1; j>=0; j--)
   {
    count=(pC->offset)>>16;
    pC->offset &= 0xffff;
    if (count)
    {
     pC->address += count;
     if (pC->address >= pC->end)
     {
      if (!pC->loop)
      {
       pC->key=0;
       break;
      }
      pC->address = (pC->end - pC->loop) & 0xffff;
     }
     pC->lastdt=pST[pC->address];
    }
    (*pOutL) += ((pC->lastdt * lvol) >> 6);
    (*pOutR) += ((pC->lastdt * rvol) >> 6);
    pOutL++;
    pOutR++;
    pC->offset += pC->pitch;
   }
  }
  pC++;
 }
}

variable_types: num int

variable_types:
buffer
short **

variable_types: length int

variable_types: i int

variable_types: j int

variable_types: rvol int

variable_types: lvol int

variable_types: count int

variable_types: struct QSOUND_CHANNEL { int bank; int address; int pitch; int reg3; int loop; int end; int vol; int pan; int reg9; int key; int lvol; int rvol; int lastdt; int offset; } *

variable_types:
pST
char *

variable_types:
datap
short *[2]

variable_types:
pOutL
short *

variable_types:
pOutR
short *


decompiled_code:
__int64 __fastcall qsound_sh_start(__int64 a1, const char *a2)
{
__int64 v3; // rax
__int64 v5; // rbx
__int64 v6; // rdi
void *v7; // rdx
double v8; // xmm1_8
double v9; // xmm0_8
double v10; // xmm0_8
const char *v11; // rax
const char *v12; // rdx
const char *v13; // rax
int v14; // eax
int v15; // eax
int v16[2]; // [rsp+8h] [rbp-90h] BYREF
__int64 v17[2]; // [rsp+10h] [rbp-88h] BYREF
char s[40]; // [rsp+20h] [rbp-78h] BYREF
char v19[80]; // [rsp+48h] [rbp-50h] BYREF

if ( !*(_DWORD *)(Machine + 836LL) )
return 0LL;
v3 = *(_QWORD *)(a1 + 8);
v5 = 0LL;
v6 = *(unsigned int *)(v3 + 4);
intf = v3;
qsound_sample_rom = memory_region(v6);
v7 = &qsound_channel;
memset(&qsound_channel, 0, 0x380uLL);
v8 = *(double *)&LC3;
*(float *)&qsound_frq_ratio = (float)((float)((float)*(int *)intf / 166.0) / (float)*(int *)(Machine + 836LL)) * 16.0;
do
{
v9 = (double)(int)v5;
if ( (double)(int)v5 < 0.0 )
{
v10 = sqrt(v9);
v8 = *(double *)&LC3;
}
else
{
v10 = sqrt(v9);
}
qsound_pan_table[v5++] = (int)(v10 * v8);
}
while ( v5 != 33 );
v17[0] = (__int64)s;
v17[1] = (__int64)v19;
v11 = (const char *)sound_name(a1, a2, v7);
sprintf(s, "%s L", v11);
v13 = (const char *)sound_name(a1, "%s L", v12);
sprintf(v19, "%s R", v13);
v14 = *(unsigned __int8 *)(intf + 8);
BYTE1(v14) = 1;
v16[0] = v14;
v15 = *(unsigned __int8 *)(intf + 12);
BYTE1(v15) = 2;
v16[1] = v15;
stream_init_multi(2LL, v17, v16, *(unsigned int *)(Machine + 836LL), 0LL, qsound_update);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 v3; // rax
__int64 v5; // rbx
__int64 v6; // rdi
void *v7; // rdx
double v8; // xmm1_8
double v9; // xmm0_8
double v10; // xmm0_8
const char *v11; // rax
const char *v12; // rdx
const char *v13; // rax
int v14; // eax
int v15; // eax
int v16[2]; // [rsp+8h] [rbp-90h] BYREF
__int64 v17[2]; // [rsp+10h] [rbp-88h] BYREF
char s[40]; // [rsp+20h] [rbp-78h] BYREF
char v19[80]; // [rsp+48h] [rbp-50h] BYREF

if ( !*(_DWORD *)(Machine + 836LL) )
return 0LL;
v3 = *(_QWORD *)(a1 + 8);
v5 = 0LL;
v6 = *(unsigned int *)(v3 + 4);
intf = v3;
qsound_sample_rom = memory_region(v6);
v7 = &qsound_channel;
memset(&qsound_channel, 0, 0x380uLL);
v8 = *(double *)&LC3;
*(float *)&qsound_frq_ratio = (float)((float)((float)*(int *)intf / 166.0) / (float)*(int *)(Machine + 836LL)) * 16.0;
do
{
v9 = (double)(int)v5;
if ( (double)(int)v5 < 0.0 )
{
v10 = sqrt(v9);
v8 = *(double *)&LC3;
}
else
{
v10 = sqrt(v9);
}
qsound_pan_table[v5++] = (int)(v10 * v8);
}
while ( v5 != 33 );
v17[0] = (__int64)s;
v17[1] = (__int64)v19;
v11 = (const char *)sound_name(a1, a2, v7);
sprintf(s, "%s L", v11);
v13 = (const char *)sound_name(a1, "%s L", v12);
sprintf(v19, "%s R", v13);
v14 = *(unsigned __int8 *)(intf + 8);
BYTE1(v14) = 1;
v16[0] = v14;
v15 = *(unsigned __int8 *)(intf + 12);
BYTE1(v15) = 2;
v16[1] = v15;
stream_init_multi(2LL, v17, v16, *(unsigned int *)(Machine + 836LL), 0LL, qsound_update);
return 0LL;
}

original_code:
int qsound_sh_start(const struct MachineSound *msound)
{
 int i;
 if (Machine->sample_rate == 0) return 0;
 intf = (struct QSound_interface*)msound->sound_interface;
 qsound_sample_rom = (QSOUND_SRC_SAMPLE *)memory_region(intf->region);
 memset(qsound_channel, 0, sizeof(qsound_channel));
 qsound_frq_ratio = ((float)intf->clock / (float)166) /
      (float) Machine->sample_rate;
 qsound_frq_ratio *= 16.0;
 for (i=0; i<33; i++)
 {
  qsound_pan_table[i]=(int)((256/sqrt(32)) * sqrt(i));
 }
 {
  char buf[( 2 )][40];
  const char *name[( 2 )];
  int vol[2];
  name[0] = buf[0];
  name[1] = buf[1];
  sprintf( buf[0], "%s L", sound_name(msound) );
  sprintf( buf[1], "%s R", sound_name(msound) );
  vol[0]=((intf->mixing_level[0] & 0xff) | ((1 & 0x03) << 8));
  vol[1]=((intf->mixing_level[1] & 0xff) | ((2 & 0x03) << 8));
  qsound_stream = stream_init_multi(
   ( 2 ),
   name,
   vol,
   Machine->sample_rate,
   0,
   qsound_update );
 }
 return 0;
}

canonical_original_code:
int qsound_sh_start(struct MachineSound *msound)
{
 int i;
 if (Machine->sample_rate == 0) return 0;
 intf = (struct QSound_interface *)msound->sound_interface;
 qsound_sample_rom = (char *)memory_region(intf->region);
 memset(qsound_channel, 0, sizeof(qsound_channel));
 qsound_frq_ratio = ((float)intf->clock / (float)166) /
      (float) Machine->sample_rate;
 qsound_frq_ratio *= 16.0;
 for (i=0; i<33; i++)
 {
  qsound_pan_table[i]=(int)((256/sqrt(32)) * sqrt(i));
 }
 {
  char buf[-1][40];
  char *name[-1];
  int vol[2];
  name[0] = buf[0];
  name[1] = buf[1];
  sprintf( buf[0], "%s L", sound_name(msound) );
  sprintf( buf[1], "%s R", sound_name(msound) );
  vol[0]=((intf->mixing_level[0] & 0xff) | ((1 & 0x03) << 8));
  vol[1]=((intf->mixing_level[1] & 0xff) | ((2 & 0x03) << 8));
  qsound_stream = stream_init_multi(
   ( 2 ),
   name,
   vol,
   Machine->sample_rate,
   0,
   qsound_update );
 }
 return 0;
}

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

variable_types:
name
char *[-1]

variable_types:
vol
int [2]

user_defined_types: struct QSound_interface { int clock; int region; int mixing_level[2]; }


decompiled_code:
void qsound_sh_stop()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void qsound_sh_stop (void)
{
 if (Machine->sample_rate == 0) return;
}

canonical_original_code:
void qsound_sh_stop()
{
 if (Machine->sample_rate == 0) return;
}


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

v2 = a2 << 8;
result = v2 | (unsigned int)(unsigned __int8)qsound_data;
qsound_data = v2 | (unsigned __int8)qsound_data;
return result;
}

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

v2 = a2 << 8;
result = v2 | (unsigned int)(unsigned __int8)qsound_data;
qsound_data = v2 | (unsigned __int8)qsound_data;
return result;
}

original_code:
void qsound_data_h_w(offs_t offset,data_t data)
{
 qsound_data=(qsound_data&0xff)|(data<<8);
}

canonical_original_code:
void qsound_data_h_w(unsigned int offset, unsigned int data)
{
 qsound_data=(qsound_data&0xff)|(data<<8);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

result = a2 | qsound_data & 0xFF00u;
qsound_data = a2 | qsound_data & 0xFF00;
return result;
}

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

result = a2 | qsound_data & 0xFF00u;
qsound_data = a2 | qsound_data & 0xFF00;
return result;
}

original_code:
void qsound_data_l_w(offs_t offset,data_t data)
{
 qsound_data=(qsound_data&0xff00)|data;
}

canonical_original_code:
void qsound_data_l_w(unsigned int offset, unsigned int data)
{
 qsound_data=(qsound_data&0xff00)|data;
}


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

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

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

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


decompiled_code:
void __fastcall qsound_set_command(int a1, int a2)
{
int v2; // eax
unsigned int v3; // edi
unsigned int v4; // eax
__int64 v5; // rdi
_DWORD *v6; // rcx
int v7; // er8
int v8; // eax
char *v9; // rdx
char *v10; // rax

if ( a1 > 127 )
{
if ( a1 <= 143 )
{
v4 = ((_BYTE)a2 - 16) & 0x3F;
v5 = a1 - 128;
if ( v4 > 0x20 )
v4 = 32;
v6 = &qsound_channel[14 * v5];
v6[7] = a2;
v7 = qsound_pan_table[v4];
v8 = qsound_pan_table[32 - v4];
v6[10] = v7;
v6[11] = v8;
}
else
{
v3 = a1 - 186;
if ( v3 <= 0xF )
qsound_channel[14 * v3 + 8] = a2;
}
}
else
{
v2 = a1 >> 3;
switch ( a1 & 7 )
{
case 0:
qsound_channel[14 * (((_BYTE)v2 + 1) & 0xF)] = (a2 << 16) & 0x7F0000;
break;
case 1:
qsound_channel[14 * v2 + 1] = a2;
break;
case 2:
v10 = (char *)&qsound_channel[14 * v2];
*((_DWORD *)v10 + 2) = (int)(float)((float)a2 * *(float *)&qsound_frq_ratio);
if ( !a2 )
*((_DWORD *)v10 + 9) = 0;
break;
case 3:
qsound_channel[14 * v2 + 3] = a2;
break;
case 4:
qsound_channel[14 * v2 + 4] = a2;
break;
case 5:
qsound_channel[14 * v2 + 5] = a2;
break;
case 6:
if ( a2 )
{
v9 = (char *)&qsound_channel[14 * v2];
if ( !*((_DWORD *)v9 + 9) )
{
*((_DWORD *)v9 + 9) = 1;
*((_QWORD *)v9 + 6) = 0LL;
}
}
else
{
qsound_channel[14 * v2 + 9] = 0;
}
qsound_channel[14 * v2 + 6] = a2;
break;
default:
return;
}
}
}

canonical_decompiled_code:
void __fastcall func6(int a1, int a2)
{
int v2; // eax
unsigned int v3; // edi
unsigned int v4; // eax
__int64 v5; // rdi
_DWORD *v6; // rcx
int v7; // er8
int v8; // eax
char *v9; // rdx
char *v10; // rax

if ( a1 > 127 )
{
if ( a1 <= 143 )
{
v4 = ((_BYTE)a2 - 16) & 0x3F;
v5 = a1 - 128;
if ( v4 > 0x20 )
v4 = 32;
v6 = &qsound_channel[14 * v5];
v6[7] = a2;
v7 = qsound_pan_table[v4];
v8 = qsound_pan_table[32 - v4];
v6[10] = v7;
v6[11] = v8;
}
else
{
v3 = a1 - 186;
if ( v3 <= 0xF )
qsound_channel[14 * v3 + 8] = a2;
}
}
else
{
v2 = a1 >> 3;
switch ( a1 & 7 )
{
case 0:
qsound_channel[14 * (((_BYTE)v2 + 1) & 0xF)] = (a2 << 16) & 0x7F0000;
break;
case 1:
qsound_channel[14 * v2 + 1] = a2;
break;
case 2:
v10 = (char *)&qsound_channel[14 * v2];
*((_DWORD *)v10 + 2) = (int)(float)((float)a2 * *(float *)&qsound_frq_ratio);
if ( !a2 )
*((_DWORD *)v10 + 9) = 0;
break;
case 3:
qsound_channel[14 * v2 + 3] = a2;
break;
case 4:
qsound_channel[14 * v2 + 4] = a2;
break;
case 5:
qsound_channel[14 * v2 + 5] = a2;
break;
case 6:
if ( a2 )
{
v9 = (char *)&qsound_channel[14 * v2];
if ( !*((_DWORD *)v9 + 9) )
{
*((_DWORD *)v9 + 9) = 1;
*((_QWORD *)v9 + 6) = 0LL;
}
}
else
{
qsound_channel[14 * v2 + 9] = 0;
}
qsound_channel[14 * v2 + 6] = a2;
break;
default:
return;
}
}
}

original_code:
void qsound_set_command(int data, int value)
{
 int ch=0,reg=0;
 if (data < 0x80)
 {
  ch=data>>3;
  reg=data & 0x07;
 }
 else
 {
  if (data < 0x90)
  {
   ch=data-0x80;
   reg=8;
  }
  else
  {
   if (data >= 0xba && data < 0xca)
   {
    ch=data-0xba;
    reg=9;
   }
   else
   {
    ch=99;
    reg=99;
   }
  }
 }
 switch (reg)
 {
  case 0:
   ch=(ch+1)&0x0f;
   qsound_channel[ch].bank=(value&0x7f)<<16;
   qsound_channel[ch].bank /= 1;
   break;
  case 1:
   qsound_channel[ch].address=value;
   qsound_channel[ch].address/=1;
   break;
  case 2:
   qsound_channel[ch].pitch=(long)
     ((float)value * qsound_frq_ratio );
   qsound_channel[ch].pitch/=1;
   if (!value)
   {
    qsound_channel[ch].key=0;
   }
   break;
  case 3:
   qsound_channel[ch].reg3=value;
   break;
  case 4:
   qsound_channel[ch].loop=value/1;
   break;
  case 5:
   qsound_channel[ch].end=value/1;
   break;
  case 6:
   if (value==0)
   {
    qsound_channel[ch].key=0;
   }
   else if (qsound_channel[ch].key==0)
   {
    qsound_channel[ch].key=1;
    qsound_channel[ch].offset=0;
    qsound_channel[ch].lastdt=0;
   }
   qsound_channel[ch].vol=value;
   break;
  case 7:
   break;
  case 8:
   {
      int pandata=(value-0x10)&0x3f;
      if (pandata > 32)
      {
     pandata=32;
      }
      qsound_channel[ch].lvol=qsound_pan_table[pandata];
      qsound_channel[ch].rvol=qsound_pan_table[32-pandata];
      qsound_channel[ch].pan = value;
   }
   break;
   case 9:
   qsound_channel[ch].reg9=value;
   break;
 }
}

canonical_original_code:
void qsound_set_command(int data, int value)
{
 int ch = 0; int reg = 0;
 if (data < 0x80)
 {
  ch=data>>3;
  reg=data & 0x07;
 }
 else
 {
  if (data < 0x90)
  {
   ch=data-0x80;
   reg=8;
  }
  else
  {
   if (data >= 0xba && data < 0xca)
   {
    ch=data-0xba;
    reg=9;
   }
   else
   {
    ch=99;
    reg=99;
   }
  }
 }
 switch (reg)
 {
  case 0:
   ch=(ch+1)&0x0f;
   qsound_channel[ch].bank=(value&0x7f)<<16;
   qsound_channel[ch].bank /= 1;
   break;
  case 1:
   qsound_channel[ch].address=value;
   qsound_channel[ch].address/=1;
   break;
  case 2:
   qsound_channel[ch].pitch=(long)
     ((float)value * qsound_frq_ratio );
   qsound_channel[ch].pitch/=1;
   if (!value)
   {
    qsound_channel[ch].key=0;
   }
   break;
  case 3:
   qsound_channel[ch].reg3=value;
   break;
  case 4:
   qsound_channel[ch].loop=value/1;
   break;
  case 5:
   qsound_channel[ch].end=value/1;
   break;
  case 6:
   if (value==0)
   {
    qsound_channel[ch].key=0;
   }
   else if (qsound_channel[ch].key==0)
   {
    qsound_channel[ch].key=1;
    qsound_channel[ch].offset=0;
    qsound_channel[ch].lastdt=0;
   }
   qsound_channel[ch].vol=value;
   break;
  case 7:
   break;
  case 8:
   {
      int pandata = (value-0x10)&0x3f;
      if (pandata > 32)
      {
     pandata=32;
      }
      qsound_channel[ch].lvol=qsound_pan_table[pandata];
      qsound_channel[ch].rvol=qsound_pan_table[32-pandata];
      qsound_channel[ch].pan = value;
   }
   break;
   case 9:
   qsound_channel[ch].reg9=value;
   break;
 }
}

variable_types: data int

variable_types: value int

variable_types: ch int

variable_types: reg int

variable_types: pandata int


decompiled_code:
void __fastcall qsound_cmd_w(__int64 a1, int a2)
{
qsound_set_command(a2, qsound_data);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
func6(a2, qsound_data);
}

original_code:
void qsound_cmd_w(offs_t offset,data_t data)
{
 qsound_set_command(data, qsound_data);
}

canonical_original_code:
void qsound_cmd_w(unsigned int offset, unsigned int data)
{
 qsound_set_command(data, qsound_data);
}


decompiled_code:
void __fastcall soundlatch_callback(int a1)
{
latch = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
latch = a1;
}

original_code:
static void soundlatch_callback(int param)
{
 latch = param;
}

variable_types: param int


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

result = (unsigned int)latch;
latch = 0;
return result;
}

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

result = (unsigned int)latch;
latch = 0;
return result;
}

original_code:
data_t bombjack_soundlatch_r(offs_t offset)
{
 int res;
 res = latch;
 latch = 0;
 return res;
}

canonical_original_code:
unsigned int bombjack_soundlatch_r(unsigned int offset)
{
 int res;
 res = latch;
 latch = 0;
 return res;
}

variable_types: res int


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

if ( background_image != a2 )
{
result = memset(dirtybuffer, 1, videoram_size);
background_image = a2;
}
return result;
}

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

if ( background_image != a2 )
{
result = memset(dirtybuffer, 1, videoram_size);
background_image = a2;
}
return result;
}

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

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


decompiled_code:
void *__fastcall bombjack_flipscreen_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

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

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

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


decompiled_code:
void *__fastcall bombjack_vh_screenrefresh(__int64 a1)
{
__int64 v1; // r14
char v2; // cl
int v3; // ebx
__int64 v4; // rbp
int v5; // er11
int v6; // edx
int v7; // eax
__int64 v8; // r12
__int64 v9; // r9
unsigned int v10; // er15
unsigned int v11; // ecx
int v12; // er12
__int64 v13; // rax
void *result; // rax
int v15; // ebx
__int64 v16; // r15
int v17; // esi
unsigned int v18; // eax
__int64 v19; // rdi
unsigned __int8 v20; // cl
__int64 v21; // rdx
__int64 v22; // r8
__int64 v23; // r9
int v24; // esi
unsigned int v25; // [rsp+10h] [rbp-58h]
int v26; // [rsp+14h] [rbp-54h]
int v27; // [rsp+20h] [rbp-48h] BYREF
int v28; // [rsp+24h] [rbp-44h]
int v29; // [rsp+28h] [rbp-40h]
int v30; // [rsp+2Ch] [rbp-3Ch]

v1 = a1;
if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = background_image;
v26 = (background_image & 7) << 9;
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
while ( 1 )
{
v10 = 255;
v6 = v3 & 0x1F;
v11 = v2 & 0x10;
if ( v11 )
{
v12 = ((v3 & 0x1F) >> 1) + v26 + 16 * (v3 >> 6);
v10 = *(unsigned __int8 *)(memory_region(140LL) + v12);
v13 = memory_region(140LL);
v6 = v3 & 0x1F;
v11 = *(unsigned __int8 *)(v13 + v12 + 256);
}
if ( *((_BYTE *)dirtybuffer + v4) )
break;
LABEL_11:
--v3;
--v4;
if ( v3 == -1 )
{
v1 = a1;
goto LABEL_18;
}
v2 = background_image;
}
v5 = v3 >> 5;
if ( flipscreen )
{
v5 = 31 - v5;
v6 = 31 - v6;
v7 = 8 * v6;
v8 = (unsigned int)(8 * v5);
if ( v10 != 255 )
{
v27 = 8 * v6;
v28 = v7 + 7;
v29 = 8 * v5;
v9 = (v11 >> 7) ^ 1;
v30 = v8 + 7;
LABEL_9:
v25 = v7;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
v10,
v11 & 0xF,
(unsigned int)flipscreen,
v9,
(unsigned int)(16 * (v6 >> 1)),
(unsigned int)(16 * (v5 / 2)),
&v27,
0LL,
0LL);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + 16 * (*(_BYTE *)(colorram + v4) & 0x10u),
*(_BYTE *)(colorram + v4) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v25,
v8,
Machine + 776LL,
2LL,
0LL);
LABEL_10:
*((_BYTE *)dirtybuffer + v4) = 0;
goto LABEL_11;
}
}
else
{
v7 = 8 * v6;
v8 = (unsigned int)(8 * v5);
if ( v10 != 255 )
{
v27 = 8 * v6;
v28 = v7 + 7;
v9 = (unsigned __int8)v11 & 0x80;
v29 = 8 * v5;
v30 = v8 + 7;
goto LABEL_9;
}
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + 16 * (*(_BYTE *)(colorram + v4) & 0x10u),
*(_BYTE *)(colorram + v4) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v6),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
goto LABEL_10;
}
LABEL_18:
copybitmap(v1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v15 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v16 = v15 + 3LL;
do
{
v17 = *(unsigned __int8 *)(spriteram + v16 - 1);
v18 = *(char *)(spriteram + v16 - 3);
v19 = *(unsigned __int8 *)(spriteram + v16);
v20 = *(_BYTE *)(spriteram + v16 - 2);
v21 = (unsigned int)(225 - v17);
if ( *(char *)(spriteram + v16 - 3) >= 0 )
v21 = (unsigned int)(241 - v17);
v22 = v20 & 0x40;
v23 = v20 & 0x80;
if ( flipscreen )
{
v24 = 224;
if ( (v20 & 0x20) == 0 )
v24 = 240;
v21 = (unsigned int)(v24 - v21);
v19 = (unsigned int)(v24 - v19);
v22 = (_DWORD)v22 == 0;
v23 = (_DWORD)v23 == 0;
}
v16 -= 4LL;
result = (void *)drawgfx(
v1,
*(_QWORD *)(Machine + 8LL * (int)((v18 >> 31) + 2) + 512),
v18 & 0x7F,
v20 & 0xF,
v22,
v23,
v19,
v21,
Machine + 776LL,
2LL,
0LL);
v15 -= 4;
}
while ( v15 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
__int64 v1; // r14
char v2; // cl
int v3; // ebx
__int64 v4; // rbp
int v5; // er11
int v6; // edx
int v7; // eax
__int64 v8; // r12
__int64 v9; // r9
unsigned int v10; // er15
unsigned int v11; // ecx
int v12; // er12
__int64 v13; // rax
void *result; // rax
int v15; // ebx
__int64 v16; // r15
int v17; // esi
unsigned int v18; // eax
__int64 v19; // rdi
unsigned __int8 v20; // cl
__int64 v21; // rdx
__int64 v22; // r8
__int64 v23; // r9
int v24; // esi
unsigned int v25; // [rsp+10h] [rbp-58h]
int v26; // [rsp+14h] [rbp-54h]
int v27; // [rsp+20h] [rbp-48h] BYREF
int v28; // [rsp+24h] [rbp-44h]
int v29; // [rsp+28h] [rbp-40h]
int v30; // [rsp+2Ch] [rbp-3Ch]

v1 = a1;
if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v2 = background_image;
v26 = (background_image & 7) << 9;
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
while ( 1 )
{
v10 = 255;
v6 = v3 & 0x1F;
v11 = v2 & 0x10;
if ( v11 )
{
v12 = ((v3 & 0x1F) >> 1) + v26 + 16 * (v3 >> 6);
v10 = *(unsigned __int8 *)(memory_region(140LL) + v12);
v13 = memory_region(140LL);
v6 = v3 & 0x1F;
v11 = *(unsigned __int8 *)(v13 + v12 + 256);
}
if ( *((_BYTE *)dirtybuffer + v4) )
break;
LABEL_11:
--v3;
--v4;
if ( v3 == -1 )
{
v1 = a1;
goto LABEL_18;
}
v2 = background_image;
}
v5 = v3 >> 5;
if ( flipscreen )
{
v5 = 31 - v5;
v6 = 31 - v6;
v7 = 8 * v6;
v8 = (unsigned int)(8 * v5);
if ( v10 != 255 )
{
v27 = 8 * v6;
v28 = v7 + 7;
v29 = 8 * v5;
v9 = (v11 >> 7) ^ 1;
v30 = v8 + 7;
LABEL_9:
v25 = v7;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
v10,
v11 & 0xF,
(unsigned int)flipscreen,
v9,
(unsigned int)(16 * (v6 >> 1)),
(unsigned int)(16 * (v5 / 2)),
&v27,
0LL,
0LL);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + 16 * (*(_BYTE *)(colorram + v4) & 0x10u),
*(_BYTE *)(colorram + v4) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v25,
v8,
Machine + 776LL,
2LL,
0LL);
LABEL_10:
*((_BYTE *)dirtybuffer + v4) = 0;
goto LABEL_11;
}
}
else
{
v7 = 8 * v6;
v8 = (unsigned int)(8 * v5);
if ( v10 != 255 )
{
v27 = 8 * v6;
v28 = v7 + 7;
v9 = (unsigned __int8)v11 & 0x80;
v29 = 8 * v5;
v30 = v8 + 7;
goto LABEL_9;
}
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + 16 * (*(_BYTE *)(colorram + v4) & 0x10u),
*(_BYTE *)(colorram + v4) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v6),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
goto LABEL_10;
}
LABEL_18:
copybitmap(v1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v15 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v16 = v15 + 3LL;
do
{
v17 = *(unsigned __int8 *)(spriteram + v16 - 1);
v18 = *(char *)(spriteram + v16 - 3);
v19 = *(unsigned __int8 *)(spriteram + v16);
v20 = *(_BYTE *)(spriteram + v16 - 2);
v21 = (unsigned int)(225 - v17);
if ( *(char *)(spriteram + v16 - 3) >= 0 )
v21 = (unsigned int)(241 - v17);
v22 = v20 & 0x40;
v23 = v20 & 0x80;
if ( flipscreen )
{
v24 = 224;
if ( (v20 & 0x20) == 0 )
v24 = 240;
v21 = (unsigned int)(v24 - v21);
v19 = (unsigned int)(v24 - v19);
v22 = (_DWORD)v22 == 0;
v23 = (_DWORD)v23 == 0;
}
v16 -= 4LL;
result = (void *)drawgfx(
v1,
*(_QWORD *)(Machine + 8LL * (int)((v18 >> 31) + 2) + 512),
v18 & 0x7F,
v20 & 0xF,
v22,
v23,
v19,
v21,
Machine + 776LL,
2LL,
0LL);
v15 -= 4;
}
while ( v15 >= 0 );
}
return result;
}

original_code:
void bombjack_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs,base;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 base = 0x200 * (background_image & 0x07);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  int tilecode,tileattribute;
  sx = offs % 32;
  sy = offs / 32;
  if (background_image & 0x10)
  {
   int bgoffs;
   bgoffs = base+16*(sy/2)+sx/2;
   tilecode = memory_region(REGION_GFX4)[bgoffs],
   tileattribute = memory_region(REGION_GFX4)[bgoffs + 0x100];
  }
  else
  {
   tilecode = 0xff;
   tileattribute = 0;
  }
  if (dirtybuffer[offs])
  {
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   if (tilecode != 0xff)
   {
    struct rectangle clip;
    int flipy;
    clip.min_x = 8*sx;
    clip.max_x = 8*sx+7;
    clip.min_y = 8*sy;
    clip.max_y = 8*sy+7;
    flipy = tileattribute & 0x80;
    if (flipscreen) flipy = !flipy;
    drawgfx(tmpbitmap,Machine->gfx[1],
      tilecode,
      tileattribute & 0x0f,
      flipscreen,flipy,
      16*(sx/2),16*(sy/2),
      &clip,TRANSPARENCY_NONE,0);
    drawgfx(tmpbitmap,Machine->gfx[0],
      videoram[offs] + 16 * (colorram[offs] & 0x10),
      colorram[offs] & 0x0f,
      flipscreen,flipscreen,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
   else
    drawgfx(tmpbitmap,Machine->gfx[0],
      videoram[offs] + 16 * (colorram[offs] & 0x10),
      colorram[offs] & 0x0f,
      flipscreen,flipscreen,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy;
  sx = spriteram[offs+3];
  if (spriteram[offs] & 0x80)
   sy = 225-spriteram[offs+2];
  else
   sy = 241-spriteram[offs+2];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen)
  {
   if (spriteram[offs+1] & 0x20)
   {
    sx = 224 - sx;
    sy = 224 - sy;
   }
   else
   {
    sx = 240 - sx;
    sy = 240 - sy;
   }
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[(spriteram[offs] & 0x80) ? 3 : 2],
    spriteram[offs] & 0x7f,
    spriteram[offs+1] & 0x0f,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void bombjack_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int base;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 base = 0x200 * (background_image & 0x07);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  int tilecode; int tileattribute;
  sx = offs % 32;
  sy = offs / 32;
  if (background_image & 0x10)
  {
   int bgoffs;
   bgoffs = base+16*(sy/2)+sx/2;
   tilecode = memory_region(REGION_GFX4)[bgoffs],
   tileattribute = memory_region(REGION_GFX4)[bgoffs + 0x100];
  }
  else
  {
   tilecode = 0xff;
   tileattribute = 0;
  }
  if (dirtybuffer[offs])
  {
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   if (tilecode != 0xff)
   {
    struct rectangle clip;
    int flipy;
    clip.min_x = 8*sx;
    clip.max_x = 8*sx+7;
    clip.min_y = 8*sy;
    clip.max_y = 8*sy+7;
    flipy = tileattribute & 0x80;
    if (flipscreen) flipy = !flipy;
    drawgfx(tmpbitmap,Machine->gfx[1],
      tilecode,
      tileattribute & 0x0f,
      flipscreen,flipy,
      16*(sx/2),16*(sy/2),
      &clip,TRANSPARENCY_NONE,0);
    drawgfx(tmpbitmap,Machine->gfx[0],
      videoram[offs] + 16 * (colorram[offs] & 0x10),
      colorram[offs] & 0x0f,
      flipscreen,flipscreen,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_PEN,0);
   }
   else
    drawgfx(tmpbitmap,Machine->gfx[0],
      videoram[offs] + 16 * (colorram[offs] & 0x10),
      colorram[offs] & 0x0f,
      flipscreen,flipscreen,
      8*sx,8*sy,
      &Machine->visible_area,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy;
  sx = spriteram[offs+3];
  if (spriteram[offs] & 0x80)
   sy = 225-spriteram[offs+2];
  else
   sy = 241-spriteram[offs+2];
  flipx = spriteram[offs+1] & 0x40;
  flipy = spriteram[offs+1] & 0x80;
  if (flipscreen)
  {
   if (spriteram[offs+1] & 0x20)
   {
    sx = 224 - sx;
    sy = 224 - sy;
   }
   else
   {
    sx = 240 - sx;
    sy = 240 - sy;
   }
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[(spriteram[offs] & 0x80) ? 3 : 2],
    spriteram[offs] & 0x7f,
    spriteram[offs+1] & 0x0f,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: base int

variable_types: sx int

variable_types: sy int

variable_types: tilecode int

variable_types: tileattribute int

variable_types: bgoffs int

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

variable_types: flipy int

variable_types: flipx int


decompiled_code:
__int64 __fastcall bombjack_soundlatch_w(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, soundlatch_callback);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return timer_set(0LL, a2, soundlatch_callback);
}

original_code:
void bombjack_soundlatch_w(offs_t offset,data_t data)
{
 timer_set((0),data,soundlatch_callback);
}

canonical_original_code:
void bombjack_soundlatch_w(unsigned int offset, unsigned int data)
{
 timer_set((0),data,soundlatch_callback);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void __fastcall select_analog_ctrl_w(__int64 a1, int a2)
{
analog_ctrl = a2;
}

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

original_code:
static void select_analog_ctrl_w(offs_t offset,data_t data)
{
 analog_ctrl = data;
}

canonical_original_code:
static void select_analog_ctrl_w(unsigned int offset, unsigned int data)
{
 analog_ctrl = data;
}