Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sctech-tr committed Jul 13, 2024
1 parent b455b57 commit fea5109
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 0 deletions.
154 changes: 154 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>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
#---------------------------------------------------------------------------------
1 change: 1 addition & 0 deletions Tutorial.pnproj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project name="Tutorial"><MagicFolder excludeFiles="*.pnproj;*.pnps;*.bak;*.tmp" excludeFolders="CVS;.svn" filter="*.c;*.cpp;*.h" name="source" path="source\"><File path="main.c"></File></MagicFolder><File path="Makefile"></File></Project>
1 change: 1 addition & 0 deletions Tutorial.pnps
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pd><ViewState><e p="Tutorial" x="true"></e><e p="Tutorial\source" x="true"></e></ViewState></pd>
221 changes: 221 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <ogc/pad.h>

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;
}

0 comments on commit fea5109

Please sign in to comment.