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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

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

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

screen0 = tilemap_create(get_tile_info_screen0, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v4) = 32;
screen1 = tilemap_create(get_tile_info_screen1, &tilemap_scan_rows, 1LL, 16LL, 16LL, 32LL, v4);
v0 = bitmap_alloc(512LL, 256LL);
screen2 = v0;
v1 = screen0;
if ( !screen0 )
return 1LL;
v2 = screen1;
if ( !v0 || !screen1 )
return 1LL;
*(_DWORD *)(screen0 + 132) = 0;
*(_DWORD *)(v2 + 132) = 0;
tilemap_set_scrollx(v1, 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;
}

return_type: int


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

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


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

variable_types: data int


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; // r13
__int64 i; // rbx
unsigned __int16 v3; // ax
char v4; // cl
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // r13
__int64 i; // rbx
unsigned __int16 v3; // ax
char v4; // cl
__int64 result; // rax

v1 = *(_QWORD *)(Machine + 520LL);
for ( i = 4LL; i != 2052; i += 8LL )
{
v3 = *(unsigned __int8 *)(splash_spriteram + i);
v4 = *(_BYTE *)(splash_spriteram + i + 2045);
if ( v4 < 0 )
v3 += 256;
result = drawgfx(
a1,
v1,
*(unsigned __int8 *)(splash_spriteram + i - 4)
+ ((unsigned __int8)(*(_WORD *)(splash_spriteram + i + 2) & 0xF) << 8),
(v4 & 0xFu) + 16,
*(_WORD *)(splash_spriteram + i + 2) & 0x40,
(unsigned __int8)*(_WORD *)(splash_spriteram + i + 2) & 0x80,
(unsigned int)v3 - 8,
240 - (unsigned int)*(unsigned __int8 *)(splash_spriteram + i - 2),
Machine + 776LL,
2LL,
0LL);
}
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: i 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; } *

variable_types: sx int

variable_types: sy int

variable_types: attr int

variable_types: number int

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


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

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

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

