decompiled_code:
__int64 port4_r()
{
return dd_sub_cpu_busy | (unsigned int)readinputport(4LL);
}

canonical_decompiled_code:
__int64 func18()
{
return dd_sub_cpu_busy | (unsigned int)readinputport(4LL);
}

original_code:
static data_t port4_r(offs_t offset)
{
 int port = readinputport( 4 );
 return port | dd_sub_cpu_busy;
}

canonical_original_code:
static unsigned int port4_r(unsigned int offset)
{
 int port = readinputport( 4 );
 return port | dd_sub_cpu_busy;
}

variable_types: port int


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

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

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

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

original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_bgvideoram[2*tile_index];
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (ddragon_bgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 3) & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_bgvideoram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = (ddragon_bgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr >> 3) & 0x07)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; }
 tile_info.flags = ((attr & 0xc0) >> 6);
}

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

return_type: void


decompiled_code:
__int64 __fastcall get_fg_tile_info(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

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

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

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned char attr = ddragon_fgvideoram[2*tile_index];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = (ddragon_fgvideoram[2*tile_index+1] + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr >> 5)]; 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; }


original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 const struct rectangle *clip = &Machine->visible_area;
 const struct GfxElement *gfx = Machine->gfx[1];
 unsigned char *src = &( ddragon_spriteram[0x800] );
 int i;
 for( i = 0; i < ( 64 * 5 ); i += 5 ) {
  int attr = src[i+1];
  if ( attr & 0x80 ) {
   int sx = 240 - src[i+4] + ( ( attr & 2 ) << 7 );
   int sy = 240 - src[i+0] + ( ( attr & 1 ) << 8 );
   int size = ( attr & 0x30 ) >> 4;
   int flipx = ( attr & 8 );
   int flipy = ( attr & 4 );
   int dx = -16,dy = -16;
   int which;
   int color;
   if ( dd2_video ) {
    color = ( src[i+2] >> 5 );
    which = src[i+3] + ( ( src[i+2] & 0x1f ) << 8 );
   } else {
    color = ( src[i+2] >> 4 ) & 0x07;
    which = src[i+3] + ( ( src[i+2] & 0x0f ) << 8 );
   }
   if (flip_screen_x)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
    dx = -dx;
    dy = -dy;
   }
   switch ( size ) {
    case 0:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 1:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 2:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 3:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+3),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
   }
  }
 }
}

canonical_original_code:
static void draw_sprites(struct osd_bitmap *bitmap)
{
 struct rectangle *clip = &Machine->visible_area;
 struct GfxElement *gfx = Machine->gfx[1];
 unsigned char *src = &( ddragon_spriteram[0x800] );
 int i;
 for( i = 0; i < ( 64 * 5 ); i += 5 ) {
  int attr = src[i+1];
  if ( attr & 0x80 ) {
   int sx = 240 - src[i+4] + ( ( attr & 2 ) << 7 );
   int sy = 240 - src[i+0] + ( ( attr & 1 ) << 8 );
   int size = ( attr & 0x30 ) >> 4;
   int flipx = ( attr & 8 );
   int flipy = ( attr & 4 );
   int dx = -16; int dy = -16;
   int which;
   int color;
   if ( dd2_video ) {
    color = ( src[i+2] >> 5 );
    which = src[i+3] + ( ( src[i+2] & 0x1f ) << 8 );
   } else {
    color = ( src[i+2] >> 4 ) & 0x07;
    which = src[i+3] + ( ( src[i+2] & 0x0f ) << 8 );
   }
   if (flip_screen_x)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
    dx = -dx;
    dy = -dy;
   }
   switch ( size ) {
    case 0:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 1:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 2:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
    case 3:
    drawgfx( bitmap, gfx, (which+0),color,flipx,flipy,sx + dx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+1),color,flipx,flipy,sx + dx,sy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+2),color,flipx,flipy,sx,sy + dy, clip,TRANSPARENCY_PEN,0);;
    drawgfx( bitmap, gfx, (which+3),color,flipx,flipy,sx,sy, clip,TRANSPARENCY_PEN,0);;
    break;
   }
  }
 }
}

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

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

variable_types:
src
unsigned char *

variable_types: i int

variable_types: attr int

variable_types: sx int

variable_types: sy int

variable_types: size int

variable_types: flipx int

variable_types: flipy int

variable_types: dx int

variable_types: dy int

variable_types: which int

variable_types: color int


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

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

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

variable_types: irq int


decompiled_code:
__int64 cpu_sound_command_w()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, (unsigned int)sound_irq);
}

canonical_decompiled_code:
__int64 func16()
{
soundlatch_w();
return cpu_cause_interrupt(2LL, (unsigned int)sound_irq);
}

