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

result = a2;
reg[a1 >> 1] = a2 | reg[a1] & HIWORD(a2);
if ( a1 )
{
if ( a1 == 2 )
{
soundlatch_w(1LL, (unsigned __int8)byte_F52);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
}
else
{
result = (__int64)ddragon3_vreg;
ddragon3_vreg[0] = reg[0];
}
return result;
}

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

result = a2;
reg[a1 >> 1] = a2 | reg[a1] & HIWORD(a2);
if ( a1 )
{
if ( a1 == 2 )
{
soundlatch_w(1LL, (unsigned __int8)byte_F52);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
}
else
{
result = (__int64)ddragon3_vreg;
ddragon3_vreg[0] = reg[0];
}
return result;
}

original_code:
static void ddragon3_io_w(offs_t offset,data_t data){
 reg[offset/2] = (((reg[offset]) & ((data) >> 16)) | ((data) & 0xffff));
 switch (offset) {
  case 0x0:
  ddragon3_vreg = reg[0];
  break;
  case 0x2:
  soundlatch_w(1,reg[1]&0xff);
  cpu_cause_interrupt( 1, -2 );
  break;
  case 0x4:
  break;
  case 0x6:
  break;
  case 0x8:
  break;
  default:
  break;
 }
}

canonical_original_code:
static void ddragon3_io_w(unsigned int offset, unsigned int data){
 reg[offset/2] = (((reg[offset]) & ((data) >> 16)) | ((data) & 0xffff));
 switch (offset) {
  case 0x0:
  ddragon3_vreg = reg[0];
  break;
  case 0x2:
  soundlatch_w(1,reg[1]&0xff);
  cpu_cause_interrupt( 1, -2 );
  break;
  case 0x4:
  break;
  case 0x6:
  break;
  case 0x8:
  break;
  default:
  break;
 }
}


decompiled_code:
__int64 __fastcall ddragon3_io_r(unsigned int a1)
{
if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
if ( a1 == 6 )
return readinputport(3LL);
return 0xFFFFLL;
}
if ( a1 )
{
if ( a1 == 2 )
return readinputport(1LL);
return 0xFFFFLL;
}
return readinputport(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
if ( a1 == 6 )
return readinputport(3LL);
return 0xFFFFLL;
}
if ( a1 )
{
if ( a1 == 2 )
return readinputport(1LL);
return 0xFFFFLL;
}
return readinputport(0LL);
}

original_code:
static data_t ddragon3_io_r(offs_t offset)
{
 switch (offset) {
  case 0x0: return readinputport(0);
  case 0x2: return readinputport(1);
  case 0x4: return readinputport(2);
  case 0x6: return readinputport(3);
  default:
  return 0xffff;
 }
}

canonical_original_code:
static unsigned int ddragon3_io_r(unsigned int offset)
{
 switch (offset) {
  case 0x0: return readinputport(0);
  case 0x2: return readinputport(1);
  case 0x4: return readinputport(2);
  case 0x6: return readinputport(3);
  default:
  return 0xffff;
 }
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall ddrago3b_io_r(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax
int v3; // ebx
char v4; // bp
int v5; // ebx

if ( a1 == 4 )
{
v5 = readinputport(2LL);
result = v5 + ((unsigned __int8)(readinputport(5LL) & 0x3F) << 8);
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
return (4 * (unsigned __int16)readinputport(5LL)) & 0x300;
return 0xFFFFLL;
}
if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
return v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
return 0xFFFFLL;
}
v3 = readinputport(0LL);
v4 = readinputport(3LL);
result = v3 + ((v4 & 0xF | (4 * (unsigned __int16)readinputport(4LL)) & 0x300u) << 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax
int v3; // ebx
char v4; // bp
int v5; // ebx

if ( a1 == 4 )
{
v5 = readinputport(2LL);
result = v5 + ((unsigned __int8)(readinputport(5LL) & 0x3F) << 8);
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
return (4 * (unsigned __int16)readinputport(5LL)) & 0x300;
return 0xFFFFLL;
}
if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
return v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
return 0xFFFFLL;
}
v3 = readinputport(0LL);
v4 = readinputport(3LL);
result = v3 + ((v4 & 0xF | (4 * (unsigned __int16)readinputport(4LL)) & 0x300u) << 8);
}
return result;
}

original_code:
static data_t ddrago3b_io_r(offs_t offset)
{
 switch (offset) {
  case 0x0: return readinputport(0) + 256*((readinputport(3)&0x0f)|((readinputport(4)&0xc0)<<2));
  case 0x2: return readinputport(1) + 256*(readinputport(4)&0x3f);
  case 0x4: return readinputport(2) + 256*(readinputport(5)&0x3f);
  case 0x6: return (readinputport(5)&0xc0)<<2;
 }
 return 0xffff;
}

canonical_original_code:
static unsigned int ddrago3b_io_r(unsigned int offset)
{
 switch (offset) {
  case 0x0: return readinputport(0) + 256*((readinputport(3)&0x0f)|((readinputport(4)&0xc0)<<2));
  case 0x2: return readinputport(1) + 256*(readinputport(4)&0x3f);
  case 0x4: return readinputport(2) + 256*(readinputport(5)&0x3f);
  case 0x6: return (readinputport(5)&0xc0)<<2;
 }
 return 0xffff;
}


decompiled_code:
__int64 __fastcall ctribe_io_r(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax
int v3; // ebx
char v4; // bp
int v5; // ebx

if ( a1 == 4 )
{
v5 = readinputport(2LL);
result = v5 + ((unsigned __int8)(readinputport(5LL) & 0x3F) << 8);
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
return (unsigned __int8)(readinputport(5LL) & 0xC0) << 8;
return 0xFFFFLL;
}
if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
return v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
return 0xFFFFLL;
}
v3 = readinputport(0LL);
v4 = readinputport(3LL);
result = v3 + ((v4 & 0xF | (4 * (unsigned __int16)readinputport(4LL)) & 0x300u) << 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax
int v3; // ebx
char v4; // bp
int v5; // ebx

if ( a1 == 4 )
{
v5 = readinputport(2LL);
result = v5 + ((unsigned __int8)(readinputport(5LL) & 0x3F) << 8);
}
else
{
if ( a1 > 4 )
{
if ( a1 == 6 )
return (unsigned __int8)(readinputport(5LL) & 0xC0) << 8;
return 0xFFFFLL;
}
if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
return v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
return 0xFFFFLL;
}
v3 = readinputport(0LL);
v4 = readinputport(3LL);
result = v3 + ((v4 & 0xF | (4 * (unsigned __int16)readinputport(4LL)) & 0x300u) << 8);
}
return result;
}

original_code:
static data_t ctribe_io_r(offs_t offset){
 switch (offset) {
  case 0x0: return readinputport(0) + 256*((readinputport(3)&0x0f)|((readinputport(4)&0xc0)<<2));
  case 0x2: return readinputport(1) + 256*(readinputport(4)&0x3f);
  case 0x4: return readinputport(2) + 256*(readinputport(5)&0x3f);
  case 0x6: return 256*(readinputport(5)&0xc0);
 }
 return 0xffff;
}

canonical_original_code:
static unsigned int ctribe_io_r(unsigned int offset){
 switch (offset) {
  case 0x0: return readinputport(0) + 256*((readinputport(3)&0x0f)|((readinputport(4)&0xc0)<<2));
  case 0x2: return readinputport(1) + 256*(readinputport(4)&0x3f);
  case 0x4: return readinputport(2) + 256*(readinputport(5)&0x3f);
  case 0x6: return 256*(readinputport(5)&0xc0);
 }
 return 0xffff;
}


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

v1 = *(_WORD *)(ddragon3_bg_videoram + 2LL * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (v1 & 0xFFF | (ddragon3_bg_tilebase << 12) & 0x1000u) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v3 * *(_DWORD *)(v2 + 52));
v4 = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (unsigned __int16)((v1 >> 12) + 16);
v5 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4;
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

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

