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

result = highspeed_flag;
sound_flags_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
return result;
}

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

result = highspeed_flag;
sound_flags_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
return result;
}

original_code:
void change_sound_flags( int port )
{
  sound_flags_update = (int)port;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

canonical_original_code:
void change_sound_flags(int port)
{
  sound_flags_update = (int)port;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

variable_types: port int


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

result = highspeed_flag;
sound_prescaler_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
return result;
}

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

result = highspeed_flag;
sound_prescaler_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
return result;
}

original_code:
void change_sound_prescaler( int new_prescaler )
{
  sound_prescaler_update = new_prescaler;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

canonical_original_code:
void change_sound_prescaler(int new_prescaler)
{
  sound_prescaler_update = new_prescaler;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

return_type: void


decompiled_code:
__int64 interval_work_set_BDRY()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(2 * sound2_intr_base) * (0.25 * *(double *)&cpu_clock_mhz);
result = (unsigned int)(int)v0;
sd2_BRDY_intr_base = (int)v0;
sd2_BRDY_intr_timer = (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(2 * sound2_intr_base) * (0.25 * *(double *)&cpu_clock_mhz);
result = (unsigned int)(int)v0;
sd2_BRDY_intr_base = (int)v0;
sd2_BRDY_intr_timer = (int)v0;
return result;
}

original_code:
void interval_work_set_BDRY( void )
{
  sd2_BRDY_intr_base = sound2_intr_base * 2 * ( cpu_clock_mhz / 4.0 );
  sd2_BRDY_intr_timer = sd2_BRDY_intr_base;
}

canonical_original_code:
void interval_work_set_BDRY()
{
  sd2_BRDY_intr_base = sound2_intr_base * 2 * ( cpu_clock_mhz / 4.0 );
  sd2_BRDY_intr_timer = sd2_BRDY_intr_base;
}


decompiled_code:
void __fastcall interval_work_set_EOS(int a1)
{
sd2_EOS_intr_base = sd2_BRDY_intr_base * a1;
sd2_EOS_intr_timer = sd2_BRDY_intr_base * a1;
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
sd2_EOS_intr_base = sd2_BRDY_intr_base * a1;
sd2_EOS_intr_timer = sd2_BRDY_intr_base * a1;
}

original_code:
void interval_work_set_EOS( int length )
{
  sd2_EOS_intr_base = sd2_BRDY_intr_base * length;
  sd2_EOS_intr_timer = sd2_EOS_intr_base;
}

canonical_original_code:
void interval_work_set_EOS(int length)
{
  sd2_EOS_intr_base = sd2_BRDY_intr_base * length;
  sd2_EOS_intr_timer = sd2_EOS_intr_base;
}

variable_types: length int


decompiled_code:
__int64 __fastcall main_INT_update(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // ebp
int v4; // ebx
bool v5; // sf
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // esi
int v13; // eax
int v14; // edx
int v15; // ecx
__int64 result; // rax
int v17; // eax
int v18; // eax
bool v19; // zf

v2 = (unsigned int)z80main_cpu[10];
v3 = SOUND_level;
v4 = rtc_intr_base;
v5 = rs232c_intr_timer - (int)v2 < 0;
v6 = rs232c_intr_timer - v2;
rs232c_intr_timer -= v2;
if ( v5 )
{
rs232c_intr_timer = rs232c_intr_base + v6;
v18 = sio_intr();
v2 = (unsigned int)z80main_cpu[10];
v19 = v18 == 0;
v6 = rs232c_intr_timer;
if ( !v19 )
{
if ( intr_sio_enable )
RS232C_flag = 1;
}
}
if ( v4 > v6 )
v4 = v6;
state_of_cpu += v2;
v5 = vsync_intr_timer - (int)v2 < 0;
v7 = vsync_intr_timer - v2;
vsync_intr_timer -= v2;
if ( v5 )
{
vsync_intr_timer = vsync_intr_base + v7;
vsync();
if ( intr_vsync_enable )
VSYNC_flag = 1;
ctrl_vrtc = 1;
v2 = (unsigned int)z80main_cpu[10];
v17 = vrtc_base;
if ( vsync_intr_timer <= v4 )
v4 = vsync_intr_timer;
goto LABEL_55;
}
if ( v7 <= v4 )
v4 = v7;
v8 = ctrl_vrtc;
if ( ctrl_vrtc == 1 )
{
v17 = vrtc_timer - v2;
LABEL_55:
vrtc_timer = v17;
if ( v17 >= 0 )
goto LABEL_41;
v17 += vrtc_base2;
ctrl_vrtc = 2;
vrtc_timer = v17;
if ( boost_cnt )
goto LABEL_41;
draw_screen(a1, a2, v2);
v8 = ctrl_vrtc;
LODWORD(v2) = z80main_cpu[10];
goto LABEL_9;
}
if ( ctrl_vrtc != 2 )
{
LABEL_9:
if ( v8 > 2 )
goto LABEL_10;
v17 = vrtc_timer;
goto LABEL_41;
}
v5 = vrtc_timer - (int)v2 < 0;
v17 = vrtc_timer - v2;
vrtc_timer -= v2;
if ( v5 )
{
ctrl_vrtc = 3;
vrtc_timer = 0xFFFF;
LABEL_10:
v5 = rtc_intr_timer - (int)v2 < 0;
v9 = rtc_intr_timer - v2;
rtc_intr_timer -= v2;
if ( !v5 )
goto LABEL_11;
goto LABEL_44;
}
LABEL_41:
if ( v4 > v17 )
v4 = v17;
v5 = rtc_intr_timer - (int)v2 < 0;
v9 = rtc_intr_timer - v2;
rtc_intr_timer -= v2;
if ( v5 )
{
LABEL_44:
v9 += rtc_intr_base;
rtc_intr_timer = v9;
if ( intr_rtc_enable )
RTC_flag = 1;
}
LABEL_11:
if ( v4 > v9 )
v4 = v9;
if ( sound_LOAD_A )
{
v5 = sd_A_intr_timer - (int)v2 < 0;
v10 = sd_A_intr_timer - v2;
sd_A_intr_timer -= v2;
if ( v5 )
{
xmame_sound_timer_over(0LL);
v10 = sd_A_intr_timer + sd_A_intr_base;
sd_A_intr_timer += sd_A_intr_base;
if ( sound_ENABLE_A )
sound_FLAG_A = sound2_MSK_TA == 0;
}
if ( v4 > v10 )
v4 = v10;
}
if ( sound_LOAD_B )
{
v5 = sd_B_intr_timer - z80main_cpu[10] < 0;
v11 = sd_B_intr_timer - z80main_cpu[10];
sd_B_intr_timer = v11;
if ( v5 )
{
xmame_sound_timer_over(1LL);
v11 = sd_B_intr_timer + sd_B_intr_base;
sd_B_intr_timer += sd_B_intr_base;
if ( sound_ENABLE_B )
sound_FLAG_B = sound2_MSK_TB == 0;
}
if ( v4 > v11 )
v4 = v11;
}
if ( sound2_FLAG_PCMBSY )
{
v12 = z80main_cpu[10];
v5 = sd2_BRDY_intr_timer - v12 < 0;
v13 = sd2_BRDY_intr_timer - v12;
sd2_BRDY_intr_timer -= v12;
if ( v5 )
{
v13 += sd2_BRDY_intr_base;
sd2_BRDY_intr_timer = v13;
sound2_FLAG_BRDY = sound2_MSK_BRDY == 0;
}
v14 = sound2_notice_EOS;
if ( sound2_notice_EOS )
{
v5 = sd2_EOS_intr_timer - v12 < 0;
v15 = sd2_EOS_intr_timer - v12;
sd2_EOS_intr_timer -= v12;
if ( v5 )
{
sd2_EOS_intr_timer = sd2_EOS_intr_base + v15;
sound2_FLAG_EOS = sound2_MSK_EOS == 0;
if ( !sound2_repeat )
sound2_FLAG_PCMBSY = 0;
sound2_notice_EOS = 0;
v14 = 0;
}
}
if ( v4 > v13 )
v4 = v13;
if ( v4 > v14 )
v4 = v14;
}
check_sound_parm_update();
if ( (sound_FLAG_A && sound2_EN_TA
|| sound_FLAG_B && sound2_EN_TB
|| sound2_FLAG_BRDY && sound2_EN_BRDY
|| sound2_FLAG_EOS && sound2_EN_EOS)
&& intr_sound_enable )
{
SOUND_level = 1;
if ( !v3 )
SOUND_flag = 1;
}
else
{
SOUND_level = 0;
}
set_INT_active();
z80main_cpu[9] = v4;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // ebp
int v4; // ebx
bool v5; // sf
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // esi
int v13; // eax
int v14; // edx
int v15; // ecx
__int64 result; // rax
int v17; // eax
int v18; // eax
bool v19; // zf

v2 = (unsigned int)z80main_cpu[10];
v3 = SOUND_level;
v4 = rtc_intr_base;
v5 = rs232c_intr_timer - (int)v2 < 0;
v6 = rs232c_intr_timer - v2;
rs232c_intr_timer -= v2;
if ( v5 )
{
rs232c_intr_timer = rs232c_intr_base + v6;
v18 = sio_intr();
v2 = (unsigned int)z80main_cpu[10];
v19 = v18 == 0;
v6 = rs232c_intr_timer;
if ( !v19 )
{
if ( intr_sio_enable )
RS232C_flag = 1;
}
}
if ( v4 > v6 )
v4 = v6;
state_of_cpu += v2;
v5 = vsync_intr_timer - (int)v2 < 0;
v7 = vsync_intr_timer - v2;
vsync_intr_timer -= v2;
if ( v5 )
{
vsync_intr_timer = vsync_intr_base + v7;
func3();
if ( intr_vsync_enable )
VSYNC_flag = 1;
ctrl_vrtc = 1;
v2 = (unsigned int)z80main_cpu[10];
v17 = vrtc_base;
if ( vsync_intr_timer <= v4 )
v4 = vsync_intr_timer;
goto LABEL_55;
}
if ( v7 <= v4 )
v4 = v7;
v8 = ctrl_vrtc;
if ( ctrl_vrtc == 1 )
{
v17 = vrtc_timer - v2;
LABEL_55:
vrtc_timer = v17;
if ( v17 >= 0 )
goto LABEL_41;
v17 += vrtc_base2;
ctrl_vrtc = 2;
vrtc_timer = v17;
if ( boost_cnt )
goto LABEL_41;
draw_screen(a1, a2, v2);
v8 = ctrl_vrtc;
LODWORD(v2) = z80main_cpu[10];
goto LABEL_9;
}
if ( ctrl_vrtc != 2 )
{
LABEL_9:
if ( v8 > 2 )
goto LABEL_10;
v17 = vrtc_timer;
goto LABEL_41;
}
v5 = vrtc_timer - (int)v2 < 0;
v17 = vrtc_timer - v2;
vrtc_timer -= v2;
if ( v5 )
{
ctrl_vrtc = 3;
vrtc_timer = 0xFFFF;
LABEL_10:
v5 = rtc_intr_timer - (int)v2 < 0;
v9 = rtc_intr_timer - v2;
rtc_intr_timer -= v2;
if ( !v5 )
goto LABEL_11;
goto LABEL_44;
}
LABEL_41:
if ( v4 > v17 )
v4 = v17;
v5 = rtc_intr_timer - (int)v2 < 0;
v9 = rtc_intr_timer - v2;
rtc_intr_timer -= v2;
if ( v5 )
{
LABEL_44:
v9 += rtc_intr_base;
rtc_intr_timer = v9;
if ( intr_rtc_enable )
RTC_flag = 1;
}
LABEL_11:
if ( v4 > v9 )
v4 = v9;
if ( sound_LOAD_A )
{
v5 = sd_A_intr_timer - (int)v2 < 0;
v10 = sd_A_intr_timer - v2;
sd_A_intr_timer -= v2;
if ( v5 )
{
xmame_sound_timer_over(0LL);
v10 = sd_A_intr_timer + sd_A_intr_base;
sd_A_intr_timer += sd_A_intr_base;
if ( sound_ENABLE_A )
sound_FLAG_A = sound2_MSK_TA == 0;
}
if ( v4 > v10 )
v4 = v10;
}
if ( sound_LOAD_B )
{
v5 = sd_B_intr_timer - z80main_cpu[10] < 0;
v11 = sd_B_intr_timer - z80main_cpu[10];
sd_B_intr_timer = v11;
if ( v5 )
{
xmame_sound_timer_over(1LL);
v11 = sd_B_intr_timer + sd_B_intr_base;
sd_B_intr_timer += sd_B_intr_base;
if ( sound_ENABLE_B )
sound_FLAG_B = sound2_MSK_TB == 0;
}
if ( v4 > v11 )
v4 = v11;
}
if ( sound2_FLAG_PCMBSY )
{
v12 = z80main_cpu[10];
v5 = sd2_BRDY_intr_timer - v12 < 0;
v13 = sd2_BRDY_intr_timer - v12;
sd2_BRDY_intr_timer -= v12;
if ( v5 )
{
v13 += sd2_BRDY_intr_base;
sd2_BRDY_intr_timer = v13;
sound2_FLAG_BRDY = sound2_MSK_BRDY == 0;
}
v14 = sound2_notice_EOS;
if ( sound2_notice_EOS )
{
v5 = sd2_EOS_intr_timer - v12 < 0;
v15 = sd2_EOS_intr_timer - v12;
sd2_EOS_intr_timer -= v12;
if ( v5 )
{
sd2_EOS_intr_timer = sd2_EOS_intr_base + v15;
sound2_FLAG_EOS = sound2_MSK_EOS == 0;
if ( !sound2_repeat )
sound2_FLAG_PCMBSY = 0;
sound2_notice_EOS = 0;
v14 = 0;
}
}
if ( v4 > v13 )
v4 = v13;
if ( v4 > v14 )
v4 = v14;
}
func1();
if ( (sound_FLAG_A && sound2_EN_TA
|| sound_FLAG_B && sound2_EN_TB
|| sound2_FLAG_BRDY && sound2_EN_BRDY
|| sound2_FLAG_EOS && sound2_EN_EOS)
&& intr_sound_enable )
{
SOUND_level = 1;
if ( !v3 )
SOUND_flag = 1;
}
else
{
SOUND_level = 0;
}
func2();
z80main_cpu[9] = v4;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

original_code:
void main_INT_update( void )
{
  int SOUND_level_old = SOUND_level;
  int icount = rtc_intr_base;
  rs232c_intr_timer -= z80main_cpu.state0;
  if( rs232c_intr_timer < 0 ){
    rs232c_intr_timer += rs232c_intr_base;
    if( sio_intr() ){
      if( intr_sio_enable )
 RS232C_flag = (1);
    }
  }
  icount = (((icount)<(rs232c_intr_timer))?(icount):(rs232c_intr_timer));
  state_of_cpu += z80main_cpu.state0;
  vsync_intr_timer -= z80main_cpu.state0;
  if( vsync_intr_timer < 0 ){
    vsync_intr_timer += vsync_intr_base;
    vsync();
    if( intr_vsync_enable )
      VSYNC_flag = (1);
    ctrl_vrtc = 1;
    vrtc_timer = vrtc_base + z80main_cpu.state0;
  }
  icount = (((icount)<(vsync_intr_timer))?(icount):(vsync_intr_timer));
  if( ctrl_vrtc == 1 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 2;
      vrtc_timer += vrtc_base2;
      if( boost_cnt == 0 ){
 draw_screen();
      }
    }
  }else if( ctrl_vrtc == 2 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 3;
      vrtc_timer = 0xffff;
    }
  }
  if( ctrl_vrtc < 3 ) icount = (((icount)<(vrtc_timer))?(icount):(vrtc_timer));
  rtc_intr_timer -= z80main_cpu.state0;
  if( rtc_intr_timer < 0 ){
    rtc_intr_timer += rtc_intr_base;
    if( intr_rtc_enable )
      RTC_flag = (1);
  }
  icount = (((icount)<(rtc_intr_timer))?(icount):(rtc_intr_timer));
  if( sound_LOAD_A ){
    sd_A_intr_timer -= z80main_cpu.state0;
    if( sd_A_intr_timer < 0 ){
      xmame_sound_timer_over(0);
      sd_A_intr_timer += sd_A_intr_base;
      if( sound_ENABLE_A ){
 if( sound2_MSK_TA ) sound_FLAG_A = 0;
 else sound_FLAG_A = 1;
      }
    }
    icount = (((icount)<(sd_A_intr_timer))?(icount):(sd_A_intr_timer));
  }
  if( sound_LOAD_B ){
    sd_B_intr_timer -= z80main_cpu.state0;
    if( sd_B_intr_timer < 0 ){
      xmame_sound_timer_over(1);
      sd_B_intr_timer += sd_B_intr_base;
      if( sound_ENABLE_B ){
 if( sound2_MSK_TB ) sound_FLAG_B = 0;
 else sound_FLAG_B = 1;
      }
    }
    icount = (((icount)<(sd_B_intr_timer))?(icount):(sd_B_intr_timer));
  }
  if( sound2_FLAG_PCMBSY ){
    sd2_BRDY_intr_timer -= z80main_cpu.state0;
    if( sd2_BRDY_intr_timer < 0 ){
      sd2_BRDY_intr_timer += sd2_BRDY_intr_base;
      {
 if( sound2_MSK_BRDY ) sound2_FLAG_BRDY = 0;
 else sound2_FLAG_BRDY = 1;
      }
    }
    icount = (((icount)<(sd2_BRDY_intr_timer))?(icount):(sd2_BRDY_intr_timer));
    if( sound2_notice_EOS ){
      sd2_EOS_intr_timer -= z80main_cpu.state0;
      if( sd2_EOS_intr_timer < 0 ){
 sd2_EOS_intr_timer += sd2_EOS_intr_base;
 if( sound2_MSK_EOS ) sound2_FLAG_EOS = 0;
 else sound2_FLAG_EOS = 1;
 if( !sound2_repeat ) sound2_FLAG_PCMBSY = 0;
 sound2_notice_EOS = (0);
      }
    }
    icount = (((icount)<(sound2_notice_EOS))?(icount):(sound2_notice_EOS));
  }
  check_sound_parm_update();
  if( ( ( sound_FLAG_A && sound2_EN_TA ) ||
 ( sound_FLAG_B && sound2_EN_TB ) ||
 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
 ( sound2_FLAG_EOS && sound2_EN_EOS ) ) && intr_sound_enable ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  if( (SOUND_level_old == (0)) && SOUND_level ){
    SOUND_flag = (1);
  }
  set_INT_active();
  z80main_cpu.icount = icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

canonical_original_code:
void main_INT_update()
{
  int SOUND_level_old = SOUND_level;
  int icount = rtc_intr_base;
  rs232c_intr_timer -= z80main_cpu.state0;
  if( rs232c_intr_timer < 0 ){
    rs232c_intr_timer += rs232c_intr_base;
    if( sio_intr() ){
      if( intr_sio_enable )
 RS232C_flag = (1);
    }
  }
  icount = (((icount)<(rs232c_intr_timer))?(icount):(rs232c_intr_timer));
  state_of_cpu += z80main_cpu.state0;
  vsync_intr_timer -= z80main_cpu.state0;
  if( vsync_intr_timer < 0 ){
    vsync_intr_timer += vsync_intr_base;
    vsync();
    if( intr_vsync_enable )
      VSYNC_flag = (1);
    ctrl_vrtc = 1;
    vrtc_timer = vrtc_base + z80main_cpu.state0;
  }
  icount = (((icount)<(vsync_intr_timer))?(icount):(vsync_intr_timer));
  if( ctrl_vrtc == 1 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 2;
      vrtc_timer += vrtc_base2;
      if( boost_cnt == 0 ){
 draw_screen();
      }
    }
  }else if( ctrl_vrtc == 2 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 3;
      vrtc_timer = 0xffff;
    }
  }
  if( ctrl_vrtc < 3 ) icount = (((icount)<(vrtc_timer))?(icount):(vrtc_timer));
  rtc_intr_timer -= z80main_cpu.state0;
  if( rtc_intr_timer < 0 ){
    rtc_intr_timer += rtc_intr_base;
    if( intr_rtc_enable )
      RTC_flag = (1);
  }
  icount = (((icount)<(rtc_intr_timer))?(icount):(rtc_intr_timer));
  if( sound_LOAD_A ){
    sd_A_intr_timer -= z80main_cpu.state0;
    if( sd_A_intr_timer < 0 ){
      xmame_sound_timer_over(0);
      sd_A_intr_timer += sd_A_intr_base;
      if( sound_ENABLE_A ){
 if( sound2_MSK_TA ) sound_FLAG_A = 0;
 else sound_FLAG_A = 1;
      }
    }
    icount = (((icount)<(sd_A_intr_timer))?(icount):(sd_A_intr_timer));
  }
  if( sound_LOAD_B ){
    sd_B_intr_timer -= z80main_cpu.state0;
    if( sd_B_intr_timer < 0 ){
      xmame_sound_timer_over(1);
      sd_B_intr_timer += sd_B_intr_base;
      if( sound_ENABLE_B ){
 if( sound2_MSK_TB ) sound_FLAG_B = 0;
 else sound_FLAG_B = 1;
      }
    }
    icount = (((icount)<(sd_B_intr_timer))?(icount):(sd_B_intr_timer));
  }
  if( sound2_FLAG_PCMBSY ){
    sd2_BRDY_intr_timer -= z80main_cpu.state0;
    if( sd2_BRDY_intr_timer < 0 ){
      sd2_BRDY_intr_timer += sd2_BRDY_intr_base;
      {
 if( sound2_MSK_BRDY ) sound2_FLAG_BRDY = 0;
 else sound2_FLAG_BRDY = 1;
      }
    }
    icount = (((icount)<(sd2_BRDY_intr_timer))?(icount):(sd2_BRDY_intr_timer));
    if( sound2_notice_EOS ){
      sd2_EOS_intr_timer -= z80main_cpu.state0;
      if( sd2_EOS_intr_timer < 0 ){
 sd2_EOS_intr_timer += sd2_EOS_intr_base;
 if( sound2_MSK_EOS ) sound2_FLAG_EOS = 0;
 else sound2_FLAG_EOS = 1;
 if( !sound2_repeat ) sound2_FLAG_PCMBSY = 0;
 sound2_notice_EOS = (0);
      }
    }
    icount = (((icount)<(sound2_notice_EOS))?(icount):(sound2_notice_EOS));
  }
  check_sound_parm_update();
  if( ( ( sound_FLAG_A && sound2_EN_TA ) ||
 ( sound_FLAG_B && sound2_EN_TB ) ||
 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
 ( sound2_FLAG_EOS && sound2_EN_EOS ) ) && intr_sound_enable ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  if( (SOUND_level_old == (0)) && SOUND_level ){
    SOUND_flag = (1);
  }
  set_INT_active();
  z80main_cpu.icount = icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

variable_types: icount int


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

RS232C_flag = 0;
VSYNC_flag = 0;
RTC_flag = 0;
SOUND_flag = 0;
SOUND_level = 0;
SOUND_edge = 0;
result = interval_work_init_all();
ctrl_vrtc = 1;
return result;
}

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

RS232C_flag = 0;
VSYNC_flag = 0;
RTC_flag = 0;
SOUND_flag = 0;
SOUND_level = 0;
SOUND_edge = 0;
result = func11();
ctrl_vrtc = 1;
return result;
}

original_code:
void main_INT_init( void )
{
  RS232C_flag = (0);
  VSYNC_flag = (0);
  RTC_flag = (0);
  SOUND_flag = (0);
  SOUND_level = (0);
  SOUND_edge = (0);
  interval_work_init_all();
  ctrl_vrtc = 1;
}

canonical_original_code:
void main_INT_init()
{
  RS232C_flag = (0);
  VSYNC_flag = (0);
  RTC_flag = (0);
  SOUND_flag = (0);
  SOUND_level = (0);
  SOUND_edge = (0);
  interval_work_init_all();
  ctrl_vrtc = 1;
}


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

if ( intr_level )
{
if ( intr_level > 0 && RS232C_flag )
{
RS232C_flag = 0;
set_INT_active();
result = 0LL;
intr_level = 0;
return result;
}
if ( intr_level > 1 && VSYNC_flag )
{
VSYNC_flag = 0;
set_INT_active();
result = 1LL;
intr_level = 0;
return result;
}
if ( intr_level > 2 && RTC_flag )
{
RTC_flag = 0;
set_INT_active();
result = 2LL;
goto LABEL_10;
}
if ( intr_level > 4 && SOUND_flag )
{
SOUND_flag = 0;
set_INT_active();
result = 4LL;
LABEL_10:
intr_level = 0;
return result;
}
}
set_INT_active();
return 0xFFFFFFFFLL;
}

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