original_code:
static void cpu_sound_command_w(offs_t offset,data_t data)
{
 soundlatch_w( offset, data );
 cpu_cause_interrupt( 2, sound_irq );
}

canonical_original_code:
static void cpu_sound_command_w(unsigned int offset, unsigned int data)
{
 soundlatch_w( offset, data );
 cpu_cause_interrupt( 2, sound_irq );
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 gorf_sh_start()
{
__int64 v0; // rbx

v0 = Machine;
*(_QWORD *)(v0 + 848) = readsamples(gorf_sample_names, *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
GorfBaseFrequency = 11025;
GorfBaseVolume = 230;
GorfChannel = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx

v0 = Machine;
*(_QWORD *)(v0 + 848) = readsamples(gorf_sample_names, *(_QWORD *)(*(_QWORD *)(Machine + 816LL) + 16LL));
GorfBaseFrequency = 11025;
GorfBaseVolume = 230;
GorfChannel = 0;
return 0LL;
}

original_code:
int gorf_sh_start(const struct MachineSound *msound)
{
 Machine->samples = readsamples(gorf_sample_names,Machine->gamedrv->name);
    GorfBaseFrequency = 11025;
    GorfBaseVolume = 230;
    GorfChannel = 0;
    return 0;
}

canonical_original_code:
int gorf_sh_start(struct MachineSound *msound)
{
 Machine->samples = readsamples(gorf_sample_names,Machine->gamedrv->name);
    GorfBaseFrequency = 11025;
    GorfBaseVolume = 230;
    GorfChannel = 0;
    return 0;
}

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

return_type: int


decompiled_code:
__int64 gorf_speech_r()
{
unsigned int v0; // er14
const char *v1; // rsi
__int64 v2; // rbx
const char *v3; // rdi

totalword_ptr = totalword;
v0 = (unsigned int)cpu_get_reg(4LL) >> 8;
if ( (v0 & 0x3F) != 63 )
{
v1 = PhonemeTable[v0 & 0x3F];
if ( totalword[0] )
{
strcat(totalword, v1);
}
else
{
strcpy(totalword, v1);
if ( plural )
{
if ( totalword[0] == 83 && !totalword[1] )
{
sample_start(GorfChannel, 117LL, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
oldword[0] = 0;
return v0;
}
plural = 0;
}
}
v2 = 0LL;
v3 = "A2AYY1";
while ( strcmp(v3, totalword) )
{
v3 = GorfWordTable[++v2];
if ( !v3 )
return v0;
}
if ( !strcmp("GDTO1RFYA2N", totalword)
|| !strcmp("RO1U1BAH1T", totalword)
|| !strcmp("KO1UH3I3E1N", totalword)
|| !strcmp("WORAYY1EH3R", totalword)
|| totalword[0] == 73 && totalword[1] == 78 && !totalword[2] )
{
plural = v2 + 1;
strcpy(oldword, totalword);
}
else
{
plural = 0;
}
sample_start(GorfChannel, (unsigned int)v2, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
return v0;
}
sample_stop(GorfChannel);
totalword[0] = 0;
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er14
const char *v1; // rsi
__int64 v2; // rbx
const char *v3; // rdi

totalword_ptr = totalword;
v0 = (unsigned int)cpu_get_reg(4LL) >> 8;
if ( (v0 & 0x3F) != 63 )
{
v1 = PhonemeTable[v0 & 0x3F];
if ( totalword[0] )
{
strcat(totalword, v1);
}
else
{
strcpy(totalword, v1);
if ( plural )
{
if ( totalword[0] == 83 && !totalword[1] )
{
sample_start(GorfChannel, 117LL, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
oldword[0] = 0;
return v0;
}
plural = 0;
}
}
v2 = 0LL;
v3 = "A2AYY1";
while ( strcmp(v3, totalword) )
{
v3 = GorfWordTable[++v2];
if ( !v3 )
return v0;
}
if ( !strcmp("GDTO1RFYA2N", totalword)
|| !strcmp("RO1U1BAH1T", totalword)
|| !strcmp("KO1UH3I3E1N", totalword)
|| !strcmp("WORAYY1EH3R", totalword)
|| totalword[0] == 73 && totalword[1] == 78 && !totalword[2] )
{
plural = v2 + 1;
strcpy(oldword, totalword);
}
else
{
plural = 0;
}
sample_start(GorfChannel, (unsigned int)v2, 0LL);
sample_set_freq(GorfChannel, GorfBaseFrequency);
totalword[0] = 0;
return v0;
}
sample_stop(GorfChannel);
totalword[0] = 0;
return v0;
}

original_code:
data_t gorf_speech_r(offs_t offset)
{
    int Phoneme,Intonation;
    int i = 0;
 int data;
    totalword_ptr = totalword;
 data = cpu_get_reg(Z80_BC) >> 8;
    Phoneme = data & 0x3F;
    Intonation = data >> 6;
  if(Phoneme==63) {
     sample_stop(GorfChannel);
                totalword[0] = 0;
      return data;
    }
  if (strlen(totalword) == 0) {
   strcpy(totalword,PhonemeTable[Phoneme]);
   if (plural != 0) {
    if (!strcmp("S",totalword)) {
     sample_start(GorfChannel, (sizeof(GorfWordTable)/sizeof(char *))-2, 0);
     sample_set_freq(GorfChannel, GorfBaseFrequency);
     totalword[0] = 0;
     oldword[0] = 0;
     return data;
    } else {
     plural=0;
    }
   }
  } else
   strcat(totalword,PhonemeTable[Phoneme]);
  for (i=0; GorfWordTable[i]; i++) {
   if (!strcmp(GorfWordTable[i],totalword)) {
    if ((!strcmp("GDTO1RFYA2N",totalword)) || (!strcmp("RO1U1BAH1T",totalword)) || (!strcmp("KO1UH3I3E1N",totalword)) || (!strcmp("WORAYY1EH3R",totalword)) || (!strcmp("IN",totalword)) ) {
     plural=i+1;
     strcpy(oldword,totalword);
    } else {
             plural=0;
          }
          sample_start(GorfChannel, i, 0);
          sample_set_freq(GorfChannel, GorfBaseFrequency);
          totalword[0] = 0;
          return data;
       }
    }
  return data;
}

canonical_original_code:
unsigned int gorf_speech_r(unsigned int offset)
{
    int Phoneme; int Intonation;
    int i = 0;
 int data;
    totalword_ptr = totalword;
 data = cpu_get_reg(Z80_BC) >> 8;
    Phoneme = data & 0x3F;
    Intonation = data >> 6;
  if(Phoneme==63) {
     sample_stop(GorfChannel);
                totalword[0] = 0;
      return data;
    }
  if (strlen(totalword) == 0) {
   strcpy(totalword,PhonemeTable[Phoneme]);
   if (plural != 0) {
    if (!strcmp("S",totalword)) {
     sample_start(GorfChannel, (sizeof(GorfWordTable)/sizeof(char *))-2, 0);
     sample_set_freq(GorfChannel, GorfBaseFrequency);
     totalword[0] = 0;
     oldword[0] = 0;
     return data;
    } else {
     plural=0;
    }
   }
  } else
   strcat(totalword,PhonemeTable[Phoneme]);
  for (i=0; GorfWordTable[i]; i++) {
   if (!strcmp(GorfWordTable[i],totalword)) {
    if ((!strcmp("GDTO1RFYA2N",totalword)) || (!strcmp("RO1U1BAH1T",totalword)) || (!strcmp("KO1UH3I3E1N",totalword)) || (!strcmp("WORAYY1EH3R",totalword)) || (!strcmp("IN",totalword)) ) {
     plural=i+1;
     strcpy(oldword,totalword);
    } else {
             plural=0;
          }
          sample_start(GorfChannel, i, 0);
          sample_set_freq(GorfChannel, GorfBaseFrequency);
          totalword[0] = 0;
          return data;
       }
    }
  return data;
}

variable_types: Phoneme int

variable_types: Intonation int

variable_types: data int

return_type: unsigned int


decompiled_code:
_BOOL8 gorf_status_r()
{
return (unsigned int)sample_playing(GorfChannel) == 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return (unsigned int)sample_playing(GorfChannel) == 0;
}

original_code:
int gorf_status_r(void)
{
    return !sample_playing(GorfChannel);
}

canonical_original_code:
int gorf_status_r()
{
    return !sample_playing(GorfChannel);
}


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

v0 = input_port_2_r(0LL) & 0x7F;
if ( gorf_status_r() )
v0 += 128;
return v0;
}

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

v0 = input_port_2_r(0LL) & 0x7F;
if ( func2() )
v0 += 128;
return v0;
}

original_code:
data_t gorf_port_2_r(offs_t offset)
{
    int Ans;
    Ans = (input_port_2_r(0) & 0x7F);
    if (gorf_status_r() != 0) Ans += 128;
    return Ans;
}

canonical_original_code:
unsigned int gorf_port_2_r(unsigned int offset)
{
    int Ans;
    Ans = (input_port_2_r(0) & 0x7F);
    if (gorf_status_r() != 0) Ans += 128;
    return Ans;
}

variable_types: Ans int


decompiled_code:
void gorf_sh_update()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void gorf_sh_update(void)
{
}

canonical_original_code:
void gorf_sh_update()
{
}


original_code:
static void K005289_update(int ch, INT16 *buffer, int length)
{
 k005289_sound_channel *voice=channel_list;
 short *mix;
 int i,v,f;
 memset(mixer_buffer, 0, length * sizeof(INT16));
 v=voice[0].volume;
 f=voice[0].frequency;
 if (v && f)
 {
  const unsigned char *w = voice[0].wave;
  int c = voice[0].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[0].counter = c;
 }
 v=voice[1].volume;
 f=voice[1].frequency;
 if (v && f)
 {
  const unsigned char *w = voice[1].wave;
  int c = voice[1].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[1].counter = c;
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

canonical_original_code:
static void K005289_update(int ch, short *buffer, int length)
{
 struct k005289_sound_channel *voice = channel_list;
 short *mix;
 int i; int v; int f;
 memset(mixer_buffer, 0, length * sizeof(INT16));
 v=voice[0].volume;
 f=voice[0].frequency;
 if (v && f)
 {
  unsigned char *w = voice[0].wave;
  int c = voice[0].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[0].counter = c;
 }
 v=voice[1].volume;
 f=voice[1].frequency;
 if (v && f)
 {
  unsigned char *w = voice[1].wave;
  int c = voice[1].counter;
  mix = mixer_buffer;
  for (i = 0; i < length; i++)
  {
   int offs;
   c+=(long)((((float)mclock / (float)(f * 16))*(float)(1<<16)) / (float)(rate / 32));
   offs = (c >> 16) & 0x1f;
   *mix++ += ((w[offs] & 0x0f) - 8) * v;
  }
  voice[1].counter = c;
 }
 mix = mixer_buffer;
 for (i = 0; i < length; i++)
  *buffer++ = mixer_lookup[*mix++];
}

variable_types: ch int

variable_types:
buffer
short *

variable_types: length int

variable_types: struct k005289_sound_channel { int frequency; int counter; int volume; unsigned char *wave; } *

variable_types:
mix
short *

variable_types: i int

variable_types: v int

variable_types: f int

variable_types:
w
unsigned char *

variable_types: c int

variable_types: offs int


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

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
LODWORD(channel_list) = k005289_A_frequency;
LODWORD(qword_518) = k005289_B_frequency;
dword_508 = k005289_A_volume;
dword_520 = k005289_B_volume;
qword_510 = sound_prom + 32 * k005289_A_waveform;
result = sound_prom + 32 * k005289_B_waveform + 256;
qword_528 = result;
return result;
}

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

if ( !fast_sound )
stream_update((unsigned int)stream, 0LL);
LODWORD(channel_list) = k005289_A_frequency;
LODWORD(qword_518) = k005289_B_frequency;
dword_508 = k005289_A_volume;
dword_520 = k005289_B_volume;
qword_510 = sound_prom + 32 * k005289_A_waveform;
result = sound_prom + 32 * k005289_B_waveform + 256;
qword_528 = result;
return result;
}

original_code:
static void k005289_recompute(void)
{
 k005289_sound_channel *voice = channel_list;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 voice[0].frequency = k005289_A_frequency;
 voice[1].frequency = k005289_B_frequency;
 voice[0].volume = k005289_A_volume;
 voice[1].volume = k005289_B_volume;
 voice[0].wave = &sound_prom[32 * k005289_A_waveform];
 voice[1].wave = &sound_prom[32 * k005289_B_waveform + 0x100];
}

canonical_original_code:
static void k005289_recompute()
{
 struct k005289_sound_channel *voice = channel_list;
    {
        extern int fast_sound;
        if (!fast_sound) stream_update(stream,0);
    }
 voice[0].frequency = k005289_A_frequency;
 voice[1].frequency = k005289_B_frequency;
 voice[0].volume = k005289_A_volume;
 voice[1].volume = k005289_B_volume;
 voice[0].wave = &sound_prom[32 * k005289_A_waveform];
 voice[1].wave = &sound_prom[32 * k005289_B_waveform + 0x100];
}

user_defined_types: struct k005289_sound_channel { int frequency; int counter; int volume; unsigned char *wave; }


decompiled_code:
__int64 __fastcall K005289_sh_start(__int64 a1)
{
__int64 v1; // rbx
void *v2; // rax
void *v3; // rbp
unsigned int v4; // er12
__int64 v5; // rax

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K005289", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K005289_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1;
v3 = v2;
v4 = make_mixer_table_constprop_0();
if ( !v4 )
{
v5 = memory_region(*(unsigned int *)(v1 + 8));
channel_list = 0LL;
sound_prom = v5;
qword_510 = v5;
dword_508 = 0;
qword_528 = v5 + 256;
qword_518 = 0LL;
dword_520 = 0;
return v4;
}
free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
void *v2; // rax
void *v3; // rbp
unsigned int v4; // er12
__int64 v5; // rax

v1 = *(_QWORD *)(a1 + 8);
stream = stream_init("K005289", *(unsigned int *)(v1 + 4), *(unsigned int *)(Machine + 836LL), 0LL, K005289_update);
mclock = *(_DWORD *)v1;
rate = *(_DWORD *)(Machine + 836LL);
v2 = malloc(4LL * rate);
mixer_buffer = v2;
if ( !v2 )
return 1;
v3 = v2;
v4 = func2();
if ( !v4 )
{
v5 = memory_region(*(unsigned int *)(v1 + 8));
channel_list = 0LL;
sound_prom = v5;
qword_510 = v5;
dword_508 = 0;
qword_528 = v5 + 256;
qword_518 = 0LL;
dword_520 = 0;
return v4;
}
free(v3);
return 1LL;
}

original_code:
int K005289_sh_start(const struct MachineSound *msound)
{
 const char *snd_name = "K005289";
 k005289_sound_channel *voice=channel_list;
 const struct k005289_interface *intf = (const struct k005289_interface *)msound->sound_interface;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K005289_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short int*)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(2))
 {
  free(mixer_buffer);
  return 1;
 }
 sound_prom = memory_region(intf->region);
 voice[0].frequency = 0;
 voice[0].volume = 0;
 voice[0].wave = &sound_prom[0];
 voice[0].counter = 0;
 voice[1].frequency = 0;
 voice[1].volume = 0;
 voice[1].wave = &sound_prom[0x100];
 voice[1].counter = 0;
 return 0;
}

canonical_original_code:
int K005289_sh_start(struct MachineSound *msound)
{
 char *snd_name = "K005289";
 struct k005289_sound_channel *voice = channel_list;
 struct k005289_interface *intf = (const struct k005289_interface *)msound->sound_interface;
 stream = stream_init(snd_name, intf->volume, Machine->sample_rate, 0, K005289_update);
 mclock = intf->master_clock;
 rate = Machine->sample_rate;
 if ((mixer_buffer = (short *)malloc(2 * sizeof(short) * Machine->sample_rate)) == 0)
  return 1;
 if (make_mixer_table(2))
 {
  free(mixer_buffer);
  return 1;
 }
 sound_prom = memory_region(intf->region);
 voice[0].frequency = 0;
 voice[0].volume = 0;
 voice[0].wave = &sound_prom[0];
 voice[0].counter = 0;
 voice[1].frequency = 0;
 voice[1].volume = 0;
 voice[1].wave = &sound_prom[0x100];
 voice[1].counter = 0;
 return 0;
}

variable_types: struct k005289_interface { int master_clock; int volume; int region; } *

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


decompiled_code:
void K005289_sh_stop()
{
free(mixer_table);
free(mixer_buffer);
}

canonical_decompiled_code:
void func4()
{
free(mixer_table);
free(mixer_buffer);
}

original_code:
void K005289_sh_stop(void)
{
 free(mixer_table);
 free(mixer_buffer);
}


decompiled_code:
__int64 __fastcall k005289_control_A_w(__int64 a1, unsigned int a2)
{
k005289_A_waveform = a2 >> 5;
k005289_A_volume = a2 & 0xF;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
k005289_A_waveform = a2 >> 5;
k005289_A_volume = a2 & 0xF;
return func1();
}

original_code:
void k005289_control_A_w(offs_t offset,data_t data)
{
 k005289_A_volume=data&0xf;
 k005289_A_waveform=data>>5;
 k005289_recompute();
}

canonical_original_code:
void k005289_control_A_w(unsigned int offset, unsigned int data)
{
 k005289_A_volume=data&0xf;
 k005289_A_waveform=data>>5;
 k005289_recompute();
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall k005289_control_B_w(__int64 a1, unsigned int a2)
{
k005289_B_waveform = a2 >> 5;
k005289_B_volume = a2 & 0xF;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
k005289_B_waveform = a2 >> 5;
k005289_B_volume = a2 & 0xF;
return func1();
}

original_code:
void k005289_control_B_w(offs_t offset,data_t data)
{
 k005289_B_volume=data&0xf;
 k005289_B_waveform=data>>5;
 k005289_recompute();
}

canonical_original_code:
void k005289_control_B_w(unsigned int offset, unsigned int data)
{
 k005289_B_volume=data&0xf;
 k005289_B_waveform=data>>5;
 k005289_recompute();
}


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

result = (unsigned int)(4096 - a1);
k005289_A_latch = 4096 - a1;
return result;
}

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

result = (unsigned int)(4096 - a1);
k005289_A_latch = 4096 - a1;
return result;
}

