decompiled_code:
__int64 osd_get_mastervolume()
{
int v1; // [rsp+0h] [rbp-10h] BYREF
char v2[12]; // [rsp+4h] [rbp-Ch] BYREF

if ( !sound_mixer )
return 4294967264LL;
if ( (unsigned int)sysdep_mixer_get(sound_mixer, 1LL, &v1, v2) )
return 4294967264LL;
return (unsigned int)(int)(float)((float)((float)((float)v1 * 32.0) / 100.0) - 32.5);
}

canonical_decompiled_code:
__int64 func3()
{
int v1; // [rsp+0h] [rbp-10h] BYREF
char v2[12]; // [rsp+4h] [rbp-Ch] BYREF

if ( !sound_mixer )
return 4294967264LL;
if ( (unsigned int)sysdep_mixer_get(sound_mixer, 1LL, &v1, v2) )
return 4294967264LL;
return (unsigned int)(int)(float)((float)((float)((float)v1 * 32.0) / 100.0) - 32.5);
}

original_code:
int osd_get_mastervolume (void)
{
   int left, right;
   float f;
   if(!sound_mixer)
      return -32;
   if(sysdep_mixer_get(sound_mixer, 1, &left, &right))
      return -32;
   f = left;
   f *= 32.0;
   f /= 100.0;
   f -= 32.5;
   return f;
}

canonical_original_code:
int osd_get_mastervolume()
{
   int left; int right;
   float f;
   if(!sound_mixer)
      return -32;
   if(sysdep_mixer_get(sound_mixer, 1, &left, &right))
      return -32;
   f = left;
   f *= 32.0;
   f /= 100.0;
   f -= 32.5;
   return f;
}

variable_types: left int

variable_types: right int


decompiled_code:
__int64 __fastcall osd_update_audio_stream(__int64 a1)
{
if ( use_sound )
sound_stream_write(sound_stream, a1, (unsigned int)sound_samples_per_frame);
return (unsigned int)sound_samples_per_frame;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( use_sound )
sound_stream_write(sound_stream, a1, (unsigned int)sound_samples_per_frame);
return (unsigned int)sound_samples_per_frame;
}

original_code:
int osd_update_audio_stream(INT16 *buffer)
{
   if (use_sound)
      sound_stream_write(sound_stream, (unsigned char *)buffer,
         sound_samples_per_frame);
   return sound_samples_per_frame;
}

canonical_original_code:
int osd_update_audio_stream(short *buffer)
{
   if (use_sound)
      sound_stream_write(sound_stream, (unsigned char *)buffer,
         sound_samples_per_frame);
   return sound_samples_per_frame;
}

variable_types:
buffer
short *

return_type: int


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

if ( sound_stream )
result = sound_stream_destroy();
if ( sound_dsp )
result = sysdep_dsp_destroy();
if ( sound_mixer )
result = sysdep_mixer_destroy();
return result;
}

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

if ( sound_stream )
result = sound_stream_destroy();
if ( sound_dsp )
result = sysdep_dsp_destroy();
if ( sound_mixer )
result = sysdep_mixer_destroy();
return result;
}

original_code:
void osd_stop_audio_stream(void)
{
   if(sound_stream)
      sound_stream_destroy(sound_stream);
   if(sound_dsp)
      sysdep_dsp_destroy(sound_dsp);
   if(sound_mixer)
      sysdep_mixer_destroy(sound_mixer);
}

canonical_original_code:
void osd_stop_audio_stream()
{
   if(sound_stream)
      sound_stream_destroy(sound_stream);
   if(sound_dsp)
      sysdep_dsp_destroy(sound_dsp);
   if(sound_mixer)
      sysdep_mixer_destroy(sound_mixer);
}

return_type: void


decompiled_code:
void __fastcall osd_sound_enable(int a1)
{
float v1; // xmm1_4

if ( sound_stream && a1 )
{
use_sound = 1;
xmame_func = &xmame_func_sound;
if ( sound_dsp )
return;
v1 = vsync_freq_hz;
sound_dsp = sysdep_dsp_create(
0LL,
sound_dsp_device,
&sample_rate,
&type,
5LL,
(float)(1.0 / v1) * *(float *)&sound_bufsize);
if ( sound_dsp )
{
sound_stream_destroy(sound_stream);
sound_stream = sound_stream_create(sound_dsp, (unsigned int)type, (unsigned int)sound_samples_per_frame, 3LL);
if ( sound_stream )
return;
osd_stop_audio_stream();
}
}
else if ( sound_dsp )
{
sysdep_dsp_destroy(sound_dsp);
sound_dsp = 0LL;
}
use_sound = 0;
xmame_func = &xmame_func_nosound;
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
float v1; // xmm1_4

if ( sound_stream && a1 )
{
use_sound = 1;
xmame_func = &xmame_func_sound;
if ( sound_dsp )
return;
v1 = vsync_freq_hz;
sound_dsp = sysdep_dsp_create(
0LL,
sound_dsp_device,
&sample_rate,
&type,
5LL,
(float)(1.0 / v1) * *(float *)&sound_bufsize);
if ( sound_dsp )
{
sound_stream_destroy(sound_stream);
sound_stream = sound_stream_create(sound_dsp, (unsigned int)type, (unsigned int)sound_samples_per_frame, 3LL);
if ( sound_stream )
return;
func5();
}
}
else if ( sound_dsp )
{
sysdep_dsp_destroy(sound_dsp);
sound_dsp = 0LL;
}
use_sound = 0;
xmame_func = &xmame_func_nosound;
}

original_code:
void osd_sound_enable (int enable_it)
{
   if (sound_stream && enable_it)
   {
      use_sound = 1;
      do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
      if (!sound_dsp)
      {
  if (!(sound_dsp = sysdep_dsp_create(((void *)0),
     sound_dsp_device,
     &sample_rate,
     &type,
     sound_bufsize * (1 / ((float)(vsync_freq_hz))),
     0x01 | 0x04)))
  {
     use_sound = 0;
     do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
  }
  else
  {
     sound_stream_destroy(sound_stream);
     if (!(sound_stream = sound_stream_create(sound_dsp, type,
        sound_samples_per_frame, 3)))
     {
        osd_stop_audio_stream();
        use_sound = 0;
        do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
     }
  }
      }
   }
   else
   {
      if (sound_dsp)
      {
  sysdep_dsp_destroy(sound_dsp);
  sound_dsp = ((void *)0);
      }
      use_sound = 0;
      do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
   }
}

canonical_original_code:
void osd_sound_enable(int enable_it)
{
   if (sound_stream && enable_it)
   {
      use_sound = 1;
      do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
      if (!sound_dsp)
      {
  if (!(sound_dsp = sysdep_dsp_create(((void *)0),
     sound_dsp_device,
     &sample_rate,
     &type,
     sound_bufsize * (1 / ((float)(vsync_freq_hz))),
     0x01 | 0x04)))
  {
     use_sound = 0;
     do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
  }
  else
  {
     sound_stream_destroy(sound_stream);
     if (!(sound_stream = sound_stream_create(sound_dsp, type,
        sound_samples_per_frame, 3)))
     {
        osd_stop_audio_stream();
        use_sound = 0;
        do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
     }
  }
      }
   }
   else
   {
      if (sound_dsp)
      {
  sysdep_dsp_destroy(sound_dsp);
  sound_dsp = ((void *)0);
      }
      use_sound = 0;
      do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
   }
}


decompiled_code:
__int64 __fastcall osd_start_audio_stream(int a1)
{
float v1; // xmm1_4
int v2; // eax
float v3; // xmm0_4
float v4; // xmm0_4
__int64 result; // rax
__int64 v6; // rdi

v1 = vsync_freq_hz;
sound_stream = 0LL;
type = a1 == 0 ? 1 : 3;
if ( !use_sound )
{
LABEL_2:
v2 = sound_fake;
if ( sound_fake )
{
v3 = *(float *)&LC6;
v2 = 8000;
}
else
{
v3 = 0.0;
}
v4 = v3 / v1;
sample_rate = v2;
result = (unsigned int)(int)v4;
sound_samples_per_frame = (int)v4;
return result;
}
sound_dsp = sysdep_dsp_create(
0LL,
sound_dsp_device,
&sample_rate,
&type,
5LL,
(float)(1.0 / v1) * *(float *)&sound_bufsize);
v6 = sound_dsp;
if ( !sound_dsp )
goto LABEL_14;
v1 = vsync_freq_hz;
if ( !use_sound )
goto LABEL_2;
sound_samples_per_frame = (int)(float)((float)sample_rate / v1);
sound_stream = sound_stream_create(sound_dsp, (unsigned int)type, (unsigned int)sound_samples_per_frame, 3LL);
if ( !sound_stream )
{
LABEL_14:
osd_stop_audio_stream(v6);
use_sound = 0;
xmame_func = &xmame_func_nosound;
v1 = vsync_freq_hz;
goto LABEL_2;
}
if ( !use_sound )
{
v1 = vsync_freq_hz;
goto LABEL_2;
}
sound_mixer = sysdep_mixer_create(0LL, sound_mixer_device, 1LL);
if ( sound_mixer && (unsigned int)rc_get_priority2(&sound_opts, "volume") )
osd_set_mastervolume(sound_attenuation);
return (unsigned int)sound_samples_per_frame;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
float v1; // xmm1_4
int v2; // eax
float v3; // xmm0_4
float v4; // xmm0_4
__int64 result; // rax
__int64 v6; // rdi

v1 = vsync_freq_hz;
sound_stream = 0LL;
type = a1 == 0 ? 1 : 3;
if ( !use_sound )
{
LABEL_2:
v2 = sound_fake;
if ( sound_fake )
{
v3 = *(float *)&LC6;
v2 = 8000;
}
else
{
v3 = 0.0;
}
v4 = v3 / v1;
sample_rate = v2;
result = (unsigned int)(int)v4;
sound_samples_per_frame = (int)v4;
return result;
}
sound_dsp = sysdep_dsp_create(
0LL,
sound_dsp_device,
&sample_rate,
&type,
5LL,
(float)(1.0 / v1) * *(float *)&sound_bufsize);
v6 = sound_dsp;
if ( !sound_dsp )
goto LABEL_14;
v1 = vsync_freq_hz;
if ( !use_sound )
goto LABEL_2;
sound_samples_per_frame = (int)(float)((float)sample_rate / v1);
sound_stream = sound_stream_create(sound_dsp, (unsigned int)type, (unsigned int)sound_samples_per_frame, 3LL);
if ( !sound_stream )
{
LABEL_14:
func5(v6);
use_sound = 0;
xmame_func = &xmame_func_nosound;
v1 = vsync_freq_hz;
goto LABEL_2;
}
if ( !use_sound )
{
v1 = vsync_freq_hz;
goto LABEL_2;
}
sound_mixer = sysdep_mixer_create(0LL, sound_mixer_device, 1LL);
if ( sound_mixer && (unsigned int)rc_get_priority2(&sound_opts, "volume") )
func2(sound_attenuation);
return (unsigned int)sound_samples_per_frame;
}

original_code:
int osd_start_audio_stream(int stereo)
{
   type = 0x01 | (stereo? 0x02:0x00);
   sound_stream = ((void *)0);
   if(use_sound)
   {
      if(!(sound_dsp = sysdep_dsp_create(((void *)0),
         sound_dsp_device,
         &sample_rate,
         &type,
         sound_bufsize * (1 / ((float)(vsync_freq_hz))),
         0x01 | 0x04)))
      {
         osd_stop_audio_stream();
         use_sound = 0;
  do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
      }
   }
   if(use_sound)
   {
      sound_samples_per_frame = sample_rate /
         ((float)(vsync_freq_hz));
      if(!(sound_stream = sound_stream_create(sound_dsp, type,
         sound_samples_per_frame, 3)))
      {
         osd_stop_audio_stream();
         use_sound = 0;
  do{ if( use_sound ) xmame_func = &xmame_func_sound; else xmame_func = &xmame_func_nosound; }while(0);
      }
   }
   if(!use_sound)
   {
      if(sound_fake)
         sample_rate = 8000;
      else
         sample_rate = 0;
      sound_samples_per_frame = sample_rate /
         ((float)(vsync_freq_hz));
      return sound_samples_per_frame;
   }
   sound_mixer = sysdep_mixer_create(((void *)0), sound_mixer_device,
      0x01);
   if(sound_mixer && rc_get_priority2(sound_opts, "volume"))
      osd_set_mastervolume(sound_attenuation);
   return sound_samples_per_frame;
}

variable_types: stereo int


original_code:
static void status_puts( int type, const unsigned char *str )
{
  int i, j, k, c, w, h16;
  const byte *p;
  byte mask;
  byte *dst = status_info[ type ].pixmap;
  if( str ){
    w = (((strlen((char *)str) * 8)<((48*8)))?(strlen((char *)str) * 8):((48*8)));
    for( i=0; i<w; i+=8 ){
      c = *str ++;
      if( c=='\0' ) break;
      if( c < 0xe0 ){
 if( has_kanji_rom &&
     (( 0x20 <= c && c <= 0x7f ) ||
      ( 0xa0 <= c && c <= 0xdf ) ) ){
   p = &kanji_rom[0][ c*8 ][0];
   h16 = (1);
 }else{
   p = &font_mem[ c*8 ];
   h16 = (0);
 }
 for( j=0; j<16; j++ ){
   for( mask=0x80, k=0; k<8; k++, mask>>=1 ){
     if( *p & mask ) dst[ j*w +i +k ] = STATUS_FG;
     else dst[ j*w +i +k ] = STATUS_BG;
   }
   if( h16 || j&1 ) p++;
 }
      }else{
 p = &status_font[ (c-0xe0) ][0];
 for( j=0; j<16; j++ ){
   for( k=0; k<8; k++ ){
     dst[ j*w +i +k ] = *p;
     p++;
   }
 }
      }
    }
    status_info[ type ].w = i;
  }else{
    status_info[ type ].w = 0;
  }
}

canonical_original_code:
static void status_puts(int type, unsigned char *str)
{
  int i; int j; int k; int c; int w; int h16;
  unsigned char *p;
  unsigned char mask;
  unsigned char *dst = status_info[ type ].pixmap;
  if( str ){
    w = (((strlen((char *)str) * 8)<((48*8)))?(strlen((char *)str) * 8):((48*8)));
    for( i=0; i<w; i+=8 ){
      c = *str ++;
      if( c=='\0' ) break;
      if( c < 0xe0 ){
 if( has_kanji_rom &&
     (( 0x20 <= c && c <= 0x7f ) ||
      ( 0xa0 <= c && c <= 0xdf ) ) ){
   p = &kanji_rom[0][ c*8 ][0];
   h16 = (1);
 }else{
   p = &font_mem[ c*8 ];
   h16 = (0);
 }
 for( j=0; j<16; j++ ){
   for( mask=0x80, k=0; k<8; k++, mask>>=1 ){
     if( *p & mask ) dst[ j*w +i +k ] = STATUS_FG;
     else dst[ j*w +i +k ] = STATUS_BG;
   }
   if( h16 || j&1 ) p++;
 }
      }else{
 p = &status_font[ (c-0xe0) ][0];
 for( j=0; j<16; j++ ){
   for( k=0; k<8; k++ ){
     dst[ j*w +i +k ] = *p;
     p++;
   }
 }
      }
    }
    status_info[ type ].w = i;
  }else{
    status_info[ type ].w = 0;
  }
}

variable_types: type int

variable_types:
str
unsigned char *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: c int

variable_types: w int

variable_types:
p
unsigned char *

variable_types:
mask
unsigned char

variable_types:
dst
unsigned char *


