-made sfmt, wfmt and gprintf faster and more simple

-set down wiiflows entry point from 0x80A00000 to 0x8062000
(saves ALOT of MEM1 for lists etc, so wiiflow should be able to read
in alot of more games in for example plugin coverflow)
-recompiled libjpeg
-removed alot of annoying debug prints
-made the trailer code faster
This commit is contained in:
fix94.1 2012-09-23 12:10:25 +00:00
parent 3420882624
commit 550ac3356b
17 changed files with 106 additions and 118 deletions

View File

@ -58,7 +58,7 @@ ios := 249
CFLAGS = -g -O2 -Wall -Wextra -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H
CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80A00000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80620000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project

View File

@ -18,6 +18,14 @@
/* Define this if you get warnings about undefined structures. */
/* #undef INCOMPLETE_TYPES_BROKEN */
/* Define "boolean" as unsigned char, not int, on Windows systems. */
#ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif
#ifdef JPEG_INTERNALS
/* #undef RIGHT_SHIFT_IS_UNSIGNED */

Binary file not shown.

View File

@ -58,12 +58,12 @@ class BannerWindow
void ToogleGameSettings();
bool GetShowBanner() { return ShowBanner; }
void SetShowBanner(bool show) { ShowBanner = show; }
void ReSetup_GX(void);
protected:
int MainLoop();
void Animate(void);
void ChangeGame(Banner *banner);
void DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color);
void ReSetup_GX(void);
void Init(CVideo *vid, u8 *font1, u8 *font2);
static const float fBannerWidth = 608.f;

View File

@ -65,12 +65,12 @@ static void USBGeckoOutput()
devoptab_list[STD_ERR] = &gecko_out;
}
void WriteToFile(char* tmp)
static void WriteToFile(char* tmp, int len)
{
if(!bufferMessages)
return;
if((strlen(tmpfilebuffer) + strlen(tmp)) < 1024)
if((strlen(tmpfilebuffer) + len) < 1024)
strcat(tmpfilebuffer, tmp);
if(WriteToSD)
@ -85,21 +85,17 @@ void WriteToFile(char* tmp)
}
}
//using the gprintf from crediar because it is smaller than mine
void gprintf( const char *format, ... )
char gprintfBuffer[256];
void gprintf(const char *format, ...)
{
char *tmp = NULL;
va_list va;
va_start(va, format);
if((vasprintf(&tmp, format, va) >= 0) && tmp)
{
WriteToFile(tmp);
WifiGecko_Send(tmp, strlen(tmp));
__out_write(NULL, 0, tmp, strlen(tmp));
free(tmp);
}
int len = vsnprintf(gprintfBuffer, 255, format, va);
__out_write(NULL, 0, gprintfBuffer, len);
WifiGecko_Send(gprintfBuffer, len);
WriteToFile(gprintfBuffer, len);
va_end(va);
}
}
char ascii(char s)
{
@ -141,6 +137,7 @@ void ghexdump(void *d, int len)
}
}
const char *initstr = "USB Gecko inited.\n";
bool InitGecko()
{
if(geckoinit)
@ -149,16 +146,16 @@ bool InitGecko()
USBGeckoOutput();
memset(tmpfilebuffer, 0, 1024);
#ifdef sd_write_log
WriteToSD = true;
#endif
#ifdef sd_write_log
WriteToSD = true;
#endif
u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1);
if(geckoattached)
{
geckoinit = true;
usb_flush(EXI_CHANNEL_1);
puts("USB Gecko inited.");
__out_write(NULL, 0, initstr, strlen(initstr));
}
return geckoinit;
}

View File

