-changed this and that, some cleanups, some more corrections

about memory stuff
This commit is contained in:
fix94.1 2012-10-15 19:16:14 +00:00
parent 8f79a359ea
commit 74b362e766
31 changed files with 327 additions and 374 deletions

View File

@ -29,6 +29,7 @@ distribution.
#include "unzip/lz77.h" #include "unzip/lz77.h"
#include "unzip/ash.h" #include "unzip/ash.h"
AnimatedBanner gameBanner;
AnimatedBanner::AnimatedBanner() AnimatedBanner::AnimatedBanner()
{ {
layout_banner = NULL; layout_banner = NULL;
@ -55,10 +56,10 @@ void AnimatedBanner::Clear()
} }
} }
bool AnimatedBanner::LoadBanner(Banner *banner) bool AnimatedBanner::LoadBanner()
{ {
u32 banner_bin_size; u32 banner_bin_size;
u8 *banner_bin = banner->GetFile((char*)"banner.bin", &banner_bin_size); u8 *banner_bin = CurrentBanner.GetFile((char*)"banner.bin", &banner_bin_size);
if(banner_bin == NULL) if(banner_bin == NULL)
return false; return false;
bool ret = LoadBannerBin(banner_bin, banner_bin_size); bool ret = LoadBannerBin(banner_bin, banner_bin_size);

View File

@ -36,7 +36,7 @@ public:
void LoadFont(u8 *font1, u8 *font2); void LoadFont(u8 *font1, u8 *font2);
void Clear(); void Clear();
bool LoadBanner(Banner *banner); bool LoadBanner();
bool LoadBannerBin(u8 *banner_bin, u32 banner_bin_size); bool LoadBannerBin(u8 *banner_bin, u32 banner_bin_size);
Layout *getBanner() const { return layout_banner; } Layout *getBanner() const { return layout_banner; }
void SetBannerTexture(const char *tex_name, const u8 *data, float width, float height, u8 fmt); void SetBannerTexture(const char *tex_name, const u8 *data, float width, float height, u8 fmt);
@ -51,4 +51,5 @@ protected:
u8 *DecompressCopy(u8 *stuff, u32 len, u32 *size); u8 *DecompressCopy(u8 *stuff, u32 len, u32 *size);
extern AnimatedBanner gameBanner;
#endif #endif

View File

@ -60,19 +60,19 @@ void BannerWindow::Init(u8 *font1, u8 *font2)
stepy1 = ((ScreenProps.y * 0.9f - yDiff) - (AnimPosY + 0.5f * fIconHeight - 0.5f * iconHeight)) * ratioY; stepy1 = ((ScreenProps.y * 0.9f - yDiff) - (AnimPosY + 0.5f * fIconHeight - 0.5f * iconHeight)) * ratioY;
stepy2 = ((ScreenProps.y * 0.9f + yDiff) - (AnimPosY + 0.5f * fIconHeight + 0.5f * iconHeight)) * ratioY; stepy2 = ((ScreenProps.y * 0.9f + yDiff) - (AnimPosY + 0.5f * fIconHeight + 0.5f * iconHeight)) * ratioY;
gameBanner->Clear(); gameBanner.Clear();
if(!FontLoaded) if(!FontLoaded)
{ {
gameBanner->LoadFont(sysFont1, sysFont2); gameBanner.LoadFont(sysFont1, sysFont2);
FontLoaded = true; FontLoaded = true;
} }
} }
void BannerWindow::LoadBanner(Banner *banner, u8 *font1, u8 *font2) void BannerWindow::LoadBanner(u8 *font1, u8 *font2)
{ {
changing = true; changing = true;
Init(font1, font2); Init(font1, font2);
gameBanner->LoadBanner(banner); gameBanner.LoadBanner();
gameSelected = 1; gameSelected = 1;
changing = false; changing = false;
ShowBanner = true; ShowBanner = true;
@ -82,7 +82,7 @@ void BannerWindow::DeleteBanner(bool gamechange)
{ {
if(!gamechange) if(!gamechange)
gameSelected = 0; gameSelected = 0;
gameBanner->Clear(); gameBanner.Clear();
} }
BannerWindow::BannerWindow() BannerWindow::BannerWindow()
@ -93,14 +93,13 @@ BannerWindow::BannerWindow()
AnimZoom = false; AnimZoom = false;
AnimStep = 20; AnimStep = 20;
gameSelected = 0; gameSelected = 0;
gameBanner = new AnimatedBanner;
} }
void BannerWindow::LoadBannerBin(u8 *bnr, u32 bnr_size, u8 *font1, u8 *font2) void BannerWindow::LoadBannerBin(u8 *bnr, u32 bnr_size, u8 *font1, u8 *font2)
{ {
changing = true; changing = true;
Init(font1, font2); Init(font1, font2);
gameBanner->LoadBannerBin(bnr, bnr_size); gameBanner.LoadBannerBin(bnr, bnr_size);
gameSelected = 1; gameSelected = 1;
changing = false; changing = false;
ShowBanner = true; ShowBanner = true;
@ -110,8 +109,8 @@ void BannerWindow::CreateGCBanner(u8 *bnr, u8 *font1, u8 *font2, const wchar_t *
{ {
GC_OpeningBnr *openingBnr = (GC_OpeningBnr *)bnr; GC_OpeningBnr *openingBnr = (GC_OpeningBnr *)bnr;
LoadBannerBin((u8*)custombanner_bin, (u32)custombanner_bin_size, font1, font2); LoadBannerBin((u8*)custombanner_bin, (u32)custombanner_bin_size, font1, font2);
gameBanner->SetBannerTexture("GCIcon.tpl", openingBnr->tpl_data, 96, 32, GX_TF_RGB5A3); gameBanner.SetBannerTexture("GCIcon.tpl", openingBnr->tpl_data, 96, 32, GX_TF_RGB5A3);
gameBanner->SetBannerText("T_GameTitle", title); gameBanner.SetBannerText("T_GameTitle", title);
} }
bool BannerWindow::ToogleZoom(void) bool BannerWindow::ToogleZoom(void)
@ -203,10 +202,10 @@ void BannerWindow::Draw(void)
// load projection matrix // load projection matrix
GX_LoadProjectionMtx(projection, GX_ORTHOGRAPHIC); GX_LoadProjectionMtx(projection, GX_ORTHOGRAPHIC);
if(gameBanner->getBanner()) if(gameBanner.getBanner())
{ {
gameBanner->getBanner()->Render(modelview, ScreenProps, m_vid.wide(), 255.f); gameBanner.getBanner()->Render(modelview, ScreenProps, m_vid.wide(), 255.f);
gameBanner->getBanner()->AdvanceFrame(); gameBanner.getBanner()->AdvanceFrame();
} }
// Setup GX // Setup GX

View File

@ -47,7 +47,7 @@ class BannerWindow
public: public:
BannerWindow(); BannerWindow();
void DeleteBanner(bool gamechange = false); void DeleteBanner(bool gamechange = false);
void LoadBanner(Banner *banner, u8 *font1, u8 *font2); void LoadBanner(u8 *font1, u8 *font2);
void LoadBannerBin(u8 *bnr, u32 bnr_size, u8 *font1, u8 *font2); void LoadBannerBin(u8 *bnr, u32 bnr_size, u8 *font1, u8 *font2);
int GetSelectedGame() { return gameSelected; } int GetSelectedGame() { return gameSelected; }
bool GetZoomSetting() { return AnimZoom; } bool GetZoomSetting() { return AnimZoom; }
@ -95,7 +95,6 @@ class BannerWindow
Mtx44 projection; Mtx44 projection;
Vec2f ScreenProps; Vec2f ScreenProps;
AnimatedBanner *gameBanner;
u8 *sysFont1; u8 *sysFont1;
u8 *sysFont2; u8 *sysFont2;
bool FontLoaded; bool FontLoaded;

View File

@ -117,6 +117,6 @@ void ExternalBooter_ChannelSetup(u64 title)
void ShutdownBeforeExit() void ShutdownBeforeExit()
{ {
DeviceHandle.UnMountAll(); DeviceHandle.UnMountAll();
Nand::Instance()->DeInit_ISFS(); NandHandle.DeInit_ISFS();
WDVD_Close(); WDVD_Close();
} }

View File

@ -42,22 +42,32 @@
#define IMET_OFFSET 0x40 #define IMET_OFFSET 0x40
#define IMET_SIGNATURE 0x494d4554 #define IMET_SIGNATURE 0x494d4554
Banner::Banner(u8 *bnr, u32 bnr_size, u64 title, bool custom) Banner CurrentBanner;
Banner::Banner()
{ {
opening = NULL;
opening_size = 0;
title = 0;
imet = NULL;
}
void Banner::SetBanner(u8 *bnr, u32 bnr_size, u64 title, bool custom)
{
ClearBanner();
if(bnr == NULL || bnr_size == 0)
return;
this->title = title; this->title = title;
opening = bnr; opening = bnr;
opening_size = bnr_size; opening_size = bnr_size;
imet = NULL; imet = (IMET *)opening;
if(opening == NULL)
return;
IMET *imet = (IMET *)opening;
if(imet->sig != IMET_SIGNATURE) if(imet->sig != IMET_SIGNATURE)
imet = (IMET *) (opening + IMET_OFFSET); imet = (IMET *) (opening + IMET_OFFSET);
if(imet->sig == IMET_SIGNATURE) if(imet->sig == IMET_SIGNATURE)
{ {
DCFlushRange(opening, opening_size);
unsigned char md5[16]; unsigned char md5[16];
unsigned char imetmd5[16]; unsigned char imetmd5[16];
@ -72,15 +82,15 @@ Banner::Banner(u8 *bnr, u32 bnr_size, u64 title, bool custom)
gprintf("Invalid md5, banner not valid for title %08x\n", title); gprintf("Invalid md5, banner not valid for title %08x\n", title);
} }
else else
{
gprintf("Invalid signature found, banner not valid for title %08x\n", title); gprintf("Invalid signature found, banner not valid for title %08x\n", title);
}
} }
Banner::~Banner() void Banner::ClearBanner()
{ {
if(opening != NULL) if(opening != NULL)
free(opening); free(opening);
opening = NULL;
opening_size = 0;
} }
bool Banner::IsValid() bool Banner::IsValid()
@ -151,7 +161,7 @@ u8 *Banner::GetFile(char *name, u32 *size)
return file; return file;
} }
Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) void Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly)
{ {
void *buf = NULL; void *buf = NULL;
u32 size = 0; u32 size = 0;
@ -162,14 +172,14 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly)
{ {
if(buf != NULL) if(buf != NULL)
free(buf); free(buf);
return NULL; return;
} }
} }
else else
{ {
FILE *fp = fopen(appname, "rb"); FILE *fp = fopen(appname, "rb");
if(fp == NULL) if(fp == NULL)
return NULL; return;
u32 size = sizeof(IMET) + IMET_OFFSET; u32 size = sizeof(IMET) + IMET_OFFSET;
if (!imetOnly) if (!imetOnly)
@ -181,11 +191,10 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly)
buf = malloc(size); buf = malloc(size);
if(!buf) if(!buf)
return NULL; return;
fread(buf, size, 1, fp); fread(buf, size, 1, fp);
fclose(fp); fclose(fp);
} }
SetBanner((u8 *)buf, size, title);
return new Banner((u8 *)buf, size, title);
} }

