decompiled_code:
__int64 spy_interrupt()
{
int v0; // edx
__int64 result; // rax

if ( !(unsigned int)K052109_is_IRQ_enabled() )
return ignore_interrupt();
v0 = cpu_getiloops();
result = 2LL;
if ( !v0 )
result = interrupt();
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // edx
__int64 result; // rax

if ( !(unsigned int)K052109_is_IRQ_enabled() )
return ignore_interrupt();
v0 = cpu_getiloops();
result = 2LL;
if ( !v0 )
result = interrupt();
return result;
}

original_code:
static int spy_interrupt(void)
{
 if (K052109_is_IRQ_enabled())
 {
  if (cpu_getiloops()) return 2;
  else return interrupt();
 }
 else return ignore_interrupt();
}

canonical_original_code:
static int spy_interrupt()
{
 if (K052109_is_IRQ_enabled())
 {
  if (cpu_getiloops()) return 2;
  else return interrupt();
 }
 else return ignore_interrupt();
}


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = K052109_set_RMRD_line((a2 >> 2) & 1);
rambank = a2 & 0x10;
return result;
}

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
result = K052109_set_RMRD_line((a2 >> 2) & 1);
rambank = a2 & 0x10;
return result;
}

original_code:
static void spy_3f90_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x04) ? 1 : 0);
 rambank = data & 0x10;
}

canonical_original_code:
static void spy_3f90_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x04) ? 1 : 0);
 rambank = data & 0x10;
}


decompiled_code:
__int64 __fastcall spy_bankedram1_r(unsigned int a1)
{
__int64 result; // rax

if ( rambank )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

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

if ( rambank )
result = paletteram_r();
else
result = *(unsigned __int8 *)(ram + a1);
return result;
}

original_code:
static data_t spy_bankedram1_r(offs_t offset)
{
 if (!rambank) return ram[offset];
 else return paletteram_r(offset);
}

canonical_original_code:
static unsigned int spy_bankedram1_r(unsigned int offset)
{
 if (!rambank) return ram[offset];
 else return paletteram_r(offset);
}

return_type: unsigned int


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

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

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

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

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

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

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

*a3 = (*a2 >> 4) & 3;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

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

*a3 = (*a2 >> 4) & 3;
result = sprite_colorbase + (*a2 & 0xFu);
*a2 = result;
return result;
}

original_code:
static void sprite_callback(int *code,int *color,int *priority,int *shadow)
{
 *priority = (*color & 0x30) >> 4;
 *color = sprite_colorbase + (*color & 0x0f);
}

canonical_original_code:
static void sprite_callback(int *code, int *color, int *priority, int *shadow)
{
 *priority = (*color & 0x30) >> 4;
 *color = sprite_colorbase + (*color & 0x0f);
}

variable_types:
priority
int *

variable_types:
shadow
int *


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

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

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

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


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

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

variable_types: v int


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

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


irqhandler

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

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

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

variable_types: linestate int


original_code:
static void sound_bank_w(offs_t offset,data_t data)
{
 unsigned char *rom;
 int bank_A,bank_B;
 rom = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 0) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(0,rom + bank_A,rom + bank_B);
 rom = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 6) & 0x03);
 K007232_bankswitch(1,rom + bank_A,rom + bank_B);
}

canonical_original_code:
static void sound_bank_w(unsigned int offset, unsigned int data)
{
 unsigned char *rom;
 int bank_A; int bank_B;
 rom = memory_region(REGION_SOUND1);
 bank_A = 0x20000 * ((data >> 0) & 0x03);
 bank_B = 0x20000 * ((data >> 2) & 0x03);
 K007232_bankswitch(0,rom + bank_A,rom + bank_B);
 rom = memory_region(REGION_SOUND2);
 bank_A = 0x20000 * ((data >> 4) & 0x03);
 bank_B = 0x20000 * ((data >> 6) & 0x03);
 K007232_bankswitch(1,rom + bank_A,rom + bank_B);
}

variable_types:
rom
unsigned char *


