3DS: Get core library building on 3DS

This commit is contained in:
Jeffrey Pfau 2014-12-08 16:04:02 -08:00
parent eb2315cdd8
commit b2a4780b17
2 changed files with 25 additions and 19 deletions

View File

@ -106,6 +106,9 @@ if(WIN32)
list(APPEND OS_LIB ws2_32)
file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
source_group("Windows-specific code" FILES ${OS_SRC})
elseif(3DS)
add_definitions(-D__3DS)
list(APPEND OS_LIB ctru)
else()
add_definitions(-DUSE_PTHREADS)
list(APPEND OS_LIB pthread)

View File

@ -10,13 +10,15 @@
#include <fcntl.h>
#include <dirent.h>
#ifndef _WIN32
#include <sys/mman.h>
#define PATH_SEP '/'
#else
#ifdef _WIN32
#include <io.h>
#include <windows.h>
#define PATH_SEP '\\'
#elif defined(__3DS)
#define PATH_SEP '/'
#else
#include <sys/mman.h>
#define PATH_SEP '/'
#endif
struct VFileFD {
@ -114,21 +116,7 @@ ssize_t _vfdWrite(struct VFile* vf, const void* buffer, size_t size) {
return write(vfd->fd, buffer, size);
}
#ifndef _WIN32
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
struct VFileFD* vfd = (struct VFileFD*) vf;
int mmapFlags = MAP_PRIVATE;
if (flags & MAP_WRITE) {
mmapFlags = MAP_SHARED;
}
return mmap(0, size, PROT_READ | PROT_WRITE, mmapFlags, vfd->fd, 0);
}
static void _vfdUnmap(struct VFile* vf, void* memory, size_t size) {
UNUSED(vf);
munmap(memory, size);
}
#else
#ifdef _WIN32
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
struct VFileFD* vfd = (struct VFileFD*) vf;
int createFlags = PAGE_WRITECOPY;
@ -154,6 +142,21 @@ static void _vfdUnmap(struct VFile* vf, void* memory, size_t size) {
CloseHandle(vfd->hMap);
vfd->hMap = 0;
}
#elif defined(__3DS)
#else
static void* _vfdMap(struct VFile* vf, size_t size, int flags) {
struct VFileFD* vfd = (struct VFileFD*) vf;
int mmapFlags = MAP_PRIVATE;
if (flags & MAP_WRITE) {
mmapFlags = MAP_SHARED;
}
return mmap(0, size, PROT_READ | PROT_WRITE, mmapFlags, vfd->fd, 0);
}
static void _vfdUnmap(struct VFile* vf, void* memory, size_t size) {
UNUSED(vf);
munmap(memory, size);
}
#endif
static void _vfdTruncate(struct VFile* vf, size_t size) {