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

sprite_colorbase = 0;
*(_QWORD *)zoom_colorbase = 0x400000010LL;
if ( (unsigned int)K051960_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
return 1LL;
if ( (unsigned int)K051316_vh_start_0(138LL, 4LL, zoom_callback_0) )
{
K051960_vh_stop();
result = 1LL;
}
else if ( (unsigned int)K051316_vh_start_1(139LL, 7LL, zoom_callback_1) )
{
K051960_vh_stop();
K051316_vh_stop_0();
result = 1LL;
}
else
{
K051316_set_offset(0LL, 8LL, 0LL);
K051316_wraparound_enable(1LL, 1LL);
result = 0LL;
}
return result;
}

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

sprite_colorbase = 0;
*(_QWORD *)zoom_colorbase = 0x400000010LL;
if ( (unsigned int)K051960_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
return 1LL;
if ( (unsigned int)K051316_vh_start_0(138LL, 4LL, zoom_callback_0) )
{
K051960_vh_stop();
result = 1LL;
}
else if ( (unsigned int)K051316_vh_start_1(139LL, 7LL, zoom_callback_1) )
{
K051960_vh_stop();
K051316_vh_stop_0();
result = 1LL;
}
else
{
K051316_set_offset(0LL, 8LL, 0LL);
K051316_wraparound_enable(1LL, 1LL);
result = 0LL;
}
return result;
}

original_code:
int chqflag_vh_start( void )
{
 sprite_colorbase = 0;
 zoom_colorbase[0] = 0x10;
 zoom_colorbase[1] = 0x04;
 if (K051960_vh_start(REGION_GFX1,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX2,4,zoom_callback_0))
 {
  K051960_vh_stop();
  return 1;
 }
 if (K051316_vh_start_1(REGION_GFX3,7,zoom_callback_1))
 {
  K051960_vh_stop();
  K051316_vh_stop_0();
  return 1;
 }
 K051316_set_offset(0, 8, 0);
 K051316_wraparound_enable(1, 1);
 return 0;
}

canonical_original_code:
int chqflag_vh_start()
{
 sprite_colorbase = 0;
 zoom_colorbase[0] = 0x10;
 zoom_colorbase[1] = 0x04;
 if (K051960_vh_start(REGION_GFX1,0,1,2,3,sprite_callback))
 {
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX2,4,zoom_callback_0))
 {
  K051960_vh_stop();
  return 1;
 }
 if (K051316_vh_start_1(REGION_GFX3,7,zoom_callback_1))
 {
  K051960_vh_stop();
  K051316_vh_stop_0();
  return 1;
 }
 K051316_set_offset(0, 8, 0);
 K051316_wraparound_enable(1, 1);
 return 0;
}


decompiled_code:
__int64 __fastcall chqflag_vh_screenrefresh(__int64 a1)
{
int i; // edx
int v2; // eax

K051316_tilemap_update_0();
K051316_tilemap_update_1();
palette_init_used_colors();
K051960_mark_sprites_colors();
for ( i = 0; i != 16; ++i )
{
v2 = i + zoom_colorbase[0];
*(_BYTE *)(palette_used_colors + 16 * v2) = 7;
}
if ( palette_recalc(zoom_colorbase, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K051316_zoom_draw_1(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 128LL);
return K051316_zoom_draw_0(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int i; // edx
int v2; // eax

K051316_tilemap_update_0();
K051316_tilemap_update_1();
palette_init_used_colors();
K051960_mark_sprites_colors();
for ( i = 0; i != 16; ++i )
{
v2 = i + zoom_colorbase[0];
*(_BYTE *)(palette_used_colors + 16 * v2) = 7;
}
if ( palette_recalc(zoom_colorbase, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K051316_zoom_draw_1(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 128LL);
return K051316_zoom_draw_0(a1, 0LL);
}

original_code:
void chqflag_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 int i;
 K051316_tilemap_update_0();
 K051316_tilemap_update_1();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0; i < 16; i++){
  palette_used_colors[(zoom_colorbase[0] + i) * 16] = (4|(1|2));
 }
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 K051316_zoom_draw_1(bitmap,0);
 K051960_sprites_draw(bitmap,0,128);
 K051316_zoom_draw_0(bitmap,0);
}

canonical_original_code:
void chqflag_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 int i;
 K051316_tilemap_update_0();
 K051316_tilemap_update_1();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 for (i = 0; i < 16; i++){
  palette_used_colors[(zoom_colorbase[0] + i) * 16] = (4|(1|2));
 }
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 K051316_zoom_draw_1(bitmap,0);
 K051960_sprites_draw(bitmap,0,128);
 K051316_zoom_draw_0(bitmap,0);
}

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

variable_types: fullrefresh int

variable_types: i int

return_type: void


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 chqflag_ym2151_irq_w()
{
return cpu_cause_interrupt(1LL, 4294967294LL);
}

canonical_decompiled_code:
__int64 func8()
{
return cpu_cause_interrupt(1LL, 4294967294LL);
}

original_code:
static void chqflag_ym2151_irq_w(int data)
{
 cpu_cause_interrupt(1,-2);
}

variable_types: data int


decompiled_code:
_QWORD *init_chqflag()
{
__int64 v0; // rbx
_QWORD *result; // rax

v0 = memory_region(129LL);
konami_rom_deinterleave_2(137LL);
result = &paletteram;
paletteram = v0 + 360448;
return result;
}

canonical_decompiled_code:
_QWORD *func9()
{
__int64 v0; // rbx
_QWORD *result; // rax

v0 = memory_region(129LL);
konami_rom_deinterleave_2(137LL);
result = &paletteram;
paletteram = v0 + 360448;
return result;
}

original_code:
static void init_chqflag(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_rom_deinterleave_2(REGION_GFX1);
 paletteram = &RAM[0x58000];
}

canonical_original_code:
static void init_chqflag()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_rom_deinterleave_2(REGION_GFX1);
 paletteram = &RAM[0x58000];
}

variable_types:
RAM
unsigned char *


original_code:
static void k007232_extvolume_w(offs_t offset,data_t data)
{
 K007232_set_volume(0,0,(data >> 4)*0x11/2,(data & 0x0f)*0x11/2);
}

canonical_original_code:
static void k007232_extvolume_w(unsigned int offset, unsigned int data)
{
 K007232_set_volume(0,0,(data >> 4)*0x11/2,(data & 0x0f)*0x11/2);
}


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

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


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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || !(unsigned int)K051960_is_NMI_enabled() )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( !(unsigned int)K051960_is_IRQ_enabled() )
return ignore_interrupt();
result = 1LL;
}
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || !(unsigned int)K051960_is_NMI_enabled() )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( !(unsigned int)K051960_is_IRQ_enabled() )
return ignore_interrupt();
result = 1LL;
}
return result;
}

original_code:
static int chqflag_interrupt( void )
{
 if (cpu_getiloops() == 0){
  if (K051960_is_IRQ_enabled()) return 1;
 }
 else if (cpu_getiloops() % 2){
  if (K051960_is_NMI_enabled()) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int chqflag_interrupt()
{
 if (cpu_getiloops() == 0){
  if (K051960_is_IRQ_enabled()) return 1;
 }
 else if (cpu_getiloops() % 2){
  if (K051960_is_NMI_enabled()) return nmi_interrupt();
 }
 return ignore_interrupt();
}

return_type: int


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

coin_counter_w(1LL, a2 & 1);
coin_counter_w(0LL, a2 & 2);
K051316_readroms = a2 & 0x10;
if ( (a2 & 0x10) != 0 )
result = cpu_setbankhandler_r(3LL, &K051316_rom_1_r);
else
result = cpu_setbankhandler_r(3LL, &K051316_1_r);
return result;
}

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

coin_counter_w(1LL, a2 & 1);
coin_counter_w(0LL, a2 & 2);
K051316_readroms = a2 & 0x10;
if ( (a2 & 0x10) != 0 )
result = cpu_setbankhandler_r(3LL, &K051316_rom_1_r);
else
result = cpu_setbankhandler_r(3LL, &K051316_1_r);
return result;
}

original_code:
static void chqflag_vreg_w(offs_t offset,data_t data)
{
 coin_counter_w(1,data & 0x01);
 coin_counter_w(0,data & 0x02);
 if ((K051316_readroms = (data & 0x10))){
  cpu_setbankhandler_r (3, K051316_rom_1_r);
 }
 else{
  cpu_setbankhandler_r (3, K051316_1_r);
 }
}

canonical_original_code:
static void chqflag_vreg_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(1,data & 0x01);
 coin_counter_w(0,data & 0x02);
 if ((K051316_readroms = (data & 0x10))){
  cpu_setbankhandler_r (3, K051316_rom_1_r);
 }
 else{
  cpu_setbankhandler_r (3, K051316_1_r);
 }
}


decompiled_code:
__int64 __fastcall chqflag_bankswitch_w(__int64 a1, char a2)
{
void *v2; // rsi
__int64 result; // rax
unsigned int v4; // eax

cpu_bankbase[4] = memory_region(129LL) + (((a2 & 0x1Fu) + 4) << 14);
if ( ophw == 4 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
if ( (a2 & 0x20) != 0 )
{
cpu_setbankhandler_r(2LL, &paletteram_r);
cpu_setbankhandler_w(2LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
if ( K051316_readroms )
v2 = &K051316_rom_0_r;
else
v2 = &K051316_0_r;
cpu_setbankhandler_r(1LL, v2);
result = cpu_setbankhandler_w(1LL, &K051316_0_w);
}
else
{
cpu_setbankhandler_r(1LL, -1LL);
cpu_setbankhandler_w(1LL, -1LL);
cpu_setbankhandler_r(2LL, -1LL);
result = cpu_setbankhandler_w(2LL, -1LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, char a2)
{
void *v2; // rsi
__int64 result; // rax
unsigned int v4; // eax

cpu_bankbase[4] = memory_region(129LL) + (((a2 & 0x1Fu) + 4) << 14);
if ( ophw == 4 )
{
ophw = -1;
v4 = cpu_get_pc();
cpu_setOPbase16(v4);
}
if ( (a2 & 0x20) != 0 )
{
cpu_setbankhandler_r(2LL, &paletteram_r);
cpu_setbankhandler_w(2LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
if ( K051316_readroms )
v2 = &K051316_rom_0_r;
else
v2 = &K051316_0_r;
cpu_setbankhandler_r(1LL, v2);
result = cpu_setbankhandler_w(1LL, &K051316_0_w);
}
else
{
cpu_setbankhandler_r(1LL, -1LL);
cpu_setbankhandler_w(1LL, -1LL);
cpu_setbankhandler_r(2LL, -1LL);
result = cpu_setbankhandler_w(2LL, -1LL);
}
return result;
}

original_code:
static void chqflag_bankswitch_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x1f)*0x4000;
 { if (4 >= 1 && 4 <= 16) { cpu_bankbase[4] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 4) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (data & 0x20){
  cpu_setbankhandler_r (2, paletteram_r);
  cpu_setbankhandler_w (2, paletteram_xBBBBBGGGGGRRRRR_swap_w);
  if (K051316_readroms){
   cpu_setbankhandler_r (1, K051316_rom_0_r);
   cpu_setbankhandler_w (1, K051316_0_w);
  }
  else{
   cpu_setbankhandler_r (1, K051316_0_r);
   cpu_setbankhandler_w (1, K051316_0_w);
  }
 }
 else{
  cpu_setbankhandler_r (1, ((mem_read_handler)-1));
  cpu_setbankhandler_w (1, ((mem_write_handler)-1));
  cpu_setbankhandler_r (2, ((mem_read_handler)-1));
  cpu_setbankhandler_w (2, ((mem_write_handler)-1));
 }
}

canonical_original_code:
static void chqflag_bankswitch_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x1f)*0x4000;
 { if (4 >= 1 && 4 <= 16) { cpu_bankbase[4] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 4) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (data & 0x20){
  cpu_setbankhandler_r (2, paletteram_r);
  cpu_setbankhandler_w (2, paletteram_xBBBBBGGGGGRRRRR_swap_w);
  if (K051316_readroms){
   cpu_setbankhandler_r (1, K051316_rom_0_r);
   cpu_setbankhandler_w (1, K051316_0_w);
  }
  else{
   cpu_setbankhandler_r (1, K051316_0_r);
   cpu_setbankhandler_w (1, K051316_0_w);
  }
 }
 else{
  cpu_setbankhandler_r (1, ((mem_read_handler)-1));
  cpu_setbankhandler_w (1, ((mem_write_handler)-1));
  cpu_setbankhandler_r (2, ((mem_read_handler)-1));
  cpu_setbankhandler_w (2, ((mem_write_handler)-1));
 }
}

variable_types: bankaddress int


decompiled_code:
__int64 __fastcall analog_read_r(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // eax
unsigned int v5; // er8
__int64 result; // rax

v4 = analog_ctrl & 3;
if ( v4 == 2 )
return (unsigned int)accel_1;
v5 = wheel_0;
if ( v4 == 3 )
return v5;
if ( v4 == 1 )
{
wheel_0 = readinputport(6LL, a2, a3, a4, (unsigned int)wheel_0);
result = (unsigned int)wheel_0;
}
else
{
accel_1 = readinputport(5LL, a2, a3, a4, (unsigned int)wheel_0);
result = (unsigned int)accel_1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // eax
unsigned int v5; // er8
__int64 result; // rax

v4 = analog_ctrl & 3;
if ( v4 == 2 )
return (unsigned int)accel_1;
v5 = wheel_0;
if ( v4 == 3 )
return v5;
if ( v4 == 1 )
{
wheel_0 = readinputport(6LL, a2, a3, a4, (unsigned int)wheel_0);
result = (unsigned int)wheel_0;
}
else
{
accel_1 = readinputport(5LL, a2, a3, a4, (unsigned int)wheel_0);
result = (unsigned int)accel_1;
}
return result;
}

original_code:
static data_t analog_read_r(offs_t offset)
{
 static int accel, wheel;
 switch (analog_ctrl & 0x03){
  case 0x00: return (accel = readinputport(5));
  case 0x01: return (wheel = readinputport(6));
  case 0x02: return accel;
  case 0x03: return wheel;
 }
 return 0xff;
}

canonical_original_code:
static unsigned int analog_read_r(unsigned int offset)
{
 static int accel; static int wheel;
 switch (analog_ctrl & 0x03){
  case 0x00: return (accel = readinputport(5));
  case 0x01: return (wheel = readinputport(6));
  case 0x02: return accel;
  case 0x03: return wheel;
 }
 return 0xff;
}

variable_types: accel int

variable_types: wheel int

return_type: unsigned int


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = zoom_colorbase + ((*a2 >> 2) & 0xFu);
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = zoom_colorbase + ((*a2 >> 2) & 0xFu);
*a2 = result;
return result;
}

original_code:
static void zoom_callback_0(int *code,int *color)
{
 *code |= ((*color & 0x03) << 8);
 *color = zoom_colorbase[0] + ((*color & 0x3c) >> 2);
}

canonical_original_code:
static void zoom_callback_0(int *code, int *color)
{
 *code |= ((*color & 0x03) << 8);
 *color = zoom_colorbase[0] + ((*color & 0x3c) >> 2);
}

variable_types:
code
int *

variable_types:
color
int *


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

tile_info[5] = (*a2 >> 6) & 3;
*a1 |= ((unsigned __int16)*a2 << 8) & 0xF00;
result = zoom_colorbase[1] + ((*a2 >> 4) & 3u);
*a2 = result;
return result;
}

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

tile_info[5] = (*a2 >> 6) & 3;
*a1 |= ((unsigned __int16)*a2 << 8) & 0xF00;
result = zoom_colorbase[1] + ((*a2 >> 4) & 3u);
*a2 = result;
return result;
}

original_code:
static void zoom_callback_1(int *code,int *color)
{
 tile_info.flags = ((*color & 0xc0) >> 6);
 *code |= ((*color & 0x0f) << 8);
 *color = zoom_colorbase[1] + ((*color & 0x30) >> 4);
}

canonical_original_code:
static void zoom_callback_1(int *code, int *color)
{
 tile_info.flags = ((*color & 0xc0) >> 6);
 *code |= ((*color & 0x0f) << 8);
 *color = zoom_colorbase[1] + ((*color & 0x30) >> 4);
}


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

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return K007232_set_volume(
1LL,
1LL,
(unsigned int)((17 * (a1 & 0xF)) >> 1),
(unsigned int)((int)((a1 & 0xFFFFFFF0) + (a1 >> 4)) / 2));
}

original_code:
static void volume_callback1(int v)
{
 K007232_set_volume(1,1,(v & 0x0f)*0x11/2,(v >> 4)*0x11/2);
}

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 func11(int a1)
{
K007232_set_volume(0LL, 0LL, (a1 >> 4) + (a1 & 0xFFFFFFF0), 0LL);
return K007232_set_volume(0LL, 1LL, 0LL, 17 * (a1 & 0xFu));
}


decompiled_code:
__int64 __fastcall kangaroo_vh_convert_color_prom(__int64 a1)
{
__int64 result; // rax
char v2; // dl

result = *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL);
if ( (_DWORD)result )
{
LODWORD(result) = 0;
do
{
a1 += 3LL;
*(_BYTE *)(a1 - 3) = -(((int)result >> 2) & 1);
*(_BYTE *)(a1 - 2) = -(((int)result >> 1) & 1);
v2 = result;
result = (unsigned int)(result + 1);
*(_BYTE *)(a1 - 1) = -(v2 & 1);
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > (unsigned int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
char v2; // dl

result = *(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 696LL);
if ( (_DWORD)result )
{
LODWORD(result) = 0;
do
{
a1 += 3LL;
*(_BYTE *)(a1 - 3) = -(((int)result >> 2) & 1);
*(_BYTE *)(a1 - 2) = -(((int)result >> 1) & 1);
v2 = result;
result = (unsigned int)(result + 1);
*(_BYTE *)(a1 - 1) = -(v2 & 1);
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > (unsigned int)result );
}
return result;
}

original_code:
void kangaroo_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++)
 {
  *(palette++) = ((i & 4) >> 2) * 0xff;
  *(palette++) = ((i & 2) >> 1) * 0xff;
  *(palette++) = ((i & 1) >> 0) * 0xff;
 }
}

canonical_original_code:
void kangaroo_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++)
 {
  *(palette++) = ((i & 4) >> 2) * 0xff;
  *(palette++) = ((i & 2) >> 1) * 0xff;
  *(palette++) = ((i & 1) >> 0) * 0xff;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 __fastcall kangaroo_plot_pixel(_DWORD *a1, __int64 a2, __int64 a3, char a4, int a5, int a6)
{
if ( a6 )
{
a2 = (unsigned int)(*a1 + ~(_DWORD)a2);
a3 = (unsigned int)(a1[1] + ~(_DWORD)a3);
}
if ( (a4 & 8) != 0 )
a5 = 0;
return plot_pixel(a1, a2, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a5 + (a4 & 7))));
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, __int64 a2, __int64 a3, char a4, int a5, int a6)
{
if ( a6 )
{
a2 = (unsigned int)(*a1 + ~(_DWORD)a2);
a3 = (unsigned int)(a1[1] + ~(_DWORD)a3);
}
if ( (a4 & 8) != 0 )
a5 = 0;
return plot_pixel(a1, a2, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (a5 + (a4 & 7))));
}

original_code:
static inline void kangaroo_plot_pixel(struct osd_bitmap *bitmap, int x, int y, int col, int color_base, int flip)
{
 if (flip)
 {
  x = bitmap->width - 1 - x;
  y = bitmap->height - 1 - y;
 }
 plot_pixel(bitmap, x, y, Machine->pens[((col & 0x08) ? 0 : color_base) + (col & 0x07)]);
}

variable_types: x int

variable_types: y int

variable_types: col int

variable_types: flip int

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


decompiled_code:
__int64 __fastcall kangaroo_redraw_4pixels(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
__int64 v3; // r15
int v4; // er13
__int64 v5; // rbx
__int64 v7; // [rsp+0h] [rbp-58h]
__int64 v8; // [rsp+8h] [rbp-50h]
int v9; // [rsp+14h] [rbp-44h]

v2 = a1 + (a2 << 8);
v3 = (int)(v2 + 2);
v7 = (int)v2;
v4 = *kangaroo_video_control & 0x10;
v9 = *kangaroo_video_control & 0x20;
kangaroo_plot_pixel(tmpbitmap, a1, a2, *(_BYTE *)(videoram + (int)v2) & 0xF, 8, v9);
v8 = (int)(v2 + 1);
v5 = (int)(v2 + 3);
kangaroo_plot_pixel(tmpbitmap, a1 + 1, a2, *(_BYTE *)(videoram + v8) & 0xF, 8, v9);
kangaroo_plot_pixel(tmpbitmap, a1 + 2, a2, *(_BYTE *)(videoram + v3) & 0xF, 8, v9);
kangaroo_plot_pixel(tmpbitmap, a1 + 3, a2, *(_BYTE *)(videoram + v5) & 0xF, 8, v9);
kangaroo_plot_pixel((_DWORD *)tmpbitmap2, a1, a2, *(_BYTE *)(videoram + v7) >> 4, 16, v4);
kangaroo_plot_pixel((_DWORD *)tmpbitmap2, a1 + 1, a2, *(_BYTE *)(videoram + v8) >> 4, 16, v4);
kangaroo_plot_pixel((_DWORD *)tmpbitmap2, a1 + 2, a2, *(_BYTE *)(videoram + v3) >> 4, 16, v4);
return kangaroo_plot_pixel((_DWORD *)tmpbitmap2, a1 + 3, a2, *(_BYTE *)(videoram + v5) >> 4, 16, v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
__int64 v3; // r15
int v4; // er13
__int64 v5; // rbx
__int64 v7; // [rsp+0h] [rbp-58h]
__int64 v8; // [rsp+8h] [rbp-50h]
int v9; // [rsp+14h] [rbp-44h]

v2 = a1 + (a2 << 8);
v3 = (int)(v2 + 2);
v7 = (int)v2;
v4 = *kangaroo_video_control & 0x10;
v9 = *kangaroo_video_control & 0x20;
func2(tmpbitmap, a1, a2, *(_BYTE *)(videoram + (int)v2) & 0xF, 8, v9);
v8 = (int)(v2 + 1);
v5 = (int)(v2 + 3);
func2(tmpbitmap, a1 + 1, a2, *(_BYTE *)(videoram + v8) & 0xF, 8, v9);
func2(tmpbitmap, a1 + 2, a2, *(_BYTE *)(videoram + v3) & 0xF, 8, v9);
func2(tmpbitmap, a1 + 3, a2, *(_BYTE *)(videoram + v5) & 0xF, 8, v9);
func2((_DWORD *)tmpbitmap2, a1, a2, *(_BYTE *)(videoram + v7) >> 4, 16, v4);
func2((_DWORD *)tmpbitmap2, a1 + 1, a2, *(_BYTE *)(videoram + v8) >> 4, 16, v4);
func2((_DWORD *)tmpbitmap2, a1 + 2, a2, *(_BYTE *)(videoram + v3) >> 4, 16, v4);
return func2((_DWORD *)tmpbitmap2, a1 + 3, a2, *(_BYTE *)(videoram + v5) >> 4, 16, v4);
}

original_code:
static inline void kangaroo_redraw_4pixels(int x, int y)
{
 int offs, flipA, flipB;
 offs = y * 256 + x;
 flipA = *kangaroo_video_control & 0x20;
 flipB = *kangaroo_video_control & 0x10;
 kangaroo_plot_pixel(tmpbitmap , x , y, videoram[offs ] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap , x+1, y, videoram[offs+1] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap , x+2, y, videoram[offs+2] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap , x+3, y, videoram[offs+3] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap2, x , y, videoram[offs ] >> 4, 16, flipB);
 kangaroo_plot_pixel(tmpbitmap2, x+1, y, videoram[offs+1] >> 4, 16, flipB);
 kangaroo_plot_pixel(tmpbitmap2, x+2, y, videoram[offs+2] >> 4, 16, flipB);
 kangaroo_plot_pixel(tmpbitmap2, x+3, y, videoram[offs+3] >> 4, 16, flipB);
}

canonical_original_code:
static inline void kangaroo_redraw_4pixels(int x, int y)
{
 int offs; int flipA; int flipB;
 offs = y * 256 + x;
 flipA = *kangaroo_video_control & 0x20;
 flipB = *kangaroo_video_control & 0x10;
 kangaroo_plot_pixel(tmpbitmap , x , y, videoram[offs ] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap , x+1, y, videoram[offs+1] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap , x+2, y, videoram[offs+2] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap , x+3, y, videoram[offs+3] & 0x0f, 8, flipA);
 kangaroo_plot_pixel(tmpbitmap2, x , y, videoram[offs ] >> 4, 16, flipB);
 kangaroo_plot_pixel(tmpbitmap2, x+1, y, videoram[offs+1] >> 4, 16, flipB);
 kangaroo_plot_pixel(tmpbitmap2, x+2, y, videoram[offs+2] >> 4, 16, flipB);
 kangaroo_plot_pixel(tmpbitmap2, x+3, y, videoram[offs+3] >> 4, 16, flipB);
}

variable_types: offs int

variable_types: flipA int

variable_types: flipB int


original_code:
void kangaroo_videoram_w(offs_t offset,data_t data)
{
 int a_Z_R,a_G_B,b_Z_R,b_G_B;
 int sx, sy, offs;
 a_Z_R = *kangaroo_bank_select & 0x01;
 a_G_B = *kangaroo_bank_select & 0x02;
 b_Z_R = *kangaroo_bank_select & 0x04;
 b_G_B = *kangaroo_bank_select & 0x08;
 sx = (offset / 256) * 4;
 sy = offset % 256;
 offs = sy * 256 + sx;
 if (a_G_B)
 {
  videoram[offs ] = (videoram[offs ] & 0xfc) | ((data & 0x10) >> 3) | ((data & 0x01) >> 0);
  videoram[offs+1] = (videoram[offs+1] & 0xfc) | ((data & 0x20) >> 4) | ((data & 0x02) >> 1);
  videoram[offs+2] = (videoram[offs+2] & 0xfc) | ((data & 0x40) >> 5) | ((data & 0x04) >> 2);
  videoram[offs+3] = (videoram[offs+3] & 0xfc) | ((data & 0x80) >> 6) | ((data & 0x08) >> 3);
 }
 if (a_Z_R)
 {
  videoram[offs ] = (videoram[offs ] & 0xf3) | ((data & 0x10) >> 1) | ((data & 0x01) << 2);
  videoram[offs+1] = (videoram[offs+1] & 0xf3) | ((data & 0x20) >> 2) | ((data & 0x02) << 1);
  videoram[offs+2] = (videoram[offs+2] & 0xf3) | ((data & 0x40) >> 3) | ((data & 0x04) >> 0);
  videoram[offs+3] = (videoram[offs+3] & 0xf3) | ((data & 0x80) >> 4) | ((data & 0x08) >> 1);
 }
 if (b_G_B)
 {
  videoram[offs ] = (videoram[offs ] & 0xcf) | ((data & 0x10) << 1) | ((data & 0x01) << 4);
  videoram[offs+1] = (videoram[offs+1] & 0xcf) | ((data & 0x20) >> 0) | ((data & 0x02) << 3);
  videoram[offs+2] = (videoram[offs+2] & 0xcf) | ((data & 0x40) >> 1) | ((data & 0x04) << 2);
  videoram[offs+3] = (videoram[offs+3] & 0xcf) | ((data & 0x80) >> 2) | ((data & 0x08) << 1);
 }
 if (b_Z_R)
 {
  videoram[offs ] = (videoram[offs ] & 0x3f) | ((data & 0x10) << 3) | ((data & 0x01) << 6);
  videoram[offs+1] = (videoram[offs+1] & 0x3f) | ((data & 0x20) << 2) | ((data & 0x02) << 5);
  videoram[offs+2] = (videoram[offs+2] & 0x3f) | ((data & 0x40) << 1) | ((data & 0x04) << 4);
  videoram[offs+3] = (videoram[offs+3] & 0x3f) | ((data & 0x80) << 0) | ((data & 0x08) << 3);
 }
 kangaroo_redraw_4pixels(sx, sy);
}

canonical_original_code:
void kangaroo_videoram_w(unsigned int offset, unsigned int data)
{
 int a_Z_R; int a_G_B; int b_Z_R; int b_G_B;
 int sx; int sy; int offs;
 a_Z_R = *kangaroo_bank_select & 0x01;
 a_G_B = *kangaroo_bank_select & 0x02;
 b_Z_R = *kangaroo_bank_select & 0x04;
 b_G_B = *kangaroo_bank_select & 0x08;
 sx = (offset / 256) * 4;
 sy = offset % 256;
 offs = sy * 256 + sx;
 if (a_G_B)
 {
  videoram[offs ] = (videoram[offs ] & 0xfc) | ((data & 0x10) >> 3) | ((data & 0x01) >> 0);
  videoram[offs+1] = (videoram[offs+1] & 0xfc) | ((data & 0x20) >> 4) | ((data & 0x02) >> 1);
  videoram[offs+2] = (videoram[offs+2] & 0xfc) | ((data & 0x40) >> 5) | ((data & 0x04) >> 2);
  videoram[offs+3] = (videoram[offs+3] & 0xfc) | ((data & 0x80) >> 6) | ((data & 0x08) >> 3);
 }
 if (a_Z_R)
 {
  videoram[offs ] = (videoram[offs ] & 0xf3) | ((data & 0x10) >> 1) | ((data & 0x01) << 2);
  videoram[offs+1] = (videoram[offs+1] & 0xf3) | ((data & 0x20) >> 2) | ((data & 0x02) << 1);
  videoram[offs+2] = (videoram[offs+2] & 0xf3) | ((data & 0x40) >> 3) | ((data & 0x04) >> 0);
  videoram[offs+3] = (videoram[offs+3] & 0xf3) | ((data & 0x80) >> 4) | ((data & 0x08) >> 1);
 }
 if (b_G_B)
 {
  videoram[offs ] = (videoram[offs ] & 0xcf) | ((data & 0x10) << 1) | ((data & 0x01) << 4);
  videoram[offs+1] = (videoram[offs+1] & 0xcf) | ((data & 0x20) >> 0) | ((data & 0x02) << 3);
  videoram[offs+2] = (videoram[offs+2] & 0xcf) | ((data & 0x40) >> 1) | ((data & 0x04) << 2);
  videoram[offs+3] = (videoram[offs+3] & 0xcf) | ((data & 0x80) >> 2) | ((data & 0x08) << 1);
 }
 if (b_Z_R)
 {
  videoram[offs ] = (videoram[offs ] & 0x3f) | ((data & 0x10) << 3) | ((data & 0x01) << 6);
  videoram[offs+1] = (videoram[offs+1] & 0x3f) | ((data & 0x20) << 2) | ((data & 0x02) << 5);
  videoram[offs+2] = (videoram[offs+2] & 0x3f) | ((data & 0x40) << 1) | ((data & 0x04) << 4);
  videoram[offs+3] = (videoram[offs+3] & 0x3f) | ((data & 0x80) << 0) | ((data & 0x08) << 3);
 }
 kangaroo_redraw_4pixels(sx, sy);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 kangaroo_sec_chip_r()
{
return ++kangaroo_clock & 0xF;
}

canonical_decompiled_code:
__int64 func5()
{
return ++kangaroo_clock & 0xF;
}

original_code:
static data_t kangaroo_sec_chip_r(offs_t offset)
{
  kangaroo_clock++;
  return (kangaroo_clock & 0x0f);
}

canonical_original_code:
static unsigned int kangaroo_sec_chip_r(unsigned int offset)
{
  kangaroo_clock++;
  return (kangaroo_clock & 0x0f);
}


decompiled_code:
void kangaroo_sec_chip_w()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
static void kangaroo_sec_chip_w(offs_t offset,data_t data)
{
}

canonical_original_code:
static void kangaroo_sec_chip_w(unsigned int offset, unsigned int data)
{
}


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

v0 = 1;
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap )
return v0;
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
{
videoram = malloc(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) * *(_DWORD *)(*(_QWORD *)(Machine + 824LL)
+ 664LL));
v0 = 0;
if ( !videoram )
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
}
return v0;
}
bitmap_free(tmpbitmap);
return 1LL;
}

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

v0 = 1;
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap )
return v0;
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( tmpbitmap2 )
{
videoram = malloc(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) * *(_DWORD *)(*(_QWORD *)(Machine + 824LL)
+ 664LL));
v0 = 0;
if ( !videoram )
{
bitmap_free(tmpbitmap);
bitmap_free(tmpbitmap2);
}
return v0;
}
bitmap_free(tmpbitmap);
return 1LL;
}

original_code:
int kangaroo_vh_start(void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 if ((videoram = (unsigned char*)malloc(Machine->drv->screen_width*Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  bitmap_free(tmpbitmap2);
 }
 return 0;
}

canonical_original_code:
int kangaroo_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 if ((videoram = (unsigned char *)malloc(Machine->drv->screen_width*Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  bitmap_free(tmpbitmap2);
 }
 return 0;
}


decompiled_code:
void kangaroo_vh_stop()
{
bitmap_free(tmpbitmap2);
bitmap_free(tmpbitmap);
free(videoram);
}

canonical_decompiled_code:
void func8()
{
bitmap_free(tmpbitmap2);
bitmap_free(tmpbitmap);
free(videoram);
}

original_code:
void kangaroo_vh_stop(void)
{
 bitmap_free(tmpbitmap2);
 bitmap_free(tmpbitmap);
 free(videoram);
}


canonical_original_code:
void kangaroo_color_mask_w(unsigned int offset, unsigned int data)
{
 int i;
 for (i = 0;i < 8;i++)
 {
  int r; int g; int b;
  r = ((i & 4) >> 2) * ((data & 0x20) ? 0xff : 0x7f);
  g = ((i & 2) >> 1) * ((data & 0x10) ? 0xff : 0x7f);
  b = ((i & 1) >> 0) * ((data & 0x08) ? 0xff : 0x7f);
  palette_change_color(8+i,r,g,b);
 }
 for (i = 0;i < 8;i++)
 {
  int r; int g; int b;
  r = ((i & 4) >> 2) * ((data & 0x04) ? 0xff : 0x7f);
  g = ((i & 2) >> 1) * ((data & 0x02) ? 0xff : 0x7f);
  b = ((i & 1) >> 0) * ((data & 0x01) ? 0xff : 0x7f);
  palette_change_color(16+i,r,g,b);
 }
}

variable_types: i int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall kangaroo_vh_screenrefresh(__int64 a1)
{
unsigned int v1; // ebp
unsigned int i; // ebx
unsigned int v3; // esi
__int64 result; // rax
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 0;
if ( palette_recalc() || screen_flipped )
{
do
{
for ( i = 0; i != 256; ++i )
{
v3 = i;
kangaroo_redraw_4pixels(v1, v3);
}
v1 += 4;
}
while ( v1 != 256 );
screen_flipped = 0;
}
v5 = (unsigned __int8)kangaroo_scroll[1];
v6[0] = (unsigned __int8)*kangaroo_scroll;
if ( (*kangaroo_bank_select & 1) != 0 )
{
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copyscrollbitmap(a1, tmpbitmap, 1LL, &v5, 1LL, v6, Machine + 776LL, 6LL, 8LL);
}
else
{
copyscrollbitmap(a1, tmpbitmap, 1LL, &v5, 1LL, v6, Machine + 776LL, 0LL, 0LL);
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 16LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v1; // ebp
unsigned int i; // ebx
unsigned int v3; // esi
__int64 result; // rax
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 0;
if ( palette_recalc() || screen_flipped )
{
do
{
for ( i = 0; i != 256; ++i )
{
v3 = i;
func3(v1, v3);
}
v1 += 4;
}
while ( v1 != 256 );
screen_flipped = 0;
}
v5 = (unsigned __int8)kangaroo_scroll[1];
v6[0] = (unsigned __int8)*kangaroo_scroll;
if ( (*kangaroo_bank_select & 1) != 0 )
{
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copyscrollbitmap(a1, tmpbitmap, 1LL, &v5, 1LL, v6, Machine + 776LL, 6LL, 8LL);
}
else
{
copyscrollbitmap(a1, tmpbitmap, 1LL, &v5, 1LL, v6, Machine + 776LL, 0LL, 0LL);
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 16LL);
}
return result;
}

original_code:
void kangaroo_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int scrollx, scrolly;
 if (palette_recalc() || screen_flipped)
 {
  int x, y;
  for (x = 0; x < 256; x+=4)
  {
   for (y = 0; y < 256; y++)
   {
    kangaroo_redraw_4pixels(x, y);
   }
  }
  screen_flipped = 0;
 }
 scrollx = kangaroo_scroll[1];
 scrolly = kangaroo_scroll[0];
 if (*kangaroo_bank_select & 0x01)
 {
  copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_COLOR,8);
 }
 else
 {
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
  copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,16);
 }
}