View File

@ -60,8 +60,9 @@ typedef struct
class Banner class Banner
{ {
public: public:
Banner(u8 *bnr, u32 bnr_size, u64 title = 0, bool custom = false); Banner();
~Banner(); void SetBanner(u8 *bnr, u32 bnr_size, u64 title = 0, bool custom = false);
void ClearBanner();
bool IsValid(); bool IsValid();
@ -69,7 +70,7 @@ class Banner
bool GetName(wchar_t *name, int language); bool GetName(wchar_t *name, int language);
u8 *GetFile(char *name, u32 *size); u8 *GetFile(char *name, u32 *size);
static Banner *GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false); void GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false);
u8 *GetBannerFile() { return opening; } u8 *GetBannerFile() { return opening; }
u32 GetBannerFileSize() { return opening_size; } u32 GetBannerFileSize() { return opening_size; }
protected: protected:
@ -81,5 +82,6 @@ class Banner
u16 *GetName(int language); u16 *GetName(int language);
static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language);
}; };
extern Banner CurrentBanner;
#endif //_BANNER_H_ #endif //_BANNER_H_

View File

@ -46,10 +46,6 @@
Channels ChannelHandle; Channels ChannelHandle;
Channels::Channels()
{
}
void Channels::Init(u32 channelType, string lang, bool reload) void Channels::Init(u32 channelType, string lang, bool reload)
{ {
if (reload) init = !reload; if (reload) init = !reload;
@ -65,8 +61,9 @@ void Channels::Init(u32 channelType, string lang, bool reload)
} }
} }
Channels::~Channels() void Channels::Cleanup()
{ {
this->channels.clear();
} }
u8 Channels::GetRequestedIOS(u64 title) u8 Channels::GetRequestedIOS(u64 title)
@ -156,16 +153,16 @@ bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootconten
return ret; return ret;
} }
Banner * Channels::GetBanner(u64 title, bool imetOnly) void Channels::GetBanner(u64 title, bool imetOnly)
{ {
char app[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char app[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
u32 cid; u32 cid;
if (!GetAppNameFromTmd(title, app, false, &cid)) if (!GetAppNameFromTmd(title, app, false, &cid))
{ {
gprintf("No title found\n"); gprintf("No title found\n");
return NULL; return;
} }
return Banner::GetBanner(title, app, true, imetOnly); CurrentBanner.GetBanner(title, app, true, imetOnly);
} }
bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language) bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language)
@ -175,12 +172,11 @@ bool Channels::GetChannelNameFromApp(u64 title, wchar_t* name, int language)
if (language > CONF_LANG_KOREAN) if (language > CONF_LANG_KOREAN)
language = CONF_LANG_ENGLISH; language = CONF_LANG_ENGLISH;
Banner *banner = GetBanner(title, true); GetBanner(title, true);
if (banner != NULL) if(CurrentBanner.IsValid())
{ {
ret = banner->GetName(name, language); ret = CurrentBanner.GetName(name, language);
delete banner; CurrentBanner.ClearBanner();
banner = NULL;
} }
return ret; return ret;

View File

@ -49,10 +49,8 @@ typedef struct
class Channels class Channels
{ {
public: public:
Channels();
~Channels();
void Init(u32 channelType, string lang, bool reload = false); void Init(u32 channelType, string lang, bool reload = false);
void Cleanup();
u32 Load(u64 title); u32 Load(u64 title);
u8 GetRequestedIOS(u64 title); u8 GetRequestedIOS(u64 title);
@ -63,7 +61,7 @@ public:
u64 GetTitle(int index); u64 GetTitle(int index);
Channel *GetChannel(int index); Channel *GetChannel(int index);
static Banner * GetBanner(u64 title, bool imetOnly = false); void GetBanner(u64 title, bool imetOnly = false);
private: private:
bool init; bool init;
u32 channelType; u32 channelType;
@ -71,10 +69,10 @@ private:
vector<Channel> channels; vector<Channel> channels;
static int GetLanguage(const char *lang); int GetLanguage(const char *lang);
u64* GetChannelList(u32* count); u64* GetChannelList(u32* count);
static bool GetAppNameFromTmd(u64 title, char* app, bool dol = false, u32* bootcontent = NULL); bool GetAppNameFromTmd(u64 title, char* app, bool dol = false, u32* bootcontent = NULL);
static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); bool GetChannelNameFromApp(u64 title, wchar_t* name, int language);
void Search(u32 channelType, string lang); void Search(u32 channelType, string lang);
}; };

View File

