Advertisement
xerpi

SceTouch 0990 CEX RE

Sep 20th, 2020 (edited)
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.23 KB | None | 0 0
  1. int SceTouchAlarm0_func(void)
  2. {
  3.     int prev_state;
  4.  
  5.     prev_state = ksceKernelCpuSuspendIntr(&g_intr);
  6.     new_touch_data(0, 0, 0);
  7.     g_sce_touch_alarm0 = -1;
  8.     ksceKernelCpuResumeIntr(&g_intr, prev_state);
  9.     return 0;
  10. }
  11.  
  12. int syscon_cb_1(SceSysconPacket *packet,SceSysconPacket *argp)
  13. {
  14.     ushort cmd;
  15.     int prev_state;
  16.     uint mask;
  17.    
  18.     if (argp == NULL)
  19.         return -1;
  20.  
  21.     prev_state = ksceKernelCpuSuspendIntr(&g_intr);
  22.    
  23.     if (*(short *)&argp[1].next != 1) {
  24.         ksceKernelCpuResumeIntr(&g_intr, prev_state);
  25.         return -1;
  26.     }
  27.    
  28.     *(short *)&argp[1].next = 0;
  29.     cmd = packet->tx[0] | (packet->tx[1] << 8);
  30.    
  31.     if (cmd == 0x300) {
  32.         mask = 3;
  33.     } else if (cmd == 0x301) {
  34.         mask = 1;
  35.     } else if (cmd == 0x302) {
  36.         mask = 2;
  37.     } else {
  38.         ksceKernelCpuResumeIntr(&g_intr, prev_state);
  39.         return -1;
  40.     }
  41.        
  42.     new_touch_data(mask, packet->unk1[1], packet->unk1[2]);
  43.     ksceKernelCpuResumeIntr(&g_intr, prev_state);
  44.     return 0;
  45. }
  46.  
  47. int syscon_cb_2(SceSysconPacket *packet, SceSysconPacket *argp)
  48. {
  49.     ushort cmd;
  50.     bool set_flag;
  51.     int prev_state;
  52.     uint time_low;
  53.     uint cur_enabled;
  54.     uint diff_enabled;
  55.     bool send;
  56.  
  57.     if (argp == NULL)
  58.         return -1;
  59.  
  60.     prev_state = ksceKernelCpuSuspendIntr(&g_intr);
  61.     if (*(short *)&argp[1].next != 1) {
  62.         ksceKernelCpuResumeIntr(&g_intr, prev_state);
  63.         return -1;
  64.     }
  65.    
  66.     *(short *)&argp[1].next = 0;
  67.    
  68.     cmd = packet->tx[0] | (packet->tx[1] << 8);
  69.     if (cmd == 0x381) {
  70.         cur_enabled = 0
  71.  
  72.         if (argp->tx[3] != 0)
  73.             cur_enabled |= 1;  
  74.         if (argp->tx[5] != 0)
  75.             cur_enabled |= 2;
  76.  
  77.         diff_enabled = cur_enabled ^ g_enabled_port_mask;
  78.         g_enabled_port_mask = cur_enabled;
  79.        
  80.         time_low = ksceKernelGetSystemTimeLow();
  81.        
  82.         if ((g_enabled_port_mask & 1) && (diff_enabled & 1))
  83.             g_front_enabled_time = time_low;
  84.  
  85.         if ((g_enabled_port_mask & 2) && (diff_enabled & 2))
  86.             g_back_enabled_time = time_low;
  87.        
  88.         if (g_baryon_version < 0x90003) {
  89.             set_flag = true;
  90.             send = false;
  91.         } else {
  92.             if (diff_enabled & 1) {
  93.                 if (g_enabled_port_mask & 1)
  94.                     g_cur_front_cmd = g_enable_front_cmd;
  95.                 else
  96.                     g_cur_front_cmd = 0;
  97.             }
  98.            
  99.             if (diff_enabled & 2) {
  100.                 if (g_enabled_port_mask & 2)
  101.                     g_cur_back_cmd = g_enable_back_cmd;
  102.                 else
  103.                     g_cur_back_cmd = 0
  104.             }
  105.            
  106.             set_flag = false;
  107.             argp->tx[0] = 0x87;
  108.             argp->tx[1] = 3;
  109.             argp->tx[2] = 9;
  110.             argp->tx[3] = diff_enabled & 1;
  111.             argp->tx[4] = g_cur_front_cmd;
  112.             argp->tx[5] = 0;
  113.             argp->tx[6] = 0;
  114.             argp->tx[7] = (diff_enabled >> 1) & 1;
  115.             argp->tx[8] = g_cur_back_cmd;
  116.             argp->tx[9] = 0;
  117.             argp->tx[10] = 0;
  118.             *(short *)&argp[1].next = 1;
  119.             *(short *)((int)&argp[1].next + 2) = 0;
  120.             send = true;
  121.         }
  122.     } else if (cmd == 0x387) {
  123.         if (argp->tx[3])
  124.             g_front_sampling = g_cur_front_cmd;
  125.  
  126.         if (argp->tx[7])
  127.             g_back_sampling = g_cur_back_cmd;
  128.  
  129.         send = !argp->tx[7];
  130.         set_flag = true;
  131.     } else {
  132.         ksceKernelCpuResumeIntr(&g_intr,prev_state);
  133.         return -1;
  134.     }
  135.    
  136.     if (g_touch_status == 4) {
  137.         if (g_enabled_port_mask != 0) {
  138.             set_flag = false;
  139.         }
  140.         if (set_flag) {
  141.             if (g_SceTouchUpdate_evflag_uid != -1) {
  142.                 ksceKernelSetEventFlag(g_SceTouchUpdate_evflag_uid, 1);
  143.             }
  144.             ksceKernelCpuResumeIntr(&g_intr, prev_state);
  145.             return 0;
  146.         }
  147.     }
  148.    
  149.     ksceKernelCpuResumeIntr(&g_intr,prev_state);
  150.  
  151.     if (send) {
  152.         prev_state = ksceSysconCmdExecAsync(argp, 0, syscon_cb_2, argp);
  153.         if (prev_state < 0) {
  154.             *(short *)&argp[1].next = 0;
  155.         }
  156.     }
  157.    
  158.     return 0;
  159. }
  160.  
  161. #define FRONT (1u << 0)
  162. #define BACK  (1u << 1)
  163. #define FAKE  (1u << 2)
  164.  
  165. int SceTouchVblank_handler(void)
  166. {
  167.     int prev_state;
  168.     uint uVar3;
  169.     uint change_back;
  170.     byte tx4;
  171.     uint send_front_packet;
  172.     uint uVar4;
  173.     uint back_set_status;
  174.     uint change_front;
  175.    
  176.     prev_state = ksceKernelCpuSuspendIntr(&g_intr);
  177.  
  178.     if (g_front_packet_pending) {
  179.         uVar3 = FAKE;
  180.         uVar4 = FRONT;
  181.         send_front_packet = 0;
  182.         g_retries_front = g_retries_front + 1; 
  183.     } else {
  184.         if (g_touch_status == 2) {
  185.             required_mask = 0
  186.             if (g_front_panel_present)
  187.                 required_mask |= 1;
  188.             if (g_back_panel_present)
  189.                 required_mask |= 2;
  190.  
  191.             if (g_baryon_version < 0x40000) {
  192.                 uVar3 = FAKE;
  193.                 uVar4 = FRONT;
  194.                 send_front_packet = 0;
  195.             } else {
  196.                 if (g_enabled_port_mask == required_mask) {
  197.                     if (g_baryon_version < 0x90003) {
  198.                         uVar3 = FAKE;
  199.                         uVar4 = FRONT;
  200.                         send_front_packet = 0;
  201.                     } else {
  202.                         // Front
  203.                         if (g_enabled_port_mask & 1) {
  204.                             if (BYTE_8100bb0e != 0) {
  205.                                 if (BYTE_8100bb0e == 2) {
  206.                                     g_cur_front_cmd = g_front_packet_size;
  207.                                 } else if (BYTE_8100bb0e != 3) {
  208.                                     g_cur_front_cmd = g_enable_front_cmd;
  209.                                 }
  210.                                 g_cur_front_cmd = 0;
  211.                             }
  212.                             BYTE_8100bb0e = 0;
  213.                         }
  214.                         // Back
  215.                         if (g_enabled_port_mask & 2) {
  216.                             if (BYTE_8100bbf6 != 0) {
  217.                                 if (BYTE_8100bbf6 == 2) {
  218.                                     g_cur_back_cmd = g_back_packet_size;
  219.                                 } else if (BYTE_8100bbf6 != 3) {
  220.                                     g_cur_back_cmd = g_enable_back_cmd;
  221.                                 }
  222.                                 g_cur_back_cmd = 0;
  223.                             }
  224.                             BYTE_8100bbf6 = 0;
  225.                         }
  226.                         change_front = g_front_sampling != g_cur_front_cmd;
  227.                         change_back = g_back_sampling != g_cur_back_cmd;
  228.                         if (change_front || change_back) {
  229.                             g_front_packet_pending = 1;
  230.                             g_packet1.tx[0] = 0x87;
  231.                             g_packet1.tx[1] = 3;
  232.                             g_packet1.tx[2] = 9;
  233.                             g_packet1.tx[3] = change_front;
  234.                             g_packet1.tx[4] = g_cur_front_cmd;
  235.                             g_packet1.tx[5] = 0;
  236.                             g_packet1.tx[6] = 0;
  237.                             g_packet1.tx[7] = change_back;
  238.                             g_packet1.tx[8] = g_cur_back_cmd;
  239.                             g_packet1.tx[9] = 0;
  240.                             g_packet1.tx[10] = 0;
  241.                             g_retries_front = 0;
  242.                             uVar3 = BACK | FAKE;
  243.                             uVar4 = FRONT | BACK;
  244.                             send_front_packet = BACK;
  245.                         } else {
  246.                             uVar3 = FAKE;
  247.                             uVar4 = FRONT;
  248.                             send_front_packet = 0;
  249.                         }
  250.    
  251.                     }
  252.                 } else { /* g_enabled_port_mask != required_mask */
  253.                     uint8_t cmd4 = 0;
  254.                     uint8_t cmd6 = 0;
  255.                     if (required_mask != 0) {
  256.                         uVar4 = required_mask & 3;
  257.                         if ((uVar4 == 2) || (uVar4 == 3)) {
  258.                             cmd4 = 0;
  259.                             cmd6 = g_back_vendor_id_dependant;
  260.                         } else {
  261.                             if (uVar4 == 1) {
  262.                                 cmd4 = g_front_vendor_id_non_dependant;
  263.                                 cmd6 = 0;
  264.                             } else {
  265.                                 cmd4 = 0;
  266.                                 cmd6 = 0;
  267.                             }
  268.                         }
  269.                     }
  270.                     g_packet1.tx[0] = 0x81;
  271.                     g_packet1.tx[1] = 3;
  272.                     g_packet1.tx[2] = 5;
  273.                     g_packet1.tx[3] = required_mask & 1;
  274.                     g_packet1.tx[4] = cmd4 | g_cmd_byte_1;
  275.                     g_packet1.tx[5] = (required_mask >> 1) & 1;
  276.                     g_packet1.tx[6] = cmd6 | g_cmd_byte_2;
  277.                     g_retries_front = 0;
  278.                     g_front_packet_pending = 1;
  279.                     uVar3 = BACK | FAKE;
  280.                     uVar4 = FRONT | BACK;
  281.                     send_front_packet = BACK;
  282.                 }
  283.             }
  284.         } else { /* g_touch_status != 2 */
  285.             if (((g_touch_status != 3) && (g_touch_status != 1) && (g_touch_status != 4)) || (g_enabled_port_mask == 0)) {
  286.                 uVar3 = FAKE;
  287.                 uVar4 = FRONT;
  288.                 send_front_packet = 0;
  289.             } else {
  290.                 g_packet1.tx[0] = 0x81;
  291.                 g_packet1.tx[1] = 3;
  292.                 g_packet1.tx[2] = 5;
  293.                 g_packet1.tx[3] = 0;
  294.                 g_packet1.tx[4] = g_cmd_byte_1;
  295.                 g_packet1.tx[5] = 0;
  296.                 g_packet1.tx[6] = g_cmd_byte_2;
  297.                 g_retries_front = 0;
  298.                 g_front_packet_pending = 1;
  299.                 uVar3 = BACK | FAKE;
  300.                 uVar4 = FRONT | BACK;
  301.                 send_front_packet = BACK;
  302.             }
  303.         }
  304.     }
  305.  
  306.     if (g_back_packet_pending) {
  307.         uVar4 = send_front_packet;
  308.         g_retries_back = g_retries_back + 1;
  309.     } else {
  310.         if ((g_touch_status != 2) || (g_enabled_port_mask == 0)) {
  311.             uVar4 = send_front_packet;
  312.             if (g_sce_touch_alarm0 == -1) {
  313.                 uVar4 = uVar3;
  314.             }
  315.         } else {
  316.             if (g_enabled_port_mask == 1)
  317.                  g_packet2.tx[0] = 1;
  318.             else if (g_enabled_port_mask == 2)
  319.                  g_packet2.tx[0] = 2;
  320.             else
  321.                 g_packet2.tx[0] = 0;
  322.             g_packet2.tx[1] = 3;
  323.             g_packet2.tx[2] = 1;
  324.             g_retries_back = 0;
  325.             g_back_packet_pending = 1;
  326.         }
  327.     }
  328.    
  329.     ksceKernelCpuResumeIntr(&g_intr, prev_state);
  330.  
  331.     if ((uVar4 & FRONT) && (ret = ksceSysconCmdExecAsync(&g_packet2, 0x400, syscon_cb_1, &g_packet2), ret < 0)) {
  332.         g_back_packet_pending = 0;
  333.     }
  334.     if ((uVar4 & BACK) && (ret = ksceSysconCmdExecAsync(&g_packet1, 0, syscon_cb_2, &g_packet1), ret < 0)) {
  335.         g_front_packet_pending = 0;
  336.     }
  337.     if (uVar4 & FAKE) {
  338.         g_sce_touch_alarm0 = ksceKernelRegisterTimer("SceTouchAlarm0", 1000, SceTouchAlarm0_func);
  339.     }
  340.     return -1;
  341. }
  342.  
  343.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement