Skip to content

Commit

Permalink
Today was one hell of a day.
Browse files Browse the repository at this point in the history
  • Loading branch information
J-D-K committed Nov 23, 2024
1 parent 298aac6 commit a8f50b6
Show file tree
Hide file tree
Showing 90 changed files with 2,326 additions and 5,728 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Set the default behavior for all files.
* text=auto eol=lf

# Normalized and converts to native line endings on checkout.
*.c text
*.cc text
*.cxx
*.cpp text
*.h text
*.hxx text
*.hpp text
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.vscode/
build/
*.cbp
*.layout
.clang-format
.clang-tidy
.editorconfig
*.lst
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "FsLib"]
path = FsLib
url = https://github.com/J-D-K/FsLib.git
1 change: 1 addition & 0 deletions FsLib
Submodule FsLib added at e2fda4
File renamed without changes.
239 changes: 239 additions & 0 deletions JKSM/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
#---------------------------------------------------------------------------------
.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
# 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):
# - <Project name>.png
# - icon.png
# - <libctru folder>/default_icon.png
#---------------------------------------------------------------------------------
TARGET := JKSM
BUILD := build
SOURCES := source source/SDL source/Data source/UI source/AppStates
DATA := data
INCLUDES := include ../FsLib/3DS/FsLib/include
#GRAPHICS := gfx
#GFXBUILD := $(BUILD)
ROMFS := romfs
#GFXBUILD := $(ROMFS)/gfx
APP_TITLE := JK's Save Manager
APP_DESCRIPTION := The 3DS save manager
APP_AUTHOR := JK

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

CFLAGS := -g -Wall -O2 -mword-relocations `sdl-config --cflags` \
`freetype-config --cflags` -fomit-frame-pointer -ffunction-sections \
$(ARCH)

CFLAGS += $(INCLUDE) -D__3DS__

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -Wno-psabi -std=c++23

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

LIBS := ../../FsLib/3DS/FsLib/lib/libFsLib.a -lSDL_image `sdl-config --libs` \
`freetype-config --libs` -ljson-c -lcurl -lmbedtls -lmbedcrypto \
-lmbedx509 -lminizip -ljpeg -lpng -lctru -lz -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 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

.PHONY: all clean

#---------------------------------------------------------------------------------
all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES)
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

$(BUILD):
@mkdir -p $@

ifneq ($(GFXBUILD),$(BUILD))
$(GFXBUILD):
@mkdir -p $@
endif

ifneq ($(DEPSDIR),$(BUILD))
$(DEPSDIR):
@mkdir -p $@
endif

#---------------------------------------------------------------------------------

send: all
@3dslink $(TARGET).3dsx

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD)

#---------------------------------------------------------------------------------
$(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
#---------------------------------------------------------------------------------------
File renamed without changes.
File renamed without changes.
File renamed without changes
45 changes: 45 additions & 0 deletions JKSM/include/AppStates/AppState.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include "SDL/SDL.hpp"

class AppState
{
public:
AppState(void) = default;
virtual ~AppState() {};

virtual void Update(void) = 0;
virtual void DrawTop(SDL_Surface *Target) = 0;
virtual void DrawBottom(SDL_Surface *Target) = 0;

// I usually avoid having this stuff in headers now, but here I don't care.
bool IsActive(void) const
{
return m_IsActive;
}

bool HasFocus(void) const
{
return m_HasFocus;
}

void Deactivate(void)
{
m_IsActive = false;
}

void TakeFocus(void)
{
m_HasFocus = false;
}

void GiveFocus(void)
{
m_HasFocus = true;
}

private:
// Whether state is active or can be purged.
bool m_IsActive = true;
// Whether a state is at the back of the vector and has focus.
bool m_HasFocus = false;
};
23 changes: 23 additions & 0 deletions JKSM/include/AppStates/TitleSelectionState.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "AppStates/AppState.hpp"
#include "Data/Data.hpp"
#include "SDL/SDL.hpp"
#include "UI/TitleView.hpp"
#include <memory>

class TitleSelectionState : public AppState
{
public:
TitleSelectionState(Data::SaveDataType SaveType);
~TitleSelectionState() {};

void Update(void);
void DrawTop(SDL_Surface *Target);
void DrawBottom(SDL_Surface *Target);

private:
// To do: Maybe not a pointer...
std::unique_ptr<UI::TitleView> m_TitleView;
// Noto for text
SDL::SharedFont m_Noto;
};
11 changes: 11 additions & 0 deletions JKSM/include/Data/Data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "Data/TitleData.hpp"
#include <vector>

namespace Data
{
// Loads data from cache or system if cache isn't present.
bool Initialize(void);
// This gets a vector of the titles with the corresponding save type.
void GetTitlesWithType(SaveDataType SaveType, std::vector<Data::TitleData *> &Out);
} // namespace Data
45 changes: 45 additions & 0 deletions JKSM/include/Data/SMDH.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include <3ds.h>
#include <stdint.h>

namespace Data
{
// This is from the 3ds homebrew menu.
typedef struct
{
uint32_t magic;
uint16_t version;
uint16_t reserved;
} smdhHeader_s;

typedef struct
{
uint16_t shortDescription[0x40];
uint16_t longDescription[0x80];
uint16_t publisher[0x40];
} smdhTitle_s;

typedef struct
{
uint8_t gameRatings[0x10];
uint32_t regionLock;
uint8_t matchMakerId[0xC];
uint32_t flags;
uint16_t eulaVersion;
uint16_t reserved;
uint16_t defaultFrame;
uint32_t cecId;
} smdhSettings_s;

typedef struct
{
smdhHeader_s header;
smdhTitle_s applicationTitles[16];
smdhSettings_s settings;
uint8_t reserved[0x8];
uint8_t smallIconData[0x480];
uint16_t bigIconData[0x900];
} SMDH;
// Attempts to load SMDH. Returns false on failure.
bool LoadSMDH(uint64_t TitleID, FS_MediaType MediaType, SMDH &Out);
} // namespace Data
Loading

0 comments on commit a8f50b6

Please sign in to comment.