decompiled_code:
void *tail2nos_init_machine()
{
void *result; // rax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(154LL);
if ( ophw == 1 )
{
ophw = -1;
v1 = cpu_get_pc();
cpu_setOPbase16(v1);
}
cpu_bankbase[2] = memory_region(155LL);
if ( ophw == 2 )
{
ophw = -1;
v2 = cpu_get_pc();
cpu_setOPbase16(v2);
}
cpu_bankbase[9] = memory_region(130LL) + 0x10000;
result = &ophw;
if ( ophw == 9 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *func12()
{
void *result; // rax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(154LL);
if ( ophw == 1 )
{
ophw = -1;
v1 = cpu_get_pc();
cpu_setOPbase16(v1);
}
cpu_bankbase[2] = memory_region(155LL);
if ( ophw == 2 )
{
ophw = -1;
v2 = cpu_get_pc();
cpu_setOPbase16(v2);
}
cpu_bankbase[9] = memory_region(130LL) + 0x10000;
result = &ophw;
if ( ophw == 9 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
static void tail2nos_init_machine(void)
{
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(memory_region(REGION_USER1)); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(memory_region(REGION_USER2)); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (UINT8 *)(memory_region(REGION_CPU2) + 0x10000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void tail2nos_init_machine()
{
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(memory_region(REGION_USER1)); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(memory_region(REGION_USER2)); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (unsigned char *)(memory_region(REGION_CPU2) + 0x10000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


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

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall tail2nos_K051316_0_r(unsigned int a1)
{
return K051316_0_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
return K051316_0_r(a1 >> 1);
}

original_code:
static data_t tail2nos_K051316_0_r(offs_t offset)
{
 return K051316_0_r(offset >> 1);
}

canonical_original_code:
static unsigned int tail2nos_K051316_0_r(unsigned int offset)
{
 return K051316_0_r(offset >> 1);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall get_tile_info(int a1)
{
unsigned __int16 v1; // si
__int64 v2; // rcx
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(tail2nos_bgvideoram + 2 * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = ((v1 & 0x1FFFu) + (charbank << 13)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * ((v1 >> 13) + 16 * charpalette);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned __int16 v1; // si
__int64 v2; // rcx
signed int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(_WORD *)(tail2nos_bgvideoram + 2 * a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = ((v1 & 0x1FFFu) + (charbank << 13)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * ((v1 >> 13) + 16 * charpalette);
v4 = *(_QWORD *)(v2 + 32);
result = 0LL;
if ( v4 )
result = *(unsigned int *)(v4 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tile_info(int tile_index)
{
 UINT16 code = (*(UINT16 *)(&tail2nos_bgvideoram[2*tile_index]));
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((code & 0x1fff) + (charbank << 13)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((code & 0xe000) >> 13) + charpalette * 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_tile_info(int tile_index)
{
 unsigned short code = (*(UINT16 *)(&tail2nos_bgvideoram[2*tile_index]));
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((code & 0x1fff) + (charbank << 13)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (((code & 0xe000) >> 13) + charpalette * 16)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types:
code
unsigned short

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


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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = ((*a2 >> 3) & 7u) + 32;
*a2 = result;
return result;
}

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

*a1 |= ((unsigned __int16)*a2 << 8) & 0x300;
result = ((*a2 >> 3) & 7u) + 32;
*a2 = result;
return result;
}

original_code:
static void zoom_callback(int *code,int *color)
{
 *code |= ((*color & 0x03) << 8);
 *color = 32 + ((*color & 0x38) >> 3);
}

canonical_original_code:
static void zoom_callback(int *code, int *color)
{
 *code |= ((*color & 0x03) << 8);
 *color = 32 + ((*color & 0x38) >> 3);
}

variable_types:
code
int *

variable_types:
color
int *


irqhandler

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

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

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

variable_types: irq int


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

cpu_bankbase[9] = memory_region(130LL) + ((unsigned __int8)(a2 & 1) << 15) + 0x10000;
result = &ophw;
if ( ophw == 9 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

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

cpu_bankbase[9] = memory_region(130LL) + ((unsigned __int8)(a2 & 1) << 15) + 0x10000;
result = &ophw;
if ( ophw == 9 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
static void sound_bankswitch_w(offs_t offset,data_t data)
{
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (UINT8 *)(memory_region(REGION_CPU2) + 0x10000 + (data & 0x01) * 0x8000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
static void sound_bankswitch_w(unsigned int offset, unsigned int data)
{
 { if (9 >= 1 && 9 <= 16) { cpu_bankbase[9] = (unsigned char *)(memory_region(REGION_CPU2) + 0x10000 + (data & 0x01) * 0x8000); if (ophw == 9) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}


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

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

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

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

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

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


decompiled_code:
__int64 srumbler_vh_start()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v2) = 64;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 64LL, v2);
bg_tilemap = v0;
if ( !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 3;
*(_DWORD *)(v0 + 136) = 0xFFFF;
*(_DWORD *)(v0 + 140) = 2047;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v2; // [rsp+0h] [rbp-18h]

fg_tilemap = tilemap_create(get_fg_tile_info, &tilemap_scan_cols, 1LL, 8LL, 8LL, 64LL, 32LL);
LODWORD(v2) = 64;
v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_cols, 2LL, 16LL, 16LL, 64LL, v2);
bg_tilemap = v0;
if ( !v0 || !fg_tilemap )
return 1LL;
*(_DWORD *)(fg_tilemap + 132) = 3;
*(_DWORD *)(v0 + 136) = 0xFFFF;
*(_DWORD *)(v0 + 140) = 2047;
return 0LL;
}

original_code:
int srumbler_vh_start(void)
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,64,64);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 3;
 bg_tilemap->transmask[0] = 0xffff;
 bg_tilemap->transmask[1] = 0x07ff;
 return 0;
}

canonical_original_code:
int srumbler_vh_start()
{
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,0x01,8,8,64,32);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,0x02, 16,16,64,64);
 if (!fg_tilemap || !bg_tilemap)
  return 1;
 fg_tilemap->transparent_pen = 3;
 bg_tilemap->transmask[0] = 0xffff;
 bg_tilemap->transmask[1] = 0x07ff;
 return 0;
}

return_type: int


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

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

original_code:
void srumbler_4009_w(offs_t offset,data_t data)
{
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x40);
 coin_counter_w(1,data & 0x80);
}

canonical_original_code:
void srumbler_4009_w(unsigned int offset, unsigned int data)
{
 flip_screen_w(0,data & 1);
 coin_counter_w(0,data & 0x40);
 coin_counter_w(1,data & 0x80);
}


decompiled_code:
__int64 __fastcall srumbler_scroll_w(int a1, int a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(bg_tilemap, 0LL, scroll_0[0] | (unsigned int)(dword_D04 << 8));
return tilemap_set_scrolly(bg_tilemap, 0LL, dword_D08 | (unsigned int)(dword_D0C << 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
scroll_0[a1] = a2;
tilemap_set_scrollx(bg_tilemap, 0LL, scroll_0[0] | (unsigned int)(dword_D04 << 8));
return tilemap_set_scrolly(bg_tilemap, 0LL, dword_D08 | (unsigned int)(dword_D0C << 8));
}

original_code:
void srumbler_scroll_w(offs_t offset,data_t data)
{
 static int scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
 tilemap_set_scrolly(bg_tilemap,0,scroll[2] | (scroll[3] << 8));
}

canonical_original_code:
void srumbler_scroll_w(unsigned int offset, unsigned int data)
{
 static int scroll[4];
 scroll[offset] = data;
 tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
 tilemap_set_scrolly(bg_tilemap,0,scroll[2] | (scroll[3] << 8));
}

variable_types:
scroll
int [4]


decompiled_code:
__int64 __fastcall srumbler_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
tilemap_draw(a1, bg_tilemap, 32LL);
draw_sprites(a1);
tilemap_draw(a1, bg_tilemap, 64LL);
return tilemap_draw(a1, fg_tilemap, 0LL);
}

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

original_code:
void srumbler_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0);
}

canonical_original_code:
void srumbler_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 tilemap_draw(bitmap,bg_tilemap,0x20);
 draw_sprites(bitmap);
 tilemap_draw(bitmap,bg_tilemap,0x40);
 tilemap_draw(bitmap,fg_tilemap,0);
}

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


decompiled_code:
__int64 __fastcall srumbler_bankswitch_w(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // eax
__int64 result; // rax

v2 = memory_region(154LL);
v3 = memory_region(145LL);
v4 = memory_region(145LL);
v5 = 5LL;
v6 = (a2 & 0xF0) + v3;
do
{
result = *(_BYTE *)(v4 + (unsigned __int8)(16 * a2) + 256LL + v5) & 0xF | (16 * *(_BYTE *)(v6 + v5)) & 0x30u;
if ( (unsigned int)v5 <= 0xF )
{
cpu_bankbase[v5 + 1] = v2 + (int)((_DWORD)result << 12);
result = (unsigned int)(v5 + 1);
if ( ophw == (_DWORD)result )
{
ophw = -1;
v7 = cpu_get_pc();
result = cpu_setOPbase16(v7);
}
}
++v5;
}
while ( v5 != 16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // rbx
__int64 v6; // rbp
unsigned int v7; // eax
__int64 result; // rax

v2 = memory_region(154LL);
v3 = memory_region(145LL);
v4 = memory_region(145LL);
v5 = 5LL;
v6 = (a2 & 0xF0) + v3;
do
{
result = *(_BYTE *)(v4 + (unsigned __int8)(16 * a2) + 256LL + v5) & 0xF | (16 * *(_BYTE *)(v6 + v5)) & 0x30u;
if ( (unsigned int)v5 <= 0xF )
{
cpu_bankbase[v5 + 1] = v2 + (int)((_DWORD)result << 12);
result = (unsigned int)(v5 + 1);
if ( ophw == (_DWORD)result )
{
ophw = -1;
v7 = cpu_get_pc();
result = cpu_setOPbase16(v7);
}
}
++v5;
}
while ( v5 != 16 );
return result;
}

original_code:
static void srumbler_bankswitch_w(offs_t offset,data_t data)
{
 int i;
 unsigned char *ROM = memory_region(REGION_USER1);
 unsigned char *prom1 = memory_region(REGION_PROMS) + (data & 0xf0);
 unsigned char *prom2 = memory_region(REGION_PROMS) + 0x100 + ((data & 0x0f) << 4);
 for (i = 0x05;i < 0x10;i++)
 {
  int bank = ((prom1[i] & 0x03) << 4) | (prom2[i] & 0x0f);
  { if (i+1 >= 1 && i+1 <= 16) { cpu_bankbase[i+1] = (UINT8 *)(&ROM[bank*0x1000]); if (ophw == i+1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

canonical_original_code:
static void srumbler_bankswitch_w(unsigned int offset, unsigned int data)
{
 int i;
 unsigned char *ROM = memory_region(REGION_USER1);
 unsigned char *prom1 = memory_region(REGION_PROMS) + (data & 0xf0);
 unsigned char *prom2 = memory_region(REGION_PROMS) + 0x100 + ((data & 0x0f) << 4);
 for (i = 0x05;i < 0x10;i++)
 {
  int bank = ((prom1[i] & 0x03) << 4) | (prom2[i] & 0x0f);
  { if (i+1 >= 1 && i+1 <= 16) { cpu_bankbase[i+1] = (unsigned char *)(&ROM[bank*0x1000]); if (ophw == i+1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 }
}

variable_types: i int

variable_types:
ROM
unsigned char *

variable_types: bank int


decompiled_code:
__int64 srumbler_init_machine()
{
return srumbler_bankswitch_w(0LL, 0);
}

canonical_decompiled_code:
__int64 func8()
{
return func7(0LL, 0);
}

original_code:
static void srumbler_init_machine(void)
{
 srumbler_bankswitch_w(0,0);
}

canonical_original_code:
static void srumbler_init_machine()
{
 srumbler_bankswitch_w(0,0);
}


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

v0 = cpu_getiloops();
result = 2LL;
if ( !v0 )
result = interrupt();
return result;
}

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

v0 = cpu_getiloops();
result = 2LL;
if ( !v0 )
result = interrupt();
return result;
}

original_code:
static int srumbler_interrupt(void)
{
 if (cpu_getiloops()==0)
 {
  return interrupt();
 }
 else
 {
  return 2;
 }
}

canonical_original_code:
static int srumbler_interrupt()
{
 if (cpu_getiloops()==0)
 {
  return interrupt();
 }
 else
 {
  return 2;
 }
}


decompiled_code:
void *__fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rdi
__int64 v2; // rsi
int v3; // ecx
signed int v4; // edx
int v5; // ecx
__int64 v6; // rax
int v7; // esi
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
__int64 v1; // rdi
__int64 v2; // rsi
int v3; // ecx
signed int v4; // edx
int v5; // ecx
__int64 v6; // rax
int v7; // esi
void *result; // rax

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

original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_foregroundram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (srumbler_foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x3c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x40) ? 0x10 : 0;
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_foregroundram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (srumbler_foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x3c) >> 2)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (attr & 0x40) ? 0x10 : 0;
}

variable_types:
attr
unsigned char

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


decompiled_code:
void *__fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rdi
unsigned __int8 v2; // r8
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rsi
void *result; // rax
int v7; // ecx

v1 = 2 * a1;
v2 = *(_BYTE *)(srumbler_backgroundram + v1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(srumbler_backgroundram + v1 + 1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 5);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = (void *)*(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = (_DWORD)result;
v7 = (v2 >> 2) & 4;
if ( (v2 & 8) != 0 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) = v7 | 2;
}
else
{
*((_DWORD *)&tile_info + 5) = v7;
}
return result;
}

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

v1 = 2 * a1;
v2 = *(_BYTE *)(srumbler_backgroundram + v1);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = (*(unsigned __int8 *)(srumbler_backgroundram + v1 + 1) + ((v2 << 8) & 0x700u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 >> 5);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = (void *)*(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = (_DWORD)result;
v7 = (v2 >> 2) & 4;
if ( (v2 & 8) != 0 )
{
result = &tile_info;
*((_DWORD *)&tile_info + 5) = v7 | 2;
}
else
{
*((_DWORD *)&tile_info + 5) = v7;
}
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_backgroundram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (srumbler_backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xe0) >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x10) >> 4)<<2);
 if (attr & 0x08) tile_info.flags |= 0x02;
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = srumbler_backgroundram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (srumbler_backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0xe0) >> 5)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = (((attr & 0x10) >> 4)<<2);
 if (attr & 0x08) tile_info.flags |= 0x02;
}


decompiled_code:
void *__fastcall draw_sprites(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v3; // rbx

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v3 = v2 + 1LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v3 - 1)
+ ((8 * *(unsigned __int8 *)(spriteram + v3)) & 0x700u));
v3 -= 4LL;
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1)
{
void *result; // rax
int v2; // ebp
__int64 v3; // rbx

result = &spriteram_size;
v2 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v3 = v2 + 1LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
*(unsigned __int8 *)(spriteram + v3 - 1)
+ ((8 * *(unsigned __int8 *)(spriteram + v3)) & 0x700u));
v3 -= 4LL;
v2 -= 4;
}
while ( v2 >= 0 );
}
return result;
}

original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = spriteram_size-4; offs>=0;offs -= 4)
 {
  int code,colour,sx,sy,flipy;
  int attr=spriteram[offs+1];
  code = spriteram[offs];
  code += ( (attr&0xe0) << 3 );
  colour = (attr & 0x1c)>>2;
  sy = spriteram[offs + 2];
  sx = spriteram[offs + 3] + 0x100 * ( attr & 0x01);
  flipy = attr & 0x02;
  if (flip_screen_x)
  {
   sx = 496 - sx;
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[2],
    code,
    colour,
    flip_screen_x,flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 for (offs = spriteram_size-4; offs>=0;offs -= 4)
 {
  int code; int colour; int sx; int sy; int flipy;
  int attr = spriteram[offs+1];
  code = spriteram[offs];
  code += ( (attr&0xe0) << 3 );
  colour = (attr & 0x1c)>>2;
  sy = spriteram[offs + 2];
  sx = spriteram[offs + 3] + 0x100 * ( attr & 0x01);
  flipy = attr & 0x02;
  if (flip_screen_x)
  {
   sx = 496 - sx;
   sy = 240 - sy;
   flipy = !flipy;
  }
  drawgfx(bitmap,Machine->gfx[2],
    code,
    colour,
    flip_screen_x,flipy,
    sx, sy,
    &Machine->visible_area,TRANSPARENCY_PEN,15);
 }
}

variable_types: offs int

variable_types: code int

variable_types: colour int

variable_types: sx int

variable_types: sy int

variable_types: flipy int

variable_types: attr int

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


decompiled_code:
__int64 __fastcall foodf_nvram_r(unsigned int a1)
{
return ((int)*((unsigned __int8 *)&nvram + ((a1 >> 2) ^ 3)) >> (2 * (a1 & 3))) & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return ((int)*((unsigned __int8 *)&nvram + ((a1 >> 2) ^ 3)) >> (2 * (a1 & 3))) & 0xF;
}

original_code:
data_t foodf_nvram_r(offs_t offset)
{
 return ((nvram[(offset / 4) ^ 0x03] >> 2*(offset % 4))) & 0x0f;
}

canonical_original_code:
unsigned int foodf_nvram_r(unsigned int offset)
{
 return ((nvram[(offset / 4) ^ 0x03] >> 2*(offset % 4))) & 0x0f;
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall foodf_nvram_w(unsigned int a1, char a2)
{
unsigned int v2; // edx
char v3; // cl
int v4; // eax
__int64 result; // rax

v2 = (a1 >> 2) ^ 3;
v3 = 2 * (a1 & 3);
v4 = ~(15 << v3);
LOBYTE(v4) = *((_BYTE *)&nvram + v2) & v4;
result = ((a2 & 0xF) << v3) | (unsigned int)v4;
*((_BYTE *)&nvram + v2) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
unsigned int v2; // edx
char v3; // cl
int v4; // eax
__int64 result; // rax

v2 = (a1 >> 2) ^ 3;
v3 = 2 * (a1 & 3);
v4 = ~(15 << v3);
LOBYTE(v4) = *((_BYTE *)&nvram + v2) & v4;
result = ((a2 & 0xF) << v3) | (unsigned int)v4;
*((_BYTE *)&nvram + v2) = result;
return result;
}

original_code:
void foodf_nvram_w(offs_t offset,data_t data)
{
 nvram[(offset / 4) ^ 0x03] &= ~(0x0f << 2*(offset % 4));
 nvram[(offset / 4) ^ 0x03] |= (data & 0x0f) << 2*(offset % 4);
}

canonical_original_code:
void foodf_nvram_w(unsigned int offset, unsigned int data)
{
 nvram[(offset / 4) ^ 0x03] &= ~(0x0f << 2*(offset % 4));
 nvram[(offset / 4) ^ 0x03] |= (data & 0x0f) << 2*(offset % 4);
}

variable_types:
data
unsigned int


decompiled_code:
void __fastcall foodf_analog_w(unsigned int a1)
{
whichport = ~(unsigned __int8)(a1 >> 1) & 3;
}

canonical_decompiled_code:
void __fastcall func2(unsigned int a1)
{
whichport = ~(unsigned __int8)(a1 >> 1) & 3;
}

original_code:
void foodf_analog_w(offs_t offset,data_t data)
{
 whichport = 3 - ((offset/2) & 3);
}

canonical_original_code:
void foodf_analog_w(unsigned int offset, unsigned int data)
{
 whichport = 3 - ((offset/2) & 3);
}


decompiled_code:
void foodf_digital_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


decompiled_code:
__int64 __fastcall foodf_vh_convert_color_prom(_BYTE *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 result; // rax

if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) )
{
v2 = 0;
do
{
*a1 = -(v2 & 1);
a1[1] = -((v2 >> 1) & 1);
a1 += 3;
*(a1 - 1) = -((v2++ >> 2) & 1);
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > (unsigned int)v2 );
}
v3 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL));
if ( (int)result > 0 )
{
LODWORD(result) = 0;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v3 + 824) + 688LL) + 16LL) + (int)result)) = result;
result = (unsigned int)(result + 1);
v3 = Machine;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL) > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 result; // rax

if ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) )
{
v2 = 0;
do
{
*a1 = -(v2 & 1);
a1[1] = -((v2 >> 1) & 1);
a1 += 3;
*(a1 - 1) = -((v2++ >> 2) & 1);
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) > (unsigned int)v2 );
}
v3 = Machine;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL)
* *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL));
if ( (int)result > 0 )
{
LODWORD(result) = 0;
do
{
*(_WORD *)(a2 + 2LL * (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v3 + 824) + 688LL) + 16LL) + (int)result)) = result;
result = (unsigned int)(result + 1);
v3 = Machine;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 12LL) * *(_DWORD *)(*(_QWORD *)(Machine + 512LL) + 24LL) > (int)result );
}
return result;
}

