Skip to content

Commit 374c2a8

Browse files
Maschellashquarky
authored andcommitted
(WiiU) Implement ProcUI-loop, add home menu support when not running an app
* WIP: Implement ProcUI loop properly, allows home menu when no game is running. Some stuff is copy pasted from wut, so variables/functions need be adjusted I guess. We loose access to MEM1 when opening the HOME Menu, so for now I replaced all MEM1 usages with MEM2, we need figure out how to handle this properly. * Fix setting setvbuf on WII_U * Preserve MEM1 and bucket via proc_ui * Revert procui callbacks * Avoid accessing MEM1 and Bucket memory when not in foreground * the exception handler are broken... * Clean up and formatting * Formatting
1 parent cd105b6 commit 374c2a8

File tree

4 files changed

+89
-64
lines changed

4 files changed

+89
-64
lines changed

frontend/drivers/platform_wiiu.c

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
#include <coreinit/dynload.h>
3434
#include <coreinit/ios.h>
3535
#include <coreinit/foreground.h>
36+
#include <coreinit/memory.h>
3637
#include <coreinit/time.h>
3738
#include <coreinit/title.h>
3839
#include <proc_ui/procui.h>
40+
#include <proc_ui/memory.h>
3941
#include <padscore/wpad.h>
4042
#include <padscore/kpad.h>
4143
#include <sysapp/launch.h>
@@ -228,6 +230,25 @@ static int frontend_wiiu_parse_drive_list(void *data, bool load_content)
228230
return 0;
229231
}
230232

233+
static bool check_proc() {
234+
switch (ProcUIProcessMessages(true)) {
235+
case PROCUI_STATUS_EXITING: {
236+
return false;
237+
}
238+
case PROCUI_STATUS_RELEASE_FOREGROUND: {
239+
ProcUIDrawDoneRelease();
240+
break;
241+
}
242+
case PROCUI_STATUS_IN_FOREGROUND: {
243+
break;
244+
}
245+
case PROCUI_STATUS_IN_BACKGROUND:
246+
default:
247+
break;
248+
}
249+
return true;
250+
}
251+
231252
static void frontend_wiiu_exec(const char *path, bool should_load_content)
232253
{
233254
/* goal: make one big buffer with all the argv's, seperated by NUL. we can
@@ -317,6 +338,13 @@ static void frontend_wiiu_exec(const char *path, bool should_load_content)
317338

318339
in_exec = true;
319340

341+
if (!should_load_content) {
342+
SYSLaunchMenu();
343+
}
344+
while (check_proc()) {
345+
346+
}
347+
320348
cleanup:
321349
free(argv_buf);
322350
argv_buf = NULL;
@@ -451,7 +479,7 @@ int main(int argc, char **argv)
451479
static void main_setup(void)
452480
{
453481
memoryInitialize();
454-
init_os_exceptions();
482+
//init_os_exceptions();
455483
init_logging();
456484
init_filesystems();
457485
init_pad_libraries();
@@ -464,35 +492,16 @@ static void main_teardown(void)
464492
deinit_pad_libraries();
465493
deinit_filesystems();
466494
deinit_logging();
467-
deinit_os_exceptions();
495+
//deinit_os_exceptions();
468496
memoryRelease();
469497
}
470498

471-
// https://github.com/devkitPro/wut/blob/7d9fa9e416bffbcd747f1a8e5701fd6342f9bc3d/libraries/libwhb/src/proc.c
472-
473-
#define HBL_TITLE_ID (0x0005000013374842)
474-
#define MII_MAKER_JPN_TITLE_ID (0x000500101004A000)
475-
#define MII_MAKER_USA_TITLE_ID (0x000500101004A100)
476-
#define MII_MAKER_EUR_TITLE_ID (0x000500101004A200)
477-
478-
static bool in_hbl = false;
479499
static bool in_aroma = false;
500+
static void* procui_mem1Storage = NULL;
501+
static void* procui_bucketStorage = NULL;
480502

481503
static void proc_setup(void)
482504
{
483-
uint64_t titleID = OSGetTitleID();
484-
485-
// Homebrew Launcher does not like the standard ProcUI application loop, sad!
486-
if (titleID == HBL_TITLE_ID ||
487-
titleID == MII_MAKER_JPN_TITLE_ID ||
488-
titleID == MII_MAKER_USA_TITLE_ID ||
489-
titleID == MII_MAKER_EUR_TITLE_ID)
490-
{
491-
// Important: OSEnableHomeButtonMenu must come before ProcUIInitEx.
492-
OSEnableHomeButtonMenu(FALSE);
493-
in_hbl = TRUE;
494-
}
495-
496505
/* Detect Aroma explicitly (it's possible to run under H&S while using Tiramisu) */
497506
OSDynLoad_Module rpxModule;
498507
if (OSDynLoad_Acquire("homebrew_rpx_loader", &rpxModule) == OS_DYNLOAD_OK)
@@ -502,33 +511,33 @@ static void proc_setup(void)
502511
}
503512

504513
ProcUIInit(&proc_save_callback);
514+
515+
uint32_t addr = 0;
516+
uint32_t size = 0;
517+
if (OSGetMemBound(OS_MEM1, &addr, &size) == 0) {
518+
procui_mem1Storage = malloc(size);
519+
if (procui_mem1Storage) {
520+
ProcUISetMEM1Storage(procui_mem1Storage, size);
521+
}
522+
}
523+
if (OSGetForegroundBucketFreeArea(&addr, &size)) {
524+
procui_bucketStorage = malloc(size);
525+
if (procui_bucketStorage) {
526+
ProcUISetBucketStorage(procui_bucketStorage, size);
527+
}
528+
}
505529
}
506530

