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

if ( pending )
{
plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned int)pending_x,
(unsigned int)pending_y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * pending_color));
*((_BYTE *)videoram + pending_x + screen_width * pending_y) = pending_color;
pending = 0;
}
result = (unsigned int)last_command;
if ( last_command == 16 )
{
y = a2;
}
else if ( last_command > 16 )
{
if ( last_command == 24 )
{
fillbitmap(*(_QWORD *)(Machine + 768LL), *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * a2), 0LL);
v3 = screen_width;
memset(videoram, a2, *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) * screen_width);
result = osd_mark_dirty(
0LL,
0LL,
(unsigned int)(v3 - 1),
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) - 1),
0LL);
}
}
else if ( last_command )
{
if ( last_command == 8 )
x = a2;
}
else
{
switch ( (unsigned __int8)a2 >> 4 )
{
case 0:
case 4:
case 8:
case 12:
break;
case 1:
case 9:
++x;
break;
case 2:
case 6:
++y;
break;
case 3:
++x;
++y;
break;
case 5:
case 13:
--x;
break;
case 7:
--x;
++y;
break;
case 10:
case 14:
--y;
break;
case 11:
++x;
--y;
break;
case 15:
--x;
--y;
break;
}
x = (unsigned __int8)x;
result = (unsigned __int8)y;
y = result;
pending = 1;
pending_x = (unsigned __int8)x;
pending_y = result;
pending_color = a2 & 0xF;
}
return result;
}

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

if ( pending )
{
plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned int)pending_x,
(unsigned int)pending_y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * pending_color));
*((_BYTE *)videoram + pending_x + screen_width * pending_y) = pending_color;
pending = 0;
}
result = (unsigned int)last_command;
if ( last_command == 16 )
{
y = a2;
}
else if ( last_command > 16 )
{
if ( last_command == 24 )
{
fillbitmap(*(_QWORD *)(Machine + 768LL), *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * a2), 0LL);
v3 = screen_width;
memset(videoram, a2, *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) * screen_width);
result = osd_mark_dirty(
0LL,
0LL,
(unsigned int)(v3 - 1),
(unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) - 1),
0LL);
}
}
else if ( last_command )
{
if ( last_command == 8 )
x = a2;
}
else
{
switch ( (unsigned __int8)a2 >> 4 )
{
case 0:
case 4:
case 8:
case 12:
break;
case 1:
case 9:
++x;
break;
case 2:
case 6:
++y;
break;
case 3:
++x;
++y;
break;
case 5:
case 13:
--x;
break;
case 7:
--x;
++y;
break;
case 10:
case 14:
--y;
break;
case 11:
++x;
--y;
break;
case 15:
--x;
--y;
break;
}
x = (unsigned __int8)x;
result = (unsigned __int8)y;
y = result;
pending = 1;
pending_x = (unsigned __int8)x;
pending_y = result;
pending_color = a2 & 0xF;
}
return result;
}

original_code:
void leprechn_graphics_data_w(offs_t offset,data_t data)
{
    int direction;
    if (pending)
    {
  plot_pixel(Machine->scrbitmap, pending_x, pending_y, Machine->pens[pending_color]);
        videoram[pending_y * screen_width + pending_x] = pending_color;
        pending = 0;
    }
    switch (last_command)
    {
    case 0x00:
        direction = (data & 0xf0) >> 4;
        switch (direction)
        {
        case 0x00:
        case 0x04:
        case 0x08:
        case 0x0c:
            break;
        case 0x01:
        case 0x09:
            x++;
            break;
        case 0x02:
        case 0x06:
            y++;
            break;
        case 0x03:
            x++;
            y++;
            break;
        case 0x05:
        case 0x0d:
            x--;
            break;
        case 0x07:
            x--;
            y++;
            break;
        case 0x0a:
        case 0x0e:
            y--;
            break;
        case 0x0b:
            x++;
            y--;
            break;
        case 0x0f:
            x--;
            y--;
            break;
        }
        x = x & 0xff;
        y = y & 0xff;
        pending = 1;
        pending_x = x;
        pending_y = y;
        pending_color = data & 0x0f;
        return;
    case 0x08:
        x = data;
        return;
    case 0x10:
        y = data;
        return;
    case 0x18:
        fillbitmap(Machine->scrbitmap,Machine->pens[data],0);
        memset(videoram, data, screen_width * Machine->drv->screen_height);
        osd_mark_dirty(0,0,screen_width-1,Machine->drv->screen_height-1,0);
        return;
    }
}

canonical_original_code:
void leprechn_graphics_data_w(unsigned int offset, unsigned int data)
{
    int direction;
    if (pending)
    {
  plot_pixel(Machine->scrbitmap, pending_x, pending_y, Machine->pens[pending_color]);
        videoram[pending_y * screen_width + pending_x] = pending_color;
        pending = 0;
    }
    switch (last_command)
    {
    case 0x00:
        direction = (data & 0xf0) >> 4;
        switch (direction)
        {
        case 0x00:
        case 0x04:
        case 0x08:
        case 0x0c:
            break;
        case 0x01:
        case 0x09:
            x++;
            break;
        case 0x02:
        case 0x06:
            y++;
            break;
        case 0x03:
            x++;
            y++;
            break;
        case 0x05:
        case 0x0d:
            x--;
            break;
        case 0x07:
            x--;
            y++;
            break;
        case 0x0a:
        case 0x0e:
            y--;
            break;
        case 0x0b:
            x++;
            y--;
            break;
        case 0x0f:
            x--;
            y--;
            break;
        }
        x = x & 0xff;
        y = y & 0xff;
        pending = 1;
        pending_x = x;
        pending_y = y;
        pending_color = data & 0x0f;
        return;
    case 0x08:
        x = data;
        return;
    case 0x10:
        y = data;
        return;
    case 0x18:
        fillbitmap(Machine->scrbitmap,Machine->pens[data],0);
        memset(videoram, data, screen_width * Machine->drv->screen_height);
        osd_mark_dirty(0,0,screen_width-1,Machine->drv->screen_height-1,0);
        return;
    }
}

variable_types: direction int


decompiled_code:
__int64 leprechn_vh_start()
{
__int64 v0; // rax

v0 = *(_QWORD *)(Machine + 824LL);
screen_width = *(_DWORD *)(v0 + 664);
videoram = malloc(*(_DWORD *)(v0 + 668) * screen_width);
if ( !videoram )
return 1LL;
pending = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax

v0 = *(_QWORD *)(Machine + 824LL);
screen_width = *(_DWORD *)(v0 + 664);
videoram = malloc(*(_DWORD *)(v0 + 668) * screen_width);
if ( !videoram )
return 1LL;
pending = 0;
return 0LL;
}

original_code:
int leprechn_vh_start(void)
{
    screen_width = Machine->drv->screen_width;
    if ((videoram = (unsigned char*)malloc(screen_width*Machine->drv->screen_height)) == 0)
    {
        return 1;
    }
    pending = 0;
    return 0;
}

canonical_original_code:
int leprechn_vh_start()
{
    screen_width = Machine->drv->screen_width;
    if ((videoram = (unsigned char *)malloc(screen_width*Machine->drv->screen_height)) == 0)
    {
        return 1;
    }
    pending = 0;
    return 0;
}

return_type: int


decompiled_code:
void leprechn_vh_stop()
{
free(videoram);
}

canonical_decompiled_code:
void func9()
{
free(videoram);
}

original_code:
void leprechn_vh_stop(void)
{
    free(videoram);
}

return_type: void


decompiled_code:
__int64 leprechn_sh_w()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func10()
{
soundlatch_w();
return cpu_cause_interrupt(1LL, 1LL);
}

original_code:
static void leprechn_sh_w(offs_t offset,data_t data)
{
    soundlatch_w(offset,data);
    cpu_cause_interrupt(1,1);
}

canonical_original_code:
static void leprechn_sh_w(unsigned int offset, unsigned int data)
{
    soundlatch_w(offset,data);
    cpu_cause_interrupt(1,1);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

if ( input_port_select == 8 )
return input_port_1_r(0LL);
if ( (unsigned __int8)input_port_select > 8u )
{
if ( input_port_select == 64 )
{
result = input_port_5_r(0LL);
}
else if ( input_port_select == (char)0x80 )
{
result = input_port_4_r(0LL);
}
else
{
result = 255LL;
}
}
else
{
switch ( input_port_select )
{
case 2:
result = input_port_2_r(0LL);
break;
case 4:
result = input_port_3_r(0LL);
break;
case 1:
result = input_port_0_r(0LL);
break;
default:
result = 255LL;
break;
}
}
return result;
}

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

if ( input_port_select == 8 )
return input_port_1_r(0LL);
if ( (unsigned __int8)input_port_select > 8u )
{
if ( input_port_select == 64 )
{
result = input_port_5_r(0LL);
}
else if ( input_port_select == (char)0x80 )
{
result = input_port_4_r(0LL);
}
else
{
result = 255LL;
}
}
else
{
switch ( input_port_select )
{
case 2:
result = input_port_2_r(0LL);
break;
case 4:
result = input_port_3_r(0LL);
break;
case 1:
result = input_port_0_r(0LL);
break;
default:
result = 255LL;
break;
}
}
return result;
}

original_code:
static data_t leprechn_input_port_r(offs_t offset)
{
    switch (input_port_select)
    {
    case 0x01:
        return input_port_0_r(0);
    case 0x02:
        return input_port_2_r(0);
    case 0x04:
        return input_port_3_r(0);
    case 0x08:
        return input_port_1_r(0);
    case 0x40:
        return input_port_5_r(0);
    case 0x80:
        return input_port_4_r(0);
    }
    return 0xff;
}

canonical_original_code:
static unsigned int leprechn_input_port_r(unsigned int offset)
{
    switch (input_port_select)
    {
    case 0x01:
        return input_port_0_r(0);
    case 0x02:
        return input_port_2_r(0);
    case 0x04:
        return input_port_3_r(0);
    case 0x08:
        return input_port_1_r(0);
    case 0x40:
        return input_port_5_r(0);
    case 0x80:
        return input_port_4_r(0);
    }
    return 0xff;
}

return_type: unsigned int


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

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

original_code:
data_t qix_sharedram_r(offs_t offset)
{
 return qix_sharedram[offset];
}

canonical_original_code:
unsigned int qix_sharedram_r(unsigned int offset)
{
 return qix_sharedram[offset];
}


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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
void __fastcall sdungeon_68705_portB_w(__int64 a1, char a2)
{
portB_out = a2;
}

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