@ -57,6 +57,8 @@ bool tbdec = false;
bool configloaded = false; bool configloaded = false;
bool emu_enabled = false; bool emu_enabled = false;
Nand NandHandle;
static NandDevice NandDeviceList[] = static NandDevice NandDeviceList[] =
{ {
{ "Disable", 0, 0x00, 0x00 }, { "Disable", 0, 0x00, 0x00 },
@ -64,22 +66,17 @@ static NandDevice NandDeviceList[] =
{ "USB 2.0 Mass Storage Device", 2, 0xF2, 0xF3 }, { "USB 2.0 Mass Storage Device", 2, 0xF2, 0xF3 },
}; };
Nand * Nand::instance = NULL; void Nand::Init()
Nand * Nand::Instance()
{ {
if(instance == NULL) MountedDevice = 0;
instance = new Nand(); EmuDevice = REAL_NAND;
return instance; Disabled = true;
Partition = 0;
FullMode = 0x100;
memset(NandPath, 0, sizeof(NandPath));
} }
void Nand::DestroyInstance() void Nand::SetPaths(string path, u32 partition, bool disable)
{
if(instance) delete instance;
instance = NULL;
}
void Nand::Init(string path, u32 partition, bool disable)
{ {
EmuDevice = disable ? REAL_NAND : partition == 0 ? EMU_SD : EMU_USB; EmuDevice = disable ? REAL_NAND : partition == 0 ? EMU_SD : EMU_USB;
Partition = disable ? REAL_NAND : partition > 0 ? partition - 1 : partition; Partition = disable ? REAL_NAND : partition > 0 ? partition - 1 : partition;

View File

@ -54,11 +54,10 @@ using namespace std;
class Nand class Nand
{ {
public: public:
static Nand * Instance(); void Init();
static void DestroyInstance();
/* Prototypes */ /* Prototypes */
void Init(string path, u32 partition, bool disable = false); void SetPaths(string path, u32 partition, bool disable = false);
s32 Enable_Emu(); s32 Enable_Emu();
s32 Disable_Emu(); s32 Disable_Emu();
bool EmulationEnabled(void); bool EmulationEnabled(void);
@ -89,9 +88,6 @@ public:
void ResetCounters(void); void ResetCounters(void);
private: private:
Nand() : MountedDevice(0), EmuDevice(REAL_NAND), Disabled(true), Partition(0), FullMode(0x100), NandPath() {}
~Nand(void){}
/* Prototypes */ /* Prototypes */
s32 Nand_Mount(NandDevice *Device); s32 Nand_Mount(NandDevice *Device);
s32 Nand_Unmount(NandDevice *Device); s32 Nand_Unmount(NandDevice *Device);
@ -137,8 +133,7 @@ private:
char NandPath[32] ATTRIBUTE_ALIGN(32); char NandPath[32] ATTRIBUTE_ALIGN(32);
char cfgpath[1024]; char cfgpath[1024];
char settxtpath[1024]; char settxtpath[1024];
static Nand * instance;
}; };
extern Nand NandHandle;
#endif #endif

View File

@ -42,12 +42,9 @@ DeviceHandler DeviceHandle;
void DeviceHandler::Init() void DeviceHandler::Init()
{ {
sd = NULL; sd.Init();
gca = NULL; usb0.Init();
gcb = NULL; OGC_Device.Init();
usb0 = NULL;
usb1 = NULL;
OGC_Device = NULL;
} }
void DeviceHandler::MountAll() void DeviceHandler::MountAll()
@ -64,21 +61,12 @@ void DeviceHandler::UnMountAll()
for(u32 i = SD; i < MAXDEVICES; i++) for(u32 i = SD; i < MAXDEVICES; i++)
UnMount(i); UnMount(i);
if(sd)
delete sd;
if(usb0)
delete usb0;
if(usb1)
delete usb1;
sd = NULL;
usb0 = NULL;
usb1 = NULL;
USBStorage2_Deinit(); USBStorage2_Deinit();
USB_Deinitialize(); USB_Deinitialize();
SDHC_Close(); SDHC_Close();
sd.Cleanup();
usb0.Cleanup();
} }
bool DeviceHandler::Mount(int dev) bool DeviceHandler::Mount(int dev)
@ -95,14 +83,11 @@ bool DeviceHandler::Mount(int dev)
bool DeviceHandler::IsInserted(int dev) bool DeviceHandler::IsInserted(int dev)
{ {
if(dev == SD) if(dev == SD)
return SD_Inserted() && sd->IsMounted(0); return SD_Inserted() && sd.IsMounted(0);
else if(dev >= USB1 && dev <= USB8) else if(dev >= USB1 && dev <= USB8)
{ {
int portPart = PartitionToPortPartition(dev-USB1); int portPart = PartitionToPortPartition(dev-USB1);
PartitionHandle *usb = GetUSBHandleFromPartition(dev-USB1); return usb0.IsMounted(portPart);
if(usb)
return usb->IsMounted(portPart);
} }
return false; return false;
@ -112,7 +97,6 @@ void DeviceHandler::UnMount(int dev)
{ {
if(dev == SD) if(dev == SD)
UnMountSD(); UnMountSD();
else if(dev >= USB1 && dev <= USB8) else if(dev >= USB1 && dev <= USB8)
UnMountUSB(dev-USB1); UnMountUSB(dev-USB1);
} }
@ -132,7 +116,7 @@ void DeviceHandler::SetModes()
bool DeviceHandler::MountSD() bool DeviceHandler::MountSD()
{ {
if(!sd) if(!sd.IsInserted() || !sd.IsMounted(0))
{ {
if(CurrentIOS.Type == IOS_TYPE_HERMES) if(CurrentIOS.Type == IOS_TYPE_HERMES)
{ /* Slowass Hermes SDHC Module */ { /* Slowass Hermes SDHC Module */
@ -143,26 +127,22 @@ bool DeviceHandler::MountSD()
usleep(1000); usleep(1000);
} }
} }
sd = new PartitionHandle(&__io_sdhc); sd.SetDevice(&__io_sdhc);
//! Mount only one SD Partition
return sd.Mount(0, DeviceName[SD], true); /* Force FAT */
} }
//! Mount only one SD Partition return true;
return sd->Mount(0, DeviceName[SD], true); /* Force FAT */
} }
bool DeviceHandler::MountUSB(int pos) bool DeviceHandler::MountUSB(int pos)
{ {
if(!usb0 && !usb1)
return false;
if(pos >= GetUSBPartitionCount()) if(pos >= GetUSBPartitionCount())
return false; return false;
int portPart = PartitionToPortPartition(pos); int portPart = PartitionToPortPartition(pos);
if(PartitionToUSBPort(pos) == 0 && usb0) if(PartitionToUSBPort(pos) == 0)
return usb0->Mount(portPart, DeviceName[USB1+pos]); return usb0.Mount(portPart, DeviceName[USB1+pos]);
else if(usb1)
return usb1->Mount(portPart, DeviceName[USB1+pos]);
return false; return false;
} }
@ -174,8 +154,8 @@ bool DeviceHandler::MountAllUSB()
/* Wait for our slowass HDD */ /* Wait for our slowass HDD */
WaitForDevice(GetUSB0Interface()); WaitForDevice(GetUSB0Interface());
/* Get Partitions and Mount them */ /* Get Partitions and Mount them */
if(!usb0) if(!usb0.IsInserted() || !usb0.IsMounted(0))
usb0 = new PartitionHandle(GetUSB0Interface()); usb0.SetDevice(GetUSB0Interface());
bool result = false; bool result = false;
int partCount = GetUSBPartitionCount(); int partCount = GetUSBPartitionCount();
for(int i = 0; i < partCount; i++) for(int i = 0; i < partCount; i++)
@ -184,7 +164,7 @@ bool DeviceHandler::MountAllUSB()
result = true; result = true;
} }
if(!result) if(!result)
result = usb0->Mount(0, DeviceName[USB1], true); /* Force FAT */ result = usb0.Mount(0, DeviceName[USB1], true); /* Force FAT */
if(result && usb_libogc_mode) if(result && usb_libogc_mode)
CreateUSBKeepAliveThread(); CreateUSBKeepAliveThread();
return result; return result;
@ -197,10 +177,10 @@ void DeviceHandler::UnMountUSB(int pos)
int portPart = PartitionToPortPartition(pos); int portPart = PartitionToPortPartition(pos);
if(PartitionToUSBPort(pos) == 0 && usb0) if(PartitionToUSBPort(pos) == 0)
return usb0->UnMount(portPart); return usb0.UnMount(portPart);
else if(usb1) //else if(usb1)
return usb1->UnMount(portPart); // return usb1->UnMount(portPart);
} }
void DeviceHandler::UnMountAllUSB() void DeviceHandler::UnMountAllUSB()
@ -209,11 +189,6 @@ void DeviceHandler::UnMountAllUSB()
for(int i = 0; i < partCount; i++) for(int i = 0; i < partCount; i++)
UnMountUSB(i); UnMountUSB(i);
delete usb0;
usb0 = NULL;
delete usb1;
usb1 = NULL;
} }
int DeviceHandler::PathToDriveType(const char *path) int DeviceHandler::PathToDriveType(const char *path)
@ -232,21 +207,21 @@ int DeviceHandler::PathToDriveType(const char *path)
const char *DeviceHandler::GetFSName(int dev) const char *DeviceHandler::GetFSName(int dev)
{ {
if(dev == SD && sd) if(dev == SD)
return sd->GetFSName(0); return sd.GetFSName(0);
else if(dev >= USB1 && dev <= USB8) else if(dev >= USB1 && dev <= USB8)
{ {
int partCount0 = 0; int partCount0 = 0;
int partCount1 = 0; //int partCount1 = 0;
if(usb0) //if(usb0)
partCount0 += usb0->GetPartitionCount(); partCount0 += usb0.GetPartitionCount();
if(usb1) //if(usb1)
partCount1 += usb1->GetPartitionCount(); // partCount1 += usb1->GetPartitionCount();
if(dev-USB1 < partCount0 && usb0) if(dev-USB1 < partCount0)
return usb0->GetFSName(dev-USB1); return usb0.GetFSName(dev-USB1);
else if(usb1) //else if(usb1)
return usb1->GetFSName(dev-USB1-partCount0); // return usb1->GetFSName(dev-USB1-partCount0);
} }
return ""; return "";
@ -273,22 +248,21 @@ u16 DeviceHandler::GetUSBPartitionCount()
{ {
u16 partCount0 = 0; u16 partCount0 = 0;
u16 partCount1 = 0; u16 partCount1 = 0;
if(usb0) partCount0 = usb0.GetPartitionCount();
partCount0 = usb0->GetPartitionCount(); //if(usb1)
if(usb1) // partCount1 = usb1->GetPartitionCount();
partCount1 = usb1->GetPartitionCount();
return partCount0+partCount1; return partCount0+partCount1;
} }
wbfs_t * DeviceHandler::GetWbfsHandle(int dev) wbfs_t * DeviceHandler::GetWbfsHandle(int dev)
{ {
if(dev == SD && sd) if(dev == SD)
return sd->GetWbfsHandle(0); return sd.GetWbfsHandle(0);
else if(dev >= USB1 && dev <= USB8 && usb0) else if(dev >= USB1 && dev <= USB8)
return usb0->GetWbfsHandle(dev-USB1); return usb0.GetWbfsHandle(dev-USB1);
else if(dev >= USB1 && dev <= USB8 && usb1) //else if(dev >= USB1 && dev <= USB8 && usb1)
return usb1->GetWbfsHandle(dev-USB1); // return usb1->GetWbfsHandle(dev-USB1);
return NULL; return NULL;
} }
@ -299,11 +273,11 @@ s32 DeviceHandler::OpenWBFS(int dev)
char *partition = (char *)DeviceName[dev]; char *partition = (char *)DeviceName[dev];
if(dev == SD && IsInserted(dev)) if(dev == SD && IsInserted(dev))
part_lba = sd->GetLBAStart(dev); part_lba = sd.GetLBAStart(dev);
else if(dev >= USB1 && dev <= USB8 && IsInserted(dev)) else if(dev >= USB1 && dev <= USB8 && IsInserted(dev))
{ {
part_idx = dev; part_idx = dev;
part_lba = usb0->GetLBAStart(dev - USB1); part_lba = usb0.GetLBAStart(dev - USB1);
} }
else else
return -1; return -1;
@ -314,10 +288,9 @@ s32 DeviceHandler::OpenWBFS(int dev)
int DeviceHandler::PartitionToUSBPort(int part) int DeviceHandler::PartitionToUSBPort(int part)
{ {
u16 partCount0 = 0; u16 partCount0 = 0;
if(usb0) //if(usb0)
partCount0 = usb0->GetPartitionCount(); partCount0 = usb0.GetPartitionCount();
if(part >= partCount0)
if(!usb0 || part >= partCount0)
return 1; return 1;
else else
return 0; return 0;
@ -326,15 +299,15 @@ int DeviceHandler::PartitionToUSBPort(int part)
int DeviceHandler::PartitionToPortPartition(int part) int DeviceHandler::PartitionToPortPartition(int part)
{ {
u16 partCount0 = 0; u16 partCount0 = 0;
if(usb0) //if(usb0)
partCount0 = usb0->GetPartitionCount(); partCount0 = usb0.GetPartitionCount();
if(!usb0 || part >= partCount0) if(part >= partCount0)
return part-partCount0; return part-partCount0;
else else
return part; return part;
} }
/*
PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part) PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part)
{ {
if(PartitionToUSBPort(part) == 0) if(PartitionToUSBPort(part) == 0)
@ -342,7 +315,7 @@ PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part)
else else
return usb1; return usb1;
} }
*/
void DeviceHandler::WaitForDevice(const DISC_INTERFACE *Handle) void DeviceHandler::WaitForDevice(const DISC_INTERFACE *Handle)
{ {
if(Handle == NULL) if(Handle == NULL)
@ -363,15 +336,15 @@ bool DeviceHandler::MountDevolution(int CurrentPartition)
/* We need to wait for the device to get ready for a remount */ /* We need to wait for the device to get ready for a remount */
WaitForDevice(handle); WaitForDevice(handle);
/* Only mount the partition we need */ /* Only mount the partition we need */
OGC_Device = new PartitionHandle(handle); OGC_Device.SetDevice(handle);
return OGC_Device->Mount(NewPartition, DeviceName[CurrentPartition], true); return OGC_Device.Mount(NewPartition, DeviceName[CurrentPartition], true);
} }
void DeviceHandler::UnMountDevolution(int CurrentPartition) void DeviceHandler::UnMountDevolution(int CurrentPartition)
{ {
int NewPartition = (CurrentPartition == SD ? CurrentPartition : CurrentPartition - 1); int NewPartition = (CurrentPartition == SD ? CurrentPartition : CurrentPartition - 1);
OGC_Device->UnMount(NewPartition); OGC_Device.UnMount(NewPartition);
delete OGC_Device; OGC_Device.Cleanup();
} }
bool DeviceHandler::UsablePartitionMounted() bool DeviceHandler::UsablePartitionMounted()

View File

@ -77,21 +77,16 @@ public:
bool MountAllUSB(); bool MountAllUSB();
bool MountUSBPort1(); bool MountUSBPort1();
bool SD_Inserted() { if(sd) return sd->IsInserted(); return false; } bool SD_Inserted() { return sd.IsInserted(); }
bool USB0_Inserted() { if(usb0) return usb0->IsInserted(); return false; } bool USB0_Inserted() { return usb0.IsInserted(); }
bool USB1_Inserted() { if(usb1) return usb1->IsInserted(); return false; }
bool UsablePartitionMounted(); bool UsablePartitionMounted();
bool PartitionUsableForNandEmu(int Partition); bool PartitionUsableForNandEmu(int Partition);
void WaitForDevice(const DISC_INTERFACE *Handle); void WaitForDevice(const DISC_INTERFACE *Handle);
void UnMountSD() { if(sd) delete sd; sd = NULL; } void UnMountSD() { sd.UnMountAll(); }
void UnMountUSB(int pos); void UnMountUSB(int pos);
void UnMountAllUSB(); void UnMountAllUSB();
PartitionHandle * GetSDHandle() const { return sd; }
PartitionHandle * GetUSB0Handle() const { return usb0; }
PartitionHandle * GetUSB1Handle() const { return usb1; }
PartitionHandle * GetUSBHandleFromPartition(int part); PartitionHandle * GetUSBHandleFromPartition(int part);
const DISC_INTERFACE *GetUSB0Interface() { return &__io_usbstorage2_port0; } const DISC_INTERFACE *GetUSB0Interface() { return &__io_usbstorage2_port0; }
const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; } const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; }
@ -112,13 +107,10 @@ public:
private: private:
bool MountUSB(int part); bool MountUSB(int part);
PartitionHandle *sd; PartitionHandle sd;
PartitionHandle *gca; PartitionHandle usb0;
PartitionHandle *gcb;
PartitionHandle *usb0;
PartitionHandle *usb1;
/* Special Devolution Stuff */ /* Special Devolution Stuff */
PartitionHandle *OGC_Device; PartitionHandle OGC_Device;
}; };
extern DeviceHandler DeviceHandle; extern DeviceHandler DeviceHandle;