canonical_original_code:
void kangaroo_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int scrollx; int scrolly;
 if (palette_recalc() || screen_flipped)
 {
  int x; int y;
  for (x = 0; x < 256; x+=4)
  {
   for (y = 0; y < 256; y++)
   {
    kangaroo_redraw_4pixels(x, y);
   }
  }
  screen_flipped = 0;
 }
 scrollx = kangaroo_scroll[1];
 scrolly = kangaroo_scroll[0];
 if (*kangaroo_bank_select & 0x01)
 {
  copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_COLOR,8);
 }
 else
 {
  copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
  copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,16);
 }
}

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

variable_types: scrollx int

variable_types: scrolly int


decompiled_code:
__int64 kangaroo_init_machine()
{
return cpu_cause_interrupt(0LL, 4294967294LL);
}

canonical_decompiled_code:
__int64 func12()
{
return cpu_cause_interrupt(0LL, 4294967294LL);
}

original_code:
static void kangaroo_init_machine(void)
{
 cpu_cause_interrupt(0,-2);
}

canonical_original_code:
static void kangaroo_init_machine()
{
 cpu_cause_interrupt(0,-2);
}


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

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

original_code:
static void kangaroo_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(0, data & 1);
 coin_counter_w(1, data & 2);
}

canonical_original_code:
static void kangaroo_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0, data & 1);
 coin_counter_w(1, data & 2);
}


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

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

original_code:
data_t safarir_ram_r(offs_t offset)
{
 return safarir_ram[offset];
}

canonical_original_code:
unsigned int safarir_ram_r(unsigned int offset)
{
 return safarir_ram[offset];
}


decompiled_code:
void __fastcall safarir_scroll_w(__int64 a1, int a2)
{
safarir_scroll = a2;
}

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

original_code:
void safarir_scroll_w(offs_t offset,data_t data)
{
 safarir_scroll = data;
}

canonical_original_code:
void safarir_scroll_w(unsigned int offset, unsigned int data)
{
 safarir_scroll = data;
}


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

if ( a2 )
{
result = safarir_ram1;
safarir_ram = safarir_ram1;
}
else
{
result = safarir_ram2;
safarir_ram = safarir_ram2;
}
return result;
}

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

if ( a2 )
{
result = safarir_ram1;
safarir_ram = safarir_ram1;
}
else
{
result = safarir_ram2;
safarir_ram = safarir_ram2;
}
return result;
}

original_code:
void safarir_ram_bank_w(offs_t offset,data_t data)
{
 safarir_ram = data ? safarir_ram1 : safarir_ram2;
}

canonical_original_code:
void safarir_ram_bank_w(unsigned int offset, unsigned int data)
{
 safarir_ram = data ? safarir_ram1 : safarir_ram2;
}


updatepixels

decompiled_code:
__int64 __fastcall updatepixels(signed int a1, unsigned int a2)
{
__int64 result; // rax
int v4; // esi
unsigned __int16 v5; // r15
__int16 v6; // bp
int v7; // edx

result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= a1
&& *(_DWORD *)(Machine + 780LL) >= a1
&& *(_DWORD *)(Machine + 784LL) <= (signed int)a2
&& *(_DWORD *)(Machine + 788LL) >= (signed int)a2 )
{
v4 = a2 << 9;
v5 = *(_WORD *)(blockout_videoram + v4 + a1);
v6 = *(_WORD *)(blockout_videoram + v4 + a1 + 0x20000);
v7 = HIBYTE(v5);
if ( (v5 & 0xFF00) == 0 )
v7 = HIBYTE(v6) + 256;
plot_pixel(tmpbitmap, (unsigned int)a1, a2, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v7));
v5 = (unsigned __int8)v5;
if ( !(_BYTE)v5 )
v5 = (unsigned __int8)v6 + 256;
result = plot_pixel(
tmpbitmap,
(unsigned int)(a1 + 1),
a2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v5));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(signed int a1, unsigned int a2)
{
__int64 result; // rax
int v4; // esi
unsigned __int16 v5; // r15
__int16 v6; // bp
int v7; // edx

result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= a1
&& *(_DWORD *)(Machine + 780LL) >= a1
&& *(_DWORD *)(Machine + 784LL) <= (signed int)a2
&& *(_DWORD *)(Machine + 788LL) >= (signed int)a2 )
{
v4 = a2 << 9;
v5 = *(_WORD *)(blockout_videoram + v4 + a1);
v6 = *(_WORD *)(blockout_videoram + v4 + a1 + 0x20000);
v7 = HIBYTE(v5);
if ( (v5 & 0xFF00) == 0 )
v7 = HIBYTE(v6) + 256;
plot_pixel(tmpbitmap, (unsigned int)a1, a2, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v7));
v5 = (unsigned __int8)v5;
if ( !(_BYTE)v5 )
v5 = (unsigned __int8)v6 + 256;
result = plot_pixel(
tmpbitmap,
(unsigned int)(a1 + 1),
a2,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v5));
}
return result;
}

original_code:
static void updatepixels(int x,int y)
{
 int front,back;
 int color;
 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)
  return;
 front = (*(UINT16 *)(&blockout_videoram[(y<<9)+x]));
 back = (*(UINT16 *)(&blockout_videoram[0x20000 + (y<<9)+x]));
 if (front>>8) color = front>>8;
 else color = (back>>8) + 256;
 plot_pixel(tmpbitmap, x, y, Machine->pens[color]);
 if (front&0xff) color = front&0xff;
 else color = (back&0xff) + 256;
 plot_pixel(tmpbitmap, x+1, y, Machine->pens[color]);
}

canonical_original_code:
static void updatepixels(int x, int y)
{
 int front; int back;
 int color;
 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)
  return;
 front = (*(unsigned short *)(&blockout_videoram[(y<<9)+x]));
 back = (*(unsigned short *)(&blockout_videoram[0x20000 + (y<<9)+x]));
 if (front>>8) color = front>>8;
 else color = (back>>8) + 256;
 plot_pixel(tmpbitmap, x, y, Machine->pens[color]);
 if (front&0xff) color = front&0xff;
 else color = (back&0xff) + 256;
 plot_pixel(tmpbitmap, x+1, y, Machine->pens[color]);
}

variable_types: x int

variable_types: y int

variable_types: front int

variable_types: back int

variable_types: color int


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

v2 = (_WORD *)(blockout_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = updatepixels(a1 & 0x1FF, (unsigned __int8)(a1 >> 9));
}
return result;
}

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

v2 = (_WORD *)(blockout_videoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = func0(a1 & 0x1FF, (unsigned __int8)(a1 >> 9));
}
return result;
}

original_code:
void blockout_videoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&blockout_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(UINT16 *)(&blockout_videoram[offset]) = (newword));
  updatepixels(offset % 512,(offset>>9) % 256);
 }
}

canonical_original_code:
void blockout_videoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&blockout_videoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  (*(unsigned short *)(&blockout_videoram[offset]) = (newword));
  updatepixels(offset % 512,(offset>>9) % 256);
 }
}

variable_types: oldword int

variable_types: newword int


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

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

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

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

variable_types:
offset
unsigned int


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

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

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

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


decompiled_code:
__int64 __fastcall blockout_paletteram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // esi

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return setcolor(a1 >> 1, v3);
}

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

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return func5(a1 >> 1, v3);
}

original_code:
void blockout_paletteram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 setcolor(offset>>1, newword);
}

canonical_original_code:
void blockout_paletteram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 setcolor(offset>>1, newword);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall blockout_frontcolor_w(__int64 a1, int a2)
{
return setcolor(512LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
return func5(512LL, a2);
}

original_code:
void blockout_frontcolor_w(offs_t offset,data_t data)
{
 setcolor(512,data);
}

canonical_original_code:
void blockout_frontcolor_w(unsigned int offset, unsigned int data)
{
 setcolor(512,data);
}


decompiled_code:
_BOOL8 blockout_vh_start()
{
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
return tmpbitmap == 0LL;
}

canonical_decompiled_code:
_BOOL8 func8()
{
tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
return tmpbitmap == 0LL;
}

original_code:
int blockout_vh_start (void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 return 0;
}

canonical_original_code:
int blockout_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 return 0;
}


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

result = bitmap_free(tmpbitmap);
tmpbitmap = 0LL;
return result;
}

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

result = bitmap_free(tmpbitmap);
tmpbitmap = 0LL;
return result;
}

original_code:
void blockout_vh_stop (void)
{
 bitmap_free(tmpbitmap);
 tmpbitmap = 0;
}

canonical_original_code:
void blockout_vh_stop()
{
 bitmap_free(tmpbitmap);
 tmpbitmap = 0;
}


decompiled_code:
__int64 __fastcall blockout_vh_screenrefresh(__int64 a1)
{
unsigned int v2; // ebp
signed int i; // ebx
signed int v4; // edi
unsigned int v5; // ebp
unsigned int v6; // er13
int j; // ebx
__int64 result; // rax
__int16 v9; // r14

v2 = 0;
if ( palette_recalc() )
{
do
{
for ( i = 0; i != 320; i += 2 )
{
v4 = i;
updatepixels(v4, v2);
}
++v2;
}
while ( v2 != 256 );
}
v5 = 0;
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v6 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1024LL);
do
{
for ( j = 0; j != 320; j += 8 )
{
result = (int)((v5 << 7) + (j >> 2));
v9 = *(_WORD *)(blockout_frontvideoram + result);
if ( v9 )
{
if ( (v9 & 0x80u) != 0 )
result = plot_pixel(a1, (unsigned int)j, v5, v6);
if ( (v9 & 0x40) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 1), v5, v6);
if ( (v9 & 0x20) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 2), v5, v6);
if ( (v9 & 0x10) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 3), v5, v6);
if ( (v9 & 8) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 4), v5, v6);
if ( (v9 & 4) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 5), v5, v6);
if ( (v9 & 2) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 6), v5, v6);
if ( (v9 & 1) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 7), v5, v6);
}
}
++v5;
}
while ( v5 != 256 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v2; // ebp
signed int i; // ebx
signed int v4; // edi
unsigned int v5; // ebp
unsigned int v6; // er13
int j; // ebx
__int64 result; // rax
__int16 v9; // r14

v2 = 0;
if ( palette_recalc() )
{
do
{
for ( i = 0; i != 320; i += 2 )
{
v4 = i;
func0(v4, v2);
}
++v2;
}
while ( v2 != 256 );
}
v5 = 0;
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
v6 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 1024LL);
do
{
for ( j = 0; j != 320; j += 8 )
{
result = (int)((v5 << 7) + (j >> 2));
v9 = *(_WORD *)(blockout_frontvideoram + result);
if ( v9 )
{
if ( (v9 & 0x80u) != 0 )
result = plot_pixel(a1, (unsigned int)j, v5, v6);
if ( (v9 & 0x40) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 1), v5, v6);
if ( (v9 & 0x20) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 2), v5, v6);
if ( (v9 & 0x10) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 3), v5, v6);
if ( (v9 & 8) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 4), v5, v6);
if ( (v9 & 4) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 5), v5, v6);
if ( (v9 & 2) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 6), v5, v6);
if ( (v9 & 1) != 0 )
result = plot_pixel(a1, (unsigned int)(j + 7), v5, v6);
}
}
++v5;
}
while ( v5 != 256 );
return result;
}

original_code:
void blockout_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (palette_recalc())
 {
  int x,y;
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=2)
   {
    updatepixels(x,y);
   }
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 {
  int x,y,color;
  color = Machine->pens[512];
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=8)
   {
    int d;
    d = (*(UINT16 *)(&blockout_frontvideoram[(y<<7)+(x>>2)]));
    if (d)
    {
     if (d&0x80) plot_pixel(bitmap, x , y, color);
     if (d&0x40) plot_pixel(bitmap, x+1, y, color);
     if (d&0x20) plot_pixel(bitmap, x+2, y, color);
     if (d&0x10) plot_pixel(bitmap, x+3, y, color);
     if (d&0x08) plot_pixel(bitmap, x+4, y, color);
     if (d&0x04) plot_pixel(bitmap, x+5, y, color);
     if (d&0x02) plot_pixel(bitmap, x+6, y, color);
     if (d&0x01) plot_pixel(bitmap, x+7, y, color);
    }
   }
  }
 }
}