original_code:
void sdungeon_68705_portB_w(offs_t offset,data_t data)
{
 portB_out = data;
}

canonical_original_code:
void sdungeon_68705_portB_w(unsigned int offset, unsigned int data)
{
 portB_out = data;
}


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

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

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

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


decompiled_code:
void __fastcall sdungeon_68705_portC_w(__int64 a1, char a2)
{
portC_out = a2;
}

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

original_code:
void sdungeon_68705_portC_w(offs_t offset,data_t data)
{
 portC_out = data;
}

canonical_original_code:
void sdungeon_68705_portC_w(unsigned int offset, unsigned int data)
{
 portC_out = data;
}


decompiled_code:
void __fastcall sdungeon_68705_ddrC_w(__int64 a1, char a2)
{
ddrC = a2;
}

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

original_code:
void sdungeon_68705_ddrC_w(offs_t offset,data_t data)
{
 ddrC = data;
}

canonical_original_code:
void sdungeon_68705_ddrC_w(unsigned int offset, unsigned int data)
{
 ddrC = data;
}


decompiled_code:
__int64 sdungeon_coin_r()
{
return (unsigned __int8)portA_out;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)portA_out;
}

original_code:
data_t sdungeon_coin_r(offs_t offset)
{
 return portA_out;
}

canonical_original_code:
unsigned int sdungeon_coin_r(unsigned int offset)
{
 return portA_out;
}


decompiled_code:
void __fastcall sdungeon_coin_w(__int64 a1, char a2)
{
portA_in = a2;
}

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

original_code:
static void sdungeon_coin_w(offs_t offset,data_t data)
{
 portA_in = data;
}

canonical_original_code:
static void sdungeon_coin_w(unsigned int offset, unsigned int data)
{
 portA_in = data;
}


decompiled_code:
__int64 __fastcall qix_videoram_r(int a1)
{
return *(unsigned __int8 *)(videoram + a1 + ((unsigned __int8)(*qix_videoaddress & 0x80) << 8));
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return *(unsigned __int8 *)(videoram + a1 + ((unsigned __int8)(*qix_videoaddress & 0x80) << 8));
}

original_code:
data_t qix_videoram_r(offs_t offset)
{
 offset += (qix_videoaddress[0] & 0x80) * 0x100;
 return videoram[offset];
}

canonical_original_code:
unsigned int qix_videoram_r(unsigned int offset)
{
 offset += (qix_videoaddress[0] & 0x80) * 0x100;
 return videoram[offset];
}


decompiled_code:
__int64 qix_addresslatch_r()
{
return *(unsigned __int8 *)(videoram + (unsigned __int8)qix_videoaddress[1]
+ ((unsigned __int8)*qix_videoaddress << 8));
}

canonical_decompiled_code:
__int64 func13()
{
return *(unsigned __int8 *)(videoram + (unsigned __int8)qix_videoaddress[1]
+ ((unsigned __int8)*qix_videoaddress << 8));
}

original_code:
data_t qix_addresslatch_r(offs_t offset)
{
 offset = qix_videoaddress[0] * 0x100 + qix_videoaddress[1];
 return videoram[offset];
}

canonical_original_code:
unsigned int qix_addresslatch_r(unsigned int offset)
{
 offset = qix_videoaddress[0] * 0x100 + qix_videoaddress[1];
 return videoram[offset];
}


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

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
{
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 func15(__int64 a1, char a2)
{
__int64 v2; // rax
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
{
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:
void zoo_bankswitch_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 0x04) { 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:
void zoo_bankswitch_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 if (data & 0x04) { 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()); } } };
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 qix_video_firq_w()
{
return cpu_cause_interrupt(1LL, 2LL);
}

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

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

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


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

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

original_code:
void qix_data_firq_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(0,2);
}

canonical_original_code:
void qix_data_firq_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(0,2);
}


decompiled_code:
__int64 qix_scanline_r()
{
return (unsigned __int8)(cpu_scalebyfcount(256LL) + 80);
}

canonical_decompiled_code:
__int64 func18()
{
return (unsigned __int8)(cpu_scalebyfcount(256LL) + 80);
}

original_code:
data_t qix_scanline_r(offs_t offset)
{
 return (cpu_scalebyfcount(256) + 80) & 0xff;
}

canonical_original_code:
unsigned int qix_scanline_r(unsigned int offset)
{
 return (cpu_scalebyfcount(256) + 80) & 0xff;
}


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

suspended = 0;
pia_unconfig();
pia_config(0LL, 0LL, &qixmcu_pia_0_intf);
pia_config(1LL, 0LL, &qix_pia_1_intf);
pia_config(2LL, 0LL, &qixmcu_pia_2_intf);
pia_config(3LL, 0LL, &qix_pia_3_intf);
pia_config(4LL, 0LL, qix_pia_4_intf);
pia_config(5LL, 0LL, &qix_pia_5_intf);
result = pia_reset();
sdungeon_coinctrl = 0;
return result;
}

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

suspended = 0;
pia_unconfig();
pia_config(0LL, 0LL, &qixmcu_pia_0_intf);
pia_config(1LL, 0LL, &qix_pia_1_intf);
pia_config(2LL, 0LL, &qixmcu_pia_2_intf);
pia_config(3LL, 0LL, &qix_pia_3_intf);
pia_config(4LL, 0LL, qix_pia_4_intf);
pia_config(5LL, 0LL, &qix_pia_5_intf);
result = pia_reset();
sdungeon_coinctrl = 0;
return result;
}

original_code:
void withmcu_init_machine(void)
{
 suspended = 0;
 pia_unconfig();
 pia_config(0, 0 | 0, &qixmcu_pia_0_intf);
 pia_config(1, 0 | 0, &qix_pia_1_intf);
 pia_config(2, 0 | 0, &qixmcu_pia_2_intf);
 pia_config(3, 0 | 0, &qix_pia_3_intf);
 pia_config(4, 0 | 0, &qix_pia_4_intf);
 pia_config(5, 0 | 0, &qix_pia_5_intf);
 pia_reset();
 sdungeon_coinctrl = 0x00;
}

canonical_original_code:
void withmcu_init_machine()
{
 suspended = 0;
 pia_unconfig();
 pia_config(0, 0 | 0, &qixmcu_pia_0_intf);
 pia_config(1, 0 | 0, &qix_pia_1_intf);
 pia_config(2, 0 | 0, &qixmcu_pia_2_intf);
 pia_config(3, 0 | 0, &qix_pia_3_intf);
 pia_config(4, 0 | 0, &qix_pia_4_intf);
 pia_config(5, 0 | 0, &qix_pia_5_intf);
 pia_reset();
 sdungeon_coinctrl = 0x00;
}


decompiled_code:
__int64 zoo_init_machine()
{
return withmcu_init_machine();
}

canonical_decompiled_code:
__int64 func20()
{
return func19();
}

original_code:
void zoo_init_machine(void)
{
 withmcu_init_machine();
}

canonical_original_code:
void zoo_init_machine()
{
 withmcu_init_machine();
}


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

suspended = 0;
pia_unconfig();
pia_config(0LL, 0LL, &qix_pia_0_intf);
pia_config(1LL, 0LL, &qix_pia_1_intf);
pia_config(2LL, 0LL, &qix_pia_2_intf);
pia_config(3LL, 0LL, &qix_pia_3_intf);
pia_config(4LL, 0LL, qix_pia_4_intf);
pia_config(5LL, 0LL, &qix_pia_5_intf);
result = pia_reset();
sdungeon_coinctrl = 0;
return result;
}

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

suspended = 0;
pia_unconfig();
pia_config(0LL, 0LL, &qix_pia_0_intf);
pia_config(1LL, 0LL, &qix_pia_1_intf);
pia_config(2LL, 0LL, &qix_pia_2_intf);
pia_config(3LL, 0LL, &qix_pia_3_intf);
pia_config(4LL, 0LL, qix_pia_4_intf);
pia_config(5LL, 0LL, &qix_pia_5_intf);
result = pia_reset();
sdungeon_coinctrl = 0;
return result;
}

original_code:
void qix_init_machine(void)
{
 suspended = 0;
 pia_unconfig();
 pia_config(0, 0 | 0, &qix_pia_0_intf);
 pia_config(1, 0 | 0, &qix_pia_1_intf);
 pia_config(2, 0 | 0, &qix_pia_2_intf);
 pia_config(3, 0 | 0, &qix_pia_3_intf);
 pia_config(4, 0 | 0, &qix_pia_4_intf);
 pia_config(5, 0 | 0, &qix_pia_5_intf);
 pia_reset();
 sdungeon_coinctrl = 0x00;
}

canonical_original_code:
void qix_init_machine()
{
 suspended = 0;
 pia_unconfig();
 pia_config(0, 0 | 0, &qix_pia_0_intf);
 pia_config(1, 0 | 0, &qix_pia_1_intf);
 pia_config(2, 0 | 0, &qix_pia_2_intf);
 pia_config(3, 0 | 0, &qix_pia_3_intf);
 pia_config(4, 0 | 0, &qix_pia_4_intf);
 pia_config(5, 0 | 0, &qix_pia_5_intf);
 pia_reset();
 sdungeon_coinctrl = 0x00;
}


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

if ( a1 )
{
cpu_cause_interrupt(2LL, 1LL);
cpu_yielduntil_trigger(500LL);
suspended = 1;
result = cpu_triggertime(107374LL, 500LL);
}
return result;
}

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

if ( a1 )
{
cpu_cause_interrupt(2LL, 1LL);
cpu_yielduntil_trigger(500LL);
suspended = 1;
result = cpu_triggertime(107374LL, 500LL);
}
return result;
}

original_code:
static void qix_pia_sint (int state)
{
 if (state)
 {
  cpu_cause_interrupt (2, 1);
  cpu_yielduntil_trigger (500);
  suspended = 1;
  cpu_triggertime (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)), 500);
 }
}

canonical_original_code:
static void qix_pia_sint(int state)
{
 if (state)
 {
  cpu_cause_interrupt (2, 1);
  cpu_yielduntil_trigger (500);
  suspended = 1;
  cpu_triggertime (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)), 500);
 }
}

variable_types: state int


decompiled_code:
__int64 qix_dac_w()
{
return DAC_data_w(0LL);
}

canonical_decompiled_code:
__int64 func23()
{
return DAC_data_w(0LL);
}

