Skip to content

Commit

Permalink
- Fix issue 217 (graphical issues with banners when navigating devices)
Browse files Browse the repository at this point in the history
  • Loading branch information
emukidid committed Aug 10, 2019
1 parent b2d694c commit 7ba9958
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 41 deletions.
2 changes: 2 additions & 0 deletions cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef struct {
int fileTypeTexId;
int regionTexId;
u8 *banner;
int bannerSize;
void *tplLocation;
GXTexObj bannerTexObj;
char description[128];
} file_meta;
Expand Down
65 changes: 30 additions & 35 deletions cube/swiss/source/devices/filemeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ extern char blankbanner[];

static heap_cntrl* meta_cache = NULL;

file_meta* create_basic_meta(const u8* img, const u32 img_size) {
file_meta* _meta = (file_meta*)memalign(32,sizeof(file_meta));
memset(_meta, 0, sizeof(file_meta));
TPLFile *tplFile = (TPLFile*) memalign(32,sizeof(TPLFile));
memset(tplFile,0,sizeof(TPLFile));
_meta->banner = memalign(32,img_size);
memcpy(_meta->banner,(void *)img, img_size);
DCFlushRange(_meta->banner, img_size);
TPL_OpenTPLFromMemory(tplFile, (void *)_meta->banner, img_size);
TPL_GetTexture(tplFile,0,&_meta->bannerTexObj);
free(tplFile);
return _meta;
}

