mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-11-29 14:49:44 +00:00
Add prefs item "dayofs" for finer-grained time offset
This commit is contained in:
parent
e676dbf839
commit
64e408ced6
@ -136,6 +136,7 @@ uint32 TimeToMacTime(time_t t)
|
|||||||
struct tm *local = localtime(&t);
|
struct tm *local = localtime(&t);
|
||||||
const int TM_EPOCH_YEAR = 1900;
|
const int TM_EPOCH_YEAR = 1900;
|
||||||
const int MAC_EPOCH_YEAR = 1904;
|
const int MAC_EPOCH_YEAR = 1904;
|
||||||
|
// Clip year and day offsets to prevent dates earlier than 1-Jan-1904
|
||||||
local->tm_year = std::max(MAC_EPOCH_YEAR - TM_EPOCH_YEAR, local->tm_year - PrefsFindInt32("yearofs"));
|
local->tm_year = std::max(MAC_EPOCH_YEAR - TM_EPOCH_YEAR, local->tm_year - PrefsFindInt32("yearofs"));
|
||||||
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
|
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
|
||||||
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
|
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
|
||||||
@ -145,7 +146,10 @@ uint32 TimeToMacTime(time_t t)
|
|||||||
int b400 = b100 >> 2;
|
int b400 = b100 >> 2;
|
||||||
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
|
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
|
||||||
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
|
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
|
||||||
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days));
|
int32 dayofs = PrefsFindInt32("dayofs");
|
||||||
|
if(dayofs > 0 && dayofs > days)
|
||||||
|
dayofs = days;
|
||||||
|
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * (days - dayofs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -76,6 +76,7 @@ prefs_desc common_prefs_items[] = {
|
|||||||
{"scale_nearest",TYPE_BOOLEAN,false,"nearest neighbor scaling"},
|
{"scale_nearest",TYPE_BOOLEAN,false,"nearest neighbor scaling"},
|
||||||
{"scale_integer",TYPE_BOOLEAN,false,"integer scaling"},
|
{"scale_integer",TYPE_BOOLEAN,false,"integer scaling"},
|
||||||
{"yearofs", TYPE_INT32, 0, "year offset"},
|
{"yearofs", TYPE_INT32, 0, "year offset"},
|
||||||
|
{"dayofs", TYPE_INT32, 0, "day offset"},
|
||||||
{NULL, TYPE_END, false, NULL} // End of list
|
{NULL, TYPE_END, false, NULL} // End of list
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -335,6 +335,7 @@ uint32 TimeToMacTime(time_t t)
|
|||||||
#endif
|
#endif
|
||||||
const int TM_EPOCH_YEAR = 1900;
|
const int TM_EPOCH_YEAR = 1900;
|
||||||
const int MAC_EPOCH_YEAR = 1904;
|
const int MAC_EPOCH_YEAR = 1904;
|
||||||
|
// Clip year and day offsets to prevent dates earlier than 1-Jan-1904
|
||||||
local->tm_year = std::max(MAC_EPOCH_YEAR - TM_EPOCH_YEAR, local->tm_year - PrefsFindInt32("yearofs"));
|
local->tm_year = std::max(MAC_EPOCH_YEAR - TM_EPOCH_YEAR, local->tm_year - PrefsFindInt32("yearofs"));
|
||||||
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
|
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
|
||||||
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
|
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
|
||||||
@ -344,7 +345,10 @@ uint32 TimeToMacTime(time_t t)
|
|||||||
int b400 = b100 >> 2;
|
int b400 = b100 >> 2;
|
||||||
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
|
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
|
||||||
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
|
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
|
||||||
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days));
|
int32 dayofs = PrefsFindInt32("dayofs");
|
||||||
|
if(dayofs > 0 && dayofs > days)
|
||||||
|
dayofs = days;
|
||||||
|
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * (days - dayofs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ prefs_desc common_prefs_items[] = {
|
|||||||
{"scale_integer",TYPE_BOOLEAN,false,"integer scaling"},
|
{"scale_integer",TYPE_BOOLEAN,false,"integer scaling"},
|
||||||
{"cpuclock", TYPE_INT32, 0, "CPU clock [MHz] of system info"},
|
{"cpuclock", TYPE_INT32, 0, "CPU clock [MHz] of system info"},
|
||||||
{"yearofs", TYPE_INT32, 0, "year offset"},
|
{"yearofs", TYPE_INT32, 0, "year offset"},
|
||||||
|
{"dayofs", TYPE_INT32, 0, "day offset"},
|
||||||
{NULL, TYPE_END, false, NULL} // End of list
|
{NULL, TYPE_END, false, NULL} // End of list
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user