original_code:
static void qix_dac_w(offs_t offset,data_t data)
{
 DAC_data_w (0, data);
}

canonical_original_code:
static void qix_dac_w(unsigned int offset, unsigned int data)
{
 DAC_data_w (0, data);
}


decompiled_code:
__int64 __fastcall qix_sound_r(unsigned int a1)
{
if ( suspended )
{
timer_trigger(500LL);
cpu_yielduntil_time(107374LL);
suspended = 0;
}
return pia_4_porta_r(a1);
}

canonical_decompiled_code:
__int64 __fastcall func24(unsigned int a1)
{
if ( suspended )
{
timer_trigger(500LL);
cpu_yielduntil_time(107374LL);
suspended = 0;
}
return pia_4_porta_r(a1);
}

original_code:
data_t qix_sound_r(offs_t offset)
{
 if (suspended)
 {
  timer_trigger (500);
  cpu_yielduntil_time (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)));
  suspended = 0;
 }
 return pia_4_porta_r (offset);
}

canonical_original_code:
unsigned int qix_sound_r(unsigned int offset)
{
 if (suspended)
 {
  timer_trigger (500);
  cpu_yielduntil_time (((timer_tm)(((float)(100)*(float)((1<<30)))/(float)1000000)));
  suspended = 0;
 }
 return pia_4_porta_r (offset);
}


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

if ( (a2 & 4) != 0 )
{
cpu_set_irq_line(3LL, 0LL, 1LL);
result = cpu_spinuntil_time(53687LL);
}
else
{
result = cpu_set_irq_line(3LL, 0LL, 0LL);
}
sdungeon_coinctrl = a2;
return result;
}

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

if ( (a2 & 4) != 0 )
{
cpu_set_irq_line(3LL, 0LL, 1LL);
result = cpu_spinuntil_time(53687LL);
}
else
{
result = cpu_set_irq_line(3LL, 0LL, 0LL);
}
sdungeon_coinctrl = a2;
return result;
}

original_code:
static void sdungeon_coinctrl_w(offs_t offset,data_t data)
{
 if (data & 0x04)
 {
  cpu_set_irq_line(3,0,1);
  cpu_spinuntil_time(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)));
 }
 else
  cpu_set_irq_line(3,0,0);
 sdungeon_coinctrl = data;
}

canonical_original_code:
static void sdungeon_coinctrl_w(unsigned int offset, unsigned int data)
{
 if (data & 0x04)
 {
  cpu_set_irq_line(3,0,1);
  cpu_spinuntil_time(((timer_tm)(((float)(50)*(float)((1<<30)))/(float)1000000)));
 }
 else
  cpu_set_irq_line(3,0,0);
 sdungeon_coinctrl = data;
}


decompiled_code:
__int64 sdungeon_68705_portB_r()
{
portB_in = input_port_1_r(0LL) & 0xF;
portB_in |= ((unsigned int)input_port_1_r(0LL) >> 3) & 0x10;
return (unsigned __int8)(portB_out & ddrB) | (unsigned int)(unsigned __int8)(~ddrB & portB_in);
}

canonical_decompiled_code:
__int64 func26()
{
portB_in = input_port_1_r(0LL) & 0xF;
portB_in |= ((unsigned int)input_port_1_r(0LL) >> 3) & 0x10;
return (unsigned __int8)(portB_out & ddrB) | (unsigned int)(unsigned __int8)(~ddrB & portB_in);
}

original_code:
data_t sdungeon_68705_portB_r(offs_t offset)
{
 portB_in = input_port_1_r(0) & 0x0F;
 portB_in = portB_in | ((input_port_1_r(0) & 0x80) >> 3);
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}

canonical_original_code:
unsigned int sdungeon_68705_portB_r(unsigned int offset)
{
 portB_in = input_port_1_r(0) & 0x0F;
 portB_in = portB_in | ((input_port_1_r(0) & 0x80) >> 3);
 return (portB_out & ddrB) | (portB_in & ~ddrB);
}


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

v0 = ~(_BYTE)sdungeon_coinctrl & 8;
return (unsigned __int8)(portC_out & ddrC) | ~(unsigned __int8)ddrC & (unsigned int)(unsigned __int8)(v0 | ((unsigned int)input_port_1_r(0LL) >> 4) & 7);
}

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

v0 = ~(_BYTE)sdungeon_coinctrl & 8;
return (unsigned __int8)(portC_out & ddrC) | ~(unsigned __int8)ddrC & (unsigned int)(unsigned __int8)(v0 | ((unsigned int)input_port_1_r(0LL) >> 4) & 7);
}

original_code:
data_t sdungeon_68705_portC_r(offs_t offset)
{
 portC_in = (~sdungeon_coinctrl & 0x08) | ((input_port_1_r(0) & 0x70) >> 4);
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}

canonical_original_code:
unsigned int sdungeon_68705_portC_r(unsigned int offset)
{
 portC_in = (~sdungeon_coinctrl & 0x08) | ((input_port_1_r(0) & 0x70) >> 4);
 return (portC_out & ddrC) | (portC_in & ~ddrC);
}


decompiled_code:
__int64 __fastcall sdungeon_pia_0_w(int a1, unsigned int a2)
{
if ( !a1 )
a2 = 0;
return timer_set(0LL, (a1 << 8) | a2, pia_0_w_callback);
}

canonical_decompiled_code:
__int64 __fastcall func28(int a1, unsigned int a2)
{
if ( !a1 )
a2 = 0;
return timer_set(0LL, (a1 << 8) | a2, pia_0_w_callback);
}

original_code:
void sdungeon_pia_0_w(offs_t offset,data_t data)
{
 if (offset == 0) data = 0;
 timer_set((0),data | (offset << 8),pia_0_w_callback);
}

canonical_original_code:
void sdungeon_pia_0_w(unsigned int offset, unsigned int data)
{
 if (offset == 0) data = 0;
 timer_set((0),data | (offset << 8),pia_0_w_callback);
}


decompiled_code:
__int64 __fastcall pia_0_w_callback(int a1)
{
return pia_0_w((unsigned int)(a1 >> 8), (unsigned __int8)a1);
}

canonical_decompiled_code:
__int64 __fastcall func29(int a1)
{
return pia_0_w((unsigned int)(a1 >> 8), (unsigned __int8)a1);
}

original_code:
static void pia_0_w_callback(int param)
{
 pia_0_w(param >> 8,param & 0xff);
}

variable_types: param int


decompiled_code:
_BOOL8 qix_vh_start()
{
videoram = malloc(0x10000uLL);
return videoram == 0LL;
}

canonical_decompiled_code:
_BOOL8 func30()
{
videoram = malloc(0x10000uLL);
return videoram == 0LL;
}

original_code:
int qix_vh_start(void)
{
 if ((videoram = (unsigned char*)malloc(256*256)) == 0)
  return 1;
 return 0;
}

canonical_original_code:
int qix_vh_start()
{
 if ((videoram = (unsigned char *)malloc(256*256)) == 0)
  return 1;
 return 0;
}


decompiled_code:
void qix_vh_stop()
{
free(videoram);
videoram = 0LL;
}

canonical_decompiled_code:
void func31()
{
free(videoram);
videoram = 0LL;
}

original_code:
void qix_vh_stop(void)
{
 free(videoram);
 videoram = 0;
}

canonical_original_code:
void qix_vh_stop()
{
 free(videoram);
 videoram = 0;
}


decompiled_code:
__int64 __fastcall update_pen(__int64 a1, unsigned int a2)
{
return palette_change_color(
a1,
table_0[a2 & 3 | (a2 >> 4) & 0xC],
table_0[a2 & 3 | (a2 >> 2) & 0xC],
table_0[a2 & 0xF]);
}

canonical_decompiled_code:
__int64 __fastcall func32(__int64 a1, unsigned int a2)
{
return palette_change_color(
a1,
table_0[a2 & 3 | (a2 >> 4) & 0xC],
table_0[a2 & 3 | (a2 >> 2) & 0xC],
table_0[a2 & 0xF]);
}

original_code:
static void update_pen (int pen, int val)
{
 static unsigned char table[16] =
 {
  0x00,
  0x12,
  0x24,
  0x49,
  0x12,
  0x24,
  0x49,
  0x92,
  0x5b,
  0x6d,
  0x92,
  0xdb,
  0x7f,
  0x91,
  0xb6,
  0xff
 };
 int bits,intensity,red,green,blue;
 intensity = (val >> 0) & 0x03;
 bits = (val >> 6) & 0x03;
 red = table[(bits << 2) | intensity];
 bits = (val >> 4) & 0x03;
 green = table[(bits << 2) | intensity];
 bits = (val >> 2) & 0x03;
 blue = table[(bits << 2) | intensity];
 palette_change_color(pen,red,green,blue);
}

canonical_original_code:
static void update_pen(int pen, int val)
{
 static unsigned char table[16] = {
  0x00,
  0x12,
  0x24,
  0x49,
  0x12,
  0x24,
  0x49,
  0x92,
  0x5b,
  0x6d,
  0x92,
  0xdb,
  0x7f,
  0x91,
  0xb6,
  0xff
 };
 int bits; int intensity; int red; int green; int blue;
 intensity = (val >> 0) & 0x03;
 bits = (val >> 6) & 0x03;
 red = table[(bits << 2) | intensity];
 bits = (val >> 4) & 0x03;
 green = table[(bits << 2) | intensity];
 bits = (val >> 2) & 0x03;
 blue = table[(bits << 2) | intensity];
 palette_change_color(pen,red,green,blue);
}

variable_types: pen int

variable_types: val int

variable_types:
table
unsigned char [16]

variable_types: bits int

variable_types: intensity int

variable_types: red int

variable_types: green int

variable_types: blue int


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

*(_BYTE *)(paletteram + a1) = a2;
result = *qix_palettebank & 3;
if ( (_DWORD)result == a1 >> 8 )
result = update_pen((unsigned __int8)a1, a2);
return result;
}

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

*(_BYTE *)(paletteram + a1) = a2;
result = *qix_palettebank & 3;
if ( (_DWORD)result == a1 >> 8 )
result = func32((unsigned __int8)a1, a2);
return result;
}

original_code:
void qix_paletteram_w(offs_t offset,data_t data)
{
 paletteram[offset] = data;
 if ((*qix_palettebank & 0x03) == (offset / 256))
  update_pen (offset % 256, data);
}