View File

@ -74,30 +74,38 @@ static inline const char *PartFromType(int type)
} }
} }
PartitionHandle::PartitionHandle(const DISC_INTERFACE *discio) void PartitionHandle::Init()
: interface(discio)
{ {
interface = NULL;
}
void PartitionHandle::SetDevice(const DISC_INTERFACE *discio)
{
Cleanup();
interface = discio;
// Sanity check // Sanity check
if (!interface) if(!interface)
return; return;
// Start the device and check that it is inserted // Start the device and check that it is inserted
if (!interface->startup()) if(!interface->startup())
return; return;
if (!interface->isInserted()) if(!interface->isInserted())
return; return;
FindPartitions(); FindPartitions();
} }
PartitionHandle::~PartitionHandle() void PartitionHandle::Cleanup()
{ {
UnMountAll(); UnMountAll();
if(interface != NULL)
//shutdown device
if(!neek2o())
interface->shutdown(); interface->shutdown();
interface = NULL;
PartitionList.clear();
MountNameList.clear();
} }
bool PartitionHandle::IsMounted(int pos) bool PartitionHandle::IsMounted(int pos)

View File

@ -117,10 +117,11 @@ typedef struct _PartitionFS {
class PartitionHandle class PartitionHandle
{ {
public: public:
//! Constructor reads the MBR and all EBRs and lists up the Partitions void Init();
PartitionHandle(const DISC_INTERFACE *discio); //! Read the MBR and all EBRs and lists up the Partitions
//! Destructor unmounts drives void SetDevice(const DISC_INTERFACE *discio);
~PartitionHandle(); //! Unmount drives
void Cleanup();
//! Is Drive inserted //! Is Drive inserted
bool IsInserted() { if(!interface) return false; else return interface->isInserted(); }; bool IsInserted() { if(!interface) return false; else return interface->isInserted(); };
//! Is the partition Mounted //! Is the partition Mounted

View File

@ -698,13 +698,12 @@ void decodeJpeg(const u8* data, int size, VideoFrame& dest)
//convert format so jpeglib understands it... //convert format so jpeglib understands it...
int start, end; int start, end;
int newSize = countRequiredSize(data, size, start, end); int newSize = countRequiredSize(data, size, start, end);
u8* buff = new u8[newSize]; u8 *buff = (u8*)MEM2_alloc(newSize);
convertToRealJpeg(buff, data, size, start, end); convertToRealJpeg(buff, data, size, start, end);
//...and feed it to jpeglib //...and feed it to jpeglib
decodeRealJpeg(buff, newSize, dest); decodeRealJpeg(buff, newSize, dest);
MEM2_free(buff);
delete [] buff;
} }
extern "C" extern "C"

View File

@ -83,10 +83,10 @@ bool loadIOS(int ios, bool MountDevices)
WDVD_Close(); WDVD_Close();
Close_Inputs(); Close_Inputs();
gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS); gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS);
Nand::Instance()->Patch_AHB(); //No AHBPROT for the next IOS NandHandle.Patch_AHB(); //No AHBPROT for the next IOS
ShutdownBeforeExit(); ShutdownBeforeExit();
ret = IOS_ReloadIOS(ios) == 0; ret = IOS_ReloadIOS(ios) == 0;
Nand::Instance()->Init_ISFS(); NandHandle.Init_ISFS();
gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched()); gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched());
WDVD_Init(); WDVD_Init();
} }

View File

@ -33,9 +33,9 @@ int main(int argc, char **argv)
gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV); gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV);
m_vid.init(); // Init video m_vid.init(); // Init video
Nand::Instance()->Init_ISFS(); //Just init ISFS, no patches yet
MEM_init(); //Inits both mem1lo and mem2 MEM_init(); //Inits both mem1lo and mem2
DeviceHandle.Init(); DeviceHandle.Init();
NandHandle.Init();
char *gameid = NULL; char *gameid = NULL;
bool Emulator_boot = false; bool Emulator_boot = false;
@ -62,7 +62,9 @@ int main(int argc, char **argv)
else if(argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL) else if(argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL)
Emulator_boot = true; Emulator_boot = true;
} }
// Load Custom IOS /* Init ISFS */
NandHandle.Init_ISFS();
/* Handle (c)IOS Loading */
if(neek2o() || Sys_DolphinMode()) if(neek2o() || Sys_DolphinMode())
{ {
iosOK = true; iosOK = true;

View File

@ -143,12 +143,13 @@ CMenu::CMenu()
m_wbf2_font = NULL; m_wbf2_font = NULL;
m_current_view = COVERFLOW_USB; m_current_view = COVERFLOW_USB;
m_Emulator_boot = false; m_Emulator_boot = false;
m_gameSound.SetVoice(1);
m_music_info = true; m_music_info = true;
} }
void CMenu::init() void CMenu::init()
{ {
SoundHandle.Init();
m_gameSound.SetVoice(1);
const char *drive = "empty"; const char *drive = "empty";
const char *check = "empty"; const char *check = "empty";
struct stat dummy; struct stat dummy;
@ -497,7 +498,7 @@ void CMenu::cleanup()
MusicPlayer.Cleanup(); MusicPlayer.Cleanup();
m_cameraSound.release(); m_cameraSound.release();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
SoundHandler::DestroyInstance(); SoundHandle.Cleanup();
soundDeinit(); soundDeinit();
m_vid.cleanup(); m_vid.cleanup();
@ -2138,12 +2139,12 @@ bool CMenu::_loadChannelList(void)
{ {
char basepath[64]; char basepath[64];
snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[currentPartition], emuPath.c_str()); snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[currentPartition], emuPath.c_str());
Nand::Instance()->PreNandCfg(basepath, m_cfg.getBool("NAND", "real_nand_miis", false), m_cfg.getBool("NAND", "real_nand_config", false)); NandHandle.PreNandCfg(basepath, m_cfg.getBool("NAND", "real_nand_miis", false), m_cfg.getBool("NAND", "real_nand_config", false));
first = false; first = false;
} }
string nandpath = sfmt("%s:%s/", DeviceName[currentPartition], emuPath.empty() ? "" : emuPath.c_str()); string nandpath = sfmt("%s:%s/", DeviceName[currentPartition], emuPath.empty() ? "" : emuPath.c_str());
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
if(!disable_emu) if(!disable_emu)
{ {
MusicPlayer.Stop(); MusicPlayer.Stop();
@ -2153,9 +2154,9 @@ bool CMenu::_loadChannelList(void)
DeviceHandle.UnMount(currentPartition); DeviceHandle.UnMount(currentPartition);
Nand::Instance()->Init(emuPath.c_str(), currentPartition, disable_emu); NandHandle.SetPaths(emuPath.c_str(), currentPartition, disable_emu);
if(Nand::Instance()->Enable_Emu() < 0) if(NandHandle.Enable_Emu() < 0)
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
gprintf("Using path: \"%s\" for NAND emulation\n", nandpath.c_str()); gprintf("Using path: \"%s\" for NAND emulation\n", nandpath.c_str());
} }
@ -2163,7 +2164,7 @@ bool CMenu::_loadChannelList(void)
if(!DeviceHandle.IsInserted(currentPartition)) if(!DeviceHandle.IsInserted(currentPartition))
DeviceHandle.Mount(currentPartition); DeviceHandle.Mount(currentPartition);
if(Nand::Instance()->EmulationEnabled() || disable_emu) if(NandHandle.EmulationEnabled() || disable_emu)
{ {
string cacheDir; string cacheDir;
if(!disable_emu) if(!disable_emu)
@ -2184,10 +2185,10 @@ bool CMenu::_loadList(void)
{ {
m_cf.clear(); m_cf.clear();
if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true)) if((m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true))
|| (m_current_view != COVERFLOW_CHANNEL && Nand::Instance()->EmulationEnabled())) || (m_current_view != COVERFLOW_CHANNEL && NandHandle.EmulationEnabled()))
{ {
MusicPlayer.Stop(); MusicPlayer.Stop();
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
_TempLoadIOS(IOS_TYPE_NORMAL_IOS); _TempLoadIOS(IOS_TYPE_NORMAL_IOS);
} }
gprintf("Switching Views\n"); gprintf("Switching Views\n");