layer0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v1) = 32;
layer1 = tilemap_create(get_tile_info1, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, v1);
tilemap_set_scroll_rows(layer0, 32LL);
if ( !layer0 )
return 1LL;
result = 1LL;
if ( layer1 )
{
v2 = _mm_loadu_si128((const __m128i *)(Machine + 776LL));
v2.m128i_i32[0] += 40;
tilemap_set_clip(layer0, &v2);
v2.m128i_i64[0] = 0x2700000000LL;
tilemap_set_clip(layer1, &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

v1 = K007121_ctrlram[0];
for ( i = 0LL; i != 32; ++i )
tilemap_set_scrollx(
layer0,
(unsigned int)i,
v1 + (unsigned int)*(unsigned __int8 *)(fastlane_k007121_regs + i + 32) - 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

v1 = K007121_ctrlram[0];
for ( i = 0LL; i != 32; ++i )
tilemap_set_scrollx(
layer0,
(unsigned int)i,
v1 + (unsigned int)*(unsigned __int8 *)(fastlane_k007121_regs + i + 32) - 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: 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 nmi_interrupt();
}
else
{
result = 1LL;
if ( (K007121_ctrlram[7] & 2) != 0 )
return result;
}
return ignore_interrupt();
}

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

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

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


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 + (int)((((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 + (int)((((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);
}

return_type: unsigned int


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

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


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


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

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 func4(__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)func3(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 func5()
{
;
}

original_code:
void SEGAPCMShutdown( void )
{
}

canonical_original_code:
void SEGAPCMShutdown()
{
}


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

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

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


SEGAPCMResetChip

decompiled_code:
char *SEGAPCMResetChip()
{
int v0; // edi
void *v1; // rdx
char *result; // rax
__int64 v3; // rcx

v0 = (int)(float)((float)((float)sample_rate / (float)emulation_rate) * 4096.0);
v1 = &unk_17C0;
result = (char *)&unk_17C0 + 32;
v3 = -3LL * ((_QWORD)&unk_17C0 - 4096);
do
{
*((_BYTE *)v1 + 1) = 0;
*(_BYTE *)v1 = 0;
*(_DWORD *)(v3 + 4LL * (_QWORD)v1 - 12172) = 0;
*(_DWORD *)(v3 + 4LL * (_QWORD)v1 - 12176) = 0;
*result = 0;
result[16] = 0;
result[32] = 0;
result[48] = 0;
result[64] = 0;
*(_DWORD *)(v3 + 4LL * (_QWORD)result - 12048) = 1;
*(_DWORD *)(v3 + 4LL * (_QWORD)result - 12176) = 0;
*(_DWORD *)(v3 + 4LL * (_QWORD)result - 12112) = v0;
v1 = (char *)v1 + 2;
++result;
}
while ( v1 != (char *)&unk_17C0 + 32 );
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)
{
__int64 result; // rax
int v3; // edi
int v4; // esi
int v5; // ecx
int v6; // er8

result = (a1 >> 3) & 0xF;
*((_BYTE *)&spcm + (a1 & 0x7FF)) = a2;
v3 = a1 & 0x87;
if ( v3 > 7 )
{
if ( v3 == 134 )
{
*((_BYTE *)&spcm + (int)result + 4160) = a2;
if ( (a2 & 1) != 0 )
{
*((_DWORD *)&spcm + (int)result + 1116) = 1;
}
else
{
result = (int)result;
*((_DWORD *)&spcm + (int)result + 1116) = 2;
*((_DWORD *)&spcm + (int)result + 1134) = 0;
}
}
}
else if ( v3 > 1 )
{
switch ( v3 )
{
case 2:
*((_BYTE *)&spcm + 2 * (int)result + 4096) = a2;
goto LABEL_9;
case 3:
*((_BYTE *)&spcm + 2 * (int)result + 4097) = a2;
LABEL_9:
result = (int)result;
v4 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4096);
v5 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4097);
v6 = (v4 + v5) >> 2;
*((_DWORD *)&spcm + 2 * (int)result + 1052) = (int)((unsigned __int64)(15461882271LL * (v6 + v4)) >> 32) >> 1;
*((_DWORD *)&spcm + 2 * (int)result + 1053) = (int)((unsigned __int64)(15461882271LL * (v5 + v6)) >> 32) >> 1;
break;
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:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4192) = a2;
*((_DWORD *)&spcm + (int)result + 1100) = (int)(float)((float)((float)sample_rate / (float)emulation_rate)
* (float)(a2 << sample_shift));
break;
default:
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned __int8 a2)
{
__int64 result; // rax
int v3; // edi
int v4; // esi
int v5; // ecx
int v6; // er8

result = (a1 >> 3) & 0xF;
*((_BYTE *)&spcm + (a1 & 0x7FF)) = a2;
v3 = a1 & 0x87;
if ( v3 > 7 )
{
if ( v3 == 134 )
{
*((_BYTE *)&spcm + (int)result + 4160) = a2;
if ( (a2 & 1) != 0 )
{
*((_DWORD *)&spcm + (int)result + 1116) = 1;
}
else
{
result = (int)result;
*((_DWORD *)&spcm + (int)result + 1116) = 2;
*((_DWORD *)&spcm + (int)result + 1134) = 0;
}
}
}
else if ( v3 > 1 )
{
switch ( v3 )
{
case 2:
*((_BYTE *)&spcm + 2 * (int)result + 4096) = a2;
goto LABEL_9;
case 3:
*((_BYTE *)&spcm + 2 * (int)result + 4097) = a2;
LABEL_9:
result = (int)result;
v4 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4096);
v5 = *((unsigned __int8 *)&spcm + 2 * (int)result + 4097);
v6 = (v4 + v5) >> 2;
*((_DWORD *)&spcm + 2 * (int)result + 1052) = (int)((unsigned __int64)(15461882271LL * (v6 + v4)) >> 32) >> 1;
*((_DWORD *)&spcm + 2 * (int)result + 1053) = (int)((unsigned __int64)(15461882271LL * (v5 + v6)) >> 32) >> 1;
break;
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:
result = (int)result;
*((_BYTE *)&spcm + (int)result + 4192) = a2;
*((_DWORD *)&spcm + (int)result + 1100) = (int)(float)((float)((float)sample_rate / (float)emulation_rate)
* (float)(a2 << sample_shift));
break;
default:
return result;
}
}
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 func9(__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()
{
int v0; // edx
__int64 result; // rax

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

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

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

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 * dword_52C), 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 * dword_52C), 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;
zoomreadroms = a2 & 0x10;
K052109_selected = a2 & 0x20;
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;
zoomreadroms = a2 & 0x10;
K052109_selected = a2 & 0x20;
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;
}


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

if ( K052109_selected )
result = K052109_051960_w(a1);
else
result = K051316_0_w();
return result;
}

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

if ( K052109_selected )
result = K052109_051960_w(a1);
else
result = K051316_0_w();
return result;
}

original_code:
static void bottom9_bankedram1_w(offs_t offset,data_t data)
{
 if (K052109_selected) K052109_051960_w(offset,data);
 else K051316_0_w(offset,data);
}

canonical_original_code:
static void bottom9_bankedram1_w(unsigned int offset, unsigned int data)
{
 if (K052109_selected) K052109_051960_w(offset,data);
 else K051316_0_w(offset,data);
}


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

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

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

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

original_code:
static data_t bottom9_bankedram2_r(offs_t offset)
{
 if (K052109_selected) return K052109_051960_r(offset + 0x2000);
 else return paletteram_r(offset);
}

canonical_original_code:
static unsigned int bottom9_bankedram2_r(unsigned int offset)
{
 if (K052109_selected) return K052109_051960_r(offset + 0x2000);
 else return paletteram_r(offset);
}


decompiled_code:
__int64 __fastcall bottom9_bankedram1_r(__int64 a1)
{
if ( K052109_selected )
return K052109_051960_r(a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
if ( K052109_selected )
return K052109_051960_r(a1);
if ( zoomreadroms )
return K051316_rom_0_r();
return K051316_0_r();
}

original_code:
static data_t bottom9_bankedram1_r(offs_t offset)
{
 if (K052109_selected)
  return K052109_051960_r(offset);
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}

canonical_original_code:
static unsigned int bottom9_bankedram1_r(unsigned int offset)
{
 if (K052109_selected)
  return K052109_051960_r(offset);
 else
 {
  if (zoomreadroms)
   return K051316_rom_0_r(offset);
  else
   return K051316_0_r(offset);
 }
}


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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x3F00;
result = layer_colorbase[a1] + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x3F00;
result = layer_colorbase[a1] + ((*a4 >> 6) & 3u);
*a4 = result;
return result;
}

original_code:
static void tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= (*color & 0x3f) << 8;
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

canonical_original_code:
static void tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= (*color & 0x3f) << 8;
 *color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
}

variable_types: layer int

variable_types: bank int

variable_types:
code
int *

variable_types:
color
int *


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

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

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

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

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

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

variable_types:
priority
int *

variable_types:
shadow
int *


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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = zoom_colorbase + ((*a2 >> 2) & 0xFu);
*a2 = result;
return result;
}

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

tile_info[5] = (*a2 >> 6) & 1;
*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = zoom_colorbase + ((*a2 >> 2) & 0xFu);
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x03) << 8);
 *color = zoom_colorbase + ((*color & 0x3c) >> 2);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 tile_info.flags = (*color & 0x40) ? 0x01 : 0;
 *code |= ((*color & 0x03) << 8);
 *color = zoom_colorbase + ((*color & 0x3c) >> 2);
}


