original_code:
static void ddribble_draw_sprites( struct osd_bitmap *bitmap, unsigned char* source, int lenght, int gfxset, int flipscreen )
{
 struct GfxElement *gfx = Machine->gfx[gfxset];
 const unsigned char *finish = source + lenght;
 while( source < finish )
 {
  int number = source[0] | ((source[1] & 0x07) << 8);
  int attr = source[4];
  int sx = source[3] | ((attr & 0x01) << 8);
  int sy = source[2];
  int flipx = attr & 0x20;
  int flipy = attr & 0x40;
  int color = (source[1] & 0xf0) >> 4;
  int width,height;
  if (flipscreen){
    flipx = !flipx;
    flipy = !flipy;
    sx = 240 - sx;
    sy = 240 - sy;
    if ((attr & 0x1c) == 0x10){
     sx -= 0x10;
     sy -= 0x10;
    }
  }
  switch (attr & 0x1c){
   case 0x10:
    width = height = 2; number &= (~3); break;
   case 0x08:
    width = 1; height = 2; number &= (~2); break;
   case 0x04:
    width = 2; height = 1; number &= (~1); break;
   default:
    width = height = 1; break;
  }
  {
   static int x_offset[2] = { 0x00, 0x01 };
   static int y_offset[2] = { 0x00, 0x02 };
   int x,y, ex, ey;
   for( y=0; y < height; y++ ){
    for( x=0; x < width; x++ ){
     ex = flipx ? (width-1-x) : x;
     ey = flipy ? (height-1-y) : y;
     drawgfx(bitmap,gfx,
      (number)+x_offset[ex]+y_offset[ey],
      color,
      flipx, flipy,
      sx+x*16,sy+y*16,
      &Machine->visible_area,
      TRANSPARENCY_PEN, 0);
    }
   }
  }
  source += 5;
 }
}

canonical_original_code:
static void ddribble_draw_sprites(struct osd_bitmap *bitmap, unsigned char *source, int lenght, int gfxset, int flipscreen)
{
 struct GfxElement *gfx = Machine->gfx[gfxset];
 unsigned char *finish = source + lenght;
 while( source < finish )
 {
  int number = source[0] | ((source[1] & 0x07) << 8);
  int attr = source[4];
  int sx = source[3] | ((attr & 0x01) << 8);
  int sy = source[2];
  int flipx = attr & 0x20;
  int flipy = attr & 0x40;
  int color = (source[1] & 0xf0) >> 4;
  int width; int height;
  if (flipscreen){
    flipx = !flipx;
    flipy = !flipy;
    sx = 240 - sx;
    sy = 240 - sy;
    if ((attr & 0x1c) == 0x10){
     sx -= 0x10;
     sy -= 0x10;
    }
  }
  switch (attr & 0x1c){
   case 0x10:
    width = height = 2; number &= (~3); break;
   case 0x08:
    width = 1; height = 2; number &= (~2); break;
   case 0x04:
    width = 2; height = 1; number &= (~1); break;
   default:
    width = height = 1; break;
  }
  {
   static int x_offset[2] = { 0x00, 0x01 };
   static int y_offset[2] = { 0x00, 0x02 };
   int x; int y; int ex; int ey;
   for( y=0; y < height; y++ ){
    for( x=0; x < width; x++ ){
     ex = flipx ? (width-1-x) : x;
     ey = flipy ? (height-1-y) : y;
     drawgfx(bitmap,gfx,
      (number)+x_offset[ex]+y_offset[ey],
      color,
      flipx, flipy,
      sx+x*16,sy+y*16,
      &Machine->visible_area,
      TRANSPARENCY_PEN, 0);
    }
   }
  }
  source += 5;
 }
}

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

variable_types:
source
unsigned char *

variable_types: lenght int

variable_types: gfxset int

variable_types: flipscreen int

variable_types:
finish
unsigned char *

variable_types: number int

variable_types: color int

variable_types: width int

variable_types: height int

variable_types: x int

variable_types: ex int

variable_types: ey int


decompiled_code:
__int64 __fastcall ddrible_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rsi

v1 = dword_13B0 & 8;
if ( (dword_13B0 & 8) != 0 )
v1 = 3LL;
tilemap_set_flip(fg_tilemap, v1);
v2 = dword_13C4 & 8;
if ( (dword_13C4 & 8) != 0 )
v2 = 3LL;
tilemap_set_flip(bg_tilemap, v2);
tilemap_set_scrollx(fg_tilemap, 0LL, dword_13A4 | ((_WORD)dword_13A8 << 8) & 0x100u);
tilemap_set_scrollx(bg_tilemap, 0LL, dword_13B8 | ((_WORD)dword_13BC << 8) & 0x100u);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned int)ddribble_vregs[0]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)dword_13B4);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
ddribble_draw_sprites(a1, ddrible_spriteram_1, 125, 2, dword_13B0 & 8);
ddribble_draw_sprites(a1, ddrible_spriteram_2, 320, 3, dword_13C4 & 8);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rsi

v1 = dword_13B0 & 8;
if ( (dword_13B0 & 8) != 0 )
v1 = 3LL;
tilemap_set_flip(fg_tilemap, v1);
v2 = dword_13C4 & 8;
if ( (dword_13C4 & 8) != 0 )
v2 = 3LL;
tilemap_set_flip(bg_tilemap, v2);
tilemap_set_scrollx(fg_tilemap, 0LL, dword_13A4 | ((_WORD)dword_13A8 << 8) & 0x100u);
tilemap_set_scrollx(bg_tilemap, 0LL, dword_13B8 | ((_WORD)dword_13BC << 8) & 0x100u);
tilemap_set_scrolly(fg_tilemap, 0LL, (unsigned int)ddribble_vregs[0]);
tilemap_set_scrolly(bg_tilemap, 0LL, (unsigned int)dword_13B4);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 0LL);
func11(a1, ddrible_spriteram_1, 125, 2, dword_13B0 & 8);
func11(a1, ddrible_spriteram_2, 320, 3, dword_13C4 & 8);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