v1 = *(_WORD *)(ddragon3_bg_videoram + 2LL * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (v1 & 0xFFF | (ddragon3_bg_tilebase << 12) & 0x1000u) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + (int)(v3 * *(_DWORD *)(v2 + 52));
v4 = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (unsigned __int16)((v1 >> 12) + 16);
v5 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4;
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 UINT16 data = ((UINT16 *)ddragon3_bg_videoram)[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((data&0xfff) | ((ddragon3_bg_tilebase&1)<<12)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((data&0xf000)>>12)+16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned short data = ((UINT16 *)ddragon3_bg_videoram)[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((data&0xfff) | ((ddragon3_bg_tilebase&1)<<12)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((data&0xf000)>>12)+16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types:
data
unsigned short

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

return_type: void


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned __int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // r8
int v6; // eax
int v7; // ecx
__int64 v8; // rsi
int v9; // ecx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_WORD *)(ddragon3_fg_videoram + 2 * v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(_WORD *)(ddragon3_fg_videoram + 2 * v1 + 2) & 0x1FFFu) % *(_DWORD *)(v3 + 8);
v5 = *(_QWORD *)(v3 + 16);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = v2;
v7 = *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v8 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2LL * v7;
v9 = 0;
if ( v8 )
v9 = *(_DWORD *)(v8 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = v9;
result = (v6 >> 6) & 1;
*((_DWORD *)&tile_info + 5) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rdi
unsigned __int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // r8
int v6; // eax
int v7; // ecx
__int64 v8; // rsi
int v9; // ecx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_WORD *)(ddragon3_fg_videoram + 2 * v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(_WORD *)(ddragon3_fg_videoram + 2 * v1 + 2) & 0x1FFFu) % *(_DWORD *)(v3 + 8);
v5 = *(_QWORD *)(v3 + 16);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = v2;
v7 = *(_DWORD *)(v3 + 12) * (v2 & 0xF);
v8 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2LL * v7;
v9 = 0;
if ( v8 )
v9 = *(_DWORD *)(v8 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = v9;
result = (v6 >> 6) & 1;
*((_DWORD *)&tile_info + 5) = result;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 UINT16 data0 = ((UINT16 *)ddragon3_fg_videoram)[2*tile_index];
 UINT16 data1 = ((UINT16 *)ddragon3_fg_videoram)[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (data1&0x1fff) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (data0&0xf)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
        tile_info.flags = ((data0&0x40) >> 6);
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned short data0 = ((UINT16 *)ddragon3_fg_videoram)[2*tile_index];
 unsigned short data1 = ((UINT16 *)ddragon3_fg_videoram)[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (data1&0x1fff) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (data0&0xf)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
        tile_info.flags = ((data0&0x40) >> 6);
}

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 sidearms_gfxctrl_w(__int64 a1, char a2)
{
__int64 result; // rax

result = a2 & 1;
bgon = a2 & 2;
objon = a2 & 1;
return result;
}

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

result = a2 & 1;
bgon = a2 & 2;
objon = a2 & 1;
return result;
}

original_code:
void sidearms_gfxctrl_w(offs_t offset,data_t data)
{
 objon = data & 0x01;
 bgon = data & 0x02;
}

canonical_original_code:
void sidearms_gfxctrl_w(unsigned int offset, unsigned int data)
{
 objon = data & 0x01;
 bgon = data & 0x02;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 sidearms_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
tmpbitmap2 = bitmap_alloc(416LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) + 32));
if ( !tmpbitmap2 )
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
tmpbitmap2 = bitmap_alloc(416LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) + 32));
if ( !tmpbitmap2 )
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

original_code:
int sidearms_vh_start(void)
{
 if (generic_vh_start() != 0)
  return 1;
 if ((tmpbitmap2 = bitmap_alloc(48*8 + 32,Machine->drv->screen_height + 32)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int sidearms_vh_start()
{
 if (generic_vh_start() != 0)
  return 1;
 if ((tmpbitmap2 = bitmap_alloc(48*8 + 32,Machine->drv->screen_height + 32)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 sidearms_vh_stop()
{
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func2()
{
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

original_code:
void sidearms_vh_stop(void)
{
 bitmap_free(tmpbitmap2);
 generic_vh_stop();
}

canonical_original_code:
void sidearms_vh_stop()
{
 bitmap_free(tmpbitmap2);
 generic_vh_stop();
}


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

coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
if ( (a2 & 0x80) != flipscreen )
flipscreen = a2 & 0x80;
return result;
}

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

coin_counter_w(0LL, a2 & 1);
result = coin_counter_w(1LL, a2 & 2);
if ( (a2 & 0x80) != flipscreen )
flipscreen = a2 & 0x80;
return result;
}

original_code:
void sidearms_c804_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
 }
}

canonical_original_code:
void sidearms_c804_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
 }
}


decompiled_code:
void *__fastcall sidearms_vh_screenrefresh(__int64 a1)
{
__int64 v2; // r10
int v3; // er9
int v4; // eax
int v5; // er12
int v6; // edx
__int64 v7; // rax
int v8; // er12
__int64 v9; // r11
int v10; // edi
int v11; // er12
int v12; // ecx
int v13; // eax
__int16 v14; // dx
__int16 v15; // si
int v16; // eax
__int64 v17; // rsi
__int128 *v18; // rsi
__int128 *v19; // r10
int v20; // ecx
unsigned int i; // eax
__int64 v22; // rax
int v23; // er9
__int64 v24; // rax
__int64 v25; // rdi
__int64 v26; // r10
char v27; // dl
int v28; // er11
__int128 *v29; // r10
int v30; // ecx
unsigned int j; // eax
__int64 v32; // rdx
__int64 v33; // rcx
__int64 v34; // r10
__int64 v35; // r11
__int64 v36; // r9
__int64 v37; // rax
char v38; // cl
int v39; // er12
__int64 v40; // rdi
__int64 v41; // rdi
unsigned int k; // eax
__int64 v43; // rcx
int v44; // er14
int v45; // esi
int v46; // eax
int v47; // er14
__int64 v48; // r13
__int64 v49; // rax
__int64 v50; // rbp
int v51; // er15
__int64 v52; // r12
__int16 v53; // cx
int v54; // edx
int v55; // eax
int v56; // eax
int v57; // er13
__int64 v58; // r12
unsigned __int8 v59; // al
__int64 v60; // rdi
__int64 v61; // rdx
int v62; // esi
void *result; // rax
int v64; // er12
__int64 v65; // r14
int v66; // ecx
int v67; // edi
char v68; // dl
int v69; // esi
__int64 v70; // [rsp-30h] [rbp-188h]
__int64 v71; // [rsp+8h] [rbp-150h]
int v72; // [rsp+18h] [rbp-140h] BYREF
int v73; // [rsp+1Ch] [rbp-13Ch] BYREF
__int128 v74[16]; // [rsp+20h] [rbp-138h] BYREF
__int64 v75; // [rsp+120h] [rbp-38h] BYREF

palette_init_used_colors();
v2 = memory_region(140LL);
v3 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 40LL);
memset(v74, 0, 0x80uLL);
v72 = ((unsigned __int8)sidearms_bg_scrollx[1] << 8) + (unsigned __int8)*sidearms_bg_scrollx + 64;
v4 = (unsigned __int8)*sidearms_bg_scrolly;
v5 = ((unsigned __int8)sidearms_bg_scrolly[1] << 8) + v4;
v6 = v72 >> 5;
v73 = -(v4 & 0x1F);
v7 = *(_QWORD *)(Machine + 520LL);
v72 = -(v72 & 0x1F);
v8 = 2 * (v6 + (v5 >> 5 << 7));
v9 = *(_QWORD *)(v7 + 32);
v10 = v8 + 26;
v11 = v8 + 2330;
do
{
v12 = v10 - 26;
do
{
v13 = v12;
v14 = 8 * v12;
v15 = v12;
v12 += 2;
v16 = v15 & 0xF801 | v14 & 0x7F0 | (v13 >> 7) & 0xE;
v17 = *(_BYTE *)(v2 + v16 + 1) >> 3;
*((_DWORD *)v74 + v17) |= *(_DWORD *)(v9
+ 4LL
* (*(unsigned __int8 *)(v2 + v16) + ((*(_BYTE *)(v2 + v16 + 1) & 1) << 8)));
}
while ( v10 != v12 );
v10 += 256;
}
while ( v11 != v10 );
v18 = v74;
v19 = v74;
do
{
v20 = *(_DWORD *)v19;
if ( (BYTE1(*(_DWORD *)v19) & 0x80u) != 0 )
*(_BYTE *)(palette_used_colors + v3 + 15LL) = 7;
for ( i = 0; i != 15; ++i )
{
if ( _bittest(&v20, i) )
*(_BYTE *)(palette_used_colors + (int)(i + v3)) = 3;
}
v19 = (__int128 *)((char *)v19 + 4);
v3 += 16;
}
while ( &v74[8] != v19 );
v74[0] = 0LL;
v22 = *(_QWORD *)(Machine + 824LL);
v74[1] = 0LL;
v74[2] = 0LL;
v24 = *(_QWORD *)(v22 + 688);
v74[3] = 0LL;
v23 = *(_DWORD *)(v24 + 64);
LODWORD(v24) = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v24 = (int)v24;
v25 = spriteram;
v26 = *(_QWORD *)(*(_QWORD *)(Machine + 528LL) + 32LL);
do
{
v27 = *(_BYTE *)(v25 + v24 + 1);
v28 = *(unsigned __int8 *)(v25 + v24);
v24 -= 32LL;
*((_DWORD *)v74 + (v27 & 0xF)) |= *(_DWORD *)(v26 + 4LL * (v28 + 8 * (v27 & 0xE0)));
}
while ( (int)v24 >= 0 );
}
v29 = v74;
do
{
v30 = *(_DWORD *)v29;
if ( (BYTE1(*(_DWORD *)v29) & 0x80u) != 0 )
*(_BYTE *)(palette_used_colors + v23 + 15LL) = 7;
for ( j = 0; j != 15; ++j )
{
if ( _bittest(&v30, j) )
*(_BYTE *)(palette_used_colors + (int)(j + v23)) = 3;
}
v29 = (__int128 *)((char *)v29 + 4);
v23 += 16;
}
while ( &v74[4] != v29 );
LODWORD(v32) = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL);
memset(v74, 0, sizeof(v74));
v33 = (unsigned int)(videoram_size - 1);
if ( videoram_size - 1 >= 0 )
{
v34 = videoram;
v35 = colorram;
v36 = *(_QWORD *)(*(_QWORD *)(Machine + 512LL) + 32LL);
v37 = (int)v33;
do
{
v38 = *(_BYTE *)(v35 + v37);
v39 = *(unsigned __int8 *)(v34 + v37--);
v40 = v38 & 0x3F;
v33 = *(unsigned int *)(v36 + 4LL * (v39 + 4 * (v38 & 0xC0)));
*((_DWORD *)v74 + v40) |= v33;
}
while ( (int)v37 >= 0 );
}
do
{
v41 = *(unsigned int *)v18;
if ( (v41 & 8) != 0 )
{
v33 = palette_used_colors;
*(_BYTE *)(palette_used_colors + (int)v32 + 3LL) = 7;
}
for ( k = 0; k != 3; ++k )
{
if ( _bittest((const int *)&v41, k) )
{
v33 = (int)(k + v32);
*(_BYTE *)(palette_used_colors + v33) = 3;
}
}
v18 = (__int128 *)((char *)v18 + 4);
v32 = (unsigned int)(v32 + 4);
}
while ( &v75 != (__int64 *)v18 );
v43 = palette_recalc(v41, v18, v32, v33);
if ( bgon )
{
v72 = ((unsigned __int8)sidearms_bg_scrollx[1] << 8) + (unsigned __int8)*sidearms_bg_scrollx + 64;
v44 = (unsigned __int8)*sidearms_bg_scrolly + ((unsigned __int8)sidearms_bg_scrolly[1] << 8);
v45 = v72 >> 5;
v46 = -(v72 & 0x1F);
v72 = v46;
v73 = -(v44 & 0x1F);
v47 = 2 * (v45 + (v44 >> 5 << 7));
if ( lastoffs_0 != v47 || v43 )
{
v48 = 0LL;
v49 = memory_region(140LL);
lastoffs_0 = v47;
v71 = a1;
v50 = v49;
do
{
v51 = v47;
v52 = 0LL;
do
{
v53 = 8 * v51;
v54 = v51 >> 7;
v55 = v51 & 0xF801;
v51 += 2;
v56 = v53 & 0x7F0 | v54 & 0xE | v55;
v70 = v52;
v52 = (unsigned int)(v52 + 32);
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(v50 + v56) + ((unsigned __int8)(*(_BYTE *)(v50 + v56 + 1) & 1) << 8),
*(_BYTE *)(v50 + v56 + 1) >> 3,
*(_BYTE *)(v50 + v56 + 1) & 2,
*(_BYTE *)(v50 + v56 + 1) & 4,
v70,
v48,
0LL,
0LL,
0LL);
}
while ( (_DWORD)v52 != 416 );
v48 = (unsigned int)(v48 + 32);
v47 += 256;
}
while ( (_DWORD)v48 != 288 );
a1 = v71;
v46 = v72;
}
v72 = v46 + 64;
copyscrollbitmap(a1, tmpbitmap2, 1LL, &v72, 1LL, &v73, Machine + 776LL, 0LL, 0LL);
}
else
{
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL, v43);
}
if ( objon )
{
v57 = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v58 = v57 + 3LL;
do
{
v59 = *(_BYTE *)(spriteram + v58 - 2);
v60 = *(unsigned __int8 *)(spriteram + v58 - 1);
v61 = *(unsigned __int8 *)(spriteram + v58) + ((16 * v59) & 0x100u);
if ( flipscreen )
{
v61 = (unsigned int)(496 - v61);
v60 = (unsigned int)(240 - v60);
}
v62 = *(unsigned __int8 *)(spriteram + v58 - 3);
v58 -= 32LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v62 + 8 * (v59 & 0xE0u),
v59 & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v61,
v60,
Machine + 776LL,
2LL,
15LL);
v57 -= 32;
}
while ( v57 >= 0 );
}
}
result = &videoram_size;
v64 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v65 = v64;
do
{
v66 = v64 & 0x3F;
v67 = v64 >> 6;
if ( flipscreen )
{
v66 = 63 - v66;
v67 = 31 - v67;
}
--v64;
v68 = *(_BYTE *)(colorram + v65);
v69 = *(unsigned __int8 *)(videoram + v65--);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v69 + 4 * (v68 & 0xC0u),
v68 & 0x3F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v66),
(unsigned int)(8 * v67),
Machine + 776LL,
2LL,
3LL);
}
while ( v64 != -1 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
__int64 v2; // r10
int v3; // er9
int v4; // eax
int v5; // er12
int v6; // edx
__int64 v7; // rax
int v8; // er12
__int64 v9; // r11
int v10; // edi
int v11; // er12
int v12; // ecx
int v13; // eax
__int16 v14; // dx
__int16 v15; // si
int v16; // eax
__int64 v17; // rsi
__int128 *v18; // rsi
__int128 *v19; // r10
int v20; // ecx
unsigned int i; // eax
__int64 v22; // rax
int v23; // er9
__int64 v24; // rax
__int64 v25; // rdi
__int64 v26; // r10
char v27; // dl
int v28; // er11
__int128 *v29; // r10
int v30; // ecx
unsigned int j; // eax
__int64 v32; // rdx
__int64 v33; // rcx
__int64 v34; // r10
__int64 v35; // r11
__int64 v36; // r9
__int64 v37; // rax
char v38; // cl
int v39; // er12
__int64 v40; // rdi
__int64 v41; // rdi
unsigned int k; // eax
__int64 v43; // rcx
int v44; // er14
int v45; // esi
int v46; // eax
int v47; // er14
__int64 v48; // r13
__int64 v49; // rax
__int64 v50; // rbp
int v51; // er15
__int64 v52; // r12
__int16 v53; // cx
int v54; // edx
int v55; // eax
int v56; // eax
int v57; // er13
__int64 v58; // r12
unsigned __int8 v59; // al
__int64 v60; // rdi
__int64 v61; // rdx
int v62; // esi
void *result; // rax
int v64; // er12
__int64 v65; // r14
int v66; // ecx
int v67; // edi
char v68; // dl
int v69; // esi
__int64 v70; // [rsp-30h] [rbp-188h]
__int64 v71; // [rsp+8h] [rbp-150h]
int v72; // [rsp+18h] [rbp-140h] BYREF
int v73; // [rsp+1Ch] [rbp-13Ch] BYREF
__int128 v74[16]; // [rsp+20h] [rbp-138h] BYREF
__int64 v75; // [rsp+120h] [rbp-38h] BYREF

palette_init_used_colors();
v2 = memory_region(140LL);
v3 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 40LL);
memset(v74, 0, 0x80uLL);
v72 = ((unsigned __int8)sidearms_bg_scrollx[1] << 8) + (unsigned __int8)*sidearms_bg_scrollx + 64;
v4 = (unsigned __int8)*sidearms_bg_scrolly;
v5 = ((unsigned __int8)sidearms_bg_scrolly[1] << 8) + v4;
v6 = v72 >> 5;
v73 = -(v4 & 0x1F);
v7 = *(_QWORD *)(Machine + 520LL);
v72 = -(v72 & 0x1F);
v8 = 2 * (v6 + (v5 >> 5 << 7));
v9 = *(_QWORD *)(v7 + 32);
v10 = v8 + 26;
v11 = v8 + 2330;
do
{
v12 = v10 - 26;
do
{
v13 = v12;
v14 = 8 * v12;
v15 = v12;
v12 += 2;
v16 = v15 & 0xF801 | v14 & 0x7F0 | (v13 >> 7) & 0xE;
v17 = *(_BYTE *)(v2 + v16 + 1) >> 3;
*((_DWORD *)v74 + v17) |= *(_DWORD *)(v9
+ 4LL
* (*(unsigned __int8 *)(v2 + v16) + ((*(_BYTE *)(v2 + v16 + 1) & 1) << 8)));
}
while ( v10 != v12 );
v10 += 256;
}
while ( v11 != v10 );
v18 = v74;
v19 = v74;
do
{
v20 = *(_DWORD *)v19;
if ( (BYTE1(*(_DWORD *)v19) & 0x80u) != 0 )
*(_BYTE *)(palette_used_colors + v3 + 15LL) = 7;
for ( i = 0; i != 15; ++i )
{
if ( _bittest(&v20, i) )
*(_BYTE *)(palette_used_colors + (int)(i + v3)) = 3;
}
v19 = (__int128 *)((char *)v19 + 4);
v3 += 16;
}
while ( &v74[8] != v19 );
v74[0] = 0LL;
v22 = *(_QWORD *)(Machine + 824LL);
v74[1] = 0LL;
v74[2] = 0LL;
v24 = *(_QWORD *)(v22 + 688);
v74[3] = 0LL;
v23 = *(_DWORD *)(v24 + 64);
LODWORD(v24) = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v24 = (int)v24;
v25 = spriteram;
v26 = *(_QWORD *)(*(_QWORD *)(Machine + 528LL) + 32LL);
do
{
v27 = *(_BYTE *)(v25 + v24 + 1);
v28 = *(unsigned __int8 *)(v25 + v24);
v24 -= 32LL;
*((_DWORD *)v74 + (v27 & 0xF)) |= *(_DWORD *)(v26 + 4LL * (v28 + 8 * (v27 & 0xE0)));
}
while ( (int)v24 >= 0 );
}
v29 = v74;
do
{
v30 = *(_DWORD *)v29;
if ( (BYTE1(*(_DWORD *)v29) & 0x80u) != 0 )
*(_BYTE *)(palette_used_colors + v23 + 15LL) = 7;
for ( j = 0; j != 15; ++j )
{
if ( _bittest(&v30, j) )
*(_BYTE *)(palette_used_colors + (int)(j + v23)) = 3;
}
v29 = (__int128 *)((char *)v29 + 4);
v23 += 16;
}
while ( &v74[4] != v29 );
LODWORD(v32) = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 16LL);
memset(v74, 0, sizeof(v74));
v33 = (unsigned int)(videoram_size - 1);
if ( videoram_size - 1 >= 0 )
{
v34 = videoram;
v35 = colorram;
v36 = *(_QWORD *)(*(_QWORD *)(Machine + 512LL) + 32LL);
v37 = (int)v33;
do
{
v38 = *(_BYTE *)(v35 + v37);
v39 = *(unsigned __int8 *)(v34 + v37--);
v40 = v38 & 0x3F;
v33 = *(unsigned int *)(v36 + 4LL * (v39 + 4 * (v38 & 0xC0)));
*((_DWORD *)v74 + v40) |= v33;
}
while ( (int)v37 >= 0 );
}
do
{
v41 = *(unsigned int *)v18;
if ( (v41 & 8) != 0 )
{
v33 = palette_used_colors;
*(_BYTE *)(palette_used_colors + (int)v32 + 3LL) = 7;
}
for ( k = 0; k != 3; ++k )
{
if ( _bittest((const int *)&v41, k) )
{
v33 = (int)(k + v32);
*(_BYTE *)(palette_used_colors + v33) = 3;
}
}
v18 = (__int128 *)((char *)v18 + 4);
v32 = (unsigned int)(v32 + 4);
}
while ( &v75 != (__int64 *)v18 );
v43 = palette_recalc(v41, v18, v32, v33);
if ( bgon )
{
v72 = ((unsigned __int8)sidearms_bg_scrollx[1] << 8) + (unsigned __int8)*sidearms_bg_scrollx + 64;
v44 = (unsigned __int8)*sidearms_bg_scrolly + ((unsigned __int8)sidearms_bg_scrolly[1] << 8);
v45 = v72 >> 5;
v46 = -(v72 & 0x1F);
v72 = v46;
v73 = -(v44 & 0x1F);
v47 = 2 * (v45 + (v44 >> 5 << 7));
if ( lastoffs_0 != v47 || v43 )
{
v48 = 0LL;
v49 = memory_region(140LL);
lastoffs_0 = v47;
v71 = a1;
v50 = v49;
do
{
v51 = v47;
v52 = 0LL;
do
{
v53 = 8 * v51;
v54 = v51 >> 7;
v55 = v51 & 0xF801;
v51 += 2;
v56 = v53 & 0x7F0 | v54 & 0xE | v55;
v70 = v52;
v52 = (unsigned int)(v52 + 32);
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(v50 + v56) + ((unsigned __int8)(*(_BYTE *)(v50 + v56 + 1) & 1) << 8),
*(_BYTE *)(v50 + v56 + 1) >> 3,
*(_BYTE *)(v50 + v56 + 1) & 2,
*(_BYTE *)(v50 + v56 + 1) & 4,
v70,
v48,
0LL,
0LL,
0LL);
}
while ( (_DWORD)v52 != 416 );
v48 = (unsigned int)(v48 + 32);
v47 += 256;
}
while ( (_DWORD)v48 != 288 );
a1 = v71;
v46 = v72;
}
v72 = v46 + 64;
copyscrollbitmap(a1, tmpbitmap2, 1LL, &v72, 1LL, &v73, Machine + 776LL, 0LL, 0LL);
}
else
{
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL, v43);
}
if ( objon )
{
v57 = spriteram_size - 32;
if ( spriteram_size - 32 >= 0 )
{
v58 = v57 + 3LL;
do
{
v59 = *(_BYTE *)(spriteram + v58 - 2);
v60 = *(unsigned __int8 *)(spriteram + v58 - 1);
v61 = *(unsigned __int8 *)(spriteram + v58) + ((16 * v59) & 0x100u);
if ( flipscreen )
{
v61 = (unsigned int)(496 - v61);
v60 = (unsigned int)(240 - v60);
}
v62 = *(unsigned __int8 *)(spriteram + v58 - 3);
v58 -= 32LL;
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v62 + 8 * (v59 & 0xE0u),
v59 & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v61,
v60,
Machine + 776LL,
2LL,
15LL);
v57 -= 32;
}
while ( v57 >= 0 );
}
}
result = &videoram_size;
v64 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v65 = v64;
do
{
v66 = v64 & 0x3F;
v67 = v64 >> 6;
if ( flipscreen )
{
v66 = 63 - v66;
v67 = 31 - v67;
}
--v64;
v68 = *(_BYTE *)(colorram + v65);
v69 = *(unsigned __int8 *)(videoram + v65--);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v69 + 4 * (v68 & 0xC0u),
v68 & 0x3F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v66),
(unsigned int)(8 * v67),
Machine + 776LL,
2LL,
3LL);
}
while ( v64 != -1 );
}
return result;
}