decompiled_code:
void __fastcall nmi_enable_w(__int64 a1, int a2)
{
nmienable = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
nmienable = a2;
}

original_code:
static void nmi_enable_w(offs_t offset,data_t data)
{
 nmienable = data;
}

canonical_original_code:
static void nmi_enable_w(unsigned int offset, unsigned int data)
{
 nmienable = data;
}


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


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

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

variable_types:
RAM
unsigned char *


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types: offs int


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

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

original_code:
data_t bublbobl_sharedram1_r(offs_t offset)
{
 return bublbobl_sharedram1[offset];
}

canonical_original_code:
unsigned int bublbobl_sharedram1_r(unsigned int offset)
{
 return bublbobl_sharedram1[offset];
}


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

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

original_code:
data_t bublbobl_sharedram2_r(offs_t offset)
{
 return bublbobl_sharedram2[offset];
}

canonical_original_code:
unsigned int bublbobl_sharedram2_r(unsigned int offset)
{
 return bublbobl_sharedram2[offset];
}


decompiled_code:
__int64 tokio_fake_r()
{
return 191LL;
}

canonical_decompiled_code:
__int64 func4()
{
return 191LL;
}

original_code:
data_t tokio_fake_r(offs_t offset)
{
  return 0xbf;
}

canonical_original_code:
unsigned int tokio_fake_r(unsigned int offset)
{
  return 0xbf;
}


decompiled_code:
void bublbobl_sh_nmi_disable_w()
{
sound_nmi_enable = 0;
}

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

original_code:
void bublbobl_sh_nmi_disable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 0;
}

canonical_original_code:
void bublbobl_sh_nmi_disable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 0;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 bublbobl_68705_portA_r()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

canonical_decompiled_code:
__int64 func6()
{
return ~(unsigned __int8)ddrA & (unsigned __int8)portA_in | (unsigned int)(unsigned __int8)(portA_out & ddrA);
}

original_code:
data_t bublbobl_68705_portA_r(offs_t offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}

canonical_original_code:
unsigned int bublbobl_68705_portA_r(unsigned int offset)
{
 return (portA_out & ddrA) | (portA_in & ~ddrA);
}


decompiled_code:
void __fastcall bublbobl_68705_portA_w(__int64 a1, char a2)
{
portA_out = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, char a2)
{
portA_out = a2;
}

original_code:
void bublbobl_68705_portA_w(offs_t offset,data_t data)
{
 portA_out = data;
}

canonical_original_code:
void bublbobl_68705_portA_w(unsigned int offset, unsigned int data)
{
 portA_out = data;
}


decompiled_code:
void __fastcall bublbobl_68705_ddrA_w(__int64 a1, char a2)
{
ddrA = a2;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2)
{
ddrA = a2;
}

original_code:
void bublbobl_68705_ddrA_w(offs_t offset,data_t data)
{
 ddrA = data;
}

canonical_original_code:
void bublbobl_68705_ddrA_w(unsigned int offset, unsigned int data)
{
 ddrA = data;
}


decompiled_code:
__int64 bublbobl_68705_portB_r()
{
return (unsigned __int8)(ddrB & portB_out);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)(ddrB & portB_out);
}

original_code:
data_t bublbobl_68705_portB_r(offs_t offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}

canonical_original_code:
unsigned int bublbobl_68705_portB_r(unsigned int offset)
{
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}


decompiled_code:
void __fastcall bublbobl_68705_ddrB_w(__int64 a1, char a2)
{
ddrB = a2;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, char a2)
{
ddrB = a2;
}

original_code:
void bublbobl_68705_ddrB_w(offs_t offset,data_t data)
{
 ddrB = data;
}

canonical_original_code:
void bublbobl_68705_ddrB_w(unsigned int offset, unsigned int data)
{
 ddrB = data;
}


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

result = *(_QWORD *)(Machine + 824LL);
if ( *(_DWORD *)(result + 700) )
{
result = 0LL;
do
{
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
++result;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 700LL) > (unsigned int)result );
}
return result;
}

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

result = *(_QWORD *)(Machine + 824LL);
if ( *(_DWORD *)(result + 700) )
{
result = 0LL;
do
{
*(_WORD *)(a2 + 2 * result) = result ^ 0xF;
++result;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 700LL) > (unsigned int)result );
}
return result;
}

original_code:
void bublbobl_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->color_table_len;i++)
  colortable[i] = i ^ 0x0f;
}

canonical_original_code:
void bublbobl_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->color_table_len;i++)
  colortable[i] = i ^ 0x0f;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

result = bublbobl_video_enable;
bublbobl_video_enable[0] = 1;
return result;
}

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

result = bublbobl_video_enable;
bublbobl_video_enable[0] = 1;
return result;
}

original_code:
static void init_tokio(void)
{
 extern int bublbobl_video_enable;
 bublbobl_video_enable = 1;
}

canonical_original_code:
static void init_tokio()
{
 extern int bublbobl_video_enable;
 bublbobl_video_enable = 1;
}


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

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

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

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

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

