decompiled_code:
__int64 pro_clk_sched()
{
unsigned int v0; // eax
int v2; // ebx
__int64 v3; // rax
int v4; // edx
int v5; // edx

if ( pro_clk_rs != (pro_clk_csr0 & 0xF) )
{
pro_clk_rs = pro_clk_csr0 & 0xF;
pro_clk_freq = pro_clk_intf[pro_clk_csr0 & 0xF];
v2 = pro_clk_freq;
v3 = pro_time_get();
pro_time_start = bigtime_mul(v3, v4, v2);
dword_7E0 = v5;
pro_clk_numint = 0;
pro_clk_int_cnt = 0;
}
v0 = 327680 / pro_clk_freq;
if ( pro_int_throttle && pro_clk_realtime && pro_clk_numint >= 3 )
v0 = 1000;
return pro_eq_sched(1LL, v0);
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
int v2; // ebx
__int64 v3; // rax
int v4; // edx
int v5; // edx

if ( pro_clk_rs != (pro_clk_csr0 & 0xF) )
{
pro_clk_rs = pro_clk_csr0 & 0xF;
pro_clk_freq = pro_clk_intf[pro_clk_csr0 & 0xF];
v2 = pro_clk_freq;
v3 = func4();
pro_time_start = func2(v3, v4, v2);
dword_7E0 = v5;
pro_clk_numint = 0;
pro_clk_int_cnt = 0;
}
v0 = 327680 / pro_clk_freq;
if ( pro_int_throttle && pro_clk_realtime && pro_clk_numint >= 3 )
v0 = 1000;
return pro_eq_sched(1LL, v0);
}

original_code:
static void pro_clk_sched ()
{
int interval, rs;
 rs = pro_clk_csr0 & 0017;
 if (rs != pro_clk_rs)
 {
   pro_clk_rs = rs;
   pro_clk_freq = pro_clk_intf[pro_clk_rs];
   pro_time_start = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_clk_numint = 0;
   pro_clk_int_cnt = 0;
 }
 interval = (40*8192) / pro_clk_freq;
 if (pro_int_throttle && pro_clk_realtime && (pro_clk_numint > 2))
   interval = 1000;
 pro_eq_sched(1, interval);
}

canonical_original_code:
static void pro_clk_sched()
{
int interval; int rs;
 rs = pro_clk_csr0 & 0017;
 if (rs != pro_clk_rs)
 {
   pro_clk_rs = rs;
   pro_clk_freq = pro_clk_intf[pro_clk_rs];
   pro_time_start = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_clk_numint = 0;
   pro_clk_int_cnt = 0;
 }
 interval = (40*8192) / pro_clk_freq;
 if (pro_int_throttle && pro_clk_realtime && (pro_clk_numint > 2))
   interval = 1000;
 pro_eq_sched(1, interval);
}

variable_types: interval int

variable_types: rs int


repo: CeRiAl/Xhomer

