Skip to content

Commit 2ba9f97

Browse files
authored
Merge branch 'xenia-project:master' into master
2 parents cec5fcf + f6b5424 commit 2ba9f97

File tree

5 files changed

+65
-24
lines changed

5 files changed

+65
-24
lines changed

src/xenia/vfs/devices/stfs_container_device.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,9 @@
1717
#include "xenia/base/math.h"
1818
#include "xenia/vfs/devices/stfs_container_entry.h"
1919

20-
#if XE_PLATFORM_WIN32
21-
#include "xenia/base/platform_win.h"
22-
#define timegm _mkgmtime
23-
#endif
24-
2520
namespace xe {
2621
namespace vfs {
2722

28-
// Convert FAT timestamp to 100-nanosecond intervals since January 1, 1601 (UTC)
29-
uint64_t decode_fat_timestamp(uint32_t date, uint32_t time) {
30-
struct tm tm = {0};
31-
// 80 is the difference between 1980 (FAT) and 1900 (tm);
32-
tm.tm_year = ((0xFE00 & date) >> 9) + 80;
33-
tm.tm_mon = (0x01E0 & date) >> 5;
34-
tm.tm_mday = (0x001F & date) >> 0;
35-
tm.tm_hour = (0xF800 & time) >> 11;
36-
tm.tm_min = (0x07E0 & time) >> 5;
37-
tm.tm_sec = (0x001F & time) << 1; // the value stored in 2-seconds intervals
38-
tm.tm_isdst = 0;
39-
time_t timet = timegm(&tm);
40-
if (timet == -1) {
41-
return 0;
42-
}
43-
// 11644473600LL is a difference between 1970 and 1601
44-
return (timet + 11644473600LL) * 10000000;
45-
}
46-
4723
StfsContainerDevice::StfsContainerDevice(const std::string_view mount_path,
4824
const std::filesystem::path& host_path)
4925
: Device(mount_path),

src/xenia/vfs/devices/stfs_xbox.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,40 @@
1010
#ifndef XENIA_VFS_DEVICES_STFS_XBOX_H_
1111
#define XENIA_VFS_DEVICES_STFS_XBOX_H_
1212

13+
#include <time.h>
14+
15+
#include "xenia/xbox.h"
1316
#include "xenia/base/string_util.h"
1417
#include "xenia/kernel/util/xex2_info.h"
1518

1619
namespace xe {
1720
namespace vfs {
1821

22+
// Convert FAT timestamp to 100-nanosecond intervals since January 1, 1601 (UTC)
23+
inline uint64_t decode_fat_timestamp(const uint32_t date, const uint32_t time) {
24+
struct tm tm = {0};
25+
// 80 is the difference between 1980 (FAT) and 1900 (tm);
26+
tm.tm_year = ((0xFE00 & date) >> 9) + 80;
27+
tm.tm_mon = ((0x01E0 & date) >> 5) - 1;
28+
tm.tm_mday = (0x001F & date) >> 0;
29+
tm.tm_hour = (0xF800 & time) >> 11;
30+
tm.tm_min = (0x07E0 & time) >> 5;
31+
tm.tm_sec = (0x001F & time) << 1; // the value stored in 2-seconds intervals
32+
tm.tm_isdst = 0;
33+
34+
#if XE_PLATFORM_WIN32
35+
time_t timet = _mkgmtime(&tm);
36+
#else
37+
time_t timet = timegm(&tm);
38+
#endif
39+
40+
if (timet == -1) {
41+
return 0;
42+
}
43+
// 11644473600LL is a difference between 1970 and 1601
44+
return (timet + 11644473600LL) * 10000000;
45+
}
46+
1947
// Structs used for interchange between Xenia and actual Xbox360 kernel/XAM
2048

2149
inline uint32_t load_uint24_be(const uint8_t* p) {

src/xenia/vfs/premake5.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ project("xenia-vfs-dump")
3232
resincludedirs({
3333
project_root,
3434
})
35+
include("testing")
3536

src/xenia/vfs/testing/premake5.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
project_root = "../../../.."
2+
include(project_root.."/tools/build")
3+
4+
test_suite("xenia-vfs-tests", project_root, ".", {
5+
links = {
6+
"xenia-vfs",
7+
},
8+
})

src/xenia/vfs/testing/vfs_test.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
******************************************************************************
3+
* Xenia : Xbox 360 Emulator Research Project *
4+
******************************************************************************
5+
* Copyright 2023 Ben Vanik. All rights reserved. *
6+
* Released under the BSD license - see LICENSE in the root for more details. *
7+
******************************************************************************
8+
*/
9+
10+
#include "xenia/vfs/devices/stfs_xbox.h"
11+
12+
#include "third_party/catch/include/catch.hpp"
13+
14+
namespace xe::vfs::test {
15+
16+
TEST_CASE("STFS Decode date and time", "[stfs_decode]") {
17+
SECTION("10 June 2022 19:46:00 UTC - Decode") {
18+
const uint16_t date = 0x54CA;
19+
const uint16_t time = 0x9DBD;
20+
const uint64_t result = 132993639580000000;
21+
22+
const uint64_t timestamp = decode_fat_timestamp(date, time);
23+
24+
REQUIRE(timestamp == result);
25+
}
26+
}
27+
28+
} // namespace xe::vfs::test

0 commit comments

Comments
 (0)