original_code:
void ddrible_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh )
{
 tilemap_set_flip(fg_tilemap, (ddribble_vregs[0][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_flip(bg_tilemap, (ddribble_vregs[1][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_scrollx(fg_tilemap,0,ddribble_vregs[0][1] | ((ddribble_vregs[0][2] & 0x01) << 8));
 tilemap_set_scrollx(bg_tilemap,0,ddribble_vregs[1][1] | ((ddribble_vregs[1][2] & 0x01) << 8));
 tilemap_set_scrolly(fg_tilemap,0,ddribble_vregs[0][0]);
 tilemap_set_scrolly(bg_tilemap,0,ddribble_vregs[1][0]);
 tilemap_update( 0 );
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 tilemap_draw(bitmap,bg_tilemap,0);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_1,0x07d,2,ddribble_vregs[0][4] & 0x08);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_2,0x140,3,ddribble_vregs[1][4] & 0x08);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void ddrible_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_set_flip(fg_tilemap, (ddribble_vregs[0][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_flip(bg_tilemap, (ddribble_vregs[1][4] & 0x08) ? (0x2 | 0x1) : 0);
 tilemap_set_scrollx(fg_tilemap,0,ddribble_vregs[0][1] | ((ddribble_vregs[0][2] & 0x01) << 8));
 tilemap_set_scrollx(bg_tilemap,0,ddribble_vregs[1][1] | ((ddribble_vregs[1][2] & 0x01) << 8));
 tilemap_set_scrolly(fg_tilemap,0,ddribble_vregs[0][0]);
 tilemap_set_scrolly(bg_tilemap,0,ddribble_vregs[1][0]);
 tilemap_update( 0 );
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 tilemap_draw(bitmap,bg_tilemap,0);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_1,0x07d,2,ddribble_vregs[0][4] & 0x08);
 ddribble_draw_sprites(bitmap,ddrible_spriteram_2,0x140,3,ddribble_vregs[1][4] & 0x08);
 tilemap_draw(bitmap,fg_tilemap,0);
}

return_type: void

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


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

if ( ddrible_int_enable_1 )
result = 2LL;
else
result = ignore_interrupt();
return result;
}

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

if ( ddrible_int_enable_1 )
result = 2LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int ddrible_interrupt_1( void )
{
 if (ddrible_int_enable_1)
  return 2;
 return ignore_interrupt();
}

canonical_original_code:
static int ddrible_interrupt_1()
{
 if (ddrible_int_enable_1)
  return 2;
 return ignore_interrupt();
}

return_type: int


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

if ( ddrible_int_enable_0 )
result = 2LL;
else
result = ignore_interrupt();
return result;
}

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

if ( ddrible_int_enable_0 )
result = 2LL;
else
result = ignore_interrupt();
return result;
}

original_code:
static int ddrible_interrupt_0( void )
{
 if (ddrible_int_enable_0)
  return 2;
 return ignore_interrupt();
}

canonical_original_code:
static int ddrible_interrupt_0()
{
 if (ddrible_int_enable_0)
  return 2;
 return ignore_interrupt();
}


canonical_original_code:
static void ddrible_vlm5030_ctrl_w(unsigned int offset, unsigned int data)
{
 unsigned char *SPEECH_ROM = memory_region(REGION_SOUND1);
 VLM5030_RST( data & 0x40 ? 1 : 0 );
 VLM5030_ST( data & 0x20 ? 1 : 0 );
 VLM5030_VCU( data & 0x10 ? 1 : 0 );
 VLM5030_set_rom(&SPEECH_ROM[data & 0x08 ? 0x10000 : 0]);
 set_RC_filter(2,1000,2200,1000,data & 0x04 ? 150000 : 0);
 set_RC_filter(1,1000,2200,1000,data & 0x02 ? 150000 : 0);
 set_RC_filter(0,1000,2200,1000,data & 0x01 ? 150000 : 0);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
// attributes: thunk
int ddrible_vlm5030_busy_r(void)
{
return rand();
}

canonical_decompiled_code:
int func16(void)
{
return rand();
}

original_code:
static data_t ddrible_vlm5030_busy_r(offs_t offset)
{
 return rand();
 if (VLM5030_BSY()) return 1;
 else return 0;
}

canonical_original_code:
static unsigned int ddrible_vlm5030_busy_r(unsigned int offset)
{
 return rand();
 if (VLM5030_BSY()) return 1;
 else return 0;
}

return_type: unsigned int


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

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

original_code:
static void ddrible_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(0,(data) & 0x01);
 coin_counter_w(1,(data >> 1) & 0x01);
}

canonical_original_code:
static void ddrible_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,(data) & 0x01);
 coin_counter_w(1,(data >> 1) & 0x01);
}


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

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

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

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

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

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

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
_DWORD *ddrible_init_machine()
{
_DWORD *result; // rax

ddrible_int_enable_1 = 0;
result = &ddrible_int_enable_0;
ddrible_int_enable_0 = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func19()
{
_DWORD *result; // rax

ddrible_int_enable_1 = 0;
result = &ddrible_int_enable_0;
ddrible_int_enable_0 = 0;
return result;
}

original_code:
void ddrible_init_machine( void )
{
 ddrible_int_enable_0 = ddrible_int_enable_1 = 0;
}

canonical_original_code:
void ddrible_init_machine()
{
 ddrible_int_enable_0 = ddrible_int_enable_1 = 0;
}


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
__int64 v5; // rsi
__int64 result; // rax

v1 = *(unsigned __int8 *)(ddrible_fg_videoram + a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(ddrible_fg_videoram + a1 + 1024LL)
+ (((*(_BYTE *)(ddrible_fg_videoram + a1) >> 6) + 4 * (dword_13AC | (v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v4 = *(_QWORD *)(v2 + 16);
v5 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4;
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v1 >> 4) & 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
__int64 v5; // rsi
__int64 result; // rax

v1 = *(unsigned __int8 *)(ddrible_fg_videoram + a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(ddrible_fg_videoram + a1 + 1024LL)
+ (((*(_BYTE *)(ddrible_fg_videoram + a1) >> 6) + 4 * (dword_13AC | (v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v4 = *(_QWORD *)(v2 + 16);
v5 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4;
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v1 >> 4) & 3;
return result;
}

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_fg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[0][3]);
 int num = ddrible_fg_videoram[tile_index + 0x400] + 256*bank;
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_fg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[0][3]);
 int num = ddrible_fg_videoram[tile_index + 0x400] + 256*bank;
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

variable_types:
attr
unsigned char

variable_types: bank int

variable_types: num int

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


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
__int64 v5; // rsi
__int64 result; // rax

v1 = *(unsigned __int8 *)(ddrible_bg_videoram + a1);
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (*(unsigned __int8 *)(ddrible_bg_videoram + a1 + 1024LL)
+ (((*(_BYTE *)(ddrible_bg_videoram + a1) >> 6) + 4 * (dword_13C0 | (v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v4 = *(_QWORD *)(v2 + 16);
v5 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4;
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v1 >> 4) & 3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ecx
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
__int64 v5; // rsi
__int64 result; // rax

v1 = *(unsigned __int8 *)(ddrible_bg_videoram + a1);
v2 = *(_QWORD *)(Machine + 520LL);
v3 = (*(unsigned __int8 *)(ddrible_bg_videoram + a1 + 1024LL)
+ (((*(_BYTE *)(ddrible_bg_videoram + a1) >> 6) + 4 * (dword_13C0 | (v1 >> 5) & 1u)) << 8))
% *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + v3 * *(_DWORD *)(v2 + 52);
v4 = *(_QWORD *)(v2 + 16);
v5 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v4;
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
*((_DWORD *)&tile_info + 5) = (v1 >> 4) & 3;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_bg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[1][3]);
 int num = ddrible_bg_videoram[tile_index + 0x400] + 256*bank;
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddrible_bg_videoram[tile_index];
 int bank = ((attr & 0xc0) >> 6) + 4*(((attr & 0x20) >> 5) | ddribble_vregs[1][3]);
 int num = ddrible_bg_videoram[tile_index + 0x400] + 256*bank;
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (num) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0x30) >> 4);
}

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


decompiled_code:
void missile_init_machine()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void missile_init_machine(void)
{
 h_pos = v_pos = 0;
}

canonical_original_code:
void missile_init_machine()
{
 h_pos = v_pos = 0;
}


decompiled_code:
__int64 missile_vh_start()
{
missile_videoram = calloc(0x10000uLL, 1uLL);
if ( !missile_videoram )
return 1LL;
missile_flipscreen = 64;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
missile_videoram = calloc(0x10000uLL, 1uLL);
if ( !missile_videoram )
return 1LL;
missile_flipscreen = 64;
return 0LL;
}

original_code:
int missile_vh_start(void)
{
 if ((missile_videoram = (unsigned char*)malloc(256 * 256)) == 0)
  return 1;
 memset (missile_videoram, 0, 256 * 256);
 missile_flipscreen = 0x40;
 return 0;
}

canonical_original_code:
int missile_vh_start()
{
 if ((missile_videoram = (unsigned char *)malloc(256 * 256)) == 0)
  return 1;
 memset (missile_videoram, 0, 256 * 256);
 missile_flipscreen = 0x40;
 return 0;
}


decompiled_code:
void missile_vh_stop()
{
free(missile_videoram);
}

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

original_code:
void missile_vh_stop(void)
{
 free(missile_videoram);
}


decompiled_code:
__int64 missile_IN0_r()
{
__int64 v0; // rdi
char v1; // bl

if ( !ctrld )
return readinputport(0LL);
if ( missile_flipscreen )
{
v0 = 6LL;
v1 = readinputport(7LL);
}
else
{
v0 = 4LL;
v1 = readinputport(5LL);
}
return readinputport(v0) & 0xF | (unsigned int)(unsigned __int8)(16 * v1);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdi
char v1; // bl

if ( !ctrld )
return readinputport(0LL);
if ( missile_flipscreen )
{
v0 = 6LL;
v1 = readinputport(7LL);
}
else
{
v0 = 4LL;
v1 = readinputport(5LL);
}
return readinputport(v0) & 0xF | (unsigned int)(unsigned __int8)(16 * v1);
}

original_code:
data_t missile_IN0_r(offs_t offset)
{
 if (ctrld)
 {
  if (!missile_flipscreen)
        return ((readinputport(5) << 4) & 0xf0) | (readinputport(4) & 0x0f);
  else
        return ((readinputport(7) << 4) & 0xf0) | (readinputport(6) & 0x0f);
 }
 else
  return (readinputport(0));
}

canonical_original_code:
unsigned int missile_IN0_r(unsigned int offset)
{
 if (ctrld)
 {
  if (!missile_flipscreen)
        return ((readinputport(5) << 4) & 0xf0) | (readinputport(4) & 0x0f);
  else
        return ((readinputport(7) << 4) & 0xf0) | (readinputport(6) & 0x0f);
 }
 else
  return (readinputport(0));
}


decompiled_code:
__int64 __fastcall missile_video_r(int a1)
{
return *(_BYTE *)(missile_videoram + a1) & 0xE0;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
return *(_BYTE *)(missile_videoram + a1) & 0xE0;
}

original_code:
int missile_video_r (int address)
{
 return (missile_videoram[address] & 0xe0);
}

canonical_original_code:
int missile_video_r(int address)
{
 return (missile_videoram[address] & 0xe0);
}

variable_types: address int


decompiled_code:
__int64 __fastcall missile_r(int a1)
{
int v1; // ebp
__int64 result; // rax

v1 = a1 + 6400;
if ( *(_BYTE *)(OP_ROM + (int)cpu_get_reg(0xFFFFFFFFLL)) == 0xA1 )
return missile_video_r(v1);
if ( v1 > 20479 )
return *(unsigned __int8 *)(missile_video2ram + v1 - 20480LL);
switch ( a1 )
{
case 12032:
return missile_IN0_r(0LL);
case 12288:
return readinputport(1LL);
case 12544:
return readinputport(2LL);
}
result = 0LL;
if ( (unsigned int)(a1 - 9984) <= 0xF )
result = pokey1_r(a1 & 0xF);
return result;
}

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

v1 = a1 + 6400;
if ( *(_BYTE *)(OP_ROM + (int)cpu_get_reg(0xFFFFFFFFLL)) == 0xA1 )
return func4(v1);
if ( v1 > 20479 )
return *(unsigned __int8 *)(missile_video2ram + v1 - 20480LL);
switch ( a1 )
{
case 12032:
return func3(0LL);
case 12288:
return readinputport(1LL);
case 12544:
return readinputport(2LL);
}
result = 0LL;
if ( (unsigned int)(a1 - 9984) <= 0xF )
result = pokey1_r(a1 & 0xF);
return result;
}

original_code:
data_t missile_r(offs_t offset)
{
 int pc, opcode;
 int address = offset + 0x1900;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0xa1)
 {
  return (missile_video_r(address));
 }
 if (address >= 0x5000)
  return missile_video2ram[address - 0x5000];
 if (address == 0x4800)
  return (missile_IN0_r(0));
 if (address == 0x4900)
  return (readinputport (1));
 if (address == 0x4a00)
  return (readinputport (2));
 if ((address >= 0x4000) && (address <= 0x400f))
  return (pokey1_r (address & 0x0f));
 return 0;
}

canonical_original_code:
unsigned int missile_r(unsigned int offset)
{
 int pc; int opcode;
 int address = offset + 0x1900;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0xa1)
 {
  return (missile_video_r(address));
 }
 if (address >= 0x5000)
  return missile_video2ram[address - 0x5000];
 if (address == 0x4800)
  return (missile_IN0_r(0));
 if (address == 0x4900)
  return (readinputport (1));
 if (address == 0x4a00)
  return (readinputport (2));
 if ((address >= 0x4000) && (address <= 0x400f))
  return (pokey1_r (address & 0x0f));
 return 0;
}

variable_types: pc int

variable_types: opcode int


decompiled_code:
void missile_flip_screen()
{
screen_flipped = 1;
}

canonical_decompiled_code:
void func6()
{
screen_flipped = 1;
}

original_code:
void missile_flip_screen (void)
{
 screen_flipped = 1;
}


decompiled_code:
__int64 __fastcall missile_blit_w(int a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
unsigned __int8 v3; // al
__int64 v4; // rdi

v1 = (unsigned __int8)a1;
v2 = (unsigned int)((a1 >> 8) - 25);
v3 = *(_BYTE *)(missile_videoram + a1) >> 5;
v4 = *(_QWORD *)(Machine + 768LL);
if ( (int)v2 > 198 )
{
if ( missile_flipscreen )
v2 = (unsigned int)(*(_DWORD *)(v4 + 4) + ~(_DWORD)v2);
}
else
{
if ( missile_flipscreen )
v2 = (unsigned int)(*(_DWORD *)(v4 + 4) + ~(_DWORD)v2);
v3 &= 6u;
}
return plot_pixel(v4, v1, v2, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v3));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
unsigned __int8 v3; // al
__int64 v4; // rdi

v1 = (unsigned __int8)a1;
v2 = (unsigned int)((a1 >> 8) - 25);
v3 = *(_BYTE *)(missile_videoram + a1) >> 5;
v4 = *(_QWORD *)(Machine + 768LL);
if ( (int)v2 > 198 )
{
if ( missile_flipscreen )
v2 = (unsigned int)(*(_DWORD *)(v4 + 4) + ~(_DWORD)v2);
}
else
{
if ( missile_flipscreen )
v2 = (unsigned int)(*(_DWORD *)(v4 + 4) + ~(_DWORD)v2);
v3 &= 6u;
}
return plot_pixel(v4, v1, v2, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * v3));
}

original_code:
void missile_blit_w (int offset)
{
 int x, y;
 int bottom;
 int color;
 y = (offset >> 8) - 25;
 x = offset & 0xff;
 if( y < 231 - 32)
  bottom = 1;
 else
  bottom = 0;
 if (missile_flipscreen)
 {
  y = Machine->scrbitmap->height - 1 - y;
 }
 color = (missile_videoram[offset] >> 5);
 if (bottom) color &= 0x06;
 plot_pixel(Machine->scrbitmap, x, y, Machine->pens[color]);
}

canonical_original_code:
void missile_blit_w(int offset)
{
 int x; int y;
 int bottom;
 int color;
 y = (offset >> 8) - 25;
 x = offset & 0xff;
 if( y < 231 - 32)
  bottom = 1;
 else
  bottom = 0;
 if (missile_flipscreen)
 {
  y = Machine->scrbitmap->height - 1 - y;
 }
 color = (missile_videoram[offset] >> 5);
 if (bottom) color &= 0x06;
 plot_pixel(Machine->scrbitmap, x, y, Machine->pens[color]);
}

variable_types: offset int

variable_types: y int

variable_types: bottom int

variable_types: color int


decompiled_code:
__int64 __fastcall missile_video_3rd_bit_w(int a1, int a2)
{
__int64 v2; // r14
int v3; // ebx
int v4; // er13
__int64 v5; // rbx
_BYTE *v6; // rdx
int v7; // edi
char v8; // al
__int64 result; // rax

v2 = 0LL;
v3 = 4 * a1 - 4;
v4 = v3 + 63488;
*(_BYTE *)(memory_region(129LL) + a1 + 1024) = a2;
v5 = v3 + 63488LL;
do
{
v6 = (_BYTE *)(missile_videoram + v5 + v2);
v7 = v4 + v2;
v8 = *v6 | 0x20;
if ( (a2 & (1 << v2)) == 0 )
v8 = *v6 & 0xC0;
++v2;
*v6 = v8;
result = missile_blit_w(v7);
}
while ( v2 != 8 );
return result;
}

original_code:
void missile_video_3rd_bit_w(offs_t offset,data_t data)
{
 int i;
 unsigned char *RAM = memory_region(REGION_CPU1);
 int address = offset + 0x400;
 RAM[address] = data;
 address = ((address - 0x401) << 2) + 0xf800;
 for (i=0; i<8; i++)
 {
  if (data & (1 << i))
   missile_videoram[address + i] |= 0x20;
  else
   missile_videoram[address + i] &= 0xc0;
  missile_blit_w (address + i);
 }
}

canonical_original_code:
void missile_video_3rd_bit_w(unsigned int offset, unsigned int data)
{
 int i;
 unsigned char *RAM = memory_region(REGION_CPU1);
 int address = offset + 0x400;
 RAM[address] = data;
 address = ((address - 0x401) << 2) + 0xf800;
 for (i=0; i<8; i++)
 {
  if (data & (1 << i))
   missile_videoram[address + i] |= 0x20;
  else
   missile_videoram[address + i] &= 0xc0;
  missile_blit_w (address + i);
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall missile_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 result; // rax
int v4; // edi

v2 = 6400;
result = palette_recalc();
if ( result || screen_flipped | a2 )
{
do
{
v4 = v2++;
result = missile_blit_w(v4);
}
while ( v2 != 0x10000 );
screen_flipped = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
int v2; // ebx
__int64 result; // rax
int v4; // edi

v2 = 6400;
result = palette_recalc();
if ( result || screen_flipped | a2 )
{
do
{
v4 = v2++;
result = func7(v4);
}
while ( v2 != 0x10000 );
screen_flipped = 0;
}
return result;
}

original_code:
void missile_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int address;
 if (palette_recalc() || full_refresh || screen_flipped)
 {
  for (address = 0x1900; address <= 0xffff; address++)
   missile_blit_w (address);
  screen_flipped = 0;
 }
}

canonical_original_code:
void missile_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int address;
 if (palette_recalc() || full_refresh || screen_flipped)
 {
  for (address = 0x1900; address <= 0xffff; address++)
   missile_blit_w (address);
  screen_flipped = 0;
 }
}

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


decompiled_code:
__int64 __fastcall missile_video_mult_w(int a1, char a2)
{
int v2; // ebx
char v3; // si

v2 = 4 * a1;
v3 = (8 * a2) & 0x40 | a2 & 0x80;
if ( 4 * a1 > 63487 )
v3 |= 0x20u;
*(_BYTE *)(missile_videoram + v2) = v3;
*(_BYTE *)(missile_videoram + v2 + 1LL) = v3;
*(_BYTE *)(missile_videoram + v2 + 2LL) = v3;
*(_BYTE *)(missile_videoram + v2 + 3LL) = v3;
missile_blit_w(v2);
missile_blit_w(v2 + 1);
missile_blit_w(v2 + 2);
return missile_blit_w(v2 + 3);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, char a2)
{
int v2; // ebx
char v3; // si

v2 = 4 * a1;
v3 = (8 * a2) & 0x40 | a2 & 0x80;
if ( 4 * a1 > 63487 )
v3 |= 0x20u;
*(_BYTE *)(missile_videoram + v2) = v3;
*(_BYTE *)(missile_videoram + v2 + 1LL) = v3;
*(_BYTE *)(missile_videoram + v2 + 2LL) = v3;
*(_BYTE *)(missile_videoram + v2 + 3LL) = v3;
func7(v2);
func7(v2 + 1);
func7(v2 + 2);
return func7(v2 + 3);
}

original_code:
void missile_video_mult_w (int address, int data)
{
 data = (data & 0x80) + ((data & 8) << 3);
 address = address << 2;
 if (address >= 0xf800) data |= 0x20;
 missile_videoram[address] = data;
 missile_videoram[address + 1] = data;
 missile_videoram[address + 2] = data;
 missile_videoram[address + 3] = data;
 missile_blit_w (address);
 missile_blit_w (address + 1);
 missile_blit_w (address + 2);
 missile_blit_w (address + 3);
}

canonical_original_code:
void missile_video_mult_w(int address, int data)
{
 data = (data & 0x80) + ((data & 8) << 3);
 address = address << 2;
 if (address >= 0xf800) data |= 0x20;
 missile_videoram[address] = data;
 missile_videoram[address + 1] = data;
 missile_videoram[address + 2] = data;
 missile_videoram[address + 3] = data;
 missile_blit_w (address);
 missile_blit_w (address + 1);
 missile_blit_w (address + 2);
 missile_blit_w (address + 3);
}

variable_types: data int


decompiled_code:
__int64 __fastcall missile_w(int a1, unsigned int a2)
{
int v2; // er12
__int64 result; // rax
__int64 v4; // rdi

v2 = a1 + 1600;
result = (int)cpu_get_reg(0xFFFFFFFFLL);
if ( *(_BYTE *)(OP_ROM + (int)result) == 0x81 )
return missile_video_w(v2, a2);
if ( v2 <= 0x3FFF )
return missile_video_mult_w(v2, a2);
if ( a1 == 17856 )
return watchdog_reset_w(19456LL, a2);
if ( a1 == 16832 )
{
if ( (((unsigned __int8)(a2 >> 6) ^ 1) & 1) != missile_flipscreen )
missile_flip_screen();
missile_flipscreen = ((unsigned __int8)(a2 >> 6) ^ 1) & 1;
coin_counter_w(0LL, a2 & 0x20);
coin_counter_w(1LL, a2 & 0x10);
coin_counter_w(2LL, a2 & 8);
osd_led_w(0LL, ~a2 >> 1);
result = osd_led_w(1LL, ~a2 >> 2);
ctrld = a2 & 1;
}
else if ( a1 != 18112 )
{
result = (unsigned int)(a1 - 14784);
if ( (unsigned int)result <= 0xF )
{
result = pokey1_w((unsigned int)v2, a2);
}
else
{
v4 = (unsigned int)(a1 - 17600);
if ( (unsigned int)v4 <= 7 )
result = palette_change_color(v4, 255 * ((~a2 >> 3) & 1), 255 * ((~a2 >> 2) & 1), 255 * ((~a2 >> 1) & 1));
}
}
return result;
}

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

v2 = a1 + 1600;
result = (int)cpu_get_reg(0xFFFFFFFFLL);
if ( *(_BYTE *)(OP_ROM + (int)result) == 0x81 )
return func10(v2, a2);
if ( v2 <= 0x3FFF )
return func12(v2, a2);
if ( a1 == 17856 )
return watchdog_reset_w(19456LL, a2);
if ( a1 == 16832 )
{
if ( (((unsigned __int8)(a2 >> 6) ^ 1) & 1) != missile_flipscreen )
func6();
missile_flipscreen = ((unsigned __int8)(a2 >> 6) ^ 1) & 1;
coin_counter_w(0LL, a2 & 0x20);
coin_counter_w(1LL, a2 & 0x10);
coin_counter_w(2LL, a2 & 8);
osd_led_w(0LL, ~a2 >> 1);
result = osd_led_w(1LL, ~a2 >> 2);
ctrld = a2 & 1;
}
else if ( a1 != 18112 )
{
result = (unsigned int)(a1 - 14784);
if ( (unsigned int)result <= 0xF )
{
result = pokey1_w((unsigned int)v2, a2);
}
else
{
v4 = (unsigned int)(a1 - 17600);
if ( (unsigned int)v4 <= 7 )
result = palette_change_color(v4, 255 * ((~a2 >> 3) & 1), 255 * ((~a2 >> 2) & 1), 255 * ((~a2 >> 1) & 1));
}
}
return result;
}

original_code:
void missile_w(offs_t offset,data_t data)
{
 int pc, opcode;
 int address = offset + 0x640;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0x81)
 {
  missile_video_w (address, data);
  return;
 }
 if (address <= 0x3fff)
 {
  missile_video_mult_w (address, data);
  return;
 }
 if (address == 0x4c00)
 {
  watchdog_reset_w (address, data);
  return;
 }
 if (address == 0x4800)
 {
  if (missile_flipscreen != (!(data & 0x40)))
   missile_flip_screen ();
  missile_flipscreen = !(data & 0x40);
  coin_counter_w (0, data & 0x20);
  coin_counter_w (1, data & 0x10);
  coin_counter_w (2, data & 0x08);
  osd_led_w (0, ~data >> 1);
  osd_led_w (1, ~data >> 2);
  ctrld = data & 1;
  return;
 }
 if (address == 0x4d00)
 {
  return;
 }
 if (address >= 0x4000 && address <= 0x400f)
 {
  pokey1_w (address, data);
  return;
 }
 if (address >= 0x4b00 && address <= 0x4b07)
 {
  int r,g,b;
  r = 0xff * ((~data >> 3) & 1);
  g = 0xff * ((~data >> 2) & 1);
  b = 0xff * ((~data >> 1) & 1);
  palette_change_color(address - 0x4b00,r,g,b);
  return;
 }
}

