Skip to content

Commit 526c166

Browse files
committed
Add wii platform (untested CI and executable)
1 parent f6bab5a commit 526c166

6 files changed

Lines changed: 320 additions & 3 deletions

File tree

.github/workflows/build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ jobs:
107107
path: |
108108
platform/wiiu/*.rpx
109109
110+
wii-standalone:
111+
name: Wii
112+
runs-on: ubuntu-latest
113+
114+
steps:
115+
- name: Checkout
116+
uses: actions/checkout@v4
117+
with:
118+
submodules : recursive
119+
120+
- name: Build
121+
run: |
122+
docker run -e ENABLE_COMPATIBILITY_REPORTING -v $GITHUB_WORKSPACE:/build_dir devkitpro/devkitppc /bin/bash -ex /build_dir/.github/workflows/buildWii.sh
123+
- uses: actions/upload-artifact@v4
124+
with:
125+
name: Nintendo Wii
126+
path: |
127+
platform/wii/*.dol
128+
110129
vita-standalone:
111130
name: Vita
112131
runs-on: ubuntu-latest

.github/workflows/buildWii.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source /etc/profile.d/devkit-env.sh
2+
3+
cd /build_dir
4+
5+
dkp-pacman -Syyu --noconfirm wii-sdl2 wii-sdl2_gfx wii-sdl2_mixer wii-sdl2_ttf wii-sdl2_image
6+
7+
#Build dol
8+
make wii

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ source/carts.zip
4949
platform/libretro/fake08_libretro.dylib
5050
platform/libretro/libs/
5151
platform/libretro/obj/
52+
platform/wii/FAKE-08.dol
5253
.DS_Store
5354

55+

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export APP_VERSION = v$(V_MAJOR).$(V_MINOR).$(V_PATCH).$(V_BUILD)
1515
export SOURCES = ../../source ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng ../../libs/simpleini ../../libs/miniz
1616
export INCLUDES = ../../include ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng ../../libs/simpleini ../../libs/miniz
1717

18-
.PHONY: all 3ds switch wiiu vita sdl2 sdl windows clean clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-windows
18+
.PHONY: all 3ds switch wiiu wii vita sdl2 sdl windows clean clean-3ds clean-switch clean-wiiu clean-wii clean-vita clean-sdl2 clean-sdl clean-windows
1919

20-
all: 3ds switch wiiu vita bittboy windows
20+
all: 3ds switch wiiu wii vita bittboy windows
2121

22-
clean: clean-tests clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-bittboy clean-windows
22+
clean: clean-tests clean-3ds clean-switch clean-wiiu clean-wii clean-vita clean-sdl2 clean-sdl clean-bittboy clean-windows
2323

2424
clean-3ds:
2525
@$(MAKE) -C platform/3ds clean
@@ -30,6 +30,9 @@ clean-switch:
3030
clean-wiiu:
3131
@$(MAKE) -C platform/wiiu clean
3232

33+
clean-wii:
34+
@$(MAKE) -C platform/wii clean
35+
3336
clean-vita:
3437
@$(MAKE) -C platform/vita clean
3538

@@ -69,6 +72,9 @@ switch:
6972
wiiu:
7073
@$(MAKE) -C platform/wiiu
7174

75+
wii:
76+
@$(MAKE) -C platform/wii
77+
7278
vita:
7379
@$(MAKE) -C platform/vita
7480

platform/wii/Makefile

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#---------------------------------------------------------------------------------
2+
# FAKE-08 Wii Makefile
3+
#---------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITPPC)),)
6+
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
7+
endif
8+
9+
include $(DEVKITPPC)/wii_rules
10+
11+
#---------------------------------------------------------------------------------
12+
# TARGET is the name of the output
13+
# BUILD is the directory where object files & intermediate files will be placed
14+
# SOURCES is a list of directories containing source code
15+
# INCLUDES is a list of directories containing header files
16+
#---------------------------------------------------------------------------------
17+
TARGET := FAKE-08
18+
BUILD := build
19+
SOURCES := ${SOURCES} ../SDL2Common/source source
20+
INCLUDES := ${INCLUDES} ../SDL2Common/source source
21+
22+
#---------------------------------------------------------------------------------
23+
# options for code generation
24+
#---------------------------------------------------------------------------------
25+
26+
CFLAGS := -g -Wall -O2 -ffunction-sections -MMD -MP -DVER_STR=\"$(APP_VERSION)\" \
27+
-ffast-math \
28+
$(MACHDEP)
29+
30+
CC := $(CXX)
31+
32+
CFLAGS += $(INCLUDE) -D__WII__ -DGEKKO
33+
34+
CXXFLAGS := $(CFLAGS) -std=gnu++17
35+
36+
ASFLAGS := -g $(MACHDEP)
37+
LDFLAGS := -g $(MACHDEP) -Wl,-Map,$(notdir $*.map)
38+
39+
LIBS := -lSDL2 -lwiikeyboard -lwiiuse -lbte -lfat -laesnd -logc -lm -lz
40+
41+
#---------------------------------------------------------------------------------
42+
# list of directories containing libraries, this must be the top level
43+
# containing include and lib
44+
#---------------------------------------------------------------------------------
45+
PORTLIBS ?= $(DEVKITPRO)/portlibs/wii
46+
LIBDIRS := $(PORTLIBS)
47+
48+
49+
#---------------------------------------------------------------------------------
50+
# no real need to edit anything past this point unless you need to add additional
51+
# rules for different file extensions
52+
#---------------------------------------------------------------------------------
53+
ifneq ($(BUILD),$(notdir $(CURDIR)))
54+
#---------------------------------------------------------------------------------
55+
56+
export OUTPUT := $(CURDIR)/$(TARGET)
57+
export TOPDIR := $(CURDIR)
58+
59+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
60+
export DEPSDIR := $(CURDIR)/$(BUILD)
61+
62+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
63+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
64+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
65+
66+
#---------------------------------------------------------------------------------
67+
# use CXX for linking C++ projects, CC for standard C
68+
#---------------------------------------------------------------------------------
69+
ifeq ($(strip $(CPPFILES)),)
70+
#---------------------------------------------------------------------------------
71+
export LD := $(CC)
72+
#---------------------------------------------------------------------------------
73+
else
74+
#---------------------------------------------------------------------------------
75+
export LD := $(CXX)
76+
#---------------------------------------------------------------------------------
77+
endif
78+
#---------------------------------------------------------------------------------
79+
80+
export SRCFILES := $(CPPFILES) $(CFILES) $(SFILES)
81+
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
82+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
83+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
84+
-I$(CURDIR)/$(BUILD) \
85+
-I$(LIBOGC_INC)
86+
87+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
88+
-L$(LIBOGC_LIB)
89+
90+
.PHONY: $(BUILD) clean all
91+
92+
#---------------------------------------------------------------------------------
93+
all: $(BUILD)
94+
95+
$(BUILD): $(SRCFILES)
96+
@[ -d $@ ] || mkdir -p $@
97+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
98+
99+
#---------------------------------------------------------------------------------
100+
clean:
101+
@echo clean ...
102+
@rm -fr $(BUILD) $(TARGET).dol $(TARGET).elf
103+
104+
#---------------------------------------------------------------------------------
105+
else
106+
.PHONY: all
107+
108+
DEPENDS := $(OFILES:.o=.d)
109+
110+
#---------------------------------------------------------------------------------
111+
# main targets
112+
#---------------------------------------------------------------------------------
113+
all : $(OUTPUT).dol
114+
115+
$(OUTPUT).dol : $(OUTPUT).elf
116+
117+
$(OUTPUT).elf : $(OFILES)
118+
119+
-include $(DEPENDS)
120+
121+
#---------------------------------------------------------------------------------
122+
endif
123+
#---------------------------------------------------------------------------------

platform/wii/source/WiiHost.cpp

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#include <gccore.h>
2+
#include <wiiuse/wpad.h>
3+
#include <fat.h>
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <dirent.h>
7+
#include <errno.h>
8+
#include <unistd.h>
9+
#include <sys/stat.h>
10+
#include <sys/types.h>
11+
12+
#include <fstream>
13+
#include <iostream>
14+
#include <vector>
15+
#include <string>
16+
using namespace std;
17+
18+
#include "../../SDL2Common/source/sdl2basehost.h"
19+
#include "../../../source/hostVmShared.h"
20+
#include "../../../source/nibblehelpers.h"
21+
#include "../../../source/filehelpers.h"
22+
#include "../../../source/logger.h"
23+
24+
// sdl
25+
#include <SDL2/SDL.h>
26+
27+
#define WINDOW_SIZE_X 640
28+
#define WINDOW_SIZE_Y 480
29+
30+
#define WINDOW_FLAGS SDL_WINDOW_FULLSCREEN
31+
#define RENDERER_FLAGS SDL_RENDERER_ACCELERATED
32+
#define PIXEL_FORMAT SDL_PIXELFORMAT_RGBA8888
33+
34+
string _wiiSettingsDir = "fake08";
35+
string _wiiSettingsPrefix = "fake08/";
36+
string _wiiCartDir = "sd:/p8carts";
37+
string _wiiCustomBiosLua = "cartpath = \"sd:/p8carts/\"\n"
38+
"pausebtn = \"+\"";
39+
40+
Host::Host(int windowWidth, int windowHeight)
41+
{
42+
fatInitDefault();
43+
44+
struct stat st = {0};
45+
46+
// Try SD first, fallback to USB
47+
if (chdir("sd:/") != 0) {
48+
chdir("usb:/");
49+
}
50+
51+
if (stat(_wiiSettingsDir.c_str(), &st) == -1) {
52+
mkdir(_wiiSettingsDir.c_str(), 0777);
53+
}
54+
55+
string cartdatadir = _wiiSettingsPrefix + "cdata";
56+
if (stat(cartdatadir.c_str(), &st) == -1) {
57+
mkdir(cartdatadir.c_str(), 0777);
58+
}
59+
60+
setPlatformParams(
61+
WINDOW_SIZE_X,
62+
WINDOW_SIZE_Y,
63+
WINDOW_FLAGS,
64+
RENDERER_FLAGS,
65+
PIXEL_FORMAT,
66+
_wiiSettingsPrefix,
67+
_wiiCustomBiosLua,
68+
_wiiCartDir
69+
);
70+
}
71+
72+
InputState_t Host::scanInput(){
73+
currKDown = 0;
74+
uint8_t kUp = 0;
75+
stretchKeyPressed = false;
76+
77+
SDL_Event event;
78+
while (SDL_PollEvent(&event)) {
79+
switch (event.type) {
80+
case SDL_JOYBUTTONDOWN:
81+
switch (event.jbutton.button) {
82+
case 0: currKDown |= P8_KEY_X; break; // A
83+
case 1: currKDown |= P8_KEY_O; break; // B
84+
case 4: stretchKeyPressed = true; break; // -
85+
case 5: currKDown |= P8_KEY_PAUSE; break; // +
86+
case 6: quit = 1; break; // Home
87+
case 7: currKDown |= P8_KEY_UP; break;
88+
case 8: currKDown |= P8_KEY_DOWN; break;
89+
case 9: currKDown |= P8_KEY_LEFT; break;
90+
case 10: currKDown |= P8_KEY_RIGHT; break;
91+
}
92+
break;
93+
case SDL_JOYBUTTONUP:
94+
switch (event.jbutton.button) {
95+
case 0: kUp |= P8_KEY_X; break;
96+
case 1: kUp |= P8_KEY_O; break;
97+
case 5: kUp |= P8_KEY_PAUSE; break;
98+
case 7: kUp |= P8_KEY_UP; break;
99+
case 8: kUp |= P8_KEY_DOWN; break;
100+
case 9: kUp |= P8_KEY_LEFT; break;
101+
case 10: kUp |= P8_KEY_RIGHT; break;
102+
}
103+
break;
104+
case SDL_QUIT:
105+
quit = 1;
106+
break;
107+
}
108+
}
109+
110+
currKHeld |= currKDown;
111+
currKHeld ^= kUp;
112+
113+
return InputState_t {
114+
currKDown,
115+
currKHeld,
116+
0, 0, 0, // No mouse/touch for now
117+
false, "" // No keyboard for now
118+
};
119+
}
120+
121+
vector<string> Host::listcarts(){
122+
vector<string> carts;
123+
124+
DIR *dir;
125+
struct dirent *ent;
126+
if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
127+
while ((ent = readdir (dir)) != NULL) {
128+
if (isCartFile(ent->d_name)){
129+
carts.push_back(ent->d_name);
130+
}
131+
}
132+
closedir (dir);
133+
}
134+
135+
return carts;
136+
}
137+
138+
std::vector<std::string> Host::listdirs() {
139+
std::vector<std::string> dirs;
140+
141+
DIR *dir;
142+
struct dirent *ent;
143+
if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
144+
while ((ent = readdir (dir)) != NULL) {
145+
if (ent->d_name[0] == '.') {
146+
continue;
147+
}
148+
std::string fullPath = _cartDirectory + "/" + ent->d_name;
149+
DIR* testDir = opendir(fullPath.c_str());
150+
if (testDir != NULL) {
151+
closedir(testDir);
152+
dirs.push_back(ent->d_name);
153+
}
154+
}
155+
closedir (dir);
156+
}
157+
158+
return dirs;
159+
}

0 commit comments

Comments
 (0)