decompiled_code:
_BOOL8 __fastcall load_driver_history(__int64 a1, char *a2, int a3)
{
__int64 v3; // rbx
_BOOL4 v5; // er15
__int64 v6; // r13
_BOOL4 v7; // eax
_BOOL4 v8; // er14
int v9; // er13
_BOOL4 v10; // eax

v3 = a1;
*a2 = 0;
v5 = 0;
if ( (unsigned __int8)ParseOpen((__int64)history_filename[0]) )
{
v5 = 1;
if ( hist_idx_1 || (v5 = index_datafile(&hist_idx_1) != 0, hist_idx_1) )
{
v6 = a1;
do
{
v7 = load_datafile_text(v6, a2, a3, (_QWORD *)hist_idx_1, DATAFILE_TAG_BIO[0]);
v6 = *(_QWORD *)(v6 + 8);
}
while ( v7 && v6 );
if ( v7 )
v5 = 0;
}
ParseClose();
}
v8 = 0;
if ( (unsigned __int8)ParseOpen((__int64)mameinfo_filename[0]) )
{
v8 = 1;
if ( mame_idx_0 || (v8 = index_datafile(&mame_idx_0) != 0, mame_idx_0) )
{
v9 = strlen(a2);
do
{
v10 = load_datafile_text(v3, &a2[v9], a3 - v9, (_QWORD *)mame_idx_0, DATAFILE_TAG_MAME[0]);
v3 = *(_QWORD *)(v3 + 8);
}
while ( v10 && v3 );
if ( v10 )
v8 = 0;
}
ParseClose();
}
return !v8 && !v5;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, char *a2, int a3)
{
__int64 v3; // rbx
_BOOL4 v5; // er15
__int64 v6; // r13
_BOOL4 v7; // eax
_BOOL4 v8; // er14
int v9; // er13
_BOOL4 v10; // eax

v3 = a1;
*a2 = 0;
v5 = 0;
if ( (unsigned __int8)func0((__int64)history_filename[0]) )
{
v5 = 1;
if ( hist_idx_1 || (v5 = func5(&hist_idx_1) != 0, hist_idx_1) )
{
v6 = a1;
do
{
v7 = func6(v6, a2, a3, (_QWORD *)hist_idx_1, DATAFILE_TAG_BIO[0]);
v6 = *(_QWORD *)(v6 + 8);
}
while ( v7 && v6 );
if ( v7 )
v5 = 0;
}
func7();
}
v8 = 0;
if ( (unsigned __int8)func0((__int64)mameinfo_filename[0]) )
{
v8 = 1;
if ( mame_idx_0 || (v8 = func5(&mame_idx_0) != 0, mame_idx_0) )
{
v9 = strlen(a2);
do
{
v10 = func6(v3, &a2[v9], a3 - v9, (_QWORD *)mame_idx_0, DATAFILE_TAG_MAME[0]);
v3 = *(_QWORD *)(v3 + 8);
}
while ( v10 && v3 );
if ( v10 )
v8 = 0;
}
func7();
}
return !v8 && !v5;
}

original_code:
int load_driver_history (const struct GameDriver *drv, char *buffer, int bufsize)
{
 static struct tDatafileIndex *hist_idx = 0;
 static struct tDatafileIndex *mame_idx = 0;
 int history = 0, mameinfo = 0;
 int err;
 *buffer = 0;
 if (ParseOpen (history_filename))
 {
  if (hist_idx)
   history = 1;
  else
   history = (index_datafile (&hist_idx) != 0);
  if (hist_idx)
  {
   const struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer, bufsize,
            hist_idx, DATAFILE_TAG_BIO);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) history = 0;
  }
  ParseClose ();
 }
 if (ParseOpen (mameinfo_filename))
 {
  if (mame_idx)
   mameinfo = 1;
  else
   mameinfo = (index_datafile (&mame_idx) != 0);
  if (mame_idx)
  {
   int len = strlen (buffer);
   const struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer+len, bufsize-len,
            mame_idx, DATAFILE_TAG_MAME);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) mameinfo = 0;
  }
  ParseClose ();
 }
 return (history == 0 && mameinfo == 0);
}

canonical_original_code:
int load_driver_history(struct GameDriver *drv, char *buffer, int bufsize)
{
 static struct tDatafileIndex *hist_idx = 0;
 static struct tDatafileIndex *mame_idx = 0;
 int history = 0; int mameinfo = 0;
 int err;
 *buffer = 0;
 if (ParseOpen (history_filename))
 {
  if (hist_idx)
   history = 1;
  else
   history = (index_datafile (&hist_idx) != 0);
  if (hist_idx)
  {
   struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer, bufsize,
            hist_idx, DATAFILE_TAG_BIO);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) history = 0;
  }
  ParseClose ();
 }
 if (ParseOpen (mameinfo_filename))
 {
  if (mame_idx)
   mameinfo = 1;
  else
   mameinfo = (index_datafile (&mame_idx) != 0);
  if (mame_idx)
  {
   int len = strlen (buffer);
   struct GameDriver *gdrv;
   gdrv = drv;
   do
   {
    err = load_datafile_text (gdrv, buffer+len, bufsize-len,
            mame_idx, DATAFILE_TAG_MAME);
    gdrv = gdrv->clone_of;
   } while (err && gdrv);
   if (err) mameinfo = 0;
  }
  ParseClose ();
 }
 return (history == 0 && mameinfo == 0);
}