canonical_original_code:
void missile_w(unsigned int offset, unsigned int data)
{
 int pc; int opcode;
 int address = offset + 0x640;
 pc = cpu_get_reg(-1);
 opcode = (OP_ROM[pc]);
 if (opcode == 0x81)
 {
  missile_video_w (address, data);
  return;
 }
 if (address <= 0x3fff)
 {
  missile_video_mult_w (address, data);
  return;
 }
 if (address == 0x4c00)
 {
  watchdog_reset_w (address, data);
  return;
 }
 if (address == 0x4800)
 {
  if (missile_flipscreen != (!(data & 0x40)))
   missile_flip_screen ();
  missile_flipscreen = !(data & 0x40);
  coin_counter_w (0, data & 0x20);
  coin_counter_w (1, data & 0x10);
  coin_counter_w (2, data & 0x08);
  osd_led_w (0, ~data >> 1);
  osd_led_w (1, ~data >> 2);
  ctrld = data & 1;
  return;
 }
 if (address == 0x4d00)
 {
  return;
 }
 if (address >= 0x4000 && address <= 0x400f)
 {
  pokey1_w (address, data);
  return;
 }
 if (address >= 0x4b00 && address <= 0x4b07)
 {
  int r; int g; int b;
  r = 0xff * ((~data >> 3) & 1);
  g = 0xff * ((~data >> 2) & 1);
  b = 0xff * ((~data >> 1) & 1);
  palette_change_color(address - 0x4b00,r,g,b);
  return;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall get_tile_info_screen0(int a1)
{
__int16 v1; // dx
unsigned __int8 v2; // ch
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int16 v1; // dx
unsigned __int8 v2; // ch
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

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

original_code:
static void get_tile_info_screen0(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code + ((0x20 + (attr & 0x0f)) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info_screen0(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code + ((0x20 + (attr & 0x0f)) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types:
data
unsigned short

variable_types:
attr
unsigned char

variable_types:
code
unsigned char


decompiled_code:
__int64 __fastcall get_tile_info_screen1(int a1)
{
__int16 v1; // dx
unsigned __int8 v2; // ch
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = *(_WORD *)(splash_videoram + 2 * a1 + 4096LL);
v2 = HIBYTE(v1);
*((_DWORD *)&tile_info + 5) = ((int)(unsigned __int8)v1 >> 1) & 1 | (2 * (_BYTE)v1) & 2;
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (((unsigned __int8)v1 >> 2) + (((HIBYTE(v1) & 0xFu) + 48) << 6)) % *(_DWORD *)(v3 + 8);
v5 = *(_DWORD *)(v3 + 12) * (v2 >> 4);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info_screen1(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index+0x1000]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 tile_info.flags = ((((code & 0x03)>>1)|((code & 0x03)<<1))&3);
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((code >> 2) + ((0x30 + (attr & 0x0f)) << 6)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info_screen1(int tile_index)
{
 unsigned short data = (*(UINT16 *)(&splash_videoram[2*tile_index+0x1000]));
 unsigned char attr = data >> 8;
 unsigned char code = data & 0xff;
 tile_info.flags = ((((code & 0x03)>>1)|((code & 0x03)<<1))&3);
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((code >> 2) + ((0x30 + (attr & 0x0f)) << 6)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xf0) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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 splash_vram_r(unsigned int a1)
{
return *(unsigned __int16 *)(splash_videoram + a1);
}

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

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

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


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

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

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

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


decompiled_code:
__int64 __fastcall splash_pixelram_w(unsigned int a1, int a2)
{
_WORD *v2; // rax
__int16 v3; // si

v2 = (_WORD *)(splash_pixelram + a1);
v3 = a2 | *v2 & HIWORD(a2);
*v2 = v3;
return plot_pixel(
screen2,
((a1 >> 1) & 0x1FF) - 9,
a1 >> 10,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned __int8)v3 + 1536));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2)
{
_WORD *v2; // rax
__int16 v3; // si

v2 = (_WORD *)(splash_pixelram + a1);
v3 = a2 | *v2 & HIWORD(a2);
*v2 = v3;
return plot_pixel(
screen2,
((a1 >> 1) & 0x1FF) - 9,
a1 >> 10,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (unsigned __int8)v3 + 1536));
}

original_code:
void splash_pixelram_w(offs_t offset,data_t data)
{
 int sx,sy,color;
 ((*(UINT16 *)((&splash_pixelram[offset])) = (((*(UINT16 *)(&splash_pixelram[offset])) & ((data) >> 16)) | (data))));
 sx = (offset >> 1) & 0x1ff;
 sy = (offset >> 10);
 color = (*(UINT16 *)(&splash_pixelram[offset]));
 plot_pixel(screen2, sx-9, sy, Machine->pens[0x300 + (color & 0xff)]);
}

canonical_original_code:
void splash_pixelram_w(unsigned int offset, unsigned int data)
{
 int sx; int sy; int color;
 ((*(unsigned short *)((&splash_pixelram[offset])) = (((*(unsigned short *)(&splash_pixelram[offset])) & ((data) >> 16)) | (data))));
 sx = (offset >> 1) & 0x1ff;
 sy = (offset >> 10);
 color = (*(unsigned short *)(&splash_pixelram[offset]));
 plot_pixel(screen2, sx-9, sy, Machine->pens[0x300 + (color & 0xff)]);
}

variable_types: sx int

variable_types: sy int


decompiled_code:
void __fastcall splash_adpcm_data_w(__int64 a1, int a2)
{
adpcm_data = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
adpcm_data = a2;
}

original_code:
static void splash_adpcm_data_w(offs_t offset,data_t data){
 adpcm_data = data;
}

canonical_original_code:
static void splash_adpcm_data_w(unsigned int offset, unsigned int data){
 adpcm_data = data;
}


decompiled_code:
__int64 __fastcall paletteram_xRRRRxGGGGxBBBBx_word_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rax
int v3; // edx

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return palette_change_color(
a1 >> 1,
(16 * ((v3 >> 11) & 0xF)) | (v3 >> 11) & 0xFu,
(16 * ((v3 >> 6) & 0xF)) | (v3 >> 6) & 0xFu,
(16 * ((v3 >> 1) & 0xF)) | (v3 >> 1) & 0xFu);
}

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

v2 = (_WORD *)(paletteram + a1);
v3 = (unsigned __int16)a2 | (unsigned __int16)*v2 & HIWORD(a2);
*v2 = v3;
return palette_change_color(
a1 >> 1,
(16 * ((v3 >> 11) & 0xF)) | (v3 >> 11) & 0xFu,
(16 * ((v3 >> 6) & 0xF)) | (v3 >> 6) & 0xFu,
(16 * ((v3 >> 1) & 0xF)) | (v3 >> 1) & 0xFu);
}

original_code:
void paletteram_xRRRRxGGGGxBBBBx_word_w(offs_t offset,data_t data)
{
 int r,g,b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 r = (newword >> 11) & 0x0f;
 g = (newword >> 6) & 0x0f;
 b = (newword >> 1) & 0x0f;
 r = (r << 4) | r;
 g = (g << 4) | g;
 b = (b << 4) | b;
 palette_change_color(offset >> 1, r, g, b);
}

canonical_original_code:
void paletteram_xRRRRxGGGGxBBBBx_word_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 r = (newword >> 11) & 0x0f;
 g = (newword >> 6) & 0x0f;
 b = (newword >> 1) & 0x0f;
 r = (r << 4) | r;
 g = (g << 4) | g;
 b = (b << 4) | b;
 palette_change_color(offset >> 1, r, g, b);
}

variable_types: oldword int

variable_types: newword int


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

*(_WORD *)(splash_videoram + a1) = a2 | *(_WORD *)(splash_videoram + a1) & HIWORD(a2);
if ( a1 > 0xFFF )
result = tilemap_mark_tile_dirty(screen1, (a1 - 4096) >> 1);
else
result = tilemap_mark_tile_dirty(screen0, a1 >> 1);
return result;
}

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

*(_WORD *)(splash_videoram + a1) = a2 | *(_WORD *)(splash_videoram + a1) & HIWORD(a2);
if ( a1 > 0xFFF )
result = tilemap_mark_tile_dirty(screen1, (a1 - 4096) >> 1);
else
result = tilemap_mark_tile_dirty(screen0, a1 >> 1);
return result;
}

original_code:
void splash_vram_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&splash_videoram[offset])) = (((*(UINT16 *)(&splash_videoram[offset])) & ((data) >> 16)) | (data))));
 if (offset < 0x1000){
  tilemap_mark_tile_dirty(screen0,offset/2);
 }
 else{
  offset -= 0x1000;
  tilemap_mark_tile_dirty(screen1,offset/2);
 }
}

