original_code:
void exctsccr_mcu_control_w(offs_t offset,data_t data) {
 if ( data == 0xff ) {
  exctsccr_mcu_ram[0x0003] = 0x01;
  exctsccr_mcu_ram[0x0005] = 0x08;
  exctsccr_mcu_ram[0x0380] = 0xf1;
  exctsccr_mcu_ram[0x0381] = 0x01;
  exctsccr_mcu_ram[0x02f8] = 0x1f;
  exctsccr_mcu_ram[0x0009] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x0170], mcu_table1, 16 );
  if ( exctsccr_mcu_ram[0x000d] == 0x01 ) {
   exctsccr_mcu_ram[0x000d] = 0x08;
   memcpy( &exctsccr_mcu_ram[0x01f0], mcu_table2, 16 );
  }
  mcu_sort_list( &exctsccr_mcu_ram[0x03e0], &exctsccr_mcu_ram[0x0300] );
  exctsccr_mcu_ram[0x02fb] = 0x7e;
  exctsccr_mcu_ram[0x02fd] = 0x7e;
  if ( mcu_code_latch ) {
   exctsccr_mcu_ram[0x02f9] = 0x7f;
   exctsccr_mcu_ram[0x02fa] = 0x0d;
   exctsccr_mcu_ram[0x02fc] = 0x05;
   exctsccr_mcu_ram[0x02fe] = 0x01;
  } else {
   exctsccr_mcu_ram[0x02f9] = 0x81;
   exctsccr_mcu_ram[0x02fa] = 0x2d;
   exctsccr_mcu_ram[0x02fc] = 0x25;
   exctsccr_mcu_ram[0x02fe] = 0x09;
  }
  if ( exctsccr_mcu_ram[0x000f] == 0x02 ) {
   exctsccr_mcu_ram[0x000f] = 0x08;
   exctsccr_mcu_ram[0x02f6] = 0xd6;
   exctsccr_mcu_ram[0x02f7] = 0x39;
  }
  if ( exctsccr_mcu_ram[0x0007] == 0x02 ) {
   exctsccr_mcu_ram[0x0007] = 0x08;
   if ( exctsccr_mcu_ram[0x0204] > 3 )
    exctsccr_mcu_ram[0x0204] = 0;
   switch( exctsccr_mcu_ram[0x0204] ) {
    case 0x00:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table4, 16 );
    break;
    case 0x01:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table5, 16 );
    break;
    case 0x02:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table6, 16 );
    break;
    case 0x03:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table7, 16 );
    break;
   }
   if ( exctsccr_mcu_ram[0x0204] != 3 )
    exctsccr_mcu_ram[0x0204]++;
  }
  exctsccr_mcu_ram[0x0011] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x007f], mcu_table8, 16*2 );
 }
}

canonical_original_code:
void exctsccr_mcu_control_w(unsigned int offset, unsigned int data) {
 if ( data == 0xff ) {
  exctsccr_mcu_ram[0x0003] = 0x01;
  exctsccr_mcu_ram[0x0005] = 0x08;
  exctsccr_mcu_ram[0x0380] = 0xf1;
  exctsccr_mcu_ram[0x0381] = 0x01;
  exctsccr_mcu_ram[0x02f8] = 0x1f;
  exctsccr_mcu_ram[0x0009] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x0170], mcu_table1, 16 );
  if ( exctsccr_mcu_ram[0x000d] == 0x01 ) {
   exctsccr_mcu_ram[0x000d] = 0x08;
   memcpy( &exctsccr_mcu_ram[0x01f0], mcu_table2, 16 );
  }
  mcu_sort_list( &exctsccr_mcu_ram[0x03e0], &exctsccr_mcu_ram[0x0300] );
  exctsccr_mcu_ram[0x02fb] = 0x7e;
  exctsccr_mcu_ram[0x02fd] = 0x7e;
  if ( mcu_code_latch ) {
   exctsccr_mcu_ram[0x02f9] = 0x7f;
   exctsccr_mcu_ram[0x02fa] = 0x0d;
   exctsccr_mcu_ram[0x02fc] = 0x05;
   exctsccr_mcu_ram[0x02fe] = 0x01;
  } else {
   exctsccr_mcu_ram[0x02f9] = 0x81;
   exctsccr_mcu_ram[0x02fa] = 0x2d;
   exctsccr_mcu_ram[0x02fc] = 0x25;
   exctsccr_mcu_ram[0x02fe] = 0x09;
  }
  if ( exctsccr_mcu_ram[0x000f] == 0x02 ) {
   exctsccr_mcu_ram[0x000f] = 0x08;
   exctsccr_mcu_ram[0x02f6] = 0xd6;
   exctsccr_mcu_ram[0x02f7] = 0x39;
  }
  if ( exctsccr_mcu_ram[0x0007] == 0x02 ) {
   exctsccr_mcu_ram[0x0007] = 0x08;
   if ( exctsccr_mcu_ram[0x0204] > 3 )
    exctsccr_mcu_ram[0x0204] = 0;
   switch( exctsccr_mcu_ram[0x0204] ) {
    case 0x00:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table4, 16 );
    break;
    case 0x01:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table5, 16 );
    break;
    case 0x02:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table6, 16 );
    break;
    case 0x03:
     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table7, 16 );
    break;
   }
   if ( exctsccr_mcu_ram[0x0204] != 3 )
    exctsccr_mcu_ram[0x0204]++;
  }
  exctsccr_mcu_ram[0x0011] = 0x08;
  memcpy( &exctsccr_mcu_ram[0x007f], mcu_table8, 16*2 );
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

original_code:
void exctsccr_gfx_bank_w(offs_t offset,data_t data) {
 gfx_bank = data & 1;
}

canonical_original_code:
void exctsccr_gfx_bank_w(unsigned int offset, unsigned int data) {
 gfx_bank = data & 1;
}

return_type: void


decompiled_code:
__int64 exctsccr_vh_start()
{
exctsccr_fm_timer = timer_pulse(14316557LL, 0LL, exctsccr_fm_callback);
return generic_vh_start();
}

canonical_decompiled_code:
__int64 func5()
{
exctsccr_fm_timer = timer_pulse(14316557LL, 0LL, exctsccr_fm_callback);
return generic_vh_start();
}

original_code:
int exctsccr_vh_start( void ) {
 exctsccr_fm_timer = timer_pulse( ((1<<30) / ((timer_tm)(75.0))), 0, exctsccr_fm_callback );
 return generic_vh_start();
}

canonical_original_code:
int exctsccr_vh_start() {
 exctsccr_fm_timer = timer_pulse( ((1<<30) / ((timer_tm)(75.0))), 0, exctsccr_fm_callback );
 return generic_vh_start();
}

return_type: int


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

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

original_code:
static void exctsccr_fm_callback( int param ) {
 cpu_cause_interrupt( 1, 0xff );
}

canonical_original_code:
static void exctsccr_fm_callback(int param) {
 cpu_cause_interrupt( 1, 0xff );
}

variable_types: param int


