-cleaned up mem allocs a bit, also corrected wrong display of

usable size in mem1 region, also fixed a fatal bug in it,
some bug is still in it...
This commit is contained in:
fix94.1 2012-05-18 16:55:04 +00:00
parent db42694703
commit f29a014ac0
10 changed files with 42 additions and 20 deletions

View File

@ -146,7 +146,7 @@ void CVideo::init(void)
VIDEO_WaitVSync();
if (m_rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
m_fifo = MEM1_alloc(ALIGN32(DEFAULT_FIFO_SIZE));
m_fifo = MEM1_memalign(32, DEFAULT_FIFO_SIZE);
memset(m_fifo, 0, DEFAULT_FIFO_SIZE);
GX_Init(m_fifo, DEFAULT_FIFO_SIZE);
GX_SetCopyClear(CColor(0), 0x00FFFFFF);
@ -178,7 +178,7 @@ void CVideo::init(void)
render();
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
m_stencil = MEM1_alloc(ALIGN32(CVideo::_stencilWidth * CVideo::_stencilHeight));
m_stencil = MEM1_memalign(32, CVideo::_stencilWidth * CVideo::_stencilHeight);
memset(m_stencil, 0, CVideo::_stencilWidth * CVideo::_stencilHeight);
}

View File

@ -241,7 +241,7 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
frag_concat(fa, fs);
}
frag_list = MEM1_alloc(ALIGN32(sizeof(FragList)));
frag_list = MEM1_memalign(32, sizeof(FragList));
if(frag_list == NULL)
goto out;

View File

@ -12,7 +12,7 @@
/* Macros */
#define round_up(x,n) (-(-(x) & -(n)))
#define ALIGN(x) (((x) + 3) & ~3)
#define ALIGN(n, x) (((x) + (n - 1)) & ~(n - 1))
#define ALIGN32(x) (((x) + 31) & ~31)
#define ALIGNED(x) __attribute__((aligned(x)))

View File

