Wii/Gamecube: Add rudimentary controls, add makefiles, fix launcher rendering being completely wrong colours

This commit is contained in:
UnknownShadow200 2023-07-01 13:30:39 +10:00
parent b6985480e1
commit 2caa47452e
7 changed files with 242 additions and 44 deletions

View File

@ -1,4 +1,4 @@
C_SOURCES:=$(wildcard *.c) C_SOURCES:=$(wildcard src/*.c)
C_OBJECTS:=$(patsubst %.c, %.o, $(C_SOURCES)) C_OBJECTS:=$(patsubst %.c, %.o, $(C_SOURCES))
OBJECTS:=$(C_OBJECTS) OBJECTS:=$(C_OBJECTS)
ENAME=ClassiCube ENAME=ClassiCube
@ -148,9 +148,9 @@ irix:
psp: psp:
$(MAKE) ClassiCube.elf PLAT=psp $(MAKE) ClassiCube.elf PLAT=psp
3ds: 3ds:
$(MAKE) -f Makefile_3DS PLAT=3ds $(MAKE) -f src/Makefile_3DS PLAT=3ds
wii: wii:
$(MAKE) -f Makefile_wii PLAT=wii $(MAKE) -f src/Makefile_wii PLAT=wii
gamecube: gamecube:
$(MAKE) -f Makefile_gamecube PLAT=gamecube $(MAKE) -f Makefile_gamecube PLAT=gamecube
@ -163,14 +163,13 @@ $(ENAME): $(OBJECTS)
$(C_OBJECTS): %.o : %.c $(C_OBJECTS): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
interop_cocoa.o: interop_cocoa.m src/interop_cocoa.o: src/interop_cocoa.m
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
Window_Haiku.o: Window_Haiku.cpp src/Window_Haiku.o: src/Window_Haiku.cpp
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
# PSP requires fixups # PSP requires fixups
ClassiCube.elf : $(ENAME) ClassiCube.elf : $(ENAME)
cp $(ENAME) ClassiCube.elf cp $(ENAME) ClassiCube.elf
psp-fixup-imports ClassiCube.elf psp-fixup-imports ClassiCube.elf

View File

@ -197,28 +197,28 @@ The generated javascript file has some issues. [See here for how to fix](doc/com
#### PSP #### PSP
cd into `src` directory, then run `make psp`. You'll need [pspsdk](https://github.com/pspdev/pspsdk) Run `make psp`. You'll need [pspsdk](https://github.com/pspdev/pspsdk)
The PSP port needs assistance from someone experienced with PSP homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord) The PSP port needs assistance from someone experienced with PSP homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord)
#### 3DS #### 3DS
cd into `src` directory, then run `make 3ds`. You'll need [libctru](https://github.com/devkitPro/libctru) Run `make 3ds`. You'll need [libctru](https://github.com/devkitPro/libctru)
The 3DS port needs assistance from someone experienced with 3DS homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord) The 3DS port needs assistance from someone experienced with 3DS homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord)
#### GameCube
Use a slighly modified standard GameCube makefile. You'll need [libogc](https://github.com/devkitPro/libogc)
The GC port needs assistance from someone experienced with GC homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord)
#### Wii #### Wii
Use a slighly modified standard Wii makefile. You'll need [libogc](https://github.com/devkitPro/libogc) Run `make wii`. You'll need [libogc](https://github.com/devkitPro/libogc)
The Wii port needs assistance from someone experienced with Wii homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord) The Wii port needs assistance from someone experienced with Wii homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord)
#### GameCube
Run `make gamecube`. You'll need [libogc](https://github.com/devkitPro/libogc)
The GC port needs assistance from someone experienced with GC homebrew development - if you're interested, please get in contact with me. (`unknownshadow200` on Discord)
##### Other ##### Other
You'll have to write the necessary code. You should read portability.md in doc folder. You'll have to write the necessary code. You should read portability.md in doc folder.

View File

@ -4,43 +4,38 @@ endif
include $(DEVKITARM)/3ds_rules include $(DEVKITARM)/3ds_rules
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# configurable options # configurable options
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
APP_ICON := $(CURDIR)"/../misc/CC_48x48.png" APP_ICON := $(CURDIR)/misc/CC_48x48.png
APP_TITLE := ClassiCube APP_TITLE := ClassiCube
APP_DESCRIPTION := Simple block building sandbox APP_DESCRIPTION := Simple block building sandbox
APP_AUTHOR := UnknownShadow200 APP_AUTHOR := UnknownShadow200
TARGET := ClassiCube-3ds TARGET := ClassiCube-3ds
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# compilation options # compilation input
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFILES := $(wildcard *.c) DEPSDIR := $(CURDIR)/build
SFILES := $(wildcard *.s) CFILES := $(wildcard src/*.c)
PICAFILES := $(wildcard *.v.pica) SFILES := $(wildcard src/*.s)
PICAFILES := $(wildcard src/*.v.pica)
LIBS := -lcitro3d -lctru -lm SMDH_FILE := src/ClassiCube.smdh
export LD := $(CC)
DEPSDIR := $(CURDIR)/build
OFILES_SOURCES := $(CFILES:.c=.o) $(SFILES:.s=.o) OFILES_SOURCES := $(CFILES:.c=.o) $(SFILES:.s=.o)
OFILES_SHADERS := $(PICAFILES:.v.pica=.shbin.o) OFILES_SHADERS := $(PICAFILES:.v.pica=.shbin.o)
OFILES := $(OFILES_SHADERS) $(OFILES_SOURCES) OFILES := $(OFILES_SHADERS) $(OFILES_SOURCES)
INCLUDE := $(foreach dir,$(CTRULIB),-I$(dir)/include) INCLUDE := $(foreach dir,$(CTRULIB),-I$(dir)/include)
LIBPATHS := $(foreach dir,$(CTRULIB),-L$(dir)/lib) LIBPATHS := $(foreach dir,$(CTRULIB),-L$(dir)/lib)
_3DSXDEPS := $(if $(NO_SMDH),,$(CURDIR)/$(TARGET).smdh) _3DSXFLAGS += --smdh=$(SMDH_FILE)
ifeq ($(strip $(NO_SMDH)),)
export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
endif
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# code generation options # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
@ -49,23 +44,27 @@ CFLAGS := -g -Wall -O2 -mword-relocations -ffunction-sections \
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lcitro3d -lctru -lm
LD := $(CC)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# main targets # main targets
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
default: $(DEPSDIR) $(TARGET).3dsx default: $(DEPSDIR) $(TARGET).3dsx
$(DEPSDIR):
@mkdir -p $@
clean: clean:
@rm $(OFILES) $(TARGET).3dsx $(TARGET).smdh $(TARGET).elf @rm $(OFILES) $(TARGET).elf $(TARGET).3dsx $(SMDH_FILE)
$(TARGET).elf : $(OFILES) $(TARGET).elf : $(OFILES)
$(TARGET).3dsx : $(TARGET).elf $(_3DSXDEPS) $(TARGET).3dsx : $(TARGET).elf $(SMDH_FILE)
Graphics_3DS.o : $(OFILES_SHADERS) Graphics_3DS.o : $(OFILES_SHADERS)
$(DEPSDIR):
@mkdir -p $@
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# rules for assembling GPU shaders # rules for assembling GPU shaders

51
src/Makefile_gamecube Normal file
View File

@ -0,0 +1,51 @@
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/gamecube_rules
#---------------------------------------------------------------------------------
# configurable options
#---------------------------------------------------------------------------------
TARGET := ClassiCube-gc
SOURCES := src
#---------------------------------------------------------------------------------
# compilation input
#---------------------------------------------------------------------------------
CFILES := $(wildcard src/*.c)
sFILES := $(wildcard src/*.s)
SFILES := $(wildcard src/*.S)
OFILES := $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
INCLUDE := -I$(LIBOGC_INC)
LIBPATHS := -L$(LIBOGC_LIB)
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
DEPSDIR := $(CURDIR)/build
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
LIBS := -lbba -lfat -logc -lm
LD := $(CC)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
default: $(DEPSDIR) $(TARGET).dol
$(DEPSDIR):
mkdir -p $@
clean:
@rm $(OFILES) $(TARGET).elf $(TARGET).dol
$(TARGET).elf: $(OFILES)
$(TARGET).dol: $(TARGET).elf

51
src/Makefile_wii Normal file
View File

@ -0,0 +1,51 @@
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
# configurable options
#---------------------------------------------------------------------------------
TARGET := ClassiCube-wii
SOURCES := src
#---------------------------------------------------------------------------------
# compilation input
#---------------------------------------------------------------------------------
CFILES := $(wildcard src/*.c)
sFILES := $(wildcard src/*.s)
SFILES := $(wildcard src/*.S)
OFILES := $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
INCLUDE := -I$(LIBOGC_INC)
LIBPATHS := -L$(LIBOGC_LIB)
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
DEPSDIR := $(CURDIR)/build
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
LIBS := -lwiikeyboard -lwiiuse -lbte -lfat -logc -lm
LD := $(CC)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
default: $(DEPSDIR) $(TARGET).dol
$(DEPSDIR):
mkdir -p $@
clean:
@rm $(OFILES) $(TARGET).elf $(TARGET).dol
$(TARGET).elf: $(OFILES)
$(TARGET).dol: $(TARGET).elf

View File

@ -6,7 +6,11 @@
#include "Funcs.h" #include "Funcs.h"
#include "Bitmap.h" #include "Bitmap.h"
#include "Errors.h" #include "Errors.h"
#include "ExtMath.h"
#include <gccore.h> #include <gccore.h>
#if defined HW_RVL
#include <wiiuse/wpad.h>
#endif
static void* xfb; static void* xfb;
static GXRModeObj* rmode; static GXRModeObj* rmode;
@ -45,7 +49,13 @@ void Window_Init(void) {
WindowInfo.Width = rmode->fbWidth; WindowInfo.Width = rmode->fbWidth;
WindowInfo.Height = rmode->xfbHeight; WindowInfo.Height = rmode->xfbHeight;
//WindowInfo.Focused = true; WindowInfo.Focused = true;
#if defined HW_RVL
WPAD_Init();
#elif defined HW_DOL
PAD_Init();
#endif
} }
static void DoCreateWindow(int _3d) { static void DoCreateWindow(int _3d) {
@ -70,9 +80,71 @@ void Window_Close(void) {
/* TODO implement */ /* TODO implement */
} }
#if defined HW_RVL
void Window_ProcessEvents(void) { void Window_ProcessEvents(void) {
/* TODO implement */ /* TODO implement */
WPAD_ScanPads();
u32 mods = WPAD_ButtonsDown(0) | WPAD_ButtonsHeld(0);
Input_SetNonRepeatable(KeyBinds[KEYBIND_PLACE_BLOCK], mods & WPAD_BUTTON_1);
Input_SetNonRepeatable(KeyBinds[KEYBIND_DELETE_BLOCK], mods & WPAD_BUTTON_2);
Input_SetNonRepeatable(KeyBinds[KEYBIND_JUMP], mods & WPAD_BUTTON_A);
Input_SetNonRepeatable(KeyBinds[KEYBIND_CHAT], mods & WPAD_BUTTON_B);
Input_SetNonRepeatable(KeyBinds[KEYBIND_INVENTORY], mods & WPAD_BUTTON_PLUS);
Input_SetNonRepeatable(IPT_ENTER, mods & WPAD_BUTTON_HOME);
Input_SetNonRepeatable(IPT_ESCAPE, mods & WPAD_BUTTON_MINUS);
Input_SetNonRepeatable(KeyBinds[KEYBIND_LEFT], mods & WPAD_BUTTON_LEFT);
Input_SetNonRepeatable(IPT_LEFT, mods & WPAD_BUTTON_LEFT);
Input_SetNonRepeatable(KeyBinds[KEYBIND_RIGHT], mods & WPAD_BUTTON_RIGHT);
Input_SetNonRepeatable(IPT_RIGHT, mods & WPAD_BUTTON_RIGHT);
Input_SetNonRepeatable(KeyBinds[KEYBIND_FORWARD], mods & WPAD_BUTTON_UP);
Input_SetNonRepeatable(IPT_UP, mods & WPAD_BUTTON_UP);
Input_SetNonRepeatable(KeyBinds[KEYBIND_BACK], mods & WPAD_BUTTON_DOWN);
Input_SetNonRepeatable(IPT_DOWN, mods & WPAD_BUTTON_DOWN);
} }
#elif defined HW_DOL
void Window_ProcessEvents(void) {
/* TODO implement */
PADStatus pads[4];
PAD_Read(pads);
int mods = pads[0].button;
int dx = pads[0].stickX;
int dy = pads[0].stickY;
if (Input_RawMode && (Math_AbsI(dx) > 1 || Math_AbsI(dy) > 1)) {
Event_RaiseRawMove(&PointerEvents.RawMoved, dx / 32.0f, dy / 32.0f);
}
Input_SetNonRepeatable(KeyBinds[KEYBIND_PLACE_BLOCK], mods & PAD_TRIGGER_L);
Input_SetNonRepeatable(KeyBinds[KEYBIND_DELETE_BLOCK], mods & PAD_TRIGGER_R);
Input_SetNonRepeatable(KeyBinds[KEYBIND_JUMP], mods & PAD_BUTTON_A);
Input_SetNonRepeatable(KeyBinds[KEYBIND_CHAT], mods & PAD_BUTTON_X);
Input_SetNonRepeatable(KeyBinds[KEYBIND_INVENTORY], mods & PAD_BUTTON_Y);
// PAD_BUTTON_B
Input_SetNonRepeatable(IPT_ENTER, mods & PAD_BUTTON_START);
Input_SetNonRepeatable(IPT_ESCAPE, mods & PAD_TRIGGER_Z);
// fake tab with PAD_BUTTON_B for Launcher too
Input_SetNonRepeatable(IPT_TAB, mods & PAD_BUTTON_B);
Input_SetNonRepeatable(KeyBinds[KEYBIND_LEFT], mods & PAD_BUTTON_LEFT);
Input_SetNonRepeatable(IPT_LEFT, mods & PAD_BUTTON_LEFT);
Input_SetNonRepeatable(KeyBinds[KEYBIND_RIGHT], mods & PAD_BUTTON_RIGHT);
Input_SetNonRepeatable(IPT_RIGHT, mods & PAD_BUTTON_RIGHT);
Input_SetNonRepeatable(KeyBinds[KEYBIND_FORWARD], mods & PAD_BUTTON_UP);
Input_SetNonRepeatable(IPT_UP, mods & PAD_BUTTON_UP);
Input_SetNonRepeatable(KeyBinds[KEYBIND_BACK], mods & PAD_BUTTON_DOWN);
Input_SetNonRepeatable(IPT_DOWN, mods & PAD_BUTTON_DOWN);
}
#endif
static void Cursor_GetRawPos(int* x, int* y) { static void Cursor_GetRawPos(int* x, int* y) {
/* TODO implement */ /* TODO implement */
@ -106,8 +178,29 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) {
// TODO: Get rid of this complexity and use the 3D API instead..
// https://github.com/devkitPro/gamecube-examples/blob/master/graphics/fb/pageflip/source/flip.c
static u32 CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2)
{
int y1, cb1, cr1, y2, cb2, cr2, cb, cr;
y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000;
cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000;
cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000;
y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000;
cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000;
cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000;
cb = (cb1 + cb2) >> 1;
cr = (cr1 + cr2) >> 1;
return (y1 << 24) | (cb << 16) | (y2 << 8) | cr;
}
void Window_DrawFramebuffer(Rect2D r) { void Window_DrawFramebuffer(Rect2D r) {
VIDEO_WaitVSync(); VIDEO_WaitVSync();
r.X &= ~0x01; // round down to nearest even horizontal index
// TODO XFB is raw yuv, but is absolutely a pain to work with.. // TODO XFB is raw yuv, but is absolutely a pain to work with..
for (int y = r.Y; y < r.Y + r.Height; y++) for (int y = r.Y; y < r.Y + r.Height; y++)
@ -115,8 +208,13 @@ void Window_DrawFramebuffer(Rect2D r) {
cc_uint32* src = fb_bmp.scan0 + y * fb_bmp.width + r.X; cc_uint32* src = fb_bmp.scan0 + y * fb_bmp.width + r.X;
u16* dst = (u16*)xfb + y * rmode->fbWidth + r.X; u16* dst = (u16*)xfb + y * rmode->fbWidth + r.X;
for (int x = 0; x < r.Width; x++) for (int x = 0; x < r.Width / 2; x++) {
dst[x] = src[x]; cc_uint32 rgb0 = src[(x<<1) + 0];
cc_uint32 rgb1 = src[(x<<1) + 1];
((u32*)dst)[x] = CvtRGB(BitmapCol_R(rgb0), BitmapCol_G(rgb0), BitmapCol_B(rgb0),
BitmapCol_R(rgb1), BitmapCol_G(rgb1), BitmapCol_B(rgb1));
}
} }
} }

View File

@ -60,7 +60,7 @@ void Window_ProcessEvents(void) {
int dx = pad.Lx - 127; int dx = pad.Lx - 127;
int dy = pad.Ly - 127; int dy = pad.Ly - 127;
if (Input_RawMode && (Math_AbsF(dx) > 1 || Math_AbsF(dy) > 1)) { if (Input_RawMode && (Math_AbsI(dx) > 1 || Math_AbsI(dy) > 1)) {
//Platform_Log2("RAW: %i, %i", &dx, &dy); //Platform_Log2("RAW: %i, %i", &dx, &dy);
Event_RaiseRawMove(&PointerEvents.RawMoved, dx / 32.0f, dy / 32.0f); Event_RaiseRawMove(&PointerEvents.RawMoved, dx / 32.0f, dy / 32.0f);
} }