canonical_original_code:
void qix_paletteram_w(unsigned int offset, unsigned int data)
{
 paletteram[offset] = data;
 if ((*qix_palettebank & 0x03) == (offset / 256))
  update_pen (offset % 256, data);
}


decompiled_code:
__int64 __fastcall qix_vh_screenrefresh(__int64 a1, int a2)
{
__int64 result; // rax
__int64 i; // rbx

result = palette_recalc();
if ( a2 || result )
{
for ( i = 0LL; i != 0x10000; ++i )
result = plot_pixel(
a1,
(unsigned __int8)i,
(unsigned int)((int)i >> 8),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)videoram + i)));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func34(__int64 a1, int a2)
{
__int64 result; // rax
__int64 i; // rbx

result = palette_recalc();
if ( a2 || result )
{
for ( i = 0LL; i != 0x10000; ++i )
result = plot_pixel(
a1,
(unsigned __int8)i,
(unsigned int)((int)i >> 8),
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)videoram + i)));
}
return result;
}

original_code:
void qix_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (palette_recalc () || full_refresh)
 {
  int offs;
  for (offs = 0; offs < 256*256; offs++)
  {
   int x = offs & 0xff;
   int y = offs >> 8;
   plot_pixel(bitmap, x, y, Machine->pens[videoram[offs]]);
  }
 }
}

canonical_original_code:
void qix_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (palette_recalc () || full_refresh)
 {
  int offs;
  for (offs = 0; offs < 256*256; offs++)
  {
   int x = offs & 0xff;
   int y = offs >> 8;
   plot_pixel(bitmap, x, y, Machine->pens[videoram[offs]]);
  }
 }
}

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

variable_types: offs int

variable_types: x int

variable_types: y int


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 func35(__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 *


original_code:
void tsamurai_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void tsamurai_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


decompiled_code:
void __fastcall tsamurai_bgcolor_w(__int64 a1, int a2)
{
bgcolor = a2;
}

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

original_code:
void tsamurai_bgcolor_w(offs_t offset,data_t data)
{
 bgcolor = data;
}

canonical_original_code:
void tsamurai_bgcolor_w(unsigned int offset, unsigned int data)
{
 bgcolor = data;
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 unknown_d803_r()
{
return 107LL;
}

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

original_code:
data_t unknown_d803_r(offs_t offset)
{
 return 0x6b;
}

canonical_original_code:
unsigned int unknown_d803_r(unsigned int offset)
{
 return 0x6b;
}


decompiled_code:
__int64 unknown_d806_r()
{
return 64LL;
}

canonical_decompiled_code:
__int64 func6()
{
return 64LL;
}

original_code:
data_t unknown_d806_r(offs_t offset)
{
 return 0x40;
}

canonical_original_code:
unsigned int unknown_d806_r(unsigned int offset)
{
 return 0x40;
}


decompiled_code:
__int64 unknown_d900_r()
{
return 106LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 106LL;
}

original_code:
data_t unknown_d900_r(offs_t offset)
{
 return 0x6a;
}

canonical_original_code:
unsigned int unknown_d900_r(unsigned int offset)
{
 return 0x6a;
}


decompiled_code:
__int64 unknown_d938_r()
{
return 251LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 251LL;
}

original_code:
data_t unknown_d938_r(offs_t offset)
{
 return 0xfb;
}

canonical_original_code:
unsigned int unknown_d938_r(unsigned int offset)
{
 return 0xfb;
}


decompiled_code:
__int64 sound_command1_r()
{
return (unsigned int)sound_command1;
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned int)sound_command1;
}

original_code:
static data_t sound_command1_r(offs_t offset)
{
 return sound_command1;
}

canonical_original_code:
static unsigned int sound_command1_r(unsigned int offset)
{
 return sound_command1;
}


decompiled_code:
__int64 sound_command2_r()
{
return (unsigned int)sound_command2;
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned int)sound_command2;
}

original_code:
static data_t sound_command2_r(offs_t offset){
 return sound_command2;
}

canonical_original_code:
static unsigned int sound_command2_r(unsigned int offset){
 return sound_command2;
}


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

background = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
foreground = v0;
if ( !v0 || !background )
return 1LL;
*(_DWORD *)(background + 132) = 0;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

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

background = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v2) = 32;
v0 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v2);
foreground = v0;
if ( !v0 || !background )
return 1LL;
*(_DWORD *)(background + 132) = 0;
*(_DWORD *)(v0 + 132) = 0;
return 0LL;
}

original_code:
int tsamurai_vh_start(void)
{
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!background || !foreground)
  return 1;
 background->transparent_pen = 0;
 foreground->transparent_pen = 0;
 return 0;
}

canonical_original_code:
int tsamurai_vh_start()
{
 background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,8,8,32,32);
 if (!background || !foreground)
  return 1;
 background->transparent_pen = 0;
 foreground->transparent_pen = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall tsamurai_scrolly_w(__int64 a1, unsigned int a2)
{
return tilemap_set_scrolly(background, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
return tilemap_set_scrolly(background, 0LL, a2);
}

original_code:
void tsamurai_scrolly_w(offs_t offset,data_t data)
{
 tilemap_set_scrolly( background, 0, data );
}

canonical_original_code:
void tsamurai_scrolly_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrolly( background, 0, data );
}


decompiled_code:
__int64 __fastcall tsamurai_scrollx_w(__int64 a1, unsigned int a2)
{
return tilemap_set_scrollx(background, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2)
{
return tilemap_set_scrollx(background, 0LL, a2);
}

original_code:
void tsamurai_scrollx_w(offs_t offset,data_t data)
{
 tilemap_set_scrollx( background, 0, data );
}

canonical_original_code:
void tsamurai_scrollx_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrollx( background, 0, data );
}


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

if ( textbank != a2 )
{
textbank = a2;
result = tilemap_mark_all_tiles_dirty(foreground);
}
return result;
}

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

if ( textbank != a2 )
{
textbank = a2;
result = tilemap_mark_all_tiles_dirty(foreground);
}
return result;
}

original_code:
void tsamurai_textbank_w(offs_t offset,data_t data)
{
 if( textbank!=data )
 {
  textbank = data;
  tilemap_mark_all_tiles_dirty( foreground );
 }
}

canonical_original_code:
void tsamurai_textbank_w(unsigned int offset, unsigned int data)
{
 if( textbank!=data )
 {
  textbank = data;
  tilemap_mark_all_tiles_dirty( foreground );
 }
}


decompiled_code:
__int64 __fastcall tsamurai_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * bgcolor), 0LL);
tilemap_draw(a1, background, 0LL);
draw_sprites(a1);
return tilemap_draw(a1, foreground, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
tilemap_update(0LL);
tilemap_render(0LL);
fillbitmap(a1, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * bgcolor), 0LL);
tilemap_draw(a1, background, 0LL);
func15(a1);
return tilemap_draw(a1, foreground, 0LL);
}

original_code:
void tsamurai_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 tilemap_update( 0 );
 tilemap_render( 0 );
 fillbitmap( bitmap, Machine->pens[bgcolor], 0 );
 tilemap_draw( bitmap, background, 0 );
 draw_sprites( bitmap );
 tilemap_draw( bitmap, foreground, 0 );
}

canonical_original_code:
void tsamurai_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 tilemap_update( 0 );
 tilemap_render( 0 );
 fillbitmap( bitmap, Machine->pens[bgcolor], 0 );
 tilemap_draw( bitmap, background, 0 );
 draw_sprites( bitmap );
 tilemap_draw( bitmap, foreground, 0 );
}

variable_types: fullrefresh int

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


decompiled_code:
__int64 sound_out2_w()
{
return DAC_data_w(1LL);
}

canonical_decompiled_code:
__int64 func17()
{
return DAC_data_w(1LL);
}

original_code:
static void sound_out2_w(offs_t offset,data_t data){
 DAC_data_w(1,data);
}

canonical_original_code:
static void sound_out2_w(unsigned int offset, unsigned int data){
 DAC_data_w(1,data);
}


decompiled_code:
__int64 sound_out1_w()
{
return DAC_data_w(0LL);
}

canonical_decompiled_code:
__int64 func18()
{
return DAC_data_w(0LL);
}

original_code:
static void sound_out1_w(offs_t offset,data_t data)
{
 DAC_data_w(0,data);
}

canonical_original_code:
static void sound_out1_w(unsigned int offset, unsigned int data)
{
 DAC_data_w(0,data);
}


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

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

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

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

original_code:
static int samurai_interrupt( void ){
 return nmi_enabled? nmi_interrupt():ignore_interrupt();
}

canonical_original_code:
static int samurai_interrupt(){
 return nmi_enabled? nmi_interrupt():ignore_interrupt();
}


