From fea510904008503c4c6d94d93936e899cfddf74d Mon Sep 17 00:00:00 2001 From: s <100468871+sctech-tr@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:56:04 +0300 Subject: [PATCH] Add files via upload --- Makefile | 154 +++++++++++++++++++++++++++++++++ Tutorial.pnproj | 1 + Tutorial.pnps | 1 + source/main.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 377 insertions(+) create mode 100644 Makefile create mode 100644 Tutorial.pnproj create mode 100644 Tutorial.pnps create mode 100644 source/main.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d0048bc --- /dev/null +++ b/Makefile @@ -0,0 +1,154 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) +endif + +include $(DEVKITPPC)/wii_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- + +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) +CXXFLAGS = $(CFLAGS) + +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lwiiuse -lbte -logc -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ + $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ + -L$(LIBOGC_LIB) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .jpg extension +#--------------------------------------------------------------------------------- +%.jpg.o : %.jpg +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +# This rule links in binary data +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +%.mod.o : %.mod +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/Tutorial.pnproj b/Tutorial.pnproj new file mode 100644 index 0000000..a7fe861 --- /dev/null +++ b/Tutorial.pnproj @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Tutorial.pnps b/Tutorial.pnps new file mode 100644 index 0000000..642ecd6 --- /dev/null +++ b/Tutorial.pnps @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..31892ee --- /dev/null +++ b/source/main.c @@ -0,0 +1,221 @@ +#include +#include +#include +#include +#include + +static void *xfb = NULL; +static GXRModeObj *rmode = NULL; + +//--------------------------------------------------------------------------------- +int main(int argc, char **argv) { +//--------------------------------------------------------------------------------- + // Some initializing stuff + // ------------------------------------------- + VIDEO_Init(); + WPAD_Init(); + PAD_Init(); + rmode = VIDEO_GetPreferredMode(NULL); + xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); + console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); + VIDEO_Configure(rmode); + VIDEO_SetNextFramebuffer(xfb); + VIDEO_SetBlack(false); + VIDEO_Flush(); + VIDEO_WaitVSync(); + if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); + printf("\x1b[2;0H"); + int homebutton = 0; + // ------------------------------------------- + printf("Text-based Controller Test v0.7-alpha\n"); + printf("Welcome! This is a really simple app that allows you to test your controllers\n"); + printf("Press the HOME button 3 times to exit.\n"); + + while(1) { + WPAD_ScanPads(); + PAD_ScanPads(); + + u32 pressed = WPAD_ButtonsDown(0); + u16 gcpressed = PAD_ButtonsDown(0); + u32 exp_type; + WPAD_Probe(0, &exp_type); + + if(exp_type == WPAD_EXP_NUNCHUK) { + if(pressed & WPAD_NUNCHUK_BUTTON_C) { + printf("Nunchuck: Button C pressed.\n"); + } + + if(pressed & WPAD_NUNCHUK_BUTTON_Z) { + printf("Nunchuck: Button Z pressed.\n"); + } + } + + if(exp_type == WPAD_EXP_CLASSIC) { + if(pressed & WPAD_CLASSIC_BUTTON_UP) { + printf("Classic Controller: Button up pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_DOWN) { + printf("Classic Controller: Button down pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_LEFT) { + printf("Classic Controller: Button left pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_RIGHT) { + printf("Classic Controller: Button right pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_A) { + printf("Classic Controller: Button A pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_B) { + printf("Classic Controller: Button B pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_X) { + printf("Classic Controller: Button X pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_Y) { + printf("Classic Controller: Button Y pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_FULL_L) { + printf("Classic Controller: L trigger pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_FULL_R) { + printf("Classic Controller: R trigger pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_ZL) { + printf("Classic Controller: ZL trigger pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_ZR) { + printf("Classic Controller: ZR trigger pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_PLUS) { + printf("Classic Controller: Button + pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_MINUS) { + printf("Classic Controller: Button - pressed.\n"); + } + + if(pressed & WPAD_CLASSIC_BUTTON_HOME) { + printf("Classic Controller: HOME button pressed.\n"); + homebutton++; + if (homebutton == 3) { + printf("exiting..."); + exit(0); + } + } + } + + + + if(gcpressed & PAD_BUTTON_A) { + printf("GameCube Controller: Button A pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_B) { + printf("GameCube Controller: Button B pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_X) { + printf("GameCube Controller: Button X pressed.\n"); + } + + if(gcpressed & PAD_TRIGGER_Z) { + printf("GameCube Controller: Z trigger pressed.\n"); + } + + if(gcpressed & PAD_TRIGGER_L) { + printf("GameCube Controller: L trigger pressed.\n"); + } + + if(gcpressed & PAD_TRIGGER_R) { + printf("GameCube Controller: R trigger pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_UP) { + printf("GameCube Controller: Button up pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_DOWN) { + printf("GameCube Controller: Button down pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_LEFT) { + printf("GameCube Controller: Button left pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_RIGHT) { + printf("GameCube Controller: Button right pressed.\n"); + } + + if(gcpressed & PAD_BUTTON_START) { + printf("GameCube Controller: Start button pressed.\n"); + } + + if(pressed & WPAD_BUTTON_A) { + printf("Wiimote: Button A pressed.\n"); + } + + if(pressed & WPAD_BUTTON_B) { + printf("Wiimote: Button B pressed.\n"); + } + + if(pressed & WPAD_BUTTON_1) { + printf("Wiimote: Button 1 pressed.\n"); + } + + if(pressed & WPAD_BUTTON_2) { + printf("Wiimote: Button 2 pressed.\n"); + } + + if(pressed & WPAD_BUTTON_MINUS) { + printf("Wiimote: Button - pressed.\n"); + } + + if(pressed & WPAD_BUTTON_PLUS) { + printf("Wiimote: Button + pressed.\n"); + } + + if(pressed & WPAD_BUTTON_HOME) { + printf("Wiimote: HOME button pressed.\n"); + homebutton++; + if (homebutton == 3) { + printf("exiting..."); + exit(0); + } + } + + if(pressed & WPAD_BUTTON_UP) { + printf("Wiimote: Button up pressed.\n"); + } + + if(pressed & WPAD_BUTTON_DOWN) { + printf("Wiimote: Button down pressed.\n"); + } + + if(pressed & WPAD_BUTTON_LEFT) { + printf("Wiimote: Button left pressed.\n"); + } + + if(pressed & WPAD_BUTTON_RIGHT) { + printf("Wiimote: Button right pressed.\n"); + } + + + + VIDEO_WaitVSync(); + } + + return 0; +}