variable_types: struct tDatafileIndex { long offset; struct GameDriver { char *source_file; struct GameDriver *clone_of; char *name; char *description; char *year; char *manufacturer; struct MachineDriver { struct MachineCPU { int cpu_type; int cpu_clock; struct MemoryReadAddress { unsigned int start; unsigned int (*handler)(unsigned int offset); } *memory_read; struct MemoryWriteAddress { unsigned int start; void (*handler)(unsigned int offset, unsigned int data); unsigned char **base; unsigned long *size; } *memory_write; struct IOReadPort { int start; unsigned int (*handler)(unsigned int offset); } *port_read; struct IOWritePort { int start; void (*handler)(unsigned int offset, unsigned int data); } *port_write; int (*vblank_interrupt)(); int vblank_interrupts_per_frame; int (*timed_interrupt)(); int timed_interrupts_per_second; void *reset_param; } cpu[8]; float frames_per_second; int vblank_duration; int cpu_slices_per_frame; void (*init_machine)(); int screen_width; struct rectangle { int min_x; int min_y; } default_visible_area; struct GfxDecodeInfo { int memory_region; int start; struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; } *gfxlayout; int color_codes_start; int total_color_codes; } *gfxdecodeinfo; unsigned int total_colors; unsigned int color_table_len; void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom); int video_attributes; void (*vh_eof_callback)(); int (*vh_start)(); void (*vh_stop)(); void (*vh_update)(struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *bitmap, int full_refresh); int sound_attributes; int obsolete1; int obsolete2; int obsolete3; struct MachineSound { int sound_type; void *sound_interface; } sound[5]; void (*nvram_handler)(void *file, int read_or_write); } *drv; struct InputPortTiny { unsigned short mask; unsigned short default_value; unsigned int type; char *name; } *input_ports; void (*driver_init)(); struct RomModule { char *name; unsigned int offset; unsigned int length; unsigned int crc; } *rom; unsigned int flags; } *driver; } *

variable_types: history int

variable_types: mameinfo int

variable_types: err int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

return_type: void


decompiled_code:
__int64 exprraid_prot_1_r()
{
return 2LL;
}

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

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

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

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
void *__fastcall exprraid_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // rbp
unsigned __int8 v2; // cl
unsigned int v3; // er12
__int64 v4; // rbx
__int64 v5; // r13
__int64 v6; // rcx
void *result; // rax
int v8; // ebx
__int64 v9; // rbp
unsigned int v10; // [rsp+8h] [rbp-40h]
unsigned int v11; // [rsp+Ch] [rbp-3Ch]

drawbg(a1, 0);
if ( spriteram_size )
{
v1 = 0LL;
do
{
v2 = *(_BYTE *)(spriteram + v1 + 1);
v3 = *(unsigned __int8 *)(spriteram + v1 + 3) + ((8 * v2) & 0x700);
v4 = (unsigned int)(unsigned __int8)(-8 - *(_BYTE *)(spriteram + v1 + 2)) - 8;
v5 = *(unsigned __int8 *)(spriteram + v1);
v11 = v2 & 4;
v6 = v2 & 3 | ((int)v2 >> 1) & 4u;
v10 = v6;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v3, v6, *(_BYTE *)(spriteram + v1 + 1) & 4, 0LL, v4, v5, 0LL, 2LL, 0LL);
if ( (*(_BYTE *)(spriteram + v1 + 1) & 0x10) != 0 )
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v3 + 1, v10, v11, 0LL, v4, (unsigned int)(v5 + 16), 0LL, 2LL, 0LL);
v1 += 4LL;
}
while ( spriteram_size > v1 );
}
drawbg(a1, 1);
result = &videoram_size;
v8 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v9 = v8;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(colorram + v9) << 8) & 0x700)
+ (unsigned int)*(unsigned __int8 *)(videoram + v9),
((int)*(unsigned __int8 *)(colorram + v9) >> 4) & 1,
0LL,
0LL,
(unsigned int)(8 * (v8 % 32)),
(unsigned int)(8 * (v8 / 32)),
Machine + 776LL,
2LL,
0LL);
--v9;
--v8;
}
while ( v8 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rbp
unsigned __int8 v2; // cl
unsigned int v3; // er12
__int64 v4; // rbx
__int64 v5; // r13
__int64 v6; // rcx
void *result; // rax
int v8; // ebx
__int64 v9; // rbp
unsigned int v10; // [rsp+8h] [rbp-40h]
unsigned int v11; // [rsp+Ch] [rbp-3Ch]

func2(a1, 0);
if ( spriteram_size )
{
v1 = 0LL;
do
{
v2 = *(_BYTE *)(spriteram + v1 + 1);
v3 = *(unsigned __int8 *)(spriteram + v1 + 3) + ((8 * v2) & 0x700);
v4 = (unsigned int)(unsigned __int8)(-8 - *(_BYTE *)(spriteram + v1 + 2)) - 8;
v5 = *(unsigned __int8 *)(spriteram + v1);
v11 = v2 & 4;
v6 = v2 & 3 | ((int)v2 >> 1) & 4u;
v10 = v6;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v3, v6, *(_BYTE *)(spriteram + v1 + 1) & 4, 0LL, v4, v5, 0LL, 2LL, 0LL);
if ( (*(_BYTE *)(spriteram + v1 + 1) & 0x10) != 0 )
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v3 + 1, v10, v11, 0LL, v4, (unsigned int)(v5 + 16), 0LL, 2LL, 0LL);
v1 += 4LL;
}
while ( spriteram_size > v1 );
}
func2(a1, 1);
result = &videoram_size;
v8 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v9 = v8;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(colorram + v9) << 8) & 0x700)
+ (unsigned int)*(unsigned __int8 *)(videoram + v9),
((int)*(unsigned __int8 *)(colorram + v9) >> 4) & 1,
0LL,
0LL,
(unsigned int)(8 * (v8 % 32)),
(unsigned int)(8 * (v8 / 32)),
Machine + 776LL,
2LL,
0LL);
--v9;
--v8;
}
while ( v8 >= 0 );
}
return result;
}