original_code:
void sidearms_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs, sx, sy;
 int scrollx,scrolly;
 static int lastoffs;
 int dirtypalette = 0;
palette_init_used_colors();
{
 int color,code,i;
 int colmask[64];
 int pal_base;
 unsigned char *p=memory_region(REGION_GFX4);
 pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
 for (color = 0;color < 32;color++) colmask[color] = 0;
 scrollx = sidearms_bg_scrollx[0] + 256 * sidearms_bg_scrollx[1] + 64;
 scrolly = sidearms_bg_scrolly[0] + 256 * sidearms_bg_scrolly[1];
 offs = 2 * (scrollx >> 5) + 0x100 * (scrolly >> 5);
 scrollx = -(scrollx & 0x1f);
 scrolly = -(scrolly & 0x1f);
 for (sy = 0;sy < 9;sy++)
 {
  for (sx = 0; sx < 13; sx++)
  {
   int offset;
   offset = offs + 2 * sx;
   offset = (offset & 0xf801) | ((offset & 0x0700) >> 7) | ((offset & 0x00fe) << 3);
   code = p[offset] + 256 * (p[offset+1] & 0x01);
   color = (p[offset+1] & 0xf8) >> 3;
   colmask[color] |= Machine->gfx[1]->pen_usage[code];
  }
  offs += 0x100;
 }
 for (color = 0;color < 32;color++)
 {
  if (colmask[color] & (1 << 15))
   palette_used_colors[pal_base + 16 * color + 15] = (4|(1|2));
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
 pal_base = Machine->drv->gfxdecodeinfo[2].color_codes_start;
 for (color = 0;color < 16;color++) colmask[color] = 0;
 for (offs = spriteram_size - 32;offs >= 0;offs -= 32)
 {
  code = spriteram[offs] + 8 * (spriteram[offs + 1] & 0xe0);
  color = spriteram[offs + 1] & 0x0f;
  colmask[color] |= Machine->gfx[2]->pen_usage[code];
 }
 for (color = 0;color < 16;color++)
 {
  if (colmask[color] & (1 << 15))
   palette_used_colors[pal_base + 16 * color + 15] = (4|(1|2));
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
 pal_base = Machine->drv->gfxdecodeinfo[0].color_codes_start;
 for (color = 0;color < 64;color++) colmask[color] = 0;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  code = videoram[offs] + 4 * (colorram[offs] & 0xc0);
  color = colorram[offs] & 0x3f;
  colmask[color] |= Machine->gfx[0]->pen_usage[code];
 }
 for (color = 0;color < 64;color++)
 {
  if (colmask[color] & (1 << 3))
   palette_used_colors[pal_base + 4 * color + 3] = (4|(1|2));
  for (i = 0;i < 3;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 4 * color + i] = (1|2);
  }
 }
}
if (palette_recalc())
 dirtypalette = 1;
 if (bgon)
 {
  scrollx = sidearms_bg_scrollx[0] + 256 * sidearms_bg_scrollx[1] + 64;
  scrolly = sidearms_bg_scrolly[0] + 256 * sidearms_bg_scrolly[1];
  offs = 2 * (scrollx >> 5) + 0x100 * (scrolly >> 5);
  scrollx = -(scrollx & 0x1f);
  scrolly = -(scrolly & 0x1f);
  if (offs != lastoffs || dirtypalette)
  {
   unsigned char *p=memory_region(REGION_GFX4);
   lastoffs = offs;
   for (sy = 0;sy < 9;sy++)
   {
    for (sx = 0; sx < 13; sx++)
    {
     int offset;
     offset = offs + 2 * sx;
     offset = (offset & 0xf801) | ((offset & 0x0700) >> 7) | ((offset & 0x00fe) << 3);
     drawgfx(tmpbitmap2,Machine->gfx[1],
       p[offset] + 256 * (p[offset+1] & 0x01),
       (p[offset+1] & 0xf8) >> 3,
       p[offset+1] & 0x02,p[offset+1] & 0x04,
       32*sx,32*sy,
       0,TRANSPARENCY_NONE,0);
    }
    offs += 0x100;
   }
  }
 scrollx += 64;
 copyscrollbitmap(bitmap,tmpbitmap2,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 else fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 if (objon)
 {
  for (offs = spriteram_size - 32;offs >= 0;offs -= 32)
  {
   sx = spriteram[offs + 3] + ((spriteram[offs + 1] & 0x10) << 4);
   sy = spriteram[offs + 2];
   if (flipscreen)
   {
    sx = 496 - sx;
    sy = 240 - sy;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs] + 8 * (spriteram[offs + 1] & 0xe0),
     spriteram[offs + 1] & 0x0f,
     flipscreen,flipscreen,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,15);
  }
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  sx = offs % 64;
  sy = offs / 64;
  if (flipscreen)
  {
   sx = 63 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 4 * (colorram[offs] & 0xc0),
    colorram[offs] & 0x3f,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,3);
 }
}

