mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-12-22 18:01:54 +01:00
*Moved wii.spiffy360.com url in theme downloader a bit down (wasn't shown on some TVs)
*Moved font cache to mem2 (seems to fix the font issues) *Moved thread start of free space getting out of the constructor (caused a few freezes on start up) *Added destroy of sound handler when closing app
This commit is contained in:
parent
2ea5a823e0
commit
9480208373
@ -146,7 +146,7 @@ extern "C" bool CheckFile(const char * filepath)
|
||||
char dirnoslash[strlen(filepath)+2];
|
||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
||||
|
||||
if(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
||||
|
||||
char * notRoot = strrchr(dirnoslash, '/');
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "FreeTypeGX.h"
|
||||
#include "memory/mem2.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -228,7 +229,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
||||
{
|
||||
int length = ((((charData->textureWidth + 3) >> 2) * ((charData->textureHeight + 3) >> 2) * 32 * 2 + 31) & ~31);
|
||||
|
||||
uint8_t * glyphData = (uint8_t *) memalign(32, length);
|
||||
uint8_t * glyphData = (uint8_t *) MEM2_alloc(length);
|
||||
if (!glyphData) return;
|
||||
|
||||
memset(glyphData, 0x00, length);
|
||||
|
@ -24,7 +24,6 @@ GuiBGM::~GuiBGM()
|
||||
|
||||
ClearList();
|
||||
}
|
||||
;
|
||||
|
||||
void GuiBGM::SetLoop(u8 l)
|
||||
{
|
||||
|
@ -1,10 +1,12 @@
|
||||
|
||||
#include "mem2.h"
|
||||
#include "mem2alloc.hpp"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MEM2_PRIORITY_SIZE 2097152 //2MB
|
||||
#define MEM2_PRIORITY_SIZE 2097152 //2MB
|
||||
|
||||
// Forbid the use of MEM2 through malloc
|
||||
u32 MALLOC_MEM2 = 0;
|
||||
|
||||
@ -15,183 +17,175 @@ static bool g_bigGoesToMem2 = false;
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void MEM2_takeBigOnes(bool b)
|
||||
{
|
||||
g_bigGoesToMem2 = b;
|
||||
}
|
||||
void MEM2_takeBigOnes(bool b)
|
||||
{
|
||||
g_bigGoesToMem2 = b;
|
||||
}
|
||||
|
||||
void MEM2_init(unsigned int mem2Size)
|
||||
{
|
||||
g_mem2gp.init(mem2Size);
|
||||
}
|
||||
void MEM2_init(unsigned int mem2Size)
|
||||
{
|
||||
g_mem2gp.init(mem2Size);
|
||||
}
|
||||
|
||||
void MEM2_cleanup(void)
|
||||
{
|
||||
g_mem2gp.cleanup();
|
||||
}
|
||||
void MEM2_cleanup(void)
|
||||
{
|
||||
g_mem2gp.cleanup();
|
||||
}
|
||||
|
||||
void *MEM2_alloc(unsigned int s)
|
||||
{
|
||||
return g_mem2gp.allocate(s);
|
||||
}
|
||||
void *MEM2_alloc(unsigned int s)
|
||||
{
|
||||
return g_mem2gp.allocate(s);
|
||||
}
|
||||
|
||||
void MEM2_free(void *p)
|
||||
{
|
||||
g_mem2gp.release(p);
|
||||
}
|
||||
void MEM2_free(void *p)
|
||||
{
|
||||
g_mem2gp.release(p);
|
||||
}
|
||||
|
||||
void *MEM2_realloc(void *p, unsigned int s)
|
||||
{
|
||||
return g_mem2gp.reallocate(p, s);
|
||||
}
|
||||
void *MEM2_realloc(void *p, unsigned int s)
|
||||
{
|
||||
return g_mem2gp.reallocate(p, s);
|
||||
}
|
||||
|
||||
unsigned int MEM2_usableSize(void *p)
|
||||
{
|
||||
return CMEM2Alloc::usableSize(p);
|
||||
}
|
||||
unsigned int MEM2_usableSize(void *p)
|
||||
{
|
||||
return CMEM2Alloc::usableSize(p);
|
||||
}
|
||||
|
||||
unsigned int MEM2_freesize()
|
||||
{
|
||||
return g_mem2gp.FreeSize();
|
||||
}
|
||||
unsigned int MEM2_freesize()
|
||||
{
|
||||
return g_mem2gp.FreeSize();
|
||||
}
|
||||
|
||||
extern __typeof( malloc ) __real_malloc;
|
||||
extern __typeof( calloc ) __real_calloc;
|
||||
extern __typeof( realloc ) __real_realloc;
|
||||
extern __typeof( memalign ) __real_memalign;
|
||||
extern __typeof( free ) __real_free;
|
||||
extern __typeof( malloc_usable_size ) __real_malloc_usable_size;
|
||||
extern __typeof(malloc) __real_malloc;
|
||||
extern __typeof(calloc) __real_calloc;
|
||||
extern __typeof(realloc) __real_realloc;
|
||||
extern __typeof(memalign) __real_memalign;
|
||||
extern __typeof(free) __real_free;
|
||||
extern __typeof(malloc_usable_size) __real_malloc_usable_size;
|
||||
|
||||
void *__wrap_malloc(size_t size)
|
||||
{
|
||||
void *p;
|
||||
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
|
||||
{
|
||||
p = MEM2_alloc(size);
|
||||
if (p != 0)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
return __real_malloc(size);
|
||||
}
|
||||
p = __real_malloc(size);
|
||||
if (p != 0)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
return MEM2_alloc(size);
|
||||
}
|
||||
void *__wrap_malloc(size_t size)
|
||||
{
|
||||
void *p;
|
||||
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
|
||||
{
|
||||
p = MEM2_alloc(size);
|
||||
if (p != 0) {
|
||||
return p;
|
||||
}
|
||||
return __real_malloc(size);
|
||||
}
|
||||
p = __real_malloc(size);
|
||||
if (p != 0) {
|
||||
return p;
|
||||
}
|
||||
return MEM2_alloc(size);
|
||||
}
|
||||
|
||||
void *__wrap_calloc(size_t n, size_t size)
|
||||
{
|
||||
void *p;
|
||||
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
|
||||
{
|
||||
p = MEM2_alloc(n * size);
|
||||
if (p != 0)
|
||||
{
|
||||
memset(p, 0, n * size);
|
||||
return p;
|
||||
}
|
||||
return __real_calloc(n, size);
|
||||
}
|
||||
p = __real_calloc(n, size);
|
||||
if (p != 0)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
p = MEM2_alloc(n * size);
|
||||
if (p != 0)
|
||||
{
|
||||
memset(p, 0, n * size);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
void *__wrap_calloc(size_t n, size_t size)
|
||||
{
|
||||
void *p;
|
||||
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
|
||||
{
|
||||
p = MEM2_alloc(n * size);
|
||||
if (p != 0)
|
||||
{
|
||||
memset(p, 0, n * size);
|
||||
return p;
|
||||
}
|
||||
return __real_calloc(n, size);
|
||||
}
|
||||
p = __real_calloc(n, size);
|
||||
if (p != 0) {
|
||||
return p;
|
||||
}
|
||||
p = MEM2_alloc(n * size);
|
||||
if (p != 0) {
|
||||
memset(p, 0, n * size);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void *__wrap_memalign(size_t a, size_t size)
|
||||
{
|
||||
void *p;
|
||||
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
|
||||
{
|
||||
if (a <= 32 && 32 % a == 0)
|
||||
{
|
||||
p = MEM2_alloc(size);
|
||||
if (p != 0)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return __real_memalign(a, size);
|
||||
}
|
||||
p = __real_memalign(a, size);
|
||||
if (p != 0 || a > 32 || 32 % a != 0)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
void *__wrap_memalign(size_t a, size_t size)
|
||||
{
|
||||
void *p;
|
||||
if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)
|
||||
{
|
||||
if (a <= 32 && 32 % a == 0)
|
||||
{
|
||||
p = MEM2_alloc(size);
|
||||
if (p != 0) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return __real_memalign(a, size);
|
||||
}
|
||||
p = __real_memalign(a, size);
|
||||
if (p != 0 || a > 32 || 32 % a != 0) {
|
||||
return p;
|
||||
}
|
||||
|
||||
return MEM2_alloc(size);
|
||||
}
|
||||
return MEM2_alloc(size);
|
||||
}
|
||||
|
||||
void __wrap_free(void *p)
|
||||
{
|
||||
if (!p) return;
|
||||
void __wrap_free(void *p)
|
||||
{
|
||||
if(!p)
|
||||
return;
|
||||
|
||||
if (((u32) p & 0x10000000) != 0)
|
||||
{
|
||||
MEM2_free(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
__real_free(p);
|
||||
}
|
||||
}
|
||||
if (((u32)p & 0x10000000) != 0)
|
||||
{
|
||||
MEM2_free(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
__real_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void *__wrap_realloc(void *p, size_t size)
|
||||
{
|
||||
void *n;
|
||||
// ptr from mem2
|
||||
if (((u32) p & 0x10000000) != 0 || (p == 0 && g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE))
|
||||
{
|
||||
n = MEM2_realloc(p, size);
|
||||
if (n != 0)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
n = __real_malloc(size);
|
||||
if (n == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (p != 0)
|
||||
{
|
||||
memcpy(n, p, MEM2_usableSize(p) < size ? MEM2_usableSize(p) : size);
|
||||
MEM2_free(p);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
// ptr from malloc
|
||||
n = __real_realloc(p, size);
|
||||
if (n != 0)
|
||||
{
|
||||
return n;
|
||||
}
|
||||
n = MEM2_alloc(size);
|
||||
if (n == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (p != 0)
|
||||
{
|
||||
memcpy(n, p, __real_malloc_usable_size(p) < size ? __real_malloc_usable_size(p) : size);
|
||||
__real_free(p);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
void *__wrap_realloc(void *p, size_t size)
|
||||
{
|
||||
void *n;
|
||||
// ptr from mem2
|
||||
if (((u32)p & 0x10000000) != 0 || (p == 0 && g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE))
|
||||
{
|
||||
n = MEM2_realloc(p, size);
|
||||
if (n != 0) {
|
||||
return n;
|
||||
}
|
||||
n = __real_malloc(size);
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (p != 0)
|
||||
{
|
||||
memcpy(n, p, MEM2_usableSize(p) < size ? MEM2_usableSize(p) : size);
|
||||
MEM2_free(p);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
// ptr from malloc
|
||||
n = __real_realloc(p, size);
|
||||
if (n != 0) {
|
||||
return n;
|
||||
}
|
||||
n = MEM2_alloc(size);
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (p != 0)
|
||||
{
|
||||
memcpy(n, p, __real_malloc_usable_size(p) < size ? __real_malloc_usable_size(p) : size);
|
||||
__real_free(p);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t __wrap_malloc_usable_size(void *p)
|
||||
{
|
||||
if (((u32) p & 0x10000000) != 0) return MEM2_usableSize(p);
|
||||
return __real_malloc_usable_size(p);
|
||||
}
|
||||
size_t __wrap_malloc_usable_size(void *p)
|
||||
{
|
||||
if (((u32)p & 0x10000000) != 0)
|
||||
return MEM2_usableSize(p);
|
||||
return __real_malloc_usable_size(p);
|
||||
}
|
||||
|
||||
} ///extern "C"
|
||||
|
@ -5,12 +5,9 @@
|
||||
#define __MEM2_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
void MEM2_init(unsigned int mem2Size);
|
||||
void MEM2_cleanup(void);
|
||||
void MEM2_takeBigOnes(bool b);
|
||||
|
@ -1,226 +1,238 @@
|
||||
|
||||
#include "mem2alloc.hpp"
|
||||
|
||||
#include <ogc/system.h>
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
class LockMutex
|
||||
{
|
||||
mutex_t &m_mutex;
|
||||
public:
|
||||
LockMutex(mutex_t &m) :
|
||||
m_mutex(m)
|
||||
{
|
||||
LWP_MutexLock(m_mutex);
|
||||
}
|
||||
~LockMutex(void)
|
||||
{
|
||||
LWP_MutexUnlock(m_mutex);
|
||||
}
|
||||
mutex_t &m_mutex;
|
||||
public:
|
||||
LockMutex(mutex_t &m) : m_mutex(m) { LWP_MutexLock(m_mutex); }
|
||||
~LockMutex(void) { LWP_MutexUnlock(m_mutex); }
|
||||
};
|
||||
|
||||
void CMEM2Alloc::init(unsigned int size)
|
||||
{
|
||||
m_baseAddress = (SBlock *) (((u32) SYS_GetArena2Lo() + 31) & ~31);
|
||||
m_endAddress = (SBlock *) ((char *) m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
|
||||
if (m_endAddress > (SBlock *) 0x93300000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes)
|
||||
m_endAddress = (SBlock *) 0x93300000;
|
||||
SYS_SetArena2Lo(m_endAddress);
|
||||
LWP_MutexInit(&m_mutex, 0);
|
||||
m_baseAddress = (SBlock *) (((u32)SYS_GetArena2Lo() + 31) & ~31);
|
||||
m_endAddress = (SBlock *) ((char *)m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
|
||||
if (m_endAddress > (SBlock *) 0x93300000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes)
|
||||
m_endAddress = (SBlock *) 0x93300000;
|
||||
SYS_SetArena2Lo(m_endAddress);
|
||||
LWP_MutexInit(&m_mutex, 0);
|
||||
}
|
||||
|
||||
void CMEM2Alloc::init(void *addr, void *end)
|
||||
{
|
||||
m_baseAddress = (SBlock *) (((u32) addr + 31) & ~31);
|
||||
m_endAddress = (SBlock *) ((u32) end & ~31);
|
||||
LWP_MutexInit(&m_mutex, 0);
|
||||
m_baseAddress = (SBlock *)(((u32)addr + 31) & ~31);
|
||||
m_endAddress = (SBlock *)((u32)end & ~31);
|
||||
LWP_MutexInit(&m_mutex, 0);
|
||||
}
|
||||
|
||||
void CMEM2Alloc::cleanup(void)
|
||||
{
|
||||
LWP_MutexDestroy(m_mutex);
|
||||
m_mutex = 0;
|
||||
m_first = 0;
|
||||
// Try to release the range we took through SYS functions
|
||||
if (SYS_GetArena2Lo() == m_endAddress) SYS_SetArena2Lo(m_baseAddress);
|
||||
m_baseAddress = 0;
|
||||
m_endAddress = 0;
|
||||
LWP_MutexDestroy(m_mutex);
|
||||
m_mutex = 0;
|
||||
m_first = 0;
|
||||
// Try to release the range we took through SYS functions
|
||||
if (SYS_GetArena2Lo() == m_endAddress)
|
||||
SYS_SetArena2Lo(m_baseAddress);
|
||||
m_baseAddress = 0;
|
||||
m_endAddress = 0;
|
||||
}
|
||||
|
||||
void CMEM2Alloc::clear(void)
|
||||
{
|
||||
m_first = 0;
|
||||
memset(m_baseAddress, 0, (u8 *) m_endAddress - (u8 *) m_endAddress);
|
||||
m_first = 0;
|
||||
memset(m_baseAddress, 0, (u8 *)m_endAddress - (u8 *)m_endAddress);
|
||||
}
|
||||
|
||||
unsigned int CMEM2Alloc::usableSize(void *p)
|
||||
{
|
||||
return p == 0 ? 0 : ((SBlock *) p - 1)->s * sizeof(SBlock);
|
||||
return p == 0 ? 0 : ((SBlock *)p - 1)->s * sizeof (SBlock);
|
||||
}
|
||||
|
||||
void *CMEM2Alloc::allocate(unsigned int s)
|
||||
{
|
||||
if (s == 0) s = 1;
|
||||
//
|
||||
LockMutex lock(m_mutex);
|
||||
//
|
||||
s = (s - 1) / sizeof(SBlock) + 1;
|
||||
// First block
|
||||
if (m_first == 0)
|
||||
{
|
||||
if (m_baseAddress + s + 1 >= m_endAddress) return 0;
|
||||
m_first = m_baseAddress;
|
||||
m_first->next = 0;
|
||||
m_first->prev = 0;
|
||||
m_first->s = s;
|
||||
m_first->f = false;
|
||||
return (void *) (m_first + 1);
|
||||
}
|
||||
// Search for a free block
|
||||
SBlock *i;
|
||||
SBlock *j;
|
||||
for (i = m_first; i != 0; i = i->next)
|
||||
{
|
||||
if (i->f && i->s >= s) break;
|
||||
j = i;
|
||||
}
|
||||
// Create a new block
|
||||
if (i == 0)
|
||||
{
|
||||
i = j + j->s + 1;
|
||||
if (i + s + 1 >= m_endAddress) return 0;
|
||||
j->next = i;
|
||||
i->prev = j;
|
||||
i->next = 0;
|
||||
i->s = s;
|
||||
i->f = false;
|
||||
return (void *) (i + 1);
|
||||
}
|
||||
// Reuse a free block
|
||||
i->f = false;
|
||||
// Split it
|
||||
if (i->s > s + 1)
|
||||
{
|
||||
j = i + s + 1;
|
||||
j->f = true;
|
||||
j->s = i->s - s - 1;
|
||||
i->s = s;
|
||||
j->next = i->next;
|
||||
j->prev = i;
|
||||
i->next = j;
|
||||
if (j->next != 0) j->next->prev = j;
|
||||
}
|
||||
return (void *) (i + 1);
|
||||
if (s == 0)
|
||||
s = 1;
|
||||
//
|
||||
LockMutex lock(m_mutex);
|
||||
//
|
||||
s = (s - 1) / sizeof (SBlock) + 1;
|
||||
// First block
|
||||
if (m_first == 0)
|
||||
{
|
||||
if (m_baseAddress + s + 1 >= m_endAddress)
|
||||
return 0;
|
||||
m_first = m_baseAddress;
|
||||
m_first->next = 0;
|
||||
m_first->prev = 0;
|
||||
m_first->s = s;
|
||||
m_first->f = false;
|
||||
return (void *)(m_first + 1);
|
||||
}
|
||||
// Search for a free block
|
||||
SBlock *i;
|
||||
SBlock *j;
|
||||
for (i = m_first; i != 0; i = i->next)
|
||||
{
|
||||
if (i->f && i->s >= s)
|
||||
break;
|
||||
j = i;
|
||||
}
|
||||
// Create a new block
|
||||
if (i == 0)
|
||||
{
|
||||
i = j + j->s + 1;
|
||||
if (i + s + 1 >= m_endAddress)
|
||||
return 0;
|
||||
j->next = i;
|
||||
i->prev = j;
|
||||
i->next = 0;
|
||||
i->s = s;
|
||||
i->f = false;
|
||||
return (void *)(i + 1);
|
||||
}
|
||||
// Reuse a free block
|
||||
i->f = false;
|
||||
// Split it
|
||||
if (i->s > s + 1)
|
||||
{
|
||||
j = i + s + 1;
|
||||
j->f = true;
|
||||
j->s = i->s - s - 1;
|
||||
i->s = s;
|
||||
j->next = i->next;
|
||||
j->prev = i;
|
||||
i->next = j;
|
||||
if (j->next != 0)
|
||||
j->next->prev = j;
|
||||
}
|
||||
return (void *)(i + 1);
|
||||
}
|
||||
|
||||
void CMEM2Alloc::release(void *p)
|
||||
{
|
||||
if (p == 0) return;
|
||||
if (p == 0)
|
||||
return;
|
||||
|
||||
LockMutex lock(m_mutex);
|
||||
SBlock *i = (SBlock *) p - 1;
|
||||
i->f = true;
|
||||
LockMutex lock(m_mutex);
|
||||
SBlock *i = (SBlock *)p - 1;
|
||||
i->f = true;
|
||||
|
||||
// If there are no other blocks following yet,
|
||||
// set the remaining size to free size. - Dimok
|
||||
if (i->next == 0) i->s = m_endAddress - i - 1;
|
||||
if(i->next == 0)
|
||||
i->s = m_endAddress - i - 1;
|
||||
|
||||
// Merge with previous block
|
||||
if (i->prev != 0 && i->prev->f)
|
||||
{
|
||||
i = i->prev;
|
||||
i->s += i->next->s + 1;
|
||||
i->next = i->next->next;
|
||||
if (i->next != 0) i->next->prev = i;
|
||||
}
|
||||
// Merge with next block
|
||||
if (i->next != 0 && i->next->f)
|
||||
{
|
||||
i->s += i->next->s + 1;
|
||||
i->next = i->next->next;
|
||||
if (i->next != 0) i->next->prev = i;
|
||||
}
|
||||
// Merge with previous block
|
||||
if (i->prev != 0 && i->prev->f)
|
||||
{
|
||||
i = i->prev;
|
||||
i->s += i->next->s + 1;
|
||||
i->next = i->next->next;
|
||||
if (i->next != 0)
|
||||
i->next->prev = i;
|
||||
}
|
||||
// Merge with next block
|
||||
if (i->next != 0 && i->next->f)
|
||||
{
|
||||
i->s += i->next->s + 1;
|
||||
i->next = i->next->next;
|
||||
if (i->next != 0)
|
||||
i->next->prev = i;
|
||||
}
|
||||
}
|
||||
|
||||
void *CMEM2Alloc::reallocate(void *p, unsigned int s)
|
||||
{
|
||||
SBlock *i;
|
||||
SBlock *j;
|
||||
void *n;
|
||||
SBlock *i;
|
||||
SBlock *j;
|
||||
void *n;
|
||||
|
||||
if (s == 0) s = 1;
|
||||
if (p == 0) return allocate(s);
|
||||
if (s == 0)
|
||||
s = 1;
|
||||
if (p == 0)
|
||||
return allocate(s);
|
||||
|
||||
i = (SBlock *) p - 1;
|
||||
s = (s - 1) / sizeof(SBlock) + 1;
|
||||
{
|
||||
LockMutex lock(m_mutex);
|
||||
i = (SBlock *)p - 1;
|
||||
s = (s - 1) / sizeof (SBlock) + 1;
|
||||
{
|
||||
LockMutex lock(m_mutex);
|
||||
|
||||
//out of memory /* Dimok */
|
||||
if (i + s + 1 >= m_endAddress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (i + s + 1 >= m_endAddress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Last block
|
||||
if (i->next == 0 && i + s + 1 < m_endAddress)
|
||||
{
|
||||
i->s = s;
|
||||
return p;
|
||||
}
|
||||
// Size <= current size + next block
|
||||
if (i->next != 0 && i->s < s && i->next->f && i->s + i->next->s + 1 >= s)
|
||||
{
|
||||
// Merge
|
||||
i->s += i->next->s + 1;
|
||||
i->next = i->next->next;
|
||||
if (i->next != 0) i->next->prev = i;
|
||||
}
|
||||
// Size <= current size
|
||||
if (i->s >= s)
|
||||
{
|
||||
// Split
|
||||
if (i->s > s + 1)
|
||||
{
|
||||
j = i + s + 1;
|
||||
j->f = true;
|
||||
j->s = i->s - s - 1;
|
||||
i->s = s;
|
||||
j->next = i->next;
|
||||
j->prev = i;
|
||||
i->next = j;
|
||||
if (j->next != 0) j->next->prev = j;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
// Size > current size
|
||||
n = allocate(s * sizeof(SBlock));
|
||||
if (n == 0) return 0;
|
||||
memcpy(n, p, i->s * sizeof(SBlock));
|
||||
release(p);
|
||||
return n;
|
||||
// Last block
|
||||
if (i->next == 0 && i + s + 1 < m_endAddress)
|
||||
{
|
||||
i->s = s;
|
||||
return p;
|
||||
}
|
||||
// Size <= current size + next block
|
||||
if (i->next != 0 && i->s < s && i->next->f && i->s + i->next->s + 1 >= s)
|
||||
{
|
||||
// Merge
|
||||
i->s += i->next->s + 1;
|
||||
i->next = i->next->next;
|
||||
if (i->next != 0)
|
||||
i->next->prev = i;
|
||||
}
|
||||
// Size <= current size
|
||||
if (i->s >= s)
|
||||
{
|
||||
// Split
|
||||
if (i->s > s + 1)
|
||||
{
|
||||
j = i + s + 1;
|
||||
j->f = true;
|
||||
j->s = i->s - s - 1;
|
||||
i->s = s;
|
||||
j->next = i->next;
|
||||
j->prev = i;
|
||||
i->next = j;
|
||||
if (j->next != 0)
|
||||
j->next->prev = j;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
// Size > current size
|
||||
n = allocate(s * sizeof (SBlock));
|
||||
if (n == 0)
|
||||
return 0;
|
||||
memcpy(n, p, i->s * sizeof (SBlock));
|
||||
release(p);
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned int CMEM2Alloc::FreeSize()
|
||||
{
|
||||
LockMutex lock(m_mutex);
|
||||
|
||||
if (m_first == 0) return (const char *) m_endAddress - (const char *) m_baseAddress;
|
||||
if (m_first == 0)
|
||||
return (const char *) m_endAddress - (const char *) m_baseAddress;
|
||||
|
||||
SBlock *i;
|
||||
SBlock *i;
|
||||
unsigned int size = 0;
|
||||
|
||||
for (i = m_first; i != 0; i = i->next)
|
||||
{
|
||||
if (i->f && i->next != 0)
|
||||
for(i = m_first; i != 0; i = i->next)
|
||||
{
|
||||
if(i->f && i->next != 0)
|
||||
size += i->s;
|
||||
|
||||
else if (i->f && i->next == 0)
|
||||
else if(i->f && i->next == 0)
|
||||
size += m_endAddress - i - 1;
|
||||
|
||||
else if (!i->f && i->next == 0) size += m_endAddress - i - i->s - 1;
|
||||
else if(!i->f && i->next == 0)
|
||||
size += m_endAddress - i - i->s - 1;
|
||||
}
|
||||
|
||||
return size * sizeof(SBlock);
|
||||
return size*sizeof(SBlock);
|
||||
}
|
||||
|
@ -8,48 +8,35 @@
|
||||
|
||||
class CMEM2Alloc
|
||||
{
|
||||
public:
|
||||
void *allocate(unsigned int s);
|
||||
void release(void *p);
|
||||
void *reallocate(void *p, unsigned int s);
|
||||
void init(unsigned int size);
|
||||
void init(void *addr, void *end);
|
||||
void cleanup(void);
|
||||
void clear(void);
|
||||
static unsigned int usableSize(void *p);
|
||||
void forceEndAddress(void *newAddr)
|
||||
{
|
||||
m_endAddress = (SBlock *) newAddr;
|
||||
}
|
||||
void *getEndAddress(void) const
|
||||
{
|
||||
return m_endAddress;
|
||||
}
|
||||
void info(void *&address, unsigned int &size) const
|
||||
{
|
||||
address = m_baseAddress;
|
||||
size = (const char *) m_endAddress - (const char *) m_baseAddress;
|
||||
}
|
||||
unsigned int FreeSize();
|
||||
//
|
||||
CMEM2Alloc(void) :
|
||||
m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0)
|
||||
{
|
||||
}
|
||||
private:
|
||||
struct SBlock
|
||||
{
|
||||
unsigned int s;
|
||||
SBlock *next;
|
||||
SBlock *prev;
|
||||
bool f;
|
||||
}__attribute__((aligned(32)));
|
||||
SBlock *m_baseAddress;
|
||||
SBlock *m_endAddress;
|
||||
SBlock *m_first;
|
||||
mutex_t m_mutex;
|
||||
private:
|
||||
CMEM2Alloc(const CMEM2Alloc &);
|
||||
public:
|
||||
void *allocate(unsigned int s);
|
||||
void release(void *p);
|
||||
void *reallocate(void *p, unsigned int s);
|
||||
void init(unsigned int size);
|
||||
void init(void *addr, void *end);
|
||||
void cleanup(void);
|
||||
void clear(void);
|
||||
static unsigned int usableSize(void *p);
|
||||
void forceEndAddress(void *newAddr) { m_endAddress = (SBlock *)newAddr; }
|
||||
void *getEndAddress(void) const { return m_endAddress; }
|
||||
void info(void *&address, unsigned int &size) const { address = m_baseAddress; size = (const char *)m_endAddress - (const char *)m_baseAddress; }
|
||||
unsigned int FreeSize();
|
||||
//
|
||||
CMEM2Alloc(void) : m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0) { }
|
||||
private:
|
||||
struct SBlock
|
||||
{
|
||||
unsigned int s;
|
||||
SBlock *next;
|
||||
SBlock *prev;
|
||||
bool f;
|
||||
} __attribute__((aligned(32)));
|
||||
SBlock *m_baseAddress;
|
||||
SBlock *m_endAddress;
|
||||
SBlock *m_first;
|
||||
mutex_t m_mutex;
|
||||
private:
|
||||
CMEM2Alloc(const CMEM2Alloc &);
|
||||
};
|
||||
|
||||
#endif // !defined(__MEM2ALLOC_HPP)
|
||||
|
@ -108,13 +108,6 @@ GameBrowseMenu::GameBrowseMenu()
|
||||
usedSpaceTxt->SetAlignment(thAlign("center - hdd info align hor"), thAlign("top - hdd info align ver"));
|
||||
usedSpaceTxt->SetPosition(thInt("0 - hdd info pos x"), thInt("400 - hdd info pos y"));
|
||||
|
||||
if(Settings.ShowFreeSpace)
|
||||
{
|
||||
HDDSizeCallback.SetCallback(this, &GameBrowseMenu::UpdateFreeSpace);
|
||||
ThreadedTask::Instance()->AddCallback(&HDDSizeCallback);
|
||||
ThreadedTask::Instance()->Execute();
|
||||
}
|
||||
|
||||
gamecntTxt = new GuiText((char *) NULL, 18, thColor("r=55 g=190 b=237 a=255 - game count color"));
|
||||
gamecntBtn = new GuiButton(100, 18);
|
||||
gamecntBtn->SetAlignment(thAlign("center - game count align hor"), thAlign("top - game count align ver"));
|
||||
@ -716,6 +709,13 @@ int GameBrowseMenu::Show()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
|
||||
if(Settings.ShowFreeSpace)
|
||||
{
|
||||
HDDSizeCallback.SetCallback(this, &GameBrowseMenu::UpdateFreeSpace);
|
||||
ThreadedTask::Instance()->AddCallback(&HDDSizeCallback);
|
||||
ThreadedTask::Instance()->Execute();
|
||||
}
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "usbloader/playlog.h"
|
||||
#include "usbloader/wbfs.h"
|
||||
#include "themes/CTheme.h"
|
||||
#include "SoundOperations/SoundHandler.hpp"
|
||||
#include "utils/ThreadedTask.hpp"
|
||||
#include "audio.h"
|
||||
#include "lstub.h"
|
||||
@ -67,11 +68,12 @@ void AppCleanUp(void)
|
||||
Settings.Save();
|
||||
|
||||
ExitGUIThreads();
|
||||
StopGX();
|
||||
|
||||
delete bgMusic;
|
||||
delete btnSoundClick;
|
||||
delete btnSoundOver;
|
||||
delete btnSoundClick2;
|
||||
delete bgMusic;
|
||||
delete background;
|
||||
delete bgImg;
|
||||
delete mainWindow;
|
||||
@ -83,9 +85,9 @@ void AppCleanUp(void)
|
||||
Theme::CleanUp();
|
||||
NewTitles::DestroyInstance();
|
||||
ThreadedTask::DestroyInstance();
|
||||
SoundHandler::DestroyInstance();
|
||||
DeinitNetwork();
|
||||
|
||||
StopGX();
|
||||
ShutdownAudio();
|
||||
|
||||
ResourceManager::DestroyInstance();
|
||||
|
@ -47,7 +47,7 @@ ThemeDownloader::ThemeDownloader()
|
||||
|
||||
urlTxt = new GuiText(tr( "Themes by www.spiffy360.com" ), 22, (GXColor) {255, 255, 255, 255});
|
||||
urlTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
urlTxt->SetPosition(350, 3);
|
||||
urlTxt->SetPosition(350, 12);
|
||||
Append(urlTxt);
|
||||
|
||||
for(int i = 0; i < 4; ++i)
|
||||
|
Loading…
Reference in New Issue
Block a user