@ -59,7 +59,7 @@ WiiMovie::WiiMovie(const char * filepath)
return;
}
SndChannels = (Video->getNumChannels() == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT;
SndChannels = (Video->getNumChannels() > 1) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT;
SndFrequence = Video->getFrequency();
fps = Video->getFps();
maxSoundSize = Video->getMaxAudioSamples()*Video->getNumChannels()*2;
@ -263,7 +263,7 @@ void WiiMovie::ReadNextFrame()
u32 FramesNeeded = (u32) (PlayTime.elapsed()*fps);
gprintf("Reading needed frames: %d\n", FramesNeeded);
//gprintf("Reading needed frames: %d\n", FramesNeeded);
while(VideoFrameCount < FramesNeeded)
{
@ -273,7 +273,7 @@ void WiiMovie::ReadNextFrame()
++VideoFrameCount;
gprintf("Loaded video frame: %d\n", VideoFrameCount);
//gprintf("Loaded video frame: %d\n", VideoFrameCount);
if(Video->hasSound())
{
@ -298,7 +298,7 @@ void WiiMovie::ReadNextFrame()
if(ASND_StatusVoice(10) == SND_UNUSED && SoundBuffer.IsBufferReady())
{
ASND_StopVoice(10);
ASND_SetVoice(10, SndChannels == 2 ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT, SndFrequence, 0, SoundBuffer.GetBuffer(), SoundBuffer.GetBufferSize(), volume, volume, THPSoundCallback);
ASND_SetVoice(10, SndChannels, SndFrequence, 0, SoundBuffer.GetBuffer(), SoundBuffer.GetBufferSize(), volume, volume, THPSoundCallback);
SoundBuffer.LoadNext();
}
}

View File

@ -752,7 +752,7 @@ void jpegErrorHandler(j_common_ptr cinfo)
//MessageBox(g_hWnd, buff, "JpegLib error:", MB_OK);
}
void decodeRealJpeg(const u8* data, int size, VideoFrame& dest)
void decodeRealJpeg(const u8* data, int size, VideoFrame& dest, bool fancy)
{
if(g_isLoading)
return;
@ -783,15 +783,21 @@ void decodeRealJpeg(const u8* data, int size, VideoFrame& dest)
cinfo.src = &sourceMgr;
jpeg_read_header(&cinfo, TRUE);
cinfo.do_fancy_upsampling = TRUE;
cinfo.do_block_smoothing = TRUE;
cinfo.dct_method = JDCT_ISLOW;
jpeg_start_decompress(&cinfo);
dest.resize(ALIGN(4, cinfo.output_width), ALIGN(4, cinfo.output_height));
if(fancy)
{
cinfo.do_fancy_upsampling = TRUE;
cinfo.do_block_smoothing = TRUE;
cinfo.dct_method = JDCT_ISLOW;
jpeg_start_decompress(&cinfo);
dest.resize(ALIGN(4, cinfo.output_width), ALIGN(4, cinfo.output_height));
}
else
{
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
jpeg_start_decompress(&cinfo);
dest.resize(cinfo.output_width, cinfo.output_height);
}
if(cinfo.num_components == 3)
{
int y = 0;

View File

@ -330,6 +330,6 @@ class JpgVideoFile : public VideoFile
VideoFrame _currFrame;
};
void decodeRealJpeg(const u8* data, int size, VideoFrame& dest);
void decodeRealJpeg(const u8* data, int size, VideoFrame& dest, bool fancy = false);
#endif //THAKIS_GCVID_H

View File

@ -1,36 +1,27 @@
#include "text.hpp"
static const wchar_t *g_whitespaces = L" \f\n\r\t\v";
int currentStr = 0;
char fmt_buffer[MAX_USES][MAX_MSG_SIZE];
char general_buffer[MAX_MSG_SIZE];
// Simplified use of sprintf
const char *fmt(const char *format, ...)
{
static int currentStr = 0;
currentStr = (currentStr + 1) % MAX_USES;
va_list va;
va_start(va, format);
static char buffer[MAX_USES][MAX_MSG_SIZE];
vsnprintf(buffer[currentStr], MAX_MSG_SIZE, format, va);
buffer[currentStr][MAX_MSG_SIZE - 1] = '\0';
currentStr = (currentStr + 1) % MAX_USES;
vsnprintf(fmt_buffer[currentStr], MAX_MSG_SIZE - 1, format, va);
va_end(va);
return buffer[currentStr];
return fmt_buffer[currentStr];
}
string sfmt(const char *format, ...)
{
va_list va;
va_start(va, format);
u32 length = vsnprintf(0, 0, format, va) + 1;
int len = vsnprintf(general_buffer, MAX_MSG_SIZE - 1, format, va);
va_end(va);
char *tmp = new char[length + 1];
va_start(va, format);
vsnprintf(tmp, length, format, va);
va_end(va);
string s = tmp;
delete[] tmp;
return s;
return string(general_buffer, len);
}
static inline bool fmtCount(const wstringEx &format, int &i, int &s)
@ -86,20 +77,13 @@ bool checkFmt(const wstringEx &ref, const wstringEx &format)
wstringEx wfmt(const wstringEx &format, ...)
{
// Don't care about performance
va_list va;
string f(format.toUTF8());
va_start(va, format);
u32 length = vsnprintf(0, 0, f.c_str(), va) + 1;
vsnprintf(general_buffer, MAX_MSG_SIZE - 1, format.toUTF8().c_str(), va);
va_end(va);
char *tmp = new char[length + 1];
va_start(va, format);
vsnprintf(tmp, length, f.c_str(), va);
va_end(va);
wstringEx ws;
ws.fromUTF8(tmp);
delete[] tmp;
return ws;
wstringEx wide_buffer;
wide_buffer.fromUTF8(general_buffer);
return wide_buffer;
}
string vectorToString(const vector<string> &vect, string sep)
@ -233,6 +217,7 @@ bool SFont::fromFile(const char *filename, u32 size, u32 lspacing, u32 w, u32 id
return true;
}
static const wchar_t *g_whitespaces = L" \f\n\r\t\v";
void CText::setText(SFont font, const wstringEx &t)
{
CText::SWord w;

View File

@ -58,7 +58,7 @@ private:
enum {
MAX_MSG_SIZE = 1024,
MAX_USES = 16,
MAX_USES = 8,
};
const char *fmt(const char *format, ...);

View File

@ -341,7 +341,7 @@ STexture::TexErr STexture::fromRAW(const u8 *buffer, u32 w, u32 h, u8 f, Alloc a
STexture::TexErr STexture::fromJPG(const u8 *buffer, const u32 buffer_size, u8 f, Alloc alloc, u32 minMipSize, u32 maxMipSize)
{
VideoFrame VideoF;
decodeRealJpeg(buffer, buffer_size, VideoF);
decodeRealJpeg(buffer, buffer_size, VideoF, true);
if(!VideoF.getData() || (VideoF.getWidth() % 4) != 0 || (VideoF.getHeight() % 4) != 0)
return TE_ERROR;
return fromRAW(VideoF.getData(), VideoF.getWidth(), VideoF.getHeight(), f, alloc, minMipSize, maxMipSize);

View File

@ -255,7 +255,7 @@ void CVideo::prepare(void)
void CVideo::cleanup(void)
{
gprintf("Cleaning up video...\n");
//gprintf("Cleaning up video...\n");
hideWaitMessage();
_clearScreen();
@ -507,7 +507,7 @@ void CVideo::_showWaitMessages(CVideo *m)
wiiLightSetLevel(0);
wiiLightOn();
gprintf("Wait Message Thread: Start\nDelay: %d, Images: %d\n", waitFrames, m->m_waitMessages.size());
//gprintf("Wait Message Thread: Start\nDelay: %d, Images: %d\n", waitFrames, m->m_waitMessages.size());
while(m->m_showWaitMessage)
{
currentLightLevel += fadeDirection * 5;
@ -536,7 +536,7 @@ void CVideo::_showWaitMessages(CVideo *m)
waitFrames--;
}
wiiLightOff();
gprintf("Wait Message Thread: End\n");
//gprintf("Wait Message Thread: End\n");
m->m_showingWaitMessages = false;
}

View File

@ -3,7 +3,7 @@
void CachedList::Load(string path, string containing, string m_lastLanguage, Config &m_plugin) /* Load All */
{
gprintf("\nLoading files containing %s in %s\n", containing.c_str(), path.c_str());
//gprintf("\nLoading files containing %s in %s\n", containing.c_str(), path.c_str());
m_loaded = false;
m_database = sfmt("%s/%s.db", m_cacheDir.c_str(), (make_db_name(path)).c_str());
@ -17,7 +17,7 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con
bool ditimes = false;
if(!m_wbfsFS)
{
gprintf("Database file: %s\n", m_database.c_str());
//gprintf("Database file: %s\n", m_database.c_str());
update_games = strcasestr(path.c_str(), "wbfs") != NULL && force_update[COVERFLOW_USB];
update_homebrew = strcasestr(path.c_str(), "apps") != NULL && force_update[COVERFLOW_HOMEBREW];
@ -26,13 +26,13 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con
const char* partition = DeviceName[DeviceHandle.PathToDriveType(path.c_str())];
update_dml = strcasestr(path.c_str(), fmt(strncmp(partition, "sd", 2) != 0 ? m_DMLgameDir.c_str() : "%s:/games", partition)) != NULL && force_update[COVERFLOW_DML];
gprintf("update_games=%d update_homebrew=%d update_dml=%d, update_emu=%d\n", update_games, update_homebrew, update_dml, update_emu);
//gprintf("update_games=%d update_homebrew=%d update_dml=%d, update_emu=%d\n", update_games, update_homebrew, update_dml, update_emu);
if(update_games || update_homebrew || update_dml || update_emu)
remove(m_database.c_str());
m_discinf = sfmt("%s/disc.info", path.c_str());
struct stat filestat, discinfo, cache;
gprintf("%s\n", path.c_str());
//gprintf("%s\n", path.c_str());
if(stat(path.c_str(), &filestat) == -1)
return;
@ -43,7 +43,7 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con
ditimes = discinfo.st_mtime > cache.st_mtime;
m_update = update_lang || noDB || (!m_skipcheck && (mtimes || ditimes));
if(m_update)
/*if(m_update)
gprintf("Cache of %s is being updated because:\n", path.c_str());
if(update_lang)
gprintf("Languages are different!\nOld language string: %s\nNew language string: %s\n", m_lastLanguage.c_str(), m_curLanguage.c_str());
@ -51,7 +51,7 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con
gprintf("A database was not found!\n");
if(!m_skipcheck && (mtimes || ditimes))
gprintf("The WBFS folder was modified!\nCache date: %i\nFolder date: %i\n", cache.st_mtime, filestat.st_mtime);
*/
if(m_extcheck && !m_update && !m_skipcheck)
{
bool m_chupdate = false;
@ -78,8 +78,8 @@ void CachedList::Load(string path, string containing, string m_lastLanguage, Con
if(m_update || m_wbfsFS)
{
gprintf("Calling list to update filelist\n");
gprintf("Updating Cache\n");
vector<string> pathlist;
list.GetPaths(pathlist, containing, path, m_wbfsFS, (update_dml || (m_update && strcasestr(path.c_str(), ":/games") != NULL)), !update_emu);
list.GetHeaders(pathlist, *this, m_settingsDir, m_curLanguage, m_DMLgameDir, m_plugin);
@ -133,9 +133,9 @@ void CachedList::LoadChannels(string path, u32 channelType, string m_lastLanguag
if(m_update)
{
gprintf("Updating channels\n");
//gprintf("Updating channels\n");
list.GetChannels(*this, m_settingsDir, channelType, m_curLanguage);
m_loaded = true;
m_update = false;

View File

@ -105,7 +105,7 @@ void CList<dir_discHdr>::GetHeaders(vector<string> pathlist, vector<dir_discHdr>
return;
headerlist.reserve(pathlist.size() + headerlist.size());
gprintf("Getting headers for paths in pathlist (%d)\n", pathlist.size());
//gprintf("Getting headers for paths in pathlist (%d)\n", pathlist.size());
vector<char*> GC_SD_IDs;
bool GC_SD_IDs_loaded = false;

View File

@ -14,7 +14,7 @@
u32 MALLOC_MEM2 = 0;
void *MEM1_lo_start = (void*)0x80004000;
void *MEM1_lo_end = (void*)0x80A00000;
void *MEM1_lo_end = (void*)0x80620000;
void *MEM2_start = (void*)0x90200000;
void *MEM2_end = (void*)0x93100000;
@ -34,7 +34,7 @@ extern __typeof(malloc_usable_size) __real_malloc_usable_size;
void MEM_init()
{
g_mem1lo.init(MEM1_lo_start, MEM1_lo_end); //about 10mb
g_mem1lo.init(MEM1_lo_start, MEM1_lo_end); //about 6mb
g_mem1lo.clear();
g_mem2gp.init(MEM2_start, MEM2_end); //about 47mb
@ -55,24 +55,16 @@ void MEM1_lo_free(void *p)
void *MEM1_alloc(unsigned int s)
{
void *p = g_mem1lo.allocate(s);
if(!p)
p = __real_malloc(s);
return p;
return __real_malloc(s);
}
void *MEM1_memalign(unsigned int a, unsigned int s)
{
void *p = g_mem1lo.allocate(s);
if(!p)
p = __real_memalign(a, s);
return p;
return __real_memalign(a, s);
}
void *MEM1_realloc(void *p, unsigned int s)
{
if(!p || ((u32)p > (u32)MEM1_lo_start && (u32)p < (u32)MEM1_lo_end))
return g_mem1lo.reallocate(p, s);
return __real_realloc(p, s);
}
@ -80,10 +72,7 @@ void MEM1_free(void *p)
{
if(!p)
return;
if((u32)p > (u32)MEM1_lo_start && (u32)p < (u32)MEM1_lo_end)
g_mem1lo.release(p);
else
__real_free(p);
__real_free(p);
}
unsigned int MEM1_freesize()

View File

@ -2139,7 +2139,6 @@ bool CMenu::_loadChannelList(void)
if(changed)
UpdateCache(COVERFLOW_CHANNEL);
gprintf("%s, which is %s\n", disable_emu ? "NAND" : DeviceName[emuPartition], changed ? "refreshing." : "cached.");
if(first && !disable_emu)
{
@ -2196,29 +2195,24 @@ bool CMenu::_loadList(void)
}
if(m_cfg.getBool(_domainFromView(), "update_cache"))
m_gameList.Update(m_current_view);
gprintf("Loading items of ");
gprintf("Switching Views\n");
bool retval;
switch(m_current_view)
{
case COVERFLOW_CHANNEL:
gprintf("channel view from ");
retval = _loadChannelList();
break;
case COVERFLOW_HOMEBREW:
gprintf("homebrew view from ");
retval = _loadHomebrewList();
break;
case COVERFLOW_DML:
gprintf("dml view from ");
retval = _loadDmlList();
break;
case COVERFLOW_EMU:
gprintf("emu view from ");
retval = _loadEmuList();
break;
default:
gprintf("usb view from ");
retval = _loadGameList();
break;
}
@ -2235,7 +2229,6 @@ bool CMenu::_loadGameList(void)
return false;
Config tmpcfg;
gprintf("%s\n", DeviceName[currentPartition]);
DeviceHandle.OpenWBFS(currentPartition);
m_gameList.Load(sfmt(GAMES_DIR, DeviceName[currentPartition]), ".wbfs|.iso", m_cfg.getString("GAMES", "lastlanguage", "EN").c_str(), tmpcfg);
m_cfg.setString("GAMES", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
@ -2251,7 +2244,6 @@ bool CMenu::_loadHomebrewList()
return false;
Config tmpcfg;
gprintf("%s\n", DeviceName[currentPartition]);
m_gameList.Load(sfmt(HOMEBREW_DIR, DeviceName[currentPartition]), ".dol|.elf", m_cfg.getString("HOMEBREW", "lastlanguage", "EN").c_str(), tmpcfg);
m_cfg.setString("HOMEBREW", "lastlanguage", m_loc.getString(m_curLanguage, "gametdb_code", "EN"));
m_cfg.save();
@ -2265,7 +2257,6 @@ bool CMenu::_loadDmlList()
return false;
Config tmpcfg;
gprintf("%s\n", DeviceName[currentPartition]);
if(currentPartition != SD)
m_gameList.Load(sfmt(m_DMLgameDir.c_str(), DeviceName[currentPartition]), "boot.bin|.iso", m_cfg.getString("DML", "lastlanguage", "EN").c_str(), tmpcfg);
else
@ -2281,7 +2272,6 @@ bool CMenu::_loadEmuList()
if(!DeviceHandle.IsInserted(currentPartition))
return false;
gprintf("%s\n", DeviceName[currentPartition]);
DIR *pdir;
struct dirent *pent;
@ -2564,7 +2554,6 @@ const char *CMenu::_domainFromView()
void CMenu::UpdateCache(u32 view)
{
gprintf("UpdateCache(%ld)\n", view);
if(view == COVERFLOW_MAX)
{
UpdateCache(COVERFLOW_USB);

View File

@ -446,9 +446,9 @@ void CMenu::_game(bool launch)
}
else if(BTN_MINUS_PRESSED)
{
string videoPath = sfmt("%s/%.3s.thp", m_videoDir.c_str(), m_cf.getId().c_str());
const char *videoPath = fmt("%s/%.3s.thp", m_videoDir.c_str(), m_cf.getId().c_str());
FILE *file = fopen(videoPath.c_str(), "rb");
FILE *file = fopen(videoPath, "r");
if(file)
{
MusicPlayer.Stop();
@ -456,22 +456,36 @@ void CMenu::_game(bool launch)
m_banner->SetShowBanner(false);
fclose(file);
_hideGame();
WiiMovie movie(videoPath.c_str());
/* Backup Background */
STexture Current_LQ_BG = m_lqBg;
STexture Current_HQ_BG = m_curBg;
STexture EmptyBG;
_setBg(EmptyBG, EmptyBG);
/* Lets play the movie */
WiiMovie movie(videoPath);
movie.SetScreenSize(m_cfg.getInt("GENERAL", "tv_width", 640), m_cfg.getInt("GENERAL", "tv_height", 480), m_cfg.getInt("GENERAL", "tv_x", 0), m_cfg.getInt("GENERAL", "tv_y", 0));
movie.SetVolume(m_cfg.getInt("GENERAL", "sound_volume_bnr", 255));
//_stopSounds();
movie.Play();
m_video_playing = true;
STexture videoBg;
while(!BTN_B_PRESSED && !BTN_A_PRESSED && !BTN_HOME_PRESSED && movie.GetNextFrame(&videoBg))
movie.Play();
m_banner->ReSetup_GX();
m_vid.setup2DProjection();
while(!BTN_B_PRESSED && !BTN_A_PRESSED && !BTN_HOME_PRESSED && movie.GetNextFrame(&m_curBg))
{
_setBg(videoBg, videoBg);
m_bgCrossFade = 10;
_mainLoopCommon(); // Redraw the background every frame
/* Draw movie BG and render */
_drawBg();
m_vid.render();
m_curBg.data.release();
/* Check if we want to stop */
WPAD_ScanPads();
PAD_ScanPads();
ButtonsPressed();
}
movie.Stop();
m_curBg.data.release();
/* Finished, so lets re-setup the background */
_setBg(Current_HQ_BG, Current_LQ_BG);
_updateBg();
/* Get back into our coverflow */
_showGame();
m_video_playing = false;
m_banner->SetShowBanner(true);