decompiled_code:
__int64 __fastcall sound_command2_w(__int64 a1, int a2)
{
sound_command2 = a2;
return cpu_cause_interrupt(2LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, int a2)
{
sound_command2 = a2;
return cpu_cause_interrupt(2LL, 4294966296LL);
}

original_code:
static void sound_command2_w(offs_t offset,data_t data)
{
 sound_command2 = data;
 cpu_cause_interrupt( 2, -1000 );
}

canonical_original_code:
static void sound_command2_w(unsigned int offset, unsigned int data)
{
 sound_command2 = data;
 cpu_cause_interrupt( 2, -1000 );
}


decompiled_code:
__int64 __fastcall sound_command1_w(__int64 a1, int a2)
{
sound_command1 = a2;
return cpu_cause_interrupt(1LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, int a2)
{
sound_command1 = a2;
return cpu_cause_interrupt(1LL, 4294966296LL);
}

original_code:
static void sound_command1_w(offs_t offset,data_t data)
{
 sound_command1 = data;
 cpu_cause_interrupt( 1, -1000 );
}

canonical_original_code:
static void sound_command1_w(unsigned int offset, unsigned int data)
{
 sound_command1 = data;
 cpu_cause_interrupt( 1, -1000 );
}


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

v1 = 2 * a1;
v2 = *(_BYTE *)(tsamurai_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(tsamurai_videoram + v1) + 4 * (v2 & 0xC0u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0x1F);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdi
char v2; // cl
__int64 v3; // rsi
signed int v4; // edx
__int64 v5; // rcx
__int64 result; // rax

v1 = 2 * a1;
v2 = *(_BYTE *)(tsamurai_videoram + v1 + 1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = (*(unsigned __int8 *)(tsamurai_videoram + v1) + 4 * (v2 & 0xC0u)) % *(_DWORD *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + *(_DWORD *)(v3 + 52) * v4;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v3 + 16) + 2LL * *(_DWORD *)(v3 + 12) * (v2 & 0x1F);
v5 = *(_QWORD *)(v3 + 32);
result = 0LL;
if ( v5 )
result = *(unsigned int *)(v5 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attributes = tsamurai_videoram[2*tile_index+1];
 int color = (attributes&0x1f);
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (tsamurai_videoram[2*tile_index]+4*(attributes&0xc0)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attributes = tsamurai_videoram[2*tile_index+1];
 int color = (attributes&0x1f);
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (tsamurai_videoram[2*tile_index]+4*(attributes&0xc0)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (color)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

variable_types:
attributes
unsigned char

variable_types: color int

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


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
unsigned int v1; // eax
__int64 v2; // rcx
int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(videoram + a1);
if ( (textbank & 1) != 0 )
v1 += 256;
v2 = *(_QWORD *)(Machine + 520LL);
v3 = v1 % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16)
+ 2LL * *(_DWORD *)(v2 + 12) * (*(_BYTE *)(colorram + 2LL * (a1 & 0x1F) + 1) & 0x1F);
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 func2(int a1)
{
unsigned int v1; // eax
__int64 v2; // rcx
int v3; // edx
__int64 v4; // rcx
__int64 result; // rax

v1 = *(unsigned __int8 *)(videoram + a1);
if ( (textbank & 1) != 0 )
v1 += 256;
v2 = *(_QWORD *)(Machine + 520LL);
v3 = v1 % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16)
+ 2LL * *(_DWORD *)(v2 + 12) * (*(_BYTE *)(colorram + 2LL * (a1 & 0x1F) + 1) & 0x1F);
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_fg_tile_info(int tile_index)
{
 int tile_number = videoram[tile_index];
 if( textbank&1 ) tile_number += 256;
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (tile_number) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (colorram[((tile_index&0x1f)*2)+1] & 0x1f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 int tile_number = videoram[tile_index];
 if( textbank&1 ) tile_number += 256;
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = (tile_number) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (colorram[((tile_index&0x1f)*2)+1] & 0x1f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
}

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 nmi_enable_w(__int64 a1, int a2)
{
nmi_enabled = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
nmi_enabled = a2;
}

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

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


decompiled_code:
__int64 __fastcall draw_sprites(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // r12
unsigned __int8 *v3; // rbx
__int64 v4; // rbp
__int64 result; // rax
__int64 v6; // rax
int v7; // esi
unsigned __int8 v8; // cl

v1 = *(_QWORD *)(Machine + 528LL);
v2 = Machine + 776LL;
v3 = (unsigned __int8 *)(spriteram + 124LL);
flicker_0 = 1 - flicker_0;
v4 = spriteram - 4LL;
do
{
v6 = (unsigned int)v3[3] - 16;
v7 = *v3;
v8 = v3[2] & 0x1F;
if ( flip_screen_x )
result = drawgfx(
a1,
v1,
v3[1] & 0x7F,
v8,
1LL,
(v3[1] & 0x80u) == 0,
(unsigned int)(224 - v6),
(unsigned int)(v7 - 16),
v2,
2LL,
0LL);
else
result = drawgfx(a1, v1, v3[1] & 0x7F, v8, 0LL, v3[1] & 0x80, v6, (unsigned int)(240 - v7), v2, 2LL, 0LL);
v3 -= 4;
}
while ( (unsigned __int8 *)v4 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // r15
__int64 v2; // r12
unsigned __int8 *v3; // rbx
__int64 v4; // rbp
__int64 result; // rax
__int64 v6; // rax
int v7; // esi
unsigned __int8 v8; // cl

v1 = *(_QWORD *)(Machine + 528LL);
v2 = Machine + 776LL;
v3 = (unsigned __int8 *)(spriteram + 124LL);
flicker_0 = 1 - flicker_0;
v4 = spriteram - 4LL;
do
{
v6 = (unsigned int)v3[3] - 16;
v7 = *v3;
v8 = v3[2] & 0x1F;
if ( flip_screen_x )
result = drawgfx(
a1,
v1,
v3[1] & 0x7F,
v8,
1LL,
(v3[1] & 0x80u) == 0,
(unsigned int)(224 - v6),
(unsigned int)(v7 - 16),
v2,
2LL,
0LL);
else
result = drawgfx(a1, v1, v3[1] & 0x7F, v8, 0LL, v3[1] & 0x80, v6, (unsigned int)(240 - v7), v2, 2LL, 0LL);
v3 -= 4;
}
while ( (unsigned __int8 *)v4 != v3 );
return result;
}

original_code:
static void draw_sprites( struct osd_bitmap *bitmap )
{
 struct GfxElement *gfx = Machine->gfx[2];
 const struct rectangle *clip = &Machine->visible_area;
 const unsigned char *source = spriteram+32*4-4;
 const unsigned char *finish = spriteram;
 static int flicker;
 flicker = 1-flicker;
 while( source>=finish )
 {
  int attributes = source[2];
  int sx = source[3] - 16;
  int sy = 240-source[0];
  int sprite_number = source[1];
  int color = attributes&0x1f;
  if( sy<-16 ) sy += 256;
  if( flip_screen_x )
  {
   drawgfx( bitmap,gfx,
    sprite_number&0x7f,
    color,
    1,(sprite_number&0x80)?0:1,
    256-32-sx,256-32-sy,
    clip,TRANSPARENCY_PEN,0 );
  }
  else
  {
   drawgfx( bitmap,gfx,
    sprite_number&0x7f,
    color,
    0,sprite_number&0x80,
    sx,sy,
    clip,TRANSPARENCY_PEN,0 );
  }
  source -= 4;
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct GfxElement *gfx = Machine->gfx[2];
 struct rectangle *clip = &Machine->visible_area;
 unsigned char *source = spriteram+32*4-4;
 unsigned char *finish = spriteram;
 static int flicker;
 flicker = 1-flicker;
 while( source>=finish )
 {
  int attributes = source[2];
  int sx = source[3] - 16;
  int sy = 240-source[0];
  int sprite_number = source[1];
  int color = attributes&0x1f;
  if( sy<-16 ) sy += 256;
  if( flip_screen_x )
  {
   drawgfx( bitmap,gfx,
    sprite_number&0x7f,
    color,
    1,(sprite_number&0x80)?0:1,
    256-32-sx,256-32-sy,
    clip,TRANSPARENCY_PEN,0 );
  }
  else
  {
   drawgfx( bitmap,gfx,
    sprite_number&0x7f,
    color,
    0,sprite_number&0x80,
    sx,sy,
    clip,TRANSPARENCY_PEN,0 );
  }
  source -= 4;
 }
}

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

variable_types:
source
unsigned char *

variable_types:
finish
unsigned char *

variable_types: flicker int

variable_types: attributes int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 __fastcall timer_callback_2608(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2608TimerOver((unsigned __int8)v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // esi
unsigned int v2; // edi

v1 = a1 >> 7;
v2 = a1 & 0x7F;
Timer[2 * v2 + v1] = 0LL;
return YM2608TimerOver((unsigned __int8)v2);
}

original_code:
static void timer_callback_2608(int param)
{
 int n=param&0x7f;
 int c=param>>7;
 Timer[n][c] = 0;
 YM2608TimerOver(n,c);
}

canonical_original_code:
static void timer_callback_2608(int param)
{
 int n = param&0x7f;
 int c = param>>7;
 Timer[n][c] = 0;
 YM2608TimerOver(n,c);
}

variable_types: param int

variable_types: n int

variable_types: c int


decompiled_code:
__int64 __fastcall YM2608UpdateRequest(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return stream_update(*((unsigned int *)&stream + a1), 100LL);
}

original_code:
void YM2608UpdateRequest(int chip)
{
 stream_update(stream[chip],100);
}

variable_types: chip int


decompiled_code:
void YM2608_sh_stop()
{
YM2608Shutdown();
if ( rhythm_buf )
free(rhythm_buf);
rhythm_buf = 0LL;
}

canonical_decompiled_code:
void func4()
{
YM2608Shutdown();
if ( rhythm_buf )
free(rhythm_buf);
rhythm_buf = 0LL;
}

original_code:
void YM2608_sh_stop(void)
{
 YM2608Shutdown();
 if( rhythm_buf ) free(rhythm_buf);
 rhythm_buf = 0;
}

canonical_original_code:
void YM2608_sh_stop()
{
 YM2608Shutdown();
 if( rhythm_buf ) free(rhythm_buf);
 rhythm_buf = 0;
}


decompiled_code:
__int64 YM2608_sh_reset()
{
__int64 result; // rax
unsigned int v1; // ebx

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
YM2608ResetChip(v1++);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

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

result = intf;
if ( *(int *)intf > 0 )
{
v1 = 0;
do
{
YM2608ResetChip(v1++);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

original_code:
void YM2608_sh_reset(void)
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2608ResetChip(i);
}

canonical_original_code:
void YM2608_sh_reset()
{
 int i;
 for (i = 0;i < intf->num;i++)
  YM2608ResetChip(i);
}

variable_types: i int


decompiled_code:
__int64 YM2608_status_port_0_A_r()
{
return (unsigned __int8)YM2608Read(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned __int8)YM2608Read(0LL, 0LL);
}

original_code:
data_t YM2608_status_port_0_A_r(offs_t offset)
{
 return YM2608Read(0,0);
}

canonical_original_code:
unsigned int YM2608_status_port_0_A_r(unsigned int offset)
{
 return YM2608Read(0,0);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 YM2608_status_port_0_B_r()
{
return (unsigned __int8)YM2608Read(0LL, 2LL);
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned __int8)YM2608Read(0LL, 2LL);
}

original_code:
data_t YM2608_status_port_0_B_r(offs_t offset)
{
 return YM2608Read(0,2);
}

canonical_original_code:
unsigned int YM2608_status_port_0_B_r(unsigned int offset)
{
 return YM2608Read(0,2);
}


decompiled_code:
__int64 YM2608_status_port_1_A_r()
{
return (unsigned __int8)YM2608Read(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned __int8)YM2608Read(1LL, 0LL);
}

original_code:
data_t YM2608_status_port_1_A_r(offs_t offset) {
 return YM2608Read(1,0);
}

canonical_original_code:
unsigned int YM2608_status_port_1_A_r(unsigned int offset) {
 return YM2608Read(1,0);
}


decompiled_code:
__int64 YM2608_status_port_1_B_r()
{
return (unsigned __int8)YM2608Read(1LL, 2LL);
}

canonical_decompiled_code:
__int64 func9()
{
return (unsigned __int8)YM2608Read(1LL, 2LL);
}

original_code:
data_t YM2608_status_port_1_B_r(offs_t offset) {
 return YM2608Read(1,2);
}

canonical_original_code:
unsigned int YM2608_status_port_1_B_r(unsigned int offset) {
 return YM2608Read(1,2);
}


decompiled_code:
__int64 YM2608_read_port_0_r()
{
return (unsigned __int8)YM2608Read(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned __int8)YM2608Read(0LL, 1LL);
}

original_code:
data_t YM2608_read_port_0_r(offs_t offset){
 return YM2608Read(0,1);
}

canonical_original_code:
unsigned int YM2608_read_port_0_r(unsigned int offset){
 return YM2608Read(0,1);
}


decompiled_code:
__int64 YM2608_read_port_1_r()
{
return (unsigned __int8)YM2608Read(1LL, 1LL);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned __int8)YM2608Read(1LL, 1LL);
}

original_code:
data_t YM2608_read_port_1_r(offs_t offset){
 return YM2608Read(1,1);
}

canonical_original_code:
unsigned int YM2608_read_port_1_r(unsigned int offset){
 return YM2608Read(1,1);
}


decompiled_code:
__int64 __fastcall YM2608_control_port_0_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 0LL, a2);
}

original_code:
void YM2608_control_port_0_A_w(offs_t offset,data_t data)
{
 YM2608Write(0,0,data);
}

canonical_original_code:
void YM2608_control_port_0_A_w(unsigned int offset, unsigned int data)
{
 YM2608Write(0,0,data);
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall YM2608_control_port_0_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 2LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 2LL, a2);
}

original_code:
void YM2608_control_port_0_B_w(offs_t offset,data_t data)
{
 YM2608Write(0,2,data);
}

canonical_original_code:
void YM2608_control_port_0_B_w(unsigned int offset, unsigned int data)
{
 YM2608Write(0,2,data);
}


decompiled_code:
__int64 __fastcall YM2608_control_port_1_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 0LL, a2);
}

original_code:
void YM2608_control_port_1_A_w(offs_t offset,data_t data){
 YM2608Write(1,0,data);
}

canonical_original_code:
void YM2608_control_port_1_A_w(unsigned int offset, unsigned int data){
 YM2608Write(1,0,data);
}


decompiled_code:
__int64 __fastcall YM2608_control_port_1_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 2LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 2LL, a2);
}

original_code:
void YM2608_control_port_1_B_w(offs_t offset,data_t data){
 YM2608Write(1,2,data);
}

canonical_original_code:
void YM2608_control_port_1_B_w(unsigned int offset, unsigned int data){
 YM2608Write(1,2,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_0_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 1LL, a2);
}

original_code:
void YM2608_data_port_0_A_w(offs_t offset,data_t data)
{
 YM2608Write(0,1,data);
}

canonical_original_code:
void YM2608_data_port_0_A_w(unsigned int offset, unsigned int data)
{
 YM2608Write(0,1,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_0_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 3LL, a2);
}

original_code:
void YM2608_data_port_0_B_w(offs_t offset,data_t data)
{
 YM2608Write(0,3,data);
}

canonical_original_code:
void YM2608_data_port_0_B_w(unsigned int offset, unsigned int data)
{
 YM2608Write(0,3,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_1_A_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 1LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 1LL, a2);
}

original_code:
void YM2608_data_port_1_A_w(offs_t offset,data_t data){
 YM2608Write(1,1,data);
}

canonical_original_code:
void YM2608_data_port_1_A_w(unsigned int offset, unsigned int data){
 YM2608Write(1,1,data);
}


decompiled_code:
__int64 __fastcall YM2608_data_port_1_B_w(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 3LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 3LL, a2);
}

original_code:
void YM2608_data_port_1_B_w(offs_t offset,data_t data){
 YM2608Write(1,3,data);
}

canonical_original_code:
void YM2608_data_port_1_B_w(unsigned int offset, unsigned int data){
 YM2608Write(1,3,data);
}


FMTimerInit

decompiled_code:
void FMTimerInit()
{
qword_528 = 0LL;
Timer = 0LL;
qword_538 = 0LL;
qword_530 = 0LL;
}

canonical_decompiled_code:
void func0()
{
qword_528 = 0LL;
Timer = 0LL;
qword_538 = 0LL;
qword_530 = 0LL;
}

original_code:
static void FMTimerInit( void )
{
 int i;
 for( i = 0 ; i < (2) ; i++ )
  Timer[i][0] = Timer[i][1] = 0;
}

canonical_original_code:
static void FMTimerInit()
{
 int i;
 for( i = 0 ; i < (2) ; i++ )
  Timer[i][0] = Timer[i][1] = 0;
}


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


decompiled_code:
__int64 io_0x03_r()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
data_t io_0x03_r(offs_t offset)
{
 return 0x00;
}

canonical_original_code:
unsigned int io_0x03_r(unsigned int offset)
{
 return 0x00;
}


decompiled_code:
void *__fastcall mrjong_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r8
unsigned __int8 v4; // cl
void *result; // rax
int v6; // ebp
__int64 v7; // rbx
__int64 v8; // r8

v1 = videoram_size - 1;
if ( videoram_size - 1 > 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v4 = *(_BYTE *)(colorram + v2);
v3 = ((int)v4 >> 6) & 1;
if ( flipscreen )
v3 = !(((int)v4 >> 6) & 1);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(8 * v4) & 0x100 | (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0x1F,
v3);
}
--v2;
--v1;
}
while ( v1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6 + 1LL;
do
{
v8 = *(_BYTE *)(spriteram + v7) & 1;
if ( flipscreen )
v8 = !(*(_BYTE *)(spriteram + v7) & 1);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(2 * *(_BYTE *)(spriteram + v7 + 2)) & 0x40 | (unsigned int)(*(_BYTE *)(spriteram + v7) >> 2),
*(_BYTE *)(spriteram + v7 + 2) & 0x1F,
v8);
v7 -= 4LL;
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r8
unsigned __int8 v4; // cl
void *result; // rax
int v6; // ebp
__int64 v7; // rbx
__int64 v8; // r8

v1 = videoram_size - 1;
if ( videoram_size - 1 > 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v4 = *(_BYTE *)(colorram + v2);
v3 = ((int)v4 >> 6) & 1;
if ( flipscreen )
v3 = !(((int)v4 >> 6) & 1);
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(8 * v4) & 0x100 | (unsigned int)*(unsigned __int8 *)(videoram + v2),
*(_BYTE *)(colorram + v2) & 0x1F,
v3);
}
--v2;
--v1;
}
while ( v1 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v6 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v7 = v6 + 1LL;
do
{
v8 = *(_BYTE *)(spriteram + v7) & 1;
if ( flipscreen )
v8 = !(*(_BYTE *)(spriteram + v7) & 1);
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
(2 * *(_BYTE *)(spriteram + v7 + 2)) & 0x40 | (unsigned int)(*(_BYTE *)(spriteram + v7) >> 2),
*(_BYTE *)(spriteram + v7 + 2) & 0x1F,
v8);
v7 -= 4LL;
v6 -= 4;
}
while ( v6 >= 0 );
}
return result;
}