507531
static void proc_exit(void)
508532
{
509-
/* If we're doing a normal exit while running under HBL, we must SYSRelaunchTitle.
510-
* If we're in an exec (i.e. launching mocha homebrew wrapper) we must *not* do that. yay! */
511-
if (in_hbl && !in_exec)
512-
SYSRelaunchTitle(0, NULL);
513-
514-
/* Similar deal for Aroma, but exit to menu. */
515-
if (!in_hbl && !in_exec)
516-
SYSLaunchMenu();
517-
518-
/* Now just tell the OS that we really are ok to exit */
519-
if (!ProcUIInShutdown())
520-
{
521-
for (;;)
522-
{
523-
ProcUIStatus status;
524-
status = ProcUIProcessMessages(TRUE);
525-
if (status == PROCUI_STATUS_EXITING)
526-
break;
527-
else if (status == PROCUI_STATUS_RELEASE_FOREGROUND)
528-
ProcUIDrawDoneRelease();
529-
}
533+
if (procui_mem1Storage) {
534+
free(procui_mem1Storage);
535+
procui_mem1Storage = NULL;
536+
}
537+
if (procui_bucketStorage) {
538+
free(procui_bucketStorage);
539+
procui_bucketStorage = NULL;
530540
}
531-
532541
ProcUIShutdown();
533542
}
534543

@@ -600,7 +609,10 @@ static void main_loop(void)
600609
OSTime start_time;
601610
int status;
602611

603-
for (;;)
612+
bool home_menu_allowed = true;
613+
OSEnableHomeButtonMenu(TRUE);
614+
615+
while (check_proc())
604616
{
605617
if (video_driver_get_ptr())
606618
{
@@ -612,8 +624,22 @@ static void main_loop(void)
612624

613625
status = runloop_iterate();
614626

615-
if (status == -1)
627+
// TODO: make this less ugly...
628+
if ((runloop_get_flags() & RUNLOOP_FLAG_CORE_RUNNING)) {
629+
if (home_menu_allowed) {
630+
OSEnableHomeButtonMenu(FALSE);
631+
home_menu_allowed = false;
632+
}
633+
} else {
634+
if (!home_menu_allowed) {
635+
OSEnableHomeButtonMenu(TRUE);
636+
home_menu_allowed = true;
637+
}
638+
}
639+
640+
if (status == -1) {
616641
break;
642+
}
617643
}
618644
}
619645
#endif

gfx/drivers/gx2_gfx.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <formats/image.h>
2424
#include <file/file_path.h>
2525
#include <string/stdstring.h>
26+
#include <proc_ui/procui.h>
2627

2728
#include "../../driver.h"
2829
#include "../../configuration.h"
@@ -1493,19 +1494,21 @@ static void gx2_free(void *data)
14931494
if (!wiiu)
14941495
return;
14951496

1496-
/* clear leftover image */
1497-
GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f);
1498-
GX2CopyColorBufferToScanBuffer(&wiiu->color_buffer, GX2_SCAN_TARGET_DRC);
1499-
GX2CopyColorBufferToScanBuffer(&wiiu->color_buffer, GX2_SCAN_TARGET_TV);
1497+
if (ProcUIInForeground()) {
1498+
/* clear leftover image */
1499+
GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f);
1500+
GX2CopyColorBufferToScanBuffer(&wiiu->color_buffer, GX2_SCAN_TARGET_DRC);
1501+
GX2CopyColorBufferToScanBuffer(&wiiu->color_buffer, GX2_SCAN_TARGET_TV);
15001502

1501-
GX2SwapScanBuffers();
1502-
GX2Flush();
1503-
GX2DrawDone();
1504-
GX2WaitForVsync();
1505-
GX2Shutdown();
1503+
GX2SwapScanBuffers();
1504+
GX2Flush();
1505+
GX2DrawDone();
1506+
GX2WaitForVsync();
15061507

1507-
GX2SetTVEnable(GX2_DISABLE);
1508-
GX2SetDRCEnable(GX2_DISABLE);
1508+
GX2SetTVEnable(GX2_DISABLE);
1509+
GX2SetDRCEnable(GX2_DISABLE);
1510+
}
1511+
GX2Shutdown();
15091512

15101513
GX2DestroyShader(&frame_shader);
15111514
GX2DestroyShader(&tex_shader);

libretro-common/vfs/vfs_implementation.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,6 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(
475475
stream->buf = (char*)memalign(0x40, bufsize);
476476
if (stream->fp)
477477
setvbuf(stream->fp, stream->buf, _IOFBF, bufsize);
478-
stream->buf = (char*)calloc(1, 0x4000);
479-
if (stream->fp)
480-
setvbuf(stream->fp, stream->buf, _IOFBF, 0x4000);
481478
}
482479
#endif
483480
}

wiiu/system/memory.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
****************************************************************************/
1717
#include <malloc.h>
18-
#include <string.h>
1918
#include "memory.h"
2019
#include <coreinit/memheap.h>
2120
#include <coreinit/memexpheap.h>
@@ -81,7 +80,7 @@ void * MEM1_alloc(unsigned int size, unsigned int align)
8180

8281
void MEM1_free(void *ptr)
8382
{
84-
if (ptr)
83+
if (ptr && ProcUIInForeground())
8584
MEMFreeToExpHeap(mem1_heap, ptr);
8685
}
8786

@@ -94,6 +93,6 @@ void * MEMBucket_alloc(unsigned int size, unsigned int align)
9493

9594
void MEMBucket_free(void *ptr)
9695
{
97-
if (ptr)
96+
if (ptr && ProcUIInForeground())
9897
MEMFreeToExpHeap(bucket_heap, ptr);
9998
}

0 commit comments

Comments
 (0)