original_code:
void k005289_pitch_A_w(offs_t offset,data_t data)
{
 k005289_A_latch = 0x1000 - offset;
}

canonical_original_code:
void k005289_pitch_A_w(unsigned int offset, unsigned int data)
{
 k005289_A_latch = 0x1000 - offset;
}


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

result = (unsigned int)(4096 - a1);
k005289_B_latch = 4096 - a1;
return result;
}

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

result = (unsigned int)(4096 - a1);
k005289_B_latch = 4096 - a1;
return result;
}

original_code:
void k005289_pitch_B_w(offs_t offset,data_t data)
{
 k005289_B_latch = 0x1000 - offset;
}

canonical_original_code:
void k005289_pitch_B_w(unsigned int offset, unsigned int data)
{
 k005289_B_latch = 0x1000 - offset;
}


decompiled_code:
__int64 k005289_keylatch_A_w()
{
k005289_A_frequency = k005289_A_latch;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 func9()
{
k005289_A_frequency = k005289_A_latch;
return func1();
}

original_code:
void k005289_keylatch_A_w(offs_t offset,data_t data)
{
 k005289_A_frequency = k005289_A_latch;
 k005289_recompute();
}

canonical_original_code:
void k005289_keylatch_A_w(unsigned int offset, unsigned int data)
{
 k005289_A_frequency = k005289_A_latch;
 k005289_recompute();
}


decompiled_code:
__int64 k005289_keylatch_B_w()
{
k005289_B_frequency = k005289_B_latch;
return k005289_recompute();
}

canonical_decompiled_code:
__int64 func10()
{
k005289_B_frequency = k005289_B_latch;
return func1();
}

original_code:
void k005289_keylatch_B_w(offs_t offset,data_t data)
{
 k005289_B_frequency = k005289_B_latch;
 k005289_recompute();
}

canonical_original_code:
void k005289_keylatch_B_w(unsigned int offset, unsigned int data)
{
 k005289_B_frequency = k005289_B_latch;
 k005289_recompute();
}


decompiled_code:
void __fastcall leprechn_graphics_command_w(__int64 a1, int a2)
{
last_command = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
last_command = a2;
}

original_code:
void leprechn_graphics_command_w(offs_t offset,data_t data)
{
    last_command = data;
}

canonical_original_code:
void leprechn_graphics_command_w(unsigned int offset, unsigned int data)
{
    last_command = data;
}


decompiled_code:
__int64 leprechn_graphics_data_r()
{
return *(unsigned __int8 *)(videoram + x + screen_width * y);
}

canonical_decompiled_code:
__int64 func1()
{
return *(unsigned __int8 *)(videoram + x + screen_width * y);
}

original_code:
data_t leprechn_graphics_data_r(offs_t offset)
{
    return videoram[y * screen_width + x];
}

canonical_original_code:
unsigned int leprechn_graphics_data_r(unsigned int offset)
{
    return videoram[y * screen_width + x];
}


decompiled_code:
void __fastcall leprechn_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // eax
int v3; // er14
__int64 v4; // rdx
unsigned int v5; // er13
__int64 v6; // rdi
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rdx

if ( a2 )
{
v2 = screen_width;
if ( screen_width > 0 )
{
v3 = 0;
do
{
v4 = Machine;
if ( *(int *)(*(_QWORD *)(Machine + 824LL) + 668LL) > 0 )
{
v5 = 0;
do
{
v6 = *(_QWORD *)(v4 + 768);
v7 = *(unsigned __int8 *)(videoram + (int)(v3 + v5 * v2));
v8 = *(_QWORD *)(v4 + 792);
v9 = v5++;
plot_pixel(v6, (unsigned int)v3, v9, *(unsigned __int16 *)(v8 + 2 * v7));
v4 = Machine;
v2 = screen_width;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) > (signed int)v5 );
}
++v3;
}
while ( v3 < v2 );
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
int v2; // eax
int v3; // er14
__int64 v4; // rdx
unsigned int v5; // er13
__int64 v6; // rdi
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rdx

if ( a2 )
{
v2 = screen_width;
if ( screen_width > 0 )
{
v3 = 0;
do
{
v4 = Machine;
if ( *(int *)(*(_QWORD *)(Machine + 824LL) + 668LL) > 0 )
{
v5 = 0;
do
{
v6 = *(_QWORD *)(v4 + 768);
v7 = *(unsigned __int8 *)(videoram + (int)(v3 + v5 * v2));
v8 = *(_QWORD *)(v4 + 792);
v9 = v5++;
plot_pixel(v6, (unsigned int)v3, v9, *(unsigned __int16 *)(v8 + 2 * v7));
v4 = Machine;
v2 = screen_width;
}
while ( *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL) > (signed int)v5 );
}
++v3;
}
while ( v3 < v2 );
}
}
}