original_code:
void exprraid_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 drawbg(bitmap,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx,sy,code,color,flipx;
  code = spriteram[offs+3] + ( ( spriteram[offs+1] & 0xe0 ) << 3 );
  sx = ((248 - spriteram[offs+2]) & 0xff) - 8;
  sy = spriteram[offs];
  color = (spriteram[offs+1] & 0x03) + ((spriteram[offs+1] & 0x08) >> 1);
  flipx = ( spriteram[offs+1] & 0x04 );
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,0,
    sx,sy,
    0,TRANSPARENCY_PEN,0);
  if ( spriteram[offs+1] & 0x10 ) {
   drawgfx(bitmap,Machine->gfx[1],
     code + 1,
     color,
     flipx,0,
     sx,sy+16,
     0,TRANSPARENCY_PEN,0);
  }
 }
 drawbg(bitmap,1);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + ((colorram[offs] & 7) << 8),
    (colorram[offs] & 0x10) >> 4,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void exprraid_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 drawbg(bitmap,0);
 for (offs = 0;offs < spriteram_size;offs += 4)
 {
  int sx; int sy; int code; int color; int flipx;
  code = spriteram[offs+3] + ( ( spriteram[offs+1] & 0xe0 ) << 3 );
  sx = ((248 - spriteram[offs+2]) & 0xff) - 8;
  sy = spriteram[offs];
  color = (spriteram[offs+1] & 0x03) + ((spriteram[offs+1] & 0x08) >> 1);
  flipx = ( spriteram[offs+1] & 0x04 );
  drawgfx(bitmap,Machine->gfx[1],
    code,
    color,
    flipx,0,
    sx,sy,
    0,TRANSPARENCY_PEN,0);
  if ( spriteram[offs+1] & 0x10 ) {
   drawgfx(bitmap,Machine->gfx[1],
     code + 1,
     color,
     flipx,0,
     sx,sy+16,
     0,TRANSPARENCY_PEN,0);
  }
 }
 drawbg(bitmap,1);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + ((colorram[offs] & 7) << 8),
    (colorram[offs] & 0x10) >> 4,
    0,0,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: code int

variable_types: color int

variable_types: flipx int


decompiled_code:
__int64 exprraid_prot_0_r()
{
return *(unsigned __int8 *)(memory_region(129LL) + 681);
}

canonical_decompiled_code:
__int64 func4()
{
return *(unsigned __int8 *)(memory_region(129LL) + 681);
}

original_code:
static data_t exprraid_prot_0_r(offs_t offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 return RAM[0x02a9];
}

canonical_original_code:
static unsigned int exprraid_prot_0_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 return RAM[0x02a9];
}

variable_types:
RAM
unsigned char *


decompiled_code:
_QWORD *exprraid_gfx_expand()
{
__int64 v0; // r8
_QWORD *result; // rax
char *v2; // rdx
_QWORD *v3; // r8

v0 = memory_region(139LL);
result = (_QWORD *)(v0 + 61440);
v2 = (char *)(v0 + 28672);
v3 = (_QWORD *)(v0 - 4096);
do
{
*result = *(_QWORD *)v2;
result[511] = *((_QWORD *)v2 + 511);
qmemcpy(
(void *)((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - ((char *)result - ((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 4096) >> 3));
*(result - 512) = *(_QWORD *)v2;
*(result - 1) = *((_QWORD *)v2 + 511);
qmemcpy(
(void *)((unsigned __int64)(result - 511) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - ((char *)result - ((unsigned __int64)(result - 511) & 0xFFFFFFFFFFFFFFF8LL) - 4096)),
8LL * (((unsigned int)result - (((_DWORD)result - 4088) & 0xFFFFFFF8)) >> 3));
result -= 1024;
v2 -= 4096;
}
while ( result != v3 );
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
__int64 v0; // r8
_QWORD *result; // rax
char *v2; // rdx
_QWORD *v3; // r8

v0 = memory_region(139LL);
result = (_QWORD *)(v0 + 61440);
v2 = (char *)(v0 + 28672);
v3 = (_QWORD *)(v0 - 4096);
do
{
*result = *(_QWORD *)v2;
result[511] = *((_QWORD *)v2 + 511);
qmemcpy(
(void *)((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - ((char *)result - ((unsigned __int64)(result + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)result - (((_DWORD)result + 8) & 0xFFFFFFF8) + 4096) >> 3));
*(result - 512) = *(_QWORD *)v2;
*(result - 1) = *((_QWORD *)v2 + 511);
qmemcpy(
(void *)((unsigned __int64)(result - 511) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - ((char *)result - ((unsigned __int64)(result - 511) & 0xFFFFFFFFFFFFFFF8LL) - 4096)),
8LL * (((unsigned int)result - (((_DWORD)result - 4088) & 0xFFFFFFF8)) >> 3));
result -= 1024;
v2 -= 4096;
}
while ( result != v3 );
return result;
}

original_code:
static void exprraid_gfx_expand(void)
{
 unsigned char *gfx = memory_region(REGION_GFX3);
 int offs = 0x10000-0x1000;
 int i;
 for ( i = 0x8000-0x1000; i >= 0; i-= 0x1000 )
 {
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
 }
}

canonical_original_code:
static void exprraid_gfx_expand()
{
 unsigned char *gfx = memory_region(REGION_GFX3);
 int offs = 0x10000-0x1000;
 int i;
 for ( i = 0x8000-0x1000; i >= 0; i-= 0x1000 )
 {
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
  memcpy( &(gfx[offs]), &(gfx[i]), 0x1000 );
  offs -= 0x1000;
 }
}

variable_types:
gfx
unsigned char *


decompiled_code:
__int64 init_wexpress()
{
__int64 v0; // rbx
__int64 result; // rax
_BYTE *v2; // rcx
_BYTE *v3; // rsi

v0 = memory_region(129LL);
exprraid_gfx_expand();
LODWORD(result) = 0;
do
{
v2 = (_BYTE *)(v0 + (int)result);
if ( *v2 == 75 )
{
v3 = (_BYTE *)(v0 + (int)result + 1);
if ( !*v3 && *(_BYTE *)(v0 + (int)result + 2) == 41 && *(_BYTE *)(v0 + (int)result + 3) == 2 )
{
*v2 = -91;
LODWORD(result) = result + 1;
*v3 = -1;
}
}
result = (unsigned int)(result + 1);
}
while ( (int)result <= 0xFFFF );
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
__int64 result; // rax
_BYTE *v2; // rcx
_BYTE *v3; // rsi

v0 = memory_region(129LL);
func5();
LODWORD(result) = 0;
do
{
v2 = (_BYTE *)(v0 + (int)result);
if ( *v2 == 75 )
{
v3 = (_BYTE *)(v0 + (int)result + 1);
if ( !*v3 && *(_BYTE *)(v0 + (int)result + 2) == 41 && *(_BYTE *)(v0 + (int)result + 3) == 2 )
{
*v2 = -91;
LODWORD(result) = result + 1;
*v3 = -1;
}
}
result = (unsigned int)(result + 1);
}
while ( (int)result <= 0xFFFF );
return result;
}

original_code:
static void init_wexpress(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 exprraid_gfx_expand();
 for ( i = 0; i < 0x10000; i++ )
 {
  if ( rom[i] == 0x4b && rom[i+1] == 0x00 && rom[i+2] == 0x29 && rom[i+3] == 0x02 )
  {
   rom[i] = 0xa5;
   i++;
   rom[i] = 0xff;
  }
 }
}

canonical_original_code:
static void init_wexpress()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
 exprraid_gfx_expand();
 for ( i = 0; i < 0x10000; i++ )
 {
  if ( rom[i] == 0x4b && rom[i+1] == 0x00 && rom[i+2] == 0x29 && rom[i+3] == 0x02 )
  {
   rom[i] = 0xa5;
   i++;
   rom[i] = 0xff;
  }
 }
}

variable_types:
rom
unsigned char *


original_code:
static void init_exprraid(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0xfffa] = rom[0xfff7];
 rom[0xfffb] = rom[0xfff6];
 rom[0xfffc] = rom[0xfff1];
 rom[0xfffd] = rom[0xfff0];
 rom[0xfffe] = rom[0xfff3];
 rom[0xffff] = rom[0xfff2];
 init_wexpress();
}

canonical_original_code:
static void init_exprraid()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 rom[0xfffa] = rom[0xfff7];
 rom[0xfffb] = rom[0xfff6];
 rom[0xfffc] = rom[0xfff1];
 rom[0xfffd] = rom[0xfff0];
 rom[0xfffe] = rom[0xfff3];
 rom[0xffff] = rom[0xfff2];
 init_wexpress();
}


decompiled_code:
_QWORD *init_wexpresb()
{
return exprraid_gfx_expand();
}

canonical_decompiled_code:
_QWORD *func8()
{
return func5();
}

original_code:
static void init_wexpresb(void)
{
 exprraid_gfx_expand();
}

canonical_original_code:
static void init_wexpresb()
{
 exprraid_gfx_expand();
}


decompiled_code:
__int64 exprraid_interrupt()
{
if ( (~(unsigned __int8)readinputport(3LL) & 0xC0) != 0 )
{
if ( !coin_0 )
{
coin_0 = 1;
return nmi_interrupt();
}
}
else
{
coin_0 = 0;
}
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func10()
{
if ( (~(unsigned __int8)readinputport(3LL) & 0xC0) != 0 )
{
if ( !coin_0 )
{
coin_0 = 1;
return nmi_interrupt();
}
}
else
{
coin_0 = 0;
}
return ignore_interrupt();
}

original_code:
static int exprraid_interrupt(void)
{
 static int coin = 0;
 if ( ( ~readinputport( 3 ) ) & 0xc0 ) {
  if ( coin == 0 ) {
   coin = 1;
   return nmi_interrupt();
  }
 } else
  coin = 0;
 return ignore_interrupt();
}

canonical_original_code:
static int exprraid_interrupt()
{
 static int coin = 0;
 if ( ( ~readinputport( 3 ) ) & 0xc0 ) {
  if ( coin == 0 ) {
   coin = 1;
   return nmi_interrupt();
  }
 } else
  coin = 0;
 return ignore_interrupt();
}

variable_types: coin int

return_type: int


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

v0 = readinputport(0LL);
if ( (v0 & 2) != 0 )
cpu_spin();
return v0;
}

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

v0 = readinputport(0LL);
if ( (v0 & 2) != 0 )
cpu_spin();
return v0;
}

original_code:
static data_t vblank_r(offs_t offset) {
 int val = readinputport( 0 );
 if ( ( val & 0x02 ) )
  cpu_spin();
 return val;
}

canonical_original_code:
static unsigned int vblank_r(unsigned int offset) {
 int val = readinputport( 0 );
 if ( ( val & 0x02 ) )
  cpu_spin();
 return val;
}

variable_types: val int


irqhandler

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

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1);
}

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

