replaced TIME_OFFSET constant by portable TimeToMacTime() function

This commit is contained in:
cebix 2001-07-06 17:36:09 +00:00
parent 791baa8f6f
commit e7a13421df
10 changed files with 54 additions and 50 deletions

View File

@ -5,6 +5,8 @@ V1.0 (snapshot) - <date>
like a 68882/68040 FPU, eliminating the need for 68060 FPU patches
- added support for platform-independant mutexes, used by adb.cpp for
thread-safe mouse handling
- the TIME_OFFSET constant has been replaced by a (portable) function
TimeToMacTime(); file dates in ExtFS should now be correct
- Unix: windowed display mode supports different resolutions and color
depth, which can be switched on-the-fly
- Unix: Ctrl-F5 grabs mouse in windowed mode (enhanced compatibility

View File

@ -61,9 +61,6 @@ typedef unsigned long long loff_t;
// Time data type for Time Manager emulation
typedef struct timeval tm_time_t;
// Offset Mac->AmigaOS time in seconds
#define TIME_OFFSET 0x8b31ef80
// Endianess conversion (not needed)
#define ntohs(x) (x)
#define ntohl(x) (x)

View File

@ -51,10 +51,9 @@ void Microseconds(uint32 &hi, uint32 &lo)
uint32 TimerDateTime(void)
{
ULONG secs;
ULONG mics;
ULONG secs, mics;
CurrentTime(&secs, &mics);
return secs + TIME_OFFSET;
return secs + 0x8b31ef80;
}

View File

@ -55,9 +55,6 @@
// Time data type for Time Manager emulation
typedef bigtime_t tm_time_t;
// Offset Mac->BeOS time in seconds
#define TIME_OFFSET 0x7c25b080
// 64 bit file offsets
typedef off_t loff_t;

View File

@ -21,6 +21,7 @@
#include <KernelKit.h>
#include "sysdeps.h"
#include "macos_util.h"
#include "timer.h"
#define DEBUG 0
@ -46,12 +47,7 @@ void Microseconds(uint32 &hi, uint32 &lo)
uint32 TimerDateTime(void)
{
time_t utc_now = time(NULL);
long tz = timezone;
time_t local_now = utc_now - tz;
if (daylight)
local_now += 3600;
return (uint32)local_now + TIME_OFFSET;
return TimeToMacTime(time(NULL));
}

View File

@ -155,9 +155,6 @@ typedef struct timespec tm_time_t;
typedef struct timeval tm_time_t;
#endif
/* Offset Mac->Unix time in seconds */
#define TIME_OFFSET 0x7c25b080
/* UAE CPU data types */
#define uae_s8 int8
#define uae_u8 uint8

View File

@ -19,6 +19,7 @@
*/
#include "sysdeps.h"
#include "macos_util.h"
#include "timer.h"
#define DEBUG 0
@ -57,15 +58,7 @@ void Microseconds(uint32 &hi, uint32 &lo)
uint32 TimerDateTime(void)
{
time_t utc_now = time(NULL);
#if defined(__linux__) || defined(__SVR4)
time_t local_now = utc_now - timezone;
#elif defined(__FreeBSD__) || defined(__NetBSD__)
time_t local_now = utc_now + localtime(&utc_now)->tm_gmtoff;
#else
time_t local_now = utc_now;
#endif
return (uint32)local_now + TIME_OFFSET;
return TimeToMacTime(time(NULL));
}

View File

@ -976,11 +976,11 @@ static int16 fs_volume_mount(uint32 pb)
// Init VCB
WriteMacInt16(vcb + vcbSigWord, 0x4244);
#if defined(__BEOS__) || defined(WIN32)
WriteMacInt32(vcb + vcbCrDate, root_stat.st_crtime + TIME_OFFSET);
WriteMacInt32(vcb + vcbCrDate, TimeToMacTime(root_stat.st_crtime));
#else
WriteMacInt32(vcb + vcbCrDate, 0);
#endif
WriteMacInt32(vcb + vcbLsMod, root_stat.st_mtime + TIME_OFFSET);
WriteMacInt32(vcb + vcbLsMod, TimeToMacTime(root_stat.st_mtime));
WriteMacInt32(vcb + vcbVolBkUp, 0);
WriteMacInt16(vcb + vcbNmFls, 1); //!!
WriteMacInt16(vcb + vcbNmRtDirs, 1); //!!
@ -1039,11 +1039,11 @@ static int16 fs_get_vol_info(uint32 pb, bool hfs)
if (ReadMacInt32(pb + ioNamePtr))
pstrcpy((char *)Mac2HostAddr(ReadMacInt32(pb + ioNamePtr)), VOLUME_NAME);
#if defined(__BEOS__) || defined(WIN32)
WriteMacInt32(pb + ioVCrDate, root_stat.st_crtime + TIME_OFFSET);
WriteMacInt32(pb + ioVCrDate, TimeToMacTime(root_stat.st_crtime));
#else
WriteMacInt32(pb + ioVCrDate, 0);
#endif
WriteMacInt32(pb + ioVLsMod, root_stat.st_mtime + TIME_OFFSET);
WriteMacInt32(pb + ioVLsMod, TimeToMacTime(root_stat.st_mtime));
WriteMacInt16(pb + ioVAtrb, 0);
WriteMacInt16(pb + ioVNmFls, 1); //!!
WriteMacInt16(pb + ioVBitMap, 0);
@ -1231,11 +1231,11 @@ read_next_de:
WriteMacInt32(pb + ioDirID, fs_item->id);
#if defined(__BEOS__) || defined(WIN32)
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
#else
WriteMacInt32(pb + ioFlCrDat, 0);
#endif
WriteMacInt32(pb + ioFlMdDat, st.st_mtime + TIME_OFFSET);
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(st.st_mtime));
get_finfo(full_path, pb + ioFlFndrInfo, hfs ? pb + ioFlXFndrInfo : 0, false);
@ -1353,7 +1353,7 @@ read_next_de:
WriteMacInt32(pb + ioDirID, fs_item->id);
WriteMacInt32(pb + ioFlParID, fs_item->parent_id);
#if defined(__BEOS__) || defined(WIN32)
WriteMacInt32(pb + ioFlCrDat, st.st_crtime + TIME_OFFSET);
WriteMacInt32(pb + ioFlCrDat, TimeToMacTime(st.st_crtime));
#else
WriteMacInt32(pb + ioFlCrDat, 0);
#endif
@ -1363,7 +1363,7 @@ read_next_de:
fs_item->mtime = mtime;
cached = false;
}
WriteMacInt32(pb + ioFlMdDat, mtime + TIME_OFFSET);
WriteMacInt32(pb + ioFlMdDat, TimeToMacTime(mtime));
WriteMacInt32(pb + ioFlBkDat, 0);
get_finfo(full_path, pb + ioFlFndrInfo, pb + ioFlXFndrInfo, S_ISDIR(st.st_mode));