original_code:
void foodf_vh_convert_color_prom (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  *(palette++) = ((i & 1) >> 0) * 0xff;
  *(palette++) = ((i & 2) >> 1) * 0xff;
  *(palette++) = ((i & 4) >> 2) * 0xff;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
}

canonical_original_code:
void foodf_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  *(palette++) = ((i & 1) >> 0) * 0xff;
  *(palette++) = ((i & 2) >> 1) * 0xff;
  *(palette++) = ((i & 4) >> 2) * 0xff;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = i;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

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

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

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


decompiled_code:
__int64 foodf_delayed_interrupt()
{
return cpu_cause_interrupt(0LL, 2LL);
}

canonical_decompiled_code:
__int64 func7()
{
return cpu_cause_interrupt(0LL, 2LL);
}

original_code:
void foodf_delayed_interrupt (int param)
{
 cpu_cause_interrupt (0, 2);
}

canonical_original_code:
void foodf_delayed_interrupt(int param)
{
 cpu_cause_interrupt (0, 2);
}

variable_types: param int


decompiled_code:
__int64 foodf_interrupt()
{
if ( !(unsigned int)cpu_getiloops() )
timer_set(107374LL, 0LL, foodf_delayed_interrupt);
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
if ( !(unsigned int)cpu_getiloops() )
timer_set(107374LL, 0LL, foodf_delayed_interrupt);
return 1LL;
}