decompiled_code:
__int64 pro_clk_uf_eq()
{
int v0; // eax
__int64 result; // rax

pro_time_update();
pro_clk_csr0 &= 0xFFFFFF7F;
v0 = pro_clk_csr2;
pro_clk_csr2 |= 0x10u;
if ( (pro_clk_csr1 & 0x10) != 0 )
{
LOBYTE(v0) = v0 | 0x90;
pro_clk_csr2 = v0;
pro_int_set(128LL);
}
if ( pro_time_sec == pro_clk_al_sec || (result = (unsigned __int8)pro_clk_al_sec & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_min == pro_clk_al_min || (result = (unsigned __int8)pro_clk_al_min & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_hour == pro_clk_al_hour || (result = (unsigned __int8)pro_clk_al_hour & 0xC0, (_DWORD)result == 192) )
{
result = (unsigned int)pro_clk_csr2;
pro_clk_csr2 |= 0x20u;
if ( (pro_clk_csr1 & 0x20) != 0 )
{
LOBYTE(result) = result | 0xA0;
pro_clk_csr2 = result;
result = pro_int_set(128LL);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
__int64 result; // rax

func3();
pro_clk_csr0 &= 0xFFFFFF7F;
v0 = pro_clk_csr2;
pro_clk_csr2 |= 0x10u;
if ( (pro_clk_csr1 & 0x10) != 0 )
{
LOBYTE(v0) = v0 | 0x90;
pro_clk_csr2 = v0;
pro_int_set(128LL);
}
if ( pro_time_sec == pro_clk_al_sec || (result = (unsigned __int8)pro_clk_al_sec & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_min == pro_clk_al_min || (result = (unsigned __int8)pro_clk_al_min & 0xC0, (_DWORD)result == 192) )
{
if ( pro_time_hour == pro_clk_al_hour || (result = (unsigned __int8)pro_clk_al_hour & 0xC0, (_DWORD)result == 192) )
{
result = (unsigned int)pro_clk_csr2;
pro_clk_csr2 |= 0x20u;
if ( (pro_clk_csr1 & 0x20) != 0 )
{
LOBYTE(result) = result | 0xA0;
pro_clk_csr2 = result;
result = pro_int_set(128LL);
}
}
}
}
return result;
}

original_code:
void pro_clk_uf_eq ()
{
 pro_time_update();
 pro_clk_csr0 = pro_clk_csr0 & ~0200;
 pro_clk_csr2 = pro_clk_csr2 | 0020;
 if ((pro_clk_csr1 & 0020) != 0)
 {
   pro_clk_csr2 = pro_clk_csr2 | 0200;
   pro_int_set(0x0080);
 }
 if (((pro_time_sec == pro_clk_al_sec)
    || ((pro_clk_al_sec & 0300) == 0300))
    && ((pro_time_min == pro_clk_al_min)
    || ((pro_clk_al_min & 0300) == 0300))
    && ((pro_time_hour == pro_clk_al_hour)
    || ((pro_clk_al_hour & 0300) == 0300)))
 {
   pro_clk_csr2 = pro_clk_csr2 | 0040;
   if ((pro_clk_csr1 & 0040) != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0200;
     pro_int_set(0x0080);
   }
 }
}

canonical_original_code:
void pro_clk_uf_eq()
{
 pro_time_update();
 pro_clk_csr0 = pro_clk_csr0 & ~0200;
 pro_clk_csr2 = pro_clk_csr2 | 0020;
 if ((pro_clk_csr1 & 0020) != 0)
 {
   pro_clk_csr2 = pro_clk_csr2 | 0200;
   pro_int_set(0x0080);
 }
 if (((pro_time_sec == pro_clk_al_sec)
    || ((pro_clk_al_sec & 0300) == 0300))
    && ((pro_time_min == pro_clk_al_min)
    || ((pro_clk_al_min & 0300) == 0300))
    && ((pro_time_hour == pro_clk_al_hour)
    || ((pro_clk_al_hour & 0300) == 0300)))
 {
   pro_clk_csr2 = pro_clk_csr2 | 0040;
   if ((pro_clk_csr1 & 0040) != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0200;
     pro_int_set(0x0080);
   }
 }
}

return_type: void


decompiled_code:
__int64 pro_clk_eq()
{
int v0; // ebx
__int64 v1; // rax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // eax

if ( pro_clk_realtime )
{
v0 = pro_clk_freq;
v1 = pro_time_get();
pro_time_current = bigtime_mul(v1, v2, v0);
dword_7D0 = v3;
pro_time_tmp = bigtime_sub(pro_time_current, v3, pro_time_start, dword_7E0);
dword_7C0 = v4;
pro_clk_numint = HIDWORD(pro_time_tmp) + 100000 * pro_time_tmp;
if ( pro_int_throttle && (pro_clk_csr2 & 0x40) != 0 && pro_int_irr < 0
|| HIDWORD(pro_time_tmp) + 100000 * (int)pro_time_tmp <= 0 )
{
return pro_clk_sched();
}
pro_time_start = bigtime_add(pro_time_start, dword_7E0, 100000);
dword_7E0 = v5;
}
else if ( sim_gtime() > 6000000.0 )
{
pro_clk_realtime = 1;
}
if ( pro_clk_rs )
{
v6 = pro_clk_csr2;
pro_clk_csr2 |= 0x40u;
if ( (pro_clk_csr1 & 0x40) != 0 )
{
LOBYTE(v6) = v6 | 0xC0;
pro_clk_csr2 = v6;
pro_int_set(128LL);
}
}
if ( ++pro_clk_int_cnt >= pro_clk_freq )
{
pro_clk_int_cnt = 0;
if ( (pro_clk_csr1 & 0x80u) == 0 )
{
pro_clk_csr0 |= 0x80u;
pro_clk_uf_sched();
}
}
return pro_clk_sched();
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
__int64 v1; // rax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // eax

if ( pro_clk_realtime )
{
v0 = pro_clk_freq;
v1 = func4();
pro_time_current = func2(v1, v2, v0);
dword_7D0 = v3;
pro_time_tmp = func0(pro_time_current, v3, pro_time_start, dword_7E0);
dword_7C0 = v4;
pro_clk_numint = HIDWORD(pro_time_tmp) + 100000 * pro_time_tmp;
if ( pro_int_throttle && (pro_clk_csr2 & 0x40) != 0 && pro_int_irr < 0
|| HIDWORD(pro_time_tmp) + 100000 * (int)pro_time_tmp <= 0 )
{
return func6();
}
pro_time_start = func1(pro_time_start, dword_7E0, 100000);
dword_7E0 = v5;
}
else if ( sim_gtime() > 6000000.0 )
{
pro_clk_realtime = 1;
}
if ( pro_clk_rs )
{
v6 = pro_clk_csr2;
pro_clk_csr2 |= 0x40u;
if ( (pro_clk_csr1 & 0x40) != 0 )
{
LOBYTE(v6) = v6 | 0xC0;
pro_clk_csr2 = v6;
pro_int_set(128LL);
}
}
if ( ++pro_clk_int_cnt >= pro_clk_freq )
{
pro_clk_int_cnt = 0;
if ( (pro_clk_csr1 & 0x80u) == 0 )
{
pro_clk_csr0 |= 0x80u;
func5();
}
}
return func6();
}

original_code:
void pro_clk_eq ()
{
int set_int;
 if (pro_clk_realtime == 0)
 {
   set_int = 1;
   if (sim_gtime() > 6000000)
     pro_clk_realtime = 1;
 }
 else
 {
   pro_time_current = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_time_tmp = bigtime_sub(pro_time_current, pro_time_start);
   pro_clk_numint = pro_time_tmp.hi * 100000 + pro_time_tmp.mid;
   if (pro_int_throttle && ((pro_clk_csr2 & 0100) != 0)
      && ((pro_int_irr[(0x0080 >> 8) & 0377] & (0x0080 & 0377)) != 0))
     set_int = 0;
   else
   if (pro_clk_numint < 1)
     set_int = 0;
   else
   {
     set_int = 1;
     pro_time_start = bigtime_add(pro_time_start, 100000);
   }
 }
 if (set_int == 1)
 {
   if (pro_clk_rs != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0100;
     if ((pro_clk_csr1 & 0100) != 0)
     {
       pro_clk_csr2 = pro_clk_csr2 | 0200;
       pro_int_set(0x0080);
     }
   }
   pro_clk_int_cnt++;
   if (pro_clk_int_cnt >= pro_clk_freq)
   {
     pro_clk_int_cnt = 0;
     if ((pro_clk_csr1 & 0200) == 0)
     {
       pro_clk_csr0 = pro_clk_csr0 | 0200;
       pro_clk_uf_sched ();
     }
   }
 }
 pro_clk_sched();
}

canonical_original_code:
void pro_clk_eq()
{
int set_int;
 if (pro_clk_realtime == 0)
 {
   set_int = 1;
   if (sim_gtime() > 6000000)
     pro_clk_realtime = 1;
 }
 else
 {
   pro_time_current = bigtime_mul(pro_time_get(), pro_clk_freq);
   pro_time_tmp = bigtime_sub(pro_time_current, pro_time_start);
   pro_clk_numint = pro_time_tmp.hi * 100000 + pro_time_tmp.mid;
   if (pro_int_throttle && ((pro_clk_csr2 & 0100) != 0)
      && ((pro_int_irr[(0x0080 >> 8) & 0377] & (0x0080 & 0377)) != 0))
     set_int = 0;
   else
   if (pro_clk_numint < 1)
     set_int = 0;
   else
   {
     set_int = 1;
     pro_time_start = bigtime_add(pro_time_start, 100000);
   }
 }
 if (set_int == 1)
 {
   if (pro_clk_rs != 0)
   {
     pro_clk_csr2 = pro_clk_csr2 | 0100;
     if ((pro_clk_csr1 & 0100) != 0)
     {
       pro_clk_csr2 = pro_clk_csr2 | 0200;
       pro_int_set(0x0080);
     }
   }
   pro_clk_int_cnt++;
   if (pro_clk_int_cnt >= pro_clk_freq)
   {
     pro_clk_int_cnt = 0;
     if ((pro_clk_csr1 & 0200) == 0)
     {
       pro_clk_csr0 = pro_clk_csr0 | 0200;
       pro_clk_uf_sched ();
     }
   }
 }
 pro_clk_sched();
}


decompiled_code:
__int64 __fastcall pro_clk_rd(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // edx

switch ( a1 & 0x3FFFFE )
{
case 0x3FF600:
result = (unsigned int)pro_time_sec;
break;
case 0x3FF602:
result = (unsigned int)pro_clk_al_sec;
break;
case 0x3FF604:
result = (unsigned int)pro_time_min;
break;
case 0x3FF606:
result = (unsigned int)pro_clk_al_min;
break;
case 0x3FF608:
result = (unsigned int)pro_time_hour;
break;
case 0x3FF60A:
result = (unsigned int)pro_clk_al_hour;
break;
case 0x3FF60C:
result = (unsigned int)(*(_DWORD *)(pro_time + 24) + 1);
break;
case 0x3FF60E:
result = *(unsigned int *)(pro_time + 12);
break;
case 0x3FF610:
result = (unsigned int)(*(_DWORD *)(pro_time + 16) + 1);
break;
case 0x3FF612:
result = (unsigned int)pro_force_year;
if ( pro_force_year < 0 )
result = (unsigned int)(*(_DWORD *)(pro_time + 20) % 100);
break;
case 0x3FF614:
result = (unsigned int)pro_clk_csr0;
break;
case 0x3FF616:
result = (unsigned int)pro_clk_csr1;
break;
case 0x3FF618:
result = (unsigned int)pro_clk_csr2;
v2 = pro_clk_csr2;
LOBYTE(v2) = pro_clk_csr2 & 0xF;
pro_clk_csr2 = v2;
break;
case 0x3FF61A:
result = (unsigned int)pro_clk_csr3;
v3 = pro_clk_csr3;
LOBYTE(v3) = pro_clk_csr3 | 0x80;
pro_clk_csr3 = v3;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 result; // rax
int v2; // edx
int v3; // edx

switch ( a1 & 0x3FFFFE )
{
case 0x3FF600:
result = (unsigned int)pro_time_sec;
break;
case 0x3FF602:
result = (unsigned int)pro_clk_al_sec;
break;
case 0x3FF604:
result = (unsigned int)pro_time_min;
break;
case 0x3FF606:
result = (unsigned int)pro_clk_al_min;
break;
case 0x3FF608:
result = (unsigned int)pro_time_hour;
break;
case 0x3FF60A:
result = (unsigned int)pro_clk_al_hour;
break;
case 0x3FF60C:
result = (unsigned int)(*(_DWORD *)(pro_time + 24) + 1);
break;
case 0x3FF60E:
result = *(unsigned int *)(pro_time + 12);
break;
case 0x3FF610:
result = (unsigned int)(*(_DWORD *)(pro_time + 16) + 1);
break;
case 0x3FF612:
result = (unsigned int)pro_force_year;
if ( pro_force_year < 0 )
result = (unsigned int)(*(_DWORD *)(pro_time + 20) % 100);
break;
case 0x3FF614:
result = (unsigned int)pro_clk_csr0;
break;
case 0x3FF616:
result = (unsigned int)pro_clk_csr1;
break;
case 0x3FF618:
result = (unsigned int)pro_clk_csr2;
v2 = pro_clk_csr2;
LOBYTE(v2) = pro_clk_csr2 & 0xF;
pro_clk_csr2 = v2;
break;
case 0x3FF61A:
result = (unsigned int)pro_clk_csr3;
v3 = pro_clk_csr3;
LOBYTE(v3) = pro_clk_csr3 | 0x80;
pro_clk_csr3 = v3;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int pro_clk_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017773000:
     data = pro_time_sec;
     break;
   case 017773002:
     data = pro_clk_al_sec;
     break;
   case 017773004:
     data = pro_time_min;
     break;
   case 017773006:
     data = pro_clk_al_min;
     break;
   case 017773010:
     data = pro_time_hour;
     break;
   case 017773012:
     data = pro_clk_al_hour;
     break;
   case 017773014:
     data = pro_time->tm_wday + 1;
     break;
   case 017773016:
     data = pro_time->tm_mday;
     break;
   case 017773020:
     data = pro_time->tm_mon + 1;
     break;
   case 017773022:
     if (pro_force_year > -1)
       data = pro_force_year;
     else
       data = pro_time->tm_year % 100;
     break;
   case 017773024:
     data = pro_clk_csr0;
     break;
   case 017773026:
     data = pro_clk_csr1;
     break;
   case 017773030:
     data = pro_clk_csr2;
     pro_clk_csr2 = pro_clk_csr2 & ~(0200 | 0100
                                    | 0040 | 0020);
     break;
   case 017773032:
     data = pro_clk_csr3;
     pro_clk_csr3 = pro_clk_csr3 | 0200;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_clk_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017773000:
     data = pro_time_sec;
     break;
   case 017773002:
     data = pro_clk_al_sec;
     break;
   case 017773004:
     data = pro_time_min;
     break;
   case 017773006:
     data = pro_clk_al_min;
     break;
   case 017773010:
     data = pro_time_hour;
     break;
   case 017773012:
     data = pro_clk_al_hour;
     break;
   case 017773014:
     data = pro_time->tm_wday + 1;
     break;
   case 017773016:
     data = pro_time->tm_mday;
     break;
   case 017773020:
     data = pro_time->tm_mon + 1;
     break;
   case 017773022:
     if (pro_force_year > -1)
       data = pro_force_year;
     else
       data = pro_time->tm_year % 100;
     break;
   case 017773024:
     data = pro_clk_csr0;
     break;
   case 017773026:
     data = pro_clk_csr1;
     break;
   case 017773030:
     data = pro_clk_csr2;
     pro_clk_csr2 = pro_clk_csr2 & ~(0200 | 0100
                                    | 0040 | 0020);
     break;
   case 017773032:
     data = pro_clk_csr3;
     pro_clk_csr3 = pro_clk_csr3 | 0200;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

variable_types: pa int

variable_types: data int

return_type: int


decompiled_code:
char __fastcall pro_clk_wr(unsigned __int8 a1, int a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = (a2 & 0xFE) - 2;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF602:
if ( a3 == 4 )
{
v3 = pro_clk_al_sec;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_al_sec = v3;
}
else
{
v3 = pro_clk_al_sec;
LOBYTE(v3) = 0;
pro_clk_al_sec = v3 | a1;
}
break;
case 0x3FF606:
if ( a3 == 4 )
{
v3 = pro_clk_al_min;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_al_min = v3;
}
else
{
v3 = pro_clk_al_min;
LOBYTE(v3) = 0;
pro_clk_al_min = v3 | a1;
}
break;
case 0x3FF60A:
if ( a3 == 4 )
{
v3 = pro_clk_al_hour;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_al_hour = v3;
}
else
{
v3 = pro_clk_al_hour;
LOBYTE(v3) = 0;
pro_clk_al_hour = v3 | a1;
}
break;
case 0x3FF614:
if ( a3 == 4 )
{
v3 = pro_clk_csr0;
if ( (a2 & 1) == 0 )
v3 = a1 & 0x7F | pro_clk_csr0 & 0xFFFFFF80;
pro_clk_csr0 = v3;
}
else
{
LOBYTE(v3) = pro_clk_csr0 & 0x80;
pro_clk_csr0 = pro_clk_csr0 & 0xFFFFFF80 | a1 & 0x7F;
}
break;
case 0x3FF616:
if ( a3 == 4 )
{
v3 = pro_clk_csr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_csr1 = v3;
}
else
{
v3 = pro_clk_csr1;
LOBYTE(v3) = 0;
pro_clk_csr1 = v3 | a1;
}
break;
default:
return v3;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func10(unsigned __int8 a1, int a2, int a3)
{
unsigned int v3; // eax

LOBYTE(v3) = (a2 & 0xFE) - 2;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF602:
if ( a3 == 4 )
{
v3 = pro_clk_al_sec;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_al_sec = v3;
}
else
{
v3 = pro_clk_al_sec;
LOBYTE(v3) = 0;
pro_clk_al_sec = v3 | a1;
}
break;
case 0x3FF606:
if ( a3 == 4 )
{
v3 = pro_clk_al_min;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_al_min = v3;
}
else
{
v3 = pro_clk_al_min;
LOBYTE(v3) = 0;
pro_clk_al_min = v3 | a1;
}
break;
case 0x3FF60A:
if ( a3 == 4 )
{
v3 = pro_clk_al_hour;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_al_hour = v3;
}
else
{
v3 = pro_clk_al_hour;
LOBYTE(v3) = 0;
pro_clk_al_hour = v3 | a1;
}
break;
case 0x3FF614:
if ( a3 == 4 )
{
v3 = pro_clk_csr0;
if ( (a2 & 1) == 0 )
v3 = a1 & 0x7F | pro_clk_csr0 & 0xFFFFFF80;
pro_clk_csr0 = v3;
}
else
{
LOBYTE(v3) = pro_clk_csr0 & 0x80;
pro_clk_csr0 = pro_clk_csr0 & 0xFFFFFF80 | a1 & 0x7F;
}
break;
case 0x3FF616:
if ( a3 == 4 )
{
v3 = pro_clk_csr1;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = 0;
v3 |= a1;
}
pro_clk_csr1 = v3;
}
else
{
v3 = pro_clk_csr1;
LOBYTE(v3) = 0;
pro_clk_csr1 = v3 | a1;
}
break;
default:
return v3;
}
return v3;
}

variable_types: access int


decompiled_code:
__int64 pro_clk_reset()
{
pro_clk_csr0 = 0;
pro_clk_csr1 = 6;
pro_clk_csr2 = 0;
pro_clk_csr3 = 128;
pro_clk_al_sec = 0;
pro_clk_al_min = 0;
pro_clk_al_hour = 0;
pro_clk_realtime = 0;
pro_clk_numint = 0;
pro_clk_freq = 0;
pro_clk_int_cnt = 0;
pro_time_start = 0LL;
dword_7E0 = 0;
pro_time_current = 0LL;
dword_7D0 = 0;
pro_time_update();
pro_clk_rs = -1;
return pro_clk_sched();
}

canonical_decompiled_code:
__int64 func11()
{
pro_clk_csr0 = 0;
pro_clk_csr1 = 6;
pro_clk_csr2 = 0;
pro_clk_csr3 = 128;
pro_clk_al_sec = 0;
pro_clk_al_min = 0;
pro_clk_al_hour = 0;
pro_clk_realtime = 0;
pro_clk_numint = 0;
pro_clk_freq = 0;
pro_clk_int_cnt = 0;
pro_time_start = 0LL;
dword_7E0 = 0;
pro_time_current = 0LL;
dword_7D0 = 0;
func3();
pro_clk_rs = -1;
return func6();
}

original_code:
void pro_clk_reset ()
{
 pro_clk_csr0 = 0000;
 pro_clk_csr1 = 0004 | 0002;
 pro_clk_csr2 = 0000;
 pro_clk_csr3 = 0200;
 pro_clk_al_sec = 0;
 pro_clk_al_min = 0;
 pro_clk_al_hour = 0;
 pro_clk_realtime = 0;
 pro_clk_numint = 0;
 pro_clk_freq = 0;
 pro_clk_int_cnt = 0;
 pro_time_start.hi = 0;
 pro_time_start.mid = 0;
 pro_time_start.lo = 0;
 pro_time_current.hi = 0;
 pro_time_current.mid = 0;
 pro_time_current.lo = 0;
 pro_time_update();
 pro_clk_rs = -1;
 pro_clk_sched();
}

canonical_original_code:
void pro_clk_reset()
{
 pro_clk_csr0 = 0000;
 pro_clk_csr1 = 0004 | 0002;
 pro_clk_csr2 = 0000;
 pro_clk_csr3 = 0200;
 pro_clk_al_sec = 0;
 pro_clk_al_min = 0;
 pro_clk_al_hour = 0;
 pro_clk_realtime = 0;
 pro_clk_numint = 0;
 pro_clk_freq = 0;
 pro_clk_int_cnt = 0;
 pro_time_start.hi = 0;
 pro_time_start.mid = 0;
 pro_time_start.lo = 0;
 pro_time_current.hi = 0;
 pro_time_current.mid = 0;
 pro_time_current.lo = 0;
 pro_time_update();
 pro_clk_rs = -1;
 pro_clk_sched();
}


decompiled_code:
__int64 pro_null_get()
{
return 256LL;
}

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

original_code:
int pro_null_get (int dev)
{
 return 256;
}

canonical_original_code:
int pro_null_get(int dev)
{
 return 256;
}

variable_types: dev int


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

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

original_code:
int pro_null_put (int dev, int schar)
{
 return 1;
}

canonical_original_code:
int pro_null_put(int dev, int schar)
{
 return 1;
}

variable_types: schar int


decompiled_code:
void pro_null_ctrl_put()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void pro_null_ctrl_put (int dev, struct serctrl *sctrl)
{
}

canonical_original_code:
void pro_null_ctrl_put(int dev, struct serctrl *sctrl)
{
}

variable_types: struct serctrl { int stop; int parity; int penable; int cs; int ibaud; int obaud; int dtr; int dsr; int rts; int cts; int ri; int cd; int ibrk; int obrk; int perror; } *


decompiled_code:
void pro_null_reset()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void pro_null_reset (int dev, int portnum)
{
}

canonical_original_code:
void pro_null_reset(int dev, int portnum)
{
}

variable_types: portnum int


decompiled_code:
void pro_null_exit()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void pro_null_exit (int dev)
{
}

canonical_original_code:
void pro_null_exit(int dev)
{
}


decompiled_code:
__int64 __fastcall pro_lk201_fifo_put(int a1)
{
int v1; // edx
__int64 result; // rax

v1 = pro_lk201_fifo_h;
pro_lk201_fifo[pro_lk201_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 1023 )
result = 0LL;
pro_lk201_fifo_h = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // edx
__int64 result; // rax

v1 = pro_lk201_fifo_h;
pro_lk201_fifo[pro_lk201_fifo_h] = a1;
result = (unsigned int)(v1 + 1);
if ( v1 == 1023 )
result = 0LL;
pro_lk201_fifo_h = result;
return result;
}

original_code:
static void pro_lk201_fifo_put (int key)
{
 pro_lk201_fifo[pro_lk201_fifo_h] = key;
 pro_lk201_fifo_h++;
 if (pro_lk201_fifo_h == 1024)
   pro_lk201_fifo_h = 0;
}

canonical_original_code:
static void pro_lk201_fifo_put(int key)
{
 pro_lk201_fifo[pro_lk201_fifo_h] = key;
 pro_lk201_fifo_h++;
 if (pro_lk201_fifo_h == 1024)
   pro_lk201_fifo_h = 0;
}

variable_types: key int


decompiled_code:
__int64 pro_lk201_fifo_get()
{
unsigned int v0; // ecx
int v1; // eax

v0 = 256;
if ( pro_lk201_fifo_h != pro_lk201_fifo_t )
{
v0 = pro_lk201_fifo[pro_lk201_fifo_t];
v1 = 0;
if ( pro_lk201_fifo_t != 1023 )
v1 = pro_lk201_fifo_t + 1;
pro_lk201_fifo_t = v1;
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ecx
int v1; // eax

v0 = 256;
if ( pro_lk201_fifo_h != pro_lk201_fifo_t )
{
v0 = pro_lk201_fifo[pro_lk201_fifo_t];
v1 = 0;
if ( pro_lk201_fifo_t != 1023 )
v1 = pro_lk201_fifo_t + 1;
pro_lk201_fifo_t = v1;
}
return v0;
}

original_code:
static int pro_lk201_fifo_get ()
{
 int key;
 if (pro_lk201_fifo_h == pro_lk201_fifo_t)
   key = 256;
 else
 {
   key = pro_lk201_fifo[pro_lk201_fifo_t];
   pro_lk201_fifo_t++;
   if (pro_lk201_fifo_t == 1024)
     pro_lk201_fifo_t = 0;
 }
 return key;
}

canonical_original_code:
static int pro_lk201_fifo_get()
{
 int key;
 if (pro_lk201_fifo_h == pro_lk201_fifo_t)
   key = 256;
 else
 {
   key = pro_lk201_fifo[pro_lk201_fifo_t];
   pro_lk201_fifo_t++;
   if (pro_lk201_fifo_t == 1024)
     pro_lk201_fifo_t = 0;
 }
 return key;
}


decompiled_code:
void __fastcall pro_lk201_ctrl_get(__int64 a1, __int64 a2)
{
*(_DWORD *)(a2 + 28) = 1;
}

original_code:
void pro_lk201_ctrl_get (int dev, struct serctrl *sctrl)
{
 sctrl->dsr = 1;
}

canonical_original_code:
void pro_lk201_ctrl_get(int dev, struct serctrl *sctrl)
{
 sctrl->dsr = 1;
}

user_defined_types: struct serctrl { int stop; int parity; int penable; int cs; int ibaud; int obaud; int dtr; int dsr; int rts; int cts; int ri; int cd; int ibrk; int obrk; int perror; }


decompiled_code:
void pro_lk201_ctrl_put()
{
;
}

original_code:
void pro_lk201_ctrl_put (int dev, struct serctrl *sctrl)
{
}

canonical_original_code:
void pro_lk201_ctrl_put(int dev, struct serctrl *sctrl)
{
}


decompiled_code:
void pro_lk201_reset()
{
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
pro_lk201_locked = 0;
pro_lk201_bell_dis = 0;
pro_lk201_param = 0;
pro_lk201_last_cmd = -1;
pro_lk201_fifo_h = 0;
pro_lk201_fifo_t = 0;
}

canonical_decompiled_code:
void func4()
{
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
pro_lk201_locked = 0;
pro_lk201_bell_dis = 0;
pro_lk201_param = 0;
pro_lk201_last_cmd = -1;
pro_lk201_fifo_h = 0;
pro_lk201_fifo_t = 0;
}

original_code:
void pro_lk201_reset (int dev, int portnum)
{
 pro_lk201_shift = 0;
 pro_lk201_ctrl = 0;
 pro_lk201_locked = 0;
 pro_lk201_bell_dis = 0;
 pro_lk201_click_dis = 0;
 pro_lk201_param = 0;
 pro_lk201_last_cmd = -1;
 pro_lk201_fifo_h = 0;
 pro_lk201_fifo_t = 0;
}

canonical_original_code:
void pro_lk201_reset(int dev, int portnum)
{
 pro_lk201_shift = 0;
 pro_lk201_ctrl = 0;
 pro_lk201_locked = 0;
 pro_lk201_bell_dis = 0;
 pro_lk201_click_dis = 0;
 pro_lk201_param = 0;
 pro_lk201_last_cmd = -1;
 pro_lk201_fifo_h = 0;
 pro_lk201_fifo_t = 0;
}


decompiled_code:
void pro_lk201_exit()
{
;
}

original_code:
void pro_lk201_exit (int dev)
{
}

canonical_original_code:
void pro_lk201_exit(int dev)
{
}


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

result = 256LL;
if ( !pro_lk201_locked )
{
result = pro_lk201_fifo_get();
if ( (_DWORD)result == 256 )
{
result = pro_keyboard_get();
if ( (_DWORD)result != 256 )
{
switch ( (_DWORD)result )
{
case 0xAE:
pro_lk201_shift = 1;
break;
case 0xAF:
pro_lk201_ctrl = 1;
break;
case 0xB3:
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
break;
case 0xED:
if ( pro_lk201_shift == 1 )
result = 201LL;
break;
case 0xE8:
if ( pro_lk201_shift == 1 )
{
pro_lk201_fifo_put(201);
pro_lk201_fifo_put(174);
result = 179LL;
}
break;
case 0x57:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(161);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x59:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(162);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x5A:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(163);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x58:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(164);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x64:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(128);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x65:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(129);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
case 0x66:
if ( pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(130);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
default:
if ( (_DWORD)result == 103 && pro_lk201_ctrl == 1 )
{
pro_lk201_fifo_put(131);
pro_lk201_fifo_put(175);
result = 179LL;
}
break;
}
}
}
}
return result;
}

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

result = 256LL;
if ( !pro_lk201_locked )
{
result = func1();
if ( (_DWORD)result == 256 )
{
result = pro_keyboard_get();
if ( (_DWORD)result != 256 )
{
switch ( (_DWORD)result )
{
case 0xAE:
pro_lk201_shift = 1;
break;
case 0xAF:
pro_lk201_ctrl = 1;
break;
case 0xB3:
pro_lk201_shift = 0;
pro_lk201_ctrl = 0;
break;
case 0xED:
if ( pro_lk201_shift == 1 )
result = 201LL;
break;
case 0xE8:
if ( pro_lk201_shift == 1 )
{
func0(201);
func0(174);
result = 179LL;
}
break;
case 0x57:
if ( pro_lk201_ctrl == 1 )
{
func0(161);
func0(175);
result = 179LL;
}
break;
case 0x59:
if ( pro_lk201_ctrl == 1 )
{
func0(162);
func0(175);
result = 179LL;
}
break;
case 0x5A:
if ( pro_lk201_ctrl == 1 )
{
func0(163);
func0(175);
result = 179LL;
}
break;
case 0x58:
if ( pro_lk201_ctrl == 1 )
{
func0(164);
func0(175);
result = 179LL;
}
break;
case 0x64:
if ( pro_lk201_ctrl == 1 )
{
func0(128);
func0(175);
result = 179LL;
}
break;
case 0x65:
if ( pro_lk201_ctrl == 1 )
{
func0(129);
func0(175);
result = 179LL;
}
break;
case 0x66:
if ( pro_lk201_ctrl == 1 )
{
func0(130);
func0(175);
result = 179LL;
}
break;
default:
if ( (_DWORD)result == 103 && pro_lk201_ctrl == 1 )
{
func0(131);
func0(175);
result = 179LL;
}
break;
}
}
}
}
return result;
}


decompiled_code:
__int64 __fastcall pro_lk201_put(__int64 a1, int a2)
{
if ( !pro_lk201_param )
{
pro_lk201_last_cmd = -1;
if ( a2 > 171 )
{
if ( a2 == 253 )
{
pro_lk201_fifo_put(1);
pro_lk201_fifo_put(0);
pro_lk201_fifo_put(0);
pro_lk201_fifo_put(0);
goto LABEL_26;
}
if ( a2 <= 253 )
{
if ( a2 == 225 )
{
pro_keyboard_auto_off();
goto LABEL_26;
}
if ( a2 == 227 )
{
pro_keyboard_auto_on();
goto LABEL_26;
}
}
else if ( a2 == 254 )
{
pro_lk201_fifo_put(182);
goto LABEL_26;
}
}
else
{
if ( a2 > 136 )
{
switch ( a2 )
{
case 137:
pro_lk201_locked = 1;
pro_lk201_fifo_put(183);
break;
case 139:
pro_lk201_locked = 0;
break;
case 153:
pro_keyboard_click_off();
break;
case 161:
pro_lk201_bell_dis = 1;
break;
case 167:
if ( !pro_lk201_bell_dis )
pro_keyboard_bell();
break;
case 171:
pro_lk201_fifo_put(1);
pro_lk201_fifo_put(0);
break;
default:
goto LABEL_23;
}
goto LABEL_26;
}
if ( a2 == 27 )
{
pro_keyboard_click_on();
goto LABEL_26;
}
}
LABEL_23:
pro_lk201_last_cmd = a2;
goto LABEL_26;
}
if ( pro_lk201_last_cmd == 35 )
{
pro_lk201_bell_dis = 0;
pro_keyboard_bell_vol(a2 & 7);
pro_lk201_last_cmd = -1;
}
LABEL_26:
pro_lk201_param = (a2 & 0x80u) == 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
if ( !pro_lk201_param )
{
pro_lk201_last_cmd = -1;
if ( a2 > 171 )
{
if ( a2 == 253 )
{
func0(1);
func0(0);
func0(0);
func0(0);
goto LABEL_26;
}
if ( a2 <= 253 )
{
if ( a2 == 225 )
{
pro_keyboard_auto_off();
goto LABEL_26;
}
if ( a2 == 227 )
{
pro_keyboard_auto_on();
goto LABEL_26;
}
}
else if ( a2 == 254 )
{
func0(182);
goto LABEL_26;
}
}
else
{
if ( a2 > 136 )
{
switch ( a2 )
{
case 137:
pro_lk201_locked = 1;
func0(183);
break;
case 139:
pro_lk201_locked = 0;
break;
case 153:
pro_keyboard_click_off();
break;
case 161:
pro_lk201_bell_dis = 1;
break;
case 167:
if ( !pro_lk201_bell_dis )
pro_keyboard_bell();
break;
case 171:
func0(1);
func0(0);
break;
default:
goto LABEL_23;
}
goto LABEL_26;
}
if ( a2 == 27 )
{
pro_keyboard_click_on();
goto LABEL_26;
}
}
LABEL_23:
pro_lk201_last_cmd = a2;
goto LABEL_26;
}
if ( pro_lk201_last_cmd == 35 )
{
pro_lk201_bell_dis = 0;
pro_keyboard_bell_vol(a2 & 7);
pro_lk201_last_cmd = -1;
}
LABEL_26:
pro_lk201_param = (a2 & 0x80u) == 0;
return 1LL;
}

original_code:
int pro_lk201_put (int dev, int key)
{
 if (pro_lk201_param == 0)
 {
   pro_lk201_last_cmd = -1;
   switch(key)
   {
     case 139:
       pro_lk201_locked = 0;
       break;
     case 137:
       pro_lk201_locked = 1;
       pro_lk201_fifo_put(183);
       break;
     case 27:
       pro_lk201_click_dis = 0;
       pro_keyboard_click_on();
       break;
     case 153:
       pro_lk201_click_dis = 1;
       pro_keyboard_click_off();
       break;
     case 161:
       pro_lk201_bell_dis = 1;
       break;
     case 167:
       if (pro_lk201_bell_dis == 0)
         pro_keyboard_bell();
       break;
     case 225:
       pro_keyboard_auto_off();
       break;
     case 227:
       pro_keyboard_auto_on();
       break;
     case 171:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       break;
     case 253:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       break;
     case 254:
       pro_lk201_fifo_put(0xb6);
       break;
     default:
       pro_lk201_last_cmd = key;
       break;
   }
 }
 else
 {
   switch(pro_lk201_last_cmd)
   {
     case 35:
       pro_lk201_bell_dis = 0;
       pro_keyboard_bell_vol(key & 0x07);
       pro_lk201_last_cmd = -1;
       break;
     default:
       break;
   }
 }
 if ((key & 0x80) != 0)
   pro_lk201_param = 0;
 else
   pro_lk201_param = 1;
 return 1;
}

canonical_original_code:
int pro_lk201_put(int dev, int key)
{
 if (pro_lk201_param == 0)
 {
   pro_lk201_last_cmd = -1;
   switch(key)
   {
     case 139:
       pro_lk201_locked = 0;
       break;
     case 137:
       pro_lk201_locked = 1;
       pro_lk201_fifo_put(183);
       break;
     case 27:
       pro_lk201_click_dis = 0;
       pro_keyboard_click_on();
       break;
     case 153:
       pro_lk201_click_dis = 1;
       pro_keyboard_click_off();
       break;
     case 161:
       pro_lk201_bell_dis = 1;
       break;
     case 167:
       if (pro_lk201_bell_dis == 0)
         pro_keyboard_bell();
       break;
     case 225:
       pro_keyboard_auto_off();
       break;
     case 227:
       pro_keyboard_auto_on();
       break;
     case 171:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       break;
     case 253:
       pro_lk201_fifo_put(1);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       pro_lk201_fifo_put(0);
       break;
     case 254:
       pro_lk201_fifo_put(0xb6);
       break;
     default:
       pro_lk201_last_cmd = key;
       break;
   }
 }
 else
 {
   switch(pro_lk201_last_cmd)
   {
     case 35:
       pro_lk201_bell_dis = 0;
       pro_keyboard_bell_vol(key & 0x07);
       pro_lk201_last_cmd = -1;
       break;
     default:
       break;
   }
 }
 if ((key & 0x80) != 0)
   pro_lk201_param = 0;
 else
   pro_lk201_param = 1;
 return 1;
}


decompiled_code:
__int64 __fastcall pro_digipad_fifo_put(int a1)
{
__int64 result; // rax
unsigned int v2; // edx
bool v3; // zf

result = (unsigned int)pro_digipad_fifo_h;
if ( pro_digipad_fifo_h - pro_digipad_fifo_t <= 1023 )
{
pro_digipad_fifo[pro_digipad_fifo_h] = a1;
v2 = result + 1;
v3 = (_DWORD)result == 1023;
result = 0LL;
if ( !v3 )
result = v2;
pro_digipad_fifo_h = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
unsigned int v2; // edx
bool v3; // zf

result = (unsigned int)pro_digipad_fifo_h;
if ( pro_digipad_fifo_h - pro_digipad_fifo_t <= 1023 )
{
pro_digipad_fifo[pro_digipad_fifo_h] = a1;
v2 = result + 1;
v3 = (_DWORD)result == 1023;
result = 0LL;
if ( !v3 )
result = v2;
pro_digipad_fifo_h = result;
}
return result;
}

original_code:
static void pro_digipad_fifo_put (int schar)
{
int fullness;
 fullness = pro_digipad_fifo_h - pro_digipad_fifo_t;
 if (fullness < 0)
   fullness += 1024;
 if (fullness < 1024)
 {
   pro_digipad_fifo[pro_digipad_fifo_h] = schar;
   pro_digipad_fifo_h++;
   if (pro_digipad_fifo_h == 1024)
     pro_digipad_fifo_h = 0;
 }
}

canonical_original_code:
static void pro_digipad_fifo_put(int schar)
{
int fullness;
 fullness = pro_digipad_fifo_h - pro_digipad_fifo_t;
 if (fullness < 0)
   fullness += 1024;
 if (fullness < 1024)
 {
   pro_digipad_fifo[pro_digipad_fifo_h] = schar;
   pro_digipad_fifo_h++;
   if (pro_digipad_fifo_h == 1024)
     pro_digipad_fifo_h = 0;
 }
}

variable_types: fullness int


decompiled_code:
void pro_digipad_ctrl_put()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void pro_digipad_ctrl_put (int dev, struct serctrl *sctrl)
{
}

canonical_original_code:
void pro_digipad_ctrl_put(int dev, struct serctrl *sctrl)
{
}


decompiled_code:
void pro_digipad_reset()
{
;
}

original_code:
void pro_digipad_reset (int dev, int portnum)
{
}

canonical_original_code:
void pro_digipad_reset(int dev, int portnum)
{
}


decompiled_code:
void pro_digipad_exit()
{
;
}

original_code:
void pro_digipad_exit (int dev)
{
}

canonical_original_code:
void pro_digipad_exit(int dev)
{
}


decompiled_code:
__int64 pro_digipad_coord()
{
int v0; // eax
int v1; // ebx
int v2; // edi
int v3; // ebp

if ( pro_digipad_remote )
{
v0 = 2 * pro_mouse_x - 64;
v1 = 2 * (600 * pro_mouse_y / -240) + 2100;
}
else
{
v0 = 2200 * (pro_mouse_x - 32) / 960;
v1 = 1375 * pro_mouse_y / -240 + 2200;
}
v2 = pro_mouse_l == 0 ? 64 : 96;
if ( pro_mouse_m )
v2 = (pro_mouse_l == 0 ? 64 : 96) | 0x10;
if ( pro_mouse_r )
v2 |= 8u;
v3 = pro_mouse_in;
if ( pro_mouse_in )
{
v3 = 0;
if ( v0 >= 0 )
v3 = v0;
}
else
{
v2 |= 4u;
v1 = pro_mouse_in;
}
LOBYTE(v2) = v2 | 0x80;
pro_digipad_fifo_put(v2);
pro_digipad_fifo_put(v3 & 0x3F | 0x80);
pro_digipad_fifo_put((v3 >> 6) & 0x3F | 0x80);
pro_digipad_fifo_put(v1 & 0x3F | 0x80);
return pro_digipad_fifo_put((v1 >> 6) & 0x3F | 0x80u);
}

original_code:
void pro_digipad_coord ()
{
int mb, tx, ty;
 if (pro_digipad_remote)
 {
   tx = 2*(pro_mouse_x-32);
   ty = 2100 - 2*(600*pro_mouse_y/240);
 }
 else
 {
   tx = (2200*(pro_mouse_x-32))/960;
   ty = 2200 - (600*2200*pro_mouse_y/960)/240;
 }
 if (tx < 0)
   tx = 0;
 mb = 0x40;
 if (pro_mouse_l)
   mb |= 0x20;
 if (pro_mouse_m)
   mb |= 0x10;
 if (pro_mouse_r)
   mb |= 0x08;
 if (!pro_mouse_in)
 {
   mb |= 0x04;
   tx = 0;
   ty = 0;
 }
 pro_digipad_fifo_put(mb|0x80);
 pro_digipad_fifo_put((tx&0x3f)|0x80);
 pro_digipad_fifo_put(((tx>>6)&0x3f)|0x80);
 pro_digipad_fifo_put((ty&0x3f)|0x80);
 pro_digipad_fifo_put(((ty>>6)&0x3f)|0x80);
}

canonical_original_code:
void pro_digipad_coord()
{
int mb; int tx; int ty;
 if (pro_digipad_remote)
 {
   tx = 2*(pro_mouse_x-32);
   ty = 2100 - 2*(600*pro_mouse_y/240);
 }
 else
 {
   tx = (2200*(pro_mouse_x-32))/960;
   ty = 2200 - (600*2200*pro_mouse_y/960)/240;
 }
 if (tx < 0)
   tx = 0;
 mb = 0x40;
 if (pro_mouse_l)
   mb |= 0x20;
 if (pro_mouse_m)
   mb |= 0x10;
 if (pro_mouse_r)
   mb |= 0x08;
 if (!pro_mouse_in)
 {
   mb |= 0x04;
   tx = 0;
   ty = 0;
 }
 pro_digipad_fifo_put(mb|0x80);
 pro_digipad_fifo_put((tx&0x3f)|0x80);
 pro_digipad_fifo_put(((tx>>6)&0x3f)|0x80);
 pro_digipad_fifo_put((ty&0x3f)|0x80);
 pro_digipad_fifo_put(((ty>>6)&0x3f)|0x80);
}

variable_types: mb int

variable_types: tx int

variable_types: ty int


decompiled_code:
__int64 __fastcall pro_digipad_get(__int64 a1, __int64 a2)
{
unsigned int v2; // edx
int v3; // eax
int v4; // ecx
bool v5; // zf
int v6; // eax

if ( !pro_digipad_suppressed )
{
v3 = pro_digipad_fifo_t;
v2 = 256;
if ( pro_digipad_fifo_h == pro_digipad_fifo_t )
return v2;
if ( !pro_digipad_enable )
return 256;
goto LABEL_15;
}
v2 = 256;
if ( pro_digipad_enable )
{
if ( pro_mouse_x != pro_digipad_last_x
|| pro_mouse_y != pro_digipad_last_y
|| pro_mouse_l != pro_digipad_last_l
|| pro_mouse_m != pro_digipad_last_m
|| pro_mouse_r != pro_digipad_last_r
|| pro_mouse_in != pro_digipad_last_in )
{
pro_digipad_coord(a1, a2, 256LL);
pro_digipad_last_x = pro_mouse_x;
pro_digipad_last_y = pro_mouse_y;
pro_digipad_last_l = pro_mouse_l;
pro_digipad_last_m = pro_mouse_m;
pro_digipad_last_r = pro_mouse_r;
pro_digipad_last_in = pro_mouse_in;
}
v3 = pro_digipad_fifo_t;
v2 = 256;
if ( pro_digipad_fifo_h != pro_digipad_fifo_t )
{
LABEL_15:
v2 = pro_digipad_fifo[v3];
v4 = v3 + 1;
v5 = v3 == 1023;
v6 = 0;
if ( !v5 )
v6 = v4;
pro_digipad_fifo_t = v6;
return v2;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned int v2; // edx
int v3; // eax
int v4; // ecx
bool v5; // zf
int v6; // eax

if ( !pro_digipad_suppressed )
{
v3 = pro_digipad_fifo_t;
v2 = 256;
if ( pro_digipad_fifo_h == pro_digipad_fifo_t )
return v2;
if ( !pro_digipad_enable )
return 256;
goto LABEL_15;
}
v2 = 256;
if ( pro_digipad_enable )
{
if ( pro_mouse_x != pro_digipad_last_x
|| pro_mouse_y != pro_digipad_last_y
|| pro_mouse_l != pro_digipad_last_l
|| pro_mouse_m != pro_digipad_last_m
|| pro_mouse_r != pro_digipad_last_r
|| pro_mouse_in != pro_digipad_last_in )
{
func5(a1, a2, 256LL);
pro_digipad_last_x = pro_mouse_x;
pro_digipad_last_y = pro_mouse_y;
pro_digipad_last_l = pro_mouse_l;
pro_digipad_last_m = pro_mouse_m;
pro_digipad_last_r = pro_mouse_r;
pro_digipad_last_in = pro_mouse_in;
}
v3 = pro_digipad_fifo_t;
v2 = 256;
if ( pro_digipad_fifo_h != pro_digipad_fifo_t )
{
LABEL_15:
v2 = pro_digipad_fifo[v3];
v4 = v3 + 1;
v5 = v3 == 1023;
v6 = 0;
if ( !v5 )
v6 = v4;
pro_digipad_fifo_t = v6;
return v2;
}
}
return v2;
}

original_code:
int pro_digipad_get (int dev)
{
 int schar;
 if ((pro_digipad_suppressed)
    && (pro_digipad_enable)
    && ((pro_mouse_x != pro_digipad_last_x)
       || (pro_mouse_y != pro_digipad_last_y)
       || (pro_mouse_l != pro_digipad_last_l)
       || (pro_mouse_m != pro_digipad_last_m)
       || (pro_mouse_r != pro_digipad_last_r)
       || (pro_mouse_in != pro_digipad_last_in)))
 {
   pro_digipad_coord();
   pro_digipad_last_x = pro_mouse_x;
   pro_digipad_last_y = pro_mouse_y;
   pro_digipad_last_l = pro_mouse_l;
   pro_digipad_last_m = pro_mouse_m;
   pro_digipad_last_r = pro_mouse_r;
   pro_digipad_last_in = pro_mouse_in;
 }
 if ((pro_digipad_fifo_h == pro_digipad_fifo_t)
    || (!pro_digipad_enable))
   schar = 256;
 else
 {
   schar = pro_digipad_fifo[pro_digipad_fifo_t];
   pro_digipad_fifo_t++;
   if (pro_digipad_fifo_t == 1024)
     pro_digipad_fifo_t = 0;
 }
 return schar;
}

canonical_original_code:
int pro_digipad_get(int dev)
{
 int schar;
 if ((pro_digipad_suppressed)
    && (pro_digipad_enable)
    && ((pro_mouse_x != pro_digipad_last_x)
       || (pro_mouse_y != pro_digipad_last_y)
       || (pro_mouse_l != pro_digipad_last_l)
       || (pro_mouse_m != pro_digipad_last_m)
       || (pro_mouse_r != pro_digipad_last_r)
       || (pro_mouse_in != pro_digipad_last_in)))
 {
   pro_digipad_coord();
   pro_digipad_last_x = pro_mouse_x;
   pro_digipad_last_y = pro_mouse_y;
   pro_digipad_last_l = pro_mouse_l;
   pro_digipad_last_m = pro_mouse_m;
   pro_digipad_last_r = pro_mouse_r;
   pro_digipad_last_in = pro_mouse_in;
 }
 if ((pro_digipad_fifo_h == pro_digipad_fifo_t)
    || (!pro_digipad_enable))
   schar = 256;
 else
 {
   schar = pro_digipad_fifo[pro_digipad_fifo_t];
   pro_digipad_fifo_t++;
   if (pro_digipad_fifo_t == 1024)
     pro_digipad_fifo_t = 0;
 }
 return schar;
}


decompiled_code:
__int64 __fastcall pro_digipad_put(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rdx
int v5; // eax

if ( (_DWORD)a2 == 19 )
{
pro_digipad_enable = 0;
goto LABEL_5;
}
if ( (_DWORD)a2 == 17 )
{
pro_digipad_enable = 1;
goto LABEL_5;
}
v3 = (unsigned int)a2;
LOBYTE(v3) = a2 | 0x80;
pro_digipad_fifo_put(v3);
if ( (_DWORD)a2 != 2 )
{
if ( pro_digipad_s1 != 1 )
goto LABEL_5;
v5 = pro_digipad_s0;
if ( (_DWORD)a2 == 83 && pro_digipad_s0 == 82 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
pro_digipad_last_x = -1;
pro_digipad_last_y = -1;
pro_digipad_enable = 1;
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
pro_digipad_fifo_put(255);
goto LABEL_5;
}
if ( (_DWORD)a2 == 77 && pro_digipad_s0 == 82 )
{
pro_digipad_remote = 1;
pro_digipad_suppressed = 0;
goto LABEL_5;
}
goto LABEL_12;
}
if ( pro_digipad_remote )
{
pro_digipad_coord(v3, a2, v4);
goto LABEL_5;
}
if ( pro_digipad_s1 == 1 )
{
v5 = pro_digipad_s0;
LABEL_12:
if ( v5 == 83 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 1;
}
else if ( (unsigned int)(v5 - 67) <= 1 || v5 == 76 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
}
}
LABEL_5:
pro_digipad_s1 = pro_digipad_s0;
pro_digipad_s0 = a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v3; // rdi
__int64 v4; // rdx
int v5; // eax

if ( (_DWORD)a2 == 19 )
{
pro_digipad_enable = 0;
goto LABEL_5;
}
if ( (_DWORD)a2 == 17 )
{
pro_digipad_enable = 1;
goto LABEL_5;
}
v3 = (unsigned int)a2;
LOBYTE(v3) = a2 | 0x80;
func0(v3);
if ( (_DWORD)a2 != 2 )
{
if ( pro_digipad_s1 != 1 )
goto LABEL_5;
v5 = pro_digipad_s0;
if ( (_DWORD)a2 == 83 && pro_digipad_s0 == 82 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
pro_digipad_last_x = -1;
pro_digipad_last_y = -1;
pro_digipad_enable = 1;
func0(255);
func0(255);
func0(255);
func0(255);
func0(255);
goto LABEL_5;
}
if ( (_DWORD)a2 == 77 && pro_digipad_s0 == 82 )
{
pro_digipad_remote = 1;
pro_digipad_suppressed = 0;
goto LABEL_5;
}
goto LABEL_12;
}
if ( pro_digipad_remote )
{
func5(v3, a2, v4);
goto LABEL_5;
}
if ( pro_digipad_s1 == 1 )
{
v5 = pro_digipad_s0;
LABEL_12:
if ( v5 == 83 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 1;
}
else if ( (unsigned int)(v5 - 67) <= 1 || v5 == 76 )
{
pro_digipad_remote = 0;
pro_digipad_suppressed = 0;
}
}
LABEL_5:
pro_digipad_s1 = pro_digipad_s0;
pro_digipad_s0 = a2;
return 1LL;
}

original_code:
int pro_digipad_put (int dev, int schar)
{
 if (schar == 19)
   pro_digipad_enable = 0;
 else if (schar == 17)
   pro_digipad_enable = 1;
 else
 {
   pro_digipad_fifo_put(schar|0x80);
   if ((schar == 2) && pro_digipad_remote)
     pro_digipad_coord();
   else if (pro_digipad_s1 == 1)
   {
     if ((pro_digipad_s0 == 82) && (schar == 83))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
       pro_digipad_last_x = -1;
       pro_digipad_last_y = -1;
       pro_digipad_enable = 1;
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
     }
     else if ((pro_digipad_s0 == 82) && (schar == 77))
     {
       pro_digipad_remote = 1;
       pro_digipad_suppressed = 0;
     }
     else if (pro_digipad_s0 == 83)
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 1;
     }
     else if ((pro_digipad_s0 == 67) || (pro_digipad_s0 == 68)
             || (pro_digipad_s0 == 76))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
     }
   }
 }
 pro_digipad_s1 = pro_digipad_s0;
 pro_digipad_s0 = schar;
 return 1;
}

canonical_original_code:
int pro_digipad_put(int dev, int schar)
{
 if (schar == 19)
   pro_digipad_enable = 0;
 else if (schar == 17)
   pro_digipad_enable = 1;
 else
 {
   pro_digipad_fifo_put(schar|0x80);
   if ((schar == 2) && pro_digipad_remote)
     pro_digipad_coord();
   else if (pro_digipad_s1 == 1)
   {
     if ((pro_digipad_s0 == 82) && (schar == 83))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
       pro_digipad_last_x = -1;
       pro_digipad_last_y = -1;
       pro_digipad_enable = 1;
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
       pro_digipad_fifo_put(0xff);
     }
     else if ((pro_digipad_s0 == 82) && (schar == 77))
     {
       pro_digipad_remote = 1;
       pro_digipad_suppressed = 0;
     }
     else if (pro_digipad_s0 == 83)
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 1;
     }
     else if ((pro_digipad_s0 == 67) || (pro_digipad_s0 == 68)
             || (pro_digipad_s0 == 76))
     {
       pro_digipad_remote = 0;
       pro_digipad_suppressed = 0;
     }
   }
 }
 pro_digipad_s1 = pro_digipad_s0;
 pro_digipad_s0 = schar;
 return 1;
}


ttinit

decompiled_code:
__int64 ttinit()
{
if ( tcgetattr(0, &cmdtty) < 0 )
return 47LL;
*(__m128i *)&runtty.c_iflag = _mm_load_si128((const __m128i *)&cmdtty);
*(__m128i *)&runtty.c_line = _mm_load_si128((const __m128i *)&cmdtty.c_line);
*(__m128i *)&runtty.c_cc[15] = _mm_load_si128((const __m128i *)&cmdtty.c_cc[15]);
*(_QWORD *)&runtty.c_cc[31] = *(_QWORD *)&cmdtty.c_cc[31];
runtty.c_ospeed = cmdtty.c_ospeed;
runtty.c_lflag &= 0xFFFFFFF5;
runtty.c_oflag &= 0xFFFFFFFE;
runtty.c_iflag &= 0xFFFFFEFF;
runtty.c_cc[0] = sim_int_char;
runtty.c_cc[1] = 0;
runtty.c_cc[2] = 0;
runtty.c_cc[3] = 0;
runtty.c_cc[4] = 0;
runtty.c_cc[11] = 0;
runtty.c_cc[8] = 0;
runtty.c_cc[10] = 0;
runtty.c_cc[9] = 0;
runtty.c_cc[12] = 0;
runtty.c_cc[13] = 0;
runtty.c_cc[14] = 0;
runtty.c_cc[15] = 0;
runtty.c_cc[6] = 0;
runtty.c_cc[5] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( tcgetattr(0, &cmdtty) < 0 )
return 47LL;
*(__m128i *)&runtty.c_iflag = _mm_load_si128((const __m128i *)&cmdtty);
*(__m128i *)&runtty.c_line = _mm_load_si128((const __m128i *)&cmdtty.c_line);
*(__m128i *)&runtty.c_cc[15] = _mm_load_si128((const __m128i *)&cmdtty.c_cc[15]);
*(_QWORD *)&runtty.c_cc[31] = *(_QWORD *)&cmdtty.c_cc[31];
runtty.c_ospeed = cmdtty.c_ospeed;
runtty.c_lflag &= 0xFFFFFFF5;
runtty.c_oflag &= 0xFFFFFFFE;
runtty.c_iflag &= 0xFFFFFEFF;
runtty.c_cc[0] = sim_int_char;
runtty.c_cc[1] = 0;
runtty.c_cc[2] = 0;
runtty.c_cc[3] = 0;
runtty.c_cc[4] = 0;
runtty.c_cc[11] = 0;
runtty.c_cc[8] = 0;
runtty.c_cc[10] = 0;
runtty.c_cc[9] = 0;
runtty.c_cc[12] = 0;
runtty.c_cc[13] = 0;
runtty.c_cc[14] = 0;
runtty.c_cc[15] = 0;
runtty.c_cc[6] = 0;
runtty.c_cc[5] = 0;
return 0LL;
}

original_code:
t_stat ttinit (void)
{
if (tcgetattr (0, &cmdtty) < 0) return (32 + 15);
runtty = cmdtty;
runtty.c_lflag = runtty.c_lflag & ~(0000010 | 0000002);
runtty.c_oflag = runtty.c_oflag & ~0000001;
runtty.c_iflag = runtty.c_iflag & ~0000400;
runtty.c_cc[0] = sim_int_char;
runtty.c_cc[1] = 0;
runtty.c_cc[2] = 0;
runtty.c_cc[3] = 0;
runtty.c_cc[4] = 0;
runtty.c_cc[11] = 0;
runtty.c_cc[8] = 0;
runtty.c_cc[10] = 0;
runtty.c_cc[9] = 0;
runtty.c_cc[12] = 0;
runtty.c_cc[13] = 0;
runtty.c_cc[14] = 0;
runtty.c_cc[15] = 0;
runtty.c_cc[6] = 0;
runtty.c_cc[5] = 0;
return 0;
}

canonical_original_code:
int ttinit()
{
if (tcgetattr (0, &cmdtty) < 0) return (32 + 15);
runtty = cmdtty;
runtty.c_lflag = runtty.c_lflag & ~(0000010 | 0000002);
runtty.c_oflag = runtty.c_oflag & ~0000001;
runtty.c_iflag = runtty.c_iflag & ~0000400;
runtty.c_cc[0] = sim_int_char;
runtty.c_cc[1] = 0;
runtty.c_cc[2] = 0;
runtty.c_cc[3] = 0;
runtty.c_cc[4] = 0;
runtty.c_cc[11] = 0;
runtty.c_cc[8] = 0;
runtty.c_cc[10] = 0;
runtty.c_cc[9] = 0;
runtty.c_cc[12] = 0;
runtty.c_cc[13] = 0;
runtty.c_cc[14] = 0;
runtty.c_cc[15] = 0;
runtty.c_cc[6] = 0;
runtty.c_cc[5] = 0;
return 0;
}


ttrunstate

decompiled_code:
__int64 ttrunstate()
{
runtty.c_cc[0] = sim_int_char;
return (tcsetattr(0, 2, &runtty) >> 31) & 0x2F;
}

canonical_decompiled_code:
__int64 func1()
{
runtty.c_cc[0] = sim_int_char;
return (tcsetattr(0, 2, &runtty) >> 31) & 0x2F;
}

original_code:
t_stat ttrunstate (void)
{
runtty.c_cc[0] = sim_int_char;
if (tcsetattr (0, 2, &runtty) < 0) return (32 + 15);
return 0;
}

canonical_original_code:
int ttrunstate()
{
runtty.c_cc[0] = sim_int_char;
if (tcsetattr (0, 2, &runtty) < 0) return (32 + 15);
return 0;
}


ttcmdstate

decompiled_code:
__int64 ttcmdstate()
{
return (tcsetattr(0, 2, &cmdtty) >> 31) & 0x2F;
}

canonical_decompiled_code:
__int64 func2()
{
return (tcsetattr(0, 2, &cmdtty) >> 31) & 0x2F;
}

original_code:
t_stat ttcmdstate (void)
{
if (tcsetattr (0, 2, &cmdtty) < 0) return (32 + 15);
return 0;
}

canonical_original_code:
int ttcmdstate()
{
if (tcsetattr (0, 2, &cmdtty) < 0) return (32 + 15);
return 0;
}


ttclose

decompiled_code:
__int64 ttclose()
{
return ttcmdstate();
}

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

original_code:
t_stat ttclose (void)
{
return ttcmdstate ();
}

canonical_original_code:
int ttclose()
{
return ttcmdstate ();
}


decompiled_code:
__int16 sim_poll_kbd()
{
int v0; // edx
__int16 result; // ax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = read(0, buf, 1uLL);
result = 0;
if ( v0 == 1 )
{
LOBYTE(result) = buf[0];
HIBYTE(result) = 2;
}
return result;
}

canonical_decompiled_code:
__int16 func4()
{
int v0; // edx
__int16 result; // ax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = read(0, buf, 1uLL);
result = 0;
if ( v0 == 1 )
{
LOBYTE(result) = buf[0];
HIBYTE(result) = 2;
}
return result;
}

original_code:
t_stat sim_poll_kbd (void)
{
int status;
unsigned char buf[1];
status = read (0, buf, 1);
if (status != 1) return 0;
else return (buf[0] | 01000);
}

canonical_original_code:
int sim_poll_kbd()
{
int status;
unsigned char buf[1];
status = read (0, buf, 1);
if (status != 1) return 0;
else return (buf[0] | 01000);
}

variable_types: status int

variable_types:
buf
unsigned char [1]


decompiled_code:
__int64 __fastcall sim_putchar(char a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 0LL;
}

original_code:
t_stat sim_putchar (int out)
{
char c;
c = out;
write (1, &c, 1);
return 0;
}

canonical_original_code:
int sim_putchar(int out)
{
char c;
c = out;
write (1, &c, 1);
return 0;
}

variable_types: out int

variable_types: c char


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

result = (*(__int64 (__fastcall **)(_QWORD))pro_kb_orig)(0LL);
if ( (_DWORD)result != 256 )
result = pro_menu((unsigned int)result);
return result;
}

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

result = (*(__int64 (__fastcall **)(_QWORD))pro_kb_orig)(0LL);
if ( (_DWORD)result != 256 )
result = pro_menu((unsigned int)result);
return result;
}

original_code:
int pro_kb_get ()
{
int key;
 key = pro_kb_orig->get(0);
 if (key != 256)
   key = pro_menu(key);
 return key;
}

canonical_original_code:
int pro_kb_get()
{
int key;
 key = pro_kb_orig->get(0);
 if (key != 256)
   key = pro_menu(key);
 return key;
}


decompiled_code:
__int64 pro_kb_rd()
{
return pro_2661kb_rd();
}

canonical_decompiled_code:
__int64 func1()
{
return pro_2661kb_rd();
}

original_code:
int pro_kb_rd (int pa)
{
 return pro_2661kb_rd(pa);
}

canonical_original_code:
int pro_kb_rd(int pa)
{
 return pro_2661kb_rd(pa);
}


decompiled_code:
__int64 pro_kb_wr()
{
return pro_2661kb_wr();
}

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

original_code:
void pro_kb_wr (int data, int pa, int access)
{
 pro_2661kb_wr(data, pa, access);
}

canonical_original_code:
void pro_kb_wr(int data, int pa, int access)
{
 pro_2661kb_wr(data, pa, access);
}


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

pro_kb_new = (__int64)pro_kb_get;
result = pro_kb;
qword_128 = *(_QWORD *)(pro_kb + 8LL);
qword_130 = *(_QWORD *)(pro_kb + 16LL);
qword_138 = *(_QWORD *)(pro_kb + 24LL);
qword_140 = *(_QWORD *)(pro_kb + 32LL);
qword_148 = *(_QWORD *)(pro_kb + 40LL);
pro_kb_orig = pro_kb;
pro_kb = &pro_kb_new;
return result;
}

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

pro_kb_new = (__int64)pro_kb_get;
result = pro_kb;
qword_128 = *(_QWORD *)(pro_kb + 8LL);
qword_130 = *(_QWORD *)(pro_kb + 16LL);
qword_138 = *(_QWORD *)(pro_kb + 24LL);
qword_140 = *(_QWORD *)(pro_kb + 32LL);
qword_148 = *(_QWORD *)(pro_kb + 40LL);
pro_kb_orig = pro_kb;
pro_kb = &pro_kb_new;
return result;
}