canonical_original_code:
void sidearms_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int sx; int sy;
 int scrollx; int scrolly;
 static int lastoffs;
 int dirtypalette = 0;
palette_init_used_colors();
{
 int color; int code; int i;
 int colmask[64];
 int pal_base;
 unsigned char *p = memory_region(REGION_GFX4);
 pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
 for (color = 0;color < 32;color++) colmask[color] = 0;
 scrollx = sidearms_bg_scrollx[0] + 256 * sidearms_bg_scrollx[1] + 64;
 scrolly = sidearms_bg_scrolly[0] + 256 * sidearms_bg_scrolly[1];
 offs = 2 * (scrollx >> 5) + 0x100 * (scrolly >> 5);
 scrollx = -(scrollx & 0x1f);
 scrolly = -(scrolly & 0x1f);
 for (sy = 0;sy < 9;sy++)
 {
  for (sx = 0; sx < 13; sx++)
  {
   int offset;
   offset = offs + 2 * sx;
   offset = (offset & 0xf801) | ((offset & 0x0700) >> 7) | ((offset & 0x00fe) << 3);
   code = p[offset] + 256 * (p[offset+1] & 0x01);
   color = (p[offset+1] & 0xf8) >> 3;
   colmask[color] |= Machine->gfx[1]->pen_usage[code];
  }
  offs += 0x100;
 }
 for (color = 0;color < 32;color++)
 {
  if (colmask[color] & (1 << 15))
   palette_used_colors[pal_base + 16 * color + 15] = (4|(1|2));
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
 pal_base = Machine->drv->gfxdecodeinfo[2].color_codes_start;
 for (color = 0;color < 16;color++) colmask[color] = 0;
 for (offs = spriteram_size - 32;offs >= 0;offs -= 32)
 {
  code = spriteram[offs] + 8 * (spriteram[offs + 1] & 0xe0);
  color = spriteram[offs + 1] & 0x0f;
  colmask[color] |= Machine->gfx[2]->pen_usage[code];
 }
 for (color = 0;color < 16;color++)
 {
  if (colmask[color] & (1 << 15))
   palette_used_colors[pal_base + 16 * color + 15] = (4|(1|2));
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
 pal_base = Machine->drv->gfxdecodeinfo[0].color_codes_start;
 for (color = 0;color < 64;color++) colmask[color] = 0;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  code = videoram[offs] + 4 * (colorram[offs] & 0xc0);
  color = colorram[offs] & 0x3f;
  colmask[color] |= Machine->gfx[0]->pen_usage[code];
 }
 for (color = 0;color < 64;color++)
 {
  if (colmask[color] & (1 << 3))
   palette_used_colors[pal_base + 4 * color + 3] = (4|(1|2));
  for (i = 0;i < 3;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 4 * color + i] = (1|2);
  }
 }
}
if (palette_recalc())
 dirtypalette = 1;
 if (bgon)
 {
  scrollx = sidearms_bg_scrollx[0] + 256 * sidearms_bg_scrollx[1] + 64;
  scrolly = sidearms_bg_scrolly[0] + 256 * sidearms_bg_scrolly[1];
  offs = 2 * (scrollx >> 5) + 0x100 * (scrolly >> 5);
  scrollx = -(scrollx & 0x1f);
  scrolly = -(scrolly & 0x1f);
  if (offs != lastoffs || dirtypalette)
  {
   unsigned char *p = memory_region(REGION_GFX4);
   lastoffs = offs;
   for (sy = 0;sy < 9;sy++)
   {
    for (sx = 0; sx < 13; sx++)
    {
     int offset;
     offset = offs + 2 * sx;
     offset = (offset & 0xf801) | ((offset & 0x0700) >> 7) | ((offset & 0x00fe) << 3);
     drawgfx(tmpbitmap2,Machine->gfx[1],
       p[offset] + 256 * (p[offset+1] & 0x01),
       (p[offset+1] & 0xf8) >> 3,
       p[offset+1] & 0x02,p[offset+1] & 0x04,
       32*sx,32*sy,
       0,TRANSPARENCY_NONE,0);
    }
    offs += 0x100;
   }
  }
 scrollx += 64;
 copyscrollbitmap(bitmap,tmpbitmap2,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 else fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 if (objon)
 {
  for (offs = spriteram_size - 32;offs >= 0;offs -= 32)
  {
   sx = spriteram[offs + 3] + ((spriteram[offs + 1] & 0x10) << 4);
   sy = spriteram[offs + 2];
   if (flipscreen)
   {
    sx = 496 - sx;
    sy = 240 - sy;
   }
   drawgfx(bitmap,Machine->gfx[2],
     spriteram[offs] + 8 * (spriteram[offs + 1] & 0xe0),
     spriteram[offs + 1] & 0x0f,
     flipscreen,flipscreen,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,15);
  }
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  sx = offs % 64;
  sy = offs / 64;
  if (flipscreen)
  {
   sx = 63 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 4 * (colorram[offs] & 0xc0),
    colorram[offs] & 0x3f,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,3);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: lastoffs int

variable_types: dirtypalette int

variable_types: color int

variable_types: code int

variable_types: i int

variable_types:
colmask
int [64]

variable_types:
p
unsigned char *

variable_types: offset int


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall turtship_ports_r(char a1)
{
unsigned int v1; // er13
unsigned int i; // er12
int v3; // eax
char v4; // cl

v1 = 0;
for ( i = 0; i != 8; ++i )
{
v3 = readinputport(i);
v4 = i;
v1 |= ((v3 >> a1) & 1) << v4;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
unsigned int v1; // er13
unsigned int i; // er12
int v3; // eax
char v4; // cl

v1 = 0;
for ( i = 0; i != 8; ++i )
{
v3 = readinputport(i);
v4 = i;
v1 |= ((v3 >> a1) & 1) << v4;
}
return v1;
}

original_code:
static data_t turtship_ports_r(offs_t offset)
{
 int i,res;
 res = 0;
 for (i = 0;i < 8;i++)
  res |= ((readinputport(i) >> offset) & 1) << i;
 return res;
}

canonical_original_code:
static unsigned int turtship_ports_r(unsigned int offset)
{
 int i; int res;
 res = 0;
 for (i = 0;i < 8;i++)
  res |= ((readinputport(i) >> offset) & 1) << i;
 return res;
}

variable_types: res int


irqhandler

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

canonical_decompiled_code:
__int64 __fastcall func5(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 __fastcall dynduke_background_r(unsigned int a1)
{
return *(unsigned __int8 *)(dynduke_back_data + a1);
}

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

original_code:
data_t dynduke_background_r(offs_t offset)
{
 return dynduke_back_data[offset];
}

canonical_original_code:
unsigned int dynduke_background_r(unsigned int offset)
{
 return dynduke_back_data[offset];
}


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

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

original_code:
data_t dynduke_foreground_r(offs_t offset)
{
 return dynduke_fore_data[offset];
}

canonical_original_code:
unsigned int dynduke_foreground_r(unsigned int offset)
{
 return dynduke_fore_data[offset];
}


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

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

original_code: static data_t dynduke_shared_r(offs_t offset) { return dynduke_shared_ram[offset]; }

canonical_original_code: static unsigned int dynduke_shared_r(unsigned int offset) { return dynduke_shared_ram[offset]; }


decompiled_code:
__int64 dynduke_interrupt()
{
return 50LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 50LL;
}

original_code:
static int dynduke_interrupt(void)
{
 return 0xc8/4;
}

canonical_original_code:
static int dynduke_interrupt()
{
 return 0xc8/4;
}


decompiled_code:
__int64 __fastcall dynduke_paletteram_w(unsigned int a1, char a2)
{
unsigned int v2; // edx
unsigned int v3; // ecx
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // er13
__int64 result; // rax
int v8; // ebx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFE));
v3 = v2 | (*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8);
v4 = v2 & 0xF0 | (v2 >> 4);
v5 = *(_BYTE *)(paletteram + (a1 & 0xFFE)) & 0xF | (16 * (*(_BYTE *)(paletteram + (a1 & 0xFFE)) & 0xF));
v6 = (v3 >> 8) & 0xF | (16 * ((v3 >> 8) & 0xF));
result = palette_change_color(a1 >> 1, v5, v4, v6);
if ( a1 <= 0x3FF )
{
v8 = (a1 >> 1) & 0xF | a1 & 0xFFE0;
palette_change_color(v8 | 0x800u, v5, v4, v6);
result = palette_change_color(v8 | 0x810u, v5, v4, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, char a2)
{
unsigned int v2; // edx
unsigned int v3; // ecx
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // er13
__int64 result; // rax
int v8; // ebx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFE));
v3 = v2 | (*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8);
v4 = v2 & 0xF0 | (v2 >> 4);
v5 = *(_BYTE *)(paletteram + (a1 & 0xFFE)) & 0xF | (16 * (*(_BYTE *)(paletteram + (a1 & 0xFFE)) & 0xF));
v6 = (v3 >> 8) & 0xF | (16 * ((v3 >> 8) & 0xF));
result = palette_change_color(a1 >> 1, v5, v4, v6);
if ( a1 <= 0x3FF )
{
v8 = (a1 >> 1) & 0xF | a1 & 0xFFE0;
palette_change_color(v8 | 0x800u, v5, v4, v6);
result = palette_change_color(v8 | 0x810u, v5, v4, v6);
}
return result;
}

original_code:
void dynduke_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 paletteram[offset]=data;
 data=paletteram[offset&0xffe]|(paletteram[offset|1]<<8);
 r = (data >> 0) & 0x0f;
 g = (data >> 4) & 0x0f;
 b = (data >> 8) & 0x0f;
 r = (r << 4) | r;
 g = (g << 4) | g;
 b = (b << 4) | b;
 palette_change_color(offset/2,r,g,b);
 if (offset<1024) {
  palette_change_color(((offset&0x1f)/2) | (offset&0xffe0) | 2048,r,g,b);
  palette_change_color(((offset&0x1f)/2) | (offset&0xffe0) | 2048 | 16,r,g,b);
 }
}

canonical_original_code:
void dynduke_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 paletteram[offset]=data;
 data=paletteram[offset&0xffe]|(paletteram[offset|1]<<8);
 r = (data >> 0) & 0x0f;
 g = (data >> 4) & 0x0f;
 b = (data >> 8) & 0x0f;
 r = (r << 4) | r;
 g = (g << 4) | g;
 b = (b << 4) | b;
 palette_change_color(offset/2,r,g,b);
 if (offset<1024) {
  palette_change_color(((offset&0x1f)/2) | (offset&0xffe0) | 2048,r,g,b);
  palette_change_color(((offset&0x1f)/2) | (offset&0xffe0) | 2048 | 16,r,g,b);
 }
}

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall dynduke_background_w(unsigned int a1, char a2)
{
*(_BYTE *)(dynduke_back_data + a1) = a2;
return tilemap_mark_tile_dirty(bg_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, char a2)
{
*(_BYTE *)(dynduke_back_data + a1) = a2;
return tilemap_mark_tile_dirty(bg_layer, a1 >> 1);
}

original_code:
void dynduke_background_w(offs_t offset,data_t data)
{
 dynduke_back_data[offset]=data;
 tilemap_mark_tile_dirty(bg_layer,offset/2);
}

canonical_original_code:
void dynduke_background_w(unsigned int offset, unsigned int data)
{
 dynduke_back_data[offset]=data;
 tilemap_mark_tile_dirty(bg_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dynduke_foreground_w(unsigned int a1, char a2)
{
*(_BYTE *)(dynduke_fore_data + a1) = a2;
return tilemap_mark_tile_dirty(fg_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, char a2)
{
*(_BYTE *)(dynduke_fore_data + a1) = a2;
return tilemap_mark_tile_dirty(fg_layer, a1 >> 1);
}

original_code:
void dynduke_foreground_w(offs_t offset,data_t data)
{
 dynduke_fore_data[offset]=data;
 tilemap_mark_tile_dirty(fg_layer,offset/2);
}

canonical_original_code:
void dynduke_foreground_w(unsigned int offset, unsigned int data)
{
 dynduke_fore_data[offset]=data;
 tilemap_mark_tile_dirty(fg_layer,offset/2);
}


decompiled_code:
__int64 __fastcall dynduke_text_w(unsigned int a1, char a2)
{
*(_BYTE *)(videoram + a1) = a2;
return tilemap_mark_tile_dirty(tx_layer, a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, char a2)
{
*(_BYTE *)(videoram + a1) = a2;
return tilemap_mark_tile_dirty(tx_layer, a1 >> 1);
}

original_code:
void dynduke_text_w(offs_t offset,data_t data)
{
 videoram[offset]=data;
 tilemap_mark_tile_dirty(tx_layer,offset/2);
}

canonical_original_code:
void dynduke_text_w(unsigned int offset, unsigned int data)
{
 videoram[offset]=data;
 tilemap_mark_tile_dirty(tx_layer,offset/2);
}


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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v4) = 32;
bg_layer = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 32LL, v4);
LODWORD(v5) = 32;
fg_layer = v1;
v2 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v5);
tx_layer = v2;
*(_QWORD *)(bg_layer + 136) = 0xFFFF00000000FFFFLL;
*(_DWORD *)(fg_layer + 132) = 15;
*(_DWORD *)(v2 + 132) = 15;
return 0LL;
}

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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v4) = 32;
bg_layer = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 32LL, v4);
LODWORD(v5) = 32;
fg_layer = v1;
v2 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v5);
tx_layer = v2;
*(_QWORD *)(bg_layer + 136) = 0xFFFF00000000FFFFLL;
*(_DWORD *)(fg_layer + 132) = 15;
*(_DWORD *)(v2 + 132) = 15;
return 0LL;
}

original_code:
int dynduke_vh_start(void)
{
 bg_layer = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,32,32);
 fg_layer = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,16,16,32,32);
 tx_layer = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01, 8, 8,32,32);
 bg_layer->transmask[0] = 0x0000ffff;
 bg_layer->transmask[1] = 0xffff0000;
 fg_layer->transparent_pen = 15;
 tx_layer->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int dynduke_vh_start()
{
 bg_layer = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,32,32);
 fg_layer = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,16,16,32,32);
 tx_layer = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01, 8, 8,32,32);
 bg_layer->transmask[0] = 0x0000ffff;
 bg_layer->transmask[1] = 0xffff0000;
 fg_layer->transparent_pen = 15;
 tx_layer->transparent_pen = 15;
 return 0;
}