canonical_original_code:
void splash_vram_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&splash_videoram[offset])) = (((*(unsigned short *)(&splash_videoram[offset])) & ((data) >> 16)) | (data))));
 if (offset < 0x1000){
  tilemap_mark_tile_dirty(screen0,offset/2);
 }
 else{
  offset -= 0x1000;
  tilemap_mark_tile_dirty(screen1,offset/2);
 }
}


decompiled_code:
__int64 splash_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rdi
__int64 v3; // rdx
__int64 v5; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_tile_info_screen0, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v5) = 32;
screen0 = v0;
screen1 = tilemap_create(get_tile_info_screen1, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v5);
v1 = bitmap_alloc(512LL, 256LL);
v2 = screen0;
screen2 = v1;
if ( !screen0 )
return 1LL;
v3 = screen1;
if ( !screen1 || !v1 )
return 1LL;
*(_DWORD *)(screen0 + 132) = 0;
*(_DWORD *)(v3 + 132) = 0;
tilemap_set_scrollx(v2, 0LL, 4LL);
return 0LL;
}

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

v0 = tilemap_create(get_tile_info_screen0, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v5) = 32;
screen0 = v0;
screen1 = tilemap_create(get_tile_info_screen1, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v5);
v1 = bitmap_alloc(512LL, 256LL);
v2 = screen0;
screen2 = v1;
if ( !screen0 )
return 1LL;
v3 = screen1;
if ( !screen1 || !v1 )
return 1LL;
*(_DWORD *)(screen0 + 132) = 0;
*(_DWORD *)(v3 + 132) = 0;
tilemap_set_scrollx(v2, 0LL, 4LL);
return 0LL;
}

original_code:
int splash_vh_start(void)
{
 screen0 = tilemap_create(get_tile_info_screen0,tilemap_scan_rows,0x01, 8, 8,64,32);
 screen1 = tilemap_create(get_tile_info_screen1,tilemap_scan_rows,0x01,16,16,32,32);
 screen2 = bitmap_alloc (512, 256);
 if (!screen0 || !screen1 || !screen2)
  return 1;
 screen0->transparent_pen = 0;
 screen1->transparent_pen = 0;
 tilemap_set_scrollx(screen0, 0, 4);
 return 0;
}

canonical_original_code:
int splash_vh_start()
{
 screen0 = tilemap_create(get_tile_info_screen0,tilemap_scan_rows,0x01, 8, 8,64,32);
 screen1 = tilemap_create(get_tile_info_screen1,tilemap_scan_rows,0x01,16,16,32,32);
 screen2 = bitmap_alloc (512, 256);
 if (!screen0 || !screen1 || !screen2)
  return 1;
 screen0->transparent_pen = 0;
 screen1->transparent_pen = 0;
 tilemap_set_scrollx(screen0, 0, 4);
 return 0;
}


decompiled_code:
__int64 __fastcall splash_vh_screenrefresh(__int64 a1)
{
tilemap_set_scrolly(screen0, 0LL, (unsigned __int16)*splash_vregs);
tilemap_set_scrolly(screen1, 0LL, (unsigned __int16)splash_vregs[1]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
copybitmap(a1, screen2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
tilemap_draw(a1, screen1, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, screen0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
tilemap_set_scrolly(screen0, 0LL, (unsigned __int16)*splash_vregs);
tilemap_set_scrolly(screen1, 0LL, (unsigned __int16)splash_vregs[1]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
copybitmap(a1, screen2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
tilemap_draw(a1, screen1, 0LL);
func9(a1);
return tilemap_draw(a1, screen0, 0LL);
}

original_code:
void splash_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_set_scrolly(screen0, 0, (*(UINT16 *)(&splash_vregs[0])));
 tilemap_set_scrolly(screen1, 0, (*(UINT16 *)(&splash_vregs[2])));
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 copybitmap(bitmap,screen2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 tilemap_draw(bitmap,screen1,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,screen0,0);
}

canonical_original_code:
void splash_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_set_scrolly(screen0, 0, (*(unsigned short *)(&splash_vregs[0])));
 tilemap_set_scrolly(screen1, 0, (*(unsigned short *)(&splash_vregs[2])));
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 copybitmap(bitmap,screen2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 tilemap_draw(bitmap,screen1,0);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,screen0,0);
}


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

MSM5205_data_w(0LL, (unsigned int)(adpcm_data >> 4));
result = (unsigned __int8)(16 * adpcm_data);
adpcm_data = (unsigned __int8)(16 * adpcm_data);
return result;
}

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

MSM5205_data_w(0LL, (unsigned int)(adpcm_data >> 4));
result = (unsigned __int8)(16 * adpcm_data);
adpcm_data = (unsigned __int8)(16 * adpcm_data);
return result;
}

original_code:
static void splash_msm5205_int(int data)
{
 MSM5205_data_w(0,adpcm_data >> 4);
 adpcm_data = (adpcm_data << 4) & 0xf0;
}


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

if ( (a2 & 0xFF0000) == 0 )
{
soundlatch_w(0LL, (unsigned __int8)a2);
result = cpu_cause_interrupt(1LL, 4294966296LL);
}
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
{
soundlatch_w(0LL, (unsigned __int8)a2);
result = cpu_cause_interrupt(1LL, 4294966296LL);
}
return result;
}

original_code:
static void splash_sh_irqtrigger_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
 {
  soundlatch_w(0,data & 0xff);
  cpu_cause_interrupt(1,-1000);
 }
}

canonical_original_code:
static void splash_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
 {
  soundlatch_w(0,data & 0xff);
  cpu_cause_interrupt(1,-1000);
 }
}


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r15
__int64 v3; // rsi
__int64 v4; // r13
__int16 v5; // r8
unsigned __int16 v6; // ax
int v7; // edi
char v8; // cl
__int64 v9; // rdx
__int64 result; // rax