original_code:
void mrjong_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = (videoram_size - 1); offs > 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int tile;
   int color;
   int sx, sy;
   int flipx, flipy;
   dirtybuffer[offs] = 0;
   tile = videoram[offs] | ((colorram[offs] & 0x20) << 3);
   flipx = (colorram[offs] & 0x40) >> 6;
   flipy = (colorram[offs] & 0x80) >> 7;
   color = colorram[offs] & 0x1f;
   sx = 31 - (offs % 32);
   sy = 31 - (offs / 32);
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap, Machine->gfx[0],
     tile,
     color,
     flipx, flipy,
     8*sx, 8*sy,
     &Machine->visible_area, TRANSPARENCY_NONE, 0);
  }
 }
 copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->visible_area, TRANSPARENCY_NONE, 0);
 for (offs = (spriteram_size - 4); offs >= 0; offs -= 4)
 {
  int sprt;
  int color;
  int sx, sy;
  int flipx, flipy;
  sprt = (((spriteram[offs + 1] >> 2) & 0x3f) | ((spriteram[offs + 3] & 0x20) << 1));
  flipx = (spriteram[offs + 1] & 0x01) >> 0;
  flipy = (spriteram[offs + 1] & 0x02) >> 1;
  color = (spriteram[offs + 3] & 0x1f);
  sx = 224 - spriteram[offs + 2];
  sy = spriteram[offs + 0];
  if (flipscreen)
  {
   sx = 208 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap, Machine->gfx[1],
    sprt,
    color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area, TRANSPARENCY_PEN, 0);
 }
}

canonical_original_code:
void mrjong_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = (videoram_size - 1); offs > 0; offs--)
 {
  if (dirtybuffer[offs])
  {
   int tile;
   int color;
   int sx; int sy;
   int flipx; int flipy;
   dirtybuffer[offs] = 0;
   tile = videoram[offs] | ((colorram[offs] & 0x20) << 3);
   flipx = (colorram[offs] & 0x40) >> 6;
   flipy = (colorram[offs] & 0x80) >> 7;
   color = colorram[offs] & 0x1f;
   sx = 31 - (offs % 32);
   sy = 31 - (offs / 32);
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(tmpbitmap, Machine->gfx[0],
     tile,
     color,
     flipx, flipy,
     8*sx, 8*sy,
     &Machine->visible_area, TRANSPARENCY_NONE, 0);
  }
 }
 copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, &Machine->visible_area, TRANSPARENCY_NONE, 0);
 for (offs = (spriteram_size - 4); offs >= 0; offs -= 4)
 {
  int sprt;
  int color;
  int sx; int sy;
  int flipx; int flipy;
  sprt = (((spriteram[offs + 1] >> 2) & 0x3f) | ((spriteram[offs + 3] & 0x20) << 1));
  flipx = (spriteram[offs + 1] & 0x01) >> 0;
  flipy = (spriteram[offs + 1] & 0x02) >> 1;
  color = (spriteram[offs + 3] & 0x1f);
  sx = 224 - spriteram[offs + 2];
  sy = spriteram[offs + 0];
  if (flipscreen)
  {
   sx = 208 - sx;
   sy = 240 - sy;
   flipx = !flipx;
   flipy = !flipy;
  }
  drawgfx(bitmap, Machine->gfx[1],
    sprt,
    color,
    flipx, flipy,
    sx, sy,
    &Machine->visible_area, TRANSPARENCY_PEN, 0);
 }
}

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