decompiled_code:
__int64 exctsccr_vh_stop()
{
if ( exctsccr_fm_timer )
{
timer_remove();
exctsccr_fm_timer = 0LL;
}
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func7()
{
if ( exctsccr_fm_timer )
{
timer_remove();
exctsccr_fm_timer = 0LL;
}
return generic_vh_stop();
}

original_code:
void exctsccr_vh_stop( void ) {
 if ( exctsccr_fm_timer ) {
  timer_remove( exctsccr_fm_timer );
  exctsccr_fm_timer = 0;
 }
 generic_vh_stop();
}

canonical_original_code:
void exctsccr_vh_stop() {
 if ( exctsccr_fm_timer ) {
  timer_remove( exctsccr_fm_timer );
  exctsccr_fm_timer = 0;
 }
 generic_vh_stop();
}


original_code:
static void exctsccr_drawsprites( struct osd_bitmap *bitmap ) {
 int offs;
 unsigned char *OBJ1, *OBJ2;
 OBJ1 = videoram;
 OBJ2 = &(spriteram[0x20]);
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx,sy,code,bank,flipx,flipy,color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 2;
  bank += ( ( OBJ1[offs+1] >> 4 ) & 1 );
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
 }
 OBJ1 = &(memory_region(REGION_CPU1)[0x8800]);
 OBJ2 = spriteram;
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx,sy,code,bank,flipx,flipy,color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 3;
  if ( color == 0 )
   continue;
  if ( color < 0x10 )
   bank++;
  if ( color > 0x10 && color < 0x17 )
  {
   drawgfx(bitmap,Machine->gfx[4],
    code,
    0x0e,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   color += 6;
  }
  if ( color==0x1d && gfx_bank==1 )
  {
   drawgfx(bitmap,Machine->gfx[3],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[4],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_COLOR, 16);
  } else
  {
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
static void exctsccr_drawsprites(struct osd_bitmap *bitmap) {
 int offs;
 unsigned char *OBJ1; unsigned char *OBJ2;
 OBJ1 = videoram;
 OBJ2 = &(spriteram[0x20]);
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx; int sy; int code; int bank; int flipx; int flipy; int color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 2;
  bank += ( ( OBJ1[offs+1] >> 4 ) & 1 );
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
 }
 OBJ1 = &(memory_region(REGION_CPU1)[0x8800]);
 OBJ2 = spriteram;
 for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
  int sx; int sy; int code; int bank; int flipx; int flipy; int color;
  sx = 256 - OBJ2[offs+1];
  sy = OBJ2[offs] - 16;
  code = ( OBJ1[offs] >> 2 ) & 0x3f;
  flipx = ( OBJ1[offs] ) & 0x01;
  flipy = ( OBJ1[offs] ) & 0x02;
  color = ( OBJ1[offs+1] ) & 0x1f;
  bank = 3;
  if ( color == 0 )
   continue;
  if ( color < 0x10 )
   bank++;
  if ( color > 0x10 && color < 0x17 )
  {
   drawgfx(bitmap,Machine->gfx[4],
    code,
    0x0e,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   color += 6;
  }
  if ( color==0x1d && gfx_bank==1 )
  {
   drawgfx(bitmap,Machine->gfx[3],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,0);
   drawgfx(bitmap,Machine->gfx[4],
    code,
    color,
    flipx, flipy,
    sx,sy,
    &Machine->visible_area,
    TRANSPARENCY_COLOR, 16);
  } else
  {
  drawgfx(bitmap,Machine->gfx[bank],
    code,
    color,
    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: sx int

variable_types: sy int

variable_types: code int

variable_types: bank int

variable_types: flipx int

variable_types: flipy int

variable_types: color int


decompiled_code:
__int64 __fastcall exctsccr_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( videoram_size != 16LL )
{
v1 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v1) )
{
*(_BYTE *)(dirtybuffer + v1) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + v1),
*(_BYTE *)(colorram + v1) & 0x1F,
0LL,
0LL,
(unsigned int)(8 * ((int)v1 % 32)),
(unsigned int)(8 * ((int)v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
++v1;
}
while ( videoram_size - 16LL > v1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return exctsccr_drawsprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( videoram_size != 16LL )
{
v1 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v1) )
{
*(_BYTE *)(dirtybuffer + v1) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + v1),
*(_BYTE *)(colorram + v1) & 0x1F,
0LL,
0LL,
(unsigned int)(8 * ((int)v1 % 32)),
(unsigned int)(8 * ((int)v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
++v1;
}
while ( videoram_size - 16LL > v1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
return func8(a1);
}

original_code:
void exctsccr_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ) {
 int offs;
 for (offs = 0;offs < ( videoram_size - 0x10 );offs++) {
  if ( dirtybuffer[offs] ) {
   int sx,sy,code;
   dirtybuffer[offs] = 0;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   code = videoram[offs];
   drawgfx(tmpbitmap,Machine->gfx[gfx_bank],
     code,
     ( colorram[offs] ) & 0x1f,
     0, 0,
     sx,sy,
     &Machine->visible_area,
     TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 exctsccr_drawsprites( bitmap );
}

canonical_original_code:
void exctsccr_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh) {
 int offs;
 for (offs = 0;offs < ( videoram_size - 0x10 );offs++) {
  if ( dirtybuffer[offs] ) {
   int sx; int sy; int code;
   dirtybuffer[offs] = 0;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   code = videoram[offs];
   drawgfx(tmpbitmap,Machine->gfx[gfx_bank],
     code,
     ( colorram[offs] ) & 0x1f,
     0, 0,
     sx,sy,
     &Machine->visible_area,
     TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 exctsccr_drawsprites( bitmap );
}

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


decompiled_code:
__int64 __fastcall exctsccr_DAC_data_w(__int64 a1, int a2)
{
return DAC_signed_data_w(a1, (unsigned int)(4 * a2));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
return DAC_signed_data_w(a1, (unsigned int)(4 * a2));
}

original_code:
void exctsccr_DAC_data_w(offs_t offset,data_t data)
{
 DAC_signed_data_w(offset,data << 2);
}

canonical_original_code:
void exctsccr_DAC_data_w(unsigned int offset, unsigned int data)
{
 DAC_signed_data_w(offset,data << 2);
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
__int64 goindol_vh_stop()
{
free(fg_dirtybuffer);
free(bg_dirtybuffer);
bitmap_free(bitmap_fg);
return bitmap_free(bitmap_bg);
}

canonical_decompiled_code:
__int64 func3()
{
free(fg_dirtybuffer);
free(bg_dirtybuffer);
bitmap_free(bitmap_fg);
return bitmap_free(bitmap_bg);
}

original_code:
void goindol_vh_stop(void)
{
 free(fg_dirtybuffer);
 free(bg_dirtybuffer);
 bitmap_free(bitmap_fg);
 bitmap_free(bitmap_bg);
}

canonical_original_code:
void goindol_vh_stop()
{
 free(fg_dirtybuffer);
 free(bg_dirtybuffer);
 bitmap_free(bitmap_fg);
 bitmap_free(bitmap_bg);
}


decompiled_code:
__int64 goindol_vh_start()
{
_QWORD *v0; // rcx
_QWORD *v1; // rcx
__int64 result; // rax

fg_dirtybuffer = malloc(0x400uLL);
if ( !fg_dirtybuffer )
return 1LL;
bg_dirtybuffer = malloc(0x400uLL);
if ( !bg_dirtybuffer )
return 1LL;
bitmap_fg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_fg )
{
bitmap_bg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_bg )
{
v0 = fg_dirtybuffer;
*(_QWORD *)fg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1024) >> 3));
v1 = bg_dirtybuffer;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v1[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
result = 0LL;
}
else
{
bitmap_free(bitmap_fg);
free(fg_dirtybuffer);
free(bg_dirtybuffer);
result = 1LL;
}
}
else
{
free(fg_dirtybuffer);
free(bg_dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
_QWORD *v0; // rcx
_QWORD *v1; // rcx
__int64 result; // rax

fg_dirtybuffer = malloc(0x400uLL);
if ( !fg_dirtybuffer )
return 1LL;
bg_dirtybuffer = malloc(0x400uLL);
if ( !bg_dirtybuffer )
return 1LL;
bitmap_fg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_fg )
{
bitmap_bg = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_bg )
{
v0 = fg_dirtybuffer;
*(_QWORD *)fg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1024) >> 3));
v1 = bg_dirtybuffer;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v1[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
result = 0LL;
}
else
{
bitmap_free(bitmap_fg);
free(fg_dirtybuffer);
free(bg_dirtybuffer);
result = 1LL;
}
}
else
{
free(fg_dirtybuffer);
free(bg_dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
int goindol_vh_start(void)
{
        if ((fg_dirtybuffer = (unsigned char*)malloc(32*32)) == 0)
 {
         return 1;
 }
        if ((bg_dirtybuffer = (unsigned char*)malloc(32*32)) == 0)
 {
  free(bg_dirtybuffer);
         return 1;
 }
 if ((bitmap_fg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(bitmap_fg);
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
        memset(fg_dirtybuffer,1,32*32);
        memset(bg_dirtybuffer,1,32*32);
        return 0;
}

canonical_original_code:
int goindol_vh_start()
{
        if ((fg_dirtybuffer = (unsigned char *)malloc(32*32)) == 0)
 {
         return 1;
 }
        if ((bg_dirtybuffer = (unsigned char *)malloc(32*32)) == 0)
 {
  free(bg_dirtybuffer);
         return 1;
 }
 if ((bitmap_fg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(bitmap_fg);
  free(fg_dirtybuffer);
  free(bg_dirtybuffer);
  return 1;
 }
        memset(fg_dirtybuffer,1,32*32);
        memset(bg_dirtybuffer,1,32*32);
        return 0;
}


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

result = (_BYTE *)memory_region(129LL);
result[8588] = 0;
result[8589] = 0;
result[8590] = 0;
return result;
}

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

result = (_BYTE *)memory_region(129LL);
result[8588] = 0;
result[8589] = 0;
result[8590] = 0;
return result;
}

original_code:
void init_homo(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0x218c] = 0x00;
 rom[0x218d] = 0x00;
 rom[0x218e] = 0x00;
}

canonical_original_code:
void init_homo()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0x218c] = 0x00;
 rom[0x218d] = 0x00;
 rom[0x218e] = 0x00;
}

variable_types:
rom
unsigned char *


decompiled_code:
__int64 __fastcall meadows_char_dirty(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx

for ( result = 0LL; result != 16; result += 4LL )
{
v3 = *(_DWORD *)((char *)&sprite_horz + result);
if ( a1 + 7 < v3 || v3 + 15 < a1 )
{
v4 = *(_DWORD *)((char *)&sprite_vert + result);
if ( a2 + 7 < v4 || v4 + 15 < a2 )
continue;
}
*(_DWORD *)((char *)&sprite_dirty + result) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx

for ( result = 0LL; result != 16; result += 4LL )
{
v3 = *(_DWORD *)((char *)&sprite_horz + result);
if ( a1 + 7 < v3 || v3 + 15 < a1 )
{
v4 = *(_DWORD *)((char *)&sprite_vert + result);
if ( a2 + 7 < v4 || v4 + 15 < a2 )
continue;
}
*(_DWORD *)((char *)&sprite_dirty + result) = 1;
}
return result;
}

original_code:
static void meadows_char_dirty(int x, int y)
{
int i;
 for (i = 0; i < 4; i++)
 {
  if ((x + 7 >= sprite_horz[i] && x <= sprite_horz[i] + 15) ||
   (y + 7 >= sprite_vert[i] && y <= sprite_vert[i] + 15))
    sprite_dirty[i] = 1;
 }
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall dirty_sprite(int a1)
{
int v1; // eax
int v2; // ecx
int v3; // edx
int v4; // eax
__int64 result; // rax
int i; // er9
int v7; // eax
int v8; // edx
int v9; // eax
unsigned int v10; // ecx
int v11; // eax
int v12; // edx
int v13; // eax
int v14; // eax
int v15; // er8
int v16; // edx
int v17; // eax

sprite_dirty[a1] = 1;
v1 = sprite_vert[a1];
v2 = v1 + 7;
v3 = v1 / 8;
v4 = v1 + 14;
if ( v2 >= 0 )
v4 = v2;
result = (unsigned int)((v4 >> 3) + 1);
if ( v3 <= (int)result )
{
for ( i = v3; ; ++i )
{
v14 = sprite_horz[a1];
v15 = v14 + 7;
v16 = v14 / 8;
v10 = v14 / 8;
v17 = v14 + 14;
if ( v15 >= 0 )
v17 = v15;
if ( v16 <= (v17 >> 3) + 1 )
{
while ( 1 )
{
if ( (unsigned int)i <= 0x1D && v10 <= 0x1F )
*(_BYTE *)(dirtybuffer + (int)(32 * i + v10)) = 1;
v7 = sprite_horz[a1];
v8 = v7 + 14;
v9 = v7 + 7;
if ( v9 < 0 )
v9 = v8;
if ( v9 >> 3 < (int)v10 )
break;
++v10;
}
}
v11 = sprite_vert[a1];
v12 = v11 + 14;
v13 = v11 + 7;
if ( v13 < 0 )
v13 = v12;
result = (unsigned int)(v13 >> 3);
if ( (int)result < i )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
int v2; // ecx
int v3; // edx
int v4; // eax
__int64 result; // rax
int i; // er9
int v7; // eax
int v8; // edx
int v9; // eax
unsigned int v10; // ecx
int v11; // eax
int v12; // edx
int v13; // eax
int v14; // eax
int v15; // er8
int v16; // edx
int v17; // eax

sprite_dirty[a1] = 1;
v1 = sprite_vert[a1];
v2 = v1 + 7;
v3 = v1 / 8;
v4 = v1 + 14;
if ( v2 >= 0 )
v4 = v2;
result = (unsigned int)((v4 >> 3) + 1);
if ( v3 <= (int)result )
{
for ( i = v3; ; ++i )
{
v14 = sprite_horz[a1];
v15 = v14 + 7;
v16 = v14 / 8;
v10 = v14 / 8;
v17 = v14 + 14;
if ( v15 >= 0 )
v17 = v15;
if ( v16 <= (v17 >> 3) + 1 )
{
while ( 1 )
{
if ( (unsigned int)i <= 0x1D && v10 <= 0x1F )
*(_BYTE *)(dirtybuffer + (int)(32 * i + v10)) = 1;
v7 = sprite_horz[a1];
v8 = v7 + 14;
v9 = v7 + 7;
if ( v9 < 0 )
v9 = v8;
if ( v9 >> 3 < (int)v10 )
break;
++v10;
}
}
v11 = sprite_vert[a1];
v12 = v11 + 14;
v13 = v11 + 7;
if ( v13 < 0 )
v13 = v12;
result = (unsigned int)(v13 >> 3);
if ( (int)result < i )
break;
}
}
return result;
}

original_code:
static void dirty_sprite(int n)
{
int x, y;
 sprite_dirty[n] = 1;
 for (y = sprite_vert[n] / 8;
   y < (sprite_vert[n] + 8 - 1) / 8 + 16 / 8 ;
   y++)
 {
  for (x = sprite_horz[n] / 8;
    x < (sprite_horz[n] + 8 - 1) / 8 + 16 / 8;
    x++)
  {
   if (y >= 0 && y < 30 && x >= 0 && x < 32)
    dirtybuffer[y * 32 + x] = 1;
  }
 }
}

canonical_original_code:
static void dirty_sprite(int n)
{
int x; int y;
 sprite_dirty[n] = 1;
 for (y = sprite_vert[n] / 8;
   y < (sprite_vert[n] + 8 - 1) / 8 + 16 / 8 ;
   y++)
 {
  for (x = sprite_horz[n] / 8;
    x < (sprite_horz[n] + 8 - 1) / 8 + 16 / 8;
    x++)
  {
   if (y >= 0 && y < 30 && x >= 0 && x < 32)
    dirtybuffer[y * 32 + x] = 1;
  }
 }
}

variable_types: n int


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

if ( !a1 )
{
result = (void *)meadows_0c00;
if ( meadows_0c00 != a2 )
{
result = &meadows_0c00;
meadows_0c00 = a2;
}
}
return result;
}

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

if ( !a1 )
{
result = (void *)meadows_0c00;
if ( meadows_0c00 != a2 )
{
result = &meadows_0c00;
meadows_0c00 = a2;
}
}
return result;
}

original_code:
void meadows_hardware_w(offs_t offset,data_t data)
{
 switch( offset ) {
  case 0:
   if (meadows_0c00 == data)
    break;
   meadows_0c00 = data;
            break;
  case 1:
            break;
        case 2:
            break;
  case 3:
   break;
 }
}

canonical_original_code:
void meadows_hardware_w(unsigned int offset, unsigned int data)
{
 switch( offset ) {
  case 0:
   if (meadows_0c00 == data)
    break;
   meadows_0c00 = data;
            break;
  case 1:
            break;
        case 2:
            break;
  case 3:
   break;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

result = 0LL;
if ( !a1 )
result = meadows_0c00;
return result;
}

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

result = 0LL;
if ( !a1 )
result = meadows_0c00;
return result;
}

original_code:
static data_t sound_hardware_r(offs_t offset)
{
 int data = 0;
 switch( offset ) {
  case 0:
   data = meadows_0c00;
            break;
  case 1: break;
  case 2: break;
  case 3: break;
 }
    return data;
}

canonical_original_code:
static unsigned int sound_hardware_r(unsigned int offset)
{
 int data = 0;
 switch( offset ) {
  case 0:
   data = meadows_0c00;
            break;
  case 1: break;
  case 2: break;
  case 3: break;
 }
    return data;
}

variable_types: data int

return_type: unsigned int


decompiled_code:
__int64 meadows_sh_start()
{
int v1[4]; // [rsp+8h] [rbp-10h] BYREF

v1[1] = 255;
v1[0] = 255;
channel = mixer_allocate_channels(2LL, v1);
mixer_set_volume((unsigned int)channel, 0LL);
mixer_play_sample((unsigned int)channel, &waveform, 2LL, (unsigned int)freq1, 1LL);
mixer_set_volume((unsigned int)(channel + 1), 0LL);
mixer_play_sample((unsigned int)(channel + 1), &waveform, 2LL, (unsigned int)freq2, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v1[4]; // [rsp+8h] [rbp-10h] BYREF

v1[1] = 255;
v1[0] = 255;
channel = mixer_allocate_channels(2LL, v1);
mixer_set_volume((unsigned int)channel, 0LL);
mixer_play_sample((unsigned int)channel, &waveform, 2LL, (unsigned int)freq1, 1LL);
mixer_set_volume((unsigned int)(channel + 1), 0LL);
mixer_play_sample((unsigned int)(channel + 1), &waveform, 2LL, (unsigned int)freq2, 1LL);
return 0LL;
}

original_code:
int meadows_sh_start(const struct MachineSound *msound)
{
 int vol[2];
 vol[0]=vol[1]=255;
 channel = mixer_allocate_channels(2,vol);
 mixer_set_volume(channel,0);
 mixer_play_sample(channel,waveform,sizeof(waveform),freq1,1);
 mixer_set_volume(channel+1,0);
 mixer_play_sample(channel+1,waveform,sizeof(waveform),freq2,1);
    return 0;
}

canonical_original_code:
int meadows_sh_start(struct MachineSound *msound)
{
 int vol[2];
 vol[0]=vol[1]=255;
 channel = mixer_allocate_channels(2,vol);
 mixer_set_volume(channel,0);
 mixer_play_sample(channel,waveform,sizeof(waveform),freq1,1);
 mixer_set_volume(channel+1,0);
 mixer_play_sample(channel+1,waveform,sizeof(waveform),freq2,1);
    return 0;
}

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

variable_types:
vol
int [2]


decompiled_code:
__int64 meadows_sh_stop()
{
mixer_stop_sample((unsigned int)channel);
return mixer_stop_sample((unsigned int)(channel + 1));
}

canonical_decompiled_code:
__int64 func6()
{
mixer_stop_sample((unsigned int)channel);
return mixer_stop_sample((unsigned int)(channel + 1));
}

original_code:
void meadows_sh_stop(void)
{
 mixer_stop_sample(channel);
    mixer_stop_sample(channel+1);
}

canonical_original_code:
void meadows_sh_stop()
{
 mixer_stop_sample(channel);
    mixer_stop_sample(channel+1);
}


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

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&deadeye_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

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

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&deadeye_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int deadeye_vh_start(void)
{
 if( generic_vh_start() ) return 1;
 overlay_create(deadeye_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}

canonical_original_code:
int deadeye_vh_start()
{
 if( generic_vh_start() ) return 1;
 overlay_create(deadeye_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}


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

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&gypsyjug_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

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

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&gypsyjug_artwork, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int gypsyjug_vh_start(void)
{
 if( generic_vh_start() ) return 1;
 overlay_create(gypsyjug_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}

canonical_original_code:
int gypsyjug_vh_start()
{
 if( generic_vh_start() ) return 1;
 overlay_create(gypsyjug_artwork, 2, Machine->drv->total_colors - 2);
    return 0;
}


decompiled_code:
__int64 __fastcall meadows_draw_sprites(__int64 a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 1LL; i != 5; ++i )
{
if ( dword_110CC[i] )
{
dword_110CC[i] = 0;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (int)i + 512),
dword_1109C[i] & 0xF,
1LL,
(unsigned int)(dword_1109C[i] >> 5),
0LL,
dword_110BC[i],
dword_110AC[i],
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

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

for ( i = 1LL; i != 5; ++i )
{
if ( dword_110CC[i] )
{
dword_110CC[i] = 0;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (int)i + 512),
dword_1109C[i] & 0xF,
1LL,
(unsigned int)(dword_1109C[i] >> 5),
0LL,
dword_110BC[i],
dword_110AC[i],
Machine + 776LL,
2LL,
0LL);
}
}
return result;
}

original_code:
static void meadows_draw_sprites(struct osd_bitmap *bitmap)
{
 int i;
 for( i = 0; i < 4; i++ ) {
  int x, y, n, p, f;
  if (!sprite_dirty[i])
   continue;
  sprite_dirty[i] = 0;
  x = sprite_horz[i];
  y = sprite_vert[i];
  n = sprite_index[i] & 0x0f;
  p = i;
  f = sprite_index[i] >> 5;
  drawgfx(bitmap, Machine->gfx[p + 1],
   n, 1, f, 0, x, y,
   &Machine->visible_area,
   TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void meadows_draw_sprites(struct osd_bitmap *bitmap)
{
 int i;
 for( i = 0; i < 4; i++ ) {
  int x; int y; int n; int p; int f;
  if (!sprite_dirty[i])
   continue;
  sprite_dirty[i] = 0;
  x = sprite_horz[i];
  y = sprite_vert[i];
  n = sprite_index[i] & 0x0f;
  p = i;
  f = sprite_index[i] >> 5;
  drawgfx(bitmap, Machine->gfx[p + 1],
   n, 1, f, 0, x, y,
   &Machine->visible_area,
   TRANSPARENCY_PEN,0);
 }
}

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

variable_types: p int

variable_types: f int


decompiled_code:
__int64 __fastcall meadows_vh_screenrefresh(__int64 a1, int a2)
{
__int64 v2; // rax
_QWORD *v3; // rdx
__int64 i; // rbx
__int64 v5; // r12

v2 = palette_recalc();
if ( a2 || v2 )
{
v3 = dirtybuffer;
*dirtybuffer = 0x101010101010101LL;
v3[119] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 960) >> 3));
}
for ( i = 0LL; i != 960; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
*((_BYTE *)dirtybuffer + i) = 0;
v5 = (unsigned int)(8 * ((int)i / 32));
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + i) & 0x7F,
1LL,
0LL,
0LL,
(unsigned int)(8 * ((int)i % 32)),
v5,
Machine + 776LL,
0LL,
0LL);
meadows_char_dirty(8 * ((int)i % 32), v5);
}
}
return meadows_draw_sprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 v2; // rax
_QWORD *v3; // rdx
__int64 i; // rbx
__int64 v5; // r12

v2 = palette_recalc();
if ( a2 || v2 )
{
v3 = dirtybuffer;
*dirtybuffer = 0x101010101010101LL;
v3[119] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 960) >> 3));
}
for ( i = 0LL; i != 960; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
*((_BYTE *)dirtybuffer + i) = 0;
v5 = (unsigned int)(8 * ((int)i / 32));
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + i) & 0x7F,
1LL,
0LL,
0LL,
(unsigned int)(8 * ((int)i % 32)),
v5,
Machine + 776LL,
0LL,
0LL);
func0(8 * ((int)i % 32), v5);
}
}
return func9(a1);
}

original_code:
void meadows_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,30 * 32);
 }
 for (i = 0; i < 30 * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int x, y;
            dirtybuffer[i] = 0;
   x = (i % 32) * 8;
   y = (i / 32) * 8;
   drawgfx(bitmap, Machine->gfx[0],
    videoram[i] & 0x7f, 1, 0,0, x, y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0);
   meadows_char_dirty(x,y);
  }
 }
 meadows_draw_sprites(bitmap);
}

