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

if ( a1 > 0xFE )
{
if ( a1 <= 0x1FE )
result = tms5220_data_w(0LL, (unsigned __int8)speech_write_buffer_0);
}
else
{
speech_write_buffer_0 = a2;
}
return result;
}

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

if ( a1 > 0xFE )
{
if ( a1 <= 0x1FE )
result = tms5220_data_w(0LL, (unsigned __int8)speech_write_buffer_0);
}
else
{
speech_write_buffer_0 = a2;
}
return result;
}

original_code:
void jedi_speech_w(offs_t offset,data_t data)
{
    static unsigned char speech_write_buffer;
    if(offset<0xff)
    {
        speech_write_buffer = data;
    }
    else if (offset<0x1ff)
    {
        tms5220_data_w(0,speech_write_buffer);
    }
}

canonical_original_code:
void jedi_speech_w(unsigned int offset, unsigned int data)
{
    static unsigned char speech_write_buffer;
    if(offset<0xff)
    {
        speech_write_buffer = data;
    }
    else if (offset<0x1ff)
    {
        tms5220_data_w(0,speech_write_buffer);
    }
}


decompiled_code:
__int64 jedi_speech_ready_r()
{
return (unsigned __int8)((unsigned int)tms5220_ready_r() == 0) << 7;
}

canonical_decompiled_code:
__int64 func20()
{
return (unsigned __int8)((unsigned int)tms5220_ready_r() == 0) << 7;
}

original_code:
data_t jedi_speech_ready_r(offs_t offset)
{
    return (!tms5220_ready_r())<<7;
}

canonical_original_code:
unsigned int jedi_speech_ready_r(unsigned int offset)
{
    return (!tms5220_ready_r())<<7;
}

variable_types:
offset
unsigned int

return_type: unsigned int


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

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

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

variable_types:
file
void *

return_type: void


decompiled_code:
char *__fastcall get_resource_path(const char *a1)
{
sprintf(resource_path_1, "%s/%s", IMAMEBASEPATH, a1);
return resource_path_1;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
sprintf(resource_path_1, "%s/%s", IMAMEBASEPATH, a1);
return resource_path_1;
}

original_code:
const char* get_resource_path(char* file)
{
  static char resource_path[1024];
  sprintf(resource_path, "%s/%s", IMAMEBASEPATH, file);
  return resource_path;
}

canonical_original_code:
char *get_resource_path(char *file)
{
  static char resource_path[1024];
  sprintf(resource_path, "%s/%s", IMAMEBASEPATH, file);
  return resource_path;
}

variable_types:
file
char *

return_type: char *


decompiled_code:
char *__fastcall get_documents_path(const char *a1)
{
sprintf(documents_path_0, "%s/%s", IMAMEBASEPATH, a1);
return documents_path_0;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
sprintf(documents_path_0, "%s/%s", IMAMEBASEPATH, a1);
return documents_path_0;
}

original_code:
const char* get_documents_path(char* file)
{
    static char documents_path[1024];
    sprintf(documents_path, "%s/%s", IMAMEBASEPATH, file);
    return documents_path;
}

canonical_original_code:
char *get_documents_path(char *file)
{
    static char documents_path[1024];
    sprintf(documents_path, "%s/%s", IMAMEBASEPATH, file);
    return documents_path;
}


original_code:
void warlord_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i, j;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int r,g,b;
  r = ((*color_prom >> 2) & 0x01) * 0xff;
  g = ((*color_prom >> 1) & 0x01) * 0xff;
  b = ((*color_prom >> 0) & 0x01) * 0xff;
  if (i >= Machine->drv->total_colors / 2)
  {
   int grey;
   grey = ((r != 0) * 0x4d) + ((g != 0) * 0x96) + ((b != 0) * 0x1c);
   r = g = b = grey;
  }
  *(palette++) = r;
  *(palette++) = g;
  *(palette++) = b;
  color_prom++;
 }
 for (i = 0; i < 8; i++)
 {
  for (j = 0; j < 4; j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i*4+j]) = i*16+j;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i*4+j]) = i*16+j*4;
  }
 }
}

canonical_original_code:
void warlord_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i; int j;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int r; int g; int b;
  r = ((*color_prom >> 2) & 0x01) * 0xff;
  g = ((*color_prom >> 1) & 0x01) * 0xff;
  b = ((*color_prom >> 0) & 0x01) * 0xff;
  if (i >= Machine->drv->total_colors / 2)
  {
   int grey;
   grey = ((r != 0) * 0x4d) + ((g != 0) * 0x96) + ((b != 0) * 0x1c);
   r = g = b = grey;
  }
  *(palette++) = r;
  *(palette++) = g;
  *(palette++) = b;
  color_prom++;
 }
 for (i = 0; i < 8; i++)
 {
  for (j = 0; j < 4; j++)
  {
   (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i*4+j]) = i*16+j;
   (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i*4+j]) = i*16+j*4;
  }
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

variable_types: j int

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: grey int


decompiled_code:
__int64 __fastcall warlord_vh_screenrefresh(__int64 a1)
{
__int64 v1; // r14
int v2; // er12
int v3; // ebx
__int64 v4; // r15
_BOOL8 v5; // r8
int v6; // esi
char v7; // cl
__int64 v8; // rbp
_BOOL8 v9; // r8
__int64 result; // rax
int v11; // edi
char v12; // dl
int v13; // er11
char v14; // cl
int v15; // [rsp+Ch] [rbp-4Ch]

v1 = a1;
if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v15 = input_port_0_r(0LL) & 0x80;
v2 = 4 * (v15 != 0);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v6 = v3 & 0x1F;
v7 = *(_BYTE *)(videoram + v4) & 0x40;
if ( v15 )
{
v6 = 31 - v6;
v5 = v7 != 0;
}
else
{
v5 = v7 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v4) & 0x3F,
(v6 >> 4) | v2 | (v3 >> 8) & 2u,
v5);
}
--v3;
--v4;
}
while ( v3 != -1 );
v1 = a1;
}
v8 = 0LL;
copybitmap(v1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v11 = *(unsigned __int8 *)(spriteram + v8 + 32);
v12 = *(_BYTE *)(spriteram + v8);
v13 = 248 - *(unsigned __int8 *)(spriteram + v8 + 16);
v14 = v12 & 0x40;
if ( v15 )
{
v11 = 248 - v11;
v9 = v14 != 0;
}
else
{
v9 = v14 == 0;
}
++v8;
result = drawgfx(v1, *(_QWORD *)(Machine + 520LL), v12 & 0x3F, (v11 >> 7) & 1 | v2 | (v13 >> 6) & 2u, v9);
}
while ( v8 != 16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r14
int v2; // er12
int v3; // ebx
__int64 v4; // r15
_BOOL8 v5; // r8
int v6; // esi
char v7; // cl
__int64 v8; // rbp
_BOOL8 v9; // r8
__int64 result; // rax
int v11; // edi
char v12; // dl
int v13; // er11
char v14; // cl
int v15; // [rsp+Ch] [rbp-4Ch]

v1 = a1;
if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v15 = input_port_0_r(0LL) & 0x80;
v2 = 4 * (v15 != 0);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v6 = v3 & 0x1F;
v7 = *(_BYTE *)(videoram + v4) & 0x40;
if ( v15 )
{
v6 = 31 - v6;
v5 = v7 != 0;
}
else
{
v5 = v7 == 0;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(_BYTE *)(videoram + v4) & 0x3F,
(v6 >> 4) | v2 | (v3 >> 8) & 2u,
v5);
}
--v3;
--v4;
}
while ( v3 != -1 );
v1 = a1;
}
v8 = 0LL;
copybitmap(v1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v11 = *(unsigned __int8 *)(spriteram + v8 + 32);
v12 = *(_BYTE *)(spriteram + v8);
v13 = 248 - *(unsigned __int8 *)(spriteram + v8 + 16);
v14 = v12 & 0x40;
if ( v15 )
{
v11 = 248 - v11;
v9 = v14 != 0;
}
else
{
v9 = v14 == 0;
}
++v8;
result = drawgfx(v1, *(_QWORD *)(Machine + 520LL), v12 & 0x3F, (v11 >> 7) & 1 | v2 | (v13 >> 6) & 2u, v9);
}
while ( v8 != 16 );
return result;
}