View File

@ -76,7 +76,7 @@ void CMenu::_showConfig4(void)
wstringEx channelName = m_loc.getWString(m_curLanguage, "disabled", L"Disabled"); wstringEx channelName = m_loc.getWString(m_curLanguage, "disabled", L"Disabled");
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
ChannelHandle.Init(0, m_loc.getString(m_curLanguage, "gametdb_code", "EN"), true); ChannelHandle.Init(0, m_loc.getString(m_curLanguage, "gametdb_code", "EN"), true);
amountOfChannels = ChannelHandle.Count(); amountOfChannels = ChannelHandle.Count();
@ -146,7 +146,7 @@ int CMenu::_config4(void)
} }
} }
if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true) == false) if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && m_cfg.getBool("NAND", "disable", true) == false)
Nand::Instance()->Enable_Emu(); NandHandle.Enable_Emu();
_hideConfig4(); _hideConfig4();
return change; return change;
} }

View File

@ -427,7 +427,7 @@ s32 CMenu::_networkComplete(s32 ok, void *usrData)
int CMenu::_initNetwork() int CMenu::_initNetwork()
{ {
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
while (net_get_status() == -EBUSY || m_thrdNetwork) {}; // Async initialization may be busy, wait to see if it succeeds. while (net_get_status() == -EBUSY || m_thrdNetwork) {}; // Async initialization may be busy, wait to see if it succeeds.
if (m_networkInit) return 0; if (m_networkInit) return 0;
if (!_isNetworkAvailable()) return -2; if (!_isNetworkAvailable()) return -2;

View File

@ -247,24 +247,20 @@ static inline int loopNum(int i, int s)
} }
static void _extractBannerTitle(Banner *bnr, int language) static void _extractBannerTitle(int language)
{ {
if (bnr != NULL) memset(banner_title, 0, 84);
{ CurrentBanner.GetName(banner_title, language);
memset(banner_title, 0, 84);
bnr->GetName(banner_title, language);
}
} }
static Banner *_extractChannelBnr(const u64 chantitle) static void _extractChannelBnr(const u64 chantitle)
{ {
return ChannelHandle.GetBanner(chantitle); ChannelHandle.GetBanner(chantitle);
} }
static Banner *_extractBnr(dir_discHdr *hdr) static void _extractBnr(dir_discHdr *hdr)
{ {
u32 size = 0; u32 size = 0;
Banner *banner = NULL;
DeviceHandle.OpenWBFS(currentPartition); DeviceHandle.OpenWBFS(currentPartition);
wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) &hdr->id, (char *) hdr->path); wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) &hdr->id, (char *) hdr->path);
if(disc != NULL) if(disc != NULL)
@ -272,11 +268,10 @@ static Banner *_extractBnr(dir_discHdr *hdr)
void *bnr = NULL; void *bnr = NULL;
size = wbfs_extract_file(disc, (char *) "opening.bnr", &bnr); size = wbfs_extract_file(disc, (char *) "opening.bnr", &bnr);
if(size > 0) if(size > 0)
banner = new Banner((u8 *)bnr, size); CurrentBanner.SetBanner((u8*)bnr, size);
WBFS_CloseDisc(disc); WBFS_CloseDisc(disc);
} }
WBFS_Close(); WBFS_Close();
return banner;
} }
static int GetLanguage(const char *lang) static int GetLanguage(const char *lang)
@ -613,22 +608,22 @@ void CMenu::_game(bool launch)
_showWaitMessage(); _showWaitMessage();
exitHandler(PRIILOADER_DEF); //Making wiiflow ready to boot something exitHandler(PRIILOADER_DEF); //Making wiiflow ready to boot something
CurrentBanner.ClearBanner();
// Get banner_title
if(hdr->type == TYPE_CHANNEL)
_extractChannelBnr(chantitle);
else if(hdr->type == TYPE_WII_GAME)
_extractBnr(hdr);
if(CurrentBanner.IsValid())
{
_extractBannerTitle(GetLanguage(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str()));
CurrentBanner.ClearBanner();
}
if(hdr->type != TYPE_HOMEBREW && hdr->type != TYPE_PLUGIN) if(hdr->type != TYPE_HOMEBREW && hdr->type != TYPE_PLUGIN)
{ {
// Get banner_title
Banner *banner = hdr->type == TYPE_CHANNEL ? _extractChannelBnr(chantitle) : (hdr->type == TYPE_WII_GAME ? _extractBnr(hdr) : NULL);
if(banner != NULL)
{
if(banner->IsValid())
_extractBannerTitle(banner, GetLanguage(m_loc.getString(m_curLanguage, "gametdb_code", "EN").c_str()));
delete banner;
}
banner = NULL;
if(Playlog_Update((char *)hdr->id, banner_title) < 0) if(Playlog_Update((char *)hdr->id, banner_title) < 0)
Playlog_Delete(); Playlog_Delete();
} }
gprintf("Launching game %s\n", (char *)hdr->id); gprintf("Launching game %s\n", (char *)hdr->id);
_launch(hdr); _launch(hdr);
@ -777,7 +772,7 @@ void CMenu::directlaunch(const char *GameID)
void CMenu::_launch(dir_discHdr *hdr) void CMenu::_launch(dir_discHdr *hdr)
{ {
/* No need to do that separate */ /* No need to do that separate */
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
/* Lets boot that shit */ /* Lets boot that shit */
if(hdr->type == TYPE_WII_GAME) if(hdr->type == TYPE_WII_GAME)
_launchGame(hdr, false); _launchGame(hdr, false);
@ -1097,11 +1092,11 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
while(1); while(1);
} }
DeviceHandle.UnMount(emuPartition); DeviceHandle.UnMount(emuPartition);
Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); NandHandle.SetPaths(emuPath.c_str(), emuPartition, false);
Nand::Instance()->Enable_Emu(); NandHandle.Enable_Emu();
} }
gameIOS = ChannelHandle.GetRequestedIOS(gameTitle); gameIOS = ChannelHandle.GetRequestedIOS(gameTitle);
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
if(_loadIOS(gameIOS, WII_Launch ? gameIOS : userIOS, id) == LOAD_IOS_FAILED) if(_loadIOS(gameIOS, WII_Launch ? gameIOS : userIOS, id) == LOAD_IOS_FAILED)
Sys_Exit(); Sys_Exit();
if((CurrentIOS.Type == IOS_TYPE_D2X || neek2o()) && rtrn != NULL && strlen(rtrn) == 4) if((CurrentIOS.Type == IOS_TYPE_D2X || neek2o()) && rtrn != NULL && strlen(rtrn) == 4)
@ -1128,14 +1123,14 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
{ {
if(NAND_Emu) if(NAND_Emu)
{ {
Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); NandHandle.SetPaths(emuPath.c_str(), emuPartition, false);
if(emulate_mode == 1) if(emulate_mode == 1)
Nand::Instance()->Set_FullMode(true); NandHandle.Set_FullMode(true);
else else
Nand::Instance()->Set_FullMode(false); NandHandle.Set_FullMode(false);
if(Nand::Instance()->Enable_Emu() < 0) if(NandHandle.Enable_Emu() < 0)
{ {
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
error(_t("errgame5", L"Enabling emu failed!")); error(_t("errgame5", L"Enabling emu failed!"));
Sys_Exit(); Sys_Exit();
} }
@ -1272,8 +1267,8 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
else else
{ {
emuPartition = _FindEmuPart(&emuPath, 1, true); emuPartition = _FindEmuPart(&emuPath, 1, true);
Nand::Instance()->CreatePath("%s:/wiiflow", DeviceName[emuPartition]); NandHandle.CreatePath("%s:/wiiflow", DeviceName[emuPartition]);
Nand::Instance()->CreatePath("%s:/wiiflow/nandemu", DeviceName[emuPartition]); NandHandle.CreatePath("%s:/wiiflow/nandemu", DeviceName[emuPartition]);
} }
} }
@ -1291,14 +1286,14 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
m_forceext = false; m_forceext = false;
_hideWaitMessage(); _hideWaitMessage();
if(!_AutoExtractSave(id)) if(!_AutoExtractSave(id))
Nand::Instance()->CreateTitleTMD(basepath, hdr); NandHandle.CreateTitleTMD(basepath, hdr);
_showWaitMessage(); _showWaitMessage();
} }
} }
if(emulate_mode > 2) if(emulate_mode > 2)
{ {
Nand::Instance()->CreateConfig(basepath); NandHandle.CreateConfig(basepath);
Nand::Instance()->Do_Region_Change(id); NandHandle.Do_Region_Change(id);
} }
} }
@ -1375,18 +1370,18 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
} }
if(emulate_mode && !neek2o() && CurrentIOS.Type == IOS_TYPE_D2X) if(emulate_mode && !neek2o() && CurrentIOS.Type == IOS_TYPE_D2X)
{ {
Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); NandHandle.SetPaths(emuPath.c_str(), emuPartition, false);
DeviceHandle.UnMount(emuPartition); DeviceHandle.UnMount(emuPartition);
if(emulate_mode == 3) if(emulate_mode == 3)
Nand::Instance()->Set_RCMode(true); NandHandle.Set_RCMode(true);
else if(emulate_mode == 4) else if(emulate_mode == 4)
Nand::Instance()->Set_FullMode(true); NandHandle.Set_FullMode(true);
else else
Nand::Instance()->Set_FullMode(false); NandHandle.Set_FullMode(false);
if(Nand::Instance()->Enable_Emu() < 0) if(NandHandle.Enable_Emu() < 0)
{ {
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
error(_t("errgame6", L"Enabling emu after reload failed!")); error(_t("errgame6", L"Enabling emu after reload failed!"));
Sys_Exit(); Sys_Exit();
} }
@ -1509,9 +1504,9 @@ SmartBuf gameSoundThreadStack;
u32 gameSoundThreadStackSize = (u32)32768; u32 gameSoundThreadStackSize = (u32)32768;
void CMenu::_gameSoundThread(CMenu *m) void CMenu::_gameSoundThread(CMenu *m)
{ {
CurrentBanner.ClearBanner();
m->m_gameSoundHdr = m->m_cf.getHdr(); m->m_gameSoundHdr = m->m_cf.getHdr();
m->m_gamesound_changed = false; m->m_gamesound_changed = false;
if(m->m_cf.getHdr()->type == TYPE_PLUGIN) if(m->m_cf.getHdr()->type == TYPE_PLUGIN)
{ {
m_banner.DeleteBanner(); m_banner.DeleteBanner();
@ -1529,7 +1524,8 @@ void CMenu::_gameSoundThread(CMenu *m)
u32 cached_bnr_size = 0; u32 cached_bnr_size = 0;
char cached_banner[256]; char cached_banner[256];
snprintf(cached_banner, sizeof(cached_banner), "%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), m->m_cf.getHdr()->id); cached_banner[255] = '\0';
strncpy(cached_banner, fmt("%s/%.6s.bnr", m->m_bnrCacheDir.c_str(), m->m_cf.getHdr()->id), 255);
FILE *fp = fopen(cached_banner, "rb"); FILE *fp = fopen(cached_banner, "rb");
if(fp) if(fp)
{ {
@ -1537,7 +1533,7 @@ void CMenu::_gameSoundThread(CMenu *m)
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
cached_bnr_size = ftell(fp); cached_bnr_size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
cached_bnr_file = (u8*)malloc(cached_bnr_size); cached_bnr_file = (u8*)MEM2_alloc(cached_bnr_size);
if(cached_bnr_file == NULL) if(cached_bnr_file == NULL)
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
@ -1551,25 +1547,13 @@ void CMenu::_gameSoundThread(CMenu *m)
else else
{ {
char custom_banner[256]; char custom_banner[256];
snprintf(custom_banner, sizeof(custom_banner), "%s/%.6s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id); custom_banner[255] = '\0';
strncpy(custom_banner, fmt("%s/%.6s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id), 255);
FILE *fp = fopen(custom_banner, "rb"); FILE *fp = fopen(custom_banner, "rb");
if(!fp) if(!fp)
{ {
snprintf(custom_banner, sizeof(custom_banner), "%s/%.3s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id); strncpy(custom_banner, fmt("%s/%.3s.bnr", m->m_customBnrDir.c_str(), m->m_cf.getHdr()->id), 255);
fp = fopen(custom_banner, "rb"); fp = fopen(custom_banner, "rb");
if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME)
{
GC_Disc disc;
disc.init(m->m_cf.getHdr()->path);
u8 *opening_bnr = disc.GetGameCubeBanner();
if(opening_bnr != NULL)
m_banner.CreateGCBanner(opening_bnr, m->m_wbf1_font, m->m_wbf2_font, m->m_cf.getHdr()->title);
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL;
disc.clear();
return;
}
} }
if(fp) if(fp)
{ {
@ -1577,7 +1561,7 @@ void CMenu::_gameSoundThread(CMenu *m)
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
custom_bnr_size = ftell(fp); custom_bnr_size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
custom_bnr_file = (u8*)malloc(custom_bnr_size); custom_bnr_file = (u8*)MEM2_alloc(custom_bnr_size);
if(custom_bnr_file == NULL) if(custom_bnr_file == NULL)
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
@ -1588,34 +1572,50 @@ void CMenu::_gameSoundThread(CMenu *m)
fread(custom_bnr_file, 1, custom_bnr_size, fp); fread(custom_bnr_file, 1, custom_bnr_size, fp);
fclose(fp); fclose(fp);
} }
if(!fp && m->m_cf.getHdr()->type == TYPE_GC_GAME)
{
GC_Disc disc;
disc.init(m->m_cf.getHdr()->path);
u8 *opening_bnr = disc.GetGameCubeBanner();
if(opening_bnr != NULL)
m_banner.CreateGCBanner(opening_bnr, m->m_wbf1_font, m->m_wbf2_font, m->m_cf.getHdr()->title);
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL;
disc.clear();
return;
}
} }
u32 sndSize = 0; u32 sndSize = 0;
u8 *soundBin = NULL; u8 *soundBin = NULL;
if(cached)
Banner *banner = cached ? new Banner(cached_bnr_file, cached_bnr_size) : CurrentBanner.SetBanner(cached_bnr_file, cached_bnr_size);
(custom ? new Banner((u8 *)custom_bnr_file, custom_bnr_size, 0, true) : else if(custom)
(m->m_gameSoundHdr->type == TYPE_WII_GAME ? _extractBnr(m->m_gameSoundHdr) : (m->m_gameSoundHdr->type == TYPE_CHANNEL ? CurrentBanner.SetBanner(custom_bnr_file, custom_bnr_size, 0, true);
_extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL))); else if(m->m_gameSoundHdr->type == TYPE_WII_GAME)
if(banner != NULL && banner->IsValid()) _extractBnr(m->m_gameSoundHdr);
{ else if(m->m_gameSoundHdr->type == TYPE_CHANNEL)
m_banner.LoadBanner(banner, m->m_wbf1_font, m->m_wbf2_font); _extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],
soundBin = banner->GetFile((char *)"sound.bin", &sndSize); m->m_gameSoundHdr->settings[1]));
} if(!CurrentBanner.IsValid())
else
{ {
m->m_gameSound.FreeMemory(); m->m_gameSound.FreeMemory();
m_banner.DeleteBanner(); m_banner.DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
delete banner; CurrentBanner.ClearBanner();
return; return;
} }
if(!custom && !cached) if(!custom && !cached && CurrentBanner.GetBannerFileSize() > 0)
{ {
FILE *fp = fopen(cached_banner, "wb"); FILE *fp = fopen(cached_banner, "wb");
fwrite(banner->GetBannerFile(), 1, banner->GetBannerFileSize(), fp); fwrite(CurrentBanner.GetBannerFile(), 1, CurrentBanner.GetBannerFileSize(), fp);
fclose(fp); fclose(fp);
} }
delete banner; m_banner.LoadBanner(m->m_wbf1_font, m->m_wbf2_font);
soundBin = CurrentBanner.GetFile((char *)"sound.bin", &sndSize);
CurrentBanner.ClearBanner();
if(soundBin != NULL) if(soundBin != NULL)
{ {
if(memcmp(&((IMD5Header *)soundBin)->fcc, "IMD5", 4) == 0) if(memcmp(&((IMD5Header *)soundBin)->fcc, "IMD5", 4) == 0)

View File

@ -153,7 +153,7 @@ void CMenu::_showMain(void)
case COVERFLOW_CHANNEL: case COVERFLOW_CHANNEL:
if(!m_cfg.getBool("NAND", "disable", true)) if(!m_cfg.getBool("NAND", "disable", true))
{ {
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
DeviceHandle.MountAll(); DeviceHandle.MountAll();
_hideMain(); _hideMain();
if(!_AutoCreateNand()) if(!_AutoCreateNand())
@ -176,7 +176,7 @@ void CMenu::_showMain(void)
} }
} }
else if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool("NAND", "disable", true)) else if(!neek2o() && m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool("NAND", "disable", true))
Nand::Instance()->Enable_Emu(); NandHandle.Enable_Emu();
} }
void CMenu::LoadView(void) void CMenu::LoadView(void)
@ -415,7 +415,7 @@ int CMenu::main(void)
_showWaitMessage(); _showWaitMessage();
m_gameSound.Stop(); m_gameSound.Stop();
CheckGameSoundThread(); CheckGameSoundThread();
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
/* Create Fake Header */ /* Create Fake Header */
dir_discHdr hdr; dir_discHdr hdr;
memset(&hdr, 0, sizeof(dir_discHdr)); memset(&hdr, 0, sizeof(dir_discHdr));
@ -647,7 +647,7 @@ int CMenu::main(void)
if(CurrentIOS.Revision > 6 && CurrentIOS.Type == IOS_TYPE_D2X) if(CurrentIOS.Revision > 6 && CurrentIOS.Type == IOS_TYPE_D2X)
isD2XnewerThanV6 = true; isD2XnewerThanV6 = true;
if(m_current_view == COVERFLOW_CHANNEL && m_cfg.getInt("NAND", "emulation", 0)) if(m_current_view == COVERFLOW_CHANNEL && m_cfg.getInt("NAND", "emulation", 0))
Nand::Instance()->Enable_Emu(); NandHandle.Enable_Emu();
u8 limiter = 0; u8 limiter = 0;
currentPartition = loopNum(currentPartition + 1, (int)USB8); currentPartition = loopNum(currentPartition + 1, (int)USB8);
while(!DeviceHandle.IsInserted(currentPartition) || while(!DeviceHandle.IsInserted(currentPartition) ||

View File

@ -93,7 +93,7 @@ bool CMenu::_TestEmuNand(int epart, const char *path, bool indept)
int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid) int CMenu::_FindEmuPart(string *emuPath, int part, bool searchvalid)
{ {
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
int emuPartition = -1; int emuPartition = -1;
string tmpPath; string tmpPath;
@ -199,7 +199,7 @@ void CMenu::_enableNandEmu(bool fromconfig)
if(CurrentIOS.Revision > 6 && CurrentIOS.Type == IOS_TYPE_D2X) if(CurrentIOS.Revision > 6 && CurrentIOS.Type == IOS_TYPE_D2X)
isD2XnewerThanV6 = true; isD2XnewerThanV6 = true;
if(m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool("NAND", "disable", true) && !neek2o() && !m_tempView) if(m_current_view == COVERFLOW_CHANNEL && !m_cfg.getBool("NAND", "disable", true) && !neek2o() && !m_tempView)
Nand::Instance()->Enable_Emu(); NandHandle.Enable_Emu();
u8 limiter = 0; u8 limiter = 0;
s8 direction = m_btnMgr.selected(m_configBtnPartitionP) ? 1 : -1; s8 direction = m_btnMgr.selected(m_configBtnPartitionP) ? 1 : -1;
if (!fromconfig) if (!fromconfig)
@ -548,14 +548,14 @@ int CMenu::_AutoExtractSave(string gameId)
{ {
char basepath[MAX_FAT_PATH]; char basepath[MAX_FAT_PATH];
snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[emuPartition], emuPath.c_str()); snprintf(basepath, sizeof(basepath), "%s:%s", DeviceName[emuPartition], emuPath.c_str());
Nand::Instance()->CreatePath("%s/import", basepath); NandHandle.CreatePath("%s/import", basepath);
Nand::Instance()->CreatePath("%s/meta", basepath); NandHandle.CreatePath("%s/meta", basepath);
Nand::Instance()->CreatePath("%s/shared1", basepath); NandHandle.CreatePath("%s/shared1", basepath);
Nand::Instance()->CreatePath("%s/shared2", basepath); NandHandle.CreatePath("%s/shared2", basepath);
Nand::Instance()->CreatePath("%s/sys", basepath); NandHandle.CreatePath("%s/sys", basepath);
Nand::Instance()->CreatePath("%s/title", basepath); NandHandle.CreatePath("%s/title", basepath);
Nand::Instance()->CreatePath("%s/ticket", basepath); NandHandle.CreatePath("%s/ticket", basepath);
Nand::Instance()->CreatePath("%s/tmp", basepath); NandHandle.CreatePath("%s/tmp", basepath);
_hideNandEmu(); _hideNandEmu();
return 0; return 0;
} }
@ -722,11 +722,11 @@ int CMenu::_NandFlasher(void *obj)
snprintf(source, sizeof(source), "%s:%s/title/00010004/%08x", DeviceName[emuPartition], emuPath.c_str(), flashID); snprintf(source, sizeof(source), "%s:%s/title/00010004/%08x", DeviceName[emuPartition], emuPath.c_str(), flashID);
snprintf(dest, sizeof(dest), "/title/00010004/%08x", flashID); snprintf(dest, sizeof(dest), "/title/00010004/%08x", flashID);
} }
Nand::Instance()->ResetCounters(); NandHandle.ResetCounters();
m.m_nandexentry = 1; m.m_nandexentry = 1;
m.m_dumpsize = Nand::Instance()->CalcFlashSize(source, CMenu::_ShowProgress, obj); m.m_dumpsize = NandHandle.CalcFlashSize(source, CMenu::_ShowProgress, obj);
m_nandext = true; m_nandext = true;
Nand::Instance()->FlashToNAND(source, dest, CMenu::_ShowProgress, obj); NandHandle.FlashToNAND(source, dest, CMenu::_ShowProgress, obj);
m.m_thrdWorking = false; m.m_thrdWorking = false;
LWP_MutexLock(m.m_mutex); LWP_MutexLock(m.m_mutex);
@ -748,7 +748,7 @@ int CMenu::_NandDumper(void *obj)
m.m_filesdone = 0; m.m_filesdone = 0;
m.m_foldersdone = 0; m.m_foldersdone = 0;
Nand::Instance()->ResetCounters(); NandHandle.ResetCounters();
if(m.m_current_view == COVERFLOW_CHANNEL) if(m.m_current_view == COVERFLOW_CHANNEL)
m.m_partRequest = m.m_cfg.getInt("NAND", "partition", -1); m.m_partRequest = m.m_cfg.getInt("NAND", "partition", -1);
@ -772,9 +772,9 @@ int CMenu::_NandDumper(void *obj)
if(m_fulldump) if(m_fulldump)
{ {
m.m_dumpsize = Nand::Instance()->CalcDumpSpace("/", CMenu::_ShowProgress, obj); m.m_dumpsize = NandHandle.CalcDumpSpace("/", CMenu::_ShowProgress, obj);
m_nandext = true; m_nandext = true;
Nand::Instance()->DoNandDump("/", basepath, CMenu::_ShowProgress, obj); NandHandle.DoNandDump("/", basepath, CMenu::_ShowProgress, obj);
} }
else else
{ {
@ -818,7 +818,7 @@ int CMenu::_NandDumper(void *obj)
if(!m._checkSave(saveList[i], true)) if(!m._checkSave(saveList[i], true))
snprintf(source, sizeof(source), "/title/00010004/%08x", savePath); snprintf(source, sizeof(source), "/title/00010004/%08x", savePath);
m.m_dumpsize = Nand::Instance()->CalcDumpSpace(source, CMenu::_ShowProgress, obj); m.m_dumpsize = NandHandle.CalcDumpSpace(source, CMenu::_ShowProgress, obj);
} }
for(u32 i = 0; i < saveList.size() && !m.m_thrdStop; ++i) for(u32 i = 0; i < saveList.size() && !m.m_thrdStop; ++i)
{ {
@ -829,7 +829,7 @@ int CMenu::_NandDumper(void *obj)
snprintf(source, sizeof(source), "/title/00010004/%08x", savePath); snprintf(source, sizeof(source), "/title/00010004/%08x", savePath);
m_nandext = true; m_nandext = true;
Nand::Instance()->DoNandDump(source, basepath, CMenu::_ShowProgress, obj); NandHandle.DoNandDump(source, basepath, CMenu::_ShowProgress, obj);
} }
} }

View File

@ -436,9 +436,9 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op)
m_cf.stopCoverLoader(); m_cf.stopCoverLoader();
_stopSounds(); _stopSounds();
MusicPlayer.Cleanup(); MusicPlayer.Cleanup();
SoundHandler::DestroyInstance(); SoundHandle.Cleanup();
soundDeinit(); soundDeinit();
Nand::Instance()->Disable_Emu(); NandHandle.Disable_Emu();
LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_GCcopyGame, (void *)this, 0, 8 * 1024, 64); LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_GCcopyGame, (void *)this, 0, 8 * 1024, 64);
break; break;
} }