decompiled_code:
__int64 __fastcall dynduke_gfxbank_w(__int64 a1, __int16 a2)
{
char v2; // al
int v3; // esi
__int64 result; // rax

v2 = a2;
v3 = (a2 << 8) & 0x1000;
fore_bankbase = v3;
back_bankbase = (v2 & 1) << 12;
if ( old_back_2 != back_bankbase )
{
tilemap_mark_all_tiles_dirty(bg_layer);
v3 = fore_bankbase;
}
if ( old_fore_1 != v3 )
{
tilemap_mark_all_tiles_dirty(fg_layer);
v3 = fore_bankbase;
}
result = (unsigned int)back_bankbase;
old_fore_1 = v3;
old_back_2 = back_bankbase;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int16 a2)
{
char v2; // al
int v3; // esi
__int64 result; // rax

v2 = a2;
v3 = (a2 << 8) & 0x1000;
fore_bankbase = v3;
back_bankbase = (v2 & 1) << 12;
if ( old_back_2 != back_bankbase )
{
tilemap_mark_all_tiles_dirty(bg_layer);
v3 = fore_bankbase;
}
if ( old_fore_1 != v3 )
{
tilemap_mark_all_tiles_dirty(fg_layer);
v3 = fore_bankbase;
}
result = (unsigned int)back_bankbase;
old_fore_1 = v3;
old_back_2 = back_bankbase;
return result;
}