original_code:
void warlord_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs, upright_mode, palette;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 upright_mode = input_port_0_r(0) & 0x80;
 palette = ( upright_mode ? 4 : 0);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,color,flipx,flipy;
   dirtybuffer[offs] = 0;
   sy = (offs / 32);
   sx = (offs % 32);
   flipx = !(videoram [offs] & 0x40);
   flipy = videoram [offs] & 0x80;
   if (upright_mode)
   {
    sx = 31 - sx;
    flipx = !flipx;
   }
   color = ((sy & 0x10) >> 3) | ((sx & 0x10) >> 4) | palette;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram [offs] & 0x3f,
     color,
     flipx, flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < 0x10;offs++)
 {
  int sx, sy, flipx, flipy, spritenum, color;
  sx = spriteram [offs + 0x20];
        sy = 248 - spriteram[offs + 0x10];
  flipx = !(spriteram [offs] & 0x40);
  flipy = spriteram [offs] & 0x80;
  if (upright_mode)
  {
   sx = 248 - sx;
   flipx = !flipx;
  }
  spritenum = (spriteram[offs] & 0x3f);
  color = ((sy & 0x80) >> 6) | ((sx & 0x80) >> 7) | palette;
  drawgfx(bitmap,Machine->gfx[1],
    spritenum, color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void warlord_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int upright_mode; int palette;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 upright_mode = input_port_0_r(0) & 0x80;
 palette = ( upright_mode ? 4 : 0);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int color; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sy = (offs / 32);
   sx = (offs % 32);
   flipx = !(videoram [offs] & 0x40);
   flipy = videoram [offs] & 0x80;
   if (upright_mode)
   {
    sx = 31 - sx;
    flipx = !flipx;
   }
   color = ((sy & 0x10) >> 3) | ((sx & 0x10) >> 4) | palette;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram [offs] & 0x3f,
     color,
     flipx, flipy,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0;offs < 0x10;offs++)
 {
  int sx; int sy; int flipx; int flipy; int spritenum; int color;
  sx = spriteram [offs + 0x20];
        sy = 248 - spriteram[offs + 0x10];
  flipx = !(spriteram [offs] & 0x40);
  flipy = spriteram [offs] & 0x80;
  if (upright_mode)
  {
   sx = 248 - sx;
   flipx = !flipx;
  }
  spritenum = (spriteram[offs] & 0x3f);
  color = ((sy & 0x80) >> 6) | ((sx & 0x80) >> 7) | palette;
  drawgfx(bitmap,Machine->gfx[1],
    spritenum, color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: palette int

variable_types: sx int

variable_types: sy int

variable_types: color int

variable_types: flipx int

variable_types: flipy int

variable_types: spritenum int


decompiled_code:
__int64 __fastcall warlord_led_w(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return osd_led_w(a1, (unsigned int)~a2 >> 7);
}

original_code:
static void warlord_led_w(offs_t offset,data_t data)
{
 osd_led_w(offset,~data >> 7);
}

canonical_original_code:
static void warlord_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(offset,~data >> 7);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 llander_sh_start()
{
__int64 result; // rax
__int64 v1; // rdx
float v2; // xmm2_4
__int64 v3; // rdi
__int64 i; // rdx

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v1 = *(_QWORD *)(Machine + 824LL);
volume = 0;
v2 = *(float *)(v1 + 640);
tone_3khz = 0;
tone_6khz = 0;
llander_explosion = 0;
sample_pos = 0;
lfsr_index = 0;
buffer_len = (int)(float)((float)(int)result / v2);
emulation_rate = (int)(float)((float)buffer_len * v2);
multiplier = 0xBB8000000LL * (768000LL / emulation_rate) / emulation_rate + ((768000LL / emulation_rate) << 16);
lfsr_buffer = (__int64)malloc(0x20000uLL);
v3 = lfsr_buffer;
if ( !lfsr_buffer )
goto LABEL_8;
for ( i = 0LL; i != 0x10000; ++i )
*(_WORD *)(v3 + 2 * i) = (2 * i) | ((((unsigned __int8)((int)i >> 6) ^ (unsigned __int8)((int)i >> 14)) & 1) == 0);
channel = mixer_allocate_channel(25LL);
sample_buffer = (__int64)calloc(2LL * buffer_len, 1uLL);
if ( sample_buffer )
result = 0LL;
else
LABEL_8:
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rdx
float v2; // xmm2_4
__int64 v3; // rdi
__int64 i; // rdx

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v1 = *(_QWORD *)(Machine + 824LL);
volume = 0;
v2 = *(float *)(v1 + 640);
tone_3khz = 0;
tone_6khz = 0;
llander_explosion = 0;
sample_pos = 0;
lfsr_index = 0;
buffer_len = (int)(float)((float)(int)result / v2);
emulation_rate = (int)(float)((float)buffer_len * v2);
multiplier = 0xBB8000000LL * (768000LL / emulation_rate) / emulation_rate + ((768000LL / emulation_rate) << 16);
lfsr_buffer = (__int64)malloc(0x20000uLL);
v3 = lfsr_buffer;
if ( !lfsr_buffer )
goto LABEL_8;
for ( i = 0LL; i != 0x10000; ++i )
*(_WORD *)(v3 + 2 * i) = (2 * i) | ((((unsigned __int8)((int)i >> 6) ^ (unsigned __int8)((int)i >> 14)) & 1) == 0);
channel = mixer_allocate_channel(25LL);
sample_buffer = (__int64)calloc(2LL * buffer_len, 1uLL);
if ( sample_buffer )
result = 0LL;
else
LABEL_8:
result = 1LL;
}
return result;
}

original_code:
int llander_sh_start(const struct MachineSound *msound)
{
 int loop,lfsrtmp,nor1,nor2,bit14,bit6;
 long fraction,remainder;
        if (Machine->sample_rate == 0) return 0;
 volume=0;
 tone_3khz=0;
 tone_6khz=0;
 llander_explosion=0;
 buffer_len = Machine->sample_rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 sample_pos = 0;
 multiplier=768000/(long)emulation_rate;
 remainder=multiplier*768000;
 fraction=remainder<<16;
 fraction/=emulation_rate;
 multiplier=(multiplier<<16)+fraction;
 lfsr_index=0;
 if ((lfsr_buffer = (unsigned short*)malloc(65536*2)) == 0) return 1;
 for(loop=0;loop<65536;loop++)
 {
  lfsrtmp=(short)loop<<1;
  bit14=(loop&0x04000)?1:0;
  bit6=(loop&0x0040)?1:0;
  nor1=(!( bit14 && bit6 ) )?0:1;
  nor2=(!(!bit14 && !bit6 ) )?0:1;
  lfsrtmp|=nor1|nor2;
  lfsr_buffer[loop]=lfsrtmp;
 }
 channel = mixer_allocate_channel(25);
 if ((sample_buffer = (INT16*)malloc(sizeof(INT16)*buffer_len)) == 0) return 1;
 memset(sample_buffer,0,sizeof(INT16)*buffer_len);
 return 0;
}

canonical_original_code:
int llander_sh_start(struct MachineSound *msound)
{
 int loop; int lfsrtmp; int nor1; int nor2; int bit14; int bit6;
 long fraction; long remainder;
        if (Machine->sample_rate == 0) return 0;
 volume=0;
 tone_3khz=0;
 tone_6khz=0;
 llander_explosion=0;
 buffer_len = Machine->sample_rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 sample_pos = 0;
 multiplier=768000/(long)emulation_rate;
 remainder=multiplier*768000;
 fraction=remainder<<16;
 fraction/=emulation_rate;
 multiplier=(multiplier<<16)+fraction;
 lfsr_index=0;
 if ((lfsr_buffer = (unsigned short *)malloc(65536*2)) == 0) return 1;
 for(loop=0;loop<65536;loop++)
 {
  lfsrtmp=(short)loop<<1;
  bit14=(loop&0x04000)?1:0;
  bit6=(loop&0x0040)?1:0;
  nor1=(!( bit14 && bit6 ) )?0:1;
  nor2=(!(!bit14 && !bit6 ) )?0:1;
  lfsrtmp|=nor1|nor2;
  lfsr_buffer[loop]=lfsrtmp;
 }
 channel = mixer_allocate_channel(25);
 if ((sample_buffer = (short *)malloc(sizeof(INT16)*buffer_len)) == 0) return 1;
 memset(sample_buffer,0,sizeof(INT16)*buffer_len);
 return 0;
}

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

variable_types: loop int

variable_types: lfsrtmp int

variable_types: fraction long

variable_types: remainder long

return_type: int


decompiled_code:
void llander_sh_stop()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void llander_sh_stop(void)
{
}

canonical_original_code:
void llander_sh_stop()
{
}


original_code:
void llander_process(INT16 *buffer,int start, int n)
{
 static int sampnum=0;
 static long noisetarg=0,noisecurrent=0;
 static long lastoversampnum=0;
 int loop,sample;
 long oversampnum,loop2;
 for(loop=0;loop<n;loop++)
 {
  oversampnum=(long)(sampnum*multiplier)>>16;
  if(lastoversampnum>>6!=oversampnum>>6)
  {
   lfsr_index=lfsr_buffer[lfsr_index];
   noisetarg=(lfsr_buffer[lfsr_index]&0x4000)?llander_volume[volume]:0x00;
   noisetarg<<=16;
  }
  for(loop2=lastoversampnum;loop2<oversampnum;loop2++)
  {
   noisecurrent+=(noisetarg-noisecurrent)>>7;
  }
  sample=(int)(noisecurrent>>16);
  sample<<=1;
  if(tone_3khz)
  {
   sample+=sinetable[(oversampnum>>2)&0x3f];
  }
  if(tone_6khz)
  {
   sample+=sinetable[(oversampnum>>1)&0x3f];
  }
  if(llander_explosion)
  {
   sample+=(int)(noisecurrent>>(16-2));
  }
  buffer[start+loop] = ((sample<<5)-0x8000);
  sampnum++;
  lastoversampnum=oversampnum;
 }
}

canonical_original_code:
void llander_process(short *buffer, int start, int n)
{
 static int sampnum = 0;
 static long noisetarg = 0; static long noisecurrent = 0;
 static long lastoversampnum = 0;
 int loop; int sample;
 long oversampnum; long loop2;
 for(loop=0;loop<n;loop++)
 {
  oversampnum=(long)(sampnum*multiplier)>>16;
  if(lastoversampnum>>6!=oversampnum>>6)
  {
   lfsr_index=lfsr_buffer[lfsr_index];
   noisetarg=(lfsr_buffer[lfsr_index]&0x4000)?llander_volume[volume]:0x00;
   noisetarg<<=16;
  }
  for(loop2=lastoversampnum;loop2<oversampnum;loop2++)
  {
   noisecurrent+=(noisetarg-noisecurrent)>>7;
  }
  sample=(int)(noisecurrent>>16);
  sample<<=1;
  if(tone_3khz)
  {
   sample+=sinetable[(oversampnum>>2)&0x3f];
  }
  if(tone_6khz)
  {
   sample+=sinetable[(oversampnum>>1)&0x3f];
  }
  if(llander_explosion)
  {
   sample+=(int)(noisecurrent>>(16-2));
  }
  buffer[start+loop] = ((sample<<5)-0x8000);
  sampnum++;
  lastoversampnum=oversampnum;
 }
}

variable_types:
buffer
short *

variable_types: start int

variable_types: n int

variable_types: sampnum int

variable_types: noisetarg long

variable_types: noisecurrent long

variable_types: lastoversampnum long

variable_types: sample int

variable_types: oversampnum long


decompiled_code:
void llander_sh_update_partial()
{
int v0; // eax
int v1; // ebx

if ( *(_DWORD *)(Machine + 836LL) )
{
v0 = sound_scalebufferpos((unsigned int)buffer_len);
v1 = v0;
if ( v0 - sample_pos > 9 )
{
llander_process(sample_buffer, sample_pos, v0 - sample_pos);
sample_pos = v1;
}
}
}

canonical_decompiled_code:
void func3()
{
int v0; // eax
int v1; // ebx

if ( *(_DWORD *)(Machine + 836LL) )
{
v0 = sound_scalebufferpos((unsigned int)buffer_len);
v1 = v0;
if ( v0 - sample_pos > 9 )
{
func2(sample_buffer, sample_pos, v0 - sample_pos);
sample_pos = v1;
}
}
}

original_code:
void llander_sh_update_partial(void)
{
 int newpos;
 if (Machine->sample_rate == 0) return;
 newpos = sound_scalebufferpos(buffer_len);
 if(newpos-sample_pos<10) return;
 llander_process (sample_buffer, sample_pos, newpos - sample_pos);
 sample_pos = newpos;
}

canonical_original_code:
void llander_sh_update_partial()
{
 int newpos;
 if (Machine->sample_rate == 0) return;
 newpos = sound_scalebufferpos(buffer_len);
 if(newpos-sample_pos<10) return;
 llander_process (sample_buffer, sample_pos, newpos - sample_pos);
 sample_pos = newpos;
}

variable_types: newpos int


decompiled_code:
__int64 llander_sh_update()
{
__int64 result; // rax
int v1; // edx

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v1 = buffer_len;
if ( sample_pos < buffer_len )
{
llander_process(sample_buffer, sample_pos, buffer_len - sample_pos);
v1 = buffer_len;
}
sample_pos = 0;
result = mixer_play_streamed_sample_16(
(unsigned int)channel,
sample_buffer,
(unsigned int)(2 * v1),
(unsigned int)emulation_rate);
}
return result;
}

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

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v1 = buffer_len;
if ( sample_pos < buffer_len )
{
func2(sample_buffer, sample_pos, buffer_len - sample_pos);
v1 = buffer_len;
}
sample_pos = 0;
result = mixer_play_streamed_sample_16(
(unsigned int)channel,
sample_buffer,
(unsigned int)(2 * v1),
(unsigned int)emulation_rate);
}
return result;
}

original_code:
void llander_sh_update(void)
{
 if (Machine->sample_rate == 0) return;
 if (sample_pos < buffer_len)
  llander_process (sample_buffer, sample_pos, buffer_len - sample_pos);
 sample_pos = 0;
 mixer_play_streamed_sample_16(channel,sample_buffer,2*buffer_len,emulation_rate);
}

canonical_original_code:
void llander_sh_update()
{
 if (Machine->sample_rate == 0) return;
 if (sample_pos < buffer_len)
  llander_process (sample_buffer, sample_pos, buffer_len - sample_pos);
 sample_pos = 0;
 mixer_play_streamed_sample_16(channel,sample_buffer,2*buffer_len,emulation_rate);
}


decompiled_code:
void llander_snd_reset_w()
{
lfsr_index = 0;
}

canonical_decompiled_code:
void func5()
{
lfsr_index = 0;
}

original_code:
void llander_snd_reset_w(offs_t offset,data_t data)
{
        lfsr_index=0;
}

canonical_original_code:
void llander_snd_reset_w(unsigned int offset, unsigned int data)
{
        lfsr_index=0;
}

variable_types:
offset
unsigned int


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

llander_sh_update_partial();
volume = a2 & 7;
tone_3khz = a2 & 0x10;
result = a2 & 0x20;
llander_explosion = a2 & 8;
tone_6khz = a2 & 0x20;
return result;
}

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

func3();
volume = a2 & 7;
tone_3khz = a2 & 0x10;
result = a2 & 0x20;
llander_explosion = a2 & 8;
tone_6khz = a2 & 0x20;
return result;
}

original_code:
void llander_sounds_w(offs_t offset,data_t data)
{
 llander_sh_update_partial();
 volume = data & 0x07;
 tone_3khz = data & 0x10;
 tone_6khz = data & 0x20;
 llander_explosion = data & 0x08;
}

canonical_original_code:
void llander_sounds_w(unsigned int offset, unsigned int data)
{
 llander_sh_update_partial();
 volume = data & 0x07;
 tone_3khz = data & 0x10;
 tone_6khz = data & 0x20;
 llander_explosion = data & 0x08;
}

variable_types:
data
unsigned int


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

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

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

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