if ( intr_level )
{
if ( intr_level > 0 && RS232C_flag )
{
RS232C_flag = 0;
func2();
result = 0LL;
intr_level = 0;
return result;
}
if ( intr_level > 1 && VSYNC_flag )
{
VSYNC_flag = 0;
func2();
result = 1LL;
intr_level = 0;
return result;
}
if ( intr_level > 2 && RTC_flag )
{
RTC_flag = 0;
func2();
result = 2LL;
goto LABEL_10;
}
if ( intr_level > 4 && SOUND_flag )
{
SOUND_flag = 0;
func2();
result = 4LL;
LABEL_10:
intr_level = 0;
return result;
}
}
func2();
return 0xFFFFFFFFLL;
}

original_code:
int main_INT_chk( void )
{
  int intr_no = -1;
  if( intr_level==0 ){
    {
      intr_no = -1;
    }
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    RS232C_flag = (0);
    intr_no = 0;
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    VSYNC_flag = (0);
    intr_no = 1;
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    RTC_flag = (0);
    intr_no = 2;
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    SOUND_flag = (0);
    intr_no = 4;
  }
  set_INT_active();
  if( intr_no >= 0 ){
    intr_level = 0;
    return intr_no;
  }else{
    return -1;
  }
}

canonical_original_code:
int main_INT_chk()
{
  int intr_no = -1;
  if( intr_level==0 ){
    {
      intr_no = -1;
    }
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    RS232C_flag = (0);
    intr_no = 0;
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    VSYNC_flag = (0);
    intr_no = 1;
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    RTC_flag = (0);
    intr_no = 2;
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    SOUND_flag = (0);
    intr_no = 4;
  }
  set_INT_active();
  if( intr_no >= 0 ){
    intr_level = 0;
    return intr_no;
  }else{
    return -1;
  }
}

return_type: int


decompiled_code:
_BOOL8 statesave_intr()
{
_BOOL8 result; // rax

if ( (unsigned int)statesave_table("INTR", &suspend_intr_work)
|| (unsigned int)statesave_table("INT2", &suspend_intr_work2)
|| (unsigned int)statesave_table("INT3", &suspend_intr_work3) )
{
result = 0LL;
}
else
{
result = (unsigned int)statesave_table("INT4", &suspend_intr_work4) == 0;
}
return result;
}

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

if ( (unsigned int)statesave_table("INTR", &suspend_intr_work)
|| (unsigned int)statesave_table("INT2", &suspend_intr_work2)
|| (unsigned int)statesave_table("INT3", &suspend_intr_work3) )
{
result = 0LL;
}
else
{
result = (unsigned int)statesave_table("INT4", &suspend_intr_work4) == 0;
}
return result;
}