original_code:
void leprechn_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 if (full_refresh)
 {
  int sx, sy;
  for (sx = 0; sx < screen_width; sx++)
  {
   for (sy = 0; sy < Machine->drv->screen_height; sy++)
   {
    plot_pixel(Machine->scrbitmap, sx, sy, Machine->pens[videoram[sy * screen_width + sx]]);
   }
  }
 }
}

canonical_original_code:
void leprechn_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 if (full_refresh)
 {
  int sx; int sy;
  for (sx = 0; sx < screen_width; sx++)
  {
   for (sy = 0; sy < Machine->drv->screen_height; sy++)
   {
    plot_pixel(Machine->scrbitmap, sx, sy, Machine->pens[videoram[sy * screen_width + sx]]);
   }
  }
 }
}

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

variable_types: sx int

variable_types: sy int


decompiled_code:
void __fastcall leprechn_input_port_select_w(__int64 a1, char a2)
{
input_port_select = a2;
}

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

original_code:
static void leprechn_input_port_select_w(offs_t offset,data_t data)
{
    input_port_select = data;
}

canonical_original_code:
static void leprechn_input_port_select_w(unsigned int offset, unsigned int data)
{
    input_port_select = data;
}


decompiled_code:
__int64 leprechn_200d_r()
{
return 2LL;
}

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