canonical_original_code:
void blockout_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (palette_recalc())
 {
  int x; int y;
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=2)
   {
    updatepixels(x,y);
   }
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 {
  int x; int y; int color;
  color = Machine->pens[512];
  for (y = 0;y < 256;y++)
  {
   for (x = 0;x < 320;x+=8)
   {
    int d;
    d = (*(unsigned short *)(&blockout_frontvideoram[(y<<7)+(x>>2)]));
    if (d)
    {
     if (d&0x80) plot_pixel(bitmap, x , y, color);
     if (d&0x40) plot_pixel(bitmap, x+1, y, color);
     if (d&0x20) plot_pixel(bitmap, x+2, y, color);
     if (d&0x10) plot_pixel(bitmap, x+3, y, color);
     if (d&0x08) plot_pixel(bitmap, x+4, y, color);
     if (d&0x04) plot_pixel(bitmap, x+5, y, color);
     if (d&0x02) plot_pixel(bitmap, x+6, y, color);
     if (d&0x01) plot_pixel(bitmap, x+7, y, color);
    }
   }
  }
 }
}

variable_types: d int


decompiled_code:
__int64 blockout_interrupt()
{
return 6 - (unsigned int)cpu_getiloops();
}

canonical_decompiled_code:
__int64 func11()
{
return 6 - (unsigned int)cpu_getiloops();
}

original_code:
int blockout_interrupt(void)
{
 return 6 - cpu_getiloops();
}

canonical_original_code:
int blockout_interrupt()
{
 return 6 - cpu_getiloops();
}


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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 2:
result = input_port_1_r(2LL);
break;
case 4:
result = input_port_2_r(4LL);
break;
case 6:
result = input_port_3_r(6LL);
break;
case 8:
result = input_port_4_r(8LL);
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 2:
result = input_port_1_r(2LL);
break;
case 4:
result = input_port_2_r(4LL);
break;
case 6:
result = input_port_3_r(6LL);
break;
case 8:
result = input_port_4_r(8LL);
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
data_t blockout_input_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return input_port_0_r(offset);
  case 2:
   return input_port_1_r(offset);
  case 4:
   return input_port_2_r(offset);
  case 6:
   return input_port_3_r(offset);
  case 8:
   return input_port_4_r(offset);
  default:
   return 0;
 }
}

canonical_original_code:
unsigned int blockout_input_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return input_port_0_r(offset);
  case 2:
   return input_port_1_r(offset);
  case 4:
   return input_port_2_r(offset);
  case 6:
   return input_port_3_r(offset);
  case 8:
   return input_port_4_r(offset);
  default:
   return 0;
 }
}


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

if ( !(_DWORD)a1 )
{
soundlatch_w(a1, a2);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

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

if ( !(_DWORD)a1 )
{
soundlatch_w(a1, a2);
result = cpu_cause_interrupt(1LL, 4294967294LL);
}
return result;
}

original_code:
void blockout_sound_command_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0:
   soundlatch_w(offset,data & 0xff);
   cpu_cause_interrupt(1,-2);
   break;
  case 2:
   break;
 }
}

canonical_original_code:
void blockout_sound_command_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0:
   soundlatch_w(offset,data & 0xff);
   cpu_cause_interrupt(1,-2);
   break;
  case 2:
   break;
 }
}


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

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

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

variable_types: irq int


setcolor

canonical_original_code:
static void setcolor(int color, int rgb)
{
 int bit0; int bit1; int bit2; int bit3;
 int r; int g; int b;
 bit0 = (rgb >> 0) & 0x01;
 bit1 = (rgb >> 1) & 0x01;
 bit2 = (rgb >> 2) & 0x01;
 bit3 = (rgb >> 3) & 0x01;
 r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 bit0 = (rgb >> 4) & 0x01;
 bit1 = (rgb >> 5) & 0x01;
 bit2 = (rgb >> 6) & 0x01;
 bit3 = (rgb >> 7) & 0x01;
 g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 bit0 = (rgb >> 8) & 0x01;
 bit1 = (rgb >> 9) & 0x01;
 bit2 = (rgb >> 10) & 0x01;
 bit3 = (rgb >> 11) & 0x01;
 b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
 palette_change_color(color,r,g,b);
}

variable_types: rgb int

variable_types: r int


decompiled_code:
void *__fastcall llander_init_colors(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // r13
void *result; // rax
__int64 v4; // rdx
int v5; // eax
__int64 v6; // rdx

avg_init_palette_white();
llander_lit_panel = 0LL;
v1 = **(_DWORD **)(Machine + 768LL);
v2 = (unsigned int)(int)((double)(int)v1 * 0.16);
result = (void *)artwork_load_size(
&llander_panel,
"llander.png",
24LL,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 24),
v1,
v2);
if ( llander_panel )
{
v4 = 24LL;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 768LL) + 8LL) == 8 )
v4 = (unsigned int)(*(_DWORD *)(llander_panel + 48) + 24);
artwork_load_size(
&llander_lit_panel,
"llander1.png",
v4,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - v4),
v1,
(unsigned int)v2);
v5 = 0;
v6 = a1 + 24;
if ( llander_lit_panel )
{
do
{
*(_BYTE *)(v6 + 2) = v5;
v6 += 3LL;
*(_BYTE *)(v6 - 2) = v5;
*(_BYTE *)(v6 - 3) = v5;
v5 += 17;
}
while ( (_BYTE)v5 != 16 );
memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_panel + 68)),
*(const void **)(llander_panel + 40),
3 * *(_DWORD *)(llander_panel + 48));
result = memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_lit_panel + 68)),
*(const void **)(llander_lit_panel + 40),
3 * *(_DWORD *)(llander_lit_panel + 48));
}
else
{
result = (void *)artwork_free(&llander_panel, "llander1.png", v6);
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // r13
void *result; // rax
__int64 v4; // rdx
int v5; // eax
__int64 v6; // rdx

avg_init_palette_white();
llander_lit_panel = 0LL;
v1 = **(_DWORD **)(Machine + 768LL);
v2 = (unsigned int)(int)((double)(int)v1 * 0.16);
result = (void *)artwork_load_size(
&llander_panel,
"llander.png",
24LL,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 24),
v1,
v2);
if ( llander_panel )
{
v4 = 24LL;
if ( *(_DWORD *)(*(_QWORD *)(Machine + 768LL) + 8LL) == 8 )
v4 = (unsigned int)(*(_DWORD *)(llander_panel + 48) + 24);
artwork_load_size(
&llander_lit_panel,
"llander1.png",
v4,
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - v4),
v1,
(unsigned int)v2);
v5 = 0;
v6 = a1 + 24;
if ( llander_lit_panel )
{
do
{
*(_BYTE *)(v6 + 2) = v5;
v6 += 3LL;
*(_BYTE *)(v6 - 2) = v5;
*(_BYTE *)(v6 - 3) = v5;
v5 += 17;
}
while ( (_BYTE)v5 != 16 );
memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_panel + 68)),
*(const void **)(llander_panel + 40),
3 * *(_DWORD *)(llander_panel + 48));
result = memcpy(
(void *)(a1 + 3 * *(_DWORD *)(llander_lit_panel + 68)),
*(const void **)(llander_lit_panel + 40),
3 * *(_DWORD *)(llander_lit_panel + 48));
}
else
{
result = (void *)artwork_free(&llander_panel, "llander1.png", v6);
}
}
return result;
}

original_code:
void llander_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int width, height, i, nextcol;
 avg_init_palette_white(palette,colortable,color_prom);
 llander_lit_panel = ((void *)0);
 width = Machine->scrbitmap->width;
 height = 0.16 * width;
 nextcol = 24;
 artwork_load_size(&llander_panel, "llander.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
 if (llander_panel != ((void *)0))
 {
  if (Machine->scrbitmap->depth == 8)
   nextcol += llander_panel->num_pens_used;
  artwork_load_size(&llander_lit_panel, "llander1.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
  if (llander_lit_panel == ((void *)0))
  {
   artwork_free(&llander_panel);
   return ;
  }
 }
 else
  return;
 for (i = 0; i < 16; i++)
  palette[3*(i+8)]=palette[3*(i+8)+1]=palette[3*(i+8)+2]= (255*i)/15;
 memcpy (palette+3*llander_panel->start_pen, llander_panel->orig_palette,
   3*llander_panel->num_pens_used);
 memcpy (palette+3*llander_lit_panel->start_pen, llander_lit_panel->orig_palette,
   3*llander_lit_panel->num_pens_used);
}

canonical_original_code:
void llander_init_colors(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int width; int height; int i; int nextcol;
 avg_init_palette_white(palette,colortable,color_prom);
 llander_lit_panel = ((void *)0);
 width = Machine->scrbitmap->width;
 height = 0.16 * width;
 nextcol = 24;
 artwork_load_size(&llander_panel, "llander.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
 if (llander_panel != ((void *)0))
 {
  if (Machine->scrbitmap->depth == 8)
   nextcol += llander_panel->num_pens_used;
  artwork_load_size(&llander_lit_panel, "llander1.png", nextcol, Machine->drv->total_colors-nextcol, width, height);
  if (llander_lit_panel == ((void *)0))
  {
   artwork_free(&llander_panel);
   return ;
  }
 }
 else
  return;
 for (i = 0; i < 16; i++)
  palette[3*(i+8)]=palette[3*(i+8)+1]=palette[3*(i+8)+2]= (255*i)/15;
 memcpy (palette+3*llander_panel->start_pen, llander_panel->orig_palette,
   3*llander_panel->num_pens_used);
 memcpy (palette+3*llander_lit_panel->start_pen, llander_lit_panel->orig_palette,
   3*llander_lit_panel->num_pens_used);
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: width int

variable_types: height int

variable_types: i int

variable_types: nextcol int


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

v0 = 1;
if ( !(unsigned int)dvg_start() )
{
v0 = 0;
if ( llander_panel )
{
dword_530 = 0;
lights_changed = 0x100000001LL;
qword_508 = 0x100000001LL;
dword_510 = 1;
lights = 0LL;
backdrop_refresh();
if ( llander_lit_panel )
backdrop_refresh();
}
}
return v0;
}

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

v0 = 1;
if ( !(unsigned int)dvg_start() )
{
v0 = 0;
if ( llander_panel )
{
dword_530 = 0;
lights_changed = 0x100000001LL;
qword_508 = 0x100000001LL;
dword_510 = 1;
lights = 0LL;
backdrop_refresh();
if ( llander_lit_panel )
backdrop_refresh();
}
}
return v0;
}

original_code:
int llander_start(void)
{
 int i;
 if (dvg_start())
  return 1;
 if (llander_panel == ((void *)0))
  return 0;
 for (i=0;i<5;i++)
 {
  lights[i] = 0;
  lights_changed[i] = 1;
 }
 if (llander_panel) backdrop_refresh(llander_panel);
 if (llander_lit_panel) backdrop_refresh(llander_lit_panel);
 return 0;
}

canonical_original_code:
int llander_start()
{
 int i;
 if (dvg_start())
  return 1;
 if (llander_panel == ((void *)0))
  return 0;
 for (i=0;i<5;i++)
 {
  lights[i] = 0;
  lights_changed[i] = 1;
 }
 if (llander_panel) backdrop_refresh(llander_panel);
 if (llander_lit_panel) backdrop_refresh(llander_lit_panel);
 return 0;
}


decompiled_code:
__int64 __fastcall llander_stop(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = dvg_stop();
if ( llander_panel )
result = artwork_free(&llander_panel, a2, v3);
if ( llander_lit_panel )
result = artwork_free(&llander_lit_panel, a2, v3);
return result;
}

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

result = dvg_stop();
if ( llander_panel )
result = artwork_free(&llander_panel, a2, v3);
if ( llander_lit_panel )
result = artwork_free(&llander_lit_panel, a2, v3);
return result;
}

original_code:
void llander_stop(void)
{
 dvg_stop();
 if (llander_panel != ((void *)0))
  artwork_free(&llander_panel);
 if (llander_lit_panel != ((void *)0))
  artwork_free(&llander_lit_panel);
}

canonical_original_code:
void llander_stop()
{
 dvg_stop();
 if (llander_panel != ((void *)0))
  artwork_free(&llander_panel);
 if (llander_lit_panel != ((void *)0))
  artwork_free(&llander_lit_panel);
}