View File

@ -28,6 +28,7 @@
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include "BNSDecoder.hpp" #include "BNSDecoder.hpp"
#include "memory/mem2.hpp"
SoundBlock DecodefromBNS(const u8 *buffer, u32 size); SoundBlock DecodefromBNS(const u8 *buffer, u32 size);
@ -69,7 +70,7 @@ BNSDecoder::~BNSDecoder()
void BNSDecoder::OpenFile() void BNSDecoder::OpenFile()
{ {
u8 * tempbuff = new (std::nothrow) u8[file_fd->size()]; u8 *tempbuff = (u8*)MEM2_alloc(file_fd->size());
if(!tempbuff) if(!tempbuff)
{ {
CloseFile(); CloseFile();
@ -86,20 +87,18 @@ void BNSDecoder::OpenFile()
else else
{ {
CloseFile(); CloseFile();
MEM2_free(tempbuff);
return; return;
} }
} }
SoundData = DecodefromBNS(tempbuff, done); SoundData = DecodefromBNS(tempbuff, done);
MEM2_free(tempbuff);
if(SoundData.buffer == NULL) if(SoundData.buffer == NULL)
{ {
CloseFile(); CloseFile();
return; return;
} }
delete [] tempbuff;
tempbuff = NULL;
Decode(); Decode();
} }

