diff --git a/.gitignore b/.gitignore index 323c173..71400b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,49 +1,10 @@ -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib +build # Executables -*.exe -*.out *.elf -*.app *.cia *.3dsx *.smdh *.bnr -TWLSaveTool -TWLSaveTool-stripped - -# CMake -CMakeCache.txt -CMakeFiles -CMakeScripts -Makefile -cmake_install.cmake -install_manifest.txt - -# Install directories -CIA/* -3ds/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 3e35715..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project(TWLSaveTool) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fomit-frame-pointer -ffast-math -std=gnu++11") -SET(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}" CACHE INTERNAL "Prefix prepended to install directories" FORCE) - -# Note that you must copy the cmake folder and the DevkitArm3DS.cmake file in this directory -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) # Add the cmake folder to the modules paths, so that we can use the tools and find_package for ctrulib -include(Tools3DS) # Include all the macros and tools needed for 3ds development. - -find_package(CTRULIB REQUIRED) # Look for ctrulib - -include_directories(${PROJECT_SOURCE_DIR}/include) - -file(GLOB_RECURSE SOURCE_FILES - source/* -) - -file(GLOB_RECURSE HEADER_FILES - include/* -) - -add_executable(TWLSaveTool ${SOURCE_FILES} ${HEADER_FILES}) # Create the elf file -target_link_libraries(TWLSaveTool 3ds::ctrulib) # Link ctrulib, this will also setup the include directories ! - -if(CIA) - add_cia_target(TWLSaveTool "${PROJECT_SOURCE_DIR}/app/build-cia.rsf" "${PROJECT_SOURCE_DIR}/app/banner.cfgx" - "${PROJECT_SOURCE_DIR}/app/DSLite_BootSound.cwav" "TWLSaveTool" "TWLSaveTool" "TuxSH" "${PROJECT_SOURCE_DIR}/app/IconLarge.png") - - install(FILES "${PROJECT_SOURCE_DIR}/TWLSaveTool.cia" DESTINATION "CIA/") -else() - add_3dsx_target(TWLSaveTool "TWLSaveTool" "A tool to backup and restore save files from NDS cartridges (requires either PokeTransporter or Pokemon Dream Radar)" "TuxSH" "${PROJECT_SOURCE_DIR}/app/IconLarge.png") - - install(FILES "${PROJECT_SOURCE_DIR}/app/TWLSaveTool.xml" "${PROJECT_SOURCE_DIR}/TWLSaveTool.3dsx" "${PROJECT_SOURCE_DIR}/TWLSaveTool.smdh" - DESTINATION "3ds/TWLSaveTool/") -endif() \ No newline at end of file diff --git a/DevkitArm3DS.cmake b/DevkitArm3DS.cmake deleted file mode 100644 index ce33349..0000000 --- a/DevkitArm3DS.cmake +++ /dev/null @@ -1,63 +0,0 @@ -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR armv6k) -set(3DS TRUE) # To be used for multiplatform projects - -# DevkitPro Paths are broken on windows, so we have to fix those -macro(msys_to_cmake_path MsysPath ResultingPath) - if(WIN32) - string(REGEX REPLACE "^/([a-zA-Z])/" "\\1:/" ${ResultingPath} "${MsysPath}") - else() - set(${ResultingPath} "${MsysPath}") - endif() -endmacro() - -msys_to_cmake_path("$ENV{DEVKITPRO}" DEVKITPRO) -if(NOT IS_DIRECTORY ${DEVKITPRO}) - message(FATAL_ERROR "Please set DEVKITPRO in your environment") -endif() - -msys_to_cmake_path("$ENV{DEVKITARM}" DEVKITARM) -if(NOT IS_DIRECTORY ${DEVKITARM}) - message(FATAL_ERROR "Please set DEVKITARM in your environment") -endif() - -# Prefix detection only works with compiler id "GNU" -# CMake will look for prefixed g++, cpp, ld, etc. automatically -if(WIN32) - set(CMAKE_C_COMPILER "${DEVKITARM}/bin/arm-none-eabi-gcc.exe") - set(CMAKE_CXX_COMPILER "${DEVKITARM}/bin/arm-none-eabi-g++.exe") - set(CMAKE_AR "${DEVKITARM}/bin/arm-none-eabi-gcc-ar.exe" CACHE STRING "") - set(CMAKE_RANLIB "${DEVKITARM}/bin/arm-none-eabi-gcc-ranlib.exe" CACHE STRING "") -else() - set(CMAKE_C_COMPILER "${DEVKITARM}/bin/arm-none-eabi-gcc") - set(CMAKE_CXX_COMPILER "${DEVKITARM}/bin/arm-none-eabi-g++") - set(CMAKE_AR "${DEVKITARM}/bin/arm-none-eabi-gcc-ar" CACHE STRING "") - set(CMAKE_RANLIB "${DEVKITARM}/bin/arm-none-eabi-gcc-ranlib" CACHE STRING "") -endif() - -set(WITH_PORTLIBS ON CACHE BOOL "use portlibs ?") - -if(WITH_PORTLIBS) - set(CMAKE_FIND_ROOT_PATH ${DEVKITARM} ${DEVKITPRO} ${DEVKITPRO}/portlibs/3ds ${DEVKITPRO}/portlibs/armv6k) -else() - set(CMAKE_FIND_ROOT_PATH ${DEVKITARM} ${DEVKITPRO}) -endif() - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -SET(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available" ) - -add_definitions(-DARM11 -D_3DS) - -set(ARCH "-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft ") -set(CMAKE_C_FLAGS " -mword-relocations ${ARCH}" CACHE STRING "C flags") -set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "C++ flags") -set(DKA_SUGGESTED_C_FLAGS "-fomit-frame-pointer -ffast-math") -set(DKA_SUGGESTED_CXX_FLAGS "${DKA_SUGGESTED_C_FLAGS} -fno-rtti -fno-exceptions -std=gnu++11") - -set(CMAKE_INSTALL_PREFIX ${DEVKITPRO}/portlibs/3ds - CACHE PATH "Install libraries in the portlibs dir") - diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..523e8a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,233 @@ +#--------------------------------------------------------------------------------- +.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 +# +# 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 := TWLSaveTool +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include +#ROMFS := romfs +APP_AUTHOR := TuxSH +APP_DESCRIPTION := A tool to backup and restore save files from NDS cartridges (requires either PokeTransporter or Pokemon Dream Radar) +ICON := app/IconLarge.png +BNR_IMAGE := app/banner.cfgx +BNR_AUDIO := app/DSLite_BootSound.cwav +RSF_FILE := app/build-cia.rsf + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft + +CFLAGS := -g -Wall -O2 -mword-relocations \ + -ffunction-sections \ + $(ARCH) + +CFLAGS += $(INCLUDE) -DARM11 -D_3DS + +CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++11 + +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,$(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 cia + +#--------------------------------------------------------------------------------- +all: $(BUILD) + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).3dsx $(TARGET).smdh $(TARGET).cia $(TARGET).elf + + +#--------------------------------------------------------------------------------- +cia: $(BUILD) + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile cia + +#--------------------------------------------------------------------------------- +3dsx: $(BUILD) + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 3dsx + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +all: $(OUTPUT).cia $(OUTPUT).3dsx + +3dsx: $(OUTPUT).3dsx + +cia: $(OUTPUT).cia + +ifeq ($(strip $(NO_SMDH)),) +$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh +$(OUTPUT).smdh : $(TOPDIR)/Makefile +else +$(OUTPUT).3dsx : $(OUTPUT).elf +endif + +$(OUTPUT).elf : $(OFILES) + +$(OUTPUT).smdh : $(APP_ICON) + @bannertool makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i $(APP_ICON) -o $@ + @echo "built ... $(notdir $@)" + +$(OUTPUT).cia : $(OUTPUT).elf $(OUTPUT).smdh $(TARGET).bnr + @makerom -f cia -target t -exefslogo -o $@ \ + -elf $(OUTPUT).elf -rsf $(TOPDIR)/$(RSF_FILE) \ + -banner $(TARGET).bnr \ + -icon $(OUTPUT).smdh + @echo "built ... $(notdir $@)" + +$(TARGET).bnr : $(TOPDIR)/$(BNR_IMAGE) $(TOPDIR)/$(BNR_AUDIO) + @bannertool makebanner -o $@ -ci $(TOPDIR)/$(BNR_IMAGE) -ca $(TOPDIR)/$(BNR_AUDIO) + @echo "built ... $@" + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @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 +#--------------------------------------------------------------------------------------- diff --git a/README.md b/README.md index 4ec2ec5..5ffa1a7 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,9 @@ TWLSaveTool is a 3DS homebrew that allows you to read, write, and erase save fil **All games** except WarioWare D.I.Y., Band Brothers DX, Art Academy DS, and Pokémon Typing Adventure should be supported. ## How to build -Have CMake and devkitPro correctly installed and set up, as well as makerom and bannertool in devkitARM/bin, then run: +Have libctru and devkitARM correctly installed and set up, as well as makerom and bannertool in an accessible path, then run: ``` -cmake -DCMAKE_TOOLCHAIN_FILE=DevkitArm3DS.cmake -DCIA=[ON or OFF] -G"Unix Makefiles" . make -make install ``` ## Special thanks diff --git a/app/TWLSaveTool.xml b/TWLSaveTool.xml similarity index 100% rename from app/TWLSaveTool.xml rename to TWLSaveTool.xml diff --git a/cmake/FindCTRULIB.cmake b/cmake/FindCTRULIB.cmake deleted file mode 100644 index 465ff6c..0000000 --- a/cmake/FindCTRULIB.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# - Try to find ctrulib -# Once done this will define -# LIBCTRU_FOUND - System has ctrulib -# LIBCTRU_INCLUDE_DIRS - The ctrulib include directories -# LIBCTRU_LIBRARIES - The libraries needed to use ctrulib -# -# It also adds an imported target named `3ds::ctrulib`. -# Linking it is the same as target_link_libraries(target ${LIBCTRU_LIBRARIES}) and target_include_directories(target ${LIBCTRU_INCLUDE_DIRS}) - -# DevkitPro paths are broken on windows, so we have to fix those -macro(msys_to_cmake_path MsysPath ResultingPath) - string(REGEX REPLACE "^/([a-zA-Z])/" "\\1:/" ${ResultingPath} "${MsysPath}") -endmacro() - -if(NOT DEVKITPRO) - msys_to_cmake_path("$ENV{DEVKITPRO}" DEVKITPRO) -endif() - -set(CTRULIB_PATHS $ENV{CTRULIB} libctru ctrulib ${DEVKITPRO}/libctru ${DEVKITPRO}/ctrulib) - -find_path(LIBCTRU_INCLUDE_DIR 3ds.h - PATHS ${CTRULIB_PATHS} - PATH_SUFFIXES include libctru/include ) - -find_library(LIBCTRU_LIBRARY NAMES ctru libctru.a - PATHS ${CTRULIB_PATHS} - PATH_SUFFIXES lib libctru/lib ) - -set(LIBCTRU_LIBRARIES ${LIBCTRU_LIBRARY} ) -set(LIBCTRU_INCLUDE_DIRS ${LIBCTRU_INCLUDE_DIR} ) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LIBCTRU_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(CTRULIB DEFAULT_MSG - LIBCTRU_LIBRARY LIBCTRU_INCLUDE_DIR) - -mark_as_advanced(LIBCTRU_INCLUDE_DIR LIBCTRU_LIBRARY ) -if(CTRULIB_FOUND) - set(CTRULIB ${LIBCTRU_INCLUDE_DIR}/..) - message(STATUS "setting CTRULIB to ${CTRULIB}") - - add_library(3ds::ctrulib STATIC IMPORTED GLOBAL) - set_target_properties(3ds::ctrulib PROPERTIES - IMPORTED_LOCATION "${LIBCTRU_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${LIBCTRU_INCLUDE_DIR}" - ) -endif() diff --git a/cmake/FindSF2D.cmake b/cmake/FindSF2D.cmake deleted file mode 100644 index 28947fa..0000000 --- a/cmake/FindSF2D.cmake +++ /dev/null @@ -1,45 +0,0 @@ -# - Try to find sf2d -# Once done this will define -# LIBSF2D_FOUND - System has sf2d -# LIBSF2D_INCLUDE_DIRS - The sf2d include directories -# LIBSF2D_LIBRARIES - The libraries needed to use sf2d -# -# It also adds an imported target named `3ds::sf2d`. -# Linking it is the same as target_link_libraries(target ${LIBSF2D_LIBRARIES}) and target_include_directories(target ${LIBSF2D_INCLUDE_DIRS}) - - -# DevkitPro paths are broken on windows, so we have to fix those -macro(msys_to_cmake_path MsysPath ResultingPath) - string(REGEX REPLACE "^/([a-zA-Z])/" "\\1:/" ${ResultingPath} "${MsysPath}") -endmacro() - -if(NOT DEVKITPRO) - msys_to_cmake_path("$ENV{DEVKITPRO}" DEVKITPRO) -endif() - -find_path(LIBSF2D_INCLUDE_DIR sf2d.h - PATH_SUFFIXES include ) - -find_library(LIBSF2D_LIBRARY NAMES sf2d libsf2d.a - PATH_SUFFIXES lib) - -set(LIBSF2D_LIBRARIES ${LIBSF2D_LIBRARY} ) -set(LIBSF2D_INCLUDE_DIRS ${LIBSF2D_INCLUDE_DIR} ) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LIBSF2D_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(SF2D DEFAULT_MSG - LIBSF2D_LIBRARY LIBSF2D_INCLUDE_DIR) - -mark_as_advanced(LIBSF2D_INCLUDE_DIR LIBSF2D_LIBRARY ) -if(SF2D_FOUND) - set(SF2D ${LIBSF2D_INCLUDE_DIR}/..) - message(STATUS "setting SF2D to ${SF2D}") - - add_library(3ds::sf2d STATIC IMPORTED GLOBAL) - set_target_properties(3ds::sf2d PROPERTIES - IMPORTED_LOCATION "${LIBSF2D_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${LIBSF2D_INCLUDE_DIR}" - ) -endif() diff --git a/cmake/Tools3DS.cmake b/cmake/Tools3DS.cmake deleted file mode 100644 index 295dafd..0000000 --- a/cmake/Tools3DS.cmake +++ /dev/null @@ -1,511 +0,0 @@ -############################################################################ -# Various macros for 3DS homebrews tools -# -# add_3dsx_target -# ^^^^^^^^^^^^^^^ -# -# This macro has two signatures : -# -# ## add_3dsx_target(target [NO_SMDH]) -# -# Adds a target that generates a .3dsx file from `target`. If NO_SMDH is specified, no .smdh file will be generated. -# -# You can set the following variables to change the SMDH file : -# -# * 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) -# * APP_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): -# - $(target).png -# - icon.png -# - $(libctru folder)/default_icon.png -# -# ## add_3dsx_target(target APP_TITLE APP_DESCRIPTION APP_AUTHOR [APP_ICON]) -# -# This version will produce the SMDH with tha values passed as arguments. Tha APP_ICON is optional and follows the same rule as the other version of `add_3dsx_target`. -# -# add_cia_target(target RSF IMAGE SOUND [APP_TITLE APP_DESCRIPTION APP_AUTHOR [APP_ICON]]) -# ^^^^^^^^^^^^^^ -# -# Same as add_3dsx_target but for CIA files. -# -# RSF is the .rsf file to be given to makerom. -# IMAGE is either a .png or a cgfximage file. -# SOUND is either a .wav or a cwavaudio file. -# -# add_netload_target(name target_or_file) -# ^^^^^^^^^^^^^^^^^^ -# -# Adds a target `name` that sends a .3dsx using the homebrew launcher netload system (3dslink). -# target_or_file is either the name of a target or of file. -# -# add_binary_library(target input1 [input2 ...]) -# ^^^^^^^^^^^^^^^^^^ -# -# /!\ Requires ASM to be enabled ( `enable_language(ASM)` or `project(yourprojectname C CXX ASM)`) -# -# Converts the files given as input to arrays of their binary data. This is useful to embed resources into your project. -# For example, logo.bmp will generate the array `u8 logo_bmp[]` and its size `logo_bmp_size`. By linking this library, you -# will also have access to a generated header file called `logo_bmp.h` which contains the declarations you need to use it. -# -# Note : All dots in the filename are converted to `_`, and if it starts with a number, `_` will be prepended. -# For example 8x8.gas.tex would give the name _8x8_gas_tex. -# -# target_embed_file(target input1 [input2 ...]) -# ^^^^^^^^^^^^^^^^^ -# -# Same as add_binary_library(tempbinlib input1 [input2 ...]) + target_link_libraries(target tempbinlib) -# -# add_shbin(output input [entrypoint] [shader_type]) -# ^^^^^^^^^^^^^^^^^^^^^^^ -# -# Assembles the shader given as `input` into the file `output`. No file extension is added. -# You can choose the shader assembler by setting SHADER_AS to `picasso` or `nihstro`. -# -# If `nihstro` is set as the assembler, entrypoint and shader_type will be used. -# entrypoint is set to `main` by default -# shader_type can be either VSHADER or GSHADER. By default it is VSHADER. -# -# generate_shbins(input1 [input2 ...]) -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# Assemble all the shader files given as input into .shbin files. Those will be located in the folder `shaders` of the build directory. -# The names of the output files will be .shbin. vshader.pica will output shader.shbin but shader.vertex.pica will output shader.shbin too. -# -# add_shbin_library(target input1 [input2 ...]) -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# /!\ Requires ASM to be enabled ( `enable_language(ASM)` or `project(yourprojectname C CXX ASM)`) -# -# This is the same as calling generate_shbins and add_binary_library. This is the function to be used to reproduce devkitArm makefiles behaviour. -# For example, add_shbin_library(shaders data/my1stshader.vsh.pica) will generate the target library `shaders` and you -# will be able to use the shbin in your program by linking it, including `my1stshader_pica.h` and using `my1stshader_pica[]` and `my1stshader_pica_size`. -# -# target_embed_shader(target input1 [input2 ...]) -# ^^^^^^^^^^^^^^^^^ -# -# Same as add_shbin_library(tempbinlib input1 [input2 ...]) + target_link_libraries(target tempbinlib) -# -############################################################################ - -if(NOT 3DS) - message(WARNING "Those tools can only be used if you are using the 3DS toolchain file. Please erase this build directory or create another one, and then use -DCMAKE_TOOLCHAIN_FILE=DevkitArm3DS.cmake when calling cmake for the 1st time. For more information, see the Readme.md for more information.") -endif() - -get_filename_component(__tools3dsdir ${CMAKE_CURRENT_LIST_FILE} PATH) # Used to locate files to be used with configure_file - -message(STATUS "Looking for 3ds tools...") - -############## -## 3DSXTOOL ## -############## -if(NOT _3DSXTOOL) - # message(STATUS "Looking for 3dsxtool...") - find_program(_3DSXTOOL 3dsxtool ${DEVKITARM}/bin) - if(_3DSXTOOL) - message(STATUS "3dsxtool: ${_3DSXTOOL} - found") - else() - message(WARNING "3dsxtool - not found") - endif() -endif() - - -############## -## SMDHTOOL ## -############## -if(NOT SMDHTOOL) - # message(STATUS "Looking for smdhtool...") - find_program(SMDHTOOL smdhtool ${DEVKITARM}/bin) - if(SMDHTOOL) - message(STATUS "smdhtool: ${SMDHTOOL} - found") - else() - message(WARNING "smdhtool - not found") - endif() -endif() - -################ -## BANNERTOOL ## -################ -if(NOT BANNERTOOL) - # message(STATUS "Looking for bannertool...") - find_program(BANNERTOOL bannertool ${DEVKITARM}/bin) - if(BANNERTOOL) - message(STATUS "bannertool: ${BANNERTOOL} - found") - else() - message(WARNING "bannertool - not found") - endif() -endif() - -set(FORCE_SMDHTOOL FALSE CACHE BOOL "Force the use of smdhtool instead of bannertool") - -############# -## MAKEROM ## -############# -if(NOT MAKEROM) - # message(STATUS "Looking for makerom...") - find_program(MAKEROM makerom ${DEVKITARM}/bin) - if(MAKEROM) - message(STATUS "makerom: ${MAKEROM} - found") - else() - message(WARNING "makerom - not found") - endif() -endif() - - - -############# -## STRIP ## -############# -if(NOT STRIP) - # message(STATUS "Looking for strip...") - find_program(STRIP arm-none-eabi-strip ${DEVKITARM}/bin) - if(STRIP) - message(STATUS "strip: ${STRIP} - found") - else() - message(WARNING "strip - not found") - endif() -endif() - - - -############# -## BIN2S ## -############# -if(NOT BIN2S) - # message(STATUS "Looking for bin2s...") - find_program(BIN2S bin2s ${DEVKITARM}/bin) - if(BIN2S) - message(STATUS "bin2s: ${BIN2S} - found") - else() - message(WARNING "bin2s - not found") - endif() -endif() - -############### -## 3DSLINK ## -############### -if(NOT _3DSLINK) - # message(STATUS "Looking for 3dslink...") - find_program(_3DSLINK 3dslink ${DEVKITARM}/bin) - if(_3DSLINK) - message(STATUS "3dslink: ${_3DSLINK} - found") - else() - message(WARNING "3dslink - not found") - endif() -endif() - -############# -## PICASSO ## -############# -if(NOT PICASSO_EXE) - # message(STATUS "Looking for Picasso...") - find_program(PICASSO_EXE picasso ${DEVKITARM}/bin) - if(PICASSO_EXE) - message(STATUS "Picasso: ${PICASSO_EXE} - found") - set(SHADER_AS picasso CACHE STRING "The shader assembler to be used. Allowed values are 'none', 'picasso' or 'nihstro'") - else() - message(STATUS "Picasso - not found") - endif() -endif() - - -############# -## NIHSTRO ## -############# - -if(NOT NIHSTRO_AS) - # message(STATUS "Looking for nihstro...") - find_program(NIHSTRO_AS nihstro ${DEVKITARM}/bin) - if(NIHSTRO_AS) - message(STATUS "nihstro: ${NIHSTRO_AS} - found") - set(SHADER_AS nihstro CACHE STRING "The shader assembler to be used. Allowed values are 'none', 'picasso' or 'nihstro'") - else() - message(STATUS "nihstro - not found") - endif() -endif() - -set(SHADER_AS none CACHE STRING "The shader assembler to be used. Allowed values are 'none', 'picasso' or 'nihstro'") - -############################### -############################### -######## MACROS ######### -############################### -############################### - - -################### -### EXECUTABLES ### -################### - - -function(__add_smdh target APP_TITLE APP_DESCRIPTION APP_AUTHOR APP_ICON) - if(BANNERTOOL AND NOT FORCE_SMDHTOOL) - set(__SMDH_COMMAND ${BANNERTOOL} makesmdh -s ${APP_TITLE} -l ${APP_DESCRIPTION} -p ${APP_AUTHOR} -i ${APP_ICON} -o ${CMAKE_CURRENT_BINARY_DIR}/${target}) - else() - set(__SMDH_COMMAND ${SMDHTOOL} --create ${APP_TITLE} ${APP_DESCRIPTION} ${APP_AUTHOR} ${APP_ICON} ${CMAKE_CURRENT_BINARY_DIR}/${target}) - endif() - add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target} - COMMAND ${__SMDH_COMMAND} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - DEPENDS ${APP_ICON} - VERBATIM - ) -endfunction() - -function(add_3dsx_target target) - get_filename_component(target_we ${target} NAME_WE) - if((NOT (${ARGC} GREATER 1 AND "${ARGV1}" STREQUAL "NO_SMDH") ) OR (${ARGC} GREATER 3) ) - if(${ARGC} GREATER 3) - set(APP_TITLE ${ARGV1}) - set(APP_DESCRIPTION ${ARGV2}) - set(APP_AUTHOR ${ARGV3}) - endif() - if(${ARGC} EQUAL 5) - set(APP_ICON ${ARGV4}) - endif() - if(NOT APP_TITLE) - set(APP_TITLE ${target}) - endif() - if(NOT APP_DESCRIPTION) - set(APP_DESCRIPTION "Built with devkitARM & libctru") - endif() - if(NOT APP_AUTHOR) - set(APP_AUTHOR "Unspecified Author") - endif() - if(NOT APP_ICON) - if(EXISTS ${target}.png) - set(APP_ICON ${target}.png) - elseif(EXISTS icon.png) - set(APP_ICON icon.png) - elseif(CTRULIB) - set(APP_ICON ${CTRULIB}/default_icon.png) - else() - message(FATAL_ERROR "No icon found ! Please use NO_SMDH or provide some icon.") - endif() - endif() - if( NOT ${target_we}.smdh) - __add_smdh(${target_we}.smdh ${APP_TITLE} ${APP_DESCRIPTION} ${APP_AUTHOR} ${APP_ICON}) - endif() - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.3dsx - COMMAND ${_3DSXTOOL} $ ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.3dsx --smdh=${CMAKE_CURRENT_BINARY_DIR}/${target_we}.smdh - DEPENDS ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.smdh - VERBATIM - ) - else() - message(STATUS "No smdh file will be generated") - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.3dsx - COMMAND ${_3DSXTOOL} $ ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.3dsx - DEPENDS ${target} - VERBATIM - ) - endif() - add_custom_target(${target_we}_3dsx ALL SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.3dsx) - set_target_properties(${target} PROPERTIES LINK_FLAGS "-specs=3dsx.specs") -endfunction() - -function(__add_ncch_banner target IMAGE SOUND) - if(IMAGE MATCHES ".*\\.png$") - set(IMG_PARAM -i ${IMAGE}) - else() - set(IMG_PARAM -ci ${IMAGE}) - endif() - if(SOUND MATCHES ".*\\.wav$") - set(SND_PARAM -a ${SOUND}) - else() - set(SND_PARAM -ca ${SOUND}) - endif() - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target} - COMMAND ${BANNERTOOL} makebanner -o ${CMAKE_CURRENT_BINARY_DIR}/${target} ${IMG_PARAM} ${SND_PARAM} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - DEPENDS ${IMAGE} ${SOUND} - VERBATIM - ) -endfunction() - -function(add_cia_target target RSF IMAGE SOUND ) - get_filename_component(target_we ${target} NAME_WE) - if(${ARGC} GREATER 6) - set(APP_TITLE ${ARGV4}) - set(APP_DESCRIPTION ${ARGV5}) - set(APP_AUTHOR ${ARGV6}) - endif() - if(${ARGC} EQUAL 8) - set(APP_ICON ${ARGV7}) - endif() - if(NOT APP_TITLE) - set(APP_TITLE ${target}) - endif() - if(NOT APP_DESCRIPTION) - set(APP_DESCRIPTION "Built with devkitARM & libctru") - endif() - if(NOT APP_AUTHOR) - set(APP_AUTHOR "Unspecified Author") - endif() - if(NOT APP_ICON) - if(EXISTS ${target}.png) - set(APP_ICON ${target}.png) - elseif(EXISTS icon.png) - set(APP_ICON icon.png) - elseif(CTRULIB) - set(APP_ICON ${CTRULIB}/default_icon.png) - else() - message(FATAL_ERROR "No icon found ! Please use NO_SMDH or provide some icon.") - endif() - endif() - if( NOT ${target_we}.smdh) - __add_smdh(${target_we}.smdh ${APP_TITLE} ${APP_DESCRIPTION} ${APP_AUTHOR} ${APP_ICON}) - endif() - __add_ncch_banner(${target_we}.bnr ${IMAGE} ${SOUND}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.cia - COMMAND ${STRIP} -o $-stripped $ - COMMAND ${MAKEROM} -f cia - -target t - -exefslogo - -o ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.cia - -elf $-stripped - -rsf ${RSF} - -banner ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.bnr - -icon ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.smdh - DEPENDS ${target} ${RSF} ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.bnr ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.smdh - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - VERBATIM - ) - - add_custom_target(${target_we}_cia ALL SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.cia) - set_target_properties(${target} PROPERTIES LINK_FLAGS "-specs=3dsx.specs") -endfunction() - -macro(add_netload_target name target) - set(NETLOAD_IP "" CACHE STRING "The ip address of the 3ds when using netload.") - if(NETLOAD_IP) - set(__NETLOAD_IP_OPTION -a ${NETLOAD_IP}) - endif() - if(NOT TARGET ${target}) - message("NOT ${target}") - set(FILE ${target}) - else() - set(FILE ${CMAKE_CURRENT_BINARY_DIR}/${target}.3dsx) - endif() - add_custom_target(${name} - COMMAND ${_3DSLINK} ${FILE} ${__NETLOAD_IP_OPTION} - DEPENDS ${FILE} - ) -endmacro() - -###################### -### File embedding ### -###################### - -macro(add_binary_library libtarget) - if(NOT ${ARGC} GREATER 1) - message(FATAL_ERROR "add_binary_library : Argument error (no input files)") - endif() - get_cmake_property(ENABLED_LANGUAGES ENABLED_LANGUAGES) - if(NOT ENABLED_LANGUAGES MATCHES ".*ASM.*") - message(FATAL_ERROR "You have to enable ASM in order to use add_shader_library. Use enable_language(ASM). Currently enabled languages are ${ENABLED_LANGUAGES}") - endif() - - - foreach(__file ${ARGN}) - get_filename_component(__file_wd ${__file} NAME) - string(REGEX REPLACE "^([0-9])" "_\\1" __BIN_FILE_NAME ${__file_wd}) # add '_' if the file name starts by a number - string(REGEX REPLACE "[-./]" "_" __BIN_FILE_NAME ${__BIN_FILE_NAME}) - - #Generate the header file - configure_file(${__tools3dsdir}/bin2s_header.h.in ${CMAKE_CURRENT_BINARY_DIR}/${libtarget}_include/${__BIN_FILE_NAME}.h) - endforeach() - - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/binaries_asm) - # Generate the assembly file, and create the new target - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/binaries_asm/${libtarget}.s - COMMAND ${BIN2S} ${ARGN} > ${CMAKE_CURRENT_BINARY_DIR}/binaries_asm/${libtarget}.s - DEPENDS ${ARGN} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - ) - - add_library(${libtarget} ${CMAKE_CURRENT_BINARY_DIR}/binaries_asm/${libtarget}.s) - target_include_directories(${libtarget} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/${libtarget}_include) -endmacro() - -macro(target_embed_file _target) - if(NOT ${ARGC} GREATER 1) - message(FATAL_ERROR "target_embed_file : Argument error (no input files)") - endif() - get_filename_component(__1st_file_wd ${ARGV1} NAME) - add_binary_library(__${_target}_embed_${__1st_file_wd} ${ARGN}) - target_link_libraries(${_target} __${_target}_embed_${__1st_file_wd}) -endmacro() - -################### -##### SHADERS ##### -################### - -macro(add_shbin OUTPUT INPUT ) - - if(SHADER_AS STREQUAL "picasso") - - if(${ARGC} GREATER 2) - message(WARNING "Picasso doesn't support changing the entrypoint or shader type") - endif() - add_custom_command(OUTPUT ${OUTPUT} COMMAND ${PICASSO_EXE} -o ${OUTPUT} ${INPUT} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) - - elseif(SHADER_AS STREQUAL "nihstro") - if(NOT NIHSTRO_AS) - message(SEND_ERROR "SHADER_AS is set to nihstro, but nihstro wasn't found. Please set NIHSTRO_AS.") - endif() - if(${ARGC} GREATER 2) - if(${ARGV2} EQUAL GSHADER) - set(SHADER_TYPE_FLAG "-g") - elseif(NOT ${ARGV2} EQUAL VSHADER) - set(_ENTRYPOINT ${ARGV2}) - endif() - endif() - if(${ARGC} GREATER 3) - if(${ARGV2} EQUAL GSHADER) - set(SHADER_TYPE_FLAG "-g") - elseif(NOT ${ARGV3} EQUAL VSHADER) - set(_ENTRYPOINT ${ARGV3}) - endif() - endif() - if(NOT _ENTRYPOINT) - set(_ENTRYPOINT "main") - endif() - add_custom_command(OUTPUT ${OUTPUT} COMMAND ${NIHSTRO_AS} ${INPUT} -o ${OUTPUT} -e ${_ENTRYPOINT} ${SHADER_TYPE_FLAG} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) - - else() - message(FATAL_ERROR "Please set SHADER_AS to 'picasso' or 'nihstro' if you use the shbin feature.") - endif() - -endmacro() - -function(generate_shbins) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders) - foreach(__shader_file ${ARGN}) - get_filename_component(__shader_file_we ${__shader_file} NAME_WE) - #Generate the shbin file - list(APPEND __SHADERS_BIN_FILES ${CMAKE_CURRENT_BINARY_DIR}/shaders/${__shader_file_we}.shbin) - add_shbin(${CMAKE_CURRENT_BINARY_DIR}/shaders/${__shader_file_we}.shbin ${__shader_file}) - endforeach() -endfunction() - -function(add_shbin_library libtarget) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders) - foreach(__shader_file ${ARGN}) - get_filename_component(__shader_file_we ${__shader_file} NAME_WE) - #Generate the shbin file - list(APPEND __SHADERS_BIN_FILES ${CMAKE_CURRENT_BINARY_DIR}/shaders/${__shader_file_we}.shbin) - add_shbin(${CMAKE_CURRENT_BINARY_DIR}/shaders/${__shader_file_we}.shbin ${__shader_file}) - endforeach() - add_binary_library(${libtarget} ${__SHADERS_BIN_FILES}) -endfunction() - - -macro(target_embed_shader _target) - if(NOT ${ARGC} GREATER 1) - message(FATAL_ERROR "target_embed_shader : Argument error (no input files)") - endif() - get_filename_component(__1st_file_wd ${ARGV1} NAME) - add_shbin_library(__${_target}_embed_${__1st_file_wd} ${ARGN}) - target_link_libraries(${_target} __${_target}_embed_${__1st_file_wd}) -endmacro() diff --git a/cmake/bin2s_header.h.in b/cmake/bin2s_header.h.in deleted file mode 100644 index 4ea7c4c..0000000 --- a/cmake/bin2s_header.h.in +++ /dev/null @@ -1,3 +0,0 @@ -extern const u8 @__BIN_FILE_NAME@_end[]; -extern const u8 @__BIN_FILE_NAME@[]; -extern const u32 @__BIN_FILE_NAME@_size; diff --git a/source/TWLCard.cpp b/source/TWLCard.cpp index 0ddc31d..2a3ccd3 100644 --- a/source/TWLCard.cpp +++ b/source/TWLCard.cpp @@ -55,7 +55,7 @@ u32 TWLCard::JEDECID(void) const { std::string TWLCard::generateFileName(void) const { std::string name(h.gameTitle); - for(int i = 0; i < name.size(); ++i) { + for(size_t i = 0; i < name.size(); ++i) { if(!( (name[i] >= 'A' && name[i] <= 'Z') || (name[i] >= 'a' && name[i] <= 'z') || (name[i] >= '0' && name[i] <= '9') || name[i] == ' ')) name[i] = '_'; } diff --git a/source/main.cpp b/source/main.cpp index fa34e68..4316794 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -22,9 +22,9 @@ extern "C"{ #include #include +#include <3ds/console.h> } -#include <3ds/console.h> #include "TWLCard.h" @@ -219,7 +219,7 @@ int main() { else if(keys & KEY_X) { try{ - printf("\x1B[33mAre you REALLY sure you want to erase your save data?\n\n(UP) Yes\t\t(DOWN) No\x1B[0m\n", fileName.c_str()); + printf("\x1B[33mAre you REALLY sure you want to erase your save data?\n\n(UP) Yes\t\t(DOWN) No\x1B[0m\n"); while(aptMainLoop()){ hidScanInput(); if(hidKeysDown() & KEY_UP) break;