decompiled_code:
void *__fastcall bankswitch_w(__int64 a1, char a2)
{
__int64 v2; // rbp
int v3; // ebx
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
if ( (a2 & 1) == 0 )
usrintf_showmessage("bankswitch RAM bank 0");
if ( (a2 & 0x10) != 0 )
v3 = (a2 & 6) + 32;
else
v3 = (a2 & 0xE) + 16;
cpu_bankbase[1] = v2 + (v3 << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func14(__int64 a1, char a2)
{
__int64 v2; // rbp
int v3; // ebx
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
if ( (a2 & 1) == 0 )
usrintf_showmessage("bankswitch RAM bank 0");
if ( (a2 & 0x10) != 0 )
v3 = (a2 & 6) + 32;
else
v3 = (a2 & 0xE) + 16;
cpu_bankbase[1] = v2 + (v3 << 12);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int offs;
if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
 if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
 else offs = 0x10000 + (data & 0x0e) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&rom[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int offs;
if ((data & 1) == 0) usrintf_showmessage("bankswitch RAM bank 0");
 if (data & 0x10) offs = 0x20000 + (data & 0x06) * 0x1000;
 else offs = 0x10000 + (data & 0x0e) * 0x1000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&rom[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: offs int


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

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

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

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


decompiled_code:
void zerozone_vh_stop()
{
free(video_dirty);
}

canonical_decompiled_code:
void func2()
{
free(video_dirty);
}

original_code:
void zerozone_vh_stop(void)
{
 free(video_dirty);
}


decompiled_code:
__int64 zerozone_vh_start()
{
size_t v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = videoram_size >> 1;
v1 = malloc(videoram_size >> 1);
video_dirty = v1;
if ( v1 )
{
memset(v1, 1, v0);
result = 0LL;
}
else
{
zerozone_vh_stop();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
size_t v0; // rbx
void *v1; // rax
__int64 result; // rax

v0 = videoram_size >> 1;
v1 = malloc(videoram_size >> 1);
video_dirty = v1;
if ( v1 )
{
memset(v1, 1, v0);
result = 0LL;
}
else
{
func2();
result = 1LL;
}
return result;
}

original_code:
int zerozone_vh_start(void)
{
 video_dirty = (unsigned char*)malloc(videoram_size/2);
 if (!video_dirty)
 {
  zerozone_vh_stop();
  return 1;
 }
 memset(video_dirty,1,videoram_size/2);
 return 0;
}

canonical_original_code:
int zerozone_vh_start()
{
 video_dirty = (unsigned char *)malloc(videoram_size/2);
 if (!video_dirty)
 {
  zerozone_vh_stop();
  return 1;
 }
 memset(video_dirty,1,videoram_size/2);
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall zerozone_sound_w(__int64 a1, __int16 a2)
{
soundlatch_w(a1, HIBYTE(a2));
return cpu_cause_interrupt(1LL, 255LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int16 a2)
{
soundlatch_w(a1, HIBYTE(a2));
return cpu_cause_interrupt(1LL, 255LL);
}

original_code:
void zerozone_sound_w(offs_t offset,data_t data)
{
 soundlatch_w (offset, (data >> 8) & 0xff);
 cpu_cause_interrupt (1, 0xff);
}

canonical_original_code:
void zerozone_sound_w(unsigned int offset, unsigned int data)
{
 soundlatch_w (offset, (data >> 8) & 0xff);
 cpu_cause_interrupt (1, 0xff);
}


decompiled_code:
__int64 __fastcall zerozone_input_r(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax

if ( a1 == 8 )
return (unsigned int)readinputport(4LL) << 8;
if ( a1 > 8 )
{
result = 0LL;
if ( a1 == 10 )
result = readinputport(3LL);
}
else if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
result = v1 | ((unsigned int)readinputport(2LL) << 8);
}
else
{
result = 0LL;
}
}
else
{
result = readinputport(0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v1; // ebx
__int64 result; // rax

if ( a1 == 8 )
return (unsigned int)readinputport(4LL) << 8;
if ( a1 > 8 )
{
result = 0LL;
if ( a1 == 10 )
result = readinputport(3LL);
}
else if ( a1 )
{
if ( a1 == 2 )
{
v1 = readinputport(1LL);
result = v1 | ((unsigned int)readinputport(2LL) << 8);
}
else
{
result = 0LL;
}
}
else
{
result = readinputport(0LL);
}
return result;
}

original_code:
static data_t zerozone_input_r(offs_t offset)
{
 switch (offset)
 {
  case 0x00:
   return readinputport(0);
  case 0x02:
   return (readinputport(1) | (readinputport(2) << 8));
  case 0x08:
   return (readinputport(4) << 8);
  case 0x0a:
   return readinputport(3);
 }
 return 0x00;
}

canonical_original_code:
static unsigned int zerozone_input_r(unsigned int offset)
{
 switch (offset)
 {
  case 0x00:
   return readinputport(0);
  case 0x02:
   return (readinputport(1) | (readinputport(2) << 8));
  case 0x08:
   return (readinputport(4) << 8);
  case 0x0a:
   return readinputport(3);
 }
 return 0x00;
}


decompiled_code:
void *__fastcall zerozone_update_palette(__int64 a1, __int64 a2, __int64 a3, _WORD *a4)
{
unsigned __int64 v4; // rsi
__int64 v5; // rax
char *v6; // r8
__int64 v7; // r9
unsigned int i; // eax
int v9; // ecx
char *v10; // rsi
void *result; // rax
__int64 v12; // [rsp+0h] [rbp-28h] BYREF
__int64 v13; // [rsp+8h] [rbp-20h]
__int64 v14; // [rsp+10h] [rbp-18h]
__int64 v15; // [rsp+18h] [rbp-10h]
char v16; // [rsp+20h] [rbp-8h] BYREF

v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
if ( videoram_size )
{
a1 = *(_QWORD *)(*(_QWORD *)(Machine + 512LL) + 32LL);
a4 = (_WORD *)zerozone_videoram;
v4 = zerozone_videoram + ((videoram_size - 1LL) & 0xFFFFFFFFFFFFFFFELL) + 2;
do
{
v5 = (*a4 >> 12) & 0xF;
a3 = *(unsigned int *)(a1 + 4LL * (*a4 & 0xFFF));
*((_WORD *)&v12 + v5) |= a3;
++a4;
}
while ( a4 != (_WORD *)v4 );
}
v6 = (char *)&v12;
v7 = 0LL;
do
{
v10 = v6;
if ( *(_WORD *)v6 )
{
*(_BYTE *)(palette_used_colors + v7) = 7;
LODWORD(a3) = v7 + 1;
for ( i = 1; i != 16; ++i )
{
v9 = *(unsigned __int16 *)v6;
if ( _bittest(&v9, i) )
{
a4 = (_WORD *)(int)a3;
a1 = palette_used_colors;
*(_BYTE *)(palette_used_colors + (int)a3) = 3;
}
else
{
a4 = (_WORD *)(int)a3;
a1 = palette_used_colors;
*(_BYTE *)(palette_used_colors + (int)a3) = 0;
}
a3 = (unsigned int)(a3 + 1);
}
}
else
{
v10 = (char *)(palette_used_colors + v7);
*(_QWORD *)v10 = 0LL;
*((_QWORD *)v10 + 1) = 0LL;
}
v6 += 2;
v7 += 16LL;
}
while ( v6 != &v16 );
result = (void *)palette_recalc(a1, v10, a3, a4, v6, v7, v12, v13, v14, v15);
if ( result )
result = memset(video_dirty, 1, videoram_size >> 1);
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, __int64 a2, __int64 a3, _WORD *a4)
{
unsigned __int64 v4; // rsi
__int64 v5; // rax
char *v6; // r8
__int64 v7; // r9
unsigned int i; // eax
int v9; // ecx
char *v10; // rsi
void *result; // rax
__int64 v12; // [rsp+0h] [rbp-28h] BYREF
__int64 v13; // [rsp+8h] [rbp-20h]
__int64 v14; // [rsp+10h] [rbp-18h]
__int64 v15; // [rsp+18h] [rbp-10h]
char v16; // [rsp+20h] [rbp-8h] BYREF

v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
if ( videoram_size )
{
a1 = *(_QWORD *)(*(_QWORD *)(Machine + 512LL) + 32LL);
a4 = (_WORD *)zerozone_videoram;
v4 = zerozone_videoram + ((videoram_size - 1LL) & 0xFFFFFFFFFFFFFFFELL) + 2;
do
{
v5 = (*a4 >> 12) & 0xF;
a3 = *(unsigned int *)(a1 + 4LL * (*a4 & 0xFFF));
*((_WORD *)&v12 + v5) |= a3;
++a4;
}
while ( a4 != (_WORD *)v4 );
}
v6 = (char *)&v12;
v7 = 0LL;
do
{
v10 = v6;
if ( *(_WORD *)v6 )
{
*(_BYTE *)(palette_used_colors + v7) = 7;
LODWORD(a3) = v7 + 1;
for ( i = 1; i != 16; ++i )
{
v9 = *(unsigned __int16 *)v6;
if ( _bittest(&v9, i) )
{
a4 = (_WORD *)(int)a3;
a1 = palette_used_colors;
*(_BYTE *)(palette_used_colors + (int)a3) = 3;
}
else
{
a4 = (_WORD *)(int)a3;
a1 = palette_used_colors;
*(_BYTE *)(palette_used_colors + (int)a3) = 0;
}
a3 = (unsigned int)(a3 + 1);
}
}
else
{
v10 = (char *)(palette_used_colors + v7);
*(_QWORD *)v10 = 0LL;
*((_QWORD *)v10 + 1) = 0LL;
}
v6 += 2;
v7 += 16LL;
}
while ( v6 != &v16 );
result = (void *)palette_recalc(a1, v10, a3, a4, v6, v7, v12, v13, v14, v15);
if ( result )
result = memset(video_dirty, 1, videoram_size >> 1);
return result;
}

original_code:
void zerozone_update_palette (void)
{
 unsigned short palette_map[16];
 int i;
 memset (palette_map, 0, sizeof (palette_map));
 for (i = 0; i < videoram_size; i += 2)
 {
  int tile, color;
  tile = (*(UINT16 *)(&zerozone_videoram[i])) & 0xfff;
  color = ((*(UINT16 *)(&zerozone_videoram[i])) & 0xf000) >> 12;
  palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
 }
 for (i = 0;i < 16;i++)
 {
  int usage = palette_map[i];
  int j;
  if (usage)
  {
   palette_used_colors[i * 16 + 0] = (4|(1|2));
   for (j = 1; j < 16; j++)
    if (palette_map[i] & (1 << j))
     palette_used_colors[i * 16 + j] = (1|2);
    else
     palette_used_colors[i * 16 + j] = 0;
  }
  else
   memset(&palette_used_colors[i * 16],0,16);
 }
 if (palette_recalc ())
  memset(video_dirty,1,videoram_size/2);
}

canonical_original_code:
void zerozone_update_palette()
{
 unsigned short palette_map[16];
 int i;
 memset (palette_map, 0, sizeof (palette_map));
 for (i = 0; i < videoram_size; i += 2)
 {
  int tile; int color;
  tile = (*(unsigned short *)(&zerozone_videoram[i])) & 0xfff;
  color = ((*(unsigned short *)(&zerozone_videoram[i])) & 0xf000) >> 12;
  palette_map[color] |= Machine->gfx[0]->pen_usage[tile];
 }
 for (i = 0;i < 16;i++)
 {
  int usage = palette_map[i];
  int j;
  if (usage)
  {
   palette_used_colors[i * 16 + 0] = (4|(1|2));
   for (j = 1; j < 16; j++)
    if (palette_map[i] & (1 << j))
     palette_used_colors[i * 16 + j] = (1|2);
    else
     palette_used_colors[i * 16 + j] = 0;
  }
  else
   memset(&palette_used_colors[i * 16],0,16);
 }
 if (palette_recalc ())
  memset(video_dirty,1,videoram_size/2);
}

variable_types: i int

variable_types: tile int

variable_types: color int

variable_types: usage int

variable_types: j int


decompiled_code:
void __fastcall nova2001_scroll_x_w(__int64 a1, int a2)
{
nova2001_xscroll = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
nova2001_xscroll = a2;
}

original_code:
void nova2001_scroll_x_w(offs_t offset,data_t data)
{
 nova2001_xscroll = data;
}

canonical_original_code:
void nova2001_scroll_x_w(unsigned int offset, unsigned int data)
{
 nova2001_xscroll = data;
}

variable_types:
offset
unsigned int


decompiled_code:
void __fastcall nova2001_scroll_y_w(__int64 a1, int a2)
{
nova2001_yscroll = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
nova2001_yscroll = a2;
}

original_code:
void nova2001_scroll_y_w(offs_t offset,data_t data)
{
 nova2001_yscroll = data;
}

canonical_original_code:
void nova2001_scroll_y_w(unsigned int offset, unsigned int data)
{
 nova2001_yscroll = data;
}

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall nova2001_flipscreen_w(__int64 a1, unsigned __int8 a2)
{
void *result; // rax

result = (void *)((a2 ^ 1) & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = (unsigned __int8)result;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = (void *)((a2 ^ 1) & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = (unsigned __int8)result;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void nova2001_flipscreen_w(offs_t offset,data_t data)
{
 if ((~data & 0x01) != flipscreen)
 {
  flipscreen = ~data & 0x01;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void nova2001_flipscreen_w(unsigned int offset, unsigned int data)
{
 if ((~data & 0x01) != flipscreen)
 {
  flipscreen = ~data & 0x01;
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
int *__fastcall nova2001_vh_screenrefresh(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // esi
int v5; // ecx
unsigned __int64 v6; // rbx
unsigned __int8 v7; // al
__int64 v8; // rsi
__int64 v9; // rdi
__int64 v10; // r8
__int64 v11; // r9
int *result; // rax
int v13; // ebx
__int64 v14; // rbp
int v15; // ecx
int v16; // esi
int v17; // [rsp+8h] [rbp-30h] BYREF
int v18[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
v4 = v2 % 32;
v5 = v2 / 32;
if ( flipscreen )
{
v4 = 31 - v2 % 32;
v5 = 31 - v2 / 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
if ( flipscreen )
{
v17 = nova2001_xscroll;
v18[0] = nova2001_yscroll;
}
else
{
v17 = -nova2001_xscroll;
v18[0] = -nova2001_yscroll;
}
copyscrollbitmap(a1, tmpbitmap, 1LL, &v17, 1LL, v18, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v6 = 0LL;
do
{
v7 = *(_BYTE *)(spriteram + v6);
if ( (v7 & 0x40) != 0 )
{
v8 = *(unsigned __int8 *)(spriteram + v6 + 1);
v9 = *(unsigned __int8 *)(spriteram + v6 + 2);
v10 = *(_BYTE *)(spriteram + v6 + 3) & 0x10;
v11 = *(_BYTE *)(spriteram + v6 + 3) & 0x20;
if ( flipscreen )
{
v8 = (unsigned int)(240 - v8);
v9 = (unsigned int)(240 - v9);
v10 = (_DWORD)v10 == 0;
v11 = (_DWORD)v11 == 0;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((v7 >> 7) + 2) & 7) + 512),
v7 & 0x3F,
*(_BYTE *)(spriteram + v6 + 3) & 0xF,
v10,
v11,
v8,
v9,
Machine + 776LL,
2LL,
0LL);
}
v6 += 32LL;
}
while ( spriteram_size > v6 );
}
result = &nova2001_videoram_size;
v13 = nova2001_videoram_size - 1;
if ( nova2001_videoram_size - 1 >= 0 )
{
v14 = v13;
do
{
v15 = v13 % 32;
v16 = v13 / 32;
if ( flipscreen )
{
v15 = 31 - v13 % 32;
v16 = 31 - v13 / 32;
}
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(nova2001_videoram + v14),
*(_BYTE *)(nova2001_colorram + v14) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v15),
(unsigned int)(8 * v16),
Machine + 776LL,
2LL,
0LL);
--v14;
--v13;
}
while ( v13 >= 0 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func4(__int64 a1)
{
int v2; // ebx
__int64 v3; // rbp
int v4; // esi
int v5; // ecx
unsigned __int64 v6; // rbx
unsigned __int8 v7; // al
__int64 v8; // rsi
__int64 v9; // rdi
__int64 v10; // r8
__int64 v11; // r9
int *result; // rax
int v13; // ebx
__int64 v14; // rbp
int v15; // ecx
int v16; // esi
int v17; // [rsp+8h] [rbp-30h] BYREF
int v18[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v3 = v2;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
v4 = v2 % 32;
v5 = v2 / 32;
if ( flipscreen )
{
v4 = 31 - v2 % 32;
v5 = 31 - v2 / 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v4),
(unsigned int)(8 * v5),
0LL,
0LL,
0LL);
}
--v3;
--v2;
}
while ( v2 >= 0 );
}
if ( flipscreen )
{
v17 = nova2001_xscroll;
v18[0] = nova2001_yscroll;
}
else
{
v17 = -nova2001_xscroll;
v18[0] = -nova2001_yscroll;
}
copyscrollbitmap(a1, tmpbitmap, 1LL, &v17, 1LL, v18, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v6 = 0LL;
do
{
v7 = *(_BYTE *)(spriteram + v6);
if ( (v7 & 0x40) != 0 )
{
v8 = *(unsigned __int8 *)(spriteram + v6 + 1);
v9 = *(unsigned __int8 *)(spriteram + v6 + 2);
v10 = *(_BYTE *)(spriteram + v6 + 3) & 0x10;
v11 = *(_BYTE *)(spriteram + v6 + 3) & 0x20;
if ( flipscreen )
{
v8 = (unsigned int)(240 - v8);
v9 = (unsigned int)(240 - v9);
v10 = (_DWORD)v10 == 0;
v11 = (_DWORD)v11 == 0;
}
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (((v7 >> 7) + 2) & 7) + 512),
v7 & 0x3F,
*(_BYTE *)(spriteram + v6 + 3) & 0xF,
v10,
v11,
v8,
v9,
Machine + 776LL,
2LL,
0LL);
}
v6 += 32LL;
}
while ( spriteram_size > v6 );
}
result = &nova2001_videoram_size;
v13 = nova2001_videoram_size - 1;
if ( nova2001_videoram_size - 1 >= 0 )
{
v14 = v13;
do
{
v15 = v13 % 32;
v16 = v13 / 32;
if ( flipscreen )
{
v15 = 31 - v13 % 32;
v16 = 31 - v13 / 32;
}
result = (int *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(nova2001_videoram + v14),
*(_BYTE *)(nova2001_colorram + v14) & 0xF,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v15),
(unsigned int)(8 * v16),
Machine + 776LL,
2LL,
0LL);
--v14;
--v13;
}
while ( v13 >= 0 );
}
return result;
}

original_code:
void nova2001_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs],
     colorram[offs] & 0x0f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx,scrolly;
  if (flipscreen)
  {
   scrollx = nova2001_xscroll;
   scrolly = nova2001_yscroll;
  }
  else
  {
   scrollx = -nova2001_xscroll;
   scrolly = -nova2001_yscroll;
  }
     copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 32)
 {
  if (spriteram[offs+0] & 0x40)
  {
   int sx,sy,flipx,flipy;
   sx = spriteram[offs+1];
   sy = spriteram[offs+2];
   flipx = spriteram[offs+3] & 0x10;
   flipy = spriteram[offs+3] & 0x20;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2 + ((spriteram[offs+0] & 0x80) >> 7)],
     spriteram[offs+0] & 0x3f,
     spriteram[offs+3] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = nova2001_videoram_size - 1;offs >= 0;offs--)
 {
  int sx,sy;
  sx = offs % 32;
  sy = offs / 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    nova2001_videoram[offs],
    nova2001_colorram[offs] & 0x0f,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void nova2001_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[1],
     videoram[offs],
     colorram[offs] & 0x0f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scrollx; int scrolly;
  if (flipscreen)
  {
   scrollx = nova2001_xscroll;
   scrolly = nova2001_yscroll;
  }
  else
  {
   scrollx = -nova2001_xscroll;
   scrolly = -nova2001_yscroll;
  }
     copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0;offs < spriteram_size;offs += 32)
 {
  if (spriteram[offs+0] & 0x40)
  {
   int sx; int sy; int flipx; int flipy;
   sx = spriteram[offs+1];
   sy = spriteram[offs+2];
   flipx = spriteram[offs+3] & 0x10;
   flipy = spriteram[offs+3] & 0x20;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2 + ((spriteram[offs+0] & 0x80) >> 7)],
     spriteram[offs+0] & 0x3f,
     spriteram[offs+3] & 0x0f,
     flipx,flipy,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
 for (offs = nova2001_videoram_size - 1;offs >= 0;offs--)
 {
  int sx; int sy;
  sx = offs % 32;
  sy = offs / 32;
  if (flipscreen)
  {
   sx = 31 - sx;
   sy = 31 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    nova2001_videoram[offs],
    nova2001_colorram[offs] & 0x0f,
    flipscreen,flipscreen,
    8*sx,8*sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: sx int

variable_types: sy int

variable_types: scrollx int

variable_types: scrolly int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
void *__fastcall funkybee_gfx_bank_w(__int64 a1, int a2)
{
void *result; // rax

result = (void *)(gfx_bank & 1);
if ( (_DWORD)result != a2 )
{
gfx_bank = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, int a2)
{
void *result; // rax

result = (void *)(gfx_bank & 1);
if ( (_DWORD)result != a2 )
{
gfx_bank = a2 & 1;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void funkybee_gfx_bank_w(offs_t offset,data_t data)
{
 if (data != (gfx_bank & 0x01))
 {
  gfx_bank = data & 0x01;
  memset(dirtybuffer, 1, videoram_size);
 }
}

canonical_original_code:
void funkybee_gfx_bank_w(unsigned int offset, unsigned int data)
{
 if (data != (gfx_bank & 0x01))
 {
  gfx_bank = data & 0x01;
  memset(dirtybuffer, 1, videoram_size);
 }
}


decompiled_code:
__int64 __fastcall funkybee_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax

draw_chars(tmpbitmap, a1);
for ( i = 7695LL; i != 7679; --i )
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (gfx_bank + 2) + 512),
((int)*(unsigned __int8 *)(videoram + i) >> 2) | (32 * *(_BYTE *)(videoram + i)) & 0x40u,
*(unsigned __int8 *)(colorram + i + 16),
0LL,
*(_BYTE *)(videoram + i) & 1,
*(unsigned __int8 *)(videoram + i + 16),
224 - (unsigned int)*(unsigned __int8 *)(colorram + i),
Machine + 776LL,
2LL,
0LL);
for ( j = 7199LL; j != 7167; --j )
{
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + j),
*(_BYTE *)(colorram + 7952LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7952LL),
(unsigned int)(8 * j - 57344),
0LL,
2LL,
0LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + j + 256),
*(_BYTE *)(colorram + 7953LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7953LL),
(unsigned int)(8 * j - 57344),
0LL,
2LL,
0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 i; // rbx
__int64 j; // rbx
__int64 result; // rax

func2(tmpbitmap, a1);
for ( i = 7695LL; i != 7679; --i )
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * (gfx_bank + 2) + 512),
((int)*(unsigned __int8 *)(videoram + i) >> 2) | (32 * *(_BYTE *)(videoram + i)) & 0x40u,
*(unsigned __int8 *)(colorram + i + 16),
0LL,
*(_BYTE *)(videoram + i) & 1,
*(unsigned __int8 *)(videoram + i + 16),
224 - (unsigned int)*(unsigned __int8 *)(colorram + i),
Machine + 776LL,
2LL,
0LL);
for ( j = 7199LL; j != 7167; --j )
{
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + j),
*(_BYTE *)(colorram + 7952LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7952LL),
(unsigned int)(8 * j - 57344),
0LL,
2LL,
0LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + j + 256),
*(_BYTE *)(colorram + 7953LL) & 3,
0LL,
0LL,
*(unsigned __int8 *)(videoram + 7953LL),
(unsigned int)(8 * j - 57344),
0LL,
2LL,
0LL);
}
return result;
}

original_code:
void funkybee_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 draw_chars(tmpbitmap, bitmap);
 for (offs = 0x0f; offs >= 0; offs--)
 {
  int sx,sy,code,col,flipy,offs2;
  offs2 = 0x1e00 + offs;
  code = videoram[offs2];
  sx = videoram[offs2 + 0x10];
  sy = 224 - colorram[offs2];
  col = colorram[offs2 + 0x10];
  flipy = code & 0x01;
  drawgfx(bitmap,Machine->gfx[2+gfx_bank],
    (code >> 2) | ((code & 2) << 5),
    col,
    0,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = 0x1f;offs >= 0;offs--)
 {
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1c00],
    colorram[0x1f10] & 0x03,
    0,0,
    videoram[0x1f10],8*offs,
    0,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1d00],
    colorram[0x1f11] & 0x03,
    0,0,
    videoram[0x1f11],8*offs,
    0,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void funkybee_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 draw_chars(tmpbitmap, bitmap);
 for (offs = 0x0f; offs >= 0; offs--)
 {
  int sx; int sy; int code; int col; int flipy; int offs2;
  offs2 = 0x1e00 + offs;
  code = videoram[offs2];
  sx = videoram[offs2 + 0x10];
  sy = 224 - colorram[offs2];
  col = colorram[offs2 + 0x10];
  flipy = code & 0x01;
  drawgfx(bitmap,Machine->gfx[2+gfx_bank],
    (code >> 2) | ((code & 2) << 5),
    col,
    0,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = 0x1f;offs >= 0;offs--)
 {
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1c00],
    colorram[0x1f10] & 0x03,
    0,0,
    videoram[0x1f10],8*offs,
    0,TRANSPARENCY_PEN,0);
  drawgfx(bitmap,Machine->gfx[gfx_bank],
    videoram[offs+0x1d00],
    colorram[0x1f11] & 0x03,
    0,0,
    videoram[0x1f11],8*offs,
    0,TRANSPARENCY_PEN,0);
 }
}

variable_types: code int

variable_types: col int

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


decompiled_code:
__int64 __fastcall funkybee_input_port_0_r(unsigned int a1)
{
watchdog_reset_r(0LL);
return input_port_0_r(a1);
}

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

original_code:
static data_t funkybee_input_port_0_r(offs_t offset)
{
 watchdog_reset_r(0);
 return input_port_0_r(offset);
}

canonical_original_code:
static unsigned int funkybee_input_port_0_r(unsigned int offset)
{
 watchdog_reset_r(0);
 return input_port_0_r(offset);
}


decompiled_code:
__int64 __fastcall draw_chars(__int64 a1, __int64 a2)
{
unsigned int i; // er15
__int64 v3; // rbx
__int64 v4; // rbp
unsigned __int8 *v5; // rsi
int *v6; // rax
char v9[112]; // [rsp+10h] [rbp-B8h] BYREF
int v10[18]; // [rsp+80h] [rbp-48h] BYREF

for ( i = 248; i != -8; i -= 8 )
{
v3 = (int)((32 * i) | 0x1F);
v4 = 248LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 3,
0LL,
0LL,
v4,
i,
0LL,
0LL,
0LL);
}
--v3;
v4 = (unsigned int)(v4 - 8);
}
while ( (_DWORD)v4 != -8 );
}
v5 = (unsigned __int8 *)funkyb_row_scroll;
v6 = (int *)v9;
do
*v6++ = -*v5;
while ( v6 != v10 );
v10[0] = 0;
v10[1] = 0;
v10[2] = 0;
v10[3] = 0;
return copyscrollbitmap(a2, a1, 32LL, v9, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int i; // er15
__int64 v3; // rbx
__int64 v4; // rbp
unsigned __int8 *v5; // rsi
int *v6; // rax
char v9[112]; // [rsp+10h] [rbp-B8h] BYREF
int v10[18]; // [rsp+80h] [rbp-48h] BYREF

for ( i = 248; i != -8; i -= 8 )
{
v3 = (int)((32 * i) | 0x1F);
v4 = 248LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v3) )
{
*(_BYTE *)(dirtybuffer + v3) = 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 8LL * gfx_bank + 512),
*(unsigned __int8 *)(videoram + v3),
*(_BYTE *)(colorram + v3) & 3,
0LL,
0LL,
v4,
i,
0LL,
0LL,
0LL);
}
--v3;
v4 = (unsigned int)(v4 - 8);
}
while ( (_DWORD)v4 != -8 );
}
v5 = (unsigned __int8 *)funkyb_row_scroll;
v6 = (int *)v9;
do
*v6++ = -*v5;
while ( v6 != v10 );
v10[0] = 0;
v10[1] = 0;
v10[2] = 0;
v10[3] = 0;
return copyscrollbitmap(a2, a1, 32LL, v9, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
static void draw_chars(struct osd_bitmap *_tmpbitmap, struct osd_bitmap *bitmap)
{
 int sx,sy;
 for (sy = 0x1f;sy >= 0;sy--)
 {
  int offs;
  offs = (sy << 8) | 0x1f;
  for (sx = 0x1f;sx >= 0;sx--,offs--)
  {
   if (dirtybuffer[offs])
   {
    dirtybuffer[offs] = 0;
    drawgfx(_tmpbitmap,Machine->gfx[gfx_bank],
      videoram[offs],
      colorram[offs] & 0x03,
      0,0,
      8*sx,8*sy,
      0,TRANSPARENCY_NONE,0);
   }
  }
 }
 {
  int offs,scroll[32];
  for (offs = 0;offs < 28;offs++)
   scroll[offs] = -*funkyb_row_scroll;
  for (;offs < 32;offs++)
   scroll[offs] = 0;
  copyscrollbitmap(bitmap,_tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

canonical_original_code:
static void draw_chars(struct osd_bitmap *_tmpbitmap, struct osd_bitmap *bitmap)
{
 int sx; int sy;
 for (sy = 0x1f;sy >= 0;sy--)
 {
  int offs;
  offs = (sy << 8) | 0x1f;
  for (sx = 0x1f;sx >= 0;sx--,offs--)
  {
   if (dirtybuffer[offs])
   {
    dirtybuffer[offs] = 0;
    drawgfx(_tmpbitmap,Machine->gfx[gfx_bank],
      videoram[offs],
      colorram[offs] & 0x03,
      0,0,
      8*sx,8*sy,
      0,TRANSPARENCY_NONE,0);
   }
  }
 }
 {
  int offs; int scroll[32];
  for (offs = 0;offs < 28;offs++)
   scroll[offs] = -*funkyb_row_scroll;
  for (;offs < 32;offs++)
   scroll[offs] = 0;
  copyscrollbitmap(bitmap,_tmpbitmap,32,scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
}

variable_types:
bitmap
struct osd_bitmap *

variable_types: offs int

variable_types:
scroll
int [32]


decompiled_code:
__int64 __fastcall astinvad_sh_port_4_w(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port4State_1 ^ (unsigned int)a2;
v3 = a2 & (port4State_1 ^ a2);
v4 = (port4State_1 ^ a2) & ~(_BYTE)a2;
port4State_1 = a2;
if ( (v3 & 1) != 0 )
result = sample_start(0LL, 0LL, 1LL);
if ( (v4 & 1) != 0 )
result = sample_stop(0LL);
if ( (v3 & 2) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v4 & 2) != 0 )
result = sample_stop(1LL);
if ( (v3 & 4) != 0 )
{
sample_start(2LL, 2LL, 0LL);
result = invaders_screen_red_w(1LL);
}
if ( (v4 & 4) != 0 )
{
sample_stop(2LL);
result = invaders_screen_red_w(0LL);
}
if ( (v3 & 8) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v4 & 8) != 0 )
result = sample_stop(3LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port4State_1 ^ (unsigned int)a2;
v3 = a2 & (port4State_1 ^ a2);
v4 = (port4State_1 ^ a2) & ~(_BYTE)a2;
port4State_1 = a2;
if ( (v3 & 1) != 0 )
result = sample_start(0LL, 0LL, 1LL);
if ( (v4 & 1) != 0 )
result = sample_stop(0LL);
if ( (v3 & 2) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v4 & 2) != 0 )
result = sample_stop(1LL);
if ( (v3 & 4) != 0 )
{
sample_start(2LL, 2LL, 0LL);
result = invaders_screen_red_w(1LL);
}
if ( (v4 & 4) != 0 )
{
sample_stop(2LL);
result = invaders_screen_red_w(0LL);
}
if ( (v3 & 8) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v4 & 8) != 0 )
result = sample_stop(3LL);
return result;
}

original_code:
void astinvad_sh_port_4_w(offs_t offset,data_t data)
{
 static int port4State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port4State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port4State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_UFO, SND_UFO, 1 );
 if ( bitsGoneLow & 0x01 ) sample_stop( SND_UFO );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_SHOT, SND_SHOT, 0 );
 if ( bitsGoneLow & 0x02 ) sample_stop( SND_SHOT );
 if ( bitsGoneHigh & 0x04 )
 {
  sample_start( SND_BASEHIT, SND_BASEHIT, 0 );
     invaders_screen_red_w(1);
    }
 if ( bitsGoneLow & 0x04 )
 {
  sample_stop( SND_BASEHIT );
     invaders_screen_red_w(0);
    }
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_INVADERHIT, SND_INVADERHIT, 0 );
 if ( bitsGoneLow & 0x08 ) sample_stop( SND_INVADERHIT );
}

