Skip to content

Commit 8aaf16c

Browse files
committed
Init commit!
1 parent f642952 commit 8aaf16c

File tree

14 files changed

+1070
-0
lines changed

14 files changed

+1070
-0
lines changed

templates/3ds/Makefile

+255
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITARM)),)
6+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
7+
endif
8+
9+
TOPDIR ?= $(CURDIR)
10+
include $(DEVKITARM)/3ds_rules
11+
12+
#---------------------------------------------------------------------------------
13+
# TARGET is the name of the output
14+
# BUILD is the directory where object files & intermediate files will be placed
15+
# SOURCES is a list of directories containing source code
16+
# DATA is a list of directories containing data files
17+
# INCLUDES is a list of directories containing header files
18+
# GRAPHICS is a list of directories containing graphics files
19+
# GFXBUILD is the directory where converted graphics files will be placed
20+
# If set to $(BUILD), it will statically link in the converted
21+
# files as if they were data files.
22+
#
23+
# NO_SMDH: if set to anything, no SMDH file is generated.
24+
# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
25+
# APP_TITLE is the name of the app stored in the SMDH file (Optional)
26+
# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
27+
# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
28+
# ICON is the filename of the icon (.png), relative to the project folder.
29+
# If not set, it attempts to use one of the following (in this order):
30+
# - <Project name>.png
31+
# - icon.png
32+
# - <libctru folder>/default_icon.png
33+
#---------------------------------------------------------------------------------
34+
TARGET := <PNAME>
35+
BUILD := build
36+
SOURCES := source
37+
DATA := data
38+
INCLUDES := include
39+
GRAPHICS := gfx
40+
GFXBUILD := $(BUILD)
41+
#ROMFS := romfs
42+
#GFXBUILD := $(ROMFS)/gfx
43+
44+
#---------------------------------------------------------------------------------
45+
# options for code generation
46+
#---------------------------------------------------------------------------------
47+
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
48+
49+
CFLAGS := -g -Wall -O2 -mword-relocations \
50+
-ffunction-sections \
51+
$(ARCH)
52+
53+
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
54+
55+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
56+
57+
ASFLAGS := -g $(ARCH)
58+
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
59+
60+
LIBS := -lctru -lm
61+
62+
#---------------------------------------------------------------------------------
63+
# list of directories containing libraries, this must be the top level containing
64+
# include and lib
65+
#---------------------------------------------------------------------------------
66+
LIBDIRS := $(CTRULIB)
67+
68+
69+
#---------------------------------------------------------------------------------
70+
# no real need to edit anything past this point unless you need to add additional
71+
# rules for different file extensions
72+
#---------------------------------------------------------------------------------
73+
ifneq ($(BUILD),$(notdir $(CURDIR)))
74+
#---------------------------------------------------------------------------------
75+
76+
export OUTPUT := $(CURDIR)/$(TARGET)
77+
export TOPDIR := $(CURDIR)
78+
79+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
80+
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \
81+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
82+
83+
export DEPSDIR := $(CURDIR)/$(BUILD)
84+
85+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
86+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
87+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
88+
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
89+
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
90+
GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s)))
91+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
92+
93+
#---------------------------------------------------------------------------------
94+
# use CXX for linking C++ projects, CC for standard C
95+
#---------------------------------------------------------------------------------
96+
ifeq ($(strip $(CPPFILES)),)
97+
#---------------------------------------------------------------------------------
98+
export LD := $(CC)
99+
#---------------------------------------------------------------------------------
100+
else
101+
#---------------------------------------------------------------------------------
102+
export LD := $(CXX)
103+
#---------------------------------------------------------------------------------
104+
endif
105+
#---------------------------------------------------------------------------------
106+
107+
#---------------------------------------------------------------------------------
108+
ifeq ($(GFXBUILD),$(BUILD))
109+
#---------------------------------------------------------------------------------
110+
export T3XFILES := $(GFXFILES:.t3s=.t3x)
111+
#---------------------------------------------------------------------------------
112+
else
113+
#---------------------------------------------------------------------------------
114+
export ROMFS_T3XFILES := $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES))
115+
export T3XHFILES := $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES))
116+
#---------------------------------------------------------------------------------
117+
endif
118+
#---------------------------------------------------------------------------------
119+
120+
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
121+
122+
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
123+
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
124+
$(addsuffix .o,$(T3XFILES))
125+
126+
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
127+
128+
export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \
129+
$(addsuffix .h,$(subst .,_,$(BINFILES))) \
130+
$(GFXFILES:.t3s=.h)
131+
132+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
133+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
134+
-I$(CURDIR)/$(BUILD)
135+
136+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
137+
138+
export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh)
139+
140+
ifeq ($(strip $(ICON)),)
141+
icons := $(wildcard *.png)
142+
ifneq (,$(findstring $(TARGET).png,$(icons)))
143+
export APP_ICON := $(TOPDIR)/$(TARGET).png
144+
else
145+
ifneq (,$(findstring icon.png,$(icons)))
146+
export APP_ICON := $(TOPDIR)/icon.png
147+
endif
148+
endif
149+
else
150+
export APP_ICON := $(TOPDIR)/$(ICON)
151+
endif
152+
153+
ifeq ($(strip $(NO_SMDH)),)
154+
export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
155+
endif
156+
157+
ifneq ($(ROMFS),)
158+
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
159+
endif
160+
161+
.PHONY: all clean
162+
163+
#---------------------------------------------------------------------------------
164+
all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES)
165+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
166+
167+
$(BUILD):
168+
@mkdir -p $@
169+
170+
ifneq ($(GFXBUILD),$(BUILD))
171+
$(GFXBUILD):
172+
@mkdir -p $@
173+
endif
174+
175+
ifneq ($(DEPSDIR),$(BUILD))
176+
$(DEPSDIR):
177+
@mkdir -p $@
178+
endif
179+
180+
#---------------------------------------------------------------------------------
181+
clean:
182+
@echo clean ...
183+
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD)
184+
185+
#---------------------------------------------------------------------------------
186+
$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s
187+
#---------------------------------------------------------------------------------
188+
@echo $(notdir $<)
189+
@tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x
190+
191+
#---------------------------------------------------------------------------------
192+
else
193+
194+
#---------------------------------------------------------------------------------
195+
# main targets
196+
#---------------------------------------------------------------------------------
197+
$(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS)
198+
199+
$(OFILES_SOURCES) : $(HFILES)
200+
201+
$(OUTPUT).elf : $(OFILES)
202+
203+
#---------------------------------------------------------------------------------
204+
# you need a rule like this for each extension you use as binary data
205+
#---------------------------------------------------------------------------------
206+
%.bin.o %_bin.h : %.bin
207+
#---------------------------------------------------------------------------------
208+
@echo $(notdir $<)
209+
@$(bin2o)
210+
211+
#---------------------------------------------------------------------------------
212+
.PRECIOUS : %.t3x
213+
#---------------------------------------------------------------------------------
214+
%.t3x.o %_t3x.h : %.t3x
215+
#---------------------------------------------------------------------------------
216+
@echo $(notdir $<)
217+
@$(bin2o)
218+
219+
#---------------------------------------------------------------------------------
220+
# rules for assembling GPU shaders
221+
#---------------------------------------------------------------------------------
222+
define shader-as
223+
$(eval CURBIN := $*.shbin)
224+
$(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
225+
echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
226+
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
227+
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
228+
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
229+
picasso -o $(CURBIN) $1
230+
bin2s $(CURBIN) | $(AS) -o $*.shbin.o
231+
endef
232+
233+
%.shbin.o %_shbin.h : %.v.pica %.g.pica
234+
@echo $(notdir $^)
235+
@$(call shader-as,$^)
236+
237+
%.shbin.o %_shbin.h : %.v.pica
238+
@echo $(notdir $<)
239+
@$(call shader-as,$<)
240+
241+
%.shbin.o %_shbin.h : %.shlist
242+
@echo $(notdir $<)
243+
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))
244+
245+
#---------------------------------------------------------------------------------
246+
%.t3x %.h : %.t3s
247+
#---------------------------------------------------------------------------------
248+
@echo $(notdir $<)
249+
@tex3ds -i $< -H $*.h -d $*.d -o $*.t3x
250+
251+
-include $(DEPSDIR)/*.d
252+
253+
#---------------------------------------------------------------------------------------
254+
endif
255+
#---------------------------------------------------------------------------------------

templates/3ds/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# template
2+
3+
This is a template for starting new 3DS libctru projects.

templates/3ds/source/main.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <3ds.h>
5+
6+
int main(int argc, char* argv[])
7+
{
8+
gfxInitDefault();
9+
consoleInit(GFX_TOP, NULL);
10+
11+
printf("Hello, world!\n");
12+
13+
// Main loop
14+
while (aptMainLoop())
15+
{
16+
gspWaitForVBlank();
17+
gfxSwapBuffers();
18+
hidScanInput();
19+
20+
// Your code goes here
21+
u32 kDown = hidKeysDown();
22+
if (kDown & KEY_START)
23+
break; // break in order to return to hbmenu
24+
}
25+
26+
gfxExit();
27+
return 0;
28+
}

templates/_common/.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Linux
2+
/bin
3+
<PNAME>
4+
5+
# Windows
6+
*.dll
7+
*.exe
8+
*.sln
9+
*.vcxproj
10+
*.filters
11+
*.user
12+
*.vs
13+
.vscode
14+
Debug/
15+
Release/
16+
17+
# Misc
18+
*.zip
19+
*.temp
20+
*.srctrlprj
21+
*.srctrldb
22+
*.srctrlbm

templates/nds/Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
ifeq ($(strip $(DEVKITARM)),)
5+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
6+
endif
7+
8+
export TARGET := <PNAME>
9+
export TOPDIR := $(CURDIR)
10+
11+
# specify a directory which contains the nitro filesystem
12+
# this is relative to the Makefile
13+
NITRO_FILES :=
14+
15+
# These set the information text in the nds file
16+
#GAME_TITLE := My Wonderful Homebrew
17+
#GAME_SUBTITLE1 := built with devkitARM
18+
#GAME_SUBTITLE2 := http://devitpro.org
19+
20+
include $(DEVKITARM)/ds_rules
21+
22+
.PHONY: checkarm7 checkarm9 clean
23+
24+
#---------------------------------------------------------------------------------
25+
# main targets
26+
#---------------------------------------------------------------------------------
27+
all: checkarm7 checkarm9 $(TARGET).nds
28+
29+
#---------------------------------------------------------------------------------
30+
checkarm7:
31+
$(MAKE) -C arm7
32+
33+
#---------------------------------------------------------------------------------
34+
checkarm9:
35+
$(MAKE) -C arm9
36+
37+
#---------------------------------------------------------------------------------
38+
$(TARGET).nds : $(NITRO_FILES) arm7/$(TARGET).elf arm9/$(TARGET).elf
39+
ndstool -c $(TARGET).nds -7 arm7/$(TARGET).elf -9 arm9/$(TARGET).elf \
40+
-b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" \
41+
$(_ADDFILES)
42+
43+
#---------------------------------------------------------------------------------
44+
arm7/$(TARGET).elf:
45+
$(MAKE) -C arm7
46+
47+
#---------------------------------------------------------------------------------
48+
arm9/$(TARGET).elf:
49+
$(MAKE) -C arm9
50+
51+
#---------------------------------------------------------------------------------
52+
clean:
53+
$(MAKE) -C arm9 clean
54+
$(MAKE) -C arm7 clean
55+
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9

templates/nds/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# template
2+
3+
This is a template for starting new NDS(i) libnds projects.

0 commit comments

Comments
 (0)