original_code:
void pro_kb_filter ()
{
 pro_kb_new.get = &pro_kb_get;
 pro_kb_new.put = pro_kb->put;
 pro_kb_new.ctrl_get = pro_kb->ctrl_get;
 pro_kb_new.ctrl_put = pro_kb->ctrl_put;
 pro_kb_new.reset = pro_kb->reset;
 pro_kb_new.exit = pro_kb->exit;
 pro_kb_orig = pro_kb;
 pro_kb = &pro_kb_new;
}

canonical_original_code:
void pro_kb_filter()
{
 pro_kb_new.get = &pro_kb_get;
 pro_kb_new.put = pro_kb->put;
 pro_kb_new.ctrl_get = pro_kb->ctrl_get;
 pro_kb_new.ctrl_put = pro_kb->ctrl_put;
 pro_kb_new.reset = pro_kb->reset;
 pro_kb_new.exit = pro_kb->exit;
 pro_kb_orig = pro_kb;
 pro_kb = &pro_kb_new;
}


decompiled_code:
__int64 pro_kb_open()
{
pro_kb_filter();
return pro_2661kb_open();
}

canonical_decompiled_code:
__int64 func4()
{
func3();
return pro_2661kb_open();
}

original_code:
void pro_kb_open ()
{
 pro_kb_filter();
 pro_2661kb_open();
}