decompiled_code:
__int64 __fastcall decode_byte(unsigned __int8 a1, _BYTE *a2)
{
_BYTE *v2; // r9
char v3; // dl
unsigned int v4; // er8
char v5; // cl
int v6; // eax

v2 = a2 + 8;
v3 = (_BYTE)a2 + 7;
v4 = 0;
do
{
v5 = v3 - (_BYTE)a2;
v6 = ((int)a1 >> *a2++) & 1;
v4 |= v6 << v5;
}
while ( v2 != a2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, _BYTE *a2)
{
_BYTE *v2; // r9
char v3; // dl
unsigned int v4; // er8
char v5; // cl
int v6; // eax

v2 = a2 + 8;
v3 = (_BYTE)a2 + 7;
v4 = 0;
do
{
v5 = v3 - (_BYTE)a2;
v6 = ((int)a1 >> *a2++) & 1;
v4 |= v6 << v5;
}
while ( v2 != a2 );
return v4;
}

original_code:
static unsigned char decode_byte(unsigned char src, unsigned char *bitp)
{
 unsigned char ret, i;
 ret = 0;
 for (i=0; i<8; i++)
  ret |= (((src >> bitp[i]) & 1) << (7-i));
 return ret;
}

canonical_original_code:
static unsigned char decode_byte(unsigned char src, unsigned char *bitp)
{
 unsigned char ret; unsigned char i;
 ret = 0;
 for (i=0; i<8; i++)
  ret |= (((src >> bitp[i]) & 1) << (7-i));
 return ret;
}

variable_types:
src
unsigned char

variable_types:
bitp
unsigned char *

variable_types:
ret
unsigned char

variable_types:
i
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall decode_word(unsigned __int16 a1, _BYTE *a2)
{
_BYTE *v2; // r9
char v3; // dl
unsigned int v4; // er8
char v5; // cl
int v6; // eax

v2 = a2 + 16;
v3 = (_BYTE)a2 + 15;
v4 = 0;
do
{
v5 = v3 - (_BYTE)a2;
v6 = ((int)a1 >> *a2++) & 1;
v4 |= v6 << v5;
}
while ( v2 != a2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1, _BYTE *a2)
{
_BYTE *v2; // r9
char v3; // dl
unsigned int v4; // er8
char v5; // cl
int v6; // eax

v2 = a2 + 16;
v3 = (_BYTE)a2 + 15;
v4 = 0;
do
{
v5 = v3 - (_BYTE)a2;
v6 = ((int)a1 >> *a2++) & 1;
v4 |= v6 << v5;
}
while ( v2 != a2 );
return v4;
}

original_code:
static unsigned short decode_word(unsigned short src, unsigned char *bitp)
{
 unsigned short ret, i;
 ret=0;
 for (i=0; i<16; i++)
  ret |= (((src >> bitp[i]) & 1) << (15-i));
 return ret;
}

canonical_original_code:
static unsigned short decode_word(unsigned short src, unsigned char *bitp)
{
 unsigned short ret; unsigned short i;
 ret=0;
 for (i=0; i<16; i++)
  ret |= (((src >> bitp[i]) & 1) << (15-i));
 return ret;
}

variable_types:
src
unsigned short

variable_types:
ret
unsigned short

variable_types:
i
unsigned short

return_type: unsigned short


decompiled_code:
__int64 bjtwin_vh_start()
{
__int64 v0; // rax
void *v1; // r8

dirtybuffer = malloc(bjtwin_txvideoram_size >> 1);
v0 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v1 = dirtybuffer;
tmpbitmap = v0;
if ( dirtybuffer )
{
if ( v0 )
{
bjtwin_spriteram = bjtwin_workram + 0x8000LL;
return 0LL;
}
}
else
{
if ( !v0 )
return 1LL;
bitmap_free(v0);
v1 = dirtybuffer;
if ( !dirtybuffer )
return 1LL;
}
free(v1);
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
void *v1; // r8

dirtybuffer = malloc(bjtwin_txvideoram_size >> 1);
v0 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v1 = dirtybuffer;
tmpbitmap = v0;
if ( dirtybuffer )
{
if ( v0 )
{
bjtwin_spriteram = bjtwin_workram + 0x8000LL;
return 0LL;
}
}
else
{
if ( !v0 )
return 1LL;
bitmap_free(v0);
v1 = dirtybuffer;
if ( !dirtybuffer )
return 1LL;
}
free(v1);
return 1LL;
}

original_code:
int bjtwin_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(bjtwin_txvideoram_size/2);
 tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height);
 if (!dirtybuffer || !tmpbitmap)
 {
  if (tmpbitmap) bitmap_free(tmpbitmap);
  if (dirtybuffer) free(dirtybuffer);
  return 1;
 }
 bjtwin_spriteram = bjtwin_workram + 0x8000;
 return 0;
}

canonical_original_code:
int bjtwin_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(bjtwin_txvideoram_size/2);
 tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height);
 if (!dirtybuffer || !tmpbitmap)
 {
  if (tmpbitmap) bitmap_free(tmpbitmap);
  if (dirtybuffer) free(dirtybuffer);
  return 1;
 }
 bjtwin_spriteram = bjtwin_workram + 0x8000;
 return 0;
}


decompiled_code:
void bjtwin_vh_stop()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
}

canonical_decompiled_code:
void func4()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
dirtybuffer = 0LL;
tmpbitmap = 0LL;
}

original_code:
void bjtwin_vh_stop(void)
{
 bitmap_free(tmpbitmap);
 free(dirtybuffer);
 dirtybuffer = 0;
 tmpbitmap = 0;
}

canonical_original_code:
void bjtwin_vh_stop()
{
 bitmap_free(tmpbitmap);
 free(dirtybuffer);
 dirtybuffer = 0;
 tmpbitmap = 0;
}


decompiled_code:
__int64 __fastcall bjtwin_paletteram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // esi
int v4; // er8
int v5; // eax
int v6; // esi

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
v4 = (v3 >> 2) & 1;
v5 = (v3 >> 3) & 1 | (v3 >> 11) & 0x1E;
LODWORD(v2) = v3;
v6 = (v3 >> 3) & 0x1E | (v3 >> 1) & 1;
return palette_change_color(
a1 >> 1,
(v5 >> 2) | (unsigned int)(8 * v5),
(8 * (v4 | ((int)v2 >> 7) & 0x1E)) | (unsigned int)((v4 | ((int)v2 >> 7) & 0x1E) >> 2),
(v6 >> 2) | (unsigned int)(8 * v6));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // esi
int v4; // er8
int v5; // eax
int v6; // esi

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
v4 = (v3 >> 2) & 1;
v5 = (v3 >> 3) & 1 | (v3 >> 11) & 0x1E;
LODWORD(v2) = v3;
v6 = (v3 >> 3) & 0x1E | (v3 >> 1) & 1;
return palette_change_color(
a1 >> 1,
(v5 >> 2) | (unsigned int)(8 * v5),
(8 * (v4 | ((int)v2 >> 7) & 0x1E)) | (unsigned int)((v4 | ((int)v2 >> 7) & 0x1E) >> 2),
(v6 >> 2) | (unsigned int)(8 * v6));
}

original_code:
void bjtwin_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = ((newword >> 11) & 0x1e) | ((newword >> 3) & 0x01);
 g = ((newword >> 7) & 0x1e) | ((newword >> 2) & 0x01);
 b = ((newword >> 3) & 0x1e) | ((newword >> 1) & 0x01);
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void bjtwin_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = ((newword >> 11) & 0x1e) | ((newword >> 3) & 0x01);
 g = ((newword >> 7) & 0x1e) | ((newword >> 2) & 0x01);
 b = ((newword >> 3) & 0x1e) | ((newword >> 1) & 0x01);
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset / 2,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: oldword int

variable_types: newword int


decompiled_code:
void *__fastcall bjtwin_flipscreen_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 1;
if ( v2 != flipscreen )
{
flipscreen = v2;
result = memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 1;
if ( v2 != flipscreen )
{
flipscreen = v2;
result = memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
}
return result;
}