v1 = 4LL;
v3 = Machine;
v4 = *(_QWORD *)(Machine + 520LL);
while ( 1 )
{
v5 = *(_WORD *)(splash_spriteram + v1 + 2);
v6 = *(unsigned __int8 *)(splash_spriteram + v1);
v7 = *(unsigned __int8 *)(splash_spriteram + v1 - 2);
v8 = *(_BYTE *)(splash_spriteram + v1 + 2045);
v9 = *(unsigned __int8 *)(splash_spriteram + v1 - 4) + ((unsigned __int8)(v5 & 0xF) << 8);
if ( v8 < 0 )
v6 += 256;
v1 += 8LL;
result = drawgfx(
a1,
v4,
v9,
(v8 & 0xFu) + 16,
v5 & 0x40,
(unsigned __int8)v5 & 0x80,
(unsigned int)v6 - 8,
(unsigned int)(240 - v7),
v3 + 776,
2LL,
0LL);
if ( v1 == 2052 )
break;
v3 = Machine;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // r15
__int64 v3; // rsi
__int64 v4; // r13
__int16 v5; // r8
unsigned __int16 v6; // ax
int v7; // edi
char v8; // cl
__int64 v9; // rdx
__int64 result; // rax

v1 = 4LL;
v3 = Machine;
v4 = *(_QWORD *)(Machine + 520LL);
while ( 1 )
{
v5 = *(_WORD *)(splash_spriteram + v1 + 2);
v6 = *(unsigned __int8 *)(splash_spriteram + v1);
v7 = *(unsigned __int8 *)(splash_spriteram + v1 - 2);
v8 = *(_BYTE *)(splash_spriteram + v1 + 2045);
v9 = *(unsigned __int8 *)(splash_spriteram + v1 - 4) + ((unsigned __int8)(v5 & 0xF) << 8);
if ( v8 < 0 )
v6 += 256;
v1 += 8LL;
result = drawgfx(
a1,
v4,
v9,
(v8 & 0xFu) + 16,
v5 & 0x40,
(unsigned __int8)v5 & 0x80,
(unsigned int)v6 - 8,
(unsigned int)(240 - v7),
v3 + 776,
2LL,
0LL);
if ( v1 == 2052 )
break;
v3 = Machine;
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int i;
 const struct GfxElement *gfx = Machine->gfx[1];
 for (i = 0; i < 0x800; i += 8){
  int sx = (*(UINT16 *)(&splash_spriteram[i+4])) & 0xff;
  int sy = 256 - ((*(UINT16 *)(&splash_spriteram[i+2])) & 0xff);
  int attr = (*(UINT16 *)(&splash_spriteram[i+6])) & 0xff;
  int attr2 = (*(UINT16 *)(&splash_spriteram[i+0x800])) >> 8;
  int number = ((*(UINT16 *)(&splash_spriteram[i])) & 0xff) + (attr & 0xf)*256;
  if (attr2 & 0x80) sx += 256;
  drawgfx(bitmap,gfx,
   number,
   0x10 + (attr2 & 0x0f),
   attr & 0x40, attr & 0x80,
   sx-8,sy-16,
   &Machine->visible_area,
   TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int i;
 struct GfxElement *gfx = Machine->gfx[1];
 for (i = 0; i < 0x800; i += 8){
  int sx = (*(UINT16 *)(&splash_spriteram[i+4])) & 0xff;
  int sy = 256 - ((*(UINT16 *)(&splash_spriteram[i+2])) & 0xff);
  int attr = (*(UINT16 *)(&splash_spriteram[i+6])) & 0xff;
  int attr2 = (*(UINT16 *)(&splash_spriteram[i+0x800])) >> 8;
  int number = ((*(UINT16 *)(&splash_spriteram[i])) & 0xff) + (attr & 0xf)*256;
  if (attr2 & 0x80) sx += 256;
  drawgfx(bitmap,gfx,
   number,
   0x10 + (attr2 & 0x0f),
   attr & 0x40, attr & 0x80,
   sx-8,sy-16,
   &Machine->visible_area,
   TRANSPARENCY_PEN,0);
 }
}

variable_types: attr int

variable_types: number int


decompiled_code:
__int64 fastlane_vh_start()
{
__int64 v0; // rax
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // [rsp+0h] [rbp-28h]
__m128i v4; // [rsp+10h] [rbp-18h] BYREF

v0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
layer0 = v0;
layer1 = tilemap_create(get_tile_info1, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, v3);
tilemap_set_scroll_rows(layer0, 32LL);
result = 1LL;
if ( layer0 )
{
if ( layer1 )
{
v4 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v4.m128i_i32[0] += 40;
((void (__fastcall *)(__int64, __m128i *))tilemap_set_clip)(layer0, &v4);
v4.m128i_i64[0] = 0x2700000000LL;
tilemap_set_clip(layer1, &v4, v2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // [rsp+0h] [rbp-28h]
__m128i v4; // [rsp+10h] [rbp-18h] BYREF

v0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
layer0 = v0;
layer1 = tilemap_create(get_tile_info1, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, v3);
tilemap_set_scroll_rows(layer0, 32LL);
result = 1LL;
if ( layer0 )
{
if ( layer1 )
{
v4 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v4.m128i_i32[0] += 40;
((void (__fastcall *)(__int64, __m128i *))tilemap_set_clip)(layer0, &v4);
v4.m128i_i64[0] = 0x2700000000LL;
tilemap_set_clip(layer1, &v4, v2);
result = 0LL;
}
}
return result;
}

original_code:
int fastlane_vh_start(void)
{
 layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,0x00,8,8,32,32);
 layer1 = tilemap_create(get_tile_info1,tilemap_scan_rows,0x00,8,8,32,32);
 tilemap_set_scroll_rows( layer0, 32 );
 if (!layer0 || !layer1)
  return 1;
 {
  struct rectangle clip = Machine->visible_area;
  clip.min_x += 40;
  tilemap_set_clip(layer0,&clip);
  clip.max_x = 39;
  clip.min_x = 0;
  tilemap_set_clip(layer1,&clip);
  return 0;
 }
}

canonical_original_code:
int fastlane_vh_start()
{
 layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,0x00,8,8,32,32);
 layer1 = tilemap_create(get_tile_info1,tilemap_scan_rows,0x00,8,8,32,32);
 tilemap_set_scroll_rows( layer0, 32 );
 if (!layer0 || !layer1)
  return 1;
 {
  struct rectangle clip = Machine->visible_area;
  clip.min_x += 40;
  tilemap_set_clip(layer0,&clip);
  clip.max_x = 39;
  clip.min_x = 0;
  tilemap_set_clip(layer1,&clip);
  return 0;
 }
}

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


decompiled_code:
__int64 __fastcall fastlane_vh_screenrefresh(__int64 a1)
{
int v1; // er12
__int64 i; // rbx
__int64 v3; // rsi
int v4; // eax

v1 = K007121_ctrlram[0];
for ( i = 0LL; i != 32; ++i )
{
v3 = (unsigned int)i;
v4 = *(unsigned __int8 *)(fastlane_k007121_regs + i + 32);
tilemap_set_scrollx(layer0, v3, (unsigned int)(v1 + v4 - 40));
}
tilemap_set_scrolly(layer0, 0LL, (unsigned __int8)K007121_ctrlram[2]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, layer0, 0LL);
K007121_sprites_draw(0LL, a1, spriteram, 0LL, 40LL, 0LL, -1LL);
return tilemap_draw(a1, layer1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // er12
__int64 i; // rbx
__int64 v3; // rsi
int v4; // eax

v1 = K007121_ctrlram[0];
for ( i = 0LL; i != 32; ++i )
{
v3 = (unsigned int)i;
v4 = *(unsigned __int8 *)(fastlane_k007121_regs + i + 32);
tilemap_set_scrollx(layer0, v3, (unsigned int)(v1 + v4 - 40));
}
tilemap_set_scrolly(layer0, 0LL, (unsigned __int8)K007121_ctrlram[2]);
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, layer0, 0LL);
K007121_sprites_draw(0LL, a1, spriteram, 0LL, 40LL, 0LL, -1LL);
return tilemap_draw(a1, layer1, 0LL);
}

original_code:
void fastlane_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i, xoffs;
 xoffs = K007121_ctrlram[0][0x00];
 for( i=0; i<32; i++ ){
  tilemap_set_scrollx(layer0, i, fastlane_k007121_regs[0x20 + i] + xoffs - 40);
 }
 tilemap_set_scrolly( layer0, 0, K007121_ctrlram[0][0x02] );
 tilemap_update( 0 );
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 tilemap_draw(bitmap,layer0,0);
 K007121_sprites_draw(0,bitmap,spriteram,0,40,0,-1);
 tilemap_draw(bitmap,layer1,0);
}

canonical_original_code:
void fastlane_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i; int xoffs;
 xoffs = K007121_ctrlram[0][0x00];
 for( i=0; i<32; i++ ){
  tilemap_set_scrollx(layer0, i, fastlane_k007121_regs[0x20 + i] + xoffs - 40);
 }
 tilemap_set_scrolly( layer0, 0, K007121_ctrlram[0][0x02] );
 tilemap_update( 0 );
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render( 0 );
 tilemap_draw(bitmap,layer0,0);
 K007121_sprites_draw(0,bitmap,spriteram,0,40,0,-1);
 tilemap_draw(bitmap,layer1,0);
}

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

variable_types: i int

variable_types: xoffs int


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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (K007121_ctrlram[7] & 1) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (K007121_ctrlram[7] & 2) == 0 )
return ignore_interrupt();
result = 1LL;
}
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (K007121_ctrlram[7] & 1) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (K007121_ctrlram[7] & 2) == 0 )
return ignore_interrupt();
result = 1LL;
}
return result;
}

