diff --git a/.gitignore b/.gitignore index 607e0ee..9785597 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ build .cache -*.3dsx -*.elf -*.smdh diff --git a/Makefile b/Makefile index 632882b..3582b23 100644 --- a/Makefile +++ b/Makefile @@ -1,229 +1,61 @@ -#--------------------------------------------------------------------------------- .SUFFIXES: -#--------------------------------------------------------------------------------- - ifeq ($(strip $(DEVKITARM)),) $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") endif - TOPDIR ?= $(CURDIR) include $(DEVKITARM)/3ds_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 -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# GRAPHICS is a list of directories containing graphics files -# GFXBUILD is the directory where converted graphics files will be placed -# If set to $(BUILD), it will statically link in the converted -# files as if they were data files. -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -GRAPHICS := gfx -GFXBUILD := $(BUILD) -#ROMFS := romfs -#GFXBUILD := $(ROMFS)/gfx +TARGET := pukeko-3ds +BUILD := build +SRCDIRS := program/src libpukeko/src +INCLUDE := -I$(CURDIR)/include \ + -I$(CURDIR)/libpukeko/include \ + -I$(CURDIR)/program/include \ + -I$(DEVKITPRO)/libctru/include \ + -I$(BUILD) -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft +# Updated architecture flags +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mfpu=vfp -CFLAGS := -g -Wall -O2 -mword-relocations \ - -ffunction-sections \ - $(ARCH) +CFLAGS := -g -Wall -O2 -mword-relocations \ + -ffunction-sections $(ARCH) \ + $(INCLUDE) -D__3DS__ -CFLAGS += $(INCLUDE) -D__3DS__ +# These are crucial for 3DS devkitARM - use 3dsx.specs +LDFLAGS := -specs=3dsx.specs $(ARCH) -L$(DEVKITPRO)/libctru/lib -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 +# Make sure to include standard C library +LIBS := -lctru -lm -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# 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 TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) -SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) -GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s))) -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 -#--------------------------------------------------------------------------------- - -#--------------------------------------------------------------------------------- -ifeq ($(GFXBUILD),$(BUILD)) -#--------------------------------------------------------------------------------- -export T3XFILES := $(GFXFILES:.t3s=.t3x) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- -export ROMFS_T3XFILES := $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES)) -export T3XHFILES := $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES)) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \ - $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ - $(addsuffix .o,$(T3XFILES)) - -export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) - -export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \ - $(addsuffix .h,$(subst .,_,$(BINFILES))) \ - $(GFXFILES:.t3s=.h) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -ifneq ($(ROMFS),) - export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) -endif +# Use find to recurse +CFILES := $(shell find $(SRCDIRS) -name '*.c') +OFILES := $(patsubst %.c,$(BUILD)/%.o,$(CFILES)) .PHONY: all clean -#--------------------------------------------------------------------------------- -all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES) - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile +all: $(BUILD) $(TARGET).3dsx + +$(TARGET).3dsx: $(BUILD)/$(TARGET).elf + @echo "[3DSX] $@" + @$(DEVKITPRO)/tools/bin/3dsxtool $< $@ $(if $(filter $(TARGET).smdh,$(wildcard $(TARGET).smdh)),--smdh=$(TARGET).smdh) $(if $(strip $(ROMFS)),--romfs=$(ROMFS)) + +$(BUILD)/$(TARGET).elf: $(OFILES) + @mkdir -p $(dir $@) + @echo "[LD] $@" + @$(CC) $(LDFLAGS) -o $@ $(OFILES) $(LIBS) + +# 🧱 C build rule +$(BUILD)/%.o: %.c + @mkdir -p $(dir $@) + @echo "[CC] $<" + @$(CC) $(CFLAGS) -MMD -MP -MF $(@:.o=.d) -c $< -o $@ $(BUILD): @mkdir -p $@ -ifneq ($(GFXBUILD),$(BUILD)) -$(GFXBUILD): - @mkdir -p $@ -endif - -ifneq ($(DEPSDIR),$(BUILD)) -$(DEPSDIR): - @mkdir -p $@ -endif - -#--------------------------------------------------------------------------------- clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD) + @echo "Cleaning build files..." + @rm -rf $(BUILD) $(TARGET).3dsx $(TARGET).elf -#--------------------------------------------------------------------------------- -$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x - -#--------------------------------------------------------------------------------- -else - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS) - -$(OFILES_SOURCES) : $(HFILES) - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o %_bin.h : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -.PRECIOUS : %.t3x %.shbin -#--------------------------------------------------------------------------------- -%.t3x.o %_t3x.h : %.t3x -#--------------------------------------------------------------------------------- - $(SILENTMSG) $(notdir $<) - $(bin2o) - -#--------------------------------------------------------------------------------- -%.shbin.o %_shbin.h : %.shbin -#--------------------------------------------------------------------------------- - $(SILENTMSG) $(notdir $<) - $(bin2o) - --include $(DEPSDIR)/*.d - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- +# ⛑ Include generated dependency files +-include $(patsubst %.o,%.d,$(OFILES)) diff --git a/compile_commands.json b/compile_commands.json deleted file mode 100644 index 035ab98..0000000 --- a/compile_commands.json +++ /dev/null @@ -1,27 +0,0 @@ -[ - { - "arguments": [ - "/opt/devkitpro//devkitARM/bin/arm-none-eabi-gcc", - "-g", - "-Wall", - "-O2", - "-mword-relocations", - "-ffunction-sections", - "-march=armv6k", - "-mtune=mpcore", - "-mfloat-abi=hard", - "-mtp=soft", - "-I/home/taigo/code/pers/pukeko-3ds/include", - "-I/opt/devkitpro//libctru/include", - "-I/home/taigo/code/pers/pukeko-3ds/build", - "-D__3DS__", - "-c", - "-o", - "input.o", - "/home/taigo/code/pers/pukeko-3ds/source/input.c" - ], - "directory": "/home/taigo/code/pers/pukeko-3ds/build", - "file": "/home/taigo/code/pers/pukeko-3ds/source/input.c", - "output": "/home/taigo/code/pers/pukeko-3ds/build/input.o" - } -] diff --git a/include/include.h b/include/include.h deleted file mode 100644 index f3ab88f..0000000 --- a/include/include.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef INCLUDE_H -#define INCLUDE_H - -#include <3ds.h> -#include -#include -#include -#include -#include - -#include "input.h" - -extern int user_money; -extern int held_pukekos; - -#endif // !INCLUDE_H diff --git a/libpukeko/Makefile b/libpukeko/Makefile new file mode 100644 index 0000000..431e54d --- /dev/null +++ b/libpukeko/Makefile @@ -0,0 +1,27 @@ +include $(DEVKITARM)/3ds_rules + +# Compiler flags +CFLAGS := -g -Wall -O2 $(ARCH) -D__3DS__ + +# Source files +SOURCES := src/navigation/selector.c + +# Object files +OFILES := $(SOURCES:.c=.o) + +# Build directory +BUILD := ../../build/libpukeko + +.PHONY: all clean + +all: $(BUILD)/libpukeko.a + +$(BUILD)/libpukeko.a: $(OFILES) + $(AR) rcs $@ $^ + +$(BUILD)/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(BUILD)/*.o $(BUILD)/libpukeko.a + diff --git a/include/input.h b/libpukeko/include/navigation.h similarity index 54% rename from include/input.h rename to libpukeko/include/navigation.h index 2442902..8b112a2 100644 --- a/include/input.h +++ b/libpukeko/include/navigation.h @@ -2,6 +2,6 @@ #define INPUT_H void waitForKey(char key); -int print_select_menu(char menu_items[10][32], int items_length); +int selector_render(char menu_items[10][32], int items_length); #endif // !INPUT_H diff --git a/source/input.c b/libpukeko/src/navigation/selector.c similarity index 64% rename from source/input.c rename to libpukeko/src/navigation/selector.c index af98f47..97f1c30 100644 --- a/source/input.c +++ b/libpukeko/src/navigation/selector.c @@ -1,18 +1,20 @@ -#include "include.h" +#include <3ds.h> +#include +#include "navigation.h" -void waitForKey(char key) { - while (true) { - hidScanInput(); - u32 key_down = hidKeysDown(); - if (key_down & key) break; - } -} +//void waitForKey(char key) { +// while (true) { +// hidScanInput(); +// u32 key_down = hidKeysDown(); +// if (key_down & key) break; +// } +//} -int cursor_select(int items) { +int render_cursor(int items) { int cursor_position = 1; printf("\x1b[%d;1H>", cursor_position); - while (true) { + while (true) { hidScanInput(); u32 key_down = hidKeysDown(); @@ -38,16 +40,16 @@ int cursor_select(int items) { return cursor_position; } -void print_menu(char menu_items[10][32], int items_length) { +void selector_draw(char menu_items[10][32], int items_length) { for (int i = 0; i < items_length; i = i + 1) { printf("\x1b[%d;2H%s", i+1, menu_items[i]); } } -int print_select_menu(char menu_items[10][32], int items_length) { +int selector_render(char menu_items[10][32], int items_length) { consoleClear(); - print_menu(menu_items, items_length); - int selection = cursor_select(items_length); + selector_draw(menu_items, items_length); + int selection = render_cursor(items_length); return selection; } diff --git a/program/Makefile b/program/Makefile new file mode 100644 index 0000000..fcba622 --- /dev/null +++ b/program/Makefile @@ -0,0 +1,27 @@ +include $(DEVKITARM)/3ds_rules + +# Compiler flags +CFLAGS := -g -Wall -O2 $(ARCH) -D__3DS__ + +# Source files +SOURCES := src/debug/debug.c src/main_menu.c src/main.c src/pukeko.c + +# Object files +OFILES := $(SOURCES:.c=.o) + +# Build directory +BUILD := ../../build/program + +.PHONY: all clean + +all: $(BUILD)/pukeko.elf + +$(BUILD)/pukeko.elf: $(OFILES) $(BUILD)/libpukeko.a + $(LD) -o $@ $^ $(LDFLAGS) $(LIBS) + +$(BUILD)/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(BUILD)/*.o $(BUILD)/pukeko.elf + diff --git a/include/debug.h b/program/include/debug.h similarity index 100% rename from include/debug.h rename to program/include/debug.h diff --git a/include/main_menu.h b/program/include/main_menu.h similarity index 100% rename from include/main_menu.h rename to program/include/main_menu.h diff --git a/include/pukeko.h b/program/include/pukeko.h similarity index 100% rename from include/pukeko.h rename to program/include/pukeko.h diff --git a/program/include/pukeko_app.h b/program/include/pukeko_app.h new file mode 100644 index 0000000..b3a21c2 --- /dev/null +++ b/program/include/pukeko_app.h @@ -0,0 +1,7 @@ +#ifndef PUKEKO_APP_H +#define PUKEKO_APP_H + +extern int user_money; +extern int held_pukekos; + +#endif // !PUKEKO_APP_H diff --git a/source/debug.c b/program/src/debug/debug.c similarity index 69% rename from source/debug.c rename to program/src/debug/debug.c index 156b8d7..9f990f8 100644 --- a/source/debug.c +++ b/program/src/debug/debug.c @@ -1,5 +1,6 @@ -#include "include.h" +#include "pukeko_app.h" #include "debug.h" +#include "../../libpukeko/include/navigation.h" void print_debug_menu() { int items_length = 2; @@ -9,7 +10,7 @@ void print_debug_menu() { }; while (true) { - int selection = print_select_menu(menu_items, items_length); + int selection = selector_render(menu_items, items_length); switch (selection) { case 1: diff --git a/source/main.c b/program/src/main.c similarity index 85% rename from source/main.c rename to program/src/main.c index c9f8aeb..295ec18 100644 --- a/source/main.c +++ b/program/src/main.c @@ -1,5 +1,7 @@ +#include <3ds.h> #include -#include "include.h" +#include +#include "pukeko_app.h" #include "main_menu.h" int user_money = 0; diff --git a/source/main_menu.c b/program/src/main_menu.c similarity index 73% rename from source/main_menu.c rename to program/src/main_menu.c index 56ac052..2422eab 100644 --- a/source/main_menu.c +++ b/program/src/main_menu.c @@ -1,7 +1,9 @@ +#include <3ds.h> #include "main_menu.h" -#include "include.h" +#include "pukeko_app.h" #include "pukeko.h" #include "debug.h" +#include "../../libpukeko/include/navigation.h" void print_main_menu() { int items_length = 3; @@ -12,7 +14,7 @@ void print_main_menu() { }; while (true) { - int selection = print_select_menu(menu_items, items_length); + int selection = selector_render(menu_items, items_length); switch (selection) { case 1: diff --git a/source/pukeko.c b/program/src/pukeko.c similarity index 89% rename from source/pukeko.c rename to program/src/pukeko.c index 6285395..0b45625 100644 --- a/source/pukeko.c +++ b/program/src/pukeko.c @@ -1,4 +1,8 @@ -#include "include.h" +#include <3ds.h> +#include +#include +#include +#include "pukeko_app.h" #include "pukeko.h" void print_top_info() { diff --git a/pukeko-3ds.3dsx b/pukeko-3ds.3dsx new file mode 100644 index 0000000..55e01d1 Binary files /dev/null and b/pukeko-3ds.3dsx differ