diff --git a/desmume/src/GPU_osd.cpp b/desmume/src/GPU_osd.cpp index 5717b8ca1..26f485214 100644 --- a/desmume/src/GPU_osd.cpp +++ b/desmume/src/GPU_osd.cpp @@ -1,21 +1,18 @@ /* Copyright (C) 2006 yopyop Copyright (C) 2006-2010 DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ #include "GPU_osd.h" @@ -562,9 +559,9 @@ void DrawHUD() if (CommonSettings.hud.ShowRTC) { - struct tm tm = rtcGetTime(); - const char *wday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - osd->addFixed(Hud.RTCDisplay.x, Hud.RTCDisplay.y, "%04d-%02d-%02d %s %02d:%02d:%02d", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, wday[tm.tm_wday%7], tm.tm_hour, tm.tm_min, tm.tm_sec); + DateTime tm = rtcGetTime(); + static const char *wday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + osd->addFixed(Hud.RTCDisplay.x, Hud.RTCDisplay.y, "%04d-%03s-%02d %s %02d:%02d:%02d", tm.get_Year(), DateTime::GetNameOfMonth(tm.get_Month()), tm.get_Day(), wday[tm.get_DayOfWeek()%7], tm.get_Hour(), tm.get_Minute(), tm.get_Second()); } DrawStateSlots(); diff --git a/desmume/src/Makefile.am b/desmume/src/Makefile.am index a4967c7f4..3b057e886 100644 --- a/desmume/src/Makefile.am +++ b/desmume/src/Makefile.am @@ -42,7 +42,7 @@ libdesmume_a_SOURCES = \ shaders.h \ movie.cpp movie.h \ PACKED.h PACKED_END.h \ - utils/mkgmtime.cpp utils/mkgmtime.h \ + utils/datetime.cpp utils/datetime.h \ utils/ConvertUTF.c utils/ConvertUTF.h utils/guid.cpp utils/guid.h \ utils/md5.cpp utils/md5.h utils/valuearray.h utils/xstring.cpp utils/xstring.h \ utils/decrypt/crc.cpp utils/decrypt/crc.h utils/decrypt/decrypt.cpp \ diff --git a/desmume/src/movie.cpp b/desmume/src/movie.cpp index 8d5ec255b..b1fc6dca8 100644 --- a/desmume/src/movie.cpp +++ b/desmume/src/movie.cpp @@ -1,20 +1,17 @@ /* Copyright 2008-2010 DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ #define WIN32_LEAN_AND_MEAN @@ -24,7 +21,7 @@ #include #include "utils/guid.h" #include "utils/xstring.h" -#include "utils/mkgmtime.h" +#include "utils/datetime.h" #include "movie.h" #include "NDSSystem.h" #include "readwrite.h" @@ -167,27 +164,10 @@ void MovieRecord::dump(MovieData* md, EMUFILE* fp, int index) fp->fputc('\n'); } -time_t FCEUI_MovieGetRTCDefault() +DateTime FCEUI_MovieGetRTCDefault() { - time_t timer; - // compatible with old desmume - struct tm t; - t.tm_year = 109; // 2009 - t.tm_mon = 0; // 1 (Jan) - t.tm_mday = 1; - t.tm_wday = 4; - t.tm_hour = 0; //12 AM - t.tm_min = 0; - t.tm_sec = 0; - timer = mkgmtime(&t); - - // current time - //timer = time(NULL); - //struct tm *tp = localtime(&timer); - //timer = mkgmtime(tp); - - return timer; + return DateTime(2009,1,1,0,0,0); } MovieData::MovieData() @@ -238,15 +218,18 @@ void MovieData::installValue(std::string& key, std::string& val) if (validFormat) { struct tm t; const char *s = val.data(); - t.tm_year = atoi(&s[0]) - 1900; - t.tm_mon = atoi(&s[5]) - 1; - t.tm_mday = atoi(&s[8]); - t.tm_hour = atoi(&s[11]); - t.tm_min = atoi(&s[14]); - t.tm_sec = atoi(&s[17]); - rtcStart = mkgmtime(&t); + int year = atoi(&s[0]); + int mon = atoi(&s[5]); + int day = atoi(&s[8]); + int hour = atoi(&s[11]); + int min = atoi(&s[14]); + int sec = atoi(&s[17]); + rtcStart = DateTime(year,mon,day,hour,min,sec); } } + else if(key == "rtcStartNew") { + DateTime::TryParse(val.c_str(),rtcStart); + } else if(key == "comment") comments.push_back(mbstowcs(val)); else if(key == "binary") @@ -320,10 +303,7 @@ int MovieData::dump(EMUFILE* fp, bool binary) fp->fprintf("firmLanguage %d\n", CommonSettings.InternalFirmConf.language); } - char timestr[32]; - struct tm *tm = gmtime(&rtcStart); - strftime(timestr, 32, "%Y-%m-%dT%H:%M:%SZ", tm); - fp->fprintf("rtcStart %s\n", timestr); + fp->fprintf("rtcStartNew %s\n", rtcStart.ToString().c_str()); for(uint32 i=0;ifprintf("comment %s\n", wcstombs(comments[i]).c_str()); @@ -646,7 +626,7 @@ bool MovieData::loadSramFrom(std::vector* buf) //begin recording a new movie //TODO - BUG - the record-from-another-savestate doesnt work. -void _CDECL_ FCEUI_SaveMovie(const char *fname, std::wstring author, int flag, std::string sramfname, time_t rtcstart) +void FCEUI_SaveMovie(const char *fname, std::wstring author, int flag, std::string sramfname, const DateTime &rtcstart) { //if(!FCEU_IsValidUI(FCEUI_RECORDMOVIE)) // return; diff --git a/desmume/src/movie.h b/desmume/src/movie.h index 3a01027e5..de2ef55d2 100644 --- a/desmume/src/movie.h +++ b/desmume/src/movie.h @@ -1,3 +1,19 @@ +/* Copyright 2008-2010 DeSmuME team + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the this software. If not, see . +*/ + #ifndef __MOVIE_H_ #define __MOVIE_H_ @@ -8,6 +24,7 @@ #include #include "emufile.h" +#include "utils/datetime.h" #include "utils/guid.h" #include "utils/md5.h" @@ -129,7 +146,7 @@ public: int rerecordCount; Desmume_Guid guid; - time_t rtcStart; // (time_t) it always means gmtime, not localtime. + DateTime rtcStart; //was the frame data stored in binary? bool binaryFlag; @@ -195,7 +212,7 @@ extern MovieData currMovieData; //adelikat: main needs this for frame counter d extern bool movie_reset_command; bool FCEUI_MovieGetInfo(EMUFILE* fp, MOVIE_INFO& info, bool skipFrameCount); -void _CDECL_ FCEUI_SaveMovie(const char *fname, std::wstring author, int flag, std::string sramfname, time_t rtcstart); +void FCEUI_SaveMovie(const char *fname, std::wstring author, int flag, std::string sramfname, const DateTime &rtcstart); const char* _CDECL_ FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _pauseframe); // returns NULL on success, errmsg on failure void FCEUI_StopMovie(); void FCEUMOV_AddInputState(); @@ -208,5 +225,5 @@ bool LoadFM2(MovieData& movieData, EMUFILE* fp, int size, bool stopAfterHeader); extern bool movie_readonly; extern bool ShowInputDisplay; void FCEUI_MakeBackupMovie(bool dispMessage); -time_t FCEUI_MovieGetRTCDefault(); +DateTime FCEUI_MovieGetRTCDefault(); #endif diff --git a/desmume/src/rtc.cpp b/desmume/src/rtc.cpp index 7d36c11d7..1ebaef8c0 100644 --- a/desmume/src/rtc.cpp +++ b/desmume/src/rtc.cpp @@ -1,22 +1,19 @@ -/* Copyright (C) 2006 yopyop +/* Copyright 2006 yopyop Copyright 2008 CrazyMax Copyright 2008-2010 DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ // TODO: interrupt handler @@ -32,8 +29,6 @@ #endif #include "movie.h" -#include "utils/mkgmtime.h" - typedef struct { @@ -98,13 +93,11 @@ static inline u8 toBCD(u8 x) bool moviemode=false; -struct tm rtcGetTime(void) +DateTime rtcGetTime(void) { - struct tm *tm = NULL; + DateTime tm; if(movieMode == MOVIEMODE_INACTIVE) { - time_t timer; - time(&timer); - tm = localtime(&timer); + return DateTime::get_Now(); } else { //now, you might think it is silly to go through all these conniptions @@ -117,20 +110,9 @@ struct tm rtcGetTime(void) u64 totalcycles = (u64)arm9rate_unitsperframe * currFrameCounter; u64 totalseconds=totalcycles/arm9rate_unitspersecond; - time_t timer; - struct tm t; - - // store start time into structure tm - timer = (time_t) currMovieData.rtcStart; - memcpy(&t, gmtime(&timer), sizeof(struct tm)); - // advance it according to the frame counter - t.tm_sec += totalseconds; - // then, normalize it - timer = mkgmtime(&t); - tm = gmtime(&timer); + DateTime timer = currMovieData.rtcStart; + return timer.AddSeconds(totalseconds); } - tm->tm_year = 100 + (tm->tm_year % 100); // 20XX - return *tm; } static void rtcRecv() @@ -153,10 +135,10 @@ static void rtcRecv() case 2: // date & time { //INFO("RTC: read date & time\n"); - struct tm tm = rtcGetTime(); - rtc.data[0] = toBCD(tm.tm_year % 100); - rtc.data[1] = toBCD(tm.tm_mon + 1); - rtc.data[2] = toBCD(tm.tm_mday); + DateTime tm = rtcGetTime(); + rtc.data[0] = toBCD(tm.get_Year() % 100); + rtc.data[1] = toBCD(tm.get_Month()); + rtc.data[2] = toBCD(tm.get_Day()); //zero 24-apr-2010 - this is nonsense. //but it is so wrong, someone mustve thought they knew what they were doing, so i am leaving it... @@ -166,22 +148,24 @@ static void rtcRecv() //do this instead (gbatek seems to say monday=0 but i don't think that is right) //0=sunday is necessary to make animal crossing behave //maybe it means "custom assignment" can be specified by the game - rtc.data[3] = tm.tm_wday; + rtc.data[3] = tm.get_DayOfWeek(); - if (!(rtc.regStatus1 & 0x02)) tm.tm_hour %= 12; - rtc.data[4] = ((tm.tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm.tm_hour); - rtc.data[5] = toBCD(tm.tm_min); - rtc.data[6] = toBCD(tm.tm_sec); + int hour = tm.get_Hour(); + if (!(rtc.regStatus1 & 0x02)) hour %= 12; + rtc.data[4] = ((hour < 12) ? 0x00 : 0x40) | toBCD(hour); + rtc.data[5] = toBCD(tm.get_Minute()); + rtc.data[6] = toBCD(tm.get_Second()); break; } case 3: // time { //INFO("RTC: read time\n"); - struct tm tm = rtcGetTime(); - if (!(rtc.regStatus1 & 0x02)) tm.tm_hour %= 12; - rtc.data[0] = ((tm.tm_hour < 12) ? 0x00 : 0x40) | toBCD(tm.tm_hour); - rtc.data[1] = toBCD(tm.tm_min); - rtc.data[2] = toBCD(tm.tm_sec); + DateTime tm = rtcGetTime(); + int hour = tm.get_Hour(); + if (!(rtc.regStatus1 & 0x02)) hour %= 12; + rtc.data[0] = ((hour < 12) ? 0x00 : 0x40) | toBCD(hour); + rtc.data[1] = toBCD(tm.get_Minute()); + rtc.data[2] = toBCD(tm.get_Second()); break; } case 4: // freq/alarm 1 diff --git a/desmume/src/rtc.h b/desmume/src/rtc.h index f8e924bac..418a56194 100644 --- a/desmume/src/rtc.h +++ b/desmume/src/rtc.h @@ -1,22 +1,19 @@ -/* Copyright (C) 2006 yopyop +/* Copyright 2006 yopyop Copyright 2008 CrazyMax Copyright 2008-2010 DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ #ifndef _RTC_H_ @@ -24,8 +21,9 @@ #include #include #include "types.h" +#include "utils/datetime.h" -struct tm rtcGetTime(void); +DateTime rtcGetTime(void); extern void rtcInit(); extern u16 rtcRead(); diff --git a/desmume/src/utils/datetime.cpp b/desmume/src/utils/datetime.cpp new file mode 100644 index 000000000..f68eea0f8 --- /dev/null +++ b/desmume/src/utils/datetime.cpp @@ -0,0 +1,5 @@ +#include "datetime.h" + +const char* DateTime::monthnames[] = { NULL, "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; +const int DateTime::daysmonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +const int DateTime::daysmonthleap[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; diff --git a/desmume/src/utils/datetime.h b/desmume/src/utils/datetime.h new file mode 100644 index 000000000..a1847fe71 --- /dev/null +++ b/desmume/src/utils/datetime.h @@ -0,0 +1,814 @@ +/* Copyright (C) 2010 DeSmuME team + + This file is based on System.DateTime.cs and System.TimeSpan.cs from mono-2.6.7 + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the this software. If not, see . +*/ + +// +// System.DateTime.cs +// +// author: +// Marcel Narings (marcel@narings.nl) +// Martin Baulig (martin@gnome.org) +// Atsushi Enomoto (atsushi@ximian.com) +// +// (C) 2001 Marcel Narings +// Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// +// System.TimeSpan.cs +// +// Authors: +// Duco Fijma (duco@lorentz.xs4all.nl) +// Andreas Nahr (ClassDevelopment@A-SoftTech.com) +// Sebastien Pouliot +// +// (C) 2001 Duco Fijma +// (C) 2004 Andreas Nahr +// Copyright (C) 2004 Novell (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#ifndef _DATETIME_H_ +#define _DATETIME_H_ + +#include +#include + +#include +#include + +#include "types.h" + +enum DayOfWeek { + DayOfWeek_Sunday=0, + DayOfWeek_Monday=1, + DayOfWeek_Tuesday=2, + DayOfWeek_Wednesday=3, + DayOfWeek_Thursday=4, + DayOfWeek_Friday=5, + DayOfWeek_Saturday=6 +}; + +class TimeSpan +{ + friend class DateTime; + +public: + static const TimeSpan& get_MaxValue() + { + static TimeSpan val(0x7FFFFFFFFFFFFFFFLL); + return val; + } + + static const TimeSpan& get_MinValue() + { + static TimeSpan val(0x8000000000000000LL); + return val; + } + + static const TimeSpan& get_Zero() + { + static TimeSpan val(0); + return val; + } + + static const s64 TicksPerDay = 864000000000LL; + static const s64 TicksPerHour = 36000000000LL; + static const s64 TicksPerMillisecond = 10000LL; + static const s64 TicksPerMinute = 600000000LL; + static const s64 TicksPerSecond = 10000000LL; + + TimeSpan () + { + } + + TimeSpan (s64 ticks) + : _ticks(ticks) + { + } + + TimeSpan (int hours, int minutes, int seconds) + { + _ticks = CalculateTicks (0, hours, minutes, seconds, 0); + } + + TimeSpan (int days, int hours, int minutes, int seconds) + { + _ticks = CalculateTicks (days, hours, minutes, seconds, 0); + } + + TimeSpan (int days, int hours, int minutes, int seconds, int milliseconds) + { + _ticks = CalculateTicks (days, hours, minutes, seconds, milliseconds); + } + + int get_Days() const { return (int) (_ticks / TicksPerDay); } + int get_Hours() const { return (int) (_ticks % TicksPerDay / TicksPerHour); } + int get_Milliseconds() const { return (int) (_ticks % TicksPerSecond / TicksPerMillisecond); } + int get_Minutes() const { return (int) (_ticks % TicksPerHour / TicksPerMinute); } + int get_Seconds() const { return (int) (_ticks % TicksPerMinute / TicksPerSecond); } + s64 get_Ticks() const { return _ticks; } + double get_TotalDays() const { return (double) _ticks / TicksPerDay; } + double get_TotalHours() const { return (double) _ticks / TicksPerHour; } + double get_TotalMilliseconds() const { return (double) _ticks / TicksPerMillisecond; } + double get_TotalMinutes() const { return (double) _ticks / TicksPerMinute; } + double get_TotalSeconds() const { return (double) _ticks / TicksPerSecond; } + + TimeSpan Add (const TimeSpan &ts) + { + return TimeSpan (_ticks + ts._ticks); + //removed: + //catch (OverflowException) throw new OverflowException (Locale.GetText ("Resulting timespan is too big.")); + } + + static int Compare (const TimeSpan& t1, const TimeSpan& t2) + { + if (t1._ticks < t2._ticks) + return -1; + if (t1._ticks > t2._ticks) + return 1; + return 0; + } + + int CompareTo (const TimeSpan& value) + { + return Compare (*this, value); + } + + TimeSpan Duration () + { + return TimeSpan(_ticks<0?-_ticks:_ticks); + //removed: + //catch (OverflowException) throw new OverflowException (Locale.GetText ("This TimeSpan value is MinValue so you cannot get the duration.")); + } + + static TimeSpan FromDays (double value) + { + return From (value, TicksPerDay); + } + + static TimeSpan FromHours (double value) + { + return From (value, TicksPerHour); + } + + static TimeSpan FromMinutes (double value) + { + return From (value, TicksPerMinute); + } + + static TimeSpan FromSeconds (double value) + { + return From (value, TicksPerSecond); + } + + static TimeSpan FromMilliseconds (double value) + { + return From (value, TicksPerMillisecond); + } + + static TimeSpan FromTicks (s64 value) + { + return TimeSpan (value); + } + + TimeSpan Negate () + { + //removed error handling + //if (_ticks == MinValue()._ticks) throw new OverflowException (Locale.GetText ( "This TimeSpan value is MinValue and cannot be negated.")); + return TimeSpan (-_ticks); + } + + TimeSpan Subtract (const TimeSpan& ts) + { + //removed error handling + //try { checked { + return TimeSpan (_ticks - ts._ticks); + // } + //} + //catch (OverflowException) { + // throw new OverflowException (Locale.GetText ("Resulting timespan is too big.")); + //} + } + + TimeSpan operator + (const TimeSpan& t2) const + { + TimeSpan temp = *this; + temp.Add (t2); + return temp; + } + + bool operator == (const TimeSpan& t2) const + { + return _ticks == t2._ticks; + } + + bool operator > (const TimeSpan& t2) const + { + return _ticks > t2._ticks; + } + + bool operator >= (const TimeSpan& t2) const + { + return _ticks >= t2._ticks; + } + + bool operator != (const TimeSpan& t2) const + { + return _ticks != t2._ticks; + } + + bool operator < (const TimeSpan& t2) const + { + return _ticks < t2._ticks; + } + + bool operator <= (const TimeSpan& t2) const + { + return _ticks <= t2._ticks; + } + + TimeSpan operator - (const TimeSpan& t2) const + { + TimeSpan temp = *this; + return temp.Subtract (t2); + } + + TimeSpan operator - () + { + return Negate (); + } + + +private: + s64 _ticks; + + static s64 CalculateTicks (int days, int hours, int minutes, int seconds, int milliseconds) + { + // there's no overflow checks for hours, minutes, ... + // so big hours/minutes values can overflow at some point and change expected values + int hrssec = (hours * 3600); // break point at (Int32.MaxValue - 596523) + int minsec = (minutes * 60); + s64 t = ((s64)(hrssec + minsec + seconds) * 1000L + (s64)milliseconds); + t *= 10000; + + bool overflow = false; + // days is problematic because it can overflow but that overflow can be + // "legal" (i.e. temporary) (e.g. if other parameters are negative) or + // illegal (e.g. sign change). + if (days > 0) { + s64 td = TicksPerDay * days; + if (t < 0) { + s64 ticks = t; + t += td; + // positive days -> total ticks should be lower + overflow = (ticks > t); + } + else { + t += td; + // positive + positive != negative result + overflow = (t < 0); + } + } + else if (days < 0) { + s64 td = TicksPerDay * days; + if (t <= 0) { + t += td; + // negative + negative != positive result + overflow = (t > 0); + } + else { + s64 ticks = t; + t += td; + // negative days -> total ticks should be lower + overflow = (t > ticks); + } + } + + //removed: + //if (overflow) throw ArgumentOutOfRangeException ("The timespan is too big or too small."); + + return t; + } + + static TimeSpan From (double value, s64 tickMultiplicator) + { + //a bunch of error handling removed + + //if (Double.IsNaN (value)) throw new ArgumentException (Locale.GetText ("Value cannot be NaN."), "value"); + //if (Double.IsNegativeInfinity (value) || Double.IsPositiveInfinity (value) || + // (value < MinValue.Ticks) || (value > MaxValue.Ticks)) + // throw new OverflowException (Locale.GetText ("Outside range [MinValue,MaxValue]")); + + //try { + value = (value * (tickMultiplicator / TicksPerMillisecond)); + + // checked { + // long val = (long) Math.Round(value); + // return new TimeSpan (val * TicksPerMillisecond); + // } + //} + //catch (OverflowException) { + // throw new OverflowException (Locale.GetText ("Resulting timespan is too big.")); + //} + //} + } + +}; + +class DateTime +{ +private: + TimeSpan ticks; + + static inline double round(const double x) { return floor(x + 0.5); } + + static const int dp400 = 146097; + static const int dp100 = 36524; + static const int dp4 = 1461; + + // w32 file time starts counting from 1/1/1601 00:00 GMT + // which is the constant ticks from the .NET epoch + static const s64 w32file_epoch = 504911232000000000LL; + + //private const long MAX_VALUE_TICKS = 3155378975400000000L; + // -- Microsoft .NET has this value. + static const s64 MAX_VALUE_TICKS = 3155378975999999999LL; + + // + // The UnixEpoch, it begins on Jan 1, 1970 at 0:0:0, expressed + // in Ticks + // + static const s64 UnixEpoch = 621355968000000000LL; + + + static const int daysmonth[13]; + static const int daysmonthleap[13]; + static const char* monthnames[13]; + + void init (int year, int month, int day, int hour, int minute, int second, int millisecond) + { + //removed error handling + /* if ( year < 1 || year > 9999 || + month < 1 || month >12 || + day < 1 || day > DaysInMonth(year, month) || + hour < 0 || hour > 23 || + minute < 0 || minute > 59 || + second < 0 || second > 59 || + millisecond < 0 || millisecond > 999) + throw new ArgumentOutOfRangeException ("Parameters describe an " + + "unrepresentable DateTime.");*/ + + ticks = TimeSpan (AbsoluteDays(year,month,day), hour, minute, second, millisecond); + } + + + + static int AbsoluteDays (int year, int month, int day) + { + const int* days; + int temp = 0, m=1 ; + + days = (IsLeapYear(year) ? daysmonthleap : daysmonth); + + while (m < month) + temp += days[m++]; + return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400)); + } + + + enum Which + { + Which_Day, + Which_DayYear, + Which_Month, + Which_Year + }; + + int FromTicks(Which what) const + { + int num400, num100, num4, numyears; + int M =1; + + const int* days = daysmonth; + int totaldays = ticks.get_Days(); + + num400 = (totaldays / dp400); + totaldays -= num400 * dp400; + + num100 = (totaldays / dp100); + if (num100 == 4) // leap + num100 = 3; + totaldays -= (num100 * dp100); + + num4 = totaldays / dp4; + totaldays -= (num4 * dp4); + + numyears = totaldays / 365 ; + + if (numyears == 4) //leap + numyears =3 ; + if (what == Which_Year ) + return num400*400 + num100*100 + num4*4 + numyears + 1; + + totaldays -= (numyears * 365) ; + if (what == Which_DayYear ) + return totaldays + 1; + + if ((numyears==3) && ((num100 == 3) || !(num4 == 24)) ) //31 dec leapyear + days = daysmonthleap; + + while (totaldays >= days[M]) + totaldays -= days[M++]; + + if (what == Which_Month ) + return M; + + return totaldays +1; + } + +public: + DateTime() + : ticks(0) + { + } + + static const char* GetNameOfMonth(int month) { return monthnames[month]; } + + DateTime (s64 ticks) + { + this->ticks = TimeSpan (ticks); + //removed error handling + //if (ticks < get_MinValue().get_Ticks() || ticks > get_MaxValue().get_Ticks()) { + // string msg = Locale.GetText ("Value {0} is outside the valid range [{1},{2}].", + // ticks, MinValue.Ticks, MaxValue.Ticks); + // throw new ArgumentOutOfRangeException ("ticks", msg); + //} + } + + static const DateTime& get_MaxValue() { + static DateTime val(false, TimeSpan (MAX_VALUE_TICKS)); + return val; + } + + static const DateTime& get_MinValue() { + static DateTime val(false, TimeSpan (0)); + return val; + } + + DateTime (int year, int month, int day) + { + init(year,month,day,0,0,0,0); + } + + DateTime (int year, int month, int day, int hour, int minute, int second) + { + init(year, month, day, hour, minute, second, 0); + } + + DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond) + { + init(year,month,day,hour,minute,second,millisecond); + } + + + DateTime (bool check, const TimeSpan& value) + { + //removed error handling + //if (check && (value.Ticks < MinValue.Ticks || value.Ticks > MaxValue.Ticks)) + // throw new ArgumentOutOfRangeException (); + + ticks = value; + } + + DateTime get_Date () const + { + return DateTime (get_Year(), get_Month(), get_Day()); + } + + int get_Month () const { + return FromTicks(Which_Month); + } + + int get_Day() const + { + return FromTicks(Which_Day); + } + + DayOfWeek get_DayOfWeek () const + { + return ( (DayOfWeek) ((ticks.get_Days()+1) % 7) ); + } + + int get_DayOfYear () const + { + return FromTicks(Which_DayYear); + } + + TimeSpan get_TimeOfDay () const + { + return TimeSpan(ticks.get_Ticks() % TimeSpan::TicksPerDay ); + } + + int get_Hour () const + { + return ticks.get_Hours(); + } + + int get_Minute () const + { + return ticks.get_Minutes(); + } + + int get_Second () const + { + return ticks.get_Seconds(); + } + + int get_Millisecond () const + { + return ticks.get_Milliseconds(); + } + + //internal static extern s64 GetTimeMonotonic (); + //internal static extern s64 GetNow (); + + static DateTime get_Now () + { + time_t timer; + time(&timer); + struct tm *tm = localtime(&timer); + return DateTime(tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec); + } + + s64 get_Ticks()const + { + return ticks.get_Ticks(); + } + + static DateTime get_Today () + { + DateTime now = get_Now(); + DateTime today = DateTime (now.get_Year(), now.get_Month(), now.get_Day()); + return today; + } + + int get_Year () const + { + return FromTicks(Which_Year); + } + + DateTime Add (const TimeSpan& value) const + { + DateTime ret = AddTicks (value.get_Ticks()); + return ret; + } + + DateTime AddDays (double value) const + { + return AddMilliseconds (round(value * 86400000)); + } + + DateTime AddTicks (const s64 value) const + { + //removed error handling + //if ((value + ticks.Ticks) > MAX_VALUE_TICKS || (value + ticks.Ticks) < 0) { + // throw new ArgumentOutOfRangeException(); + //} + return DateTime (value + ticks.get_Ticks()); + } + + DateTime AddHours (double value) const + { + return AddMilliseconds (value * 3600000); + } + + DateTime AddMilliseconds (double value) const + { + //removed error handling + /* if ((value * TimeSpan.TicksPerMillisecond) > long.MaxValue || + (value * TimeSpan.TicksPerMillisecond) < long.MinValue) { + throw new ArgumentOutOfRangeException(); + } + */ + s64 msticks = (s64) round(value * TimeSpan::TicksPerMillisecond); + return AddTicks (msticks); + } + + DateTime AddMinutes (double value) const + { + return AddMilliseconds (value * 60000); + } + + DateTime AddMonths (int months) const + { + int day, month, year, maxday ; + DateTime temp; + + day = get_Day(); + month = get_Month() + (months % 12); + year = get_Year() + months/12 ; + + if (month < 1) + { + month = 12 + month ; + year -- ; + } + else if (month>12) + { + month = month -12; + year ++; + } + maxday = DaysInMonth(year, month); + if (day > maxday) + day = maxday; + + temp = (year, month, day); + return temp.Add (get_TimeOfDay()); + } + + DateTime AddSeconds (double value) const + { + return AddMilliseconds (value * 1000); + } + + DateTime AddYears (int value) const + { + return AddMonths (value * 12); + } + + static int Compare (const DateTime& t1, const DateTime& t2) + { + if (t1.ticks < t2.ticks) + return -1; + else if (t1.ticks > t2.ticks) + return 1; + else + return 0; + } + + static int DaysInMonth (int year, int month) + { + const int* days ; + + //removed error handling + //if (month < 1 || month >12)throw new ArgumentOutOfRangeException (); + //if (year < 1 || year > 9999)throw new ArgumentOutOfRangeException (); + + days = (IsLeapYear(year) ? daysmonthleap : daysmonth); + return days[month]; + } + static bool IsLeapYear (int year) + { + //removed error handling + /* if (year < 1 || year > 9999) + throw new ArgumentOutOfRangeException ();*/ + return ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ; + } + + TimeSpan Subtract (const DateTime& value) const + { + return TimeSpan (ticks.get_Ticks()) - value.ticks; + } + + DateTime Subtract(const TimeSpan& value) const + { + TimeSpan newticks; + + newticks = (TimeSpan (ticks.get_Ticks())) - value; + DateTime ret = DateTime (true,newticks); + return ret; + } + + DateTime operator +(const TimeSpan& t) const + { + return DateTime (true, ticks + t); + } + + bool operator ==(const DateTime& d2) const + { + return (ticks == d2.ticks); + } + + bool operator >(const DateTime& t2) const + { + return (ticks > t2.ticks); + } + + bool operator >=(const DateTime &t2) const + { + return (ticks >= t2.ticks); + } + + bool operator !=(const DateTime& d2) const + { + return (ticks != d2.ticks); + } + + bool operator <(const DateTime& t2) const + { + return (ticks < t2.ticks ); + } + + bool operator <=(const DateTime& t2) const + { + return (ticks <= t2.ticks); + } + + TimeSpan operator -(const DateTime& d2) const + { + return TimeSpan((ticks - d2.ticks).get_Ticks()); + } + + DateTime operator -(const TimeSpan& t) const + { + return DateTime (true, ticks - t); + } + + //try to have a canonical format here. this was comment was typed at 2010-oct-04 02:16:44:000 + + std::string ToString() const + { + char tmp[32]; + sprintf(tmp,"%04d-%s-%02d %02d:%02d:%02d:%03d",get_Year(),monthnames[get_Month()],get_Day(),get_Hour(),get_Minute(),get_Second(),get_Millisecond()); + return tmp; + } + + static bool TryParse(const char* str, DateTime& out) + { + int year,mon=-1,day,hour,min,sec,ms; + char strmon[4]; + int done = sscanf(str,"%04d-%3s-%02d %02d:%02d:%02d:%03d",&year,strmon,&day,&hour,&min,&sec,&ms); + if(done != 7) return false; + for(int i=1;i<12;i++) + if(!strncasecmp(monthnames[i],strmon,3)) + { + mon=i; + break; + } + if(mon==-1) return false; + out = DateTime(year,mon,day,hour,min,sec); + return true; + } + + static DateTime Parse(const char* str) + { + DateTime ret; + TryParse(str,ret); + return ret; + } + +}; + + +#endif //_DATETIME_H_ diff --git a/desmume/src/utils/mkgmtime.cpp b/desmume/src/utils/mkgmtime.cpp deleted file mode 100644 index 6a8ccd019..000000000 --- a/desmume/src/utils/mkgmtime.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* utils/mkgmtime.cpp - - Copyright (C) 2010 DeSmuME team - - This file is part of DeSmuME - - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -//Taken from newlib 1.18.0 which is licensed under GPL 2 and modified for desmume - -/* - * mktime.c - * Original Author: G. Haley - * - * Converts the broken-down time, expressed as local time, in the structure - * pointed to by tim_p into a calendar time value. The original values of the - * tm_wday and tm_yday fields of the structure are ignored, and the original - * values of the other fields have no restrictions. On successful completion - * the fields of the structure are set to represent the specified calendar - * time. Returns the specified calendar time. If the calendar time can not be - * represented, returns the value (time_t) -1. - * - * Modifications: Fixed tm_isdst usage - 27 August 2008 Craig Howland. - */ - -#include -#include -#include "mkgmtime.h" - -#define _SEC_IN_MINUTE 60L -#define _SEC_IN_HOUR 3600L -#define _SEC_IN_DAY 86400L - -static const int DAYS_IN_MONTH[12] = -{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - -#define _DAYS_IN_MONTH(x) ((x == 1) ? days_in_feb : DAYS_IN_MONTH[x]) - -static const int _DAYS_BEFORE_MONTH[12] = -{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - -#define _ISLEAP(y) (((y) % 4) == 0 && (((y) % 100) != 0 || (((y)+1900) % 400) == 0)) -#define _DAYS_IN_YEAR(year) (_ISLEAP(year) ? 366 : 365) - -static void validate_structure(tm *tim_p) -{ - div_t res; - int days_in_feb = 28; - - /* calculate time & date to account for out of range values */ - if (tim_p->tm_sec < 0 || tim_p->tm_sec > 59) - { - res = div (tim_p->tm_sec, 60); - tim_p->tm_min += res.quot; - if ((tim_p->tm_sec = res.rem) < 0) - { - tim_p->tm_sec += 60; - --tim_p->tm_min; - } - } - - if (tim_p->tm_min < 0 || tim_p->tm_min > 59) - { - res = div (tim_p->tm_min, 60); - tim_p->tm_hour += res.quot; - if ((tim_p->tm_min = res.rem) < 0) - { - tim_p->tm_min += 60; - --tim_p->tm_hour; - } - } - - if (tim_p->tm_hour < 0 || tim_p->tm_hour > 23) - { - res = div (tim_p->tm_hour, 24); - tim_p->tm_mday += res.quot; - if ((tim_p->tm_hour = res.rem) < 0) - { - tim_p->tm_hour += 24; - --tim_p->tm_mday; - } - } - - if (tim_p->tm_mon > 11) - { - res = div (tim_p->tm_mon, 12); - tim_p->tm_year += res.quot; - if ((tim_p->tm_mon = res.rem) < 0) - { - tim_p->tm_mon += 12; - --tim_p->tm_year; - } - } - - if (_DAYS_IN_YEAR (tim_p->tm_year) == 366) - days_in_feb = 29; - - if (tim_p->tm_mday <= 0) - { - while (tim_p->tm_mday <= 0) - { - if (--tim_p->tm_mon == -1) - { - tim_p->tm_year--; - tim_p->tm_mon = 11; - days_in_feb = - ((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ? - 29 : 28); - } - tim_p->tm_mday += _DAYS_IN_MONTH (tim_p->tm_mon); - } - } - else - { - while (tim_p->tm_mday > _DAYS_IN_MONTH (tim_p->tm_mon)) - { - tim_p->tm_mday -= _DAYS_IN_MONTH (tim_p->tm_mon); - if (++tim_p->tm_mon == 12) - { - tim_p->tm_year++; - tim_p->tm_mon = 0; - days_in_feb = - ((_DAYS_IN_YEAR (tim_p->tm_year) == 366) ? - 29 : 28); - } - } - } -} - -time_t mkgmtime(tm *tim_p) -{ - time_t tim = 0; - long days = 0; - int year, isdst, tm_isdst; - - /* validate structure */ - validate_structure (tim_p); - - /* compute hours, minutes, seconds */ - tim += tim_p->tm_sec + (tim_p->tm_min * _SEC_IN_MINUTE) + - (tim_p->tm_hour * _SEC_IN_HOUR); - - /* compute days in year */ - days += tim_p->tm_mday - 1; - days += _DAYS_BEFORE_MONTH[tim_p->tm_mon]; - if (tim_p->tm_mon > 1 && _DAYS_IN_YEAR (tim_p->tm_year) == 366) - days++; - - /* compute day of the year */ - tim_p->tm_yday = days; - - if (tim_p->tm_year > 10000 - || tim_p->tm_year < -10000) - { - return (time_t) -1; - } - - /* compute days in other years */ - if (tim_p->tm_year > 70) - { - for (year = 70; year < tim_p->tm_year; year++) - days += _DAYS_IN_YEAR (year); - } - else if (tim_p->tm_year < 70) - { - for (year = 69; year > tim_p->tm_year; year--) - days -= _DAYS_IN_YEAR (year); - days -= _DAYS_IN_YEAR (year); - } - - /* compute day of the week */ - if ((tim_p->tm_wday = (days + 4) % 7) < 0) - tim_p->tm_wday += 7; - - /* compute total seconds */ - tim += (days * _SEC_IN_DAY); - - /* Convert user positive into 1 */ - tm_isdst = tim_p->tm_isdst > 0 ? 1 : tim_p->tm_isdst; - isdst = tm_isdst; - - //screw this! - - // if (_daylight) - // { - // int y = tim_p->tm_year + YEAR_BASE; - // if (y == tz->__tzyear || __tzcalc_limits (y)) - //{ - // /* calculate start of dst in dst local time and - // start of std in both std local time and dst local time */ - // time_t startdst_dst = tz->__tzrule[0].change - // - (time_t) tz->__tzrule[1].offset; - // time_t startstd_dst = tz->__tzrule[1].change - // - (time_t) tz->__tzrule[1].offset; - // time_t startstd_std = tz->__tzrule[1].change - // - (time_t) tz->__tzrule[0].offset; - // /* if the time is in the overlap between dst and std local times */ - // if (tim >= startstd_std && tim < startstd_dst) - // ; /* we let user decide or leave as -1 */ - // else - // { - // isdst = (tz->__tznorth - // ? (tim >= startdst_dst && tim < startstd_std) - // : (tim >= startdst_dst || tim < startstd_std)); - // /* if user committed and was wrong, perform correction, but not - // * if the user has given a negative value (which - // * asks mktime() to determine if DST is in effect or not) */ - // if (tm_isdst >= 0 && (isdst ^ tm_isdst) == 1) - // { - // /* we either subtract or add the difference between - // time zone offsets, depending on which way the user got it - // wrong. The diff is typically one hour, or 3600 seconds, - // and should fit in a 16-bit int, even though offset - // is a long to accomodate 12 hours. */ - // int diff = (int) (tz->__tzrule[0].offset - // - tz->__tzrule[1].offset); - // if (!isdst) - // diff = -diff; - // tim_p->tm_sec += diff; - // validate_structure (tim_p); - // tim += diff; /* we also need to correct our current time calculation */ - // } - // } - //} - // } - - //screw this also - /* add appropriate offset to put time in gmt format */ - //if (isdst == 1) - // tim += (time_t) tz->__tzrule[1].offset; - //else /* otherwise assume std time */ - // tim += (time_t) tz->__tzrule[0].offset; - - //and screw this too - /* reset isdst flag to what we have calculated */ - tim_p->tm_isdst = isdst; - - return tim; -} diff --git a/desmume/src/utils/mkgmtime.h b/desmume/src/utils/mkgmtime.h deleted file mode 100644 index bf211987d..000000000 --- a/desmume/src/utils/mkgmtime.h +++ /dev/null @@ -1,28 +0,0 @@ -/* utils/mkgmtime.h - - Copyright (C) 2010 DeSmuME team - - This file is part of DeSmuME - - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _MKGMTIME_H_ -#define _MKGMTIME_H_ - -#include -time_t mkgmtime(tm *tim_p); - -#endif //_MKGMTIME_H_ diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index 5d31ded47..0ccbea01b 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -1359,6 +1359,14 @@ RelativePath="..\utils\ConvertUTF.h" > + + + + diff --git a/desmume/src/windows/DeSmuME_2008.vcproj b/desmume/src/windows/DeSmuME_2008.vcproj index 90eada807..b08bba9b1 100644 --- a/desmume/src/windows/DeSmuME_2008.vcproj +++ b/desmume/src/windows/DeSmuME_2008.vcproj @@ -1058,6 +1058,14 @@ RelativePath="..\utils\ConvertUTF.h" > + + + + @@ -1078,14 +1086,6 @@ RelativePath="..\utils\md5.h" > - - - - diff --git a/desmume/src/windows/DeSmuME_2010.vcxproj b/desmume/src/windows/DeSmuME_2010.vcxproj index 0e2b0411d..eafc6803f 100644 --- a/desmume/src/windows/DeSmuME_2010.vcxproj +++ b/desmume/src/windows/DeSmuME_2010.vcxproj @@ -470,8 +470,8 @@ + - @@ -594,7 +594,7 @@ - + diff --git a/desmume/src/windows/DeSmuME_2010.vcxproj.filters b/desmume/src/windows/DeSmuME_2010.vcxproj.filters index d4816aa7c..9c23ef31c 100644 --- a/desmume/src/windows/DeSmuME_2010.vcxproj.filters +++ b/desmume/src/windows/DeSmuME_2010.vcxproj.filters @@ -378,9 +378,6 @@ Windows\tools - - Core\utils - Core\addons @@ -399,6 +396,9 @@ Core + + Core\utils + @@ -725,9 +725,6 @@ Windows\tools - - Core\utils - @@ -735,6 +732,9 @@ Core + + Core\utils + diff --git a/desmume/src/windows/replay.cpp b/desmume/src/windows/replay.cpp index d518cda6a..d9d1fd097 100644 --- a/desmume/src/windows/replay.cpp +++ b/desmume/src/windows/replay.cpp @@ -1,21 +1,17 @@ -/* windows/replay.cpp - Copyright (C) 2008-2010 DeSmuME team +/* Copyright (C) 2008-2010 DeSmuME team - This file is part of DeSmuME + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + You should have received a copy of the GNU General Public License + along with the this software. If not, see . */ #include "types.h" @@ -32,7 +28,6 @@ #include "movie.h" #include "rtc.h" #include "utils/xstring.h" -#include "utils/mkgmtime.h" bool replayreadonly=1; @@ -262,17 +257,16 @@ static INT_PTR CALLBACK RecordDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, CheckDlgButton(hwndDlg, IDC_START_FROM_SRAM, ((flag == 1) ? BST_CHECKED : BST_UNCHECKED)); SetFocus(GetDlgItem(hwndDlg, IDC_EDIT_FILENAME)); - time_t timer = FCEUI_MovieGetRTCDefault(); - struct tm *t = gmtime(&timer); + DateTime t = FCEUI_MovieGetRTCDefault(); ZeroMemory(&systime, sizeof(SYSTEMTIME)); - systime.wYear = t->tm_year + 1900; - systime.wMonth = t->tm_mon + 1; - systime.wDay = t->tm_mday; - systime.wDayOfWeek = t->tm_wday; - systime.wHour = t->tm_hour; - systime.wMinute = t->tm_min; - systime.wSecond = t->tm_sec; - systime.wMilliseconds = 0; + systime.wYear = t.get_Year(); + systime.wMonth = t.get_Month(); + systime.wDay = t.get_Day(); + systime.wDayOfWeek = t.get_DayOfWeek(); + systime.wHour = t.get_Hour(); + systime.wMinute = t.get_Minute(); + systime.wSecond = t.get_Second(); + systime.wMilliseconds = t.get_Millisecond(); DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DTP_DATE), GDT_VALID, &systime); DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DTP_TIME), GDT_VALID, &systime); @@ -304,20 +298,18 @@ static INT_PTR CALLBACK RecordDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, std::string sramfname = GetDlgItemText(hwndDlg,IDC_EDIT_SRAMFILENAME); if (fname.length()) { - time_t rtcstart; struct tm t; DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DTP_DATE), &systime); - t.tm_year = systime.wYear - 1900; - t.tm_mon = systime.wMonth - 1; + t.tm_year = systime.wYear; + t.tm_mon = systime.wMonth; t.tm_mday = systime.wDay; t.tm_wday = systime.wDayOfWeek; DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DTP_TIME), &systime); t.tm_hour = systime.wHour; t.tm_min = systime.wMinute; t.tm_sec = systime.wSecond; - t.tm_isdst= -1; - rtcstart = mkgmtime(&t); + DateTime rtcstart(t.tm_year,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec); FCEUI_SaveMovie(fname.c_str(), author, flag, sramfname, rtcstart); EndDialog(hwndDlg, 0);