libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
WiiPlatform.cpp
1/****************************************************************************
2 * Platform Abstraction Layer (OGC driver)
3 * Daryl Borth 2026
4 * WiiPlatform.cpp
5 ***************************************************************************/
6#include "WiiPlatform.h"
7
9{
10 this->config = config;
11
12 this->threadDriver = new OgcThreadDriver();
13 this->threadDriver->init();
14
15 this->videoDriver = new OgcVideoDriver();
16 this->videoDriver->init(config.canvasWidth, config.canvasHeight);
17
18 this->audioDriver = new OgcAudioDriver();
19 this->audioDriver->init();
20
21 this->inputDriver = new OgcInputDriver();
22 this->inputDriver->init();
23
24 this->fileSystemDriver = new WiiFileSystemDriver();
25 this->fileSystemDriver->init();
26
27#if LOGGING_ENABLED
28 this->logger = new Logger();
29 this->logger->registerBackend(LOGGER_OSREPORT, new OgcLoggerSysReport());
30 this->logger->registerBackend(LOGGER_UDP, new OgcLoggerUdp());
31 this->logger->registerBackend(LOGGER_SERIAL, new OgcLoggerUsbGecko());
32 this->logger->registerBackend(LOGGER_FILE, new LoggerFile());
33
34 LogConfig logConfig;
35 static const int deviceCandidates[] = { DEVICE_SD, DEVICE_USB };
36
37 const char * mountPath = FindFirstMountedPath(this->fileSystemDriver, deviceCandidates, 2);
38
39 if(mountPath[0] != '\0') {
40 // mountPath already ends in "/" (eg. "sd:/") - no separator needed.
41 snprintf(logConfig.filePath, sizeof(logConfig.filePath), "%sdebug.log", mountPath);
42 }
43
44 this->logger->init(logConfig);
45#endif
46}
47
49{
50 if (logger) {
51 logger->shutdown();
52 delete logger;
53 logger = nullptr;
54 }
55
56 if (fileSystemDriver) {
57 fileSystemDriver->shutdown();
58 delete fileSystemDriver;
59 fileSystemDriver = nullptr;
60 }
61
62 if (inputDriver) {
63 inputDriver->shutdown();
64 delete inputDriver;
65 inputDriver = nullptr;
66 }
67
68 if (audioDriver) {
69 audioDriver->shutdown();
70 delete audioDriver;
71 audioDriver = nullptr;
72 }
73
74 if (videoDriver) {
75 videoDriver->shutdown();
76 delete videoDriver;
77 videoDriver = nullptr;
78 }
79
80 if (threadDriver) {
81 threadDriver->shutdown();
82 delete threadDriver;
83 threadDriver = nullptr;
84 }
85}
86/****************************************************************************
87 * Shutdown/reset
88 ***************************************************************************/
89
90// Status::Exiting alone doesn't tell requestExit() what to do below
91static bool hardwarePowerOffRequested = false;
92
93void NotifyWiiShutdownRequested() { hardwarePowerOffRequested = true; platform->triggerExit(); }
94
95// shutdown() only tears down the HAL drivers - it has no opinion on what
96// should happen to the console afterward. requestExit() is where that
97// decision actually gets made: if the event that brought us here was a
98// real power button press (console or Wiimote), honor it with a proper
99// IOS-mediated power-off via SYS_ResetSystem rather than falling through
100// to a plain exit()
102{
103 this->shutdown();
104
105 if(hardwarePowerOffRequested)
106 SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, FALSE);
107 else
108 exit(0);
109}
110
111// No reset callback is registered - SYS_ResetButtonDown() (polled in
112// getSystemEvent() below) is a real libogc polling primitive, so there's
113// nothing for a callback to add here.
115{
116 if(platform->getStatus() == Status::Exiting)
118
119 static bool wasResetDown = false;
120 bool isResetDown = SYS_ResetButtonDown();
121 bool justPressed = isResetDown && !wasResetDown;
122 wasResetDown = isResetDown;
123
124 if(justPressed)
126
127 return SystemEvent::None;
128}
Log backend that appends to a file through the platform's devoptab path.
Definition LoggerFile.h:26
Central fan-out dispatcher.
Definition Logger.h:191
GC/Wii AudioDriver: AESND-based fixed voices for one-shots, wraps a GuiSoundOggPlayer for the backgro...
GC/Wii InputDriver: PAD (GameCube) / WPAD (Wiimote, Nunchuk, Classic, Wii U Pro Controller) plus a Wi...
Log backend writing to the console debug output via SYS_Report.
Non-blocking UDP log backend.
Log backend for a USB Gecko adapter over EXI, via usbgecko.c.
GC/Wii ThreadDriver, built on libogc's LWP threading primitives.
GC/Wii VideoDriver: raw GX, double-buffered XFB.
PlatformConfig config
Set by init() in every concrete Platform - store the passed-in config as the very first line of the o...
Definition Platform.h:117
Wii FileSystemDriver: hot-pluggable SD and up to 3 concurrent USB MSD plus DVD (ISO9660) and DEVICE_S...
void shutdown() override
Shuts down and releases all five drivers.
SystemEvent getSystemEvent() override
Current hardware/OS-level system event, if any.
void init(const PlatformConfig &config) override
Constructs and initializes all five drivers for this platform.
void requestExit() override
Tears down the platform (via shutdown()) and then performs whatever platform-appropriate action actua...
SystemEvent
A hardware/OS-level system event a Platform can report.
Definition Platform.h:37
@ ResetRequested
Reset button pressed (Wii only).
Definition Platform.h:44
@ ShutdownRequested
Power button pressed (console or, on Wii, a Wiimote) - or, on Wii U, the OS asking the app to exit.
Definition Platform.h:41
Full runtime configuration for the Logger.
Definition Logger.h:101
char filePath[1024]
Path of the log file for the file backend. Each platform's init() points this at debug....
Definition Logger.h:134
Settings passed to Platform::init().
Definition Platform.h:50