variable_types: linestate int


decompiled_code:
__int64 sound_cpu_command_w()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 4LL);
}

canonical_decompiled_code:
__int64 func11()
{
soundlatch_w(0LL);
return cpu_cause_interrupt(1LL, 4LL);
}

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

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

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall canyon_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( a2 || *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v3) & 0x3F,
*(_BYTE *)(videoram + v3) >> 7,
0LL,
0LL,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(unsigned __int8 *)(spriteram + 9LL) >> 3) & 3,
0LL,
*(char *)(spriteram + 9LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 1LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 8LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(unsigned __int8 *)(spriteram + 11LL) >> 3) & 3,
1LL,
*(char *)(spriteram + 11LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 3LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 10LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
2LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 5LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 12LL),
Machine + 776LL,
2LL,
0LL);
return drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
3LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 7LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 14LL),
Machine + 776LL,
2LL,
0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( a2 || *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v3) & 0x3F,
*(_BYTE *)(videoram + v3) >> 7,
0LL,
0LL,
(unsigned int)(8 * (v2 % 32)),
(unsigned int)(8 * (v2 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(unsigned __int8 *)(spriteram + 9LL) >> 3) & 3,
0LL,
*(char *)(spriteram + 9LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 1LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 8LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(unsigned __int8 *)(spriteram + 11LL) >> 3) & 3,
1LL,
*(char *)(spriteram + 11LL) >= 0,
0LL,
224 - (unsigned int)*(unsigned __int8 *)(spriteram + 3LL),
240 - (unsigned int)*(unsigned __int8 *)(spriteram + 10LL),
Machine + 776LL,
2LL,
0LL);
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
2LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 5LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 12LL),
Machine + 776LL,
2LL,
0LL);
return drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
0LL,
3LL,
0LL,
0LL,
254 - (unsigned int)*(unsigned __int8 *)(spriteram + 7LL),
246 - (unsigned int)*(unsigned __int8 *)(spriteram + 14LL),
Machine + 776LL,
2LL,
0LL);
}