decompiled_code:
__int64 __fastcall llander_screenrefresh(__int64 a1, unsigned int a2)
{
int v2; // ebx
double v3; // xmm0_8
__int64 *v4; // rbx
int *v5; // rbp
float v6; // xmm4_4
__int128 *v7; // r15
__int64 result; // rax
float v9; // xmm2_4
int v10; // er9
int v11; // [rsp+0h] [rbp-78h]
float v12; // [rsp+4h] [rbp-74h]
unsigned int v13; // [rsp+10h] [rbp-68h]
unsigned int v14; // [rsp+14h] [rbp-64h]
unsigned int v15; // [rsp+18h] [rbp-60h]
unsigned int v16; // [rsp+18h] [rbp-60h]
unsigned int v17; // [rsp+1Ch] [rbp-5Ch]
unsigned int v18; // [rsp+1Ch] [rbp-5Ch]
int v19[4]; // [rsp+20h] [rbp-58h] BYREF
__int64 v20; // [rsp+30h] [rbp-48h]
__int64 v21; // [rsp+38h] [rbp-40h]

if ( !llander_panel )
return ((__int64 (*)(void))vector_vh_screenrefresh)();
v2 = **(_DWORD **)llander_panel;
v11 = *(_DWORD *)(*(_QWORD *)llander_panel + 4LL);
v19[0] = *(_DWORD *)a1;
v19[1] = *(_DWORD *)(a1 + 4) - v11;
v20 = *(_QWORD *)(a1 + 16);
v21 = *(_QWORD *)(a1 + 24);
vector_vh_screenrefresh(v19);
if ( a2 )
{
v10 = *(_DWORD *)(a1 + 4);
v16 = v10 - v11;
v18 = v10 - 1;
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
osd_mark_dirty(0LL, v16, (unsigned int)(v2 - 1), v18, 0LL);
}
v3 = (double)v2;
v4 = &lights_changed;
v5 = (int *)&light_areas;
v6 = v3 / 800.0;
v7 = &lights;
v12 = v6;
do
{
result = *(_DWORD *)v4 | a2;
if ( *(_DWORD *)v4 | a2 )
{
v9 = (float)(*(_DWORD *)(a1 + 4) - v11);
v13 = (int)(float)((float)*v5 * v12);
v14 = (int)(float)((float)v5[1] * v12);
v15 = (int)(float)((float)((float)v5[2] * v12) + v9);
v17 = (int)(float)((float)((float)v5[3] * v12) + v9);
if ( *(_DWORD *)v7 )
copybitmap(a1, *(_QWORD *)llander_lit_panel, 0LL, 0LL, 0LL);
else
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
result = osd_mark_dirty(v13, v15, v14, v17, 0LL);
*(_DWORD *)v4 = 0;
}
v4 = (__int64 *)((char *)v4 + 4);
v5 += 4;
v7 = (__int128 *)((char *)v7 + 4);
}
while ( v4 != (__int64 *)((char *)&lights_changed + 20) );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
int v2; // ebx
double v3; // xmm0_8
__int64 *v4; // rbx
int *v5; // rbp
float v6; // xmm4_4
__int128 *v7; // r15
__int64 result; // rax
float v9; // xmm2_4
int v10; // er9
int v11; // [rsp+0h] [rbp-78h]
float v12; // [rsp+4h] [rbp-74h]
unsigned int v13; // [rsp+10h] [rbp-68h]
unsigned int v14; // [rsp+14h] [rbp-64h]
unsigned int v15; // [rsp+18h] [rbp-60h]
unsigned int v16; // [rsp+18h] [rbp-60h]
unsigned int v17; // [rsp+1Ch] [rbp-5Ch]
unsigned int v18; // [rsp+1Ch] [rbp-5Ch]
int v19[4]; // [rsp+20h] [rbp-58h] BYREF
__int64 v20; // [rsp+30h] [rbp-48h]
__int64 v21; // [rsp+38h] [rbp-40h]

if ( !llander_panel )
return ((__int64 (*)(void))vector_vh_screenrefresh)();
v2 = **(_DWORD **)llander_panel;
v11 = *(_DWORD *)(*(_QWORD *)llander_panel + 4LL);
v19[0] = *(_DWORD *)a1;
v19[1] = *(_DWORD *)(a1 + 4) - v11;
v20 = *(_QWORD *)(a1 + 16);
v21 = *(_QWORD *)(a1 + 24);
vector_vh_screenrefresh(v19);
if ( a2 )
{
v10 = *(_DWORD *)(a1 + 4);
v16 = v10 - v11;
v18 = v10 - 1;
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
osd_mark_dirty(0LL, v16, (unsigned int)(v2 - 1), v18, 0LL);
}
v3 = (double)v2;
v4 = &lights_changed;
v5 = (int *)&light_areas;
v6 = v3 / 800.0;
v7 = &lights;
v12 = v6;
do
{
result = *(_DWORD *)v4 | a2;
if ( *(_DWORD *)v4 | a2 )
{
v9 = (float)(*(_DWORD *)(a1 + 4) - v11);
v13 = (int)(float)((float)*v5 * v12);
v14 = (int)(float)((float)v5[1] * v12);
v15 = (int)(float)((float)((float)v5[2] * v12) + v9);
v17 = (int)(float)((float)((float)v5[3] * v12) + v9);
if ( *(_DWORD *)v7 )
copybitmap(a1, *(_QWORD *)llander_lit_panel, 0LL, 0LL, 0LL);
else
copybitmap(a1, *(_QWORD *)llander_panel, 0LL, 0LL, 0LL);
result = osd_mark_dirty(v13, v15, v14, v17, 0LL);
*(_DWORD *)v4 = 0;
}
v4 = (__int64 *)((char *)v4 + 4);
v5 += 4;
v7 = (__int128 *)((char *)v7 + 4);
}
while ( v4 != (__int64 *)((char *)&lights_changed + 20) );
return result;
}

original_code:
void llander_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i, pwidth, pheight;
 float scale;
 struct osd_bitmap vector_bitmap;
 struct rectangle rect;
 if (llander_panel == ((void *)0))
 {
  vector_vh_screenrefresh(bitmap,full_refresh);
  return;
 }
 pwidth = llander_panel->artwork->width;
 pheight = llander_panel->artwork->height;
 vector_bitmap.width = bitmap->width;
 vector_bitmap.height = bitmap->height - pheight;
 vector_bitmap._private = bitmap->_private;
 vector_bitmap.line = bitmap->line;
 vector_vh_screenrefresh(&vector_bitmap,full_refresh);
 if (full_refresh)
 {
  rect.min_x = 0;
  rect.max_x = pwidth-1;
  rect.min_y = bitmap->height - pheight;
  rect.max_y = bitmap->height - 1;
  copybitmap(bitmap,llander_panel->artwork,0,0,
       0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
  osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
 }
 scale = pwidth/800.0;
 for (i=0;i<5;i++)
 {
  if (lights_changed[i] || full_refresh)
  {
   rect.min_x = scale * light_areas[i].min_x;
   rect.max_x = scale * light_areas[i].max_x;
   rect.min_y = bitmap->height - pheight + scale * light_areas[i].min_y;
   rect.max_y = bitmap->height - pheight + scale * light_areas[i].max_y;
   if (lights[i])
    copybitmap(bitmap,llander_lit_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   else
    copybitmap(bitmap,llander_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
   lights_changed[i] = 0;
  }
 }
}

canonical_original_code:
void llander_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i; int pwidth; int pheight;
 float scale;
 struct osd_bitmap vector_bitmap;
 struct rectangle rect;
 if (llander_panel == ((void *)0))
 {
  vector_vh_screenrefresh(bitmap,full_refresh);
  return;
 }
 pwidth = llander_panel->artwork->width;
 pheight = llander_panel->artwork->height;
 vector_bitmap.width = bitmap->width;
 vector_bitmap.height = bitmap->height - pheight;
 vector_bitmap._private = bitmap->_private;
 vector_bitmap.line = bitmap->line;
 vector_vh_screenrefresh(&vector_bitmap,full_refresh);
 if (full_refresh)
 {
  rect.min_x = 0;
  rect.max_x = pwidth-1;
  rect.min_y = bitmap->height - pheight;
  rect.max_y = bitmap->height - 1;
  copybitmap(bitmap,llander_panel->artwork,0,0,
       0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
  osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
 }
 scale = pwidth/800.0;
 for (i=0;i<5;i++)
 {
  if (lights_changed[i] || full_refresh)
  {
   rect.min_x = scale * light_areas[i].min_x;
   rect.max_x = scale * light_areas[i].max_x;
   rect.min_y = bitmap->height - pheight + scale * light_areas[i].min_y;
   rect.max_y = bitmap->height - pheight + scale * light_areas[i].max_y;
   if (lights[i])
    copybitmap(bitmap,llander_lit_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   else
    copybitmap(bitmap,llander_panel->artwork,0,0,
         0,bitmap->height - pheight,&rect,TRANSPARENCY_NONE,0);
   osd_mark_dirty (rect.min_x,rect.min_y,rect.max_x,rect.max_y,0);
   lights_changed[i] = 0;
  }
 }
}

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

variable_types: pwidth int

variable_types: pheight int

variable_types: scale float

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


decompiled_code:
__int64 __fastcall llander_led_w(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

for ( result = 0LL; result != 5; ++result )
{
v3 = (a2 & (1 << (4 - result))) != 0;
if ( *((_DWORD *)&lights + result) != v3 )
{
*((_DWORD *)&lights + result) = v3;
*((_DWORD *)&lights_changed + result) = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

for ( result = 0LL; result != 5; ++result )
{
v3 = (a2 & (1 << (4 - result))) != 0;
if ( *((_DWORD *)&lights + result) != v3 )
{
*((_DWORD *)&lights + result) = v3;
*((_DWORD *)&lights_changed + result) = 1;
}
}
return result;
}

original_code:
void llander_led_w(offs_t offset,data_t data)
{
    int i;
    for (i=0;i<5;i++)
    {
  int new_light = (data & (1 << (4-i))) != 0;
  if (lights[i] != new_light)
  {
   lights[i] = new_light;
   lights_changed[i] = 1;
  }
    }
}

canonical_original_code:
void llander_led_w(unsigned int offset, unsigned int data)
{
    int i;
    for (i=0;i<5;i++)
    {
  int new_light = (data & (1 << (4-i))) != 0;
  if (lights[i] != new_light)
  {
   lights[i] = new_light;
   lights_changed[i] = 1;
  }
    }
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall suprloco_scrollram_r(int a1)
{
return suprloco_scrollram[a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return suprloco_scrollram[a1];
}

original_code:
data_t suprloco_scrollram_r(offs_t offset)
{
 return suprloco_scrollram[offset];
}

canonical_original_code:
unsigned int suprloco_scrollram_r(unsigned int offset)
{
 return suprloco_scrollram[offset];
}


decompiled_code:
__int64 suprloco_control_r()
{
return (unsigned int)control;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)control;
}

original_code:
data_t suprloco_control_r(offs_t offset)
{
 return control;
}

canonical_original_code:
unsigned int suprloco_control_r(unsigned int offset)
{
 return control;
}


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

if ( flip_screen_x )
{
a2 = *a1 + ~a2;
a3 = a1[1] + ~a3;
}
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= a2
&& *(_DWORD *)(Machine + 780LL) >= a2
&& *(_DWORD *)(Machine + 784LL) <= a3
&& *(_DWORD *)(Machine + 788LL) >= a3 )
{
result = plot_pixel();
}
return result;
}

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

if ( flip_screen_x )
{
a2 = *a1 + ~a2;
a3 = a1[1] + ~a3;
}
result = Machine;
if ( *(_DWORD *)(Machine + 776LL) <= a2
&& *(_DWORD *)(Machine + 780LL) >= a2
&& *(_DWORD *)(Machine + 784LL) <= a3
&& *(_DWORD *)(Machine + 788LL) >= a3 )
{
result = plot_pixel();
}
return result;
}

original_code:
static inline void draw_pixel(struct osd_bitmap *bitmap,int x,int y,int color)
{
 if (flip_screen_x)
 {
  x = bitmap->width - x - 1;
  y = bitmap->height - y - 1;
 }
 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)
  return;
 plot_pixel(bitmap, x, y, color);
}

canonical_original_code:
static inline void draw_pixel(struct osd_bitmap *bitmap, int x, int y, int color)
{
 if (flip_screen_x)
 {
  x = bitmap->width - x - 1;
  y = bitmap->height - y - 1;
 }
 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)
  return;
 plot_pixel(bitmap, x, y, color);
}

variable_types: x int

variable_types: y int

variable_types: color int


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

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
((void (__fastcall *)(__int64, __int64))tilemap_set_scroll_rows)(v0, 32LL);
result = 0LL;
}
return result;
}

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