original_code:
void dynduke_gfxbank_w(offs_t offset,data_t data)
{
 static int old_back,old_fore;
 if (data&0x01) back_bankbase=0x1000; else back_bankbase=0;
 if (data&0x10) fore_bankbase=0x1000; else fore_bankbase=0;
 if (back_bankbase!=old_back)
  tilemap_mark_all_tiles_dirty(bg_layer);
 if (fore_bankbase!=old_fore)
  tilemap_mark_all_tiles_dirty(fg_layer);
 old_back=back_bankbase;
 old_fore=fore_bankbase;
}

canonical_original_code:
void dynduke_gfxbank_w(unsigned int offset, unsigned int data)
{
 static int old_back; static int old_fore;
 if (data&0x01) back_bankbase=0x1000; else back_bankbase=0;
 if (data&0x10) fore_bankbase=0x1000; else fore_bankbase=0;
 if (back_bankbase!=old_back)
  tilemap_mark_all_tiles_dirty(bg_layer);
 if (fore_bankbase!=old_fore)
  tilemap_mark_all_tiles_dirty(fg_layer);
 old_back=back_bankbase;
 old_fore=fore_bankbase;
}


decompiled_code:
__int64 __fastcall dynduke_vh_screenrefresh(__int64 a1)
{
char *v2; // r8
__int64 v3; // rsi
__int64 v4; // r10
__int64 v5; // rdi
__int64 v6; // rdx
__int64 v7; // r9
__int16 v8; // ax
__int16 v9; // r11
char v10; // cl
__int64 v11; // rdi
__int64 v12; // rcx
unsigned int i; // eax
int v15[32]; // [rsp+0h] [rbp-98h] BYREF
char v16[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 = (char *)v15;
v3 = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
memset(v15, 0, sizeof(v15));
v4 = spriteram;
v5 = buffered_spriteram;
v6 = 8LL;
v7 = *(_QWORD *)(*(_QWORD *)(Machine + 536LL) + 32LL);
do
{
v8 = *(unsigned __int8 *)(v5 + v6 - 5);
v9 = *(unsigned __int8 *)(v5 + v6 - 6);
v10 = *(_BYTE *)(v4 + v6 - 7);
v6 += 8LL;
v15[v10 & 0x1F] |= *(_DWORD *)(v7 + 4LL * ((v9 + (v8 << 8)) & 0x3FFF));
}
while ( v6 != 4104 );
LODWORD(v11) = v3;
do
{
v12 = *(unsigned int *)v2;
for ( i = 0; i != 15; ++i )
{
if ( _bittest((const int *)&v12, i) )
{
v6 = (int)(i + v11);
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v6) = 3;
}
}
v2 += 4;
v11 = (unsigned int)(v11 + 16);
}
while ( v2 != v16 );
if ( palette_recalc(v11, v3, v6, v12, v2, v16) )
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)
{
char *v2; // r8
__int64 v3; // rsi
__int64 v4; // r10
__int64 v5; // rdi
__int64 v6; // rdx
__int64 v7; // r9
__int16 v8; // ax
__int16 v9; // r11
char v10; // cl
__int64 v11; // rdi
__int64 v12; // rcx
unsigned int i; // eax
int v15[32]; // [rsp+0h] [rbp-98h] BYREF
char v16[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 = (char *)v15;
v3 = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(Machine + 824LL) + 688LL) + 88LL);
memset(v15, 0, sizeof(v15));
v4 = spriteram;
v5 = buffered_spriteram;
v6 = 8LL;
v7 = *(_QWORD *)(*(_QWORD *)(Machine + 536LL) + 32LL);
do
{
v8 = *(unsigned __int8 *)(v5 + v6 - 5);
v9 = *(unsigned __int8 *)(v5 + v6 - 6);
v10 = *(_BYTE *)(v4 + v6 - 7);
v6 += 8LL;
v15[v10 & 0x1F] |= *(_DWORD *)(v7 + 4LL * ((v9 + (v8 << 8)) & 0x3FFF));
}
while ( v6 != 4104 );
LODWORD(v11) = v3;
do
{
v12 = *(unsigned int *)v2;
for ( i = 0; i != 15; ++i )
{
if ( _bittest((const int *)&v12, i) )
{
v6 = (int)(i + v11);
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v6) = 3;
}
}
v2 += 4;
v11 = (unsigned int)(v11 + 16);
}
while ( v2 != v16 );
if ( palette_recalc(v11, v3, v6, v12, v2, v16) )
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:
// attributes: thunk
__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();
}


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; // r8

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; // r8

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: erg int

