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

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

original_code: static data_t dcon_background_r(offs_t offset) { return (*(UINT16 *)(&dcon_back_data[offset])); }

canonical_original_code: static unsigned int dcon_background_r(unsigned int offset) { return (*(unsigned short *)(&dcon_back_data[offset])); }


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

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

original_code: static data_t dcon_foreground_r(offs_t offset) { return (*(UINT16 *)(&dcon_fore_data[offset])); }

canonical_original_code: static unsigned int dcon_foreground_r(unsigned int offset) { return (*(unsigned short *)(&dcon_fore_data[offset])); }

variable_types:
offset
unsigned int

return_type: unsigned int


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

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

original_code: static data_t dcon_midground_r(offs_t offset) { return (*(UINT16 *)(&dcon_mid_data[offset])); }

canonical_original_code: static unsigned int dcon_midground_r(unsigned int offset) { return (*(unsigned short *)(&dcon_mid_data[offset])); }


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

dcon_enable = a2;
if ( (a2 & 4) != 0 )
tilemap_set_enable(foreground_layer, 0LL);
else
tilemap_set_enable(foreground_layer, 1LL);
if ( (dcon_enable & 2) != 0 )
tilemap_set_enable(midground_layer, 0LL);
else
tilemap_set_enable(midground_layer, 1LL);
if ( (dcon_enable & 1) != 0 )
result = tilemap_set_enable(background_layer, 0LL);
else
result = tilemap_set_enable(background_layer, 1LL);
return result;
}

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

dcon_enable = a2;
if ( (a2 & 4) != 0 )
tilemap_set_enable(foreground_layer, 0LL);
else
tilemap_set_enable(foreground_layer, 1LL);
if ( (dcon_enable & 2) != 0 )
tilemap_set_enable(midground_layer, 0LL);
else
tilemap_set_enable(midground_layer, 1LL);
if ( (dcon_enable & 1) != 0 )
result = tilemap_set_enable(background_layer, 0LL);
else
result = tilemap_set_enable(background_layer, 1LL);
return result;
}

original_code:
void dcon_control_w(offs_t offset,data_t data)
{
 dcon_enable=data;
 if ((dcon_enable&4)==4)
  tilemap_set_enable(foreground_layer,0);
 else
  tilemap_set_enable(foreground_layer,1);
 if ((dcon_enable&2)==2)
  tilemap_set_enable(midground_layer,0);
 else
  tilemap_set_enable(midground_layer,1);
 if ((dcon_enable&1)==1)
  tilemap_set_enable(background_layer,0);
 else
  tilemap_set_enable(background_layer,1);
}

canonical_original_code:
void dcon_control_w(unsigned int offset, unsigned int data)
{
 dcon_enable=data;
 if ((dcon_enable&4)==4)
  tilemap_set_enable(foreground_layer,0);
 else
  tilemap_set_enable(foreground_layer,1);
 if ((dcon_enable&2)==2)
  tilemap_set_enable(midground_layer,0);
 else
  tilemap_set_enable(midground_layer,1);
 if ((dcon_enable&1)==1)
  tilemap_set_enable(background_layer,0);
 else
  tilemap_set_enable(background_layer,1);
}