canonical_original_code:
void astinvad_sh_port_4_w(unsigned int offset, unsigned int data)
{
 static int port4State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port4State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port4State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_UFO, SND_UFO, 1 );
 if ( bitsGoneLow & 0x01 ) sample_stop( SND_UFO );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_SHOT, SND_SHOT, 0 );
 if ( bitsGoneLow & 0x02 ) sample_stop( SND_SHOT );
 if ( bitsGoneHigh & 0x04 )
 {
  sample_start( SND_BASEHIT, SND_BASEHIT, 0 );
     invaders_screen_red_w(1);
    }
 if ( bitsGoneLow & 0x04 )
 {
  sample_stop( SND_BASEHIT );
     invaders_screen_red_w(0);
    }
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_INVADERHIT, SND_INVADERHIT, 0 );
 if ( bitsGoneLow & 0x08 ) sample_stop( SND_INVADERHIT );
}

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int


decompiled_code:
__int64 __fastcall astinvad_sh_port_5_w(__int64 a1, int a2)
{
char v2; // r12
char v3; // bp
char v4; // r13
__int64 result; // rax

v2 = port5State_0 ^ a2;
v3 = a2 & (port5State_0 ^ a2);
v4 = (port5State_0 ^ a2) & ~(_BYTE)a2;
port5State_0 = a2;
if ( (v3 & 1) != 0 )
result = sample_start(4LL, 4LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_start(5LL, 5LL, 0LL);
if ( (v3 & 4) != 0 )
result = sample_start(6LL, 6LL, 0LL);
if ( (v3 & 8) != 0 )
result = sample_start(7LL, 7LL, 0LL);
if ( (v3 & 0x10) != 0 )
result = sample_start(8LL, 8LL, 0LL);
if ( (v4 & 0x10) != 0 )
result = sample_stop(8LL);
if ( (v2 & 0x20) != 0 )
result = invaders_flip_screen_w(a2 & 0x20);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
char v2; // r12
char v3; // bp
char v4; // r13
__int64 result; // rax

v2 = port5State_0 ^ a2;
v3 = a2 & (port5State_0 ^ a2);
v4 = (port5State_0 ^ a2) & ~(_BYTE)a2;
port5State_0 = a2;
if ( (v3 & 1) != 0 )
result = sample_start(4LL, 4LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_start(5LL, 5LL, 0LL);
if ( (v3 & 4) != 0 )
result = sample_start(6LL, 6LL, 0LL);
if ( (v3 & 8) != 0 )
result = sample_start(7LL, 7LL, 0LL);
if ( (v3 & 0x10) != 0 )
result = sample_start(8LL, 8LL, 0LL);
if ( (v4 & 0x10) != 0 )
result = sample_stop(8LL);
if ( (v2 & 0x20) != 0 )
result = invaders_flip_screen_w(a2 & 0x20);
return result;
}

original_code:
void astinvad_sh_port_5_w(offs_t offset,data_t data)
{
 static int port5State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port5State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port5State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_FLEET1, SND_FLEET1, 0 );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_FLEET2, SND_FLEET2, 0 );
 if ( bitsGoneHigh & 0x04 ) sample_start( SND_FLEET3, SND_FLEET3, 0 );
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_FLEET4, SND_FLEET4, 0 );
 if ( bitsGoneHigh & 0x10 ) sample_start( SND_UFO2, SND_UFO2, 0 );
 if ( bitsGoneLow & 0x10 ) sample_stop( SND_UFO2 );
 if ( bitsChanged & 0x20 ) invaders_flip_screen_w(data & 0x20);
}