variable_types: offs int

variable_types: tile int

variable_types: color int

variable_types: flipx int

variable_types: flipy int

variable_types: sprt int


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

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

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

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

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

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


decompiled_code:
void *__fastcall io_0x00_w(__int64 a1, char a2)
{
return mrjong_flipscreen_w(0LL, (a2 & 4u) > 2);
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, char a2)
{
return func3(0LL, (a2 & 4u) > 2);
}

original_code:
void io_0x00_w(offs_t offset,data_t data)
{
 mrjong_flipscreen_w(0, ((data & 0x04) > 2));
}

canonical_original_code:
void io_0x00_w(unsigned int offset, unsigned int data)
{
 mrjong_flipscreen_w(0, ((data & 0x04) > 2));
}


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

cpu_bankbase[1] = memory_region(129LL) + (int)(((a2 & 7) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
result = (void *)((a2 >> 3) & 7);
if ( ((a2 >> 3) & 7) != gfxbank )
{
gfxbank = (a2 >> 3) & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

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

cpu_bankbase[1] = memory_region(129LL) + (int)(((a2 & 7) + 4) << 14);
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
cpu_setOPbase16(v3);
}
result = (void *)((a2 >> 3) & 7);
if ( ((a2 >> 3) & 7) != gfxbank )
{
gfxbank = (a2 >> 3) & 7;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void sichuan2_bankswitch_w(offs_t offset,data_t data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (gfxbank != ((data & 0x38) >> 3))
 {
  gfxbank = (data & 0x38) >> 3;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void sichuan2_bankswitch_w(unsigned int offset, unsigned int data)
{
 int bankaddress;
 unsigned char *RAM = memory_region(REGION_CPU1);
 bankaddress = 0x10000 + (data & 0x07) * 0x4000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
 if (gfxbank != ((data & 0x38) >> 3))
 {
  gfxbank = (data & 0x38) >> 3;
  memset(dirtybuffer,1,videoram_size);
 }
}

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall sichuan2_paletteram_w(unsigned int a1, char a2)
{
int v2; // esi
int v3; // edx
int v4; // ecx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(_BYTE *)(paletteram + (unsigned __int8)a1) & 0x1F;
v3 = *(_BYTE *)(paletteram + (unsigned int)(unsigned __int8)a1 + 256) & 0x1F;
v4 = *(_BYTE *)(paletteram + (unsigned int)(unsigned __int8)a1 + 512) & 0x1F;
return palette_change_color(
(unsigned __int8)a1,
(8 * v2) | (unsigned int)(v2 >> 2),
(8 * v3) | (unsigned int)(v3 >> 2),
(8 * v4) | (unsigned int)(v4 >> 2));
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, char a2)
{
int v2; // esi
int v3; // edx
int v4; // ecx

*(_BYTE *)(paletteram + a1) = a2;
v2 = *(_BYTE *)(paletteram + (unsigned __int8)a1) & 0x1F;
v3 = *(_BYTE *)(paletteram + (unsigned int)(unsigned __int8)a1 + 256) & 0x1F;
v4 = *(_BYTE *)(paletteram + (unsigned int)(unsigned __int8)a1 + 512) & 0x1F;
return palette_change_color(
(unsigned __int8)a1,
(8 * v2) | (unsigned int)(v2 >> 2),
(8 * v3) | (unsigned int)(v3 >> 2),
(8 * v4) | (unsigned int)(v4 >> 2));
}

original_code:
void sichuan2_paletteram_w(offs_t offset,data_t data)
{
 int r,g,b;
 paletteram[offset] = data;
 offset &= 0xff;
 r = paletteram[offset+0x000] & 0x1f;
 g = paletteram[offset+0x100] & 0x1f;
 b = paletteram[offset+0x200] & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset,r,g,b);
}

canonical_original_code:
void sichuan2_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 paletteram[offset] = data;
 offset &= 0xff;
 r = paletteram[offset+0x000] & 0x1f;
 g = paletteram[offset+0x100] & 0x1f;
 b = paletteram[offset+0x200] & 0x1f;
 r = (r << 3) | (r >> 2);
 g = (g << 3) | (g >> 2);
 b = (b << 3) | (b >> 2);
 palette_change_color(offset,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall sichuan2_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rsi

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1 + 1LL;
do
{
v3 = v2 - 1;
if ( *((char *)dirtybuffer + v2 - 1) || *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((*(unsigned __int8 *)(videoram + v2) << 8) & 0xF00u) + (gfxbank << 12),
*(_BYTE *)(videoram + v2) >> 4,
0LL,
0LL,
8
* (((((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 26) + (unsigned __int8)(v1 / 2)) & 0x3F)
- ((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 26)),
(unsigned int)(8 * (v1 / 128)),
Machine + 776LL,
0LL,
0LL);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rsi

if ( palette_recalc() )
memset(dirtybuffer, 1, videoram_size);
v1 = videoram_size - 2;
if ( (int)videoram_size - 2 >= 0 )
{
v2 = v1 + 1LL;
do
{
v3 = v2 - 1;
if ( *((char *)dirtybuffer + v2 - 1) || *((_BYTE *)dirtybuffer + v2) )
{
*((_BYTE *)dirtybuffer + v2) = 0;
*((_BYTE *)dirtybuffer + v3) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v3) + ((*(unsigned __int8 *)(videoram + v2) << 8) & 0xF00u) + (gfxbank << 12),
*(_BYTE *)(videoram + v2) >> 4,
0LL,
0LL,
8
* (((((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 26) + (unsigned __int8)(v1 / 2)) & 0x3F)
- ((unsigned int)((int)(v1 + ((unsigned int)v1 >> 31)) >> 31) >> 26)),
(unsigned int)(8 * (v1 / 128)),
Machine + 776LL,
0LL,
0LL);
}
v2 -= 2LL;
v1 -= 2;
}
while ( v1 >= 0 );
}
return copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}

original_code:
void sichuan2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx,sy;
   dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 64;
   sy = (offs/2) / 64;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0x0f) << 8) + (gfxbank << 12),
     (videoram[offs+1] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

canonical_original_code:
void sichuan2_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc())
  memset(dirtybuffer,1,videoram_size);
 for (offs = videoram_size-2;offs >= 0;offs -= 2)
 {
  if (dirtybuffer[offs] || dirtybuffer[offs+1])
  {
   int sx; int sy;
   dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
   sx = (offs/2) % 64;
   sy = (offs/2) / 64;
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + ((videoram[offs+1] & 0x0f) << 8) + (gfxbank << 12),
     (videoram[offs+1] & 0xf0) >> 4,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
}

variable_types: sx int

variable_types: sy int


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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


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

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

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

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

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

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

variable_types: ret int


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

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

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int


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

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

original_code:
data_t pandoras_vram_r(offs_t offset)
{
 return videoram[offset];
}

canonical_original_code:
unsigned int pandoras_vram_r(unsigned int offset)
{
 return videoram[offset];
}


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

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

original_code:
data_t pandoras_cram_r(offs_t offset)
{
 return colorram[offset];
}

canonical_original_code:
unsigned int pandoras_cram_r(unsigned int offset)
{
 return colorram[offset];
}


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

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

original_code:
static data_t pandoras_sharedram_r(offs_t offset){
 return pandoras_sharedram[offset];
}

canonical_original_code:
static unsigned int pandoras_sharedram_r(unsigned int offset){
 return pandoras_sharedram[offset];
}


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

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

original_code:
static data_t pandoras_sharedram2_r(offs_t offset){
 return pandoras_sharedram2[offset];
}

canonical_original_code:
static unsigned int pandoras_sharedram2_r(unsigned int offset){
 return pandoras_sharedram2[offset];
}


decompiled_code:
void __fastcall i8039_irqen_w(__int64 a1, char a2)
{
i8039_irqenable = a2 & 0x80;
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, char a2)
{
i8039_irqenable = a2 & 0x80;
}

original_code:
static void i8039_irqen_w(offs_t offset,data_t data)
{
 i8039_irqenable = data & 0x80;
}

canonical_original_code:
static void i8039_irqen_w(unsigned int offset, unsigned int data)
{
 i8039_irqenable = data & 0x80;
}


decompiled_code:
void pandoras_init_machine()
{
firq_old_data_b = 0;
firq_old_data_a = 0;
irq_enable_b = 0;
irq_enable_a = 0;
}

canonical_decompiled_code:
void func9()
{
firq_old_data_b = 0;
firq_old_data_a = 0;
irq_enable_b = 0;
irq_enable_a = 0;
}

original_code:
static void pandoras_init_machine( void )
{
 firq_old_data_a = firq_old_data_b = 0;
 irq_enable_a = irq_enable_b = 0;
}

canonical_original_code:
static void pandoras_init_machine()
{
 firq_old_data_a = firq_old_data_b = 0;
 irq_enable_a = irq_enable_b = 0;
}


decompiled_code:
void pandoras_portB_w()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

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

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


decompiled_code:
_BOOL8 pandoras_vh_start()
{
layer0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return layer0 == 0;
}

canonical_decompiled_code:
_BOOL8 func11()
{
layer0 = tilemap_create(get_tile_info0, &tilemap_scan_rows, 0LL, 8LL, 8LL, 32LL, 32LL);
return layer0 == 0;
}

original_code:
int pandoras_vh_start(void)
{
 layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,0x00,8,8,32,32);
 if (!layer0)
  return 1;
 return 0;
}

canonical_original_code:
int pandoras_vh_start()
{
 layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,0x00,8,8,32,32);
 if (!layer0)
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall pandoras_scrolly_w(__int64 a1, unsigned int a2)
{
return tilemap_set_scrolly(layer0, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2)
{
return tilemap_set_scrolly(layer0, 0LL, a2);
}

original_code:
void pandoras_scrolly_w(offs_t offset,data_t data)
{
 tilemap_set_scrolly(layer0,0,data);
}

canonical_original_code:
void pandoras_scrolly_w(unsigned int offset, unsigned int data)
{
 tilemap_set_scrolly(layer0,0,data);
}


decompiled_code:
__int64 __fastcall pandoras_vh_screenrefresh(__int64 a1)
{
tilemap_update(layer0);
tilemap_render(layer0);
tilemap_draw(a1, layer0, 1LL);
draw_sprites(a1, (unsigned __int8 *)(pandoras_sharedram + 2048LL));
return tilemap_draw(a1, layer0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
tilemap_update(layer0);
tilemap_render(layer0);
tilemap_draw(a1, layer0, 1LL);
func15(a1, (unsigned __int8 *)(pandoras_sharedram + 2048LL));
return tilemap_draw(a1, layer0, 0LL);
}

original_code:
void pandoras_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update( layer0 );
 tilemap_render( layer0 );
 tilemap_draw( bitmap, layer0, 1 );
 draw_sprites( bitmap, &pandoras_sharedram[0x800] );
 tilemap_draw( bitmap, layer0, 0 );
}

canonical_original_code:
void pandoras_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update( layer0 );
 tilemap_render( layer0 );
 tilemap_draw( bitmap, layer0, 1 );
 draw_sprites( bitmap, &pandoras_sharedram[0x800] );
 tilemap_draw( bitmap, layer0, 0 );
}

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


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

if ( !firq_old_data_a && a2 )
result = cpu_cause_interrupt(0LL, 2LL);
firq_old_data_a = a2;
return result;
}

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

if ( !firq_old_data_a && a2 )
result = cpu_cause_interrupt(0LL, 2LL);
firq_old_data_a = a2;
return result;
}

original_code:
void pandoras_cpua_irqtrigger_w(offs_t offset,data_t data){
 if (!firq_old_data_a && data){
  cpu_cause_interrupt(0,2);
 }
 firq_old_data_a = data;
}

canonical_original_code:
void pandoras_cpua_irqtrigger_w(unsigned int offset, unsigned int data){
 if (!firq_old_data_a && data){
  cpu_cause_interrupt(0,2);
 }
 firq_old_data_a = data;
}


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

if ( !firq_old_data_b && a2 )
result = cpu_cause_interrupt(1LL, 2LL);
firq_old_data_b = a2;
return result;
}

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

if ( !firq_old_data_b && a2 )
result = cpu_cause_interrupt(1LL, 2LL);
firq_old_data_b = a2;
return result;
}