original_code:
static data_t leprechn_200d_r(offs_t offset)
{
    return 0x02;
}

canonical_original_code:
static unsigned int leprechn_200d_r(unsigned int offset)
{
    return 0x02;
}


decompiled_code:
__int64 leprechn_0805_r()
{
return 192LL;
}

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

original_code:
static data_t leprechn_0805_r(offs_t offset)
{
    return 0xc0;
}

canonical_original_code:
static unsigned int leprechn_0805_r(unsigned int offset)
{
    return 0xc0;
}


decompiled_code:
__int64 __fastcall leprechn_graphics_data_w(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v3; // ebx
unsigned __int8 v4; // dl

if ( pending )
{
plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned int)pending_x,
(unsigned int)pending_y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * pending_color));
pending = 0;
*((_BYTE *)videoram + pending_x + screen_width * pending_y) = pending_color;
}
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, screen_width * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL));
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
{
v4 = x;
LOBYTE(result) = y;
switch ( (unsigned __int8)a2 >> 4 )
{
case 0:
case 4:
case 8:
case 12:
goto LABEL_15;
case 1:
case 9:
v4 = x + 1;
goto LABEL_15;
case 2:
case 6:
goto LABEL_17;
case 3:
v4 = x + 1;
LABEL_17:
LOBYTE(result) = y + 1;
goto LABEL_15;
case 5:
case 13:
v4 = x - 1;
goto LABEL_15;
case 7:
v4 = x - 1;
LOBYTE(result) = y + 1;
goto LABEL_15;
case 10:
case 14:
goto LABEL_14;
case 11:
v4 = x + 1;
LOBYTE(result) = y - 1;
goto LABEL_15;
case 15:
v4 = x - 1;
LABEL_14:
LOBYTE(result) = y - 1;
LABEL_15:
result = (unsigned __int8)result;
pending_color = a2 & 0xF;
x = v4;
y = result;
pending = 1;
pending_x = v4;
pending_y = (unsigned __int8)result;
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v3; // ebx
unsigned __int8 v4; // dl

if ( pending )
{
plot_pixel(
*(_QWORD *)(Machine + 768LL),
(unsigned int)pending_x,
(unsigned int)pending_y,
*(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * pending_color));
pending = 0;
*((_BYTE *)videoram + pending_x + screen_width * pending_y) = pending_color;
}
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, screen_width * *(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 668LL));
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
{
v4 = x;
LOBYTE(result) = y;
switch ( (unsigned __int8)a2 >> 4 )
{
case 0:
case 4:
case 8:
case 12:
goto LABEL_15;
case 1:
case 9:
v4 = x + 1;
goto LABEL_15;
case 2:
case 6:
goto LABEL_17;
case 3:
v4 = x + 1;
LABEL_17:
LOBYTE(result) = y + 1;
goto LABEL_15;
case 5:
case 13:
v4 = x - 1;
goto LABEL_15;
case 7:
v4 = x - 1;
LOBYTE(result) = y + 1;
goto LABEL_15;
case 10:
case 14:
goto LABEL_14;
case 11:
v4 = x + 1;
LOBYTE(result) = y - 1;
goto LABEL_15;
case 15:
v4 = x - 1;
LABEL_14:
LOBYTE(result) = y - 1;
LABEL_15:
result = (unsigned __int8)result;
pending_color = a2 & 0xF;
x = v4;
y = result;
pending = 1;
pending_x = v4;
pending_y = (unsigned __int8)result;
break;
}
}
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;
}


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

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

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


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


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

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

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


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
__int64 v3; // rax
void *result; // rax
unsigned int v5; // eax

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
v3 = v2 + 0x10000;
else
v3 = v2 + 40960;
cpu_bankbase[1] = v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
return result;
}

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