variable_types:
data
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall dcon_background_w(unsigned int a1, int a2)
{
*(_WORD *)(dcon_back_data + a1) = a2 | *(_WORD *)(dcon_back_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(background_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
*(_WORD *)(dcon_back_data + a1) = a2 | *(_WORD *)(dcon_back_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(background_layer, a1 >> 1);
}

original_code:
void dcon_background_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&dcon_back_data[offset])) = (((*(UINT16 *)(&dcon_back_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( background_layer,offset/2);
}

canonical_original_code:
void dcon_background_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&dcon_back_data[offset])) = (((*(unsigned short *)(&dcon_back_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( background_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dcon_foreground_w(unsigned int a1, int a2)
{
*(_WORD *)(dcon_fore_data + a1) = a2 | *(_WORD *)(dcon_fore_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(foreground_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2)
{
*(_WORD *)(dcon_fore_data + a1) = a2 | *(_WORD *)(dcon_fore_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(foreground_layer, a1 >> 1);
}

original_code:
void dcon_foreground_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&dcon_fore_data[offset])) = (((*(UINT16 *)(&dcon_fore_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( foreground_layer,offset/2);
}

canonical_original_code:
void dcon_foreground_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&dcon_fore_data[offset])) = (((*(unsigned short *)(&dcon_fore_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( foreground_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dcon_midground_w(unsigned int a1, int a2)
{
*(_WORD *)(dcon_mid_data + a1) = a2 | *(_WORD *)(dcon_mid_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(midground_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, int a2)
{
*(_WORD *)(dcon_mid_data + a1) = a2 | *(_WORD *)(dcon_mid_data + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(midground_layer, a1 >> 1);
}

original_code:
void dcon_midground_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&dcon_mid_data[offset])) = (((*(UINT16 *)(&dcon_mid_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( midground_layer,offset/2);
}

canonical_original_code:
void dcon_midground_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&dcon_mid_data[offset])) = (((*(unsigned short *)(&dcon_mid_data[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( midground_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dcon_text_w(unsigned int a1, int a2)
{
*(_WORD *)(videoram + a1) = a2 | *(_WORD *)(videoram + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(text_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, int a2)
{
*(_WORD *)(videoram + a1) = a2 | *(_WORD *)(videoram + a1) & HIWORD(a2);
return tilemap_mark_tile_dirty(text_layer, a1 >> 1);
}

original_code:
void dcon_text_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&videoram[offset])) = (((*(UINT16 *)(&videoram[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( text_layer,offset/2);
}

canonical_original_code:
void dcon_text_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&videoram[offset])) = (((*(unsigned short *)(&videoram[offset])) & ((data) >> 16)) | (data))));
 tilemap_mark_tile_dirty( text_layer,offset/2);
}


decompiled_code:
__int64 dcon_vh_start()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v3; // [rsp+0h] [rbp-18h]
__int64 v4; // [rsp+0h] [rbp-18h]
__int64 v5; // [rsp+0h] [rbp-18h]

background_layer = tilemap_create(get_back_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v3) = 32;
foreground_layer = tilemap_create(get_fore_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v3);
LODWORD(v4) = 32;
midground_layer = tilemap_create(get_mid_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v4);
LODWORD(v5) = 32;
v0 = tilemap_create(get_text_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v5);
text_layer = v0;
if ( !background_layer )
return 1LL;
v1 = foreground_layer;
if ( !foreground_layer )
return 1LL;
if ( !v0 || !midground_layer )
return 1LL;
*(_DWORD *)(midground_layer + 132) = 15;
*(_DWORD *)(v1 + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v3; // [rsp+0h] [rbp-18h]
__int64 v4; // [rsp+0h] [rbp-18h]
__int64 v5; // [rsp+0h] [rbp-18h]

background_layer = tilemap_create(get_back_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v3) = 32;
foreground_layer = tilemap_create(get_fore_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v3);
LODWORD(v4) = 32;
midground_layer = tilemap_create(get_mid_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v4);
LODWORD(v5) = 32;
v0 = tilemap_create(get_text_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v5);
text_layer = v0;
if ( !background_layer )
return 1LL;
v1 = foreground_layer;
if ( !foreground_layer )
return 1LL;
if ( !v0 || !midground_layer )
return 1LL;
*(_DWORD *)(midground_layer + 132) = 15;
*(_DWORD *)(v1 + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

original_code:
int dcon_vh_start(void)
{
 background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 midground_layer = tilemap_create(get_mid_tile_info, tilemap_scan_rows,0x01,16,16,32,32);
 text_layer = tilemap_create(get_text_tile_info,tilemap_scan_rows,0x01, 8,8,64,32);
 if (!background_layer || !foreground_layer || !midground_layer || !text_layer)
  return 1;
 midground_layer->transparent_pen = 15;
 foreground_layer->transparent_pen = 15;
 text_layer->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int dcon_vh_start()
{
 background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 midground_layer = tilemap_create(get_mid_tile_info, tilemap_scan_rows,0x01,16,16,32,32);
 text_layer = tilemap_create(get_text_tile_info,tilemap_scan_rows,0x01, 8,8,64,32);
 if (!background_layer || !foreground_layer || !midground_layer || !text_layer)
  return 1;
 midground_layer->transparent_pen = 15;
 foreground_layer->transparent_pen = 15;
 text_layer->transparent_pen = 15;
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall dcon_vh_screenrefresh(__int64 a1)
{
tilemap_set_scrollx(background_layer, 0LL, (unsigned __int16)*dcon_scroll_ram);
tilemap_set_scrolly(background_layer, 0LL, (unsigned __int16)dcon_scroll_ram[1]);
tilemap_set_scrollx(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[2]);
tilemap_set_scrolly(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[3]);
tilemap_set_scrollx(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[4]);
tilemap_set_scrolly(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[5]);
tilemap_update(0LL);
palette_init_used_colors();
mark_sprite_colours();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( (dcon_enable & 1) != 0 )
fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
else
tilemap_draw(a1, background_layer, 0LL);
draw_sprites(a1, 2);
tilemap_draw(a1, midground_layer, 0LL);
draw_sprites(a1, 1);
tilemap_draw(a1, foreground_layer, 0LL);
draw_sprites(a1, 0);
draw_sprites(a1, 3);
return tilemap_draw(a1, text_layer, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
tilemap_set_scrollx(background_layer, 0LL, (unsigned __int16)*dcon_scroll_ram);
tilemap_set_scrolly(background_layer, 0LL, (unsigned __int16)dcon_scroll_ram[1]);
tilemap_set_scrollx(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[2]);
tilemap_set_scrolly(midground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[3]);
tilemap_set_scrollx(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[4]);
tilemap_set_scrolly(foreground_layer, 0LL, (unsigned __int16)dcon_scroll_ram[5]);
tilemap_update(0LL);
palette_init_used_colors();
func4();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( (dcon_enable & 1) != 0 )
fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
else
tilemap_draw(a1, background_layer, 0LL);
func14(a1, 2);
tilemap_draw(a1, midground_layer, 0LL);
func14(a1, 1);
tilemap_draw(a1, foreground_layer, 0LL);
func14(a1, 0);
func14(a1, 3);
return tilemap_draw(a1, text_layer, 0LL);
}

original_code:
void dcon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_set_scrollx( background_layer,0, (*(UINT16 *)(&dcon_scroll_ram[0])) );
 tilemap_set_scrolly( background_layer,0, (*(UINT16 *)(&dcon_scroll_ram[2])) );
 tilemap_set_scrollx( midground_layer, 0, (*(UINT16 *)(&dcon_scroll_ram[4])) );
 tilemap_set_scrolly( midground_layer, 0, (*(UINT16 *)(&dcon_scroll_ram[6])) );
 tilemap_set_scrollx( foreground_layer,0, (*(UINT16 *)(&dcon_scroll_ram[8])) );
 tilemap_set_scrolly( foreground_layer,0, (*(UINT16 *)(&dcon_scroll_ram[0xa])) );
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colours();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if ((dcon_enable&1)!=1)
  tilemap_draw(bitmap,background_layer,0);
 else
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
 draw_sprites(bitmap,2);
 tilemap_draw(bitmap,midground_layer,0);
 draw_sprites(bitmap,1);
 tilemap_draw(bitmap,foreground_layer,0);
 draw_sprites(bitmap,0);
 draw_sprites(bitmap,3);
 tilemap_draw(bitmap,text_layer,0);
}

canonical_original_code:
void dcon_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_set_scrollx( background_layer,0, (*(unsigned short *)(&dcon_scroll_ram[0])) );
 tilemap_set_scrolly( background_layer,0, (*(unsigned short *)(&dcon_scroll_ram[2])) );
 tilemap_set_scrollx( midground_layer, 0, (*(unsigned short *)(&dcon_scroll_ram[4])) );
 tilemap_set_scrolly( midground_layer, 0, (*(unsigned short *)(&dcon_scroll_ram[6])) );
 tilemap_set_scrollx( foreground_layer,0, (*(unsigned short *)(&dcon_scroll_ram[8])) );
 tilemap_set_scrolly( foreground_layer,0, (*(unsigned short *)(&dcon_scroll_ram[0xa])) );
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colours();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if ((dcon_enable&1)!=1)
  tilemap_draw(bitmap,background_layer,0);
 else
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
 draw_sprites(bitmap,2);
 tilemap_draw(bitmap,midground_layer,0);
 draw_sprites(bitmap,1);
 tilemap_draw(bitmap,foreground_layer,0);
 draw_sprites(bitmap,0);
 draw_sprites(bitmap,3);
 tilemap_draw(bitmap,text_layer,0);
}

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


decompiled_code:
__int64 init_dcon()
{
return install_seibu_sound_speedup(1LL);
}

canonical_decompiled_code:
__int64 func16()
{
return install_seibu_sound_speedup(1LL);
}

original_code:
static void init_dcon(void)
{
 install_seibu_sound_speedup(1);
}

canonical_original_code:
static void init_dcon()
{
 install_seibu_sound_speedup(1);
}


decompiled_code:
__int64 __fastcall dcon_sound_w(__int64 a1, unsigned __int8 a2)
{
return seibu_soundlatch_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
return seibu_soundlatch_w(a1, a2);
}

original_code:
static void dcon_sound_w(offs_t offset,data_t data)
{
 seibu_soundlatch_w(offset,data&0xff);
}

canonical_original_code:
static void dcon_sound_w(unsigned int offset, unsigned int data)
{
 seibu_soundlatch_w(offset,data&0xff);
}


decompiled_code:
__int64 __fastcall dcon_control_r(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebx

if ( a1 == 2 )
{
v3 = readinputport(0LL);
result = v3 + ((unsigned int)readinputport(1LL) << 8);
}
else if ( a1 == 4 )
{
result = readinputport(2LL);
}
else
{
result = 0xFFFFLL;
if ( !a1 )
{
v2 = readinputport(4LL);
result = v2 + ((unsigned int)readinputport(3LL) << 8);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
__int64 result; // rax
int v2; // ebx
int v3; // ebx

if ( a1 == 2 )
{
v3 = readinputport(0LL);
result = v3 + ((unsigned int)readinputport(1LL) << 8);
}
else if ( a1 == 4 )
{
result = readinputport(2LL);
}
else
{
result = 0xFFFFLL;
if ( !a1 )
{
v2 = readinputport(4LL);
result = v2 + ((unsigned int)readinputport(3LL) << 8);
}
}
return result;
}

original_code:
static data_t dcon_control_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return (readinputport(4) + (readinputport(3) << 8));
  case 2:
   return (readinputport(0) + (readinputport(1) << 8));
  case 4:
   return readinputport(2);
 }
 return 0xffff;
}

canonical_original_code:
static unsigned int dcon_control_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return (readinputport(4) + (readinputport(3) << 8));
  case 2:
   return (readinputport(0) + (readinputport(1) << 8));
  case 4:
   return readinputport(2);
 }
 return 0xffff;
}


decompiled_code:
__int64 __fastcall get_back_tile_info(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(dcon_back_data + 2 * a1);
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(dcon_back_data + 2 * a1);
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_back_tile_info(int tile_index)
{
 int tile=(*(UINT16 *)(&dcon_back_data[2*tile_index]));
 int color=(tile>>12)&0xf;
 tile&=0xfff;
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_back_tile_info(int tile_index)
{
 int tile = (*(UINT16 *)(&dcon_back_data[2*tile_index]));
 int color = (tile>>12)&0xf;
 tile&=0xfff;
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types: tile int

variable_types: color int

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


decompiled_code:
__int64 __fastcall get_fore_tile_info(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(dcon_fore_data + 2 * a1);
v2 = *(_QWORD *)(Machine + 528LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(dcon_fore_data + 2 * a1);
v2 = *(_QWORD *)(Machine + 528LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_fore_tile_info(int tile_index)
{
 int tile=(*(UINT16 *)(&dcon_fore_data[2*tile_index]));
 int color=(tile>>12)&0xf;
 tile&=0xfff;
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_fore_tile_info(int tile_index)
{
 int tile = (*(UINT16 *)(&dcon_fore_data[2*tile_index]));
 int color = (tile>>12)&0xf;
 tile&=0xfff;
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

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


decompiled_code:
__int64 __fastcall get_text_tile_info(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(videoram + 2 * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned __int16 v1; // cx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(videoram + 2 * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (v1 & 0xFFFu) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 >> 12);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_text_tile_info(int tile_index)
{
 int tile=(*(UINT16 *)(&videoram[2*tile_index]));
 int color=(tile>>12)&0xf;
 tile&=0xfff;
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_text_tile_info(int tile_index)
{
 int tile = (*(UINT16 *)(&videoram[2*tile_index]));
 int color = (tile>>12)&0xf;
 tile&=0xfff;
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (tile) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}


decompiled_code:
__int64 mark_sprite_colours()
{
__int64 v0; // rdx
int v1; // er10
char *v2; // rdi
char *v3; // rax
__int64 v4; // r9
unsigned __int16 *v5; // r11
__int64 v6; // rbp
int v7; // edx
int v8; // eax
int v9; // ecx
__int64 result; // rax
int v11; // ecx
int v12[64]; // [rsp+0h] [rbp-110h] BYREF
char v13[16]; // [rsp+100h] [rbp-10h] BYREF

v0 = Machine;
v1 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 112LL);
v2 = (char *)v12;
v3 = (char *)v12;
do
{
*(_DWORD *)v3 = 0;
v3 += 4;
}
while ( v3 != v13 );
v4 = *(_QWORD *)(*(_QWORD *)(v0 + 544) + 32LL);
v5 = (unsigned __int16 *)(spriteram + 8LL);
v6 = spriteram + 2048LL;
do
{
v7 = v12[*v5 & 0x3F];
v8 = v5[1] & 0x3FFF;
v9 = v8 + ((((int)*v5 >> 10) & 7) + 1) * ((((int)*v5 >> 7) & 7) + 1);
do
v7 |= *(_DWORD *)(v4 + 4LL * (v8++ & 0x3FFF));
while ( v8 != v9 );
v12[*v5 & 0x3F] = v7;
v5 += 4;
}
while ( v5 != (unsigned __int16 *)v6 );
do
{
v11 = *(_DWORD *)v2;
LODWORD(result) = 0;
do
{
if ( _bittest(&v11, result) )
*(_BYTE *)(palette_used_colors + (int)result + v1) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v2 += 4;
v1 += 16;
}
while ( v2 != v13 );
return result;
}

original_code:
static void mark_sprite_colours(void)
{
 int colmask[64],i,pal_base,color,offs,sprite,multi;
 pal_base = Machine->drv->gfxdecodeinfo[4].color_codes_start;
 for (color = 0;color < 64;color++) colmask[color] = 0;
 for (offs = 8;offs <0x800;offs += 8)
 {
  color = (*(UINT16 *)(&spriteram[offs+0]))&0x3f;
  sprite = (*(UINT16 *)(&spriteram[offs+2]));
  sprite &= 0x3fff;
  multi=((((*(UINT16 *)(&spriteram[offs+0]))&0x0380)>>7)+1)*((((*(UINT16 *)(&spriteram[offs+0]))&0x1c00)>>10)+1);
  for (i=0; i<multi; i++)
   colmask[color] |= Machine->gfx[4]->pen_usage[(sprite+i)&0x3fff];
 }
 for (color = 0;color < 64;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

canonical_original_code:
static void mark_sprite_colours()
{
 int colmask[64]; int i; int pal_base; int color; int offs; int sprite; int multi;
 pal_base = Machine->drv->gfxdecodeinfo[4].color_codes_start;
 for (color = 0;color < 64;color++) colmask[color] = 0;
 for (offs = 8;offs <0x800;offs += 8)
 {
  color = (*(unsigned short *)(&spriteram[offs+0]))&0x3f;
  sprite = (*(unsigned short *)(&spriteram[offs+2]));
  sprite &= 0x3fff;
  multi=((((*(unsigned short *)(&spriteram[offs+0]))&0x0380)>>7)+1)*((((*(unsigned short *)(&spriteram[offs+0]))&0x1c00)>>10)+1);
  for (i=0; i<multi; i++)
   colmask[color] |= Machine->gfx[4]->pen_usage[(sprite+i)&0x3fff];
 }
 for (color = 0;color < 64;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

variable_types:
colmask
int [64]

variable_types: i int

variable_types: offs int

variable_types: sprite int

variable_types: multi int


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int16 v3; // dx
unsigned __int16 v4; // bx
__int16 v5; // r12
unsigned int v6; // ebx
__int16 v7; // si
__int16 v8; // ax
unsigned int v9; // ecx
unsigned int v10; // eax
unsigned __int16 v11; // r15
int v12; // er12
__int64 v13; // rbp
unsigned int v14; // [rsp+Ch] [rbp-5Ch]
__int64 i; // [rsp+10h] [rbp-58h]
unsigned int v16; // [rsp+18h] [rbp-50h]
int v17; // [rsp+1Ch] [rbp-4Ch]
unsigned int v18; // [rsp+20h] [rbp-48h]
unsigned int v19; // [rsp+28h] [rbp-40h]

for ( i = 2040LL; i != -8; result = i )
{
v3 = *(_WORD *)(spriteram + i);
if ( (v3 & 0x8000u) != 0 )
{
v4 = *(_WORD *)(spriteram + i + 2);
if ( (int)v4 >> 14 == a2 )
{
v5 = v4 & 0x3FFF;
v6 = v4 & 0x3FFF;
v7 = *(_WORD *)(spriteram + i + 6);
v8 = *(_WORD *)(spriteram + i + 4);
v9 = (unsigned __int16)v8 | 0xFFFFFE00;
if ( v8 >= 0 )
v9 = v8 & 0x1FF;
v10 = (unsigned __int16)v7 | 0xFFFFFE00;
if ( v7 >= 0 )
v10 = v7 & 0x1FF;
v18 = v10;
v11 = *(_WORD *)(spriteram + i) & 0x3F;
v17 = ((int)v3 >> 7) & 7;
v12 = v17 + (unsigned __int16)(v5 + 1);
v14 = v9;
v19 = v9 + 16 * ((((int)v3 >> 10) & 7) + 1);
do
{
v16 = v6;
v13 = v18;
do
{
drawgfx(a1, *(_QWORD *)(Machine + 544LL), v6++, v11, 0LL, 0LL, v14, v13, Machine + 776LL, 2LL, 15LL);
v13 = (unsigned int)(v13 + 16);
}
while ( v6 != v12 );
v6 = v17 + v16 + 1;
v12 += v17 + 1;
v14 += 16;
}
while ( v14 != v19 );
}
}
i -= 8LL;
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap,int pri)
{
 int offs,fx,fy,x,y,color,sprite;
 int dx,dy,ax,ay;
 for (offs = 0x800-8;offs >= 0;offs -= 8)
 {
  if (((*(UINT16 *)(&spriteram[offs+0]))&0x8000)!=0x8000) continue;
  sprite = (*(UINT16 *)(&spriteram[offs+2]));
  if ((sprite>>14)!=pri) continue;
  sprite &= 0x3fff;
  y = (*(UINT16 *)(&spriteram[offs+6]));
  x = (*(UINT16 *)(&spriteram[offs+4]));
  if (x&0x8000) x=0-(0x200-(x&0x1ff));
  else x&=0x1ff;
  if (y&0x8000) y=0-(0x200-(y&0x1ff));
  else y&=0x1ff;
  color = (*(UINT16 *)(&spriteram[offs+0]))&0x3f;
  fx = 0;
  fy = 0;
  dy=(((*(UINT16 *)(&spriteram[offs+0]))&0x0380)>>7)+1;
  dx=(((*(UINT16 *)(&spriteram[offs+0]))&0x1c00)>>10)+1;
  for (ax=0; ax<dx; ax++)
   for (ay=0; ay<dy; ay++) {
    drawgfx(bitmap,Machine->gfx[4],
    sprite++,
    color,fx,fy,x+ax*16,y+ay*16,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
   }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap, int pri)
{
 int offs; int fx; int fy; int x; int y; int color; int sprite;
 int dx; int dy; int ax; int ay;
 for (offs = 0x800-8;offs >= 0;offs -= 8)
 {
  if (((*(unsigned short *)(&spriteram[offs+0]))&0x8000)!=0x8000) continue;
  sprite = (*(unsigned short *)(&spriteram[offs+2]));
  if ((sprite>>14)!=pri) continue;
  sprite &= 0x3fff;
  y = (*(unsigned short *)(&spriteram[offs+6]));
  x = (*(unsigned short *)(&spriteram[offs+4]));
  if (x&0x8000) x=0-(0x200-(x&0x1ff));
  else x&=0x1ff;
  if (y&0x8000) y=0-(0x200-(y&0x1ff));
  else y&=0x1ff;
  color = (*(unsigned short *)(&spriteram[offs+0]))&0x3f;
  fx = 0;
  fy = 0;
  dy=(((*(unsigned short *)(&spriteram[offs+0]))&0x0380)>>7)+1;
  dx=(((*(unsigned short *)(&spriteram[offs+0]))&0x1c00)>>10)+1;
  for (ax=0; ax<dx; ax++)
   for (ay=0; ay<dy; ay++) {
    drawgfx(bitmap,Machine->gfx[4],
    sprite++,
    color,fx,fy,x+ax*16,y+ay*16,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
   }
 }
}

variable_types: pri int

variable_types: fx int

variable_types: fy int

variable_types: x int

variable_types: y int

variable_types: dx int

variable_types: dy int

variable_types: ax int

variable_types: ay int

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


decompiled_code:
__int64 __fastcall bogeyman_videoram_r(unsigned int a1)
{
return *(unsigned __int8 *)(bogeyman_videoram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return *(unsigned __int8 *)(bogeyman_videoram + a1);
}

original_code: static data_t bogeyman_videoram_r(offs_t offset) { return bogeyman_videoram[offset]; }

canonical_original_code: static unsigned int bogeyman_videoram_r(unsigned int offset) { return bogeyman_videoram[offset]; }

variable_types:
offset
unsigned int


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

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

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

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

variable_types:
data
unsigned int


decompiled_code:
__int64 bogeyman_vh_start()
{
size_t v0; // rbx

v0 = videoram_size;
dirtybuffer = malloc(videoram_size);
memset(dirtybuffer, 1, v0);
tmpbitmap = bitmap_alloc(256LL, 256LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
size_t v0; // rbx

v0 = videoram_size;
dirtybuffer = malloc(videoram_size);
memset(dirtybuffer, 1, v0);
tmpbitmap = bitmap_alloc(256LL, 256LL);
return 0LL;
}

original_code:
int bogeyman_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(videoram_size);
 memset(dirtybuffer,1,videoram_size);
 tmpbitmap = bitmap_alloc(256,256);
 return 0;
}

canonical_original_code:
int bogeyman_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(videoram_size);
 memset(dirtybuffer,1,videoram_size);
 tmpbitmap = bitmap_alloc(256,256);
 return 0;
}


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

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

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

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


decompiled_code:
__int64 __fastcall bogeyman_paletteram_w(__int64 a1, int a2)
{
return paletteram_BBGGGRRR_w(a1, (unsigned int)~a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
return paletteram_BBGGGRRR_w(a1, (unsigned int)~a2);
}

original_code:
void bogeyman_paletteram_w(offs_t offset,data_t data)
{
 paletteram_BBGGGRRR_w(offset,~data);
}

canonical_original_code:
void bogeyman_paletteram_w(unsigned int offset, unsigned int data)
{
 paletteram_BBGGGRRR_w(offset,~data);
}


decompiled_code:
__int64 __fastcall bogeyman_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbp
_BYTE *v2; // rdx
int v3; // eax
unsigned __int64 v4; // rbp
unsigned __int8 v5; // al
__int64 v6; // r14
__int64 v7; // r12
int v8; // er15
_BOOL4 v9; // er13
__int64 j; // rbp
_BOOL4 v11; // er10
__int64 result; // rax
int v13; // ecx
int v14; // esi
unsigned int v15; // edx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
flipscreen = 0;
for ( i = 0LL; i != 256; ++i )
{
v2 = (char *)dirtybuffer + i + 256;
if ( *v2 | *((_BYTE *)dirtybuffer + i) )
{
*v2 = 0;
*((_BYTE *)dirtybuffer + i) = 0;
v3 = i + 15;
if ( (int)i >= 0 )
v3 = i;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine
+ 8LL
* (((*(unsigned __int8 *)(bogeyman_videoram + i) | (*(unsigned __int8 *)(bogeyman_videoram + i + 256) << 8) & 0x100) >> 7)
+ 3)
+ 512),
*(_BYTE *)(bogeyman_videoram + i) & 0x7F,
(*(_BYTE *)(bogeyman_videoram + i + 256) >> 1) & 7,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(16 * ((int)i % 16)),
v3 & 0xFFFFFFF0,
0LL,
0LL,
0LL);
}
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v4 = 0LL;
do
{
v5 = *(_BYTE *)(spriteram + v4);
if ( (v5 & 1) != 0 )
{
v6 = *(unsigned __int8 *)(spriteram + v4 + 3);
v7 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + v4 + 2));
v8 = v5 & 0x10;
if ( (v5 & 0x10) != 0 )
v7 = (unsigned int)(v7 - 16);
v9 = (v5 & 4) == 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v4 + 1) + ((4 * v5) & 0x100u),
((int)v5 >> 3) & 1,
(v5 & 4) == 0,
0LL,
v6,
v7,
Machine + 776LL,
2LL,
0LL);
if ( v8 )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v4 + 1) + ((4 * *(unsigned __int8 *)(spriteram + v4)) & 0x100u) + 1,
((int)*(unsigned __int8 *)(spriteram + v4) >> 3) & 1,
v9,
0LL,
v6,
(unsigned int)(v7 + 16),
Machine + 776LL,
2LL,
0LL);
}
v4 += 4LL;
}
while ( spriteram_size > v4 );
}
for ( j = 0LL; j != 1024; ++j )
{
v13 = (int)j % 32;
v14 = (int)j / 32;
if ( flipscreen )
{
v13 = 31 - (int)j % 32;
v14 = 31 - (int)j / 32;
}
result = *(unsigned __int8 *)(videoram + j);
v15 = result | (*(unsigned __int8 *)(videoram + j + 1024) << 8) & 0x300;
if ( v15 )
{
if ( !(v15 >> 9) )
{
if ( v15 - 267 <= 0x4F )
{
v11 = 1;
}
else
{
if ( v15 - 376 <= 0x4E )
{
v11 = 1;
goto LABEL_24;
}
v11 = v15 - 2 <= 0x33;
}
if ( v15 - 480 <= 0x12 )
v11 = 1;
goto LABEL_24;
}
v11 = v15 - 528 <= 0x16E;
LABEL_24:
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (v15 >> 9) + 512),
v15 & 0x1FF,
v11,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v13),
(unsigned int)(8 * v14),
Machine + 776LL,
2LL,
0LL);
continue;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 i; // rbp
_BYTE *v2; // rdx
int v3; // eax
unsigned __int64 v4; // rbp
unsigned __int8 v5; // al
__int64 v6; // r14
__int64 v7; // r12
int v8; // er15
_BOOL4 v9; // er13
__int64 j; // rbp
_BOOL4 v11; // er10
__int64 result; // rax
int v13; // ecx
int v14; // esi
unsigned int v15; // edx

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
flipscreen = 0;
for ( i = 0LL; i != 256; ++i )
{
v2 = (char *)dirtybuffer + i + 256;
if ( *v2 | *((_BYTE *)dirtybuffer + i) )
{
*v2 = 0;
*((_BYTE *)dirtybuffer + i) = 0;
v3 = i + 15;
if ( (int)i >= 0 )
v3 = i;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine
+ 8LL
* (((*(unsigned __int8 *)(bogeyman_videoram + i) | (*(unsigned __int8 *)(bogeyman_videoram + i + 256) << 8) & 0x100) >> 7)
+ 3)
+ 512),
*(_BYTE *)(bogeyman_videoram + i) & 0x7F,
(*(_BYTE *)(bogeyman_videoram + i + 256) >> 1) & 7,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(16 * ((int)i % 16)),
v3 & 0xFFFFFFF0,
0LL,
0LL,
0LL);
}
}
copyscrollbitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v4 = 0LL;
do
{
v5 = *(_BYTE *)(spriteram + v4);
if ( (v5 & 1) != 0 )
{
v6 = *(unsigned __int8 *)(spriteram + v4 + 3);
v7 = (unsigned __int8)(-16 - *(_BYTE *)(spriteram + v4 + 2));
v8 = v5 & 0x10;
if ( (v5 & 0x10) != 0 )
v7 = (unsigned int)(v7 - 16);
v9 = (v5 & 4) == 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v4 + 1) + ((4 * v5) & 0x100u),
((int)v5 >> 3) & 1,
(v5 & 4) == 0,
0LL,
v6,
v7,
Machine + 776LL,
2LL,
0LL);
if ( v8 )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v4 + 1) + ((4 * *(unsigned __int8 *)(spriteram + v4)) & 0x100u) + 1,
((int)*(unsigned __int8 *)(spriteram + v4) >> 3) & 1,
v9,
0LL,
v6,
(unsigned int)(v7 + 16),
Machine + 776LL,
2LL,
0LL);
}
v4 += 4LL;
}
while ( spriteram_size > v4 );
}
for ( j = 0LL; j != 1024; ++j )
{
v13 = (int)j % 32;
v14 = (int)j / 32;
if ( flipscreen )
{
v13 = 31 - (int)j % 32;
v14 = 31 - (int)j / 32;
}
result = *(unsigned __int8 *)(videoram + j);
v15 = result | (*(unsigned __int8 *)(videoram + j + 1024) << 8) & 0x300;
if ( v15 )
{
if ( !(v15 >> 9) )
{
if ( v15 - 267 <= 0x4F )
{
v11 = 1;
}
else
{
if ( v15 - 376 <= 0x4E )
{
v11 = 1;
goto LABEL_24;
}
v11 = v15 - 2 <= 0x33;
}
if ( v15 - 480 <= 0x12 )
v11 = 1;
goto LABEL_24;
}
v11 = v15 - 528 <= 0x16E;
LABEL_24:
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (v15 >> 9) + 512),
v15 & 0x1FF,
v11,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v13),
(unsigned int)(8 * v14),
Machine + 776LL,
2LL,
0LL);
continue;
}
}
return result;
}

original_code:
void bogeyman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int mx,my,offs,color,tile,bank,sx,sy,flipx,flipy,multi;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 flipscreen=0;
 for (offs = 0; offs<0x100; offs++)
 {
  if (dirtybuffer[offs] | dirtybuffer[offs+0x100])
  {
   dirtybuffer[offs] = dirtybuffer[offs+0x100] = 0;
   sx=offs%16;
   sy=offs/16;
   bank=((bogeyman_videoram[offs+0x100] & 0x01) << 8) | bogeyman_videoram[offs];
   bank=(bank/0x80)+3;
   color=bogeyman_videoram[offs+0x100]>>1;
   drawgfx(tmpbitmap,Machine->gfx[bank],
     bogeyman_videoram[offs]&0x7f,
     color&7,
     flipscreen,flipscreen,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = 0;
   multi=spriteram[offs] & 0x10;
   if (multi) sy-=16;
   if (1 )
   {
    sx = 240 - sx;
    flipx = !flipx;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (multi)
    drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1]+ 1 + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy+16,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = 0;offs < 0x400; offs ++)
 {
  mx=offs%32;
  my=offs/32;
  if (flipscreen) {mx=31-mx; my=31-my;}
  tile=videoram[offs] | ((videoram[offs+0x400]&3)<<8);
  bank=tile/0x200;
  if (!tile) continue;
  color = 0;
  if (!bank)
  {
   if ((tile >= 0x002) && (tile < 0x036)) color = 1;
   if ((tile >= 0x10b) && (tile < 0x15b)) color = 1;
   if ((tile >= 0x178) && (tile < 0x1c7)) color = 1;
   if ((tile >= 0x1e0) && (tile < 0x1f3)) color = 1;
  } else {
   if ((tile >= (0x010+0x200)) && (tile < (0x17f+0x200))) color = 1;
  }
  drawgfx(bitmap,Machine->gfx[bank],
    tile&0x1ff,
    color,
    flipscreen,flipscreen,
    8*mx,8*my,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void bogeyman_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int mx; int my; int offs; int color; int tile; int bank; int sx; int sy; int flipx; int flipy; int multi;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 flipscreen=0;
 for (offs = 0; offs<0x100; offs++)
 {
  if (dirtybuffer[offs] | dirtybuffer[offs+0x100])
  {
   dirtybuffer[offs] = dirtybuffer[offs+0x100] = 0;
   sx=offs%16;
   sy=offs/16;
   bank=((bogeyman_videoram[offs+0x100] & 0x01) << 8) | bogeyman_videoram[offs];
   bank=(bank/0x80)+3;
   color=bogeyman_videoram[offs+0x100]>>1;
   drawgfx(tmpbitmap,Machine->gfx[bank],
     bogeyman_videoram[offs]&0x7f,
     color&7,
     flipscreen,flipscreen,
     16*sx,16*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  if (spriteram[offs] & 0x01)
  {
   sx = 240 - spriteram[offs+3];
   sy = (240 - spriteram[offs+2]) & 0xff;
   flipx = spriteram[offs] & 0x04;
   flipy = 0;
   multi=spriteram[offs] & 0x10;
   if (multi) sy-=16;
   if (1 )
   {
    sx = 240 - sx;
    flipx = !flipx;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1] + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
   if (multi)
    drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs+1]+ 1 + ((spriteram[offs] & 0x40) << 2),
     (spriteram[offs] & 0x08) >> 3,
     flipx,flipy,
     sx,sy+16,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = 0;offs < 0x400; offs ++)
 {
  mx=offs%32;
  my=offs/32;
  if (flipscreen) {mx=31-mx; my=31-my;}
  tile=videoram[offs] | ((videoram[offs+0x400]&3)<<8);
  bank=tile/0x200;
  if (!tile) continue;
  color = 0;
  if (!bank)
  {
   if ((tile >= 0x002) && (tile < 0x036)) color = 1;
   if ((tile >= 0x10b) && (tile < 0x15b)) color = 1;
   if ((tile >= 0x178) && (tile < 0x1c7)) color = 1;
   if ((tile >= 0x1e0) && (tile < 0x1f3)) color = 1;
  } else {
   if ((tile >= (0x010+0x200)) && (tile < (0x17f+0x200))) color = 1;
  }
  drawgfx(bitmap,Machine->gfx[bank],
    tile&0x1ff,
    color,
    flipscreen,flipscreen,
    8*mx,8*my,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: mx int

variable_types: my int

variable_types: color int

variable_types: tile int

variable_types: bank int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int


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

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

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

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

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

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

variable_types: last int


decompiled_code:
__int64 __fastcall osd_start_audio_stream(int a1)
{
__int64 result; // rax
int v2; // ebp

usestereo = a1 != 0;
result = *(unsigned int *)(Machine + 836LL);
v2 = (int)(float)((float)(int)result / *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL));
samples_per_frame = v2;
if ( (_DWORD)result )
{
samples_buffer = calloc(v2, 2 * (a1 != 0) + 2);
result = (unsigned int)v2;
if ( !a1 )
{
conversion_buffer = calloc(v2, 4uLL);
result = (unsigned int)v2;
}
}
return result;
}

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

usestereo = a1 != 0;
result = *(unsigned int *)(Machine + 836LL);
v2 = (int)(float)((float)(int)result / *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL));
samples_per_frame = v2;
if ( (_DWORD)result )
{
samples_buffer = calloc(v2, 2 * (a1 != 0) + 2);
result = (unsigned int)v2;
if ( !a1 )
{
conversion_buffer = calloc(v2, 4uLL);
result = (unsigned int)v2;
}
}
return result;
}

original_code:
int osd_start_audio_stream(int stereo)
{
 usestereo = stereo ? 1 : 0;
 samples_per_frame = Machine->sample_rate / Machine->drv->frames_per_second;
 if (Machine->sample_rate == 0) return 0;
 samples_buffer = (short *) calloc(samples_per_frame, 2 + usestereo * 2);
 if (!usestereo) conversion_buffer = (short *) calloc(samples_per_frame, 4);
 return samples_per_frame;
}

variable_types: stereo int


decompiled_code:
_DWORD *osd_stop_audio_stream()
{
_DWORD *result; // rax

result = &samples_per_frame;
samples_per_frame = 0;
return result;
}

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

result = &samples_per_frame;
samples_per_frame = 0;
return result;
}

original_code:
void osd_stop_audio_stream(void)
{
 samples_per_frame = 0;
}

canonical_original_code:
void osd_stop_audio_stream()
{
 samples_per_frame = 0;
}


decompiled_code:
__int64 __fastcall osd_update_audio_stream(void *src)
{
memcpy(samples_buffer, src, samples_per_frame * (usestereo == 0 ? 2 : 4));
hook_audio_done();
return (unsigned int)samples_per_frame;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src)
{
memcpy(samples_buffer, src, samples_per_frame * (usestereo == 0 ? 2 : 4));
hook_audio_done();
return (unsigned int)samples_per_frame;
}

original_code:
int osd_update_audio_stream(INT16 *buffer)
{
 memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
   hook_audio_done();
 return samples_per_frame;
}

canonical_original_code:
int osd_update_audio_stream(short *buffer)
{
 memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
   hook_audio_done();
 return samples_per_frame;
}

variable_types:
buffer
short *


decompiled_code:
__int64 osd_get_mastervolume()
{
return 100LL;
}

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

original_code:
int osd_get_mastervolume(void)
{
 return 100;
}

canonical_original_code:
int osd_get_mastervolume()
{
 return 100;
}


decompiled_code:
void osd_sound_enable()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void osd_sound_enable(int enable_it)
{
 (void)enable_it;
}


decompiled_code:
void osd_opl_write()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void osd_opl_write(int chip,int data)
{
 (void)chip;
 (void)data;
}

canonical_original_code:
void osd_opl_write(int chip, int data)
{
 (void)chip;
 (void)data;
}

variable_types: chip int

variable_types: data int


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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
RAM
unsigned char *


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

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

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

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

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

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


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

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

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

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

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

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

variable_types: lines int

variable_types: offs int


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

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

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

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

variable_types:
data
unsigned int


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

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

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

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


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

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

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

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

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

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

variable_types: layer int

variable_types:
code
int *

variable_types:
color
int *


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

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

variable_types: v int


decompiled_code:
__int64 speedup_r()
{
__int64 v0; // rbp
int v1; // ebx

v0 = memory_region(129LL);
v1 = *(unsigned __int8 *)(v0 + 1045) | (*(unsigned __int8 *)(v0 + 1044) << 8);
if ( (int)memory_region_length(129LL) > v1
&& (*(unsigned __int8 *)(v0 + v1 + 1) | (*(unsigned __int8 *)(v0 + v1) << 8)) == 0xFFFF )
{
cpu_spinuntil_int();
}
return *(unsigned __int8 *)(v0 + 1044);
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rbp
int v1; // ebx

v0 = memory_region(129LL);
v1 = *(unsigned __int8 *)(v0 + 1045) | (*(unsigned __int8 *)(v0 + 1044) << 8);
if ( (int)memory_region_length(129LL) > v1
&& (*(unsigned __int8 *)(v0 + v1 + 1) | (*(unsigned __int8 *)(v0 + v1) << 8)) == 0xFFFF )
{
cpu_spinuntil_int();
}
return *(unsigned __int8 *)(v0 + 1044);
}

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

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


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

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

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

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

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

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

variable_types: addr int

variable_types:
x
int *

variable_types:
y
int *

variable_types:
c
int *


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

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

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

canonical_original_code:
int aztarac_vg_interrupt()
{
    return 4;
}


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

variable_types: x int

variable_types: y int

variable_types: color int

variable_types: intensity int


decompiled_code:
void __fastcall aztarac_ubr_w(__int64 a1, char a2)
{
int v2; // er12
int v3; // ebx
int v6; // [rsp+0h] [rbp-40h] BYREF
int v7; // [rsp+4h] [rbp-3Ch] BYREF
int v8; // [rsp+8h] [rbp-38h] BYREF
int v9; // [rsp+Ch] [rbp-34h] BYREF
int v10; // [rsp+10h] [rbp-30h] BYREF
int v11[11]; // [rsp+14h] [rbp-2Ch] BYREF

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

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

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

variable_types:
offset
unsigned int

variable_types: c int

variable_types: xoffset int

variable_types: yoffset int

variable_types: defaddr int

variable_types: objaddr int

variable_types: ndefs int


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

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

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

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

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

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

variable_types: xmin int

variable_types: xmax int

variable_types: ymin int

variable_types: ymax int


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

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

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

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

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

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

variable_types:
data
unsigned int


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

result = memory_region(129LL);
*(_WORD *)(result + 112) = 0;
*(_WORD *)(result + 114) = 3074;
return result;
}

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

result = memory_region(129LL);
*(_WORD *)(result + 112) = 0;
*(_WORD *)(result + 114) = 3074;
return result;
}

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

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

variable_types:
rom
unsigned char *


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

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

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

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

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

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


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

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

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


decompiled_code:
__int64 __fastcall ppi8255_r(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 (*v3)(void); // rdx
__int64 (__fastcall *v4)(__int64, __int64, _QWORD); // rax
int v5; // edx
unsigned int v6; // esi

if ( *(_DWORD *)intf < (int)a1 )
return 0LL;
result = 0LL;
if ( (int)a2 <= 3 )
{
if ( (_DWORD)a2 == 2 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64, _QWORD))(intf + 24);
v5 = 0;
if ( v4 )
v5 = v4(a1, a2, 0LL);
v6 = chips[9 * (int)a1 + 7];
result = v6 ^ chips[9 * (int)a1 + 4] & (v6 ^ v5);
}
else
{
result = 255LL;
if ( (_DWORD)a2 != 3 )
{
if ( (_DWORD)a2 )
{
if ( (_DWORD)a2 == 1 )
{
if ( chips[9 * (int)a1 + 3] )
{
v3 = *(__int64 (**)(void))(intf + 16);
result = 0LL;
if ( v3 )
return v3();
}
else
{
result = chips[9 * (int)a1 + 6];
}
}
else
{
result = 0LL;
}
}
else if ( chips[9 * (int)a1 + 2] )
{
v3 = *(__int64 (**)(void))(intf + 8);
result = 0LL;
if ( v3 )
return v3();
}
else
{
result = chips[9 * (int)a1 + 5];
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 (*v3)(void); // rdx
__int64 (__fastcall *v4)(__int64, __int64, _QWORD); // rax
int v5; // edx
unsigned int v6; // esi

if ( *(_DWORD *)intf < (int)a1 )
return 0LL;
result = 0LL;
if ( (int)a2 <= 3 )
{
if ( (_DWORD)a2 == 2 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64, _QWORD))(intf + 24);
v5 = 0;
if ( v4 )
v5 = v4(a1, a2, 0LL);
v6 = chips[9 * (int)a1 + 7];
result = v6 ^ chips[9 * (int)a1 + 4] & (v6 ^ v5);
}
else
{
result = 255LL;
if ( (_DWORD)a2 != 3 )
{
if ( (_DWORD)a2 )
{
if ( (_DWORD)a2 == 1 )
{
if ( chips[9 * (int)a1 + 3] )
{
v3 = *(__int64 (**)(void))(intf + 16);
result = 0LL;
if ( v3 )
return v3();
}
else
{
result = chips[9 * (int)a1 + 6];
}
}
else
{
result = 0LL;
}
}
else if ( chips[9 * (int)a1 + 2] )
{
v3 = *(__int64 (**)(void))(intf + 8);
result = 0LL;
if ( v3 )
return v3();
}
else
{
result = chips[9 * (int)a1 + 5];
}
}
}
}
return result;
}

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

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

variable_types: which int

variable_types: offset int

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

variable_types: input int


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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return func1(0LL, a1);
}

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

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

variable_types:
offset
unsigned int


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

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return func1(1LL, a1);
}

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

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


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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return func1(2LL, a1);
}

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

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


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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return func1(3LL, a1);
}

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

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


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

canonical_decompiled_code:
__int64 func0()
{
alpha_rcvd = 1;
gamma_xmtd = 0;
return (unsigned int)gamma_data;
}

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

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


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

canonical_decompiled_code:
__int64 func1()
{
gamma_rcvd = 1;
alpha_xmtd = 0;
return (unsigned int)alpha_data;
}

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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

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

variable_types:
bank
int [2]

variable_types:
RAM
unsigned char *


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

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

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

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

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

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

variable_types:
bank
int [4]


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

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

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

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

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

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


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

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

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

variable_types: param int


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

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

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

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


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

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

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

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

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

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

variable_types: res int


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

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

variable_types:
file
void *


decompiled_code:
void profiler_stop()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void profiler_stop(void) { }

canonical_original_code: void profiler_stop() { }


decompiled_code:
void profiler_mark()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: void profiler_mark(int type) { }

canonical_original_code: void profiler_mark(int type) { }

variable_types: type int


decompiled_code:
void profiler_show()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


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

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

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

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

variable_types:
data
unsigned int


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

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

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

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

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

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