canonical_original_code:
void meadows_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,30 * 32);
 }
 for (i = 0; i < 30 * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int x; int y;
            dirtybuffer[i] = 0;
   x = (i % 32) * 8;
   y = (i / 32) * 8;
   drawgfx(bitmap, Machine->gfx[0],
    videoram[i] & 0x7f, 1, 0,0, x, y,
    &Machine->visible_area,
    TRANSPARENCY_NONE,0);
   meadows_char_dirty(x,y);
  }
 }
 meadows_draw_sprites(bitmap);
}


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

if ( a1 == 2 )
return flip_bits[(unsigned __int8)(cycles_currently_ran() - cycles_at_vsync)];
if ( a1 > 2 )
{
result = 0LL;
if ( a1 == 3 )
result = input_port_2_r(0LL);
}
else if ( a1 )
{
result = input_port_1_r(0LL);
}
else
{
result = input_port_0_r(0LL);
}
return result;
}

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

if ( a1 == 2 )
return flip_bits[(unsigned __int8)(cycles_currently_ran() - cycles_at_vsync)];
if ( a1 > 2 )
{
result = 0LL;
if ( a1 == 3 )
result = input_port_2_r(0LL);
}
else if ( a1 )
{
result = input_port_1_r(0LL);
}
else
{
result = input_port_0_r(0LL);
}
return result;
}

original_code:
data_t meadows_hardware_r(offs_t offset)
{
 switch( offset ) {
        case 0:
            return input_port_0_r(0);
        case 1:
            return input_port_1_r(0);
        case 2:
   return flip_bits[(cycles_currently_ran() - cycles_at_vsync) & 0xff];
        case 3:
            return input_port_2_r(0);
    }
    return 0;
}

canonical_original_code:
unsigned int meadows_hardware_r(unsigned int offset)
{
 switch( offset ) {
        case 0:
            return input_port_0_r(0);
        case 1:
            return input_port_1_r(0);
        case 2:
   return flip_bits[(cycles_currently_ran() - cycles_at_vsync) & 0xff];
        case 3:
            return input_port_2_r(0);
    }
    return 0;
}


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

cycles_at_vsync = cycles_currently_ran();
v0 = sense_state_3;
sense_state_3 ^= 1u;
cpu_set_irq_line(0LL, 1LL, v0 != 1);
if ( (input_port_3_r(0LL) & 1) != 0 && !coin1_state_2 )
{
coin1_state_2 = 1;
cpu_irq_line_vector_w(0LL, 0LL, 130LL);
cpu_set_irq_line(0LL, 0LL, 3LL);
}
coin1_state_2 = 0;
return ignore_interrupt();
}

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

cycles_at_vsync = cycles_currently_ran();
v0 = sense_state_3;
sense_state_3 ^= 1u;
cpu_set_irq_line(0LL, 1LL, v0 != 1);
if ( (input_port_3_r(0LL) & 1) != 0 && !coin1_state_2 )
{
coin1_state_2 = 1;
cpu_irq_line_vector_w(0LL, 0LL, 130LL);
cpu_set_irq_line(0LL, 0LL, 3LL);
}
coin1_state_2 = 0;
return ignore_interrupt();
}

original_code:
int meadows_interrupt(void)
{
static int sense_state = 0;
static int coin1_state = 0;
    cycles_at_vsync = cycles_currently_ran();
 sense_state ^= 1;
 cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0);
 if( input_port_3_r(0) & 0x01 ) {
  if( !coin1_state ) {
   coin1_state = 1;
   cpu_irq_line_vector_w(0,0,0x82);
   cpu_set_irq_line(0,0,3);
  }
 }
 coin1_state = 0;
 return ignore_interrupt();
}

canonical_original_code:
int meadows_interrupt()
{
static int sense_state = 0;
static int coin1_state = 0;
    cycles_at_vsync = cycles_currently_ran();
 sense_state ^= 1;
 cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0);
 if( input_port_3_r(0) & 0x01 ) {
  if( !coin1_state ) {
   coin1_state = 1;
   cpu_irq_line_vector_w(0,0,0x82);
   cpu_set_irq_line(0,0,3);
  }
 }
 coin1_state = 0;
 return ignore_interrupt();
}