canonical_original_code:
void tokio_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&ROM[0x10000 + 0x4000 * (data & 7)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
ROM
unsigned char *


decompiled_code:
__int64 __fastcall bublbobl_bankswitch_w(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + ((((a2 ^ 4) & 7u) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
bublbobl_video_enable[0] = a2 & 0x40;
return flip_screen_w(0LL, a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 a2)
{
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + ((((a2 ^ 4) & 7u) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
bublbobl_video_enable[0] = a2 & 0x40;
return flip_screen_w(0LL, a2 & 0x80);
}

original_code:
void bublbobl_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&ROM[0x10000 + 0x4000 * ((data ^ 4) & 7)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 bublbobl_video_enable = data & 0x40;
 flip_screen_w(0,data & 0x80);
}

canonical_original_code:
void bublbobl_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&ROM[0x10000 + 0x4000 * ((data ^ 4) & 7)]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 bublbobl_video_enable = data & 0x40;
 flip_screen_w(0,data & 0x80);
}


decompiled_code:
__int64 __fastcall tokio_videoctrl_w(__int64 a1, unsigned __int8 a2)
{
return flip_screen_w(0LL, a2 & 0x80);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 a2)
{
return flip_screen_w(0LL, a2 & 0x80);
}

original_code:
void tokio_videoctrl_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 0x80);
}

canonical_original_code:
void tokio_videoctrl_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 0x80);
}


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

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

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

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


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

sound_nmi_enable = 1;
if ( pending_nmi )
{
result = cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

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

sound_nmi_enable = 1;
if ( pending_nmi )
{
result = cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 0;
}
return result;
}

original_code:
void bublbobl_sh_nmi_enable_w(offs_t offset,data_t data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(2,-2);
  pending_nmi = 0;
 }
}

canonical_original_code:
void bublbobl_sh_nmi_enable_w(unsigned int offset, unsigned int data)
{
 sound_nmi_enable = 1;
 if (pending_nmi)
 {
  cpu_cause_interrupt(2,-2);
  pending_nmi = 0;
 }
}


decompiled_code:
__int64 __fastcall bublbobl_sound_command_w(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2)
{
soundlatch_w();
return timer_set(0LL, a2, nmi_callback);
}

original_code:
void bublbobl_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}

canonical_original_code:
void bublbobl_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w(offset,data);
 timer_set((0),data,nmi_callback);
}


decompiled_code:
__int64 bublbobl_m68705_interrupt()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(3LL, 0LL, 0LL);
else
cpu_set_irq_line(3LL, 0LL, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func20()
{
if ( (cpu_getiloops() & 1) != 0 )
cpu_set_irq_line(3LL, 0LL, 0LL);
else
cpu_set_irq_line(3LL, 0LL, 1LL);
return 0LL;
}

original_code:
int bublbobl_m68705_interrupt(void)
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(3,0,0);
 else
  cpu_set_irq_line(3,0,1);
    return 0;
}

canonical_original_code:
int bublbobl_m68705_interrupt()
{
 if (cpu_getiloops() & 1)
  cpu_set_irq_line(3,0,0);
 else
  cpu_set_irq_line(3,0,1);
    return 0;
}


decompiled_code:
__int64 __fastcall bublbobl_68705_portB_w(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // eax
unsigned __int8 *v4; // rcx

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out | address & 0xFF00;
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
address = (unsigned __int8)address | ((unsigned __int8)portA_out << 8) & 0xF00;
if ( (ddrB & 0x10) != 0 && (a2 & 0x10) == 0 && (portB_out & 0x10) != 0 )
{
if ( (a2 & 8) != 0 )
{
if ( (address & 0x800) != 0 )
{
result = address & 0xC00;
if ( (_DWORD)result == 3072 )
{
result = *(unsigned __int8 *)(bublbobl_sharedram2 + (address & 0x3FF));
latch = *(unsigned __int8 *)(bublbobl_sharedram2 + (address & 0x3FF));
}
}
else
{
result = readinputport((address & 3u) + 1);
latch = result;
}
}
else
{
result = (unsigned int)address;
if ( (address & 0xC00) == 3072 )
{
result = address & 0x3FF;
*(_BYTE *)(bublbobl_sharedram2 + result) = portA_out;
}
}
}
if ( (ddrB & 0x20) != 0 && (a2 & 0x20) == 0 && (portB_out & 0x20) != 0 )
{
v3 = rand();
v4 = (unsigned __int8 *)bublbobl_sharedram2;
*(_BYTE *)(bublbobl_sharedram2 + 124LL) = v3 % 6;
cpu_irq_line_vector_w(0LL, 0LL, *v4);
result = cpu_set_irq_line(0LL, 0LL, 2LL);
}
portB_out = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, char a2)
{
__int64 result; // rax
int v3; // eax
unsigned __int8 *v4; // rcx

result = (unsigned __int8)ddrB;
if ( (ddrB & 1) != 0 && (a2 & 1) == 0 && (portB_out & 1) != 0 )
portA_in = latch;
if ( (ddrB & 2) != 0 && (a2 & 2) != 0 && (portB_out & 2) == 0 )
address = (unsigned __int8)portA_out | address & 0xFF00;
if ( (ddrB & 4) != 0 && (a2 & 4) != 0 && (portB_out & 4) == 0 )
address = (unsigned __int8)address | ((unsigned __int8)portA_out << 8) & 0xF00;
if ( (ddrB & 0x10) != 0 && (a2 & 0x10) == 0 && (portB_out & 0x10) != 0 )
{
if ( (a2 & 8) != 0 )
{
if ( (address & 0x800) != 0 )
{
result = address & 0xC00;
if ( (_DWORD)result == 3072 )
{
result = *(unsigned __int8 *)(bublbobl_sharedram2 + (address & 0x3FF));
latch = *(unsigned __int8 *)(bublbobl_sharedram2 + (address & 0x3FF));
}
}
else
{
result = readinputport((address & 3u) + 1);
latch = result;
}
}
else
{
result = (unsigned int)address;
if ( (address & 0xC00) == 3072 )
{
result = address & 0x3FF;
*(_BYTE *)(bublbobl_sharedram2 + result) = portA_out;
}
}
}
if ( (ddrB & 0x20) != 0 && (a2 & 0x20) == 0 && (portB_out & 0x20) != 0 )
{
v3 = rand();
v4 = (unsigned __int8 *)bublbobl_sharedram2;
*(_BYTE *)(bublbobl_sharedram2 + 124LL) = v3 % 6;
cpu_irq_line_vector_w(0LL, 0LL, *v4);
result = cpu_set_irq_line(0LL, 0LL, 2LL);
}
portB_out = a2;
return result;
}