original_code:
void canyon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (full_refresh || dirtybuffer[offs])
  {
   int charcode;
   int sx,sy;
   dirtybuffer[offs]=0;
   charcode = videoram[offs] & 0x3F;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0],
     charcode, (videoram[offs] & 0x80)>>7,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs=0; offs<2; offs++)
 {
  int sx, sy;
  int pic;
  int flipx;
  sx = 224 - spriteram[offs*2+1];
  sy = 240 - spriteram[offs*2+8];
  pic = spriteram[offs*2+9];
  if (pic & 0x80)
   flipx=0;
  else
   flipx=1;
        drawgfx(bitmap,Machine->gfx[1],
                (pic & 0x18) >> 3, offs,
  flipx,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs=2; offs<4; offs++)
 {
  int sx, sy;
  sx = 254 - spriteram[offs*2+1];
  sy = 246 - spriteram[offs*2+8];
        drawgfx(bitmap,Machine->gfx[2],
                0, offs,
  0,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void canyon_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (full_refresh || dirtybuffer[offs])
  {
   int charcode;
   int sx; int sy;
   dirtybuffer[offs]=0;
   charcode = videoram[offs] & 0x3F;
   sx = 8 * (offs % 32);
   sy = 8 * (offs / 32);
   drawgfx(tmpbitmap,Machine->gfx[0],
     charcode, (videoram[offs] & 0x80)>>7,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs=0; offs<2; offs++)
 {
  int sx; int sy;
  int pic;
  int flipx;
  sx = 224 - spriteram[offs*2+1];
  sy = 240 - spriteram[offs*2+8];
  pic = spriteram[offs*2+9];
  if (pic & 0x80)
   flipx=0;
  else
   flipx=1;
        drawgfx(bitmap,Machine->gfx[1],
                (pic & 0x18) >> 3, offs,
  flipx,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs=2; offs<4; offs++)
 {
  int sx; int sy;
  sx = 254 - spriteram[offs*2+1];
  sy = 246 - spriteram[offs*2+8];
        drawgfx(bitmap,Machine->gfx[2],
                0, offs,
  0,0,sx,sy,
  &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: charcode int

variable_types: pic int

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


decompiled_code:
__int64 __fastcall canyon_motor_w(char a1, char a2)
{
return discrete_sound_w(a1 & 1, a2 & 0xF);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, char a2)
{
return discrete_sound_w(a1 & 1, a2 & 0xF);
}

original_code:
void canyon_motor_w(offs_t offset,data_t data)
{
        discrete_sound_w(offset & 0x01, data & 0x0f);
}

canonical_original_code:
void canyon_motor_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(offset & 0x01, data & 0x0f);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall canyon_explode_w(__int64 a1, unsigned int a2)
{
return discrete_sound_w(6LL, a2 >> 4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
return discrete_sound_w(6LL, a2 >> 4);
}

original_code:
void canyon_explode_w(offs_t offset,data_t data)
{
        discrete_sound_w(6, data / 16);
}

canonical_original_code:
void canyon_explode_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(6, data / 16);
}


decompiled_code:
__int64 __fastcall canyon_attract_w(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 4, ((unsigned __int8)(a1 >> 1) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 4, ((unsigned __int8)(a1 >> 1) ^ 1) & 1);
}

original_code:
void canyon_attract_w(offs_t offset,data_t data)
{
        discrete_sound_w(4 + (offset & 0x01), !(offset & 0x02));
}

canonical_original_code:
void canyon_attract_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(4 + (offset & 0x01), !(offset & 0x02));
}


decompiled_code:
__int64 __fastcall canyon_whistle_w(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 2, (a1 >> 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return discrete_sound_w((a1 & 1) + 2, (a1 >> 1) & 1);
}

original_code:
void canyon_whistle_w(offs_t offset,data_t data)
{
        discrete_sound_w(2 + (offset & 0x01), (offset & 0x02) >> 1);
}

canonical_original_code:
void canyon_whistle_w(unsigned int offset, unsigned int data)
{
        discrete_sound_w(2 + (offset & 0x01), (offset & 0x02) >> 1);
}


decompiled_code:
__int64 __fastcall canyon_options_r(char a1)
{
unsigned int v1; // edi

v1 = a1 & 3;
if ( v1 == 2 )
return ((unsigned int)input_port_0_r(0LL) >> 2) & 3;
if ( v1 > 2 )
return input_port_0_r(0LL) & 3;
if ( v1 )
return ((unsigned int)input_port_0_r(0LL) >> 4) & 3;
return (unsigned __int8)input_port_0_r(0LL) >> 6;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
unsigned int v1; // edi

v1 = a1 & 3;
if ( v1 == 2 )
return ((unsigned int)input_port_0_r(0LL) >> 2) & 3;
if ( v1 > 2 )
return input_port_0_r(0LL) & 3;
if ( v1 )
return ((unsigned int)input_port_0_r(0LL) >> 4) & 3;
return (unsigned __int8)input_port_0_r(0LL) >> 6;
}

original_code:
static data_t canyon_options_r(offs_t offset)
{
 switch (offset & 0x03)
 {
  case 0x00:
   return ((input_port_0_r(0) >> 6) & 0x03);
  case 0x01:
   return ((input_port_0_r(0) >> 4) & 0x03);
  case 0x02:
   return ((input_port_0_r(0) >> 2) & 0x03);
  case 0x03:
   return ((input_port_0_r(0) >> 0) & 0x03);
 }
 return 0xFF;
}

canonical_original_code:
static unsigned int canyon_options_r(unsigned int offset)
{
 switch (offset & 0x03)
 {
  case 0x00:
   return ((input_port_0_r(0) >> 6) & 0x03);
  case 0x01:
   return ((input_port_0_r(0) >> 4) & 0x03);
  case 0x02:
   return ((input_port_0_r(0) >> 2) & 0x03);
  case 0x03:
   return ((input_port_0_r(0) >> 0) & 0x03);
 }
 return 0xFF;
}


decompiled_code:
__int64 __fastcall canyon_switches_r(char a1)
{
__int64 result; // rax
char v2; // bl
char v3; // bl
char v4; // bl
char v5; // bl

switch ( a1 & 7 )
{
case 0:
result = (unsigned __int8)((unsigned __int8)input_port_3_r(0LL) << 7);
break;
case 1:
result = (unsigned __int8)((unsigned __int8)input_port_3_r(0LL) << 6) & 0x80;
break;
case 2:
v2 = input_port_3_r(0LL);
result = (unsigned int)input_port_1_r(0LL) | (32 * v2) & 0x80;
break;
case 3:
v3 = input_port_3_r(0LL);
result = (unsigned int)input_port_2_r(0LL) | (16 * v3) & 0x80;
break;
case 4:
result = (unsigned __int8)(8 * input_port_3_r(0LL)) & 0x80;
break;
case 5:
result = (unsigned __int8)(4 * input_port_3_r(0LL)) & 0x80;
break;
case 6:
v4 = input_port_3_r(0LL);
result = (unsigned int)input_port_1_r(0LL) | (2 * v4) & 0x80;
break;
case 7:
v5 = input_port_3_r(0LL);
result = (unsigned int)input_port_2_r(0LL) | v5 & 0x80;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
__int64 result; // rax
char v2; // bl
char v3; // bl
char v4; // bl
char v5; // bl

switch ( a1 & 7 )
{
case 0:
result = (unsigned __int8)((unsigned __int8)input_port_3_r(0LL) << 7);
break;
case 1:
result = (unsigned __int8)((unsigned __int8)input_port_3_r(0LL) << 6) & 0x80;
break;
case 2:
v2 = input_port_3_r(0LL);
result = (unsigned int)input_port_1_r(0LL) | (32 * v2) & 0x80;
break;
case 3:
v3 = input_port_3_r(0LL);
result = (unsigned int)input_port_2_r(0LL) | (16 * v3) & 0x80;
break;
case 4:
result = (unsigned __int8)(8 * input_port_3_r(0LL)) & 0x80;
break;
case 5:
result = (unsigned __int8)(4 * input_port_3_r(0LL)) & 0x80;
break;
case 6:
v4 = input_port_3_r(0LL);
result = (unsigned int)input_port_1_r(0LL) | (2 * v4) & 0x80;
break;
case 7:
v5 = input_port_3_r(0LL);
result = (unsigned int)input_port_2_r(0LL) | v5 & 0x80;
break;
}
return result;
}

original_code:
static data_t canyon_switches_r(offs_t offset)
{
 switch (offset & 0x07)
 {
  case 0x00:
   return ((input_port_3_r(0) << 7) & 0x80);
  case 0x01:
   return ((input_port_3_r(0) << 6) & 0x80);
  case 0x02:
   return ((input_port_3_r(0) << 5) & 0x80) | input_port_1_r(0);
  case 0x03:
   return ((input_port_3_r(0) << 4) & 0x80) | input_port_2_r(0);
  case 0x04:
   return ((input_port_3_r(0) << 3) & 0x80);
  case 0x05:
   return ((input_port_3_r(0) << 2) & 0x80);
  case 0x06:
   return ((input_port_3_r(0) << 1) & 0x80) | input_port_1_r(0);
  case 0x07:
   return ((input_port_3_r(0) << 0) & 0x80) | input_port_2_r(0);
 }
 return 0xFF;
}

canonical_original_code:
static unsigned int canyon_switches_r(unsigned int offset)
{
 switch (offset & 0x07)
 {
  case 0x00:
   return ((input_port_3_r(0) << 7) & 0x80);
  case 0x01:
   return ((input_port_3_r(0) << 6) & 0x80);
  case 0x02:
   return ((input_port_3_r(0) << 5) & 0x80) | input_port_1_r(0);
  case 0x03:
   return ((input_port_3_r(0) << 4) & 0x80) | input_port_2_r(0);
  case 0x04:
   return ((input_port_3_r(0) << 3) & 0x80);
  case 0x05:
   return ((input_port_3_r(0) << 2) & 0x80);
  case 0x06:
   return ((input_port_3_r(0) << 1) & 0x80) | input_port_1_r(0);
  case 0x07:
   return ((input_port_3_r(0) << 0) & 0x80) | input_port_2_r(0);
 }
 return 0xFF;
}


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

switch ( a1 )
{
case 0:
ddragon3_fg_scrollx = a2;
break;
case 2:
ddragon3_fg_scrolly = a2;
break;
case 4:
ddragon3_bg_scrollx = a2;
break;
case 6:
ddragon3_bg_scrolly = a2;
break;
case 12:
result = (unsigned __int16)(ddragon3_bg_tilebase & HIWORD(a2));
ddragon3_bg_tilebase = (result | a2) & 0x1FF;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
ddragon3_fg_scrollx = a2;
break;
case 2:
ddragon3_fg_scrolly = a2;
break;
case 4:
ddragon3_bg_scrollx = a2;
break;
case 6:
ddragon3_bg_scrolly = a2;
break;
case 12:
result = (unsigned __int16)(ddragon3_bg_tilebase & HIWORD(a2));
ddragon3_bg_tilebase = (result | a2) & 0x1FF;
break;
default:
return result;
}
return result;
}

original_code:
void ddragon3_scroll_w(offs_t offset,data_t data){
 switch (offset) {
  case 0x0:
  ddragon3_fg_scrollx = data;
  return;
  case 0x2:
  ddragon3_fg_scrolly = data;
  return;
  case 0x4:
  ddragon3_bg_scrollx = data;
  return;
  case 0x6:
  ddragon3_bg_scrolly = data;
  return;
  case 0xc:
  ddragon3_bg_tilebase = (((ddragon3_bg_tilebase) & ((data) >> 16)) | ((data) & 0xffff))&0x1ff;
  return;
  default:
  break;
 }
}

canonical_original_code:
void ddragon3_scroll_w(unsigned int offset, unsigned int data){
 switch (offset) {
  case 0x0:
  ddragon3_fg_scrollx = data;
  return;
  case 0x2:
  ddragon3_fg_scrolly = data;
  return;
  case 0x4:
  ddragon3_bg_scrollx = data;
  return;
  case 0x6:
  ddragon3_bg_scrolly = data;
  return;
  case 0xc:
  ddragon3_bg_tilebase = (((ddragon3_bg_tilebase) & ((data) >> 16)) | ((data) & 0xffff))&0x1ff;
  return;
  default:
  break;
 }
}


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

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

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

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


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

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

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

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


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

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

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

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

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

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

variable_types: oldword int

variable_types: newword int


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

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

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

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

original_code:
void ddragon3_fg_videoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&ddragon3_fg_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if( oldword != newword )
 {
  (*(UINT16 *)(&ddragon3_fg_videoram[offset]) = (newword));
  offset = offset/4;
  tilemap_mark_tile_dirty(foreground,offset);
 }
}

canonical_original_code:
void ddragon3_fg_videoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&ddragon3_fg_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if( oldword != newword )
 {
  (*(unsigned short *)(&ddragon3_fg_videoram[offset]) = (newword));
  offset = offset/4;
  tilemap_mark_tile_dirty(foreground,offset);
 }
}


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

ddragon3_bg_tilebase = 0;
old_ddragon3_bg_tilebase = -1;
background = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v2);
foreground = v0;
if ( !background || !v0 )
return 1LL;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

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

ddragon3_bg_tilebase = 0;
old_ddragon3_bg_tilebase = -1;
background = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v2);
foreground = v0;
if ( !background || !v0 )
return 1LL;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

original_code:
int ddragon3_vh_start(void){
 ddragon3_bg_tilebase = 0;
 old_ddragon3_bg_tilebase = -1;
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 if (!background || !foreground)
  return 1;
 foreground->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int ddragon3_vh_start(){
 ddragon3_bg_tilebase = 0;
 old_ddragon3_bg_tilebase = -1;
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00, 16,16,32,32);
 foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,32,32);
 if (!background || !foreground)
  return 1;
 foreground->transparent_pen = 0;
 return 0;
}


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

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

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

variable_types: irq int


decompiled_code:
__int64 __fastcall oki_bankswitch_w(__int64 a1, char a2)
{
return OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (unsigned __int8)(a2 & 1) << 18);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char a2)
{
return OKIM6295_set_bank_base(0LL, 0xFFFFFFFFLL, (unsigned __int8)(a2 & 1) << 18);
}

original_code:
static void oki_bankswitch_w(offs_t offset,data_t data)
{
 OKIM6295_set_bank_base(0, -1, (data & 1) * 0x40000);
}

canonical_original_code:
static void oki_bankswitch_w(unsigned int offset, unsigned int data)
{
 OKIM6295_set_bank_base(0, -1, (data & 1) * 0x40000);
}


decompiled_code:
__int64 ddragon3_cpu_interrupt()
{
return (unsigned int)((unsigned int)cpu_getiloops() == 0) + 5;
}

canonical_decompiled_code:
__int64 func14()
{
return (unsigned int)((unsigned int)cpu_getiloops() == 0) + 5;
}

original_code:
static int ddragon3_cpu_interrupt(void) {
 if( cpu_getiloops() == 0 ){
  return 6;
 }
 else {
  return 5;
 }
 return 0;
}

canonical_original_code:
static int ddragon3_cpu_interrupt() {
 if( cpu_getiloops() == 0 ){
  return 6;
 }
 else {
  return 5;
 }
 return 0;
}


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_E92);
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_E92);
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)
{
__int64 result; // rax

if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
result = 0xFFFFLL;
if ( a1 == 6 )
result = readinputport(3LL);
}
else if ( a1 )
{
if ( a1 == 2 )
result = readinputport(1LL);
else
result = 0xFFFFLL;
}
else
{
result = readinputport(0LL);
}
return result;
}

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