v0 = tilemap_create(get_tile_info, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
bg_tilemap = v0;
result = 1LL;
if ( v0 )
{
((void (__fastcall *)(__int64, __int64))tilemap_set_scroll_rows)(v0, 32LL);
result = 0LL;
}
return result;
}

original_code:
int suprloco_vh_start(void)
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}

canonical_original_code:
int suprloco_vh_start()
{
 bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,0x00,8,8,32,32);
 if (!bg_tilemap)
  return 1;
 tilemap_set_scroll_rows(bg_tilemap,32);
 return 0;
}


decompiled_code:
__int64 __fastcall suprloco_scrollram_w(unsigned int a1, unsigned int a2)
{
suprloco_scrollram[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, a1, a2 - (flip_screen_x == 0 ? 8 : -8));
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
suprloco_scrollram[a1] = a2;
return tilemap_set_scrollx(bg_tilemap, a1, a2 - (flip_screen_x == 0 ? 8 : -8));
}

original_code:
void suprloco_scrollram_w(offs_t offset,data_t data)
{
 int adj = flip_screen_x ? -8 : 8;
 suprloco_scrollram[offset] = data;
 tilemap_set_scrollx(bg_tilemap,offset, data - adj);
}

canonical_original_code:
void suprloco_scrollram_w(unsigned int offset, unsigned int data)
{
 int adj = flip_screen_x ? -8 : 8;
 suprloco_scrollram[offset] = data;
 tilemap_set_scrollx(bg_tilemap,offset, data - adj);
}

variable_types:
data
unsigned int

variable_types: adj int


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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
flip_screen_w(0LL, a2 & 0x80);
result = tilemap_set_scrolly(bg_tilemap, 0LL, flip_screen_x != 0 ? 0xFFFFFFE0 : 0);
control = a2;
return result;
}

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
flip_screen_w(0LL, a2 & 0x80);
result = tilemap_set_scrolly(bg_tilemap, 0LL, flip_screen_x != 0 ? 0xFFFFFFE0 : 0);
control = a2;
return result;
}

original_code:
void suprloco_control_w(offs_t offset,data_t data)
{
 if ((control & 0x10) != (data & 0x10))
 {
 }
 coin_counter_w(0, data & 0x01);
 coin_counter_w(1, data & 0x02);
 flip_screen_w(0,data & 0x80);
 tilemap_set_scrolly(bg_tilemap,0,flip_screen_x ? -32 : 0);
 control = data;
}

canonical_original_code:
void suprloco_control_w(unsigned int offset, unsigned int data)
{
 if ((control & 0x10) != (data & 0x10))
 {
 }
 coin_counter_w(0, data & 0x01);
 coin_counter_w(1, data & 0x02);
 flip_screen_w(0,data & 0x80);
 tilemap_set_scrolly(bg_tilemap,0,flip_screen_x ? -32 : 0);
 control = data;
}


original_code:
static void render_sprite(struct osd_bitmap *bitmap,int spr_number)
{
 int sx,sy,col,row,height,src,adjy,dy;
 unsigned char *spr_reg;
 unsigned short *spr_palette;
 short skip;
 spr_reg = spriteram + 0x10 * spr_number;
 src = spr_reg[6] + (spr_reg[7] << 8);
 skip = spr_reg[4] + (spr_reg[5] << 8);
 height = spr_reg[1] - spr_reg[0];
 spr_palette = Machine->remapped_colortable + 0x100 + 0x10 * spr_reg[3] + ((control & 0x20)?0x100:0);
 sx = spr_reg[2];
 sy = spr_reg[0] + 1;
 if (!flip_screen_x)
 {
  adjy = sy;
  dy = 1;
 }
 else
 {
  adjy = sy + height + 30;
  dy = -1;
 }
 for (row = 0;row < height;row++,adjy+=dy)
 {
  int color1,color2,flipx;
  UINT8 data;
  UINT8 *gfx;
  src += skip;
  col = 0;
  gfx = &(memory_region(REGION_GFX2)[src & 0x7fff]);
  flipx = src & 0x8000;
  while (1)
  {
   if (flipx)
   {
    data = *gfx--;
    color1 = data & 0x0f;
    color2 = data >> 4;
   }
   else
   {
    data = *gfx++;
    color1 = data >> 4;
    color2 = data & 0x0f;
   }
   if (color1 == 15) break;
   if (color1)
    draw_pixel(bitmap,sx+col, adjy,spr_palette[color1]);
   if (color2 == 15) break;
   if (color2)
    draw_pixel(bitmap,sx+col+1,adjy,spr_palette[color2]);
   col += 2;
  }
 }
}

canonical_original_code:
static void render_sprite(struct osd_bitmap *bitmap, int spr_number)
{
 int sx; int sy; int col; int row; int height; int src; int adjy; int dy;
 unsigned char *spr_reg;
 unsigned short *spr_palette;
 short skip;
 spr_reg = spriteram + 0x10 * spr_number;
 src = spr_reg[6] + (spr_reg[7] << 8);
 skip = spr_reg[4] + (spr_reg[5] << 8);
 height = spr_reg[1] - spr_reg[0];
 spr_palette = Machine->remapped_colortable + 0x100 + 0x10 * spr_reg[3] + ((control & 0x20)?0x100:0);
 sx = spr_reg[2];
 sy = spr_reg[0] + 1;
 if (!flip_screen_x)
 {
  adjy = sy;
  dy = 1;
 }
 else
 {
  adjy = sy + height + 30;
  dy = -1;
 }
 for (row = 0;row < height;row++,adjy+=dy)
 {
  int color1; int color2; int flipx;
  unsigned char data;
  unsigned char *gfx;
  src += skip;
  col = 0;
  gfx = &(memory_region(REGION_GFX2)[src & 0x7fff]);
  flipx = src & 0x8000;
  while (1)
  {
   if (flipx)
   {
    data = *gfx--;
    color1 = data & 0x0f;
    color2 = data >> 4;
   }
   else
   {
    data = *gfx++;
    color1 = data >> 4;
    color2 = data & 0x0f;
   }
   if (color1 == 15) break;
   if (color1)
    draw_pixel(bitmap,sx+col, adjy,spr_palette[color1]);
   if (color2 == 15) break;
   if (color2)
    draw_pixel(bitmap,sx+col+1,adjy,spr_palette[color2]);
   col += 2;
  }
 }
}

variable_types: sx int

variable_types: sy int

variable_types: col int

variable_types: row int

variable_types: src int

variable_types: adjy int

variable_types: dy int

variable_types: skip short

variable_types: flipx int

variable_types:
data
unsigned char

variable_types:
gfx
unsigned char *


decompiled_code:
__int64 __fastcall suprloco_vh_screenrefresh(_DWORD *a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func9(a1);
return tilemap_draw(a1, bg_tilemap, 1LL);
}

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

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

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


original_code:
void init_suprloco(void)
{
 int i, j, k, color_source, color_dest;
 unsigned char *source, *dest, *lookup;
 source = memory_region(REGION_GFX1);
 dest = source + 0x6000;
 lookup = memory_region(REGION_PROMS) + 0x0200;
 for (i = 0; i < 0x80; i++, lookup += 8)
 {
  for (j = 0; j < 0x40; j++, source++, dest++)
  {
   dest[0] = dest[0x2000] = dest[0x4000] = dest[0x6000] = 0;
   for (k = 0; k < 8; k++)
   {
    color_source = (((source[0x0000] >> k) & 0x01) << 2) |
          (((source[0x2000] >> k) & 0x01) << 1) |
          (((source[0x4000] >> k) & 0x01) << 0);
    color_dest = lookup[color_source];
    dest[0x0000] |= (((color_dest >> 3) & 0x01) << k);
    dest[0x2000] |= (((color_dest >> 2) & 0x01) << k);
    dest[0x4000] |= (((color_dest >> 1) & 0x01) << k);
    dest[0x6000] |= (((color_dest >> 0) & 0x01) << k);
   }
  }
 }
 suprloco_decode();
}

canonical_original_code:
void init_suprloco()
{
 int i; int j; int k; int color_source; int color_dest;
 unsigned char *source; unsigned char *dest; unsigned char *lookup;
 source = memory_region(REGION_GFX1);
 dest = source + 0x6000;
 lookup = memory_region(REGION_PROMS) + 0x0200;
 for (i = 0; i < 0x80; i++, lookup += 8)
 {
  for (j = 0; j < 0x40; j++, source++, dest++)
  {
   dest[0] = dest[0x2000] = dest[0x4000] = dest[0x6000] = 0;
   for (k = 0; k < 8; k++)
   {
    color_source = (((source[0x0000] >> k) & 0x01) << 2) |
          (((source[0x2000] >> k) & 0x01) << 1) |
          (((source[0x4000] >> k) & 0x01) << 0);
    color_dest = lookup[color_source];
    dest[0x0000] |= (((color_dest >> 3) & 0x01) << k);
    dest[0x2000] |= (((color_dest >> 2) & 0x01) << k);
    dest[0x4000] |= (((color_dest >> 1) & 0x01) << k);
    dest[0x6000] |= (((color_dest >> 0) & 0x01) << k);
   }
  }
 }
 suprloco_decode();
}

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
source
unsigned char *

variable_types:
dest
unsigned char *

variable_types:
lookup
unsigned char *


decompiled_code:
__int64 suprloco_soundport_w()
{
soundlatch_w(0LL);
cpu_cause_interrupt(1LL, 4294967294LL);
return cpu_spinuntil_time(53687LL);
}

canonical_decompiled_code:
__int64 func12()
{
soundlatch_w(0LL);
cpu_cause_interrupt(1LL, 4294967294LL);
return cpu_spinuntil_time(53687LL);
}

original_code:
static void suprloco_soundport_w(offs_t offset,data_t data)
{
 soundlatch_w(0,data);
 cpu_cause_interrupt(1,-2);
 cpu_spinuntil_time(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)));
}

canonical_original_code:
static void suprloco_soundport_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(0,data);
 cpu_cause_interrupt(1,-2);
 cpu_spinuntil_time(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)));
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

v1 = 2 * a1;
v2 = *(unsigned __int8 *)(suprloco_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x300 | (unsigned __int64)*(unsigned __int8 *)(suprloco_videoram + v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 2) & 7);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 6) = (v2 >> 5) & 1;
return result;
}

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