original_code:
int foodf_interrupt (void)
{
 if (cpu_getiloops () == 0)
  timer_set (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)), 0, foodf_delayed_interrupt);
 return 1;
}

canonical_original_code:
int foodf_interrupt()
{
 if (cpu_getiloops () == 0)
  timer_set (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)), 0, foodf_delayed_interrupt);
 return 1;
}


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

if ( a2 )
return osd_fwrite(a1, &nvram, 128LL);
if ( a1 )
return osd_fread(a1, &nvram, 128LL);
nvram = -1LL;
qword_D88 = -1LL;
qword_D90 = -1LL;
qword_D98 = -1LL;
qword_DA0 = -1LL;
qword_DA8 = -1LL;
qword_DB0 = -1LL;
qword_DB8 = -1LL;
qword_DC0 = -1LL;
qword_DC8 = -1LL;
qword_DD0 = -1LL;
qword_DD8 = -1LL;
qword_DE0 = -1LL;
qword_DE8 = -1LL;
qword_DF0 = -1LL;
qword_DF8 = -1LL;
return result;
}

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

if ( a2 )
return osd_fwrite(a1, &nvram, 128LL);
if ( a1 )
return osd_fread(a1, &nvram, 128LL);
nvram = -1LL;
qword_D88 = -1LL;
qword_D90 = -1LL;
qword_D98 = -1LL;
qword_DA0 = -1LL;
qword_DA8 = -1LL;
qword_DB0 = -1LL;
qword_DB8 = -1LL;
qword_DC0 = -1LL;
qword_DC8 = -1LL;
qword_DD0 = -1LL;
qword_DD8 = -1LL;
qword_DE0 = -1LL;
qword_DE8 = -1LL;
qword_DF0 = -1LL;
qword_DF8 = -1LL;
return result;
}

original_code:
void foodf_nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,128);
 else
 {
  if (file)
   osd_fread(file,nvram,128);
  else
   memset(nvram,0xff,128);
 }
}

canonical_original_code:
void foodf_nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,128);
 else
 {
  if (file)
   osd_fread(file,nvram,128);
  else
   memset(nvram,0xff,128);
 }
}

variable_types:
file
void *


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

if ( a1 <= 6 && ((1LL << a1) & 0x55) != 0 )
result = readinputport((unsigned int)whichport, a2, 0LL);
else
result = 0LL;
return result;
}

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

if ( a1 <= 6 && ((1LL << a1) & 0x55) != 0 )
result = readinputport((unsigned int)whichport, a2, 0LL);
else
result = 0LL;
return result;
}

original_code:
data_t foodf_analog_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
  case 2:
  case 4:
  case 6:
   return readinputport (whichport);
 }
 return 0;
}

canonical_original_code:
unsigned int foodf_analog_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
  case 2:
  case 4:
  case 6:
   return readinputport (whichport);
 }
 return 0;
}


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

result = 0LL;
if ( !a1 )
result = input_port_4_r();
return result;
}

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

result = 0LL;
if ( !a1 )
result = input_port_4_r();
return result;
}

original_code:
data_t foodf_digital_r(offs_t offset)
{
 switch (offset)
 {
  case 0:
   return input_port_4_r (offset);
 }
 return 0;
}

canonical_original_code:
unsigned int foodf_digital_r(unsigned int offset)
{
 switch (offset)
 {
  case 0:
   return input_port_4_r (offset);
 }
 return 0;
}


decompiled_code:
void foodf_vh_stop()
{
if ( playfieldbitmap )
bitmap_free();
playfieldbitmap = 0LL;
if ( playfielddirty )
free(playfielddirty);
playfielddirty = 0LL;
}

canonical_decompiled_code:
void func12()
{
if ( playfieldbitmap )
bitmap_free();
playfieldbitmap = 0LL;
if ( playfielddirty )
free(playfielddirty);
playfielddirty = 0LL;
}

original_code:
void foodf_vh_stop(void)
{
 if (playfieldbitmap) bitmap_free(playfieldbitmap); playfieldbitmap = 0;
 if (playfielddirty) free(playfielddirty); playfielddirty = 0;
}

canonical_original_code:
void foodf_vh_stop()
{
 if (playfieldbitmap) bitmap_free(playfieldbitmap); playfieldbitmap = 0;
 if (playfielddirty) free(playfielddirty); playfielddirty = 0;
}


decompiled_code:
__int64 foodf_vh_start()
{
void *v0; // rdi
__int64 result; // rax

v0 = playfielddirty;
if ( !playfielddirty && (v0 = malloc(foodf_playfieldram_size >> 1), (playfielddirty = v0) == 0LL)
|| (memset(v0, 1, foodf_playfieldram_size >> 1), result = 0LL, !playfieldbitmap)
&& (playfieldbitmap = bitmap_alloc(256LL, 256LL), result = 0LL, !playfieldbitmap) )
{
foodf_vh_stop();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
void *v0; // rdi
__int64 result; // rax

v0 = playfielddirty;
if ( !playfielddirty && (v0 = malloc(foodf_playfieldram_size >> 1), (playfielddirty = v0) == 0LL)
|| (memset(v0, 1, foodf_playfieldram_size >> 1), result = 0LL, !playfieldbitmap)
&& (playfieldbitmap = bitmap_alloc(256LL, 256LL), result = 0LL, !playfieldbitmap) )
{
func12();
result = 1LL;
}
return result;
}

original_code:
int foodf_vh_start(void)
{
 if (!playfielddirty) playfielddirty = (unsigned char*)malloc(foodf_playfieldram_size / 2);
 if (!playfielddirty)
 {
  foodf_vh_stop ();
  return 1;
 }
 memset (playfielddirty, 1, foodf_playfieldram_size / 2);
 if (!playfieldbitmap) playfieldbitmap = bitmap_alloc (32*8, 32*8);
 if (!playfieldbitmap)
 {
  foodf_vh_stop ();
  return 1;
 }
 return 0;
}

canonical_original_code:
int foodf_vh_start()
{
 if (!playfielddirty) playfielddirty = (unsigned char *)malloc(foodf_playfieldram_size / 2);
 if (!playfielddirty)
 {
  foodf_vh_stop ();
  return 1;
 }
 memset (playfielddirty, 1, foodf_playfieldram_size / 2);
 if (!playfieldbitmap) playfieldbitmap = bitmap_alloc (32*8, 32*8);
 if (!playfieldbitmap)
 {
  foodf_vh_stop ();
  return 1;
 }
 return 0;
}


original_code:
void foodf_paletteram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int bit0,bit1,bit2;
 int r,g,b;
 (*(UINT16 *)(&paletteram[offset]) = (newword));
 bit0 = (newword >> 0) & 0x01;
 bit1 = (newword >> 1) & 0x01;
 bit2 = (newword >> 2) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (newword >> 3) & 0x01;
 bit1 = (newword >> 4) & 0x01;
 bit2 = (newword >> 5) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (newword >> 6) & 0x01;
 bit2 = (newword >> 7) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset / 2,r,g,b);
}

canonical_original_code:
void foodf_paletteram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&paletteram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 int bit0; int bit1; int bit2;
 int r; int g; int b;
 (*(unsigned short *)(&paletteram[offset]) = (newword));
 bit0 = (newword >> 0) & 0x01;
 bit1 = (newword >> 1) & 0x01;
 bit2 = (newword >> 2) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (newword >> 3) & 0x01;
 bit1 = (newword >> 4) & 0x01;
 bit2 = (newword >> 5) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (newword >> 6) & 0x01;
 bit2 = (newword >> 7) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset / 2,r,g,b);
}

variable_types: oldword int

variable_types: newword int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall foodf_pokey1_r(unsigned int a1)
{
return pokey1_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1)
{
return pokey1_r(a1 >> 1);
}

original_code: data_t foodf_pokey1_r(offs_t offset) { return pokey1_r (offset/2); }

canonical_original_code: unsigned int foodf_pokey1_r(unsigned int offset) { return pokey1_r (offset/2); }