decompiled_code:
__int64 init_gypsyjug()
{
int v0; // ebx
const void *v1; // rbp
void *v2; // rax
__int64 i; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v0 = memory_region_length(139LL);
v1 = (const void *)memory_region(138LL);
v2 = (void *)memory_region(139LL);
memcpy(v2, v1, v0);
for ( i = 0LL; ; i += 32LL )
{
result = memory_region_length(140LL);
if ( (int)result <= (int)i )
break;
v4 = memory_region(140LL);
*(_QWORD *)(v4 + i) = 0LL;
*(_QWORD *)(v4 + i + 8) = 0LL;
*(_QWORD *)(v4 + i + 16) = 0LL;
*(_QWORD *)(v4 + i + 24) = 0x8001C003C0038001LL;
v5 = memory_region(141LL);
*(_QWORD *)(v5 + i) = 0LL;
*(_QWORD *)(v5 + i + 8) = 0LL;
*(_QWORD *)(v5 + i + 16) = 0LL;
*(_QWORD *)(v5 + i + 24) = 0x8001C003C0038001LL;
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
int v0; // ebx
const void *v1; // rbp
void *v2; // rax
__int64 i; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 result; // rax

v0 = memory_region_length(139LL);
v1 = (const void *)memory_region(138LL);
v2 = (void *)memory_region(139LL);
memcpy(v2, v1, v0);
for ( i = 0LL; ; i += 32LL )
{
result = memory_region_length(140LL);
if ( (int)result <= (int)i )
break;
v4 = memory_region(140LL);
*(_QWORD *)(v4 + i) = 0LL;
*(_QWORD *)(v4 + i + 8) = 0LL;
*(_QWORD *)(v4 + i + 16) = 0LL;
*(_QWORD *)(v4 + i + 24) = 0x8001C003C0038001LL;
v5 = memory_region(141LL);
*(_QWORD *)(v5 + i) = 0LL;
*(_QWORD *)(v5 + i + 8) = 0LL;
*(_QWORD *)(v5 + i + 16) = 0LL;
*(_QWORD *)(v5 + i + 24) = 0x8001C003C0038001LL;
}
return result;
}

original_code:
static void init_gypsyjug(void)
{
int i;
static unsigned char ball[16*2] = {
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x01,0x80, 0x03,0xc0, 0x03,0xc0, 0x01,0x80};
 memcpy(memory_region(REGION_GFX3),memory_region(REGION_GFX2),memory_region_length(REGION_GFX3));
 for (i = 0; i < memory_region_length(REGION_GFX4); i += 16*2)
 {
  memcpy(memory_region(REGION_GFX4) + i, ball, sizeof(ball));
  memcpy(memory_region(REGION_GFX5) + i, ball, sizeof(ball));
 }
}

canonical_original_code:
static void init_gypsyjug()
{
int i;
static unsigned char ball[-1] = {
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
 0x01,0x80, 0x03,0xc0, 0x03,0xc0, 0x01,0x80};
 memcpy(memory_region(REGION_GFX3),memory_region(REGION_GFX2),memory_region_length(REGION_GFX3));
 for (i = 0; i < memory_region_length(REGION_GFX4); i += 16*2)
 {
  memcpy(memory_region(REGION_GFX4) + i, ball, sizeof(ball));
  memcpy(memory_region(REGION_GFX5) + i, ball, sizeof(ball));
 }
}

variable_types:
ball
unsigned char [-1]


decompiled_code:
__int64 meadows_sh_update()
{
int v0; // ebp
__int64 v1; // rdx
int v2; // ebx
int v3; // ebx
unsigned __int64 v4; // rdx
char v5; // bl
int v6; // ebx
int v7; // ebx
int v8; // eax
__int64 result; // rax

if ( latched_0c01_6 == meadows_0c01 )
{
v4 = (unsigned __int64)&meadows_0c03;
if ( latched_0c03_5 == meadows_0c03 )
{
v5 = meadows_0c02;
if ( latched_0c02_4 == meadows_0c02 )
goto LABEL_16;
goto LABEL_9;
}
}
v0 = 0;
if ( (meadows_0c03 & 8) != 0 )
v0 = (meadows_0c01 >> 1) & 0x78;
v1 = (unsigned int)s2650_get_flag();
if ( (_DWORD)v1 )
v0 += 128;
v2 = ~meadows_0c01 & 0xF;
if ( (~meadows_0c01 & 0xF) != 0 )
{
v3 = v2 + 1;
v1 = (unsigned int)(19531 % v3);
freq1 = 19531 / v3;
v2 = v0;
}
mixer_set_sample_frequency((unsigned int)channel, (unsigned int)(2 * freq1), v1);
mixer_set_volume((unsigned int)channel, (unsigned int)(100 * v2 / 255));
v5 = meadows_0c02;
if ( latched_0c02_4 != meadows_0c02 || latched_0c03_5 != meadows_0c03 )
{
LABEL_9:
v6 = (unsigned __int8)~v5;
if ( v6 )
{
v7 = v6 + 1;
v4 = (unsigned int)(156250 % v7);
v8 = (156250 / v7) >> 1;
if ( (meadows_0c03 & 1) == 0 )
v8 = (156250 / v7) >> 2;
freq2 = v8;
v6 = (meadows_0c03 & 2) != 0 ? 0xA0 : 0;
}
mixer_set_sample_frequency((unsigned int)(channel + 1), (unsigned int)(2 * freq2), v4);
mixer_set_volume((unsigned int)(channel + 1), (unsigned int)(100 * v6 / 255));
if ( latched_0c03_5 != meadows_0c03 )
{
dac_enable = meadows_0c03 & 4;
if ( (meadows_0c03 & 4) != 0 )
DAC_data_w(0LL, (unsigned __int8)meadows_dac);
else
DAC_data_w(0LL, 0LL);
}
}
LABEL_16:
latched_0c01_6 = meadows_0c01;
latched_0c02_4 = meadows_0c02;
result = meadows_0c03;
latched_0c03_5 = meadows_0c03;
return result;
}

canonical_decompiled_code:
__int64 func16()
{
int v0; // ebp
__int64 v1; // rdx
int v2; // ebx
int v3; // ebx
unsigned __int64 v4; // rdx
char v5; // bl
int v6; // ebx
int v7; // ebx
int v8; // eax
__int64 result; // rax

if ( latched_0c01_6 == meadows_0c01 )
{
v4 = (unsigned __int64)&meadows_0c03;
if ( latched_0c03_5 == meadows_0c03 )
{
v5 = meadows_0c02;
if ( latched_0c02_4 == meadows_0c02 )
goto LABEL_16;
goto LABEL_9;
}
}
v0 = 0;
if ( (meadows_0c03 & 8) != 0 )
v0 = (meadows_0c01 >> 1) & 0x78;
v1 = (unsigned int)s2650_get_flag();
if ( (_DWORD)v1 )
v0 += 128;
v2 = ~meadows_0c01 & 0xF;
if ( (~meadows_0c01 & 0xF) != 0 )
{
v3 = v2 + 1;
v1 = (unsigned int)(19531 % v3);
freq1 = 19531 / v3;
v2 = v0;
}
mixer_set_sample_frequency((unsigned int)channel, (unsigned int)(2 * freq1), v1);
mixer_set_volume((unsigned int)channel, (unsigned int)(100 * v2 / 255));
v5 = meadows_0c02;
if ( latched_0c02_4 != meadows_0c02 || latched_0c03_5 != meadows_0c03 )
{
LABEL_9:
v6 = (unsigned __int8)~v5;
if ( v6 )
{
v7 = v6 + 1;
v4 = (unsigned int)(156250 % v7);
v8 = (156250 / v7) >> 1;
if ( (meadows_0c03 & 1) == 0 )
v8 = (156250 / v7) >> 2;
freq2 = v8;
v6 = (meadows_0c03 & 2) != 0 ? 0xA0 : 0;
}
mixer_set_sample_frequency((unsigned int)(channel + 1), (unsigned int)(2 * freq2), v4);
mixer_set_volume((unsigned int)(channel + 1), (unsigned int)(100 * v6 / 255));
if ( latched_0c03_5 != meadows_0c03 )
{
dac_enable = meadows_0c03 & 4;
if ( (meadows_0c03 & 4) != 0 )
DAC_data_w(0LL, (unsigned __int8)meadows_dac);
else
DAC_data_w(0LL, 0LL);
}
}
LABEL_16:
latched_0c01_6 = meadows_0c01;
latched_0c02_4 = meadows_0c02;
result = meadows_0c03;
latched_0c03_5 = meadows_0c03;
return result;
}

original_code:
void meadows_sh_update(void)
{
static unsigned char latched_0c01 = 0;
static unsigned char latched_0c02 = 0;
static unsigned char latched_0c03 = 0;
int preset, amp;
    if (latched_0c01 != meadows_0c01 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x08) == 0) ? 0 : (meadows_0c01 & 0xf0) >> 1;
  if( s2650_get_flag() )
   amp += 0x80;
  preset = (meadows_0c01 & 15) ^ 15;
  if (preset)
   freq1 = (5000000 / 256) / (preset + 1);
  else amp = 0;
  mixer_set_sample_frequency(channel, freq1 * sizeof(waveform));
  mixer_set_volume(channel,amp*100/255);
    }
 if (latched_0c02 != meadows_0c02 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x02) != 0) ? 0xa0 : 0;
  preset = meadows_0c02 ^ 0xff;
  if (preset)
  {
   freq2 = (5000000 / 32) / (preset + 1) / 2;
   if ((meadows_0c03 & 0x01) == 0)
    freq2 >>= 1;
  }
  else amp = 0;
  mixer_set_sample_frequency(channel+1, freq2 * sizeof(waveform));
  mixer_set_volume(channel+1,amp*100/255);
    }
 if (latched_0c03 != meadows_0c03)
 {
  dac_enable = meadows_0c03 & 0x04;
  if (dac_enable)
   DAC_data_w(0, meadows_dac);
  else
   DAC_data_w(0, 0);
    }
    latched_0c01 = meadows_0c01;
 latched_0c02 = meadows_0c02;
 latched_0c03 = meadows_0c03;
}

canonical_original_code:
void meadows_sh_update()
{
static unsigned char latched_0c01 = 0;
static unsigned char latched_0c02 = 0;
static unsigned char latched_0c03 = 0;
int preset; int amp;
    if (latched_0c01 != meadows_0c01 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x08) == 0) ? 0 : (meadows_0c01 & 0xf0) >> 1;
  if( s2650_get_flag() )
   amp += 0x80;
  preset = (meadows_0c01 & 15) ^ 15;
  if (preset)
   freq1 = (5000000 / 256) / (preset + 1);
  else amp = 0;
  mixer_set_sample_frequency(channel, freq1 * sizeof(waveform));
  mixer_set_volume(channel,amp*100/255);
    }
 if (latched_0c02 != meadows_0c02 || latched_0c03 != meadows_0c03)
 {
  amp = ((meadows_0c03 & 0x02) != 0) ? 0xa0 : 0;
  preset = meadows_0c02 ^ 0xff;
  if (preset)
  {
   freq2 = (5000000 / 32) / (preset + 1) / 2;
   if ((meadows_0c03 & 0x01) == 0)
    freq2 >>= 1;
  }
  else amp = 0;
  mixer_set_sample_frequency(channel+1, freq2 * sizeof(waveform));
  mixer_set_volume(channel+1,amp*100/255);
    }
 if (latched_0c03 != meadows_0c03)
 {
  dac_enable = meadows_0c03 & 0x04;
  if (dac_enable)
   DAC_data_w(0, meadows_dac);
  else
   DAC_data_w(0, 0);
    }
    latched_0c01 = meadows_0c01;
 latched_0c02 = meadows_0c02;
 latched_0c03 = meadows_0c03;
}

variable_types: preset int

variable_types: amp int


decompiled_code:
__int64 __fastcall meadows_sh_dac_w(unsigned __int8 a1)
{
__int64 result; // rax

meadows_dac = a1;
if ( dac_enable )
result = DAC_data_w(0LL, a1);
else
result = DAC_data_w(0LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned __int8 a1)
{
__int64 result; // rax

meadows_dac = a1;
if ( dac_enable )
result = DAC_data_w(0LL, a1);
else
result = DAC_data_w(0LL, 0LL);
return result;
}

original_code:
void meadows_sh_dac_w(int data)
{
 meadows_dac = data;
 if (dac_enable)
  DAC_data_w(0, meadows_dac);
 else
  DAC_data_w(0, 0);
}


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

v0 = sense_state_1;
sense_state_1 ^= 1u;
cpu_set_irq_line(1LL, 1LL, v0 != 1);
return ignore_interrupt();
}

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

v0 = sense_state_1;
sense_state_1 ^= 1u;
cpu_set_irq_line(1LL, 1LL, v0 != 1);
return ignore_interrupt();
}

original_code:
static int sound_interrupt(void)
{
 static int sense_state = 0;
 sense_state ^= 1;
 cpu_set_irq_line( 1, 1, (sense_state) ? 1 : 0 );
 return ignore_interrupt();
}

canonical_original_code:
static int sound_interrupt()
{
 static int sense_state = 0;
 sense_state ^= 1;
 cpu_set_irq_line( 1, 1, (sense_state) ? 1 : 0 );
 return ignore_interrupt();
}


