this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OSGLUSDL: use time stuff from OSGLUXWN, this is unix after all

This fixes the issue of having the clock not set at startup

+78 -110
+1
setup/WRCNFGAP.i
··· 371 371 WriteDestFileLn("#include <stdio.h>"); 372 372 WriteDestFileLn("#include <stdlib.h>"); 373 373 WriteDestFileLn("#include <string.h>"); 374 + WriteDestFileLn("#include <sys/time.h>"); 374 375 } else if (gbk_apifam_sd2 == gbo_apifam) { 375 376 WriteDestFileLn("#include <SDL2/SDL.h>"); 376 377 WriteDestFileLn("#include <stdio.h>");
+77 -110
src/OSGLUSDL.c
··· 1773 1773 1774 1774 /* --- time, date, location --- */ 1775 1775 1776 + #define HaveWorkingTime 1 1777 + 1776 1778 #define dbglog_TimeStuff (0 && dbglog_HAVE) 1777 1779 1778 1780 LOCALVAR ui5b TrueEmulatedTime = 0; 1779 - /* 1780 - OSGLUxxx common: 1781 - The amount of time the program has 1782 - been running, measured in Macintosh 1783 - "ticks". There are 60.14742 ticks per 1784 - second. 1785 1781 1786 - (time when the emulation is 1787 - stopped for more than a few ticks 1788 - should not be counted.) 1789 - */ 1782 + #include "DATE2SEC.h" 1790 1783 1791 - #if 0 == SDL_MAJOR_VERSION 1792 - #define HaveWorkingTime 0 1793 - #else 1794 - #define HaveWorkingTime 1 1795 - #endif 1784 + #define TicksPerSecond 1000000 1796 1785 1797 - #if 0 != SDL_MAJOR_VERSION 1786 + LOCALVAR blnr HaveTimeDelta = falseblnr; 1787 + LOCALVAR ui5b TimeDelta; 1798 1788 1799 - #define MyInvTimeDivPow 16 1800 - #define MyInvTimeDiv (1 << MyInvTimeDivPow) 1801 - #define MyInvTimeDivMask (MyInvTimeDiv - 1) 1802 - #define MyInvTimeStep 1089590 /* 1000 / 60.14742 * MyInvTimeDiv */ 1789 + LOCALVAR ui5b NewMacDateInSeconds; 1803 1790 1791 + LOCALVAR ui5b LastTimeSec; 1792 + LOCALVAR ui5b LastTimeUsec; 1804 1793 LOCALVAR Uint32 LastTime; 1805 - 1806 1794 LOCALVAR Uint32 NextIntTime; 1807 - LOCALVAR ui5b NextFracTime; 1808 1795 1809 - #endif /* 0 != SDL_MAJOR_VERSION */ 1796 + LOCALPROC GetCurrentTicks(void) 1797 + { 1798 + struct timeval t; 1799 + 1800 + gettimeofday(&t, NULL); 1801 + if (! HaveTimeDelta) { 1802 + time_t Current_Time; 1803 + struct tm *s; 1804 + 1805 + (void) time(&Current_Time); 1806 + s = localtime(&Current_Time); 1807 + TimeDelta = Date2MacSeconds(s->tm_sec, s->tm_min, s->tm_hour, 1808 + s->tm_mday, 1 + s->tm_mon, 1900 + s->tm_year) - t.tv_sec; 1809 + #if 0 && AutoTimeZone /* how portable is this ? */ 1810 + CurMacDelta = ((ui5b)(s->tm_gmtoff) & 0x00FFFFFF) 1811 + | ((s->tm_isdst ? 0x80 : 0) << 24); 1812 + #endif 1813 + HaveTimeDelta = trueblnr; 1814 + } 1815 + 1816 + NewMacDateInSeconds = t.tv_sec + TimeDelta; 1817 + LastTimeSec = (ui5b)t.tv_sec; 1818 + LastTimeUsec = (ui5b)t.tv_usec; 1819 + } 1820 + 1821 + #define MyInvTimeStep 16626 /* TicksPerSecond / 60.14742 */ 1822 + 1823 + LOCALVAR ui5b NextTimeSec; 1824 + LOCALVAR ui5b NextTimeUsec; 1810 1825 1811 1826 LOCALPROC IncrNextTime(void) 1812 1827 { 1813 - #if 0 != SDL_MAJOR_VERSION 1814 - NextFracTime += MyInvTimeStep; 1815 - NextIntTime += (NextFracTime >> MyInvTimeDivPow); 1816 - NextFracTime &= MyInvTimeDivMask; 1817 - #endif /* 0 != SDL_MAJOR_VERSION */ 1828 + NextTimeUsec += MyInvTimeStep; 1829 + if (NextTimeUsec >= TicksPerSecond) { 1830 + NextTimeUsec -= TicksPerSecond; 1831 + NextTimeSec += 1; 1832 + } 1818 1833 } 1819 1834 1820 1835 LOCALPROC InitNextTime(void) 1821 1836 { 1822 - #if 0 != SDL_MAJOR_VERSION 1823 - NextIntTime = LastTime; 1824 - NextFracTime = 0; 1837 + NextTimeSec = LastTimeSec; 1838 + NextTimeUsec = LastTimeUsec; 1825 1839 IncrNextTime(); 1826 - #endif /* 0 != SDL_MAJOR_VERSION */ 1827 1840 } 1828 1841 1829 - LOCALVAR ui5b NewMacDateInSeconds; 1842 + LOCALPROC StartUpTimeAdjust(void) 1843 + { 1844 + GetCurrentTicks(); 1845 + InitNextTime(); 1846 + } 1830 1847 1831 - LOCALFUNC blnr UpdateTrueEmulatedTime(void) 1848 + LOCALFUNC si5b GetTimeDiff(void) 1832 1849 { 1833 - /* 1834 - OSGLUxxx common: 1835 - Update TrueEmulatedTime. Needs to convert between how the host 1836 - operating system measures time and Macintosh ticks. 1837 - */ 1850 + return ((si5b)(LastTimeSec - NextTimeSec)) * TicksPerSecond 1851 + + ((si5b)(LastTimeUsec - NextTimeUsec)); 1852 + } 1838 1853 1839 - #if 0 != SDL_MAJOR_VERSION 1840 - Uint32 LatestTime; 1854 + LOCALPROC UpdateTrueEmulatedTime(void) 1855 + { 1841 1856 si5b TimeDiff; 1842 1857 1843 - LatestTime = SDL_GetTicks(); 1844 - if (LatestTime != LastTime) { 1845 - 1846 - NewMacDateInSeconds = LatestTime / 1000; 1847 - /* no date and time api in SDL */ 1858 + GetCurrentTicks(); 1848 1859 1849 - LastTime = LatestTime; 1850 - TimeDiff = (LatestTime - NextIntTime); 1851 - /* this should work even when time wraps */ 1852 - if (TimeDiff >= 0) { 1853 - if (TimeDiff > 256) { 1854 - /* emulation interrupted, forget it */ 1855 - ++TrueEmulatedTime; 1856 - InitNextTime(); 1860 + TimeDiff = GetTimeDiff(); 1861 + if (TimeDiff >= 0) { 1862 + if (TimeDiff > 16 * MyInvTimeStep) { 1863 + /* emulation interrupted, forget it */ 1864 + ++TrueEmulatedTime; 1865 + InitNextTime(); 1857 1866 1858 1867 #if dbglog_TimeStuff 1859 - dbglog_writelnNum("emulation interrupted", 1860 - TrueEmulatedTime); 1868 + dbglog_writelnNum("emulation interrupted", 1869 + TrueEmulatedTime); 1861 1870 #endif 1862 - } else { 1863 - do { 1864 - ++TrueEmulatedTime; 1865 - IncrNextTime(); 1866 - TimeDiff = (LatestTime - NextIntTime); 1867 - } while (TimeDiff >= 0); 1868 - } 1869 - return trueblnr; 1870 1871 } else { 1871 - if (TimeDiff < -256) { 1872 + do { 1873 + ++TrueEmulatedTime; 1874 + IncrNextTime(); 1875 + TimeDiff -= TicksPerSecond; 1876 + } while (TimeDiff >= 0); 1877 + } 1878 + } else if (TimeDiff < - 16 * MyInvTimeStep) { 1879 + /* clock goofed if ever get here, reset */ 1872 1880 #if dbglog_TimeStuff 1873 - dbglog_writeln("clock set back"); 1881 + dbglog_writeln("clock set back"); 1874 1882 #endif 1875 - /* clock goofed if ever get here, reset */ 1876 - InitNextTime(); 1877 - } 1878 - } 1883 + 1884 + InitNextTime(); 1879 1885 } 1880 - #endif /* 0 != SDL_MAJOR_VERSION */ 1881 - 1882 - return falseblnr; 1883 1886 } 1884 - 1885 1887 1886 1888 LOCALFUNC blnr CheckDateTime(void) 1887 1889 { 1888 - /* 1889 - OSGLUxxx common: 1890 - Update CurMacDateInSeconds, the number 1891 - of seconds since midnight January 1, 1904. 1892 - 1893 - return true if CurMacDateInSeconds is 1894 - different than it was on the last 1895 - call to CheckDateTime. 1896 - */ 1897 - 1898 1890 if (CurMacDateInSeconds != NewMacDateInSeconds) { 1899 1891 CurMacDateInSeconds = NewMacDateInSeconds; 1900 1892 return trueblnr; ··· 1903 1895 } 1904 1896 } 1905 1897 1906 - LOCALPROC StartUpTimeAdjust(void) 1907 - { 1908 - /* 1909 - OSGLUxxx common: 1910 - prepare to call UpdateTrueEmulatedTime. 1911 - 1912 - will be called again when haven't been 1913 - regularly calling UpdateTrueEmulatedTime, 1914 - (such as the emulation has been stopped). 1915 - */ 1916 - 1917 - #if 0 != SDL_MAJOR_VERSION 1918 - LastTime = SDL_GetTicks(); 1919 - #endif 1920 - InitNextTime(); 1921 - } 1922 - 1923 1898 LOCALFUNC blnr InitLocationDat(void) 1924 1899 { 1925 - #if dbglog_OSGInit 1926 - dbglog_writeln("enter InitLocationDat"); 1927 - #endif 1928 - 1929 - #if 0 != SDL_MAJOR_VERSION 1930 - LastTime = SDL_GetTicks(); 1931 - InitNextTime(); 1932 - NewMacDateInSeconds = LastTime / 1000; 1900 + GetCurrentTicks(); 1933 1901 CurMacDateInSeconds = NewMacDateInSeconds; 1934 - #endif 1935 1902 1936 1903 return trueblnr; 1937 1904 }