canonical_original_code:
void pro_kb_open()
{
 pro_kb_filter();
 pro_2661kb_open();
}


decompiled_code:
__int64 pro_kb_reset()
{
pro_2661kb_reset();
return pro_kb_open();
}

canonical_decompiled_code:
__int64 func5()
{
pro_2661kb_reset();
return func4();
}

original_code:
void pro_kb_reset ()
{
 pro_2661kb_reset();
 pro_kb_open();
}

canonical_original_code:
void pro_kb_reset()
{
 pro_2661kb_reset();
 pro_kb_open();
}


decompiled_code:
__int64 pro_kb_exit()
{
return (*(__int64 (__fastcall **)(_QWORD))(pro_kb + 40LL))(0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return (*(__int64 (__fastcall **)(_QWORD))(pro_kb + 40LL))(0LL);
}

original_code:
void pro_kb_exit ()
{
 pro_kb->exit(0);
}

canonical_original_code:
void pro_kb_exit()
{
 pro_kb->exit(0);
}


decompiled_code:
__int64 __fastcall pro_vid_pixop(int a1, int a2, __int16 a3, int a4, int a5)
{
__int16 v5; // dx
int v6; // eax
char v7; // si
int v8; // er9
int v9; // edx
__int64 result; // rax

v5 = pro_vid_y_offset + ((a3 << 6) | (a2 >> 4) & 0x3F);
v6 = v5 & 0x3FFF;
v7 = a2 & 0xF;
v8 = a4 << v7;
v9 = (unsigned __int16)PRO_VRAM[0x4000 * (__int64)a1 + (v5 & 0x3FFF)];
if ( a5 == 3 )
{
LOWORD(v9) = ~(_WORD)v8 & v9;
}
else if ( a5 > 3 )
{
if ( a5 == 4 )
v9 = v8 | v9 & ~(1 << v7);
}
else if ( a5 == 1 )
{
LOWORD(v9) = v8 ^ v9;
}
else if ( a5 == 2 )
{
LOWORD(v9) = v8 | v9;
}
PRO_VRAM[0x4000 * (__int64)a1 + v6] = v9;
result = v6 >> 6;
pro_vid_mvalid[(int)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, __int16 a3, int a4, int a5)
{
__int16 v5; // dx
int v6; // eax
char v7; // si
int v8; // er9
int v9; // edx
__int64 result; // rax

v5 = pro_vid_y_offset + ((a3 << 6) | (a2 >> 4) & 0x3F);
v6 = v5 & 0x3FFF;
v7 = a2 & 0xF;
v8 = a4 << v7;
v9 = (unsigned __int16)PRO_VRAM[0x4000 * (__int64)a1 + (v5 & 0x3FFF)];
if ( a5 == 3 )
{
LOWORD(v9) = ~(_WORD)v8 & v9;
}
else if ( a5 > 3 )
{
if ( a5 == 4 )
v9 = v8 | v9 & ~(1 << v7);
}
else if ( a5 == 1 )
{
LOWORD(v9) = v8 ^ v9;
}
else if ( a5 == 2 )
{
LOWORD(v9) = v8 | v9;
}
PRO_VRAM[0x4000 * (__int64)a1 + v6] = v9;
result = v6 >> 6;
pro_vid_mvalid[(int)result] = 0;
return result;
}

original_code:
static void pro_vid_pixop(int pnum, int x, int y, int data, int pixop)
{
int vindex, vbit, vmask, vdata, bit;
 vindex = ((((y << 6) | ((x >> 4) & 077)) + pro_vid_y_offset) & 0037777);
 vbit = x & 017;
 vmask = ~(01 << vbit) & 0177777;
 bit = data << vbit;
 vdata = PRO_VRAM[pnum][vindex];
 switch (pixop)
 {
   case 001:
     vdata = vdata ^ bit;
     break;
   case 002:
     vdata = vdata | bit;
     break;
   case 003:
     vdata = vdata & (~bit & 0177777);
     break;
   case 004:
     vdata = (vdata & vmask) | bit;
     break;
   default:
     break;
 }
 PRO_VRAM[pnum][vindex] = vdata;
 pro_vid_mvalid[((vindex) >> 6)] = 0;
}

canonical_original_code:
static void pro_vid_pixop(int pnum, int x, int y, int data, int pixop)
{
int vindex; int vbit; int vmask; int vdata; int bit;
 vindex = ((((y << 6) | ((x >> 4) & 077)) + pro_vid_y_offset) & 0037777);
 vbit = x & 017;
 vmask = ~(01 << vbit) & 0177777;
 bit = data << vbit;
 vdata = PRO_VRAM[pnum][vindex];
 switch (pixop)
 {
   case 001:
     vdata = vdata ^ bit;
     break;
   case 002:
     vdata = vdata | bit;
     break;
   case 003:
     vdata = vdata & (~bit & 0177777);
     break;
   case 004:
     vdata = (vdata & vmask) | bit;
     break;
   default:
     break;
 }
 PRO_VRAM[pnum][vindex] = vdata;
 pro_vid_mvalid[((vindex) >> 6)] = 0;
}

variable_types: pnum int

variable_types: x int

variable_types: y int

variable_types: pixop int

variable_types: vindex int

variable_types: vbit int

variable_types: vmask int

variable_types: vdata int

variable_types: bit int


decompiled_code:
__int64 pro_vid_sched()
{
return pro_eq_sched(3LL, (pro_vid_csr & 1) == 0 ? 7500 : 9000);
}

original_code:
static void pro_vid_sched ()
{
int interval;
 if ((pro_vid_csr & 0000001) == 0)
   interval = 7500;
 else
   interval = 9000;
 pro_eq_sched(3, interval);
}

canonical_original_code:
static void pro_vid_sched()
{
int interval;
 if ((pro_vid_csr & 0000001) == 0)
   interval = 7500;
 else
   interval = 9000;
 pro_eq_sched(3, interval);
}

variable_types: interval int


decompiled_code:
__int64 pro_vid_eq()
{
if ( (pro_vid_csr & 0x40) != 0 )
pro_int_set(260LL);
if ( pro_vid_skip )
{
++pro_vid_skip;
}
else
{
pro_screen_update();
pro_vid_skip = 0;
}
return pro_vid_sched();
}

canonical_decompiled_code:
__int64 func2()
{
if ( (pro_vid_csr & 0x40) != 0 )
pro_int_set(260LL);
if ( pro_vid_skip )
{
++pro_vid_skip;
}
else
{
pro_screen_update();
pro_vid_skip = 0;
}
return func1();
}

original_code:
void pro_vid_eq ()
{
 if ((pro_vid_csr & 0000100) != 0)
   pro_int_set(0x0104);
 if (pro_vid_skip == 0)
 {
   pro_screen_update();
   pro_vid_skip = 0;
 }
 else
   pro_vid_skip++;
 pro_vid_sched();
}

canonical_original_code:
void pro_vid_eq()
{
 if ((pro_vid_csr & 0000100) != 0)
   pro_int_set(0x0104);
 if (pro_vid_skip == 0)
 {
   pro_screen_update();
   pro_vid_skip = 0;
 }
 else
   pro_vid_skip++;
 pro_vid_sched();
}


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

if ( (pro_vid_csr & 0x4000) != 0 )
result = pro_int_set(516LL);
pro_vid_csr |= 0x8000u;
pro_vid_cnt = 0;
return result;
}

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

if ( (pro_vid_csr & 0x4000) != 0 )
result = pro_int_set(516LL);
pro_vid_csr |= 0x8000u;
pro_vid_cnt = 0;
return result;
}