canonical_original_code:
void astinvad_sh_port_5_w(unsigned int offset, unsigned int data)
{
 static int port5State;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port5State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port5State = data;
 if ( bitsGoneHigh & 0x01 ) sample_start( SND_FLEET1, SND_FLEET1, 0 );
 if ( bitsGoneHigh & 0x02 ) sample_start( SND_FLEET2, SND_FLEET2, 0 );
 if ( bitsGoneHigh & 0x04 ) sample_start( SND_FLEET3, SND_FLEET3, 0 );
 if ( bitsGoneHigh & 0x08 ) sample_start( SND_FLEET4, SND_FLEET4, 0 );
 if ( bitsGoneHigh & 0x10 ) sample_start( SND_UFO2, SND_UFO2, 0 );
 if ( bitsGoneLow & 0x10 ) sample_stop( SND_UFO2 );
 if ( bitsChanged & 0x20 ) invaders_flip_screen_w(data & 0x20);
}

variable_types:
offset
unsigned int


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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

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

if ( (readinputport(2LL) & 1) != 0 )
result = nmi_interrupt();
else
result = interrupt();
return result;
}

original_code:
static int spaceint_interrupt(void)
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return interrupt();
}

canonical_original_code:
static int spaceint_interrupt()
{
 if (readinputport(2) & 1)
  return nmi_interrupt();
 else return interrupt();
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void *__fastcall rocnrope_flipscreen_w(__int64 a1, unsigned __int8 a2)
{
void *result; // rax

result = (void *)((a2 ^ 1) & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = (unsigned __int8)result;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

result = (void *)((a2 ^ 1) & 1);
if ( (_DWORD)result != flipscreen )
{
flipscreen = (unsigned __int8)result;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void rocnrope_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != (~data & 1))
 {
  flipscreen = ~data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void rocnrope_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != (~data & 1))
 {
  flipscreen = ~data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall rocnrope_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ebp
__int64 v5; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + 2 * (*(_BYTE *)(colorram + v2) & 0x80u),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v5 = v4 + 1LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v5),
*(_BYTE *)(spriteram_2 + v5 - 1) & 0xF);
v5 -= 2LL;
v4 -= 2;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ebp
__int64 v5; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + 2 * (*(_BYTE *)(colorram + v2) & 0x80u),
*(_BYTE *)(colorram + v2) & 0xF);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 2;
if ( spriteram_size - 2 >= 0 )
{
v5 = v4 + 1LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(spriteram + v5),
*(_BYTE *)(spriteram_2 + v5 - 1) & 0xF);
v5 -= 2LL;
v4 -= 2;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void rocnrope_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipx,flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x20;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 2 * (colorram[offs] & 0x80),
     colorram[offs] & 0x0f,
     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 = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    spriteram_2[offs] & 0x0f,
    spriteram_2[offs] & 0x40,~spriteram_2[offs] & 0x80,
    240-spriteram[offs],spriteram_2[offs + 1],
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
void rocnrope_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipx; int flipy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x20;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 2 * (colorram[offs] & 0x80),
     colorram[offs] & 0x0f,
     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 = spriteram_size - 2;offs >= 0;offs -= 2)
 {
  drawgfx(bitmap,Machine->gfx[1],
    spriteram[offs + 1],
    spriteram_2[offs] & 0x0f,
    spriteram_2[offs] & 0x40,~spriteram_2[offs] & 0x80,
    240-spriteram[offs],spriteram_2[offs + 1],
    &Machine->visible_area,TRANSPARENCY_COLOR,0);
 }
}

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

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 init_rocnrope()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = memory_region(129LL);
v1 = memory_region_length(129LL);
konami1_decode();
result = v1 / 2 + 28733;
*(_BYTE *)(v0 + result) = -104;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = memory_region(129LL);
v1 = memory_region_length(129LL);
konami1_decode();
result = v1 / 2 + 28733;
*(_BYTE *)(v0 + result) = -104;
return result;
}

