From da6a4c5b742ea164d8616ebe8aaf39183f441da6 Mon Sep 17 00:00:00 2001 From: "Rustem Gimadutdinov (rgimad)" Date: Wed, 6 May 2020 22:35:48 +0000 Subject: [PATCH] kwine: added time function git-svn-id: svn://kolibrios.org@7880 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/emulator/kwine/bin/lib/msvcrt.dll | Bin 8813 -> 10300 bytes programs/emulator/kwine/bin/samples.zip | Bin 15928 -> 17009 bytes programs/emulator/kwine/lib/kolibrisys.h | 20 +++++ programs/emulator/kwine/lib/msvcrt.dll.c | 9 +++ programs/emulator/kwine/lib/time.c | 86 +++++++++++++++++++++ programs/emulator/kwine/lib/time.h | 29 +++++++ programs/emulator/kwine/readme.txt | 6 +- 7 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 programs/emulator/kwine/lib/kolibrisys.h create mode 100644 programs/emulator/kwine/lib/time.c create mode 100644 programs/emulator/kwine/lib/time.h diff --git a/programs/emulator/kwine/bin/lib/msvcrt.dll b/programs/emulator/kwine/bin/lib/msvcrt.dll index 45f1a6945565d47d60a284ea0b65dcb68934ecbf..3d296d7f5a40eb167d791737f05493bb47d46509 100644 GIT binary patch delta 3656 zcmZ{neQXnD9LJyQx>BLrI_U)FUe3M9W)Lu903l(#oSDhc5ttzg>E>Qo!wL%&5y9M& zGP9--S#F6-AQ3X6^Cb}+>SBgz8QN{2l(^{rAUes=5=tD&A~hMz?{m-fw_TW*^zQR~ zp5OiM_dNGpd%e4Gf-?cNJJ*e0*UjZkk(m0_q zqD(x%5F<)2Rtt+LeSCxwB_vvx^Yqq$Xk8VpsAvs~!-$YK^wv^kR5ZtUlV7gP<&V9j z-^Ou&$P$iO^gGG@@$ysJnUpLwpy1Xgj#s9%hBC@8g%cKjccqXNy+0DHN(8Ql|IH8I z&Xb1xH&aT7N~4kzk0_JKjw%!Ua3>w72RF6$O3I{PNl5xtookeY`j?K5z$L69DT=$V zugY;x)QdIE9XjHw6xFpoSc&>#io6iHk21fL5pyi*|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Z><~s1<65LQn@J z?uBu*F5=@G>_!Yjy-*+24-G&OXp|+cOQtB=7@GJ&8b=$?G?gY1r!tWeXwzsjXme=u zXfM%Tqb;BXXprVgkR>VmqVFw_h6LH*Ex#P{DAdJyqG zGy+ASQ78(HK{03?nuMmH1f+V+>r|*23PTYn0WCsX5SariNmwYYKt`_(CC69O&^AGMWcQNt%ka8vQ7BAD+_b(#m3SR(;ndl+U zysJJL<&n9@=Vb09o&vE?_ET@of_+q4<>cTQi8gqR&w5`;^P0<2e({=ODGvU!#DAXb zI0_e!rTDpcEk!-eDPT!$T&gVP2A66}8RAlBDdMLTv=s3ih&N>RgeJH&TFPVXLcrfW z$GzRs7rBHiWu1$cOZHxFbD8EjbBBp`dF`2{>`B^YAb2K+Kec4pP{?J)QruiVT8dvg kSMImha!+f+<)w$tvW&^gr*To6E$>fWt{9TEjmlg90pp0b>i_@% diff --git a/programs/emulator/kwine/bin/samples.zip b/programs/emulator/kwine/bin/samples.zip index 94a17ff3624a382a5a3e462f9dc8f2ab30ea5140..5fab40f550ddd7d839ab9286d0db135a4733fd46 100644 GIT binary patch delta 1046 zcmdl{^Rb0-!*5d!W)=|!1_llWORnVsx@Lu+d zYjXXsv*yPS9+5NnU|eKuRApqqXz3H+$f_Zh(6GagL5aOokJ*@6yyYQ-;QKlzq2^WW zi95VB#MyWxB(@n`kbkjMWtvLUVcC<8J}a{L7$(LU860THac5icf2P4z##Z4kMv81r zf0GzO4>zqk$C#s{bt379zSY44jSGKroK9k6WN)kgzf9p1t9`&K6=UMt~-%nSM?Nb`VQE|qPQY&n%<~J@} zpkcgTh4)BTy}!S%=edLiHP5y{2UiA$0B>06SpY*Xv-0MORlv|wVa5zSL%qb}+|o(8 z-BN}E$M5UEDVN~$5(&DvHGJ*2#>2M{9bD)xzv6hvBdy_+7Bg5TdR-<(_>b*t8J z@}HUa?Ps1@H)p%jq1bxP%}4)yezfh3ajf^}6#_SMg6>vs|90q*d#-`QbA!6OYr~Xo z{7o>?>3WrBxBG8ZY}oz0XNMnU-OT=`bN-Xgf}UGf4^(-%98_@qpfP2KIY;$+ z?E~j^E0-^fr&g=B7hPis)Ye!(UBRYFHCC1y7~q^7J^R^fcamOH&;hv#+9 zkCM)ZKK1xb+jVazdrtJ@3+fkl$*$P@nQPzw%%AM+BJKBYm^A9{_`0i4n=fBKNOMoK z_^T%Vwwepimsl+Js6BuFE!*_RA77kZU4J^sW#0d?H(z!yU-n$BzWifxZ(yE>wbxU} zJLnY1<+7q^C&x;*$ukH{t=_j7;(jT) znb%C5qaGxVE6=EalmUSP5dSnq%|V8GsTHYQU?~O$Mg|E6x0~5|UzD#gDm3SV>G0i= za!-MLh}94)FcVfZvK^Dn(d_`HGh{pb=P%L)*`ZRh1Wd15FT3yw*bY`;CTCy}2g3Ip K3=BDzARYiK>63Q= delta 34 kcmey^!nmVm!*A2gd6t?SBCKo-Kp+Z)nj8!aKTSbA0KXFlz5oCK diff --git a/programs/emulator/kwine/lib/kolibrisys.h b/programs/emulator/kwine/lib/kolibrisys.h new file mode 100644 index 0000000000..ad5ac1e2a7 --- /dev/null +++ b/programs/emulator/kwine/lib/kolibrisys.h @@ -0,0 +1,20 @@ +#ifndef __KOS_32_SYS_H__ +#define __KOS_32_SYS_H__ + +#include "stddef.h" + +static inline uint32_t _ksys_get_date(void) +{ + uint32_t val; + asm volatile ("int $0x40":"=a"(val):"a"(29)); + return val; +} + +static inline uint32_t _ksys_get_system_clock(void) +{ + uint32_t val; + asm volatile ("int $0x40":"=a"(val):"a"(3)); + return val; +} + +#endif \ No newline at end of file diff --git a/programs/emulator/kwine/lib/msvcrt.dll.c b/programs/emulator/kwine/lib/msvcrt.dll.c index 8cdf7a038e..55d6405c50 100644 --- a/programs/emulator/kwine/lib/msvcrt.dll.c +++ b/programs/emulator/kwine/lib/msvcrt.dll.c @@ -12,6 +12,9 @@ #include "stdio.c" #include "stdlib.c" +#include "time.h" +#include "time.c" + typedef struct { @@ -39,6 +42,9 @@ const char sz_free[] = "free"; const char sz_realloc[] = "realloc"; //const char sz_[] = ""; +// time +const char sz_time[] = "time"; + //uint32_t EXPORTS[] __asm__("EXPORTS") = export_t EXPORTS[] = @@ -57,6 +63,9 @@ export_t EXPORTS[] = {sz_malloc, (void*)malloc}, {sz_free, (void*)free}, {sz_realloc, (void*)realloc}, + + {sz_time, (void*)time}, + {NULL, NULL}, }; diff --git a/programs/emulator/kwine/lib/time.c b/programs/emulator/kwine/lib/time.c new file mode 100644 index 0000000000..eda6634933 --- /dev/null +++ b/programs/emulator/kwine/lib/time.c @@ -0,0 +1,86 @@ +#include "time.h" +#include "kolibrisys.h" + +struct tm __buffertime; + +struct tm * localtime (const time_t * timer) +/* non-standard! ignore parameter and return just time now */ +{ + int kos_date, kos_time; + kos_date = _ksys_get_date(); + kos_time = _ksys_get_system_clock(); + + int bcd_day = (kos_date >> 16); + int bcd_mon = ((kos_date & 0xFF00) >> 8); + int bcd_year = (kos_date & 0xFF); + __buffertime.tm_mday = ((bcd_day & 0xF0)>>4)*10 + (bcd_day & 0x0F); + __buffertime.tm_mon = ((bcd_mon & 0xF0)>>4)*10 + (bcd_mon & 0x0F) - 1; + __buffertime.tm_year = ((bcd_year & 0xF0)>>4)*10 + (bcd_year & 0x0F) + 100; + //printf("%d %d %d\n", __buffertime.tm_mday, __buffertime.tm_mon, __buffertime.tm_year); + + __buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */ + + int bcd_sec = (kos_time >> 16); + int bcd_min = ((kos_time & 0xFF00) >> 8); + int bcd_hour = (kos_time & 0xFF); + + __buffertime.tm_sec = ((bcd_sec & 0xF0)>>4)*10 + (bcd_sec & 0x0F); + __buffertime.tm_min = ((bcd_min & 0xF0)>>4)*10 + (bcd_min & 0x0F); + __buffertime.tm_hour = ((bcd_hour & 0xF0)>>4)*10 + (bcd_hour & 0x0F); + //printf("%d %d %d\n", __buffertime.tm_sec, __buffertime.tm_min, __buffertime.tm_hour); + + return &__buffertime; +} + +time_t time (time_t* timer) +{ + time_t t = mktime(localtime(0)); + if (timer) *timer = t; + return t; +} + +time_t mktime (struct tm * timeptr) +{ + /*int y, m, d; + time_t t; + y = timeptr->tm_year + 1900; + m = timeptr->tm_mon + 1; + d = timeptr->tm_mday; // to -1 or not to -1? + + if (m < 3) { m += 12; y -= 1; } + + t = y * 365 + y / 4 + y /400 - y / 100; // years - > days + t += 30 * m + 3 * (m + 1) / 5 + d; // add month days + + t -= 719561; // 01 jan 1970 + t *= 86400; + + t += 3600 * timeptr->tm_hour + 60 * timeptr->tm_min + timeptr->tm_sec; + + return t;*/ + + int utcdiff = -3; + const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + unsigned long int tyears, tdays, leaps, utc_hrs; + int i; + + tyears = timeptr->tm_year - 70 ;// tm->tm_year is from 1900. + leaps = (tyears + 2) / 4; // no of next two lines until year 2100. + i = (timeptr->tm_year - 100) / 100; + leaps -= ( (i/4)*3 + i%4 ); + tdays = 0; + for (i=0; i < timeptr->tm_mon; i++) tdays += mon_days[i]; + + tdays += timeptr->tm_mday-1; // days of month passed. + tdays = tdays + (tyears * 365) + leaps; + + utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone. + return (tdays * 86400) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec; +} + +double difftime (time_t end, time_t beginning) +{ + return end - beginning; +} + + diff --git a/programs/emulator/kwine/lib/time.h b/programs/emulator/kwine/lib/time.h new file mode 100644 index 0000000000..584cd587eb --- /dev/null +++ b/programs/emulator/kwine/lib/time.h @@ -0,0 +1,29 @@ +#ifndef _TIME_H +#define _TIME_H + +typedef unsigned long int clock_t; +typedef unsigned long int time_t; +//#define clock() get_tick_count() +#define CLOCKS_PER_SEC 100 + +struct tm { + int tm_sec; /* seconds after the minute 0-61*/ + int tm_min; /* minutes after the hour 0-59 */ + int tm_hour; /* hours since midnight 0-23 */ + int tm_mday; /* day of the month 1-31 */ + int tm_mon; /* months since January 0-11 */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday 0-6 */ + int tm_yday; /* days since January 1 0-365 */ + int tm_isdst; /* Daylight Saving Time flag */ +}; + +time_t mktime(struct tm * timeptr); +time_t time(time_t* timer); +struct tm * localtime(const time_t * timer); /* non-standard! ignore parameter and return just time now, not generate tm_isdst, tm_yday, tm_wday == -1 */ +double difftime(time_t end, time_t beginning); + +extern struct tm __buffertime; + +#endif + diff --git a/programs/emulator/kwine/readme.txt b/programs/emulator/kwine/readme.txt index c8cc192220..594c7f3748 100644 --- a/programs/emulator/kwine/readme.txt +++ b/programs/emulator/kwine/readme.txt @@ -1,4 +1,4 @@ -KWINE v0.0.2 +KWINE Developers: - 0CodErr founder of project PEload @@ -9,7 +9,3 @@ How to use: kwine, lib/kernel32.dll, lib/msvcrt.dll - usage: kwine mysuperexefile.exe - -Changelog: - - msvcrt.dll rewritten in c - - added malloc, free, realloc, strcmp, strcat, strlen, printf to msvcrt.dll \ No newline at end of file