Initial rebase of xerpi's port
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221
diff --git a/Makefile.vita.dolce b/Makefile.vita.dolce
new file mode 100644
index 0000000..c9ca1ca
--- /dev/null
+++ b/Makefile.vita.dolce
@@ -0,0 +1,59 @@
+# Based on port by xerpi
+# Makefile to build the SDL library
+
+TARGET_LIB = libSDL2.a
+
+SOURCES = \
+ src/*.c \
+ src/atomic/*.c \
+ src/audio/*.c \
+ src/audio/vita/*.c \
+ src/cpuinfo/*.c \
+ src/events/*.c \
+ src/file/*.c \
+ src/haptic/*.c \
+ src/haptic/dummy/*.c \
+ src/joystick/*.c \
+ src/joystick/vita/*.c \
+ src/loadso/dummy/*.c \
+ src/power/*.c \
+ src/power/vita/*.c \
+ src/filesystem/dummy/*.c \
+ src/render/*.c \
+ src/render/software/*.c \
+ src/render/opengles2/SDL_render_gles2.c \
+ src/render/vita/*.c \
+ src/sensor/*.c \
+ src/sensor/dummy/*.c \
+ src/stdlib/*.c \
+ src/thread/*.c \
+ src/thread/generic/SDL_systls.c \
+ src/thread/vita/*.c \
+ src/timer/*.c \
+ src/timer/vita/*.c \
+ src/video/*.c \
+ src/video/vita/*.c \
+ src/video/yuv2rgb/*.c \
+
+OBJS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
+
+PREFIX = arm-dolce-eabi
+CC = $(PREFIX)-gcc
+AR = $(PREFIX)-ar
+CFLAGS = -g -Wl,-q -Wall -O3 -Iinclude \
+ -D__VITA__ -D__ARM_ARCH=7 -D__ARM_ARCH_7A__ \
+ -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=hard
+ASFLAGS = $(CFLAGS)
+
+$(TARGET_LIB): $(OBJS)
+ $(AR) rcs $@ $^
+
+clean:
+ @rm -f $(TARGET_LIB) $(OBJS)
+
+install: $(TARGET_LIB)
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/lib"
+ @cp $(TARGET_LIB) $(DOLCESDK)/arm-dolce-eabi/lib
+ @mkdir -p "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @cp include/*.h "$(DOLCESDK)/arm-dolce-eabi/include/SDL2"
+ @echo "Installed!"
diff --git a/include/SDL_config.h b/include/SDL_config.h
index 378e180..0c3f56f 100644
--- a/include/SDL_config.h
+++ b/include/SDL_config.h
@@ -43,6 +43,8 @@
#include "SDL_config_psp.h"
#elif defined(__OS2__)
#include "SDL_config_os2.h"
+#elif defined(__VITA__)
+#include "SDL_config_vita.h"
#else
/* This is a minimal configuration just to get SDL running on new platforms. */
#include "SDL_config_minimal.h"
diff --git a/include/SDL_config_vita.h b/include/SDL_config_vita.h
new file mode 100644
index 0000000..d03aae3
--- /dev/null
+++ b/include/SDL_config_vita.h
@@ -0,0 +1,158 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SDL_config_vita_h
+#define _SDL_config_vita_h
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* include stdint.h here, needed on Vita to compile the yuv_rgb.h */
+#include <stdint.h>
+
+#ifdef __GNUC__
+#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1
+#endif
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_EXP 1
+#define HAVE_EXPF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+/* #define HAVE_SYSCONF 1 */
+/* #define HAVE_SIGACTION 1 */
+
+
+/* VITA isn't that sophisticated */
+#define LACKS_SYS_MMAN_H 1
+
+
+#define SDL_AUDIO_DRIVER_VITA 1
+#define SDL_THREAD_VITA 1
+#define SDL_JOYSTICK_VITA 1
+#define SDL_TIMERS_VITA 1
+#define SDL_POWER_VITA 1
+#define SDL_VIDEO_DRIVER_VITA 1
+
+
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#define SDL_VIDEO_OPENGL_ES2 1
+
+
+/* !!! FIXME: what does VITA do for filesystem stuff? */
+#define SDL_FILESYSTEM_DUMMY 1
+
+/* VITA doesn't have haptic device (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DISABLED 1
+
+/* VITA can't load shared object (src/loadso/dummy/\*.c) */
+// that' not true, but oh well
+#define SDL_LOADSO_DISABLED 1
+
+#define SDL_SENSOR_DISABLED 1
+#define SDL_SENSOR_DUMMY 1
+
+#endif /* _SDL_config_vita_h */
diff --git a/src/SDL.c b/src/SDL.c
index 124acee..c5cf067 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -527,6 +527,8 @@ SDL_GetPlatform()
return "iOS";
#elif __PSP__
return "PlayStation Portable";
+#elif __VITA__
+ return "PlayStation Vita";
#else
return "Unknown (see SDL_platform.h)";
#endif
diff --git a/src/SDL_log.c b/src/SDL_log.c
index 9a5d1c4..d14c3d2 100644
--- a/src/SDL_log.c
+++ b/src/SDL_log.c
@@ -422,6 +422,13 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
fclose (pFile);
}
+#elif defined(__VITA__)
+ {
+ FILE* pFile;
+ pFile = fopen ("ux0:/data/SDL_Log.txt", "a");
+ fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
+ fclose (pFile);
+ }
#endif
#if HAVE_STDIO_H
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 725e169..00ee976 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -98,6 +98,9 @@ static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_PSP
&PSPAUDIO_bootstrap,
#endif
+#if SDL_AUDIO_DRIVER_VITA
+ &VITAAUD_bootstrap,
+#endif
#if SDL_AUDIO_DRIVER_EMSCRIPTEN
&EMSCRIPTENAUDIO_bootstrap,
#endif
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index 0c66ec6..d7fd556 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -208,6 +208,7 @@ extern AudioBootStrap FUSIONSOUND_bootstrap;
extern AudioBootStrap openslES_bootstrap;
extern AudioBootStrap ANDROIDAUDIO_bootstrap;
extern AudioBootStrap PSPAUDIO_bootstrap;
+extern AudioBootStrap VITAAUD_bootstrap;
extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap;
extern AudioBootStrap OS2AUDIO_bootstrap;
diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c
new file mode 100644
index 0000000..5225b80
--- /dev/null
+++ b/src/audio/vita/SDL_vitaaudio.c
@@ -0,0 +1,203 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_VITA
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+
+#include "SDL_audio.h"
+#include "SDL_error.h"
+#include "SDL_timer.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_vitaaudio.h"
+
+#include <psp2/kernel/threadmgr.h>
+#include <psp2/audioout.h>
+
+#define SCE_AUDIO_SAMPLE_ALIGN(s) (((s) + 63) & ~63)
+#define SCE_AUDIO_MAX_VOLUME 0x8000
+
+/* The tag name used by VITA audio */
+#define VITAAUD_DRIVER_NAME "vita"
+
+static int
+VITAAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ int format, mixlen, i, port = SCE_AUDIO_OUT_PORT_TYPE_MAIN;
+
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc(sizeof(*this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden, 0, sizeof(*this->hidden));
+ switch (this->spec.format & 0xff) {
+ case 8:
+ case 16:
+ this->spec.format = AUDIO_S16LSB;
+ break;
+ default:
+ return SDL_SetError("Unsupported audio format");
+ }
+
+ /* The sample count must be a multiple of 64. */
+ this->spec.samples = SCE_AUDIO_SAMPLE_ALIGN(this->spec.samples);
+
+ /* Update the fragment size as size in bytes. */
+/* SDL_CalculateAudioSpec(this->spec); MOD */
+ switch (this->spec.format) {
+ case AUDIO_U8:
+ this->spec.silence = 0x80;
+ break;
+ default:
+ this->spec.silence = 0x00;
+ break;
+ }
+ this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8;
+ this->spec.size *= this->spec.channels;
+ this->spec.size *= this->spec.samples;
+
+/* ========================================== */
+
+ /* Allocate the mixing buffer. Its size and starting address must
+ be a multiple of 64 bytes. Our sample count is already a multiple of
+ 64, so spec->size should be a multiple of 64 as well. */
+ mixlen = this->spec.size * NUM_BUFFERS;
+ this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
+ if (this->hidden->rawbuf == NULL) {
+ return SDL_SetError("Couldn't allocate mixing buffer");
+ }
+
+ /* Setup the hardware channel. */
+ if (this->spec.channels == 1) {
+ format = SCE_AUDIO_OUT_MODE_MONO;
+ } else {
+ format = SCE_AUDIO_OUT_MODE_STEREO;
+ }
+
+ if(this->spec.freq < 48000) {
+ port = SCE_AUDIO_OUT_PORT_TYPE_BGM;
+ }
+
+ this->hidden->channel = sceAudioOutOpenPort(port, this->spec.samples, this->spec.freq, format);
+ if (this->hidden->channel < 0) {
+ free(this->hidden->rawbuf);
+ this->hidden->rawbuf = NULL;
+ return SDL_SetError("Couldn't reserve hardware channel");
+ }
+
+ memset(this->hidden->rawbuf, 0, mixlen);
+ for (i = 0; i < NUM_BUFFERS; i++) {
+ this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
+ }
+
+ this->hidden->next_buffer = 0;
+ return 0;
+}
+
+static void VITAAUD_PlayDevice(_THIS)
+{
+ Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
+
+ int vols[2] = {SCE_AUDIO_MAX_VOLUME, SCE_AUDIO_MAX_VOLUME};
+ sceAudioOutSetVolume(this->hidden->channel, SCE_AUDIO_VOLUME_FLAG_L_CH|SCE_AUDIO_VOLUME_FLAG_R_CH, vols);
+ sceAudioOutOutput(this->hidden->channel, mixbuf);
+
+ this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
+}
+
+/* This function waits until it is possible to write a full sound buffer */
+static void VITAAUD_WaitDevice(_THIS)
+{
+ /* Because we block when sending audio, there's no need for this function to do anything. */
+}
+static Uint8 *VITAAUD_GetDeviceBuf(_THIS)
+{
+ return this->hidden->mixbufs[this->hidden->next_buffer];
+}
+
+static void VITAAUD_CloseDevice(_THIS)
+{
+ if (this->hidden->channel >= 0) {
+ sceAudioOutReleasePort(this->hidden->channel);
+ this->hidden->channel = -1;
+ }
+
+ if (this->hidden->rawbuf != NULL) {
+ free(this->hidden->rawbuf);
+ this->hidden->rawbuf = NULL;
+ }
+}
+static void VITAAUD_ThreadInit(_THIS)
+{
+ /* Increase the priority of this audio thread by 1 to put it
+ ahead of other SDL threads. */
+ SceUID thid;
+ SceKernelThreadInfo info;
+ thid = sceKernelGetThreadId();
+ info.size = sizeof(SceKernelThreadInfo);
+ if (sceKernelGetThreadInfo(thid, &info) == 0) {
+ sceKernelChangeThreadPriority(thid, info.currentPriority - 1);
+ }
+}
+
+
+static int
+VITAAUD_Init(SDL_AudioDriverImpl * impl)
+{
+
+ /* Set the function pointers */
+ impl->OpenDevice = VITAAUD_OpenDevice;
+ impl->PlayDevice = VITAAUD_PlayDevice;
+ impl->WaitDevice = VITAAUD_WaitDevice;
+ impl->GetDeviceBuf = VITAAUD_GetDeviceBuf;
+ impl->CloseDevice = VITAAUD_CloseDevice;
+ impl->ThreadInit = VITAAUD_ThreadInit;
+
+ /* VITA audio device */
+ impl->OnlyHasDefaultOutputDevice = 1;
+/*
+ impl->HasCaptureSupport = 1;
+
+ impl->OnlyHasDefaultInputDevice = 1;
+*/
+ /*
+ impl->DetectDevices = DSOUND_DetectDevices;
+ impl->Deinitialize = DSOUND_Deinitialize;
+ */
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap VITAAUD_bootstrap = {
+ "vita", "VITA audio driver", VITAAUD_Init, 0
+};
+
+ /* SDL_AUDI */
+
+#endif /* SDL_AUDIO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/audio/vita/SDL_vitaaudio.h b/src/audio/vita/SDL_vitaaudio.h
new file mode 100644
index 0000000..0c1ad52
--- /dev/null
+++ b/src/audio/vita/SDL_vitaaudio.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SDL_vitaaudio_h
+#define _SDL_vitaaudio_h
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+#define NUM_BUFFERS 2
+
+struct SDL_PrivateAudioData {
+ /* The hardware output channel. */
+ int channel;
+ /* The raw allocated mixing buffer. */
+ Uint8 *rawbuf;
+ /* Individual mixing buffers. */
+ Uint8 *mixbufs[NUM_BUFFERS];
+ /* Index of the next available mixing buffer. */
+ int next_buffer;
+};
+
+#endif /* _SDL_vitaaudio_h */
+/* vim: ts=4 sw=4
+ */
diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
index 1f134e1..1668e70 100644
--- a/src/cpuinfo/SDL_cpuinfo.c
+++ b/src/cpuinfo/SDL_cpuinfo.c
@@ -450,6 +450,8 @@ CPU_haveNEON(void)
return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;
#elif (defined(__ARM_ARCH) && (__ARM_ARCH >= 8)) || defined(__aarch64__)
return 1; /* ARMv8 always has non-optional NEON support. */
+#elif __VITA__
+ return 1;
#elif defined(__APPLE__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7)
/* (note that sysctlbyname("hw.optional.neon") doesn't work!) */
return 1; /* all Apple ARMv7 chips and later have NEON. */
diff --git a/src/dynapi/SDL_dynapi.h b/src/dynapi/SDL_dynapi.h
index e8acb7f..2619ff7 100644
--- a/src/dynapi/SDL_dynapi.h
+++ b/src/dynapi/SDL_dynapi.h
@@ -57,6 +57,8 @@
#define SDL_DYNAMIC_API 0
#elif defined(__clang_analyzer__)
#define SDL_DYNAMIC_API 0 /* Turn off for static analysis, so reports are more clear. */
+#elif defined(__VITA__)
+#define SDL_DYNAMIC_API 0 /* vitasdk doesn't support dynamic linking */
#endif
/* everyone else. This is where we turn on the API if nothing forced it off. */
diff --git a/src/joystick/SDL_gamecontrollerdb.h b/src/joystick/SDL_gamecontrollerdb.h
index 9ee4d45..87d3c56 100644
--- a/src/joystick/SDL_gamecontrollerdb.h
+++ b/src/joystick/SDL_gamecontrollerdb.h
@@ -856,6 +856,10 @@ static const char *s_ControllerMappings [] =
#if defined(SDL_JOYSTICK_EMSCRIPTEN)
"default,Standard Gamepad,a:b0,b:b1,back:b8,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b16,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
#endif
+#if defined(SDL_JOYSTICK_VITA)
+ "50535669746120436f6e74726f6c6c65,PSVita Controller,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
+#endif
+ "hidapi,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
NULL
};
diff --git a/src/joystick/vita/SDL_sysjoystick.c b/src/joystick/vita/SDL_sysjoystick.c
new file mode 100644
index 0000000..151e3f8
--- /dev/null
+++ b/src/joystick/vita/SDL_sysjoystick.c
@@ -0,0 +1,310 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_JOYSTICK_VITA
+
+/* This is the PSVita implementation of the SDL joystick API */
+#include <psp2/types.h>
+#include <psp2/ctrl.h>
+#include <psp2/kernel/threadmgr.h>
+
+#include <stdio.h> /* For the definition of NULL */
+#include <stdlib.h>
+
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+
+#include "SDL_events.h"
+#include "SDL_error.h"
+#include "SDL_thread.h"
+#include "SDL_mutex.h"
+#include "SDL_timer.h"
+
+/* Current pad state */
+static SceCtrlData pad0 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 };
+static SceCtrlData pad1 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 };
+static SceCtrlData pad2 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 };
+static SceCtrlData pad3 = { .lx = 0, .ly = 0, .rx = 0, .ry = 0, .buttons = 0 };
+static int port_map[4]= { 0, 2, 3, 4 }; //index: SDL joy number, entry: Vita port number
+static int SDL_numjoysticks = 1;
+static const unsigned int button_map[] = {
+ SCE_CTRL_TRIANGLE, SCE_CTRL_CIRCLE, SCE_CTRL_CROSS, SCE_CTRL_SQUARE,
+ SCE_CTRL_LTRIGGER, SCE_CTRL_RTRIGGER,
+ SCE_CTRL_DOWN, SCE_CTRL_LEFT, SCE_CTRL_UP, SCE_CTRL_RIGHT,
+ SCE_CTRL_SELECT, SCE_CTRL_START};
+static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
+
+typedef struct
+{
+ int x;
+ int y;
+} point;
+
+/* 4 points define the bezier-curve. */
+/* The Vita has a good amount of analog travel, so use a linear curve */
+static point a = { 0, 0 };
+static point b = { 0, 0 };
+static point c = { 128, 32767 };
+static point d = { 128, 32767 };
+
+/* simple linear interpolation between two points */
+static SDL_INLINE void lerp (point *dest, point *a, point *b, float t)
+{
+ dest->x = a->x + (b->x - a->x)*t;
+ dest->y = a->y + (b->y - a->y)*t;
+}
+
+/* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
+static int calc_bezier_y(float t)
+{
+ point ab, bc, cd, abbc, bccd, dest;
+ lerp (&ab, &a, &b, t); /* point between a and b */
+ lerp (&bc, &b, &c, t); /* point between b and c */
+ lerp (&cd, &c, &d, t); /* point between c and d */
+ lerp (&abbc, &ab, &bc, t); /* point between ab and bc */
+ lerp (&bccd, &bc, &cd, t); /* point between bc and cd */
+ lerp (&dest, &abbc, &bccd, t); /* point on the bezier-curve */
+ return dest.y;
+}
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * It should return number of joysticks, or -1 on an unrecoverable fatal error.
+ */
+int SDL_SYS_JoystickInit(void)
+{
+ int i;
+
+ /* Setup input */
+ sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
+
+ /* Create an accurate map from analog inputs (0 to 255)
+ to SDL joystick positions (-32768 to 32767) */
+ for (i = 0; i < 128; i++)
+ {
+ float t = (float)i/127.0f;
+ analog_map[i+128] = calc_bezier_y(t);
+ analog_map[127-i] = -1 * analog_map[i+128];
+ }
+
+ SceCtrlPortInfo myPortInfo;
+
+ // Assume we have at least one controller, even when nothing is paired
+ // This way the user can jump in, pair a controller
+ // and control things immediately even if it is paired
+ // after the app has already started.
+
+ SDL_numjoysticks = 1;
+
+ //How many additional paired controllers are there?
+ sceCtrlGetControllerPortInfo(&myPortInfo);
+ //On Vita TV, port 0 and 1 are the same controller
+ //and that is the first one, so start at port 2
+ for (i=2; i<=4; i++)
+ {
+ if (myPortInfo.port[i]!=SCE_CTRL_TYPE_UNPAIRED)
+ {
+ SDL_numjoysticks++;
+ }
+ }
+ return SDL_numjoysticks;
+}
+
+int SDL_SYS_NumJoysticks()
+{
+ return SDL_numjoysticks;
+}
+
+void SDL_SYS_JoystickDetect()
+{
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ if (device_index == 1)
+ return "PSVita Controller";
+
+ if (device_index == 2)
+ return "PSVita Controller";
+
+ if (device_index == 3)
+ return "PSVita Controller";
+
+ return "PSVita Controller";
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return device_index;
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *SDL_SYS_JoystickName(int index)
+{
+ if (index == 0)
+ return "PSVita Controller";
+
+ if (index == 1)
+ return "PSVita Controller";
+
+ if (index == 2)
+ return "PSVita Controller";
+
+ if (index == 3)
+ return "PSVita Controller";
+
+ SDL_SetError("No joystick available with that index");
+ return(NULL);
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
+{
+ joystick->nbuttons = sizeof(button_map)/sizeof(*button_map);
+ joystick->naxes = 4;
+ joystick->nhats = 0;
+ joystick->instance_id = device_index;
+
+ return 0;
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return SDL_TRUE;
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
+{
+ int i;
+ unsigned int buttons;
+ unsigned int changed;
+ unsigned char lx, ly, rx, ry;
+ static unsigned int old_buttons[] = { 0, 0, 0, 0 };
+ static unsigned char old_lx[] = { 0, 0, 0, 0 };
+ static unsigned char old_ly[] = { 0, 0, 0, 0 };
+ static unsigned char old_rx[] = { 0, 0, 0, 0 };
+ static unsigned char old_ry[] = { 0, 0, 0, 0 };
+ SceCtrlData *pad = NULL;
+
+ int index = (int) SDL_JoystickInstanceID(joystick);
+
+ if (index == 0) pad = &pad0;
+ else if (index == 1) pad = &pad1;
+ else if (index == 2) pad = &pad2;
+ else if (index == 3) pad = &pad3;
+ else return;
+
+ sceCtrlPeekBufferPositive(port_map[index], pad, 1);
+
+ buttons = pad->buttons;
+ lx = pad->lx;
+ ly = pad->ly;
+ rx = pad->rx;
+ ry = pad->ry;
+/*
+ for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
+ SDL_PrivateJoystickButton(
+ joystick, i,
+ (buttons & button_map[i]) ?
+ SDL_PRESSED : SDL_RELEASED);
+}
+*/
+ // Axes
+
+ if(old_lx[index] != lx) {
+ SDL_PrivateJoystickAxis(joystick, 0, analog_map[lx]);
+ old_lx[index] = lx;
+ }
+ if(old_ly[index] != ly) {
+ SDL_PrivateJoystickAxis(joystick, 1, analog_map[ly]);
+ old_ly[index] = ly;
+ }
+ if(old_rx[index] != rx) {
+ SDL_PrivateJoystickAxis(joystick, 2, analog_map[rx]);
+ old_rx[index] = rx;
+ }
+ if(old_ry[index] != ry) {
+ SDL_PrivateJoystickAxis(joystick, 3, analog_map[ry]);
+ old_ry[index] = ry;
+ }
+
+ // Buttons
+ changed = old_buttons[index] ^ buttons;
+ old_buttons[index] = buttons;
+ if(changed) {
+ for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
+ if(changed & button_map[i]) {
+ SDL_PrivateJoystickButton(
+ joystick, i,
+ (buttons & button_map[i]) ?
+ SDL_PRESSED : SDL_RELEASED);
+ }
+ }
+ }
+}
+
+/* Function to close a joystick after use */
+void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
+{
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void SDL_SYS_JoystickQuit(void)
+{
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+#endif /* SDL_JOYSTICK_VITA */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c
index e8033b8..6c39e83 100644
--- a/src/power/SDL_power.c
+++ b/src/power/SDL_power.c
@@ -68,6 +68,9 @@ static SDL_GetPowerInfo_Impl implementations[] = {
#ifdef SDL_POWER_PSP /* handles PSP. */
SDL_GetPowerInfo_PSP,
#endif
+#ifdef SDL_POWER_VITA /* handles PSVita. */
+ SDL_GetPowerInfo_VITA,
+#endif
#ifdef SDL_POWER_WINRT /* handles WinRT */
SDL_GetPowerInfo_WinRT,
#endif
diff --git a/src/power/SDL_syspower.h b/src/power/SDL_syspower.h
index f6b0f3b..0325caa 100644
--- a/src/power/SDL_syspower.h
+++ b/src/power/SDL_syspower.h
@@ -38,6 +38,7 @@ SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_VITA(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *);
diff --git a/src/power/vita/SDL_syspower.c b/src/power/vita/SDL_syspower.c
new file mode 100644
index 0000000..5aa8df0
--- /dev/null
+++ b/src/power/vita/SDL_syspower.c
@@ -0,0 +1,68 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_VITA
+
+#include "SDL_power.h"
+#include <psp2/power.h>
+
+
+SDL_bool
+SDL_GetPowerInfo_VITA(SDL_PowerState * state, int *seconds,
+ int *percent)
+{
+ int battery = 1;
+ int plugged = scePowerIsPowerOnline();
+ int charging = scePowerIsBatteryCharging();
+
+ *state = SDL_POWERSTATE_UNKNOWN;
+ *seconds = -1;
+ *percent = -1;
+
+ if (!battery) {
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ *seconds = -1;
+ *percent = -1;
+ } else if (charging) {
+ *state = SDL_POWERSTATE_CHARGING;
+ *percent = scePowerGetBatteryLifePercent();
+ *seconds = scePowerGetBatteryLifeTime()*60;
+ } else if (plugged) {
+ *state = SDL_POWERSTATE_CHARGED;
+ *percent = scePowerGetBatteryLifePercent();
+ *seconds = scePowerGetBatteryLifeTime()*60;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ *percent = scePowerGetBatteryLifePercent();
+ *seconds = scePowerGetBatteryLifeTime()*60;
+ }
+
+
+ return SDL_TRUE; /* always the definitive answer on VITA. */
+}
+
+#endif /* SDL_POWER_VITA */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h
index e738b0d..0ff4502 100644
--- a/src/thread/SDL_thread_c.h
+++ b/src/thread/SDL_thread_c.h
@@ -34,6 +34,8 @@
#include "windows/SDL_systhread_c.h"
#elif SDL_THREAD_PSP
#include "psp/SDL_systhread_c.h"
+#elif SDL_THREAD_VITA
+#include "vita/SDL_systhread_c.h"
#elif SDL_THREAD_STDCPP
#include "stdcpp/SDL_systhread_c.h"
#elif SDL_THREAD_OS2
diff --git a/src/thread/vita/SDL_syscond.c b/src/thread/vita/SDL_syscond.c
new file mode 100644
index 0000000..ad2391d
--- /dev/null
+++ b/src/thread/vita/SDL_syscond.c
@@ -0,0 +1,224 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_VITA
+
+/* An implementation of condition variables using semaphores and mutexes */
+/*
+ This implementation borrows heavily from the BeOS condition variable
+ implementation, written by Christopher Tate and Owen Smith. Thanks!
+ */
+
+#include "SDL_thread.h"
+
+struct SDL_cond
+{
+ SDL_mutex *lock;
+ int waiting;
+ int signals;
+ SDL_sem *wait_sem;
+ SDL_sem *wait_done;
+};
+
+/* Create a condition variable */
+SDL_cond *
+SDL_CreateCond(void)
+{
+ SDL_cond *cond;
+
+ cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
+ if (cond) {
+ cond->lock = SDL_CreateMutex();
+ cond->wait_sem = SDL_CreateSemaphore(0);
+ cond->wait_done = SDL_CreateSemaphore(0);
+ cond->waiting = cond->signals = 0;
+ if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
+ SDL_DestroyCond(cond);
+ cond = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return (cond);
+}
+
+/* Destroy a condition variable */
+void
+SDL_DestroyCond(SDL_cond * cond)
+{
+ if (cond) {
+ if (cond->wait_sem) {
+ SDL_DestroySemaphore(cond->wait_sem);
+ }
+ if (cond->wait_done) {
+ SDL_DestroySemaphore(cond->wait_done);
+ }
+ if (cond->lock) {
+ SDL_DestroyMutex(cond->lock);
+ }
+ SDL_free(cond);
+ }
+}
+
+/* Restart one of the threads that are waiting on the condition variable */
+int
+SDL_CondSignal(SDL_cond * cond)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* If there are waiting threads not already signalled, then
+ signal the condition and wait for the thread to respond.
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->waiting > cond->signals) {
+ ++cond->signals;
+ SDL_SemPost(cond->wait_sem);
+ SDL_UnlockMutex(cond->lock);
+ SDL_SemWait(cond->wait_done);
+ } else {
+ SDL_UnlockMutex(cond->lock);
+ }
+
+ return 0;
+}
+
+/* Restart all threads that are waiting on the condition variable */
+int
+SDL_CondBroadcast(SDL_cond * cond)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* If there are waiting threads not already signalled, then
+ signal the condition and wait for the thread to respond.
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->waiting > cond->signals) {
+ int i, num_waiting;
+
+ num_waiting = (cond->waiting - cond->signals);
+ cond->signals = cond->waiting;
+ for (i = 0; i < num_waiting; ++i) {
+ SDL_SemPost(cond->wait_sem);
+ }
+ /* Now all released threads are blocked here, waiting for us.
+ Collect them all (and win fabulous prizes!) :-)
+ */
+ SDL_UnlockMutex(cond->lock);
+ for (i = 0; i < num_waiting; ++i) {
+ SDL_SemWait(cond->wait_done);
+ }
+ } else {
+ SDL_UnlockMutex(cond->lock);
+ }
+
+ return 0;
+}
+
+/* Wait on the condition variable for at most 'ms' milliseconds.
+ The mutex must be locked before entering this function!
+ The mutex is unlocked during the wait, and locked again after the wait.
+
+Typical use:
+
+Thread A:
+ SDL_LockMutex(lock);
+ while ( ! condition ) {
+ SDL_CondWait(cond, lock);
+ }
+ SDL_UnlockMutex(lock);
+
+Thread B:
+ SDL_LockMutex(lock);
+ ...
+ condition = true;
+ ...
+ SDL_CondSignal(cond);
+ SDL_UnlockMutex(lock);
+ */
+int
+SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
+{
+ int retval;
+
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* Obtain the protection mutex, and increment the number of waiters.
+ This allows the signal mechanism to only perform a signal if there
+ are waiting threads.
+ */
+ SDL_LockMutex(cond->lock);
+ ++cond->waiting;
+ SDL_UnlockMutex(cond->lock);
+
+ /* Unlock the mutex, as is required by condition variable semantics */
+ SDL_UnlockMutex(mutex);
+
+ /* Wait for a signal */
+ if (ms == SDL_MUTEX_MAXWAIT) {
+ retval = SDL_SemWait(cond->wait_sem);
+ } else {
+ retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
+ }
+
+ /* Let the signaler know we have completed the wait, otherwise
+ the signaler can race ahead and get the condition semaphore
+ if we are stopped between the mutex unlock and semaphore wait,
+ giving a deadlock. See the following URL for details:
+ http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->signals > 0) {
+ /* If we timed out, we need to eat a condition signal */
+ if (retval > 0) {
+ SDL_SemWait(cond->wait_sem);
+ }
+ /* We always notify the signal thread that we are done */
+ SDL_SemPost(cond->wait_done);
+
+ /* Signal handshake complete */
+ --cond->signals;
+ }
+ --cond->waiting;
+ SDL_UnlockMutex(cond->lock);
+
+ /* Lock the mutex, as is required by condition variable semantics */
+ SDL_LockMutex(mutex);
+
+ return retval;
+}
+
+/* Wait on the condition variable forever */
+int
+SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
+{
+ return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
+}
+
+#endif /* SDL_THREAD_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/thread/vita/SDL_sysmutex.c b/src/thread/vita/SDL_sysmutex.c
new file mode 100644
index 0000000..6584fb2
--- /dev/null
+++ b/src/thread/vita/SDL_sysmutex.c
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_VITA
+
+/* An implementation of mutexes using semaphores */
+
+#include "SDL_thread.h"
+#include "SDL_systhread_c.h"
+
+
+struct SDL_mutex
+{
+ int recursive;
+ SDL_threadID owner;
+ SDL_sem *sem;
+};
+
+/* Create a mutex */
+SDL_mutex *
+SDL_CreateMutex(void)
+{
+ SDL_mutex *mutex;
+
+ /* Allocate mutex memory */
+ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
+ if (mutex) {
+ /* Create the mutex semaphore, with initial value 1 */
+ mutex->sem = SDL_CreateSemaphore(1);
+ mutex->recursive = 0;
+ mutex->owner = 0;
+ if (!mutex->sem) {
+ SDL_free(mutex);
+ mutex = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return mutex;
+}
+
+/* Free the mutex */
+void
+SDL_DestroyMutex(SDL_mutex * mutex)
+{
+ if (mutex) {
+ if (mutex->sem) {
+ SDL_DestroySemaphore(mutex->sem);
+ }
+ SDL_free(mutex);
+ }
+}
+
+/* Lock the semaphore */
+int
+SDL_mutexP(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ SDL_threadID this_thread;
+
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ this_thread = SDL_ThreadID();
+ if (mutex->owner == this_thread) {
+ ++mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ We set the locking thread id after we obtain the lock
+ so unlocks from other threads will fail.
+ */
+ SDL_SemWait(mutex->sem);
+ mutex->owner = this_thread;
+ mutex->recursive = 0;
+ }
+
+ return 0;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+/* Unlock the mutex */
+int
+SDL_mutexV(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ /* If we don't own the mutex, we can't unlock it */
+ if (SDL_ThreadID() != mutex->owner) {
+ return SDL_SetError("mutex not owned by this thread");
+ }
+
+ if (mutex->recursive) {
+ --mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ First reset the owner so another thread doesn't lock
+ the mutex and set the ownership before we reset it,
+ then release the lock semaphore.
+ */
+ mutex->owner = 0;
+ SDL_SemPost(mutex->sem);
+ }
+ return 0;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+#endif /* SDL_THREAD_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/thread/vita/SDL_sysmutex_c.h b/src/thread/vita/SDL_sysmutex_c.h
new file mode 100644
index 0000000..7481b66
--- /dev/null
+++ b/src/thread/vita/SDL_sysmutex_c.h
@@ -0,0 +1,22 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/thread/vita/SDL_syssem.c b/src/thread/vita/SDL_syssem.c
new file mode 100644
index 0000000..073ba09
--- /dev/null
+++ b/src/thread/vita/SDL_syssem.c
@@ -0,0 +1,163 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_VITA
+
+/* Semaphore functions for the VITA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL_error.h"
+#include "SDL_thread.h"
+
+#include <psp2/types.h>
+#include <psp2/kernel/error.h>
+#include <psp2/kernel/threadmgr.h>
+
+struct SDL_semaphore {
+ SceUID semid;
+};
+
+
+/* Create a semaphore */
+SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
+{
+ SDL_sem *sem;
+
+ sem = (SDL_sem *) malloc(sizeof(*sem));
+ if (sem != NULL) {
+ /* TODO: Figure out the limit on the maximum value. */
+ sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
+ if (sem->semid < 0) {
+ SDL_SetError("Couldn't create semaphore");
+ free(sem);
+ sem = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return sem;
+}
+
+/* Free the semaphore */
+void SDL_DestroySemaphore(SDL_sem *sem)
+{
+ if (sem != NULL) {
+ if (sem->semid > 0) {
+ sceKernelDeleteSema(sem->semid);
+ sem->semid = 0;
+ }
+
+ free(sem);
+ }
+}
+
+/* TODO: This routine is a bit overloaded.
+ * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass
+ * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout
+ * is specified, convert it to microseconds. */
+int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
+{
+ Uint32 *pTimeout;
+ unsigned int res;
+
+ if (sem == NULL) {
+ SDL_SetError("Passed a NULL sem");
+ return 0;
+ }
+
+ if (timeout == 0) {
+ res = sceKernelPollSema(sem->semid, 1);
+ if (res < 0) {
+ return SDL_MUTEX_TIMEDOUT;
+ }
+ return 0;
+ }
+
+ if (timeout == SDL_MUTEX_MAXWAIT) {
+ pTimeout = NULL;
+ } else {
+ timeout *= 1000; /* Convert to microseconds. */
+ pTimeout = &timeout;
+ }
+
+ res = sceKernelWaitSema(sem->semid, 1, pTimeout);
+ switch (res) {
+ case SCE_KERNEL_OK:
+ return 0;
+ case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
+ return SDL_MUTEX_TIMEDOUT;
+ default:
+ return SDL_SetError("WaitForSingleObject() failed");
+ }
+}
+
+int SDL_SemTryWait(SDL_sem *sem)
+{
+ return SDL_SemWaitTimeout(sem, 0);
+}
+
+int SDL_SemWait(SDL_sem *sem)
+{
+ return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
+}
+
+/* Returns the current count of the semaphore */
+Uint32 SDL_SemValue(SDL_sem *sem)
+{
+ SceKernelSemaInfo info;
+ info.size = sizeof(info);
+
+ if (sem == NULL) {
+ SDL_SetError("Passed a NULL sem");
+ return 0;
+ }
+
+ if (sceKernelGetSemaInfo(sem->semid, &info) >= 0) {
+ return info.currentCount;
+ }
+
+ return 0;
+}
+
+int SDL_SemPost(SDL_sem *sem)
+{
+ int res;
+
+ if (sem == NULL) {
+ return SDL_SetError("Passed a NULL sem");
+ }
+
+ res = sceKernelSignalSema(sem->semid, 1);
+ if (res < 0) {
+ return SDL_SetError("sceKernelSignalSema() failed");
+ }
+
+ return 0;
+}
+
+#endif /* SDL_THREAD_VITA */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/thread/vita/SDL_systhread.c b/src/thread/vita/SDL_systhread.c
new file mode 100644
index 0000000..d2375fd
--- /dev/null
+++ b/src/thread/vita/SDL_systhread.c
@@ -0,0 +1,112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_VITA
+
+/* VITA thread management routines for SDL */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL_error.h"
+#include "SDL_thread.h"
+#include "../SDL_systhread.h"
+#include "../SDL_thread_c.h"
+#include <psp2/types.h>
+#include <psp2/kernel/threadmgr.h>
+
+
+static int ThreadEntry(SceSize args, void *argp)
+{
+ SDL_RunThread(*(void **) argp);
+ return 0;
+}
+
+int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
+{
+ SceKernelThreadInfo info;
+ int priority = 32;
+
+ /* Set priority of new thread to the same as the current thread */
+ info.size = sizeof(SceKernelThreadInfo);
+ if (sceKernelGetThreadInfo(sceKernelGetThreadId(), &info) == 0) {
+ priority = info.currentPriority;
+ }
+
+ thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
+ priority, 0x10000, 0, 0, NULL);
+
+ if (thread->handle < 0) {
+ return SDL_SetError("sceKernelCreateThread() failed");
+ }
+
+ sceKernelStartThread(thread->handle, 4, &args);
+ return 0;
+}
+
+void SDL_SYS_SetupThread(const char *name)
+{
+ /* Do nothing. */
+}
+
+SDL_threadID SDL_ThreadID(void)
+{
+ return (SDL_threadID) sceKernelGetThreadId();
+}
+
+void SDL_SYS_WaitThread(SDL_Thread *thread)
+{
+ sceKernelWaitThreadEnd(thread->handle, NULL, NULL);
+ sceKernelDeleteThread(thread->handle);
+}
+
+void SDL_SYS_DetachThread(SDL_Thread *thread)
+{
+ /* !!! FIXME: is this correct? */
+ sceKernelDeleteThread(thread->handle);
+}
+
+void SDL_SYS_KillThread(SDL_Thread *thread)
+{
+ sceKernelDeleteThread(thread->handle);
+}
+
+int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
+{
+ int value;
+
+ if (priority == SDL_THREAD_PRIORITY_LOW) {
+ value = 19;
+ } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
+ value = -20;
+ } else {
+ value = 0;
+ }
+
+ return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
+
+}
+
+#endif /* SDL_THREAD_VITA */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/thread/vita/SDL_systhread_c.h b/src/thread/vita/SDL_systhread_c.h
new file mode 100644
index 0000000..80bf49d
--- /dev/null
+++ b/src/thread/vita/SDL_systhread_c.h
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include <psp2/types.h>
+
+typedef SceUID SYS_ThreadHandle;
diff --git a/src/timer/vita/SDL_systimer.c b/src/timer/vita/SDL_systimer.c
new file mode 100644
index 0000000..adc7b85
--- /dev/null
+++ b/src/timer/vita/SDL_systimer.c
@@ -0,0 +1,91 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_TIMERS_VITA
+
+#include "SDL_thread.h"
+#include "SDL_timer.h"
+#include "SDL_error.h"
+#include "../SDL_timer_c.h"
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <psp2/kernel/processmgr.h>
+
+static uint64_t start;
+static SDL_bool ticks_started = SDL_FALSE;
+
+void
+SDL_TicksInit(void)
+{
+ if (ticks_started) {
+ return;
+ }
+ ticks_started = SDL_TRUE;
+
+ start = sceKernelGetProcessTimeWide();
+}
+
+void
+SDL_TicksQuit(void)
+{
+ ticks_started = SDL_FALSE;
+}
+
+Uint32 SDL_GetTicks(void)
+{
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ uint64_t now;
+ Uint32 ticks;
+
+ now = sceKernelGetProcessTimeWide();
+ ticks = (now - start)/1000;
+ return (ticks);
+}
+
+Uint64
+SDL_GetPerformanceCounter(void)
+{
+ return SDL_GetTicks();
+}
+
+Uint64
+SDL_GetPerformanceFrequency(void)
+{
+ return 1000;
+}
+
+void SDL_Delay(Uint32 ms)
+{
+ const Uint32 max_delay = 0xffffffffUL / 1000;
+ if(ms > max_delay)
+ ms = max_delay;
+ sceKernelDelayThreadCB(ms * 1000);
+}
+
+#endif /* SDL_TIMERS_VITA */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index d5adac0..c6f0048 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -428,6 +428,7 @@ extern VideoBootStrap PND_bootstrap;
extern VideoBootStrap UIKIT_bootstrap;
extern VideoBootStrap Android_bootstrap;
extern VideoBootStrap PSP_bootstrap;
+extern VideoBootStrap VITA_bootstrap;
extern VideoBootStrap RPI_bootstrap;
extern VideoBootStrap KMSDRM_bootstrap;
extern VideoBootStrap KMSDRM_LEGACY_bootstrap;
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 77f252b..e262a19 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -94,6 +94,9 @@ static VideoBootStrap *bootstrap[] = {
#if SDL_VIDEO_DRIVER_PSP
&PSP_bootstrap,
#endif
+#if SDL_VIDEO_DRIVER_VITA
+ &VITA_bootstrap,
+#endif
#if SDL_VIDEO_DRIVER_KMSDRM
&KMSDRM_bootstrap,
#endif
diff --git a/src/video/vita/SDL_vitagl.c b/src/video/vita/SDL_vitagl.c
new file mode 100644
index 0000000..831586c
--- /dev/null
+++ b/src/video/vita/SDL_vitagl.c
@@ -0,0 +1,221 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VITA
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL_error.h"
+#include "SDL_vitavideo.h"
+#include "SDL_vitagl_c.h"
+
+/*****************************************************************************/
+/* SDL OpenGL/OpenGL ES functions */
+/*****************************************************************************/
+#define EGLCHK(stmt) \
+ do { \
+ EGLint err; \
+ \
+ stmt; \
+ err = eglGetError(); \
+ if (err != EGL_SUCCESS) { \
+ SDL_SetError("EGL error %d", err); \
+ return 0; \
+ } \
+ } while (0)
+
+int
+VITA_GL_LoadLibrary(_THIS, const char *path)
+{
+ pibInit(PIB_SHACCCG);
+ return 0;
+}
+
+void *
+VITA_GL_GetProcAddress(_THIS, const char *proc)
+{
+ return eglGetProcAddress(proc);
+}
+
+void
+VITA_GL_UnloadLibrary(_THIS)
+{
+ eglTerminate(_this->gl_data->display);
+}
+
+static EGLint width = 960;
+static EGLint height = 544;
+
+SDL_GLContext
+VITA_GL_CreateContext(_THIS, SDL_Window * window)
+{
+
+ SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+
+ EGLint attribs[32];
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface surface;
+ EGLConfig config;
+ EGLint num_configs;
+ int i;
+
+
+ /* EGL init taken from glutCreateWindow() in VITAGL's glut.c. */
+ EGLCHK(display = eglGetDisplay(0));
+
+ EGLCHK(eglInitialize(display, NULL, NULL));
+ wdata->uses_gles = SDL_TRUE;
+ window->flags |= SDL_WINDOW_FULLSCREEN;
+
+ EGLCHK(eglBindAPI(EGL_OPENGL_ES_API));
+
+ /* Setup the config based on SDL's current values. */
+ i = 0;
+ attribs[i++] = EGL_RED_SIZE;
+ attribs[i++] = 8;//_this->gl_config.red_size;
+ attribs[i++] = EGL_GREEN_SIZE;
+ attribs[i++] = 8;//_this->gl_config.green_size;
+ attribs[i++] = EGL_BLUE_SIZE;
+ attribs[i++] = 8;//_this->gl_config.blue_size;
+ attribs[i++] = EGL_DEPTH_SIZE;
+ attribs[i++] = 32;//_this->gl_config.depth_size;
+
+// if (_this->gl_config.alpha_size)
+ {
+ attribs[i++] = EGL_ALPHA_SIZE;
+ attribs[i++] = 8;//_this->gl_config.alpha_size;
+ }
+ if (_this->gl_config.stencil_size)
+ {
+ attribs[i++] = EGL_STENCIL_SIZE;
+ attribs[i++] = _this->gl_config.stencil_size;
+ }
+
+ attribs[i++] = EGL_SURFACE_TYPE;
+ attribs[i++] = 5;
+
+ attribs[i++] = EGL_RENDERABLE_TYPE;
+ attribs[i++] = EGL_OPENGL_ES2_BIT;
+
+ attribs[i++] = EGL_NONE;
+
+ EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
+
+ if (num_configs == 0)
+ {
+ SDL_SetError("No valid EGL configs for requested mode");
+ return 0;
+ }
+
+ const EGLint contextAttribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ EGLCHK(surface = eglCreateWindowSurface(display, config, VITA_WINDOW_960X544, NULL));
+
+ EGLCHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs));
+
+ EGLCHK(eglMakeCurrent(display, surface, surface, context));
+
+ EGLCHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
+ EGLCHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));
+
+ _this->gl_data->display = display;
+ _this->gl_data->context = context;
+ _this->gl_data->surface = surface;
+
+
+ return context;
+}
+
+int
+VITA_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
+ _this->gl_data->surface, _this->gl_data->context))
+ {
+ return SDL_SetError("Unable to make EGL context current");
+ }
+ return 0;
+}
+
+int
+VITA_GL_SetSwapInterval(_THIS, int interval)
+{
+ EGLBoolean status;
+ status = eglSwapInterval(_this->gl_data->display, interval);
+ if (status == EGL_TRUE) {
+ /* Return success to upper level */
+ _this->gl_data->swapinterval = interval;
+ return 0;
+ }
+ /* Failed to set swap interval */
+ return SDL_SetError("Unable to set the EGL swap interval");
+}
+
+int
+VITA_GL_GetSwapInterval(_THIS)
+{
+ return _this->gl_data->swapinterval;
+}
+
+int
+VITA_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
+ return SDL_SetError("eglSwapBuffers() failed");
+ }
+ return 0;
+}
+
+void
+VITA_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ EGLBoolean status;
+
+ if (phdata->egl_initialized != SDL_TRUE) {
+ SDL_SetError("VITA: GLES initialization failed, no OpenGL ES support");
+ return;
+ }
+
+ /* Check if OpenGL ES connection has been initialized */
+ if (_this->gl_data->display != EGL_NO_DISPLAY) {
+ if (context != EGL_NO_CONTEXT) {
+ status = eglDestroyContext(_this->gl_data->display, context);
+ if (status != EGL_TRUE) {
+ /* Error during OpenGL ES context destroying */
+ SDL_SetError("VITA: OpenGL ES context destroy error");
+ return;
+ }
+ }
+ }
+
+ return;
+}
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitagl_c.h b/src/video/vita/SDL_vitagl_c.h
new file mode 100644
index 0000000..61d44e4
--- /dev/null
+++ b/src/video/vita/SDL_vitagl_c.h
@@ -0,0 +1,56 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_vitagl_c_h_
+#define SDL_vitagl_c_h_
+
+
+#include <pib.h>
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+#include "SDL_vitavideo.h"
+
+
+typedef struct SDL_GLDriverData {
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface surface;
+ uint32_t swapinterval;
+}SDL_GLDriverData;
+
+extern void * VITA_GL_GetProcAddress(_THIS, const char *proc);
+extern int VITA_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context);
+extern void VITA_GL_SwapBuffers(_THIS);
+
+extern int VITA_GL_SwapWindow(_THIS, SDL_Window * window);
+extern SDL_GLContext VITA_GL_CreateContext(_THIS, SDL_Window * window);
+
+extern int VITA_GL_LoadLibrary(_THIS, const char *path);
+extern void VITA_GL_UnloadLibrary(_THIS);
+extern int VITA_GL_SetSwapInterval(_THIS, int interval);
+extern int VITA_GL_GetSwapInterval(_THIS);
+
+
+#endif /* SDL_vitagl_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitakeyboard.c b/src/video/vita/SDL_vitakeyboard.c
new file mode 100644
index 0000000..efa407f
--- /dev/null
+++ b/src/video/vita/SDL_vitakeyboard.c
@@ -0,0 +1,198 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VITA
+
+#include <psp2/kernel/processmgr.h>
+#include <psp2/ctrl.h>
+#include <psp2/hid.h>
+
+#include "SDL_events.h"
+#include "SDL_log.h"
+#include "SDL_vitavideo.h"
+#include "SDL_vitakeyboard.h"
+#include "../../events/SDL_keyboard_c.h"
+
+SceHidKeyboardReport k_reports[SCE_HID_MAX_REPORT];
+int keyboard_hid_handle = 0;
+Uint8 prev_keys[6] = {0};
+Uint8 prev_modifiers = 0;
+Uint8 locks = 0;
+Uint8 lock_key_down = 0;
+
+void
+VITA_InitKeyboard(void)
+{
+ sceHidKeyboardEnumerate(&keyboard_hid_handle, 1);
+}
+
+void
+VITA_PollKeyboard(void)
+{
+ // We skip polling keyboard if no window is created
+ if (Vita_Window == NULL)
+ return;
+
+ if (keyboard_hid_handle > 0)
+ {
+ int numReports = sceHidKeyboardRead(keyboard_hid_handle, (SceHidKeyboardReport**)&k_reports, SCE_HID_MAX_REPORT);
+
+ if (numReports < 0) {
+ keyboard_hid_handle = 0;
+ }
+ else if (numReports) {
+ // Numlock and Capslock state changes only on a SDL_PRESSED event
+ // The k_report only reports the state of the LED
+ if (k_reports[numReports - 1].modifiers[1] & 0x1) {
+ if (!(locks & 0x1)) {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
+ locks |= 0x1;
+ }
+ }
+ else {
+ if (locks & 0x1) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
+ locks &= ~0x1;
+ }
+ }
+
+ if (k_reports[numReports - 1].modifiers[1] & 0x2) {
+ if (!(locks & 0x2)) {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
+ locks |= 0x2;
+ }
+ }
+ else {
+ if (locks & 0x2) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
+ locks &= ~0x2;
+ }
+ }
+
+ if (k_reports[numReports - 1].modifiers[1] & 0x4) {
+ if (!(locks & 0x4)) {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_SCROLLLOCK);
+ locks |= 0x4;
+ }
+ }
+ else {
+ if (locks & 0x4) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_SCROLLLOCK);
+ locks &= ~0x4;
+ }
+ }
+
+ Uint8 changed_modifiers = k_reports[numReports - 1].modifiers[0] ^ prev_modifiers;
+
+ if (changed_modifiers & 0x01) {
+ if (prev_modifiers & 0x01) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LCTRL);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LCTRL);
+ }
+ }
+ if (changed_modifiers & 0x02) {
+ if (prev_modifiers & 0x02) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
+ }
+ }
+ if (changed_modifiers & 0x04) {
+ if (prev_modifiers & 0x04) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LALT);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LALT);
+ }
+ }
+ if (changed_modifiers & 0x08) {
+ if (prev_modifiers & 0x08) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LGUI);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LGUI);
+ }
+ }
+ if (changed_modifiers & 0x10) {
+ if (prev_modifiers & 0x10) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RCTRL);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RCTRL);
+ }
+ }
+ if (changed_modifiers & 0x20) {
+ if (prev_modifiers & 0x20) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RSHIFT);
+ }
+ }
+ if (changed_modifiers & 0x40) {
+ if (prev_modifiers & 0x40) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RALT);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RALT);
+ }
+ }
+ if (changed_modifiers & 0x80) {
+ if (prev_modifiers & 0x80) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RGUI);
+ }
+ else {
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RGUI);
+ }
+ }
+
+ prev_modifiers = k_reports[numReports - 1].modifiers[0];
+
+ for (int i = 0; i < 6; i++) {
+
+ int keyCode = k_reports[numReports - 1].keycodes[i];
+
+ if (keyCode != prev_keys[i]) {
+
+ if (prev_keys[i]) {
+ SDL_SendKeyboardKey(SDL_RELEASED, prev_keys[i]);
+ }
+ if (keyCode) {
+ SDL_SendKeyboardKey(SDL_PRESSED, keyCode);
+ }
+ prev_keys[i] = keyCode;
+ }
+ }
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitakeyboard.h b/src/video/vita/SDL_vitakeyboard.h
new file mode 100644
index 0000000..b0ff5ff
--- /dev/null
+++ b/src/video/vita/SDL_vitakeyboard.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SDL_vitakeyboard_h
+#define _SDL_vitakeyboard_h
+
+#include "../../SDL_internal.h"
+
+/* Keyboard functions */
+extern void VITA_InitKeyboard(void);
+extern void VITA_PollKeyboard(void);
+
+#endif /* _SDL_vitakeyboard_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitamouse.c b/src/video/vita/SDL_vitamouse.c
new file mode 100644
index 0000000..d5af6bf
--- /dev/null
+++ b/src/video/vita/SDL_vitamouse.c
@@ -0,0 +1,94 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VITA
+
+#include <psp2/kernel/processmgr.h>
+#include <psp2/ctrl.h>
+#include <psp2/hid.h>
+
+#include "SDL_events.h"
+#include "SDL_log.h"
+#include "SDL_mouse.h"
+#include "SDL_vitavideo.h"
+#include "SDL_vitamouse_c.h"
+#include "../../events/SDL_mouse_c.h"
+
+SceHidMouseReport m_reports[SCE_HID_MAX_REPORT];
+int mouse_hid_handle = 0;
+Uint8 prev_buttons = 0;
+
+void
+VITA_InitMouse(void)
+{
+ sceHidMouseEnumerate(&mouse_hid_handle, 1);
+}
+
+void
+VITA_PollMouse(void)
+{
+ // We skip polling mouse if no window is created
+ if (Vita_Window == NULL)
+ return;
+
+ if (mouse_hid_handle > 0)
+ {
+ int numReports = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport**)&m_reports, SCE_HID_MAX_REPORT);
+ if (numReports > 0)
+ {
+ for (int i = 0; i <= numReports - 1; i++)
+ {
+ Uint8 changed_buttons = m_reports[i].buttons ^ prev_buttons;
+
+ if (changed_buttons & 0x1) {
+ if (prev_buttons & 0x1)
+ SDL_SendMouseButton(Vita_Window, 0, SDL_RELEASED, SDL_BUTTON_LEFT);
+ else
+ SDL_SendMouseButton(Vita_Window, 0, SDL_PRESSED, SDL_BUTTON_LEFT);
+ }
+ if (changed_buttons & 0x2) {
+ if (prev_buttons & 0x2)
+ SDL_SendMouseButton(Vita_Window, 0, SDL_RELEASED, SDL_BUTTON_RIGHT);
+ else
+ SDL_SendMouseButton(Vita_Window, 0, SDL_PRESSED, SDL_BUTTON_RIGHT);
+ }
+ if (changed_buttons & 0x4) {
+ if (prev_buttons & 0x4)
+ SDL_SendMouseButton(Vita_Window, 0, SDL_RELEASED, SDL_BUTTON_MIDDLE);
+ else
+ SDL_SendMouseButton(Vita_Window, 0, SDL_PRESSED, SDL_BUTTON_MIDDLE);
+ }
+
+ prev_buttons = m_reports[i].buttons;
+
+ if (m_reports[i].rel_x || m_reports[i].rel_y)
+ {
+ SDL_SendMouseMotion(Vita_Window, 0, 1, m_reports[i].rel_x, m_reports[i].rel_y);
+ }
+ }
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitamouse_c.h b/src/video/vita/SDL_vitamouse_c.h
new file mode 100644
index 0000000..ea8648c
--- /dev/null
+++ b/src/video/vita/SDL_vitamouse_c.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SDL_vitamouse_h
+#define _SDL_vitamouse_h
+
+#include "../../SDL_internal.h"
+
+/* mouse functions */
+extern void VITA_InitMouse(void);
+extern void VITA_PollMouse(void);
+
+#endif /* _SDL_vitamouse_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c
new file mode 100644
index 0000000..f101d35
--- /dev/null
+++ b/src/video/vita/SDL_vitatouch.c
@@ -0,0 +1,179 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VITA
+
+#include <psp2/kernel/processmgr.h>
+#include <psp2/touch.h>
+
+#include "SDL_events.h"
+#include "SDL_log.h"
+#include "SDL_vitavideo.h"
+#include "SDL_vitatouch.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+
+SceTouchData touch_old[SCE_TOUCH_PORT_MAX_NUM];
+SceTouchData touch[SCE_TOUCH_PORT_MAX_NUM];
+
+SceTouchPanelInfo panelinfo[SCE_TOUCH_PORT_MAX_NUM];
+
+float aAWidth[SCE_TOUCH_PORT_MAX_NUM];
+float aAHeight[SCE_TOUCH_PORT_MAX_NUM];
+float dispWidth[SCE_TOUCH_PORT_MAX_NUM];
+float dispHeight[SCE_TOUCH_PORT_MAX_NUM];
+float forcerange[SCE_TOUCH_PORT_MAX_NUM];
+
+void
+VITA_InitTouch(void)
+{
+ sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
+ sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
+ sceTouchEnableTouchForce(SCE_TOUCH_PORT_FRONT);
+ sceTouchEnableTouchForce(SCE_TOUCH_PORT_BACK);
+
+ SceTouchPanelInfo panelinfo[SCE_TOUCH_PORT_MAX_NUM];
+ for(int port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
+ sceTouchGetPanelInfo(port, &panelinfo[port]);
+ aAWidth[port] = (float)(panelinfo[port].maxAaX - panelinfo[port].minAaX);
+ aAHeight[port] = (float)(panelinfo[port].maxAaY - panelinfo[port].minAaY);
+ dispWidth[port] = (float)(panelinfo[port].maxDispX - panelinfo[port].minDispX);
+ dispHeight[port] = (float)(panelinfo[port].maxDispY - panelinfo[port].minDispY);
+ forcerange[port] = (float)(panelinfo[port].maxForce - panelinfo[port].minForce);
+ }
+
+ // Support passing both front and back touch devices in events
+ SDL_AddTouch((SDL_TouchID)0, SDL_TOUCH_DEVICE_DIRECT, "Front");
+ SDL_AddTouch((SDL_TouchID)1, SDL_TOUCH_DEVICE_DIRECT, "Back");
+}
+
+void
+VITA_QuitTouch(void){
+ sceTouchDisableTouchForce(SCE_TOUCH_PORT_FRONT);
+ sceTouchDisableTouchForce(SCE_TOUCH_PORT_BACK);
+}
+
+void
+VITA_PollTouch(void)
+{
+ // We skip polling touch if no window is created
+ if (Vita_Window == NULL)
+ return;
+
+ SDL_FingerID finger_id = 0;
+ int port;
+
+ memcpy(touch_old, touch, sizeof(touch_old));
+
+ for(port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
+ sceTouchPeek(port, &touch[port], 1);
+ if (touch[port].reportNum > 0) {
+ for (int i = 0; i < touch[port].reportNum; i++)
+ {
+ // adjust coordinates and forces to return normalized values
+ // for the front, screen area is used as a reference (for direct touch)
+ // e.g. touch_x = 1.0 corresponds to screen_x = 960
+ // for the back panel, the active touch area is used as reference
+ float x = 0;
+ float y = 0;
+ VITA_ConvertTouchXYToSDLXY(&x, &y, touch[port].report[i].x, touch[port].report[i].y, port);
+ float force = (touch[port].report[i].force - panelinfo[port].minForce) / forcerange[port];
+ finger_id = (SDL_FingerID) touch[port].report[i].id;
+
+ // Send an initial touch
+ SDL_SendTouch((SDL_TouchID)port,
+ finger_id,
+ Vita_Window,
+ SDL_TRUE,
+ x,
+ y,
+ force);
+
+ // Always send the motion
+ SDL_SendTouchMotion((SDL_TouchID)port,
+ finger_id,
+ Vita_Window,
+ x,
+ y,
+ force);
+ }
+ }
+
+ // some fingers might have been let go
+ if (touch_old[port].reportNum > 0) {
+ for (int i = 0; i < touch_old[port].reportNum; i++) {
+ int finger_up = 1;
+ if (touch[port].reportNum > 0) {
+ for (int j = 0; j < touch[port].reportNum; j++) {
+ if (touch[port].report[j].id == touch_old[port].report[i].id ) {
+ finger_up = 0;
+ }
+ }
+ }
+ if (finger_up == 1) {
+ float x = 0;
+ float y = 0;
+ VITA_ConvertTouchXYToSDLXY(&x, &y, touch_old[port].report[i].x, touch_old[port].report[i].y, port);
+ float force = (touch_old[port].report[i].force - panelinfo[port].minForce) / forcerange[port];
+ finger_id = (SDL_FingerID) touch_old[port].report[i].id;
+ // Finger released from screen
+ SDL_SendTouch((SDL_TouchID)port,
+ finger_id,
+ Vita_Window,
+ SDL_FALSE,
+ x,
+ y,
+ force);
+ }
+ }
+ }
+ }
+}
+
+void VITA_ConvertTouchXYToSDLXY(float *sdl_x, float *sdl_y, int vita_x, int vita_y, int port) {
+ float x = 0;
+ float y = 0;
+ if (port == SCE_TOUCH_PORT_FRONT) {
+ x = (vita_x - panelinfo[port].minDispX) / dispWidth[port];
+ y = (vita_y - panelinfo[port].minDispY) / dispHeight[port];
+ } else {
+ x = (vita_x - panelinfo[port].minAaX) / aAWidth[port];
+ y = (vita_y - panelinfo[port].minAaY) / aAHeight[port];
+ }
+ if (x < 0.0) {
+ x = 0.0;
+ } else if (x > 1.0) {
+ x = 1.0;
+ }
+ if (y < 0.0) {
+ y = 0.0;
+ } else if (y > 1.0) {
+ y = 1.0;
+ }
+ *sdl_x = x;
+ *sdl_y = y;
+}
+
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitatouch.h b/src/video/vita/SDL_vitatouch.h
new file mode 100644
index 0000000..1de0dea
--- /dev/null
+++ b/src/video/vita/SDL_vitatouch.h
@@ -0,0 +1,35 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SDL_vitatouch_h
+#define _SDL_vitatouch_h
+
+#include "../../SDL_internal.h"
+
+/* Touch functions */
+extern void VITA_InitTouch(void);
+extern void VITA_QuitTouch(void);
+extern void VITA_PollTouch(void);
+void VITA_ConvertTouchXYToSDLXY(float *sdl_x, float *sdl_y, int vita_x, int vita_y, int port);
+
+#endif /* _SDL_vitatouch_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c
new file mode 100644
index 0000000..5ff813e
--- /dev/null
+++ b/src/video/vita/SDL_vitavideo.c
@@ -0,0 +1,341 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VITA
+
+/* SDL internals */
+#include "../SDL_sysvideo.h"
+#include "SDL_version.h"
+#include "SDL_syswm.h"
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+
+/* VITA declarations */
+#include "SDL_vitavideo.h"
+#include "SDL_vitatouch.h"
+#include "SDL_vitakeyboard.h"
+#include "SDL_vitamouse_c.h"
+#include "SDL_vitagl_c.h"
+
+SDL_Window *Vita_Window;
+
+/* unused
+static SDL_bool VITA_initialized = SDL_FALSE;
+*/
+static int
+VITA_Available(void)
+{
+ return 1;
+}
+
+static void
+VITA_Destroy(SDL_VideoDevice * device)
+{
+/* SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; */
+
+ if (device->driverdata != NULL) {
+ device->driverdata = NULL;
+ }
+}
+
+static SDL_VideoDevice *
+VITA_Create()
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *phdata;
+ SDL_GLDriverData *gldata;
+
+ int status;
+
+ /* Check if VITA could be initialized */
+ status = VITA_Available();
+ if (status == 0) {
+ /* VITA could not be used */
+ return NULL;
+ }
+
+ /* Initialize SDL_VideoDevice structure */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize internal VITA specific data */
+ phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (phdata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+
+ gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData));
+ if (gldata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ SDL_free(phdata);
+ return NULL;
+ }
+ device->gl_data = gldata;
+ phdata->egl_initialized = SDL_TRUE;
+
+ device->driverdata = phdata;
+
+ /* Setup amount of available displays and current display */
+ device->num_displays = 0;
+
+ /* Set device free function */
+ device->free = VITA_Destroy;
+
+ /* Setup all functions which we can handle */
+ device->VideoInit = VITA_VideoInit;
+ device->VideoQuit = VITA_VideoQuit;
+ device->GetDisplayModes = VITA_GetDisplayModes;
+ device->SetDisplayMode = VITA_SetDisplayMode;
+ device->CreateSDLWindow = VITA_CreateWindow;
+ device->CreateSDLWindowFrom = VITA_CreateWindowFrom;
+ device->SetWindowTitle = VITA_SetWindowTitle;
+ device->SetWindowIcon = VITA_SetWindowIcon;
+ device->SetWindowPosition = VITA_SetWindowPosition;
+ device->SetWindowSize = VITA_SetWindowSize;
+ device->ShowWindow = VITA_ShowWindow;
+ device->HideWindow = VITA_HideWindow;
+ device->RaiseWindow = VITA_RaiseWindow;
+ device->MaximizeWindow = VITA_MaximizeWindow;
+ device->MinimizeWindow = VITA_MinimizeWindow;
+ device->RestoreWindow = VITA_RestoreWindow;
+ device->SetWindowGrab = VITA_SetWindowGrab;
+ device->DestroyWindow = VITA_DestroyWindow;
+ device->GetWindowWMInfo = VITA_GetWindowWMInfo;
+
+ device->GL_LoadLibrary = VITA_GL_LoadLibrary;
+ device->GL_GetProcAddress = VITA_GL_GetProcAddress;
+ device->GL_UnloadLibrary = VITA_GL_UnloadLibrary;
+ device->GL_CreateContext = VITA_GL_CreateContext;
+ device->GL_MakeCurrent = VITA_GL_MakeCurrent;
+ device->GL_SetSwapInterval = VITA_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = VITA_GL_GetSwapInterval;
+ device->GL_SwapWindow = VITA_GL_SwapWindow;
+ device->GL_DeleteContext = VITA_GL_DeleteContext;
+
+ device->HasScreenKeyboardSupport = VITA_HasScreenKeyboardSupport;
+ device->ShowScreenKeyboard = VITA_ShowScreenKeyboard;
+ device->HideScreenKeyboard = VITA_HideScreenKeyboard;
+ device->IsScreenKeyboardShown = VITA_IsScreenKeyboardShown;
+
+ device->PumpEvents = VITA_PumpEvents;
+
+ return device;
+}
+
+VideoBootStrap VITA_bootstrap = {
+ "VITA",
+ "VITA Video Driver",
+ VITA_Available,
+ VITA_Create
+};
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions */
+/*****************************************************************************/
+int
+VITA_VideoInit(_THIS)
+{
+ SDL_VideoDisplay display;
+ SDL_DisplayMode current_mode;
+
+ SDL_zero(current_mode);
+
+ current_mode.w = 960;
+ current_mode.h = 544;
+
+ current_mode.refresh_rate = 60;
+ /* 32 bpp for default */
+ current_mode.format = SDL_PIXELFORMAT_ABGR8888;
+
+ current_mode.driverdata = NULL;
+
+ SDL_zero(display);
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+ display.driverdata = NULL;
+
+ SDL_AddVideoDisplay(&display);
+ VITA_InitTouch();
+ VITA_InitKeyboard();
+ VITA_InitMouse();
+
+ return 1;
+}
+
+void
+VITA_VideoQuit(_THIS)
+{
+ VITA_QuitTouch();
+}
+
+void
+VITA_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+
+}
+
+int
+VITA_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+int
+VITA_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wdata;
+
+ /* Allocate window internal data */
+ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (wdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Setup driver data for this window */
+ window->driverdata = wdata;
+
+ // Vita can only have one window
+ if (Vita_Window != NULL)
+ {
+ // Replace this with something else
+ return SDL_OutOfMemory();
+ }
+
+ Vita_Window = window;
+
+ // fix input, we need to find a better way
+ SDL_SetKeyboardFocus(window);
+
+ /* Window has been successfully created */
+ return 0;
+}
+
+int
+VITA_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ return -1;
+}
+
+void
+VITA_SetWindowTitle(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+}
+void
+VITA_SetWindowPosition(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_SetWindowSize(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_ShowWindow(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_HideWindow(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_RaiseWindow(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_MaximizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_MinimizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_RestoreWindow(_THIS, SDL_Window * window)
+{
+}
+void
+VITA_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+
+}
+void
+VITA_DestroyWindow(_THIS, SDL_Window * window)
+{
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function */
+/*****************************************************************************/
+SDL_bool
+VITA_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("application not compiled with SDL %d.%d\n",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+
+ /* Failed to get window manager information */
+ return SDL_FALSE;
+}
+
+
+/* TO Write Me */
+SDL_bool VITA_HasScreenKeyboardSupport(_THIS)
+{
+ return SDL_FALSE;
+}
+void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window)
+{
+}
+void VITA_HideScreenKeyboard(_THIS, SDL_Window *window)
+{
+}
+SDL_bool VITA_IsScreenKeyboardShown(_THIS, SDL_Window *window)
+{
+ return SDL_FALSE;
+}
+
+void VITA_PumpEvents(_THIS)
+{
+ VITA_PollTouch();
+ VITA_PollKeyboard();
+ VITA_PollMouse();
+}
+
+#endif /* SDL_VIDEO_DRIVER_VITA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/vita/SDL_vitavideo.h b/src/video/vita/SDL_vitavideo.h
new file mode 100644
index 0000000..1902ec6
--- /dev/null
+++ b/src/video/vita/SDL_vitavideo.h
@@ -0,0 +1,102 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SDL_vitavideo_h
+#define _SDL_vitavideo_h
+
+#include "../../SDL_internal.h"
+#include "../SDL_sysvideo.h"
+
+typedef struct SDL_VideoData
+{
+ SDL_bool egl_initialized; /* OpenGL device initialization status */
+ uint32_t egl_refcount; /* OpenGL reference count */
+
+} SDL_VideoData;
+
+
+typedef struct SDL_DisplayData
+{
+
+} SDL_DisplayData;
+
+
+typedef struct SDL_WindowData
+{
+ SDL_bool uses_gles;
+
+} SDL_WindowData;
+
+extern SDL_Window * Vita_Window;
+
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration */
+/****************************************************************************/
+
+/* Display and window functions */
+int VITA_VideoInit(_THIS);
+void VITA_VideoQuit(_THIS);
+void VITA_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+int VITA_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+int VITA_CreateWindow(_THIS, SDL_Window * window);
+int VITA_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+void VITA_SetWindowTitle(_THIS, SDL_Window * window);
+void VITA_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void VITA_SetWindowPosition(_THIS, SDL_Window * window);
+void VITA_SetWindowSize(_THIS, SDL_Window * window);
+void VITA_ShowWindow(_THIS, SDL_Window * window);
+void VITA_HideWindow(_THIS, SDL_Window * window);
+void VITA_RaiseWindow(_THIS, SDL_Window * window);
+void VITA_MaximizeWindow(_THIS, SDL_Window * window);
+void VITA_MinimizeWindow(_THIS, SDL_Window * window);
+void VITA_RestoreWindow(_THIS, SDL_Window * window);
+void VITA_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+void VITA_DestroyWindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool VITA_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+#if SDL_VIDEO_DRIVER_VITA
+/* OpenGL functions */
+int VITA_GL_LoadLibrary(_THIS, const char *path);
+void *VITA_GL_GetProcAddress(_THIS, const char *proc);
+void VITA_GL_UnloadLibrary(_THIS);
+SDL_GLContext VITA_GL_CreateContext(_THIS, SDL_Window * window);
+int VITA_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int VITA_GL_SetSwapInterval(_THIS, int interval);
+int VITA_GL_GetSwapInterval(_THIS);
+int VITA_GL_SwapWindow(_THIS, SDL_Window * window);
+void VITA_GL_DeleteContext(_THIS, SDL_GLContext context);
+#endif
+
+/* VITA on screen keyboard */
+SDL_bool VITA_HasScreenKeyboardSupport(_THIS);
+void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window);
+void VITA_HideScreenKeyboard(_THIS, SDL_Window *window);
+SDL_bool VITA_IsScreenKeyboardShown(_THIS, SDL_Window *window);
+
+void VITA_PumpEvents(_THIS);
+
+#endif /* _SDL_pspvideo_h */
+
+/* vi: set ts=4 sw=4 expandtab: */