@ -6,6 +6,7 @@
#include "mem2.hpp"
#include "mem2alloc.hpp"
#include "gecko.h"
#include "utils.h"
// Forbid the use of MEM2 through malloc
u32 MALLOC_MEM2 = 0;
@ -44,6 +45,11 @@ void *MEM1_alloc(unsigned int s)
return g_mem1gp.allocate(s);
}
void *MEM1_memalign(unsigned int a, unsigned int s)
{
return g_mem1gp.allocate(ALIGN(a, s));
}
void *MEM1_realloc(void *p, unsigned int s)
{
return g_mem1gp.reallocate(p, s);
@ -54,6 +60,16 @@ void MEM1_free(void *p)
g_mem1gp.release(p);
}
unsigned int MEM1_usableSize(void *p)
{
return g_mem1gp.usableSize(p);
}
unsigned int MEM1_freesize()
{
return g_mem1gp.FreeSize();
}
void MEM2_init(unsigned int mem2Size)
{
@ -81,6 +97,11 @@ void *MEM2_alloc(unsigned int s)
return g_mem2gp.allocate(s);
}
void *MEM2_memalign(unsigned int a, unsigned int s)
{
return g_mem2gp.allocate(ALIGN(a, s));
}
void *MEM2_realloc(void *p, unsigned int s)
{
return g_mem2gp.reallocate(p, s);
@ -88,7 +109,7 @@ void *MEM2_realloc(void *p, unsigned int s)
unsigned int MEM2_usableSize(void *p)
{
return CMEM2Alloc::usableSize(p);
return g_mem2gp.usableSize(p);
}
unsigned int MEM2_freesize()

View File

@ -16,14 +16,18 @@ void MEM1_init(void *addr, void *end);
void MEM1_cleanup(void);
void MEM1_clear(void);
void *MEM1_alloc(unsigned int s);
void *MEM1_memalign(unsigned int a, unsigned int s);
void *MEM1_realloc(void *p, unsigned int s);
void MEM1_free(void *p);
unsigned int MEM1_usableSize(void *p);
unsigned int MEM1_freesize();
void MEM2_init(unsigned int mem2Size);
void MEM2_cleanup(void);
void MEM2_clear(void);
void MEM2_free(void *p);
void *MEM2_alloc(unsigned int s);
void *MEM2_memalign(unsigned int a, unsigned int s);
void *MEM2_realloc(void *p, unsigned int s);
unsigned int MEM2_usableSize(void *p);
unsigned int MEM2_freesize();

View File

@ -1,10 +1,5 @@
#include "smartptr.hpp"
SmartBuf smartMalloc(unsigned int size)
{
return SmartBuf((unsigned char *)malloc(size), SmartBuf::SRCALL_MALLOC);
}
SmartBuf smartMemAlign32(unsigned int size)
{
return smartAnyAlloc(size);

View File

@ -14,7 +14,7 @@
template <class T> class SmartPtr
{
public:
enum SrcAlloc { SRCALL_MALLOC, SRCALL_MEM2, SRCALL_MEM1, SRCALL_NEW };
enum SrcAlloc { SRCALL_NEW, SRCALL_MEM1, SRCALL_MEM2 };
T &operator*(void) const { return *m_p; }
T *operator->(void) const { return m_p; }
bool operator!(void) const { return m_p == NULL; }
@ -25,11 +25,14 @@ public:
{
switch(m_srcAlloc)
{
case SRCALL_NEW:
delete m_p;
case SRCALL_MEM1:
MEM1_free(m_p);
break;
case SRCALL_MEM2:
MEM2_free(m_p);
break;
default:
free(m_p);
delete m_p;
break;
}
delete m_refcount;
@ -67,7 +70,6 @@ protected:
typedef SmartPtr<unsigned char> SmartBuf;
typedef SmartPtr<GuiSound> SmartGuiSound;
SmartBuf smartMalloc(unsigned int size);
SmartBuf smartMemAlign32(unsigned int size);
SmartBuf smartMem2Alloc(unsigned int size);
SmartBuf smartAnyAlloc(unsigned int size);

View File

@ -1776,7 +1776,7 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting)
m_cameraSound->Play(255);
}
#ifdef SHOWMEM
m_btnMgr.setText(m_mem2FreeSize, wfmt(L"Mem2 Free:%u, Mem1 Free:%u", MEM2_freesize(), SYS_GetArena1Size()), true);
m_btnMgr.setText(m_mem2FreeSize, wfmt(L"Mem2 Free:%u, Mem1 Free:%u", MEM2_freesize(), MEM1_freesize()), true);
#endif
}

View File

@ -1420,7 +1420,7 @@ void CMenu::_gameSoundThread(CMenu *m)
_extractBannerTitle(banner, GetLanguage(m->m_loc.getString(m->m_curLanguage, "gametdb_code", "EN").c_str()));
const u8 *soundBin = banner->GetFile((char *) "sound.bin", &sndSize);
delete banner;
MEM2_free(banner);
if (soundBin == NULL || (((IMD5Header *)soundBin)->fcc != 'IMD5' && ((IMD5Header *)soundBin)->fcc != 'RIFF'))
{
@ -1442,7 +1442,7 @@ void CMenu::_playGameSound(void)
CheckGameSoundThread();
if(!gameSoundThreadStack.get())
gameSoundThreadStack = smartAnyAlloc(gameSoundThreadStackSize);
gameSoundThreadStack = smartMem1Alloc(gameSoundThreadStackSize);
LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void *)this, gameSoundThreadStack.get(), gameSoundThreadStackSize, 60);
}

View File

@ -52,7 +52,7 @@ void BufferCircle::SetBufferBlockSize(int size)
{
if(SoundBuffer[i] != NULL)
MEM1_free(SoundBuffer[i]);
SoundBuffer[i] = (u8 *)MEM1_alloc(ALIGN32(BufferBlockSize));
SoundBuffer[i] = (u8 *)MEM1_memalign(32, BufferBlockSize);
BufferSize[i] = 0;
BufferReady[i] = false;
}
@ -72,7 +72,7 @@ void BufferCircle::Resize(int size)
for(int i = oldSize; i < Size(); i++)
{
if(BufferBlockSize > 0)
SoundBuffer[i] = (u8 *)MEM1_alloc(ALIGN32(BufferBlockSize));
SoundBuffer[i] = (u8 *)MEM1_memalign(32, BufferBlockSize);
else
SoundBuffer[i] = NULL;
BufferSize[i] = 0;