original_code:
void pro_vid_cmd_eq ()
{
 if ((pro_vid_csr & 0040000) != 0)
   pro_int_set(0x0204);
 pro_vid_csr = pro_vid_csr | 0100000;
 pro_vid_cnt = 0;
}

canonical_original_code:
void pro_vid_cmd_eq()
{
 if ((pro_vid_csr & 0040000) != 0)
   pro_int_set(0x0204);
 pro_vid_csr = pro_vid_csr | 0100000;
 pro_vid_cnt = 0;
}


decompiled_code:
__int64 __fastcall pro_vram_rd(_DWORD *a1, int a2)
{
int v2; // esi
__int64 result; // rax
double v4; // xmm0_8

if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v2 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF;
switch ( pro_vid_plane_en )
{
case 0:
*a1 = 0xFFFF;
break;
case 1:
case 3:
case 5:
case 7:
*a1 = (unsigned __int16)PRO_VRAM[v2];
break;
case 2:
case 6:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x4000];
break;
case 4:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x8000];
break;
default:
*a1 = 0xFFFF;
break;
}
result = 0LL;
}
else
{
*a1 = 0;
v4 = sim_gtime();
printf("%10f Warning: video memory (R) not at default location!\r\n", v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2)
{
int v2; // esi
__int64 result; // rax
double v4; // xmm0_8

if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v2 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF;
switch ( pro_vid_plane_en )
{
case 0:
*a1 = 0xFFFF;
break;
case 1:
case 3:
case 5:
case 7:
*a1 = (unsigned __int16)PRO_VRAM[v2];
break;
case 2:
case 6:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x4000];
break;
case 4:
*a1 = (unsigned __int16)PRO_VRAM[v2 + 0x8000];
break;
default:
*a1 = 0xFFFF;
break;
}
result = 0LL;
}
else
{
*a1 = 0;
v4 = sim_gtime();
printf("%10f Warning: video memory (R) not at default location!\r\n", v4);
result = 0LL;
}
return result;
}

original_code:
int pro_vram_rd (int *data, int pa, int access)
{
int vindex;
 if ((pa & 017700000) == pro_vid_mem_base)
 {
   vindex = ((((pa-pro_vid_mem_base) >> 1) + pro_vid_y_offset) & 0037777);
   switch (pro_vid_plane_en)
   {
     case 00:
       *data = 0177777;
       break;
     case 01:
     case 03:
     case 05:
     case 07:
       *data = PRO_VRAM[0][vindex];
       break;
     case 02:
     case 06:
       *data = PRO_VRAM[1][vindex];
       break;
     case 04:
       *data = PRO_VRAM[2][vindex];
       break;
     default:
       *data = 0177777;
       break;
   }
 }
 else
 {
   *data = 0;
   printf("%10f Warning: video memory (R) not at default location!\r\n", sim_gtime());
 }
 return 0;
}

canonical_original_code:
int pro_vram_rd(int *data, int pa, int access)
{
int vindex;
 if ((pa & 017700000) == pro_vid_mem_base)
 {
   vindex = ((((pa-pro_vid_mem_base) >> 1) + pro_vid_y_offset) & 0037777);
   switch (pro_vid_plane_en)
   {
     case 00:
       *data = 0177777;
       break;
     case 01:
     case 03:
     case 05:
     case 07:
       *data = PRO_VRAM[0][vindex];
       break;
     case 02:
     case 06:
       *data = PRO_VRAM[1][vindex];
       break;
     case 04:
       *data = PRO_VRAM[2][vindex];
       break;
     default:
       *data = 0177777;
       break;
   }
 }
 else
 {
   *data = 0;
   printf("%10f Warning: video memory (R) not at default location!\r\n", sim_gtime());
 }
 return 0;
}

variable_types:
data
int *

variable_types: pa int

variable_types: access int


