Skip to content

Commit 0f516d9

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 0f516d9

4 files changed

Lines changed: 98 additions & 78 deletions

File tree

frontend/drivers/platform_wiiu.c

Lines changed: 82 additions & 61 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
@@ -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
325347
static 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
345368
static bool frontend_wiiu_set_fork(enum frontend_fork fork_mode)
@@ -451,7 +474,7 @@ int main(int argc, char **argv)
451474
static 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;
479494
static bool in_aroma = false;
495+
static void* procui_mem1Storage = NULL;
496+
static void* procui_bucketStorage = NULL;
480497

481498
static 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

507526
static 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

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)