original_code:
void bjtwin_flipscreen_w(offs_t offset,data_t data)
{
 if ((data & 1) != flipscreen)
 {
  flipscreen = data & 1;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
}

canonical_original_code:
void bjtwin_flipscreen_w(unsigned int offset, unsigned int data)
{
 if ((data & 1) != flipscreen)
 {
  flipscreen = data & 1;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
}


decompiled_code:
__int64 __fastcall bjtwin_vh_screenrefresh(_QWORD *a1, _QWORD *a2)
{
void *v2; // r15
__int16 v3; // bx
void *v4; // rcx
int v5; // ebx
int v6; // edx
unsigned __int16 v7; // ax
__int64 i; // rax
__m128i *v9; // rdx
int v10; // edx
int v11; // ebp
_BYTE *v12; // rax
__int64 v13; // r15
int v14; // esi
int v15; // edi
int v16; // eax
__int64 v17; // rdi
__int64 v18; // rdx
__int64 v19; // rsi
__int64 result; // rax
__int64 v21; // rcx
__int64 v22; // r8
int v23; // ebp
__int16 v24; // bx
unsigned __int16 v25; // ax
int v26; // er13
__int16 v27; // r12
unsigned int v28; // er10
void *v29; // [rsp+8h] [rbp-60h]
__int64 j; // [rsp+18h] [rbp-50h]
__int16 v31; // [rsp+20h] [rbp-48h]
__int16 v32; // [rsp+24h] [rbp-44h]
int v33; // [rsp+28h] [rbp-40h]
int v34; // [rsp+2Ch] [rbp-3Ch]

v2 = a1;
v3 = *bjtwin_videocontrol;
palette_init_used_colors();
v5 = (v3 & 0xF) << 11;
v6 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v6 >= 0 )
{
a1 = &palette_used_colors;
a2 = &bjtwin_txvideoram;
v4 = (void *)(2 * v6);
do
{
--v6;
v7 = *(_WORD *)((char *)v4 + bjtwin_txvideoram);
v4 = (char *)v4 - 2;
*(__m128i *)(palette_used_colors + (unsigned __int8)(16 * (v7 >> 12))) = _mm_load_si128((const __m128i *)&LC0);
}
while ( v6 != -1 );
}
for ( i = 0LL; i != 4096; i += 16LL )
{
while ( 1 )
{
v9 = (__m128i *)bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + i) )
break;
i += 16LL;
if ( i == 4096 )
goto LABEL_8;
}
v10 = *(unsigned __int16 *)(bjtwin_spriteram + i + 14);
v4 = &palette_used_colors;
v9 = (__m128i *)(palette_used_colors + 16 * (v10 + 16));
*v9 = _mm_load_si128((const __m128i *)&LC0);
}
LABEL_8:
if ( !palette_recalc(a1, a2, v9, v4) && oldbgstart_2 == v5 )
{
v11 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v11 < 0 )
goto LABEL_19;
LABEL_10:
v29 = v2;
v12 = dirtybuffer;
v13 = v11;
do
{
if ( v12[v13] )
{
v14 = v11 >> 5;
v15 = v11 & 0x1F;
v16 = ((int)*(unsigned __int16 *)(bjtwin_txvideoram + 2 * v11) >> 11) & 1;
if ( flipscreen )
{
v14 = 47 - v14;
v15 = 31 - v15;
}
v17 = (unsigned int)(8 * v15);
v18 = *(_WORD *)(bjtwin_txvideoram + 2 * v11) & 0x7FF;
v19 = (unsigned int)(8 * v14);
if ( v16 )
v18 = (unsigned int)(v18 + v5);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v16 + 512),
v18,
(int)*(unsigned __int16 *)(bjtwin_txvideoram + 2 * v11) >> 12,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v19,
v17,
0LL,
0LL,
0LL);
v12 = dirtybuffer;
*((_BYTE *)dirtybuffer + v13) = 0;
}
--v11;
--v13;
}
while ( v11 != -1 );
v2 = v29;
goto LABEL_19;
}
oldbgstart_2 = v5;
memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
v11 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v11 >= 0 )
goto LABEL_10;
LABEL_19:
copybitmap(v2, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( j = 0LL; j != 4096; result = j )
{
v21 = bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + j) )
{
v22 = (unsigned int)flipscreen;
v31 = 16;
v23 = *(unsigned __int16 *)(bjtwin_spriteram + j + 6);
v24 = *(_WORD *)(bjtwin_spriteram + j + 12) & 0x1FF;
v25 = *(_WORD *)(bjtwin_spriteram + j + 2);
v32 = (*(_WORD *)(bjtwin_spriteram + j + 8) & 0x1FF) + 64;
v34 = (v25 & 0xF) + 1;
v33 = (unsigned __int16)((v25 >> 4) + 1);
if ( flipscreen )
{
v31 = -16;
v32 = 367 - ((*(_WORD *)(bjtwin_spriteram + j + 8) & 0x1FF) + 64);
v24 = 239 - v24;
}
v26 = (v25 & 0xF) + 1;
v27 = v32;
while ( 1 )
{
v28 = v23++ & 0x1FFF;
drawgfx(
v2,
*(_QWORD *)(Machine + 528LL),
v28,
*(unsigned __int16 *)(v21 + j + 14),
v22,
(unsigned int)v22,
v27 & 0x1FF,
v24 & 0x1FF,
Machine + 776LL,
2LL,
15LL);
if ( --v26 )
{
v27 += v31;
}
else
{
if ( !--v33 )
break;
v26 = v34;
v27 = v32;
v24 += v31;
}
v22 = (unsigned int)flipscreen;
v21 = bjtwin_spriteram;
}
}
j += 16LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD *a2)
{
void *v2; // r15
__int16 v3; // bx
void *v4; // rcx
int v5; // ebx
int v6; // edx
unsigned __int16 v7; // ax
__int64 i; // rax
__m128i *v9; // rdx
int v10; // edx
int v11; // ebp
_BYTE *v12; // rax
__int64 v13; // r15
int v14; // esi
int v15; // edi
int v16; // eax
__int64 v17; // rdi
__int64 v18; // rdx
__int64 v19; // rsi
__int64 result; // rax
__int64 v21; // rcx
__int64 v22; // r8
int v23; // ebp
__int16 v24; // bx
unsigned __int16 v25; // ax
int v26; // er13
__int16 v27; // r12
unsigned int v28; // er10
void *v29; // [rsp+8h] [rbp-60h]
__int64 j; // [rsp+18h] [rbp-50h]
__int16 v31; // [rsp+20h] [rbp-48h]
__int16 v32; // [rsp+24h] [rbp-44h]
int v33; // [rsp+28h] [rbp-40h]
int v34; // [rsp+2Ch] [rbp-3Ch]

v2 = a1;
v3 = *bjtwin_videocontrol;
palette_init_used_colors();
v5 = (v3 & 0xF) << 11;
v6 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v6 >= 0 )
{
a1 = &palette_used_colors;
a2 = &bjtwin_txvideoram;
v4 = (void *)(2 * v6);
do
{
--v6;
v7 = *(_WORD *)((char *)v4 + bjtwin_txvideoram);
v4 = (char *)v4 - 2;
*(__m128i *)(palette_used_colors + (unsigned __int8)(16 * (v7 >> 12))) = _mm_load_si128((const __m128i *)&LC0);
}
while ( v6 != -1 );
}
for ( i = 0LL; i != 4096; i += 16LL )
{
while ( 1 )
{
v9 = (__m128i *)bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + i) )
break;
i += 16LL;
if ( i == 4096 )
goto LABEL_8;
}
v10 = *(unsigned __int16 *)(bjtwin_spriteram + i + 14);
v4 = &palette_used_colors;
v9 = (__m128i *)(palette_used_colors + 16 * (v10 + 16));
*v9 = _mm_load_si128((const __m128i *)&LC0);
}
LABEL_8:
if ( !palette_recalc(a1, a2, v9, v4) && oldbgstart_2 == v5 )
{
v11 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v11 < 0 )
goto LABEL_19;
LABEL_10:
v29 = v2;
v12 = dirtybuffer;
v13 = v11;
do
{
if ( v12[v13] )
{
v14 = v11 >> 5;
v15 = v11 & 0x1F;
v16 = ((int)*(unsigned __int16 *)(bjtwin_txvideoram + 2 * v11) >> 11) & 1;
if ( flipscreen )
{
v14 = 47 - v14;
v15 = 31 - v15;
}
v17 = (unsigned int)(8 * v15);
v18 = *(_WORD *)(bjtwin_txvideoram + 2 * v11) & 0x7FF;
v19 = (unsigned int)(8 * v14);
if ( v16 )
v18 = (unsigned int)(v18 + v5);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 8LL * v16 + 512),
v18,
(int)*(unsigned __int16 *)(bjtwin_txvideoram + 2 * v11) >> 12,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
v19,
v17,
0LL,
0LL,
0LL);
v12 = dirtybuffer;
*((_BYTE *)dirtybuffer + v13) = 0;
}
--v11;
--v13;
}
while ( v11 != -1 );
v2 = v29;
goto LABEL_19;
}
oldbgstart_2 = v5;
memset(dirtybuffer, 1, bjtwin_txvideoram_size >> 1);
v11 = (bjtwin_txvideoram_size >> 1) - 1;
if ( v11 >= 0 )
goto LABEL_10;
LABEL_19:
copybitmap(v2, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
for ( j = 0LL; j != 4096; result = j )
{
v21 = bjtwin_spriteram;
if ( *(_WORD *)(bjtwin_spriteram + j) )
{
v22 = (unsigned int)flipscreen;
v31 = 16;
v23 = *(unsigned __int16 *)(bjtwin_spriteram + j + 6);
v24 = *(_WORD *)(bjtwin_spriteram + j + 12) & 0x1FF;
v25 = *(_WORD *)(bjtwin_spriteram + j + 2);
v32 = (*(_WORD *)(bjtwin_spriteram + j + 8) & 0x1FF) + 64;
v34 = (v25 & 0xF) + 1;
v33 = (unsigned __int16)((v25 >> 4) + 1);
if ( flipscreen )
{
v31 = -16;
v32 = 367 - ((*(_WORD *)(bjtwin_spriteram + j + 8) & 0x1FF) + 64);
v24 = 239 - v24;
}
v26 = (v25 & 0xF) + 1;
v27 = v32;
while ( 1 )
{
v28 = v23++ & 0x1FFF;
drawgfx(
v2,
*(_QWORD *)(Machine + 528LL),
v28,
*(unsigned __int16 *)(v21 + j + 14),
v22,
(unsigned int)v22,
v27 & 0x1FF,
v24 & 0x1FF,
Machine + 776LL,
2LL,
15LL);
if ( --v26 )
{
v27 += v31;
}
else
{
if ( !--v33 )
break;
v26 = v34;
v27 = v32;
v24 += v31;
}
v22 = (unsigned int)flipscreen;
v21 = bjtwin_spriteram;
}
}
j += 16LL;
}
return result;
}

original_code:
void bjtwin_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 static int oldbgstart = -1;
 int offs, bgstart;
 bgstart = 2048 * ((*(UINT16 *)(&bjtwin_videocontrol[0])) & 0x0f);
 palette_init_used_colors();
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  int color = ((*(UINT16 *)(&bjtwin_txvideoram[offs*2])) >> 12);
  memset(&palette_used_colors[16 * color],(1|2),16);
 }
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(UINT16 *)(&bjtwin_spriteram[offs])) != 0)
   memset(&palette_used_colors[256 + 16*(*(UINT16 *)(&bjtwin_spriteram[offs+14]))],(1|2),16);
 }
 if (palette_recalc() || (oldbgstart != bgstart))
 {
  oldbgstart = bgstart;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx = offs / 32;
   int sy = offs % 32;
   int tilecode = (*(UINT16 *)(&bjtwin_txvideoram[offs*2]));
   int bank = (tilecode & 0x800) ? 1 : 0;
   if (flipscreen)
   {
    sx = 47-sx;
    sy = 31-sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[bank],
     (tilecode & 0x7ff) + ((bank) ? bgstart : 0),
     tilecode >> 12,
     flipscreen, flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(UINT16 *)(&bjtwin_spriteram[offs])) != 0)
  {
   int sx = ((*(UINT16 *)(&bjtwin_spriteram[offs+8])) & 0x1ff) + 64;
   int sy = ((*(UINT16 *)(&bjtwin_spriteram[offs+12])) & 0x1ff);
   int tilecode = (*(UINT16 *)(&bjtwin_spriteram[offs+6]));
   int xx = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) & 0x0f) + 1;
   int yy = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) >> 4) + 1;
   int width = xx;
   int delta = 16;
   int startx = sx;
   if (flipscreen)
   {
    sx = 367 - sx;
    sy = 239 - sy;
    delta = -16;
    startx = sx;
   }
   do
   {
    do
    {
     drawgfx(bitmap,Machine->gfx[2],
       tilecode & 0x1fff,
       (*(UINT16 *)(&bjtwin_spriteram[offs+14])),
       flipscreen, flipscreen,
       sx & 0x1ff,sy & 0x1ff,
       &Machine->visible_area,TRANSPARENCY_PEN,15);
     tilecode++;
     sx += delta;
    } while (--xx);
    sy += delta;
    sx = startx;
    xx = width;
   } while (--yy);
  }
 }
}

canonical_original_code:
void bjtwin_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 static int oldbgstart = -1;
 int offs; int bgstart;
 bgstart = 2048 * ((*(unsigned short *)(&bjtwin_videocontrol[0])) & 0x0f);
 palette_init_used_colors();
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  int color = ((*(UINT16 *)(&bjtwin_txvideoram[offs*2])) >> 12);
  memset(&palette_used_colors[16 * color],(1|2),16);
 }
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(unsigned short *)(&bjtwin_spriteram[offs])) != 0)
   memset(&palette_used_colors[256 + 16*(*(unsigned short *)(&bjtwin_spriteram[offs+14]))],(1|2),16);
 }
 if (palette_recalc() || (oldbgstart != bgstart))
 {
  oldbgstart = bgstart;
  memset(dirtybuffer, 1, bjtwin_txvideoram_size/2);
 }
 for (offs = (bjtwin_txvideoram_size/2)-1; offs >= 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx = offs / 32;
   int sy = offs % 32;
   int tilecode = (*(UINT16 *)(&bjtwin_txvideoram[offs*2]));
   int bank = (tilecode & 0x800) ? 1 : 0;
   if (flipscreen)
   {
    sx = 47-sx;
    sy = 31-sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[bank],
     (tilecode & 0x7ff) + ((bank) ? bgstart : 0),
     tilecode >> 12,
     flipscreen, flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = 0; offs < 256*16; offs += 16)
 {
  if ((*(unsigned short *)(&bjtwin_spriteram[offs])) != 0)
  {
   int sx = ((*(UINT16 *)(&bjtwin_spriteram[offs+8])) & 0x1ff) + 64;
   int sy = ((*(UINT16 *)(&bjtwin_spriteram[offs+12])) & 0x1ff);
   int tilecode = (*(UINT16 *)(&bjtwin_spriteram[offs+6]));
   int xx = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) & 0x0f) + 1;
   int yy = ((*(UINT16 *)(&bjtwin_spriteram[offs+2])) >> 4) + 1;
   int width = xx;
   int delta = 16;
   int startx = sx;
   if (flipscreen)
   {
    sx = 367 - sx;
    sy = 239 - sy;
    delta = -16;
    startx = sx;
   }
   do
   {
    do
    {
     drawgfx(bitmap,Machine->gfx[2],
       tilecode & 0x1fff,
       (*(unsigned short *)(&bjtwin_spriteram[offs+14])),
       flipscreen, flipscreen,
       sx & 0x1ff,sy & 0x1ff,
       &Machine->visible_area,TRANSPARENCY_PEN,15);
     tilecode++;
     sx += delta;
    } while (--xx);
    sy += delta;
    sx = startx;
    xx = width;
   } while (--yy);
  }
 }
}

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

variable_types: oldbgstart int

variable_types: offs int

variable_types: bgstart int

variable_types: color int

variable_types: sx int

variable_types: sy int

variable_types: tilecode int

variable_types: bank int

variable_types: xx int

variable_types: yy int

variable_types: width int

variable_types: delta int

variable_types: startx int


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

if ( (a2 & 0xFF0000) == 0 )
{
switch ( a1 )
{
case 0:
result = OKIM6295_set_bank_base(0LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 2:
result = OKIM6295_set_bank_base(0LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 4:
result = OKIM6295_set_bank_base(0LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 6:
result = OKIM6295_set_bank_base(0LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 8:
result = OKIM6295_set_bank_base(1LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 10:
result = OKIM6295_set_bank_base(1LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 12:
result = OKIM6295_set_bank_base(1LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 14:
result = OKIM6295_set_bank_base(1LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
default:
return result;
}
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
switch ( a1 )
{
case 0:
result = OKIM6295_set_bank_base(0LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 2:
result = OKIM6295_set_bank_base(0LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 4:
result = OKIM6295_set_bank_base(0LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 6:
result = OKIM6295_set_bank_base(0LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 8:
result = OKIM6295_set_bank_base(1LL, 0LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 10:
result = OKIM6295_set_bank_base(1LL, 1LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 12:
result = OKIM6295_set_bank_base(1LL, 2LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
case 14:
result = OKIM6295_set_bank_base(1LL, 3LL, (unsigned __int8)(a2 & 0xF) << 16);
break;
default:
return result;
}
}
return result;
}

original_code:
void bjtwin_oki6295_bankswitch_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  switch (offset)
  {
   case 0x00: OKIM6295_set_bank_base(0, 0, (data & 0x0f) * 0x10000); break;
   case 0x02: OKIM6295_set_bank_base(0, 1, (data & 0x0f) * 0x10000); break;
   case 0x04: OKIM6295_set_bank_base(0, 2, (data & 0x0f) * 0x10000); break;
   case 0x06: OKIM6295_set_bank_base(0, 3, (data & 0x0f) * 0x10000); break;
   case 0x08: OKIM6295_set_bank_base(1, 0, (data & 0x0f) * 0x10000); break;
   case 0x0a: OKIM6295_set_bank_base(1, 1, (data & 0x0f) * 0x10000); break;
   case 0x0c: OKIM6295_set_bank_base(1, 2, (data & 0x0f) * 0x10000); break;
   case 0x0e: OKIM6295_set_bank_base(1, 3, (data & 0x0f) * 0x10000); break;
  }
 }
}

canonical_original_code:
void bjtwin_oki6295_bankswitch_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  switch (offset)
  {
   case 0x00: OKIM6295_set_bank_base(0, 0, (data & 0x0f) * 0x10000); break;
   case 0x02: OKIM6295_set_bank_base(0, 1, (data & 0x0f) * 0x10000); break;
   case 0x04: OKIM6295_set_bank_base(0, 2, (data & 0x0f) * 0x10000); break;
   case 0x06: OKIM6295_set_bank_base(0, 3, (data & 0x0f) * 0x10000); break;
   case 0x08: OKIM6295_set_bank_base(1, 0, (data & 0x0f) * 0x10000); break;
   case 0x0a: OKIM6295_set_bank_base(1, 1, (data & 0x0f) * 0x10000); break;
   case 0x0c: OKIM6295_set_bank_base(1, 2, (data & 0x0f) * 0x10000); break;
   case 0x0e: OKIM6295_set_bank_base(1, 3, (data & 0x0f) * 0x10000); break;
  }
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall bjtwin_address_map_bg0(unsigned __int64 a1)
{
return (a1 >> 16) & 4 | (a1 >> 10) & 2 | (a1 >> 2) & 1;
}

original_code:
unsigned long bjtwin_address_map_bg0(unsigned long addr)
{
   return ((addr&0x00004)>> 2) | ((addr&0x00800)>> 10) | ((addr&0x40000)>>16);
}

variable_types:
addr
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall bjtwin_address_map_sprites(unsigned __int64 a1)
{
return (a1 >> 16) & 2 | (a1 >> 4) & 1;
}

original_code:
unsigned long bjtwin_address_map_sprites(unsigned long addr)
{
   return ((addr&0x00010)>> 4) | ((addr&0x20000)>>16);
}


decompiled_code:
_BYTE *init_bjtwin()
{
unsigned __int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rax
unsigned __int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int16 v6; // ax
__int64 v7; // rax
_BYTE *v8; // rdx
_BYTE *v9; // rcx
_BYTE *v10; // rax
__int64 v11; // rax
_BYTE *v12; // rdx
__int64 v13; // rcx
_BYTE *result; // rax

v0 = 0LL;
v1 = memory_region(138LL);
while ( (int)memory_region_length(138LL) > (int)v0 )
{
v2 = bjtwin_address_map_bg0(v0);
*(_BYTE *)(v1 + v0) = decode_byte(*(_BYTE *)(v1 + v0), &decode_data_bg_1[8 * v2]);
++v0;
}
v3 = 0LL;
v4 = memory_region(139LL);
while ( (int)memory_region_length(139LL) > (int)v3 )
{
v5 = bjtwin_address_map_sprites(v3);
v6 = decode_word(
*(unsigned __int8 *)(v4 + v3 + 1) + (*(unsigned __int8 *)(v4 + v3) << 8),
&decode_data_sprite_0[16 * v5]);
*(_BYTE *)(v4 + v3 + 1) = v6;
*(_BYTE *)(v4 + v3) = HIBYTE(v6);
v3 += 2LL;
}
v7 = memory_region(146LL);
v8 = (_BYTE *)(v7 + 1024);
v9 = (_BYTE *)(v7 + 1049600);
do
{
v10 = v8 - 1024;
do
{
*v10 = 0;
v10 += 8;
*(v10 - 5) = 0;
}
while ( v10 != v8 );
v8 = v10 + 0x10000;
}
while ( v10 + 0x10000 != v9 );
v11 = memory_region(147LL);
v12 = (_BYTE *)(v11 + 1024);
v13 = v11 + 1049600;
do
{
result = v12 - 1024;
do
{
*result = 0;
result += 8;
*(result - 5) = 0;
}
while ( v12 != result );
v12 += 0x10000;
}
while ( (_BYTE *)v13 != v12 );
return result;
}

variable_types:
rom
unsigned char *

variable_types: A int

variable_types: i int

variable_types:
tmp
unsigned short


decompiled_code:
void __fastcall vigilant_horiz_scroll_w(int a1, int a2)
{
if ( a1 )
horiz_scroll_high = (a2 & 1) << 8;
else
horiz_scroll_low = a2;
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
if ( a1 )
horiz_scroll_high = (a2 & 1) << 8;
else
horiz_scroll_low = a2;
}

original_code:
void vigilant_horiz_scroll_w(offs_t offset,data_t data)
{
 if (offset==0)
  horiz_scroll_low = data;
 else
  horiz_scroll_high = (data & 0x01) * 256;
}

canonical_original_code:
void vigilant_horiz_scroll_w(unsigned int offset, unsigned int data)
{
 if (offset==0)
  horiz_scroll_low = data;
 else
  horiz_scroll_high = (data & 0x01) * 256;
}


decompiled_code:
void __fastcall vigilant_rear_horiz_scroll_w(int a1, int a2)
{
if ( a1 )
rear_horiz_scroll_high = (a2 & 7) << 8;
else
rear_horiz_scroll_low = a2;
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
if ( a1 )
rear_horiz_scroll_high = (a2 & 7) << 8;
else
rear_horiz_scroll_low = a2;
}

original_code:
void vigilant_rear_horiz_scroll_w(offs_t offset,data_t data)
{
 if (offset==0)
  rear_horiz_scroll_low = data;
 else
  rear_horiz_scroll_high = (data & 0x07) * 256;
}

canonical_original_code:
void vigilant_rear_horiz_scroll_w(unsigned int offset, unsigned int data)
{
 if (offset==0)
  rear_horiz_scroll_low = data;
 else
  rear_horiz_scroll_high = (data & 0x07) * 256;
}


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

result = a2 & 0x40;
rear_color = a2 & 0xD;
rear_disable = a2 & 0x40;
return result;
}

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

result = a2 & 0x40;
rear_color = a2 & 0xD;
rear_disable = a2 & 0x40;
return result;
}

original_code:
void vigilant_rear_color_w(offs_t offset,data_t data)
{
 rear_disable = data & 0x40;
 rear_color = (data & 0x0d);
}

canonical_original_code:
void vigilant_rear_color_w(unsigned int offset, unsigned int data)
{
 rear_disable = data & 0x40;
 rear_color = (data & 0x0d);
}


decompiled_code:
__int64 vigilant_vh_start()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v2; // rcx
unsigned int v3; // er8

generic_vh_start();
v0 = bitmap_alloc(1536LL, 256LL);
v3 = 0;
bg_bitmap = v0;
if ( !v0 )
{
generic_vh_stop(1536LL, 256LL, v1, v2, 0LL);
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 v2; // rcx
unsigned int v3; // er8

generic_vh_start();
v0 = bitmap_alloc(1536LL, 256LL);
v3 = 0;
bg_bitmap = v0;
if ( !v0 )
{
generic_vh_stop(1536LL, 256LL, v1, v2, 0LL);
v3 = 1;
}
return v3;
}

original_code:
int vigilant_vh_start(void)
{
 generic_vh_start();
 if ((bg_bitmap = bitmap_alloc(512*3,256)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int vigilant_vh_start()
{
 generic_vh_start();
 if ((bg_bitmap = bitmap_alloc(512*3,256)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall vigilant_vh_stop(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8

v2 = bg_bitmap;
bitmap_free(bg_bitmap);
return generic_vh_stop(v2, a2, v3, v4, v5);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8

v2 = bg_bitmap;
bitmap_free(bg_bitmap);
return generic_vh_stop(v2, a2, v3, v4, v5);
}

original_code:
void vigilant_vh_stop(void)
{
 bitmap_free(bg_bitmap);
 generic_vh_stop();
}

canonical_original_code:
void vigilant_vh_stop()
{
 bitmap_free(bg_bitmap);
 generic_vh_stop();
}


decompiled_code:
__int64 __fastcall vigilant_paletteram_w(unsigned int a1, char a2)
{
*(_BYTE *)(paletteram + a1) = a2;
return palette_change_color(
(unsigned int)(unsigned __int8)a1 + ((int)(a1 & 0x400) >> 2),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + ((unsigned __int8)a1 | a1 & 0x400))),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + ((unsigned __int8)a1 | a1 & 0x400) + 256)),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + ((unsigned __int8)a1 | a1 & 0x400) + 512)));
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
*(_BYTE *)(paletteram + a1) = a2;
return palette_change_color(
(unsigned int)(unsigned __int8)a1 + ((int)(a1 & 0x400) >> 2),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + ((unsigned __int8)a1 | a1 & 0x400))),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + ((unsigned __int8)a1 | a1 & 0x400) + 256)),
(unsigned __int8)(8 * *(_BYTE *)(paletteram + ((unsigned __int8)a1 | a1 & 0x400) + 512)));
}

original_code:
void vigilant_paletteram_w(offs_t offset,data_t data)
{
 int bank,r,g,b;
 paletteram[offset] = data;
 bank = offset & 0x400;
 offset &= 0xff;
 r = (paletteram[bank + offset + 0x000] << 3) & 0xFF;
 g = (paletteram[bank + offset + 0x100] << 3) & 0xFF;
 b = (paletteram[bank + offset + 0x200] << 3) & 0xFF;
 palette_change_color((bank >> 2) + offset,r,g,b);
}

canonical_original_code:
void vigilant_paletteram_w(unsigned int offset, unsigned int data)
{
 int bank; int r; int g; int b;
 paletteram[offset] = data;
 bank = offset & 0x400;
 offset &= 0xff;
 r = (paletteram[bank + offset + 0x000] << 3) & 0xFF;
 g = (paletteram[bank + offset + 0x100] << 3) & 0xFF;
 b = (paletteram[bank + offset + 0x200] << 3) & 0xFF;
 palette_change_color((bank >> 2) + offset,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int


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

cpu_bankbase[1] = memory_region(129LL) + (((a2 & 7u) + 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 func10(__int64 a1, char a2)
{
void *result; // rax
unsigned int v3; // eax

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

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

canonical_original_code:
void vigilant_bank_select_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 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: bankaddress int

variable_types:
RAM
unsigned char *


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

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

original_code:
void vigilant_out2_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x04);
}

canonical_original_code:
void vigilant_out2_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x04);
}


decompiled_code:
__int64 __fastcall kikcubic_coin_w(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char a2)
{
coin_counter_w(0LL, a2 & 0x10);
return coin_counter_w(1LL, a2 & 0x20);
}

original_code:
void kikcubic_coin_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void kikcubic_coin_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x10);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 update_background()
{
__int64 v0; // rbp
int v1; // er12
__int64 v2; // r15
unsigned int v3; // ebx
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // [rsp-30h] [rbp-78h]
unsigned int i; // [rsp+Ch] [rbp-3Ch]

for ( i = 0; i != 1536; result = i )
{
v0 = 0LL;
v1 = 8 * i + 16;
do
{
v2 = i;
v3 = v1 - 16;
do
{
v4 = v3++;
v6 = v2;
v2 = (unsigned int)(v2 + 32);
drawgfx(bg_bitmap, *(_QWORD *)(Machine + 528LL), v4, (int)v0 > 127, 0LL, 0LL, v6, v0, 0LL, 0LL, 0LL);
}
while ( v3 != v1 );
v0 = (unsigned int)(v0 + 1);
v1 = v3 + 16;
}
while ( (_DWORD)v0 != 256 );
i += 512;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
int v1; // er12
__int64 v2; // r15
unsigned int v3; // ebx
__int64 v4; // rdx
__int64 result; // rax
__int64 v6; // [rsp-30h] [rbp-78h]
unsigned int i; // [rsp+Ch] [rbp-3Ch]

for ( i = 0; i != 1536; result = i )
{
v0 = 0LL;
v1 = 8 * i + 16;
do
{
v2 = i;
v3 = v1 - 16;
do
{
v4 = v3++;
v6 = v2;
v2 = (unsigned int)(v2 + 32);
drawgfx(bg_bitmap, *(_QWORD *)(Machine + 528LL), v4, (int)v0 > 127, 0LL, 0LL, v6, v0, 0LL, 0LL, 0LL);
}
while ( v3 != v1 );
v0 = (unsigned int)(v0 + 1);
v1 = v3 + 16;
}
while ( (_DWORD)v0 != 256 );
i += 512;
}
return result;
}

original_code:
static void update_background( void )
{
 int row,col,page;
 int charcode;
 charcode=0;
 for (page=0; page<3; page++)
 {
  for( row=0; row<256; row++ )
  {
   for( col=0; col<512; col+=32 )
   {
    drawgfx(bg_bitmap,
      Machine->gfx[2],
      charcode,
      row < 128 ? 0 : 1,
      0,0,
      512*page + col,row,
      0,TRANSPARENCY_NONE,0);
    charcode++;
   }
  }
 }
}

canonical_original_code:
static void update_background()
{
 int row; int col; int page;
 int charcode;
 charcode=0;
 for (page=0; page<3; page++)
 {
  for( row=0; row<256; row++ )
  {
   for( col=0; col<512; col+=32 )
   {
    drawgfx(bg_bitmap,
      Machine->gfx[2],
      charcode,
      row < 128 ? 0 : 1,
      0,0,
      512*page + col,row,
      0,TRANSPARENCY_NONE,0);
    charcode++;
   }
  }
 }
}

variable_types: row int

variable_types: col int

variable_types: page int

variable_types: charcode int


decompiled_code:
__int64 __fastcall draw_background(__int64 a1)
{
int v2[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v2[0] = 506 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
if ( rear_refresh )
{
update_background();
rear_refresh = 0;
}
return copyscrollbitmap(a1, bg_bitmap, 1LL, v2, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v2[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v2[0] = 506 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
if ( rear_refresh )
{
func6();
rear_refresh = 0;
}
return copyscrollbitmap(a1, bg_bitmap, 1LL, v2, 0LL, 0LL, &bottomvisiblearea, 0LL, 0LL);
}

original_code:
static void draw_background( struct osd_bitmap *bitmap )
{
 int scrollx = 0x17a + 16*8 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
 if (rear_refresh)
 {
  update_background( );
  rear_refresh=0;
 }
 copyscrollbitmap(bitmap,bg_bitmap,1,&scrollx,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap)
{
 int scrollx = 0x17a + 16*8 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
 if (rear_refresh)
 {
  update_background( );
  rear_refresh=0;
 }
 copyscrollbitmap(bitmap,bg_bitmap,1,&scrollx,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
}

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

variable_types: scrollx int


original_code:
static data_t aeroboto_201_r(offs_t offset)
{
 int res[4] = { 0xff,0x9f,0x1b,0x03};
 static int count;
 return res[(count++)&3];
}

canonical_original_code:
static unsigned int aeroboto_201_r(unsigned int offset)
{
 int res[4] = { 0xff,0x9f,0x1b,0x03};
 static int count;
 return res[(count++)&3];
}

variable_types:
offset
unsigned int

variable_types:
res
int [4]

variable_types: count int


decompiled_code:
void *__fastcall aeroboto_vh_screenrefresh(__int64 a1)
{
int v1; // eax
__int64 v2; // r15
int v3; // ebx
int v4; // esi
int v5; // er10
__int64 v6; // r12
int v7; // ebx
int v8; // esi
void *result; // rax
int v10; // er12
__int64 v11; // rbx
__int64 v12; // rcx
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // [rsp-28h] [rbp-80h]
__int64 v16; // [rsp+10h] [rbp-48h]
__int64 v17; // [rsp+10h] [rbp-48h]
unsigned int v18; // [rsp+18h] [rbp-40h]
unsigned int v19; // [rsp+18h] [rbp-40h]
int v20; // [rsp+1Ch] [rbp-3Ch]
int v21; // [rsp+1Ch] [rbp-3Ch]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
v20 = v1;
v3 = 8 * (v1 & 0x1F);
v18 = 8 * (v1 >> 5);
v16 = v1 >> 5;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(aeroboto_charbank[0] << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
0LL,
0LL,
0LL,
v3 - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v16),
v18,
Machine + 776LL,
0LL,
0LL);
v4 = *(unsigned __int8 *)(videoram + v2--);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)(v4 + (aeroboto_charbank[0] << 8)),
0LL,
0LL,
0LL,
v3 - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v16) + 256,
v18,
Machine + 776LL,
0LL,
0LL);
v1 = v20 - 1;
}
while ( v20 );
v5 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v6 = v5;
do
{
v21 = v5;
v7 = 8 * (v5 & 0x1F);
v19 = 8 * (v5 >> 5);
v17 = v5 >> 5;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(aeroboto_charbank[0] << 8) + (unsigned int)*(unsigned __int8 *)(aeroboto_videoram + v6),
0LL,
0LL,
0LL,
v7 - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v17),
v19,
Machine + 776LL,
2LL,
0LL);
v8 = *(unsigned __int8 *)(aeroboto_videoram + v6--);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)(v8 + (aeroboto_charbank[0] << 8)),
0LL,
0LL,
0LL,
v7 - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v17) + 256,
v19,
Machine + 776LL,
2LL,
0LL);
v5 = v21 - 1;
}
while ( v21 );
}
}
result = &spriteram_size;
v10 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v10 + 3LL;
do
{
v12 = *(_BYTE *)(spriteram + v11 - 1) & 0xF;
v15 = 239 - (unsigned int)*(unsigned __int8 *)(spriteram + v11 - 3);
v13 = *(unsigned __int8 *)(spriteram + v11);
v14 = *(unsigned __int8 *)(spriteram + v11 - 2);
v11 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v14,
v12,
0LL,
0LL,
v13,
v15,
Machine + 776LL,
2LL,
0LL);
v10 -= 4;
}
while ( v10 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // eax
__int64 v2; // r15
int v3; // ebx
int v4; // esi
int v5; // er10
__int64 v6; // r12
int v7; // ebx
int v8; // esi
void *result; // rax
int v10; // er12
__int64 v11; // rbx
__int64 v12; // rcx
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // [rsp-28h] [rbp-80h]
__int64 v16; // [rsp+10h] [rbp-48h]
__int64 v17; // [rsp+10h] [rbp-48h]
unsigned int v18; // [rsp+18h] [rbp-40h]
unsigned int v19; // [rsp+18h] [rbp-40h]
int v20; // [rsp+1Ch] [rbp-3Ch]
int v21; // [rsp+1Ch] [rbp-3Ch]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
v20 = v1;
v3 = 8 * (v1 & 0x1F);
v18 = 8 * (v1 >> 5);
v16 = v1 >> 5;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(aeroboto_charbank[0] << 8) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
0LL,
0LL,
0LL,
v3 - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v16),
v18,
Machine + 776LL,
0LL,
0LL);
v4 = *(unsigned __int8 *)(videoram + v2--);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)(v4 + (aeroboto_charbank[0] << 8)),
0LL,
0LL,
0LL,
v3 - (unsigned int)*(unsigned __int8 *)(aeroboto_bgscroll + v16) + 256,
v18,
Machine + 776LL,
0LL,
0LL);
v1 = v20 - 1;
}
while ( v20 );
v5 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v6 = v5;
do
{
v21 = v5;
v7 = 8 * (v5 & 0x1F);
v19 = 8 * (v5 >> 5);
v17 = v5 >> 5;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(aeroboto_charbank[0] << 8) + (unsigned int)*(unsigned __int8 *)(aeroboto_videoram + v6),
0LL,
0LL,
0LL,
v7 - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v17),
v19,
Machine + 776LL,
2LL,
0LL);
v8 = *(unsigned __int8 *)(aeroboto_videoram + v6--);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(unsigned int)(v8 + (aeroboto_charbank[0] << 8)),
0LL,
0LL,
0LL,
v7 - (unsigned int)*(unsigned __int8 *)(aeroboto_fgscroll + v17) + 256,
v19,
Machine + 776LL,
2LL,
0LL);
v5 = v21 - 1;
}
while ( v21 );
}
}
result = &spriteram_size;
v10 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v11 = v10 + 3LL;
do
{
v12 = *(_BYTE *)(spriteram + v11 - 1) & 0xF;
v15 = 239 - (unsigned int)*(unsigned __int8 *)(spriteram + v11 - 3);
v13 = *(unsigned __int8 *)(spriteram + v11);
v14 = *(unsigned __int8 *)(spriteram + v11 - 2);
v11 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
v14,
v12,
0LL,
0LL,
v13,
v15,
Machine + 776LL,
2LL,
0LL);
v10 -= 4;
}
while ( v10 >= 0 );
}
return result;
}

original_code:
void aeroboto_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size-4;offs >= 0;offs -= 4)
 {
  int sx,sy;
  sx = spriteram[offs + 3];
  sy = 239 - spriteram[offs];
  drawgfx(bitmap,Machine->gfx[2],
    spriteram[offs + 1],
    spriteram[offs + 2] & 0x0f,
    0,0,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void aeroboto_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 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] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
  drawgfx(bitmap,Machine->gfx[0],
    videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_bgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy],8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[0],
    aeroboto_videoram[offs] + 256 * aeroboto_charbank,
    0,
    0,0,
    8*sx - aeroboto_fgscroll[sy] + 256,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = spriteram_size-4;offs >= 0;offs -= 4)
 {
  int sx; int sy;
  sx = spriteram[offs + 3];
  sy = 239 - spriteram[offs];
  drawgfx(bitmap,Machine->gfx[2],
    spriteram[offs + 1],
    spriteram[offs + 2] & 0x0f,
    0,0,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: offs int

variable_types: sx int

variable_types: sy int

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


decompiled_code:
__int64 aeroboto_in0_r()
{
return readinputport((unsigned int)player);
}

canonical_decompiled_code:
__int64 func2()
{
return readinputport((unsigned int)player);
}

original_code:
static data_t aeroboto_in0_r(offs_t offset)
{
 return readinputport(player);
}

canonical_original_code:
static unsigned int aeroboto_in0_r(unsigned int offset)
{
 return readinputport(player);
}


decompiled_code:
void __fastcall adjust_xy(int a1)
{
switch ( a1 )
{
case 0:
--x;
++y;
break;
case 1:
--y;
break;
case 2:
--x;
break;
case 4:
++x;
++y;
break;
case 5:
++y;
break;
case 6:
++x;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
switch ( a1 )
{
case 0:
--x;
++y;
break;
case 1:
--y;
break;
case 2:
--x;
break;
case 4:
++x;
++y;
break;
case 5:
++y;
break;
case 6:
++x;
break;
default:
return;
}
}

original_code:
static void adjust_xy(int offset)
{
 switch(offset)
 {
 case 0x00: x--; y++; break;
 case 0x01: y--; break;
 case 0x02: x--; break;
 case 0x04: x++; y++; break;
 case 0x05: y++; break;
 case 0x06: x++; break;
 }
}

variable_types: offset int


decompiled_code:
__int64 __fastcall graph_processor_r(int a1)
{
unsigned int v1; // er8

adjust_xy(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // er8

func0(a1);
return v1;
}

original_code:
data_t graph_processor_r(offs_t offset)
{
 int ret;
 if (bmap)
 {
  ret = tmpvideoram2[y*256+x];
 }
 else
 {
  ret = tmpvideoram[y*256+x];
 }
 adjust_xy(offset);
 return ret;
}

canonical_original_code:
unsigned int graph_processor_r(unsigned int offset)
{
 int ret;
 if (bmap)
 {
  ret = tmpvideoram2[y*256+x];
 }
 else
 {
  ret = tmpvideoram[y*256+x];
 }
 adjust_xy(offset);
 return ret;
}

variable_types: ret int


decompiled_code:
void __fastcall graph_processor_w(int a1, char a2)
{
int v2; // ebx
__int64 v3; // rsi
__int64 v4; // rcx

if ( a1 == 3 )
{
x = a2;
}
else if ( a1 == 7 )
{
y = a2;
}
else
{
v2 = a2 & 7;
v3 = (unsigned __int8)(x - 6);
v4 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v2 + 16));
if ( bmap )
{
plot_pixel(tmpbitmap, v3, (unsigned __int8)y, v4);
*((_BYTE *)tmpvideoram + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
else
{
plot_pixel(tmpbitmap2, v3, (unsigned __int8)y, v4);
*((_BYTE *)tmpvideoram2 + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
adjust_xy(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, char a2)
{
int v2; // ebx
__int64 v3; // rsi
__int64 v4; // rcx

if ( a1 == 3 )
{
x = a2;
}
else if ( a1 == 7 )
{
y = a2;
}
else
{
v2 = a2 & 7;
v3 = (unsigned __int8)(x - 6);
v4 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v2 + 16));
if ( bmap )
{
plot_pixel(tmpbitmap, v3, (unsigned __int8)y, v4);
*((_BYTE *)tmpvideoram + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
else
{
plot_pixel(tmpbitmap2, v3, (unsigned __int8)y, v4);
*((_BYTE *)tmpvideoram2 + 256 * (unsigned __int8)y + (unsigned __int8)x) = v2;
}
func0(a1);
}
}

original_code:
void graph_processor_w(offs_t offset,data_t data)
{
 int col;
 switch (offset)
 {
 case 0x03: x=data; break;
 case 0x07: y=data; break;
 default:
  col = data & 0x07;
  if (bmap)
  {
   plot_pixel(tmpbitmap, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram[y*256+x] = col;
  }
  else
  {
   plot_pixel(tmpbitmap2, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram2[y*256+x] = col;
  }
  adjust_xy(offset);
  break;
 }
}

canonical_original_code:
void graph_processor_w(unsigned int offset, unsigned int data)
{
 int col;
 switch (offset)
 {
 case 0x03: x=data; break;
 case 0x07: y=data; break;
 default:
  col = data & 0x07;
  if (bmap)
  {
   plot_pixel(tmpbitmap, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram[y*256+x] = col;
  }
  else
  {
   plot_pixel(tmpbitmap2, (x-6)&0xff, y, Machine->pens[16 + col]);
   tmpvideoram2[y*256+x] = col;
  }
  adjust_xy(offset);
  break;
 }
}

variable_types:
data
unsigned int


decompiled_code:
__int64 refresh_bitmaps()
{
unsigned int v0; // ebp
__int64 v1; // rbx
int v2; // er15
unsigned int v3; // er14
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-40h]

v0 = 0;
v6 = 0LL;
do
{
v1 = v6;
v2 = -6;
do
{
v3 = (unsigned __int8)v2++;
plot_pixel(
tmpbitmap,
v3,
v0,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)tmpvideoram + v1) + 32));
v4 = *((unsigned __int8 *)tmpvideoram2 + v1++);
result = plot_pixel(tmpbitmap2, v3, v0, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2 * v4 + 32));
}
while ( v2 != 250 );
v6 += 256LL;
++v0;
}
while ( v0 != 256 );
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebp
__int64 v1; // rbx
int v2; // er15
unsigned int v3; // er14
__int64 v4; // rcx
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-40h]

v0 = 0;
v6 = 0LL;
do
{
v1 = v6;
v2 = -6;
do
{
v3 = (unsigned __int8)v2++;
plot_pixel(
tmpbitmap,
v3,
v0,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)tmpvideoram + v1) + 32));
v4 = *((unsigned __int8 *)tmpvideoram2 + v1++);
result = plot_pixel(tmpbitmap2, v3, v0, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2 * v4 + 32));
}
while ( v2 != 250 );
v6 += 256LL;
++v0;
}
while ( v0 != 256 );
return result;
}

original_code:
static void refresh_bitmaps(void)
{
 int lx,ly;
 for (ly = 0; ly < 256; ly++)
 {
  for (lx = 0; lx < 256; lx++)
  {
   plot_pixel(tmpbitmap, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram[ly*256+lx]]);
   plot_pixel(tmpbitmap2, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram2[ly*256+lx]]);
  }
 }
}