original_code:
static int fastlane_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (K007121_ctrlram[0][0x07] & 0x02) return 1;
 }
 else if (cpu_getiloops() % 2)
 {
  if (K007121_ctrlram[0][0x07] & 0x01) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int fastlane_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (K007121_ctrlram[0][0x07] & 0x02) return 1;
 }
 else if (cpu_getiloops() % 2)
 {
  if (K007121_ctrlram[0][0x07] & 0x01) return nmi_interrupt();
 }
 return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall fastlane_K007232_write_port_1_w(int a1)
{
return K007232_write_port_1_w(a1 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return K007232_write_port_1_w(a1 ^ 1u);
}

original_code:
static void fastlane_K007232_write_port_1_w(offs_t offset,data_t data)
{
 K007232_write_port_1_w(offset ^ 1, data);
}

canonical_original_code:
static void fastlane_K007232_write_port_1_w(unsigned int offset, unsigned int data)
{
 K007232_write_port_1_w(offset ^ 1, data);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall fastlane_K007232_write_port_0_w(int a1)
{
return K007232_write_port_0_w(a1 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return K007232_write_port_0_w(a1 ^ 1u);
}

original_code:
static void fastlane_K007232_write_port_0_w(offs_t offset,data_t data)
{
 K007232_write_port_0_w(offset ^ 1, data);
}

canonical_original_code:
static void fastlane_K007232_write_port_0_w(unsigned int offset, unsigned int data)
{
 K007232_write_port_0_w(offset ^ 1, data);
}


decompiled_code:
__int64 __fastcall fastlane_bankswitch_w(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
cpu_bankbase[1] = v2 + ((((a2 >> 2) & 3) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
cpu_setOPbase16(v5);
}
v3 = memory_region(147LL);
return K007232_bankswitch(1LL, v3 + ((a2 << 14) & 0x40000), v3 + ((a2 << 14) & 0x40000));
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax
unsigned int v5; // eax

v2 = memory_region(129LL);
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
cpu_bankbase[1] = v2 + ((((a2 >> 2) & 3) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
cpu_setOPbase16(v5);
}
v3 = memory_region(147LL);
return K007232_bankswitch(1LL, v3 + ((a2 << 14) & 0x40000), v3 + ((a2 << 14) & 0x40000));
}

original_code:
static void fastlane_bankswitch_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 bankaddress = 0x10000 + ((data & 0x0c) >> 2) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 RAM = memory_region(REGION_SOUND2);
 K007232_bankswitch(1,RAM + 0x40000*((data & 0x10) >> 4),RAM + 0x40000*((data & 0x10) >> 4));
}

canonical_original_code:
static void fastlane_bankswitch_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 bankaddress = 0x10000 + ((data & 0x0c) >> 2) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 RAM = memory_region(REGION_SOUND2);
 K007232_bankswitch(1,RAM + 0x40000*((data & 0x10) >> 4),RAM + 0x40000*((data & 0x10) >> 4));
}

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall fastlane_K007232_read_port_1_r(int a1)
{
return K007232_read_port_1_r(a1 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return K007232_read_port_1_r(a1 ^ 1u);
}

original_code:
static data_t fastlane_K007232_read_port_1_r(offs_t offset)
{
 return K007232_read_port_1_r(offset ^ 1);
}

canonical_original_code:
static unsigned int fastlane_K007232_read_port_1_r(unsigned int offset)
{
 return K007232_read_port_1_r(offset ^ 1);
}


decompiled_code:
__int64 __fastcall fastlane_K007232_read_port_0_r(int a1)
{
return K007232_read_port_0_r(a1 ^ 1u);
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return K007232_read_port_0_r(a1 ^ 1u);
}

original_code:
static data_t fastlane_K007232_read_port_0_r(offs_t offset)
{
 return K007232_read_port_0_r(offset ^ 1);
}

canonical_original_code:
static unsigned int fastlane_K007232_read_port_0_r(unsigned int offset)
{
 return K007232_read_port_0_r(offset ^ 1);
}


original_code:
static void get_tile_info0(int tile_index)
{
 int attr = fastlane_videoram1[tile_index];
 int code = fastlane_videoram1[tile_index + 0x400];
 int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
 int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
 int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
 int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
 int bank = ((attr & 0x80) >> 7) |
   ((attr >> (bit0+2)) & 0x02) |
   ((attr >> (bit1+1)) & 0x04) |
   ((attr >> (bit2 )) & 0x08) |
   ((attr >> (bit3-1)) & 0x10) |
   ((K007121_ctrlram[0][0x03] & 0x01) << 5);
 int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
 bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code+bank*256) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (1)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info0(int tile_index)
{
 int attr = fastlane_videoram1[tile_index];
 int code = fastlane_videoram1[tile_index + 0x400];
 int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
 int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
 int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
 int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
 int bank = ((attr & 0x80) >> 7) |
   ((attr >> (bit0+2)) & 0x02) |
   ((attr >> (bit1+1)) & 0x04) |
   ((attr >> (bit2 )) & 0x08) |
   ((attr >> (bit3-1)) & 0x10) |
   ((K007121_ctrlram[0][0x03] & 0x01) << 5);
 int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
 bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code+bank*256) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (1)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

variable_types: code int

variable_types: bank int

variable_types: mask int


original_code:
static void get_tile_info1(int tile_index)
{
 int attr = fastlane_videoram2[tile_index];
 int code = fastlane_videoram2[tile_index + 0x400];
 int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
 int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
 int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
 int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
 int bank = ((attr & 0x80) >> 7) |
   ((attr >> (bit0+2)) & 0x02) |
   ((attr >> (bit1+1)) & 0x04) |
   ((attr >> (bit2 )) & 0x08) |
   ((attr >> (bit3-1)) & 0x10) |
   ((K007121_ctrlram[0][0x03] & 0x01) << 5);
 int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
 bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code+bank*256) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tile_info1(int tile_index)
{
 int attr = fastlane_videoram2[tile_index];
 int code = fastlane_videoram2[tile_index + 0x400];
 int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
 int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
 int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
 int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
 int bank = ((attr & 0x80) >> 7) |
   ((attr >> (bit0+2)) & 0x02) |
   ((attr >> (bit1+1)) & 0x04) |
   ((attr >> (bit2 )) & 0x08) |
   ((attr >> (bit3-1)) & 0x10) |
   ((K007121_ctrlram[0][0x03] & 0x01) << 5);
 int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
 bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (code+bank*256) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (0)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

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

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

variable_types: v int


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

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


SEGAPCMInit

decompiled_code:
__int64 __fastcall SEGAPCMInit(__int64 a1, int a2, int a3, __int64 a4, unsigned __int8 a5)
{
int v6; // er12
float v7; // xmm2_4
int v8; // edi
int v9; // eax
int v10; // esi
int v11; // eax
__int64 v12; // rax
int v13; // ebx
const char *v14; // rax
const char *v15; // rax
int v16; // eax
int v18[2]; // [rsp+0h] [rbp-90h] BYREF
__int64 v19[2]; // [rsp+8h] [rbp-88h] BYREF
char s[40]; // [rsp+18h] [rbp-78h] BYREF
char v21[80]; // [rsp+40h] [rbp-50h] BYREF

pcm_rom = a4;
v6 = *(_DWORD *)(Machine + 836LL);
v7 = *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL);
v8 = SEGAPCM_samples[2 * a3];
sample_shift = SEGAPCM_samples[2 * a3 + 1];
v9 = a2 & 0xFFFFFF;
v10 = a2 >> 16;
sample_rate = v8;
dword_19D0 = v9;
v11 = (unsigned __int8)v10;
if ( !v10 )
v11 = 112;
dword_19D4 = v11;
v12 = 0LL;
emulation_rate = (int)(float)((float)(int)(float)((float)v6 / v7) * v7);
do
{
byte_1821[v12] = 0;
byte_1821[v12 - 1] = 0;
dword_1890[v12 + 1] = 0;
dword_1890[v12] = 0;
*(_DWORD *)((char *)&unk_1990 + 2 * v12) = 1;
*(_DWORD *)((char *)&unk_1950 + 2 * v12) = (int)(float)((float)((float)v8
/ (float)(int)(float)((float)(int)(float)((float)v6 / v7)
* v7))
* 4096.0);
v12 += 2LL;
}
while ( v12 != 32 );
v13 = a5;
xmmword_1910 = 0LL;
xmmword_1920 = 0LL;
xmmword_1930 = 0LL;
xmmword_1940 = 0LL;
xmmword_19D8 = 0LL;
xmmword_19E8 = 0LL;
xmmword_19F8 = 0LL;
xmmword_1A08 = 0LL;
xmmword_1880 = (__int128)_mm_load_si128((const __m128i *)&LC3);
xmmword_1840 = 0LL;
xmmword_1850 = 0LL;
xmmword_1860 = 0LL;
xmmword_1870 = 0LL;
v19[0] = (__int64)s;
v19[1] = (__int64)v21;
v14 = (const char *)sound_name(a1);
sprintf(s, "%s L", v14);
v15 = (const char *)sound_name(a1);
sprintf(v21, "%s R", v15);
v16 = (unsigned __int8)v13;
BYTE1(v13) = 2;
BYTE1(v16) = 1;
v18[1] = v13;
v18[0] = v16;
stream_init_multi(2LL, v19, v18, (unsigned int)v6, 0LL, SEGAPCMUpdate);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3, __int64 a4, unsigned __int8 a5)
{
int v6; // er12
float v7; // xmm2_4
int v8; // edi
int v9; // eax
int v10; // esi
int v11; // eax
__int64 v12; // rax
int v13; // ebx
const char *v14; // rax
const char *v15; // rax
int v16; // eax
int v18[2]; // [rsp+0h] [rbp-90h] BYREF
__int64 v19[2]; // [rsp+8h] [rbp-88h] BYREF
char s[40]; // [rsp+18h] [rbp-78h] BYREF
char v21[80]; // [rsp+40h] [rbp-50h] BYREF

pcm_rom = a4;
v6 = *(_DWORD *)(Machine + 836LL);
v7 = *(float *)(*(_QWORD *)(Machine + 824LL) + 640LL);
v8 = SEGAPCM_samples[2 * a3];
sample_shift = SEGAPCM_samples[2 * a3 + 1];
v9 = a2 & 0xFFFFFF;
v10 = a2 >> 16;
sample_rate = v8;
dword_19D0 = v9;
v11 = (unsigned __int8)v10;
if ( !v10 )
v11 = 112;
dword_19D4 = v11;
v12 = 0LL;
emulation_rate = (int)(float)((float)(int)(float)((float)v6 / v7) * v7);
do
{
byte_1821[v12] = 0;
byte_1821[v12 - 1] = 0;
dword_1890[v12 + 1] = 0;
dword_1890[v12] = 0;
*(_DWORD *)((char *)&unk_1990 + 2 * v12) = 1;
*(_DWORD *)((char *)&unk_1950 + 2 * v12) = (int)(float)((float)((float)v8
/ (float)(int)(float)((float)(int)(float)((float)v6 / v7)
* v7))
* 4096.0);
v12 += 2LL;
}
while ( v12 != 32 );
v13 = a5;
xmmword_1910 = 0LL;
xmmword_1920 = 0LL;
xmmword_1930 = 0LL;
xmmword_1940 = 0LL;
xmmword_19D8 = 0LL;
xmmword_19E8 = 0LL;
xmmword_19F8 = 0LL;
xmmword_1A08 = 0LL;
xmmword_1880 = (__int128)_mm_load_si128((const __m128i *)&LC3);
xmmword_1840 = 0LL;
xmmword_1850 = 0LL;
xmmword_1860 = 0LL;
xmmword_1870 = 0LL;
v19[0] = (__int64)s;
v19[1] = (__int64)v21;
v14 = (const char *)sound_name(a1);
sprintf(s, "%s L", v14);
v15 = (const char *)sound_name(a1);
sprintf(v21, "%s R", v15);
v16 = (unsigned __int8)v13;
BYTE1(v13) = 2;
BYTE1(v16) = 1;
v18[1] = v13;
v18[0] = v16;
stream_init_multi(2LL, v19, v18, (unsigned int)v6, 0LL, SEGAPCMUpdate);
return 0LL;
}

original_code:
int SEGAPCMInit( const struct MachineSound *msound, int banksize, int mode, unsigned char *inpcm, int volume )
{
 int i;
 int rate = Machine->sample_rate;
 buffer_len = rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 sample_rate = SEGAPCM_samples[mode][0];
 sample_shift = SEGAPCM_samples[mode][1];
 pcm_rom = inpcm;
 spcm.bankshift = banksize&0xffffff;
 if( (banksize>>16) == 0x00 )
 {
  spcm.bankmask = ((0x70<<16)>>16)&0x00ff;
 }
 else
 {
  spcm.bankmask = (banksize>>16)&0x00ff;
 }
 for( i = 0; i < (16); i++ )
 {
  spcm.gain[i][L_PAN] = spcm.gain[i][R_PAN] = (unsigned char)0;
  spcm.vol[i][L_PAN] = spcm.vol[i][R_PAN] = 0;
  spcm.addr_l[i] = 0;
  spcm.addr_h[i] = 0;
  spcm.bank[i] = 0;
  spcm.end_h[i] = 0;
  spcm.delta_t[i] = 0x80;
  spcm.flag[i] = 1;
  spcm.add_addr[i] = 0;
  spcm.step[i] = (int)(((float)sample_rate / (float)emulation_rate) * (float)(0x80<<5));
  spcm.pcmd[i] = 0;
 }
 {
  char buf[LR_PAN][40];
  const char *name[LR_PAN];
  int vol[2];
  name[0] = buf[0];
  name[1] = buf[1];
  sprintf( buf[0], "%s L", sound_name(msound) );
  sprintf( buf[1], "%s R", sound_name(msound) );
  vol[0] = (1<<8) | (volume&0xff);
  vol[1] = (2<<8) | (volume&0xff);
  stream = stream_init_multi( LR_PAN, name, vol, rate, 0, SEGAPCMUpdate );
 }
 return 0;
}

canonical_original_code:
int SEGAPCMInit(struct MachineSound *msound, int banksize, int mode, unsigned char *inpcm, int volume)
{
 int i;
 int rate = Machine->sample_rate;
 buffer_len = rate / Machine->drv->frames_per_second;
 emulation_rate = buffer_len * Machine->drv->frames_per_second;
 sample_rate = SEGAPCM_samples[mode][0];
 sample_shift = SEGAPCM_samples[mode][1];
 pcm_rom = inpcm;
 spcm.bankshift = banksize&0xffffff;
 if( (banksize>>16) == 0x00 )
 {
  spcm.bankmask = ((0x70<<16)>>16)&0x00ff;
 }
 else
 {
  spcm.bankmask = (banksize>>16)&0x00ff;
 }
 for( i = 0; i < (16); i++ )
 {
  spcm.gain[i][L_PAN] = spcm.gain[i][R_PAN] = (unsigned char)0;
  spcm.vol[i][L_PAN] = spcm.vol[i][R_PAN] = 0;
  spcm.addr_l[i] = 0;
  spcm.addr_h[i] = 0;
  spcm.bank[i] = 0;
  spcm.end_h[i] = 0;
  spcm.delta_t[i] = 0x80;
  spcm.flag[i] = 1;
  spcm.add_addr[i] = 0;
  spcm.step[i] = (int)(((float)sample_rate / (float)emulation_rate) * (float)(0x80<<5));
  spcm.pcmd[i] = 0;
 }
 {
  char buf[-1][40];
  char *name[-1];
  int vol[2];
  name[0] = buf[0];
  name[1] = buf[1];
  sprintf( buf[0], "%s L", sound_name(msound) );
  sprintf( buf[1], "%s R", sound_name(msound) );
  vol[0] = (1<<8) | (volume&0xff);
  vol[1] = (2<<8) | (volume&0xff);
  stream = stream_init_multi( LR_PAN, name, vol, rate, 0, SEGAPCMUpdate );
 }
 return 0;
}

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

variable_types: banksize int

variable_types: mode int

variable_types:
inpcm
unsigned char *

variable_types: volume int

variable_types: rate int

variable_types:
name
char *[-1]

variable_types:
vol
int [2]


decompiled_code:
__int64 __fastcall SEGAPCM_sh_start(__int64 a1)
{
__int64 result; // rax
int *v2; // rbx
int v3; // er12
__int64 v4; // rax

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v2 = *(int **)(a1 + 8);
v3 = v2[3];
v4 = memory_region((unsigned int)v2[2]);
result = (unsigned int)SEGAPCMInit(a1, v2[1] & 0xFFFFFF, *v2, v4, v3) != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
int *v2; // rbx
int v3; // er12
__int64 v4; // rax

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
{
v2 = *(int **)(a1 + 8);
v3 = v2[3];
v4 = memory_region((unsigned int)v2[2]);
result = (unsigned int)func2(a1, v2[1] & 0xFFFFFF, *v2, v4, v3) != 0;
}
return result;
}

original_code:
int SEGAPCM_sh_start( const struct MachineSound *msound )
{
 struct SEGAPCMinterface *intf = (struct SEGAPCMinterface *)msound->sound_interface;
 if (Machine->sample_rate == 0) return 0;
 if( SEGAPCMInit( msound, intf->bank&0x00ffffff, intf->mode, (unsigned char *)memory_region(intf->region), intf->volume ) )
  return 1;
 return 0;
}

canonical_original_code:
int SEGAPCM_sh_start(struct MachineSound *msound)
{
 struct SEGAPCMinterface *intf = (struct SEGAPCMinterface *)msound->sound_interface;
 if (Machine->sample_rate == 0) return 0;
 if( SEGAPCMInit( msound, intf->bank&0x00ffffff, intf->mode, (unsigned char *)memory_region(intf->region), intf->volume ) )
  return 1;
 return 0;
}

variable_types: struct SEGAPCMinterface { int mode; int bank; int region; int volume; } *

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


SEGAPCMShutdown

decompiled_code:
void SEGAPCMShutdown()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void SEGAPCMShutdown( void )
{
}

canonical_original_code:
void SEGAPCMShutdown()
{
}


decompiled_code:
// attributes: thunk
void SEGAPCM_sh_stop()
{
SEGAPCMShutdown();
}

canonical_decompiled_code:
void func5()
{
func4();
}

original_code:
void SEGAPCM_sh_stop( void )
{
 SEGAPCMShutdown();
}


SEGAPCMResetChip

decompiled_code:
__int64 SEGAPCMResetChip()
{
__int64 result; // rax
int v1; // er10

result = 0LL;
v1 = (int)(float)((float)((float)sample_rate / (float)emulation_rate) * 4096.0);
do
{
byte_1821[result] = 0;
byte_1821[result - 1] = 0;
dword_1890[result + 1] = 0;
dword_1890[result - 3] = 0;
*(_DWORD *)((char *)&unk_1990 + 2 * result) = 1;
*(_DWORD *)((char *)&unk_1990 + 2 * result - 64) = v1;
result += 2LL;
}
while ( result != 32 );
xmmword_1840 = 0LL;
xmmword_1850 = 0LL;
xmmword_1860 = 0LL;
xmmword_1870 = 0LL;
xmmword_1880 = 0LL;
xmmword_1910 = 0LL;
xmmword_1920 = 0LL;
xmmword_1930 = 0LL;
xmmword_1940 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
int v1; // er10

result = 0LL;
v1 = (int)(float)((float)((float)sample_rate / (float)emulation_rate) * 4096.0);
do
{
byte_1821[result] = 0;
byte_1821[result - 1] = 0;
dword_1890[result + 1] = 0;
dword_1890[result - 3] = 0;
*(_DWORD *)((char *)&unk_1990 + 2 * result) = 1;
*(_DWORD *)((char *)&unk_1990 + 2 * result - 64) = v1;
result += 2LL;
}
while ( result != 32 );
xmmword_1840 = 0LL;
xmmword_1850 = 0LL;
xmmword_1860 = 0LL;
xmmword_1870 = 0LL;
xmmword_1880 = 0LL;
xmmword_1910 = 0LL;
xmmword_1920 = 0LL;
xmmword_1930 = 0LL;
xmmword_1940 = 0LL;
return result;
}

original_code:
void SEGAPCMResetChip( void )
{
 int i;
 for( i = 0; i < (16); i++ )
 {
  spcm.gain[i][L_PAN] = spcm.gain[i][R_PAN] = (unsigned char)0;
  spcm.vol[i][L_PAN] = spcm.vol[i][R_PAN] = 0;
  spcm.addr_l[i] = 0;
  spcm.addr_h[i] = 0;
  spcm.bank[i] = 0;
  spcm.end_h[i] = 0;
  spcm.delta_t[i] = 0;
  spcm.flag[i] = 1;
  spcm.add_addr[i] = 0;
  spcm.step[i] = (int)(((float)sample_rate / (float)emulation_rate) * (float)(0x80<<5));
 }
}

canonical_original_code:
void SEGAPCMResetChip()
{
 int i;
 for( i = 0; i < (16); i++ )
 {
  spcm.gain[i][L_PAN] = spcm.gain[i][R_PAN] = (unsigned char)0;
  spcm.vol[i][L_PAN] = spcm.vol[i][R_PAN] = 0;
  spcm.addr_l[i] = 0;
  spcm.addr_h[i] = 0;
  spcm.bank[i] = 0;
  spcm.end_h[i] = 0;
  spcm.delta_t[i] = 0;
  spcm.flag[i] = 1;
  spcm.add_addr[i] = 0;
  spcm.step[i] = (int)(((float)sample_rate / (float)emulation_rate) * (float)(0x80<<5));
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall SegaPCM_w(int a1, unsigned __int8 a2)
{
__int16 v3; // cx
int v4; // edi
__int64 result; // rax
char v6; // cl
float v7; // xmm1_4
int v8; // edi
int v9; // ecx
int v10; // esi

v3 = a1;
v4 = a1 & 0x87;
*((_BYTE *)&spcm + (v3 & 0x7FF)) = a2;
result = (a1 >> 3) & 0xF;
if ( v4 > 7 )
{
if ( v4 == 134 )
{
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4160) = a2;
if ( (a2 & 1) != 0 )
{
*((_DWORD *)&spcm + (int)result + 1116) = 1;
}
else
{
*((_DWORD *)&spcm + (int)result + 1116) = 2;
*((_DWORD *)&spcm + (int)result + 1134) = 0;
}
}
}
else if ( v4 > 1 )
{
switch ( v4 )
{
case 3:
result = (int)result;
v8 = a2;
*((_BYTE *)&spcm + 2 * (int)result + 4097) = a2;
v9 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4096);
goto LABEL_14;
case 4:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4128) = a2;
break;
case 5:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4144) = a2;
break;
case 6:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4176) = a2;
break;
case 7:
v6 = sample_shift;
result = (int)result;
v7 = (float)emulation_rate;
*((_BYTE *)&spcm + (int)result + 4192) = a2;
*((_DWORD *)&spcm + (int)result + 1100) = (int)(float)((float)((float)sample_rate / v7) * (float)(a2 << v6));
break;
default:
result = (int)result;
v9 = a2;
*((_BYTE *)&spcm + 2 * (int)result + 4096) = a2;
v8 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4097);
LABEL_14:
v10 = (v9 + v8) >> 2;
*((_DWORD *)&spcm + 2 * result + 1052) = 9 * (v10 + v9) / 5u;
*((_DWORD *)&spcm + 2 * result + 1053) = 9 * (v8 + v10) / 5u;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned __int8 a2)
{
__int16 v3; // cx
int v4; // edi
__int64 result; // rax
char v6; // cl
float v7; // xmm1_4
int v8; // edi
int v9; // ecx
int v10; // esi

v3 = a1;
v4 = a1 & 0x87;
*((_BYTE *)&spcm + (v3 & 0x7FF)) = a2;
result = (a1 >> 3) & 0xF;
if ( v4 > 7 )
{
if ( v4 == 134 )
{
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4160) = a2;
if ( (a2 & 1) != 0 )
{
*((_DWORD *)&spcm + (int)result + 1116) = 1;
}
else
{
*((_DWORD *)&spcm + (int)result + 1116) = 2;
*((_DWORD *)&spcm + (int)result + 1134) = 0;
}
}
}
else if ( v4 > 1 )
{
switch ( v4 )
{
case 3:
result = (int)result;
v8 = a2;
*((_BYTE *)&spcm + 2 * (int)result + 4097) = a2;
v9 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4096);
goto LABEL_14;
case 4:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4128) = a2;
break;
case 5:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4144) = a2;
break;
case 6:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4176) = a2;
break;
case 7:
v6 = sample_shift;
result = (int)result;
v7 = (float)emulation_rate;
*((_BYTE *)&spcm + (int)result + 4192) = a2;
*((_DWORD *)&spcm + (int)result + 1100) = (int)(float)((float)((float)sample_rate / v7) * (float)(a2 << v6));
break;
default:
result = (int)result;
v9 = a2;
*((_BYTE *)&spcm + 2 * (int)result + 4096) = a2;
v8 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4097);
LABEL_14:
v10 = (v9 + v8) >> 2;
*((_DWORD *)&spcm + 2 * result + 1052) = 9 * (v10 + v9) / 5u;
*((_DWORD *)&spcm + 2 * result + 1053) = 9 * (v8 + v10) / 5u;
break;
}
}
return result;
}