original_code:
void pandoras_cpub_irqtrigger_w(offs_t offset,data_t data){
 if (!firq_old_data_b && data){
  cpu_cause_interrupt(1,2);
 }
 firq_old_data_b = data;
}

canonical_original_code:
void pandoras_cpub_irqtrigger_w(unsigned int offset, unsigned int data){
 if (!firq_old_data_b && data){
  cpu_cause_interrupt(1,2);
 }
 firq_old_data_b = data;
}


decompiled_code:
__int64 pandoras_z80_irqtrigger_w()
{
return cpu_cause_interrupt(2LL, 255LL);
}

canonical_decompiled_code:
__int64 func19()
{
return cpu_cause_interrupt(2LL, 255LL);
}

original_code:
void pandoras_z80_irqtrigger_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(2,0xff);
}

canonical_original_code:
void pandoras_z80_irqtrigger_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(2,0xff);
}


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

if ( i8039_irqenable )
result = cpu_cause_interrupt(3LL, 1LL);
return result;
}

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

if ( i8039_irqenable )
result = cpu_cause_interrupt(3LL, 1LL);
return result;
}

original_code:
void pandoras_i8039_irqtrigger_w(offs_t offset,data_t data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(3,1);
}

canonical_original_code:
void pandoras_i8039_irqtrigger_w(unsigned int offset, unsigned int data)
{
 if (i8039_irqenable)
  cpu_cause_interrupt(3,1);
}


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

result = 1LL;
if ( !irq_enable_b )
result = ignore_interrupt();
return result;
}

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

result = 1LL;
if ( !irq_enable_b )
result = ignore_interrupt();
return result;
}

original_code:
static int pandoras_interrupt_b( void ){
 if (irq_enable_b)
  return 1;
 return ignore_interrupt();
}

canonical_original_code:
static int pandoras_interrupt_b(){
 if (irq_enable_b)
  return 1;
 return ignore_interrupt();
}


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

result = 1LL;
if ( !irq_enable_a )
result = ignore_interrupt();
return result;
}

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

result = 1LL;
if ( !irq_enable_a )
result = ignore_interrupt();
return result;
}

original_code:
static int pandoras_interrupt_a( void ){
 if (irq_enable_a)
  return 1;
 return ignore_interrupt();
}

canonical_original_code:
static int pandoras_interrupt_a(){
 if (irq_enable_a)
  return 1;
 return ignore_interrupt();
}


decompiled_code:
__int64 pandoras_portB_r()
{
return ((int)cpu_gettotalcycles() / 1024) & 0xF;
}

canonical_decompiled_code:
__int64 func23()
{
return ((int)cpu_gettotalcycles() / 1024) & 0xF;
}

original_code:
static data_t pandoras_portB_r(offs_t offset)
{
 return (cpu_gettotalcycles() / 1024) & 0x0f;
}

canonical_original_code:
static unsigned int pandoras_portB_r(unsigned int offset)
{
 return (cpu_gettotalcycles() / 1024) & 0x0f;
}


decompiled_code:
__int64 __fastcall pandoras_flipscreen_w(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 != 0 ? 3 : 0);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, int a2)
{
return tilemap_set_flip(0LL, a2 != 0 ? 3 : 0);
}

original_code:
void pandoras_flipscreen_w(offs_t offset,data_t data)
{
 flipscreen = data;
 tilemap_set_flip(0, flipscreen ? (0x2 | 0x1) : 0);
}

canonical_original_code:
void pandoras_flipscreen_w(unsigned int offset, unsigned int data)
{
 flipscreen = data;
 tilemap_set_flip(0, flipscreen ? (0x2 | 0x1) : 0);
}


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

switch ( a1 )
{
case 0:
if ( !a2 )
result = cpu_set_irq_line(0LL, 0LL, 0LL);
irq_enable_a = a2;
break;
case 2:
result = coin_counter_w(0LL, a2 & 1);
break;
case 3:
result = coin_counter_w(1LL, a2 & 1);
break;
case 5:
result = pandoras_flipscreen_w(0LL, a2);
break;
case 6:
if ( !a2 )
result = cpu_set_irq_line(1LL, 0LL, 0LL);
irq_enable_b = a2;
break;
case 7:
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
if ( !a2 )
result = cpu_set_irq_line(0LL, 0LL, 0LL);
irq_enable_a = a2;
break;
case 2:
result = coin_counter_w(0LL, a2 & 1);
break;
case 3:
result = coin_counter_w(1LL, a2 & 1);
break;
case 5:
result = func24(0LL, a2);
break;
case 6:
if ( !a2 )
result = cpu_set_irq_line(1LL, 0LL, 0LL);
irq_enable_b = a2;
break;
case 7:
result = cpu_cause_interrupt(1LL, 4LL);
break;
default:
return result;
}
return result;
}

original_code:
static void pandoras_int_control_w(offs_t offset,data_t data){
 switch (offset){
  case 0x00: if (!data) cpu_set_irq_line(0, 0, 0);
     irq_enable_a = data;
     break;
  case 0x02: coin_counter_w(0,data & 0x01);
     break;
  case 0x03: coin_counter_w(1,data & 0x01);
     break;
  case 0x05: pandoras_flipscreen_w(0, data);
     break;
  case 0x06: if (!data) cpu_set_irq_line(1, 0, 0);
     irq_enable_b = data;
     break;
  case 0x07: cpu_cause_interrupt(1,4);
     break;
  default:
   break;
 }
}

canonical_original_code:
static void pandoras_int_control_w(unsigned int offset, unsigned int data){
 switch (offset){
  case 0x00: if (!data) cpu_set_irq_line(0, 0, 0);
     irq_enable_a = data;
     break;
  case 0x02: coin_counter_w(0,data & 0x01);
     break;
  case 0x03: coin_counter_w(1,data & 0x01);
     break;
  case 0x05: pandoras_flipscreen_w(0, data);
     break;
  case 0x06: if (!data) cpu_set_irq_line(1, 0, 0);
     irq_enable_b = data;
     break;
  case 0x07: cpu_cause_interrupt(1,4);
     break;
  default:
   break;
 }
}


decompiled_code:
void *__fastcall get_tile_info0(int a1)
{
unsigned __int8 v1; // cl
__int64 v2; // rsi
signed int v3; // edx
__int64 v4; // rax
int v5; // esi
void *result; // rax

v1 = *(_BYTE *)(colorram + a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(videoram + a1) + ((16 * v1) & 0x100u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 & 0xF);
v4 = *(_QWORD *)(v2 + 32);
v5 = 0;
if ( v4 )
v5 = *(_DWORD *)(v4 + 4LL * v3);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v5;
*((_DWORD *)&tile_info + 5) = v1 >> 6;
*((_DWORD *)&tile_info + 6) = ((int)v1 >> 5) & 1;
return result;
}

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

v1 = *(_BYTE *)(colorram + a1);
v2 = *(_QWORD *)(Machine + 512LL);
v3 = (*(unsigned __int8 *)(videoram + a1) + ((16 * v1) & 0x100u)) % *(_DWORD *)(v2 + 8);
tile_info = *(_QWORD *)(v2 + 40) + *(_DWORD *)(v2 + 52) * v3;
*((_QWORD *)&tile_info + 1) = *(_QWORD *)(v2 + 16) + 2LL * *(_DWORD *)(v2 + 12) * (v1 & 0xF);
v4 = *(_QWORD *)(v2 + 32);
v5 = 0;
if ( v4 )
v5 = *(_DWORD *)(v4 + 4LL * v3);
result = &tile_info;
*((_DWORD *)&tile_info + 4) = v5;
*((_DWORD *)&tile_info + 5) = v1 >> 6;
*((_DWORD *)&tile_info + 6) = ((int)v1 >> 5) & 1;
return result;
}

original_code:
static void get_tile_info0(int tile_index)
{
 unsigned char attr = colorram[tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index] + ((attr & 0x10) << 4)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x20) >> 5;
}

canonical_original_code:
static void get_tile_info0(int tile_index)
{
 unsigned char attr = colorram[tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (videoram[tile_index] + ((attr & 0x10) << 4)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x0f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = ((attr & 0xc0) >> 6);
 tile_info.priority = (attr & 0x20) >> 5;
}

variable_types:
attr
unsigned char

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