decompiled_code:
__int64 __fastcall dynduke_vh_screenrefresh(__int64 a1)
{
__int64 v2; // rdx
__int64 v3; // r9
char *v4; // rdi
char *v5; // rax
__int64 v6; // r11
__int64 v7; // rsi
__int64 v8; // r10
__int64 i; // rdx
__int64 v10; // rcx
unsigned int j; // eax
__int64 v12; // rcx
int v14[32]; // [rsp+0h] [rbp-98h] BYREF
char v15[24]; // [rsp+80h] [rbp-18h] BYREF

tilemap_set_scrolly(
bg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 4LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 4LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 2LL)) & 0x300u));
tilemap_set_scrollx(
bg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 20LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 20LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 18LL)) & 0x300u));
tilemap_set_scrolly(
fg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 36LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 36LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 34LL)) & 0x300u));
tilemap_set_scrollx(
fg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 52LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 52LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 50LL)) & 0x300u));
tilemap_set_enable(bg_layer, (unsigned int)back_enable);
tilemap_set_enable(fg_layer, (unsigned int)fore_enable);
tilemap_update(0LL);
palette_init_used_colors();
v2 = Machine;
LODWORD(v3) = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
v4 = (char *)v14;
v5 = (char *)v14;
do
{
*(_DWORD *)v5 = 0;
v5 += 4;
}
while ( v5 != v15 );
v6 = spriteram;
v7 = buffered_spriteram;
v8 = *(_QWORD *)(*(_QWORD *)(v2 + 536) + 32LL);
for ( i = 8LL; i != 4104; i += 8LL )
{
v10 = *(_BYTE *)(v6 + i - 7) & 0x1F;
v14[v10] |= *(_DWORD *)(v8
+ 4LL
* ((*(unsigned __int8 *)(v7 + i - 6) + (*(unsigned __int8 *)(v7 + i - 5) << 8)) & 0x3FFF));
}
do
{
v12 = *(unsigned int *)v4;
for ( j = 0; j != 15; ++j )
{
if ( _bittest((const int *)&v12, j) )
{
i = (int)(j + v3);
v7 = palette_used_colors;
*(_BYTE *)(palette_used_colors + i) = 3;
}
}
v4 += 4;
v3 = (unsigned int)(v3 + 16);
}
while ( v4 != v15 );
if ( palette_recalc(v4, v7, i, v12, v15, v3) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( back_enable )
tilemap_draw(a1, bg_layer, 32LL);
else
fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
draw_sprites(a1, 0);
draw_sprites(a1, 1);
tilemap_draw(a1, bg_layer, 64LL);
draw_sprites(a1, 2);
tilemap_draw(a1, fg_layer, 0LL);
draw_sprites(a1, 3);
return tilemap_draw(a1, tx_layer, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 v2; // rdx
__int64 v3; // r9
char *v4; // rdi
char *v5; // rax
__int64 v6; // r11
__int64 v7; // rsi
__int64 v8; // r10
__int64 i; // rdx
__int64 v10; // rcx
unsigned int j; // eax
__int64 v12; // rcx
int v14[32]; // [rsp+0h] [rbp-98h] BYREF
char v15[24]; // [rsp+80h] [rbp-18h] BYREF

tilemap_set_scrolly(
bg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 4LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 4LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 2LL)) & 0x300u));
tilemap_set_scrollx(
bg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 20LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 20LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 18LL)) & 0x300u));
tilemap_set_scrolly(
fg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 36LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 36LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 34LL)) & 0x300u));
tilemap_set_scrollx(
fg_layer,
0LL,
(*(_BYTE *)(dynduke_scroll_ram + 52LL) >> 7)
+ ((unsigned __int8)(2 * *(_BYTE *)(dynduke_scroll_ram + 52LL)) | (16 * *(unsigned __int8 *)(dynduke_scroll_ram + 50LL)) & 0x300u));
tilemap_set_enable(bg_layer, (unsigned int)back_enable);
tilemap_set_enable(fg_layer, (unsigned int)fore_enable);
tilemap_update(0LL);
palette_init_used_colors();
v2 = Machine;
LODWORD(v3) = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
v4 = (char *)v14;
v5 = (char *)v14;
do
{
*(_DWORD *)v5 = 0;
v5 += 4;
}
while ( v5 != v15 );
v6 = spriteram;
v7 = buffered_spriteram;
v8 = *(_QWORD *)(*(_QWORD *)(v2 + 536) + 32LL);
for ( i = 8LL; i != 4104; i += 8LL )
{
v10 = *(_BYTE *)(v6 + i - 7) & 0x1F;
v14[v10] |= *(_DWORD *)(v8
+ 4LL
* ((*(unsigned __int8 *)(v7 + i - 6) + (*(unsigned __int8 *)(v7 + i - 5) << 8)) & 0x3FFF));
}
do
{
v12 = *(unsigned int *)v4;
for ( j = 0; j != 15; ++j )
{
if ( _bittest((const int *)&v12, j) )
{
i = (int)(j + v3);
v7 = palette_used_colors;
*(_BYTE *)(palette_used_colors + i) = 3;
}
}
v4 += 4;
v3 = (unsigned int)(v3 + 16);
}
while ( v4 != v15 );
if ( palette_recalc(v4, v7, i, v12, v15, v3) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( back_enable )
tilemap_draw(a1, bg_layer, 32LL);
else
fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
func15(a1, 0);
func15(a1, 1);
tilemap_draw(a1, bg_layer, 64LL);
func15(a1, 2);
tilemap_draw(a1, fg_layer, 0LL);
func15(a1, 3);
return tilemap_draw(a1, tx_layer, 0LL);
}

original_code:
void dynduke_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int color,offs,sprite;
 int colmask[32],i,pal_base;
 tilemap_set_scrolly( bg_layer,0, ((dynduke_scroll_ram[0x02]&0x30)<<4)+((dynduke_scroll_ram[0x04]&0x7f)<<1)+((dynduke_scroll_ram[0x04]&0x80)>>7) );
 tilemap_set_scrollx( bg_layer,0, ((dynduke_scroll_ram[0x12]&0x30)<<4)+((dynduke_scroll_ram[0x14]&0x7f)<<1)+((dynduke_scroll_ram[0x14]&0x80)>>7) );
 tilemap_set_scrolly( fg_layer,0, ((dynduke_scroll_ram[0x22]&0x30)<<4)+((dynduke_scroll_ram[0x24]&0x7f)<<1)+((dynduke_scroll_ram[0x24]&0x80)>>7) );
 tilemap_set_scrollx( fg_layer,0, ((dynduke_scroll_ram[0x32]&0x30)<<4)+((dynduke_scroll_ram[0x34]&0x7f)<<1)+((dynduke_scroll_ram[0x34]&0x80)>>7) );
 tilemap_set_enable( bg_layer,back_enable);
 tilemap_set_enable( fg_layer,fore_enable);
 tilemap_update(0);
 palette_init_used_colors();
 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
 for (color = 0;color < 32;color++) colmask[color] = 0;
 for (offs = 0;offs <0x1000;offs += 8)
 {
  color = spriteram[offs+1]&0x1f;
  sprite = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  sprite &= 0x3fff;
  colmask[color] |= Machine->gfx[3]->pen_usage[sprite];
 }
 for (color = 0;color < 32;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (back_enable)
  tilemap_draw(bitmap,bg_layer,0x20);
 else
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
 draw_sprites(bitmap,0);
 draw_sprites(bitmap,1);
 tilemap_draw(bitmap,bg_layer,0x40);
 draw_sprites(bitmap,2);
 tilemap_draw(bitmap,fg_layer,0);
 draw_sprites(bitmap,3);
 tilemap_draw(bitmap,tx_layer,0);
}

canonical_original_code:
void dynduke_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int color; int offs; int sprite;
 int colmask[32]; int i; int pal_base;
 tilemap_set_scrolly( bg_layer,0, ((dynduke_scroll_ram[0x02]&0x30)<<4)+((dynduke_scroll_ram[0x04]&0x7f)<<1)+((dynduke_scroll_ram[0x04]&0x80)>>7) );
 tilemap_set_scrollx( bg_layer,0, ((dynduke_scroll_ram[0x12]&0x30)<<4)+((dynduke_scroll_ram[0x14]&0x7f)<<1)+((dynduke_scroll_ram[0x14]&0x80)>>7) );
 tilemap_set_scrolly( fg_layer,0, ((dynduke_scroll_ram[0x22]&0x30)<<4)+((dynduke_scroll_ram[0x24]&0x7f)<<1)+((dynduke_scroll_ram[0x24]&0x80)>>7) );
 tilemap_set_scrollx( fg_layer,0, ((dynduke_scroll_ram[0x32]&0x30)<<4)+((dynduke_scroll_ram[0x34]&0x7f)<<1)+((dynduke_scroll_ram[0x34]&0x80)>>7) );
 tilemap_set_enable( bg_layer,back_enable);
 tilemap_set_enable( fg_layer,fore_enable);
 tilemap_update(0);
 palette_init_used_colors();
 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
 for (color = 0;color < 32;color++) colmask[color] = 0;
 for (offs = 0;offs <0x1000;offs += 8)
 {
  color = spriteram[offs+1]&0x1f;
  sprite = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  sprite &= 0x3fff;
  colmask[color] |= Machine->gfx[3]->pen_usage[sprite];
 }
 for (color = 0;color < 32;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (back_enable)
  tilemap_draw(bitmap,bg_layer,0x20);
 else
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
 draw_sprites(bitmap,0);
 draw_sprites(bitmap,1);
 tilemap_draw(bitmap,bg_layer,0x40);
 draw_sprites(bitmap,2);
 tilemap_draw(bitmap,fg_layer,0);
 draw_sprites(bitmap,3);
 tilemap_draw(bitmap,tx_layer,0);
}

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

variable_types: offs int

variable_types: sprite int

variable_types:
colmask
int [32]


decompiled_code:
__int64 init_dynduke()
{
return seibu_sound_decrypt();
}

canonical_decompiled_code:
__int64 func17()
{
return seibu_sound_decrypt();
}

original_code:
static void init_dynduke(void)
{
 seibu_sound_decrypt();
}

canonical_original_code:
static void init_dynduke()
{
 seibu_sound_decrypt();
}

return_type: void


