Skip to content

Commit

Permalink
Initial commit with content!
Browse files Browse the repository at this point in the history
This revision of TownManager works! Will release later.
  • Loading branch information
dragos240 committed Oct 30, 2016
1 parent 58418e0 commit 8e8ef76
Show file tree
Hide file tree
Showing 35 changed files with 1,865 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.sh
*.xcf
TownManager.*
!TownManager.xml
!TownManager.rsf
build/
ideas/
tm.conf
231 changes: 231 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>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
#
# 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):
# - <Project name>.png
# - icon.png
# - <libctru folder>/default_icon.png
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
ROMFS := romfs

APP_TITLE := TownManager
APP_DESCRIPTION := A specialized save manager for AC:NL
APP_AUTHOR := Dragos240

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft

#CFLAGS := -g -Wall -O2 -mword-relocations \
# -ffunction-sections \
# $(ARCH)

CFLAGS := -g -Wall -Wextra -O2 -mword-relocations \
-fomit-frame-pointer -ffunction-sections \
$(ARCH)

CFLAGS += $(INCLUDE) -DARM11 -D_3DS

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := -lsfil -lsftd -lfreetype -lpng -lz -lsf2d -lcitro3d -lctru -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CTRULIB) $(PORTLIBS)


#---------------------------------------------------------------------------------
# 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 GITREV := $(shell git rev-parse HEAD 2>/dev/null | cut -c1-8)
export VERSION_MAJOR := 0
export VERSION_MINOR := 1
export VERSION_BUGFIX := 0
export VERSION := $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUGFIX)-$(GITREV)

export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(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)))
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)) \
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

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)

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

.PHONY: $(BUILD) clean all

#---------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
echo clean ...
rm -rf $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(TARGET).cia

citra:
citra-qt $(TARGET).3dsx

cia:
bannertool makebanner -i res/banner\ icon.png -a res/audio.wav -o banner.bnr
bannertool makesmdh -s "TownManager" -l "TownManager" -p "Dragos240" -i icon.png -o icon.icn
makerom -f cia -o TownManager.cia -rsf res/TownManager.rsf -target t -exefslogo -elf TownManager.elf \
-ver "$(VERSION)" -icon icon.icn -banner banner.bnr
rm -f banner.bnr icon.icn

zip:
rm -rf TownManager-latest
mkdir TownManager-latest
cp $(TARGET).3dsx $(OUTPUT).smdh TownManager-latest
zip -r TownManager-latest.zip TownManager-latest/

#---------------------------------------------------------------------------------
else

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
ifeq ($(strip $(NO_SMDH)),)
$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
else
$(OUTPUT).3dsx : $(OUTPUT).elf
endif

$(OUTPUT).elf : $(OFILES)

#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

#---------------------------------------------------------------------------------
%.png.o : %.png
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

#---------------------------------------------------------------------------------
# rules for assembling GPU shaders
#---------------------------------------------------------------------------------
define shader-as
$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
picasso -o $(CURBIN) $1
bin2s $(CURBIN) | $(AS) -o $@
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
endef

%.shbin.o : %.v.pica %.g.pica
@echo $(notdir $^)
@$(call shader-as,$^)

%.shbin.o : %.v.pica
@echo $(notdir $<)
@$(call shader-as,$<)

%.shbin.o : %.shlist
@echo $(notdir $<)
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))

-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
1 change: 1 addition & 0 deletions TownManager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<targets selectable="true" />
1 change: 1 addition & 0 deletions hans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<targets selectable="true" />
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions include/backup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef TM_BACKUP_H
#define TM_BACKUP_H

u64 filesize_to_u64(FS_Archive arch, char* filepath);
int buffer_to_file(FS_Archive arch, char* buffer, u64 size, char* dirpath, char* filename);
char* file_to_buffer(FS_Archive arch, char* dirpath, char* filename);

void backup_to_prev_folder(char* dirname);

#endif
18 changes: 18 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef TM_COMMON_H
#define TM_COMMON_H

#include <3ds.h>

#define GAMEID 0x0004000000086300
#define SECOND_IN_NS (1000*1000*1000)
#define SIZE_GARDEN 522752
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

extern bool is3dsx;
extern int debug;

void setIs3dsx();

char* u16str2str(u16* wstr);

#endif
23 changes: 23 additions & 0 deletions include/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef TM_FS_H
#define TM_FS_H

typedef struct{
int numdirs;
char** dirs;
} dir_t;

typedef struct{
int numfiles;
char** files;
} file_t;

extern FS_Archive game_arch;
extern FS_Archive sdmc_arch;

Result fs_init();
Result fs_fini();

dir_t get_dirs(char* path);
file_t get_files(FS_Archive arch, char* path);

#endif
32 changes: 32 additions & 0 deletions include/gfx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef TM_GFX_H
#define TM_GFX_H

#include <3ds.h>
#include <sf2d.h>
#include <sftd.h>

extern sf2d_texture* arrow;
extern sftd_font* font;
extern sftd_font* font_bold;

typedef struct{
int x;
int y;
} pos_t;

extern pos_t current_pos;

extern const int COLOR_WHITE;
extern const int COLOR_BLACK;

void gfx_init();
void gfx_fini();

void gfx_waitbutton();
int gfx_prompt(char* message, char* keymsg);
int gfx_prompt3(char* message, char* keymsg);
void gfx_error(Result ret, char* file, int line);
void gfx_displaymessage(char* msg, ...);
void gfx_waitmessage(char* msg, ...);

#endif
6 changes: 6 additions & 0 deletions include/kb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef TM_KB_H
#define TM_KB_H

char* get_string(char* hint);

#endif
11 changes: 11 additions & 0 deletions include/launcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef TM_LAUNCHER_H
#define TM_LAUNCHER_H

Result launcher_init();
Result launcher_fini();

int prepare_to_launch(char* dirname);
Result NSS_Reboot(u32 pid_low, u32 pid_high, u8 mediatype, u8 flag);
void launch_game();

#endif
6 changes: 6 additions & 0 deletions include/menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef TM_MENU_H
#define TM_MENU_H

void display_menu(char **menu_entries, int total_entries, int *menupos, char *headerstr);

#endif
13 changes: 13 additions & 0 deletions include/tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef TM_TESTS_H
#define TM_TESTS_H

void run_tests();

void text_test();
void simple_gfx_test();
void gfx_test();
void menu_test();
void kb_test();
void launcher_test();

#endif
13 changes: 13 additions & 0 deletions include/town.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef TM_TOWN_H
#define TM_TOWN_H

void populate_menu_entries(char*** menu_entries, int* menucount);

void create_town();
void init_save_folder();
void load_tm_config(char** current);

void town_opts(char* dirname);
void delete_town(char* dirname);

#endif
Loading

0 comments on commit 8e8ef76

Please sign in to comment.