decompiled_code:
__int64 status_mode()
{
int v0; // ebx
__int64 result; // rax
char v2[9]; // [rsp+0h] [rbp-18h] BYREF
__int16 v3; // [rsp+9h] [rbp-Fh]
__int16 v4; // [rsp+Bh] [rbp-Dh]
__int16 v5; // [rsp+Dh] [rbp-Bh]

v0 = boot_basic;
if ( (unsigned int)(boot_basic - 1) > 2 )
v0 = 0;
if ( !boot_clock_4mhz )
v0 += 4;
if ( key_scan[10] >= 0 )
v0 += 8;
if ( (key_scan[8] & 0x20) == 0 )
v0 += 16;
result = (unsigned int)(v0 + 32);
if ( numlock_emu )
v0 += 32;
if ( (_DWORD)stat_var != v0 )
{
LODWORD(stat_var) = v0;
strcpy(v2, (&mode_str_0)[v0 & 7]);
if ( (v0 & 8) != 0 )
v3 = -2315;
if ( (v0 & 0x10) != 0 )
v4 = romaji_input_mode == 0 ? -1801 : -1287;
if ( (v0 & 0x20) != 0 )
v5 = -773;
result = status_puts(0, v2);
LODWORD(stat_draw) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
__int64 result; // rax
char v2[9]; // [rsp+0h] [rbp-18h] BYREF
__int16 v3; // [rsp+9h] [rbp-Fh]
__int16 v4; // [rsp+Bh] [rbp-Dh]
__int16 v5; // [rsp+Dh] [rbp-Bh]

v0 = boot_basic;
if ( (unsigned int)(boot_basic - 1) > 2 )
v0 = 0;
if ( !boot_clock_4mhz )
v0 += 4;
if ( key_scan[10] >= 0 )
v0 += 8;
if ( (key_scan[8] & 0x20) == 0 )
v0 += 16;
result = (unsigned int)(v0 + 32);
if ( numlock_emu )
v0 += 32;
if ( (_DWORD)stat_var != v0 )
{
LODWORD(stat_var) = v0;
strcpy(v2, (&mode_str_0)[v0 & 7]);
if ( (v0 & 8) != 0 )
v3 = -2315;
if ( (v0 & 0x10) != 0 )
v4 = romaji_input_mode == 0 ? -1801 : -1287;
if ( (v0 & 0x20) != 0 )
v5 = -773;
result = func0(0, v2);
LODWORD(stat_draw) = 1;
}
return result;
}

original_code:
static __inline__ void status_mode( void )
{
  int mode = 0;
  byte buf[16];
  static const char *mode_str[] = {
    "N   4MHz       ", "V1S 4MHz       ", "V1H 4MHz       ", "V2  4MHz       ",
    "N   8MHz       ", "V1S 8MHz       ", "V1H 8MHz       ", "V2  8MHz       ",
  };
  switch( boot_basic ){
  case BASIC_N: mode = 0; break;
  case BASIC_V1S: mode = 1; break;
  case BASIC_V1H: mode = 2; break;
  case BASIC_V2: mode = 3; break;
  }
  if( boot_clock_4mhz == (0) ) mode += 4;
  if( (key_scan[0x0a] & 0x80) == 0 ) mode += 8;
  if( (key_scan[0x08] & 0x20) == 0 ) mode += 16;
  if( numlock_emu ) mode += 32;
  if( stat_var[0] != mode ){
    stat_var[0] = mode;
    strcpy( (char *)buf, mode_str[ mode & 0x7 ] );
    if( mode & 8 ){
      buf[ 9] = FNT_CAP_1;
      buf[10] = FNT_CAP_2;
    }
    if( mode & 16 ){
      if( romaji_input_mode ){
 buf[11] = FNT_RMJ_1;
 buf[12] = FNT_RMJ_2;
      }else{
 buf[11] = FNT_KAN_1;
 buf[12] = FNT_KAN_2;
      }
    }
    if( mode & 32 ){
 buf[13] = FNT_NUM_1;
 buf[14] = FNT_NUM_2;
    }
    status_puts( 0, (const unsigned char *)buf );
    stat_draw[ 0 ] = (1);
  }
}

canonical_original_code:
static __inline__ void status_mode()
{
  int mode = 0;
  unsigned char buf[16];
  static char *mode_str[] = {
    "N   4MHz       ", "V1S 4MHz       ", "V1H 4MHz       ", "V2  4MHz       ",
    "N   8MHz       ", "V1S 8MHz       ", "V1H 8MHz       ", "V2  8MHz       ",
  };
  switch( boot_basic ){
  case BASIC_N: mode = 0; break;
  case BASIC_V1S: mode = 1; break;
  case BASIC_V1H: mode = 2; break;
  case BASIC_V2: mode = 3; break;
  }
  if( boot_clock_4mhz == (0) ) mode += 4;
  if( (key_scan[0x0a] & 0x80) == 0 ) mode += 8;
  if( (key_scan[0x08] & 0x20) == 0 ) mode += 16;
  if( numlock_emu ) mode += 32;
  if( stat_var[0] != mode ){
    stat_var[0] = mode;
    strcpy( (char *)buf, mode_str[ mode & 0x7 ] );
    if( mode & 8 ){
      buf[ 9] = FNT_CAP_1;
      buf[10] = FNT_CAP_2;
    }
    if( mode & 16 ){
      if( romaji_input_mode ){
 buf[11] = FNT_RMJ_1;
 buf[12] = FNT_RMJ_2;
      }else{
 buf[11] = FNT_KAN_1;
 buf[12] = FNT_KAN_2;
      }
    }
    if( mode & 32 ){
 buf[13] = FNT_NUM_1;
 buf[14] = FNT_NUM_2;
    }
    status_puts( 0, (unsigned char *)buf );
    stat_draw[ 0 ] = (1);
  }
}

variable_types: mode int

variable_types:
buf
unsigned char [16]


decompiled_code:
__int64 status_fdd()
{
__int64 v0; // rbx
__int64 result; // rax
int *v2; // rax
_BYTE *v3; // rdx
int v4; // [rsp+0h] [rbp-18h] BYREF
char v5[20]; // [rsp+4h] [rbp-14h] BYREF

v0 = (unsigned int)get_drive_ready(0LL) == 0;
if ( !(unsigned int)get_drive_ready(1LL) )
LODWORD(v0) = v0 | 2;
result = tape_writing();
if ( (_DWORD)result )
{
LODWORD(v0) = v0 | 0xC;
if ( (_DWORD)v0 == dword_6D8 )
return result;
dword_6D8 = v0;
v2 = (int *)v5;
v4 = 552924146;
LABEL_9:
if ( (v0 & 2) != 0 )
{
*((_BYTE *)v2 + 2) = -27;
v3 = (char *)v2 + 6;
*(_WORD *)v2 = -6941;
if ( (v0 & 1) != 0 )
{
LABEL_11:
*((_BYTE *)v2 + 5) = -21;
*(_WORD *)((char *)v2 + 3) = -5399;
LABEL_12:
*v3 = 0;
result = status_puts(2, (const char *)&v4);
dword_4F48 = 1;
return result;
}
}
else
{
*((_BYTE *)v2 + 2) = -30;
v3 = (char *)v2 + 6;
*(_WORD *)v2 = -7712;
if ( (v0 & 1) != 0 )
goto LABEL_11;
}
*((_BYTE *)v2 + 5) = -24;
*(_WORD *)((char *)v2 + 3) = -6170;
goto LABEL_12;
}
result = tape_reading();
if ( (_DWORD)result )
{
LODWORD(v0) = v0 | 8;
if ( (_DWORD)v0 != dword_6D8 )
{
dword_6D8 = v0;
v2 = (int *)v5;
v4 = 552726767;
goto LABEL_9;
}
}
else
{
result = tape_exist();
if ( (_DWORD)result )
{
LODWORD(v0) = v0 | 4;
if ( (_DWORD)v0 != dword_6D8 )
{
dword_6D8 = v0;
v2 = (int *)v5;
v4 = 552529388;
goto LABEL_9;
}
}
else if ( (_DWORD)v0 != dword_6D8 )
{
dword_6D8 = v0;
v2 = &v4;
goto LABEL_9;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx
__int64 result; // rax
int *v2; // rax
_BYTE *v3; // rdx
int v4; // [rsp+0h] [rbp-18h] BYREF
char v5[20]; // [rsp+4h] [rbp-14h] BYREF

v0 = (unsigned int)get_drive_ready(0LL) == 0;
if ( !(unsigned int)get_drive_ready(1LL) )
LODWORD(v0) = v0 | 2;
result = tape_writing();
if ( (_DWORD)result )
{
LODWORD(v0) = v0 | 0xC;
if ( (_DWORD)v0 == dword_6D8 )
return result;
dword_6D8 = v0;
v2 = (int *)v5;
v4 = 552924146;
LABEL_9:
if ( (v0 & 2) != 0 )
{
*((_BYTE *)v2 + 2) = -27;
v3 = (char *)v2 + 6;
*(_WORD *)v2 = -6941;
if ( (v0 & 1) != 0 )
{
LABEL_11:
*((_BYTE *)v2 + 5) = -21;
*(_WORD *)((char *)v2 + 3) = -5399;
LABEL_12:
*v3 = 0;
result = func0(2, (const char *)&v4);
dword_4F48 = 1;
return result;
}
}
else
{
*((_BYTE *)v2 + 2) = -30;
v3 = (char *)v2 + 6;
*(_WORD *)v2 = -7712;
if ( (v0 & 1) != 0 )
goto LABEL_11;
}
*((_BYTE *)v2 + 5) = -24;
*(_WORD *)((char *)v2 + 3) = -6170;
goto LABEL_12;
}
result = tape_reading();
if ( (_DWORD)result )
{
LODWORD(v0) = v0 | 8;
if ( (_DWORD)v0 != dword_6D8 )
{
dword_6D8 = v0;
v2 = (int *)v5;
v4 = 552726767;
goto LABEL_9;
}
}
else
{
result = tape_exist();
if ( (_DWORD)result )
{
LODWORD(v0) = v0 | 4;
if ( (_DWORD)v0 != dword_6D8 )
{
dword_6D8 = v0;
v2 = (int *)v5;
v4 = 552529388;
goto LABEL_9;
}
}
else if ( (_DWORD)v0 != dword_6D8 )
{
dword_6D8 = v0;
v2 = &v4;
goto LABEL_9;
}
}
return result;
}

variable_types: fdd int


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

result = 0x1000000000LL;
status_info[0] = (__int64)&pixmap;
status_info[1] = 0x1000000000LL;
status_info[2] = (__int64)&unk_1F20;
status_info[3] = 0x1000000000LL;
stat_draw = 0x100000001LL;
dword_4F48 = 1;
status_info[4] = (__int64)&unk_3720;
status_info[5] = 0x1000000000LL;
stat_msg_exist = 0LL;
dword_4F38 = 0;
stat_var = -1LL;
dword_6D8 = -1;
return result;
}

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

result = 0x1000000000LL;
status_info[0] = (__int64)&pixmap;
status_info[1] = 0x1000000000LL;
status_info[2] = (__int64)&unk_1F20;
status_info[3] = 0x1000000000LL;
stat_draw = 0x100000001LL;
dword_4F48 = 1;
status_info[4] = (__int64)&unk_3720;
status_info[5] = 0x1000000000LL;
stat_msg_exist = 0LL;
dword_4F38 = 0;
stat_var = -1LL;
dword_6D8 = -1;
return result;
}

original_code:
void status_init( void )
{
  int i;
  for( i=0; i<3; i++ ){
    stat_draw[i] = (1);
    stat_msg_exist[i] = (0);
    stat_var[i] = -1;
    status_info[i].pixmap = &pixmap[i][0];
    status_info[i].w = 0;
    status_info[i].h = (16);
  }
}

canonical_original_code:
void status_init()
{
  int i;
  for( i=0; i<3; i++ ){
    stat_draw[i] = (1);
    stat_msg_exist[i] = (0);
    stat_var[i] = -1;
    status_info[i].pixmap = &pixmap[i][0];
    status_info[i].w = 0;
    status_info[i].h = (16);
  }
}


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

if ( a1 )
{
result = 0x100000001LL;
dword_4F48 = 1;
stat_draw = 0x100000001LL;
}
else
{
stat_var = -1LL;
dword_6D8 = -1;
}
return result;
}

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

if ( a1 )
{
result = 0x100000001LL;
dword_4F48 = 1;
stat_draw = 0x100000001LL;
}
else
{
stat_var = -1LL;
dword_6D8 = -1;
}
return result;
}

original_code:
void status_reset( int show )
{
  if( show ){
    stat_draw[0] = stat_draw[1] = stat_draw[2] = (1);
  }else{
    stat_var[0] = stat_var[1] = stat_var[2] = -1;
  }
}

canonical_original_code:
void status_reset(int show)
{
  if( show ){
    stat_draw[0] = stat_draw[1] = stat_draw[2] = (1);
  }else{
    stat_var[0] = stat_var[1] = stat_var[2] = -1;
  }
}

variable_types: show int


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

result = status_puts(a1, a3);
if ( a2 < 0 )
{
*((_DWORD *)&stat_msg_exist + a1) = 0;
*((_DWORD *)&stat_var + a1) = -1;
}
else
{
*((_DWORD *)&stat_msg_exist + a1) = 1;
}
stat_msg_timer[a1] = a2;
*((_DWORD *)&stat_draw + a1) = 1;
return result;
}

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

result = func0(a1, a3);
if ( a2 < 0 )
{
*((_DWORD *)&stat_msg_exist + a1) = 0;
*((_DWORD *)&stat_var + a1) = -1;
}
else
{
*((_DWORD *)&stat_msg_exist + a1) = 1;
}
stat_msg_timer[a1] = a2;
*((_DWORD *)&stat_draw + a1) = 1;
return result;
}

original_code:
void status_message( int kind, int frames, const char *msg )
{
  status_puts( kind, (const unsigned char *)msg );
  if( frames >= 0 ){ stat_msg_exist[ kind ] = (1); }
  else { stat_msg_exist[ kind ] = (0); stat_var[ kind ] = -1; }
  stat_msg_timer[ kind ] = frames;
  stat_draw[ kind ] = (1);
}

canonical_original_code:
void status_message(int kind, int frames, char *msg)
{
  status_puts( kind, (unsigned char *)msg );
  if( frames >= 0 ){ stat_msg_exist[ kind ] = (1); }
  else { stat_msg_exist[ kind ] = (0); stat_var[ kind ] = -1; }
  stat_msg_timer[ kind ] = frames;
  stat_draw[ kind ] = (1);
}

variable_types: kind int