original_code:
void bublbobl_68705_portB_w(offs_t offset,data_t data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = (address & 0xff00) | portA_out;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  address = (address & 0x00ff) | ((portA_out & 0x0f) << 8);
 }
 if ((ddrB & 0x10) && (~data & 0x10) && (portB_out & 0x10))
 {
  if (data & 0x08)
  {
   if ((address & 0x0800) == 0x0000)
   {
    latch = readinputport((address & 3) + 1);
   }
   else if ((address & 0x0c00) == 0x0c00)
   {
    latch = bublbobl_sharedram2[address & 0x03ff];
   }
  }
  else
  {
   if ((address & 0x0c00) == 0x0c00)
   {
    bublbobl_sharedram2[address & 0x03ff] = portA_out;
   }
  }
 }
 if ((ddrB & 0x20) && (~data & 0x20) && (portB_out & 0x20))
 {
  bublbobl_sharedram2[0x7c] = rand()%6;
  cpu_irq_line_vector_w(0,0,bublbobl_sharedram2[0]);
  cpu_set_irq_line(0,0,2);
 }
 portB_out = data;
}

canonical_original_code:
void bublbobl_68705_portB_w(unsigned int offset, unsigned int data)
{
 if ((ddrB & 0x01) && (~data & 0x01) && (portB_out & 0x01))
 {
  portA_in = latch;
 }
 if ((ddrB & 0x02) && (data & 0x02) && (~portB_out & 0x02))
 {
  address = (address & 0xff00) | portA_out;
 }
 if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
 {
  address = (address & 0x00ff) | ((portA_out & 0x0f) << 8);
 }
 if ((ddrB & 0x10) && (~data & 0x10) && (portB_out & 0x10))
 {
  if (data & 0x08)
  {
   if ((address & 0x0800) == 0x0000)
   {
    latch = readinputport((address & 3) + 1);
   }
   else if ((address & 0x0c00) == 0x0c00)
   {
    latch = bublbobl_sharedram2[address & 0x03ff];
   }
  }
  else
  {
   if ((address & 0x0c00) == 0x0c00)
   {
    bublbobl_sharedram2[address & 0x03ff] = portA_out;
   }
  }
 }
 if ((ddrB & 0x20) && (~data & 0x20) && (portB_out & 0x20))
 {
  bublbobl_sharedram2[0x7c] = rand()%6;
  cpu_irq_line_vector_w(0,0,bublbobl_sharedram2[0]);
  cpu_set_irq_line(0,0,2);
 }
 portB_out = data;
}


decompiled_code:
void *init_bublbobl()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x8000), (const void *)(v0 + 0x10000), 0x4000uLL);
}

canonical_decompiled_code:
void *func23()
{
__int64 v0; // rax

v0 = memory_region(129LL);
return memcpy((void *)(v0 + 0x8000), (const void *)(v0 + 0x10000), 0x4000uLL);
}

original_code:
static void init_bublbobl(void)
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 memcpy(ROM+0x08000,ROM+0x10000,0x4000);
}

canonical_original_code:
static void init_bublbobl()
{
 unsigned char *ROM = memory_region(REGION_CPU1);
 memcpy(ROM+0x08000,ROM+0x10000,0x4000);
}


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

if ( sound_nmi_enable )
return cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 1;
return result;
}

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

if ( sound_nmi_enable )
return cpu_cause_interrupt(2LL, 4294967294LL);
pending_nmi = 1;
return result;
}

original_code:
static void nmi_callback(int param)
{
 if (sound_nmi_enable) cpu_cause_interrupt(2,-2);
 else pending_nmi = 1;
}

variable_types: param int


irqhandler

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

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

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

variable_types: irq int


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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0xE00;
result = layer_colorbase[a1] + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

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

*a3 |= ((unsigned __int16)*a4 << 8) & 0x100 | ((unsigned __int16)*a4 << 7) & 0xE00;
result = layer_colorbase[a1] + ((*a4 >> 5) & 7u);
*a4 = result;
return result;
}

original_code:
static void gradius3_tile_callback(int layer,int bank,int *code,int *color)
{
 *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
}

canonical_original_code:
static void gradius3_tile_callback(int layer, int bank, int *code, int *color)
{
 *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
 *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
}

variable_types: layer int