decompiled_code:
void *__fastcall init_palette(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

canonical_decompiled_code:
void *__fastcall func14(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}


decompiled_code:
void __fastcall bzone_sound_update(__int64 a1, __int64 a2, unsigned int a3)
{
int v4; // edi
int v5; // ecx
int v6; // er8
int v7; // er12
int v8; // esi
int v9; // er13
int v10; // ebx
int v11; // er11
int v12; // er9
int v13; // xmm7_4
int v14; // xmm6_4
int v15; // ebp
int v16; // er14
int v17; // er10
_BOOL4 i; // esi
int v19; // edx
char v20; // al
int v21; // er8
int v22; // eax
int v23; // er15
int v24; // er15
int v25; // edx
int v26; // er10
int v27; // eax
int v28; // edx
bool v29; // zf
int v30; // eax
int v31; // edx
int v32; // er10
int v33; // eax
int v34; // edx
int v35; // eax
int v36; // eax
int v37; // edx
int v38; // xmm1_4
int v39; // xmm0_4
double v40; // xmm0_8
int v41; // edx
int v42; // eax
int v43; // eax
int v44; // edx
__int64 v45; // [rsp+0h] [rbp-A0h]
char v46; // [rsp+Ah] [rbp-96h]
char v47; // [rsp+Bh] [rbp-95h]
int v48; // [rsp+Ch] [rbp-94h]
int v49; // [rsp+10h] [rbp-90h]
int v50; // [rsp+14h] [rbp-8Ch]
__int16 *v51; // [rsp+18h] [rbp-88h]
int v52; // [rsp+20h] [rbp-80h]
int v53; // [rsp+24h] [rbp-7Ch]
__int64 v54; // [rsp+28h] [rbp-78h]
int v55; // [rsp+30h] [rbp-70h]
int v56; // [rsp+34h] [rbp-6Ch]
char v57; // [rsp+38h] [rbp-68h]
char v58; // [rsp+39h] [rbp-67h]
char v59; // [rsp+3Ah] [rbp-66h]
char v60; // [rsp+3Bh] [rbp-65h]
int v61; // [rsp+3Ch] [rbp-64h]
int v62; // [rsp+40h] [rbp-60h]
int v63; // [rsp+44h] [rbp-5Ch]
int v64; // [rsp+48h] [rbp-58h]
int v65; // [rsp+4Ch] [rbp-54h]
int v66; // [rsp+50h] [rbp-50h]
int v67; // [rsp+54h] [rbp-4Ch]
char v68; // [rsp+58h] [rbp-48h]
char v69; // [rsp+5Ch] [rbp-44h]
char v70; // [rsp+5Dh] [rbp-43h]
char v71; // [rsp+5Eh] [rbp-42h]
char v72; // [rsp+5Fh] [rbp-41h]
int v73; // [rsp+60h] [rbp-40h]
char v74; // [rsp+64h] [rbp-3Ch]
char v75; // [rsp+65h] [rbp-3Bh]
char v76; // [rsp+66h] [rbp-3Ah]
char v77; // [rsp+67h] [rbp-39h]
char v78; // [rsp+68h] [rbp-38h]
char v79; // [rsp+6Ch] [rbp-34h]
char v80; // [rsp+6Dh] [rbp-33h]
char v81; // [rsp+6Eh] [rbp-32h]
char v82; // [rsp+6Fh] [rbp-31h]

v45 = a2;
if ( !a3 )
return;
v4 = poly_counter;
v5 = poly_shift;
v6 = explosion_clock;
v7 = explosion_out;
v8 = shell_clock;
v9 = shell_out;
v52 = latch & 1;
v61 = explosion_amp_counter;
v49 = explosion_amp;
v64 = latch & 2;
v51 = (__int16 *)discharge;
v53 = latch & 4;
v62 = shell_amp_counter;
v50 = shell_amp;
v65 = latch & 8;
v55 = latch & 0x80;
v73 = (latch & 0x10) == 0 ? 184 : 240;
v63 = motor_rate_counter;
v56 = motor_rate;
v10 = motor_counter;
v11 = motor_counter_a;
v12 = motor_counter_b;
v13 = r0_2;
v14 = r1_1;
v15 = motor_amp_new;
v66 = motor_amp_step;
v67 = motor_amp_counter;
v48 = last_val_0;
v54 = a2 + 2LL * a3;
v77 = 0;
v72 = 0;
v69 = 0;
v71 = 0;
v60 = 0;
v47 = 0;
v59 = 0;
v46 = 0;
v58 = 0;
v57 = 0;
v81 = 0;
v78 = 0;
v80 = 0;
v82 = 0;
v79 = 0;
v76 = 0;
v75 = 0;
v74 = 0;
v70 = 0;
v68 = 0;
v16 = motor_amp;
do
{
v4 -= 6000;
if ( v4 <= 0 )
{
v17 = v8;
for ( i = v6; ; i = v22 != 28672 )
{
v4 += *(_DWORD *)(Machine + 836LL);
v19 = ((unsigned int)v5 >> 3) & 1;
v20 = (((unsigned int)v5 >> 14) ^ 1) & 1;
v21 = 2 * v5 + 1;
v5 *= 2;
if ( (_BYTE)v19 != v20 )
v5 = v21;
v22 = v5 & 0x7000;
v6 = v22 != 28672;
if ( v22 != 28672 && !i )
{
v7 ^= 1u;
v46 = 1;
}
v8 = (v5 >> 15) & 1;
if ( v8 && !v17 )
{
v9 ^= 1u;
v47 = 1;
}
if ( v4 > 0 )
break;
v17 = (v5 >> 15) & 1;
}
v59 = 1;
v58 = 1;
v57 = 1;
}
if ( v52 )
{
if ( !v7 )
{
v23 = 0;
v60 = 1;
v49 = 0x7FFF;
goto LABEL_17;
}
v60 = 1;
v49 = 0x7FFF;
LABEL_29:
if ( v61 - 35616 < 0 )
{
v26 = *(_DWORD *)(Machine + 836LL);
v27 = (35616 - v61) / v26 + 1;
v61 = v27 * v26 + v61 - 35616;
v28 = v49 - v27;
v29 = v49 == v27;
v30 = 0;
if ( v28 >= 0 && !v29 )
v30 = v28;
v49 = v30;
v71 = 1;
v60 = 1;
}
else
{
v61 -= 35616;
v71 = 1;
}
goto LABEL_26;
}
v23 = v7;
if ( !v7 )
goto LABEL_17;
if ( v49 > 0 )
goto LABEL_29;
LABEL_26:
if ( v64 )
v23 = v51[v49] / 3;
else
v23 = v51[v49] / 4;
LABEL_17:
if ( v53 )
{
if ( !v9 )
{
v69 = 1;
v50 = 0x7FFF;
goto LABEL_20;
}
v69 = 1;
v50 = 0x7FFF;
LABEL_40:
v31 = v62;
v62 -= 75779;
if ( v62 < 0 )
{
v32 = *(_DWORD *)(Machine + 836LL);
v33 = (75779 - v31) / v32 + 1;
v62 += v33 * v32;
v34 = v50 - v33;
v29 = v50 == v33;
v35 = 0;
if ( v34 >= 0 && !v29 )
v35 = v34;
v50 = v35;
v72 = 1;
v69 = 1;
}
else
{
v72 = 1;
}
goto LABEL_37;
}
if ( !v9 )
goto LABEL_20;
if ( v50 > 0 )
goto LABEL_40;
LABEL_37:
if ( v65 )
v23 += v51[v50] / 3;
else
v23 += v51[v50] / 4;
LABEL_20:
if ( !v55 )
goto LABEL_21;
if ( v73 != v56 )
{
v63 -= 224;
if ( v63 > 0 )
{
v78 = 1;
}
else
{
v36 = v63;
v37 = v56;
do
{
v36 += *(_DWORD *)(Machine + 836LL);
v37 = v37 + 2 * (v73 > v37) - 1;
}
while ( v36 <= 0 );
v63 = v36;
v56 = v37;
v81 = 1;
v78 = 1;
}
}
v10 -= v56;
if ( v10 <= 0 )
{
while ( 1 )
{
v10 += *(_DWORD *)(Machine + 836LL);
if ( ++v11 == 16 )
{
++v12;
v11 = 6;
if ( v12 == 16 )
{
v12 = 4;
v11 = 6;
v38 = LC1;
v39 = LC0;
goto LABEL_65;
}
}
else if ( ++v12 == 16 )
{
v12 = 4;
}
if ( (v11 & 8) != 0 )
{
v38 = LC0;
v39 = LC1;
}
else
{
v38 = LC1;
v39 = LC0;
}
LABEL_65:
if ( v11 == 15 )
*(float *)&v38 = *(float *)&v38 + 0.0000303030303030303;
else
*(float *)&v39 = *(float *)&v39 + 0.0000303030303030303;
if ( (v12 & 8) != 0 )
*(float *)&v38 = *(float *)&v38 + 0.0000303030303030303;
else
*(float *)&v39 = *(float *)&v39 + 0.0000303030303030303;
if ( v12 == 15 )
*(float *)&v38 = *(float *)&v38 + 0.0000303030303030303;
else
*(float *)&v39 = *(float *)&v39 + 0.0000303030303030303;
*(float *)&v13 = 1.0 / *(float *)&v39;
*(float *)&v14 = 1.0 / *(float *)&v38;
v15 = (int)(float)((float)(*(float *)&v13 * 32767.0) / (float)(*(float *)&v13 + (float)(1.0 / *(float *)&v38)));
if ( v15 <= v16 )
v40 = (double)(v16 - v15) / (*(float *)&v13 * 0.00000047);
else
v40 = (double)(v15 - v16) / (*(float *)&v14 * 0.00000047);
if ( v10 > 0 )
{
v66 = (int)v40;
v80 = 1;
v79 = 1;
v76 = 1;
v75 = 1;
v74 = 1;
v70 = 1;
break;
}
}
}
if ( v15 != v16 )
{
v77 = 1;
v41 = v67;
v67 -= v66;
if ( v67 < 0 )
{
v43 = (v66 - v41) / *(_DWORD *)(Machine + 836LL) + 1;
v67 += v43 * *(_DWORD *)(Machine + 836LL);
if ( v15 >= v16 )
{
v16 += v43;
if ( v16 <= v15 )
{
v77 = 1;
v82 = 1;
goto LABEL_76;
}
v16 = v15;
}
else
{
v44 = v16 - v43;
if ( v16 - v43 < v15 )
v44 = v15;
v16 = v44;
}
v77 = 1;
v82 = 1;
LABEL_84:
v42 = v51[v16] / 3;
goto LABEL_78;
}
}
LABEL_76:
if ( v15 <= v16 )
goto LABEL_84;
v42 = (0x7FFF - v51[0x7FFF - v16]) / 3;
LABEL_78:
v23 += v42;
v68 = 1;
LABEL_21:
v24 = v48 + v23;
v45 += 2LL;
*(_WORD *)(v45 - 2) = v24 / 2;
v25 = v24 + 2 * v48;
v48 = v25 / 4;
}
while ( v45 != v54 );
poly_counter = v4;
if ( v68 )
motor_counter = v10;
if ( v70 )
r0_2 = v13;
if ( v74 )
r1_1 = v14;
if ( v75 )
motor_counter_a = v11;
if ( v76 )
motor_counter_b = v12;
if ( v79 )
motor_amp_new = v15;
if ( v82 )
motor_amp = v16;
if ( v80 )
motor_amp_step = v66;
if ( v78 )
motor_rate_counter = v63;
if ( v81 )
motor_rate = v56;
if ( v57 )
poly_shift = v5;
if ( v58 )
explosion_clock = v6;
if ( v46 )
explosion_out = v7;
if ( v59 )
shell_clock = v8;
if ( v47 )
shell_out = v9;
if ( v60 )
explosion_amp = v49;
if ( v71 )
explosion_amp_counter = v61;
if ( v69 )
shell_amp = v50;
if ( v72 )
shell_amp_counter = v62;
if ( v77 )
motor_amp_counter = v67;
last_val_0 = v25 / 4;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, unsigned int a3)
{
int v4; // edi
int v5; // ecx
int v6; // er8
int v7; // er12
int v8; // esi
int v9; // er13
int v10; // ebx
int v11; // er11
int v12; // er9
int v13; // xmm7_4
int v14; // xmm6_4
int v15; // ebp
int v16; // er14
int v17; // er10
_BOOL4 i; // esi
int v19; // edx
char v20; // al
int v21; // er8
int v22; // eax
int v23; // er15
int v24; // er15
int v25; // edx
int v26; // er10
int v27; // eax
int v28; // edx
bool v29; // zf
int v30; // eax
int v31; // edx
int v32; // er10
int v33; // eax
int v34; // edx
int v35; // eax
int v36; // eax
int v37; // edx
int v38; // xmm1_4
int v39; // xmm0_4
double v40; // xmm0_8
int v41; // edx
int v42; // eax
int v43; // eax
int v44; // edx
__int64 v45; // [rsp+0h] [rbp-A0h]
char v46; // [rsp+Ah] [rbp-96h]
char v47; // [rsp+Bh] [rbp-95h]
int v48; // [rsp+Ch] [rbp-94h]
int v49; // [rsp+10h] [rbp-90h]
int v50; // [rsp+14h] [rbp-8Ch]
__int16 *v51; // [rsp+18h] [rbp-88h]
int v52; // [rsp+20h] [rbp-80h]
int v53; // [rsp+24h] [rbp-7Ch]
__int64 v54; // [rsp+28h] [rbp-78h]
int v55; // [rsp+30h] [rbp-70h]
int v56; // [rsp+34h] [rbp-6Ch]
char v57; // [rsp+38h] [rbp-68h]
char v58; // [rsp+39h] [rbp-67h]
char v59; // [rsp+3Ah] [rbp-66h]
char v60; // [rsp+3Bh] [rbp-65h]
int v61; // [rsp+3Ch] [rbp-64h]
int v62; // [rsp+40h] [rbp-60h]
int v63; // [rsp+44h] [rbp-5Ch]
int v64; // [rsp+48h] [rbp-58h]
int v65; // [rsp+4Ch] [rbp-54h]
int v66; // [rsp+50h] [rbp-50h]
int v67; // [rsp+54h] [rbp-4Ch]
char v68; // [rsp+58h] [rbp-48h]
char v69; // [rsp+5Ch] [rbp-44h]
char v70; // [rsp+5Dh] [rbp-43h]
char v71; // [rsp+5Eh] [rbp-42h]
char v72; // [rsp+5Fh] [rbp-41h]
int v73; // [rsp+60h] [rbp-40h]
char v74; // [rsp+64h] [rbp-3Ch]
char v75; // [rsp+65h] [rbp-3Bh]
char v76; // [rsp+66h] [rbp-3Ah]
char v77; // [rsp+67h] [rbp-39h]
char v78; // [rsp+68h] [rbp-38h]
char v79; // [rsp+6Ch] [rbp-34h]
char v80; // [rsp+6Dh] [rbp-33h]
char v81; // [rsp+6Eh] [rbp-32h]
char v82; // [rsp+6Fh] [rbp-31h]

v45 = a2;
if ( !a3 )
return;
v4 = poly_counter;
v5 = poly_shift;
v6 = explosion_clock;
v7 = explosion_out;
v8 = shell_clock;
v9 = shell_out;
v52 = latch & 1;
v61 = explosion_amp_counter;
v49 = explosion_amp;
v64 = latch & 2;
v51 = (__int16 *)discharge;
v53 = latch & 4;
v62 = shell_amp_counter;
v50 = shell_amp;
v65 = latch & 8;
v55 = latch & 0x80;
v73 = (latch & 0x10) == 0 ? 184 : 240;
v63 = motor_rate_counter;
v56 = motor_rate;
v10 = motor_counter;
v11 = motor_counter_a;
v12 = motor_counter_b;
v13 = r0_2;
v14 = r1_1;
v15 = motor_amp_new;
v66 = motor_amp_step;
v67 = motor_amp_counter;
v48 = last_val_0;
v54 = a2 + 2LL * a3;
v77 = 0;
v72 = 0;
v69 = 0;
v71 = 0;
v60 = 0;
v47 = 0;
v59 = 0;
v46 = 0;
v58 = 0;
v57 = 0;
v81 = 0;
v78 = 0;
v80 = 0;
v82 = 0;
v79 = 0;
v76 = 0;
v75 = 0;
v74 = 0;
v70 = 0;
v68 = 0;
v16 = motor_amp;
do
{
v4 -= 6000;
if ( v4 <= 0 )
{
v17 = v8;
for ( i = v6; ; i = v22 != 28672 )
{
v4 += *(_DWORD *)(Machine + 836LL);
v19 = ((unsigned int)v5 >> 3) & 1;
v20 = (((unsigned int)v5 >> 14) ^ 1) & 1;
v21 = 2 * v5 + 1;
v5 *= 2;
if ( (_BYTE)v19 != v20 )
v5 = v21;
v22 = v5 & 0x7000;
v6 = v22 != 28672;
if ( v22 != 28672 && !i )
{
v7 ^= 1u;
v46 = 1;
}
v8 = (v5 >> 15) & 1;
if ( v8 && !v17 )
{
v9 ^= 1u;
v47 = 1;
}
if ( v4 > 0 )
break;
v17 = (v5 >> 15) & 1;
}
v59 = 1;
v58 = 1;
v57 = 1;
}
if ( v52 )
{
if ( !v7 )
{
v23 = 0;
v60 = 1;
v49 = 0x7FFF;
goto LABEL_17;
}
v60 = 1;
v49 = 0x7FFF;
LABEL_29:
if ( v61 - 35616 < 0 )
{
v26 = *(_DWORD *)(Machine + 836LL);
v27 = (35616 - v61) / v26 + 1;
v61 = v27 * v26 + v61 - 35616;
v28 = v49 - v27;
v29 = v49 == v27;
v30 = 0;
if ( v28 >= 0 && !v29 )
v30 = v28;
v49 = v30;
v71 = 1;
v60 = 1;
}
else
{
v61 -= 35616;
v71 = 1;
}
goto LABEL_26;
}
v23 = v7;
if ( !v7 )
goto LABEL_17;
if ( v49 > 0 )
goto LABEL_29;
LABEL_26:
if ( v64 )
v23 = v51[v49] / 3;
else
v23 = v51[v49] / 4;
LABEL_17:
if ( v53 )
{
if ( !v9 )
{
v69 = 1;
v50 = 0x7FFF;
goto LABEL_20;
}
v69 = 1;
v50 = 0x7FFF;
LABEL_40:
v31 = v62;
v62 -= 75779;
if ( v62 < 0 )
{
v32 = *(_DWORD *)(Machine + 836LL);
v33 = (75779 - v31) / v32 + 1;
v62 += v33 * v32;
v34 = v50 - v33;
v29 = v50 == v33;
v35 = 0;
if ( v34 >= 0 && !v29 )
v35 = v34;
v50 = v35;
v72 = 1;
v69 = 1;
}
else
{
v72 = 1;
}
goto LABEL_37;
}
if ( !v9 )
goto LABEL_20;
if ( v50 > 0 )
goto LABEL_40;
LABEL_37:
if ( v65 )
v23 += v51[v50] / 3;
else
v23 += v51[v50] / 4;
LABEL_20:
if ( !v55 )
goto LABEL_21;
if ( v73 != v56 )
{
v63 -= 224;
if ( v63 > 0 )
{
v78 = 1;
}
else
{
v36 = v63;
v37 = v56;
do
{
v36 += *(_DWORD *)(Machine + 836LL);
v37 = v37 + 2 * (v73 > v37) - 1;
}
while ( v36 <= 0 );
v63 = v36;
v56 = v37;
v81 = 1;
v78 = 1;
}
}
v10 -= v56;
if ( v10 <= 0 )
{
while ( 1 )
{
v10 += *(_DWORD *)(Machine + 836LL);
if ( ++v11 == 16 )
{
++v12;
v11 = 6;
if ( v12 == 16 )
{
v12 = 4;
v11 = 6;
v38 = LC1;
v39 = LC0;
goto LABEL_65;
}
}
else if ( ++v12 == 16 )
{
v12 = 4;
}
if ( (v11 & 8) != 0 )
{
v38 = LC0;
v39 = LC1;
}
else
{
v38 = LC1;
v39 = LC0;
}
LABEL_65:
if ( v11 == 15 )
*(float *)&v38 = *(float *)&v38 + 0.0000303030303030303;
else
*(float *)&v39 = *(float *)&v39 + 0.0000303030303030303;
if ( (v12 & 8) != 0 )
*(float *)&v38 = *(float *)&v38 + 0.0000303030303030303;
else
*(float *)&v39 = *(float *)&v39 + 0.0000303030303030303;
if ( v12 == 15 )
*(float *)&v38 = *(float *)&v38 + 0.0000303030303030303;
else
*(float *)&v39 = *(float *)&v39 + 0.0000303030303030303;
*(float *)&v13 = 1.0 / *(float *)&v39;
*(float *)&v14 = 1.0 / *(float *)&v38;
v15 = (int)(float)((float)(*(float *)&v13 * 32767.0) / (float)(*(float *)&v13 + (float)(1.0 / *(float *)&v38)));
if ( v15 <= v16 )
v40 = (double)(v16 - v15) / (*(float *)&v13 * 0.00000047);
else
v40 = (double)(v15 - v16) / (*(float *)&v14 * 0.00000047);
if ( v10 > 0 )
{
v66 = (int)v40;
v80 = 1;
v79 = 1;
v76 = 1;
v75 = 1;
v74 = 1;
v70 = 1;
break;
}
}
}
if ( v15 != v16 )
{
v77 = 1;
v41 = v67;
v67 -= v66;
if ( v67 < 0 )
{
v43 = (v66 - v41) / *(_DWORD *)(Machine + 836LL) + 1;
v67 += v43 * *(_DWORD *)(Machine + 836LL);
if ( v15 >= v16 )
{
v16 += v43;
if ( v16 <= v15 )
{
v77 = 1;
v82 = 1;
goto LABEL_76;
}
v16 = v15;
}
else
{
v44 = v16 - v43;
if ( v16 - v43 < v15 )
v44 = v15;
v16 = v44;
}
v77 = 1;
v82 = 1;
LABEL_84:
v42 = v51[v16] / 3;
goto LABEL_78;
}
}
LABEL_76:
if ( v15 <= v16 )
goto LABEL_84;
v42 = (0x7FFF - v51[0x7FFF - v16]) / 3;
LABEL_78:
v23 += v42;
v68 = 1;
LABEL_21:
v24 = v48 + v23;
v45 += 2LL;
*(_WORD *)(v45 - 2) = v24 / 2;
v25 = v24 + 2 * v48;
v48 = v25 / 4;
}
while ( v45 != v54 );
poly_counter = v4;
if ( v68 )
motor_counter = v10;
if ( v70 )
r0_2 = v13;
if ( v74 )
r1_1 = v14;
if ( v75 )
motor_counter_a = v11;
if ( v76 )
motor_counter_b = v12;
if ( v79 )
motor_amp_new = v15;
if ( v82 )
motor_amp = v16;
if ( v80 )
motor_amp_step = v66;
if ( v78 )
motor_rate_counter = v63;
if ( v81 )
motor_rate = v56;
if ( v57 )
poly_shift = v5;
if ( v58 )
explosion_clock = v6;
if ( v46 )
explosion_out = v7;
if ( v59 )
shell_clock = v8;
if ( v47 )
shell_out = v9;
if ( v60 )
explosion_amp = v49;
if ( v71 )
explosion_amp_counter = v61;
if ( v69 )
shell_amp = v50;
if ( v72 )
shell_amp_counter = v62;
if ( v77 )
motor_amp_counter = v67;
last_val_0 = v25 / 4;
}

original_code:
static void bzone_sound_update(int param, INT16 *buffer, int length)
{
 while( length-- )
 {
  static int last_val = 0;
  int sum = 0;
  poly_counter -= 6000;
  while( poly_counter <= 0 )
  {
   int clock;
   poly_counter += Machine->sample_rate;
   if( ((poly_shift & 0x0008) == 0) == ((poly_shift & 0x4000) == 0) )
    poly_shift = (poly_shift << 1) | 1;
   else
    poly_shift <<= 1;
   clock = ((poly_shift & 0x7000) == 0x7000) ? 0 : 1;
   if( clock && !explosion_clock )
    explosion_out ^= 1;
   explosion_clock = clock;
   clock = (poly_shift >> 15) & 1;
   if( clock && !shell_clock )
    shell_out ^= 1;
   shell_clock = clock;
  }
  if( latch & 0x01 )
   explosion_amp = 32767;
  if( explosion_out )
  {
   if( explosion_amp > 0 )
   {
    explosion_amp_counter -= (int)(32767 / (0.23*4));
    if( explosion_amp_counter < 0 )
    {
     int n = (-explosion_amp_counter / Machine->sample_rate) + 1;
     explosion_amp_counter += n * Machine->sample_rate;
     if( (explosion_amp -= n) < 0 )
      explosion_amp = 0;
    }
   }
   if( latch & 0x02 )
    sum += (0 ? 0x7fff - discharge[0x7fff-explosion_amp] : discharge[explosion_amp])/3;
   else
    sum += (0 ? 0x7fff - discharge[0x7fff-explosion_amp] : discharge[explosion_amp])/4;
  }
  if( latch & 0x04 )
   shell_amp = 32767;
  if( shell_out )
  {
   if( shell_amp > 0 )
   {
    shell_amp_counter -= (int)(32767 / (0.1081*4));
    if( shell_amp_counter < 0 )
    {
     int n = (-shell_amp_counter / Machine->sample_rate) + 1;
     shell_amp_counter += n * Machine->sample_rate;
     if( (shell_amp -= n) < 0 )
      shell_amp = 0;
    }
   }
   if( latch & 0x08 )
    sum += (0 ? 0x7fff - discharge[0x7fff-shell_amp] : discharge[shell_amp])/3;
   else
    sum += (0 ? 0x7fff - discharge[0x7fff-shell_amp] : discharge[shell_amp])/4;
  }
  if( latch & 0x80 )
  {
   static float r0 = 1.0/1e12, r1 = 1.0/1e12;
   motor_rate_new = (latch & 0x10) ? 240 : 184;
   if( motor_rate != motor_rate_new )
   {
    motor_rate_counter -= (int)((240 - 184) / 0.25);
    while( motor_rate_counter <= 0 )
    {
     motor_rate_counter += Machine->sample_rate;
     motor_rate += (motor_rate < motor_rate_new) ? +1 : -1;
    }
   }
   motor_counter -= motor_rate;
   while( motor_counter <= 0 )
   {
    motor_counter += Machine->sample_rate;
    r0 = 1.0/1e12;
    r1 = 1.0/1e12;
    if( ++motor_counter_a == 16 )
     motor_counter_a = 6;
    if( ++motor_counter_b == 16 )
     motor_counter_b = 4;
    if( motor_counter_a & 8 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    if( motor_counter_a == 15 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    if( motor_counter_b & 8 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    if( motor_counter_b == 15 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    r0 = 1.0/r0;
    r1 = 1.0/r1;
    motor_amp_new = (int)(32767 * r0 / (r0 + r1));
    if( motor_amp_new > motor_amp )
     motor_amp_step = (int)((motor_amp_new - motor_amp) / (r1*0.47e-6));
    else
     motor_amp_step = (int)((motor_amp - motor_amp_new) / (r0*0.47e-6));
   }
   if( motor_amp != motor_amp_new )
   {
    motor_amp_counter -= motor_amp_step;
    if( motor_amp_counter < 0 )
    {
     int n = (-motor_amp_counter / Machine->sample_rate) + 1;
     motor_amp_counter += n * Machine->sample_rate;
     if( motor_amp > motor_amp_new )
     {
      motor_amp -= n;
      if( motor_amp < motor_amp_new )
       motor_amp = motor_amp_new;
     }
     else
     {
      motor_amp += n;
      if( motor_amp > motor_amp_new )
       motor_amp = motor_amp_new;
     }
    }
   }
   sum += ((motor_amp<motor_amp_new) ? 0x7fff - discharge[0x7fff-motor_amp] : discharge[motor_amp])/3;
  }
  *buffer++ = (sum + last_val) / 2;
  last_val = (sum + last_val * 3) / 4;
 }
}

canonical_original_code:
static void bzone_sound_update(int param, short *buffer, int length)
{
 while( length-- )
 {
  static int last_val = 0;
  int sum = 0;
  poly_counter -= 6000;
  while( poly_counter <= 0 )
  {
   int clock;
   poly_counter += Machine->sample_rate;
   if( ((poly_shift & 0x0008) == 0) == ((poly_shift & 0x4000) == 0) )
    poly_shift = (poly_shift << 1) | 1;
   else
    poly_shift <<= 1;
   clock = ((poly_shift & 0x7000) == 0x7000) ? 0 : 1;
   if( clock && !explosion_clock )
    explosion_out ^= 1;
   explosion_clock = clock;
   clock = (poly_shift >> 15) & 1;
   if( clock && !shell_clock )
    shell_out ^= 1;
   shell_clock = clock;
  }
  if( latch & 0x01 )
   explosion_amp = 32767;
  if( explosion_out )
  {
   if( explosion_amp > 0 )
   {
    explosion_amp_counter -= (int)(32767 / (0.23*4));
    if( explosion_amp_counter < 0 )
    {
     int n = (-explosion_amp_counter / Machine->sample_rate) + 1;
     explosion_amp_counter += n * Machine->sample_rate;
     if( (explosion_amp -= n) < 0 )
      explosion_amp = 0;
    }
   }
   if( latch & 0x02 )
    sum += (0 ? 0x7fff - discharge[0x7fff-explosion_amp] : discharge[explosion_amp])/3;
   else
    sum += (0 ? 0x7fff - discharge[0x7fff-explosion_amp] : discharge[explosion_amp])/4;
  }
  if( latch & 0x04 )
   shell_amp = 32767;
  if( shell_out )
  {
   if( shell_amp > 0 )
   {
    shell_amp_counter -= (int)(32767 / (0.1081*4));
    if( shell_amp_counter < 0 )
    {
     int n = (-shell_amp_counter / Machine->sample_rate) + 1;
     shell_amp_counter += n * Machine->sample_rate;
     if( (shell_amp -= n) < 0 )
      shell_amp = 0;
    }
   }
   if( latch & 0x08 )
    sum += (0 ? 0x7fff - discharge[0x7fff-shell_amp] : discharge[shell_amp])/3;
   else
    sum += (0 ? 0x7fff - discharge[0x7fff-shell_amp] : discharge[shell_amp])/4;
  }
  if( latch & 0x80 )
  {
   static float r0 = 1.0/1e12; static float r1 = 1.0/1e12;
   motor_rate_new = (latch & 0x10) ? 240 : 184;
   if( motor_rate != motor_rate_new )
   {
    motor_rate_counter -= (int)((240 - 184) / 0.25);
    while( motor_rate_counter <= 0 )
    {
     motor_rate_counter += Machine->sample_rate;
     motor_rate += (motor_rate < motor_rate_new) ? +1 : -1;
    }
   }
   motor_counter -= motor_rate;
   while( motor_counter <= 0 )
   {
    motor_counter += Machine->sample_rate;
    r0 = 1.0/1e12;
    r1 = 1.0/1e12;
    if( ++motor_counter_a == 16 )
     motor_counter_a = 6;
    if( ++motor_counter_b == 16 )
     motor_counter_b = 4;
    if( motor_counter_a & 8 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    if( motor_counter_a == 15 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    if( motor_counter_b & 8 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    if( motor_counter_b == 15 )
     r1 += 1.0/33000;
    else
     r0 += 1.0/33000;
    r0 = 1.0/r0;
    r1 = 1.0/r1;
    motor_amp_new = (int)(32767 * r0 / (r0 + r1));
    if( motor_amp_new > motor_amp )
     motor_amp_step = (int)((motor_amp_new - motor_amp) / (r1*0.47e-6));
    else
     motor_amp_step = (int)((motor_amp - motor_amp_new) / (r0*0.47e-6));
   }
   if( motor_amp != motor_amp_new )
   {
    motor_amp_counter -= motor_amp_step;
    if( motor_amp_counter < 0 )
    {
     int n = (-motor_amp_counter / Machine->sample_rate) + 1;
     motor_amp_counter += n * Machine->sample_rate;
     if( motor_amp > motor_amp_new )
     {
      motor_amp -= n;
      if( motor_amp < motor_amp_new )
       motor_amp = motor_amp_new;
     }
     else
     {
      motor_amp += n;
      if( motor_amp > motor_amp_new )
       motor_amp = motor_amp_new;
     }
    }
   }
   sum += ((motor_amp<motor_amp_new) ? 0x7fff - discharge[0x7fff-motor_amp] : discharge[motor_amp])/3;
  }
  *buffer++ = (sum + last_val) / 2;
  last_val = (sum + last_val * 3) / 4;
 }
}

variable_types: param int

variable_types:
buffer
short *

variable_types: length int

variable_types: sum int

variable_types: clock int


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

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

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

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


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

if ( latch != a2 )
{
stream_update((unsigned int)channel, 0LL);
latch = a2;
result = mixer_sound_enable_global_w(a2 & 0x20);
}
return result;
}

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

if ( latch != a2 )
{
stream_update((unsigned int)channel, 0LL);
latch = a2;
result = mixer_sound_enable_global_w(a2 & 0x20);
}
return result;
}

original_code:
void bzone_sounds_w(offs_t offset,data_t data)
{
 if( data == latch )
  return;
 stream_update(channel, 0);
    latch = data;
    mixer_sound_enable_global_w(latch & 0x20);
}

canonical_original_code:
void bzone_sounds_w(unsigned int offset, unsigned int data)
{
 if( data == latch )
  return;
 stream_update(channel, 0);
    latch = data;
    mixer_sound_enable_global_w(latch & 0x20);
}


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

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

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

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

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

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

variable_types: i int

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


decompiled_code:
void bzone_sh_stop()
{
if ( discharge )
free(discharge);
discharge = 0LL;
}

canonical_decompiled_code:
void func4()
{
if ( discharge )
free(discharge);
discharge = 0LL;
}

original_code:
void bzone_sh_stop(void)
{
 if( discharge )
  free(discharge);
 discharge = ((void *)0);
}

canonical_original_code:
void bzone_sh_stop()
{
 if( discharge )
  free(discharge);
 discharge = ((void *)0);
}


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

v0 = readinputport(3LL);
return one_joy_trans[readinputport(4LL) & 0x1F] | v0;
}

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

v0 = readinputport(3LL);
return one_joy_trans[readinputport(4LL) & 0x1F] | v0;
}

original_code:
static data_t bzone_IN3_r(offs_t offset)
{
 int res,res1;
 res=readinputport(3);
 res1=readinputport(4);
 res|=one_joy_trans[res1&0x1f];
 return (res);
}

canonical_original_code:
static unsigned int bzone_IN3_r(unsigned int offset)
{
 int res; int res1;
 res=readinputport(3);
 res1=readinputport(4);
 res|=one_joy_trans[res1&0x1f];
 return (res);
}

variable_types:
offset
unsigned int

variable_types: res int


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

if ( rb_input_select )
result = readinputport(5LL);
else
result = readinputport(6LL);
return result;
}

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

if ( rb_input_select )
result = readinputport(5LL);
else
result = readinputport(6LL);
return result;
}

original_code:
static data_t redbaron_joy_r(offs_t offset)
{
 if (rb_input_select)
  return readinputport (5);
 else
  return readinputport (6);
}

canonical_original_code:
static unsigned int redbaron_joy_r(unsigned int offset)
{
 if (rb_input_select)
  return readinputport (5);
 else
  return readinputport (6);
}


decompiled_code:
__int64 bzone_IN0_r()
{
int v0; // edx
int v1; // eax
int v2; // ebx
int v3; // edx
__int64 result; // rax
unsigned int v5; // ebx

v2 = readinputport(0LL);
v0 = cpu_gettotalcycles();
v1 = v2;
LOBYTE(v1) = v2 | 0x80;
LOBYTE(v2) = v2 & 0x7F;
if ( (v0 & 0x100) != 0 )
v2 = v1;
v3 = avgdvg_done();
result = v2 | 0x40u;
v5 = v2 & 0xFFFFFFBF;
if ( !v3 )
result = v5;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edx
int v1; // eax
int v2; // ebx
int v3; // edx
__int64 result; // rax
unsigned int v5; // ebx

v2 = readinputport(0LL);
v0 = cpu_gettotalcycles();
v1 = v2;
LOBYTE(v1) = v2 | 0x80;
LOBYTE(v2) = v2 & 0x7F;
if ( (v0 & 0x100) != 0 )
v2 = v1;
v3 = avgdvg_done();
result = v2 | 0x40u;
v5 = v2 & 0xFFFFFFBF;
if ( !v3 )
result = v5;
return result;
}

original_code:
data_t bzone_IN0_r(offs_t offset)
{
 int res;
 res = readinputport(0);
 if (cpu_gettotalcycles() & 0x100)
  res |= (1<<7);
 else
  res &= ~(1<<7);
 if (avgdvg_done())
  res |= (1<<6);
 else
  res &= ~(1<<6);
 return res;
}

canonical_original_code:
unsigned int bzone_IN0_r(unsigned int offset)
{
 int res;
 res = readinputport(0);
 if (cpu_gettotalcycles() & 0x100)
  res |= (1<<7);
 else
  res &= ~(1<<7);
 if (avgdvg_done())
  res |= (1<<6);
 else
  res &= ~(1<<6);
 return res;
}


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

if ( (readinputport(0LL) & 0x10) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (readinputport(0LL) & 0x10) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int bzone_interrupt(void)
{
 if (readinputport(0) & 0x10)
  return nmi_interrupt();
 else
  return ignore_interrupt();
}

canonical_original_code:
static int bzone_interrupt()
{
 if (readinputport(0) & 0x10)
  return nmi_interrupt();
 else
  return ignore_interrupt();
}


decompiled_code:
void mnight_init_machine()
{
main_cpu_num = 0;
}

canonical_decompiled_code:
void func2()
{
main_cpu_num = 0;
}

original_code:
void mnight_init_machine(void)
{
 main_cpu_num = 0;
}


decompiled_code:
__int64 mnight_interrupt()
{
return 215LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 215LL;
}

original_code:
int mnight_interrupt(void)
{
 return 0x00d7;
}

canonical_original_code:
int mnight_interrupt()
{
 return 0x00d7;
}


decompiled_code:
__int64 mnight_bankselect_r()
{
return (unsigned int)mnight_bank_latch;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)mnight_bank_latch;
}

original_code:
data_t mnight_bankselect_r(offs_t offset)
{
 return mnight_bank_latch;
}

canonical_original_code:
unsigned int mnight_bankselect_r(unsigned int offset)
{
 return mnight_bank_latch;
}


decompiled_code:
__int64 mnight_vh_start()
{
_QWORD *v0; // rdx
__int64 v1; // rax
__int64 v2; // rcx
int v3; // edx
__int64 result; // rax

bg_dirtybuffer = malloc(0x400uLL);
if ( !bg_dirtybuffer )
return 1LL;
bitmap_bg = (void *)bitmap_alloc(
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL)),
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)));
if ( bitmap_bg )
{
bitmap_sp = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_sp )
{
v0 = bg_dirtybuffer;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1024) >> 3));
memset(palette_used_colors, 3, *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL));
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
if ( *(int *)(v2 + 24) <= 0 )
{
result = 0LL;
}
else
{
v3 = 0;
do
{
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v1 + 824) + 688LL) + 40LL)
+ *(_DWORD *)(v2 + 12) * v3
+ 15) = 7;
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 64LL)
+ *(_DWORD *)(*(_QWORD *)(Machine + 528LL) + 12LL) * v3++
+ 15) = 7;
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v2 + 24) > v3 );
result = 0LL;
}
}
else
{
free(bg_dirtybuffer);
free(bitmap_bg);
result = 1LL;
}
}
else
{
free(bg_dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
_QWORD *v0; // rdx
__int64 v1; // rax
__int64 v2; // rcx
int v3; // edx
__int64 result; // rax

bg_dirtybuffer = malloc(0x400uLL);
if ( !bg_dirtybuffer )
return 1LL;
bitmap_bg = (void *)bitmap_alloc(
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 664LL)),
(unsigned int)(2 * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL)));
if ( bitmap_bg )
{
bitmap_sp = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( bitmap_sp )
{
v0 = bg_dirtybuffer;
*(_QWORD *)bg_dirtybuffer = 0x101010101010101LL;
v0[127] = 0x101010101010101LL;
memset(
(void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL),
1u,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 1024) >> 3));
memset(palette_used_colors, 3, *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL));
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
if ( *(int *)(v2 + 24) <= 0 )
{
result = 0LL;
}
else
{
v3 = 0;
do
{
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v1 + 824) + 688LL) + 40LL)
+ *(_DWORD *)(v2 + 12) * v3
+ 15) = 7;
*((_BYTE *)palette_used_colors
+ *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 64LL)
+ *(_DWORD *)(*(_QWORD *)(Machine + 528LL) + 12LL) * v3++
+ 15) = 7;
v1 = Machine;
v2 = *(_QWORD *)(Machine + 520LL);
}
while ( *(_DWORD *)(v2 + 24) > v3 );
result = 0LL;
}
}
else
{
free(bg_dirtybuffer);
free(bitmap_bg);
result = 1LL;
}
}
else
{
free(bg_dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
int mnight_vh_start(void)
{
 int i;
 if ((bg_dirtybuffer = (unsigned char*)malloc(1024)) == 0)
 {
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc (Machine->drv->screen_width*2,Machine->drv->screen_height*2)) == 0)
 {
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_sp = bitmap_alloc (Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(bg_dirtybuffer);
  free(bitmap_bg);
  return 1;
 }
 memset(bg_dirtybuffer,1,1024);
 memset(palette_used_colors,(1|2),Machine->drv->total_colors * sizeof(unsigned char));
 for (i = 0;i < Machine->gfx[1]->total_colors;i++)
 {
  palette_used_colors[Machine->drv->gfxdecodeinfo[1].color_codes_start + i * Machine->gfx[1]->color_granularity+15] = (4|(1|2));
  palette_used_colors[Machine->drv->gfxdecodeinfo[2].color_codes_start + i * Machine->gfx[2]->color_granularity+15] = (4|(1|2));
 }
 return 0;
}

canonical_original_code:
int mnight_vh_start()
{
 int i;
 if ((bg_dirtybuffer = (unsigned char *)malloc(1024)) == 0)
 {
  return 1;
 }
 if ((bitmap_bg = bitmap_alloc (Machine->drv->screen_width*2,Machine->drv->screen_height*2)) == 0)
 {
  free(bg_dirtybuffer);
  return 1;
 }
 if ((bitmap_sp = bitmap_alloc (Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(bg_dirtybuffer);
  free(bitmap_bg);
  return 1;
 }
 memset(bg_dirtybuffer,1,1024);
 memset(palette_used_colors,(1|2),Machine->drv->total_colors * sizeof(unsigned char));
 for (i = 0;i < Machine->gfx[1]->total_colors;i++)
 {
  palette_used_colors[Machine->drv->gfxdecodeinfo[1].color_codes_start + i * Machine->gfx[1]->color_granularity+15] = (4|(1|2));
  palette_used_colors[Machine->drv->gfxdecodeinfo[2].color_codes_start + i * Machine->gfx[2]->color_granularity+15] = (4|(1|2));
 }
 return 0;
}


decompiled_code:
void mnight_vh_stop()
{
bitmap_free(bitmap_bg);
bitmap_free(bitmap_sp);
free(bg_dirtybuffer);
}

canonical_decompiled_code:
void func6()
{
bitmap_free(bitmap_bg);
bitmap_free(bitmap_sp);
free(bg_dirtybuffer);
}

original_code:
void mnight_vh_stop(void)
{
 bitmap_free(bitmap_bg);
 bitmap_free(bitmap_sp);
 free(bg_dirtybuffer);
}


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

if ( bg_enable != a2 )
{
*(_BYTE *)(mnight_bgenable_ram + a1) = a2;
bg_enable = a2;
if ( a2 )
result = memset(bg_dirtybuffer, 1, mnight_backgroundram_size >> 1);
else
result = (void *)fillbitmap(bitmap_bg, palette_transparent_pen, 0LL);
}
return result;
}

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

if ( bg_enable != a2 )
{
*(_BYTE *)(mnight_bgenable_ram + a1) = a2;
bg_enable = a2;
if ( a2 )
result = memset(bg_dirtybuffer, 1, mnight_backgroundram_size >> 1);
else
result = (void *)fillbitmap(bitmap_bg, palette_transparent_pen, 0LL);
}
return result;
}

original_code:
void mnight_background_enable_w(offs_t offset,data_t data)
{
 if (bg_enable!=data)
 {
  mnight_bgenable_ram[offset] = data;
  bg_enable = data;
  if (bg_enable)
   memset(bg_dirtybuffer, 1, mnight_backgroundram_size / 2);
  else
   fillbitmap(bitmap_bg, palette_transparent_pen,0);
 }
}

canonical_original_code:
void mnight_background_enable_w(unsigned int offset, unsigned int data)
{
 if (bg_enable!=data)
 {
  mnight_bgenable_ram[offset] = data;
  bg_enable = data;
  if (bg_enable)
   memset(bg_dirtybuffer, 1, mnight_backgroundram_size / 2);
  else
   fillbitmap(bitmap_bg, palette_transparent_pen,0);
 }
}

variable_types:
data
unsigned int


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

result = a2 & 1;
if ( (_DWORD)result != sp_overdraw )
{
*(_BYTE *)(mnight_spoverdraw_ram + a1) = a2;
result = fillbitmap(bitmap_sp, 15LL, Machine + 776LL);
sp_overdraw = a2 & 1;
}
return result;
}

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

result = a2 & 1;
if ( (_DWORD)result != sp_overdraw )
{
*(_BYTE *)(mnight_spoverdraw_ram + a1) = a2;
result = fillbitmap(bitmap_sp, 15LL, Machine + 776LL);
sp_overdraw = a2 & 1;
}
return result;
}