variable_types: frames int

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall status_update(int a1)
{
int v1; // ebp
__int64 v2; // rbx
int v3; // eax
int v4; // eax
int v5; // eax
__int64 result; // rax
__int64 v7; // rcx

v1 = 1;
v2 = 0LL;
if ( (_DWORD)stat_msg_exist )
goto LABEL_6;
LABEL_2:
while ( !v2 )
{
status_mode();
LABEL_5:
while ( 1 )
{
++v2;
++v1;
if ( !*((_DWORD *)&stat_msg_exist + v2) )
break;
LABEL_6:
v3 = stat_msg_timer[v2];
if ( !v3 )
goto LABEL_4;
v4 = v3 - 1;
stat_msg_timer[v2] = v4;
if ( v4 )
goto LABEL_4;
status_message(v2, -1, 0LL);
v5 = *((_DWORD *)&stat_msg_exist + v2);
*((_DWORD *)&stat_var + v2) = -1;
if ( !v5 )
goto LABEL_2;
if ( v1 == 3 )
goto LABEL_10;
}
}
if ( (_DWORD)v2 == 2 )
{
status_fdd();
}
else
{
LABEL_4:
if ( v1 != 3 )
goto LABEL_5;
}
LABEL_10:
result = now_status;
if ( now_status )
{
v7 = 0LL;
result = 0LL;
do
{
if ( *((_DWORD *)&stat_draw + v7) | a1 )
{
*((_DWORD *)&stat_draw + v7) = 0;
result = (1 << v7) | (unsigned int)result;
}
++v7;
}
while ( v7 != 3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // ebp
__int64 v2; // rbx
int v3; // eax
int v4; // eax
int v5; // eax
__int64 result; // rax
__int64 v7; // rcx

v1 = 1;
v2 = 0LL;
if ( (_DWORD)stat_msg_exist )
goto LABEL_6;
LABEL_2:
while ( !v2 )
{
func1();
LABEL_5:
while ( 1 )
{
++v2;
++v1;
if ( !*((_DWORD *)&stat_msg_exist + v2) )
break;
LABEL_6:
v3 = stat_msg_timer[v2];
if ( !v3 )
goto LABEL_4;
v4 = v3 - 1;
stat_msg_timer[v2] = v4;
if ( v4 )
goto LABEL_4;
func5(v2, -1, 0LL);
v5 = *((_DWORD *)&stat_msg_exist + v2);
*((_DWORD *)&stat_var + v2) = -1;
if ( !v5 )
goto LABEL_2;
if ( v1 == 3 )
goto LABEL_10;
}
}
if ( (_DWORD)v2 == 2 )
{
func2();
}
else
{
LABEL_4:
if ( v1 != 3 )
goto LABEL_5;
}
LABEL_10:
result = now_status;
if ( now_status )
{
v7 = 0LL;
result = 0LL;
do
{
if ( *((_DWORD *)&stat_draw + v7) | a1 )
{
*((_DWORD *)&stat_draw + v7) = 0;
result = (1 << v7) | (unsigned int)result;
}
++v7;
}
while ( v7 != 3 );
}
return result;
}

original_code:
int status_update( int force )
{
  int i, ret = 0;
  for( i=0; i<3; i++ ){
    if( stat_msg_exist[i] ){
      if( stat_msg_timer[i] ){
 if( -- stat_msg_timer[i]==0 ){
   status_message( i, -1, ((void *)0) );
   stat_var[i] = -1;
 }
      }
    }
    if( stat_msg_exist[i] == (0) ){
      if ( i==0 ){ status_mode(); }
      else if( i==2 ){ status_fdd(); }
    }
  }
  if( now_status ){
    for( i=0; i<3; i++ ){
      if( stat_draw[i] || force ){
 stat_draw[i] = (0);
 ret |= 1<<i;
      }
    }
  }
  return ret;
}

canonical_original_code:
int status_update(int force)
{
  int i; int ret = 0;
  for( i=0; i<3; i++ ){
    if( stat_msg_exist[i] ){
      if( stat_msg_timer[i] ){
 if( -- stat_msg_timer[i]==0 ){
   status_message( i, -1, ((void *)0) );
   stat_var[i] = -1;
 }
      }
    }
    if( stat_msg_exist[i] == (0) ){
      if ( i==0 ){ status_mode(); }
      else if( i==2 ){ status_fdd(); }
    }
  }
  if( now_status ){
    for( i=0; i<3; i++ ){
      if( stat_draw[i] || force ){
 stat_draw[i] = (0);
 ret |= 1<<i;
      }
    }
  }
  return ret;
}

variable_types: force int

variable_types: ret int


decompiled_code:
const char *indicate_bootup_logo()
{
const char *result; // rax
char v1[40]; // [rsp+0h] [rbp-28h] BYREF

result = (const char *)get_keysym_menu();
if ( result )
{
sprintf(v1, "<%.8s> key to MENU", result);
status_message(0, 240, "QUASI88 0.6.3");
result = (const char *)status_message(1, 0, v1);
}
return result;
}

canonical_decompiled_code:
const char *func7()
{
const char *result; // rax
char v1[40]; // [rsp+0h] [rbp-28h] BYREF

result = (const char *)get_keysym_menu();
if ( result )
{
sprintf(v1, "<%.8s> key to MENU", result);
func5(0, 240, "QUASI88 0.6.3");
result = (const char *)func5(1, 0, v1);
}
return result;
}

original_code:
void indicate_bootup_logo( void )
{
  char menu_msg[24];
  const char *keysym = get_keysym_menu();
  if( keysym ){
    sprintf( menu_msg, "<%.8s> key to MENU", keysym );
    status_message( 0, 60*4, "QUASI88" " " "0.6.3" );
    status_message( 1, 0, menu_msg );
  }
}

canonical_original_code:
void indicate_bootup_logo()
{
  char menu_msg[24];
  char *keysym = get_keysym_menu();
  if( keysym ){
    sprintf( menu_msg, "<%.8s> key to MENU", keysym );
    status_message( 0, 60*4, "QUASI88" " " "0.6.3" );
    status_message( 1, 0, menu_msg );
  }
}

variable_types:
keysym
char *


decompiled_code:
__int64 indicate_stateload_logo()
{
status_message(0, 240, "QUASI88 0.6.3");
return status_message(1, 240, "State Load Successful !");
}

canonical_decompiled_code:
__int64 func8()
{
func5(0, 240, "QUASI88 0.6.3");
return func5(1, 240, "State Load Successful !");
}

original_code:
void indicate_stateload_logo( void )
{
  status_message( 0, 60*4, "QUASI88" " " "0.6.3" );
  status_message( 1, 60*4, "State Load Successful !" );
}

canonical_original_code:
void indicate_stateload_logo()
{
  status_message( 0, 60*4, "QUASI88" " " "0.6.3" );
  status_message( 1, 60*4, "State Load Successful !" );
}


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

intr_sound_enable = 0;
sound_ENABLE_A = 0;
memset(&sound_reg, 0, 0x100uLL);
*(&sound_reg + 41) = 3;
memset(&sound2_reg, 0, 0x100uLL);
result = 0xFFFFFFFFLL;
sound_ENABLE_B = 0;
*((_WORD *)&sound_reg + 7) = -1;
sound_LOAD_A = 0;
sound_LOAD_B = 0;
sound_FLAG_A = 0;
sound_FLAG_B = 0;
sound_TIMER_A = 0;
sound_TIMER_B = 0;
sound_prescaler = 6;
sound_prescaler_sel = 2;
sound2_MSK_TA = 0;
sound2_MSK_TB = 0;
sound2_EN_TA = 1;
sound2_EN_TB = 2;
sound2_EN_EOS = 0;
sound2_EN_BRDY = 0;
sound2_EN_ZERO = 0;
sound2_FLAG_EOS = 0;
sound2_FLAG_BRDY = 0;
sound2_FLAG_ZERO = 0;
sound2_FLAG_PCMBSY = 0;
sound2_read_dummy = 2;
return result;
}

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

intr_sound_enable = 0;
sound_ENABLE_A = 0;
memset(&sound_reg, 0, 0x100uLL);
*(&sound_reg + 41) = 3;
memset(&sound2_reg, 0, 0x100uLL);
result = 0xFFFFFFFFLL;
sound_ENABLE_B = 0;
*((_WORD *)&sound_reg + 7) = -1;
sound_LOAD_A = 0;
sound_LOAD_B = 0;
sound_FLAG_A = 0;
sound_FLAG_B = 0;
sound_TIMER_A = 0;
sound_TIMER_B = 0;
sound_prescaler = 6;
sound_prescaler_sel = 2;
sound2_MSK_TA = 0;
sound2_MSK_TB = 0;
sound2_EN_TA = 1;
sound2_EN_TB = 2;
sound2_EN_EOS = 0;
sound2_EN_BRDY = 0;
sound2_EN_ZERO = 0;
sound2_FLAG_EOS = 0;
sound2_FLAG_BRDY = 0;
sound2_FLAG_ZERO = 0;
sound2_FLAG_PCMBSY = 0;
sound2_read_dummy = 2;
return result;
}

original_code:
void sound_init( void )
{
  int i;
  for( i=0; i<0x100; i++ ) sound_reg [ i ] = 0x00;
  for( i=0; i<0x100; i++ ) sound2_reg[ i ] = 0x00;
  sound_reg[0x0e]=0xff;
  sound_reg[0x0f]=0xff;
  intr_sound_enable = 0x00;
  sound_reg[0x29]=0x03;
  sound_ENABLE_A = (0);
  sound_ENABLE_B = (0);
  sound_LOAD_A = (0);
  sound_LOAD_B = (0);
  sound_FLAG_A = 0;
  sound_FLAG_B = 0;
  sound_TIMER_A = 0;
  sound_TIMER_B = 0;
  sound_prescaler = 6;
  sound_prescaler_sel = 2;
  sound2_MSK_TA = 0x00;
  sound2_MSK_TB = 0x00;
  sound2_EN_TA = 0x01;
  sound2_EN_TB = 0x02;
  sound2_EN_EOS = (0);
  sound2_EN_BRDY = (0);
  sound2_EN_ZERO = (0);
  sound2_FLAG_EOS = 0;
  sound2_FLAG_BRDY = 0;
  sound2_FLAG_ZERO = 0;
  sound2_FLAG_PCMBSY = 0;
  sound2_read_dummy = 2;
}

canonical_original_code:
void sound_init()
{
  int i;
  for( i=0; i<0x100; i++ ) sound_reg [ i ] = 0x00;
  for( i=0; i<0x100; i++ ) sound2_reg[ i ] = 0x00;
  sound_reg[0x0e]=0xff;
  sound_reg[0x0f]=0xff;
  intr_sound_enable = 0x00;
  sound_reg[0x29]=0x03;
  sound_ENABLE_A = (0);
  sound_ENABLE_B = (0);
  sound_LOAD_A = (0);
  sound_LOAD_B = (0);
  sound_FLAG_A = 0;
  sound_FLAG_B = 0;
  sound_TIMER_A = 0;
  sound_TIMER_B = 0;
  sound_prescaler = 6;
  sound_prescaler_sel = 2;
  sound2_MSK_TA = 0x00;
  sound2_MSK_TB = 0x00;
  sound2_EN_TA = 0x01;
  sound2_EN_TB = 0x02;
  sound2_EN_EOS = (0);
  sound2_EN_BRDY = (0);
  sound2_EN_ZERO = (0);
  sound2_FLAG_EOS = 0;
  sound2_FLAG_BRDY = 0;
  sound2_FLAG_ZERO = 0;
  sound2_FLAG_PCMBSY = 0;
  sound2_read_dummy = 2;
}

variable_types: i int


decompiled_code:
__int64 __fastcall sound_out_reg(unsigned __int8 a1)
{
sound_reg_select = a1;
return xmame_sound_out_reg();
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
sound_reg_select = a1;
return xmame_sound_out_reg();
}

original_code:
void sound_out_reg( byte data )
{
  sound_reg_select = data & 0xff;
  xmame_sound_out_reg( data );
}

canonical_original_code:
void sound_out_reg(unsigned char data)
{
  sound_reg_select = data & 0xff;
  xmame_sound_out_reg( data );
}

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall sound_out_data(unsigned __int8 a1)
{
__int64 result; // rax
int v2; // eax

sound_reg[sound_reg_select] = a1;
xmame_sound_out_data(a1);
result = (unsigned int)(sound_reg_select - 36);
switch ( sound_reg_select )
{
case '$':
case '%':
sound_TIMER_A = sound_reg[37] & 3 | (4 * (unsigned __int8)sound_reg[36]);
result = interval_work_set_TIMER_A();
break;
case '&':
sound_TIMER_B = a1;
result = interval_work_set_TIMER_B();
break;
case '\'':
result = change_sound_flags(39LL);
break;
case ')':
if ( sound_board == 1 )
result = change_sound_flags(41LL);
break;
case '-':
if ( verbose_snd )
printf("SOUND out %X\n", 45LL);
v2 = sound_prescaler_sel | 2;
goto LABEL_13;
case '.':
if ( verbose_snd )
printf("SOUND out %X\n", 46LL);
v2 = sound_prescaler_sel | 1;
LABEL_13:
sound_prescaler_sel = v2;
result = change_sound_prescaler((unsigned int)pres_3[v2]);
break;
case '/':
if ( verbose_snd )
printf("SOUND out %X\n", 47LL);
sound_prescaler_sel = 0;
result = change_sound_prescaler(2LL);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
__int64 result; // rax
int v2; // eax

sound_reg[sound_reg_select] = a1;
xmame_sound_out_data(a1);
result = (unsigned int)(sound_reg_select - 36);
switch ( sound_reg_select )
{
case '$':
case '%':
sound_TIMER_A = sound_reg[37] & 3 | (4 * (unsigned __int8)sound_reg[36]);
result = interval_work_set_TIMER_A();
break;
case '&':
sound_TIMER_B = a1;
result = interval_work_set_TIMER_B();
break;
case '\'':
result = change_sound_flags(39LL);
break;
case ')':
if ( sound_board == 1 )
result = change_sound_flags(41LL);
break;
case '-':
if ( verbose_snd )
printf("SOUND out %X\n", 45LL);
v2 = sound_prescaler_sel | 2;
goto LABEL_13;
case '.':
if ( verbose_snd )
printf("SOUND out %X\n", 46LL);
v2 = sound_prescaler_sel | 1;
LABEL_13:
sound_prescaler_sel = v2;
result = change_sound_prescaler((unsigned int)pres_3[v2]);
break;
case '/':
if ( verbose_snd )
printf("SOUND out %X\n", 47LL);
sound_prescaler_sel = 0;
result = change_sound_prescaler(2LL);
break;
default:
return result;
}
return result;
}

original_code:
void sound_out_data( byte data )
{
  static const int pres[4] = { 2, 2, 6, 3 };
  sound_reg[ sound_reg_select ] = data;
  xmame_sound_out_data( data );
  switch( sound_reg_select ){
  case 0x24:
  case 0x25:
    sound_TIMER_A = ((int)sound_reg[ 0x24 ]<<2) | (sound_reg[ 0x25 ] & 0x03);
    interval_work_set_TIMER_A();
    break;
  case 0x26:
    sound_TIMER_B = (int)data;
    interval_work_set_TIMER_B();
    break;
  case 0x27:
    change_sound_flags( 0x27 );
    break;
  case 0x29:
    if( sound_board==SOUND_II ){
      change_sound_flags( 0x29 );
    }
    break;
  case 0x2d:
    if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
    sound_prescaler_sel |= 2;
    change_sound_prescaler( pres[sound_prescaler_sel] );
    break;
  case 0x2e:
    if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
    sound_prescaler_sel |= 1;
    change_sound_prescaler( pres[sound_prescaler_sel] );
    break;
  case 0x2f:
    if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
    sound_prescaler_sel = 0;
    change_sound_prescaler( pres[sound_prescaler_sel] );
    break;
  }
}

canonical_original_code:
void sound_out_data(unsigned char data)
{
  static int pres[4] = { 2, 2, 6, 3 };
  sound_reg[ sound_reg_select ] = data;
  xmame_sound_out_data( data );
  switch( sound_reg_select ){
  case 0x24:
  case 0x25:
    sound_TIMER_A = ((int)sound_reg[ 0x24 ]<<2) | (sound_reg[ 0x25 ] & 0x03);
    interval_work_set_TIMER_A();
    break;
  case 0x26:
    sound_TIMER_B = (int)data;
    interval_work_set_TIMER_B();
    break;
  case 0x27:
    change_sound_flags( 0x27 );
    break;
  case 0x29:
    if( sound_board==SOUND_II ){
      change_sound_flags( 0x29 );
    }
    break;
  case 0x2d:
    if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
    sound_prescaler_sel |= 2;
    change_sound_prescaler( pres[sound_prescaler_sel] );
    break;
  case 0x2e:
    if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
    sound_prescaler_sel |= 1;
    change_sound_prescaler( pres[sound_prescaler_sel] );
    break;
  case 0x2f:
    if( verbose_snd ) printf("SOUND out %X\n",sound_reg_select);
    sound_prescaler_sel = 0;
    change_sound_prescaler( pres[sound_prescaler_sel] );
    break;
  }
}

variable_types:
pres
int [4]


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

xmame_sound_in_status();
result = (unsigned int)(2 * sound_FLAG_B);
LOBYTE(result) = sound_FLAG_A | (2 * sound_FLAG_B);
return result;
}

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

xmame_sound_in_status();
result = (unsigned int)(2 * sound_FLAG_B);
LOBYTE(result) = sound_FLAG_A | (2 * sound_FLAG_B);
return result;
}

original_code:
byte sound_in_status( void )
{
  xmame_sound_in_status();
  return ( sound_FLAG_B << 1 ) | sound_FLAG_A;
}