decompiled_code:
__int64 __fastcall pro_vram_wr(__int16 a1, int a2, int a3)
{
int v3; // eax
char v4; // cl
__int16 v5; // di
__int16 v6; // dx
__int64 v8; // rsi
__int16 v9; // dx
__int16 v10; // dx
double v11; // xmm0_8

if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v3 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF;
v4 = pro_vid_plane_en;
if ( (pro_vid_plane_en & 1) != 0 )
{
if ( a3 != 4 )
{
PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF] = a1;
if ( (v4 & 2) == 0 )
{
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_18;
}
goto LABEL_17;
}
if ( (a2 & 1) != 0 )
{
HIBYTE(PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF]) = a1;
if ( (v4 & 2) != 0 )
{
LABEL_9:
HIBYTE(PRO_VRAM[v3 + 0x4000]) = a1;
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_10;
}
goto LABEL_13;
}
v6 = PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF];
LOBYTE(v6) = 0;
PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF] = (unsigned __int8)a1 | v6;
if ( (v4 & 2) == 0 )
{
LABEL_13:
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_25;
}
}
else
{
if ( (pro_vid_plane_en & 2) == 0 )
{
if ( (pro_vid_plane_en & 4) == 0 )
goto LABEL_19;
if ( a3 != 4 )
goto LABEL_18;
LABEL_25:
if ( (a2 & 1) != 0 )
{
LABEL_10:
v5 = LOBYTE(PRO_VRAM[v3 + 0x8000]) | (unsigned __int16)(a1 << 8);
LABEL_11:
PRO_VRAM[v3 + 0x8000] = v5;
goto LABEL_19;
}
LABEL_22:
v10 = PRO_VRAM[v3 + 0x8000];
LOBYTE(v10) = 0;
v5 = v10 | (unsigned __int8)a1;
goto LABEL_11;
}
if ( a3 != 4 )
{
LABEL_17:
PRO_VRAM[v3 + 0x4000] = a1;
if ( (v4 & 4) != 0 )
LABEL_18:
PRO_VRAM[v3 + 0x8000] = a1;
LABEL_19:
pro_vid_mvalid[v3 >> 6] = 0;
return 0LL;
}
if ( (a2 & 1) != 0 )
goto LABEL_9;
}
v8 = v3 + 0x4000LL;
v9 = PRO_VRAM[v8];
LOBYTE(v9) = 0;
PRO_VRAM[v8] = (unsigned __int8)a1 | v9;
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_22;
}
v11 = sim_gtime();
printf("%10f Warning: video memory (W) not at default location!\r\n", v11);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1, int a2, int a3)
{
int v3; // eax
char v4; // cl
__int16 v5; // di
__int16 v6; // dx
__int64 v8; // rsi
__int16 v9; // dx
__int16 v10; // dx
double v11; // xmm0_8

if ( (a2 & 0x3F8000) == pro_vid_mem_base )
{
v3 = ((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF;
v4 = pro_vid_plane_en;
if ( (pro_vid_plane_en & 1) != 0 )
{
if ( a3 != 4 )
{
PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF] = a1;
if ( (v4 & 2) == 0 )
{
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_18;
}
goto LABEL_17;
}
if ( (a2 & 1) != 0 )
{
HIBYTE(PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF]) = a1;
if ( (v4 & 2) != 0 )
{
LABEL_9:
HIBYTE(PRO_VRAM[v3 + 0x4000]) = a1;
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_10;
}
goto LABEL_13;
}
v6 = PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF];
LOBYTE(v6) = 0;
PRO_VRAM[((_WORD)pro_vid_y_offset + (unsigned __int16)((a2 - pro_vid_mem_base) >> 1)) & 0x3FFF] = (unsigned __int8)a1 | v6;
if ( (v4 & 2) == 0 )
{
LABEL_13:
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_25;
}
}
else
{
if ( (pro_vid_plane_en & 2) == 0 )
{
if ( (pro_vid_plane_en & 4) == 0 )
goto LABEL_19;
if ( a3 != 4 )
goto LABEL_18;
LABEL_25:
if ( (a2 & 1) != 0 )
{
LABEL_10:
v5 = LOBYTE(PRO_VRAM[v3 + 0x8000]) | (unsigned __int16)(a1 << 8);
LABEL_11:
PRO_VRAM[v3 + 0x8000] = v5;
goto LABEL_19;
}
LABEL_22:
v10 = PRO_VRAM[v3 + 0x8000];
LOBYTE(v10) = 0;
v5 = v10 | (unsigned __int8)a1;
goto LABEL_11;
}
if ( a3 != 4 )
{
LABEL_17:
PRO_VRAM[v3 + 0x4000] = a1;
if ( (v4 & 4) != 0 )
LABEL_18:
PRO_VRAM[v3 + 0x8000] = a1;
LABEL_19:
pro_vid_mvalid[v3 >> 6] = 0;
return 0LL;
}
if ( (a2 & 1) != 0 )
goto LABEL_9;
}
v8 = v3 + 0x4000LL;
v9 = PRO_VRAM[v8];
LOBYTE(v9) = 0;
PRO_VRAM[v8] = (unsigned __int8)a1 | v9;
if ( (v4 & 4) == 0 )
goto LABEL_19;
goto LABEL_22;
}
v11 = sim_gtime();
printf("%10f Warning: video memory (W) not at default location!\r\n", v11);
return 0LL;
}

variable_types: data int


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

result = 0LL;
memset(pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
return result;
}

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

result = 0LL;
memset(pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
return result;
}

original_code:
void pro_clear_mvalid ()
{
   memset(&pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
}

canonical_original_code:
void pro_clear_mvalid()
{
   memset(&pro_vid_mvalid, 0, sizeof(pro_vid_mvalid));
}


decompiled_code:
__int64 __fastcall pro_vid_rd(int a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3FFFFE;
if ( v1 > 4192534 )
{
result = 0xFFFFLL;
if ( v1 == 4192640 )
result = 65283LL;
}
else if ( v1 <= 4192511 )
{
result = 0xFFFFLL;
}
else
{
switch ( v1 )
{
case 4192512:
result = 65282LL;
break;
case 4192516:
result = (unsigned int)pro_vid_csr;
break;
case 4192518:
result = (unsigned int)pro_vid_p1c;
break;
case 4192520:
result = (unsigned int)pro_vid_opc;
break;
case 4192524:
result = (unsigned int)pro_vid_scl;
break;
case 4192526:
result = (unsigned int)pro_vid_x;
break;
case 4192528:
result = (unsigned int)pro_vid_y;
break;
case 4192530:
case 4192532:
case 4192534:
result = 65407LL;
break;
default:
result = 0xFFFFLL;
break;
}
}
return result;
}

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

v1 = a1 & 0x3FFFFE;
if ( v1 > 4192534 )
{
result = 0xFFFFLL;
if ( v1 == 4192640 )
result = 65283LL;
}
else if ( v1 <= 4192511 )
{
result = 0xFFFFLL;
}
else
{
switch ( v1 )
{
case 4192512:
result = 65282LL;
break;
case 4192516:
result = (unsigned int)pro_vid_csr;
break;
case 4192518:
result = (unsigned int)pro_vid_p1c;
break;
case 4192520:
result = (unsigned int)pro_vid_opc;
break;
case 4192524:
result = (unsigned int)pro_vid_scl;
break;
case 4192526:
result = (unsigned int)pro_vid_x;
break;
case 4192528:
result = (unsigned int)pro_vid_y;
break;
case 4192530:
case 4192532:
case 4192534:
result = 65407LL;
break;
default:
result = 0xFFFFLL;
break;
}
}
return result;
}

original_code:
int pro_vid_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774400:
     data = 0177402;
     break;
   case 017774404:
     data = pro_vid_csr;
     break;
   case 017774406:
     data = pro_vid_p1c;
     break;
   case 017774410:
     data = pro_vid_opc;
     break;
   case 017774414:
     data = pro_vid_scl;
     break;
   case 017774416:
     data = pro_vid_x;
     break;
   case 017774420:
     data = pro_vid_y;
     break;
   case 017774422:
     data = 0177577;
     break;
   case 017774424:
     data = 0177577;
     break;
   case 017774426:
     data = 0177577;
     break;
   case 017774600:
     data = 0177403;
     break;
   default:
     data = 0177777;
     break;
 }
 return data;
}

canonical_original_code:
int pro_vid_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017774400:
     data = 0177402;
     break;
   case 017774404:
     data = pro_vid_csr;
     break;
   case 017774406:
     data = pro_vid_p1c;
     break;
   case 017774410:
     data = pro_vid_opc;
     break;
   case 017774414:
     data = pro_vid_scl;
     break;
   case 017774416:
     data = pro_vid_x;
     break;
   case 017774420:
     data = pro_vid_y;
     break;
   case 017774422:
     data = 0177577;
     break;
   case 017774424:
     data = 0177577;
     break;
   case 017774426:
     data = 0177577;
     break;
   case 017774600:
     data = 0177403;
     break;
   default:
     data = 0177777;
     break;
 }
 return data;
}


decompiled_code:
char __fastcall pro_vid_wr(int a1, int a2, int a3)
{
int v3; // eax
unsigned __int16 v4; // bx
int v5; // eax
int v6; // edi
int v7; // edx
int v8; // eax
int v9; // eax
int v10; // er15
__int16 v11; // dx
int v12; // eax
int *v13; // r14
int v14; // ecx
int v15; // er8
int v16; // er13
int v17; // er15
int v18; // er12
int v19; // ebx
int i; // ebp
unsigned __int16 v21; // ax
unsigned __int16 v22; // ax
unsigned __int16 v23; // ax
int v24; // eax
int v26; // [rsp+0h] [rbp-68h]
int v27; // [rsp+4h] [rbp-64h]
int v28; // [rsp+8h] [rbp-60h]
int v29; // [rsp+Ch] [rbp-5Ch]
int v30; // [rsp+18h] [rbp-50h]
__int16 v31; // [rsp+1Ch] [rbp-4Ch]
int v32[17]; // [rsp+24h] [rbp-44h] BYREF

LOBYTE(v3) = (a2 & 0xFE) - 4;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF904:
v4 = pro_vid_csr;
if ( a3 == 4 )
{
if ( (a2 & 1) != 0 )
{
v5 = pro_vid_csr;
BYTE1(v5) = BYTE1(pro_vid_csr) & 0xB8;
v6 = v5 | ((_WORD)a1 << 8) & 0x4743;
}
else
{
v6 = pro_vid_csr & 0xFFFFFFBC | a1 & 0x43;
}
pro_vid_csr = v6;
}
else
{
pro_vid_csr = pro_vid_csr & 0xFFFFB8BC | a1 & 0x4743;
}
LOBYTE(v3) = pro_vid_csr;
if ( (pro_vid_csr & 0x4000) != 0 && (v4 & 0x4000) == 0 && (pro_vid_csr & 0x8000) != 0 )
LOBYTE(v3) = pro_int_set(516LL);
if ( (((unsigned __int16)pro_vid_csr ^ v4) & 0x400) != 0 )
LOBYTE(v3) = pro_mapchange();
break;
case 0x3FF906:
pro_vid_p1c = pro_vid_p1c & 0xFFFFFFC0 | a1 & 0x3F;
v3 = (pro_vid_opc >> 4) & 2 | (pro_vid_opc >> 11) & 4;
pro_vid_plane_en = v3 | (pro_vid_p1c >> 5) & 1;
break;
case 0x3FF908:
pro_vid_opc = pro_vid_opc & 0xFFFFC0C0 | a1 & 0x3F3F;
v3 = (pro_vid_p1c >> 5) & 1;
pro_vid_plane_en = v3 | (pro_vid_opc >> 11) & 4 | (pro_vid_opc >> 4) & 2;
break;
case 0x3FF90A:
LOBYTE(v3) = pro_colormap_write((a1 >> 8) & 7, (unsigned __int8)a1);
break;
case 0x3FF90C:
v7 = pro_vid_scl;
v8 = pro_vid_scl;
LOBYTE(v8) = 0;
pro_vid_scl = v8 | (unsigned __int8)a1;
if ( pro_vid_scl != v7 )
pro_scroll();
LOBYTE(v3) = (_BYTE)pro_vid_scl << 6;
pro_vid_y_offset = ((_WORD)pro_vid_scl << 6) & 0x3FC0;
break;
case 0x3FF90E:
LOBYTE(v3) = 0;
pro_vid_x = pro_vid_x & 0xFFFFFC00 | a1 & 0x3FF;
break;
case 0x3FF910:
v3 = pro_vid_y;
LOBYTE(v3) = 0;
pro_vid_y = v3 | (unsigned __int8)a1;
break;
case 0x3FF912:
HIWORD(v9) = HIWORD(pro_vid_cnt);
LOWORD(v9) = 0;
v10 = (unsigned __int16)a1 | v9;
pro_vid_cnt = v10;
v11 = pro_vid_csr;
v12 = pro_vid_csr;
BYTE1(v12) = BYTE1(pro_vid_csr) & 0x7F;
pro_vid_csr = v12;
if ( v10 )
{
v32[0] = pro_vid_p1c & 7;
v32[1] = pro_vid_opc & 7;
v32[2] = (pro_vid_opc >> 8) & 7;
v27 = v11 & 0x200;
v28 = v11 & 0x100;
v13 = v32;
v29 = 0;
v26 = v10;
do
{
v16 = pro_vid_x;
v17 = pro_vid_y;
v19 = ((_WORD)pro_vid_y_offset + ((unsigned __int16)((_WORD)pro_vid_y << 6) | (pro_vid_x >> 4) & 0x3F)) & 0x3FFF;
v18 = pro_vid_pat;
v24 = 0xFFFF;
if ( (pro_vid_pat & 1) == 0 )
v24 = pro_vid_pat & 1;
v31 = v24;
if ( v26 > 0 )
{
v30 = v24;
for ( i = 0; i != v26; ++i )
{
if ( v27 )
{
switch ( *v13 )
{
case 1:
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ~PRO_VRAM[0x4000 * (__int64)v29 + v19];
goto LABEL_41;
case 2:
PRO_VRAM[0x4000 * (__int64)v29 + v19] = v31;
goto LABEL_41;
case 3:
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ~v31;
goto LABEL_41;
case 5:
v21 = PRO_VRAM[0x4000 * (__int64)v29 + v19];
if ( !v28 )
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = (v30 >> 15) | (2 * v21);
v30 = v21;
goto LABEL_50;
}
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ((_WORD)v30 << 15) | (v21 >> 1);
v30 = v21;
goto LABEL_52;
case 6:
v22 = PRO_VRAM[0x4000 * (__int64)v29 + v19];
if ( !v28 )
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = (v30 >> 14) | (4 * v22);
v30 = v22;
goto LABEL_50;
}
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ((_WORD)v30 << 14) | (v22 >> 2);
v30 = v22;
goto LABEL_52;
case 7:
v23 = PRO_VRAM[0x4000 * (__int64)v29 + v19];
if ( v28 )
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ((_WORD)v30 << 12) | (v23 >> 4);
v30 = v23;
LABEL_52:
pro_vid_mvalid[v19 >> 6] = 0;
LABEL_53:
v19 = ((_WORD)v19 - 1) & 0x3FFF;
}
else
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = (v30 >> 12) | (16 * v23);
v30 = v23;
LABEL_50:
pro_vid_mvalid[v19 >> 6] = 0;
LABEL_42:
v19 = ((_WORD)v19 + 1) & 0x3FFF;
}
break;
default:
LABEL_41:
pro_vid_mvalid[v19 >> 6] = 0;
if ( !v28 )
goto LABEL_42;
goto LABEL_53;
}
}
else
{
v15 = *v13;
switch ( *v13 )
{
case 1:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
goto LABEL_26;
case 2:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 4;
goto LABEL_26;
case 3:
v14 = (v18 & 1) == 0;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 4;
goto LABEL_26;
case 4:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 2;
goto LABEL_26;
case 5:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 3;
goto LABEL_26;
case 6:
v14 = 1;
v15 = 3;
goto LABEL_26;
case 7:
v14 = 1;
v15 = 2;
LABEL_26:
pro_vid_pixop(v29, v16, v17, v14, v15);
break;
default:
break;
}
if ( v28 )
{
if ( ++v17 == 256 )
{
++v16;
v17 = 0;
if ( v16 == 1024 )
v16 = v27;
}
}
else if ( ++v16 == 1024 )
{
++v17;
v16 = 0;
if ( v17 == 256 )
v17 = v28;
}
}
}
}
++v29;
++v13;
}
while ( v29 != 3 );
pro_vid_pat = v18;
}
LOBYTE(v3) = pro_eq_sched(4LL, 1LL);
break;
case 0x3FF914:
HIWORD(v3) = HIWORD(pro_vid_pat);
LOWORD(v3) = 0;
pro_vid_pat = v3 | (unsigned __int16)a1;
break;
case 0x3FF916:
LOBYTE(v3) = pro_vid_mbr & 0x80;
pro_vid_mbr = pro_vid_mbr & 0xFFFFFF80 | a1 & 0x7F;
pro_vid_mem_base = pro_vid_mbr << 15;
iotable = pro_vid_mbr << 15;
*((_DWORD *)&iotable + 1) = (pro_vid_mbr << 15) + 0x7FFF;
break;
default:
return v3;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func8(int a1, int a2, int a3)
{
int v3; // eax
unsigned __int16 v4; // bx
int v5; // eax
int v6; // edi
int v7; // edx
int v8; // eax
int v9; // eax
int v10; // er15
__int16 v11; // dx
int v12; // eax
int *v13; // r14
int v14; // ecx
int v15; // er8
int v16; // er13
int v17; // er15
int v18; // er12
int v19; // ebx
int i; // ebp
unsigned __int16 v21; // ax
unsigned __int16 v22; // ax
unsigned __int16 v23; // ax
int v24; // eax
int v26; // [rsp+0h] [rbp-68h]
int v27; // [rsp+4h] [rbp-64h]
int v28; // [rsp+8h] [rbp-60h]
int v29; // [rsp+Ch] [rbp-5Ch]
int v30; // [rsp+18h] [rbp-50h]
__int16 v31; // [rsp+1Ch] [rbp-4Ch]
int v32[17]; // [rsp+24h] [rbp-44h] BYREF

LOBYTE(v3) = (a2 & 0xFE) - 4;
switch ( a2 & 0x3FFFFE )
{
case 0x3FF904:
v4 = pro_vid_csr;
if ( a3 == 4 )
{
if ( (a2 & 1) != 0 )
{
v5 = pro_vid_csr;
BYTE1(v5) = BYTE1(pro_vid_csr) & 0xB8;
v6 = v5 | ((_WORD)a1 << 8) & 0x4743;
}
else
{
v6 = pro_vid_csr & 0xFFFFFFBC | a1 & 0x43;
}
pro_vid_csr = v6;
}
else
{
pro_vid_csr = pro_vid_csr & 0xFFFFB8BC | a1 & 0x4743;
}
LOBYTE(v3) = pro_vid_csr;
if ( (pro_vid_csr & 0x4000) != 0 && (v4 & 0x4000) == 0 && (pro_vid_csr & 0x8000) != 0 )
LOBYTE(v3) = pro_int_set(516LL);
if ( (((unsigned __int16)pro_vid_csr ^ v4) & 0x400) != 0 )
LOBYTE(v3) = pro_mapchange();
break;
case 0x3FF906:
pro_vid_p1c = pro_vid_p1c & 0xFFFFFFC0 | a1 & 0x3F;
v3 = (pro_vid_opc >> 4) & 2 | (pro_vid_opc >> 11) & 4;
pro_vid_plane_en = v3 | (pro_vid_p1c >> 5) & 1;
break;
case 0x3FF908:
pro_vid_opc = pro_vid_opc & 0xFFFFC0C0 | a1 & 0x3F3F;
v3 = (pro_vid_p1c >> 5) & 1;
pro_vid_plane_en = v3 | (pro_vid_opc >> 11) & 4 | (pro_vid_opc >> 4) & 2;
break;
case 0x3FF90A:
LOBYTE(v3) = pro_colormap_write((a1 >> 8) & 7, (unsigned __int8)a1);
break;
case 0x3FF90C:
v7 = pro_vid_scl;
v8 = pro_vid_scl;
LOBYTE(v8) = 0;
pro_vid_scl = v8 | (unsigned __int8)a1;
if ( pro_vid_scl != v7 )
pro_scroll();
LOBYTE(v3) = (_BYTE)pro_vid_scl << 6;
pro_vid_y_offset = ((_WORD)pro_vid_scl << 6) & 0x3FC0;
break;
case 0x3FF90E:
LOBYTE(v3) = 0;
pro_vid_x = pro_vid_x & 0xFFFFFC00 | a1 & 0x3FF;
break;
case 0x3FF910:
v3 = pro_vid_y;
LOBYTE(v3) = 0;
pro_vid_y = v3 | (unsigned __int8)a1;
break;
case 0x3FF912:
HIWORD(v9) = HIWORD(pro_vid_cnt);
LOWORD(v9) = 0;
v10 = (unsigned __int16)a1 | v9;
pro_vid_cnt = v10;
v11 = pro_vid_csr;
v12 = pro_vid_csr;
BYTE1(v12) = BYTE1(pro_vid_csr) & 0x7F;
pro_vid_csr = v12;
if ( v10 )
{
v32[0] = pro_vid_p1c & 7;
v32[1] = pro_vid_opc & 7;
v32[2] = (pro_vid_opc >> 8) & 7;
v27 = v11 & 0x200;
v28 = v11 & 0x100;
v13 = v32;
v29 = 0;
v26 = v10;
do
{
v16 = pro_vid_x;
v17 = pro_vid_y;
v19 = ((_WORD)pro_vid_y_offset + ((unsigned __int16)((_WORD)pro_vid_y << 6) | (pro_vid_x >> 4) & 0x3F)) & 0x3FFF;
v18 = pro_vid_pat;
v24 = 0xFFFF;
if ( (pro_vid_pat & 1) == 0 )
v24 = pro_vid_pat & 1;
v31 = v24;
if ( v26 > 0 )
{
v30 = v24;
for ( i = 0; i != v26; ++i )
{
if ( v27 )
{
switch ( *v13 )
{
case 1:
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ~PRO_VRAM[0x4000 * (__int64)v29 + v19];
goto LABEL_41;
case 2:
PRO_VRAM[0x4000 * (__int64)v29 + v19] = v31;
goto LABEL_41;
case 3:
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ~v31;
goto LABEL_41;
case 5:
v21 = PRO_VRAM[0x4000 * (__int64)v29 + v19];
if ( !v28 )
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = (v30 >> 15) | (2 * v21);
v30 = v21;
goto LABEL_50;
}
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ((_WORD)v30 << 15) | (v21 >> 1);
v30 = v21;
goto LABEL_52;
case 6:
v22 = PRO_VRAM[0x4000 * (__int64)v29 + v19];
if ( !v28 )
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = (v30 >> 14) | (4 * v22);
v30 = v22;
goto LABEL_50;
}
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ((_WORD)v30 << 14) | (v22 >> 2);
v30 = v22;
goto LABEL_52;
case 7:
v23 = PRO_VRAM[0x4000 * (__int64)v29 + v19];
if ( v28 )
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = ((_WORD)v30 << 12) | (v23 >> 4);
v30 = v23;
LABEL_52:
pro_vid_mvalid[v19 >> 6] = 0;
LABEL_53:
v19 = ((_WORD)v19 - 1) & 0x3FFF;
}
else
{
PRO_VRAM[0x4000 * (__int64)v29 + v19] = (v30 >> 12) | (16 * v23);
v30 = v23;
LABEL_50:
pro_vid_mvalid[v19 >> 6] = 0;
LABEL_42:
v19 = ((_WORD)v19 + 1) & 0x3FFF;
}
break;
default:
LABEL_41:
pro_vid_mvalid[v19 >> 6] = 0;
if ( !v28 )
goto LABEL_42;
goto LABEL_53;
}
}
else
{
v15 = *v13;
switch ( *v13 )
{
case 1:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
goto LABEL_26;
case 2:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 4;
goto LABEL_26;
case 3:
v14 = (v18 & 1) == 0;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 4;
goto LABEL_26;
case 4:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 2;
goto LABEL_26;
case 5:
v14 = v18 & 1;
v18 = (v18 >> 1) | (unsigned __int16)((_WORD)v18 << 15);
v15 = 3;
goto LABEL_26;
case 6:
v14 = 1;
v15 = 3;
goto LABEL_26;
case 7:
v14 = 1;
v15 = 2;
LABEL_26:
func0(v29, v16, v17, v14, v15);
break;
default:
break;
}
if ( v28 )
{
if ( ++v17 == 256 )
{
++v16;
v17 = 0;
if ( v16 == 1024 )
v16 = v27;
}
}
else if ( ++v16 == 1024 )
{
++v17;
v16 = 0;
if ( v17 == 256 )
v17 = v28;
}
}
}
}
++v29;
++v13;
}
while ( v29 != 3 );
pro_vid_pat = v18;
}
LOBYTE(v3) = pro_eq_sched(4LL, 1LL);
break;
case 0x3FF914:
HIWORD(v3) = HIWORD(pro_vid_pat);
LOWORD(v3) = 0;
pro_vid_pat = v3 | (unsigned __int16)a1;
break;
case 0x3FF916:
LOBYTE(v3) = pro_vid_mbr & 0x80;
pro_vid_mbr = pro_vid_mbr & 0xFFFFFF80 | a1 & 0x7F;
pro_vid_mem_base = pro_vid_mbr << 15;
iotable = pro_vid_mbr << 15;
*((_DWORD *)&iotable + 1) = (pro_vid_mbr << 15) + 0x7FFF;
break;
default:
return v3;
}
return v3;
}