original_code:
void mnight_sprite_overdraw_w(offs_t offset,data_t data)
{
 if (sp_overdraw != (data&1))
 {
  mnight_spoverdraw_ram[offset] = data;
  fillbitmap(bitmap_sp,15,&Machine->visible_area);
  sp_overdraw = data & 1;
 }
}

canonical_original_code:
void mnight_sprite_overdraw_w(unsigned int offset, unsigned int data)
{
 if (sp_overdraw != (data&1))
 {
  mnight_spoverdraw_ram[offset] = data;
  fillbitmap(bitmap_sp,15,&Machine->visible_area);
  sp_overdraw = data & 1;
 }
}


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

result = (char *)memory_region((unsigned int)(main_cpu_num + 129));
if ( mnight_bank_latch != a2 )
{
mnight_bank_latch = a2;
cpu_bankbase[1] = &result[0x4000 * (a2 & 7) + 0x10000];
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v3);
}
}
return result;
}

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

result = (char *)memory_region((unsigned int)(main_cpu_num + 129));
if ( mnight_bank_latch != a2 )
{
mnight_bank_latch = a2;
cpu_bankbase[1] = &result[0x4000 * (a2 & 7) + 0x10000];
result = (char *)&ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (char *)cpu_setOPbase16(v3);
}
}
return result;
}