View File

@ -103,7 +103,7 @@ bool Musicplayer::PosFromPrevFile()
return false; return false;
MusicFile.Load((*CurrentFileName).c_str()); MusicFile.Load((*CurrentFileName).c_str());
SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Seek(CurrentPosition); SoundHandle.Decoder(MusicFile.GetVoice())->Seek(CurrentPosition);
SetVolume(CurrentVolume); SetVolume(CurrentVolume);
MusicFile.Play(); MusicFile.Play();
CurrentPosition = 0; CurrentPosition = 0;
@ -117,7 +117,7 @@ void Musicplayer::Stop()
if(!MusicFile.IsPlaying()) if(!MusicFile.IsPlaying())
return; return;
MusicFile.Pause(); MusicFile.Pause();
CurrentPosition = SoundHandler::Instance()->Decoder(MusicFile.GetVoice())->Tell(); CurrentPosition = SoundHandle.Decoder(MusicFile.GetVoice())->Tell();
MusicFile.FreeMemory(); MusicFile.FreeMemory();
MusicStopped = true; MusicStopped = true;
} }

View File

@ -34,9 +34,9 @@
#include "gecko/gecko.h" #include "gecko/gecko.h"
#include "memory/mem2.hpp" #include "memory/mem2.hpp"
SoundHandler * SoundHandler::instance = NULL; SoundHandler SoundHandle;
SoundHandler::SoundHandler() void SoundHandler::Init()
{ {
Decoding = false; Decoding = false;
ExitRequested = false; ExitRequested = false;
@ -51,7 +51,7 @@ SoundHandler::SoundHandler()
gprintf("SHND: Running sound thread\n"); gprintf("SHND: Running sound thread\n");
} }
SoundHandler::~SoundHandler() void SoundHandler::Cleanup()
{ {
gprintf("SHND: Stopping sound thread\n"); gprintf("SHND: Stopping sound thread\n");
@ -69,22 +69,6 @@ SoundHandler::~SoundHandler()
gprintf("SHND: Stopped sound thread\n"); gprintf("SHND: Stopped sound thread\n");
} }
SoundHandler * SoundHandler::Instance()
{
if (instance == NULL)
instance = new SoundHandler();
return instance;
}
void SoundHandler::DestroyInstance()
{
if(instance)
{
delete instance;
instance = NULL;
}
}
void SoundHandler::AddDecoder(int voice, const char * filepath) void SoundHandler::AddDecoder(int voice, const char * filepath)
{ {
if(voice < 0 || voice >= MAX_DECODERS) if(voice < 0 || voice >= MAX_DECODERS)

View File

@ -35,34 +35,32 @@
class SoundHandler class SoundHandler
{ {
public: public:
static SoundHandler * Instance(); void Init();
static void DestroyInstance(); void Cleanup();
void AddDecoder(int voice, const char * filepath); void AddDecoder(int voice, const char *filepath);
void AddDecoder(int voice, const u8 * snd, int len); void AddDecoder(int voice, const u8 *snd, int len);
void RemoveDecoder(int voice); void RemoveDecoder(int voice);
void DestroyDecoder(SoundDecoder * decoder); void DestroyDecoder(SoundDecoder *decoder);
SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); }; SoundDecoder *Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); }; void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
bool IsDecoding() { return Decoding; }; bool IsDecoding() { return Decoding; };
protected: protected:
SoundHandler(); static void *UpdateThread(void *arg);
~SoundHandler();
static void * UpdateThread(void *arg);
void InternalSoundUpdates(); void InternalSoundUpdates();
void ClearDecoderList(); void ClearDecoderList();
SoundDecoder * GetSoundDecoder(const char * filepath); SoundDecoder *GetSoundDecoder(const char *filepath);
SoundDecoder * GetSoundDecoder(const u8 * sound, int length); SoundDecoder *GetSoundDecoder(const u8 *sound, int length);
static SoundHandler * instance; u8 *ThreadStack;
u8 * ThreadStack;
lwp_t SoundThread; lwp_t SoundThread;
lwpq_t ThreadQueue; lwpq_t ThreadQueue;
bool Decoding; bool Decoding;
bool ExitRequested; bool ExitRequested;
SoundDecoder * DecoderList[MAX_DECODERS]; SoundDecoder *DecoderList[MAX_DECODERS];
}; };
extern SoundHandler SoundHandle;
#endif #endif