original_code:
static void init_rocnrope(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 konami1_decode();
 rom[0x703d + diff] = 0x98;
}

canonical_original_code:
static void init_rocnrope()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int diff = memory_region_length(REGION_CPU1) / 2;
 konami1_decode();
 rom[0x703d + diff] = 0x98;
}

variable_types:
rom
unsigned char *

variable_types: diff int


decompiled_code:
__int64 init_rocnropk()
{
return konami1_decode();
}

canonical_decompiled_code:
__int64 func5()
{
return konami1_decode();
}

original_code:
static void init_rocnropk(void)
{
 konami1_decode();
}

canonical_original_code:
static void init_rocnropk()
{
 konami1_decode();
}


decompiled_code:
__int64 kncljoe_vh_start()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
tilemap_set_scroll_rows(v0, 4LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 64LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
tilemap_set_scroll_rows(v0, 4LL);
result = 0LL;
}
return result;
}

original_code:
int kncljoe_vh_start( void )
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 tilemap_set_scroll_rows(bg_tilemap,4);
 return 0;
}

canonical_original_code:
int kncljoe_vh_start()
{
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x00,8,8,64,32);
 if (!bg_tilemap)
  return 1;
 tilemap_set_scroll_rows(bg_tilemap,4);
 return 0;
}


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

flipscreen = a2 & 1;
tilemap_set_flip(0LL, (unsigned int)(2 - flipscreen));
coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 0x20);
result = a2 >> 4;
if ( ((a2 & 0x10) != 0) != tile_bank )
{
tile_bank = (a2 & 0x10) != 0;
result = tilemap_mark_all_tiles_dirty(bg_tilemap);
}
sprite_bank = (a2 >> 2) & 1;
return result;
}

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

flipscreen = a2 & 1;
tilemap_set_flip(0LL, (unsigned int)(2 - flipscreen));
coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 0x20);
result = a2 >> 4;
if ( ((a2 & 0x10) != 0) != tile_bank )
{
tile_bank = (a2 & 0x10) != 0;
result = tilemap_mark_all_tiles_dirty(bg_tilemap);
}
sprite_bank = (a2 >> 2) & 1;
return result;
}

original_code:
void kncljoe_control_w(offs_t offset,data_t data)
{
 flipscreen = data & 0x01;
 tilemap_set_flip(0,flipscreen ? 0x1 : 0x2);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
 if (tile_bank != ((data & 0x10) >> 4))
 {
  tile_bank = (data & 0x10) >> 4;
  tilemap_mark_all_tiles_dirty(bg_tilemap);
 }
 sprite_bank = (data & 0x04) >> 2;
}

canonical_original_code:
void kncljoe_control_w(unsigned int offset, unsigned int data)
{
 flipscreen = data & 0x01;
 tilemap_set_flip(0,flipscreen ? 0x1 : 0x2);
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
 if (tile_bank != ((data & 0x10) >> 4))
 {
  tile_bank = (data & 0x10) >> 4;
  tilemap_mark_all_tiles_dirty(bg_tilemap);
 }
 sprite_bank = (data & 0x04) >> 2;
}


decompiled_code:
__int64 __fastcall kncljoe_scroll_w(__int64 a1, unsigned int a2)
{
tilemap_set_scrollx(bg_tilemap, 0LL, a2);
tilemap_set_scrollx(bg_tilemap, 1LL, a2);
tilemap_set_scrollx(bg_tilemap, 2LL, a2);
return tilemap_set_scrollx(bg_tilemap, 3LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
tilemap_set_scrollx(bg_tilemap, 0LL, a2);
tilemap_set_scrollx(bg_tilemap, 1LL, a2);
tilemap_set_scrollx(bg_tilemap, 2LL, a2);
return tilemap_set_scrollx(bg_tilemap, 3LL, 0LL);
}

original_code:
void kncljoe_scroll_w(offs_t offset,data_t data)
{
 tilemap_set_scrollx(bg_tilemap,0,data);
 tilemap_set_scrollx(bg_tilemap,1,data);
 tilemap_set_scrollx(bg_tilemap,2,data);
 tilemap_set_scrollx(bg_tilemap,3,0);
}

canonical_original_code:
void kncljoe_scroll_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrollx(bg_tilemap,0,data);
 tilemap_set_scrollx(bg_tilemap,1,data);
 tilemap_set_scrollx(bg_tilemap,2,data);
 tilemap_set_scrollx(bg_tilemap,3,0);
}


decompiled_code:
__int64 __fastcall kncljoe_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
palette_recalc();
tilemap_draw(a1, bg_tilemap, 0LL);
return draw_sprites(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
palette_recalc();
tilemap_draw(a1, bg_tilemap, 0LL);
return func5(a1);
}

original_code:
void kncljoe_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
        tilemap_render(0);
 palette_recalc();
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
}

canonical_original_code:
void kncljoe_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
        tilemap_render(0);
 palette_recalc();
 tilemap_draw(bitmap,bg_tilemap,0);
 draw_sprites(bitmap);
}


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rax
unsigned __int8 v2; // cl
int v3; // esi
__int64 v4; // rdi
signed int v5; // edx
__int64 v6; // rcx
int v7; // eax
__int64 result; // rax

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

original_code:
static void get_bg_tile_info(int tile_index)
{
 int attr = videoram[2*tile_index+1];
 int code = videoram[2*tile_index] + ((attr & 0xc0) << 2) + (tile_bank << 10);
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0xf)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((((attr & 0x30) >> 4)>>1)|(((attr & 0x30) >> 4)<<1))&3);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 int attr = videoram[2*tile_index+1];
 int code = videoram[2*tile_index] + ((attr & 0xc0) << 2) + (tile_bank << 10);
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0xf)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((((attr & 0x30) >> 4)>>1)|(((attr & 0x30) >> 4)<<1))&3);
}

variable_types: attr int

variable_types: code int

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


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r13
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rcx
__int64 v8; // rsi
__int64 v9; // rdx
char v10; // r9
__m128i v11; // [rsp+0h] [rbp-38h] BYREF

v11 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v1 = *(_QWORD *)(Machine + 8LL * (sprite_bank + 1) + 512);
if ( flipscreen )
v11.m128i_i32[3] -= 64;
else
v11.m128i_i32[2] += 64;
result = spriteram_size;
if ( spriteram_size >= 0 )
{
v3 = spriteram_size;
v4 = spriteram_size - 4LL - 4LL * (spriteram_size >> 2);
do
{
v8 = *(unsigned __int8 *)(spriteram + v3);
v7 = *(unsigned __int8 *)(spriteram + v3 + 3);
v9 = *(unsigned __int8 *)(spriteram + v3 + 2);
v10 = *(_BYTE *)(spriteram + v3 + 1);
v5 = v10 & 0x40;
if ( (v10 & 0x10) != 0 )
v9 = (unsigned int)(v9 + 512);
if ( (v10 & 0x20) != 0 )
v9 = (unsigned int)(v9 + 256);
if ( flipscreen )
{
v5 = (_DWORD)v5 == 0;
v6 = (unsigned int)v10 >> 31;
v7 = (unsigned int)(240 - v7);
v8 = (unsigned int)(240 - v8);
}
else
{
v6 = v10 >= 0;
}
result = drawgfx(a1, v1, v9, *(_BYTE *)(spriteram + v3 + 1) & 0xF, v5, v6, v7, v8, &v11, 2LL, 0LL);
v3 -= 4LL;
}
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r13
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rcx
__int64 v8; // rsi
__int64 v9; // rdx
char v10; // r9
__m128i v11; // [rsp+0h] [rbp-38h] BYREF

v11 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v1 = *(_QWORD *)(Machine + 8LL * (sprite_bank + 1) + 512);
if ( flipscreen )
v11.m128i_i32[3] -= 64;
else
v11.m128i_i32[2] += 64;
result = spriteram_size;
if ( spriteram_size >= 0 )
{
v3 = spriteram_size;
v4 = spriteram_size - 4LL - 4LL * (spriteram_size >> 2);
do
{
v8 = *(unsigned __int8 *)(spriteram + v3);
v7 = *(unsigned __int8 *)(spriteram + v3 + 3);
v9 = *(unsigned __int8 *)(spriteram + v3 + 2);
v10 = *(_BYTE *)(spriteram + v3 + 1);
v5 = v10 & 0x40;
if ( (v10 & 0x10) != 0 )
v9 = (unsigned int)(v9 + 512);
if ( (v10 & 0x20) != 0 )
v9 = (unsigned int)(v9 + 256);
if ( flipscreen )
{
v5 = (_DWORD)v5 == 0;
v6 = (unsigned int)v10 >> 31;
v7 = (unsigned int)(240 - v7);
v8 = (unsigned int)(240 - v8);
}
else
{
v6 = v10 >= 0;
}
result = drawgfx(a1, v1, v9, *(_BYTE *)(spriteram + v3 + 1) & 0xF, v5, v6, v7, v8, &v11, 2LL, 0LL);
v3 -= 4LL;
}
while ( v3 != v4 );
}
return result;
}