variable_types: vplane int

variable_types: vcount int

variable_types: vpixpat int

variable_types: vwordpat int

variable_types: vsi int

variable_types: pixdata int

variable_types:
vop
int [3]


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

memset(PRO_VRAM, 0, (size_t)&unk_18000);
pro_vid_csr = 0x8000;
pro_vid_p1c = 0;
pro_vid_opc = 0;
pro_vid_scl = 65280;
pro_vid_x = 0;
pro_vid_y = 0;
pro_vid_cnt = 0;
pro_vid_pat = 0;
pro_vid_mbr = 0;
pro_vid_mem_base = 0;
pro_vid_plane_en = 0;
pro_vid_y_offset = 0;
pro_vid_skip = 0;
pro_vid_sched();
pro_screen_reset();
result = pro_screen_init();
if ( (_DWORD)result == -1 )
result = pro_exit();
return result;
}

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

memset(PRO_VRAM, 0, (size_t)&unk_18000);
pro_vid_csr = 0x8000;
pro_vid_p1c = 0;
pro_vid_opc = 0;
pro_vid_scl = 65280;
pro_vid_x = 0;
pro_vid_y = 0;
pro_vid_cnt = 0;
pro_vid_pat = 0;
pro_vid_mbr = 0;
pro_vid_mem_base = 0;
pro_vid_plane_en = 0;
pro_vid_y_offset = 0;
pro_vid_skip = 0;
func1();
pro_screen_reset();
result = pro_screen_init();
if ( (_DWORD)result == -1 )
result = pro_exit();
return result;
}

original_code:
void pro_vid_reset ()
{
        memset(&PRO_VRAM, 0, sizeof(PRO_VRAM));
 pro_vid_csr = 0000000 | 0100000;
 pro_vid_p1c = 0;
 pro_vid_opc = 0;
 pro_vid_scl = 0177400;
 pro_vid_x = 0;
 pro_vid_y = 0;
 pro_vid_cnt = 0;
 pro_vid_pat = 0;
 pro_vid_mbr = 0;
 pro_vid_mem_base = 0;
 pro_vid_plane_en = 0;
 pro_vid_y_offset = 0;
 pro_vid_skip = 0;
 pro_vid_sched();
 pro_screen_reset();
 if (pro_screen_init() == -1)
   pro_exit();
}

canonical_original_code:
void pro_vid_reset()
{
        memset(&PRO_VRAM, 0, sizeof(PRO_VRAM));
 pro_vid_csr = 0000000 | 0100000;
 pro_vid_p1c = 0;
 pro_vid_opc = 0;
 pro_vid_scl = 0177400;
 pro_vid_x = 0;
 pro_vid_y = 0;
 pro_vid_cnt = 0;
 pro_vid_pat = 0;
 pro_vid_mbr = 0;
 pro_vid_mem_base = 0;
 pro_vid_plane_en = 0;
 pro_vid_y_offset = 0;
 pro_vid_skip = 0;
 pro_vid_sched();
 pro_screen_reset();
 if (pro_screen_init() == -1)
   pro_exit();
}


decompiled_code:
__int64 pro_vid_exit()
{
return pro_screen_close();
}

canonical_decompiled_code:
__int64 func10()
{
return pro_screen_close();
}

original_code:
void pro_vid_exit ()
{
 pro_screen_close();
}

canonical_original_code:
void pro_vid_exit()
{
 pro_screen_close();
}


decompiled_code:
__int64 __fastcall rom_rd(_DWORD *a1, int a2)
{
*a1 = (unsigned __int16)ROM[(a2 - 4173824) >> 1];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2)
{
*a1 = (unsigned __int16)ROM[(a2 - 4173824) >> 1];
return 0LL;
}

original_code:
int rom_rd (int *data, int pa, int access)
{
 *data = ROM[(pa-017730000) >> 1];
 return 0;
}

canonical_original_code:
int rom_rd(int *data, int pa, int access)
{
 *data = ROM[(pa-017730000) >> 1];
 return 0;
}


decompiled_code:
__int64 rom_wr()
{
return 32LL;
}

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

original_code:
int rom_wr (int data, int pa, int access)
{
 return (32 + 0);
}

canonical_original_code:
int rom_wr(int data, int pa, int access)
{
 return (32 + 0);
}