variable_types: orig 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 v5; // rax
__int64 v6; // 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 + (v1 & 0xFFFu)) % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (back_palbase + (v1 >> 12));
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v5 = *(_QWORD *)(v2 + 16) + 2 * v4;
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 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 v5; // rax
__int64 v6; // 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 + (v1 & 0xFFFu)) % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (back_palbase + (v1 >> 12));
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v5 = *(_QWORD *)(v2 + 16) + 2 * v4;
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 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 v5; // rax
__int64 v6; // 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 + (v1 & 0xFFFu)) % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (v1 >> 12);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v5 = *(_QWORD *)(v2 + 16) + 2 * v4;
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 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 v5; // rax
__int64 v6; // 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 + (v1 & 0xFFFu)) % *(_DWORD *)(v2 + 8);
v4 = *(_DWORD *)(v2 + 12) * (v1 >> 12);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v5 = *(_QWORD *)(v2 + 16) + 2 * v4;
v6 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5;
result = 0LL;
if ( v6 )
result = *(unsigned int *)(v6 + 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; }
}


decompiled_code:
__int64 __fastcall get_tx_tile_info(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // 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);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 0xF);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 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
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // 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);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 0xF);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 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]; }

variable_types:
offset
unsigned int


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


decompiled_code:
__int64 mnchmobl_vh_start()
{
_OWORD *v0; // rax
__int64 result; // rax
__m128i v2; // xmm0

dirtybuffer = malloc(0x100uLL);
tmpbitmap = bitmap_alloc(512LL, 512LL);
v0 = dirtybuffer;
if ( tmpbitmap && dirtybuffer )
{
v2 = _mm_load_si128((const __m128i *)&LC0);
*dirtybuffer = v2;
v0[1] = v2;
v0[2] = v2;
v0[3] = v2;
v0[4] = v2;
v0[5] = v2;
v0[6] = v2;
v0[7] = v2;
v0[8] = v2;
v0[9] = v2;
v0[10] = v2;
v0[11] = v2;
v0[12] = v2;
v0[13] = v2;
v0[14] = v2;
v0[15] = v2;
result = 0LL;
}
else
{
mnchmobl_vh_stop();
result = 1LL;
}
return result;
}

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


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; // r14
__int64 v2; // r15
int v3; // ecx
__int64 v4; // r13
int v5; // ebx
__int64 result; // rax
int v7; // er8
int v8; // edx
char v9; // cl
unsigned int v10; // esi
int v11; // er9
char v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]

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

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // r14
__int64 v2; // r15
int v3; // ecx
__int64 v4; // r13
int v5; // ebx
__int64 result; // rax
int v7; // er8
int v8; // edx
char v9; // cl
unsigned int v10; // esi
int v11; // er9
char v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]