original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
 struct rectangle clip = Machine->visible_area;
 const struct GfxElement *gfx = Machine->gfx[1 + sprite_bank];
 int offs;
 if (flipscreen)
  clip.max_y -= 64;
 else
  clip.min_y += 64;
 for (offs = spriteram_size;offs >= 0;offs -= 4)
 {
  int sy = spriteram[offs];
  int sx = spriteram[offs+3];
  int code = spriteram[offs+2];
  int attr = spriteram[offs+1];
  int flipx = attr & 0x40;
  int flipy = !(attr & 0x80);
  int color = attr & 0x0f;
  if (attr & 0x10) code += 512;
  if (attr & 0x20) code += 256;
  if (flipscreen)
  {
   flipx = !flipx;
   flipy = !flipy;
   sx = 240 - sx;
   sy = 240 - sy;
  }
  drawgfx(bitmap,gfx,
    code,
    color,
    flipx,flipy,
    sx,sy,
    &clip,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct rectangle clip = Machine->visible_area;
 struct GfxElement *gfx = Machine->gfx[1 + sprite_bank];
 int offs;
 if (flipscreen)
  clip.max_y -= 64;
 else
  clip.min_y += 64;
 for (offs = spriteram_size;offs >= 0;offs -= 4)
 {
  int sy = spriteram[offs];
  int sx = spriteram[offs+3];
  int code = spriteram[offs+2];
  int attr = spriteram[offs+1];
  int flipx = attr & 0x40;
  int flipy = !(attr & 0x80);
  int color = attr & 0x0f;
  if (attr & 0x10) code += 512;
  if (attr & 0x20) code += 256;
  if (flipscreen)
  {
   flipx = !flipx;
   flipy = !flipy;
   sx = 240 - sx;
   sy = 240 - sy;
  }
  drawgfx(bitmap,gfx,
    code,
    color,
    flipx,flipy,
    sx,sy,
    &clip,TRANSPARENCY_PEN,0);
 }
}

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

variable_types: offs int

variable_types: flipx int

variable_types: flipy int

variable_types: color int

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


decompiled_code:
void *get_crc_table()
{
return &crc_table;
}

canonical_decompiled_code:
void *func3()
{
return &crc_table;
}

original_code:
const unsigned long * get_crc_table()
{
    return (const unsigned long *)crc_table;
}

canonical_original_code:
unsigned long *get_crc_table()
{
    return (unsigned long *)crc_table;
}

return_type: unsigned long *


decompiled_code:
__int64 __fastcall dotrikun_videoram_w(unsigned int a1, unsigned int a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // ebx
unsigned int v5; // ebp
int i; // er15
unsigned int v7; // er13

*(_BYTE *)(videoram + a1) = a2;
v2 = 16 * (a1 & 0xF);
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= v2 && *(_DWORD *)(Machine + 780LL) >= v2 )
{
v4 = 2 * (a1 >> 4);
if ( *(_DWORD *)(Machine + 784LL) <= v4 && *(_DWORD *)(Machine + 788LL) >= v4 )
{
v5 = v2 + 14;
for ( i = 0; i != 8; ++i )
{
v7 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1));
plot_pixel(
*(_QWORD *)(Machine + 768LL),
v5,
(unsigned int)v4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1)));
plot_pixel(*(_QWORD *)(Machine + 768LL), v5 + 1, (unsigned int)v4, v7);
plot_pixel(*(_QWORD *)(Machine + 768LL), v5, (unsigned int)(v4 + 1), v7);
result = plot_pixel(*(_QWORD *)(Machine + 768LL), v5 + 1, (unsigned int)(v4 + 1), v7);
v5 -= 2;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // ebx
unsigned int v5; // ebp
int i; // er15
unsigned int v7; // er13

*(_BYTE *)(videoram + a1) = a2;
v2 = 16 * (a1 & 0xF);
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= v2 && *(_DWORD *)(Machine + 780LL) >= v2 )
{
v4 = 2 * (a1 >> 4);
if ( *(_DWORD *)(Machine + 784LL) <= v4 && *(_DWORD *)(Machine + 788LL) >= v4 )
{
v5 = v2 + 14;
for ( i = 0; i != 8; ++i )
{
v7 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1));
plot_pixel(
*(_QWORD *)(Machine + 768LL),
v5,
(unsigned int)v4,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * ((a2 >> i) & 1)));
plot_pixel(*(_QWORD *)(Machine + 768LL), v5 + 1, (unsigned int)v4, v7);
plot_pixel(*(_QWORD *)(Machine + 768LL), v5, (unsigned int)(v4 + 1), v7);
result = plot_pixel(*(_QWORD *)(Machine + 768LL), v5 + 1, (unsigned int)(v4 + 1), v7);
v5 -= 2;
}
}
}
return result;
}

original_code:
void dotrikun_videoram_w(offs_t offset,data_t data)
{
 int i;
 int x, y;
 int color;
 videoram[offset] = data;
 x = 2 * (((offset % 16) * 8));
 y = 2 * ((offset / 16));
 if (x >= Machine->visible_area.min_x &&
   x <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y &&
   y <= Machine->visible_area.max_y)
 {
  for (i = 0; i < 8; i++)
  {
   color = Machine->pens[((data >> i) & 0x01)];
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i), y, color);
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i)+1, y, color);
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i), y+1, color);
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i)+1, y+1, color);
  }
 }
}

canonical_original_code:
void dotrikun_videoram_w(unsigned int offset, unsigned int data)
{
 int i;
 int x; int y;
 int color;
 videoram[offset] = data;
 x = 2 * (((offset % 16) * 8));
 y = 2 * ((offset / 16));
 if (x >= Machine->visible_area.min_x &&
   x <= Machine->visible_area.max_x &&
   y >= Machine->visible_area.min_y &&
   y <= Machine->visible_area.max_y)
 {
  for (i = 0; i < 8; i++)
  {
   color = Machine->pens[((data >> i) & 0x01)];
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i), y, color);
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i)+1, y, color);
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i), y+1, color);
   plot_pixel(Machine->scrbitmap, x + 2*(7 - i)+1, y+1, color);
  }
 }
}

variable_types:
offset
unsigned int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall dotrikun_color_w(__int64 a1, char a2)
{
palette_change_color(
0LL,
(unsigned __int8)-((a2 & 8) != 0),
(unsigned __int8)-((a2 & 0x10) != 0),
(unsigned __int8)-((a2 & 0x20) != 0));
return palette_change_color(
1LL,
(unsigned __int8)-(a2 & 1),
(unsigned __int8)-((a2 & 2) != 0),
(unsigned __int8)-((a2 & 4) != 0));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
palette_change_color(
0LL,
(unsigned __int8)-((a2 & 8) != 0),
(unsigned __int8)-((a2 & 0x10) != 0),
(unsigned __int8)-((a2 & 0x20) != 0));
return palette_change_color(
1LL,
(unsigned __int8)-(a2 & 1),
(unsigned __int8)-((a2 & 2) != 0),
(unsigned __int8)-((a2 & 4) != 0));
}

original_code:
void dotrikun_color_w(offs_t offset,data_t data)
{
 int r, g, b;
 r = ((data & 0x08) ? 0xff : 0x00);
 g = ((data & 0x10) ? 0xff : 0x00);
 b = ((data & 0x20) ? 0xff : 0x00);
 palette_change_color(0, r, g, b);
 r = ((data & 0x01) ? 0xff : 0x00);
 g = ((data & 0x02) ? 0xff : 0x00);
 b = ((data & 0x04) ? 0xff : 0x00);
 palette_change_color(1, r, g, b);
}

canonical_original_code:
void dotrikun_color_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 r = ((data & 0x08) ? 0xff : 0x00);
 g = ((data & 0x10) ? 0xff : 0x00);
 b = ((data & 0x20) ? 0xff : 0x00);
 palette_change_color(0, r, g, b);
 r = ((data & 0x01) ? 0xff : 0x00);
 g = ((data & 0x02) ? 0xff : 0x00);
 b = ((data & 0x04) ? 0xff : 0x00);
 palette_change_color(1, r, g, b);
}

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


original_code:
void higemaru_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = *(color_prom++) & 0x0f;
 color_prom += 128;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