original_code:
void SegaPCM_w(offs_t offset,data_t data)
{
 int r = offset;
 int v = data;
 int rate;
 int lv, rv, cen;
 int channel = (r>>3)&0x0f;
 spcm.writeram[r&0x07ff] = (char)v;
 switch( (r&0x87) )
 {
  case 0x00:
  case 0x01:
  case 0x84: case 0x85:
  case 0x87:
   break;
  case 0x02:
   spcm.gain[channel][L_PAN] = v&0xff;
remake_vol:
   lv = spcm.gain[channel][L_PAN]; rv = spcm.gain[channel][R_PAN];
   cen = (lv + rv) / 4;
   spcm.vol[channel][L_PAN] = (lv + cen)*9/5;
   spcm.vol[channel][R_PAN] = (rv + cen)*9/5;
   break;
  case 0x03:
   spcm.gain[channel][R_PAN] = v&0xff;
   goto remake_vol;
  case 0x04:
   spcm.addr_l[channel]= v;
   break;
  case 0x05:
   spcm.addr_h[channel]= v;
   break;
  case 0x06:
   spcm.end_h[channel]= v;
   break;
  case 0x07:
   spcm.delta_t[channel]= v;
   rate = (v&0x00ff)<<sample_shift;
   spcm.step[channel] = (int)(((float)sample_rate / (float)emulation_rate) * (float)rate);
   break;
  case 0x86:
   spcm.bank[channel]= v;
   if( v&1 ) spcm.flag[channel] = 1;
   else
   {
    spcm.flag[channel] = 2;
    spcm.pcmd[channel] = 0;
   }
   break;
 }
}