decompiled_code:
__int64 __fastcall foodf_pokey2_r(unsigned int a1)
{
return pokey2_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1)
{
return pokey2_r(a1 >> 1);
}

original_code: data_t foodf_pokey2_r(offs_t offset) { return pokey2_r (offset/2); }

canonical_original_code: unsigned int foodf_pokey2_r(unsigned int offset) { return pokey2_r (offset/2); }


decompiled_code:
__int64 __fastcall foodf_pokey3_r(unsigned int a1)
{
return pokey3_r(a1 >> 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
return pokey3_r(a1 >> 1);
}

original_code: data_t foodf_pokey3_r(offs_t offset) { return pokey3_r (offset/2); }

canonical_original_code: unsigned int foodf_pokey3_r(unsigned int offset) { return pokey3_r (offset/2); }


decompiled_code:
__int64 __fastcall foodf_pokey1_w(unsigned int a1, unsigned __int8 a2)
{
return pokey1_w(a1 >> 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1, unsigned __int8 a2)
{
return pokey1_w(a1 >> 1, a2);
}

original_code: void foodf_pokey1_w(offs_t offset,data_t data) { pokey1_w (offset/2, data & 0xff); }

canonical_original_code: void foodf_pokey1_w(unsigned int offset, unsigned int data) { pokey1_w (offset/2, data & 0xff); }


decompiled_code:
__int64 __fastcall foodf_pokey2_w(unsigned int a1, unsigned __int8 a2)
{
return pokey2_w(a1 >> 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1, unsigned __int8 a2)
{
return pokey2_w(a1 >> 1, a2);
}

original_code: void foodf_pokey2_w(offs_t offset,data_t data) { pokey2_w (offset/2, data & 0xff); }

canonical_original_code: void foodf_pokey2_w(unsigned int offset, unsigned int data) { pokey2_w (offset/2, data & 0xff); }


decompiled_code:
__int64 __fastcall foodf_pokey3_w(unsigned int a1, unsigned __int8 a2)
{
return pokey3_w(a1 >> 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1, unsigned __int8 a2)
{
return pokey3_w(a1 >> 1, a2);
}

original_code: void foodf_pokey3_w(offs_t offset,data_t data) { pokey3_w (offset/2, data & 0xff); }

canonical_original_code: void foodf_pokey3_w(unsigned int offset, unsigned int data) { pokey3_w (offset/2, data & 0xff); }


decompiled_code:
__int64 quantum_interrupt()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
int quantum_interrupt(void)
{
 return 1;
}

canonical_original_code:
int quantum_interrupt()
{
 return 1;
}


decompiled_code:
__int64 quantum_switches_r()
{
int v0; // ebx

v0 = input_port_0_r(0LL);
return v0 | (unsigned int)((unsigned int)avgdvg_done() != 0);
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx

v0 = input_port_0_r(0LL);
return v0 | (unsigned int)((unsigned int)avgdvg_done() != 0);
}

original_code:
data_t quantum_switches_r(offs_t offset)
{
 return (input_port_0_r(0) |
  (avgdvg_done() ? 1 : 0));
}

canonical_original_code:
unsigned int quantum_switches_r(unsigned int offset)
{
 return (input_port_0_r(0) |
  (avgdvg_done() ? 1 : 0));
}


decompiled_code:
__int64 __fastcall quantum_led_w(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 1);
osd_led_w(0LL, (a2 >> 4) & 1);
return osd_led_w(1LL, (a2 & 0x20) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 2);
coin_counter_w(1LL, a2 & 1);
osd_led_w(0LL, (a2 >> 4) & 1);
return osd_led_w(1LL, (a2 & 0x20) != 0);
}

original_code:
void quantum_led_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 1);
 osd_led_w(0,(data & 0x10) >> 4);
 osd_led_w(1,(data & 0x20) >> 5);
}

canonical_original_code:
void quantum_led_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 2);
 coin_counter_w(1,data & 1);
 osd_led_w(0,(data & 0x10) >> 4);
 osd_led_w(1,(data & 0x20) >> 5);
}


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

if ( (a1 & 0x20) != 0 )
result = pokey2_w((a1 >> 1) & 0xF);
else
result = pokey1_w((a1 >> 1) & 0xF);
return result;
}

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

if ( (a1 & 0x20) != 0 )
result = pokey2_w((a1 >> 1) & 0xF);
else
result = pokey1_w((a1 >> 1) & 0xF);
return result;
}

original_code:
void quantum_snd_w(offs_t offset,data_t data)
{
 if (offset & 0x20)
  pokey2_w((offset >> 1) % 0x10,data);
 else
  pokey1_w((offset >> 1) % 0x10,data);
}

canonical_original_code:
void quantum_snd_w(unsigned int offset, unsigned int data)
{
 if (offset & 0x20)
  pokey2_w((offset >> 1) % 0x10,data);
 else
  pokey1_w((offset >> 1) % 0x10,data);
}


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

if ( (a1 & 0x20) != 0 )
result = pokey2_r((a1 >> 1) & 0xF);
else
result = pokey1_r((a1 >> 1) & 0xF);
return result;
}

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

if ( (a1 & 0x20) != 0 )
result = pokey2_r((a1 >> 1) & 0xF);
else
result = pokey1_r((a1 >> 1) & 0xF);
return result;
}

original_code:
data_t quantum_snd_r(offs_t offset)
{
 if (offset & 0x20)
  return pokey2_r((offset >> 1) % 0x10);
 else
  return pokey1_r((offset >> 1) % 0x10);
}

canonical_original_code:
unsigned int quantum_snd_r(unsigned int offset)
{
 if (offset & 0x20)
  return pokey2_r((offset >> 1) % 0x10);
 else
  return pokey1_r((offset >> 1) % 0x10);
}


decompiled_code:
__int64 __fastcall quantum_trackball_r(unsigned int a1)
{
int v1; // ebx

v1 = input_port_4_r();
return 16 * v1 + (unsigned int)input_port_3_r(a1);
}

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

v1 = input_port_4_r();
return 16 * v1 + (unsigned int)input_port_3_r(a1);
}

original_code:
data_t quantum_trackball_r(offs_t offset)
{
 int x, y;
 x = input_port_4_r (offset);
 y = input_port_3_r (offset);
 return (x << 4) + y;
}

canonical_original_code:
unsigned int quantum_trackball_r(unsigned int offset)
{
 int x; int y;
 x = input_port_4_r (offset);
 y = input_port_3_r (offset);
 return (x << 4) + y;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall quantum_input_1_r(char a1)
{
return ((unsigned int)input_port_1_r(0LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return ((unsigned int)input_port_1_r(0LL) << (7 - a1)) & 0x80;
}

original_code:
data_t quantum_input_1_r(offs_t offset)
{
 return (input_port_1_r (0) << (7 - (offset - 0x00))) & 0x80;
}

canonical_original_code:
unsigned int quantum_input_1_r(unsigned int offset)
{
 return (input_port_1_r (0) << (7 - (offset - 0x00))) & 0x80;
}


decompiled_code:
__int64 __fastcall quantum_input_2_r(char a1)
{
return ((unsigned int)input_port_2_r(0LL) << (7 - a1)) & 0x80;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return ((unsigned int)input_port_2_r(0LL) << (7 - a1)) & 0x80;
}

original_code:
data_t quantum_input_2_r(offs_t offset)
{
 return (input_port_2_r (0) << (7 - (offset - 0x00))) & 0x80;
}

canonical_original_code:
unsigned int quantum_input_2_r(unsigned int offset)
{
 return (input_port_2_r (0) << (7 - (offset - 0x00))) & 0x80;
}


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

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

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

if ( a2 )
return EEPROM_save();
result = EEPROM_init(&eeprom_interface);
if ( a1 )
{
init_eeprom_count = 0;
result = EEPROM_load(a1);
}
else
{
init_eeprom_count = 10;
}
return result;
}

original_code:
void simpsons_nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}

canonical_original_code:
void simpsons_nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  EEPROM_save(file);
 else
 {
  EEPROM_init(&eeprom_interface);
  if (file)
  {
   init_eeprom_count = 0;
   EEPROM_load(file);
  }
  else
   init_eeprom_count = 10;
 }
}


decompiled_code:
__int64 simpsons_eeprom_r()
{
int v0; // ebx
int v1; // ebx

v0 = EEPROM_read_bit();
v1 = readinputport(5LL) & 1 | (16 * v0);
if ( init_eeprom_count )
{
--init_eeprom_count;
v1 &= 0xFEu;
}
return v1 | 0x20u;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
int v1; // ebx

v0 = EEPROM_read_bit();
v1 = readinputport(5LL) & 1 | (16 * v0);
if ( init_eeprom_count )
{
--init_eeprom_count;
v1 &= 0xFEu;
}
return v1 | 0x20u;
}

original_code:
data_t simpsons_eeprom_r(offs_t offset)
{
 int res;
 res = (EEPROM_read_bit() << 4);
 res |= 0x20;
 res |= readinputport( 5 ) & 1;
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xfe;
 }
 return res;
}

canonical_original_code:
unsigned int simpsons_eeprom_r(unsigned int offset)
{
 int res;
 res = (EEPROM_read_bit() << 4);
 res |= 0x20;
 res |= readinputport( 5 ) & 1;
 if (init_eeprom_count)
 {
  init_eeprom_count--;
  res &= 0xfe;
 }
 return res;
}

variable_types: res int


decompiled_code:
__int64 __fastcall simpsons_coin_counter_w(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
K052109_set_RMRD_line((a2 >> 3) & 1);
return K053246_set_OBJCHA_line(((unsigned __int8)(a2 >> 5) ^ 1) & 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
coin_counter_w(0LL, a2 & 1);
coin_counter_w(1LL, a2 & 2);
K052109_set_RMRD_line((a2 >> 3) & 1);
return K053246_set_OBJCHA_line(((unsigned __int8)(a2 >> 5) ^ 1) & 1);
}

original_code:
void simpsons_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x08) ? 1 : 0);
 K053246_set_OBJCHA_line((~data & 0x20) ? 1 : 0);
}

canonical_original_code:
void simpsons_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(0,data & 0x01);
 coin_counter_w(1,data & 0x02);
 K052109_set_RMRD_line((data & 0x08) ? 1 : 0);
 K053246_set_OBJCHA_line((~data & 0x20) ? 1 : 0);
}


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

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