View File

@ -263,7 +263,8 @@ extern void EnqueueMac(uint32 elem, uint32 list); // Enqueue QElem in list
extern int FindFreeDriveNumber(int num); // Find first free drive number, starting at "num"
extern void MountVolume(void *fh); // Mount volume with given file handle (see sys.h)
extern void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size); // Calculate disk image file layout given file size and first 256 data bytes
extern uint32 DebugUtil(uint32 Selector); // DebugUtil() Replacement
extern uint32 DebugUtil(uint32 Selector); // DebugUtil() Replacement
extern uint32 TimeToMacTime(time_t t); // Convert time_t value to MacOS time
// Construct four-character-code
#define FOURCC(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d))

View File

@ -106,19 +106,41 @@ void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_s
uint32 DebugUtil(uint32 Selector)
{
switch (Selector)
{
case duDebuggerGetMax:
return 3;
case duDebuggerEnter:
return 0;
case duDebuggerExit:
return 0;
case duDebuggerPoll:
ADBInterrupt();
return 0;
default:
return (uint32) paramErr;
}
switch (Selector) {
case duDebuggerGetMax:
return 3;
case duDebuggerEnter:
return 0;
case duDebuggerExit:
return 0;
case duDebuggerPoll:
ADBInterrupt();
return 0;
default:
return (uint32) paramErr;
}
}
/*
* Convert time_t value to MacOS time (seconds since 1.1.1904)
*/
uint32 TimeToMacTime(time_t t)
{
// This code is taken from glibc 2.2
// Convert to number of seconds elapsed since 1-Jan-1904
struct tm *local = localtime(&t);
const int TM_EPOCH_YEAR = 1900;
const int MAC_EPOCH_YEAR = 1904;
int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3);
int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3);
int a100 = a4 / 25 - (a4 % 25 < 0);
int b100 = b4 / 25 - (b4 % 25 < 0);
int a400 = a100 >> 2;
int b400 = b100 >> 2;
int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
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));
}