if ( a1 == 4 )
return readinputport(2LL);
if ( a1 > 4 )
{
result = 0xFFFFLL;
if ( a1 == 6 )
result = readinputport(3LL);
}
else if ( a1 )
{
if ( a1 == 2 )
result = readinputport(1LL);
else
result = 0xFFFFLL;
}
else
{
result = readinputport(0LL);
}
return result;
}

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


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 )
{
result = 0xFFFFLL;
if ( a1 == 6 )
result = (4 * (unsigned __int16)readinputport(5LL)) & 0x300;
}
else if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
result = v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
else
{
result = 0xFFFFLL;
}
}
else
{
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 )
{
result = 0xFFFFLL;
if ( a1 == 6 )
result = (4 * (unsigned __int16)readinputport(5LL)) & 0x300;
}
else if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
result = v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
else
{
result = 0xFFFFLL;
}
}
else
{
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 )
{
result = 0xFFFFLL;
if ( a1 == 6 )
result = (unsigned __int8)(readinputport(5LL) & 0xC0) << 8;
}
else if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
result = v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
else
{
result = 0xFFFFLL;
}
}
else
{
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 )
{
result = 0xFFFFLL;
if ( a1 == 6 )
result = (unsigned __int8)(readinputport(5LL) & 0xC0) << 8;
}
else if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
result = v1 + ((unsigned __int8)(readinputport(4LL) & 0x3F) << 8);
}
else
{
result = 0xFFFFLL;
}
}
else
{
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
int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

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

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

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

original_code:
static void get_bg_tile_info(int tile_index)
{
 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; } *


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

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

result = a2 & 1;
objon = a2 & 1;
bgon = a2 & 2;
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;
}


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

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

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


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, unsigned __int8 a2)
{
__int64 result; // rax

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

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = a2 & 0x80;
if ( (_DWORD)result != 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 v1; // rdi
__int64 v2; // r8
int v3; // er10
int *v4; // rsi
char *v5; // rax
int v6; // edx
int v7; // eax
int v8; // er11
__int64 v9; // r9
int v10; // er11
int v11; // er8
int v12; // er11
int v13; // ecx
int v14; // edx
__int64 v15; // rbx
int v16; // er8
int v17; // er10
int *v18; // r9
unsigned int i; // eax
int v20; // ecx
__int64 v21; // rcx
int v22; // er10
int *v23; // rax
__int64 v24; // rax
__int64 v25; // rdi
__int64 v26; // r9
__int64 v27; // rcx
int v28; // er8
int v29; // er10
int *v30; // r9
unsigned int j; // eax
int v32; // ecx
__int64 v33; // rdx
__int64 v34; // rdi
int *v35; // rax
__int64 v36; // rax
__int64 v37; // r11
__int64 v38; // r10
__int64 v39; // r8
unsigned int k; // eax
int v41; // ecx
__int64 v42; // rcx
char v43; // al
__int64 v44; // r12
unsigned int l; // er15
int v46; // ebx
__int64 v47; // rbp
int v48; // eax
int v49; // ebp
__int64 v50; // rbx
__int64 v51; // rdx
__int64 v52; // rdi
void *result; // rax
int v54; // ebx
__int64 v55; // rbp
int v56; // esi
int v57; // ecx
int v59; // [rsp+Ch] [rbp-14Ch]
int v60[16]; // [rsp+10h] [rbp-148h] BYREF
__int64 v61; // [rsp+50h] [rbp-108h] BYREF
char v62; // [rsp+90h] [rbp-C8h] BYREF
__int64 v63; // [rsp+110h] [rbp-48h] BYREF
int v64; // [rsp+118h] [rbp-40h] BYREF
int v65[15]; // [rsp+11Ch] [rbp-3Ch] BYREF

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

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
__int64 v1; // rdi
__int64 v2; // r8
int v3; // er10
int *v4; // rsi
char *v5; // rax
int v6; // edx
int v7; // eax
int v8; // er11
__int64 v9; // r9
int v10; // er11
int v11; // er8
int v12; // er11
int v13; // ecx
int v14; // edx
__int64 v15; // rbx
int v16; // er8
int v17; // er10
int *v18; // r9
unsigned int i; // eax
int v20; // ecx
__int64 v21; // rcx
int v22; // er10
int *v23; // rax
__int64 v24; // rax
__int64 v25; // rdi
__int64 v26; // r9
__int64 v27; // rcx
int v28; // er8
int v29; // er10
int *v30; // r9
unsigned int j; // eax
int v32; // ecx
__int64 v33; // rdx
__int64 v34; // rdi
int *v35; // rax
__int64 v36; // rax
__int64 v37; // r11
__int64 v38; // r10
__int64 v39; // r8
unsigned int k; // eax
int v41; // ecx
__int64 v42; // rcx
char v43; // al
__int64 v44; // r12
unsigned int l; // er15
int v46; // ebx
__int64 v47; // rbp
int v48; // eax
int v49; // ebp
__int64 v50; // rbx
__int64 v51; // rdx
__int64 v52; // rdi
void *result; // rax
int v54; // ebx
__int64 v55; // rbp
int v56; // esi
int v57; // ecx
int v59; // [rsp+Ch] [rbp-14Ch]
int v60[16]; // [rsp+10h] [rbp-148h] BYREF
__int64 v61; // [rsp+50h] [rbp-108h] BYREF
char v62; // [rsp+90h] [rbp-C8h] BYREF
__int64 v63; // [rsp+110h] [rbp-48h] BYREF
int v64; // [rsp+118h] [rbp-40h] BYREF
int v65[15]; // [rsp+11Ch] [rbp-3Ch] BYREF

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

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall turtship_ports_r(char a1)
{
unsigned int v1; // ebp
unsigned int i; // ebx

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

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
unsigned int v1; // ebp
unsigned int i; // ebx

v1 = 0;
for ( i = 0; i != 8; ++i )
v1 |= (((int)readinputport(i) >> a1) & 1) << i;
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


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; // er12
unsigned int v4; // ebp
unsigned int v5; // er13
__int64 result; // rax
int v7; // ebx

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

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

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(unsigned __int8 *)(paletteram + (a1 & 0xFFE));
v3 = *(_BYTE *)(paletteram + (a1 & 0xFFE)) & 0xF | (16 * (*(_BYTE *)(paletteram + (a1 & 0xFFE)) & 0xF));
v4 = v2 & 0xF0 | (v2 >> 4);
v5 = ((v2 | (*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8)) >> 8) & 0xF | (16
* (((v2 | (*(unsigned __int8 *)(paletteram + (a1 | 1)) << 8)) >> 8) & 0xF));
result = palette_change_color(a1 >> 1, v3, v4, v5);
if ( a1 <= 0x3FF )
{
v7 = ((unsigned __int8)(a1 & 0x1F) >> 1) | a1 & 0xFFE0;
palette_change_color(v7 | 0x800u, v3, v4, v5);
result = palette_change_color(v7 | 0x810u, v3, v4, v5);
}
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: 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; // rdx
__int64 v3; // [rsp+0h] [rbp-18h]
__int64 v4; // [rsp+0h] [rbp-18h]

bg_layer = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v3) = 32;
fg_layer = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 32LL, v3);
LODWORD(v4) = 32;
v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v4);
tx_layer = v0;
v1 = bg_layer;
*(_DWORD *)(bg_layer + 136) = 0xFFFF;
*(_DWORD *)(v1 + 140) = -65536;
*(_DWORD *)(fg_layer + 132) = 15;
*(_DWORD *)(v0 + 132) = 15;
return 0LL;
}

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

bg_layer = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 32LL, 32LL);
LODWORD(v3) = 32;
fg_layer = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 16LL, 16LL, 32LL, v3);
LODWORD(v4) = 32;
v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v4);
tx_layer = v0;
v1 = bg_layer;
*(_DWORD *)(bg_layer + 136) = 0xFFFF;
*(_DWORD *)(v1 + 140) = -65536;
*(_DWORD *)(fg_layer + 132) = 15;
*(_DWORD *)(v0 + 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)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int16 a2)
{
__int64 result; // rax

back_bankbase = (a2 & 1) << 12;
fore_bankbase = (a2 << 8) & 0x1000;
if ( old_back_2 != back_bankbase )
tilemap_mark_all_tiles_dirty(bg_layer);
if ( fore_bankbase != old_fore_1 )
tilemap_mark_all_tiles_dirty(fg_layer);
old_back_2 = back_bankbase;
result = (unsigned int)fore_bankbase;
old_fore_1 = fore_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;
}