View File

@ -58,7 +58,7 @@ static inline int GetFirstUnusedVoice()
extern "C" void SoundCallback(s32 voice) extern "C" void SoundCallback(s32 voice)
{ {
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice); SoundDecoder *decoder = SoundHandle.Decoder(voice);
if(!decoder) if(!decoder)
return; return;
@ -67,13 +67,13 @@ extern "C" void SoundCallback(s32 voice)
if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK) if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK)
{ {
decoder->LoadNext(); decoder->LoadNext();
SoundHandler::Instance()->ThreadSignal(); SoundHandle.ThreadSignal();
} }
} }
else if(decoder->IsEOF()) else if(decoder->IsEOF())
ASND_StopVoice(voice); ASND_StopVoice(voice);
else else
SoundHandler::Instance()->ThreadSignal(); SoundHandle.ThreadSignal();
} }
GuiSound::GuiSound() GuiSound::GuiSound()
@ -143,7 +143,7 @@ void GuiSound::FreeMemory()
// Prevent reinitialization of SoundHandler since we're exiting // Prevent reinitialization of SoundHandler since we're exiting
if(!Sys_Exiting()) if(!Sys_Exiting())
SoundHandler::Instance()->RemoveDecoder(this->voice); SoundHandle.RemoveDecoder(this->voice);
if(allocated && sound != NULL) if(allocated && sound != NULL)
free(sound); free(sound);
@ -173,9 +173,9 @@ bool GuiSound::Load(const char * filepath)
fread(&magic, 1, 4, f); fread(&magic, 1, 4, f);
fclose(f); fclose(f);
SoundHandler::Instance()->AddDecoder(this->voice, filepath); SoundHandle.AddDecoder(this->voice, filepath);
//gprintf("gui_sound.cpp: Loading %s using voice %d\n", filepath, this->voice); //gprintf("gui_sound.cpp: Loading %s using voice %d\n", filepath, this->voice);
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder) if(!decoder)
{ {
gprintf("gui_sound.cpp: No Decoder!\n"); gprintf("gui_sound.cpp: No Decoder!\n");
@ -185,7 +185,7 @@ bool GuiSound::Load(const char * filepath)
if(!decoder->IsBufferReady()) if(!decoder->IsBufferReady())
{ {
gprintf("gui_sound.cpp: Buffer not ready!\n"); gprintf("gui_sound.cpp: Buffer not ready!\n");
SoundHandler::Instance()->RemoveDecoder(this->voice); SoundHandle.RemoveDecoder(this->voice);
return false; return false;
} }
@ -209,11 +209,11 @@ bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
length = len; length = len;
allocated = isallocated; allocated = isallocated;
SoundHandler::Instance()->AddDecoder(this->voice, sound, length); SoundHandle.AddDecoder(this->voice, sound, length);
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder || !decoder->IsBufferReady()) if(!decoder || !decoder->IsBufferReady())
{ {
SoundHandler::Instance()->RemoveDecoder(this->voice); SoundHandle.RemoveDecoder(this->voice);
return false; return false;
} }
@ -270,7 +270,7 @@ void GuiSound::Play(int vol, bool restart)
if((IsPlaying() && !restart) || this->voice < 0 || this->voice >= 16) if((IsPlaying() && !restart) || this->voice < 0 || this->voice >= 16)
return; return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
@ -285,7 +285,7 @@ void GuiSound::Play(int vol, bool restart)
u8 * curbuffer = decoder->GetBuffer(); u8 * curbuffer = decoder->GetBuffer();
int bufsize = decoder->GetBufferSize(); int bufsize = decoder->GetBufferSize();
decoder->LoadNext(); decoder->LoadNext();
SoundHandler::Instance()->ThreadSignal(); SoundHandle.ThreadSignal();
ASND_SetVoice(this->voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback); ASND_SetVoice(this->voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback);
} }
@ -303,14 +303,14 @@ void GuiSound::Stop()
ASND_StopVoice(this->voice); ASND_StopVoice(this->voice);
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
decoder->ClearBuffer(); decoder->ClearBuffer();
Rewind(); Rewind();
SoundHandler::Instance()->ThreadSignal(); SoundHandle.ThreadSignal();
} }
void GuiSound::Pause() void GuiSound::Pause()
@ -357,7 +357,7 @@ void GuiSound::SetLoop(u8 l)
{ {
loop = l; loop = l;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
@ -366,7 +366,7 @@ void GuiSound::SetLoop(u8 l)
void GuiSound::Rewind() void GuiSound::Rewind()
{ {
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice); SoundDecoder *decoder = SoundHandle.Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;

View File

@ -36,6 +36,7 @@
#include "ZipFile.h" #include "ZipFile.h"
#include "fileOps/fileOps.h" #include "fileOps/fileOps.h"
#include "memory/mem2.hpp"
ZipFile::ZipFile(const char *filepath) ZipFile::ZipFile(const char *filepath)
{ {
@ -61,10 +62,9 @@ bool ZipFile::ExtractAll(const char *dest)
bool Stop = false; bool Stop = false;
u32 blocksize = 1024 * 50; u32 blocksize = 1024*50;
u8 *buffer = new u8[blocksize]; u8 *buffer = (u8*)MEM2_memalign(32, blocksize);
if(buffer == NULL)
if(!buffer)
return false; return false;
char writepath[MAXPATHLEN]; char writepath[MAXPATHLEN];
@ -126,8 +126,7 @@ bool ZipFile::ExtractAll(const char *dest)
if(unzGoToNextFile(File) != UNZ_OK) if(unzGoToNextFile(File) != UNZ_OK)
Stop = true; Stop = true;
} }
MEM2_free(buffer);
delete[] buffer;
buffer = NULL; buffer = NULL;
return true; return true;