v1 = 0LL;
v2 = Machine + 776LL;
v3 = *(unsigned __int8 *)(mnchmobl_vreg + 7LL);
v12 = *(_BYTE *)(mnchmobl_vreg + 6LL);
v4 = *(_QWORD *)(Machine + 8LL * ((v3 >> 6) & 1) + 528);
v5 = -144 - (v3 >> 7);
result = (unsigned int)(4 * mnchmobl_palette_bank + 3);
v13 = 4 * mnchmobl_palette_bank + 3;
do
{
while ( 1 )
{
v7 = v1;
v8 = *(unsigned __int8 *)(mnchmobl_sprite_tile + v1);
v9 = *(_BYTE *)(mnchmobl_sprite_tile + v1);
if ( v8 != 255 )
{
v10 = *(unsigned __int8 *)(mnchmobl_sprite_attr + v1);
if ( (v10 & 0x80u) != 0 )
break;
}
if ( ++v1 == 512 )
return result;
}
v11 = *(unsigned __int8 *)(mnchmobl_sprite_xpos + v1++);
result = drawgfx(
a1,
v4,
~(_BYTE)v8 & 0x7F,
v13 - (v10 & 3),
0LL,
0LL,
v5 + 2 * (unsigned int)(unsigned __int8)(-32 - v12 - ((v11 >> 1) | v9 & 0x80)),
32 * (v7 >> 6) + ((v10 >> 2) & 0x1F),
v2,
2LL,
7LL);
}
while ( v1 != 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; // r13
int v2; // er10
__int64 v3; // rbx
unsigned __int8 *v4; // r10
unsigned __int8 *v5; // r14
__int64 v6; // r15
__int64 v7; // rdx
__int64 result; // rax
__int64 v9; // [rsp-28h] [rbp-80h]
int v10; // [rsp+Ch] [rbp-4Ch]
__m128i v11[4]; // [rsp+10h] [rbp-48h] BYREF

v10 = 0;
v1 = *(_QWORD *)(Machine + 512LL);
v11[0] = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
do
{
v2 = v10 & 1;
v3 = (unsigned int)(8 * v2);
v4 = (unsigned __int8 *)(mnchmobl_status_vram + 32 * v2);
v5 = v4;
if ( v10 <= 1 )
{
v5 = v4 + 64;
v3 = (unsigned int)(v3 + 304);
}
v6 = 0LL;
do
{
v7 = *v5++;
v9 = v6;
v6 = (unsigned int)(v6 + 8);
drawgfx(a1, v1, v7, 0LL, 0LL, 0LL, v3, v9, v11, 0LL, 0LL);
}
while ( (_DWORD)v6 != 256 );
result = (unsigned int)++v10;
}
while ( v10 != 4 );
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 v1; // r14
__int64 v2; // r13
__int64 v3; // rbx
int v4; // edx
__int64 v5; // rax
__int64 v6; // rbp
unsigned __int8 *v7; // r14
__int64 v8; // rdx
__int64 v10; // [rsp-30h] [rbp-B8h]
unsigned __int8 *v11; // [rsp+8h] [rbp-80h]
unsigned int v12; // [rsp+14h] [rbp-74h]
unsigned __int8 *v13; // [rsp+18h] [rbp-70h]
__int64 v14; // [rsp+20h] [rbp-68h]
__int64 v15; // [rsp+28h] [rbp-60h]
int v16; // [rsp+48h] [rbp-40h] BYREF
int v17[15]; // [rsp+4Ch] [rbp-3Ch] BYREF

v1 = 0LL;
v15 = memory_region(138LL);
v2 = *(_QWORD *)(Machine + 520LL);
do
{
while ( !*((_BYTE *)dirtybuffer + v1) )
{
if ( ++v1 == 256 )
goto LABEL_9;
}
v14 = v1;
v3 = 32 * (unsigned int)(v1 & 0xF);
v12 = 32 * ((int)v1 >> 4);
v4 = *(unsigned __int8 *)(videoram + v1);
*((_BYTE *)dirtybuffer + v1) = 0;
v5 = 4 * v4;
v11 = (unsigned __int8 *)(v15 + v5);
v13 = (unsigned __int8 *)(v15 + 4096 + v5);
do
{
v6 = v12;
v7 = v11;
do
{
v8 = *v7++;
v10 = v6;
v6 = (unsigned int)(v6 + 8);
drawgfx(tmpbitmap, v2, v8, (unsigned int)mnchmobl_palette_bank, 0LL, 0LL, v10, v3, 0LL, 0LL, 0LL);
}
while ( v12 + 32 != (_DWORD)v6 );
v11 += 1024;
v3 = (unsigned int)(v3 + 8);
}
while ( v13 != v11 );
v1 = v14 + 1;
}
while ( v14 != 255 );
LABEL_9:
v17[0] = 0;
v16 = -208 - ((*(_BYTE *)(mnchmobl_vreg + 7LL) >> 7) + 2 * *(unsigned __int8 *)(mnchmobl_vreg + 6LL));
return copyscrollbitmap(a1, tmpbitmap, 1LL, &v16, 1LL, v17, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // r14
__int64 v2; // r13
__int64 v3; // rbx
int v4; // edx
__int64 v5; // rax
__int64 v6; // rbp
unsigned __int8 *v7; // r14
__int64 v8; // rdx
__int64 v10; // [rsp-30h] [rbp-B8h]
unsigned __int8 *v11; // [rsp+8h] [rbp-80h]
unsigned int v12; // [rsp+14h] [rbp-74h]
unsigned __int8 *v13; // [rsp+18h] [rbp-70h]
__int64 v14; // [rsp+20h] [rbp-68h]
__int64 v15; // [rsp+28h] [rbp-60h]
int v16; // [rsp+48h] [rbp-40h] BYREF
int v17[15]; // [rsp+4Ch] [rbp-3Ch] BYREF

v1 = 0LL;
v15 = memory_region(138LL);
v2 = *(_QWORD *)(Machine + 520LL);
do
{
while ( !*((_BYTE *)dirtybuffer + v1) )
{
if ( ++v1 == 256 )
goto LABEL_9;
}
v14 = v1;
v3 = 32 * (unsigned int)(v1 & 0xF);
v12 = 32 * ((int)v1 >> 4);
v4 = *(unsigned __int8 *)(videoram + v1);
*((_BYTE *)dirtybuffer + v1) = 0;
v5 = 4 * v4;
v11 = (unsigned __int8 *)(v15 + v5);
v13 = (unsigned __int8 *)(v15 + 4096 + v5);
do
{
v6 = v12;
v7 = v11;
do
{
v8 = *v7++;
v10 = v6;
v6 = (unsigned int)(v6 + 8);
drawgfx(tmpbitmap, v2, v8, (unsigned int)mnchmobl_palette_bank, 0LL, 0LL, v10, v3, 0LL, 0LL, 0LL);
}
while ( v12 + 32 != (_DWORD)v6 );
v11 += 1024;
v3 = (unsigned int)(v3 + 8);
}
while ( v13 != v11 );
v1 = v14 + 1;
}
while ( v14 != 255 );
LABEL_9:
v17[0] = 0;
v16 = -208 - ((*(_BYTE *)(mnchmobl_vreg + 7LL) >> 7) + 2 * *(unsigned __int8 *)(mnchmobl_vreg + 6LL));
return copyscrollbitmap(a1, tmpbitmap, 1LL, &v16, 1LL, v17, 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:
__int64 __fastcall blitscreen_dirty1_color8(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // r13
__int64 v5; // r14
int v6; // er12
int v7; // er10
__int64 v8; // rbx
__int64 v9; // r15
int v10; // ebp
int v11; // er11
int v12; // edx
int v13; // ecx
__int64 v14; // rsi
__int64 i; // rdi
int v16; // er9
__int64 v17; // [rsp+0h] [rbp-60h]
__int64 v18; // [rsp+8h] [rbp-58h]
int v19; // [rsp+14h] [rbp-4Ch]
int v20; // [rsp+18h] [rbp-48h]
unsigned int v21; // [rsp+1Ch] [rbp-44h]
__int64 v22; // [rsp+20h] [rbp-40h]
__int64 v23; // [rsp+28h] [rbp-38h]

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 result; // rax
__int64 v4; // r13
__int64 v5; // r14
int v6; // er12
int v7; // er10
__int64 v8; // rbx
__int64 v9; // r15
int v10; // ebp
int v11; // er11
int v12; // edx
int v13; // ecx
__int64 v14; // rsi
__int64 i; // rdi
int v16; // er9
__int64 v17; // [rsp+0h] [rbp-60h]
__int64 v18; // [rsp+8h] [rbp-58h]
int v19; // [rsp+14h] [rbp-4Ch]
int v20; // [rsp+18h] [rbp-48h]
unsigned int v21; // [rsp+1Ch] [rbp-44h]
__int64 v22; // [rsp+20h] [rbp-40h]
__int64 v23; // [rsp+28h] [rbp-38h]

v1 = *(_QWORD **)(a1 + 24);
v2 = v1[1] - *v1;
v17 = v1[skiplines] + skipcolumns;
result = gfx_width;
v18 = gp2x_screen15 + 2 * (gfx_xoffset + (__int64)(int)(gfx_width * gfx_yoffset));
v20 = gfx_display_lines;
if ( gfx_display_lines > 0 )
{
v4 = (int)v2;
v5 = 2LL * (int)gfx_width;
v6 = 16;
v7 = gfx_display_columns;
v23 = 2LL * (int)(16 * gfx_width);
v8 = dirty_new;
v22 = 16 * (int)v2;
v21 = ((gfx_display_lines - 1) & 0xFFFFFFF0) + 32;
v9 = dirty_old;
do
{
result = (unsigned int)(v6 - 16);
v10 = 0;
v19 = result;
v11 = (int)result >> 4 << 8;
while ( v7 > v10 )
{
while ( 1 )
{
v12 = v10 + 16;
result = v11 + (v10 >> 4);
if ( *(_BYTE *)(v8 + result) || *(_BYTE *)(v9 + result) )
break;
v10 += 16;
if ( v7 <= v12 )
goto LABEL_20;
}
result = v10;
v13 = 16;
v14 = v17 + v10;
for ( i = v18 + 2LL * v10; v12 < v7; v13 += 16 )
{
result = v11 + (v12 >> 4);
if ( !*(_BYTE *)(v8 + result) && !*(_BYTE *)(v9 + result) )
break;
v12 += 16;
}
if ( v7 < v12 )
{
v13 = v7 - v10;
v10 = v7;
}
else
{
v10 += v13;
}
v16 = v19;
do
{
if ( v20 <= v16 )
break;
result = 0LL;
do
{
*(_WORD *)(i + 2 * result) = gp2x_palette[*(unsigned __int8 *)(v14 + result)];
++result;
}
while ( v13 != result );
++v16;
v14 += v4;
i += v5;
}
while ( v6 != v16 );
}
LABEL_20:
v6 += 16;
v17 += v22;
v18 += v23;
}
while ( v21 != 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