canonical_original_code:
static void refresh_bitmaps()
{
 int lx; int ly;
 for (ly = 0; ly < 256; ly++)
 {
  for (lx = 0; lx < 256; lx++)
  {
   plot_pixel(tmpbitmap, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram[ly*256+lx]]);
   plot_pixel(tmpbitmap2, (lx-6)&0xff, ly, Machine->pens[16 + tmpvideoram2[ly*256+lx]]);
  }
 }
}

variable_types: lx int

variable_types: ly int


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

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

original_code:
static data_t cloak_sharedram_r(offs_t offset)
{
 return cloak_sharedram[offset];
}

canonical_original_code:
static unsigned int cloak_sharedram_r(unsigned int offset)
{
 return cloak_sharedram[offset];
}


variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
void *__fastcall cloak_clearbmp_w(__int64 a1, char a2)
{
void *result; // rax
__int64 v3; // rsi
__int64 v4; // rdx

result = (void *)(a2 & 1);
bmap = a2 & 1;
if ( (a2 & 2) != 0 )
{
v3 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL);
v4 = Machine + 776LL;
if ( (_BYTE)result )
{
fillbitmap(tmpbitmap, v3, v4);
result = memset(tmpvideoram, 0, 0x10000uLL);
}
else
{
fillbitmap(tmpbitmap2, v3, v4);
result = memset(tmpvideoram2, 0, 0x10000uLL);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, char a2)
{
void *result; // rax
__int64 v3; // rsi
__int64 v4; // rdx

result = (void *)(a2 & 1);
bmap = a2 & 1;
if ( (a2 & 2) != 0 )
{
v3 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL);
v4 = Machine + 776LL;
if ( (_BYTE)result )
{
fillbitmap(tmpbitmap, v3, v4);
result = memset(tmpvideoram, 0, 0x10000uLL);
}
else
{
fillbitmap(tmpbitmap2, v3, v4);
result = memset(tmpvideoram2, 0, 0x10000uLL);
}
}
return result;
}

original_code:
void cloak_clearbmp_w(offs_t offset,data_t data)
{
 bmap = data & 1;
 if (data & 2)
 {
  if (bmap)
  {
   fillbitmap(tmpbitmap, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram, 0, 256*256);
  }
  else
  {
   fillbitmap(tmpbitmap2, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram2, 0, 256*256);
  }
 }
}

canonical_original_code:
void cloak_clearbmp_w(unsigned int offset, unsigned int data)
{
 bmap = data & 1;
 if (data & 2)
 {
  if (bmap)
  {
   fillbitmap(tmpbitmap, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram, 0, 256*256);
  }
  else
  {
   fillbitmap(tmpbitmap2, Machine->pens[16], &Machine->visible_area);
   memset(tmpvideoram2, 0, 256*256);
  }
 }
}


decompiled_code:
void cloak_vh_stop()
{
if ( charbitmap )
bitmap_free();
if ( tmpbitmap2 )
bitmap_free();
if ( tmpbitmap )
bitmap_free();
if ( dirtybuffer )
free(dirtybuffer);
if ( tmpvideoram )
free(tmpvideoram);
if ( tmpvideoram2 )
free(tmpvideoram2);
}

canonical_decompiled_code:
void func8()
{
if ( charbitmap )
bitmap_free();
if ( tmpbitmap2 )
bitmap_free();
if ( tmpbitmap )
bitmap_free();
if ( dirtybuffer )
free(dirtybuffer);
if ( tmpvideoram )
free(tmpvideoram);
if ( tmpvideoram2 )
free(tmpvideoram2);
}

original_code:
void cloak_vh_stop(void)
{
 if (charbitmap) bitmap_free(charbitmap);
 if (tmpbitmap2) bitmap_free(tmpbitmap2);
 if (tmpbitmap) bitmap_free(tmpbitmap);
 if (dirtybuffer) free(dirtybuffer);
 if (tmpvideoram) free(tmpvideoram);
 if (tmpvideoram2) free(tmpvideoram2);
}

canonical_original_code:
void cloak_vh_stop()
{
 if (charbitmap) bitmap_free(charbitmap);
 if (tmpbitmap2) bitmap_free(tmpbitmap2);
 if (tmpbitmap) bitmap_free(tmpbitmap);
 if (dirtybuffer) free(dirtybuffer);
 if (tmpvideoram) free(tmpvideoram);
 if (tmpvideoram2) free(tmpvideoram2);
}


decompiled_code:
__int64 cloak_vh_start()
{
__int64 v0; // rax
unsigned int v1; // er8
size_t v2; // r12
void *v3; // rdi

v0 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v1 = 1;
tmpbitmap = v0;
if ( !v0 )
return v1;
charbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( charbitmap )
{
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
{
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpvideoram = malloc(0x10000uLL);
if ( tmpvideoram )
{
tmpvideoram2 = malloc(0x10000uLL);
if ( tmpvideoram2 )
return 0;
}
}
}
}
cloak_vh_stop();
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax
unsigned int v1; // er8
size_t v2; // r12
void *v3; // rdi

v0 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v1 = 1;
tmpbitmap = v0;
if ( !v0 )
return v1;
charbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( charbitmap )
{
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
{
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpvideoram = malloc(0x10000uLL);
if ( tmpvideoram )
{
tmpvideoram2 = malloc(0x10000uLL);
if ( tmpvideoram2 )
return 0;
}
}
}
}
func8();
return 1LL;
}