decompiled_code:
__int64 __fastcall gradius3_sprite_callback(_DWORD *a1, int *a2, _DWORD *a3)
{
int v3; // eax
int v4; // eax
__int64 result; // rax

v3 = (*a2 >> 5) & 3;
if ( gradius3_priority )
v4 = primask_1[v3 + 4];
else
v4 = primask_1[v3];
*a3 = v4;
*a1 |= ((unsigned __int16)*a2 << 13) & 0x2000;
result = sprite_colorbase + ((*a2 >> 1) & 0xFu);
*a2 = result;
return result;
}

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

v3 = (*a2 >> 5) & 3;
if ( gradius3_priority )
v4 = primask_1[v3 + 4];
else
v4 = primask_1[v3];
*a3 = v4;
*a1 |= ((unsigned __int16)*a2 << 13) & 0x2000;
result = sprite_colorbase + ((*a2 >> 1) & 0xFu);
*a2 = result;
return result;
}

original_code:
static void gradius3_sprite_callback(int *code,int *color,int *priority_mask,int *shadow)
{
 static int primask[2][4] =
 {
  { 0xaa|0xf0, 0xaa, 0xaa|0xf0, 0xaa|0xcc|0xf0 },
  { 0xcc|0xf0, 0xf0, 0, 0xaa|0xcc|0xf0 }
 };
 int pri = ((*color & 0x60) >> 5);
 if (gradius3_priority == 0) *priority_mask = primask[0][pri];
 else *priority_mask = primask[1][pri];
 *code |= (*color & 0x01) << 13;
 *color = sprite_colorbase + ((*color & 0x1e) >> 1);
}

canonical_original_code:
static void gradius3_sprite_callback(int *code, int *color, int *priority_mask, int *shadow)
{
 static int primask[2][4] = {
  { 0xaa|0xf0, 0xaa, 0xaa|0xf0, 0xaa|0xcc|0xf0 },
  { 0xcc|0xf0, 0xf0, 0, 0xaa|0xcc|0xf0 }
 };
 int pri = ((*color & 0x60) >> 5);
 if (gradius3_priority == 0) *priority_mask = primask[0][pri];
 else *priority_mask = primask[1][pri];
 *code |= (*color & 0x01) << 13;
 *color = sprite_colorbase + ((*color & 0x1e) >> 1);
}

variable_types:
primask
int [2][4]

variable_types: pri int


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

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

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

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


decompiled_code:
void __fastcall cpuB_irqenable_w(__int64 a1, unsigned int a2)
{
if ( (a2 & 0xFF000000) == 0 )
irqBmask = (a2 >> 8) & 7;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned int a2)
{
if ( (a2 & 0xFF000000) == 0 )
irqBmask = (a2 >> 8) & 7;
}

original_code:
static void cpuB_irqenable_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
  irqBmask = (data >> 8) & 0x07;
}

canonical_original_code:
static void cpuB_irqenable_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
  irqBmask = (data >> 8) & 0x07;
}


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

result = (unsigned int)irqAen;
if ( irqAen )
result = 2LL;
return result;
}

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

result = (unsigned int)irqAen;
if ( irqAen )
result = 2LL;
return result;
}

original_code:
static int cpuA_interrupt(void)
{
 if (irqAen) return 2;
 return 0;
}

canonical_original_code:
static int cpuA_interrupt()
{
 if (irqAen) return 2;
 return 0;
}