original_code:
data_t simpsons_sound_interrupt_r(offs_t offset)
{
 cpu_cause_interrupt( 1, 0xff );
 return 0x00;
}

canonical_original_code:
unsigned int simpsons_sound_interrupt_r(unsigned int offset)
{
 cpu_cause_interrupt( 1, 0xff );
 return 0x00;
}


decompiled_code:
__int64 __fastcall simpsons_sound_r(int a1)
{
__int64 result; // rax
unsigned int v2; // edx

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
return K053260_r((unsigned int)(a1 + 2));
v2 = res_0 & 0xFC | ((_BYTE)res_0 + 1) & 3;
res_0 = v2;
if ( a1 )
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax
unsigned int v2; // edx

result = *(unsigned int *)(Machine + 836LL);
if ( (_DWORD)result )
return K053260_r((unsigned int)(a1 + 2));
v2 = res_0 & 0xFC | ((_BYTE)res_0 + 1) & 3;
res_0 = v2;
if ( a1 )
result = v2;
return result;
}

original_code:
data_t simpsons_sound_r(offs_t offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else
 {
  static int res = 0x80;
  res = (res & 0xfc) | ((res + 1) & 0x03);
  return offset ? res : 0x00;
 }
}

canonical_original_code:
unsigned int simpsons_sound_r(unsigned int offset)
{
 if (Machine->sample_rate != 0) return K053260_r(2 + offset);
 else
 {
  static int res = 0x80;
  res = (res & 0xfc) | ((res + 1) & 0x03);
  return offset ? res : 0x00;
 }
}


decompiled_code:
__int64 simpsons_speedup1_r()
{
_BYTE *v0; // rbx
__int64 result; // rax
int v2; // ebp

v0 = (_BYTE *)memory_region(129LL);
if ( v0[18538] )
{
if ( v0[18538] == 1 )
v0[18538] = 0;
result = (unsigned __int8)v0[18754];
}
else
{
v2 = (unsigned __int8)v0[18755] | ((unsigned __int8)v0[18754] << 8);
if ( (int)memory_region_length(129LL) <= v2 )
{
result = (unsigned __int8)v0[18754];
}
else
{
if ( ((unsigned __int8)v0[v2 + 1] | ((unsigned __int8)v0[v2] << 8)) == 0xFFFF )
cpu_spinuntil_int();
result = (unsigned __int8)v0[18754];
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
_BYTE *v0; // rbx
__int64 result; // rax
int v2; // ebp

v0 = (_BYTE *)memory_region(129LL);
if ( v0[18538] )
{
if ( v0[18538] == 1 )
v0[18538] = 0;
result = (unsigned __int8)v0[18754];
}
else
{
v2 = (unsigned __int8)v0[18755] | ((unsigned __int8)v0[18754] << 8);
if ( (int)memory_region_length(129LL) <= v2 )
{
result = (unsigned __int8)v0[18754];
}
else
{
if ( ((unsigned __int8)v0[v2 + 1] | ((unsigned __int8)v0[v2] << 8)) == 0xFFFF )
cpu_spinuntil_int();
result = (unsigned __int8)v0[18754];
}
}
return result;
}

original_code:
data_t simpsons_speedup1_r(offs_t offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int data1 = RAM[0x486a];
 if ( data1 == 0 )
 {
  int data2 = ( RAM[0x4942] << 8 ) | RAM[0x4943];
  if ( data2 < memory_region_length(REGION_CPU1) )
  {
   data2 = ( RAM[data2] << 8 ) | RAM[data2 + 1];
   if ( data2 == 0xffff )
    cpu_spinuntil_int();
   return RAM[0x4942];
  }
  return RAM[0x4942];
 }
 if ( data1 == 1 )
  RAM[0x486a]--;
 return RAM[0x4942];
}

canonical_original_code:
unsigned int simpsons_speedup1_r(unsigned int offset)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int data1 = RAM[0x486a];
 if ( data1 == 0 )
 {
  int data2 = ( RAM[0x4942] << 8 ) | RAM[0x4943];
  if ( data2 < memory_region_length(REGION_CPU1) )
  {
   data2 = ( RAM[data2] << 8 ) | RAM[data2 + 1];
   if ( data2 == 0xffff )
    cpu_spinuntil_int();
   return RAM[0x4942];
  }
  return RAM[0x4942];
 }
 if ( data1 == 1 )
  RAM[0x486a]--;
 return RAM[0x4942];
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 simpsons_speedup2_r()
{
unsigned __int8 v0; // bl

v0 = *(_BYTE *)(memory_region(129LL) + 18518);
if ( v0 == 1 )
cpu_spinuntil_int();
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned __int8 v0; // bl

v0 = *(_BYTE *)(memory_region(129LL) + 18518);
if ( v0 == 1 )
cpu_spinuntil_int();
return v0;
}

original_code:
data_t simpsons_speedup2_r(offs_t offset)
{
 int data = memory_region(REGION_CPU1)[0x4856];
 if ( data == 1 )
  cpu_spinuntil_int();
 return data;
}

canonical_original_code:
unsigned int simpsons_speedup2_r(unsigned int offset)
{
 int data = memory_region(REGION_CPU1)[0x4856];
 if ( data == 1 )
  cpu_spinuntil_int();
 return data;
}

variable_types: data int


decompiled_code:
void *__fastcall simpsons_banking(char a1)
{
__int64 v1; // rax
int v2; // edx
int v3; // ebx
void *result; // rax
unsigned int v5; // eax

v1 = memory_region(129LL);
v2 = a1 & 0xF0;
if ( v2 == 32 )
{
v3 = ((a1 & 0xF) + 40) << 13;
}
else if ( (a1 & 0xF0u) > 0x20 )
{
if ( v2 == 48 )
v3 = ((a1 & 0xF) + 56) << 13;
else
v3 = 0;
}
else if ( (a1 & 0xF0) != 0 )
{
if ( v2 == 16 )
v3 = ((a1 & 0xF) + 24) << 13;
else
v3 = 0;
}
else
{
v3 = ((a1 & 0xF) + 8) << 13;
}
cpu_bankbase[1] = v1 + v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func10(char a1)
{
__int64 v1; // rax
int v2; // edx
int v3; // ebx
void *result; // rax
unsigned int v5; // eax

v1 = memory_region(129LL);
v2 = a1 & 0xF0;
if ( v2 == 32 )
{
v3 = ((a1 & 0xF) + 40) << 13;
}
else if ( (a1 & 0xF0u) > 0x20 )
{
if ( v2 == 48 )
v3 = ((a1 & 0xF) + 56) << 13;
else
v3 = 0;
}
else if ( (a1 & 0xF0) != 0 )
{
if ( v2 == 16 )
v3 = ((a1 & 0xF) + 24) << 13;
else
v3 = 0;
}
else
{
v3 = ((a1 & 0xF) + 8) << 13;
}
cpu_bankbase[1] = v1 + v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

original_code:
static void simpsons_banking( int lines )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 switch ( lines & 0xf0 )
 {
  case 0x00:
   offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x10:
   offs = 0x30000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x20:
   offs = 0x50000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x30:
   offs = 0x70000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  default:
  break;
 }
 { 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 simpsons_banking(int lines)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 int offs = 0;
 switch ( lines & 0xf0 )
 {
  case 0x00:
   offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x10:
   offs = 0x30000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x20:
   offs = 0x50000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  case 0x30:
   offs = 0x70000 + ( ( lines & 0x0f ) * 0x2000 );
  break;
  default:
  break;
 }
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[offs]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: lines int

variable_types: offs int


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

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

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

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

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

canonical_original_code:
static void z80_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 offset = 0x10000 + ( ( ( data & 7 ) - 2 ) * 0x4000 );
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[ offset ]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

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

v0 = K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback);
result = 1LL;
if ( !v0 )
{
result = K053247_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback);
if ( (_DWORD)result )
{
K052109_vh_stop();
result = 1LL;
}
}
return result;
}

original_code:
int simpsons_vh_start( void )
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int simpsons_vh_start()
{
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K053247_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 simpsons_vh_stop()
{
K052109_vh_stop();
return K053247_vh_stop();
}

original_code:
void simpsons_vh_stop( void )
{
 K052109_vh_stop();
 K053247_vh_stop();
}

canonical_original_code:
void simpsons_vh_stop()
{
 K052109_vh_stop();
 K053247_vh_stop();
}


decompiled_code:
__int64 __fastcall simpsons_K052109_r(int a1)
{
return K052109_r((unsigned int)(a1 + 0x2000));
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1)
{
return K052109_r((unsigned int)(a1 + 0x2000));
}

original_code:
static data_t simpsons_K052109_r(offs_t offset)
{
 return K052109_r(offset + 0x2000);
}

canonical_original_code:
static unsigned int simpsons_K052109_r(unsigned int offset)
{
 return K052109_r(offset + 0x2000);
}


decompiled_code:
__int64 __fastcall simpsons_K052109_w(int a1)
{
return K052109_w((unsigned int)(a1 + 0x2000));
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1)
{
return K052109_w((unsigned int)(a1 + 0x2000));
}

original_code:
static void simpsons_K052109_w(offs_t offset,data_t data)
{
 K052109_w(offset + 0x2000,data);
}

canonical_original_code:
static void simpsons_K052109_w(unsigned int offset, unsigned int data)
{
 K052109_w(offset + 0x2000,data);
}


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

if ( a1 <= 0xFFF )
result = K053247_r();
else
result = *(unsigned __int8 *)(simpsons_xtraram + a1 - 4096);
return result;
}

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

if ( a1 <= 0xFFF )
result = K053247_r();
else
result = *(unsigned __int8 *)(simpsons_xtraram + a1 - 4096);
return result;
}

original_code:
static data_t simpsons_K053247_r(offs_t offset)
{
 if (offset < 0x1000) return K053247_r(offset);
 else return simpsons_xtraram[offset - 0x1000];
}

canonical_original_code:
static unsigned int simpsons_K053247_r(unsigned int offset)
{
 if (offset < 0x1000) return K053247_r(offset);
 else return simpsons_xtraram[offset - 0x1000];
}


decompiled_code:
__int64 __fastcall simpsons_vh_screenrefresh(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_90C = K053251_get_palette_index(3LL);
dword_910 = K053251_get_palette_index(4LL);
K052109_tilemap_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_8FC = K053251_get_priority(3LL);
v4 = 2;
dword_900 = K053251_get_priority(4LL);
sortlayers((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053247_sprites_draw(a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
unsigned int v2; // [rsp+4h] [rbp-14h] BYREF
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

bg_colorbase = K053251_get_palette_index(0LL);
sprite_colorbase = K053251_get_palette_index(1LL);
layer_colorbase[0] = K053251_get_palette_index(2LL);
dword_90C = K053251_get_palette_index(3LL);
dword_910 = K053251_get_palette_index(4LL);
K052109_tilemap_update();
palette_init_used_colors();
K053247_mark_sprites_colors();
*(_BYTE *)(palette_used_colors + 16 * bg_colorbase) |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
v2 = 0;
layerpri = K053251_get_priority(2LL);
v3 = 1;
dword_8FC = K053251_get_priority(3LL);
v4 = 2;
dword_900 = K053251_get_priority(4LL);
func2((int *)&v2, &layerpri);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 32LL * bg_colorbase), Machine + 776LL);
K052109_tilemap_draw(a1, v2, 0x10000LL);
K052109_tilemap_draw(a1, v3, 0x20000LL);
K052109_tilemap_draw(a1, v4, 0x40000LL);
return K053247_sprites_draw(a1);
}

original_code:
void simpsons_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI3);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI4);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053247_sprites_draw(bitmap);
}