canonical_original_code:
unsigned char sound_in_status()
{
  xmame_sound_in_status();
  return ( sound_FLAG_B << 1 ) | sound_FLAG_A;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall sound_in_data(int a1)
{
unsigned int v1; // er8

xmame_sound_in_data();
if ( sound_reg_select <= 15 )
return (unsigned __int8)sound_reg[sound_reg_select];
v1 = 0;
if ( sound_reg_select == 255 )
LOBYTE(v1) = (a1 | sound_port & 2) != 0;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int v1; // er8

xmame_sound_in_data();
if ( sound_reg_select <= 15 )
return (unsigned __int8)sound_reg[sound_reg_select];
v1 = 0;
if ( sound_reg_select == 255 )
LOBYTE(v1) = (a1 | sound_port & 2) != 0;
return v1;
}

original_code:
byte sound_in_data( int always_sound_II )
{
  xmame_sound_in_data();
  if ( sound_reg_select < 0x10 ){
    return sound_reg[ sound_reg_select ];
  }else if( sound_reg_select == 0xff ){
    if( always_sound_II ) return 0x01;
    else{
      if( sound_port & (0x02) ) return 0x01;
      else return 0x00;
    }
  }else{
    return 0x00;
  }
}

canonical_original_code:
unsigned char sound_in_data(int always_sound_II)
{
  xmame_sound_in_data();
  if ( sound_reg_select < 0x10 ){
    return sound_reg[ sound_reg_select ];
  }else if( sound_reg_select == 0xff ){
    if( always_sound_II ) return 0x01;
    else{
      if( sound_port & (0x02) ) return 0x01;
      else return 0x00;
    }
  }else{
    return 0x00;
  }
}


decompiled_code:
__int64 __fastcall sound2_out_reg(unsigned __int8 a1)
{
sound2_reg_select = a1;
return xmame_sound2_out_reg();
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1)
{
sound2_reg_select = a1;
return xmame_sound2_out_reg();
}

original_code:
void sound2_out_reg( byte data )
{
  sound2_reg_select = data & 0xff;
  xmame_sound2_out_reg( data );
}

canonical_original_code:
void sound2_out_reg(unsigned char data)
{
  sound2_reg_select = data & 0xff;
  xmame_sound2_out_reg( data );
}


decompiled_code:
__int64 __fastcall sound2_out_data(char a1)
{
__int64 result; // rax
char v2; // dl
char v3; // si
int v4; // esi
int v5; // eax

sound2_reg[sound2_reg_select] = a1;
xmame_sound2_out_data((unsigned __int8)a1);
result = (unsigned int)sound2_reg_select;
switch ( sound2_reg_select )
{
case 0:
v2 = a1 & 0x20;
v3 = a1 & 0x40;
sound2_repeat = a1 & 0x10;
sound2_rec = a1 & 0x40;
result = a1 & 0x20;
sound2_mem = a1 & 0x20;
if ( !sound2_FLAG_PCMBSY )
{
if ( !v2 )
{
LABEL_16:
if ( (a1 & 1) == 0 )
{
LABEL_19:
sound2_stat = 0;
return result;
}
goto LABEL_17;
}
if ( a1 >= 0 )
{
if ( v3 )
{
sound2_delay |= 8u;
sound2_stat = 3;
}
else
{
sound2_stat = 4;
sound2_read_dummy = 2;
}
sound2_data_addr = sound2_start_addr;
goto LABEL_30;
}
if ( v3 )
{
sound2_stat = 1;
sound2_intr_base = sound2_record_intr_base;
}
else
{
sound2_stat = 2;
sound2_intr_base = sound2_replay_intr_base;
}
interval_work_set_BDRY();
if ( sound2_stop_addr == sound2_limit_addr )
{
if ( sound2_stop_addr > sound2_start_addr )
{
v5 = sound2_stop_addr - sound2_start_addr;
goto LABEL_43;
}
v5 = 0x3FFFF - sound2_start_addr;
}
else
{
if ( sound2_limit_addr > sound2_start_addr && sound2_stop_addr > sound2_start_addr )
{
if ( sound2_stop_addr < sound2_limit_addr )
goto LABEL_42;
LABEL_48:
sound2_notice_EOS = 0;
LABEL_44:
result = (unsigned int)sound2_mem;
sound2_FLAG_PCMBSY = 1;
if ( (a1 & 1) == 0 )
{
LABEL_18:
if ( (_DWORD)result )
return result;
goto LABEL_19;
}
LABEL_17:
sound2_repeat = 0;
sound2_FLAG_PCMBSY = 0;
goto LABEL_18;
}
v4 = sound2_start_addr;
if ( sound2_limit_addr <= sound2_start_addr )
v4 = sound2_limit_addr;
if ( sound2_stop_addr >= v4 )
{
if ( sound2_stop_addr > sound2_start_addr )
{
LABEL_42:
v5 = sound2_stop_addr - sound2_start_addr;
LABEL_43:
sound2_notice_EOS = 1;
interval_work_set_EOS((unsigned int)(v5 + 1));
goto LABEL_44;
}
goto LABEL_46;
}
if ( sound2_limit_addr <= sound2_start_addr )
{
LABEL_46:
v5 = 0x3FFFF - sound2_start_addr;
goto LABEL_47;
}
v5 = sound2_limit_addr - sound2_start_addr + sound2_stop_addr;
}
LABEL_47:
if ( v5 )
goto LABEL_43;
goto LABEL_48;
}
if ( !v2 )
{
sound2_FLAG_PCMBSY = 0;
goto LABEL_16;
}
LABEL_30:
if ( (a1 & 1) != 0 )
goto LABEL_17;
return result;
case 1:
result = (a1 & 2) == 0 ? 2 : 5;
sound2_mem_size = (a1 & 2) == 0 ? 2 : 5;
return result;
case 2:
case 3:
result = (*(unsigned __int16 *)&sound2_reg[2] << sound2_mem_size) & 0x3FFFF;
sound2_start_addr = (*(unsigned __int16 *)&sound2_reg[2] << sound2_mem_size) & 0x3FFFF;
return result;
case 4:
case 5:
result = (((*(unsigned __int16 *)&sound2_reg[4] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
sound2_stop_addr = (((*(unsigned __int16 *)&sound2_reg[4] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
return result;
case 6:
case 7:
result = (unsigned __int8)sound2_reg[6] | ((unsigned __int8)sound2_reg[7] << 8) & 0x700u;
if ( !((unsigned __int8)sound2_reg[6] | ((unsigned __int8)sound2_reg[7] << 8) & 0x700) )
result = 2048LL;
sound2_record_intr_base = result;
return result;
case 8:
if ( sound2_stat == 3 )
{
if ( sound2_stop_addr == sound2_data_addr || sound2_data_addr == 0x3FFFF )
sound2_delay |= 4u;
*(_BYTE *)(sound2_adpcm + sound2_data_addr) = a1;
sound2_delay |= 8u;
result = (sound2_data_addr + 1) & 0x3FFFF;
sound2_data_addr = (sound2_data_addr + 1) & 0x3FFFF;
}
return result;
case 9:
case 10:
result = 72LL;
if ( *(_WORD *)&sound2_reg[9] )
result = 4718592 / *(unsigned __int16 *)&sound2_reg[9];
sound2_replay_intr_base = result;
return result;
case 12:
case 13:
result = (((*(unsigned __int16 *)&sound2_reg[12] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
sound2_limit_addr = (((*(unsigned __int16 *)&sound2_reg[12] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
return result;
case 16:
return change_sound_flags(16LL);
default:
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
__int64 result; // rax
char v2; // dl
char v3; // si
int v4; // esi
int v5; // eax

sound2_reg[sound2_reg_select] = a1;
xmame_sound2_out_data((unsigned __int8)a1);
result = (unsigned int)sound2_reg_select;
switch ( sound2_reg_select )
{
case 0:
v2 = a1 & 0x20;
v3 = a1 & 0x40;
sound2_repeat = a1 & 0x10;
sound2_rec = a1 & 0x40;
result = a1 & 0x20;
sound2_mem = a1 & 0x20;
if ( !sound2_FLAG_PCMBSY )
{
if ( !v2 )
{
LABEL_16:
if ( (a1 & 1) == 0 )
{
LABEL_19:
sound2_stat = 0;
return result;
}
goto LABEL_17;
}
if ( a1 >= 0 )
{
if ( v3 )
{
sound2_delay |= 8u;
sound2_stat = 3;
}
else
{
sound2_stat = 4;
sound2_read_dummy = 2;
}
sound2_data_addr = sound2_start_addr;
goto LABEL_30;
}
if ( v3 )
{
sound2_stat = 1;
sound2_intr_base = sound2_record_intr_base;
}
else
{
sound2_stat = 2;
sound2_intr_base = sound2_replay_intr_base;
}
interval_work_set_BDRY();
if ( sound2_stop_addr == sound2_limit_addr )
{
if ( sound2_stop_addr > sound2_start_addr )
{
v5 = sound2_stop_addr - sound2_start_addr;
goto LABEL_43;
}
v5 = 0x3FFFF - sound2_start_addr;
}
else
{
if ( sound2_limit_addr > sound2_start_addr && sound2_stop_addr > sound2_start_addr )
{
if ( sound2_stop_addr < sound2_limit_addr )
goto LABEL_42;
LABEL_48:
sound2_notice_EOS = 0;
LABEL_44:
result = (unsigned int)sound2_mem;
sound2_FLAG_PCMBSY = 1;
if ( (a1 & 1) == 0 )
{
LABEL_18:
if ( (_DWORD)result )
return result;
goto LABEL_19;
}
LABEL_17:
sound2_repeat = 0;
sound2_FLAG_PCMBSY = 0;
goto LABEL_18;
}
v4 = sound2_start_addr;
if ( sound2_limit_addr <= sound2_start_addr )
v4 = sound2_limit_addr;
if ( sound2_stop_addr >= v4 )
{
if ( sound2_stop_addr > sound2_start_addr )
{
LABEL_42:
v5 = sound2_stop_addr - sound2_start_addr;
LABEL_43:
sound2_notice_EOS = 1;
interval_work_set_EOS((unsigned int)(v5 + 1));
goto LABEL_44;
}
goto LABEL_46;
}
if ( sound2_limit_addr <= sound2_start_addr )
{
LABEL_46:
v5 = 0x3FFFF - sound2_start_addr;
goto LABEL_47;
}
v5 = sound2_limit_addr - sound2_start_addr + sound2_stop_addr;
}
LABEL_47:
if ( v5 )
goto LABEL_43;
goto LABEL_48;
}
if ( !v2 )
{
sound2_FLAG_PCMBSY = 0;
goto LABEL_16;
}
LABEL_30:
if ( (a1 & 1) != 0 )
goto LABEL_17;
return result;
case 1:
result = (a1 & 2) == 0 ? 2 : 5;
sound2_mem_size = (a1 & 2) == 0 ? 2 : 5;
return result;
case 2:
case 3:
result = (*(unsigned __int16 *)&sound2_reg[2] << sound2_mem_size) & 0x3FFFF;
sound2_start_addr = (*(unsigned __int16 *)&sound2_reg[2] << sound2_mem_size) & 0x3FFFF;
return result;
case 4:
case 5:
result = (((*(unsigned __int16 *)&sound2_reg[4] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
sound2_stop_addr = (((*(unsigned __int16 *)&sound2_reg[4] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
return result;
case 6:
case 7:
result = (unsigned __int8)sound2_reg[6] | ((unsigned __int8)sound2_reg[7] << 8) & 0x700u;
if ( !((unsigned __int8)sound2_reg[6] | ((unsigned __int8)sound2_reg[7] << 8) & 0x700) )
result = 2048LL;
sound2_record_intr_base = result;
return result;
case 8:
if ( sound2_stat == 3 )
{
if ( sound2_stop_addr == sound2_data_addr || sound2_data_addr == 0x3FFFF )
sound2_delay |= 4u;
*(_BYTE *)(sound2_adpcm + sound2_data_addr) = a1;
sound2_delay |= 8u;
result = (sound2_data_addr + 1) & 0x3FFFF;
sound2_data_addr = (sound2_data_addr + 1) & 0x3FFFF;
}
return result;
case 9:
case 10:
result = 72LL;
if ( *(_WORD *)&sound2_reg[9] )
result = 4718592 / *(unsigned __int16 *)&sound2_reg[9];
sound2_replay_intr_base = result;
return result;
case 12:
case 13:
result = (((*(unsigned __int16 *)&sound2_reg[12] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
sound2_limit_addr = (((*(unsigned __int16 *)&sound2_reg[12] + 1) << sound2_mem_size) - 1) & 0x3FFFF;
return result;
case 16:
return change_sound_flags(16LL);
default:
return result;
}
}

original_code:
void sound2_out_data( byte data )
{
  int wk, l;
  sound2_reg[ sound2_reg_select ] = data;
  xmame_sound2_out_data( data );
  switch( sound2_reg_select ){
  case 0x00:
    sound2_repeat = data & 0x10;
    sound2_mem = data & 0x20;
    sound2_rec = data & 0x40;
    if( sound2_FLAG_PCMBSY ){
      if( !sound2_mem ) sound2_FLAG_PCMBSY = 0;
    }else{
      if( sound2_mem ){
 if( data & 0x80 ){
   if( sound2_rec ){
     sound2_stat = ADPCM_RECORD;
     sound2_intr_base = sound2_record_intr_base;
   }else{
     sound2_stat = ADPCM_REPLAY;
     sound2_intr_base = sound2_replay_intr_base;
   }
   interval_work_set_BDRY();
   if( sound2_stop_addr == sound2_limit_addr ){
     if( sound2_start_addr < sound2_stop_addr ) l = sound2_stop_addr - sound2_start_addr;
     else l = 0x3ffff - sound2_start_addr;
   }else{
     if ( sound2_start_addr<sound2_stop_addr && sound2_start_addr<sound2_limit_addr ){ if( sound2_stop_addr<sound2_limit_addr ) l = sound2_stop_addr - sound2_start_addr;
            else l = 0;
     }else if( sound2_stop_addr<sound2_start_addr && sound2_stop_addr<sound2_limit_addr ){ if( sound2_start_addr<sound2_limit_addr ) l = sound2_limit_addr - sound2_start_addr + sound2_stop_addr;
            else l = 0x3ffff - sound2_start_addr;
     }else { if( sound2_start_addr<sound2_stop_addr ) l = sound2_stop_addr - sound2_start_addr;
        else l = 0x3ffff - sound2_start_addr;
     }
   }
   if( l ){
     sound2_notice_EOS = (1);
     interval_work_set_EOS( l+1 );
   }else{
     sound2_notice_EOS = (0);
   }
   sound2_FLAG_PCMBSY = 1;
 }else{
   if( sound2_rec ){
     sound2_stat = ADPCM_WRITE;
     sound2_delay |= 0x08;
   }else{
     sound2_stat = ADPCM_READ;
     sound2_read_dummy = 2;
   }
   sound2_data_addr = sound2_start_addr;
 }
      }
    }
    if( data & 0x01 ){
      sound2_repeat = 0;
      sound2_FLAG_PCMBSY = 0;
    }
    if( !sound2_mem ) sound2_stat = ADPCM_HALT;
    break;
  case 0x01:
    sound2_mem_size = (data & 0x02) ? 5 : 2;
    break;
  case 0x02:
  case 0x03:
    sound2_start_addr = ((int)sound2_reg[ 0x03 ] << 8) | sound2_reg[ 0x02 ];
    sound2_start_addr = (sound2_start_addr << sound2_mem_size);
    sound2_start_addr &= 0x3ffff;
    break;
  case 0x04:
  case 0x05:
    sound2_stop_addr = ((int)sound2_reg[ 0x05 ] << 8) | sound2_reg[ 0x04 ];
    sound2_stop_addr = ((sound2_stop_addr+1) << sound2_mem_size ) -1;
    sound2_stop_addr &= 0x3ffff;
    break;
  case 0x08:
    if( sound2_stat==ADPCM_WRITE ){
      if( sound2_data_addr == sound2_stop_addr ||
   sound2_data_addr == 0x3ffff ){
 sound2_delay |= 0x04;
      }
      sound2_adpcm[ sound2_data_addr ] = data;
 sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
      sound2_delay |= 0x08;
    }
    break;
  case 0x0c:
  case 0x0d:
    sound2_limit_addr = ((int)sound2_reg[ 0x0d ] << 8) | sound2_reg[ 0x0c ];
    sound2_limit_addr = ((sound2_limit_addr+1)<< sound2_mem_size ) -1;
    sound2_limit_addr &= 0x3ffff;
    break;
  case 0x06:
  case 0x07:
    wk = (((int)sound2_reg[ 0x07 ]&0x07) << 8) | sound2_reg[ 0x06 ];
    wk &= 0x7ff;
    if( wk==0 ) wk = 0x800;
    sound2_record_intr_base = wk;
    break;
  case 0x09:
  case 0x0a:
    wk = ((int)sound2_reg[ 0x0a ] << 8) | sound2_reg[ 0x09 ];
    if( wk==0 ) wk = 0x10000;
    sound2_replay_intr_base = 72 * 65536 / wk;
    break;
  case 0x10:
    change_sound_flags( 0x10 );
    break;
  }
}

canonical_original_code:
void sound2_out_data(unsigned char data)
{
  int wk; int l;
  sound2_reg[ sound2_reg_select ] = data;
  xmame_sound2_out_data( data );
  switch( sound2_reg_select ){
  case 0x00:
    sound2_repeat = data & 0x10;
    sound2_mem = data & 0x20;
    sound2_rec = data & 0x40;
    if( sound2_FLAG_PCMBSY ){
      if( !sound2_mem ) sound2_FLAG_PCMBSY = 0;
    }else{
      if( sound2_mem ){
 if( data & 0x80 ){
   if( sound2_rec ){
     sound2_stat = ADPCM_RECORD;
     sound2_intr_base = sound2_record_intr_base;
   }else{
     sound2_stat = ADPCM_REPLAY;
     sound2_intr_base = sound2_replay_intr_base;
   }
   interval_work_set_BDRY();
   if( sound2_stop_addr == sound2_limit_addr ){
     if( sound2_start_addr < sound2_stop_addr ) l = sound2_stop_addr - sound2_start_addr;
     else l = 0x3ffff - sound2_start_addr;
   }else{
     if ( sound2_start_addr<sound2_stop_addr && sound2_start_addr<sound2_limit_addr ){ if( sound2_stop_addr<sound2_limit_addr ) l = sound2_stop_addr - sound2_start_addr;
            else l = 0;
     }else if( sound2_stop_addr<sound2_start_addr && sound2_stop_addr<sound2_limit_addr ){ if( sound2_start_addr<sound2_limit_addr ) l = sound2_limit_addr - sound2_start_addr + sound2_stop_addr;
            else l = 0x3ffff - sound2_start_addr;
     }else { if( sound2_start_addr<sound2_stop_addr ) l = sound2_stop_addr - sound2_start_addr;
        else l = 0x3ffff - sound2_start_addr;
     }
   }
   if( l ){
     sound2_notice_EOS = (1);
     interval_work_set_EOS( l+1 );
   }else{
     sound2_notice_EOS = (0);
   }
   sound2_FLAG_PCMBSY = 1;
 }else{
   if( sound2_rec ){
     sound2_stat = ADPCM_WRITE;
     sound2_delay |= 0x08;
   }else{
     sound2_stat = ADPCM_READ;
     sound2_read_dummy = 2;
   }
   sound2_data_addr = sound2_start_addr;
 }
      }
    }
    if( data & 0x01 ){
      sound2_repeat = 0;
      sound2_FLAG_PCMBSY = 0;
    }
    if( !sound2_mem ) sound2_stat = ADPCM_HALT;
    break;
  case 0x01:
    sound2_mem_size = (data & 0x02) ? 5 : 2;
    break;
  case 0x02:
  case 0x03:
    sound2_start_addr = ((int)sound2_reg[ 0x03 ] << 8) | sound2_reg[ 0x02 ];
    sound2_start_addr = (sound2_start_addr << sound2_mem_size);
    sound2_start_addr &= 0x3ffff;
    break;
  case 0x04:
  case 0x05:
    sound2_stop_addr = ((int)sound2_reg[ 0x05 ] << 8) | sound2_reg[ 0x04 ];
    sound2_stop_addr = ((sound2_stop_addr+1) << sound2_mem_size ) -1;
    sound2_stop_addr &= 0x3ffff;
    break;
  case 0x08:
    if( sound2_stat==ADPCM_WRITE ){
      if( sound2_data_addr == sound2_stop_addr ||
   sound2_data_addr == 0x3ffff ){
 sound2_delay |= 0x04;
      }
      sound2_adpcm[ sound2_data_addr ] = data;
 sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
      sound2_delay |= 0x08;
    }
    break;
  case 0x0c:
  case 0x0d:
    sound2_limit_addr = ((int)sound2_reg[ 0x0d ] << 8) | sound2_reg[ 0x0c ];
    sound2_limit_addr = ((sound2_limit_addr+1)<< sound2_mem_size ) -1;
    sound2_limit_addr &= 0x3ffff;
    break;
  case 0x06:
  case 0x07:
    wk = (((int)sound2_reg[ 0x07 ]&0x07) << 8) | sound2_reg[ 0x06 ];
    wk &= 0x7ff;
    if( wk==0 ) wk = 0x800;
    sound2_record_intr_base = wk;
    break;
  case 0x09:
  case 0x0a:
    wk = ((int)sound2_reg[ 0x0a ] << 8) | sound2_reg[ 0x09 ];
    if( wk==0 ) wk = 0x10000;
    sound2_replay_intr_base = 72 * 65536 / wk;
    break;
  case 0x10:
    change_sound_flags( 0x10 );
    break;
  }
}

variable_types: wk int

variable_types: l int


decompiled_code:
__int64 sound2_in_status()
{
unsigned int v0; // edx
int v1; // esi
int v2; // ecx
int v3; // eax

xmame_sound2_in_status();
v0 = sound2_delay;
if ( (sound2_delay & 8) != 0 && (v0 = sound2_delay & 0xFFFFFFF7, sound2_delay &= 0xFFFFFFF7, !sound2_MSK_BRDY) )
{
sound2_FLAG_BRDY = 1;
v1 = 8;
}
else
{
v1 = 8 * (unsigned __int8)sound2_FLAG_BRDY;
}
if ( (v0 & 4) != 0 && (sound2_delay = v0 & 0xFFFFFFFB, !sound2_MSK_EOS) )
{
sound2_FLAG_EOS = 1;
v2 = 4;
}
else
{
v2 = 4 * (unsigned __int8)sound2_FLAG_EOS;
}
v3 = (16 * sound2_FLAG_ZERO) | (32 * sound2_FLAG_PCMBSY);
LOBYTE(v3) = sound_FLAG_A | v3;
return v2 | v1 | (2 * sound_FLAG_B) | (unsigned int)v3;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // edx
int v1; // esi
int v2; // ecx
int v3; // eax

xmame_sound2_in_status();
v0 = sound2_delay;
if ( (sound2_delay & 8) != 0 && (v0 = sound2_delay & 0xFFFFFFF7, sound2_delay &= 0xFFFFFFF7, !sound2_MSK_BRDY) )
{
sound2_FLAG_BRDY = 1;
v1 = 8;
}
else
{
v1 = 8 * (unsigned __int8)sound2_FLAG_BRDY;
}
if ( (v0 & 4) != 0 && (sound2_delay = v0 & 0xFFFFFFFB, !sound2_MSK_EOS) )
{
sound2_FLAG_EOS = 1;
v2 = 4;
}
else
{
v2 = 4 * (unsigned __int8)sound2_FLAG_EOS;
}
v3 = (16 * sound2_FLAG_ZERO) | (32 * sound2_FLAG_PCMBSY);
LOBYTE(v3) = sound_FLAG_A | v3;
return v2 | v1 | (2 * sound_FLAG_B) | (unsigned int)v3;
}

original_code:
byte sound2_in_status( void )
{
  xmame_sound2_in_status();
  if( sound2_delay & 0x08 ){
    sound2_delay &= ~0x08;
    if( !sound2_MSK_BRDY ) sound2_FLAG_BRDY = 1;
  }
  if( sound2_delay & 0x04 ){
    sound2_delay &= ~0x04;
    if( !sound2_MSK_EOS ) sound2_FLAG_EOS = 1;
  }
  return ( sound2_FLAG_PCMBSY << 5 ) | ( sound2_FLAG_ZERO << 4 ) |
         ( sound2_FLAG_BRDY << 3 ) | ( sound2_FLAG_EOS << 2 ) |
  ( sound_FLAG_B << 1 ) | sound_FLAG_A;
}

canonical_original_code:
unsigned char sound2_in_status()
{
  xmame_sound2_in_status();
  if( sound2_delay & 0x08 ){
    sound2_delay &= ~0x08;
    if( !sound2_MSK_BRDY ) sound2_FLAG_BRDY = 1;
  }
  if( sound2_delay & 0x04 ){
    sound2_delay &= ~0x04;
    if( !sound2_MSK_EOS ) sound2_FLAG_EOS = 1;
  }
  return ( sound2_FLAG_PCMBSY << 5 ) | ( sound2_FLAG_ZERO << 4 ) |
         ( sound2_FLAG_BRDY << 3 ) | ( sound2_FLAG_EOS << 2 ) |
  ( sound_FLAG_B << 1 ) | sound_FLAG_A;
}


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

xmame_sound2_in_data();
result = 0LL;
if ( sound2_reg_select == 8 && sound2_stat == 4 )
{
v1 = sound2_data_addr;
if ( sound2_read_dummy )
{
--sound2_read_dummy;
}
else
{
if ( sound2_data_addr == sound2_stop_addr )
return result;
v1 = (sound2_data_addr + 1) & 0x3FFFF;
result = *(unsigned __int8 *)(sound2_adpcm + sound2_data_addr);
sound2_data_addr = v1;
}
if ( v1 != sound2_stop_addr )
sound2_FLAG_BRDY = sound2_MSK_BRDY == 0;
}
return result;
}

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

xmame_sound2_in_data();
result = 0LL;
if ( sound2_reg_select == 8 && sound2_stat == 4 )
{
v1 = sound2_data_addr;
if ( sound2_read_dummy )
{
--sound2_read_dummy;
}
else
{
if ( sound2_data_addr == sound2_stop_addr )
return result;
v1 = (sound2_data_addr + 1) & 0x3FFFF;
result = *(unsigned __int8 *)(sound2_adpcm + sound2_data_addr);
sound2_data_addr = v1;
}
if ( v1 != sound2_stop_addr )
sound2_FLAG_BRDY = sound2_MSK_BRDY == 0;
}
return result;
}

original_code:
byte sound2_in_data( void )
{
  byte data = 0x00;
  xmame_sound2_in_data();
  if( sound2_reg_select==0x08 ){
    if( sound2_stat==ADPCM_READ ){
      if( sound2_read_dummy ){
 sound2_read_dummy --;
      }else{
 if( sound2_data_addr != sound2_stop_addr ){
   data = sound2_adpcm[ sound2_data_addr ];
     sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
 }
      }
      if( sound2_data_addr != sound2_stop_addr ){
 sound2_FLAG_BRDY = sound2_MSK_BRDY ? 0 : 1;
      }
      return data;
    }
  }
  return 0x00;
}

canonical_original_code:
unsigned char sound2_in_data()
{
  unsigned char data = 0x00;
  xmame_sound2_in_data();
  if( sound2_reg_select==0x08 ){
    if( sound2_stat==ADPCM_READ ){
      if( sound2_read_dummy ){
 sound2_read_dummy --;
      }else{
 if( sound2_data_addr != sound2_stop_addr ){
   data = sound2_adpcm[ sound2_data_addr ];
     sound2_data_addr = (sound2_data_addr+1) & 0x3ffff;
 }
      }
      if( sound2_data_addr != sound2_stop_addr ){
 sound2_FLAG_BRDY = sound2_MSK_BRDY ? 0 : 1;
      }
      return data;
    }
  }
  return 0x00;
}


decompiled_code:
_BOOL8 statesave_sound()
{
int v0; // er8
_BOOL8 result; // rax

v0 = statesave_table("SND ", &suspend_sound_work);
result = 0LL;
if ( !v0 )
result = (unsigned int)statesave_table("SND2", &suspend_sound_work2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 func9()
{
int v0; // er8
_BOOL8 result; // rax

v0 = statesave_table("SND ", &suspend_sound_work);
result = 0LL;
if ( !v0 )
result = (unsigned int)statesave_table("SND2", &suspend_sound_work2) == 0;
return result;
}

original_code:
int statesave_sound( void )
{
  if( statesave_table( "SND ", suspend_sound_work ) != (0) ) return (0);
  if( statesave_table( "SND2", suspend_sound_work2 ) != (0) ) return (0);
  return (1);
}

canonical_original_code:
int statesave_sound()
{
  if( statesave_table( "SND ", suspend_sound_work ) != (0) ) return (0);
  if( statesave_table( "SND2", suspend_sound_work2 ) != (0) ) return (0);
  return (1);
}


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

v0 = 0;
if ( !(unsigned int)stateload_table("SND ", &suspend_sound_work) )
{
v0 = 1;
if ( (unsigned int)stateload_table("SND2", &suspend_sound_work2) )
{
puts("stateload : Statefile is old. (ver 0.6.0 or 1?)");
if ( sound_prescaler == 6 )
sound_prescaler_sel = 2;
else
sound_prescaler_sel = 3 * (sound_prescaler == 3);
}
}
return v0;
}

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

v0 = 0;
if ( !(unsigned int)stateload_table("SND ", &suspend_sound_work) )
{
v0 = 1;
if ( (unsigned int)stateload_table("SND2", &suspend_sound_work2) )
{
puts("stateload : Statefile is old. (ver 0.6.0 or 1?)");
if ( sound_prescaler == 6 )
sound_prescaler_sel = 2;
else
sound_prescaler_sel = 3 * (sound_prescaler == 3);
}
}
return v0;
}

original_code:
int stateload_sound( void )
{
  if( stateload_table( "SND ", suspend_sound_work ) != (0) ) return (0);
  if( stateload_table( "SND2", suspend_sound_work2 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.0 or 1?)\n" );
    if ( sound_prescaler == 6 ) sound_prescaler_sel = 2;
    else if ( sound_prescaler == 3 ) sound_prescaler_sel = 3;
    else sound_prescaler_sel = 0;
    return (1);
  }
  return (1);
}

canonical_original_code:
int stateload_sound()
{
  if( stateload_table( "SND ", suspend_sound_work ) != (0) ) return (0);
  if( stateload_table( "SND2", suspend_sound_work2 ) != (0) ){
    printf( "stateload : Statefile is old. (ver 0.6.0 or 1?)\n" );
    if ( sound_prescaler == 6 ) sound_prescaler_sel = 2;
    else if ( sound_prescaler == 3 ) sound_prescaler_sel = 3;
    else sound_prescaler_sel = 0;
    return (1);
  }
  return (1);
}


decompiled_code:
void sound_output_after_stateload()
{
int *v0; // r12
__int64 v1; // rbx
int v2; // edx
__int64 v3; // rbp
_DWORD *i; // rax
__int64 v5; // rdi
__int64 v6; // rbx
_DWORD *v7; // rax
int j; // edx
unsigned int v9; // ebx
__int64 v10; // rdi
__int64 v11; // rdi

if ( use_sound )
{
switch ( sound_prescaler_sel )
{
case 1:
xmame_sound_out_reg(47LL);
xmame_sound_out_data(0LL);
xmame_sound_out_reg(46LL);
xmame_sound_out_data(0LL);
break;
case 3:
xmame_sound_out_reg(46LL);
xmame_sound_out_data(0LL);
break;
case 0:
xmame_sound_out_reg(47LL);
xmame_sound_out_data(0LL);
break;
}
v0 = (int *)&addr_2203_2;
if ( sound_board )
v0 = (int *)&addr_2608_1;
v1 = 0LL;
v2 = 0;
v3 = (__int64)&v0[2 * (sound_board == 0 ? 13 : 16) + 3];
LABEL_9:
for ( i = v0 + 1; v2 > (int)v1 || *i < (int)v1; v2 = *(i - 1) )
{
i += 2;
if ( i == (_DWORD *)v3 )
{
if ( ++v1 == 256 )
goto LABEL_17;
LABEL_15:
v2 = *v0;
goto LABEL_9;
}
}
xmame_sound_out_reg((unsigned int)v1);
v5 = (unsigned __int8)sound_reg[v1++];
xmame_sound_out_data(v5);
if ( v1 != 256 )
goto LABEL_15;
LABEL_17:
if ( sound_board == 1 )
{
v6 = 0LL;
LABEL_19:
while ( 2 )
{
v7 = &unk_1184;
for ( j = 1; j > (int)v6 || *v7 < (int)v6; j = *(v7 - 1) )
{
v7 += 2;
if ( v7 == (_DWORD *)&unk_11F4 )
{
if ( ++v6 != 256 )
goto LABEL_19;
goto LABEL_25;
}
}
xmame_sound2_out_reg((unsigned int)v6);
v11 = sound2_reg[v6++];
xmame_sound2_out_data(v11);
if ( v6 != 256 )
continue;
break;
}
LABEL_25:
v9 = sound2_reg[0];
xmame_sound2_out_reg(0LL);
v10 = v9;
LOBYTE(v10) = v9 & 0x7F;
xmame_sound2_out_data(v10);
}
}
}

canonical_decompiled_code:
void func11()
{
int *v0; // r12
__int64 v1; // rbx
int v2; // edx
__int64 v3; // rbp
_DWORD *i; // rax
__int64 v5; // rdi
__int64 v6; // rbx
_DWORD *v7; // rax
int j; // edx
unsigned int v9; // ebx
__int64 v10; // rdi
__int64 v11; // rdi

if ( use_sound )
{
switch ( sound_prescaler_sel )
{
case 1:
xmame_sound_out_reg(47LL);
xmame_sound_out_data(0LL);
xmame_sound_out_reg(46LL);
xmame_sound_out_data(0LL);
break;
case 3:
xmame_sound_out_reg(46LL);
xmame_sound_out_data(0LL);
break;
case 0:
xmame_sound_out_reg(47LL);
xmame_sound_out_data(0LL);
break;
}
v0 = (int *)&addr_2203_2;
if ( sound_board )
v0 = (int *)&addr_2608_1;
v1 = 0LL;
v2 = 0;
v3 = (__int64)&v0[2 * (sound_board == 0 ? 13 : 16) + 3];
LABEL_9:
for ( i = v0 + 1; v2 > (int)v1 || *i < (int)v1; v2 = *(i - 1) )
{
i += 2;
if ( i == (_DWORD *)v3 )
{
if ( ++v1 == 256 )
goto LABEL_17;
LABEL_15:
v2 = *v0;
goto LABEL_9;
}
}
xmame_sound_out_reg((unsigned int)v1);
v5 = (unsigned __int8)sound_reg[v1++];
xmame_sound_out_data(v5);
if ( v1 != 256 )
goto LABEL_15;
LABEL_17:
if ( sound_board == 1 )
{
v6 = 0LL;
LABEL_19:
while ( 2 )
{
v7 = &unk_1184;
for ( j = 1; j > (int)v6 || *v7 < (int)v6; j = *(v7 - 1) )
{
v7 += 2;
if ( v7 == (_DWORD *)&unk_11F4 )
{
if ( ++v6 != 256 )
goto LABEL_19;
goto LABEL_25;
}
}
xmame_sound2_out_reg((unsigned int)v6);
v11 = sound2_reg[v6++];
xmame_sound2_out_data(v11);
if ( v6 != 256 )
continue;
break;
}
LABEL_25:
v9 = sound2_reg[0];
xmame_sound2_out_reg(0LL);
v10 = v9;
LOBYTE(v10) = v9 & 0x7F;
xmame_sound2_out_data(v10);
}
}
}

original_code:
void sound_output_after_stateload( void )
{
  const int (*addr)[2];
  int size;
  static const int addr_2203[][2] = {
    { 0x00, 0x0f },
    { 0x24, 0x28 },
    { 0x30, 0x3e },
    { 0x40, 0x4e },
    { 0x50, 0x5e },
    { 0x60, 0x6e },
    { 0x70, 0x7e },
    { 0x80, 0x8e },
    { 0x90, 0x9e },
    { 0xa0, 0xa2 },
    { 0xa4, 0xa6 },
    { 0xa8, 0xaa },
    { 0xac, 0xae },
    { 0xb0, 0xb2 },
  };
  static const int addr_2608[][2] = {
    { 0x00, 0x0f },
    { 0x11, 0x12 },
    { 0x18, 0x1d },
    { 0x22, 0x22 },
    { 0x24, 0x29 },
    { 0x30, 0x3e },
    { 0x40, 0x4e },
    { 0x50, 0x5e },
    { 0x60, 0x6e },
    { 0x70, 0x7e },
    { 0x80, 0x8e },
    { 0x90, 0x9e },
    { 0xa0, 0xa2 },
    { 0xa4, 0xa6 },
    { 0xa8, 0xaa },
    { 0xac, 0xae },
    { 0xb0, 0xb2 },
  };
  static const int addr_2608_2[][2] = {
    { 0x01, 0x10 },
    { 0x30, 0x3e },
    { 0x40, 0x4e },
    { 0x50, 0x5e },
    { 0x60, 0x6e },
    { 0x70, 0x7e },
    { 0x80, 0x8e },
    { 0x90, 0x9e },
    { 0xa0, 0xa2 },
    { 0xa4, 0xa6 },
    { 0xa8, 0xaa },
    { 0xac, 0xae },
    { 0xb0, 0xb2 },
    { 0xb4, 0xb6 },
  };
  if( use_sound ){
    int i, j;
    switch( sound_prescaler_sel ){
    case 0:
      xmame_sound_out_reg( 0x2f ); xmame_sound_out_data( 0 );
      break;
    case 1:
      xmame_sound_out_reg( 0x2f ); xmame_sound_out_data( 0 );
      xmame_sound_out_reg( 0x2e ); xmame_sound_out_data( 0 );
      break;
    case 3:
      xmame_sound_out_reg( 0x2e ); xmame_sound_out_data( 0 );
      break;
    default:
      break;
    }
    if( sound_board==SOUND_I ){ addr = addr_2203; size = (int)(sizeof(addr_2203)/sizeof((addr_2203)[0])); }
    else { addr = addr_2608; size = (int)(sizeof(addr_2608)/sizeof((addr_2608)[0])); }
    for( i=0; i<256; i++ ){
      for( j=0; j<size; j++ ){
 if( addr[j][0] <= i && i <= addr[j][1] ){
   xmame_sound_out_reg( i );
   xmame_sound_out_data( sound_reg[ i ] );
   break;
 }
      }
    }
    if( sound_board==SOUND_II ){
      addr = addr_2608_2;
      size = (int)(sizeof(addr_2608_2)/sizeof((addr_2608_2)[0]));
      for( i=0; i<256; i++ ){
 for( j=0; j<size; j++ ){
   if( addr[j][0] <= i && i <= addr[j][1] ){
     xmame_sound2_out_reg( i );
     xmame_sound2_out_data( sound2_reg[ i ] );
     break;
   }
 }
      }
      i = sound2_reg[ 0 ];
      i &= ~0x80;
      xmame_sound2_out_reg( 0 );
      xmame_sound2_out_data( i );
    }
  }
}

variable_types:
addr
int (*)[2]

variable_types: size int

variable_types: j int


decompiled_code:
void __fastcall set_romaji_que(char *a1)
{
char v1; // dl
_BYTE *v2; // rcx
int v3; // eax

v1 = *a1;
v2 = a1 + 1;
if ( *a1 )
{
v3 = romaji_set;
do
{
++v2;
romaji_que[v3] = v1;
v1 = *(v2 - 1);
v3 = ((_BYTE)v3 + 1) & 0x3F;
}
while ( v1 );
romaji_set = v3;
}
}

canonical_decompiled_code:
void __fastcall func0(char *a1)
{
char v1; // dl
_BYTE *v2; // rcx
int v3; // eax

v1 = *a1;
v2 = a1 + 1;
if ( *a1 )
{
v3 = romaji_set;
do
{
++v2;
romaji_que[v3] = v1;
v1 = *(v2 - 1);
v3 = ((_BYTE)v3 + 1) & 0x3F;
}
while ( v1 );
romaji_set = v3;
}
}

original_code:
static void set_romaji_que( const Uchar *p )
{
  Uchar c;
  while( (c = *p++ ) ){
    romaji_que[ romaji_set++ ] = c;
    romaji_set &= ((64)-1);
  }
}

canonical_original_code:
static void set_romaji_que(unsigned char *p)
{
  unsigned char c;
  while( (c = *p++ ) ){
    romaji_que[ romaji_set++ ] = c;
    romaji_set &= ((64)-1);
  }
}

variable_types:
p
unsigned char *

variable_types:
c
unsigned char


romajicmp

decompiled_code:
int __fastcall romajicmp(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int romajicmp( const void *p1, const void *p2 )
{
  return strcmp( ((const romaji_list *)p1)->s, ((const romaji_list *)p2)->s );
}

canonical_original_code:
static int romajicmp(void *p1, void *p2)
{
  return strcmp( ((struct romaji_list *)p1)->s, ((struct romaji_list *)p2)->s );
}

user_defined_types: struct romaji_list { char *s; unsigned char list[4]; }


decompiled_code:
__int64 romaji_output()
{
__int64 result; // rax
unsigned int v1; // eax
char v2; // cl
unsigned int v3; // eax
char v4; // cl

result = (unsigned int)press_timer;
if ( press_timer == 4 )
{
v1 = (unsigned __int8)romaji_que[romaji_ptr];
v2 = romaji_que[romaji_ptr];
romaji_ptr = ((_BYTE)romaji_ptr + 1) & 0x3F;
if ( (v1 & 8) != 0 )
key_scan[8] |= 0x40u;
result = v1 >> 4;
press_timer = 5;
key_scan[result] |= 1 << (v2 & 7);
}
else if ( press_timer == 8 )
{
press_timer = 0;
}
else if ( press_timer )
{
result = (unsigned int)++press_timer;
}
else
{
result = romaji_ptr;
if ( romaji_ptr != romaji_set )
{
v3 = (unsigned __int8)romaji_que[romaji_ptr];
v4 = romaji_que[romaji_ptr];
if ( (v3 & 8) != 0 )
key_scan[8] &= 0xBFu;
result = v3 >> 4;
press_timer = 1;
key_scan[result] &= ~(1 << (v4 & 7));
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
unsigned int v1; // eax
char v2; // cl
unsigned int v3; // eax
char v4; // cl

result = (unsigned int)press_timer;
if ( press_timer == 4 )
{
v1 = (unsigned __int8)romaji_que[romaji_ptr];
v2 = romaji_que[romaji_ptr];
romaji_ptr = ((_BYTE)romaji_ptr + 1) & 0x3F;
if ( (v1 & 8) != 0 )
key_scan[8] |= 0x40u;
result = v1 >> 4;
press_timer = 5;
key_scan[result] |= 1 << (v2 & 7);
}
else if ( press_timer == 8 )
{
press_timer = 0;
}
else if ( press_timer )
{
result = (unsigned int)++press_timer;
}
else
{
result = romaji_ptr;
if ( romaji_ptr != romaji_set )
{
v3 = (unsigned __int8)romaji_que[romaji_ptr];
v4 = romaji_que[romaji_ptr];
if ( (v3 & 8) != 0 )
key_scan[8] &= 0xBFu;
result = v3 >> 4;
press_timer = 1;
key_scan[result] &= ~(1 << (v4 & 7));
}
}
return result;
}

original_code:
void romaji_output( void )
{
  Uint c;
  switch( press_timer ){
  case 0:
    if( romaji_ptr != romaji_set ){
      c = romaji_que[ romaji_ptr ];
      if( c & 0x08 ) key_scan[8] &= ~0x40;
      key_scan[ c>>4 ] &= ~(1<<(c&7));
      press_timer ++;
    }
    break;
  case (4):
    c = romaji_que[ romaji_ptr++ ];
    romaji_ptr &= ((64)-1);
    if( c & 0x08 ) key_scan[8] |= 0x40;
    key_scan[ c>>4 ] |= (1<<(c&7));
    press_timer ++;
    break;
  case (4)*2:
    press_timer = 0;
    break;
  default:
    press_timer ++;
  }
}

canonical_original_code:
void romaji_output()
{
  unsigned int c;
  switch( press_timer ){
  case 0:
    if( romaji_ptr != romaji_set ){
      c = romaji_que[ romaji_ptr ];
      if( c & 0x08 ) key_scan[8] &= ~0x40;
      key_scan[ c>>4 ] &= ~(1<<(c&7));
      press_timer ++;
    }
    break;
  case (4):
    c = romaji_que[ romaji_ptr++ ];
    romaji_ptr &= ((64)-1);
    if( c & 0x08 ) key_scan[8] |= 0x40;
    key_scan[ c>>4 ] |= (1<<(c&7));
    press_timer ++;
    break;
  case (4)*2:
    press_timer = 0;
    break;
  default:
    press_timer ++;
  }
}

variable_types:
c
unsigned int


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

result = (unsigned int)(press_timer - 1);
if ( (unsigned int)result <= 3 )
{
press_timer = 4;
result = romaji_output();
}
romaji_set = 0;
romaji_ptr = 0;
press_timer = 0;
input_size = 0;
return result;
}

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

result = (unsigned int)(press_timer - 1);
if ( (unsigned int)result <= 3 )
{
press_timer = 4;
result = func2();
}
romaji_set = 0;
romaji_ptr = 0;
press_timer = 0;
input_size = 0;
return result;
}

original_code:
void romaji_clear( void )
{
  if( 0< press_timer && press_timer <= (4) ){
    press_timer = (4);
    romaji_output();
  }
  romaji_set = 0;
  romaji_ptr = 0;
  press_timer = 0;
  input_size = 0;
}

canonical_original_code:
void romaji_clear()
{
  if( 0< press_timer && press_timer <= (4) ){
    press_timer = (4);
    romaji_output();
  }
  romaji_set = 0;
  romaji_ptr = 0;
  press_timer = 0;
  input_size = 0;
}


decompiled_code:
unsigned __int64 romaji_init()
{
void **v0; // rax
__int64 v1; // rcx
__m128i v2; // xmm2
const __m128i *v3; // rdx
const __m128i *v4; // rcx
int v5; // esi
__m128i v6; // xmm0
__int64 v7; // rax
unsigned __int64 result; // rax
int v9; // edx
__int64 v10; // rcx
__m128i v11; // xmm1

romaji_clear();
if ( romaji_type == 1 )
{
v0 = &list_msime;
v1 = 243LL;
}
else
{
v0 = &list_egg;
if ( romaji_type == 2 )
v0 = &list_atok;
v1 = 214LL;
if ( romaji_type != 2 )
v1 = 180LL;
}
v2 = _mm_load_si128((const __m128i *)v0);
v3 = (const __m128i *)(v0 + 2);
nr_list = 1;
v4 = (const __m128i *)&v0[2 * v1];
v5 = 1;
list[0] = (__int128)v2;
do
{
if ( v3 == v4 )
break;
v6 = _mm_load_si128(v3++);
v7 = nr_list++;
v5 = nr_list;
list[v7] = (__int128)v6;
}
while ( v5 <= 279 );
qsort(list, v5, 0x10uLL, romajicmp);
result = 0LL;
v9 = nr_list;
v10 = nr_list;
do
{
v11 = _mm_load_si128((const __m128i *)&(&list_mark)[result / 8]);
nr_list = ++v9;
list[v10 + result / 0x10] = (__int128)v11;
if ( v9 > 279 )
break;
result += 16LL;
}
while ( result != 144 );
return result;
}

canonical_decompiled_code:
unsigned __int64 func4()
{
void **v0; // rax
__int64 v1; // rcx
__m128i v2; // xmm2
const __m128i *v3; // rdx
const __m128i *v4; // rcx
int v5; // esi
__m128i v6; // xmm0
__int64 v7; // rax
unsigned __int64 result; // rax
int v9; // edx
__int64 v10; // rcx
__m128i v11; // xmm1

func3();
if ( romaji_type == 1 )
{
v0 = &list_msime;
v1 = 243LL;
}
else
{
v0 = &list_egg;
if ( romaji_type == 2 )
v0 = &list_atok;
v1 = 214LL;
if ( romaji_type != 2 )
v1 = 180LL;
}
v2 = _mm_load_si128((const __m128i *)v0);
v3 = (const __m128i *)(v0 + 2);
nr_list = 1;
v4 = (const __m128i *)&v0[2 * v1];
v5 = 1;
list[0] = (__int128)v2;
do
{
if ( v3 == v4 )
break;
v6 = _mm_load_si128(v3++);
v7 = nr_list++;
v5 = nr_list;
list[v7] = (__int128)v6;
}
while ( v5 <= 279 );
qsort(list, v5, 0x10uLL, romajicmp);
result = 0LL;
v9 = nr_list;
v10 = nr_list;
do
{
v11 = _mm_load_si128((const __m128i *)&(&list_mark)[result / 8]);
nr_list = ++v9;
list[v10 + result / 0x10] = (__int128)v11;
if ( v9 > 279 )
break;
result += 16LL;
}
while ( result != 144 );
return result;
}

original_code:
void romaji_init( void )
{
  int i, nr_p;
  const romaji_list *p;
  romaji_clear();
  nr_list = 0;
  if ( romaji_type==1 ){ p = list_msime; nr_p = (int)(sizeof(list_msime)/sizeof((list_msime)[0])); }
  else if( romaji_type==2 ){ p = list_atok; nr_p = (int)(sizeof(list_atok)/sizeof((list_atok)[0])); }
  else { p = list_egg; nr_p = (int)(sizeof(list_egg)/sizeof((list_egg)[0])); }
  for( i=0; i<nr_p; i++ ){
    list[ nr_list ++ ] = *p ++;
    if( nr_list >= (int)(sizeof(list)/sizeof((list)[0])) ) break;
  }
  qsort( &list, nr_list, sizeof(romaji_list), romajicmp );
  p = list_mark;
  nr_p = (int)(sizeof(list_mark)/sizeof((list_mark)[0]));
  for( i=0; i<nr_p; i++ ){
    list[ nr_list ++ ] = *p ++;
    if( nr_list >= (int)(sizeof(list)/sizeof((list)[0])) ) break;
  }
}

canonical_original_code:
void romaji_init()
{
  int i; int nr_p;
  struct romaji_list *p;
  romaji_clear();
  nr_list = 0;
  if ( romaji_type==1 ){ p = list_msime; nr_p = (int)(sizeof(list_msime)/sizeof((list_msime)[0])); }
  else if( romaji_type==2 ){ p = list_atok; nr_p = (int)(sizeof(list_atok)/sizeof((list_atok)[0])); }
  else { p = list_egg; nr_p = (int)(sizeof(list_egg)/sizeof((list_egg)[0])); }
  for( i=0; i<nr_p; i++ ){
    list[ nr_list ++ ] = *p ++;
    if( nr_list >= (int)(sizeof(list)/sizeof((list)[0])) ) break;
  }
  qsort( &list, nr_list, sizeof(romaji_list), romajicmp );
  p = list_mark;
  nr_p = (int)(sizeof(list_mark)/sizeof((list_mark)[0]));
  for( i=0; i<nr_p; i++ ){
    list[ nr_list ++ ] = *p ++;
    if( nr_list >= (int)(sizeof(list)/sizeof((list)[0])) ) break;
  }
}

variable_types: struct romaji_list { char *s; unsigned char list[4]; } *


decompiled_code:
__int64 __fastcall romaji_input(int c)
{
unsigned __int64 v1; // rax
char v2; // bp
int v3; // ebx
int v4; // ebp
int v5; // ebx
__int64 v6; // r12
char *v7; // rsi
int v8; // edi
int v9; // er8
_BYTE *v10; // rax
_BYTE *v11; // rcx
char *v12; // rdx
size_t v13; // rdx
size_t v14; // rdx
__int64 result; // rax
__int64 v16; // rdx
unsigned __int16 v17; // ax
unsigned __int64 v18; // rdx
__int64 v19; // rcx

v1 = (unsigned int)(c - 32);
v2 = c;
if ( (unsigned int)v1 <= 0x20 )
{
v16 = 0x10000F081LL;
if ( !_bittest64(&v16, v1) )
goto LABEL_26;
}
else if ( (c & 0xFFFFFFDF) != 91 && c != 125 )
{
LABEL_26:
v17 = (*_ctype_b_loc())[c];
if ( (v17 & 0x200) != 0 )
{
v2 = toupper(c);
}
else if ( (v17 & 0x100) == 0 )
{
if ( c == 156 )
{
if ( input_size )
{
romaji_clear();
return 0LL;
}
}
else
{
v18 = (unsigned int)(c - 152);
if ( (unsigned int)v18 <= 0x2B )
{
v19 = 0xC0000000401LL;
result = (unsigned int)c;
if ( _bittest64(&v19, v18) )
return result;
}
else if ( (unsigned int)(c - 150) <= 1 )
{
return (unsigned int)c;
}
}
romaji_clear();
return (unsigned int)c;
}
goto LABEL_3;
}
LABEL_3:
v3 = input_size;
input_buf[input_size] = v2;
v4 = nr_list;
v5 = v3 + 1;
input_size = v5;
v6 = v5 - 1LL;
if ( !v5 )
return 0LL;
while ( v4 <= 0 )
{
LABEL_16:
if ( input_buf[0] == 78 )
{
set_romaji_que("Q");
goto LABEL_22;
}
if ( v5 <= 1 )
{
LABEL_22:
v14 = v6;
input_size = --v5;
--v6;
memmove(input_buf, &byte_16CD, v14);
if ( !v5 )
return 0LL;
}
else
{
if ( input_buf[0] == byte_16CD )
set_romaji_que("Z");
v13 = v6;
input_size = --v5;
--v6;
memmove(input_buf, &byte_16CD, v13);
}
}
v7 = (char *)&unk_4F0;
v8 = 1;
v9 = 0;
while ( 1 )
{
v10 = (_BYTE *)*((_QWORD *)v7 - 2);
if ( v5 > 0 )
{
v11 = &v10[v5];
v12 = input_buf;
while ( *v12 == *v10 )
{
++v10;
++v12;
if ( v10 == v11 )
{
if ( !*v10 )
{
set_romaji_que(v7 - 8);
goto LABEL_29;
}
if ( v4 <= v8 )
goto LABEL_28;
v9 = 1;
goto LABEL_12;
}
}
}
if ( v9 )
break;
if ( v8 >= v4 )
goto LABEL_16;
LABEL_12:
++v8;
v7 += 16;
}
LABEL_28:
if ( input_size > 3 )
LABEL_29:
input_size = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int c)
{
unsigned __int64 v1; // rax
char v2; // bp
int v3; // ebx
int v4; // ebp
int v5; // ebx
__int64 v6; // r12
char *v7; // rsi
int v8; // edi
int v9; // er8
_BYTE *v10; // rax
_BYTE *v11; // rcx
char *v12; // rdx
size_t v13; // rdx
size_t v14; // rdx
__int64 result; // rax
__int64 v16; // rdx
unsigned __int16 v17; // ax
unsigned __int64 v18; // rdx
__int64 v19; // rcx

v1 = (unsigned int)(c - 32);
v2 = c;
if ( (unsigned int)v1 <= 0x20 )
{
v16 = 0x10000F081LL;
if ( !_bittest64(&v16, v1) )
goto LABEL_26;
}
else if ( (c & 0xFFFFFFDF) != 91 && c != 125 )
{
LABEL_26:
v17 = (*_ctype_b_loc())[c];
if ( (v17 & 0x200) != 0 )
{
v2 = toupper(c);
}
else if ( (v17 & 0x100) == 0 )
{
if ( c == 156 )
{
if ( input_size )
{
func3();
return 0LL;
}
}
else
{
v18 = (unsigned int)(c - 152);
if ( (unsigned int)v18 <= 0x2B )
{
v19 = 0xC0000000401LL;
result = (unsigned int)c;
if ( _bittest64(&v19, v18) )
return result;
}
else if ( (unsigned int)(c - 150) <= 1 )
{
return (unsigned int)c;
}
}
func3();
return (unsigned int)c;
}
goto LABEL_3;
}
LABEL_3:
v3 = input_size;
input_buf[input_size] = v2;
v4 = nr_list;
v5 = v3 + 1;
input_size = v5;
v6 = v5 - 1LL;
if ( !v5 )
return 0LL;
while ( v4 <= 0 )
{
LABEL_16:
if ( input_buf[0] == 78 )
{
func0("Q");
goto LABEL_22;
}
if ( v5 <= 1 )
{
LABEL_22:
v14 = v6;
input_size = --v5;
--v6;
memmove(input_buf, &byte_16CD, v14);
if ( !v5 )
return 0LL;
}
else
{
if ( input_buf[0] == byte_16CD )
func0("Z");
v13 = v6;
input_size = --v5;
--v6;
memmove(input_buf, &byte_16CD, v13);
}
}
v7 = (char *)&unk_4F0;
v8 = 1;
v9 = 0;
while ( 1 )
{
v10 = (_BYTE *)*((_QWORD *)v7 - 2);
if ( v5 > 0 )
{
v11 = &v10[v5];
v12 = input_buf;
while ( *v12 == *v10 )
{
++v10;
++v12;
if ( v10 == v11 )
{
if ( !*v10 )
{
func0(v7 - 8);
goto LABEL_29;
}
if ( v4 <= v8 )
goto LABEL_28;
v9 = 1;
goto LABEL_12;
}
}
}
if ( v9 )
break;
if ( v8 >= v4 )
goto LABEL_16;
LABEL_12:
++v8;
v7 += 16;
}
LABEL_28:
if ( input_size > 3 )
LABEL_29:
input_size = 0;
return 0LL;
}

original_code:
int romaji_input( int key )
{
  int i, j;
  if( key == ' ' ||
      key == '@' ||
      key == '[' ||
      key == '/' ||
      key == '-' ||
      key == '{' ||
      key == '}' ||
      key == '.' ||
      key == ',' ||
      key == '\'' ){
    ;
  }
  else if( ((*__ctype_b_loc ())[(int) ((key))] & (unsigned short int) _ISlower) ){
    key = toupper( key );
  }
  else if( ((*__ctype_b_loc ())[(int) ((key))] & (unsigned short int) _ISupper) ){
    ;
  }
  else {
    if( key == KEY88_ESC && input_size != 0 ){
      romaji_clear();
      return 0;
    }
    if( key == KEY88_SHIFT ||
 key == KEY88_SHIFTL ||
 key == KEY88_SHIFTR ||
 key == KEY88_CAPS ||
 key == KEY88_KANA ||
 key == KEY88_GRAPH ){
      ;
    }else{
      romaji_clear();
    }
    return key;
  }
  input_buf[ input_size ] = key;
  input_size ++;
  while( input_size ){
    int list_size = nr_list;
    romaji_list *list_p = list;
    int same = (0);
    int nearly = (0);
    for( i=0; i<list_size; i++, list_p++ ){
      const char *s1 = input_buf;
      const char *s2 = list_p->s;
      for( j=0; j<input_size; j++, s1++, s2++ ){
 if( *s1 != *s2 ){ j=0; break; }
      }
      if( j==0 ){
 if( nearly ) break;
      }else{
 if( *s2 == '\0' ){
   same = (1); break;
 }else{
   nearly = (1);
 }
      }
    }
    if( same ){
      set_romaji_que( list_p->list );
      input_size = 0;
      break;
    }else if( nearly ){
      break;
    }else{
      if( input_buf[0] == 'N' ){
 set_romaji_que( list_NN.list );
      }else if( input_size >= 2 &&
  input_buf[0]==input_buf[1] ){
 set_romaji_que( list_tu.list );
      }
      input_size --;
      memmove( &input_buf[0], &input_buf[1],input_size );
    }
  }
  if( input_size >= (int)sizeof(input_buf) )
    input_size = 0;
  return 0;
}

canonical_original_code:
int romaji_input(int key)
{
  int i; int j;
  if( key == ' ' ||
      key == '@' ||
      key == '[' ||
      key == '/' ||
      key == '-' ||
      key == '{' ||
      key == '}' ||
      key == '.' ||
      key == ',' ||
      key == '\'' ){
    ;
  }
  else if( ((*__ctype_b_loc ())[(int) ((key))] & (unsigned short) _ISlower) ){
    key = toupper( key );
  }
  else if( ((*__ctype_b_loc ())[(int) ((key))] & (unsigned short) _ISupper) ){
    ;
  }
  else {
    if( key == KEY88_ESC && input_size != 0 ){
      romaji_clear();
      return 0;
    }
    if( key == KEY88_SHIFT ||
 key == KEY88_SHIFTL ||
 key == KEY88_SHIFTR ||
 key == KEY88_CAPS ||
 key == KEY88_KANA ||
 key == KEY88_GRAPH ){
      ;
    }else{
      romaji_clear();
    }
    return key;
  }
  input_buf[ input_size ] = key;
  input_size ++;
  while( input_size ){
    int list_size = nr_list;
    struct romaji_list *list_p = list;
    int same = (0);
    int nearly = (0);
    for( i=0; i<list_size; i++, list_p++ ){
      char *s1 = input_buf;
      char *s2 = list_p->s;
      for( j=0; j<input_size; j++, s1++, s2++ ){
 if( *s1 != *s2 ){ j=0; break; }
      }
      if( j==0 ){
 if( nearly ) break;
      }else{
 if( *s2 == '\0' ){
   same = (1); break;
 }else{
   nearly = (1);
 }
      }
    }
    if( same ){
      set_romaji_que( list_p->list );
      input_size = 0;
      break;
    }else if( nearly ){
      break;
    }else{
      if( input_buf[0] == 'N' ){
 set_romaji_que( list_NN.list );
      }else if( input_size >= 2 &&
  input_buf[0]==input_buf[1] ){
 set_romaji_que( list_tu.list );
      }
      input_size --;
      memmove( &input_buf[0], &input_buf[1],input_size );
    }
  }
  if( input_size >= (int)sizeof(input_buf) )
    input_size = 0;
  return 0;
}

variable_types: key int

variable_types: same int

variable_types: nearly int


original_code:
void BEEP88UpdateOne(int num, INT16 *buffer, int length)
{
  int i, data;
  unsigned short *buf16 = (unsigned short *)buffer;
  {
    for( i=0; i < length ; i++ ){
      if( BEEP[num].port40 & 0x20 ){
 BEEP[num].cnt ++;
 if ( BEEP[num].cnt < BEEP[num].cnt_of_clock/2 ) data = 0x2000;
 else if( BEEP[num].cnt < BEEP[num].cnt_of_clock ) data = 0x0000;
 else{ BEEP[num].cnt -= BEEP[num].cnt_of_clock; data = 0x0000; }
      }else{
 data = 0x0000;
      }
      if( BEEP[num].port40 & 0x80 ) data = 0x2000;
      *buf16 ++ = data;
    }
  }
}

canonical_original_code:
void BEEP88UpdateOne(int num, short *buffer, int length)
{
  int i; int data;
  unsigned short *buf16 = (unsigned short *)buffer;
  {
    for( i=0; i < length ; i++ ){
      if( BEEP[num].port40 & 0x20 ){
 BEEP[num].cnt ++;
 if ( BEEP[num].cnt < BEEP[num].cnt_of_clock/2 ) data = 0x2000;
 else if( BEEP[num].cnt < BEEP[num].cnt_of_clock ) data = 0x0000;
 else{ BEEP[num].cnt -= BEEP[num].cnt_of_clock; data = 0x0000; }
      }else{
 data = 0x0000;
      }
      if( BEEP[num].port40 & 0x80 ) data = 0x2000;
      *buf16 ++ = data;
    }
  }
}

variable_types: num int

variable_types:
buffer
short *

variable_types: length int

variable_types: data int


decompiled_code:
__int64 __fastcall BEEP88Init(int a1, int a2, int a3)
{
if ( a1 > 1 )
return 0xFFFFFFFFLL;
memset(BEEP, 0, 28LL * a1);
if ( a1 == 1 )
{
dword_1C4 = a2;
dword_1C8 = a3;
BEEP[0] = 0;
dword_1CC = 0;
dword_1D4 = a3 / a2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3)
{
if ( a1 > 1 )
return 0xFFFFFFFFLL;
memset(BEEP, 0, 28LL * a1);
if ( a1 == 1 )
{
dword_1C4 = a2;
dword_1C8 = a3;
BEEP[0] = 0;
dword_1CC = 0;
dword_1D4 = a3 / a2;
}
return 0LL;
}

original_code:
int BEEP88Init(int num, int clock, int sample_rate )
{
  int i;
  if (num>1) return (-1);
  memset(BEEP,0,sizeof(Beep) * num);
  for ( i = 0 ; i < num; i++ ) {
    BEEP[i].status = i;
    BEEP[i].clock = clock;
    BEEP[i].sample_rate = sample_rate;
    BEEP[i].sample_bit_8 = (0);
    BEEP[i].cnt_of_clock = sample_rate / clock;
  }
  return(0);
}

canonical_original_code:
int BEEP88Init(int num, int clock, int sample_rate)
{
  int i;
  if (num>1) return (-1);
  memset(BEEP,0,sizeof(Beep) * num);
  for ( i = 0 ; i < num; i++ ) {
    BEEP[i].status = i;
    BEEP[i].clock = clock;
    BEEP[i].sample_rate = sample_rate;
    BEEP[i].sample_bit_8 = (0);
    BEEP[i].cnt_of_clock = sample_rate / clock;
  }
  return(0);
}

variable_types: clock int

variable_types: i int


decompiled_code:
void BEEP88Shutdown()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void BEEP88Shutdown(void)
{
}

canonical_original_code:
void BEEP88Shutdown()
{
}


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

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return stream_update((unsigned int)stream[a1], 0LL);
}

original_code:
void BEEP88UpdateRequest( int chip )
{
  stream_update( stream[chip], 0 );
}

canonical_original_code:
void BEEP88UpdateRequest(int chip)
{
  stream_update( stream[chip], 0 );
}

variable_types: chip int


decompiled_code:
_BOOL8 __fastcall BEEP88_sh_start(__int64 a1)
{
unsigned int *v2; // rax
__int64 v3; // rdi
__int64 v4; // rbx
const char *v5; // rax
char v7[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = *(unsigned int **)(a1 + 8);
v3 = *v2;
intf = (__int64)v2;
if ( (int)v3 > 0 )
{
v4 = 0LL;
do
{
v5 = (const char *)sound_name(a1);
sprintf(v7, "%s #%d", v5, (unsigned int)v4);
stream[v4] = stream_init(
v7,
*(unsigned __int16 *)(intf + 4LL * (int)v4 + 8),
sample_rate,
(unsigned int)v4,
&BEEP88UpdateOne);
v2 = (unsigned int *)intf;
++v4;
v3 = *(unsigned int *)intf;
}
while ( (int)v3 > (int)v4 );
}
return (unsigned int)BEEP88Init(v3, v2[1], sample_rate) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
unsigned int *v2; // rax
__int64 v3; // rdi
__int64 v4; // rbx
const char *v5; // rax
char v7[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = *(unsigned int **)(a1 + 8);
v3 = *v2;
intf = (__int64)v2;
if ( (int)v3 > 0 )
{
v4 = 0LL;
do
{
v5 = (const char *)sound_name(a1);
sprintf(v7, "%s #%d", v5, (unsigned int)v4);
stream[v4] = stream_init(
v7,
*(unsigned __int16 *)(intf + 4LL * (int)v4 + 8),
sample_rate,
(unsigned int)v4,
&BEEP88UpdateOne);
v2 = (unsigned int *)intf;
++v4;
v3 = *(unsigned int *)intf;
}
while ( (int)v3 > (int)v4 );
}
return (unsigned int)BEEP88Init(v3, v2[1], sample_rate) != 0;
}

original_code:
int BEEP88_sh_start(const struct MachineSound *msound)
{
  int i;
  intf = msound->sound_interface;
  for (i = 0;i < intf->num;i++)
  {
    int volume;
    char name[20];
    sprintf(name,"%s #%d",sound_name(msound),i);
    volume = intf->mixing_level[i]&0xffff;
    stream[i] = stream_init(name,volume,sample_rate,i,BEEP88UpdateOne);
  }
  if (BEEP88Init(intf->num,intf->baseclock,sample_rate) == 0)
  {
    return 0;
  }
  return 1;
}

canonical_original_code:
int BEEP88_sh_start(struct MachineSound *msound)
{
  int i;
  intf = msound->sound_interface;
  for (i = 0;i < intf->num;i++)
  {
    int volume;
    char name[20];
    sprintf(name,"%s #%d",sound_name(msound),i);
    volume = intf->mixing_level[i]&0xffff;
    stream[i] = stream_init(name,volume,sample_rate,i,BEEP88UpdateOne);
  }
  if (BEEP88Init(intf->num,intf->baseclock,sample_rate) == 0)
  {
    return 0;
  }
  return 1;
}

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

variable_types: volume int

variable_types:
name
char [20]


decompiled_code:
// attributes: thunk
__int64 BEEP88_sh_stop()
{
return BEEP88Shutdown();
}

canonical_decompiled_code:
__int64 func2()
{
return BEEP88Shutdown();
}

original_code:
void BEEP88_sh_stop(void)
{
  BEEP88Shutdown();
}

canonical_original_code:
void BEEP88_sh_stop()
{
  BEEP88Shutdown();
}


decompiled_code:
__int64 BEEP88_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++;
BEEP88ResetChip(v2);
result = intf;
}
while ( *(_DWORD *)intf > (signed int)v1 );
}
return result;
}

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

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

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

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


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

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

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

canonical_original_code:
void BEEP88_write_port_0_w(unsigned int offset, unsigned char data)
{
  BEEP88Write(0,data);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall make_snapshot(__int64 a1, __int64 a2)
{
void (**v2)(void); // rdx
int v3; // eax
__int64 result; // rax
void (**v5)(void); // rsi

v2 = (void (**)(void))&snapshot_list_normal;
if ( use_interlace )
{
v2 = (void (**)(void))&snapshot_list_itlace;
if ( use_interlace <= 0 )
{
snapshot_clear(a1, a2, &snapshot_list_itlace);
v2 = (void (**)(void))&snapshot_list_skipln;
}
}
v3 = CRTC_SZ_LINES != 25;
if ( (sys_ctrl & 1) == 0 )
v3 += 2;
if ( (grph_ctrl & 8) != 0 )
{
if ( (grph_ctrl & 0x10) == 0 )
{
v5 = v2 + 8;
v2 += 24;
if ( (grph_ctrl & 1) != 0 )
v2 = v5;
}
}
else
{
v2 += 16;
}
v2[2 * v3 + 1]();
setup_palette(&pal);
result = 0LL;
byte_3F802 = 0;
word_3F800 = 0;
return result;
}

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

v2 = (void (**)(void))&snapshot_list_normal;
if ( use_interlace )
{
v2 = (void (**)(void))&snapshot_list_itlace;
if ( use_interlace <= 0 )
{
snapshot_clear(a1, a2, &snapshot_list_itlace);
v2 = (void (**)(void))&snapshot_list_skipln;
}
}
v3 = CRTC_SZ_LINES != 25;
if ( (sys_ctrl & 1) == 0 )
v3 += 2;
if ( (grph_ctrl & 8) != 0 )
{
if ( (grph_ctrl & 0x10) == 0 )
{
v5 = v2 + 8;
v2 += 24;
if ( (grph_ctrl & 1) != 0 )
v2 = v5;
}
}
else
{
v2 += 16;
}
v2[2 * v3 + 1]();
setup_palette(&pal);
result = 0LL;
byte_3F802 = 0;
word_3F800 = 0;
return result;
}

original_code:
static void make_snapshot( void )
{
  int vram_mode, text_mode;
  SNAPSHOT_FUNC (*list)[4][2];
  if ( use_interlace == 0 ){ list = snapshot_list_normal; }
  else if( use_interlace > 0 ){ list = snapshot_list_itlace; }
  else { snapshot_clear();
     list = snapshot_list_skipln; }
  if( sys_ctrl & (0x01) ){
    if( CRTC_SZ_LINES == 25 ){ text_mode = V_80x25; }
    else { text_mode = V_80x20; }
  }else{
    if( CRTC_SZ_LINES == 25 ){ text_mode = V_40x25; }
    else { text_mode = V_40x20; }
  }
  if( grph_ctrl & (0x08) ){
    if( grph_ctrl & (0x10) ){
        vram_mode = V_COLOR;
    }else{
      if( grph_ctrl & (0x01) ){
 vram_mode = V_MONO;
      }else{
 vram_mode = V_HIRESO;
      }
    }
  }else{
        vram_mode = V_UNDISP;
  }
  (list[ vram_mode ][ text_mode ][ V_ALL ])();
  setup_palette( pal );
  pal[16].red = 0;
  pal[16].green = 0;
  pal[16].blue = 0;
}

canonical_original_code:
static void make_snapshot()
{
  int vram_mode; int text_mode;
  SNAPSHOT_FUNC (*list)[4][2];
  if ( use_interlace == 0 ){ list = snapshot_list_normal; }
  else if( use_interlace > 0 ){ list = snapshot_list_itlace; }
  else { snapshot_clear();
     list = snapshot_list_skipln; }
  if( sys_ctrl & (0x01) ){
    if( CRTC_SZ_LINES == 25 ){ text_mode = V_80x25; }
    else { text_mode = V_80x20; }
  }else{
    if( CRTC_SZ_LINES == 25 ){ text_mode = V_40x25; }
    else { text_mode = V_40x20; }
  }
  if( grph_ctrl & (0x08) ){
    if( grph_ctrl & (0x10) ){
        vram_mode = V_COLOR;
    }else{
      if( grph_ctrl & (0x01) ){
 vram_mode = V_MONO;
      }else{
 vram_mode = V_HIRESO;
      }
    }
  }else{
        vram_mode = V_UNDISP;
  }
  (list[ vram_mode ][ text_mode ][ V_ALL ])();
  setup_palette( pal );
  pal[16].red = 0;
  pal[16].green = 0;
  pal[16].blue = 0;
}


decompiled_code:
size_t screen_snapshot_init()
{
size_t result; // rax
_DWORD *v1; // rbx
char *v2; // rdi
__int64 v3; // rdx
__int64 v4; // rcx

if ( !file_snap )
set_snapshot_filename(1LL);
memset(snapshot_cmd, 0, sizeof(snapshot_cmd));
result = (size_t)getenv("QUASI88_SSS_CMD");
v1 = (_DWORD *)result;
if ( !result )
goto LABEL_5;
result = strlen((const char *)result);
if ( result > 0x3FF )
goto LABEL_5;
++result;
v2 = snapshot_cmd;
if ( (unsigned int)result >= 8 )
{
v4 = (unsigned int)result >> 3;
qmemcpy(snapshot_cmd, v1, 8 * v4);
v2 = &snapshot_cmd[8 * v4];
v1 += 2 * v4;
}
v3 = 0LL;
if ( (result & 4) == 0 )
{
if ( (result & 2) == 0 )
goto LABEL_10;
LABEL_12:
*(_WORD *)&v2[v3] = *(_WORD *)((char *)v1 + v3);
v3 += 2LL;
if ( (result & 1) != 0 )
goto LABEL_11;
LABEL_5:
snapshot_cmd_do = 0;
return result;
}
*(_DWORD *)v2 = *v1;
v3 = 4LL;
if ( (result & 2) != 0 )
goto LABEL_12;
LABEL_10:
if ( (result & 1) == 0 )
goto LABEL_5;
LABEL_11:
result = *((unsigned __int8 *)v1 + v3);
v2[v3] = result;
snapshot_cmd_do = 0;
return result;
}

canonical_decompiled_code:
size_t func4()
{
size_t result; // rax
_DWORD *v1; // rbx
char *v2; // rdi
__int64 v3; // rdx
__int64 v4; // rcx

if ( !file_snap )
set_snapshot_filename(1LL);
memset(snapshot_cmd, 0, sizeof(snapshot_cmd));
result = (size_t)getenv("QUASI88_SSS_CMD");
v1 = (_DWORD *)result;
if ( !result )
goto LABEL_5;
result = strlen((const char *)result);
if ( result > 0x3FF )
goto LABEL_5;
++result;
v2 = snapshot_cmd;
if ( (unsigned int)result >= 8 )
{
v4 = (unsigned int)result >> 3;
qmemcpy(snapshot_cmd, v1, 8 * v4);
v2 = &snapshot_cmd[8 * v4];
v1 += 2 * v4;
}
v3 = 0LL;
if ( (result & 4) == 0 )
{
if ( (result & 2) == 0 )
goto LABEL_10;
LABEL_12:
*(_WORD *)&v2[v3] = *(_WORD *)((char *)v1 + v3);
v3 += 2LL;
if ( (result & 1) != 0 )
goto LABEL_11;
LABEL_5:
snapshot_cmd_do = 0;
return result;
}
*(_DWORD *)v2 = *v1;
v3 = 4LL;
if ( (result & 2) != 0 )
goto LABEL_12;
LABEL_10:
if ( (result & 1) == 0 )
goto LABEL_5;
LABEL_11:
result = *((unsigned __int8 *)v1 + v3);
v2[v3] = result;
snapshot_cmd_do = 0;
return result;
}

original_code:
void screen_snapshot_init( void )
{
  const char *s;
  if( file_snap[0] == '\0' ){
    set_snapshot_filename( (1) );
  }
  memset( snapshot_cmd, 0, (1024) );
  s = getenv( "QUASI88_SSS_CMD" );
  if( s && (strlen(s) < (1024)) ){
    strcpy( snapshot_cmd, s );
  }
  snapshot_cmd_do = (0);
}

canonical_original_code:
void screen_snapshot_init()
{
  char *s;
  if( file_snap[0] == '\0' ){
    set_snapshot_filename( (1) );
  }
  memset( snapshot_cmd, 0, (1024) );
  s = getenv( "QUASI88_SSS_CMD" );
  if( s && (strlen(s) < (1024)) ){
    strcpy( snapshot_cmd, s );
  }
  snapshot_cmd_do = (0);
}

variable_types:
s
char *


decompiled_code:
int __fastcall oss_mixer_get(__int64 a1, int a2, _DWORD *a3, _DWORD *a4)
{
int result; // eax
int v7; // edx
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

result = ioctl(**(_DWORD **)(a1 + 184), oss_mixer_sysdep_to_oss[a2] | 0x80044D00, &v8);
if ( result )
{
perror("error: SOUND_MIXER_READ");
result = -1;
}
else
{
v7 = BYTE1(v8);
*a3 = (unsigned __int8)v8;
*a4 = v7;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, _DWORD *a3, _DWORD *a4)
{
int result; // eax
int v7; // edx
int v8; // [rsp+Ch] [rbp-1Ch] BYREF

result = ioctl(**(_DWORD **)(a1 + 184), oss_mixer_sysdep_to_oss[a2] | 0x80044D00, &v8);
if ( result )
{
perror("error: SOUND_MIXER_READ");
result = -1;
}
else
{
v7 = BYTE1(v8);
*a3 = (unsigned __int8)v8;
*a4 = v7;
}
return result;
}

original_code:
static int oss_mixer_get(struct sysdep_mixer_struct *mixer,
   int channel, int *left, int *right)
{
   int value;
   struct oss_mixer_priv_data *priv = mixer->_priv;
   if(ioctl(priv->fd, (((2U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((oss_mixer_sysdep_to_oss[channel])) << 0) | ((((sizeof(int)))) << ((0 +8)+8))),
      &value))
   {
      perror("error: SOUND_MIXER_READ");
      return -1;
   }
   *left = value & 0xFF;
   *right = (value >> 8) & 0xFF;
   return 0;
}

variable_types: struct sysdep_mixer_struct { int flags; char channel_available[10]; char restore_channel[10]; int cache_left[10]; int cache_right[10]; int orig_left[10]; int orig_right[10]; void *_priv; int (*set)(struct sysdep_mixer_struct *mixer, int channel, int left, int right); int (*get)(struct sysdep_mixer_struct *mixer, int channel, int *left, int *right); void (*destroy)(struct sysdep_mixer_struct *mixer); } *

variable_types: channel int

variable_types:
left
int *

variable_types:
right
int *

variable_types: value int

variable_types: struct oss_mixer_priv_data { int fd; } *


decompiled_code:
int __fastcall oss_mixer_set(__int64 a1, int a2, int a3, int a4)
{
int *v4; // rax
int v5; // esi
int result; // eax
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = *(int **)(a1 + 184);
v5 = oss_mixer_sysdep_to_oss[a2];
v7[0] = a3 | (a4 << 8);
result = ioctl(*v4, v5 | 0xC0044D00, v7);
if ( result )
{
perror("error: SOUND_MIXER_WRITE");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2, int a3, int a4)
{
int *v4; // rax
int v5; // esi
int result; // eax
int v7[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4 = *(int **)(a1 + 184);
v5 = oss_mixer_sysdep_to_oss[a2];
v7[0] = a3 | (a4 << 8);
result = ioctl(*v4, v5 | 0xC0044D00, v7);
if ( result )
{
perror("error: SOUND_MIXER_WRITE");
result = -1;
}
return result;
}

original_code:
static int oss_mixer_set(struct sysdep_mixer_struct *mixer,
   int channel, int left, int right)
{
   int i = left | right << 8;
   struct oss_mixer_priv_data *priv = mixer->_priv;
   if(ioctl(priv->fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((oss_mixer_sysdep_to_oss[channel])) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &i))
   {
      perror("error: SOUND_MIXER_WRITE");
      return -1;
   }
   return 0;
}

variable_types: left int

variable_types: right int

user_defined_types: struct sysdep_mixer_struct { int flags; char channel_available[10]; char restore_channel[10]; int cache_left[10]; int cache_right[10]; int orig_left[10]; int orig_right[10]; void *_priv; int (*set)(struct sysdep_mixer_struct *mixer, int channel, int left, int right); int (*get)(struct sysdep_mixer_struct *mixer, int channel, int *left, int *right); void (*destroy)(struct sysdep_mixer_struct *mixer); }