v1 = 2 * a1;
v2 = *(unsigned __int8 *)(suprloco_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x300 | (unsigned __int64)*(unsigned __int8 *)(suprloco_videoram + v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 2) & 7);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 6) = (v2 >> 5) & 1;
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = suprloco_videoram[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (suprloco_videoram[2*tile_index] | ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x1c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.priority = (attr & 0x20) >> 5;
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned char attr = suprloco_videoram[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (suprloco_videoram[2*tile_index] | ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x1c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.priority = (attr & 0x20) >> 5;
}

variable_types:
attr
unsigned char

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(_DWORD *a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx

result = spriteram_size >> 4;
if ( spriteram_size >> 4 )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(spriteram + 16 * v2 + 2) != 0xFF )
render_sprite(a1, v2);
++v2;
result = spriteram_size >> 4;
}
while ( spriteram_size >> 4 > v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx

result = spriteram_size >> 4;
if ( spriteram_size >> 4 )
{
v2 = 0LL;
do
{
if ( *(_BYTE *)(spriteram + 16 * v2 + 2) != 0xFF )
func8(a1, v2);
++v2;
result = spriteram_size >> 4;
}
while ( spriteram_size >> 4 > v2 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int spr_number;
 unsigned char *spr_reg;
 for (spr_number = 0;spr_number < (spriteram_size >> 4);spr_number++)
 {
  spr_reg = spriteram + 0x10 * spr_number;
  if (spr_reg[2] != 0xff)
   render_sprite(bitmap,spr_number);
 }
}


decompiled_code:
void __fastcall mpatrol_bg1xpos_w(__int64 a1, char a2)
{
bg1xpos = a2;
}

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

original_code:
void mpatrol_bg1xpos_w(offs_t offset,data_t data)
{
 bg1xpos = data;
}

canonical_original_code:
void mpatrol_bg1xpos_w(unsigned int offset, unsigned int data)
{
 bg1xpos = data;
}


decompiled_code:
void __fastcall mpatrol_bg1ypos_w(__int64 a1, char a2)
{
bg1ypos = a2;
}

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

original_code:
void mpatrol_bg1ypos_w(offs_t offset,data_t data)
{
 bg1ypos = data;
}

canonical_original_code:
void mpatrol_bg1ypos_w(unsigned int offset, unsigned int data)
{
 bg1ypos = data;
}


decompiled_code:
void __fastcall mpatrol_bg2xpos_w(__int64 a1, char a2)
{
bg2xpos = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, char a2)
{
bg2xpos = a2;
}

original_code:
void mpatrol_bg2xpos_w(offs_t offset,data_t data)
{
 bg2xpos = data;
}

canonical_original_code:
void mpatrol_bg2xpos_w(unsigned int offset, unsigned int data)
{
 bg2xpos = data;
}


decompiled_code:
void __fastcall mpatrol_bg2ypos_w(__int64 a1, char a2)
{
bg2ypos = a2;
}

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

original_code:
void mpatrol_bg2ypos_w(offs_t offset,data_t data)
{
 bg2ypos = data;
}

canonical_original_code:
void mpatrol_bg2ypos_w(unsigned int offset, unsigned int data)
{
 bg2ypos = data;
}


decompiled_code:
void __fastcall mpatrol_bgcontrol_w(__int64 a1, char a2)
{
bgcontrol = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char a2)
{
bgcontrol = a2;
}

original_code:
void mpatrol_bgcontrol_w(offs_t offset,data_t data)
{
 bgcontrol = data;
}

canonical_original_code:
void mpatrol_bgcontrol_w(unsigned int offset, unsigned int data)
{
 bgcontrol = data;
}


decompiled_code:
__int64 mpatrol_vh_start()
{
__int64 *i; // rbx
__int64 v1; // rax
__int64 v2; // rdi
unsigned int v3; // er15
__int64 v4; // r14
__int64 v5; // rdx
int v7; // [rsp+8h] [rbp-40h]
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

v8 = generic_vh_start();
if ( v8 )
return 1;
v7 = 3;
for ( i = &bgbitmap; ; ++i )
{
v1 = bitmap_alloc(256LL, 64LL);
*i = v1;
v2 = v1;
if ( !v1 )
break;
v3 = 0;
while ( 1 )
{
v4 = 32 * v3;
drawgfx(v2, *(_QWORD *)(Machine + 8 * (v7 - 1 + 64LL)), v3, 0LL, 0LL, 0LL, v4, 0LL, 0LL, 0LL, 0LL);
v5 = v3++;
drawgfx(*i, *(_QWORD *)(Machine + 8LL * v7 + 512), v5, 0LL, 0LL, 0LL, v4, 32LL, 0LL, 0LL, 0LL);
if ( v3 == 8 )
break;
v2 = *i;
}
v7 += 2;
if ( v7 == 9 )
return v8;
}
generic_vh_stop();
return 1;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 *i; // rbx
__int64 v1; // rax
__int64 v2; // rdi
unsigned int v3; // er15
__int64 v4; // r14
__int64 v5; // rdx
int v7; // [rsp+8h] [rbp-40h]
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

v8 = generic_vh_start();
if ( v8 )
return 1;
v7 = 3;
for ( i = &bgbitmap; ; ++i )
{
v1 = bitmap_alloc(256LL, 64LL);
*i = v1;
v2 = v1;
if ( !v1 )
break;
v3 = 0;
while ( 1 )
{
v4 = 32 * v3;
drawgfx(v2, *(_QWORD *)(Machine + 8 * (v7 - 1 + 64LL)), v3, 0LL, 0LL, 0LL, v4, 0LL, 0LL, 0LL, 0LL);
v5 = v3++;
drawgfx(*i, *(_QWORD *)(Machine + 8LL * v7 + 512), v5, 0LL, 0LL, 0LL, v4, 32LL, 0LL, 0LL, 0LL);
if ( v3 == 8 )
break;
v2 = *i;
}
v7 += 2;
if ( v7 == 9 )
return v8;
}
generic_vh_stop();
return 1;
}

original_code:
int mpatrol_vh_start(void)
{
 int i,j;
 if (generic_vh_start() != 0)
  return 1;
 for (i = 0;i < 3;i++)
 {
  if ((bgbitmap[i] = bitmap_alloc(256,(64))) == 0)
  {
   generic_vh_stop();
   return 1;
  }
  for (j = 0;j < 8;j++)
  {
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i],
     j,0,
     0,0,
     32 * j,0,
     0,TRANSPARENCY_NONE,0);
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i + 1],
     j,0,
     0,0,
     32 * j,((64) / 2),
     0,TRANSPARENCY_NONE,0);
  }
 }
 return 0;
}

canonical_original_code:
int mpatrol_vh_start()
{
 int i; int j;
 if (generic_vh_start() != 0)
  return 1;
 for (i = 0;i < 3;i++)
 {
  if ((bgbitmap[i] = bitmap_alloc(256,(64))) == 0)
  {
   generic_vh_stop();
   return 1;
  }
  for (j = 0;j < 8;j++)
  {
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i],
     j,0,
     0,0,
     32 * j,0,
     0,TRANSPARENCY_NONE,0);
   drawgfx(bgbitmap[i],Machine->gfx[2 + 2 * i + 1],
     j,0,
     0,0,
     32 * j,((64) / 2),
     0,TRANSPARENCY_NONE,0);
  }
 }
 return 0;
}


decompiled_code:
__int64 mpatrol_vh_stop()
{
bitmap_free(bgbitmap);
bitmap_free(qword_13E8);
bitmap_free(qword_13F0);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func8()
{
bitmap_free(bgbitmap);
bitmap_free(qword_13E8);
bitmap_free(qword_13F0);
return generic_vh_stop();
}

original_code:
void mpatrol_vh_stop(void)
{
 bitmap_free(bgbitmap[0]);
 bitmap_free(bgbitmap[1]);
 bitmap_free(bgbitmap[2]);
 generic_vh_stop();
}

canonical_original_code:
void mpatrol_vh_stop()
{
 bitmap_free(bgbitmap[0]);
 bitmap_free(bgbitmap[1]);
 bitmap_free(bgbitmap[2]);
 generic_vh_stop();
}


decompiled_code:
__int64 __fastcall mpatrol_flipscreen_w(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
if ( (v2 & 1) != flipscreen )
{
flipscreen = v2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2)
{
char v2; // bl

v2 = a2 ^ ((readinputport(4LL) & 1) == 0);
if ( (v2 & 1) != flipscreen )
{
flipscreen = v2 & 1;
memset(dirtybuffer, 1, videoram_size);
}
coin_counter_w(0LL, v2 & 2);
return coin_counter_w(1LL, v2 & 0x20);
}

original_code:
void mpatrol_flipscreen_w(offs_t offset,data_t data)
{
 data ^= ~readinputport(4) & 1;
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}

canonical_original_code:
void mpatrol_flipscreen_w(unsigned int offset, unsigned int data)
{
 data ^= ~readinputport(4) & 1;
 if (flipscreen != (data & 1))
 {
  flipscreen = data & 1;
  memset(dirtybuffer,1,videoram_size);
 }
 coin_counter_w(0,data & 0x02);
 coin_counter_w(1,data & 0x20);
}


decompiled_code:
__int64 mpatrol_input_port_3_r()
{
int v0; // ebx
__int64 result; // rax

v0 = input_port_3_r(0LL);
if ( (input_port_4_r(0LL) & 4) != 0 )
result = v0 | (16 * (unsigned int)input_port_5_r(0LL));
else
result = v0 | (unsigned int)(input_port_5_r(0LL) & 0xF0);
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
__int64 result; // rax

v0 = input_port_3_r(0LL);
if ( (input_port_4_r(0LL) & 4) != 0 )
result = v0 | (16 * (unsigned int)input_port_5_r(0LL));
else
result = v0 | (unsigned int)(input_port_5_r(0LL) & 0xF0);
return result;
}

original_code:
data_t mpatrol_input_port_3_r(offs_t offset)
{
 int ret = input_port_3_r(0);
 if (input_port_4_r(0) & 0x04)
 {
  ret |= (input_port_5_r(0) << 4);
 }
 else
 {
  ret |= (input_port_5_r(0) & 0xf0);
 }
 return ret;
}

canonical_original_code:
unsigned int mpatrol_input_port_3_r(unsigned int offset)
{
 int ret = input_port_3_r(0);
 if (input_port_4_r(0) & 0x04)
 {
  ret |= (input_port_5_r(0) << 4);
 }
 else
 {
  ret |= (input_port_5_r(0) & 0xf0);
 }
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 mpatrol_protection_r()
{
return (unsigned __int8)cpu_get_reg(5LL);
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned __int8)cpu_get_reg(5LL);
}

original_code:
data_t mpatrol_protection_r(offs_t offset)
{
 return cpu_get_reg(Z80_DE) & 0xff;
}

canonical_original_code:
unsigned int mpatrol_protection_r(unsigned int offset)
{
 return cpu_get_reg(Z80_DE) & 0xff;
}


decompiled_code:
__int64 __fastcall draw_background(__int64 a1, unsigned int a2, int a3, __int64 a4, int a5, unsigned int a6)
{
__int64 v6; // r13
unsigned int v7; // er12
unsigned int v8; // ebx
int v9; // er10
_DWORD v12[4]; // [rsp+20h] [rbp-58h] BYREF
_DWORD v13[18]; // [rsp+30h] [rbp-48h] BYREF

v6 = a6;
v7 = a2;
v8 = a3;
get_clip(v12, a3, a3 + 63);
get_clip(v13, v8 + 64, v9);
if ( flipscreen )
{
v7 = 256 - a2;
v8 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) - 64 - v8;
}
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v7, v8, v12, v6, 128LL);
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v7 - 256, v8, v12, v6, 128LL);
return fillbitmap(
a1,
*(unsigned __int16 *)(*(_QWORD *)(*(_QWORD *)(Machine + 8LL * (2 * a5 + 2) + 512) + 16LL) + 6LL),
v13);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2, int a3, __int64 a4, int a5, unsigned int a6)
{
__int64 v6; // r13
unsigned int v7; // er12
unsigned int v8; // ebx
int v9; // er10
_DWORD v12[4]; // [rsp+20h] [rbp-58h] BYREF
_DWORD v13[18]; // [rsp+30h] [rbp-48h] BYREF

v6 = a6;
v7 = a2;
v8 = a3;
func6(v12, a3, a3 + 63);
func6(v13, v8 + 64, v9);
if ( flipscreen )
{
v7 = 256 - a2;
v8 = *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) - 64 - v8;
}
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v7, v8, v12, v6, 128LL);
copybitmap(a1, bgbitmap[a5], (unsigned int)flipscreen, (unsigned int)flipscreen, v7 - 256, v8, v12, v6, 128LL);
return fillbitmap(
a1,
*(unsigned __int16 *)(*(_QWORD *)(*(_QWORD *)(Machine + 8LL * (2 * a5 + 2) + 512) + 16LL) + 6LL),
v13);
}

original_code:
static void draw_background(struct osd_bitmap *bitmap,
                            int xpos, int ypos, int ypos_end, int image,
       int transparency)
{
 struct rectangle clip1, clip2;
 get_clip(&clip1, ypos, ypos + (64) - 1);
 get_clip(&clip2, ypos + (64), ypos_end);
 if (flipscreen)
 {
  xpos = 256 - xpos;
  ypos = Machine->drv->screen_height - (64) - ypos;
 }
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos, ypos,&clip1,transparency,128);
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos - 256,ypos,&clip1,transparency,128);
 fillbitmap(bitmap,Machine->gfx[image*2+2]->colortable[3],&clip2);
}

canonical_original_code:
static void draw_background(struct osd_bitmap *bitmap, int xpos, int ypos, int ypos_end, int image, int transparency)
{
 struct rectangle clip1; struct rectangle clip2;
 get_clip(&clip1, ypos, ypos + (64) - 1);
 get_clip(&clip2, ypos + (64), ypos_end);
 if (flipscreen)
 {
  xpos = 256 - xpos;
  ypos = Machine->drv->screen_height - (64) - ypos;
 }
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos, ypos,&clip1,transparency,128);
 copybitmap(bitmap,bgbitmap[image],flipscreen,flipscreen,xpos - 256,ypos,&clip1,transparency,128);
 fillbitmap(bitmap,Machine->gfx[image*2+2]->colortable[3],&clip2);
}

variable_types: xpos int

variable_types: ypos int

variable_types: image int

variable_types: transparency int

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