canonical_original_code:
void simpsons_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int layer[3];
 bg_colorbase = K053251_get_palette_index(K053251_CI0);
 sprite_colorbase = K053251_get_palette_index(K053251_CI1);
 layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
 layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
 layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
 K052109_tilemap_update();
 palette_init_used_colors();
 K053247_mark_sprites_colors();
 palette_used_colors[16 * bg_colorbase] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 layer[0] = 0;
 layerpri[0] = K053251_get_priority(K053251_CI2);
 layer[1] = 1;
 layerpri[1] = K053251_get_priority(K053251_CI3);
 layer[2] = 2;
 layerpri[2] = K053251_get_priority(K053251_CI4);
 sortlayers(layer,layerpri);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[16 * bg_colorbase],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,layer[0],1<<16);
 K052109_tilemap_draw(bitmap,layer[1],2<<16);
 K052109_tilemap_draw(bitmap,layer[2],4<<16);
 K053247_sprites_draw(bitmap);
}

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

variable_types:
layer
int [3]


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

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

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

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


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

if ( (unsigned int)cpu_getiloops() )
{
v2 = K052109_is_IRQ_enabled();
result = 1LL;
if ( v2 )
return result;
return ignore_interrupt();
}
if ( !simpsons_firq_enabled )
return ignore_interrupt();
v1 = K053247_is_IRQ_enabled();
result = 2LL;
if ( !v1 )
return ignore_interrupt();
return result;
}

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

if ( (unsigned int)cpu_getiloops() )
{
v2 = K052109_is_IRQ_enabled();
result = 1LL;
if ( v2 )
return result;
return ignore_interrupt();
}
if ( !simpsons_firq_enabled )
return ignore_interrupt();
v1 = K053247_is_IRQ_enabled();
result = 2LL;
if ( !v1 )
return ignore_interrupt();
return result;
}

original_code:
static int simpsons_irq(void)
{
 if (cpu_getiloops() == 0)
 {
  if (simpsons_firq_enabled && K053247_is_IRQ_enabled())
   return 2;
 }
 else
 {
  if (K052109_is_IRQ_enabled())
   return 1;
 }
 return ignore_interrupt();
}

canonical_original_code:
static int simpsons_irq()
{
 if (cpu_getiloops() == 0)
 {
  if (simpsons_firq_enabled && K053247_is_IRQ_enabled())
   return 2;
 }
 else
 {
  if (K052109_is_IRQ_enabled())
   return 1;
 }
 return ignore_interrupt();
}


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

if ( (a1 & 1) != 0 )
{
cpu_setbankhandler_r(3LL, &paletteram_r);
cpu_setbankhandler_w(3LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
}
else
{
cpu_setbankhandler_r(3LL, &K052109_r);
cpu_setbankhandler_w(3LL, &K052109_w);
}
if ( (a1 & 2) != 0 )
{
cpu_setbankhandler_r(4LL, simpsons_K053247_r);
result = cpu_setbankhandler_w(4LL, simpsons_K053247_w);
}
else
{
cpu_setbankhandler_r(4LL, simpsons_K052109_r);
result = cpu_setbankhandler_w(4LL, simpsons_K052109_w);
}
return result;
}

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

if ( (a1 & 1) != 0 )
{
cpu_setbankhandler_r(3LL, &paletteram_r);
cpu_setbankhandler_w(3LL, &paletteram_xBBBBBGGGGGRRRRR_swap_w);
}
else
{
cpu_setbankhandler_r(3LL, &K052109_r);
cpu_setbankhandler_w(3LL, &K052109_w);
}
if ( (a1 & 2) != 0 )
{
cpu_setbankhandler_r(4LL, simpsons_K053247_r);
result = cpu_setbankhandler_w(4LL, simpsons_K053247_w);
}
else
{
cpu_setbankhandler_r(4LL, simpsons_K052109_r);
result = cpu_setbankhandler_w(4LL, simpsons_K052109_w);
}
return result;
}

original_code:
void simpsons_video_banking(int bank)
{
 if (bank & 1)
 {
  cpu_setbankhandler_r(3,paletteram_r);
  cpu_setbankhandler_w(3,paletteram_xBBBBBGGGGGRRRRR_swap_w);
 }
 else
 {
  cpu_setbankhandler_r(3,K052109_r);
  cpu_setbankhandler_w(3,K052109_w);
 }
 if (bank & 2)
 {
  cpu_setbankhandler_r(4,simpsons_K053247_r);
  cpu_setbankhandler_w(4,simpsons_K053247_w);
 }
 else
 {
  cpu_setbankhandler_r(4,simpsons_K052109_r);
  cpu_setbankhandler_w(4,simpsons_K052109_w);
 }
}

variable_types: bank int


decompiled_code:
__int64 simpsons_init_machine()
{
__int64 v0; // rax
unsigned int v2; // eax
unsigned int v3; // eax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = simpsons_banking;
paletteram = v0 + 557056;
simpsons_xtraram = v0 + 561152;
simpsons_firq_enabled[0] = 0;
cpu_bankbase[1] = v0 + 0x10000;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
cpu_setOPbase16(v2);
}
cpu_bankbase[2] = memory_region(130LL) + 0x10000;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
return simpsons_video_banking(0);
}

