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+
231252static 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
@@ -322,24 +343,26 @@ static void frontend_wiiu_exec(const char *path, bool should_load_content)
322343 argv_buf = NULL ;
323344}
324345
346+ #ifdef IS_SALAMANDER
325347static void frontend_wiiu_exitspawn (char * s , size_t len , char * args )
326348{
327- bool should_load_content = false;
328- #ifndef IS_SALAMANDER
329- if ( wiiu_fork_mode == FRONTEND_FORK_NONE )
330- return ;
331-
332- switch ( wiiu_fork_mode )
333- {
334- case FRONTEND_FORK_CORE_WITH_ARGS :
335- should_load_content = true ;
336- break ;
337- default :
338- break ;
349+ frontend_wiiu_exec ( s , false) ;
350+ while ( check_proc ());
351+ }
352+ #else /* ifndef IS_SALAMANDER */
353+ static void frontend_wiiu_exitspawn ( char * s , size_t len , char * args )
354+ {
355+ if ( wiiu_fork_mode == FRONTEND_FORK_NONE ) {
356+ /* Exit to menu */
357+ SYSLaunchMenu () ;
358+ } else {
359+ /* Load a core */
360+ frontend_wiiu_exec ( s , wiiu_fork_mode == FRONTEND_FORK_CORE_WITH_ARGS ) ;
339361 }
340- #endif
341- frontend_wiiu_exec ( s , should_load_content );
362+
363+ while ( check_proc () );
342364}
365+ #endif /* IS_SALAMANDER */
343366
344367#ifndef IS_SALAMANDER
345368static bool frontend_wiiu_set_fork (enum frontend_fork fork_mode )
@@ -451,7 +474,7 @@ int main(int argc, char **argv)
451474static void main_setup (void )
452475{
453476 memoryInitialize ();
454- init_os_exceptions ();
477+ // init_os_exceptions();
455478 init_logging ();
456479 init_filesystems ();
457480 init_pad_libraries ();
@@ -464,35 +487,16 @@ static void main_teardown(void)
464487 deinit_pad_libraries ();
465488 deinit_filesystems ();
466489 deinit_logging ();
467- deinit_os_exceptions ();
490+ // deinit_os_exceptions();
468491 memoryRelease ();
469492}
470493
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;
479494static bool in_aroma = false;
495+ static void * procui_mem1Storage = NULL ;
496+ static void * procui_bucketStorage = NULL ;
480497
481498static void proc_setup (void )
482499{
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-
496500 /* Detect Aroma explicitly (it's possible to run under H&S while using Tiramisu) */
497501 OSDynLoad_Module rpxModule ;
498502 if (OSDynLoad_Acquire ("homebrew_rpx_loader" , & rpxModule ) == OS_DYNLOAD_OK )
@@ -502,33 +506,33 @@ static void proc_setup(void)
502506 }
503507
504508 ProcUIInit (& proc_save_callback );
509+
510+ uint32_t addr = 0 ;
511+ uint32_t size = 0 ;
512+ if (OSGetMemBound (OS_MEM1 , & addr , & size ) == 0 ) {
513+ procui_mem1Storage = malloc (size );
514+ if (procui_mem1Storage ) {
515+ ProcUISetMEM1Storage (procui_mem1Storage , size );
516+ }
517+ }
518+ if (OSGetForegroundBucketFreeArea (& addr , & size )) {
519+ procui_bucketStorage = malloc (size );
520+ if (procui_bucketStorage ) {
521+ ProcUISetBucketStorage (procui_bucketStorage , size );
522+ }
523+ }
505524}
506525
507526static void proc_exit (void )
508527{
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- }
528+ if (procui_mem1Storage ) {
529+ free (procui_mem1Storage );
530+ procui_mem1Storage = NULL ;
531+ }
532+ if (procui_bucketStorage ) {
533+ free (procui_bucketStorage );
534+ procui_bucketStorage = NULL ;
530535 }
531-
532536 ProcUIShutdown ();
533537}
534538
@@ -600,7 +604,10 @@ static void main_loop(void)
600604 OSTime start_time ;
601605 int status ;
602606
603- for (;;)
607+ bool home_menu_allowed = true;
608+ OSEnableHomeButtonMenu (TRUE);
609+
610+ while (check_proc ())
604611 {
605612 if (video_driver_get_ptr ())
606613 {
@@ -612,8 +619,22 @@ static void main_loop(void)
612619
613620 status = runloop_iterate ();
614621
615- if (status == -1 )
622+ // TODO: make this less ugly...
623+ if ((runloop_get_flags () & RUNLOOP_FLAG_CORE_RUNNING )) {
624+ if (home_menu_allowed ) {
625+ OSEnableHomeButtonMenu (FALSE);
626+ home_menu_allowed = false;
627+ }
628+ } else {
629+ if (!home_menu_allowed ) {
630+ OSEnableHomeButtonMenu (TRUE);
631+ home_menu_allowed = true;
632+ }
633+ }
634+
635+ if (status == -1 ) {
616636 break ;
637+ }
617638 }
618639}
619640#endif
0 commit comments