v2 = memory_region(130LL);
if ( (a2 & 4) != 0 )
v3 = v2 + 0x10000;
else
v3 = v2 + 40960;
cpu_bankbase[1] = v3;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v5 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v5);
}
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:
// attributes: thunk
__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)(ddrB & portB_out) | (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)(ddrB & portB_out) | (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);
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall qix_vh_screenrefresh(__int64 a1, int a2)
{
__int64 result; // rax
__int64 i; // rbx
__int64 v4; // rsi
__int64 v5; // rcx
int v6; // edx

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

canonical_decompiled_code:
__int64 __fastcall func35(__int64 a1, int a2)
{
__int64 result; // rax
__int64 i; // rbx
__int64 v4; // rsi
__int64 v5; // rcx
int v6; // edx

result = palette_recalc();
if ( result || a2 )
{
for ( i = 0LL; i != 0x10000; ++i )
{
v4 = (unsigned __int8)i;
v5 = *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * *((unsigned __int8 *)videoram + i));
v6 = i;
result = plot_pixel(a1, v4, (unsigned int)(v6 >> 8), v5);
}
}
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: offs int

variable_types: x int

variable_types: y int

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


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

canonical_decompiled_code:
void *__fastcall func36(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, 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:
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 v1; // rax
__int64 v3; // [rsp+0h] [rbp-18h]

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

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

v0 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v3) = 32;
background = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, v3);
foreground = v1;
if ( !v1 || !background )
return 1LL;
*(_DWORD *)(background + 132) = 0;
*(_DWORD *)(v1 + 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: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: fullrefresh int


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
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // 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);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 0x1F);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdi
char v2; // cl
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // 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);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 0x1F);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_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
unsigned int v3; // edx
char v4; // al
__int64 v5; // rdi
int v6; // eax
__int64 v7; // 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) + (int)(v3 * *(_DWORD *)(v2 + 52));
v4 = *(_BYTE *)(colorram + 2LL * (a1 & 0x1F) + 1);
v5 = *(_QWORD *)(v2 + 16);
v6 = *(_DWORD *)(v2 + 12) * (v4 & 0x1F);
v7 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v3);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
unsigned int v1; // eax
__int64 v2; // rcx
unsigned int v3; // edx
char v4; // al
__int64 v5; // rdi
int v6; // eax
__int64 v7; // 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) + (int)(v3 * *(_DWORD *)(v2 + 52));
v4 = *(_BYTE *)(colorram + 2LL * (a1 & 0x1F) + 1);
v5 = *(_QWORD *)(v2 + 16);
v6 = *(_DWORD *)(v2 + 12) * (v4 & 0x1F);
v7 = *(_QWORD *)(v2 + 32);
*((_QWORD *)&tile_info + 1) = v5 + 2LL * v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 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; }
}


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


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)
{
Timer[2 * (a1 & 0x7F) + (a1 >> 7)] = 0LL;
return YM2608TimerOver(a1 & 0x7F);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
Timer[2 * (a1 & 0x7F) + (a1 >> 7)] = 0LL;
return YM2608TimerOver(a1 & 0x7F);
}

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 func3(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 func5()
{
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
__int64 v2; // rdi

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

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
unsigned int v1; // ebx
__int64 v2; // rdi

result = *(unsigned int *)intf;
if ( (int)result > 0 )
{
v1 = 0;
do
{
v2 = v1++;
YM2608ResetChip(v2);
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 func7()
{
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 func8()
{
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 func9()
{
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 func10()
{
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 func11()
{
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 func12()
{
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 func13(__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 func14(__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 func15(__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 func16(__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 func17(__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 func18(__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 func19(__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 func20(__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_588 = 0LL;
Timer = 0LL;
qword_598 = 0LL;
qword_590 = 0LL;
}

canonical_decompiled_code:
void func0()
{
qword_588 = 0LL;
Timer = 0LL;
qword_598 = 0LL;
qword_590 = 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;
}