decompiled_code:
__int64 dynduke_eof_callback()
{
return buffer_spriteram_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func18()
{
return buffer_spriteram_w(0LL, 0LL);
}

original_code:
static void dynduke_eof_callback(void)
{
 buffer_spriteram_w(0,0);
}

canonical_original_code:
static void dynduke_eof_callback()
{
 buffer_spriteram_w(0,0);
}


decompiled_code:
__int64 __fastcall dynduke_soundcpu_r(unsigned int a1)
{
__int64 result; // rax
char v2; // dl

if ( a1 == 4 )
{
if ( *(_DWORD *)(Machine + 836LL) || (v2 = readinputport(), result = 1LL, (v2 & 1) == 0) )
{
result = *(unsigned __int8 *)(seibu_shared_sound_ram + 6LL);
*(_BYTE *)(seibu_shared_sound_ram + 6LL) = 0;
}
}
else
{
result = 0LL;
if ( a1 != 10 )
{
if ( a1 > 0xA || (result = 160LL, a1 != 6) )
result = *(unsigned __int8 *)(seibu_shared_sound_ram + a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1)
{
__int64 result; // rax
char v2; // dl

if ( a1 == 4 )
{
if ( *(_DWORD *)(Machine + 836LL) || (v2 = readinputport(), result = 1LL, (v2 & 1) == 0) )
{
result = *(unsigned __int8 *)(seibu_shared_sound_ram + 6LL);
*(_BYTE *)(seibu_shared_sound_ram + 6LL) = 0;
}
}
else
{
result = 0LL;
if ( a1 != 10 )
{
if ( a1 > 0xA || (result = 160LL, a1 != 6) )
result = *(unsigned __int8 *)(seibu_shared_sound_ram + a1);
}
}
return result;
}

original_code:
static data_t dynduke_soundcpu_r(offs_t offset)
{
 int erg,orig;
 orig=seibu_shared_sound_ram[offset];
 if (offset==4 && (!Machine->sample_rate) && (readinputport(4)&1)==1) return 1;
 switch (offset)
 {
  case 0x04:{erg=seibu_shared_sound_ram[6];seibu_shared_sound_ram[6]=0;break;}
  case 0x06:{erg=0xa0;break;}
  case 0x0a:{erg=0;break;}
  default: erg=seibu_shared_sound_ram[offset];
 }
 return erg;
}

canonical_original_code:
static unsigned int dynduke_soundcpu_r(unsigned int offset)
{
 int erg; int orig;
 orig=seibu_shared_sound_ram[offset];
 if (offset==4 && (!Machine->sample_rate) && (readinputport(4)&1)==1) return 1;
 switch (offset)
 {
  case 0x04:{erg=seibu_shared_sound_ram[6];seibu_shared_sound_ram[6]=0;break;}
  case 0x06:{erg=0xa0;break;}
  case 0x0a:{erg=0;break;}
  default: erg=seibu_shared_sound_ram[offset];
 }
 return erg;
}

variable_types:
offset
unsigned int

variable_types: erg int

variable_types: orig int

return_type: unsigned int


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(dynduke_back_data + 2 * a1) + (*(unsigned __int8 *)(dynduke_back_data + 2 * a1 + 1LL) << 8);
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (back_bankbase
+ ((*(unsigned __int8 *)(dynduke_back_data + 2 * a1)
+ (*(unsigned __int8 *)(dynduke_back_data + 2 * a1 + 1LL) << 8)) & 0xFFFu))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (back_palbase + (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 func2(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(dynduke_back_data + 2 * a1) + (*(unsigned __int8 *)(dynduke_back_data + 2 * a1 + 1LL) << 8);
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (back_bankbase
+ ((*(unsigned __int8 *)(dynduke_back_data + 2 * a1)
+ (*(unsigned __int8 *)(dynduke_back_data + 2 * a1 + 1LL) << 8)) & 0xFFFu))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (back_palbase + (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_bg_tile_info(int tile_index)
{
 int tile=dynduke_back_data[2*tile_index]+(dynduke_back_data[2*tile_index+1]<<8);
 int color=tile >> 12;
 tile=tile&0xfff;
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (tile+back_bankbase) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color+back_palbase)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 int tile = dynduke_back_data[2*tile_index]+(dynduke_back_data[2*tile_index+1]<<8);
 int color = tile >> 12;
 tile=tile&0xfff;
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (tile+back_bankbase) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color+back_palbase)]; 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_fg_tile_info(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(dynduke_fore_data + 2 * a1) + (*(unsigned __int8 *)(dynduke_fore_data + 2 * a1 + 1LL) << 8);
v2 = *(_QWORD *)(Machine + 528LL);
v3 = (fore_bankbase
+ ((*(unsigned __int8 *)(dynduke_fore_data + 2 * a1)
+ (*(unsigned __int8 *)(dynduke_fore_data + 2 * a1 + 1LL) << 8)) & 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)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(dynduke_fore_data + 2 * a1) + (*(unsigned __int8 *)(dynduke_fore_data + 2 * a1 + 1LL) << 8);
v2 = *(_QWORD *)(Machine + 528LL);
v3 = (fore_bankbase
+ ((*(unsigned __int8 *)(dynduke_fore_data + 2 * a1)
+ (*(unsigned __int8 *)(dynduke_fore_data + 2 * a1 + 1LL) << 8)) & 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_fg_tile_info(int tile_index)
{
 int tile=dynduke_fore_data[2*tile_index]+(dynduke_fore_data[2*tile_index+1]<<8);
 int color=tile >> 12;
 tile=tile&0xfff;
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (tile+fore_bankbase) % 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_fg_tile_info(int tile_index)
{
 int tile = dynduke_fore_data[2*tile_index]+(dynduke_fore_data[2*tile_index+1]<<8);
 int color = tile >> 12;
 tile=tile&0xfff;
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (tile+fore_bankbase) % 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_tx_tile_info(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

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

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

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

original_code:
static void get_tx_tile_info(int tile_index)
{
 int tile=videoram[2*tile_index]+((videoram[2*tile_index+1]&0xc0)<<2);
 int color=videoram[2*tile_index+1]&0xf;
 { 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_tx_tile_info(int tile_index)
{
 int tile = videoram[2*tile_index]+((videoram[2*tile_index+1]&0xc0)<<2);
 int color = videoram[2*tile_index+1]&0xf;
 { 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:
void __fastcall draw_sprites(__int64 a1, int a2)
{
__int64 i; // rbx

if ( sprite_enable )
{
for ( i = 4095LL; i != -1; i -= 8LL )
{
if ( *(_BYTE *)(buffered_spriteram + i) == 15 && ((*(_BYTE *)(buffered_spriteram + i - 2) >> 5) & 3) == a2 )
drawgfx(
a1,
*(_QWORD *)(Machine + 536LL),
(*(unsigned __int8 *)(buffered_spriteram + i - 5) + (*(unsigned __int8 *)(buffered_spriteram + i - 4) << 8)) & 0x3FFF,
*(_BYTE *)(buffered_spriteram + i - 6) & 0x1F);
}
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, int a2)
{
__int64 i; // rbx

if ( sprite_enable )
{
for ( i = 4095LL; i != -1; i -= 8LL )
{
if ( *(_BYTE *)(buffered_spriteram + i) == 15 && ((*(_BYTE *)(buffered_spriteram + i - 2) >> 5) & 3) == a2 )
drawgfx(
a1,
*(_QWORD *)(Machine + 536LL),
(*(unsigned __int8 *)(buffered_spriteram + i - 5) + (*(unsigned __int8 *)(buffered_spriteram + i - 4) << 8)) & 0x3FFF,
*(_BYTE *)(buffered_spriteram + i - 6) & 0x1F);
}
}
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap,int pri)
{
 int offs,fx,fy,x,y,color,sprite;
 if (!sprite_enable) return;
 for (offs = 0x1000-8;offs >= 0;offs -= 8)
 {
  if (buffered_spriteram[offs+7]!=0xf) continue;
  if (buffered_spriteram[offs+0]==0xf0f) continue;
  if (((buffered_spriteram[offs+5]>>5)&3)!=pri) continue;
  fx= buffered_spriteram[offs+1]&0x20;
  fy= buffered_spriteram[offs+1]&0x40;
  y = buffered_spriteram[offs+0];
  x = buffered_spriteram[offs+4];
  if (buffered_spriteram[offs+5]&1) x=0-(0x100-x);
  color = buffered_spriteram[offs+1]&0x1f;
  sprite = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  sprite &= 0x3fff;
  if (flipscreen) {
   x=240-x;
   y=240-y;
   if (fx) fx=0; else fx=1;
   if (fy) fy=0; else fy=1;
  }
  drawgfx(bitmap,Machine->gfx[3],
    sprite,
    color,fx,fy,x,y,
    &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;
 if (!sprite_enable) return;
 for (offs = 0x1000-8;offs >= 0;offs -= 8)
 {
  if (buffered_spriteram[offs+7]!=0xf) continue;
  if (buffered_spriteram[offs+0]==0xf0f) continue;
  if (((buffered_spriteram[offs+5]>>5)&3)!=pri) continue;
  fx= buffered_spriteram[offs+1]&0x20;
  fy= buffered_spriteram[offs+1]&0x40;
  y = buffered_spriteram[offs+0];
  x = buffered_spriteram[offs+4];
  if (buffered_spriteram[offs+5]&1) x=0-(0x100-x);
  color = buffered_spriteram[offs+1]&0x1f;
  sprite = buffered_spriteram[offs+2]+(buffered_spriteram[offs+3]<<8);
  sprite &= 0x3fff;
  if (flipscreen) {
   x=240-x;
   y=240-y;
   if (fx) fx=0; else fx=1;
   if (fy) fy=0; else fy=1;
  }
  drawgfx(bitmap,Machine->gfx[3],
    sprite,
    color,fx,fy,x,y,
    &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

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


original_code:
void mnchmobl_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 = (*color_prom >> 6) & 0x01;
  bit1 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  color_prom++;
 }
}

canonical_original_code:
void mnchmobl_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 = (*color_prom >> 6) & 0x01;
  bit1 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x4f * bit0 + 0xa8 * bit1;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

original_code: data_t mnchmobl_sprite_xpos_r(offs_t offset){ return mnchmobl_sprite_xpos[offset]; }

canonical_original_code: unsigned int mnchmobl_sprite_xpos_r(unsigned int offset){ return mnchmobl_sprite_xpos[offset]; }


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

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

original_code: data_t mnchmobl_sprite_attr_r(offs_t offset){ return mnchmobl_sprite_attr[offset]; }

canonical_original_code: unsigned int mnchmobl_sprite_attr_r(unsigned int offset){ return mnchmobl_sprite_attr[offset]; }


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

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

original_code: data_t mnchmobl_sprite_tile_r(offs_t offset){ return mnchmobl_sprite_tile[offset]; }

canonical_original_code: unsigned int mnchmobl_sprite_tile_r(unsigned int offset){ return mnchmobl_sprite_tile[offset]; }


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

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

original_code:
data_t mnchmobl_videoram_r(offs_t offset)
{
 return videoram[offset];
}

canonical_original_code:
unsigned int mnchmobl_videoram_r(unsigned int offset)
{
 return videoram[offset];
}


decompiled_code:
void __fastcall mnchmobl_nmi_enable_w(__int64 a1, int a2)
{
mnchmobl_nmi_enable = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
mnchmobl_nmi_enable = a2;
}

original_code:
static void mnchmobl_nmi_enable_w(offs_t offset,data_t data)
{
 mnchmobl_nmi_enable = data;
}

canonical_original_code:
static void mnchmobl_nmi_enable_w(unsigned int offset, unsigned int data)
{
 mnchmobl_nmi_enable = data;
}

variable_types:
data
unsigned int


decompiled_code:
void mnchmobl_vh_stop()
{
if ( tmpbitmap )
bitmap_free();
free(dirtybuffer);
}

canonical_decompiled_code:
void func9()
{
if ( tmpbitmap )
bitmap_free();
free(dirtybuffer);
}

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

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


original_code:
int mnchmobl_vh_start( void )
{
 dirtybuffer = (unsigned char*)malloc(0x100);
 tmpbitmap = bitmap_alloc(512,512);
 if( dirtybuffer && tmpbitmap )
 {
  memset( dirtybuffer, 1, 0x100 );
  return 0;
 }
 mnchmobl_vh_stop();
 return 1;
}

canonical_original_code:
int mnchmobl_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(0x100);
 tmpbitmap = bitmap_alloc(512,512);
 if( dirtybuffer && tmpbitmap )
 {
  memset( dirtybuffer, 1, 0x100 );
  return 0;
 }
 mnchmobl_vh_stop();
 return 1;
}

return_type: int


decompiled_code:
__int64 __fastcall mnchmobl_vh_screenrefresh(__int64 a1)
{
draw_background(a1);
draw_sprites(a1);
return draw_status(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
func13(a1);
func11(a1);
return func12(a1);
}

original_code:
void mnchmobl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 draw_background( bitmap );
 draw_sprites( bitmap );
 draw_status( bitmap );
}

canonical_original_code:
void mnchmobl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 draw_background( bitmap );
 draw_sprites( bitmap );
 draw_status( bitmap );
}

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


decompiled_code:
__int64 mnchmobl_soundlatch_w()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 4294966296LL);
}

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

original_code:
void mnchmobl_soundlatch_w(offs_t offset,data_t data)
{
 soundlatch_w( offset, data );
 cpu_cause_interrupt( 1, -1000 );
}

canonical_original_code:
void mnchmobl_soundlatch_w(unsigned int offset, unsigned int data)
{
 soundlatch_w( offset, data );
 cpu_cause_interrupt( 1, -1000 );
}


decompiled_code:
__int64 mnchmobl_interrupt()
{
bool v0; // zf

v0 = which_0 == 0;
which_0 = which_0 == 0;
if ( v0 )
return interrupt();
if ( mnchmobl_nmi_enable )
return nmi_interrupt();
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func16()
{
bool v0; // zf

v0 = which_0 == 0;
which_0 = which_0 == 0;
if ( v0 )
return interrupt();
if ( mnchmobl_nmi_enable )
return nmi_interrupt();
return ignore_interrupt();
}

original_code:
static int mnchmobl_interrupt( void )
{
 static int which;
 which = !which;
 if( which ) return interrupt();
 if( mnchmobl_nmi_enable ) return nmi_interrupt();
 return ignore_interrupt();
}

canonical_original_code:
static int mnchmobl_interrupt()
{
 static int which;
 which = !which;
 if( which ) return interrupt();
 if( mnchmobl_nmi_enable ) return nmi_interrupt();
 return ignore_interrupt();
}

variable_types: which int


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r15
int v2; // er13
int v3; // er14
__int64 v4; // rbx
char v5; // r12
__int64 result; // rax
unsigned int v7; // edx
__int64 v8; // [rsp+0h] [rbp-48h]

v1 = Machine + 776LL;
v2 = -144 - (*(_BYTE *)(mnchmobl_vreg + 7LL) >> 7);
v8 = *(_QWORD *)(Machine + 8LL * ((*(unsigned __int8 *)(mnchmobl_vreg + 7LL) >> 6) & 1) + 528);
v3 = 4 * mnchmobl_palette_bank + 3;
v4 = 0LL;
v5 = -32 - *(_BYTE *)(mnchmobl_vreg + 6LL);
do
{
result = *(unsigned __int8 *)(mnchmobl_sprite_tile + v4);
if ( (_BYTE)result != 0xFF )
{
v7 = *(unsigned __int8 *)(mnchmobl_sprite_attr + v4);
if ( (v7 & 0x80u) != 0 )
result = drawgfx(
a1,
v8,
~(_BYTE)result & 0x7F,
v3 - (v7 & 3),
0LL,
0LL,
v2
+ 2
* (unsigned int)(unsigned __int8)(v5
- (((int)*(unsigned __int8 *)(mnchmobl_sprite_xpos + v4) >> 1) | result & 0x80)),
32 * ((int)v4 / 64) + ((v7 >> 2) & 0x1F),
v1,
2LL,
7LL);
}
++v4;
}
while ( v4 != 512 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // r15
int v2; // er13
int v3; // er14
__int64 v4; // rbx
char v5; // r12
__int64 result; // rax
unsigned int v7; // edx
__int64 v8; // [rsp+0h] [rbp-48h]

v1 = Machine + 776LL;
v2 = -144 - (*(_BYTE *)(mnchmobl_vreg + 7LL) >> 7);
v8 = *(_QWORD *)(Machine + 8LL * ((*(unsigned __int8 *)(mnchmobl_vreg + 7LL) >> 6) & 1) + 528);
v3 = 4 * mnchmobl_palette_bank + 3;
v4 = 0LL;
v5 = -32 - *(_BYTE *)(mnchmobl_vreg + 6LL);
do
{
result = *(unsigned __int8 *)(mnchmobl_sprite_tile + v4);
if ( (_BYTE)result != 0xFF )
{
v7 = *(unsigned __int8 *)(mnchmobl_sprite_attr + v4);
if ( (v7 & 0x80u) != 0 )
result = drawgfx(
a1,
v8,
~(_BYTE)result & 0x7F,
v3 - (v7 & 3),
0LL,
0LL,
v2
+ 2
* (unsigned int)(unsigned __int8)(v5
- (((int)*(unsigned __int8 *)(mnchmobl_sprite_xpos + v4) >> 1) | result & 0x80)),
32 * ((int)v4 / 64) + ((v7 >> 2) & 0x1F),
v1,
2LL,
7LL);
}
++v4;
}
while ( v4 != 512 );
return result;
}

original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
 const struct rectangle *clip = &Machine->visible_area;
 int scroll = mnchmobl_vreg[6];
 int flags = mnchmobl_vreg[7];
 int xadjust = - 128-16 - ((flags&0x80)?1:0);
 int bank = (flags&0x40)?1:0;
 const struct GfxElement *gfx = Machine->gfx[2+bank];
 int color_base = mnchmobl_palette_bank*4+3;
 int i;
 for( i=0; i<0x200; i++ )
 {
  int tile_number = mnchmobl_sprite_tile[i];
  int attributes = mnchmobl_sprite_attr[i];
  int sx = mnchmobl_sprite_xpos[i];
  int sy = (i/0x40)*0x20;
  sy += (attributes>>2)&0x1f;
  if( tile_number != 0xff && (attributes&0x80) )
  {
   sx = (sx>>1) | (tile_number&0x80);
   sx = 2*((-32-scroll - sx)&0xff)+xadjust;
   drawgfx( bitmap, gfx,
    0x7f - (tile_number&0x7f),
    color_base-(attributes&0x03),
    0,0,
    sx,sy,
    clip, TRANSPARENCY_PEN, 7 );
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct rectangle *clip = &Machine->visible_area;
 int scroll = mnchmobl_vreg[6];
 int flags = mnchmobl_vreg[7];
 int xadjust = - 128-16 - ((flags&0x80)?1:0);
 int bank = (flags&0x40)?1:0;
 struct GfxElement *gfx = Machine->gfx[2+bank];
 int color_base = mnchmobl_palette_bank*4+3;
 int i;
 for( i=0; i<0x200; i++ )
 {
  int tile_number = mnchmobl_sprite_tile[i];
  int attributes = mnchmobl_sprite_attr[i];
  int sx = mnchmobl_sprite_xpos[i];
  int sy = (i/0x40)*0x20;
  sy += (attributes>>2)&0x1f;
  if( tile_number != 0xff && (attributes&0x80) )
  {
   sx = (sx>>1) | (tile_number&0x80);
   sx = 2*((-32-scroll - sx)&0xff)+xadjust;
   drawgfx( bitmap, gfx,
    0x7f - (tile_number&0x7f),
    color_base-(attributes&0x03),
    0,0,
    sx,sy,
    clip, TRANSPARENCY_PEN, 7 );
  }
 }
}

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

variable_types: scroll int

variable_types: flags int

variable_types: xadjust int

variable_types: bank int

variable_types: attributes int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 __fastcall draw_status(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // rbx
unsigned __int8 *v3; // rbp
__int64 result; // rax
int v5; // ebp
__int64 v6; // r12
int i; // [rsp+Ch] [rbp-4Ch]
__m128i v8[4]; // [rsp+10h] [rbp-48h] BYREF

v8[0] = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v1 = *(_QWORD *)(Machine + 512LL);
for ( i = 0; i != 4; result = (unsigned int)i )
{
v5 = i & 1;
v6 = (unsigned int)(8 * v5);
v3 = (unsigned __int8 *)(mnchmobl_status_vram + 32 * v5);
if ( i <= 1 )
{
v3 += 64;
v6 = (unsigned int)(v6 + 304);
}
v2 = 0LL;
do
{
drawgfx(a1, v1, *v3++, 0LL, 0LL, 0LL, v6, v2, v8, 0LL, 0LL);
v2 = (unsigned int)(v2 + 8);
}
while ( (_DWORD)v2 != 256 );
++i;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // rbx
unsigned __int8 *v3; // rbp
__int64 result; // rax
int v5; // ebp
__int64 v6; // r12
int i; // [rsp+Ch] [rbp-4Ch]
__m128i v8[4]; // [rsp+10h] [rbp-48h] BYREF

v8[0] = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v1 = *(_QWORD *)(Machine + 512LL);
for ( i = 0; i != 4; result = (unsigned int)i )
{
v5 = i & 1;
v6 = (unsigned int)(8 * v5);
v3 = (unsigned __int8 *)(mnchmobl_status_vram + 32 * v5);
if ( i <= 1 )
{
v3 += 64;
v6 = (unsigned int)(v6 + 304);
}
v2 = 0LL;
do
{
drawgfx(a1, v1, *v3++, 0LL, 0LL, 0LL, v6, v2, v8, 0LL, 0LL);
v2 = (unsigned int)(v2 + 8);
}
while ( (_DWORD)v2 != 256 );
++i;
}
return result;
}

original_code:
static void draw_status( struct osd_bitmap *bitmap )
{
 struct rectangle clip = Machine->visible_area;
 const struct GfxElement *gfx = Machine->gfx[0];
 int row;
 for( row=0; row<4; row++ )
 {
  int sy,sx = (row&1)*8;
  const unsigned char *source = mnchmobl_status_vram + (row&1)*32;
  if( row<=1 )
  {
   source+=2*32;
   sx+=256+32+16;
  }
  for( sy=0; sy<256; sy+=8 )
  {
   drawgfx( bitmap, gfx,
    *source++,
    0,
    0,0,
    sx,sy,
    &clip,
    TRANSPARENCY_NONE, 0 );
  }
 }
}

canonical_original_code:
static void draw_status(struct osd_bitmap *bitmap)
{
 struct rectangle clip = Machine->visible_area;
 struct GfxElement *gfx = Machine->gfx[0];
 int row;
 for( row=0; row<4; row++ )
 {
  int sy; int sx = (row&1)*8;
  unsigned char *source = mnchmobl_status_vram + (row&1)*32;
  if( row<=1 )
  {
   source+=2*32;
   sx+=256+32+16;
  }
  for( sy=0; sy<256; sy+=8 )
  {
   drawgfx( bitmap, gfx,
    *source++,
    0,
    0,0,
    sx,sy,
    &clip,
    TRANSPARENCY_NONE, 0 );
  }
 }
}

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

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; } *

variable_types: row int

variable_types:
source
unsigned char *


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
__int64 i; // r12
unsigned __int8 *v2; // r15
__int64 v3; // rbx
unsigned __int8 *v4; // rbp
__int16 v5; // dx
__int64 v7; // [rsp+0h] [rbp-78h]
unsigned int v8; // [rsp+8h] [rbp-70h]
unsigned __int8 *v9; // [rsp+10h] [rbp-68h]
__int64 v10; // [rsp+20h] [rbp-58h]
int v11; // [rsp+38h] [rbp-40h] BYREF
int v12[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v10 = memory_region(138LL);
v7 = *(_QWORD *)(Machine + 520LL);
for ( i = 0LL; i != 256; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
v5 = *(unsigned __int8 *)(videoram + i);
*((_BYTE *)dirtybuffer + i) = 0;
v2 = (unsigned __int8 *)(v10 + ((4 * v5) & 0x3FC));
v8 = 32 * ((int)i % 16);
v9 = v2 + 4096;
do
{
v3 = (unsigned int)(32 * ((int)i / 16));
v4 = v2;
do
{
drawgfx(tmpbitmap, v7, *v4++, (unsigned int)mnchmobl_palette_bank, 0LL, 0LL, v3, v8, 0LL, 0LL, 0LL);
v3 = (unsigned int)(v3 + 8);
}
while ( (_DWORD)v3 != 32 * ((int)i / 16) + 32 );
v2 += 1024;
v8 += 8;
}
while ( v2 != v9 );
}
}
v11 = -208 - ((*(_BYTE *)(mnchmobl_vreg + 7LL) >> 7) + 2 * *(unsigned __int8 *)(mnchmobl_vreg + 6LL));
v12[0] = 0;
return copyscrollbitmap(a1, tmpbitmap, 1LL, &v11, 1LL, v12, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 i; // r12
unsigned __int8 *v2; // r15
__int64 v3; // rbx
unsigned __int8 *v4; // rbp
__int16 v5; // dx
__int64 v7; // [rsp+0h] [rbp-78h]
unsigned int v8; // [rsp+8h] [rbp-70h]
unsigned __int8 *v9; // [rsp+10h] [rbp-68h]
__int64 v10; // [rsp+20h] [rbp-58h]
int v11; // [rsp+38h] [rbp-40h] BYREF
int v12[15]; // [rsp+3Ch] [rbp-3Ch] BYREF

v10 = memory_region(138LL);
v7 = *(_QWORD *)(Machine + 520LL);
for ( i = 0LL; i != 256; ++i )
{
if ( *((_BYTE *)dirtybuffer + i) )
{
v5 = *(unsigned __int8 *)(videoram + i);
*((_BYTE *)dirtybuffer + i) = 0;
v2 = (unsigned __int8 *)(v10 + ((4 * v5) & 0x3FC));
v8 = 32 * ((int)i % 16);
v9 = v2 + 4096;
do
{
v3 = (unsigned int)(32 * ((int)i / 16));
v4 = v2;
do
{
drawgfx(tmpbitmap, v7, *v4++, (unsigned int)mnchmobl_palette_bank, 0LL, 0LL, v3, v8, 0LL, 0LL, 0LL);
v3 = (unsigned int)(v3 + 8);
}
while ( (_DWORD)v3 != 32 * ((int)i / 16) + 32 );
v2 += 1024;
v8 += 8;
}
while ( v2 != v9 );
}
}
v11 = -208 - ((*(_BYTE *)(mnchmobl_vreg + 7LL) >> 7) + 2 * *(unsigned __int8 *)(mnchmobl_vreg + 6LL));
v12[0] = 0;
return copyscrollbitmap(a1, tmpbitmap, 1LL, &v11, 1LL, v12, Machine + 776LL, 0LL, 0LL);
}

original_code:
static void draw_background( struct osd_bitmap *bitmap )
{
 unsigned char *tile_data = memory_region(REGION_GFX2);
 const struct GfxElement *gfx = Machine->gfx[1];
 int offs;
 for( offs=0; offs<0x100; offs++ )
 {
  if( dirtybuffer[offs] )
  {
   int sy = (offs%16)*32;
   int sx = (offs/16)*32;
   int tile_number = videoram[offs];
   int row,col;
   dirtybuffer[offs] = 0;
   for( row=0; row<4; row++ )
   {
    for( col=0; col<4; col++ )
    {
     drawgfx( tmpbitmap,gfx,
      tile_data[col+tile_number*4+row*0x400],
      mnchmobl_palette_bank,
      0,0,
      sx+col*8, sy+row*8,
      0, TRANSPARENCY_NONE, 0 );
    }
   }
  }
 }
 {
  int scrollx = -(mnchmobl_vreg[6]*2+(mnchmobl_vreg[7]>>7))-64-128-16;
  int scrolly = 0;
  copyscrollbitmap(bitmap,tmpbitmap,
   1,&scrollx,1,&scrolly,
   &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap)
{
 unsigned char *tile_data = memory_region(REGION_GFX2);
 struct GfxElement *gfx = Machine->gfx[1];
 int offs;
 for( offs=0; offs<0x100; offs++ )
 {
  if( dirtybuffer[offs] )
  {
   int sy = (offs%16)*32;
   int sx = (offs/16)*32;
   int tile_number = videoram[offs];
   int row; int col;
   dirtybuffer[offs] = 0;
   for( row=0; row<4; row++ )
   {
    for( col=0; col<4; col++ )
    {
     drawgfx( tmpbitmap,gfx,
      tile_data[col+tile_number*4+row*0x400],
      mnchmobl_palette_bank,
      0,0,
      sx+col*8, sy+row*8,
      0, TRANSPARENCY_NONE, 0 );
    }
   }
  }
 }
 {
  int scrollx = -(mnchmobl_vreg[6]*2+(mnchmobl_vreg[7]>>7))-64-128-16;
  int scrolly = 0;
  copyscrollbitmap(bitmap,tmpbitmap,
   1,&scrollx,1,&scrolly,
   &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

variable_types: offs int

variable_types: col int

variable_types: scrollx int

variable_types: scrolly int


decompiled_code:
int *__fastcall blitscreen_dirty1_color8(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 v3; // r15
int *result; // rax
int v5; // er12
int v6; // er13
int v7; // er9
int v8; // edx
__int64 v9; // rax
int v10; // er10
__int64 v11; // rax
__int64 v12; // rcx
__int64 v13; // rsi
int v14; // er11
int v15; // edi
__int64 v16; // rax
int v17; // ebx
__int64 v18; // [rsp+0h] [rbp-48h]
__int64 v19; // [rsp+8h] [rbp-40h]
__int64 v20; // [rsp+10h] [rbp-38h]

v1 = *(_QWORD **)(a1 + 24);
v2 = v1[1] - *v1;
v19 = v1[skiplines] + skipcolumns;
v3 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v20 = 16 * (int)v2;
v5 = 16;
v6 = 0;
v18 = (int)v2;
do
{
v15 = gfx_display_columns;
if ( gfx_display_columns > 0 )
{
v17 = (v6 / 16) << 8;
v14 = 0;
do
{
v16 = v17 + v14 / 16;
if ( *(_BYTE *)(dirty_new + v16) || (v7 = 16, *(_BYTE *)(dirty_old + v16)) )
{
v12 = v14 + v19;
v13 = v3 + 2LL * v14;
v8 = v14 + 16;
if ( v14 + 16 >= v15 )
{
v7 = 16;
}
else
{
v7 = 16;
do
{
v9 = v17 + v8 / 16;
if ( !*(_BYTE *)(dirty_new + v9) && !*(_BYTE *)(dirty_old + v9) )
break;
v7 += 16;
v8 += 16;
}
while ( v8 < v15 );
}
if ( v8 > v15 )
v7 = v15 - v14;
v10 = v6;
do
{
if ( gfx_display_lines <= v10 )
break;
v11 = 0LL;
if ( v7 > 0 )
{
do
{
*(_WORD *)(v13 + 2 * v11) = gp2x_palette[*(unsigned __int8 *)(v12 + v11)];
++v11;
}
while ( v11 != v7 );
}
v12 += v18;
v13 += 2LL * gfx_width;
++v10;
}
while ( v5 != v10 );
}
v14 += v7;
v15 = gfx_display_columns;
}
while ( gfx_display_columns > v14 );
}
v19 += v20;
v3 += 32LL * gfx_width;
v6 += 16;
v5 += 16;
result = &gfx_display_lines;
}
while ( gfx_display_lines > v6 );
}
return result;
}

original_code:
void blitscreen_dirty1_color8(struct osd_bitmap *bitmap)
{
 int x, y;
 int width=(bitmap->line[1] - bitmap->line[0]);
 unsigned char *lb=bitmap->line[skiplines] + skipcolumns;
 unsigned short *address=gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned char *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = gp2x_palette[lb0[wx]];
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty1_color8(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0]);
 unsigned char *lb = bitmap->line[skiplines] + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned char *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = gp2x_palette[lb0[wx]];
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

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

variable_types: x int

variable_types: y int

variable_types: width int

variable_types:
lb
unsigned char *

variable_types:
address
unsigned short *

variable_types: w int

variable_types: h int

variable_types: wx int


decompiled_code:
int *__fastcall blitscreen_dirty0_color8(__int64 a1)
{
__int64 v1; // rax
int v2; // er11
__int64 v3; // rcx
__int64 v4; // rsi
int v5; // er9
__int64 v6; // r8
__int64 v7; // r10
int *result; // rax
__int64 v9; // rax

v1 = *(_QWORD *)(a1 + 24);
v2 = gfx_display_columns;
v3 = *(_QWORD *)(v1 + 8LL * skiplines) + skipcolumns;
v4 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
v5 = 0;
v6 = (unsigned int)gfx_display_columns;
v7 = (int)(*(_QWORD *)(v1 + 8) - *(_DWORD *)v1);
for ( result = &gfx_display_lines; gfx_display_lines > v5; result = &gfx_display_lines )
{
v9 = 0LL;
if ( v2 > 0 )
{
do
{
*(_WORD *)(v4 + 2 * v9) = gp2x_palette[*(unsigned __int8 *)(v3 + v9)];
++v9;
}
while ( v6 != v9 );
}
v3 += v7;
v4 += 2LL * gfx_width;
++v5;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func1(__int64 a1)
{
__int64 v1; // rax
int v2; // er11
__int64 v3; // rcx
__int64 v4; // rsi
int v5; // er9
__int64 v6; // r8
__int64 v7; // r10
int *result; // rax
__int64 v9; // rax

v1 = *(_QWORD *)(a1 + 24);
v2 = gfx_display_columns;
v3 = *(_QWORD *)(v1 + 8LL * skiplines) + skipcolumns;
v4 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
v5 = 0;
v6 = (unsigned int)gfx_display_columns;
v7 = (int)(*(_QWORD *)(v1 + 8) - *(_DWORD *)v1);
for ( result = &gfx_display_lines; gfx_display_lines > v5; result = &gfx_display_lines )
{
v9 = 0LL;
if ( v2 > 0 )
{
do
{
*(_WORD *)(v4 + 2 * v9) = gp2x_palette[*(unsigned __int8 *)(v3 + v9)];
++v9;
}
while ( v6 != v9 );
}
v3 += v7;
v4 += 2LL * gfx_width;
++v5;
}
return result;
}

original_code:
void blitscreen_dirty0_color8(struct osd_bitmap *bitmap)
{
 int x,y;
 int width=(bitmap->line[1] - bitmap->line[0]);
 int columns=gfx_display_columns;
 unsigned char *lb = bitmap->line[skiplines] + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = gp2x_palette[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty0_color8(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0]);
 int columns = gfx_display_columns;
 unsigned char *lb = bitmap->line[skiplines] + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = gp2x_palette[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

variable_types: columns int


decompiled_code:
__int64 __fastcall blitscreen_dirty1_palettized16(__int64 a1)
{
_QWORD *v1; // rdx
__int64 result; // rax
int v3; // er13
int v4; // er14
int v5; // er10
int v6; // edx
__int64 v7; // rax
int v8; // er11
__int64 v9; // rax
__int64 v10; // rdi
__int64 v11; // rsi
int v12; // ebx
int v13; // ecx
__int64 v14; // rax
__int64 v15; // rsi
int v16; // ebp
__int64 v17; // [rsp+0h] [rbp-50h]
__int64 v18; // [rsp+8h] [rbp-48h]
__int64 v19; // [rsp+10h] [rbp-40h]
__int64 v20; // [rsp+18h] [rbp-38h]

v1 = *(_QWORD **)(a1 + 24);
result = (__int64)(v1[1] - *v1) >> 1;
v19 = v1[skiplines] + 2LL * skipcolumns;
v18 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
if ( gfx_display_lines > 0 )
{
v17 = 2LL * (int)result;
v20 = 32LL * (_DWORD)result;
v3 = 16;
v4 = 0;
do
{
v13 = gfx_display_columns;
if ( gfx_display_columns > 0 )
{
v16 = (v4 / 16) << 8;
v12 = 0;
do
{
v14 = v16 + v12 / 16;
if ( *(_BYTE *)(dirty_new + v14) || (v5 = 16, *(_BYTE *)(dirty_old + v14)) )
{
v15 = 2LL * v12;
v10 = v19 + v15;
v11 = v18 + v15;
v6 = v12 + 16;
if ( v12 + 16 >= v13 )
{
v5 = 16;
}
else
{
v5 = 16;
do
{
v7 = v16 + v6 / 16;
if ( !*(_BYTE *)(dirty_new + v7) && !*(_BYTE *)(dirty_old + v7) )
break;
v5 += 16;
v6 += 16;
}
while ( v6 < v13 );
}
if ( v6 > v13 )
v5 = v13 - v12;
v8 = v4;
do
{
if ( gfx_display_lines <= v8 )
break;
v9 = 0LL;
if ( v5 > 0 )
{
do
{
*(_WORD *)(v11 + 2 * v9) = *(_DWORD *)(palette_16bit_lookup + 4LL
* *(unsigned __int16 *)(v10 + 2 * v9));
++v9;
}
while ( v9 != v5 );
}
v10 += v17;
v11 += 2LL * gfx_width;
++v8;
}
while ( v3 != v8 );
}
v12 += v5;
v13 = gfx_display_columns;
}
while ( gfx_display_columns > v12 );
}
v19 += v20;
v18 += 32LL * gfx_width;
v4 += 16;
v3 += 16;
result = (__int64)&gfx_display_lines;
}
while ( gfx_display_lines > v4 );
}
return result;
}

original_code:
void blitscreen_dirty1_palettized16(struct osd_bitmap *bitmap)
{
 int x, y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb=((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address=gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = palette_16bit_lookup[lb0[wx]];
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty1_palettized16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = palette_16bit_lookup[lb0[wx]];
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

variable_types:
lb
unsigned short *


decompiled_code:
int *__fastcall blitscreen_dirty0_palettized16(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // r11
int v3; // ebx
__int64 v4; // rsi
__int64 v5; // rdi
int *result; // rax
__int64 v7; // r11
int v8; // er10
__int64 v9; // rax

v1 = *(_QWORD **)(a1 + 24);
v2 = (__int64)(v1[1] - *v1) >> 1;
v3 = gfx_display_columns;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v7 = 2LL * (int)v2;
v8 = 0;
do
{
v9 = 0LL;
if ( v3 > 0 )
{
do
{
*(_WORD *)(v5 + 2 * v9) = *(_DWORD *)(palette_16bit_lookup + 4LL * *(unsigned __int16 *)(v4 + 2 * v9));
++v9;
}
while ( v3 != v9 );
}
v4 += v7;
v5 += 2LL * gfx_width;
++v8;
result = &gfx_display_lines;
}
while ( gfx_display_lines > v8 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func3(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // r11
int v3; // ebx
__int64 v4; // rsi
__int64 v5; // rdi
int *result; // rax
__int64 v7; // r11
int v8; // er10
__int64 v9; // rax

v1 = *(_QWORD **)(a1 + 24);
v2 = (__int64)(v1[1] - *v1) >> 1;
v3 = gfx_display_columns;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v7 = 2LL * (int)v2;
v8 = 0;
do
{
v9 = 0LL;
if ( v3 > 0 )
{
do
{
*(_WORD *)(v5 + 2 * v9) = *(_DWORD *)(palette_16bit_lookup + 4LL * *(unsigned __int16 *)(v4 + 2 * v9));
++v9;
}
while ( v3 != v9 );
}
v4 += v7;
v5 += 2LL * gfx_width;
++v8;
result = &gfx_display_lines;
}
while ( gfx_display_lines > v8 );
}
return result;
}

original_code:
void blitscreen_dirty0_palettized16(struct osd_bitmap *bitmap)
{
 int x,y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 int columns=gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = palette_16bit_lookup[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty0_palettized16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 int columns = gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = palette_16bit_lookup[lb[x]];
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}


original_code:
void blitscreen_dirty1_color16(struct osd_bitmap *bitmap)
{
 int x, y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb=((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address=gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = lb0[wx]&0xFFDF;
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty1_color16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y += 16)
 {
  for (x = 0; x < gfx_display_columns; )
  {
   int w = 16;
   if ((dirty_new[(y)/16 * 256 + (x)/16] || dirty_old[(y)/16 * 256 + (x)/16]))
   {
    int h;
    unsigned short *lb0 = lb + x;
    unsigned short *address0 = address + x;
    while (x + w < gfx_display_columns && (dirty_new[(y)/16 * 256 + (x+w)/16] || dirty_old[(y)/16 * 256 + (x+w)/16]))
                       w += 16;
    if (x + w > gfx_display_columns)
                       w = gfx_display_columns - x;
    for (h = 0; ((h < 16) && ((y + h) < gfx_display_lines)); h++)
    {
     int wx;
     for (wx=0;wx<w;wx++)
     {
      address0[wx] = lb0[wx]&0xFFDF;
     }
     lb0 += width;
     address0 += gfx_width;
    }
   }
   x += w;
         }
  lb += 16 * width;
  address += 16 * gfx_width;
 }
 ;
}


decompiled_code:
int *__fastcall blitscreen_dirty0_color16(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // r9
int v3; // er10
__int64 v4; // rcx
__int64 v5; // rsi
int *result; // rax
__int64 v7; // r9
int v8; // er8
__int64 v9; // rax

v1 = *(_QWORD **)(a1 + 24);
v2 = (__int64)(v1[1] - *v1) >> 1;
v3 = gfx_display_columns;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v7 = 2LL * (int)v2;
v8 = 0;
do
{
v9 = 0LL;
if ( v3 > 0 )
{
do
{
*(_WORD *)(v5 + 2 * v9) = *(_WORD *)(v4 + 2 * v9) & 0xFFDF;
++v9;
}
while ( v3 != v9 );
}
v4 += v7;
v5 += 2LL * gfx_width;
++v8;
result = &gfx_display_lines;
}
while ( gfx_display_lines > v8 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func5(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // r9
int v3; // er10
__int64 v4; // rcx
__int64 v5; // rsi
int *result; // rax
__int64 v7; // r9
int v8; // er8
__int64 v9; // rax

v1 = *(_QWORD **)(a1 + 24);
v2 = (__int64)(v1[1] - *v1) >> 1;
v3 = gfx_display_columns;
v4 = v1[skiplines] + 2LL * skipcolumns;
v5 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(gfx_width * gfx_yoffset));
result = &gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v7 = 2LL * (int)v2;
v8 = 0;
do
{
v9 = 0LL;
if ( v3 > 0 )
{
do
{
*(_WORD *)(v5 + 2 * v9) = *(_WORD *)(v4 + 2 * v9) & 0xFFDF;
++v9;
}
while ( v3 != v9 );
}
v4 += v7;
v5 += 2LL * gfx_width;
++v8;
result = &gfx_display_lines;
}
while ( gfx_display_lines > v8 );
}
return result;
}

original_code:
void blitscreen_dirty0_color16(struct osd_bitmap *bitmap)
{
 int x,y;
 int width=(bitmap->line[1] - bitmap->line[0])>>1;
 int columns=gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = lb[x]&0xFFDF;
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}

canonical_original_code:
void blitscreen_dirty0_color16(struct osd_bitmap *bitmap)
{
 int x; int y;
 int width = (bitmap->line[1] - bitmap->line[0])>>1;
 int columns = gfx_display_columns;
 unsigned short *lb = ((unsigned short*)(bitmap->line[skiplines])) + skipcolumns;
 unsigned short *address = gp2x_screen15 + gfx_xoffset + (gfx_yoffset * gfx_width);
 for (y = 0; y < gfx_display_lines; y++)
 {
  for (x = 0; x < columns; x++)
  {
   address[x] = lb[x]&0xFFDF;
  }
  lb+=width;
  address+=gfx_width;
 }
 ;
}


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

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

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

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

variable_types:
offset
unsigned int


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

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

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

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

variable_types:
data
unsigned int


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 lkage_68705_portC_r()
{
portC_in = main_sent != 0;
if ( !mcu_sent )
portC_in |= 2u;
return ~(unsigned __int8)ddrC & (unsigned __int8)portC_in | (unsigned int)(unsigned __int8)(portC_out & ddrC);
}

canonical_decompiled_code:
__int64 func5()
{
portC_in = main_sent != 0;
if ( !mcu_sent )
portC_in |= 2u;
return ~(unsigned __int8)ddrC & (unsigned __int8)portC_in | (unsigned int)(unsigned __int8)(portC_out & ddrC);
}

original_code:
data_t lkage_68705_portC_r(offs_t offset)
{
 portC_in = 0;
 if (main_sent) portC_in |= 0x01;
 if (!mcu_sent) portC_in |= 0x02;
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}

canonical_original_code:
unsigned int lkage_68705_portC_r(unsigned int offset)
{
 portC_in = 0;
 if (main_sent) portC_in |= 0x01;
 if (!mcu_sent) portC_in |= 0x02;
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}


decompiled_code:
void __fastcall lkage_68705_portC_w(__int64 a1, char a2)
{
portC_out = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char a2)
{
portC_out = a2;
}

original_code:
void lkage_68705_portC_w(offs_t offset,data_t data)
{
 portC_out = data;
}

canonical_original_code:
void lkage_68705_portC_w(unsigned int offset, unsigned int data)
{
 portC_out = data;
}


decompiled_code:
void __fastcall lkage_68705_ddrC_w(__int64 a1, char a2)
{
ddrC = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, char a2)
{
ddrC = a2;
}

original_code:
void lkage_68705_ddrC_w(offs_t offset,data_t data)
{
 ddrC = data;
}

canonical_original_code:
void lkage_68705_ddrC_w(unsigned int offset, unsigned int data)
{
 ddrC = data;
}


decompiled_code:
__int64 lkage_mcu_r()
{
mcu_sent = 0;
return (unsigned __int8)from_mcu;
}

canonical_decompiled_code:
__int64 func8()
{
mcu_sent = 0;
return (unsigned __int8)from_mcu;
}

original_code:
data_t lkage_mcu_r(offs_t offset)
{
 mcu_sent = 0;
 return from_mcu;
}

canonical_original_code:
unsigned int lkage_mcu_r(unsigned int offset)
{
 mcu_sent = 0;
 return from_mcu;
}


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

result = main_sent == 0;
if ( mcu_sent )
result = (unsigned int)result | 2;
return result;
}

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

result = main_sent == 0;
if ( mcu_sent )
result = (unsigned int)result | 2;
return result;
}

original_code:
data_t lkage_mcu_status_r(offs_t offset)
{
 int res = 0;
 if (!main_sent) res |= 0x01;
 if (mcu_sent) res |= 0x02;
 return res;
}

canonical_original_code:
unsigned int lkage_mcu_status_r(unsigned int offset)
{
 int res = 0;
 if (!main_sent) res |= 0x01;
 if (mcu_sent) res |= 0x02;
 return res;
}

variable_types: res int


decompiled_code:
void lkage_sh_nmi_disable_w()
{
sound_nmi_enable = 0;
}

canonical_decompiled_code:
void func13()
{
sound_nmi_enable = 0;
}

original_code:
void lkage_sh_nmi_disable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 0;
}

canonical_original_code:
void lkage_sh_nmi_disable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 0;
}


decompiled_code:
__int64 fake_mcu_r()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0LL;
}

original_code:
static data_t fake_mcu_r(offs_t offset)
{
 return 0;
}

canonical_original_code:
static unsigned int fake_mcu_r(unsigned int offset)
{
 return 0;
}


decompiled_code:
__int64 fake_status_r()
{
return 3LL;
}

canonical_decompiled_code:
__int64 func15()
{
return 3LL;
}

original_code:
static data_t fake_status_r(offs_t offset)
{
 return 3;
}

canonical_original_code:
static unsigned int fake_status_r(unsigned int offset)
{
 return 3;
}


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

if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
result = (unsigned __int8)from_main;
portA_in = from_main;
if ( main_sent )
result = cpu_set_irq_line(2LL, 0LL, 0LL);
main_sent = 0;
}
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
{
result = (unsigned __int8)portA_out;
from_mcu = portA_out;
mcu_sent = 1;
}
portB_out = a2;
return result;
}

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

if ( (ddrB & 2) != 0 && (a2 & 2) == 0 && (portB_out & 2) != 0 )
{
result = (unsigned __int8)from_main;
portA_in = from_main;
if ( main_sent )
result = cpu_set_irq_line(2LL, 0LL, 0LL);
main_sent = 0;
}
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
{
result = (unsigned __int8)portA_out;
from_mcu = portA_out;
mcu_sent = 1;
}
portB_out = a2;
return result;
}

original_code:
void lkage_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
 {
  portA_in = from_main;
  if (main_sent) cpu_set_irq_line(2,0,0);
  main_sent = 0;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  from_mcu = portA_out;
  mcu_sent = 1;
 }
 portB_out = data;
}

canonical_original_code:
void lkage_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
 {
  portA_in = from_main;
  if (main_sent) cpu_set_irq_line(2,0,0);
  main_sent = 0;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  from_mcu = portA_out;
  mcu_sent = 1;
 }
 portB_out = data;
}


decompiled_code:
__int64 __fastcall lkage_mcu_w(__int64 a1, char a2)
{
from_main = a2;
main_sent = 1;
return cpu_set_irq_line(2LL, 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, char a2)
{
from_main = a2;
main_sent = 1;
return cpu_set_irq_line(2LL, 0LL, 1LL);
}

original_code:
void lkage_mcu_w(offs_t offset,data_t data)
{
 from_main = data;
 main_sent = 1;
 cpu_set_irq_line(2,0,1);
}

canonical_original_code:
void lkage_mcu_w(unsigned int offset, unsigned int data)
{
 from_main = data;
 main_sent = 1;
 cpu_set_irq_line(2,0,1);
}


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

result = videoram + a1;
if ( *(unsigned __int8 *)result != a2 )
{
*(_BYTE *)result = a2;
result = a1 >> 10;
if ( (_DWORD)result == 1 )
{
result = tilemap_mark_tile_dirty(fg_tilemap, a1 & 0x3FF);
}
else if ( (_DWORD)result == 2 )
{
result = tilemap_mark_tile_dirty(bg_tilemap, a1 & 0x3FF);
}
else if ( a1 <= 0x3FF )
{
result = tilemap_mark_tile_dirty(tx_tilemap, a1 & 0x3FF);
}
}
return result;
}

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

result = videoram + a1;
if ( *(unsigned __int8 *)result != a2 )
{
*(_BYTE *)result = a2;
result = a1 >> 10;
if ( (_DWORD)result == 1 )
{
result = tilemap_mark_tile_dirty(fg_tilemap, a1 & 0x3FF);
}
else if ( (_DWORD)result == 2 )
{
result = tilemap_mark_tile_dirty(bg_tilemap, a1 & 0x3FF);
}
else if ( a1 <= 0x3FF )
{
result = tilemap_mark_tile_dirty(tx_tilemap, a1 & 0x3FF);
}
}
return result;
}

original_code:
void lkage_videoram_w(offs_t offset,data_t data)
{
 if( videoram[offset]!=data )
 {
  videoram[offset] = data;
  switch( offset/0x400 )
  {
   case 0:
   tilemap_mark_tile_dirty(tx_tilemap,offset & 0x3ff);
   break;
   case 1:
   tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
   break;
   case 2:
   tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
   break;
  }
 }
}

canonical_original_code:
void lkage_videoram_w(unsigned int offset, unsigned int data)
{
 if( videoram[offset]!=data )
 {
  videoram[offset] = data;
  switch( offset/0x400 )
  {
   case 0:
   tilemap_mark_tile_dirty(tx_tilemap,offset & 0x3ff);
   break;
   case 1:
   tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
   break;
   case 2:
   tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
   break;
  }
 }
}


decompiled_code:
__int64 lkage_vh_start()
{
__int64 v0; // rdi
__int64 v2; // [rsp+0h] [rbp-28h]
__int64 v3; // [rsp+0h] [rbp-28h]

fg_tile_bank = 0;
bg_tile_bank = 0;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
LODWORD(v3) = 32;
v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
tx_tilemap = v0;
if ( !bg_tilemap )
return 1LL;
if ( !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132LL) = 0;
*(_DWORD *)(v0 + 132) = 0;
tilemap_set_scrolldx(v0, 4294967287LL, 15LL);
tilemap_set_scrolldx(fg_tilemap, 4294967281LL, 13LL);
tilemap_set_scrolldx(bg_tilemap, 4294967283LL, 19LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
__int64 v0; // rdi
__int64 v2; // [rsp+0h] [rbp-28h]
__int64 v3; // [rsp+0h] [rbp-28h]

fg_tile_bank = 0;
bg_tile_bank = 0;
bg_tilemap = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
LODWORD(v3) = 32;
v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
tx_tilemap = v0;
if ( !bg_tilemap )
return 1LL;
if ( !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132LL) = 0;
*(_DWORD *)(v0 + 132) = 0;
tilemap_set_scrolldx(v0, 4294967287LL, 15LL);
tilemap_set_scrolldx(fg_tilemap, 4294967281LL, 13LL);
tilemap_set_scrolldx(bg_tilemap, 4294967283LL, 19LL);
return 0LL;
}

original_code:
int lkage_vh_start(void)
{
 bg_tile_bank = fg_tile_bank = 0;
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 tx_tilemap->transparent_pen = 0;
 tilemap_set_scrolldx(tx_tilemap,-9,15);
 tilemap_set_scrolldx(fg_tilemap,-15,13);
 tilemap_set_scrolldx(bg_tilemap,-13,19);
 return 0;
}

canonical_original_code:
int lkage_vh_start()
{
 bg_tile_bank = fg_tile_bank = 0;
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 0;
 tx_tilemap->transparent_pen = 0;
 tilemap_set_scrolldx(tx_tilemap,-9,15);
 tilemap_set_scrolldx(fg_tilemap,-15,13);
 tilemap_set_scrolldx(bg_tilemap,-13,19);
 return 0;
}


decompiled_code:
__int64 __fastcall lkage_sound_command_w(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

original_code:
void lkage_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}

canonical_original_code:
void lkage_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}


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

sound_nmi_enable = 1;
if ( pending_nmi )
{
result = cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

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

sound_nmi_enable = 1;
if ( pending_nmi )
{
result = cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

original_code:
void lkage_sh_nmi_enable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(1,-2);
  pending_nmi = 0;
 }
}

canonical_original_code:
void lkage_sh_nmi_enable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(1,-2);
  pending_nmi = 0;
 }
}


decompiled_code:
__int64 init_lkageb()
{
install_mem_read_handler(0LL, 61538LL, 61538LL, fake_mcu_r);
return install_mem_read_handler(0LL, 61575LL, 61575LL, fake_status_r);
}

canonical_decompiled_code:
__int64 func25()
{
install_mem_read_handler(0LL, 61538LL, 61538LL, fake_mcu_r);
return install_mem_read_handler(0LL, 61575LL, 61575LL, fake_status_r);
}

original_code:
void init_lkageb(void)
{
 install_mem_read_handler(0,0xf062,0xf062,fake_mcu_r);
 install_mem_read_handler(0,0xf087,0xf087,fake_status_r);
}

canonical_original_code:
void init_lkageb()
{
 install_mem_read_handler(0,0xf062,0xf062,fake_mcu_r);
 install_mem_read_handler(0,0xf087,0xf087,fake_status_r);
}


decompiled_code:
__int64 __fastcall port_fetch_r(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(154LL) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func26(unsigned int a1)
{
return *(unsigned __int8 *)(memory_region(154LL) + a1);
}

original_code:
static data_t port_fetch_r(offs_t offset)
{
 return memory_region(REGION_USER1)[offset];
}

canonical_original_code:
static unsigned int port_fetch_r(unsigned int offset)
{
 return memory_region(REGION_USER1)[offset];
}


decompiled_code:
__int64 __fastcall lkage_vh_screenrefresh(__int64 a1)
{
flip_screen_x_w(0LL, (lkage_vreg[2] ^ 1) & 1);
flip_screen_y_w(0LL, ~lkage_vreg[2] & 2);
if ( bg_tile_bank != (lkage_vreg[1] & 8) )
{
bg_tile_bank = lkage_vreg[1] & 8;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
if ( fg_tile_bank != (*lkage_vreg & 4) )
{
fg_tile_bank = *lkage_vreg & 4;
tilemap_mark_all_tiles_dirty(fg_tilemap);
}
lkage_set_palette_row(0, 0, 128);
lkage_set_palette_row(8, (unsigned __int8)((lkage_vreg[1] >> 4) + 48), 16);
lkage_set_palette_row(9, (unsigned __int8)((lkage_vreg[1] >> 4) + 32), 16);
lkage_set_palette_row(10, 17, 16);
tilemap_set_scrollx(tx_tilemap, 0LL, (unsigned __int8)*lkage_scroll);
tilemap_set_scrolly(tx_tilemap, 0LL, (unsigned __int8)lkage_scroll[1]);
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[2]);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[3]);
tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[4]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[5]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( (lkage_vreg[2] & 0xF0) != 0xF0 )
return tilemap_draw(a1, tx_tilemap, 16LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1, 1);
tilemap_draw(a1, fg_tilemap, 0LL);
draw_sprites(a1, 0);
return tilemap_draw(a1, tx_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1)
{
flip_screen_x_w(0LL, (lkage_vreg[2] ^ 1) & 1);
flip_screen_y_w(0LL, ~lkage_vreg[2] & 2);
if ( bg_tile_bank != (lkage_vreg[1] & 8) )
{
bg_tile_bank = lkage_vreg[1] & 8;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
if ( fg_tile_bank != (*lkage_vreg & 4) )
{
fg_tile_bank = *lkage_vreg & 4;
tilemap_mark_all_tiles_dirty(fg_tilemap);
}
lkage_set_palette_row(0, 0, 128);
lkage_set_palette_row(8, (unsigned __int8)((lkage_vreg[1] >> 4) + 48), 16);
lkage_set_palette_row(9, (unsigned __int8)((lkage_vreg[1] >> 4) + 32), 16);
lkage_set_palette_row(10, 17, 16);
tilemap_set_scrollx(tx_tilemap, 0LL, (unsigned __int8)*lkage_scroll);
tilemap_set_scrolly(tx_tilemap, 0LL, (unsigned __int8)lkage_scroll[1]);
tilemap_set_scrollx(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[2]);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned __int8)lkage_scroll[3]);
tilemap_set_scrollx(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[4]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned __int8)lkage_scroll[5]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( (lkage_vreg[2] & 0xF0) != 0xF0 )
return tilemap_draw(a1, tx_tilemap, 16LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func21(a1, 1);
tilemap_draw(a1, fg_tilemap, 0LL);
func21(a1, 0);
return tilemap_draw(a1, tx_tilemap, 0LL);
}

original_code:
void lkage_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 flip_screen_x_w(0,~lkage_vreg[2] & 0x01);
 flip_screen_y_w(0,~lkage_vreg[2] & 0x02);
 if( bg_tile_bank != (lkage_vreg[1]&0x08) )
 {
  bg_tile_bank = lkage_vreg[1]&0x08;
  tilemap_mark_all_tiles_dirty( bg_tilemap );
 }
 if( fg_tile_bank != (lkage_vreg[0]&0x04) )
 {
  fg_tile_bank = lkage_vreg[0]&0x04;
  tilemap_mark_all_tiles_dirty( fg_tilemap );
 }
 {
  lkage_set_palette_row( 0x0, 0x00, 16*8 );
  lkage_set_palette_row( 0x8, 0x30 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0x9, 0x20 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0xa, 0x11, 16 );
 }
 tilemap_set_scrollx(tx_tilemap,0,lkage_scroll[0]);
 tilemap_set_scrolly(tx_tilemap,0,lkage_scroll[1]);
 tilemap_set_scrollx(fg_tilemap,0,lkage_scroll[2]);
 tilemap_set_scrolly(fg_tilemap,0,lkage_scroll[3]);
 tilemap_set_scrollx(bg_tilemap,0,lkage_scroll[4]);
 tilemap_set_scrolly(bg_tilemap,0,lkage_scroll[5]);
 tilemap_update( 0 );
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 if ((lkage_vreg[2] & 0xf0) == 0xf0)
 {
  tilemap_draw( bitmap,bg_tilemap,0 );
  draw_sprites( bitmap, 1 );
  tilemap_draw( bitmap,fg_tilemap,0 );
  draw_sprites( bitmap, 0 );
  tilemap_draw( bitmap,tx_tilemap,0 );
 }
 else
 {
  tilemap_draw( bitmap,tx_tilemap,0x10 );
 }
}

canonical_original_code:
void lkage_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 flip_screen_x_w(0,~lkage_vreg[2] & 0x01);
 flip_screen_y_w(0,~lkage_vreg[2] & 0x02);
 if( bg_tile_bank != (lkage_vreg[1]&0x08) )
 {
  bg_tile_bank = lkage_vreg[1]&0x08;
  tilemap_mark_all_tiles_dirty( bg_tilemap );
 }
 if( fg_tile_bank != (lkage_vreg[0]&0x04) )
 {
  fg_tile_bank = lkage_vreg[0]&0x04;
  tilemap_mark_all_tiles_dirty( fg_tilemap );
 }
 {
  lkage_set_palette_row( 0x0, 0x00, 16*8 );
  lkage_set_palette_row( 0x8, 0x30 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0x9, 0x20 + (lkage_vreg[1]>>4),16 );
  lkage_set_palette_row( 0xa, 0x11, 16 );
 }
 tilemap_set_scrollx(tx_tilemap,0,lkage_scroll[0]);
 tilemap_set_scrolly(tx_tilemap,0,lkage_scroll[1]);
 tilemap_set_scrollx(fg_tilemap,0,lkage_scroll[2]);
 tilemap_set_scrolly(fg_tilemap,0,lkage_scroll[3]);
 tilemap_set_scrollx(bg_tilemap,0,lkage_scroll[4]);
 tilemap_set_scrolly(bg_tilemap,0,lkage_scroll[5]);
 tilemap_update( 0 );
 if (palette_recalc()) tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 if ((lkage_vreg[2] & 0xf0) == 0xf0)
 {
  tilemap_draw( bitmap,bg_tilemap,0 );
  draw_sprites( bitmap, 1 );
  tilemap_draw( bitmap,fg_tilemap,0 );
  draw_sprites( bitmap, 0 );
  tilemap_draw( bitmap,tx_tilemap,0 );
 }
 else
 {
  tilemap_draw( bitmap,tx_tilemap,0x10 );
 }
}


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rcx
signed int v2; // edx
__int64 v3; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = (*(unsigned __int8 *)(videoram + a1 + 2048LL) + (bg_tile_bank == 0 ? 0xFFFFFC00 : 0) + 1280)
% *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v2;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16);
v3 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v3 )
result = *(unsigned int *)(v3 + 4LL * v2);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int64 v1; // rcx
signed int v2; // edx
__int64 v3; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = (*(unsigned __int8 *)(videoram + a1 + 2048LL) + (bg_tile_bank == 0 ? 0xFFFFFC00 : 0) + 1280)
% *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v2;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16);
v3 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v3 )
result = *(unsigned int *)(v3 + 4LL * v2);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x800] + 256 * (bg_tile_bank?5:1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x800] + 256 * (bg_tile_bank?5:1)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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_fg_tile_info(int a1)
{
__int64 v1; // rcx
signed int v2; // edx
__int64 v3; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = (((fg_tile_bank != 0) << 8) + (unsigned int)*(unsigned __int8 *)(videoram + a1 + 1024LL)) % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v2;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16) + 2LL * *(int *)(v1 + 12);
v3 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v3 )
result = *(unsigned int *)(v3 + 4LL * v2);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 v1; // rcx
signed int v2; // edx
__int64 v3; // rcx
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 512LL);
v2 = (((fg_tile_bank != 0) << 8) + (unsigned int)*(unsigned __int8 *)(videoram + a1 + 1024LL)) % *(_DWORD *)(v1 + 8);
tile_info = *(_QWORD *)(v1 + 40) + *(_DWORD *)(v1 + 52) * v2;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v1 + 16) + 2LL * *(int *)(v1 + 12);
v3 = *(_QWORD *)(v1 + 32);
result = 0LL;
if ( v3 )
result = *(unsigned int *)(v3 + 4LL * v2);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x400] + 256 * (fg_tile_bank?1:0)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (1)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index + 0x400] + 256 * (fg_tile_bank?1:0)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (1)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}


decompiled_code:
__int64 __fastcall get_tx_tile_info(int a1)
{
__int64 v1; // rcx
signed int v2; // edx
__int64 v3; // rcx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 v1; // rcx
signed int v2; // edx
__int64 v3; // rcx
__int64 result; // rax

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

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

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


irqhandler

decompiled_code:
__int64 __fastcall irqhandler(int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1 != 0);
}

original_code:
static void irqhandler(int irq)
{
 cpu_set_irq_line(1,0,irq ? 1 : 0);
}

variable_types: irq int


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

if ( sound_nmi_enable )
return cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 1;
return result;
}

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

if ( sound_nmi_enable )
return cpu_cause_interrupt(1LL, 4294967294LL);
pending_nmi = 1;
return result;
}

original_code:
static void nmi_callback(int param)
{
 if (sound_nmi_enable) cpu_cause_interrupt(1,-2);
 else pending_nmi = 1;
}

variable_types: param int


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

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

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

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


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

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

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

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


decompiled_code:
void *__fastcall tail2nos_zoomdata_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
void *result; // rax
unsigned int v5; // esi

v2 = (_WORD *)(zoomdata + a1);
v3 = (unsigned __int16)*v2;
result = (void *)(v3 & HIWORD(a2));
v5 = (unsigned int)result | (unsigned __int16)a2;
if ( v3 != v5 )
{
dirtygfx = 1;
result = dirtychar;
*((_BYTE *)dirtychar + (a1 >> 7)) = 1;
*v2 = v5;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
void *result; // rax
unsigned int v5; // esi

v2 = (_WORD *)(zoomdata + a1);
v3 = (unsigned __int16)*v2;
result = (void *)(v3 & HIWORD(a2));
v5 = (unsigned int)result | (unsigned __int16)a2;
if ( v3 != v5 )
{
dirtygfx = 1;
result = dirtychar;
*((_BYTE *)dirtychar + (a1 >> 7)) = 1;
*v2 = v5;
}
return result;
}

original_code:
void tail2nos_zoomdata_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&zoomdata[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  dirtygfx = 1;
  dirtychar[offset / 128] = 1;
  (*(UINT16 *)(&zoomdata[offset]) = (newword));
 }
}

canonical_original_code:
void tail2nos_zoomdata_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&zoomdata[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  dirtygfx = 1;
  dirtychar[offset / 128] = 1;
  (*(unsigned short *)(&zoomdata[offset]) = (newword));
 }
}

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 tail2nos_vh_start()
{
unsigned int v0; // ebx
void *v2; // rdx

bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
v0 = 1;
if ( bg_tilemap )
{
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
{
v0 = 1;
}
else
{
v2 = malloc(0x400uLL);
dirtychar = v2;
if ( v2 )
{
memset(v2, 1u, 0x400uLL);
*(_DWORD *)(bg_tilemap + 132) = 15;
K051316_wraparound_enable(0LL, 1LL);
K051316_set_offset(0LL, 4294967207LL, 4294967282LL);
zoomdata = memory_region(139LL);
}
else
{
K051316_vh_stop_0();
v0 = 1;
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
void *v2; // rdx

bg_tilemap = tilemap_create(get_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
v0 = 1;
if ( bg_tilemap )
{
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
{
v0 = 1;
}
else
{
v2 = malloc(0x400uLL);
dirtychar = v2;
if ( v2 )
{
memset(v2, 1u, 0x400uLL);
*(_DWORD *)(bg_tilemap + 132) = 15;
K051316_wraparound_enable(0LL, 1LL);
K051316_set_offset(0LL, 4294967207LL, 4294967282LL);
zoomdata = memory_region(139LL);
}
else
{
K051316_vh_stop_0();
v0 = 1;
}
}
}
return v0;
}

original_code:
int tail2nos_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x01,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
  return 1;
 if (!(dirtychar = (unsigned char*)malloc(0x400)))
 {
  K051316_vh_stop_0();
  return 1;
 }
 memset(dirtychar,1,0x400);
 bg_tilemap->transparent_pen = 15;
 K051316_wraparound_enable(0,1);
 K051316_set_offset(0,-89,-14);
 zoomdata = memory_region(REGION_GFX3);
 return 0;
}

canonical_original_code:
int tail2nos_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x01,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
  return 1;
 if (!(dirtychar = (unsigned char *)malloc(0x400)))
 {
  K051316_vh_stop_0();
  return 1;
 }
 memset(dirtychar,1,0x400);
 bg_tilemap->transparent_pen = 15;
 K051316_wraparound_enable(0,1);
 K051316_set_offset(0,-89,-14);
 zoomdata = memory_region(REGION_GFX3);
 return 0;
}


decompiled_code:
void tail2nos_vh_stop()
{
K051316_vh_stop_0();
free(dirtychar);
dirtychar = 0LL;
}

canonical_decompiled_code:
void func6()
{
K051316_vh_stop_0();
free(dirtychar);
dirtychar = 0LL;
}

original_code:
void tail2nos_vh_stop(void)
{
 K051316_vh_stop_0();
 free(dirtychar);
 dirtychar = 0;
}

canonical_original_code:
void tail2nos_vh_stop()
{
 K051316_vh_stop_0();
 free(dirtychar);
 dirtychar = 0;
}


decompiled_code:
__int64 __fastcall tail2nos_bgvideoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(tail2nos_bgvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(tail2nos_bgvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 1);
}
return result;
}

original_code:
void tail2nos_bgvideoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&tail2nos_bgvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(UINT16 *)(&tail2nos_bgvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,offset/2);
 }
}

canonical_original_code:
void tail2nos_bgvideoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&tail2nos_bgvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(unsigned short *)(&tail2nos_bgvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,offset/2);
 }
}


decompiled_code:
void __fastcall tail2nos_gfxbank_w(__int64 a1, int a2)
{
int v2; // eax

if ( (a2 & 0xFF0000) == 0 )
{
v2 = a2 & 1;
if ( (a2 & 4) != 0 )
v2 = 2;
if ( charbank != v2 )
{
charbank = v2;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
if ( charpalette != ((a2 & 0x20) == 0 ? 3 : 7) )
{
charpalette = (a2 & 0x20) == 0 ? 3 : 7;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
video_enable = a2 & 0x10;
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
int v2; // eax

if ( (a2 & 0xFF0000) == 0 )
{
v2 = a2 & 1;
if ( (a2 & 4) != 0 )
v2 = 2;
if ( charbank != v2 )
{
charbank = v2;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
if ( charpalette != ((a2 & 0x20) == 0 ? 3 : 7) )
{
charpalette = (a2 & 0x20) == 0 ? 3 : 7;
tilemap_mark_all_tiles_dirty(bg_tilemap);
}
video_enable = a2 & 0x10;
}
}

original_code:
void tail2nos_gfxbank_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  int bank;
  if (data & 0x04) bank = 2;
  else if (data & 0x01) bank = 1;
  else bank = 0;
  if (charbank != bank)
  {
   charbank = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  if (data & 0x20) bank = 7;
  else bank = 3;
  if (charpalette != bank)
  {
   charpalette = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  video_enable = data & 0x10;
 }
}

canonical_original_code:
void tail2nos_gfxbank_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  int bank;
  if (data & 0x04) bank = 2;
  else if (data & 0x01) bank = 1;
  else bank = 0;
  if (charbank != bank)
  {
   charbank = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  if (data & 0x20) bank = 7;
  else bank = 3;
  if (charpalette != bank)
  {
   charpalette = bank;
   tilemap_mark_all_tiles_dirty(bg_tilemap);
  }
  video_enable = data & 0x10;
 }
}

variable_types: bank int


decompiled_code:
__int64 __fastcall tail2nos_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbx

if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 1024; ++i )
{
if ( *((_BYTE *)dirtychar + i) )
{
*((_BYTE *)dirtychar + i) = 0;
decodechar(*(_QWORD *)(Machine + 528LL), (unsigned int)i, zoomdata, &tilelayout_0);
}
}
tilemap_mark_all_tiles_dirty(0LL);
}
K051316_tilemap_update_0();
tilemap_update(bg_tilemap);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( !video_enable )
return fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K051316_zoom_draw_0(a1, 0LL);
drawsprites(a1);
return tilemap_draw(a1, bg_tilemap, 0LL);
}

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

if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 1024; ++i )
{
if ( *((_BYTE *)dirtychar + i) )
{
*((_BYTE *)dirtychar + i) = 0;
decodechar(*(_QWORD *)(Machine + 528LL), (unsigned int)i, zoomdata, &tilelayout_0);
}
}
tilemap_mark_all_tiles_dirty(0LL);
}
K051316_tilemap_update_0();
tilemap_update(bg_tilemap);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
if ( !video_enable )
return fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K051316_zoom_draw_0(a1, 0LL);
drawsprites(a1);
return tilemap_draw(a1, bg_tilemap, 0LL);
}

original_code:
void tail2nos_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 static struct GfxLayout tilelayout =
 {
  16,16,
  0x400,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4,
    10*4, 11*4, 8*4, 9*4, 14*4, 15*4, 12*4, 13*4 },
  { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
    8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
  128*8
 };
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x400;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[2],i,zoomdata,&tilelayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K051316_tilemap_update_0();
 tilemap_update(bg_tilemap);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (video_enable)
 {
  K051316_zoom_draw_0(bitmap,0);
  drawsprites(bitmap);
  tilemap_draw(bitmap,bg_tilemap,0);
 }
 else
  fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
}

canonical_original_code:
void tail2nos_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 static struct GfxLayout tilelayout = {
  16,16,
  0x400,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4,
    10*4, 11*4, 8*4, 9*4, 14*4, 15*4, 12*4, 13*4 },
  { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
    8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
  128*8
 };
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x400;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[2],i,zoomdata,&tilelayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K051316_tilemap_update_0();
 tilemap_update(bg_tilemap);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 if (video_enable)
 {
  K051316_zoom_draw_0(bitmap,0);
  drawsprites(bitmap);
  tilemap_draw(bitmap,bg_tilemap,0);
 }
 else
  fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
}

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

variable_types: struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; }

variable_types: i int