original_code:
int cloak_vh_start(void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((charbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((dirtybuffer = (unsigned char*)malloc(videoram_size)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpvideoram = (unsigned char*)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpvideoram2 = (unsigned char*)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int cloak_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((charbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((dirtybuffer = (unsigned char *)malloc(videoram_size)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 memset(dirtybuffer,1,videoram_size);
 if ((tmpvideoram = (unsigned char *)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 if ((tmpvideoram2 = (unsigned char *)malloc(256*256)) == 0)
 {
  cloak_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall cloak_led_w(int a1, int a2)
{
return osd_led_w((unsigned int)(1 - a1), (unsigned int)~a2 >> 7);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
return osd_led_w((unsigned int)(1 - a1), (unsigned int)~a2 >> 7);
}

original_code:
void cloak_led_w(offs_t offset,data_t data)
{
 osd_led_w(1 - offset,~data >> 7);
}

canonical_original_code:
void cloak_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w(1 - offset,~data >> 7);
}


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

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

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

variable_types:
file
void *


decompiled_code:
void init_jack()
{
timer_rate = 128;
}

canonical_decompiled_code:
void func0()
{
timer_rate = 128;
}

original_code:
static void init_jack(void)
{
 timer_rate = 128;
}

canonical_original_code:
static void init_jack()
{
 timer_rate = 128;
}


canonical_decompiled_code:
void func1()
{
timer_rate = 16;
}

original_code:
static void init_zzyzzyxx(void)
{
 timer_rate = 16;
}

canonical_original_code:
static void init_zzyzzyxx()
{
 timer_rate = 16;
}


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

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

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

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


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

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

original_code:
data_t jack_flipscreen_r(offs_t offset)
{
 flip_screen_w(0, offset);
 return 0;
}

canonical_original_code:
unsigned int jack_flipscreen_r(unsigned int offset)
{
 flip_screen_w(0, offset);
 return 0;
}


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

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

original_code:
void jack_flipscreen_w(offs_t offset,data_t data)
{
 flip_screen_w(0, offset);
}

canonical_original_code:
void jack_flipscreen_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0, offset);
}


decompiled_code:
void *__fastcall jack_vh_screenrefresh(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // r15
int v5; // edi
int v6; // esi
void *result; // rax
int v8; // ebx
__int64 v9; // r15
__int64 v10; // rdi
__int64 v11; // r11
__int64 v12; // r9
unsigned __int8 v13; // cl
__int64 v14; // r8
__int64 v15; // rdx

if ( palette_recalc() || a2 )
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v6 = v3 >> 5;
v5 = v3 & 0x1F;
if ( flip_screen_x )
v6 = 31 - v6;
else
v5 = 31 - v5;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + ((32 * *(unsigned __int8 *)(colorram + v4)) & 0x300u),
*(_BYTE *)(colorram + v4) & 7,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v6),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v4;
}
while ( v3 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v8 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v9 = v8 + 1LL;
do
{
v10 = *(unsigned __int8 *)(spriteram + v9);
v11 = *(unsigned __int8 *)(spriteram + v9 - 1);
v12 = *(_BYTE *)(spriteram + v9 + 2) & 0x40;
v13 = *(_BYTE *)(spriteram + v9 + 2) & 7;
v14 = *(_BYTE *)(spriteram + v9 + 2) & 0x80;
v15 = *(unsigned __int8 *)(spriteram + v9 + 1) + ((32 * *(unsigned __int8 *)(spriteram + v9 + 2)) & 0x100u);
if ( flip_screen_x )
{
v10 = (unsigned int)(248 - v10);
v11 = (unsigned int)(248 - v11);
v14 = (_DWORD)v14 == 0;
v12 = (_DWORD)v12 == 0;
}
v9 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v15,
v13,
v14,
v12,
v10,
v11,
Machine + 776LL,
2LL,
0LL);
v8 -= 4;
}
while ( v8 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // r15
int v5; // edi
int v6; // esi
void *result; // rax
int v8; // ebx
__int64 v9; // r15
__int64 v10; // rdi
__int64 v11; // r11
__int64 v12; // r9
unsigned __int8 v13; // cl
__int64 v14; // r8
__int64 v15; // rdx

if ( palette_recalc() || a2 )
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v6 = v3 >> 5;
v5 = v3 & 0x1F;
if ( flip_screen_x )
v6 = 31 - v6;
else
v5 = 31 - v5;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v4) + ((32 * *(unsigned __int8 *)(colorram + v4)) & 0x300u),
*(_BYTE *)(colorram + v4) & 7,
flip_screen_x,
flip_screen_x,
(unsigned int)(8 * v6),
(unsigned int)(8 * v5),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v4;
}
while ( v3 != -1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v8 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v9 = v8 + 1LL;
do
{
v10 = *(unsigned __int8 *)(spriteram + v9);
v11 = *(unsigned __int8 *)(spriteram + v9 - 1);
v12 = *(_BYTE *)(spriteram + v9 + 2) & 0x40;
v13 = *(_BYTE *)(spriteram + v9 + 2) & 7;
v14 = *(_BYTE *)(spriteram + v9 + 2) & 0x80;
v15 = *(unsigned __int8 *)(spriteram + v9 + 1) + ((32 * *(unsigned __int8 *)(spriteram + v9 + 2)) & 0x100u);
if ( flip_screen_x )
{
v10 = (unsigned int)(248 - v10);
v11 = (unsigned int)(248 - v11);
v14 = (_DWORD)v14 == 0;
v12 = (_DWORD)v12 == 0;
}
v9 -= 4LL;
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v15,
v13,
v14,
v12,
v10,
v11,
Machine + 776LL,
2LL,
0LL);
v8 -= 4;
}
while ( v8 >= 0 );
}
return result;
}

original_code:
void jack_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs / 32;
   sy = 31 - offs % 32;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x18) << 5),
     colorram[offs] & 0x07,
     flip_screen_x,flip_screen_x,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,num, color,flipx,flipy;
  sx = spriteram[offs + 1];
  sy = spriteram[offs];
  num = spriteram[offs + 2] + ((spriteram[offs + 3] & 0x08) << 5);
  color = spriteram[offs + 3] & 0x07;
  flipx = (spriteram[offs + 3] & 0x80);
  flipy = (spriteram[offs + 3] & 0x40);
  if (flip_screen_x)
  {
   sx = 248 - sx;
   sy = 248 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    num,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void jack_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs / 32;
   sy = 31 - offs % 32;
   if (flip_screen_x)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x18) << 5),
     colorram[offs] & 0x07,
     flip_screen_x,flip_screen_x,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int num; int color; int flipx; int flipy;
  sx = spriteram[offs + 1];
  sy = spriteram[offs];
  num = spriteram[offs + 2] + ((spriteram[offs + 3] & 0x08) << 5);
  color = spriteram[offs + 3] & 0x07;
  flipx = (spriteram[offs + 3] & 0x80);
  flipy = (spriteram[offs + 3] & 0x40);
  if (flip_screen_x)
  {
   sx = 248 - sx;
   sy = 248 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    num,
    color,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: num int

variable_types: color int

variable_types: flipx int

variable_types: flipy int


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

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

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

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

variable_types:
offset
unsigned int


decompiled_code:
__int64 treahunt_decode()
{
__int64 v0; // rbx
_BYTE *v1; // rbp
_BYTE *v2; // rsi
__int64 i; // rcx
__int64 result; // rax
int v5; // er8
int v6; // er11
int v7; // er10
int v8; // er9
int v9; // edi

v0 = memory_region(129LL);
v1 = (_BYTE *)(v0 + (int)memory_region_length(129LL) / 2);
memory_set_opcode_base(0LL, v1);
v2 = v1;
for ( i = 0LL; i != 0x4000; ++i )
{
v5 = *(unsigned __int8 *)(v0 + i);
v6 = (8 * (_BYTE)v5) & 0x10;
v7 = (16 * *(_BYTE *)(v0 + i)) & 0x40;
v8 = (v5 >> 3) & 2;
v9 = (v5 >> 4) & 4;
if ( (i & 0x1000) != 0 )
{
result = v9 | v8 | v7 | v6 | v5 & 0x28 | (v5 >> 7) | (unsigned int)(v5 << 7);
if ( (i & 4) == 0 )
{
result = (unsigned int)result ^ 0xFFFFFF81;
*v2 = result;
goto LABEL_4;
}
}
else
{
result = v9 | v8 | v6 | v7 | v5 & 0xFFFFFFA9 ^ 0xFFFFFF81;
}
*v2 = result;
LABEL_4:
++v2;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rbx
_BYTE *v1; // rbp
_BYTE *v2; // rsi
__int64 i; // rcx
__int64 result; // rax
int v5; // er8
int v6; // er11
int v7; // er10
int v8; // er9
int v9; // edi

v0 = memory_region(129LL);
v1 = (_BYTE *)(v0 + (int)memory_region_length(129LL) / 2);
memory_set_opcode_base(0LL, v1);
v2 = v1;
for ( i = 0LL; i != 0x4000; ++i )
{
v5 = *(unsigned __int8 *)(v0 + i);
v6 = (8 * (_BYTE)v5) & 0x10;
v7 = (16 * *(_BYTE *)(v0 + i)) & 0x40;
v8 = (v5 >> 3) & 2;
v9 = (v5 >> 4) & 4;
if ( (i & 0x1000) != 0 )
{
result = v9 | v8 | v7 | v6 | v5 & 0x28 | (v5 >> 7) | (unsigned int)(v5 << 7);
if ( (i & 4) == 0 )
{
result = (unsigned int)result ^ 0xFFFFFF81;
*v2 = result;
goto LABEL_4;
}
}
else
{
result = v9 | v8 | v6 | v7 | v5 & 0xFFFFFFA9 ^ 0xFFFFFF81;
}
*v2 = result;
LABEL_4:
++v2;
}
return result;
}

original_code:
static void treahunt_decode(void)
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int data;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0; A < 0x4000; A++)
 {
  data = rom[A];
  if (A & 0x1000)
  {
   rom[A+diff] =
     ((data & 0x01) << 7) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4) |
     ((data & 0x80) >> 7);
   if ((A & 0x04) == 0)
    rom[A+diff] ^= 0x81;
  }
  else
  {
   rom[A+diff] =
     (~data & 0x81) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4);
  }
 }
}

canonical_original_code:
static void treahunt_decode()
{
 int A;
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 int data;
 memory_set_opcode_base(0,rom+diff);
 for (A = 0; A < 0x4000; A++)
 {
  data = rom[A];
  if (A & 0x1000)
  {
   rom[A+diff] =
     ((data & 0x01) << 7) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4) |
     ((data & 0x80) >> 7);
   if ((A & 0x04) == 0)
    rom[A+diff] ^= 0x81;
  }
  else
  {
   rom[A+diff] =
     (~data & 0x81) |
     ((data & 0x02) << 3) |
     ((data & 0x04) << 4) |
      (data & 0x28) |
     ((data & 0x10) >> 3) |
     ((data & 0x40) >> 4);
  }
 }
}

variable_types: A int

variable_types:
rom
unsigned char *

variable_types: diff int

variable_types: data int


decompiled_code:
__int64 init_treahunt()
{
timer_rate = 128;
return treahunt_decode();
}

canonical_decompiled_code:
__int64 func9()
{
timer_rate = 128;
return func8();
}

original_code:
static void init_treahunt(void)
{
 timer_rate = 128;
 treahunt_decode();
}

canonical_original_code:
static void init_treahunt()
{
 timer_rate = 128;
 treahunt_decode();
}


decompiled_code:
__int64 timer_r()
{
return (unsigned int)((int)cpu_gettotalcycles() / timer_rate);
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)((int)cpu_gettotalcycles() / timer_rate);
}

original_code:
static data_t timer_r(offs_t offset)
{
 return cpu_gettotalcycles() / timer_rate;
}

canonical_original_code:
static unsigned int timer_r(unsigned int offset)
{
 return cpu_gettotalcycles() / timer_rate;
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
unsigned __int64 __fastcall espial_attributeram_w(unsigned int a1, int a2)
{
_BYTE *v2; // rdi
unsigned __int64 result; // rax

v2 = (_BYTE *)(espial_attributeram + a1);
result = (unsigned __int8)*v2;
if ( (_DWORD)result != a2 )
{
*v2 = a2;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned int a1, int a2)
{
_BYTE *v2; // rdi
unsigned __int64 result; // rax

v2 = (_BYTE *)(espial_attributeram + a1);
result = (unsigned __int8)*v2;
if ( (_DWORD)result != a2 )
{
*v2 = a2;
result = (unsigned __int64)memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void espial_attributeram_w(offs_t offset,data_t data)
{
 if (espial_attributeram[offset] != data)
 {
  espial_attributeram[offset] = data;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void espial_attributeram_w(unsigned int offset, unsigned int data)
{
 if (espial_attributeram[offset] != data)
 {
  espial_attributeram[offset] = data;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
data
unsigned int


decompiled_code:
__int64 espial_init_machine()
{
return interrupt_enable_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return interrupt_enable_w(0LL, 0LL);
}

original_code:
void espial_init_machine(void)
{
 interrupt_enable_w(0, 0);
}

canonical_original_code:
void espial_init_machine()
{
 interrupt_enable_w(0, 0);
}


decompiled_code:
__int64 __fastcall zodiac_master_interrupt_enable_w(__int64 a1, int a2)
{
return interrupt_enable_w(a1, a2 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return interrupt_enable_w(a1, a2 ^ 1u);
}

original_code:
void zodiac_master_interrupt_enable_w(offs_t offset,data_t data)
{
 interrupt_enable_w(offset, data ^ 1);
}

canonical_original_code:
void zodiac_master_interrupt_enable_w(unsigned int offset, unsigned int data)
{
 interrupt_enable_w(offset, data ^ 1);
}