decompiled_code:
__int64 __fastcall reg_wr(unsigned __int8 a1, int a2, int a3)
{
__int64 v3; // rsi
__int16 v4; // ax
__int64 result; // rax
__int16 v6; // di
__int16 v7; // ax
int v8; // ecx
int v9; // eax
int v10; // eax
unsigned int v11; // eax

if ( (unsigned int)(a2 - 4191772) > 0x63 )
{
if ( (unsigned int)(a2 - 4191872) <= 0xB )
{
pro_int_wr();
result = 0LL;
}
else
{
v8 = a2 & 0x3FFFFE;
if ( (a2 & 0x3FFFFE) == 4192196 )
{
if ( a3 == 4 )
{
v11 = pro_led;
if ( (a2 & 1) == 0 )
v11 = a1 & 0xF | pro_led & 0xFFFFFFF0;
pro_led = v11;
result = 0LL;
}
else
{
pro_led = a1 & 0xF | pro_led & 0xFFFFFFF0;
result = 0LL;
}
}
else if ( (a2 & 0x3FFFFEu) <= 0x3FF7C4 )
{
if ( (a2 & 0x3FFFFEu) > 0x3FF706 )
{
if ( (a2 & 0x3FFFFEu) > 0x3FF746 )
{
result = 32LL;
if ( v8 == 4192192 )
{
if ( a3 == 4 )
{
v10 = pro_csr;
if ( (a2 & 1) == 0 )
{
LOBYTE(v10) = pro_csr & 0x7F;
v10 |= a1 & 0x80;
}
pro_csr = v10;
result = 0LL;
}
else
{
v9 = pro_csr;
LOBYTE(v9) = pro_csr & 0x7F;
pro_csr = a1 & 0x80 | v9;
result = 0LL;
}
}
}
else
{
result = 32LL;
if ( (a2 & 0x3FFFFEu) > 0x3FF73F )
{
if ( ((1LL << ((unsigned __int8)v8 - 64)) & 0x55) != 0 )
{
pro_kb_wr();
result = 0LL;
}
else
{
result = 32LL;
}
}
}
}
else if ( (a2 & 0x3FFFFEu) > 0x3FF6BF )
{
switch ( v8 )
{
case 4191936:
case 4191938:
case 4191940:
case 4191942:
case 4191944:
case 4191946:
case 4191948:
pro_com_wr();
result = 0LL;
break;
case 4192000:
case 4192002:
case 4192004:
case 4192006:
pro_ptr_wr();
result = 0LL;
break;
default:
result = 32LL;
break;
}
}
else if ( (unsigned int)(v8 - 4191744) > 0x1A )
{
result = 32LL;
}
else
{
switch ( v8 )
{
case 4191744:
case 4191746:
case 4191748:
case 4191750:
case 4191752:
case 4191754:
case 4191756:
case 4191758:
case 4191760:
case 4191762:
case 4191764:
case 4191766:
case 4191768:
case 4191770:
pro_clk_wr();
result = 0LL;
break;
default:
result = 32LL;
break;
}
}
}
else if ( (a2 & 0x3FFFFEu) > 0x3FF916 )
{
if ( (a2 & 0x3FFFFEu) > 0x3FFF76 )
{
result = 32 * (unsigned int)(v8 != 4194280);
}
else if ( (a2 & 0x3FFFFEu) > 0x3FFF6F )
{
if ( ((1LL << ((unsigned __int8)v8 - 112)) & 0x55) != 0 )
{
pro_maint_wr();
result = 0LL;
}
else
{
result = 32LL;
}
}
else
{
result = 32LL;
if ( v8 == 4192642 )
{
LABEL_36:
pro_vid_wr();
result = 0LL;
}
}
}
else if ( (a2 & 0x3FFFFEu) > 0x3FF881 )
{
switch ( v8 )
{
case 4192386:
case 4192388:
case 4192390:
case 4192392:
case 4192394:
case 4192398:
case 4192400:
case 4192402:
case 4192404:
case 4192406:
pro_rx_wr();
result = 0LL;
break;
case 4192514:
case 4192516:
case 4192518:
case 4192520:
case 4192522:
case 4192524:
case 4192526:
case 4192528:
case 4192530:
case 4192532:
case 4192534:
goto LABEL_36;
default:
result = 32LL;
break;
}
}
else if ( (unsigned int)(v8 - 4192258) > 0xE )
{
result = 32LL;
}
else
{
switch ( v8 )
{
case 4192258:
case 4192260:
case 4192262:
case 4192264:
case 4192266:
case 4192268:
case 4192270:
case 4192272:
pro_rd_wr();
result = 0LL;
break;
default:
result = 32LL;
break;
}
}
}
}
else if ( a3 == 4 )
{
if ( (a2 & 1) != 0 )
{
v6 = BATRAM[(a2 - 4191772) >> 1];
}
else
{
v7 = BATRAM[(a2 - 4191772) >> 1];
LOBYTE(v7) = 0;
v6 = v7 | a1;
}
BATRAM[(a2 - 4191772) >> 1] = v6;
result = 0LL;
}
else
{
v3 = (a2 - 4191772) >> 1;
v4 = BATRAM[v3];
LOBYTE(v4) = 0;
BATRAM[v3] = a1 | v4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, int a2, int a3)
{
__int64 v3; // rsi
__int16 v4; // ax
__int64 result; // rax
__int16 v6; // di
__int16 v7; // ax
int v8; // ecx
int v9; // eax
int v10; // eax
unsigned int v11; // eax

if ( (unsigned int)(a2 - 4191772) > 0x63 )
{
if ( (unsigned int)(a2 - 4191872) <= 0xB )
{
pro_int_wr();
result = 0LL;
}
else
{
v8 = a2 & 0x3FFFFE;
if ( (a2 & 0x3FFFFE) == 4192196 )
{
if ( a3 == 4 )
{
v11 = pro_led;
if ( (a2 & 1) == 0 )
v11 = a1 & 0xF | pro_led & 0xFFFFFFF0;
pro_led = v11;
result = 0LL;
}
else
{
pro_led = a1 & 0xF | pro_led & 0xFFFFFFF0;
result = 0LL;
}
}
else if ( (a2 & 0x3FFFFEu) <= 0x3FF7C4 )
{
if ( (a2 & 0x3FFFFEu) > 0x3FF706 )
{
if ( (a2 & 0x3FFFFEu) > 0x3FF746 )
{
result = 32LL;
if ( v8 == 4192192 )
{
if ( a3 == 4 )
{
v10 = pro_csr;
if ( (a2 & 1) == 0 )
{
LOBYTE(v10) = pro_csr & 0x7F;
v10 |= a1 & 0x80;
}
pro_csr = v10;
result = 0LL;
}
else
{
v9 = pro_csr;
LOBYTE(v9) = pro_csr & 0x7F;
pro_csr = a1 & 0x80 | v9;
result = 0LL;
}
}
}
else
{
result = 32LL;
if ( (a2 & 0x3FFFFEu) > 0x3FF73F )
{
if ( ((1LL << ((unsigned __int8)v8 - 64)) & 0x55) != 0 )
{
pro_kb_wr();
result = 0LL;
}
else
{
result = 32LL;
}
}
}
}
else if ( (a2 & 0x3FFFFEu) > 0x3FF6BF )
{
switch ( v8 )
{
case 4191936:
case 4191938:
case 4191940:
case 4191942:
case 4191944:
case 4191946:
case 4191948:
pro_com_wr();
result = 0LL;
break;
case 4192000:
case 4192002:
case 4192004:
case 4192006:
pro_ptr_wr();
result = 0LL;
break;
default:
result = 32LL;
break;
}
}
else if ( (unsigned int)(v8 - 4191744) > 0x1A )
{
result = 32LL;
}
else
{
switch ( v8 )
{
case 4191744:
case 4191746:
case 4191748:
case 4191750:
case 4191752:
case 4191754:
case 4191756:
case 4191758:
case 4191760:
case 4191762:
case 4191764:
case 4191766:
case 4191768:
case 4191770:
pro_clk_wr();
result = 0LL;
break;
default:
result = 32LL;
break;
}
}
}
else if ( (a2 & 0x3FFFFEu) > 0x3FF916 )
{
if ( (a2 & 0x3FFFFEu) > 0x3FFF76 )
{
result = 32 * (unsigned int)(v8 != 4194280);
}
else if ( (a2 & 0x3FFFFEu) > 0x3FFF6F )
{
if ( ((1LL << ((unsigned __int8)v8 - 112)) & 0x55) != 0 )
{
pro_maint_wr();
result = 0LL;
}
else
{
result = 32LL;
}
}
else
{
result = 32LL;
if ( v8 == 4192642 )
{
LABEL_36:
pro_vid_wr();
result = 0LL;
}
}
}
else if ( (a2 & 0x3FFFFEu) > 0x3FF881 )
{
switch ( v8 )
{
case 4192386:
case 4192388:
case 4192390:
case 4192392:
case 4192394:
case 4192398:
case 4192400:
case 4192402:
case 4192404:
case 4192406:
pro_rx_wr();
result = 0LL;
break;
case 4192514:
case 4192516:
case 4192518:
case 4192520:
case 4192522:
case 4192524:
case 4192526:
case 4192528:
case 4192530:
case 4192532:
case 4192534:
goto LABEL_36;
default:
result = 32LL;
break;
}
}
else if ( (unsigned int)(v8 - 4192258) > 0xE )
{
result = 32LL;
}
else
{
switch ( v8 )
{
case 4192258:
case 4192260:
case 4192262:
case 4192264:
case 4192266:
case 4192268:
case 4192270:
case 4192272:
pro_rd_wr();
result = 0LL;
break;
default:
result = 32LL;
break;
}
}
}
}
else if ( a3 == 4 )
{
if ( (a2 & 1) != 0 )
{
v6 = BATRAM[(a2 - 4191772) >> 1];
}
else
{
v7 = BATRAM[(a2 - 4191772) >> 1];
LOBYTE(v7) = 0;
v6 = v7 | a1;
}
BATRAM[(a2 - 4191772) >> 1] = v6;
result = 0LL;
}
else
{
v3 = (a2 - 4191772) >> 1;
v4 = BATRAM[v3];
LOBYTE(v4) = 0;
BATRAM[v3] = a1 | v4;
result = 0LL;
}
return result;
}


decompiled_code:
__int64 __fastcall pro_mem_rd(int a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3FFFFE;
result = 16LL;
if ( v1 != 4192772 )
{
result = (unsigned int)pro_mem_cmd;
if ( v1 != 4192774 )
{
result = 0LL;
if ( v1 == 4192768 )
{
result = (unsigned __int16)MEMROM[pro_mem_ptr];
pro_mem_ptr = ((_WORD)pro_mem_ptr + 1) & 0x3FF;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // edi
__int64 result; // rax

v1 = a1 & 0x3FFFFE;
result = 16LL;
if ( v1 != 4192772 )
{
result = (unsigned int)pro_mem_cmd;
if ( v1 != 4192774 )
{
result = 0LL;
if ( v1 == 4192768 )
{
result = (unsigned __int16)MEMROM[pro_mem_ptr];
pro_mem_ptr = ((_WORD)pro_mem_ptr + 1) & 0x3FF;
}
}
}
return result;
}

original_code:
int pro_mem_rd (int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017775000:
     data = MEMROM[pro_mem_ptr++];
     pro_mem_ptr &= 01777;
     break;
   case 017775004:
     data = 020;
     break;
   case 017775006:
     data = pro_mem_cmd;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}

canonical_original_code:
int pro_mem_rd(int pa)
{
int data;
 switch (pa & 017777776)
 {
   case 017775000:
     data = MEMROM[pro_mem_ptr++];
     pro_mem_ptr &= 01777;
     break;
   case 017775004:
     data = 020;
     break;
   case 017775006:
     data = pro_mem_cmd;
     break;
   default:
     data = 0;
     break;
 }
 return data;
}


decompiled_code:
char __fastcall pro_mem_wr(char a1, int a2, int a3)
{
int v3; // eax

v3 = a2 & 0x3FFFFE;
if ( (a2 & 0x3FFFFE) == 4192770 )
{
pro_mem_ptr = 0;
}
else if ( v3 == 4192774 )
{
if ( a3 == 4 )
{
v3 = pro_mem_cmd;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = pro_mem_cmd & 0x78;
v3 |= a1 & 0x87;
}
pro_mem_cmd = v3;
}
else
{
v3 = pro_mem_cmd;
LOBYTE(v3) = pro_mem_cmd & 0x78;
pro_mem_cmd = v3 | a1 & 0x87;
}
}
return v3;
}

canonical_decompiled_code:
char __fastcall func1(char a1, int a2, int a3)
{
int v3; // eax

v3 = a2 & 0x3FFFFE;
if ( (a2 & 0x3FFFFE) == 4192770 )
{
pro_mem_ptr = 0;
}
else if ( v3 == 4192774 )
{
if ( a3 == 4 )
{
v3 = pro_mem_cmd;
if ( (a2 & 1) == 0 )
{
LOBYTE(v3) = pro_mem_cmd & 0x78;
v3 |= a1 & 0x87;
}
pro_mem_cmd = v3;
}
else
{
v3 = pro_mem_cmd;
LOBYTE(v3) = pro_mem_cmd & 0x78;
pro_mem_cmd = v3 | a1 & 0x87;
}
}
return v3;
}


decompiled_code:
void pro_mem_reset()
{
pro_mem_ptr = 0;
pro_mem_cmd = 32;
}

canonical_decompiled_code:
void func2()
{
pro_mem_ptr = 0;
pro_mem_cmd = 32;
}

original_code:
void pro_mem_reset ()
{
 pro_mem_ptr = 0;
 pro_mem_cmd = 040;
}

canonical_original_code:
void pro_mem_reset()
{
 pro_mem_ptr = 0;
 pro_mem_cmd = 040;
}


decompiled_code:
void pro_mem_exit()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void pro_mem_exit ()
{
}

canonical_original_code:
void pro_mem_exit()
{
}


decompiled_code:
__int64 __fastcall pro_eq_sched(char a1, int a2)
{
int v2; // esi
int v3; // ecx
__int64 result; // rax

v2 = pro_eq_ptr + a2;
v3 = v2 + 11;
while ( 1 )
{
result = v2 & 0x7FFFF;
if ( !PRO_EQ[result] )
break;
if ( ++v2 == v3 )
return result;
}
PRO_EQ[v2 & 0x7FFFF] = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2)
{
int v2; // esi
int v3; // ecx
__int64 result; // rax

v2 = pro_eq_ptr + a2;
v3 = v2 + 11;
while ( 1 )
{
result = v2 & 0x7FFFF;
if ( !PRO_EQ[result] )
break;
if ( ++v2 == v3 )
return result;
}
PRO_EQ[v2 & 0x7FFFF] = a1;
return result;
}

original_code:
void pro_eq_sched (int eventnum, int interval)
{
int i, j;
 for(i=0; i<11; i++)
 {
   j = (pro_eq_ptr + interval + i) & ((1<<19) - 1);
   if (PRO_EQ[j] == 0)
   {
     PRO_EQ[j] = eventnum;
     break;
   }
 }
}

canonical_original_code:
void pro_eq_sched(int eventnum, int interval)
{
int i; int j;
 for(i=0; i<11; i++)
 {
   j = (pro_eq_ptr + interval + i) & ((1<<19) - 1);
   if (PRO_EQ[j] == 0)
   {
     PRO_EQ[j] = eventnum;
     break;
   }
 }
}

variable_types: eventnum int

variable_types: i int

variable_types: j int


decompiled_code:
void *pro_eq_reset()
{
void *result; // rax

result = memset(PRO_EQ, 0, (size_t)&unk_80000);
pro_eq_ptr = 0;
return result;
}

canonical_decompiled_code:
void *func1()
{
void *result; // rax

result = memset(PRO_EQ, 0, (size_t)&unk_80000);
pro_eq_ptr = 0;
return result;
}

original_code:
void pro_eq_reset ()
{
 memset(&PRO_EQ, 0, sizeof(PRO_EQ));
 pro_eq_ptr = 0;
}

canonical_original_code:
void pro_eq_reset()
{
 memset(&PRO_EQ, 0, sizeof(PRO_EQ));
 pro_eq_ptr = 0;
}


jenkins

repo: Cecca/gdem

original_code:
unsigned long long int jenkins(unsigned long long int x, unsigned long long int seed ) {
  unsigned long long int a = seed + x;
  unsigned long long int b = seed;
  unsigned long long int c = 0x9e3779b97f4a7c13L;
  a -= b; a -= c; a ^= c >> 43;
  b -= c; b -= a; b ^= a << 9;
  c -= a; c -= b; c ^= b >> 8;
  a -= b; a -= c; a ^= c >> 38;
  b -= c; b -= a; b ^= a << 23;
  c -= a; c -= b; c ^= b >> 5;
  a -= b; a -= c; a ^= c >> 35;
  b -= c; b -= a; b ^= a << 49;
  c -= a; c -= b; c ^= b >> 11;
  a -= b; a -= c; a ^= c >> 12;
  b -= c; b -= a; b ^= a << 18;
  c -= a; c -= b; c ^= b >> 22;
  return c;
}

canonical_original_code:
unsigned long long jenkins(unsigned long long x, unsigned long long seed) {
  unsigned long long a = seed + x;
  unsigned long long b = seed;
  unsigned long long c = 0x9e3779b97f4a7c13L;
  a -= b; a -= c; a ^= c >> 43;
  b -= c; b -= a; b ^= a << 9;
  c -= a; c -= b; c ^= b >> 8;
  a -= b; a -= c; a ^= c >> 38;
  b -= c; b -= a; b ^= a << 23;
  c -= a; c -= b; c ^= b >> 5;
  a -= b; a -= c; a ^= c >> 35;
  b -= c; b -= a; b ^= a << 49;
  c -= a; c -= b; c ^= b >> 11;
  a -= b; a -= c; a ^= c >> 12;
  b -= c; b -= a; b ^= a << 18;
  c -= a; c -= b; c ^= b >> 22;
  return c;
}

variable_types:
x
unsigned long long

variable_types:
seed
unsigned long long

variable_types:
a
unsigned long long

variable_types:
b
unsigned long long

variable_types:
c
unsigned long long

return_type: unsigned long long


decompiled_code:
void *__fastcall hll_cnt_init(__int64 a1, __int64 a2)
{
int v3; // eax
void *v4; // rdi

*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = 1 << a2;
v3 = -1;
if ( a2 )
v3 = ~(-1 << (32 - a2));
*(_DWORD *)(a1 + 12) = v3;
v4 = malloc(1 << a2);
*(_QWORD *)(a1 + 16) = v4;
if ( !v4 )
{
fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58LL);
exit(1);
}
return memset(v4, 0, 1 << a2);
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2)
{
int v3; // eax
void *v4; // rdi

*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = 1 << a2;
v3 = -1;
if ( a2 )
v3 = ~(-1 << (32 - a2));
*(_DWORD *)(a1 + 12) = v3;
v4 = malloc(1 << a2);
*(_QWORD *)(a1 + 16) = v4;
if ( !v4 )
{
fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58LL);
exit(1);
}
return memset(v4, 0, 1 << a2);
}

original_code:
inline void hll_cnt_init (hll_counter_t *counter, size_t bits) {
  ((void) (0));
  counter->b = bits;
  counter->m = 1 << bits;
  if (bits != 0) {
    counter->mask = ~(~0 << (sizeof(hll_hash_t)*8 - bits));
  } else {
    counter->mask = ~0;
  }
  size_t mem = counter->m*sizeof(hll_reg_t);
  counter->registers = (hll_reg_t*) malloc(mem);
  if(counter->registers == 0) { fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58); exit(1); };
  memset(counter->registers, 0, mem);
}

canonical_original_code:
inline void hll_cnt_init(struct hll_counter *counter, unsigned long bits) {
  ((void) (0));
  counter->b = bits;
  counter->m = 1 << bits;
  if (bits != 0) {
    counter->mask = ~(~0 << (sizeof(hll_hash_t)*8 - bits));
  } else {
    counter->mask = ~0;
  }
  unsigned long mem = counter->m*sizeof(hll_reg_t);
  counter->registers = (unsigned char *) malloc(mem);
  if(counter->registers == 0) { fprintf(stderr, "Could not allocate memory successfully %s, %d", "hll_counter.c", 58); exit(1); };
  memset(counter->registers, 0, mem);
}

variable_types: struct hll_counter { unsigned long m; unsigned int b; unsigned int mask; unsigned char *registers; } *

variable_types:
bits
unsigned long

variable_types:
mem
unsigned long


decompiled_code:
void __fastcall hll_cnt_free(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
inline void hll_cnt_free (hll_counter_t * counter) {
  ((void) (0));
  free(counter->registers);
}

canonical_original_code:
inline void hll_cnt_free(struct hll_counter *counter) {
  ((void) (0));
  free(counter->registers);
}

user_defined_types: struct hll_counter { unsigned long m; unsigned int b; unsigned int mask; unsigned char *registers; }