decompiled_code:
__int64 __fastcall gradius3_gfxrom_r(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(138LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 v1; // rax

v1 = memory_region(138LL);
return *(unsigned __int8 *)(v1 + a1) | (*(unsigned __int8 *)(v1 + a1 + 1) << 8);
}

original_code:
data_t gradius3_gfxrom_r(offs_t offset)
{
 unsigned char *gfxdata = memory_region(REGION_GFX2);
 return (gfxdata[offset+1] << 8) | gfxdata[offset];
}

canonical_original_code:
unsigned int gradius3_gfxrom_r(unsigned int offset)
{
 unsigned char *gfxdata = memory_region(REGION_GFX2);
 return (gfxdata[offset+1] << 8) | gfxdata[offset];
}

variable_types:
gfxdata
unsigned char *


decompiled_code:
__int64 gradius3_vh_start()
{
unsigned int v0; // er12
unsigned int v2; // ebx
__int64 v3; // rax
void *v4; // rdx

layer_colorbase[0] = 0;
dword_B5C = 32;
dword_B60 = 48;
sprite_colorbase = 16;
v0 = 1;
if ( !(unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, gradius3_tile_callback) )
{
v0 = K051960_vh_start(138LL, 3LL, 2LL, 1LL, 0LL, gradius3_sprite_callback);
v2 = v0;
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
}
else
{
do
{
v3 = memory_region(138LL);
decodechar(*(_QWORD *)(Machine + 520LL), v2++, v3, &spritelayout_2);
}
while ( v2 != 0x4000 );
v4 = malloc(0x1000uLL);
dirtychar = v4;
if ( v4 )
{
memset(v4, 1u, 0x1000uLL);
}
else
{
K052109_vh_stop();
K051960_vh_stop();
v0 = 1;
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er12
unsigned int v2; // ebx
__int64 v3; // rax
void *v4; // rdx

layer_colorbase[0] = 0;
dword_B5C = 32;
dword_B60 = 48;
sprite_colorbase = 16;
v0 = 1;
if ( !(unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, gradius3_tile_callback) )
{
v0 = K051960_vh_start(138LL, 3LL, 2LL, 1LL, 0LL, gradius3_sprite_callback);
v2 = v0;
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
}
else
{
do
{
v3 = memory_region(138LL);
decodechar(*(_QWORD *)(Machine + 520LL), v2++, v3, &spritelayout_2);
}
while ( v2 != 0x4000 );
v4 = malloc(0x1000uLL);
dirtychar = v4;
if ( v4 )
{
memset(v4, 1u, 0x1000uLL);
}
else
{
K052109_vh_stop();
K051960_vh_stop();
v0 = 1;
}
}
}
return v0;
}

variable_types: struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; }


decompiled_code:
void gradius3_vh_stop()
{
K052109_vh_stop();
K051960_vh_stop();
free(dirtychar);
dirtychar = 0LL;
}

canonical_decompiled_code:
void func10()
{
K052109_vh_stop();
K051960_vh_stop();
free(dirtychar);
dirtychar = 0LL;
}

original_code:
void gradius3_vh_stop(void)
{
 K052109_vh_stop();
 K051960_vh_stop();
 free(dirtychar);
 dirtychar = 0;
}

canonical_original_code:
void gradius3_vh_stop()
{
 K052109_vh_stop();
 K051960_vh_stop();
 free(dirtychar);
 dirtychar = 0;
}


decompiled_code:
__int64 __fastcall gradius3_vh_screenrefresh(__int64 a1)
{
__int64 i; // rbx

K052109_w(7552LL, 16LL);
K052109_w(7936LL, 50LL);
if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 4096; ++i )
{
if ( *((_BYTE *)dirtychar + i) )
{
*((_BYTE *)dirtychar + i) = 0;
decodechar(*(_QWORD *)(Machine + 512LL), (unsigned int)i, gradius3_gfxram, &charlayout_0);
}
}
tilemap_mark_all_tiles_dirty(0LL);
}
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
if ( gradius3_priority )
{
K052109_tilemap_draw(a1, 0LL, 65552LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 131088LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
K052109_tilemap_draw(a1, 0LL, 0x10000LL);
}
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 i; // rbx

K052109_w(7552LL, 16LL);
K052109_w(7936LL, 50LL);
if ( dirtygfx )
{
dirtygfx = 0;
for ( i = 0LL; i != 4096; ++i )
{
if ( *((_BYTE *)dirtychar + i) )
{
*((_BYTE *)dirtychar + i) = 0;
decodechar(*(_QWORD *)(Machine + 512LL), (unsigned int)i, gradius3_gfxram, &charlayout_0);
}
}
tilemap_mark_all_tiles_dirty(0LL);
}
K052109_tilemap_update();
palette_init_used_colors();
K051960_mark_sprites_colors();
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
if ( gradius3_priority )
{
K052109_tilemap_draw(a1, 0LL, 65552LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 131088LL);
K052109_tilemap_draw(a1, 2LL, 0x40000LL);
K052109_tilemap_draw(a1, 0LL, 0x10000LL);
}
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

original_code:
void gradius3_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 static struct GfxLayout charlayout =
 {
  8,8,
  0x1000,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 },
  { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
  32*8
 };
 K052109_w(0x1d80,0x10);
 K052109_w(0x1f00,0x32);
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x1000;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[0],i,gradius3_gfxram,&charlayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 if (gradius3_priority == 0)
 {
  K052109_tilemap_draw(bitmap,1,0x10|(2<<16));
  K052109_tilemap_draw(bitmap,2,4<<16);
  K052109_tilemap_draw(bitmap,0,1<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,0,0x10|(1<<16));
  K052109_tilemap_draw(bitmap,1,2<<16);
  K052109_tilemap_draw(bitmap,2,4<<16);
 }
 K051960_sprites_draw(bitmap,-1,-1);
}

canonical_original_code:
void gradius3_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 static struct GfxLayout charlayout = {
  8,8,
  0x1000,
  4,
  { 0, 1, 2, 3 },
  { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 },
  { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
  32*8
 };
 K052109_w(0x1d80,0x10);
 K052109_w(0x1f00,0x32);
 if (dirtygfx)
 {
  int i;
  dirtygfx = 0;
  for (i = 0;i < 0x1000;i++)
  {
   if (dirtychar[i])
   {
    dirtychar[i] = 0;
    decodechar(Machine->gfx[0],i,gradius3_gfxram,&charlayout);
   }
  }
  tilemap_mark_all_tiles_dirty(0);
 }
 K052109_tilemap_update();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 if (gradius3_priority == 0)
 {
  K052109_tilemap_draw(bitmap,1,0x10|(2<<16));
  K052109_tilemap_draw(bitmap,2,4<<16);
  K052109_tilemap_draw(bitmap,0,1<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,0,0x10|(1<<16));
  K052109_tilemap_draw(bitmap,1,2<<16);
  K052109_tilemap_draw(bitmap,2,4<<16);
 }
 K051960_sprites_draw(bitmap,-1,-1);
}

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

user_defined_types: struct GfxLayout { unsigned short width; unsigned int total; unsigned short planes; unsigned int planeoffset[8]; unsigned int xoffset[64]; unsigned int yoffset[64]; unsigned short charincrement; }


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

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

original_code:
static void init_gradius3(void)
{
 konami_rom_deinterleave_2(REGION_GFX2);
}

canonical_original_code:
static void init_gradius3()
{
 konami_rom_deinterleave_2(REGION_GFX2);
}


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

result = cpu_set_reset_line(1LL, 1LL);
irqAen = 0;
irqBmask = 0;
return result;
}

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

result = cpu_set_reset_line(1LL, 1LL);
irqAen = 0;
irqBmask = 0;
return result;
}

original_code:
static void gradius3_init(void)
{
 cpu_set_reset_line(1,1);
 irqAen = 0;
 irqBmask = 0;
}