canonical_original_code:
void SegaPCM_w(unsigned int offset, unsigned int data)
{
 int r = offset;
 int v = data;
 int rate;
 int lv; int rv; int cen;
 int channel = (r>>3)&0x0f;
 spcm.writeram[r&0x07ff] = (char)v;
 switch( (r&0x87) )
 {
  case 0x00:
  case 0x01:
  case 0x84: case 0x85:
  case 0x87:
   break;
  case 0x02:
   spcm.gain[channel][L_PAN] = v&0xff;
remake_vol:
   lv = spcm.gain[channel][L_PAN]; rv = spcm.gain[channel][R_PAN];
   cen = (lv + rv) / 4;
   spcm.vol[channel][L_PAN] = (lv + cen)*9/5;
   spcm.vol[channel][R_PAN] = (rv + cen)*9/5;
   break;
  case 0x03:
   spcm.gain[channel][R_PAN] = v&0xff;
   goto remake_vol;
  case 0x04:
   spcm.addr_l[channel]= v;
   break;
  case 0x05:
   spcm.addr_h[channel]= v;
   break;
  case 0x06:
   spcm.end_h[channel]= v;
   break;
  case 0x07:
   spcm.delta_t[channel]= v;
   rate = (v&0x00ff)<<sample_shift;
   spcm.step[channel] = (int)(((float)sample_rate / (float)emulation_rate) * (float)rate);
   break;
  case 0x86:
   spcm.bank[channel]= v;
   if( v&1 ) spcm.flag[channel] = 1;
   else
   {
    spcm.flag[channel] = 2;
    spcm.pcmd[channel] = 0;
   }
   break;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

variable_types: r int

variable_types: lv int

variable_types: rv int

variable_types: cen int

variable_types: channel int


decompiled_code:
__int64 __fastcall SegaPCM_r(__int16 a1)
{
return (unsigned int)spcm[a1 & 0x7FF];
}

canonical_decompiled_code:
__int64 __fastcall func8(__int16 a1)
{
return (unsigned int)spcm[a1 & 0x7FF];
}

original_code:
data_t SegaPCM_r(offs_t offset)
{
 return spcm.writeram[offset & 0x07ff];
}

canonical_original_code:
unsigned int SegaPCM_r(unsigned int offset)
{
 return spcm.writeram[offset & 0x07ff];
}


decompiled_code:
void __fastcall ramtek_mask_w(__int64 a1, char a2)
{
mask = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, char a2)
{
mask = a2;
}

original_code:
void ramtek_mask_w(offs_t offset,data_t data)
{
 mask = data;
}

canonical_original_code:
void ramtek_mask_w(unsigned int offset, unsigned int data)
{
 mask = data;
}


decompiled_code:
__int64 M79_interrupt()
{
return 207LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 207LL;
}

original_code:
static int M79_interrupt(void)
{
 return 0x00cf;
}

canonical_original_code:
static int M79_interrupt()
{
 return 0x00cf;
}


decompiled_code:
_BYTE *init_m79amb()
{
_BYTE *result; // rax
_BYTE *v1; // rdx

result = (_BYTE *)memory_region(129LL);
v1 = result + 0x2000;
do
{
*result = ~*result;
++result;
}
while ( result != v1 );
return result;
}

canonical_decompiled_code:
_BYTE *func4()
{
_BYTE *result; // rax
_BYTE *v1; // rdx

result = (_BYTE *)memory_region(129LL);
v1 = result + 0x2000;
do
{
*result = ~*result;
++result;
}
while ( result != v1 );
return result;
}

original_code:
static void init_m79amb(void)
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
  for (i = 0;i < 0x2000;i++)
  rom[i] = ~rom[i];
}

canonical_original_code:
static void init_m79amb()
{
 unsigned char *rom = memory_region(REGION_CPU1);
 int i;
  for (i = 0;i < 0x2000;i++)
  rom[i] = ~rom[i];
}

variable_types:
rom
unsigned char *


decompiled_code:
__int64 gray5bit_controller1_r()
{
char v0; // bl

v0 = input_port_3_r(0LL);
return v0 & 0xE0 | ~(unsigned __int8)ControllerTable[input_port_3_r(0LL) & 0x1F] & 0x1Fu;
}

canonical_decompiled_code:
__int64 func5()
{
char v0; // bl

v0 = input_port_3_r(0LL);
return v0 & 0xE0 | ~(unsigned __int8)ControllerTable[input_port_3_r(0LL) & 0x1F] & 0x1Fu;
}

original_code:
static data_t gray5bit_controller1_r(offs_t offset)
{
    return (input_port_3_r(0) & 0xe0) | (~ControllerTable[input_port_3_r(0) & 0x1f] & 0x1f);
}

canonical_original_code:
static unsigned int gray5bit_controller1_r(unsigned int offset)
{
    return (input_port_3_r(0) & 0xe0) | (~ControllerTable[input_port_3_r(0) & 0x1f] & 0x1f);
}


decompiled_code:
__int64 gray5bit_controller0_r()
{
char v0; // bl

v0 = input_port_2_r(0LL);
return v0 & 0xE0 | ~(unsigned __int8)ControllerTable[input_port_2_r(0LL) & 0x1F] & 0x1Fu;
}

canonical_decompiled_code:
__int64 func6()
{
char v0; // bl

v0 = input_port_2_r(0LL);
return v0 & 0xE0 | ~(unsigned __int8)ControllerTable[input_port_2_r(0LL) & 0x1F] & 0x1Fu;
}

original_code:
static data_t gray5bit_controller0_r(offs_t offset)
{
    return (input_port_2_r(0) & 0xe0) | (~ControllerTable[input_port_2_r(0) & 0x1f] & 0x1f);
}

canonical_original_code:
static unsigned int gray5bit_controller0_r(unsigned int offset)
{
    return (input_port_2_r(0) & 0xe0) | (~ControllerTable[input_port_2_r(0) & 0x1f] & 0x1f);
}


decompiled_code:
void sound_w()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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


original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
}


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

layer_colorbase = 0LL;
dword_570 = 16;
v0 = 1;
sprite_colorbase = 32;
zoom_colorbase = 48;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
return v0;
if ( !(unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
K051960_vh_stop();
}
return v0;
}
K052109_vh_stop();
return 1LL;
}

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

layer_colorbase = 0LL;
dword_570 = 16;
v0 = 1;
sprite_colorbase = 32;
zoom_colorbase = 48;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
return v0;
if ( !(unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(139LL, 4LL, zoom_callback);
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
K051960_vh_stop();
}
return v0;
}
K052109_vh_stop();
return 1LL;
}

original_code:
int bottom9_vh_start(void)
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 zoom_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int bottom9_vh_start()
{
 layer_colorbase[0] = 0;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 16;
 sprite_colorbase = 32;
 zoom_colorbase = 48;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
 {
  return 1;
 }
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,4,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall bottom9_vh_screenrefresh(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 v3; // rdx

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
if ( palette_recalc(a1, v2, v3, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * SHIDWORD(layer_colorbase)), Machine + 776LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K051316_zoom_draw_0(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 2LL, 3LL);
return K052109_tilemap_draw(a1, 1LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rsi
__int64 v3; // rdx

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = 16 * zoom_colorbase;
v2 = v1 + 256;
do
{
v3 = palette_used_colors;
*(_BYTE *)(palette_used_colors + v1) = 7;
v1 += 16LL;
}
while ( v1 != v2 );
if ( palette_recalc(a1, v2, v3, &palette_used_colors) )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * SHIDWORD(layer_colorbase)), Machine + 776LL);
K051960_sprites_draw(a1, 1LL, 1LL);
K051316_zoom_draw_0(a1, 0LL);
K051960_sprites_draw(a1, 0LL, 0LL);
K052109_tilemap_draw(a1, 2LL, 0LL);
K051960_sprites_draw(a1, 2LL, 3LL);
return K052109_tilemap_draw(a1, 1LL, 0LL);
}

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

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

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


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

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

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

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


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

if ( nmienable )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( nmienable )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int bottom9_sound_interrupt(void)
{
 if (nmienable) return nmi_interrupt();
 else return ignore_interrupt();
}

canonical_original_code:
static int bottom9_sound_interrupt()
{
 if (nmienable) return nmi_interrupt();
 else return ignore_interrupt();
}


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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K052109_is_IRQ_enabled() )
result = interrupt();
else
result = ignore_interrupt();
return result;
}

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

canonical_original_code:
static int bottom9_interrupt()
{
 if (K052109_is_IRQ_enabled()) return interrupt();
 else return ignore_interrupt();
}


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

if ( K052109_selected )
result = K052109_051960_w((unsigned int)(a1 + 0x2000));
else
result = paletteram_xBBBBBGGGGGRRRRR_swap_w();
return result;
}

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

if ( K052109_selected )
result = K052109_051960_w((unsigned int)(a1 + 0x2000));
else
result = paletteram_xBBBBBGGGGGRRRRR_swap_w();
return result;
}

original_code:
static void bottom9_bankedram2_w(offs_t offset,data_t data)
{
 if (K052109_selected) K052109_051960_w(offset + 0x2000,data);
 else paletteram_xBBBBBGGGGGRRRRR_swap_w(offset,data);
}

canonical_original_code:
static void bottom9_bankedram2_w(unsigned int offset, unsigned int data)
{
 if (K052109_selected) K052109_051960_w(offset + 0x2000,data);
 else paletteram_xBBBBBGGGGGRRRRR_swap_w(offset,data);
}


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

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

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

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


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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
K052109_set_RMRD_line((a2 >> 2) & 1);
bottom9_video_enable = ~(_BYTE)a2 & 8;
result = a2 & 0x10;
K052109_selected = a2 & 0x20;
zoomreadroms = a2 & 0x10;
return result;
}

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

coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
K052109_set_RMRD_line((a2 >> 2) & 1);
bottom9_video_enable = ~(_BYTE)a2 & 8;
result = a2 & 0x10;
K052109_selected = a2 & 0x20;
zoomreadroms = a2 & 0x10;
return result;
}

original_code:
static void bottom9_1f90_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x04) ? 1 : 0);
 bottom9_video_enable = ~data & 0x08;
 zoomreadroms = data & 0x10;
 K052109_selected = data & 0x20;
}

canonical_original_code:
static void bottom9_1f90_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x04) ? 1 : 0);
 bottom9_video_enable = ~data & 0x08;
 zoomreadroms = data & 0x10;
 K052109_selected = data & 0x20;
}