original_code:
int statesave_intr( void )
{
  if( statesave_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( statesave_table( "INT2", suspend_intr_work2 ) != (0) ) return (0);
  if( statesave_table( "INT3", suspend_intr_work3 ) != (0) ) return (0);
  if( statesave_table( "INT4", suspend_intr_work4 ) != (0) ) return (0);
  return (1);
}

canonical_original_code:
int statesave_intr()
{
  if( statesave_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( statesave_table( "INT2", suspend_intr_work2 ) != (0) ) return (0);
  if( statesave_table( "INT3", suspend_intr_work3 ) != (0) ) return (0);
  if( statesave_table( "INT4", suspend_intr_work4 ) != (0) ) return (0);
  return (1);
}


decompiled_code:
__int64 stateload_intr()
{
int v0; // er8
__int64 result; // rax
int v2; // er8
int v3; // eax

boost_cnt = 0;
v0 = stateload_table("INTR", &suspend_intr_work);
result = 0LL;
if ( !v0 )
{
if ( (unsigned int)stateload_table("INT2", &suspend_intr_work2) )
{
puts("stateload : Statefile is old. (ver 0.6.0?)");
vrtc_base2 = (int)((double)vsync_intr_base * 0.8928571428571429);
if ( !ctrl_vrtc )
ctrl_vrtc = 2;
}
else
{
if ( !(unsigned int)stateload_table("INT3", &suspend_intr_work3) )
{
v2 = stateload_table("INT4", &suspend_intr_work4);
result = 1LL;
if ( !v2 )
return result;
puts("stateload : Statefile is old. (ver 0.6.2?)");
LABEL_16:
boost = 1;
return 1LL;
}
puts("stateload : Statefile is old. (ver 0.6.1?)");
}
if ( !sound_FLAG_A || (v3 = 1, !sound2_EN_TA) )
{
if ( !sound_FLAG_B || (v3 = 1, !sound2_EN_TB) )
{
if ( !sound2_FLAG_BRDY || (v3 = 1, !sound2_EN_BRDY) )
{
v3 = sound2_FLAG_EOS;
if ( sound2_FLAG_EOS )
v3 = sound2_EN_EOS != 0;
}
}
}
SOUND_level = v3;
SOUND_edge = 0;
goto LABEL_16;
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
int v0; // er8
__int64 result; // rax
int v2; // er8
int v3; // eax

boost_cnt = 0;
v0 = stateload_table("INTR", &suspend_intr_work);
result = 0LL;
if ( !v0 )
{
if ( (unsigned int)stateload_table("INT2", &suspend_intr_work2) )
{
puts("stateload : Statefile is old. (ver 0.6.0?)");
vrtc_base2 = (int)((double)vsync_intr_base * 0.8928571428571429);
if ( !ctrl_vrtc )
ctrl_vrtc = 2;
}
else
{
if ( !(unsigned int)stateload_table("INT3", &suspend_intr_work3) )
{
v2 = stateload_table("INT4", &suspend_intr_work4);
result = 1LL;
if ( !v2 )
return result;
puts("stateload : Statefile is old. (ver 0.6.2?)");
LABEL_16:
boost = 1;
return 1LL;
}
puts("stateload : Statefile is old. (ver 0.6.1?)");
}
if ( !sound_FLAG_A || (v3 = 1, !sound2_EN_TA) )
{
if ( !sound_FLAG_B || (v3 = 1, !sound2_EN_TB) )
{
if ( !sound2_FLAG_BRDY || (v3 = 1, !sound2_EN_BRDY) )
{
v3 = sound2_FLAG_EOS;
if ( sound2_FLAG_EOS )
v3 = sound2_EN_EOS != 0;
}
}
}
SOUND_level = v3;
SOUND_edge = 0;
goto LABEL_16;
}
return result;
}

original_code:
int stateload_intr( void )
{
  boost_cnt = 0;
  if( stateload_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( stateload_table( "INT2", suspend_intr_work2 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.0?)\n" );
    goto NOT_HAVE_SID2;
  }
  if( stateload_table( "INT3", suspend_intr_work3 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.1?)\n" );
    goto NOT_HAVE_SID3;
  }
  if( stateload_table( "INT4", suspend_intr_work4 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.2?)\n" );
    goto NOT_HAVE_SID4;
  }
  return (1);
 NOT_HAVE_SID2:
  vrtc_base2 = vsync_intr_base * (( 400.0 ) /448.0);
  if( ctrl_vrtc == 0 ) ctrl_vrtc = 2;
 NOT_HAVE_SID3:
  if( ( sound_FLAG_A && sound2_EN_TA ) ||
      ( sound_FLAG_B && sound2_EN_TB ) ||
      ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
      ( sound2_FLAG_EOS && sound2_EN_EOS ) ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  SOUND_edge = (0);
 NOT_HAVE_SID4:
  boost = 1;
  return (1);
}

canonical_original_code:
int stateload_intr()
{
  boost_cnt = 0;
  if( stateload_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( stateload_table( "INT2", suspend_intr_work2 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.0?)\n" );
    goto NOT_HAVE_SID2;
  }
  if( stateload_table( "INT3", suspend_intr_work3 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.1?)\n" );
    goto NOT_HAVE_SID3;
  }
  if( stateload_table( "INT4", suspend_intr_work4 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.2?)\n" );
    goto NOT_HAVE_SID4;
  }
  return (1);
 NOT_HAVE_SID2:
  vrtc_base2 = vsync_intr_base * (( 400.0 ) /448.0);
  if( ctrl_vrtc == 0 ) ctrl_vrtc = 2;
 NOT_HAVE_SID3:
  if( ( sound_FLAG_A && sound2_EN_TA ) ||
      ( sound_FLAG_B && sound2_EN_TB ) ||
      ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
      ( sound2_FLAG_EOS && sound2_EN_EOS ) ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  SOUND_edge = (0);
 NOT_HAVE_SID4:
  boost = 1;
  return (1);
}


decompiled_code:
__int64 __fastcall YM2608UpdateRequest(int a1)
{
return stream_update((unsigned int)stream[a1], 100LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(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:
_BOOL8 __fastcall YM2608_sh_start(__int64 a1)
{
unsigned int v1; // er12
bool v2; // cc
__int64 v5; // rax
__int64 v6; // rdi
__int64 v7; // r14
const char *v8; // rax
const char *v9; // rax
void *v10; // rax
__int64 v11; // rdi
int v12; // eax
unsigned int v13; // [rsp+4h] [rbp-C4h]
int v14[2]; // [rsp+10h] [rbp-B8h] BYREF
_DWORD v15[2]; // [rsp+18h] [rbp-B0h] BYREF
__int64 v16[2]; // [rsp+20h] [rbp-A8h] BYREF
_QWORD v17[2]; // [rsp+30h] [rbp-98h] BYREF
char s[40]; // [rsp+40h] [rbp-88h] BYREF
char v19[96]; // [rsp+68h] [rbp-60h] BYREF

v1 = sample_rate;
v2 = **(_DWORD **)(a1 + 8) <= 2;
intf = *(_QWORD *)(a1 + 8);
if ( !v2 || (unsigned int)AY8910_sh_start_ym() )
return 1LL;
v5 = intf;
v6 = *(unsigned int *)intf;
if ( (int)v6 <= 0 )
{
v12 = YM2608Init(v6, *(unsigned int *)(intf + 4), v1, v17, v15, 0LL, 0LL);
}
else
{
v7 = 0LL;
do
{
v16[0] = (__int64)s;
v13 = *(_DWORD *)(v5 + 4LL * (int)v7 + 240);
v14[0] = (unsigned __int16)v13;
v8 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v8, (unsigned int)v7, 1LL);
v16[1] = (__int64)v19;
v14[1] = HIWORD(v13);
v9 = (const char *)sound_name(a1);
sprintf(v19, "%s #%d Ch%d", v9, (unsigned int)v7, 2LL);
stream[v7] = stream_init_multi(2LL, v16, v14, v1, (unsigned int)v7, &YM2608UpdateOne);
v10 = (void *)sound2_adpcm;
if ( !sound2_adpcm )
{
v10 = malloc(0x40000uLL);
sound2_adpcm = v10;
}
v15[v7] = 0x40000;
v17[v7] = v10;
v5 = intf;
++v7;
v11 = *(unsigned int *)intf;
}
while ( (int)v11 > (int)v7 );
v12 = YM2608Init(v11, *(unsigned int *)(intf + 4), v1, v17, v15, 0LL, 0LL);
}
return v12 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
unsigned int v1; // er12
bool v2; // cc
__int64 v5; // rax
__int64 v6; // rdi
__int64 v7; // r14
const char *v8; // rax
const char *v9; // rax
void *v10; // rax
__int64 v11; // rdi
int v12; // eax
unsigned int v13; // [rsp+4h] [rbp-C4h]
int v14[2]; // [rsp+10h] [rbp-B8h] BYREF
_DWORD v15[2]; // [rsp+18h] [rbp-B0h] BYREF
__int64 v16[2]; // [rsp+20h] [rbp-A8h] BYREF
_QWORD v17[2]; // [rsp+30h] [rbp-98h] BYREF
char s[40]; // [rsp+40h] [rbp-88h] BYREF
char v19[96]; // [rsp+68h] [rbp-60h] BYREF

v1 = sample_rate;
v2 = **(_DWORD **)(a1 + 8) <= 2;
intf = *(_QWORD *)(a1 + 8);
if ( !v2 || (unsigned int)AY8910_sh_start_ym() )
return 1LL;
v5 = intf;
v6 = *(unsigned int *)intf;
if ( (int)v6 <= 0 )
{
v12 = YM2608Init(v6, *(unsigned int *)(intf + 4), v1, v17, v15, 0LL, 0LL);
}
else
{
v7 = 0LL;
do
{
v16[0] = (__int64)s;
v13 = *(_DWORD *)(v5 + 4LL * (int)v7 + 240);
v14[0] = (unsigned __int16)v13;
v8 = (const char *)sound_name(a1);
sprintf(s, "%s #%d Ch%d", v8, (unsigned int)v7, 1LL);
v16[1] = (__int64)v19;
v14[1] = HIWORD(v13);
v9 = (const char *)sound_name(a1);
sprintf(v19, "%s #%d Ch%d", v9, (unsigned int)v7, 2LL);
stream[v7] = stream_init_multi(2LL, v16, v14, v1, (unsigned int)v7, &YM2608UpdateOne);
v10 = (void *)sound2_adpcm;
if ( !sound2_adpcm )
{
v10 = malloc(0x40000uLL);
sound2_adpcm = v10;
}
v15[v7] = 0x40000;
v17[v7] = v10;
v5 = intf;
++v7;
v11 = *(unsigned int *)intf;
}
while ( (int)v11 > (int)v7 );
v12 = YM2608Init(v11, *(unsigned int *)(intf + 4), v1, v17, v15, 0LL, 0LL);
}
return v12 != 0;
}

original_code:
int YM2608_sh_start(const struct MachineSound *msound)
{
 int i,j;
 int rate = sample_rate;
 char buf[2][40];
 const char *name[2];
 int mixed_vol,vol[2];
 void *pcmbufa[2];
 int pcmsizea[2];
 intf = msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start_ym(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2608UpdateOne);
  if( sound2_adpcm==((void *)0) ){
    sound2_adpcm = (byte *)malloc( 256 * 1024 * sizeof(char) );
  }
  pcmbufa[i] = sound2_adpcm;
  pcmsizea[i] = 256 * 1024;
 }
 if (YM2608Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,
             0,0) == 0)
  return 0;
 return 1;
}

canonical_original_code:
int YM2608_sh_start(struct MachineSound *msound)
{
 int i; int j;
 int rate = sample_rate;
 char buf[2][40];
 char *name[2];
 int mixed_vol; int vol[2];
 void *pcmbufa[2];
 int pcmsizea[2];
 intf = msound->sound_interface;
 if( intf->num > (2) ) return 1;
 if (AY8910_sh_start_ym(msound)) return 1;
 FMTimerInit();
 for (i = 0;i < intf->num;i++)
 {
  mixed_vol = intf->volumeFM[i];
  for (j = 0 ; j < 2 ; j++)
  {
   name[j]=buf[j];
   vol[j] = mixed_vol & 0xffff;
   mixed_vol>>=16;
   sprintf(buf[j],"%s #%d Ch%d",sound_name(msound),i,j+1);
  }
  stream[i] = stream_init_multi(2,name,vol,rate,i,YM2608UpdateOne);
  if( sound2_adpcm==((void *)0) ){
    sound2_adpcm = (unsigned char *)malloc( 256 * 1024 * sizeof(char) );
  }
  pcmbufa[i] = sound2_adpcm;
  pcmsizea[i] = 256 * 1024;
 }
 if (YM2608Init(intf->num,intf->baseclock,rate,
             pcmbufa,pcmsizea,
             0,0) == 0)
  return 0;
 return 1;
}

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

variable_types: i int

variable_types: j int

variable_types: rate int

variable_types:
buf
char [2][40]

variable_types:
name
char *[2]

variable_types:
vol
int [2]

variable_types:
pcmbufa
void *[2]

variable_types:
pcmsizea
int [2]


decompiled_code:
__int64 YM2608_sh_stop()
{
YM2608Shutdown();
return AY8910_sh_stop_ym();
}

canonical_decompiled_code:
__int64 func3()
{
YM2608Shutdown();
return AY8910_sh_stop_ym();
}

original_code:
void YM2608_sh_stop(void)
{
 YM2608Shutdown();
 AY8910_sh_stop_ym();
}

canonical_original_code:
void YM2608_sh_stop()
{
 YM2608Shutdown();
 AY8910_sh_stop_ym();
}


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


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

canonical_decompiled_code:
__int64 func5()
{
return YM2608Read(0LL, 0LL);
}

original_code:
data8_t YM2608_status_port_0_A_r(__attribute__((__unused__)) offs_t offset)
{
 return YM2608Read(0,0);
}

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

variable_types:
offset
unsigned int

return_type: unsigned char


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

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

original_code:
data8_t YM2608_status_port_0_B_r(__attribute__((__unused__)) offs_t offset)
{
 return YM2608Read(0,2);
}

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


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

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

original_code:
data8_t YM2608_status_port_1_A_r(__attribute__((__unused__)) offs_t offset) {
 return YM2608Read(1,0);
}

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


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

canonical_decompiled_code:
__int64 func8()
{
return YM2608Read(1LL, 2LL);
}

original_code:
data8_t YM2608_status_port_1_B_r(__attribute__((__unused__)) offs_t offset) {
 return YM2608Read(1,2);
}

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


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

canonical_decompiled_code:
__int64 func9()
{
return YM2608Read(0LL, 1LL);
}

original_code:
data8_t YM2608_read_port_0_r(__attribute__((__unused__)) offs_t offset){
 return YM2608Read(0,1);
}

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


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

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

original_code:
data8_t YM2608_read_port_1_r(__attribute__((__unused__)) offs_t offset){
 return YM2608Read(1,1);
}

canonical_original_code:
unsigned char 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 func11(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 0LL, a2);
}

original_code:
void YM2608_control_port_0_A_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data)
{
 YM2608Write(0,0,data);
}

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

variable_types:
data
unsigned char


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 func12(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 2LL, a2);
}

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

canonical_original_code:
void YM2608_control_port_0_B_w(unsigned int offset, unsigned char 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 func13(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 0LL, a2);
}

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

canonical_original_code:
void YM2608_control_port_1_A_w(unsigned int offset, unsigned char 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 func14(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 2LL, a2);
}

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

canonical_original_code:
void YM2608_control_port_1_B_w(unsigned int offset, unsigned char 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 func15(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 1LL, a2);
}

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

canonical_original_code:
void YM2608_data_port_0_A_w(unsigned int offset, unsigned char 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 func16(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(0LL, 3LL, a2);
}

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

canonical_original_code:
void YM2608_data_port_0_B_w(unsigned int offset, unsigned char 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 func17(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 1LL, a2);
}

original_code:
void YM2608_data_port_1_A_w(__attribute__((__unused__)) offs_t offset, __attribute__((__unused__)) data8_t data){
 YM2608Write(1,1,data);
}

canonical_original_code:
void YM2608_data_port_1_A_w(unsigned int offset, unsigned char 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 func18(__int64 a1, unsigned __int8 a2)
{
return YM2608Write(1LL, 3LL, a2);
}

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

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


original_code:
void pio_init( void )
{
  int side;
  for( side=0; side<2; side++ ){
    pio_AB[ side ][ (0) ].type = (0);
    pio_AB[ side ][ (0) ].exist = (0);
    pio_AB[ side ][ (0) ].data = 0x00;
    pio_AB[ side ][ (1) ].type = (1);
    pio_AB[ side ][ (1) ].exist = (0);
    pio_AB[ side ][ (1) ].data = 0x00;
    pio_C[ side ][ (0) ].type = (1);
    pio_C[ side ][ (0) ].cont_f = 1;
    pio_C[ side ][ (0) ].data = 0x00;
    pio_C[ side ][ (1) ].type = (0);
    pio_C[ side ][ (1) ].cont_f = 1;
    pio_C[ side ][ (1) ].data = 0x00;
  }
}

canonical_original_code:
void pio_init()
{
  int side;
  for( side=0; side<2; side++ ){
    pio_AB[ side ][ (0) ].type = (0);
    pio_AB[ side ][ (0) ].exist = (0);
    pio_AB[ side ][ (0) ].data = 0x00;
    pio_AB[ side ][ (1) ].type = (1);
    pio_AB[ side ][ (1) ].exist = (0);
    pio_AB[ side ][ (1) ].data = 0x00;
    pio_C[ side ][ (0) ].type = (1);
    pio_C[ side ][ (0) ].cont_f = 1;
    pio_C[ side ][ (0) ].data = 0x00;
    pio_C[ side ][ (1) ].type = (0);
    pio_C[ side ][ (1) ].cont_f = 1;
    pio_C[ side ][ (1) ].data = 0x00;
  }
}

variable_types: side int


decompiled_code:
__int64 __fastcall pio_read_AB(int a1, int a2)
{
__int64 v3; // r12
__int64 v4; // rbp
__int16 *v5; // rdx
__int16 *v6; // rsi
__int64 v7; // r15
__int64 v8; // r14
__int64 v9; // rax
__int16 *v11; // rdx
__int16 *v12; // rsi
__int16 *v13; // rdx
__int16 *v14; // rsi

v3 = a2 ^ 1;
v4 = a1 ^ 1;
if ( !LODWORD(pio_AB[4 * v4 + 2 * v3]) )
{
if ( !verbose_pio )
{
v7 = a2;
v8 = a1;
if ( LODWORD(pio_AB[4 * a1 + 2 * a2]) != 1 )
{
LABEL_9:
v9 = 2 * (v3 + 2 * v4);
if ( HIDWORD(pio_AB[v9]) != 1 )
{
if ( cpu_timing == 1 )
{
if ( !a1 )
{
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
}
else if ( (cpu_timing & 0xFFFFFFFD) != 0 )
{
return BYTE4(pio_AB[4 * v4 + 1 + 2 * v3]);
}
if ( verbose_pio )
{
v11 = aAbms;
v12 = &aAbms[2];
if ( a2 )
v11 = &aAbms[1];
if ( a1 )
v12 = &aAbms[3];
printf("PIO Read continuously : side = %s : port = %s\n", v12, v11);
}
return BYTE4(pio_AB[4 * v4 + 1 + 2 * v3]);
}
HIDWORD(pio_AB[v9]) = 0;
return BYTE4(pio_AB[4 * v4 + 1 + 2 * v3]);
}
return BYTE4(pio_AB[4 * v8 + 1 + 2 * v7]);
}
v5 = aAbms;
v6 = &aAbms[2];
if ( a2 )
v5 = &aAbms[1];
if ( a1 )
v6 = &aAbms[3];
printf("PIO AB READ PORT Mismatch : side = %s : port = %s\n", v6, v5);
}
v7 = a2;
v8 = a1;
if ( LODWORD(pio_AB[4 * a1 + 2 * a2]) != 1 )
goto LABEL_9;
if ( !verbose_pio )
return BYTE4(pio_AB[4 * v8 + 1 + 2 * v7]);
v13 = aAbms;
v14 = &aAbms[2];
if ( a2 )
v13 = &aAbms[1];
if ( a1 )
v14 = &aAbms[3];
printf("PIO Read from WRITE-PORT : side = %s : port = %s\n", v14, v13);
return BYTE4(pio_AB[4 * a1 + 1 + 2 * a2]);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v3; // r12
__int64 v4; // rbp
__int16 *v5; // rdx
__int16 *v6; // rsi
__int64 v7; // r15
__int64 v8; // r14
__int64 v9; // rax
__int16 *v11; // rdx
__int16 *v12; // rsi
__int16 *v13; // rdx
__int16 *v14; // rsi

v3 = a2 ^ 1;
v4 = a1 ^ 1;
if ( !LODWORD(pio_AB[4 * v4 + 2 * v3]) )
{
if ( !verbose_pio )
{
v7 = a2;
v8 = a1;
if ( LODWORD(pio_AB[4 * a1 + 2 * a2]) != 1 )
{
LABEL_9:
v9 = 2 * (v3 + 2 * v4);
if ( HIDWORD(pio_AB[v9]) != 1 )
{
if ( cpu_timing == 1 )
{
if ( !a1 )
{
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
}
else if ( (cpu_timing & 0xFFFFFFFD) != 0 )
{
return BYTE4(pio_AB[4 * v4 + 1 + 2 * v3]);
}
if ( verbose_pio )
{
v11 = aAbms;
v12 = &aAbms[2];
if ( a2 )
v11 = &aAbms[1];
if ( a1 )
v12 = &aAbms[3];
printf("PIO Read continuously : side = %s : port = %s\n", v12, v11);
}
return BYTE4(pio_AB[4 * v4 + 1 + 2 * v3]);
}
HIDWORD(pio_AB[v9]) = 0;
return BYTE4(pio_AB[4 * v4 + 1 + 2 * v3]);
}
return BYTE4(pio_AB[4 * v8 + 1 + 2 * v7]);
}
v5 = aAbms;
v6 = &aAbms[2];
if ( a2 )
v5 = &aAbms[1];
if ( a1 )
v6 = &aAbms[3];
printf("PIO AB READ PORT Mismatch : side = %s : port = %s\n", v6, v5);
}
v7 = a2;
v8 = a1;
if ( LODWORD(pio_AB[4 * a1 + 2 * a2]) != 1 )
goto LABEL_9;
if ( !verbose_pio )
return BYTE4(pio_AB[4 * v8 + 1 + 2 * v7]);
v13 = aAbms;
v14 = &aAbms[2];
if ( a2 )
v13 = &aAbms[1];
if ( a1 )
v14 = &aAbms[3];
printf("PIO Read from WRITE-PORT : side = %s : port = %s\n", v14, v13);
return BYTE4(pio_AB[4 * a1 + 1 + 2 * a2]);
}

original_code:
byte pio_read_AB( int side, int port )
{
  if( pio_AB[ side^1 ][ port^1 ].type == (0) ){
    if( verbose_pio ) printf( "PIO AB READ PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (1) ){
    if( verbose_pio ) printf( "PIO Read from WRITE-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
    return (pio_AB[ side ][ port ].data);
  }
  if( pio_AB[ side^1 ][ port^1 ].exist == (1) ){
    pio_AB[ side^1 ][ port^1 ].exist = (0);
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Read continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      break;
    }
  }
  return (pio_AB[ side^1 ][ port^1 ].data);
}

canonical_original_code:
unsigned char pio_read_AB(int side, int port)
{
  if( pio_AB[ side^1 ][ port^1 ].type == (0) ){
    if( verbose_pio ) printf( "PIO AB READ PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (1) ){
    if( verbose_pio ) printf( "PIO Read from WRITE-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
    return (pio_AB[ side ][ port ].data);
  }
  if( pio_AB[ side^1 ][ port^1 ].exist == (1) ){
    pio_AB[ side^1 ][ port^1 ].exist = (0);
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Read continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      break;
    }
  }
  return (pio_AB[ side^1 ][ port^1 ].data);
}


decompiled_code:
__int64 __fastcall pio_write_AB(int a1, int a2, char a3)
{
__int64 v5; // r13
__int64 v6; // r14
__int16 *v7; // rdx
__int16 *v8; // rsi
__int64 result; // rax
__int16 *v10; // rdx
__int16 *v11; // rsi
bool v12; // zf
__int16 *v13; // rdx
__int16 *v14; // rsi

if ( LODWORD(pio_AB[4 * (a1 ^ 1) + 2 * (a2 ^ 1)]) == 1 )
{
if ( !verbose_pio )
{
v5 = a2;
v6 = a1;
goto LABEL_9;
}
v12 = a2 == 0;
v13 = aAbms;
v14 = &aAbms[2];
if ( !v12 )
v13 = &aAbms[1];
if ( a1 )
v14 = &aAbms[3];
printf("PIO AB Write PORT Mismatch : side = %s : port = %s\n", v14, v13);
}
v5 = a2;
v6 = a1;
if ( !LODWORD(pio_AB[4 * a1 + 2 * a2]) && verbose_pio )
{
v7 = aAbms;
v8 = &aAbms[2];
if ( a2 )
v7 = &aAbms[1];
if ( a1 )
v8 = &aAbms[3];
printf("PIO Write to READ-PORT : side = %s : port = %s\n", v8, v7);
}
LABEL_9:
result = 16 * (v5 + 2 * v6);
if ( !*(_DWORD *)((char *)pio_AB + result + 4) )
{
*(_DWORD *)((char *)pio_AB + result + 4) = 1;
*((_BYTE *)&pio_AB[1] + result + 4) = a3;
return result;
}
if ( cpu_timing == 1 )
{
if ( !a1 )
{
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
}
else
{
result = cpu_timing & 0xFFFFFFFD;
if ( (_DWORD)result )
return result;
}
if ( verbose_pio )
{
v10 = aAbms;
v11 = &aAbms[2];
if ( a2 )
v10 = &aAbms[1];
if ( a1 )
v11 = &aAbms[3];
printf("PIO Write continuously : side = %s : port = %s\n", v11, v10);
}
result = 16 * (v5 + 2 * v6);
*((_BYTE *)&pio_AB[1] + result + 4) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, char a3)
{
__int64 v5; // r13
__int64 v6; // r14
__int16 *v7; // rdx
__int16 *v8; // rsi
__int64 result; // rax
__int16 *v10; // rdx
__int16 *v11; // rsi
bool v12; // zf
__int16 *v13; // rdx
__int16 *v14; // rsi

if ( LODWORD(pio_AB[4 * (a1 ^ 1) + 2 * (a2 ^ 1)]) == 1 )
{
if ( !verbose_pio )
{
v5 = a2;
v6 = a1;
goto LABEL_9;
}
v12 = a2 == 0;
v13 = aAbms;
v14 = &aAbms[2];
if ( !v12 )
v13 = &aAbms[1];
if ( a1 )
v14 = &aAbms[3];
printf("PIO AB Write PORT Mismatch : side = %s : port = %s\n", v14, v13);
}
v5 = a2;
v6 = a1;
if ( !LODWORD(pio_AB[4 * a1 + 2 * a2]) && verbose_pio )
{
v7 = aAbms;
v8 = &aAbms[2];
if ( a2 )
v7 = &aAbms[1];
if ( a1 )
v8 = &aAbms[3];
printf("PIO Write to READ-PORT : side = %s : port = %s\n", v8, v7);
}
LABEL_9:
result = 16 * (v5 + 2 * v6);
if ( !*(_DWORD *)((char *)pio_AB + result + 4) )
{
*(_DWORD *)((char *)pio_AB + result + 4) = 1;
*((_BYTE *)&pio_AB[1] + result + 4) = a3;
return result;
}
if ( cpu_timing == 1 )
{
if ( !a1 )
{
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
}
else
{
result = cpu_timing & 0xFFFFFFFD;
if ( (_DWORD)result )
return result;
}
if ( verbose_pio )
{
v10 = aAbms;
v11 = &aAbms[2];
if ( a2 )
v10 = &aAbms[1];
if ( a1 )
v11 = &aAbms[3];
printf("PIO Write continuously : side = %s : port = %s\n", v11, v10);
}
result = 16 * (v5 + 2 * v6);
*((_BYTE *)&pio_AB[1] + result + 4) = a3;
return result;
}

original_code:
void pio_write_AB( int side, int port, byte data )
{
  if( pio_AB[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO AB Write PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO Write to READ-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].exist == (0) ){
    pio_AB[ side ][ port ].exist = (1);
    pio_AB[ side ][ port ].data = data;
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Write continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      pio_AB[ side ][ port ].data = data;
      break;
    }
  }
  return;
}

canonical_original_code:
void pio_write_AB(int side, int port, unsigned char data)
{
  if( pio_AB[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO AB Write PORT Mismatch" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO Write to READ-PORT" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
  }
  if( pio_AB[ side ][ port ].exist == (0) ){
    pio_AB[ side ][ port ].exist = (1);
    pio_AB[ side ][ port ].data = data;
  }else{
    switch( cpu_timing ){
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
    case 0:
    case 2:
      if( verbose_pio ) printf( "PIO Write continuously" " : side = %s : port = %s\n", (side==(0))?"M":"S", (port==(0))?"A":"B" );
      pio_AB[ side ][ port ].data = data;
      break;
    }
  }
  return;
}


decompiled_code:
char __fastcall pio_read_C(int a1)
{
__int64 v1; // rbp
__int64 v2; // r13
int v3; // eax
int *v4; // rcx
int v5; // edx
char v6; // al
char result; // al
__int64 v8; // rbx
int v9; // edx
__int16 *v10; // rsi
__int16 *v11; // rsi

v1 = a1 ^ 1;
if ( !pio_C[8 * v1] && !pio_C[8 * (a1 ^ 1) + 4] && verbose_pio )
{
v10 = &aAbms[2];
if ( a1 )
v10 = &aAbms[3];
printf("PIO C READ PORT Mismatch : side = %s\n", v10);
}
v2 = 8LL * a1;
v3 = pio_C[v2];
v4 = &pio_C[v2];
if ( v3 == 1 )
{
v5 = v4[4];
if ( v5 != 1 )
goto LABEL_21;
if ( !verbose_pio )
{
v6 = 16 * *((_BYTE *)v4 + 12);
goto LABEL_15;
}
v11 = &aAbms[2];
if ( a1 )
v11 = &aAbms[3];
printf("PIO C Read from WRITE-PORT : side = %s\n", v11);
v3 = pio_C[8 * a1];
}
v5 = pio_C[8 * a1 + 4];
if ( !v3 )
{
v6 = 16 * LOBYTE(pio_C[8 * v1 + 7]);
goto LABEL_6;
}
LABEL_21:
v6 = 16 * LOBYTE(pio_C[8 * a1 + 3]);
LABEL_6:
if ( !v5 )
{
result = LOBYTE(pio_C[8 * v1 + 3]) | v6;
goto LABEL_8;
}
LABEL_15:
result = LOBYTE(pio_C[8 * a1 + 7]) | v6;
LABEL_8:
v8 = 8LL * a1;
v9 = pio_C[v8 + 6];
pio_C[v8 + 6] = v9 ^ 1;
if ( v9 == 1 )
{
if ( cpu_timing )
{
if ( cpu_timing == 1 && !a1 )
{
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
}
else
{
select_main_cpu ^= 1u;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(int a1)
{
__int64 v1; // rbp
__int64 v2; // r13
int v3; // eax
int *v4; // rcx
int v5; // edx
char v6; // al
char result; // al
__int64 v8; // rbx
int v9; // edx
__int16 *v10; // rsi
__int16 *v11; // rsi

v1 = a1 ^ 1;
if ( !pio_C[8 * v1] && !pio_C[8 * (a1 ^ 1) + 4] && verbose_pio )
{
v10 = &aAbms[2];
if ( a1 )
v10 = &aAbms[3];
printf("PIO C READ PORT Mismatch : side = %s\n", v10);
}
v2 = 8LL * a1;
v3 = pio_C[v2];
v4 = &pio_C[v2];
if ( v3 == 1 )
{
v5 = v4[4];
if ( v5 != 1 )
goto LABEL_21;
if ( !verbose_pio )
{
v6 = 16 * *((_BYTE *)v4 + 12);
goto LABEL_15;
}
v11 = &aAbms[2];
if ( a1 )
v11 = &aAbms[3];
printf("PIO C Read from WRITE-PORT : side = %s\n", v11);
v3 = pio_C[8 * a1];
}
v5 = pio_C[8 * a1 + 4];
if ( !v3 )
{
v6 = 16 * LOBYTE(pio_C[8 * v1 + 7]);
goto LABEL_6;
}
LABEL_21:
v6 = 16 * LOBYTE(pio_C[8 * a1 + 3]);
LABEL_6:
if ( !v5 )
{
result = LOBYTE(pio_C[8 * v1 + 3]) | v6;
goto LABEL_8;
}
LABEL_15:
result = LOBYTE(pio_C[8 * a1 + 7]) | v6;
LABEL_8:
v8 = 8LL * a1;
v9 = pio_C[v8 + 6];
pio_C[v8 + 6] = v9 ^ 1;
if ( v9 == 1 )
{
if ( cpu_timing )
{
if ( cpu_timing == 1 && !a1 )
{
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
}
else
{
select_main_cpu ^= 1u;
z80_state_intchk = 0;
z80_state_goal = 1;
}
}
return result;
}

original_code:
byte pio_read_C( int side )
{
  byte data;
  if( pio_C[ side^1 ][ (0) ].type == (0) &&
      pio_C[ side^1 ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C READ PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (1) &&
      pio_C[ side ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Read from WRITE-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) ){
    data = pio_C[ side^1 ][ (1) ].data << 4;
  }else{
    data = pio_C[ side ][ (0) ].data << 4;
  }
  if( pio_C[ side ][ (1) ].type == (0) ){
    data |= pio_C[ side^1 ][ (0) ].data;
  }else{
    data |= pio_C[ side ][ (1) ].data;
  }
  pio_C[ side ][ (1) ].cont_f ^= 1;
  if( pio_C[ side ][ (1) ].cont_f == 0 ){
    switch( cpu_timing ){
    case 0:
      select_main_cpu ^= 1;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      break;
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
      break;
    case 2:
      break;
    }
  }
  return data;
}

canonical_original_code:
unsigned char pio_read_C(int side)
{
  unsigned char data;
  if( pio_C[ side^1 ][ (0) ].type == (0) &&
      pio_C[ side^1 ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C READ PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (1) &&
      pio_C[ side ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Read from WRITE-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) ){
    data = pio_C[ side^1 ][ (1) ].data << 4;
  }else{
    data = pio_C[ side ][ (0) ].data << 4;
  }
  if( pio_C[ side ][ (1) ].type == (0) ){
    data |= pio_C[ side^1 ][ (0) ].data;
  }else{
    data |= pio_C[ side ][ (1) ].data;
  }
  pio_C[ side ][ (1) ].cont_f ^= 1;
  if( pio_C[ side ][ (1) ].cont_f == 0 ){
    switch( cpu_timing ){
    case 0:
      select_main_cpu ^= 1;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      break;
    case 1:
      if( side==(0) ){
 dual_cpu_count = CPU_1_COUNT;
 do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
      }
      break;
    case 2:
      break;
    }
  }
  return data;
}


decompiled_code:
char __fastcall pio_write_C(int a1, unsigned __int8 a2)
{
_BOOL8 v3; // r12
__int64 v4; // r13
__int16 *v5; // rsi
__int64 v6; // rdx
int v7; // eax
char v8; // cl
char result; // al
int *v10; // rdx
bool v11; // zf
__int16 *v12; // rsi

v3 = (a2 & 8) == 0;
if ( pio_C[8 * (a1 ^ 1) + 4 * ((a2 & 8) != 0)] == 1 )
{
v4 = a1;
if ( !verbose_pio )
goto LABEL_7;
v12 = &aAbms[2];
if ( a1 )
v12 = &aAbms[3];
printf("PIO C Write PORT Mismatch : side = %s\n", v12);
}
v4 = a1;
if ( !pio_C[8 * a1 + 4 * v3] && verbose_pio )
{
v5 = &aAbms[2];
if ( a1 )
v5 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", v5);
}
LABEL_7:
v6 = 4 * (v3 + 2 * v4);
v7 = 1 << ((a2 >> 1) & 3);
v8 = v7 | LOBYTE(pio_C[v6 + 3]);
result = LOBYTE(pio_C[v6 + 3]) & ~(_BYTE)v7;
v10 = &pio_C[v6];
if ( (a2 & 1) != 0 )
result = v8;
v11 = cpu_timing == 1;
*((_BYTE *)v10 + 12) = result;
if ( v11 && !a1 )
{
z80_state_intchk = 0;
result = CPU_1_COUNT;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
return result;
}

canonical_decompiled_code:
char __fastcall func4(int a1, unsigned __int8 a2)
{
_BOOL8 v3; // r12
__int64 v4; // r13
__int16 *v5; // rsi
__int64 v6; // rdx
int v7; // eax
char v8; // cl
char result; // al
int *v10; // rdx
bool v11; // zf
__int16 *v12; // rsi

v3 = (a2 & 8) == 0;
if ( pio_C[8 * (a1 ^ 1) + 4 * ((a2 & 8) != 0)] == 1 )
{
v4 = a1;
if ( !verbose_pio )
goto LABEL_7;
v12 = &aAbms[2];
if ( a1 )
v12 = &aAbms[3];
printf("PIO C Write PORT Mismatch : side = %s\n", v12);
}
v4 = a1;
if ( !pio_C[8 * a1 + 4 * v3] && verbose_pio )
{
v5 = &aAbms[2];
if ( a1 )
v5 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", v5);
}
LABEL_7:
v6 = 4 * (v3 + 2 * v4);
v7 = 1 << ((a2 >> 1) & 3);
v8 = v7 | LOBYTE(pio_C[v6 + 3]);
result = LOBYTE(pio_C[v6 + 3]) & ~(_BYTE)v7;
v10 = &pio_C[v6];
if ( (a2 & 1) != 0 )
result = v8;
v11 = cpu_timing == 1;
*((_BYTE *)v10 + 12) = result;
if ( v11 && !a1 )
{
z80_state_intchk = 0;
result = CPU_1_COUNT;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
return result;
}

original_code:
void pio_write_C( int side, byte data )
{
  int port;
  if( data & 0x08 ) port = (0);
  else port = (1);
  data &= 0x07;
  if( pio_C[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Write PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( data & 0x01 ) pio_C[ side ][ port ].data |= ( 1 << (data>>1) );
  else pio_C[ side ][ port ].data &= ~( 1 << (data>>1) );
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}

canonical_original_code:
void pio_write_C(int side, unsigned char data)
{
  int port;
  if( data & 0x08 ) port = (0);
  else port = (1);
  data &= 0x07;
  if( pio_C[ side^1 ][ port^1 ].type == (1) ){
    if( verbose_pio ) printf( "PIO C Write PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ port ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( data & 0x01 ) pio_C[ side ][ port ].data |= ( 1 << (data>>1) );
  else pio_C[ side ][ port ].data &= ~( 1 << (data>>1) );
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}


decompiled_code:
char __fastcall pio_write_C_direct(int a1, unsigned __int8 a2)
{
__int64 v3; // rbx
char result; // al
bool v5; // zf
__int16 *v6; // rsi
__int16 *v7; // rsi

if ( pio_C[8 * (a1 ^ 1)] == 1 && pio_C[8 * (a1 ^ 1) + 4] == 1 && verbose_pio )
{
v7 = &aAbms[2];
if ( a1 )
v7 = &aAbms[3];
printf("PIO C WRITE PORT Mismatch : side = %s\n", v7);
}
if ( !pio_C[8 * a1] && !pio_C[8 * a1 + 4] && verbose_pio )
{
v6 = &aAbms[2];
if ( a1 )
v6 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", v6);
}
v3 = 8LL * a1;
result = a2 >> 4;
v5 = cpu_timing == 1;
LOBYTE(pio_C[v3 + 7]) = a2 & 0xF;
LOBYTE(pio_C[v3 + 3]) = a2 >> 4;
if ( v5 && !a1 )
{
result = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(int a1, unsigned __int8 a2)
{
__int64 v3; // rbx
char result; // al
bool v5; // zf
__int16 *v6; // rsi
__int16 *v7; // rsi

if ( pio_C[8 * (a1 ^ 1)] == 1 && pio_C[8 * (a1 ^ 1) + 4] == 1 && verbose_pio )
{
v7 = &aAbms[2];
if ( a1 )
v7 = &aAbms[3];
printf("PIO C WRITE PORT Mismatch : side = %s\n", v7);
}
if ( !pio_C[8 * a1] && !pio_C[8 * a1 + 4] && verbose_pio )
{
v6 = &aAbms[2];
if ( a1 )
v6 = &aAbms[3];
printf("PIO C Write to READ-PORT : side = %s\n", v6);
}
v3 = 8LL * a1;
result = a2 >> 4;
v5 = cpu_timing == 1;
LOBYTE(pio_C[v3 + 7]) = a2 & 0xF;
LOBYTE(pio_C[v3 + 3]) = a2 >> 4;
if ( v5 && !a1 )
{
result = CPU_1_COUNT;
z80_state_intchk = 0;
z80_state_goal = 1;
dual_cpu_count = CPU_1_COUNT;
}
return result;
}

original_code:
void pio_write_C_direct( int side, byte data )
{
  if( pio_C[ side^1 ][ (0) ].type == (1) &&
      pio_C[ side^1 ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C WRITE PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) &&
      pio_C[ side ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  pio_C[ side ][ (0) ].data = data >> 4;
  pio_C[ side ][ (1) ].data = data & 0x0f;
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}

canonical_original_code:
void pio_write_C_direct(int side, unsigned char data)
{
  if( pio_C[ side^1 ][ (0) ].type == (1) &&
      pio_C[ side^1 ][ (1) ].type == (1) ){
    if( verbose_pio ) printf( "PIO C WRITE PORT Mismatch" " : side = %s\n", (side==(0))?"M":"S" );
  }
  if( pio_C[ side ][ (0) ].type == (0) &&
      pio_C[ side ][ (1) ].type == (0) ){
    if( verbose_pio ) printf( "PIO C Write to READ-PORT" " : side = %s\n", (side==(0))?"M":"S" );
  }
  pio_C[ side ][ (0) ].data = data >> 4;
  pio_C[ side ][ (1) ].data = data & 0x0f;
  switch( cpu_timing ){
  case 0:
  case 2:
    break;
  case 1:
    if( side==(0) ){
      dual_cpu_count = CPU_1_COUNT;
      do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
    }
    break;
  }
  return;
}


decompiled_code:
_BOOL8 statesave_pio()
{
return (unsigned int)statesave_table("PIO ", &suspend_pio_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
return (unsigned int)statesave_table("PIO ", &suspend_pio_work) == 0;
}

original_code:
int statesave_pio( void )
{
  if( statesave_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int statesave_pio()
{
  if( statesave_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
_BOOL8 stateload_pio()
{
return (unsigned int)stateload_table("PIO ", &suspend_pio_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return (unsigned int)stateload_table("PIO ", &suspend_pio_work) == 0;
}

original_code:
int stateload_pio( void )
{
  if( stateload_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int stateload_pio()
{
  if( stateload_table( "PIO ", suspend_pio_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
__int64 __fastcall sub_fetch(unsigned __int16 a1)
{
if ( memory_wait && a1 <= 0x3FFFu )
++z80sub_cpu[10];
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 a1)
{
if ( memory_wait && a1 <= 0x3FFFu )
++z80sub_cpu[10];
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

original_code:
byte sub_fetch( word addr )
{
  if( memory_wait ){
    if( addr < 0x4000 )
      z80sub_cpu.state0 += 1;
  }
  return sub_romram[ addr & 0x7fff ];
}

canonical_original_code:
unsigned char sub_fetch(unsigned short addr)
{
  if( memory_wait ){
    if( addr < 0x4000 )
      z80sub_cpu.state0 += 1;
  }
  return sub_romram[ addr & 0x7fff ];
}

variable_types:
addr
unsigned short


decompiled_code:
__int64 __fastcall sub_mem_read(__int16 a1)
{
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
return *(unsigned __int8 *)(sub_romram + (a1 & 0x7FFF));
}

original_code:
byte sub_mem_read( word addr )
{
  return sub_romram[ addr & 0x7fff ];
}

canonical_original_code:
unsigned char sub_mem_read(unsigned short addr)
{
  return sub_romram[ addr & 0x7fff ];
}


decompiled_code:
__int64 sub_INT_chk()
{
int v0; // edx

v0 = FDC_flag;
z80sub_cpu[8] = 0;
return (unsigned int)-(v0 == 0);
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx

v0 = FDC_flag;
z80sub_cpu[8] = 0;
return (unsigned int)-(v0 == 0);
}

original_code:
int sub_INT_chk( void )
{
  z80sub_cpu.INT_active = (0);
  if( FDC_flag ) return 0;
  else return -1;
}

canonical_original_code:
int sub_INT_chk()
{
  z80sub_cpu.INT_active = (0);
  if( FDC_flag ) return 0;
  else return -1;
}


decompiled_code:
int __fastcall sub_mem_write(unsigned __int16 a1, char a2)
{
int result; // eax

if ( (a1 & 0xC000) == 0x4000 )
{
result = sub_romram;
*(_BYTE *)(sub_romram + a1) = a2;
return result;
}
result = verbose_io;
if ( !verbose_io )
{
if ( (a1 & 0x4000) == 0 )
return result;
goto LABEL_4;
}
result = printf("SUB Memory Write BAD %04x\n", a1);
if ( (a1 & 0x4000) != 0 )
{
LABEL_4:
result = sub_romram;
*(_BYTE *)(sub_romram + (a1 & 0x7FFF)) = a2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int16 a1, char a2)
{
int result; // eax

if ( (a1 & 0xC000) == 0x4000 )
{
result = sub_romram;
*(_BYTE *)(sub_romram + a1) = a2;
return result;
}
result = verbose_io;
if ( !verbose_io )
{
if ( (a1 & 0x4000) == 0 )
return result;
goto LABEL_4;
}
result = printf("SUB Memory Write BAD %04x\n", a1);
if ( (a1 & 0x4000) != 0 )
{
LABEL_4:
result = sub_romram;
*(_BYTE *)(sub_romram + (a1 & 0x7FFF)) = a2;
}
return result;
}

original_code:
void sub_mem_write( word addr, byte data )
{
  if( (addr & 0xc000) == 0x4000 ){
    sub_romram[ addr & 0x7fff ] = data;
  }else{
    if( verbose_io ) printf("SUB Memory Write BAD %04x\n",addr);
    if( (addr & 0x4000 ) == 0x4000 ){
      sub_romram[ addr & 0x7fff ] = data;
    }
  }
}

canonical_original_code:
void sub_mem_write(unsigned short addr, unsigned char data)
{
  if( (addr & 0xc000) == 0x4000 ){
    sub_romram[ addr & 0x7fff ] = data;
  }else{
    if( verbose_io ) printf("SUB Memory Write BAD %04x\n",addr);
    if( (addr & 0x4000 ) == 0x4000 ){
      sub_romram[ addr & 0x7fff ] = data;
    }
  }
}


decompiled_code:
int __fastcall sub_io_out(unsigned __int8 a1, unsigned __int8 a2)
{
int result; // eax

if ( a1 < 0xF4u )
{
LABEL_3:
result = verbose_io;
if ( verbose_io )
result = printf("SUB OUT data %02X to undecoeded port %02XH\n", a2, a1);
}
else
{
result = (unsigned __int8)(a1 + 12);
switch ( a1 )
{
case 0xF4:
case 0xF7:
case 0xF8:
return result;
case 0xF5:
case 0xF6:
case 0xF9:
case 0xFA:
goto LABEL_3;
case 0xFB:
result = fdc_write(a2);
z80_state_intchk = 0;
break;
case 0xFC:
result = pio_write_AB(1LL, 0LL, a2);
break;
case 0xFD:
result = pio_write_AB(1LL, 1LL, a2);
break;
case 0xFE:
result = pio_write_C_direct(1LL, a2);
break;
case 0xFF:
if ( (a2 & 0x80u) != 0 )
result = pio_set_mode(1LL);
else
result = pio_write_C(1LL);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int8 a1, unsigned __int8 a2)
{
int result; // eax

if ( a1 < 0xF4u )
{
LABEL_3:
result = verbose_io;
if ( verbose_io )
result = printf("SUB OUT data %02X to undecoeded port %02XH\n", a2, a1);
}
else
{
result = (unsigned __int8)(a1 + 12);
switch ( a1 )
{
case 0xF4:
case 0xF7:
case 0xF8:
return result;
case 0xF5:
case 0xF6:
case 0xF9:
case 0xFA:
goto LABEL_3;
case 0xFB:
result = fdc_write(a2);
z80_state_intchk = 0;
break;
case 0xFC:
result = pio_write_AB(1LL, 0LL, a2);
break;
case 0xFD:
result = pio_write_AB(1LL, 1LL, a2);
break;
case 0xFE:
result = pio_write_C_direct(1LL, a2);
break;
case 0xFF:
if ( (a2 & 0x80u) != 0 )
result = pio_set_mode(1LL);
else
result = pio_write_C(1LL);
break;
}
}
return result;
}

original_code:
void sub_io_out( byte port, byte data )
{
  switch( port ){
  case 0xf4:
    return;
  case 0xf7:
    return;
  case 0xf8:
    return;
  case 0xfb:
    fdc_write( data );
    do{ z80_state_intchk = 0; }while(0);
    return;
  case 0xfc:
    if(1){}else printf("   <==%02x\n",data);
    pio_write_AB( (1), (0), data );
    return;
  case 0xfd:
    if(1){}else printf("   <--%02x\n",data);
    pio_write_AB( (1), (1), data );
    return;
  case 0xfe:
    pio_write_C_direct( (1), data );
    return;
  case 0xff:
    if( data & 0x80 ) pio_set_mode( (1), data );
    else pio_write_C( (1), data );
    return;
  }
  if( verbose_io ) printf("SUB OUT data %02X to undecoeded port %02XH\n",data,port);
}

canonical_original_code:
void sub_io_out(unsigned char port, unsigned char data)
{
  switch( port ){
  case 0xf4:
    return;
  case 0xf7:
    return;
  case 0xf8:
    return;
  case 0xfb:
    fdc_write( data );
    do{ z80_state_intchk = 0; }while(0);
    return;
  case 0xfc:
    if(1){}else printf("   <==%02x\n",data);
    pio_write_AB( (1), (0), data );
    return;
  case 0xfd:
    if(1){}else printf("   <--%02x\n",data);
    pio_write_AB( (1), (1), data );
    return;
  case 0xfe:
    pio_write_C_direct( (1), data );
    return;
  case 0xff:
    if( data & 0x80 ) pio_set_mode( (1), data );
    else pio_write_C( (1), data );
    return;
  }
  if( verbose_io ) printf("SUB OUT data %02X to undecoeded port %02XH\n",data,port);
}

variable_types:
port
unsigned char


decompiled_code:
__int64 __fastcall sub_io_in(unsigned __int8 a1)
{
__int64 result; // rax

switch ( a1 )
{
case 0xF8:
z80_state_intchk = 0;
fdc_TC();
goto LABEL_4;
case 0xFA:
z80_state_intchk = 0;
result = fdc_status();
break;
case 0xFB:
z80_state_intchk = 0;
result = fdc_read();
break;
case 0xFC:
result = pio_read_AB(1LL, 0LL);
break;
case 0xFD:
result = pio_read_AB(1LL, 1LL);
break;
case 0xFE:
result = pio_read_C(1LL);
break;
default:
if ( verbose_io )
printf("SUB IN from undecoeded port %02XH\n", a1);
LABEL_4:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
__int64 result; // rax

switch ( a1 )
{
case 0xF8:
z80_state_intchk = 0;
fdc_TC();
goto LABEL_4;
case 0xFA:
z80_state_intchk = 0;
result = fdc_status();
break;
case 0xFB:
z80_state_intchk = 0;
result = fdc_read();
break;
case 0xFC:
result = pio_read_AB(1LL, 0LL);
break;
case 0xFD:
result = pio_read_AB(1LL, 1LL);
break;
case 0xFE:
result = pio_read_C(1LL);
break;
default:
if ( verbose_io )
printf("SUB IN from undecoeded port %02XH\n", a1);
LABEL_4:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
byte sub_io_in( byte port )
{
  switch( port ){
  case 0xf8:
    do{ z80_state_intchk = 0; }while(0);
    fdc_TC();
    return 0xff;
  case 0xfa:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_status();
  case 0xfb:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_read();
  case 0xfc:
    {
      byte data = pio_read_AB( (1), (0) );
      if(1){}else printf("   ==>%02x\n",data);
      return data;
    }
  case 0xfd:
    {
      byte data = pio_read_AB( (1), (1) );
      if(1){}else printf("   -->%02x\n",data);
      return data;
    }
  case 0xfe:
    return pio_read_C( (1) );
  }
  if( verbose_io ) printf("SUB IN        from undecoeded port %02XH\n",port);
  return 0xff;
}

canonical_original_code:
unsigned char sub_io_in(unsigned char port)
{
  switch( port ){
  case 0xf8:
    do{ z80_state_intchk = 0; }while(0);
    fdc_TC();
    return 0xff;
  case 0xfa:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_status();
  case 0xfb:
    do{ z80_state_intchk = 0; }while(0);
    return fdc_read();
  case 0xfc:
    {
      unsigned char data = pio_read_AB( (1), (0) );
      if(1){}else printf("   ==>%02x\n",data);
      return data;
    }
  case 0xfd:
    {
      unsigned char data = pio_read_AB( (1), (1) );
      if(1){}else printf("   -->%02x\n",data);
      return data;
    }
  case 0xfe:
    return pio_read_C( (1) );
  }
  if( verbose_io ) printf("SUB IN        from undecoeded port %02XH\n",port);
  return 0xff;
}


decompiled_code:
__int64 __fastcall sub_INT_update(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
int v3; // eax
int v4; // ecx
int v5; // ebx
__int64 result; // rax
__int64 v7; // rdx

v2 = (unsigned int)z80sub_cpu[10];
v3 = fdc_ctrl(v2);
v4 = sub_load_rate;
v5 = v3;
z80sub_cpu[8] = FDC_flag != 0;
if ( v4 )
{
if ( cpu_timing <= 1 )
{
v7 = (unsigned int)((z80sub_cpu[10] + sub_total_state_0) >> 31);
sub_total_state_0 += z80sub_cpu[10];
if ( sub_total_state_0 / v4 >= state_of_vsync )
{
LODWORD(v7) = sub_total_state_0 % v4;
event_handle(v2, a2, v7);
draw_screen();
sub_total_state_0 = 0;
}
}
}
if ( v5 < 0 )
v5 = 999999;
z80sub_cpu[9] = v5;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
int v3; // eax
int v4; // ecx
int v5; // ebx
__int64 result; // rax
__int64 v7; // rdx

v2 = (unsigned int)z80sub_cpu[10];
v3 = fdc_ctrl(v2);
v4 = sub_load_rate;
v5 = v3;
z80sub_cpu[8] = FDC_flag != 0;
if ( v4 )
{
if ( cpu_timing <= 1 )
{
v7 = (unsigned int)((z80sub_cpu[10] + sub_total_state_0) >> 31);
sub_total_state_0 += z80sub_cpu[10];
if ( sub_total_state_0 / v4 >= state_of_vsync )
{
LODWORD(v7) = sub_total_state_0 % v4;
event_handle(v2, a2, v7);
draw_screen();
sub_total_state_0 = 0;
}
}
}
if ( v5 < 0 )
v5 = 999999;
z80sub_cpu[9] = v5;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

original_code:
void sub_INT_update( void )
{
  static int sub_total_state = 0;
  int icount;
  icount = fdc_ctrl( z80sub_cpu.state0 );
  if( FDC_flag ){ z80sub_cpu.INT_active = (1); }
  else { z80sub_cpu.INT_active = (0); }
  if( sub_load_rate && cpu_timing < 2 ){
    sub_total_state += z80sub_cpu.state0;
    if( sub_total_state/sub_load_rate >= state_of_vsync ){
      event_handle();
      draw_screen();
      sub_total_state = 0;
    }
  }
  z80sub_cpu.icount = (icount<0) ? 999999 : icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

canonical_original_code:
void sub_INT_update()
{
  static int sub_total_state = 0;
  int icount;
  icount = fdc_ctrl( z80sub_cpu.state0 );
  if( FDC_flag ){ z80sub_cpu.INT_active = (1); }
  else { z80sub_cpu.INT_active = (0); }
  if( sub_load_rate && cpu_timing < 2 ){
    sub_total_state += z80sub_cpu.state0;
    if( sub_total_state/sub_load_rate >= state_of_vsync ){
      event_handle();
      draw_screen();
      sub_total_state = 0;
    }
  }
  z80sub_cpu.icount = (icount<0) ? 999999 : icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}


decompiled_code:
void sub_INT_init()
{
FDC_flag = 0;
}

canonical_decompiled_code:
void func8()
{
FDC_flag = 0;
}

original_code:
void sub_INT_init( void )
{
  FDC_flag = (0);
}

canonical_original_code:
void sub_INT_init()
{
  FDC_flag = (0);
}


decompiled_code:
void pc88sub_term()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void pc88sub_term( void )
{
}

canonical_original_code:
void pc88sub_term()
{
}


decompiled_code:
__int64 __fastcall sub_fetch_with_BP(unsigned __int16 a1)
{
check_break_point(2, a1, "FETCH from");
return sub_fetch(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 a1)
{
func7(2, a1, "FETCH from");
return func0(a1);
}

original_code:
byte sub_fetch_with_BP( word addr )
{
  check_break_point( BP_READ, addr, "FETCH from" );
  return sub_fetch( addr );
}

canonical_original_code:
unsigned char sub_fetch_with_BP(unsigned short addr)
{
  check_break_point( BP_READ, addr, "FETCH from" );
  return sub_fetch( addr );
}


decompiled_code:
__int64 __fastcall sub_mem_read_with_BP(__int16 a1)
{
check_break_point(2, a1, "READ from");
return sub_mem_read(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1)
{
func7(2, a1, "READ from");
return func1(a1);
}

original_code:
byte sub_mem_read_with_BP( word addr )
{
  check_break_point( BP_READ, addr, "READ from" );
  return sub_mem_read( addr );
}

canonical_original_code:
unsigned char sub_mem_read_with_BP(unsigned short addr)
{
  check_break_point( BP_READ, addr, "READ from" );
  return sub_mem_read( addr );
}


decompiled_code:
int __fastcall sub_mem_write_with_BP(unsigned __int16 a1, char a2)
{
check_break_point(3, a1, "WRITE to");
return sub_mem_write(a1, a2);
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int16 a1, char a2)
{
func7(3, a1, "WRITE to");
return func3(a1, a2);
}

original_code:
void sub_mem_write_with_BP( word addr, byte data )
{
  check_break_point( BP_WRITE, addr, "WRITE to" );
  sub_mem_write( addr, data );
}

canonical_original_code:
void sub_mem_write_with_BP(unsigned short addr, unsigned char data)
{
  check_break_point( BP_WRITE, addr, "WRITE to" );
  sub_mem_write( addr, data );
}


decompiled_code:
__int64 __fastcall sub_io_in_with_BP(unsigned __int8 a1)
{
check_break_point(4, a1, "IN from");
return sub_io_in(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 a1)
{
func7(4, a1, "IN from");
return func5(a1);
}

original_code:
byte sub_io_in_with_BP( byte port )
{
  check_break_point( BP_IN, port, "IN from" );
  return sub_io_in( port );
}

canonical_original_code:
unsigned char sub_io_in_with_BP(unsigned char port)
{
  check_break_point( BP_IN, port, "IN from" );
  return sub_io_in( port );
}


decompiled_code:
int __fastcall sub_io_out_with_BP(unsigned __int8 a1, unsigned __int8 a2)
{
check_break_point(5, a1, "OUT to");
return sub_io_out(a1, a2);
}

canonical_decompiled_code:
int __fastcall func14(unsigned __int8 a1, unsigned __int8 a2)
{
func7(5, a1, "OUT to");
return func4(a1, a2);
}

original_code:
void sub_io_out_with_BP( byte port, byte data )
{
  check_break_point( BP_OUT, port, "OUT to" );
  sub_io_out( port, data );
}

canonical_original_code:
void sub_io_out_with_BP(unsigned char port, unsigned char data)
{
  check_break_point( BP_OUT, port, "OUT to" );
  sub_io_out( port, data );
}


decompiled_code:
void *pc88sub_bus_setup()
{
int v0; // eax
bool v1; // zf
void *result; // rax

v0 = memory_wait;
*(_QWORD *)&z80sub_cpu[18] = sub_mem_write;
*(_QWORD *)&z80sub_cpu[16] = sub_mem_read;
*(_QWORD *)&z80sub_cpu[20] = sub_io_in;
v1 = v0 == 0;
result = sub_fetch;
*(_QWORD *)&z80sub_cpu[22] = sub_io_out;
if ( v1 )
result = sub_mem_read;
*(_QWORD *)&z80sub_cpu[14] = result;
return result;
}

canonical_decompiled_code:
void *func15()
{
int v0; // eax
bool v1; // zf
void *result; // rax

v0 = memory_wait;
*(_QWORD *)&z80sub_cpu[18] = sub_mem_write;
*(_QWORD *)&z80sub_cpu[16] = sub_mem_read;
*(_QWORD *)&z80sub_cpu[20] = sub_io_in;
v1 = v0 == 0;
result = sub_fetch;
*(_QWORD *)&z80sub_cpu[22] = sub_io_out;
if ( v1 )
result = sub_mem_read;
*(_QWORD *)&z80sub_cpu[14] = result;
return result;
}

original_code:
void pc88sub_bus_setup( void )
{
  if( memory_wait ){
    z80sub_cpu.fetch = sub_fetch;
  }else{
    z80sub_cpu.fetch = sub_mem_read;
  }
  z80sub_cpu.mem_read = sub_mem_read;
  z80sub_cpu.mem_write = sub_mem_write;
  z80sub_cpu.io_read = sub_io_in;
  z80sub_cpu.io_write = sub_io_out;
}

canonical_original_code:
void pc88sub_bus_setup()
{
  if( memory_wait ){
    z80sub_cpu.fetch = sub_fetch;
  }else{
    z80sub_cpu.fetch = sub_mem_read;
  }
  z80sub_cpu.mem_read = sub_mem_read;
  z80sub_cpu.mem_write = sub_mem_write;
  z80sub_cpu.io_read = sub_io_in;
  z80sub_cpu.io_write = sub_io_out;
}


decompiled_code:
void __fastcall pc88sub_init(unsigned int a1)
{
__int16 v1; // ax
__int16 v2; // ax

if ( a1 <= 1 )
{
z80_reset(z80sub_cpu);
pc88sub_bus_setup();
v2 = z80sub_cpu[3];
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
LOWORD(z80sub_cpu[28]) = v2;
LOWORD(z80sub_cpu[12]) = 256;
sub_INT_init();
}
else
{
pc88sub_bus_setup();
v1 = z80sub_cpu[3];
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
LOWORD(z80sub_cpu[28]) = v1;
LOWORD(z80sub_cpu[12]) = 256;
}
}

canonical_decompiled_code:
void __fastcall func16(unsigned int a1)
{
__int16 v1; // ax
__int16 v2; // ax

if ( a1 <= 1 )
{
z80_reset(z80sub_cpu);
func15();
v2 = z80sub_cpu[3];
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
LOWORD(z80sub_cpu[28]) = v2;
LOWORD(z80sub_cpu[12]) = 256;
func8();
}
else
{
func15();
v1 = z80sub_cpu[3];
*(_QWORD *)&z80sub_cpu[24] = sub_INT_update;
*(_QWORD *)&z80sub_cpu[26] = sub_INT_chk;
LOWORD(z80sub_cpu[28]) = v1;
LOWORD(z80sub_cpu[12]) = 256;
}
}

original_code:
void pc88sub_init( int init )
{
  if( init == (0) || init == (1) ){
    z80_reset( &z80sub_cpu );
  }
  pc88sub_bus_setup();
  z80sub_cpu.intr_update = sub_INT_update;
  z80sub_cpu.intr_ack = sub_INT_chk;
  z80sub_cpu.break_if_halt = (1);
  z80sub_cpu.PC_prev = z80sub_cpu.PC;
  z80sub_cpu.log = (0);
  if( init == (0) || init == (1) ){
    sub_INT_init();
  }
}

canonical_original_code:
void pc88sub_init(int init)
{
  if( init == (0) || init == (1) ){
    z80_reset( &z80sub_cpu );
  }
  pc88sub_bus_setup();
  z80sub_cpu.intr_update = sub_INT_update;
  z80sub_cpu.intr_ack = sub_INT_chk;
  z80sub_cpu.break_if_halt = (1);
  z80sub_cpu.PC_prev = z80sub_cpu.PC;
  z80sub_cpu.log = (0);
  if( init == (0) || init == (1) ){
    sub_INT_init();
  }
}

variable_types: init int


decompiled_code:
_BOOL8 statesave_pc88sub()
{
return (unsigned int)statesave_table("SUB ", &suspend_pc88sub_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func17()
{
return (unsigned int)statesave_table("SUB ", &suspend_pc88sub_work) == 0;
}

original_code:
int statesave_pc88sub( void )
{
  if( statesave_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int statesave_pc88sub()
{
  if( statesave_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
_BOOL8 stateload_pc88sub()
{
return (unsigned int)stateload_table("SUB ", &suspend_pc88sub_work) == 0;
}

canonical_decompiled_code:
_BOOL8 func18()
{
return (unsigned int)stateload_table("SUB ", &suspend_pc88sub_work) == 0;
}

original_code:
int stateload_pc88sub( void )
{
  if( stateload_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}

canonical_original_code:
int stateload_pc88sub()
{
  if( stateload_table( "SUB ", suspend_pc88sub_work ) == (0) ) return (1);
  else return (0);
}


decompiled_code:
__int64 __fastcall check_break_point(int a1, unsigned __int16 a2, const char *a3)
{
__int64 result; // rax

result = get_emu_mode();
if ( (_DWORD)result != 5 )
{
result = 0LL;
while ( break_point[2 * result + 20] != a1 || break_point[2 * result + 21] != a2 )
{
if ( ++result == 10 )
return result;
}
printf("*** Break at %04x *** ( SUB[#%d] : %s %04x )\n", LOWORD(z80sub_cpu[3]), (unsigned int)(result + 1), a3, a2);
result = set_emu_mode(5LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned __int16 a2, const char *a3)
{
__int64 result; // rax

result = get_emu_mode();
if ( (_DWORD)result != 5 )
{
result = 0LL;
while ( break_point[2 * result + 20] != a1 || break_point[2 * result + 21] != a2 )
{
if ( ++result == 10 )
return result;
}
printf("*** Break at %04x *** ( SUB[#%d] : %s %04x )\n", LOWORD(z80sub_cpu[3]), (unsigned int)(result + 1), a3, a2);
result = set_emu_mode(5LL);
}
return result;
}

original_code:
static __inline__ void check_break_point( int type, word addr, char *str )
{
  int i;
  if ( get_emu_mode() == MONITOR ) return;
  for( i=0; i<(10); i++ ){
    if( break_point[BP_SUB][i].type == type &&
        break_point[BP_SUB][i].addr == addr ){
      printf( "*** Break at %04x *** ( SUB[#%d] : %s %04x )\n",
       z80sub_cpu.PC.W, i+1, str, addr );
      set_emu_mode( MONITOR );
      break;
    }
  }
}

canonical_original_code:
static __inline__ void check_break_point(int type, unsigned short addr, char *str)
{
  int i;
  if ( get_emu_mode() == MONITOR ) return;
  for( i=0; i<(10); i++ ){
    if( break_point[BP_SUB][i].type == type &&
        break_point[BP_SUB][i].addr == addr ){
      printf( "*** Break at %04x *** ( SUB[#%d] : %s %04x )\n",
       z80sub_cpu.PC.W, i+1, str, addr );
      set_emu_mode( MONITOR );
      break;
    }
  }
}

variable_types: type int

variable_types:
str
char *


decompiled_code:
void *filter_alloc()
{
return malloc(0x6CuLL);
}

canonical_decompiled_code:
void *func0()
{
return malloc(0x6CuLL);
}

original_code:
static filter* filter_alloc(void) {
 filter* f = malloc(sizeof(filter));
 return f;
}

canonical_original_code:
static struct filter_struct *filter_alloc() {
 struct filter_struct *f = malloc(sizeof(filter));
 return f;
}

variable_types: struct filter_struct { int xcoeffs[-1]; unsigned int order; } *


decompiled_code:
// attributes: thunk
void filter_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
void filter_free(filter* f) {
 free(f);
}

canonical_original_code:
void filter_free(struct filter_struct *f) {
 free(f);
}

user_defined_types: struct filter_struct { int xcoeffs[-1]; unsigned int order; }


decompiled_code:
void *__fastcall filter_state_reset(__int64 a1, _DWORD *a2)
{
__int64 v2; // rdx
void *result; // rax

v2 = *(unsigned int *)(a1 + 104);
*a2 = 0;
if ( (_DWORD)v2 )
result = memset(a2 + 1, 0, 4 * v2);
return result;
}

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

v2 = *(unsigned int *)(a1 + 104);
*a2 = 0;
if ( (_DWORD)v2 )
result = memset(a2 + 1, 0, 4 * v2);
return result;
}

original_code:
void filter_state_reset(filter* f, filter_state* s) {
 int i;
 s->prev_mac = 0;
 for(i=0;i<f->order;++i) {
  s->xprev[i] = 0;
 }
}

canonical_original_code:
void filter_state_reset(struct filter_struct *f, struct filter_state_struct *s) {
 int i;
 s->prev_mac = 0;
 for(i=0;i<f->order;++i) {
  s->xprev[i] = 0;
 }
}

variable_types: struct filter_state_struct { unsigned int prev_mac; int xprev[51]; } *

variable_types: i int


decompiled_code:
_QWORD *filter_state_alloc()
{
_QWORD *v0; // r8

v0 = malloc(0xD0uLL);
*(_DWORD *)v0 = 0;
*(_QWORD *)((char *)v0 + 4) = 0LL;
v0[25] = 0LL;
memset(
(void *)(((unsigned __int64)v0 + 12) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 12) & 0xFFFFFFF8) + 208) >> 3));
return v0;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // r8

v0 = malloc(0xD0uLL);
*(_DWORD *)v0 = 0;
*(_QWORD *)((char *)v0 + 4) = 0LL;
v0[25] = 0LL;
memset(
(void *)(((unsigned __int64)v0 + 12) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 12) & 0xFFFFFFF8) + 208) >> 3));
return v0;
}

original_code:
filter_state* filter_state_alloc(void) {
 int i;
        filter_state* s = malloc(sizeof(filter_state));
 s->prev_mac = 0;
 for(i=0;i<51;++i)
  s->xprev[i] = 0;
 return s;
}

canonical_original_code:
struct filter_state_struct *filter_state_alloc() {
 int i;
        struct filter_state_struct *s = malloc(sizeof(filter_state));
 s->prev_mac = 0;
 for(i=0;i<51;++i)
  s->xprev[i] = 0;
 return s;
}

return_type: struct filter_state_struct { unsigned int prev_mac; int xprev[51]; } *


decompiled_code:
// attributes: thunk
void filter_state_free(void *ptr)
{
filter_free(ptr);
}

canonical_decompiled_code:
void func4(void *ptr)
{
func1(ptr);
}

original_code:
void filter_state_free(filter_state* s) {
 free(s);
}

canonical_original_code:
void filter_state_free(struct filter_state_struct *s) {
 free(s);
}

user_defined_types: struct filter_state_struct { unsigned int prev_mac; int xprev[51]; }


original_code:
filter_real filter_compute(filter* f, filter_state* s) {
 unsigned order = f->order;
 unsigned midorder = f->order / 2;
 filter_real y = 0;
 unsigned i,j,k;
 i = s->prev_mac;
 j = i + 1;
 if (j == order)
  j = 0;
 for(k=0;k<midorder;++k) {
  y += f->xcoeffs[midorder-k] * (s->xprev[i] + s->xprev[j]);
  ++j;
  if (j == order)
   j = 0;
  if (i == 0)
   i = order - 1;
  else
   --i;
 }
 y += f->xcoeffs[0] * s->xprev[i];
 return y >> 15;
}

canonical_original_code:
int filter_compute(struct filter_struct *f, struct filter_state_struct *s) {
 unsigned int order = f->order;
 unsigned int midorder = f->order / 2;
 int y = 0;
 unsigned int i; unsigned int j; unsigned int k;
 i = s->prev_mac;
 j = i + 1;
 if (j == order)
  j = 0;
 for(k=0;k<midorder;++k) {
  y += f->xcoeffs[midorder-k] * (s->xprev[i] + s->xprev[j]);
  ++j;
  if (j == order)
   j = 0;
  if (i == 0)
   i = order - 1;
  else
   --i;
 }
 y += f->xcoeffs[0] * s->xprev[i];
 return y >> 15;
}

variable_types:
order
unsigned int

variable_types:
midorder
unsigned int

variable_types: y int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
k
unsigned int


decompiled_code:
__int64 statefile_revision()
{
return (unsigned int)statefile_rev;
}

canonical_decompiled_code:
__int64 func22()
{
return (unsigned int)statefile_rev;
}

original_code:
int statefile_revision( void )
{
  return statefile_rev;
}

canonical_original_code:
int statefile_revision()
{
  return statefile_rev;
}


statesave

decompiled_code:
_BOOL8 statesave()
{
_BOOL4 v0; // er12
_BOOL8 result; // rax

if ( file_state )
{
if ( verbose_suspend )
printf("statesave : %s\n", &file_state);
v0 = 0;
statesave_fp = osd_fopen(13LL, &file_state, "wb");
if ( statesave_fp )
{
if ( !(unsigned int)statesave_header()
&& (unsigned int)statesave_emu()
&& (unsigned int)statesave_memory()
&& (unsigned int)statesave_pc88main()
&& (unsigned int)statesave_crtcdmac()
&& (unsigned int)statesave_sound()
&& (unsigned int)statesave_pio()
&& (unsigned int)statesave_screen()
&& (unsigned int)statesave_intr()
&& (unsigned int)statesave_keyboard()
&& (unsigned int)statesave_pc88sub()
&& (unsigned int)statesave_fdc() )
{
v0 = statesave_system() != 0;
}
else
{
v0 = 0;
}
osd_fclose(statesave_fp);
}
result = v0;
}
else
{
puts("state-file name not defined");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func24()
{
_BOOL4 v0; // er12
_BOOL8 result; // rax

if ( file_state )
{
if ( verbose_suspend )
printf("statesave : %s\n", &file_state);
v0 = 0;
statesave_fp = osd_fopen(13LL, &file_state, "wb");
if ( statesave_fp )
{
if ( !(unsigned int)func12()
&& (unsigned int)statesave_emu()
&& (unsigned int)statesave_memory()
&& (unsigned int)statesave_pc88main()
&& (unsigned int)statesave_crtcdmac()
&& (unsigned int)statesave_sound()
&& (unsigned int)statesave_pio()
&& (unsigned int)statesave_screen()
&& (unsigned int)statesave_intr()
&& (unsigned int)statesave_keyboard()
&& (unsigned int)statesave_pc88sub()
&& (unsigned int)statesave_fdc() )
{
v0 = statesave_system() != 0;
}
else
{
v0 = 0;
}
osd_fclose(statesave_fp);
}
result = v0;
}
else
{
puts("state-file name not defined");
result = 0LL;
}
return result;
}

original_code:
int statesave( void )
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "statesave : %s\n", file_state );
  if( (statesave_fp = osd_fopen( FTYPE_STATE_SAVE, file_state, "wb" )) ){
    if( statesave_header() == (0) ){
      do{
 if( statesave_emu() == (0) ) break;
 if( statesave_memory() == (0) ) break;
 if( statesave_pc88main() == (0) ) break;
 if( statesave_crtcdmac() == (0) ) break;
 if( statesave_sound() == (0) ) break;
 if( statesave_pio() == (0) ) break;
 if( statesave_screen() == (0) ) break;
 if( statesave_intr() == (0) ) break;
 if( statesave_keyboard() == (0) ) break;
 if( statesave_pc88sub() == (0) ) break;
 if( statesave_fdc() == (0) ) break;
 if( statesave_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( statesave_fp );
  }
  return success;
}

canonical_original_code:
int statesave()
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "statesave : %s\n", file_state );
  if( (statesave_fp = osd_fopen( FTYPE_STATE_SAVE, file_state, "wb" )) ){
    if( statesave_header() == (0) ){
      do{
 if( statesave_emu() == (0) ) break;
 if( statesave_memory() == (0) ) break;
 if( statesave_pc88main() == (0) ) break;
 if( statesave_crtcdmac() == (0) ) break;
 if( statesave_sound() == (0) ) break;
 if( statesave_pio() == (0) ) break;
 if( statesave_screen() == (0) ) break;
 if( statesave_intr() == (0) ) break;
 if( statesave_keyboard() == (0) ) break;
 if( statesave_pc88sub() == (0) ) break;
 if( statesave_fdc() == (0) ) break;
 if( statesave_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( statesave_fp );
  }
  return success;
}

variable_types: success int


decompiled_code:
__int64 stateload_check()
{
unsigned int v0; // er12
const char *v1; // rsi

if ( file_state )
{
stateload_fp = osd_fopen(12LL, &file_state, "rb");
if ( stateload_fp )
{
if ( !(unsigned int)stateload_header() )
{
osd_fclose(stateload_fp);
v0 = 1;
if ( verbose_suspend )
{
v1 = "OK";
goto LABEL_4;
}
return v0;
}
osd_fclose(stateload_fp);
}
}
if ( verbose_suspend )
{
v0 = 0;
v1 = "FAILED";
LABEL_4:
printf("stateload: file check ... %s\n", v1);
return v0;
}
return 0;
}

canonical_decompiled_code:
__int64 func25()
{
unsigned int v0; // er12
const char *v1; // rsi

if ( file_state )
{
stateload_fp = osd_fopen(12LL, &file_state, "rb");
if ( stateload_fp )
{
if ( !(unsigned int)func11() )
{
osd_fclose(stateload_fp);
v0 = 1;
if ( verbose_suspend )
{
v1 = "OK";
goto LABEL_4;
}
return v0;
}
osd_fclose(stateload_fp);
}
}
if ( verbose_suspend )
{
v0 = 0;
v1 = "FAILED";
LABEL_4:
printf("stateload: file check ... %s\n", v1);
return v0;
}
return 0;
}

original_code:
int stateload_check( void )
{
  int success = (0);
  if( file_state[0] &&
      (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      success = (1);
    }
    osd_fclose( stateload_fp );
  }
  if( verbose_suspend ){
    printf( "stateload: file check ... %s\n", (success)?"OK":"FAILED" );
  }
  return success;
}

canonical_original_code:
int stateload_check()
{
  int success = (0);
  if( file_state[0] &&
      (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      success = (1);
    }
    osd_fclose( stateload_fp );
  }
  if( verbose_suspend ){
    printf( "stateload: file check ... %s\n", (success)?"OK":"FAILED" );
  }
  return success;
}


stateload

decompiled_code:
_BOOL8 stateload()
{
_BOOL4 v0; // er12
_BOOL8 result; // rax

if ( file_state )
{
if ( verbose_suspend )
printf("stateload: %s\n", &file_state);
v0 = 0;
stateload_fp = osd_fopen(12LL, &file_state, "rb");
if ( stateload_fp )
{
if ( !(unsigned int)stateload_header()
&& (unsigned int)stateload_emu()
&& (unsigned int)stateload_sound()
&& (unsigned int)stateload_memory()
&& (unsigned int)stateload_pc88main()
&& (unsigned int)stateload_crtcdmac()
&& (unsigned int)stateload_pio()
&& (unsigned int)stateload_screen()
&& (unsigned int)stateload_intr()
&& (unsigned int)stateload_keyboard()
&& (unsigned int)stateload_pc88sub()
&& (unsigned int)stateload_fdc() )
{
v0 = stateload_system() != 0;
}
else
{
v0 = 0;
}
osd_fclose(stateload_fp);
}
result = v0;
}
else
{
puts("state-file name not defined");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func26()
{
_BOOL4 v0; // er12
_BOOL8 result; // rax

if ( file_state )
{
if ( verbose_suspend )
printf("stateload: %s\n", &file_state);
v0 = 0;
stateload_fp = osd_fopen(12LL, &file_state, "rb");
if ( stateload_fp )
{
if ( !(unsigned int)func11()
&& (unsigned int)stateload_emu()
&& (unsigned int)stateload_sound()
&& (unsigned int)stateload_memory()
&& (unsigned int)stateload_pc88main()
&& (unsigned int)stateload_crtcdmac()
&& (unsigned int)stateload_pio()
&& (unsigned int)stateload_screen()
&& (unsigned int)stateload_intr()
&& (unsigned int)stateload_keyboard()
&& (unsigned int)stateload_pc88sub()
&& (unsigned int)stateload_fdc() )
{
v0 = stateload_system() != 0;
}
else
{
v0 = 0;
}
osd_fclose(stateload_fp);
}
result = v0;
}
else
{
puts("state-file name not defined");
result = 0LL;
}
return result;
}

original_code:
int stateload( void )
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "stateload: %s\n", file_state );
  if( (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      do{
 if( stateload_emu() == (0) ) break;
 if( stateload_sound() == (0) ) break;
 if( stateload_memory() == (0) ) break;
 if( stateload_pc88main() == (0) ) break;
 if( stateload_crtcdmac() == (0) ) break;
 if( stateload_pio() == (0) ) break;
 if( stateload_screen() == (0) ) break;
 if( stateload_intr() == (0) ) break;
 if( stateload_keyboard() == (0) ) break;
 if( stateload_pc88sub() == (0) ) break;
 if( stateload_fdc() == (0) ) break;
 if( stateload_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( stateload_fp );
  }
  return success;
}

canonical_original_code:
int stateload()
{
  int success = (0);
  if( file_state[0] == '\0' ){
    printf( "state-file name not defined\n" );
    return (0);
  }
  if( verbose_suspend )
    printf( "stateload: %s\n", file_state );
  if( (stateload_fp = osd_fopen( FTYPE_STATE_LOAD, file_state, "rb" )) ){
    if( stateload_header() == (0) ){
      do{
 if( stateload_emu() == (0) ) break;
 if( stateload_sound() == (0) ) break;
 if( stateload_memory() == (0) ) break;
 if( stateload_pc88main() == (0) ) break;
 if( stateload_crtcdmac() == (0) ) break;
 if( stateload_pio() == (0) ) break;
 if( stateload_screen() == (0) ) break;
 if( stateload_intr() == (0) ) break;
 if( stateload_keyboard() == (0) ) break;
 if( stateload_pc88sub() == (0) ) break;
 if( stateload_fdc() == (0) ) break;
 if( stateload_system() == (0) ) break;
 success = (1);
      }while(0);
    }
    osd_fclose( stateload_fp );
  }
  return success;
}


decompiled_code:
void stateload_init()
{
if ( (!file_state || resume_flag && !resume_file) && !(unsigned int)set_state_filename(1LL) )
{
puts("stateload: Intarnal err...");
resume_flag = 0;
}
}

canonical_decompiled_code:
void func27()
{
if ( (!file_state || resume_flag && !resume_file) && !(unsigned int)set_state_filename(1LL) )
{
puts("stateload: Intarnal err...");
resume_flag = 0;
}
}

original_code:
void stateload_init( void )
{
  if( file_state[0] == '\0' ||
      ( resume_flag && resume_file == (0) ) ){
    if( set_state_filename( (1) ) == (0) ){
      printf( "stateload: Intarnal err...\n" );
      resume_flag = (0);
    }
  }
}

canonical_original_code:
void stateload_init()
{
  if( file_state[0] == '\0' ||
      ( resume_flag && resume_file == (0) ) ){
    if( set_state_filename( (1) ) == (0) ){
      printf( "stateload: Intarnal err...\n" );
      resume_flag = (0);
    }
  }
}