canonical_original_code:
static void gradius3_init()
{
 cpu_set_reset_line(1,1);
 irqAen = 0;
 irqBmask = 0;
}


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

if ( (cpu_getiloops() & 1) == 0 )
return irqBmask & 1;
result = irqBmask & 2;
if ( (irqBmask & 2) != 0 )
result = 2LL;
return result;
}

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

if ( (cpu_getiloops() & 1) == 0 )
return irqBmask & 1;
result = irqBmask & 2;
if ( (irqBmask & 2) != 0 )
result = 2LL;
return result;
}

original_code:
static int cpuB_interrupt(void)
{
 if (cpu_getiloops() & 1)
 {
  if (irqBmask & 2) return 2;
 }
 else
 {
  if (irqBmask & 1) return 1;
 }
 return 0;
}

canonical_original_code:
static int cpuB_interrupt()
{
 if (cpu_getiloops() & 1)
 {
  if (irqBmask & 2) return 2;
 }
 else
 {
  if (irqBmask & 1) return 1;
 }
 return 0;
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051960_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051960_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void K051960_halfword_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051960_w(offset >> 1,data & 0xff);
}

canonical_original_code:
static void K051960_halfword_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051960_w(offset >> 1,data & 0xff);
}


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

if ( (a2 & 0xFF0000) == 0 )
result = K051937_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

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

if ( (a2 & 0xFF0000) == 0 )
result = K051937_w(a1 >> 1, (unsigned __int8)a2);
return result;
}

original_code:
static void K051937_halfword_w(offs_t offset,data_t data)
{
 if ((data & 0x00ff0000) == 0)
  K051937_w(offset >> 1,data & 0xff);
}

canonical_original_code:
static void K051937_halfword_w(unsigned int offset, unsigned int data)
{
 if ((data & 0x00ff0000) == 0)
  K051937_w(offset >> 1,data & 0xff);
}


decompiled_code:
__int64 __fastcall K051960_halfword_r(unsigned int a1)
{
return K051960_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1)
{
return K051960_r(a1 >> 1);
}

original_code:
static data_t K051960_halfword_r(offs_t offset)
{
 return K051960_r(offset >> 1);
}

canonical_original_code:
static unsigned int K051960_halfword_r(unsigned int offset)
{
 return K051960_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall K051937_halfword_r(unsigned int a1)
{
return K051937_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1)
{
return K051937_r(a1 >> 1);
}

original_code:
static data_t K051937_halfword_r(offs_t offset)
{
 return K051937_r(offset >> 1);
}

canonical_original_code:
static unsigned int K051937_halfword_r(unsigned int offset)
{
 return K051937_r(offset >> 1);
}


decompiled_code:
__int64 __fastcall K052109_halfword_r(unsigned int a1)
{
return K052109_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned int a1)
{
return K052109_r(a1 >> 1);
}

original_code:
static data_t K052109_halfword_r(offs_t offset)
{
 return K052109_r(offset >> 1);
}

canonical_original_code:
static unsigned int K052109_halfword_r(unsigned int offset)
{
 return K052109_r(offset >> 1);
}


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

if ( (irqBmask & 4) != 0 )
result = cpu_cause_interrupt(1LL, 4LL);
return result;
}

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

if ( (irqBmask & 4) != 0 )
result = cpu_cause_interrupt(1LL, 4LL);
return result;
}

original_code:
static void cpuB_irqtrigger_w(offs_t offset,data_t data)
{
 if (irqBmask & 4)
 {
  cpu_cause_interrupt(1,4);
 }
}

canonical_original_code:
static void cpuB_irqtrigger_w(unsigned int offset, unsigned int data)
{
 if (irqBmask & 4)
 {
  cpu_cause_interrupt(1,4);
 }
}


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

if ( (a2 & 0xFF000000) == 0 )
{
coin_counter_w(0LL, BYTE1(a2) & 1);
coin_counter_w(1LL, BYTE1(a2) & 2);
gradius3_priority = BYTE1(a2) & 4;
result = cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 11) ^ 1) & 1);
irqAen = (a2 >> 8) & 0x20;
}
return result;
}

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

if ( (a2 & 0xFF000000) == 0 )
{
coin_counter_w(0LL, BYTE1(a2) & 1);
coin_counter_w(1LL, BYTE1(a2) & 2);
gradius3_priority = BYTE1(a2) & 4;
result = cpu_set_reset_line(1LL, ((unsigned __int8)(a2 >> 11) ^ 1) & 1);
irqAen = (a2 >> 8) & 0x20;
}
return result;
}

original_code:
static void cpuA_ctrl_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
 {
  data >>= 8;
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
  gradius3_priority = data & 0x04;
  cpu_set_reset_line(1,(data & 0x08) ? 0 : 1);
  irqAen = data & 0x20;
 }
}

canonical_original_code:
static void cpuA_ctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
 {
  data >>= 8;
  coin_counter_w(0,data & 0x01);
  coin_counter_w(1,data & 0x02);
  gradius3_priority = data & 0x04;
  cpu_set_reset_line(1,(data & 0x08) ? 0 : 1);
  irqAen = data & 0x20;
 }
}


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

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

original_code:
static data_t sharedram_r(offs_t offset)
{
 return (*(UINT16 *)(&sharedram[offset]));
}

canonical_original_code:
static unsigned int sharedram_r(unsigned int offset)
{
 return (*(unsigned short *)(&sharedram[offset]));
}


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

variable_types: v int


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

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

variable_types:
RAM
unsigned char *