canonical_original_code:
void higemaru_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = *(color_prom++) & 0x0f;
 color_prom += 128;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void *__fastcall higemaru_c800_w(__int64 a1, unsigned __int8 a2)
{
void *result; // rax

coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 1);
result = (void *)(a2 & 0x80);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 0x80;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 1);
result = (void *)(a2 & 0x80);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 0x80;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void higemaru_c800_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 1);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void higemaru_c800_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 1);
 if (flipscreen != (data & 0x80))
 {
  flipscreen = data & 0x80;
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
__int64 __fastcall higemaru_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // esi
int v4; // ecx
__int64 result; // rax
__int64 v6; // r14
unsigned __int8 v7; // r12
unsigned __int8 v8; // dl
__int64 v9; // rbp
__int64 v10; // r15
unsigned int v11; // er13
unsigned int v12; // ebx
unsigned int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v3 = v1 % 32;
v4 = v1 / 32;
if ( flipscreen )
{
v3 = 31 - v1 % 32;
v4 = 31 - v1 / 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((2 * *(unsigned __int8 *)(colorram + v2)) & 0x100u),
*(_BYTE *)(colorram + v2) & 0x1F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v3),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = (unsigned int)(spriteram_size - 16);
v14 = spriteram_size - 16;
if ( spriteram_size - 16 >= 0 )
{
v6 = (int)result;
do
{
v8 = *(_BYTE *)(spriteram + v6) & 0x7F;
v9 = *(unsigned __int8 *)(spriteram + v6 + 12);
v10 = *(unsigned __int8 *)(spriteram + v6 + 8);
v11 = *(_BYTE *)(spriteram + v6 + 4) & 0x10;
v12 = *(_BYTE *)(spriteram + v6 + 4) & 0x20;
if ( flipscreen )
{
v9 = (unsigned int)(240 - v9);
v10 = (unsigned int)(240 - v10);
v11 = v11 == 0;
v12 = v12 == 0;
}
v7 = *(_BYTE *)(spriteram + v6 + 4) & 0xF;
v13 = v8;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v8, v7, v11, v12, v9, v10, Machine + 776LL, 2LL, 15LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
v7,
v11,
v12,
(unsigned int)(v9 - 256),
v10,
Machine + 776LL,
2LL,
15LL);
v6 -= 16LL;
v14 -= 16;
}
while ( v14 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // esi
int v4; // ecx
__int64 result; // rax
__int64 v6; // r14
unsigned __int8 v7; // r12
unsigned __int8 v8; // dl
__int64 v9; // rbp
__int64 v10; // r15
unsigned int v11; // er13
unsigned int v12; // ebx
unsigned int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v3 = v1 % 32;
v4 = v1 / 32;
if ( flipscreen )
{
v3 = 31 - v1 % 32;
v4 = 31 - v1 / 32;
}
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((2 * *(unsigned __int8 *)(colorram + v2)) & 0x100u),
*(_BYTE *)(colorram + v2) & 0x1F,
(unsigned int)flipscreen,
(unsigned int)flipscreen,
(unsigned int)(8 * v3),
(unsigned int)(8 * v4),
0LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = (unsigned int)(spriteram_size - 16);
v14 = spriteram_size - 16;
if ( spriteram_size - 16 >= 0 )
{
v6 = (int)result;
do
{
v8 = *(_BYTE *)(spriteram + v6) & 0x7F;
v9 = *(unsigned __int8 *)(spriteram + v6 + 12);
v10 = *(unsigned __int8 *)(spriteram + v6 + 8);
v11 = *(_BYTE *)(spriteram + v6 + 4) & 0x10;
v12 = *(_BYTE *)(spriteram + v6 + 4) & 0x20;
if ( flipscreen )
{
v9 = (unsigned int)(240 - v9);
v10 = (unsigned int)(240 - v10);
v11 = v11 == 0;
v12 = v12 == 0;
}
v7 = *(_BYTE *)(spriteram + v6 + 4) & 0xF;
v13 = v8;
drawgfx(a1, *(_QWORD *)(Machine + 520LL), v8, v7, v11, v12, v9, v10, Machine + 776LL, 2LL, 15LL);
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v13,
v7,
v11,
v12,
(unsigned int)(v9 - 256),
v10,
Machine + 776LL,
2LL,
15LL);
v6 -= 16LL;
v14 -= 16;
}
while ( v14 >= 0 );
}
return result;
}

original_code:
void higemaru_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x80) << 1),
     colorram[offs] & 0x1f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 16;offs >= 0;offs -= 16)
 {
  int code,col,sx,sy,flipx,flipy;
  code = spriteram[offs] & 0x7f;
  col = spriteram[offs + 4] & 0x0f;
  sx = spriteram[offs + 12];
  sy = spriteram[offs + 8];
  flipx = spriteram[offs + 4] & 0x10;
  flipy = spriteram[offs + 4] & 0x20;
  if (flipscreen)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code,
    col,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    col,
    flipx,flipy,
    sx - 256,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
 }
}

canonical_original_code:
void higemaru_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x80) << 1),
     colorram[offs] & 0x1f,
     flipscreen,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 16;offs >= 0;offs -= 16)
 {
  int code; int col; int sx; int sy; int flipx; int flipy;
  code = spriteram[offs] & 0x7f;
  col = spriteram[offs + 4] & 0x0f;
  sx = spriteram[offs + 12];
  sy = spriteram[offs + 8];
  flipx = spriteram[offs + 4] & 0x10;
  flipy = spriteram[offs + 4] & 0x20;
  if (flipscreen)
  {
   sx = 240 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    code,
    col,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
  drawgfx(bitmap,Machine->gfx[1],
    code,
    col,
    flipx,flipy,
    sx - 256,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
 }
}

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

variable_types: sx int

variable_types: sy int

variable_types: code int

variable_types: col int


decompiled_code:
__int64 higemaru_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 207 : 215;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)cpu_getiloops() == 0 ? 207 : 215;
}

original_code:
int higemaru_interrupt(void)
{
 if (cpu_getiloops() == 0) return 0x00cf;
 else return 0x00d7;
}

canonical_original_code:
int higemaru_interrupt()
{
 if (cpu_getiloops() == 0) return 0x00cf;
 else return 0x00d7;
}