canonical_decompiled_code:
__int64 func24()
{
__int64 v0; // rax
unsigned int v2; // eax
unsigned int v3; // eax

v0 = memory_region(129LL);
konami_cpu_setlines_callback = simpsons_banking;
paletteram = v0 + 557056;
simpsons_xtraram = v0 + 561152;
simpsons_firq_enabled[0] = 0;
cpu_bankbase[1] = v0 + 0x10000;
if ( ophw == 1 )
{
ophw = -1;
v2 = cpu_get_pc();
cpu_setOPbase16(v2);
}
cpu_bankbase[2] = memory_region(130LL) + 0x10000;
if ( ophw == 2 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
return func23(0);
}

original_code:
void simpsons_init_machine( void )
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = simpsons_banking;
 paletteram = &RAM[0x88000];
 simpsons_xtraram = &RAM[0x89000];
 simpsons_firq_enabled = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 RAM = memory_region(REGION_CPU2);
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (UINT8 *)(&RAM[0x10000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 simpsons_video_banking( 0 );
}

canonical_original_code:
void simpsons_init_machine()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 konami_cpu_setlines_callback = simpsons_banking;
 paletteram = &RAM[0x88000];
 simpsons_xtraram = &RAM[0x89000];
 simpsons_firq_enabled = 0;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[0x10000]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 RAM = memory_region(REGION_CPU2);
 { if (2 >= 1 && 2 <= 16) { cpu_bankbase[2] = (unsigned char *)(&RAM[0x10000]); if (ophw == 2) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 simpsons_video_banking( 0 );
}


decompiled_code:
__int64 ccastles_bitmode_r()
{
char v0; // cl
int v1; // eax
unsigned int v2; // edx
char v3; // dl
char v4; // cl
int v5; // eax

v0 = *ccastles_screen_addr;
v1 = (*ccastles_screen_addr >> 1) | ((unsigned __int8)ccastles_screen_addr[1] << 7);
v2 = 0;
if ( (unsigned int)(v1 - 3072) <= 0x73FF )
{
if ( !*ccastles_screen_inc_enable )
{
v3 = v0 - 1;
v4 = v0 + 1;
if ( *ccastles_screen_inc )
v4 = v3;
*ccastles_screen_addr = v4;
}
if ( !ccastles_screen_inc_enable[1] )
{
if ( ccastles_screen_inc[1] )
--ccastles_screen_addr[1];
else
++ccastles_screen_addr[1];
}
v5 = v1 - 3072;
if ( (*ccastles_screen_addr & 1) != 0 )
v2 = (unsigned __int8)(16 * *(_BYTE *)(videoram + v5));
else
v2 = *(_BYTE *)(videoram + v5) & 0xF0;
}
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
char v0; // cl
int v1; // eax
unsigned int v2; // edx
char v3; // dl
char v4; // cl
int v5; // eax

v0 = *ccastles_screen_addr;
v1 = (*ccastles_screen_addr >> 1) | ((unsigned __int8)ccastles_screen_addr[1] << 7);
v2 = 0;
if ( (unsigned int)(v1 - 3072) <= 0x73FF )
{
if ( !*ccastles_screen_inc_enable )
{
v3 = v0 - 1;
v4 = v0 + 1;
if ( *ccastles_screen_inc )
v4 = v3;
*ccastles_screen_addr = v4;
}
if ( !ccastles_screen_inc_enable[1] )
{
if ( ccastles_screen_inc[1] )
--ccastles_screen_addr[1];
else
++ccastles_screen_addr[1];
}
v5 = v1 - 3072;
if ( (*ccastles_screen_addr & 1) != 0 )
v2 = (unsigned __int8)(16 * *(_BYTE *)(videoram + v5));
else
v2 = *(_BYTE *)(videoram + v5) & 0xF0;
}
return v2;
}

original_code:
data_t ccastles_bitmode_r(offs_t offset)
{
 int addr;
 addr = (ccastles_screen_addr[1]<<7) | (ccastles_screen_addr[0]>>1);
 if ((addr >= 0x0c00) && (addr < 0x8000))
 {
  if (!ccastles_screen_inc_enable[0])
  {
   if (!ccastles_screen_inc[0])
    ccastles_screen_addr[0] ++;
   else
    ccastles_screen_addr[0] --;
  }
  if (!ccastles_screen_inc_enable[1])
  {
   if (!ccastles_screen_inc[1])
    ccastles_screen_addr[1] ++;
   else
    ccastles_screen_addr[1] --;
  }
  addr -= 0xc00;
  if (ccastles_screen_addr[0] & 0x01)
   return ((videoram[addr] & 0x0f) << 4);
  else
   return (videoram[addr] & 0xf0);
 }
 return 0;
}

canonical_original_code:
unsigned int ccastles_bitmode_r(unsigned int offset)
{
 int addr;
 addr = (ccastles_screen_addr[1]<<7) | (ccastles_screen_addr[0]>>1);
 if ((addr >= 0x0c00) && (addr < 0x8000))
 {
  if (!ccastles_screen_inc_enable[0])
  {
   if (!ccastles_screen_inc[0])
    ccastles_screen_addr[0] ++;
   else
    ccastles_screen_addr[0] --;
  }
  if (!ccastles_screen_inc_enable[1])
  {
   if (!ccastles_screen_inc[1])
    ccastles_screen_addr[1] ++;
   else
    ccastles_screen_addr[1] --;
  }
  addr -= 0xc00;
  if (ccastles_screen_addr[0] & 0x01)
   return ((videoram[addr] & 0x0f) << 4);
  else
   return (videoram[addr] & 0xf0);
 }
 return 0;
}

variable_types: addr int


decompiled_code:
__int64 ccastles_vh_start()
{
unsigned int v0; // edx

tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v0 = 1;
if ( tmpbitmap )
{
maskbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( maskbitmap )
{
sprite_bm = bitmap_alloc(16LL, 16LL);
v0 = 0;
if ( !sprite_bm )
{
bitmap_free(maskbitmap);
bitmap_free(tmpbitmap);
v0 = 1;
}
}
else
{
bitmap_free(tmpbitmap);
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // edx

tmpbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
v0 = 1;
if ( tmpbitmap )
{
maskbitmap = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( maskbitmap )
{
sprite_bm = bitmap_alloc(16LL, 16LL);
v0 = 0;
if ( !sprite_bm )
{
bitmap_free(maskbitmap);
bitmap_free(tmpbitmap);
v0 = 1;
}
}
else
{
bitmap_free(tmpbitmap);
v0 = 1;
}
}
return v0;
}

original_code:
int ccastles_vh_start(void)
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((maskbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 if ((sprite_bm = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(maskbitmap);
  bitmap_free(tmpbitmap);
  return 1;
 }
 return 0;
}

canonical_original_code:
int ccastles_vh_start()
{
 if ((tmpbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  return 1;
 if ((maskbitmap = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  bitmap_free(tmpbitmap);
  return 1;
 }
 if ((sprite_bm = bitmap_alloc(16,16)) == 0)
 {
  bitmap_free(maskbitmap);
  bitmap_free(tmpbitmap);
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 ccastles_vh_stop()
{
bitmap_free(sprite_bm);
bitmap_free(maskbitmap);
return bitmap_free(tmpbitmap);
}

canonical_decompiled_code:
__int64 func4()
{
bitmap_free(sprite_bm);
bitmap_free(maskbitmap);
return bitmap_free(tmpbitmap);
}

original_code:
void ccastles_vh_stop(void)
{
 bitmap_free(sprite_bm);
 bitmap_free(maskbitmap);
 bitmap_free(tmpbitmap);
}

canonical_original_code:
void ccastles_vh_stop()
{
 bitmap_free(sprite_bm);
 bitmap_free(maskbitmap);
 bitmap_free(tmpbitmap);
}


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

v2 = memory_region(129LL);
if ( a2 )
{
cpu_bankbase[1] = v2 + 0x10000;
result = &ophw;
if ( ophw != 1 )
return result;
LABEL_6:
ophw = -1;
v4 = cpu_get_pc();
return (void *)cpu_setOPbase16(v4);
}
cpu_bankbase[1] = v2 + 40960;
result = &ophw;
if ( ophw == 1 )
goto LABEL_6;
return result;
}

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

v2 = memory_region(129LL);
if ( a2 )
{
cpu_bankbase[1] = v2 + 0x10000;
result = &ophw;
if ( ophw != 1 )
return result;
LABEL_6:
ophw = -1;
v4 = cpu_get_pc();
return (void *)cpu_setOPbase16(v4);
}
cpu_bankbase[1] = v2 + 40960;
result = &ophw;
if ( ophw == 1 )
goto LABEL_6;
return result;
}

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

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


decompiled_code:
__int64 __fastcall ccastles_coin_counter_w(int a1, int a2)
{
return coin_counter_w(a1 ^ 1u, (unsigned int)~a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return coin_counter_w(a1 ^ 1u, (unsigned int)~a2);
}

original_code:
static void ccastles_coin_counter_w(offs_t offset,data_t data)
{
 coin_counter_w(offset^1, ~data);
}

canonical_original_code:
static void ccastles_coin_counter_w(unsigned int offset, unsigned int data)
{
 coin_counter_w(offset^1, ~data);
}


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

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

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

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


decompiled_code:
_BYTE *redraw_bitmap()
{
char v0; // r15
char v1; // r14
int i; // er12
int j; // ebx
unsigned __int8 v4; // al
_BYTE *result; // rax
char v6; // [rsp+Eh] [rbp-3Ah]
char v7; // [rsp+Fh] [rbp-39h]

v0 = *ccastles_screen_addr;
v1 = ccastles_screen_addr[1];
v6 = *ccastles_screen_inc_enable;
v7 = ccastles_screen_inc_enable[1];
ccastles_screen_inc_enable[1] = 1;
*ccastles_screen_inc_enable = 1;
for ( i = 0; i != 256; ++i )
{
ccastles_screen_addr[1] = i;
for ( j = 0; j != 256; ++j )
{
*ccastles_screen_addr = j;
v4 = ccastles_bitmode_r(0LL);
ccastles_bitmode_w(0LL, v4);
}
}
*ccastles_screen_addr = v0;
ccastles_screen_addr[1] = v1;
*ccastles_screen_inc_enable = v6;
result = ccastles_screen_inc_enable;
ccastles_screen_inc_enable[1] = v7;
return result;
}

canonical_decompiled_code:
_BYTE *func1()
{
char v0; // r15
char v1; // r14
int i; // er12
int j; // ebx
unsigned __int8 v4; // al
_BYTE *result; // rax
char v6; // [rsp+Eh] [rbp-3Ah]
char v7; // [rsp+Fh] [rbp-39h]

v0 = *ccastles_screen_addr;
v1 = ccastles_screen_addr[1];
v6 = *ccastles_screen_inc_enable;
v7 = ccastles_screen_inc_enable[1];
ccastles_screen_inc_enable[1] = 1;
*ccastles_screen_inc_enable = 1;
for ( i = 0; i != 256; ++i )
{
ccastles_screen_addr[1] = i;
for ( j = 0; j != 256; ++j )
{
*ccastles_screen_addr = j;
v4 = func0(0LL);
ccastles_bitmode_w(0LL, v4);
}
}
*ccastles_screen_addr = v0;
ccastles_screen_addr[1] = v1;
*ccastles_screen_inc_enable = v6;
result = ccastles_screen_inc_enable;
ccastles_screen_inc_enable[1] = v7;
return result;
}

original_code:
static void redraw_bitmap(void)
{
 int x, y;
 int screen_addr0_save, screen_addr1_save, screen_inc_enable0_save, screen_inc_enable1_save;
 screen_addr0_save = ccastles_screen_addr[0];
 screen_addr1_save = ccastles_screen_addr[1];
 screen_inc_enable0_save = ccastles_screen_inc_enable[0];
 screen_inc_enable1_save = ccastles_screen_inc_enable[1];
 ccastles_screen_inc_enable[0] = ccastles_screen_inc_enable[1] = 1;
 for (y = 0; y < 256; y++)
 {
  ccastles_screen_addr[1] = y;
  for (x = 0; x < 256; x++)
  {
   ccastles_screen_addr[0] = x;
   ccastles_bitmode_w(0, ccastles_bitmode_r(0));
  }
 }
 ccastles_screen_addr[0] = screen_addr0_save;
 ccastles_screen_addr[1] = screen_addr1_save;
 ccastles_screen_inc_enable[0] = screen_inc_enable0_save;
 ccastles_screen_inc_enable[1] = screen_inc_enable1_save;
}

canonical_original_code:
static void redraw_bitmap()
{
 int x; int y;
 int screen_addr0_save; int screen_addr1_save; int screen_inc_enable0_save; int screen_inc_enable1_save;
 screen_addr0_save = ccastles_screen_addr[0];
 screen_addr1_save = ccastles_screen_addr[1];
 screen_inc_enable0_save = ccastles_screen_inc_enable[0];
 screen_inc_enable1_save = ccastles_screen_inc_enable[1];
 ccastles_screen_inc_enable[0] = ccastles_screen_inc_enable[1] = 1;
 for (y = 0; y < 256; y++)
 {
  ccastles_screen_addr[1] = y;
  for (x = 0; x < 256; x++)
  {
   ccastles_screen_addr[0] = x;
   ccastles_bitmode_w(0, ccastles_bitmode_r(0));
  }
 }
 ccastles_screen_addr[0] = screen_addr0_save;
 ccastles_screen_addr[1] = screen_addr1_save;
 ccastles_screen_inc_enable[0] = screen_inc_enable0_save;
 ccastles_screen_inc_enable[1] = screen_inc_enable1_save;
}


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

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

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

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

variable_types:
file
void *


decompiled_code:
void cchip1_init_machine()
{
dword_1D8 = 0;
dword_1D4 = 0;
cchip = 0;
cchip1_bank = 0;
}

canonical_decompiled_code:
void func0()
{
dword_1D8 = 0;
dword_1D4 = 0;
cchip = 0;
cchip1_bank = 0;
}

original_code:
void cchip1_init_machine(void)
{
 cchip[0] = cchip[1] = cchip[2] = 0;
 cchip1_bank = 0;
}

canonical_original_code:
void cchip1_init_machine()
{
 cchip[0] = cchip[1] = cchip[2] = 0;
 cchip1_bank = 0;
}


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

if ( a1 == 4 )
{
result = 128LL;
if ( cchip1_bank != 1 )
{
result = (unsigned int)dword_1D8;
if ( dword_1D8 )
dword_1D8 = 0;
else
result = readinputport(6LL);
}
}
else if ( a1 <= 4 )
{
if ( a1 )
{
if ( a1 != 2 )
{
LABEL_22:
result = 255LL;
if ( cchip1_bank == 1 )
result = cchip1_code[a1 >> 1];
return result;
}
result = 231LL;
if ( cchip1_bank != 1 )
{
result = (unsigned int)dword_1D4;
if ( dword_1D4 )
dword_1D4 = 0;
else
result = readinputport(5LL);
}
}
else
{
result = 72LL;
if ( cchip1_bank != 1 )
{
result = (unsigned int)cchip;
if ( cchip )
cchip = 0;
else
result = readinputport(4LL);
}
}
}
else
{
result = 1LL;
if ( a1 == 2050 )
return result;
if ( a1 == 3072 )
return (unsigned int)cchip1_bank;
result = 255LL;
if ( a1 <= 0x1EF )
goto LABEL_22;
}
return result;
}

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

if ( a1 == 4 )
{
result = 128LL;
if ( cchip1_bank != 1 )
{
result = (unsigned int)dword_1D8;
if ( dword_1D8 )
dword_1D8 = 0;
else
result = readinputport(6LL);
}
}
else if ( a1 <= 4 )
{
if ( a1 )
{
if ( a1 != 2 )
{
LABEL_22:
result = 255LL;
if ( cchip1_bank == 1 )
result = cchip1_code[a1 >> 1];
return result;
}
result = 231LL;
if ( cchip1_bank != 1 )
{
result = (unsigned int)dword_1D4;
if ( dword_1D4 )
dword_1D4 = 0;
else
result = readinputport(5LL);
}
}
else
{
result = 72LL;
if ( cchip1_bank != 1 )
{
result = (unsigned int)cchip;
if ( cchip )
cchip = 0;
else
result = readinputport(4LL);
}
}
}
else
{
result = 1LL;
if ( a1 == 2050 )
return result;
if ( a1 == 3072 )
return (unsigned int)cchip1_bank;
result = 255LL;
if ( a1 <= 0x1EF )
goto LABEL_22;
}
return result;
}

original_code:
data_t cchip1_r(offs_t offset)
{
 int ret = 0;
 switch (offset)
 {
  case 0x000:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[0])
    {
     ret = cchip[0];
     cchip[0] = 0;
    }
    else
     ret = readinputport (4);
   break;
  case 0x002:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[1])
    {
     ret = cchip[1];
     cchip[1] = 0;
    }
    else
     ret = readinputport (5);
   break;
  case 0x004:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[2])
    {
     ret = cchip[2];
     cchip[2] = 0;
    }
    else
     ret = readinputport (6);
   break;
  case 0x802:
   ret = 0x01;
   break;
  case 0xc00:
   ret = cchip1_bank;
   break;
  default:
   if (offset < 0x1f0 && cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
   {
    ret = 0xff;
   }
   break;
 }
 return ret;
}

canonical_original_code:
unsigned int cchip1_r(unsigned int offset)
{
 int ret = 0;
 switch (offset)
 {
  case 0x000:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[0])
    {
     ret = cchip[0];
     cchip[0] = 0;
    }
    else
     ret = readinputport (4);
   break;
  case 0x002:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[1])
    {
     ret = cchip[1];
     cchip[1] = 0;
    }
    else
     ret = readinputport (5);
   break;
  case 0x004:
   if (cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
    if (cchip[2])
    {
     ret = cchip[2];
     cchip[2] = 0;
    }
    else
     ret = readinputport (6);
   break;
  case 0x802:
   ret = 0x01;
   break;
  case 0xc00:
   ret = cchip1_bank;
   break;
  default:
   if (offset < 0x1f0 && cchip1_bank == 1)
    ret = cchip1_code[offset/2];
   else
   {
    ret = 0xff;
   }
   break;
 }
 return ret;
}

variable_types: ret int


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

if ( a1 == 4 )
{
result = 75LL;
if ( (_BYTE)a2 == 52 )
a2 = 75;
dword_1D8 = a2;
}
else if ( a1 > 4 )
{
if ( a1 == 3072 )
cchip1_bank = a2 & 7;
}
else if ( a1 )
{
if ( a1 == 2 )
{
result = 87LL;
if ( (_BYTE)a2 == 70 )
a2 = 87;
dword_1D4 = a2;
}
}
else
{
result = 71LL;
if ( (_BYTE)a2 == 74 )
a2 = 71;
cchip = a2;
}
return result;
}

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

if ( a1 == 4 )
{
result = 75LL;
if ( (_BYTE)a2 == 52 )
a2 = 75;
dword_1D8 = a2;
}
else if ( a1 > 4 )
{
if ( a1 == 3072 )
cchip1_bank = a2 & 7;
}
else if ( a1 )
{
if ( a1 == 2 )
{
result = 87LL;
if ( (_BYTE)a2 == 70 )
a2 = 87;
dword_1D4 = a2;
}
}
else
{
result = 71LL;
if ( (_BYTE)a2 == 74 )
a2 = 71;
cchip = a2;
}
return result;
}

original_code:
void cchip1_w(offs_t offset,data_t data)
{
 switch (offset)
 {
  case 0x0000:
   if ((data & 0xff) == 0x4a)
    cchip[0] = 0x47;
   else cchip[0] = data;
   break;
  case 0x0002:
   if ((data & 0xff) == 0x46)
    cchip[1] = 0x57;
   else cchip[1] = data;
   break;
  case 0x0004:
   if ((data & 0xff) == 0x34)
    cchip[2] = 0x4b;
   else cchip[2] = data;
   break;
  case 0xc00:
   cchip1_bank = data & 0x07;
   break;
  default:
   break;
 }
}

canonical_original_code:
void cchip1_w(unsigned int offset, unsigned int data)
{
 switch (offset)
 {
  case 0x0000:
   if ((data & 0xff) == 0x4a)
    cchip[0] = 0x47;
   else cchip[0] = data;
   break;
  case 0x0002:
   if ((data & 0xff) == 0x46)
    cchip[1] = 0x57;
   else cchip[1] = data;
   break;
  case 0x0004:
   if ((data & 0xff) == 0x34)
    cchip[2] = 0x4b;
   else cchip[2] = data;
   break;
  case 0xc00:
   cchip1_bank = data & 0x07;
   break;
  default:
   break;
 }
}


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

result = 1LL;
if ( a1 != 2050 )
result = *(unsigned __int8 *)(cchip_ram + a1);
return result;
}

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

result = 1LL;
if ( a1 != 2050 )
result = *(unsigned __int8 *)(cchip_ram + a1);
return result;
}

original_code:
data_t cchip2_r(offs_t offset)
{
    int ret = 0;
    switch (offset)
    {
        case 0x802:
            ret = 0x01;
            break;
        default:
            ret = cchip_ram[offset];
            break;
    }
    return ret;
}

canonical_original_code:
unsigned int cchip2_r(unsigned int offset)
{
    int ret = 0;
    switch (offset)
    {
        case 0x802:
            ret = 0x01;
            break;
        default:
            ret = cchip_ram[offset];
            break;
    }
    return ret;
}


decompiled_code:
void *__fastcall get_bgram0_tile_info(int a1)
{
int v1; // eax
int v2; // edx
unsigned __int8 v3; // di
__int64 v4; // rsi
int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

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

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

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

original_code:
static void get_bgram0_tile_info(int tile_index)
{
 int attr = xain_bgram0[tile_index | 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (xain_bgram0[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

canonical_original_code:
static void get_bgram0_tile_info(int tile_index)
{
 int attr = xain_bgram0[tile_index | 0x400];
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (xain_bgram0[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

variable_types: attr int

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


decompiled_code:
void *__fastcall get_bgram1_tile_info(int a1)
{
int v1; // eax
int v2; // edx
unsigned __int8 v3; // di
__int64 v4; // rsi
int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

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

canonical_decompiled_code:
void *__fastcall func2(int a1)
{
int v1; // eax
int v2; // edx
unsigned __int8 v3; // di
__int64 v4; // rsi
int v5; // edx
__int64 v6; // rax
int v7; // ecx
void *result; // rax

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

original_code:
static void get_bgram1_tile_info(int tile_index)
{
 int attr = xain_bgram1[tile_index | 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (xain_bgram1[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}

canonical_original_code:
static void get_bgram1_tile_info(int tile_index)
{
 int attr = xain_bgram1[tile_index | 0x400];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (xain_bgram1[tile_index] | ((attr & 7) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x70) >> 4)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (attr & 0x80) ? 0x01 : 0;
}


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

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

original_code:
data_t xain_sharedram_r(offs_t offset)
{
 return xain_sharedram[offset];
}

canonical_original_code:
unsigned int xain_sharedram_r(unsigned int offset)
{
 return xain_sharedram[offset];
}


canonical_decompiled_code:
__int64 func5()
{
return 77LL;
}

original_code:
static data_t xain_68705_r(offs_t offset)
{
 return 0x4d;
}

canonical_original_code:
static unsigned int xain_68705_r(unsigned int offset)
{
 return 0x4d;
}


canonical_decompiled_code:
void func6()
{
;
}

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

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