void meta_free(void* ptr) {
if(meta_cache && ptr) {
__lwp_heap_free(meta_cache, ptr);
Expand All @@ -51,7 +37,7 @@ void meta_free(void* ptr) {

void* meta_alloc(unsigned int size){
if(!meta_cache){
meta_cache = memalign(32,sizeof(heap_cntrl));
meta_cache = memalign(32, sizeof(heap_cntrl));
__lwp_heap_init(meta_cache, memalign(32,META_CACHE_SIZE), META_CACHE_SIZE, 32);
}

Expand All @@ -75,6 +61,18 @@ void* meta_alloc(unsigned int size){
return ptr;
}

file_meta* create_basic_meta(void* tplTexObj) {
file_meta* meta = (file_meta*)meta_alloc(sizeof(file_meta));
memset(meta, 0, sizeof(file_meta));
meta->tplLocation = tplTexObj;
return meta;
}

void meta_create_direct_texture(file_meta* meta) {
DCFlushRange(meta->banner, meta->bannerSize);
GX_InitTexObj(&meta->bannerTexObj, meta->banner, 96, 32, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP,GX_FALSE);
}

void populate_meta(file_handle *f) {
// If the meta hasn't been created, lets read it.

Expand All @@ -87,9 +85,9 @@ void populate_meta(file_handle *f) {
// If it's a GCM or ISO or DVD Disc
if(endsWith(f->name,".iso") || endsWith(f->name,".gcm")) {

f->meta = (file_meta*)meta_alloc(sizeof(file_meta));
memset(f->meta, 0, sizeof(file_meta));
if(devices[DEVICE_CUR] == &__device_wode) {
f->meta = (file_meta*)meta_alloc(sizeof(file_meta));
memset(f->meta, 0, sizeof(file_meta));
// Assign GCM region texture
ISOInfo_t* isoInfo = (ISOInfo_t*)&f->other;
char region = wodeRegionToChar(isoInfo->iso_region);
Expand All @@ -99,32 +97,29 @@ void populate_meta(file_handle *f) {
f->meta->regionTexId = TEX_NTSCU;
else if(region == 'P')
f->meta->regionTexId = TEX_PAL;
f->meta->banner = memalign(32,BannerSize);
memcpy(f->meta->banner,blankbanner+0x20,BannerSize);
DCFlushRange(f->meta->banner,BannerSize);
GX_InitTexObj(&f->meta->bannerTexObj,f->meta->banner,96,32,GX_TF_RGB5A3,GX_CLAMP,GX_CLAMP,GX_FALSE);

f->meta->banner = memalign(32,GCM_STD_BNR_SIZE);
memcpy(f->meta->banner,blankbanner+0x20,GCM_STD_BNR_SIZE);
f->meta->bannerSize = GCM_STD_BNR_SIZE;
meta_create_direct_texture(f->meta);
}
else {
f->meta = (file_meta*)meta_alloc(sizeof(file_meta));
memset(f->meta, 0, sizeof(file_meta));
DiskHeader *header = memalign(32, sizeof(DiskHeader));
devices[DEVICE_CUR]->seekFile(f, 0, DEVICE_HANDLER_SEEK_SET);
devices[DEVICE_CUR]->readFile(f, header, sizeof(DiskHeader));

if(header->DVDMagicWord == DVD_MAGIC) {
//print_gecko("FILE identifed as valid GCM\r\n");
unsigned int bannerOffset = getBannerOffset(f);
f->meta->banner = memalign(32,BannerSize);
f->meta->banner = memalign(32,GCM_STD_BNR_SIZE);
if(!bannerOffset) {
//print_gecko("Banner not found\r\n");
memcpy(f->meta->banner,blankbanner+0x20,BannerSize);
memcpy(f->meta->banner,blankbanner+0x20,GCM_STD_BNR_SIZE);
}
else
{
devices[DEVICE_CUR]->seekFile(f,bannerOffset+0x20,DEVICE_HANDLER_SEEK_SET);
if(devices[DEVICE_CUR]->readFile(f,f->meta->banner,BannerSize)!=BannerSize) {
memcpy(f->meta->banner,blankbanner+0x20,BannerSize);
if(devices[DEVICE_CUR]->readFile(f,f->meta->banner,GCM_STD_BNR_SIZE)!=GCM_STD_BNR_SIZE) {
memcpy(f->meta->banner,blankbanner+0x20,GCM_STD_BNR_SIZE);
}
//print_gecko("Read banner from %08X+0x20\r\n", bannerOffset);

Expand All @@ -141,8 +136,8 @@ void populate_meta(file_handle *f) {
devices[DEVICE_CUR]->readFile(f,&f->meta->description[0],0x80);
//print_gecko("Meta Description: [%s]\r\n",&f->meta->description[0]);
}
DCFlushRange(f->meta->banner,BannerSize);
GX_InitTexObj(&f->meta->bannerTexObj,f->meta->banner,96,32,GX_TF_RGB5A3,GX_CLAMP,GX_CLAMP,GX_FALSE);
f->meta->bannerSize = GCM_STD_BNR_SIZE;
meta_create_direct_texture(f->meta);
//print_gecko("Meta Gathering complete\r\n\r\n");
// Assign GCM region texture
char region = wodeRegionToChar(header->RegionCode);
Expand All @@ -159,20 +154,20 @@ void populate_meta(file_handle *f) {
}
}
else if(endsWith(f->name,".mp3")) { //MP3
f->meta = create_basic_meta(mp3img_tpl, mp3img_tpl_size);
f->meta = create_basic_meta(&mp3imgTexObj);
}
else if(endsWith(f->name,".dol")) { //DOL
f->meta = create_basic_meta(dolimg_tpl, dolimg_tpl_size);
f->meta = create_basic_meta(&dolimgTexObj);
}
else if(endsWith(f->name,".dol+cli")) { //DOL+CLI
f->meta = create_basic_meta(dolcliimg_tpl, dolcliimg_tpl_size);
f->meta = create_basic_meta(&dolcliimgTexObj);
}
else {
f->meta = create_basic_meta(fileimg_tpl, fileimg_tpl_size);
f->meta = create_basic_meta(&fileimgTexObj);
}
}
else if (f->fileAttrib == IS_DIR) {
f->meta = create_basic_meta(dirimg_tpl, dirimg_tpl_size);
f->meta = create_basic_meta(&dirimgTexObj);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/devices/filemeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include "deviceHandler.h"

// Banner is 96 cols * 32 lines in RGB5A3 fmt
#define BannerSize (96*32*2)
#define GCM_STD_BNR_SIZE (96*32*2)

void meta_create_direct_texture(file_meta* meta);
void populate_meta(file_handle *f);
void meta_free(void* ptr);
#endif
Expand Down
35 changes: 30 additions & 5 deletions cube/swiss/source/gui/FrameBufferMagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ TPLFile checkedTPL;
GXTexObj checkedTexObj;
TPLFile uncheckedTPL;
GXTexObj uncheckedTexObj;
TPLFile mp3imgTPL;
GXTexObj mp3imgTexObj;
TPLFile dolimgTPL;
GXTexObj dolimgTexObj;
TPLFile dolcliimgTPL;
GXTexObj dolcliimgTexObj;
TPLFile fileimgTPL;
GXTexObj fileimgTexObj;
TPLFile dirimgTPL;
GXTexObj dirimgTexObj;


static char fbTextBuffer[64];

Expand Down Expand Up @@ -366,6 +377,16 @@ static void init_textures()
TPL_GetTexture(&checkedTPL,checked_32,&checkedTexObj);
TPL_OpenTPLFromMemory(&uncheckedTPL, (void *)unchecked_32_tpl, unchecked_32_tpl_size);
TPL_GetTexture(&uncheckedTPL,unchecked_32,&uncheckedTexObj);
TPL_OpenTPLFromMemory(&mp3imgTPL, (void *)mp3img_tpl, mp3img_tpl_size);
TPL_GetTexture(&mp3imgTPL,0,&mp3imgTexObj);
TPL_OpenTPLFromMemory(&dolimgTPL, (void *)dolimg_tpl, dolimg_tpl_size);
TPL_GetTexture(&dolimgTPL,0,&dolimgTexObj);
TPL_OpenTPLFromMemory(&dolcliimgTPL, (void *)dolcliimg_tpl, dolcliimg_tpl_size);
TPL_GetTexture(&dolcliimgTPL,0,&dolcliimgTexObj);
TPL_OpenTPLFromMemory(&fileimgTPL, (void *)fileimg_tpl, fileimg_tpl_size);
TPL_GetTexture(&fileimgTPL,0,&fileimgTexObj);
TPL_OpenTPLFromMemory(&dirimgTPL, (void *)dirimg_tpl, dirimg_tpl_size);
TPL_GetTexture(&dirimgTPL,0,&dirimgTexObj);
}

static void drawInit()
Expand Down Expand Up @@ -958,10 +979,10 @@ static void _DrawFileBrowserButton(uiDrawObj_t *evt) {

// Draw banner if there is one
file_handle *file = data->file;
if(file->meta && file->meta->banner) {
if(file->meta && (file->meta->banner || file->meta->tplLocation)) {
GX_SetTevOp (GX_TEVSTAGE0, GX_REPLACE);
GX_InvalidateTexAll();
GX_LoadTexObj(&file->meta->bannerTexObj, GX_TEXMAP0);
GX_LoadTexObj(file->meta->tplLocation ? file->meta->tplLocation : &file->meta->bannerTexObj, GX_TEXMAP0);
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
GX_Position3f32((float) data->x1+7,(float) data->y1+4, 0.0f );
GX_Color4u8(255, 255, 255, 255);
Expand All @@ -982,7 +1003,6 @@ static void _DrawFileBrowserButton(uiDrawObj_t *evt) {
}

float scale = GetTextScaleToFitInWidth(data->displayName, (data->x2-data->x1-96-35)-(borderSize*2));

drawString(data->x1 + borderSize+5+96, data->y1+borderSize, data->displayName, scale, false, defaultColor);

// Print specific stats
Expand Down Expand Up @@ -1020,9 +1040,14 @@ uiDrawObj_t* DrawFileBrowserButton(int x1, int y1, int x2, int y2, char *message
if(file->meta) {
eventData->file->meta = calloc(1, sizeof(file_meta));
memcpy(eventData->file->meta, file->meta, sizeof(file_meta));
memset(&eventData->file->meta->bannerTexObj, 0, sizeof(GXTexObj));
if(file->meta->banner) {
eventData->file->meta->banner = memalign(32, BannerSize);
memcpy(eventData->file->meta->banner, file->meta->banner, BannerSize);
eventData->file->meta->banner = memalign(32, eventData->file->meta->bannerSize);
memcpy(eventData->file->meta->banner, file->meta->banner, eventData->file->meta->bannerSize);
// Make a copy cause we want this one to be killed off when the display event is disposed
if(eventData->file->meta->bannerSize == GCM_STD_BNR_SIZE) {
meta_create_direct_texture(eventData->file->meta);
}
}
}
strcpy(eventData->displayName, message);
Expand Down
6 changes: 6 additions & 0 deletions cube/swiss/source/gui/FrameBufferMagic.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ enum TextureId
TEX_UNCHECKED
};

extern GXTexObj mp3imgTexObj;
extern GXTexObj dolimgTexObj;
extern GXTexObj dolcliimgTexObj;
extern GXTexObj fileimgTexObj;
extern GXTexObj dirimgTexObj;

typedef struct kbBtn_ {
int supportedEntryMode;
char *val;
Expand Down

0 comments on commit 7ba9958

Please sign in to comment.