Merge branch 'master' into great-refactor
Conflicts: libctru/include/3ds/services/hid.h libctru/include/3ds/services/irrst.h
This commit is contained in:
commit
b481e6a446
6
libctru/include/3ds/mappable.h
Normal file
6
libctru/include/3ds/mappable.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Functions for allocating/deallocating mappable memory
|
||||||
|
void* mappableAlloc(size_t size); // returns a page-aligned address
|
||||||
|
void mappableFree(void* mem);
|
||||||
|
u32 mappableSpaceFree(void); // get free mappable space in bytes
|
@ -2,7 +2,6 @@
|
|||||||
#include <3ds/types.h>
|
#include <3ds/types.h>
|
||||||
|
|
||||||
#define CSND_NUM_CHANNELS 32
|
#define CSND_NUM_CHANNELS 32
|
||||||
#define CSND_SHAREDMEM_DEFAULT 0x10004000
|
|
||||||
|
|
||||||
#define CSND_TIMER(n) (0x3FEC3FC / ((u32)(n)))
|
#define CSND_TIMER(n) (0x3FEC3FC / ((u32)(n)))
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
//See also: http://3dbrew.org/wiki/HID_Services http://3dbrew.org/wiki/HID_Shared_Memory
|
//See also: http://3dbrew.org/wiki/HID_Services http://3dbrew.org/wiki/HID_Shared_Memory
|
||||||
|
|
||||||
#define HID_SHAREDMEM_DEFAULT (0x10000000)
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
KEY_A = BIT(0),
|
KEY_A = BIT(0),
|
||||||
@ -75,7 +73,7 @@ typedef enum
|
|||||||
extern Handle hidMemHandle;
|
extern Handle hidMemHandle;
|
||||||
extern vu32* hidSharedMem;
|
extern vu32* hidSharedMem;
|
||||||
|
|
||||||
Result hidInit(u32* sharedMem);
|
Result hidInit(void);
|
||||||
void hidExit(void);
|
void hidExit(void);
|
||||||
|
|
||||||
void hidScanInput(void);
|
void hidScanInput(void);
|
||||||
|
@ -4,12 +4,10 @@
|
|||||||
|
|
||||||
#include "3ds/services/hid.h" // for circlePosition definition
|
#include "3ds/services/hid.h" // for circlePosition definition
|
||||||
|
|
||||||
#define IRRST_SHAREDMEM_DEFAULT (0x1000A000)
|
|
||||||
|
|
||||||
extern Handle irrstMemHandle;
|
extern Handle irrstMemHandle;
|
||||||
extern vu32* irrstSharedMem;
|
extern vu32* irrstSharedMem;
|
||||||
|
|
||||||
Result irrstInit(u32* sharedMem);
|
Result irrstInit(void);
|
||||||
void irrstExit(void);
|
void irrstExit(void);
|
||||||
|
|
||||||
void irrstScanInput(void);
|
void irrstScanInput(void);
|
||||||
|
61
libctru/source/allocator/mappable.cpp
Normal file
61
libctru/source/allocator/mappable.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <3ds/types.h>
|
||||||
|
#include <3ds/mappable.h>
|
||||||
|
#include <3ds/util/rbtree.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "mem_pool.h"
|
||||||
|
#include "addrmap.h"
|
||||||
|
|
||||||
|
static MemPool sMappablePool;
|
||||||
|
|
||||||
|
static bool mappableInit()
|
||||||
|
{
|
||||||
|
auto blk = MemBlock::Create((u8*)0x10000000, 0x04000000);
|
||||||
|
if (blk)
|
||||||
|
{
|
||||||
|
sMappablePool.AddBlock(blk);
|
||||||
|
rbtree_init(&sAddrMap, addrMapNodeComparator);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* mappableAlloc(size_t size)
|
||||||
|
{
|
||||||
|
// Initialize the pool if it is not ready
|
||||||
|
if (!sMappablePool.Ready() && !mappableInit())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// Allocate the chunk
|
||||||
|
MemChunk chunk;
|
||||||
|
if (!sMappablePool.Allocate(chunk, size, 12))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto node = newNode(chunk);
|
||||||
|
if (!node)
|
||||||
|
{
|
||||||
|
sMappablePool.Deallocate(chunk);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (rbtree_insert(&sAddrMap, &node->node));
|
||||||
|
return chunk.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mappableFree(void* mem)
|
||||||
|
{
|
||||||
|
auto node = getNode(mem);
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
// Free the chunk
|
||||||
|
sMappablePool.Deallocate(node->chunk);
|
||||||
|
|
||||||
|
// Free the node
|
||||||
|
delNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 mappableSpaceFree()
|
||||||
|
{
|
||||||
|
return sMappablePool.GetFreeSpace();
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
#include <3ds/gfx.h>
|
#include <3ds/gfx.h>
|
||||||
#include <3ds/svc.h>
|
#include <3ds/svc.h>
|
||||||
#include <3ds/linear.h>
|
#include <3ds/linear.h>
|
||||||
|
#include <3ds/mappable.h>
|
||||||
#include <3ds/vram.h>
|
#include <3ds/vram.h>
|
||||||
#include <3ds/gpu/gx.h>
|
#include <3ds/gpu/gx.h>
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomForm
|
|||||||
|
|
||||||
gspInit();
|
gspInit();
|
||||||
|
|
||||||
gfxSharedMemory=(u8*)0x10002000;
|
gfxSharedMemory=(u8*)mappableAlloc(0x1000);
|
||||||
|
|
||||||
GSPGPU_AcquireRight(0x0);
|
GSPGPU_AcquireRight(0x0);
|
||||||
|
|
||||||
@ -192,6 +193,12 @@ void gfxExit(void)
|
|||||||
GSPGPU_UnregisterInterruptRelayQueue();
|
GSPGPU_UnregisterInterruptRelayQueue();
|
||||||
|
|
||||||
svcCloseHandle(gspSharedMemHandle);
|
svcCloseHandle(gspSharedMemHandle);
|
||||||
|
if(gfxSharedMemory != NULL)
|
||||||
|
{
|
||||||
|
mappableFree(gfxSharedMemory);
|
||||||
|
gfxSharedMemory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
svcCloseHandle(gspEvent);
|
svcCloseHandle(gspEvent);
|
||||||
|
|
||||||
GSPGPU_ReleaseRight();
|
GSPGPU_ReleaseRight();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <3ds/types.h>
|
#include <3ds/types.h>
|
||||||
#include <3ds/svc.h>
|
#include <3ds/svc.h>
|
||||||
#include <3ds/srv.h>
|
#include <3ds/srv.h>
|
||||||
|
#include <3ds/mappable.h>
|
||||||
#include <3ds/os.h>
|
#include <3ds/os.h>
|
||||||
#include <3ds/services/csnd.h>
|
#include <3ds/services/csnd.h>
|
||||||
#include <3ds/ipc.h>
|
#include <3ds/ipc.h>
|
||||||
@ -119,7 +120,6 @@ Result CSND_Reset(void)
|
|||||||
Result csndInit(void)
|
Result csndInit(void)
|
||||||
{
|
{
|
||||||
Result ret=0;
|
Result ret=0;
|
||||||
csndSharedMem = (vu32*)CSND_SHAREDMEM_DEFAULT;
|
|
||||||
|
|
||||||
// TODO: proper error handling!
|
// TODO: proper error handling!
|
||||||
|
|
||||||
@ -134,17 +134,33 @@ Result csndInit(void)
|
|||||||
csndSharedMemSize = csndOffsets[3] + 0x3C; // Total size of the CSND shared memory
|
csndSharedMemSize = csndOffsets[3] + 0x3C; // Total size of the CSND shared memory
|
||||||
|
|
||||||
ret = CSND_Initialize();
|
ret = CSND_Initialize();
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) goto cleanup1;
|
||||||
|
|
||||||
|
csndSharedMem = (vu32*)mappableAlloc(csndSharedMemSize);
|
||||||
|
if(!csndSharedMem)
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup1;
|
||||||
|
}
|
||||||
|
|
||||||
ret = svcMapMemoryBlock(csndSharedMemBlock, (u32)csndSharedMem, 3, 0x10000000);
|
ret = svcMapMemoryBlock(csndSharedMemBlock, (u32)csndSharedMem, 3, 0x10000000);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) goto cleanup2;
|
||||||
|
|
||||||
memset((void*)csndSharedMem, 0, csndSharedMemSize);
|
memset((void*)csndSharedMem, 0, csndSharedMemSize);
|
||||||
|
|
||||||
ret = CSND_AcquireSoundChannels(&csndChannels);
|
ret = CSND_AcquireSoundChannels(&csndChannels);
|
||||||
if (ret != 0) return ret;
|
if (!ret) return 0;
|
||||||
|
|
||||||
return 0;
|
cleanup2:
|
||||||
|
svcCloseHandle(csndSharedMemBlock);
|
||||||
|
if(csndSharedMem != NULL)
|
||||||
|
{
|
||||||
|
mappableFree((void*) csndSharedMem);
|
||||||
|
csndSharedMem = NULL;
|
||||||
|
}
|
||||||
|
cleanup1:
|
||||||
|
svcCloseHandle(csndHandle);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result csndExit(void)
|
Result csndExit(void)
|
||||||
@ -162,6 +178,13 @@ Result csndExit(void)
|
|||||||
|
|
||||||
ret = CSND_Shutdown();
|
ret = CSND_Shutdown();
|
||||||
svcCloseHandle(csndHandle);
|
svcCloseHandle(csndHandle);
|
||||||
|
|
||||||
|
if(csndSharedMem != NULL)
|
||||||
|
{
|
||||||
|
mappableFree((void*) csndSharedMem);
|
||||||
|
csndSharedMem = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <3ds/types.h>
|
#include <3ds/types.h>
|
||||||
#include <3ds/svc.h>
|
#include <3ds/svc.h>
|
||||||
#include <3ds/srv.h>
|
#include <3ds/srv.h>
|
||||||
|
#include <3ds/mappable.h>
|
||||||
#include <3ds/services/apt.h>
|
#include <3ds/services/apt.h>
|
||||||
#include <3ds/services/hid.h>
|
#include <3ds/services/hid.h>
|
||||||
#include <3ds/services/irrst.h>
|
#include <3ds/services/irrst.h>
|
||||||
@ -26,30 +27,34 @@ static angularRate gRate;
|
|||||||
|
|
||||||
static bool hidInitialised;
|
static bool hidInitialised;
|
||||||
|
|
||||||
Result hidInit(u32* sharedMem)
|
Result hidInit(void)
|
||||||
{
|
{
|
||||||
u8 val=0;
|
u8 val=0;
|
||||||
Result ret=0;
|
Result ret=0;
|
||||||
|
|
||||||
if(hidInitialised) return ret;
|
if(hidInitialised) return ret;
|
||||||
|
|
||||||
if(!sharedMem)sharedMem=(u32*)HID_SHAREDMEM_DEFAULT;
|
|
||||||
|
|
||||||
// Request service.
|
// Request service.
|
||||||
if((ret=srvGetServiceHandle(&hidHandle, "hid:USER")) && (ret=srvGetServiceHandle(&hidHandle, "hid:SPVR")))return ret;
|
if((ret=srvGetServiceHandle(&hidHandle, "hid:USER")) && (ret=srvGetServiceHandle(&hidHandle, "hid:SPVR")))return ret;
|
||||||
|
|
||||||
// Get sharedmem handle.
|
// Get sharedmem handle.
|
||||||
if((ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;
|
if((ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;
|
||||||
|
|
||||||
// Map HID shared memory at addr "sharedMem".
|
// Map HID shared memory.
|
||||||
hidSharedMem=sharedMem;
|
hidSharedMem=(vu32*)mappableAlloc(0x2b0);
|
||||||
|
if(!hidSharedMem)
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup1;
|
||||||
|
}
|
||||||
|
|
||||||
if((ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
if((ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
||||||
|
|
||||||
APT_CheckNew3DS(&val);
|
APT_CheckNew3DS(&val);
|
||||||
|
|
||||||
if(val)
|
if(val)
|
||||||
{
|
{
|
||||||
ret = irrstInit(NULL);
|
ret = irrstInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset internal state.
|
// Reset internal state.
|
||||||
@ -59,6 +64,11 @@ Result hidInit(u32* sharedMem)
|
|||||||
|
|
||||||
cleanup2:
|
cleanup2:
|
||||||
svcCloseHandle(hidMemHandle);
|
svcCloseHandle(hidMemHandle);
|
||||||
|
if(hidSharedMem != NULL)
|
||||||
|
{
|
||||||
|
mappableFree((void*) hidSharedMem);
|
||||||
|
hidSharedMem = NULL;
|
||||||
|
}
|
||||||
cleanup1:
|
cleanup1:
|
||||||
svcCloseHandle(hidHandle);
|
svcCloseHandle(hidHandle);
|
||||||
return ret;
|
return ret;
|
||||||
@ -81,6 +91,12 @@ void hidExit(void)
|
|||||||
{
|
{
|
||||||
irrstExit();
|
irrstExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(hidSharedMem != NULL)
|
||||||
|
{
|
||||||
|
mappableFree((void*) hidSharedMem);
|
||||||
|
hidSharedMem = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
hidInitialised = false;
|
hidInitialised = false;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <3ds/types.h>
|
#include <3ds/types.h>
|
||||||
#include <3ds/svc.h>
|
#include <3ds/svc.h>
|
||||||
#include <3ds/srv.h>
|
#include <3ds/srv.h>
|
||||||
|
#include <3ds/mappable.h>
|
||||||
#include <3ds/services/irrst.h>
|
#include <3ds/services/irrst.h>
|
||||||
#include <3ds/ipc.h>
|
#include <3ds/ipc.h>
|
||||||
|
|
||||||
@ -22,11 +23,10 @@ static u32 kHeld;
|
|||||||
static circlePosition csPos;
|
static circlePosition csPos;
|
||||||
static bool irrstUsed = false;
|
static bool irrstUsed = false;
|
||||||
|
|
||||||
Result irrstInit(u32* sharedMem)
|
Result irrstInit(void)
|
||||||
{
|
{
|
||||||
if(irrstUsed)return 0;
|
if(irrstUsed)return 0;
|
||||||
|
|
||||||
if(!sharedMem)sharedMem=(u32*)IRRST_SHAREDMEM_DEFAULT;
|
|
||||||
Result ret=0;
|
Result ret=0;
|
||||||
|
|
||||||
// Request service.
|
// Request service.
|
||||||
@ -38,8 +38,14 @@ Result irrstInit(u32* sharedMem)
|
|||||||
// Initialize ir:rst
|
// Initialize ir:rst
|
||||||
if(__get_handle_from_list("ir:rst")==0)ret=IRRST_Initialize(10, 0);
|
if(__get_handle_from_list("ir:rst")==0)ret=IRRST_Initialize(10, 0);
|
||||||
|
|
||||||
// Map ir:rst shared memory at addr "sharedMem".
|
// Map ir:rst shared memory.
|
||||||
irrstSharedMem=sharedMem;
|
irrstSharedMem=(vu32*)mappableAlloc(0x98);
|
||||||
|
if(!irrstSharedMem)
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup1;
|
||||||
|
}
|
||||||
|
|
||||||
if((ret=svcMapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
if((ret=svcMapMemoryBlock(irrstMemHandle, (u32)irrstSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
|
||||||
|
|
||||||
// Reset internal state.
|
// Reset internal state.
|
||||||
@ -49,6 +55,11 @@ Result irrstInit(u32* sharedMem)
|
|||||||
|
|
||||||
cleanup2:
|
cleanup2:
|
||||||
svcCloseHandle(irrstMemHandle);
|
svcCloseHandle(irrstMemHandle);
|
||||||
|
if(irrstSharedMem != NULL)
|
||||||
|
{
|
||||||
|
mappableFree((void*) irrstSharedMem);
|
||||||
|
irrstSharedMem = NULL;
|
||||||
|
}
|
||||||
cleanup1:
|
cleanup1:
|
||||||
svcCloseHandle(irrstHandle);
|
svcCloseHandle(irrstHandle);
|
||||||
return ret;
|
return ret;
|
||||||
@ -65,6 +76,12 @@ void irrstExit(void)
|
|||||||
if(__get_handle_from_list("ir:rst")==0) IRRST_Shutdown();
|
if(__get_handle_from_list("ir:rst")==0) IRRST_Shutdown();
|
||||||
svcCloseHandle(irrstMemHandle);
|
svcCloseHandle(irrstMemHandle);
|
||||||
svcCloseHandle(irrstHandle);
|
svcCloseHandle(irrstHandle);
|
||||||
|
|
||||||
|
if(irrstSharedMem != NULL)
|
||||||
|
{
|
||||||
|
mappableFree((void*) irrstSharedMem);
|
||||||
|
irrstSharedMem = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void irrstWaitForEvent(bool nextEvent)
|
void irrstWaitForEvent(bool nextEvent)
|
||||||
|
@ -10,7 +10,7 @@ void __attribute__((weak)) __appInit() {
|
|||||||
// Initialize services
|
// Initialize services
|
||||||
srvInit();
|
srvInit();
|
||||||
aptInit();
|
aptInit();
|
||||||
hidInit(NULL);
|
hidInit();
|
||||||
|
|
||||||
fsInit();
|
fsInit();
|
||||||
sdmcInit();
|
sdmcInit();
|
||||||
|
Loading…
Reference in New Issue
Block a user