decompiled_code:
__int64 __fastcall uistring_init(__int64 a1)
{
char *v1; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
__int64 v9; // rbx
size_t v10; // rax
char *v11; // rax
char src[256]; // [rsp+10h] [rbp-338h] BYREF
char dest[8]; // [rsp+110h] [rbp-238h] BYREF
__int64 v14; // [rsp+118h] [rbp-230h]
char v15[232]; // [rsp+120h] [rbp-228h] BYREF
int v16; // [rsp+208h] [rbp-140h]
__int16 v17; // [rsp+20Ch] [rbp-13Ch]
char v18; // [rsp+20Eh] [rbp-13Ah]
char s1; // [rsp+210h] [rbp-138h] BYREF
char s[311]; // [rsp+211h] [rbp-137h] BYREF

*(_QWORD *)dest = 0LL;
v14 = 0LL;
memset(v15, 0, sizeof(v15));
v16 = 0;
v17 = 0;
v18 = 0;
v1 = (char *)trans_text;
do
{
*(_QWORD *)v1 = 0LL;
v1 += 8;
}
while ( v1 != (char *)&trans_text[110] );
memset(lang, 0, sizeof(lang));
if ( a1 )
{
LABEL_8:
while ( osd_fgets(&s1, 255LL, a1) )
{
if ( s1 != 10 && s1 != 59 )
{
if ( s1 == 91 )
{
v3 = strtok(s, "]");
strcpy(dest, v3);
}
else
{
if ( !strcmp(dest, "LangInfo") )
{
v5 = strtok(&s1, "=");
if ( !strcmp(v5, "Version") )
{
v4 = strtok(0LL, "\n");
_isoc99_sscanf(v4, "%d", lang);
}
else if ( !strcmp(v5, "Language") )
{
v7 = strtok(0LL, "\n");
strcpy(&lang[18], v7);
}
else if ( !strcmp(v5, "Author") )
{
v8 = strtok(0LL, "\n");
strcpy(&lang[528], v8);
}
else if ( !strcmp(v5, "Font") )
{
v6 = strtok(0LL, "\n");
strcpy(&lang[273], v6);
}
}
if ( !strcmp(dest, "Strings") )
{
strtok(&s1, "\n");
v9 = 0LL;
while ( strcmp(&s1, default_text[v9]) )
{
if ( ++v9 == 109 )
goto LABEL_8;
}
osd_fgets(src, 255LL, a1);
strtok(src, "\n");
v10 = strlen(src);
v11 = (char *)malloc(v10 + 1);
trans_text[(int)v9] = v11;
strcpy(v11, src);
}
}
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char *v1; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
__int64 v9; // rbx
size_t v10; // rax
char *v11; // rax
char src[256]; // [rsp+10h] [rbp-338h] BYREF
char dest[8]; // [rsp+110h] [rbp-238h] BYREF
__int64 v14; // [rsp+118h] [rbp-230h]
char v15[232]; // [rsp+120h] [rbp-228h] BYREF
int v16; // [rsp+208h] [rbp-140h]
__int16 v17; // [rsp+20Ch] [rbp-13Ch]
char v18; // [rsp+20Eh] [rbp-13Ah]
char s1; // [rsp+210h] [rbp-138h] BYREF
char s[311]; // [rsp+211h] [rbp-137h] BYREF

*(_QWORD *)dest = 0LL;
v14 = 0LL;
memset(v15, 0, sizeof(v15));
v16 = 0;
v17 = 0;
v18 = 0;
v1 = (char *)trans_text;
do
{
*(_QWORD *)v1 = 0LL;
v1 += 8;
}
while ( v1 != (char *)&trans_text[110] );
memset(lang, 0, sizeof(lang));
if ( a1 )
{
LABEL_8:
while ( osd_fgets(&s1, 255LL, a1) )
{
if ( s1 != 10 && s1 != 59 )
{
if ( s1 == 91 )
{
v3 = strtok(s, "]");
strcpy(dest, v3);
}
else
{
if ( !strcmp(dest, "LangInfo") )
{
v5 = strtok(&s1, "=");
if ( !strcmp(v5, "Version") )
{
v4 = strtok(0LL, "\n");
_isoc99_sscanf(v4, "%d", lang);
}
else if ( !strcmp(v5, "Language") )
{
v7 = strtok(0LL, "\n");
strcpy(&lang[18], v7);
}
else if ( !strcmp(v5, "Author") )
{
v8 = strtok(0LL, "\n");
strcpy(&lang[528], v8);
}
else if ( !strcmp(v5, "Font") )
{
v6 = strtok(0LL, "\n");
strcpy(&lang[273], v6);
}
}
if ( !strcmp(dest, "Strings") )
{
strtok(&s1, "\n");
v9 = 0LL;
while ( strcmp(&s1, default_text[v9]) )
{
if ( ++v9 == 109 )
goto LABEL_8;
}
osd_fgets(src, 255LL, a1);
strtok(src, "\n");
v10 = strlen(src);
v11 = (char *)malloc(v10 + 1);
trans_text[(int)v9] = v11;
strcpy(v11, src);
}
}
}
}
}
return 0LL;
}

original_code:
int uistring_init (void *langfile)
{
 int i;
 char curline[255];
 char section[255] = "\0";
 char *ptr;
 for (i = 0; i <= UI_last_entry; i ++)
 {
  trans_text[i] = ((void *)0);
 }
 memset(&lang, 0, sizeof(lang));
 if (!langfile) return 0;
 while (osd_fgets (curline, 255, langfile) != ((void *)0))
 {
  if (curline[0] == ';') continue;
  if (curline[0] == '\n') continue;
  if (curline[0] == '[')
  {
   ptr = strtok (&curline[1], "]");
   strcpy (section, ptr);
   continue;
  }
  if (strcmp (section, "LangInfo") == 0)
  {
   ptr = strtok (curline, "=");
   if (strcmp (ptr, "Version") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    sscanf (ptr, "%d", &lang.version);
   }
   else if (strcmp (ptr, "Language") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    strcpy (lang.langname, ptr);
   }
   else if (strcmp (ptr, "Author") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    strcpy (lang.author, ptr);
   }
   else if (strcmp (ptr, "Font") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    strcpy (lang.fontname, ptr);
   }
  }
  if (strcmp (section, "Strings") == 0)
  {
   ptr = strtok (curline, "\n");
   for (i = 0; i < UI_last_entry; i ++)
   {
    if (strcmp (curline, default_text[i]) == 0)
    {
     char transline[255];
     osd_fgets (transline, 255, langfile);
     ptr = strtok (transline, "\n");
     trans_text[i] = (char*) malloc(strlen(transline)+1);
     strcpy (trans_text[i], transline);
     break;
    }
   }
  }
 }
 return 0;
}

canonical_original_code:
int uistring_init(void *langfile)
{
 int i;
 char curline[255];
 char section[255] = "\0";
 char *ptr;
 for (i = 0; i <= UI_last_entry; i ++)
 {
  trans_text[i] = ((void *)0);
 }
 memset(&lang, 0, sizeof(lang));
 if (!langfile) return 0;
 while (osd_fgets (curline, 255, langfile) != ((void *)0))
 {
  if (curline[0] == ';') continue;
  if (curline[0] == '\n') continue;
  if (curline[0] == '[')
  {
   ptr = strtok (&curline[1], "]");
   strcpy (section, ptr);
   continue;
  }
  if (strcmp (section, "LangInfo") == 0)
  {
   ptr = strtok (curline, "=");
   if (strcmp (ptr, "Version") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    sscanf (ptr, "%d", &lang.version);
   }
   else if (strcmp (ptr, "Language") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    strcpy (lang.langname, ptr);
   }
   else if (strcmp (ptr, "Author") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    strcpy (lang.author, ptr);
   }
   else if (strcmp (ptr, "Font") == 0)
   {
    ptr = strtok (((void *)0), "\n");
    strcpy (lang.fontname, ptr);
   }
  }
  if (strcmp (section, "Strings") == 0)
  {
   ptr = strtok (curline, "\n");
   for (i = 0; i < UI_last_entry; i ++)
   {
    if (strcmp (curline, default_text[i]) == 0)
    {
     char transline[255];
     osd_fgets (transline, 255, langfile);
     ptr = strtok (transline, "\n");
     trans_text[i] = (char *) malloc(strlen(transline)+1);
     strcpy (trans_text[i], transline);
     break;
    }
   }
  }
 }
 return 0;
}

variable_types:
langfile
void *

variable_types:
curline
char [255]

variable_types:
section
char [255]

variable_types:
ptr
char *

variable_types:
transline
char [255]


decompiled_code:
void uistring_shutdown()
{
void **v0; // rbx

v0 = (void **)trans_text;
do
{
if ( *v0 )
{
free(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != &trans_text[110] );
}

canonical_decompiled_code:
void func1()
{
void **v0; // rbx

v0 = (void **)trans_text;
do
{
if ( *v0 )
{
free(*v0);
*v0 = 0LL;
}
++v0;
}
while ( v0 != &trans_text[110] );
}

original_code:
void uistring_shutdown (void)
{
 int i;
 for (i = 0; i <= UI_last_entry; i ++)
 {
  if (trans_text[i])
  {
   free(trans_text[i]);
   trans_text[i] = ((void *)0);
  }
 }
}

canonical_original_code:
void uistring_shutdown()
{
 int i;
 for (i = 0; i <= UI_last_entry; i ++)
 {
  if (trans_text[i])
  {
   free(trans_text[i]);
   trans_text[i] = ((void *)0);
  }
 }
}


decompiled_code:
char *__fastcall ui_getstring(int a1)
{
char *result; // rax

result = (char *)trans_text[a1];
if ( !result )
result = default_text[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *result; // rax

result = (char *)trans_text[a1];
if ( !result )
result = default_text[a1];
return result;
}

original_code:
const char * ui_getstring (int string_num)
{
 if (trans_text[string_num] != ((void *)0))
  return trans_text[string_num];
 else
  return default_text[string_num];
}

canonical_original_code:
char *ui_getstring(int string_num)
{
 if (trans_text[string_num] != ((void *)0))
  return trans_text[string_num];
 else
  return default_text[string_num];
}

return_type: char *


decompiled_code:
void *__fastcall pkunwar_flipscreen_w(__int64 a1, char a2)
{
void *result; // rax

if ( flipscreen != (a2 & 1) )
{
flipscreen = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
result = (void *)(a2 & 2);
if ( dword_814 != (_DWORD)result )
{
dword_814 = a2 & 2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

if ( flipscreen != (a2 & 1) )
{
flipscreen = a2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
result = (void *)(a2 & 2);
if ( dword_814 != (_DWORD)result )
{
dword_814 = a2 & 2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void pkunwar_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen[0] != (data & 1))
 {
  flipscreen[0] = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipscreen[1] != (data & 2))
 {
  flipscreen[1] = data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void pkunwar_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen[0] != (data & 1))
 {
  flipscreen[0] = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 if (flipscreen[1] != (data & 2))
 {
  flipscreen[1] = data & 2;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall pkunwar_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
unsigned __int64 v3; // rbx
void *result; // rax
int v5; // ebx
__int64 v6; // r12
__int16 v7; // dx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(colorram + v2) << 8) & 0x700) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 4);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v3 = 0LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(_BYTE *)(spriteram + v3) >> 2) + ((*(unsigned __int8 *)(spriteram + v3 + 3) << 6) & 0x1C0u),
*(_BYTE *)(spriteram + v3 + 3) >> 4);
v3 += 32LL;
}
while ( spriteram_size > v3 );
}
result = &videoram_size;
v5 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v6 = v5;
do
{
result = (void *)colorram;
v7 = *(unsigned __int8 *)(colorram + v6);
if ( (v7 & 8) != 0 )
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v6) + ((v7 << 8) & 0x700u),
(unsigned __int8)v7 >> 4);
--v6;
--v5;
}
while ( v5 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
unsigned __int64 v3; // rbx
void *result; // rax
int v5; // ebx
__int64 v6; // r12
__int16 v7; // dx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
((*(unsigned __int8 *)(colorram + v2) << 8) & 0x700) + (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) >> 4);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
if ( spriteram_size )
{
v3 = 0LL;
do
{
drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(*(_BYTE *)(spriteram + v3) >> 2) + ((*(unsigned __int8 *)(spriteram + v3 + 3) << 6) & 0x1C0u),
*(_BYTE *)(spriteram + v3 + 3) >> 4);
v3 += 32LL;
}
while ( spriteram_size > v3 );
}
result = &videoram_size;
v5 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v6 = v5;
do
{
result = (void *)colorram;
v7 = *(unsigned __int8 *)(colorram + v6);
if ( (v7 & 8) != 0 )
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v6) + ((v7 << 8) & 0x700u),
(unsigned __int8)v7 >> 4);
--v6;
--v5;
}
while ( v5 >= 0 );
}
return result;
}

original_code:
void pkunwar_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x07) << 8),
     (colorram[offs] & 0xf0) >> 4,
     flipscreen[0],flipscreen[1],
     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 < spriteram_size;offs += 32)
 {
  int sx,sy,flipx,flipy;
  sx = ((spriteram[offs + 1] + 8) & 0xff) - 8;
  sy = spriteram[offs + 2];
  flipx = spriteram[offs] & 0x01;
  flipy = spriteram[offs] & 0x02;
  if (flipscreen[0])
  {
   sx = 240 - sx;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    ((spriteram[offs] & 0xfc) >> 2) + ((spriteram[offs + 3] & 0x07) << 6),
    (spriteram[offs + 3] & 0xf0) >> 4,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x08)
  {
   int sx,sy;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x07) << 8),
     (colorram[offs] & 0xf0) >> 4,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

canonical_original_code:
void pkunwar_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x07) << 8),
     (colorram[offs] & 0xf0) >> 4,
     flipscreen[0],flipscreen[1],
     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 < spriteram_size;offs += 32)
 {
  int sx; int sy; int flipx; int flipy;
  sx = ((spriteram[offs + 1] + 8) & 0xff) - 8;
  sy = spriteram[offs + 2];
  flipx = spriteram[offs] & 0x01;
  flipy = spriteram[offs] & 0x02;
  if (flipscreen[0])
  {
   sx = 240 - sx;
   flipx = !flipx;
  }
  if (flipscreen[1])
  {
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[1],
    ((spriteram[offs] & 0xfc) >> 2) + ((spriteram[offs + 3] & 0x07) << 6),
    (spriteram[offs + 3] & 0xf0) >> 4,
    flipx,flipy,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (colorram[offs] & 0x08)
  {
   int sx; int sy;
   sx = offs % 32;
   sy = offs / 32;
   if (flipscreen[0]) sx = 31 - sx;
   if (flipscreen[1]) sy = 31 - sy;
   drawgfx(bitmap,Machine->gfx[0],
     videoram[offs] + ((colorram[offs] & 0x07) << 8),
     (colorram[offs] & 0xf0) >> 4,
     flipscreen[0],flipscreen[1],
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_PEN,0);
  }
 }
}

variable_types: offs int

variable_types: flipx int

variable_types: flipy int


decompiled_code:
__int64 __fastcall invinco_sh_port2_w(__int64 a1, int a2)
{
char v2; // bl
__int64 result; // rax

v2 = a2 ^ (port2State_0 | a2);
port2State_0 = a2;
if ( (v2 & 4) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v2 & 8) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v2 & 0x10) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v2 & 0x20) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v2 & 0x40) != 0 )
result = sample_start(4LL, 4LL, 0LL);
if ( v2 < 0 )
result = sample_start(5LL, 5LL, 0LL);
return result;
}

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

v2 = a2 ^ (port2State_0 | a2);
port2State_0 = a2;
if ( (v2 & 4) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v2 & 8) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v2 & 0x10) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v2 & 0x20) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v2 & 0x40) != 0 )
result = sample_start(4LL, 4LL, 0LL);
if ( v2 < 0 )
result = sample_start(5LL, 5LL, 0LL);
return result;
}

original_code:
void invinco_sh_port2_w(offs_t offset,data_t data)
{
 static int port2State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_SAUCER, SND_SAUCER, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_MOVE1, SND_MOVE1, 0 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_MOVE2, SND_MOVE2, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_FIRE, SND_FIRE, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_INVHIT, SND_INVHIT, 0 );
 }
 if ( bitsGoneLow & 0x80 )
 {
  sample_start( SND_SHIPHIT, SND_SHIPHIT, 0 );
 }
}

canonical_original_code:
void invinco_sh_port2_w(unsigned int offset, unsigned int data)
{
 static int port2State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_SAUCER, SND_SAUCER, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_MOVE1, SND_MOVE1, 0 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_MOVE2, SND_MOVE2, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_FIRE, SND_FIRE, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_INVHIT, SND_INVHIT, 0 );
 }
 if ( bitsGoneLow & 0x80 )
 {
  sample_start( SND_SHIPHIT, SND_SHIPHIT, 0 );
 }
}

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int