original_code:
void mnight_bankselect_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU1+main_cpu_num);
 int bankaddress;
 if ( data != mnight_bank_latch )
 {
  mnight_bank_latch = data;
  bankaddress = 0x10000 + ((data & 0x7) * 0x4000);
  { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

canonical_original_code:
void mnight_bankselect_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU1+main_cpu_num);
 int bankaddress;
 if ( data != mnight_bank_latch )
 {
  mnight_bank_latch = data;
  bankaddress = 0x10000 + ((data & 0x7) * 0x4000);
  { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0xF) + 16) << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 0xF) + 16) << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void junofrst_bankselect_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x0f) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void junofrst_bankselect_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x0f) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


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

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

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

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

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

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

variable_types: last int


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

if ( i8039_irqenable )
result = cpu_cause_interrupt(2LL, 1LL);
return result;
}

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

if ( i8039_irqenable )
result = cpu_cause_interrupt(2LL, 1LL);
return result;
}

original_code:
void junofrst_i8039_irq_w(offs_t offset,data_t data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(2,1);
}

canonical_original_code:
void junofrst_i8039_irq_w(unsigned int offset, unsigned int data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(2,1);
}


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

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

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

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


decompiled_code:
__int64 __fastcall junofrst_portB_w(__int64 a1, unsigned int a2)
{
unsigned int i; // ebp
__int64 v4; // r8
__int64 result; // rax

for ( i = 0; i != 3; ++i )
{
v4 = -(a2 & 1) & 0xB798;
if ( (a2 & 2) != 0 )
v4 = (unsigned int)(v4 + 220000);
a2 >>= 2;
result = set_RC_filter(i, 1000LL, 2200LL, 200LL, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
unsigned int i; // ebp
__int64 v4; // r8
__int64 result; // rax

for ( i = 0; i != 3; ++i )
{
v4 = -(a2 & 1) & 0xB798;
if ( (a2 & 2) != 0 )
v4 = (unsigned int)(v4 + 220000);
a2 >>= 2;
result = set_RC_filter(i, 1000LL, 2200LL, 200LL, v4);
}
return result;
}

original_code:
static void junofrst_portB_w(offs_t offset,data_t data)
{
 int i;
 for (i = 0;i < 3;i++)
 {
  int C;
  C = 0;
  if (data & 1) C += 47000;
  if (data & 2) C += 220000;
  data >>= 2;
  set_RC_filter(i,1000,2200,200,C);
 }
}

canonical_original_code:
static void junofrst_portB_w(unsigned int offset, unsigned int data)
{
 int i;
 for (i = 0;i < 3;i++)
 {
  int C;
  C = 0;
  if (data & 1) C += 47000;
  if (data & 2) C += 220000;
  data >>= 2;
  set_RC_filter(i,1000,2200,200,C);
 }
}

variable_types: C int


decompiled_code:
__int64 junofrst_portA_r()
{
int v0; // edx
unsigned int v1; // eax

v0 = cpu_gettotalcycles();
v1 = v0 + 511;
if ( v0 >= 0 )
v1 = v0;
return i8039_status | (v1 >> 5) & 0xF0;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edx
unsigned int v1; // eax

v0 = cpu_gettotalcycles();
v1 = v0 + 511;
if ( v0 >= 0 )
v1 = v0;
return i8039_status | (v1 >> 5) & 0xF0;
}

original_code:
static data_t junofrst_portA_r(offs_t offset)
{
 int timer;
 timer = (cpu_gettotalcycles() / (1024/2)) & 0x0f;
 return (timer << 4) | i8039_status;
}

canonical_original_code:
static unsigned int junofrst_portA_r(unsigned int offset)
{
 int timer;
 timer = (cpu_gettotalcycles() / (1024/2)) & 0x0f;
 return (timer << 4) | i8039_status;
}

variable_types: timer int


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

result = (unsigned __int8)a2 & 0x80;
i8039_irqenable = a2 & 0x80;
i8039_status = (a2 >> 4) & 7;
return result;
}

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

result = (unsigned __int8)a2 & 0x80;
i8039_irqenable = a2 & 0x80;
i8039_status = (a2 >> 4) & 7;
return result;
}

original_code:
static void i8039_irqen_and_status_w(offs_t offset,data_t data)
{
 i8039_irqenable = data & 0x80;
 i8039_status = (data & 0x70) >> 4;
}

canonical_original_code:
static void i8039_irqen_and_status_w(unsigned int offset, unsigned int data)
{
 i8039_irqenable = data & 0x80;
 i8039_status = (data & 0x70) >> 4;
}


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

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

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

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


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

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

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

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

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

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


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

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

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


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

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_4B4 = K053251_get_palette_index(4LL);
dword_4B8 = K053251_get_palette_index(3LL);
K052109_tilemap_update();
palette_init_used_colors();
K053245_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_49C = K053251_get_priority(4LL);
v4 = 2;
dword_4A0 = K053251_get_priority(3LL);
sortlayers((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053245_sprites_draw(a1);
}

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

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_4B4 = K053251_get_palette_index(4LL);
dword_4B8 = K053251_get_palette_index(3LL);
K052109_tilemap_update();
palette_init_used_colors();
K053245_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_49C = K053251_get_priority(4LL);
v4 = 2;
dword_4A0 = K053251_get_priority(3LL);
func2((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053245_sprites_draw(a1);
}

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

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

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

variable_types:
layer
int [3]